configs/stm32l4r9ai-disco: Add ksh config, some updates for I2C, SPI and DFSDM support.

This commit is contained in:
Juha Niskanen 2019-05-28 09:31:36 -06:00 committed by Gregory Nutt
parent 7214f8ae76
commit c9ecd548e0
24 changed files with 802 additions and 102 deletions

View File

@ -54,7 +54,7 @@
* Alignment of the user space FLASH partition is also a critical factor: * Alignment of the user space FLASH partition is also a critical factor:
* The user space FLASH partition will be spanned with a single region of * The user space FLASH partition will be spanned with a single region of
* size 2**n bytes. The alignment of the user-space region must be the same. * size 2**n bytes. The alignment of the user-space region must be the same.
* As a consequence, as the user-space increases in size, the alignmment * As a consequence, as the user-space increases in size, the alignment
* requirement also increases. * requirement also increases.
* *
* This alignment requirement means that the largest user space FLASH region * This alignment requirement means that the largest user space FLASH region

View File

@ -54,7 +54,7 @@
* Alignment of the user space FLASH partition is also a critical factor: * Alignment of the user space FLASH partition is also a critical factor:
* The user space FLASH partition will be spanned with a single region of * The user space FLASH partition will be spanned with a single region of
* size 2**n bytes. The alignment of the user-space region must be the same. * size 2**n bytes. The alignment of the user-space region must be the same.
* As a consequence, as the user-space increases in size, the alignmment * As a consequence, as the user-space increases in size, the alignment
* requirement also increases. * requirement also increases.
* *
* This alignment requirement means that the largest user space FLASH region * This alignment requirement means that the largest user space FLASH region

View File

@ -54,7 +54,7 @@
* Alignment of the user space FLASH partition is also a critical factor: * Alignment of the user space FLASH partition is also a critical factor:
* The user space FLASH partition will be spanned with a single region of * The user space FLASH partition will be spanned with a single region of
* size 2**n bytes. The alignment of the user-space region must be the same. * size 2**n bytes. The alignment of the user-space region must be the same.
* As a consequence, as the user-space increases in size, the alignmment * As a consequence, as the user-space increases in size, the alignment
* requirement also increases. * requirement also increases.
* *
* This alignment requirement means that the largest user space FLASH region * This alignment requirement means that the largest user space FLASH region

View File

@ -54,7 +54,7 @@
* Alignment of the user space FLASH partition is also a critical factor: * Alignment of the user space FLASH partition is also a critical factor:
* The user space FLASH partition will be spanned with a single region of * The user space FLASH partition will be spanned with a single region of
* size 2**n bytes. The alignment of the user-space region must be the same. * size 2**n bytes. The alignment of the user-space region must be the same.
* As a consequence, as the user-space increases in size, the alignmment * As a consequence, as the user-space increases in size, the alignment
* requirement also increases. * requirement also increases.
* *
* This alignment requirement means that the largest user space FLASH region * This alignment requirement means that the largest user space FLASH region

View File

@ -48,7 +48,7 @@
* Alignment of the user space FLASH partition is a critical factor: The * Alignment of the user space FLASH partition is a critical factor: The
* user space FLASH partition will be spanned with a single region of size * user space FLASH partition will be spanned with a single region of size
* 2**n bytes. The alignment of the user-space region must be the same. As * 2**n bytes. The alignment of the user-space region must be the same. As
* a consequence, as the user-space increases in size, the alignmment * a consequence, as the user-space increases in size, the alignment
* requirement also increases. * requirement also increases.
* *
* This alignment requirement means that the largest user space FLASH region * This alignment requirement means that the largest user space FLASH region

View File

@ -47,7 +47,7 @@
* Alignment of the user space FLASH partition is a critical factor: The * Alignment of the user space FLASH partition is a critical factor: The
* user space FLASH partition will be spanned with a single region of size * user space FLASH partition will be spanned with a single region of size
* 2**n bytes. The alignment of the user-space region must be the same. As * 2**n bytes. The alignment of the user-space region must be the same. As
* a consequence, as the user-space increases in size, the alignmment * a consequence, as the user-space increases in size, the alignment
* requirement also increases. * requirement also increases.
* *
* This alignment requirement means that the largest user space FLASH region * This alignment requirement means that the largest user space FLASH region

View File

@ -54,7 +54,7 @@
* Alignment of the user space FLASH partition is also a critical factor: * Alignment of the user space FLASH partition is also a critical factor:
* The user space FLASH partition will be spanned with a single region of * The user space FLASH partition will be spanned with a single region of
* size 2**n bytes. The alignment of the user-space region must be the same. * size 2**n bytes. The alignment of the user-space region must be the same.
* As a consequence, as the user-space increases in size, the alignmment * As a consequence, as the user-space increases in size, the alignment
* requirement also increases. * requirement also increases.
* *
* This alignment requirement means that the largest user space FLASH region * This alignment requirement means that the largest user space FLASH region

View File

@ -55,7 +55,7 @@
* Alignment of the user space FLASH partition is also a critical factor: * Alignment of the user space FLASH partition is also a critical factor:
* The user space FLASH partition will be spanned with a single region of * The user space FLASH partition will be spanned with a single region of
* size 2**n bytes. The alignment of the user-space region must be the same. * size 2**n bytes. The alignment of the user-space region must be the same.
* As a consequence, as the user-space increases in size, the alignmment * As a consequence, as the user-space increases in size, the alignment
* requirement also increases. * requirement also increases.
* *
* This alignment requirement means that the largest user space FLASH region * This alignment requirement means that the largest user space FLASH region

View File

@ -54,7 +54,7 @@
* Alignment of the user space FLASH partition is also a critical factor: * Alignment of the user space FLASH partition is also a critical factor:
* The user space FLASH partition will be spanned with a single region of * The user space FLASH partition will be spanned with a single region of
* size 2**n bytes. The alignment of the user-space region must be the same. * size 2**n bytes. The alignment of the user-space region must be the same.
* As a consequence, as the user-space increases in size, the alignmment * As a consequence, as the user-space increases in size, the alignment
* requirement also increases. * requirement also increases.
* *
* This alignment requirement means that the largest user space FLASH region * This alignment requirement means that the largest user space FLASH region

View File

