drivers/sensors/max31855: Add multiple max31855 sensors feature and support for bambino-200e and stm32f4discovery

This commit is contained in:
Tiago Almeida 2018-04-09 15:36:27 -06:00 committed by Gregory Nutt
parent 195c210535
commit a482867c00
13 changed files with 655 additions and 64 deletions

View File

@ -349,6 +349,38 @@
#define PINCONF_U3_RXD PINCONF_U3_RXD_2
#define PINCONF_U3_DIR PINCONF_U3_DIR_2
/* SPI Pins ****************************************************************/
/* The Bambino 200E has SPI peripheral pins reserved for SPIFI.
* SSP0 and SSP1 are available on Socket 1 and 10, respectively:
*
* --------- ---------- -----------------
* SIGNAL Socket/Pin LPC4330FBD144 PIN
* --------- ---------- -----------------
* SSP0_SCK s:1 / p:9 112 P3_0
* SSP0_SSEL s:1 / p:6 38 P1_0
* SSP0_MISO s:1 / p:8 42 P1_1
* SSP0_MOSI s:1 / p:7 43 P1_2
* SSP1_SCK s:10 / p:9 120 PF_4
* SSP1_SSEL s:10 / p:6 48 P1_5
* SSP1_MISO s:10 / p:8 44 P1_3
* SSP1_MOSI s:10 / p:7 47 P1_4
* --------- ---------- -----------------
*
* The following definitions must be provided so that the LPC43 serial
* driver can set up the SPI ports properly (see the
* file arch/arm/src/lpc43xx/lpc4310203050_pinconf.h for more info).
*/
#define PINCONF_SSP0_SCK PINCONF_SSP0_SCK_3
#define PINCONF_SSP0_SSEL PINCONF_SSP0_SSEL_3
#define PINCONF_SSP0_MISO PINCONF_SSP0_MISO_3
#define PINCONF_SSP0_MOSI PINCONF_SSP0_MOSI_3
#define PINCONF_SSP1_SCK PINCONF_SSP1_SCK_1
#define PINCONF_SSP1_SSEL PINCONF_SSP1_SSEL_3
#define PINCONF_SSP1_MISO PINCONF_SSP1_MISO_3
#define PINCONF_SSP1_MOSI PINCONF_SSP1_MOSI_3
/* Ethernet */
#define PINCONF_ENET_RX_DV PINCONF_ENET_RX_DV_2

View File

@ -0,0 +1,62 @@
# CONFIG_ARCH_FPU is not set
# CONFIG_NSH_DISABLE_IFCONFIG is not set
# CONFIG_NSH_DISABLE_PS is not set
CONFIG_ARCH_BOARD_BAMBINO_200E=y
CONFIG_ARCH_BOARD="bambino-200e"
CONFIG_ARCH_CHIP_LPC4330FBD144=y
CONFIG_ARCH_CHIP_LPC43XX=y
CONFIG_ARCH_STACKDUMP=y
CONFIG_ARCH_STDARG_H=y
CONFIG_ARCH="arm"
CONFIG_BOARD_LOOPSPERMSEC=18535
CONFIG_BOARD_INITIALIZE=y
CONFIG_BUILTIN=y
CONFIG_CDCACM=y
CONFIG_DEBUG_ERROR=y
CONFIG_DEBUG_SENSORS_ERROR=y
CONFIG_DEBUG_SYMBOLS=y
CONFIG_EXAMPLES_MAX31855=y
CONFIG_EXAMPLES_NSH=y
CONFIG_EXAMPLES_TIMER=y
CONFIG_FAT_LCNAMES=y
CONFIG_FAT_LFN=y
CONFIG_FS_FAT=y
CONFIG_LPC43_BOOT_SPIFI=y
CONFIG_LPC43_SSP0=y
CONFIG_LPC43_SSP1=y
CONFIG_LPC43_TMR0=y
CONFIG_LPC43_UART1=y
CONFIG_LPC43_USB0=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=4
CONFIG_RAM_SIZE=131072
CONFIG_RAM_START=0x10000000
CONFIG_RAW_BINARY=y
CONFIG_RR_INTERVAL=200
CONFIG_SCHED_WAITPID=y
CONFIG_SDCLONE_DISABLE=y
CONFIG_SENSORS_MAX31855=y
CONFIG_SPI=y
CONFIG_START_DAY=11
CONFIG_START_MONTH=7
CONFIG_START_YEAR=2012
CONFIG_SYMTAB_ORDEREDBYNAME=y
CONFIG_SYSTEM_CDCACM_DEVMINOR=1
CONFIG_SYSTEM_CDCACM=y
CONFIG_TASK_NAME_SIZE=0
CONFIG_TIMER=y
CONFIG_UART1_SERIAL_CONSOLE=y
CONFIG_USBDEV=y
CONFIG_USER_ENTRYPOINT="nsh_main"
CONFIG_WDOG_INTRESERVE=0

