如果不启用SYSCFG时钟,理论上不是应该无法正常中断么?
但是,在使用GPIOA_Pin_0时,竟然进中断了,为什么?
代码如下,引脚跟战舰探索者不一样,各位可以改下试试。。。求教下原因,求深入解释;
[mw_shl_code=c,true]#include "stm32f4xx.h"
uint32_t inc_ms = 0;
uint8_t light_on = 0;
void SysTickDelayms(uint32_t ms)
{
inc_ms = 0;
SysTick->CTRL |= 0x01;
while(inc_ms < ms);
SysTick->CTRL &= ~(uint32_t)0x1;
}
void GPIOD_Init(void)
{
// 1.配置时钟
RCC->AHB1ENR |= (uint32_t)0x01 << 3; // 启用GPIOD的时钟
// 2.配置模式
GPIOD->MODER |= (uint32_t)0x01 << (12 * 2); // 设置GPIOD12的模式为输出
GPIOD->MODER |= (uint32_t)0x01 << (13 * 2);
GPIOD->MODER |= (uint32_t)0x01 << (14 * 2);
GPIOD->MODER |= (uint32_t)0x01 << (15 * 2);
// 3.配置输出模式
GPIOD->OTYPER &= ~((uint32_t)0x0 << 12); // 0 推挽输出
GPIOD->OTYPER &= ~((uint32_t)0x0 << 13);
GPIOD->OTYPER &= ~((uint32_t)0x0 << 14);
GPIOD->OTYPER &= ~((uint32_t)0x0 << 15);
// 4.配置上下拉
GPIOD-> UPDR |= (uint32_t)0x01 << (12 * 2); // 01 上拉
GPIOD-> UPDR |= (uint32_t)0x01 << (13 * 2);
GPIOD-> UPDR |= (uint32_t)0x01 << (14 * 2);
GPIOD-> UPDR |= (uint32_t)0x01 << (15 * 2);
// 5.配置速度
GPIOD->OSPEEDR |= (uint32_t)0x01 << (12 * 2); // 01 25MHz
GPIOD->OSPEEDR |= (uint32_t)0x01 << (13 * 2);
GPIOD->OSPEEDR |= (uint32_t)0x01 << (14 * 2);
GPIOD->OSPEEDR |= (uint32_t)0x01 << (15 * 2);
// 6.锁定模式(可选,锁定之后引脚模式便不可以更改)
// 略
// 7.配置完成,给定初始输出
GPIOD->BSRRL = (uint16_t)((uint16_t)0x1 << 12); // 置位寄存给定,关闭灯
GPIOD->BSRRH = (uint16_t)((uint16_t)0x1 << 13); // 复位寄存给定,打开灯
GPIOD->BSRRL = (uint16_t)((uint16_t)0x1 << 14);
GPIOD->BSRRH = (uint16_t)((uint16_t)0x1 << 15);
}
void RCC_SetSYSCLK_HSE()
{
__IO uint32_t cfgr = 0;
cfgr = RCC->CFGR;
cfgr &= ~(uint32_t)0x03;
cfgr |= (uint32_t)0x1; // SET HSE AS SYSTEM CLOCK
RCC->CFGR = cfgr;
}
void SysTick_Init()
{
SysTick->LOAD = 1000 * 8 / 8; // HSE 8 MHz, FCLK = SYSCLK / 8
SysTick->CTRL &= ~((uint32_t)0x1 << 2); // CLKSOURCE, =1--FCLK, =0--STCLK(ARM未规定,STM32定义为AHB)
SysTick->CTRL |= ((uint32_t)0x1 << 1); // 启用中断方式
}
void EXTI0_Init()
{
RCC->AHB1ENR |= (uint32_t)0x01; // GPIOA
NVIC_EnableIRQ(EXTI0_IRQn); // 库函数配置
// RCC->APB2ENR |= (uint32_t)0x1 << 14; // 启用SYSCFG,不启用也能中断?
EXTI->IMR |= (uint32_t)0x1;
EXTI->FTSR |= (uint32_t)0x1;
// EXTI->RTSR |= (uint32_t)0x1;
SYSCFG->EXTICR[0] &= ~(uint32_t)0xF;
}
void main()
{
uint32_t delayms = 500;
RCC_SetSYSCLK_HSE();
SysTick_Init();
GPIOD_Init();
EXTI0_Init();
while(1)
{
while(light_on)
{
GPIOD->ODR ^= (uint16_t)0xF << 12;
SysTickDelayms(delayms);
//软中断测试
//EXTI->SWIER |= 0x1;
}
}
}
void SysTick_Handler(void)
{
inc_ms++;
return;
}
void EXTI0_IRQHandler(void)
{
EXTI-> R |= (uint32_t)0x1;
light_on = !light_on;
return;
}
[/mw_shl_code]
|