@ -77,11 +77,14 @@
#endif #endif
/* ADC measurements /* ADC measurements
* Default is ADC1_IN9 (PA4) connected to STMod+ connector CN1 pin 13. *
* Some of the choices are:
* ADC1_IN9 (PA4) connected to STMod+ connector CN1 pin 13.
* ADC1_IN12 (PA7) connected to Arduino A0.
*/ */
#define ADC1_MEASURE_CHANNEL 9 #define ADC1_MEASURE_CHANNEL 12
#define GPIO_MEASURE_ADC (GPIO_ADC1_IN9) #define GPIO_MEASURE_ADC (GPIO_ADC1_IN12)
/* Alternate function pin selections ************************************************/ /* Alternate function pin selections ************************************************/
@ -119,7 +122,7 @@
/* I2C /* I2C
* *
* The optional _GPIO configurations allow the I2C driver to manually * The optional GPIO configurations allow the I2C driver to manually
* reset the bus to clear stuck slaves. They match the pin configuration, * reset the bus to clear stuck slaves. They match the pin configuration,
* but are normally-high GPIOs. * but are normally-high GPIOs.
* *
@ -131,24 +134,24 @@
*/ */
#define GPIO_I2C1_SCL (GPIO_I2C1_SCL_1|GPIO_OPENDRAIN|GPIO_SPEED_50MHz|GPIO_OUTPUT_SET) #define GPIO_I2C1_SCL (GPIO_I2C1_SCL_1|GPIO_OPENDRAIN|GPIO_SPEED_50MHz|GPIO_OUTPUT_SET)
#define GPIO_I2C1_SDA (GPIO_I2C1_SDA_1|GPIO_OPENDRAIN|GPIO_SPEED_50MHz|GPIO_OUTPUT_SET) #define GPIO_I2C1_SDA (GPIO_I2C1_SDA_3|GPIO_OPENDRAIN|GPIO_SPEED_50MHz|GPIO_OUTPUT_SET)
#define GPIO_I2C1_SCL_GPIO \ #define GPIO_I2C1_SCL_GPIO \
(GPIO_OUTPUT|GPIO_OPENDRAIN|GPIO_SPEED_50MHz|GPIO_OUTPUT_SET|GPIO_PORTB|GPIO_PIN6) (GPIO_OUTPUT|GPIO_OPENDRAIN|GPIO_SPEED_50MHz|GPIO_OUTPUT_SET|GPIO_PORTB|GPIO_PIN6)
#define GPIO_I2C1_SDA_GPIO \ #define GPIO_I2C1_SDA_GPIO \
(GPIO_OUTPUT|GPIO_OPENDRAIN|GPIO_SPEED_50MHz|GPIO_OUTPUT_SET|GPIO_PORTB|GPIO_PIN7) (GPIO_OUTPUT|GPIO_OPENDRAIN|GPIO_SPEED_50MHz|GPIO_OUTPUT_SET|GPIO_PORTG|GPIO_PIN13)
/* XXX Is I2C2 used on Disco? */ /* XXX Is I2C2 used on Disco? */
#if 0 /* I2C3 connects to Arduino Uno V3 connector pins D15 (I2C3_SCL) and D14 (I2C3_SDA). */
#define GPIO_I2C2_SCL (GPIO_I2C2_SCL_1|GPIO_OPENDRAIN|GPIO_SPEED_50MHz|GPIO_OUTPUT_SET) #define GPIO_I2C3_SCL (GPIO_I2C3_SCL_2|GPIO_OPENDRAIN|GPIO_SPEED_50MHz|GPIO_OUTPUT_SET)
#define GPIO_I2C2_SDA (GPIO_I2C2_SDA_1|GPIO_OPENDRAIN|GPIO_SPEED_50MHz|GPIO_OUTPUT_SET) #define GPIO_I2C3_SDA (GPIO_I2C3_SDA_2|GPIO_OPENDRAIN|GPIO_SPEED_50MHz|GPIO_OUTPUT_SET)
#define GPIO_I2C2_SCL_GPIO \ #define GPIO_I2C3_SCL_GPIO \
(GPIO_OUTPUT|GPIO_OPENDRAIN|GPIO_SPEED_50MHz|GPIO_OUTPUT_SET|GPIO_PORTB|GPIO_PIN10) (GPIO_OUTPUT|GPIO_OPENDRAIN|GPIO_SPEED_50MHz|GPIO_OUTPUT_SET|GPIO_PORTG|GPIO_PIN7)
#define GPIO_I2C2_SDA_GPIO \ #define GPIO_I2C3_SDA_GPIO \
(GPIO_OUTPUT|GPIO_OPENDRAIN|GPIO_SPEED_50MHz|GPIO_OUTPUT_SET|GPIO_PORTB|GPIO_PIN11) (GPIO_OUTPUT|GPIO_OPENDRAIN|GPIO_SPEED_50MHz|GPIO_OUTPUT_SET|GPIO_PORTG|GPIO_PIN8)
#endif /* XXX Is I2C4 used on Disco? */
/* SPI */ /* SPI */
@ -158,11 +161,35 @@
#define GPIO_SPI1_MOSI GPIO_SPI1_MOSI_1 #define GPIO_SPI1_MOSI GPIO_SPI1_MOSI_1
#define GPIO_SPI1_SCK GPIO_SPI1_SCK_1 #define GPIO_SPI1_SCK GPIO_SPI1_SCK_1
/* XXX is SPI2 used on Disco? */ /* SPI2 connects to Arduino Uno V3 connector pins D10-D13,
* also to DSI display.
*/
#define GPIO_SPI2_MISO GPIO_SPI2_MISO_3 #define GPIO_SPI2_MISO GPIO_SPI2_MISO_1
#define GPIO_SPI2_MOSI GPIO_SPI2_MOSI_3 #define GPIO_SPI2_MOSI GPIO_SPI2_MOSI_1
#define GPIO_SPI2_SCK GPIO_SPI2_SCK_3 #define GPIO_SPI2_SCK GPIO_SPI2_SCK_1
/* XXX is SPI3 used on Disco? */
#if 0
#define GPIO_SPI3_MISO GPIO_SPI3_MISO_3
#define GPIO_SPI3_MOSI GPIO_SPI3_MOSI_3
#define GPIO_SPI3_SCK GPIO_SPI3_SCK_3
#endif
/* DFSDM1
*
* DFSDM is connected to two MEMS microphones (MP34DT01) by default.
* PC2 -> CKOUT
* PB12 -> DATIN1
* PH2 -> MIC_VDD GPIO
*/
#define GPIO_DFSDM_DATIN1 GPIO_DFSDM_DATIN1_1
#define GPIO_DFSDM_CKOUT GPIO_DFSDM_CKOUT_1
#define GPIO_MIC_VDD (GPIO_OUTPUT | GPIO_PUSHPULL | GPIO_SPEED_2MHz | \
GPIO_OUTPUT_CLEAR | GPIO_PORTH | GPIO_PIN2)
/* LEDs /* LEDs
* *

View File

@ -155,6 +155,10 @@
#define STM32L4_USE_LSE 1 #define STM32L4_USE_LSE 1
/* HSI16 used as I2C clock */
#define STM32L4_I2C_USE_HSI16 1
/* AHB clock (HCLK) is SYSCLK (120 MHz) */ /* AHB clock (HCLK) is SYSCLK (120 MHz) */
#define STM32L4_RCC_CFGR_HPRE RCC_CFGR_HPRE_SYSCLK /* HCLK = SYSCLK / 1 */ #define STM32L4_RCC_CFGR_HPRE RCC_CFGR_HPRE_SYSCLK /* HCLK = SYSCLK / 1 */
@ -261,6 +265,10 @@
#define STM32L4_USE_LSE 1 #define STM32L4_USE_LSE 1
/* HSI16 used as I2C clock */
#define STM32L4_I2C_USE_HSI16 1
/* Configure the HCLK divisor (for the AHB bus, core, memory, and DMA */ /* Configure the HCLK divisor (for the AHB bus, core, memory, and DMA */
#define STM32L4_RCC_CFGR_HPRE RCC_CFGR_HPRE_SYSCLK /* HCLK = SYSCLK / 1 */ #define STM32L4_RCC_CFGR_HPRE RCC_CFGR_HPRE_SYSCLK /* HCLK = SYSCLK / 1 */
@ -354,6 +362,10 @@
#define STM32L4_USE_LSE 1 #define STM32L4_USE_LSE 1
/* HSI16 used as I2C clock */
#define STM32L4_I2C_USE_HSI16 1
/* Configure the HCLK divisor (for the AHB bus, core, memory, and DMA */ /* Configure the HCLK divisor (for the AHB bus, core, memory, and DMA */
#define STM32L4_RCC_CFGR_HPRE RCC_CFGR_HPRE_SYSCLK /* HCLK = SYSCLK / 1 */ #define STM32L4_RCC_CFGR_HPRE RCC_CFGR_HPRE_SYSCLK /* HCLK = SYSCLK / 1 */

View File

@ -0,0 +1,2 @@
/nuttx_user.elf

View File

