The CH32V003 is the world's most affordable RISC-V microcontroller:
File → New → C Project
→ Select "RISC-V C Project"
→ Chip: WCH CH32V003
→ Debugger: WCH-LinkE
#include "ch32v00x.h"
int main(void) {
// Initialize GPIO
GPIO_InitTypeDef GPIO_InitStruct = {0};
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_2;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOC, &GPIO_InitStruct);
while(1) {
GPIO_SetBits(GPIOC, GPIO_Pin_2);
Delay_Ms(500);
GPIO_ResetBits(GPIOC, GPIO_Pin_2);
Delay_Ms(500);
}
}
Connect WCH-LinkE to the CH32V003 SWD pins:
| WCH-LinkE | CH32V003 |
|---|---|
| SWDIO | PD4 |
| SWCLK | PD1 |
| GND | GND |
| 3V3 | VCC |
wlink flash build/ch32v003.elf
The CH32V003 has a built-in USB 2.0 Full Speed PHY:
#include "ch32v00x_usb.h"
// HID keyboard example - sends "Hello" on button press
void USB_HID_SendKey(uint8_t key) {
// USB HID report endpoint
USBFSD->EP1_TX = key;
USBFSD->INT_FG = USBFS_UIF_EP1_TX;
}
The CH32V003 includes a 2.4G RF transceiver:
#include "ch32v00x_rf.h"
void RF_Init() {
RF_Config_t cfg = {
.channel = 2,
.rate = RF_RATE_1M,
.power = RF_POWER_20DBM,
.addr = 0x12345678
};
RF_Config(&cfg);
}
void RF_Send(uint8_t *data, uint8_t len) {
RF_Tx(data, len);
while(RF_GetStatus() != RF_TX_DONE);
}
wlink erase before flashing