Code Monkey home page Code Monkey logo

ota_update_stm32_using_esp32's Introduction

Stargazers Forks Issues License


Logo

OTA for STM32Fxx MCU using ESP32

Program your STM32Fxx Over-the-Air using ESP32
****
View Code · Report Bug · Request Feature · Create a Pull Request

Table of Contents

About the Project

The project aims at enabling firmware update of STM32Fxx and STM32Gxx series MCUs Over-the-Air using ESP32.

Testing was done with ESP32-DevKitC v4 board and STM32F103C8T6 (Blue Pill), STM32F072C8T6 and STM32G431KB (NUCLEO-G431KB). You can try with any other STM32Fxx/STM32Gxx MCUs and let us know how it worked out.

Code

/esp_stm_flash -> Basic flashing utility, requires path of the .bin file which has been already uploaded in SPIFFS

/file_serving_stm -> OTA demo, with HTTP File Server with embedded flash link

/references -> Python scripts for understanding the flashing protocol commands and verification

Getting Started

Hardware Required

To run the OTA demo, you need an ESP32 dev board (e.g. ESP32-WROVER Kit) or ESP32 core board (e.g. ESP32-DevKitC). For the STM32, you can use the STM32 Blue Pill.

Prerequisites

  • ESP-IDF v4.0 and above

    You can visit the ESP-IDF Programmming Guide for the installation steps.

  • Arduino IDE

    Arduino IDE provides with an easy way to generate the .bin files for your STM32 MCU. For setting up Arduino Core for the STM32 family, you can follow this link.

    You can also use CubeIDE or Keil for generation of .bin files.

Setting Up

  1. Wire your STM32 (e.g. Blue Pill) to the ESP32 as follows:

    ESP32 STM32
    GPIO4(TX) PA10(RX)
    GPIO5(RX) PA9(TX)
    GPIO19 RESET
    GND GND
  2. Generate a .bin file for the STM32 MCU code you want to flash.

Disclaimer

We have assumed that the STM32 is already in boot mode before flashing the code (Step 1 & 5 in Usage section). You can use a MOSFET as a switch to automate the process, using an ESP32 GPIO as an input.

The program code uses only the path of the binary file to be flashed as a parameter. Thus, it can be easily integrated into any other projects as the file can be sent to ESP32 over any protocol (MQTT, HTTP Client, WebSockets).

Read carefully the Boot Mode Procedure (AN2606) and the USART protocol used in Bootloader Mode (AN3105) in order to deeply understand how to use this project with other STM32 microcontrollers.

Usage (For STM32 Blue Pill)

  1. Make sure the BOOT0 jumper pin on the board is set to 1 (programming mode) while uploading the code. Once the code is flashed this pin can be changed back to initial position (operating mode). This procedure with your STM32Fxx MCU varies according with your MCU version.

    Refer this documentation for help.

  1. Open the project configuration menu (idf.py menuconfig) go to Example Connection Configuration ->
    1. WiFi SSID: WiFi network to which your PC is also connected to.
    2. WiFi Password: WiFi password

  1. In order to test the OTA demo -> /file_serving_stm :
    1. Compile and burn the firmware idf.py -p PORT -b BAUD flash
    2. Run idf.py -p PORT monitor and note down the IP assigned to your ESP module. The default port is 80.
    3. Test the example interactively on a web browser (assuming IP is 192.168.43.82):
      • Open path http://192.168.43.82/ to see an HTML web page with list of files on the server (initially empty)
      • Use the file upload form on the webpage to select and upload a .bin file to the server
      • Click a file link to download / open the file on browser (if supported)
      • Click the delete link visible next to each file entry to delete them
      • Click on the flash link to flash the .bin code file uploaded to the connected STM32.

  1. After clicking the flash link, you should get the following results -

  1. Revert the BOOT0 pin to its initial position and press the RESET Button on the STM32.
  2. Voila! your STM32 is now running the code you uploaded Over-the-Air!

Compatibility

According to STM documentation, this project could be compatible with a wide range of microcontrollers, prior to some customization:

  • STM32F0 Series (verified)
  • STM32F1 Series (verified)
  • STM32F2 Series
  • STM32F3 Series
  • STM32F4 Series
  • STM32F7 Series
  • STM32G0 Series
  • STM32G4 Series (verified)
  • STM32H7 Series
  • STM32L0 Series
  • STM32L1 Series
  • STM32L4 Series
  • STM32L5 Series
  • STM32U5 Series
  • STM32WB Series
  • STM32WL Series

Troubleshooting

  • Check your wiring. Make sure that the ESP32 and STM32 are powered separately. Don't power one MCU using the other.
  • Verify your WiFi SSID and password.
  • Check if your STM32 is locked using this official tool by STMicroelectronics and unlock it by erasing the memory of your chip.
  • Check your STM32 code, which generated the .bin file, for any 'logical' errors.
  • For any other bugs or errors, you can always raise issues.

Contributors

For OTA updates for AVR MCUs, you can follow this project.

Acknowledgements and Resources

License

Distributed under the MIT License. See LICENSE for more information.

ota_update_stm32_using_esp32's People