@ -0,0 +1,122 @@
############################################################################
# configs/stm32l4r9ai-disco/kernel/Makefile
#
# Copyright (C) 2019 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.
#
############################################################################
-include $(TOPDIR)/Make.defs
# This is the directory for the board-specific header files
BOARD_INCLUDE = $(TOPDIR)$(DELIM)configs$(DELIM)$(CONFIG_ARCH_BOARD)$(DELIM)include
# The entry point name (if none is provided in the .config file)
CONFIG_USER_ENTRYPOINT ?= user_start
ENTRYPT = $(patsubst "%",%,$(CONFIG_USER_ENTRYPOINT))
# Get the paths to the libraries and the links script path in format that
# is appropriate for the host OS
ifeq ($(WINTOOL),y)
# Windows-native toolchains
USER_LIBPATHS = ${shell for path in $(USERLIBS); do dir=`dirname $(TOPDIR)$(DELIM)$$path`;echo "-L\"`cygpath -w $$dir`\"";done}
USER_LDSCRIPT = -T "${shell cygpath -w $(TOPDIR)$(DELIM)configs$(DELIM)$(CONFIG_ARCH_BOARD)$(DELIM)scripts$(DELIM)memory.ld}"
USER_LDSCRIPT += -T "${shell cygpath -w $(TOPDIR)$(DELIM)configs$(DELIM)$(CONFIG_ARCH_BOARD)$(DELIM)scripts$(DELIM)user-space.ld}"
USER_HEXFILE += "${shell cygpath -w $(TOPDIR)$(DELIM)nuttx_user.hex}"
USER_SRECFILE += "${shell cygpath -w $(TOPDIR)$(DELIM)nuttx_user.srec}"
USER_BINFILE += "${shell cygpath -w $(TOPDIR)$(DELIM)nuttx_user.bin}"
else
# Linux/Cygwin-native toolchain
USER_LIBPATHS = $(addprefix -L$(TOPDIR)$(DELIM),$(dir $(USERLIBS)))
USER_LDSCRIPT = -T$(TOPDIR)$(DELIM)configs$(DELIM)$(CONFIG_ARCH_BOARD)$(DELIM)scripts$(DELIM)memory.ld
USER_LDSCRIPT += -T$(TOPDIR)$(DELIM)configs$(DELIM)$(CONFIG_ARCH_BOARD)$(DELIM)scripts$(DELIM)user-space.ld
USER_HEXFILE += "$(TOPDIR)$(DELIM)nuttx_user.hex"
USER_SRECFILE += "$(TOPDIR)$(DELIM)nuttx_user.srec"
USER_BINFILE += "$(TOPDIR)$(DELIM)nuttx_user.bin"
endif
USER_LDFLAGS = --undefined=$(ENTRYPT) --entry=$(ENTRYPT) $(USER_LDSCRIPT)
USER_LDLIBS = $(patsubst lib%,-l%,$(basename $(notdir $(USERLIBS))))
USER_LIBGCC = "${shell "$(CC)" $(ARCHCPUFLAGS) -print-libgcc-file-name}"
# Source files
CSRCS = stm32l4_userspace.c
COBJS = $(CSRCS:.c=$(OBJEXT))
OBJS = $(COBJS)
# Targets:
all: $(TOPDIR)$(DELIM)nuttx_user.elf $(TOPDIR)$(DELIM)User.map
.PHONY: nuttx_user.elf depend clean distclean
$(COBJS): %$(OBJEXT): %.c
$(call COMPILE, $<, $@)
# Create the nuttx_user.elf file containing all of the user-mode code
nuttx_user.elf: $(OBJS)
$(Q) $(LD) -o $@ $(USER_LDFLAGS) $(USER_LIBPATHS) $(OBJS) --start-group $(USER_LDLIBS) --end-group $(USER_LIBGCC)
$(TOPDIR)$(DELIM)nuttx_user.elf: nuttx_user.elf
@echo "LD: nuttx_user.elf"
$(Q) cp -a nuttx_user.elf $(TOPDIR)$(DELIM)nuttx_user.elf
ifeq ($(CONFIG_INTELHEX_BINARY),y)
@echo "CP: nuttx_user.hex"
$(Q) $(OBJCOPY) $(OBJCOPYARGS) -O ihex nuttx_user.elf $(USER_HEXFILE)
endif
ifeq ($(CONFIG_MOTOROLA_SREC),y)
@echo "CP: nuttx_user.srec"
$(Q) $(OBJCOPY) $(OBJCOPYARGS) -O srec nuttx_user.elf $(USER_SRECFILE)
endif
ifeq ($(CONFIG_RAW_BINARY),y)
@echo "CP: nuttx_user.bin"
$(Q) $(OBJCOPY) $(OBJCOPYARGS) -O binary nuttx_user.elf $(USER_BINFILE)
endif
$(TOPDIR)$(DELIM)User.map: nuttx_user.elf
@echo "MK: User.map"
$(Q) $(NM) nuttx_user.elf >$(TOPDIR)$(DELIM)User.map
$(Q) $(CROSSDEV)size nuttx_user.elf
.depend:
depend: .depend
clean:
$(call DELFILE, nuttx_user.elf)
$(call DELFILE, "$(TOPDIR)$(DELIM)nuttx_user.*")
$(call DELFILE, "$(TOPDIR)$(DELIM)User.map")
$(call CLEAN)
distclean: clean

View File

@ -0,0 +1,132 @@
/****************************************************************************
* configs/stm32l4r9ai-disco/kernel/stm32l4_userspace.c
*
* Copyright (C) 2019 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 <stdlib.h>
#include <nuttx/arch.h>
#include <nuttx/mm/mm.h>
#include <nuttx/wqueue.h>
#include <nuttx/userspace.h>
#if defined(CONFIG_BUILD_PROTECTED) && !defined(__KERNEL__)
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* Configuration ************************************************************/
#ifndef CONFIG_NUTTX_USERSPACE
# error "CONFIG_NUTTX_USERSPACE not defined"
#endif
#if CONFIG_NUTTX_USERSPACE != 0x08020000
# error "CONFIG_NUTTX_USERSPACE must be 0x08020000 to match memory.ld"
#endif
/****************************************************************************
* Public Data
****************************************************************************/
/* These 'addresses' of these values are setup by the linker script. They
* are not actual uint32_t storage locations! They are only used
* meaningfully in the following way:
*
* - The linker script defines, for example, the symbol_sdata.
* - The declaration extern uint32_t _sdata; makes C happy. C will believe
* that the value _sdata is the address of a uint32_t variable _data (it is
* not!).
* - We can recover the linker value then by simply taking the address of
* of _data. like: uint32_t *pdata = &_sdata;
*/
extern uint32_t _stext; /* Start of .text */
extern uint32_t _etext; /* End_1 of .text + .rodata */
extern const uint32_t _eronly; /* End+1 of read only section (.text + .rodata) */
extern uint32_t _sdata; /* Start of .data */
extern uint32_t _edata; /* End+1 of .data */
extern uint32_t _sbss; /* Start of .bss */
extern uint32_t _ebss; /* End+1 of .bss */
/* This is the user space entry point */
int CONFIG_USER_ENTRYPOINT(int argc, char *argv[]);
const struct userspace_s userspace __attribute__ ((section (".userspace"))) =
{
/* General memory map */
.us_entrypoint = (main_t)CONFIG_USER_ENTRYPOINT,
.us_textstart = (uintptr_t)&_stext,
.us_textend = (uintptr_t)&_etext,
.us_datasource = (uintptr_t)&_eronly,
.us_datastart = (uintptr_t)&_sdata,
.us_dataend = (uintptr_t)&_edata,
.us_bssstart = (uintptr_t)&_sbss,
.us_bssend = (uintptr_t)&_ebss,
/* Memory manager heap structure */
.us_heap = &g_mmheap,
/* Task/thread startup routines */
.task_startup = task_startup,
#ifndef CONFIG_DISABLE_PTHREAD
.pthread_startup = pthread_startup,
#endif
/* Signal handler trampoline */
.signal_handler = up_signal_handler,
/* User-space work queue support (declared in include/nuttx/wqueue.h) */
#ifdef CONFIG_LIB_USRWORK
.work_usrstart = work_usrstart,
#endif
};
/****************************************************************************
* Public Functions
****************************************************************************/
#endif /* CONFIG_BUILD_PROTECTED && !__KERNEL__ */

View File

@ -0,0 +1,119 @@
############################################################################
# configs/stm32l4r9ai-disco/knsh/Make.defs
#
# Copyright (C) 2017 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.
#
############################################################################
include ${TOPDIR}/.config
include ${TOPDIR}/tools/Config.mk
include ${TOPDIR}/arch/arm/src/armv7-m/Toolchain.defs
LDSCRIPT1 = memory.ld
LDSCRIPT2 = kernel-space.ld
ifeq ($(WINTOOL),y)
# Windows-native toolchains
DIRLINK = $(TOPDIR)/tools/copydir.sh
DIRUNLINK = $(TOPDIR)/tools/unlink.sh
MKDEP = $(TOPDIR)/tools/mknulldeps.sh
ARCHINCLUDES = -I. -isystem "${shell cygpath -w $(TOPDIR)/include}"
ARCHXXINCLUDES = -I. -isystem "${shell cygpath -w $(TOPDIR)/include}" -isystem "${shell cygpath -w $(TOPDIR)/include/cxx}"
ARCHSCRIPT = -T "${shell cygpath -w $(TOPDIR)/configs/$(CONFIG_ARCH_BOARD)/scripts/$(LDSCRIPT1)}"
ARCHSCRIPT += -T "${shell cygpath -w $(TOPDIR)/configs/$(CONFIG_ARCH_BOARD)/scripts/$(LDSCRIPT2)}"
else
# Linux/Cygwin-native toolchain
MKDEP = $(TOPDIR)/tools/mkdeps$(HOSTEXEEXT)
ARCHINCLUDES = -I. -isystem $(TOPDIR)/include
ARCHXXINCLUDES = -I. -isystem $(TOPDIR)/include -isystem $(TOPDIR)/include/cxx
ARCHSCRIPT = -T$(TOPDIR)/configs/$(CONFIG_ARCH_BOARD)/scripts/$(LDSCRIPT1)
ARCHSCRIPT += -T$(TOPDIR)/configs/$(CONFIG_ARCH_BOARD)/scripts/$(LDSCRIPT2)
endif
CC = $(CROSSDEV)gcc
CXX = $(CROSSDEV)g++
CPP = $(CROSSDEV)gcc -E
LD = $(CROSSDEV)ld
STRIP = $(CROSSDEV)strip --strip-unneeded
AR = $(ARCROSSDEV)ar rcs
NM = $(ARCROSSDEV)nm
OBJCOPY = $(CROSSDEV)objcopy
OBJDUMP = $(CROSSDEV)objdump
ARCHCCVERSION = ${shell $(CC) -v 2>&1 | sed -n '/^gcc version/p' | sed -e 's/^gcc version \([0-9\.]\)/\1/g' -e 's/[-\ ].*//g' -e '1q'}
ARCHCCMAJOR = ${shell echo $(ARCHCCVERSION) | cut -d'.' -f1}
ifeq ($(CONFIG_DEBUG_SYMBOLS),y)
ARCHOPTIMIZATION = -g
endif
ifneq ($(CONFIG_DEBUG_NOOPT),y)
ARCHOPTIMIZATION += $(MAXOPTIMIZATION) -fno-strict-aliasing -fno-strength-reduce -fomit-frame-pointer
endif
ARCHCFLAGS = -fno-builtin
ARCHCXXFLAGS = -fno-builtin -fno-exceptions -fcheck-new -fno-rtti
ARCHWARNINGS = -Wall -Wstrict-prototypes -Wshadow -Wundef
ARCHWARNINGSXX = -Wall -Wshadow -Wundef
ARCHDEFINES =
ARCHPICFLAGS = -fpic -msingle-pic-base -mpic-register=r10
CFLAGS = $(ARCHCFLAGS) $(ARCHWARNINGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) $(ARCHDEFINES) $(EXTRADEFINES) -pipe
CPICFLAGS = $(ARCHPICFLAGS) $(CFLAGS)
CXXFLAGS = $(ARCHCXXFLAGS) $(ARCHWARNINGSXX) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHXXINCLUDES) $(ARCHDEFINES) $(EXTRADEFINES) -pipe
CXXPICFLAGS = $(ARCHPICFLAGS) $(CXXFLAGS)
CPPFLAGS = $(ARCHINCLUDES) $(ARCHDEFINES) $(EXTRADEFINES)
AFLAGS = $(CFLAGS) -D__ASSEMBLY__
NXFLATLDFLAGS1 = -r -d -warn-common
NXFLATLDFLAGS2 = $(NXFLATLDFLAGS1) -T$(TOPDIR)/binfmt/libnxflat/gnu-nxflat-pcrel.ld -no-check-sections
LDNXFLATFLAGS = -e main -s 2048
ASMEXT = .S
OBJEXT = .o
LIBEXT = .a
EXEEXT =
ifneq ($(CROSSDEV),arm-nuttx-elf-)
LDFLAGS += -nostartfiles -nodefaultlibs
endif
ifeq ($(CONFIG_DEBUG_SYMBOLS),y)
LDFLAGS += -g
endif
#LDFLAGS += -Map=${TOPDIR}/nuttx.map
#CFLAGS += -Wa,-adhln
#CXXFLAGS += -Wa,-adhln
HOSTCC = gcc
HOSTINCLUDES = -I.
HOSTCFLAGS = -Wall -Wstrict-prototypes -Wshadow -Wundef -g -pipe
HOSTLDFLAGS =

View File

