10.4作业(补交)

4.中断实验(A7核/M4核)

.h

#ifndef __KEY_H__
#define __KEY_H__
#include "stm32mp1xx_rcc.h"
#include "stm32mp1xx_gpio.h"
#include "stm32mp1xx_exti.h"
#include "stm32mp1xx_gic.h"
/*****KEY1---->PF9**********/
//初始化EXTI层
void pf9_exti_init();
//初始化GICD层
void pf9_gicd_init();
//初始化GICC层
void pf9_gicc_init();
 
 
 
 
#endif

 .c

#include "key.h"
 
/*****KEY1---->PF9**********/
//初始化EXTI层
void pf9_exti_init()
{
/*****RCC章节初始化******/
//1.设置GPIOF组时钟使能 MP_AHB4ENSETR[5] = 1
    RCC->MP_AHB4ENSETR |= 0x1<<5;
 
/*****GPIO章节初始化******/
//1.设置PF9引脚为输入模式 MODER[19:18] = 00
GPIOF->MODER &=(~(0x3<<18));
 
/*****EXTI章节初始化******/
//1.设置PF9引脚和EXIT9控制器进行连接 EXTICR3[15:8] = 0x05
EXTI->EXTICR3 &=(~(0xff<<8));
EXTI->EXTICR3 |= (0x05<<8);
//2.设置PF9引脚检测方式下降沿 FTSR1[9] = 1
EXTI->FTSR1 |= 0x1<<9;
//3.设置PF9引脚中断不屏蔽 C1IMR1[9] = 1
    EXTI->C1IMR1 |= 0x1<<9;
}
 
//初始化GICD层
void pf9_gicd_init()
{
//1.设置GICD层全局中断使能寄存器 CTRL[0] = 1
GICD->CTRL |=0x1<<0;
//2.设置GICD层中断使能寄存器 ISENABLER[3] 第三位 1
GICD->ISENABLER[3] |= 0x1<<3;
//3.设置GICD层中断优先级寄存器IPRIORITYR[24] [31:27]
GICD->IPRIORITYR[24] &=(~(0x1f<<27));
//4.设置GICD层中断目标分配寄存器 ITARGETSR[24] [25:24] = 01
GICD->ITARGETSR[24] &=(~(0x3<<24));
GICD->ITARGETSR[24] |=0x1<<24;
}
 
//初始化GICC层
void pf9_gicc_init()
{
//1.设置GICC层全局中断使能寄存器 CTRL[0] = 1
     GICC->CTRL |=0x1<<0;
//2.设置GICC层中断优先级寄存器 PMR[7:3]
GICC->PMR &=(~(0x1f<<3));
GICC->PMR |=0x1f<<3;
}

M4

10.4作业(补交)_第1张图片

 10.4作业(补交)_第2张图片

10.4作业(补交)_第3张图片 

 现象
10.4作业(补交)_第4张图片

 

你可能感兴趣的:(单片机,stm32,嵌入式硬件)