【STM32笔记】:P04 断言的使用

stm32f10x_conf.h 这个文件还可配置是否使用"断言"编译选项


断言配置,如下:

javascript 复制代码
#ifdef  USE_FULL_ASSERT

/**
  * @brief  The assert_param macro is used for function's parameters check.
  * @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_failed((uint8_t *)__FILE__, __LINE__))
/* Exported functions ------------------------------------------------------- */
  void assert_failed(uint8_t* file, uint32_t line);
#else
  #define assert_param(expr) ((void)0)
#endif /* USE_FULL_ASSERT */

在 ST 标准库的函数中,一般会包含输入参数检查,即上述代码中的"assert_param"宏,当参数不符合要求时,会调用"assert_failed"函数,这个函数默认是空的。实际开发中使用断言时,先通过定义 USE_FULL_ASSERT 宏来使能断言,然后定义"assert_failed"函数,通常我们会让它调用 printf 函数输出错误说明。使能断言后,程序运行时会检查函数的输入参数,当软件经过测试,可发布时,会取消 USE_FULL_ASSERT 宏来去掉断言功能,使程序全速运行。

相关推荐
Cathy Bryant3 小时前
大模型推理(九):采样温度
笔记·神经网络·机器学习·数学建模·transformer
阳光宅男@李光熠3 小时前
【质量管理】构建供应链韧性的第一道防线——高风险供应商的识别
笔记·学习
岑梓铭3 小时前
考研408《计算机组成原理》复习笔记,第五章(5)——CPU的【微程序控制器】
笔记·考研·408·计算机组成原理·计组
白云偷星子4 小时前
MySQL笔记13
数据库·笔记·mysql
optimistic_chen4 小时前
【Java EE进阶 --- SpringBoot】Mybatis - plus 操作数据库
数据库·spring boot·笔记·java-ee·mybatis·mybatis-plus
yuuki2332334 小时前
【C语言】文件操作(附源码与图片)
c语言·后端
GilgameshJSS4 小时前
STM32H743-ARM例程22-USB_CDC
arm开发·stm32·嵌入式硬件
江苏学蠡信息科技有限公司4 小时前
STM32中硬件I2C的时钟占空比
stm32·单片机·fpga开发
光子物联单片机4 小时前
STM32G474单片机开发入门(十七)DAC详解及输出电压和正弦波实战
stm32·单片机·嵌入式硬件·mcu