View File

@ -37,7 +37,11 @@
-include $(TOPDIR)/Make.defs
ASRCS =
CSRCS = lpc43_boot.c
CSRCS = lpc43_boot.c lpc43_ssp.c
ifeq ($(CONFIG_SENSORS_MAX31855),y)
CSRCS += lpc43_max31855.c
endif
ifeq ($(CONFIG_LIB_BOARDCTL),y)
CSRCS += lpc43_appinit.c

View File

@ -1,7 +1,7 @@
/****************************************************************************
* configs/bambino-200e/src/bambino-200e.h
*
* Copyright (C) 2016 Gregory Nutt. All rights reserved.
* Copyright (C) 2016, 2018 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
* Alan Carvalho de Assis acassis@gmail.com [nuttx] <nuttx@yahoogroups.com>
*
@ -70,8 +70,10 @@
#define PINCONFIG_LED1 PINCONF_GPIO3p7
#define PINCONFIG_LED2 PINCONF_GPIO5p5
#define GPIO_LED1 (GPIO_MODE_OUTPUT | GPIO_VALUE_ONE | GPIO_PORT3 | GPIO_PIN7)
#define GPIO_LED2 (GPIO_MODE_OUTPUT | GPIO_VALUE_ONE | GPIO_PORT5 | GPIO_PIN5)
#define GPIO_LED1 (GPIO_MODE_OUTPUT | GPIO_VALUE_ONE | GPIO_PORT3 | \
GPIO_PIN7)
#define GPIO_LED2 (GPIO_MODE_OUTPUT | GPIO_VALUE_ONE | GPIO_PORT5 | \
GPIO_PIN5)
/****************************************************************************
* Buttons GPIO
@ -90,6 +92,15 @@
#define GPIO_SSP0_MISO GPIO_SSP0_MISO_1
#define GPIO_SSP0_MOSI GPIO_SSP0_MOSI_1
/* Max31855 Chip Select pins */
#define PINCONFIG_MAX31855_CS1 PINCONF_GPIO0p4
#define PINCONFIG_MAX31855_CS2 PINCONF_GPIO1p8
#define GPIO_MAX31855_CS1 (GPIO_MODE_OUTPUT | GPIO_VALUE_ONE | \
GPIO_PORT0 | GPIO_PIN4)
#define GPIO_MAX31855_CS2 (GPIO_MODE_OUTPUT | GPIO_VALUE_ONE | \
GPIO_PORT1 | GPIO_PIN8)
/* We need to redefine USB_PWRD as GPIO to get USB Host working
* Also remember to add 2 resistors of 15K to D+ and D- pins.
*/
@ -130,7 +141,6 @@
# undef HAVE_MMCSD
#endif
/****************************************************************************
* Public Types
****************************************************************************/
@ -149,12 +159,32 @@
* Name: lpc43_sspdev_initialize
*
* Description:
* Called to configure SPI chip select GPIO pins for the Lincoln 80 board.
* Called to configure SPI chip select GPIO pins for the Bambino-200e
* board.
*
****************************************************************************/
void weak_function lpc43_sspdev_initialize(void);
/************************************************************************************
* Name: lpc43_max31855initialize
*
* Description:
* Initialize and register the MAX31855 Temperature Sensor driver.
*
* Input parameters:
* devpath - The full path to the driver to register. E.g., "/dev/temp0"
* spi - An instance of the SPI interface to use to communicate with
* MAX31855
* devid - Minor device number. E.g., 0, 1, 2, etc.
*
* Returned Value:
* Zero (OK) on success; a negated errno value on failure.
*
************************************************************************************/
int lpc43_max31855initialize(FAR const char *devpath, int bus, uint16_t devid);
/************************************************************************************
* Name: lpc43xx_timerinitialize()
*

View File

@ -1,7 +1,7 @@
/************************************************************************************
* configs/bambino-200e/src/lpc43_boot.c
*
* Copyright (C) 2016 Gregory Nutt. All rights reserved.
* Copyright (C) 2016, 2018 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
* Alan Carvalho de Assis acassis@gmail.com [nuttx] <nuttx@yahoogroups.com>
*
@ -50,6 +50,22 @@
#include "bambino-200e.h"
/****************************************************************************
* Public Types
****************************************************************************/
enum devid_e
{
DEVID0 = 0,
DEVID1
};
enum ssp_channel_e
{
SSP0 = 0,
SSP1
};
/************************************************************************************
* Public Functions
************************************************************************************/
@ -58,9 +74,9 @@
* Name: lpc43_boardinitialize
*
* Description:
* All LPC43xx architectures must provide the following entry point. This entry point
* is called early in the intitialization -- after all memory has been configured
* and mapped but before any devices have been initialized.
* All LPC43xx architectures must provide the following entry point. This entry
* point is called early in the initialization -- after all memory has been
* configured and mapped but before any devices have been initialized.
*
************************************************************************************/
@ -71,4 +87,67 @@ void lpc43_boardinitialize(void)
#ifdef CONFIG_ARCH_LEDS
board_autoled_initialize();
#endif
/* Configure SSP chip selects if 1) Any SSP channel is not disabled, and 2) the
* weak function lpc43_sspdev_initialize() has been brought into the link.
*/
#if defined(CONFIG_LPC43_SSP0) || defined(CONFIG_LPC43_SSP1)
if (lpc43_sspdev_initialize)
{
lpc43_sspdev_initialize();
}
#endif
}
/****************************************************************************
* Name: board_initialize
*
* Description:
* If CONFIG_BOARD_INITIALIZE is selected, then an additional
* initialization call will be performed in the boot-up sequence to a
* function called board_initialize(). board_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_INITIALIZE
void board_initialize(void)
{
/* Configure max31855 driver for SSP0 or SSP1 */
#if defined(CONFIG_SENSORS_MAX31855)
int ret;
#if defined(CONFIG_LPC43_SSP0)
ret = lpc43_max31855initialize("/dev/temp0", SSP0, DEVID0);
if (ret < 0)
{
serr("ERROR: lpc43_max31855initialize failed: %d\n", ret);
}
ret = lpc43_max31855initialize("/dev/temp1", SSP0, DEVID1);
if (ret < 0)
{
serr("ERROR: lpc43_max31855initialize failed: %d\n", ret);
}
#endif
#if defined(CONFIG_LPC43_SSP1)
ret = lpc43_max31855initialize("/dev/temp2", SSP1, DEVID0);
if (ret < 0)
{
serr("ERROR: lpc43_max31855initialize failed: %d\n", ret);
}
ret = lpc43_max31855initialize("/dev/temp3", SSP1, DEVID1);
if (ret < 0)
{
serr("ERROR: lpc43_max31855initialize failed: %d\n", ret);
}
#endif
#endif
}
#endif

