博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
STM32里面的一些小函数——assert_param,PUTCHAR_PROTOTYPE
阅读量:4624 次
发布时间:2019-06-09

本文共 1086 字,大约阅读时间需要 3 分钟。

assert_param

可以在stm32f10x_conf.h找到原型,

#ifdef USE_FULL_ASSERT

  #define assert_param(expr) ((expr) ? (void)0 : assert_failed((uint8_t*)__FILE__, __LINE__))

  void assert_failed(uint8_t* file, uint32_t line);

#else

  #define assert_param(expr) ((void)0)
#endif 

大概是什么意思呢?

分两段看:若定义了USE_FULL_ASSERT,则执行下面的define语句和后面的void assert_failed函数,   反之则只执行assert_param函数(空函数)。

assert_param(expr) ((expr) ? (void)0 : assert_failed((uint8_t*)__FILE__, __LINE__)):

如果expr为真,即执行(void)0函数,如果expr为假,即执行后面的assert_failed函数,而assrt_failed函数在main下面可以找到

void assert_failed(u8* file, u32 line) 

{ /* User can add his own implementation to report the file name and linenumber, 
ex: printf("Wrong parameters value: file %s on line %d\r\n", file,line) */ 
/* Infinite loop */ 
while (1) { } 
}

也就是说,可以用assert函数,来执行判断功能,用来程序在跑飞的时候,进入此处。

 

PUTCHAR_PROTOTYPE在main函数中可以找到原型,此处定义的是USART1,可以借助这个函数测试串口是否正常。

PUTCHAR_PROTOTYPE

{
USART_SendData(USART1, (uint8_t) ch);
/* Loop until the end of transmission */
while (USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET)
{}
return ch;
}

 

 

转载于:https://www.cnblogs.com/Blog-c/p/6756869.html

你可能感兴趣的文章
foreach 和 for 循环的区别
查看>>
说话人识别/声纹识别的研究综述(转)
查看>>
如何烧写BIOS到SD卡里面
查看>>
3-C++程序的结构1.1
查看>>
第十八课 Gazebo仿真器
查看>>
g2o:一种图优化的C++框架
查看>>
微信自定义菜单errcode(40016)
查看>>
十天冲刺-09
查看>>
python格式化输出的方式汇总
查看>>
linux 安装中文包和设置中文环境
查看>>
Mac 使用WireShark
查看>>
OpenCV---环境安装和初次使用
查看>>
回调函数的经典代码使用
查看>>
【学术篇】bzoj3262 陌上花开. cdq分治入门
查看>>
daily scrum 12.8
查看>>
Nginx初识
查看>>
EOJ 2847 路由结点
查看>>
题解 化学反应
查看>>
题解 楼房重建
查看>>
Python汉字转换成拼音
查看>>