2022-2-23作业

一、通过操作Cortex-A7核,串口输入相应的命令,控制LED灯进行工作

1.例如在串口输入led1on,开饭led1灯点亮

2.例如在串口输入led1off,开饭led1灯熄灭

3.例如在串口输入led2on,开饭led2灯点亮

4.例如在串口输入led2off,开饭led2灯熄灭

5.例如在串口输入led3on,开饭led3灯点亮

6.例如在串口输入led3off,开饭led3灯熄灭

二、检测中断到来时,让LED灯状态取反,并且在串口工具上打印一句话

例如:当按键1按下之后,让LED1状态取反,并打印“LED1 down”

        当按键2按下之后,让LED2状态取反,并打印“LED2 down”

        当按键3按下之后,让LED3状态取反,并打印“LED3 down”

        火焰传感器/人体红外/光电开关实验要求如上 


作业一:

stm32mp1xx_rcc.h:

#ifndef __STM32MP1XX_RCC_H__
#define __STM32MP1XX_RCC_H__ 

typedef struct {
	volatile unsigned int TZCR;     	// 0x000
	volatile unsigned int res1[2]; 		// 0x004-0x008
	volatile unsigned int OCENSETR;     // 0x00C
	volatile unsigned int OCENCLRR;  	// 0x010
	volatile unsigned int res2[1]; 		// 0x014
	volatile unsigned int HSICFGR; 		// 0x018
	volatile unsigned int CSICFGR; 		// 0x01C
	volatile unsigned int MPCKSELR; 	// 0x020
	volatile unsigned int ASSCKSELR; 	// 0x024
	volatile unsigned int PCK12SELR; 	// 0x028
	volatile unsigned int MPCKDIVR; 	// 0x02C
	volatile unsigned int AXIDIVR; 		// 0x030
	volatile unsigned int res3[2];      
	volatile unsigned int APB4DIVR; 	// 0x03C
	volatile unsigned int APB5DIVR; 	// 0x040
	volatile unsigned int RTCDIVR; 		// 0x044
	volatile unsigned int MSSCKSELR;    // 0x048
	volatile unsigned int res4[13];
	volatile unsigned int PLL1CR; 		// 0x080
	volatile unsigned int PLL1CFGR1; 	// 0x084
	volatile unsigned int PLL1CFGR2; 	// 0x088
	volatile unsigned int PLL1FRACR; 	// 0x08C
	volatile unsigned int PLL1CSGR;     // 0x090
	volatile unsigned int PLL2CR; 		// 0x094
	volatile unsigned int PLL2CFGR1; 	// 0x098
	volatile unsigned int PLL2CFGR2; 	// 0x09C
	volatile unsigned int PLL2FRACR;    // 0x0A0
	volatile unsigned int PLL2CSGR;     // 0x0A4
	volatile unsigned int res5[6];
	volatile unsigned int I2C46CKSELR;  // 0x0C0
	volatile unsigned int SPI6CKSELR;   // 0x0C4
	volatile unsigned int UART1CKSELR;  // 0x0C8
	volatile unsigned int RNG1CKSELR;   // 0x0CC
	volatile unsigned int CPERCKSELR;   // 0x0D0
	volatile unsigned int STGENCKSELR;  // 0x0D4
	volatile unsigned int DDRITFCR; 	// 0x0D8
	volatile unsigned int res6[9];
	volatile unsigned int MP_BOOTCR;  	// 0x100
	volatile unsigned int MP_SREQSETR;  // 0x104
	volatile unsigned int MP_SREQCLRR;  // 0x108
	volatile unsigned int MP_GCR;  		// 0x10C
	volatile unsigned int MP_APRSTCR; 	// 0x110 
	volatile unsigned int MP_APRSTSR;   // 0x114
	volatile unsigned int res7[10];
	volatile unsigned int BDCR; 		// 0x140
	volatile unsigned int RDLSICR;  	// 0x144
	volatile unsigned int res8[14];
	volatile unsigned int APB4RSTSETR; 	// 0x180
	volatile unsigned int APB4RSTCLRR; 	// 0x184
	volatile unsigned int APB5RSTSETR;  // 0x188
	volatile unsigned int APB5RSTCLRR;  // 0x18C
	volatile unsigned int AHB5RSTSETR;  // 0x190
	volatile unsigned int AHB5RSTCLRR;  // 0x194
	volatile unsigned int AHB6RSTSETR;  // 0x198
	volatile unsigned int AHB6RSTCLRR;  // 0x19C
	volatile unsigned int TZAHB6RSTSELR;// 0x1A0
	volatile unsigned int TZAHB6RSTCLRR;// 0x1A4
	volatile unsigned int res9[22];
	volatile unsigned int MP_APB4ENSETR;// 0x200
	volatile unsigned int MP_APB4ENCLRR;// 0x204
	volatile unsigned int MP_APB5ENSETR;// 0x208
	volatile unsigned int MP_APB5ENCLRR;// 0x20C
	volatile unsigned int MP_AHB5ENSETR;// 0x210
	volatile unsigned int MP_AHB5ENCLRR;// 0x214
	volatile unsigned int MP_AHB6ENSETR;// 0x218
	volatile unsigned int MP_AHB6ENCLRR;// 0x21C
	volatile unsigned int MP_TZAHB6ENSELR;// 0x220
	volatile unsigned int MP_TZAHB6ENCLRR;// 0x224
	volatile unsigned int res10[22];
	volatile unsigned int MC_APB4ENSETR; // 0x280
	volatile unsigned int MC_APB4ENCLRR; // 0x284
	volatile unsigned int MC_APB5ENSETR; // 0x288
	volatile unsigned int MC_APB5ENCLRR; // 0x28C
	volatile unsigned int MC_AHB5ENSETR; // 0x290
	volatile unsigned int MC_AHB5ENCLRR; // 0x294
	volatile unsigned int MC_AHB6ENSETR; // 0x298
	volatile unsigned int MC_AHB6ENCLRR; // 0x29C
	volatile unsigned int res11[24];
	volatile unsigned int MP_APB4LPENSETR; // 0x300
	volatile unsigned int MP_APB4LPENCLRR; // 0x304
	volatile unsigned int MP_APB5LPENSETR; // 0x308
	volatile unsigned int MP_APB5LPENCLRR; // 0x30C
	volatile unsigned int MP_AHB5LPENSETR; // 0x310
	volatile unsigned int MP_AHB5LPENCLRR; // 0x314
	volatile unsigned int MP_AHB6LPENSETR; // 0x318
	volatile unsigned int MP_AHB6LPENCLRR; // 0x31C
	volatile unsigned int MP_TZAHB6LPENSETR; // 0x320
	volatile unsigned int MP_TZAHB6LPENCLRR; // 0x324
	volatile unsigned int res12[22];
	volatile unsigned int MC_APB4LPENSETR; // 0x380
	volatile unsigned int MC_APB4LPENCLRR; // 0x384
	volatile unsigned int MC_APB5LPENSETR; // 0x388
	volatile unsigned int MC_APB5LPENCLRR; // 0x38C
	volatile unsigned int MC_AHB5LPENSETR; // 0x390
	volatile unsigned int MC_AHB5LPENCLRR; // 0x394
	volatile unsigned int MC_AHB6LPENSETR; // 0x398
	volatile unsigned int MC_AHB6LPENCLRR; // 0x39C
	volatile unsigned int res13[24];
	volatile unsigned int BR_RSTSCLRR; 		// 0x400
	volatile unsigned int MP_GRSTCSETR; 	// 0x404
	volatile unsigned int MP_RSTSR; 		// 0x408 
	volatile unsigned int MP_IWDGFZSETR; 	// 0x40C
	volatile unsigned int MP_IWDGFZCLRR;  	// 0x410
	volatile unsigned int MP_CIER; 			// 0x414
	volatile unsigned int MP_CIFR; 			// 0x418
	volatile unsigned int PWRLPDLYCR; 		// 0x41C
	volatile unsigned int MP_RSTSS; 		// 0x420
	volatile unsigned int res14[247];
	volatile unsigned int MCO1CFGR; 		// 0x800
	volatile unsigned int MCO2CFGR; 		// 0x804 
	volatile unsigned int OCRDYR; 			// 0x808
	volatile unsigned int DBGCFGR; 			// 0x80C
	volatile unsigned int res15[4];
	volatile unsigned int RCK3SELR; 		// 0x820
	volatile unsigned int RCK4SELR; 		// 0x824
	volatile unsigned int TIMG1PRER;  		// 0x828
	volatile unsigned int TIMG2PRER; 		// 0x82C
	volatile unsigned int MCUDIVR; 			// 0x830
	volatile unsigned int APB1DIVR; 		// 0x834
	volatile unsigned int APB2DIVR; 		// 0x838
	volatile unsigned int APB3DIVR; 		// 0x83C
	volatile unsigned int res16[16];
	volatile unsigned int PLL3CR;   		// 0x880
	volatile unsigned int PLL3CFGR1; 		// 0x884
	volatile unsigned int PLL3CFGR2; 		// 0x888
	volatile unsigned int PLL3FRACR; 		// 0x88C
	volatile unsigned int PLL3CSGR; 		// 0x890
	volatile unsigned int PLL4CR; 			// 0x894
	volatile unsigned int PLL4CFGR1; 		// 0x898
	volatile unsigned int PLL4CFGR2; 		// 0x89C
	volatile unsigned int PLL4FRACR; 		// 0x8A0
	volatile unsigned int PLL4CSGR; 		// 0x8A4
	volatile unsigned int res17[6];
	volatile unsigned int I2C12CKSELR; 		// 0x8C0
	volatile unsigned int I2C35CKSELR;  	// 0x8C4
	volatile unsigned int SAI1CKSELR; 		// 0x8C8
	volatile unsigned int SAI2CKSELR; 		// 0x8CC
	volatile unsigned int SAI3CKSELR; 		// 0x8D0
	volatile unsigned int SAI4CKSELR; 		// 0x8D4
	volatile unsigned int SPI2S1CKSELR; 	// 0x8D8
	volatile unsigned int SPI2S23CKSELR; 	// 0x8DC
	volatile unsigned int SPI45CKSELR; 		// 0x8E0
	volatile unsigned int UART6CKSELR; 		// 0x8E4
	volatile unsigned int UART24CKSELR; 	// 0x8E8
	volatile unsigned int UART35CKSELR; 	// 0x8EC
	volatile unsigned int UART78CKSELR; 	// 0x8F0
	volatile unsigned int SDMMC12CKSELR; 	// 0x8F4
	volatile unsigned int SDMMC3CKSELR; 	// 0x8F8
	volatile unsigned int ETHCKSELR; 		// 0x8FC
	volatile unsigned int QSPICKSELR; 		// 0x900
	volatile unsigned int FMCCKSELR; 		// 0x904
	volatile unsigned int res18[1];
	volatile unsigned int FDCANCKSELR; 		// 0x90C
	volatile unsigned int res19[1];
	volatile unsigned int SPDIFCKSELR; 		// 0x914
	volatile unsigned int CECCKSELR; 		// 0x918
	volatile unsigned int USBCKSELR; 		// 0x91C
	volatile unsigned int RNG2CKSELR;  		// 0x920
	volatile unsigned int DSICKSELR; 		// 0x924
	volatile unsigned int ADCCKSELR; 		// 0x928
	volatile unsigned int LPTIM45CKSELR; 	// 0x92C
	volatile unsigned int LPTIM23CKSELR;    // 0x930
	volatile unsigned int LPTIM1CKSELR; 	// 0x934
	volatile unsigned int res20[18];
	volatile unsigned int APB1RSTSETR; 		// 0x980
	volatile unsigned int APB1RSTCLRR; 		// 0x984
	volatile unsigned int APB2RSTSETR; 		// 0x988
	volatile unsigned int APB2RSTCLRR; 		// 0x98C
	volatile unsigned int APB3RSTSETR; 		// 0x990
	volatile unsigned int APB3RSTCLRR; 		// 0x994
	volatile unsigned int AHB2RSTSETR; 		// 0x998
	volatile unsigned int AHB2RSTCLRR;  	// 0x99C
	volatile unsigned int AHB3RSTSETR; 		// 0x9A0
	volatile unsigned int AHB3RSTCLRR; 		// 0x9A4
	volatile unsigned int AHB4RSTSETR; 		// 0x9A8
	volatile unsigned int AHB4RSTCLRR; 		// 0x9AC
	volatile unsigned int res21[20];
	volatile unsigned int MP_APB1ENSETR; 	// 0xA00
	volatile unsigned int MP_APB1ENCLRR; 	// 0xA04
	volatile unsigned int MP_APB2ENSETR; 	// 0xA08
	volatile unsigned int MP_APB2ENCLRR;  	// 0xA0C
	volatile unsigned int MP_APB3ENSETR; 	// 0xA10
	volatile unsigned int MP_APB3ENCLRR; 	// 0xA14
	volatile unsigned int MP_AHB2ENSETR; 	// 0xA18
	volatile unsigned int MP_AHB2ENCLRR; 	// 0xA1C
	volatile unsigned int MP_AHB3ENSETR; 	// 0xA20
	volatile unsigned int MP_AHB3ENCLRR; 	// 0xA24
	volatile unsigned int MP_AHB4ENSETR; 	// 0xA28
	volatile unsigned int MP_AHB4ENCLRR; 	// 0xA2C
	volatile unsigned int res22[2];
	volatile unsigned int MP_MLAHBENSETR; 	// 0xA38
	volatile unsigned int MP_MLAHBENCLRR; 	// 0xA3C
	volatile unsigned int res23[16];
	volatile unsigned int MC_APB1ENSETR; 	// 0xA80
	volatile unsigned int MC_APB1ENCLRR; 	// 0xA84
	volatile unsigned int MC_APB2ENSETR; 	// 0xA88
	volatile unsigned int MC_APB2ENCLRR; 	// 0xA8C
	volatile unsigned int MC_APB3ENSETR; 	// 0xA90
	volatile unsigned int MC_APB3ENCLRR; 	// 0xA94
	volatile unsigned int MC_AHB2ENSETR; 	// 0xA98
	volatile unsigned int MC_AHB2ENCLRR; 	// 0xA9C
	volatile unsigned int MC_AHB3ENSETR; 	// 0xAA0
	volatile unsigned int MC_AHB3ENCLRR; 	// 0xAA4
	volatile unsigned int MC_AHB4ENSETR; 	// 0xAA8
	volatile unsigned int MC_AHB4ENCLRR; 	// 0xAAC
	volatile unsigned int MC_AXIMENSETR; 	// 0xAB0
	volatile unsigned int MC_AXIMENCLRR; 	// 0xAB4
	volatile unsigned int MC_MLAHBENSETR; 	// 0xAB8
	volatile unsigned int MC_MLAHBENCLRR; 	// 0xABC
	volatile unsigned int res24[16];
	volatile unsigned int MP_APB1LPENSETR; 	// 0xB00
	volatile unsigned int MP_APB1LPENCLRR; 	// 0xB04
	volatile unsigned int MP_APB2LPENSETR;  // 0xB08
	volatile unsigned int MP_APB2LPENCLRR; 	// 0xB0C
	volatile unsigned int MP_APB3LPENSETR; 	// 0xB10
	volatile unsigned int MP_APB3LPENCLRR;  // 0xB14
	volatile unsigned int MP_AHB2LPENSETR;  // 0xB18
	volatile unsigned int MP_AHB2LPENCLRR;  // 0xB1C
	volatile unsigned int MP_AHB3LPENSETR;  // 0xB20
	volatile unsigned int MP_AHB3LPENCLRR;  // 0xB24
	volatile unsigned int MP_AHB4LPENSETR;  // 0xB28
	volatile unsigned int MP_AHB4LPENCLRR;  // 0xB2C
	volatile unsigned int MP_AXIMLPENSETR;  // 0xB30
	volatile unsigned int MP_AXIMLPENCLRR;  // 0xB34
	volatile unsigned int MP_MLAHBLPENSETR; // 0xB38
	volatile unsigned int MP_MLAHBLPENCLRR; // 0xB3C
	volatile unsigned int res25[16];
	volatile unsigned int MC_APB1LPENSETR;  // 0xB80
	volatile unsigned int MC_APB1LPENCLRR; 	// 0xB84
	volatile unsigned int MC_APB2LPENSETR;  // 0xB88
	volatile unsigned int MC_APB2LPENCLRR;  // 0xB8C
	volatile unsigned int MC_APB3LPENSETR;  // 0xB90 
	volatile unsigned int MC_APB3LPENCLRR;  // 0xB94
	volatile unsigned int MC_AHB2LPENSETR;  // 0xB98
	volatile unsigned int MC_AHB2LPENCLRR;  // 0xB9C
	volatile unsigned int MC_AHB3LPENSETR;  // 0xBA0 
	volatile unsigned int MC_AHB3LPENCLRR;  // 0xBA4
	volatile unsigned int MC_AHB4LPENSETR;  // 0xBA8
	volatile unsigned int MC_AHB4LPENCLRR;  // 0xBAC
	volatile unsigned int MC_AXIMLPENSETR;  // 0xBB0
	volatile unsigned int MC_AXIMLPENCLRR;  // 0xBB4
	volatile unsigned int MC_MLAHBLPENSETR; // 0xBB8
	volatile unsigned int MC_MLAHBLPENCLRR; // 0xBBC
	volatile unsigned int res26[16];
	volatile unsigned int MC_RSTSCLRR;  	// 0xC00
	volatile unsigned int res27[4];
	volatile unsigned int MC_CIER;  		// 0xC14
	volatile unsigned int MC_CIFR; 			// 0xC18
	volatile unsigned int res28[246];
	volatile unsigned int VERR; 			// 0xFF4
	volatile unsigned int IDR; 				// 0xFF8
	volatile unsigned int SIDR; 			// 0xFFC
}rcc_t;

#define RCC   ((rcc_t *)0x50000000)

#endif  // __STM32MP1XX_RCC_H__

stm32mp1xx_gpio.h:

#ifndef __STM32MP1xx_GPIO_H__
#define __STM32MP1xx_GPIO_H__

typedef struct {
	volatile unsigned int MODER;   // 0x00
	volatile unsigned int OTYPER;  // 0x04
	volatile unsigned int OSPEEDR; // 0x08
	volatile unsigned int PUPDR;   // 0x0C
	volatile unsigned int IDR;     // 0x10
	volatile unsigned int ODR;     // 0x14
	volatile unsigned int BSRR;    // 0x18
	volatile unsigned int LCKR;    // 0x1C 
	volatile unsigned int AFRL;    // 0x20 
	volatile unsigned int AFRH;    // 0x24
	volatile unsigned int BRR;     // 0x28
	volatile unsigned int res;
	volatile unsigned int SECCFGR; // 0x30

}gpio_t;

#define  GPIOA   ((gpio_t *)0x50002000)
#define  GPIOB   ((gpio_t *)0x50003000)
#define  GPIOC   ((gpio_t *)0x50004000)
#define  GPIOD   ((gpio_t *)0x50005000)
#define  GPIOE   ((gpio_t *)0x50006000)
#define  GPIOF   ((gpio_t *)0x50007000)
#define  GPIOG   ((gpio_t *)0x50008000)
#define  GPIOH   ((gpio_t *)0x50009000)
#define  GPIOI   ((gpio_t *)0x5000A000)
#define  GPIOJ   ((gpio_t *)0x5000B000)
#define  GPIOK   ((gpio_t *)0x5000C000)
#define  GPIOZ   ((gpio_t *)0x54004000)

