Hi everyone
While working with low-power modes on STM32L1, we found a bug (?) in gcc with -Os optimization - somehow it “optimizes” rather simple periph_clk_en(bus_t bus, uint32_t mask) function in cpu/stm32_common/cpu_common.c, so using it right after waking up from STOP mode results in Hard Fault (for some reasons, in our firmware it is called from clk_init(), and clk_init() is called right after __WFI() in LPM code, as we need to switch MCU from 2 MHz MSI clock back to our default clock settings).
Didn’t dig it any deeper yet, but just for everyone to know:
-void periph_clk_en(bus_t bus, uint32_t mask)
+void attribute((optimize(“O3”))) periph_clk_en(bus_t bus, uint32_t mask)
fixes it.