Menu

#159 Flashing STM32U5 works with STM32CubeProgrammer but not stm32flash

none
New
nobody
None
Medium
Defect
2023-09-20
2023-09-20
carlos
No

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!

Discussion

  • carlos

    carlos - 2023-09-20

    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:

    $ 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.000035>
    write(1, "\x73\x74\x6d\x33\x32\x66\x6c\x61\x73\x68\x20\x30\x2e\x37\x0a", 15stm32flash 0.7
    ) = 15 <0.000046>
    write(1, "\x0a", 1
    )                     = 1 <0.000044>
    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.000007>
    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.000091>
    write(3, "\x7f", 1)                     = 1 <0.000034>
    read(3, "\x79", 1)                      = 1 <0.034393>
    write(3, "\x01\xfe", 2)                 = 2 <0.000137>
    read(3, "\x00", 1)                      = 1 <0.032637>
    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.000144>
    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.000153>
    write(1, "\x0a", 1
    )                     = 1 <0.000123>
    +++ exited with 1 +++
    
     
  • carlos

    carlos - 2023-09-20

    another typo... the response to cmd 0x01 on the logic analyzer is {0x79, 0x31, 0x00, 0x00, 0x79}

     
  • carlos

    carlos - 2023-09-20

    Output from minicom, which I think confirms that the problem is with stm32flash:

    Ready
    UART>{0x01,0xfe
    UART LIVE DISPLAY, } TO STOP
    WRITE: 0x01 
    WRITE: 0xFE 
    UART>
    READ: 0x79
    
    READ: 0x31
    
    READ: 0x00
    
    READ: 0x00
    
    READ: 0x79
    UART>
    

    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.

     
  • Tormod Volden

    Tormod Volden - 2023-09-20

    Thanks for the traces. Strangely, the strace shows that there is a 0x00 byte coming in on the port:

    read(3, "\x00", 1)                      = 1 <0.032637>
    

    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
  • Tormod Volden

    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.

     

Anonymous
Anonymous

Add attachments
Cancel