Author Topic: CH32V003 code not running  (Read 3315 times)

0 Members and 1 Guest are viewing this topic.

Offline hackmanTopic starter

  • Contributor
  • Posts: 16
  • Country: gb
CH32V003 code not running
« on: August 08, 2025, 07:41:14 am »
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.

 
« Last Edit: August 08, 2025, 08:08:29 am by hackman »
 

Offline brucehoult

  • Super Contributor
  • ***
  • Posts: 6403
  • Country: nz
Re: CH32V003 code not running
« Reply #1 on: August 08, 2025, 09:51:46 am »
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?
 

Offline hackmanTopic starter

  • Contributor
  • Posts: 16
  • Country: gb
Re: CH32V003 code not running
« Reply #2 on: August 08, 2025, 11:03:21 am »
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.
 

Offline hackmanTopic starter

  • Contributor
  • Posts: 16
  • Country: gb
Re: CH32V003 code not running
« Reply #3 on: August 08, 2025, 11:57:23 am »
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)  :)
 

Offline brucehoult

  • Super Contributor
  • ***
  • Posts: 6403
  • Country: nz
Re: CH32V003 code not running
« Reply #4 on: August 08, 2025, 12:19:10 pm »
Do take a look at https://github.com/cnlohr/ch32fun for an alternative more lightweight set of headers.
 

Offline hackmanTopic starter

  • Contributor
  • Posts: 16
  • Country: gb
Re: CH32V003 code not running
« Reply #5 on: August 08, 2025, 12:45:32 pm »
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.
 

Offline snarkysparky

  • Frequent Contributor
  • **
  • Posts: 440
  • Country: us
Re: CH32V003 code not running
« Reply #6 on: August 08, 2025, 07:21:51 pm »
I remember reading somewhere that the code will not run when loaded unless something is checked in the box in software.

This might help

https://community.element14.com/technologies/embedded/b/blog/posts/low-cost-microcontrollers-using-a-ch32v003-risc-v-device
 

Online HwAoRrDk

  • Super Contributor
  • ***
  • Posts: 1919
  • Country: gb
Re: CH32V003 code not running
« Reply #7 on: August 09, 2025, 06:44:12 am »
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.

Do 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.

I can program both boards with the demo GPIO code supplied with Mounriver Studio and they both work as expected.

Which 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 sets SYSCLK_FREQ_48MHZ_HSI in system_ch32v00x.c. You won't have it running on the external oscillator unless you change to an appropriate SYSCLK_FREQ_*_HSE.

The board using the internal oscillator has a pushbutton and pulldown resistor on PC0.

That 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.
 

Offline hackmanTopic starter

  • Contributor
  • Posts: 16
  • Country: gb
Re: CH32V003 code not running
« Reply #8 on: August 09, 2025, 11:41:45 am »
These are the boards https://www.aliexpress.com/item/1005008105615031.html

As 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  :)
 
 

Offline brucehoult

  • Super Contributor
  • ***
  • Posts: 6403
  • Country: nz
Re: CH32V003 code not running
« Reply #9 on: August 09, 2025, 01:02:33 pm »
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
 

Online HwAoRrDk

  • Super Contributor
  • ***
  • Posts: 1919
  • Country: gb
Re: CH32V003 code not running
« Reply #10 on: August 09, 2025, 01:54:02 pm »
These are the boards https://www.aliexpress.com/item/1005008105615031.html

Ugh, 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 clearly not a "MuseLab NanoCH32V003", just something in the same form-factor and pin arrangement. The actual MuseLab nanoCH32V003 isn'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?

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.

It 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).
« Last Edit: August 09, 2025, 01:57:20 pm by HwAoRrDk »
 

Offline brucehoult

  • Super Contributor
  • ***
  • Posts: 6403
  • Country: nz
Re: CH32V003 code not running
« Reply #11 on: August 09, 2025, 02:06:14 pm »
Despite what the listing description says, what they're selling is clearly not a "MuseLab NanoCH32V003", just something in the same form-factor and pin arrangement.

Oh, 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 again

https://www.aliexpress.com/item/1005006217778264.html
 

Offline hackmanTopic starter

  • Contributor
  • Posts: 16
  • Country: gb
Re: CH32V003 code not running
« Reply #12 on: August 09, 2025, 02:34:15 pm »
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
 

Offline evugar

  • Newbie
  • Posts: 1
  • Country: se
Re: CH32V003 code not running
« Reply #13 on: April 24, 2026, 10:20:24 am »
Could you sort out "code not running" issue?
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf