ARM day6 (标准pin引脚启动)

news2024/10/7 18:32:17

A7核

led.h

#ifndef __LED_H__
#define __LED_H__


//寄存器封装
//声明一个结构体
typedef struct {
	volatile unsigned int MODER;   //00
	volatile unsigned int OTYPER;  //04
	volatile unsigned int OSPEEDR; //08
	volatile unsigned int PUPDR;   //0C
	volatile unsigned int IDR;     //10
	volatile unsigned int ODR;     //14
}gpio_t;

#define GPIOE (gpio_t*)0x50006000
#define GPIOF (gpio_t*)0x50007000 

//引脚封装

#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

//模式寄存器封装 0 1 2 3
typedef enum{
	INPUT,       //输入 0
	OUTPUT,      //输出 1
	ALT,         //2
	ANALOG,      //3
}gpio_moder_t;

//输出类型寄存器封装 
typedef enum{
	PP,        //推挽 0
	OD,        //开漏 1
}gpio_otyper_t;

//输出数据寄存器封装
typedef enum{
	LOW,             //低速
	MED,             //中速
	HIGH,            //高速
	WERY_HIGH,       //超高速
}gpio_ospeedr_t;


//上下拉电阻寄存器封装
typedef enum{
	NO_PUPDR,  //禁止 0
	PU,        //上拉 1
	PD,        //下拉 2
}gpio_pupdr_t;


//高低电平寄存器封装
typedef enum{
	GPIO_RESET_T,   //低电平 0
	GPIO_SET_T,     //高电平 1
}gpio_odr_t;

typedef struct{
	gpio_moder_t moder;     //模式      
	gpio_otyper_t otyper;   //输出类型
	gpio_ospeedr_t ospeedr; //输出速度
	gpio_pupdr_t pupdr;     //是否上下拉
}gpio_init_t;

//PE10  PF10  PE8
//函数1功能:GPIO初始化
//参数:1)GPIO组号  2)引脚编号  3)初始化相关值
//返回值:无
void hal_gpio_init(gpio_t* gpiox,unsigned int pin,gpio_init_t* init);


//开关灯
void operate_pin(gpio_t* gpiox,unsigned int pin,unsigned int gpio_status);

#endif

led.c

#include "led.h"


//初始化引脚
void hal_gpio_init(gpio_t* gpiox,unsigned int pin,gpio_init_t* init)
{
	//模式
	gpiox->MODER &= (~(0x3 << pin*2));
	gpiox->MODER |= (init->moder << pin*2);
	//类型
	gpiox->OTYPER &= (~(0x1 << pin));
	gpiox->OTYPER |= (init->otyper << pin);
	//速率
	gpiox->OSPEEDR &= (~(0x3 << pin*2));
	gpiox->OSPEEDR |= (init->ospeedr << pin*2);
	//上下拉
	gpiox->PUPDR &= (~(0x3 << pin*2));
	gpiox->PUPDR |= (init->pupdr << pin*2);
}

void operate_pin(gpio_t* gpiox,unsigned int pin,unsigned int gpio_status)
{
	if(gpio_status == GPIO_SET_T)
		gpiox->ODR &= (~(0x1 << pin));
	else
		gpiox->ODR |= (0x1 << pin);
}


main.c

#include "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++);
}

void led_init()
{
	//使能
	*(volatile unsigned int *)0x50000A28 |= (0x3 << 4);

	//初始化结构体
	gpio_init_t init = {OUTPUT,PP,LOW,NO_PUPDR};
	//初始化引脚
	hal_gpio_init(GPIOE,GPIO_PIN_10,&init);
	hal_gpio_init(GPIOF,GPIO_PIN_10,&init);
	hal_gpio_init(GPIOE,GPIO_PIN_8,&init);

}

int main()
{

	// LED灯初始化
	led_init();

	while(1)
	{
		operate_pin(GPIOE,GPIO_PIN_10,GPIO_SET_T);
		delay_ms(200);
		operate_pin(GPIOE,GPIO_PIN_10,GPIO_RESET_T);
		operate_pin(GPIOF,GPIO_PIN_10,GPIO_SET_T);
		delay_ms(200);
		operate_pin(GPIOF,GPIO_PIN_10,GPIO_RESET_T);
		operate_pin(GPIOE,GPIO_PIN_8,GPIO_SET_T);
		delay_ms(200);
		operate_pin(GPIOE,GPIO_PIN_8,GPIO_RESET_T);
	}
	return 0;
}

M4核启动

gpio.c

/**
  ******************************************************************************
  * @file    gpio.c
  * @brief   This file provides code for the configuration
  *          of all used GPIO pins.
  ******************************************************************************
  * @attention
  *
  * <h2><center>&copy; Copyright (c) 2023 STMicroelectronics.
  * All rights reserved.</center></h2>
  *
  * This software component is licensed by ST under BSD 3-Clause license,
  * the "License"; You may not use this file except in compliance with the
  * License. You may obtain a copy of the License at:
  *                        opensource.org/licenses/BSD-3-Clause
  *
  ******************************************************************************
  */

/* Includes ------------------------------------------------------------------*/
#include "gpio.h"

/* USER CODE BEGIN 0 */

/* USER CODE END 0 */

/*----------------------------------------------------------------------------*/
/* Configure GPIO                                                             */
/*----------------------------------------------------------------------------*/
/* USER CODE BEGIN 1 */

/* USER CODE END 1 */

/** Configure pins
*/
void MX_GPIO_Init(void)
{

  GPIO_InitTypeDef GPIO_InitStruct = {0};

  /* GPIO Ports Clock Enable */
  __HAL_RCC_GPIOF_CLK_ENABLE();
  __HAL_RCC_GPIOE_CLK_ENABLE();

  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(GPIOF, GPIO_PIN_10, GPIO_PIN_RESET);

  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(GPIOE, GPIO_PIN_10|GPIO_PIN_8, GPIO_PIN_RESET);

  /*Configure GPIO pin : PF10 */
  GPIO_InitStruct.Pin = GPIO_PIN_10;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  HAL_GPIO_Init(GPIOF, &GPIO_InitStruct);

  /*Configure GPIO pins : PE10 PE8 */
  GPIO_InitStruct.Pin = GPIO_PIN_10|GPIO_PIN_8;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);

}

/* USER CODE BEGIN 2 */

/* USER CODE END 2 */

/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

main.c

/* USER CODE BEGIN Header */
/**
  ******************************************************************************
  * @file           : main.c
  * @brief          : Main program body
  ******************************************************************************
  * @attention
  *
  * <h2><center>&copy; Copyright (c) 2023 STMicroelectronics.
  * All rights reserved.</center></h2>
  *
  * This software component is licensed by ST under BSD 3-Clause license,
  * the "License"; You may not use this file except in compliance with the
  * License. You may obtain a copy of the License at:
  *                        opensource.org/licenses/BSD-3-Clause
  *
  ******************************************************************************
  */
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "gpio.h"

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */

/* USER CODE END Includes */

/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */

/* USER CODE END PTD */

/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
/* USER CODE END PD */

/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */

/* USER CODE END PM */

/* Private variables ---------------------------------------------------------*/

/* USER CODE BEGIN PV */

/* USER CODE END PV */

/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
/* USER CODE BEGIN PFP */

/* USER CODE END PFP */

/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */

/* USER CODE END 0 */

/**
  * @brief  The application entry point.
  * @retval int
  */
int main(void)
{
  /* USER CODE BEGIN 1 */

  /* USER CODE END 1 */

  /* MCU Configuration--------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* USER CODE BEGIN Init */

  /* USER CODE END Init */

  if(IS_ENGINEERING_BOOT_MODE())
  {
    /* Configure the system clock */
    SystemClock_Config();
  }

  /* USER CODE BEGIN SysInit */

  /* USER CODE END SysInit */

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  /* USER CODE BEGIN 2 */

  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
    /* USER CODE END WHILE */
			HAL_GPIO_WritePin(GPIOE, GPIO_PIN_10, GPIO_PIN_SET);
			HAL_Delay(100);
		  HAL_GPIO_WritePin(GPIOE, GPIO_PIN_10, GPIO_PIN_RESET);
		  HAL_GPIO_WritePin(GPIOF, GPIO_PIN_10, GPIO_PIN_SET);
			HAL_Delay(100);
		  HAL_GPIO_WritePin(GPIOF, GPIO_PIN_10, GPIO_PIN_RESET);
		  HAL_GPIO_WritePin(GPIOE, GPIO_PIN_8, GPIO_PIN_SET);
			HAL_Delay(100);
		  HAL_GPIO_WritePin(GPIOE, GPIO_PIN_8, GPIO_PIN_RESET);
		
    /* USER CODE BEGIN 3 */
  }
  /* USER CODE END 3 */
}

/**
  * @brief System Clock Configuration
  * @retval None
  */
void SystemClock_Config(void)
{
  RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};

  /** Initializes the RCC Oscillators according to the specified parameters
  * in the RCC_OscInitTypeDef structure.
  */
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_LSI;
  RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  RCC_OscInitStruct.HSICalibrationValue = 16;
  RCC_OscInitStruct.HSIDivValue = RCC_HSI_DIV1;
  RCC_OscInitStruct.LSIState = RCC_LSI_ON;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
  RCC_OscInitStruct.PLL2.PLLState = RCC_PLL_NONE;
  RCC_OscInitStruct.PLL3.PLLState = RCC_PLL_NONE;
  RCC_OscInitStruct.PLL4.PLLState = RCC_PLL_NONE;
  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  {
    Error_Handler();
  }
  /** RCC Clock Config
  */
  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_ACLK
                              |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2
                              |RCC_CLOCKTYPE_PCLK3|RCC_CLOCKTYPE_PCLK4
                              |RCC_CLOCKTYPE_PCLK5;
  RCC_ClkInitStruct.AXISSInit.AXI_Clock = RCC_AXISSOURCE_HSI;
  RCC_ClkInitStruct.AXISSInit.AXI_Div = RCC_AXI_DIV1;
  RCC_ClkInitStruct.MCUInit.MCU_Clock = RCC_MCUSSOURCE_HSI;
  RCC_ClkInitStruct.MCUInit.MCU_Div = RCC_MCU_DIV1;
  RCC_ClkInitStruct.APB4_Div = RCC_APB4_DIV1;
  RCC_ClkInitStruct.APB5_Div = RCC_APB5_DIV1;
  RCC_ClkInitStruct.APB1_Div = RCC_APB1_DIV1;
  RCC_ClkInitStruct.APB2_Div = RCC_APB2_DIV1;
  RCC_ClkInitStruct.APB3_Div = RCC_APB3_DIV1;

  if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct) != HAL_OK)
  {
    Error_Handler();
  }
}

/* USER CODE BEGIN 4 */

/* USER CODE END 4 */

/**
  * @brief  This function is executed in case of error occurrence.
  * @retval None
  */
void Error_Handler(void)
{
  /* USER CODE BEGIN Error_Handler_Debug */
  /* User can add his own implementation to report the HAL error return state */
  __disable_irq();
  while (1)
  {
  }
  /* USER CODE END Error_Handler_Debug */
}

#ifdef  USE_FULL_ASSERT
/**
  * @brief  Reports the name of the source file and the source line number
  *         where the assert_param error has occurred.
  * @param  file: pointer to the source file name
  * @param  line: assert_param error line source number
  * @retval None
  */
void assert_failed(uint8_t *file, uint32_t line)
{
  /* USER CODE BEGIN 6 */
  /* User can add his own implementation to report the file name and line number,
     ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  /* USER CODE END 6 */
}
#endif /* USE_FULL_ASSERT */

/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

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

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

“全球筷子第一股”双枪科技携手纷享销客连接型CRM

近日&#xff0c;纷享销客携手双枪科技股份有限公司&#xff08;以下简称“双枪”&#xff09;&#xff0c;“主数据与订货管理系统”项目启动会在浙江杭州举行&#xff0c;双枪和纷享销客双方多位高管共同出席了当天的启动会&#xff0c;并针对双方项目组的紧密合作给予了一致…

【C++面向对象】用电管理数据管理系统(面向对象)

&#x1f449;博__主&#x1f448;&#xff1a;米码收割机 &#x1f449;技__能&#x1f448;&#xff1a;C/Python语言 &#x1f449;公众号&#x1f448;&#xff1a;测试开发自动化 &#x1f449;荣__誉&#x1f448;&#xff1a;阿里云博客专家博主、51CTO技术博主 &#x…

word转化为ftl格式文件模板,导出后office提示文件错误

需求如下: 使用模板,导出word文件,最近在做这个需求,本地环境用的是wps,结合本地的环境快速完成了开发需求之后,有一天客户发现office打开报错,本人深感不接,wps都能打开,各个在线文档也都支持,为何office就不支持,环境不同。 分析: wps是按照office版本迭代开发…

对比学习论文-系列4

文章目录 MedCLIP: Contrastive Learning from Unpaired Medical Images and Text目标问题来源模型架构 Supervised Prototypical Contrastive Learning for Emotion Recognition in ConversationPrototypical Contrastive LearningCurriculum Strategy&#xff1a; KECP: Know…

Lion:闭源大语言模型的对抗性蒸馏

通过调整 70k 指令跟踪数据&#xff0c;Lion (7B) 可以实现 ChatGPT 95% 的能力&#xff01; 消息 我们目前正在致力于训练更大尺寸的版本&#xff08;如果可行的话&#xff0c;13B、33B 和 65B&#xff09;。感谢您的耐心等待。 **[2023年6月10日]**我们发布了微调过程中解…

MyBatis逆向工程的配置与生成

什么是逆向工程 所谓的逆向⼯程是&#xff1a;根据数据库表逆向⽣成Java的pojo类&#xff0c;SqlMapper.xml⽂件&#xff0c;以及Mapper接⼝类 等。 要完成这个⼯作&#xff0c;需要借助别⼈写好的逆向⼯程插件。 1.在pom中添加逆向工程插件 <!--定制构建过程--> <bu…

字符流的使用

1&#xff1a;文件字符流输入流-一次读取一个字符 1:文件字符输入流&#xff1a;Reader 以内存为基准&#xff0c;把磁盘文件中的数据以字符的形式读取到内存中去。 2&#xff1a;文件字符流输入流-一次读取一个字符数组 3&#xff1a;文件字符输出流 作用&#xff1a;以内存…

【现场问题】flink-cdc,Oracle2Mysql的坑,Oracle区分大小写导致