View File

@ -0,0 +1,103 @@
/************************************************************************************
* configs/bambino-200e/src/lpc43_max31855.c
*
* Copyright (C) 2015 Alan Carvalho de Assis. All rights reserved.
* Author: Alan Carvalho de Assis <acassis@gmail.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 <debug.h>
#include <string.h>
#include <nuttx/sensors/max31855.h>
#include "bambino-200e.h"
#include <nuttx/spi/spi.h>
#include "lpc43_spi.h"
#include "lpc43_ssp.h"
#include <nuttx/kmalloc.h>
#include <nuttx/fs/fs.h>
#include <nuttx/random.h>
#if defined(CONFIG_SPI) && defined(CONFIG_SENSORS_MAX31855)
/************************************************************************************
* Public Functions
************************************************************************************/
/************************************************************************************
* Name: lpc43_max31855initialize
*
* Description:
* Initialize and register the MAX31855 Temperature Sensor driver.
*
* Input parameters:
* devpath - The full path to the driver to register. E.g., "/dev/temp0"
* spi - An instance of the SPI interface to use to communicate with
* MAX31855
* devid - Minor device number. E.g., 0, 1, 2, etc.
* Returned Value:
* Zero (OK) on success; a negated errno value on failure.
*
************************************************************************************/
int lpc43_max31855initialize(FAR const char *devpath, int bus, uint16_t devid)
{
FAR struct spi_dev_s *spi;
spi = lpc43_sspbus_initialize(bus);
if (!spi)
{
snerr("ERROR: Failed to initialize SSP%d\n", bus);
return -ENODEV;
}
/* Then register the temperature sensor */
int ret = max31855_register(devpath, spi, devid);
if (ret < 0)
{
snerr("ERROR: Error registering MAX31855\n");
}
return ret;
}
#endif /* CONFIG_SPI && CONFIG_SENSORS_MAX31855 */

View File

@ -0,0 +1,185 @@
/************************************************************************************
* configs/bambino-200e/src/lpc43_ssp.c
*
* Copyright (C) 2011-2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* 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 <debug.h>
#include <string.h>
#include "lpc43_spi.h"
#include "lpc43_ssp.h"
#include <nuttx/spi/spi.h>
#include <arch/board/board.h>
#include "bambino-200e.h"
#include <nuttx/kmalloc.h>
#include <nuttx/fs/fs.h>
#include <nuttx/random.h>
/************************************************************************************
* Public Functions
************************************************************************************/
/****************************************************************************
* Name: lpc43_sspdev_initialize
*
* Description:
* Called to configure SPI chip select GPIO pins for the Bambino-200e board.
*
****************************************************************************/
void weak_function lpc43_sspdev_initialize(void)
{
#ifdef CONFIG_SENSORS_MAX31855
lpc43_pin_config(PINCONFIG_MAX31855_CS1);
int ret = lpc43_gpio_config(GPIO_MAX31855_CS1);
if (ret < 0)
{
snerr("ERROR: Error configuring chip select GPIO pin\n");
}
lpc43_pin_config(PINCONFIG_MAX31855_CS2);
ret = lpc43_gpio_config(GPIO_MAX31855_CS2);
if (ret < 0)
{
snerr("ERROR: Error configuring chip select GPIO pin\n")
}
#endif
}
/************************************************************************************
* Name: lpc43_ssp0select
*
* Description:
* Perform chip selection using GPIO pins, controlling data flow in SSP0 channel.
*
* Input parameters:
* devpath - The full path to the driver. E.g., "/dev/temp0"
* devid - Minor device number. E.g., 0, 1, 2, etc.
* selected - Logical state of the pin
*
************************************************************************************/
void lpc43_ssp0select(FAR struct spi_dev_s *dev, uint32_t devid, bool selected)
{
spiinfo("devid: %d CS: %s\n", (int)devid, selected ? "assert" : "de-assert");
#if defined(CONFIG_SENSORS_MAX31855)
if (devid == SPIDEV_TEMPERATURE(0))
{
lpc43_gpio_write(GPIO_MAX31855_CS1, !selected);
}
if (devid == SPIDEV_TEMPERATURE(1))
{
lpc43_gpio_write(GPIO_MAX31855_CS2, !selected);
}
#endif
}
/************************************************************************************
* Name: lpc43_ssp0status
*
* Description:
* Perform status operations in SSP0 channel, using GPIO pins.
*
* Input parameters:
* devpath - The full path to the driver. E.g., "/dev/temp0"
* devid - Minor device number. E.g., 0, 1, 2, etc.
*
* Returned Value:
* Zero
************************************************************************************/
uint8_t lpc43_ssp0status(FAR struct spi_dev_s *dev, uint32_t devid)
{
return 0;
}
/************************************************************************************
* Name: lpc43_ssp1select
*
* Description:
* Perform chip selection using GPIO pins, controlling data flow in SSP1 channel.
*
* Input parameters:
* devpath - The full path to the driver. E.g., "/dev/temp0"
* devid - Minor device number. E.g., 0, 1, 2, etc.
* selected - Logical state of the pin
*
************************************************************************************/
void lpc43_ssp1select(FAR struct spi_dev_s *dev, uint32_t devid, bool selected)
{
spiinfo("devid: %d CS: %s\n", (int)devid, selected ? "assert" : "de-assert");
#if defined(CONFIG_SENSORS_MAX31855)
if (devid == SPIDEV_TEMPERATURE(0))
{
lpc43_gpio_write(GPIO_MAX31855_CS1, !selected);
}
if (devid == SPIDEV_TEMPERATURE(1))
{
lpc43_gpio_write(GPIO_MAX31855_CS2, !selected);
}
#endif
}
/************************************************************************************
* Name: lpc43_ssp1status
*
* Description:
* Perform status operations in SSP1 channel, using GPIO pins.
*
* Input parameters:
* devpath - The full path to the driver. E.g., "/dev/temp0"
* devid - Minor device number. E.g., 0, 1, 2, etc.
*
* Returned Value:
* Zero
************************************************************************************/
uint8_t lpc43_ssp1status(FAR struct spi_dev_s *dev, uint32_t devid)
{
return 0;
}

