BOARD_GPIO_PROFILES.md 7.8 KB

Board GPIO profiles

The GPIO manager must not expose every pin supported by an ESP SoC. A pin is available to a user only when the selected complete board profile lists it and declares the capabilities that the requested mode needs.

Policy

  • At most four user-configurable GPIO channels may be active at one time.
  • The board profile is the source of truth for the pins that may be exposed.
  • Camera, SD-card, flash/PSRAM, UART, boot-strapping, status-LED and other board-owned pins are reserved.
  • Board-owned functions (for example the AI-Thinker flash LED) are not user channels and are not exposed through the generic GPIO endpoint.
  • Unknown or unaudited boards fail closed: no user GPIO pin is enabled.
  • A SoC-valid pin is not automatically a board-safe pin.
  • PWM and other peripheral modes must not be enabled until both the board profile and the GPIO driver backend implement and validate them.

Current profiles

AI-Thinker ESP32-CAM

The current build selects BOARD_ESP32CAM_AITHINKER and defines SD_USE_ONE_LINE_MODE.

With __SD_USE_ONE_LINE_MODE__ enabled, GPIO13 (DAT3) is available after SD-card mount. main.cpp sets its pull-up before mounting; the generic GPIO handler is created only after the mount has succeeded. DAT3 is not part of the active 1-bit data bus, so the handler may then reconfigure GPIO13 as a digital input or output.

GPIO12 (DAT2) is also unused by the active 1-bit SDMMC data bus, but it is the ESP32 MTDI strapping pin. The AI-Thinker SD socket connects DAT2 to GPIO12, so a card-side pull-up can affect the boot-time VDD_SDIO strap. The profile now exposes GPIO12 only when the firmware reads all three eFuse fields XPD_SDIO_FORCE, XPD_SDIO_REG, and XPD_SDIO_TIEH as set, which forces VDD_SDIO to 3.3 V independently of MTDI. Otherwise GPIO12 remains reserved. This check is read-only: the firmware never programs eFuses. The 3.3 V setting is permanent and must be programmed separately by the owner after confirming the module's flash requirements. If the build changes to 4-bit SD mode, both DAT2 and DAT3 remain reserved.

GPIO0, GPIO1, GPIO3, GPIO4 and all camera/active-SD/flash/memory pins are not general-purpose user pins. GPIO12 is a special conditional case: it is available only when VDD_SDIO is permanently forced to 3.3 V by eFuse. In particular:

  • GPIO0 is the camera XCLK and a boot-strapping pin.
  • GPIO1/GPIO3 are UART0 TX/RX.
  • GPIO4 is the board flash LED.
  • GPIO12 is DAT2/MTDI and remains reserved unless the fixed 3.3 V eFuse state is verified.
  • GPIO2, GPIO14 and GPIO15 belong to the active 1-bit SDMMC interface.
  • Camera, flash/PSRAM and board status LED pins remain reserved.

allexoK ESP32-S3-POE-A-CAM+ (BOARD_ESP32_S3_ALEKSEI reference)

The allexoK fork's esp32s3-test branch provides a concrete board definition and a working PlatformIO environment named esp32s3-aleksei. Its current pin map in code/include/defines.h assigns:

Function GPIO
Ethernet power enable 45
Peripheral power enable 46
W5500 SPI MOSI / MISO / CLK / CS / INT 1 / 14 / 21 / 39 / 38
SDMMC CLK / CMD / D0 40 / 42 / 41
SD DAT1 / DAT2 / DAT3 (4-bit mode) 4 / 12 / 13
Camera XCLK / SIOD / SIOC 15 / 4 / 5
Camera D7..D0 16 / 17 / 18 / 47 / 10 / 8 / 9 / 11
Camera VSYNC / HREF / PCLK 6 / 7 / 13
Board status LED / camera flash LED 48 / 48
External WS2812 chain 12
Battery ADC 2

The fork's history documents an important correction. In the initial running version, camera D4 was assigned to GPIO12. Commit 9370e60d33 moved the external WS281x channel to GPIO47; commit d3650e188d then explicitly restored GPIO12 for the LED chain and assigned camera D4 to GPIO47. Therefore the current mapping is camera D4 = GPIO47 and WS2812 = GPIO12. Never reuse the earlier GPIO12 camera-D4 mapping.

