cancel
Showing results for 
Search instead for 
Did you mean: 

LPUART LL driver not working, HAL driver working (STM32L476JG)

Alex Hösl
Associate II
Posted on April 04, 2018 at 17:00

Hi everybody,

I'm currently facing the following problem: I initialize code with CubeMX for a STM32L476JG. I want to use the low level drivers, but they don't seem to work. I was doing several hours of testing and trying to find the error, but don't come further anymore.

My last try was to switch to the HAL drivers for a simple test, voila, it's working! Immediately, without any problems!

But I need the LL drivers. Maybe somebody can help me!

This is how Cube initialises the LPUART with LL drivers:

/* LPUART1 init function */
static void MX_LPUART1_UART_Init(void)
{
 LL_LPUART_InitTypeDef LPUART_InitStruct;
 LL_GPIO_InitTypeDef GPIO_InitStruct;
 /* Peripheral clock enable */
 LL_APB1_GRP2_EnableClock(LL_APB1_GRP2_PERIPH_LPUART1);
 
 /**LPUART1 GPIO Configuration 
 PB11 ------> LPUART1_TX
 PB12 ------> LPUART1_RTS
 PB13 ------> LPUART1_CTS
 PB10 ------> LPUART1_RX 
 */
 GPIO_InitStruct.Pin = LL_GPIO_PIN_11|LL_GPIO_PIN_12|LL_GPIO_PIN_13|LL_GPIO_PIN_10;
 GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
 GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_VERY_HIGH;
 GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
 GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
 GPIO_InitStruct.Alternate = LL_GPIO_AF_8;
 LL_GPIO_Init(GPIOB, &GPIO_InitStruct);
 /* LPUART1 DMA Init */
 
 /* LPUART_TX Init */
 LL_DMA_SetPeriphRequest(DMA2, LL_DMA_CHANNEL_6, LL_DMA_REQUEST_4);
 LL_DMA_SetDataTransferDirection(DMA2, LL_DMA_CHANNEL_6, LL_DMA_DIRECTION_MEMORY_TO_PERIPH);
 LL_DMA_SetChannelPriorityLevel(DMA2, LL_DMA_CHANNEL_6, LL_DMA_PRIORITY_MEDIUM);
 LL_DMA_SetMode(DMA2, LL_DMA_CHANNEL_6, LL_DMA_MODE_NORMAL);
 LL_DMA_SetPeriphIncMode(DMA2, LL_DMA_CHANNEL_6, LL_DMA_PERIPH_NOINCREMENT);
 LL_DMA_SetMemoryIncMode(DMA2, LL_DMA_CHANNEL_6, LL_DMA_MEMORY_INCREMENT);
 LL_DMA_SetPeriphSize(DMA2, LL_DMA_CHANNEL_6, LL_DMA_PDATAALIGN_BYTE);
 LL_DMA_SetMemorySize(DMA2, LL_DMA_CHANNEL_6, LL_DMA_MDATAALIGN_BYTE);
 /* LPUART1 interrupt Init */
 NVIC_SetPriority(LPUART1_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(),5, 0));
 NVIC_EnableIRQ(LPUART1_IRQn);
 LPUART_InitStruct.BaudRate = 9600;
 LPUART_InitStruct.DataWidth = LL_LPUART_DATAWIDTH_8B;
 LPUART_InitStruct.StopBits = LL_LPUART_STOPBITS_1;
 LPUART_InitStruct.Parity = LL_LPUART_PARITY_NONE;
 LPUART_InitStruct.TransferDirection = LL_LPUART_DIRECTION_TX_RX;
 LPUART_InitStruct.HardwareFlowControl = LL_LPUART_HWCONTROL_NONE;
 LL_LPUART_Init(LPUART1, &LPUART_InitStruct);
}

After that, I was trying to send some data (doesn't work). Am I missing something?:

 while(1)
 {
 LL_LPUART_TransmitData8(LPUART1, 0x55);
 myTimer_CPU_Delay(10);
 }

And that's how Cube initialises with HAL drivers:

/* LPUART1 init function */
static void MX_LPUART1_UART_Init(void)
{
 hlpuart1.Instance = LPUART1;
 hlpuart1.Init.BaudRate = 9600;
 hlpuart1.Init.WordLength = UART_WORDLENGTH_8B;
 hlpuart1.Init.StopBits = UART_STOPBITS_1;
 hlpuart1.Init.Parity = UART_PARITY_NONE;
 hlpuart1.Init.Mode = UART_MODE_TX_RX;
 hlpuart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
 hlpuart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
 hlpuart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
 if (HAL_UART_Init(&hlpuart1) != HAL_OK)
 {
 _Error_Handler(__FILE__, __LINE__);
 }
}

And I can successfully transmit after that with the following:

 uint8_t data = 0x55;
 while(1)
 {
 HAL_UART_Transmit(&hlpuart1, &data, sizeof(data), 100);
 myTimer_CPU_Delay(10);
 }

I would appreciate a tipp, hint, solution! If you need further information, I'm sure I'll find them.

Thanks in advance,

Regards

Alex

#ll-uart #uart #lpuart #ll-drivers #hal-versus-ll-drivers #hal-uart #stm32-l4
1 ACCEPTED SOLUTION

Accepted Solutions
Posted on April 04, 2018 at 19:25

Make sure you enable the GPIO bank clocks for the pins involved before initializing them.

LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOB);

Use a debugger Peripheral View to check register settings in RCC, GPIO and LPUART1

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

View solution in original post

6 REPLIES 6
Posted on April 04, 2018 at 19:25

Make sure you enable the GPIO bank clocks for the pins involved before initializing them.

LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOB);

Use a debugger Peripheral View to check register settings in RCC, GPIO and LPUART1

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Alex Hösl
Associate II
Posted on April 05, 2018 at 09:43

Thanks a lot!

I checked the register settings and compared LL to HAL.

The HAL LPUART is enabled after initialisation, the LL doesn't enable LPUART (CR1 bit0). I manually called the LL_LPUART_Enable() function and now it works.

I'm wondering why this is necessary. When I used the LL drivers of USART on a similar MCU it wasn't necessary. Maybe this is one of the low power functionalities?! The LL USART CubeMX code enables UART at the end of the initialisation:

...

  LL_USART_Init(USART2, &USART_InitStruct);

  LL_USART_ConfigAsyncMode(USART2);

  LL_USART_Enable(USART2);

}

The LL LPUART ends with the LL_LPUART_Init() function.

For me the problem is solved, thanks again!

Posted on April 05, 2018 at 13:40

Hi

alexander.hoesl

‌,

The call of

LL_LPUART_Enable()

has to be available in the generated project by STM32CubeMX.

I will log this issue to our STM32CubeMX team.

-Amel

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Posted on July 06, 2018 at 14:32

Please note that a call of 

LL_LPUART_Enable is added in code generated by the last CubeMX version (V4.26).

6amel

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

DSwar.1
Associate

Good day,

I have encountered this same issue where LL_LPUART_Enable() is missing from the code generated by CubeMX and I have version 5.6.0

Regards,

Dylan.

Hello @DSwar.1​ ,

I cannot reproduce the issue on my side. Could you please share your .ioc file?

Thanks,

Amel

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.