CH32V003 code not running - Page 1
Forum section: electronics / general

author: hackman
author_rank: Newbie
timestamp: August 08, 2025, 07:41:14 am
content: I have two types of CH32V003 board with the 20 pin ssop chip.One board has a crystal oscillator, the other uses the internal oscillator.I can program both boards with the demo GPIO code supplied with Mounriver Studio and they both work as expected.The board using the internal oscillator has a pushbutton and pulldown resistor on PC0.If I remove the resistor, the code stops running, replace it and the board works again.If I reprogram the board without the resistor, the code runs as long as the board is powered. Disconnect and reconnect the power and things are dead again.If I replace the resistor the code runs again .I have been trawling the data sheet looking for any relevant info, if anybody can give me a clue what is going on I would appreciate it.Edit, I should have added, the demo code supplied just sends some info about the chip via the uart and toggles a pin.

author: brucehoult
author_rank: Super Contributor
timestamp: August 08, 2025, 09:51:46 am
content: If the switch is NO and there is no resistor then if its actually configured as an input it will be floating and all kinds of bad things can happen, possibly including triggering a lot of interrupts.Does the demo code, or any HAL that it uses, configure that pin at all?

author: hackman
author_rank: Newbie
timestamp: August 08, 2025, 11:03:21 am
content: I will have another look at the demo code and see exactly what it is doing.The code I tried first configured GPIOC as all inputs with pullups enabled, that is how I discovered the pulldown on PC0.Removed the resistor (the switch is NO) and my code stopped working, that is when I tried the demo code and it behaves exactly the same.I will try putting a pullup on PC0 and see what happens but none of the other pins with internal pullups on GPIOC are causing problems.

author: hackman
author_rank: Newbie
timestamp: August 08, 2025, 11:57:23 am
content: After a quick test run (subject to a longer, more comprehensive test), it seems that either an external pullup or pulldown resistor fixes the problem.Doing a simple pin toggle on GPIOD with no reference to GPIOC at all still fails without the resistor on PC0.I have tested five of these boards and they all fail the same way.The other type of boards I have all function perfectly ok with the same code and no resistor.I will put it down to weirdness unless anyone has a rational explanation.Other than that, after my first try, I am impressed with these chips, they are easy to use and come with a development system that runs on Linux.I know people bash most of the manufacturer provided libraries and ide's but if the primary aim is to just get something working, then this one works ( apart from the odd glitch)

author: brucehoult
author_rank: Super Contributor
timestamp: August 08, 2025, 12:19:10 pm
content: Do take a look athttps://github.com/cnlohr/ch32funfor an alternative more lightweight set of headers.

author: hackman
author_rank: Newbie
timestamp: August 08, 2025, 12:45:32 pm
content: Thanks, I tried the cnlohr stuff on the weird boards and they fail, tried on the other boards and they work. Super fast programming though, I think I will stick with it.I have a batch of new processors on their way somewhere between the UK and China, when they arrive I will swap the chips on the odd boards and see what happens.

author: snarkysparky
author_rank: Frequent Contributor
timestamp: August 08, 2025, 07:21:51 pm
content: I remember reading somewhere that the code will not run when loaded unless something is checked in the box in software.This might helphttps://community.element14.com/technologies/embedded/b/blog/posts/low-cost-microcontrollers-using-a-ch32v003-risc-v-device

author: HwAoRrDk
author_rank: Super Contributor
timestamp: August 09, 2025, 06:44:12 am
content: Quote from: hackman on August 08, 2025, 07:41:14 amDo you have a link to these boards? Or a schematic? Are these something you bought or made yourself? It would be helpful to know how they are configured.Quote from: hackman on August 08, 2025, 07:41:14 amWhich demo code?This demo code?By the way, that code will be running even the board that has a crystal oscillator on the internal oscillator. By default it setsSYSCLK_FREQ_48MHZ_HSIinsystem_ch32v00x.c. You won't have it running on the external oscillator unless you change to an appropriateSYSCLK_FREQ_*_HSE.Quote from: hackman on August 08, 2025, 07:41:14 amThat really shouldn't be of any consequence when running the above demo code - it shouldn't affect anything. That demo code doesn't configure GPIOC at all, so PC0 will be left in its default state, which - as brucehoult said - is a floating input. The fact it has an external pull-down resistor on it should only make any code that cares to read that pin read a '0' (or if the button is pressed, presumably a '1'). Also, PC0 doesn't have any special alternate function (unlike, e.g. PD7 NRST, PD1 SWIM) so when there's no resistor, it should never affect anything that badly even if its value is flapping about randomly.I suspect something else is going on here.Either the boards aren't configured how you think they are, or you're not dealing with the GPIO pins you think you are.Have you tried fully erasing the chips? Including resetting the option bytes to their default values.

