AnsweredAssumed Answered

STM32F072 PWR_EnterSTOPMode USART problem

Question asked by plec.krzysztof on Oct 2, 2014
Latest reply on Oct 8, 2014 by sung.chen_chung
Hi, I have a major problem about my STM32F072. I'm trying to join usage of PWR_EnterSTOPMode with USART. I use USART1 and 3 from my microcontroller, it initialiaze properly and I'm able to communicate through it. Mentioned issue appears after using PWR_EnterSTOPMode function, USART communication still works but it isn't synchronized, so I get a bunch of incorrect characters on the output. I suposse that there is some kind of mess with system clocks after usage of sleep mode. 
I will be very grateful for any help.

001.    USART_InitTypeDef USART_InitStructure;
002.  GPIO_InitTypeDef GPIO_InitStructure;
003.  NVIC_InitTypeDef NVIC_InitStructure;
004. 
005.  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
006.  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);
007. 
008.  RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE);
009.  RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3,ENABLE);
010. 
011.  ///////////////////////////////////////////____PIN_CFG____///////////////////////////////////////////
012.  RCC->AHBENR |= RCC_AHBENR_GPIOAEN;
013.  GPIOA->MODER = (GPIOA->MODER & ~(GPIO_MODER_MODER8  )) | (GPIO_MODER_MODER8_0 );
014.     //GPIOB->PUPDR |= ~(GPIO_PUPDR_PUPDR3_1);
015.     //GPIOA->PUPDR = (GPIOA->PUPDR & ~(GPIO_PUPDR_PUPDR8_1));
016.   //  Port C
017. 
018.   RCC->AHBENR |= RCC_AHBENR_GPIOCEN;
019.   GPIOC->MODER = (GPIOC->MODER & ~(GPIO_MODER_MODER9 | GPIO_MODER_MODER7| GPIO_MODER_MODER6)) \
020.          | (GPIO_MODER_MODER9_0 | GPIO_MODER_MODER7_0| GPIO_MODER_MODER6_0);
021.   GPIOC->PUPDR = (GPIOC->PUPDR & ~(GPIO_PUPDR_PUPDR9_1 | GPIO_PUPDR_PUPDR7_1| GPIO_PUPDR_PUPDR6_1));
022. 
023.   //  Port B
024. 
025.   RCC->AHBENR |= RCC_AHBENR_GPIOBEN;
026.   GPIOB->MODER = (GPIOB->MODER & ~(GPIO_MODER_MODER0 |GPIO_MODER_MODER1 | GPIO_MODER_MODER2 | GPIO_MODER_MODER3 )) \
027.           | (GPIO_MODER_MODER0_0 | GPIO_MODER_MODER1_0 | GPIO_MODER_MODER2_0 | GPIO_MODER_MODER3_0);
028.   //GPIOB->PUPDR |= ~(GPIO_PUPDR_PUPDR3_1);
029.   GPIOB->PUPDR = (GPIOB->PUPDR & ~(GPIO_PUPDR_PUPDR0_1 | GPIO_PUPDR_PUPDR1_1 | GPIO_PUPDR_PUPDR2_1 | GPIO_PUPDR_PUPDR3_1));
030. 
031.  ///////////////////////////////////////____END_OF_PIN_CFG____///////////////////////////////////////
032. 
033.///////////////////////////////////////////____USART_1____///////////////////////////////////////////
034. 
035.  GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_1);
036.  GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_1);
037. 
038.  // Configure USART1 pins:  Rx and Tx ----------------------------
039.  GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_9 | GPIO_Pin_10;
040.  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
041.  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
042.  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
043.  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
044.  GPIO_Init(GPIOA, &GPIO_InitStructure);
045. 
046.  // Enable USART1 IRQ
047.  NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
048.  NVIC_InitStructure.NVIC_IRQChannelPriority = 0;
049.  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
050.  NVIC_Init(&NVIC_InitStructure);
051. 
052.  USART_InitStructure.USART_BaudRate = 115200;
053.  USART_InitStructure.USART_WordLength = USART_WordLength_8b;
054.  USART_InitStructure.USART_StopBits = USART_StopBits_1;
055.  USART_InitStructure.USART_Parity = USART_Parity_No;
056.  USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
057.  USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
058.  USART_Init(USART1, &USART_InitStructure);
059. 
060.  USART_Cmd(USART1,ENABLE);
061. 
062.  USART_ITConfig(USART1, USART_IT_RXNE, ENABLE); // Enable always
063. 
064.  ///////////////////////////////////////____END_OF_USART_1____/////////////////////////////////////// 
065. 
066.  ///////////////////////////////////////////____USART_3____///////////////////////////////////////////
067. 
068.GPIO_PinAFConfig(GPIOB, GPIO_PinSource10, GPIO_AF_4);
069.  GPIO_PinAFConfig(GPIOB, GPIO_PinSource11, GPIO_AF_4);
070. 
071. // Configure USART3 pins:   and Tx ---------------------------
072.  GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_10 | GPIO_Pin_11;
073.  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
074.  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
075.  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
076.  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
077.  GPIO_Init(GPIOB, &GPIO_InitStructure);
078. 
079.  // Enable USART3 IRQ
080.   NVIC_InitStructure.NVIC_IRQChannel = USART3_4_IRQn;
081.   NVIC_InitStructure.NVIC_IRQChannelPriority = 0;
082.   NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
083.   NVIC_Init(&NVIC_InitStructure);
084. 
085.   USART_InitStructure.USART_BaudRate = 115200;
086.   USART_InitStructure.USART_WordLength = USART_WordLength_8b;
087.   USART_InitStructure.USART_StopBits = USART_StopBits_1;
088.   USART_InitStructure.USART_Parity = USART_Parity_No;
089.   USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
090.   USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
091.   USART_Init(USART3, &USART_InitStructure);
092. 
093.   USART_Cmd(USART3,ENABLE);
094. 
095.   USART_ITConfig(USART3, USART_IT_RXNE, ENABLE); // Enable always
096.//   USART3->CR1 |= USART_CR1_TCIE; enable TC interrupt
097. 
098.//   NVIC_SetPriority(USART3_4_IRQn, 0); // (3)
099.//   NVIC_EnableIRQ(USART3_4_IRQn); // (4) /
100. 
101.  ///////////////////////////////////////____END_OF_USART_3____///////////////////////////////////////
102. 
103.     Configure_GPIO_LED();
104.          GPIO_SetBits(GPIOB, GPIO_Pin_1);
105. 
106.          /* Enable PWR APB1 Clock */
107.          RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
108. 
109.          /* Allow access to Backup */
110.          PWR_BackupAccessCmd(ENABLE);
111. 
112.          /* Reset RTC Domain */
113.          RCC_BackupResetCmd(ENABLE);
114.          RCC_BackupResetCmd(DISABLE);
115.          RTCInit();
116. 
117.          RTC_SetWakeUpCounter(0x3000-1);
118.          /* Enable the Wakeup Interrupt */
119.          RTC_ITConfig(RTC_IT_WUT, ENABLE);
120. 
121.RTC_WakeUpCmd(ENABLE);
122.          PWR_EnterSTOPMode(PWR_Regulator_LowPower, PWR_STOPEntry_WFI);
123.          RTC_WakeUpCmd(DISABLE);




Outcomes