Code generator missing #define for HAL_I2C_MODULE_ENABLED when enabling an SMBus interface.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-05-28 2:20 AM
In STM32CubeMX, when I enable an I2C interface in SMBus mode (and no other I2C interfaces are enabled), the resulting code emitted in file stm32f4xx_hal_conf.h has this line commented out:
/* #define HAL_I2C_MODULE_ENABLED */
As a consequence, stm32f4xx_hal_i2c.h is not included. This leads to compile errors in stm32f4xx_hal_smbus.h, which needs typedef I2C_TypeDef.
Solved! Go to Solution.
- Labels:
-
I2C
-
STM32CubeMX
-
STM32F4 Series
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-06-08 10:26 AM
Hello @LGjes.1​ ,
Let me first welcome you to the STM32 Community and apologize for the the somewhat late reply :smiling_face_with_smiling_eyes:
When enabling SMBus mode through STM32CubeMX interface, #define HAL_SMBUS_MODULE_ENABLED will be uncommented, so the stm32f4xx_hal_smbus.h file will be included and there's no need to enable the HAL_I2C_MODULE.
Furthermore, the I2C_TypeDef structure (in stm32f4xx_hal_smbus.h file) is defined in the stm32f401xe.h which is the CMSIS STM32F401xE Device Peripheral Access Layer Header File containing :
- Data structures and the address mapping for all peripherals
- peripherals registers declarations and bits definition
- Macros to access peripheral’s registers hardware
Noting that I'm executing a simple test case using STM32F401RETx MCU, but this is generic for all MCUs supporting SMBus peripheral.
> This leads to compile errors in stm32f4xx_hal_smbus.h, which needs typedef I2C_TypeDef.
Could you please precise which compilation errors are getting? If it is possible, it will be more helpful to attach your .ioc to check from our side.
Hope my answer helps you.
Khouloud.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-06-08 10:26 AM
Hello @LGjes.1​ ,
Let me first welcome you to the STM32 Community and apologize for the the somewhat late reply :smiling_face_with_smiling_eyes:
When enabling SMBus mode through STM32CubeMX interface, #define HAL_SMBUS_MODULE_ENABLED will be uncommented, so the stm32f4xx_hal_smbus.h file will be included and there's no need to enable the HAL_I2C_MODULE.
Furthermore, the I2C_TypeDef structure (in stm32f4xx_hal_smbus.h file) is defined in the stm32f401xe.h which is the CMSIS STM32F401xE Device Peripheral Access Layer Header File containing :
- Data structures and the address mapping for all peripherals
- peripherals registers declarations and bits definition
- Macros to access peripheral’s registers hardware
Noting that I'm executing a simple test case using STM32F401RETx MCU, but this is generic for all MCUs supporting SMBus peripheral.
> This leads to compile errors in stm32f4xx_hal_smbus.h, which needs typedef I2C_TypeDef.
Could you please precise which compilation errors are getting? If it is possible, it will be more helpful to attach your .ioc to check from our side.
Hope my answer helps you.
Khouloud.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-06-09 1:11 AM
Hi Khouloud,
I must admit that I didn't keep that project setup. And now I'm working with a different setup, so I don't see the problem.
Like you, I cannot reproduce it just from a blank template. Most likely it was a mistake of mine - it was my first attempt at configuring a project with CubeMX. So don't spend more time on it ;)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-06-11 12:23 PM
Hi @LGjes.1​,
Glad that you no longer have the problem. In this case, I'm closing this post by clicking the Select as Best button on my reply . This will help other members of the community find this response more quickly :)
Do not hesitate to raise any issue/feedback.
khouloud.
