Prerequisite:
- Buy the WCH LinkE Emulation Debugger Module from the usual places from China for less than $5. You won't even get to the bootstrap loader on the CH32V003 without one as there are no hardware bootstrap pins. For higher end chips, the bootloader can download from USB using WCHISPTool.
Don't be temped by the cheaper older WCH Link module. It is powered by CH549 (8051 core with 60K FLASH/2K RAM)) It is not useful here but good for hacking it into CMSIS-DAP.LinkE module is the one you want to get. Powered by CH32V305 with 128K FLASH/32K RAM. It supports for the low pin count parts that uses a single wire debug interface e.g. CH32V003 and newer chips e.g. CH32X035.
- Download: WCH-Link Local Burning Tool: WCH-LinkUtility.ZIP from this page. It'll also install a COM port driver.
Select WCH-LinkRV mode, hit Set. The blue LED turns off. This is now the default mode.
Hit Refresh, it now shows up as RISC-V Link.
Note:
- "Enable SDI Printf" option allows you to send debug messages on a virtual serial port piggy back on the SDI debugger interface (i.e. Semihosting). This is useful for low pin count parts. The support functions are described inside debug.h See: https://www.cnblogs.com/liaigu/p/17628184.html (use Chrome for translation)
- WCH-LinkDAP-WINUSB mode is for debugging with CH32F (Arm) series.
- You can flash a new firmware and turning LinkE into a high-speed JTAG bridge similar to CH347 for DSP/FPGA using WCHLinkEJtagUpdTool.ZIP. You'll need to re-flash the LinkE firmware to switch back.
- The instructions below requires Git pre-installed. Git: https://git-scm.com/downloads
Install IDE
- Install Visual Studio Code: https://code.visualstudio.com/
- Optional: Change PlatformIO Install Directory to path other than under your Windows user profile directory.
Reference: https://community.platformio.org/t/vscode-install-directory/12325/2Setting thePLATFORMIO_CORE_DIR
pointing to my folder where the policies allow execution solves the issue. I set this value inside the standard Windows uservariables and then after this run the normal package installation process within VSCode.
Under Windows Advance User Setting/Environment Variable/User variable. The highlighted path is where you want it.
Use Take Ownership on the directory if it is under "program files" to allow for write permission there.
- Install Extension: PlatformIO IDE (C/C++ Extension)
- Go to https://github.com/Community-PIO-CH32V/ch32-pio-projects It is not yet in the official Platform IO, so follow the instructions to install the CH32V Platform.
- Optional: Change default project directory
See https://community.platformio.org/t/how-to-change-default-new-project-location/2828/18
Hit the terminal icon on bottom to bring up this terminal. For some reasons, this one works properly. |
Type in the following and your directory path. Add quotes around the path if there are any spaces.
pio settings set projects_dir your_directory_path
PlatformIO.ini
There is a nasty surprise in the system_ch32v00x.c file. This is part of the startup code that is provided and set the SYSCLK prior to passing control to main().
build_flags = -D SYSCLK_FREQ_24MHZ_HSI
Creating a New Project
- Select Platform IO on the side bar (Ant Icon), hit "Create New Project". Give it a name.
- Select "Generic CH32V003F4P6 (W.CH)" if you are using your own design or "CH32V003F4P6-EVT-R0 (W.CH)" for the eval board.
- There is choice for "Noneos-SDK" for bare metal or "Arduino" platform. The Ch32V003 part is too small for other RTOS platforms.