@ -0,0 +1,88 @@
#
# 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_NSH_ARGCAT is not set
# CONFIG_NSH_CMDPARMS is not set
CONFIG_ARCH="arm"
CONFIG_ARCH_BOARD="stm32l4r9ai-disco"
CONFIG_ARCH_BOARD_STM32L4R9AI_DISCO=y
CONFIG_ARCH_BUTTONS=y
CONFIG_ARCH_CHIP_STM32L4=y
CONFIG_ARCH_CHIP_STM32L4R9AI=y
CONFIG_ARCH_INTERRUPTSTACK=2048
CONFIG_ARCH_IRQBUTTONS=y
CONFIG_ARCH_STACKDUMP=y
CONFIG_ARM_MPU=y
CONFIG_BOARDCTL_IOCTL=y
CONFIG_BOARDCTL_UNIQUEID=y
CONFIG_BOARDCTL_UNIQUEID_SIZE=12
CONFIG_BOARD_LOOPSPERMSEC=9234
CONFIG_BUILD_PROTECTED=y
CONFIG_DEBUG_FULLOPT=y
CONFIG_DEBUG_SYMBOLS=y
CONFIG_DEV_LOOP=y
CONFIG_DEV_ZERO=y
CONFIG_FS_PROCFS=y
CONFIG_FS_PROCFS_REGISTER=y
CONFIG_FS_TMPFS=y
CONFIG_HAVE_CXX=y
CONFIG_HAVE_CXXINITIALIZE=y
CONFIG_I2C=y
CONFIG_I2C_DRIVER=y
CONFIG_INTELHEX_BINARY=y
CONFIG_MAX_TASKS=16
CONFIG_MAX_WDOGPARMS=2
CONFIG_MM_REGIONS=3
CONFIG_MTD=y
CONFIG_MTD_PARTITION=y
CONFIG_NFILE_DESCRIPTORS=8
CONFIG_NFILE_STREAMS=8
CONFIG_NSH_ARCHINIT=y
CONFIG_NSH_DISABLE_DD=y
CONFIG_NSH_DISABLE_IFUPDOWN=y
CONFIG_NSH_DISABLE_MKRD=y
CONFIG_NSH_FILEIOSIZE=512
CONFIG_NSH_READLINE=y
CONFIG_NUTTX_USERSPACE=0x08020000
CONFIG_PASS1_BUILDIR="configs/stm32l4r9ai-disco/kernel"
CONFIG_PREALLOC_MQ_MSGS=4
CONFIG_PREALLOC_TIMERS=4
CONFIG_PREALLOC_WDOGS=8
CONFIG_RAM_SIZE=98304
CONFIG_RAM_START=0x20000000
CONFIG_RAW_BINARY=y
CONFIG_RR_INTERVAL=200
CONFIG_RTC_ALARM=y
CONFIG_RTC_DATETIME=y
CONFIG_RTC_DRIVER=y
CONFIG_RTC_IOCTL=y
CONFIG_RTC_NALARMS=2
CONFIG_SCHED_WAITPID=y
CONFIG_SDCLONE_DISABLE=y
CONFIG_SPI_DRIVER=y
CONFIG_STM32L4_DISABLE_IDLE_SLEEP_DURING_DEBUG=y
CONFIG_STM32L4_I2C1=y
CONFIG_STM32L4_I2C3=y
CONFIG_STM32L4_PWR=y
CONFIG_STM32L4_RNG=y
CONFIG_STM32L4_RTC=y
CONFIG_STM32L4_SAI1PLL=y
CONFIG_STM32L4_SPI2=y
CONFIG_STM32L4_SRAM2_HEAP=y
CONFIG_STM32L4_UART4=y
CONFIG_STM32L4_USART2=y
CONFIG_SYSTEM_NSH=y
CONFIG_SYSTEM_NSH_CXXINITIALIZE=y
CONFIG_SYS_RESERVED=8
CONFIG_TASK_NAME_SIZE=0
CONFIG_UART4_BAUD=2000000
CONFIG_UART4_RXBUFSIZE=512
CONFIG_UART4_SERIAL_CONSOLE=y
CONFIG_USERMAIN_STACKSIZE=3072
CONFIG_USER_ENTRYPOINT="nsh_main"
CONFIG_WDOG_INTRESERVE=1

View File

@ -7,7 +7,6 @@
# #
# CONFIG_ARCH_FPU is not set # CONFIG_ARCH_FPU is not set
# CONFIG_NSH_ARGCAT is not set # CONFIG_NSH_ARGCAT is not set
# CONFIG_NSH_CMDOPT_HEXDUMP is not set
# CONFIG_NSH_CMDPARMS is not set # CONFIG_NSH_CMDPARMS is not set
CONFIG_ARCH="arm" CONFIG_ARCH="arm"
CONFIG_ARCH_BOARD="stm32l4r9ai-disco" CONFIG_ARCH_BOARD="stm32l4r9ai-disco"
@ -27,12 +26,15 @@ CONFIG_DEV_LOOP=y
CONFIG_DEV_ZERO=y CONFIG_DEV_ZERO=y
CONFIG_EXAMPLES_ALARM=y CONFIG_EXAMPLES_ALARM=y
CONFIG_EXAMPLES_MEDIA=y CONFIG_EXAMPLES_MEDIA=y
CONFIG_EXAMPLES_RANDOM=y
CONFIG_FS_PROCFS=y CONFIG_FS_PROCFS=y
CONFIG_FS_PROCFS_REGISTER=y CONFIG_FS_PROCFS_REGISTER=y
CONFIG_FS_ROMFS=y CONFIG_FS_ROMFS=y
CONFIG_FS_TMPFS=y CONFIG_FS_TMPFS=y
CONFIG_HAVE_CXX=y CONFIG_HAVE_CXX=y
CONFIG_HAVE_CXXINITIALIZE=y CONFIG_HAVE_CXXINITIALIZE=y
CONFIG_I2C=y
CONFIG_I2C_DRIVER=y
CONFIG_INTELHEX_BINARY=y CONFIG_INTELHEX_BINARY=y
CONFIG_MAX_TASKS=16 CONFIG_MAX_TASKS=16
CONFIG_MAX_WDOGPARMS=2 CONFIG_MAX_WDOGPARMS=2
@ -46,7 +48,6 @@ CONFIG_NSH_ARCHROMFS=y
CONFIG_NSH_BUILTIN_APPS=y CONFIG_NSH_BUILTIN_APPS=y
CONFIG_NSH_DISABLE_IFUPDOWN=y CONFIG_NSH_DISABLE_IFUPDOWN=y
CONFIG_NSH_FILEIOSIZE=512 CONFIG_NSH_FILEIOSIZE=512
CONFIG_NSH_LINELEN=80
CONFIG_NSH_READLINE=y CONFIG_NSH_READLINE=y
CONFIG_NSH_ROMFSETC=y CONFIG_NSH_ROMFSETC=y
CONFIG_PREALLOC_MQ_MSGS=4 CONFIG_PREALLOC_MQ_MSGS=4
@ -63,12 +64,15 @@ CONFIG_RTC_IOCTL=y
CONFIG_RTC_NALARMS=2 CONFIG_RTC_NALARMS=2
CONFIG_SCHED_WAITPID=y CONFIG_SCHED_WAITPID=y
CONFIG_SDCLONE_DISABLE=y CONFIG_SDCLONE_DISABLE=y
CONFIG_SPI=y CONFIG_SPI_DRIVER=y
CONFIG_STM32L4_DISABLE_IDLE_SLEEP_DURING_DEBUG=y CONFIG_STM32L4_DISABLE_IDLE_SLEEP_DURING_DEBUG=y
CONFIG_STM32L4_I2C1=y
CONFIG_STM32L4_I2C3=y
CONFIG_STM32L4_PWR=y CONFIG_STM32L4_PWR=y
CONFIG_STM32L4_RNG=y CONFIG_STM32L4_RNG=y
CONFIG_STM32L4_RTC=y CONFIG_STM32L4_RTC=y
CONFIG_STM32L4_SAI1PLL=y CONFIG_STM32L4_SAI1PLL=y
CONFIG_STM32L4_SPI2=y
CONFIG_STM32L4_SRAM2_HEAP=y CONFIG_STM32L4_SRAM2_HEAP=y
CONFIG_STM32L4_UART4=y CONFIG_STM32L4_UART4=y
CONFIG_STM32L4_USART2=y CONFIG_STM32L4_USART2=y

View File

