2022-04-01 06:22 AM
Hi all,
I've tried every example I can find to send data to a terminal using UART on my Nucleo 144. Every time the code builds fine but there is never anything on the terminal, and the code doesn't get stuck anywhere it runs fine.
Solved! Go to Solution.
2022-04-01 07:00 AM
On this Nucleo board, communication between the target STM32L5
and the ST-LINK is enabled using LPUART1, to support the Virtual COM port.
Associated GPIO are as in your hal msp file PG7 and PG8 for TX/RX.
Is your terminal configured in same way than your LPUART1 (BaudRate = 209700; WordLength 7Bits, 1 StopBit, No Parity) ?
Default value used by MX for baudrate might need to be updated, depending on how is configured your hyperterminal open on Virtual COM port ...
Regards
2022-04-01 06:32 AM
Hello @JRich.7
What nucleo board are you using ?
If you generate your project using CubeMX, TX/RX pins associated to the U(S)ART instance you are using, are expected to be initialised in the stm32XXxx_hal_msp.c file (in the HAL_UART_MspInit() function). Please make sure these GPIO are corresponding to those you expect to use on your Nucleo board.
Are you connecting your board to the terminal using VCP ?
Regards
2022-04-01 06:39 AM
I'm using L4R5ZI-P. I'll attach the HAL_UART_MspInit() function below, I think it's correct but not sure how to be certain. I've tried both using a command shell console within CubeIDE and also with PuTTY. Thanks for your help!
/**
* @brief UART MSP Initialization
* This function configures the hardware resources used in this example
* @param huart: UART handle pointer
* @retval None
*/
void HAL_UART_MspInit(UART_HandleTypeDef* huart)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
if(huart->Instance==LPUART1)
{
/* USER CODE BEGIN LPUART1_MspInit 0 */
/* USER CODE END LPUART1_MspInit 0 */
/** Initializes the peripherals clock
*/
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_LPUART1;
PeriphClkInit.Lpuart1ClockSelection = RCC_LPUART1CLKSOURCE_PCLK1;
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
{
Error_Handler();
}
/* Peripheral clock enable */
__HAL_RCC_LPUART1_CLK_ENABLE();
__HAL_RCC_GPIOG_CLK_ENABLE();
HAL_PWREx_EnableVddIO2();
/**LPUART1 GPIO Configuration
PG7 ------> LPUART1_TX
PG8 ------> LPUART1_RX
*/
GPIO_InitStruct.Pin = GPIO_PIN_7|GPIO_PIN_8;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF8_LPUART1;
HAL_GPIO_Init(GPIOG, &GPIO_InitStruct);
/* USER CODE BEGIN LPUART1_MspInit 1 */
/* USER CODE END LPUART1_MspInit 1 */
}
else if(huart->Instance==USART2)
{
/* USER CODE BEGIN USART2_MspInit 0 */
/* USER CODE END USART2_MspInit 0 */
/** Initializes the peripherals clock
*/
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART2;
PeriphClkInit.Usart2ClockSelection = RCC_USART2CLKSOURCE_PCLK1;
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
{
Error_Handler();
}
/* Peripheral clock enable */
__HAL_RCC_USART2_CLK_ENABLE();
__HAL_RCC_GPIOD_CLK_ENABLE();
/**USART2 GPIO Configuration
PD3 ------> USART2_CTS
PD4 ------> USART2_RTS
PD5 ------> USART2_TX
PD6 ------> USART2_RX
*/
GPIO_InitStruct.Pin = GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF7_USART2;
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
/* USER CODE BEGIN USART2_MspInit 1 */
/* USER CODE END USART2_MspInit 1 */
}
else if(huart->Instance==USART3)
{
/* USER CODE BEGIN USART3_MspInit 0 */
/* USER CODE END USART3_MspInit 0 */
/** Initializes the peripherals clock
*/
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART3;
PeriphClkInit.Usart3ClockSelection = RCC_USART3CLKSOURCE_PCLK1;
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
{
Error_Handler();
}
/* Peripheral clock enable */
__HAL_RCC_USART3_CLK_ENABLE();
__HAL_RCC_GPIOC_CLK_ENABLE();
/**USART3 GPIO Configuration
PC4 ------> USART3_TX
PC5 ------> USART3_RX
*/
GPIO_InitStruct.Pin = GPIO_PIN_4|GPIO_PIN_5;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF7_USART3;
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
/* USER CODE BEGIN USART3_MspInit 1 */
/* USER CODE END USART3_MspInit 1 */
}
}
2022-04-01 07:00 AM
On this Nucleo board, communication between the target STM32L5
and the ST-LINK is enabled using LPUART1, to support the Virtual COM port.
Associated GPIO are as in your hal msp file PG7 and PG8 for TX/RX.
Is your terminal configured in same way than your LPUART1 (BaudRate = 209700; WordLength 7Bits, 1 StopBit, No Parity) ?
Default value used by MX for baudrate might need to be updated, depending on how is configured your hyperterminal open on Virtual COM port ...
Regards
2022-04-01 07:56 AM
Thank you! That fixed it :D