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; // 0x000volatile unsigned int res1[2]; // 0x004-0x008volatile unsigned int OCENSETR; // 0x00Cvolatile unsigned int OCENCLRR; // 0x010volatile unsigned int res2[1]; // 0x014volatile unsigned int HSICFGR; // 0x018volatile unsigned int CSICFGR; // 0x01Cvolatile unsigned int MPCKSELR; // 0x020volatile unsigned int ASSCKSELR; // 0x024volatile unsigned int PCK12SELR; // 0x028volatile unsigned int MPCKDIVR; // 0x02Cvolatile unsigned int AXIDIVR; // 0x030volatile unsigned int res3[2]; volatile unsigned int APB4DIVR; // 0x03Cvolatile unsigned int APB5DIVR; // 0x040volatile unsigned int RTCDIVR; // 0x044volatile unsigned int MSSCKSELR; // 0x048volatile unsigned int res4[13];volatile unsigned int PLL1CR; // 0x080volatile unsigned int PLL1CFGR1; // 0x084volatile unsigned int PLL1CFGR2; // 0x088volatile unsigned int PLL1FRACR; // 0x08Cvolatile unsigned int PLL1CSGR; // 0x090volatile unsigned int PLL2CR; // 0x094volatile unsigned int PLL2CFGR1; // 0x098volatile unsigned int PLL2CFGR2; // 0x09Cvolatile unsigned int PLL2FRACR; // 0x0A0volatile unsigned int PLL2CSGR; // 0x0A4volatile unsigned int res5[6];volatile unsigned int I2C46CKSELR; // 0x0C0volatile unsigned int SPI6CKSELR; // 0x0C4volatile unsigned int UART1CKSELR; // 0x0C8volatile unsigned int RNG1CKSELR; // 0x0CCvolatile unsigned int CPERCKSELR; // 0x0D0volatile unsigned int STGENCKSELR; // 0x0D4volatile unsigned int DDRITFCR; // 0x0D8volatile unsigned int res6[9];volatile unsigned int MP_BOOTCR; // 0x100volatile unsigned int MP_SREQSETR; // 0x104volatile unsigned int MP_SREQCLRR; // 0x108volatile unsigned int MP_GCR; // 0x10Cvolatile unsigned int MP_APRSTCR; // 0x110 volatile unsigned int MP_APRSTSR; // 0x114volatile unsigned int res7[10];volatile unsigned int BDCR; // 0x140volatile unsigned int RDLSICR; // 0x144volatile unsigned int res8[14];volatile unsigned int APB4RSTSETR; // 0x180volatile unsigned int APB4RSTCLRR; // 0x184volatile unsigned int APB5RSTSETR; // 0x188volatile unsigned int APB5RSTCLRR; // 0x18Cvolatile unsigned int AHB5RSTSETR; // 0x190volatile unsigned int AHB5RSTCLRR; // 0x194volatile unsigned int AHB6RSTSETR; // 0x198volatile unsigned int AHB6RSTCLRR; // 0x19Cvolatile unsigned int TZAHB6RSTSELR;// 0x1A0volatile unsigned int TZAHB6RSTCLRR;// 0x1A4volatile unsigned int res9[22];volatile unsigned int MP_APB4ENSETR;// 0x200volatile unsigned int MP_APB4ENCLRR;// 0x204volatile unsigned int MP_APB5ENSETR;// 0x208volatile unsigned int MP_APB5ENCLRR;// 0x20Cvolatile unsigned int MP_AHB5ENSETR;// 0x210volatile unsigned int MP_AHB5ENCLRR;// 0x214volatile unsigned int MP_AHB6ENSETR;// 0x218volatile unsigned int MP_AHB6ENCLRR;// 0x21Cvolatile unsigned int MP_TZAHB6ENSELR;// 0x220volatile unsigned int MP_TZAHB6ENCLRR;// 0x224volatile unsigned int res10[22];volatile unsigned int MC_APB4ENSETR; // 0x280volatile unsigned int MC_APB4ENCLRR; // 0x284volatile unsigned int MC_APB5ENSETR; // 0x288volatile unsigned int MC_APB5ENCLRR; // 0x28Cvolatile unsigned int MC_AHB5ENSETR; // 0x290volatile unsigned int MC_AHB5ENCLRR; // 0x294volatile unsigned int MC_AHB6ENSETR; // 0x298volatile unsigned int MC_AHB6ENCLRR; // 0x29Cvolatile unsigned int res11[24];volatile unsigned int MP_APB4LPENSETR; // 0x300volatile unsigned int MP_APB4LPENCLRR; // 0x304volatile unsigned int MP_APB5LPENSETR; // 0x308volatile unsigned int MP_APB5LPENCLRR; // 0x30Cvolatile unsigned int MP_AHB5LPENSETR; // 0x310volatile unsigned int MP_AHB5LPENCLRR; // 0x314volatile unsigned int MP_AHB6LPENSETR; // 0x318volatile unsigned int MP_AHB6LPENCLRR; // 0x31Cvolatile unsigned int MP_TZAHB6LPENSETR; // 0x320volatile unsigned int MP_TZAHB6LPENCLRR; // 0x324volatile unsigned int res12[22];volatile unsigned int MC_APB4LPENSETR; // 0x380volatile unsigned int MC_APB4LPENCLRR; // 0x384volatile unsigned int MC_APB5LPENSETR; // 0x388volatile unsigned int MC_APB5LPENCLRR; // 0x38Cvolatile unsigned int MC_AHB5LPENSETR; // 0x390volatile unsigned int MC_AHB5LPENCLRR; // 0x394volatile unsigned int MC_AHB6LPENSETR; // 0x398volatile unsigned int MC_AHB6LPENCLRR; // 0x39Cvolatile unsigned int res13[24];volatile unsigned int BR_RSTSCLRR; // 0x400volatile unsigned int MP_GRSTCSETR; // 0x404volatile unsigned int MP_RSTSR; // 0x408 volatile unsigned int MP_IWDGFZSETR; // 0x40Cvolatile unsigned int MP_IWDGFZCLRR; // 0x410volatile unsigned int MP_CIER; // 0x414volatile unsigned int MP_CIFR; // 0x418volatile unsigned int PWRLPDLYCR; // 0x41Cvolatile unsigned int MP_RSTSS; // 0x420volatile unsigned int res14[247];volatile unsigned int MCO1CFGR; // 0x800volatile unsigned int MCO2CFGR; // 0x804 volatile unsigned int OCRDYR; // 0x808volatile unsigned int DBGCFGR; // 0x80Cvolatile unsigned int res15[4];volatile unsigned int RCK3SELR; // 0x820volatile unsigned int RCK4SELR; // 0x824volatile unsigned int TIMG1PRER; // 0x828volatile unsigned int TIMG2PRER; // 0x82Cvolatile unsigned int MCUDIVR; // 0x830volatile unsigned int APB1DIVR; // 0x834volatile unsigned int APB2DIVR; // 0x838volatile unsigned int APB3DIVR; // 0x83Cvolatile unsigned int res16[16];volatile unsigned int PLL3CR; // 0x880volatile unsigned int PLL3CFGR1; // 0x884volatile unsigned int PLL3CFGR2; // 0x888volatile unsigned int PLL3FRACR; // 0x88Cvolatile unsigned int PLL3CSGR; // 0x890volatile unsigned int PLL4CR; // 0x894volatile unsigned int PLL4CFGR1; // 0x898volatile unsigned int PLL4CFGR2; // 0x89Cvolatile unsigned int PLL4FRACR; // 0x8A0volatile unsigned int PLL4CSGR; // 0x8A4volatile unsigned int res17[6];volatile unsigned int I2C12CKSELR; // 0x8C0volatile unsigned int I2C35CKSELR; // 0x8C4volatile unsigned int SAI1CKSELR; // 0x8C8volatile unsigned int SAI2CKSELR; // 0x8CCvolatile unsigned int SAI3CKSELR; // 0x8D0volatile unsigned int SAI4CKSELR; // 0x8D4volatile unsigned int SPI2S1CKSELR; // 0x8D8volatile unsigned int SPI2S23CKSELR; // 0x8DCvolatile unsigned int SPI45CKSELR; // 0x8E0volatile unsigned int UART6CKSELR; // 0x8E4volatile unsigned int UART24CKSELR; // 0x8E8volatile unsigned int UART35CKSELR; // 0x8ECvolatile unsigned int UART78CKSELR; // 0x8F0volatile unsigned int SDMMC12CKSELR; // 0x8F4volatile unsigned int SDMMC3CKSELR; // 0x8F8volatile unsigned int ETHCKSELR; // 0x8FCvolatile unsigned int QSPICKSELR; // 0x900volatile unsigned int FMCCKSELR; // 0x904volatile unsigned int res18[1];volatile unsigned int FDCANCKSELR; // 0x90Cvolatile unsigned int res19[1];volatile unsigned int SPDIFCKSELR; // 0x914volatile unsigned int CECCKSELR; // 0x918volatile unsigned int USBCKSELR; // 0x91Cvolatile unsigned int RNG2CKSELR; // 0x920volatile unsigned int DSICKSELR; // 0x924volatile unsigned int ADCCKSELR; // 0x928volatile unsigned int LPTIM45CKSELR; // 0x92Cvolatile unsigned int LPTIM23CKSELR; // 0x930volatile unsigned int LPTIM1CKSELR; // 0x934volatile unsigned int res20[18];volatile unsigned int APB1RSTSETR; // 0x980volatile unsigned int APB1RSTCLRR; // 0x984volatile unsigned int APB2RSTSETR; // 0x988volatile unsigned int APB2RSTCLRR; // 0x98Cvolatile unsigned int APB3RSTSETR; // 0x990volatile unsigned int APB3RSTCLRR; // 0x994volatile unsigned int AHB2RSTSETR; // 0x998volatile unsigned int AHB2RSTCLRR; // 0x99Cvolatile unsigned int AHB3RSTSETR; // 0x9A0volatile unsigned int AHB3RSTCLRR; // 0x9A4volatile unsigned int AHB4RSTSETR; // 0x9A8volatile unsigned int AHB4RSTCLRR; // 0x9ACvolatile unsigned int res21[20];volatile unsigned int MP_APB1ENSETR; // 0xA00volatile unsigned int MP_APB1ENCLRR; // 0xA04volatile unsigned int MP_APB2ENSETR; // 0xA08volatile unsigned int MP_APB2ENCLRR; // 0xA0Cvolatile unsigned int MP_APB3ENSETR; // 0xA10volatile unsigned int MP_APB3ENCLRR; // 0xA14volatile unsigned int MP_AHB2ENSETR; // 0xA18volatile unsigned int MP_AHB2ENCLRR; // 0xA1Cvolatile unsigned int MP_AHB3ENSETR; // 0xA20volatile unsigned int MP_AHB3ENCLRR; // 0xA24volatile unsigned int MP_AHB4ENSETR; // 0xA28volatile unsigned int MP_AHB4ENCLRR; // 0xA2Cvolatile unsigned int res22[2];volatile unsigned int MP_MLAHBENSETR; // 0xA38volatile unsigned int MP_MLAHBENCLRR; // 0xA3Cvolatile unsigned int res23[16];volatile unsigned int MC_APB1ENSETR; // 0xA80volatile unsigned int MC_APB1ENCLRR; // 0xA84volatile unsigned int MC_APB2ENSETR; // 0xA88volatile unsigned int MC_APB2ENCLRR; // 0xA8Cvolatile unsigned int MC_APB3ENSETR; // 0xA90volatile unsigned int MC_APB3ENCLRR; // 0xA94volatile unsigned int MC_AHB2ENSETR; // 0xA98volatile unsigned int MC_AHB2ENCLRR; // 0xA9Cvolatile unsigned int MC_AHB3ENSETR; // 0xAA0volatile unsigned int MC_AHB3ENCLRR; // 0xAA4volatile unsigned int MC_AHB4ENSETR; // 0xAA8volatile unsigned int MC_AHB4ENCLRR; // 0xAACvolatile unsigned int MC_AXIMENSETR; // 0xAB0volatile unsigned int MC_AXIMENCLRR; // 0xAB4volatile unsigned int MC_MLAHBENSETR; // 0xAB8volatile unsigned int MC_MLAHBENCLRR; // 0xABCvolatile unsigned int res24[16];volatile unsigned int MP_APB1LPENSETR; // 0xB00volatile unsigned int MP_APB1LPENCLRR; // 0xB04volatile unsigned int MP_APB2LPENSETR; // 0xB08volatile unsigned int MP_APB2LPENCLRR; // 0xB0Cvolatile unsigned int MP_APB3LPENSETR; // 0xB10volatile unsigned int MP_APB3LPENCLRR; // 0xB14volatile unsigned int MP_AHB2LPENSETR; // 0xB18volatile unsigned int MP_AHB2LPENCLRR; // 0xB1Cvolatile unsigned int MP_AHB3LPENSETR; // 0xB20volatile unsigned int MP_AHB3LPENCLRR; // 0xB24volatile unsigned int MP_AHB4LPENSETR; // 0xB28volatile unsigned int MP_AHB4LPENCLRR; // 0xB2Cvolatile unsigned int MP_AXIMLPENSETR; // 0xB30volatile unsigned int MP_AXIMLPENCLRR; // 0xB34volatile unsigned int MP_MLAHBLPENSETR; // 0xB38volatile unsigned int MP_MLAHBLPENCLRR; // 0xB3Cvolatile unsigned int res25[16];volatile unsigned int MC_APB1LPENSETR; // 0xB80volatile unsigned int MC_APB1LPENCLRR; // 0xB84volatile unsigned int MC_APB2LPENSETR; // 0xB88volatile unsigned int MC_APB2LPENCLRR; // 0xB8Cvolatile unsigned int MC_APB3LPENSETR; // 0xB90 volatile unsigned int MC_APB3LPENCLRR; // 0xB94volatile unsigned int MC_AHB2LPENSETR; // 0xB98volatile unsigned int MC_AHB2LPENCLRR; // 0xB9Cvolatile unsigned int MC_AHB3LPENSETR; // 0xBA0 volatile unsigned int MC_AHB3LPENCLRR; // 0xBA4volatile unsigned int MC_AHB4LPENSETR; // 0xBA8volatile unsigned int MC_AHB4LPENCLRR; // 0xBACvolatile unsigned int MC_AXIMLPENSETR; // 0xBB0volatile unsigned int MC_AXIMLPENCLRR; // 0xBB4volatile unsigned int MC_MLAHBLPENSETR; // 0xBB8volatile unsigned int MC_MLAHBLPENCLRR; // 0xBBCvolatile unsigned int res26[16];volatile unsigned int MC_RSTSCLRR; // 0xC00volatile unsigned int res27[4];volatile unsigned int MC_CIER; // 0xC14volatile unsigned int MC_CIFR; // 0xC18volatile unsigned int res28[246];volatile unsigned int VERR; // 0xFF4volatile unsigned int IDR; // 0xFF8volatile 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; // 0x00volatile unsigned int OTYPER; // 0x04volatile unsigned int OSPEEDR; // 0x08volatile unsigned int PUPDR; // 0x0Cvolatile unsigned int IDR; // 0x10volatile unsigned int ODR; // 0x14volatile unsigned int BSRR; // 0x18volatile unsigned int LCKR; // 0x1C volatile unsigned int AFRL; // 0x20 volatile unsigned int AFRH; // 0x24volatile unsigned int BRR; // 0x28volatile 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 registervolatile unsigned int FPR1; // EXTI falling edge pending registervolatile unsigned int TZENR1; // EXTI TrustZone enable registervolatile unsigned int RES1[2]; volatile unsigned int RTSR2; // EXTI rising trigger selection registervolatile unsigned int FTSR2; // EXTI falling trigger selection registervolatile unsigned int SWIER2; // EXTI software interrupt event registervolatile unsigned int RPR2; // EXTI rising edge pending registervolatile unsigned int FPR2; // EXTI falling edge pending registervolatile unsigned int TZENR2; // EXTI TrustZone enable registervolatile unsigned int RES2[2];volatile unsigned int RTSR3; // EXTI rising trigger selection registervolatile unsigned int FTSR3; // EXTI falling trigger selection registervolatile unsigned int SWIER3; // EXTI software interrupt event registervolatile unsigned int RPR3; // EXTI rising edge pending registervolatile unsigned int FPR3; // EXTI falling edge pending registervolatile unsigned int TZENR3; // EXTI TrustZone enable registervolatile unsigned int RES3[2];volatile unsigned int EXTICR1; // EXTI external interrupt selection register 1volatile 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 registervolatile unsigned int C1EMR1; // EXTI CPU1 wakeup with event mask registervolatile unsigned int RES5[2];volatile unsigned int C1IMR2; // EXTI CPU1 wakeup with interrupt mask registervolatile unsigned int C1EMR2; // EXTI CPU1 wakeup with event mask registervolatile 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 registervolatile unsigned int C2EMR1; // EXTI CPU2 wakeup with event mask registervolatile unsigned int RES8[2];volatile unsigned int C2IMR2; // EXTI CPU2 wakeup with interrupt mask registervolatile unsigned int C2EMR2; // EXTI CPU2 wakeup with event mask registervolatile 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));elsegpiox->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;
}
测试结果如下:
作业二:
实验现象如下:
相关文章:
2022-2-23作业
一、通过操作Cortex-A7核,串口输入相应的命令,控制LED灯进行工作 1.例如在串口输入led1on,开饭led1灯点亮 2.例如在串口输入led1off,开饭led1灯熄灭 3.例如在串口输入led2on,开饭led2灯点亮 4.例如在串口输入led2off,开饭led2灯熄灭 5.例如在串口输…...
1.基于Label studio的训练数据标注指南:信息抽取(实体关系抽取)、文本分类等
文本抽取任务Label Studio使用指南 1.基于Label studio的训练数据标注指南:信息抽取(实体关系抽取)、文本分类等 2.基于Label studio的训练数据标注指南:(智能文档)文档抽取任务、PDF、表格、图片抽取标注等…...
“高退货率”标签引热议,亚马逊跨境电商是好是坏?
在多数卖家不知情的情况下,亚马逊“高退货率”标签上线,该消息已被官方证实,目的是为了践行以客户为中心的理念和推动卖家提升服务。 官方确认上线“高退货率”标签 近期,有亚马逊卖家发现产品详情页出现了“高退货率”标签&…...
Pinia2
一、入门案例 1、安装 npm i pinia -S 2、注册插件 //main.ts import { createPinia } from pinia app.use(createPinia()) 3、创建store/countStore.ts import { defineStore } from "pinia"; const useCounterStore defineStore(counterStore,{ state(){ return{…...
服务器配置 | 在Windows本地打开服务器端Tensorboard结果
文章目录方法1:直接cmd使用ssh登录远程服务器方法2:利用Xshell设置本地端口进行监听方法3:利用MobaXterm设置本地端口监听这里介绍三个方法,在在Windows本地打开服务器端Tensorboard结果 方法1:直接cmd使用ssh登录远程…...
13 nuxt3学习(新建页面 内置组件 assets 路由)
新建页面 Nuxt项目中的页面是在 pages目录 下创建的 在pages目录创建的页面,Nuxt会根据该页面的目录结构和其文件名来自动生成对应的路由。页面路由也称为文件系统路由器(file system router),路由是Nuxt的核心功能之一 方式一…...
Linus命令记录(持续编辑版)
目录 一、前言 二、2023年2月查找Linus命令记录 1、竖线 |,双竖线 ||,&和&& 2、wc 3、free 和 top 4、c 库函数 strcpy() 5、c 库函数 memmove() 6、open 三、2023年3月查找Linus命令记录 1、sort 2、uniq 一、前言 有时候遇到不…...
玩转ThreadLocal
前言 ThreadLocal想必都不陌生,当多线程访问同一个共享变量时,就容易出现并发问题,为了保证线程安全,我们需要对共享变量进行同步加锁,但这又带来了性能消耗以及使用者的负担,那么有没有可能当我们创建一个…...
亚马逊二审来袭,跨境电商传统验证算法真的靠谱吗?
多个大卖突遭二审 已有卖家账号被封 近期有不少卖家在论坛上反映称自己收到了亚马逊的二次视频验证邮件。 邮件上称: 卖家必须要完成额外的身份审查,才有资格在亚马逊继续销售商品;亚马逊要求卖家出示注册时提交的身份证原件和营业执照原件…...
微信小程序|基于小程序+云开发制作一个租房小程序
经济发展的同时伴随着大批人群的流动,租房需求一直是持久不衰的话题,如何租好房,好租房,跟随此文一起制作一个租房小程序,让租房不再困难。 一、小程序1. 创建小程序2. 首页3. 房源列表页4. 房源详情页5. 个人中心页</...
2.4 群辉驱动:多网口,系统网络只能识别两个网口 解决教程
所需工具下载:链接:https://pan.baidu.com/s/1CMLl6waOuW-Ys2gKZx7Jgg?pwdchct提取码:chct安装的黑群晖华硕z490i主板自带一个i225 2.5G,后又插了一个4口8125B四口网卡,发现控制面板->网络->网络界面 只识别了其…...
Android正确使用资源res文件
观看此文注意首先有的UI改颜色,没用,发现无法更改按钮背景颜色。我的AS下载的是最新版本,Button按钮的背景颜色一直都是亮紫色,无法更改。为什么呢?首先在你的清单文件中看你应用的是哪个主题。我现在用的是这个可能你…...
5分钟搭建第一个k8s集群
急速上手Minikube搭建单节点 k8s集群实战什么是Minikube?环境准备安装步骤一.安装Docker1.安装yml2.设置阿里云镜像3.查看可安装的docker版本4. 安装docker5. 查看docker版本6.配置docker开机自启动7. 启动docker, 查看docker 启动状态二.安装k8s1.配置镜像源2.安装kubectl3.安…...
【MySQL】查询操作(基础篇)
目录 1、查询操作(Retrieve) 1.1 全列查询 1.2 指定列查询 1.3 查询字段为表达式 1.4 别名 1.5 去重:DISTINCT 1.6 排序:ORDER BY 1.7 条件查询:WHERE 1.8 分页查询 1、查询操作(Retrieve) 查询操作算的上是 SQL 中最复杂的操作了…...
工程管理系统+spring cloud 系统管理+java 系统设置+二次开发
工程项目各模块及其功能点清单 一、系统管理 1、数据字典:实现对数据字典标签的增删改查操作 2、编码管理:实现对系统编码的增删改查操作 3、用户管理:管理和查看用户角色 4、菜单管理:实现对系统菜单的增删改查操…...
MyBatisPlus Study Notes
文章目录1 MyBatisPlus概述1.1 MyBatis介绍1.2 MyBatisPlus特性2 标准数据层开发2.1 MyBatisPlus的CRUD操作API2.2 分页功能接口实现2.2.1 config(配置层)拦截器实现2.2.2 Dao(Mapper)数据访问层(CRUD)操作2.2.3 Junit单元测试进行…...
【Vu3 测试篇】自动化测试
一、为什么需要测试 自动化测试能够预防无意引入的 bug,并鼓励开发者将应用分解为可测试、可维护的函数、模块、类和组件。这能够帮助你和你的团队更快速、自信地构建复杂的 Vue 应用。与任何应用一样,新的 Vue 应用可能会以多种方式崩溃,因…...
Android system实战 — Android R(11) 第三方apk权限
Android system实战 — 第三方apk权限问题0. 前言1. 源码实现1.1 主要函数1.2 修改思路和实现1.2.1 修改思路1.2.2 方案一1.2.3 方案二0. 前言 最近在调试时遇到了第三方apk申请运行时权限,以及signature级别 install 权限不允许赋予给第三方apk,虽然这是…...
面试总结1
这里写目录标题什么是ORM?为什么mybatis是半自动的ORM框架?动态sqlJDBC步骤:jdbc的缺点:JDBC,MyBatis的区别:MyBatis相比JDBC的优势缓存一级缓存一级缓存在下面情况会被清除二级缓存最近在面试,发现了许多自…...
【Hello Linux】程序地址空间
作者:小萌新 专栏:Linux 作者简介:大二学生 希望能和大家一起进步! 本篇博客简介:简单介绍下进程地址空间 程序地址空间程序地址空间语言中的程序地址空间矛盾系统中的程序地址空间为什么要有进程地址空间思维导图总结…...
电脑崩溃蓝屏问题如何重装系统
电脑是我们日常生活和工作中必不可少的工具,但在使用过程中,难免会遇到各种问题,例如系统崩溃、蓝屏、病毒感染等,这些问题会严重影响我们的使用体验和工作效率。而小白一键重装系统可以帮助我们快速解决这些问题,本文…...
《商用密码应用与安全性评估》第一章密码基础知识1.2密码评估基本原理
商用密码应用安全性评估(简称“密评”)的定义:在采用商用密码技术、产品和服务集成建设的网络与信息系统中,对其密码应用的合规性、正确性、有效性等进行评估 信息安全管理过程 相关标准 国际:ISO/IEC TR 13335 中国:GB/T …...
【编程基础之Python】7、Python基本数据类型
【编程基础之Python】7、Python基本数据类型Python基本数据类型整数(int)基本的四则运算位运算比较运算运算优先级浮点数(float)布尔值(bool)字符串(str)Python数据类型变换隐式类型…...
Kakfa详解(一)
kafka使用场景 canal同步mysqlelk日志系统业务系统Topic kafka基础概念 Producer: 消息生产者,向kafka发送消息Consumer: 从kafka中拉取消息消费的客户端Consumer Group: 消费者组,消费者组是多个消费者的集合。消费者组之间互不影响,所有…...
图解LeetCode——剑指 Offer 12. 矩阵中的路径
一、题目 给定一个 m x n 二维字符网格 board 和一个字符串单词 word 。如果 word 存在于网格中,返回 true ;否则,返回 false 。 单词必须按照字母顺序,通过相邻的单元格内的字母构成,其中“相邻”单元格是那些水平相…...
particles在vue3中的基本使用
第三方库地址 particles.vue3 - npm 1.安装插件 npm i particles.vue3 npm i tsparticles2.在main.js中引入 import Particles from particles.vue3 app.use(Particles) // 配置相关的文件常用 api particles.number.value>粒子的数量particles.number.density粒子的稀密…...
04 Android基础--RelativeLayout
04 Android基础--RelativeLayout什么是RelativeLayout?RelativeLayout的常见用法:什么是RelativeLayout? 相对布局(RelativeLayout)是一种根据父容器和兄弟控件作为参照来确定控件位置的布局方式。 根据父容器定位 在相…...
python基础命令
1.现在包的安装路径 #pip show 包名 2.pip讲解 相信对于大多数熟悉Python的人来说,一定都听说并且使用过pip这个工具,但是对它的了解可能还不一定是非常的透彻,今天小编就来为大家介绍10个使用pip的小技巧,相信对大家以后管理和…...
用 Real-ESRGAN 拯救座机画质,自制高清版动漫资源
内容一览:Real-ESRGAN 是 ESRGAN 升级之作,主要有三点创新:提出高阶退化过程模拟实际图像退化,使用光谱归一化 U-Net 鉴别器增加鉴别器的能力,以及使用纯合成数据进行训练。 关键词:Real-ESRGAN 超分辨率 视…...
数据结构预备知识(模板)
模板 功能上类比C的重载函数,可以使用一种通用的形式,去代替诸多数据类型,使得使用同一种函数的时候,可以实现对于不同数据类型的相同操作。增强类和函数的可重用性。 使用模板函数为函数或类声明一个一般的模式,使得…...
网站建设中的技术问题/余姚网站如何进行优化
%{ 1.这就是传说中的多行注释 2.成功! %} 注意是大括号哟...
自营店网站建设/重庆seo推广外包
场景:java 解析csv文件例子,csv文件 中文乱码有关问题java 解析csv文件例子,csv文件 中文乱码问题java 解析csv文件例子,采用了第三方包,csv文件 中文乱码问题解析方法:public List resolveCsv(String csvFileName) {CSVReader re…...
东莞网站建设aj工作室/在线咨询
接着进行逻辑回归项目的训练,我在进行这个训练的过程中,遇到了自己无法解决的问题,在接下来的博客中会提到,我用的解决办法都不适用,最后用到了sklearn库,发现这是真香,完全不用自己造轮子&…...
深圳网站建设网络推广公司/百度关键词推广价格
1. find /test ! -name "test" -type d -prune -o -type f -name "*.txt" -print 查找/test下的.txt的普通文件,不查找子目录。 2. find . ! -name "." -type d -prune -o -type f -print 查找当前目录下的普通文件,不查找…...
西藏山南建设局网站/手机百度下载app
希望能够帮助到一些朋友,认识到数据库索引正确设计的重要性。 由于我比较懒,就简单用文字描述一下,就懒得切图片证明了,懂技术的朋友可以自己测试一下,可证实我的测试结果是否真实。不懂技术的朋友信不信也无妨。 测…...
律师事务所网站设计/营销型网站建设价格
Python 近两年一直霸占编程语言排行榜 Top3,火热程度有目共睹。这也让刚入行的程序员,甚至 BATJ 的技术大牛,都意识到 Python 对于一个程序员职业发展的重要性,将其作为第一/第二开发语言去学习。虽然 Python 以简单易学著称&…...