Created
June 12, 2022 15:40
-
-
Save mamemomonga/1322c53d17f6fd70f14bded3dcce64b5 to your computer and use it in GitHub Desktop.
ArduinoCLI + ESP32 + FFAT
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -------------------------------------- | |
# Arduino-CLI + ESP32 + FFAT | |
# -------------------------------------- | |
# http://marc.merlins.org/perso/arduino/post_2019-03-30_Using-FatFS-FFat-on-ESP32-Flash-With-Arduino.html | |
# https://github.com/marcmerlin/esp32_fatfsimage/blob/master/README.md | |
# https://github.com/labplus-cn/mkfatfs | |
# https://github.com/lorol/arduino-esp32fs-plugin | |
# https://github.com/marcmerlin/arduino-esp32/tree/master/libraries/FFat/examples/FFat_Test | |
# -------------------------------------- | |
# スケッチのDirectory | |
AR_SKETCH=app | |
# Serialポート | |
AR_PORT=/dev/cu.usbserial-2002 | |
# ESP32-WROOM-32E 16M Flash (3MB APP/9MB FATFS) | |
AR_FQBN=esp32:esp32:esp32:UploadSpeed=921600,PSRAM=enabled,FlashSize=16M,PartitionScheme=app3M_fat9M_16MB | |
ARDUINO_DATA_PATH := $(shell arduino-cli config dump --format json | jq -r .directories.data) | |
ESPTOOL_VERSION := $(shell arduino-cli board details -b esp32:esp32:esp32 --format json | jq -r '.tools_dependencies | .[] | select(.name == "esptool_py") | .version') | |
ESPTOOL_PATH := $(ARDUINO_DATA_PATH)/packages/esp32/tools/esptool_py/$(ESPTOOL_VERSION)/esptool | |
# PartitionScheme=app3M_fat9M_16MB の FATサイズと開始位置 | |
# https://github.com/espressif/arduino-esp32/blob/master/tools/partitions/app3M_fat9M_16MB.csv 参照 | |
# 1セクタ(4096バイト)ずらす必要がある | |
# https://github.com/marcmerlin/esp32_fatfsimage/blob/master/README.md | |
# Offset: 0x610000 - 0x1000 = 0x611000 | |
FATFS_OFFSET := $(shell perl -E 'printf("0x%0X\n",0x610000 + 0x1000);') | |
# Size: 0x9F0000 - 0x1000 = 0x9EF000 | |
FATFS_SIZE := $(shell perl -E 'printf("0x%0X\n", 0x9F0000 - 0x1000);') | |
upload: build/$(AR_SKETCH).ino.hex | |
arduino-cli upload -b $(AR_FQBN) -p $(AR_PORT) $(AR_PROGRAMMER) --input-dir "$(CURDIR)/build" | |
compile: build/$(AR_SKETCH).ino.hex | |
monitor: | |
arduino-cli monitor -p $(AR_PORT) -c Baudrate=115200 | |
clean: | |
rm -rf build | |
rm -f fatfs.img | |
build/$(AR_SKETCH).ino.hex: $(AR_SKETCH)/$(AR_SKETCH).ino | |
arduino-cli compile -b $(AR_FQBN) --build-path "$(CURDIR)/build" $(AR_SKETCH) | |
.PHONY: upload compile serial clean | |
# https://github.com/labplus-cn/mkfatfs | |
bin/mkfatfs: | |
mkdir -p bin | |
cd bin && curl -L -o mkfatfs.zip https://github.com/labplus-cn/mkfatfs/releases/download/v2.0.1/mkfatfs_mac.zip | |
cd bin && unzip mkfatfs.zip | |
fatfs.img: bin/mkfatfs | |
@echo "FATFS_SIZE: $(FATFS_SIZE)" | |
./bin/mkfatfs -t fatfs -c fatfs -s $(FATFS_SIZE) ./fatfs.img | |
fatfs: fatfs.img | |
@echo "FATFS_OFFSET: $(FATFS_OFFSET)" | |
$(ESPTOOL_PATH) --chip esp32 --port $(AR_PORT) --baud 921600 \ | |
--before default_reset --after hard_reset \ | |
write_flash -z --flash_size detect $(FATFS_OFFSET) fatfs.img |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment