We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hi,
I am trying to use HAL driver for STM32L053C8 discovery board. In DMA.h I defined:
typedef struct { DMA_Channel_TypeDef *Instance; /*!< Register base address */ DMA_InitTypeDef Init; /*!< DMA communication parameters */ __IO DMA_StateTypeDef State; /*!< DMA transfer state */ void *Parent; /*!< Parent object state */ //void (* XferCpltCallback)( struct __DMA_HandleTypeDef * hdma); /*!< DMA transfer complete callback */ //void (* XferHalfCpltCallback)( struct __DMA_HandleTypeDef * hdma); /*!< DMA Half transfer complete callback */ //void (* XferErrorCallback)( struct __DMA_HandleTypeDef * hdma); /*!< DMA transfer error callback */ }DMA_HandleTypeDef;
then in ADC.h I include that DMA.h file but after compilation, the compiler reports: ..\Inc\ADC.h(127): error: #20: identifier "DMA_HandleTypeDef" is undefined DMA_HandleTypeDef *DMA_Handle; /*!< Pointer DMA Handler */ ..\Src\DMA.c: 0 warnings, 1 error
Actually there is no red cross on the right of DMA_HandleTypeDef in Keil uvision5 IDE in ADC.h file.
typedef struct __ADC_HandleTypeDef { ADC_TypeDef *Instance; /*!< Register base address */ ADC_InitTypeDef Init; /*!< ADC required parameters */ DMA_HandleTypeDef *DMA_Handle; /*!< Pointer DMA Handler */ __IO ADC_StateTypeDef State; /*!< ADC communication state */ //__IO uint32_t ErrorCode; /*!< ADC Error code */ }ADC_HandleTypeDef;
I dont know the reason why that happenes. Can anyone help me? Thank you.
Rebuild target 'STM32L053C8_Discovery' compiling system_stm32l0xx.c... assembling startup_stm32l053xx.s... compiling main.c... compiling stm32l0xx_it.c... compiling Memory.c... compiling ADC.c... compiling DMA.c... ..\Inc\ADC.h(127): error: #20: identifier "DMA_HandleTypeDef" is undefined DMA_HandleTypeDef *DMA_Handle; /*!< Pointer DMA Handler */ ..\Src\DMA.c: 0 warnings, 1 error "STM32L053C8_Discovery\STM32L053C8_Discovery.axf" - 1 Error(s), 0 Warning(s). Target not created. Build Time Elapsed: 00:00:02
Here is the output of compilation. It seems that ADC is compiled ealier than DMA. Maybe that is the reason? How to change that order?
Thank you.
It seems that ADC is compiled ealier than DMA.
No, that is not the reason.
The problem is that DMA.c has an #include of ADC.h in it, but no (fully working) #include of DMA.h before that. As ADC.h uses a type from DMA.h, it should normally #include "DMA.h" to make sure that type is known. It doesn't, and that's why you get that error message.
Forget about search paths, or the order of files in the project. You need to worry about the order of #includes in your source, and in the #include's files themselves.
It is the order of include file in ADC.c.
Problem solved.
Thank you Hans-Bernhard Broeker.