From 78161a1fe3d660abb87b851fef1a630ae3b5255e Mon Sep 17 00:00:00 2001 From: Jeroen Domburg Date: Mon, 12 Dec 2016 20:05:58 +0800 Subject: [PATCH 1/4] Replace non-multicore-aware rom funcs with multicore-aware funcs, ESP_LOG->ESP_EARLY_LOG fix, reserve ints used in wireless libs. Fixes WiFi crashing --- components/esp32/cpu_start.c | 5 ++++- components/esp32/intr_alloc.c | 17 ++++++++++++++--- components/esp32/ld/esp32.rom.ld | 21 ++++++++++++++------- components/esp32/lib | 2 +- components/freertos/xtensa_intr_asm.S | 4 ++++ 5 files changed, 37 insertions(+), 12 deletions(-) diff --git a/components/esp32/cpu_start.c b/components/esp32/cpu_start.c index d6088b040..c7667fec6 100644 --- a/components/esp32/cpu_start.c +++ b/components/esp32/cpu_start.c @@ -228,8 +228,11 @@ void start_cpu1_default(void) while (port_xSchedulerRunning[0] == 0) { ; } + //Take care putting stuff here: if asked, FreeRTOS will happily tell you the scheduler + //has started, but it isn't active *on this CPU* yet. esp_crosscore_int_init(); - ESP_LOGI(TAG, "Starting scheduler on APP CPU."); + + ESP_EARLY_LOGI(TAG, "Starting scheduler on APP CPU."); xPortStartScheduler(); } #endif //!CONFIG_FREERTOS_UNICORE diff --git a/components/esp32/intr_alloc.c b/components/esp32/intr_alloc.c index 77572b1a5..3ffffeacd 100644 --- a/components/esp32/intr_alloc.c +++ b/components/esp32/intr_alloc.c @@ -106,8 +106,8 @@ const static int_desc_t int_desc[32]={ { 1, INTTP_NA, {INT6RES, INT6RES } }, //6 { 1, INTTP_NA, {INTDESC_SPECIAL,INTDESC_SPECIAL}}, //7 { 1, INTTP_LEVEL, {INTDESC_RESVD, INTDESC_RESVD } }, //8 - { 1, INTTP_LEVEL, {INTDESC_NORMAL, INTDESC_NORMAL} }, //9 - { 1, INTTP_EDGE , {INTDESC_RESVD, INTDESC_NORMAL} }, //10 + { 1, INTTP_LEVEL, {INTDESC_RESVD, INTDESC_RESVD } }, //9 //FRC1 + { 1, INTTP_EDGE , {INTDESC_RESVD, INTDESC_RESVD } }, //10 //FRC2 { 3, INTTP_NA, {INTDESC_SPECIAL,INTDESC_SPECIAL}}, //11 { 1, INTTP_LEVEL, {INTDESC_NORMAL, INTDESC_NORMAL} }, //12 { 1, INTTP_LEVEL, {INTDESC_NORMAL, INTDESC_NORMAL} }, //13 @@ -721,7 +721,18 @@ void esp_intr_noniram_enable() ::"r"(intmask):"a3"); } - +//These functions are provided in ROM, but the ROM-based functions use non-multicore-capable +//virtualized interrupt levels. Thus, we disable them in the ld file and provide working +//equivalents here. + + +void ets_isr_unmask(unsigned int mask) { + xt_ints_on(mask); +} + +void ets_isr_mask(unsigned int mask) { + xt_ints_off(mask); +} diff --git a/components/esp32/ld/esp32.rom.ld b/components/esp32/ld/esp32.rom.ld index b557271fa..6241ff840 100644 --- a/components/esp32/ld/esp32.rom.ld +++ b/components/esp32/ld/esp32.rom.ld @@ -169,12 +169,6 @@ PROVIDE ( ets_get_xtal_scale = 0x4000856c ); PROVIDE ( ets_install_putc1 = 0x40007d18 ); PROVIDE ( ets_install_putc2 = 0x40007d38 ); PROVIDE ( ets_install_uart_printf = 0x40007d28 ); -PROVIDE ( ets_intr_count = 0x3ffe03fc ); -PROVIDE ( ets_intr_lock = 0x400067b0 ); -PROVIDE ( ets_intr_unlock = 0x400067c4 ); -PROVIDE ( ets_isr_attach = 0x400067ec ); -PROVIDE ( ets_isr_mask = 0x400067fc ); -PROVIDE ( ets_isr_unmask = 0x40006808 ); PROVIDE ( ets_post = 0x4000673c ); PROVIDE ( ets_printf = 0x40007d54 ); PROVIDE ( ets_readySet_ = 0x3ffe01f0 ); @@ -1730,6 +1724,13 @@ PROVIDE ( Xthal_intlevel = 0x3ff9c2b4 ); PROVIDE ( xthal_memcpy = 0x4000c0bc ); PROVIDE ( xthal_set_ccompare = 0x4000c058 ); PROVIDE ( xthal_set_intclear = 0x4000c1ec ); +PROVIDE ( _xtos_set_intlevel = 0x4000bfdc ); +/* +These functions are xtos-related (or call xtos-related functions) and do not play well +with multicore FreeRTOS. Where needed, we provide alternatives that are multicore +compatible. +*/ +/* PROVIDE ( _xtos_alloca_handler = 0x40000010 ); PROVIDE ( _xtos_cause3_handler = 0x40000dd8 ); PROVIDE ( _xtos_c_handler_table = 0x3ffe0548 ); @@ -1748,13 +1749,19 @@ PROVIDE ( _xtos_return_from_exc = 0x4000c034 ); PROVIDE ( _xtos_set_exception_handler = 0x4000074c ); PROVIDE ( _xtos_set_interrupt_handler = 0x4000bf78 ); PROVIDE ( _xtos_set_interrupt_handler_arg = 0x4000bf34 ); -PROVIDE ( _xtos_set_intlevel = 0x4000bfdc ); PROVIDE ( _xtos_set_min_intlevel = 0x4000bff8 ); PROVIDE ( _xtos_set_vpri = 0x40000934 ); PROVIDE ( _xtos_syscall_handler = 0x40000790 ); PROVIDE ( _xtos_unhandled_exception = 0x4000c024 ); PROVIDE ( _xtos_unhandled_interrupt = 0x4000c01c ); PROVIDE ( _xtos_vpri_enabled = 0x3ffe0654 ); +PROVIDE ( ets_intr_count = 0x3ffe03fc ); +PROVIDE ( ets_intr_lock = 0x400067b0 ); +PROVIDE ( ets_intr_unlock = 0x400067c4 ); +PROVIDE ( ets_isr_attach = 0x400067ec ); +PROVIDE ( ets_isr_mask = 0x400067fc ); +PROVIDE ( ets_isr_unmask = 0x40006808 ); +*/ /* Following are static data, but can be used, not generated by script <<<<< btdm data */ PROVIDE ( ld_acl_env = 0x3ffb8258 ); PROVIDE ( ld_active_ch_map = 0x3ffb8334 ); diff --git a/components/esp32/lib b/components/esp32/lib index 3a412c08a..5902a2229 160000 --- a/components/esp32/lib +++ b/components/esp32/lib @@ -1 +1 @@ -Subproject commit 3a412c08af1ace47a58d1f8722a8fed5b8d3b944 +Subproject commit 5902a2229e5371aeea45c09e63ea5e233b58750f diff --git a/components/freertos/xtensa_intr_asm.S b/components/freertos/xtensa_intr_asm.S index 330b68f59..f2d236108 100644 --- a/components/freertos/xtensa_intr_asm.S +++ b/components/freertos/xtensa_intr_asm.S @@ -158,8 +158,10 @@ xt_ints_on: #else movi a3, 0 xsr a3, INTENABLE /* Disables all interrupts */ + rsync or a2, a3, a2 /* set bits in mask */ wsr a2, INTENABLE /* Re-enable ints */ + rsync mov a2, a3 /* return prev mask */ #endif #else @@ -206,9 +208,11 @@ xt_ints_off: #else movi a4, 0 xsr a4, INTENABLE /* Disables all interrupts */ + rsync or a3, a4, a2 /* set bits in mask */ xor a3, a3, a2 /* invert bits in mask set in mask, essentially clearing them */ wsr a3, INTENABLE /* Re-enable ints */ + rsync mov a2, a4 /* return prev mask */ #endif #else From 071615b059858feb45afc093a62f7852f846ddcd Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Fri, 9 Dec 2016 19:44:27 +0800 Subject: [PATCH 2/4] freertos: fix TLS delete callback test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit “Full” printf uses more stack space than “nano” printf, and more space than available in the idle task. This caused stack overflow in TLS delete test. Replacing printf with ets_printf. --- components/freertos/test/test_tls_deletecb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/freertos/test/test_tls_deletecb.c b/components/freertos/test/test_tls_deletecb.c index 5277b761a..8628f42ec 100644 --- a/components/freertos/test/test_tls_deletecb.c +++ b/components/freertos/test/test_tls_deletecb.c @@ -16,7 +16,7 @@ static void tskdelcb(int no, void *arg) { - printf("Delete callback: %d = %p!\n", no, arg); + ets_printf("Delete callback: %d = %p!\n", no, arg); } From 8f3c74353a6b334e3f1002d101cf923348117c78 Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Sun, 11 Dec 2016 22:25:02 +0800 Subject: [PATCH 3/4] newlib: fix unit test name in test config --- components/idf_test/unit_test/TestCaseAll.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/idf_test/unit_test/TestCaseAll.yml b/components/idf_test/unit_test/TestCaseAll.yml index 6f974e0bf..4e5c01f21 100644 --- a/components/idf_test/unit_test/TestCaseAll.yml +++ b/components/idf_test/unit_test/TestCaseAll.yml @@ -7,9 +7,9 @@ test cases: category: Function cmd set: - IDFUnitTest/UnitTest - - - test_case = "check if ROM is used for functions" + - - test_case = "check if ROM or Flash is used for functions" - [dummy] - comment: check if ROM is used for functions + comment: check if ROM or Flash is used for functions execution time: 0 expected result: 1. set succeed initial condition: UTINIT1 From d5c57d1d10155bd0ee43610c5839bee551fa7cd4 Mon Sep 17 00:00:00 2001 From: Jeroen Domburg Date: Tue, 13 Dec 2016 11:29:34 +0800 Subject: [PATCH 4/4] Put ets_isr_* functions into IRAM. Original fns were in ROM so people may expect them to work when flash cache is out. --- components/esp32/intr_alloc.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/components/esp32/intr_alloc.c b/components/esp32/intr_alloc.c index 3ffffeacd..57a6a97de 100644 --- a/components/esp32/intr_alloc.c +++ b/components/esp32/intr_alloc.c @@ -726,12 +726,12 @@ void esp_intr_noniram_enable() //equivalents here. -void ets_isr_unmask(unsigned int mask) { - xt_ints_on(mask); +void IRAM_ATTR ets_isr_unmask(unsigned int mask) { + xt_ints_on(mask); } -void ets_isr_mask(unsigned int mask) { - xt_ints_off(mask); +void IRAM_ATTR ets_isr_mask(unsigned int mask) { + xt_ints_off(mask); }