2026-02-12 5:29 PM - edited 2026-02-12 5:35 PM
my UART settings are as follows:
void USART_Configuration(EUartCom uartCom)
{
USART_Config(uartCom, COM_BAUDRATE[uartCom]);
}
void USART_Config(EUartCom uartCom, uint32_t baudrate)
{
USART_DeInit(COM_USART[uartCom]);
GPIO_InitTypeDef GPIO_InitStructure;
// DE:
GPIO_InitStructure.GPIO_Pin = COM_DE_PIN[uartCom];
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(COM_DE_PORT[uartCom], &GPIO_InitStructure);
GPIO_ResetBits(COM_DE_PORT[uartCom], COM_DE_PIN[uartCom]);
// TX:
GPIO_InitStructure.GPIO_Pin = COM_TX_PIN[uartCom];
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_25MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(COM_TX_PORT[uartCom], &GPIO_InitStructure);
// RX:
GPIO_InitStructure.GPIO_Pin = COM_RX_PIN[uartCom];
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(COM_RX_PORT[uartCom], &GPIO_InitStructure);
// AF:
GPIO_PinAFConfig(COM_TX_PORT[uartCom], COM_TX_PIN_SOURCE[uartCom], COM_AF[uartCom]); // TX
GPIO_PinAFConfig(COM_RX_PORT[uartCom], COM_RX_PIN_SOURCE[uartCom], COM_AF[uartCom]); // RX
// USART
USART_InitTypeDef USART_InitStructure;
USART_InitStructure.USART_BaudRate = baudrate;
USART_InitStructure.USART_WordLength = COM_WORD_LENGTH[uartCom];
USART_InitStructure.USART_StopBits = COM_STOP_BITS[uartCom];
USART_InitStructure.USART_Parity = COM_PARITY[uartCom];
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Init(COM_USART[uartCom], &USART_InitStructure);
// RXNE Enable
USART_ITConfig(COM_USART[uartCom], USART_IT_RXNE, ENABLE);
// IDLE Enable
USART_ITConfig(COM_USART[uartCom], USART_IT_IDLE, ENABLE);
// USART
USART_Cmd(COM_USART[uartCom], ENABLE);
}
UART setting by getting defined value.
uint32_t COM_BAUDRATE[COMn] = {76800, 57600, 38400, 115200};
USART_Configuration(COM0);
USART_TX_DMA_Init(COM0);
USART_SetDE(COM0, serialRx);
USART_Configuration(COM1);
//USART_Config(COM1, 57600);
USART_TX_DMA_Init(COM1);
USART_SetDE(COM1, serialTx);
USART_Configuration(COM2);
USART_TX_DMA_Init(COM2);
USART_SetDE(COM2, serialTx);At this time, 'USART_Configuration' is not set,
but 'USART_Config(COM1, 57600)' is operate OK. ;(
Why is this happening?
This code(USART_Configuration) works on STM32F207VG 144pin is OK, but does't work on 100pin chip.
USART1, 3 is OK.
USART2 is problem;
2026-03-11 3:57 PM
It is based on SPL.
If the order of setting the function is UART2, 1, and 3, 1 is not set. I think the parameter applied to the function is the difference between constant or variable.
2026-03-12 7:19 AM
I don't use SPL, but if you find it does not work as expected, given it's not being maintained, you may be better off not using it, but resort to direct register programming.
JW
2026-03-12 7:27 AM
@waclawek.jan wrote:given [SPL] is not being maintained, you may be better off not using it, but resort to direct register programming.
@liszto or HAL (which replaced the SPL)
2026-03-12 7:59 AM
IMO Cube/LL is more the replacement of SPL than Cube/HAL.
JW
2026-03-12 8:08 AM
Yes, that's another option.
And, of course, both LL and HAL can be used without CubeMX ...
@liszto - See: STM32CubeF2