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
相关推荐
一枝小雨6 天前
ARM异常处理流程与中断机制总结,与常见丢中断情况
arm开发·嵌入式硬件·架构·系统架构·arm
亿道电子Emdoor9 天前
【ARM】MDK-解决中文注释的乱码问题
arm开发·stm32·单片机·arm·mdk
亿道电子Emdoor10 天前
【ARM】MDK-解决单机版LIC获取报错
arm开发·stm32·单片机·arm
Invinciblenuonuo13 天前
STM32八股【1】-----启动流程和startup文件理解
stm32·arm
亿道电子Emdoor1 个月前
【ARM】DS如何查看工程的堆栈使用情况
arm开发·stm32·单片机·arm
toradexsh1 个月前
ARM 处理器平台 eMMC Flash 存储磨损测试示例
linux·arm·nxp·toradex·emmc
CYRUS STUDIO1 个月前
使用 AndroidNativeEmu 调用 JNI 函数
android·汇编·arm开发·arm·逆向·jni
小虾米的Daddy2 个月前
ARM64 Trust Firmware [一]
linux·arm·安全架构
世事如云有卷舒2 个月前
《ARM64体系结构编程与实践》学习笔记(三)
笔记·学习·arm
亿道电子Emdoor2 个月前
【ARM】MDK烧录配置文件无权限访问
arm开发·stm32·单片机·arm