Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions bsp/wch/risc-v/ch32v003f4p6-evt/.clang-format-ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# WCH peripheral library, keep the vendor copy.
libraries/
8 changes: 8 additions & 0 deletions bsp/wch/risc-v/ch32v003f4p6-evt/Kconfig
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"
49 changes: 49 additions & 0 deletions bsp/wch/risc-v/ch32v003f4p6-evt/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# 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)

## 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** 文件。默认只打开 GPIO 和 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 >`。
12 changes: 12 additions & 0 deletions bsp/wch/risc-v/ch32v003f4p6-evt/SConscript
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')
33 changes: 33 additions & 0 deletions bsp/wch/risc-v/ch32v003f4p6-evt/SConstruct
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)
6 changes: 6 additions & 0 deletions bsp/wch/risc-v/ch32v003f4p6-evt/applications/SConscript
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')
20 changes: 20 additions & 0 deletions bsp/wch/risc-v/ch32v003f4p6-evt/applications/main.c
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);
}
}
18 changes: 18 additions & 0 deletions bsp/wch/risc-v/ch32v003f4p6-evt/board/Kconfig
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
12 changes: 12 additions & 0 deletions bsp/wch/risc-v/ch32v003f4p6-evt/board/SConscript
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from building import *

cwd = GetCurrentDir()
src = Split('''
board.c
drv_usart.c
nano_libc.c
startup_ch32v00x.S
''')
path = [cwd]
group = DefineGroup('Drivers', src, depend=[''], CPPPATH=path)
Return('group')
62 changes: 62 additions & 0 deletions bsp/wch/risc-v/ch32v003f4p6-evt/board/board.c
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();
}
30 changes: 30 additions & 0 deletions bsp/wch/risc-v/ch32v003f4p6-evt/board/board.h
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
Loading
Loading