// 为了使用 uint8_t 类型 #include <assert.h> // 为了使用 assert 宏(这里假设 assert_failed 是一个类似 assert 的错误处理函数) // 假设 assert_failed 函数的声明如下,实际声明可能有所不同 void assert_failed(uint8_t *file, uint32_t line); #define assert_param(expr) ((expr) ?
第1行,宏定义常量USE_FULL_ASSERT的值为1 第14行,是一个宏定义assert_param(expr),通过一个条件判断语句,如果表达式expr的值为真,则assert_param(expr)返回(void)0,如果表达式expr的值为假,则assert_param(expr)返回assert_failed((uint8_t *)__FILE__, __LINE__)。 第16行,函数声明void assert_failed...
STM32——assert_param(expr) 在STM32的固件库和提供的例程中,到处都可以见到assert_param()的使用。如果打开任何一个例程中的stm32f10x_conf.h文件,就可以看到实际上assert_param是一个宏定义; 在固件库中,它的作用就是检测传递给函数的参数是否是有效的参数。 所谓有效的参数是指满足规定范围的参数,比如某个...
assert_param函数的定义如下: ``` #define assert_param(expr) ((void)0) ``` 这个宏定义中的expr是一个表达式,它用于检查函数参数是否合法。如果expr为false,assert_param函数就会触发一个断言,导致程序停止运行。如果expr为true,assert_param函数就不会做任何事情,程序会继续执行。 assert_param函数的用法 assert...
18#define assert_param(expr) ((void)0)19#endif /* USE_FULL_ASSERT */ 第1⾏代码,默认情况下断⾔是关闭的,已经把“#define USE_FULL_ASSERT 1 ”注释掉,说明USE_FULL_ASSERT未被定义。如果需要打开断⾔的功能,需要将“#define USE_FULL_ASSERT 1 ”注释去掉,如下代码所⽰ 1#define USE_...
这是断言机制。意思是在关闭断言的情况下,void MY_NVIC_SetVectorTable(u32 NVIC_VectTab,u32 Offset){ assert_param(IS_NVIC_VECTTAB(NVIC_VectTab));assert_param(IS_NVIC_OFFSET(Offset));SCB->VTOR=NVIC_VectTab|(Offset&(u32)0x1FFFFF80);} 就相当于:void MY_NVIC_SetVectorTable(u32 NVIC...
出处 expr命令为Linux中的命令,一般用于整数值计算,但也可用于字符串操作。使用权限 所有使用者格式expr argument operator argument 参数说明 argument:为第一个参数 operator:为操作运算符 argument:为第二个参数
在STM32中,assert_param是一个宏,用于检查函数的输入参数是否满足预期条件。该宏的定义位于CMSIS库中的stm32fxxx.h文件中。 assert_param宏的定义如下所示: #define assert_param(expr) ((expr) ? (void)0 : assert_failed((uint8_t *)__FILE__, __LINE__)) 复制代码 assert_param宏接受一个表达式...
* @param expr: If expr is false, it calls assert_failed function which reports * the name of the source file and the source line number of the call * that failed. If expr is true, it returns no value. * @retval None */ #define assert_param(expr) ((expr) ? (void)0 : assert_...
#define assert_param(expr) ((expr) ? (void)0 : assert_failed((uint8_t *)__FILE__, __LINE__)) 如果没定义USE_FULL_ASSERT,那么就会定义#define assert_param(expr) ((void)0),这是为什么呢,是因为用户在代码调试阶段很可能会输入错误的参数而出现错误,一般这种错误不会察觉到,所以当我们想检查这...