I keep going through the HAL manual but it's just a miserable excuse for a manual. It's just a pdf auto-generated from the comments in the source code. There are no complete code examples and in lots of places the functions don't work.
Doxygen! I really prefer reading directly the code together with the comments.
For example, the HAL_Delay() function doesn't work. I do the Inits and setups as mentioned in the manual but when I checked, HAL_GetTick() is always zero. I don't know what I need to enable to get this to work.
Yes, that caught me too at first.
In
every some HAL header
and in most examples you can find the statement about using a 1ms tick to make sure the HAL works, but how to get it working is not spelled out very clearly.
As westfw says, interrupt handlers are just regular C functions, for the system tick that would be:
void SysTick_Handler(void)
{
/* your code here */
}
Now, the HAL provides a couple of functions to place in the handler, defined in stm32f?xx_hal.c (where ? is the F family number).
The first is more or less mandatory, as it increments the tick:
__weak void HAL_IncTick(void)
{
uwTick++;
}
The other one,
void HAL_SYSTICK_IRQHandler(void)
is optional, it just calls an user overridable (weak) callback function.
So the handler should look something like:
void SysTick_Handler(void)
{
HAL_IncTick();
HAL_SYSTICK_IRQHandler();
}
And you could insert other things to do every tick in your
void HAL_SYSTICK_Callback(void);
Note that this is a very general mechanism used by the HAL: it provides the building blocks for handling the interrupt from the peripherals, but it's up to you to write the xxxx_Hander() functions.
One way of learning all this could be using CubeMX to generate the skeleton code for various peripherals (and the clock chain settings) and study that: I used it quite a lot in the beginning, but now I almost know my way around HAL maze.
It will generate all the needed initialization code, generally quite easily readable, including (if enabled) interrupt handlers.
I could just go to mbed.org and use that but I don't want it to be super-simplified to DigitalWrite(). I'd like to learn what's going on under the hood, but to a point that my current schedule allows. This is a hobby .
Right attitude! mbed can be an easy way to begin if you only have done some Arduino stuff, but using the HAL (and also knwoing the involved registers and how to bypass it) will for sure teach a lot more.