Page 1 of 1

esp _log.h causes random TG1WDT_SYS_RESET / RTCWDT_RTC_RESET in C++

Posted: Sun Jan 24, 2021 2:02 pm
by leenowell
Hi All,

I have been having random resets (TG1WDT_SYS_RESET followed by RTCWDT_RTC_RESET) and core dumps. From the logging, I could see the odd corrupt characters but could not work out what is corrupting it. I have now been able to reproduce it with a minimal test and the results are a bit odd.

The code is as follows

Code: Select all

extern "C"
{
	#include "esp_event.h"
	#include "driver/gpio.h"
	void app_main(void);
}
#include "esp_log.h"

void app_main(void)
{
	ESP_LOGI("app_main", "PowerOn");
#define m_rstPin 	 GPIO_NUM_5
#define m_pwkeyPin 	 GPIO_NUM_4
#define m_powerPin	 GPIO_NUM_23
#define m_txPin		 GPIO_NUM_27
#define m_rxPin		 GPIO_NUM_26

	ESP_ERROR_CHECK(gpio_set_direction(m_powerPin, GPIO_MODE_OUTPUT));
	ESP_ERROR_CHECK(gpio_set_level(m_powerPin, 1));

	vTaskDelay(3000 / portTICK_RATE_MS);
    while (1)
	{
	    vTaskDelay(3000 / portTICK_RATE_MS);
	}
}
and the log is

Code: Select all

x€xv4.2 2nd stage bootloader
I (31) boot: compile time 09:01:59
I (31) boot: chip revision: 1
I (33) boot_comm: chip revision: 1, min. bootloader chip revision: 0
I (40) boot.esp32: SPI Speed      : 40MHz
I (45) boot.esp32: SPI Mode       : DIO
I (49) boot.esp32: SPI Flash Size : 2MB
I (54) boot: Enabling RNG early entropy source...
I (59) boot: Partition Table:
I (63) boot: ## Label            Usage          Type ST Offset   Length
I (70) boot:  0 nvs              WiFi data        01 02 00009000 00006000
I (78) boot:  1 phy_init         RF data          01 01 0000f000 00001000
I (85) boot:  2 factory          factory app      00 00 00010000 00100000
I (93) boot:  3 coredump         Unknown data     01 03 00110000 00010000
I (100) boot: End of partition table
I (104) boot_comm: chip revision: 1, min. application chip revision: 0
I (112) esp_image: segment 0: paddr=0x00010020 vaddr=0x3f400020 size=0x05ec8 ( 24264) map
I (130) esp_image: segment 1: paddr=0x00015ef0 vaddr=0x3ffb0000 size=0x038d8 ( 14552) load
I (136) esp_image: segment 2: paddr=0x000197d0 vaddr=0x40080000 size=0x00404 (  1028) load
I (139) esp_image: segment 3: paddr=0x00019bdc vaddr=0x40080404 size=0x0643c ( 25660) load
I (158) esp_image: segment 4: paddr=0x00020020 vaddr=0x400d0020 size=0x146b4 ( 83636) map
I (191) esp_image: segment 5: paddr=0x000346dc vaddr=0x40086840 size=0x03e70 ( 15984) load
I (204) boot: Loaded app from partition at offset 0x10000
I (204) boot: Disabling RNG early entropy source...
I (205) cpu_start: Pro cpu up.
I (208) cpu_start: Application information:
I (213) cpu_start: Project name:     app-template
I (218) cpu_start: App version:      1
I (223) cpu_start: Compile time:     Jan 24 2021 09:01:50
I (229) cpu_start: ELF file SHA256:  0ae194287451a0a0...
I (235) cpu_start: ESP-IDF:          v4.2
I (240) cpu_start: Starting app cpu, entry point is 0x400815ec
I (0) cpu_start: App cpu up.
I (250) heap_init: Initializing. RAM available for dynamic allocation:
I (257) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM
I (263) heap_init: At 3FFB48B0 len 0002B750 (173 KiB): DRAM
I (269) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM
I (276) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (282) heap_init: At 4008A6B0 len 00015950 (86 KiB): IRAM
I (288) cpu_start: Pro cpu start user code
I (306) spi_flash: detected chip: generic
I (307) spi_flash: flash io: dio
W (307) spi_flash: Detected size(4096k) larger than the size in the binary image header(2048k). Using the size in the binary image header.
I (317) esp_core_dump_flash: Init core dump to flash
I (324) esp_core_dump_flash: Found partition 'coredump' @ 110000 65536 bytes
I (333) esp_core_dump_flash: Found core dump 10640 bytes in flash @ 0x110000
I (339) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.
I (350) app_main: PowerOn
ets Jun  8 2016 00:22:57

rst:0x8 (TG1WDT_SYS_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:0x3fff0030,len:4
load:0x3fff0034,len:7064
load:0x40078000,len:13184
ho 0 tail 12 room 4
load:0x40080400,len:4580
entry 0x400806f4
I (61) boot: ESP-IDF v4.2 2nd stage bootloader
I (61) boot: compile time 09:01:59
I (62) boot: chip revision: 1
I (65) boot_comm: chip revision: 1, min. bootloader chip revision: 0
I (72) boot.esp32: SPI Speed      : 40MHz
I (76) boot.esp32: SPI Mode       : DIO
I (81) boot.esp32: SPI Flash Size : 2MB
W (86) boot.esp32: PRO CPU has been reset by WDT.
W (91) boot.esp32: WDT reset info: PRO CPU PC=0x4008435f
W (97) boot.esp32: WDT reset info: APP CPU PC=0x400846ec
I (103) boot: Enabling RNG early entropy source...
I (108) boot: Partition Table:
I (112) boot: ## Label            Usage          Type ST Offset   Length
I (119) boot:  0 nvs              WiFi data        01 02 00009000 00006000
I (127) boot:  1 phy_init         RF data          01 01 0000f000 00001000
I (135) boot:  2 factory          factory app      00 00 00010000 00100000
I (142) boot:  3 coredump         Unknown data     01 03 00110000 00010000
I (150) boot: End of partition table
I (154) boot_comm: chip revision: 1, min. application chip revision: 0
I (161) esp_image: segment 0: paddr=0x00010020 vaddr=0x3f400020 size=0x05ec8 ( 24264) map
I (179) esp_image: segment 1: paddr=0x00015ef0 vaddr=0x3ffb0000 size=0x038d8 ( 14552) load
I (186) esp_image: segment 2: paddr=0x000197d0 vaddr=0x40080000 size=0x00404 (  1028) load
I (188) esp_image: segment 3: paddr=0x00019bdc vaddr=0x40080404 size=0x0643c ( 25660) load
I (208) esp_image: segment 4: paddr=0x00020020 vaddr=0x400d0020 size=0x146b4 ( 83636) map
I (240) esp_image: segment 5: paddr=0x000346dc vaddr=0x40086840 size=0x03e70 ( 15984) load
I (254) boot: Loaded app from partition at offset 0x10000
I (254) boot: Disabling RNG early entropy source...
I (254) cpu_start: Pro cpu up.
I (258) cpu_start: Application information:
I (263) cpu_start: Project name:     app-template
I (268) cpu_start: App version:      1
I (272) cpu_start: Compile time:     Jan 24 2021 09:01:50
I (278) cpu_start: ELF file SHA256:  0ae194287451a0a0...
I (284) cpu_start: ESP-IDF:          v4.2
I (289) cpu_start: Starting app cpu, entry point is 0x400815ec
I (0) cpu_start: App cpu up.
I (300) heap_init: Initializing. RAM available for dynamic allocation:
I (306) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM
I (313) heap_init: At 3FFB48B0 len 0002B750 (173 KiB): DRAM
I (319) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM
I (325) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (332) heap_init: At 4008A6B0 len 00015950 (86 KiB): IRAM
I (338) cpu_start: Pro cpu start user code
ets Jun  8 2016 00:22:57

rst:0x10 (RTCWDT_RTC_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:0x3fff0030,len:4
load:0x3fff0034,len:7064
load:0x40078000,len:13184
ho 0 tail 12 room 4
load:0x40080400,len:4580
entry 0x400806f4
I (31) boot: ESP-IDF v4.2 2nd stage bootloader
I (31) boot: compile time 09:01:59
I (31) boot: chip revision: 1
I (33) boot_comm: chip revision: 1, min. bootloader chip revision: 0
I (40) boot.esp32: SPI Speed      : 40MHz
I (45) boot.esp32: SPI Mode       : DIO
I (50) boot.esp32: SPI Flash Size : 2MB
I (54) boot: Enabling RNG early entropy source...
I (60) boot: Partition Table:
I (63) boot: ## Label            Usage          Type ST Offset   Length
I (70) boot:  0 nvs              WiFi data        01 02 00009000 00006000
I (78) boot:  1 phy_init         RF data          01 01 0000f000 00001000
I (85) boot:  2 factory          factory app      00 00 00010000 00100000
I (93) boot:  3 coredump         Unknown data     01 03 00110000 00010000
I (100) boot: End of partition table
I (105) boot_comm: chip revision: 1, min. application chip revision: 0
I (112) esp_image: segment 0: paddr=0x00010020 vaddr=0x3f400020 size=0x05ec8 ( 24264) map
I (130) esp_image: segment 1: paddr=0x00015ef0 vaddr=0x3ffb0000 size=0x038d8 ( 14552) load
I (136) esp_image: segment 2: paddr=0x000197d0 vaddr=0x40080000 size=0x00404 (  1028) load
I (139) esp_image: segment 3: paddr=0x00019bdc vaddr=0x40080404 size=0x0643c ( 25660) load
I (159) esp_image: segment 4: paddr=0x00020020 vaddr=0x400d0020 size=0x146b4 ( 83636) map
I (191) esp_image: segment 5: paddr=0x000346dc vaddr=0x40086840 size=0x03e70 ( 15984) load
I (204) boot: Loaded app from partition at offset 0x10000
I (204) boot: Disabling RNG early entropy source...
I (205) cpu_start: Pro cpu up.
I (208) cpu_start: Application information:
I (213) cpu_start: Project name:     app-template
I (219) cpu_start: App version:      1
I (223) cpu_start: Compile time:     Jan 24 2021 09:01:50
I (229) cpu_start: ELF file SHA256:  0ae194287451a0a0...
I (235) cpu_start: ESP-IDF:          v4.2
I (240) cpu_start: Starting app cpu, entry point is 0x400815ec
I (0) cpu_start: App cpu up.
I (250) heap_init: Initializing. RAM available for dynamic allocation:
I (257) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM
I (263) heap_init: At 3FFB48B0 len 0002B750 (173 KiB): DRAM
I (270) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM
I (276) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (282) heap_init: At 4008A6B0 len 00015950 (86 KiB): IRAM
I (288) cpu_start: Pro cpu start user code
I (307) spi_flash: detected chip: generic
I (307) spi_flash: flash io: dio
W (307) spi_flash: Detected size(4096k) larger than the size in the binary image header(2048k). Using the size in the binary image header.
I (318) esp_core_dump_flash: Init core dump to flash
I (324) esp_core_dump_flash: Found partition 'coredump' @ 110000 65536 bytes
I (334) esp_core_dump_flash: Found core dump 10640 bytes in flash @ 0x110000
I (339) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.
I (350) app_main: PowerOn
If I then move the "#include "esp_log.h" to inside the "extern C" block like this

Code: Select all

extern "C"
{
	#include "esp_event.h"
	#include "driver/gpio.h"
        #include "esp_log.h"
	void app_main(void);
}
it works fine with the following log.

Code: Select all

€€xøxøx—½µÁ¥±•time 09:01:59
I (31) boot: chip revision: 1
I (33) boot_comm: chip revision: 1, min. bootloader chip revision: 0
I (40) boot.esp32: SPI Speed      : 40MHz
I (45) boot.esp32: SPI Mode       : DIO
I (49) boot.esp32: SPI Flash Size : 2MB
I (54) boot: Enabling RNG early entropy source...
I (59) boot: Partition Table:
I (63) boot: ## Label            Usage          Type ST Offset   Length
I (70) boot:  0 nvs              WiFi data        01 02 00009000 00006000
I (78) boot:  1 phy_init         RF data          01 01 0000f000 00001000
I (85) boot:  2 factory          factory app      00 00 00010000 00100000
I (93) boot:  3 coredump         Unknown data     01 03 00110000 00010000
I (100) boot: End of partition table
I (104) boot_comm: chip revision: 1, min. application chip revision: 0
I (112) esp_image: segment 0: paddr=0x00010020 vaddr=0x3f400020 size=0x05ec8 ( 24264) map
I (130) esp_image: segment 1: paddr=0x00015ef0 vaddr=0x3ffb0000 size=0x038d8 ( 14552) load
I (136) esp_image: segment 2: paddr=0x000197d0 vaddr=0x40080000 size=0x00404 (  1028) load
I (139) esp_image: segment 3: paddr=0x00019bdc vaddr=0x40080404 size=0x0643c ( 25660) load
I (158) esp_image: segment 4: paddr=0x00020020 vaddr=0x400d0020 size=0x146b4 ( 83636) map
I (191) esp_image: segment 5: paddr=0x000346dc vaddr=0x40086840 size=0x03e70 ( 15984) load
I (204) boot: Loaded app from partition at offset 0x10000
I (204) boot: Disabling RNG early entropy source...
I (205) cpu_start: Pro cpu up.
I (208) cpu_start: Application information:
I (213) cpu_start: Project name:     app-template
I (218) cpu_start: App version:      1
I (223) cpu_start: Compile time:     Jan 24 2021 09:01:50
I (229) cpu_start: ELF file SHA256:  807103bfea6fc150...
I (235) cpu_start: ESP-IDF:          v4.2
I (240) cpu_start: Starting app cpu, entry point is 0x400815ec
I (0) cpu_start: App cpu up.
I (250) heap_init: Initializing. RAM available for dynamic allocation:
I (257) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM
I (263) heap_init: At 3FFB48B0 len 0002B750 (173 KiB): DRAM
I (269) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM
I (276) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (282) heap_init: At 4008A6B0 len 00015950 (86 KiB): IRAM
I (288) cpu_start: Pro cpu start user code
I (306) spi_flash: detected chip: generic
I (307) spi_flash: flash io: dio
W (307) spi_flash: Detected size(4096k) larger than the size in the binary image header(2048k). Using the size in the binary image header.
I (317) esp_core_dump_flash: Init core dump to flash
I (324) esp_core_dump_flash: Found partition 'coredump' @ 110000 65536 bytes
I (333) esp_core_dump_flash: Found core dump 10640 bytes in flash @ 0x110000
I (339) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.
I (350) app_main: PowerOn
It would appear that despite compiling OK, there is some issue with esp_log.h being included in C++?

git describe on esp_idf gives me

Code: Select all

$ git describe
v4.2
Would appreciate your thoughts - it has taken days to narrow it down to this :)

thanks

Lee.