0702_ARM6

练习:
中断实验
main.c

#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

#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

#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

上一篇:「实战应用」如何用DHTMLX将上下文菜单集成到JavaScript甘特图中(二)


下一篇:tongweb+ths6011测试websocket(by lqw)