cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F446RE Nucleo - only two UARTs are usable

Posted on November 09, 2015 at 19:09

Hi,

I'm trying to use multiple UARTs on the STM32F446 Nucleo board. I used STM32CubeMX to generate code that initializes all available UARTs and USARTs at 115200 baud and the MCU to run at 180MHz.

void
my_putc(UART_HandleTypeDef* huart, 
char
c) {
while
(!(huart->Instance->SR & USART_FLAG_TXE));
huart->Instance->DR = c;
}
void
my_puts(UART_HandleTypeDef* huart, 
const
char
* s) {
while
(*s) {
my_putc(huart, *s);
++s;
}
}
int
main(
void
) {
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* Configure the system clock */
SystemClock_Config();
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_USART1_UART_Init();
MX_USART2_UART_Init();
MX_USART3_UART_Init();
MX_UART5_Init();
MX_UART4_Init();
MX_USART6_UART_Init();
/* USER CODE BEGIN WHILE */
while
(1) {
my_puts(&huart1, 
''Hello UART1\n''
);
my_puts(&huart2, 
''Hello UART2\n''
);
my_puts(&huart3, 
''Hello UART3\n''
);
my_puts(&huart4, 
''Hello UART4\n''
);
my_puts(&huart5, 
''Hello UART5\n''
);
my_puts(&huart6, 
''Hello UART6\n''
);
}
}
void
SystemClock_Config(
void
) {
RCC_OscInitTypeDef RCC_OscInitStruct;
RCC_ClkInitTypeDef RCC_ClkInitStruct;
__PWR_CLK_ENABLE();
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
RCC_OscInitStruct.HSICalibrationValue = 16;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
RCC_OscInitStruct.PLL.PLLM = 8;
RCC_OscInitStruct.PLL.PLLN = 180;
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
RCC_OscInitStruct.PLL.PLLQ = 2;
RCC_OscInitStruct.PLL.PLLR = 2;
HAL_RCC_OscConfig(&RCC_OscInitStruct);
HAL_PWREx_ActivateOverDrive();
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK | 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_DIV1; 
HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_3);
}

However I only receive output on UART2 and UART3, all other UARTs are silent. When connecting a scope it turns out that the other UARTs are much faster (the yellow line is UART6, the blue line UART3). 0690X00000605awQAA.png Why is that? What can I do to make them usable? They are all initialized in the same way (see usart.c). #stm32f446 #hal #uart
2 REPLIES 2
Posted on November 09, 2015 at 19:24

It works when I use

RCC_OscInitStruct.PLL.PLLN = 160;

instead of

RCC_OscInitStruct.PLL.PLLN = 180;

Does that mean the MCU will only run at 160MHz?
Posted on November 09, 2015 at 22:21

I'm pretty sure APB2 would need to be slower than DIV1, and flash wait states greater than 3, for 180 MHz operation. Review the RM

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..