2026-03-25 10:52 AM
NUCLEO F767ZI, CubeIDE 2.1.1, CubeMX 6.17.0
I'm trying to set up UART with printf()
#include <stdio.h>
UART_HandleTypeDef huart3;
static void MX_USART3_UART_Init(void);
int __io_putchar(int ch)
{
HAL_UART_Transmit(&huart3, (uint8_t *)ch, 1, 10);
return ch;
}
....
// in main
// in while
prinf("UART test\r\n");
// MX generated USART3 init
static void MX_USART3_UART_Init(void)
{
/* USER CODE BEGIN USART3_Init 0 */
/* USER CODE END USART3_Init 0 */
/* USER CODE BEGIN USART3_Init 1 */
/* USER CODE END USART3_Init 1 */
huart3.Instance = USART3;
huart3.Init.BaudRate = 115200;
huart3.Init.WordLength = UART_WORDLENGTH_8B;
huart3.Init.StopBits = UART_STOPBITS_1;
huart3.Init.Parity = UART_PARITY_NONE;
huart3.Init.Mode = UART_MODE_TX_RX;
huart3.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart3.Init.OverSampling = UART_OVERSAMPLING_16;
huart3.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
huart3.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
if (HAL_UART_Init(&huart3) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN USART3_Init 2 */
/* USER CODE END USART3_Init 2 */
}
Clock tree from MX
Output in Tera Term window
TT is set up exactly the same as the UART init in the code.
Anyone know whats going on here?
Solved! Go to Solution.
2026-03-26 7:39 AM - last edited on 2026-03-26 7:44 AM by mƎALLEm
My original code,
HAL_UART_Transmit(&huart3, (uint8_t *)ch, 1, 10);
What it should be,
HAL_UART_Transmit(&huart3, (uint8_t *)&ch, 1, 10);
Notice the & in front of the ch
2026-03-25 10:55 AM - edited 2026-03-25 10:57 AM
Hello,
You have set a wrong HSE clock value to 25MHz:
You need to set it to 8MHz as the ST-LINK-V2 MCO output on that Nucleo board is 8MHz
2026-03-25 10:59 AM
Gibberish on a terminal is almost always due to wrong baud rate.
As @mƎALLEm said, if you enter the wrong value for the HSE clock frequency, then your baud rate will be wrong - as will any other frequencies derived from HSE.
2026-03-25 11:10 AM
Still gibberish
2026-03-25 11:21 AM
Did you regenerate the code, compile it with that config and upload the application to the MCU?
2026-03-25 11:38 AM
Yes
2026-03-25 11:39 AM - edited 2026-03-25 11:41 AM
And what if you select HSI as clock source instead of HSE?:
If it's working, that means definetly you have an issue with HSE, a missing solder bridge on STLINK MCO output path or something similar. If not, you have an issue with TeraTerm UART configuration.
2026-03-25 11:59 AM
No not working with HSI either
Settings in TT are the same as in the USART3 init. (I've also tried RealTerm & get the same gibberish there too)
2026-03-25 12:30 PM - edited 2026-03-25 12:33 PM
Configure the data lenght in Tera term to 7 bit instead of 8 bit.
This is the example from CubeF7 https://github.com/STMicroelectronics/STM32CubeF7/blob/master/Projects/STM32F767ZI-Nucleo/Examples/UART/UART_Printf/
that suggests in its readme file that you need to set the datalenght to 7 bit:
This is what was said in a comment the example code: Word Length = 8 Bits (7 data bit + 1 parity bit)
/* UART configured as follows:
- Word Length = 8 Bits (7 data bit + 1 parity bit) :
BE CAREFUL : Program 7 data bits + 1 parity bit in PC HyperTerminal
- Stop Bit = One Stop bit
- Parity = ODD parity
- BaudRate = 9600 baud
- Hardware flow control disabled (RTS and CTS signals) */
UartHandle.Instance = USARTx;
UartHandle.Init.BaudRate = 9600;
UartHandle.Init.WordLength = UART_WORDLENGTH_8B;
UartHandle.Init.StopBits = UART_STOPBITS_1;
UartHandle.Init.Parity = UART_PARITY_ODD;
UartHandle.Init.HwFlowCtl = UART_HWCONTROL_NONE;
UartHandle.Init.Mode = UART_MODE_TX_RX;
UartHandle.Init.OverSampling = UART_OVERSAMPLING_16;
if (HAL_UART_Init(&UartHandle) != HAL_OK)
{
/* Initialization Error */
Error_Handler();
}
This is apart of the wrong HSE frequency value you set in CubeMx: 25MHz instead of 8MHz (the issue I raised in a previous post).
Hope that helps
2026-03-25 12:54 PM
Sorry but this doesn't solve the issue either.
Even reconfiguring the UART with an odd partity bit & changing the corresponding settings in TT as suggested, I'm still getting gibberish.