沁恒CH32V307VCT6最小系统板,引出了所有IO口,一个Type-C连接到USB2.0全速OTG接口,一个Flash芯片 型号W25Q64 容量64Mbit 连接到SPI2接口,板上还有TL432电压基准1.25V(实测1.246V左右)可通过跳线连接到PC3的AD13,还有3.29V基准通过0欧电阻可连接到ADC参考电压VREF。
- 画了个 MSP430F149的最小系统板 开源出来了:https://blog.zeruns.tech/archives/713.html
- STM32F030C8T6最小系统板和流水灯(原理图和PCB):https://blog.zeruns.tech/archives/715.html
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
实物图
原理图
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即可 另一个空着。
元件购买地址
- 0805电阻样品本:https://u.jd.com/DzK9k0O
- 0805电容样品本:https://s.click.taobao.com/cTZzzDu
- CH32V307VCT6:https://s.click.taobao.com/5SjzzDu
- W25Q64JV:https://s.click.taobao.com/YAv6NEu
- TL432:https://s.click.taobao.com/t3AzzDu
- WCH-Link:https://s.click.taobao.com/m6KyzDu
- 排针:https://u.jd.com/DbKUBDu
元器件购买推荐立创商城,优惠注册链接: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的代码:
/** Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.** Redistribution and use in source and binary forms, with or without modification,* are permitted provided that the following conditions are met:** 1. Redistributions of source code must retain the above copyright notice, this list of* conditions and the following disclaimer.** 2. Redistributions in binary form must reproduce the above copyright notice, this list* of conditions and the following disclaimer in the documentation and/or other materials* provided with the distribution.** 3. Neither the name of the copyright holder nor the names of its contributors may be used* to endorse or promote products derived from this software without specific prior written* permission.** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.*/#include "debug.h"
#include "los_tick.h"
#include "los_task.h"
#include "los_config.h"
#include "los_interrupt.h"
#include "los_debug.h"
#include "los_compiler.h"/* Global define *//* Global Variable */
__attribute__((aligned (8))) UINT8 g_memStart[LOSCFG_SYS_HEAP_SIZE];
UINT32 g_VlaueSp=0;u8 i = 0,j=0,k=0;/********************************************************************** @fn taskSampleEntry3** @brief taskSampleEntry3 program.** @return none*/
VOID taskSampleEntry3(VOID)
{while(1) {LOS_TaskDelay(2000);printf("taskSampleEntry3 running,task3 SP:%08x\n",__get_SP());GPIO_WriteBit(GPIOD, GPIO_Pin_13, (k == 0) ? (k = Bit_SET) : (k = Bit_RESET));}
}/********************************************************************** @fn taskSampleEntry2** @brief taskSampleEntry2 program.** @return none*/
VOID taskSampleEntry2(VOID)
{while(1) {LOS_TaskDelay(1000);printf("taskSampleEntry2 running,task2 SP:%08x\n",__get_SP());GPIO_WriteBit(GPIOD, GPIO_Pin_12, (j == 0) ? (j = Bit_SET) : (j = Bit_RESET));}
}/********************************************************************** @fn taskSampleEntry1** @brief taskSampleEntry1 program.** @return none*/
VOID taskSampleEntry1(VOID)
{while(1) {LOS_TaskDelay(500);printf("taskSampleEntry1 running,task1 SP:%08x\n",__get_SP());GPIO_WriteBit(GPIOD, GPIO_Pin_11, (i == 0) ? (i = Bit_SET) : (i = Bit_RESET));}}
// https://blog.zeruns.tech
/********************************************************************** @fn EXTI0_INT_INIT** @brief Initializes EXTI0 collection.** @return none*/
void EXTI0_INT_INIT(void)
{GPIO_InitTypeDef GPIO_InitStructure={0};EXTI_InitTypeDef EXTI_InitStructure={0};NVIC_InitTypeDef NVIC_InitStructure={0};RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO|RCC_APB2Periph_GPIOA,ENABLE);GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;GPIO_Init(GPIOA, &GPIO_InitStructure);/* GPIOA ----> EXTI_Line0 */GPIO_EXTILineConfig(GPIO_PortSourceGPIOA,GPIO_PinSource0);EXTI_InitStructure.EXTI_Line=EXTI_Line0;EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;EXTI_InitStructure.EXTI_LineCmd = ENABLE;EXTI_Init(&EXTI_InitStructure);NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn;NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;NVIC_InitStructure.NVIC_IRQChannelSubPriority = 4;NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;NVIC_Init(&NVIC_InitStructure);
}void GPIO_INIT(void) {GPIO_InitTypeDef GPIO_InitStructure = { 0 };RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD, ENABLE);GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12|GPIO_Pin_11|GPIO_Pin_13;GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;GPIO_Init(GPIOD, &GPIO_InitStructure);}/********************************************************************** @fn taskSample** @brief taskSample program.** @return none*/
UINT32 taskSample(VOID) {UINT32 uwRet;UINT32 taskID1, taskID2, taskID3;TSK_INIT_PARAM_S stTask = { 0 };stTask.pfnTaskEntry = (TSK_ENTRY_FUNC) taskSampleEntry1;stTask.uwStackSize = 0X500;stTask.pcName = "taskSampleEntry1";stTask.usTaskPrio = 6;/* 高优先级 */uwRet = LOS_TaskCreate(&taskID1, &stTask);if (uwRet != LOS_OK) {printf("create task1 failed\n");}stTask.pfnTaskEntry = (TSK_ENTRY_FUNC) taskSampleEntry2;stTask.uwStackSize = 0X500;stTask.pcName = "taskSampleEntry2";stTask.usTaskPrio = 7;/* 低优先级 */uwRet = LOS_TaskCreate(&taskID2, &stTask);if (uwRet != LOS_OK) {printf("create task2 failed\n");}stTask.pfnTaskEntry = (TSK_ENTRY_FUNC) taskSampleEntry3;stTask.uwStackSize = 0X500;stTask.pcName = "taskSampleEntry3";stTask.usTaskPrio = 7;/* 低优先级 */uwRet = LOS_TaskCreate(&taskID3, &stTask);if (uwRet != LOS_OK) {printf("create task3 failed\n");}
// https://blog.vpszj.cnEXTI0_INT_INIT();return LOS_OK;
}/********************************************************************** @fn main** @brief Main program.** @return none*/
LITE_OS_SEC_TEXT_INIT int main(void)
{unsigned int ret;NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);SystemCoreClockUpdate();Delay_Init();GPIO_INIT();USART_Printf_Init(115200);printf("SystemClk:%d\r\n",SystemCoreClock);printf( "ChipID:%08x\r\n", DBGMCU_GetCHIPID() );ret = LOS_KernelInit();taskSample();if (ret == LOS_OK){LOS_Start();}GPIO_WriteBit(GPIOC, GPIO_Pin_1,RESET);while (1) {__asm volatile("nop");}}/********************************************************************** @fn EXTI0_IRQHandler** @brief This function handles EXTI0 Handler.** @return none*/
void EXTI0_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
void EXTI0_IRQHandler(void)
{/* 中断栈使用的是原来调用main设置的值,将中断栈和线程栈分开,这样线程跳中断,中断函数如果嵌套深度较大,不至于* 线程栈被压满溢出,但是采用当前方式,线程进中断时,编译器保存到的16个caller寄存器任然压入线程栈,如果需要希* 望caller寄存器压入中断栈,则中断函数的入口和出口需要使用汇编,中间调用用户中断处理函数即可,详见los_exc.S* 中的ipq_entry例子* */GET_INT_SP();HalIntEnter();if(EXTI_GetITStatus(EXTI_Line0)!=RESET){g_VlaueSp= __get_SP();printf("Run at EXTI:");printf("interruption sp:%08x\r\n",g_VlaueSp);HalDisplayTaskInfo();EXTI_ClearITPendingBit(EXTI_Line0); /* Clear Flag */}HalIntExit();FREE_INT_SP();
}
其他开源项目推荐
- SY8205同步降压可调DCDC电源模块(原理图和PCB):https://blog.zeruns.tech/archives/717.html
- 2011年全国电赛题-开关电源模块并联供电系统:https://blog.zeruns.tech/archives/718.html
- 2007年电赛电源题:30到36V可调升压DCDC模块(UC3843):https://oshwhub.com/zeruns/36v-sheng-ya-dcdc-mo-kuai-uc3842
- STC12C5A60S2最小系统板/51单片机温度显示和温度控制风扇:https://blog.zeruns.tech/archives/721.html
- 移植好U8g2图形库的STM32F407标准库工程模板:https://blog.zeruns.tech/archives/722.html
推荐阅读
- 高性价比和便宜的VPS/云服务器推荐: https://blog.vpszj.cn/archives/41.html
- 怎样搭建个人博客:https://blog.zeruns.tech/archives/218.html
- 我的世界服务器搭建教程:https://blog.zeruns.tech/tag/mc/
- STM32读取SHT3x系列温湿度传感器:https://blog.zeruns.tech/archives/700.html
- 使用VSCode代替Keil实现STM32和51单片机的开发:https://blog.zeruns.tech/archives/690.html
- 雨云 美国高防独服 性能测评,8核16G 50兆 200G防御:https://blog.vpszj.cn/archives/1603.html
- 特语云 湖北十堰 高防VPS 性能评测,4核8G 10兆 100G防御:https://blog.vpszj.cn/archives/1523.html