Reading from USB port on ESP32-S3
Posted: Thu Dec 26, 2024 7:48 pm
I'm feeling particularly dumb...
Working on a project with an ESP32-S3-WROOM with built in USB port. I'm using the USB port to program the ESP32 and monitor / debug the code.
When the device first boots I need to write some basic parameters to it - these are device specific, so not hard coded.
My plan was to use the serial monitor in VS Code (or a python script) to write these parameters into the device.
I'd also like to install a device specific private key
I've been looking at the different USB/UART examples in the IDF - tiny USB seems like overkill for this simple application.
In the main application, printf is directed to the USB output and is visible in the debug / serial console in VS Code - so stdout goes to the USB port.
On this basis, I was hoping to use stdin to read from the USB port. Simple...
However the following very basic code does not appear to be work. When I send some text from the computer to the USB port it's not being picked up by the code.
Any suggestions very much appreciated.
Working on a project with an ESP32-S3-WROOM with built in USB port. I'm using the USB port to program the ESP32 and monitor / debug the code.
When the device first boots I need to write some basic parameters to it - these are device specific, so not hard coded.
My plan was to use the serial monitor in VS Code (or a python script) to write these parameters into the device.
I'd also like to install a device specific private key
I've been looking at the different USB/UART examples in the IDF - tiny USB seems like overkill for this simple application.
In the main application, printf is directed to the USB output and is visible in the debug / serial console in VS Code - so stdout goes to the USB port.
On this basis, I was hoping to use stdin to read from the USB port. Simple...
However the following very basic code does not appear to be work. When I send some text from the computer to the USB port it's not being picked up by the code.
Any suggestions very much appreciated.
Code: Select all
/* USB stdin/stdout */
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/gpio.h"
#include "esp_log.h"
#include "sdkconfig.h"
void read_stdin_task(void *pvParameters) {
char buffer[100];
while (1) {
printf("Enter some text: \n");
if (fgets(buffer, sizeof(buffer), stdin) != NULL) {
printf("You entered: %s\n", buffer);
}
vTaskDelay(pdMS_TO_TICKS(1000)); // Delay to avoid busy looping
}
}
void app_main(void)
{
xTaskCreate(read_stdin_task, "read_stdin_task", 4096, NULL, 5, NULL);
while (1) {
vTaskDelay(pdMS_TO_TICKS(1000));
}
}