diff --git a/bsp/wch/risc-v/ch32v307v-r1/README.md b/bsp/wch/risc-v/ch32v307v-r1/README.md index fdf31b56a9..d77a79445a 100644 --- a/bsp/wch/risc-v/ch32v307v-r1/README.md +++ b/bsp/wch/risc-v/ch32v307v-r1/README.md @@ -4,7 +4,7 @@ ## 1 Introduction -CH32V307V-R1 is a RISC-V core-based development board with a maximum main frequency of 144Mhz. It delivers the best value for developers to try and get started with RISC-V architecture. +CH32V307V-R1 is a RISC-V core-based development board with a maximum main frequency of 144Mhz. It delivers the best value for developers to try and get started with RISC-V architecture. This document records the execution instruction of the BSP (board support package) provided by the RT-Thread community for the CH32V307V-R1 development board. @@ -14,7 +14,7 @@ The document is covered in three parts: - Compiling - Quickly Get Started -By reading the Quickly Get Started section developers can quickly get their hands on this BSP and run RT-Thread on the board. +By reading the Quickly Get Started section developers can quickly get their hands on this BSP and run RT-Thread on the board. ![board](./figures/ch32v307.jpg) @@ -59,11 +59,11 @@ Use a data cable to connect the onboard wch-link to the PC, and turn on the powe #### 3.1.3 Download -Open the WCH RISC-V MCU ProgrammerTool, select the **rtthread.bin** file that we just generated, and download it. +Open the WCH RISC-V MCU ProgrammerTool, select the **rtthread.bin** file that we just generated, and download it. ![tool](./figures/tool.png) -> Note that Chip Mem here is set to 224K ROM + 96K RAM. +> Note that Chip Mem here is set to 224K ROM + 96K RAM. #### 3.1.4 Running Result @@ -71,6 +71,10 @@ In the terminal tool, open the onboard wch-link serial port (WCHDapLink SERIAL, ![end](./figures/end.png) +#### 3.1.5 If no running result + +Replace download tool with WCH-LinkUtility. +[Details](https://club.rt-thread.org/ask/article/44e5b4bc129ff373.html) ### 3.2 Use VSCode to edit and compile the project @@ -114,7 +118,7 @@ Copy the compilation chain path into the Toolchain path: ![toolchain](./figures/toolchain.png) -Change Prefix: +Change Prefix: ![prefix](./figures/prefix.png) @@ -122,7 +126,7 @@ Set the tool: ![toolset](./figures/toolset.png) -#### 3.3.3 Compiling +#### 3.3.3 Compiling The result is shown as below: diff --git a/bsp/wch/risc-v/ch32v307v-r1/README_zh.md b/bsp/wch/risc-v/ch32v307v-r1/README_zh.md index 2245f789ec..92c92f1cbe 100644 --- a/bsp/wch/risc-v/ch32v307v-r1/README_zh.md +++ b/bsp/wch/risc-v/ch32v307v-r1/README_zh.md @@ -10,14 +10,14 @@ CH32V307V-R1 是 WCH 推出的一款基于 RISC-V 内核的开发板,最高主 **基本特性:** -- MCU:CH32V307VCT6,主频 144MHz,FLASH和RAM可配置 -- LED:2个,用户 LEDs,LED1(blue),LED2(blue)。 -- 按键:2个,Reset,User 。 -- USB:2个,Tpye-C。 -- 网口:1个,内置 10M PHY。 +- MCU:CH32V307VCT6,主频 144MHz,FLASH 和 RAM 可配置 +- LED:2 个,用户 LEDs,LED1(blue),LED2(blue)。 +- 按键:2 个,Reset,User 。 +- USB:2 个,Tpye-C。 +- 网口:1 个,内置 10M PHY。 - 板载 WCH-Link 下载调试工具。 -更多信息和资源请访问[互联型RISC-V单片机 CH32V307](https://www.wch.cn/products/CH32V307.html) 以及 [官网文档资料](https://github.com/openwch/ch32v307) +更多信息和资源请访问[互联型 RISC-V 单片机 CH32V307](https://www.wch.cn/products/CH32V307.html) 以及 [官网文档资料](https://github.com/openwch/ch32v307) ## 2 编译说明 @@ -29,18 +29,18 @@ CH32V307V-R1 是 WCH 推出的一款基于 RISC-V 内核的开发板,最高主 ## 3 使用说明 ->本章节是为刚接触 RT-Thread 的新手准备的使用说明,遵循简单的步骤即可将 RT-Thread 操作系统运行在该开发板上,看到实验效果 。 +> 本章节是为刚接触 RT-Thread 的新手准备的使用说明,遵循简单的步骤即可将 RT-Thread 操作系统运行在该开发板上,看到实验效果 。 -### 3.1 使用Env编译BSP +### 3.1 使用 Env 编译 BSP -本节讲解如何使用Env工具来编译BSP工程。 +本节讲解如何使用 Env 工具来编译 BSP 工程。 -#### 3.1.1 编译BSP +#### 3.1.1 编译 BSP -1. [下载WCH编译工具链](https://github.com/NanjingQinheng/sdk-toolchain-RISC-V-GCC-WCH/archive/refs/tags/V1.0.0.zip) -2. 下载Env工具[最新版本](https://github.com/RT-Thread/env-windows/releases) -3. 下载RT-Thread[最新源码](https://github.com/RT-Thread/rt-thread/archive/refs/heads/master.zip) -4. 并在当前BSP根目录下打开Env工具并执行 `scons --exec-path=D:\sdk-toolchain-RISC-V-GCC-WCH-1.0.0\bin` 命令,在指定工具链位置的同时直接编译。 +1. [下载 WCH 编译工具链](https://github.com/NanjingQinheng/sdk-toolchain-RISC-V-GCC-WCH/archive/refs/tags/V1.0.0.zip) +2. 下载 Env 工具[最新版本](https://github.com/RT-Thread/env-windows/releases) +3. 下载 RT-Thread[最新源码](https://github.com/RT-Thread/rt-thread/archive/refs/heads/master.zip) +4. 并在当前 BSP 根目录下打开 Env 工具并执行 `scons --exec-path=D:\sdk-toolchain-RISC-V-GCC-WCH-1.0.0\bin` 命令,在指定工具链位置的同时直接编译。 5. 编译完成之后会生成 **rtthread.bin** 文件。 ![sconscompile](./figures/sconscompile.jpg) @@ -51,21 +51,25 @@ CH32V307V-R1 是 WCH 推出的一款基于 RISC-V 内核的开发板,最高主 #### 3.1.3 下载 -打开 WCH RISC-V MCU ProgrammerTool 下载软件,选择刚刚生成的 **rtthread.bin** 文件,进行下载。 +打开 WCH RISC-V MCU ProgrammerTool 下载软件,选择刚刚生成的 **rtthread.bin** 文件,进行下载。 ![tool](./figures/tool.png) -> 注意:这里Chip Mem 设置为224K ROM + 96K RAM。不要以参考手册为准。 +> 注意:这里 Chip Mem 设置为 224K ROM + 96K RAM。不要以参考手册为准。 #### 3.1.4 运行结果 -在终端工具里打开板载 wch-link 串口(WCHDapLink SERIAL,默认115200-8-1-N),复位设备后,在串口上可以看到 RT-Thread 的输出信息: +在终端工具里打开板载 wch-link 串口(WCHDapLink SERIAL,默认 115200-8-1-N),复位设备后,在串口上可以看到 RT-Thread 的输出信息: ![end](./figures/end.png) -### 3.2 使用VSCode编译工程 +#### 3.1.5 无运行结果解决方案 -在Env终端中敲入命令 `scons --target=vsc` 来生成VSCode工程. 接着敲入命令 `code .` 来打开VSCode. +将 WCH RISC-V MCU ProgrammerTool 下载软件替换为 WCH-LinkUtility.[详情](https://club.rt-thread.org/ask/article/44e5b4bc129ff373.html) + +### 3.2 使用 VSCode 编译工程 + +在 Env 终端中敲入命令 `scons --target=vsc` 来生成 VSCode 工程. 接着敲入命令 `code .` 来打开 VSCode. 使用 **VSCode 终端** 敲入命令 `scons -j12 --exec-path=D:\sdk-toolchain-RISC-V-GCC-WCH-1.0.0\bin` 来编译工程。 diff --git a/bsp/wch/risc-v/ch32v307v-r1/board/board.c b/bsp/wch/risc-v/ch32v307v-r1/board/board.c index 399c957846..0c74613730 100644 --- a/bsp/wch/risc-v/ch32v307v-r1/board/board.c +++ b/bsp/wch/risc-v/ch32v307v-r1/board/board.c @@ -18,32 +18,18 @@ extern uint32_t SystemCoreClock; static uint32_t _SysTick_Config(rt_uint32_t ticks) { - NVIC_SetPriority(SysTicK_IRQn,0xf0); - NVIC_SetPriority(Software_IRQn,0xf0); + 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; + SysTick->CTLR = 0; + SysTick->SR = 0; + SysTick->CNT = 0; + SysTick->CMP = ticks - 1; + SysTick->CTLR = 0xF; return 0; } -#if defined(RT_USING_USER_MAIN) && defined(RT_USING_HEAP) -#define RT_HEAP_SIZE (4096) -static uint32_t rt_heap[RT_HEAP_SIZE]; -rt_weak void *rt_heap_begin_get(void) -{ - return rt_heap; -} - -rt_weak void *rt_heap_end_get(void) -{ - return rt_heap + RT_HEAP_SIZE; -} -#endif - /** * This function will initial your board. */ @@ -53,7 +39,7 @@ void rt_hw_board_init() _SysTick_Config(SystemCoreClock / RT_TICK_PER_SECOND); #if defined(RT_USING_USER_MAIN) && defined(RT_USING_HEAP) - rt_system_heap_init(rt_heap_begin_get(), rt_heap_end_get()); + rt_system_heap_init((void *) HEAP_BEGIN, (void *) HEAP_END); #endif /* USART driver initialization is open by default */ #ifdef RT_USING_SERIAL @@ -75,7 +61,7 @@ void SysTick_Handler(void) GET_INT_SP(); /* enter interrupt */ rt_interrupt_enter(); - SysTick->SR=0; + SysTick->SR = 0; rt_tick_increase(); /* leave interrupt */ rt_interrupt_leave(); diff --git a/bsp/wch/risc-v/ch32v307v-r1/board/board.h b/bsp/wch/risc-v/ch32v307v-r1/board/board.h index dd6a5b3b2d..4af121813b 100644 --- a/bsp/wch/risc-v/ch32v307v-r1/board/board.h +++ b/bsp/wch/risc-v/ch32v307v-r1/board/board.h @@ -8,7 +8,7 @@ * 2022-08-23 liYony first version */ -// <<< Use Configuration Wizard in Context Menu >>> +/* <<< Use Configuration Wizard in Context Menu >>> */ #ifndef __BOARD_H__ #define __BOARD_H__ @@ -21,9 +21,9 @@ #define SRAM_SIZE 96 #define SRAM_END (0x20000000 + SRAM_SIZE * 1024) -extern int _ebss; +extern int _ebss, _susrstack; #define HEAP_BEGIN ((void *)&_ebss) -#define HEAP_END (SRAM_END-_stack_size) +#define HEAP_END ((void *)&_susrstack) void rt_hw_board_init(void);