cancel
Showing results for 
Search instead for 
Did you mean: 

Can't get the ST-Link-routed USART communication to work on the STM32F767ZI

jdh
Associate II

I'm trying to print output to the console in the STM32 work bench, but I can't seem to get anything out, and with my lack of a logic analyzer the best I can do is confirm my calls to HAL_UART_Transmit return HAL_OK. Below is the minimal example I'm attempting:

int main(void)
{
	HAL_Init();
 
	UART_HandleTypeDef huart3;
	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;
	HAL_UART_Init(&huart3);
 
	HAL_UART_Transmit(&huart3, (uint8_t*)"HELLO\n", 6, 0xFFFF);
 
        // Confirms that execution passed the transmit
	BSP_LED_Init(LED2);
	for(;;){
		BSP_LED_Toggle(LED2);
		HAL_Delay(1);
		BSP_LED_Toggle(LED2);
		HAL_Delay(9);
	}
	BSP_LED_DeInit(LED2);
}

I've attempted to use both 9600 and 115200 baud across USART1, 2, and 3 (I found documentation that says 3 should be correct for routing to the ST-Link's virtual console). I'm also trying to maintain as minimal a toolset as possible (MXCube didn't work for some reason and I don't want to run mbedOS, just FreeRTOS).

I imagine I must be missing some sort of initialization or configuration, and if anyone could point towards some good documentation as well I would be extremely grateful. The best I can find so far is the unified Nucleo board reference and it doesn't contain much useful information about getting UART or USART working.

EDIT (some details):

Dev machine OS: Windows 10

Dev board: STM32F767ZI Nucleo

IDE/Debugger: System Workbench for STM32

Toolchain: Ac6 STM32 MCU GCC

Third-party libraries: FreeRTOS included but not called (yet)

12 REPLIES 12

Got to watch those auto/local variables. Back in the SPL days ST used to have global variables for everything, and the startup initialized them, now they frequently use auto/local ones, and those can definitely bite you.

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

I wish I could say this is the first time I've made such a hilariously basic mistake, hell I wish I could say I've only made the mistake while working on hobbyist projects.

Hopefully it sticks this time, though, I have to remember that if I'm not populating every part of a struct on the stack I need to = { 0 } that sucker right away.

Either way, thank you for all the help!

> Back in the SPL days ST used to have global variables for everything, and the startup initialized them, now they frequently use auto/local ones

Maybe because of those newer MCUs with several RAM regions. The standard GNU startup files only support one block of initialized data - if I understand correctly.

If there's several such blocks, you have to tweak the init code in the startup.

In this situation using any static/global initialized data is dangerous.

-- pa