@ -46,16 +46,16 @@
* 0x0800:0000 address range. * 0x0800:0000 address range.
* *
* For MPU support, the kernel-mode NuttX section is assumed to be 128Kb of * For MPU support, the kernel-mode NuttX section is assumed to be 128Kb of
* FLASH and 4Kb of SRAM. That is an excessive amount for the kernel which * FLASH and 16Kb of SRAM. That is an excessive amount for the kernel which
* should fit into 64KB and, of course, can be optimized as needed (See * should fit into 64KB and, of course, can be optimized as needed (See
* also configs/stm32f4discovery/scripts/kernel-space.ld). Allowing the * also configs/stm32l4r9ai-disco/scripts/kernel-space.ld). Allowing the
* additional does permit addition debug instrumentation to be added to the * additional does permit addition debug instrumentation to be added to the
* kernel space without overflowing the partition. * kernel space without overflowing the partition.
* *
* Alignment of the user space FLASH partition is also a critical factor: * Alignment of the user space FLASH partition is also a critical factor:
* The user space FLASH partition will be spanned with a single region of * The user space FLASH partition will be spanned with a single region of
* size 2**n bytes. The alignment of the user-space region must be the same. * size 2**n bytes. The alignment of the user-space region must be the same.
* As a consequence, as the user-space increases in size, the alignmment * As a consequence, as the user-space increases in size, the alignment
* requirement also increases. * requirement also increases.
* *
* This alignment requirement means that the largest user space FLASH region * This alignment requirement means that the largest user space FLASH region
@ -63,39 +63,21 @@
* 0x08800000. If you change this address, don't forget to change the * 0x08800000. If you change this address, don't forget to change the
* CONFIG_NUTTX_USERSPACE configuration setting to match and to modify * CONFIG_NUTTX_USERSPACE configuration setting to match and to modify
* the check in kernel/userspace.c. * the check in kernel/userspace.c.
*
* For the same reasons, the maximum size of the SRAM mapping is limited to
* 4KB. Both of these alignment limitations could be reduced by using
* multiple regions to map the FLASH/SDRAM range or perhaps with some
* clever use of subregions.
*
* A detailed memory map for the 96KB SRAM region is as follows:
*
* 0x20000 0000: Kernel .data region. Typical size: 0.1KB
* ------- ---- Kernel .bss region. Typical size: 1.8KB
* 0x20000 0800: Kernel IDLE thread stack (approximate). Size is
* determined by CONFIG_IDLETHREAD_STACKSIZE and
* adjustments for alignment. Typical is 1KB.
* ------- ---- Padded to 4KB
* 0x20000 2000: User .data region. Size is variable.
* ------- ---- User .bss region Size is variable.
* 0x20000 4000: Beginning of kernel heap. Size determined by
* CONFIG_MM_KERNEL_HEAPSIZE.
* ------- ---- Beginning of user heap. Can vary with other settings.
* 0x20001 8000: End+1 of CPU RAM
*/ */
MEMORY MEMORY
{ {
/* 1024Kb FLASH */ /* 2048Kb FLASH */
kflash (rx) : ORIGIN = 0x08000000, LENGTH = 128K kflash (rx) : ORIGIN = 0x08000000, LENGTH = 128K
uflash (rx) : ORIGIN = 0x08020000, LENGTH = 128K uflash (rx) : ORIGIN = 0x08020000, LENGTH = 128K
xflash (rx) : ORIGIN = 0x08040000, LENGTH = 768K xflash (rx) : ORIGIN = 0x08040000, LENGTH = 1792K
/* 96Kb of contiguous SRAM */ /* 640Kb of contiguous SRAM */
ksram (rwx) : ORIGIN = 0x20000000, LENGTH = 8K ksram (rwx) : ORIGIN = 0x20000000, LENGTH = 16K
usram (rwx) : ORIGIN = 0x20001000, LENGTH = 8K usram (rwx) : ORIGIN = 0x20004000, LENGTH = 16K
xsram (rwx) : ORIGIN = 0x20002000, LENGTH = 80K xsram (rwx) : ORIGIN = 0x20008000, LENGTH = 192K + 64K - 32K
sram3 (rwx) : ORIGIN = 0x20040000, LENGTH = 384K
} }

View File

@ -36,16 +36,12 @@
-include $(TOPDIR)/Make.defs -include $(TOPDIR)/Make.defs
ASRCS = ASRCS =
CSRCS = stm32_boot.c stm32_spi.c CSRCS = stm32_boot.c
ifeq ($(CONFIG_ARCH_BOARD_STM32L4_CUSTOM_CLOCKCONFIG),y) ifeq ($(CONFIG_ARCH_BOARD_STM32L4_CUSTOM_CLOCKCONFIG),y)
CSRCS += stm32_clockconfig.c CSRCS += stm32_clockconfig.c
endif endif
ifeq ($(CONFIG_STM32L4_OTGFS),y)
CSRCS += stm32_usb.c
endif
ifeq ($(CONFIG_ARCH_LEDS),y) ifeq ($(CONFIG_ARCH_LEDS),y)
CSRCS += stm32_autoleds.c CSRCS += stm32_autoleds.c
else else
@ -57,13 +53,26 @@ CSRCS += stm32_buttons.c
endif endif
ifeq ($(CONFIG_ADC),y) ifeq ($(CONFIG_ADC),y)
ifeq ($(CONFIG_STM32L4_ADC),y)
CSRCS += stm32_adc.c CSRCS += stm32_adc.c
endif endif
ifeq ($(CONFIG_STM32L4_DFSDM),y)
CSRCS += stm32_dfsdm.c
endif
endif
ifeq ($(CONFIG_DAC),y) ifeq ($(CONFIG_DAC),y)
CSRCS += stm32_dac.c CSRCS += stm32_dac.c
endif endif
ifeq ($(CONFIG_STM32L4_SPI),y)
CSRCS += stm32_spi.c
endif
ifeq ($(CONFIG_STM32L4_OTGFS),y)
CSRCS += stm32_usb.c
endif
ifeq ($(CONFIG_LIB_BOARDCTL),y) ifeq ($(CONFIG_LIB_BOARDCTL),y)
CSRCS += stm32_appinit.c CSRCS += stm32_appinit.c
endif endif

View File

@ -78,6 +78,15 @@
* Private Data * Private Data
****************************************************************************/ ****************************************************************************/
#ifdef CONFIG_I2C
# ifdef CONFIG_STM32L4_I2C1
static struct i2c_master_s* g_i2c1;
# endif
# ifdef CONFIG_STM32L4_I2C3
static struct i2c_master_s* g_i2c3;
# endif
#endif
/**************************************************************************** /****************************************************************************
* Public Functions * Public Functions
****************************************************************************/ ****************************************************************************/
@ -156,6 +165,23 @@ int board_app_initialize(uintptr_t arg)
} }
#endif #endif
#ifdef CONFIG_I2C
i2cinfo("Initializing I2C buses\n");
#ifdef CONFIG_STM32L4_I2C1
g_i2c1 = stm32l4_i2cbus_initialize(1);
#ifdef CONFIG_I2C_DRIVER
i2c_register(g_i2c1, 1);
#endif
#endif
#ifdef CONFIG_STM32L4_I2C3
g_i2c3 = stm32l4_i2cbus_initialize(3);
#ifdef CONFIG_I2C_DRIVER
i2c_register(g_i2c3, 3);
#endif
#endif
#endif /* CONFIG_I2C */
#ifdef HAVE_USBHOST #ifdef HAVE_USBHOST
/* Initialize USB host operation. stm32l4_usbhost_initialize() starts a /* Initialize USB host operation. stm32l4_usbhost_initialize() starts a
* thread that will monitor for USB connection and disconnection events. * thread that will monitor for USB connection and disconnection events.
@ -184,7 +210,16 @@ int board_app_initialize(uintptr_t arg)
ainfo("Initializing ADC\n"); ainfo("Initializing ADC\n");
(void)stm32l4_adc_setup(); (void)stm32l4_adc_setup();
#ifdef CONFIG_STM32L4_DFSDM
/* Initialize DFSDM and register its filters as additional ADC devices. */
ret = stm32_dfsdm_setup();
if (ret < 0)
{
aerr("ERROR: Failed to start DFSDM: %d\n", ret);
}
#endif #endif
#endif /* CONFIG_ADC */
#ifdef CONFIG_DAC #ifdef CONFIG_DAC
ainfo("Initializing DAC\n"); ainfo("Initializing DAC\n");

View File

@ -73,8 +73,8 @@ void stm32l4_board_initialize(void)
* stm32_spiinitialize() has been brought into the link. * stm32_spiinitialize() has been brought into the link.
*/ */
#if defined(CONFIG_STM32_SPI1) || defined(CONFIG_STM32_SPI2) || defined(CONFIG_STM32_SPI3) #ifdef CONFIG_STM32L4_SPI
stm32l4_spiinitialize(); stm32_spiinitialize();
#endif #endif
#ifdef CONFIG_STM32L4_OTGFS #ifdef CONFIG_STM32L4_OTGFS

