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;}