Skip to content

Commit 719787b

Browse files
bors[bot]Flole998
andauthored
Merge #19192
19192: cpu/esp32: fixes for boot issues and crashes on ESP32 r=kaspar030 a=Flole998 ### Contribution description In syscalls_init() there is a call to malloc(), which will return NULL if the heap is not initialized before, causing the entire board to fail booting if MODULE_ESP_IDF_HEAP is used. API of [vTaskDelete()](https://www.freertos.org/a00126.html) says, that if NULL is passed to vTaskDelete the calling task should be deleted. This PR needs a backport to 2023.01. ### Testing procedure Just compiling on the ESP32S2 and running it with WiFi caused it to not start anymore, no output, nothing. When Null is written to that null-pointer it hangs. The second commit fixed an issue/assertion fail that happens when the WiFi connection drops/disconnects. ### Issues/PRs references Issue was introduced with PR #19146 Co-authored-by: Flole998 <[email protected]>
2 parents f85366a + 56d2997 commit 719787b

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

cpu/esp32/startup.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,14 @@ static NORETURN void IRAM system_startup_cpu0(void)
147147
puf_sram_init((uint8_t *)&_sheap, SEED_RAM_LEN);
148148
#endif
149149

150+
#if IS_USED(MODULE_ESP_IDF_HEAP)
151+
/* init heap */
152+
heap_caps_init();
153+
if (IS_ACTIVE(ENABLE_DEBUG)) {
154+
ets_printf("Heap free: %u byte\n", get_free_heap_size());
155+
}
156+
#endif
157+
150158
/* initialize system call tables of ESP32x rom and newlib */
151159
syscalls_init();
152160

@@ -206,14 +214,6 @@ static NORETURN void IRAM system_startup_cpu0(void)
206214

207215
LOG_STARTUP("PRO cpu is up (single core mode, only PRO cpu is used)\n");
208216

209-
#if IS_USED(MODULE_ESP_IDF_HEAP)
210-
/* init heap */
211-
heap_caps_init();
212-
if (IS_ACTIVE(ENABLE_DEBUG)) {
213-
ets_printf("Heap free: %u byte\n", get_free_heap_size());
214-
}
215-
#endif
216-
217217
/* init esp_timer implementation */
218218
esp_timer_early_init();
219219

cpu/esp_common/freertos/task.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ void vTaskDelete(TaskHandle_t xTaskToDelete)
116116
DEBUG("%s pid=%d task=%p\n", __func__, thread_getpid(), xTaskToDelete);
117117

118118
uint32_t pid = (uint32_t)xTaskToDelete;
119+
if (pid == 0) {
120+
pid = thread_getpid();
121+
}
119122
assert(pid_is_valid(pid));
120123

121124
/* remove the task from scheduling */

0 commit comments

Comments
 (0)