The current fork selects Octal PSRAM in sdkconfig.esp32s3-aleksei and uses GPIO26-GPIO37 for flash/PSRAM connections in this module/build configuration. All of these pins are reserved, in addition to the camera, SDMMC, W5500, power-control, UART, USB/JTAG, strap and LED pins listed above. The board-specific profile added here deliberately exposes no general-purpose user GPIOs. The four-channel limit remains a maximum, not a promise that every board has four free pins.

Source references:

  • allexoK/AI-on-the-edge-device, branch esp32s3-test, commit 83336e031c8d89dc75a89859fb616e14f19213e3
  • code/include/defines.h, code/platformio.ini, code/sdkconfig.esp32s3-aleksei, code/main/main.cpp
  • Pin correction history: 9370e60d33 and d3650e188d

This is a board-specific reference only. Confirm the exact PCB revision, module variant and schematic errata before using the profile on a different ESP32-S3 carrier or module.

Adding another board (including ESP32-S3)

A new board must have its own profile. Before adding any user pin, audit the complete module and carrier-board schematics, including camera wiring, SD-card wiring, flash/PSRAM package and module variant, USB/JTAG, UART, strapping pins, status LEDs, and any external peripherals.

ESP32-S3 SoC GPIO availability alone is not sufficient. For example, GPIO0, GPIO3, GPIO45 and GPIO46 are strapping pins; GPIO19/GPIO20 may be used by USB Serial/JTAG; GPIO26-GPIO32 are commonly used by flash/PSRAM, and GPIO33- GPIO37 may be used by octal flash/PSRAM depending on the module. The exact reserved set depends on the selected ESP32-S3 module and board.

Until a specific ESP32-S3 board has been audited, its profile must expose no user GPIOs. Do not copy the AI-Thinker pin list or create a generic ESP32-S3 allow-list.

GPIO capability endpoint

The authenticated existing GET /GPIO endpoint also supports GET /GPIO?capabilities=1. This read-only request returns JSON with the active profile name, the maximum channel count, and each whitelisted pin with its capability bitmask:

{
  "profile": "board profile name",
  "maxChannels": 4,
  "pins": [
    { "gpio": 25, "capabilities": 19 }
  ]
}

Capability bits are defined in board_gpio_profile.h: input=1, output=2, pull-up=4, pull-down=8, interrupt=16, PWM=32. The firmware remains the authoritative validator; hiding or disabling a browser control is not a security boundary.

The configuration page now creates its GPIO channel controls from the profile response, and the parameter parser registers GPIO0-GPIO48. Only pins returned by the active profile are serialized from the browser. The firmware parser still independently validates every configured pin and accepts no more than four user channels.

The supplied test configuration contains mappings for AI-Thinker ESP32-CAM, WROVER-KIT, Freenove ESP32-S3-CAM, and ESP32-S3-ETH V1/V2. These mappings are useful evidence of existing board resource assignments, but do not by themselves prove that any unused pin is safe for general-purpose use. The Freenove mapping assigns GPIO2 to the generic handler and also to the status LED, and GPIO48 to the generic handler and flash LED; both are therefore reserved. The ETH V1/V2 mappings assign GPIO33-GPIO36 to the generic handler, but the exact module flash/PSRAM variant and full carrier wiring still need verification. Consequently these supplied S3 profiles currently fail closed with an empty user-pin whitelist.

Build integration still needs verification: the checked-in code/include/defines.h currently contains board branches for BOARD_WROVER_KIT, BOARD_M5STACK_PSRAM, and BOARD_ESP32CAM_AITHINKER, but not the supplied Freenove or S3-ETH board branches. The S3 profile additions must not be considered build-ready until the selected S3 board definitions and build environments are integrated and compiled. The supplied WROVER config uses the name BOARD_WROVER_KIT_ESP32, whereas the current checked-in definitions use BOARD_WROVER_KIT; this naming difference also needs reconciliation.