There are several available boards on the market. This project requires the WCH-LinkE programmer. Labels may say DIO,D1 or PD1 mean the same.
To use either the LED1 or LED2 lamp on this board we need to add a wire to connect them to pin PD0. We use code that toggles hardware GPIO pin 0 of chip PortD.
The WCH-LinkE dongle provides enough 3volt power for our board. Our SWDIO programming pin connects to pin PD1 on the board. We are looking at the back of the USB dongle.
A driver installed in my Windows PC when I installed WCH-Link Utility. If you experience difficulty connecting then check your Windows Device Manger.
Documentation says you can load the WCH-Link driver with Zadig. Linux may require you to add openocd package to your OS. More information on the WCH-LinkE debug probe/programmer.
What is CH32V003?It is an MCU micro-controller unit chip. Numbers and letters at the end are for different chip packages and options. The product webpage shows it to be much like the ATmega328 in your Arduino board.
Download from this page the board manual and reference routine package and you get sample code and pdf documents for your chip.
Open ArduinoIDESave a new sketch called BlinkCH32V003.ino. Arduino IDE uses a high-level programming language called C/C++. It's like algebra with plus, minus, etc. Search the interweb and you will find a lot of code you can use.
Arduino PreferencesMenu File->Preferences. Choose a comfortable font size. Tick boxes for verbose output during compilation and upload. Type this address into Additional Boards Manager URLs:
https://github.com/openwch/board_manager_files/raw/main/package_ch32v_index.json
Click OK to save these changes.
Tools->Boards Manager...Open the Boards Manager. There will be an update to refresh the database.
Search for the CH32V RISC-V boards package. Install will take a while for about 1GByte of software to download.
More info at OpenWCH repository.
Select BoardMenu Tools->Boards->CH32 and select the CH32V00x board. This will work for many RISC-V development boards.
Type in this code. Save the sketch. Because we selected a CH32V00x board we use the alias PD0 for our output pin on PORTD pin0. It is the standard blink example.
void setup() {
pinMode(PD0, OUTPUT); }
void loop() {
digitalWrite(PD0, HIGH);
delay(250);
digitalWrite(PD0, LOW);
delay(250);
}
Select COM PortJust like Arduino. We don't need to select an external programmer. Default settings.
Click the arrow or menu Sketch->Upload and watch the progress at the bottom of the screen. The red/orange text is different from Arduino because it is a different upload software.
There ya go. You should move your LED jumper to different ports and change the code to make the new pin toggle. Change delay times. Make LED blink multiple times.
Experiment with other IO pins. Change delay values, make multiple pins blink.
What's going on?The boards manager package installed a compiler program to generate the output file for a RISC-V processor. Look closely at the output text. We are writing an output elf file to run on our board using a language called rv32eczw.
To program RISC-V chips your Arduino program has added two important programs. Riscv-none-embed-gcc is a C/C++ compiler for RV32E RISC-V programming. Openocd is like avrdude that it uploads to the board, but also a debugging server for your PC.
ArduinoIDE exports hex files for Uno programs. For our RISC-V board it exports a binary that you can upload with WCH-Link Utility or other compatible flash programmer. You will find a .bin file in the Arduino project folder.
On a Linux computer we have to run a shell script to install and configure for WCH boards. Open hidden directory ~/.arduino15/packages/WCH/tools/beforeinstall/1.0.0 which contains start.sh.
Right-click Open Terminal Here and type ./start.sh. You will be prompted for your password.
Restart the computer and you should now be able to upload to a board.
Comments
Please log in or sign up to comment.