From 4d8ad3c87738eed231c2dec97b713c135b292524 Mon Sep 17 00:00:00 2001 From: Jeroen Domburg Date: Fri, 28 Oct 2016 12:05:42 +0800 Subject: [PATCH 1/6] Fix int wdt iram, fix some fallout of moving panic stuff to esp32 --- components/esp32/Kconfig | 2 +- components/esp32/int_wdt.c | 5 +++-- components/freertos/FreeRTOS-openocd.c | 2 +- components/freertos/Kconfig | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/components/esp32/Kconfig b/components/esp32/Kconfig index 9e141529b..3b50dbd2c 100644 --- a/components/esp32/Kconfig +++ b/components/esp32/Kconfig @@ -157,7 +157,7 @@ config ULP_COPROC_RESERVE_MEM choice ESP32_PANIC prompt "Panic handler behaviour" - default FREERTOS_PANIC_PRINT_REBOOT + default ESP32_PANIC_PRINT_REBOOT help If FreeRTOS detects unexpected behaviour or an unhandled exception, the panic handler is invoked. Configure the panic handlers action here. diff --git a/components/esp32/int_wdt.c b/components/esp32/int_wdt.c index 93a4d9fe6..11de8f20d 100644 --- a/components/esp32/int_wdt.c +++ b/components/esp32/int_wdt.c @@ -24,6 +24,7 @@ #include #include "esp_err.h" #include "esp_intr.h" +#include "esp_attr.h" #include "soc/timer_group_struct.h" #include "soc/timer_group_reg.h" @@ -66,7 +67,7 @@ void esp_int_wdt_init() { //Not static; the ISR assembly checks this. bool int_wdt_app_cpu_ticked=false; -void vApplicationTickHook(void) { +void IRAM_ATTR vApplicationTickHook(void) { if (xPortGetCoreID()!=0) { int_wdt_app_cpu_ticked=true; } else { @@ -82,7 +83,7 @@ void vApplicationTickHook(void) { } } #else -void vApplicationTickHook(void) { +void IRAM_ATTR vApplicationTickHook(void) { if (xPortGetCoreID()!=0) return; TIMERG1.wdt_wprotect=TIMG_WDT_WKEY_VALUE; TIMERG1.wdt_config2=CONFIG_INT_WDT_TIMEOUT_MS*2; //Set timeout before interrupt diff --git a/components/freertos/FreeRTOS-openocd.c b/components/freertos/FreeRTOS-openocd.c index 6177f0205..d74564495 100644 --- a/components/freertos/FreeRTOS-openocd.c +++ b/components/freertos/FreeRTOS-openocd.c @@ -18,6 +18,6 @@ #define USED #endif -#ifdef CONFIG_FREERTOS_DEBUG_OCDAWARE +#ifdef CONFIG_ESP32_DEBUG_OCDAWARE const int USED uxTopUsedPriority = configMAX_PRIORITIES - 1; #endif \ No newline at end of file diff --git a/components/freertos/Kconfig b/components/freertos/Kconfig index 413c710d2..25d5581e8 100644 --- a/components/freertos/Kconfig +++ b/components/freertos/Kconfig @@ -121,7 +121,7 @@ endchoice config FREERTOS_BREAK_ON_SCHEDULER_START_JTAG bool "Stop program on scheduler start when JTAG/OCD is detected" - depends on FREERTOS_DEBUG_OCDAWARE + depends on ESP32_DEBUG_OCDAWARE default y help If JTAG/OCD is connected, stop execution when the scheduler is started and the first From a038a2b5335f2b330eb32748f1950add28b85947 Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Fri, 28 Oct 2016 13:41:07 +0800 Subject: [PATCH 2/6] freertos: fix calling first task hook --- components/freertos/tasks.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/components/freertos/tasks.c b/components/freertos/tasks.c index 64cc3a65d..bd32f834f 100644 --- a/components/freertos/tasks.c +++ b/components/freertos/tasks.c @@ -1018,6 +1018,11 @@ static void prvAddNewTaskToReadyList( TCB_t *pxNewTCB, TaskFunction_t pxTaskCode if( uxCurrentNumberOfTasks == ( UBaseType_t ) 1 ) { +#if portFIRST_TASK_HOOK + if ( xPortGetCoreID() == 0 ) { + vPortFirstTaskHook(pxTaskCode); + } +#endif /* configFIRST_TASK_HOOK */ /* This is the first task to be created so do the preliminary initialisation required. We will not recover if this call fails, but we will report the failure. */ @@ -1044,12 +1049,6 @@ static void prvAddNewTaskToReadyList( TCB_t *pxNewTCB, TaskFunction_t pxTaskCode /* Schedule if nothing is scheduled yet, or overwrite a task of lower prio. */ if ( pxCurrentTCB[i] == NULL || pxCurrentTCB[i]->uxPriority <= pxNewTCB->uxPriority ) { -#if portFIRST_TASK_HOOK - if ( i == 0) { - vPortFirstTaskHook(pxTaskCode); - } -#endif /* configFIRST_TASK_HOOK */ - pxCurrentTCB[i] = pxNewTCB; break; } From 309bd12855b15b55a3226733c9a25cd09033cb65 Mon Sep 17 00:00:00 2001 From: Jeroen Domburg Date: Fri, 28 Oct 2016 14:32:11 +0800 Subject: [PATCH 3/6] Re-add panic.o to IRAM/DRAM. --- components/esp32/ld/esp32.common.ld | 3 ++- components/esp32/panic.c | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/components/esp32/ld/esp32.common.ld b/components/esp32/ld/esp32.common.ld index 2226e9882..7b14b6da1 100644 --- a/components/esp32/ld/esp32.common.ld +++ b/components/esp32/ld/esp32.common.ld @@ -47,6 +47,7 @@ SECTIONS _iram_text_start = ABSOLUTE(.); *(.iram1 .iram1.*) *libfreertos.a:(.literal .text .literal.* .text.*) + *libesp32.a:panic.o(.literal .text .literal.* .text.*) *libphy.a:(.literal .text .literal.* .text.*) *librtc.a:(.literal .text .literal.* .text.*) *libpp.a:(.literal .text .literal.* .text.*) @@ -92,7 +93,7 @@ SECTIONS KEEP(*(.gnu.linkonce.s2.*)) KEEP(*(.jcr)) *(.dram1 .dram1.*) - *libfreertos.a:panic.o(.rodata .rodata.*) + *libesp32.a:panic.o(.rodata .rodata.*) _data_end = ABSOLUTE(.); . = ALIGN(4); _heap_start = ABSOLUTE(.); diff --git a/components/esp32/panic.c b/components/esp32/panic.c index c806dace2..c5d8aa669 100644 --- a/components/esp32/panic.c +++ b/components/esp32/panic.c @@ -30,7 +30,7 @@ #include "esp_gdbstub.h" #include "esp_panic.h" - +#include "esp_attr.h" /* Panic handlers; these get called when an unhandled exception occurs or the assembly-level @@ -38,6 +38,10 @@ task switching / interrupt code runs into an unrecoverable error. The default ta overflow handler also is in here. */ +/* +Note: The linker script will put everything in this file in IRAM/DRAM, so it also works with flash cache disabled. +*/ + #if !CONFIG_ESP32_PANIC_SILENT_REBOOT //printf may be broken, so we fix our own printing fns... inline static void panicPutchar(char c) { From 3cd86d6bce502b41248b6fb8bccaeb1a4ee47c7d Mon Sep 17 00:00:00 2001 From: Jeroen Domburg Date: Fri, 28 Oct 2016 14:37:36 +0800 Subject: [PATCH 4/6] Also call tick hook on app cpu when scheduler is suspended --- components/freertos/tasks.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/freertos/tasks.c b/components/freertos/tasks.c index bd32f834f..e4b887273 100644 --- a/components/freertos/tasks.c +++ b/components/freertos/tasks.c @@ -2308,7 +2308,7 @@ BaseType_t xSwitchRequired = pdFALSE; { /* Guard against the tick hook being called when the pended tick count is being unwound (when the scheduler is being unlocked). */ - if( uxPendedTicks == ( UBaseType_t ) 0U ) + if( ( uxSchedulerSuspended[ xPortGetCoreID() ] != ( UBaseType_t ) pdFALSE ) || uxPendedTicks == ( UBaseType_t ) 0U ) { vApplicationTickHook(); } From 0e90983c9f0aaf1caf003b92d2f0471c92a389f0 Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Fri, 28 Oct 2016 16:16:12 +0800 Subject: [PATCH 5/6] vfs: fix adding CR --- components/vfs/vfs_uart.c | 1 + 1 file changed, 1 insertion(+) diff --git a/components/vfs/vfs_uart.c b/components/vfs/vfs_uart.c index bfccad896..d9d755f9b 100644 --- a/components/vfs/vfs_uart.c +++ b/components/vfs/vfs_uart.c @@ -18,6 +18,7 @@ #include "sys/errno.h" #include "sys/lock.h" #include "soc/uart_struct.h" +#include "sdkconfig.h" static uart_dev_t* s_uarts[3] = {&UART0, &UART1, &UART2}; static _lock_t s_uart_locks[3]; // per-UART locks, lazily initialized From 5ffd6155f28eb906212238868fe242e0aeaa6da4 Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Fri, 28 Oct 2016 16:17:41 +0800 Subject: [PATCH 6/6] set default interrupt watchdog timeout to 300ms 10ms is too low for openocd/gdb to work, so it's not a very useful default value. --- components/esp32/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/esp32/Kconfig b/components/esp32/Kconfig index 3b50dbd2c..b5a8d2f2d 100644 --- a/components/esp32/Kconfig +++ b/components/esp32/Kconfig @@ -206,7 +206,7 @@ config INT_WDT config INT_WDT_TIMEOUT_MS int "Interrupt watchdog timeout (ms)" depends on INT_WDT - default 10 + default 300 range 10 10000 help The timeout of the watchdog, in miliseconds. Make this higher than the FreeRTOS tick rate.