//对引脚进行封装      
#define GPIO_PIN_0 0  
#define GPIO_PIN_1 1  
#define GPIO_PIN_2 2  
#define GPIO_PIN_3 3  
#define GPIO_PIN_4 4  
#define GPIO_PIN_5 5  
#define GPIO_PIN_6 6  
#define GPIO_PIN_7 7  
#define GPIO_PIN_8 8  
#define GPIO_PIN_9 9  
#define GPIO_PIN_10 10
#define GPIO_PIN_11 11
#define GPIO_PIN_12 12
#define GPIO_PIN_13 13
#define GPIO_PIN_14 14
#define GPIO_PIN_15 15

//寄存器输出模式           
typedef enum{              
    Input,                 
    Output,                
    Alternate,        
    Analog,                
}gpio_moder_t;             
                           
//寄存器输出类型           
typedef enum{              
    Push_pull,             
    Open_drain,            
}gpio_otyper_t;            
                           
//寄存器输出速度           
typedef enum{              
    Low_speed,             
    Medium_speed,          
    High_speed,            
    Very_high_speed,       
}gpio_ospeedr_t;           
                           
//寄存器是否需要上下拉     
typedef enum{              
    No_up_down,            
    Pull_up,               
    Pull_down,             
    Reserved,              
}gpio_pupdr_t;             
                           
//对GPIO引脚状态封装       
typedef enum{              
    gpio_reset_t,          
    gpio_set_t,            
}gpio_status_t;            
                           
//对GPIO进行初始化         
typedef struct{            
    gpio_moder_t moder;    
    gpio_otyper_t otyper;  
    gpio_ospeedr_t ospeedr;
    gpio_pupdr_t pupdr;    
}gpio_init_t;              

#endif // __STM32MP1xx_GPIO_H__

stm32mp1xx_uart.h:

#ifndef __STM32MP1XX_UART_H__
#define __STM32MP1XX_UART_H__

typedef struct {
	volatile unsigned int CR1;
	volatile unsigned int CR2;
	volatile unsigned int CR3;
	volatile unsigned int BRR;
	volatile unsigned int GTPR;
	volatile unsigned int RTOR;
	volatile unsigned int RQR;
	volatile unsigned int ISR;
	volatile unsigned int ICR;
	volatile unsigned int RDR;
	volatile unsigned int TDR;
	volatile unsigned int PRESC;
}uart_t;

#define USART1  ((uart_t *)0x5C000000)
#define USART2  ((uart_t *)0x4000E000)
#define USART3  ((uart_t *)0x4000F000)
#define USART4  ((uart_t *)0x40010000)
#define USART5  ((uart_t *)0x40011000)
#define USART6  ((uart_t *)0x44003000)
#define USART7  ((uart_t *)0x40018000)
#define USART8  ((uart_t *)0x40019000)

