Benefits of HAL over LL for simple peripherals
Hi guys,
I am wondering, if there is any “real” benefit in using the HAL over the LL for simple peripherals like GPIO, ADCs or Timers.
So far it looked to me like the HAL does not make the user code more compact or readable. Instead, it just gets more bulky and harder to debug since you have to deal with the HAL code as well.
Just as an example, look at the two functions which both do the same. They do a blocking ADC conversion on a given channel. In this case, the LL variant is actually shorter.
static uint16_t read_adc_chn_LL(uint32_t chn)
{
LL_ADC_REG_SetSequencerChannels(ADC1, chn);
LL_ADC_REG_StartConversion(ADC1);
while (LL_ADC_REG_IsConversionOngoing(ADC1));
return LL_ADC_REG_ReadConversionData12(ADC1);
}
static uint16_t read_adc_chn_HAL(uint32_t chn)
{
ADC_ChannelConfTypeDef sConfig = {0};
sConfig.Channel = chn;
sConfig.Rank = 1;
sConfig.SamplingTime = ADC_SAMPLETIME_28CYCLES;
HAL_ADC_ConfigChannel(&hadc1, &sConfig);
HAL_ADC_Start(&hadc1);
HAL_ADC_PollForConversion(&hadc1, 1000);
return HAL_ADC_GetValue(&hadc1);
}A similar thing is also true for timers. I get the benefits of the HAL for more complex peripherals like I2C or UART since the HAL offers some convenient functions for this, but I fail to see the benefit of using the HAL in these simple cases.
Am I missing something important here?
Cheers,
D.Frejek
