Skip to main content
Graduate
July 11, 2024
Solved

How can I use an ESP32 to update the firmware of an STM32 from any family

  • July 11, 2024
  • 4 replies
  • 7575 views

Hello, I am designing a device that will have an STM32L4 or maybe an STM32U and will communicate with an ESP32 for internet connectivity. However, at some point, I would like to update the firmware remotely, and have the ESP32 stop executing its conventional software and act as a programmer for the STM32. Is this possible? And if so, where can I find detailed information on how to do it? I hope you can help me, thank you.

    This topic has been closed for replies.
    Best answer by Andrew Neil

    @WPazH wrote:

     Is this possible? 


    Yes.

    You have 2 choices:

    1. Use the STM32's System bootloader.
      This requires control of the STM32's Reset & BOOT pins.
      There are Application Notes describing the Bootloader protocol and supported interfaces.
    2. Use a custom bootloader.
      As it's custom, you can do it without needing to use the STM32's Reset & BOOT pins, and can use any interface & protocol you like.
      See the In-Application Programming Application Notes for examples.
      3rd-party bootloaders  are available.

     

    With an ESP32, you could either have the ESP "push" the update to the STM, or have the STM "pull" the update from the ESP, or the ESP could be purely passive and transparent ...

     

    Similar question yesterday:

    https://community.st.com/t5/stm32-mcus-boards-and-hardware/how-to-remotely-update-code-on-stm32-microcontroller/m-p/695840

     

    #Bootloader #FirmwareUpdate #InApplicationProgramming  #OTA  #IAP

    4 replies

    Graduate II
    July 11, 2024

    Perhaps another solution could be - using the STM32L4 to download the new firmware into an external EEPROM compatible with AN2606, then cause the SMT32L4 to Reset with the appropriate Boot mode...

    Kind regards
    Pedro

    Super User
    July 11, 2024

    @WPazH wrote:

     Is this possible? 


    Yes.

    You have 2 choices:

    1. Use the STM32's System bootloader.
      This requires control of the STM32's Reset & BOOT pins.
      There are Application Notes describing the Bootloader protocol and supported interfaces.
    2. Use a custom bootloader.
      As it's custom, you can do it without needing to use the STM32's Reset & BOOT pins, and can use any interface & protocol you like.
      See the In-Application Programming Application Notes for examples.
      3rd-party bootloaders  are available.

     

    With an ESP32, you could either have the ESP "push" the update to the STM, or have the STM "pull" the update from the ESP, or the ESP could be purely passive and transparent ...

     

    Similar question yesterday:

    https://community.st.com/t5/stm32-mcus-boards-and-hardware/how-to-remotely-update-code-on-stm32-microcontroller/m-p/695840

     

    #Bootloader #FirmwareUpdate #InApplicationProgramming  #OTA  #IAP

    Super User
    July 11, 2024

    System Bootloader:

    Picking an L4 Product Page at random, and going to the 'Documentation' Tab:

    https://www.st.com/en/microcontrollers-microprocessors/stm32l412c8.html#documentation

    AN2606 STM32 microcontroller system memory boot mode

    AN3154 CAN protocol used in the STM32 bootloader

    AN4221 I2C protocol used in the STM32 bootloader

    AN4286 SPI protocol used in the STM32 bootloader

    AN3155 USART protocol used in the STM32 bootloader
    AN3156 USB DFU protocol used in the STM32 bootloader

     

    In Application Programming:

    AN4657 STM32 in-application programming (IAP) using the USART

    https://www.st.com/resource/en/application_note/an4657-stm32-inapplication-programming-iap-using-the-usart-stmicroelectronics.pdf

    https://github.com/STMicroelectronics/STM32CubeL4/tree/master/Projects/STM32L476G-EVAL/Applications/IAP/IAP_Main

     

    Also have a browse through the Knowledgebase - several articles there on bootloaders:

    https://community.st.com/t5/stm32-mcus/tkb-p/stm32-mcus-knowledge-base

    just one example:

    https://community.st.com/t5/stm32-mcus/how-to-program-a-stm32-with-another-stm32-using-embedded/ta-p/612362

     

    PS:

    ST's Open Bootloader:

    https://community.st.com/t5/stm32-mcus/how-to-use-the-st-open-bootloader-for-stm32-microcontrollers/ta-p/49896

    WPazHAuthor
    Graduate
    July 16, 2024

    Hi @PGump.1  and @Andrew Neil  , your answers were very helpful. I will try to implement the two methods you mentioned, as the ESP32 needs to send the update to two STM32s, and I'm not very sure which method would be more effective. Thank you for the help.

    Graduate
    April 18, 2025

    WILL YOU PLEASE SHARE THE SOURCE CODE FOR UPLOAD FIRMWARE  VIA UART , AND  PLEASE SHARE HOW TO USE THE SYSTEM BOOTLOADER HOW TO ACTIVATE THAT TO RECEVE FIRMWARE , 
    I AM DOING AN OTA WITH THE STM32U575  AND THE ESP32 CAN YOU GUIDE ME

    Explorer
    August 2, 2025

    Hey Hi premkumar! you got solution? , Since we are also working on it! and couldnt found proper codebase or solutions for it.

    Super User
    August 2, 2025

    Here you can find help for your STM32 project.