Author Topic: Program STM32 with another STM32  (Read 2375 times)

0 Members and 1 Guest are viewing this topic.

Offline ratataxTopic starter

  • Regular Contributor
  • *
  • Posts: 134
  • Country: fr
Program STM32 with another STM32
« on: April 03, 2021, 10:57:32 am »
I want to upload a firmware to an STM32 from another STM32 using UART. I implemented in my application the UART bootloader protocol described here: https://www.st.com/resource/en/application_note/cd00264342-usart-protocol-used-in-the-stm32-bootloader-stmicroelectronics.pdf

The communication between the two devices works, I start the "slave" STM32 in system bootloader mode, I send write memory commands with the "master" STM32 with the data and it returns ACK which means it worked.

Then I restart the slave STM32 in normal mode, but it doesn't do anything, even a gpio toggle program doesn't work.

I'm not sure about the following things..

- The compiled code of the program to upload (.bin compiled with STM32CubeIDE) should be written directly to 0x8000000 memory address, right ? (flash base address) I'm confused because some people seems to write the code after this address, then put some custom bootloader code at 0x8000000 to jump to it but it's not mandatory, isn't it ?

- I haven't managed to make the Read Memory command to work for the UART bootloader protocol, so I can't check the written data. I followed exactly the document but I get only a 1 byte response that doesn't make sense, I even compared my code to this one (https://github.com/ARMinARM/stm32flash/blob/master/stm32.c) to make sure I was sending the right commands.

I feel a bit stuck, I already did many things to remove them from the possible causes: using a different power supply, replacing the STM32 chip, checking all decoupling caps, using the internal oscillator to remove potential external crystal issues...
« Last Edit: April 03, 2021, 11:00:43 am by ratatax »
 

Offline Siwastaja

  • Super Contributor
  • ***
  • Posts: 8172
  • Country: fi
Re: Program STM32 with another STM32
« Reply #1 on: April 03, 2021, 04:44:42 pm »
Did you remember to run erase command before writing?

Check the .bin manually. The first two 4-byte words should be stack pointer initialization value, and the address of the init function.
 

Offline abyrvalg

  • Frequent Contributor
  • **
  • Posts: 824
  • Country: es
Re: Program STM32 with another STM32
« Reply #2 on: April 03, 2021, 09:19:29 pm »
Try reading out the flash content via SWD and compare it with the image you’ve programmed.
 

Offline darkspr1te

  • Frequent Contributor
  • **
  • Posts: 290
  • Country: zm
Re: Program STM32 with another STM32
« Reply #3 on: April 08, 2021, 01:45:13 pm »
I want to upload a firmware to an STM32 from another STM32 using UART. I implemented in my application the UART bootloader protocol described here: https://www.st.com/resource/en/application_note/cd00264342-usart-protocol-used-in-the-stm32-bootloader-stmicroelectronics.pdf

The communication between the two devices works, I start the "slave" STM32 in system bootloader mode, I send write memory commands with the "master" STM32 with the data and it returns ACK which means it worked.

Then I restart the slave STM32 in normal mode, but it doesn't do anything, even a gpio toggle program doesn't work.

I'm not sure about the following things..

- The compiled code of the program to upload (.bin compiled with STM32CubeIDE) should be written directly to 0x8000000 memory address, right ? (flash base address) I'm confused because some people seems to write the code after this address, then put some custom bootloader code at 0x8000000 to jump to it but it's not mandatory, isn't it ?

- I haven't managed to make the Read Memory command to work for the UART bootloader protocol, so I can't check the written data. I followed exactly the document but I get only a 1 byte response that doesn't make sense, I even compared my code to this one (https://github.com/ARMinARM/stm32flash/blob/master/stm32.c) to make sure I was sending the right commands.

I feel a bit stuck, I already did many things to remove them from the possible causes: using a different power supply, replacing the STM32 chip, checking all decoupling caps, using the internal oscillator to remove potential external crystal issues...

when dealing with stm32 and memory try and remember that you write to 0x000000 but execute 0x8000000,
i would first read back the second stm32 memory dump and compare to your bin. You cannot write to un-erased memory , you have to erase each block first then write. memory has to be unlocked prior to writing /erasing.

also confirm that your blink code does in fact work by flashing the second stm bin file directly via stlink or similar ,

darkspr1te

 

Offline camila

  • Contributor
  • !
  • Posts: 11
  • Country: us
Re: Program STM32 with another STM32
« Reply #4 on: April 08, 2021, 06:36:57 pm »
Try AN3155, It will help you in this regard
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf