Electronic – Cube IDE : Error: unknown type name ‘HAL_StatusTypeDef’

armembeddedststm32stm32cubemx

I am taking code from a stm32f0 series and trying to convert it to a stm32l4 series dev kit. I have already changed the necessary addresses and include files that I needed to migrate, but I keep on getting the following errors in the stm32l4xx_hal_uart Files:

../Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal.h:610:1: error: unknown type name 'HAL_StatusTypeDef'; did you mean 'HAL_RTCStateTypeDef'?
HAL_StatusTypeDef HAL_DeInit(void);
^~~~~~~~~~~~~~~~~

The error appears by this segment of code:

HAL_StatusTypeDef HAL_HalfDuplex_Init(UART_HandleTypeDef *huart);

I have already defined the HAL_UART_MODULE_ENABLED in the stm32l4xx_hal_conf.h and nothing has changed.

What is the cause of this and how can I fix it?

Best Answer

I just got the same issue but with an STM32F407 microcontroller. Suddently, the build broke and there were 102 errors saying that HAL_StatusTypeDef was unknown. I followed the path to all the includes, and what I saw is that "stm32f4xx_hal_def.h" includes "stm32f4xx.h", which indirectly re-includes "stm32f4xx_hal_def.h" for each device you have enabled in "stm32f4xx_hal_conf.h". Except that each include of "stm32f4xx_hal_conf.h" includes again "stm32f4xx_hal_def.h", but this will fail, as the #define __STM32F4xx_HAL_DEF guards the file of being included twice ! So the conclusion for me was to always include "stm32f4xx.h", and not any intermediate file, as all these circular includes are calling for trouble !