Skip to content

Commit 13d653b

Browse files
committed
stm32n6: Add sys_get_reset_reason() backed by RCC_RSR
Mirror the pattern used by the other stm32 ports. Reads RCC_RSR once in an early constructor, maps the STM32N6-specific flags to the portable reset_reason_t bits, and clears the flags via RMVF so the next boot reflects only the new cause. The sysinfo shell command then prints the cause on reboot like it does on h7/g4/f4. Reset-reason bits from RM0486 §14.10.8 (RCC_RSR): bit 30 LPWRRSTF → LOW_POWER_RESET bit 28 WWDGRSTF → WATCHDOG bit 26 IWDGRSTF → WATCHDOG bit 24 SFTRSTF → SW_RESET bit 23 PORRSTF → POWER_ON bit 22 PINRSTF → EXT_RESET bit 21 BORRSTF → BROWNOUT bit 17 LCKRSTF → CPU_LOCKUP
1 parent de86136 commit 13d653b

3 files changed

Lines changed: 62 additions & 0 deletions

File tree

src/platform/stm32n6/stm32n6.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ SRCS += ${C}/systick.c \
2525
${P}/stm32n6_dma.c \
2626
${P}/stm32n6_rif.c \
2727
${P}/stm32n6_idle.c \
28+
${P}/stm32n6_info.c \
2829

2930
SRCS-${ENABLE_NET_IPV4} += ${P}/stm32n6_eth.c
3031

src/platform/stm32n6/stm32n6_clk.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#define RCC_SR (RCC_BASE + 0x004)
99
#define RCC_CFGR1 (RCC_BASE + 0x020)
1010
#define RCC_CFGR2 (RCC_BASE + 0x024)
11+
#define RCC_RSR (RCC_BASE + 0x034)
1112

1213
#define RCC_PLLxCFGR1(x) (RCC_BASE + 0x70 + (x) * 0x10)
1314
#define RCC_PLLxCFGR2(x) (RCC_BASE + 0x74 + (x) * 0x10)
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#include <mios/sys.h>
2+
3+
#include "stm32n6_reg.h"
4+
#include "stm32n6_clk.h"
5+
6+
// RCC_RSR bit layout (RM0486 §14.10.8):
7+
// bit 30 LPWRRSTF — Illegal Stop or Standby
8+
// bit 28 WWDGRSTF — Window watchdog reset
9+
// bit 26 IWDGRSTF — Independent watchdog reset
10+
// bit 24 SFTRSTF — Software reset (SYSRESETREQ)
11+
// bit 23 PORRSTF — POR/PDR
12+
// bit 22 PINRSTF — Pin (NRST) reset
13+
// bit 21 BORRSTF — Brownout reset
14+
// bit 17 LCKRSTF — CPU lockup
15+
// bit 16 RMVF — write-1 to clear all flags
16+
17+
#define RCC_RSR_LPWRRSTF (1u << 30)
18+
#define RCC_RSR_WWDGRSTF (1u << 28)
19+
#define RCC_RSR_IWDGRSTF (1u << 26)
20+
#define RCC_RSR_SFTRSTF (1u << 24)
21+
#define RCC_RSR_PORRSTF (1u << 23)
22+
#define RCC_RSR_PINRSTF (1u << 22)
23+
#define RCC_RSR_BORRSTF (1u << 21)
24+
#define RCC_RSR_LCKRSTF (1u << 17)
25+
#define RCC_RSR_RMVF (1u << 16)
26+
27+
static uint32_t reset_reason;
28+
29+
static void __attribute__((constructor(102)))
30+
stm32n6_get_reset_reason(void)
31+
{
32+
uint32_t rr = reg_rd(RCC_RSR);
33+
uint32_t n = 0;
34+
35+
if(rr & RCC_RSR_LPWRRSTF)
36+
n |= RESET_REASON_LOW_POWER_RESET;
37+
if(rr & (RCC_RSR_IWDGRSTF | RCC_RSR_WWDGRSTF))
38+
n |= RESET_REASON_WATCHDOG;
39+
if(rr & RCC_RSR_SFTRSTF)
40+
n |= RESET_REASON_SW_RESET;
41+
if(rr & RCC_RSR_PORRSTF)
42+
n |= RESET_REASON_POWER_ON;
43+
if(rr & RCC_RSR_PINRSTF)
44+
n |= RESET_REASON_EXT_RESET;
45+
if(rr & RCC_RSR_BORRSTF)
46+
n |= RESET_REASON_BROWNOUT;
47+
if(rr & RCC_RSR_LCKRSTF)
48+
n |= RESET_REASON_CPU_LOCKUP;
49+
50+
// Clear the flags so the next boot shows only the new cause
51+
reg_wr(RCC_RSR, RCC_RSR_RMVF);
52+
53+
reset_reason = n;
54+
}
55+
56+
reset_reason_t
57+
sys_get_reset_reason(void)
58+
{
59+
return reset_reason;
60+
}

0 commit comments

Comments
 (0)