Site icon

CH32V003 Programming: How to get started

CH32V003, why so much noise about it?

The CH32V003 is a 10-cent RISC-V microcontroller from WCH. It is a unique and exciting chip for a number of reasons.

First, it is one of the cheapest microcontrollers on the market, making it ideal for cost-sensitive applications. Second, it is based on the RISC-V architecture, which is an open and royalty-free instruction set architecture.

This means that engineers can develop software for the CH32V003 using a variety of tools and compilers.

Technical Spec

This MCU can be used in a wide variety of applications, including consumer electronics, Industrial automation, IoT devices, Wearables, Educational projects

Here are some specific examples of how it could be used:

Here are some additional reasons why engineers should pay attention to the CH32V003:

Overall, it is a compelling microcontroller for engineers to consider. It is affordable, versatile, and easy to use.

Development Setup for CH32V003

Hardware

How to buy the CH32V003 Kit?

In India, you can buy the CH32V003 Development kit from Evelta Electronics.

If you are outside India, you can buy the development board and programmer from Aliexpress. (The website is banned in India).

Or on Tinde the evaluation board it is available

Software

CH32V003 Datasheet and Reference Manual

Check the latest version on WCH Website, sometimes it is difficult to download from Chinese website so I have added download links from my repository.

CH32V003 Development Board
Programmer
MounRiver Studio IDE

How to install MounRiver IDE for CH32V003

The MounRiver IDE is a powerful and easy-to-use IDE for developing applications for the CH32V003 MCU. By following the steps in this blog post, you can install and set up MounRiver IDE for CH32V003 development, create new projects, compile and program your applications, and debug your code.

For Installation follow the steps mentioned below:

Download the latest version of MounRiver IDE. If you are facing any issue in downloading IDE from their website, you an download from here MounRiver IDE V1.9 and upgrade it.

Please note that as per WCH, software support is the best available for Windows OS and good on Linux but for macOS software is very little, so be careful

  1. Windows:
    • Extract the downloaded archive to a location on your computer.
    • Open the MounRiver IDE directory and double-click on the MounRiverIDE.exe file to launch the IDE.
  2. macOS:
    • Extract the downloaded archive to a location on your computer.
    • Open the MounRiver IDE directory and double-click on the MounRiverIDE.app file to launch the IDE.
  3. Linux:
    • Extract the downloaded archive to a location on your computer. Open a terminal and navigate to the MounRiver IDE directory. Run the following command to launch the IDE:
    ./MounRiverIDE

Installation of the MounRiver IDE is quite simple as any other software.

Creating a new project

To create a new project in MounRiver IDE for CH32V003 development, follow these steps:

  1. Click on the File menu and select New > Project.
  2. In the New Project dialog box, select the MounRiver Project and click Next.
  3. In the Project Properties dialog box, enter a name for your project and select the CH32V003 MCU from the Device list.
  4. Click Finish to create the new project.

Compiling and programming your application

To compile and program your application to the CH32V003 MCU, follow these steps:

  1. Click on the Project menu and select Build Project.
  2. Once the project has been compiled successfully, click on the Flash menu and select Download.
  3. In the Download dialog box, select the compiled binary file from the File list and click Open.
  4. Click Download to program the binary file to the CH32V003 MCU.

Debugging your application

To debug your application, follow these steps:

  1. Connect the CH32V003 board to your computer using a USB cable.
  2. Click on the Debug menu and select Start Debugging.
  3. In the Debug perspective, you can set breakpoints, step through your code, and inspect the values of variables.

Compiling and Running Example Code

So, now that we have all the hardware available and MounRiver IDE is installed, we can see how to open, compile and run an existing code example. This will basically complete the “Setting up Development Environment” for CH32V003 programming.

Example codes are available on WCH website and you can download Example Codes, Evaluation Board Design Files, Schematics

Once you download the zip and extract the folder you will get two folders inside, one is EXAM where all example codes are available and another one is PUB, where you find schematic of the evaluation board, user manual, datasheet and reference manual, etc.

EXAM Folder contents

PUB Folder contents

Let us now open one GPIO toggle program and compile and run it.

Go to File>Load

Browse the folder where examples are downloaded.

Chose the GPIO folder

Go inside the folder and double click on the project file to load the project.

Once project is loaded, open the main.c and see the code, it has two main section/functions, GPIO_Toggle_INIT where it configures a particular(D0) GPIO as output, sets its mode as Push-Pull and its speed to 50Mhz(you can set to other speed also like 10MHz.

In the main function, you see System Clock is set, a delay is given to settle the clock and then Printf is initialized so you can print some debug output, you can ignore them for now.

Next is GPIO_Toggle_INIT is called and in while (1) , GPIO write Bit function is called with 250mSec delay.

GPIO_WriteBit function basically is used to set the Pin/Bit high or Low.

Now to built the project, go to Project>>Build Project

Program will be compiled and you will get console output as shown below. If code has no error it will be compiled showing 0 error, 0 warnings and how much memory each section of the code took, see TEXT, DATA, BSS, DEC.

In order to Flash the code, connect the Programmer and development board to the programmer with 3.3V, GND and SWDIO pin. CH32V003 needs only one pin for programming as it is a one-wire programing interface.

To Flash the program go to Flash>>Download

After Flashing is done, you will get console output as shown in the image below. This shows program is flashed successfully and you will see LED blink program working on your development board.

See Blink LED/Toggle GPIO program in the action in the video below:

I hope you have learned how to setup the development environment, compile and run your first program successfully on CH32V003 MCU.


See also:

  1. Setting up the Development Environment for CH32V003: Compile and Run first example code
  2. CH32V003: GPIO as Output
  3. CH32V003: GPIO as Input (Polling, Interrupt)
  4. CH32V003: UART Transmit / Receive data
  5. CH32V003: PWM output with Frequency and Duty Cycle Control
  6. CH32V003: ADC for analog signal measurement
  7. CH32V003: I2C Interface
  8. CH32V003: SPI Interface
  9. CH32V003: Timer Interrupt
  10. CH32V003: How to read 64-bit Unique ID

I am currently working as an embedded systems design consultant and helping companies build custom embedded products, develop test automation solution for their PCB.

If you have any feedback about the blog, you can share in the comments below or you can also contact me directly.

Read more interesting articles on Embedded Systems Design.


Exit mobile version