View File

@ -0,0 +1,146 @@
/****************************************************************************
* configs/stm32l4r9ai-disco/src/stm32_dfsdm.c
*
* Copyright (C) 2019 Haltian Ltd. All rights reserved.
* Authors: Juha Niskanen <juha.niskanen@haltian.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 <nuttx/board.h>
#include <nuttx/analog/adc.h>
#include "stm32l4_gpio.h"
#include "stm32l4_dfsdm.h"
#include "stm32l4r9ai-disco.h"
#include <arch/board/board.h>
#if defined(CONFIG_ADC) && defined(CONFIG_STM32L4_DFSDM)
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: stm32_dfsdm_setup
****************************************************************************/
int stm32_dfsdm_setup(void)
{
static bool initialized = false;
if (!initialized)
{
int ret;
struct adc_dev_s *adc;
ainfo("Initializing DFSDM\n");
/* TODO: just some arbitrary channels selected, missing input pin
* configuration and DFSDM mode selection: SPI/Manchester or internal
* parallel inputs (CPU/DMA/ADC).
*/
#ifdef CONFIG_STM32L4_DFSDM1_FLT0
adc = stm32l4_dfsdm_initialize(0, (const uint8_t[1]){0}, 1);
if (adc == NULL)
{
aerr("Failed to get DFSDM FLT0 interface\n");
return -ENODEV;
}
ret = adc_register("/dev/adc_flt0", adc);
if (ret < 0)
{
aerr("adc_register failed: %d\n", ret);
return ret;
}
#endif
#ifdef CONFIG_STM32L4_DFSDM1_FLT1
adc = stm32l4_dfsdm_initialize(1, (const uint8_t[2]){0,1}, 2);
if (adc == NULL)
{
aerr("Failed to get DFSDM FLT1 interface\n");
return -ENODEV;
}
ret = adc_register("/dev/adc_flt1", adc);
if (ret < 0)
{
aerr("adc_register failed: %d\n", ret);
return ret;
}
#endif
#ifdef CONFIG_STM32L4_DFSDM1_FLT2
adc = stm32l4_dfsdm_initialize(2, (const uint8_t[8]){0,1,2,3,4,5,6,7}, 8);
if (adc == NULL)
{
aerr("Failed to get DFSDM FLT2 interface\n");
return -ENODEV;
}
ret = adc_register("/dev/adc_flt2", adc);
if (ret < 0)
{
aerr("adc_register failed: %d\n", ret);
return ret;
}
#endif
#ifdef CONFIG_STM32L4_DFSDM1_FLT3
adc = stm32l4_dfsdm_initialize(3, (const uint8_t[4]){6,5,4,3}, 4);
if (adc == NULL)
{
aerr("Failed to get DFSDM FLT3 interface\n");
return -ENODEV;
}
ret = adc_register("/dev/adc_flt3", adc);
if (ret < 0)
{
aerr("adc_register failed: %d\n", ret);
return ret;
}
#endif
initialized = true;
}
return OK;
}
#endif /* CONFIG_ADC && CONFIG_STM32L4_DFSDM */

View File

