ARM Cortex-M uses the AAPCS ABI (r0-r12 caller-saved, sp/r13/lr/r14/pc/r15, xPSR). RISC-V uses ILP32 with its own conventions: x0 (zero), x1 (ra), x2 (sp), x8-x9 (s0/fp, s1), x10-x11 (a0-a1, return regs), x12-x17 (a2-a7, args), x18-x27 (s2-s11). If you previously relied on which registers are clobbered by an interrupt, you need to recheck.
Practical consequence: any inline assembly in your STM32 code (often CMSIS-DSP functions or zero-delay busy loops) will not assemble and must be rewritten.For FreeRTOS this means:
portSAVE_CONTEXT / portRESTORE_CONTEXT macros that push the full 32+ register context on the current task's stackrt_interrupt_enter() / rt_interrupt_leave() to enable accurate scheduling statistics.
CH32V307's clock tree differs in two ways from STM32F4:
SystemClock setups. Use it instead of guessing.
If your STM32F4 used FSMC to talk to an external SRAM/NOR/PSRAM, CH32V307's FSMC is largely compatible at the API surface but expects a slightly different timing-pattern layout. The good news: WCH-EVT provides a working FSMC example for 16-bit SRAM and 16-bit NAND.
GPIO is mostly drop-in, but three subtle differences:Third-party library compatibility hurdles:
When porting an STM32 project, walk through this checklist:
startup_ch32v30x.s)ch32v30x.hbsp/wch/ch32v307 and update Kconfig optionsMigration is worth it when:
Stay on STM32 when:
For more WCH RISC-V discussion, see our WCH MCU category. For K1/K3 and broader RISC-V SoC topics, browse the K1 / K3 / OpenWrt categories.
CH32V003 是基于 RISC-V RV32EC 指令集的超低成本 MCU,批量价约 $0.1,主频 48MHz,非常适合替代传统 8 位 MCU(如 STM8S003)。
推荐使用 MounRiver Studio(基于 Eclipse):
#include "ch32v00x.h"
int main(void) { RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD, ENABLE); GPIO_InitTypeDef cfg = {GPIO_Pin_4, GPIO_Speed_50MHz, GPIO_Mode_Out_PP}; GPIO_Init(GPIOD, &cfg); while (1) { GPIO_WriteBit(GPIOD, GPIO_Pin_4, Bit_RESET); Delay_Ms(500); GPIO_WriteBit(GPIOD, GPIO_Pin_4, Bit_SET); Delay_Ms(500); } }更多资料请访问 open-riscv.com 芯片资料专区。
如有更多问题,欢迎在论坛继续讨论或联系 contact@open-riscv.comWCH staff responded with the following guidance:
For developers migrating from STM32 + Keil/STM32CubeIDE to WCH RISC-V:
Step 1: Create project in MRS2 (select chip, peripherals, clock config) Step 2: Export CMakeLists from MRS2 (File -> Export -> CMakeLists) Step 3: Open CMakeLists in CLion Step 4: Configure toolchain: WCHToolChain for compiler, OpenOCD for debugger Step 5: Connect WCH-LinkE debug probe (SWD 2-wire interface) Step 6: Build and debug from CLion| Aspect | STM32 (Keil/CubeIDE) | WCH RISC-V (MRS2) |
|---|---|---|
| IDE | Keil uVision / STM32CubeIDE | MounRiver Studio (MRS2) |
| Architecture | ARM Cortex-M | RISC-V (QingKe RV32IMACF) |
| Debug interface | SWD (ST-Link) | SWD (WCH-LinkE) |
| HAL library | STM32 HAL/LL | WCH Standard Peripheral Library |
| RTOS support | FreeRTOS, ThreadX | FreeRTOS, RT-Thread (both supported) |
| Toolchain | ARM Compiler / GCC | RISC-V GCC (WCHToolChain) |
-march=rv32imac, -mabi=ilp32) and the interrupt controller differences (CLIC vs NVIC).
Source: WCH Forum -- MounRiver Studio + CLion + WCH-LinkE
On CH32V (and every RV32 part from WCH), the trap vector table must be populated at link time with entries that are actual C functions marked as interrupt handlers. STM32's startup files give you pre-named weak aliases like DMA1_Channel4_IRQHandler; on RISC-V there is no such naming convention unless your startup assembly declares it. If you copy an STM32 vector table into a CH32V project, the table entries will point at addresses that the C compiler never emitted, and the first interrupt lands wherever the linker happened to place data.
Three concrete items to verify:If you are moving FreeRTOS or RT-Thread across, the scheduler's context switch is a separate path from the trap entry and both need checking: the software interrupt used for yield must not share the same save frame as the hardware interrupt path unless you deliberately designed it to.
Once that layer is correct the rest of the migration is routine, and the FreeRTOS port notes we published cover the nesting and critical-section specifics that differ from the Cortex-M baseline. For product inquiries, contact contact@open-riscv.com or visit /forum/inquiry