STM32F0xx的头文件USE_STDPERIPH_DRIVER宏的用途,可自定义
时间:10-02
整理:3721RD
点击:
写在前面——如果知道了宏的使用目的,用户完全可以根据自己的喜好,随意更改之。
ST公司提供STM32F0xx的头文件STM32F0xx.h,编译器都要定义一个宏:USE_STDPERIPH_DRIVER,如果不定义它 ---- 照ST公司的做法,就会出现问题,如
实际上,打开头文件研究一下就知道,关系到这个宏的地方只有两处:
第一处是:
#if !defined USE_STDPERIPH_DRIVER
/**
* @brief Comment the line below if you will not use the peripherals drivers.
In this case, these drivers will not be included and the application code will
be based on direct access to peripherals registers
*/
/*#define USE_STDPERIPH_DRIVER*/
#endif /* USE_STDPERIPH_DRIVER */
第二处是:
#ifdef USE_STDPERIPH_DRIVER
#include "stm32f0xx_conf.h"
#endif
大家一看就应该明白,使用这个宏的目的只有一个,就是把头文件stm32f0xx_conf.h包含进来。
而stm32f0xx_conf.h头文件的除了包含所有硬件资源的头文件外,还包含有一个宏定义:
#include "stm32f0xx_adc.h"
#include "stm32f0xx_cec.h"
#include "stm32f0xx_crc.h"
……
/* 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 */
ST公司提供STM32F0xx的头文件STM32F0xx.h,编译器都要定义一个宏:USE_STDPERIPH_DRIVER,如果不定义它 ---- 照ST公司的做法,就会出现问题,如
实际上,打开头文件研究一下就知道,关系到这个宏的地方只有两处:
第一处是:
#if !defined USE_STDPERIPH_DRIVER
/**
* @brief Comment the line below if you will not use the peripherals drivers.
In this case, these drivers will not be included and the application code will
be based on direct access to peripherals registers
*/
/*#define USE_STDPERIPH_DRIVER*/
#endif /* USE_STDPERIPH_DRIVER */
第二处是:
#ifdef USE_STDPERIPH_DRIVER
#include "stm32f0xx_conf.h"
#endif
大家一看就应该明白,使用这个宏的目的只有一个,就是把头文件stm32f0xx_conf.h包含进来。
而stm32f0xx_conf.h头文件的除了包含所有硬件资源的头文件外,还包含有一个宏定义:
#include "stm32f0xx_adc.h"
#include "stm32f0xx_cec.h"
#include "stm32f0xx_crc.h"
……
/* 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 */