Hi,
We've been trying to implement a custom hardfault handler on Zephyr, for a custom board based on nRF52833.
According to Zephyr, also according to one old post on this forum, the Zephyr HardFault handler void k_sys_fatal_error_handler(unsigned int reason, const z_arch_esf_t *esf)) should be defined as weak, and it is, but on NCS there's no weak implementation.
The weak implementation is defined on "zephyr/kernel/fatal.c"
/* * Copyright (c) 2019 Intel Corporation. * * SPDX-License-Identifier: Apache-2.0 */ #include <zephyr/kernel.h> #include <kernel_internal.h> #include <zephyr/kernel_structs.h> #include <zephyr/sys/__assert.h> #include <zephyr/arch/cpu.h> #include <zephyr/logging/log_ctrl.h> #include <zephyr/logging/log.h> #include <zephyr/fatal.h> #ifndef CONFIG_XTENSA #include <zephyr/debug/coredump.h> #endif LOG_MODULE_DECLARE(os, CONFIG_KERNEL_LOG_LEVEL); /* LCOV_EXCL_START */ FUNC_NORETURN __weak void arch_system_halt(unsigned int reason) { ARG_UNUSED(reason); /* TODO: What's the best way to totally halt the system if SMP * is enabled? */ (void)arch_irq_lock(); for (;;) { /* Spin endlessly */ } } /* LCOV_EXCL_STOP */ /* LCOV_EXCL_START */ __weak void k_sys_fatal_error_handler(unsigned int reason, const z_arch_esf_t *esf) { ARG_UNUSED(esf); LOG_PANIC(); LOG_ERR("Halting system"); arch_system_halt(reason); CODE_UNREACHABLE; /* LCOV_EXCL_LINE */ }
The non weak implementation is defined on "nrf/lib/fatal_error/fatal_error.c"
/* * Copyright (c) 2019 Nordic Semiconductor ASA * * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause */ #include <zephyr/arch/cpu.h> #include <zephyr/logging/log_ctrl.h> #include <zephyr/logging/log.h> #include <zephyr/fatal.h> LOG_MODULE_REGISTER(fatal_error, CONFIG_FATAL_ERROR_LOG_LEVEL); extern void sys_arch_reboot(int type); void k_sys_fatal_error_handler(unsigned int reason, const z_arch_esf_t *esf) { ARG_UNUSED(esf); ARG_UNUSED(reason); LOG_PANIC(); if (IS_ENABLED(CONFIG_RESET_ON_FATAL_ERROR)) { LOG_ERR("Resetting system"); sys_arch_reboot(0); } else { LOG_ERR("Halting system"); for (;;) { /* Spin endlessly */ } } CODE_UNREACHABLE; }
NCS version is 2.5.2
What is missing me? How do we proceed on this?
Cheers,
J