Skip to content

Commit

Permalink
[nrf noup] platform: nordic_nrf: Don't hang in IRQs by default
Browse files Browse the repository at this point in the history
The current default IRQ handler will hang forever. It is bad practice
to hang forever in production.

Instead we now print the exception information and then panic. Which
will either reboot or hang forever depending on the configuration.

It is bad practice to for the default IRQ handler to be triggered at
all and it should indicate a configuration error.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
  • Loading branch information
SebastianBoe authored and nordicjm committed Jul 13, 2023
1 parent 3dcb0c3 commit 49627ca
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 2 deletions.
21 changes: 21 additions & 0 deletions platform/ext/target/nordic_nrf/common/core/startup.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,27 @@
#include "hw_init.h"
#include "startup.h"

#ifndef DOMAIN_NS
#include "utilities.h"
#endif

void default_irq_handler(void)
{
/*
* This file is used by the TF-M build system. Usually in the
* secure domain (tfm_s.elf), but also for vanilla BL2 and for
* testing purposes in the non-secure domain (tfm_ns.elf).
*
* When used in vanilla BL2 or the non-secure domain we do not
* have tfm_core_panic so we loop forever instead.
*/
#if defined(DOMAIN_NS) || defined(BL2)
while(1);
#else
tfm_core_panic();
#endif
}

/*----------------------------------------------------------------------------
Reset Handler called on controller reset
*----------------------------------------------------------------------------*/
Expand Down
6 changes: 6 additions & 0 deletions platform/ext/target/nordic_nrf/common/core/startup.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ __NO_RETURN void __attribute__((weak, alias("default_tfm_IRQHandler"))) handler_

__NO_RETURN void Reset_Handler(void);

/*
* The default irq handler is used as a backup in case of
* misconfiguration.
*/
void default_irq_handler(void);

extern const VECTOR_TABLE_Type __VECTOR_TABLE[];

#endif /* __STARTUP_H__ */
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,15 @@
#include "cmsis.h"
#include "hw_init.h"
#include "startup.h"
#include "exception_info.h"

__NO_RETURN __attribute__((naked)) void default_tfm_IRQHandler(void) {
while(1);
EXCEPTION_INFO(EXCEPTION_TYPE_PLATFORM);

__ASM volatile(
"BL default_irq_handler \n"
"B . \n"
);
}

DEFAULT_IRQ_HANDLER(NMI_Handler)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,15 @@
#include "cmsis.h"
#include "hw_init.h"
#include "startup.h"
#include "exception_info.h"

__NO_RETURN __attribute__((naked)) void default_tfm_IRQHandler(void) {
while(1);
EXCEPTION_INFO(EXCEPTION_TYPE_PLATFORM);

__ASM volatile(
"BL default_irq_handler \n"
"B . \n"
);
}

DEFAULT_IRQ_HANDLER(NMI_Handler)
Expand Down

0 comments on commit 49627ca

Please sign in to comment.