View File

@ -0,0 +1,60 @@
# CONFIG_ARCH_FPU is not set
# CONFIG_NSH_ARGCAT is not set
# CONFIG_NSH_CMDOPT_DF_H is not set
# CONFIG_NSH_CMDOPT_HEXDUMP is not set
# CONFIG_NSH_CMDPARMS is not set
CONFIG_ARCH_BOARD_STM32F4_DISCOVERY=y
CONFIG_ARCH_BOARD="stm32f4discovery"
CONFIG_ARCH_BUTTONS=y
CONFIG_ARCH_CHIP_STM32=y
CONFIG_ARCH_CHIP_STM32F407VG=y
CONFIG_ARCH_STACKDUMP=y
CONFIG_ARCH="arm"
CONFIG_ARMV7M_TOOLCHAIN_CODESOURCERYW=y
CONFIG_BOARD_LOOPSPERMSEC=16717
CONFIG_BOARD_INITIALIZE=y
CONFIG_BUILTIN=y
CONFIG_DEBUG_ERROR=y
CONFIG_DEBUG_SENSORS_ERROR=y
CONFIG_DISABLE_POLL=y
CONFIG_EXAMPLES_MAX31855=y
CONFIG_EXAMPLES_NSH_CXXINITIALIZE=y
CONFIG_EXAMPLES_NSH=y
CONFIG_FS_PROCFS=y
CONFIG_HAVE_CXX=y
CONFIG_HAVE_CXXINITIALIZE=y
CONFIG_HOST_WINDOWS=y
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_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=16
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_MAX31855=y
CONFIG_SPI=y
CONFIG_START_DAY=6
CONFIG_START_MONTH=12
CONFIG_START_YEAR=2011
CONFIG_STM32_JTAG_SW_ENABLE=y
CONFIG_STM32_OTGFS=y
CONFIG_STM32_PWR=y
CONFIG_STM32_SPI1=y
CONFIG_STM32_SPI2=y
CONFIG_STM32_USART2=y
CONFIG_USART2_RXBUFSIZE=128
CONFIG_USART2_SERIAL_CONSOLE=y
CONFIG_USART2_TXBUFSIZE=128
CONFIG_USER_ENTRYPOINT="nsh_main"

View File

