2020-04-07 03:12 AM
I arrange 3 main advantage for using the HAL rountines compared with direct memory access.
Is that three advantage is correct thus i able to continue my explaination for HAL.
Thanks anyone helip me in advance!
2020-04-07 04:11 AM
Pretty sure HAL is not fast and nimble.
Code is relatively portable.
High level code and good abstraction can reduce development time.
2020-04-07 04:40 AM
> HAL will faster than direct access.
No. Who told you that?
HAL functions themselves are accessing the memory mapped registers directly, there is no other way, but they check a few things in the handle structures before each access. This makes them a lot slower than a simple register access. See the result here.
> HAL will offer more easy to remember the function names
HAL function names might be easy to remember, but they are poorly documented. HAL documentation is most of the time a single sentence for each function or parameter, not really explaining what it is exactly doing.
On the other hand, registers and bitfields are extensively documented in the reference manual, with timing diagrams and step-by-step examples on how to use them.
> HAL will make the code more portable.
In some special cases. Otherwise HAL is not even always compatible with itself, the behaviour of functions are sometimes changed between releases. The register interface is guaranteed to remain stable throughout the lifecycle of the product, i.e. at least 10 years. There are no guarantees that HAL will be available next week, ST can abandon it any time like they did with the SPL library.
If you want to continue, you can find a few more "advantages" of using HAL here.
2020-04-07 04:43 AM
HAL is neither high level nor does it offer a good abstraction.
2020-04-07 04:58 AM
> I am writing the explaination for HAL.
Why?
JW
2020-04-07 09:00 AM
A HAL does help in portability. Maybe, sometimes, depending on how well it's designed and coded. For a large controller family with similar peripherals some level of abstraction does help when working across several series (in my case, L0, L1, L4, F7). The ST HAL however is not my first choice as an example to praise.
I still use the SPL API with my own libraries, to good effect. The abstraction is simpler and doesn't all those hidden "gotchas" embedded in the HAL interactions. The parameter checking does help in the initial debugging...everyone makes typo errors.
Easy to remember? That's subjective and not really all that relevant. Code reuse is a necessity in commercial programming. I rely on cut and paste more than function mnemonics. Maybe if this were assembly language the "easy to remember" might be significant (a good example is the old DEC VMS system calls). With C, no.
A HAL is a layer on top of direct register access. Think about it, how can it possibly be faster? and is that so important? On battery powered systems I often slow down to 4MHz and still have plenty of CPU cycles left. I'm not concerned about saving a few bus cycles with direct vs. abstraction layer.
This sounds like homework. Kinda sad to see what's taught in comp sci (or is this electrical engineering?) classrooms now. I suppose questioning fundamental assumptions (AKA critical thinking) isn't part of the curriculum any longer.
Jack Peacock
2020-04-07 05:38 PM
Thanks guys for reply me. I wrting the explaination for HAl which is because i going to writing a report about what i learn about STM32.
2020-04-07 07:53 PM
This may be helpful for your homework: see the free intro chapter.
2020-04-08 12:19 AM
Well, the example on Page 14 tells a lot...
JW
2020-04-08 12:21 AM
> i going to writing a report about what i learn about STM32.
Well, then perhaps you should write about *your* experience with HAL.
So, you using HAL, did you find your code to run faster? Did you find you could port your code better? Did you remember function names easier?
Note, that correct answers require also a reference (e.g. "as compared with using registers directly").
JW