UART causing the ESP32 to reboot

Hasan Shadi
Posts: 26
Joined: Tue Mar 31, 2020 7:26 pm

UART causing the ESP32 to reboot

Postby Hasan Shadi » Thu May 28, 2020 5:32 pm

I have written an app based on an example in the ESP-IDF. It sends a message "AT;\r\n", which should return something like "Ok\r\n". Well, it crashes and says something related rx_interrupt. Where other times it does not crash, but it stays on but does not receive anything. Before the app crashes, it sends this: "uart_rx_intr_handler_default at C:/Users/Hassan/Documents/Arduino/ES
P/esp-idf/components/driver/uart.c:846" to the console. This the message from the console since the crash:
rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0018,len:4
load:0x3fff001c,len:6996
load:0x40078000,len:14076
load:0x40080400,len:4304
entry 0x400806e8
I (71) boot: Chip Revision: 1
I (71) boot_comm: chip revision: 1, min. bootloader chip revision: 0
I (39) boot: ESP-IDF v4.0-280-ga3f3c7bdc-dirty 2nd stage bootloader
I (39) boot: compile time 13:23:02
I (39) boot: Enabling RNG early entropy source...
I (45) boot: SPI Speed : 40MHz
I (49) boot: SPI Mode : DIO
I (53) boot: SPI Flash Size : 2MB
I (58) boot: Partition Table:
I (61) boot: ## Label Usage Type ST Offset Length
I (68) boot: 0 nvs WiFi data 01 02 00009000 00006000
I (76) boot: 1 phy_init RF data 01 01 0000f000 00001000
I (83) boot: 2 factory factory app 00 00 00010000 00100000
I (91) boot: End of partition table
I (95) boot_comm: chip revision: 1, min. application chip revision: 0
I (102) esp_image: segment 0: paddr=0x00010020 vaddr=0x3f400020 size=0x06ae4 ( 2
7364) map
I (121) esp_image: segment 1: paddr=0x00016b0c vaddr=0x3ffb0000 size=0x02118 (
8472) load
I (125) esp_image: segment 2: paddr=0x00018c2c vaddr=0x40080000 size=0x00400 (
1024) load
0x40080000: _WindowOverflow4 at C:/Users/Hassan/Documents/Arduino/ESP/esp-idf/co
mponents/freertos/xtensa_vectors.S:1778

I (129) esp_image: segment 3: paddr=0x00019034 vaddr=0x40080400 size=0x06fdc ( 2
8636) load
I (150) esp_image: segment 4: paddr=0x00020018 vaddr=0x400d0018 size=0x14dd4 ( 8
5460) map
0x400d0018: _stext at ??:?

I (181) esp_image: segment 5: paddr=0x00034df4 vaddr=0x400873dc size=0x0339c ( 1
3212) load
0x400873dc: rtc_clk_cpu_freq_to_pll_mhz at C:/Users/Hassan/Documents/Arduino/ESP
/esp-idf/components/soc/esp32/rtc_clk.c:496

I (193) boot: Loaded app from partition at offset 0x10000
I (193) boot: Disabling RNG early entropy source...
I (194) cpu_start: Pro cpu up.
I (197) cpu_start: Application information:
I (202) cpu_start: Project name: JoyStick_Game
I (208) cpu_start: App version: 1
I (212) cpu_start: Compile time: May 28 2020 13:23:16
I (218) cpu_start: ELF file SHA256: 03209e5cbe0d9139...
I (224) cpu_start: ESP-IDF: v4.0-280-ga3f3c7bdc-dirty
I (231) cpu_start: Starting app cpu, entry point is 0x4008105c
0x4008105c: call_start_cpu1 at C:/Users/Hassan/Documents/Arduino/ESP/esp-idf/com
ponents/esp32/cpu_start.c:271

I (0) cpu_start: App cpu up.
I (241) heap_init: Initializing. RAM available for dynamic allocation:
I (248) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM
I (254) heap_init: At 3FFB3110 len 0002CEF0 (179 KiB): DRAM
I (260) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM
I (267) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (273) heap_init: At 4008A778 len 00015888 (86 KiB): IRAM
I (279) cpu_start: Pro cpu start user code
I (297) spi_flash: detected chip: generic
I (298) spi_flash: flash io: dio
W (298) spi_flash: Detected size(4096k) larger than the size in the binary image
header(2048k). Using the size in the binary image header.
I (308) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.
Starting the ESP32!
Guru Meditation Error: Core 0 panic'ed (IllegalInstruction). Exception was unha
ndled.
Memory dump at 0x400d4ed8: 323c6232 33803d22 bf2a0000
0x400d4ed8: uart_rx_intr_handler_default at C:/Users/Hassan/Documents/Arduino/ES
P/esp-idf/components/driver/uart.c:846

Core 0 register dump:
PC : 0x400d4ede PS : 0x00060031 A0 : 0x400825ac A1 : 0x3f
fb0640
0x400d4ede: uart_rx_intr_handler_default at C:/Users/Hassan/Documents/Arduino/ES
P/esp-idf/components/driver/uart.c:847

0x400825ac: _xt_lowint1 at C:/Users/Hassan/Documents/Arduino/ESP/esp-idf/compone
nts/freertos/xtensa_vectors.S:1153

A2 : 0x3ffb6b4c A3 : 0x00000006 A4 : 0x3ff50000 A5 : 0x00
000080
A6 : 0x00000001 A7 : 0x00000001 A8 : 0x00000006 A9 : 0x00
000006
A10 : 0x00000000 A11 : 0x3ffb778e A12 : 0x3ffb0648 A13 : 0x3f
fb7760
A14 : 0x00000003 A15 : 0x00060723 SAR : 0x0000001b EXCCAUSE: 0x00
000000
EXCVADDR: 0x00000000 LBEG : 0x4000c2e0 LEND : 0x4000c2f6 LCOUNT : 0xff
ffffff
Core 0 was running in ISR context:
EPC1 : 0x400d4ede EPC2 : 0x00000000 EPC3 : 0x00000000 EPC4 : 0x00
000000
0x400d4ede: uart_rx_intr_handler_default at C:/Users/Hassan/Documents/Arduino/ES
P/esp-idf/components/driver/uart.c:847


ELF file SHA256: 03209e5cbe0d91398f2c6af37c1ab8f309088d271af452d367a0ad5c972fa91
3

Backtrace: 0x400d4edb:0x3ffb0640 0x400825a9:0x3ffb0690 0x4000bfed:0x3ffb4e20 0x4
00892c9:0x3ffb4e30 0x400d56dd:0x3ffb4e50 0x400d577e:0x3ffb4e80 0x400d6012:0x3ffb
4ec0 0x400d3cd2:0x3ffb4ef0 0x400d0c72:0x3ffb4f30 0x40087d99:0x3ffb4f50
0x400d4edb: uart_rx_intr_handler_default at C:/Users/Hassan/Documents/Arduino/ES
P/esp-idf/components/driver/uart.c:847

0x400825a9: _xt_lowint1 at C:/Users/Hassan/Documents/Arduino/ESP/esp-idf/compone
nts/freertos/xtensa_vectors.S:1153

0x400892c9: vTaskExitCritical at C:/Users/Hassan/Documents/Arduino/ESP/esp-idf/c
omponents/freertos/tasks.c:4274

0x400d56dd: uart_enable_tx_intr at C:/Users/Hassan/Documents/Arduino/ESP/esp-idf
/components/driver/uart.c:532 (discriminator 2)

0x400d577e: uart_tx_all at C:/Users/Hassan/Documents/Arduino/ESP/esp-idf/compone
nts/driver/uart.c:1165

0x400d6012: uart_write_bytes at C:/Users/Hassan/Documents/Arduino/ESP/esp-idf/co
mponents/driver/uart.c:1195 (discriminator 2)

0x400d3cd2: loop() at c:\users\hassan\documents\arduino\esp\esp32-projects\joyst
ick_game\build/../main/main.cpp:59 (discriminator 1)
(inlined by) app_main at c:\users\hassan\documents\arduino\esp\esp32-projects\j
oystick_game\build/../main/main.cpp:49 (discriminator 1)

0x400d0c72: main_task at C:/Users/Hassan/Documents/Arduino/ESP/esp-idf/component
s/esp32/cpu_start.c:553

0x40087d99: vPortTaskWrapper at C:/Users/Hassan/Documents/Arduino/ESP/esp-idf/co
mponents/freertos/port.c:143
and this is the code:

Code: Select all

#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_system.h"
#include "esp_event.h"
#include <driver/uart.h>

extern "C" {
    void app_main();
}

inline void loop();

void app_main()
{
    printf("Starting the ESP32!\n");
    
    {
        uart_config_t uartConfig;
        uartConfig.baud_rate = 9600;
        uartConfig.data_bits = UART_DATA_8_BITS;
        uartConfig.flow_ctrl = UART_HW_FLOWCTRL_DISABLE;
        uartConfig.parity = UART_PARITY_DISABLE;
        uartConfig.stop_bits = UART_STOP_BITS_1;
        uartConfig.use_ref_tick = false;
        uartConfig.rx_flow_ctrl_thresh = 0;
        ESP_ERROR_CHECK(uart_param_config(UART_NUM_1, &uartConfig));
    }

    ESP_ERROR_CHECK(uart_set_pin(UART_NUM_1, 10, 9, -1, -1));
    ESP_ERROR_CHECK(uart_driver_install(UART_NUM_1, 1024 * 2, 1024 * 2, 0, 0, 0));

    while (true) {
        loop();
    }
}

unsigned char readBuffer[4];
int returned;

inline void loop() {

    vTaskDelay(pdMS_TO_TICKS(1000));
    printf("Sent out %d\n", uart_write_bytes(UART_NUM_1, "AT;\r\n", 6));
    printf("AT\n");
    if ((returned = uart_read_bytes(UART_NUM_1, readBuffer, 4, (TickType_t)0)) > 0) {
        printf("Received something!\n");
        printf("%s\n", readBuffer);
        memset(readBuffer, 0, 4);
    }
    printf("Returned: %d\n", returned);

}


WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: UART causing the ESP32 to reboot

Postby WiFive » Fri May 29, 2020 1:30 am

Try other gpio not 9&10

Hasan Shadi
Posts: 26
Joined: Tue Mar 31, 2020 7:26 pm

Re: UART causing the ESP32 to reboot

Postby Hasan Shadi » Fri May 29, 2020 2:29 am

WiFive wrote:
Fri May 29, 2020 1:30 am
Try other gpio not 9&10
I have tried other UART, like UART0. Remember that UART does not work on any pin, there are designated pins for the UART interfaces. I have tried UART0, it did not reboot, but still it did not receive any message. I have discovered that the ESP32 is not 5V tolerant, and the other board that I am communicating with is a 5V board (meaning its 'HIGH' is 5V, where the ESP32 has a 'HIGH' signal as 3.3V), so I have to somehow decrease the voltage into 3.3V for the ESP32 to consider it as HIGH and get something on the ESP32 UART interface. Consider the problem solved.

Thank you anyway!

ESP_Angus
Posts: 2344
Joined: Sun May 08, 2016 4:11 am

Re: UART causing the ESP32 to reboot

Postby ESP_Angus » Fri May 29, 2020 3:57 am

Hasan Shadi wrote:
Fri May 29, 2020 2:29 am
Remember that UART does not work on any pin, there are designated pins for the UART interfaces.
It's a bit confusing, but the UARTs can actually work on any pins via the GPIO Matrix (see the relevant chapter in the TRM for all the details). If you change the pin numbers for uart_set_pin() when configuring the driver then it should work. (GPIOs 9 & 10 are connected internally to the flash chip, which is the reason for the random crash.)

EDIT: But yes, you will also need a level shifter for the 5V signals. They're probably not causing the crash, but it may cause other problems in time.

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: UART causing the ESP32 to reboot

Postby WiFive » Fri May 29, 2020 9:18 am

Hasan Shadi wrote:
Fri May 29, 2020 2:29 am
Remember that UART does not work on any pin, there are designated pins for the UART interfaces.
Most modern microcontrollers don't suffer this limitation anymore

Who is online

Users browsing this forum: No registered users and 127 guests