Skip to content
Public template

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

M5Stack Tab5 firmware

ESP-IDF firmware for the M5Stack Tab5: an ESP32-P4 tablet with a 5" 1280x720 MIPI-DSI panel, an ESP32-C6 radio co-processor, a MIPI-CSI camera, a USB-A host port and a removable NP-F550 battery.

The application is an LVGL UI with one page per subsystem, so every driver in the tree can be exercised on the device itself, and the same subsystems are reachable from a host over a line-based control protocol. It covers the whole board — every peripheral the hardware has, connectivity, the fixed-function accelerators, and two independent firmware-update paths.

Use it as a starting point: the board is already brought up, so a new project begins with working drivers rather than with bring-up.

make rename NAME=my_project

That rewrites the project name through the tree. Afterwards, set CONFIG_APP_NAME, CONFIG_APP_BLE_DEVICE_NAME and the USB product string in firmware/main/Kconfig.projbuild and firmware/components/app_usb_device/Kconfig.

What it does

Page Covered by Notes
Keyboard components/tab5_keyboard Tab5 Keyboard accessory over I2C, with hot-plug detection and all three report formats. Keys are forwarded to LVGL as keypad input.
Touch BSP + ui_touch.c GT911 or ST7123/ST7121, probed at boot. The test pad exists to confirm the touch transform matches the display rotation.
Pointer ui_pointer.c What the USB mouse reports against where LVGL draws its cursor, and which screen corners each has reached.
Wi-Fi components/app_wifi Station and soft AP over esp_wifi_remote; scan, associate, DHCP.
BLE components/app_ble NimBLE peripheral and observer, with the controller on the C6.
USB components/app_usb_host Every device on the USB-A port is listed; HID keyboards and mice also drive LVGL.
Power components/app_power Charge enable, QC/PD fast-charge request, USB-A and Grove 5 V rails, antenna select, INA226 measurements, deep sleep, power off.
Camera components/app_camera SC202CS over MIPI-CSI through esp_video's V4L2 interface, scaled and rotated by the PPA, stills encoded by the JPEG block. Frames are only rescaled when something is ready to draw one, which is what keeps the preview and the rest of the interface both moving.
Audio components/app_audio ES8388 speaker with automatic headphone muting, ES7210 dual-microphone capture, WAVE playback and recording.
Storage components/app_storage microSD over 4-bit SDMMC and SPIFFS, browsed with lv_file_explorer. The card has one owner at a time: the firmware, or the USB host in mass-storage mode.
Sensors components/app_sensors BMI270 motion with a live chart, RX8130CE clock and wake alarm.
RS-485 components/app_rs485 Half-duplex SIT3088 bus with hardware driver-enable, a hex transmitter and a traffic monitor.
Accelerators components/app_accel PPA, hardware JPEG and hardware crypto, benchmarked against their software equivalents, and against each other out of PSRAM and internal SRAM.
OTA components/app_ota Two 4 MB slots with rollback; download over HTTP(S), inspect and select slots. A new image is confirmed only if the interface, a filesystem and enough heap are actually there — otherwise it is left to roll back.
System ui_system.c Chip revision, flash size, IDF version, heap and PSRAM. The app version carries the short Git SHA, so a bug report identifies its build.
Log app_ui.c Timestamped log of everything the pages report.

Sixteen pages is more than a tab bar carries legibly, so navigation uses LVGL's lv_menu: a sidebar page of entries and a main page area, with the switching handled by lv_menu_set_load_page_event().

Every text field is wired to one shared lv_keyboard, raised on focus and lowered on confirm — without it there is no way to type an SSID or an OTA URL when neither the Tab5 Keyboard accessory nor a USB keyboard is attached.

The status bar carries one chip per subsystem, so a glance shows what came up.

Only the page on screen runs its timers. The others are paused, so a board left on one tab is not polling the IMU, the SD card and the codec for widgets nobody can see — which also means PERF reads very differently depending on which page is open.