#endif // __STM32MP1XX_UART_H__

stm32mp1xx_exti.h:

#ifndef __STM32MP1XX_EXTI_H__
#define __STM32MP1XX_EXTI_H__

typedef struct{
	volatile unsigned int RTSR1; 	// EXTI rising trigger selection register 	
	volatile unsigned int FTSR1; 	// EXTI falling trigger selection register	
	volatile unsigned int SWIER1;   // EXTI software interrupt event register 
	volatile unsigned int RPR1;     // EXTI rising edge pending register
	volatile unsigned int FPR1;  	// EXTI falling edge pending register
	volatile unsigned int TZENR1;   // EXTI TrustZone enable register
	volatile unsigned int RES1[2];  
	volatile unsigned int RTSR2;    // EXTI rising trigger selection register
	volatile unsigned int FTSR2;    // EXTI falling trigger selection register
	volatile unsigned int SWIER2;   // EXTI software interrupt event register
	volatile unsigned int RPR2;     // EXTI rising edge pending register
	volatile unsigned int FPR2;	    // EXTI falling edge pending register
	volatile unsigned int TZENR2;   // EXTI TrustZone enable register
	volatile unsigned int RES2[2];
	volatile unsigned int RTSR3;    // EXTI rising trigger selection register
	volatile unsigned int FTSR3;    // EXTI falling trigger selection register
	volatile unsigned int SWIER3;   // EXTI software interrupt event register
	volatile unsigned int RPR3;     // EXTI rising edge pending register
	volatile unsigned int FPR3;     // EXTI falling edge pending register
	volatile unsigned int TZENR3;   // EXTI TrustZone enable register
	volatile unsigned int RES3[2];
	volatile unsigned int EXTICR1;	// EXTI external interrupt selection register 1
	volatile unsigned int EXTICR2;  // EXTI external interrupt selection register 2	
	volatile unsigned int EXTICR3;  // EXTI external interrupt selection register 3	
	volatile unsigned int EXTICR4;  // EXTI external interrupt selection register 4	
	volatile unsigned int RES4[4];
	volatile unsigned int C1IMR1;   // EXTI CPU1 wakeup with interrupt mask register
	volatile unsigned int C1EMR1;   // EXTI CPU1 wakeup with event mask register
	volatile unsigned int RES5[2];
	volatile unsigned int C1IMR2;   // EXTI CPU1 wakeup with interrupt mask register
	volatile unsigned int C1EMR2;   // EXTI CPU1 wakeup with event mask register
	volatile unsigned int RES6[2];
	volatile unsigned int C1IMR3;   // EXTI CPU1 wakeup with interrupt mask register	
	volatile unsigned int C1EMR3;   // EXTI CPU1 wakeup with event mask register 
	volatile unsigned int RES7[6];
	volatile unsigned int C2IMR1;   // EXTI CPU2 wakeup with interrupt mask register
	volatile unsigned int C2EMR1;   // EXTI CPU2 wakeup with event mask register
	volatile unsigned int RES8[2];
	volatile unsigned int C2IMR2;   // EXTI CPU2 wakeup with interrupt mask register
	volatile unsigned int C2EMR2;   // EXTI CPU2 wakeup with event mask register
	volatile unsigned int RES9[2];
	volatile unsigned int C2IMR3;   // EXTI CPU2 wakeup with interrupt mask register 
	volatile unsigned int C2EMR3;   // EXTI CPU2 wakeup with event mask register 
	volatile unsigned int RES10[2];
}exti_t;

#define  EXTI   ((exti_t*)0x5000D000)

#endif //__STM32MP1XX_EXTI_H__

stm32mp1xx_gic.h:

#ifndef __STM32MP1XX_GIC_H__
#define __STM32MP1XX_GIC_H__ 


typedef struct {
	volatile unsigned int CTRL;
	volatile unsigned int TYPER;
	volatile unsigned int IIDR;
	volatile unsigned int RES1[29];
	volatile unsigned int IGROUPR[9];
	volatile unsigned int RES2[23];
	volatile unsigned int ISENABLER[9];
	volatile unsigned int RES3[23];
	volatile unsigned int ICENABLER[9];
	volatile unsigned int RES4[23];
	volatile unsigned int ISPENDR[9];
	volatile unsigned int RES5[23];
	volatile unsigned int ICPENDR[9];
	volatile unsigned int RES6[23];
	volatile unsigned int ISACTIVER[9];
	volatile unsigned int RES7[23];
	volatile unsigned int ICACTIVER[9];
	volatile unsigned int RES8[23];
	volatile unsigned int IPRIORITYR[72];
	volatile unsigned int RES9[184];
	volatile unsigned int ITARGETSR[72];
	volatile unsigned int RES10[184];	
	volatile unsigned int ICFGR[18];
	volatile unsigned int RES11[46];

}gicd_t;
#define GICD  ((gicd_t*)0xA0021000)


typedef struct {
	volatile unsigned int CTRL;
	volatile unsigned int PMR;
	volatile unsigned int BRR;
	volatile unsigned int IAR;
	volatile unsigned int EOIR;
	volatile unsigned int RPR;
	volatile unsigned int HPPIR;
	volatile unsigned int ABPR;
	volatile unsigned int AIAR;
	volatile unsigned int AEOIR;
	volatile unsigned int AHPPIR;
	volatile unsigned int RES1[41];
	volatile unsigned int APR0;
	volatile unsigned int RES2[3];
	volatile unsigned int NSAPR0;
	volatile unsigned int RES3[6];
	volatile unsigned int IIDR;
	volatile unsigned int RES4[960];
	volatile unsigned int DIRDIR;

}gicc_t;
#define GICC  ((gicc_t*)0xA0022000) 

