cancel
Showing results for 
Search instead for 
Did you mean: 

For low power, is LL better than HAL?

TheRaprus
Associate III
 
6 REPLIES 6
S.Ma
Principal

It is quite similar to the following question:

Is writing in assembly language better than C ?

Going lower level enables more control... for who has the tech know how for it.

Saving power is relative, there maybe many ways to reduce power, only few will have a significant impact.... power saving starts with a mission profile. Then, usually follows the question: what is the lowest core frequency that meet the application needs, to minimize the active and running power, then the power saving mode (clock stop...).... is the application sleeping 50% or 98% of the time?

HAL vs LL may require higher core frequency if more code is run relatively. Similarly for RTOS/linux vs Bare metal... trade offs are.to be well selected.

TheRaprus
Associate III

Generally speaking I agree with you, but two things:

Using LL need deepest knowledge of the micro (and this is a must for the best solution ever).

From the ST website: "The general rule to minimize the power consumption is to perform the task for the shortest possible time, at the lowest possible operating frequency and with the clock enabled to a minimal part of the silicon."

HAL need SysTick "The SysTick timer is configured to be used to generate variable increments by calling HAL_IncTick() function in SysTick ISR and retrieve the value of this variable by calling HAL_GetTick() function. The call HAL_GetTick() function is mandatory when using HAL drivers with Polling Process or when using HAL_Delay()." So, to reach the best low consumption SysTick must be enabled on wakeUp and vice-versa. ISR is shortest using LL than HAL, and they don't need SysTick .

The point can be: is a HAL ISR 20% slowest than LL, and it's called every minute, is the effort to learn all the uC so deep necessary?

I saw code where the LL are "copied" inside a ISR or a routine, like this:

GPIOA->ODR &= ~(1<<4); {

   while (!((SPI1->SR)&(1<<1))) {};

   SPI1->DR = opcode; }

>> illeggible!

In the past I used the Standard Template Library, and I prefer LL than HAL. But many lazy programmers use HAL without knowing how they work...

S.Ma
Principal

Well the 1 msec interrupt could use an lptim in some families so in between clock stop is possiblr.

Coding just what you need will tend to be the most efficient.

The HAL is a bit of a train wreck in many respects, and the paradigms it uses are often unhelpful ​and forced.

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

I was actually surprised that the LL stuff I had a look at seemed only like a slightly toned down HAL.

So in case of doubt, write and read the registers directly.

Sometime yes. Ofcourse, if you search only a bit set/reset OK. On a serial R/W interrupt things are most compicated (for me in HAL mode :face_with_tears_of_joy:). Unfortunately good library (as HAL are IMHO) makes programmers lazy.