All global variables set to non-initialized values after HAL_SYSTICK_Config()
I am using the B-L072Z-LRWAN1 board. All global variables are their initialized values up until SystemClock_Config() executes HAL_RCC_OscConfig() which executes HAL_InitTick(). Once it reaches that point, all the global variables get filled with garbage values, and the program counter seems to stop executing the source code in main.c, and loops around a file called 0x1FF0017C.
The program did not always do this. it changed when I added code to debug the controller in LP run and stop mode. Here is the functions for entering LP run mode:
//put the controller in low-powered run mode
void enter_LPRun(void)
{
/* 1. Each digital IP clock must be enabled or disabled by using the
RCC_APBxENR and RCC_AHBENR registers */
RCC->APB1ENR |= RCC_APB1ENR_PWREN;
RCC->APB1ENR |= RCC_APB1ENR_LPTIM1EN;
RCC->APB2ENR |= RCC_APB2ENR_SPI1EN;
/* 2. The frequency of the system clock must be decreased to not exceed the
frequency of f_MSI range1. */
// Reinitialize peripherals dependent on clock speed
MX_LPTIM1_Init();
MX_SPI1_Init();
/* 3. The regulator is forced in low-power mode by software
(LPRUN and LPSDSR bits set ) */
//enable fast wake up for debugging
PWR->CR |= PWR_CR_FWU;
CLEAR_BIT(PWR->CR, PWR_CR_LPRUN); // Be sure LPRUN is cleared!
HAL_PWREx_EnableLowPowerRunMode();
}
and in the while(1) loop, under a conditional, here is the code to put the controller in stop mode.
//enable debugging in stop mode
SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STOP);
//this bit has to be cleared before entering stop mode
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);
//enter STOP mode, wait for interrupt
HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);
Attached is my ioc file. Let me know if you need anything else.
edit: more precisely, the behaviour happens on the command NVIC_SetPriority() here (ticks = 131):
__STATIC_INLINE uint32_t SysTick_Config(uint32_t ticks)
{
if ((ticks - 1UL) > SysTick_LOAD_RELOAD_Msk)
{
return (1UL); /* Reload value impossible */
}
SysTick->LOAD = (uint32_t)(ticks - 1UL); /* set reload register */
NVIC_SetPriority (SysTick_IRQn, (1UL << __NVIC_PRIO_BITS) - 1UL); /* set Priority for Systick Interrupt */
SysTick->VAL = 0UL; /* Load the SysTick Counter Value */
SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk |
SysTick_CTRL_TICKINT_Msk |
SysTick_CTRL_ENABLE_Msk; /* Enable SysTick IRQ and SysTick Timer */
return (0UL); /* Function successful */
}
