board: nucleo-l152re: Added registering logic I2C on /dev.

board: nucleo-l152re: Added registering logic I2C on /dev.

squash 5 commits

board: nucleo-l152re: Add missing I2C1 GPIO definition
I2C1 not worked due to it's GPIO pin definition has been missing on board.h.
Fix it through include two pin macros on stm32l15xxx_pinmap.h(arch/arm/src/stm32/hardware) to board.h
GPIO_I2C1_SCL => PB8 (CN5 pin 10, D15)
GPIO_I2C1_SDA => PB9 (CN5 pin 9, D14)

Added board_late_initialize() function for init I2C.

board: nucleo-l152re: Added registering logic I2C on /dev.
I2C1 hasn't been registered on /dev. Fix it.

board: nucleo-l152re: Fix code style.

Update board.h

board: nucleo-l152re: Fix code style.

Variables starting with symbol '"g_*" means it is a global variable, I think this is not the case here.

Fix code style
This commit is contained in:
John Bonham 2022-02-07 10:52:21 +03:00 committed by Xiang Xiao
parent 8e64db45c7
commit f731763211
3 changed files with 76 additions and 0 deletions

View File

@ -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 */

View File

@ -26,11 +26,14 @@
#include <sys/types.h>
#include <syslog.h>
#include <debug.h>
#include <nuttx/board.h>
#include <nuttx/fs/fs.h>
#include <nuttx/leds/userled.h>
#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 */

View File

@ -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