cancel
Showing results for 
Search instead for 
Did you mean: 

Issues with STM32H7 USART bootloader application code

JSqui
Associate

Hello,

I writing an application code that will allow the system memory bootloader to be entered via a simple USART receive. I basically followed this post and got it working successfully:

https://community.st.com/s/article/STM32H7-bootloader-jump-from-application

This was the first piece of the puzzle though. The end goal is to have a custom Python GUI to upload a .bin file to the chip through the standard USART bootloader. I have been developing and debugging this GUI extensively, and watched everything on the logic analyzer to make sure it's sending what I expect, and that the ACKs are truly being received.

I have tried this process that works without the GUI, to confirm my setup is good:

  1. I send my USART character to the STM32H7 via serial - I see that it stops blinking the LED of the running program and jumps to the bootloader like it should.
  2. I can then connect to it with the STM32CubeProgrammer and download the .bin file without issues through the USART bootloader
  3. I press reset on the board and I see that my binary file that was just uploaded is working (slower blinking LED)

The python program seems to be working in theory, and this is what the steps are:

  1. The Python program sends the USART character to the STM32H7 via serial - I see that it stops blinking the LED of the running program and jumps to the bootloader like it should.
  2. The Python program sends the 0x7F command and receives the ACK
  3. The Python program sends the mass erase command, receives the proper ACK, and gets the ACK when this is completed successfully.
  4. The Python program then starts the sequence of write commands (0x31), along with the parsed .bin file.
  5. The entire file is downloaded with apparent success, as I receive ACKs every step of the way, and I can see that the application code is there when I connect via ST-Link and look at the memory.
  6. When I press the reset button, the code never runs - I never see the LED turn on or start blinking.

My question is, what could be the possible difference between what the STM32CubeProgrammer is doing and what my Python code is doing?

Here are some things I've noticed on the logic analyzer when comparing the two:

  • The STM32CubeProgrammer is periodically sending the 0x02 (get ID) command while not busy with anything else
  • The STM32CubeProgrammer requests and reads all the option bytes shortly after connection

My code doesn't do any of this, but I don't see why it should need to. I've also verified the option bytes are set to have Readout Protection at level 0.

Is there more detailed information on what the STM32CubeProgrammer is doing behind the scenes? Any ideas on what could be happening?

Please see the attached Python code (if interested). I can't understand what would be preventing the user code from running after I apparently successfully upload it all via my GUI.

Thanks for any help in advance.

2 REPLIES 2
TDK
Guru

Download and compare the flash after programming with both methods and look at the differences.

If you feel a post has answered your question, please click "Accept as Solution".
JSqui
Associate

Thanks for the advice. I was about to do this, but finally tried reading the bytes another way from the binary file. For some reason the encoding I was reading the binary file with was reading most of the bytes correctly, but there must have been some weird ones in the middle that got screwed up and I didn't notice them when looking at the beginning and end on the logic analyzer. I ended up getting it to work correctly and how have a stable, simple, and customizable GUI tool that should be platform independent at the end when I make an executable from it.