author: hackman
author_rank: Newbie
timestamp: August 09, 2025, 11:41:45 am
content: These are the boardshttps://www.aliexpress.com/item/1005008105615031.htmlAs I said this is my first time trying them and I had about 10 minutes using them before I ran into this problem and there is a huge amount of reading of data sheets between problem and solution.I used minichlink with the -u switch to unbrick the chip and it worked. I have no idea yet what gets reset by this command so some reading of minichlink code is needed.Thanks for all the replies

author: brucehoult
author_rank: Super Contributor
timestamp: August 09, 2025, 01:02:33 pm
content: I don't know that exact board. I have a number of very similar ones from Muse Lab, who I find to be a reliable vendor. I haven't noticed any problems with them, other than that they put the LED on the pin normally used for UART RX, which is fine if you want printf-only (plus LED), but means you have to remap the UART if you want 2-way serial and also LED. It's easy to do, it's just a #if in the header file.https://www.aliexpress.com/item/1005005221751705.html

author: HwAoRrDk
author_rank: Super Contributor
timestamp: August 09, 2025, 01:54:02 pm
content: Quote from: hackman on August 09, 2025, 11:41:45 amUgh, yet another cheap development board where the maker/vendor doesn't offer a schematic.Despite what the listing description says, what they're selling is clearlynota "MuseLab NanoCH32V003", just something in the same form-factor and pin arrangement. The actualMuseLab nanoCH32V003isn't the same as this one, because that uses a QFN package version of the MCU, a 3.3V regulator, a 24 MHz crystal, and has a reset button. This AliExpress board has none of those things.What is apparent from the photos however, is the following:- 20-pin TSSOP package.- No voltage regulator.- No external crystal - internal oscillator only. (Do you then have another different board that does have one?)- 5V (-ish) operation. There appears to be a series diode on VBUS from the USB connector, presumably to avoid back-feeding the USB connection when external voltage applied to 'V' pins.- Two LEDs. One appears to be connected to supply voltage. The other it's not clear what it's purpose is. Possibly connected to a GPIO, maybe PC5?- Capacitor to ground on PD7, which makes sense for NRST when relying on the internal pull-up.- A button that is not reset, but indeed appears to be connected to PC0. It appears to pull to ground, so the adjacent connected 10k resistor must be a pull-up.- USB DP/DN pins appear to be connected to something, possibly to PD5/PD6?Which resistor were you messing with, and how exactly? The one next to the button?Quote from: hackman on August 09, 2025, 11:41:45 amIt erases the entire flash memory and resets the option bytes to their default values (which includes disabling read-out protection, disabling any write-protection on all areas of the flash, and enabling the reset pin).

author: brucehoult
author_rank: Super Contributor
timestamp: August 09, 2025, 02:06:14 pm
content: Quote from: HwAoRrDk on August 09, 2025, 01:54:02 pmOh, ugh, I hadn't noticed the description. But I already noted that it's clearly different to my Muse Lab boards. Thanks for your details analysis!I think the WeAct Studio boards are also good, but they cost more againhttps://www.aliexpress.com/item/1005006217778264.html

author: hackman
author_rank: Newbie
timestamp: August 09, 2025, 02:34:15 pm
content: Thanks for the info, the boards served their purpose, I now know a whole heap more about them than I did 24 hours ago and I have the bare chips on their way here.The resistor on PC0 is a pulldown with the button switch connected to V+.One led has the anode connected to V+ via a resistor and cathode connected to PD1, another source of confusion if you try and blink it before finding out what PD1 does.The other led/resistor is just connected across V+ & Gnd