2015-01-24 10:54 AM
Hi there... Using the non-hal on an STM32F2xx, I can read/write at 3,333,333 BAUD without a problem. When I port the code to STM32F4xx, I am unable to read/write to the USART1 at the same BAUD rate - instead, it times out.
If I change the baud rate to 4,300,000 - it works. If I change it back to 3,333,333 - it doesn't work. Does anyone have an idea of why this could be happening? Here is my non-working code...UART_HandleTypeDef huart1;
int main(void) {
HAL_Init();
__GPIOA_CLK_ENABLE();
__GPIOB_CLK_ENABLE();
__GPIOC_CLK_ENABLE();
GPIO_InitTypeDef GPIO_InitStruct;
// --------------------------------------------------------------------------- LED
GPIO_InitStruct.Pin = GPIO_PIN_15;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
// --------------------------------------------------------------------------- USART 1
/**USART1 GPIO Configuration
PA9 ------> USART1_TX
PA10 ------> USART1_RX
PA11 ------> USART1_CTS
PA12 ------> USART1_RTS
*/
__USART1_CLK_ENABLE();
GPIO_InitStruct.Pin = GPIO_PIN_9 | GPIO_PIN_10;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF7_USART1;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
GPIO_InitStruct.Pin = GPIO_PIN_11 | GPIO_PIN_12;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF7_USART1;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
huart1.Instance = USART1;
huart1.Init.BaudRate = 3333333;
huart1.Init.WordLength = UART_WORDLENGTH_8B;
huart1.Init.StopBits = UART_STOPBITS_1;
huart1.Init.Parity = UART_PARITY_NONE;
huart1.Init.Mode = UART_MODE_TX_RX;
huart1.Init.HwFlowCtl = UART_HWCONTROL_RTS_CTS;
huart1.Init.OverSampling = UART_OVERSAMPLING_8;
HAL_UART_Init(&huart1);
// ---------------------------------------------------------------------------
for (;;) {
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_15, GPIO_PIN_SET);
HAL_Delay(250);
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_15, GPIO_PIN_RESET);
HAL_Delay(250);
HAL_UART_Transmit(&huart1, (uint8_t *)&''Hello'', 5, 1000);
}
}
#uart-usart-stm32f4xx-baud
2015-01-25 06:44 AM
Does the problem manifest if you run the STM32F4 at 120 MHz?
The USART at high baud rates is going to be impacted by the APB speed, whether that's 60, 84 or 90 MHz in this case.Other than that you'll have to wade through the source, and look at the USART/BRR registers, etc.