STM32CubeF4
STM32CubeF4 copied to clipboard
STM32412G-Discovery BSP : Undefined behavior when `BSP_COM_Init` is called with `COM2`
Setup
- Board : STM32F412G-DISCO
- IDE : VS Code + Platform.io
Describe the bug
The BSP for the STM32F412G-DISCO (Drivers/BSP/STM32412G-Discovery/stm32412g_discovery.c) has a method to initialize the serial communication :
void BSP_COM_Init(COM_TypeDef COM, UART_HandleTypeDef *huart)
According to the documentation, COM can be COM1 or COM2:
* @param COM: COM port to be configured.
* This parameter can be one of the following values:
* COM1
* COM2
* @param huart: Pointer
But actually, only COM1 (which is used for USART2) can be used. Indeed, the number of COM is set to 1:
#define COMn ((uint8_t)1)
and the arrays COM_USART[COMn], COM_TX_PORT[COMn], COM_RX_PORT[COMn], COM_TX_PIN[COMn], COM_RX_PIN[COMn], COM_TX_AF[COMn], COM_RX_AF[COMn] are only defined for a single entry : COM1.
So when BSP_COM_Init is called with COM2 for the COM argument, the result is undefined.
How To Reproduce
- Call
BSP_COM_InitwithCOM2as first argument
Additional context
BSP_COM_Initcurrently returnsvoid, so it can't return an error if called withCOM2. Perhaps it would be good to return aHAL_StatusTypeDefinstead ofvoid. This could also be used to detect other problems during the initialization of the USART.- It was not intuitive to me that
COM1was actually used forUSART2.
Screenshots
n/a
ST Internal Reference: 132859
Hello @supcik,
The issue you reported has been fixed in the frame of version v1.28.0 of the STM32CubeF4 published recently on GitHub. Thank you again for having reported.
With regards,