Flashing STM32U5 works with STM32CubeProgrammer but not stm32flash
Open source flash program for STM32 using the ST serial bootloader
Brought to you by:
tormod
Hello,
I am trying to flash the stm32u585. However I am seeing the following error:
$ ./stm32flash -k /dev/ttyUSB1 -b 115200 -m 8e1
stm32flash 0.7
http://stm32flash.sourceforge.net/
Interface serial_posix: 115200 8E1
Got byte 0x00 instead of ACK
Unexpected reply from device on command 0x01
My device can be programmed using STM32CubeProgrammer. Also, I have verified with my logic analyzer that the STM32 is returning the correct response. It returns:
{0x79, 0x31, 0x00, 0x79}, which I believe is a good response. I have also ran it with strace to see what is going on:
$ strace -xx -T -e read,write ./stm32flash -k /dev/ttyUSB1 -b 115200 -m 8e1
read(3, "\x7f\x45\x4c\x46\x02\x01\x01\x03\x00\x00\x00\x00\x00\x00\x00\x00\x03\x00\x3e\x00\x01\x00\x00\x00\xc0\x41\x02\x00\x00\x00\x00\x00"..., 832) = 832 <0.000028>
write(1, "\x73\x74\x6d\x33\x32\x66\x6c\x61\x73\x68\x20\x30\x2e\x37\x0a", 15stm32flash 0.7
) = 15 <0.000014>
write(1, "\x0a", 1
) = 1 <0.000010>
write(1, "\x68\x74\x74\x70\x3a\x2f\x2f\x73\x74\x6d\x33\x32\x66\x6c\x61\x73\x68\x2e\x73\x6f\x75\x72\x63\x65\x66\x6f\x72\x67\x65\x2e\x6e\x65"..., 36http://stm32flash.sourceforge.net/
) = 36 <0.000014>
write(1, "\x49\x6e\x74\x65\x72\x66\x61\x63\x65\x20\x73\x65\x72\x69\x61\x6c\x5f\x70\x6f\x73\x69\x78\x3a\x20\x31\x31\x35\x32\x30\x30\x20\x38"..., 35Interface serial_posix: 115200 8E1
) = 35 <0.000057>
write(3, "\x7f", 1) = 1 <0.000036>
read(3, "", 1) = 0 <0.525159>
write(3, "\x7f", 1) = 1 <0.000163>
read(3, "\x1f", 1) = 1 <0.034125>
write(3, "\x01\xfe", 2) = 2 <0.000112>
read(3, "\x00", 1) = 1 <0.032354>
write(2, "\x47\x6f\x74\x20\x62\x79\x74\x65\x20\x30\x78\x30\x30\x20\x69\x6e\x73\x74\x65\x61\x64\x20\x6f\x66\x20\x41\x43\x4b\x0a", 29Got byte 0x00 instead of ACK
) = 29 <0.000128>
write(2, "\x55\x6e\x65\x78\x70\x65\x63\x74\x65\x64\x20\x72\x65\x70\x6c\x79\x20\x66\x72\x6f\x6d\x20\x64\x65\x76\x69\x63\x65\x20\x6f\x6e\x20"..., 45Unexpected reply from device on command 0x01
) = 45 <0.000143>
write(1, "\x0a", 1
) = 1 <0.000052>
+++ exited with 1 +++
I would appreciate any guidance to solve this issue. Thank you in advance!
Anonymous
My apologies. I think this is a better strace capture. The first capture I posted shows the scenario where the bootloader has already been through an init sequence. This capture shows stm32flash receiving the acknowledgement from my device:
another typo... the response to cmd 0x01 on the logic analyzer is {0x79, 0x31, 0x00, 0x00, 0x79}
Output from minicom, which I think confirms that the problem is with stm32flash:
Note: this is through a Buspirate v3.6, which has an FT232 on it. To use stm32flash I put the buspirate in "transparent bridge" mode and then run stm32flash. This works with STMCubeProgrammer.
Thanks for the traces. Strangely, the strace shows that there is a 0x00 byte coming in on the port:
Can you run STM32CubeProgrammer through strace to see if there are 0x00 bytes that it maybe chooses to ignores?
Last edit: Tormod Volden 2023-09-20
Maybe an undocumented pause is needed after the first 0x7f / 0x79 exchange?
There are some similar issues in 134, 106, 155.