@ -1,7 +1,7 @@
/****************************************************************************
* config/stm32f4discovery/src/stm32_bringup.c
*
* Copyright (C) 2012, 2014-2017 Gregory Nutt. All rights reserved.
* Copyright (C) 2012, 2014-2018 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -290,7 +290,9 @@ int stm32_bringup(void)
#endif
#ifdef CONFIG_SENSORS_MAX31855
ret = stm32_max31855initialize("/dev/temp0");
/* Register device 0 on spi channel 2 */
ret = stm32_max31855initialize("/dev/temp0", 2, 0);
if (ret < 0)
{
serr("ERROR: stm32_max31855initialize failed: %d\n", ret);

View File

@ -51,12 +51,6 @@
#if defined(CONFIG_SPI) && defined(CONFIG_SENSORS_MAX31855) && defined(CONFIG_STM32_SPI2)
/************************************************************************************
* Pre-processor Definitions
************************************************************************************/
#define MAX31855_SPI_PORTNO 2 /* On SPI2 */
/************************************************************************************
* Public Functions
************************************************************************************/
@ -68,19 +62,21 @@
* Initialize and register the MAX31855 Temperature Sensor driver.
*
* Input Parameters:
* devpath - The full path to the driver to register. E.g., "/dev/temp0"
* devpath - The full path to the driver to register. E.g., "/dev/temp0"
* bus - Bus number (for hardware that has mutiple SPI interfaces)
* devid - ID associated to the device. E.g., 0, 1, 2, etc.
*
* Returned Value:
* Zero (OK) on success; a negated errno value on failure.
*
************************************************************************************/
int stm32_max31855initialize(FAR const char *devpath)
int stm32_max31855initialize(FAR const char *devpath, int bus, uint16_t devid)
{
FAR struct spi_dev_s *spi;
int ret;
spi = stm32_spibus_initialize(MAX31855_SPI_PORTNO);
spi = stm32_spibus_initialize(bus);
if (!spi)
{
@ -89,7 +85,7 @@ int stm32_max31855initialize(FAR const char *devpath)
/* Then register the barometer sensor */
ret = max31855_register(devpath, spi);
ret = max31855_register(devpath, spi, devid);
if (ret < 0)
{
snerr("ERROR: Error registering MAX31855\n");

View File

@ -1,7 +1,8 @@
/****************************************************************************
* configs/stm32f4discovery/src/stm32f4discovery.h
*
* Copyright (C) 2011-2012, 2015-2016 Gregory Nutt. All rights reserved.
* Copyright (C) 2011-2012, 2015-2016, 2018 Gregory Nutt. All rights
* reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -48,7 +49,8 @@
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* Configuration *************************************************************/
/* Configuration ************************************************************/
/* Define what timer and channel to use as XEN1210 CLK */
@ -233,7 +235,7 @@
#define GPIO_BTN_USER (GPIO_INPUT|GPIO_FLOAT|GPIO_EXTI|GPIO_PORTA|GPIO_PIN0)
/* ZERO CROSS pin definiton */
/* ZERO CROSS pin definition */
#define GPIO_ZEROCROSS (GPIO_INPUT|GPIO_FLOAT|GPIO_EXTI|GPIO_PORTD|GPIO_PIN0)
@ -256,16 +258,16 @@
#define GPIO_MAX31855_CS (GPIO_OUTPUT|GPIO_PUSHPULL|GPIO_SPEED_50MHz|\
GPIO_OUTPUT_SET|GPIO_PORTD|GPIO_PIN8)
#define GPIO_MAX6675_CS (GPIO_OUTPUT|GPIO_PUSHPULL|GPIO_SPEED_50MHz|\
#define GPIO_MAX6675_CS (GPIO_OUTPUT|GPIO_PUSHPULL|GPIO_SPEED_50MHz|\
GPIO_OUTPUT_SET|GPIO_PORTD|GPIO_PIN8)
/* XEN1210 magnetic sensor */
#define GPIO_XEN1210_INT (GPIO_INPUT|GPIO_FLOAT|GPIO_EXTI|\
GPIO_OPENDRAIN|GPIO_PORTA|GPIO_PIN5)
#define GPIO_XEN1210_INT (GPIO_INPUT|GPIO_FLOAT|GPIO_EXTI|\
GPIO_OPENDRAIN|GPIO_PORTA|GPIO_PIN5)
#define GPIO_CS_XEN1210 (GPIO_OUTPUT|GPIO_PUSHPULL|GPIO_SPEED_50MHz|\
GPIO_OUTPUT_SET|GPIO_PORTA|GPIO_PIN4)
#define GPIO_CS_XEN1210 (GPIO_OUTPUT|GPIO_PUSHPULL|GPIO_SPEED_50MHz|\
GPIO_OUTPUT_SET|GPIO_PORTA|GPIO_PIN4)
/* USB OTG FS
*
@ -283,7 +285,6 @@
# define GPIO_OTGFS_OVER (GPIO_INPUT|GPIO_EXTI|GPIO_FLOAT|\
GPIO_SPEED_100MHz|GPIO_PUSHPULL|\
GPIO_PORTD|GPIO_PIN5)
#else
# define GPIO_OTGFS_OVER (GPIO_INPUT|GPIO_FLOAT|GPIO_SPEED_100MHz|\
GPIO_PUSHPULL|GPIO_PORTD|GPIO_PIN5)
@ -324,13 +325,13 @@
/* Display JLX12864G */
#define STM32_LCD_RST (GPIO_OUTPUT|GPIO_PUSHPULL|GPIO_SPEED_50MHz|\
#define STM32_LCD_RST (GPIO_OUTPUT|GPIO_PUSHPULL|GPIO_SPEED_50MHz|\
GPIO_OUTPUT_SET|GPIO_PORTB|GPIO_PIN6)
#define STM32_LCD_CS (GPIO_OUTPUT|GPIO_PUSHPULL|GPIO_SPEED_50MHz|\
#define STM32_LCD_CS (GPIO_OUTPUT|GPIO_PUSHPULL|GPIO_SPEED_50MHz|\
GPIO_OUTPUT_SET|GPIO_PORTB|GPIO_PIN7)
#define STM32_LCD_RS (GPIO_OUTPUT|GPIO_PUSHPULL|GPIO_SPEED_50MHz|\
#define STM32_LCD_RS (GPIO_OUTPUT|GPIO_PUSHPULL|GPIO_SPEED_50MHz|\
GPIO_OUTPUT_SET|GPIO_PORTB|GPIO_PIN8)
/* STM32F4DIS-BB MicroSD
@ -428,14 +429,14 @@ void weak_function stm32_spidev_initialize(void);
*
****************************************************************************/
FAR struct i2s_dev_s *stm32_i2sdev_initialize(int port);
FAR struct i2s_dev_s *stm32_i2sdev_initialize(int port);
/****************************************************************************
* Name: stm32_bh1750initialize
*
* Description:
* Called to configure an I2C and to register BH1750FVI for the stm32f4discovery
* board.
* Called to configure an I2C and to register BH1750FVI for the
* stm32f4discovery board.
*
****************************************************************************/
@ -447,8 +448,8 @@ int stm32_bh1750initialize(FAR const char *devpath);
* Name: stm32_bmp180initialize
*
* Description:
* Called to configure an I2C and to register BMP180 for the stm32f4discovery
* board.
* Called to configure an I2C and to register BMP180 for the
* stm32f4discovery board.
*
****************************************************************************/
@ -460,8 +461,8 @@ int stm32_bmp180initialize(FAR const char *devpath);
* Name: stm32_lis3dshinitialize
*
* Description:
* Called to configure SPI 1, and to register LIS3DSH and its external interrupt
* for the stm32f4discovery board.
* Called to configure SPI 1, and to register LIS3DSH and its external
* interrupt for the stm32f4discovery board.
*
****************************************************************************/
@ -548,7 +549,7 @@ void stm32_extmemgpios(const uint32_t *gpios, int ngpios);
* Name: stm32_extmemaddr
*
* Description:
* Initialize adress line GPIOs for external memory access
* Initialize address line GPIOs for external memory access
*
****************************************************************************/
@ -614,7 +615,8 @@ void stm32_led_pminitialize(void);
*
****************************************************************************/
#if defined(CONFIG_PM) && defined(CONFIG_ARCH_IDLE_CUSTOM) && defined(CONFIG_PM_BUTTONS)
#if defined(CONFIG_PM) && defined(CONFIG_ARCH_IDLE_CUSTOM) && \
defined(CONFIG_PM_BUTTONS)
void stm32_pm_buttons(void);
#endif
@ -666,6 +668,27 @@ int stm32_qencoder_initialize(FAR const char *devpath, int timer);
int stm32_zerocross_initialize(void);
#endif
/****************************************************************************
* Name: stm32_max31855initialize
*
* Description:
* Initialize and register the MAX31855 Temperature Sensor driver.
*
* Input Parameters:
* devpath - The full path to the driver to register. E.g., "/dev/temp0"
* bus - Bus number (for hardware that has mutiple SPI interfaces)
* devid - ID associated to the device. E.g., 0, 1, 2, etc.
*
* Returned Value:
* Zero (OK) on success; a negated errno value on failure.
*
****************************************************************************/
#ifdef CONFIG_SENSORS_MAX31855
int stm32_max31855initialize(FAR const char *devpath, int bus,
uint16_t devid);
#endif
/****************************************************************************
* Name: stm32_max6675initialize
*
@ -683,8 +706,9 @@ int stm32_max6675initialize(FAR const char *devpath);
*
* Description:
* This function is called by platform-specific, setup logic to configure
* and register the CS43L22 device. This function will register the driver
* as /dev/cs43l22[x] where x is determined by the minor device number.
* and register the CS43L22 device. This function will register the
* driver as /dev/cs43l22[x] where x is determined by the minor device
* number.
*
* Input Parameters:
* minor - The input device minor number

View File

@ -77,9 +77,9 @@ struct max31855_dev_s
{
FAR struct spi_dev_s *spi; /* Saved SPI driver instance */
int16_t temp;
uint16_t devid; /* Select minor device number */
};
/****************************************************************************
* Private Function Prototypes
****************************************************************************/
@ -177,7 +177,8 @@ static int max31855_close(FAR struct file *filep)
* Name: max31855_read
****************************************************************************/
static ssize_t max31855_read(FAR struct file *filep, FAR char *buffer, size_t buflen)
static ssize_t max31855_read(FAR struct file *filep, FAR char *buffer,
size_t buflen)
{
FAR struct inode *inode = filep->f_inode;
FAR struct max31855_dev_s *priv = inode->i_private;
@ -203,7 +204,7 @@ static ssize_t max31855_read(FAR struct file *filep, FAR char *buffer, size_t bu
/* Enable MAX31855's chip select */
max31855_lock(priv->spi);
SPI_SELECT(priv->spi, SPIDEV_TEMPERATURE(0), true);
SPI_SELECT(priv->spi, SPIDEV_TEMPERATURE(priv->devid), true);
/* Read temperature */
@ -211,9 +212,18 @@ static ssize_t max31855_read(FAR struct file *filep, FAR char *buffer, size_t bu
/* Disable MAX31855's chip select */
SPI_SELECT(priv->spi, SPIDEV_TEMPERATURE(0), false);
SPI_SELECT(priv->spi, SPIDEV_TEMPERATURE(priv->devid), false);
max31855_unlock(priv->spi);
/* Detect any errors during SPI transmission */
if (!(regmsb) || regmsb == -1)
{
snerr("ERROR: Data transmission failed on device %d:\n", priv->devid);
snerr(" One or more MAX31855 pins are not properly connected!\n\n");
return -EINVAL;
}
regval = (regmsb & 0xFF000000) >> 24;
regval |= (regmsb & 0xFF0000) >> 8;
regval |= (regmsb & 0xFF00) << 8;
@ -257,7 +267,7 @@ static ssize_t max31855_read(FAR struct file *filep, FAR char *buffer, size_t bu
snerr(" The thermocouple input is not connected!\n");
}
ret = -EINVAL;
return -EINVAL;
}
/* Return two bytes, the temperature is fixed point Q12.2, then divide by 4
@ -285,21 +295,23 @@ static ssize_t max31855_write(FAR struct file *filep, FAR const char *buffer,
* Name: max31855_register
*
* Description:
* Register the MAX31855 character device as 'devpath'
* This function will register the max31855 driver as /dev/tempN
* where N is the minor device number
*
* Input Parameters:
* devpath - The full path to the driver to register. E.g., "/dev/temp0"
* i2c - An instance of the I2C interface to use to communicate wit
* MAX31855 addr - The I2C address of the MAX31855. The base I2C address
* of the MAX31855 is 0x48. Bits 0-3 can be controlled to get 8 unique
* addresses from 0x48 through 0x4f.
* devpath - The full path to the driver to register. E.g., "/dev/temp0"
* spi - An instance of the SPI interface to use to communicate with
* MAX31855
* devid - Minor device number. E.g., 0, 1, 2, etc.
*
* Returned Value:
* Zero (OK) on success; a negated errno value on failure.
* Zero is returned on success. Otherwise, a negated errno value is
* returned to indicate the nature of the failure.
*
****************************************************************************/
int max31855_register(FAR const char *devpath, FAR struct spi_dev_s *spi)
int max31855_register(FAR const char *devpath, FAR struct spi_dev_s *spi,
uint16_t devid)
{
FAR struct max31855_dev_s *priv;
int ret;
@ -317,8 +329,9 @@ int max31855_register(FAR const char *devpath, FAR struct spi_dev_s *spi)
return -ENOMEM;
}
priv->spi = spi;
priv->temp = 0;
priv->spi = spi;
priv->temp = 0;
priv->devid = devid;
/* Register the character driver */

View File

@ -73,13 +73,14 @@ extern "C"
* Name: max31855_register
*
* Description:
* This function will register the max31855 driver as /dev/tempN
* where N is the minor device number
* This function will register the max31855 driver as /dev/tempN
* where N is the minor device number.
*
* Input Parameters:
* devpath - The full path to the driver to register. E.g., "/dev/temp0"
* devpath - The full path to the driver to register. E.g., "/dev/temp0"
* spi - An instance of the SPI interface to use to communicate with
* MAX31855
* devid - Minor device number. E.g., 0, 1, 2, etc.
*
* Returned Value:
* Zero is returned on success. Otherwise, a negated errno value is
@ -87,7 +88,7 @@ extern "C"
*
****************************************************************************/
int max31855_register(FAR const char *devpath, FAR struct spi_dev_s *spi);
int max31855_register(FAR const char *devpath, FAR struct spi_dev_s *spi, uint16_t devid);
#undef EXTERN
#ifdef __cplusplus