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 */
2019-08-02 02:26 AM
I have the same problem. As I tried to add a User Constant the compiler complained about redefinition of USE_HAL_SPI_REGISTER_CALLBACKS constant. Please tell how to mofify these!
2019-09-05 05:51 AM
Same here. Is there any way to modify this through code or Device Configuration Tool (neé STM32CubeMX) or any hidden config file?
Also, is there any way to enable a peripherial in config tool, but do not generate ANY code for it?
2019-09-27 09:35 AM
Have the same problem, that HAL conf header is reset every time code is generated through CubeMX, and I have to go in and change it back.
2019-09-27 10:46 AM
Maybe user constants is where they designed to be, because CubeMX will know your preference to use callbacks when generating code.
User constants go to main.h
To avoid compiler complaints, define the user constants exactly as they are defined in other place, or remove duplicate definitions from your code.
-- pa
2019-09-27 11:07 AM
As d.koekeny noted, that doesn't quite work. There is contradictory info in the SDK, too: there is a hal_conf_template.h in Drivers/HAL_Driver/Inc/ that is supposed to be copied and renamed into the application source folder, which is where CubeMX puts it, but then it also ignores edits to it and clobbers it when regenerating code.
2020-01-16 03:51 PM
I'm afraid this is breakage in CubeMX and there's no way to avoid it short of hand modifying stm32h7xx_hal_conf.h and hoping it survives the next code generation (unlikely)
ST, please modify stm32h7xx_hal_conf.h so it generates #ifndef wrappers around the "USE_HAL_***_REGISTER_CALLBACKS" or advise the better solution.
#ifndef USE_HAL_UART_REGISTER_CALLBACKS
#define USE_HAL_USE_HAL_UART_REGISTER_CALLBACKS 0U /* Blah */
#endif
2020-05-27 09:06 AM
And no answer to this?
2020-06-05 02:05 PM
I came to the same issue, and if you want the short answer, it's not supported (at least up to the current version of STM32CubeIDE - v1.3.0).
Has been fixed in STM32CubeIDE v1.4.0, see answers below.
My current workaround is to copy the _hal_conf.h file to some other directory, modify it to my liking and add its path to the top of the Include directories list. I also needed to set the Is a workspace path option to keep the code generator from changing its order.
Obviously, when you're doing any major reconfiguration (enabling/disabling peripherals etc.) you need to manually update your customized variant, which isn't ideal.
See next post.
---
If you want the long answer: I did some digging around STM32CubeIDE files.
If you look at any of the internal template files for *_hal_conf.h at
stm32cubeide/plugins/com.st.stm32cube.common.mx_X.X.X.XXXXXXXXXXXX/db/templates/
(version numbers replaced with X)
The value of those defines is not part of a template, which means the code generator simply copies them as-is.
I also did some tests to check if I could override the template by adding a customized variant as a user template (these are partially described in STMCubeMX manual @ 6.3 Custom code generation, in STM32CubeIDE you configure it via Project Manager > Code Generator > Template Settings). It seemed like a neat idea, given that that user template configuration is saved as part of the ioc file.
What I've figured out is that while you can override the Cube-provided file, most internal templates fail to parse correctly (you get an empty file) since the code generator does not seem to provide the same context to user templates.
Soooo, they need to fix their internal templates.
2020-06-07 07:29 AM
I've expanded on my previous solution by using user templates feature to patch the _hal_conf.h file with USER CODE sections.
This allows us to manually manage REGISTER_CALLBACKS section while the rest is managed by the code generator.