Code: Select all
#include <sys/param.h>
#include <string.h>
#include "esp_err.h"
#include "esp_log.h"
#include "driver/uart.h"
#include "driver/gpio.h"
#include "esp32_port.h"
#include "esp_loader.h"
#include "esp_loader_io.h"
#include <common/example_common.h>
#include "esp_flash.h"
static const char *TAG = "serial_flasher";
#define HIGHER_BAUDRATE 230400
void app_main()
{
example_binaries_t bin;
const loader_esp32_config_t config = {
.baud_rate = 115200,
.uart_port = UART_NUM_1,
.uart_rx_pin = GPIO_NUM_16,
.uart_tx_pin = GPIO_NUM_17,
.reset_trigger_pin = GPIO_NUM_8,
.gpio0_trigger_pin = GPIO_NUM_20,
};
if (loader_port_esp32_init(&config) != ESP_LOADER_SUCCESS){ESP_LOGE(TAG, "Serial Initialization Failed.");return;}
if (connect_to_target(HIGHER_BAUDRATE) == ESP_LOADER_SUCCESS)
{
get_example_binaries(esp_loader_get_target(), &bin);
ESP_LOGI(TAG, "Loading Bootloader......"); flash_binary(bin.boot.data, bin.boot.size, bin.boot.addr);
ESP_LOGI(TAG, "Loading Partition Table"); flash_binary(bin.part.data, bin.part.size, bin.part.addr);
ESP_LOGI(TAG, "Loading APP......"); flash_binary(bin.app.data, bin.app.size, bin.app.addr);
ESP_LOGI(TAG, "Done SUCCESS !!!");
}
}
I build the code above using ESP-IDF, the IDE is VS code platformIO.
I faced a problem after building the code above based on the default ESP Serial Flasher from Espressif.
The error resulted from the build is as follow:
c:/users/user/.platformio/packages/toolchain-xtensa-esp32s3/bin/../lib/gcc/xtensa-esp32s3-elf/12.2.0/../../../../xtensa-esp32s3-elf/bin/ld.exe: .pio/build/esp32-s3-devkitc-1-n16r8v/src/main.o:(.literal.app_main+0x20): undefined reference to `flash_binary'
c:/users/user/.platformio/packages/toolchain-xtensa-esp32s3/bin/../lib/gcc/xtensa-esp32s3-elf/12.2.0/../../../../xtensa-esp32s3-elf/bin/ld.exe: .pio/build/esp32-s3-devkitc-1-n16r8v/src/main.o: in function `app_main':
C:\Data\Desktop\Vincent\Testing\usingESPIDF\bootloader_v1/src/main.c:38: undefined reference to `flash_binary'
collect2.exe: error: ld returned 1 exit status
*** [.pio\build\esp32-s3-devkitc-1-n16r8v\firmware.elf] Error 1
Any solutions for this? Thanks in advanced.