Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Arduino Nano ESP32 board] Reboot loop upon using Serial0 #9662

Closed
1 task done
zul00 opened this issue May 21, 2024 · 10 comments
Closed
1 task done

[Arduino Nano ESP32 board] Reboot loop upon using Serial0 #9662

zul00 opened this issue May 21, 2024 · 10 comments
Assignees
Labels
IDE: PlaformIO Issue relates to PlatformIO IDE Type: Question Only question Type: 3rd party Boards

Comments

@zul00
Copy link

zul00 commented May 21, 2024

Board

Arduino Nano ESP32

Device Description

Default devkit from Arduino

Hardware Configuration

The UART0 bus is connected to an FTDI serial adapter

Version

latest master (checkout manually)

IDE Name

PlatformIO

Operating System

Ubuntu 22.04

Flash frequency

240Mhz

PSRAM enabled

yes

Upload speed

115200

Description

My platform was on espressif32@6.7.0 which uses arduino@2.0.16.
When using the setup above I got a reboot loop upon using Serial0, I expect there is no reboot loop.

Below is the message that was captured from UART0 port

22:42:31.537 > ESP-ROM:esp32s3-20210327
22:42:31.887 > Build:Mar 27 2021
22:42:31.887 > rst:0xc (RTC_SW_CPU_RST),boot:0x8 (SPI_FAST_FLASH_BOOT)
22:42:31.887 > Saved PC:0x4202a9b2
22:42:31.887 > SPIWP:0xee
22:42:31.887 > mode:DIO, clock div:1
22:42:31.887 > load:0x3fce3808,len:0x44c
22:42:31.887 > load:0x403c9700,len:0xbe4
22:42:31.887 > load:0x403cc700,len:0x2a68
22:42:31.887 > entry 0x403c98d4
22:42:32.849 > ESP-ROM:esp32s3-20210327
22:42:33.205 > Build:Mar 27 2021
22:42:33.205 > rst:0xc (RTC_SW_CPU_RST),boot:0x8 (SPI_FAST_FLASH_BOOT)
22:42:33.205 > Saved PC:0x4037ef97
22:42:33.205 > SPIWP:0xee
22:42:33.205 > mode:DIO, clock div:1
22:42:33.205 > load:0x3fce3808,len:0x44c
22:42:33.205 > load:0x403c9700,len:0xbe4
22:42:33.205 > load:0x403cc700,len:0x2a68
22:42:33.205 > entry 0x403c98d4
22:42:34.164 > ESP-ROM:esp32s3-20210327
22:42:34.515 > Build:Mar 27 2021
22:42:34.515 > rst:0xc (RTC_SW_CPU_RST),boot:0x8 (SPI_FAST_FLASH_BOOT)
22:42:34.515 > Saved PC:0x4037efb4
22:42:34.515 > SPIWP:0xee
22:42:34.515 > mode:DIO, clock div:1
22:42:34.515 > load:0x3fce3808,len:0x44c
22:42:34.515 > load:0x403c9700,len:0xbe4
22:42:34.515 > load:0x403cc700,len:0x2a68
22:42:34.515 > entry 0x403c98d4

However, if I downgraded the platform to espressif32@6.6.0 which uses arduino@2.0.14, it works as expected.

22:44:07.107 > [  1053][E][main.cpp:11] loop(): Hi
22:44:07.107 >
22:44:08.097 > [  2053][E][main.cpp:11] loop(): Hi
22:44:08.113 >
22:44:09.103 > [  3053][E][main.cpp:11] loop(): Hi
22:44:09.103 >
22:44:10.109 > [  4053][E][main.cpp:11] loop(): Hi
22:44:10.109 >
22:44:11.099 > [  5053][E][main.cpp:11] loop(): Hi
22:44:11.115 >
22:44:12.105 > [  6053][E][main.cpp:11] loop(): Hi

I am new to both Arduino and PlatformIO, so let me know if I posted in the correct repository.

Thanks,
Zul

Sketch

Sketch

#include <Arduino.h>

void setup() {
    Serial0.begin(115200);
}

void loop() {
    log_e("Hi\r\n");

    delay(1000);  // Delay to throttle loop execution, adjust as necessary
}

PlatformIO configuration

[env:arduino_nano_esp32]
; NOTE: We got an issue with Serial0 on v6.7.0
; espressif v6.7.0 uses arduino v2.0.16; idf v4.4.7
; device went into reboot loop
; 
; On espressif v6.6.0 which uses arduino v2.0.14; it works fine
platform = espressif32@6.7.0
framework = arduino
board = arduino_nano_esp32

Debug Message

