Repository navigation
[bsp][ch32v003] add CH32V003F4P6-EVT support #11838
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Rbb666
merged 5 commits into
RT-Thread:master
from
cms19859230182-lang:bsp/ch32v003f4p6-evt
Sep 28, 2026
+9,258
−0
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
9e2383c
[bsp][ch32v003] add CH32V003F4P6-EVT support
cms19859230182-lang 95c6d18
[bsp][ch32v003] format the files we wrote
cms19859230182-lang 45c89f0
[bsp][ch32v003] keep the format ignore inside this BSP
cms19859230182-lang 2c49014
[bsp][ch32v003] list the peripherals this board actually runs
cms19859230182-lang f5e3e44
[bsp][ch32v003] trigger and clear the QingKe V2 software interrupt
cms19859230182-lang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| # WCH peripheral library, keep the vendor copy. | ||
| libraries/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| mainmenu "RT-Thread Configuration" | ||
|
|
||
| BSP_DIR := . | ||
|
|
||
| RTT_DIR := ../../../.. | ||
|
|
||
| source "$(RTT_DIR)/Kconfig" | ||
| rsource "board/Kconfig" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| # ch32v003f4p6-evt BSP 说明 | ||
|
|
||
| ## 1 开发板简介 | ||
|
|
||
| CH32V003F4P6-EVT 是 WCH 推出的一款基于 RISC-V 内核的开发板,最高主频为 48MHz。 | ||
|
|
||
| **基本特性:** | ||
|
|
||
| - MCU:CH32V003F4P6,主频 48MHz,Flash 16KB,SRAM 2KB | ||
| - 封装:TSSOP20 | ||
| - USB:1 个 Type-C,只供电 | ||
| - 板上无 WCH-Link,需外接 | ||
|
|
||
| 更多信息请访问 [CH32V003](https://www.wch.cn/products/CH32V003.html) 以及 [openwch/ch32v003](https://github.com/openwch/ch32v003) | ||
|
|
||
| ## 外设支持 | ||
|
|
||
| 本 BSP 目前对外设的支持情况如下: | ||
|
|
||
| | **片上外设** | **支持情况** | **备注** | | ||
| | :----------- | :----------: | :------- | | ||
| | UART | 支持 | USART1,TX PD5,RX PD6。115200,能进 msh,`help` 有回显 | | ||
| | GPIO | 待支持 | | | ||
| | ADC | 待支持 | | | ||
| | SPI | 待支持 | | | ||
| | I2C | 待支持 | | | ||
| | TIM | 待支持 | | | ||
|
|
||
| ### IO 在板级支持包中的映射情况 | ||
|
|
||
| | IO | 板级包中的定义 | | ||
| | --- | -------------- | | ||
| | PD5 | USART1_TX | | ||
| | PD6 | USART1_RX | | ||
| | PD1 | SWDIO | | ||
|
|
||
| ## 2 编译说明 | ||
|
|
||
| 板级包支持 RISC-V GCC 开发环境,以下是具体版本信息: | ||
|
|
||
| | IDE/编译器 | 已测试版本 | | ||
| | ---------- | -------------------- | | ||
| | GCC | WCH RISC-V GCC 8.2.0 | | ||
|
|
||
| ## 3 使用说明 | ||
|
|
||
| > 本章节是为刚接触 RT-Thread 的新手准备的使用说明,遵循简单的步骤即可将 RT-Thread 操作系统运行在该开发板上,看到实验效果。 | ||
|
|
||
| ### 3.1 使用 Env 编译 BSP | ||
|
|
||
| 1. [下载 WCH 编译工具链](https://github.com/NanjingQinheng/sdk-toolchain-RISC-V-GCC-WCH) | ||
| 2. 下载 Env 工具 [最新版本](https://github.com/RT-Thread/env-windows/releases) | ||
| 3. 在当前 BSP 目录下执行 `scons --exec-path=工具链的bin目录` | ||
| 4. 编译完成之后会生成 **rtthread.bin** 文件。默认只打开 UART1。 | ||
|
|
||
| ### 3.2 硬件连接 | ||
|
|
||
| 使用杜邦线连接 WCH-LinkE:3V3–VCC,GND–GND,SWDIO–PD1。不接 SWCLK,不要用 LinkE 的 5V 给板子供电。 | ||
|
|
||
| 串口另外交叉连接:LinkE 的 TX 接板子 PD6,RX 接板子 PD5。 | ||
|
|
||
| ### 3.3 下载 | ||
|
|
||
| 打开 WCH-LinkUtility,Series 选择 CH32V003,选择刚刚生成的 **rtthread.bin** 进行下载。不要勾选 Erase All。 | ||
|
|
||
| > 注意:Chip Mem 不要点 Set。芯片正在运行时直接下载会失败,要先拉住复位再下载。 | ||
|
|
||
| ### 3.4 运行结果 | ||
|
|
||
| 在终端工具里打开 WCH-Link 的串口(115200-8-1-N),复位设备后,可以看到 RT-Thread 的输出信息和 `msh >`。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import os | ||
| Import('RTT_ROOT') | ||
| from building import * | ||
|
|
||
| cwd = GetCurrentDir() | ||
| objs = [] | ||
| for d in os.listdir(cwd): | ||
| path = os.path.join(cwd, d) | ||
| if os.path.isfile(os.path.join(path, 'SConscript')): | ||
| objs = objs + SConscript(os.path.join(d, 'SConscript')) | ||
|
|
||
| Return('objs') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| import os | ||
| import sys | ||
| import rtconfig | ||
| from SCons.Script import * | ||
|
|
||
| if os.getenv('RTT_ROOT'): | ||
| RTT_ROOT = os.getenv('RTT_ROOT') | ||
| else: | ||
| RTT_ROOT = os.path.normpath(os.getcwd() + '/../../../..') | ||
|
|
||
| sys.path = sys.path + [os.path.join(RTT_ROOT, 'tools')] | ||
| try: | ||
| from building import * | ||
| except: | ||
| print('Cannot find RT-Thread root directory, please check RTT_ROOT') | ||
| print(RTT_ROOT) | ||
| exit(-1) | ||
|
|
||
| TARGET = 'rtthread.' + rtconfig.TARGET_EXT | ||
|
|
||
| DefaultEnvironment(tools=[]) | ||
| env = Environment(tools=['mingw'], | ||
| AS=rtconfig.AS, ASFLAGS=rtconfig.AFLAGS, | ||
| CC=rtconfig.CC, CFLAGS=rtconfig.CFLAGS, | ||
| AR=rtconfig.AR, ARFLAGS='-rc', | ||
| LINK=rtconfig.LINK, LINKFLAGS=rtconfig.LFLAGS) | ||
| env.PrependENVPath('PATH', rtconfig.EXEC_PATH) | ||
|
|
||
| Export('RTT_ROOT') | ||
| Export('rtconfig') | ||
|
|
||
| objs = PrepareBuilding(env, RTT_ROOT, has_libcpu=False) | ||
| DoBuilding(TARGET, objs) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| from building import * | ||
|
|
||
| cwd = GetCurrentDir() | ||
| src = Glob('*.c') | ||
| group = DefineGroup('Applications', src, depend=[''], CPPPATH=[cwd]) | ||
| Return('group') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| /* | ||
| * Copyright (c) 2006-2026, RT-Thread Development Team | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| * Change Logs: | ||
| * Date Author Notes | ||
| * 2026-09-25 seteiro CH32V003F4P6-EVT | ||
| */ | ||
|
|
||
| #include <rtthread.h> | ||
|
|
||
| int main(void) | ||
| { | ||
| rt_kprintf("MCU: CH32V003F4P6\n"); | ||
| while (1) | ||
| { | ||
| rt_thread_mdelay(1000); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| menu "Hardware Drivers Config" | ||
|
|
||
| config SOC_CH32V003F4 | ||
| bool | ||
| select ARCH_RISCV | ||
| select SOC_RISCV_FAMILY_CH32 | ||
| default y | ||
|
|
||
| config BSP_USING_UART | ||
| bool | ||
| select RT_USING_SERIAL | ||
| default y | ||
|
|
||
| config BSP_USING_UART1 | ||
| bool | ||
| default y | ||
|
|
||
| endmenu |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| from building import * | ||
|
|
||
| cwd = GetCurrentDir() | ||
| src = Split(''' | ||
| board.c | ||
| drv_usart.c | ||
| nano_libc.c | ||
| software_irq.c | ||
| startup_ch32v00x.S | ||
| ''') | ||
| path = [cwd] | ||
| group = DefineGroup('Drivers', src, depend=[''], CPPPATH=path) | ||
| Return('group') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| /* | ||
| * Copyright (c) 2006-2026, RT-Thread Development Team | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| * Change Logs: | ||
| * Date Author Notes | ||
| * 2026-09-25 seteiro CH32V003F4P6-EVT: SysTick on the QingKe V2 PFIC | ||
| */ | ||
|
|
||
| #include "board.h" | ||
| #include <rtthread.h> | ||
|
|
||
| #ifdef BSP_USING_UART | ||
| #include "drv_usart.h" | ||
| #endif | ||
|
|
||
| extern uint32_t SystemCoreClock; | ||
|
|
||
| static uint32_t _SysTick_Config(rt_uint32_t ticks) | ||
| { | ||
| NVIC_SetPriority(SysTicK_IRQn, 0xf0); | ||
| NVIC_SetPriority(Software_IRQn, 0xf0); | ||
| NVIC_EnableIRQ(SysTicK_IRQn); | ||
| NVIC_EnableIRQ(Software_IRQn); | ||
| SysTick->CTLR = 0; | ||
| SysTick->SR = 0; | ||
| SysTick->CNT = 0; | ||
| SysTick->CMP = ticks - 1; | ||
| SysTick->CTLR = 0xF; | ||
| return 0; | ||
| } | ||
|
|
||
| void rt_hw_board_init(void) | ||
| { | ||
| _SysTick_Config(SystemCoreClock / RT_TICK_PER_SECOND); | ||
|
|
||
| #if defined(RT_USING_USER_MAIN) && defined(RT_USING_HEAP) | ||
| rt_system_heap_init((void *)HEAP_BEGIN, (void *)HEAP_END); | ||
| #endif | ||
| #ifdef BSP_USING_UART | ||
| rt_hw_usart_init(); | ||
| #endif | ||
| #ifdef RT_USING_CONSOLE | ||
| rt_console_set_device(RT_CONSOLE_DEVICE_NAME); | ||
| #endif | ||
| #ifdef RT_USING_COMPONENTS_INIT | ||
| rt_components_board_init(); | ||
| #endif | ||
| } | ||
|
|
||
| void SysTick_Handler(void) __attribute__((interrupt())); | ||
| void SysTick_Handler(void) | ||
| { | ||
| GET_INT_SP(); | ||
| rt_interrupt_enter(); | ||
| SysTick->SR = 0; | ||
| rt_hw_usart_rx_poll(); | ||
| rt_tick_increase(); | ||
| rt_interrupt_leave(); | ||
| FREE_INT_SP(); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| /* | ||
| * Copyright (c) 2006-2026, RT-Thread Development Team | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| * Change Logs: | ||
| * Date Author Notes | ||
| * 2026-09-25 seteiro CH32V003F4P6-EVT: 16KB flash, 2KB RAM | ||
| */ | ||
|
|
||
| #ifndef __BOARD_H__ | ||
| #define __BOARD_H__ | ||
|
|
||
| #include "ch32v00x.h" | ||
| #include <rthw.h> | ||
|
|
||
| #define SRAM_SIZE 2 | ||
| #define SRAM_END (0x20000000 + SRAM_SIZE * 1024) | ||
|
|
||
| extern int _ebss; | ||
| extern int _susrstack; | ||
| #define HEAP_BEGIN ((void *)&_ebss) | ||
| #define HEAP_END ((void *)&_susrstack) | ||
|
|
||
| #define GET_INT_SP() asm volatile("csrrw sp,mscratch,sp") | ||
| #define FREE_INT_SP() asm volatile("csrrw sp,mscratch,sp") | ||
|
|
||
| void rt_hw_board_init(void); | ||
|
|
||
| #endif |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.