Skip to content

Commit 2ad543e

Browse files
committed
esp32: Use esptool.py to flash with 'make flash'
This flashes Zephyr at 0x1000: that's where the first stage bootloader, part of the ESP32 ROM, expects to find an "image header". The second-stage bootloader, part of ESP-IDF, isn't used by the Zephyr port. However, the bootloader can be used if desired; please refer to the ESP-IDF documentation on how to set up partitions tables and use the bootloader. The following environment variables will affect the ESP32 flashing process: Variable Default value ESP_DEVICE /dev/ttyUSB0 ESP_BAUD_RATE 921600 ESP_FLASH_SIZE detect ESP_FLASH_FREQ 40m ESP_FLASH_MODE dio ESP_TOOL espidf It's impossible to determine which serial port the ESP32 board is connected to, as it uses a generic RS232-USB converter. The default of /dev/ttyUSB0 is provided as that's often the assigned name on a Linux machine without any other such converters. The baud rate of 921600bps is recommended. If experiencing issues when flashing, try halving the value a few times (460800, 230400, 115200, etc). It might be necessary to change the flash frequency or the flash mode; please refer to the esptool documentation for guidance on these settings. If ${ESP_TOOL} is set to "espidf", the esptool.py script found within ESP-IDF will be used. Otherwise, this variable is handled as a path to the tool. Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
1 parent ad4261a commit 2ad543e

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

boards/xtensa/esp32/Makefile.board

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
EMU_PLATFORM ?=
22
DEBUG_SCRIPT :=
3+
FLASH_SCRIPT := esp32.sh

scripts/support/esp32.sh

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/bin/bash
2+
3+
ESP_DEVICE=${ESP_DEVICE:-/dev/ttyUSB0}
4+
ESP_BAUD_RATE=${ESP_BAUD_RATE:-921600}
5+
ESP_FLASH_SIZE=${ESP_FLASH_SIZE:-detect}
6+
ESP_FLASH_FREQ=${ESP_FLASH_FREQ:-40m}
7+
ESP_FLASH_MODE=${ESP_FLASH_MODE:-dio}
8+
ESP_TOOL=${ESP_TOOL:-espidf}
9+
10+
cmd_flash() {
11+
local esptool
12+
local elf_name=${O}/${KERNEL_ELF_NAME}
13+
14+
if [ "x${ESP_TOOL}" = "xespidf" ]; then
15+
esptool=${ESP_IDF_PATH}/components/esptool_py/esptool/esptool.py
16+
else
17+
esptool=${ESP_TOOL}
18+
fi
19+
if [ ! -x ${esptool} ]; then
20+
echo "esptool could not be found at ${esptool}"
21+
exit 1
22+
fi
23+
24+
echo "Converting ELF to BIN"
25+
${esptool} --chip esp32 elf2image ${elf_name}
26+
27+
echo "Flashing ESP32 on ${ESP_DEVICE} (${ESP_BAUD_RATE}bps)"
28+
${esptool} --chip esp32 \
29+
--port ${ESP_DEVICE} \
30+
--baud ${ESP_BAUD_RATE} \
31+
--before default_reset \
32+
--after hard_reset \
33+
write_flash \
34+
-u \
35+
--flash_mode ${ESP_FLASH_MODE} \
36+
--flash_freq ${ESP_FLASH_FREQ} \
37+
--flash_size ${ESP_FLASH_SIZE} \
38+
0x1000 ${elf_name/.elf/.bin}
39+
}
40+
41+
CMD="$1"; shift
42+
case "${CMD}" in
43+
flash)
44+
cmd_flash "$@"
45+
;;
46+
*)
47+
echo "${CMD} not supported"
48+
exit 1
49+
;;
50+
esac

0 commit comments

Comments
 (0)