2016-12-22 09:11 AM
Hello everybody,
In first time, I'm sorry for my english! ^^
I'm trying to configure an I2C communication for a MCU STM32F401RT6. I don't use ...Cube_MX but I use STM32f4xx_HAL Library for different reason and not STM32f4xx library.
My program compile but there is a problem with the linker => I have the famous error message : undefined reference to 'HAL_I2C_Init' (Yes, again and again this error message ^^).
To simplify, I removed other file .c and .h and I keep just Main program.
Here main.c Program
#include ''stm32f4xx_hal.h''
#include ''stm32f4xx_hal_def.h''#include ''stm32f4xx_hal_i2c.h''#define I2Cx I2C1
#define I2Cx_CLK_ENABLE() __HAL_RCC_I2C1_CLK_ENABLE()#define I2Cx_SCL_GPIO_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE()#define I2Cx_SDA_GPIO_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE()#define I2Cx_FORCE_RESET() __HAL_RCC_I2C1_FORCE_RESET() #define I2Cx_RELEASE_RESET() __HAL_RCC_I2C1_RELEASE_RESET()#define I2Cx_SCL_PIN GPIO_PIN_6#define I2Cx_SCL_GPIO_PORT GPIOB#define I2Cx_SDA_PIN GPIO_PIN_7#define I2Cx_SDA_GPIO_PORT GPIOB#define I2Cx_GPIO_MODE GPIO_MODE_AF_OD#define I2Cx_GPIO_PULL GPIO_PULLUP#define I2Cx_GPIO_SPEED GPIO_SPEED_FREQ_HIGH#define I2Cx_SCL_AF GPIO_AF4_I2C1#define I2Cx_SDA_AF GPIO_AF4_I2C1//=======================================================================================
static I2C_HandleTypeDef hi2c;//=======================================================================================bool I2CInit(void);int main(void) {
I2CInit();
}
bool I2CInit(void) {
hi2c.Instance = I2Cx; hi2c.Init.ClockSpeed = 100000; // 100kHz hi2c.Init.DutyCycle = I2C_DUTYCYCLE_2; // 50% duty cycle --> standard hi2c.Init.OwnAddress1 = 0x00; // own address, not relevant in master mode hi2c.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT; // Set address length to 7 bit addresses hi2c.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE; // Disable seconde Address hi2c.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE; // Disable general call hi2c.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE; // Disable no stretch hi2c.Devaddress = 0x3B;if (HAL_I2C_DeInit(&hi2c) != HAL_OK) {
return false; }if (HAL_I2C_Init(&hi2c) != HAL_OK) {
return false; }//HAL_I2C_MspInit(&hi2c);
return true;
}//=======================================================================================I compile and link with a makefile and config.mk on Cygdrive terminal.
here the message on my terminal.
I don't see where is the problem. I looked for on google but I didn't find a solution. I specify that the stm32f4xx_hal_conf.h include HAL_I2C_MODULE_ENABLED
Do you understand where is the problem?
Thank you very much for your assistance?
Régis
2016-12-26 06:15 AM
Dear
loucas
,It seems your pathis not configured properly.
Make sure that your project has the right include paths and source files from the same tree.
Best Regards
Imen