Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How is the flash programmed? #3

Open
jonsmirl opened this issue Oct 26, 2022 · 21 comments
Open

How is the flash programmed? #3

jonsmirl opened this issue Oct 26, 2022 · 21 comments

Comments

@jonsmirl
Copy link

Does CH32V003 the on-chip boot code have the ability to flash the device, or is the only way to flash a new CH32V003 is via SWD? We would like to attach this chip to a larger CPU and allow that larger CPU to update the flash in the CH32V003.

@fukunlab
Copy link
Contributor

fukunlab commented Nov 3, 2022

Unfortunately WCH_Link (SDI) and BOOT protocol is not open, WCH_Link (SDI) but not SWD is the only way to flash CH32V003.

@jonsmirl
Copy link
Author

jonsmirl commented Nov 3, 2022

We are using OTP chips currently. I wanted to evaluate switching to this chip to allow updating of our code. But we can't achieve that without the larger host CPU having some way to reflash the chip while in-circuit. Manufacturing is also an issue, the host CPU needs to initially flash the chip.

@jonsmirl
Copy link
Author

jonsmirl commented Nov 3, 2022

Apparently Mounriver has released the protocol. https://github.com/kprasadvnsi/riscv-openocd-wch
But this is not in a form where it can be used by a host CPU. Additional work is needed to extract out a minimal flash programming library.

@martinribelotta
Copy link

A reverse inginering of WCH (ch32v) SWD protocol is made by @fxsheep here https://github.com/fxsheep/openocd_wchlink-rv/wiki/WCH-RVSWD-protocol
The flash algorithm for varios wch parts was found in @kprasadvnsi repo on https://github.com/kprasadvnsi/riscv-openocd-wch/blob/master/src/jtag/drivers/wlink.c#L110-L337
Maybe a new openocd with ch32v003 support is required but the MounRiver guys are receptive if you send an e-mail to [email protected]
But this require a lot of work for obtain a full floss toolchain to work...

@jonsmirl In my view, you have two ways to go:

  • Obtain a wlink and sniff the SWDIO during programming (hard way)
  • Implement a bit-bypass in your host cpu using one SWDIO input to the wlink cable and the slaves ch32v003 SWDIO pins

@jonsmirl
Copy link
Author

jonsmirl commented Nov 3, 2022

This is for a commercial product, so we don't have the luxury of spending a lot of time on open source code development. If there is no simple solution to the host being able to flash the chip we'll just continue using Padauk OTP parts which are not upgradable.

@fukunlab
Copy link
Contributor

fukunlab commented Nov 4, 2022

@jonsmirl So the product is

1. using a large host CPU is MCU to flash slave CH32V003, the host and slave MCU on the same PCB board. And you want to use host CPU loading programmer to CH32V003 by ETH , WIFI etc. at real time .
Ans: Write a private protocol ISP
2. The host CPU or MCU characters a load programmer tools. CH32V003 is the only MCU on the PCB board.
Ans: Use WCH_Link, data transfer just one-wire completed loading , thus three pad (VCC, GND, DATA)should be reserved on the PCB board. If there no PC to do that, WCH have a loading tools with out PC

@martinribelotta
Copy link

If there no PC to do that, WCH have a loading tools with out PC

That sound interesting... some plans to publish this with the regular HAL/Examples?

@martinribelotta
Copy link

An other cuestio:

Is ok if I make a reverse engineering of the CH32V3xx and CH32V003xx SWD/SDI protocol?

@josuah
Copy link

josuah commented Nov 28, 2022

Here is another discussion with multiple engineers interested in an open-source tool-chain to program the chips:

https://www.eevblog.com/forum/microcontrollers/wch-$0-10-risc-v-mcu/?all

@claudioolmedo
Copy link

Is it possible to use another CH32V3xx made with serial communication firmware to record another CH32V3xx?
If it's that cheap you can have two chips for low-cost denveloper boards.
Without having to buy the official WCH-LinkE, can anyone confirm if it's possible?

@jonsmirl
Copy link
Author

WCH Link clones are $1.20.
https://www.aliexpress.us/item/3256804314210866.html

@fxsheep
Copy link

fxsheep commented Feb 17, 2023

Since RVSWD is a synchronous protocol, I think it can be implemented as a custom transport+ bitbang driver in OpenOCD and reuse existing bitbang SWD hardware. This possibly reduces cost to 0.

@martinribelotta
Copy link

From Patrik twitter:
image

If you can wait, they will post the documentation of the 1-wire swd protocol

@zoobab
Copy link

zoobab commented Feb 21, 2023

There is now a simple libusb program minichlink to flash it:

https://github.com/cnlohr/ch32v003fun

@andelf
Copy link

andelf commented Feb 28, 2023

Checkout https://github.com/ch32-rs/wlink 😝

@Dreagonmon
Copy link

It seems the recent commit contains an example implement of using the one-wire procotol: https://github.com/openwch/ch32v003/tree/main/CH32V003_1Line_Base_on_CH32F103

@perigoso
Copy link

Checkout https://github.com/ch32-rs/wlink stuck_out_tongue_closed_eyes

ooh that might be handy, I'm planning to implement this debug protocol in Black Magic Debug, see blackmagic-debug/blackmagic/pull/1399, though for now I'm only working on the undocumented RVSWD (see also https://perigoso.github.io/rins and https://github.com/perigoso/sigrok-rvswd for RVSWD related things)

@yrabbit
Copy link

yrabbit commented Apr 13, 2023

WCH Link clones are $1.20. https://www.aliexpress.us/item/3256804314210866.html

These are indeed cheap clones, but they are Link clones that cannot program the ch32v003 - you need LinkE for that

@krasin
Copy link

krasin commented Jun 10, 2023

FIY: https://github.com/aappleby/PicoRVD is an example of how to flash CH32V003 from an RP2040. The code is fully open-source and should theoretically be adaptable to other uses, such as a host MCU flashing a peripheral CH32V003.

@mrx23dot
Copy link

Any WCH-Link alternatives support debugging over openocd?
The official WCH-Link is slow as hell.

@qiyongshuang
Copy link
Collaborator

I noticed that there is an USART_IAP program in EVT(CH32V003EVT\EVT\EXAM\USART_IAP).The program is placed in the BOOT area. We can use the USART port to write Flash.

kholia pushed a commit to kholia/ch32v003 that referenced this issue Jul 11, 2024
Update README: add libusb package
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests