Introduction #
Industrial edge controllers often need to exchange logs, calibration tables, and backups with removable media without a host computer. The ESP32-S3 in the NORVI X1 has a native Full-Speed USB peripheral that can act as a USB Host for Mass Storage Class (MSC) flash drives formatted as FAT32.
The NORVI X-BK0 expansion module breaks out the X1’s USB differential pair (USBP/USBN) and regulated 5V/GND rails to screw terminals. Wiring a Type-A female USB receptacle to these terminals gives the X1 a rugged, dedicated USB Host port without an OTG adapter.
This tutorial covers the X-BK0 wiring, Arduino IDE configuration, firmware architecture, and a commissioning procedure that reads /norvi_log.txt, writes an identical copy (/norvi_log_cpy.txt), and displays the text on the onboard ST7789 TFT with touch scrolling.
System Architecture #
The system bridges the ESP32-S3 native USB host controller through the X-BK0 expansion bus to an external Type-A female USB receptacle, while driving the SPI TFT display and I2C capacitive touchscreen on the NORVI X1 front panel.
Type-AExp. BusSPI / I2CST7789 TFT andCST816S Touch 240 × 320NORVI X1 ESP32-S3USB HostNORVI X-BK0Type-A FemaleUSBP/N, 5V, GNDUSB Flash Drive FAT32 MSC/norvi_log.txt
Figure 1: Signal and power path from the USB flash drive through the X-BK0 expander to the NORVI X1
Operational Sequence #
- Peripheral Isolation and Bus Init. On boot, the sketch parks unused chip-select lines on the shared SPI bus (W5500_CS and SD_CS), initializes I2C for the CST816S touch controller, and starts the ST7789 display.
- USB Host Enumeration. USBHost.begin() activates the ESP32-S3 USB peripheral in Host Mode across the X-BK0 expansion interface. While waiting for media, the header status dot blinks yellow and the status card displays PLUG PENDRIVE….
- Filesystem Mount. When a flash drive is plugged into the Type-A female socket wired to X-BK0, USBHostMSC.mounted() becomes true, the status dot switches to green, and USBMSCFS.begin() mounts the FAT32 partition at /usb.
- Buffered Read, Write, and Display. The controller opens /norvi_log.txt for reading and creates
/norvi_log_cpy.txt for writing. Data is transferred in 128-byte blocks, word-wrapped with uniform indentation, and streamed live to the display.
- Safe Unmount and Touch Inspection. After closing both files, USBMSCFS.end() unmounts the volume cleanly so the drive can be removed without file-allocation-table corruption. The operator can drag vertically across the text pane to review long files.
Hardware Components #
| Component | Role | Key details |
|---|---|---|
| NORVI X1 (CPU-S3) | Host controller | ESP32-S3 dual-core MCU, native USB PHY (GPIO 19/20),2.0 in ST7789 TFT (240 × 320), CST816S capacitive touch, 24 V DC supply |
| NORVI X-BK0 | Expansion breakout | Side-mounted expansion module breaking out USBP, USBN, 5V, and GND terminals from the X1 expansion connector |
| USB Type-A Female Connector | Host receptacle | 4-pin USB Type-A female socket (breakout board or panel-mount pigtail) wired to the X-BK0 terminals |
| USB Flash Drive | Mass storage | USB 2.0/3.0 flash drive formatted as FAT32 containing/norvi_log.txt in the root directory |
| 24 V DC Power Supply | Main power | Powers the NORVI X1 and regulates the internal 5V rail delivered to the X-BK0 and flash drive |
Pin Allocation and Shared Bus Management #
| Function | GPIO /Terminal | Notes |
|---|---|---|
| USB Host Data (D− / D+) | IO19 / IO20 | Routed via the X1 expansion port to USBN and USBPon X-BK0 |
| SPI Bus (MOSI / MISO / SCLK) | IO11 / IO13 / IO12 | Shared across TFT, W5500 Ethernet, and SD card reader |
| TFT Display (CS / DC / RST) | IO45 / IO46 /−1 | ST7789 panel driven at 10 MHz SPI; software reset (−1) avoids conflict with TOUCH_INT |
| SPI Chip-Select Parks | IO1 / IO42 | W5500_CS (IO1) and SD_CS (IO42) driven HIGH at boot to prevent SPI bus contention |
| Capacitive Touch (I2C) | IO8 / IO9 | SDA = 8, SCL = 9, INT = 47, RST = 48 (CST816S ataddress 0x15) |
Hardware Assembly and X-BK0 Wiring #
Wire the Type-A Female USB Connector to X-BK0 #
Wire the four pins of the USB Type-A female receptacle to the corresponding terminals on the X-BK0 expander according to Table 3.
| X-BK0Terminal | USB Type-A Pin | Standard Wire Color | Function |
|---|---|---|---|
| 5V | Pin 1 (VBUS) | Red | +5 V DC power output to the flash drive |
| USBN | Pin 2 (D−) | White | USB differential data negative (GPIO 19) |
| USBP | Pin 3 (D+) | Green | USB differential data positive (GPIO 20) |
| GND | Pin 4 (GND) | Black | Power and signal ground reference |

Verify Polarity and Shared USB Lines #
Check 5V and GND before inserting media: Reversing 5V and GND on the Type-A female connector will immediately damage an inserted USB flash drive. Verify 5.0 V across Pin 1 and Pin 4 with a multimeter before plugging in a drive.
Keep data leads short and twisted: Keep the USBP and USBN wires short (under 15 cm) and twisted together to maintain USB signal integrity.
Programming vs. Host Mode: Because the X-BK0 USBP/USBN terminals share GPIO 19/20 with the NORVI X1 programming port, disconnect the flash drive from the X-BK0 receptacle whenever uploading firmware from a PC.
Mount the X-BK0 Expander #
- Switch off the 24 V DC supply before attaching or wiring expansion hardware.
- Mount the NORVI X-BK0 module on the DIN rail immediately beside the NORVI X1 and press it firmly onto the side expansion bus connector until latched.
- Connect the 24 V DC industrial supply to the +24V and GND power terminals on the NORVI X1.
Arduino IDE Configuration and Libraries #
Board Settings #
Select ESP32S3 Dev Module as the board and configure the following under Tools before compiling and uploading (Table 4).
| Setting | Value |
|---|---|
| Board | ESP32S3 Dev Module |
| USB CDC On Boot | Disabled |
| CPU Frequency | 240MHz (WiFi) |
| Core Debug Level | None |
| USB DFU On Boot | Disabled |
| Erase All Flash Before Sketch Upload | Disabled |
| Events Run On | Core 1 |
| Flash Mode | QIO 80MHz |
| Flash Size | 16MB (128Mb) |
| JTAG Adapter | Disabled |
| Arduino Runs On | Core 1 |
| USB Firmware MSC On Boot | Disabled |
| Partition Scheme | Default 4MB with spiffs (1.2MB APP/1.5MB SPIFFS) |
| PSRAM | QSPI PSRAM |
| Upload Mode | USB-OTG CDC (TinyUSB) |
| Upload Speed | 921600 |
| USB Mode | Hardware CDC and JTAG |
USB CDC On Boot must stay Disabled so the CDC serial device does not claim the USB peripheral before USBHost.begin() runs.
Required Libraries #
Install the following libraries via the Arduino Library Manager or vendor repository:
| Library | Header(s) | Purpose |
|---|---|---|
| ESP32 USB Host MSC | USBHost.h, USBHostMSC.h, USBMSCFS.h | Enumerates USB Mass Storage devices on USBP/USBNand mounts FAT32 partitions [1] |
| Adafruit GFX & ST7789 | Adafruit_GFX.h, Adafruit_ST7789.h | Renders header banners, status cards, justified text rows, and scrollbars [2] |
| CST816S Touch Driver | CST816S.h | Reads capacitive touch coordinates over I2C for bidirectional scrolling [3] |
Firmware Architecture and Key Routines #
Shared SPI Bus and Pin Conflict Prevention #
On the NORVI X1, the ST7789 TFT controller shares SPI lines (SCLK=12, MISO=13, MOSI=11) with the W5500 Ethernet chip (CS=1) and microSD slot (CS=42). In addition, GPIO 47 is wired to the capacitive touch interrupt (TOUCH_INT). Driving W5500_CS and SD_CS high before calling SPI.begin() isolates the TFT, while passing -1 as TFT_RST prevents display resets from disturbing the CST816S interrupt line.
- FAT32 Read and Byte-for-Byte Write (runUsbReadWrite())
Once USBHostMSC.mounted() returns true, runUsbReadWrite() executes the file transfer pipeline:
- Mount Volume: USBMSCFS.begin(“/usb”, 10, false) mounts the first FAT32 partition on the flash drive.
- Open Source and Destination: USBMSCFS.open(“/norvi_log.txt”, FILE_READ) opens the source file, and USBMSCFS.open(“/norvi_log_cpy.txt”, FILE_WRITE) creates or overwrites the target copy.
- Chunked Transfer and Pacing: Data is read in 128-byte chunks (rf.read(data, 128)) and immediately written (wf.write(data, n)). A proportional delay scaled by rf.size() paces screen updates so the operator can observe live streaming.
- Safe Unmount: Both file handles are closed with .close() and USBMSCFS.end() flushes cached FAT sectors before reporting R/W COMPLETE.
Word-Wrapped Justification and Touch Scrolling #
To display arbitrary text files cleanly on a 240 × 320 portrait screen:
- Word Wrapping (printFileLine): Paragraphs are split at word boundaries up to 35 characters (210 px), stripping leading spaces so every row aligns flush at x = 18 while paragraph starts receive a yellow > marker at x = 6.
- Full Justification (drawJustifiedLine): Non-final wrapped rows distribute extra horizontal pixels evenly across inter-word spaces so both left and right text edges align cleanly.
- Bidirectional Touch Scroll (touchScrollTask): Up to 250 wrapped rows are retained in logBuf. Because the display uses setRotation(2), vertical touch coordinates are inverted (ty = 319 – touch.data.y). Dragging downward scrolls down toward later lines, dragging upward scrolls up toward earlier lines,
and a right-edge scrollbar indicates position.
Three-State Header Blink Indicator #
The circular heartbeat indicator at top-right ((228, 14)) communicates hardware status at a glance:
| Indicator Color | System Condition | Trigger Logic |
|---|---|---|
| Yellow (blinking) | Ready / Idle | I2C touch healthy and USB Host initialized, waiting for flash drive |
| Green (blinking) | Media Connected | USB flash drive enumerated on X-BK0 and mounted (st.mounted == true) |
| Red (blinking) | Hardware / Bus Fault | CST816S I2C check failed (0x15 NACK) orUSBHost.begin() failed |
Commissioning and Test Procedure #
- Prepare the Sample File (norvi_log.txt)
Format a USB flash drive as FAT32 (allocation unit size: Default) on a PC and save the following multi-line text as norvi_log.txt in the root directory:
Step-by-Step Verification #
- Ensure no flash drive is inserted into the X-BK0 USB connector, then flash the arduino code onto the NORVI X1 using the board settings in Section 4.
- Disconnect the PC programming cable and power the NORVI X1 from the 24 V DC supply.
- Verify that the TFT shows PLUG PENDRIVE… in the status card and a blinking yellow dot in the upper-right header (see Figure 3).
- Insert the prepared FAT32 flash drive into the Type-A female connector wired to the X-BK0 expander. Observe the status sequence: PENDRIVE FOUND → OPENING FILE… → READING & COPYING… → R/W COMPLETE, while the indicator turns green (see Figure 4).
- Slide a finger down and up across the FILE CONTENT: area to verify smooth bidirectional scrolling and scrollbar tracking.
- Unplug the flash drive (the display clears and returns to PLUG PENDRIVE… with a yellow dot), insert it into a PC, and confirm that norvi_log_cpy.txt matches norvi_log.txt byte-for-byte.


