找回密码
立即注册
搜索
热搜: 活动 交友 discuz
发新帖

343

积分

0

好友

31

主题
发表于 2023-8-24 02:53:11 | 查看: 2057| 回复: 1 IP:中国广东省 中国电信公众宽带
本帖最后由 zeruns 于 2023-8-24 02:54 编辑

沁恒CH32V307VCT6最小系统板,引出了所有IO口,一个Type-C连接到USB2.0全速OTG接口,一个Flash芯片 型号W25Q64 容量64Mbit 连接到SPI2接口,板上还有TL432电压基准1.25V(实测1.246V左右)可通过跳线连接到PC3的AD13,还有3.29V基准通过0欧电阻可连接到ADC参考电压VREF。

CH32V307VCT6简介
CH32V 系列是基于青稞 32 位 RISC-V 设计的工业级通用微控制器。全系产品加入硬件堆栈区、快速中断入口等设计,相比标准大大提高了中断响应速度。CH32V303_305_307 系列搭载 V4F 内核,支持单精度浮点指令集,具有更高的运算性能。在产品功能上支持 144MHz 主频零等待运行,并根据不同应用方向提供了具有特色的资源结构,例如 8 组 USART/UART 串口,4 组电机定时器,内置 PHY 收发器的USB2.0 高速接口(480Mbps),千兆以太网 MAC 等。

沁恒官网产品简介:https://url.zeruns.tech/Hcd8p
样品免费申请地址(运费到付):https://url.zeruns.tech/x67TF
芯片数据手册下载地址:https://url.zeruns.tech/hDzqw    提取码:cn7c

实物图


原理图
图中的Type-C接口有点问题,CC1和CC2要用5.1K电阻分别下拉,我并联下拉了会导致使用Emark线时不能正常供电,立创开源平台上的项目已修正。

PCB
顶层:
TL432的1.25V(实测1.246V左右)电压基准可通过H8插跳线帽接到GPIOPC3的ADC13接口。
SW3是控制BOOT0和1自举引脚的,可以设置自举模式(具体看芯片手册2.5.2的 片上存储器及自举模式),都打到低电平(关闭)就行。
H9排针时用于接WCH-Link烧录代码用的。
H5排针是用于选择VBAT引脚的电源,如果没插电池就通过跳线帽接到3.3V电源,如果插了电池可接到BAT。
底层:
如果不需要外接VDDA电源和VREF要将底面的R11和R7接上0欧电阻,然后VREF+可以通过R8和R9选择接LDO降压出来的3.3V电源或者TL432输出的3.29V参考电压,正常接R9即可 另一个空着。
元件购买地址
元器件购买推荐立创商城,优惠注册链接:https://activity.szlcsc.com/invite/D03E5B9CEAAE70A4.html
板上所有元器件都可以在立创商城买到,在开源链接里的BOM表那点立即到立创商城下单可将用到的元器件一键导入到购物车。
例程代码
完整工程下载地址:https://url.zeruns.tech/2q4tX   提取码:9527
立创开源平台开源链接:https://url.zeruns.tech/Avda8
例程用了 Harmony LiteOS-M 系统,例程中建了3个任务,分别是:LED2间隔500ms闪一下,LED3间隔1秒闪一下,LED4间隔2秒闪一次。(上面的动图速度加快了1.5倍)
工程要用MounRiver Studio软件打开。

