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

serial port support for GNU/Linux #15

Merged
merged 1 commit into from
Jul 21, 2024

Conversation

nikitos1550
Copy link

Hi!
For my project I am using ch582f as companion chip for embedded GNU/Linux SoC. Connection interface between chips is uart.
Now I can upgrade ch582f during main SoC boot. Maybe this feature will be also useful for community.

Actually UART protocol is same as USB one:

WCH chips expose similar protocol via UART (UART0 or UART1).
The only difference is prefix and crc:
0x57 0xAB for request
0x55 0xAA for response
CRC is just 8bit all bytes some except prefix.

Proof of work:

$ ./isp55e0 -p /dev/ttyUSB0 -d 
Dump - request
a1 12 00 00 00 4d 43 55 20 49 53 50 20 26 20 57 
43 48 2e 43 4e 
Dump - response
a1 00 02 00 82 16 
Found device CH582
Dump - request
a7 02 00 1f 00 
Dump - response
a7 00 1a 00 1f 00 ff ff ff ff ff ff ff ff 48 0f 
ff 40 00 02 04 00 c1 4d 85 26 3b 38 81 ac 
Bootloader version 2.4.0
Unique chip ID c1-4d-85-26-3b-38-81-ac
$ ./isp55e0 -p /dev/ttyUSB0 -f ./images/blepowermanager-0.0.1.bin 
Found device CH582
Bootloader version 2.4.0
Unique chip ID c1-4d-85-26-3b-38-81-ac
Code flashing successful
Firmware is good

Notes:

  • I added serial port support only for GNU/Linux, have no idea how it works under Win. Code became a bit more ugly because of ifdefs.
  • I do not know what code formatter do you use, so I tried format code manually in same style.
  • For debug mode dumps are printed without additional uart wrapper bytes, I am not sure does it follow your original debug idea or not.

@nikitos1550
Copy link
Author

P.S. Also I forget to update README.md :-(

isp55e0.c Outdated
@@ -610,13 +612,19 @@ static const struct option long_options[] = {
{ "data-flash", required_argument, 0, 'k' },
{ "data-verify", required_argument, 0, 'l' },
{ "data-dump", required_argument, 0, 'm' },
#ifndef WIN32
{ "port", required_argument, 0, 'p' },
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatting issue here and elsewhere. Lines start with a tab, not 8 spaces.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code follows the linux coding style (or tries to), if that helps.

#define SHORT_OPTS "c:df:hk:l:m:"
#else
#define SHORT_OPTS "c:df:hk:l:m:p:"
#endif
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer something less verbose:
c = getopt_long(argc, argv, "c:df:hk:l:m:"
#ifndef WIN32
"p:"
#endif
, long_options .....

@frank-zago
Copy link
Owner

That looks good. Can you also update the help section in the README? And a line to show which device was tested, around line 30.

@nikitos1550
Copy link
Author

@frank-zago here you are

@frank-zago
Copy link
Owner

Sorry. I didn't see that before merging some code. Can you rebase?

@nikitos1550
Copy link
Author

@frank-zago rebased.

@frank-zago frank-zago merged commit 1466884 into frank-zago:master Jul 21, 2024
@nikitos1550 nikitos1550 deleted the serial-port-linux branch July 21, 2024 15:48
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

Successfully merging this pull request may close these issues.

2 participants