我在互联网上找不到任何解决方案,这就是我在这里问的原因。
我的Led_TypeDef变量在MyDriverConfig.h中未定义。首先,我在MyApplications.h中定义了:
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __MYAPPLICATIONS_H
#define __MYAPPLICATIONS_H
#ifdef __cplusplus
extern "C" {
#endif
#include "main.h"
typedef enum
{
LED1 = 0,
LED_GREEN = LED1
} Led_TypeDef;
#define LEDn 1
#define LED1_PIN GPIO_PIN_0
#define LED1_GPIO_PORT GPIOB
#define LED1_GPIO_CLK_ENABLE() __GPIOA_CLK_ENABLE()
#define LED1_GPIO_CLK_DISABLE() __GPIOA_CLK_DISABLE()
#define LEDx_GPIO_CLK_ENABLE(__INDEX__) (((__INDEX__) == 0) ? LED1_GPIO_CLK_ENABLE() : 0)
#define LEDx_GPIO_CLK_DISABLE(__INDEX__) (((__INDEX__) == 0) ? LED1_GPIO_CLK_DISABLE() : 0)
void LED_On(Led_TypeDef Led);
void LED_Off(Led_TypeDef Led);
void LED_Toggle(Led_TypeDef Led);
void MCU_Configuration(void);
#endif /* __MYAPPLICATIONS_H */
然后,在MyConfigDriver.h中:
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __MYCONFIG_H
#define __MYCONFIG_H
#ifdef __cplusplus
extern "C" {
#endif
#include "main.h"
void SystemClock_Config(void);
void MX_LED_Init(Led_TypeDef Led);
void MX_CAN_Init(void);
void MX_I2C1_Init(void);
void MX_SPI1_Init(void);
void MX_USART2_UART_Init(void);
#endif /* __MYCONFIG_H */
我认为它很明确,因为我的main.h包括所有:
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __MAIN_H
#define __MAIN_H
#include "stm32f0xx_hal.h"
#include "MyDriverConfig.h"
#include "MyApplications.h"
#endif /* __MAIN_H */
这些是我得到的错误:
MyApplications.c
Error[Pe020]: identifier "Led_TypeDef" is undefined C:\Inc\MyDriverConfig.h 24
Error while running C/C++ Compiler
main.c
Error[Pe020]: identifier "Led_TypeDef" is undefined C:\Inc\MyDriverConfig.h 24
Error while running C/C++ Compiler
错误总数:2 警告总数:0
当我在MyDriverConfig.h中包含MyApplication.h时,我得到了这个:
Updating build tree...
MyApplications.c
Error[Pe020]: identifier "Led_TypeDef" is undefined C:\Users\Inc\MyDriverConfig.h 25
Error while running C/C++ Compiler
main.c
MyDriverConfig.c
Total number of errors: 1
Total number of warnings: 0
当我在MyDriverConfig.h中使用Led_TypDef一次时,我不理解MyApplications时,我不明白为什么会出现两个错误。
我也尝试过添加 extern Led_TypeDef Led; 在MyApplication.h中没有任何结果。
答案 0 :(得分:0)
好的,谢谢。对于那些可能感兴趣的人来说,这种方式运作良好:
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __MAIN_H
#define __MAIN_H
#include "stm32f0xx_hal.h"
#include "MyDriverConfig.h"
#include "MyApplications.h"
#endif /* __MAIN_H */
现在在MyDriverConfig.h
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __MYCONFIG_H
#define __MYCONFIG_H
#ifdef __cplusplus
extern "C" {
#endif
#include "stm32f0xx_hal.h"
#include "MyApplications.h"
extern GPIO_TypeDef* LED_PORT[LEDn];
extern const uint16_t LED_PIN[LEDn];
[...]
void MX_LED_Init(Led_TypeDef Led);
#endif /* __MYCONFIG_H */
然后,在MyDriverConfig.c
中 /* Includes ------------------------------------------------------------------*/
#include "MyDriverConfig.h"
[...]
void MX_LED_Init(Led_TypeDef Led)
{
[...]
}
然后,在MyApplications.h中
#ifndef __MYAPPLICATIONS_H
#define __MYAPPLICATIONS_H
#ifdef __cplusplus
extern "C" {
#endif
#include "stm32f0xx_hal.h"
typedef enum
{
LED1 = 0,
LED_GREEN = LED1
} Led_TypeDef;
[...]
void LED_On(Led_TypeDef Led);
#endif /* __MYAPPLICATIONS_H */
最后在MyApplications.c中
#include "MyApplications.h"
#include "MyDriverConfig.h"
GPIO_TypeDef* LED_PORT[LEDn] = {LED1_GPIO_PORT};
const uint16_t LED_PIN[LEDn] = {LED1_PIN};
代码并不完美,因为还有一些循环包含:stm32f0xx_hal.h但它编译得很好。