Page 1 of 1
stm32u3 stop3
Posted: Fri Jul 31, 2026 1:22 am
by geoffrey.brown
I'm trying to get stop3 working. One issue is that after the wfi, it's necessary to restart the clocks. One procedure that "appears" to do this is hal_lld_clock_switch_mode; however, there appears to be an assumption in this code that the system clock is HCLK. It also seems that this might be overkill in a situation where we only use MSI and MSIK at 24mhz.
bool hal_lld_clock_switch_mode(const halclkcfg_t *ccp) {
if (hal_lld_clock_check_tree(ccp)) {
return true;
}
if (hal_lld_clock_configure(ccp)) {
return true;
}
/* Updating the current system clock setting value.*/
hal_lld_set_coreclock(hal_lld_get_clock_point(CLK_HCLK));
return false;
}
Re: stm32u3 stop3
Posted: Fri Jul 31, 2026 4:12 am
by Giovanni
Could you be more specific? restarting clock should just be switching to the hal_clkcfg_default configuration again. The core clock is always HCLK I think.
Giovanni
Re: stm32u3 stop3
Posted: Fri Jul 31, 2026 11:30 am
by geoffrey.brown
Here's how I have my clocks enabled
#define STM32_HSI16_ENABLED FALSE
#define STM32_HSIKERON_ENABLED FALSE
#define STM32_HSI48_ENABLED FALSE
#define STM32_HSE_ENABLED FALSE
#define STM32_LSI_ENABLED FALSE
#define STM32_LSE_ENABLED TRUE
#define STM32_LSE_BYPASS TRUE
#define STM32_MSIRC0_MODE RCC_MSIRC0_FREE
#define STM32_MSIRC1_MODE RCC_MSIRC1_FREE
#define STM32_MSIPLL1N_VALUE 0
#define STM32_MSIS_SRCDIV RCC_ICSCR1_MSIS_IRC1_DIV2
#define STM32_MSIK_SRCDIV RCC_ICSCR1_MSIK_IRC1_DIV1
#define STM32_MSIBIAS RCC_ICSCR1_MSIBIAS_CONTINUOUS
#define STM32_SW RCC_CFGR1_SW_MSIS
#define STM32_HPRE RCC_CFGR2_HPRE_DIV1
#define STM32_PPRE1 RCC_CFGR2_PPRE1_DIV1
#define STM32_PPRE2 RCC_CFGR2_PPRE2_DIV1
#define STM32_PPRE3 RCC_CFGR3_PPRE3_DIV1
#define STM32_STOPWUCK RCC_CFGR1_STOPWUCK_MSIS
#define STM32_STOPKERWUCK RCC_CFGR1_STOPKERWUCK_MSIK
#define STM32_MCO1SEL RCC_CFGR1_MCO1SEL_OFF
#define STM32_MCO1PRE_VALUE 1
#define STM32_MCO2SEL RCC_CFGR1_MCO2SEL_OFF
#define STM32_MCO2PRE_VALUE 1
#define STM32_LSCOSEL RCC_BDCR_LSCOSEL_NOCLOCK
Re: stm32u3 stop3
Posted: Fri Jul 31, 2026 3:10 pm
by Giovanni
Does applying hal_clkcfg_default work for you? the initialization code is already there used at startup so it is not overkill. You need to enable dynamic clocking in mcuconf.h to use it.
BTW, currently there are 2 U3 port, the one postfixed with _TEST is the new one, feedback is appreciated because the code is generated using a new tool from an XML clock tree description.
Giovanni
Re: stm32u3 stop3
Posted: Mon Aug 10, 2026 1:02 am
by geoffrey.brown
I never really got things working properly with stop3. I could execute code afterwards, but no longer write to flash for logging. I ended up taking the cowards way out -- park a tag in the backup registers and reset. In the particular software architecture, that was "normal" since on the stm32l432 I use standby. On the stm32u375 I never managed to get standby working properly. It's one of those features that ST doesn't seem to be able to document meaningfully and their forum is less than useless ("try the hal examples" -- which are mostly wrong anyway).
I will try your new port to see what happens.
Geoffrey