diff --git a/boards/arm/stm32/nucleo-l152re/include/board.h b/boards/arm/stm32/nucleo-l152re/include/board.h index d1e29b4efe6..e553ebd1425 100644 --- a/boards/arm/stm32/nucleo-l152re/include/board.h +++ b/boards/arm/stm32/nucleo-l152re/include/board.h @@ -221,4 +221,9 @@ #define GPIO_SPI1_MISO GPIO_SPI1_MISO_2 #define GPIO_SPI1_SCK GPIO_SPI1_SCK_1 +/* I2C1 */ + +#define GPIO_I2C1_SCL GPIO_I2C1_SCL_2 /* PB8 CN5 pin 10, D15 */ +#define GPIO_I2C1_SDA GPIO_I2C1_SDA_2 /* PB9 CN5 pin 9, D14 */ + #endif /* __BOARDS_ARM_STM32_NUCLEO_L152RE_INCLUDE_BOARD_H */ diff --git a/boards/arm/stm32/nucleo-l152re/src/stm32_appinitialize.c b/boards/arm/stm32/nucleo-l152re/src/stm32_appinitialize.c index 6b146d53bcb..e0c8ca2b866 100644 --- a/boards/arm/stm32/nucleo-l152re/src/stm32_appinitialize.c +++ b/boards/arm/stm32/nucleo-l152re/src/stm32_appinitialize.c @@ -26,11 +26,14 @@ #include #include +#include #include #include #include +#include "stm32_i2c.h" + #include "nucleo-l152re.h" /**************************************************************************** @@ -80,6 +83,52 @@ int board_app_initialize(uintptr_t arg) { int ret; +#ifdef CONFIG_STM32_I2C1 + FAR struct i2c_master_s *i2c1; +#endif +#ifdef CONFIG_STM32_I2C2 + FAR struct i2c_master_s *i2c2; +#endif + +#ifdef CONFIG_STM32_I2C1 + /* Get the I2C lower half instance */ + + i2c1 = stm32_i2cbus_initialize(1); + if (i2c1 == NULL) + { + i2cerr("ERROR: Initialize I2C1: %d\n", ret); + } + else + { + /* Register the I2C character driver */ + + ret = i2c_register(i2c1, 1); + if (ret < 0) + { + i2cerr("ERROR: Failed to register I2C1 device: %d\n", ret); + } + } +#endif + +#ifdef CONFIG_STM32_I2C2 + /* Get the I2C lower half instance */ + + i2c2 = stm32_i2cbus_initialize(2); + if (i2c2 == NULL) + { + i2cerr("ERROR: Initialize I2C2: %d\n", ret); + } + else + { + /* Register the I2C character driver */ + + ret = i2c_register(i2c2, 2); + if (ret < 0) + { + i2cerr("ERROR: Failed to register I2C2 device: %d\n", ret); + } + } +#endif #ifdef HAVE_LEDS /* Register the LED driver */ diff --git a/boards/arm/stm32/nucleo-l152re/src/stm32_boot.c b/boards/arm/stm32/nucleo-l152re/src/stm32_boot.c index 19a9a201ec6..2d2b55ca8df 100644 --- a/boards/arm/stm32/nucleo-l152re/src/stm32_boot.c +++ b/boards/arm/stm32/nucleo-l152re/src/stm32_boot.c @@ -68,3 +68,25 @@ void stm32_boardinitialize(void) board_autoled_initialize(); #endif } + +/**************************************************************************** + * Name: board_late_initialize + * + * Description: + * If CONFIG_BOARD_LATE_INITIALIZE is selected, then an additional + * initialization call will be performed in the boot-up sequence to a + * function called board_late_initialize(). board_late_initialize() will be + * called immediately after up_initialize() is called and just before the + * initial application is started. This additional initialization phase + * may be used, for example, to initialize board-specific device drivers. + * + ****************************************************************************/ + +#ifdef CONFIG_BOARD_LATE_INITIALIZE +void board_late_initialize(void) +{ + /* Perform board-specific initialization */ + + board_app_initialize(0); +} +#endif