cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F429 Cannot set baud rate less then 9600

egoltzman
Senior
Posted on January 08, 2016 at 22:58

I have a target board that is based on theSTM324x9I_EVAL, I need to use 2 UARTS, I set up UART4 and USART1 both at 1200 BAUD, my clock is 180MHz with HSE of 25MHz.

The strange thing I'm facing is that (from application reason) I need to use 1200 BAUD on those UARTs, the UART4 is set and working as expected but the USART1 when setting to baud rate higher then 9600 worked fine and if I try to use lower baud rates the output is 9600 for setup of 1200, 4800 for setup of 600, 2400 for 300 and when I tried 150 I got unreadable data. What is going on? What am I'm doing wrong? This is my setup code:

OperationalUartHandle.Instance = USART1;
OperationalUartHandle.Init.BaudRate = 1200;
OperationalUartHandle.Init.WordLength = UART_WORDLENGTH_8B;
OperationalUartHandle.Init.StopBits = UART_STOPBITS_1;
OperationalUartHandle.Init.Parity = UART_PARITY_NONE;
OperationalUartHandle.Init.HwFlowCtl = UART_HWCONTROL_NONE;
OperationalUartHandle.Init.Mode = UART_MODE_TX_RX;
OperationalUartHandle.Init.OverSampling = UART_OVERSAMPLING_16;
if
(HAL_UART_Init(&OperationalUartHandle) != HAL_OK){
Error_Handler();
}

And the MSP:

__USART1_CLK_ENABLE();
GPIO_InitStruct.Pin = USARTx_TX_PIN;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
GPIO_InitStruct.Alternate = USARTx_TX_AF;
HAL_GPIO_Init(USARTx_TX_GPIO_PORT, &GPIO_InitStruct);
GPIO_InitStruct.Pin = USARTx_RX_PIN;
GPIO_InitStruct.Alternate = USARTx_RX_AF;
HAL_GPIO_Init(USARTx_RX_GPIO_PORT, &GPIO_InitStruct);

Thanks #stm32f4-uart
4 REPLIES 4
Posted on January 08, 2016 at 23:35

You might have to drop the APB clocks down lower. The baud rate divider register is only 16-bits as I recall.

90,000,000 / 65,536 = 1,373.29

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
egoltzman
Senior
Posted on January 09, 2016 at 00:10

Thank you Clive,

I tried you suggestion and change the PLLN to 320 to get a 160M and 80M on the APB, is that what I should do? I never change the clock on my system. When I did that, out of the blue I got a freeRTOS (8.1.2) stack overflow fail, any idea why? For the reference, This is my initial clock config function. Thank you for your help! Eyal

static
void
SystemClock_Config(
void
)
{
RCC_ClkInitTypeDef RCC_ClkInitStruct;
RCC_OscInitTypeDef RCC_OscInitStruct;
/* Enable Power Control clock */
__HAL_RCC_PWR_CLK_ENABLE();
/* The voltage scaling allows optimizing the power consumption when the device is 
clocked below the maximum system frequency, to update the voltage scaling value 
regarding system frequency refer to product datasheet. */
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
/* Enable HSE Oscillator and activate PLL with HSE as source */
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
RCC_OscInitStruct.PLL.PLLM = 25;
RCC_OscInitStruct.PLL.PLLN = 360;
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
RCC_OscInitStruct.PLL.PLLQ = 7;
HAL_RCC_OscConfig(&RCC_OscInitStruct);
/* Activate the Over-Drive mode */
HAL_PWREx_EnableOverDrive(); 
/* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 
clocks dividers */
RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4; 
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2; 
HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5);
}

Posted on January 09, 2016 at 01:35

You don't need to change the PLL, you need to change the APBxCLKDividers

I would suggest you get out a scope and verify the bit timings when sending 0x55 characters.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
egoltzman
Senior
Posted on January 09, 2016 at 09:52

Thanks!

Changing APB2CLKDivider to RCC_HCLK_DIV4 did the trick, I had some mystical attitude for those values...

Eyal