cancel
Showing results for 
Search instead for 
Did you mean: 

Code generator missing #define for HAL_I2C_MODULE_ENABLED when enabling an SMBus interface.

LGjes.1
Associate II

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.

1 ACCEPTED SOLUTION

Accepted Solutions

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

0693W00000BaRgFQAV.jpgNoting 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.

View solution in original post

3 REPLIES 3

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

0693W00000BaRgFQAV.jpgNoting 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.

LGjes.1
Associate II

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 ;)

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.