@ -45,6 +45,7 @@
#include <errno.h> #include <errno.h>
#include <nuttx/spi/spi.h> #include <nuttx/spi/spi.h>
#include <nuttx/spi/spi_transfer.h>
#include <arch/board/board.h> #include <arch/board/board.h>
#include <up_arch.h> #include <up_arch.h>
@ -53,20 +54,20 @@
#include "stm32l4r9ai-disco.h" #include "stm32l4r9ai-disco.h"
#if defined(CONFIG_STM32_SPI1) || defined(CONFIG_STM32_SPI2) || defined(CONFIG_STM32_SPI3) #if defined(CONFIG_STM32L4_SPI1) || defined(CONFIG_STM32L4_SPI2) || defined(CONFIG_STM32L4_SPI3)
/************************************************************************************ /************************************************************************************
* Public Data * Public Data
************************************************************************************/ ************************************************************************************/
/* Global driver instances */ /* Global driver instances */
#ifdef CONFIG_STM32_SPI1 #ifdef CONFIG_STM32L4_SPI1
struct spi_dev_s *g_spi1; struct spi_dev_s *g_spi1;
#endif #endif
#ifdef CONFIG_STM32_SPI2 #ifdef CONFIG_STM32L4_SPI2
struct spi_dev_s *g_spi2; struct spi_dev_s *g_spi2;
#endif #endif
#ifdef CONFIG_STM32_SPI3 #ifdef CONFIG_STM32L4_SPI3
struct spi_dev_s *g_spi3; struct spi_dev_s *g_spi3;
#endif #endif
@ -84,53 +85,62 @@ struct spi_dev_s *g_spi3;
void weak_function stm32_spiinitialize(void) void weak_function stm32_spiinitialize(void)
{ {
#ifdef CONFIG_STM32_SPI1 #ifdef CONFIG_STM32L4_SPI1
/* Configure SPI-based devices on SPI1 */ /* Configure SPI-based devices on SPI1 */
g_spi1 = up_spiinitialize(1); g_spi1 = stm32l4_spibus_initialize(1);
if (!g_spi1) if (!g_spi1)
{ {
spierr("ERROR: [boot] FAILED to initialize SPI port 1\n"); spierr("ERROR: [boot] FAILED to initialize SPI port 1\n");
} }
#ifdef CONFIG_SPI_DRIVER
spi_register(g_spi1, 1);
#endif
#ifdef HAVE_MMCSD #ifdef HAVE_MMCSD
stm32_configgpio(GPIO_SPI_CS_SD_CARD); stm32l4_configgpio(GPIO_SPI_CS_SD_CARD);
#endif #endif
#endif #endif
#ifdef CONFIG_STM32_SPI2 #ifdef CONFIG_STM32L4_SPI2
/* Configure SPI-based devices on SPI2 */ /* Configure SPI-based devices on SPI2 */
g_spi2 = up_spiinitialize(2); g_spi2 = stm32l4_spibus_initialize(2);
if (!g_spi2) if (!g_spi2)
{ {
spierr("ERROR: [boot] FAILED to initialize SPI port 2\n"); spierr("ERROR: [boot] FAILED to initialize SPI port 2\n");
} }
#ifdef CONFIG_SPI_DRIVER
spi_register(g_spi2, 2);
#endif
#warning No devices specified on SPI2 #warning No devices specified on SPI2
#endif #endif
#ifdef CONFIG_STM32_SPI2 #ifdef CONFIG_STM32L4_SPI3
/* Configure SPI-based devices on SPI3 */ /* Configure SPI-based devices on SPI3 */
g_spi2 = up_spiinitialize(3); g_spi3 = stm32l4_spibus_initialize(3);
if (!g_spi2) if (!g_spi3)
{ {
spierr("ERROR: [boot] FAILED to initialize SPI port 3\n"); spierr("ERROR: [boot] FAILED to initialize SPI port 3\n");
} }
#ifdef CONFIG_SPI_DRIVER
spi_register(g_spi3, 3);
#endif
#warning No devices specified on SPI3 #warning No devices specified on SPI3
#endif #endif
} }
/**************************************************************************** /****************************************************************************
* Name: stm32_spi1/2/3select and stm32_spi1/2/3status * Name: stm32l4_spi1/2/3select and stm32l4_spi1/2/3status
* *
* Description: * Description:
* The external functions, stm32_spi1/2/3select and stm32_spi1/2/3status must be * The external functions, stm32_spi1/2/3select and stm32_spi1/2/3status must be
* provided by board-specific logic. They are implementations of the select * provided by board-specific logic. They are implementations of the select
* and status methods of the SPI interface defined by struct spi_ops_s (see * and status methods of the SPI interface defined by struct spi_ops_s (see
* include/nuttx/spi/spi.h). All other methods (including up_spiinitialize()) * include/nuttx/spi/spi.h). All other methods (including stm32l4_spibus_initialize())
* are provided by common STM32 logic. To use this common SPI logic on your * are provided by common STM32 logic. To use this common SPI logic on your
* board: * board:
* *
@ -139,60 +149,60 @@ void weak_function stm32_spiinitialize(void)
* 2. Provide stm32_spi1/2/3select() and stm32_spi1/2/3status() functions in your * 2. Provide stm32_spi1/2/3select() and stm32_spi1/2/3status() functions in your
* board-specific logic. These functions will perform chip selection and * board-specific logic. These functions will perform chip selection and
* status operations using GPIOs in the way your board is configured. * status operations using GPIOs in the way your board is configured.
* 3. Add a calls to up_spiinitialize() in your low level application * 3. Add a calls to stm32l4_spibus_initialize() in your low level application
* initialization logic * initialization logic
* 4. The handle returned by up_spiinitialize() may then be used to bind the * 4. The handle returned by stm32l4_spibus_initialize() may then be used to bind the
* SPI driver to higher level logic (e.g., calling * SPI driver to higher level logic (e.g., calling
* mmcsd_spislotinitialize(), for example, will bind the SPI driver to * mmcsd_spislotinitialize(), for example, will bind the SPI driver to
* the SPI MMC/SD driver). * the SPI MMC/SD driver).
* *
****************************************************************************/ ****************************************************************************/
#ifdef CONFIG_STM32_SPI1 #ifdef CONFIG_STM32L4_SPI1
void stm32_spi1select(FAR struct spi_dev_s *dev, uint32_t devid, bool selected) void stm32l4_spi1select(FAR struct spi_dev_s *dev, uint32_t devid, bool selected)
{ {
spiinfo("devid: %d CS: %s\n", (int)devid, selected ? "assert" : "de-assert"); spiinfo("devid: %d CS: %s\n", (int)devid, selected ? "assert" : "de-assert");
#ifdef HAVE_MMCSD #ifdef HAVE_MMCSD
if (devid == SPIDEV_MMCSD(0)) if (devid == SPIDEV_MMCSD(0))
{ {
stm32_gpiowrite(GPIO_SPI_CS_SD_CARD, !selected); stm32l4_gpiowrite(GPIO_SPI_CS_SD_CARD, !selected);
} }
#endif #endif
} }
uint8_t stm32_spi1status(FAR struct spi_dev_s *dev, uint32_t devid) uint8_t stm32l4_spi1status(FAR struct spi_dev_s *dev, uint32_t devid)
{ {
return 0; return 0;
} }
#endif #endif
#ifdef CONFIG_STM32_SPI2 #ifdef CONFIG_STM32L4_SPI2
void stm32_spi2select(FAR struct spi_dev_s *dev, uint32_t devid, bool selected) void stm32l4_spi2select(FAR struct spi_dev_s *dev, uint32_t devid, bool selected)
{ {
spiinfo("devid: %d CS: %s\n", (int)devid, selected ? "assert" : "de-assert"); spiinfo("devid: %d CS: %s\n", (int)devid, selected ? "assert" : "de-assert");
} }
uint8_t stm32_spi2status(FAR struct spi_dev_s *dev, uint32_t devid) uint8_t stm32l4_spi2status(FAR struct spi_dev_s *dev, uint32_t devid)
{ {
return 0; return 0;
} }
#endif #endif
#ifdef CONFIG_STM32_SPI3 #ifdef CONFIG_STM32L4_SPI3
void stm32_spi3select(FAR struct spi_dev_s *dev, uint32_t devid, bool selected) void stm32l4_spi3select(FAR struct spi_dev_s *dev, uint32_t devid, bool selected)
spiinfo("devid: %d CS: %s\n", (int)devid, selected ? "assert" : "de-assert"); spiinfo("devid: %d CS: %s\n", (int)devid, selected ? "assert" : "de-assert");
} }
uint8_t stm32_spi3status(FAR struct spi_dev_s *dev, uint32_t devid) uint8_t stm32l4_spi3status(FAR struct spi_dev_s *dev, uint32_t devid)
{ {
return 0; return 0;
} }
#endif #endif
/**************************************************************************** /****************************************************************************
* Name: stm32_spi1cmddata * Name: stm32l4_spi1/2/3cmddata
* *
* Description: * Description:
* Set or clear the SH1101A A0 or SD1306 D/C n bit to select data (true) * Set or clear the SH1101A A0 or SD1306 D/C n bit to select data (true)
@ -215,26 +225,26 @@ uint8_t stm32_spi3status(FAR struct spi_dev_s *dev, uint32_t devid)
****************************************************************************/ ****************************************************************************/
#ifdef CONFIG_SPI_CMDDATA #ifdef CONFIG_SPI_CMDDATA
#ifdef CONFIG_STM32_SPI1 #ifdef CONFIG_STM32L4_SPI1
int stm32_spi1cmddata(FAR struct spi_dev_s *dev, uint32_t devid, bool cmd) int stm32l4_spi1cmddata(FAR struct spi_dev_s *dev, uint32_t devid, bool cmd)
{ {
return OK; return OK;
} }
#endif #endif
#ifdef CONFIG_STM32_SPI2 #ifdef CONFIG_STM32L4_SPI2
int stm32_spi2cmddata(FAR struct spi_dev_s *dev, uint32_t devid, bool cmd) int stm32l4_spi2cmddata(FAR struct spi_dev_s *dev, uint32_t devid, bool cmd)
{ {
return OK; return OK;
} }
#endif #endif
#ifdef CONFIG_STM32_SPI3 #ifdef CONFIG_STM32L4_SPI3
int stm32_spi3cmddata(FAR struct spi_dev_s *dev, uint32_t devid, bool cmd) int stm32l4_spi3cmddata(FAR struct spi_dev_s *dev, uint32_t devid, bool cmd)
{ {
return OK; return OK;
} }
#endif #endif
#endif /* CONFIG_SPI_CMDDATA */ #endif /* CONFIG_SPI_CMDDATA */
#endif /* CONFIG_STM32_SPI1 || CONFIG_STM32_SPI2 || CONFIG_STM32_SPI3 */ #endif /* CONFIG_STM32L4_SPI1 || CONFIG_STM32L4_SPI2 || CONFIG_STM32L4_SPI3 */

View File

@ -190,10 +190,10 @@
/* Global driver instances */ /* Global driver instances */
#ifdef CONFIG_STM32_SPI1 #ifdef CONFIG_STM32L4_SPI1
extern struct spi_dev_s *g_spi1; extern struct spi_dev_s *g_spi1;
#endif #endif
#ifdef CONFIG_STM32_SPI2 #ifdef CONFIG_STM32L4_SPI2
extern struct spi_dev_s *g_spi2; extern struct spi_dev_s *g_spi2;
#endif #endif
@ -231,6 +231,18 @@ int stm32l4_adc_measure_voltages(uint32_t *vrefint, uint32_t *vbat, uint32_t *ve
int stm32l4_dac_setup(void); int stm32l4_dac_setup(void);
/************************************************************************************
* Name: stm32_dfsdm_setup
*
* Description:
* Initialize DFSDM and register the ADC drivers for DFSDM filters.
*
************************************************************************************/
#if defined(CONFIG_ADC) && defined(CONFIG_STM32L4_DFSDM)
int stm32_dfsdm_setup(void);
#endif
/************************************************************************************ /************************************************************************************
* Name: stm32_spiinitialize * Name: stm32_spiinitialize
* *