22:42:31.537 > ESP-ROM:esp32s3-20210327
22:42:31.887 > Build:Mar 27 2021
22:42:31.887 > rst:0xc (RTC_SW_CPU_RST),boot:0x8 (SPI_FAST_FLASH_BOOT)
22:42:31.887 > Saved PC:0x4202a9b2
22:42:31.887 > SPIWP:0xee
22:42:31.887 > mode:DIO, clock div:1
22:42:31.887 > load:0x3fce3808,len:0x44c
22:42:31.887 > load:0x403c9700,len:0xbe4
22:42:31.887 > load:0x403cc700,len:0x2a68
22:42:31.887 > entry 0x403c98d4
22:42:32.849 > ESP-ROM:esp32s3-20210327
22:42:33.205 > Build:Mar 27 2021
22:42:33.205 > rst:0xc (RTC_SW_CPU_RST),boot:0x8 (SPI_FAST_FLASH_BOOT)
22:42:33.205 > Saved PC:0x4037ef97
22:42:33.205 > SPIWP:0xee
22:42:33.205 > mode:DIO, clock div:1
22:42:33.205 > load:0x3fce3808,len:0x44c
22:42:33.205 > load:0x403c9700,len:0xbe4
22:42:33.205 > load:0x403cc700,len:0x2a68
22:42:33.205 > entry 0x403c98d4
22:42:34.164 > ESP-ROM:esp32s3-20210327
22:42:34.515 > Build:Mar 27 2021
22:42:34.515 > rst:0xc (RTC_SW_CPU_RST),boot:0x8 (SPI_FAST_FLASH_BOOT)
22:42:34.515 > Saved PC:0x4037efb4
22:42:34.515 > SPIWP:0xee
22:42:34.515 > mode:DIO, clock div:1
22:42:34.515 > load:0x3fce3808,len:0x44c
22:42:34.515 > load:0x403c9700,len:0xbe4
22:42:34.515 > load:0x403cc700,len:0x2a68
22:42:34.515 > entry 0x403c98d4

Other Steps to Reproduce

No response

I have checked existing issues, online documentation and the Troubleshooting Guide

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.
@zul00 zul00 added the Status: Awaiting triage Issue is waiting for triage label May 21, 2024
@zul00
Copy link
Author

zul00 commented May 22, 2024

I forgot to mention that there is no problem on espressif32@6.7.0 if I use USBCDC as the streamer, i.e. Serial

@lbernstone
Copy link
Contributor

lbernstone commented May 22, 2024

Do you have this issue if you use the vanilla esp32s3 variant rather than the Nano?

@zul00
Copy link
Author

zul00 commented May 22, 2024

I have an access to an ESP32-S3-EYE, I will test it later

@SuGlider
Copy link
Collaborator

@zul00 - When using PlatformIO + Arduino Core 2.0.16 or 2.0.14, please add ARDUINO_USB_MODE=1 to your PlatformIO.ini setup.

The PlatformIO ESP32 Nano board definition lacks the ARDUINO_USB_MODE definition. This is the source the the issue.
https://github.com/platformio/platform-espressif32/blob/develop/boards/arduino_nano_esp32.json

USB Mode and CDC on Boot necessary flags:

ARDUINO_USB_MODE=1 ==> HW USB Serial JTAG interface of the S3
ARDUINO_USB_MODE=0 ==> USB OTG (TinyUSB) interface of the S3

ARDUINO_USB_CDC_ON_BOOT=1 ==> Using this setting, Serial0 is UART0 and Serial is the USB CDC interface.
ARDUINO_USB_CDC_ON_BOOT=0 ==> Serial is defined as the UART0 interface. Using this, Serial0 isn't defined and it shall produce a compilation error.

CORE_DEBUG_LEVEL=5 ==> sets a debug level message output. Level: 0 to 5.

For the Example from this post, this shall be the configuration:

[env:arduino_nano_esp32]
; NOTE: We got an issue with Serial0 on v6.7.0
; espressif v6.7.0 uses arduino v2.0.16; idf v4.4.7
; device went into reboot loop
; 
; On espressif v6.6.0 which uses arduino v2.0.14; it works fine
platform = espressif32@6.7.0
framework = arduino
board = arduino_nano_esp32
build_flags = 
   -DARDUINO_USB_MODE=1
   -DARDUINO_USB_CDC_ON_BOOT=1
   -DCORE_DEBUG_LEVEL=5

@SuGlider SuGlider added Type: Question Only question IDE: PlaformIO Issue relates to PlatformIO IDE and removed Status: Awaiting triage Issue is waiting for triage labels May 22, 2024
@zul00
Copy link
Author

zul00 commented May 23, 2024

I tested the configuration above, but I still got a reboot loop with a report that UART0 is not installed. Below is the snapshot

