cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F091 UART1 Wake-UP from stop mode

b239955
Associate II
Posted on June 17, 2016 at 14:03

I've been trying to get this beast to wake up from stop mode when it received data on UART1.

This is my approach in code

int
main()
{
SystemCoreClockUpdate();
initStopMode();
initUart();
//Init other stuff
while
(1)
{
//Do some stuff
enterStopMode();
}
}
void
initStopMode(){
DBGMCU_Config(DBGMCU_STOP, ENABLE); 
//Enable debugger in stop mode
USART_StopModeWakeUpSourceConfig(USART1, USART_WakeUpSource_StartBit);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE); 
//Enable clock for PWR peripheral
}
void
enterStopMode() {
RCC_HSICmd(ENABLE);
RCC_USARTCLKConfig(RCC_USART1CLK_HSI);
USART_STOPModeCmd(USART1, ENABLE);
PWR_EnterSTOPMode(PWR_Regulator_ON, PWR_STOPEntry_WFI); 
//Enter stop mode
}

While it does enter stop mode, I can't get it to wake-up at all. In normal mode, I'm using HSE to provide clock for the system. I just can't figure out what I'm doing wrong, could any of you help me with this ? #uart #low-power-stop-mode
5 REPLIES 5
slimen
Senior
Posted on June 17, 2016 at 14:32

Hi,

You can start from UART example under the STM32F0 cube firmware package, you find the needed for your project under this application:

STM32Cube_FW_F0_V1.6.0\Projects\STM32091C_EVAL\Examples\UART\UART_WakeUpFromStop

This example shows how to configure a UART to wake up the MCU from STOP mode

when the proper stimulus is received.

Regards

Walid FTITI_O
Senior II
Posted on June 17, 2016 at 14:38

Hi ,

You should enable the wake-up from stop interrupt by adding the code below before entering stop mode.

/* Enable the wake up from stop Interrupt */ 
USART_ITConfig(EVAL_COM1, USART_IT_WU, ENABLE);

-Hannibal-
b239955
Associate II
Posted on June 17, 2016 at 16:32

Thank you both for replying so fast :).

I've tried to enable the USART_IT_WU interrupt. I change this function to do it:

void initStopMode(){
DBGMCU_Config(DBGMCU_STOP, ENABLE); //Enable debugger in stop mode
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE); //Enable clock for PWR peripheral
RCC_HSICmd(ENABLE); //Enable high speed internal oscilator
USART_StopModeWakeUpSourceConfig(USART1, USART_WakeUpSource_StartBit);
USART_ITConfig(USART1, USART_IT_WU, ENABLE);
USART_STOPModeCmd(USART1, ENABLE);
}

And added these lines to my interrupt handler:

if (USART_GetITStatus(p->usart, USART_IT_WU) != RESET) { // wake-up interrupt
USART_ClearITPendingBit(p->usart, USART_IT_WU);
}

It still doesn't want to wake up. I forgot to mention that I also have enabled DMA for USART1, but I guess that won't make a difference. I will definitely check out the example that you recommended, and compare it to my code, and probably flash it to my MCU to see if it does work with the example.
b239955
Associate II
Posted on June 17, 2016 at 16:57

Just checked out the example project. We're using the standard peripheral driver library, and the example code is written using the newer HAL libraries. I did compare the sequence in which command's are executed in the example project, it seems like I'm doing it in the right order.

My first guess now is that it has something to do with system clocks. ST documentation is a little vague on that. It says in the reference manual that entering stop mode disables the HSI. It also says that UART is able to wake up the core when it's clocked by LSE or HSI. I don't have a low speed oscillator connected. I do have and external crystal at 12 Mhz, which powers the system during normal operation. Right now I'm i switching the clock source for UART1 to HSI right before entering stop mode.

b239955
Associate II
Posted on June 23, 2016 at 17:27

Continued working on resolving this issue, read in the reference manual that waking up from UART would only work with UART disabled, so I tried disabling it before entering stop mode. It still does not work.

I did try another approach today, cause I was pretty much out of options with waking up from UART1. I reconfigured PA10 at run time, as an EXTI line, and tried to wake up from that. First I tried switching if I could reconfigure at run time, by checking if it triggered the interrupt handler, which it did. When I entered stop mode however, it still doesn't wake up. I'm beginning to think somehow this chip enters limbo when it enters stop mode. This is my code for reconfiguring PA10, and entering stop mode:


USART_DMACmd(USART1, USART_DMAReq_Rx, DISABLE); //Disable DMA for UART1
GPIO_InitTypeDef gpioInit;
gpioInit.GPIO_Pin = GPIO_Pin_10;
gpioInit.GPIO_Mode = GPIO_Mode_IN;
gpioInit.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOA, &gpioInit);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_0); // Rx
NVIC->ICPR[0] = 0xFF; //Clear pending interrupts
EXTI_InitTypeDef initStruct;
SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA, EXTI_PinSource10);
EXTI_StructInit(&initStruct);
initStruct.EXTI_Line = EXTI_Line10;
initStruct.EXTI_Mode = EXTI_Mode_Event;
initStruct.EXTI_LineCmd = ENABLE;
initStruct.EXTI_Trigger = EXTI_Trigger_Rising_Falling;
EXTI_Init(&initStruct);
NVIC_InitTypeDef NVIC_InitStruct;
NVIC_InitStruct.NVIC_IRQChannel = EXTI4_15_IRQn;
NVIC_InitStruct.NVIC_IRQChannelPriority = 0x03;
NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStruct);
PWR_EnterSTOPMode(PWR_Regulator_LowPower, PWR_STOPEntry_WFI); //Enter stop mode
GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_1); // Rx
USART_DMACmd(USART1, USART_DMAReq_Rx, ENABLE); //Enable DMA for UART1

It would be great if ST provided clearer instructions on this subject. The documentation is not very clear on how to use low power modes, at least it isn't in my opinion. My sincerest thanks in advance to anyone help me with this, you would be my hero :).