[bsp] wch ch32v307v-r1动态初始化堆内存 (#6849)

#### 为什么提交这份PR (why to submit this PR)
- 修复ch32v307v-r1 board.h 中变量_stack_size未声明BUG
- 提供ch32v307v-r1动态堆内存分配(宏开关)代码
- ch32v307v-r1 MD文档新增烧录方式,作为烧录后无运行结果的替代方案

#### 你的解决方案是什么 (what is your solution)
- 去掉_stack_size未声明变量
- 动态分配内存堆,将堆起始地址放在.bss段结尾,堆结束地址放在.stack段开头[详情](https://club.rt-thread.org/ask/article/001065082e9ae611.html)
- 将烧录工具替换为WCH-LinkUtility

#### 在什么测试环境下测试通过 (what is the test environment)
- 开发工具: RT-Thread Studio
- 测试板卡:ch32v307v-r1评估板
- 烧录工具:WCH-LinkUtility
This commit is contained in:
会飞的诸 2023-01-14 09:50:33 +08:00 committed by GitHub
parent ddccef3a64
commit fec7404506
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 45 additions and 51 deletions

View File

@ -4,7 +4,7 @@
## 1 Introduction ## 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. 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 - Compiling
- Quickly Get Started - 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) ![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 #### 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) ![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 #### 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) ![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 ### 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) ![toolchain](./figures/toolchain.png)
Change Prefix: Change Prefix:
![prefix](./figures/prefix.png) ![prefix](./figures/prefix.png)
@ -122,7 +126,7 @@ Set the tool:
![toolset](./figures/toolset.png) ![toolset](./figures/toolset.png)
#### 3.3.3 Compiling #### 3.3.3 Compiling
The result is shown as below: The result is shown as below:

View File

@ -10,14 +10,14 @@ CH32V307V-R1 是 WCH 推出的一款基于 RISC-V 内核的开发板,最高主
**基本特性:** **基本特性:**
- MCUCH32V307VCT6主频 144MHzFLASH和RAM可配置 - MCUCH32V307VCT6主频 144MHzFLASH RAM 可配置
- LED2个用户 LEDsLED1blueLED2blue - LED2 个,用户 LEDsLED1blueLED2blue
- 按键2个ResetUser 。 - 按键2 ResetUser 。
- USB2个Tpye-C。 - USB2 Tpye-C。
- 网口1个内置 10M PHY。 - 网口1 个,内置 10M PHY。
- 板载 WCH-Link 下载调试工具。 - 板载 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 编译说明 ## 2 编译说明
@ -29,18 +29,18 @@ CH32V307V-R1 是 WCH 推出的一款基于 RISC-V 内核的开发板,最高主
## 3 使用说明 ## 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) 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) 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) 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` 命令,在指定工具链位置的同时直接编译。 4. 并在当前 BSP 根目录下打开 Env 工具并执行 `scons --exec-path=D:\sdk-toolchain-RISC-V-GCC-WCH-1.0.0\bin` 命令,在指定工具链位置的同时直接编译。
5. 编译完成之后会生成 **rtthread.bin** 文件。 5. 编译完成之后会生成 **rtthread.bin** 文件。
![sconscompile](./figures/sconscompile.jpg) ![sconscompile](./figures/sconscompile.jpg)
@ -51,21 +51,25 @@ CH32V307V-R1 是 WCH 推出的一款基于 RISC-V 内核的开发板,最高主
#### 3.1.3 下载 #### 3.1.3 下载
打开 WCH RISC-V MCU ProgrammerTool 下载软件,选择刚刚生成的 **rtthread.bin** 文件,进行下载。 打开 WCH RISC-V MCU ProgrammerTool 下载软件,选择刚刚生成的 **rtthread.bin** 文件,进行下载。
![tool](./figures/tool.png) ![tool](./figures/tool.png)
> 注意这里Chip Mem 设置为224K ROM + 96K RAM。不要以参考手册为准。 > 注意:这里 Chip Mem 设置为 224K ROM + 96K RAM。不要以参考手册为准。
#### 3.1.4 运行结果 #### 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) ![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` 来编译工程。 使用 **VSCode 终端** 敲入命令 `scons -j12 --exec-path=D:\sdk-toolchain-RISC-V-GCC-WCH-1.0.0\bin` 来编译工程。

View File

@ -18,32 +18,18 @@ extern uint32_t SystemCoreClock;
static uint32_t _SysTick_Config(rt_uint32_t ticks) static uint32_t _SysTick_Config(rt_uint32_t ticks)
{ {
NVIC_SetPriority(SysTicK_IRQn,0xf0); NVIC_SetPriority(SysTicK_IRQn, 0xf0);
NVIC_SetPriority(Software_IRQn,0xf0); NVIC_SetPriority(Software_IRQn, 0xf0);
NVIC_EnableIRQ(SysTicK_IRQn); NVIC_EnableIRQ(SysTicK_IRQn);
NVIC_EnableIRQ(Software_IRQn); NVIC_EnableIRQ(Software_IRQn);
SysTick->CTLR=0; SysTick->CTLR = 0;
SysTick->SR=0; SysTick->SR = 0;
SysTick->CNT=0; SysTick->CNT = 0;
SysTick->CMP=ticks-1; SysTick->CMP = ticks - 1;
SysTick->CTLR=0xF; SysTick->CTLR = 0xF;
return 0; 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. * This function will initial your board.
*/ */
@ -53,7 +39,7 @@ void rt_hw_board_init()
_SysTick_Config(SystemCoreClock / RT_TICK_PER_SECOND); _SysTick_Config(SystemCoreClock / RT_TICK_PER_SECOND);
#if defined(RT_USING_USER_MAIN) && defined(RT_USING_HEAP) #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 #endif
/* USART driver initialization is open by default */ /* USART driver initialization is open by default */
#ifdef RT_USING_SERIAL #ifdef RT_USING_SERIAL
@ -75,7 +61,7 @@ void SysTick_Handler(void)
GET_INT_SP(); GET_INT_SP();
/* enter interrupt */ /* enter interrupt */
rt_interrupt_enter(); rt_interrupt_enter();
SysTick->SR=0; SysTick->SR = 0;
rt_tick_increase(); rt_tick_increase();
/* leave interrupt */ /* leave interrupt */
rt_interrupt_leave(); rt_interrupt_leave();

View File

@ -8,7 +8,7 @@
* 2022-08-23 liYony first version * 2022-08-23 liYony first version
*/ */
// <<< Use Configuration Wizard in Context Menu >>> /* <<< Use Configuration Wizard in Context Menu >>> */
#ifndef __BOARD_H__ #ifndef __BOARD_H__
#define __BOARD_H__ #define __BOARD_H__
@ -21,9 +21,9 @@
#define SRAM_SIZE 96 #define SRAM_SIZE 96
#define SRAM_END (0x20000000 + SRAM_SIZE * 1024) #define SRAM_END (0x20000000 + SRAM_SIZE * 1024)
extern int _ebss; extern int _ebss, _susrstack;
#define HEAP_BEGIN ((void *)&_ebss) #define HEAP_BEGIN ((void *)&_ebss)
#define HEAP_END (SRAM_END-_stack_size) #define HEAP_END ((void *)&_susrstack)
void rt_hw_board_init(void); void rt_hw_board_init(void);