Build Firmware MicroPython สำหรับ ESP32
1 min readOct 15, 2024
ใช้ Raspberry Pi ค่อนข้างง่าย
- ติดตั้ง Cmake
sudo apt install cmake -y
2.ติดตั้ง Tools IDF
ดู เลข Version ล่าสุดได้ที่
https://github.com/espressif/esp-idf
แล้วติดตั้ง
cd /home/pi
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
cd esp-idf
./install.sh
. ./export.sh
idf.py พร้อมใช้
คำสั่ง get_idf ใช้สำหรับ ?
ใช้ได้กับบอร์ด esp32c6, esp32c3, esp32c2, esp32s2, esp32h2, esp32, esp32s3, esp32p4
3. โหลด Source MicroPython
ดู Version ใหม่ได้จากเวป https://micropython.org/download/
cd /home/pi/.espressif/
wget https://micropython.org/resources/source/micropython-1.23.0.tar.xz
tar axvf micropython-1.23.0.tar.xz
4. Make
cd /home/pi/.espressif/micropython-1.23.0/ports/esp32
make BOARD=ESP32_GENERIC
Board อื่น เช่น ESP32_GENERIC_S3, ESP32_GENERIC_C3
เสร็จแล้วจะได้ไฟล์สำคัญ สามไฟล์
bootloader @0x001000 23264 ( 5408 remaining)
partitions @0x008000 3072 ( 1024 remaining)
application @0x010000 1661280 ( 370336 remaining)
~/.espressif/micropython-1.23.0/ports/esp32/build-ESP32_GENERIC/bootloader bootloader.bin
~/.espressif/micropython-1.23.0/ports/esp32/build-ESP32_GENERIC/partition_table partition-table.bin
~/.espressif/micropython-1.23.0/ports/esp32/build-ESP32_GENERIC/ micropython.bin
5.โหลดไฟล์ทั้งสามลง PC แล้วใช้ ESP32 Flash Download tools เพื่อ Flash ลง ESP32 ตามภาพ
วิธีเปลี่ยนให้ เริ่มต้น Start โปรแกรมไหนตอน Reset หรือ Reboot ทำได้สองวิธี
- แก้ไฟล์ main.py ใส่ import xxx.py
- แก้ไฟล์ boot.py ใส่
import machine
machine.main('xxx.py')
Ref.