The radio lives on a second chip

The ESP32-P4 has no radio. Wi-Fi and BLE both run on the on-board ESP32-C6-MINI-1U and reach the P4 over SDIO:

  • esp_wifi_remote forwards the ordinary esp_wifi API, so app_wifi.c is written as if the radio were local.
  • esp_hosted carries both that RPC and the BLE HCI byte stream. app_ble_init() calls esp_hosted_bt_host_stack_setup() to bind NimBLE's HCI to the link before nimble_port_init(), and the local controller is compiled out (CONFIG_BT_CONTROLLER_DISABLED).
  • esp_hosted ships a Tab5 board profile (CONFIG_ESP32P4_TAB5_C6_BOARD) that carries the SDIO pin map: CLK 12, CMD 13, D0-D3 on 11/10/9/8, reset on 15.
  • The C6's rail is behind the second IO expander, so bsp_feature_enable(BSP_FEATURE_WIFI, true) has to run before esp_wifi_init().

The C6 must be running matching ESP-Hosted co-processor firmware. Tab5 ships with it; if Wi-Fi never comes up, reflashing the C6 is the first thing to check.

The two USB ports

The ESP32-P4 has two independent USB OTG controllers, which is what lets the board be a host and a device at the same time:

  • USB-A is driven by the high-speed controller. bsp_usb_host_start() claims it, and components/app_usb_host lists whatever is plugged in while esp_lvgl_port routes HID keyboards and mice into LVGL.
  • USB-C is normally the USB-Serial/JTAG peripheral: the log console, esptool, and by default the control console below.

Device mode uses the full-speed controller, whose pads are the same ones USB-Serial/JTAG drives on the USB-C connector — so it replaces USB-Serial/JTAG rather than joining it. That is why CONFIG_APP_USB_DEVICE_ENABLE is off by default: turning it on moves the log console onto the CDC interface and costs esptool its automatic download-mode reset, so reflashing means holding BOOT through a reset.

TinyUSB is what implements device mode, but it is not vendored here: Espressif's espressif/esp_tinyusb component bundles TinyUSB and adds the ESP-IDF glue — PHY setup, the device task, CDC-ACM, MSC and the console redirect — so components/app_usb_device only picks the port and the classes.

make usb-device-build       # CDC-ACM console + control protocol, SD card as mass storage

Mass storage hands the card to the host outright: the firmware drops its filesystem, the card stays initialised without one, and nothing on the device reads or writes files until the mode ends. Leaving and re-entering mounts it again, so captures written before the handover are still there afterwards.

Control console

Every subsystem is reachable from a host over one line-based protocol: query power, switch rails, scan Wi-Fi, drive RS-485, take a photo, and push firmware into the inactive OTA slot with a SHA-256 check. See docs/CONSOLE.md for the full command list.

make console                # raw terminal on the control console
make ota-upload             # push the built image into the inactive slot over USB
make smoke PORT=...         # drive every subsystem and fail on any fault

make smoke is the gate before handing anything over. It answers 39 commands across every subsystem and fails on a panic, a watchdog, a reset or an error from this firmware's own components. It is deliberately silent — the audio check drops the volume to zero around the tone, so it can be run in a room with people in it.

The console can also drive the interface, which is what makes UI behaviour measurable rather than a matter of watching the screen:

UI PAGE Camera
UI PRESS Start preview
UI                          # completed display refreshes — what actually reaches the panel

Requirements

  • Docker, for the ESP-IDF toolchain. No image is built: compose.yaml runs the stock espressif/idf:v6.1 image directly.
  • uv, for the host-side tools (esptool, the serial monitor).
  • clang-format for make style-check.
make setup     # pull the image, install the host tools
make build     # build the product profile
make flash     # write it over USB-C
make monitor   # serial console with backtrace decoding

make help lists everything. make flash picks the first Espressif USB CDC device it finds; pass PORT=/dev/cu.usbmodemXXXX when more than one board is attached.

