Skip to main content
SZano
Associate III
October 20, 2021
Solved

HAL bug in glass LCD clock init (STM32L0)

  • October 20, 2021
  • 1 reply
  • 1008 views

in software package STM32L0 1.12.1

in file stm32l0xx_hal_rcc_ex.c

in function

HAL_StatusTypeDef HAL_RCCEx_PeriphCLKConfig(RCC_PeriphCLKInitTypeDef *PeriphClkInit)

The RTC and LCD have their own settings, though they share the same clock.

These settings are usually handled correctly, e.g.

/*------------------------------- RTC/LCD Configuration ------------------------*/
 if ((((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_RTC) == RCC_PERIPHCLK_RTC)
#if defined(LCD)
 || (((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_LCD) == RCC_PERIPHCLK_LCD)
#endif /* LCD */
 )

but they're not correctly handled everywhere; at the end of the block quoted above, there is this initialization:

__HAL_RCC_RTC_CONFIG(PeriphClkInit->RTCClockSelection);

However, if the function was called to initialize the LCD and not the RTC, this is wrong, as it will disable the clock.

This is what that one-line init should actually be:

#if defined(LCD)
	if((((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_RTC) == RCC_PERIPHCLK_RTC)
		&& (((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_LCD) == RCC_PERIPHCLK_LCD))
	{
		if(PeriphClkInit->RTCClockSelection != PeriphClkInit->LCDClockSelection) {
			/* RTC and LCD share the same clock; cannot have different settings for the two of them */
			return HAL_ERROR;
		}
	}
	if((((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_RTC) == RCC_PERIPHCLK_RTC)) {
		__HAL_RCC_RTC_CONFIG(PeriphClkInit->RTCClockSelection);
	} else {
		__HAL_RCC_RTC_CONFIG(PeriphClkInit->LCDClockSelection);
	}
#else
	__HAL_RCC_RTC_CONFIG(PeriphClkInit->RTCClockSelection);
#endif

However, you might probably want to do the RTCClockSelection!=LCDClockSelection check before this point, before touching other registers, to avoid leaving the system in an inconsistent state.

This topic has been closed for replies.
Best answer by Amel NASRI

Hi @Community member​ ,

Thanks for bringing this limitation to our attention.

I reported it in an internal ticket to development team.

Internal ticket number: 116449 (This is an internal tracking number and is not accessible or usable by customers).

-Amel

1 reply

Amel NASRI
Amel NASRIBest answer
ST Technical Moderator
October 25, 2021

Hi @Community member​ ,

Thanks for bringing this limitation to our attention.

I reported it in an internal ticket to development team.

Internal ticket number: 116449 (This is an internal tracking number and is not accessible or usable by customers).

-Amel

To give better visibility on the answered topics, please click on "Best Answer" on the reply which solved your issue or answered your question.