Skip to content
This repository has been archived by the owner on Feb 2, 2024. It is now read-only.

Flash over UART #5

Open
COKPOWEHEU opened this issue Nov 16, 2023 · 13 comments
Open

Flash over UART #5

COKPOWEHEU opened this issue Nov 16, 2023 · 13 comments

Comments

@COKPOWEHEU
Copy link

It would be nice to implement programming via UART.
I can implement this myself, but right now your code is very cohesive. You will have to tear off all references to the USB and put it in a module that can be replaced with a uart.
At the same time, the isp commands themselves are almost identical. Bytes (0x57, 0xAB) are added at the beginning and a checksum (sum of all bytes except 0x57, 0xAB) at the end. For reception at the beginning, not 0x57, 0xAB, but 0x55, 0xAA.
This will require refactoring the entire source file. Should I do this or just redo everything from scratch in my fork?

@jmaselbas
Copy link
Owner

yeah that might be an interesting thing to add, can you provide a very crude/simple (maybe standalone) implementation as an example?
It doesn't have to be clean, it's mainly to have a starting point.
Depending on how this goes I might refactor the entire source file.

@COKPOWEHEU
Copy link
Author

cmd_identify_example.zip
My test code with command 0xA1 (identify). Connects to /dev/ttyUSB0 and writes (tested on v307)
57 AB A1 12 00 00 00 4D 43 55 20 49 53 50 20 26 20 57 43 48 2E 43 4E AB
recv 2: 55 AA A1 00 02 00 71 17 2B

request structure:
(57 AB)(const preamble) A1(command) (12 00)(length) (00 00 4D 43 55 20 49 53 50 20 26 20 57 43 48 2E 43 4E)(data) AB(checksum)
checksum is sum of (command) + (length) + (data).
response structure:
(55 AA)(const preamble) A1(command) 00(I dont know what is it) (02 00)(length) (71 17)(data) 2B(checksum)

@COKPOWEHEU
Copy link
Author

I tried to disassemble bootloader of v307: https://github.com/COKPOWEHEU/ch32v307_bootloader/blob/main/Bootloader_original/result/src/main.S#L1150
UART buffer starts from 0x2000'02c0. And there is variable on 0x2000'0300 (USB configuration). So size of UART buffer is 64 bytes.
Analysis of exchange between official WCH tool and controller shows that 'size' field is 61 bytes or less. (Bytes 0x57, 0xAB does not store, checksum too), 1 byte of 'cmd' + 2 bytes of 'len' + 61 bytes of data = 64 bytes.

@COKPOWEHEU
Copy link
Author

Work in progress! Exchange with 307 made for both usb and uart.
https://github.com/COKPOWEHEU/wch-isp/tree/refactor
Another commands does not implemented yet

@jmaselbas
Copy link
Owner

I took a look at your code. I also tried to communicate with a device (CH32V003) but it didn't worked, I didn't managed to get any answers on the UART

@COKPOWEHEU
Copy link
Author

Yes, I read the v003 have some problems with bootloader. At least it haven't boot0 / boot1 pins... But my chips doesn't arrived so I can't test them myself. I tested v307 (works with USB and UART) and v203 (USB only: UART does not work even with the WCH proprietary utility).

I took a look at your code.

What version? Recently I added reading database from rust version of wch-isp and make a lot of changes

@jmaselbas
Copy link
Owner

the very first version with only the identification CMD.
It fails to receive anything, I think I haven't setup my device properly.
What are you doing for the device to enter the UART bootloader ? And which uart are you using ?
I also tried with the USART1 on CH32V203 (PB6 & PB7)

@COKPOWEHEU
Copy link
Author

USB-UART bridge on ft4232 and homemade bridge on stm32f103. Controller v307 works, but v203 does not. v203g8 works with USB only. I tried UART1 (PA9, PA10) and UART1-remap (PB6, PB7) and swapped Rx/Tx (I dont know... if there is a mistake in my pcb). The only answer is 'timeout'. May be I will try on ch32v103 but it will take a long time
BTW, by default UART1 mapped on PA9, PA10. This is the case in stm32, in gd32 and in ch32v307.

@jmaselbas
Copy link
Owner

all I have is CH32V003, CH32V103, CH32V203 and CH32V208

@delfer
Copy link

delfer commented Jan 14, 2024

Hello friends! Any updates on UART support?

@jmaselbas
Copy link
Owner

I don't think its going to happen for two reasons:

  • termios is "only" supported by POSIX and I don't want to write windows specific code.
  • i didn't managed to communicate with the wch mcu bootloader trough UART

@COKPOWEHEU
Copy link
Author

COKPOWEHEU commented Jan 14, 2024 via email

@COKPOWEHEU
Copy link
Author

I tested on v307rct6 (both USBs and UART), v303cbt6, v103, v208rbt6 and v203g8r6. The last controller, v203g8r6, burns via USB and UART2 (on PA2, PA3 - instead of UART1 on PA9, PA10). Although, as I heard, v203c8 uses normal UART1.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants