历史上的今天
今天是:2025年03月25日(星期二)
2020年03月25日 | STM32固件库中assert_param的作用——学习笔记
2020-03-25 来源:eefocus
在学习stm32库函数过程中,笔者遇到大量的assert_param语句。经查明,assert_param的作用就是用来判断传递给函数的参数是否是有效值。
以下是从固件库中复制粘贴的:
void RCC_APB2PeriphClockCmd(uint32_t RCC_APB2Periph, FunctionalState NewState)
{
/* Check the parameters */
assert_param(IS_RCC_APB2_PERIPH(RCC_APB2Periph));
assert_param(IS_FUNCTIONAL_STATE(NewState));
if (NewState != DISABLE)
{
RCC->APB2ENR |= RCC_APB2Periph;
}
else
{
RCC->APB2ENR &= ~RCC_APB2Periph;
}
}
笔者用keil中的鼠标右键“go to definition xxxxxx"" 查看assert_param(IS_RCC_APB2_PERIPH(RCC_APB2Periph));语句中IS_RCC_APB2_PERIPH的定义,得到如下结果:
/** @defgroup APB2_peripheral
* @{
*/
#define RCC_APB2Periph_AFIO ((uint32_t)0x00000001)
#define RCC_APB2Periph_GPIOA ((uint32_t)0x00000004)
#define RCC_APB2Periph_GPIOB ((uint32_t)0x00000008)
#define RCC_APB2Periph_GPIOC ((uint32_t)0x00000010)
#define RCC_APB2Periph_GPIOD ((uint32_t)0x00000020)
#define RCC_APB2Periph_GPIOE ((uint32_t)0x00000040)
#define RCC_APB2Periph_GPIOF ((uint32_t)0x00000080)
#define RCC_APB2Periph_GPIOG ((uint32_t)0x00000100)
#define RCC_APB2Periph_ADC1 ((uint32_t)0x00000200)
#define RCC_APB2Periph_ADC2 ((uint32_t)0x00000400)
#define RCC_APB2Periph_TIM1 ((uint32_t)0x00000800)
#define RCC_APB2Periph_SPI1 ((uint32_t)0x00001000)
#define RCC_APB2Periph_TIM8 ((uint32_t)0x00002000)
#define RCC_APB2Periph_USART1 ((uint32_t)0x00004000)
#define RCC_APB2Periph_ADC3 ((uint32_t)0x00008000)
#define RCC_APB2Periph_TIM15 ((uint32_t)0x00010000)
#define RCC_APB2Periph_TIM16 ((uint32_t)0x00020000)
#define RCC_APB2Periph_TIM17 ((uint32_t)0x00040000)
#define RCC_APB2Periph_TIM9 ((uint32_t)0x00080000)
#define RCC_APB2Periph_TIM10 ((uint32_t)0x00100000)
#define RCC_APB2Periph_TIM11 ((uint32_t)0x00200000)
#define IS_RCC_APB2_PERIPH(PERIPH) ((((PERIPH) & 0xFFC00002) == 0x00) && ((PERIPH) != 0x00))
。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
以这个函数为例:
void RCC_APB2PeriphClockCmd(uint32_t RCC_APB2Periph, FunctionalState NewState)的作用就是使能APB2外设时钟,而当我们调用这个函数的时候,所给它的参数必须是以上规定的几个数值中的一个,不可随意填一个未定义的值进去。assert_param()函数有效的解决了这个问题,它在函数运行之初,便判断工程师所给的值是否为这个函数的有效值,以达到纠错报错的功能。同时,当我们不知道这个函数该填入什么样的值的时候,就可以使用keil中提供的右键“go to definition xxxx"查看assert_param()括号中的定义。
下一篇:单片机引脚模式配置
史海拾趣
|
1、输入端与输出端的边线应避免相邻平行, 以免产生反射干扰。必要时应加地线隔离;两相邻层的布线要互相垂直,平行容易产生寄生耦合。 2、地线>电源线>信号线,通常信号线宽为:8mil~12mil;电源线为50mil~100mil。对数字电路 ...… 查看全部问答> |
|
EVC中是不是不支持settimer的SLIDER_TIMER参数?? EVC中是不是不支持settimer的SLIDER_TIMER参数?? mSliderTimer = SetTimer(SLIDER_TIMER, 100, NULL); 报错是:error C2065: \'SLIDER_TIMER\' : undeclared identifier… 查看全部问答> |
|
晚上回家测试波形是否正确, 软仿好向没问题了!整个算法一次耗时,4.125us,在10KHz的PWM时占用CPU资源4.125%,硬件是可能更长一点儿,晚上在报告.执行的算法: 模拟的角度发生器, 电压变化自补尝 &nbs ...… 查看全部问答> |
|
报名参与:『ADI实验室电路DIY大赛』正式启动!https://bbs.eeworld.com.cn/thread-293726-1-1.html ADI实验室电路品种繁多,涉及面很广,如何选择合适的DIY项目可能是件容易令人困扰的事,但深究起来,其实可玩性是很大的,从今天开始,我将陆续 ...… 查看全部问答> |
|
大家帮看看为什么DeviceIoControl访问OID_802_11_BSSID_LIST老是失败 如题,下面一段程序中,DeviceIoControl访问OID_802_11_BSSID_LIST老是失败(见下面红色),也就是说bResult一直等于0;为什么?请教牛人!!!可能的问题出现在哪?为什么第二个DeviceIoControl失败?#include \"stdafx.h\"#include <windows.h ...… 查看全部问答> |




