cancel
Showing results for 
Search instead for 
Did you mean: 

How to set USE_HAL_***_REGISTER_CALLBACKS from CubeMX

ALowe
Associate II

In order to use the HAL's register callback capability, various flags are set for each peripheral in the stm32***_hal_config.h generated by CubeMX such as USE_HAL_FDCAN_REGISTER_CALLBACKS.

The issue is that these defines don't look for a prior define first, so it's not possible to override via compiler options etc and each time the project is regenerated it replaces this file.

Is there not a way that these can be set that won't be erased upon each generation?

Many thanks

14 REPLIES 14

Thanks for both of you.

S.Ma
Principal

What cubemx is to add a compiler command option with this callbacks, and this is why it is not visible in source and header files. Beware, the callback by id will generate a switch case inside the time critical interrupt service routine, hence longer duration.

The ID is used only for configuration to indicate which function pointer is being set. Processing, including the ISR, doesn't need ID and just calls the callback function. On the contrary the older approach of using a single callback function for all peripheral instances requires the application to implement an if/switch to determine for which particular peripheral instance the callback is being called.

S.Ma
Principal

Also true and related to multiple instances. My comment is more related to the multiple interrupt sources of one peripheral. Transmit, receive, break, error, compare, overflow... etc

On the other hand splitting the events to separate functions often makes the code ridiculous. For example, for DMA events HT and TC one almost always needs the same processing code just with some index or address being different. With multiple callbacks one has to either copy the code, which is stupid and inefficient, or implement it in the third function, which need an additional parameter to signal from which callback it is being called and again sort it out in that third function, which is even more ridiculous.