Skip to main content
SP.3
Associate II
October 4, 2019
Solved

LPUART configuration in STM32L4R5ZI board

  • October 4, 2019
  • 2 replies
  • 2214 views

Hi,

I am using STM32l4 nucleo-144 board to create an example application for LPUART1 communication.

Part number - STM32L4R5ZI

I have configured the GPIO and required clocks. But still not able to do a successful transaction.

		/* Enable Power Clock */
		LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_PWR);
 
		/* Ensure that HSI is wake-up system clock */
		LL_RCC_SetClkAfterWakeFromStop(LL_RCC_STOP_WAKEUPCLOCK_HSI);
 
		/*##### -1- Enable peripherals and GPIO Clocks #####*/
		/* Enable GPIO TX/RX clock */
		LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOG);
 
		/* Configure TX Pin as : Alternate function, High Speed, PushPull, Pull up */
		LL_GPIO_SetPinMode(GPIOG, LL_GPIO_PIN_7, LL_GPIO_MODE_ALTERNATE);
		LL_GPIO_SetAFPin_8_15(GPIOG, LL_GPIO_PIN_7, LL_GPIO_AF_8);
		LL_GPIO_SetPinSpeed(GPIOG, LL_GPIO_PIN_7, LL_GPIO_SPEED_FREQ_VERY_HIGH);
		LL_GPIO_SetPinOutputType(GPIOG, LL_GPIO_PIN_7, LL_GPIO_OUTPUT_PUSHPULL);
		LL_GPIO_SetPinPull(GPIOG, LL_GPIO_PIN_7, LL_GPIO_PULL_NO);
 
		/* Configure RX Pin as : Alternate function, High Speed, PushPull, Pull up */
		LL_GPIO_SetPinMode(GPIOG, LL_GPIO_PIN_8, LL_GPIO_MODE_ALTERNATE);
		LL_GPIO_SetAFPin_8_15(GPIOG, LL_GPIO_PIN_8, LL_GPIO_AF_8);
		LL_GPIO_SetPinSpeed(GPIOG, LL_GPIO_PIN_8, LL_GPIO_SPEED_FREQ_VERY_HIGH);
		LL_GPIO_SetPinOutputType(GPIOG, LL_GPIO_PIN_8, LL_GPIO_OUTPUT_PUSHPULL);
		LL_GPIO_SetPinPull(GPIOG, LL_GPIO_PIN_8, LL_GPIO_PULL_NO);
 
		/* Enable SPI clock */
		/* Initialize LPUART instance according to parameters defined in initialization structure */
		LL_LPUART_Init(LPUART1, &nucleoLpuartStruct);
 
		/* Set the wake-up event type : specify wake-up on RXNE flag */
		LL_LPUART_SetWKUPType(LPUART1, LL_LPUART_WAKEUP_ON_RXNE);
 
		/*##### -2- Configure peripheral GPIO #####*/
		LL_APB1_GRP2_EnableClock(LL_APB1_GRP2_PERIPH_LPUART1);
 
		/* Set LPUART1 clock source as HSI */
		LL_RCC_SetLPUARTClockSource(LL_RCC_LPUART1_CLKSOURCE_HSI);
 
		/*##### -3- NVIC Configuration for LPUART1 interrupts #####*/
		/* - Set priority for LPUART1_IRQn */
		/* - Enable LPUART1_IRQn */
		NVIC_SetPriority(LPUART1_IRQn, 0);
		NVIC_EnableIRQ(LPUART1_IRQn);
 
 LL_LPUART_Enable(LPUART1);

Is there any example code available for LPUART of STM32L4R5ZI board ?

Thanks & Regards,

Shanmathi P

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

I imagine I could find or create an example if I looked.

For this board​ you will need to enable VDDIO for GPIO G to work.

2 replies

Tesla DeLorean
Tesla DeLoreanBest answer
Guru
October 4, 2019

I imagine I could find or create an example if I looked.

For this board​ you will need to enable VDDIO for GPIO G to work.

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
SP.3
SP.3Author
Associate II
October 4, 2019

Hi Clive,

I have added LL_PWR_EnableVddIO2(); API call.

Still communication is not success.

It would be great if you could share the example code for this board.

Tesla DeLorean
Guru
October 4, 2019

I'm not using LL, but this is what works for me.

 /* IOSV bit MUST be set to access GPIO port G[2:15] */
 __HAL_RCC_PWR_CLK_ENABLE();
 HAL_PWREx_EnableVddIO2();
 
//****************************************************************************
 
void LPUART1_Init(void)
{
 GPIO_InitTypeDef GPIO_InitStruct = { 0 };
 
 __LPUART1_CLK_ENABLE();
 __GPIOG_CLK_ENABLE();
 
 /* UART RX/TX GPIO pin configuration */
 GPIO_InitStruct.Pin = GPIO_PIN_7 | GPIO_PIN_8;
 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
 GPIO_InitStruct.Pull = GPIO_PULLUP;
 GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
 GPIO_InitStruct.Alternate = GPIO_AF8_LPUART1;
 
 HAL_GPIO_Init(GPIOG, &GPIO_InitStruct);
 
 /*## Configure the UART peripheral ######################################*/
 /* Put the USART peripheral in the Asynchronous mode (UART Mode) */
 /* UART1 configured as follow:
 - Word Length = 8 Bits
 - Stop Bit = One Stop bit
 - Parity = NO parity
 - BaudRate = 115200 baud
 - Hardware flow control disabled (RTS and CTS signals) */
 UartHandle.Instance = LPUART1;
 
 UartHandle.Init.BaudRate = 115200;
 UartHandle.Init.WordLength = UART_WORDLENGTH_8B;
 UartHandle.Init.StopBits = UART_STOPBITS_1;
 UartHandle.Init.Parity = UART_PARITY_NONE;
 UartHandle.Init.HwFlowCtl = UART_HWCONTROL_NONE;
 UartHandle.Init.Mode = UART_MODE_TX_RX;
 
 UartHandle.Init.OverSampling = UART_OVERSAMPLING_16;
#ifdef UART_ONE_BIT_SAMPLE_DISABLE
 UartHandle.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
#endif
 
 if (HAL_UART_Init(&UartHandle) != HAL_OK)
 {
 /* Initialization Error */
 Error_Handler();
 }
 
// HAL_NVIC_SetPriority(LPUART1_IRQn, 1, 0);
// HAL_NVIC_EnableIRQ(LPUART1_IRQn);
}
 
//****************************************************************************

The availability of LL specific examples for the board is low, you could fund some work if you need some.

If think you enable the LPUART1 clock too late in your original post

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
Tesla DeLorean
Guru
October 4, 2019

Enable the LPUART1 clock before initializing it. Perhaps move both clock enables (GPIOG and LPUART1) to the top.

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
SP.3
SP.3Author
Associate II
October 10, 2019

Thanks @Community member​ .

I am now able to send data via LPUART successfully, after implementing the above suggestions.

SP.3
SP.3Author
Associate II
October 15, 2019

Hi @Community member​ ,

The data transmission and reception is fine when connected via the virtual com port.

But when I try to connect the GPIO pins via a USB to UART converter, only TX from the nucleo board works. RX data from PC to board is not received. Is there any additional configuration or hardware changes required?