Troubleshooting #
| Symptom | Likely cause | Remedy |
|---|---|---|
| Stays on PLUG PENDRIVE… whendrive is inserted | USBP and USBN swapped, loose X-BK0 connection, or missing 5 V | Verify USBN → Pin 2 (D−), USBP → Pin 3 (D+), check 5 V on Pin 1, and re-seat X-BK0 onto X1 |
| FAT32 MOUNT FAIL | Flash drive formatted as exFAT or NTFS | Reformat the flash drive as FAT32 (use a ≤ 32 GB partition if Windows hides FAT32) |
| SOURCE FILE FAIL | Missing or misnamed input file | Verify norvi_log.txt is in the root folder (/) with exact lowercase naming |
| Header beater dot blinks red | CST816S I2C NACK orUSB Host init error | Check SDA=8, SCL=9, ensure TFT_RST is −1, and power-cycle the 24 V supply |
| Display remains black | Shared SPI bus contention | Confirm W5500_CS (IO1) and SD_CS (IO42) are driven HIGH before SPI.begin() |
| Cannot upload sketch from Arduino IDE | Flash drive still attached to X-BK0 or USB in Host Mode | Unplug the drive from X-BK0; hold BOOT while pressing RESET on the X1 to enter download mode |
References #
Explore technical files and available resources.
View on GitHub ↗- Espressif Systems, ESP32-S3 Technical Reference Manual: USB On-The-Go (USB), v1.4, 2025.
- Adafruit Industries, “Adafruit-GFX-Library & Adafruit-ST7735-Library,” GitHub repository. [Online]. Available: https://github.com/adafruit/Adafruit-ST7735-Library (accessed Nov. 23, 2026).
Explore technical files and available resources.
View on GitHub ↗- F. Biego, “CST816S: Arduino library for the CST816S touch controller,” GitHub repository. [Online]. Available: https://github.com/fbiego/CST816S (accessed Nov. 23, 2026).
- NORVI, “NORVI X1 Industrial ESP32-S3 Controller Datasheet,” ICONIC DEVICES. [Online]. Available: https://norvi.io (accessed Nov. 23, 2026).
Explore technical files and available resources.
View on GitHub ↗