Skip to main content
Associate II
January 14, 2026
Question

Hard Fault running cmwx1zzabz_0xx on B-L072Z-LRWAN1 discovery board

  • January 14, 2026
  • 2 replies
  • 211 views

When I Debug cmwx1zzabz_0xx, I get a hard fault somewhere near a call to HAL_PWR_EnterSLEEPMode(). It happens just after all the init code, somewhere in the first call to MX_LoRaWAN_Process(). If I step into MX_LoRaWAN_Process() and continue stepping, there is no fault.

Note that I commented out the calls to DBG_Disable() and DBG_ProbesInit() in SystemApp_Init() since they drop the ST-Link connection over USB.

 

2 replies

Andrew Neil
Super User
January 14, 2026
A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
CCPAuthor
Associate II
January 14, 2026

Thanks for the useful article. I recompiled with optimizations off. The PC after the Hard Fault suggests this line in HAL_PWR_EnterSTOPMode():
...

 
/* Select Stop mode entry --------------------------------------------------*/
if(STOPEntry == PWR_STOPENTRY_WFI)
{
 /* Request Wait For Interrupt */
 __WFI();
}
else
{
 /* Request Wait For Event */
 __SEV();
 __WFE();
 __WFE();
}


/* Reset SLEEPDEEP bit of Cortex System Control Register */
CLEAR_BIT(SCB->SCR, SCB_SCR_SLEEPDEEP_Msk);

The request waits for event before executing the problem CLEAR_BIT macro. If I set a breakpoint on it, run to it and continue, the fault doesn't occur.

 

I tried replacing the CLEAR_BIT macro by reading the register to a local variable, clearing the bit in the variable and writing back to the register. This appears to fix the problem, but only if I build with Optimizations off (-O0). Any suggestions?


Edited to apply source code formatting - please see How to insert source code for future reference.