#ifndef __KEY_H__
#define __KEY_H__#include "stm32mp1xx_rcc.h"
#include "stm32mp1xx_gpio.h"
#include "stm32mp1xx_exti.h"
#include "stm32mp1xx_gic.h"//对RCC/GPIO/EXTI章节的初始化
void hal_key1_exti_init();//对GIC的初始化
void hal_key1_gic_init();#endif#include "key.h"
extern void printf(const char *fmt, ...);void do_irq(void)
{unsigned int num;num = GICC->IAR & 0x3ff;switch (num){case 99:printf("key1 press#####\n");//1.消除EXTI层中断挂起标志位EXTI->FPR1 |= (0x1 << 9);//2.消除GICD层的中断挂起标志位GICD->ICPENDR[3] |= (0x1 << 3);break;case 98:break;case 97:break;}//3.清除获取到的中断号GICC->EOIR |= num;
}#include "key.h"//对RCC/GPIO/EXTI章节的初始化
void hal_key1_exti_init()
{//RCCRCC->MP_AHB4ENSETR |= (0x1 << 5);//GPIO设置输入模式GPIOF->MODER &= (~(0x3 << 18));//EXTI//1.外部中断选择寄存器,选择与哪个EXTI(16)链接EXTI->EXTICR3 &= (~(0xff << 8));EXTI->EXTICR3 |= (0x5 << 8);//2.设置中断下降沿触发方式EXTI->FTSR1 |= (0x1 << 9);//3.中断屏蔽选择寄存器EXTI->C1IMR1 |= (0b01 << 9);}//对GIC的初始化
void hal_key1_gic_init()
{//GICD的初始化//1.使能GICD层控制器GICD->CTLR |= 0x1;//2.设置GICD层的中断使能GICD->ISENABLER[3] |= (0x1 << 3);//3.设置GICD层中断优先级GICD->IPRIORITYR[24] &= (~(0x1F << 27));//4.设置GICD层中断目标分配寄存器GICD->ITARGETSR[24] |= (0x1 << 24);//GICC章节初始化//1.使能GICC层控制器GICC->CTLR |= 0x1;//2.设置GICC层中断优先级GICC->PMR |= (0x1 << 3);
}