#endif  // __STM32MP1XX_GIC_H__

uart_led.h:

#ifndef __UART_LED_H__
#define __UART_LED_H__

#include "stm32mp1xx_rcc.h"
#include "stm32mp1xx_gpio.h"
#include "stm32mp1xx_uart.h"
#include "stm32mp1xx_exti.h"
#include "stm32mp1xx_gic.h"

//重写strcmp函数
int strcmp(const char *s1, const char *s2);

//对LED灯初始化
void hal_led_init();

//对GPIO引脚初始化函数
void hal_gpio_init(gpio_t* gpiox, gpio_init_t* init, unsigned int pin);

//对GPIO引脚写操作函数
void hal_led_gpio_write(gpio_t* gpiox, unsigned int pin, gpio_status_t state);

//初始化串口
void hal_uart_init();

//发送一个字节
void uart_put_char(const char str);
 
//发送一个字符串
void uart_put_string(const char* str);
 
//接受一个字符
char uart_get_char();
 
//接收一个字符串
char* uart_get_string();

#endif

uart_led.c:

#include "uart_led.h"

extern void printf(const char *fmt, ...);
extern void delay_ms(int ms);

//重写strcmp函数
int strcmp(const char *s1, const char *s2)
{
	int t = 0;
	while(*s1 || *s2)
	{
		if(*s1 != *s2)
		{
			t = *s1 - *s2;
			return t;
		}
		*s1 ++;
		*s2 ++;
	}
	return t;
}

//对LED灯初始化
void hal_led_init()
{
	//RCC时钟初始化
	RCC->MP_AHB4ENSETR |= (0x3 << 4);

	//结构体初始化
	gpio_init_t init = {Output, Push_pull, Low_speed, No_up_down};

	//GPIO初始化
	hal_gpio_init(GPIOE, &init, GPIO_PIN_10);
	hal_gpio_init(GPIOF, &init, GPIO_PIN_10);
	hal_gpio_init(GPIOE, &init, GPIO_PIN_8);
}

//对GPIO引脚初始化函数
void hal_gpio_init(gpio_t* gpiox, gpio_init_t* init, unsigned int pin)
{
	//GPIO输出模式初始化
	gpiox->MODER &= (~(0x3 << (pin * 2)));
	gpiox->MODER |= (init->moder << (pin * 2));

	//GPIO输出类型初始化
	gpiox->OTYPER &= (~(0x1 << pin));
	gpiox->OTYPER |= (init->otyper << pin);

	//GPIO输出速度初始化
	gpiox->OSPEEDR &= (~(0x3 << (pin * 2)));
	gpiox->OSPEEDR |= (init->ospeedr << (pin * 2));

	//GPIO是否需要上下拉
	gpiox->PUPDR &= (~(0x3 << (pin * 2)));
	gpiox->PUPDR |= (init->pupdr << (pin * 2));
}

//对GPIO引脚写操作函数
void hal_led_gpio_write(gpio_t* gpiox, unsigned int pin, gpio_status_t state)
{
	if(gpio_reset_t == state)
		gpiox->ODR &= (~(0x1 << pin));
	else
		gpiox->ODR |= (0x1 << pin);
}

//初始化串口
void hal_uart_init()
{
	/*********RCC章节初始化********/
	RCC->MP_AHB4ENSETR |= (0x1 << 1);
	RCC->MP_AHB4ENSETR |= (0x1 << 6);
	RCC->MP_APB1ENSETR |= (0x1 << 16);
	/*********GPIO章节初始化*******/
	gpio_init_t init = {0};
	init.moder = Alternate; 	//设置GPIO模式为复用模式
	hal_gpio_init(GPIOB, &init, GPIO_PIN_2);
	hal_gpio_init(GPIOG, &init, GPIO_PIN_11);

	GPIOB->MODER |= (0x1 << 5);
	GPIOB->AFRL &= (~(0xF << 8));
	GPIOB->AFRL |= (0x1 << 11);
	GPIOG->MODER |= (0x1 << 23);
	GPIOG->AFRH &= (~(0xF << 12));
	GPIOG->AFRH |= (0x3 << 13);
	/*********UART章节初始化*******/
	if(USART4->CR1 & (0x1 << 0))    //判断UE位是否为0    
	{                                                    
		delay_ms(500);                                   
		USART4->CR1 &= (~(0x1 << 0));                    
	}                                                    
	USART4->CR1 &= (~(0x1 << 28));  //设置数据位宽度为8位
	USART4->CR1 &= (~(0x1 << 12));                       
	USART4->CR1 &= (~(0x1 << 15));  //设置串口采样率     
	USART4->CR1 &= (~(0x1 << 10));  //设置无奇偶校验位   
	USART4->CR2 &= (~(0x3 << 12));  //设置串口1位停止位  
	USART4->PRESC &= (~(0x3 << 3)); //设置串口不分频     
	USART4->BRR |= 0x22B;           //设置串口波特率     
	USART4->CR1 |= (0x1 << 2);      //串口发送器使能     
	USART4->CR1 |= (0x1 << 3);      //串口接收器使能     
	USART4->CR1 |= (0x1 << 0);          //串口使能       
}

//发送一个字节
void uart_put_char(const char str)
{
	//1.判断发送数据寄存器是否为空,为空才可以发送下一个字节
	//ISR[7]  
	//读0:发送数据寄存器满,需要等待
	//读1:发送数据寄存器空,才可以发送下一个字节数据
	while(!(USART4->ISR & (0x1 << 7)));
 
	//2.将要发送的字符写到发送数据寄存器中
	USART4->TDR = str;
 
	//3.判断发送数据是否完成 ISR[6]
	while(!(USART4->ISR & (0x1 << 6)));
}
 
