diff --git a/components/esp_common/CMakeLists.txt b/components/esp_common/CMakeLists.txt index 98b178af6..a5f37842d 100644 --- a/components/esp_common/CMakeLists.txt +++ b/components/esp_common/CMakeLists.txt @@ -7,6 +7,7 @@ if(BOOTLOADER_BUILD) else() # Regular app build set(srcs "src/brownout.c" + "src/esp_err.c" "src/dbg_stubs.c" "src/esp_err_to_name.c" "src/freertos_hooks.c" diff --git a/components/esp_common/linker.lf b/components/esp_common/linker.lf new file mode 100644 index 000000000..589f73740 --- /dev/null +++ b/components/esp_common/linker.lf @@ -0,0 +1,4 @@ +[mapping:esp_common] +archive: lib_esp_common.a +entries: + esp_err (noflash) \ No newline at end of file diff --git a/components/esp_system/abort.c b/components/esp_common/src/esp_err.c similarity index 69% rename from components/esp_system/abort.c rename to components/esp_common/src/esp_err.c index 5933b4a35..3286b0058 100644 --- a/components/esp_system/abort.c +++ b/components/esp_common/src/esp_err.c @@ -11,52 +11,18 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. - #include #include #include "esp_err.h" #include "esp_spi_flash.h" -#include "esp_system.h" - -#include "esp_private/system_internal.h" - -#include "soc/cpu.h" -#include "soc/soc_caps.h" -#include "hal/cpu_hal.h" #if CONFIG_IDF_TARGET_ESP32 #include "esp32/rom/ets_sys.h" -#else +#elif CONFIG_IDF_TARGET_ESP32S2 #include "esp32s2/rom/ets_sys.h" #endif -#include "panic.h" - -void __attribute__((noreturn)) abort(void) -{ - char buf[47] = { 0 }; - - _Static_assert(UINTPTR_MAX == 0xffffffff, "abort() assumes 32-bit addresses"); - _Static_assert(SOC_CPU_CORES_NUM < 10, "abort() assumes number of cores is [1..9]"); - - char addr_buf[9] = { 0 }; - char core_buf[2] = { 0 }; - - itoa((uint32_t)(__builtin_return_address(0) - 3), addr_buf, 16); - itoa(cpu_ll_get_core_id(), core_buf, 10); - - const char *str[4] = { "abort() was called at PC 0x", addr_buf, " on core ", core_buf }; - for (int i = 0, k = 0; i < 4; i++) { - for (int j = 0; str[i][j] != '\0'; j++) { - buf[k] = str[i][j]; - k++; - } - } - - esp_system_abort(buf); -} - static void esp_error_check_failed_print(const char *msg, esp_err_t rc, const char *file, int line, const char *function, const char *expression) { ets_printf("%s failed: esp_err_t 0x%x", msg, rc); diff --git a/components/esp_system/CMakeLists.txt b/components/esp_system/CMakeLists.txt index a1439ea79..fbc5c49c1 100644 --- a/components/esp_system/CMakeLists.txt +++ b/components/esp_system/CMakeLists.txt @@ -1,4 +1,4 @@ -idf_component_register(SRCS "abort.c" "panic.c" "reset_reason.c" "system_api.c" +idf_component_register(SRCS "panic.c" "reset_reason.c" "system_api.c" INCLUDE_DIRS include PRIV_INCLUDE_DIRS private_include PRIV_REQUIRES spi_flash app_update diff --git a/components/newlib/CMakeLists.txt b/components/newlib/CMakeLists.txt index 01f0234c2..fd3d5a5d9 100644 --- a/components/newlib/CMakeLists.txt +++ b/components/newlib/CMakeLists.txt @@ -1,4 +1,5 @@ set(srcs + "abort.c" "heap.c" "locks.c" "poll.c" diff --git a/components/newlib/abort.c b/components/newlib/abort.c new file mode 100644 index 000000000..4137d74fc --- /dev/null +++ b/components/newlib/abort.c @@ -0,0 +1,46 @@ +// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at + +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#include +#include + +#include "esp_system.h" + +#include "soc/soc_caps.h" +#include "hal/cpu_hal.h" + +void __attribute__((noreturn)) abort(void) +{ + #define ERR_STR1 "abort() was called at PC 0x" + #define ERR_STR2 " on core " + + _Static_assert(UINTPTR_MAX == 0xffffffff, "abort() assumes 32-bit addresses"); + _Static_assert(SOC_CPU_CORES_NUM < 10, "abort() assumes number of cores is 1 to 9"); + + char addr_buf[9] = { 0 }; + char core_buf[2] = { 0 }; + + char buf[sizeof(ERR_STR1) + sizeof(addr_buf) + sizeof(core_buf) + sizeof(ERR_STR2) + 1 /* null char */] = { 0 }; + + itoa((uint32_t)(__builtin_return_address(0) - 3), addr_buf, 16); + itoa(cpu_ll_get_core_id(), core_buf, 10); + + const char *str[] = { ERR_STR1, addr_buf, ERR_STR2, core_buf }; + + char *dest = buf; + for (int i = 0; i < sizeof(str) / sizeof(str[0]); i++) { + strcat(dest, str[i]); + } + + esp_system_abort(buf); +} diff --git a/components/newlib/newlib.lf b/components/newlib/newlib.lf index 59d3ace55..63a93164a 100644 --- a/components/newlib/newlib.lf +++ b/components/newlib/newlib.lf @@ -1,6 +1,5 @@ -# Places the heap related functions from heap.c into IRAM - [mapping:newlib] archive: libnewlib.a entries: heap (noflash) + abort (noflash)