这个错误是因为在stm8s_conf.h中只声明了一个函数 void assert_failed(u8* file, u32 line),但是没有地方实现它。
1.找个地方写个空函数就行,常见在main.c中末尾加此函数
这个判断语句使用的,当被判断的值出错时就会跳到下面的函数中
void assert_failed(u8* file, u32 line)
{
/* User can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* Infinite loop */
while (1)
{
}
}
2.或者直接屏蔽*#define USE_FULL_ASSERT 1*这儿条语句,但是判断出错后不会跳转
科普:这个语句是用于库函数中常见的
例如在看门狗函数中:
/* Check the parameters */
assert_param(IS_IWDG_PRESCALER_OK(IWDG_Prescaler));
/**
* @brief Macro used by the assert function in order to check the different
* values of the prescaler.
*/
#define IS_IWDG_PRESCALER_OK(VALUE) (((VALUE) == IWDG_Prescaler_4 ) || \
((VALUE) == IWDG_Prescaler_8 ) || \
((VALUE) == IWDG_Prescaler_16 ) || \
((VALUE) == IWDG_Prescaler_32 ) || \
((VALUE) == IWDG_Prescaler_64 ) || \
((VALUE) == IWDG_Prescaler_128 ) || \
((VALUE) == IWDG_Prescaler_256))
“stm8s_conf.h”中宏定义了这个,是为了进行参数校验
#define assert_param(expr) ((expr) ? (void)0 : assert_failed((uint8_t *)__FILE__, __LINE__))
这种参数检查的方法虽然会增加一定的代码开销,但可以帮助开发者及早发现错误,减少出错的几率