Skip to main content
Visitor II
September 8, 2019
Solved

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

  • September 8, 2019
  • 2 replies
  • 3808 views

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)

    This topic has been closed for replies.
    Best answer by Tesla DeLorean

    Enable clocks for UART and GPIO involved.

    Configure GPIO pins and association with the UART.​

    2 replies

    Graduate II
    September 8, 2019

    Enable clocks for UART and GPIO involved.

    Configure GPIO pins and association with the UART.​

    Graduate II
    September 8, 2019

    Check peripheral register settings in the debugger​

    jdhAuthor
    Visitor II
    September 8, 2019

    I saw examples that started the clocks, so I added this in accordance:

    __GPIOA_CLK_ENABLE();
    __USART3_CLK_ENABLE();

    to no avail. I was also operating under the assumption that GPIO information would be handled by the HAL using the USART3 definition (a position in the peripheral memory mapping section). Is this incorrect?

    EDIT/UPDATE: I also attempted to replicate the tutorial's pin initialization like so:

    GPIO_InitTypeDef GPIO_InitStruct;
    GPIO_InitStruct.Pin = GPIO_PIN_2|GPIO_PIN_3;
    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
    GPIO_InitStruct.Alternate = GPIO_AF7_USART3;
    HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

    Still nothing, though.

    Graduate II
    September 8, 2019

    Not only adjust HSE frequency, but also make sure HSE bypass is enabled. Confirm correct system frequency with a LED blinking once per second.

    Configure USART baudrate and remember to set the same baudrate in terminal software on a PC side . :)

    jdhAuthor
    Visitor II
    September 9, 2019

    I've confirmed that the frequency is correct with the suggested 1sec blink rate, I've also ensured that the baud rates match on the terminal as well as the code, but I'm still getting gibberish out.

    It appears as though the data line is not actually working correctly, I can reverse the string input and still get the same 'noise' out. Correction: this only occurs within the workbench, Tera Term shows different output for a different string. Strange.

    Another strange clue: Tera Term only shows 2 bytes being received when I send 5 ("BEEF\n"), and what's received is absolute gibberish ("€%").