Question
Is there a potential bug in HAL_StatusTypeDef enum definition?
typedef enum
{
HAL_OK = 0x00U,
HAL_ERROR = 0x01U,
HAL_BUSY = 0x02U,
HAL_TIMEOUT = 0x03U,
} HAL_StatusTypeDef;This is the actual defintion of the HAL_StatusTypeDef. Other status codes are defined in other modules headers like this:
#define HAL_CAN_ERROR_TIMEOUT (0x00020000U)In System Workbench, using GCC, this leads to the following warning, as soon as you check against that specific ERROR:
...Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_can.h:269:39: warning: large integer implicitly truncated to unsigned type [-Woverflow]At first, it is only a warning but I would expect, that it will lead to wired problems, if you try to handle errors correctly.
I suggest, simply adding a dummy value to the enum typedef to force GCC to choose an integer type of the appropriate size like this in stm32f4xx_hal_def.h:
typedef enum
{
HAL_OK = 0x00U,
HAL_ERROR = 0x01U,
HAL_BUSY = 0x02U,
HAL_TIMEOUT = 0x03U,
HAL_STATUS_MAX = 0xFFFFFFFFU
} HAL_StatusTypeDef;