Skip to content

Latest commit

 

History

History

README.md

Flash Multiple Partitions Example

Overview

This example demonstrates how to flash an Espressif SoC (target) from another MCU (host) using esp_serial_flasher. Binaries to be flashed from the host MCU to the Espressif SoC can be found in binaries folder and are converted into C-array during build process.

The following steps are performed in order to re-program targets memory:

  1. UART1 through which the the new binary will be transferred is initialized.
  2. The host puts the target device into the boot mode and tries to connect by calling esp_loader_connect().
  3. The binary file is opened and its size is acquired, as it has to be known before flashing.
  4. Then esp_loader_flash_start() is called to enter the flashing mode and erase the amount of memory to be flashed.
  5. esp_loader_flash_write() function is called repeatedly until the whole binary image is transferred.

Note

In addition to the steps mentioned above, esp_loader_change_transmission_rate() is called after the connection is established in order to increase the flashing speed. This does not apply for the ESP8266, as its bootloader does not support this command. However, the ESP8266 is capable of detecting the baud rate during connection phase and can be changed before calling esp_loader_connect(), if necessary.

Connection Configuration

In the majority of cases ESP_LOADER_CONNECT_DEFAULT helper macro is used in order to initialize loader_connect_args_t data structure passed to esp_loader_connect(). Helper macro sets the maximum time to wait for a response and the number of retrials. For more detailed information refer to serial protocol.

Hardware Required

  • Two development boards with Espressif SoCs (e.g., ESP32-DevKitC, ESP-WROVER-KIT, etc.).
  • One or two USB cables for power supply and programming.
  • Jumper cables to connect host to target according to table below.

Hardware Connection

This example uses the UART interface. For detailed interface information and general hardware considerations, see the Hardware Connections Guide.

ESP32-to-Espressif SoC Pin Assignment:

ESP32 (host) Espressif SoC (target)
IO26 BOOT
IO25 RESET
IO4 RX0
IO5 TX0

Prepare Target Firmware

Place the required target firmware binaries in the target-firmware/ directory. You can use your own binaries, build them from the esp-idf examples, or build them from the source in the test/target-example-src directory.

Required binaries:

  • bootloader.bin - ESP bootloader binary
  • partition-table.bin - Partition table configuration
  • app.bin - Main application binary

Build and Flash

To run the example, type the following command:

idf.py -p PORT flash monitor

(To exit the serial monitor, type Ctrl-].)

See the Getting Started Guide for full steps to configure and use ESP-IDF to build projects.

Configuration

For details about available configuration options, please refer to the top level README.md. Binaries to be flashed are placed in a separate folder (binaries.c) for each possible target and converted to C-array.

Example Output

Here is the example's console output:

...
Connected to target
Transmission rate changed changed
I (2484) serial_flasher: Loading bootloader...
Erasing flash (this may take a while)...
Start programming
Progress: 100 %
Finished programming
Flash verified
I (4074) serial_flasher: Loading partition table...
Erasing flash (this may take a while)...
Start programming
Progress: 100 %
Finished programming
Flash verified
I (4284) serial_flasher: Loading app...
Erasing flash (this may take a while)...
Start programming
Progress: 100 %
Finished programming
Flash verified
I (11934) serial_flasher: Done!
I (11273) serial_flasher: ********************************************
I (11273) serial_flasher: *** Logs below are print from slave .... ***
I (11273) serial_flasher: ********************************************
Hello world!