Skip to content

Latest commit

 

History

History
160 lines (122 loc) · 5.59 KB

File metadata and controls

160 lines (122 loc) · 5.59 KB
Supported Targets ESP32-P4 ESP32-S2 ESP32-S3

Multi-Interface Data Logger

This project implements a comprehensive data logging system that captures data from multiple communication interfaces simultaneously and stores them to separate log files on an SD card.

Features

  • USB CDC Host: Supports multiple USB CDC devices (TinyUSB, CP210x, CH34x series)
  • UART Logging: Simultaneous logging from UART1 and UART2
  • SD Card Storage: Automatic file creation and data logging to separate files
  • Hot-pluggable: USB devices can be connected/disconnected during operation
  • Configurable: GPIO pins, baudrates, and features configurable via menuconfig
  • Timestamp Support: Optional timestamp prefixing for all log entries (milliseconds since boot - no real-time clock or internet sync, future feature)

Hardware Requirements

ESP32-S3 Board

  • ESP32-S3 development board with USB-OTG support
  • SD card slot or SPI SD card adapter

Default SD Card SPI Configuration

  • MISO: GPIO 5 (configurable)
  • MOSI: GPIO 4 (configurable)
  • CLK: GPIO 1 (configurable)
  • CS: GPIO 2 (configurable)

Default Pin Configuration

  • UART1: TX=GPIO -1 (no change), RX=GPIO 43, Baudrate=115200
  • UART2: TX=GPIO -1 (no change), RX=GPIO 44, Baudrate=115200
  • USB CDC: Baudrate=115200

Note: All pins and baudrates are configurable via menuconfig

Supported USB Devices

  • CDC-ACM: TinyUSB CDC devices (0x303A:0x4001, 0x303A:0x4002, 0x303A:0x1001)
  • CP210x Series: Silicon Labs USB-to-Serial adapters
  • CH34x Series: WinChipHead USB-to-Serial adapters

Configuration

Use idf.py menuconfig to configure the system:

Data Logger Configuration Menu

  1. SD Card SPI Configuration

    • MISO Pin (default: 5)
    • MOSI Pin (default: 4)
    • CLK Pin (default: 1)
    • CS Pin (default: 2)
  2. UART1 Configuration

    • TX Pin (default: -1, no change)
    • RX Pin (default: 43)
    • Baudrate (default: 115200)
  3. UART2 Configuration

    • TX Pin (default: -1, no change)
    • RX Pin (default: 44)
    • Baudrate (default: 115200)
  4. USB Configuration

    • Baudrate (default: 115200)
  5. General Settings

    • Enable/Disable timestamp in log files (default: no change)

Build and Flash

  1. Configure the project:
idf.py menuconfig
  1. Build and flash the project:
idf.py build
idf.py -p PORT flash monitor

(Replace PORT with the name of the serial port to use.)

File Structure

Source Files

  • main/main.c - Main application, SD card initialization, task management
  • main/usb_logger.c/h - USB CDC logging functionality
  • main/uart_logger.c/h - UART logging functionality
  • main/Kconfig.projbuild - Configuration menu definitions

Log Files (on SD Card)

  • /sdcard/usb.txt - USB CDC data log
  • /sdcard/uart1.txt - UART1 data log
  • /sdcard/uart2.txt - UART2 data log

Usage

  1. Prepare Hardware:

    • Insert formatted SD card into the ESP32-S3 board
    • Connect UART devices to configured pins (optional)
    • Connect USB CDC devices to USB port (optional)
  2. Power On:

    • The system will automatically initialize the SD card
    • Log files will be created if they don't exist
    • The system waits 10 seconds before starting USB host mode (safety delay for firmware flashing)
  3. Operation:

    • Data received on any interface is automatically logged to its respective file
    • USB devices can be hot-plugged (connected/disconnected during operation)
    • All data is also echoed to the console for debugging
    • UART interfaces are configured in RX-only mode by default (TX pins disabled)
  4. Log File Format:

    • With timestamps: [12345] received_data
    • Without timestamps: received_data (default)

Example Output

After flashing and connecting devices, you should see output similar to:

I (256) DATA-LOGGER: Starting Data Logger Application
I (345) DATA-LOGGER: SD card mounted successfully
I (356) DATA-LOGGER: Created new USB log file: /sdcard/usb.txt
I (367) DATA-LOGGER: Created new UART1 log file: /sdcard/uart1.txt
I (378) DATA-LOGGER: Created new UART2 log file: /sdcard/uart2.txt
I (389) USB-CDC: Installing USB Host
I (456) USB-CDC: Installing CDC-ACM driver
I (467) DATA-LOGGER: All logging tasks started
I (478) DATA-LOGGER: Configuration:
I (500) DATA-LOGGER:   SD Card SPI - MISO:5, MOSI:4, CLK:1, CS:2
I (511) DATA-LOGGER:   USB Baudrate: 115200
I (522) DATA-LOGGER:   UART1 - TX:-1, RX:43, Baudrate:115200
I (533) DATA-LOGGER:   UART2 - TX:-1, RX:44, Baudrate:115200
I (544) DATA-LOGGER:   Timestamp: Disabled
I (10533) USB-CDC: Scanning all supported devices...
I (10544) USB-CDC: Opening TinyUSB CDC device 0x303A:0x4001...
I (10755) USB-CDC: Successfully opened TinyUSB CDC device
...
I (11866) USB-CDC: USB data written to file (15 bytes)
I (11877) UART-LOGGER: UART1 data written to file (8 bytes)

Troubleshooting

  • SD Card Issues: Ensure SD card is formatted as FAT32 and properly inserted
  • USB Device Not Detected: Check USB connections and try different USB devices
  • UART No Data: Verify TX/RX pin connections and baudrate settings
  • Build Errors: Ensure ESP-IDF v5.4.0 is properly installed and sourced

Technical Details

  • Task Priorities: All logging tasks use the same priority as the main task
  • Buffer Sizes: USB=512 bytes, UART=1024 bytes
  • Safety Features: 10-second startup delay for firmware flashing, automatic reconnection, error handling
  • Memory Management: Efficient file I/O with immediate flushing for data integrity
  • UART Configuration: RX-only mode by default (TX pins set to -1, no change)