- Source code link: https://github.com/Community-PIO-CH32V/ch32-pio-projects
- Reference Installation Document:
- PlatformIO Core: https://docs.platformio.org/en/latest/core/installation/index.html
- PlatformIO CH32V: https://pio-ch32v.readthedocs.io/en/latest/installation.html
- CH32V203G6U6-EVT-R0-1v0
- A USB to UART debugger
- A WCH-Link(E)
You can first check if the package manager contains the platformio-core package. If not, you can install using the installation script:
curl -fsSL -o get-platformio.py https://raw.githubusercontent.com/platformio/platformio-core-installer/master/get-platformio.py
python3 get-platformio.py
Install CH32V development environment:
pio pkg install -g -p https://github.com/Community-PIO-CH32V/platform-ch32v.git
Add udev rules and apply (you may need to change GROUP according to the distribution):
curl -fsSL https://raw.githubusercontent.com/platformio/platformio-core/develop/platformio/assets/system/99-platformio-udev.rules | sudo tee /etc/udev/rules.d/99-platformio-udev.rules
cat << EOF | sudo tee -a /etc/udev/rules.d/99-platformio-udev.rules
SUBSYSTEM=="usb", ATTR{idVendor}="1a86", ATTR{idProduct}=="8010", GROUP="plugdev"
SUBSYSTEM=="usb", ATTR{idVendor}="4348", ATTR{idProduct}=="55e0", GROUP="plugdev"
SUBSYSTEM=="usb", ATTR{idVendor}="1a86", ATTR{idProduct}=="8012", GROUP="plugdev"
EOF
sudo udevadm control --reload-rules
sudo udevadm trigger
Add user groups:
- Debian series:
sudo usermod -a -G dialout $USER
sudo usermod -a -G plugdev $USER
- Arch series:
sudo usermod -a -G uucp $USER
sudo usermod -a -G lock $USER
Clone relevant repositories:
git clone https://github.com/Community-PIO-CH32V/platform-ch32v.git
Compile the code using pio:
cd platform-ch32v/examples/hello-world-rt-thread
pio run
Ensure WCH-Link(E) is connected to the SWD debug port, then use pio to flash the image:
pio run --target upload
If the flashing is unsuccessful, you can try manually specifying:
pio run -e your_board --target upload
If you are using the C8T6 series, please ignore this step.
This is because other chips are not included in the default chip list, so we need to add them manually.
You can find the json file corresponding to your board in platform-ch32v/boards
.
cat << EOF | tee -a platformio.ini
[env:your_board]
board = your_board
EOF
- Error: error writing to flash at address 0x00000000 at offset 0x00000000
- This is due to the low firmware version of WCH-Link. (See important-notices).
- Please connect WCH-Link once using the WCH-Link Utility on Windows to automatically update. Currently, this tool is only available for Windows.
- Error: Read-Protect Status Currently Enabled
- This is caused by the chip's write protection being enabled. On Windows, we can use the WCH-Link Utility to disable protection, and on Linux, OpenOCD can be used to disable protection:
cd ~/.platformio/packages/tool-openocd-riscv-wch/bin
./openocd -f wch-riscv.cfg -c init -c halt -c "flash protect wch_riscv 0 last off " -c exit
cd -
Connect to the development board via serial port.
The system should boot up normally, and information should be viewable through the onboard serial port.
The system booted up normally, and information was viewable through the onboard serial port.
Screen recording (from compile to startup):
The MCU shown in the log below is incorrect, as the example hardcodes that string. See main.c#L:65 The DeviceID confirms that it is indeed running on the target board.
\ | /
- RT - Thread Operating System
/ | \ 3.1.3 build Apr 25 2024
2006 - 2019 Copyright by rt-thread team
MCU: CH32V307
SystemClk:96000000
DeviceID: 00000510
www.wch.cn
msh >
Successful: The actual result matches the expected result.
Failed: The actual result does not match the expected result.
Test successful.