//发送一个字符串
void uart_put_string(const char* str)
{
	//判断是否为'\0',一个字符一个字符发
	for(int i = 0; str[i] != '\0'; i++)
	{
		uart_put_char(str[i]);	
	}
	printf("\n");
}
 
//接受一个字符
char uart_get_char()
{
	char ch;
	//1.判断接收数据寄存器是否有数据可读 ISR[5]
	while(!(USART4->ISR & (0x1 << 5)));
 
	//2.将接收到的数据读出来
	ch = USART4->RDR;
 
	return ch;
}
 
char buff[50] = {0};
//接收一个字符串
char* uart_get_string()
{
	int i = 0;
 
	//for循环
	//当键盘的回车键'\r'按下之后,字符串输入完成
	for(i = 0; i < 48; i++)
	{
		buff[i] = uart_get_char();	
		if(buff[i] == '\r')
			break;
		uart_put_char(buff[i]);
	}
	
	//字符串补'\0'
	buff[i] = '\0';
	printf("\n");

	//对接收到的字符串进行判断
	if(strcmp(buff,"led1on") == 0)
	{
		hal_led_gpio_write(GPIOE, GPIO_PIN_10, gpio_set_t);
		return "LED1_ON success";
	}
	else if(strcmp(buff,"led1off") == 0)
	{
		hal_led_gpio_write(GPIOE, GPIO_PIN_10, gpio_reset_t);
		return "LED1_OFF success";
	}
	else if(strcmp(buff,"led2on") == 0)
	{
		hal_led_gpio_write(GPIOF, GPIO_PIN_10, gpio_set_t);
		return "LED2_ON success";
	}
	else if(strcmp(buff,"led2off") == 0)
	{
		hal_led_gpio_write(GPIOF, GPIO_PIN_10, gpio_reset_t);
		return "LED2_OFF success";
	}
	else if(strcmp(buff,"led3on") == 0)
	{
		hal_led_gpio_write(GPIOE, GPIO_PIN_8, gpio_set_t);
		return "LED3_ON success";
	}
	else if(strcmp(buff,"led3off") == 0)
	{
		hal_led_gpio_write(GPIOE, GPIO_PIN_8, gpio_reset_t);
		return "LED3_OFF success";
	}

	return "invalid instruction!";
}

 main.c:

#include "uart_led.h"

extern void printf(const char *fmt, ...);

void delay_ms(int ms)
{
	int i,j;
	for(i = 0; i < ms;i++)
		for (j = 0; j < 1800; j++);
}

int main()
{
	hal_led_init();     //LED灯初始化
	hal_uart_init(); 	//串口初始化
	while(1)
	{
		uart_put_string(uart_get_string());
	}
	return 0;
}

测试结果如下: 


作业二:

 实验现象如下:

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:/a/159.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

100天精通Python(可视化篇)——第77天:数据可视化入门基础大全(万字总结+含常用图表动图展示)

文章目录1. 什么是数据可视化&#xff1f;2. 为什么会用数据可视化&#xff1f;3. 数据可视化的好处&#xff1f;4. 如何使用数据可视化&#xff1f;5. Python数据可视化常用工具1&#xff09;Matplotlib绘图2&#xff09;Seaborn绘图3&#xff09;Bokeh绘图6. 常用图表介绍及其…

为什么很多计算机专业大学生毕业后还会参加培训?

基于IT互联网行业越来越卷的现状&#xff0c;就算是科班出身&#xff0c;很多也是达不到用人单位的要求。面对这样的现实情况&#xff0c;有的同学会选择继续深造&#xff0c;比如考个研&#xff0c;去年考研人数457万人次&#xff0c;可见越来越的同学是倾向考研提升学历来达到…

GH3018超低功耗、超高精度的心率传感器

GH3018是一款超低功耗、超高精度的心率传感器&#xff0c;集成了3路LED驱动器、一个光学接收器&#xff08;PD&#xff09;及模拟前端&#xff08;AFE&#xff09;&#xff0c;支持心率&#xff08;HR&#xff09;、心率变异性&#xff08;HRV&#xff09;、血氧饱和度&#xf…

Springboot——自定义Filter使用测试总结

文章目录前言自定义过滤器并验证关于排除某些请求的方式创建测试接口请求测试验证异常过滤器的执行流程注意事项资料参考前言 在Java-web的开发领域&#xff0c;对于过滤器和拦截器用处还是很多&#xff0c;但两者的概念却极易混淆。 过滤器和拦截器都是采用AOP的核心思想&am…

HTML 扫盲

✏️作者&#xff1a;银河罐头 &#x1f4cb;系列专栏&#xff1a;JavaEE &#x1f332;“种一棵树最好的时间是十年前&#xff0c;其次是现在” 目录前言HTML 结构快速生成代码框架HTML 常见标签注释标签标题标签: h1-h6段落标签&#xff1a;p换行标签&#xff1a;br格式化标签…

PTA第六章作业详解

&#x1f680;write in front&#x1f680; &#x1f4dd;个人主页&#xff1a;认真写博客的夏目浅石. &#x1f381;欢迎各位→点赞&#x1f44d; 收藏⭐️ 留言&#x1f4dd; &#x1f4e3;系列专栏&#xff1a;夏目的作业 &#x1f4ac;总结&#xff1a;希望你看完之后&am…

JAVA进阶 —— Stream流

目录 一、 引言 二、 Stream流概述 三、Stream流的使用步骤 1. 获取Stream流 1.1 单列集合 1.2 双列集合 1.3 数组 1.4 零散数据 2. Stream流的中间方法 3. Stream流的终结方法 四、 练习 1. 数据过滤 2. 数据操作 - 按年龄筛选 3. 数据操作 - 演员信息要求…

