Exploring the RISC-V MCU: Avoiding Common Pitfalls

01

Unboxing the CH32V307

Actually, I prepared to play with RISC-V last year, and specifically bought a book <Computer Organization and Design – Hardware/Software Interface> Fifth Edition RISC-V Version. I remember the first time I bought this book was the MIPS version, and now many years have passed…

I posted on a DIY forum, preparing to make a small DIY toy, but I haven’t thought of a target yet. I estimate it should initially be a USB/Network port to multiple serial ports tool.

The selection definitely has to have USB HS interface because FS cannot support multiple serial ports. I used to be a moderator for ST, and I have some ST boards, one of which is a USB HS board that I haven’t used, always feeling that it’s a bit overpriced.

I previously made a microcontroller development board using the CH340 chip, which has very good stability and supports Linux, Mac, and other systems. I am a supporter of Linux, and I would be very happy if it supports macOS.

Since the board I bought is not in mass production, I didn’t bother the sales recommended by WCH, I just placed an order on JLC, and got a board. Introverted people are somewhat lazy and don’t like to deal with others, generally, if it can be bought with money, they won’t waste feelings. Once DIY starts making money, I can order chips myself; otherwise, it’s better to let some platform complete it.

02

The First Pitfall of the Board: Most People Won’t Encounter

The board is equipped with three Type-C connectors, and I thought it was really advanced, but when I plugged it in, there was no power, and I was extremely frustrated. I haven’t dealt with USB power theft for many years, and I feel bullied, but I suspect it’s because PD protocol wasn’t added.

Because last year I downgraded the USB A interface, almost all my chargers and computers at home do not support USB A, all are USB C. This forced me to rummage through old computers and look for USB A to USB C adapters, which is quite troublesome~

Fortunately, I have a wired keyboard with such a cable; I hurriedly brought it back from the company (the miserable life of a coder, to use good things must buy them myself, the company’s entry-level stuff).

I found my ThinkPad from 2014, and it still works. I installed the Mounriver development tool; I am familiar with Eclipse, but since it’s Java-based and consumes memory, I generally don’t like to use it. The IDE I bought now is still Java-based, so I specifically bought a high-memory computer for it, which is a waste not to use. I have already licensed several software, and now I downloaded the official onboard code package to get started.

As a low-level programmer, the first thing to do is to look at the WCH-Link implementation plan and found that the device manager is serial + HID, especially for Linux-compatible software like OpenOCD, which I also played with 12 years ago; it’s an OpenJTAG solution. I didn’t master it well, but my leader, Mr. Lao, played it very well.

Exploring the RISC-V MCU: Avoiding Common Pitfalls

03

The Second Pitfall of the Board: Does This Thing Still Want to Test Me?

I want to light up that blue LED; the program compiled successfully, downloaded successfully, and verified debugging also succeeded, but why isn’t the LED lighting up on such a good board?

I went to check the schematic and found that its design thinking is quite unique, directly connected to the pin header. I searched eight times and couldn’t find how the LED could light up without being connected…

A face of despair looking for answers.

In the document introduction, I found that I need to connect J3 to IO to light it up, which is testing my 20 years of inventory. Buying short circuit blocks and DuPont wires, I never lack money, I have at least eighty.

So, I abandoned the ugly schematic I drew and relied on the board annotations to find PA0 because I couldn’t find where PA0 was on the schematic after looking for a long time (waiting for my web version of the schematic).

After connecting the wire, the LED finally flashed, but that wasn’t my goal.

On the Mounriver website, I saw the entry for the Mac version, downloaded it, and the toolchain was a bit disappointing, but it was enough to use. After all, even if I get an Eclipse, I might not use it; just using make is enough. With such an open tool like OpenOCD, writing my own interface is not a problem.

The document says that OpenOCD depends on libusb. Previously, when I was messing with libusb on Windows, my computer kept acting up, so I’m not too fond of it. Why use libusb for something that can be done with a serial port! I endured it and did a brew update, then brew install libusb. Don’t underestimate the command line; it’s a fantastic productivity tool.

By the way, can’t this document be more detailed? Bringing two cfg files, can’t you bring a shell startup file?

After racking my brains, I indeed remembered I could –help, and had a guess, ./openocd -f wch-risc-v.cfg, the program started stably, the blue light on the development board flashed, the main chip hung up, which means success. It felt really great!

This WCH-Link is done so well; if it could be open-sourced, it would definitely receive world-class praise.

Exploring the RISC-V MCU: Avoiding Common Pitfalls

I used a Type-C to HDMI extension I bought years ago, converted it to USB A, and then connected it to the board using a USB A to USB C cable. I’ve bought quite a few expensive modules before, and the original Apple ones have just the right compatibility.

Let’s have another picture of OpenOCD; seeing this, it’s like a cat seeing a mouse, eating is impossible, but I must play with it.

Info: Listening on port 6666 for TCL connections

Info: Listening on port 4444 for telnet connections

Exploring the RISC-V MCU: Avoiding Common Pitfalls

Looking at these two ports, I think of the days I wrote TCL, too familiar, but now I’ve forgotten everything.

However, since eight serial ports have been integrated, it must let everyone know the power of serial ports. As an expert with 5 years of embedded and 5 years of internet development experience, even a leaf can be a weapon for protection.

My skills are not outdated, who can compete with me, let’s have fun together!
Disclaimer:This article is originally from 21ic forum user icecut. If you need to reprint, please indicate the source.
Friendly Reminder:

Due to recent changes in WeChat public platform push rules, many readers have reported that they did not see updated articles in time. According to the latest rules, it is recommended to click on “Recommended Reading, Sharing, Collecting,” etc., to become a frequent reader.

Recommended Reading:

  • Looking forward! Huawei version of ChatGPT will be released on July 7

  • BYD Xi’an factory suddenly caught fire, cause of fire unknown!

  • Global foundry giants exposed to shut down two factories in mainland, which may affect 28,000 people!
Exploring the RISC-V MCU: Avoiding Common Pitfalls
Exploring the RISC-V MCU: Avoiding Common Pitfalls

Add the Admin WeChat

What exactly is the difference between you and the top engineers?
Join the technical exchange group for face-to-face conversation with experts

Please click 【Looking】 to give the editor a thumbs up~

Exploring the RISC-V MCU: Avoiding Common Pitfalls

Leave a Comment