2019-05-22 01:55 AM
Hi all,
I'd like to register some user defined callbacks using the HAL_***_RegisterCallback() functions.
I understood that first I need to define the compilation flag USE_HAL_***_REGISTER_CALLBACKS but where should I put it? Looking through the various examples I stepped into F4-Discovery DMA_FLASHtoRAM example and its stm32fxxx_hal_conf.h, copied below, which (hopefully) provides the answer.
Considering that i don't want to manually modify this file in my project (nor there is a user code section in it), how can i set the code generator to automatically insert the required defines?
Thanks,
Lorenzo
/* ########################### System Configuration ######################### */
/**
* @brief This is the HAL system configuration section
*/
#define VDD_VALUE (3300U) /*!< Value of VDD in mv */
#define TICK_INT_PRIORITY (0x0FU) /*!< tick interrupt priority */
#define USE_RTOS 0U
#define PREFETCH_ENABLE 0U /* The prefetch will be enabled in SystemClock_Config(), depending on the used
STM32F405/415/07/417 device: RevA (prefetch must be off) or RevZ (prefetch can be on/off) */
#define INSTRUCTION_CACHE_ENABLE 1U
#define DATA_CACHE_ENABLE 1U
#define USE_HAL_ADC_REGISTER_CALLBACKS 0U /* ADC register callback disabled */
#define USE_HAL_CAN_REGISTER_CALLBACKS 0U /* CAN register callback disabled */
#define USE_HAL_CEC_REGISTER_CALLBACKS 0U /* CEC register callback disabled */
#define USE_HAL_CRYP_REGISTER_CALLBACKS 0U /* CRYP register callback disabled */
#define USE_HAL_DAC_REGISTER_CALLBACKS 0U /* DAC register callback disabled */
#define USE_HAL_DCMI_REGISTER_CALLBACKS 0U /* DCMI register callback disabled */
#define USE_HAL_DFSDM_REGISTER_CALLBACKS 0U /* DFSDM register callback disabled */
#define USE_HAL_DMA2D_REGISTER_CALLBACKS 0U /* DMA2D register callback disabled */
#define USE_HAL_DSI_REGISTER_CALLBACKS 0U /* DSI register callback disabled */
#define USE_HAL_ETH_REGISTER_CALLBACKS 0U /* ETH register callback disabled */
#define USE_HAL_HASH_REGISTER_CALLBACKS 0U /* HASH register callback disabled */
#define USE_HAL_HCD_REGISTER_CALLBACKS 0U /* HCD register callback disabled */
#define USE_HAL_I2C_REGISTER_CALLBACKS 0U /* I2C register callback disabled */
#define USE_HAL_FMPI2C_REGISTER_CALLBACKS 0U /* FMPI2C register callback disabled */
#define USE_HAL_I2S_REGISTER_CALLBACKS 0U /* I2S register callback disabled */
#define USE_HAL_IRDA_REGISTER_CALLBACKS 0U /* IRDA register callback disabled */
#define USE_HAL_LPTIM_REGISTER_CALLBACKS 0U /* LPTIM register callback disabled */
#define USE_HAL_LTDC_REGISTER_CALLBACKS 0U /* LTDC register callback disabled */
#define USE_HAL_MMC_REGISTER_CALLBACKS 0U /* MMC register callback disabled */
#define USE_HAL_NAND_REGISTER_CALLBACKS 0U /* NAND register callback disabled */
#define USE_HAL_NOR_REGISTER_CALLBACKS 0U /* NOR register callback disabled */
#define USE_HAL_PCCARD_REGISTER_CALLBACKS 0U /* PCCARD register callback disabled */
#define USE_HAL_PCD_REGISTER_CALLBACKS 0U /* PCD register callback disabled */
#define USE_HAL_QSPI_REGISTER_CALLBACKS 0U /* QSPI register callback disabled */
#define USE_HAL_RNG_REGISTER_CALLBACKS 0U /* RNG register callback disabled */
#define USE_HAL_RTC_REGISTER_CALLBACKS 0U /* RTC register callback disabled */
#define USE_HAL_SAI_REGISTER_CALLBACKS 0U /* SAI register callback disabled */
#define USE_HAL_SD_REGISTER_CALLBACKS 0U /* SD register callback disabled */
#define USE_HAL_SMARTCARD_REGISTER_CALLBACKS 0U /* SMARTCARD register callback disabled */
#define USE_HAL_SDRAM_REGISTER_CALLBACKS 0U /* SDRAM register callback disabled */
#define USE_HAL_SRAM_REGISTER_CALLBACKS 0U /* SRAM register callback disabled */
#define USE_HAL_SPDIFRX_REGISTER_CALLBACKS 0U /* SPDIFRX register callback disabled */
#define USE_HAL_SMBUS_REGISTER_CALLBACKS 0U /* SMBUS register callback disabled */
#define USE_HAL_SPI_REGISTER_CALLBACKS 0U /* SPI register callback disabled */
#define USE_HAL_TIM_REGISTER_CALLBACKS 0U /* TIM register callback disabled */
#define USE_HAL_UART_REGISTER_CALLBACKS 0U /* UART register callback disabled */
#define USE_HAL_USART_REGISTER_CALLBACKS 0U /* USART register callback disabled */
#define USE_HAL_WWDG_REGISTER_CALLBACKS 0U /* WWDG register callback disabled */
2020-08-07 08:52 PM
You can enable callbacks by defining the macro USE_HAL_UART_REGISTER_CALLBACKS in the Project->Properties dialog:
2020-08-07 11:02 PM
At least not in recent versions of STM32CubeIDE. It will be redefined by generated code as described above.
2020-08-07 11:23 PM
I'm using CubeIDE 1.3.1 and setting the symbol above allows me to use HAL_UART_RegisterCallback() to register callbacks and is working fine. Maybe it depends on the specific target or options selected in CubeMX.
2020-08-10 05:45 AM
It's and old topic, but today i stumbled upon STM32CubeMX Project Manager > Advanced Settings > Register Callback where those settings can be configured.
2020-08-26 08:32 AM
This feature has also been added to STM32CubeIDE 1.4.0 now.
Do note that the Register Callback pane might be obscured, you need to scroll right inside the device configuration window.
2020-08-26 12:22 PM
@KnarfB and @Tadej Pe�?ar
Thanks for giving us a heads up on this. I appreciate it.
2020-10-06 08:54 PM
This trick of the definition in the Project->Properties dialog unfortunately this doesn't work for USE_HAL_COMP_REGISTER_CALLBACKS, even though it looks like it should:
../Core/Inc/stm32g4xx_hal_conf.h:81:0: warning: "USE_HAL_COMP_REGISTER_CALLBACKS" redefined
#define USE_HAL_COMP_REGISTER_CALLBACKS 0U
<command-line>:0:0: note: this is the location of the previous definition
In file included from ../Drivers/STM32G4xx_HAL_Driver/Inc/stm32g4xx_hal.h:30:0,
from ../Drivers/CMSIS/Device/ST/STM32G4xx/Include/stm32g4xx.h:187,
from ../Core/Src/system_stm32g4xx.c:79:
So still no good.
2020-10-06 08:57 PM
Never mind, the below solution in the Project Manager works.
2020-10-28 09:05 AM
While this does actually work, it is annoying that the comment in the file still says "register callback disabled" even though it is enabled. For example:
#define USE_HAL_DCMI_REGISTER_CALLBACKS 1U /* DCMI register callback disabled */
This is not a functionality issue, but it would be nice if the comment reflected what the setting actually is.
2020-12-21 06:44 AM
Hello, I just want to point out a solution on same topic that was proposed here: