[STM32F1] MCU 在 STOP 状态下通过 UART 唤醒分 析

[复制链接]
898|10
 楼主| 药无尘 发表于 2021-11-3 10:33 | 显示全部楼层 |阅读模式
唤醒机制:在 MCU 进入 STOP 状态后, 不能直接通过 UART 等中断外设唤醒, 只能通过 EXTI 外部中断方式唤醒。 但是我们
可以在 MCU 进入 STOP 前将 RX 脚设为 EXTI 模式,并使能对应的中断来实现。相关代码在 STM3210B-EVAL 上测试可以实
现该功能。  

 楼主| 药无尘 发表于 2021-11-3 10:33 | 显示全部楼层
  1. int main(void)
  2. {
  3. #ifdef DEBUG
  4. debug();
  5. #endif
  6. // System Init...
  7. System_Init();
  8. PWR_DeInit();
  9. UART_Init();
  10. // Global Variables Init...
  11. Global_Variables_Init(); // + by dsg for global variables init...
  12. while(1)
  13. {
  14. /* Request to enter STOP mode with regulator in low power mode*/
  15. PWR_EnterSTOPMode(PWR_Regulator_LowPower, PWR_STOPEntry_WFI);
  16. }
  17. }


 楼主| 药无尘 发表于 2021-11-3 10:34 | 显示全部楼层
  1. void EXTIX_Init(void)
  2. {
  3. EXTI_InitTypeDef EXTI_InitStructure;
  4. NVIC_InitTypeDef NVIC_InitStructure;
  5. RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);
  6. GPIO_EXTILineConfig(GPIO_PortSourceGPIOB,GPIO_PinSource11);
  7. EXTI_InitStructure.EXTI_Line=EXTI_Line11; //GPIOA.3 UART2_RX
  8. EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
  9. EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
  10. EXTI_InitStructure.EXTI_LineCmd = ENABLE;
  11. EXTI_Init(&EXTI_InitStructure);
  12. NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQChannel;
  13. NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x02;
  14. NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x01;
  15. NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  16. NVIC_Init(&NVIC_InitStructure);
  17. }
  18. /*******************************************************************************
  19. * Function Name : EXTI15_10_IRQHandler
  20. * Description : This function handles External lines 15 to 10 interrupt request.
  21. * Input : None
  22. * Output : None
  23. * Return : None
  24. *******************************************************************************/
  25. void EXTI15_10_IRQHandler(void)
  26. {
  27. EXTI_ClearITPendingBit(EXTI_Line11);
  28. NVIC_GenerateSystemReset();
  29. }


 楼主| 药无尘 发表于 2021-11-3 10:35 | 显示全部楼层
  1. void PWR_EnterSTOPMode(u32 PWR_Regulator, u8 PWR_STOPEntry)
  2. {
  3. // Change the UART RX PIN to external interrupt mode
  4. EXTIX_Init();
  5. GPIO_ResetBits(GPIOC, GPIO_Pin_6);
  6. GPIO_ResetBits(GPIOC, GPIO_Pin_7);
  7. GPIO_ResetBits(GPIOC, GPIO_Pin_8);
  8. u32 tmpreg = 0;
  9. /* Check the parameters */
  10. assert_param(IS_PWR_REGULATOR(PWR_Regulator));
  11. assert_param(IS_PWR_STOP_ENTRY(PWR_STOPEntry));
  12. /* Select the regulator state in STOP mode ---------------------------------*/
  13. tmpreg = PWR->CR;
  14. /* Clear PDDS and LPDS bits */
  15. tmpreg &= CR_DS_Mask;
  16. /* Set LPDS bit according to PWR_Regulator value */
  17. tmpreg |= PWR_Regulator;
  18. /* Store the new value */
  19. PWR->CR = tmpreg;
  20. /* Set SLEEPDEEP bit of Cortex System Control Register */
  21. *(vu32 *) SCB_SysCtrl |= SysCtrl_SLEEPDEEP_Set;
  22. /* Select STOP mode entry --------------------------------------------------*/
  23. if(PWR_STOPEntry == PWR_STOPEntry_WFI)
  24. {
  25. /* Request Wait For Interrupt */
  26. __WFI();
  27. }
  28. else
  29. {
  30. /* Request Wait For Event */
  31. __WFE();
  32. }
  33. }


 楼主| 药无尘 发表于 2021-11-3 10:36 | 显示全部楼层
  1. void UART_Init(void)
  2. {
  3. GPIO_InitTypeDef GPIO_InitStructure;
  4. USART_InitTypeDef USART_InitStructure;
  5. NVIC_InitTypeDef NVIC_InitStructure;
  6. /* Enable USART3 clock */
  7. RCC_APB1PeriphClockCmd( RCC_APB1Periph_USART3, ENABLE);
  8. // GPIO Settings for USART3
  9. // PB10: TXD_ROOM
  10. GPIO_StructInit(&GPIO_InitStructure);
  11. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
  12. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  13. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
  14. GPIO_Init(GPIOB, &GPIO_InitStructure);
  15. // PB11: RXD_ROOM
  16. GPIO_StructInit(&GPIO_InitStructure);
  17. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
  18. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  19. //GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
  20. GPIO_Init(GPIOB, &GPIO_InitStructure);
  21. /* USARTx configuration ------------------------------------------------------*/
  22. /* USARTx configured as follow:
  23. - BaudRate = 600 baud
  24. - Word Length = 8 Bits
  25. - Two Stop Bit
  26. - Even parity
  27. - Hardware flow control disabled (RTS and CTS signals)
  28. - Receive and transmit enabled
  29. */
  30. USART_DeInit(USART3);
  31. USART_InitStructure.USART_BaudRate =9600;
  32. USART_InitStructure.USART_WordLength = USART_WordLength_9b;
  33. USART_InitStructure.USART_StopBits = USART_StopBits_2;
  34. USART_InitStructure.USART_Parity = USART_Parity_Even;
  35. USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
  36. USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
  37. USART_Init(USART3, &USART_InitStructure);
  38. UartRxON();
  39. // In initial state, waiting for indoor data...
  40. USART_ITConfig(USART3, USART_IT_TXE, DISABLE);
  41. USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);
  42. UART_State=UART_RX; //0; // 0: received state 1: transmit state
  43. /* Enable the USART3 Interrupt */
  44. NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQChannel;
  45. NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 3;
  46. NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
  47. NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  48. NVIC_Init(&NVIC_InitStructure);
  49. /* Enable USART3 */
  50. USART_Cmd(USART3, ENABLE);
  51. }


labasi 发表于 2021-12-1 13:27 | 显示全部楼层
大概需要多长时间啊
guanjiaer 发表于 2021-12-1 13:58 | 显示全部楼层
找原因挺有意思的
heimaojingzhang 发表于 2021-12-1 13:59 | 显示全部楼层
理论上可以通过串口唤醒吗
keaibukelian 发表于 2021-12-1 14:01 | 显示全部楼层
可以设置成其他模式吗
tpgf 发表于 2021-12-1 14:05 | 显示全部楼层
看来跟引脚的模式有关系啊
paotangsan 发表于 2021-12-1 14:06 | 显示全部楼层
有更深层次的低功耗吗
您需要登录后才可以回帖 登录 | 注册

本版积分规则

79

主题

623

帖子

3

粉丝
快速回复 在线客服 返回列表 返回顶部