cancel
Showing results for 
Search instead for 
Did you mean: 

Enter and Exit STOP Mode with RTC and EXTI

yoann2
Associate II
Posted on July 27, 2016 at 16:36

Hello,

I have made a previous subject for exit standby mode with WKUP and RTC but no response wet, so i have try to to do the same with STOP mode also problems... Platfrom is STM32L162 I just want to : Enter in STOP Mode Exit if i have RTC timer IT or EXTI IT on PC13 pin During my tests it's seems that i don't enter in STOP Mode, I am wake up every time withTIM2_IRQHandler even if it's deactivated with HAL_SuspendTick, my code is very simple :

void system_clock_config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct;
RCC_ClkInitTypeDef RCC_ClkInitStruct;
RCC_PeriphCLKInitTypeDef PeriphClkInit;
__HAL_RCC_PWR_CLK_ENABLE();
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_LSI
|RCC_OSCILLATORTYPE_HSE;
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
RCC_OscInitStruct.HSICalibrationValue = 16;
RCC_OscInitStruct.LSIState = RCC_LSI_ON;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL6;
RCC_OscInitStruct.PLL.PLLDIV = RCC_PLL_DIV3;
HAL_RCC_OscConfig(&RCC_OscInitStruct);
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1);
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_RTC;
PeriphClkInit.RTCClockSelection = RCC_RTCCLKSOURCE_LSI;
HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit);
HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);
HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
/* SysTick_IRQn interrupt configuration */
HAL_NVIC_SetPriority(SysTick_IRQn, 15, 0);
}

void Configure_PC13(void) {
/* Set variables used */
GPIO_InitTypeDef GPIO_InitStruct;
/* Set pin as input */
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
GPIO_InitStruct.Pin = WAKEUP_TILT_Pin;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
__HAL_GPIO_EXTI_CLEAR_FLAG(WAKEUP_TILT_Pin);
NVIC_ClearPendingIRQ(EXTI15_10_IRQn);
/* Add IRQ vector to NVIC */
HAL_NVIC_SetPriority(EXTI15_10_IRQn, 2, 0);
HAL_NVIC_EnableIRQ(EXTI15_10_IRQn);
}

void enter_stop_mode(void)
{
/* RTC configuration */
RTCHandle.Instance = RTC;
RTCHandle.Init.HourFormat = RTC_HOURFORMAT_24;
RTCHandle.Init.AsynchPrediv =0x7F; // LSE as RTC clock: RTC_ASYNCH_PREDIV
RTCHandle.Init.SynchPrediv = 0x00FF; // LSE as RTC clock: RTC_SYNCH_PREDIV;
RTCHandle.Init.OutPut = RTC_OUTPUT_DISABLE;
RTCHandle.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
RTCHandle.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
Configure_PC13();
HAL_RTCEx_SetWakeUpTimer_IT(&RTCHandle, 0x000A, RTC_WAKEUPCLOCK_CK_SPRE_16BITS);
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);
HAL_GPIO_WritePin(GPIOE, LED1_Pin, 0);
HAL_GPIO_WritePin(GPIOE, LED2_Pin, 0);
HAL_GPIO_WritePin(GPIOE, LED3_Pin, 0);
HAL_SuspendTick();
/* Enter Stop Mode */
HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);
////////////////
// STOP MODE
////////////////
HAL_ResumeTick();
/* Disable Wakeup Counter */
HAL_RTCEx_DeactivateWakeUpTimer(&RTCHandle);
/* Configures system clock after wake-up from STOP: enable HSE, PLL and select
PLL as system clock source (HSE and PLL are disabled in STOP mode) */
system_clock_config();
// Blinking LED to mark end of STOP Mode
HAL_GPIO_TogglePin(GPIOE, LED1_Pin);
HAL_Delay(200);
HAL_GPIO_TogglePin(GPIOE, LED1_Pin);
}

Thanks

#rtc #standby #stm32l1 #stop #shallow-pool
4 REPLIES 4
Posted on July 27, 2016 at 17:07

..but no response yet..

 

I wouldn't suggest you get your expectations too high.

Unfortunately your part isn't heavily used by forum participants and even less with this library. You'd perhaps be better discussing your project with your FAE, or forums focusing on the L162 security processor.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
yoann2
Associate II
Posted on July 27, 2016 at 17:19

Thanks Clive1 for your fast response, i was thinking my problem is pretty simple, anything in my code can explain why I don't enter in Stop Mode ?

After the instruction 

HAL_PWR_EnterSTOPMode, i am in STOP mode you are alright ?instruction after this line should be execute  after Exit STOP condition isn't it ?

yoann2
Associate II
Posted on August 02, 2016 at 17:21

Hi,

For my previous post there is a Errata sheet from ST : DM00106315 and we can't be wake in our case from standby after RTC AND WKUP because our WKUP pin is high before entering in standby...

I have still problem to enter in STOP mode, i never enter in this mode just like a interrupt occur every time, example are very simple but this doesn't work any idea : reconfigure clock because STOP, disable some hidden IRQ ??

Posted on February 08, 2018 at 17:14

Hi, i haved the same problem, and found the fix reading the Datasheet:

'To enter Stop mode, all EXTI Line pending bits (in Pending register EXTI_PR)) and RTC Alarm flag must be reset. Otherwise, the Stop mode entry procedure is ignored and program execution continues'

Sure to clear all pending bits in 

EXTI_PR, to force a stop mode enter 

EXTI->PR = 0xFFFFFFFF;

HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);