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.
Right click and see where it's defined.
Then look at what include files it's actually using for dependencies, and change the search path, or ordering, if appropriate.
Hi Westonsupermare,
I right click that type of member in struct def in ADC.h. It is able to go to DMA.h where the original struct is defined.
I am not clear about how to change the path or ordering like you said. What do I do?
Thank you.
Aren't the include paths under the Options for the C/C++ compiler?
Half suspect it isn't including the file you think, or has some circular references.
Try naming the file you want to use more uniquely.
The file is in the folder of include paths set in options. I have only two header files...
Two things: 1) Correct file included? 2) File included in the correct order?
Order of directories in the include search path is almost certainly irrelevant here.
The problem is much more likely to be that either
a) that typedef in DMA.h comes before that of the definition of the type(s) it uses, or b) there is a cyclic dependency of header files.
For both problems, the most important check is to have the compiler generate preprocessor output to a file, and then look at that very closely: what is defined where, and in which order?
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?
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.