Environment
- WSL2 on Ubuntu-24.02.
- esptool on Windows.
1. Setting up ESP-IDF and the build environment
Runs on Ubuntu.
sudo apt update
sudo apt install -y build-essential libusb-1.0-0-dev libffi-dev git pkg-config python3 python3-venv cmake virtualenv python3-pip python3-virtualenv
mkdir esp32
cd esp32
git clone -b v5.2.2 --recursive https://github.com/espressif/esp-idf.git
cd esp-idf
git checkout v5.2.2
git submodule update --init --recursive
./install.sh esp32
source export.sh
2. Building the firmware with “st7789_mpy” module
2.1 Clone and setting
cd ~/esp32
git clone https://github.com/micropython/micropython.git
git clone https://github.com/russhughes/st7789_mpy.git
git clone https://github.com/Mythologyli/MicroPython-ESP32-S3-N16R8.git
cp -r MicroPython-ESP32-S3-N16R8/ESP32_GENERIC_S3_N16R8 micropython/ports/esp32/boards/ESP32_GENERIC_S3_N16R2
cd micropython/ports/esp32/boards/ESP32_GENERIC_S3_N16R2
and edit 2files(include option).
(1) mpconfigboard.cmake
set(IDF_TARGET esp32s3)
set(SDKCONFIG_DEFAULTS
boards/sdkconfig.base
${SDKCONFIG_IDF_VERSION_SPECIFIC}
boards/sdkconfig.usb
boards/sdkconfig.ble
boards/sdkconfig.spiram_sx
boards/ESP32_GENERIC_S3_N16R2/sdkconfig.board
boards/sdkconfig.240mhz
)
list(APPEND MICROPY_DEF_BOARD
MICROPY_HW_BOARD_NAME="Generic Board:16MB-FLASH & 2MB-PSRAM. Built-in russhughesi/ST7789_mpy module"
)
(2) (option) mpconfigboard.h
Not mandatory
#ifndef MICROPY_HW_BOARD_NAME
// Can be set by mpconfigboard.cmake.
#define MICROPY_HW_BOARD_NAME "ESP32-S3-Pico"
#endif
#define MICROPY_HW_MCU_NAME "ESP32S3R2"
#define MICROPY_PY_NETWORK_HOSTNAME_DEFAULT "ESP32S3Pico"
// Enable UART REPL for modules that have an external USB-UART and don't use native USB.
#define MICROPY_HW_ENABLE_UART_REPL (1)
#define MICROPY_HW_I2C0_SCL (9)
#define MICROPY_HW_I2C0_SDA (8)
2.2 (option)Copy to st7789_mpy python module.
If you don’t understand the “frozon_module”, DON’T do this option.
e.g.
cd ~/esp32/micropython/ports/esp32/
cp ../../../st7789_mpy/fonts/bitmap/vga1_16x16.py modules
cp ../../../st7789_mpy/fonts/truetype/NotoSans_32.py modules
cp ../../../st7789_mpy/fonts/vector/scripts.py modules
and so on...
Copy only those modules for which freeze is “yes”.
Refer to “Readme.md” under “st7789_mpy/fonts” directories.
bitmap/README.md truetype/README.md vector/README.md
2.3 Build
cd ~/esp32/micropython/
git submodule update --init
cd ports/esp32
make BOARD=ESP32_GENERIC_S3_N16R2 submodules
export IDF_TARGET=esp32s3
make BOARD=ESP32_GENERIC_S3_N16R2 USER_C_MODULES=../../../../st7789_mpy/st7789/micropython.cmake
After firmware has been built, run the following command.
cd build-ESP32_GENERIC_S3_N16R2
explore.exe .
Explore will open a folder and copy the “firmware.bin” to a directory where esptool can run.
2.4 Write firmware to ESP32-S3-Pico
My ESP32-S3-Pico is COM5, so run the following command.
.\esptool.exe --port COM5 --chip esp32s3 -b 460800 --before default_reset --after no_reset write_flash --flash_mode dio --flash_size 16MB --flash_freq 80m 0x0 firmware.bin
And re-connect USB.