ricardgb opened a new issue, #22462:
URL: https://github.com/apache/nuttx/issues/22462

   **Description**
   
   On the ESP32-S3, a build with `CONFIG_NO_SERIAL_CONSOLE=y` that uses UART0 
as an ordinary serial
   port (`/dev/ttyS0`, for SLIP or another protocol) gets a dead port: nothing 
is sent and nothing
   is received.
   
   Such a build does not compile today, because of 
espressif/esp-hal-3rdparty#20. With the fix
   proposed there (espressif/esp-hal-3rdparty#21: `CONFIG_ESP_CONSOLE_NONE`, 
console UART number
   `-1`, the ESP-IDF convention) it compiles and boots, and the HAL then treats 
UART0 as an unused
   peripheral at startup. That is right for the HAL, but the NuttX driver
   (`arch/xtensa/src/esp32s3/esp32s3_lowputc.c`) does not undo it:
   
   1. **Clock.** `esp_perip_clk_init()` (`esp32s3/clk.c`, the `#if 
CONFIG_ESP_CONSOLE_UART_NUM != 0`
      blocks) gates the clock of UART0 and holds it in reset. 
`esp32s3_lowputc_enable_sysclk()`
      enables the clock only `if (priv->id > 0)`, because UART0 has no entry in 
`periph_module_t`.
      So UART0 stays without clock and sends nothing.
   2. **RX signal.** `bootloader_console_init()` (the `CONFIG_ESP_CONSOLE_NONE` 
variant in
      `bootloader_console.c`) connects the RX signal of UART0 to a constant 
level in the GPIO matrix
      (`GPIO_FUNC12_IN_SEL_CFG` read back as `0xb8`). 
`esp32s3_lowputc_config_pins()` does not
      connect the RX signal when the pins are the IO_MUX ones, so with the 
clock fixed UART0 sends
      but receives nothing.
   
   **Reproduce (esp32s3-devkit:nsh, master `a8bb89bf680`)**
   
   Replace `apps/examples/hello/hello_main.c` with 
`nuttx-esp32s3-uart0-no-console-repro.c` below
   (opens `/dev/ttyS0`, prints a banner, answers every line), then:
   
   ```sh
   # HAL with the fix of espressif/esp-hal-3rdparty#21
   export ESP_HAL_3RDPARTY_URL=https://github.com/ricardgb/esp-hal-3rdparty.git
   export ESP_HAL_3RDPARTY_VERSION=c657ca9657b7a82a993d9de4ab9f94e1f499e972
   export DISABLE_GIT_DEPTH=1
   
   ./tools/configure.sh esp32s3-devkit:nsh
   kconfig-tweak --disable UART0_SERIAL_CONSOLE --enable NO_SERIAL_CONSOLE \
                 --disable DEV_CONSOLE --disable NSH_CONSOLE \
                 --disable SYSTEM_NSH --disable NSH_LIBRARY --enable 
EXAMPLES_HELLO \
                 --set-str INIT_ENTRYPOINT hello_main --set-str INIT_ENTRYNAME 
hello
   make olddefconfig && make
   ```
   
   Flash it and listen on UART0 (115200) from the host; after the banner send 
`hello 123`.
   
   Result on an ESP32-S3 (rev v0.2) with a USB-serial converter on UART0:
   
   | | After the messages of the ROM | Answer to `hello 123` |
   |---|---|---|
   | master + HAL fix | nothing | nothing |
   | master + HAL fix + clock change only | `UART0 is open, send a line` | 
nothing |
   | master + HAL fix + both changes | `UART0 is open, send a line` | `got: 
hello 123` |
   
   **Seen first on a custom board**
   
   ESP32-S3 board with SLIP on UART0 and no console. There the board is set to 
reset on a crash,
   and the first open of UART0 gave a reset loop: `EXCCAUSE` 6 (integer divide 
by zero) in
   `esp32s3_lowputc_baud()`, with the registers of UART0 reading zero. With the 
clock change the
   board sent SLIP frames and received none; with both changes the link works 
(ping 100 of 100
   with 900 bytes, HTTP and telnet over it).
   
   **Proposed fix**
   
   PR to follow: in `esp32s3_lowputc_enable_sysclk()` enable the clock of UART0 
and release its
   reset in the system registers, and in `esp32s3_lowputc_config_pins()` 
connect the RX signal to
   the RX pin.
   
   **Not checked**
   
   The ESP32 and the ESP32-S2 (their HAL `sdkconfig.h` has the same gap, see
   espressif/esp-hal-3rdparty#20) and the RISC-V Espressif chips.
   
   <details>
   <summary>nuttx-esp32s3-uart0-no-console-repro.c (replaces 
apps/examples/hello/hello_main.c)</summary>
   
   ```c
   /****************************************************************************
    * Reproducer: UART0 of the ESP32-S3 as an ordinary serial port in a build
    * with no serial console.  Replaces apps/examples/hello/hello_main.c.
    *
    * Opens /dev/ttyS0 (UART0, 115200 8N1, GPIO43/GPIO44), prints a banner
    * and then answers every line that it receives.
    
****************************************************************************/
   
   #include <nuttx/config.h>
   
   #include <fcntl.h>
   #include <stdio.h>
   #include <string.h>
   #include <unistd.h>
   
   int main(int argc, FAR char *argv[])
   {
     static const char banner[] = "UART0 is open, send a line\r\n";
     char line[64];
     char out[80];
     size_t n = 0;
     char ch;
     int fd;
   
     sleep(1);
   
     fd = open("/dev/ttyS0", O_RDWR);
     if (fd < 0)
       {
         return 1;
       }
   
     write(fd, banner, sizeof(banner) - 1);
   
     for (; ; )
       {
         if (read(fd, &ch, 1) != 1)
           {
             continue;
           }
   
         if (ch != '\n' && ch != '\r' && n < sizeof(line) - 1)
           {
             line[n++] = ch;
             continue;
           }
   
         line[n] = '\0';
         n = 0;
         snprintf(out, sizeof(out), "got: %s\r\n", line);
         write(fd, out, strlen(out));
       }
   
     return 0;
   }
   ```
   
   </details>
   
   *Disclosure: this report and the patch were prepared with the help of an AI 
agent (Claude Code,
   Anthropic); the failure and the fix were reproduced on real hardware and 
human-reviewed.*
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to