I will be experimenting with a RISC-V microcontroller from WCH that is in the CH32V003…
- User
I will be experimenting with a RISC-V microcontroller from WCH that is in the CH32V003 family. I am interested in using more than one of these CH32V chips in a single device and want to use a larger "master microcontroller" to program the flash of the CH32V chips. It is my understanding that the CH32V has a dedicated boot loader built-in "System Flash" from the factory. The chip also has 16KB of "user flash" for the application.
I want to be able to automate the process of programming the CH32V chips after they are all integrated onto the PCB. I want to use a custom bootloader that determines the position of each chip on the board (using discreet voltages on an ADC pin) and programs each chip according to its role in the circuit.
This means that I need to have broad flexibility in the following areas:
- I need to be able to put a temporary staging bootloader in the user flash. Then...
- I need to be able to boot from this bootloader and communicate with the master microcontroller to program the rest of the chip.
Ideally, as part of step 2, I would like to be able to overwrite the factory bootloader (from the temporary staging bootloader in user flash) with my official bootloader then use my official bootloader to load the application in the user flash.
If this (ideal setup) doesn't work, I would have to be able to use my staging bootloader to load the application in the user flash.
Has anyone been able to figure out a way to replace the bootloader built into the CH32V?
Can this replacement be done in the final circuit?
Can this replacement be done from the user flash?
Assistant
It looks like replacing the factory bootloader on the CH32V microcontrollers should be possible, but it may require some effort. Here are some key points:
-
The CH32V has a read-only "System Flash" that contains the factory bootloader. This cannot be directly overwritten.
-
The CH32V has a "User Flash" section that can be programmed by the user. A custom bootloader can be loaded into this flash.
-
The CH32V has a BOOT0 pin that can be used to select which flash section to boot from - System Flash (factory bootloader) or User Flash (custom bootloader).
-
To replace the factory bootloader:
- Load a custom "staging" bootloader into the User Flash
- Set BOOT0 to boot from User Flash
- Have the staging bootloader communicate with the master microcontroller
- The master can then program the System Flash with the official custom bootloader
- Set BOOT0 back to boot from System Flash
- The custom bootloader in System Flash will now boot and can load the main application into User Flash
So in summary, it should be possible to overwrite the factory bootloader, but it requires temporarily booting a custom staging bootloader from User Flash, then having that staging bootloader reprogram the System Flash. Once the System Flash is reprogrammed, BOOT0 needs to be set back to boot from System Flash to use the new custom bootloader.
The key steps would be:
- Load staging bootloader into User Flash
- Set BOOT0 to boot from User Flash
- Have staging bootloader communicate with master to program System Flash
- Set BOOT0 to boot from System Flash
- Use new custom bootloader in System Flash to load application into User Flash
I hope this helps outline the basic steps needed to replace the factory bootloader on the CH32V microcontrollers! Let me know if you have any other questions.
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.