stm32h5: stop/standby mode reset_cause not reported
machine.reset_cause() reports 0 instead of 4 when system starts from stop or standby mode.
MicroPython v1.20.0-288-g3a153d92f-dirty on 2023-10-15; NUCLEO_H563ZI with STM32H563ZI
Type "help()" for more information.
The fix is to to add the following in void machine_init(void)
#elif defined(STM32H5)
if (PWR->PMSR & PWR_PMSR_STOPF || PWR->PMSR & PWR_PMSR_SBF) {
// came out of standby or stop mode
reset_cause = PYB_RESET_DEEPSLEEP;
PWR->PMCR |= PWR_PMCR_CSSF;
} else
A PR will follow in the next days.
`machine.reset_cause()` always returns 0 on Arduino Portenta H7 port
Observed on a Portenta H7, running stock 1.19.1 firmware, over a UART repl:
MicroPython v1.19.1 on 2022-06-18; PORTENTA with STM32H747
Type "help()" for more information.
>>> import machine
>>> machine.reset_cause() # have just soft-reset, so should be 0
0
>>> machine.WDT(timeout=1000) # trigger watchdog reset in 1second
<WDT>
>>> MPY: can't mount SD card
MicroPython v1.19.1 on 2022-06-18; PORTENTA with STM32H747
Type "help()" for more information.
>>> import machine
>>> machine.reset_cause() # have just booted after a watchdog reset; should be equal to machine.WDT_RESET
0
>>> machine.WDT_RESET
3
Update: it's an issue with reset_cause() more generally:
No matter what reset is actually done (I've tried soft, hard, and watchdog), machine.reset_cause() always returns 0. Reading stm.mem32[stm.RCC + stm.RCC_RSR] also returns 0, which I think is expected since modmachine.c tells this register to reset (via RCC->RCC_SR |= RCC_SR_RMVF;) but even if I comment out this line and recompile, the RCC_RSR register still always returns 0. Is it possible the bootloader or other core of the H747 is clearing this before micropython has a chance to?
Have tested on 1.19 and 1.20.