蓝桥杯第十四届蓝桥杯模拟赛第三期考场应对攻略(C/C++)

这里把我的想法和思路写出来&#xff0c;恳请批评指正&#xff01; 目录 考前准备 试题1&#xff1a; 试题2&#xff1a; 试题3&#xff1a; 试题4&#xff1a; 试题5&#xff1a; 试题6&#xff1a; 试题7&#xff1a; 试题8&#xff1a; 试题9&#xff1a; 试题1…

第十六章 Java为什么使用序列化

为何要指定serialVersionUID的值如果不指定显示serialVersionUID的值&#xff0c;jvm在序列化时会自动生成一个serialVersionUID&#xff0c;跟属性一起序列化&#xff0c;再进行持久化或者网络传输&#xff0c;在反序列化时&#xff0c;jvm会根据属性自动生成一个新版的serial…

【Jetpack】Lifecycle 架构组件 ( 系统组件与普通组件解耦 | Lifecycle 解耦系统组件与普通组件 | 解耦服务组件与普通组件 | 监听应用程序生命周期 )

文章目录一、系统组件与普通组件解耦二、Lifecycle 解耦 Activity 系统组件与 UI 组件1、传统实现方式① Activity 系统组件② 布局文件③ 执行效果2、LifeCycle 实现方式① 自定义 UI 组件② Activity 系统组件③ 布局组件④ 执行效果三、LifecycleService 解耦 Service 与 UI…

为什么北欧的顶级程序员数量远超中国?

说起北欧&#xff0c;很多人会想到寒冷的冬天&#xff0c;漫长的极夜&#xff0c;童话王国和圣诞老人&#xff0c;但是如果我罗列下诞生于北欧的计算机技术&#xff0c;恐怕你会惊掉下巴。Linux&#xff1a;世界上最流行的开源操作系统&#xff0c;最早的内核由Linus Torvalds开…

2022济南大学acm新生赛题解

通过答题情况的难度系数&#xff1a; 签到&#xff1a;ABL 简单&#xff1a;DGKQ 中等&#xff1a;CMN 困难&#xff1a;EFHIJOPRST A-和 算出n个数的和判断正负性即可&#xff01;&#xff01;&#xff01; 发现很多同学的代码错误&#xff1a;要么sum未赋初值&#xf…

DDOS攻击

注&#xff1a;本博客只是为了自己的学习&#xff0c;记录自己的学习&#xff0c;请勿用于其他途径、1、winR-->cmd2、ping 网站3、替换IP1 import java.io.BufferedInputStream;2 import java.io.IOException;3 import java.net.MalformedURLException;4 import java.net.U…

Vue3做出B站【bilibili】 Vue3+TypeScript+ant-design-vue【快速入门一篇文章精通系列(一)前端项目案例】

本项目分为二部分 1、后台管理系统&#xff08;用户管理&#xff0c;角色管理&#xff0c;视频管理等&#xff09; 2、客户端&#xff08;登录注册、发布视频&#xff09; Vue3做出B站【bilibili】 Vue3TypeScriptant-design-vue【快速入门一篇文章精通系列&#xff08;一&…

【C++】STL简介 及 string的使用

文章目录1. STL简介1.1 什么是STL1.2 STL的版本1.3 STL的六大组件2. string类的使用2.1 C语言中的字符串2.2 标准库中的string类2.3 string类的常用接口说明1. string类对象的常见构造2. string类对象的容量操作3. string类对象的修改操作4. resize和reserve5. 认识迭代器&…

产品研发项目进度管理软件工具有哪些推荐?整理10款最佳进度管理软件

项目进度管理是确保项目按时完成的关键过程&#xff0c;使用合适的项目进度管理工具能确保帮助项目管理者实时了解和控制项目的进展情况&#xff0c;及时发现和解决问题&#xff0c;减少项目风险&#xff0c;提高项目效率和管理水平。这里将整理出国内外最受欢迎的10款项目进度…

ASEMI低压MOS管SI2301参数,SI2301体积,SI2301尺寸

编辑-Z ASEMI低压MOS管SI2301参数&#xff1a; 型号&#xff1a;SI2301 漏极-源极电压&#xff08;VDS&#xff09;&#xff1a;20V 栅源电压&#xff08;VGS&#xff09;&#xff1a;8V 漏极电流&#xff08;ID&#xff09;&#xff1a;2.3A 功耗&#xff08;PD&#xf…

Simulink壁咚(一)——What and How

目录 一、前言 二、Simulink 知多少 三、滤波算法 四、Model Verification 五、Model Coverage 六、Simulink测试实例 七、Simulink Test 八、Test Manager 九、Test Harness 十、 学习 一、前言 Simulink从2017b以后更加工程化和实用化&#xff0c;基于MBD的功能日趋…

MATLAB绘制ROC曲线

ROC曲线(Receiver Operating Characteristic Curve) 1 简介 ROC曲线是用于评估二元分类模型&#xff08;如Logistic回归&#xff09;表现优劣的一种工具&#xff0c;其横轴表示假阳性率&#xff08;false positive rate&#xff0c;FPR&#xff09;&#xff0c;即实际为负例但…

MySQL事务详解

&#x1f3c6;今日学习目标&#xff1a; &#x1f340;Spring事务和MySQL事务详解 ✅创作者&#xff1a;林在闪闪发光 ⏰预计时间&#xff1a;30分钟 &#x1f389;个人主页&#xff1a;林在闪闪发光的个人主页 &#x1f341;林在闪闪发光的个人社区&#xff0c;欢迎你的加入: …