2014-10-02 07:28 AM
Hi, I have a major problem about mySTM32F I'm trying to join usage ofPWR_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 usingPWR_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.
USART_InitTypeDef USART_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3,ENABLE);
///////////////////////////////////////////____PIN_CFG____///////////////////////////////////////////
RCC->AHBENR |= RCC_AHBENR_GPIOAEN;
GPIOA->MODER = (GPIOA->MODER & ~(GPIO_MODER_MODER8 )) | (GPIO_MODER_MODER8_0 );
//GPIOB->PUPDR |= ~(GPIO_PUPDR_PUPDR3_1);
//GPIOA->PUPDR = (GPIOA->PUPDR & ~(GPIO_PUPDR_PUPDR8_1));
// Port C
RCC->AHBENR |= RCC_AHBENR_GPIOCEN;
GPIOC->MODER = (GPIOC->MODER & ~(GPIO_MODER_MODER9 | GPIO_MODER_MODER7| GPIO_MODER_MODER6)) \
| (GPIO_MODER_MODER9_0 | GPIO_MODER_MODER7_0| GPIO_MODER_MODER6_0);
GPIOC->PUPDR = (GPIOC->PUPDR & ~(GPIO_PUPDR_PUPDR9_1 | GPIO_PUPDR_PUPDR7_1| GPIO_PUPDR_PUPDR6_1));
// Port B
RCC->AHBENR |= RCC_AHBENR_GPIOBEN;
GPIOB->MODER = (GPIOB->MODER & ~(GPIO_MODER_MODER0 |GPIO_MODER_MODER1 | GPIO_MODER_MODER2 | GPIO_MODER_MODER3 )) \
| (GPIO_MODER_MODER0_0 | GPIO_MODER_MODER1_0 | GPIO_MODER_MODER2_0 | GPIO_MODER_MODER3_0);
//GPIOB->PUPDR |= ~(GPIO_PUPDR_PUPDR3_1);
GPIOB->PUPDR = (GPIOB->PUPDR & ~(GPIO_PUPDR_PUPDR0_1 | GPIO_PUPDR_PUPDR1_1 | GPIO_PUPDR_PUPDR2_1 | GPIO_PUPDR_PUPDR3_1));
///////////////////////////////////////____END_OF_PIN_CFG____///////////////////////////////////////
///////////////////////////////////////////____USART_1____///////////////////////////////////////////
GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_1);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_1);
// Configure USART1 pins: Rx and Tx ----------------------------
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_10;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
// Enable USART1 IRQ
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
USART_InitStructure.USART_BaudRate = 115200;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Init(USART1, &USART_InitStructure);
USART_Cmd(USART1,ENABLE);
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE); // Enable always
///////////////////////////////////////____END_OF_USART_1____///////////////////////////////////////
///////////////////////////////////////////____USART_3____///////////////////////////////////////////
GPIO_PinAFConfig(GPIOB, GPIO_PinSource10, GPIO_AF_4);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource11, GPIO_AF_4);
// Configure USART3 pins: and Tx ---------------------------
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10 | GPIO_Pin_11;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOB, &GPIO_InitStructure);
// Enable USART3 IRQ
NVIC_InitStructure.NVIC_IRQChannel = USART3_4_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
USART_InitStructure.USART_BaudRate = 115200;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Init(USART3, &USART_InitStructure);
USART_Cmd(USART3,ENABLE);
USART_ITConfig(USART3, USART_IT_RXNE, ENABLE); // Enable always
// USART3->CR1 |= USART_CR1_TCIE; enable TC interrupt
// NVIC_SetPriority(USART3_4_IRQn, 0); // (3)
// NVIC_EnableIRQ(USART3_4_IRQn); // (4) /
///////////////////////////////////////____END_OF_USART_3____///////////////////////////////////////
Configure_GPIO_LED();
GPIO_SetBits(GPIOB, GPIO_Pin_1);
/* Enable PWR APB1 Clock */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
/* Allow access to Backup */
PWR_BackupAccessCmd(ENABLE);
/* Reset RTC Domain */
RCC_BackupResetCmd(ENABLE);
RCC_BackupResetCmd(DISABLE);
RTCInit();
RTC_SetWakeUpCounter(0x3000-1);
/* Enable the Wakeup Interrupt */
RTC_ITConfig(RTC_IT_WUT, ENABLE);
RTC_WakeUpCmd(ENABLE);
PWR_EnterSTOPMode(PWR_Regulator_LowPower, PWR_STOPEntry_WFI);
RTC_WakeUpCmd(DISABLE);
#wfi-pwr_enterstopmode-interrupt #stm32f072
2014-10-08 04:06 AM
Hi
If you look at the reference manual, you will see that in STOP mode ''All 1.2 V domain clocks OFF'' and ''HSI and HSE oscillators OFF'' This will affect any peripheral devices that are clocked from these internal clock sources. This will probably explain why you are getting incorrect characters on the output. You need to check the reference manual to see how long it takes for the clocks to recover and flush the UART buffer until the clock has recovered.