AnsweredAssumed Answered

STM32Cube F4 V1.5.0 -- suggested code improvement

Question asked by Mike Duffy on Apr 23, 2015
The function (as defined in usbd_cdc.c)

     uint8_t  USBD_CDC_TransmitPacket(USBD_HandleTypeDef *pdev)

in fact returns values of type USBD_StatusTypeDef, not uint8_t.

This causes type collisions, and IAR warnings of the form "enumerated type mixed with another type" if one does something like this:

     USBD_HandleTypeDef      handle;
     USBD_StatusTypeDef     result;
     result = USBD_CDC_TransmitPacket(&handle)

It would be nice if the types returned by a function match the return type of the function. :)

Affected files are

...\STM32Cube_FW_F4_V1.5.0\Middlewares\ST\STM32_USB_Device_Library\Class\CDC\Src\usbd_cdc.c (definition)
...\STM32Cube_FW_F4_V1.5.0\Middlewares\ST\STM32_USB_Device_Library\Class\CDC\Inc\usbd_cdc.h (declaration)

This may occur elsewhere in the HAL, but this is one I have encountered.  I did not perform an exhaustive check.  I presume a lint-like checker would locate similar problems if they exist.

This problem exists in 1.4.0 as well.