diff options
-rw-r--r-- | libmaple/nvic.c | 13 | ||||
-rw-r--r-- | libmaple/nvic.h | 2 |
2 files changed, 14 insertions, 1 deletions
diff --git a/libmaple/nvic.c b/libmaple/nvic.c index 3be5a5a..345c850 100644 --- a/libmaple/nvic.c +++ b/libmaple/nvic.c @@ -83,3 +83,16 @@ void nvic_init(uint32 vector_table_address, uint32 offset) { void nvic_set_vector_table(uint32 addr, uint32 offset) { SCB_BASE->VTOR = addr | (offset & 0x1FFFFF80); } + +/** + * @brief Force a system reset. + * + * Resets all major system components, excluding debug. + */ +void nvic_sys_reset() { + uint32 prigroup = SCB_BASE->AIRCR & SCB_AIRCR_PRIGROUP; + SCB_BASE->AIRCR = SCB_AIRCR_VECTKEY | SCB_AIRCR_SYSRESETREQ | prigroup; + asm volatile("dsb"); + while (1) + ; +} diff --git a/libmaple/nvic.h b/libmaple/nvic.h index e3b052d..feb7335 100644 --- a/libmaple/nvic.h +++ b/libmaple/nvic.h @@ -177,6 +177,7 @@ void nvic_init(uint32 vector_table_address, uint32 offset); void nvic_set_vector_table(uint32 address, uint32 offset); void nvic_irq_set_priority(nvic_irq_num irqn, uint8 priority); +void nvic_sys_reset(); /** * Enables interrupts and configurable fault handlers (clear PRIMASK). @@ -238,4 +239,3 @@ static inline void nvic_irq_disable_all(void) { #endif #endif - |