This is an automated email from the ASF dual-hosted git repository.

jerzy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git

commit 7abecfa870ef347b2c275394bd0b14f8075df29f
Author: Jerzy Kasenberg <jerzy.kasenb...@codecoup.pl>
AuthorDate: Wed Apr 20 16:41:41 2022 +0200

    mcu/nrf5340: Add stack limiter for Main stack
    
    Main stack (used by bootloader and interrupts) was not
    setup to be checked by hardware only (process stack limiter
    was enabled).
    Now Main stack limiter is also enforced.
    
    Signed-off-by: Jerzy Kasenberg <jerzy.kasenb...@codecoup.pl>
---
 hw/mcu/nordic/nrf5340/src/system_nrf5340.c         | 6 ++++++
 hw/mcu/nordic/nrf5340_net/src/system_nrf5340_net.c | 6 ++++++
 2 files changed, 12 insertions(+)

diff --git a/hw/mcu/nordic/nrf5340/src/system_nrf5340.c 
b/hw/mcu/nordic/nrf5340/src/system_nrf5340.c
index 831d232bd..5efc30050 100644
--- a/hw/mcu/nordic/nrf5340/src/system_nrf5340.c
+++ b/hw/mcu/nordic/nrf5340/src/system_nrf5340.c
@@ -61,6 +61,9 @@ NOTICE: This file has been modified by Nordic Semiconductor 
ASA.
     uint32_t SystemCoreClock __attribute__((used)) = __SYSTEM_CLOCK_INITIAL;
 #endif
 
+/* stack limit provided by linker script */
+extern uint32_t __StackLimit[];
+
 void SystemCoreClockUpdate(void)
 {
     SystemCoreClock = __SYSTEM_CLOCK_MAX >> (NRF_CLOCK->HFCLKCTRL & 
(CLOCK_HFCLKCTRL_HCLK_Msk));
@@ -252,6 +255,9 @@ void SystemInit(void)
     SystemCoreClockUpdate();
 
     NVIC_Relocate();
+
+    /* Setup Cortex-M33 stack limiter to detect stack overflow in interrupts 
and bootloader code */
+    __set_MSPLIM((uint32_t)__StackLimit);
 }
 
 /*lint --flb "Leave library region" */
diff --git a/hw/mcu/nordic/nrf5340_net/src/system_nrf5340_net.c 
b/hw/mcu/nordic/nrf5340_net/src/system_nrf5340_net.c
index 499889624..9566ada9c 100644
--- a/hw/mcu/nordic/nrf5340_net/src/system_nrf5340_net.c
+++ b/hw/mcu/nordic/nrf5340_net/src/system_nrf5340_net.c
@@ -44,6 +44,9 @@ NOTICE: This file has been modified by Nordic Semiconductor 
ASA.
     uint32_t SystemCoreClock __attribute__((used)) = __SYSTEM_CLOCK;
 #endif
 
+/* stack limit provided by linker script */
+extern uint32_t __StackLimit[];
+
 void SystemCoreClockUpdate(void)
 {
     SystemCoreClock = __SYSTEM_CLOCK;
@@ -91,6 +94,9 @@ void SystemInit(void)
     SystemCoreClockUpdate();
 
     NVIC_Relocate();
+
+    /* Setup Cortex-M33 stack limiter to detect stack overflow in interrupts 
and bootloader code */
+    __set_MSPLIM((uint32_t)__StackLimit);
 }
 
 /*lint --flb "Leave library region" */

Reply via email to