configs/olimex-stm32-e407: Add IN219 support.

This commit is contained in:
Juan Flores 2019-07-12 07:29:03 -06:00 committed by Gregory Nutt
parent 09757bec7d
commit 3174bf4165
6 changed files with 222 additions and 0 deletions

View File

@ -89,3 +89,20 @@ Configurations
you should see a device called "dac0". Now execute the app
dac put a value at the output.
INA219:
------
This is a configuration example for the INA219 DC current sensor. This
sensor works with I2C, you need to do the next connections:
INA219 VIN -> Board 3.3V
INA219 GND -> Board GND
INA219 SCL -> Board PB6 (Arduino header D1)
INA219 SDA -> Board PB7 (Arduino header D0)
This example is configured to work with the USBNSH instead of UART NSH, so
the console will be shown over the USB_OTG1 connector.
On the console, type "ls /dev " and if the registration process goes fine,
you should see a device called "ina219". Now execute the app
ina219 to see the ambient pressure value.

View File

@ -0,0 +1,66 @@
#
# This file is autogenerated: PLEASE DO NOT EDIT IT.
#
# You can use "make menuconfig" to make any modifications to the installed .config file.
# You can then do "make savedefconfig" to generate a new defconfig file that includes your
# modifications.
#
# CONFIG_ARCH_FPU is not set
# CONFIG_DEV_CONSOLE is not set
CONFIG_ARCH="arm"
CONFIG_ARCH_BOARD="olimex-stm32-e407"
CONFIG_ARCH_BOARD_OLIMEX_STM32E407=y
CONFIG_ARCH_BUTTONS=y
CONFIG_ARCH_CHIP_STM32=y
CONFIG_ARCH_CHIP_STM32F407ZG=y
CONFIG_ARCH_STACKDUMP=y
CONFIG_BOARDCTL_USBDEVCTRL=y
CONFIG_BOARD_LATE_INITIALIZE=y
CONFIG_BOARD_LOOPSPERMSEC=16717
CONFIG_BUILTIN=y
CONFIG_CDCACM=y
CONFIG_CDCACM_CONSOLE=y
CONFIG_CDCACM_RXBUFSIZE=256
CONFIG_CDCACM_TXBUFSIZE=256
CONFIG_EXAMPLES_HELLO=y
CONFIG_EXAMPLES_INA219=y
CONFIG_FS_PROCFS=y
CONFIG_HAVE_CXX=y
CONFIG_HAVE_CXXINITIALIZE=y
CONFIG_IDLETHREAD_STACKSIZE=2048
CONFIG_INTELHEX_BINARY=y
CONFIG_MAX_TASKS=16
CONFIG_MAX_WDOGPARMS=2
CONFIG_MM_REGIONS=2
CONFIG_NFILE_DESCRIPTORS=8
CONFIG_NFILE_STREAMS=8
CONFIG_NSH_ARCHINIT=y
CONFIG_NSH_BUILTIN_APPS=y
CONFIG_NSH_FILEIOSIZE=512
CONFIG_NSH_LINELEN=64
CONFIG_NSH_READLINE=y
CONFIG_PREALLOC_MQ_MSGS=4
CONFIG_PREALLOC_TIMERS=4
CONFIG_PREALLOC_WDOGS=8
CONFIG_RAM_SIZE=114688
CONFIG_RAM_START=0x20000000
CONFIG_RAW_BINARY=y
CONFIG_RR_INTERVAL=200
CONFIG_SCHED_WAITPID=y
CONFIG_SDCLONE_DISABLE=y
CONFIG_SENSORS=y
CONFIG_SENSORS_INA219=y
CONFIG_START_DAY=27
CONFIG_START_YEAR=2013
CONFIG_STM32_I2C1=y
CONFIG_STM32_JTAG_SW_ENABLE=y
CONFIG_STM32_OTGFS=y
CONFIG_STM32_PWR=y
CONFIG_STM32_USART2=y
CONFIG_SYSLOG_CHAR=y
CONFIG_SYSLOG_DEVPATH="/dev/ttyS0"
CONFIG_SYSTEM_NSH=y
CONFIG_SYSTEM_NSH_CXXINITIALIZE=y
CONFIG_USBDEV=y
CONFIG_USER_ENTRYPOINT="nsh_main"
CONFIG_WDOG_INTRESERVE=1

