0
\$\begingroup\$

I wonder if the STM32F4 CubeMX peripheral HAL libraries saves the internal state of the peripherals OR if they are stateless? I am concerned about this because I want to know the possibility and safety of mixing the use of HAL libraries with direct register accesses at places where time-saving is more critical.

\$\endgroup\$
3
  • 4
    \$\begingroup\$ Both. You have to look at the source on a case by case basis for particular operations. Mostly it is the more complex things where there is software state. \$\endgroup\$ Commented Jan 27, 2019 at 16:00
  • 2
    \$\begingroup\$ Mixing HAL functions and direct register acces should only be done if you are realy sure about the peripheral state. Usually it is not a good idea. If you need that time critical access, throw away the HAL driver and write your own driver for all cases. \$\endgroup\$
    – A.R.C.
    Commented Jan 28, 2019 at 7:18
  • 2
    \$\begingroup\$ @A.R.C. actually the HAL is incomplete enough that bypassing it is often needed for routine tasks after using it for initial setup. But there is no general answer. \$\endgroup\$ Commented Jan 28, 2019 at 15:19

1 Answer 1

4
\$\begingroup\$

Look at the Low Level library (LL) this provides a much lighter weight wrapper around the registers.

You can generate the LL code from Cube by selecting LL from the advanced settings tab in the Project Manager section.

You should see a list of peripherals and be able to select HAL or LL. I have not had much joy in mixing HAL and LL so generally pick one or the other for every peripheral. As for the state held by each peripheral the best place to start looking is the reference manual Cheers.

\$\endgroup\$
2
  • \$\begingroup\$ @MatsK: Your comment would be MUCH better if you explained how this answer violates the rules. In particular, the emphasis on looking at the reference manual is relevant. \$\endgroup\$ Commented Jan 29, 2019 at 3:10
  • \$\begingroup\$ @MatsK: I still don't see how his (useful) answer violates the rules. I'm a fairly long-timer user and I don't understand how his answer violates any rules. If I don't get it, how do you expect a newbie to get it? Please explain in detail what you mean. \$\endgroup\$ Commented Jan 29, 2019 at 16:01

Not the answer you're looking for? Browse other questions tagged or ask your own question.