ESP32 スケッチアップロード・動作確認

無線機能を使用したスケッチ実行時のエラー

Brownout detector was triggered

ets Jun  8 2016 00:22:57

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:1216
ho 0 tail 12 room 4
load:0x40078000,len:10944
load:0x40080400,len:6388
entry 0x400806b4

WifiやBluetoothの無線機能使用時(BLE:Bluetooth Low Enegyは未確認)、USBからの給電容量を超えた電流が必要になるため、電圧のドロップダウンが発生。この電圧降下が原因でESP32のハードリセット・再起動が繰り返される。

USB-UARTの電源(USB)とは別に、ESP32の電源(DC12-DC3.3Vコンバータ)を用意することで回避(グランド共通)。

電源のラインノイズ対策:パイパスコンデンサの挿入、電源ラインとグランドラインのリード線をツイストすること。

esp32_dev_board

esp32+switch

LM2596 Step-Down Switching Regulator

CP2102 USB 2.0 To UART

BOOTスイッチを押下した状態でRESETスイッチを押すことで、アップロードモードに切り替わります。アップロード完了後、RESETスイッチを押すことで読み込んだソフトで動作します。

アップロード条件は以下の通りです。
esp32-wifi-scan

ESP32 Pinout Reference

GPIO Input Output Notes
0 pulled up OK outputs PWM signal at boot
1 TX pin OK debug output at boot
2 OK OK connected to on-board LED
3 OK RX pin HIGH at boot
4 OK OK
5 OK OK outputs PWM signal at boot
6 x x connected to the integrated SPI flash
7 x x connected to the integrated SPI flash
8 x x connected to the integrated SPI flash
9 x x connected to the integrated SPI flash
10 x x connected to the integrated SPI flash
11 x x connected to the integrated SPI flash
12 OK OK boot fail if pulled high
13 OK OK
14 OK OK outputs PWM signal at boot
15 OK OK outputs PWM signal at boot
16 OK OK
17 OK OK
18 OK OK
19 OK OK
21 OK OK
22 OK OK
23 OK OK
25 OK OK
26 OK OK
27 OK OK
32 OK OK
33 OK OK
34 OK input only
35 OK input only
36 OK input only
39 OK input only

チップID定義(MACアドレスから)

uint32_t chipId = 0;

void setup() {
  Serial.begin(115200);
}

void loop() {
  for(int i=0; i<17; i=i+8) {
    chipId |= ((ESP.getEfuseMac() >> (40 - i)) & 0xff) << i;
  }

  Serial.printf("ESP32 Chip model = %s Rev %d\n", ESP.getChipModel(), ESP.getChipRevision());
  Serial.printf("This chip has %d cores\n", ESP.getChipCores());
  Serial.print("Chip ID: "); Serial.println(chipId);
  
  delay(3000);

}

LittleFS_esp32

https://www.arduino.cc/reference/en/libraries/littlefs_esp32/

#define USE_LittleFS

#include <FS.h>
#ifdef USE_LittleFS
  #define SPIFFS LITTLEFS
  #include <LITTLEFS.h> 
#else
  #include <SPIFFS.h>
#endif 

Differences with SPIFFS

  • LittleFS has folders, you need to iterate files in folders unless you set #define CONFIG_LITTLEFS_SPIFFS_COMPAT 1
  • At root a “/folder” = “folder”
  • Requires a label for mount point, NULL will not work. Recommended is to use default LITTLEFS.begin()
  • maxOpenFiles parameter is unused, kept for compatibility
  • LITTLEFS.mkdir(path) and LITTLEFS.rmdir(path) are available
  • file.seek() behaves like on FFat see more details
  • file.write() and file.print() when partition space is ending may return different than really written bytes (on other FS is also inconsistent).
  • Speed comparison based on LittleFS_test.ino sketch (for a file 1048576 bytes):
Filesystem Read time [ms] Write time [ms]
FAT 276 14493
LITTLEFS 446* 16387
SPIFFS 767 65622

*The read speed improved by changing #define CONFIG_LITTLEFS_CACHE_SIZE from 128 to 512

ESP WiFiManager

Double Reset Detector