HAL bug in glass LCD clock init (STM32L0)
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);
#endifHowever, 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.
