From b9638de3887d6a715c95bb4ee311ab4c52c33ff0 Mon Sep 17 00:00:00 2001 From: Guillherme Amaral Date: Fri, 20 Dec 2019 13:04:34 -0600 Subject: [PATCH] boards/arm/stm32f0l0g0/nucleo-g070rb: Enable I2C. --- .../arm/stm32f0l0g0/nucleo-g070rb/README.txt | 1 + .../nucleo-g070rb/configs/nsh/defconfig | 5 ++ .../nucleo-g070rb/src/stm32_bringup.c | 65 +++++++++++++++++++ 3 files changed, 71 insertions(+) diff --git a/boards/arm/stm32f0l0g0/nucleo-g070rb/README.txt b/boards/arm/stm32f0l0g0/nucleo-g070rb/README.txt index 73c0433a05..932a2700be 100644 --- a/boards/arm/stm32f0l0g0/nucleo-g070rb/README.txt +++ b/boards/arm/stm32f0l0g0/nucleo-g070rb/README.txt @@ -12,3 +12,4 @@ STATUS 2019-10-04: Enable basic timer TIM6. Timer example working. 2019-10-17: Add PWM support. PWM example working. 2019-11-04: Add button driver and GPIO driver support. Buttons and GPIO examples working. + 2019-12-20: Add i2C driver driver support and i2C tool. diff --git a/boards/arm/stm32f0l0g0/nucleo-g070rb/configs/nsh/defconfig b/boards/arm/stm32f0l0g0/nucleo-g070rb/configs/nsh/defconfig index 28436658c3..da26cc3e4c 100644 --- a/boards/arm/stm32f0l0g0/nucleo-g070rb/configs/nsh/defconfig +++ b/boards/arm/stm32f0l0g0/nucleo-g070rb/configs/nsh/defconfig @@ -34,6 +34,9 @@ CONFIG_EXAMPLES_GPIO=y CONFIG_EXAMPLES_HELLO=y CONFIG_EXAMPLES_PWM=y CONFIG_EXAMPLES_TIMER=y +CONFIG_I2C=y +CONFIG_I2CTOOL_MAXADDR=0xff +CONFIG_I2CTOOL_MINADDR=0x00 CONFIG_INPUT=y CONFIG_INTELHEX_BINARY=y CONFIG_MAX_TASKS=8 @@ -60,6 +63,7 @@ CONFIG_START_DAY=19 CONFIG_START_MONTH=5 CONFIG_START_YEAR=2013 CONFIG_STDIO_DISABLE_BUFFERING=y +CONFIG_STM32F0L0G0_I2C1=y CONFIG_STM32F0L0G0_PWM_MULTICHAN=y CONFIG_STM32F0L0G0_PWR=y CONFIG_STM32F0L0G0_TIM14=y @@ -100,6 +104,7 @@ CONFIG_STM32F0L0G0_TIM3_CHANNEL4=y CONFIG_STM32F0L0G0_TIM3_PWM=y CONFIG_STM32F0L0G0_TIM6=y CONFIG_STM32F0L0G0_USART2=y +CONFIG_SYSTEM_I2CTOOL=y CONFIG_SYSTEM_NSH=y CONFIG_TASK_NAME_SIZE=0 CONFIG_TASK_SPAWN_DEFAULT_STACKSIZE=1536 diff --git a/boards/arm/stm32f0l0g0/nucleo-g070rb/src/stm32_bringup.c b/boards/arm/stm32f0l0g0/nucleo-g070rb/src/stm32_bringup.c index 53c640ca90..e3a4263ab2 100644 --- a/boards/arm/stm32f0l0g0/nucleo-g070rb/src/stm32_bringup.c +++ b/boards/arm/stm32f0l0g0/nucleo-g070rb/src/stm32_bringup.c @@ -3,6 +3,10 @@ * * Copyright (C) 2019 Gregory Nutt. All rights reserved. * Author: Daniel Pereira Volpato + * Guillherme da Silva Amaral + * + * Based on: boards/arm/stm32h7/stm32h747i-disco/src/stm32_bringup.c + * Author: Gregory Nutt * * Based on: boards/arm/stm32f0l0g0/nucleo-g071rb/src/stm32_bringup.c * Author: Mateusz Szafoni @@ -50,6 +54,7 @@ #include #include "nucleo-g070rb.h" +#include "stm32_i2c.h" /**************************************************************************** * Pre-processor Definitions @@ -69,6 +74,62 @@ # define HAVE_DAC2 1 #endif +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: stm32_i2c_register + * + * Description: + * Register one I2C drivers for the I2C tool. + * + ****************************************************************************/ + +#if defined(CONFIG_I2C) && defined(CONFIG_SYSTEM_I2CTOOL) +static void stm32_i2c_register(int bus) +{ + struct i2c_master_s *i2c; + int ret; + + i2c = stm32_i2cbus_initialize(bus); + if (i2c == NULL) + { + syslog(LOG_ERR, "ERROR: Failed to get I2C%d interface\n", bus); + } + else + { + ret = i2c_register(i2c, bus); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: Failed to register I2C%d driver: %d\n", + bus, ret); + stm32_i2cbus_uninitialize(i2c); + } + } +} +#endif + +/**************************************************************************** + * Name: stm32_i2ctool + * + * Description: + * Register I2C drivers for the I2C tool. + * + ****************************************************************************/ + +#if defined(CONFIG_I2C) && defined(CONFIG_SYSTEM_I2CTOOL) +static void stm32_i2ctool(void) +{ +#ifdef CONFIG_STM32F0L0G0_I2C1 + stm32_i2c_register(1); +#endif +#ifdef CONFIG_STM32F0L0G0_I2C2 + stm32_i2c_register(2); +#endif +} +#endif + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -102,6 +163,10 @@ int stm32_bringup(void) } #endif +#if defined(CONFIG_I2C) && defined(CONFIG_SYSTEM_I2CTOOL) + stm32_i2ctool(); +#endif + #ifdef CONFIG_BUTTONS /* Register the BUTTON driver */