cancel
Showing results for 
Search instead for 
Did you mean: 

HAL bug in glass LCD clock init (STM32L0)

SZano
Associate III

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Amel NASRI
ST Employee

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 Accept as Solution on the reply which solved your issue or answered your question.

View solution in original post

1 REPLY 1
Amel NASRI
ST Employee

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 Accept as Solution on the reply which solved your issue or answered your question.