UART not Initalizing

MA_EMBEDDED
Posts: 1
Joined: Fri May 16, 2025 1:25 pm

UART not Initalizing

Postby MA_EMBEDDED » Fri May 16, 2025 1:56 pm

Hi everyone,

I'm working with the ESP32-S3 N8R2 chip using ESP-IDF version 5.3.3 in VS Code, and I’ve run into an issue with UART0 initialization that happens randomly.

Setup:

- ESP32-S3 N8R2
- ESP-IDF 5.3.3
- Using all three UARTs (UART0, UART1, UART2) for serial communication
- UART0 is initialized at startup inside app_main() using a FreeRTOS queue-based event handler
- UART1 is initialized later in the code using the exact same method, and it works reliably every time

Issue:

Sometimes UART0 initializes correctly, and other times it doesn't — the behavior is inconsistent. When it fails, I get the following debug output:

E (00:00:00.264) uart: uart_param_config(846): register back up is not supported
E (00:00:00.265) UART CLASS: UART parameter config failed: ESP_ERR_NOT_SUPPORTED (code 262)

What I’ve Tried:
1. I removed the default console debug output on UART0 via sdkconfig, thinking it might be a conflict — but the problem still persists.
2. I tried moving the UART0 initialization to a later point in the code (similar to UART1), but it still occasionally fails.
3. I reviewed the initialization code against the official ESP-IDF UART example and am using the same structure.

Additional Notes:
1. I need to use all three UART ports for device communication, so swapping or disabling UART0 isn’t an option.
2. I’ve attached debug output screenshots showing both successful and failed initialization cases for reference.
3. I also provided the code portions where I initialize the UART and the code to initialize the UART.

Has anyone else encountered this kind of sporadic behavior with UART0 on the S3? I’d really appreciate any insights or suggestions.

Thanks in advance!

This snip-it of the code is where I am initializing the UART just on startup:

QueueHandle_t DsPICuartQueue = nullptr; // Define the queue

Code: Select all

extern "C" {
void app_main() {

  gpio_reset_pin(DsPIC_IRQ_PIN);
  gpio_set_direction(DsPIC_IRQ_PIN, GPIO_MODE_OUTPUT);
  gpio_set_level(DsPIC_IRQ_PIN, 1);

  std::shared_ptr<UART> dspic_uart = std::make_shared<UART>(
      UART_NUM_0, 21, 14, 115200, UART_DATA_8_BITS, UART_PARITY_DISABLE,
      UART_STOP_BITS_1, UART_HW_FLOWCTRL_DISABLE);

  if (dspic_uart == nullptr) {
    DEBUG_LOG("Failed to create dspic_uart");
    throw std::runtime_error("Failed to create dspic_uart");
  }
  //esp_err_t result = dspic_uart->init(512);
  esp_err_t result = dspic_uart->init(1024, DsPICuartQueue, dspic_event_task, "dspic_event_task", 5048);

  if (result != ESP_OK) {
    DEBUG_LOG("uart not initalized \n\r");
  } else {
    DEBUG_LOG("uart initalized correctly\n\r");
  }
  }
  }
This is the UART init function that creates the FreeRTOS Queue event handler:

Code: Select all

esp_err_t UART::init(
  int buffer_size, QueueHandle_t &queue, TaskFunction_t pxTaskCode,
  const char *const pcName,
  const uint32_t usStackDepth /*, char pattern, uint8_t pattern_len*/) {
  LOG_DEBUG("UART init %d", 2);

  uart_driver_delete(uart_num);
  vTaskDelay(pdMS_TO_TICKS(10));
  
  esp_err_t ret = uart_param_config(uart_num, &uart_config);
  if (ret != ESP_OK) 
  {
    ESP_LOGE("UART CLASS", "UART parameter config failed: %s\n", esp_err_to_name(ret));
    return ret;
  }

  ret = uart_set_pin(uart_num, tx_pin, rx_pin, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
  if (ret != ESP_OK){
    ESP_LOGE("UART CLASS", "UART set pin failed: %s\n", esp_err_to_name(ret));
    return ret;
  } 

  ret = uart_driver_install(uart_num, buffer_size, buffer_size, UART_QUEUE_SIZE, &queue, 0);
  if (ret != ESP_OK) 
  {
    ESP_LOGE("UART CLASS", "UART driver install failed: %s\n", esp_err_to_name(ret));
    return ret;
  }

  if (queue == NULL) {
    LOG_ERROR("UART queue initialization failed. %s", "");
    return ret;
  }

  // Create a task to handler UART event from ISR
  BaseType_t result = xTaskCreatePinnedToCoreWithCaps(pxTaskCode, pcName, usStackDepth, NULL, 12, NULL, 0, MALLOC_CAP_SPIRAM);
  if (result != pdPASS) {
    LOG_ERROR("Failed to create uart1_event_task %d", result);
  }

  LOG_DEBUG("UART init %d done", 2);

  is_driver_installed = true;
  return ESP_OK;
}
Attachments
UART not initalized_.JPG
UART not initalized_.JPG (292.83 KiB) Viewed 8125 times
UART initalized correctly_.JPG
UART initalized correctly_.JPG (307.17 KiB) Viewed 8125 times

Who is online

Users browsing this forum: No registered users and 1 guest