As I mentioned It took me quite a few days to get all of the information together to evaluate using the Moun River IDE to develop and upload code to WCH Risc-V MCUs such as the WCH32V003 and CH32V103. So I hope to present the challenges and solutions I found in one single place so that others may avoid the delay.

To start - there is no current support for these MCU in the Arduino IDE...

   [ CORRECTION June 18 '23 ] - WCH just released a package for the Arduino IDE

 which is what I am most familiar with.   BUT it uses the Link boards to upload - there is no serial bootloader so I am getting nowhere fast.

 WCH is the inventor of these modules (at least to us English speakers).  They may be familiar as the company behind the CH340G USB-UART chip used on many early Arduinos.  They have a high level of competence designing USB chips.  Lately they have released a full line of RISC-V based MCUs, most of which feature a native USB interface.  These chips caught my attention for their low-cost - less than a Canadian Quarter - in low quantities for the lower end chips.  RISC-V is royalty-free as opposed to ARM, or AVR which is owned by MicroChip. The WCH line follows the STM line of ARM MCUs and in many cases there is a direct correspondence between the part numbers.

So, to begin I ordered a WCH32V003 and a WCH32V103 as well as the WCH-LinkE which is similar to a USBASP in the Arduino world and supposedly necessary to program at least the smaller of these 2 modules. It claims to be able to do emulation as well...

WCH recommends using the Moun River Eclipse based IDE for software development - it's free so while I was waiting for the hardware to arrive I downloaded and installed it... (Not to worry - (there is an "English" link in the upper right of the webpage).  So far.. so smooth...  ( see my "Instructions", you need to install the toolchain separately ).... but not easy to do a search for this company...  Search engines assume that you mean Moon River (and they do not have https::)..  Installation was quite straight forward on my Ubuntu 23.04 Linux system.

After that came the head scratching - Where to get examples, how to config the IDE for these particular boards etc..  The answer came from the WCH github. I received the "003" board first and found the Repository has a wealth of information. As in any first try on an MCU I wanted to make an LED Blink.  In the GPIO sub directory, as for the other examples, you will find a ".wvprog" file that contains the necessary information to start complilng the Toggle GPIO example.

Actually it would be much better to clone the whole repository, using git clone https://github.com/openwch/ch32v003.git..  OR - even MUCHER better - the IDE supports importing projects directly from github,,,

I found compiling to be as expected...  see my discussion on writing code for these MCUs...

BUT - I came to grief when it comes to uploading... I could not get the W-LinkE driver to work correctly. The W-Link supports 2 modes - Flash mode or Serial mode - which seems like a great idea...  You could upload via the SWC ISP and then monitor output from the serial port from the W-Link...

When I first connected the W-Link to USB a red LED lit up.  This indicated that it is in flash mode..  To switch to serial mode, power off.. hold down the ModeS button and power on.  You should see a blue led lit, indicating serial mode.  Te verify driver installation you could do a ls /dev/ttyA* and look for a ttyACMx file which is how direct USB serial ports appear in Linux. You can also do a lsusb to see if the W-Link has been recognized.

In my case the driver was loaded and the device recognized when in serial mode but nothing happened i flash mode.  A /dev/ch3v?? device never showed. ( I actually put a condom on my mouse and gave my keyboard a shot and connect a HD with Windows 10 and tried this ) - it seemed to work - Win10 does a song and dance as USB drivers get loaded and unloaded....  and in fact both the red and blue LEDs were lit..  MounRiver displayed a "DownLoad" button.

When I rebooted into Linux with both LEDs lit it complained bitterly about not being able to enumerate the USB devices..

so I intend to raise an issue on the openwch github referencing this hackaday...

June 18 2023 - the saga continues...

I ordered 2 more Link boards and someone loaned me a LapTop with Windows 10.....   And managed to brick all 2 of my Links (2 x LinkE and 1 LinkR)..  Under Win 10 both MRS and the Utility program recognized the Link boards BUT INSISTED on upgrading their firmware from 2.7 to 2.8..  Having no choice I allowed this to happen - the upload went smoothly BUT the result is a bricked Link board.  MRS will not recognize the Link and the Utility program crashes and Windows closes it.  According to the documentation this could be remedied by using 2-Wire jtag to upload the appropriate firmware.  BUT, of course you need a functioning Link to do this...  (chicken or egg?).

   ---- to be continued.... I have raised a new more specific issue on the WCH github.

.... moving on - I reeived the additional hardware and when I took a look at the Moun River webpage I noticed that the had a newer version of both MRS and the ToolChain.  I downloaded both ....  and.... Voila...  It seems to work perfectly on Linux - both Ubuntu 23.04 and Mint 21...  I am now happily programming he little -003 board.  As I mentioned one of my goals is to write a serial bootloader,  The little -003 only has 1 serial port and no USB ports to I need a way to debug seeing as the project involves using the serial port.  So I dug out a bit banged 7 Segment Tube driver I had written for the ATTiny10..  Bits is bits - didn't take long to get it working...  Drop me a note if interested..  So far I have had success with the serial port and the GPIO pins.  I came to grief with I2C - needs more work.  Also need to figure out the Reset switch...  Doesn't work...  Think I need to dig into the RCC init.

I do like the way the EVT EXAMs on the github come complete - they all seem to include RCC init, Serial/printf init and GPIO init...  Gets one off to a good start...

Still need to check out the -103 board (maybe I bricked it as well) - I also have a -203 board stuck in Canada Customs..

I finally got my remaining hardware - I have to say that I am more than pleased...  I will be closing out this blog as completed....  With the following takeaways...

The boards other than the -003 have a "code lockout" mechanism - they can be unlocked from within the MRS IDE.  I believe there is also a stand-alone program to do this in Windows - (being a Linux bigot this does me no good).

Boards that re faithful to the original WCH designs have LED(s) but they are not connect to any GPIOs - they are brought out to pins that can be jumpered to any GPIO you wish to use.

I will be posting example code of my continuing journey on my github.  Hope to see you there.