cancel
Showing results for 
Search instead for 
Did you mean: 

Sleepmode not working properly

MCasas
Associate II

Hello,

I'm using a stm32f070f6 mcu.

My problem is that, when I debug separately my bootloader and my APP code, everything works fine, but when I put them together in a hex file and upload it to my MCU(the bootloader remaps the IVT to the RAM before jumping and deinitialize all the used peripherals on it), everything works fine except the sleepmode.

The sleepmode is usually woken up by the TMR16 UIE interrupt, which at the same is the interrupt used in the bootloader to count how many seconds I should stay there. If I disable the sleepmode from the APP, the TMR16 is not used anymore in the app, and everything works fine.

That's the part of the code in which I denitialize all the peripherals:

			__disable_irq(); //disable interrupts before jumping to the application
 
			LL_I2C_DeInit(I2C1);
			LL_TIM_DeInit(TIM14);
			LL_TIM_DeInit(TIM16);
			LL_TIM_ClearFlag_UPDATE(TIM16);
			LL_TIM_DisableIT_UPDATE(TIM16);
			LL_USART_DeInit(USART2);
 
			/* Set Vector Table Offset Register */
 
			  for(uint8_t i = 0; i < 48; i++)
			  {
				VectorTable[i] = *(__IO uint32_t*)(APP_ADDRESS + (i<<2));
			  }
 
			  /* Enable the SYSCFG peripheral clock*/
			  __RCC_SYSCFG_CLK_ENABLE();
 
			  /* Remap SRAM at 0x00000000 */
			  __SYSCFG_REMAPMEMORY_SRAM();
 
			  __enable_irq(); ///////////////////ACTIVAR AQU�?
 
//			__DMB();
 
//			__set_CONTROL(0); //ensure that the Main Stack Pointer is being used
 
			/* Initialize user application's Stack Pointer */
			__set_MSP(*(__IO uint32_t*) APP_ADDRESS);
			Jump_To_Application();

and this is the sleepmode function that if I comment, everything works fine:

void sleepmode_WFI(void)
{
	LL_LPM_EnableSleep(); //enable sleepmode
	LL_TIM_ClearFlag_UPDATE(TIM16); //clear UIE Flag
	LL_TIM_SetCounter(TIM16, 0); //TMR16->CNT = 0 ;
	LL_TIM_EnableIT_UPDATE(TIM16); //enable timer 16 interrupt
	LL_TIM_EnableCounter(TIM16); //start the timer 16 which will wake up the device every 1 second
	UART_printf("sleep\n\r", sizeof("sleep\n\r"));
    __WFI(); //enter in sleepmode
}
 
 

Thank you for your help.

1 REPLY 1
MCasas
Associate II

Can someone give me a hand with that, please?

Thanks!