0702_ARM6

练习:

中断实验

main.c

cpp 复制代码
#include "key.h"
int main()
{
    //初始化rcc gpio
    hal_key_rcc_gpio_init();
    //初始化exti
    hal_key_exti_init();
    //初始化gic
    hal_key_gic_init();
    
    while(1){
        
    }
    return 0;
}

key.c

cpp 复制代码
#include "key.h"

//GPIOF初始化
void hal_key_rcc_gpio_init(){
    //1.rcc初始化使能GPIOF控制器
    RCC->MP_AHB4ENSETR |= (0x1<<5);
    //2.GPIO模式设置
    //将PF9引脚设置为输入模式
    GPIOF->MODER &= ~(0x3<<18);
    //将PF7引脚设置为输入模式
    GPIOF->MODER &= ~(0x3<<14);
    //将PF8引脚设置为输入模式
    GPIOF->MODER &= ~(0x3<<16);
}

//EXTI初始化
void hal_key_exti_init(){
    //PF9
    //1.设置PF9外部中断选择寄存器进行连接
    EXTI->EXTICR3 &= ~(0xff<<8);
    EXTI->EXTICR3 |= (0x05<<8);
    //2.设置PF9对应EXTI编号下降沿触发
    EXTI->FTSR1 |= (0x1<<9);
    //3.设置PF9对应EXTI层中断不屏蔽
    EXTI->C1EMR1 |= (0x1<<9);

    //PF7
    //1.设置PF7外部中断选择寄存器进行连接
    EXTI->EXTICR2 &= ~(0xff<<24);
    EXTI->EXTICR2 |= (0x05<<24);
    //2.设置PF7对应EXTI编号下降沿触发
    EXTI->FTSR1 |= (0x1<<7);
    //3.设置PF7对应EXTI层中断不屏蔽
    EXTI->C1EMR1 |= (0x1<<7);

    //PF8
    //1.设置PF8外部中断选择寄存器进行连接
    EXTI->EXTICR3 &= ~(0xff);
    EXTI->EXTICR3 |= (0x05);
    //2.设置PF8对应EXTI编号下降沿触发
    EXTI->FTSR1 |= (0x1<<8);
    //3.设置PF8对应EXTI层中断不屏蔽
    EXTI->C1EMR1 |= (0x1<<8);
}

//GIC初始化
void hal_key_gic_init(){
    //1.使能GICD组0
    GICD->CTRL |= 0x1;

    //PF9
    //GICD
    //1.设置PF9对应中断号99使能
    GICD->ISENABLER[3] |= (0x1<<3);
    //2.设置GICD层中断优先级
    GICD->IPRIORITYR[24] &= ~(0x1f<<27);
    //GICD->IPRIORITYR[24] |= (0x1<<27);
    //3.设置GICD层中断分配
    GICD->ITARGETSR[24] &= ~(0x3<<24);
    GICD->ITARGETSR[24] |= (0x1<<24);
    
    //PF7
    //GICD
    //1.设置PF7对应中断号97使能
    GICD->ISENABLER[3] |= (0x1<<1);
    //2.设置GICD层中断优先级
    GICD->IPRIORITYR[24] &= ~(0x1f<<11);
    //GICD->IPRIORITYR[24] |= (0x1<<11);
    //3.设置GICD层中断分配
    GICD->ITARGETSR[24] &= ~(0x3<<8);
    GICD->ITARGETSR[24] |= (0x1<<8);

    //PF8
    //GICD
    //1.设置PF8对应中断号98使能
    GICD->ISENABLER[3] |= (0x1<<2);
    //2.设置GICD层中断优先级
    GICD->IPRIORITYR[24] &= ~(0x1f<<19);
    //GICD->IPRIORITYR[24] |= (0x1<<19);
    //3.设置GICD层中断分配
    GICD->ITARGETSR[24] &= ~(0x3<<16);
    GICD->ITARGETSR[24] |= (0x1<<16);

    //2.设置GICC层组0使能
    GICC->CTRL |= 0x1;
    //3.设置GICC层中断优先级
    GICC->PMR |= (0xf<<3);
}

key.h

cpp 复制代码
#ifndef __KEY_H__
#define  __KEY_H__
#include "stm32mp1xx_gpio.h"
#include "stm32mp1xx_rcc.h"
#include "stm32mp1xx_exti.h"
#include "stm32mp1xx_gic.h"
extern  void do_irq(void);
// GPIOF初始化
void hal_key_rcc_gpio_init();
// EXTI初始化
void hal_key_exti_init();
// GIC初始化
void hal_key_gic_init();

#endif
相关推荐
TeYiToKu2 天前
笔记整理—linux驱动开发部分(10)input子系统与相关框架
linux·驱动开发·笔记·嵌入式硬件·arm·1024程序员节
亿道电子2 天前
【ARM】MDK-E203 Undefined identifier
arm开发·stm32·单片机·arm
CYRUS STUDIO2 天前
Android下的系统调用 (syscall),内联汇编syscall
android·linux·汇编·arm开发·arm·内联汇编
CYRUS STUDIO4 天前
ARM64汇编寻址、汇编指令、指令编码方式
android·汇编·arm开发·arm·arm64
TeYiToKu5 天前
笔记整理—linux驱动开发部分(9)framebuffer驱动框架
linux·c语言·arm开发·驱动开发·笔记·嵌入式硬件·arm
编程圈子5 天前
I.MX6U 裸机开发2. 芯片简介、汇编基础及GPIO操作准备工作
嵌入式硬件·arm
CyberSecurity_zhang8 天前
Armv8的安全启动
安全·arm·tf-a·tf-m·安全启动
苏寅8 天前
arm64-v8a 和 armeabi-v7a 有啥区别?
arm
冷凝雨15 天前
【复旦微FM33 MCU 外设开发指南】外设篇1——硬件除法器
arm·1024程序员节·复旦微·fm33·fm33lc0
嵌入式小能手16 天前
串口通讯编程示例之开发板测试
linux·嵌入式硬件·arm