main.c的代码:
  1. /*
  2.   * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
  3.   * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
  4.   *
  5.   * Redistribution and use in source and binary forms, with or without modification,
  6.   * are permitted provided that the following conditions are met:
  7.   *
  8.   * 1. Redistributions of source code must retain the above copyright notice, this list of
  9.   *    conditions and the following disclaimer.
  10.   *
  11.   * 2. Redistributions in binary form must reproduce the above copyright notice, this list
  12.   *    of conditions and the following disclaimer in the documentation and/or other materials
  13.   *    provided with the distribution.
  14.   *
  15.   * 3. Neither the name of the copyright holder nor the names of its contributors may be used
  16.   *    to endorse or promote products derived from this software without specific prior written
  17.   *    permission.
  18.   *
  19.   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  20.   * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  21.   * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  22.   * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  23.   * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  24.   * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  25.   * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  26.   * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  27.   * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  28.   * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  29.   * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30.   */

  31. #include "debug.h"
  32. #include "los_tick.h"
  33. #include "los_task.h"
  34. #include "los_config.h"
  35. #include "los_interrupt.h"
  36. #include "los_debug.h"
  37. #include "los_compiler.h"

  38. /* Global define */


  39. /* Global Variable */
  40. __attribute__((aligned (8))) UINT8 g_memStart[LOSCFG_SYS_HEAP_SIZE];
  41. UINT32 g_VlaueSp=0;

  42. u8 i = 0,j=0,k=0;

  43. /*********************************************************************
  44.   * @fn      taskSampleEntry3
  45.   *
  46.   * @brief   taskSampleEntry3 program.
  47.   *
  48.   * @return  none
  49.   */
  50. VOID taskSampleEntry3(VOID)
  51. {
  52.      while(1) {
  53.        LOS_TaskDelay(2000);
  54.        printf("taskSampleEntry3 running,task3 SP:%08x\n",__get_SP());
  55.        GPIO_WriteBit(GPIOD, GPIO_Pin_13, (k == 0) ? (k = Bit_SET) : (k = Bit_RESET));
  56.      }
  57. }


  58. /*********************************************************************
  59.   * @fn      taskSampleEntry2
  60.   *
  61.   * @brief   taskSampleEntry2 program.
  62.   *
  63.   * @return  none
  64.   */
  65. VOID taskSampleEntry2(VOID)
  66. {
  67.      while(1) {
  68.        LOS_TaskDelay(1000);
  69.        printf("taskSampleEntry2 running,task2 SP:%08x\n",__get_SP());
  70.        GPIO_WriteBit(GPIOD, GPIO_Pin_12, (j == 0) ? (j = Bit_SET) : (j = Bit_RESET));
  71.      }
  72. }

  73. /*********************************************************************
  74.   * @fn      taskSampleEntry1
  75.   *
  76.   * @brief   taskSampleEntry1 program.
  77.   *
  78.   * @return  none
  79.   */
  80. VOID taskSampleEntry1(VOID)
  81. {
  82.      while(1) {
  83.        LOS_TaskDelay(500);
  84.        printf("taskSampleEntry1 running,task1 SP:%08x\n",__get_SP());
  85.        GPIO_WriteBit(GPIOD, GPIO_Pin_11, (i == 0) ? (i = Bit_SET) : (i = Bit_RESET));
  86.      }

  87. }
  88. // <a href="https://blog.zeruns.tech" target="_blank">https://blog.zeruns.tech</a>
  89. /*********************************************************************
  90.   * @fn      EXTI0_INT_INIT
  91.   *
  92.   * @brief   Initializes EXTI0 collection.
  93.   *
  94.   * @return  none
  95.   */
  96. void EXTI0_INT_INIT(void)
  97. {
  98.    GPIO_InitTypeDef  GPIO_InitStructure={0};
  99.    EXTI_InitTypeDef EXTI_InitStructure={0};
  100.    NVIC_InitTypeDef NVIC_InitStructure={0};

  101.    RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO|RCC_APB2Periph_GPIOA,ENABLE);

  102.    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
  103.    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
  104.    GPIO_Init(GPIOA, &GPIO_InitStructure);

  105.     /* GPIOA ----> EXTI_Line0 */
  106.    GPIO_EXTILineConfig(GPIO_PortSourceGPIOA,GPIO_PinSource0);
  107.    EXTI_InitStructure.EXTI_Line=EXTI_Line0;
  108.    EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
  109.    EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
  110.    EXTI_InitStructure.EXTI_LineCmd = ENABLE;
  111.    EXTI_Init(&EXTI_InitStructure);

  112.    NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn;
  113.    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
  114.    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 4;
  115.    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  116.    NVIC_Init(&NVIC_InitStructure);
  117. }

  118. void GPIO_INIT(void) {
  119.      GPIO_InitTypeDef GPIO_InitStructure = { 0 };

  120.      RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD, ENABLE);
  121.      GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12|GPIO_Pin_11|GPIO_Pin_13;
  122.      GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  123.      GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  124.      GPIO_Init(GPIOD, &GPIO_InitStructure);

  125. }

  126. /*********************************************************************
  127.   * @fn      taskSample
  128.   *
  129.   * @brief   taskSample program.
  130.   *
  131.   * @return  none
  132.   */
  133. UINT32 taskSample(VOID) {
  134.      UINT32 uwRet;
  135.      UINT32 taskID1, taskID2, taskID3;
  136.      TSK_INIT_PARAM_S stTask = { 0 };
  137.      stTask.pfnTaskEntry = (TSK_ENTRY_FUNC) taskSampleEntry1;
  138.      stTask.uwStackSize = 0X500;
  139.      stTask.pcName = "taskSampleEntry1";
  140.      stTask.usTaskPrio = 6;/* 高优先级 */
  141.      uwRet = LOS_TaskCreate(&taskID1, &stTask);
  142.      if (uwRet != LOS_OK) {
  143.          printf("create task1 failed\n");
  144.      }

  145.      stTask.pfnTaskEntry = (TSK_ENTRY_FUNC) taskSampleEntry2;
  146.      stTask.uwStackSize = 0X500;
  147.      stTask.pcName = "taskSampleEntry2";
  148.      stTask.usTaskPrio = 7;/* 低优先级 */
  149.      uwRet = LOS_TaskCreate(&taskID2, &stTask);
  150.      if (uwRet != LOS_OK) {
  151.          printf("create task2 failed\n");
  152.      }

  153.      stTask.pfnTaskEntry = (TSK_ENTRY_FUNC) taskSampleEntry3;
  154.          stTask.uwStackSize = 0X500;
  155.          stTask.pcName = "taskSampleEntry3";
  156.          stTask.usTaskPrio = 7;/* 低优先级 */
  157.          uwRet = LOS_TaskCreate(&taskID3, &stTask);
  158.          if (uwRet != LOS_OK) {
  159.              printf("create task3 failed\n");
  160.          }
  161. // <a href="https://blog.vpszj.cn" target="_blank">https://blog.vpszj.cn</a>
  162.      EXTI0_INT_INIT();
  163.      return LOS_OK;
  164. }

  165. /*********************************************************************
  166.   * @fn      main
  167.   *
  168.   * @brief   Main program.
  169.   *
  170.   * @return  none
  171.   */
  172. LITE_OS_SEC_TEXT_INIT int main(void)
  173. {
  174.      unsigned int ret;

  175.      NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
  176.      SystemCoreClockUpdate();
  177.      Delay_Init();
  178.      GPIO_INIT();
  179.      USART_Printf_Init(115200);
  180.          
  181.      printf("SystemClk:%d\r\n",SystemCoreClock);
  182.      printf( "ChipID:%08x\r\n", DBGMCU_GetCHIPID() );

  183.      ret = LOS_KernelInit();
  184.      taskSample();
  185.      if (ret == LOS_OK)
  186.      {
  187.          LOS_Start();
  188.      }

  189.      GPIO_WriteBit(GPIOC, GPIO_Pin_1,RESET);

  190.      while (1) {
  191.          __asm volatile("nop");
  192.      }

  193. }


  194. /*********************************************************************
  195.   * @fn      EXTI0_IRQHandler
  196.   *
  197.   * @brief   This function handles EXTI0 Handler.
  198.   *
  199.   * @return  none
  200.   */
  201. void EXTI0_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
  202. void EXTI0_IRQHandler(void)
  203. {
  204.    /* 中断栈使用的是原来调用main设置的值,将中断栈和线程栈分开,这样线程跳中断,中断函数如果嵌套深度较大,不至于
  205.     * 线程栈被压满溢出,但是采用当前方式,线程进中断时,编译器保存到的16个caller寄存器任然压入线程栈,如果需要希
  206.     * 望caller寄存器压入中断栈,则中断函数的入口和出口需要使用汇编,中间调用用户中断处理函数即可,详见los_exc.S
  207.     * 中的ipq_entry例子
  208.     *  */
  209.    GET_INT_SP();
  210.    HalIntEnter();
  211.    if(EXTI_GetITStatus(EXTI_Line0)!=RESET)
  212.    {
  213.      g_VlaueSp= __get_SP();
  214.      printf("Run at EXTI:");
  215.      printf("interruption sp:%08x\r\n",g_VlaueSp);
  216.      HalDisplayTaskInfo();
  217.      EXTI_ClearITPendingBit(EXTI_Line0);     /* Clear Flag */
  218.    }
  219.    HalIntExit();
  220.    FREE_INT_SP();
  221. }
复制代码

其他开源项目推荐推荐阅读


发表于 2023-8-24 03:05:37 IP:中国广东省 中国电信公众宽带
不错,挺好的,感觉板子可以再画小一点
*滑块验证:
您需要登录后才可以回帖 登录 | 立即注册

手机版|小黑屋|国产电子社区 ( 沪ICP备2023018578号-1|

苏公网安备 32011102010465号


)|网站地图

GMT+8, 2024-12-9 10:08 , Processed in 0.057611 second(s), 22 queries , MemCached On.

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表