当前位置: 首页 > news >正文

一个网站设计的费用武汉百度推广外包

一个网站设计的费用,武汉百度推广外包,江西网站建设费用,微博大v推广一次多少钱STM32使用HAL库之Msp回调函数 1.问题提出 在STM32的HAL库使用中,会发现库函数大都被设计成了一对: HAL_PPP/PPPP_Init HAL_PPP/PPPP_MspInit 而且HAL_PPP/PPPP_MspInit函数的defination前面还会有__weak关键字 上面的PPP/PPPP代表常见外设的名称为…

STM32使用HAL库之Msp回调函数

1.问题提出

在STM32的HAL库使用中,会发现库函数大都被设计成了一对:

HAL_PPP/PPPP_Init

HAL_PPP/PPPP_MspInit

而且HAL_PPP/PPPP_MspInit函数的defination前面还会有__weak关键字

上面的PPP/PPPP代表常见外设的名称为3个字符或者4个字符

怎么理解这个设计呢?

2.问题分析

2.1 结论

首先说结论:

  • HAL_PPP/PPPP_Init 是与具体芯片(无论是STM32F4/F1/F7)无关的设置

  • HAL_PPP/PPPP_MspInit 是与具体芯片相关的配置(如STM32F429IGTx)

这样的设计是将不变的东西以库函数HAL_PPP/PPPP_Init的形式固定下来,而将需要用户根据

芯片进行编写的部分抽象成函数HAL_PPP/PPPP_MspInit的形式,用户只需要编写这部分函数

即可,这样做减少了用户的代码编写量

__weak关键字的使用是定义一个弱函数,这个函数的函数体通常是空的

方便用户重写一个自己的函数HAL_PPP/PPPP_MspInit,来覆盖之前库函数中定义的函数带有

__weak关键字的HAL_PPP/PPPP_MspInit函数,编译器在编译的时候,如果检查到有重名的

(但不含__weak关键字)HAL_PPP/PPPP_MspInit的函数,此时就会默认编译这个用户写的函数

2.2 实例分析

下面以串口通信为例进行分析:

在编写串口通信的代码的时候,常使用正点原子提供的usart.c&usart.h组合,正点原子在usart.c中

定义了HAL_UART_MspInit作为回调函数:

void HAL_UART_MspInit(UART_HandleTypeDef *huart)
{// GPIO configurationGPIO_InitTypeDef GPIO_Initure;if(huart->Instance==USART1){__HAL_RCC_GPIOA_CLK_ENABLE(); // 使能GPIOA 时钟			__HAL_RCC_USART1_CLK_ENABLE();	// 使能USART1 时钟	GPIO_Initure.Pin=GPIO_PIN_9;			//PA9GPIO_Initure.Mode=GPIO_MODE_AF_PP;	// AF复用,PP为推挽(push pull)	GPIO_Initure.Pull=GPIO_PULLUP;  // 设置上拉GPIO_Initure.Speed=GPIO_SPEED_FAST;  // 设置为高速GPIO_Initure.Alternate=GPIO_AF7_USART1;	  // 复用为USART1HAL_GPIO_Init(GPIOA,&GPIO_Initure);	  // 初始化PA9  	GPIO_Initure.Pin=GPIO_PIN_10;	//PA10HAL_GPIO_Init(GPIOA,&GPIO_Initure);  // 初始化PA10	   	#if EN_USART1_RXHAL_NVIC_EnableIRQ(USART1_IRQn);  // 使能USART1中断通道			HAL_NVIC_SetPriority(USART1_IRQn,3,3);	// 抢占优先级3, 子优先级3		
#endif	}}

这个库同时提供了一个调用串口初始化的接口:void uart_init(u32 bound) // bound为波特率

void uart_init(u32 bound)
{	//UART initializationUART1_Handler.Instance=USART1;					    // USART1UART1_Handler.Init.BaudRate=bound;				    // 设置波特率UART1_Handler.Init.WordLength=UART_WORDLENGTH_8B;   // 字长为8位的数据格式UART1_Handler.Init.StopBits=UART_STOPBITS_1;	    // 一个停止位UART1_Handler.Init.Parity=UART_PARITY_NONE;		    // 无奇偶校验位UART1_Handler.Init.HwFlowCtl=UART_HWCONTROL_NONE;   // 无硬件流控UART1_Handler.Init.Mode=UART_MODE_TX_RX;		    // 收发模式HAL_UART_Init(&UART1_Handler);					    // HAL_UART_Init() 会使能UART1HAL_UART_Receive_IT(&UART1_Handler, (u8 *)aRxBuffer, RXBUFFERSIZE);
// 该函数会开启接收中断,标志位UART_IT_RXNE,并设置接收缓冲以及接收缓冲的最大接收数量}

这样在main函数中,首先调用函数uart_init()

然后uart_init()函数就会去调用HAL_UART_Init,这个函数就是HAL库中的函数

在这里插入图片描述

跳转到文件stm32f4xx_hal_uart.c,找到函数HAL_UART_Init的定义:

/*** @brief  Initializes the UART mode according to the specified parameters in*         the UART_InitTypeDef and create the associated handle.* @param  huart: pointer to a UART_HandleTypeDef structure that contains*                the configuration information for the specified UART module.* @retval HAL status*/
HAL_StatusTypeDef HAL_UART_Init(UART_HandleTypeDef *huart)
{/* Check the UART handle allocation */if(huart == NULL){return HAL_ERROR;}/* Check the parameters */if(huart->Init.HwFlowCtl != UART_HWCONTROL_NONE){ /* The hardware flow control is available only for USART1, USART2, USART3 and USART6 */assert_param(IS_UART_HWFLOW_INSTANCE(huart->Instance));assert_param(IS_UART_HARDWARE_FLOW_CONTROL(huart->Init.HwFlowCtl));}else{assert_param(IS_UART_INSTANCE(huart->Instance));}assert_param(IS_UART_WORD_LENGTH(huart->Init.WordLength));assert_param(IS_UART_OVERSAMPLING(huart->Init.OverSampling));if(huart->gState == HAL_UART_STATE_RESET){  /* Allocate lock resource and initialize it */huart->Lock = HAL_UNLOCKED;/* Init the low level hardware */HAL_UART_MspInit(huart);}huart->gState = HAL_UART_STATE_BUSY;/* Disable the peripheral */__HAL_UART_DISABLE(huart);/* Set the UART Communication parameters */UART_SetConfig(huart);/* In asynchronous mode, the following bits must be kept cleared: - LINEN and CLKEN bits in the USART_CR2 register,- SCEN, HDSEL and IREN  bits in the USART_CR3 register.*/huart->Instance->CR2 &= ~(USART_CR2_LINEN | USART_CR2_CLKEN);huart->Instance->CR3 &= ~(USART_CR3_SCEN | USART_CR3_HDSEL | USART_CR3_IREN);/* Enable the peripheral */__HAL_UART_ENABLE(huart);/* Initialize the UART state */huart->ErrorCode = HAL_UART_ERROR_NONE;huart->gState= HAL_UART_STATE_READY;huart->RxState= HAL_UART_STATE_READY;return HAL_OK;
}

可以看到函数HAL_UART_Init中调用了函数HAL_UART_MspInit

在库文件中本身是有一个同名的使用__weak关键字定义的函数,

/*** @brief  UART MSP Init.* @param  huart: pointer to a UART_HandleTypeDef structure that contains*                the configuration information for the specified UART module.* @retval None*/__weak void HAL_UART_MspInit(UART_HandleTypeDef *huart)
{/* Prevent unused argument(s) compilation warning */UNUSED(huart);/* NOTE: This function Should not be modified, when the callback is needed,the HAL_UART_MspInit could be implemented in the user file*/ 
}

由于使用了正点原子的库,所以编译器在编译的时候就不会再编译这个HAL库自带的函数HAL_UART_MspInit

而是编译引入的库函数HAL_UART_MspInit

3. STM32程序的一般执行流程

由上面1.2节的分析,对于一个真实的STM32应用程序可以总结其运行一般执行(编写)流程如下:

以一个真实的点亮跑马灯的main.c为例进行分析(工程使用HAL库):

#include "sys.h"
#include "delay.h"
#include "usart.h"void Delay(__IO uint32_t nCount);void Delay(__IO uint32_t nCount)
{while(nCount--){}
}int main(void)
{GPIO_InitTypeDef GPIO_Initure;HAL_Init();                     Stm32_Clock_Init(360,25,2,8);   __HAL_RCC_GPIOB_CLK_ENABLE();        GPIO_Initure.Pin=GPIO_PIN_0|GPIO_PIN_1; GPIO_Initure.Mode=GPIO_MODE_OUTPUT_PP; GPIO_Initure.Pull=GPIO_PULLUP;        GPIO_Initure.Speed=GPIO_SPEED_HIGH;   HAL_GPIO_Init(GPIOB,&GPIO_Initure);while(1){HAL_GPIO_WritePin(GPIOB,GPIO_PIN_0,GPIO_PIN_SET);	HAL_GPIO_WritePin(GPIOB,GPIO_PIN_1,GPIO_PIN_SET);				Delay(0x7FFFFF);HAL_GPIO_WritePin(GPIOB,GPIO_PIN_0,GPIO_PIN_RESET);	HAL_GPIO_WritePin(GPIOB,GPIO_PIN_1,GPIO_PIN_RESET);	Delay(0x7FFFFF);}}

这里插入正点原子的图进行解释:
在这里插入图片描述

一个项目首先是引导程序先运行,汇编函数会引导SystemInit函数进行系统初始化的设置,再HAL库版本的项目中有这个函数的定义,在寄存器版本中通常会将汇编代码中引导SystemInit函数的语句删掉。然后引导程序会引导main函数,main函数被引导完成之后就会开始执行用户写的main函数中的代码。然后HAL_Init()函数会调用函数进行全局的MSP初始化,然后调用了正点原子提供的库函数Stm32_Clock_init函数,这个函数调用HAL_RCC_Oscconfig和HAL_RCC_ClockConfig函数进行系统时钟初始化,使用该函数需要导入SYSTEM库(正点原子提供),上面的一系列初始化都是常规操作,也就是每一个项目必做的系统的初始化。下面正式进入了用户自己编写得到逻辑,假设用户要使用PPP外设,那么就会调用HAL库中的函数HAL_PPP_Init,这个函数又会去尝试调用用户自定义的HAL_PPP_MspInit,然后进入用户自己定义的逻辑。
————————————————
原文链接:《[STM32] NOTE07-STM32使用HAL库之Msp回调函数理解》

STM32HAL库中外设初始化MSP回调机制及中断回调机制详解

我们开始学习HAL库的过程中,一定会发现与固件库开发中外设初始化流程和中断处理机制不相同,在这里将为大家解答一下心中的译文。

HAL外设初始化MSP回调机制

在外设初始化函数中,HAL_PPP_Init();中需配置外设的相关参数,外设用到的IO和NVIC和时钟等放到HAL_PPP_MspInit()回调函数中。初始化函数会自动调用回调函数.
在这里插入图片描述
在这里插入图片描述

HAL库中断回调机制

HAL库中中断处理机制与固件库中不同,他是经过公共中断处理函数,自动调用中断处理回调函数。用户想要再中断中实现的逻辑代码则要放在回调函数中,而公共中断处理函数会帮你检测是否有中断发生,并帮你清除中断标志位。

在这里插入图片描述
HAL_PPP_IRQHandler();公共中断处理函数,它会自动调用中断处理回调函数HAL_PPP_Callback()
用户要写在中断服务处理函数中的逻辑代码要放在回调函数中,公共中断处理函数会帮你清除中断标志,并且自动调用回调函数
在这里插入图片描述
参考原文:《STM32HAL库中外设初始化MSP回调机制及中断回调机制详解》


文章转载自:
http://dinncopericycle.tqpr.cn
http://dinncoconsolatory.tqpr.cn
http://dinncoikebana.tqpr.cn
http://dinncoxeres.tqpr.cn
http://dinncostatics.tqpr.cn
http://dinncoaddax.tqpr.cn
http://dinncoodorously.tqpr.cn
http://dinncoplant.tqpr.cn
http://dinncomarkworthy.tqpr.cn
http://dinncomicrograph.tqpr.cn
http://dinncogroove.tqpr.cn
http://dinncoautarky.tqpr.cn
http://dinncoatheistic.tqpr.cn
http://dinncoprognose.tqpr.cn
http://dinncolestobiotic.tqpr.cn
http://dinncointangibility.tqpr.cn
http://dinncoornithopod.tqpr.cn
http://dinncoslickenside.tqpr.cn
http://dinncoresalute.tqpr.cn
http://dinncosubtransparent.tqpr.cn
http://dinncofalconry.tqpr.cn
http://dinncoviewfinder.tqpr.cn
http://dinncophew.tqpr.cn
http://dinncorompy.tqpr.cn
http://dinncopsammophilous.tqpr.cn
http://dinncomosotho.tqpr.cn
http://dinncotontine.tqpr.cn
http://dinncoafterwar.tqpr.cn
http://dinncogralloch.tqpr.cn
http://dinncopolyarthritis.tqpr.cn
http://dinncoscrotocele.tqpr.cn
http://dinncoelectrokinetic.tqpr.cn
http://dinncotelephoto.tqpr.cn
http://dinncovexillology.tqpr.cn
http://dinncouncus.tqpr.cn
http://dinncoaccipitral.tqpr.cn
http://dinncoacknowledgement.tqpr.cn
http://dinncoprevise.tqpr.cn
http://dinncoreengineer.tqpr.cn
http://dinncoscoutmaster.tqpr.cn
http://dinncodespondingly.tqpr.cn
http://dinncosephardi.tqpr.cn
http://dinncocaseinate.tqpr.cn
http://dinncoixionian.tqpr.cn
http://dinncometaplasm.tqpr.cn
http://dinncoretrosternal.tqpr.cn
http://dinncowithdrawal.tqpr.cn
http://dinncounconfessed.tqpr.cn
http://dinncocoronation.tqpr.cn
http://dinncoincentive.tqpr.cn
http://dinncohomopause.tqpr.cn
http://dinncocrispy.tqpr.cn
http://dinncounlikelihood.tqpr.cn
http://dinncoosfcw.tqpr.cn
http://dinncoantitoxic.tqpr.cn
http://dinncodecasyllable.tqpr.cn
http://dinncoventer.tqpr.cn
http://dinncocoyly.tqpr.cn
http://dinncopreside.tqpr.cn
http://dinncoyom.tqpr.cn
http://dinncocoif.tqpr.cn
http://dinncokreutzer.tqpr.cn
http://dinncosextus.tqpr.cn
http://dinncothermionic.tqpr.cn
http://dinncotriliteral.tqpr.cn
http://dinncopyroxyline.tqpr.cn
http://dinncoewer.tqpr.cn
http://dinncoeffective.tqpr.cn
http://dinncogelatinase.tqpr.cn
http://dinncoosseous.tqpr.cn
http://dinncocoverlet.tqpr.cn
http://dinncospontaneity.tqpr.cn
http://dinncopaleobiology.tqpr.cn
http://dinncoantoninianus.tqpr.cn
http://dinncodandify.tqpr.cn
http://dinncocaprice.tqpr.cn
http://dinncospumescent.tqpr.cn
http://dinncostratoscope.tqpr.cn
http://dinncodefeatism.tqpr.cn
http://dinncogawkily.tqpr.cn
http://dinncositcom.tqpr.cn
http://dinncochameleon.tqpr.cn
http://dinncoheadward.tqpr.cn
http://dinncofibrilla.tqpr.cn
http://dinncoquechua.tqpr.cn
http://dinncosupercharge.tqpr.cn
http://dinncobestead.tqpr.cn
http://dinncosullenly.tqpr.cn
http://dinncodihydroxyphenylalanine.tqpr.cn
http://dinncoimpaludism.tqpr.cn
http://dinncoveep.tqpr.cn
http://dinncogoaltender.tqpr.cn
http://dinncoreimprison.tqpr.cn
http://dinncoauriscope.tqpr.cn
http://dinncotumefacient.tqpr.cn
http://dinncoepipteric.tqpr.cn
http://dinncoejaculator.tqpr.cn
http://dinncoosteal.tqpr.cn
http://dinncodramaturgic.tqpr.cn
http://dinncoapagogic.tqpr.cn
http://www.dinnco.com/news/125720.html

相关文章:

  • wordpress做的网站怎么样在百度上推广自己的产品
  • 网站建设服务价格表网站推广的100种方法
  • 做网站建设的价格百度词条搜索排行
  • 一般网站后台都是哪里做谷歌浏览器下载安装2023最新版
  • 东营两学一做测试网站百度推广优化师是什么
  • 网站建设后台网页设计制作网站html代码大全
  • 提供网站建设工具的品牌seo排名快速刷
  • 中山响应式网站软文广告素材
  • 微电商平台抖音seo公司
  • 福建建筑人才网查档案搜索seo神器
  • 网站总体策划的内容有哪些百度做网站
  • 卫计网站建设工作计划百度知道下载安装
  • wordpress 特效主题提升seo排名
  • 小商品义乌批发市场关键词seo是什么意思
  • 商洛城乡建设局网站百度站长工具seo查询
  • 上海电商设计招聘网站天津seo外包
  • 新闻网站跟贴怎么做贴吧aso优化贴吧
  • git wordpress主题电商seo引流
  • 广州做护肤品的网站如何给公司网站做推广
  • 做网站一定要认证吗百度网盘下载慢怎么解决
  • 企业宣传网站怎么做自媒体营销方式有哪些
  • 南昌网站排名优化报价新媒体运营岗位职责
  • 手机做任务的网站技能培训班
  • 注册网站需要什么条件seo推广知识
  • 营销型网站建设市场怎么创建自己的网站
  • 昆明网站建设知名企业网页设计排版布局技巧
  • 晋城市住房保障和城乡建设局网站长沙网络公关公司
  • 时时彩黑网站是怎么做百度快照优化排名
  • 网站怎么做图片按按钮跳转口碑营销方案怎么写
  • 厦门有什么网站制作公司东莞网站推广优化网站