大小写导致的问题 错误的flink-cdc语句sql我们看一下oracle的数据库字段再看一下错误sql里面的内容flink报错内容 正确的sql三级目录 错误的flink-cdc语句sql CREATE TABLE t_wx_source_1 (id String,name String,age String ) WITH (connector oracle-cdc,hostname 192.168…

U-Boot移植 (3)- uboot启动Linux内核测试

文章目录 1. bootcmd 和 bootargs 环境变量1.1 环境变量 bootcmd1.2 环境变量 bootargs 2. uboot 启动 Linux 测试2.1 从 EMMC 启动 Linux 系统2.2 从网络启动 Linux 系统 3. 总结 1. bootcmd 和 bootargs 环境变量 1.1 环境变量 bootcmd bootcmd 保存着 uboot 默认命令&…

Netty专题:netty概述,及丢弃协议服务(1)

Netty 是一个 Java NIO 客户端服务器框架&#xff0c;使用它可以快速简单地开发网络应用程序&#xff0c;比如服务器和客户端的协议。Netty 大大简化了网络程序的开发过程比如 TCP 和 UDP 的 socket 服务的开发。 JDK 原生 NIO 程序的问题 JDK 原生也有一套网络应用程序 API&…

秋招算法岗c++面经

目录 1、指针与引用的区别 2.const关键字 3.重载和重写(覆盖)的区别 4.new和malloc的区别(new封装了malloc) 5.static和const的区别 6. c三大特性 7.虚函数 8.纯虚函数 9.虚继承 10. 智能指针 11. 内存泄漏 12.c的内存分布 13.STL介绍 1、指针与引用的区别 指针存…

【Web3】认识NFT

NFT&#xff08;非同质化代币&#xff09;在Web3中扮演着重要的角色。Web3是指下一代互联网&#xff0c;它建立在区块链技术之上&#xff0c;旨在实现更加去中心化、透明和用户掌控的互联网。 NFT在Web3的一些重要作用&#xff1a; 唯一性和可证明稀缺性&#xff1a;NFT是一种…

vscode突然不能输入中文句号,怎么办

vscode突然不能输入中文句号&#xff0c;怎么办? 敲代码敲得好好的&#xff0c;突然无论打句号&#xff0c;出来的都是英文的句号&#xff0c;无法打出中文的句号&#xff0c; 让人着实着急。。。 记录一下解决办法&#xff1a; Ctrl 句号&#xff0c;然后再测试一下&…

JavaWeb 速通HTML(常用标签汇总及演示)

目录 一、拾枝杂谈 1.网页组成 : 1 结构 2 表现 3 行为 2.HTML入门 : 1 基本介绍 2.基本结构 : 3.HTML标签 : 1 基本说明 2 注意事项 二、常用标签汇总及演示 1.font标签 : 1 定义 2 演示 2.字符实体 : 1 定义 2 演示 3.标题标签 : 1 定义 2 演示 4. 超链接标签 : 1…

香薰市场分析:天猫香薰销售额近7.2亿,市场增长潜力大

在Z世代崛起的背景下&#xff0c;香薰作为能够调节情绪&#xff0c;提升生活品质的产品&#xff0c;备受市场青睐。作为一种健康、美容、舒缓压力的新兴行业&#xff0c;香薰市场也形成了自己的特色和竞争力&#xff0c;其发展前景十分广阔。 根据鲸参谋电商数据分析平台的相关…

Redis集群主从复制哨兵

环境配置&#xff1a; 一主二从 从机配置 主机查看 真实的主从配置应该在配置文件中配置&#xff0c;才是永久的 没哨兵的情况下&#xff0c;主机断开后。从机不会默认升级为主节点。需要手动配置。主机在启动后。依赖可以正常使用。从机断开后&#xff0c;期间主机写入东西&am…

探索HTML的黑科技:让你的网页变得无与伦比!

文章目录 1. 使用语义化标签2. 嵌套标签正确闭合3. 使用无障碍&#xff08;Accessibility&#xff09;特性4. 利用表单验证5. 使用内联 SVG6. 优化图像加载7. 优化 CSS 和 JavaScript8. 使用响应式设计9. 使用嵌入式视频和音频10. SEO 优化 以下是十个常用的 HTML 技巧&#xf…

SpringBoot整合Redis哨兵模式

文章目录 1、Redis哨兵复习2、整合3、简单举例4、RedisTemplate详解5、补充 1、Redis哨兵复习 Redis哨兵主要有三点作用&#xff1a; 监控&#xff1a;不断检查master和slave是否正常运行通知&#xff1a;当被监控的主从服务器发生问题时&#xff0c;向其他哨兵和客户端发送通…

当量因子法、InVEST、SolVES模型等多技术融合在生态系统服务功能社会价值评估

第一章 理论基础与研究热点分析 1. 生态系统服务与生态系统服务价值介绍 ​ 2. 生态系统服务价值研究方法 3. 生态系统服务价值研究热点 Citespace文献可视化分析 VOSviewer文献可视化分析 第二章 空间数据来源及预处理 1. 空间数据简介 2. ArcGIS Pro数据采集与分析 数…

直流运算放大器-----四种反馈电路(一)

目录 电压串联负反馈 电路图 计算公式 仿真 电压并联负反馈 电路图 计算公式 仿真 电流串联负反馈 电路图 计算公式 仿真 电流并联负反馈 电路图 计算公式 仿真 电压电流&#xff0c;串联并联反馈区分 电压串联负反馈 电路图 计算公式 仿真 因为是二倍放大&#x…