股票

symbol _assert_failed not defined (Debugstm8s_adc1.o )

在调试STM8的时候出现了这个问题,即函数assert_failed 未定义。
之前没有使用库文件,全部自己调用寄存器编制的程序就没有碰到这种问题。
在头文件stm8s_conf.h中对函数有引用:

  1. #ifndef FULL_ASSERT /* FULL_ASSERT not defined */  
  2. void assert_failed(void);  
  3. #define assert_param(expr) ((expr) ? (void)(0) : assert_failed())  
  4. #else /* FULL_ASSERT defined */  
  5. void assert_failed(u8 *file, u16 line);  
  6. #define assert_param(expr) ((expr) ? (void)(0) : assert_failed(__FILE__, __LINE__))  
  7. #endif  

出现报错是由于使用的main文件模板时将以下的函数删掉了!所以直接加上相应的函数就OK!
在main.c文件的末尾添加以下的语句:

  1. #ifdef FULL_ASSERT  
  2. <pre>/** 
  3.   * @brief  Reports the name of the source file and the source line number 
  4.   *   where the assert_param error has occurred. 
  5.   * @param file: pointer to the source file name 
  6.   * @param line: assert_param error line source number 
  7.   * @retval : None 
  8.   */  
  9. void assert_failed(u8* file, u32 line)  
  10. {  
  11.   /* User can add his own implementation to report the file name and line number, 
  12.      ex: printf(“Wrong parameters value: file %s on line %drn”, file, line) */  
  13.   
  14.   /* Infinite loop */  
  15.   while (1)  
  16.   {  
  17.   }  
  18. }  
  19. #endif  

注意定义的时候函数格式要与引用的时候对应上,一种带参数一种不带参数。

打赏
原文链接:,转发请注明来源!

打酱油的进行回复 点击这里取消回复。

  • 打酱油的

    楼主您好,我的stn8s_config.h里是这样的
    #define USE_FULL_ASSERT (1)

    /* Exported macro ------------------------------------------------------------*/
    #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 */

    #endif /* __STM8S_CONF_H */
    这个跟您的不一样,但是根据您的建议更改了#ifdef FULL_ASSERT及后面的语句后又出现新的报错
    #error cpstm8 stm8s_stdperiph_lib\stm8s_stdperiph_driver\inc\stm8s_gpio.h:153 bad #endif
    真的找不出解决办法了,真心向您求助

    回复
    • 2 Responses to “symbol _assert_failed not defined (Debugstm8s_adc1.o )”
      • 打酱油的

        楼主您好,我的stn8s_config.h里是这样的
        #define USE_FULL_ASSERT (1)

        /* Exported macro ------------------------------------------------------------*/
        #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 */

        #endif /* __STM8S_CONF_H */
        这个跟您的不一样,但是根据您的建议更改了#ifdef FULL_ASSERT及后面的语句后又出现新的报错
        #error cpstm8 stm8s_stdperiph_lib\stm8s_stdperiph_driver\inc\stm8s_gpio.h:153 bad #endif
        真的找不出解决办法了,真心向您求助

        回复
        • 过了这么几天,应该解决了吧?看告警像是格式错误,是不是 #endif多了一个?看你这个结尾有俩,多了导致和别的文件冲突了。

          美多多 回复私信