STM32CubeMX generates HAL library code that does not compile
Hello,
Under linux (project generated by STM32CubeMX), the compiler reports illegal implicit casts from void * to PCD_HandleTypeDef in the HAL libraries.
The problems are in two files: usbd_conf.c and usbd_cdc.c
I solved this by following the example in other HAL sources, by adding explicit type casts for all reported problems like so (line 354 of usbd_conf.c):
hal_status = HAL_PCD_DeInit((PCD_HandleTypeDef*) pdev->pData);
The errors are present in the latest version of the HAL (I updated STM32CubeMX and the project today)
While correcting this I wondered about two things:
1. Why do only these specific files not include the type casts that are included in other HAL library files.
Done by a different programmer / added later to the HAL?
2. Why were these errors not caught by ST?
Perhaps this was not tested under linux or not tested from a freshly generated project?
Or perhaps I am doing something wrong here?
Thanks for your reply and best regards,
John
Example error message:
arm-none-eabi-g++ -c -mcpu=cortex-m3 -mthumb -DUSE_HAL_DRIVER -DSTM32F103xB -IInc -IDrivers/STM32F1xx_HAL_Driver/Inc -IDrivers/STM32F1xx_HAL_Driver/Inc/Legacy -IMiddlewares/ST/STM32_USB_Device_Library/Core/Inc -IMiddlewares/ST/STM32_USB_Device_Library/Class/CDC/Inc -IDrivers/CMSIS/Device/ST/STM32F1xx/Include -IDrivers/CMSIS/Include -O3 -Wall -fdata-sections -ffunction-sections -g -gdwarf-2 -MMD -MP -MF"build/usbd_conf.d" -x c++ -Wa,-a,-ad,-alms=build/usbd_conf.lst Src/usbd_conf.c -o build/usbd_conf.o
Src/usbd_conf.c: In function 'USBD_StatusTypeDef USBD_LL_DeInit(USBD_HandleTypeDef*)':
Src/usbd_conf.c:354:37: error: invalid conversion from 'void*' to 'PCD_HandleTypeDef*' [-fpermissive]
hal_status = HAL_PCD_DeInit(pdev->pData);