View File

@ -88,5 +88,9 @@ ifeq ($(CONFIG_DAC),y)
CSRCS += stm32_dac.c
endif
ifeq ($(CONFIG_SENSORS_INA219),y)
CSRCS += stm32_ina219.c
endif
include $(TOPDIR)/configs/Board.mk

View File

@ -305,5 +305,23 @@ int stm32_bmp180initialize(FAR const char *devpath);
int stm32_dac_setup(void);
#endif
/************************************************************************************
* Name: stm32_ina219initialize
*
* Description:
* Initialize and register the INA219 voltage/current sensor.
*
* Input parameters:
* devpath - The full path to the driver to register. E.g., "/dev/ina219"
*
* Returned Value:
* Zero (OK) on success; a negated errno value on failure.
*
************************************************************************************/
#if defined(CONFIG_I2C) && defined(CONFIG_SENSORS_INA219)
int stm32_ina219initialize(FAR const char *devpath);
#endif
#endif /* __ASSEMBLY__ */
#endif /* __CONFIGS_OLIMEX_STM32_E407_SRC_INTERNAL_H */

View File

@ -239,6 +239,16 @@ int stm32_bringup(void)
}
#endif
#ifdef CONFIG_SENSORS_INA219
/* Configure and initialize the INA219 sensor */
ret = stm32_ina219initialize("/dev/ina219");
if (ret < 0)
{
syslog(LOG_ERR, "ERROR: stm32_ina219initialize() failed: %d\n", ret);
}
#endif
UNUSED(ret);
return OK;
}

View File

@ -0,0 +1,107 @@
/************************************************************************************
* configs/olimex-stm32-e407/src/stm32_ina219.c
*
* Copyright (C) 2018 Erle Robotics (Juan Flores Muñoz). All rights reserved.
* Author: Erle Robotics (Juan Flores Muñoz) <juan@erlerobotics.com>
*
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
************************************************************************************/
/************************************************************************************
* Included Files
************************************************************************************/
#include <nuttx/config.h>
#include <errno.h>
#include <syslog.h>
#include <nuttx/spi/spi.h>
#include <nuttx/sensors/ina219.h>
#include "stm32.h"
#include "stm32_i2c.h"
#include "olimex-stm32-e407.h"
#if defined(CONFIG_I2C) && defined(CONFIG_SENSORS_INA219)
/************************************************************************************
* Pre-processor Definitions
************************************************************************************/
#define INA219_I2C_PORTNO 1 /* On I2C1 */
/************************************************************************************
* Public Functions
************************************************************************************/
/************************************************************************************
* Name: stm32_ina219initialize
*
* Description:
* Initialize and register the INA219 voltage/current sensor.
*
* Input parameters:
* devpath - The full path to the driver to register. E.g., "/dev/ina219"
*
* Returned Value:
* Zero (OK) on success; a negated errno value on failure.
*
************************************************************************************/
int stm32_ina219initialize(FAR const char *devpath)
{
FAR struct i2c_master_s *i2c;
int ret;
sninfo("Initializing INA219!\n");
/* Initialize I2C */
i2c = stm32_i2cbus_initialize(INA219_I2C_PORTNO);
if (!i2c)
{
return -ENODEV;
}
/* Then register the sensor */
ret = ina219_register(devpath, i2c,0x40,100000,0x00);
if (ret < 0)
{
syslog(LOG_ERR, "ERROR: Error registering hih6130\n");
}
return ret;
}
#endif /* CONFIG_I2C && CONFIG_SENSORS_INA219 */