Contributors

laukik-hase avatar rickie95 avatar udit7395 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

ota_update_stm32_using_esp32's Issues

Flashing with DFU

A project I'm running builds to a DFU file instead of a .bin file. It's crashing before I can even upload the file. Is it possible to flash this? When I attempt to upload the 110KB DFU file it returns

I (18706) FILE_SERVER_HTTP: Found file : Blink.ino.bin (13492 bytes)
E (24596) FILE_SERVER_HTTP: Failed to create file : /spiffs/myproject.ino.dfu
W (24596) httpd_txrx: httpd_resp_send_err: 500 Internal Server Error - Failed to create file
W (24606) httpd_uri: httpd_uri: uri handler execution failed
E (24816) FILE_SERVER_HTTP: Failed to create file : /spiffs/myproject.ino.dfu
W (24826) httpd_txrx: httpd_resp_send_err: 500 Internal Server Error - Failed to create file
W (24836) httpd_uri: httpd_uri: uri handler execution failed

and on the webpage it shows

Server closed the connection abruptly!

For OTA updates for AVR MCUs, you can follow this project: ESP-LINK (ESP8266 it's cheaper)

The esp-link firmware connects a micro-controller to the internet using an ESP8266 Wifi module. It implements a number of features:

transparent bridge between Wifi and serial, useful for debugging or inputting into a uC
flash-programming attached Arduino/AVR microcontrollers and LPC800-series and other ARM microcontrollers via Wifi
built-in stk500v1 programmer for AVR uC's: program using HTTP upload of hex file
outbound REST HTTP requests from the attached micro-controller to the internet
MQTT client pub/sub from the attached micro-controller to the internet
serve custom web pages containing data that is dynamically pulled from the attached uC and that contain buttons and fields that are transmitted to the attached uC (feature not fully ready yet)

https://github.com/jeelabs/esp-link

ESP32 can't using other Serial?

Can't I use other serial ports? Do I have to use the main serial port? I use ESP32, I can use Serial, but I can't use Serial2

Thanks for your sharing

It's a pretty good project.
While, I must recovery jumper cap of Boot pins and put down the reset button to ensure the program downloaded in MCU to restart.
In orther word, through ESP32 can flash the MCU wirelessly, we have to recover the wiring and reset it offline .

Serial Timeout ERROR

Hi for all, I am trying to use this example, but I couldnt it successfully. I got Serial timeout error.( esp32 and stm32 could not talk successfully. ) I have tried everything, powered up stm32 and esp32 with different sources, erased stm32 flash memory with STMFlashLoader, changed up baudrate, or buttons and still got error. What could be the reason of this?
Thank you...

D (337256) : stm_flash (flashSTM:74) File name: /spiffs/blink.bin
I (337256) : stm_pro_mode (initGPIO:76) GPIO Initialized
I (337256) : stm_flash (flashSTM:83) Writing STM32 Memory
I (337256) : stm_flash (writeTask:7) Write Task
I (337256) : stm_pro_mode (resetSTM:81) Starting RESET Procedure
I (337856) : stm_pro_mode (resetSTM:88) Finished RESET Procedure
I (337856) : stm_pro_mode (cmdSync:114) SYNC
E (337896) : stm_pro_mode (sendBytes:231) Serial Timeout
I (337896) : stm_pro_mode (cmdGet:123) GET
E (337936) : stm_pro_mode (sendBytes:231) Serial Timeout
I (337936) : stm_pro_mode (cmdVersion:132) GET VERSION & READ PROTECTION STATUS
E (337976) : stm_pro_mode (sendBytes:231) Serial Timeout
I (337976) : stm_pro_mode (cmdId:141) CHECK ID
E (338016) : stm_pro_mode (sendBytes:231) Serial Timeout
I (338016) : stm_pro_mode (cmdErase:149) ERASE MEMORY
E (338056) : stm_pro_mode (sendBytes:231) Serial Timeout
I (338056) : stm_pro_mode (cmdExtErase:166) EXTENDED ERASE MEMORY
E (338096) : stm_pro_mode (sendBytes:231) Serial Timeout
I (338106) : stm_flash (writeTask:19) Writing block: 1
I (338106) : stm_pro_mode (flashPage:279) Flashing Page
I (338106) : stm_pro_mode (cmdWrite:183) WRITE MEMORY
E (338146) : stm_pro_mode (sendBytes:231) Serial Timeout
E (338186) : stm_pro_mode (sendBytes:231) Serial Timeout
E (338496) : stm_pro_mode (flashPage:318) Serial Timeout
I (338496) : stm_flash (flashSTM:92) STM32 Flashed Successfully!!!
I (338496) : stm_flash (flashSTM:95) Ending Connection
I (338496) : stm_pro_mode (resetSTM:81) Starting RESET Procedure
I (339096) : stm_pro_mode (resetSTM:88) Finished RESET Procedure
I (339096) : stm_pro_mode (endConn:98) Ending Connection
I (339096) : stm_flash (flashSTM:98) Closing file
E (339096) : FILE_SERVER_HTTP (flash_post_handler:445) Target flashing failed

Replacing UART by RS485

Hello,

We have 2 boards, one ESP32 and one STM32. They are communicating by RS485 over UART with at each side one RS485 transceiver.
Do you think it's possible to download the STM32 firmware by RS485 ?

Thank you.

running the project in vscode

Hello! thanks for the project. How to compile it in vscode if we have here two directories esp_stm_flash and file_serving_stm and each of them has its own main file?

control BOOT0 pin from ESP

By adding an additional pin, controlling BOOT0, the whole programming operation can be automated without human intevention

flash ESP32 instead of STM32 after uploading the file to the file server

Hello! I downloaded the project about flashing ESP instead of STM32 through a file server on the link https://github.com/versamodule/ESP32-OTA-Webserver but I face some problems:

-I can't open menuconfig so as to set the SSID and password;
-When I try to build I get the error Unknown CMake command "register_component" . When I comment this line in CMakeLists.txt , the compilation is done but the flashin is not possible(command flash from idf.py not found).

fatal error: driver/uart.h: No such file or directory

Hello! I am trying to test the file_serving_stm project but I can´t manage to make it compile.
It throws the following error:
fatal error: driver/uart.h: No such file or directory

image

It would be really helpful if someone can help me to solutionate this.
Thanks! real

Compatibility with F407

I want to flash my STM32F407 discovery board, but I can't quite get it to work
I've tried it on a F103 (bluepill) and it worked fine.

Everything looks great, but after trying to erase memory, I get a sync failure.

Screenshot_20201110_230134

I (78643) : stm_pro_mode (initGPIO:78) GPIO Initialized
I (78643) : stm_flash (flashSTM:83) Writing STM32 Memory
I (78643) : stm_flash (writeTask:7) Write Task
I (78653) : stm_pro_mode (resetSTM:83) Starting RESET Procedure
I (78663) : stm_pro_mode (resetSTM:84) Toggling pin (19)
I (79263) : stm_pro_mode (resetSTM:91) Finished RESET Procedure
I (79263) : stm_pro_mode (cmdSync:117) SYNC, 0x7F
I (79263) : stm_pro_mode (sendBytes:222) Sync Success
I (79263) : stm_pro_mode (cmdGet:126) GET
I (79273) : stm_pro_mode (sendBytes:222) Sync Success
I (79273) : stm_pro_mode (cmdVersion:135) GET VERSION & READ PROTECTION STATUS
I (79283) : stm_pro_mode (sendBytes:222) Sync Success
I (79293) : stm_pro_mode (cmdId:144) CHECK ID
I (79293) : stm_pro_mode (sendBytes:222) Sync Success
I (79303) : stm_pro_mode (cmdErase:152) ERASE MEMORY
E (79303) : stm_pro_mode (sendBytes:228) Sync Failure
I (79313) : stm_pro_mode (cmdExtErase:169) EXTENDED ERASE MEMORY
I (79323) : stm_pro_mode (sendBytes:222) Sync Success
E (79913) : stm_pro_mode (sendBytes:234) Serial Timeout
I (79913) : stm_flash (writeTask:19) Writing block: 1
I (79913) : stm_pro_mode (flashPage:282) Flashing Page
I (79923) : stm_pro_mode (cmdWrite:186) WRITE MEMORY
E (80503) : stm_pro_mode (sendBytes:234) Serial Timeout
E (81083) : stm_pro_mode (sendBytes:234) Serial Timeout
E (81673) : stm_pro_mode (flashPage:321) Serial Timeout
I (81673) : stm_flash (flashSTM:92) STM32 Flashed Successfully!!!
I (81683) : stm_flash (flashSTM:95) Ending Connection
I (81683) : stm_pro_mode (resetSTM:83) Starting RESET Procedure
I (81693) : stm_pro_mode (resetSTM:84) Toggling pin (19)
I (82293) : stm_pro_mode (resetSTM:91) Finished RESET Procedure
I (82293) : stm_pro_mode (endConn:101) Ending Connection
I (82293) : stm_flash (flashSTM:98) Closing file
E (82293) : FILE_SERVER_HTTP (flash_post_handler:444) Target flashing failed

Have you tried it with an F4? Any idea on what I should test/debug? I've tried reducing the baud rate to 9600bps, which didn't help.

Here's are the packets during the attempted flash:
ota_stm32f4_uart_traffic.zip

Thanks!!

URI Header too long

Hey, I am able to successfully upload the code on the local server but when I am pressing the flash button the web page breaks and I see this error (I (1540683) FILE_SERVER_HTTP: Found file : I2C_RTC.bin (11668 bytes)
I (1540693) FILE_SERVER_HTTP: Found file : UartTest.bin (8220 bytes)
I (1540703) FILE_SERVER_HTTP: Found file : blink.bin (4552 bytes)
I (1542803) FILE_SERVER_HTTP: Sending file : /blink.bin (4552 bytes)...
I (1542813) FILE_SERVER_HTTP: File sending complete
W (1548003) httpd_parse: parse_block: request URI/header too long
) when I monitor the COM port . I just built and flashed the file_serving_stm folder and flashed it, is it correct?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.