现象:调试STM32F411低功耗的时候,使用的PA1做个唤醒源,发现在没有触发EXTI的时候,MCU居然被唤醒。
原因:PA1配置成EXTI(上拉输入),经常被误触发
解决方式:将PA1配置成浮空输入,并且外部上拉一个4.7k电阻,就不会误触发了。
这种bug的原因一直没有搞清,先记下省的以后就忘记了,猜测可能是STM32芯片bug。
EXTI配置代码如下:
void TM_SetExit(FunctionalState State)
{
//PA1
#define REQUEST_PORT GPIOA
#define REQUEST_PIN GPIO_Pin_1
#define REQUEST_CLK_BUS RCC_AHB1Periph_GPIOA
#define REQUEST_PORT_SRC EXTI_PortSourceGPIOA
#define REQUEST_PIN_SRC GPIO_PinSource1
#define REQUEST_EXTI_LINE EXTI_Line1
#define REQUEST_NVIC_CHANNEL EXTI1_IRQn
GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
EXTI_InitTypeDef EXTI_InitStructure;
RCC_AHB1PeriphClockCmd(REQUEST_CLK_BUS, ENABLE);
GPIO_InitStructure.GPIO_Pin = REQUEST_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;//GPIO_PuPd_UP;
GPIO_Init(REQUEST_PORT, &GPIO_InitStructure);
SYSCFG_EXTILineConfig(REQUEST_PORT_SRC, REQUEST_PIN_SRC);
NVIC_InitStructure.NVIC_IRQChannel = REQUEST_NVIC_CHANNEL;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 6;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = State;
NVIC_Init(&NVIC_InitStructure);
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_LineCmd = State;
EXTI_InitStructure.EXTI_Line = REQUEST_EXTI_LINE;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_Init(&EXTI_InitStructure);
EXTI_ClearITPendingBit(REQUEST_EXTI_LINE);
}
原文地址:https://www.cnblogs.com/mfc1207/p/9324324.html