stm8 IAR中使用固件库

stm8s标准固件库(STSW-STM8069)下载,http://www.st.com/web/en/catalog/tools/PF258009

首先,需要下载固件库相关文件

在固件库里面,有以下东西比较重要:

 

 这里面是外设的相关.c与.h文件,也是我们固件库的主要使用部分,以及包括stm8s.h这个标准库头文件。

然后还有以下三个文件,也要找到,放入工程目录下即可。放入工程目录的好处是不用添加其文件所在位置。

 

 然后在project-options-c/c++ complier-preprocessor中的additional include directories中添加固件库相关.c与.h文件所在的目录,$PROJ_DIR$表示当前工作目录。

 

 在这里我们还要告诉以下我们使用的是什么系列单片机,如上图Defined symbols所示。

之后便在工程中右键,添加相关需要使用的外设的固件库.c文件到工程中即可开始使用。我这里使用了时钟,以及IO这两个固件库。

 

void assert_failed(u8* file, u32 line);这个函数只是在“stm8s_conf.h”这个文件里面声
明,用来在返回值验证出错的时候调用,所以还需要在一个恰当的地方将这个函数实现。
一般在“main.c”中插入已下代码:

#ifdef USE_FULL_ASSERT

/**
  * @brief  Reports the name of the source file and the source line number
  *   where the assert_param error has occurred.
  * @param file: pointer to the source file name
  * @param line: assert_param error line source number
  * @retval : None
  */
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)
  {
  }
}
#endif

 

posted @ 2021-03-24 15:31  菜芽caiya  阅读(363)  评论(0编辑  收藏  举报