10:40:19.139 > ESP-ROM:esp32s3-20210327
10:40:19.442 > Build:Mar 27 2021
10:40:19.442 > rst:0xc (RTC_SW_CPU_RST),boot:0x8 (SPI_FAST_FLASH_BOOT)
10:40:19.474 > Saved PC:0x420248d6
10:40:19.474 > SPIWP:0xee
10:40:19.474 > mode:DIO, clock div:1
10:40:19.474 > load:0x3fce3808,len:0x44c
10:40:19.474 > load:0x403c9700,len:0xbe4
10:40:19.474 > load:0x403cc700,len:0x2a68
10:40:19.474 > entry 0x403c98d4
10:40:19.561 > [    92][V][esp32-hal-ledc.c:231] analogWrite(): GPIO 46 - Using Channel 7, Value = 183
10:40:19.561 > [   100][V][esp32-hal-ledc.c:231] analogWrite(): GPIO 0 - Using Channel 6, Value = 255
10:40:19.561 > [   108][V][esp32-hal-ledc.c:231] analogWrite(): GPIO 45 - Using Channel 5, Value = 71
...
10:40:22.444 > [  3006][V][esp32-hal-ledc.c:231] analogWrite(): GPIO 45 - Using Channel 5, Value = 255
10:40:22.495 > [  3036][I][esp32-hal-psram.c:96] psramInit(): PSRAM enabled
10:40:22.495 > [  3046][V][esp32-hal-uart.c:330] uartBegin(): UART0 baud(115200) Mode(800001c) rxPin(115) txPin(0)
10:40:22.495 > [  3055][V][esp32-hal-uart.c:416] uartBegin(): UART0 not installed. Starting installation
10:40:22.495 > ESP-ROM:esp32s3-20210327
10:40:22.828 > Build:Mar 27 2021
10:40:22.828 > rst:0xc (RTC_SW_CPU_RST),boot:0x8 (SPI_FAST_FLASH_BOOT)
10:40:22.828 > Saved PC:0x420248d6
10:40:22.828 > SPIWP:0xee
10:40:22.828 > mode:DIO, clock div:1
10:40:22.828 > load:0x3fce3808,len:0x44c
10:40:22.828 > load:0x403c9700,len:0xbe4
10:40:22.828 > load:0x403cc700,len:0x2a68
10:40:22.828 > entry 0x403c98d4

What is weird is that it mentioned about initializing the uart0 on an incorrect pin.

I adjusted the sketch to

void setup() {
    Serial0.begin(115200, SERIAL_8N1, SOC_RX0, SOC_TX0); // or
    //     Serial0.begin(115200, SERIAL_8N1, 44, 43);
}

But the result is still the same. I am guessing that is happening before it went into the setup from the sketch, right?

@SuGlider
Copy link
Collaborator

SuGlider commented May 23, 2024

@zul00 - Arduino ESP32 Nano board has an exclusive pin remapping scheme

Please use the pins as defined in the pinout pdf file or/and in this header file:
https://github.com/espressif/arduino-esp32/blob/master/variants/arduino_nano_nora/pins_arduino.h

void setup() {
    Serial0.begin(115200, SERIAL_8N1, D0, D1); // or
    //  Serial0.begin(115200, SERIAL_8N1, RX, TX);  // this also works for the ESP32 Nano
    //     Serial0.begin(115200, SERIAL_8N1, 44, 43);  <-- remapped
}

@SuGlider SuGlider changed the title Reboot loop upon using Serial0 [Arduino ESP32 Nano board] Reboot loop upon using Serial0 May 23, 2024
@SuGlider SuGlider changed the title [Arduino ESP32 Nano board] Reboot loop upon using Serial0 [Arduino Nano ESP32 board] Reboot loop upon using Serial0 May 23, 2024
@zul00
Copy link
Author

zul00 commented May 24, 2024

Thanks @SuGlider !

Now I understand that there is a remap there. So this one also works :)

    Serial0.begin(115200, SERIAL_8N1, 0, 1);

So I think the problem with the sketch below is because in the framework-arduinoespressif32/cores/esp32/HardwareSerial.cpp the serial pins default to SOC_RX0 and SOC_TX0.

    Serial0.begin(115200);

And those SOC_* pins are not defined when BOARD_HAS_PIN_REMAP is set. Where this flag is by default set for this particular board.

@zul00
Copy link
Author

zul00 commented May 24, 2024

Should there be a fix? Maybe HardwareSerial can have an #ifndef for SOC_* with #ifdef forR/TX? or #ifdefforBOARD_HAS_PIN_REMAP`?

If you think that is a good idea, I am willing to contribute :)

@SuGlider
Copy link
Collaborator

SuGlider commented May 24, 2024

There are a few ways to fix it.

The SOC_* pins could be defined in the pins_arduino.h ESP32 Nano board file.

Or the mapping function shall check if the requested pin does exist and return -1, which means that it shouldn't be changed.

The main problem is that the mapping function defined in the variant folder of this board returns a value from an array, but the array max number of items is shorter than 43 or 44 (Rx/Tx real pins), causing it to return trash values for the "pins" out of the array range.

@VojtechBartoska
Copy link
Collaborator

Looks this ticket was already answered, closing. If needed, you can reopen it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
IDE: PlaformIO Issue relates to PlatformIO IDE Type: Question Only question Type: 3rd party Boards
Projects
None yet
Development

No branches or pull requests

4 participants