Layout

compose.yaml                     stock espressif/idf image, workspace mounted at /workspace
Makefile                         every build, flash, monitor and quality target
firmware/                the ESP-IDF project
  partitions.csv                 16 MB: nvs, otadata, phy_init, two 4 MB app slots, 4 MB spiffs
  sdkconfig.defaults             base configuration; profiles layer fragments on top
  main/                          bring-up order and the Kconfig for orientation and BLE name
  components/
    tab5_keyboard/               I2C keyboard accessory driver, hot-plug aware
    app_wifi/  app_ble/          connectivity through the C6
    app_usb_host/                USB Host observer client
    app_usb_device/              TinyUSB device mode: CDC-ACM and mass storage
    app_power/                   charging, rails, antenna select, INA226, deep sleep
    app_camera/                  V4L2 capture, PPA scaling, JPEG stills
    app_audio/                   ES8388 playback and ES7210 capture
    app_storage/                 microSD and SPIFFS
    app_sensors/                 BMI270 and the RX8130CE clock
    app_rs485/                   half-duplex SIT3088 bus
    app_accel/                   PPA, JPEG and crypto, plus benchmarks
    app_console/                 control protocol (esp_console) and serial firmware upload
    app_ota/                     slot management and HTTP(S) updates
    app_ui/                      LVGL: status bar, sidebar, pages, keypad routing
docs/HARDWARE.md                 pin maps and register maps gathered during bring-up
docs/CONSOLE.md                  the control and firmware-upload protocol
docs/PROGRESS.md                 what is verified, what broke and why, what is still open
tools/serial_ota.py              host side of the firmware upload
tools/smoke.py                   the pre-handover check behind `make smoke`

Start with docs/PROGRESS.md if you are picking this up: it records the explanations that turned out to be wrong as carefully as the ones that held, which is the part that saves time.

Build profiles

PROFILE selects which sdkconfig fragments are layered on top of sdkconfig.defaults, and each profile builds into its own directory.

Profile Adds
product (default) nothing
tearing-free two full framebuffers plus LVGL direct mode
verbose debug logging and the LVGL performance overlay
usb-device USB-C in device mode: CDC-ACM console and SD card mass storage
make PROFILE=verbose build
make PROFILE=verbose flash

Editing sdkconfig.defaults does not affect an existing build directory: ESP-IDF only applies defaults to options that are not already in sdkconfig. Run make reconfigure, which deletes the profile's sdkconfig first.

Updating firmware

Two paths, and the board supports both at once.

Over Wi-Fi, from the OTA page:

make build
make ota-serve          # serves the built image on port 8000

Then in the OTA tab, point the URL at http://<your-host>:8000/tab5_app.bin and press Download and install. The image lands in whichever slot is not running; the next restart boots it on probation, and app_ota_confirm_running() — the last thing app_main() does — confirms it, but only if the interface, a filesystem and enough heap are actually there. If it never gets that far, or gets there in worse shape than the image it replaced, the bootloader returns to the previous slot.

Plain HTTP is allowed by CONFIG_APP_OTA_ALLOW_INSECURE_HTTP, which is on by default so a throwaway python -m http.server works. Turn it off for anything that leaves the bench.

Over USB, with no network at all:

make build
make ota-upload

The host hashes the image, the device streams it straight into the inactive slot, and the slot only becomes bootable when the SHA-256 matches. Same rollback behaviour either way.

Display orientation

The panel is addressed natively as 720x1280 portrait, but the Tab5 is a landscape device. CONFIG_APP_UI_ROTATION rotates the UI; the default is 90 degrees, giving 1280x720. A DSI panel cannot swap its own axes, so the rotation is done on the rendered buffer by esp_lvgl_port with the ESP32-P4's PPA doing the work. The Touch tab is the quickest way to confirm that the touch transform followed the rotation.

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages