|
| 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