DEV Community

codemee
codemee

Posted on

使用命令列工具上傳檔案到 ESP32 開發板

arduino-esp32fs-plugin 外掛目前並不支援 Arduino IDE 2, 不過其實可以依照以下的步驟利用命令列工具上傳檔案

  1. 從 Arduino 的 preferences.txt 找到目前選擇的控制板型號、晶片平台以及分割 (partition) 方式:

    board=d32
    ...
    custom_PartitionScheme=d32_default
    ...
    target_platform=esp32
    
  2. 目前平台可用的分割方式可在平台的 board.txt 檔中找到, 底下以 ESP 的 d32 板子為例, 檔案在 packages\esp32\hardware\esp32\2.0.5\boards.txt:

    d32.menu.PartitionScheme.default=Default
    d32.menu.PartitionScheme.default.build.partitions=default
    

    第一行是顯示在 Arduino 工具功能表下的分割方式選項文字, 第二行是對應的分割設定檔名稱。

  3. 利用上述資訊, 即可找到分割設定檔, 例如 default 設定檔在 packages\esp32\hardware\esp32\2.0.5\tools\partitions\default.csv:

    # Name,   Type, SubType, Offset,  Size, Flags
    nvs,      data, nvs,     0x9000,  0x5000,
    otadata,  data, ota,     0xe000,  0x2000,
    app0,     app,  ota_0,   0x10000, 0x140000,
    app1,     app,  ota_1,   0x150000,0x140000,
    spiffs,   data, spiffs,  0x290000,0x170000,
    

    就可以知道個別分割區的類型、起始位址、大小。

  4. 有了以上資訊就可以利用隨 ESP32 Arduino Core 就有的 mkspiffs 工具從指定的資料夾建立該資料夾的 spiffs 映像檔:

    # .\mkspiffs -c .\test_dir\ -s 0x170000 test.bin
    
    選項 說明
    -c 要建立映像檔的資料夾, 所有要上傳到 ESP32 開發板的檔案都要放在這個映像檔內
    -s 映像檔的大小, 這可從 partition 設定檔中取得

    mkspiffs 工具在 packages\esp32\tools\mkspiffs 下。

  5. 製作好的映像檔可以透過 esptool 上傳到 ESP32 開發板上, 例如:

    # ./esptool.exe --chip esp32 --port com4 --baud 921600  write_flash -z  0x290000 test.bin
    
    選項 說明
    --chip, -c 晶片型號, 可用 auto, esp8266, esp32, esp32s2, esp32s3beta2, esp32s3, esp32c3, esp32c6beta, esp32h2beta1, esp32h2beta2, esp32c2
    --port, -p 連接埠
    --baud, -b 上傳速率

    最後的兩個參數是 spiffs 分割區的位址以及映像檔的路徑, 分割區位址可由分割設定檔中取得。

    esptool 工具放在 packages\esp32\tools\esptool_py 下。

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs