8000 esp32/panichandler: Print support information on panic. · micropython/micropython@c10a74b · GitHub
[go: up one dir, main page]

Skip to content

Commit c10a74b

Browse files
DvdGiessendpgeorge
authored andcommitted
esp32/panichandler: Print support information on panic.
When a fatal error occurs it's important to know which precise version it occurred on in order to be able to decode the crash dump information such as the backtrace. By wrapping around the built-in IDF panic handler we can print some extra information whenever a fatal error occurs. The message links to a new wiki page which contains additional information on how to debug ESP32 issues, and links to the bug reporting issue template. Signed-off-by: Daniël van de Giessen <daniel@dvdgiessen.nl>
1 parent a0d4fdc commit c10a74b

File tree

3 files changed

+72
-0
lines changed

3 files changed

+72
-0
lines changed

ports/esp32/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,8 @@ include($ENV{IDF_PATH}/tools/cmake/project.cmake)
5959
# Set the location of the main component for the project (one per target).
6060
list(APPEND EXTRA_COMPONENT_DIRS main_${IDF_TARGET})
6161

62+
# Enable the panic handler wrapper
63+
idf_build_set_property(LINK_OPTIONS "-Wl,--wrap=esp_panic_handler" APPEND)
64+
6265
# Define the project.
6366
project(micropython)

ports/esp32/esp32_common.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ list(APPEND MICROPY_SOURCE_DRIVERS
5353
)
5454

5555
list(APPEND MICROPY_SOURCE_PORT
56+
panichandler.c
5657
adc.c
5758
main.c
5859
ppp_set_auth.c

ports/esp32/panichandler.c

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2024 Mindhash B.V.
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
27+
#include "genhdr/mpversion.h"
28+
#include "py/mpconfig.h"
29+
30+
#ifdef MICROPY_BUILD_TYPE
31+
#define MICROPY_BUILD_TYPE_PAREN " (" MICROPY_BUILD_TYPE ")"
32+
#else
33+
#define MICROPY_BUILD_TYPE_PAREN
34+
#endif
35+
36+
#ifdef CONFIG_ESP_PANIC_HANDLER_IRAM
37+
#define MICROPY_WRAP_PANICHANDLER_FUN(f) IRAM_ATTR f
38+
#define MICROPY_WRAP_PANICHANDLER_STR(s) DRAM_STR(s)
39+
#else
40+
#define MICROPY_WRAP_PANICHANDLER_FUN(f) f
41+
#define MICROPY_WRAP_PANICHANDLER_STR(s) (s)
42+
#endif
43+
44+
void __real_esp_panic_handler(void *);
45+
void esp_panic_handler_reconfigure_wdts(uint32_t timeout_ms);
46+
void panic_print_str(const char *str);
47+
48+
void MICROPY_WRAP_PANICHANDLER_FUN(__wrap_esp_panic_handler)(void *info) {
49+
esp_panic_handler_reconfigure_wdts(1000);
50+
51+
const static char *msg = MICROPY_WRAP_PANICHANDLER_STR(
52+
"\r\n"
53+
"A fatal error occurred. The crash dump printed below may be used to help\r\n"
54+
"determine what caused it. If you are not already running the most recent\r\n"
55+
"version of MicroPython, consider upgrading. New versions often fix bugs.\r\n"
56+
"\r\n"
57+
"To learn more about how to debug and/or report this crash visit the wiki\r\n"
58+
"page at: https://github.com/micropython/micropython/wiki/ESP32-debugging\r\n"
59+
"\r\n"
60+
"MPY version : " MICROPY_GIT_TAG " on " MICROPY_BUILD_DATE MICROPY_BUILD_TYPE_PAREN "\r\n"
61+
"IDF version : " IDF_VER "\r\n"
62+
"Machine : " MICROPY_HW_BOARD_NAME " with " MICROPY_HW_MCU_NAME "\r\n"
63+
"\r\n"
64+
);
65+
panic_print_str(msg);
66+
67+
__real_esp_panic_handler(info);
68+
}

0 commit comments

Comments
 (0)
0