From 8708cddde16863c86d15b8781db40739d64ff4bb Mon Sep 17 00:00:00 2001
From: Lok Tep
Date: Thu, 16 Jun 2016 13:44:14 +0200
Subject: [PATCH 001/734] mmc1 copy + dcache
---
arch/arm/src/stm32f7/Make.defs | 4 +
arch/arm/src/stm32f7/chip/stm32_sdmmc.h | 52 +
.../src/stm32f7/chip/stm32f74xx75xx_sdmmc.h | 268 ++
arch/arm/src/stm32f7/stm32_sdmmc.c | 2977 +++++++++++++++++
arch/arm/src/stm32f7/stm32_sdmmc.h | 129 +
configs/stm32f746-ws/include/board.h | 42 +
configs/stm32f746-ws/nsh/defconfig | 41 +-
configs/stm32f746-ws/src/stm32_spi.c | 12 +-
8 files changed, 3507 insertions(+), 18 deletions(-)
create mode 100644 arch/arm/src/stm32f7/chip/stm32_sdmmc.h
create mode 100644 arch/arm/src/stm32f7/chip/stm32f74xx75xx_sdmmc.h
create mode 100644 arch/arm/src/stm32f7/stm32_sdmmc.c
create mode 100644 arch/arm/src/stm32f7/stm32_sdmmc.h
diff --git a/arch/arm/src/stm32f7/Make.defs b/arch/arm/src/stm32f7/Make.defs
index 07aa380ebd..123c70ffc2 100644
--- a/arch/arm/src/stm32f7/Make.defs
+++ b/arch/arm/src/stm32f7/Make.defs
@@ -147,6 +147,10 @@ ifeq ($(CONFIG_STM32F7_SPI),y)
CHIP_CSRCS += stm32_spi.c
endif
+ifeq ($(CONFIG_STM32F7_SDMMC1),y)
+CHIP_CSRCS += stm32_sdmmc.c
+endif
+
ifeq ($(CONFIG_STM32F7_TIM),y)
CHIP_CSRCS += stm32_tim.c
endif
diff --git a/arch/arm/src/stm32f7/chip/stm32_sdmmc.h b/arch/arm/src/stm32f7/chip/stm32_sdmmc.h
new file mode 100644
index 0000000000..e04bdddc1e
--- /dev/null
+++ b/arch/arm/src/stm32f7/chip/stm32_sdmmc.h
@@ -0,0 +1,52 @@
+/************************************************************************************
+ * arch/arm/src/stm32f7/chip/stm32_i2c.h
+ *
+ * Copyright (C) 2015 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * 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.
+ *
+ ************************************************************************************/
+
+#ifndef __ARCH_ARM_SRC_STM32F7_CHIP_STM32_SDMMC_H
+#define __ARCH_ARM_SRC_STM32F7_CHIP_STM32_SDMMC_H
+
+/************************************************************************************
+ * Included Files
+ ************************************************************************************/
+
+#include
+#include "chip.h"
+
+#if defined(CONFIG_STM32F7_STM32F74XX) || defined(CONFIG_STM32F7_STM32F75XX)
+# include "stm32f74xx75xx_sdmmc.h"
+#else
+# error "Unsupported STM32 F7 part"
+#endif
+
+#endif /* __ARCH_ARM_SRC_STM32F7_CHIP_STM32_SDMMC_H */
diff --git a/arch/arm/src/stm32f7/chip/stm32f74xx75xx_sdmmc.h b/arch/arm/src/stm32f7/chip/stm32f74xx75xx_sdmmc.h
new file mode 100644
index 0000000000..e40990ec16
--- /dev/null
+++ b/arch/arm/src/stm32f7/chip/stm32f74xx75xx_sdmmc.h
@@ -0,0 +1,268 @@
+/************************************************************************************
+ * arch/arm/src/stm32/chip/stm32_sdio.h
+ *
+ * Copyright (C) 2009, 2011-2013 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * 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.
+ *
+ ************************************************************************************/
+
+#ifndef __ARCH_ARM_SRC_STM32F7_CHIP_STM32F74XX75XX_SDMMC_H
+#define __ARCH_ARM_SRC_STM32F7_CHIP_STM32F74XX75XX_SDMMC_H
+
+/************************************************************************************
+ * Pre-processor Definitions
+ ************************************************************************************/
+
+/* Register Offsets *****************************************************************/
+
+#define STM32_SDMMC1_POWER_OFFSET 0x0000 /* SDIO power control register */
+#define STM32_SDMMC1_CLKCR_OFFSET 0x0004 /* SDI clock control register */
+#define STM32_SDMMC1_ARG_OFFSET 0x0008 /* SDIO argument register */
+#define STM32_SDMMC1_CMD_OFFSET 0x000c /* SDIO command register */
+#define STM32_SDMMC1_RESPCMD_OFFSET 0x0010 /* SDIO command response register */
+#define STM32_SDMMC1_RESP_OFFSET(n) (0x0010+4*(n))
+#define STM32_SDMMC1_RESP1_OFFSET 0x0014 /* SDIO response 1 register */
+#define STM32_SDMMC1_RESP2_OFFSET 0x0018 /* SDIO response 2 register */
+#define STM32_SDMMC1_RESP3_OFFSET 0x001c /* SDIO response 3 register */
+#define STM32_SDMMC1_RESP4_OFFSET 0x0020 /* SDIO response 4 register */
+#define STM32_SDMMC1_DTIMER_OFFSET 0x0024 /* SDIO data timer register */
+#define STM32_SDMMC1_DLEN_OFFSET 0x0028 /* SDIO data length register */
+#define STM32_SDMMC1_DCTRL_OFFSET 0x002c /* SDIO data control register */
+#define STM32_SDMMC1_DCOUNT_OFFSET 0x0030 /* SDIO data counter register */
+#define STM32_SDMMC1_STA_OFFSET 0x0034 /* SDIO status register */
+#define STM32_SDMMC1_ICR_OFFSET 0x0038 /* SDIO interrupt clear register */
+#define STM32_SDMMC1_MASK_OFFSET 0x003c /* SDIO mask register */
+#define STM32_SDMMC1_FIFOCNT_OFFSET 0x0048 /* SDIO FIFO counter register */
+#define STM32_SDMMC1_FIFO_OFFSET 0x0080 /* SDIO data FIFO register */
+
+/* Register Addresses ***************************************************************/
+
+#define STM32_SDMMC1_POWER (STM32_SDMMC1_BASE+STM32_SDMMC1_POWER_OFFSET)
+#define STM32_SDMMC1_CLKCR (STM32_SDMMC1_BASE+STM32_SDMMC1_CLKCR_OFFSET)
+#define STM32_SDMMC1_ARG (STM32_SDMMC1_BASE+STM32_SDMMC1_ARG_OFFSET)
+#define STM32_SDMMC1_CMD (STM32_SDMMC1_BASE+STM32_SDMMC1_CMD_OFFSET)
+#define STM32_SDMMC1_RESPCMD (STM32_SDMMC1_BASE+STM32_SDMMC1_RESPCMD_OFFSET)
+#define STM32_SDMMC1_RESP(n) (STM32_SDMMC1_BASE+STM32_SDMMC1_RESP_OFFSET(n))
+#define STM32_SDMMC1_RESP1 (STM32_SDMMC1_BASE+STM32_SDMMC1_RESP1_OFFSET)
+#define STM32_SDMMC1_RESP2 (STM32_SDMMC1_BASE+STM32_SDMMC1_RESP2_OFFSET)
+#define STM32_SDMMC1_RESP3 (STM32_SDMMC1_BASE+STM32_SDMMC1_RESP3_OFFSET)
+#define STM32_SDMMC1_RESP4 (STM32_SDMMC1_BASE+STM32_SDMMC1_RESP4_OFFSET)
+#define STM32_SDMMC1_DTIMER (STM32_SDMMC1_BASE+STM32_SDMMC1_DTIMER_OFFSET)
+#define STM32_SDMMC1_DLEN (STM32_SDMMC1_BASE+STM32_SDMMC1_DLEN_OFFSET)
+#define STM32_SDMMC1_DCTRL (STM32_SDMMC1_BASE+STM32_SDMMC1_DCTRL_OFFSET)
+#define STM32_SDMMC1_DCOUNT (STM32_SDMMC1_BASE+STM32_SDMMC1_DCOUNT_OFFSET)
+#define STM32_SDMMC1_STA (STM32_SDMMC1_BASE+STM32_SDMMC1_STA_OFFSET)
+#define STM32_SDMMC1_ICR (STM32_SDMMC1_BASE+STM32_SDMMC1_ICR_OFFSET)
+#define STM32_SDMMC1_MASK (STM32_SDMMC1_BASE+STM32_SDMMC1_MASK_OFFSET)
+#define STM32_SDMMC1_FIFOCNT (STM32_SDMMC1_BASE+STM32_SDMMC1_FIFOCNT_OFFSET)
+#define STM32_SDMMC1_FIFO (STM32_SDMMC1_BASE+STM32_SDMMC1_FIFO_OFFSET)
+
+
+/* Register Bitfield Definitions ****************************************************/
+
+#define SDIO_POWER_PWRCTRL_SHIFT (0) /* Bits 0-1: Power supply control bits */
+#define SDIO_POWER_PWRCTRL_MASK (3 << SDIO_POWER_PWRCTRL_SHIFT)
+# define SDIO_POWER_PWRCTRL_OFF (0 << SDIO_POWER_PWRCTRL_SHIFT) /* 00: Power-off: card clock stopped */
+# define SDIO_POWER_PWRCTRL_PWRUP (2 << SDIO_POWER_PWRCTRL_SHIFT) /* 10: Reserved power-up */
+# define SDIO_POWER_PWRCTRL_ON (3 << SDIO_POWER_PWRCTRL_SHIFT) /* 11: Power-on: card is clocked */
+
+#define SDIO_POWER_RESET (0) /* Reset value */
+
+#define SDIO_CLKCR_CLKDIV_SHIFT (0) /* Bits 7-0: Clock divide factor */
+#define SDIO_CLKCR_CLKDIV_MASK (0xff << SDIO_CLKCR_CLKDIV_SHIFT)
+#define SDIO_CLKCR_CLKEN (1 << 8) /* Bit 8: Clock enable bit */
+#define SDIO_CLKCR_PWRSAV (1 << 9) /* Bit 9: Power saving configuration bit */
+#define SDIO_CLKCR_BYPASS (1 << 10) /* Bit 10: Clock divider bypass enable bit */
+#define SDIO_CLKCR_WIDBUS_SHIFT (11) /* Bits 12-11: Wide bus mode enable bits */
+#define SDIO_CLKCR_WIDBUS_MASK (3 << SDIO_CLKCR_WIDBUS_SHIFT)
+# define SDIO_CLKCR_WIDBUS_D1 (0 << SDIO_CLKCR_WIDBUS_SHIFT) /* 00: Default (SDIO_D0) */
+# define SDIO_CLKCR_WIDBUS_D4 (1 << SDIO_CLKCR_WIDBUS_SHIFT) /* 01: 4-wide (SDIO_D[3:0]) */
+# define SDIO_CLKCR_WIDBUS_D8 (2 << SDIO_CLKCR_WIDBUS_SHIFT) /* 10: 8-wide (SDIO_D[7:0]) */
+#define SDIO_CLKCR_NEGEDGE (1 << 13) /* Bit 13: SDIO_CK dephasing selection bit */
+#define SDIO_CLKCR_HWFC_EN (1 << 14) /* Bit 14: HW Flow Control enable */
+
+#define SDIO_CLKCR_RESET (0) /* Reset value */
+#define SDIO_ARG_RESET (0) /* Reset value */
+
+#define SDIO_CLKCR_CLKEN_BB (STM32_SDMMC1_CLKCR_BB + (8 * 4))
+#define SDIO_CLKCR_PWRSAV_BB (STM32_SDMMC1_CLKCR_BB + (9 * 4))
+#define SDIO_CLKCR_BYPASS_BB (STM32_SDMMC1_CLKCR_BB + (10 * 4))
+#define SDIO_CLKCR_NEGEDGE_BB (STM32_SDMMC1_CLKCR_BB + (13 * 4))
+#define SDIO_CLKCR_HWFC_EN_BB (STM32_SDMMC1_CLKCR_BB + (14 * 4))
+
+#define SDIO_CMD_CMDINDEX_SHIFT (0)
+#define SDIO_CMD_CMDINDEX_MASK (0x3f << SDIO_CMD_CMDINDEX_SHIFT)
+#define SDIO_CMD_WAITRESP_SHIFT (6) /* Bits 7-6: Wait for response bits */
+#define SDIO_CMD_WAITRESP_MASK (3 << SDIO_CMD_WAITRESP_SHIFT)
+# define SDIO_CMD_NORESPONSE (0 << SDIO_CMD_WAITRESP_SHIFT) /* 00/10: No response */
+# define SDIO_CMD_SHORTRESPONSE (1 << SDIO_CMD_WAITRESP_SHIFT) /* 01: Short response */
+# define SDIO_CMD_LONGRESPONSE (3 << SDIO_CMD_WAITRESP_SHIFT) /* 11: Long response */
+#define SDIO_CMD_WAITINT (1 << 8) /* Bit 8: CPSM waits for interrupt request */
+#define SDIO_CMD_WAITPEND (1 << 9) /* Bit 9: CPSM Waits for ends of data transfer */
+#define SDIO_CMD_CPSMEN (1 << 10) /* Bit 10: Command path state machine enable */
+#define SDIO_CMD_SUSPEND (1 << 11) /* Bit 11: SD I/O suspend command */
+#define SDIO_CMD_ENDCMD (1 << 12) /* Bit 12: Enable CMD completion */
+#define SDIO_CMD_NIEN (1 << 13) /* Bit 13: not Interrupt Enable */
+#define SDIO_CMD_ATACMD (1 << 14) /* Bit 14: CE-ATA command */
+
+#define SDIO_CMD_RESET (0) /* Reset value */
+
+#define SDIO_CMD_WAITINT_BB (STM32_SDMMC1_CMD_BB + (8 * 4))
+#define SDIO_CMD_WAITPEND_BB (STM32_SDMMC1_CMD_BB + (9 * 4))
+#define SDIO_CMD_CPSMEN_BB (STM32_SDMMC1_CMD_BB + (10 * 4))
+#define SDIO_CMD_SUSPEND_BB (STM32_SDMMC1_CMD_BB + (11 * 4))
+#define SDIO_CMD_ENCMD_BB (STM32_SDMMC1_CMD_BB + (12 * 4))
+#define SDIO_CMD_NIEN_BB (STM32_SDMMC1_CMD_BB + (13 * 4))
+#define SDIO_CMD_ATACMD_BB (STM32_SDMMC1_CMD_BB + (14 * 4))
+
+#define SDIO_RESPCMD_SHIFT (0)
+#define SDIO_RESPCMD_MASK (0x3f << SDIO_RESPCMD_SHIFT)
+
+#define SDIO_DTIMER_RESET (0) /* Reset value */
+
+#define SDIO_DLEN_SHIFT (0)
+#define SDIO_DLEN_MASK (0x01ffffff << SDIO_DLEN_SHIFT)
+
+#define SDIO_DLEN_RESET (0) /* Reset value */
+
+#define SDIO_DCTRL_DTEN (1 << 0) /* Bit 0: Data transfer enabled bit */
+#define SDIO_DCTRL_DTDIR (1 << 1) /* Bit 1: Data transfer direction */
+#define SDIO_DCTRL_DTMODE (1 << 2) /* Bit 2: Data transfer mode */
+#define SDIO_DCTRL_DMAEN (1 << 3) /* Bit 3: DMA enable bit */
+#define SDIO_DCTRL_DBLOCKSIZE_SHIFT (4) /* Bits 7-4: Data block size */
+#define SDIO_DCTRL_DBLOCKSIZE_MASK (15 << SDIO_DCTRL_DBLOCKSIZE_SHIFT)
+# define SDIO_DCTRL_1BYTE (0 << SDIO_DCTRL_DBLOCKSIZE_SHIFT)
+# define SDIO_DCTRL_2BYTES (1 << SDIO_DCTRL_DBLOCKSIZE_SHIFT)
+# define SDIO_DCTRL_4BYTES (2 << SDIO_DCTRL_DBLOCKSIZE_SHIFT)
+# define SDIO_DCTRL_8BYTES (3 << SDIO_DCTRL_DBLOCKSIZE_SHIFT)
+# define SDIO_DCTRL_16BYTES (4 << SDIO_DCTRL_DBLOCKSIZE_SHIFT)
+# define SDIO_DCTRL_32BYTES (5 << SDIO_DCTRL_DBLOCKSIZE_SHIFT)
+# define SDIO_DCTRL_64BYTES (6 << SDIO_DCTRL_DBLOCKSIZE_SHIFT)
+# define SDIO_DCTRL_128BYTES (7 << SDIO_DCTRL_DBLOCKSIZE_SHIFT)
+# define SDIO_DCTRL_256BYTES (8 << SDIO_DCTRL_DBLOCKSIZE_SHIFT)
+# define SDIO_DCTRL_512BYTES (9 << SDIO_DCTRL_DBLOCKSIZE_SHIFT)
+# define SDIO_DCTRL_1KBYTE (10 << SDIO_DCTRL_DBLOCKSIZE_SHIFT)
+# define SDIO_DCTRL_2KBYTES (11 << SDIO_DCTRL_DBLOCKSIZE_SHIFT)
+# define SDIO_DCTRL_4KBYTES (12 << SDIO_DCTRL_DBLOCKSIZE_SHIFT)
+# define SDIO_DCTRL_8KBYTES (13 << SDIO_DCTRL_DBLOCKSIZE_SHIFT)
+# define SDIO_DCTRL_16KBYTES (14 << SDIO_DCTRL_DBLOCKSIZE_SHIFT)
+#define SDIO_DCTRL_RWSTART (1 << 8) /* Bit 8: Read wait start */
+#define SDIO_DCTRL_RWSTOP (1 << 9) /* Bit 9: Read wait stop */
+#define SDIO_DCTRL_RWMOD (1 << 10) /* Bit 10: Read wait mode */
+#define SDIO_DCTRL_SDIOEN (1 << 11) /* Bit 11: SD I/O enable functions */
+
+#define SDIO_DCTRL_RESET (0) /* Reset value */
+
+#define SDIO_DCTRL_DTEN_BB (STM32_SDMMC1_DCTRL_BB + (0 * 4))
+#define SDIO_DCTRL_DTDIR_BB (STM32_SDMMC1_DCTRL_BB + (1 * 4))
+#define SDIO_DCTRL_DTMODE_BB (STM32_SDMMC1_DCTRL_BB + (2 * 4))
+#define SDIO_DCTRL_DMAEN_BB (STM32_SDMMC1_DCTRL_BB + (3 * 4))
+#define SDIO_DCTRL_RWSTART_BB (STM32_SDMMC1_DCTRL_BB + (8 * 4))
+#define SDIO_DCTRL_RWSTOP_BB (STM32_SDMMC1_DCTRL_BB + (9 * 4))
+#define SDIO_DCTRL_RWMOD_BB (STM32_SDMMC1_DCTRL_BB + (10 * 4))
+#define SDIO_DCTRL_SDIOEN_BB (STM32_SDMMC1_DCTRL_BB + (11 * 4))
+
+#define SDIO_DATACOUNT_SHIFT (0)
+#define SDIO_DATACOUNT_MASK (0x01ffffff << SDIO_DATACOUNT_SHIFT)
+
+#define SDIO_STA_CCRCFAIL (1 << 0) /* Bit 0: Command response CRC fail */
+#define SDIO_STA_DCRCFAIL (1 << 1) /* Bit 1: Data block CRC fail */
+#define SDIO_STA_CTIMEOUT (1 << 2) /* Bit 2: Command response timeout */
+#define SDIO_STA_DTIMEOUT (1 << 3) /* Bit 3: Data timeout */
+#define SDIO_STA_TXUNDERR (1 << 4) /* Bit 4: Transmit FIFO underrun error */
+#define SDIO_STA_RXOVERR (1 << 5) /* Bit 5: Received FIFO overrun error */
+#define SDIO_STA_CMDREND (1 << 6) /* Bit 6: Command response received */
+#define SDIO_STA_CMDSENT (1 << 7) /* Bit 7: Command sent */
+#define SDIO_STA_DATAEND (1 << 8) /* Bit 8: Data end */
+#define SDIO_STA_STBITERR (1 << 9) /* Bit 9: Start bit not detected */
+#define SDIO_STA_DBCKEND (1 << 10) /* Bit 10: Data block sent/received */
+#define SDIO_STA_CMDACT (1 << 11) /* Bit 11: Command transfer in progress */
+#define SDIO_STA_TXACT (1 << 12) /* Bit 12: Data transmit in progress */
+#define SDIO_STA_RXACT (1 << 13) /* Bit 13: Data receive in progress */
+#define SDIO_STA_TXFIFOHE (1 << 14) /* Bit 14: Transmit FIFO half empty */
+#define SDIO_STA_RXFIFOHF (1 << 15) /* Bit 15: Receive FIFO half full */
+#define SDIO_STA_TXFIFOF (1 << 16) /* Bit 16: Transmit FIFO full */
+#define SDIO_STA_RXFIFOF (1 << 17) /* Bit 17: Receive FIFO full */
+#define SDIO_STA_TXFIFOE (1 << 18) /* Bit 18: Transmit FIFO empty */
+#define SDIO_STA_RXFIFOE (1 << 19) /* Bit 19: Receive FIFO empty */
+#define SDIO_STA_TXDAVL (1 << 20) /* Bit 20: Data available in transmit FIFO */
+#define SDIO_STA_RXDAVL (1 << 21) /* Bit 21: Data available in receive FIFO */
+#define SDIO_STA_SDIOIT (1 << 22) /* Bit 22: SDIO interrupt received */
+#define SDIO_STA_CEATAEND (1 << 23) /* Bit 23: CMD6 CE-ATA command completion */
+
+#define SDIO_ICR_CCRCFAILC (1 << 0) /* Bit 0: CCRCFAIL flag clear bit */
+#define SDIO_ICR_DCRCFAILC (1 << 1) /* Bit 1: DCRCFAIL flag clear bit */
+#define SDIO_ICR_CTIMEOUTC (1 << 2) /* Bit 2: CTIMEOUT flag clear bit */
+#define SDIO_ICR_DTIMEOUTC (1 << 3) /* Bit 3: DTIMEOUT flag clear bit */
+#define SDIO_ICR_TXUNDERRC (1 << 4) /* Bit 4: TXUNDERR flag clear bit */
+#define SDIO_ICR_RXOVERRC (1 << 5) /* Bit 5: RXOVERR flag clear bit */
+#define SDIO_ICR_CMDRENDC (1 << 6) /* Bit 6: CMDREND flag clear bit */
+#define SDIO_ICR_CMDSENTC (1 << 7) /* Bit 7: CMDSENT flag clear bit */
+#define SDIO_ICR_DATAENDC (1 << 8) /* Bit 8: DATAEND flag clear bit */
+#define SDIO_ICR_STBITERRC (1 << 9) /* Bit 9: STBITERR flag clear bit */
+#define SDIO_ICR_DBCKENDC (1 << 10) /* Bit 10: DBCKEND flag clear bit */
+#define SDIO_ICR_SDIOITC (1 << 22) /* Bit 22: SDIOIT flag clear bit */
+#define SDIO_ICR_CEATAENDC (1 << 23) /* Bit 23: CEATAEND flag clear bit */
+
+#define SDIO_ICR_RESET 0x00c007ff
+#define SDIO_ICR_STATICFLAGS 0x000005ff
+
+#define SDIO_MASK_CCRCFAILIE (1 << 0) /* Bit 0: Command CRC fail interrupt enable */
+#define SDIO_MASK_DCRCFAILIE (1 << 1) /* Bit 1: Data CRC fail interrupt enable */
+#define SDIO_MASK_CTIMEOUTIE (1 << 2) /* Bit 2: Command timeout interrupt enable */
+#define SDIO_MASK_DTIMEOUTIE (1 << 3) /* Bit 3: Data timeout interrupt enable */
+#define SDIO_MASK_TXUNDERRIE (1 << 4) /* Bit 4: Tx FIFO underrun error interrupt enable */
+#define SDIO_MASK_RXOVERRIE (1 << 5) /* Bit 5: Rx FIFO overrun error interrupt enable */
+#define SDIO_MASK_CMDRENDIE (1 << 6) /* Bit 6: Command response received interrupt enable */
+#define SDIO_MASK_CMDSENTIE (1 << 7) /* Bit 7: Command sent interrupt enable */
+#define SDIO_MASK_DATAENDIE (1 << 8) /* Bit 8: Data end interrupt enable */
+#define SDIO_MASK_STBITERRIE (1 << 9) /* Bit 9: Start bit error interrupt enable */
+#define SDIO_MASK_DBCKENDIE (1 << 10) /* Bit 10: Data block end interrupt enable */
+#define SDIO_MASK_CMDACTIE (1 << 11) /* Bit 11: Command acting interrupt enable */
+#define SDIO_MASK_TXACTIE (1 << 12) /* Bit 12: Data transmit acting interrupt enable */
+#define SDIO_MASK_RXACTIE (1 << 13) /* Bit 13: Data receive acting interrupt enable */
+#define SDIO_MASK_TXFIFOHEIE (1 << 14) /* Bit 14: Tx FIFO half empty interrupt enable */
+#define SDIO_MASK_RXFIFOHFIE (1 << 15) /* Bit 15: Rx FIFO half full interrupt enable */
+#define SDIO_MASK_TXFIFOFIE (1 << 16) /* Bit 16: Tx FIFO full interrupt enable */
+#define SDIO_MASK_RXFIFOFIE (1 << 17) /* Bit 17: Rx FIFO full interrupt enable */
+#define SDIO_MASK_TXFIFOEIE (1 << 18) /* Bit 18: Tx FIFO empty interrupt enable */
+#define SDIO_MASK_RXFIFOEIE (1 << 19) /* Bit 19: Rx FIFO empty interrupt enable */
+#define SDIO_MASK_TXDAVLIE (1 << 20) /* Bit 20: Data available in Tx FIFO interrupt enable */
+#define SDIO_MASK_RXDAVLIE (1 << 21) /* Bit 21: Data available in Rx FIFO interrupt enable */
+#define SDIO_MASK_SDIOITIE (1 << 22) /* Bit 22: SDIO mode interrupt received interrupt enable */
+#define SDIO_MASK_CEATAENDIE (1 << 23) /* Bit 23: CE-ATA command completion interrupt enable */
+
+#define SDIO_MASK_RESET (0)
+
+#define SDIO_FIFOCNT_SHIFT (0)
+#define SDIO_FIFOCNT_MASK (0x01ffffff << SDIO_FIFOCNT_SHIFT)
+
+#endif /* __ARCH_ARM_SRC_STM32F7_CHIP_STM32F74XX75XX_SDMMC_H */
+
diff --git a/arch/arm/src/stm32f7/stm32_sdmmc.c b/arch/arm/src/stm32f7/stm32_sdmmc.c
new file mode 100644
index 0000000000..58f7b7318d
--- /dev/null
+++ b/arch/arm/src/stm32f7/stm32_sdmmc.c
@@ -0,0 +1,2977 @@
+/****************************************************************************
+ * arch/arm/src/stm32f7/stm32_sdio.c
+ *
+ * Copyright (C) 2009, 2011-2016 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * 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 "stm32_sdmmc.h"
+
+#include
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include
+#include
+
+#include "cache.h"
+#include "chip.h"
+#include "up_arch.h"
+
+#include "stm32_dma.h"
+#include "stm32_gpio.h"
+
+
+/* TODO STM32F7_SDMMC2
+ */
+
+#ifdef CONFIG_STM32F7_SDMMC1
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Configuration ************************************************************/
+/* Required system configuration options:
+ *
+ * CONFIG_ARCH_DMA - Enable architecture-specific DMA subsystem
+ * initialization. Required if CONFIG_SDIO_DMA is enabled.
+ * CONFIG_STM32F7_DMA2 - Enable STM32 DMA2 support. Required if
+ * CONFIG_SDIO_DMA is enabled
+ * CONFIG_SCHED_WORKQUEUE -- Callback support requires work queue support.
+ *
+ * Driver-specific configuration options:
+ *
+ * CONFIG_SDIO_MUXBUS - Setting this configuration enables some locking
+ * APIs to manage concurrent accesses on the SDIO bus. This is not
+ * needed for the simple case of a single SD card, for example.
+ * CONFIG_SDIO_DMA - Enable SDIO. This is a marginally optional. For
+ * most usages, SDIO will cause data overruns if used without DMA.
+ * NOTE the above system DMA configuration options.
+ * CONFIG_SDIO_WIDTH_D1_ONLY - This may be selected to force the driver
+ * operate with only a single data line (the default is to use all
+ * 4 SD data lines).
+ * CONFIG_SDIO_PRI - SDIO interrupt priority. This setting is not very
+ * important since interrupt nesting is not currently supported.
+ * CONFIG_SDM_DMAPRIO - SDIO DMA priority. This can be selecte if
+ * CONFIG_SDIO_DMA is enabled.
+ * CONFIG_SDIO_XFRDEBUG - Enables some very low-level debug output
+ * This also requires CONFIG_DEBUG_FS and CONFIG_DEBUG_INFO
+ */
+
+#if defined(CONFIG_SDIO_DMA) && !defined(CONFIG_STM32F7_DMA2)
+# warning "CONFIG_SDIO_DMA support requires CONFIG_STM32F7_DMA2"
+#endif
+
+#ifndef CONFIG_SDIO_DMA
+# warning "Large Non-DMA transfer may result in RX overrun failures"
+#endif
+
+#ifndef CONFIG_SCHED_WORKQUEUE
+# error "Callback support requires CONFIG_SCHED_WORKQUEUE"
+#endif
+
+#ifndef CONFIG_SDIO_PRI
+# define CONFIG_SDIO_PRI NVIC_SYSH_PRIORITY_DEFAULT
+#endif
+
+#ifdef CONFIG_SDIO_DMA
+# ifndef CONFIG_SDIO_DMAPRIO
+# define CONFIG_SDIO_DMAPRIO DMA_SCR_PRIVERYHI
+# endif
+# if (CONFIG_SDIO_DMAPRIO & ~DMA_SCR_PL_MASK) != 0
+# error "Illegal value for CONFIG_SDIO_DMAPRIO"
+# endif
+#else
+# undef CONFIG_SDIO_DMAPRIO
+#endif
+
+#if !defined(CONFIG_DEBUG_FS) || !defined(CONFIG_DEBUG_FEATURES)
+# undef CONFIG_SDIO_XFRDEBUG
+#endif
+
+/* Friendly CLKCR bit re-definitions ****************************************/
+
+#define SDIO_CLKCR_RISINGEDGE (0)
+#define SDIO_CLKCR_FALLINGEDGE SDIO_CLKCR_NEGEDGE
+
+/* Mode dependent settings. These depend on clock devisor settings that must
+ * be defined in the board-specific board.h header file: SDIO_INIT_CLKDIV,
+ * SDIO_MMCXFR_CLKDIV, and SDIO_SDXFR_CLKDIV.
+ */
+
+#define STM32_CLCKCR_INIT (SDMMC1_INIT_CLKDIV | SDIO_CLKCR_RISINGEDGE | \
+ SDIO_CLKCR_WIDBUS_D1)
+#define SDIO_CLKCR_MMCXFR (SDMMC1_MMCXFR_CLKDIV | SDIO_CLKCR_RISINGEDGE | \
+ SDIO_CLKCR_WIDBUS_D1)
+#define SDIO_CLCKR_SDXFR (SDMMC1_SDXFR_CLKDIV | SDIO_CLKCR_RISINGEDGE | \
+ SDIO_CLKCR_WIDBUS_D1)
+#define SDIO_CLCKR_SDWIDEXFR (SDMMC1_SDXFR_CLKDIV | SDIO_CLKCR_RISINGEDGE | \
+ SDIO_CLKCR_WIDBUS_D4)
+
+/* Timing */
+
+#define SDIO_CMDTIMEOUT (100000)
+#define SDIO_LONGTIMEOUT (0x7fffffff)
+
+/* Big DTIMER setting */
+
+#define SDIO_DTIMER_DATATIMEOUT (0x000fffff)
+
+/* DMA channel/stream configuration register settings. The following
+ * must be selected. The DMA driver will select the remaining fields.
+ *
+ * - 32-bit DMA
+ * - Memory increment
+ * - Direction (memory-to-peripheral, peripheral-to-memory)
+ * - Memory burst size (F4 only)
+ */
+
+
+/* STM32 stream configuration register (SCR) settings. */
+
+#define SDIO_RXDMA32_CONFIG (DMA_SCR_PFCTRL | DMA_SCR_DIR_P2M|DMA_SCR_MINC | \
+ DMA_SCR_PSIZE_32BITS | DMA_SCR_MSIZE_32BITS | \
+ CONFIG_SDIO_DMAPRIO | DMA_SCR_PBURST_INCR4 | \
+ DMA_SCR_MBURST_INCR4)
+#define SDIO_TXDMA32_CONFIG (DMA_SCR_PFCTRL | DMA_SCR_DIR_M2P | DMA_SCR_MINC | \
+ DMA_SCR_PSIZE_32BITS | DMA_SCR_MSIZE_32BITS | \
+ CONFIG_SDIO_DMAPRIO | DMA_SCR_PBURST_INCR4 | \
+ DMA_SCR_MBURST_INCR4)
+
+/* SDIO DMA Channel/Stream selection. There
+ * are multiple DMA stream options that must be dis-ambiguated in the board.h
+ * file.
+ */
+
+#define SDIO_DMACHAN DMAMAP_SDMMC1
+
+/* FIFO sizes */
+
+#define SDIO_HALFFIFO_WORDS (8)
+#define SDIO_HALFFIFO_BYTES (8*4)
+
+/* Data transfer interrupt mask bits */
+
+#define SDIO_RECV_MASK (SDIO_MASK_DCRCFAILIE | SDIO_MASK_DTIMEOUTIE | \
+ SDIO_MASK_DATAENDIE | SDIO_MASK_RXOVERRIE | \
+ SDIO_MASK_RXFIFOHFIE | SDIO_MASK_STBITERRIE)
+#define SDIO_SEND_MASK (SDIO_MASK_DCRCFAILIE | SDIO_MASK_DTIMEOUTIE | \
+ SDIO_MASK_DATAENDIE | SDIO_MASK_TXUNDERRIE | \
+ SDIO_MASK_TXFIFOHEIE | SDIO_MASK_STBITERRIE)
+#define SDIO_DMARECV_MASK (SDIO_MASK_DCRCFAILIE | SDIO_MASK_DTIMEOUTIE | \
+ SDIO_MASK_DATAENDIE | SDIO_MASK_RXOVERRIE | \
+ SDIO_MASK_STBITERRIE)
+#define SDIO_DMASEND_MASK (SDIO_MASK_DCRCFAILIE | SDIO_MASK_DTIMEOUTIE | \
+ SDIO_MASK_DATAENDIE | SDIO_MASK_TXUNDERRIE | \
+ SDIO_MASK_STBITERRIE)
+
+/* Event waiting interrupt mask bits */
+
+#define SDIO_CMDDONE_STA (SDIO_STA_CMDSENT)
+#define SDIO_RESPDONE_STA (SDIO_STA_CTIMEOUT | SDIO_STA_CCRCFAIL | \
+ SDIO_STA_CMDREND)
+#define SDIO_XFRDONE_STA (0)
+
+#define SDIO_CMDDONE_MASK (SDIO_MASK_CMDSENTIE)
+#define SDIO_RESPDONE_MASK (SDIO_MASK_CCRCFAILIE | SDIO_MASK_CTIMEOUTIE | \
+ SDIO_MASK_CMDRENDIE)
+#define SDIO_XFRDONE_MASK (0)
+
+#define SDIO_CMDDONE_ICR (SDIO_ICR_CMDSENTC | SDIO_ICR_DBCKENDC)
+#define SDIO_RESPDONE_ICR (SDIO_ICR_CTIMEOUTC | SDIO_ICR_CCRCFAILC | \
+ SDIO_ICR_CMDRENDC | SDIO_ICR_DBCKENDC)
+#define SDIO_XFRDONE_ICR (SDIO_ICR_DATAENDC | SDIO_ICR_DCRCFAILC | \
+ SDIO_ICR_DTIMEOUTC | SDIO_ICR_RXOVERRC | \
+ SDIO_ICR_TXUNDERRC | SDIO_ICR_STBITERRC | \
+ SDIO_ICR_DBCKENDC)
+
+#define SDIO_WAITALL_ICR (SDIO_CMDDONE_ICR | SDIO_RESPDONE_ICR | \
+ SDIO_XFRDONE_ICR | SDIO_ICR_DBCKENDC)
+
+/* Let's wait until we have both SDIO transfer complete and DMA complete. */
+
+#define SDIO_XFRDONE_FLAG (1)
+#define SDIO_DMADONE_FLAG (2)
+#define SDIO_ALLDONE (3)
+
+/* Register logging support */
+
+#ifdef CONFIG_SDIO_XFRDEBUG
+# ifdef CONFIG_SDIO_DMA
+# define SAMPLENDX_BEFORE_SETUP 0
+# define SAMPLENDX_BEFORE_ENABLE 1
+# define SAMPLENDX_AFTER_SETUP 2
+# define SAMPLENDX_END_TRANSFER 3
+# define SAMPLENDX_DMA_CALLBACK 4
+# define DEBUG_NSAMPLES 5
+# else
+# define SAMPLENDX_BEFORE_SETUP 0
+# define SAMPLENDX_AFTER_SETUP 1
+# define SAMPLENDX_END_TRANSFER 2
+# define DEBUG_NSAMPLES 3
+# endif
+#endif
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+/* This structure defines the state of the STM32 SDIO interface */
+
+struct stm32_dev_s
+{
+ struct sdio_dev_s dev; /* Standard, base SDIO interface */
+
+ /* STM32-specific extensions */
+ /* Event support */
+
+ sem_t waitsem; /* Implements event waiting */
+ sdio_eventset_t waitevents; /* Set of events to be waited for */
+ uint32_t waitmask; /* Interrupt enables for event waiting */
+ volatile sdio_eventset_t wkupevent; /* The event that caused the wakeup */
+ WDOG_ID waitwdog; /* Watchdog that handles event timeouts */
+
+ /* Callback support */
+
+ uint8_t cdstatus; /* Card status */
+ sdio_eventset_t cbevents; /* Set of events to be cause callbacks */
+ worker_t callback; /* Registered callback function */
+ void *cbarg; /* Registered callback argument */
+ struct work_s cbwork; /* Callback work queue structure */
+
+ /* Interrupt mode data transfer support */
+
+ uint32_t *buffer; /* Address of current R/W buffer */
+ size_t remaining; /* Number of bytes remaining in the transfer */
+ uint32_t xfrmask; /* Interrupt enables for data transfer */
+
+ /* DMA data transfer support */
+
+ bool widebus; /* Required for DMA support */
+#ifdef CONFIG_SDIO_DMA
+ volatile uint8_t xfrflags; /* Used to synchronize SDIO and DMA completion events */
+ bool dmamode; /* true: DMA mode transfer */
+ DMA_HANDLE dma; /* Handle for DMA channel */
+#endif
+};
+
+/* Register logging support */
+
+#ifdef CONFIG_SDIO_XFRDEBUG
+struct stm32_sdioregs_s
+{
+ uint8_t power;
+ uint16_t clkcr;
+ uint16_t dctrl;
+ uint32_t dtimer;
+ uint32_t dlen;
+ uint32_t dcount;
+ uint32_t sta;
+ uint32_t mask;
+ uint32_t fifocnt;
+};
+
+struct stm32_sampleregs_s
+{
+ struct stm32_sdioregs_s sdio;
+#if defined(CONFIG_DEBUG_DMA_INFO) && defined(CONFIG_SDIO_DMA)
+ struct stm32_dmaregs_s dma;
+#endif
+};
+#endif
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+/* Low-level helpers ********************************************************/
+
+static void stm32_takesem(struct stm32_dev_s *priv);
+#define stm32_givesem(priv) (sem_post(&priv->waitsem))
+static inline void stm32_setclkcr(uint32_t clkcr);
+static void stm32_configwaitints(struct stm32_dev_s *priv, uint32_t waitmask,
+ sdio_eventset_t waitevents, sdio_eventset_t wkupevents);
+static void stm32_configxfrints(struct stm32_dev_s *priv, uint32_t xfrmask);
+static void stm32_setpwrctrl(uint32_t pwrctrl);
+static inline uint32_t stm32_getpwrctrl(void);
+
+/* DMA Helpers **************************************************************/
+
+#ifdef CONFIG_SDIO_XFRDEBUG
+static void stm32_sampleinit(void);
+static void stm32_sdiosample(struct stm32_sdioregs_s *regs);
+static void stm32_sample(struct stm32_dev_s *priv, int index);
+static void stm32_sdiodump(struct stm32_sdioregs_s *regs, const char *msg);
+static void stm32_dumpsample(struct stm32_dev_s *priv,
+ struct stm32_sampleregs_s *regs, const char *msg);
+static void stm32_dumpsamples(struct stm32_dev_s *priv);
+#else
+# define stm32_sampleinit()
+# define stm32_sample(priv,index)
+# define stm32_dumpsamples(priv)
+#endif
+
+#ifdef CONFIG_SDIO_DMA
+static void stm32_dmacallback(DMA_HANDLE handle, uint8_t status, void *arg);
+#endif
+
+/* Data Transfer Helpers ****************************************************/
+
+static uint8_t stm32_log2(uint16_t value);
+static void stm32_dataconfig(uint32_t timeout, uint32_t dlen, uint32_t dctrl);
+static void stm32_datadisable(void);
+static void stm32_sendfifo(struct stm32_dev_s *priv);
+static void stm32_recvfifo(struct stm32_dev_s *priv);
+static void stm32_eventtimeout(int argc, uint32_t arg);
+static void stm32_endwait(struct stm32_dev_s *priv, sdio_eventset_t wkupevent);
+static void stm32_endtransfer(struct stm32_dev_s *priv, sdio_eventset_t wkupevent);
+
+/* Interrupt Handling *******************************************************/
+
+static int stm32_interrupt(int irq, void *context);
+#ifdef CONFIG_MMCSD_SDIOWAIT_WRCOMPLETE
+static int stm32_rdyinterrupt(int irq, void *context);
+#endif
+
+/* SDIO interface methods ***************************************************/
+
+/* Mutual exclusion */
+
+#ifdef CONFIG_SDIO_MUXBUS
+static int stm32_lock(FAR struct sdio_dev_s *dev, bool lock);
+#endif
+
+/* Initialization/setup */
+
+static void stm32_reset(FAR struct sdio_dev_s *dev);
+static uint8_t stm32_status(FAR struct sdio_dev_s *dev);
+static void stm32_widebus(FAR struct sdio_dev_s *dev, bool enable);
+static void stm32_clock(FAR struct sdio_dev_s *dev,
+ enum sdio_clock_e rate);
+static int stm32_attach(FAR struct sdio_dev_s *dev);
+
+/* Command/Status/Data Transfer */
+
+static int stm32_sendcmd(FAR struct sdio_dev_s *dev, uint32_t cmd,
+ uint32_t arg);
+static int stm32_recvsetup(FAR struct sdio_dev_s *dev, FAR uint8_t *buffer,
+ size_t nbytes);
+static int stm32_sendsetup(FAR struct sdio_dev_s *dev,
+ FAR const uint8_t *buffer, uint32_t nbytes);
+static int stm32_cancel(FAR struct sdio_dev_s *dev);
+
+static int stm32_waitresponse(FAR struct sdio_dev_s *dev, uint32_t cmd);
+static int stm32_recvshortcrc(FAR struct sdio_dev_s *dev, uint32_t cmd,
+ uint32_t *rshort);
+static int stm32_recvlong(FAR struct sdio_dev_s *dev, uint32_t cmd,
+ uint32_t rlong[4]);
+static int stm32_recvshort(FAR struct sdio_dev_s *dev, uint32_t cmd,
+ uint32_t *rshort);
+static int stm32_recvnotimpl(FAR struct sdio_dev_s *dev, uint32_t cmd,
+ uint32_t *rnotimpl);
+
+/* EVENT handler */
+
+static void stm32_waitenable(FAR struct sdio_dev_s *dev,
+ sdio_eventset_t eventset);
+static sdio_eventset_t
+ stm32_eventwait(FAR struct sdio_dev_s *dev, uint32_t timeout);
+static void stm32_callbackenable(FAR struct sdio_dev_s *dev,
+ sdio_eventset_t eventset);
+static int stm32_registercallback(FAR struct sdio_dev_s *dev,
+ worker_t callback, void *arg);
+
+/* DMA */
+
+#ifdef CONFIG_SDIO_DMA
+static bool stm32_dmasupported(FAR struct sdio_dev_s *dev);
+#ifdef CONFIG_SDIO_PREFLIGHT
+static int stm32_dmapreflight(FAR struct sdio_dev_s *dev,
+ FAR const uint8_t *buffer, size_t buflen);
+#endif
+static int stm32_dmarecvsetup(FAR struct sdio_dev_s *dev,
+ FAR uint8_t *buffer, size_t buflen);
+static int stm32_dmasendsetup(FAR struct sdio_dev_s *dev,
+ FAR const uint8_t *buffer, size_t buflen);
+#endif
+
+/* Initialization/uninitialization/reset ************************************/
+
+static void stm32_callback(void *arg);
+static void stm32_default(void);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+struct stm32_dev_s g_sdiodev =
+{
+ .dev =
+ {
+#ifdef CONFIG_SDIO_MUXBUS
+ .lock = stm32_lock,
+#endif
+ .reset = stm32_reset,
+ .status = stm32_status,
+ .widebus = stm32_widebus,
+ .clock = stm32_clock,
+ .attach = stm32_attach,
+ .sendcmd = stm32_sendcmd,
+#ifdef CONFIG_SDIO_BLOCKSETUP
+ .blocksetup = stm32_blocksetup, /* Not implemented yet */
+#endif
+ .recvsetup = stm32_recvsetup,
+ .sendsetup = stm32_sendsetup,
+ .cancel = stm32_cancel,
+ .waitresponse = stm32_waitresponse,
+ .recvR1 = stm32_recvshortcrc,
+ .recvR2 = stm32_recvlong,
+ .recvR3 = stm32_recvshort,
+ .recvR4 = stm32_recvnotimpl,
+ .recvR5 = stm32_recvnotimpl,
+ .recvR6 = stm32_recvshortcrc,
+ .recvR7 = stm32_recvshort,
+ .waitenable = stm32_waitenable,
+ .eventwait = stm32_eventwait,
+ .callbackenable = stm32_callbackenable,
+ .registercallback = stm32_registercallback,
+#ifdef CONFIG_SDIO_DMA
+ .dmasupported = stm32_dmasupported,
+#ifdef CONFIG_SDIO_PREFLIGHT
+ .dmapreflight = stm32_dmapreflight,
+#endif
+ .dmarecvsetup = stm32_dmarecvsetup,
+ .dmasendsetup = stm32_dmasendsetup,
+#endif
+ },
+};
+
+/* Register logging support */
+
+#ifdef CONFIG_SDIO_XFRDEBUG
+static struct stm32_sampleregs_s g_sampleregs[DEBUG_NSAMPLES];
+#endif
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Low-level Helpers
+ ****************************************************************************/
+/****************************************************************************
+ * Name: stm32_takesem
+ *
+ * Description:
+ * Take the wait semaphore (handling false alarm wakeups due to the receipt
+ * of signals).
+ *
+ * Input Parameters:
+ * dev - Instance of the SDIO device driver state structure.
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+static void stm32_takesem(struct stm32_dev_s *priv)
+{
+ /* Take the semaphore (perhaps waiting) */
+
+ while (sem_wait(&priv->waitsem) != 0)
+ {
+ /* The only case that an error should occr here is if the wait was
+ * awakened by a signal.
+ */
+
+ ASSERT(errno == EINTR);
+ }
+}
+
+/****************************************************************************
+ * Name: stm32_setclkcr
+ *
+ * Description:
+ * Modify oft-changed bits in the CLKCR register. Only the following bit-
+ * fields are changed:
+ *
+ * CLKDIV, PWRSAV, BYPASS, WIDBUS, NEGEDGE, and HWFC_EN
+ *
+ * Input Parameters:
+ * clkcr - A new CLKCR setting for the above mentions bits (other bits
+ * are ignored.
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+static inline void stm32_setclkcr(uint32_t clkcr)
+{
+ uint32_t regval = getreg32(STM32_SDMMC1_CLKCR);
+
+ /* Clear CLKDIV, PWRSAV, BYPASS, WIDBUS, NEGEDGE, HWFC_EN bits */
+
+ regval &= ~(SDIO_CLKCR_CLKDIV_MASK | SDIO_CLKCR_PWRSAV | SDIO_CLKCR_BYPASS |
+ SDIO_CLKCR_WIDBUS_MASK | SDIO_CLKCR_NEGEDGE | SDIO_CLKCR_HWFC_EN |
+ SDIO_CLKCR_CLKEN);
+
+ /* Replace with user provided settings */
+
+ clkcr &= (SDIO_CLKCR_CLKDIV_MASK | SDIO_CLKCR_PWRSAV | SDIO_CLKCR_BYPASS |
+ SDIO_CLKCR_WIDBUS_MASK | SDIO_CLKCR_NEGEDGE | SDIO_CLKCR_HWFC_EN |
+ SDIO_CLKCR_CLKEN);
+
+ regval |= clkcr;
+ putreg32(regval, STM32_SDMMC1_CLKCR);
+
+ finfo("CLKCR: %08x PWR: %08x\n",
+ getreg32(STM32_SDMMC1_CLKCR), getreg32(STM32_SDMMC1_POWER));
+}
+
+/****************************************************************************
+ * Name: stm32_configwaitints
+ *
+ * Description:
+ * Enable/disable SDIO interrupts needed to suport the wait function
+ *
+ * Input Parameters:
+ * priv - A reference to the SDIO device state structure
+ * waitmask - The set of bits in the SDIO MASK register to set
+ * waitevents - Waited for events
+ * wkupevent - Wake-up events
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+static void stm32_configwaitints(struct stm32_dev_s *priv, uint32_t waitmask,
+ sdio_eventset_t waitevents,
+ sdio_eventset_t wkupevent)
+{
+ irqstate_t flags;
+#ifdef CONFIG_MMCSD_SDIOWAIT_WRCOMPLETE
+ int pinset;
+#endif
+
+ /* Save all of the data and set the new interrupt mask in one, atomic
+ * operation.
+ */
+ flags = enter_critical_section();
+
+#ifdef CONFIG_MMCSD_SDIOWAIT_WRCOMPLETE
+ if ((waitmask & SDIOWAIT_WRCOMPLETE) != 0)
+ {
+ /* Do not use this in STM32_SDMMC1_MASK register */
+
+ waitmask &= !SDIOWAIT_WRCOMPLETE;
+
+ pinset = GPIO_SDMMC1_D0 & (GPIO_PORT_MASK | GPIO_PIN_MASK);
+ pinset |= (GPIO_INPUT | GPIO_FLOAT | GPIO_EXTI);
+
+ /* Arm the SDIO_D Ready and install Isr */
+
+ stm32_gpiosetevent(pinset, true, false, false, stm32_rdyinterrupt);
+ }
+
+ /* Disarm SDIO_D ready */
+
+ if ((wkupevent & SDIOWAIT_WRCOMPLETE) != 0)
+ {
+ stm32_gpiosetevent(GPIO_SDMMC1_D0, false, false, false , NULL);
+ stm32_configgpio(GPIO_SDMMC1_D0);
+ }
+#endif
+
+ priv->waitevents = waitevents;
+ priv->wkupevent = wkupevent;
+ priv->waitmask = waitmask;
+#ifdef CONFIG_SDIO_DMA
+ priv->xfrflags = 0;
+#endif
+ putreg32(priv->xfrmask | priv->waitmask, STM32_SDMMC1_MASK);
+ leave_critical_section(flags);
+}
+
+/****************************************************************************
+ * Name: stm32_configxfrints
+ *
+ * Description:
+ * Enable SDIO interrupts needed to support the data transfer event
+ *
+ * Input Parameters:
+ * priv - A reference to the SDIO device state structure
+ * xfrmask - The set of bits in the SDIO MASK register to set
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+static void stm32_configxfrints(struct stm32_dev_s *priv, uint32_t xfrmask)
+{
+ irqstate_t flags;
+ flags = enter_critical_section();
+ priv->xfrmask = xfrmask;
+ putreg32(priv->xfrmask | priv->waitmask, STM32_SDMMC1_MASK);
+ leave_critical_section(flags);
+}
+
+/****************************************************************************
+ * Name: stm32_setpwrctrl
+ *
+ * Description:
+ * Change the PWRCTRL field of the SDIO POWER register to turn the SDIO
+ * ON or OFF
+ *
+ * Input Parameters:
+ * clkcr - A new PWRCTRL setting
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+static void stm32_setpwrctrl(uint32_t pwrctrl)
+{
+ uint32_t regval;
+
+ regval = getreg32(STM32_SDMMC1_POWER);
+ regval &= ~SDIO_POWER_PWRCTRL_MASK;
+ regval |= pwrctrl;
+ putreg32(regval, STM32_SDMMC1_POWER);
+}
+
+/****************************************************************************
+ * Name: stm32_getpwrctrl
+ *
+ * Description:
+ * Return the current value of the the PWRCTRL field of the SDIO POWER
+ * register. This function can be used to see if the SDIO is powered ON
+ * or OFF
+ *
+ * Input Parameters:
+ * None
+ *
+ * Returned Value:
+ * The current value of the the PWRCTRL field of the SDIO POWER register.
+ *
+ ****************************************************************************/
+
+static inline uint32_t stm32_getpwrctrl(void)
+{
+ return getreg32(STM32_SDMMC1_POWER) & SDIO_POWER_PWRCTRL_MASK;
+}
+
+/****************************************************************************
+ * DMA Helpers
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: stm32_sampleinit
+ *
+ * Description:
+ * Setup prior to collecting DMA samples
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_SDIO_XFRDEBUG
+static void stm32_sampleinit(void)
+{
+ memset(g_sampleregs, 0xff, DEBUG_NSAMPLES * sizeof(struct stm32_sampleregs_s));
+}
+#endif
+
+/****************************************************************************
+ * Name: stm32_sdiosample
+ *
+ * Description:
+ * Sample SDIO registers
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_SDIO_XFRDEBUG
+static void stm32_sdiosample(struct stm32_sdioregs_s *regs)
+{
+ regs->power = (uint8_t)getreg32(STM32_SDMMC1_POWER);
+ regs->clkcr = (uint16_t)getreg32(STM32_SDMMC1_CLKCR);
+ regs->dctrl = (uint16_t)getreg32(STM32_SDMMC1_DCTRL);
+ regs->dtimer = getreg32(STM32_SDMMC1_DTIMER);
+ regs->dlen = getreg32(STM32_SDMMC1_DLEN);
+ regs->dcount = getreg32(STM32_SDMMC1_DCOUNT);
+ regs->sta = getreg32(STM32_SDMMC1_STA);
+ regs->mask = getreg32(STM32_SDMMC1_MASK);
+ regs->fifocnt = getreg32(STM32_SDMMC1_FIFOCNT);
+}
+#endif
+
+/****************************************************************************
+ * Name: stm32_sample
+ *
+ * Description:
+ * Sample SDIO/DMA registers
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_SDIO_XFRDEBUG
+static void stm32_sample(struct stm32_dev_s *priv, int index)
+{
+ struct stm32_sampleregs_s *regs = &g_sampleregs[index];
+
+#if defined(CONFIG_DEBUG_DMA_INFO) && defined(CONFIG_SDIO_DMA)
+ if (priv->dmamode)
+ {
+ stm32_dmasample(priv->dma, ®s->dma);
+ }
+#endif
+
+ stm32_sdiosample(®s->sdio);
+}
+#endif
+
+/****************************************************************************
+ * Name: stm32_sdiodump
+ *
+ * Description:
+ * Dump one register sample
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_SDIO_XFRDEBUG
+static void stm32_sdiodump(struct stm32_sdioregs_s *regs, const char *msg)
+{
+ ferr("SDIO Registers: %s\n", msg);
+ ferr(" POWER[%08x]: %08x\n", STM32_SDMMC1_POWER, regs->power);
+ ferr(" CLKCR[%08x]: %08x\n", STM32_SDMMC1_CLKCR, regs->clkcr);
+ ferr(" DCTRL[%08x]: %08x\n", STM32_SDMMC1_DCTRL, regs->dctrl);
+ ferr(" DTIMER[%08x]: %08x\n", STM32_SDMMC1_DTIMER, regs->dtimer);
+ ferr(" DLEN[%08x]: %08x\n", STM32_SDMMC1_DLEN, regs->dlen);
+ ferr(" DCOUNT[%08x]: %08x\n", STM32_SDMMC1_DCOUNT, regs->dcount);
+ ferr(" STA[%08x]: %08x\n", STM32_SDMMC1_STA, regs->sta);
+ ferr(" MASK[%08x]: %08x\n", STM32_SDMMC1_MASK, regs->mask);
+ ferr("FIFOCNT[%08x]: %08x\n", STM32_SDMMC1_FIFOCNT, regs->fifocnt);
+}
+#endif
+
+/****************************************************************************
+ * Name: stm32_dumpsample
+ *
+ * Description:
+ * Dump one register sample
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_SDIO_XFRDEBUG
+static void stm32_dumpsample(struct stm32_dev_s *priv,
+ struct stm32_sampleregs_s *regs, const char *msg)
+{
+#if defined(CONFIG_DEBUG_DMA_INFO) && defined(CONFIG_SDIO_DMA)
+ if (priv->dmamode)
+ {
+ stm32_dmadump(priv->dma, ®s->dma, msg);
+ }
+#endif
+
+ stm32_sdiodump(®s->sdio, msg);
+}
+#endif
+
+/****************************************************************************
+ * Name: stm32_dumpsamples
+ *
+ * Description:
+ * Dump all sampled register data
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_SDIO_XFRDEBUG
+static void stm32_dumpsamples(struct stm32_dev_s *priv)
+{
+ stm32_dumpsample(priv, &g_sampleregs[SAMPLENDX_BEFORE_SETUP], "Before setup");
+
+#if defined(CONFIG_DEBUG_DMA_INFO) && defined(CONFIG_SDIO_DMA)
+ if (priv->dmamode)
+ {
+ stm32_dumpsample(priv, &g_sampleregs[SAMPLENDX_BEFORE_ENABLE], "Before DMA enable");
+ }
+#endif
+
+ stm32_dumpsample(priv, &g_sampleregs[SAMPLENDX_AFTER_SETUP], "After setup");
+ stm32_dumpsample(priv, &g_sampleregs[SAMPLENDX_END_TRANSFER], "End of transfer");
+
+#if defined(CONFIG_DEBUG_DMA_INFO) && defined(CONFIG_SDIO_DMA)
+ if (priv->dmamode)
+ {
+ stm32_dumpsample(priv, &g_sampleregs[SAMPLENDX_DMA_CALLBACK], "DMA Callback");
+ }
+#endif
+}
+#endif
+
+/****************************************************************************
+ * Name: stm32_dmacallback
+ *
+ * Description:
+ * Called when SDIO DMA completes
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_SDIO_DMA
+static void stm32_dmacallback(DMA_HANDLE handle, uint8_t status, void *arg)
+{
+ FAR struct stm32_dev_s *priv = (FAR struct stm32_dev_s *)arg;
+ DEBUGASSERT(priv->dmamode);
+ sdio_eventset_t result;
+
+ /* In the normal case, SDIO appears to handle the End-Of-Transfer interrupt
+ * first with the End-Of-DMA event occurring significantly later. On
+ * transfer errors, however, the DMA error will occur before the End-of-
+ * Transfer.
+ */
+
+ stm32_sample((struct stm32_dev_s *)arg, SAMPLENDX_DMA_CALLBACK);
+
+ /* Get the result of the DMA transfer */
+
+ if ((status & DMA_STATUS_ERROR) != 0)
+ {
+ fllerr("DMA error %02x, remaining: %d\n", status, priv->remaining);
+ result = SDIOWAIT_ERROR;
+ }
+ else
+ {
+ result = SDIOWAIT_TRANSFERDONE;
+ }
+
+ /* Then terminate the transfer if this completes all of the steps in the
+ * transfer OR if a DMA error occurred. In the non-error case, we should
+ * already have the SDIO transfer done interrupt. If not, the transfer
+ * will appropriately time out.
+ */
+
+ priv->xfrflags |= SDIO_DMADONE_FLAG;
+ if (priv->xfrflags == SDIO_ALLDONE || result == SDIOWAIT_ERROR)
+ {
+ stm32_endtransfer(priv, result);
+ }
+}
+#endif
+
+/****************************************************************************
+ * Data Transfer Helpers
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: stm32_log2
+ *
+ * Description:
+ * Take (approximate) log base 2 of the provided number (Only works if the
+ * provided number is a power of 2).
+ *
+ ****************************************************************************/
+
+static uint8_t stm32_log2(uint16_t value)
+{
+ uint8_t log2 = 0;
+
+ /* 0000 0000 0000 0001 -> return 0,
+ * 0000 0000 0000 001x -> return 1,
+ * 0000 0000 0000 01xx -> return 2,
+ * 0000 0000 0000 1xxx -> return 3,
+ * ...
+ * 1xxx xxxx xxxx xxxx -> return 15,
+ */
+
+ DEBUGASSERT(value > 0);
+ while (value != 1)
+ {
+ value >>= 1;
+ log2++;
+ }
+
+ return log2;
+}
+
+/****************************************************************************
+ * Name: stm32_dataconfig
+ *
+ * Description:
+ * Configure the SDIO data path for the next data transfer
+ *
+ ****************************************************************************/
+
+static void stm32_dataconfig(uint32_t timeout, uint32_t dlen, uint32_t dctrl)
+{
+ uint32_t regval = 0;
+
+ /* Enable data path */
+
+ putreg32(timeout, STM32_SDMMC1_DTIMER); /* Set DTIMER */
+ putreg32(dlen, STM32_SDMMC1_DLEN); /* Set DLEN */
+
+ /* Configure DCTRL DTDIR, DTMODE, and DBLOCKSIZE fields and set the DTEN
+ * field
+ */
+
+ regval = getreg32(STM32_SDMMC1_DCTRL);
+ regval &= ~(SDIO_DCTRL_DTDIR | SDIO_DCTRL_DTMODE | SDIO_DCTRL_DBLOCKSIZE_MASK);
+ dctrl &= (SDIO_DCTRL_DTDIR | SDIO_DCTRL_DTMODE | SDIO_DCTRL_DBLOCKSIZE_MASK);
+ regval |= (dctrl | SDIO_DCTRL_DTEN);
+ putreg32(regval, STM32_SDMMC1_DCTRL);
+}
+
+/****************************************************************************
+ * Name: stm32_datadisable
+ *
+ * Description:
+ * Disable the SDIO data path setup by stm32_dataconfig() and
+ * disable DMA.
+ *
+ ****************************************************************************/
+
+static void stm32_datadisable(void)
+{
+ uint32_t regval;
+
+ /* Disable the data path */
+
+ putreg32(SDIO_DTIMER_DATATIMEOUT, STM32_SDMMC1_DTIMER); /* Reset DTIMER */
+ putreg32(0, STM32_SDMMC1_DLEN); /* Reset DLEN */
+
+ /* Reset DCTRL DTEN, DTDIR, DTMODE, DMAEN, and DBLOCKSIZE fields */
+
+ regval = getreg32(STM32_SDMMC1_DCTRL);
+ regval &= ~(SDIO_DCTRL_DTEN | SDIO_DCTRL_DTDIR | SDIO_DCTRL_DTMODE |
+ SDIO_DCTRL_DMAEN | SDIO_DCTRL_DBLOCKSIZE_MASK);
+ putreg32(regval, STM32_SDMMC1_DCTRL);
+}
+
+/****************************************************************************
+ * Name: stm32_sendfifo
+ *
+ * Description:
+ * Send SDIO data in interrupt mode
+ *
+ * Input Parameters:
+ * priv - An instance of the SDIO device interface
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+static void stm32_sendfifo(struct stm32_dev_s *priv)
+{
+ union
+ {
+ uint32_t w;
+ uint8_t b[4];
+ } data;
+
+ /* Loop while there is more data to be sent and the RX FIFO is not full */
+
+ while (priv->remaining > 0 &&
+ (getreg32(STM32_SDMMC1_STA) & SDIO_STA_TXFIFOF) == 0)
+ {
+ /* Is there a full word remaining in the user buffer? */
+
+ if (priv->remaining >= sizeof(uint32_t))
+ {
+ /* Yes, transfer the word to the TX FIFO */
+
+ data.w = *priv->buffer++;
+ priv->remaining -= sizeof(uint32_t);
+ }
+ else
+ {
+ /* No.. transfer just the bytes remaining in the user buffer,
+ * padding with zero as necessary to extend to a full word.
+ */
+
+ uint8_t *ptr = (uint8_t *)priv->remaining;
+ int i;
+
+ data.w = 0;
+ for (i = 0; i < (int)priv->remaining; i++)
+ {
+ data.b[i] = *ptr++;
+ }
+
+ /* Now the transfer is finished */
+
+ priv->remaining = 0;
+ }
+
+ /* Put the word in the FIFO */
+
+ putreg32(data.w, STM32_SDMMC1_FIFO);
+ }
+}
+
+/****************************************************************************
+ * Name: stm32_recvfifo
+ *
+ * Description:
+ * Receive SDIO data in interrupt mode
+ *
+ * Input Parameters:
+ * priv - An instance of the SDIO device interface
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+static void stm32_recvfifo(struct stm32_dev_s *priv)
+{
+ union
+ {
+ uint32_t w;
+ uint8_t b[4];
+ } data;
+
+ /* Loop while there is space to store the data and there is more
+ * data available in the RX FIFO.
+ */
+
+ while (priv->remaining > 0 &&
+ (getreg32(STM32_SDMMC1_STA) & SDIO_STA_RXDAVL) != 0)
+ {
+ /* Read the next word from the RX FIFO */
+
+ data.w = getreg32(STM32_SDMMC1_FIFO);
+ if (priv->remaining >= sizeof(uint32_t))
+ {
+ /* Transfer the whole word to the user buffer */
+
+ *priv->buffer++ = data.w;
+ priv->remaining -= sizeof(uint32_t);
+ }
+ else
+ {
+ /* Transfer any trailing fractional word */
+
+ uint8_t *ptr = (uint8_t *)priv->buffer;
+ int i;
+
+ for (i = 0; i < (int)priv->remaining; i++)
+ {
+ *ptr++ = data.b[i];
+ }
+
+ /* Now the transfer is finished */
+
+ priv->remaining = 0;
+ }
+ }
+}
+
+/****************************************************************************
+ * Name: stm32_eventtimeout
+ *
+ * Description:
+ * The watchdog timeout setup when the event wait start has expired without
+ * any other waited-for event occurring.
+ *
+ * Input Parameters:
+ * argc - The number of arguments (should be 1)
+ * arg - The argument (state structure reference cast to uint32_t)
+ *
+ * Returned Value:
+ * None
+ *
+ * Assumptions:
+ * Always called from the interrupt level with interrupts disabled.
+ *
+ ****************************************************************************/
+
+static void stm32_eventtimeout(int argc, uint32_t arg)
+{
+ struct stm32_dev_s *priv = (struct stm32_dev_s *)arg;
+
+ /* There is always race conditions with timer expirations. */
+
+ DEBUGASSERT((priv->waitevents & SDIOWAIT_TIMEOUT) != 0 || priv->wkupevent != 0);
+
+ /* Is a data transfer complete event expected? */
+
+ if ((priv->waitevents & SDIOWAIT_TIMEOUT) != 0)
+ {
+ /* Yes.. wake up any waiting threads */
+
+ stm32_endwait(priv, SDIOWAIT_TIMEOUT);
+ fllerr("Timeout: remaining: %d\n", priv->remaining);
+ }
+}
+
+/****************************************************************************
+ * Name: stm32_endwait
+ *
+ * Description:
+ * Wake up a waiting thread if the waited-for event has occurred.
+ *
+ * Input Parameters:
+ * priv - An instance of the SDIO device interface
+ * wkupevent - The event that caused the wait to end
+ *
+ * Returned Value:
+ * None
+ *
+ * Assumptions:
+ * Always called from the interrupt level with interrupts disabled.
+ *
+ ****************************************************************************/
+
+static void stm32_endwait(struct stm32_dev_s *priv, sdio_eventset_t wkupevent)
+{
+ /* Cancel the watchdog timeout */
+
+ (void)wd_cancel(priv->waitwdog);
+
+ /* Disable event-related interrupts */
+
+ stm32_configwaitints(priv, 0, 0, wkupevent);
+
+ /* Wake up the waiting thread */
+
+ stm32_givesem(priv);
+}
+
+/****************************************************************************
+ * Name: stm32_endtransfer
+ *
+ * Description:
+ * Terminate a transfer with the provided status. This function is called
+ * only from the SDIO interrupt handler when end-of-transfer conditions
+ * are detected.
+ *
+ * Input Parameters:
+ * priv - An instance of the SDIO device interface
+ * wkupevent - The event that caused the transfer to end
+ *
+ * Returned Value:
+ * None
+ *
+ * Assumptions:
+ * Always called from the interrupt level with interrupts disabled.
+ *
+ ****************************************************************************/
+
+static void stm32_endtransfer(struct stm32_dev_s *priv, sdio_eventset_t wkupevent)
+{
+ /* Disable all transfer related interrupts */
+
+ stm32_configxfrints(priv, 0);
+
+ /* Clearing pending interrupt status on all transfer related interrupts */
+
+ putreg32(SDIO_XFRDONE_ICR, STM32_SDMMC1_ICR);
+
+ /* If this was a DMA transfer, make sure that DMA is stopped */
+
+#ifdef CONFIG_SDIO_DMA
+ if (priv->dmamode)
+ {
+ /* DMA debug instrumentation */
+
+ stm32_sample(priv, SAMPLENDX_END_TRANSFER);
+
+ /* Make sure that the DMA is stopped (it will be stopped automatically
+ * on normal transfers, but not necessarily when the transfer terminates
+ * on an error condition).
+ */
+
+ stm32_dmastop(priv->dma);
+ }
+#endif
+
+ /* Mark the transfer finished */
+
+ priv->remaining = 0;
+
+ /* Is a thread wait for these data transfer complete events? */
+
+ if ((priv->waitevents & wkupevent) != 0)
+ {
+ /* Yes.. wake up any waiting threads */
+
+ stm32_endwait(priv, wkupevent);
+ }
+}
+
+/****************************************************************************
+ * Interrupt Handling
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: stm32_rdyinterrupt
+ *
+ * Description:
+ * SDIO ready interrupt handler
+ *
+ * Input Parameters:
+ * dev - An instance of the SDIO device interface
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_MMCSD_SDIOWAIT_WRCOMPLETE
+static int stm32_rdyinterrupt(int irq, void *context)
+{
+ struct stm32_dev_s *priv = &g_sdiodev;
+ stm32_endwait(priv, SDIOWAIT_WRCOMPLETE);
+ return OK;
+}
+#endif
+
+/****************************************************************************
+ * Name: stm32_interrupt
+ *
+ * Description:
+ * SDIO interrupt handler
+ *
+ * Input Parameters:
+ * dev - An instance of the SDIO device interface
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+static int stm32_interrupt(int irq, void *context)
+{
+ struct stm32_dev_s *priv = &g_sdiodev;
+ uint32_t enabled;
+ uint32_t pending;
+
+ /* Loop while there are pending interrupts. Check the SDIO status
+ * register. Mask out all bits that don't correspond to enabled
+ * interrupts. (This depends on the fact that bits are ordered
+ * the same in both the STA and MASK register). If there are non-zero
+ * bits remaining, then we have work to do here.
+ */
+
+ while ((enabled = getreg32(STM32_SDMMC1_STA) & getreg32(STM32_SDMMC1_MASK)) != 0)
+ {
+ /* Handle in progress, interrupt driven data transfers ****************/
+
+ pending = enabled & priv->xfrmask;
+ if (pending != 0)
+ {
+#ifdef CONFIG_SDIO_DMA
+ if (!priv->dmamode)
+#endif
+ {
+ /* Is the RX FIFO half full or more? Is so then we must be
+ * processing a receive transaction.
+ */
+
+ if ((pending & SDIO_STA_RXFIFOHF) != 0)
+ {
+ /* Receive data from the RX FIFO */
+
+ stm32_recvfifo(priv);
+ }
+
+ /* Otherwise, Is the transmit FIFO half empty or less? If so we must
+ * be processing a send transaction. NOTE: We can't be processing
+ * both!
+ */
+
+ else if ((pending & SDIO_STA_TXFIFOHE) != 0)
+ {
+ /* Send data via the TX FIFO */
+
+ stm32_sendfifo(priv);
+ }
+ }
+
+ /* Handle data end events */
+
+ if ((pending & SDIO_STA_DATAEND) != 0)
+ {
+ /* Handle any data remaining the RX FIFO. If the RX FIFO is
+ * less than half full at the end of the transfer, then no
+ * half-full interrupt will be received.
+ */
+
+ /* Was this transfer performed in DMA mode? */
+
+#ifdef CONFIG_SDIO_DMA
+ if (priv->dmamode)
+ {
+ /* Yes.. Terminate the transfers only if the DMA has also
+ * finished.
+ */
+
+ priv->xfrflags |= SDIO_XFRDONE_FLAG;
+ if (priv->xfrflags == SDIO_ALLDONE)
+ {
+ stm32_endtransfer(priv, SDIOWAIT_TRANSFERDONE);
+ }
+
+ /* Otherwise, just disable futher transfer interrupts and
+ * wait for the DMA complete event.
+ */
+
+ else
+ {
+ stm32_configxfrints(priv, 0);
+ }
+ }
+ else
+#endif
+ {
+ /* Receive data from the RX FIFO */
+
+ stm32_recvfifo(priv);
+
+ /* Then terminate the transfer */
+
+ stm32_endtransfer(priv, SDIOWAIT_TRANSFERDONE);
+ }
+ }
+
+ /* Handle data block send/receive CRC failure */
+
+ else if ((pending & SDIO_STA_DCRCFAIL) != 0)
+ {
+ /* Terminate the transfer with an error */
+
+ fllerr("ERROR: Data block CRC failure, remaining: %d\n", priv->remaining);
+ stm32_endtransfer(priv, SDIOWAIT_TRANSFERDONE | SDIOWAIT_ERROR);
+ }
+
+ /* Handle data timeout error */
+
+ else if ((pending & SDIO_STA_DTIMEOUT) != 0)
+ {
+ /* Terminate the transfer with an error */
+
+ fllerr("ERROR: Data timeout, remaining: %d\n", priv->remaining);
+ stm32_endtransfer(priv, SDIOWAIT_TRANSFERDONE | SDIOWAIT_TIMEOUT);
+ }
+
+ /* Handle RX FIFO overrun error */
+
+ else if ((pending & SDIO_STA_RXOVERR) != 0)
+ {
+ /* Terminate the transfer with an error */
+
+ fllerr("ERROR: RX FIFO overrun, remaining: %d\n", priv->remaining);
+ stm32_endtransfer(priv, SDIOWAIT_TRANSFERDONE | SDIOWAIT_ERROR);
+ }
+
+ /* Handle TX FIFO underrun error */
+
+ else if ((pending & SDIO_STA_TXUNDERR) != 0)
+ {
+ /* Terminate the transfer with an error */
+
+ fllerr("ERROR: TX FIFO underrun, remaining: %d\n", priv->remaining);
+ stm32_endtransfer(priv, SDIOWAIT_TRANSFERDONE | SDIOWAIT_ERROR);
+ }
+
+ /* Handle start bit error */
+
+ else if ((pending & SDIO_STA_STBITERR) != 0)
+ {
+ /* Terminate the transfer with an error */
+
+ fllerr("ERROR: Start bit, remaining: %d\n", priv->remaining);
+ stm32_endtransfer(priv, SDIOWAIT_TRANSFERDONE | SDIOWAIT_ERROR);
+ }
+ }
+
+ /* Handle wait events *************************************************/
+
+ pending = enabled & priv->waitmask;
+ if (pending != 0)
+ {
+ /* Is this a response completion event? */
+
+ if ((pending & SDIO_RESPDONE_STA) != 0)
+ {
+ /* Yes.. Is their a thread waiting for response done? */
+
+ if ((priv->waitevents & SDIOWAIT_RESPONSEDONE) != 0)
+ {
+ /* Yes.. wake the thread up */
+
+ putreg32(SDIO_RESPDONE_ICR | SDIO_CMDDONE_ICR, STM32_SDMMC1_ICR);
+ stm32_endwait(priv, SDIOWAIT_RESPONSEDONE);
+ }
+ }
+
+ /* Is this a command completion event? */
+
+ if ((pending & SDIO_CMDDONE_STA) != 0)
+ {
+ /* Yes.. Is their a thread waiting for command done? */
+
+ if ((priv->waitevents & SDIOWAIT_RESPONSEDONE) != 0)
+ {
+ /* Yes.. wake the thread up */
+
+ putreg32(SDIO_CMDDONE_ICR, STM32_SDMMC1_ICR);
+ stm32_endwait(priv, SDIOWAIT_CMDDONE);
+ }
+ }
+ }
+ }
+
+ return OK;
+}
+
+/****************************************************************************
+ * SDIO Interface Methods
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: stm32_lock
+ *
+ * Description:
+ * Locks the bus. Function calls low-level multiplexed bus routines to
+ * resolve bus requests and acknowledgment issues.
+ *
+ * Input Parameters:
+ * dev - An instance of the SDIO device interface
+ * lock - TRUE to lock, FALSE to unlock.
+ *
+ * Returned Value:
+ * OK on success; a negated errno on failure
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_SDIO_MUXBUS
+static int stm32_lock(FAR struct sdio_dev_s *dev, bool lock)
+{
+ /* Single SDIO instance so there is only one possibility. The multiplex
+ * bus is part of board support package.
+ */
+
+ stm32_muxbus_sdio_lock(lock);
+ return OK;
+}
+#endif
+
+/****************************************************************************
+ * Name: stm32_reset
+ *
+ * Description:
+ * Reset the SDIO controller. Undo all setup and initialization.
+ *
+ * Input Parameters:
+ * dev - An instance of the SDIO device interface
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+static void stm32_reset(FAR struct sdio_dev_s *dev)
+{
+ FAR struct stm32_dev_s *priv = (FAR struct stm32_dev_s *)dev;
+ irqstate_t flags;
+
+ /* Disable clocking */
+
+ flags = enter_critical_section();
+ stm32_setpwrctrl(SDIO_POWER_PWRCTRL_OFF);
+
+ /* Put SDIO registers in their default, reset state */
+
+ stm32_default();
+
+ /* Reset data */
+
+ priv->waitevents = 0; /* Set of events to be waited for */
+ priv->waitmask = 0; /* Interrupt enables for event waiting */
+ priv->wkupevent = 0; /* The event that caused the wakeup */
+#ifdef CONFIG_SDIO_DMA
+ priv->xfrflags = 0; /* Used to synchronize SDIO and DMA completion events */
+#endif
+
+ wd_cancel(priv->waitwdog); /* Cancel any timeouts */
+
+ /* Interrupt mode data transfer support */
+
+ priv->buffer = 0; /* Address of current R/W buffer */
+ priv->remaining = 0; /* Number of bytes remaining in the transfer */
+ priv->xfrmask = 0; /* Interrupt enables for data transfer */
+
+ /* DMA data transfer support */
+
+ priv->widebus = false; /* Required for DMA support */
+#ifdef CONFIG_SDIO_DMA
+ priv->dmamode = false; /* true: DMA mode transfer */
+#endif
+
+ /* Configure the SDIO peripheral */
+
+ stm32_setclkcr(STM32_CLCKCR_INIT | SDIO_CLKCR_CLKEN);
+ stm32_setpwrctrl(SDIO_POWER_PWRCTRL_ON);
+ leave_critical_section(flags);
+
+ finfo("CLCKR: %08x POWER: %08x\n",
+ getreg32(STM32_SDMMC1_CLKCR), getreg32(STM32_SDMMC1_POWER));
+}
+
+/****************************************************************************
+ * Name: stm32_status
+ *
+ * Description:
+ * Get SDIO status.
+ *
+ * Input Parameters:
+ * dev - Device-specific state data
+ *
+ * Returned Value:
+ * Returns a bitset of status values (see stm32_status_* defines)
+ *
+ ****************************************************************************/
+
+static uint8_t stm32_status(FAR struct sdio_dev_s *dev)
+{
+ struct stm32_dev_s *priv = (struct stm32_dev_s *)dev;
+ return priv->cdstatus;
+}
+
+/****************************************************************************
+ * Name: stm32_widebus
+ *
+ * Description:
+ * Called after change in Bus width has been selected (via ACMD6). Most
+ * controllers will need to perform some special operations to work
+ * correctly in the new bus mode.
+ *
+ * Input Parameters:
+ * dev - An instance of the SDIO device interface
+ * wide - true: wide bus (4-bit) bus mode enabled
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+static void stm32_widebus(FAR struct sdio_dev_s *dev, bool wide)
+{
+ struct stm32_dev_s *priv = (struct stm32_dev_s *)dev;
+ priv->widebus = wide;
+}
+
+/****************************************************************************
+ * Name: stm32_clock
+ *
+ * Description:
+ * Enable/disable SDIO clocking
+ *
+ * Input Parameters:
+ * dev - An instance of the SDIO device interface
+ * rate - Specifies the clocking to use (see enum sdio_clock_e)
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+static void stm32_clock(FAR struct sdio_dev_s *dev, enum sdio_clock_e rate)
+{
+ uint32_t clckr;
+
+ switch (rate)
+ {
+ /* Disable clocking (with default ID mode divisor) */
+
+ default:
+ case CLOCK_SDIO_DISABLED:
+ clckr = STM32_CLCKCR_INIT;
+ return;
+
+ /* Enable in initial ID mode clocking (<400KHz) */
+
+ case CLOCK_IDMODE:
+ clckr = (STM32_CLCKCR_INIT | SDIO_CLKCR_CLKEN);
+ break;
+
+ /* Enable in MMC normal operation clocking */
+
+ case CLOCK_MMC_TRANSFER:
+ clckr = (SDIO_CLKCR_MMCXFR | SDIO_CLKCR_CLKEN);
+ break;
+
+ /* SD normal operation clocking (wide 4-bit mode) */
+
+ case CLOCK_SD_TRANSFER_4BIT:
+#ifndef CONFIG_SDIO_WIDTH_D1_ONLY
+ clckr = (SDIO_CLCKR_SDWIDEXFR | SDIO_CLKCR_CLKEN);
+ break;
+#endif
+
+ /* SD normal operation clocking (narrow 1-bit mode) */
+
+ case CLOCK_SD_TRANSFER_1BIT:
+ clckr = (SDIO_CLCKR_SDXFR | SDIO_CLKCR_CLKEN);
+ break;
+ }
+
+ /* Set the new clock frequency along with the clock enable/disable bit */
+
+ stm32_setclkcr(clckr);
+}
+
+/****************************************************************************
+ * Name: stm32_attach
+ *
+ * Description:
+ * Attach and prepare interrupts
+ *
+ * Input Parameters:
+ * dev - An instance of the SDIO device interface
+ *
+ * Returned Value:
+ * OK on success; A negated errno on failure.
+ *
+ ****************************************************************************/
+
+static int stm32_attach(FAR struct sdio_dev_s *dev)
+{
+ int ret;
+
+ /* Attach the SDIO interrupt handler */
+
+ ret = irq_attach(STM32_IRQ_SDMMC1, stm32_interrupt);
+ if (ret == OK)
+ {
+
+ /* Disable all interrupts at the SDIO controller and clear static
+ * interrupt flags
+ */
+
+ putreg32(SDIO_MASK_RESET, STM32_SDMMC1_MASK);
+ putreg32(SDIO_ICR_STATICFLAGS, STM32_SDMMC1_ICR);
+
+ /* Enable SDIO interrupts at the NVIC. They can now be enabled at
+ * the SDIO controller as needed.
+ */
+
+ up_enable_irq(STM32_IRQ_SDMMC1);
+
+#ifdef CONFIG_ARCH_IRQPRIO
+ /* Set the interrupt priority */
+
+ up_prioritize_irq(STM32_IRQ_SDIO, CONFIG_SDIO_PRI);
+#endif
+ }
+
+ return ret;
+}
+
+/****************************************************************************
+ * Name: stm32_sendcmd
+ *
+ * Description:
+ * Send the SDIO command
+ *
+ * Input Parameters:
+ * dev - An instance of the SDIO device interface
+ * cmd - The command to send (32-bits, encoded)
+ * arg - 32-bit argument required with some commands
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+static int stm32_sendcmd(FAR struct sdio_dev_s *dev, uint32_t cmd, uint32_t arg)
+{
+ uint32_t regval;
+ uint32_t cmdidx;
+
+ /* Set the SDIO Argument value */
+
+ putreg32(arg, STM32_SDMMC1_ARG);
+
+ /* Clear CMDINDEX, WAITRESP, WAITINT, WAITPEND, and CPSMEN bits */
+
+ regval = getreg32(STM32_SDMMC1_CMD);
+ regval &= ~(SDIO_CMD_CMDINDEX_MASK | SDIO_CMD_WAITRESP_MASK |
+ SDIO_CMD_WAITINT | SDIO_CMD_WAITPEND | SDIO_CMD_CPSMEN);
+
+ /* Set WAITRESP bits */
+
+ switch (cmd & MMCSD_RESPONSE_MASK)
+ {
+ case MMCSD_NO_RESPONSE:
+ regval |= SDIO_CMD_NORESPONSE;
+ break;
+
+ case MMCSD_R1_RESPONSE:
+ case MMCSD_R1B_RESPONSE:
+ case MMCSD_R3_RESPONSE:
+ case MMCSD_R4_RESPONSE:
+ case MMCSD_R5_RESPONSE:
+ case MMCSD_R6_RESPONSE:
+ case MMCSD_R7_RESPONSE:
+ regval |= SDIO_CMD_SHORTRESPONSE;
+ break;
+
+ case MMCSD_R2_RESPONSE:
+ regval |= SDIO_CMD_LONGRESPONSE;
+ break;
+ }
+
+ /* Set CPSMEN and the command index */
+
+ cmdidx = (cmd & MMCSD_CMDIDX_MASK) >> MMCSD_CMDIDX_SHIFT;
+ regval |= cmdidx | SDIO_CMD_CPSMEN;
+
+ finfo("cmd: %08x arg: %08x regval: %08x\n", cmd, arg, regval);
+
+ /* Write the SDIO CMD */
+
+ putreg32(SDIO_RESPDONE_ICR | SDIO_CMDDONE_ICR, STM32_SDMMC1_ICR);
+ putreg32(regval, STM32_SDMMC1_CMD);
+ return OK;
+}
+
+/****************************************************************************
+ * Name: stm32_recvsetup
+ *
+ * Description:
+ * Setup hardware in preparation for data transfer from the card in non-DMA
+ * (interrupt driven mode). This method will do whatever controller setup
+ * is necessary. This would be called for SD memory just BEFORE sending
+ * CMD13 (SEND_STATUS), CMD17 (READ_SINGLE_BLOCK), CMD18
+ * (READ_MULTIPLE_BLOCKS), ACMD51 (SEND_SCR), etc. Normally, SDIO_WAITEVENT
+ * will be called to receive the indication that the transfer is complete.
+ *
+ * Input Parameters:
+ * dev - An instance of the SDIO device interface
+ * buffer - Address of the buffer in which to receive the data
+ * nbytes - The number of bytes in the transfer
+ *
+ * Returned Value:
+ * Number of bytes sent on success; a negated errno on failure
+ *
+ ****************************************************************************/
+
+static int stm32_recvsetup(FAR struct sdio_dev_s *dev, FAR uint8_t *buffer,
+ size_t nbytes)
+{
+ struct stm32_dev_s *priv = (struct stm32_dev_s *)dev;
+ uint32_t dblocksize;
+
+ DEBUGASSERT(priv != NULL && buffer != NULL && nbytes > 0);
+ DEBUGASSERT(((uint32_t)buffer & 3) == 0);
+
+ /* Reset the DPSM configuration */
+
+ stm32_datadisable();
+ stm32_sampleinit();
+ stm32_sample(priv, SAMPLENDX_BEFORE_SETUP);
+
+ /* Save the destination buffer information for use by the interrupt handler */
+
+ priv->buffer = (uint32_t *)buffer;
+ priv->remaining = nbytes;
+#ifdef CONFIG_SDIO_DMA
+ priv->dmamode = false;
+#endif
+
+ /* Then set up the SDIO data path */
+
+ dblocksize = stm32_log2(nbytes) << SDIO_DCTRL_DBLOCKSIZE_SHIFT;
+ stm32_dataconfig(SDIO_DTIMER_DATATIMEOUT, nbytes, dblocksize | SDIO_DCTRL_DTDIR);
+
+ /* And enable interrupts */
+
+ stm32_configxfrints(priv, SDIO_RECV_MASK);
+ stm32_sample(priv, SAMPLENDX_AFTER_SETUP);
+ return OK;
+}
+
+/****************************************************************************
+ * Name: stm32_sendsetup
+ *
+ * Description:
+ * Setup hardware in preparation for data transfer from the card. This method
+ * will do whatever controller setup is necessary. This would be called
+ * for SD memory just AFTER sending CMD24 (WRITE_BLOCK), CMD25
+ * (WRITE_MULTIPLE_BLOCK), ... and before SDIO_SENDDATA is called.
+ *
+ * Input Parameters:
+ * dev - An instance of the SDIO device interface
+ * buffer - Address of the buffer containing the data to send
+ * nbytes - The number of bytes in the transfer
+ *
+ * Returned Value:
+ * Number of bytes sent on success; a negated errno on failure
+ *
+ ****************************************************************************/
+
+static int stm32_sendsetup(FAR struct sdio_dev_s *dev, FAR const uint8_t *buffer,
+ size_t nbytes)
+{
+ struct stm32_dev_s *priv = (struct stm32_dev_s *)dev;
+ uint32_t dblocksize;
+
+ DEBUGASSERT(priv != NULL && buffer != NULL && nbytes > 0);
+ DEBUGASSERT(((uint32_t)buffer & 3) == 0);
+
+ /* Reset the DPSM configuration */
+
+ stm32_datadisable();
+ stm32_sampleinit();
+ stm32_sample(priv, SAMPLENDX_BEFORE_SETUP);
+
+ /* Save the source buffer information for use by the interrupt handler */
+
+ priv->buffer = (uint32_t *)buffer;
+ priv->remaining = nbytes;
+#ifdef CONFIG_SDIO_DMA
+ priv->dmamode = false;
+#endif
+
+ /* Then set up the SDIO data path */
+
+ dblocksize = stm32_log2(nbytes) << SDIO_DCTRL_DBLOCKSIZE_SHIFT;
+ stm32_dataconfig(SDIO_DTIMER_DATATIMEOUT, nbytes, dblocksize);
+
+ /* Enable TX interrupts */
+
+ stm32_configxfrints(priv, SDIO_SEND_MASK);
+ stm32_sample(priv, SAMPLENDX_AFTER_SETUP);
+ return OK;
+}
+
+/****************************************************************************
+ * Name: stm32_cancel
+ *
+ * Description:
+ * Cancel the data transfer setup of SDIO_RECVSETUP, SDIO_SENDSETUP,
+ * SDIO_DMARECVSETUP or SDIO_DMASENDSETUP. This must be called to cancel
+ * the data transfer setup if, for some reason, you cannot perform the
+ * transfer.
+ *
+ * Input Parameters:
+ * dev - An instance of the SDIO device interface
+ *
+ * Returned Value:
+ * OK is success; a negated errno on failure
+ *
+ ****************************************************************************/
+
+static int stm32_cancel(FAR struct sdio_dev_s *dev)
+{
+ struct stm32_dev_s *priv = (struct stm32_dev_s *)dev;
+
+ /* Disable all transfer- and event- related interrupts */
+
+ stm32_configxfrints(priv, 0);
+ stm32_configwaitints(priv, 0, 0, 0);
+
+ /* Clearing pending interrupt status on all transfer- and event- related
+ * interrupts
+ */
+
+ putreg32(SDIO_WAITALL_ICR, STM32_SDMMC1_ICR);
+
+ /* Cancel any watchdog timeout */
+
+ (void)wd_cancel(priv->waitwdog);
+
+ /* If this was a DMA transfer, make sure that DMA is stopped */
+
+#ifdef CONFIG_SDIO_DMA
+ if (priv->dmamode)
+ {
+ /* Make sure that the DMA is stopped (it will be stopped automatically
+ * on normal transfers, but not necessarily when the transfer terminates
+ * on an error condition.
+ */
+
+ stm32_dmastop(priv->dma);
+ }
+#endif
+
+ /* Mark no transfer in progress */
+
+ priv->remaining = 0;
+ return OK;
+}
+
+/****************************************************************************
+ * Name: stm32_waitresponse
+ *
+ * Description:
+ * Poll-wait for the response to the last command to be ready.
+ *
+ * Input Parameters:
+ * dev - An instance of the SDIO device interface
+ * cmd - The command that was sent. See 32-bit command definitions above.
+ *
+ * Returned Value:
+ * OK is success; a negated errno on failure
+ *
+ ****************************************************************************/
+
+static int stm32_waitresponse(FAR struct sdio_dev_s *dev, uint32_t cmd)
+{
+ int32_t timeout;
+ uint32_t events;
+
+ switch (cmd & MMCSD_RESPONSE_MASK)
+ {
+ case MMCSD_NO_RESPONSE:
+ events = SDIO_CMDDONE_STA;
+ timeout = SDIO_CMDTIMEOUT;
+ break;
+
+ case MMCSD_R1_RESPONSE:
+ case MMCSD_R1B_RESPONSE:
+ case MMCSD_R2_RESPONSE:
+ case MMCSD_R6_RESPONSE:
+ events = SDIO_RESPDONE_STA;
+ timeout = SDIO_LONGTIMEOUT;
+ break;
+
+ case MMCSD_R4_RESPONSE:
+ case MMCSD_R5_RESPONSE:
+ return -ENOSYS;
+
+ case MMCSD_R3_RESPONSE:
+ case MMCSD_R7_RESPONSE:
+ events = SDIO_RESPDONE_STA;
+ timeout = SDIO_CMDTIMEOUT;
+ break;
+
+ default:
+ return -EINVAL;
+ }
+
+ /* Then wait for the response (or timeout) */
+
+ while ((getreg32(STM32_SDMMC1_STA) & events) == 0)
+ {
+ if (--timeout <= 0)
+ {
+ ferr("ERROR: Timeout cmd: %08x events: %08x STA: %08x\n",
+ cmd, events, getreg32(STM32_SDMMC1_STA));
+
+ return -ETIMEDOUT;
+ }
+ }
+
+ putreg32(SDIO_CMDDONE_ICR, STM32_SDMMC1_ICR);
+ return OK;
+}
+
+/****************************************************************************
+ * Name: stm32_recvRx
+ *
+ * Description:
+ * Receive response to SDIO command. Only the critical payload is
+ * returned -- that is 32 bits for 48 bit status and 128 bits for 136 bit
+ * status. The driver implementation should verify the correctness of
+ * the remaining, non-returned bits (CRCs, CMD index, etc.).
+ *
+ * Input Parameters:
+ * dev - An instance of the SDIO device interface
+ * Rx - Buffer in which to receive the response
+ *
+ * Returned Value:
+ * Number of bytes sent on success; a negated errno on failure. Here a
+ * failure means only a faiure to obtain the requested reponse (due to
+ * transport problem -- timeout, CRC, etc.). The implementation only
+ * assures that the response is returned intacta and does not check errors
+ * within the response itself.
+ *
+ ****************************************************************************/
+
+static int stm32_recvshortcrc(FAR struct sdio_dev_s *dev, uint32_t cmd, uint32_t *rshort)
+{
+#ifdef CONFIG_DEBUG_FEATURES
+ uint32_t respcmd;
+#endif
+ uint32_t regval;
+ int ret = OK;
+
+ /* R1 Command response (48-bit)
+ * 47 0 Start bit
+ * 46 0 Transmission bit (0=from card)
+ * 45:40 bit5 - bit0 Command index (0-63)
+ * 39:8 bit31 - bit0 32-bit card status
+ * 7:1 bit6 - bit0 CRC7
+ * 0 1 End bit
+ *
+ * R1b Identical to R1 with the additional busy signaling via the data
+ * line.
+ *
+ * R6 Published RCA Response (48-bit, SD card only)
+ * 47 0 Start bit
+ * 46 0 Transmission bit (0=from card)
+ * 45:40 bit5 - bit0 Command index (0-63)
+ * 39:8 bit31 - bit0 32-bit Argument Field, consisting of:
+ * [31:16] New published RCA of card
+ * [15:0] Card status bits {23,22,19,12:0}
+ * 7:1 bit6 - bit0 CRC7
+ * 0 1 End bit
+ */
+
+
+#ifdef CONFIG_DEBUG_FEATURES
+ if (!rshort)
+ {
+ ferr("ERROR: rshort=NULL\n");
+ ret = -EINVAL;
+ }
+
+ /* Check that this is the correct response to this command */
+
+ else if ((cmd & MMCSD_RESPONSE_MASK) != MMCSD_R1_RESPONSE &&
+ (cmd & MMCSD_RESPONSE_MASK) != MMCSD_R1B_RESPONSE &&
+ (cmd & MMCSD_RESPONSE_MASK) != MMCSD_R6_RESPONSE)
+ {
+ ferr("ERROR: Wrong response CMD=%08x\n", cmd);
+ ret = -EINVAL;
+ }
+ else
+#endif
+ {
+ /* Check if a timeout or CRC error occurred */
+
+ regval = getreg32(STM32_SDMMC1_STA);
+ if ((regval & SDIO_STA_CTIMEOUT) != 0)
+ {
+ ferr("ERROR: Command timeout: %08x\n", regval);
+ ret = -ETIMEDOUT;
+ }
+ else if ((regval & SDIO_STA_CCRCFAIL) != 0)
+ {
+ ferr("ERROR: CRC failure: %08x\n", regval);
+ ret = -EIO;
+ }
+#ifdef CONFIG_DEBUG_FEATURES
+ else
+ {
+ /* Check response received is of desired command */
+
+ respcmd = getreg32(STM32_SDMMC1_RESPCMD);
+ if ((uint8_t)(respcmd & SDIO_RESPCMD_MASK) != (cmd & MMCSD_CMDIDX_MASK))
+ {
+ ferr("ERROR: RESCMD=%02x CMD=%08x\n", respcmd, cmd);
+ ret = -EINVAL;
+ }
+ }
+#endif
+ }
+
+ /* Clear all pending message completion events and return the R1/R6 response */
+
+ putreg32(SDIO_RESPDONE_ICR | SDIO_CMDDONE_ICR, STM32_SDMMC1_ICR);
+ *rshort = getreg32(STM32_SDMMC1_RESP1);
+ return ret;
+}
+
+static int stm32_recvlong(FAR struct sdio_dev_s *dev, uint32_t cmd, uint32_t rlong[4])
+{
+ uint32_t regval;
+ int ret = OK;
+
+ /* R2 CID, CSD register (136-bit)
+ * 135 0 Start bit
+ * 134 0 Transmission bit (0=from card)
+ * 133:128 bit5 - bit0 Reserved
+ * 127:1 bit127 - bit1 127-bit CID or CSD register
+ * (including internal CRC)
+ * 0 1 End bit
+ */
+
+#ifdef CONFIG_DEBUG_FEATURES
+ /* Check that R1 is the correct response to this command */
+
+ if ((cmd & MMCSD_RESPONSE_MASK) != MMCSD_R2_RESPONSE)
+ {
+ ferr("ERROR: Wrong response CMD=%08x\n", cmd);
+ ret = -EINVAL;
+ }
+ else
+#endif
+ {
+ /* Check if a timeout or CRC error occurred */
+
+ regval = getreg32(STM32_SDMMC1_STA);
+ if (regval & SDIO_STA_CTIMEOUT)
+ {
+ ferr("ERROR: Timeout STA: %08x\n", regval);
+ ret = -ETIMEDOUT;
+ }
+ else if (regval & SDIO_STA_CCRCFAIL)
+ {
+ ferr("ERROR: CRC fail STA: %08x\n", regval);
+ ret = -EIO;
+ }
+ }
+
+ /* Return the long response */
+
+ putreg32(SDIO_RESPDONE_ICR | SDIO_CMDDONE_ICR, STM32_SDMMC1_ICR);
+ if (rlong)
+ {
+ rlong[0] = getreg32(STM32_SDMMC1_RESP1);
+ rlong[1] = getreg32(STM32_SDMMC1_RESP2);
+ rlong[2] = getreg32(STM32_SDMMC1_RESP3);
+ rlong[3] = getreg32(STM32_SDMMC1_RESP4);
+ }
+ return ret;
+}
+
+static int stm32_recvshort(FAR struct sdio_dev_s *dev, uint32_t cmd, uint32_t *rshort)
+{
+ uint32_t regval;
+ int ret = OK;
+
+ /* R3 OCR (48-bit)
+ * 47 0 Start bit
+ * 46 0 Transmission bit (0=from card)
+ * 45:40 bit5 - bit0 Reserved
+ * 39:8 bit31 - bit0 32-bit OCR register
+ * 7:1 bit6 - bit0 Reserved
+ * 0 1 End bit
+ */
+
+ /* Check that this is the correct response to this command */
+
+#ifdef CONFIG_DEBUG_FEATURES
+ if ((cmd & MMCSD_RESPONSE_MASK) != MMCSD_R3_RESPONSE &&
+ (cmd & MMCSD_RESPONSE_MASK) != MMCSD_R7_RESPONSE)
+ {
+ ferr("ERROR: Wrong response CMD=%08x\n", cmd);
+ ret = -EINVAL;
+ }
+ else
+#endif
+ {
+ /* Check if a timeout occurred (Apparently a CRC error can terminate
+ * a good response)
+ */
+
+ regval = getreg32(STM32_SDMMC1_STA);
+ if (regval & SDIO_STA_CTIMEOUT)
+ {
+ ferr("ERROR: Timeout STA: %08x\n", regval);
+ ret = -ETIMEDOUT;
+ }
+ }
+
+ putreg32(SDIO_RESPDONE_ICR | SDIO_CMDDONE_ICR, STM32_SDMMC1_ICR);
+ if (rshort)
+ {
+ *rshort = getreg32(STM32_SDMMC1_RESP1);
+ }
+ return ret;
+}
+
+/* MMC responses not supported */
+
+static int stm32_recvnotimpl(FAR struct sdio_dev_s *dev, uint32_t cmd, uint32_t *rnotimpl)
+{
+ putreg32(SDIO_RESPDONE_ICR | SDIO_CMDDONE_ICR, STM32_SDMMC1_ICR);
+ return -ENOSYS;
+}
+
+/****************************************************************************
+ * Name: stm32_waitenable
+ *
+ * Description:
+ * Enable/disable of a set of SDIO wait events. This is part of the
+ * the SDIO_WAITEVENT sequence. The set of to-be-waited-for events is
+ * configured before calling stm32_eventwait. This is done in this way
+ * to help the driver to eliminate race conditions between the command
+ * setup and the subsequent events.
+ *
+ * The enabled events persist until either (1) SDIO_WAITENABLE is called
+ * again specifying a different set of wait events, or (2) SDIO_EVENTWAIT
+ * returns.
+ *
+ * Input Parameters:
+ * dev - An instance of the SDIO device interface
+ * eventset - A bitset of events to enable or disable (see SDIOWAIT_*
+ * definitions). 0=disable; 1=enable.
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+static void stm32_waitenable(FAR struct sdio_dev_s *dev,
+ sdio_eventset_t eventset)
+{
+ struct stm32_dev_s *priv = (struct stm32_dev_s *)dev;
+ uint32_t waitmask;
+
+ DEBUGASSERT(priv != NULL);
+
+ /* Disable event-related interrupts */
+
+ stm32_configwaitints(priv, 0, 0, 0);
+
+ /* Select the interrupt mask that will give us the appropriate wakeup
+ * interrupts.
+ */
+
+#if defined(CONFIG_MMCSD_SDIOWAIT_WRCOMPLETE)
+ if ((eventset & SDIOWAIT_WRCOMPLETE) != 0)
+ {
+ waitmask = SDIOWAIT_WRCOMPLETE;
+ }
+ else
+#endif
+ {
+ waitmask = 0;
+ if ((eventset & SDIOWAIT_CMDDONE) != 0)
+ {
+ waitmask |= SDIO_CMDDONE_MASK;
+ }
+
+ if ((eventset & SDIOWAIT_RESPONSEDONE) != 0)
+ {
+ waitmask |= SDIO_RESPDONE_MASK;
+ }
+
+ if ((eventset & SDIOWAIT_TRANSFERDONE) != 0)
+ {
+ waitmask |= SDIO_XFRDONE_MASK;
+ }
+
+ /* Enable event-related interrupts */
+
+ putreg32(SDIO_WAITALL_ICR, STM32_SDMMC1_ICR);
+ }
+
+ stm32_configwaitints(priv, waitmask, eventset, 0);
+}
+
+/****************************************************************************
+ * Name: stm32_eventwait
+ *
+ * Description:
+ * Wait for one of the enabled events to occur (or a timeout). Note that
+ * all events enabled by SDIO_WAITEVENTS are disabled when stm32_eventwait
+ * returns. SDIO_WAITEVENTS must be called again before stm32_eventwait
+ * can be used again.
+ *
+ * Input Parameters:
+ * dev - An instance of the SDIO device interface
+ * timeout - Maximum time in milliseconds to wait. Zero means immediate
+ * timeout with no wait. The timeout value is ignored if
+ * SDIOWAIT_TIMEOUT is not included in the waited-for eventset.
+ *
+ * Returned Value:
+ * Event set containing the event(s) that ended the wait. Should always
+ * be non-zero. All events are disabled after the wait concludes.
+ *
+ ****************************************************************************/
+
+static sdio_eventset_t stm32_eventwait(FAR struct sdio_dev_s *dev,
+ uint32_t timeout)
+{
+ struct stm32_dev_s *priv = (struct stm32_dev_s *)dev;
+ sdio_eventset_t wkupevent = 0;
+ irqstate_t flags;
+ int ret;
+
+ /* There is a race condition here... the event may have completed before
+ * we get here. In this case waitevents will be zero, but wkupevents will
+ * be non-zero (and, hopefully, the semaphore count will also be non-zero.
+ */
+
+ flags = enter_critical_section();
+ DEBUGASSERT(priv->waitevents != 0 || priv->wkupevent != 0);
+
+ /* Check if the timeout event is specified in the event set */
+
+ if ((priv->waitevents & SDIOWAIT_TIMEOUT) != 0)
+ {
+ int delay;
+
+ /* Yes.. Handle a cornercase: The user request a timeout event but
+ * with timeout == 0?
+ */
+
+ if (!timeout)
+ {
+ /* Then just tell the caller that we already timed out */
+
+ wkupevent = SDIOWAIT_TIMEOUT;
+ goto errout;
+ }
+
+ /* Start the watchdog timer */
+
+ delay = MSEC2TICK(timeout);
+ ret = wd_start(priv->waitwdog, delay, (wdentry_t)stm32_eventtimeout,
+ 1, (uint32_t)priv);
+ if (ret != OK)
+ {
+ ferr("ERROR: wd_start failed: %d\n", ret);
+ }
+ }
+
+#if defined(CONFIG_MMCSD_SDIOWAIT_WRCOMPLETE)
+ if ((priv->waitevents & SDIOWAIT_WRCOMPLETE) != 0)
+ {
+ /* Atomically read pin to see if ready (true) and determine if ISR fired
+ * If Pin is ready and if ISR did NOT fire end the wait here
+ */
+
+ if (stm32_gpioread(GPIO_SDMMC1_D0) &&
+ (priv->wkupevent & SDIOWAIT_WRCOMPLETE) == 0)
+ {
+ stm32_endwait(priv, SDIOWAIT_WRCOMPLETE);
+ }
+ }
+#endif
+
+ /* Loop until the event (or the timeout occurs). Race conditions are avoided
+ * by calling stm32_waitenable prior to triggering the logic that will cause
+ * the wait to terminate. Under certain race conditions, the waited-for
+ * may have already occurred before this function was called!
+ */
+
+ for (; ; )
+ {
+ /* Wait for an event in event set to occur. If this the event has already
+ * occurred, then the semaphore will already have been incremented and
+ * there will be no wait.
+ */
+
+ stm32_takesem(priv);
+ wkupevent = priv->wkupevent;
+
+ /* Check if the event has occurred. When the event has occurred, then
+ * evenset will be set to 0 and wkupevent will be set to a nonzero value.
+ */
+
+ if (wkupevent != 0)
+ {
+ /* Yes... break out of the loop with wkupevent non-zero */
+
+ break;
+ }
+ }
+
+ /* Disable event-related interrupts */
+
+ stm32_configwaitints(priv, 0, 0, 0);
+#ifdef CONFIG_SDIO_DMA
+ priv->xfrflags = 0;
+#endif
+
+errout:
+ leave_critical_section(flags);
+ stm32_dumpsamples(priv);
+ return wkupevent;
+}
+
+/****************************************************************************
+ * Name: stm32_callbackenable
+ *
+ * Description:
+ * Enable/disable of a set of SDIO callback events. This is part of the
+ * the SDIO callback sequence. The set of events is configured to enabled
+ * callbacks to the function provided in stm32_registercallback.
+ *
+ * Events are automatically disabled once the callback is performed and no
+ * further callback events will occur until they are again enabled by
+ * calling this methos.
+ *
+ * Input Parameters:
+ * dev - An instance of the SDIO device interface
+ * eventset - A bitset of events to enable or disable (see SDIOMEDIA_*
+ * definitions). 0=disable; 1=enable.
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+static void stm32_callbackenable(FAR struct sdio_dev_s *dev,
+ sdio_eventset_t eventset)
+{
+ struct stm32_dev_s *priv = (struct stm32_dev_s *)dev;
+
+ finfo("eventset: %02x\n", eventset);
+ DEBUGASSERT(priv != NULL);
+
+ priv->cbevents = eventset;
+ stm32_callback(priv);
+}
+
+/****************************************************************************
+ * Name: stm32_registercallback
+ *
+ * Description:
+ * Register a callback that that will be invoked on any media status
+ * change. Callbacks should not be made from interrupt handlers, rather
+ * interrupt level events should be handled by calling back on the work
+ * thread.
+ *
+ * When this method is called, all callbacks should be disabled until they
+ * are enabled via a call to SDIO_CALLBACKENABLE
+ *
+ * Input Parameters:
+ * dev - Device-specific state data
+ * callback - The funtion to call on the media change
+ * arg - A caller provided value to return with the callback
+ *
+ * Returned Value:
+ * 0 on success; negated errno on failure.
+ *
+ ****************************************************************************/
+
+static int stm32_registercallback(FAR struct sdio_dev_s *dev,
+ worker_t callback, void *arg)
+{
+ struct stm32_dev_s *priv = (struct stm32_dev_s *)dev;
+
+ /* Disable callbacks and register this callback and is argument */
+
+ finfo("Register %p(%p)\n", callback, arg);
+ DEBUGASSERT(priv != NULL);
+
+ priv->cbevents = 0;
+ priv->cbarg = arg;
+ priv->callback = callback;
+ return OK;
+}
+
+/****************************************************************************
+ * Name: stm32_dmasupported
+ *
+ * Description:
+ * Return true if the hardware can support DMA
+ *
+ * Input Parameters:
+ * dev - An instance of the SDIO device interface
+ *
+ * Returned Value:
+ * true if DMA is supported.
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_SDIO_DMA
+static bool stm32_dmasupported(FAR struct sdio_dev_s *dev)
+{
+ return true;
+}
+#endif
+
+/****************************************************************************
+ * Name: stm32_dmapreflight
+ *
+ * Description:
+ * Preflight an SDIO DMA operation. If the buffer is not well-formed for
+ * SDIO DMA transfer (alignment, size, etc.) returns an error.
+ *
+ * Input Parameters:
+ * dev - An instance of the SDIO device interface
+ * buffer - The memory to DMA to/from
+ * buflen - The size of the DMA transfer in bytes
+ *
+ * Returned Value:
+ * OK on success; a negated errno on failure
+ ****************************************************************************/
+
+#if defined(CONFIG_SDIO_DMA) && defined(CONFIG_SDIO_PREFLIGHT)
+static int stm32_dmapreflight(FAR struct sdio_dev_s *dev,
+ FAR const uint8_t *buffer, size_t buflen)
+{
+ struct stm32_dev_s *priv = (struct stm32_dev_s *)dev;
+
+ DEBUGASSERT(priv != NULL && buffer != NULL && buflen > 0);
+
+ /* Wide bus operation is required for DMA */
+
+ if (!priv->widebus)
+ {
+ return -EINVAL;
+ }
+
+ /* DMA must be possible to the buffer */
+
+ if (!stm32_dmacapable((uintptr_t)buffer, (buflen + 3) >> 2, SDIO_RXDMA32_CONFIG))
+ {
+ return -EFAULT;
+ }
+
+ return 0;
+}
+#endif
+
+/****************************************************************************
+ * Name: stm32_dmarecvsetup
+ *
+ * Description:
+ * Setup to perform a read DMA. If the processor supports a data cache,
+ * then this method will also make sure that the contents of the DMA memory
+ * and the data cache are coherent. For read transfers this may mean
+ * invalidating the data cache.
+ *
+ * Input Parameters:
+ * dev - An instance of the SDIO device interface
+ * buffer - The memory to DMA from
+ * buflen - The size of the DMA transfer in bytes
+ *
+ * Returned Value:
+ * OK on success; a negated errno on failure
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_SDIO_DMA
+static int stm32_dmarecvsetup(FAR struct sdio_dev_s *dev, FAR uint8_t *buffer,
+ size_t buflen)
+{
+ struct stm32_dev_s *priv = (struct stm32_dev_s *)dev;
+ uint32_t dblocksize;
+
+ DEBUGASSERT(priv != NULL && buffer != NULL && buflen > 0);
+#ifdef CONFIG_SDIO_PREFLIGHT
+ DEBUGASSERT(stm32_dmapreflight(dev, buffer, buflen) == 0);
+#endif
+
+#ifdef CONFIG_ARMV7M_DCACHE
+ /* buffer alignment is required for DMA transfers with dcache */
+
+ if (((uintptr_t)buffer & (ARMV7M_DCACHE_LINESIZE-1)) != 0 || (buflen & (ARMV7M_DCACHE_LINESIZE-1)) != 0)
+ {
+ return -EFAULT;
+ }
+#endif
+
+ /* Reset the DPSM configuration */
+
+ stm32_datadisable();
+
+ /* Initialize register sampling */
+
+ stm32_sampleinit();
+ stm32_sample(priv, SAMPLENDX_BEFORE_SETUP);
+
+ /* Save the destination buffer information for use by the interrupt handler */
+
+ priv->buffer = (uint32_t *)buffer;
+ priv->remaining = buflen;
+ priv->dmamode = true;
+
+ /* Then set up the SDIO data path */
+
+ dblocksize = stm32_log2(buflen) << SDIO_DCTRL_DBLOCKSIZE_SHIFT;
+ stm32_dataconfig(SDIO_DTIMER_DATATIMEOUT, buflen, dblocksize | SDIO_DCTRL_DTDIR);
+
+ /* Configure the RX DMA */
+
+ stm32_configxfrints(priv, SDIO_DMARECV_MASK);
+
+ stm32_dmasetup(priv->dma, STM32_SDMMC1_FIFO, (uint32_t)buffer,
+ (buflen + 3) >> 2, SDIO_RXDMA32_CONFIG);
+
+ /* Force RAM reread */
+
+ arch_invalidate_dcache((uintptr_t)buffer,(uintptr_t)buffer + buflen);
+
+ /* Start the DMA */
+
+ stm32_sample(priv, SAMPLENDX_BEFORE_ENABLE);
+ stm32_dmastart(priv->dma, stm32_dmacallback, priv, false);
+ stm32_sample(priv, SAMPLENDX_AFTER_SETUP);
+
+ return OK;
+}
+#endif
+
+/****************************************************************************
+ * Name: stm32_dmasendsetup
+ *
+ * Description:
+ * Setup to perform a write DMA. If the processor supports a data cache,
+ * then this method will also make sure that the contents of the DMA memory
+ * and the data cache are coherent. For write transfers, this may mean
+ * flushing the data cache.
+ *
+ * Input Parameters:
+ * dev - An instance of the SDIO device interface
+ * buffer - The memory to DMA into
+ * buflen - The size of the DMA transfer in bytes
+ *
+ * Returned Value:
+ * OK on success; a negated errno on failure
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_SDIO_DMA
+static int stm32_dmasendsetup(FAR struct sdio_dev_s *dev,
+ FAR const uint8_t *buffer, size_t buflen)
+{
+ struct stm32_dev_s *priv = (struct stm32_dev_s *)dev;
+ uint32_t dblocksize;
+
+ DEBUGASSERT(priv != NULL && buffer != NULL && buflen > 0);
+#ifdef CONFIG_SDIO_PREFLIGHT
+ DEBUGASSERT(stm32_dmapreflight(dev, buffer, buflen) == 0);
+#endif
+
+#ifdef CONFIG_ARMV7M_DCACHE
+ /* buffer alignment is required for DMA transfers with dcache */
+
+ if (((uintptr_t)buffer & (ARMV7M_DCACHE_LINESIZE-1)) != 0 || (buflen & (ARMV7M_DCACHE_LINESIZE-1)) != 0)
+ {
+ return -EFAULT;
+ }
+#endif
+
+ /* Reset the DPSM configuration */
+
+ stm32_datadisable();
+
+ /* Initialize register sampling */
+
+ stm32_sampleinit();
+ stm32_sample(priv, SAMPLENDX_BEFORE_SETUP);
+
+ /* Save the source buffer information for use by the interrupt handler */
+
+ priv->buffer = (uint32_t *)buffer;
+ priv->remaining = buflen;
+ priv->dmamode = true;
+
+ /* Then set up the SDIO data path */
+
+ dblocksize = stm32_log2(buflen) << SDIO_DCTRL_DBLOCKSIZE_SHIFT;
+ stm32_dataconfig(SDIO_DTIMER_DATATIMEOUT, buflen, dblocksize);
+
+ /* Configure the TX DMA */
+
+ stm32_dmasetup(priv->dma, STM32_SDMMC1_FIFO, (uint32_t)buffer,
+ (buflen + 3) >> 2, SDIO_TXDMA32_CONFIG);
+
+ stm32_sample(priv, SAMPLENDX_BEFORE_ENABLE);
+
+ /* Flush cache to physical memory */
+
+ arch_flush_dcache((uintptr_t)buffer, (uintptr_t)buffer + buflen);
+
+ /* Start the DMA */
+
+ stm32_dmastart(priv->dma, stm32_dmacallback, priv, false);
+ stm32_sample(priv, SAMPLENDX_AFTER_SETUP);
+
+ /* Enable TX interrupts */
+
+ stm32_configxfrints(priv, SDIO_DMASEND_MASK);
+
+ return OK;
+}
+#endif
+
+/****************************************************************************
+ * Initialization/uninitialization/reset
+ ****************************************************************************/
+/****************************************************************************
+ * Name: stm32_callback
+ *
+ * Description:
+ * Perform callback.
+ *
+ * Assumptions:
+ * This function does not execute in the context of an interrupt handler.
+ * It may be invoked on any user thread or scheduled on the work thread
+ * from an interrupt handler.
+ *
+ ****************************************************************************/
+
+static void stm32_callback(void *arg)
+{
+ struct stm32_dev_s *priv = (struct stm32_dev_s *)arg;
+
+ /* Is a callback registered? */
+
+ DEBUGASSERT(priv != NULL);
+ finfo("Callback %p(%p) cbevents: %02x cdstatus: %02x\n",
+ priv->callback, priv->cbarg, priv->cbevents, priv->cdstatus);
+
+ if (priv->callback)
+ {
+ /* Yes.. Check for enabled callback events */
+
+ if ((priv->cdstatus & SDIO_STATUS_PRESENT) != 0)
+ {
+ /* Media is present. Is the media inserted event enabled? */
+
+ if ((priv->cbevents & SDIOMEDIA_INSERTED) == 0)
+ {
+ /* No... return without performing the callback */
+
+ return;
+ }
+ }
+ else
+ {
+ /* Media is not present. Is the media eject event enabled? */
+
+ if ((priv->cbevents & SDIOMEDIA_EJECTED) == 0)
+ {
+ /* No... return without performing the callback */
+
+ return;
+ }
+ }
+
+ /* Perform the callback, disabling further callbacks. Of course, the
+ * the callback can (and probably should) re-enable callbacks.
+ */
+
+ priv->cbevents = 0;
+
+ /* Callbacks cannot be performed in the context of an interrupt handler.
+ * If we are in an interrupt handler, then queue the callback to be
+ * performed later on the work thread.
+ */
+
+ if (up_interrupt_context())
+ {
+ /* Yes.. queue it */
+
+ finfo("Queuing callback to %p(%p)\n", priv->callback, priv->cbarg);
+ (void)work_queue(HPWORK, &priv->cbwork, (worker_t)priv->callback, priv->cbarg, 0);
+ }
+ else
+ {
+ /* No.. then just call the callback here */
+
+ finfo("Callback to %p(%p)\n", priv->callback, priv->cbarg);
+ priv->callback(priv->cbarg);
+ }
+ }
+}
+
+/****************************************************************************
+ * Name: stm32_default
+ *
+ * Description:
+ * Restore SDIO registers to their default, reset values
+ *
+ ****************************************************************************/
+
+static void stm32_default(void)
+{
+ putreg32(SDIO_POWER_RESET, STM32_SDMMC1_POWER);
+ putreg32(SDIO_CLKCR_RESET, STM32_SDMMC1_CLKCR);
+ putreg32(SDIO_ARG_RESET, STM32_SDMMC1_ARG);
+ putreg32(SDIO_CMD_RESET, STM32_SDMMC1_CMD);
+ putreg32(SDIO_DTIMER_RESET, STM32_SDMMC1_DTIMER);
+ putreg32(SDIO_DLEN_RESET, STM32_SDMMC1_DLEN);
+ putreg32(SDIO_DCTRL_RESET, STM32_SDMMC1_DCTRL);
+ putreg32(SDIO_ICR_RESET, STM32_SDMMC1_ICR);
+ putreg32(SDIO_MASK_RESET, STM32_SDMMC1_MASK);
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: sdio_initialize
+ *
+ * Description:
+ * Initialize SDIO for operation.
+ *
+ * Input Parameters:
+ * slotno - Not used.
+ *
+ * Returned Values:
+ * A reference to an SDIO interface structure. NULL is returned on failures.
+ *
+ ****************************************************************************/
+
+FAR struct sdio_dev_s *sdio_initialize(int slotno)
+{
+ /* There is only one slot */
+
+ struct stm32_dev_s *priv = &g_sdiodev;
+
+ /* Initialize the SDIO slot structure */
+
+ sem_init(&priv->waitsem, 0, 0);
+ priv->waitwdog = wd_create();
+ DEBUGASSERT(priv->waitwdog);
+
+ /* Allocate a DMA channel */
+
+#ifdef CONFIG_SDIO_DMA
+ priv->dma = stm32_dmachannel(SDIO_DMACHAN);
+ DEBUGASSERT(priv->dma);
+#endif
+
+ /* Configure GPIOs for 4-bit, wide-bus operation (the chip is capable of
+ * 8-bit wide bus operation but D4-D7 are not configured).
+ *
+ * If bus is multiplexed then there is a custom bus configuration utility
+ * in the scope of the board support package.
+ */
+
+#ifndef CONFIG_SDIO_MUXBUS
+ stm32_configgpio(GPIO_SDMMC1_D0);
+#ifndef CONFIG_SDIO_WIDTH_D1_ONLY
+ stm32_configgpio(GPIO_SDMMC1_D1);
+ stm32_configgpio(GPIO_SDMMC1_D2);
+ stm32_configgpio(GPIO_SDMMC1_D3);
+#endif
+ stm32_configgpio(GPIO_SDMMC1_CK);
+ stm32_configgpio(GPIO_SDMMC1_CMD);
+#endif
+
+ /* Reset the card and assure that it is in the initial, unconfigured
+ * state.
+ */
+
+ stm32_reset(&priv->dev);
+ return &g_sdiodev.dev;
+}
+
+/****************************************************************************
+ * Name: sdio_mediachange
+ *
+ * Description:
+ * Called by board-specific logic -- posssible from an interrupt handler --
+ * in order to signal to the driver that a card has been inserted or
+ * removed from the slot
+ *
+ * Input Parameters:
+ * dev - An instance of the SDIO driver device state structure.
+ * cardinslot - true is a card has been detected in the slot; false if a
+ * card has been removed from the slot. Only transitions
+ * (inserted->removed or removed->inserted should be reported)
+ *
+ * Returned Values:
+ * None
+ *
+ ****************************************************************************/
+
+void sdio_mediachange(FAR struct sdio_dev_s *dev, bool cardinslot)
+{
+ struct stm32_dev_s *priv = (struct stm32_dev_s *)dev;
+ uint8_t cdstatus;
+ irqstate_t flags;
+
+ /* Update card status */
+
+ flags = enter_critical_section();
+ cdstatus = priv->cdstatus;
+ if (cardinslot)
+ {
+ priv->cdstatus |= SDIO_STATUS_PRESENT;
+ }
+ else
+ {
+ priv->cdstatus &= ~SDIO_STATUS_PRESENT;
+ }
+
+ leave_critical_section(flags);
+
+ finfo("cdstatus OLD: %02x NEW: %02x\n", cdstatus, priv->cdstatus);
+
+ /* Perform any requested callback if the status has changed */
+
+ if (cdstatus != priv->cdstatus)
+ {
+ stm32_callback(priv);
+ }
+}
+
+/****************************************************************************
+ * Name: sdio_wrprotect
+ *
+ * Description:
+ * Called by board-specific logic to report if the card in the slot is
+ * mechanically write protected.
+ *
+ * Input Parameters:
+ * dev - An instance of the SDIO driver device state structure.
+ * wrprotect - true is a card is writeprotected.
+ *
+ * Returned Values:
+ * None
+ *
+ ****************************************************************************/
+
+void sdio_wrprotect(FAR struct sdio_dev_s *dev, bool wrprotect)
+{
+ struct stm32_dev_s *priv = (struct stm32_dev_s *)dev;
+ irqstate_t flags;
+
+ /* Update card status */
+
+ flags = enter_critical_section();
+ if (wrprotect)
+ {
+ priv->cdstatus |= SDIO_STATUS_WRPROTECTED;
+ }
+ else
+ {
+ priv->cdstatus &= ~SDIO_STATUS_WRPROTECTED;
+ }
+ finfo("cdstatus: %02x\n", priv->cdstatus);
+ leave_critical_section(flags);
+}
+#endif /* CONFIG_STM32F7_SDMMC1 */
diff --git a/arch/arm/src/stm32f7/stm32_sdmmc.h b/arch/arm/src/stm32f7/stm32_sdmmc.h
new file mode 100644
index 0000000000..29e14683ce
--- /dev/null
+++ b/arch/arm/src/stm32f7/stm32_sdmmc.h
@@ -0,0 +1,129 @@
+/************************************************************************************
+ * arch/arm/src/stm32/stm32_sdio.h
+ *
+ * Copyright (C) 2009, 2011, 2015 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * 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.
+ *
+ ************************************************************************************/
+
+#ifndef __ARCH_ARM_SRC_STM32F7_STM32_SDMMC_H
+#define __ARCH_ARM_SRC_STM32F7_STM32_SDMMC_H
+
+/************************************************************************************
+ * Included Files
+ ************************************************************************************/
+
+#include "chip/stm32_sdmmc.h"
+
+#include
+#include
+#include
+
+#include "chip.h"
+
+/************************************************************************************
+ * Public Functions
+ ************************************************************************************/
+
+#ifndef __ASSEMBLY__
+
+#undef EXTERN
+#if defined(__cplusplus)
+#define EXTERN extern "C"
+extern "C"
+{
+#else
+#define EXTERN extern
+#endif
+
+/****************************************************************************
+ * Name: sdio_initialize
+ *
+ * Description:
+ * Initialize SDIO for operation.
+ *
+ * Input Parameters:
+ * slotno - Not used.
+ *
+ * Returned Values:
+ * A reference to an SDIO interface structure. NULL is returned on failures.
+ *
+ ****************************************************************************/
+
+struct sdio_dev_s; /* See include/nuttx/sdio.h */
+FAR struct sdio_dev_s *sdio_initialize(int slotno);
+
+/****************************************************************************
+ * Name: sdio_mediachange
+ *
+ * Description:
+ * Called by board-specific logic -- posssible from an interrupt handler --
+ * in order to signal to the driver that a card has been inserted or
+ * removed from the slot
+ *
+ * Input Parameters:
+ * dev - An instance of the SDIO driver device state structure.
+ * cardinslot - true is a card has been detected in the slot; false if a
+ * card has been removed from the slot. Only transitions
+ * (inserted->removed or removed->inserted should be reported)
+ *
+ * Returned Values:
+ * None
+ *
+ ****************************************************************************/
+
+void sdio_mediachange(FAR struct sdio_dev_s *dev, bool cardinslot);
+
+/****************************************************************************
+ * Name: sdio_wrprotect
+ *
+ * Description:
+ * Called by board-specific logic to report if the card in the slot is
+ * mechanically write protected.
+ *
+ * Input Parameters:
+ * dev - An instance of the SDIO driver device state structure.
+ * wrprotect - true is a card is writeprotected.
+ *
+ * Returned Values:
+ * None
+ *
+ ****************************************************************************/
+
+void sdio_wrprotect(FAR struct sdio_dev_s *dev, bool wrprotect);
+
+#undef EXTERN
+#if defined(__cplusplus)
+}
+#endif
+
+#endif /* __ASSEMBLY__ */
+#endif /* __ARCH_ARM_SRC_STM32F7_STM32_SDMMC_H */
+
diff --git a/configs/stm32f746-ws/include/board.h b/configs/stm32f746-ws/include/board.h
index 1f5e3f030c..df3474497a 100644
--- a/configs/stm32f746-ws/include/board.h
+++ b/configs/stm32f746-ws/include/board.h
@@ -213,6 +213,48 @@
#define GPIO_I2C1_SCL GPIO_I2C1_SCL_1
#define GPIO_I2C1_SDA GPIO_I2C1_SDA_1
+/* SDMMC */
+
+/* Stream selections are arbitrary for now but might become important in the future
+ * if we set aside more DMA channels/streams.
+ *
+ * SDIO DMA
+ * DMAMAP_SDMMC1_1 = Channel 4, Stream 3
+ * DMAMAP_SDMMC1_2 = Channel 4, Stream 6
+ */
+
+#define DMAMAP_SDMMC1 DMAMAP_SDMMC1_1
+
+/* SDIO dividers. Note that slower clocking is required when DMA is disabled
+ * in order to avoid RX overrun/TX underrun errors due to delayed responses
+ * to service FIFOs in interrupt driven mode. These values have not been
+ * tuned!!!
+ *
+ * SDIOCLK=48MHz, SDIO_CK=SDIOCLK/(118+2)=400 KHz
+ */
+
+#define SDMMC1_INIT_CLKDIV (118 << SDIO_CLKCR_CLKDIV_SHIFT)
+
+/* DMA ON: SDIOCLK=48MHz, SDIO_CK=SDIOCLK/(1+2)=16 MHz
+ * DMA OFF: SDIOCLK=48MHz, SDIO_CK=SDIOCLK/(2+2)=12 MHz
+ */
+
+#ifdef CONFIG_SDIO_DMA
+# define SDMMC1_MMCXFR_CLKDIV (1 << SDIO_CLKCR_CLKDIV_SHIFT)
+#else
+# define SDMMC1_MMCXFR_CLKDIV (2 << SDIO_CLKCR_CLKDIV_SHIFT)
+#endif
+
+/* DMA ON: SDIOCLK=48MHz, SDIO_CK=SDIOCLK/(1+2)=16 MHz
+ * DMA OFF: SDIOCLK=48MHz, SDIO_CK=SDIOCLK/(2+2)=12 MHz
+ */
+
+#ifdef CONFIG_SDIO_DMA
+# define SDMMC1_SDXFR_CLKDIV (1 << SDIO_CLKCR_CLKDIV_SHIFT)
+#else
+# define SDMMC1_SDXFR_CLKDIV (2 << SDIO_CLKCR_CLKDIV_SHIFT)
+#endif
+
/************************************************************************************
* Public Data
************************************************************************************/
diff --git a/configs/stm32f746-ws/nsh/defconfig b/configs/stm32f746-ws/nsh/defconfig
index df3654343f..c282d9ee49 100644
--- a/configs/stm32f746-ws/nsh/defconfig
+++ b/configs/stm32f746-ws/nsh/defconfig
@@ -170,7 +170,7 @@ CONFIG_STM32F7_HAVE_LTDC=y
# CONFIG_STM32F7_ADC is not set
# CONFIG_STM32F7_CAN is not set
# CONFIG_STM32F7_DAC is not set
-# CONFIG_STM32F7_DMA is not set
+CONFIG_STM32F7_DMA=y
CONFIG_STM32F7_I2C=y
# CONFIG_STM32F7_SAI is not set
CONFIG_STM32F7_SPI=y
@@ -185,7 +185,7 @@ CONFIG_STM32F7_ADC1=y
# CONFIG_STM32F7_CRC is not set
# CONFIG_STM32F7_CRYP is not set
# CONFIG_STM32F7_DMA1 is not set
-# CONFIG_STM32F7_DMA2 is not set
+CONFIG_STM32F7_DMA2=y
# CONFIG_STM32F7_DAC1 is not set
# CONFIG_STM32F7_DAC2 is not set
# CONFIG_STM32F7_DCMI is not set
@@ -203,7 +203,7 @@ CONFIG_STM32F7_I2C1=y
# CONFIG_STM32F7_SAI1 is not set
# CONFIG_STM32F7_RNG is not set
# CONFIG_STM32F7_SAI2 is not set
-# CONFIG_STM32F7_SDMMC1 is not set
+CONFIG_STM32F7_SDMMC1=y
# CONFIG_STM32F7_SPDIFRX is not set
CONFIG_STM32F7_SPI1=y
# CONFIG_STM32F7_SPI2 is not set
@@ -243,7 +243,7 @@ CONFIG_STM32F7_USART6=y
#
# CONFIG_ARCH_NOINTC is not set
# CONFIG_ARCH_VECNOTIRQ is not set
-# CONFIG_ARCH_DMA is not set
+CONFIG_ARCH_DMA=y
CONFIG_ARCH_HAVE_IRQPRIO=y
# CONFIG_ARCH_L2CACHE is not set
# CONFIG_ARCH_HAVE_COHERENT_DCACHE is not set
@@ -464,6 +464,7 @@ CONFIG_SPI_EXCHANGE=y
# CONFIG_SPI_CRCGENERATION is not set
# CONFIG_I2S is not set
CONFIG_ADC=y
+CONFIG_SDIO_DMA=y
#
# Timer Driver Support
@@ -485,7 +486,15 @@ CONFIG_WATCHDOG_DEVPATH="/dev/watchdog0"
# CONFIG_USERLED is not set
# CONFIG_RGBLED is not set
# CONFIG_PCA9635PW is not set
-# CONFIG_MMCSD is not set
+
+CONFIG_MMCSD=y
+CONFIG_MMCSD_NSLOTS=1
+CONFIG_MMCSD_MULTIBLOCK_DISABLE=y
+CONFIG_ARCH_HAVE_SDIO=y
+CONFIG_ARCH_HAVE_SDIOWAIT_WRCOMPLETE=y
+CONFIG_MMCSD_SDIO=y
+CONFIG_MMCSD_SDIOWAIT_WRCOMPLETE=y
+
# CONFIG_MODEM is not set
# CONFIG_MTD is not set
# CONFIG_EEPROM is not set
@@ -578,19 +587,27 @@ CONFIG_USART6_2STOP=0
# CONFIG_DISABLE_MOUNTPOINT is not set
# CONFIG_FS_AUTOMOUNTER is not set
# CONFIG_DISABLE_PSEUDOFS_OPERATIONS is not set
-# CONFIG_FS_READABLE is not set
-# CONFIG_FS_WRITABLE is not set
+CONFIG_FS_READABLE=y
+CONFIG_FS_WRITABLE=y
# CONFIG_FS_NAMED_SEMAPHORES is not set
CONFIG_FS_MQUEUE_MPATH="/var/mqueue"
# CONFIG_FS_RAMMAP is not set
-# CONFIG_FS_FAT is not set
+CONFIG_FS_FAT=y
+CONFIG_FAT_LCNAMES=y
+CONFIG_FAT_LFN=y
+CONFIG_FAT_MAXFNAME=32
# CONFIG_FS_NXFFS is not set
-# CONFIG_FS_ROMFS is not set
-# CONFIG_FS_TMPFS is not set
+CONFIG_FS_ROMFS=y
+CONFIG_FS_TMPFS=y
+CONFIG_FS_TMPFS_BLOCKSIZE=512
+CONFIG_FS_TMPFS_DIRECTORY_ALLOCGUARD=64
+CONFIG_FS_TMPFS_DIRECTORY_FREEGUARD=128
+CONFIG_FS_TMPFS_FILE_ALLOCGUARD=512
+CONFIG_FS_TMPFS_FILE_FREEGUARD=1024
# CONFIG_FS_SMARTFS is not set
# CONFIG_FS_BINFS is not set
-# CONFIG_FS_PROCFS is not set
-# CONFIG_FS_UNIONFS is not set
+CONFIG_FS_PROCFS=y
+CONFIG_FS_PROCFS_REGISTER=y
#
# System Logging
diff --git a/configs/stm32f746-ws/src/stm32_spi.c b/configs/stm32f746-ws/src/stm32_spi.c
index e973ca9b82..517ea3761b 100644
--- a/configs/stm32f746-ws/src/stm32_spi.c
+++ b/configs/stm32f746-ws/src/stm32_spi.c
@@ -101,7 +101,7 @@ void weak_function stm32_spidev_initialize(void)
#ifdef CONFIG_STM32F7_SPI1
void stm32_spi1select(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool selected)
{
- spidbg("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_spi1status(FAR struct spi_dev_s *dev, enum spi_dev_e devid)
@@ -113,7 +113,7 @@ uint8_t stm32_spi1status(FAR struct spi_dev_s *dev, enum spi_dev_e devid)
#ifdef CONFIG_STM32F7_SPI2
void stm32_spi2select(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool selected)
{
- spidbg("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, enum spi_dev_e devid)
@@ -125,7 +125,7 @@ uint8_t stm32_spi2status(FAR struct spi_dev_s *dev, enum spi_dev_e devid)
#ifdef CONFIG_STM32F7_SPI3
void stm32_spi3select(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool selected)
{
- spidbg("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, enum spi_dev_e devid)
@@ -137,7 +137,7 @@ uint8_t stm32_spi3status(FAR struct spi_dev_s *dev, enum spi_dev_e devid)
#ifdef CONFIG_STM32F7_SPI4
void stm32_spi4select(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool selected)
{
- spidbg("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_spi4status(FAR struct spi_dev_s *dev, enum spi_dev_e devid)
@@ -149,7 +149,7 @@ uint8_t stm32_spi4status(FAR struct spi_dev_s *dev, enum spi_dev_e devid)
#ifdef CONFIG_STM32F7_SPI5
void stm32_spi5select(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool selected)
{
- spidbg("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_spi5status(FAR struct spi_dev_s *dev, enum spi_dev_e devid)
@@ -161,7 +161,7 @@ uint8_t stm32_spi5status(FAR struct spi_dev_s *dev, enum spi_dev_e devid)
#ifdef CONFIG_STM32F7_SPI6
void stm32_spi6select(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool selected)
{
- spidbg("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_spi6status(FAR struct spi_dev_s *dev, enum spi_dev_e devid)
--
GitLab
From 98e7e5c402aa79ca07a6a8f8766e6aed3ff9eb04 Mon Sep 17 00:00:00 2001
From: Lok Tep
Date: Fri, 17 Jun 2016 17:47:23 +0200
Subject: [PATCH 002/734] usb copy
---
arch/arm/src/stm32f7/Make.defs | 8 +
arch/arm/src/stm32f7/chip/stm32_otg.h | 1022 +++
.../src/stm32f7/chip/stm32f74xx75xx_sdmmc.h | 2 +-
arch/arm/src/stm32f7/stm32_i2c.c | 2 +-
arch/arm/src/stm32f7/stm32_otg.h | 139 +
arch/arm/src/stm32f7/stm32_otgdev.c | 5666 +++++++++++++++++
arch/arm/src/stm32f7/stm32_otghost.c | 5306 +++++++++++++++
arch/arm/src/stm32f7/stm32_sdmmc.h | 2 +-
8 files changed, 12144 insertions(+), 3 deletions(-)
create mode 100644 arch/arm/src/stm32f7/chip/stm32_otg.h
create mode 100644 arch/arm/src/stm32f7/stm32_otg.h
create mode 100644 arch/arm/src/stm32f7/stm32_otgdev.c
create mode 100644 arch/arm/src/stm32f7/stm32_otghost.c
diff --git a/arch/arm/src/stm32f7/Make.defs b/arch/arm/src/stm32f7/Make.defs
index 123c70ffc2..1474c0b57d 100644
--- a/arch/arm/src/stm32f7/Make.defs
+++ b/arch/arm/src/stm32f7/Make.defs
@@ -151,6 +151,14 @@ ifeq ($(CONFIG_STM32F7_SDMMC1),y)
CHIP_CSRCS += stm32_sdmmc.c
endif
+ifeq ($(CONFIG_USBDEV),y)
+CHIP_CSRCS += stm32_otgdev.c
+endif
+
+ifeq ($(CONFIG_USBHOST),y)
+CHIP_CSRCS += stm32_otghost.c
+endif
+
ifeq ($(CONFIG_STM32F7_TIM),y)
CHIP_CSRCS += stm32_tim.c
endif
diff --git a/arch/arm/src/stm32f7/chip/stm32_otg.h b/arch/arm/src/stm32f7/chip/stm32_otg.h
new file mode 100644
index 0000000000..ee06497102
--- /dev/null
+++ b/arch/arm/src/stm32f7/chip/stm32_otg.h
@@ -0,0 +1,1022 @@
+/****************************************************************************************************
+ * arch/arm/src/stm32f7/chip/stm32f_otgfs.h
+ *
+ * Copyright (C) 2012, 2014-2015 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2016 Omni Hoverboards Inc. All rights reserved.
+ * Author: Gregory Nutt
+ * Paul Alexander Patience
+ *
+ * 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.
+ *
+ ****************************************************************************************************/
+
+#ifndef __ARCH_ARM_SRC_STM32F7_CHIP_STM32_OTG_H
+#define __ARCH_ARM_SRC_STM32F7_CHIP_STM32_OTG_H
+
+/****************************************************************************************************
+ * Included Files
+ ****************************************************************************************************/
+/****************************************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************************************/
+/* General definitions */
+
+#define OTG_EPTYPE_CTRL (0) /* Control */
+#define OTG_EPTYPE_ISOC (1) /* Isochronous */
+#define OTG_EPTYPE_BULK (2) /* Bulk */
+#define OTG_EPTYPE_INTR (3) /* Interrupt */
+
+#define OTG_PID_DATA0 (0)
+#define OTG_PID_DATA2 (1)
+#define OTG_PID_DATA1 (2)
+#define OTG_PID_MDATA (3) /* Non-control */
+#define OTG_PID_SETUP (3) /* Control */
+
+/* Register Offsets *********************************************************************************/
+/* Core global control and status registers */
+
+#define STM32_OTG_GOTGCTL_OFFSET 0x0000 /* Control and status register */
+#define STM32_OTG_GOTGINT_OFFSET 0x0004 /* Interrupt register */
+#define STM32_OTG_GAHBCFG_OFFSET 0x0008 /* AHB configuration register */
+#define STM32_OTG_GUSBCFG_OFFSET 0x000c /* USB configuration register */
+#define STM32_OTG_GRSTCTL_OFFSET 0x0010 /* Reset register */
+#define STM32_OTG_GINTSTS_OFFSET 0x0014 /* Core interrupt register */
+#define STM32_OTG_GINTMSK_OFFSET 0x0018 /* Interrupt mask register */
+#define STM32_OTG_GRXSTSR_OFFSET 0x001c /* Receive status debug read/OTG status read register */
+#define STM32_OTG_GRXSTSP_OFFSET 0x0020 /* Receive status debug read/OTG status pop register */
+#define STM32_OTG_GRXFSIZ_OFFSET 0x0024 /* Receive FIFO size register */
+#define STM32_OTG_HNPTXFSIZ_OFFSET 0x0028 /* Host non-periodic transmit FIFO size register */
+#define STM32_OTG_DIEPTXF0_OFFSET 0x0028 /* Endpoint 0 Transmit FIFO size */
+#define STM32_OTG_HNPTXSTS_OFFSET 0x002c /* Non-periodic transmit FIFO/queue status register */
+#define STM32_OTG_GCCFG_OFFSET 0x0038 /* General core configuration register */
+#define STM32_OTG_CID_OFFSET 0x003c /* Core ID register */
+#define STM32_OTG_HPTXFSIZ_OFFSET 0x0100 /* Host periodic transmit FIFO size register */
+
+#define STM32_OTG_DIEPTXF_OFFSET(n) (104+(((n)-1) << 2))
+#define STM32_OTG_DIEPTXF1_OFFSET 0x0104 /* Device IN endpoint transmit FIFO1 size register */
+#define STM32_OTG_DIEPTXF2_OFFSET 0x0108 /* Device IN endpoint transmit FIFO2 size register */
+#define STM32_OTG_DIEPTXF3_OFFSET 0x010c /* Device IN endpoint transmit FIFO3 size register */
+
+/* Host-mode control and status registers */
+
+#define STM32_OTG_HCFG_OFFSET 0x0400 /* Host configuration register */
+#define STM32_OTG_HFIR_OFFSET 0x0404 /* Host frame interval register */
+#define STM32_OTG_HFNUM_OFFSET 0x0408 /* Host frame number/frame time remaining register */
+#define STM32_OTG_HPTXSTS_OFFSET 0x0410 /* Host periodic transmit FIFO/queue status register */
+#define STM32_OTG_HAINT_OFFSET 0x0414 /* Host all channels interrupt register */
+#define STM32_OTG_HAINTMSK_OFFSET 0x0418 /* Host all channels interrupt mask register */
+#define STM32_OTG_HPRT_OFFSET 0x0440 /* Host port control and status register */
+
+#define STM32_OTG_CHAN_OFFSET(n) (0x500 + ((n) << 5)
+#define STM32_OTG_HCCHAR_CHOFFSET 0x0000 /* Host channel characteristics register */
+#define STM32_OTG_HCINT_CHOFFSET 0x0008 /* Host channel interrupt register */
+#define STM32_OTG_HCINTMSK_CHOFFSET 0x000c /* Host channel interrupt mask register */
+#define STM32_OTG_HCTSIZ_CHOFFSET 0x0010 /* Host channel interrupt register */
+
+#define STM32_OTG_HCCHAR_OFFSET(n) (0x500 + ((n) << 5))
+#define STM32_OTG_HCCHAR0_OFFSET 0x0500 /* Host channel-0 characteristics register */
+#define STM32_OTG_HCCHAR1_OFFSET 0x0520 /* Host channel-1 characteristics register */
+#define STM32_OTG_HCCHAR2_OFFSET 0x0540 /* Host channel-2 characteristics register */
+#define STM32_OTG_HCCHAR3_OFFSET 0x0560 /* Host channel-3 characteristics register */
+#define STM32_OTG_HCCHAR4_OFFSET 0x0580 /* Host channel-4 characteristics register */
+#define STM32_OTG_HCCHAR5_OFFSET 0x05a0 /* Host channel-5 characteristics register */
+#define STM32_OTG_HCCHAR6_OFFSET 0x05c0 /* Host channel-6 characteristics register */
+#define STM32_OTG_HCCHAR7_OFFSET 0x05e0 /* Host channel-7 characteristics register */
+
+#define STM32_OTG_HCINT_OFFSET(n) (0x508 + ((n) << 5))
+#define STM32_OTG_HCINT0_OFFSET 0x0508 /* Host channel-0 interrupt register */
+#define STM32_OTG_HCINT1_OFFSET 0x0528 /* Host channel-1 interrupt register */
+#define STM32_OTG_HCINT2_OFFSET 0x0548 /* Host channel-2 interrupt register */
+#define STM32_OTG_HCINT3_OFFSET 0x0568 /* Host channel-3 interrupt register */
+#define STM32_OTG_HCINT4_OFFSET 0x0588 /* Host channel-4 interrupt register */
+#define STM32_OTG_HCINT5_OFFSET 0x05a8 /* Host channel-5 interrupt register */
+#define STM32_OTG_HCINT6_OFFSET 0x05c8 /* Host channel-6 interrupt register */
+#define STM32_OTG_HCINT7_OFFSET 0x05e8 /* Host channel-7 interrupt register */
+
+#define STM32_OTG_HCINTMSK_OFFSET(n) (0x50c + ((n) << 5))
+#define STM32_OTG_HCINTMSK0_OFFSET 0x050c /* Host channel-0 interrupt mask register */
+#define STM32_OTG_HCINTMSK1_OFFSET 0x052c /* Host channel-1 interrupt mask register */
+#define STM32_OTG_HCINTMSK2_OFFSET 0x054c /* Host channel-2 interrupt mask register */
+#define STM32_OTG_HCINTMSK3_OFFSET 0x056c /* Host channel-3 interrupt mask register */
+#define STM32_OTG_HCINTMSK4_OFFSET 0x058c /* Host channel-4 interrupt mask register */
+#define STM32_OTG_HCINTMSK5_OFFSET 0x05ac /* Host channel-5 interrupt mask register */
+#define STM32_OTG_HCINTMSK6_OFFSET 0x05cc /* Host channel-6 interrupt mask register */
+#define STM32_OTG_HCINTMSK7_OFFSET 0x05ec /* Host channel-7 interrupt mask register */
+
+#define STM32_OTG_HCTSIZ_OFFSET(n) (0x510 + ((n) << 5))
+#define STM32_OTG_HCTSIZ0_OFFSET 0x0510 /* Host channel-0 interrupt register */
+#define STM32_OTG_HCTSIZ1_OFFSET 0x0530 /* Host channel-1 interrupt register */
+#define STM32_OTG_HCTSIZ2_OFFSET 0x0550 /* Host channel-2 interrupt register */
+#define STM32_OTG_HCTSIZ3_OFFSET 0x0570 /* Host channel-3 interrupt register */
+#define STM32_OTG_HCTSIZ4_OFFSET 0x0590 /* Host channel-4 interrupt register */
+#define STM32_OTG_HCTSIZ5_OFFSET 0x05b0 /* Host channel-5 interrupt register */
+#define STM32_OTG_HCTSIZ6_OFFSET 0x05d0 /* Host channel-6 interrupt register */
+#define STM32_OTG_HCTSIZ7_OFFSET 0x05f0 /* Host channel-7 interrupt register */
+
+/* Device-mode control and status registers */
+
+#define STM32_OTG_DCFG_OFFSET 0x0800 /* Device configuration register */
+#define STM32_OTG_DCTL_OFFSET 0x0804 /* Device control register */
+#define STM32_OTG_DSTS_OFFSET 0x0808 /* Device status register */
+#define STM32_OTG_DIEPMSK_OFFSET 0x0810 /* Device IN endpoint common interrupt mask register */
+#define STM32_OTG_DOEPMSK_OFFSET 0x0814 /* Device OUT endpoint common interrupt mask register */
+#define STM32_OTG_DAINT_OFFSET 0x0818 /* Device all endpoints interrupt register */
+#define STM32_OTG_DAINTMSK_OFFSET 0x081c /* All endpoints interrupt mask register */
+#define STM32_OTG_DVBUSDIS_OFFSET 0x0828 /* Device VBUS discharge time register */
+#define STM32_OTG_DVBUSPULSE_OFFSET 0x082c /* Device VBUS pulsing time register */
+#define STM32_OTG_DIEPEMPMSK_OFFSET 0x0834 /* Device IN endpoint FIFO empty interrupt mask register */
+
+#define STM32_OTG_DIEP_OFFSET(n) (0x0900 + ((n) << 5))
+#define STM32_OTG_DIEPCTL_EPOFFSET 0x0000 /* Device endpoint control register */
+#define STM32_OTG_DIEPINT_EPOFFSET 0x0008 /* Device endpoint interrupt register */
+#define STM32_OTG_DIEPTSIZ_EPOFFSET 0x0010 /* Device IN endpoint transfer size register */
+#define STM32_OTG_DTXFSTS_EPOFFSET 0x0018 /* Device IN endpoint transmit FIFO status register */
+
+#define STM32_OTG_DIEPCTL_OFFSET(n) (0x0900 + ((n) << 5))
+#define STM32_OTG_DIEPCTL0_OFFSET 0x0900 /* Device control IN endpoint 0 control register */
+#define STM32_OTG_DIEPCTL1_OFFSET 0x0920 /* Device control IN endpoint 2 control register */
+#define STM32_OTG_DIEPCTL2_OFFSET 0x0940 /* Device control IN endpoint 3 control register */
+#define STM32_OTG_DIEPCTL3_OFFSET 0x0960 /* Device control IN endpoint 4 control register */
+
+#define STM32_OTG_DIEPINT_OFFSET(n) (0x0908 + ((n) << 5))
+#define STM32_OTG_DIEPINT0_OFFSET 0x0908 /* Device endpoint-0 interrupt register */
+#define STM32_OTG_DIEPINT1_OFFSET 0x0928 /* Device endpoint-1 interrupt register */
+#define STM32_OTG_DIEPINT2_OFFSET 0x0948 /* Device endpoint-2 interrupt register */
+#define STM32_OTG_DIEPINT3_OFFSET 0x0968 /* Device endpoint-3 interrupt register */
+
+#define STM32_OTG_DIEPTSIZ_OFFSET(n) (0x910 + ((n) << 5))
+#define STM32_OTG_DIEPTSIZ0_OFFSET 0x0910 /* Device IN endpoint 0 transfer size register */
+#define STM32_OTG_DIEPTSIZ1_OFFSET 0x0930 /* Device IN endpoint 1 transfer size register */
+#define STM32_OTG_DIEPTSIZ2_OFFSET 0x0950 /* Device IN endpoint 2 transfer size register */
+#define STM32_OTG_DIEPTSIZ3_OFFSET 0x0970 /* Device IN endpoint 3 transfer size register */
+
+#define STM32_OTG_DTXFSTS_OFFSET(n) (0x0918 + ((n) << 5))
+#define STM32_OTG_DTXFSTS0_OFFSET 0x0918 /* Device OUT endpoint-0 TxFIFO status register */
+#define STM32_OTG_DTXFSTS1_OFFSET 0x0938 /* Device OUT endpoint-1 TxFIFO status register */
+#define STM32_OTG_DTXFSTS2_OFFSET 0x0958 /* Device OUT endpoint-2 TxFIFO status register */
+#define STM32_OTG_DTXFSTS3_OFFSET 0x0978 /* Device OUT endpoint-3 TxFIFO status register */
+
+#define STM32_OTG_DOEP_OFFSET(n) (0x0b00 + ((n) << 5))
+#define STM32_OTG_DOEPCTL_EPOFFSET 0x0000 /* Device control OUT endpoint 0 control register */
+#define STM32_OTG_DOEPINT_EPOFFSET 0x0008 /* Device endpoint-x interrupt register */
+
+#define STM32_OTG_DOEPCTL_OFFSET(n) (0x0b00 + ((n) << 5))
+#define STM32_OTG_DOEPCTL0_OFFSET 0x00b00 /* Device OUT endpoint 0 control register */
+#define STM32_OTG_DOEPCTL1_OFFSET 0x00b20 /* Device OUT endpoint 1 control register */
+#define STM32_OTG_DOEPCTL2_OFFSET 0x00b40 /* Device OUT endpoint 2 control register */
+#define STM32_OTG_DOEPCTL3_OFFSET 0x00b60 /* Device OUT endpoint 3 control register */
+
+#define STM32_OTG_DOEPINT_OFFSET(n) (0x0b08 + ((n) << 5))
+#define STM32_OTG_DOEPINT0_OFFSET 0x00b08 /* Device endpoint-0 interrupt register */
+#define STM32_OTG_DOEPINT1_OFFSET 0x00b28 /* Device endpoint-1 interrupt register */
+#define STM32_OTG_DOEPINT2_OFFSET 0x00b48 /* Device endpoint-2 interrupt register */
+#define STM32_OTG_DOEPINT3_OFFSET 0x00b68 /* Device endpoint-3 interrupt register */
+
+#define STM32_OTG_DOEPTSIZ_OFFSET(n) (0x0b10 + ((n) << 5))
+#define STM32_OTG_DOEPTSIZ0_OFFSET 0x00b10 /* Device OUT endpoint-0 transfer size register */
+#define STM32_OTG_DOEPTSIZ1_OFFSET 0x00b30 /* Device OUT endpoint-1 transfer size register */
+#define STM32_OTG_DOEPTSIZ2_OFFSET 0x00b50 /* Device OUT endpoint-2 transfer size register */
+#define STM32_OTG_DOEPTSIZ3_OFFSET 0x00b70 /* Device OUT endpoint-3 transfer size register */
+
+/* Power and clock gating registers */
+
+#define STM32_OTG_PCGCCTL_OFFSET 0x0e00 /* Power and clock gating control register */
+
+/* Data FIFO (DFIFO) access registers */
+
+#define STM32_OTG_DFIFO_DEP_OFFSET(n) (0x1000 + ((n) << 12))
+#define STM32_OTG_DFIFO_HCH_OFFSET(n) (0x1000 + ((n) << 12))
+
+#define STM32_OTG_DFIFO_DEP0_OFFSET 0x1000 /* 0x1000-0x1ffc Device IN/OUT Endpoint 0 DFIFO Write/Read Access */
+#define STM32_OTG_DFIFO_HCH0_OFFSET 0x1000 /* 0x1000-0x1ffc Host OUT/IN Channel 0 DFIFO Read/Write Access */
+
+#define STM32_OTG_DFIFO_DEP1_OFFSET 0x2000 /* 0x2000-0x2ffc Device IN/OUT Endpoint 1 DFIFO Write/Read Access */
+#define STM32_OTG_DFIFO_HCH1_OFFSET 0x2000 /* 0x2000-0x2ffc Host OUT/IN Channel 1 DFIFO Read/Write Access */
+
+#define STM32_OTG_DFIFO_DEP2_OFFSET 0x3000 /* 0x3000-0x3ffc Device IN/OUT Endpoint 2 DFIFO Write/Read Access */
+#define STM32_OTG_DFIFO_HCH2_OFFSET 0x3000 /* 0x3000-0x3ffc Host OUT/IN Channel 2 DFIFO Read/Write Access */
+
+#define STM32_OTG_DFIFO_DEP3_OFFSET 0x4000 /* 0x4000-0x4ffc Device IN/OUT Endpoint 3 DFIFO Write/Read Access */
+#define STM32_OTG_DFIFO_HCH3_OFFSET 0x4000 /* 0x4000-0x4ffc Host OUT/IN Channel 3 DFIFO Read/Write Access */
+
+/* Register Addresses *******************************************************************************/
+
+#define STM32_OTG_GOTGCTL (STM32_OTG_BASE+STM32_OTG_GOTGCTL_OFFSET)
+#define STM32_OTG_GOTGINT (STM32_OTG_BASE+STM32_OTG_GOTGINT_OFFSET)
+#define STM32_OTG_GAHBCFG (STM32_OTG_BASE+STM32_OTG_GAHBCFG_OFFSET)
+#define STM32_OTG_GUSBCFG (STM32_OTG_BASE+STM32_OTG_GUSBCFG_OFFSET)
+#define STM32_OTG_GRSTCTL (STM32_OTG_BASE+STM32_OTG_GRSTCTL_OFFSET)
+#define STM32_OTG_GINTSTS (STM32_OTG_BASE+STM32_OTG_GINTSTS_OFFSET)
+#define STM32_OTG_GINTMSK (STM32_OTG_BASE+STM32_OTG_GINTMSK_OFFSET)
+#define STM32_OTG_GRXSTSR (STM32_OTG_BASE+STM32_OTG_GRXSTSR_OFFSET)
+#define STM32_OTG_GRXSTSP (STM32_OTG_BASE+STM32_OTG_GRXSTSP_OFFSET)
+#define STM32_OTG_GRXFSIZ (STM32_OTG_BASE+STM32_OTG_GRXFSIZ_OFFSET)
+#define STM32_OTG_HNPTXFSIZ (STM32_OTG_BASE+STM32_OTG_HNPTXFSIZ_OFFSET)
+#define STM32_OTG_DIEPTXF0 (STM32_OTG_BASE+STM32_OTG_DIEPTXF0_OFFSET)
+#define STM32_OTG_HNPTXSTS (STM32_OTG_BASE+STM32_OTG_HNPTXSTS_OFFSET)
+#define STM32_OTG_GCCFG (STM32_OTG_BASE+STM32_OTG_GCCFG_OFFSET)
+#define STM32_OTG_CID (STM32_OTG_BASE+STM32_OTG_CID_OFFSET)
+#define STM32_OTG_HPTXFSIZ (STM32_OTG_BASE+STM32_OTG_HPTXFSIZ_OFFSET)
+
+#define STM32_OTG_DIEPTXF(n) (STM32_OTG_BASE+STM32_OTG_DIEPTXF_OFFSET(n))
+#define STM32_OTG_DIEPTXF1 (STM32_OTG_BASE+STM32_OTG_DIEPTXF1_OFFSET)
+#define STM32_OTG_DIEPTXF2 (STM32_OTG_BASE+STM32_OTG_DIEPTXF2_OFFSET)
+#define STM32_OTG_DIEPTXF3 (STM32_OTG_BASE+STM32_OTG_DIEPTXF3_OFFSET)
+
+/* Host-mode control and status registers */
+
+#define STM32_OTG_HCFG (STM32_OTG_BASE+STM32_OTG_HCFG_OFFSET)
+#define STM32_OTG_HFIR (STM32_OTG_BASE+STM32_OTG_HFIR_OFFSET)
+#define STM32_OTG_HFNUM (STM32_OTG_BASE+STM32_OTG_HFNUM_OFFSET)
+#define STM32_OTG_HPTXSTS (STM32_OTG_BASE+STM32_OTG_HPTXSTS_OFFSET)
+#define STM32_OTG_HAINT (STM32_OTG_BASE+STM32_OTG_HAINT_OFFSET)
+#define STM32_OTG_HAINTMSK (STM32_OTG_BASE+STM32_OTG_HAINTMSK_OFFSET)
+#define STM32_OTG_HPRT (STM32_OTG_BASE+STM32_OTG_HPRT_OFFSET)
+
+#define STM32_OTG_CHAN(n) (STM32_OTG_BASE+STM32_OTG_CHAN_OFFSET(n))
+
+#define STM32_OTG_HCCHAR(n) (STM32_OTG_BASE+STM32_OTG_HCCHAR_OFFSET(n))
+#define STM32_OTG_HCCHAR0 (STM32_OTG_BASE+STM32_OTG_HCCHAR0_OFFSET)
+#define STM32_OTG_HCCHAR1 (STM32_OTG_BASE+STM32_OTG_HCCHAR1_OFFSET)
+#define STM32_OTG_HCCHAR2 (STM32_OTG_BASE+STM32_OTG_HCCHAR2_OFFSET)
+#define STM32_OTG_HCCHAR3 (STM32_OTG_BASE+STM32_OTG_HCCHAR3_OFFSET)
+#define STM32_OTG_HCCHAR4 (STM32_OTG_BASE+STM32_OTG_HCCHAR4_OFFSET)
+#define STM32_OTG_HCCHAR5 (STM32_OTG_BASE+STM32_OTG_HCCHAR5_OFFSET)
+#define STM32_OTG_HCCHAR6 (STM32_OTG_BASE+STM32_OTG_HCCHAR6_OFFSET)
+#define STM32_OTG_HCCHAR7 (STM32_OTG_BASE+STM32_OTG_HCCHAR7_OFFSET)
+
+#define STM32_OTG_HCINT(n) (STM32_OTG_BASE+STM32_OTG_HCINT_OFFSET(n))
+#define STM32_OTG_HCINT0 (STM32_OTG_BASE+STM32_OTG_HCINT0_OFFSET)
+#define STM32_OTG_HCINT1 (STM32_OTG_BASE+STM32_OTG_HCINT1_OFFSET)
+#define STM32_OTG_HCINT2 (STM32_OTG_BASE+STM32_OTG_HCINT2_OFFSET)
+#define STM32_OTG_HCINT3 (STM32_OTG_BASE+STM32_OTG_HCINT3_OFFSET)
+#define STM32_OTG_HCINT4 (STM32_OTG_BASE+STM32_OTG_HCINT4_OFFSET)
+#define STM32_OTG_HCINT5 (STM32_OTG_BASE+STM32_OTG_HCINT5_OFFSET)
+#define STM32_OTG_HCINT6 (STM32_OTG_BASE+STM32_OTG_HCINT6_OFFSET)
+#define STM32_OTG_HCINT7 (STM32_OTG_BASE+STM32_OTG_HCINT7_OFFSET)
+
+#define STM32_OTG_HCINTMSK(n) (STM32_OTG_BASE+STM32_OTG_HCINTMSK_OFFSET(n))
+#define STM32_OTG_HCINTMSK0 (STM32_OTG_BASE+STM32_OTG_HCINTMSK0_OFFSET)
+#define STM32_OTG_HCINTMSK1 (STM32_OTG_BASE+STM32_OTG_HCINTMSK1_OFFSET)
+#define STM32_OTG_HCINTMSK2 (STM32_OTG_BASE+STM32_OTG_HCINTMSK2_OFFSET)
+#define STM32_OTG_HCINTMSK3 (STM32_OTG_BASE+STM32_OTG_HCINTMSK3_OFFSET)
+#define STM32_OTG_HCINTMSK4 (STM32_OTG_BASE+STM32_OTG_HCINTMSK4_OFFSET)
+#define STM32_OTG_HCINTMSK5 (STM32_OTG_BASE+STM32_OTG_HCINTMSK5_OFFSET)
+#define STM32_OTG_HCINTMSK6 (STM32_OTG_BASE+STM32_OTG_HCINTMSK6_OFFSET)
+#define STM32_OTG_HCINTMSK7 (STM32_OTG_BASE+STM32_OTG_HCINTMSK7_OFFSET)_
+
+#define STM32_OTG_HCTSIZ(n) (STM32_OTG_BASE+STM32_OTG_HCTSIZ_OFFSET(n))
+#define STM32_OTG_HCTSIZ0 (STM32_OTG_BASE+STM32_OTG_HCTSIZ0_OFFSET)
+#define STM32_OTG_HCTSIZ1 (STM32_OTG_BASE+STM32_OTG_HCTSIZ1_OFFSET)
+#define STM32_OTG_HCTSIZ2 (STM32_OTG_BASE+STM32_OTG_HCTSIZ2_OFFSET)
+#define STM32_OTG_HCTSIZ3 (STM32_OTG_BASE+STM32_OTG_HCTSIZ3_OFFSET)
+#define STM32_OTG_HCTSIZ4 (STM32_OTG_BASE+STM32_OTG_HCTSIZ4_OFFSET)
+#define STM32_OTG_HCTSIZ5 (STM32_OTG_BASE+STM32_OTG_HCTSIZ5_OFFSET)
+#define STM32_OTG_HCTSIZ6 (STM32_OTG_BASE+STM32_OTG_HCTSIZ6_OFFSET)
+#define STM32_OTG_HCTSIZ7 (STM32_OTG_BASE+STM32_OTG_HCTSIZ7_OFFSET)
+
+/* Device-mode control and status registers */
+
+#define STM32_OTG_DCFG (STM32_OTG_BASE+STM32_OTG_DCFG_OFFSET)
+#define STM32_OTG_DCTL (STM32_OTG_BASE+STM32_OTG_DCTL_OFFSET)
+#define STM32_OTG_DSTS (STM32_OTG_BASE+STM32_OTG_DSTS_OFFSET)
+#define STM32_OTG_DIEPMSK (STM32_OTG_BASE+STM32_OTG_DIEPMSK_OFFSET)
+#define STM32_OTG_DOEPMSK (STM32_OTG_BASE+STM32_OTG_DOEPMSK_OFFSET)
+#define STM32_OTG_DAINT (STM32_OTG_BASE+STM32_OTG_DAINT_OFFSET)
+#define STM32_OTG_DAINTMSK (STM32_OTG_BASE+STM32_OTG_DAINTMSK_OFFSET)
+#define STM32_OTG_DVBUSDIS (STM32_OTG_BASE+STM32_OTG_DVBUSDIS_OFFSET)
+#define STM32_OTG_DVBUSPULSE (STM32_OTG_BASE+STM32_OTG_DVBUSPULSE_OFFSET)
+#define STM32_OTG_DIEPEMPMSK (STM32_OTG_BASE+STM32_OTG_DIEPEMPMSK_OFFSET)
+
+#define STM32_OTG_DIEP(n) (STM32_OTG_BASE+STM32_OTG_DIEP_OFFSET(n))
+
+#define STM32_OTG_DIEPCTL(n) (STM32_OTG_BASE+STM32_OTG_DIEPCTL_OFFSET(n))
+#define STM32_OTG_DIEPCTL0 (STM32_OTG_BASE+STM32_OTG_DIEPCTL0_OFFSET)
+#define STM32_OTG_DIEPCTL1 (STM32_OTG_BASE+STM32_OTG_DIEPCTL1_OFFSET)
+#define STM32_OTG_DIEPCTL2 (STM32_OTG_BASE+STM32_OTG_DIEPCTL2_OFFSET)
+#define STM32_OTG_DIEPCTL3 (STM32_OTG_BASE+STM32_OTG_DIEPCTL3_OFFSET)
+
+#define STM32_OTG_DIEPINT(n) (STM32_OTG_BASE+STM32_OTG_DIEPINT_OFFSET(n))
+#define STM32_OTG_DIEPINT0 (STM32_OTG_BASE+STM32_OTG_DIEPINT0_OFFSET)
+#define STM32_OTG_DIEPINT1 (STM32_OTG_BASE+STM32_OTG_DIEPINT1_OFFSET)
+#define STM32_OTG_DIEPINT2 (STM32_OTG_BASE+STM32_OTG_DIEPINT2_OFFSET)
+#define STM32_OTG_DIEPINT3 (STM32_OTG_BASE+STM32_OTG_DIEPINT3_OFFSET)
+
+#define STM32_OTG_DIEPTSIZ(n) (STM32_OTG_BASE+STM32_OTG_DIEPTSIZ_OFFSET(n))
+#define STM32_OTG_DIEPTSIZ0 (STM32_OTG_BASE+STM32_OTG_DIEPTSIZ0_OFFSET)
+#define STM32_OTG_DIEPTSIZ1 (STM32_OTG_BASE+STM32_OTG_DIEPTSIZ1_OFFSET)
+#define STM32_OTG_DIEPTSIZ2 (STM32_OTG_BASE+STM32_OTG_DIEPTSIZ2_OFFSET)
+#define STM32_OTG_DIEPTSIZ3 (STM32_OTG_BASE+STM32_OTG_DIEPTSIZ3_OFFSET)
+
+#define STM32_OTG_DTXFSTS(n) (STM32_OTG_BASE+STM32_OTG_DTXFSTS_OFFSET(n))
+#define STM32_OTG_DTXFSTS0 (STM32_OTG_BASE+STM32_OTG_DTXFSTS0_OFFSET)
+#define STM32_OTG_DTXFSTS1 (STM32_OTG_BASE+STM32_OTG_DTXFSTS1_OFFSET)
+#define STM32_OTG_DTXFSTS2 (STM32_OTG_BASE+STM32_OTG_DTXFSTS2_OFFSET)
+#define STM32_OTG_DTXFSTS3 (STM32_OTG_BASE+STM32_OTG_DTXFSTS3_OFFSET)
+
+#define STM32_OTG_DOEP(n) (STM32_OTG_BASE+STM32_OTG_DOEP_OFFSET(n))
+
+#define STM32_OTG_DOEPCTL(n) (STM32_OTG_BASE+STM32_OTG_DOEPCTL_OFFSET(n))
+#define STM32_OTG_DOEPCTL0 (STM32_OTG_BASE+STM32_OTG_DOEPCTL0_OFFSET)
+#define STM32_OTG_DOEPCTL1 (STM32_OTG_BASE+STM32_OTG_DOEPCTL1_OFFSET)
+#define STM32_OTG_DOEPCTL2 (STM32_OTG_BASE+STM32_OTG_DOEPCTL2_OFFSET)
+#define STM32_OTG_DOEPCTL3 (STM32_OTG_BASE+STM32_OTG_DOEPCTL3_OFFSET)
+
+#define STM32_OTG_DOEPINT(n) (STM32_OTG_BASE+STM32_OTG_DOEPINT_OFFSET(n))
+#define STM32_OTG_DOEPINT0 (STM32_OTG_BASE+STM32_OTG_DOEPINT0_OFFSET)
+#define STM32_OTG_DOEPINT1 (STM32_OTG_BASE+STM32_OTG_DOEPINT1_OFFSET)
+#define STM32_OTG_DOEPINT2 (STM32_OTG_BASE+STM32_OTG_DOEPINT2_OFFSET)
+#define STM32_OTG_DOEPINT3 (STM32_OTG_BASE+STM32_OTG_DOEPINT3_OFFSET)
+
+#define STM32_OTG_DOEPTSIZ(n) (STM32_OTG_BASE+STM32_OTG_DOEPTSIZ_OFFSET(n))
+#define STM32_OTG_DOEPTSIZ0 (STM32_OTG_BASE+STM32_OTG_DOEPTSIZ0_OFFSET)
+#define STM32_OTG_DOEPTSIZ1 (STM32_OTG_BASE+STM32_OTG_DOEPTSIZ1_OFFSET)
+#define STM32_OTG_DOEPTSIZ2 (STM32_OTG_BASE+STM32_OTG_DOEPTSIZ2_OFFSET)
+#define STM32_OTG_DOEPTSIZ3 (STM32_OTG_BASE+STM32_OTG_DOEPTSIZ3_OFFSET)
+
+/* Power and clock gating registers */
+
+#define STM32_OTG_PCGCCTL (STM32_OTG_BASE+STM32_OTG_PCGCCTL_OFFSET)
+
+/* Data FIFO (DFIFO) access registers */
+
+#define STM32_OTG_DFIFO_DEP(n) (STM32_OTG_BASE+STM32_OTG_DFIFO_DEP_OFFSET(n))
+#define STM32_OTG_DFIFO_HCH(n) (STM32_OTG_BASE+STM32_OTG_DFIFO_HCH_OFFSET(n))
+
+#define STM32_OTG_DFIFO_DEP0 (STM32_OTG_BASE+STM32_OTG_DFIFO_DEP0_OFFSET)
+#define STM32_OTG_DFIFO_HCH0 (STM32_OTG_BASE+STM32_OTG_DFIFO_HCH0_OFFSET)
+
+#define STM32_OTG_DFIFO_DEP1 (STM32_OTG_BASE+STM32_OTG_DFIFO_DEP1_OFFSET)
+#define STM32_OTG_DFIFO_HCH1 (STM32_OTG_BASE+STM32_OTG_DFIFO_HCH1_OFFSET)
+
+#define STM32_OTG_DFIFO_DEP2 (STM32_OTG_BASE+STM32_OTG_DFIFO_DEP2_OFFSET)
+#define STM32_OTG_DFIFO_HCH2 (STM32_OTG_BASE+STM32_OTG_DFIFO_HCH2_OFFSET)
+
+#define STM32_OTG_DFIFO_DEP3 (STM32_OTG_BASE+STM32_OTG_DFIFO_DEP3_OFFSET)
+#define STM32_OTG_DFIFO_HCH3 (STM32_OTG_BASE+STM32_OTG_DFIFO_HCH3_OFFSET)
+
+/* Register Bitfield Definitions ********************************************************************/
+/* Core global control and status registers */
+
+/* Control and status register */
+
+#define OTG_GOTGCTL_SRQSCS (1 << 0) /* Bit 0: Session request success */
+#define OTG_GOTGCTL_SRQ (1 << 1) /* Bit 1: Session request */
+#define OTG_GOTGCTL_VBVALOEN (1 << 2) /* Bit 2: VBUS valid override enable */
+#define OTG_GOTGCTL_VBVALOVAL (1 << 3) /* Bit 3: VBUS valid override value */
+#define OTG_GOTGCTL_AVALOEN (1 << 4) /* Bit 4: A-peripheral session valid override enable */
+#define OTG_GOTGCTL_AVALOVAL (1 << 5) /* Bit 5: A-peripheral session valid override value */
+#define OTG_GOTGCTL_BVALOEN (1 << 6) /* Bit 6: B-peripheral session valid override enable */
+#define OTG_GOTGCTL_BVALOVAL (1 << 7) /* Bit 7: B-peripheral session valid override value */
+#define OTG_GOTGCTL_HNGSCS (1 << 8) /* Bit 8: Host negotiation success */
+#define OTG_GOTGCTL_HNPRQ (1 << 9) /* Bit 9: HNP request */
+#define OTG_GOTGCTL_HSHNPEN (1 << 10) /* Bit 10: host set HNP enable */
+#define OTG_GOTGCTL_DHNPEN (1 << 11) /* Bit 11: Device HNP enabled */
+#define OTG_GOTGCTL_EHEN (1 << 12) /* Bit 12: Embedded host enable */
+ /* Bits 13-15: Reserved, must be kept at reset value */
+#define OTG_GOTGCTL_CIDSTS (1 << 16) /* Bit 16: Connector ID status */
+#define OTG_GOTGCTL_DBCT (1 << 17) /* Bit 17: Long/short debounce time */
+#define OTG_GOTGCTL_ASVLD (1 << 18) /* Bit 18: A-session valid */
+#define OTG_GOTGCTL_BSVLD (1 << 19) /* Bit 19: B-session valid */
+#define OTG_GOTGCTL_OTGVER (1 << 20) /* Bit 20: OTG version */
+ /* Bits 21-31: Reserved, must be kept at reset value */
+/* Interrupt register */
+ /* Bits 1:0 Reserved, must be kept at reset value */
+#define OTG_GOTGINT_SEDET (1 << 2) /* Bit 2: Session end detected */
+ /* Bits 3-7: Reserved, must be kept at reset value */
+#define OTG_GOTGINT_SRSSCHG (1 << 8) /* Bit 8: Session request success status change */
+#define OTG_GOTGINT_HNSSCHG (1 << 9) /* Bit 9: Host negotiation success status change */
+ /* Bits 16:10 Reserved, must be kept at reset value */
+#define OTG_GOTGINT_HNGDET (1 << 17) /* Bit 17: Host negotiation detected */
+#define OTG_GOTGINT_ADTOCHG (1 << 18) /* Bit 18: A-device timeout change */
+#define OTG_GOTGINT_DBCDNE (1 << 19) /* Bit 19: Debounce done */
+#define OTG_GOTGINT_IDCHNG (1 << 20) /* Bit 20: Change in ID pin input value */
+ /* Bits 21-31: Reserved, must be kept at reset value */
+
+/* AHB configuration register */
+
+#define OTG_GAHBCFG_GINTMSK (1 << 0) /* Bit 0: Global interrupt mask */
+ /* Bits 1-6: Reserved, must be kept at reset value */
+#define OTG_GAHBCFG_TXFELVL (1 << 7) /* Bit 7: TxFIFO empty level */
+#define OTG_GAHBCFG_PTXFELVL (1 << 8) /* Bit 8: Periodic TxFIFO empty level */
+ /* Bits 20-31: Reserved, must be kept at reset value */
+/* USB configuration register */
+
+#define OTG_GUSBCFG_TOCAL_SHIFT (0) /* Bits 0-2: FS timeout calibration */
+#define OTG_GUSBCFG_TOCAL_MASK (7 << OTG_GUSBCFG_TOCAL_SHIFT)
+ /* Bits 3-5: Reserved, must be kept at reset value */
+#define OTG_GUSBCFG_PHYSEL (1 << 6) /* Bit 6: Full Speed serial transceiver select */
+ /* Bit 7: Reserved, must be kept at reset value */
+#define OTG_GUSBCFG_SRPCAP (1 << 8) /* Bit 8: SRP-capable */
+#define OTG_GUSBCFG_HNPCAP (1 << 9) /* Bit 9: HNP-capable */
+#define OTG_GUSBCFG_TRDT_SHIFT (10) /* Bits 10-13: USB turnaround time */
+#define OTG_GUSBCFG_TRDT_MASK (15 << OTG_GUSBCFG_TRDT_SHIFT)
+# define OTG_GUSBCFG_TRDT(n) ((n) << OTG_GUSBCFG_TRDT_SHIFT)
+ /* Bits 14-28: Reserved, must be kept at reset value */
+#define OTG_GUSBCFG_FHMOD (1 << 29) /* Bit 29: Force host mode */
+#define OTG_GUSBCFG_FDMOD (1 << 30) /* Bit 30: Force device mode */
+#define OTG_GUSBCFG_CTXPKT (1 << 31) /* Bit 31: Corrupt Tx packet */
+ /* Bits 20-31: Reserved, must be kept at reset value */
+/* Reset register */
+
+#define OTG_GRSTCTL_CSRST (1 << 0) /* Bit 0: Core soft reset */
+#define OTG_GRSTCTL_HSRST (1 << 1) /* Bit 1: HCLK soft reset */
+#define OTG_GRSTCTL_FCRST (1 << 2) /* Bit 2: Host frame counter reset */
+ /* Bit 3 Reserved, must be kept at reset value */
+#define OTG_GRSTCTL_RXFFLSH (1 << 4) /* Bit 4: RxFIFO flush */
+#define OTG_GRSTCTL_TXFFLSH (1 << 5) /* Bit 5: TxFIFO flush */
+#define OTG_GRSTCTL_TXFNUM_SHIFT (6) /* Bits 6-10: TxFIFO number */
+#define OTG_GRSTCTL_TXFNUM_MASK (31 << OTG_GRSTCTL_TXFNUM_SHIFT)
+# define OTG_GRSTCTL_TXFNUM_HNONPER (0 << OTG_GRSTCTL_TXFNUM_SHIFT) /* Non-periodic TxFIFO flush in host mode */
+# define OTG_GRSTCTL_TXFNUM_HPER (1 << OTG_GRSTCTL_TXFNUM_SHIFT) /* Periodic TxFIFO flush in host mode */
+# define OTG_GRSTCTL_TXFNUM_HALL (16 << OTG_GRSTCTL_TXFNUM_SHIFT) /* Flush all the transmit FIFOs in host mode.*/
+# define OTG_GRSTCTL_TXFNUM_D(n) ((n) << OTG_GRSTCTL_TXFNUM_SHIFT) /* TXFIFO n flush in device mode, n=0-15 */
+# define OTG_GRSTCTL_TXFNUM_DALL (16 << OTG_GRSTCTL_TXFNUM_SHIFT) /* Flush all the transmit FIFOs in device mode.*/
+ /* Bits 11-31: Reserved, must be kept at reset value */
+#define OTG_GRSTCTL_AHBIDL (1 << 31) /* Bit 31: AHB master idle */
+
+/* Core interrupt and Interrupt mask registers */
+
+#define OTG_GINTSTS_CMOD (1 << 0) /* Bit 0: Current mode of operation */
+# define OTG_GINTSTS_DEVMODE (0)
+# define OTG_GINTSTS_HOSTMODE (OTG_GINTSTS_CMOD)
+#define OTG_GINT_MMIS (1 << 1) /* Bit 1: Mode mismatch interrupt */
+#define OTG_GINT_OTG (1 << 2) /* Bit 2: OTG interrupt */
+#define OTG_GINT_SOF (1 << 3) /* Bit 3: Start of frame */
+#define OTG_GINT_RXFLVL (1 << 4) /* Bit 4: RxFIFO non-empty */
+#define OTG_GINT_NPTXFE (1 << 5) /* Bit 5: Non-periodic TxFIFO empty */
+#define OTG_GINT_GINAKEFF (1 << 6) /* Bit 6: Global IN non-periodic NAK effective */
+#define OTG_GINT_GONAKEFF (1 << 7) /* Bit 7: Global OUT NAK effective */
+ /* Bits 8-9: Reserved, must be kept at reset value */
+#define OTG_GINT_ESUSP (1 << 10) /* Bit 10: Early suspend */
+#define OTG_GINT_USBSUSP (1 << 11) /* Bit 11: USB suspend */
+#define OTG_GINT_USBRST (1 << 12) /* Bit 12: USB reset */
+#define OTG_GINT_ENUMDNE (1 << 13) /* Bit 13: Enumeration done */
+#define OTG_GINT_ISOODRP (1 << 14) /* Bit 14: Isochronous OUT packet dropped interrupt */
+#define OTG_GINT_EOPF (1 << 15) /* Bit 15: End of periodic frame interrupt */
+ /* Bits 16 Reserved, must be kept at reset value */
+#define OTG_GINTMSK_EPMISM (1 << 17) /* Bit 17: Endpoint mismatch interrupt mask */
+#define OTG_GINT_IEP (1 << 18) /* Bit 18: IN endpoint interrupt */
+#define OTG_GINT_OEP (1 << 19) /* Bit 19: OUT endpoint interrupt */
+#define OTG_GINT_IISOIXFR (1 << 20) /* Bit 20: Incomplete isochronous IN transfer */
+#define OTG_GINT_IISOOXFR (1 << 21) /* Bit 21: Incomplete isochronous OUT transfer (device) */
+#define OTG_GINT_IPXFR (1 << 21) /* Bit 21: Incomplete periodic transfer (host) */
+ /* Bit 22: Reserved, must be kept at reset value */
+#define OTG_GINT_RSTDET (1 << 23) /* Bit 23: Reset detected interrupt */
+#define OTG_GINT_HPRT (1 << 24) /* Bit 24: Host port interrupt */
+#define OTG_GINT_HC (1 << 25) /* Bit 25: Host channels interrupt */
+#define OTG_GINT_PTXFE (1 << 26) /* Bit 26: Periodic TxFIFO empty */
+#define OTG_GINT_LPMINT (1 << 27) /* Bit 27: LPM interrupt */
+#define OTG_GINT_CIDSCHG (1 << 28) /* Bit 28: Connector ID status change */
+#define OTG_GINT_DISC (1 << 29) /* Bit 29: Disconnect detected interrupt */
+#define OTG_GINT_SRQ (1 << 30) /* Bit 30: Session request/new session detected interrupt */
+#define OTG_GINT_WKUP (1 << 31) /* Bit 31: Resume/remote wakeup detected interrupt */
+
+/* Receive status debug read/OTG status read and pop registers (host mode) */
+
+#define OTG_GRXSTSH_CHNUM_SHIFT (0) /* Bits 0-3: Channel number */
+#define OTG_GRXSTSH_CHNUM_MASK (15 << OTG_GRXSTSH_CHNUM_SHIFT)
+#define OTG_GRXSTSH_BCNT_SHIFT (4) /* Bits 4-14: Byte count */
+#define OTG_GRXSTSH_BCNT_MASK (0x7ff << OTG_GRXSTSH_BCNT_SHIFT)
+#define OTG_GRXSTSH_DPID_SHIFT (15) /* Bits 15-16: Data PID */
+#define OTG_GRXSTSH_DPID_MASK (3 << OTG_GRXSTSH_DPID_SHIFT)
+# define OTG_GRXSTSH_DPID_DATA0 (0 << OTG_GRXSTSH_DPID_SHIFT)
+# define OTG_GRXSTSH_DPID_DATA2 (1 << OTG_GRXSTSH_DPID_SHIFT)
+# define OTG_GRXSTSH_DPID_DATA1 (2 << OTG_GRXSTSH_DPID_SHIFT)
+# define OTG_GRXSTSH_DPID_MDATA (3 << OTG_GRXSTSH_DPID_SHIFT)
+#define OTG_GRXSTSH_PKTSTS_SHIFT (17) /* Bits 17-20: Packet status */
+#define OTG_GRXSTSH_PKTSTS_MASK (15 << OTG_GRXSTSH_PKTSTS_SHIFT)
+# define OTG_GRXSTSH_PKTSTS_INRECVD (2 << OTG_GRXSTSH_PKTSTS_SHIFT) /* IN data packet received */
+# define OTG_GRXSTSH_PKTSTS_INDONE (3 << OTG_GRXSTSH_PKTSTS_SHIFT) /* IN transfer completed */
+# define OTG_GRXSTSH_PKTSTS_DTOGERR (5 << OTG_GRXSTSH_PKTSTS_SHIFT) /* Data toggle error */
+# define OTG_GRXSTSH_PKTSTS_HALTED (7 << OTG_GRXSTSH_PKTSTS_SHIFT) /* Channel halted */
+ /* Bits 21-31: Reserved, must be kept at reset value */
+/* Receive status debug read/OTG status read and pop registers (device mode) */
+
+#define OTG_GRXSTSD_EPNUM_SHIFT (0) /* Bits 0-3: Endpoint number */
+#define OTG_GRXSTSD_EPNUM_MASK (15 << OTG_GRXSTSD_EPNUM_SHIFT)
+#define OTG_GRXSTSD_BCNT_SHIFT (4) /* Bits 4-14: Byte count */
+#define OTG_GRXSTSD_BCNT_MASK (0x7ff << OTG_GRXSTSD_BCNT_SHIFT)
+#define OTG_GRXSTSD_DPID_SHIFT (15) /* Bits 15-16: Data PID */
+#define OTG_GRXSTSD_DPID_MASK (3 << OTG_GRXSTSD_DPID_SHIFT)
+# define OTG_GRXSTSD_DPID_DATA0 (0 << OTG_GRXSTSD_DPID_SHIFT)
+# define OTG_GRXSTSD_DPID_DATA2 (1 << OTG_GRXSTSD_DPID_SHIFT)
+# define OTG_GRXSTSD_DPID_DATA1 (2 << OTG_GRXSTSD_DPID_SHIFT)
+# define OTG_GRXSTSD_DPID_MDATA (3 << OTG_GRXSTSD_DPID_SHIFT)
+#define OTG_GRXSTSD_PKTSTS_SHIFT (17) /* Bits 17-20: Packet status */
+#define OTG_GRXSTSD_PKTSTS_MASK (15 << OTG_GRXSTSD_PKTSTS_SHIFT)
+# define OTG_GRXSTSD_PKTSTS_OUTNAK (1 << OTG_GRXSTSD_PKTSTS_SHIFT) /* Global OUT NAK */
+# define OTG_GRXSTSD_PKTSTS_OUTRECVD (2 << OTG_GRXSTSD_PKTSTS_SHIFT) /* OUT data packet received */
+# define OTG_GRXSTSD_PKTSTS_OUTDONE (3 << OTG_GRXSTSD_PKTSTS_SHIFT) /* OUT transfer completed */
+# define OTG_GRXSTSD_PKTSTS_SETUPDONE (4 << OTG_GRXSTSD_PKTSTS_SHIFT) /* SETUP transaction completed */
+# define OTG_GRXSTSD_PKTSTS_SETUPRECVD (6 << OTG_GRXSTSD_PKTSTS_SHIFT) /* SETUP data packet received */
+#define OTG_GRXSTSD_FRMNUM_SHIFT (21) /* Bits 21-24: Frame number */
+#define OTG_GRXSTSD_FRMNUM_MASK (15 << OTG_GRXSTSD_FRMNUM_SHIFT)
+ /* Bits 25-31: Reserved, must be kept at reset value */
+/* Receive FIFO size register */
+
+#define OTG_GRXFSIZ_MASK (0xffff)
+
+/* Host non-periodic transmit FIFO size register */
+
+#define OTG_HNPTXFSIZ_NPTXFSA_SHIFT (0) /* Bits 0-15: Non-periodic transmit RAM start address */
+#define OTG_HNPTXFSIZ_NPTXFSA_MASK (0xffff << OTG_HNPTXFSIZ_NPTXFSA_SHIFT)
+#define OTG_HNPTXFSIZ_NPTXFD_SHIFT (16) /* Bits 16-31: Non-periodic TxFIFO depth */
+#define OTG_HNPTXFSIZ_NPTXFD_MASK (0xffff << OTG_HNPTXFSIZ_NPTXFD_SHIFT)
+# define OTG_HNPTXFSIZ_NPTXFD_MIN (16 << OTG_HNPTXFSIZ_NPTXFD_SHIFT)
+# define OTG_HNPTXFSIZ_NPTXFD_MAX (256 << OTG_HNPTXFSIZ_NPTXFD_SHIFT)
+
+/* Endpoint 0 Transmit FIFO size */
+
+#define OTG_DIEPTXF0_TX0FD_SHIFT (0) /* Bits 0-15: Endpoint 0 transmit RAM start address */
+#define OTG_DIEPTXF0_TX0FD_MASK (0xffff << OTG_DIEPTXF0_TX0FD_SHIFT)
+#define OTG_DIEPTXF0_TX0FSA_SHIFT (16) /* Bits 16-31: Endpoint 0 TxFIFO depth */
+#define OTG_DIEPTXF0_TX0FSA_MASK (0xffff << OTG_DIEPTXF0_TX0FSA_SHIFT)
+# define OTG_DIEPTXF0_TX0FSA_MIN (16 << OTG_DIEPTXF0_TX0FSA_SHIFT)
+# define OTG_DIEPTXF0_TX0FSA_MAX (256 << OTG_DIEPTXF0_TX0FSA_SHIFT)
+
+/* Non-periodic transmit FIFO/queue status register */
+
+#define OTG_HNPTXSTS_NPTXFSAV_SHIFT (0) /* Bits 0-15: Non-periodic TxFIFO space available */
+#define OTG_HNPTXSTS_NPTXFSAV_MASK (0xffff << OTG_HNPTXSTS_NPTXFSAV_SHIFT)
+# define OTG_HNPTXSTS_NPTXFSAV_FULL (0 << OTG_HNPTXSTS_NPTXFSAV_SHIFT)
+#define OTG_HNPTXSTS_NPTQXSAV_SHIFT (16) /* Bits 16-23: Non-periodic transmit request queue space available */
+#define OTG_HNPTXSTS_NPTQXSAV_MASK (0xff << OTG_HNPTXSTS_NPTQXSAV_SHIFT)
+# define OTG_HNPTXSTS_NPTQXSAV_FULL (0 << OTG_HNPTXSTS_NPTQXSAV_SHIFT)
+#define OTG_HNPTXSTS_NPTXQTOP_SHIFT (24) /* Bits 24-30: Top of the non-periodic transmit request queue */
+#define OTG_HNPTXSTS_NPTXQTOP_MASK (0x7f << OTG_HNPTXSTS_NPTXQTOP_SHIFT)
+# define OTG_HNPTXSTS_TERMINATE (1 << 24) /* Bit 24: Terminate (last entry for selected channel/endpoint) */
+# define OTG_HNPTXSTS_TYPE_SHIFT (25) /* Bits 25-26: Status */
+# define OTG_HNPTXSTS_TYPE_MASK (3 << OTG_HNPTXSTS_TYPE_SHIFT)
+# define OTG_HNPTXSTS_TYPE_INOUT (0 << OTG_HNPTXSTS_TYPE_SHIFT) /* IN/OUT token */
+# define OTG_HNPTXSTS_TYPE_ZLP (1 << OTG_HNPTXSTS_TYPE_SHIFT) /* Zero-length transmit packet (device IN/host OUT) */
+# define OTG_HNPTXSTS_TYPE_HALT (3 << OTG_HNPTXSTS_TYPE_SHIFT) /* Channel halt command */
+# define OTG_HNPTXSTS_CHNUM_SHIFT (27) /* Bits 27-30: Channel number */
+# define OTG_HNPTXSTS_CHNUM_MASK (15 << OTG_HNPTXSTS_CHNUM_SHIFT)
+# define OTG_HNPTXSTS_EPNUM_SHIFT (27) /* Bits 27-30: Endpoint number */
+# define OTG_HNPTXSTS_EPNUM_MASK (15 << OTG_HNPTXSTS_EPNUM_SHIFT)
+ /* Bit 31 Reserved, must be kept at reset value */
+/* General core configuration register */
+ /* Bits 0-15: Reserved, must be kept at reset value */
+#define OTG_GCCFG_PWRDWN (1 << 16) /* Bit 16: Power down */
+ /* Bit 17 Reserved, must be kept at reset value */
+#define OTG_GCCFG_VBDEN (1 << 21) /* Bit 21: USB VBUS detection enable */
+ /* Bits 22-31: Reserved, must be kept at reset value */
+/* Core ID register (32-bit product ID) */
+
+/* Host periodic transmit FIFO size register */
+
+#define OTG_HPTXFSIZ_PTXSA_SHIFT (0) /* Bits 0-15: Host periodic TxFIFO start address */
+#define OTG_HPTXFSIZ_PTXSA_MASK (0xffff << OTG_HPTXFSIZ_PTXSA_SHIFT)
+#define OTG_HPTXFSIZ_PTXFD_SHIFT (16) /* Bits 16-31: Host periodic TxFIFO depth */
+#define OTG_HPTXFSIZ_PTXFD_MASK (0xffff << OTG_HPTXFSIZ_PTXFD_SHIFT)
+
+/* Device IN endpoint transmit FIFOn size register */
+
+#define OTG_DIEPTXF_INEPTXSA_SHIFT (0) /* Bits 0-15: IN endpoint FIFOx transmit RAM start address */
+#define OTG_DIEPTXF_INEPTXSA_MASK (0xffff << OTG_DIEPTXF_INEPTXSA_SHIFT)
+#define OTG_DIEPTXF_INEPTXFD_SHIFT (16) /* Bits 16-31: IN endpoint TxFIFO depth */
+#define OTG_DIEPTXF_INEPTXFD_MASK (0xffff << OTG_DIEPTXF_INEPTXFD_SHIFT)
+# define OTG_DIEPTXF_INEPTXFD_MIN (16 << OTG_DIEPTXF_INEPTXFD_MASK)
+
+/* Host-mode control and status registers */
+
+/* Host configuration register */
+
+#define OTG_HCFG_FSLSPCS_SHIFT (0) /* Bits 0-1: FS/LS PHY clock select */
+#define OTG_HCFG_FSLSPCS_MASK (3 << OTG_HCFG_FSLSPCS_SHIFT)
+# define OTG_HCFG_FSLSPCS_FS48MHz (1 << OTG_HCFG_FSLSPCS_SHIFT) /* FS host mode, PHY clock is running at 48 MHz */
+# define OTG_HCFG_FSLSPCS_LS48MHz (1 << OTG_HCFG_FSLSPCS_SHIFT) /* LS host mode, Select 48 MHz PHY clock frequency */
+# define OTG_HCFG_FSLSPCS_LS6MHz (2 << OTG_HCFG_FSLSPCS_SHIFT) /* LS host mode, Select 6 MHz PHY clock frequency */
+#define OTG_HCFG_FSLSS (1 << 2) /* Bit 2: FS- and LS-only support */
+ /* Bits 31:3 Reserved, must be kept at reset value */
+/* Host frame interval register */
+
+#define OTG_HFIR_MASK (0xffff)
+
+/* Host frame number/frame time remaining register */
+
+#define OTG_HFNUM_FRNUM_SHIFT (0) /* Bits 0-15: Frame number */
+#define OTG_HFNUM_FRNUM_MASK (0xffff << OTG_HFNUM_FRNUM_SHIFT)
+#define OTG_HFNUM_FTREM_SHIFT (16) /* Bits 16-31: Frame time remaining */
+#define OTG_HFNUM_FTREM_MASK (0xffff << OTG_HFNUM_FTREM_SHIFT)
+
+/* Host periodic transmit FIFO/queue status register */
+
+#define OTG_HPTXSTS_PTXFSAVL_SHIFT (0) /* Bits 0-15: Periodic transmit data FIFO space available */
+#define OTG_HPTXSTS_PTXFSAVL_MASK (0xffff << OTG_HPTXSTS_PTXFSAVL_SHIFT)
+# define OTG_HPTXSTS_PTXFSAVL_FULL (0 << OTG_HPTXSTS_PTXFSAVL_SHIFT)
+#define OTG_HPTXSTS_PTXQSAV_SHIFT (16) /* Bits 16-23: Periodic transmit request queue space available */
+#define OTG_HPTXSTS_PTXQSAV_MASK (0xff << OTG_HPTXSTS_PTXQSAV_SHIFT)
+# define OTG_HPTXSTS_PTXQSAV_FULL (0 << OTG_HPTXSTS_PTXQSAV_SHIFT)
+#define OTG_HPTXSTS_PTXQTOP_SHIFT (24) /* Bits 24-31: Top of the periodic transmit request queue */
+#define OTG_HPTXSTS_PTXQTOP_MASK (0x7f << OTG_HPTXSTS_PTXQTOP_SHIFT)
+# define OTG_HPTXSTS_TERMINATE (1 << 24) /* Bit 24: Terminate (last entry for selected channel/endpoint) */
+# define OTG_HPTXSTS_TYPE_SHIFT (25) /* Bits 25-26: Type */
+# define OTG_HPTXSTS_TYPE_MASK (3 << OTG_HPTXSTS_TYPE_SHIFT)
+# define OTG_HPTXSTS_TYPE_INOUT (0 << OTG_HPTXSTS_TYPE_SHIFT) /* IN/OUT token */
+# define OTG_HPTXSTS_TYPE_ZLP (1 << OTG_HPTXSTS_TYPE_SHIFT) /* Zero-length transmit packet */
+# define OTG_HPTXSTS_TYPE_HALT (3 << OTG_HPTXSTS_TYPE_SHIFT) /* Disable channel command */
+# define OTG_HPTXSTS_EPNUM_SHIFT (27) /* Bits 27-30: Endpoint number */
+# define OTG_HPTXSTS_EPNUM_MASK (15 << OTG_HPTXSTS_EPNUM_SHIFT)
+# define OTG_HPTXSTS_CHNUM_SHIFT (27) /* Bits 27-30: Channel number */
+# define OTG_HPTXSTS_CHNUM_MASK (15 << OTG_HPTXSTS_CHNUM_SHIFT)
+# define OTG_HPTXSTS_ODD (1 << 24) /* Bit 31: Send in odd (vs even) frame */
+
+/* Host all channels interrupt and all channels interrupt mask registers */
+
+#define OTG_HAINT(n) (1 << (n)) /* Bits 15:0 HAINTM: Channel interrupt */
+
+/* Host port control and status register */
+
+#define OTG_HPRT_PCSTS (1 << 0) /* Bit 0: Port connect status */
+#define OTG_HPRT_PCDET (1 << 1) /* Bit 1: Port connect detected */
+#define OTG_HPRT_PENA (1 << 2) /* Bit 2: Port enable */
+#define OTG_HPRT_PENCHNG (1 << 3) /* Bit 3: Port enable/disable change */
+#define OTG_HPRT_POCA (1 << 4) /* Bit 4: Port overcurrent active */
+#define OTG_HPRT_POCCHNG (1 << 5) /* Bit 5: Port overcurrent change */
+#define OTG_HPRT_PRES (1 << 6) /* Bit 6: Port resume */
+#define OTG_HPRT_PSUSP (1 << 7) /* Bit 7: Port suspend */
+#define OTG_HPRT_PRST (1 << 8) /* Bit 8: Port reset */
+ /* Bit 9: Reserved, must be kept at reset value */
+#define OTG_HPRT_PLSTS_SHIFT (10) /* Bits 10-11: Port line status */
+#define OTG_HPRT_PLSTS_MASK (3 << OTG_HPRT_PLSTS_SHIFT)
+# define OTG_HPRT_PLSTS_DP (1 << 10) /* Bit 10: Logic level of OTG_FS_FS_DP */
+# define OTG_HPRT_PLSTS_DM (1 << 11) /* Bit 11: Logic level of OTG_FS_FS_DM */
+#define OTG_HPRT_PPWR (1 << 12) /* Bit 12: Port power */
+#define OTG_HPRT_PTCTL_SHIFT (13) /* Bits 13-16: Port test control */
+#define OTG_HPRT_PTCTL_MASK (15 << OTG_HPRT_PTCTL_SHIFT)
+# define OTG_HPRT_PTCTL_DISABLED (0 << OTG_HPRT_PTCTL_SHIFT) /* Test mode disabled */
+# define OTG_HPRT_PTCTL_J (1 << OTG_HPRT_PTCTL_SHIFT) /* Test_J mode */
+# define OTG_HPRT_PTCTL_L (2 << OTG_HPRT_PTCTL_SHIFT) /* Test_K mode */
+# define OTG_HPRT_PTCTL_SE0_NAK (3 << OTG_HPRT_PTCTL_SHIFT) /* Test_SE0_NAK mode */
+# define OTG_HPRT_PTCTL_PACKET (4 << OTG_HPRT_PTCTL_SHIFT) /* Test_Packet mode */
+# define OTG_HPRT_PTCTL_FORCE (5 << OTG_HPRT_PTCTL_SHIFT) /* Test_Force_Enable */
+#define OTG_HPRT_PSPD_SHIFT (17) /* Bits 17-18: Port speed */
+#define OTG_HPRT_PSPD_MASK (3 << OTG_HPRT_PSPD_SHIFT)
+# define OTG_HPRT_PSPD_FS (1 << OTG_HPRT_PSPD_SHIFT) /* Full speed */
+# define OTG_HPRT_PSPD_LS (2 << OTG_HPRT_PSPD_SHIFT) /* Low speed */
+ /* Bits 19-31: Reserved, must be kept at reset value */
+
+/* Host channel-n characteristics register */
+
+#define OTG_HCCHAR_MPSIZ_SHIFT (0) /* Bits 0-10: Maximum packet size */
+#define OTG_HCCHAR_MPSIZ_MASK (0x7ff << OTG_HCCHAR_MPSIZ_SHIFT)
+#define OTG_HCCHAR_EPNUM_SHIFT (11) /* Bits 11-14: Endpoint number */
+#define OTG_HCCHAR_EPNUM_MASK (15 << OTG_HCCHAR_EPNUM_SHIFT)
+#define OTG_HCCHAR_EPDIR (1 << 15) /* Bit 15: Endpoint direction */
+# define OTG_HCCHAR_EPDIR_OUT (0)
+# define OTG_HCCHAR_EPDIR_IN OTG_HCCHAR_EPDIR
+ /* Bit 16 Reserved, must be kept at reset value */
+#define OTG_HCCHAR_LSDEV (1 << 17) /* Bit 17: Low-speed device */
+#define OTG_HCCHAR_EPTYP_SHIFT (18) /* Bits 18-19: Endpoint type */
+#define OTG_HCCHAR_EPTYP_MASK (3 << OTG_HCCHAR_EPTYP_SHIFT)
+# define OTG_HCCHAR_EPTYP_CTRL (0 << OTG_HCCHAR_EPTYP_SHIFT) /* Control */
+# define OTG_HCCHAR_EPTYP_ISOC (1 << OTG_HCCHAR_EPTYP_SHIFT) /* Isochronous */
+# define OTG_HCCHAR_EPTYP_BULK (2 << OTG_HCCHAR_EPTYP_SHIFT) /* Bulk */
+# define OTG_HCCHAR_EPTYP_INTR (3 << OTG_HCCHAR_EPTYP_SHIFT) /* Interrupt */
+#define OTG_HCCHAR_MCNT_SHIFT (20) /* Bits 20-21: Multicount */
+#define OTG_HCCHAR_MCNT_MASK (3 << OTG_HCCHAR_MCNT_SHIFT)
+#define OTG_HCCHAR_DAD_SHIFT (22) /* Bits 22-28: Device address */
+#define OTG_HCCHAR_DAD_MASK (0x7f << OTG_HCCHAR_DAD_SHIFT)
+#define OTG_HCCHAR_ODDFRM (1 << 29) /* Bit 29: Odd frame */
+#define OTG_HCCHAR_CHDIS (1 << 30) /* Bit 30: Channel disable */
+#define OTG_HCCHAR_CHENA (1 << 31) /* Bit 31: Channel enable */
+
+/* Host channel-n interrupt and Host channel-0 interrupt mask registers */
+
+#define OTG_HCINT_XFRC (1 << 0) /* Bit 0: Transfer completed */
+#define OTG_HCINT_CHH (1 << 1) /* Bit 1: Channel halted */
+ /* Bit 2: Reserved, must be kept at reset value */
+#define OTG_HCINT_STALL (1 << 3) /* Bit 3: STALL response received interrupt */
+#define OTG_HCINT_NAK (1 << 4) /* Bit 4: NAK response received interrupt */
+#define OTG_HCINT_ACK (1 << 5) /* Bit 5: ACK response received/transmitted interrupt */
+#define OTG_HCINT_NYET (1 << 6) /* Bit 6: Response received interrupt */
+#define OTG_HCINT_TXERR (1 << 7) /* Bit 7: Transaction error */
+#define OTG_HCINT_BBERR (1 << 8) /* Bit 8: Babble error */
+#define OTG_HCINT_FRMOR (1 << 9) /* Bit 9: Frame overrun */
+#define OTG_HCINT_DTERR (1 << 10) /* Bit 10: Data toggle error */
+ /* Bits 11-31 Reserved, must be kept at reset value */
+/* Host channel-n interrupt register */
+
+#define OTG_HCTSIZ_XFRSIZ_SHIFT (0) /* Bits 0-18: Transfer size */
+#define OTG_HCTSIZ_XFRSIZ_MASK (0x7ffff << OTG_HCTSIZ_XFRSIZ_SHIFT)
+#define OTG_HCTSIZ_PKTCNT_SHIFT (19) /* Bits 19-28: Packet count */
+#define OTG_HCTSIZ_PKTCNT_MASK (0x3ff << OTG_HCTSIZ_PKTCNT_SHIFT)
+#define OTG_HCTSIZ_DPID_SHIFT (29) /* Bits 29-30: Data PID */
+#define OTG_HCTSIZ_DPID_MASK (3 << OTG_HCTSIZ_DPID_SHIFT)
+# define OTG_HCTSIZ_DPID_DATA0 (0 << OTG_HCTSIZ_DPID_SHIFT)
+# define OTG_HCTSIZ_DPID_DATA2 (1 << OTG_HCTSIZ_DPID_SHIFT)
+# define OTG_HCTSIZ_DPID_DATA1 (2 << OTG_HCTSIZ_DPID_SHIFT)
+# define OTG_HCTSIZ_DPID_MDATA (3 << OTG_HCTSIZ_DPID_SHIFT) /* Non-control */
+# define OTG_HCTSIZ_PID_SETUP (3 << OTG_HCTSIZ_DPID_SHIFT) /* Control */
+ /* Bit 31 Reserved, must be kept at reset value */
+/* Device-mode control and status registers */
+
+/* Device configuration register */
+
+#define OTG_DCFG_DSPD_SHIFT (0) /* Bits 0-1: Device speed */
+#define OTG_DCFG_DSPD_MASK (3 << OTG_DCFG_DSPD_SHIFT)
+# define OTG_DCFG_DSPD_FS (3 << OTG_DCFG_DSPD_SHIFT) /* Full speed */
+#define OTG_DCFG_NZLSOHSK (1 << 2) /* Bit 2: Non-zero-length status OUT handshake */
+ /* Bit 3: Reserved, must be kept at reset value */
+#define OTG_DCFG_DAD_SHIFT (4) /* Bits 4-10: Device address */
+#define OTG_DCFG_DAD_MASK (0x7f << OTG_DCFG_DAD_SHIFT)
+#define OTG_DCFG_PFIVL_SHIFT (11) /* Bits 11-12: Periodic frame interval */
+#define OTG_DCFG_PFIVL_MASK (3 << OTG_DCFG_PFIVL_SHIFT)
+# define OTG_DCFG_PFIVL_80PCT (0 << OTG_DCFG_PFIVL_SHIFT) /* 80% of the frame interval */
+# define OTG_DCFG_PFIVL_85PCT (1 << OTG_DCFG_PFIVL_SHIFT) /* 85% of the frame interval */
+# define OTG_DCFG_PFIVL_90PCT (2 << OTG_DCFG_PFIVL_SHIFT) /* 90% of the frame interval */
+# define OTG_DCFG_PFIVL_95PCT (3 << OTG_DCFG_PFIVL_SHIFT) /* 95% of the frame interval */
+ /* Bits 13-31 Reserved, must be kept at reset value */
+/* Device control register */
+
+#define OTG_TESTMODE_DISABLED (0) /* Test mode disabled */
+#define OTG_TESTMODE_J (1) /* Test_J mode */
+#define OTG_TESTMODE_K (2) /* Test_K mode */
+#define OTG_TESTMODE_SE0_NAK (3) /* Test_SE0_NAK mode */
+#define OTG_TESTMODE_PACKET (4) /* Test_Packet mode */
+#define OTG_TESTMODE_FORCE (5) /* Test_Force_Enable */
+
+#define OTG_DCTL_RWUSIG (1 << 0) /* Bit 0: Remote wakeup signaling */
+#define OTG_DCTL_SDIS (1 << 1) /* Bit 1: Soft disconnect */
+#define OTG_DCTL_GINSTS (1 << 2) /* Bit 2: Global IN NAK status */
+#define OTG_DCTL_GONSTS (1 << 3) /* Bit 3: Global OUT NAK status */
+#define OTG_DCTL_TCTL_SHIFT (4) /* Bits 4-6: Test control */
+#define OTG_DCTL_TCTL_MASK (7 << OTG_DCTL_TCTL_SHIFT)
+# define OTG_DCTL_TCTL_DISABLED (0 << OTG_DCTL_TCTL_SHIFT) /* Test mode disabled */
+# define OTG_DCTL_TCTL_J (1 << OTG_DCTL_TCTL_SHIFT) /* Test_J mode */
+# define OTG_DCTL_TCTL_K (2 << OTG_DCTL_TCTL_SHIFT) /* Test_K mode */
+# define OTG_DCTL_TCTL_SE0_NAK (3 << OTG_DCTL_TCTL_SHIFT) /* Test_SE0_NAK mode */
+# define OTG_DCTL_TCTL_PACKET (4 << OTG_DCTL_TCTL_SHIFT) /* Test_Packet mode */
+# define OTG_DCTL_TCTL_FORCE (5 << OTG_DCTL_TCTL_SHIFT) /* Test_Force_Enable */
+#define OTG_DCTL_SGINAK (1 << 7) /* Bit 7: Set global IN NAK */
+#define OTG_DCTL_CGINAK (1 << 8) /* Bit 8: Clear global IN NAK */
+#define OTG_DCTL_SGONAK (1 << 9) /* Bit 9: Set global OUT NAK */
+#define OTG_DCTL_CGONAK (1 << 10) /* Bit 10: Clear global OUT NAK */
+#define OTG_DCTL_POPRGDNE (1 << 11) /* Bit 11: Power-on programming done */
+ /* Bits 12-31: Reserved, must be kept at reset value */
+/* Device status register */
+
+#define OTG_DSTS_SUSPSTS (1 << 0) /* Bit 0: Suspend status */
+#define OTG_DSTS_ENUMSPD_SHIFT (1) /* Bits 1-2: Enumerated speed */
+#define OTG_DSTS_ENUMSPD_MASK (3 << OTG_DSTS_ENUMSPD_SHIFT)
+# define OTG_DSTS_ENUMSPD_FS (3 << OTG_DSTS_ENUMSPD_MASK) /* Full speed */
+ /* Bits 4-7: Reserved, must be kept at reset value */
+#define OTG_DSTS_EERR (1 << 3) /* Bit 3: Erratic error */
+#define OTG_DSTS_SOFFN_SHIFT (8) /* Bits 8-21: Frame number of the received SOF */
+#define OTG_DSTS_SOFFN_MASK (0x3fff << OTG_DSTS_SOFFN_SHIFT)
+#define OTG_DSTS_SOFFN0 (1 << 8) /* Bits 8: Frame number even/odd bit */
+#define OTG_DSTS_SOFFN_EVEN 0
+#define OTG_DSTS_SOFFN_ODD OTG_DSTS_SOFFN0
+ /* Bits 22-31: Reserved, must be kept at reset value */
+/* Device IN endpoint common interrupt mask register */
+
+#define OTG_DIEPMSK_XFRCM (1 << 0) /* Bit 0: Transfer completed interrupt mask */
+#define OTG_DIEPMSK_EPDM (1 << 1) /* Bit 1: Endpoint disabled interrupt mask */
+ /* Bit 2: Reserved, must be kept at reset value */
+#define OTG_DIEPMSK_TOM (1 << 3) /* Bit 3: Timeout condition mask (Non-isochronous endpoints) */
+#define OTG_DIEPMSK_ITTXFEMSK (1 << 4) /* Bit 4: IN token received when TxFIFO empty mask */
+#define OTG_DIEPMSK_INEPNMM (1 << 5) /* Bit 5: IN token received with EP mismatch mask */
+#define OTG_DIEPMSK_INEPNEM (1 << 6) /* Bit 6: IN endpoint NAK effective mask */
+ /* Bits 7-31: Reserved, must be kept at reset value */
+/* Device OUT endpoint common interrupt mask register */
+
+#define OTG_DOEPMSK_XFRCM (1 << 0) /* Bit 0: Transfer completed interrupt mask */
+#define OTG_DOEPMSK_EPDM (1 << 1) /* Bit 1: Endpoint disabled interrupt mask */
+ /* Bit 2: Reserved, must be kept at reset value */
+#define OTG_DOEPMSK_STUPM (1 << 3) /* Bit 3: SETUP phase done mask */
+#define OTG_DOEPMSK_OTEPDM (1 << 4) /* Bit 4: OUT token received when endpoint disabled mask */
+ /* Bits 5-31: Reserved, must be kept at reset value */
+/* Device all endpoints interrupt and All endpoints interrupt mask registers */
+
+#define OTG_DAINT_IEP_SHIFT (0) /* Bits 0-15: IN endpoint interrupt bits */
+#define OTG_DAINT_IEP_MASK (0xffff << OTG_DAINT_IEP_SHIFT)
+# define OTG_DAINT_IEP(n) (1 << (n))
+#define OTG_DAINT_OEP_SHIFT (16) /* Bits 16-31: OUT endpoint interrupt bits */
+#define OTG_DAINT_OEP_MASK (0xffff << OTG_DAINT_OEP_SHIFT)
+# define OTG_DAINT_OEP(n) (1 << ((n)+16))
+
+/* Device VBUS discharge time register */
+
+#define OTG_DVBUSDIS_MASK (0xffff)
+
+/* Device VBUS pulsing time register */
+
+#define OTG_DVBUSPULSE_MASK (0xfff)
+
+/* Device IN endpoint FIFO empty interrupt mask register */
+
+#define OTG_DIEPEMPMSK(n) (1 << (n))
+
+/* Device control IN endpoint 0 control register */
+
+#define OTG_DIEPCTL0_MPSIZ_SHIFT (0) /* Bits 0-1: Maximum packet size */
+#define OTG_DIEPCTL0_MPSIZ_MASK (3 << OTG_DIEPCTL0_MPSIZ_SHIFT)
+# define OTG_DIEPCTL0_MPSIZ_64 (0 << OTG_DIEPCTL0_MPSIZ_SHIFT) /* 64 bytes */
+# define OTG_DIEPCTL0_MPSIZ_32 (1 << OTG_DIEPCTL0_MPSIZ_SHIFT) /* 32 bytes */
+# define OTG_DIEPCTL0_MPSIZ_16 (2 << OTG_DIEPCTL0_MPSIZ_SHIFT) /* 16 bytes */
+# define OTG_DIEPCTL0_MPSIZ_8 (3 << OTG_DIEPCTL0_MPSIZ_SHIFT) /* 8 bytes */
+ /* Bits 2-14: Reserved, must be kept at reset value */
+#define OTG_DIEPCTL0_USBAEP (1 << 15) /* Bit 15: USB active endpoint */
+ /* Bit 16: Reserved, must be kept at reset value */
+#define OTG_DIEPCTL0_NAKSTS (1 << 17) /* Bit 17: NAK status */
+#define OTG_DIEPCTL0_EPTYP_SHIFT (18) /* Bits 18-19: Endpoint type */
+#define OTG_DIEPCTL0_EPTYP_MASK (3 << OTG_DIEPCTL0_EPTYP_SHIFT)
+# define OTG_DIEPCTL0_EPTYP_CTRL (0 << OTG_DIEPCTL0_EPTYP_SHIFT) /* Control (hard-coded) */
+ /* Bit 20: Reserved, must be kept at reset value */
+#define OTG_DIEPCTL0_STALL (1 << 21) /* Bit 21: STALL handshake */
+#define OTG_DIEPCTL0_TXFNUM_SHIFT (22) /* Bits 22-25: TxFIFO number */
+#define OTG_DIEPCTL0_TXFNUM_MASK (15 << OTG_DIEPCTL0_TXFNUM_SHIFT)
+#define OTG_DIEPCTL0_CNAK (1 << 26) /* Bit 26: Clear NAK */
+#define OTG_DIEPCTL0_SNAK (1 << 27) /* Bit 27: Set NAK */
+ /* Bits 28-29: Reserved, must be kept at reset value */
+#define OTG_DIEPCTL0_EPDIS (1 << 30) /* Bit 30: Endpoint disable */
+#define OTG_DIEPCTL0_EPENA (1 << 31) /* Bit 31: Endpoint enable */
+
+/* Device control IN endpoint n control register */
+
+#define OTG_DIEPCTL_MPSIZ_SHIFT (0) /* Bits 0-10: Maximum packet size */
+#define OTG_DIEPCTL_MPSIZ_MASK (0x7ff << OTG_DIEPCTL_MPSIZ_SHIFT)
+ /* Bits 11-14: Reserved, must be kept at reset value */
+#define OTG_DIEPCTL_USBAEP (1 << 15) /* Bit 15: USB active endpoint */
+#define OTG_DIEPCTL_EONUM (1 << 16) /* Bit 16: Even/odd frame */
+# define OTG_DIEPCTL_EVEN (0)
+# define OTG_DIEPCTL_ODD OTG_DIEPCTL_EONUM
+# define OTG_DIEPCTL_DATA0 (0)
+# define OTG_DIEPCTL_DATA1 OTG_DIEPCTL_EONUM
+#define OTG_DIEPCTL_NAKSTS (1 << 17) /* Bit 17: NAK status */
+#define OTG_DIEPCTL_EPTYP_SHIFT (18) /* Bits 18-19: Endpoint type */
+#define OTG_DIEPCTL_EPTYP_MASK (3 << OTG_DIEPCTL_EPTYP_SHIFT)
+# define OTG_DIEPCTL_EPTYP_CTRL (0 << OTG_DIEPCTL_EPTYP_SHIFT) /* Control */
+# define OTG_DIEPCTL_EPTYP_ISOC (1 << OTG_DIEPCTL_EPTYP_SHIFT) /* Isochronous */
+# define OTG_DIEPCTL_EPTYP_BULK (2 << OTG_DIEPCTL_EPTYP_SHIFT) /* Bulk */
+# define OTG_DIEPCTL_EPTYP_INTR (3 << OTG_DIEPCTL_EPTYP_SHIFT) /* Interrupt */
+ /* Bit 20: Reserved, must be kept at reset value */
+#define OTG_DIEPCTL_STALL (1 << 21) /* Bit 21: STALL handshake */
+#define OTG_DIEPCTL_TXFNUM_SHIFT (22) /* Bits 22-25: TxFIFO number */
+#define OTG_DIEPCTL_TXFNUM_MASK (15 << OTG_DIEPCTL_TXFNUM_SHIFT)
+#define OTG_DIEPCTL_CNAK (1 << 26) /* Bit 26: Clear NAK */
+#define OTG_DIEPCTL_SNAK (1 << 27) /* Bit 27: Set NAK */
+#define OTG_DIEPCTL_SD0PID (1 << 28) /* Bit 28: Set DATA0 PID (interrupt/bulk) */
+#define OTG_DIEPCTL_SEVNFRM (1 << 28) /* Bit 28: Set even frame (isochronous)) */
+#define OTG_DIEPCTL_SODDFRM (1 << 29) /* Bit 29: Set odd frame (isochronous) */
+#define OTG_DIEPCTL_EPDIS (1 << 30) /* Bit 30: Endpoint disable */
+#define OTG_DIEPCTL_EPENA (1 << 31) /* Bit 31: Endpoint enable */
+
+/* Device endpoint-n interrupt register */
+
+#define OTG_DIEPINT_XFRC (1 << 0) /* Bit 0: Transfer completed interrupt */
+#define OTG_DIEPINT_EPDISD (1 << 1) /* Bit 1: Endpoint disabled interrupt */
+ /* Bit 2: Reserved, must be kept at reset value */
+#define OTG_DIEPINT_TOC (1 << 3) /* Bit 3: Timeout condition */
+#define OTG_DIEPINT_ITTXFE (1 << 4) /* Bit 4: IN token received when TxFIFO is empty */
+ /* Bit 5: Reserved, must be kept at reset value */
+#define OTG_DIEPINT_INEPNE (1 << 6) /* Bit 6: IN endpoint NAK effective */
+#define OTG_DIEPINT_TXFE (1 << 7) /* Bit 7: Transmit FIFO empty */
+ /* Bits 8-31: Reserved, must be kept at reset value */
+/* Device IN endpoint 0 transfer size register */
+
+#define OTG_DIEPTSIZ0_XFRSIZ_SHIFT (0) /* Bits 0-6: Transfer size */
+#define OTG_DIEPTSIZ0_XFRSIZ_MASK (0x7f << OTG_DIEPTSIZ0_XFRSIZ_SHIFT)
+ /* Bits 7-18: Reserved, must be kept at reset value */
+#define OTG_DIEPTSIZ0_PKTCNT_SHIFT (19) /* Bits 19-20: Packet count */
+#define OTG_DIEPTSIZ0_PKTCNT_MASK (3 << OTG_DIEPTSIZ0_PKTCNT_SHIFT)
+ /* Bits 21-31: Reserved, must be kept at reset value */
+/* Device IN endpoint n transfer size register */
+
+#define OTG_DIEPTSIZ_XFRSIZ_SHIFT (0) /* Bits 0-18: Transfer size */
+#define OTG_DIEPTSIZ_XFRSIZ_MASK (0x7ffff << OTG_DIEPTSIZ_XFRSIZ_SHIFT)
+#define OTG_DIEPTSIZ_PKTCNT_SHIFT (19) /* Bit 19-28: Packet count */
+#define OTG_DIEPTSIZ_PKTCNT_MASK (0x3ff << OTG_DIEPTSIZ_PKTCNT_SHIFT)
+#define OTG_DIEPTSIZ_MCNT_SHIFT (29) /* Bits 29-30: Multi count */
+#define OTG_DIEPTSIZ_MCNT_MASK (3 << OTG_DIEPTSIZ_MCNT_SHIFT)
+ /* Bit 31: Reserved, must be kept at reset value */
+/* Device OUT endpoint TxFIFO status register */
+
+#define OTG_DTXFSTS_MASK (0xffff)
+
+/* Device OUT endpoint 0 control register */
+
+#define OTG_DOEPCTL0_MPSIZ_SHIFT (0) /* Bits 0-1: Maximum packet size */
+#define OTG_DOEPCTL0_MPSIZ_MASK (3 << OTG_DOEPCTL0_MPSIZ_SHIFT)
+# define OTG_DOEPCTL0_MPSIZ_64 (0 << OTG_DOEPCTL0_MPSIZ_SHIFT) /* 64 bytes */
+# define OTG_DOEPCTL0_MPSIZ_32 (1 << OTG_DOEPCTL0_MPSIZ_SHIFT) /* 32 bytes */
+# define OTG_DOEPCTL0_MPSIZ_16 (2 << OTG_DOEPCTL0_MPSIZ_SHIFT) /* 16 bytes */
+# define OTG_DOEPCTL0_MPSIZ_8 (3 << OTG_DOEPCTL0_MPSIZ_SHIFT) /* 8 bytes */
+ /* Bits 2-14: Reserved, must be kept at reset value */
+#define OTG_DOEPCTL0_USBAEP (1 << 15) /* Bit 15: USB active endpoint */
+ /* Bit 16: Reserved, must be kept at reset value */
+#define OTG_DOEPCTL0_NAKSTS (1 << 17) /* Bit 17: NAK status */
+#define OTG_DOEPCTL0_EPTYP_SHIFT (18) /* Bits 18-19: Endpoint type */
+#define OTG_DOEPCTL0_EPTYP_MASK (3 << OTG_DOEPCTL0_EPTYP_SHIFT)
+# define OTG_DOEPCTL0_EPTYP_CTRL (0 << OTG_DOEPCTL0_EPTYP_SHIFT) /* Control (hard-coded) */
+#define OTG_DOEPCTL0_SNPM (1 << 20) /* Bit 20: Snoop mode */
+#define OTG_DOEPCTL0_STALL (1 << 21) /* Bit 21: STALL handshake */
+ /* Bits 22-25: Reserved, must be kept at reset value */
+#define OTG_DOEPCTL0_CNAK (1 << 26) /* Bit 26: Clear NAK */
+#define OTG_DOEPCTL0_SNAK (1 << 27) /* Bit 27: Set NAK */
+ /* Bits 28-29: Reserved, must be kept at reset value */
+#define OTG_DOEPCTL0_EPDIS (1 << 30) /* Bit 30: Endpoint disable */
+#define OTG_DOEPCTL0_EPENA (1 << 31) /* Bit 31: Endpoint enable */
+
+/* Device OUT endpoint n control register */
+
+#define OTG_DOEPCTL_MPSIZ_SHIFT (0) /* Bits 0-10: Maximum packet size */
+#define OTG_DOEPCTL_MPSIZ_MASK (0x7ff << OTG_DOEPCTL_MPSIZ_SHIFT)
+ /* Bits 11-14: Reserved, must be kept at reset value */
+#define OTG_DOEPCTL_USBAEP (1 << 15) /* Bit 15: USB active endpoint */
+#define OTG_DOEPCTL_DPID (1 << 16) /* Bit 16: Endpoint data PID (interrupt/buld) */
+# define OTG_DOEPCTL_DATA0 (0)
+# define OTG_DOEPCTL_DATA1 OTG_DOEPCTL_DPID
+#define OTG_DOEPCTL_EONUM (1 << 16) /* Bit 16: Even/odd frame (isochronous) */
+# define OTG_DOEPCTL_EVEN (0)
+# define OTG_DOEPCTL_ODD OTG_DOEPCTL_EONUM
+#define OTG_DOEPCTL_NAKSTS (1 << 17) /* Bit 17: NAK status */
+#define OTG_DOEPCTL_EPTYP_SHIFT (18) /* Bits 18-19: Endpoint type */
+#define OTG_DOEPCTL_EPTYP_MASK (3 << OTG_DOEPCTL_EPTYP_SHIFT)
+# define OTG_DOEPCTL_EPTYP_CTRL (0 << OTG_DOEPCTL_EPTYP_SHIFT) /* Control */
+# define OTG_DOEPCTL_EPTYP_ISOC (1 << OTG_DOEPCTL_EPTYP_SHIFT) /* Isochronous */
+# define OTG_DOEPCTL_EPTYP_BULK (2 << OTG_DOEPCTL_EPTYP_SHIFT) /* Bulk */
+# define OTG_DOEPCTL_EPTYP_INTR (3 << OTG_DOEPCTL_EPTYP_SHIFT) /* Interrupt */
+#define OTG_DOEPCTL_SNPM (1 << 20) /* Bit 20: Snoop mode */
+#define OTG_DOEPCTL_STALL (1 << 21) /* Bit 21: STALL handshake */
+ /* Bits 22-25: Reserved, must be kept at reset value */
+#define OTG_DOEPCTL_CNAK (1 << 26) /* Bit 26: Clear NAK */
+#define OTG_DOEPCTL_SNAK (1 << 27) /* Bit 27: Set NAK */
+#define OTG_DOEPCTL_SD0PID (1 << 28) /* Bit 28: Set DATA0 PID (interrupt/bulk) */
+#define OTG_DOEPCTL_SEVNFRM (1 << 28) /* Bit 28: Set even frame (isochronous) */
+#define OTG_DOEPCTL_SD1PID (1 << 29) /* Bit 29: Set DATA1 PID (interrupt/bulk) */
+#define OTG_DOEPCTL_SODDFRM (1 << 29) /* Bit 29: Set odd frame (isochronous */
+#define OTG_DOEPCTL_EPDIS (1 << 30) /* Bit 30: Endpoint disable */
+#define OTG_DOEPCTL_EPENA (1 << 31) /* Bit 31: Endpoint enable */
+
+/* Device endpoint-n interrupt register */
+
+#define OTG_DOEPINT_XFRC (1 << 0) /* Bit 0: Transfer completed interrupt */
+#define OTG_DOEPINT_EPDISD (1 << 1) /* Bit 1: Endpoint disabled interrupt */
+ /* Bit 2: Reserved, must be kept at reset value */
+#define OTG_DOEPINT_SETUP (1 << 3) /* Bit 3: SETUP phase done */
+#define OTG_DOEPINT_OTEPDIS (1 << 4) /* Bit 4: OUT token received when endpoint disabled */
+ /* Bit 5: Reserved, must be kept at reset value */
+#define OTG_DOEPINT_B2BSTUP (1 << 6) /* Bit 6: Back-to-back SETUP packets received */
+ /* Bits 7-31: Reserved, must be kept at reset value */
+/* Device OUT endpoint-0 transfer size register */
+
+#define OTG_DOEPTSIZ0_XFRSIZ_SHIFT (0) /* Bits 0-6: Transfer size */
+#define OTG_DOEPTSIZ0_XFRSIZ_MASK (0x7f << OTG_DOEPTSIZ0_XFRSIZ_SHIFT)
+ /* Bits 7-18: Reserved, must be kept at reset value */
+#define OTG_DOEPTSIZ0_PKTCNT (1 << 19) /* Bit 19 PKTCNT: Packet count */
+ /* Bits 20-28: Reserved, must be kept at reset value */
+#define OTG_DOEPTSIZ0_STUPCNT_SHIFT (29) /* Bits 29-30: SETUP packet count */
+#define OTG_DOEPTSIZ0_STUPCNT_MASK (3 << OTG_DOEPTSIZ0_STUPCNT_SHIFT)
+ /* Bit 31: Reserved, must be kept at reset value */
+/* Device OUT endpoint-n transfer size register */
+
+#define OTG_DOEPTSIZ_XFRSIZ_SHIFT (0) /* Bits 0-18: Transfer size */
+#define OTG_DOEPTSIZ_XFRSIZ_MASK (0x7ffff << OTG_DOEPTSIZ_XFRSIZ_SHIFT)
+#define OTG_DOEPTSIZ_PKTCNT_SHIFT (19) /* Bit 19-28: Packet count */
+#define OTG_DOEPTSIZ_PKTCNT_MASK (0x3ff << OTG_DOEPTSIZ_PKTCNT_SHIFT)
+#define OTG_DOEPTSIZ_STUPCNT_SHIFT (29) /* Bits 29-30: SETUP packet count */
+#define OTG_DOEPTSIZ_STUPCNT_MASK (3 << OTG_DOEPTSIZ_STUPCNT_SHIFT)
+#define OTG_DOEPTSIZ_RXDPID_SHIFT (29) /* Bits 29-30: Received data PID */
+#define OTG_DOEPTSIZ_RXDPID_MASK (3 << OTG_DOEPTSIZ_RXDPID_SHIFT)
+# define OTG_DOEPTSIZ_RXDPID_DATA0 (0 << OTG_DOEPTSIZ_RXDPID_SHIFT)
+# define OTG_DOEPTSIZ_RXDPID_DATA2 (1 << OTG_DOEPTSIZ_RXDPID_SHIFT)
+# define OTG_DOEPTSIZ_RXDPID_DATA1 (2 << OTG_DOEPTSIZ_RXDPID_SHIFT)
+# define OTG_DOEPTSIZ_RXDPID_MDATA (3 << OTG_DOEPTSIZ_RXDPID_SHIFT)
+ /* Bit 31: Reserved, must be kept at reset value */
+/* Power and clock gating control register */
+
+#define OTG_PCGCCTL_STPPCLK (1 << 0) /* Bit 0: Stop PHY clock */
+#define OTG_PCGCCTL_GATEHCLK (1 << 1) /* Bit 1: Gate HCLK */
+ /* Bits 2-3: Reserved, must be kept at reset value */
+#define OTG_PCGCCTL_PHYSUSP (1 << 4) /* Bit 4: PHY Suspended */
+ /* Bits 5-31: Reserved, must be kept at reset value */
+
+#endif /* __ARCH_ARM_SRC_STM32F7_CHIP_STM32_OTG_H */
diff --git a/arch/arm/src/stm32f7/chip/stm32f74xx75xx_sdmmc.h b/arch/arm/src/stm32f7/chip/stm32f74xx75xx_sdmmc.h
index e40990ec16..f710aed6d1 100644
--- a/arch/arm/src/stm32f7/chip/stm32f74xx75xx_sdmmc.h
+++ b/arch/arm/src/stm32f7/chip/stm32f74xx75xx_sdmmc.h
@@ -1,5 +1,5 @@
/************************************************************************************
- * arch/arm/src/stm32/chip/stm32_sdio.h
+ * arch/arm/src/stm32f7/chip/stm32_sdio.h
*
* Copyright (C) 2009, 2011-2013 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt
diff --git a/arch/arm/src/stm32f7/stm32_i2c.c b/arch/arm/src/stm32f7/stm32_i2c.c
index bc34aa25aa..6bd842263d 100644
--- a/arch/arm/src/stm32f7/stm32_i2c.c
+++ b/arch/arm/src/stm32f7/stm32_i2c.c
@@ -1,5 +1,5 @@
/************************************************************************************
- * arch/arm/src/stm32/stm32f3xx_i2c.c
+ * arch/arm/src/stm32f7/stm32f3xx_i2c.c
* STM32 F3 I2C Hardware Layer - Device Driver
*
* Copyright (C) 2011 Uros Platise. All rights reserved.
diff --git a/arch/arm/src/stm32f7/stm32_otg.h b/arch/arm/src/stm32f7/stm32_otg.h
new file mode 100644
index 0000000000..69def14608
--- /dev/null
+++ b/arch/arm/src/stm32f7/stm32_otg.h
@@ -0,0 +1,139 @@
+/************************************************************************************
+ * arch/arm/src/stm32f7/stm32_otg.h
+ *
+ * Copyright (C) 2012-2013 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * 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.
+ *
+ ************************************************************************************/
+
+#ifndef __ARCH_ARM_SRC_STM32F7_STM32_OTG_H
+#define __ARCH_ARM_SRC_STM32F7_STM32_OTG_H
+
+/************************************************************************************
+ * Included Files
+ ************************************************************************************/
+
+#include
+
+#include
+
+
+#include "chip/stm32_otg.h"
+
+#if defined(CONFIG_STM32_OTGFS) || defined(CONFIG_STM32_OTGHS)
+
+/************************************************************************************
+ * Pre-processor Definitions
+ ************************************************************************************/
+/* Configuration ********************************************************************/
+
+#ifndef CONFIG_OTG_PRI
+# define CONFIG_OTG_PRI NVIC_SYSH_PRIORITY_DEFAULT
+#endif
+
+#if defined(CONFIG_STM32_OTGFS)
+# define STM32_IRQ_OTG STM32_IRQ_OTGFS
+# define STM32_OTG_BASE STM32_USBOTGFS_BASE
+# define STM32_NENDPOINTS (6) /* ep0-5 x 2 for IN and OUT */
+#endif
+
+#if defined(CONFIG_STM32_OTGHS)
+# define STM32_IRQ_OTG STM32_IRQ_OTGHS
+# define STM32_OTG_BASE STM32_USBOTGHS_BASE
+# define STM32_NENDPOINTS (8) /* ep0-7 x 2 for IN and OUT */
+#endif
+
+/************************************************************************************
+ * Public Functions
+ ************************************************************************************/
+
+#ifndef __ASSEMBLY__
+
+#undef EXTERN
+#if defined(__cplusplus)
+#define EXTERN extern "C"
+extern "C"
+{
+#else
+#define EXTERN extern
+#endif
+
+/****************************************************************************
+ * Name: stm32_otghost_initialize
+ *
+ * Description:
+ * Initialize USB host device controller hardware.
+ *
+ * Input Parameters:
+ * controller -- If the device supports more than USB host controller, then
+ * this identifies which controller is being initializeed. Normally, this
+ * is just zero.
+ *
+ * Returned Value:
+ * And instance of the USB host interface. The controlling task should
+ * use this interface to (1) call the wait() method to wait for a device
+ * to be connected, and (2) call the enumerate() method to bind the device
+ * to a class driver.
+ *
+ * Assumptions:
+ * - This function should called in the initialization sequence in order
+ * to initialize the USB device functionality.
+ * - Class drivers should be initialized prior to calling this function.
+ * Otherwise, there is a race condition if the device is already connected.
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_USBHOST
+struct usbhost_connection_s;
+FAR struct usbhost_connection_s *stm32_otghost_initialize(int controller);
+#endif
+
+/************************************************************************************
+ * Name: stm32_usbsuspend
+ *
+ * Description:
+ * Board logic must provide the stm32_usbsuspend logic if the OTG FS device driver
+ * is used. This function is called whenever the USB enters or leaves suspend
+ * mode. This is an opportunity for the board logic to shutdown clocks, power,
+ * etc. while the USB is suspended.
+ *
+ ************************************************************************************/
+
+void stm32_usbsuspend(FAR struct usbdev_s *dev, bool resume);
+
+#undef EXTERN
+#if defined(__cplusplus)
+}
+#endif
+
+#endif /* __ASSEMBLY__ */
+#endif /* CONFIG_STM32_OTGFS */
+#endif /* __ARCH_ARM_SRC_STM32F7_STM32_OTG_H */
+
diff --git a/arch/arm/src/stm32f7/stm32_otgdev.c b/arch/arm/src/stm32f7/stm32_otgdev.c
new file mode 100644
index 0000000000..e362ef2b45
--- /dev/null
+++ b/arch/arm/src/stm32f7/stm32_otgdev.c
@@ -0,0 +1,5666 @@
+/****************************************************************************
+ * arch/arm/src/stm32f7/stm32_otgdev.c
+ *
+ * Copyright (C) 2012-2014 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * 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
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include
+#include
+#include
+#include
+#include
+
+#include
+#include
+
+#include "chip.h"
+#include "stm32_otg.h"
+#include "up_arch.h"
+#include "up_internal.h"
+
+
+#if defined(CONFIG_USBDEV) && (defined(CONFIG_STM32_OTGFS) || defined(CONFIG_STM32_OTGHS))
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+/* Configuration ***************************************************************/
+
+#ifndef CONFIG_USBDEV_EP0_MAXSIZE
+# define CONFIG_USBDEV_EP0_MAXSIZE 64
+#endif
+
+#ifndef CONFIG_USBDEV_SETUP_MAXDATASIZE
+# define CONFIG_USBDEV_SETUP_MAXDATASIZE CONFIG_USBDEV_EP0_MAXSIZE
+#endif
+
+#ifndef CONFIG_USBDEV_MAXPOWER
+# define CONFIG_USBDEV_MAXPOWER 100 /* mA */
+#endif
+
+/* There is 1.25Kb of FIFO memory. The default partitions this memory
+ * so that there is a TxFIFO allocated for each endpoint and with more
+ * memory provided for the common RxFIFO. A more knowledge-able
+ * configuration would not allocate any TxFIFO space to OUT endpoints.
+ */
+
+#ifndef CONFIG_USBDEV_RXFIFO_SIZE
+# define CONFIG_USBDEV_RXFIFO_SIZE 512
+#endif
+
+#ifndef CONFIG_USBDEV_EP0_TXFIFO_SIZE
+# define CONFIG_USBDEV_EP0_TXFIFO_SIZE 192
+#endif
+
+#ifndef CONFIG_USBDEV_EP1_TXFIFO_SIZE
+# define CONFIG_USBDEV_EP1_TXFIFO_SIZE 192
+#endif
+
+#ifndef CONFIG_USBDEV_EP2_TXFIFO_SIZE
+# define CONFIG_USBDEV_EP2_TXFIFO_SIZE 192
+#endif
+
+#ifndef CONFIG_USBDEV_EP3_TXFIFO_SIZE
+# define CONFIG_USBDEV_EP3_TXFIFO_SIZE 192
+#endif
+
+#if (CONFIG_USBDEV_RXFIFO_SIZE + CONFIG_USBDEV_EP0_TXFIFO_SIZE + \
+ CONFIG_USBDEV_EP2_TXFIFO_SIZE + CONFIG_USBDEV_EP3_TXFIFO_SIZE) > 1280
+# error "FIFO allocations exceed FIFO memory size"
+#endif
+
+/* The actual FIFO addresses that we use must be aligned to 4-byte boundaries;
+ * FIFO sizes must be provided in units of 32-bit words.
+ */
+
+#define STM32_RXFIFO_BYTES ((CONFIG_USBDEV_RXFIFO_SIZE + 3) & ~3)
+#define STM32_RXFIFO_WORDS ((CONFIG_USBDEV_RXFIFO_SIZE + 3) >> 2)
+
+#define STM32_EP0_TXFIFO_BYTES ((CONFIG_USBDEV_EP0_TXFIFO_SIZE + 3) & ~3)
+#define STM32_EP0_TXFIFO_WORDS ((CONFIG_USBDEV_EP0_TXFIFO_SIZE + 3) >> 2)
+
+#if STM32_EP0_TXFIFO_WORDS < 16 || STM32_EP0_TXFIFO_WORDS > 256
+# error "CONFIG_USBDEV_EP0_TXFIFO_SIZE is out of range"
+#endif
+
+#define STM32_EP1_TXFIFO_BYTES ((CONFIG_USBDEV_EP1_TXFIFO_SIZE + 3) & ~3)
+#define STM32_EP1_TXFIFO_WORDS ((CONFIG_USBDEV_EP1_TXFIFO_SIZE + 3) >> 2)
+
+#if STM32_EP1_TXFIFO_WORDS < 16
+# error "CONFIG_USBDEV_EP1_TXFIFO_SIZE is out of range"
+#endif
+
+#define STM32_EP2_TXFIFO_BYTES ((CONFIG_USBDEV_EP2_TXFIFO_SIZE + 3) & ~3)
+#define STM32_EP2_TXFIFO_WORDS ((CONFIG_USBDEV_EP2_TXFIFO_SIZE + 3) >> 2)
+
+#if STM32_EP2_TXFIFO_WORDS < 16
+# error "CONFIG_USBDEV_EP2_TXFIFO_SIZE is out of range"
+#endif
+
+#define STM32_EP3_TXFIFO_BYTES ((CONFIG_USBDEV_EP3_TXFIFO_SIZE + 3) & ~3)
+#define STM32_EP3_TXFIFO_WORDS ((CONFIG_USBDEV_EP3_TXFIFO_SIZE + 3) >> 2)
+
+#if STM32_EP3_TXFIFO_WORDS < 16
+# error "CONFIG_USBDEV_EP3_TXFIFO_SIZE is out of range"
+#endif
+
+/* Debug ***********************************************************************/
+/* Trace error codes */
+
+#define STM32_TRACEERR_ALLOCFAIL 0x01
+#define STM32_TRACEERR_BADCLEARFEATURE 0x02
+#define STM32_TRACEERR_BADDEVGETSTATUS 0x03
+#define STM32_TRACEERR_BADEPNO 0x04
+#define STM32_TRACEERR_BADEPGETSTATUS 0x05
+#define STM32_TRACEERR_BADGETCONFIG 0x06
+#define STM32_TRACEERR_BADGETSETDESC 0x07
+#define STM32_TRACEERR_BADGETSTATUS 0x08
+#define STM32_TRACEERR_BADSETADDRESS 0x09
+#define STM32_TRACEERR_BADSETCONFIG 0x0a
+#define STM32_TRACEERR_BADSETFEATURE 0x0b
+#define STM32_TRACEERR_BADTESTMODE 0x0c
+#define STM32_TRACEERR_BINDFAILED 0x0d
+#define STM32_TRACEERR_DISPATCHSTALL 0x0e
+#define STM32_TRACEERR_DRIVER 0x0f
+#define STM32_TRACEERR_DRIVERREGISTERED 0x10
+#define STM32_TRACEERR_EP0NOSETUP 0x11
+#define STM32_TRACEERR_EP0SETUPSTALLED 0x12
+#define STM32_TRACEERR_EPINNULLPACKET 0x13
+#define STM32_TRACEERR_EPINUNEXPECTED 0x14
+#define STM32_TRACEERR_EPOUTNULLPACKET 0x15
+#define STM32_TRACEERR_EPOUTUNEXPECTED 0x16
+#define STM32_TRACEERR_INVALIDCTRLREQ 0x17
+#define STM32_TRACEERR_INVALIDPARMS 0x18
+#define STM32_TRACEERR_IRQREGISTRATION 0x19
+#define STM32_TRACEERR_NOEP 0x1a
+#define STM32_TRACEERR_NOTCONFIGURED 0x1b
+#define STM32_TRACEERR_EPOUTQEMPTY 0x1c
+#define STM32_TRACEERR_EPINREQEMPTY 0x1d
+#define STM32_TRACEERR_NOOUTSETUP 0x1e
+#define STM32_TRACEERR_POLLTIMEOUT 0x1f
+
+/* Trace interrupt codes */
+
+#define STM32_TRACEINTID_USB 1 /* USB Interrupt entry/exit */
+#define STM32_TRACEINTID_INTPENDING 2 /* On each pass through the loop */
+
+#define STM32_TRACEINTID_EPOUT (10 + 0) /* First level interrupt decode */
+#define STM32_TRACEINTID_EPIN (10 + 1)
+#define STM32_TRACEINTID_MISMATCH (10 + 2)
+#define STM32_TRACEINTID_WAKEUP (10 + 3)
+#define STM32_TRACEINTID_SUSPEND (10 + 4)
+#define STM32_TRACEINTID_SOF (10 + 5)
+#define STM32_TRACEINTID_RXFIFO (10 + 6)
+#define STM32_TRACEINTID_DEVRESET (10 + 7)
+#define STM32_TRACEINTID_ENUMDNE (10 + 8)
+#define STM32_TRACEINTID_IISOIXFR (10 + 9)
+#define STM32_TRACEINTID_IISOOXFR (10 + 10)
+#define STM32_TRACEINTID_SRQ (10 + 11)
+#define STM32_TRACEINTID_OTG (10 + 12)
+
+#define STM32_TRACEINTID_EPOUT_XFRC (40 + 0) /* EPOUT second level decode */
+#define STM32_TRACEINTID_EPOUT_EPDISD (40 + 1)
+#define STM32_TRACEINTID_EPOUT_SETUP (40 + 2)
+#define STM32_TRACEINTID_DISPATCH (40 + 3)
+
+#define STM32_TRACEINTID_GETSTATUS (50 + 0) /* EPOUT third level decode */
+#define STM32_TRACEINTID_EPGETSTATUS (50 + 1)
+#define STM32_TRACEINTID_DEVGETSTATUS (50 + 2)
+#define STM32_TRACEINTID_IFGETSTATUS (50 + 3)
+#define STM32_TRACEINTID_CLEARFEATURE (50 + 4)
+#define STM32_TRACEINTID_SETFEATURE (50 + 5)
+#define STM32_TRACEINTID_SETADDRESS (50 + 6)
+#define STM32_TRACEINTID_GETSETDESC (50 + 7)
+#define STM32_TRACEINTID_GETCONFIG (50 + 8)
+#define STM32_TRACEINTID_SETCONFIG (50 + 9)
+#define STM32_TRACEINTID_GETSETIF (50 + 10)
+#define STM32_TRACEINTID_SYNCHFRAME (50 + 11)
+
+#define STM32_TRACEINTID_EPIN_XFRC (70 + 0) /* EPIN second level decode */
+#define STM32_TRACEINTID_EPIN_TOC (70 + 1)
+#define STM32_TRACEINTID_EPIN_ITTXFE (70 + 2)
+#define STM32_TRACEINTID_EPIN_EPDISD (70 + 3)
+#define STM32_TRACEINTID_EPIN_TXFE (70 + 4)
+
+#define STM32_TRACEINTID_EPIN_EMPWAIT (80 + 0) /* EPIN second level decode */
+
+#define STM32_TRACEINTID_OUTNAK (90 + 0) /* RXFLVL second level decode */
+#define STM32_TRACEINTID_OUTRECVD (90 + 1)
+#define STM32_TRACEINTID_OUTDONE (90 + 2)
+#define STM32_TRACEINTID_SETUPDONE (90 + 3)
+#define STM32_TRACEINTID_SETUPRECVD (90 + 4)
+
+/* Endpoints ******************************************************************/
+
+
+/* Odd physical endpoint numbers are IN; even are OUT */
+
+#define STM32_EPPHYIN2LOG(epphy) ((uint8_t)(epphy)|USB_DIR_IN)
+#define STM32_EPPHYOUT2LOG(epphy) ((uint8_t)(epphy)|USB_DIR_OUT)
+
+/* Endpoint 0 */
+
+#define EP0 (0)
+
+/* The set of all enpoints available to the class implementation (1-3) */
+
+#define STM32_EP_AVAILABLE (0x0e) /* All available endpoints */
+
+/* Maximum packet sizes for full speed endpoints */
+
+#define STM32_MAXPACKET (64) /* Max packet size (1-64) */
+
+/* Delays **********************************************************************/
+
+#define STM32_READY_DELAY 200000
+#define STM32_FLUSH_DELAY 200000
+
+/* Request queue operations ****************************************************/
+
+#define stm32_rqempty(ep) ((ep)->head == NULL)
+#define stm32_rqpeek(ep) ((ep)->head)
+
+/* Standard stuff **************************************************************/
+
+#ifndef MIN
+# define MIN(a,b) ((a) < (b) ? (a) : (b))
+#endif
+
+#ifndef MAX
+# define MAX(a,b) ((a) > (b) ? (a) : (b))
+#endif
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+/* Overall device state */
+
+enum stm32_devstate_e
+{
+ DEVSTATE_DEFAULT = 0, /* Power-up, unconfigured state. This state simply
+ * means that the device is not yet been given an
+ * address.
+ * SET: At initialization, uninitialization,
+ * reset, and whenever the device address
+ * is set to zero
+ * TESTED: Never
+ */
+ DEVSTATE_ADDRESSED, /* Device address has been assigned, not no
+ * configuration has yet been selected.
+ * SET: When either a non-zero device address
+ * is first assigned or when the device
+ * is unconfigured (with configuration == 0)
+ * TESTED: never
+ */
+ DEVSTATE_CONFIGURED, /* Address assigned and configured:
+ * SET: When the device has been addressed and
+ * an non-zero configuration has been selected.
+ * TESTED: In many places to assure that the USB device
+ * has been properly configured by the host.
+ */
+};
+
+/* Endpoint 0 states */
+
+enum stm32_ep0state_e
+{
+ EP0STATE_IDLE = 0, /* Idle State, leave on receiving a SETUP packet or
+ * epsubmit:
+ * SET: In stm32_epin() and stm32_epout() when
+ * we revert from request processing to
+ * SETUP processing.
+ * TESTED: Never
+ */
+ EP0STATE_SETUP_OUT, /* OUT SETUP packet received. Waiting for the DATA
+ * OUT phase of SETUP Packet to complete before
+ * processing a SETUP command (without a USB request):
+ * SET: Set in stm32_rxinterrupt() when SETUP OUT
+ * packet is received.
+ * TESTED: In stm32_ep0out_receive()
+ */
+ EP0STATE_SETUP_READY, /* IN SETUP packet received -OR- OUT SETUP packet and
+ * accompanying data have been received. Processing
+ * of SETUP command will happen soon.
+ * SET: (1) stm32_ep0out_receive() when the OUT
+ * SETUP data phase completes, or (2)
+ * stm32_rxinterrupt() when an IN SETUP is
+ * packet received.
+ * TESTED: Tested in stm32_epout_interrupt() when
+ * SETUP phase is done to see if the SETUP
+ * command is ready to be processed. Also
+ * tested in stm32_ep0out_setup() just to
+ * double-check that we have a SETUP request
+ * and any accompanying data.
+ */
+ EP0STATE_SETUP_PROCESS, /* SETUP Packet is being processed by stm32_ep0out_setup():
+ * SET: When SETUP packet received in EP0 OUT
+ * TESTED: Never
+ */
+ EP0STATE_SETUPRESPONSE, /* Short SETUP response write (without a USB request):
+ * SET: When SETUP response is sent by
+ * stm32_ep0in_setupresponse()
+ * TESTED: Never
+ */
+ EP0STATE_DATA_IN, /* Waiting for data out stage (with a USB request):
+ * SET: In stm32_epin_request() when a write
+ * request is processed on EP0.
+ * TESTED: In stm32_epin() to see if we should
+ * revert to SETUP processing.
+ */
+ EP0STATE_DATA_OUT /* Waiting for data in phase to complete ( with a
+ * USB request)
+ * SET: In stm32_epout_request() when a read
+ * request is processed on EP0.
+ * TESTED: In stm32_epout() to see if we should
+ * revert to SETUP processing
+ */
+};
+
+/* Parsed control request */
+
+struct stm32_ctrlreq_s
+{
+ uint8_t type;
+ uint8_t req;
+ uint16_t value;
+ uint16_t index;
+ uint16_t len;
+};
+
+/* A container for a request so that the request may be retained in a list */
+
+struct stm32_req_s
+{
+ struct usbdev_req_s req; /* Standard USB request */
+ struct stm32_req_s *flink; /* Supports a singly linked list */
+};
+
+/* This is the internal representation of an endpoint */
+
+struct stm32_ep_s
+{
+ /* Common endpoint fields. This must be the first thing defined in the
+ * structure so that it is possible to simply cast from struct usbdev_ep_s
+ * to struct stm32_ep_s.
+ */
+
+ struct usbdev_ep_s ep; /* Standard endpoint structure */
+
+ /* STM32-specific fields */
+
+ struct stm32_usbdev_s *dev; /* Reference to private driver data */
+ struct stm32_req_s *head; /* Request list for this endpoint */
+ struct stm32_req_s *tail;
+ uint8_t epphy; /* Physical EP address */
+ uint8_t eptype:2; /* Endpoint type */
+ uint8_t active:1; /* 1: A request is being processed */
+ uint8_t stalled:1; /* 1: Endpoint is stalled */
+ uint8_t isin:1; /* 1: IN Endpoint */
+ uint8_t odd:1; /* 1: Odd frame */
+ uint8_t zlp:1; /* 1: Transmit a zero-length-packet (IN EPs only) */
+};
+
+/* This structure retains the state of the USB device controller */
+
+struct stm32_usbdev_s
+{
+ /* Common device fields. This must be the first thing defined in the
+ * structure so that it is possible to simply cast from struct usbdev_s
+ * to struct stm32_usbdev_s.
+ */
+
+ struct usbdev_s usbdev;
+
+ /* The bound device class driver */
+
+ struct usbdevclass_driver_s *driver;
+
+ /* STM32-specific fields */
+
+ uint8_t stalled:1; /* 1: Protocol stalled */
+ uint8_t selfpowered:1; /* 1: Device is self powered */
+ uint8_t addressed:1; /* 1: Peripheral address has been set */
+ uint8_t configured:1; /* 1: Class driver has been configured */
+ uint8_t wakeup:1; /* 1: Device remote wake-up */
+ uint8_t dotest:1; /* 1: Test mode selected */
+
+ uint8_t devstate:4; /* See enum stm32_devstate_e */
+ uint8_t ep0state:4; /* See enum stm32_ep0state_e */
+ uint8_t testmode:4; /* Selected test mode */
+ uint8_t epavail[2]; /* Bitset of available OUT/IN endpoints */
+
+ /* E0 SETUP data buffering.
+ *
+ * ctrlreq:
+ * The 8-byte SETUP request is received on the EP0 OUT endpoint and is
+ * saved.
+ *
+ * ep0data
+ * For OUT SETUP requests, the SETUP data phase must also complete before
+ * the SETUP command can be processed. The pack receipt logic will save
+ * the accompanying EP0 IN data in ep0data[] before the SETUP command is
+ * processed.
+ *
+ * For IN SETUP requests, the DATA phase will occur AFTER the SETUP
+ * control request is processed. In that case, ep0data[] may be used as
+ * the response buffer.
+ *
+ * ep0datlen
+ * Length of OUT DATA received in ep0data[] (Not used with OUT data)
+ */
+
+ struct usb_ctrlreq_s ctrlreq;
+ uint8_t ep0data[CONFIG_USBDEV_SETUP_MAXDATASIZE];
+ uint16_t ep0datlen;
+
+ /* The endpoint lists */
+
+ struct stm32_ep_s epin[STM32_NENDPOINTS];
+ struct stm32_ep_s epout[STM32_NENDPOINTS];
+};
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+/* Register operations ********************************************************/
+
+#if defined(CONFIG_STM32_USBDEV_REGDEBUG) && defined(CONFIG_DEBUG_FEATURES)
+static uint32_t stm32_getreg(uint32_t addr);
+static void stm32_putreg(uint32_t val, uint32_t addr);
+#else
+# define stm32_getreg(addr) getreg32(addr)
+# define stm32_putreg(val,addr) putreg32(val,addr)
+#endif
+
+/* Request queue operations ****************************************************/
+
+static FAR struct stm32_req_s *stm32_req_remfirst(FAR struct stm32_ep_s *privep);
+static bool stm32_req_addlast(FAR struct stm32_ep_s *privep,
+ FAR struct stm32_req_s *req);
+
+/* Low level data transfers and request operations *****************************/
+/* Special endpoint 0 data transfer logic */
+
+static void stm32_ep0in_setupresponse(FAR struct stm32_usbdev_s *priv,
+ FAR uint8_t *data, uint32_t nbytes);
+static inline void stm32_ep0in_transmitzlp(FAR struct stm32_usbdev_s *priv);
+static void stm32_ep0in_activate(void);
+
+static void stm32_ep0out_ctrlsetup(FAR struct stm32_usbdev_s *priv);
+
+/* IN request and TxFIFO handling */
+
+static void stm32_txfifo_write(FAR struct stm32_ep_s *privep,
+ FAR uint8_t *buf, int nbytes);
+static void stm32_epin_transfer(FAR struct stm32_ep_s *privep,
+ FAR uint8_t *buf, int nbytes);
+static void stm32_epin_request(FAR struct stm32_usbdev_s *priv,
+ FAR struct stm32_ep_s *privep);
+
+/* OUT request and RxFIFO handling */
+
+static void stm32_rxfifo_read(FAR struct stm32_ep_s *privep,
+ FAR uint8_t *dest, uint16_t len);
+static void stm32_rxfifo_discard(FAR struct stm32_ep_s *privep, int len);
+static void stm32_epout_complete(FAR struct stm32_usbdev_s *priv,
+ FAR struct stm32_ep_s *privep);
+static inline void stm32_ep0out_receive(FAR struct stm32_ep_s *privep, int bcnt);
+static inline void stm32_epout_receive(FAR struct stm32_ep_s *privep, int bcnt);
+static void stm32_epout_request(FAR struct stm32_usbdev_s *priv,
+ FAR struct stm32_ep_s *privep);
+
+/* General request handling */
+
+static void stm32_ep_flush(FAR struct stm32_ep_s *privep);
+static void stm32_req_complete(FAR struct stm32_ep_s *privep,
+ int16_t result);
+static void stm32_req_cancel(FAR struct stm32_ep_s *privep,
+ int16_t status);
+
+/* Interrupt handling **********************************************************/
+
+static struct stm32_ep_s *stm32_ep_findbyaddr(struct stm32_usbdev_s *priv,
+ uint16_t eplog);
+static int stm32_req_dispatch(FAR struct stm32_usbdev_s *priv,
+ FAR const struct usb_ctrlreq_s *ctrl);
+static void stm32_usbreset(FAR struct stm32_usbdev_s *priv);
+
+/* Second level OUT endpoint interrupt processing */
+
+static inline void stm32_ep0out_testmode(FAR struct stm32_usbdev_s *priv,
+ uint16_t index);
+static inline void stm32_ep0out_stdrequest(struct stm32_usbdev_s *priv,
+ FAR struct stm32_ctrlreq_s *ctrlreq);
+static inline void stm32_ep0out_setup(struct stm32_usbdev_s *priv);
+static inline void stm32_epout(FAR struct stm32_usbdev_s *priv,
+ uint8_t epno);
+static inline void stm32_epout_interrupt(FAR struct stm32_usbdev_s *priv);
+
+/* Second level IN endpoint interrupt processing */
+
+static inline void stm32_epin_runtestmode(FAR struct stm32_usbdev_s *priv);
+static inline void stm32_epin(FAR struct stm32_usbdev_s *priv, uint8_t epno);
+static inline void stm32_epin_txfifoempty(FAR struct stm32_usbdev_s *priv, int epno);
+static inline void stm32_epin_interrupt(FAR struct stm32_usbdev_s *priv);
+
+/* Other second level interrupt processing */
+
+static inline void stm32_resumeinterrupt(FAR struct stm32_usbdev_s *priv);
+static inline void stm32_suspendinterrupt(FAR struct stm32_usbdev_s *priv);
+static inline void stm32_rxinterrupt(FAR struct stm32_usbdev_s *priv);
+static inline void stm32_enuminterrupt(FAR struct stm32_usbdev_s *priv);
+#ifdef CONFIG_USBDEV_ISOCHRONOUS
+static inline void stm32_isocininterrupt(FAR struct stm32_usbdev_s *priv);
+static inline void stm32_isocoutinterrupt(FAR struct stm32_usbdev_s *priv);
+#endif
+#ifdef CONFIG_USBDEV_VBUSSENSING
+static inline void stm32_sessioninterrupt(FAR struct stm32_usbdev_s *priv);
+static inline void stm32_otginterrupt(FAR struct stm32_usbdev_s *priv);
+#endif
+
+/* First level interrupt processing */
+
+static int stm32_usbinterrupt(int irq, FAR void *context);
+
+/* Endpoint operations *********************************************************/
+/* Global OUT NAK controls */
+
+static void stm32_enablegonak(FAR struct stm32_ep_s *privep);
+static void stm32_disablegonak(FAR struct stm32_ep_s *privep);
+
+/* Endpoint configuration */
+
+static int stm32_epout_configure(FAR struct stm32_ep_s *privep,
+ uint8_t eptype, uint16_t maxpacket);
+static int stm32_epin_configure(FAR struct stm32_ep_s *privep,
+ uint8_t eptype, uint16_t maxpacket);
+static int stm32_ep_configure(FAR struct usbdev_ep_s *ep,
+ FAR const struct usb_epdesc_s *desc, bool last);
+static void stm32_ep0_configure(FAR struct stm32_usbdev_s *priv);
+
+/* Endpoint disable */
+
+static void stm32_epout_disable(FAR struct stm32_ep_s *privep);
+static void stm32_epin_disable(FAR struct stm32_ep_s *privep);
+static int stm32_ep_disable(FAR struct usbdev_ep_s *ep);
+
+/* Endpoint request management */
+
+static FAR struct usbdev_req_s *stm32_ep_allocreq(FAR struct usbdev_ep_s *ep);
+static void stm32_ep_freereq(FAR struct usbdev_ep_s *ep,
+ FAR struct usbdev_req_s *);
+
+/* Endpoint buffer management */
+
+#ifdef CONFIG_USBDEV_DMA
+static void *stm32_ep_allocbuffer(FAR struct usbdev_ep_s *ep, unsigned bytes);
+static void stm32_ep_freebuffer(FAR struct usbdev_ep_s *ep, FAR void *buf);
+#endif
+
+/* Endpoint request submission */
+
+static int stm32_ep_submit(FAR struct usbdev_ep_s *ep,
+ struct usbdev_req_s *req);
+
+/* Endpoint request cancellation */
+
+static int stm32_ep_cancel(FAR struct usbdev_ep_s *ep,
+ struct usbdev_req_s *req);
+
+/* Stall handling */
+
+static int stm32_epout_setstall(FAR struct stm32_ep_s *privep);
+static int stm32_epin_setstall(FAR struct stm32_ep_s *privep);
+static int stm32_ep_setstall(FAR struct stm32_ep_s *privep);
+static int stm32_ep_clrstall(FAR struct stm32_ep_s *privep);
+static int stm32_ep_stall(FAR struct usbdev_ep_s *ep, bool resume);
+static void stm32_ep0_stall(FAR struct stm32_usbdev_s *priv);
+
+/* Endpoint allocation */
+
+static FAR struct usbdev_ep_s *stm32_ep_alloc(FAR struct usbdev_s *dev,
+ uint8_t epno, bool in, uint8_t eptype);
+static void stm32_ep_free(FAR struct usbdev_s *dev,
+ FAR struct usbdev_ep_s *ep);
+
+/* USB device controller operations ********************************************/
+
+static int stm32_getframe(struct usbdev_s *dev);
+static int stm32_wakeup(struct usbdev_s *dev);
+static int stm32_selfpowered(struct usbdev_s *dev, bool selfpowered);
+static int stm32_pullup(struct usbdev_s *dev, bool enable);
+static void stm32_setaddress(struct stm32_usbdev_s *priv,
+ uint16_t address);
+static int stm32_txfifo_flush(uint32_t txfnum);
+static int stm32_rxfifo_flush(void);
+
+/* Initialization **************************************************************/
+
+static void stm32_swinitialize(FAR struct stm32_usbdev_s *priv);
+static void stm32_hwinitialize(FAR struct stm32_usbdev_s *priv);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+/* Since there is only a single USB interface, all status information can be
+ * be simply retained in a single global instance.
+ */
+
+static struct stm32_usbdev_s g_otghsdev;
+
+static const struct usbdev_epops_s g_epops =
+{
+ .configure = stm32_ep_configure,
+ .disable = stm32_ep_disable,
+ .allocreq = stm32_ep_allocreq,
+ .freereq = stm32_ep_freereq,
+#ifdef CONFIG_USBDEV_DMA
+ .allocbuffer = stm32_ep_allocbuffer,
+ .freebuffer = stm32_ep_freebuffer,
+#endif
+ .submit = stm32_ep_submit,
+ .cancel = stm32_ep_cancel,
+ .stall = stm32_ep_stall,
+};
+
+static const struct usbdev_ops_s g_devops =
+{
+ .allocep = stm32_ep_alloc,
+ .freeep = stm32_ep_free,
+ .getframe = stm32_getframe,
+ .wakeup = stm32_wakeup,
+ .selfpowered = stm32_selfpowered,
+ .pullup = stm32_pullup,
+};
+
+/* Device error strings that may be enabled for more descriptive USB trace
+ * output.
+ */
+
+#ifdef CONFIG_USBDEV_TRACE_STRINGS
+const struct trace_msg_t g_usb_trace_strings_deverror[] =
+{
+ TRACE_STR(STM32_TRACEERR_ALLOCFAIL ),
+ TRACE_STR(STM32_TRACEERR_BADCLEARFEATURE ),
+ TRACE_STR(STM32_TRACEERR_BADDEVGETSTATUS ),
+ TRACE_STR(STM32_TRACEERR_BADEPNO ),
+ TRACE_STR(STM32_TRACEERR_BADEPGETSTATUS ),
+ TRACE_STR(STM32_TRACEERR_BADGETCONFIG ),
+ TRACE_STR(STM32_TRACEERR_BADGETSETDESC ),
+ TRACE_STR(STM32_TRACEERR_BADGETSTATUS ),
+ TRACE_STR(STM32_TRACEERR_BADSETADDRESS ),
+ TRACE_STR(STM32_TRACEERR_BADSETCONFIG ),
+ TRACE_STR(STM32_TRACEERR_BADSETFEATURE ),
+ TRACE_STR(STM32_TRACEERR_BADTESTMODE ),
+ TRACE_STR(STM32_TRACEERR_BINDFAILED ),
+ TRACE_STR(STM32_TRACEERR_DISPATCHSTALL ),
+ TRACE_STR(STM32_TRACEERR_DRIVER ),
+ TRACE_STR(STM32_TRACEERR_DRIVERREGISTERED),
+ TRACE_STR(STM32_TRACEERR_EP0NOSETUP ),
+ TRACE_STR(STM32_TRACEERR_EP0SETUPSTALLED ),
+ TRACE_STR(STM32_TRACEERR_EPINNULLPACKET ),
+ TRACE_STR(STM32_TRACEERR_EPINUNEXPECTED ),
+ TRACE_STR(STM32_TRACEERR_EPOUTNULLPACKET ),
+ TRACE_STR(STM32_TRACEERR_EPOUTUNEXPECTED ),
+ TRACE_STR(STM32_TRACEERR_INVALIDCTRLREQ ),
+ TRACE_STR(STM32_TRACEERR_INVALIDPARMS ),
+ TRACE_STR(STM32_TRACEERR_IRQREGISTRATION ),
+ TRACE_STR(STM32_TRACEERR_NOEP ),
+ TRACE_STR(STM32_TRACEERR_NOTCONFIGURED ),
+ TRACE_STR(STM32_TRACEERR_EPOUTQEMPTY ),
+ TRACE_STR(STM32_TRACEERR_EPINREQEMPTY ),
+ TRACE_STR(STM32_TRACEERR_NOOUTSETUP ),
+ TRACE_STR(STM32_TRACEERR_POLLTIMEOUT ),
+ TRACE_STR_END
+};
+#endif
+
+/* Interrupt event strings that may be enabled for more descriptive USB trace
+ * output.
+ */
+
+#ifdef CONFIG_USBDEV_TRACE_STRINGS
+const struct trace_msg_t g_usb_trace_strings_intdecode[] =
+{
+ TRACE_STR(STM32_TRACEINTID_USB ),
+ TRACE_STR(STM32_TRACEINTID_INTPENDING ),
+ TRACE_STR(STM32_TRACEINTID_EPOUT ),
+ TRACE_STR(STM32_TRACEINTID_EPIN ),
+ TRACE_STR(STM32_TRACEINTID_MISMATCH ),
+ TRACE_STR(STM32_TRACEINTID_WAKEUP ),
+ TRACE_STR(STM32_TRACEINTID_SUSPEND ),
+ TRACE_STR(STM32_TRACEINTID_SOF ),
+ TRACE_STR(STM32_TRACEINTID_RXFIFO ),
+ TRACE_STR(STM32_TRACEINTID_DEVRESET ),
+ TRACE_STR(STM32_TRACEINTID_ENUMDNE ),
+ TRACE_STR(STM32_TRACEINTID_IISOIXFR ),
+ TRACE_STR(STM32_TRACEINTID_IISOOXFR ),
+ TRACE_STR(STM32_TRACEINTID_SRQ ),
+ TRACE_STR(STM32_TRACEINTID_OTG ),
+ TRACE_STR(STM32_TRACEINTID_EPOUT_XFRC ),
+ TRACE_STR(STM32_TRACEINTID_EPOUT_EPDISD),
+ TRACE_STR(STM32_TRACEINTID_EPOUT_SETUP ),
+ TRACE_STR(STM32_TRACEINTID_DISPATCH ),
+ TRACE_STR(STM32_TRACEINTID_GETSTATUS ),
+ TRACE_STR(STM32_TRACEINTID_EPGETSTATUS ),
+ TRACE_STR(STM32_TRACEINTID_DEVGETSTATUS),
+ TRACE_STR(STM32_TRACEINTID_IFGETSTATUS ),
+ TRACE_STR(STM32_TRACEINTID_CLEARFEATURE),
+ TRACE_STR(STM32_TRACEINTID_SETFEATURE ),
+ TRACE_STR(STM32_TRACEINTID_SETADDRESS ),
+ TRACE_STR(STM32_TRACEINTID_GETSETDESC ),
+ TRACE_STR(STM32_TRACEINTID_GETCONFIG ),
+ TRACE_STR(STM32_TRACEINTID_SETCONFIG ),
+ TRACE_STR(STM32_TRACEINTID_GETSETIF ),
+ TRACE_STR(STM32_TRACEINTID_SYNCHFRAME ),
+ TRACE_STR(STM32_TRACEINTID_EPIN_XFRC ),
+ TRACE_STR(STM32_TRACEINTID_EPIN_TOC ),
+ TRACE_STR(STM32_TRACEINTID_EPIN_ITTXFE ),
+ TRACE_STR(STM32_TRACEINTID_EPIN_EPDISD ),
+ TRACE_STR(STM32_TRACEINTID_EPIN_TXFE ),
+ TRACE_STR(STM32_TRACEINTID_EPIN_EMPWAIT),
+ TRACE_STR(STM32_TRACEINTID_OUTNAK ),
+ TRACE_STR(STM32_TRACEINTID_OUTRECVD ),
+ TRACE_STR(STM32_TRACEINTID_OUTDONE ),
+ TRACE_STR(STM32_TRACEINTID_SETUPDONE ),
+ TRACE_STR(STM32_TRACEINTID_SETUPRECVD ),
+ TRACE_STR_END
+};
+#endif
+
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: stm32_getreg
+ *
+ * Description:
+ * Get the contents of an STM32 register
+ *
+ ****************************************************************************/
+
+#if defined(CONFIG_STM32_USBDEV_REGDEBUG) && defined(CONFIG_DEBUG_FEATURES)
+static uint32_t stm32_getreg(uint32_t addr)
+{
+ static uint32_t prevaddr = 0;
+ static uint32_t preval = 0;
+ static uint32_t count = 0;
+
+ /* Read the value from the register */
+
+ uint32_t val = getreg32(addr);
+
+ /* Is this the same value that we read from the same register last time? Are
+ * we polling the register? If so, suppress some of the output.
+ */
+
+ if (addr == prevaddr && val == preval)
+ {
+ if (count == 0xffffffff || ++count > 3)
+ {
+ if (count == 4)
+ {
+ llerr("...\n");
+ }
+
+ return val;
+ }
+ }
+
+ /* No this is a new address or value */
+
+ else
+ {
+ /* Did we print "..." for the previous value? */
+
+ if (count > 3)
+ {
+ /* Yes.. then show how many times the value repeated */
+
+ llerr("[repeats %d more times]\n", count-3);
+ }
+
+ /* Save the new address, value, and count */
+
+ prevaddr = addr;
+ preval = val;
+ count = 1;
+ }
+
+ /* Show the register value read */
+
+ llerr("%08x->%08x\n", addr, val);
+ return val;
+}
+#endif
+
+/****************************************************************************
+ * Name: stm32_putreg
+ *
+ * Description:
+ * Set the contents of an STM32 register to a value
+ *
+ ****************************************************************************/
+
+#if defined(CONFIG_STM32_USBDEV_REGDEBUG) && defined(CONFIG_DEBUG_FEATURES)
+static void stm32_putreg(uint32_t val, uint32_t addr)
+{
+ /* Show the register value being written */
+
+ llerr("%08x<-%08x\n", addr, val);
+
+ /* Write the value */
+
+ putreg32(val, addr);
+}
+#endif
+
+/****************************************************************************
+ * Name: stm32_req_remfirst
+ *
+ * Description:
+ * Remove a request from the head of an endpoint request queue
+ *
+ ****************************************************************************/
+
+static FAR struct stm32_req_s *stm32_req_remfirst(FAR struct stm32_ep_s *privep)
+{
+ FAR struct stm32_req_s *ret = privep->head;
+
+ if (ret)
+ {
+ privep->head = ret->flink;
+ if (!privep->head)
+ {
+ privep->tail = NULL;
+ }
+
+ ret->flink = NULL;
+ }
+
+ return ret;
+}
+
+/****************************************************************************
+ * Name: stm32_req_addlast
+ *
+ * Description:
+ * Add a request to the end of an endpoint request queue
+ *
+ ****************************************************************************/
+
+static bool stm32_req_addlast(FAR struct stm32_ep_s *privep,
+ FAR struct stm32_req_s *req)
+{
+ bool is_empty = !privep->head;
+
+ req->flink = NULL;
+ if (is_empty)
+ {
+ privep->head = req;
+ privep->tail = req;
+ }
+ else
+ {
+ privep->tail->flink = req;
+ privep->tail = req;
+ }
+ return is_empty;
+}
+
+/****************************************************************************
+ * Name: stm32_ep0in_setupresponse
+ *
+ * Description:
+ * Schedule a short transfer on Endpoint 0 (IN or OUT)
+ *
+ ****************************************************************************/
+
+static void stm32_ep0in_setupresponse(FAR struct stm32_usbdev_s *priv,
+ FAR uint8_t *buf, uint32_t nbytes)
+{
+ stm32_epin_transfer(&priv->epin[EP0], buf, nbytes);
+ priv->ep0state = EP0STATE_SETUPRESPONSE;
+ stm32_ep0out_ctrlsetup(priv);
+}
+
+/****************************************************************************
+ * Name: stm32_ep0in_transmitzlp
+ *
+ * Description:
+ * Send a zero length packet (ZLP) on endpoint 0 IN
+ *
+ ****************************************************************************/
+
+static inline void stm32_ep0in_transmitzlp(FAR struct stm32_usbdev_s *priv)
+{
+ stm32_ep0in_setupresponse(priv, NULL, 0);
+}
+
+/****************************************************************************
+ * Name: stm32_ep0in_activate
+ *
+ * Description:
+ * Activate the endpoint 0 IN endpoint.
+ *
+ ****************************************************************************/
+
+static void stm32_ep0in_activate(void)
+{
+ uint32_t regval;
+
+ /* Set the max packet size of the IN EP. */
+
+ regval = stm32_getreg(STM32_OTG_DIEPCTL0);
+ regval &= ~OTG_DIEPCTL0_MPSIZ_MASK;
+
+#if CONFIG_USBDEV_EP0_MAXSIZE == 8
+ regval |= OTG_DIEPCTL0_MPSIZ_8;
+#elif CONFIG_USBDEV_EP0_MAXSIZE == 16
+ regval |= OTG_DIEPCTL0_MPSIZ_16;
+#elif CONFIG_USBDEV_EP0_MAXSIZE == 32
+ regval |= OTG_DIEPCTL0_MPSIZ_32;
+#elif CONFIG_USBDEV_EP0_MAXSIZE == 64
+ regval |= OTG_DIEPCTL0_MPSIZ_64;
+#else
+# error "Unsupported value of CONFIG_USBDEV_EP0_MAXSIZE"
+#endif
+
+ stm32_putreg(regval, STM32_OTG_DIEPCTL0);
+
+ /* Clear global IN NAK */
+
+ regval = stm32_getreg(STM32_OTG_DCTL);
+ regval |= OTG_DCTL_CGINAK;
+ stm32_putreg(regval, STM32_OTG_DCTL);
+}
+
+/****************************************************************************
+ * Name: stm32_ep0out_ctrlsetup
+ *
+ * Description:
+ * Setup to receive a SETUP packet.
+ *
+ ****************************************************************************/
+
+static void stm32_ep0out_ctrlsetup(FAR struct stm32_usbdev_s *priv)
+{
+ uint32_t regval;
+
+ /* Setup the hardware to perform the SETUP transfer */
+
+ regval = (USB_SIZEOF_CTRLREQ * 3 << OTG_DOEPTSIZ0_XFRSIZ_SHIFT) |
+ (OTG_DOEPTSIZ0_PKTCNT) |
+ (3 << OTG_DOEPTSIZ0_STUPCNT_SHIFT);
+ stm32_putreg(regval, STM32_OTG_DOEPTSIZ0);
+
+ /* Then clear NAKing and enable the transfer */
+
+ regval = stm32_getreg(STM32_OTG_DOEPCTL0);
+ regval |= (OTG_DOEPCTL0_CNAK | OTG_DOEPCTL0_EPENA);
+ stm32_putreg(regval, STM32_OTG_DOEPCTL0);
+}
+
+/****************************************************************************
+ * Name: stm32_txfifo_write
+ *
+ * Description:
+ * Send data to the endpoint's TxFIFO.
+ *
+ ****************************************************************************/
+
+static void stm32_txfifo_write(FAR struct stm32_ep_s *privep,
+ FAR uint8_t *buf, int nbytes)
+{
+ uint32_t regaddr;
+ uint32_t regval;
+ int nwords;
+ int i;
+
+ /* Convert the number of bytes to words */
+
+ nwords = (nbytes + 3) >> 2;
+
+ /* Get the TxFIFO for this endpoint (same as the endpoint number) */
+
+ regaddr = STM32_OTG_DFIFO_DEP(privep->epphy);
+
+ /* Then transfer each word to the TxFIFO */
+
+ for (i = 0; i < nwords; i++)
+ {
+ /* Read four bytes from the source buffer (to avoid unaligned accesses)
+ * and pack these into one 32-bit word (little endian).
+ */
+
+ regval = (uint32_t)*buf++;
+ regval |= ((uint32_t)*buf++) << 8;
+ regval |= ((uint32_t)*buf++) << 16;
+ regval |= ((uint32_t)*buf++) << 24;
+
+ /* Then write the packet data to the TxFIFO */
+
+ stm32_putreg(regval, regaddr);
+ }
+}
+
+/****************************************************************************
+ * Name: stm32_epin_transfer
+ *
+ * Description:
+ * Start the Tx data transfer
+ *
+ ****************************************************************************/
+
+static void stm32_epin_transfer(FAR struct stm32_ep_s *privep,
+ FAR uint8_t *buf, int nbytes)
+{
+ uint32_t pktcnt;
+ uint32_t regval;
+
+ /* Read the DIEPSIZx register */
+
+ regval = stm32_getreg(STM32_OTG_DIEPTSIZ(privep->epphy));
+
+ /* Clear the XFRSIZ, PKTCNT, and MCNT field of the DIEPSIZx register */
+
+ regval &= ~(OTG_DIEPTSIZ_XFRSIZ_MASK | OTG_DIEPTSIZ_PKTCNT_MASK |
+ OTG_DIEPTSIZ_MCNT_MASK);
+
+ /* Are we sending a zero length packet (ZLP) */
+
+ if (nbytes == 0)
+ {
+ /* Yes.. leave the transfer size at zero and set the packet count to 1 */
+
+ pktcnt = 1;
+ }
+ else
+ {
+ /* No.. Program the transfer size and packet count . First calculate:
+ *
+ * xfrsize = The total number of bytes to be sent.
+ * pktcnt = the number of packets (of maxpacket bytes) required to
+ * perform the transfer.
+ */
+
+ pktcnt = ((uint32_t)nbytes + (privep->ep.maxpacket - 1)) / privep->ep.maxpacket;
+ }
+
+ /* Set the XFRSIZ and PKTCNT */
+
+ regval |= (pktcnt << OTG_DIEPTSIZ_PKTCNT_SHIFT);
+ regval |= ((uint32_t)nbytes << OTG_DIEPTSIZ_XFRSIZ_SHIFT);
+
+ /* If this is an isochronous endpoint, then set the multi-count field to
+ * the PKTCNT as well.
+ */
+
+ if (privep->eptype == USB_EP_ATTR_XFER_ISOC)
+ {
+ regval |= (pktcnt << OTG_DIEPTSIZ_MCNT_SHIFT);
+ }
+
+ /* Save DIEPSIZx register value */
+
+ stm32_putreg(regval, STM32_OTG_DIEPTSIZ(privep->epphy));
+
+ /* Read the DIEPCTLx register */
+
+ regval = stm32_getreg(STM32_OTG_DIEPCTL(privep->epphy));
+
+ /* If this is an isochronous endpoint, then set the even/odd frame bit
+ * the DIEPCTLx register.
+ */
+
+ if (privep->eptype == USB_EP_ATTR_XFER_ISOC)
+ {
+ /* Check bit 0 of the frame number of the received SOF and set the
+ * even/odd frame to match.
+ */
+
+ uint32_t status = stm32_getreg(STM32_OTG_DSTS);
+ if ((status & OTG_DSTS_SOFFN0) == OTG_DSTS_SOFFN_EVEN)
+ {
+ regval |= OTG_DIEPCTL_SEVNFRM;
+ }
+ else
+ {
+ regval |= OTG_DIEPCTL_SODDFRM;
+ }
+ }
+
+ /* EP enable, IN data in FIFO */
+
+ regval &= ~OTG_DIEPCTL_EPDIS;
+ regval |= (OTG_DIEPCTL_CNAK | OTG_DIEPCTL_EPENA);
+ stm32_putreg(regval, STM32_OTG_DIEPCTL(privep->epphy));
+
+ /* Transfer the data to the TxFIFO. At this point, the caller has already
+ * assured that there is sufficient space in the TxFIFO to hold the transfer
+ * we can just blindly continue.
+ */
+
+ stm32_txfifo_write(privep, buf, nbytes);
+}
+
+/****************************************************************************
+ * Name: stm32_epin_request
+ *
+ * Description:
+ * Begin or continue write request processing.
+ *
+ ****************************************************************************/
+
+static void stm32_epin_request(FAR struct stm32_usbdev_s *priv,
+ FAR struct stm32_ep_s *privep)
+{
+ struct stm32_req_s *privreq;
+ uint32_t regaddr;
+ uint32_t regval;
+ uint8_t *buf;
+ int nbytes;
+ int nwords;
+ int bytesleft;
+
+ /* We get here in one of four possible ways. From three interrupting
+ * events:
+ *
+ * 1. From stm32_epin as part of the transfer complete interrupt processing
+ * This interrupt indicates that the last transfer has completed.
+ * 2. As part of the ITTXFE interrupt processing. That interrupt indicates
+ * that an IN token was received when the associated TxFIFO was empty.
+ * 3. From stm32_epin_txfifoempty as part of the TXFE interrupt processing.
+ * The TXFE interrupt is only enabled when the TxFIFO is full and the
+ * software must wait for space to become available in the TxFIFO.
+ *
+ * And this function may be called immediately when the write request is
+ * queue to start up the next transaction.
+ *
+ * 4. From stm32_ep_submit when a new write request is received WHILE the
+ * endpoint is not active (privep->active == false).
+ */
+
+ /* Check the request from the head of the endpoint request queue */
+
+ privreq = stm32_rqpeek(privep);
+ if (!privreq)
+ {
+ usbtrace(TRACE_DEVERROR(STM32_TRACEERR_EPINREQEMPTY), privep->epphy);
+
+ /* There is no TX transfer in progress and no new pending TX
+ * requests to send. To stop transmitting any data on a particular
+ * IN endpoint, the application must set the IN NAK bit. To set this
+ * bit, the following field must be programmed.
+ */
+
+ regaddr = STM32_OTG_DIEPCTL(privep->epphy);
+ regval = stm32_getreg(regaddr);
+ regval |= OTG_DIEPCTL_SNAK;
+ stm32_putreg(regval, regaddr);
+
+ /* The endpoint is no longer active */
+
+ privep->active = false;
+ return;
+ }
+
+ ullinfo("EP%d req=%p: len=%d xfrd=%d zlp=%d\n",
+ privep->epphy, privreq, privreq->req.len,
+ privreq->req.xfrd, privep->zlp);
+
+ /* Check for a special case: If we are just starting a request (xfrd==0) and
+ * the class driver is trying to send a zero-length packet (len==0). Then set
+ * the ZLP flag so that the packet will be sent.
+ */
+
+ if (privreq->req.len == 0)
+ {
+ /* The ZLP flag is set TRUE whenever we want to force the driver to
+ * send a zero-length-packet on the next pass through the loop (below).
+ * The flag is cleared whenever a packet is sent in the loop below.
+ */
+
+ privep->zlp = true;
+ }
+
+ /* Add one more packet to the TxFIFO. We will wait for the transfer
+ * complete event before we add the next packet (or part of a packet
+ * to the TxFIFO).
+ *
+ * The documentation says that we can can multiple packets to the TxFIFO,
+ * but it seems that we need to get the transfer complete event before
+ * we can add the next (or maybe I have got something wrong?)
+ */
+
+#if 0
+ while (privreq->req.xfrd < privreq->req.len || privep->zlp)
+#else
+ if (privreq->req.xfrd < privreq->req.len || privep->zlp)
+#endif
+ {
+ /* Get the number of bytes left to be sent in the request */
+
+ bytesleft = privreq->req.len - privreq->req.xfrd;
+ nbytes = bytesleft;
+
+ /* Assume no zero-length-packet on the next pass through this loop */
+
+ privep->zlp = false;
+
+ /* Limit the size of the transfer to one full packet and handle
+ * zero-length packets (ZLPs).
+ */
+
+ if (nbytes > 0)
+ {
+ /* Either send the maxpacketsize or all of the remaining data in
+ * the request.
+ */
+
+ if (nbytes >= privep->ep.maxpacket)
+ {
+ nbytes = privep->ep.maxpacket;
+
+ /* Handle the case where this packet is exactly the
+ * maxpacketsize. Do we need to send a zero-length packet
+ * in this case?
+ */
+
+ if (bytesleft == privep->ep.maxpacket &&
+ (privreq->req.flags & USBDEV_REQFLAGS_NULLPKT) != 0)
+ {
+ /* The ZLP flag is set TRUE whenever we want to force
+ * the driver to send a zero-length-packet on the next
+ * pass through this loop. The flag is cleared (above)
+ * whenever we are committed to sending any packet and
+ * set here when we want to force one more pass through
+ * the loop.
+ */
+
+ privep->zlp = true;
+ }
+ }
+ }
+
+ /* Get the transfer size in 32-bit words */
+
+ nwords = (nbytes + 3) >> 2;
+
+ /* Get the number of 32-bit words available in the TxFIFO. The
+ * DXTFSTS indicates the amount of free space available in the
+ * endpoint TxFIFO. Values are in terms of 32-bit words:
+ *
+ * 0: Endpoint TxFIFO is full
+ * 1: 1 word available
+ * 2: 2 words available
+ * n: n words available
+ */
+
+ regaddr = STM32_OTG_DTXFSTS(privep->epphy);
+
+ /* Check for space in the TxFIFO. If space in the TxFIFO is not
+ * available, then set up an interrupt to resume the transfer when
+ * the TxFIFO is empty.
+ */
+
+ regval = stm32_getreg(regaddr);
+ if ((int)(regval & OTG_DTXFSTS_MASK) < nwords)
+ {
+ usbtrace(TRACE_INTDECODE(STM32_TRACEINTID_EPIN_EMPWAIT), (uint16_t)regval);
+
+ /* There is insufficient space in the TxFIFO. Wait for a TxFIFO
+ * empty interrupt and try again.
+ */
+
+ uint32_t empmsk = stm32_getreg(STM32_OTG_DIEPEMPMSK);
+ empmsk |= OTG_DIEPEMPMSK(privep->epphy);
+ stm32_putreg(empmsk, STM32_OTG_DIEPEMPMSK);
+
+ /* Terminate the transfer. We will try again when the TxFIFO empty
+ * interrupt is received.
+ */
+
+ return;
+ }
+
+ /* Transfer data to the TxFIFO */
+
+ buf = privreq->req.buf + privreq->req.xfrd;
+ stm32_epin_transfer(privep, buf, nbytes);
+
+ /* If it was not before, the OUT endpoint is now actively transferring
+ * data.
+ */
+
+ privep->active = true;
+
+ /* EP0 is a special case */
+
+ if (privep->epphy == EP0)
+ {
+ priv->ep0state = EP0STATE_DATA_IN;
+ }
+
+ /* Update for the next time through the loop */
+
+ privreq->req.xfrd += nbytes;
+ }
+
+ /* Note that the ZLP, if any, must be sent as a separate transfer. The need
+ * for a ZLP is indicated by privep->zlp. If all of the bytes were sent
+ * (including any final null packet) then we are finished with the transfer
+ */
+
+ if (privreq->req.xfrd >= privreq->req.len && !privep->zlp)
+ {
+ usbtrace(TRACE_COMPLETE(privep->epphy), privreq->req.xfrd);
+
+ /* We are finished with the request (although the transfer has not
+ * yet completed).
+ */
+
+ stm32_req_complete(privep, OK);
+ }
+}
+
+/****************************************************************************
+ * Name: stm32_rxfifo_read
+ *
+ * Description:
+ * Read packet from the RxFIFO into a read request.
+ *
+ ****************************************************************************/
+
+static void stm32_rxfifo_read(FAR struct stm32_ep_s *privep,
+ FAR uint8_t *dest, uint16_t len)
+{
+ uint32_t regaddr;
+ int i;
+
+ /* Get the address of the RxFIFO. Note: there is only one RxFIFO so
+ * we might as well use the address associated with EP0.
+ */
+
+ regaddr = STM32_OTG_DFIFO_DEP(EP0);
+
+ /* Read 32-bits and write 4 x 8-bits at time (to avoid unaligned accesses) */
+
+ for (i = 0; i < len; i += 4)
+ {
+ union
+ {
+ uint32_t w;
+ uint8_t b[4];
+ } data;
+
+ /* Read 1 x 32-bits of EP0 packet data */
+
+ data.w = stm32_getreg(regaddr);
+
+ /* Write 4 x 8-bits of EP0 packet data */
+
+ *dest++ = data.b[0];
+ *dest++ = data.b[1];
+ *dest++ = data.b[2];
+ *dest++ = data.b[3];
+ }
+}
+
+/****************************************************************************
+ * Name: stm32_rxfifo_discard
+ *
+ * Description:
+ * Discard packet data from the RxFIFO.
+ *
+ ****************************************************************************/
+
+static void stm32_rxfifo_discard(FAR struct stm32_ep_s *privep, int len)
+{
+ if (len > 0)
+ {
+ uint32_t regaddr;
+ int i;
+
+ /* Get the address of the RxFIFO Note: there is only one RxFIFO so
+ * we might as well use the address associated with EP0.
+ */
+
+ regaddr = STM32_OTG_DFIFO_DEP(EP0);
+
+ /* Read 32-bits at time */
+
+ for (i = 0; i < len; i += 4)
+ {
+ volatile uint32_t data = stm32_getreg(regaddr);
+ (void)data;
+ }
+ }
+}
+
+/****************************************************************************
+ * Name: stm32_epout_complete
+ *
+ * Description:
+ * This function is called when an OUT transfer complete interrupt is
+ * received. It completes the read request at the head of the endpoint's
+ * request queue.
+ *
+ ****************************************************************************/
+
+static void stm32_epout_complete(FAR struct stm32_usbdev_s *priv,
+ FAR struct stm32_ep_s *privep)
+{
+ struct stm32_req_s *privreq;
+
+ /* Since a transfer just completed, there must be a read request at the head of
+ * the endpoint request queue.
+ */
+
+ privreq = stm32_rqpeek(privep);
+ DEBUGASSERT(privreq);
+
+ if (!privreq)
+ {
+ /* An OUT transfer completed, but no packet to receive the data. This
+ * should not happen.
+ */
+
+ usbtrace(TRACE_DEVERROR(STM32_TRACEERR_EPOUTQEMPTY), privep->epphy);
+ privep->active = false;
+ return;
+ }
+
+ ullinfo("EP%d: len=%d xfrd=%d\n",
+ privep->epphy, privreq->req.len, privreq->req.xfrd);
+
+ /* Return the completed read request to the class driver and mark the state
+ * IDLE.
+ */
+
+ usbtrace(TRACE_COMPLETE(privep->epphy), privreq->req.xfrd);
+ stm32_req_complete(privep, OK);
+ privep->active = false;
+
+ /* Now set up the next read request (if any) */
+
+ stm32_epout_request(priv, privep);
+}
+
+/****************************************************************************
+ * Name: stm32_ep0out_receive
+ *
+ * Description:
+ * This function is called from the RXFLVL interrupt handler when new incoming
+ * data is available in the endpoint's RxFIFO. This function will simply
+ * copy the incoming data into pending request's data buffer.
+ *
+ ****************************************************************************/
+
+static inline void stm32_ep0out_receive(FAR struct stm32_ep_s *privep, int bcnt)
+{
+ FAR struct stm32_usbdev_s *priv;
+
+ /* Sanity Checking */
+
+ DEBUGASSERT(privep && privep->ep.priv);
+ priv = (FAR struct stm32_usbdev_s *)privep->ep.priv;
+
+ ullinfo("EP0: bcnt=%d\n", bcnt);
+ usbtrace(TRACE_READ(EP0), bcnt);
+
+ /* Verify that an OUT SETUP request as received before this data was
+ * received in the RxFIFO.
+ */
+
+ if (priv->ep0state == EP0STATE_SETUP_OUT)
+ {
+ /* Read the data into our special buffer for SETUP data */
+
+ int readlen = MIN(CONFIG_USBDEV_SETUP_MAXDATASIZE, bcnt);
+ stm32_rxfifo_read(privep, priv->ep0data, readlen);
+
+ /* Do we have to discard any excess bytes? */
+
+ stm32_rxfifo_discard(privep, bcnt - readlen);
+
+ /* Now we can process the setup command */
+
+ privep->active = false;
+ priv->ep0state = EP0STATE_SETUP_READY;
+ priv->ep0datlen = readlen;
+
+ stm32_ep0out_setup(priv);
+ }
+ else
+ {
+ /* This is an error. We don't have any idea what to do with the EP0
+ * data in this case. Just read and discard it so that the RxFIFO
+ * does not become constipated.
+ */
+
+ usbtrace(TRACE_DEVERROR(STM32_TRACEERR_NOOUTSETUP), priv->ep0state);
+ stm32_rxfifo_discard(privep, bcnt);
+ privep->active = false;
+ }
+}
+
+/****************************************************************************
+ * Name: stm32_epout_receive
+ *
+ * Description:
+ * This function is called from the RXFLVL interrupt handler when new incoming
+ * data is available in the endpoint's RxFIFO. This function will simply
+ * copy the incoming data into pending request's data buffer.
+ *
+ ****************************************************************************/
+
+static inline void stm32_epout_receive(FAR struct stm32_ep_s *privep, int bcnt)
+{
+ struct stm32_req_s *privreq;
+ uint8_t *dest;
+ int buflen;
+ int readlen;
+
+ /* Get a reference to the request at the head of the endpoint's request
+ * queue.
+ */
+
+ privreq = stm32_rqpeek(privep);
+ if (!privreq)
+ {
+ /* Incoming data is available in the RxFIFO, but there is no read setup
+ * to receive the receive the data. This should not happen for data
+ * endpoints; those endpoints should have been NAKing any OUT data tokens.
+ *
+ * We should get here normally on OUT data phase following an OUT
+ * SETUP command. EP0 data will still receive data in this case and it
+ * should not be NAKing.
+ */
+
+ if (privep->epphy == 0)
+ {
+ stm32_ep0out_receive(privep, bcnt);
+ }
+ else
+ {
+ /* Otherwise, the data is lost. This really should not happen if
+ * NAKing is working as expected.
+ */
+
+ usbtrace(TRACE_DEVERROR(STM32_TRACEERR_EPOUTQEMPTY), privep->epphy);
+
+ /* Discard the data in the RxFIFO */
+
+ stm32_rxfifo_discard(privep, bcnt);
+ }
+
+ privep->active = false;
+ return;
+ }
+
+ ullinfo("EP%d: len=%d xfrd=%d\n", privep->epphy, privreq->req.len, privreq->req.xfrd);
+ usbtrace(TRACE_READ(privep->epphy), bcnt);
+
+ /* Get the number of bytes to transfer from the RxFIFO */
+
+ buflen = privreq->req.len - privreq->req.xfrd;
+ DEBUGASSERT(buflen > 0 && buflen >= bcnt);
+ readlen = MIN(buflen, bcnt);
+
+ /* Get the destination of the data transfer */
+
+ dest = privreq->req.buf + privreq->req.xfrd;
+
+ /* Transfer the data from the RxFIFO to the request's data buffer */
+
+ stm32_rxfifo_read(privep, dest, readlen);
+
+ /* If there were more bytes in the RxFIFO than could be held in the read
+ * request, then we will have to discard those.
+ */
+
+ stm32_rxfifo_discard(privep, bcnt - readlen);
+
+ /* Update the number of bytes transferred */
+
+ privreq->req.xfrd += readlen;
+}
+
+/****************************************************************************
+ * Name: stm32_epout_request
+ *
+ * Description:
+ * This function is called when either (1) new read request is received, or
+ * (2) a pending receive request completes. If there is no read in pending,
+ * then this function will initiate the next OUT (read) operation.
+ *
+ ****************************************************************************/
+
+static void stm32_epout_request(FAR struct stm32_usbdev_s *priv,
+ FAR struct stm32_ep_s *privep)
+{
+ struct stm32_req_s *privreq;
+ uint32_t regaddr;
+ uint32_t regval;
+ uint32_t xfrsize;
+ uint32_t pktcnt;
+
+ /* Make sure that there is not already a pending request request. If there is,
+ * just return, leaving the newly received request in the request queue.
+ */
+
+ if (!privep->active)
+ {
+ /* Loop until a valid request is found (or the request queue is empty).
+ * The loop is only need to look at the request queue again is an invalid
+ * read request is encountered.
+ */
+
+ for (; ; )
+ {
+ /* Get a reference to the request at the head of the endpoint's request queue */
+
+ privreq = stm32_rqpeek(privep);
+ if (!privreq)
+ {
+ usbtrace(TRACE_DEVERROR(STM32_TRACEERR_EPOUTQEMPTY), privep->epphy);
+
+ /* There are no read requests to be setup. Configure the hardware to
+ * NAK any incoming packets. (This should already be the case. I
+ * think that the hardware will automatically NAK after a transfer is
+ * completed until SNAK is cleared).
+ */
+
+ regaddr = STM32_OTG_DOEPCTL(privep->epphy);
+ regval = stm32_getreg(regaddr);
+ regval |= OTG_DOEPCTL_SNAK;
+ stm32_putreg(regval, regaddr);
+
+ /* This endpoint is no longer actively transferring */
+
+ privep->active = false;
+ return;
+ }
+
+ ullinfo("EP%d: len=%d\n", privep->epphy, privreq->req.len);
+
+ /* Ignore any attempt to receive a zero length packet (this really
+ * should not happen.
+ */
+
+ if (privreq->req.len <= 0)
+ {
+ usbtrace(TRACE_DEVERROR(STM32_TRACEERR_EPOUTNULLPACKET), 0);
+ stm32_req_complete(privep, OK);
+ }
+
+ /* Otherwise, we have a usable read request... break out of the loop */
+
+ else
+ {
+ break;
+ }
+ }
+
+ /* Setup the pending read into the request buffer. First calculate:
+ *
+ * pktcnt = the number of packets (of maxpacket bytes) required to
+ * perform the transfer.
+ * xfrsize = The total number of bytes required (in units of
+ * maxpacket bytes).
+ */
+
+ pktcnt = (privreq->req.len + (privep->ep.maxpacket - 1)) / privep->ep.maxpacket;
+ xfrsize = pktcnt * privep->ep.maxpacket;
+
+ /* Then setup the hardware to perform this transfer */
+
+ regaddr = STM32_OTG_DOEPTSIZ(privep->epphy);
+ regval = stm32_getreg(regaddr);
+ regval &= ~(OTG_DOEPTSIZ_XFRSIZ_MASK | OTG_DOEPTSIZ_PKTCNT_MASK);
+ regval |= (xfrsize << OTG_DOEPTSIZ_XFRSIZ_SHIFT);
+ regval |= (pktcnt << OTG_DOEPTSIZ_PKTCNT_SHIFT);
+ stm32_putreg(regval, regaddr);
+
+ /* Then enable the transfer */
+
+ regaddr = STM32_OTG_DOEPCTL(privep->epphy);
+ regval = stm32_getreg(regaddr);
+
+ /* When an isochronous transfer is enabled the Even/Odd frame bit must
+ * also be set appropriately.
+ */
+
+#ifdef CONFIG_USBDEV_ISOCHRONOUS
+ if (privep->eptype == USB_EP_ATTR_XFER_ISOC)
+ {
+ if (privep->odd)
+ {
+ regval |= OTG_DOEPCTL_SODDFRM;
+ }
+ else
+ {
+ regval |= OTG_DOEPCTL_SEVNFRM;
+ }
+ }
+#endif
+
+ /* Clearing NAKing and enable the transfer. */
+
+ regval |= (OTG_DOEPCTL_CNAK | OTG_DOEPCTL_EPENA);
+ stm32_putreg(regval, regaddr);
+
+ /* A transfer is now active on this endpoint */
+
+ privep->active = true;
+
+ /* EP0 is a special case. We need to know when to switch back to
+ * normal SETUP processing.
+ */
+
+ if (privep->epphy == EP0)
+ {
+ priv->ep0state = EP0STATE_DATA_OUT;
+ }
+ }
+}
+
+/****************************************************************************
+ * Name: stm32_ep_flush
+ *
+ * Description:
+ * Flush any primed descriptors from this ep
+ *
+ ****************************************************************************/
+
+static void stm32_ep_flush(struct stm32_ep_s *privep)
+{
+ if (privep->isin)
+ {
+ stm32_txfifo_flush(OTG_GRSTCTL_TXFNUM_D(privep->epphy));
+ }
+ else
+ {
+ stm32_rxfifo_flush();
+ }
+}
+
+/****************************************************************************
+ * Name: stm32_req_complete
+ *
+ * Description:
+ * Handle termination of the request at the head of the endpoint request queue.
+ *
+ ****************************************************************************/
+
+static void stm32_req_complete(struct stm32_ep_s *privep, int16_t result)
+{
+ FAR struct stm32_req_s *privreq;
+
+ /* Remove the request at the head of the request list */
+
+ privreq = stm32_req_remfirst(privep);
+ DEBUGASSERT(privreq != NULL);
+
+ /* If endpoint 0, temporarily reflect the state of protocol stalled
+ * in the callback.
+ */
+
+ bool stalled = privep->stalled;
+ if (privep->epphy == EP0)
+ {
+ privep->stalled = privep->dev->stalled;
+ }
+
+ /* Save the result in the request structure */
+
+ privreq->req.result = result;
+
+ /* Callback to the request completion handler */
+
+ privreq->req.callback(&privep->ep, &privreq->req);
+
+ /* Restore the stalled indication */
+
+ privep->stalled = stalled;
+}
+
+/****************************************************************************
+ * Name: stm32_req_cancel
+ *
+ * Description:
+ * Cancel all pending requests for an endpoint
+ *
+ ****************************************************************************/
+
+static void stm32_req_cancel(struct stm32_ep_s *privep, int16_t status)
+{
+ if (!stm32_rqempty(privep))
+ {
+ stm32_ep_flush(privep);
+ }
+
+ while (!stm32_rqempty(privep))
+ {
+ usbtrace(TRACE_COMPLETE(privep->epphy),
+ (stm32_rqpeek(privep))->req.xfrd);
+ stm32_req_complete(privep, status);
+ }
+}
+
+/****************************************************************************
+ * Name: stm32_ep_findbyaddr
+ *
+ * Description:
+ * Find the physical endpoint structure corresponding to a logic endpoint
+ * address
+ *
+ ****************************************************************************/
+
+static struct stm32_ep_s *stm32_ep_findbyaddr(struct stm32_usbdev_s *priv,
+ uint16_t eplog)
+{
+ struct stm32_ep_s *privep;
+ uint8_t epphy = USB_EPNO(eplog);
+
+ if (epphy >= STM32_NENDPOINTS)
+ {
+ return NULL;
+ }
+
+ /* Is this an IN or an OUT endpoint? */
+
+ if (USB_ISEPIN(eplog))
+ {
+ privep = &priv->epin[epphy];
+ }
+ else
+ {
+ privep = &priv->epout[epphy];
+ }
+
+ /* Return endpoint reference */
+
+ DEBUGASSERT(privep->epphy == epphy);
+ return privep;
+}
+
+/****************************************************************************
+ * Name: stm32_req_dispatch
+ *
+ * Description:
+ * Provide unhandled setup actions to the class driver. This is logically part
+ * of the USB interrupt handler.
+ *
+ ****************************************************************************/
+
+static int stm32_req_dispatch(struct stm32_usbdev_s *priv,
+ const struct usb_ctrlreq_s *ctrl)
+{
+ int ret = -EIO;
+
+ usbtrace(TRACE_INTDECODE(STM32_TRACEINTID_DISPATCH), 0);
+ if (priv->driver)
+ {
+ /* Forward to the control request to the class driver implementation */
+
+ ret = CLASS_SETUP(priv->driver, &priv->usbdev, ctrl,
+ priv->ep0data, priv->ep0datlen);
+ }
+
+ if (ret < 0)
+ {
+ /* Stall on failure */
+
+ usbtrace(TRACE_DEVERROR(STM32_TRACEERR_DISPATCHSTALL), 0);
+ priv->stalled = true;
+ }
+
+ return ret;
+}
+
+/****************************************************************************
+ * Name: stm32_usbreset
+ *
+ * Description:
+ * Reset Usb engine
+ *
+ ****************************************************************************/
+
+static void stm32_usbreset(struct stm32_usbdev_s *priv)
+{
+ FAR struct stm32_ep_s *privep;
+ uint32_t regval;
+ int i;
+
+ /* Clear the Remote Wake-up Signaling */
+
+ regval = stm32_getreg(STM32_OTG_DCTL);
+ regval &= ~OTG_DCTL_RWUSIG;
+ stm32_putreg(regval, STM32_OTG_DCTL);
+
+ /* Flush the EP0 Tx FIFO */
+
+ stm32_txfifo_flush(OTG_GRSTCTL_TXFNUM_D(EP0));
+
+ /* Tell the class driver that we are disconnected. The class
+ * driver should then accept any new configurations.
+ */
+
+ if (priv->driver)
+ {
+ CLASS_DISCONNECT(priv->driver, &priv->usbdev);
+ }
+
+ /* Mark all endpoints as available */
+
+ priv->epavail[0] = STM32_EP_AVAILABLE;
+ priv->epavail[1] = STM32_EP_AVAILABLE;
+
+ /* Disable all end point interrupts */
+
+ for (i = 0; i < STM32_NENDPOINTS ; i++)
+ {
+ /* Disable endpoint interrupts */
+
+ stm32_putreg(0xff, STM32_OTG_DIEPINT(i));
+ stm32_putreg(0xff, STM32_OTG_DOEPINT(i));
+
+ /* Return write requests to the class implementation */
+
+ privep = &priv->epin[i];
+ stm32_req_cancel(privep, -ESHUTDOWN);
+
+ /* Reset IN endpoint status */
+
+ privep->stalled = false;
+
+ /* Return read requests to the class implementation */
+
+ privep = &priv->epout[i];
+ stm32_req_cancel(privep, -ESHUTDOWN);
+
+ /* Reset endpoint status */
+
+ privep->stalled = false;
+ }
+
+ stm32_putreg(0xffffffff, STM32_OTG_DAINT);
+
+ /* Mask all device endpoint interrupts except EP0 */
+
+ regval = (OTG_DAINT_IEP(EP0) | OTG_DAINT_OEP(EP0));
+ stm32_putreg(regval, STM32_OTG_DAINTMSK);
+
+ /* Unmask OUT interrupts */
+
+ regval = (OTG_DOEPMSK_XFRCM | OTG_DOEPMSK_STUPM | OTG_DOEPMSK_EPDM);
+ stm32_putreg(regval, STM32_OTG_DOEPMSK);
+
+ /* Unmask IN interrupts */
+
+ regval = (OTG_DIEPMSK_XFRCM | OTG_DIEPMSK_EPDM | OTG_DIEPMSK_TOM);
+ stm32_putreg(regval, STM32_OTG_DIEPMSK);
+
+ /* Reset device address to 0 */
+
+ stm32_setaddress(priv, 0);
+ priv->devstate = DEVSTATE_DEFAULT;
+ priv->usbdev.speed = USB_SPEED_FULL;
+
+ /* Re-configure EP0 */
+
+ stm32_ep0_configure(priv);
+
+ /* Setup EP0 to receive SETUP packets */
+
+ stm32_ep0out_ctrlsetup(priv);
+}
+
+/****************************************************************************
+ * Name: stm32_ep0out_testmode
+ *
+ * Description:
+ * Select test mode
+ *
+ ****************************************************************************/
+
+static inline void stm32_ep0out_testmode(FAR struct stm32_usbdev_s *priv,
+ uint16_t index)
+{
+ uint8_t testmode;
+
+ testmode = index >> 8;
+ switch (testmode)
+ {
+ case 1:
+ priv->testmode = OTG_TESTMODE_J;
+ break;
+
+ case 2:
+ priv->testmode = OTG_TESTMODE_K;
+ break;
+
+ case 3:
+ priv->testmode = OTG_TESTMODE_SE0_NAK;
+ break;
+
+ case 4:
+ priv->testmode = OTG_TESTMODE_PACKET;
+ break;
+
+ case 5:
+ priv->testmode = OTG_TESTMODE_FORCE;
+ break;
+
+ default:
+ usbtrace(TRACE_DEVERROR(STM32_TRACEERR_BADTESTMODE), testmode);
+ priv->dotest = false;
+ priv->testmode = OTG_TESTMODE_DISABLED;
+ priv->stalled = true;
+ }
+
+ priv->dotest = true;
+ stm32_ep0in_transmitzlp(priv);
+}
+
+/****************************************************************************
+ * Name: stm32_ep0out_stdrequest
+ *
+ * Description:
+ * Handle a stanard request on EP0. Pick off the things of interest to the
+ * USB device controller driver; pass what is left to the class driver.
+ *
+ ****************************************************************************/
+
+static inline void stm32_ep0out_stdrequest(struct stm32_usbdev_s *priv,
+ FAR struct stm32_ctrlreq_s *ctrlreq)
+{
+ FAR struct stm32_ep_s *privep;
+
+ /* Handle standard request */
+
+ switch (ctrlreq->req)
+ {
+ case USB_REQ_GETSTATUS:
+ {
+ /* type: device-to-host; recipient = device, interface, endpoint
+ * value: 0
+ * index: zero interface endpoint
+ * len: 2; data = status
+ */
+
+ usbtrace(TRACE_INTDECODE(STM32_TRACEINTID_GETSTATUS), 0);
+ if (!priv->addressed ||
+ ctrlreq->len != 2 ||
+ USB_REQ_ISOUT(ctrlreq->type) ||
+ ctrlreq->value != 0)
+ {
+ priv->stalled = true;
+ }
+ else
+ {
+ switch (ctrlreq->type & USB_REQ_RECIPIENT_MASK)
+ {
+ case USB_REQ_RECIPIENT_ENDPOINT:
+ {
+ usbtrace(TRACE_INTDECODE(STM32_TRACEINTID_EPGETSTATUS), 0);
+ privep = stm32_ep_findbyaddr(priv, ctrlreq->index);
+ if (!privep)
+ {
+ usbtrace(TRACE_DEVERROR(STM32_TRACEERR_BADEPGETSTATUS), 0);
+ priv->stalled = true;
+ }
+ else
+ {
+ if (privep->stalled)
+ {
+ priv->ep0data[0] = (1 << USB_FEATURE_ENDPOINTHALT);
+ }
+ else
+ {
+ priv->ep0data[0] = 0; /* Not stalled */
+ }
+
+ priv->ep0data[1] = 0;
+ stm32_ep0in_setupresponse(priv, priv->ep0data, 2);
+ }
+ }
+ break;
+
+ case USB_REQ_RECIPIENT_DEVICE:
+ {
+ if (ctrlreq->index == 0)
+ {
+ usbtrace(TRACE_INTDECODE(STM32_TRACEINTID_DEVGETSTATUS), 0);
+
+ /* Features: Remote Wakeup and self-powered */
+
+ priv->ep0data[0] = (priv->selfpowered << USB_FEATURE_SELFPOWERED);
+ priv->ep0data[0] |= (priv->wakeup << USB_FEATURE_REMOTEWAKEUP);
+ priv->ep0data[1] = 0;
+
+ stm32_ep0in_setupresponse(priv, priv->ep0data, 2);
+ }
+ else
+ {
+ usbtrace(TRACE_DEVERROR(STM32_TRACEERR_BADDEVGETSTATUS), 0);
+ priv->stalled = true;
+ }
+ }
+ break;
+
+ case USB_REQ_RECIPIENT_INTERFACE:
+ {
+ usbtrace(TRACE_INTDECODE(STM32_TRACEINTID_IFGETSTATUS), 0);
+ priv->ep0data[0] = 0;
+ priv->ep0data[1] = 0;
+
+ stm32_ep0in_setupresponse(priv, priv->ep0data, 2);
+ }
+ break;
+
+ default:
+ {
+ usbtrace(TRACE_DEVERROR(STM32_TRACEERR_BADGETSTATUS), 0);
+ priv->stalled = true;
+ }
+ break;
+ }
+ }
+ }
+ break;
+
+ case USB_REQ_CLEARFEATURE:
+ {
+ /* type: host-to-device; recipient = device, interface or endpoint
+ * value: feature selector
+ * index: zero interface endpoint;
+ * len: zero, data = none
+ */
+
+ usbtrace(TRACE_INTDECODE(STM32_TRACEINTID_CLEARFEATURE), 0);
+ if (priv->addressed != 0 && ctrlreq->len == 0)
+ {
+ uint8_t recipient = ctrlreq->type & USB_REQ_RECIPIENT_MASK;
+ if (recipient == USB_REQ_RECIPIENT_ENDPOINT &&
+ ctrlreq->value == USB_FEATURE_ENDPOINTHALT &&
+ (privep = stm32_ep_findbyaddr(priv, ctrlreq->index)) != NULL)
+ {
+ stm32_ep_clrstall(privep);
+ stm32_ep0in_transmitzlp(priv);
+ }
+ else if (recipient == USB_REQ_RECIPIENT_DEVICE &&
+ ctrlreq->value == USB_FEATURE_REMOTEWAKEUP)
+ {
+ priv->wakeup = 0;
+ stm32_ep0in_transmitzlp(priv);
+ }
+ else
+ {
+ /* Actually, I think we could just stall here. */
+
+ (void)stm32_req_dispatch(priv, &priv->ctrlreq);
+ }
+ }
+ else
+ {
+ usbtrace(TRACE_DEVERROR(STM32_TRACEERR_BADCLEARFEATURE), 0);
+ priv->stalled = true;
+ }
+ }
+ break;
+
+ case USB_REQ_SETFEATURE:
+ {
+ /* type: host-to-device; recipient = device, interface, endpoint
+ * value: feature selector
+ * index: zero interface endpoint;
+ * len: 0; data = none
+ */
+
+ usbtrace(TRACE_INTDECODE(STM32_TRACEINTID_SETFEATURE), 0);
+ if (priv->addressed != 0 && ctrlreq->len == 0)
+ {
+ uint8_t recipient = ctrlreq->type & USB_REQ_RECIPIENT_MASK;
+ if (recipient == USB_REQ_RECIPIENT_ENDPOINT &&
+ ctrlreq->value == USB_FEATURE_ENDPOINTHALT &&
+ (privep = stm32_ep_findbyaddr(priv, ctrlreq->index)) != NULL)
+ {
+ stm32_ep_setstall(privep);
+ stm32_ep0in_transmitzlp(priv);
+ }
+ else if (recipient == USB_REQ_RECIPIENT_DEVICE &&
+ ctrlreq->value == USB_FEATURE_REMOTEWAKEUP)
+ {
+ priv->wakeup = 1;
+ stm32_ep0in_transmitzlp(priv);
+ }
+ else if (recipient == USB_REQ_RECIPIENT_DEVICE &&
+ ctrlreq->value == USB_FEATURE_TESTMODE &&
+ ((ctrlreq->index & 0xff) == 0))
+ {
+ stm32_ep0out_testmode(priv, ctrlreq->index);
+ }
+ else if (priv->configured)
+ {
+ /* Actually, I think we could just stall here. */
+
+ (void)stm32_req_dispatch(priv, &priv->ctrlreq);
+ }
+ else
+ {
+ usbtrace(TRACE_DEVERROR(STM32_TRACEERR_BADSETFEATURE), 0);
+ priv->stalled = true;
+ }
+ }
+ else
+ {
+ usbtrace(TRACE_DEVERROR(STM32_TRACEERR_BADSETFEATURE), 0);
+ priv->stalled = true;
+ }
+ }
+ break;
+
+ case USB_REQ_SETADDRESS:
+ {
+ /* type: host-to-device; recipient = device
+ * value: device address
+ * index: 0
+ * len: 0; data = none
+ */
+
+ usbtrace(TRACE_INTDECODE(STM32_TRACEINTID_SETADDRESS), ctrlreq->value);
+ if ((ctrlreq->type & USB_REQ_RECIPIENT_MASK) == USB_REQ_RECIPIENT_DEVICE &&
+ ctrlreq->index == 0 &&
+ ctrlreq->len == 0 &&
+ ctrlreq->value < 128 &&
+ priv->devstate != DEVSTATE_CONFIGURED)
+ {
+ /* Save the address. We cannot actually change to the next address until
+ * the completion of the status phase.
+ */
+
+ stm32_setaddress(priv, (uint16_t)priv->ctrlreq.value[0]);
+ stm32_ep0in_transmitzlp(priv);
+ }
+ else
+ {
+ usbtrace(TRACE_DEVERROR(STM32_TRACEERR_BADSETADDRESS), 0);
+ priv->stalled = true;
+ }
+ }
+ break;
+
+ case USB_REQ_GETDESCRIPTOR:
+ /* type: device-to-host; recipient = device
+ * value: descriptor type and index
+ * index: 0 or language ID;
+ * len: descriptor len; data = descriptor
+ */
+
+ case USB_REQ_SETDESCRIPTOR:
+ /* type: host-to-device; recipient = device
+ * value: descriptor type and index
+ * index: 0 or language ID;
+ * len: descriptor len; data = descriptor
+ */
+
+ {
+ usbtrace(TRACE_INTDECODE(STM32_TRACEINTID_GETSETDESC), 0);
+ if ((ctrlreq->type & USB_REQ_RECIPIENT_MASK) == USB_REQ_RECIPIENT_DEVICE)
+ {
+ (void)stm32_req_dispatch(priv, &priv->ctrlreq);
+ }
+ else
+ {
+ usbtrace(TRACE_DEVERROR(STM32_TRACEERR_BADGETSETDESC), 0);
+ priv->stalled = true;
+ }
+ }
+ break;
+
+ case USB_REQ_GETCONFIGURATION:
+ /* type: device-to-host; recipient = device
+ * value: 0;
+ * index: 0;
+ * len: 1; data = configuration value
+ */
+
+ {
+ usbtrace(TRACE_INTDECODE(STM32_TRACEINTID_GETCONFIG), 0);
+ if (priv->addressed &&
+ (ctrlreq->type & USB_REQ_RECIPIENT_MASK) == USB_REQ_RECIPIENT_DEVICE &&
+ ctrlreq->value == 0 &&
+ ctrlreq->index == 0 &&
+ ctrlreq->len == 1)
+ {
+ (void)stm32_req_dispatch(priv, &priv->ctrlreq);
+ }
+ else
+ {
+ usbtrace(TRACE_DEVERROR(STM32_TRACEERR_BADGETCONFIG), 0);
+ priv->stalled = true;
+ }
+ }
+ break;
+
+ case USB_REQ_SETCONFIGURATION:
+ /* type: host-to-device; recipient = device
+ * value: configuration value
+ * index: 0;
+ * len: 0; data = none
+ */
+
+ {
+ usbtrace(TRACE_INTDECODE(STM32_TRACEINTID_SETCONFIG), 0);
+ if (priv->addressed &&
+ (ctrlreq->type & USB_REQ_RECIPIENT_MASK) == USB_REQ_RECIPIENT_DEVICE &&
+ ctrlreq->index == 0 &&
+ ctrlreq->len == 0)
+ {
+ /* Give the configuration to the class driver */
+
+ int ret = stm32_req_dispatch(priv, &priv->ctrlreq);
+
+ /* If the class driver accepted the configuration, then mark the
+ * device state as configured (or not, depending on the
+ * configuration).
+ */
+
+ if (ret == OK)
+ {
+ uint8_t cfg = (uint8_t)ctrlreq->value;
+ if (cfg != 0)
+ {
+ priv->devstate = DEVSTATE_CONFIGURED;
+ priv->configured = true;
+ }
+ else
+ {
+ priv->devstate = DEVSTATE_ADDRESSED;
+ priv->configured = false;
+ }
+ }
+ }
+ else
+ {
+ usbtrace(TRACE_DEVERROR(STM32_TRACEERR_BADSETCONFIG), 0);
+ priv->stalled = true;
+ }
+ }
+ break;
+
+ case USB_REQ_GETINTERFACE:
+ /* type: device-to-host; recipient = interface
+ * value: 0
+ * index: interface;
+ * len: 1; data = alt interface
+ */
+
+ case USB_REQ_SETINTERFACE:
+ /* type: host-to-device; recipient = interface
+ * value: alternate setting
+ * index: interface;
+ * len: 0; data = none
+ */
+
+ {
+ usbtrace(TRACE_INTDECODE(STM32_TRACEINTID_GETSETIF), 0);
+ (void)stm32_req_dispatch(priv, &priv->ctrlreq);
+ }
+ break;
+
+ case USB_REQ_SYNCHFRAME:
+ /* type: device-to-host; recipient = endpoint
+ * value: 0
+ * index: endpoint;
+ * len: 2; data = frame number
+ */
+
+ {
+ usbtrace(TRACE_INTDECODE(STM32_TRACEINTID_SYNCHFRAME), 0);
+ }
+ break;
+
+ default:
+ {
+ usbtrace(TRACE_DEVERROR(STM32_TRACEERR_INVALIDCTRLREQ), 0);
+ priv->stalled = true;
+ }
+ break;
+ }
+}
+
+/****************************************************************************
+ * Name: stm32_ep0out_setup
+ *
+ * Description:
+ * USB Ctrl EP Setup Event. This is logically part of the USB interrupt
+ * handler. This event occurs when a setup packet is receive on EP0 OUT.
+ *
+ ****************************************************************************/
+
+static inline void stm32_ep0out_setup(struct stm32_usbdev_s *priv)
+{
+ struct stm32_ctrlreq_s ctrlreq;
+
+ /* Verify that a SETUP was received */
+
+ if (priv->ep0state != EP0STATE_SETUP_READY)
+ {
+ usbtrace(TRACE_DEVERROR(STM32_TRACEERR_EP0NOSETUP), priv->ep0state);
+ return;
+ }
+
+ /* Terminate any pending requests */
+
+ stm32_req_cancel(&priv->epout[EP0], -EPROTO);
+ stm32_req_cancel(&priv->epin[EP0], -EPROTO);
+
+ /* Assume NOT stalled */
+
+ priv->epout[EP0].stalled = false;
+ priv->epin[EP0].stalled = false;
+ priv->stalled = false;
+
+ /* Starting to process a control request - update state */
+
+ priv->ep0state = EP0STATE_SETUP_PROCESS;
+
+ /* And extract the little-endian 16-bit values to host order */
+
+ ctrlreq.type = priv->ctrlreq.type;
+ ctrlreq.req = priv->ctrlreq.req;
+ ctrlreq.value = GETUINT16(priv->ctrlreq.value);
+ ctrlreq.index = GETUINT16(priv->ctrlreq.index);
+ ctrlreq.len = GETUINT16(priv->ctrlreq.len);
+
+ ullinfo("type=%02x req=%02x value=%04x index=%04x len=%04x\n",
+ ctrlreq.type, ctrlreq.req, ctrlreq.value, ctrlreq.index, ctrlreq.len);
+
+ /* Check for a standard request */
+
+ if ((ctrlreq.type & USB_REQ_TYPE_MASK) != USB_REQ_TYPE_STANDARD)
+ {
+ /* Dispatch any non-standard requests */
+
+ (void)stm32_req_dispatch(priv, &priv->ctrlreq);
+ }
+ else
+ {
+ /* Handle standard requests. */
+
+ stm32_ep0out_stdrequest(priv, &ctrlreq);
+ }
+
+ /* Check if the setup processing resulted in a STALL */
+
+ if (priv->stalled)
+ {
+ usbtrace(TRACE_DEVERROR(STM32_TRACEERR_EP0SETUPSTALLED), priv->ep0state);
+ stm32_ep0_stall(priv);
+ }
+
+ /* Reset state/data associated with thie SETUP request */
+
+ priv->ep0datlen = 0;
+}
+
+/****************************************************************************
+ * Name: stm32_epout
+ *
+ * Description:
+ * This is part of the OUT endpoint interrupt processing. This function
+ * handles the OUT event for a single endpoint.
+ *
+ ****************************************************************************/
+
+static inline void stm32_epout(FAR struct stm32_usbdev_s *priv, uint8_t epno)
+{
+ FAR struct stm32_ep_s *privep;
+
+ /* Endpoint 0 is a special case. */
+
+ if (epno == 0)
+ {
+ privep = &priv->epout[EP0];
+
+ /* In the EP0STATE_DATA_OUT state, we are receiving data into the
+ * request buffer. In that case, we must continue the request
+ * processing.
+ */
+
+ if (priv->ep0state == EP0STATE_DATA_OUT)
+ {
+ /* Continue processing data from the EP0 OUT request queue */
+
+ stm32_epout_complete(priv, privep);
+
+ /* If we are not actively processing an OUT request, then we
+ * need to setup to receive the next control request.
+ */
+
+ if (!privep->active)
+ {
+ stm32_ep0out_ctrlsetup(priv);
+ priv->ep0state = EP0STATE_IDLE;
+ }
+ }
+ }
+
+ /* For other endpoints, the only possibility is that we are continuing
+ * or finishing an OUT request.
+ */
+
+ else if (priv->devstate == DEVSTATE_CONFIGURED)
+ {
+ stm32_epout_complete(priv, &priv->epout[epno]);
+ }
+}
+
+/****************************************************************************
+ * Name: stm32_epout_interrupt
+ *
+ * Description:
+ * USB OUT endpoint interrupt handler. The core generates this interrupt when
+ * there is an interrupt is pending on one of the OUT endpoints of the core.
+ * The driver must read the OTG DAINT register to determine the exact number
+ * of the OUT endpoint on which the interrupt occurred, and then read the
+ * corresponding OTG DOEPINTx register to determine the exact cause of the
+ * interrupt.
+ *
+ ****************************************************************************/
+
+static inline void stm32_epout_interrupt(FAR struct stm32_usbdev_s *priv)
+{
+ uint32_t daint;
+ uint32_t regval;
+ uint32_t doepint;
+ int epno;
+
+ /* Get the pending, enabled interrupts for the OUT endpoint from the endpoint
+ * interrupt status register.
+ */
+
+ regval = stm32_getreg(STM32_OTG_DAINT);
+ regval &= stm32_getreg(STM32_OTG_DAINTMSK);
+ daint = (regval & OTG_DAINT_OEP_MASK) >> OTG_DAINT_OEP_SHIFT;
+
+ if (daint == 0)
+ {
+ /* We got an interrupt, but there is no unmasked endpoint that caused
+ * it ?! When this happens, the interrupt flag never gets cleared and
+ * we are stuck in infinite interrupt loop.
+ *
+ * This shouldn't happen if we are diligent about handling timing
+ * issues when masking endpoint interrupts. However, this workaround
+ * avoids infinite loop and allows operation to continue normally. It
+ * works by clearing each endpoint flags, masked or not.
+ */
+
+ regval = stm32_getreg(STM32_OTG_DAINT);
+ daint = (regval & OTG_DAINT_OEP_MASK) >> OTG_DAINT_OEP_SHIFT;
+
+ usbtrace(TRACE_DEVERROR(STM32_TRACEERR_EPOUTUNEXPECTED),
+ (uint16_t)regval);
+
+ epno = 0;
+ while (daint)
+ {
+ if ((daint & 1) != 0)
+ {
+ regval = stm32_getreg(STM32_OTG_DOEPINT(epno));
+ ullerr("DOEPINT(%d) = %08x\n", epno, regval);
+ stm32_putreg(0xFF, STM32_OTG_DOEPINT(epno));
+ }
+
+ epno++;
+ daint >>= 1;
+ }
+
+ return;
+ }
+
+ /* Process each pending IN endpoint interrupt */
+
+ epno = 0;
+ while (daint)
+ {
+ /* Is an OUT interrupt pending for this endpoint? */
+
+ if ((daint & 1) != 0)
+ {
+ /* Yes.. get the OUT endpoint interrupt status */
+
+ doepint = stm32_getreg(STM32_OTG_DOEPINT(epno));
+ doepint &= stm32_getreg(STM32_OTG_DOEPMSK);
+
+ /* Transfer completed interrupt. This interrupt is trigged when
+ * stm32_rxinterrupt() removes the last packet data from the RxFIFO.
+ * In this case, core internally sets the NAK bit for this endpoint to
+ * prevent it from receiving any more packets.
+ */
+
+ if ((doepint & OTG_DOEPINT_XFRC) != 0)
+ {
+ usbtrace(TRACE_INTDECODE(STM32_TRACEINTID_EPOUT_XFRC), (uint16_t)doepint);
+
+ /* Clear the bit in DOEPINTn for this interrupt */
+
+ stm32_putreg(OTG_DOEPINT_XFRC, STM32_OTG_DOEPINT(epno));
+
+ /* Handle the RX transfer data ready event */
+
+ stm32_epout(priv, epno);
+ }
+
+ /* Endpoint disabled interrupt (ignored because this interrupt is
+ * used in polled mode by the endpoint disable logic).
+ */
+#if 1
+ /* REVISIT: */
+ if ((doepint & OTG_DOEPINT_EPDISD) != 0)
+ {
+ usbtrace(TRACE_INTDECODE(STM32_TRACEINTID_EPOUT_EPDISD), (uint16_t)doepint);
+
+ /* Clear the bit in DOEPINTn for this interrupt */
+
+ stm32_putreg(OTG_DOEPINT_EPDISD, STM32_OTG_DOEPINT(epno));
+ }
+#endif
+ /* Setup Phase Done (control EPs) */
+
+ if ((doepint & OTG_DOEPINT_SETUP) != 0)
+ {
+ usbtrace(TRACE_INTDECODE(STM32_TRACEINTID_EPOUT_SETUP), priv->ep0state);
+
+ /* Handle the receipt of the IN SETUP packets now (OUT setup
+ * packet processing may be delayed until the accompanying
+ * OUT DATA is received)
+ */
+
+ if (priv->ep0state == EP0STATE_SETUP_READY)
+ {
+ stm32_ep0out_setup(priv);
+ }
+ stm32_putreg(OTG_DOEPINT_SETUP, STM32_OTG_DOEPINT(epno));
+ }
+ }
+
+ epno++;
+ daint >>= 1;
+ }
+}
+
+/****************************************************************************
+ * Name: stm32_epin_runtestmode
+ *
+ * Description:
+ * Execute the test mode setup by the SET FEATURE request
+ *
+ ****************************************************************************/
+
+static inline void stm32_epin_runtestmode(FAR struct stm32_usbdev_s *priv)
+{
+ uint32_t regval = stm32_getreg(STM32_OTG_DCTL);
+ regval &= OTG_DCTL_TCTL_MASK;
+ regval |= (uint32_t)priv->testmode << OTG_DCTL_TCTL_SHIFT;
+ stm32_putreg(regval , STM32_OTG_DCTL);
+
+ priv->dotest = 0;
+ priv->testmode = OTG_TESTMODE_DISABLED;
+}
+
+/****************************************************************************
+ * Name: stm32_epin
+ *
+ * Description:
+ * This is part of the IN endpoint interrupt processing. This function
+ * handles the IN event for a single endpoint.
+ *
+ ****************************************************************************/
+
+static inline void stm32_epin(FAR struct stm32_usbdev_s *priv, uint8_t epno)
+{
+ FAR struct stm32_ep_s *privep = &priv->epin[epno];
+
+ /* Endpoint 0 is a special case. */
+
+ if (epno == 0)
+ {
+ /* In the EP0STATE_DATA_IN state, we are sending data from request
+ * buffer. In that case, we must continue the request processing.
+ */
+
+ if (priv->ep0state == EP0STATE_DATA_IN)
+ {
+ /* Continue processing data from the EP0 OUT request queue */
+
+ stm32_epin_request(priv, privep);
+
+ /* If we are not actively processing an OUT request, then we
+ * need to setup to receive the next control request.
+ */
+
+ if (!privep->active)
+ {
+ stm32_ep0out_ctrlsetup(priv);
+ priv->ep0state = EP0STATE_IDLE;
+ }
+ }
+
+ /* Test mode is another special case */
+
+ if (priv->dotest)
+ {
+ stm32_epin_runtestmode(priv);
+ }
+ }
+
+ /* For other endpoints, the only possibility is that we are continuing
+ * or finishing an IN request.
+ */
+
+ else if (priv->devstate == DEVSTATE_CONFIGURED)
+ {
+ /* Continue processing data from the endpoint write request queue */
+
+ stm32_epin_request(priv, privep);
+ }
+}
+
+/****************************************************************************
+ * Name: stm32_epin_txfifoempty
+ *
+ * Description:
+ * TxFIFO empty interrupt handling
+ *
+ ****************************************************************************/
+
+static inline void stm32_epin_txfifoempty(FAR struct stm32_usbdev_s *priv, int epno)
+{
+ FAR struct stm32_ep_s *privep = &priv->epin[epno];
+
+ /* Continue processing the write request queue. This may mean sending
+ * more data from the existing request or terminating the current requests
+ * and (perhaps) starting the IN transfer from the next write request.
+ */
+
+ stm32_epin_request(priv, privep);
+}
+
+/****************************************************************************
+ * Name: stm32_epin_interrupt
+ *
+ * Description:
+ * USB IN endpoint interrupt handler. The core generates this interrupt when
+ * an interrupt is pending on one of the IN endpoints of the core. The driver
+ * must read the OTG DAINT register to determine the exact number of the IN
+ * endpoint on which the interrupt occurred, and then read the corresponding
+ * OTG DIEPINTx register to determine the exact cause of the interrupt.
+ *
+ ****************************************************************************/
+
+static inline void stm32_epin_interrupt(FAR struct stm32_usbdev_s *priv)
+{
+ uint32_t diepint;
+ uint32_t daint;
+ uint32_t mask;
+ uint32_t empty;
+ int epno;
+
+ /* Get the pending, enabled interrupts for the IN endpoint from the endpoint
+ * interrupt status register.
+ */
+
+ daint = stm32_getreg(STM32_OTG_DAINT);
+ daint &= stm32_getreg(STM32_OTG_DAINTMSK);
+ daint &= OTG_DAINT_IEP_MASK;
+
+ if (daint == 0)
+ {
+ /* We got an interrupt, but there is no unmasked endpoint that caused
+ * it ?! When this happens, the interrupt flag never gets cleared and
+ * we are stuck in infinite interrupt loop.
+ *
+ * This shouldn't happen if we are diligent about handling timing
+ * issues when masking endpoint interrupts. However, this workaround
+ * avoids infinite loop and allows operation to continue normally. It
+ * works by clearing each endpoint flags, masked or not.
+ */
+
+ daint = stm32_getreg(STM32_OTG_DAINT);
+ usbtrace(TRACE_DEVERROR(STM32_TRACEERR_EPINUNEXPECTED),
+ (uint16_t)daint);
+
+ daint &= OTG_DAINT_IEP_MASK;
+ epno = 0;
+
+ while (daint)
+ {
+ if ((daint & 1) != 0)
+ {
+ ullerr("DIEPINT(%d) = %08x\n",
+ epno, stm32_getreg(STM32_OTG_DIEPINT(epno)));
+ stm32_putreg(0xFF, STM32_OTG_DIEPINT(epno));
+ }
+
+ epno++;
+ daint >>= 1;
+ }
+
+ return;
+ }
+
+ /* Process each pending IN endpoint interrupt */
+
+ epno = 0;
+ while (daint)
+ {
+ /* Is an IN interrupt pending for this endpoint? */
+
+ if ((daint & 1) != 0)
+ {
+ /* Get IN interrupt mask register. Bits 0-6 correspond to enabled
+ * interrupts as will be found in the DIEPINT interrupt status
+ * register.
+ */
+
+ mask = stm32_getreg(STM32_OTG_DIEPMSK);
+
+ /* Check if the TxFIFO not empty interrupt is enabled for this
+ * endpoint in the DIEPMSK register. Bits n corresponds to
+ * endpoint n in the register. That condition corresponds to
+ * bit 7 of the DIEPINT interrupt status register. There is
+ * no TXFE bit in the mask register, so we fake one here.
+ */
+
+ empty = stm32_getreg(STM32_OTG_DIEPEMPMSK);
+ if ((empty & OTG_DIEPEMPMSK(epno)) != 0)
+ {
+ mask |= OTG_DIEPINT_TXFE;
+ }
+
+ /* Now, read the interrupt status and mask out all disabled
+ * interrupts.
+ */
+
+ diepint = stm32_getreg(STM32_OTG_DIEPINT(epno)) & mask;
+
+ /* Decode and process the enabled, pending interrupts */
+ /* Transfer completed interrupt */
+
+ if ((diepint & OTG_DIEPINT_XFRC) != 0)
+ {
+ usbtrace(TRACE_INTDECODE(STM32_TRACEINTID_EPIN_XFRC),
+ (uint16_t)diepint);
+
+ /* It is possible that logic may be waiting for a the
+ * TxFIFO to become empty. We disable the TxFIFO empty
+ * interrupt here; it will be re-enabled if there is still
+ * insufficient space in the TxFIFO.
+ */
+
+ empty &= ~OTG_DIEPEMPMSK(epno);
+ stm32_putreg(empty, STM32_OTG_DIEPEMPMSK);
+ stm32_putreg(OTG_DIEPINT_XFRC, STM32_OTG_DIEPINT(epno));
+
+ /* IN transfer complete */
+
+ stm32_epin(priv, epno);
+ }
+
+ /* Timeout condition */
+
+ if ((diepint & OTG_DIEPINT_TOC) != 0)
+ {
+ usbtrace(TRACE_INTDECODE(STM32_TRACEINTID_EPIN_TOC), (uint16_t)diepint);
+ stm32_putreg(OTG_DIEPINT_TOC, STM32_OTG_DIEPINT(epno));
+ }
+
+ /* IN token received when TxFIFO is empty. Applies to non-periodic IN
+ * endpoints only. This interrupt indicates that an IN token was received
+ * when the associated TxFIFO (periodic/non-periodic) was empty. This
+ * interrupt is asserted on the endpoint for which the IN token was
+ * received.
+ */
+
+ if ((diepint & OTG_DIEPINT_ITTXFE) != 0)
+ {
+ usbtrace(TRACE_INTDECODE(STM32_TRACEINTID_EPIN_ITTXFE), (uint16_t)diepint);
+ stm32_epin_request(priv, &priv->epin[epno]);
+ stm32_putreg(OTG_DIEPINT_ITTXFE, STM32_OTG_DIEPINT(epno));
+ }
+
+ /* IN endpoint NAK effective (ignored as this used only in polled
+ * mode)
+ */
+#if 0
+ if ((diepint & OTG_DIEPINT_INEPNE) != 0)
+ {
+ usbtrace(TRACE_INTDECODE(STM32_TRACEINTID_EPIN_INEPNE), (uint16_t)diepint);
+ stm32_putreg(OTG_DIEPINT_INEPNE, STM32_OTG_DIEPINT(epno));
+ }
+#endif
+ /* Endpoint disabled interrupt (ignored as this used only in polled
+ * mode)
+ */
+#if 0
+ if ((diepint & OTG_DIEPINT_EPDISD) != 0)
+ {
+ usbtrace(TRACE_INTDECODE(STM32_TRACEINTID_EPIN_EPDISD), (uint16_t)diepint);
+ stm32_putreg(OTG_DIEPINT_EPDISD, STM32_OTG_DIEPINT(epno));
+ }
+#endif
+ /* Transmit FIFO empty */
+
+ if ((diepint & OTG_DIEPINT_TXFE) != 0)
+ {
+ usbtrace(TRACE_INTDECODE(STM32_TRACEINTID_EPIN_TXFE), (uint16_t)diepint);
+
+ /* If we were waiting for TxFIFO to become empty, the we might have both
+ * XFRC and TXFE interrupts pending. Since we do the same thing for both
+ * cases, ignore the TXFE if we have already processed the XFRC.
+ */
+
+ if ((diepint & OTG_DIEPINT_XFRC) == 0)
+ {
+ /* Mask further FIFO empty interrupts. This will be re-enabled
+ * whenever we need to wait for a FIFO event.
+ */
+
+ empty &= ~OTG_DIEPEMPMSK(epno);
+ stm32_putreg(empty, STM32_OTG_DIEPEMPMSK);
+
+ /* Handle TxFIFO empty */
+
+ stm32_epin_txfifoempty(priv, epno);
+ }
+
+ /* Clear the pending TxFIFO empty interrupt */
+
+ stm32_putreg(OTG_DIEPINT_TXFE, STM32_OTG_DIEPINT(epno));
+ }
+ }
+
+ epno++;
+ daint >>= 1;
+ }
+}
+
+/****************************************************************************
+ * Name: stm32_resumeinterrupt
+ *
+ * Description:
+ * Resume/remote wakeup detected interrupt
+ *
+ ****************************************************************************/
+
+static inline void stm32_resumeinterrupt(FAR struct stm32_usbdev_s *priv)
+{
+ uint32_t regval;
+
+ /* Restart the PHY clock and un-gate USB core clock (HCLK) */
+
+#ifdef CONFIG_USBDEV_LOWPOWER
+ regval = stm32_getreg(STM32_OTG_PCGCCTL);
+ regval &= ~(OTG_PCGCCTL_STPPCLK | OTG_PCGCCTL_GATEHCLK);
+ stm32_putreg(regval, STM32_OTG_PCGCCTL);
+#endif
+
+ /* Clear remote wake-up signaling */
+
+ regval = stm32_getreg(STM32_OTG_DCTL);
+ regval &= ~OTG_DCTL_RWUSIG;
+ stm32_putreg(regval, STM32_OTG_DCTL);
+
+ /* Restore full power -- whatever that means for this particular board */
+
+ stm32_usbsuspend((struct usbdev_s *)priv, true);
+
+ /* Notify the class driver of the resume event */
+
+ if (priv->driver)
+ {
+ CLASS_RESUME(priv->driver, &priv->usbdev);
+ }
+}
+
+/****************************************************************************
+ * Name: stm32_suspendinterrupt
+ *
+ * Description:
+ * USB suspend interrupt
+ *
+ ****************************************************************************/
+
+static inline void stm32_suspendinterrupt(FAR struct stm32_usbdev_s *priv)
+{
+#ifdef CONFIG_USBDEV_LOWPOWER
+ uint32_t regval;
+#endif
+
+ /* Notify the class driver of the suspend event */
+
+ if (priv->driver)
+ {
+ CLASS_SUSPEND(priv->driver, &priv->usbdev);
+ }
+
+#ifdef CONFIG_USBDEV_LOWPOWER
+ /* OTG_DSTS_SUSPSTS is set as long as the suspend condition is detected
+ * on USB. Check if we are still have the suspend condition, that we are
+ * connected to the host, and that we have been configured.
+ */
+
+ regval = stm32_getreg(STM32_OTG_DSTS);
+
+ if ((regval & OTG_DSTS_SUSPSTS) != 0 && devstate == DEVSTATE_CONFIGURED)
+ {
+ /* Switch off OTG clocking. Setting OTG_PCGCCTL_STPPCLK stops the
+ * PHY clock.
+ */
+
+ regval = stm32_getreg(STM32_OTG_PCGCCTL);
+ regval |= OTG_PCGCCTL_STPPCLK;
+ stm32_putreg(regval, STM32_OTG_PCGCCTL);
+
+ /* Setting OTG_PCGCCTL_GATEHCLK gate HCLK to modules other than
+ * the AHB Slave and Master and wakeup logic.
+ */
+
+ regval |= OTG_PCGCCTL_GATEHCLK;
+ stm32_putreg(regval, STM32_OTG_PCGCCTL);
+ }
+#endif
+
+ /* Let the board-specific logic know that we have entered the suspend
+ * state
+ */
+
+ stm32_usbsuspend((FAR struct usbdev_s *)priv, false);
+}
+
+/****************************************************************************
+ * Name: stm32_rxinterrupt
+ *
+ * Description:
+ * RxFIFO non-empty interrupt. This interrupt indicates that there is at
+ * least one packet pending to be read from the RxFIFO.
+ *
+ ****************************************************************************/
+
+static inline void stm32_rxinterrupt(FAR struct stm32_usbdev_s *priv)
+{
+ FAR struct stm32_ep_s *privep;
+ uint32_t regval;
+ int bcnt;
+ int epphy;
+
+ /* Disable the Rx status queue level interrupt */
+
+ regval = stm32_getreg(STM32_OTG_GINTMSK);
+ regval &= ~OTG_GINT_RXFLVL;
+ stm32_putreg(regval, STM32_OTG_GINTMSK);
+
+ /* Get the status from the top of the FIFO */
+
+ regval = stm32_getreg(STM32_OTG_GRXSTSP);
+
+ /* Decode status fields */
+
+ epphy = (regval & OTG_GRXSTSD_EPNUM_MASK) >> OTG_GRXSTSD_EPNUM_SHIFT;
+
+ if (epphy < STM32_NENDPOINTS)
+ {
+ privep = &priv->epout[epphy];
+
+ /* Handle the RX event according to the packet status field */
+
+ switch (regval & OTG_GRXSTSD_PKTSTS_MASK)
+ {
+ /* Global OUT NAK. This indicate that the global OUT NAK bit has taken
+ * effect.
+ *
+ * PKTSTS = Global OUT NAK, BCNT = 0, EPNUM = Don't Care, DPID = Don't
+ * Care.
+ */
+
+ case OTG_GRXSTSD_PKTSTS_OUTNAK:
+ {
+ usbtrace(TRACE_INTDECODE(STM32_TRACEINTID_OUTNAK), 0);
+ }
+ break;
+
+ /* OUT data packet received.
+ *
+ * PKTSTS = DataOUT, BCNT = size of the received data OUT packet,
+ * EPNUM = EPNUM on which the packet was received, DPID = Actual Data PID.
+ */
+
+ case OTG_GRXSTSD_PKTSTS_OUTRECVD:
+ {
+ usbtrace(TRACE_INTDECODE(STM32_TRACEINTID_OUTRECVD), epphy);
+ bcnt = (regval & OTG_GRXSTSD_BCNT_MASK) >> OTG_GRXSTSD_BCNT_SHIFT;
+ if (bcnt > 0)
+ {
+ stm32_epout_receive(privep, bcnt);
+ }
+ }
+ break;
+
+ /* OUT transfer completed. This indicates that an OUT data transfer for
+ * the specified OUT endpoint has completed. After this entry is popped
+ * from the receive FIFO, the core asserts a Transfer Completed interrupt
+ * on the specified OUT endpoint.
+ *
+ * PKTSTS = Data OUT Transfer Done, BCNT = 0, EPNUM = OUT EP Num on
+ * which the data transfer is complete, DPID = Don't Care.
+ */
+
+ case OTG_GRXSTSD_PKTSTS_OUTDONE:
+ {
+ usbtrace(TRACE_INTDECODE(STM32_TRACEINTID_OUTDONE), epphy);
+ }
+ break;
+
+ /* SETUP transaction completed. This indicates that the Setup stage for
+ * the specified endpoint has completed and the Data stage has started.
+ * After this entry is popped from the receive FIFO, the core asserts a
+ * Setup interrupt on the specified control OUT endpoint (triggers an
+ * interrupt).
+ *
+ * PKTSTS = Setup Stage Done, BCNT = 0, EPNUM = Control EP Num,
+ * DPID = Don't Care.
+ */
+
+ case OTG_GRXSTSD_PKTSTS_SETUPDONE:
+ {
+ usbtrace(TRACE_INTDECODE(STM32_TRACEINTID_SETUPDONE), epphy);
+ }
+ break;
+
+ /* SETUP data packet received. This indicates that a SETUP packet for the
+ * specified endpoint is now available for reading from the receive FIFO.
+ *
+ * PKTSTS = SETUP, BCNT = 8, EPNUM = Control EP Num, DPID = D0.
+ */
+
+ case OTG_GRXSTSD_PKTSTS_SETUPRECVD:
+ {
+ uint16_t datlen;
+
+ usbtrace(TRACE_INTDECODE(STM32_TRACEINTID_SETUPRECVD), epphy);
+
+ /* Read EP0 setup data. NOTE: If multiple SETUP packets are received,
+ * the last one overwrites the previous setup packets and only that
+ * last SETUP packet will be processed.
+ */
+
+ stm32_rxfifo_read(&priv->epout[EP0], (FAR uint8_t *)&priv->ctrlreq,
+ USB_SIZEOF_CTRLREQ);
+
+ /* Was this an IN or an OUT SETUP packet. If it is an OUT SETUP,
+ * then we need to wait for the completion of the data phase to
+ * process the setup command. If it is an IN SETUP packet, then
+ * we must processing the command BEFORE we enter the DATA phase.
+ *
+ * If the data associated with the OUT SETUP packet is zero length,
+ * then, of course, we don't need to wait.
+ */
+
+ datlen = GETUINT16(priv->ctrlreq.len);
+ if (USB_REQ_ISOUT(priv->ctrlreq.type) && datlen > 0)
+ {
+ /* Clear NAKSTS so that we can receive the data */
+
+ regval = stm32_getreg(STM32_OTG_DOEPCTL0);
+ regval |= OTG_DOEPCTL0_CNAK;
+ stm32_putreg(regval, STM32_OTG_DOEPCTL0);
+
+ /* Wait for the data phase. */
+
+ priv->ep0state = EP0STATE_SETUP_OUT;
+ }
+ else
+ {
+ /* We can process the setup data as soon as SETUP done word is
+ * popped of the RxFIFO.
+ */
+
+ priv->ep0state = EP0STATE_SETUP_READY;
+ }
+ }
+ break;
+
+ default:
+ {
+ usbtrace(TRACE_DEVERROR(STM32_TRACEERR_INVALIDPARMS),
+ (regval & OTG_GRXSTSD_PKTSTS_MASK) >> OTG_GRXSTSD_PKTSTS_SHIFT);
+ }
+ break;
+ }
+ }
+
+ /* Enable the Rx Status Queue Level interrupt */
+
+ regval = stm32_getreg(STM32_OTG_GINTMSK);
+ regval |= OTG_GINT_RXFLVL;
+ stm32_putreg(regval, STM32_OTG_GINTMSK);
+}
+
+/****************************************************************************
+ * Name: stm32_enuminterrupt
+ *
+ * Description:
+ * Enumeration done interrupt
+ *
+ ****************************************************************************/
+
+static inline void stm32_enuminterrupt(FAR struct stm32_usbdev_s *priv)
+{
+ uint32_t regval;
+
+ /* Activate EP0 */
+
+ stm32_ep0in_activate();
+
+ /* Set USB turn-around time for the full speed device with internal PHY interface. */
+
+ regval = stm32_getreg(STM32_OTG_GUSBCFG);
+ regval &= ~OTG_GUSBCFG_TRDT_MASK;
+ regval |= OTG_GUSBCFG_TRDT(5);
+ stm32_putreg(regval, STM32_OTG_GUSBCFG);
+}
+
+/****************************************************************************
+ * Name: stm32_isocininterrupt
+ *
+ * Description:
+ * Incomplete isochronous IN transfer interrupt. Assertion of the incomplete
+ * isochronous IN transfer interrupt indicates an incomplete isochronous IN
+ * transfer on at least one of the isochronous IN endpoints.
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_USBDEV_ISOCHRONOUS
+static inline void stm32_isocininterrupt(FAR struct stm32_usbdev_s *priv)
+{
+ int i;
+
+ /* The application must read the endpoint control register for all isochronous
+ * IN endpoints to detect endpoints with incomplete IN data transfers.
+ */
+
+ for (i = 0; i < STM32_NENDPOINTS; i++)
+ {
+ /* Is this an isochronous IN endpoint? */
+
+ privep = &priv->epin[i];
+ if (privep->eptype != USB_EP_ATTR_XFER_ISOC)
+ {
+ /* No... keep looking */
+
+ continue;
+ }
+
+ /* Is there an active read request on the isochronous OUT endpoint? */
+
+ if (!privep->active)
+ {
+ /* No.. the endpoint is not actively transmitting data */
+
+ continue;
+ }
+
+ /* Check if this is the endpoint that had the incomplete transfer */
+
+ regaddr = STM32_OTG_DIEPCTL(privep->epphy);
+ doepctl = stm32_getreg(regaddr);
+ dsts = stm32_getreg(STM32_OTG_DSTS);
+
+ /* EONUM = 0:even frame, 1:odd frame
+ * SOFFN = Frame number of the received SOF
+ */
+
+ eonum = ((doepctl & OTG_DIEPCTL_EONUM) != 0);
+ soffn = ((dsts & OTG_DSTS_SOFFN0) != 0);
+
+ if (eonum != soffn)
+ {
+ /* Not this endpoint */
+
+ continue;
+ }
+
+ /* For isochronous IN endpoints with incomplete transfers,
+ * the application must discard the data in the memory and
+ * disable the endpoint.
+ */
+
+ stm32_req_complete(privep, -EIO);
+#warning "Will clear OTG_DIEPCTL_USBAEP too"
+ stm32_epin_disable(privep);
+ break;
+ }
+}
+#endif
+
+/****************************************************************************
+ * Name: stm32_isocoutinterrupt
+ *
+ * Description:
+ * Incomplete periodic transfer interrupt
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_USBDEV_ISOCHRONOUS
+static inline void stm32_isocoutinterrupt(FAR struct stm32_usbdev_s *priv)
+{
+ FAR struct stm32_ep_s *privep;
+ FAR struct stm32_req_s *privreq;
+ uint32_t regaddr;
+ uint32_t doepctl;
+ uint32_t dsts;
+ bool eonum;
+ bool soffn;
+
+ /* When it receives an IISOOXFR interrupt, the application must read the
+ * control registers of all isochronous OUT endpoints to determine which
+ * endpoints had an incomplete transfer in the current microframe. An
+ * endpoint transfer is incomplete if both the following conditions are true:
+ *
+ * DOEPCTLx:EONUM = DSTS:SOFFN[0], and
+ * DOEPCTLx:EPENA = 1
+ */
+
+ for (i = 0; i < STM32_NENDPOINTS; i++)
+ {
+ /* Is this an isochronous OUT endpoint? */
+
+ privep = &priv->epout[i];
+ if (privep->eptype != USB_EP_ATTR_XFER_ISOC)
+ {
+ /* No... keep looking */
+
+ continue;
+ }
+
+ /* Is there an active read request on the isochronous OUT endpoint? */
+
+ if (!privep->active)
+ {
+ /* No.. the endpoint is not actively transmitting data */
+
+ continue;
+ }
+
+ /* Check if this is the endpoint that had the incomplete transfer */
+
+ regaddr = STM32_OTG_DOEPCTL(privep->epphy);
+ doepctl = stm32_getreg(regaddr);
+ dsts = stm32_getreg(STM32_OTG_DSTS);
+
+ /* EONUM = 0:even frame, 1:odd frame
+ * SOFFN = Frame number of the received SOF
+ */
+
+ eonum = ((doepctl & OTG_DOEPCTL_EONUM) != 0);
+ soffn = ((dsts & OTG_DSTS_SOFFN0) != 0);
+
+ if (eonum != soffn)
+ {
+ /* Not this endpoint */
+
+ continue;
+ }
+
+ /* For isochronous OUT endpoints with incomplete transfers,
+ * the application must discard the data in the memory and
+ * disable the endpoint.
+ */
+
+ stm32_req_complete(privep, -EIO);
+#warning "Will clear OTG_DOEPCTL_USBAEP too"
+ stm32_epout_disable(privep);
+ break;
+ }
+}
+#endif
+
+/****************************************************************************
+ * Name: stm32_sessioninterrupt
+ *
+ * Description:
+ * Session request/new session detected interrupt
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_USBDEV_VBUSSENSING
+static inline void stm32_sessioninterrupt(FAR struct stm32_usbdev_s *priv)
+{
+#warning "Missing logic"
+}
+#endif
+
+/****************************************************************************
+ * Name: stm32_otginterrupt
+ *
+ * Description:
+ * OTG interrupt
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_USBDEV_VBUSSENSING
+static inline void stm32_otginterrupt(FAR struct stm32_usbdev_s *priv)
+{
+ uint32_t regval;
+
+ /* Check for session end detected */
+
+ regval = stm32_getreg(STM32_OTG_GOTGINT);
+ if ((regval & OTG_GOTGINT_SEDET) != 0)
+ {
+#warning "Missing logic"
+ }
+
+ /* Clear OTG interrupt */
+
+ stm32_putreg(retval, STM32_OTG_GOTGINT);
+}
+#endif
+
+/****************************************************************************
+ * Name: stm32_usbinterrupt
+ *
+ * Description:
+ * USB interrupt handler
+ *
+ ****************************************************************************/
+
+static int stm32_usbinterrupt(int irq, FAR void *context)
+{
+ /* At present, there is only a single OTG device support. Hence it is
+ * pre-allocated as g_otghsdev. However, in most code, the private data
+ * structure will be referenced using the 'priv' pointer (rather than the
+ * global data) in order to simplify any future support for multiple devices.
+ */
+
+ FAR struct stm32_usbdev_s *priv = &g_otghsdev;
+ uint32_t regval;
+
+ usbtrace(TRACE_INTENTRY(STM32_TRACEINTID_USB), 0);
+
+ /* Assure that we are in device mode */
+
+ DEBUGASSERT((stm32_getreg(STM32_OTG_GINTSTS) & OTG_GINTSTS_CMOD) == OTG_GINTSTS_DEVMODE);
+
+ /* Get the state of all enabled interrupts. We will do this repeatedly
+ * some interrupts (like RXFLVL) will generate additional interrupting
+ * events.
+ */
+
+ for (; ; )
+ {
+ /* Get the set of pending, un-masked interrupts */
+
+ regval = stm32_getreg(STM32_OTG_GINTSTS);
+ regval &= stm32_getreg(STM32_OTG_GINTMSK);
+
+ /* Break out of the loop when there are no further pending (and
+ * unmasked) interrupts to be processes.
+ */
+
+ if (regval == 0)
+ {
+ break;
+ }
+ usbtrace(TRACE_INTDECODE(STM32_TRACEINTID_INTPENDING), (uint16_t)regval);
+
+ /* OUT endpoint interrupt. The core sets this bit to indicate that an
+ * interrupt is pending on one of the OUT endpoints of the core.
+ */
+
+ if ((regval & OTG_GINT_OEP) != 0)
+ {
+ usbtrace(TRACE_INTDECODE(STM32_TRACEINTID_EPOUT), (uint16_t)regval);
+ stm32_epout_interrupt(priv);
+ stm32_putreg(OTG_GINT_OEP, STM32_OTG_GINTSTS);
+ }
+
+ /* IN endpoint interrupt. The core sets this bit to indicate that
+ * an interrupt is pending on one of the IN endpoints of the core.
+ */
+
+ if ((regval & OTG_GINT_IEP) != 0)
+ {
+ usbtrace(TRACE_INTDECODE(STM32_TRACEINTID_EPIN), (uint16_t)regval);
+ stm32_epin_interrupt(priv);
+ stm32_putreg(OTG_GINT_IEP, STM32_OTG_GINTSTS);
+ }
+
+ /* Host/device mode mismatch error interrupt */
+
+#ifdef CONFIG_DEBUG_USB
+ if ((regval & OTG_GINT_MMIS) != 0)
+ {
+ usbtrace(TRACE_INTDECODE(STM32_TRACEINTID_MISMATCH), (uint16_t)regval);
+ stm32_putreg(OTG_GINT_MMIS, STM32_OTG_GINTSTS);
+ }
+#endif
+
+ /* Resume/remote wakeup detected interrupt */
+
+ if ((regval & OTG_GINT_WKUP) != 0)
+ {
+ usbtrace(TRACE_INTDECODE(STM32_TRACEINTID_WAKEUP), (uint16_t)regval);
+ stm32_resumeinterrupt(priv);
+ stm32_putreg(OTG_GINT_WKUP, STM32_OTG_GINTSTS);
+ }
+
+ /* USB suspend interrupt */
+
+ if ((regval & OTG_GINT_USBSUSP) != 0)
+ {
+ usbtrace(TRACE_INTDECODE(STM32_TRACEINTID_SUSPEND), (uint16_t)regval);
+ stm32_suspendinterrupt(priv);
+ stm32_putreg(OTG_GINT_USBSUSP, STM32_OTG_GINTSTS);
+ }
+
+ /* Start of frame interrupt */
+
+#ifdef CONFIG_USBDEV_SOFINTERRUPT
+ if ((regval & OTG_GINT_SOF) != 0)
+ {
+ usbtrace(TRACE_INTDECODE(STM32_TRACEINTID_SOF), (uint16_t)regval);
+ stm32_putreg(OTG_GINT_SOF, STM32_OTG_GINTSTS);
+ }
+#endif
+
+ /* RxFIFO non-empty interrupt. Indicates that there is at least one
+ * packet pending to be read from the RxFIFO.
+ */
+
+ if ((regval & OTG_GINT_RXFLVL) != 0)
+ {
+ usbtrace(TRACE_INTDECODE(STM32_TRACEINTID_RXFIFO), (uint16_t)regval);
+ stm32_rxinterrupt(priv);
+ stm32_putreg(OTG_GINT_RXFLVL, STM32_OTG_GINTSTS);
+ }
+
+ /* USB reset interrupt */
+
+ if ((regval & OTG_GINT_USBRST) != 0)
+ {
+ usbtrace(TRACE_INTDECODE(STM32_TRACEINTID_DEVRESET), (uint16_t)regval);
+
+ /* Perform the device reset */
+
+ stm32_usbreset(priv);
+ usbtrace(TRACE_INTEXIT(STM32_TRACEINTID_USB), 0);
+ stm32_putreg(OTG_GINT_USBRST, STM32_OTG_GINTSTS);
+ return OK;
+ }
+
+ /* Enumeration done interrupt */
+
+ if ((regval & OTG_GINT_ENUMDNE) != 0)
+ {
+ usbtrace(TRACE_INTDECODE(STM32_TRACEINTID_ENUMDNE), (uint16_t)regval);
+ stm32_enuminterrupt(priv);
+ stm32_putreg(OTG_GINT_ENUMDNE, STM32_OTG_GINTSTS);
+ }
+
+ /* Incomplete isochronous IN transfer interrupt. When the core finds
+ * non-empty any of the isochronous IN endpoint FIFOs scheduled for
+ * the current frame non-empty, the core generates an IISOIXFR
+ * interrupt.
+ */
+
+#ifdef CONFIG_USBDEV_ISOCHRONOUS
+ if ((regval & OTG_GINT_IISOIXFR) != 0)
+ {
+ usbtrace(TRACE_INTDECODE(STM32_TRACEINTID_IISOIXFR), (uint16_t)regval);
+ stm32_isocininterrupt(priv);
+ stm32_putreg(OTG_GINT_IISOIXFR, STM32_OTG_GINTSTS);
+ }
+
+ /* Incomplete isochronous OUT transfer. For isochronous OUT
+ * endpoints, the XFRC interrupt may not always be asserted. If the
+ * core drops isochronous OUT data packets, the application could fail
+ * to detect the XFRC interrupt. The incomplete Isochronous OUT data
+ * interrupt indicates that an XFRC interrupt was not asserted on at
+ * least one of the isochronous OUT endpoints. At this point, the
+ * endpoint with the incomplete transfer remains enabled, but no active
+ * transfers remain in progress on this endpoint on the USB.
+ */
+
+ if ((regval & OTG_GINT_IISOOXFR) != 0)
+ {
+ usbtrace(TRACE_INTDECODE(STM32_TRACEINTID_IISOOXFR), (uint16_t)regval);
+ stm32_isocoutinterrupt(priv);
+ stm32_putreg(OTG_GINT_IISOOXFR, STM32_OTG_GINTSTS);
+ }
+#endif
+
+ /* Session request/new session detected interrupt */
+
+#ifdef CONFIG_USBDEV_VBUSSENSING
+ if ((regval & OTG_GINT_SRQ) != 0)
+ {
+ usbtrace(TRACE_INTDECODE(STM32_TRACEINTID_SRQ), (uint16_t)regval);
+ stm32_sessioninterrupt(priv);
+ stm32_putreg(OTG_GINT_SRQ, STM32_OTG_GINTSTS);
+ }
+
+ /* OTG interrupt */
+
+ if ((regval & OTG_GINT_OTG) != 0)
+ {
+ usbtrace(TRACE_INTDECODE(STM32_TRACEINTID_OTG), (uint16_t)regval);
+ stm32_otginterrupt(priv);
+ stm32_putreg(OTG_GINT_OTG, STM32_OTG_GINTSTS);
+ }
+#endif
+ }
+
+ usbtrace(TRACE_INTEXIT(STM32_TRACEINTID_USB), 0);
+ return OK;
+}
+
+/****************************************************************************
+ * Endpoint operations
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: stm32_enablegonak
+ *
+ * Description:
+ * Enable global OUT NAK mode
+ *
+ ****************************************************************************/
+
+static void stm32_enablegonak(FAR struct stm32_ep_s *privep)
+{
+ uint32_t regval;
+
+ /* First, make sure that there is no GNOAKEFF interrupt pending. */
+
+#if 0
+ stm32_putreg(OTG_GINT_GONAKEFF, STM32_OTG_GINTSTS);
+#endif
+
+ /* Enable Global OUT NAK mode in the core. */
+
+ regval = stm32_getreg(STM32_OTG_DCTL);
+ regval |= OTG_DCTL_SGONAK;
+ stm32_putreg(regval, STM32_OTG_DCTL);
+
+#if 0
+ /* Wait for the GONAKEFF interrupt that indicates that the OUT NAK
+ * mode is in effect. When the interrupt handler pops the OUTNAK word
+ * from the RxFIFO, the core sets the GONAKEFF interrupt.
+ */
+
+ while ((stm32_getreg(STM32_OTG_GINTSTS) & OTG_GINT_GONAKEFF) == 0);
+ stm32_putreg(OTG_GINT_GONAKEFF, STM32_OTG_GINTSTS);
+
+#else
+ /* Since we are in the interrupt handler, we cannot wait inline for the
+ * GONAKEFF because it cannot occur until service the RXFLVL global interrupt
+ * and pop the OUTNAK word from the RxFIFO.
+ *
+ * Perhaps it is sufficient to wait for Global OUT NAK status to be reported
+ * in OTG DCTL register?
+ */
+
+ while ((stm32_getreg(STM32_OTG_DCTL) & OTG_DCTL_GONSTS) == 0);
+#endif
+}
+
+/****************************************************************************
+ * Name: stm32_disablegonak
+ *
+ * Description:
+ * Disable global OUT NAK mode
+ *
+ ****************************************************************************/
+
+static void stm32_disablegonak(FAR struct stm32_ep_s *privep)
+{
+ uint32_t regval;
+
+ /* Set the "Clear the Global OUT NAK bit" to disable global OUT NAK mode */
+
+ regval = stm32_getreg(STM32_OTG_DCTL);
+ regval |= OTG_DCTL_CGONAK;
+ stm32_putreg(regval, STM32_OTG_DCTL);
+}
+
+/****************************************************************************
+ * Name: stm32_epout_configure
+ *
+ * Description:
+ * Configure an OUT endpoint, making it usable
+ *
+ * Input Parameters:
+ * privep - a pointer to an internal endpoint structure
+ * eptype - The type of the endpoint
+ * maxpacket - The max packet size of the endpoint
+ *
+ ****************************************************************************/
+
+static int stm32_epout_configure(FAR struct stm32_ep_s *privep, uint8_t eptype,
+ uint16_t maxpacket)
+{
+ uint32_t mpsiz;
+ uint32_t regaddr;
+ uint32_t regval;
+
+ usbtrace(TRACE_EPCONFIGURE, privep->epphy);
+
+ /* For EP0, the packet size is encoded */
+
+ if (privep->epphy == EP0)
+ {
+ DEBUGASSERT(eptype == USB_EP_ATTR_XFER_CONTROL);
+
+ /* Map the size in bytes to the encoded value in the register */
+
+ switch (maxpacket)
+ {
+ case 8:
+ mpsiz = OTG_DOEPCTL0_MPSIZ_8;
+ break;
+
+ case 16:
+ mpsiz = OTG_DOEPCTL0_MPSIZ_16;
+ break;
+
+ case 32:
+ mpsiz = OTG_DOEPCTL0_MPSIZ_32;
+ break;
+
+ case 64:
+ mpsiz = OTG_DOEPCTL0_MPSIZ_64;
+ break;
+
+ default:
+ uerr("Unsupported maxpacket: %d\n", maxpacket);
+ return -EINVAL;
+ }
+ }
+
+ /* For other endpoints, the packet size is in bytes */
+
+ else
+ {
+ mpsiz = (maxpacket << OTG_DOEPCTL_MPSIZ_SHIFT);
+ }
+
+ /* If the endpoint is already active don't change the endpoint control
+ * register.
+ */
+
+ regaddr = STM32_OTG_DOEPCTL(privep->epphy);
+ regval = stm32_getreg(regaddr);
+ if ((regval & OTG_DOEPCTL_USBAEP) == 0)
+ {
+ if (regval & OTG_DOEPCTL_NAKSTS)
+ {
+ regval |= OTG_DOEPCTL_CNAK;
+ }
+
+ regval &= ~(OTG_DOEPCTL_MPSIZ_MASK | OTG_DOEPCTL_EPTYP_MASK);
+ regval |= mpsiz;
+ regval |= (eptype << OTG_DOEPCTL_EPTYP_SHIFT);
+ regval |= (OTG_DOEPCTL_SD0PID | OTG_DOEPCTL_USBAEP);
+ stm32_putreg(regval, regaddr);
+
+ /* Save the endpoint configuration */
+
+ privep->ep.maxpacket = maxpacket;
+ privep->eptype = eptype;
+ privep->stalled = false;
+ }
+
+ /* Enable the interrupt for this endpoint */
+
+ regval = stm32_getreg(STM32_OTG_DAINTMSK);
+ regval |= OTG_DAINT_OEP(privep->epphy);
+ stm32_putreg(regval, STM32_OTG_DAINTMSK);
+ return OK;
+}
+
+/****************************************************************************
+ * Name: stm32_epin_configure
+ *
+ * Description:
+ * Configure an IN endpoint, making it usable
+ *
+ * Input Parameters:
+ * privep - a pointer to an internal endpoint structure
+ * eptype - The type of the endpoint
+ * maxpacket - The max packet size of the endpoint
+ *
+ ****************************************************************************/
+
+static int stm32_epin_configure(FAR struct stm32_ep_s *privep, uint8_t eptype,
+ uint16_t maxpacket)
+{
+ uint32_t mpsiz;
+ uint32_t regaddr;
+ uint32_t regval;
+
+ usbtrace(TRACE_EPCONFIGURE, privep->epphy);
+
+ /* For EP0, the packet size is encoded */
+
+ if (privep->epphy == EP0)
+ {
+ DEBUGASSERT(eptype == USB_EP_ATTR_XFER_CONTROL);
+
+ /* Map the size in bytes to the encoded value in the register */
+
+ switch (maxpacket)
+ {
+ case 8:
+ mpsiz = OTG_DIEPCTL0_MPSIZ_8;
+ break;
+
+ case 16:
+ mpsiz = OTG_DIEPCTL0_MPSIZ_16;
+ break;
+
+ case 32:
+ mpsiz = OTG_DIEPCTL0_MPSIZ_32;
+ break;
+
+ case 64:
+ mpsiz = OTG_DIEPCTL0_MPSIZ_64;
+ break;
+
+ default:
+ uerr("Unsupported maxpacket: %d\n", maxpacket);
+ return -EINVAL;
+ }
+ }
+
+ /* For other endpoints, the packet size is in bytes */
+
+ else
+ {
+ mpsiz = (maxpacket << OTG_DIEPCTL_MPSIZ_SHIFT);
+ }
+
+
+ /* If the endpoint is already active don't change the endpoint control
+ * register.
+ */
+
+ regaddr = STM32_OTG_DIEPCTL(privep->epphy);
+ regval = stm32_getreg(regaddr);
+ if ((regval & OTG_DIEPCTL_USBAEP) == 0)
+ {
+ if (regval & OTG_DIEPCTL_NAKSTS)
+ {
+ regval |= OTG_DIEPCTL_CNAK;
+ }
+
+ regval &= ~(OTG_DIEPCTL_MPSIZ_MASK | OTG_DIEPCTL_EPTYP_MASK | OTG_DIEPCTL_TXFNUM_MASK);
+ regval |= mpsiz;
+ regval |= (eptype << OTG_DIEPCTL_EPTYP_SHIFT);
+ regval |= (eptype << OTG_DIEPCTL_TXFNUM_SHIFT);
+ regval |= (OTG_DIEPCTL_SD0PID | OTG_DIEPCTL_USBAEP);
+ stm32_putreg(regval, regaddr);
+
+ /* Save the endpoint configuration */
+
+ privep->ep.maxpacket = maxpacket;
+ privep->eptype = eptype;
+ privep->stalled = false;
+ }
+
+ /* Enable the interrupt for this endpoint */
+
+ regval = stm32_getreg(STM32_OTG_DAINTMSK);
+ regval |= OTG_DAINT_IEP(privep->epphy);
+ stm32_putreg(regval, STM32_OTG_DAINTMSK);
+
+ return OK;
+}
+
+/****************************************************************************
+ * Name: stm32_ep_configure
+ *
+ * Description:
+ * Configure endpoint, making it usable
+ *
+ * Input Parameters:
+ * ep - the struct usbdev_ep_s instance obtained from allocep()
+ * desc - A struct usb_epdesc_s instance describing the endpoint
+ * last - true if this this last endpoint to be configured. Some hardware
+ * needs to take special action when all of the endpoints have been
+ * configured.
+ *
+ ****************************************************************************/
+
+static int stm32_ep_configure(FAR struct usbdev_ep_s *ep,
+ FAR const struct usb_epdesc_s *desc,
+ bool last)
+{
+ FAR struct stm32_ep_s *privep = (FAR struct stm32_ep_s *)ep;
+ uint16_t maxpacket;
+ uint8_t eptype;
+ int ret;
+
+ usbtrace(TRACE_EPCONFIGURE, privep->epphy);
+ DEBUGASSERT(desc->addr == ep->eplog);
+
+ /* Initialize EP capabilities */
+
+ maxpacket = GETUINT16(desc->mxpacketsize);
+ eptype = desc->attr & USB_EP_ATTR_XFERTYPE_MASK;
+
+ /* Setup Endpoint Control Register */
+
+ if (privep->isin)
+ {
+ ret = stm32_epin_configure(privep, eptype, maxpacket);
+ }
+ else
+ {
+ ret = stm32_epout_configure(privep, eptype, maxpacket);
+ }
+
+ return ret;
+}
+
+/****************************************************************************
+ * Name: stm32_ep0_configure
+ *
+ * Description:
+ * Reset Usb engine
+ *
+ ****************************************************************************/
+
+static void stm32_ep0_configure(FAR struct stm32_usbdev_s *priv)
+{
+ /* Enable EP0 IN and OUT */
+
+ (void)stm32_epin_configure(&priv->epin[EP0], USB_EP_ATTR_XFER_CONTROL,
+ CONFIG_USBDEV_EP0_MAXSIZE);
+ (void)stm32_epout_configure(&priv->epout[EP0], USB_EP_ATTR_XFER_CONTROL,
+ CONFIG_USBDEV_EP0_MAXSIZE);
+}
+
+/****************************************************************************
+ * Name: stm32_epout_disable
+ *
+ * Description:
+ * Diable an OUT endpoint will no longer be used
+ *
+ ****************************************************************************/
+
+static void stm32_epout_disable(FAR struct stm32_ep_s *privep)
+{
+ uint32_t regaddr;
+ uint32_t regval;
+ irqstate_t flags;
+
+ usbtrace(TRACE_EPDISABLE, privep->epphy);
+
+ /* Is this an IN or an OUT endpoint */
+
+ /* Before disabling any OUT endpoint, the application must enable
+ * Global OUT NAK mode in the core.
+ */
+
+ flags = enter_critical_section();
+ stm32_enablegonak(privep);
+
+ /* Disable the required OUT endpoint by setting the EPDIS and SNAK bits
+ * int DOECPTL register.
+ */
+
+ regaddr = STM32_OTG_DOEPCTL(privep->epphy);
+ regval = stm32_getreg(regaddr);
+ regval &= ~OTG_DOEPCTL_USBAEP;
+ regval |= (OTG_DOEPCTL_EPDIS | OTG_DOEPCTL_SNAK);
+ stm32_putreg(regval, regaddr);
+
+ /* Wait for the EPDISD interrupt which indicates that the OUT
+ * endpoint is completely disabled.
+ */
+
+#if 0 /* Doesn't happen */
+ regaddr = STM32_OTG_DOEPINT(privep->epphy);
+ while ((stm32_getreg(regaddr) & OTG_DOEPINT_EPDISD) == 0);
+#else
+ /* REVISIT: */
+ up_udelay(10);
+#endif
+
+ /* Clear the EPDISD interrupt indication */
+
+ stm32_putreg(OTG_DOEPINT_EPDISD, STM32_OTG_DOEPINT(privep->epphy));
+
+ /* Then disable the Global OUT NAK mode to continue receiving data
+ * from other non-disabled OUT endpoints.
+ */
+
+ stm32_disablegonak(privep);
+
+ /* Disable endpoint interrupts */
+
+ regval = stm32_getreg(STM32_OTG_DAINTMSK);
+ regval &= ~OTG_DAINT_OEP(privep->epphy);
+ stm32_putreg(regval, STM32_OTG_DAINTMSK);
+
+ /* Cancel any queued read requests */
+
+ stm32_req_cancel(privep, -ESHUTDOWN);
+
+ leave_critical_section(flags);
+}
+
+/****************************************************************************
+ * Name: stm32_epin_disable
+ *
+ * Description:
+ * Disable an IN endpoint when it will no longer be used
+ *
+ ****************************************************************************/
+
+static void stm32_epin_disable(FAR struct stm32_ep_s *privep)
+{
+ uint32_t regaddr;
+ uint32_t regval;
+ irqstate_t flags;
+
+ usbtrace(TRACE_EPDISABLE, privep->epphy);
+
+ /* After USB reset, the endpoint will already be deactivated by the
+ * hardware. Trying to disable again will just hang in the wait.
+ */
+
+ regaddr = STM32_OTG_DIEPCTL(privep->epphy);
+ regval = stm32_getreg(regaddr);
+ if ((regval & OTG_DIEPCTL_USBAEP) == 0)
+ {
+ return;
+ }
+
+ /* This INEPNE wait logic is suggested by reference manual, but seems
+ * to get stuck to infinite loop.
+ */
+
+#if 0
+ /* Make sure that there is no pending IPEPNE interrupt (because we are
+ * to poll this bit below).
+ */
+
+ stm32_putreg(OTG_DIEPINT_INEPNE, STM32_OTG_DIEPINT(privep->epphy));
+
+ /* Set the endpoint in NAK mode */
+
+ regaddr = STM32_OTG_DIEPCTL(privep->epphy);
+ regval = stm32_getreg(regaddr);
+ regval &= ~OTG_DIEPCTL_USBAEP;
+ regval |= (OTG_DIEPCTL_EPDIS | OTG_DIEPCTL_SNAK);
+ stm32_putreg(regval, regaddr);
+
+ /* Wait for the INEPNE interrupt that indicates that we are now in NAK mode */
+
+ regaddr = STM32_OTG_DIEPINT(privep->epphy);
+ while ((stm32_getreg(regaddr) & OTG_DIEPINT_INEPNE) == 0);
+
+ /* Clear the INEPNE interrupt indication */
+
+ stm32_putreg(OTG_DIEPINT_INEPNE, regaddr);
+#endif
+
+ /* Deactivate and disable the endpoint by setting the EPDIS and SNAK bits
+ * the DIEPCTLx register.
+ */
+
+ flags = enter_critical_section();
+ regaddr = STM32_OTG_DIEPCTL(privep->epphy);
+ regval = stm32_getreg(regaddr);
+ regval &= ~OTG_DIEPCTL_USBAEP;
+ regval |= (OTG_DIEPCTL_EPDIS | OTG_DIEPCTL_SNAK);
+ stm32_putreg(regval, regaddr);
+
+ /* Wait for the EPDISD interrupt which indicates that the IN
+ * endpoint is completely disabled.
+ */
+
+ regaddr = STM32_OTG_DIEPINT(privep->epphy);
+ while ((stm32_getreg(regaddr) & OTG_DIEPINT_EPDISD) == 0);
+
+ /* Clear the EPDISD interrupt indication */
+
+ stm32_putreg(OTG_DIEPINT_EPDISD, stm32_getreg(regaddr));
+
+ /* Flush any data remaining in the TxFIFO */
+
+ stm32_txfifo_flush(OTG_GRSTCTL_TXFNUM_D(privep->epphy));
+
+ /* Disable endpoint interrupts */
+
+ regval = stm32_getreg(STM32_OTG_DAINTMSK);
+ regval &= ~OTG_DAINT_IEP(privep->epphy);
+ stm32_putreg(regval, STM32_OTG_DAINTMSK);
+
+ /* Cancel any queued write requests */
+
+ stm32_req_cancel(privep, -ESHUTDOWN);
+ leave_critical_section(flags);
+}
+
+/****************************************************************************
+ * Name: stm32_ep_disable
+ *
+ * Description:
+ * The endpoint will no longer be used
+ *
+ ****************************************************************************/
+
+static int stm32_ep_disable(FAR struct usbdev_ep_s *ep)
+{
+ FAR struct stm32_ep_s *privep = (FAR struct stm32_ep_s *)ep;
+
+#ifdef CONFIG_DEBUG_FEATURES
+ if (!ep)
+ {
+ usbtrace(TRACE_DEVERROR(STM32_TRACEERR_INVALIDPARMS), 0);
+ return -EINVAL;
+ }
+#endif
+
+ usbtrace(TRACE_EPDISABLE, privep->epphy);
+
+ /* Is this an IN or an OUT endpoint */
+
+ if (privep->isin)
+ {
+ /* Disable the IN endpoint */
+
+ stm32_epin_disable(privep);
+ }
+ else
+ {
+ /* Disable the OUT endpoint */
+
+ stm32_epout_disable(privep);
+ }
+
+ return OK;
+}
+
+/****************************************************************************
+ * Name: stm32_ep_allocreq
+ *
+ * Description:
+ * Allocate an I/O request
+ *
+ ****************************************************************************/
+
+static FAR struct usbdev_req_s *stm32_ep_allocreq(FAR struct usbdev_ep_s *ep)
+{
+ FAR struct stm32_req_s *privreq;
+
+#ifdef CONFIG_DEBUG_FEATURES
+ if (!ep)
+ {
+ usbtrace(TRACE_DEVERROR(STM32_TRACEERR_INVALIDPARMS), 0);
+ return NULL;
+ }
+#endif
+
+ usbtrace(TRACE_EPALLOCREQ, ((FAR struct stm32_ep_s *)ep)->epphy);
+
+ privreq = (FAR struct stm32_req_s *)kmm_malloc(sizeof(struct stm32_req_s));
+ if (!privreq)
+ {
+ usbtrace(TRACE_DEVERROR(STM32_TRACEERR_ALLOCFAIL), 0);
+ return NULL;
+ }
+
+ memset(privreq, 0, sizeof(struct stm32_req_s));
+ return &privreq->req;
+}
+
+/****************************************************************************
+ * Name: stm32_ep_freereq
+ *
+ * Description:
+ * Free an I/O request
+ *
+ ****************************************************************************/
+
+static void stm32_ep_freereq(FAR struct usbdev_ep_s *ep, FAR struct usbdev_req_s *req)
+{
+ FAR struct stm32_req_s *privreq = (FAR struct stm32_req_s *)req;
+
+#ifdef CONFIG_DEBUG_FEATURES
+ if (!ep || !req)
+ {
+ usbtrace(TRACE_DEVERROR(STM32_TRACEERR_INVALIDPARMS), 0);
+ return;
+ }
+#endif
+
+ usbtrace(TRACE_EPFREEREQ, ((FAR struct stm32_ep_s *)ep)->epphy);
+ kmm_free(privreq);
+}
+
+/****************************************************************************
+ * Name: stm32_ep_allocbuffer
+ *
+ * Description:
+ * Allocate an I/O buffer
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_USBDEV_DMA
+static void *stm32_ep_allocbuffer(FAR struct usbdev_ep_s *ep, unsigned bytes)
+{
+ usbtrace(TRACE_EPALLOCBUFFER, privep->epphy);
+
+#ifdef CONFIG_USBDEV_DMAMEMORY
+ return usbdev_dma_alloc(bytes);
+#else
+ return kmm_malloc(bytes);
+#endif
+}
+#endif
+
+/****************************************************************************
+ * Name: stm32_ep_freebuffer
+ *
+ * Description:
+ * Free an I/O buffer
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_USBDEV_DMA
+static void stm32_ep_freebuffer(FAR struct usbdev_ep_s *ep, FAR void *buf)
+{
+ usbtrace(TRACE_EPFREEBUFFER, privep->epphy);
+
+#ifdef CONFIG_USBDEV_DMAMEMORY
+ usbdev_dma_free(buf);
+#else
+ kmm_free(buf);
+#endif
+}
+#endif
+
+/****************************************************************************
+ * Name: stm32_ep_submit
+ *
+ * Description:
+ * Submit an I/O request to the endpoint
+ *
+ ****************************************************************************/
+
+static int stm32_ep_submit(FAR struct usbdev_ep_s *ep, FAR struct usbdev_req_s *req)
+{
+ FAR struct stm32_req_s *privreq = (FAR struct stm32_req_s *)req;
+ FAR struct stm32_ep_s *privep = (FAR struct stm32_ep_s *)ep;
+ FAR struct stm32_usbdev_s *priv;
+ irqstate_t flags;
+ int ret = OK;
+
+ /* Some sanity checking */
+
+#ifdef CONFIG_DEBUG_FEATURES
+ if (!req || !req->callback || !req->buf || !ep)
+ {
+ usbtrace(TRACE_DEVERROR(STM32_TRACEERR_INVALIDPARMS), 0);
+ ullinfo("req=%p callback=%p buf=%p ep=%p\n", req, req->callback, req->buf, ep);
+ return -EINVAL;
+ }
+#endif
+
+ usbtrace(TRACE_EPSUBMIT, privep->epphy);
+ priv = privep->dev;
+
+#ifdef CONFIG_DEBUG_FEATURES
+ if (!priv->driver)
+ {
+ usbtrace(TRACE_DEVERROR(STM32_TRACEERR_NOTCONFIGURED), priv->usbdev.speed);
+ return -ESHUTDOWN;
+ }
+#endif
+
+ /* Handle the request from the class driver */
+
+ req->result = -EINPROGRESS;
+ req->xfrd = 0;
+
+ /* Disable Interrupts */
+
+ flags = enter_critical_section();
+
+ /* If we are stalled, then drop all requests on the floor */
+
+ if (privep->stalled)
+ {
+ ret = -EBUSY;
+ }
+ else
+ {
+ /* Add the new request to the request queue for the endpoint. */
+
+ if (stm32_req_addlast(privep, privreq) && !privep->active)
+ {
+ /* If a request was added to an IN endpoint, then attempt to send
+ * the request data buffer now.
+ */
+
+ if (privep->isin)
+ {
+ usbtrace(TRACE_INREQQUEUED(privep->epphy), privreq->req.len);
+
+ /* If the endpoint is not busy with another write request,
+ * then process the newly received write request now.
+ */
+
+ if (!privep->active)
+ {
+ stm32_epin_request(priv, privep);
+ }
+ }
+
+ /* If the request was added to an OUT endpoint, then attempt to
+ * setup a read into the request data buffer now (this will, of
+ * course, fail if there is already a read in place).
+ */
+
+ else
+ {
+ usbtrace(TRACE_OUTREQQUEUED(privep->epphy), privreq->req.len);
+ stm32_epout_request(priv, privep);
+ }
+ }
+ }
+
+ leave_critical_section(flags);
+ return ret;
+}
+
+/****************************************************************************
+ * Name: stm32_ep_cancel
+ *
+ * Description:
+ * Cancel an I/O request previously sent to an endpoint
+ *
+ ****************************************************************************/
+
+static int stm32_ep_cancel(FAR struct usbdev_ep_s *ep, FAR struct usbdev_req_s *req)
+{
+ FAR struct stm32_ep_s *privep = (FAR struct stm32_ep_s *)ep;
+ irqstate_t flags;
+
+#ifdef CONFIG_DEBUG_FEATURES
+ if (!ep || !req)
+ {
+ usbtrace(TRACE_DEVERROR(STM32_TRACEERR_INVALIDPARMS), 0);
+ return -EINVAL;
+ }
+#endif
+
+ usbtrace(TRACE_EPCANCEL, privep->epphy);
+
+ flags = enter_critical_section();
+
+ /* FIXME: if the request is the first, then we need to flush the EP
+ * otherwise just remove it from the list
+ *
+ * but ... all other implementations cancel all requests ...
+ */
+
+ stm32_req_cancel(privep, -ESHUTDOWN);
+ leave_critical_section(flags);
+ return OK;
+}
+
+/****************************************************************************
+ * Name: stm32_epout_setstall
+ *
+ * Description:
+ * Stall an OUT endpoint
+ *
+ ****************************************************************************/
+
+static int stm32_epout_setstall(FAR struct stm32_ep_s *privep)
+{
+#if 1
+ /* This implementation follows the requirements from the STM32 F4 reference
+ * manual.
+ */
+
+ uint32_t regaddr;
+ uint32_t regval;
+
+ /* Put the core in the Global OUT NAK mode */
+
+ stm32_enablegonak(privep);
+
+ /* Disable and STALL the OUT endpoint by setting the EPDIS and STALL bits
+ * in the DOECPTL register.
+ */
+
+ regaddr = STM32_OTG_DOEPCTL(privep->epphy);
+ regval = stm32_getreg(regaddr);
+ regval |= (OTG_DOEPCTL_EPDIS | OTG_DOEPCTL_STALL);
+ stm32_putreg(regval, regaddr);
+
+ /* Wait for the EPDISD interrupt which indicates that the OUT
+ * endpoint is completely disabled.
+ */
+
+#if 0 /* Doesn't happen */
+ regaddr = STM32_OTG_DOEPINT(privep->epphy);
+ while ((stm32_getreg(regaddr) & OTG_DOEPINT_EPDISD) == 0);
+#else
+ /* REVISIT: */
+ up_udelay(10);
+#endif
+
+ /* Disable Global OUT NAK mode */
+
+ stm32_disablegonak(privep);
+
+ /* The endpoint is now stalled */
+
+ privep->stalled = true;
+ return OK;
+#else
+ /* This implementation follows the STMicro code example. */
+ /* REVISIT: */
+
+ uint32_t regaddr;
+ uint32_t regval;
+
+ /* Stall the OUT endpoint by setting the STALL bit in the DOECPTL register. */
+
+ regaddr = STM32_OTG_DOEPCTL(privep->epphy);
+ regval = stm32_getreg(regaddr);
+ regval |= OTG_DOEPCTL_STALL;
+ stm32_putreg(regval, regaddr);
+
+ /* The endpoint is now stalled */
+
+ privep->stalled = true;
+ return OK;
+#endif
+}
+
+/****************************************************************************
+ * Name: stm32_epin_setstall
+ *
+ * Description:
+ * Stall an IN endpoint
+ *
+ ****************************************************************************/
+
+static int stm32_epin_setstall(FAR struct stm32_ep_s *privep)
+{
+ uint32_t regaddr;
+ uint32_t regval;
+
+ /* Get the IN endpoint device control register */
+
+ regaddr = STM32_OTG_DIEPCTL(privep->epphy);
+ regval = stm32_getreg(regaddr);
+
+ /* Then stall the endpoint */
+
+ regval |= OTG_DIEPCTL_STALL;
+ stm32_putreg(regval, regaddr);
+
+ /* The endpoint is now stalled */
+
+ privep->stalled = true;
+ return OK;
+}
+
+/****************************************************************************
+ * Name: stm32_ep_setstall
+ *
+ * Description:
+ * Stall an endpoint
+ *
+ ****************************************************************************/
+
+static int stm32_ep_setstall(FAR struct stm32_ep_s *privep)
+{
+ usbtrace(TRACE_EPSTALL, privep->epphy);
+
+ /* Is this an IN endpoint? */
+
+ if (privep->isin == 1)
+ {
+ return stm32_epin_setstall(privep);
+ }
+ else
+ {
+ return stm32_epout_setstall(privep);
+ }
+}
+
+/****************************************************************************
+ * Name: stm32_ep_clrstall
+ *
+ * Description:
+ * Resume a stalled endpoint
+ *
+ ****************************************************************************/
+
+static int stm32_ep_clrstall(FAR struct stm32_ep_s *privep)
+{
+ uint32_t regaddr;
+ uint32_t regval;
+ uint32_t stallbit;
+ uint32_t data0bit;
+
+ usbtrace(TRACE_EPRESUME, privep->epphy);
+
+ /* Is this an IN endpoint? */
+
+ if (privep->isin == 1)
+ {
+ /* Clear the stall bit in the IN endpoint device control register */
+
+ regaddr = STM32_OTG_DIEPCTL(privep->epphy);
+ stallbit = OTG_DIEPCTL_STALL;
+ data0bit = OTG_DIEPCTL_SD0PID;
+ }
+ else
+ {
+ /* Clear the stall bit in the IN endpoint device control register */
+
+ regaddr = STM32_OTG_DOEPCTL(privep->epphy);
+ stallbit = OTG_DOEPCTL_STALL;
+ data0bit = OTG_DOEPCTL_SD0PID;
+ }
+
+ /* Clear the stall bit */
+
+ regval = stm32_getreg(regaddr);
+ regval &= ~stallbit;
+
+ /* Set the DATA0 pid for interrupt and bulk endpoints */
+
+ if (privep->eptype == USB_EP_ATTR_XFER_INT ||
+ privep->eptype == USB_EP_ATTR_XFER_BULK)
+ {
+ /* Writing this bit sets the DATA0 PID */
+
+ regval |= data0bit;
+ }
+
+ stm32_putreg(regval, regaddr);
+
+ /* The endpoint is no longer stalled */
+
+ privep->stalled = false;
+ return OK;
+}
+
+/****************************************************************************
+ * Name: stm32_ep_stall
+ *
+ * Description:
+ * Stall or resume an endpoint
+ *
+ ****************************************************************************/
+
+static int stm32_ep_stall(FAR struct usbdev_ep_s *ep, bool resume)
+{
+ FAR struct stm32_ep_s *privep = (FAR struct stm32_ep_s *)ep;
+ irqstate_t flags;
+ int ret;
+
+ /* Set or clear the stall condition as requested */
+
+ flags = enter_critical_section();
+ if (resume)
+ {
+ ret = stm32_ep_clrstall(privep);
+ }
+ else
+ {
+ ret = stm32_ep_setstall(privep);
+ }
+ leave_critical_section(flags);
+
+ return ret;
+}
+
+/****************************************************************************
+ * Name: stm32_ep0_stall
+ *
+ * Description:
+ * Stall endpoint 0
+ *
+ ****************************************************************************/
+
+static void stm32_ep0_stall(FAR struct stm32_usbdev_s *priv)
+{
+ stm32_epin_setstall(&priv->epin[EP0]);
+ stm32_epout_setstall(&priv->epout[EP0]);
+ priv->stalled = true;
+ stm32_ep0out_ctrlsetup(priv);
+}
+
+/****************************************************************************
+ * Device operations
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: stm32_ep_alloc
+ *
+ * Description:
+ * Allocate an endpoint matching the parameters.
+ *
+ * Input Parameters:
+ * eplog - 7-bit logical endpoint number (direction bit ignored). Zero means
+ * that any endpoint matching the other requirements will suffice. The
+ * assigned endpoint can be found in the eplog field.
+ * in - true: IN (device-to-host) endpoint requested
+ * eptype - Endpoint type. One of {USB_EP_ATTR_XFER_ISOC, USB_EP_ATTR_XFER_BULK,
+ * USB_EP_ATTR_XFER_INT}
+ *
+ ****************************************************************************/
+
+static FAR struct usbdev_ep_s *stm32_ep_alloc(FAR struct usbdev_s *dev,
+ uint8_t eplog, bool in,
+ uint8_t eptype)
+{
+ FAR struct stm32_usbdev_s *priv = (FAR struct stm32_usbdev_s *)dev;
+ uint8_t epavail;
+ irqstate_t flags;
+ int epphy;
+ int epno = 0;
+
+ usbtrace(TRACE_DEVALLOCEP, (uint16_t)eplog);
+
+ /* Ignore any direction bits in the logical address */
+
+ epphy = USB_EPNO(eplog);
+
+ /* Get the set of available endpoints depending on the direction */
+
+ flags = enter_critical_section();
+ epavail = priv->epavail[in];
+
+ /* A physical address of 0 means that any endpoint will do */
+
+ if (epphy > 0)
+ {
+ /* Otherwise, we will return the endpoint structure only for the requested
+ * 'logical' endpoint. All of the other checks will still be performed.
+ *
+ * First, verify that the logical endpoint is in the range supported by
+ * by the hardware.
+ */
+
+ if (epphy >= STM32_NENDPOINTS)
+ {
+ usbtrace(TRACE_DEVERROR(STM32_TRACEERR_BADEPNO), (uint16_t)epphy);
+ return NULL;
+ }
+
+ /* Remove all of the candidate endpoints from the bitset except for the
+ * this physical endpoint number.
+ */
+
+ epavail &= (1 << epphy);
+ }
+
+ /* Is there an available endpoint? */
+
+ if (epavail)
+ {
+ /* Yes.. Select the lowest numbered endpoint in the set of available
+ * endpoints.
+ */
+
+ for (epno = 1; epno < STM32_NENDPOINTS; epno++)
+ {
+ uint8_t bit = 1 << epno;
+ if ((epavail & bit) != 0)
+ {
+ /* Mark the endpoint no longer available */
+
+ priv->epavail[in] &= ~(1 << epno);
+
+ /* And return the pointer to the standard endpoint structure */
+
+ leave_critical_section(flags);
+ return in ? &priv->epin[epno].ep : &priv->epout[epno].ep;
+ }
+ }
+
+ /* We should not get here */
+ }
+
+ usbtrace(TRACE_DEVERROR(STM32_TRACEERR_NOEP), (uint16_t)eplog);
+ leave_critical_section(flags);
+ return NULL;
+}
+
+/****************************************************************************
+ * Name: stm32_ep_free
+ *
+ * Description:
+ * Free the previously allocated endpoint
+ *
+ ****************************************************************************/
+
+static void stm32_ep_free(FAR struct usbdev_s *dev, FAR struct usbdev_ep_s *ep)
+{
+ FAR struct stm32_usbdev_s *priv = (FAR struct stm32_usbdev_s *)dev;
+ FAR struct stm32_ep_s *privep = (FAR struct stm32_ep_s *)ep;
+ irqstate_t flags;
+
+ usbtrace(TRACE_DEVFREEEP, (uint16_t)privep->epphy);
+
+ if (priv && privep)
+ {
+ /* Mark the endpoint as available */
+
+ flags = enter_critical_section();
+ priv->epavail[privep->isin] |= (1 << privep->epphy);
+ leave_critical_section(flags);
+ }
+}
+
+/****************************************************************************
+ * Name: stm32_getframe
+ *
+ * Description:
+ * Returns the current frame number
+ *
+ ****************************************************************************/
+
+static int stm32_getframe(struct usbdev_s *dev)
+{
+ uint32_t regval;
+
+ usbtrace(TRACE_DEVGETFRAME, 0);
+
+ /* Return the last frame number of the last SOF detected by the hardware */
+
+ regval = stm32_getreg(STM32_OTG_DSTS);
+ return (int)((regval & OTG_DSTS_SOFFN_MASK) >> OTG_DSTS_SOFFN_SHIFT);
+}
+
+/****************************************************************************
+ * Name: stm32_wakeup
+ *
+ * Description:
+ * Exit suspend mode.
+ *
+ ****************************************************************************/
+
+static int stm32_wakeup(struct usbdev_s *dev)
+{
+ FAR struct stm32_usbdev_s *priv = (FAR struct stm32_usbdev_s *)dev;
+ uint32_t regval;
+ irqstate_t flags;
+
+ usbtrace(TRACE_DEVWAKEUP, 0);
+
+ /* Is wakeup enabled? */
+
+ flags = enter_critical_section();
+ if (priv->wakeup)
+ {
+ /* Yes... is the core suspended? */
+
+ regval = stm32_getreg(STM32_OTG_DSTS);
+ if ((regval & OTG_DSTS_SUSPSTS) != 0)
+ {
+ /* Re-start the PHY clock and un-gate USB core clock (HCLK) */
+
+#ifdef CONFIG_USBDEV_LOWPOWER
+ regval = stm32_getreg(STM32_OTG_PCGCCTL);
+ regval &= ~(OTG_PCGCCTL_STPPCLK | OTG_PCGCCTL_GATEHCLK);
+ stm32_putreg(regval, STM32_OTG_PCGCCTL);
+#endif
+ /* Activate Remote wakeup signaling */
+
+ regval = stm32_getreg(STM32_OTG_DCTL);
+ regval |= OTG_DCTL_RWUSIG;
+ stm32_putreg(regval, STM32_OTG_DCTL);
+ up_mdelay(5);
+ regval &= ~OTG_DCTL_RWUSIG;
+ stm32_putreg(regval, STM32_OTG_DCTL);
+ }
+ }
+
+ leave_critical_section(flags);
+ return OK;
+}
+
+/****************************************************************************
+ * Name: stm32_selfpowered
+ *
+ * Description:
+ * Sets/clears the device self-powered feature
+ *
+ ****************************************************************************/
+
+static int stm32_selfpowered(struct usbdev_s *dev, bool selfpowered)
+{
+ FAR struct stm32_usbdev_s *priv = (FAR struct stm32_usbdev_s *)dev;
+
+ usbtrace(TRACE_DEVSELFPOWERED, (uint16_t)selfpowered);
+
+#ifdef CONFIG_DEBUG_FEATURES
+ if (!dev)
+ {
+ usbtrace(TRACE_DEVERROR(STM32_TRACEERR_INVALIDPARMS), 0);
+ return -ENODEV;
+ }
+#endif
+
+ priv->selfpowered = selfpowered;
+ return OK;
+}
+
+/****************************************************************************
+ * Name: stm32_pullup
+ *
+ * Description:
+ * Software-controlled connect to/disconnect from USB host
+ *
+ ****************************************************************************/
+
+static int stm32_pullup(struct usbdev_s *dev, bool enable)
+{
+ uint32_t regval;
+
+ usbtrace(TRACE_DEVPULLUP, (uint16_t)enable);
+
+ irqstate_t flags = enter_critical_section();
+ regval = stm32_getreg(STM32_OTG_DCTL);
+ if (enable)
+ {
+ /* Connect the device by clearing the soft disconnect bit in the DCTL
+ * register
+ */
+
+ regval &= ~OTG_DCTL_SDIS;
+ }
+ else
+ {
+ /* Connect the device by setting the soft disconnect bit in the DCTL
+ * register
+ */
+
+ regval |= OTG_DCTL_SDIS;
+ }
+
+ stm32_putreg(regval, STM32_OTG_DCTL);
+ leave_critical_section(flags);
+ return OK;
+}
+
+/****************************************************************************
+ * Name: stm32_setaddress
+ *
+ * Description:
+ * Set the devices USB address
+ *
+ ****************************************************************************/
+
+static void stm32_setaddress(struct stm32_usbdev_s *priv, uint16_t address)
+{
+ uint32_t regval;
+
+ /* Set the device address in the DCFG register */
+
+ regval = stm32_getreg(STM32_OTG_DCFG);
+ regval &= ~OTG_DCFG_DAD_MASK;
+ regval |= ((uint32_t)address << OTG_DCFG_DAD_SHIFT);
+ stm32_putreg(regval, STM32_OTG_DCFG);
+
+ /* Are we now addressed? (i.e., do we have a non-NULL device
+ * address?)
+ */
+
+ if (address != 0)
+ {
+ priv->devstate = DEVSTATE_ADDRESSED;
+ priv->addressed = true;
+ }
+ else
+ {
+ priv->devstate = DEVSTATE_DEFAULT;
+ priv->addressed = false;
+ }
+}
+
+/****************************************************************************
+ * Name: stm32_txfifo_flush
+ *
+ * Description:
+ * Flush the specific TX fifo.
+ *
+ ****************************************************************************/
+
+static int stm32_txfifo_flush(uint32_t txfnum)
+{
+ uint32_t regval;
+ uint32_t timeout;
+
+ /* Initiate the TX FIFO flush operation */
+
+ regval = OTG_GRSTCTL_TXFFLSH | txfnum;
+ stm32_putreg(regval, STM32_OTG_GRSTCTL);
+
+ /* Wait for the FLUSH to complete */
+
+ for (timeout = 0; timeout < STM32_FLUSH_DELAY; timeout++)
+ {
+ regval = stm32_getreg(STM32_OTG_GRSTCTL);
+ if ((regval & OTG_GRSTCTL_TXFFLSH) == 0)
+ {
+ break;
+ }
+ }
+
+ /* Wait for 3 PHY Clocks */
+
+ up_udelay(3);
+ return OK;
+}
+
+/****************************************************************************
+ * Name: stm32_rxfifo_flush
+ *
+ * Description:
+ * Flush the RX fifo.
+ *
+ ****************************************************************************/
+
+static int stm32_rxfifo_flush(void)
+{
+ uint32_t regval;
+ uint32_t timeout;
+
+ /* Initiate the RX FIFO flush operation */
+
+ stm32_putreg(OTG_GRSTCTL_RXFFLSH, STM32_OTG_GRSTCTL);
+
+ /* Wait for the FLUSH to complete */
+
+ for (timeout = 0; timeout < STM32_FLUSH_DELAY; timeout++)
+ {
+ regval = stm32_getreg(STM32_OTG_GRSTCTL);
+ if ((regval & OTG_GRSTCTL_RXFFLSH) == 0)
+ {
+ break;
+ }
+ }
+
+ /* Wait for 3 PHY Clocks */
+
+ up_udelay(3);
+ return OK;
+}
+
+/****************************************************************************
+ * Name: stm32_swinitialize
+ *
+ * Description:
+ * Initialize all driver data structures.
+ *
+ ****************************************************************************/
+
+static void stm32_swinitialize(FAR struct stm32_usbdev_s *priv)
+{
+ FAR struct stm32_ep_s *privep;
+ int i;
+
+ /* Initialize the device state structure */
+
+ memset(priv, 0, sizeof(struct stm32_usbdev_s));
+
+ priv->usbdev.ops = &g_devops;
+ priv->usbdev.ep0 = &priv->epin[EP0].ep;
+
+ priv->epavail[0] = STM32_EP_AVAILABLE;
+ priv->epavail[1] = STM32_EP_AVAILABLE;
+
+ priv->epin[EP0].ep.priv = priv;
+ priv->epout[EP0].ep.priv = priv;
+
+ /* Initialize the endpoint lists */
+
+ for (i = 0; i < STM32_NENDPOINTS; i++)
+ {
+ /* Set endpoint operations, reference to driver structure (not
+ * really necessary because there is only one controller), and
+ * the physical endpoint number (which is just the index to the
+ * endpoint).
+ */
+
+ privep = &priv->epin[i];
+ privep->ep.ops = &g_epops;
+ privep->dev = priv;
+ privep->isin = 1;
+
+ /* The index, i, is the physical endpoint address; Map this
+ * to a logical endpoint address usable by the class driver.
+ */
+
+ privep->epphy = i;
+ privep->ep.eplog = STM32_EPPHYIN2LOG(i);
+
+ /* Control until endpoint is activated */
+
+ privep->eptype = USB_EP_ATTR_XFER_CONTROL;
+ privep->ep.maxpacket = CONFIG_USBDEV_EP0_MAXSIZE;
+ }
+
+ /* Initialize the endpoint lists */
+
+ for (i = 0; i < STM32_NENDPOINTS; i++)
+ {
+ /* Set endpoint operations, reference to driver structure (not
+ * really necessary because there is only one controller), and
+ * the physical endpoint number (which is just the index to the
+ * endpoint).
+ */
+
+ privep = &priv->epout[i];
+ privep->ep.ops = &g_epops;
+ privep->dev = priv;
+
+ /* The index, i, is the physical endpoint address; Map this
+ * to a logical endpoint address usable by the class driver.
+ */
+
+ privep->epphy = i;
+ privep->ep.eplog = STM32_EPPHYOUT2LOG(i);
+
+ /* Control until endpoint is activated */
+
+ privep->eptype = USB_EP_ATTR_XFER_CONTROL;
+ privep->ep.maxpacket = CONFIG_USBDEV_EP0_MAXSIZE;
+ }
+}
+
+/****************************************************************************
+ * Name: stm32_hwinitialize
+ *
+ * Description:
+ * Configure the OTG core for operation.
+ *
+ ****************************************************************************/
+
+static void stm32_hwinitialize(FAR struct stm32_usbdev_s *priv)
+{
+ uint32_t regval;
+ uint32_t timeout;
+ uint32_t address;
+ int i;
+
+ /* At start-up the core is in FS/HS mode. */
+
+ /* Disable global interrupts by clearing the GINTMASK bit in the GAHBCFG
+ * register; Set the TXFELVL bit in the GAHBCFG register so that TxFIFO
+ * interrupts will occur when the TxFIFO is truly empty (not just half full).
+ */
+
+ stm32_putreg(OTG_GAHBCFG_TXFELVL, STM32_OTG_GAHBCFG);
+
+#if defined(CONFIG_STM32_OTGHS)
+ /* Set the PHYSEL bit in the GUSBCFG register to select the OTG HS serial
+ * transceiver: "This bit is always 1 with write-only access"
+ */
+
+ regval = stm32_getreg(STM32_OTG_GUSBCFG);
+ regval |= OTG_GUSBCFG_PHYSEL;
+ stm32_putreg(regval, STM32_OTG_GUSBCFG);
+#endif
+
+ /* Common USB OTG core initialization */
+ /* Reset after a PHY select and set Host mode. First, wait for AHB master
+ * IDLE state.
+ */
+
+ for (timeout = 0; timeout < STM32_READY_DELAY; timeout++)
+ {
+ up_udelay(3);
+ regval = stm32_getreg(STM32_OTG_GRSTCTL);
+ if ((regval & OTG_GRSTCTL_AHBIDL) != 0)
+ {
+ break;
+ }
+ }
+
+ /* Then perform the core soft reset. */
+
+ stm32_putreg(OTG_GRSTCTL_CSRST, STM32_OTG_GRSTCTL);
+ for (timeout = 0; timeout < STM32_READY_DELAY; timeout++)
+ {
+ regval = stm32_getreg(STM32_OTG_GRSTCTL);
+ if ((regval & OTG_GRSTCTL_CSRST) == 0)
+ {
+ break;
+ }
+ }
+
+ /* Wait for 3 PHY Clocks */
+
+ up_udelay(3);
+
+ /* Deactivate the power down */
+
+
+ /* Detection Enable when set
+ */
+
+ regval = OTG_GCCFG_PWRDWN;
+
+# ifdef CONFIG_USBDEV_VBUSSENSING
+ regval |= OTG_GCCFG_VBDEN;
+# endif
+
+
+ stm32_putreg(regval, STM32_OTG_GCCFG);
+ up_mdelay(20);
+
+ /* When VBUS sensing is not used we
+ * need to force the B session valid
+ */
+
+
+# ifndef CONFIG_USBDEV_VBUSSENSING
+ regval = stm32_getreg(STM32_OTG_GOTGCTL);
+ regval |= (OTG_GOTGCTL_BVALOEN | OTG_GOTGCTL_BVALOVAL);
+ stm32_putreg(regval, STM32_OTG_GOTGCTL);
+# endif
+
+
+ /* Force Device Mode */
+
+ regval = stm32_getreg(STM32_OTG_GUSBCFG);
+ regval &= ~OTG_GUSBCFG_FHMOD;
+ regval |= OTG_GUSBCFG_FDMOD;
+ stm32_putreg(regval, STM32_OTG_GUSBCFG);
+ up_mdelay(50);
+
+ /* Initialize device mode */
+ /* Restart the PHY Clock */
+
+ stm32_putreg(0, STM32_OTG_PCGCCTL);
+
+ /* Device configuration register */
+
+ regval = stm32_getreg(STM32_OTG_DCFG);
+ regval &= ~OTG_DCFG_PFIVL_MASK;
+ regval |= OTG_DCFG_PFIVL_80PCT;
+ stm32_putreg(regval, STM32_OTG_DCFG);
+
+ /* Set full speed PHY */
+
+ regval = stm32_getreg(STM32_OTG_DCFG);
+ regval &= ~OTG_DCFG_DSPD_MASK;
+ regval |= OTG_DCFG_DSPD_FS;
+ stm32_putreg(regval, STM32_OTG_DCFG);
+
+ /* Set Rx FIFO size */
+
+ stm32_putreg(STM32_RXFIFO_WORDS, STM32_OTG_GRXFSIZ);
+
+ /* EP0 TX */
+
+ address = STM32_RXFIFO_WORDS;
+ regval = (address << OTG_DIEPTXF0_TX0FD_SHIFT) |
+ (STM32_EP0_TXFIFO_WORDS << OTG_DIEPTXF0_TX0FSA_SHIFT);
+ stm32_putreg(regval, STM32_OTG_DIEPTXF0);
+
+ /* EP1 TX */
+
+ address += STM32_EP0_TXFIFO_WORDS;
+ regval = (address << OTG_DIEPTXF_INEPTXSA_SHIFT) |
+ (STM32_EP1_TXFIFO_WORDS << OTG_DIEPTXF_INEPTXFD_SHIFT);
+ stm32_putreg(regval, STM32_OTG_DIEPTXF1);
+
+ /* EP2 TX */
+
+ address += STM32_EP1_TXFIFO_WORDS;
+ regval = (address << OTG_DIEPTXF_INEPTXSA_SHIFT) |
+ (STM32_EP2_TXFIFO_WORDS << OTG_DIEPTXF_INEPTXFD_SHIFT);
+ stm32_putreg(regval, STM32_OTG_DIEPTXF2);
+
+ /* EP3 TX */
+
+ address += STM32_EP2_TXFIFO_WORDS;
+ regval = (address << OTG_DIEPTXF_INEPTXSA_SHIFT) |
+ (STM32_EP3_TXFIFO_WORDS << OTG_DIEPTXF_INEPTXFD_SHIFT);
+ stm32_putreg(regval, STM32_OTG_DIEPTXF3);
+
+ /* Flush the FIFOs */
+
+ stm32_txfifo_flush(OTG_GRSTCTL_TXFNUM_DALL);
+ stm32_rxfifo_flush();
+
+ /* Clear all pending Device Interrupts */
+
+ stm32_putreg(0, STM32_OTG_DIEPMSK);
+ stm32_putreg(0, STM32_OTG_DOEPMSK);
+ stm32_putreg(0, STM32_OTG_DIEPEMPMSK);
+ stm32_putreg(0xffffffff, STM32_OTG_DAINT);
+ stm32_putreg(0, STM32_OTG_DAINTMSK);
+
+ /* Configure all IN endpoints */
+
+ for (i = 0; i < STM32_NENDPOINTS; i++)
+ {
+ regval = stm32_getreg(STM32_OTG_DIEPCTL(i));
+ if ((regval & OTG_DIEPCTL_EPENA) != 0)
+ {
+ /* The endpoint is already enabled */
+
+ regval = OTG_DIEPCTL_EPENA | OTG_DIEPCTL_SNAK;
+ }
+ else
+ {
+ regval = 0;
+ }
+
+ stm32_putreg(regval, STM32_OTG_DIEPCTL(i));
+ stm32_putreg(0, STM32_OTG_DIEPTSIZ(i));
+ stm32_putreg(0xff, STM32_OTG_DIEPINT(i));
+ }
+
+ /* Configure all OUT endpoints */
+
+ for (i = 0; i < STM32_NENDPOINTS; i++)
+ {
+ regval = stm32_getreg(STM32_OTG_DOEPCTL(i));
+ if ((regval & OTG_DOEPCTL_EPENA) != 0)
+ {
+ /* The endpoint is already enabled */
+
+ regval = OTG_DOEPCTL_EPENA | OTG_DOEPCTL_SNAK;
+ }
+ else
+ {
+ regval = 0;
+ }
+
+ stm32_putreg(regval, STM32_OTG_DOEPCTL(i));
+ stm32_putreg(0, STM32_OTG_DOEPTSIZ(i));
+ stm32_putreg(0xff, STM32_OTG_DOEPINT(i));
+ }
+
+ /* Disable all interrupts. */
+
+ stm32_putreg(0, STM32_OTG_GINTMSK);
+
+ /* Clear any pending USB_OTG Interrupts */
+
+ stm32_putreg(0xffffffff, STM32_OTG_GOTGINT);
+
+ /* Clear any pending interrupts */
+
+ stm32_putreg(0xbfffffff, STM32_OTG_GINTSTS);
+
+#ifdef defined(CONFIG_STM32_OTGHS)
+ /* Disable the ULPI Clock enable in RCC AHB1 Register. This must
+ * be done because if both the ULPI and the FS PHY clock enable bits
+ * are set at the same time, the ARM never awakens from WFI due to
+ * some bug / errata in the chip.
+ */
+
+ regval = stm32_getreg(STM32_RCC_AHB1LPENR);
+ regval &= ~RCC_AHB1ENR_OTGULPIEN;
+ stm32_putreg(regval, STM32_RCC_AHB1LPENR);
+#endif
+
+ /* Enable the interrupts in the INTMSK */
+
+ regval = (OTG_GINT_RXFLVL | OTG_GINT_USBSUSP | OTG_GINT_ENUMDNE |
+ OTG_GINT_IEP | OTG_GINT_OEP | OTG_GINT_USBRST);
+
+#ifdef CONFIG_USBDEV_ISOCHRONOUS
+ regval |= (OTG_GINT_IISOIXFR | OTG_GINT_IISOOXFR);
+#endif
+
+#ifdef CONFIG_USBDEV_SOFINTERRUPT
+ regval |= OTG_GINT_SOF;
+#endif
+
+#ifdef CONFIG_USBDEV_VBUSSENSING
+ regval |= (OTG_GINT_OTG | OTG_GINT_SRQ);
+#endif
+
+#ifdef CONFIG_DEBUG_USB
+ regval |= OTG_GINT_MMIS;
+#endif
+
+ stm32_putreg(regval, STM32_OTG_GINTMSK);
+
+ /* Enable the USB global interrupt by setting GINTMSK in the global OTG
+ * AHB configuration register; Set the TXFELVL bit in the GAHBCFG
+ * register so that TxFIFO interrupts will occur when the TxFIFO is truly
+ * empty (not just half full).
+ */
+
+ stm32_putreg(OTG_GAHBCFG_GINTMSK | OTG_GAHBCFG_TXFELVL,
+ STM32_OTG_GAHBCFG);
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: up_usbinitialize
+ *
+ * Description:
+ * Initialize USB hardware.
+ *
+ * Assumptions:
+ * - This function is called very early in the initialization sequence
+ * - PLL and GIO pin initialization is not performed here but should been in
+ * the low-level boot logic: PLL1 must be configured for operation at 48MHz
+ * and P0.23 and PO.31 in PINSEL1 must be configured for Vbus and USB connect
+ * LED.
+ *
+ ****************************************************************************/
+
+void up_usbinitialize(void)
+{
+ /* At present, there is only a single OTG device support. Hence it is
+ * pre-allocated as g_otghsdev. However, in most code, the private data
+ * structure will be referenced using the 'priv' pointer (rather than the
+ * global data) in order to simplify any future support for multiple devices.
+ */
+
+ FAR struct stm32_usbdev_s *priv = &g_otghsdev;
+ int ret;
+
+ usbtrace(TRACE_DEVINIT, 0);
+
+ /* Here we assume that:
+ *
+ * 1. GPIOA and OTG peripheral clocking has already been enabled as part
+ * of the boot sequence.
+ * 2. Board-specific logic has already enabled other board specific GPIOs
+ * for things like soft pull-up, VBUS sensing, power controls, and over-
+ * current detection.
+ */
+
+ /* Configure OTG alternate function pins
+ */
+
+ stm32_configgpio(GPIO_OTG_DM);
+ stm32_configgpio(GPIO_OTG_DP);
+ stm32_configgpio(GPIO_OTG_ID); /* Only needed for OTG */
+
+ /* SOF output pin configuration is configurable. */
+
+#ifdef CONFIG_STM32_OTG_SOFOUTPUT
+ stm32_configgpio(GPIO_OTG_SOF);
+#endif
+
+ /* Uninitialize the hardware so that we know that we are starting from a
+ * known state. */
+
+ up_usbuninitialize();
+
+ /* Initialie the driver data structure */
+
+ stm32_swinitialize(priv);
+
+ /* Attach the OTG interrupt handler */
+
+ ret = irq_attach(STM32_IRQ_OTG, stm32_usbinterrupt);
+ if (ret < 0)
+ {
+ uerr("irq_attach failed\n", ret);
+ goto errout;
+ }
+
+ /* Initialize the USB OTG core */
+
+ stm32_hwinitialize(priv);
+
+ /* Disconnect device */
+
+ stm32_pullup(&priv->usbdev, false);
+
+ /* Reset/Re-initialize the USB hardware */
+
+ stm32_usbreset(priv);
+
+ /* Enable USB controller interrupts at the NVIC */
+
+ up_enable_irq(STM32_IRQ_OTG);
+
+#ifdef CONFIG_ARCH_IRQPRIO
+ /* Set the interrupt priority */
+
+ up_prioritize_irq(STM32_IRQ_OTG, CONFIG_OTG_PRI);
+#endif
+ return;
+
+errout:
+ up_usbuninitialize();
+}
+
+/****************************************************************************
+ * Name: up_usbuninitialize
+ ****************************************************************************/
+
+void up_usbuninitialize(void)
+{
+ /* At present, there is only a single OTG device support. Hence it is
+ * pre-allocated as g_otghsdev. However, in most code, the private data
+ * structure will be referenced using the 'priv' pointer (rather than the
+ * global data) in order to simplify any future support for multiple devices.
+ */
+
+ FAR struct stm32_usbdev_s *priv = &g_otghsdev;
+ irqstate_t flags;
+ int i;
+
+ usbtrace(TRACE_DEVUNINIT, 0);
+
+ if (priv->driver)
+ {
+ usbtrace(TRACE_DEVERROR(STM32_TRACEERR_DRIVERREGISTERED), 0);
+ usbdev_unregister(priv->driver);
+ }
+
+ /* Disconnect device */
+
+ flags = enter_critical_section();
+ stm32_pullup(&priv->usbdev, false);
+ priv->usbdev.speed = USB_SPEED_UNKNOWN;
+
+ /* Disable and detach IRQs */
+
+ up_disable_irq(STM32_IRQ_OTG);
+ irq_detach(STM32_IRQ_OTG);
+
+ /* Disable all endpoint interrupts */
+
+ for (i = 0; i < STM32_NENDPOINTS; i++)
+ {
+ stm32_putreg(0xff, STM32_OTG_DIEPINT(i));
+ stm32_putreg(0xff, STM32_OTG_DOEPINT(i));
+ }
+
+ stm32_putreg(0, STM32_OTG_DIEPMSK);
+ stm32_putreg(0, STM32_OTG_DOEPMSK);
+ stm32_putreg(0, STM32_OTG_DIEPEMPMSK);
+ stm32_putreg(0, STM32_OTG_DAINTMSK);
+ stm32_putreg(0xffffffff, STM32_OTG_DAINT);
+
+ /* Flush the FIFOs */
+
+ stm32_txfifo_flush(OTG_GRSTCTL_TXFNUM_DALL);
+ stm32_rxfifo_flush();
+
+ /* TODO: Turn off USB power and clocking */
+
+ priv->devstate = DEVSTATE_DEFAULT;
+ leave_critical_section(flags);
+}
+
+/****************************************************************************
+ * Name: usbdev_register
+ *
+ * Description:
+ * Register a USB device class driver. The class driver's bind() method will be
+ * called to bind it to a USB device driver.
+ *
+ ****************************************************************************/
+
+int usbdev_register(struct usbdevclass_driver_s *driver)
+{
+ /* At present, there is only a single OTG device support. Hence it is
+ * pre-allocated as g_otghsdev. However, in most code, the private data
+ * structure will be referenced using the 'priv' pointer (rather than the
+ * global data) in order to simplify any future support for multiple devices.
+ */
+
+ FAR struct stm32_usbdev_s *priv = &g_otghsdev;
+ int ret;
+
+ usbtrace(TRACE_DEVREGISTER, 0);
+
+#ifdef CONFIG_DEBUG_FEATURES
+ if (!driver || !driver->ops->bind || !driver->ops->unbind ||
+ !driver->ops->disconnect || !driver->ops->setup)
+ {
+ usbtrace(TRACE_DEVERROR(STM32_TRACEERR_INVALIDPARMS), 0);
+ return -EINVAL;
+ }
+
+ if (priv->driver)
+ {
+ usbtrace(TRACE_DEVERROR(STM32_TRACEERR_DRIVER), 0);
+ return -EBUSY;
+ }
+#endif
+
+ /* First hook up the driver */
+
+ priv->driver = driver;
+
+ /* Then bind the class driver */
+
+ ret = CLASS_BIND(driver, &priv->usbdev);
+ if (ret)
+ {
+ usbtrace(TRACE_DEVERROR(STM32_TRACEERR_BINDFAILED), (uint16_t)-ret);
+ priv->driver = NULL;
+ }
+ else
+ {
+ /* Enable USB controller interrupts */
+
+ up_enable_irq(STM32_IRQ_OTG);
+
+ /* FIXME: nothing seems to call DEV_CONNECT(), but we need to set
+ * the RS bit to enable the controller. It kind of makes sense
+ * to do this after the class has bound to us...
+ * GEN: This bug is really in the class driver. It should make the
+ * soft connect when it is ready to be enumerated. I have added
+ * that logic to the class drivers but left this logic here.
+ */
+
+ stm32_pullup(&priv->usbdev, true);
+ priv->usbdev.speed = USB_SPEED_FULL;
+ }
+
+ return ret;
+}
+
+/****************************************************************************
+ * Name: usbdev_unregister
+ *
+ * Description:
+ * Un-register usbdev class driver.If the USB device is connected to a USB host,
+ * it will first disconnect(). The driver is also requested to unbind() and clean
+ * up any device state, before this procedure finally returns.
+ *
+ ****************************************************************************/
+
+int usbdev_unregister(struct usbdevclass_driver_s *driver)
+{
+ /* At present, there is only a single OTG device support. Hence it is
+ * pre-allocated as g_otghsdev. However, in most code, the private data
+ * structure will be referenced using the 'priv' pointer (rather than the
+ * global data) in order to simplify any future support for multiple devices.
+ */
+
+ FAR struct stm32_usbdev_s *priv = &g_otghsdev;
+ irqstate_t flags;
+
+ usbtrace(TRACE_DEVUNREGISTER, 0);
+
+#ifdef CONFIG_DEBUG_FEATURES
+ if (driver != priv->driver)
+ {
+ usbtrace(TRACE_DEVERROR(STM32_TRACEERR_INVALIDPARMS), 0);
+ return -EINVAL;
+ }
+#endif
+
+ /* Reset the hardware and cancel all requests. All requests must be
+ * canceled while the class driver is still bound.
+ */
+
+ flags = enter_critical_section();
+ stm32_usbreset(priv);
+ leave_critical_section(flags);
+
+ /* Unbind the class driver */
+
+ CLASS_UNBIND(driver, &priv->usbdev);
+
+ /* Disable USB controller interrupts */
+
+ flags = enter_critical_section();
+ up_disable_irq(STM32_IRQ_OTG);
+
+ /* Disconnect device */
+
+ stm32_pullup(&priv->usbdev, false);
+
+ /* Unhook the driver */
+
+ priv->driver = NULL;
+ leave_critical_section(flags);
+
+ return OK;
+}
+
+#endif /* CONFIG_USBDEV && CONFIG_STM32_OTGDEV */
diff --git a/arch/arm/src/stm32f7/stm32_otghost.c b/arch/arm/src/stm32f7/stm32_otghost.c
new file mode 100644
index 0000000000..cc00b1336f
--- /dev/null
+++ b/arch/arm/src/stm32f7/stm32_otghost.c
@@ -0,0 +1,5306 @@
+/****************************************************************************
+ * arch/arm/src/stm32f7/stm32_otghost.c
+ *
+ * Copyright (C) 2012-2016 Gregory Nutt. All rights reserved.
+ * Authors: Gregory Nutt
+ *
+ * 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
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include
+
+#include "chip.h" /* Includes default GPIO settings */
+#include /* May redefine GPIO settings */
+
+#include "up_arch.h"
+#include "up_internal.h"
+
+#include "stm32_otg.h"
+
+#if defined(CONFIG_USBHOST) && defined(CONFIG_STM32_OTGFS)
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+/* Configuration ***************************************************************/
+/* STM32 USB OTG FS Host Driver Support
+ *
+ * Pre-requisites
+ *
+ * CONFIG_USBHOST - Enable general USB host support
+ * CONFIG_STM32_OTGFS - Enable the STM32 USB OTG FS block
+ * CONFIG_STM32_SYSCFG - Needed
+ *
+ * Options:
+ *
+ * CONFIG_STM32_OTG_RXFIFO_SIZE - Size of the RX FIFO in 32-bit words.
+ * Default 128 (512 bytes)
+ * CONFIG_STM32_OTG_NPTXFIFO_SIZE - Size of the non-periodic Tx FIFO
+ * in 32-bit words. Default 96 (384 bytes)
+ * CONFIG_STM32_OTG_PTXFIFO_SIZE - Size of the periodic Tx FIFO in 32-bit
+ * words. Default 96 (384 bytes)
+ * CONFIG_STM32_OTG_DESCSIZE - Maximum size of a descriptor. Default: 128
+ * CONFIG_STM32_OTG_SOFINTR - Enable SOF interrupts. Why would you ever
+ * want to do that?
+ * CONFIG_STM32_USBHOST_REGDEBUG - Enable very low-level register access
+ * debug. Depends on CONFIG_DEBUG_FEATURES.
+ * CONFIG_STM32_USBHOST_PKTDUMP - Dump all incoming and outgoing USB
+ * packets. Depends on CONFIG_DEBUG_FEATURES.
+ */
+
+/* Pre-requisites (partial) */
+
+#ifndef CONFIG_STM32_SYSCFG
+# error "CONFIG_STM32_SYSCFG is required"
+#endif
+
+/* Default RxFIFO size */
+
+#ifndef CONFIG_STM32_OTG_RXFIFO_SIZE
+# define CONFIG_STM32_OTG_RXFIFO_SIZE 128
+#endif
+
+/* Default host non-periodic Tx FIFO size */
+
+#ifndef CONFIG_STM32_OTG_NPTXFIFO_SIZE
+# define CONFIG_STM32_OTG_NPTXFIFO_SIZE 96
+#endif
+
+/* Default host periodic Tx fifo size register */
+
+#ifndef CONFIG_STM32_OTG_PTXFIFO_SIZE
+# define CONFIG_STM32_OTG_PTXFIFO_SIZE 96
+#endif
+
+/* Maximum size of a descriptor */
+
+#ifndef CONFIG_STM32_OTG_DESCSIZE
+# define CONFIG_STM32_OTG_DESCSIZE 128
+#endif
+
+/* Register/packet debug depends on CONFIG_DEBUG_FEATURES */
+
+#ifndef CONFIG_DEBUG_FEATURES
+# undef CONFIG_STM32_USBHOST_REGDEBUG
+# undef CONFIG_STM32_USBHOST_PKTDUMP
+#endif
+
+/* HCD Setup *******************************************************************/
+/* Hardware capabilities */
+
+#define STM32_NHOST_CHANNELS 8 /* Number of host channels */
+#define STM32_MAX_PACKET_SIZE 64 /* Full speed max packet size */
+#define STM32_EP0_DEF_PACKET_SIZE 8 /* EP0 default packet size */
+#define STM32_EP0_MAX_PACKET_SIZE 64 /* EP0 FS max packet size */
+#define STM32_MAX_TX_FIFOS 15 /* Max number of TX FIFOs */
+#define STM32_MAX_PKTCOUNT 256 /* Max packet count */
+#define STM32_RETRY_COUNT 3 /* Number of ctrl transfer retries */
+
+/* Delays **********************************************************************/
+
+#define STM32_READY_DELAY 200000 /* In loop counts */
+#define STM32_FLUSH_DELAY 200000 /* In loop counts */
+#define STM32_SETUP_DELAY SEC2TICK(5) /* 5 seconds in system ticks */
+#define STM32_DATANAK_DELAY SEC2TICK(5) /* 5 seconds in system ticks */
+
+/* Ever-present MIN/MAX macros */
+
+#ifndef MIN
+# define MIN(a, b) (((a) < (b)) ? (a) : (b))
+#endif
+
+#ifndef MAX
+# define MAX(a, b) (((a) > (b)) ? (a) : (b))
+#endif
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+/* The following enumeration represents the various states of the USB host
+ * state machine (for debug purposes only)
+ */
+
+enum stm32_smstate_e
+{
+ SMSTATE_DETACHED = 0, /* Not attached to a device */
+ SMSTATE_ATTACHED, /* Attached to a device */
+ SMSTATE_ENUM, /* Attached, enumerating */
+ SMSTATE_CLASS_BOUND, /* Enumeration complete, class bound */
+};
+
+/* This enumeration provides the reason for the channel halt. */
+
+enum stm32_chreason_e
+{
+ CHREASON_IDLE = 0, /* Inactive (initial state) */
+ CHREASON_FREED, /* Channel is no longer in use */
+ CHREASON_XFRC, /* Transfer complete */
+ CHREASON_NAK, /* NAK received */
+ CHREASON_NYET, /* NotYet received */
+ CHREASON_STALL, /* Endpoint stalled */
+ CHREASON_TXERR, /* Transfer error received */
+ CHREASON_DTERR, /* Data toggle error received */
+ CHREASON_FRMOR, /* Frame overrun */
+ CHREASON_CANCELLED /* Transfer cancelled */
+};
+
+/* This structure retains the state of one host channel. NOTE: Since there
+ * is only one channel operation active at a time, some of the fields in
+ * in the structure could be moved in struct stm32_ubhost_s to achieve
+ * some memory savings.
+ */
+
+struct stm32_chan_s
+{
+ sem_t waitsem; /* Channel wait semaphore */
+ volatile uint8_t result; /* The result of the transfer */
+ volatile uint8_t chreason; /* Channel halt reason. See enum stm32_chreason_e */
+ uint8_t chidx; /* Channel index */
+ uint8_t epno; /* Device endpoint number (0-127) */
+ uint8_t eptype; /* See OTG_EPTYPE_* definitions */
+ uint8_t funcaddr; /* Device function address */
+ uint8_t speed; /* Device speed */
+ uint8_t pid; /* Data PID */
+ uint8_t npackets; /* Number of packets (for data toggle) */
+ bool inuse; /* True: This channel is "in use" */
+ volatile bool indata1; /* IN data toggle. True: DATA01 (Bulk and INTR only) */
+ volatile bool outdata1; /* OUT data toggle. True: DATA01 */
+ bool in; /* True: IN endpoint */
+ volatile bool waiter; /* True: Thread is waiting for a channel event */
+ uint16_t maxpacket; /* Max packet size */
+ uint16_t buflen; /* Buffer length (at start of transfer) */
+ volatile uint16_t xfrd; /* Bytes transferred (at end of transfer) */
+ volatile uint16_t inflight; /* Number of Tx bytes "in-flight" */
+ FAR uint8_t *buffer; /* Transfer buffer pointer */
+#ifdef CONFIG_USBHOST_ASYNCH
+ usbhost_asynch_t callback; /* Transfer complete callback */
+ FAR void *arg; /* Argument that accompanies the callback */
+#endif
+};
+
+/* A channel represents on uni-directional endpoint. So, in the case of the
+ * bi-directional, control endpoint, there must be two channels to represent
+ * the endpoint.
+ */
+
+struct stm32_ctrlinfo_s
+{
+ uint8_t inndx; /* EP0 IN control channel index */
+ uint8_t outndx; /* EP0 OUT control channel index */
+};
+
+/* This structure retains the state of the USB host controller */
+
+struct stm32_usbhost_s
+{
+ /* Common device fields. This must be the first thing defined in the
+ * structure so that it is possible to simply cast from struct usbhost_s
+ * to structstm32_usbhost_s.
+ */
+
+ struct usbhost_driver_s drvr;
+
+ /* This is the hub port description understood by class drivers */
+
+ struct usbhost_roothubport_s rhport;
+
+ /* Overall driver status */
+
+ volatile uint8_t smstate; /* The state of the USB host state machine */
+ uint8_t chidx; /* ID of channel waiting for space in Tx FIFO */
+ volatile bool connected; /* Connected to device */
+ volatile bool change; /* Connection change */
+ volatile bool pscwait; /* True: Thread is waiting for a port event */
+ sem_t exclsem; /* Support mutually exclusive access */
+ sem_t pscsem; /* Semaphore to wait for a port event */
+ struct stm32_ctrlinfo_s ep0; /* Root hub port EP0 description */
+
+#ifdef CONFIG_USBHOST_HUB
+ /* Used to pass external hub port events */
+
+ volatile struct usbhost_hubport_s *hport;
+#endif
+
+ /* The state of each host channel */
+
+ struct stm32_chan_s chan[STM32_MAX_TX_FIFOS];
+};
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+/* Register operations ********************************************************/
+
+#ifdef CONFIG_STM32_USBHOST_REGDEBUG
+static void stm32_printreg(uint32_t addr, uint32_t val, bool iswrite);
+static void stm32_checkreg(uint32_t addr, uint32_t val, bool iswrite);
+static uint32_t stm32_getreg(uint32_t addr);
+static void stm32_putreg(uint32_t addr, uint32_t value);
+#else
+# define stm32_getreg(addr) getreg32(addr)
+# define stm32_putreg(addr,val) putreg32(val,addr)
+#endif
+
+static inline void stm32_modifyreg(uint32_t addr, uint32_t clrbits,
+ uint32_t setbits);
+
+#ifdef CONFIG_STM32_USBHOST_PKTDUMP
+# define stm32_pktdump(m,b,n) lib_dumpbuffer(m,b,n)
+#else
+# define stm32_pktdump(m,b,n)
+#endif
+
+/* Semaphores ******************************************************************/
+
+static void stm32_takesem(sem_t *sem);
+#define stm32_givesem(s) sem_post(s);
+
+/* Byte stream access helper functions *****************************************/
+
+static inline uint16_t stm32_getle16(const uint8_t *val);
+
+/* Channel management **********************************************************/
+
+static int stm32_chan_alloc(FAR struct stm32_usbhost_s *priv);
+static inline void stm32_chan_free(FAR struct stm32_usbhost_s *priv, int chidx);
+static inline void stm32_chan_freeall(FAR struct stm32_usbhost_s *priv);
+static void stm32_chan_configure(FAR struct stm32_usbhost_s *priv, int chidx);
+static void stm32_chan_halt(FAR struct stm32_usbhost_s *priv, int chidx,
+ enum stm32_chreason_e chreason);
+static int stm32_chan_waitsetup(FAR struct stm32_usbhost_s *priv,
+ FAR struct stm32_chan_s *chan);
+#ifdef CONFIG_USBHOST_ASYNCH
+static int stm32_chan_asynchsetup(FAR struct stm32_usbhost_s *priv,
+ FAR struct stm32_chan_s *chan,
+ usbhost_asynch_t callback, FAR void *arg);
+#endif
+static int stm32_chan_wait(FAR struct stm32_usbhost_s *priv,
+ FAR struct stm32_chan_s *chan);
+static void stm32_chan_wakeup(FAR struct stm32_usbhost_s *priv,
+ FAR struct stm32_chan_s *chan);
+static int stm32_ctrlchan_alloc(FAR struct stm32_usbhost_s *priv,
+ uint8_t epno, uint8_t funcaddr, uint8_t speed,
+ FAR struct stm32_ctrlinfo_s *ctrlep);
+static int stm32_ctrlep_alloc(FAR struct stm32_usbhost_s *priv,
+ FAR const struct usbhost_epdesc_s *epdesc,
+ FAR usbhost_ep_t *ep);
+static int stm32_xfrep_alloc(FAR struct stm32_usbhost_s *priv,
+ FAR const struct usbhost_epdesc_s *epdesc,
+ FAR usbhost_ep_t *ep);
+
+/* Control/data transfer logic *************************************************/
+
+static void stm32_transfer_start(FAR struct stm32_usbhost_s *priv, int chidx);
+#if 0 /* Not used */
+static inline uint16_t stm32_getframe(void);
+#endif
+static int stm32_ctrl_sendsetup(FAR struct stm32_usbhost_s *priv,
+ FAR struct stm32_ctrlinfo_s *ep0,
+ FAR const struct usb_ctrlreq_s *req);
+static int stm32_ctrl_senddata(FAR struct stm32_usbhost_s *priv,
+ FAR struct stm32_ctrlinfo_s *ep0,
+ FAR uint8_t *buffer, unsigned int buflen);
+static int stm32_ctrl_recvdata(FAR struct stm32_usbhost_s *priv,
+ FAR struct stm32_ctrlinfo_s *ep0,
+ FAR uint8_t *buffer, unsigned int buflen);
+static int stm32_in_setup(FAR struct stm32_usbhost_s *priv, int chidx);
+static ssize_t stm32_in_transfer(FAR struct stm32_usbhost_s *priv, int chidx,
+ FAR uint8_t *buffer, size_t buflen);
+#ifdef CONFIG_USBHOST_ASYNCH
+static void stm32_in_next(FAR struct stm32_usbhost_s *priv,
+ FAR struct stm32_chan_s *chan);
+static int stm32_in_asynch(FAR struct stm32_usbhost_s *priv, int chidx,
+ FAR uint8_t *buffer, size_t buflen,
+ usbhost_asynch_t callback, FAR void *arg);
+#endif
+static int stm32_out_setup(FAR struct stm32_usbhost_s *priv, int chidx);
+static ssize_t stm32_out_transfer(FAR struct stm32_usbhost_s *priv, int chidx,
+ FAR uint8_t *buffer, size_t buflen);
+#ifdef CONFIG_USBHOST_ASYNCH
+static void stm32_out_next(FAR struct stm32_usbhost_s *priv,
+ FAR struct stm32_chan_s *chan);
+static int stm32_out_asynch(FAR struct stm32_usbhost_s *priv, int chidx,
+ FAR uint8_t *buffer, size_t buflen,
+ usbhost_asynch_t callback, FAR void *arg);
+#endif
+
+/* Interrupt handling **********************************************************/
+/* Lower level interrupt handlers */
+
+static void stm32_gint_wrpacket(FAR struct stm32_usbhost_s *priv,
+ FAR uint8_t *buffer, int chidx, int buflen);
+static inline void stm32_gint_hcinisr(FAR struct stm32_usbhost_s *priv,
+ int chidx);
+static inline void stm32_gint_hcoutisr(FAR struct stm32_usbhost_s *priv,
+ int chidx);
+static void stm32_gint_connected(FAR struct stm32_usbhost_s *priv);
+static void stm32_gint_disconnected(FAR struct stm32_usbhost_s *priv);
+
+/* Second level interrupt handlers */
+
+#ifdef CONFIG_STM32_OTG_SOFINTR
+static inline void stm32_gint_sofisr(FAR struct stm32_usbhost_s *priv);
+#endif
+static inline void stm32_gint_rxflvlisr(FAR struct stm32_usbhost_s *priv);
+static inline void stm32_gint_nptxfeisr(FAR struct stm32_usbhost_s *priv);
+static inline void stm32_gint_ptxfeisr(FAR struct stm32_usbhost_s *priv);
+static inline void stm32_gint_hcisr(FAR struct stm32_usbhost_s *priv);
+static inline void stm32_gint_hprtisr(FAR struct stm32_usbhost_s *priv);
+static inline void stm32_gint_discisr(FAR struct stm32_usbhost_s *priv);
+static inline void stm32_gint_ipxfrisr(FAR struct stm32_usbhost_s *priv);
+
+/* First level, global interrupt handler */
+
+static int stm32_gint_isr(int irq, FAR void *context);
+
+/* Interrupt controls */
+
+static void stm32_gint_enable(void);
+static void stm32_gint_disable(void);
+static inline void stm32_hostinit_enable(void);
+static void stm32_txfe_enable(FAR struct stm32_usbhost_s *priv, int chidx);
+
+/* USB host controller operations **********************************************/
+
+static int stm32_wait(FAR struct usbhost_connection_s *conn,
+ FAR struct usbhost_hubport_s **hport);
+static int stm32_rh_enumerate(FAR struct stm32_usbhost_s *priv,
+ FAR struct usbhost_connection_s *conn,
+ FAR struct usbhost_hubport_s *hport);
+static int stm32_enumerate(FAR struct usbhost_connection_s *conn,
+ FAR struct usbhost_hubport_s *hport);
+
+static int stm32_ep0configure(FAR struct usbhost_driver_s *drvr,
+ usbhost_ep_t ep0, uint8_t funcaddr, uint8_t speed,
+ uint16_t maxpacketsize);
+static int stm32_epalloc(FAR struct usbhost_driver_s *drvr,
+ FAR const FAR struct usbhost_epdesc_s *epdesc,
+ FAR usbhost_ep_t *ep);
+static int stm32_epfree(FAR struct usbhost_driver_s *drvr, usbhost_ep_t ep);
+static int stm32_alloc(FAR struct usbhost_driver_s *drvr,
+ FAR uint8_t **buffer, FAR size_t *maxlen);
+static int stm32_free(FAR struct usbhost_driver_s *drvr, FAR uint8_t *buffer);
+static int stm32_ioalloc(FAR struct usbhost_driver_s *drvr,
+ FAR uint8_t **buffer, size_t buflen);
+static int stm32_iofree(FAR struct usbhost_driver_s *drvr, FAR uint8_t *buffer);
+static int stm32_ctrlin(FAR struct usbhost_driver_s *drvr, usbhost_ep_t ep0,
+ const struct usb_ctrlreq_s *req,
+ FAR uint8_t *buffer);
+static int stm32_ctrlout(FAR struct usbhost_driver_s *drvr, usbhost_ep_t ep0,
+ FAR const struct usb_ctrlreq_s *req,
+ FAR const uint8_t *buffer);
+static ssize_t stm32_transfer(FAR struct usbhost_driver_s *drvr, usbhost_ep_t ep,
+ FAR uint8_t *buffer, size_t buflen);
+#ifdef CONFIG_USBHOST_ASYNCH
+static int stm32_asynch(FAR struct usbhost_driver_s *drvr, usbhost_ep_t ep,
+ FAR uint8_t *buffer, size_t buflen,
+ usbhost_asynch_t callback, FAR void *arg);
+#endif
+static int stm32_cancel(FAR struct usbhost_driver_s *drvr, usbhost_ep_t ep);
+#ifdef CONFIG_USBHOST_HUB
+static int stm32_connect(FAR struct usbhost_driver_s *drvr,
+ FAR struct usbhost_hubport_s *hport,
+ bool connected);
+#endif
+static void stm32_disconnect(FAR struct usbhost_driver_s *drvr,
+ FAR struct usbhost_hubport_s *hport);
+
+/* Initialization **************************************************************/
+
+static void stm32_portreset(FAR struct stm32_usbhost_s *priv);
+static void stm32_flush_txfifos(uint32_t txfnum);
+static void stm32_flush_rxfifo(void);
+static void stm32_vbusdrive(FAR struct stm32_usbhost_s *priv, bool state);
+static void stm32_host_initialize(FAR struct stm32_usbhost_s *priv);
+
+static inline void stm32_sw_initialize(FAR struct stm32_usbhost_s *priv);
+static inline int stm32_hw_initialize(FAR struct stm32_usbhost_s *priv);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/* In this driver implementation, support is provided for only a single a single
+ * USB device. All status information can be simply retained in a single global
+ * instance.
+ */
+
+static struct stm32_usbhost_s g_usbhost;
+
+/* This is the connection/enumeration interface */
+
+static struct usbhost_connection_s g_usbconn =
+{
+ .wait = stm32_wait,
+ .enumerate = stm32_enumerate,
+};
+
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: stm32_printreg
+ *
+ * Description:
+ * Print the contents of an STM32xx register operation
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_STM32_USBHOST_REGDEBUG
+static void stm32_printreg(uint32_t addr, uint32_t val, bool iswrite)
+{
+ llerr("%08x%s%08x\n", addr, iswrite ? "<-" : "->", val);
+}
+#endif
+
+/****************************************************************************
+ * Name: stm32_checkreg
+ *
+ * Description:
+ * Get the contents of an STM32 register
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_STM32_USBHOST_REGDEBUG
+static void stm32_checkreg(uint32_t addr, uint32_t val, bool iswrite)
+{
+ static uint32_t prevaddr = 0;
+ static uint32_t preval = 0;
+ static uint32_t count = 0;
+ static bool prevwrite = false;
+
+ /* Is this the same value that we read from/wrote to the same register last time?
+ * Are we polling the register? If so, suppress the output.
+ */
+
+ if (addr == prevaddr && val == preval && prevwrite == iswrite)
+ {
+ /* Yes.. Just increment the count */
+
+ count++;
+ }
+ else
+ {
+ /* No this is a new address or value or operation. Were there any
+ * duplicate accesses before this one?
+ */
+
+ if (count > 0)
+ {
+ /* Yes.. Just one? */
+
+ if (count == 1)
+ {
+ /* Yes.. Just one */
+
+ stm32_printreg(prevaddr, preval, prevwrite);
+ }
+ else
+ {
+ /* No.. More than one. */
+
+ llerr("[repeats %d more times]\n", count);
+ }
+ }
+
+ /* Save the new address, value, count, and operation for next time */
+
+ prevaddr = addr;
+ preval = val;
+ count = 0;
+ prevwrite = iswrite;
+
+ /* Show the new regisgter access */
+
+ stm32_printreg(addr, val, iswrite);
+ }
+}
+#endif
+
+/****************************************************************************
+ * Name: stm32_getreg
+ *
+ * Description:
+ * Get the contents of an STM32 register
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_STM32_USBHOST_REGDEBUG
+static uint32_t stm32_getreg(uint32_t addr)
+{
+ /* Read the value from the register */
+
+ uint32_t val = getreg32(addr);
+
+ /* Check if we need to print this value */
+
+ stm32_checkreg(addr, val, false);
+ return val;
+}
+#endif
+
+/****************************************************************************
+ * Name: stm32_putreg
+ *
+ * Description:
+ * Set the contents of an STM32 register to a value
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_STM32_USBHOST_REGDEBUG
+static void stm32_putreg(uint32_t addr, uint32_t val)
+{
+ /* Check if we need to print this value */
+
+ stm32_checkreg(addr, val, true);
+
+ /* Write the value */
+
+ putreg32(val, addr);
+}
+#endif
+
+/****************************************************************************
+ * Name: stm32_modifyreg
+ *
+ * Description:
+ * Modify selected bits of an STM32 register.
+ *
+ ****************************************************************************/
+
+static inline void stm32_modifyreg(uint32_t addr, uint32_t clrbits, uint32_t setbits)
+{
+ stm32_putreg(addr, (((stm32_getreg(addr)) & ~clrbits) | setbits));
+}
+
+/****************************************************************************
+ * Name: stm32_takesem
+ *
+ * Description:
+ * This is just a wrapper to handle the annoying behavior of semaphore
+ * waits that return due to the receipt of a signal.
+ *
+ ****************************************************************************/
+
+static void stm32_takesem(sem_t *sem)
+{
+ /* Take the semaphore (perhaps waiting) */
+
+ while (sem_wait(sem) != 0)
+ {
+ /* The only case that an error should occr here is if the wait was
+ * awakened by a signal.
+ */
+
+ ASSERT(errno == EINTR);
+ }
+}
+
+/****************************************************************************
+ * Name: stm32_getle16
+ *
+ * Description:
+ * Get a (possibly unaligned) 16-bit little endian value.
+ *
+ ****************************************************************************/
+
+static inline uint16_t stm32_getle16(const uint8_t *val)
+{
+ return (uint16_t)val[1] << 8 | (uint16_t)val[0];
+}
+
+/****************************************************************************
+ * Name: stm32_chan_alloc
+ *
+ * Description:
+ * Allocate a channel.
+ *
+ ****************************************************************************/
+
+static int stm32_chan_alloc(FAR struct stm32_usbhost_s *priv)
+{
+ int chidx;
+
+ /* Search the table of channels */
+
+ for (chidx = 0; chidx < STM32_NHOST_CHANNELS; chidx++)
+ {
+ /* Is this channel available? */
+
+ if (!priv->chan[chidx].inuse)
+ {
+ /* Yes... make it "in use" and return the index */
+
+ priv->chan[chidx].inuse = true;
+ return chidx;
+ }
+ }
+
+ /* All of the channels are "in-use" */
+
+ return -EBUSY;
+}
+
+/****************************************************************************
+ * Name: stm32_chan_free
+ *
+ * Description:
+ * Free a previoiusly allocated channel.
+ *
+ ****************************************************************************/
+
+static void stm32_chan_free(FAR struct stm32_usbhost_s *priv, int chidx)
+{
+ DEBUGASSERT((unsigned)chidx < STM32_NHOST_CHANNELS);
+
+ /* Halt the channel */
+
+ stm32_chan_halt(priv, chidx, CHREASON_FREED);
+
+ /* Mark the channel available */
+
+ priv->chan[chidx].inuse = false;
+}
+
+/****************************************************************************
+ * Name: stm32_chan_freeall
+ *
+ * Description:
+ * Free all channels.
+ *
+ ****************************************************************************/
+
+static inline void stm32_chan_freeall(FAR struct stm32_usbhost_s *priv)
+{
+ uint8_t chidx;
+
+ /* Free all host channels */
+
+ for (chidx = 2; chidx < STM32_NHOST_CHANNELS; chidx ++)
+ {
+ stm32_chan_free(priv, chidx);
+ }
+}
+
+/****************************************************************************
+ * Name: stm32_chan_configure
+ *
+ * Description:
+ * Configure or re-configure a host channel. Host channels are configured
+ * when endpoint is allocated and EP0 (only) is re-configured with the
+ * max packet size or device address changes.
+ *
+ ****************************************************************************/
+
+static void stm32_chan_configure(FAR struct stm32_usbhost_s *priv, int chidx)
+{
+ FAR struct stm32_chan_s *chan = &priv->chan[chidx];
+ uint32_t regval;
+
+ /* Clear any old pending interrupts for this host channel. */
+
+ stm32_putreg(STM32_OTG_HCINT(chidx), 0xffffffff);
+
+ /* Enable channel interrupts required for transfers on this channel. */
+
+ regval = 0;
+
+ switch (chan->eptype)
+ {
+ case OTG_EPTYPE_CTRL:
+ case OTG_EPTYPE_BULK:
+ {
+#ifdef HAVE_USBHOST_TRACE_VERBOSE
+ uint16_t intrace;
+ uint16_t outtrace;
+
+ /* Determine the definitive trace ID to use below */
+
+ if (chan->eptype == OTG_EPTYPE_CTRL)
+ {
+ intrace = OTG_VTRACE2_CHANCONF_CTRL_IN;
+ outtrace = OTG_VTRACE2_CHANCONF_CTRL_OUT;
+ }
+ else
+ {
+ intrace = OTG_VTRACE2_CHANCONF_BULK_IN;
+ outtrace = OTG_VTRACE2_CHANCONF_BULK_OUT;
+ }
+#endif
+
+ /* Interrupts required for CTRL and BULK endpoints */
+
+ regval |= (OTG_HCINT_XFRC | OTG_HCINT_STALL | OTG_HCINT_NAK |
+ OTG_HCINT_TXERR | OTG_HCINT_DTERR);
+
+ /* Additional setting for IN/OUT endpoints */
+
+ if (chan->in)
+ {
+ usbhost_vtrace2(intrace, chidx, chan->epno);
+ regval |= OTG_HCINT_BBERR;
+ }
+ else
+ {
+ usbhost_vtrace2(outtrace, chidx, chan->epno);
+ regval |= OTG_HCINT_NYET;
+ }
+ }
+ break;
+
+ case OTG_EPTYPE_INTR:
+ {
+ /* Interrupts required for INTR endpoints */
+
+ regval |= (OTG_HCINT_XFRC | OTG_HCINT_STALL | OTG_HCINT_NAK |
+ OTG_HCINT_TXERR | OTG_HCINT_FRMOR | OTG_HCINT_DTERR);
+
+ /* Additional setting for IN endpoints */
+
+ if (chan->in)
+ {
+ usbhost_vtrace2(OTG_VTRACE2_CHANCONF_INTR_IN, chidx,
+ chan->epno);
+ regval |= OTG_HCINT_BBERR;
+ }
+#ifdef HAVE_USBHOST_TRACE_VERBOSE
+ else
+ {
+ usbhost_vtrace2(OTG_VTRACE2_CHANCONF_INTR_OUT, chidx,
+ chan->epno);
+ }
+#endif
+ }
+ break;
+
+ case OTG_EPTYPE_ISOC:
+ {
+ /* Interrupts required for ISOC endpoints */
+
+ regval |= (OTG_HCINT_XFRC | OTG_HCINT_ACK | OTG_HCINT_FRMOR);
+
+ /* Additional setting for IN endpoints */
+
+ if (chan->in)
+ {
+ usbhost_vtrace2(OTG_VTRACE2_CHANCONF_ISOC_IN, chidx,
+ chan->epno);
+ regval |= (OTG_HCINT_TXERR | OTG_HCINT_BBERR);
+ }
+#ifdef HAVE_USBHOST_TRACE_VERBOSE
+ else
+ {
+ usbhost_vtrace2(OTG_VTRACE2_CHANCONF_ISOC_OUT, chidx,
+ chan->epno);
+ }
+#endif
+ }
+ break;
+ }
+
+ stm32_putreg(STM32_OTG_HCINTMSK(chidx), regval);
+
+ /* Enable the top level host channel interrupt. */
+
+ stm32_modifyreg(STM32_OTG_HAINTMSK, 0, OTG_HAINT(chidx));
+
+ /* Make sure host channel interrupts are enabled. */
+
+ stm32_modifyreg(STM32_OTG_GINTMSK, 0, OTG_GINT_HC);
+
+ /* Program the HCCHAR register */
+
+ regval = ((uint32_t)chan->maxpacket << OTG_HCCHAR_MPSIZ_SHIFT) |
+ ((uint32_t)chan->epno << OTG_HCCHAR_EPNUM_SHIFT) |
+ ((uint32_t)chan->eptype << OTG_HCCHAR_EPTYP_SHIFT) |
+ ((uint32_t)chan->funcaddr << OTG_HCCHAR_DAD_SHIFT);
+
+ /* Special case settings for low speed devices */
+
+ if (chan->speed == USB_SPEED_LOW)
+ {
+ regval |= OTG_HCCHAR_LSDEV;
+ }
+
+ /* Special case settings for IN endpoints */
+
+ if (chan->in)
+ {
+ regval |= OTG_HCCHAR_EPDIR_IN;
+ }
+
+ /* Special case settings for INTR endpoints */
+
+ if (chan->eptype == OTG_EPTYPE_INTR)
+ {
+ regval |= OTG_HCCHAR_ODDFRM;
+ }
+
+ /* Write the channel configuration */
+
+ stm32_putreg(STM32_OTG_HCCHAR(chidx), regval);
+}
+
+/****************************************************************************
+ * Name: stm32_chan_halt
+ *
+ * Description:
+ * Halt the channel associated with 'chidx' by setting the CHannel DISable
+ * (CHDIS) bit in in the HCCHAR register.
+ *
+ ****************************************************************************/
+
+static void stm32_chan_halt(FAR struct stm32_usbhost_s *priv, int chidx,
+ enum stm32_chreason_e chreason)
+{
+ uint32_t hcchar;
+ uint32_t intmsk;
+ uint32_t eptype;
+ unsigned int avail;
+
+ /* Save the reason for the halt. We need this in the channel halt interrupt
+ * handling logic to know what to do next.
+ */
+
+ usbhost_vtrace2(OTG_VTRACE2_CHANHALT, chidx, chreason);
+
+ priv->chan[chidx].chreason = (uint8_t)chreason;
+
+ /* "The application can disable any channel by programming the OTG_FS_HCCHARx
+ * register with the CHDIS and CHENA bits set to 1. This enables the OTG_FS
+ * host to flush the posted requests (if any) and generates a channel halted
+ * interrupt. The application must wait for the CHH interrupt in OTG_FS_HCINTx
+ * before reallocating the channel for other transactions. The OTG_FS host
+ * does not interrupt the transaction that has already been started on the
+ * USB."
+ */
+
+ hcchar = stm32_getreg(STM32_OTG_HCCHAR(chidx));
+ hcchar |= (OTG_HCCHAR_CHDIS | OTG_HCCHAR_CHENA);
+
+ /* Get the endpoint type from the HCCHAR register */
+
+ eptype = hcchar & OTG_HCCHAR_EPTYP_MASK;
+
+ /* Check for space in the Tx FIFO to issue the halt.
+ *
+ * "Before disabling a channel, the application must ensure that there is at
+ * least one free space available in the non-periodic request queue (when
+ * disabling a non-periodic channel) or the periodic request queue (when
+ * disabling a periodic channel). The application can simply flush the
+ * posted requests when the Request queue is full (before disabling the
+ * channel), by programming the OTG_FS_HCCHARx register with the CHDIS bit
+ * set to 1, and the CHENA bit cleared to 0.
+ */
+
+ if (eptype == OTG_HCCHAR_EPTYP_CTRL || eptype == OTG_HCCHAR_EPTYP_BULK)
+ {
+ /* Get the number of words available in the non-periodic Tx FIFO. */
+
+ avail = stm32_getreg(STM32_OTG_HNPTXSTS) & OTG_HNPTXSTS_NPTXFSAV_MASK;
+ }
+ else /* if (eptype == OTG_HCCHAR_EPTYP_ISOC || eptype == OTG_HCCHAR_EPTYP_INTR) */
+ {
+ /* Get the number of words available in the non-periodic Tx FIFO. */
+
+ avail = stm32_getreg(STM32_OTG_HPTXSTS) & OTG_HPTXSTS_PTXFSAVL_MASK;
+ }
+
+ /* Check if there is any space available in the Tx FIFO. */
+
+ if (avail == 0)
+ {
+ /* The Tx FIFO is full... disable the channel to flush the requests */
+
+ hcchar &= ~OTG_HCCHAR_CHENA;
+ }
+
+ /* Unmask the CHannel Halted (CHH) interrupt */
+
+ intmsk = stm32_getreg(STM32_OTG_HCINTMSK(chidx));
+ intmsk |= OTG_HCINT_CHH;
+ stm32_putreg(STM32_OTG_HCINTMSK(chidx), intmsk);
+
+ /* Halt the channel by setting CHDIS (and maybe CHENA) in the HCCHAR */
+
+ stm32_putreg(STM32_OTG_HCCHAR(chidx), hcchar);
+}
+
+/****************************************************************************
+ * Name: stm32_chan_waitsetup
+ *
+ * Description:
+ * Set the request for the transfer complete event well BEFORE enabling the
+ * transfer (as soon as we are absolutely committed to the to avoid transfer).
+ * We do this to minimize race conditions. This logic would have to be expanded
+ * if we want to have more than one packet in flight at a time!
+ *
+ * Assumptions:
+ * Called from a normal thread context BEFORE the transfer has been started.
+ *
+ ****************************************************************************/
+
+static int stm32_chan_waitsetup(FAR struct stm32_usbhost_s *priv,
+ FAR struct stm32_chan_s *chan)
+{
+ irqstate_t flags = enter_critical_section();
+ int ret = -ENODEV;
+
+ /* Is the device still connected? */
+
+ if (priv->connected)
+ {
+ /* Yes.. then set waiter to indicate that we expect to be informed when
+ * either (1) the device is disconnected, or (2) the transfer completed.
+ */
+
+ chan->waiter = true;
+#ifdef CONFIG_USBHOST_ASYNCH
+ chan->callback = NULL;
+ chan->arg = NULL;
+#endif
+ ret = OK;
+ }
+
+ leave_critical_section(flags);
+ return ret;
+}
+
+/****************************************************************************
+ * Name: stm32_chan_asynchsetup
+ *
+ * Description:
+ * Set the request for the transfer complete event well BEFORE enabling the
+ * transfer (as soon as we are absolutely committed to the to avoid transfer).
+ * We do this to minimize race conditions. This logic would have to be expanded
+ * if we want to have more than one packet in flight at a time!
+ *
+ * Assumptions:
+ * Might be called from the level of an interrupt handler
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_USBHOST_ASYNCH
+static int stm32_chan_asynchsetup(FAR struct stm32_usbhost_s *priv,
+ FAR struct stm32_chan_s *chan,
+ usbhost_asynch_t callback, FAR void *arg)
+{
+ irqstate_t flags = enter_critical_section();
+ int ret = -ENODEV;
+
+ /* Is the device still connected? */
+
+ if (priv->connected)
+ {
+ /* Yes.. then set waiter to indicate that we expect to be informed when
+ * either (1) the device is disconnected, or (2) the transfer completed.
+ */
+
+ chan->waiter = false;
+ chan->callback = callback;
+ chan->arg = arg;
+ ret = OK;
+ }
+
+ leave_critical_section(flags);
+ return ret;
+}
+#endif
+
+/****************************************************************************
+ * Name: stm32_chan_wait
+ *
+ * Description:
+ * Wait for a transfer on a channel to complete.
+ *
+ * Assumptions:
+ * Called from a normal thread context
+ *
+ ****************************************************************************/
+
+static int stm32_chan_wait(FAR struct stm32_usbhost_s *priv,
+ FAR struct stm32_chan_s *chan)
+{
+ irqstate_t flags;
+ int ret;
+
+ /* Disable interrupts so that the following operations will be atomic. On
+ * the OTG FS global interrupt needs to be disabled. However, here we disable
+ * all interrupts to exploit that fact that interrupts will be re-enabled
+ * while we wait.
+ */
+
+ flags = enter_critical_section();
+
+ /* Loop, testing for an end of transfer condition. The channel 'result'
+ * was set to EBUSY and 'waiter' was set to true before the transfer; 'waiter'
+ * will be set to false and 'result' will be set appropriately when the
+ * transfer is completed.
+ */
+
+ do
+ {
+ /* Wait for the transfer to complete. NOTE the transfer may already
+ * completed before we get here or the transfer may complete while we
+ * wait here.
+ */
+
+ ret = sem_wait(&chan->waitsem);
+
+ /* sem_wait should succeed. But it is possible that we could be
+ * awakened by a signal too.
+ */
+
+ DEBUGASSERT(ret == OK || get_errno() == EINTR);
+ }
+ while (chan->waiter);
+
+ /* The transfer is complete re-enable interrupts and return the result */
+
+ ret = -(int)chan->result;
+ leave_critical_section(flags);
+ return ret;
+}
+
+/****************************************************************************
+ * Name: stm32_chan_wakeup
+ *
+ * Description:
+ * A channel transfer has completed... wakeup any threads waiting for the
+ * transfer to complete.
+ *
+ * Assumptions:
+ * This function is called from the transfer complete interrupt handler for
+ * the channel. Interrupts are disabled.
+ *
+ ****************************************************************************/
+
+static void stm32_chan_wakeup(FAR struct stm32_usbhost_s *priv,
+ FAR struct stm32_chan_s *chan)
+{
+ /* Is the transfer complete? */
+
+ if (chan->result != EBUSY)
+ {
+ /* Is there a thread waiting for this transfer to complete? */
+
+ if (chan->waiter)
+ {
+#ifdef CONFIG_USBHOST_ASYNCH
+ /* Yes.. there should not also be a callback scheduled */
+
+ DEBUGASSERT(chan->callback == NULL);
+#endif
+ /* Wake'em up! */
+
+ usbhost_vtrace2(chan->in ? OTG_VTRACE2_CHANWAKEUP_IN :
+ OTG_VTRACE2_CHANWAKEUP_OUT,
+ chan->epno, chan->result);
+
+ stm32_givesem(&chan->waitsem);
+ chan->waiter = false;
+ }
+
+#ifdef CONFIG_USBHOST_ASYNCH
+ /* No.. is an asynchronous callback expected when the transfer
+ * completes?
+ */
+
+ else if (chan->callback)
+ {
+ /* Handle continuation of IN/OUT pipes */
+
+ if (chan->in)
+ {
+ stm32_in_next(priv, chan);
+ }
+ else
+ {
+ stm32_out_next(priv, chan);
+ }
+ }
+#endif
+ }
+}
+
+/****************************************************************************
+ * Name: stm32_ctrlchan_alloc
+ *
+ * Description:
+ * Allocate and configured channels for a control pipe.
+ *
+ ****************************************************************************/
+
+static int stm32_ctrlchan_alloc(FAR struct stm32_usbhost_s *priv,
+ uint8_t epno, uint8_t funcaddr, uint8_t speed,
+ FAR struct stm32_ctrlinfo_s *ctrlep)
+{
+ FAR struct stm32_chan_s *chan;
+ int inndx;
+ int outndx;
+
+ outndx = stm32_chan_alloc(priv);
+ if (outndx < 0)
+ {
+ return -ENOMEM;
+ }
+
+ ctrlep->outndx = outndx;
+ chan = &priv->chan[outndx];
+ chan->epno = epno;
+ chan->in = false;
+ chan->eptype = OTG_EPTYPE_CTRL;
+ chan->funcaddr = funcaddr;
+ chan->speed = speed;
+ chan->maxpacket = STM32_EP0_DEF_PACKET_SIZE;
+ chan->indata1 = false;
+ chan->outdata1 = false;
+
+ /* Configure control OUT channels */
+
+ stm32_chan_configure(priv, outndx);
+
+ /* Allocate and initialize the control IN channel */
+
+ inndx = stm32_chan_alloc(priv);
+ if (inndx < 0)
+ {
+ stm32_chan_free(priv, outndx);
+ return -ENOMEM;
+ }
+
+ ctrlep->inndx = inndx;
+ chan = &priv->chan[inndx];
+ chan->epno = epno;
+ chan->in = true;
+ chan->eptype = OTG_EPTYPE_CTRL;
+ chan->funcaddr = funcaddr;
+ chan->speed = speed;
+ chan->maxpacket = STM32_EP0_DEF_PACKET_SIZE;
+ chan->indata1 = false;
+ chan->outdata1 = false;
+
+ /* Configure control IN channels */
+
+ stm32_chan_configure(priv, inndx);
+ return OK;
+}
+
+/****************************************************************************
+ * Name: stm32_ctrlep_alloc
+ *
+ * Description:
+ * Allocate a container and channels for control pipe.
+ *
+ * Input Parameters:
+ * priv - The private USB host driver state.
+ * epdesc - Describes the endpoint to be allocated.
+ * ep - A memory location provided by the caller in which to receive the
+ * allocated endpoint descriptor.
+ *
+ * Returned Values:
+ * On success, zero (OK) is returned. On a failure, a negated errno value is
+ * returned indicating the nature of the failure
+ *
+ * Assumptions:
+ * This function will *not* be called from an interrupt handler.
+ *
+ ****************************************************************************/
+
+static int stm32_ctrlep_alloc(FAR struct stm32_usbhost_s *priv,
+ FAR const struct usbhost_epdesc_s *epdesc,
+ FAR usbhost_ep_t *ep)
+{
+ FAR struct usbhost_hubport_s *hport;
+ FAR struct stm32_ctrlinfo_s *ctrlep;
+ int ret;
+
+ /* Sanity check. NOTE that this method should only be called if a device is
+ * connected (because we need a valid low speed indication).
+ */
+
+ DEBUGASSERT(epdesc->hport != NULL);
+ hport = epdesc->hport;
+
+ /* Allocate a container for the control endpoint */
+
+ ctrlep = (FAR struct stm32_ctrlinfo_s *)kmm_malloc(sizeof(struct stm32_ctrlinfo_s));
+ if (ctrlep == NULL)
+ {
+ uerr("ERROR: Failed to allocate control endpoint container\n");
+ return -ENOMEM;
+ }
+
+ /* Then allocate and configure the IN/OUT channnels */
+
+ ret = stm32_ctrlchan_alloc(priv, epdesc->addr & USB_EPNO_MASK,
+ hport->funcaddr, hport->speed, ctrlep);
+ if (ret < 0)
+ {
+ uerr("ERROR: stm32_ctrlchan_alloc failed: %d\n", ret);
+ kmm_free(ctrlep);
+ return ret;
+ }
+
+ /* Return a pointer to the control pipe container as the pipe "handle" */
+
+ *ep = (usbhost_ep_t)ctrlep;
+ return OK;
+}
+
+/************************************************************************************
+ * Name: stm32_xfrep_alloc
+ *
+ * Description:
+ * Allocate and configure one unidirectional endpoint.
+ *
+ * Input Parameters:
+ * priv - The private USB host driver state.
+ * epdesc - Describes the endpoint to be allocated.
+ * ep - A memory location provided by the caller in which to receive the
+ * allocated endpoint descriptor.
+ *
+ * Returned Values:
+ * On success, zero (OK) is returned. On a failure, a negated errno value is
+ * returned indicating the nature of the failure
+ *
+ * Assumptions:
+ * This function will *not* be called from an interrupt handler.
+ *
+ ************************************************************************************/
+
+static int stm32_xfrep_alloc(FAR struct stm32_usbhost_s *priv,
+ FAR const struct usbhost_epdesc_s *epdesc,
+ FAR usbhost_ep_t *ep)
+{
+ struct usbhost_hubport_s *hport;
+ FAR struct stm32_chan_s *chan;
+ int chidx;
+
+ /* Sanity check. NOTE that this method should only be called if a device is
+ * connected (because we need a valid low speed indication).
+ */
+
+ DEBUGASSERT(epdesc->hport != NULL);
+ hport = epdesc->hport;
+
+ /* Allocate a host channel for the endpoint */
+
+ chidx = stm32_chan_alloc(priv);
+ if (chidx < 0)
+ {
+ uerr("ERROR: Failed to allocate a host channel\n");
+ return -ENOMEM;
+ }
+
+ /* Decode the endpoint descriptor to initialize the channel data structures.
+ * Note: Here we depend on the fact that the endpoint point type is
+ * encoded in the same way in the endpoint descriptor as it is in the OTG
+ * HS hardware.
+ */
+
+ chan = &priv->chan[chidx];
+ chan->epno = epdesc->addr & USB_EPNO_MASK;
+ chan->in = epdesc->in;
+ chan->eptype = epdesc->xfrtype;
+ chan->funcaddr = hport->funcaddr;
+ chan->speed = hport->speed;
+ chan->maxpacket = epdesc->mxpacketsize;
+ chan->indata1 = false;
+ chan->outdata1 = false;
+
+ /* Then configure the endpoint */
+
+ stm32_chan_configure(priv, chidx);
+
+ /* Return the index to the allocated channel as the endpoint "handle" */
+
+ *ep = (usbhost_ep_t)chidx;
+ return OK;
+}
+
+/****************************************************************************
+ * Name: stm32_transfer_start
+ *
+ * Description:
+ * Start at transfer on the select IN or OUT channel.
+ *
+ ****************************************************************************/
+
+static void stm32_transfer_start(FAR struct stm32_usbhost_s *priv, int chidx)
+{
+ FAR struct stm32_chan_s *chan;
+ uint32_t regval;
+ unsigned int npackets;
+ unsigned int maxpacket;
+ unsigned int avail;
+ unsigned int wrsize;
+ unsigned int minsize;
+
+ /* Set up the initial state of the transfer */
+
+ chan = &priv->chan[chidx];
+
+ usbhost_vtrace2(OTG_VTRACE2_STARTTRANSFER, chidx, chan->buflen);
+
+ chan->result = EBUSY;
+ chan->inflight = 0;
+ chan->xfrd = 0;
+ priv->chidx = chidx;
+
+ /* Compute the expected number of packets associated to the transfer.
+ * If the transfer length is zero (or less than the size of one maximum
+ * size packet), then one packet is expected.
+ */
+
+ /* If the transfer size is greater than one packet, then calculate the
+ * number of packets that will be received/sent, including any partial
+ * final packet.
+ */
+
+ maxpacket = chan->maxpacket;
+
+ if (chan->buflen > maxpacket)
+ {
+ npackets = (chan->buflen + maxpacket - 1) / maxpacket;
+
+ /* Clip if the buffer length if it exceeds the maximum number of
+ * packets that can be transferred (this should not happen).
+ */
+
+ if (npackets > STM32_MAX_PKTCOUNT)
+ {
+ npackets = STM32_MAX_PKTCOUNT;
+ chan->buflen = STM32_MAX_PKTCOUNT * maxpacket;
+ usbhost_trace2(OTG_TRACE2_CLIP, chidx, chan->buflen);
+ }
+ }
+ else
+ {
+ /* One packet will be sent/received (might be a zero length packet) */
+
+ npackets = 1;
+ }
+
+ /* If it is an IN transfer, then adjust the size of the buffer UP to
+ * a full number of packets. Hmmm... couldn't this cause an overrun
+ * into unallocated memory?
+ */
+
+#if 0 /* Think about this */
+ if (chan->in)
+ {
+ /* Force the buffer length to an even multiple of maxpacket */
+
+ chan->buflen = npackets * maxpacket;
+ }
+#endif
+
+ /* Save the number of packets in the transfer. We will need this in
+ * order to set the next data toggle correctly when the transfer
+ * completes.
+ */
+
+ chan->npackets = (uint8_t)npackets;
+
+ /* Setup the HCTSIZn register */
+
+ regval = ((uint32_t)chan->buflen << OTG_HCTSIZ_XFRSIZ_SHIFT) |
+ ((uint32_t)npackets << OTG_HCTSIZ_PKTCNT_SHIFT) |
+ ((uint32_t)chan->pid << OTG_HCTSIZ_DPID_SHIFT);
+ stm32_putreg(STM32_OTG_HCTSIZ(chidx), regval);
+
+ /* Setup the HCCHAR register: Frame oddness and host channel enable */
+
+ regval = stm32_getreg(STM32_OTG_HCCHAR(chidx));
+
+ /* Set/clear the Odd Frame bit. Check for an even frame; if so set Odd
+ * Frame. This field is applicable for only periodic (isochronous and
+ * interrupt) channels.
+ */
+
+ if ((stm32_getreg(STM32_OTG_HFNUM) & 1) == 0)
+ {
+ regval |= OTG_HCCHAR_ODDFRM;
+ }
+ else
+ {
+ regval &= ~OTG_HCCHAR_ODDFRM;
+ }
+
+ regval &= ~OTG_HCCHAR_CHDIS;
+ regval |= OTG_HCCHAR_CHENA;
+ stm32_putreg(STM32_OTG_HCCHAR(chidx), regval);
+
+ /* If this is an out transfer, then we need to do more.. we need to copy
+ * the outgoing data into the correct TxFIFO.
+ */
+
+ if (!chan->in && chan->buflen > 0)
+ {
+ /* Handle non-periodic (CTRL and BULK) OUT transfers differently than
+ * periodic (INTR and ISOC) OUT transfers.
+ */
+
+ minsize = MIN(chan->buflen, chan->maxpacket);
+
+ switch (chan->eptype)
+ {
+ case OTG_EPTYPE_CTRL: /* Non periodic transfer */
+ case OTG_EPTYPE_BULK:
+ {
+ /* Read the Non-periodic Tx FIFO status register */
+
+ regval = stm32_getreg(STM32_OTG_HNPTXSTS);
+ avail = ((regval & OTG_HNPTXSTS_NPTXFSAV_MASK) >> OTG_HNPTXSTS_NPTXFSAV_SHIFT) << 2;
+ }
+ break;
+
+ /* Periodic transfer */
+
+ case OTG_EPTYPE_INTR:
+ case OTG_EPTYPE_ISOC:
+ {
+ /* Read the Non-periodic Tx FIFO status register */
+
+ regval = stm32_getreg(STM32_OTG_HPTXSTS);
+ avail = ((regval & OTG_HPTXSTS_PTXFSAVL_MASK) >> OTG_HPTXSTS_PTXFSAVL_SHIFT) << 2;
+ }
+ break;
+
+ default:
+ DEBUGASSERT(false);
+ return;
+ }
+
+ /* Is there space in the TxFIFO to hold the minimum size packet? */
+
+ if (minsize <= avail)
+ {
+ /* Yes.. Get the size of the biggest thing that we can put in the Tx FIFO now */
+
+ wrsize = chan->buflen;
+ if (wrsize > avail)
+ {
+ /* Clip the write size to the number of full, max sized packets
+ * that will fit in the Tx FIFO.
+ */
+
+ unsigned int wrpackets = avail / chan->maxpacket;
+ wrsize = wrpackets * chan->maxpacket;
+ }
+
+ /* Write packet into the Tx FIFO. */
+
+ stm32_gint_wrpacket(priv, chan->buffer, chidx, wrsize);
+ }
+
+ /* Did we put the entire buffer into the Tx FIFO? */
+
+ if (chan->buflen > avail)
+ {
+ /* No, there was insufficient space to hold the entire transfer ...
+ * Enable the Tx FIFO interrupt to handle the transfer when the Tx
+ * FIFO becomes empty.
+ */
+
+ stm32_txfe_enable(priv, chidx);
+ }
+ }
+}
+
+/****************************************************************************
+ * Name: stm32_getframe
+ *
+ * Description:
+ * Get the current frame number. The frame number (FRNUM) field increments
+ * when a new SOF is transmitted on the USB, and is cleared to 0 when it
+ * reaches 0x3fff.
+ *
+ ****************************************************************************/
+
+#if 0 /* Not used */
+static inline uint16_t stm32_getframe(void)
+{
+ return (uint16_t)(stm32_getreg(STM32_OTG_HFNUM) & OTG_HFNUM_FRNUM_MASK);
+}
+#endif
+
+/****************************************************************************
+ * Name: stm32_ctrl_sendsetup
+ *
+ * Description:
+ * Send an IN/OUT SETUP packet.
+ *
+ ****************************************************************************/
+
+static int stm32_ctrl_sendsetup(FAR struct stm32_usbhost_s *priv,
+ FAR struct stm32_ctrlinfo_s *ep0,
+ FAR const struct usb_ctrlreq_s *req)
+{
+ FAR struct stm32_chan_s *chan;
+ systime_t start;
+ systime_t elapsed;
+ int ret;
+
+ /* Loop while the device reports NAK (and a timeout is not exceeded */
+
+ chan = &priv->chan[ep0->outndx];
+ start = clock_systimer();
+
+ do
+ {
+ /* Send the SETUP packet */
+
+ chan->pid = OTG_PID_SETUP;
+ chan->buffer = (FAR uint8_t *)req;
+ chan->buflen = USB_SIZEOF_CTRLREQ;
+ chan->xfrd = 0;
+
+ /* Set up for the wait BEFORE starting the transfer */
+
+ ret = stm32_chan_waitsetup(priv, chan);
+ if (ret < 0)
+ {
+ usbhost_trace1(OTG_TRACE1_DEVDISCONN, 0);
+ return ret;
+ }
+
+ /* Start the transfer */
+
+ stm32_transfer_start(priv, ep0->outndx);
+
+ /* Wait for the transfer to complete */
+
+ ret = stm32_chan_wait(priv, chan);
+
+ /* Return on success and for all failures other than EAGAIN. EAGAIN
+ * means that the device NAKed the SETUP command and that we should
+ * try a few more times.
+ */
+
+ if (ret != -EAGAIN)
+ {
+ /* Output some debug information if the transfer failed */
+
+ if (ret < 0)
+ {
+ usbhost_trace1(OTG_TRACE1_TRNSFRFAILED, ret);
+ }
+
+ /* Return the result in any event */
+
+ return ret;
+ }
+
+ /* Get the elapsed time (in frames) */
+
+ elapsed = clock_systimer() - start;
+ }
+ while (elapsed < STM32_SETUP_DELAY);
+
+ return -ETIMEDOUT;
+}
+
+/****************************************************************************
+ * Name: stm32_ctrl_senddata
+ *
+ * Description:
+ * Send data in the data phase of an OUT control transfer. Or send status
+ * in the status phase of an IN control transfer
+ *
+ ****************************************************************************/
+
+static int stm32_ctrl_senddata(FAR struct stm32_usbhost_s *priv,
+ FAR struct stm32_ctrlinfo_s *ep0,
+ FAR uint8_t *buffer, unsigned int buflen)
+{
+ FAR struct stm32_chan_s *chan = &priv->chan[ep0->outndx];
+ int ret;
+
+ /* Save buffer information */
+
+ chan->buffer = buffer;
+ chan->buflen = buflen;
+ chan->xfrd = 0;
+
+ /* Set the DATA PID */
+
+ if (buflen == 0)
+ {
+ /* For status OUT stage with buflen == 0, set PID DATA1 */
+
+ chan->outdata1 = true;
+ }
+
+ /* Set the Data PID as per the outdata1 boolean */
+
+ chan->pid = chan->outdata1 ? OTG_PID_DATA1 : OTG_PID_DATA0;
+
+ /* Set up for the wait BEFORE starting the transfer */
+
+ ret = stm32_chan_waitsetup(priv, chan);
+ if (ret < 0)
+ {
+ usbhost_trace1(OTG_TRACE1_DEVDISCONN, 0);
+ return ret;
+ }
+
+ /* Start the transfer */
+
+ stm32_transfer_start(priv, ep0->outndx);
+
+ /* Wait for the transfer to complete and return the result */
+
+ return stm32_chan_wait(priv, chan);
+}
+
+/****************************************************************************
+ * Name: stm32_ctrl_recvdata
+ *
+ * Description:
+ * Receive data in the data phase of an IN control transfer. Or receive status
+ * in the status phase of an OUT control transfer
+ *
+ ****************************************************************************/
+
+static int stm32_ctrl_recvdata(FAR struct stm32_usbhost_s *priv,
+ FAR struct stm32_ctrlinfo_s *ep0,
+ FAR uint8_t *buffer, unsigned int buflen)
+{
+ FAR struct stm32_chan_s *chan = &priv->chan[ep0->inndx];
+ int ret;
+
+ /* Save buffer information */
+
+ chan->pid = OTG_PID_DATA1;
+ chan->buffer = buffer;
+ chan->buflen = buflen;
+ chan->xfrd = 0;
+
+ /* Set up for the wait BEFORE starting the transfer */
+
+ ret = stm32_chan_waitsetup(priv, chan);
+ if (ret < 0)
+ {
+ usbhost_trace1(OTG_TRACE1_DEVDISCONN, 0);
+ return ret;
+ }
+
+ /* Start the transfer */
+
+ stm32_transfer_start(priv, ep0->inndx);
+
+ /* Wait for the transfer to complete and return the result */
+
+ return stm32_chan_wait(priv, chan);
+}
+
+/****************************************************************************
+ * Name: stm32_in_setup
+ *
+ * Description:
+ * Initiate an IN transfer on an bulk, interrupt, or isochronous pipe.
+ *
+ ****************************************************************************/
+
+static int stm32_in_setup(FAR struct stm32_usbhost_s *priv, int chidx)
+{
+ FAR struct stm32_chan_s *chan;
+
+ /* Set up for the transfer based on the direction and the endpoint type */
+
+ chan = &priv->chan[chidx];
+ switch (chan->eptype)
+ {
+ default:
+ case OTG_EPTYPE_CTRL: /* Control */
+ {
+ /* This kind of transfer on control endpoints other than EP0 are not
+ * currently supported
+ */
+
+ return -ENOSYS;
+ }
+
+ case OTG_EPTYPE_ISOC: /* Isochronous */
+ {
+ /* Set up the IN data PID */
+
+ usbhost_vtrace2(OTG_VTRACE2_ISOCIN, chidx, chan->buflen);
+ chan->pid = OTG_PID_DATA0;
+ }
+ break;
+
+ case OTG_EPTYPE_BULK: /* Bulk */
+ {
+ /* Setup the IN data PID */
+
+ usbhost_vtrace2(OTG_VTRACE2_BULKIN, chidx, chan->buflen);
+ chan->pid = chan->indata1 ? OTG_PID_DATA1 : OTG_PID_DATA0;
+ }
+ break;
+
+ case OTG_EPTYPE_INTR: /* Interrupt */
+ {
+ /* Setup the IN data PID */
+
+ usbhost_vtrace2(OTG_VTRACE2_INTRIN, chidx, chan->buflen);
+ chan->pid = chan->indata1 ? OTG_PID_DATA1 : OTG_PID_DATA0;
+ }
+ break;
+ }
+
+ /* Start the transfer */
+
+ stm32_transfer_start(priv, chidx);
+ return OK;
+}
+
+/****************************************************************************
+ * Name: stm32_in_transfer
+ *
+ * Description:
+ * Transfer 'buflen' bytes into 'buffer' from an IN channel.
+ *
+ ****************************************************************************/
+
+static ssize_t stm32_in_transfer(FAR struct stm32_usbhost_s *priv, int chidx,
+ FAR uint8_t *buffer, size_t buflen)
+{
+ FAR struct stm32_chan_s *chan;
+ systime_t start;
+ systime_t elapsed;
+ int ret;
+
+ /* Loop until the transfer completes (i.e., buflen is decremented to zero)
+ * or a fatal error occurs (any error other than a simple NAK)
+ */
+
+ chan = &priv->chan[chidx];
+ chan->buffer = buffer;
+ chan->buflen = buflen;
+ chan->xfrd = 0;
+
+ start = clock_systimer();
+ while (chan->xfrd < chan->buflen)
+ {
+ /* Set up for the wait BEFORE starting the transfer */
+
+ ret = stm32_chan_waitsetup(priv, chan);
+ if (ret < 0)
+ {
+ usbhost_trace1(OTG_TRACE1_DEVDISCONN, 0);
+ return (ssize_t)ret;
+ }
+
+ /* Set up for the transfer based on the direction and the endpoint type */
+
+ ret = stm32_in_setup(priv, chidx);
+ if (ret < 0)
+ {
+ uerr("ERROR: stm32_in_setup failed: %d\n", ret);
+ return (ssize_t)ret;
+ }
+
+ /* Wait for the transfer to complete and get the result */
+
+ ret = stm32_chan_wait(priv, chan);
+
+ /* EAGAIN indicates that the device NAKed the transfer and we need
+ * do try again. Anything else (success or other errors) will
+ * cause use to return
+ */
+
+ if (ret < 0)
+ {
+ usbhost_trace1(OTG_TRACE1_TRNSFRFAILED, ret);
+
+ /* Check for a special case: If (1) the transfer was NAKed and (2)
+ * no Tx FIFO empty or Rx FIFO not-empty event occurred, then we
+ * should be able to just flush the Rx and Tx FIFOs and try again.
+ * We can detect this latter case because the then the transfer
+ * buffer pointer and buffer size will be unaltered.
+ */
+
+ elapsed = clock_systimer() - start;
+ if (ret != -EAGAIN || /* Not a NAK condition OR */
+ elapsed >= STM32_DATANAK_DELAY || /* Timeout has elapsed OR */
+ chan->xfrd > 0) /* Data has been partially transferred */
+ {
+ /* Break out and return the error */
+
+ uerr("ERROR: stm32_chan_wait failed: %d\n", ret);
+ return (ssize_t)ret;
+ }
+ }
+ }
+
+ return (ssize_t)chan->xfrd;
+}
+
+/****************************************************************************
+ * Name: stm32_in_next
+ *
+ * Description:
+ * Initiate the next of a sequence of asynchronous transfers.
+ *
+ * Assumptions:
+ * This function is always called from an interrupt handler
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_USBHOST_ASYNCH
+static void stm32_in_next(FAR struct stm32_usbhost_s *priv,
+ FAR struct stm32_chan_s *chan)
+{
+ usbhost_asynch_t callback;
+ FAR void *arg;
+ ssize_t nbytes;
+ int result;
+ int ret;
+
+ /* Is the full transfer complete? Did the last chunk transfer complete OK? */
+
+ result = -(int)chan->result;
+ if (chan->xfrd < chan->buflen && result == OK)
+ {
+ /* Yes.. Set up for the next transfer based on the direction and the
+ * endpoint type
+ */
+
+ ret = stm32_in_setup(priv, chan->chidx);
+ if (ret >= 0)
+ {
+ return;
+ }
+
+ uerr("ERROR: stm32_in_setup failed: %d\n", ret);
+ result = ret;
+ }
+
+ /* The transfer is complete, with or without an error */
+
+ uinfo("Transfer complete: %d\n", result);
+
+ /* Extract the callback information */
+
+ callback = chan->callback;
+ arg = chan->arg;
+ nbytes = chan->xfrd;
+
+ chan->callback = NULL;
+ chan->arg = NULL;
+ chan->xfrd = 0;
+
+ /* Then perform the callback */
+
+ if (result < 0)
+ {
+ nbytes = (ssize_t)result;
+ }
+
+ callback(arg, nbytes);
+}
+#endif
+
+/****************************************************************************
+ * Name: stm32_in_asynch
+ *
+ * Description:
+ * Initiate the first of a sequence of asynchronous transfers.
+ *
+ * Assumptions:
+ * This function is never called from an interrupt handler
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_USBHOST_ASYNCH
+static int stm32_in_asynch(FAR struct stm32_usbhost_s *priv, int chidx,
+ FAR uint8_t *buffer, size_t buflen,
+ usbhost_asynch_t callback, FAR void *arg)
+{
+ FAR struct stm32_chan_s *chan;
+ int ret;
+
+ /* Set up for the transfer data and callback BEFORE starting the first transfer */
+
+ chan = &priv->chan[chidx];
+ chan->buffer = buffer;
+ chan->buflen = buflen;
+ chan->xfrd = 0;
+
+ ret = stm32_chan_asynchsetup(priv, chan, callback, arg);
+ if (ret < 0)
+ {
+ uerr("ERROR: stm32_chan_asynchsetup failed: %d\n", ret);
+ return ret;
+ }
+
+ /* Set up for the transfer based on the direction and the endpoint type */
+
+ ret = stm32_in_setup(priv, chidx);
+ if (ret < 0)
+ {
+ uerr("ERROR: stm32_in_setup failed: %d\n", ret);
+ }
+
+ /* And return with the transfer pending */
+
+ return ret;
+}
+#endif
+
+/****************************************************************************
+ * Name: stm32_out_setup
+ *
+ * Description:
+ * Initiate an OUT transfer on an bulk, interrupt, or isochronous pipe.
+ *
+ ****************************************************************************/
+
+static int stm32_out_setup(FAR struct stm32_usbhost_s *priv, int chidx)
+{
+ FAR struct stm32_chan_s *chan;
+
+ /* Set up for the transfer based on the direction and the endpoint type */
+
+ chan = &priv->chan[chidx];
+ switch (chan->eptype)
+ {
+ default:
+ case OTG_EPTYPE_CTRL: /* Control */
+ {
+ /* This kind of transfer on control endpoints other than EP0 are not
+ * currently supported
+ */
+
+ return -ENOSYS;
+ }
+
+ case OTG_EPTYPE_ISOC: /* Isochronous */
+ {
+ /* Set up the OUT data PID */
+
+ usbhost_vtrace2(OTG_VTRACE2_ISOCOUT, chidx, chan->buflen);
+ chan->pid = OTG_PID_DATA0;
+ }
+ break;
+
+ case OTG_EPTYPE_BULK: /* Bulk */
+ {
+ /* Setup the OUT data PID */
+
+ usbhost_vtrace2(OTG_VTRACE2_BULKOUT, chidx, chan->buflen);
+ chan->pid = chan->outdata1 ? OTG_PID_DATA1 : OTG_PID_DATA0;
+ }
+ break;
+
+ case OTG_EPTYPE_INTR: /* Interrupt */
+ {
+ /* Setup the OUT data PID */
+
+ usbhost_vtrace2(OTG_VTRACE2_INTROUT, chidx, chan->buflen);
+ chan->pid = chan->outdata1 ? OTG_PID_DATA1 : OTG_PID_DATA0;
+
+ /* Toggle the OUT data PID for the next transfer */
+
+ chan->outdata1 ^= true;
+ }
+ break;
+ }
+
+ /* Start the transfer */
+
+ stm32_transfer_start(priv, chidx);
+ return OK;
+}
+
+/****************************************************************************
+ * Name: stm32_out_transfer
+ *
+ * Description:
+ * Transfer the 'buflen' bytes in 'buffer' through an OUT channel.
+ *
+ ****************************************************************************/
+
+static ssize_t stm32_out_transfer(FAR struct stm32_usbhost_s *priv, int chidx,
+ FAR uint8_t *buffer, size_t buflen)
+{
+ FAR struct stm32_chan_s *chan;
+ systime_t start;
+ systime_t elapsed;
+ size_t xfrlen;
+ ssize_t xfrd;
+ int ret;
+
+ /* Loop until the transfer completes (i.e., buflen is decremented to zero)
+ * or a fatal error occurs (any error other than a simple NAK)
+ */
+
+ chan = &priv->chan[chidx];
+ start = clock_systimer();
+ xfrd = 0;
+
+ while (buflen > 0)
+ {
+ /* Transfer one packet at a time. The hardware is capable of queueing
+ * multiple OUT packets, but I just haven't figured out how to handle
+ * the case where a single OUT packet in the group is NAKed.
+ */
+
+ xfrlen = MIN(chan->maxpacket, buflen);
+ chan->buffer = buffer;
+ chan->buflen = xfrlen;
+ chan->xfrd = 0;
+
+ /* Set up for the wait BEFORE starting the transfer */
+
+ ret = stm32_chan_waitsetup(priv, chan);
+ if (ret < 0)
+ {
+ usbhost_trace1(OTG_TRACE1_DEVDISCONN, 0);
+ return (ssize_t)ret;
+ }
+
+ /* Set up for the transfer based on the direction and the endpoint type */
+
+ ret = stm32_out_setup(priv, chidx);
+ if (ret < 0)
+ {
+ uerr("ERROR: stm32_out_setup failed: %d\n", ret);
+ return (ssize_t)ret;
+ }
+
+ /* Wait for the transfer to complete and get the result */
+
+ ret = stm32_chan_wait(priv, chan);
+
+ /* Handle transfer failures */
+
+ if (ret < 0)
+ {
+ usbhost_trace1(OTG_TRACE1_TRNSFRFAILED, ret);
+
+ /* Check for a special case: If (1) the transfer was NAKed and (2)
+ * no Tx FIFO empty or Rx FIFO not-empty event occurred, then we
+ * should be able to just flush the Rx and Tx FIFOs and try again.
+ * We can detect this latter case because the then the transfer
+ * buffer pointer and buffer size will be unaltered.
+ */
+
+ elapsed = clock_systimer() - start;
+ if (ret != -EAGAIN || /* Not a NAK condition OR */
+ elapsed >= STM32_DATANAK_DELAY || /* Timeout has elapsed OR */
+ chan->xfrd > 0) /* Data has been partially transferred */
+ {
+ /* Break out and return the error */
+
+ uerr("ERROR: stm32_chan_wait failed: %d\n", ret);
+ return (ssize_t)ret;
+ }
+
+ /* Is this flush really necessary? What does the hardware do with the
+ * data in the FIFO when the NAK occurs? Does it discard it?
+ */
+
+ stm32_flush_txfifos(OTG_GRSTCTL_TXFNUM_HALL);
+
+ /* Get the device a little time to catch up. Then retry the transfer
+ * using the same buffer pointer and length.
+ */
+
+ usleep(20*1000);
+ }
+ else
+ {
+ /* Successfully transferred. Update the buffer pointer and length */
+
+ buffer += xfrlen;
+ buflen -= xfrlen;
+ xfrd += chan->xfrd;
+ }
+ }
+
+ return xfrd;
+}
+
+/****************************************************************************
+ * Name: stm32_out_next
+ *
+ * Description:
+ * Initiate the next of a sequence of asynchronous transfers.
+ *
+ * Assumptions:
+ * This function is always called from an interrupt handler
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_USBHOST_ASYNCH
+static void stm32_out_next(FAR struct stm32_usbhost_s *priv,
+ FAR struct stm32_chan_s *chan)
+{
+ usbhost_asynch_t callback;
+ FAR void *arg;
+ ssize_t nbytes;
+ int result;
+ int ret;
+
+ /* Is the full transfer complete? Did the last chunk transfer complete OK? */
+
+ result = -(int)chan->result;
+ if (chan->xfrd < chan->buflen && result == OK)
+ {
+ /* Yes.. Set up for the next transfer based on the direction and the
+ * endpoint type
+ */
+
+ ret = stm32_out_setup(priv, chan->chidx);
+ if (ret >= 0)
+ {
+ return;
+ }
+
+ uerr("ERROR: stm32_out_setup failed: %d\n", ret);
+ result = ret;
+ }
+
+ /* The transfer is complete, with or without an error */
+
+ uinfo("Transfer complete: %d\n", result);
+
+ /* Extract the callback information */
+
+ callback = chan->callback;
+ arg = chan->arg;
+ nbytes = chan->xfrd;
+
+ chan->callback = NULL;
+ chan->arg = NULL;
+ chan->xfrd = 0;
+
+ /* Then perform the callback */
+
+ if (result < 0)
+ {
+ nbytes = (ssize_t)result;
+ }
+
+ callback(arg, nbytes);
+}
+#endif
+
+/****************************************************************************
+ * Name: stm32_out_asynch
+ *
+ * Description:
+ * Initiate the first of a sequence of asynchronous transfers.
+ *
+ * Assumptions:
+ * This function is never called from an interrupt handler
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_USBHOST_ASYNCH
+static int stm32_out_asynch(FAR struct stm32_usbhost_s *priv, int chidx,
+ FAR uint8_t *buffer, size_t buflen,
+ usbhost_asynch_t callback, FAR void *arg)
+{
+ FAR struct stm32_chan_s *chan;
+ int ret;
+
+ /* Set up for the transfer data and callback BEFORE starting the first transfer */
+
+ chan = &priv->chan[chidx];
+ chan->buffer = buffer;
+ chan->buflen = buflen;
+ chan->xfrd = 0;
+
+ ret = stm32_chan_asynchsetup(priv, chan, callback, arg);
+ if (ret < 0)
+ {
+ uerr("ERROR: stm32_chan_asynchsetup failed: %d\n", ret);
+ return ret;
+ }
+
+ /* Set up for the transfer based on the direction and the endpoint type */
+
+ ret = stm32_out_setup(priv, chidx);
+ if (ret < 0)
+ {
+ uerr("ERROR: stm32_out_setup failed: %d\n", ret);
+ }
+
+ /* And return with the transfer pending */
+
+ return ret;
+}
+#endif
+
+/****************************************************************************
+ * Name: stm32_gint_wrpacket
+ *
+ * Description:
+ * Transfer the 'buflen' bytes in 'buffer' to the Tx FIFO associated with
+ * 'chidx' (non-DMA).
+ *
+ ****************************************************************************/
+
+static void stm32_gint_wrpacket(FAR struct stm32_usbhost_s *priv,
+ FAR uint8_t *buffer, int chidx, int buflen)
+{
+ FAR uint32_t *src;
+ uint32_t fifo;
+ int buflen32;
+
+ stm32_pktdump("Sending", buffer, buflen);
+
+ /* Get the number of 32-byte words associated with this byte size */
+
+ buflen32 = (buflen + 3) >> 2;
+
+ /* Get the address of the Tx FIFO associated with this channel */
+
+ fifo = STM32_OTG_DFIFO_HCH(chidx);
+
+ /* Transfer all of the data into the Tx FIFO */
+
+ src = (FAR uint32_t *)buffer;
+ for (; buflen32 > 0; buflen32--)
+ {
+ uint32_t data = *src++;
+ stm32_putreg(fifo, data);
+ }
+
+ /* Increment the count of bytes "in-flight" in the Tx FIFO */
+
+ priv->chan[chidx].inflight += buflen;
+}
+
+/****************************************************************************
+ * Name: stm32_gint_hcinisr
+ *
+ * Description:
+ * USB OTG FS host IN channels interrupt handler
+ *
+ * One the completion of the transfer, the channel result byte may be set as
+ * follows:
+ *
+ * OK - Transfer completed successfully
+ * EAGAIN - If devices NAKs the transfer or NYET occurs
+ * EPERM - If the endpoint stalls
+ * EIO - On a TX or data toggle error
+ * EPIPE - Frame overrun
+ *
+ * EBUSY in the result field indicates that the transfer has not completed.
+ *
+ ****************************************************************************/
+
+static inline void stm32_gint_hcinisr(FAR struct stm32_usbhost_s *priv,
+ int chidx)
+{
+ FAR struct stm32_chan_s *chan = &priv->chan[chidx];
+ uint32_t regval;
+ uint32_t pending;
+
+ /* Read the HCINT register to get the pending HC interrupts. Read the
+ * HCINTMSK register to get the set of enabled HC interrupts.
+ */
+
+ pending = stm32_getreg(STM32_OTG_HCINT(chidx));
+ regval = stm32_getreg(STM32_OTG_HCINTMSK(chidx));
+
+ /* AND the two to get the set of enabled, pending HC interrupts */
+
+ pending &= regval;
+ ullinfo("HCINTMSK%d: %08x pending: %08x\n", chidx, regval, pending);
+
+ /* Check for a pending ACK response received/transmitted (ACK) interrupt */
+
+ if ((pending & OTG_HCINT_ACK) != 0)
+ {
+ /* Clear the pending the ACK response received/transmitted (ACK) interrupt */
+
+ stm32_putreg(STM32_OTG_HCINT(chidx), OTG_HCINT_ACK);
+ }
+
+ /* Check for a pending STALL response receive (STALL) interrupt */
+
+ else if ((pending & OTG_HCINT_STALL) != 0)
+ {
+ /* Clear the NAK and STALL Conditions. */
+
+ stm32_putreg(STM32_OTG_HCINT(chidx), (OTG_HCINT_NAK | OTG_HCINT_STALL));
+
+ /* Halt the channel when a STALL, TXERR, BBERR or DTERR interrupt is
+ * received on the channel.
+ */
+
+ stm32_chan_halt(priv, chidx, CHREASON_STALL);
+
+ /* When there is a STALL, clear any pending NAK so that it is not
+ * processed below.
+ */
+
+ pending &= ~OTG_HCINT_NAK;
+ }
+
+ /* Check for a pending Data Toggle ERRor (DTERR) interrupt */
+
+ else if ((pending & OTG_HCINT_DTERR) != 0)
+ {
+ /* Halt the channel when a STALL, TXERR, BBERR or DTERR interrupt is
+ * received on the channel.
+ */
+
+ stm32_chan_halt(priv, chidx, CHREASON_DTERR);
+
+ /* Clear the NAK and data toggle error conditions */
+
+ stm32_putreg(STM32_OTG_HCINT(chidx), (OTG_HCINT_NAK | OTG_HCINT_DTERR));
+ }
+
+ /* Check for a pending FRaMe OverRun (FRMOR) interrupt */
+
+ if ((pending & OTG_HCINT_FRMOR) != 0)
+ {
+ /* Halt the channel -- the CHH interrupt is expected next */
+
+ stm32_chan_halt(priv, chidx, CHREASON_FRMOR);
+
+ /* Clear the FRaMe OverRun (FRMOR) condition */
+
+ stm32_putreg(STM32_OTG_HCINT(chidx), OTG_HCINT_FRMOR);
+ }
+
+ /* Check for a pending TransFeR Completed (XFRC) interrupt */
+
+ else if ((pending & OTG_HCINT_XFRC) != 0)
+ {
+ /* Clear the TransFeR Completed (XFRC) condition */
+
+ stm32_putreg(STM32_OTG_HCINT(chidx), OTG_HCINT_XFRC);
+
+ /* Then handle the transfer completion event based on the endpoint type */
+
+ if (chan->eptype == OTG_EPTYPE_CTRL || chan->eptype == OTG_EPTYPE_BULK)
+ {
+ /* Halt the channel -- the CHH interrupt is expected next */
+
+ stm32_chan_halt(priv, chidx, CHREASON_XFRC);
+
+ /* Clear any pending NAK condition. The 'indata1' data toggle
+ * should have been appropriately updated by the RxFIFO
+ * logic as each packet was received.
+ */
+
+ stm32_putreg(STM32_OTG_HCINT(chidx), OTG_HCINT_NAK);
+ }
+ else if (chan->eptype == OTG_EPTYPE_INTR)
+ {
+ /* Force the next transfer on an ODD frame */
+
+ regval = stm32_getreg(STM32_OTG_HCCHAR(chidx));
+ regval |= OTG_HCCHAR_ODDFRM;
+ stm32_putreg(STM32_OTG_HCCHAR(chidx), regval);
+
+ /* Set the request done state */
+
+ chan->result = OK;
+ }
+ }
+
+ /* Check for a pending CHannel Halted (CHH) interrupt */
+
+ else if ((pending & OTG_HCINT_CHH) != 0)
+ {
+ /* Mask the CHannel Halted (CHH) interrupt */
+
+ regval = stm32_getreg(STM32_OTG_HCINTMSK(chidx));
+ regval &= ~OTG_HCINT_CHH;
+ stm32_putreg(STM32_OTG_HCINTMSK(chidx), regval);
+
+ /* Update the request state based on the host state machine state */
+
+ if (chan->chreason == CHREASON_XFRC)
+ {
+ /* Set the request done result */
+
+ chan->result = OK;
+ }
+ else if (chan->chreason == CHREASON_STALL)
+ {
+ /* Set the request stall result */
+
+ chan->result = EPERM;
+ }
+ else if ((chan->chreason == CHREASON_TXERR) ||
+ (chan->chreason == CHREASON_DTERR))
+ {
+ /* Set the request I/O error result */
+
+ chan->result = EIO;
+ }
+ else if (chan->chreason == CHREASON_NAK)
+ {
+ /* Halt on NAK only happens on an INTR channel. Fetch the HCCHAR register
+ * and check for an interrupt endpoint.
+ */
+
+ regval = stm32_getreg(STM32_OTG_HCCHAR(chidx));
+ if ((regval & OTG_HCCHAR_EPTYP_MASK) == OTG_HCCHAR_EPTYP_INTR)
+ {
+ /* Toggle the IN data toggle (Used by Bulk and INTR only) */
+
+ chan->indata1 ^= true;
+ }
+
+ /* Set the NAK error result */
+
+ chan->result = EAGAIN;
+ }
+ else /* if (chan->chreason == CHREASON_FRMOR) */
+ {
+ /* Set the frame overrun error result */
+
+ chan->result = EPIPE;
+ }
+
+ /* Clear the CHannel Halted (CHH) condition */
+
+ stm32_putreg(STM32_OTG_HCINT(chidx), OTG_HCINT_CHH);
+ }
+
+ /* Check for a pending Transaction ERror (TXERR) interrupt */
+
+ else if ((pending & OTG_HCINT_TXERR) != 0)
+ {
+ /* Halt the channel when a STALL, TXERR, BBERR or DTERR interrupt is
+ * received on the channel.
+ */
+
+ stm32_chan_halt(priv, chidx, CHREASON_TXERR);
+
+ /* Clear the Transaction ERror (TXERR) condition */
+
+ stm32_putreg(STM32_OTG_HCINT(chidx), OTG_HCINT_TXERR);
+ }
+
+ /* Check for a pending NAK response received (NAK) interrupt */
+
+ else if ((pending & OTG_HCINT_NAK) != 0)
+ {
+ /* For a BULK transfer, the hardware is capable of retrying
+ * automatically on a NAK. However, this is not always
+ * what we need to do. So we always halt the transfer and
+ * return control to high level logic in the event of a NAK.
+ */
+
+#if 1
+ /* Halt the interrupt channel */
+
+ if (chan->eptype == OTG_EPTYPE_INTR)
+ {
+ /* Halt the channel -- the CHH interrupt is expected next */
+
+ stm32_chan_halt(priv, chidx, CHREASON_NAK);
+ }
+
+ /* Re-activate CTRL and BULK channels.
+ * REVISIT: This can cause a lot of interrupts!
+ */
+
+ else if (chan->eptype == OTG_EPTYPE_CTRL ||
+ chan->eptype == OTG_EPTYPE_BULK)
+ {
+ /* Re-activate the channel by clearing CHDIS and assuring that
+ * CHENA is set
+ */
+
+ regval = stm32_getreg(STM32_OTG_HCCHAR(chidx));
+ regval |= OTG_HCCHAR_CHENA;
+ regval &= ~OTG_HCCHAR_CHDIS;
+ stm32_putreg(STM32_OTG_HCCHAR(chidx), regval);
+ }
+#else
+ /* Halt all transfers on the NAK -- the CHH interrupt is expected next */
+
+ stm32_chan_halt(priv, chidx, CHREASON_NAK);
+#endif
+
+ /* Clear the NAK condition */
+
+ stm32_putreg(STM32_OTG_HCINT(chidx), OTG_HCINT_NAK);
+ }
+
+ /* Check for a transfer complete event */
+
+ stm32_chan_wakeup(priv, chan);
+}
+
+/****************************************************************************
+ * Name: stm32_gint_hcoutisr
+ *
+ * Description:
+ * USB OTG FS host OUT channels interrupt handler
+ *
+ * One the completion of the transfer, the channel result byte may be set as
+ * follows:
+ *
+ * OK - Transfer completed successfully
+ * EAGAIN - If devices NAKs the transfer or NYET occurs
+ * EPERM - If the endpoint stalls
+ * EIO - On a TX or data toggle error
+ * EPIPE - Frame overrun
+ *
+ * EBUSY in the result field indicates that the transfer has not completed.
+ *
+ ****************************************************************************/
+
+static inline void stm32_gint_hcoutisr(FAR struct stm32_usbhost_s *priv,
+ int chidx)
+{
+ FAR struct stm32_chan_s *chan = &priv->chan[chidx];
+ uint32_t regval;
+ uint32_t pending;
+
+ /* Read the HCINT register to get the pending HC interrupts. Read the
+ * HCINTMSK register to get the set of enabled HC interrupts.
+ */
+
+ pending = stm32_getreg(STM32_OTG_HCINT(chidx));
+ regval = stm32_getreg(STM32_OTG_HCINTMSK(chidx));
+
+ /* AND the two to get the set of enabled, pending HC interrupts */
+
+ pending &= regval;
+ ullinfo("HCINTMSK%d: %08x pending: %08x\n", chidx, regval, pending);
+
+ /* Check for a pending ACK response received/transmitted (ACK) interrupt */
+
+ if ((pending & OTG_HCINT_ACK) != 0)
+ {
+ /* Clear the pending the ACK response received/transmitted (ACK) interrupt */
+
+ stm32_putreg(STM32_OTG_HCINT(chidx), OTG_HCINT_ACK);
+ }
+
+ /* Check for a pending FRaMe OverRun (FRMOR) interrupt */
+
+ else if ((pending & OTG_HCINT_FRMOR) != 0)
+ {
+ /* Halt the channel (probably not necessary for FRMOR) */
+
+ stm32_chan_halt(priv, chidx, CHREASON_FRMOR);
+
+ /* Clear the pending the FRaMe OverRun (FRMOR) interrupt */
+
+ stm32_putreg(STM32_OTG_HCINT(chidx), OTG_HCINT_FRMOR);
+ }
+
+ /* Check for a pending TransFeR Completed (XFRC) interrupt */
+
+ else if ((pending & OTG_HCINT_XFRC) != 0)
+ {
+ /* Decrement the number of bytes remaining by the number of
+ * bytes that were "in-flight".
+ */
+
+ priv->chan[chidx].buffer += priv->chan[chidx].inflight;
+ priv->chan[chidx].xfrd += priv->chan[chidx].inflight;
+ priv->chan[chidx].inflight = 0;
+
+ /* Halt the channel -- the CHH interrupt is expected next */
+
+ stm32_chan_halt(priv, chidx, CHREASON_XFRC);
+
+ /* Clear the pending the TransFeR Completed (XFRC) interrupt */
+
+ stm32_putreg(STM32_OTG_HCINT(chidx), OTG_HCINT_XFRC);
+ }
+
+ /* Check for a pending STALL response receive (STALL) interrupt */
+
+ else if ((pending & OTG_HCINT_STALL) != 0)
+ {
+ /* Clear the pending the STALL response receiv (STALL) interrupt */
+
+ stm32_putreg(STM32_OTG_HCINT(chidx), OTG_HCINT_STALL);
+
+ /* Halt the channel when a STALL, TXERR, BBERR or DTERR interrupt is
+ * received on the channel.
+ */
+
+ stm32_chan_halt(priv, chidx, CHREASON_STALL);
+ }
+
+ /* Check for a pending NAK response received (NAK) interrupt */
+
+ else if ((pending & OTG_HCINT_NAK) != 0)
+ {
+ /* Halt the channel -- the CHH interrupt is expected next */
+
+ stm32_chan_halt(priv, chidx, CHREASON_NAK);
+
+ /* Clear the pending the NAK response received (NAK) interrupt */
+
+ stm32_putreg(STM32_OTG_HCINT(chidx), OTG_HCINT_NAK);
+ }
+
+ /* Check for a pending Transaction ERror (TXERR) interrupt */
+
+ else if ((pending & OTG_HCINT_TXERR) != 0)
+ {
+ /* Halt the channel when a STALL, TXERR, BBERR or DTERR interrupt is
+ * received on the channel.
+ */
+
+ stm32_chan_halt(priv, chidx, CHREASON_TXERR);
+
+ /* Clear the pending the Transaction ERror (TXERR) interrupt */
+
+ stm32_putreg(STM32_OTG_HCINT(chidx), OTG_HCINT_TXERR);
+ }
+
+ /* Check for a NYET interrupt */
+
+#if 0 /* NYET is a reserved bit in the HCINT register */
+ else if ((pending & OTG_HCINT_NYET) != 0)
+ {
+ /* Halt the channel */
+
+ stm32_chan_halt(priv, chidx, CHREASON_NYET);
+
+ /* Clear the pending the NYET interrupt */
+
+ stm32_putreg(STM32_OTG_HCINT(chidx), OTG_HCINT_NYET);
+ }
+#endif
+
+ /* Check for a pending Data Toggle ERRor (DTERR) interrupt */
+
+ else if (pending & OTG_HCINT_DTERR)
+ {
+ /* Halt the channel when a STALL, TXERR, BBERR or DTERR interrupt is
+ * received on the channel.
+ */
+
+ stm32_chan_halt(priv, chidx, CHREASON_DTERR);
+
+ /* Clear the pending the Data Toggle ERRor (DTERR) and NAK interrupts */
+
+ stm32_putreg(STM32_OTG_HCINT(chidx), (OTG_HCINT_DTERR | OTG_HCINT_NAK));
+ }
+
+ /* Check for a pending CHannel Halted (CHH) interrupt */
+
+ else if ((pending & OTG_HCINT_CHH) != 0)
+ {
+ /* Mask the CHannel Halted (CHH) interrupt */
+
+ regval = stm32_getreg(STM32_OTG_HCINTMSK(chidx));
+ regval &= ~OTG_HCINT_CHH;
+ stm32_putreg(STM32_OTG_HCINTMSK(chidx), regval);
+
+ if (chan->chreason == CHREASON_XFRC)
+ {
+ /* Set the request done result */
+
+ chan->result = OK;
+
+ /* Read the HCCHAR register to get the HCCHAR register to get
+ * the endpoint type.
+ */
+
+ regval = stm32_getreg(STM32_OTG_HCCHAR(chidx));
+
+ /* Is it a bulk endpoint? Were an odd number of packets
+ * transferred?
+ */
+
+ if ((regval & OTG_HCCHAR_EPTYP_MASK) == OTG_HCCHAR_EPTYP_BULK &&
+ (chan->npackets & 1) != 0)
+ {
+ /* Yes to both... toggle the data out PID */
+
+ chan->outdata1 ^= true;
+ }
+ }
+ else if (chan->chreason == CHREASON_NAK ||
+ chan->chreason == CHREASON_NYET)
+ {
+ /* Set the try again later result */
+
+ chan->result = EAGAIN;
+ }
+ else if (chan->chreason == CHREASON_STALL)
+ {
+ /* Set the request stall result */
+
+ chan->result = EPERM;
+ }
+ else if ((chan->chreason == CHREASON_TXERR) ||
+ (chan->chreason == CHREASON_DTERR))
+ {
+ /* Set the I/O failure result */
+
+ chan->result = EIO;
+ }
+ else /* if (chan->chreason == CHREASON_FRMOR) */
+ {
+ /* Set the frame error result */
+
+ chan->result = EPIPE;
+ }
+
+ /* Clear the pending the CHannel Halted (CHH) interrupt */
+
+ stm32_putreg(STM32_OTG_HCINT(chidx), OTG_HCINT_CHH);
+ }
+
+ /* Check for a transfer complete event */
+
+ stm32_chan_wakeup(priv, chan);
+}
+
+/****************************************************************************
+ * Name: stm32_gint_connected
+ *
+ * Description:
+ * Handle a connection event.
+ *
+ ****************************************************************************/
+
+static void stm32_gint_connected(FAR struct stm32_usbhost_s *priv)
+{
+ /* We we previously disconnected? */
+
+ if (!priv->connected)
+ {
+ /* Yes.. then now we are connected */
+
+ usbhost_vtrace1(OTG_VTRACE1_CONNECTED, 0);
+ priv->connected = true;
+ priv->change = true;
+ DEBUGASSERT(priv->smstate == SMSTATE_DETACHED);
+
+ /* Notify any waiters */
+
+ priv->smstate = SMSTATE_ATTACHED;
+ if (priv->pscwait)
+ {
+ stm32_givesem(&priv->pscsem);
+ priv->pscwait = false;
+ }
+ }
+}
+
+/****************************************************************************
+ * Name: stm32_gint_disconnected
+ *
+ * Description:
+ * Handle a disconnection event.
+ *
+ ****************************************************************************/
+
+static void stm32_gint_disconnected(FAR struct stm32_usbhost_s *priv)
+{
+ /* Were we previously connected? */
+
+ if (priv->connected)
+ {
+ /* Yes.. then we no longer connected */
+
+ usbhost_vtrace1(OTG_VTRACE1_DISCONNECTED, 0);
+
+ /* Are we bound to a class driver? */
+
+ if (priv->rhport.hport.devclass)
+ {
+ /* Yes.. Disconnect the class driver */
+
+ CLASS_DISCONNECTED(priv->rhport.hport.devclass);
+ priv->rhport.hport.devclass = NULL;
+ }
+
+ /* Re-Initialize Host for new Enumeration */
+
+ priv->smstate = SMSTATE_DETACHED;
+ priv->connected = false;
+ priv->change = true;
+ stm32_chan_freeall(priv);
+
+ priv->rhport.hport.speed = USB_SPEED_FULL;
+
+ /* Notify any waiters that there is a change in the connection state */
+
+ if (priv->pscwait)
+ {
+ stm32_givesem(&priv->pscsem);
+ priv->pscwait = false;
+ }
+ }
+}
+
+/****************************************************************************
+ * Name: stm32_gint_sofisr
+ *
+ * Description:
+ * USB OTG FS start-of-frame interrupt handler
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_STM32_OTG_SOFINTR
+static inline void stm32_gint_sofisr(FAR struct stm32_usbhost_s *priv)
+{
+ /* Handle SOF interrupt */
+#warning "Do what?"
+
+ /* Clear pending SOF interrupt */
+
+ stm32_putreg(STM32_OTG_GINTSTS, OTG_GINT_SOF);
+}
+#endif
+
+/****************************************************************************
+ * Name: stm32_gint_rxflvlisr
+ *
+ * Description:
+ * USB OTG FS RxFIFO non-empty interrupt handler
+ *
+ ****************************************************************************/
+
+static inline void stm32_gint_rxflvlisr(FAR struct stm32_usbhost_s *priv)
+{
+ FAR uint32_t *dest;
+ uint32_t grxsts;
+ uint32_t intmsk;
+ uint32_t hcchar;
+ uint32_t hctsiz;
+ uint32_t fifo;
+ int bcnt;
+ int bcnt32;
+ int chidx;
+ int i;
+
+ /* Disable the RxFIFO non-empty interrupt */
+
+ intmsk = stm32_getreg(STM32_OTG_GINTMSK);
+ intmsk &= ~OTG_GINT_RXFLVL;
+ stm32_putreg(STM32_OTG_GINTMSK, intmsk);
+
+ /* Read and pop the next status from the Rx FIFO */
+
+ grxsts = stm32_getreg(STM32_OTG_GRXSTSP);
+ ullinfo("GRXSTS: %08x\n", grxsts);
+
+ /* Isolate the channel number/index in the status word */
+
+ chidx = (grxsts & OTG_GRXSTSH_CHNUM_MASK) >> OTG_GRXSTSH_CHNUM_SHIFT;
+
+ /* Get the host channel characteristics register (HCCHAR) for this channel */
+
+ hcchar = stm32_getreg(STM32_OTG_HCCHAR(chidx));
+
+ /* Then process the interrupt according to the packet status */
+
+ switch (grxsts & OTG_GRXSTSH_PKTSTS_MASK)
+ {
+ case OTG_GRXSTSH_PKTSTS_INRECVD: /* IN data packet received */
+ {
+ /* Read the data into the host buffer. */
+
+ bcnt = (grxsts & OTG_GRXSTSH_BCNT_MASK) >> OTG_GRXSTSH_BCNT_SHIFT;
+ if (bcnt > 0 && priv->chan[chidx].buffer != NULL)
+ {
+ /* Transfer the packet from the Rx FIFO into the user buffer */
+
+ dest = (FAR uint32_t *)priv->chan[chidx].buffer;
+ fifo = STM32_OTG_DFIFO_HCH(0);
+ bcnt32 = (bcnt + 3) >> 2;
+
+ for (i = 0; i < bcnt32; i++)
+ {
+ *dest++ = stm32_getreg(fifo);
+ }
+
+ stm32_pktdump("Received", priv->chan[chidx].buffer, bcnt);
+
+ /* Toggle the IN data pid (Used by Bulk and INTR only) */
+
+ priv->chan[chidx].indata1 ^= true;
+
+ /* Manage multiple packet transfers */
+
+ priv->chan[chidx].buffer += bcnt;
+ priv->chan[chidx].xfrd += bcnt;
+
+ /* Check if more packets are expected */
+
+ hctsiz = stm32_getreg(STM32_OTG_HCTSIZ(chidx));
+ if ((hctsiz & OTG_HCTSIZ_PKTCNT_MASK) != 0)
+ {
+ /* Re-activate the channel when more packets are expected */
+
+ hcchar |= OTG_HCCHAR_CHENA;
+ hcchar &= ~OTG_HCCHAR_CHDIS;
+ stm32_putreg(STM32_OTG_HCCHAR(chidx), hcchar);
+ }
+ }
+ }
+ break;
+
+ case OTG_GRXSTSH_PKTSTS_INDONE: /* IN transfer completed */
+ case OTG_GRXSTSH_PKTSTS_DTOGERR: /* Data toggle error */
+ case OTG_GRXSTSH_PKTSTS_HALTED: /* Channel halted */
+ default:
+ break;
+ }
+
+ /* Re-enable the RxFIFO non-empty interrupt */
+
+ intmsk |= OTG_GINT_RXFLVL;
+ stm32_putreg(STM32_OTG_GINTMSK, intmsk);
+}
+
+/****************************************************************************
+ * Name: stm32_gint_nptxfeisr
+ *
+ * Description:
+ * USB OTG FS non-periodic TxFIFO empty interrupt handler
+ *
+ ****************************************************************************/
+
+static inline void stm32_gint_nptxfeisr(FAR struct stm32_usbhost_s *priv)
+{
+ FAR struct stm32_chan_s *chan;
+ uint32_t regval;
+ unsigned int wrsize;
+ unsigned int avail;
+ unsigned int chidx;
+
+ /* Recover the index of the channel that is waiting for space in the Tx
+ * FIFO.
+ */
+
+ chidx = priv->chidx;
+ chan = &priv->chan[chidx];
+
+ /* Reduce the buffer size by the number of bytes that were previously placed
+ * in the Tx FIFO.
+ */
+
+ chan->buffer += chan->inflight;
+ chan->xfrd += chan->inflight;
+ chan->inflight = 0;
+
+ /* If we have now transferred the entire buffer, then this transfer is
+ * complete (this case really should never happen because we disable
+ * the NPTXFE interrupt on the final packet).
+ */
+
+ if (chan->xfrd >= chan->buflen)
+ {
+ /* Disable further Tx FIFO empty interrupts and bail. */
+
+ stm32_modifyreg(STM32_OTG_GINTMSK, OTG_GINT_NPTXFE, 0);
+ return;
+ }
+
+ /* Read the status from the top of the non-periodic TxFIFO */
+
+ regval = stm32_getreg(STM32_OTG_HNPTXSTS);
+
+ /* Extract the number of bytes available in the non-periodic Tx FIFO. */
+
+ avail = ((regval & OTG_HNPTXSTS_NPTXFSAV_MASK) >> OTG_HNPTXSTS_NPTXFSAV_SHIFT) << 2;
+
+ /* Get the size to put in the Tx FIFO now */
+
+ wrsize = chan->buflen - chan->xfrd;
+
+ /* Get minimal size packet that can be sent. Something is seriously
+ * configured wrong if one packet will not fit into the empty Tx FIFO.
+ */
+
+ DEBUGASSERT(wrsize > 0 && avail >= MIN(wrsize, chan->maxpacket));
+ if (wrsize > avail)
+ {
+ /* Clip the write size to the number of full, max sized packets
+ * that will fit in the Tx FIFO.
+ */
+
+ unsigned int wrpackets = avail / chan->maxpacket;
+ wrsize = wrpackets * chan->maxpacket;
+ }
+
+ /* Otherwise, this will be the last packet to be sent in this transaction.
+ * We now need to disable further NPTXFE interrupts.
+ */
+
+ else
+ {
+ stm32_modifyreg(STM32_OTG_GINTMSK, OTG_GINT_NPTXFE, 0);
+ }
+
+ /* Write the next group of packets into the Tx FIFO */
+
+ ullinfo("HNPTXSTS: %08x chidx: %d avail: %d buflen: %d xfrd: %d wrsize: %d\n",
+ regval, chidx, avail, chan->buflen, chan->xfrd, wrsize);
+
+ stm32_gint_wrpacket(priv, chan->buffer, chidx, wrsize);
+}
+
+/****************************************************************************
+ * Name: stm32_gint_ptxfeisr
+ *
+ * Description:
+ * USB OTG FS periodic TxFIFO empty interrupt handler
+ *
+ ****************************************************************************/
+
+static inline void stm32_gint_ptxfeisr(FAR struct stm32_usbhost_s *priv)
+{
+ FAR struct stm32_chan_s *chan;
+ uint32_t regval;
+ unsigned int wrsize;
+ unsigned int avail;
+ unsigned int chidx;
+
+ /* Recover the index of the channel that is waiting for space in the Tx
+ * FIFO.
+ */
+
+ chidx = priv->chidx;
+ chan = &priv->chan[chidx];
+
+ /* Reduce the buffer size by the number of bytes that were previously placed
+ * in the Tx FIFO.
+ */
+
+ chan->buffer += chan->inflight;
+ chan->xfrd += chan->inflight;
+ chan->inflight = 0;
+
+ /* If we have now transfered the entire buffer, then this transfer is
+ * complete (this case really should never happen because we disable
+ * the PTXFE interrupt on the final packet).
+ */
+
+ if (chan->xfrd >= chan->buflen)
+ {
+ /* Disable further Tx FIFO empty interrupts and bail. */
+
+ stm32_modifyreg(STM32_OTG_GINTMSK, OTG_GINT_PTXFE, 0);
+ return;
+ }
+
+ /* Read the status from the top of the periodic TxFIFO */
+
+ regval = stm32_getreg(STM32_OTG_HPTXSTS);
+
+ /* Extract the number of bytes available in the periodic Tx FIFO. */
+
+ avail = ((regval & OTG_HPTXSTS_PTXFSAVL_MASK) >> OTG_HPTXSTS_PTXFSAVL_SHIFT) << 2;
+
+ /* Get the size to put in the Tx FIFO now */
+
+ wrsize = chan->buflen - chan->xfrd;
+
+ /* Get minimal size packet that can be sent. Something is seriously
+ * configured wrong if one packet will not fit into the empty Tx FIFO.
+ */
+
+ DEBUGASSERT(wrsize && avail >= MIN(wrsize, chan->maxpacket));
+ if (wrsize > avail)
+ {
+ /* Clip the write size to the number of full, max sized packets
+ * that will fit in the Tx FIFO.
+ */
+
+ unsigned int wrpackets = avail / chan->maxpacket;
+ wrsize = wrpackets * chan->maxpacket;
+ }
+
+ /* Otherwise, this will be the last packet to be sent in this transaction.
+ * We now need to disable further PTXFE interrupts.
+ */
+
+ else
+ {
+ stm32_modifyreg(STM32_OTG_GINTMSK, OTG_GINT_PTXFE, 0);
+ }
+
+ /* Write the next group of packets into the Tx FIFO */
+
+ ullinfo("HPTXSTS: %08x chidx: %d avail: %d buflen: %d xfrd: %d wrsize: %d\n",
+ regval, chidx, avail, chan->buflen, chan->xfrd, wrsize);
+
+ stm32_gint_wrpacket(priv, chan->buffer, chidx, wrsize);
+}
+
+/****************************************************************************
+ * Name: stm32_gint_hcisr
+ *
+ * Description:
+ * USB OTG FS host channels interrupt handler
+ *
+ ****************************************************************************/
+
+static inline void stm32_gint_hcisr(FAR struct stm32_usbhost_s *priv)
+{
+ uint32_t haint;
+ uint32_t hcchar;
+ int i = 0;
+
+ /* Read the Host all channels interrupt register and test each bit in the
+ * register. Each bit i, i=0...(STM32_NHOST_CHANNELS-1), corresponds to
+ * a pending interrupt on channel i.
+ */
+
+ haint = stm32_getreg(STM32_OTG_HAINT);
+ for (i = 0; i < STM32_NHOST_CHANNELS; i++)
+ {
+ /* Is an interrupt pending on this channel? */
+
+ if ((haint & OTG_HAINT(i)) != 0)
+ {
+ /* Yes... read the HCCHAR register to get the direction bit */
+
+ hcchar = stm32_getreg(STM32_OTG_HCCHAR(i));
+
+ /* Was this an interrupt on an IN or an OUT channel? */
+
+ if ((hcchar & OTG_HCCHAR_EPDIR) != 0)
+ {
+ /* Handle the HC IN channel interrupt */
+
+ stm32_gint_hcinisr(priv, i);
+ }
+ else
+ {
+ /* Handle the HC OUT channel interrupt */
+
+ stm32_gint_hcoutisr(priv, i);
+ }
+ }
+ }
+}
+
+/****************************************************************************
+ * Name: stm32_gint_hprtisr
+ *
+ * Description:
+ * USB OTG FS host port interrupt handler
+ *
+ ****************************************************************************/
+
+static inline void stm32_gint_hprtisr(FAR struct stm32_usbhost_s *priv)
+{
+ uint32_t hprt;
+ uint32_t newhprt;
+ uint32_t hcfg;
+
+ usbhost_vtrace1(OTG_VTRACE1_GINT_HPRT, 0);
+ /* Read the port status and control register (HPRT) */
+
+ hprt = stm32_getreg(STM32_OTG_HPRT);
+
+ /* Setup to clear the interrupt bits in GINTSTS by setting the corresponding
+ * bits in the HPRT. The HCINT interrupt bit is cleared when the appropriate
+ * status bits in the HPRT register are cleared.
+ */
+
+ newhprt = hprt & ~(OTG_HPRT_PENA | OTG_HPRT_PCDET |
+ OTG_HPRT_PENCHNG | OTG_HPRT_POCCHNG);
+
+ /* Check for Port Overcurrent CHaNGe (POCCHNG) */
+
+ if ((hprt & OTG_HPRT_POCCHNG) != 0)
+ {
+ /* Set up to clear the POCCHNG status in the new HPRT contents. */
+
+ usbhost_vtrace1(OTG_VTRACE1_GINT_HPRT_POCCHNG, 0);
+ newhprt |= OTG_HPRT_POCCHNG;
+ }
+
+ /* Check for Port Connect DETected (PCDET). The core sets this bit when a
+ * device connection is detected.
+ */
+
+ if ((hprt & OTG_HPRT_PCDET) != 0)
+ {
+ /* Set up to clear the PCDET status in the new HPRT contents. Then
+ * process the new connection event.
+ */
+
+ usbhost_vtrace1(OTG_VTRACE1_GINT_HPRT_PCDET, 0);
+ newhprt |= OTG_HPRT_PCDET;
+ stm32_portreset(priv);
+ stm32_gint_connected(priv);
+ }
+
+ /* Check for Port Enable CHaNGed (PENCHNG) */
+
+ if ((hprt & OTG_HPRT_PENCHNG) != 0)
+ {
+ /* Set up to clear the PENCHNG status in the new HPRT contents. */
+
+ usbhost_vtrace1(OTG_VTRACE1_GINT_HPRT_PENCHNG, 0);
+ newhprt |= OTG_HPRT_PENCHNG;
+
+ /* Was the port enabled? */
+
+ if ((hprt & OTG_HPRT_PENA) != 0)
+ {
+ /* Yes.. handle the new connection event */
+
+ stm32_gint_connected(priv);
+
+ /* Check the Host ConFiGuration register (HCFG) */
+
+ hcfg = stm32_getreg(STM32_OTG_HCFG);
+
+ /* Is this a low speed or full speed connection (OTG FS does not
+ * support high speed)
+ */
+
+ if ((hprt & OTG_HPRT_PSPD_MASK) == OTG_HPRT_PSPD_LS)
+ {
+ /* Set the Host Frame Interval Register for the 6KHz speed */
+
+ usbhost_vtrace1(OTG_VTRACE1_GINT_HPRT_LSDEV, 0);
+ stm32_putreg(STM32_OTG_HFIR, 6000);
+
+ /* Are we switching from FS to LS? */
+
+ if ((hcfg & OTG_HCFG_FSLSPCS_MASK) != OTG_HCFG_FSLSPCS_LS6MHz)
+ {
+ usbhost_vtrace1(OTG_VTRACE1_GINT_HPRT_FSLSSW, 0);
+
+ /* Yes... configure for LS */
+
+ hcfg &= ~OTG_HCFG_FSLSPCS_MASK;
+ hcfg |= OTG_HCFG_FSLSPCS_LS6MHz;
+ stm32_putreg(STM32_OTG_HCFG, hcfg);
+
+ /* And reset the port */
+
+ stm32_portreset(priv);
+ }
+ }
+ else /* if ((hprt & OTG_HPRT_PSPD_MASK) == OTG_HPRT_PSPD_FS) */
+ {
+
+ usbhost_vtrace1(OTG_VTRACE1_GINT_HPRT_FSDEV, 0);
+ stm32_putreg(STM32_OTG_HFIR, 48000);
+
+ /* Are we switching from LS to FS? */
+
+ if ((hcfg & OTG_HCFG_FSLSPCS_MASK) != OTG_HCFG_FSLSPCS_FS48MHz)
+ {
+
+ usbhost_vtrace1(OTG_VTRACE1_GINT_HPRT_LSFSSW, 0);
+ /* Yes... configure for FS */
+
+ hcfg &= ~OTG_HCFG_FSLSPCS_MASK;
+ hcfg |= OTG_HCFG_FSLSPCS_FS48MHz;
+ stm32_putreg(STM32_OTG_HCFG, hcfg);
+
+ /* And reset the port */
+
+ stm32_portreset(priv);
+ }
+ }
+ }
+ }
+
+ /* Clear port interrupts by setting bits in the HPRT */
+
+ stm32_putreg(STM32_OTG_HPRT, newhprt);
+}
+
+/****************************************************************************
+ * Name: stm32_gint_discisr
+ *
+ * Description:
+ * USB OTG FS disconnect detected interrupt handler
+ *
+ ****************************************************************************/
+
+static inline void stm32_gint_discisr(FAR struct stm32_usbhost_s *priv)
+{
+ /* Handle the disconnection event */
+
+ stm32_gint_disconnected(priv);
+
+ /* Clear the dicsonnect interrupt */
+
+ stm32_putreg(STM32_OTG_GINTSTS, OTG_GINT_DISC);
+}
+
+/****************************************************************************
+ * Name: stm32_gint_ipxfrisr
+ *
+ * Description:
+ * USB OTG FS incomplete periodic interrupt handler
+ *
+ ****************************************************************************/
+
+static inline void stm32_gint_ipxfrisr(FAR struct stm32_usbhost_s *priv)
+{
+ uint32_t regval;
+
+ /* CHENA : Set to enable the channel
+ * CHDIS : Set to stop transmitting/receiving data on a channel
+ */
+
+ regval = stm32_getreg(STM32_OTG_HCCHAR(0));
+ regval |= (OTG_HCCHAR_CHDIS | OTG_HCCHAR_CHENA);
+ stm32_putreg(STM32_OTG_HCCHAR(0), regval);
+
+ /* Clear the incomplete isochronous OUT interrupt */
+
+ stm32_putreg(STM32_OTG_GINTSTS, OTG_GINT_IPXFR);
+}
+
+/****************************************************************************
+ * Name: stm32_gint_isr
+ *
+ * Description:
+ * USB OTG FS global interrupt handler
+ *
+ ****************************************************************************/
+
+static int stm32_gint_isr(int irq, FAR void *context)
+{
+ /* At present, there is only support for a single OTG FS host. Hence it is
+ * pre-allocated as g_usbhost. However, in most code, the private data
+ * structure will be referenced using the 'priv' pointer (rather than the
+ * global data) in order to simplify any future support for multiple devices.
+ */
+
+ FAR struct stm32_usbhost_s *priv = &g_usbhost;
+ uint32_t pending;
+
+ /* If OTG were supported, we would need to check if we are in host or
+ * device mode when the global interrupt occurs. Here we support only
+ * host mode
+ */
+
+ /* Loop while there are pending interrupts to process. This loop may save a
+ * little interrupt handling overhead.
+ */
+
+ for (; ; )
+ {
+ /* Get the unmasked bits in the GINT status */
+
+ pending = stm32_getreg(STM32_OTG_GINTSTS);
+ pending &= stm32_getreg(STM32_OTG_GINTMSK);
+
+ /* Return from the interrupt when there are no further pending
+ * interrupts.
+ */
+
+ if (pending == 0)
+ {
+ return OK;
+ }
+
+ /* Otherwise, process each pending, unmasked GINT interrupts */
+
+ /* Handle the start of frame interrupt */
+
+#ifdef CONFIG_STM32_OTG_SOFINTR
+ if ((pending & OTG_GINT_SOF) != 0)
+ {
+ usbhost_vtrace1(OTG_VTRACE1_GINT_SOF, 0);
+ stm32_gint_sofisr(priv);
+ }
+#endif
+
+ /* Handle the RxFIFO non-empty interrupt */
+
+ if ((pending & OTG_GINT_RXFLVL) != 0)
+ {
+ usbhost_vtrace1(OTG_VTRACE1_GINT_RXFLVL, 0);
+ stm32_gint_rxflvlisr(priv);
+ }
+
+ /* Handle the non-periodic TxFIFO empty interrupt */
+
+ if ((pending & OTG_GINT_NPTXFE) != 0)
+ {
+ usbhost_vtrace1(OTG_VTRACE1_GINT_NPTXFE, 0);
+ stm32_gint_nptxfeisr(priv);
+ }
+
+ /* Handle the periodic TxFIFO empty interrupt */
+
+ if ((pending & OTG_GINT_PTXFE) != 0)
+ {
+ usbhost_vtrace1(OTG_VTRACE1_GINT_PTXFE, 0);
+ stm32_gint_ptxfeisr(priv);
+ }
+
+ /* Handle the host channels interrupt */
+
+ if ((pending & OTG_GINT_HC) != 0)
+ {
+ usbhost_vtrace1(OTG_VTRACE1_GINT_HC, 0);
+ stm32_gint_hcisr(priv);
+ }
+
+ /* Handle the host port interrupt */
+
+ if ((pending & OTG_GINT_HPRT) != 0)
+ {
+ stm32_gint_hprtisr(priv);
+ }
+
+ /* Handle the disconnect detected interrupt */
+
+ if ((pending & OTG_GINT_DISC) != 0)
+ {
+ usbhost_vtrace1(OTG_VTRACE1_GINT_DISC, 0);
+ stm32_gint_discisr(priv);
+ }
+
+ /* Handle the incomplete periodic transfer */
+
+ if ((pending & OTG_GINT_IPXFR) != 0)
+ {
+ usbhost_vtrace1(OTG_VTRACE1_GINT_IPXFR, 0);
+ stm32_gint_ipxfrisr(priv);
+ }
+ }
+
+ /* We won't get here */
+
+ return OK;
+}
+
+/****************************************************************************
+ * Name: stm32_gint_enable and stm32_gint_disable
+ *
+ * Description:
+ * Respectively enable or disable the global OTG FS interrupt.
+ *
+ * Input Parameters:
+ * None
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+static void stm32_gint_enable(void)
+{
+ uint32_t regval;
+
+ /* Set the GINTMSK bit to unmask the interrupt */
+
+ regval = stm32_getreg(STM32_OTG_GAHBCFG);
+ regval |= OTG_GAHBCFG_GINTMSK;
+ stm32_putreg(STM32_OTG_GAHBCFG, regval);
+}
+
+static void stm32_gint_disable(void)
+{
+ uint32_t regval;
+
+ /* Clear the GINTMSK bit to mask the interrupt */
+
+ regval = stm32_getreg(STM32_OTG_GAHBCFG);
+ regval &= ~OTG_GAHBCFG_GINTMSK;
+ stm32_putreg(STM32_OTG_GAHBCFG, regval);
+}
+
+/****************************************************************************
+ * Name: stm32_hostinit_enable
+ *
+ * Description:
+ * Enable host interrupts.
+ *
+ * Input Parameters:
+ * None
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+static inline void stm32_hostinit_enable(void)
+{
+ uint32_t regval;
+
+ /* Disable all interrupts. */
+
+ stm32_putreg(STM32_OTG_GINTMSK, 0);
+
+ /* Clear any pending interrupts. */
+
+ stm32_putreg(STM32_OTG_GINTSTS, 0xffffffff);
+
+ /* Clear any pending USB OTG Interrupts (should be done elsewhere if OTG is supported) */
+
+ stm32_putreg(STM32_OTG_GOTGINT, 0xffffffff);
+
+ /* Clear any pending USB OTG interrupts */
+
+ stm32_putreg(STM32_OTG_GINTSTS, 0xbfffffff);
+
+ /* Enable the host interrupts */
+ /* Common interrupts:
+ *
+ * OTG_GINT_WKUP : Resume/remote wakeup detected interrupt
+ * OTG_GINT_USBSUSP : USB suspend
+ */
+
+ regval = (OTG_GINT_WKUP | OTG_GINT_USBSUSP);
+
+ /* If OTG were supported, we would need to enable the following as well:
+ *
+ * OTG_GINT_OTG : OTG interrupt
+ * OTG_GINT_SRQ : Session request/new session detected interrupt
+ * OTG_GINT_CIDSCHG : Connector ID status change
+ */
+
+ /* Host-specific interrupts
+ *
+ * OTG_GINT_SOF : Start of frame
+ * OTG_GINT_RXFLVL : RxFIFO non-empty
+ * OTG_GINT_IISOOXFR : Incomplete isochronous OUT transfer
+ * OTG_GINT_HPRT : Host port interrupt
+ * OTG_GINT_HC : Host channels interrupt
+ * OTG_GINT_DISC : Disconnect detected interrupt
+ */
+
+#ifdef CONFIG_STM32_OTG_SOFINTR
+ regval |= (OTG_GINT_SOF | OTG_GINT_RXFLVL | OTG_GINT_IISOOXFR |
+ OTG_GINT_HPRT | OTG_GINT_HC | OTG_GINT_DISC);
+#else
+ regval |= (OTG_GINT_RXFLVL | OTG_GINT_IPXFR | OTG_GINT_HPRT |
+ OTG_GINT_HC | OTG_GINT_DISC);
+#endif
+ stm32_putreg(STM32_OTG_GINTMSK, regval);
+}
+
+/****************************************************************************
+ * Name: stm32_txfe_enable
+ *
+ * Description:
+ * Enable Tx FIFO empty interrupts. This is necessary when the entire
+ * transfer will not fit into Tx FIFO. The transfer will then be completed
+ * when the Tx FIFO is empty. NOTE: The Tx FIFO interrupt is disabled
+ * the fifo empty interrupt handler when the transfer is complete.
+ *
+ * Input Parameters:
+ * priv - Driver state structure reference
+ * chidx - The channel that requires the Tx FIFO empty interrupt
+ *
+ * Returned Value:
+ * None
+ *
+ * Assumptions:
+ * Called from user task context. Interrupts must be disabled to assure
+ * exclusive access to the GINTMSK register.
+ *
+ ****************************************************************************/
+
+static void stm32_txfe_enable(FAR struct stm32_usbhost_s *priv, int chidx)
+{
+ FAR struct stm32_chan_s *chan = &priv->chan[chidx];
+ irqstate_t flags;
+ uint32_t regval;
+
+ /* Disable all interrupts so that we have exclusive access to the GINTMSK
+ * (it would be sufficent just to disable the GINT interrupt).
+ */
+
+ flags = enter_critical_section();
+
+ /* Should we enable the periodic or non-peridic Tx FIFO empty interrupts */
+
+ regval = stm32_getreg(STM32_OTG_GINTMSK);
+ switch (chan->eptype)
+ {
+ default:
+ case OTG_EPTYPE_CTRL: /* Non periodic transfer */
+ case OTG_EPTYPE_BULK:
+ regval |= OTG_GINT_NPTXFE;
+ break;
+
+ case OTG_EPTYPE_INTR: /* Periodic transfer */
+ case OTG_EPTYPE_ISOC:
+ regval |= OTG_GINT_PTXFE;
+ break;
+ }
+
+ /* Enable interrupts */
+
+ stm32_putreg(STM32_OTG_GINTMSK, regval);
+ leave_critical_section(flags);
+}
+
+/****************************************************************************
+ * USB Host Controller Operations
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: stm32_wait
+ *
+ * Description:
+ * Wait for a device to be connected or disconnected to/from a hub port.
+ *
+ * Input Parameters:
+ * conn - The USB host connection instance obtained as a parameter from the call to
+ * the USB driver initialization logic.
+ * hport - The location to return the hub port descriptor that detected the
+ * connection related event.
+ *
+ * Returned Values:
+ * Zero (OK) is returned on success when a device in connected or
+ * disconnected. This function will not return until either (1) a device is
+ * connected or disconnect to/from any hub port or until (2) some failure
+ * occurs. On a failure, a negated errno value is returned indicating the
+ * nature of the failure
+ *
+ * Assumptions:
+ * - Called from a single thread so no mutual exclusion is required.
+ * - Never called from an interrupt handler.
+ *
+ ****************************************************************************/
+
+static int stm32_wait(FAR struct usbhost_connection_s *conn,
+ FAR struct usbhost_hubport_s **hport)
+{
+ FAR struct stm32_usbhost_s *priv = &g_usbhost;
+ struct usbhost_hubport_s *connport;
+ irqstate_t flags;
+
+ /* Loop until a change in connection state is detected */
+
+ flags = enter_critical_section();
+ for (; ; )
+ {
+ /* Is there a change in the connection state of the single root hub
+ * port?
+ */
+
+ if (priv->change)
+ {
+ connport = &priv->rhport.hport;
+
+ /* Yes. Remember the new state */
+
+ connport->connected = priv->connected;
+ priv->change = false;
+
+ /* And return the root hub port */
+
+ *hport = connport;
+ leave_critical_section(flags);
+
+ uinfo("RHport Connected: %s\n", connport->connected ? "YES" : "NO");
+ return OK;
+ }
+
+#ifdef CONFIG_USBHOST_HUB
+ /* Is a device connected to an external hub? */
+
+ if (priv->hport)
+ {
+ /* Yes.. return the external hub port */
+
+ connport = (struct usbhost_hubport_s *)priv->hport;
+ priv->hport = NULL;
+
+ *hport = connport;
+ leave_critical_section(flags);
+
+ uinfo("Hub port Connected: %s\n", connport->connected ? "YES" : "NO");
+ return OK;
+ }
+#endif
+
+ /* Wait for the next connection event */
+
+ priv->pscwait = true;
+ stm32_takesem(&priv->pscsem);
+ }
+}
+
+/****************************************************************************
+ * Name: stm32_enumerate
+ *
+ * Description:
+ * Enumerate the connected device. As part of this enumeration process,
+ * the driver will (1) get the device's configuration descriptor, (2)
+ * extract the class ID info from the configuration descriptor, (3) call
+ * usbhost_findclass() to find the class that supports this device, (4)
+ * call the create() method on the struct usbhost_registry_s interface
+ * to get a class instance, and finally (5) call the connect() method
+ * of the struct usbhost_class_s interface. After that, the class is in
+ * charge of the sequence of operations.
+ *
+ * Input Parameters:
+ * conn - The USB host connection instance obtained as a parameter from
+ * the call to the USB driver initialization logic.
+ * hport - The descriptor of the hub port that has the newly connected
+ * device.
+ *
+ * Returned Values:
+ * On success, zero (OK) is returned. On a failure, a negated errno value is
+ * returned indicating the nature of the failure
+ *
+ * Assumptions:
+ * This function will *not* be called from an interrupt handler.
+ *
+ ****************************************************************************/
+
+static int stm32_rh_enumerate(FAR struct stm32_usbhost_s *priv,
+ FAR struct usbhost_connection_s *conn,
+ FAR struct usbhost_hubport_s *hport)
+{
+ uint32_t regval;
+ int ret;
+
+ DEBUGASSERT(conn != NULL && hport != NULL && hport->port == 0);
+
+ /* Are we connected to a device? The caller should have called the wait()
+ * method first to be assured that a device is connected.
+ */
+
+ while (!priv->connected)
+ {
+ /* No, return an error */
+
+ usbhost_trace1(OTG_TRACE1_DEVDISCONN, 0);
+ return -ENODEV;
+ }
+
+ DEBUGASSERT(priv->smstate == SMSTATE_ATTACHED);
+
+ /* USB 2.0 spec says at least 50ms delay before port reset. We wait 100ms. */
+
+ usleep(100*1000);
+
+ /* Reset the host port */
+
+ stm32_portreset(priv);
+
+ /* Get the current device speed */
+
+ regval = stm32_getreg(STM32_OTG_HPRT);
+ if ((regval & OTG_HPRT_PSPD_MASK) == OTG_HPRT_PSPD_LS)
+ {
+ priv->rhport.hport.speed = USB_SPEED_LOW;
+ }
+ else
+ {
+ priv->rhport.hport.speed = USB_SPEED_FULL;
+ }
+
+ /* Allocate and initialize the root hub port EP0 channels */
+
+ ret = stm32_ctrlchan_alloc(priv, 0, 0, priv->rhport.hport.speed, &priv->ep0);
+ if (ret < 0)
+ {
+ uerr("ERROR: Failed to allocate a control endpoint: %d\n", ret);
+ }
+
+ return ret;
+}
+
+static int stm32_enumerate(FAR struct usbhost_connection_s *conn,
+ FAR struct usbhost_hubport_s *hport)
+{
+ FAR struct stm32_usbhost_s *priv = &g_usbhost;
+ int ret;
+
+ DEBUGASSERT(hport);
+
+ /* If this is a connection on the root hub, then we need to go to
+ * little more effort to get the device speed. If it is a connection
+ * on an external hub, then we already have that information.
+ */
+
+#ifdef CONFIG_USBHOST_HUB
+ if (ROOTHUB(hport))
+#endif
+ {
+ ret = stm32_rh_enumerate(priv, conn, hport);
+ if (ret < 0)
+ {
+ return ret;
+ }
+ }
+
+ /* Then let the common usbhost_enumerate do the real enumeration. */
+
+ uinfo("Enumerate the device\n");
+ priv->smstate = SMSTATE_ENUM;
+ ret = usbhost_enumerate(hport, &hport->devclass);
+
+ /* The enumeration may fail either because of some HCD interfaces failure
+ * or because the device class is not supported. In either case, we just
+ * need to perform the disconnection operation and make ready for a new
+ * enumeration.
+ */
+
+ if (ret < 0)
+ {
+ /* Return to the disconnected state */
+
+ uerr("ERROR: Enumeration failed: %d\n", ret);
+ stm32_gint_disconnected(priv);
+ }
+
+ return ret;
+}
+
+/************************************************************************************
+ * Name: stm32_ep0configure
+ *
+ * Description:
+ * Configure endpoint 0. This method is normally used internally by the
+ * enumerate() method but is made available at the interface to support an
+ * external implementation of the enumeration logic.
+ *
+ * Input Parameters:
+ * drvr - The USB host driver instance obtained as a parameter from the call to
+ * the class create() method.
+ * ep0 - The (opaque) EP0 endpoint instance
+ * funcaddr - The USB address of the function containing the endpoint that EP0
+ * controls
+ * speed - The speed of the port USB_SPEED_LOW, _FULL, or _HIGH
+ * maxpacketsize - The maximum number of bytes that can be sent to or
+ * received from the endpoint in a single data packet
+ *
+ * Returned Values:
+ * On success, zero (OK) is returned. On a failure, a negated errno value is
+ * returned indicating the nature of the failure
+ *
+ * Assumptions:
+ * This function will *not* be called from an interrupt handler.
+ *
+ ************************************************************************************/
+
+static int stm32_ep0configure(FAR struct usbhost_driver_s *drvr, usbhost_ep_t ep0,
+ uint8_t funcaddr, uint8_t speed,
+ uint16_t maxpacketsize)
+{
+ FAR struct stm32_usbhost_s *priv = (FAR struct stm32_usbhost_s *)drvr;
+ FAR struct stm32_ctrlinfo_s *ep0info = (FAR struct stm32_ctrlinfo_s *)ep0;
+ FAR struct stm32_chan_s *chan;
+
+ DEBUGASSERT(drvr != NULL && ep0info != NULL && funcaddr < 128 &&
+ maxpacketsize <= 64);
+
+ /* We must have exclusive access to the USB host hardware and state structures */
+
+ stm32_takesem(&priv->exclsem);
+
+ /* Configure the EP0 OUT channel */
+
+ chan = &priv->chan[ep0info->outndx];
+ chan->funcaddr = funcaddr;
+ chan->speed = speed;
+ chan->maxpacket = maxpacketsize;
+
+ stm32_chan_configure(priv, ep0info->outndx);
+
+ /* Configure the EP0 IN channel */
+
+ chan = &priv->chan[ep0info->inndx];
+ chan->funcaddr = funcaddr;
+ chan->speed = speed;
+ chan->maxpacket = maxpacketsize;
+
+ stm32_chan_configure(priv, ep0info->inndx);
+
+ stm32_givesem(&priv->exclsem);
+ return OK;
+}
+
+/************************************************************************************
+ * Name: stm32_epalloc
+ *
+ * Description:
+ * Allocate and configure one endpoint.
+ *
+ * Input Parameters:
+ * drvr - The USB host driver instance obtained as a parameter from the call to
+ * the class create() method.
+ * epdesc - Describes the endpoint to be allocated.
+ * ep - A memory location provided by the caller in which to receive the
+ * allocated endpoint descriptor.
+ *
+ * Returned Values:
+ * On success, zero (OK) is returned. On a failure, a negated errno value is
+ * returned indicating the nature of the failure
+ *
+ * Assumptions:
+ * This function will *not* be called from an interrupt handler.
+ *
+ ************************************************************************************/
+
+static int stm32_epalloc(FAR struct usbhost_driver_s *drvr,
+ FAR const struct usbhost_epdesc_s *epdesc,
+ FAR usbhost_ep_t *ep)
+{
+ FAR struct stm32_usbhost_s *priv = (FAR struct stm32_usbhost_s *)drvr;
+ int ret;
+
+ /* Sanity check. NOTE that this method should only be called if a device is
+ * connected (because we need a valid low speed indication).
+ */
+
+ DEBUGASSERT(drvr != 0 && epdesc != NULL && ep != NULL);
+
+ /* We must have exclusive access to the USB host hardware and state structures */
+
+ stm32_takesem(&priv->exclsem);
+
+ /* Handler control pipes differently from other endpoint types. This is
+ * because the normal, "transfer" endpoints are unidirectional an require
+ * only a single channel. Control endpoints, however, are bi-diretional
+ * and require two channels, one for the IN and one for the OUT direction.
+ */
+
+ if (epdesc->xfrtype == OTG_EPTYPE_CTRL)
+ {
+ ret = stm32_ctrlep_alloc(priv, epdesc, ep);
+ }
+ else
+ {
+ ret = stm32_xfrep_alloc(priv, epdesc, ep);
+ }
+
+ stm32_givesem(&priv->exclsem);
+ return ret;
+}
+
+/************************************************************************************
+ * Name: stm32_epfree
+ *
+ * Description:
+ * Free and endpoint previously allocated by DRVR_EPALLOC.
+ *
+ * Input Parameters:
+ * drvr - The USB host driver instance obtained as a parameter from the call to
+ * the class create() method.
+ * ep - The endpoint to be freed.
+ *
+ * Returned Values:
+ * On success, zero (OK) is returned. On a failure, a negated errno value is
+ * returned indicating the nature of the failure
+ *
+ * Assumptions:
+ * This function will *not* be called from an interrupt handler.
+ *
+ ************************************************************************************/
+
+static int stm32_epfree(FAR struct usbhost_driver_s *drvr, usbhost_ep_t ep)
+{
+ FAR struct stm32_usbhost_s *priv = (FAR struct stm32_usbhost_s *)drvr;
+
+ DEBUGASSERT(priv);
+
+ /* We must have exclusive access to the USB host hardware and state structures */
+
+ stm32_takesem(&priv->exclsem);
+
+ /* A single channel is represent by an index in the range of 0 to STM32_MAX_TX_FIFOS.
+ * Otherwise, the ep must be a pointer to an allocated control endpoint structure.
+ */
+
+ if ((uintptr_t)ep < STM32_MAX_TX_FIFOS)
+ {
+ /* Halt the channel and mark the channel available */
+
+ stm32_chan_free(priv, (int)ep);
+ }
+ else
+ {
+ /* Halt both control channel and mark the channels available */
+
+ FAR struct stm32_ctrlinfo_s *ctrlep = (FAR struct stm32_ctrlinfo_s *)ep;
+ stm32_chan_free(priv, ctrlep->inndx);
+ stm32_chan_free(priv, ctrlep->outndx);
+
+ /* And free the control endpoint container */
+
+ kmm_free(ctrlep);
+ }
+
+ stm32_givesem(&priv->exclsem);
+ return OK;
+}
+
+/****************************************************************************
+ * Name: stm32_alloc
+ *
+ * Description:
+ * Some hardware supports special memory in which request and descriptor data can
+ * be accessed more efficiently. This method provides a mechanism to allocate
+ * the request/descriptor memory. If the underlying hardware does not support
+ * such "special" memory, this functions may simply map to kmm_malloc.
+ *
+ * This interface was optimized under a particular assumption. It was assumed
+ * that the driver maintains a pool of small, pre-allocated buffers for descriptor
+ * traffic. NOTE that size is not an input, but an output: The size of the
+ * pre-allocated buffer is returned.
+ *
+ * Input Parameters:
+ * drvr - The USB host driver instance obtained as a parameter from the call to
+ * the class create() method.
+ * buffer - The address of a memory location provided by the caller in which to
+ * return the allocated buffer memory address.
+ * maxlen - The address of a memory location provided by the caller in which to
+ * return the maximum size of the allocated buffer memory.
+ *
+ * Returned Values:
+ * On success, zero (OK) is returned. On a failure, a negated errno value is
+ * returned indicating the nature of the failure
+ *
+ * Assumptions:
+ * - Called from a single thread so no mutual exclusion is required.
+ * - Never called from an interrupt handler.
+ *
+ ****************************************************************************/
+
+static int stm32_alloc(FAR struct usbhost_driver_s *drvr,
+ FAR uint8_t **buffer, FAR size_t *maxlen)
+{
+ FAR uint8_t *alloc;
+
+ DEBUGASSERT(drvr && buffer && maxlen);
+
+ /* There is no special memory requirement for the STM32. */
+
+ alloc = (FAR uint8_t *)kmm_malloc(CONFIG_STM32_OTG_DESCSIZE);
+ if (!alloc)
+ {
+ return -ENOMEM;
+ }
+
+ /* Return the allocated address and size of the descriptor buffer */
+
+ *buffer = alloc;
+ *maxlen = CONFIG_STM32_OTG_DESCSIZE;
+ return OK;
+}
+
+/****************************************************************************
+ * Name: stm32_free
+ *
+ * Description:
+ * Some hardware supports special memory in which request and descriptor data can
+ * be accessed more efficiently. This method provides a mechanism to free that
+ * request/descriptor memory. If the underlying hardware does not support
+ * such "special" memory, this functions may simply map to kmm_free().
+ *
+ * Input Parameters:
+ * drvr - The USB host driver instance obtained as a parameter from the call to
+ * the class create() method.
+ * buffer - The address of the allocated buffer memory to be freed.
+ *
+ * Returned Values:
+ * On success, zero (OK) is returned. On a failure, a negated errno value is
+ * returned indicating the nature of the failure
+ *
+ * Assumptions:
+ * - Never called from an interrupt handler.
+ *
+ ****************************************************************************/
+
+static int stm32_free(FAR struct usbhost_driver_s *drvr, FAR uint8_t *buffer)
+{
+ /* There is no special memory requirement */
+
+ DEBUGASSERT(drvr && buffer);
+ kmm_free(buffer);
+ return OK;
+}
+
+/************************************************************************************
+ * Name: stm32_ioalloc
+ *
+ * Description:
+ * Some hardware supports special memory in which larger IO buffers can
+ * be accessed more efficiently. This method provides a mechanism to allocate
+ * the request/descriptor memory. If the underlying hardware does not support
+ * such "special" memory, this functions may simply map to kmm_malloc.
+ *
+ * This interface differs from DRVR_ALLOC in that the buffers are variable-sized.
+ *
+ * Input Parameters:
+ * drvr - The USB host driver instance obtained as a parameter from the call to
+ * the class create() method.
+ * buffer - The address of a memory location provided by the caller in which to
+ * return the allocated buffer memory address.
+ * buflen - The size of the buffer required.
+ *
+ * Returned Values:
+ * On success, zero (OK) is returned. On a failure, a negated errno value is
+ * returned indicating the nature of the failure
+ *
+ * Assumptions:
+ * This function will *not* be called from an interrupt handler.
+ *
+ ************************************************************************************/
+
+static int stm32_ioalloc(FAR struct usbhost_driver_s *drvr,
+ FAR uint8_t **buffer, size_t buflen)
+{
+ FAR uint8_t *alloc;
+
+ DEBUGASSERT(drvr && buffer && buflen > 0);
+
+ /* There is no special memory requirement */
+
+ alloc = (FAR uint8_t *)kmm_malloc(buflen);
+ if (!alloc)
+ {
+ return -ENOMEM;
+ }
+
+ /* Return the allocated buffer */
+
+ *buffer = alloc;
+ return OK;
+}
+
+/************************************************************************************
+ * Name: stm32_iofree
+ *
+ * Description:
+ * Some hardware supports special memory in which IO data can be accessed more
+ * efficiently. This method provides a mechanism to free that IO buffer
+ * memory. If the underlying hardware does not support such "special" memory,
+ * this functions may simply map to kmm_free().
+ *
+ * Input Parameters:
+ * drvr - The USB host driver instance obtained as a parameter from the call to
+ * the class create() method.
+ * buffer - The address of the allocated buffer memory to be freed.
+ *
+ * Returned Values:
+ * On success, zero (OK) is returned. On a failure, a negated errno value is
+ * returned indicating the nature of the failure
+ *
+ * Assumptions:
+ * This function will *not* be called from an interrupt handler.
+ *
+ ************************************************************************************/
+
+static int stm32_iofree(FAR struct usbhost_driver_s *drvr, FAR uint8_t *buffer)
+{
+ /* There is no special memory requirement */
+
+ DEBUGASSERT(drvr && buffer);
+ kmm_free(buffer);
+ return OK;
+}
+
+/****************************************************************************
+ * Name: stm32_ctrlin and stm32_ctrlout
+ *
+ * Description:
+ * Process a IN or OUT request on the control endpoint. These methods
+ * will enqueue the request and wait for it to complete. Only one transfer may be
+ * queued; Neither these methods nor the transfer() method can be called again
+ * until the control transfer functions returns.
+ *
+ * These are blocking methods; these functions will not return until the
+ * control transfer has completed.
+ *
+ * Input Parameters:
+ * drvr - The USB host driver instance obtained as a parameter from the call to
+ * the class create() method.
+ * ep0 - The control endpoint to send/receive the control request.
+ * req - Describes the request to be sent. This request must lie in memory
+ * created by DRVR_ALLOC.
+ * buffer - A buffer used for sending the request and for returning any
+ * responses. This buffer must be large enough to hold the length value
+ * in the request description. buffer must have been allocated using DRVR_ALLOC.
+ *
+ * NOTE: On an IN transaction, req and buffer may refer to the same allocated
+ * memory.
+ *
+ * Returned Values:
+ * On success, zero (OK) is returned. On a failure, a negated errno value is
+ * returned indicating the nature of the failure
+ *
+ * Assumptions:
+ * - Called from a single thread so no mutual exclusion is required.
+ * - Never called from an interrupt handler.
+ *
+ ****************************************************************************/
+
+static int stm32_ctrlin(FAR struct usbhost_driver_s *drvr, usbhost_ep_t ep0,
+ FAR const struct usb_ctrlreq_s *req,
+ FAR uint8_t *buffer)
+{
+ FAR struct stm32_usbhost_s *priv = (FAR struct stm32_usbhost_s *)drvr;
+ FAR struct stm32_ctrlinfo_s *ep0info = (FAR struct stm32_ctrlinfo_s *)ep0;
+ uint16_t buflen;
+ systime_t start;
+ systime_t elapsed;
+ int retries;
+ int ret;
+
+ DEBUGASSERT(priv != NULL && ep0info != NULL && req != NULL);
+ usbhost_vtrace2(OTG_VTRACE2_CTRLIN, req->type, req->req);
+ uinfo("type:%02x req:%02x value:%02x%02x index:%02x%02x len:%02x%02x\n",
+ req->type, req->req, req->value[1], req->value[0],
+ req->index[1], req->index[0], req->len[1], req->len[0]);
+
+ /* Extract values from the request */
+
+ buflen = stm32_getle16(req->len);
+
+ /* We must have exclusive access to the USB host hardware and state structures */
+
+ stm32_takesem(&priv->exclsem);
+
+ /* Loop, retrying until the retry time expires */
+
+ for (retries = 0; retries < STM32_RETRY_COUNT; retries++)
+ {
+ /* Send the SETUP request */
+
+ ret = stm32_ctrl_sendsetup(priv, ep0info, req);
+ if (ret < 0)
+ {
+ usbhost_trace1(OTG_TRACE1_SENDSETUP, -ret);
+ continue;
+ }
+
+ /* Get the start time. Loop again until the timeout expires */
+
+ start = clock_systimer();
+ do
+ {
+ /* Handle the IN data phase (if any) */
+
+ if (buflen > 0)
+ {
+ ret = stm32_ctrl_recvdata(priv, ep0info, buffer, buflen);
+ if (ret < 0)
+ {
+ usbhost_trace1(OTG_TRACE1_RECVDATA, -ret);
+ }
+ }
+
+ /* Handle the status OUT phase */
+
+ if (ret == OK)
+ {
+ priv->chan[ep0info->outndx].outdata1 ^= true;
+ ret = stm32_ctrl_senddata(priv, ep0info, NULL, 0);
+ if (ret == OK)
+ {
+ /* All success transactions exit here */
+
+ stm32_givesem(&priv->exclsem);
+ return OK;
+ }
+
+ usbhost_trace1(OTG_TRACE1_SENDDATA, ret < 0 ? -ret : ret);
+ }
+
+ /* Get the elapsed time (in frames) */
+
+ elapsed = clock_systimer() - start;
+ }
+ while (elapsed < STM32_DATANAK_DELAY);
+ }
+
+ /* All failures exit here after all retries and timeouts have been exhausted */
+
+ stm32_givesem(&priv->exclsem);
+ return -ETIMEDOUT;
+}
+
+static int stm32_ctrlout(FAR struct usbhost_driver_s *drvr, usbhost_ep_t ep0,
+ FAR const struct usb_ctrlreq_s *req,
+ FAR const uint8_t *buffer)
+{
+ FAR struct stm32_usbhost_s *priv = (FAR struct stm32_usbhost_s *)drvr;
+ FAR struct stm32_ctrlinfo_s *ep0info = (FAR struct stm32_ctrlinfo_s *)ep0;
+ uint16_t buflen;
+ systime_t start;
+ systime_t elapsed;
+ int retries;
+ int ret;
+
+ DEBUGASSERT(priv != NULL && ep0info != NULL && req != NULL);
+ usbhost_vtrace2(OTG_VTRACE2_CTRLOUT, req->type, req->req);
+ uinfo("type:%02x req:%02x value:%02x%02x index:%02x%02x len:%02x%02x\n",
+ req->type, req->req, req->value[1], req->value[0],
+ req->index[1], req->index[0], req->len[1], req->len[0]);
+
+ /* Extract values from the request */
+
+ buflen = stm32_getle16(req->len);
+
+ /* We must have exclusive access to the USB host hardware and state structures */
+
+ stm32_takesem(&priv->exclsem);
+
+ /* Loop, retrying until the retry time expires */
+
+ for (retries = 0; retries < STM32_RETRY_COUNT; retries++)
+ {
+ /* Send the SETUP request */
+
+ ret = stm32_ctrl_sendsetup(priv, ep0info, req);
+ if (ret < 0)
+ {
+ usbhost_trace1(OTG_TRACE1_SENDSETUP, -ret);
+ continue;
+ }
+
+ /* Get the start time. Loop again until the timeout expires */
+
+ start = clock_systimer();
+ do
+ {
+ /* Handle the data OUT phase (if any) */
+
+ if (buflen > 0)
+ {
+ /* Start DATA out transfer (only one DATA packet) */
+
+ priv->chan[ep0info->outndx].outdata1 = true;
+ ret = stm32_ctrl_senddata(priv, ep0info, NULL, 0);
+ if (ret < 0)
+ {
+ usbhost_trace1(OTG_TRACE1_SENDDATA, -ret);
+ }
+ }
+
+ /* Handle the status IN phase */
+
+ if (ret == OK)
+ {
+ ret = stm32_ctrl_recvdata(priv, ep0info, NULL, 0);
+ if (ret == OK)
+ {
+ /* All success transactins exit here */
+
+ stm32_givesem(&priv->exclsem);
+ return OK;
+ }
+
+ usbhost_trace1(OTG_TRACE1_RECVDATA, ret < 0 ? -ret : ret);
+ }
+
+ /* Get the elapsed time (in frames) */
+
+ elapsed = clock_systimer() - start;
+ }
+ while (elapsed < STM32_DATANAK_DELAY);
+ }
+
+ /* All failures exit here after all retries and timeouts have been exhausted */
+
+ stm32_givesem(&priv->exclsem);
+ return -ETIMEDOUT;
+}
+
+/****************************************************************************
+ * Name: stm32_transfer
+ *
+ * Description:
+ * Process a request to handle a transfer descriptor. This method will
+ * enqueue the transfer request, blocking until the transfer completes. Only
+ * one transfer may be queued; Neither this method nor the ctrlin or
+ * ctrlout methods can be called again until this function returns.
+ *
+ * This is a blocking method; this functions will not return until the
+ * transfer has completed.
+ *
+ * Input Parameters:
+ * drvr - The USB host driver instance obtained as a parameter from the call to
+ * the class create() method.
+ * ep - The IN or OUT endpoint descriptor for the device endpoint on which to
+ * perform the transfer.
+ * buffer - A buffer containing the data to be sent (OUT endpoint) or received
+ * (IN endpoint). buffer must have been allocated using DRVR_ALLOC
+ * buflen - The length of the data to be sent or received.
+ *
+ * Returned Values:
+ * On success, a non-negative value is returned that indicates the number
+ * of bytes successfully transferred. On a failure, a negated errno value is
+ * returned that indicates the nature of the failure:
+ *
+ * EAGAIN - If devices NAKs the transfer (or NYET or other error where
+ * it may be appropriate to restart the entire transaction).
+ * EPERM - If the endpoint stalls
+ * EIO - On a TX or data toggle error
+ * EPIPE - Overrun errors
+ *
+ * Assumptions:
+ * - Called from a single thread so no mutual exclusion is required.
+ * - Never called from an interrupt handler.
+ *
+ ****************************************************************************/
+
+static ssize_t stm32_transfer(FAR struct usbhost_driver_s *drvr, usbhost_ep_t ep,
+ FAR uint8_t *buffer, size_t buflen)
+{
+ FAR struct stm32_usbhost_s *priv = (FAR struct stm32_usbhost_s *)drvr;
+ unsigned int chidx = (unsigned int)ep;
+ ssize_t nbytes;
+
+ uinfo("chidx: %d buflen: %d\n", (unsigned int)ep, buflen);
+
+ DEBUGASSERT(priv && buffer && chidx < STM32_MAX_TX_FIFOS && buflen > 0);
+
+ /* We must have exclusive access to the USB host hardware and state structures */
+
+ stm32_takesem(&priv->exclsem);
+
+ /* Handle IN and OUT transfer slightly differently */
+
+ if (priv->chan[chidx].in)
+ {
+ nbytes = stm32_in_transfer(priv, chidx, buffer, buflen);
+ }
+ else
+ {
+ nbytes = stm32_out_transfer(priv, chidx, buffer, buflen);
+ }
+
+ stm32_givesem(&priv->exclsem);
+ return nbytes;
+}
+
+/****************************************************************************
+ * Name: stm32_asynch
+ *
+ * Description:
+ * Process a request to handle a transfer descriptor. This method will
+ * enqueue the transfer request and return immediately. When the transfer
+ * completes, the the callback will be invoked with the provided transfer.
+ * This method is useful for receiving interrupt transfers which may come
+ * infrequently.
+ *
+ * Only one transfer may be queued; Neither this method nor the ctrlin or
+ * ctrlout methods can be called again until the transfer completes.
+ *
+ * Input Parameters:
+ * drvr - The USB host driver instance obtained as a parameter from the call to
+ * the class create() method.
+ * ep - The IN or OUT endpoint descriptor for the device endpoint on which to
+ * perform the transfer.
+ * buffer - A buffer containing the data to be sent (OUT endpoint) or received
+ * (IN endpoint). buffer must have been allocated using DRVR_ALLOC
+ * buflen - The length of the data to be sent or received.
+ * callback - This function will be called when the transfer completes.
+ * arg - The arbitrary parameter that will be passed to the callback function
+ * when the transfer completes.
+ *
+ * Returned Values:
+ * On success, zero (OK) is returned. On a failure, a negated errno value is
+ * returned indicating the nature of the failure
+ *
+ * Assumptions:
+ * - Called from a single thread so no mutual exclusion is required.
+ * - Never called from an interrupt handler.
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_USBHOST_ASYNCH
+static int stm32_asynch(FAR struct usbhost_driver_s *drvr, usbhost_ep_t ep,
+ FAR uint8_t *buffer, size_t buflen,
+ usbhost_asynch_t callback, FAR void *arg)
+{
+ FAR struct stm32_usbhost_s *priv = (FAR struct stm32_usbhost_s *)drvr;
+ unsigned int chidx = (unsigned int)ep;
+ int ret;
+
+ uinfo("chidx: %d buflen: %d\n", (unsigned int)ep, buflen);
+
+ DEBUGASSERT(priv && buffer && chidx < STM32_MAX_TX_FIFOS && buflen > 0);
+
+ /* We must have exclusive access to the USB host hardware and state structures */
+
+ stm32_takesem(&priv->exclsem);
+
+ /* Handle IN and OUT transfer slightly differently */
+
+ if (priv->chan[chidx].in)
+ {
+ ret = stm32_in_asynch(priv, chidx, buffer, buflen, callback, arg);
+ }
+ else
+ {
+ ret = stm32_out_asynch(priv, chidx, buffer, buflen, callback, arg);
+ }
+
+ stm32_givesem(&priv->exclsem);
+ return ret;
+}
+#endif /* CONFIG_USBHOST_ASYNCH */
+
+/************************************************************************************
+ * Name: stm32_cancel
+ *
+ * Description:
+ * Cancel a pending transfer on an endpoint. Cancelled synchronous or
+ * asynchronous transfer will complete normally with the error -ESHUTDOWN.
+ *
+ * Input Parameters:
+ * drvr - The USB host driver instance obtained as a parameter from the call to
+ * the class create() method.
+ * ep - The IN or OUT endpoint descriptor for the device endpoint on which an
+ * asynchronous transfer should be transferred.
+ *
+ * Returned Values:
+ * On success, zero (OK) is returned. On a failure, a negated errno value is
+ * returned indicating the nature of the failure.
+ *
+ ************************************************************************************/
+
+static int stm32_cancel(FAR struct usbhost_driver_s *drvr, usbhost_ep_t ep)
+{
+ FAR struct stm32_usbhost_s *priv = (FAR struct stm32_usbhost_s *)drvr;
+ FAR struct stm32_chan_s *chan;
+ unsigned int chidx = (unsigned int)ep;
+ irqstate_t flags;
+
+ uinfo("chidx: %u: %d\n", chidx);
+
+ DEBUGASSERT(priv && chidx < STM32_MAX_TX_FIFOS);
+ chan = &priv->chan[chidx];
+
+ /* We need to disable interrupts to avoid race conditions with the asynchronous
+ * completion of the transfer being cancelled.
+ */
+
+ flags = enter_critical_section();
+
+ /* Halt the channel */
+
+ stm32_chan_halt(priv, chidx, CHREASON_CANCELLED);
+ chan->result = -ESHUTDOWN;
+
+ /* Is there a thread waiting for this transfer to complete? */
+
+ if (chan->waiter)
+ {
+#ifdef CONFIG_USBHOST_ASYNCH
+ /* Yes.. there should not also be a callback scheduled */
+
+ DEBUGASSERT(chan->callback == NULL);
+#endif
+
+ /* Wake'em up! */
+
+ stm32_givesem(&chan->waitsem);
+ chan->waiter = false;
+ }
+
+#ifdef CONFIG_USBHOST_ASYNCH
+ /* No.. is an asynchronous callback expected when the transfer
+ * completes?
+ */
+
+ else if (chan->callback)
+ {
+ usbhost_asynch_t callback;
+ FAR void *arg;
+
+ /* Extract the callback information */
+
+ callback = chan->callback;
+ arg = chan->arg;
+
+ chan->callback = NULL;
+ chan->arg = NULL;
+ chan->xfrd = 0;
+
+ /* Then perform the callback */
+
+ callback(arg, -ESHUTDOWN);
+ }
+#endif
+
+ leave_critical_section(flags);
+ return OK;
+}
+
+/************************************************************************************
+ * Name: stm32_connect
+ *
+ * Description:
+ * New connections may be detected by an attached hub. This method is the
+ * mechanism that is used by the hub class to introduce a new connection
+ * and port description to the system.
+ *
+ * Input Parameters:
+ * drvr - The USB host driver instance obtained as a parameter from the call to
+ * the class create() method.
+ * hport - The descriptor of the hub port that detected the connection
+ * related event
+ * connected - True: device connected; false: device disconnected
+ *
+ * Returned Values:
+ * On success, zero (OK) is returned. On a failure, a negated errno value is
+ * returned indicating the nature of the failure.
+ *
+ ************************************************************************************/
+
+#ifdef CONFIG_USBHOST_HUB
+static int stm32_connect(FAR struct usbhost_driver_s *drvr,
+ FAR struct usbhost_hubport_s *hport,
+ bool connected)
+{
+ FAR struct stm32_usbhost_s *priv = (FAR struct stm32_usbhost_s *)drvr;
+ irqstate_t flags;
+
+ DEBUGASSERT(priv != NULL && hport != NULL);
+
+ /* Set the connected/disconnected flag */
+
+ hport->connected = connected;
+ ullinfo("Hub port %d connected: %s\n", hport->port, connected ? "YES" : "NO");
+
+ /* Report the connection event */
+
+ flags = enter_critical_section();
+ priv->hport = hport;
+ if (priv->pscwait)
+ {
+ priv->pscwait = false;
+ stm32_givesem(&priv->pscsem);
+ }
+
+ leave_critical_section(flags);
+ return OK;
+}
+#endif
+
+/****************************************************************************
+ * Name: stm32_disconnect
+ *
+ * Description:
+ * Called by the class when an error occurs and driver has been disconnected.
+ * The USB host driver should discard the handle to the class instance (it is
+ * stale) and not attempt any further interaction with the class driver instance
+ * (until a new instance is received from the create() method). The driver
+ * should not called the class' disconnected() method.
+ *
+ * Input Parameters:
+ * drvr - The USB host driver instance obtained as a parameter from the call to
+ * the class create() method.
+ * hport - The port from which the device is being disconnected. Might be a port
+ * on a hub.
+ *
+ * Returned Values:
+ * None
+ *
+ * Assumptions:
+ * - Only a single class bound to a single device is supported.
+ * - Never called from an interrupt handler.
+ *
+ ****************************************************************************/
+
+static void stm32_disconnect(FAR struct usbhost_driver_s *drvr,
+ FAR struct usbhost_hubport_s *hport)
+{
+ DEBUGASSERT(hport != NULL);
+ hport->devclass = NULL;
+}
+
+/****************************************************************************
+ * Initialization
+ ****************************************************************************/
+/****************************************************************************
+ * Name: stm32_portreset
+ *
+ * Description:
+ * Reset the USB host port.
+ *
+ * NOTE: "Before starting to drive a USB reset, the application waits for the
+ * OTG interrupt triggered by the debounce done bit (DBCDNE bit in
+ * OTG_FS_GOTGINT), which indicates that the bus is stable again after the
+ * electrical debounce caused by the attachment of a pull-up resistor on DP
+ * (FS) or DM (LS).
+ *
+ * Input Parameters:
+ * priv -- USB host driver private data structure.
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+static void stm32_portreset(FAR struct stm32_usbhost_s *priv)
+{
+ uint32_t regval;
+
+ regval = stm32_getreg(STM32_OTG_HPRT);
+ regval &= ~(OTG_HPRT_PENA | OTG_HPRT_PCDET | OTG_HPRT_PENCHNG |
+ OTG_HPRT_POCCHNG);
+ regval |= OTG_HPRT_PRST;
+ stm32_putreg(STM32_OTG_HPRT, regval);
+
+ up_mdelay(20);
+
+ regval &= ~OTG_HPRT_PRST;
+ stm32_putreg(STM32_OTG_HPRT, regval);
+
+ up_mdelay(20);
+}
+
+/****************************************************************************
+ * Name: stm32_flush_txfifos
+ *
+ * Description:
+ * Flush the selected Tx FIFO.
+ *
+ * Input Parameters:
+ * txfnum -- USB host driver private data structure.
+ *
+ * Returned Value:
+ * None.
+ *
+ ****************************************************************************/
+
+static void stm32_flush_txfifos(uint32_t txfnum)
+{
+ uint32_t regval;
+ uint32_t timeout;
+
+ /* Initiate the TX FIFO flush operation */
+
+ regval = OTG_GRSTCTL_TXFFLSH | txfnum;
+ stm32_putreg(STM32_OTG_GRSTCTL, regval);
+
+ /* Wait for the FLUSH to complete */
+
+ for (timeout = 0; timeout < STM32_FLUSH_DELAY; timeout++)
+ {
+ regval = stm32_getreg(STM32_OTG_GRSTCTL);
+ if ((regval & OTG_GRSTCTL_TXFFLSH) == 0)
+ {
+ break;
+ }
+ }
+
+ /* Wait for 3 PHY Clocks */
+
+ up_udelay(3);
+}
+
+/****************************************************************************
+ * Name: stm32_flush_rxfifo
+ *
+ * Description:
+ * Flush the Rx FIFO.
+ *
+ * Input Parameters:
+ * priv -- USB host driver private data structure.
+ *
+ * Returned Value:
+ * None.
+ *
+ ****************************************************************************/
+
+static void stm32_flush_rxfifo(void)
+{
+ uint32_t regval;
+ uint32_t timeout;
+
+ /* Initiate the RX FIFO flush operation */
+
+ stm32_putreg(STM32_OTG_GRSTCTL, OTG_GRSTCTL_RXFFLSH);
+
+ /* Wait for the FLUSH to complete */
+
+ for (timeout = 0; timeout < STM32_FLUSH_DELAY; timeout++)
+ {
+ regval = stm32_getreg(STM32_OTG_GRSTCTL);
+ if ((regval & OTG_GRSTCTL_RXFFLSH) == 0)
+ {
+ break;
+ }
+ }
+
+ /* Wait for 3 PHY Clocks */
+
+ up_udelay(3);
+}
+
+/****************************************************************************
+ * Name: stm32_vbusdrive
+ *
+ * Description:
+ * Drive the Vbus +5V.
+ *
+ * Input Parameters:
+ * priv - USB host driver private data structure.
+ * state - True: Drive, False: Don't drive
+ *
+ * Returned Value:
+ * None.
+ *
+ ****************************************************************************/
+
+static void stm32_vbusdrive(FAR struct stm32_usbhost_s *priv, bool state)
+{
+ uint32_t regval;
+
+ /* Enable/disable the external charge pump */
+
+ stm32_usbhost_vbusdrive(0, state);
+
+ /* Turn on the Host port power. */
+
+ regval = stm32_getreg(STM32_OTG_HPRT);
+ regval &= ~(OTG_HPRT_PENA | OTG_HPRT_PCDET | OTG_HPRT_PENCHNG |
+ OTG_HPRT_POCCHNG);
+
+ if (((regval & OTG_HPRT_PPWR) == 0) && state)
+ {
+ regval |= OTG_HPRT_PPWR;
+ stm32_putreg(STM32_OTG_HPRT, regval);
+ }
+
+ if (((regval & OTG_HPRT_PPWR) != 0) && !state)
+ {
+ regval &= ~OTG_HPRT_PPWR;
+ stm32_putreg(STM32_OTG_HPRT, regval);
+ }
+
+ up_mdelay(200);
+}
+
+/****************************************************************************
+ * Name: stm32_host_initialize
+ *
+ * Description:
+ * Initialize/re-initialize hardware for host mode operation. At present,
+ * this function is called only from stm32_hw_initialize(). But if OTG mode
+ * were supported, this function would also be called to swtich between
+ * host and device modes on a connector ID change interrupt.
+ *
+ * Input Parameters:
+ * priv -- USB host driver private data structure.
+ *
+ * Returned Value:
+ * None.
+ *
+ ****************************************************************************/
+
+static void stm32_host_initialize(FAR struct stm32_usbhost_s *priv)
+{
+ uint32_t regval;
+ uint32_t offset;
+ int i;
+
+ /* Restart the PHY Clock */
+
+ stm32_putreg(STM32_OTG_PCGCCTL, 0);
+
+ /* Initialize Host Configuration (HCFG) register */
+
+ regval = stm32_getreg(STM32_OTG_HCFG);
+ regval &= ~OTG_HCFG_FSLSPCS_MASK;
+ regval |= OTG_HCFG_FSLSPCS_FS48MHz;
+ stm32_putreg(STM32_OTG_HCFG, regval);
+
+ /* Reset the host port */
+
+ stm32_portreset(priv);
+
+ /* Clear the FS-/LS-only support bit in the HCFG register */
+
+ regval = stm32_getreg(STM32_OTG_HCFG);
+ regval &= ~OTG_HCFG_FSLSS;
+ stm32_putreg(STM32_OTG_HCFG, regval);
+
+ /* Carve up FIFO memory for the Rx FIFO and the periodic and non-periodic Tx FIFOs */
+ /* Configure Rx FIFO size (GRXFSIZ) */
+
+ stm32_putreg(STM32_OTG_GRXFSIZ, CONFIG_STM32_OTG_RXFIFO_SIZE);
+ offset = CONFIG_STM32_OTG_RXFIFO_SIZE;
+
+ /* Setup the host non-periodic Tx FIFO size (HNPTXFSIZ) */
+
+ regval = (offset | (CONFIG_STM32_OTG_NPTXFIFO_SIZE << OTG_HNPTXFSIZ_NPTXFD_SHIFT));
+ stm32_putreg(STM32_OTG_HNPTXFSIZ, regval);
+ offset += CONFIG_STM32_OTG_NPTXFIFO_SIZE;
+
+ /* Set up the host periodic Tx fifo size register (HPTXFSIZ) */
+
+ regval = (offset | (CONFIG_STM32_OTG_PTXFIFO_SIZE << OTG_HPTXFSIZ_PTXFD_SHIFT));
+ stm32_putreg(STM32_OTG_HPTXFSIZ, regval);
+
+ /* If OTG were supported, we sould need to clear HNP enable bit in the
+ * USB_OTG control register about here.
+ */
+
+ /* Flush all FIFOs */
+
+ stm32_flush_txfifos(OTG_GRSTCTL_TXFNUM_HALL);
+ stm32_flush_rxfifo();
+
+ /* Clear all pending HC Interrupts */
+
+ for (i = 0; i < STM32_NHOST_CHANNELS; i++)
+ {
+ stm32_putreg(STM32_OTG_HCINT(i), 0xffffffff);
+ stm32_putreg(STM32_OTG_HCINTMSK(i), 0);
+ }
+
+ /* Driver Vbus +5V (the smoke test). Should be done elsewhere in OTG
+ * mode.
+ */
+
+ stm32_vbusdrive(priv, true);
+
+ /* Enable host interrupts */
+
+ stm32_hostinit_enable();
+}
+
+/****************************************************************************
+ * Name: stm32_sw_initialize
+ *
+ * Description:
+ * One-time setup of the host driver state structure.
+ *
+ * Input Parameters:
+ * priv -- USB host driver private data structure.
+ *
+ * Returned Value:
+ * None.
+ *
+ ****************************************************************************/
+
+static inline void stm32_sw_initialize(FAR struct stm32_usbhost_s *priv)
+{
+ FAR struct usbhost_driver_s *drvr;
+ FAR struct usbhost_hubport_s *hport;
+ int i;
+
+ /* Initialize the device operations */
+
+ drvr = &priv->drvr;
+ drvr->ep0configure = stm32_ep0configure;
+ drvr->epalloc = stm32_epalloc;
+ drvr->epfree = stm32_epfree;
+ drvr->alloc = stm32_alloc;
+ drvr->free = stm32_free;
+ drvr->ioalloc = stm32_ioalloc;
+ drvr->iofree = stm32_iofree;
+ drvr->ctrlin = stm32_ctrlin;
+ drvr->ctrlout = stm32_ctrlout;
+ drvr->transfer = stm32_transfer;
+#ifdef CONFIG_USBHOST_ASYNCH
+ drvr->asynch = stm32_asynch;
+#endif
+ drvr->cancel = stm32_cancel;
+#ifdef CONFIG_USBHOST_HUB
+ drvr->connect = stm32_connect;
+#endif
+ drvr->disconnect = stm32_disconnect;
+
+ /* Initialize the public port representation */
+
+ hport = &priv->rhport.hport;
+ hport->drvr = drvr;
+#ifdef CONFIG_USBHOST_HUB
+ hport->parent = NULL;
+#endif
+ hport->ep0 = (usbhost_ep_t)&priv->ep0;
+ hport->speed = USB_SPEED_FULL;
+
+ /* Initialize function address generation logic */
+
+ usbhost_devaddr_initialize(&priv->rhport);
+
+ /* Initialize semaphores */
+
+ sem_init(&priv->pscsem, 0, 0);
+ sem_init(&priv->exclsem, 0, 1);
+
+ /* Initialize the driver state data */
+
+ priv->smstate = SMSTATE_DETACHED;
+ priv->connected = false;
+ priv->change = false;
+
+ /* Put all of the channels back in their initial, allocated state */
+
+ memset(priv->chan, 0, STM32_MAX_TX_FIFOS * sizeof(struct stm32_chan_s));
+
+ /* Initialize each channel */
+
+ for (i = 0; i < STM32_MAX_TX_FIFOS; i++)
+ {
+ FAR struct stm32_chan_s *chan = &priv->chan[i];
+ chan->chidx = i;
+ sem_init(&chan->waitsem, 0, 0);
+ }
+}
+
+/****************************************************************************
+ * Name: stm32_hw_initialize
+ *
+ * Description:
+ * One-time setup of the host controller harware for normal operations.
+ *
+ * Input Parameters:
+ * priv -- USB host driver private data structure.
+ *
+ * Returned Value:
+ * Zero on success; a negated errno value on failure.
+ *
+ ****************************************************************************/
+
+static inline int stm32_hw_initialize(FAR struct stm32_usbhost_s *priv)
+{
+ uint32_t regval;
+ unsigned long timeout;
+
+ /* Set the PHYSEL bit in the GUSBCFG register to select the OTG FS serial
+ * transceiver: "This bit is always 1 with write-only access"
+ */
+
+ regval = stm32_getreg(STM32_OTG_GUSBCFG);
+ regval |= OTG_GUSBCFG_PHYSEL;
+ stm32_putreg(STM32_OTG_GUSBCFG, regval);
+
+ /* Reset after a PHY select and set Host mode. First, wait for AHB master
+ * IDLE state.
+ */
+
+ for (timeout = 0; timeout < STM32_READY_DELAY; timeout++)
+ {
+ up_udelay(3);
+ regval = stm32_getreg(STM32_OTG_GRSTCTL);
+ if ((regval & OTG_GRSTCTL_AHBIDL) != 0)
+ {
+ break;
+ }
+ }
+
+ /* Then perform the core soft reset. */
+
+ stm32_putreg(STM32_OTG_GRSTCTL, OTG_GRSTCTL_CSRST);
+ for (timeout = 0; timeout < STM32_READY_DELAY; timeout++)
+ {
+ regval = stm32_getreg(STM32_OTG_GRSTCTL);
+ if ((regval & OTG_GRSTCTL_CSRST) == 0)
+ {
+ break;
+ }
+ }
+
+ /* Wait for 3 PHY Clocks */
+
+ up_udelay(3);
+
+ /* Deactivate the power down */
+
+ regval = (OTG_GCCFG_PWRDWN | OTG_GCCFG_VBUSASEN | OTG_GCCFG_VBUSBSEN);
+#ifndef CONFIG_USBDEV_VBUSSENSING
+ regval |= OTG_GCCFG_NOVBUSSENS;
+#endif
+#ifdef CONFIG_STM32_OTG_SOFOUTPUT
+ regval |= OTG_GCCFG_SOFOUTEN;
+#endif
+ stm32_putreg(STM32_OTG_GCCFG, regval);
+ up_mdelay(20);
+
+ /* Initialize OTG features: In order to support OTP, the HNPCAP and SRPCAP
+ * bits would need to be set in the GUSBCFG register about here.
+ */
+
+ /* Force Host Mode */
+
+ regval = stm32_getreg(STM32_OTG_GUSBCFG);
+ regval &= ~OTG_GUSBCFG_FDMOD;
+ regval |= OTG_GUSBCFG_FHMOD;
+ stm32_putreg(STM32_OTG_GUSBCFG, regval);
+ up_mdelay(50);
+
+ /* Initialize host mode and return success */
+
+ stm32_host_initialize(priv);
+ return OK;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: stm32_otgfshost_initialize
+ *
+ * Description:
+ * Initialize USB host device controller hardware.
+ *
+ * Input Parameters:
+ * controller -- If the device supports more than USB host controller, then
+ * this identifies which controller is being initialized. Normally, this
+ * is just zero.
+ *
+ * Returned Value:
+ * And instance of the USB host interface. The controlling task should
+ * use this interface to (1) call the wait() method to wait for a device
+ * to be connected, and (2) call the enumerate() method to bind the device
+ * to a class driver.
+ *
+ * Assumptions:
+ * - This function should called in the initialization sequence in order
+ * to initialize the USB device functionality.
+ * - Class drivers should be initialized prior to calling this function.
+ * Otherwise, there is a race condition if the device is already connected.
+ *
+ ****************************************************************************/
+
+FAR struct usbhost_connection_s *stm32_otgfshost_initialize(int controller)
+{
+ /* At present, there is only support for a single OTG FS host. Hence it is
+ * pre-allocated as g_usbhost. However, in most code, the private data
+ * structure will be referenced using the 'priv' pointer (rather than the
+ * global data) in order to simplify any future support for multiple devices.
+ */
+
+ FAR struct stm32_usbhost_s *priv = &g_usbhost;
+
+ /* Sanity checks */
+
+ DEBUGASSERT(controller == 0);
+
+ /* Make sure that interrupts from the OTG FS core are disabled */
+
+ stm32_gint_disable();
+
+ /* Reset the state of the host driver */
+
+ stm32_sw_initialize(priv);
+
+ /* Alternate function pin configuration. Here we assume that:
+ *
+ * 1. GPIOA, SYSCFG, and OTG FS peripheral clocking have already been\
+ * enabled as part of the boot sequence.
+ * 2. Board-specific logic has already enabled other board specific GPIOs
+ * for things like soft pull-up, VBUS sensing, power controls, and over-
+ * current detection.
+ */
+
+ /* Configure OTG FS alternate function pins for DM, DP, ID, and SOF.
+ *
+ * PIN* SIGNAL DIRECTION
+ * ---- ----------- ----------
+ * PA8 OTG_FS_SOF SOF clock output
+ * PA9 OTG_FS_VBUS VBUS input for device, Driven by external regulator by
+ * host (not an alternate function)
+ * PA10 OTG_FS_ID OTG ID pin (only needed in Dual mode)
+ * PA11 OTG_FS_DM D- I/O
+ * PA12 OTG_FS_DP D+ I/O
+ *
+ * *Pins may vary from device-to-device.
+ */
+
+ stm32_configgpio(GPIO_OTG_DM);
+ stm32_configgpio(GPIO_OTG_DP);
+ stm32_configgpio(GPIO_OTG_ID); /* Only needed for OTG */
+
+ /* SOF output pin configuration is configurable */
+
+#ifdef CONFIG_STM32_OTG_SOFOUTPUT
+ stm32_configgpio(GPIO_OTG_SOF);
+#endif
+
+ /* Initialize the USB OTG FS core */
+
+ stm32_hw_initialize(priv);
+
+ /* Attach USB host controller interrupt handler */
+
+ if (irq_attach(STM32_IRQ_OTGFS, stm32_gint_isr) != 0)
+ {
+ usbhost_trace1(OTG_TRACE1_IRQATTACH, 0);
+ return NULL;
+ }
+
+ /* Enable USB OTG FS global interrupts */
+
+ stm32_gint_enable();
+
+ /* Enable interrupts at the interrupt controller */
+
+ up_enable_irq(STM32_IRQ_OTGFS);
+ return &g_usbconn;
+}
+
+#endif /* CONFIG_USBHOST && CONFIG_STM32_OTGFS */
diff --git a/arch/arm/src/stm32f7/stm32_sdmmc.h b/arch/arm/src/stm32f7/stm32_sdmmc.h
index 29e14683ce..18e6c44601 100644
--- a/arch/arm/src/stm32f7/stm32_sdmmc.h
+++ b/arch/arm/src/stm32f7/stm32_sdmmc.h
@@ -1,5 +1,5 @@
/************************************************************************************
- * arch/arm/src/stm32/stm32_sdio.h
+ * arch/arm/src/stm32f7/stm32_sdio.h
*
* Copyright (C) 2009, 2011, 2015 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt
--
GitLab
From 6f2e37e3adb3da2bcb3a7fe0bacfc23b7dd9707d Mon Sep 17 00:00:00 2001
From: Lok Tep
Date: Sun, 19 Jun 2016 23:06:21 +0200
Subject: [PATCH 003/734] mmc + usb
---
arch/arm/src/stm32f7/stm32_otg.h | 32 +-
arch/arm/src/stm32f7/stm32_otgdev.c | 17 +-
arch/arm/src/stm32f7/stm32_otghost.c | 84 ++---
arch/arm/src/stm32f7/stm32_sdmmc.c | 5 +
configs/stm32f746-ws/nsh/defconfig | 86 ++++-
configs/stm32f746-ws/src/Makefile | 10 +-
.../stm32f746-ws/src/stm32_appinitialize.c | 18 +
configs/stm32f746-ws/src/stm32_dma_alloc.c | 117 ++++++
configs/stm32f746-ws/src/stm32_sdmmc.c | 171 +++++++++
configs/stm32f746-ws/src/stm32_usb.c | 340 ++++++++++++++++++
configs/stm32f746-ws/src/stm32f746-ws.h | 33 ++
11 files changed, 842 insertions(+), 71 deletions(-)
create mode 100644 configs/stm32f746-ws/src/stm32_dma_alloc.c
create mode 100644 configs/stm32f746-ws/src/stm32_sdmmc.c
create mode 100644 configs/stm32f746-ws/src/stm32_usb.c
diff --git a/arch/arm/src/stm32f7/stm32_otg.h b/arch/arm/src/stm32f7/stm32_otg.h
index 69def14608..0bb6b9b393 100644
--- a/arch/arm/src/stm32f7/stm32_otg.h
+++ b/arch/arm/src/stm32f7/stm32_otg.h
@@ -44,10 +44,10 @@
#include
-
+#include "chip.h"
#include "chip/stm32_otg.h"
-#if defined(CONFIG_STM32_OTGFS) || defined(CONFIG_STM32_OTGHS)
+#if defined(CONFIG_STM32F7_OTGFS) || defined(CONFIG_STM32F7_OTGHS)
/************************************************************************************
* Pre-processor Definitions
@@ -58,16 +58,26 @@
# define CONFIG_OTG_PRI NVIC_SYSH_PRIORITY_DEFAULT
#endif
-#if defined(CONFIG_STM32_OTGFS)
-# define STM32_IRQ_OTG STM32_IRQ_OTGFS
-# define STM32_OTG_BASE STM32_USBOTGFS_BASE
-# define STM32_NENDPOINTS (6) /* ep0-5 x 2 for IN and OUT */
+#if defined(CONFIG_STM32F7_OTGFS)
+# define STM32_IRQ_OTG STM32_IRQ_OTGFS
+# define STM32_OTG_BASE STM32_USBOTGFS_BASE
+# define STM32_NENDPOINTS (6) /* ep0-5 x 2 for IN and OUT */
+# define GPIO_OTG_DM GPIO_OTGFS_DM
+# define GPIO_OTG_DP GPIO_OTGFS_DP
+# define GPIO_OTG_ID GPIO_OTGFS_ID
+# define GPIO_OTG_SOF GPIO_OTGFS_SOF
+
#endif
-#if defined(CONFIG_STM32_OTGHS)
-# define STM32_IRQ_OTG STM32_IRQ_OTGHS
-# define STM32_OTG_BASE STM32_USBOTGHS_BASE
-# define STM32_NENDPOINTS (8) /* ep0-7 x 2 for IN and OUT */
+#if defined(CONFIG_STM32F7_OTGHS)
+# define STM32_IRQ_OTG STM32_IRQ_OTGHS
+# define STM32_OTG_BASE STM32_USBOTGHS_BASE
+# define STM32_NENDPOINTS (8) /* ep0-7 x 2 for IN and OUT */
+# define GPIO_OTG_DM GPIO_OTGHS_DM
+# define GPIO_OTG_DP GPIO_OTGHS_DP
+# define GPIO_OTG_ID GPIO_OTGHS_ID
+# define GPIO_OTG_SOF GPIO_OTGHS_SOF
+
#endif
/************************************************************************************
@@ -134,6 +144,6 @@ void stm32_usbsuspend(FAR struct usbdev_s *dev, bool resume);
#endif
#endif /* __ASSEMBLY__ */
-#endif /* CONFIG_STM32_OTGFS */
+#endif /* CONFIG_STM32F7_OTGFS */
#endif /* __ARCH_ARM_SRC_STM32F7_STM32_OTG_H */
diff --git a/arch/arm/src/stm32f7/stm32_otgdev.c b/arch/arm/src/stm32f7/stm32_otgdev.c
index e362ef2b45..d4d46c4efb 100644
--- a/arch/arm/src/stm32f7/stm32_otgdev.c
+++ b/arch/arm/src/stm32f7/stm32_otgdev.c
@@ -57,12 +57,13 @@
#include
#include "chip.h"
+#include "stm32_gpio.h"
#include "stm32_otg.h"
#include "up_arch.h"
#include "up_internal.h"
-#if defined(CONFIG_USBDEV) && (defined(CONFIG_STM32_OTGFS) || defined(CONFIG_STM32_OTGHS))
+#if defined(CONFIG_USBDEV) && (defined(CONFIG_STM32F7_OTGFS) || defined(CONFIG_STM32F7_OTGHS))
/****************************************************************************
* Pre-processor Definitions
@@ -469,7 +470,7 @@ struct stm32_usbdev_s
/* Register operations ********************************************************/
-#if defined(CONFIG_STM32_USBDEV_REGDEBUG) && defined(CONFIG_DEBUG_FEATURES)
+#if defined(CONFIG_STM32F7_USBDEV_REGDEBUG) && defined(CONFIG_DEBUG_FEATURES)
static uint32_t stm32_getreg(uint32_t addr);
static void stm32_putreg(uint32_t val, uint32_t addr);
#else
@@ -789,7 +790,7 @@ const struct trace_msg_t g_usb_trace_strings_intdecode[] =
*
****************************************************************************/
-#if defined(CONFIG_STM32_USBDEV_REGDEBUG) && defined(CONFIG_DEBUG_FEATURES)
+#if defined(CONFIG_STM32F7_USBDEV_REGDEBUG) && defined(CONFIG_DEBUG_FEATURES)
static uint32_t stm32_getreg(uint32_t addr)
{
static uint32_t prevaddr = 0;
@@ -852,7 +853,7 @@ static uint32_t stm32_getreg(uint32_t addr)
*
****************************************************************************/
-#if defined(CONFIG_STM32_USBDEV_REGDEBUG) && defined(CONFIG_DEBUG_FEATURES)
+#if defined(CONFIG_STM32F7_USBDEV_REGDEBUG) && defined(CONFIG_DEBUG_FEATURES)
static void stm32_putreg(uint32_t val, uint32_t addr)
{
/* Show the register value being written */
@@ -5134,7 +5135,7 @@ static void stm32_hwinitialize(FAR struct stm32_usbdev_s *priv)
stm32_putreg(OTG_GAHBCFG_TXFELVL, STM32_OTG_GAHBCFG);
-#if defined(CONFIG_STM32_OTGHS)
+#if defined(CONFIG_STM32F7_OTGHS)
/* Set the PHYSEL bit in the GUSBCFG register to select the OTG HS serial
* transceiver: "This bit is always 1 with write-only access"
*/
@@ -5329,7 +5330,7 @@ static void stm32_hwinitialize(FAR struct stm32_usbdev_s *priv)
stm32_putreg(0xbfffffff, STM32_OTG_GINTSTS);
-#ifdef defined(CONFIG_STM32_OTGHS)
+#if defined(CONFIG_STM32F7_OTGHS)
/* Disable the ULPI Clock enable in RCC AHB1 Register. This must
* be done because if both the ULPI and the FS PHY clock enable bits
* are set at the same time, the ARM never awakens from WFI due to
@@ -5424,7 +5425,7 @@ void up_usbinitialize(void)
/* SOF output pin configuration is configurable. */
-#ifdef CONFIG_STM32_OTG_SOFOUTPUT
+#ifdef CONFIG_STM32F7_OTG_SOFOUTPUT
stm32_configgpio(GPIO_OTG_SOF);
#endif
@@ -5663,4 +5664,4 @@ int usbdev_unregister(struct usbdevclass_driver_s *driver)
return OK;
}
-#endif /* CONFIG_USBDEV && CONFIG_STM32_OTGDEV */
+#endif /* CONFIG_USBDEV && CONFIG_STM32F7_OTGDEV */
diff --git a/arch/arm/src/stm32f7/stm32_otghost.c b/arch/arm/src/stm32f7/stm32_otghost.c
index cc00b1336f..0feb6c98da 100644
--- a/arch/arm/src/stm32f7/stm32_otghost.c
+++ b/arch/arm/src/stm32f7/stm32_otghost.c
@@ -67,7 +67,7 @@
#include "stm32_otg.h"
-#if defined(CONFIG_USBHOST) && defined(CONFIG_STM32_OTGFS)
+#if defined(CONFIG_USBHOST) && defined(CONFIG_STM32F7_OTGFS)
/****************************************************************************
* Pre-processor Definitions
@@ -78,61 +78,61 @@
* Pre-requisites
*
* CONFIG_USBHOST - Enable general USB host support
- * CONFIG_STM32_OTGFS - Enable the STM32 USB OTG FS block
- * CONFIG_STM32_SYSCFG - Needed
+ * CONFIG_STM32F7_OTGFS - Enable the STM32 USB OTG FS block
+ * CONFIG_STM32F7_SYSCFG - Needed
*
* Options:
*
- * CONFIG_STM32_OTG_RXFIFO_SIZE - Size of the RX FIFO in 32-bit words.
+ * CONFIG_STM32F7_OTG_RXFIFO_SIZE - Size of the RX FIFO in 32-bit words.
* Default 128 (512 bytes)
- * CONFIG_STM32_OTG_NPTXFIFO_SIZE - Size of the non-periodic Tx FIFO
+ * CONFIG_STM32F7_OTG_NPTXFIFO_SIZE - Size of the non-periodic Tx FIFO
* in 32-bit words. Default 96 (384 bytes)
- * CONFIG_STM32_OTG_PTXFIFO_SIZE - Size of the periodic Tx FIFO in 32-bit
+ * CONFIG_STM32F7_OTG_PTXFIFO_SIZE - Size of the periodic Tx FIFO in 32-bit
* words. Default 96 (384 bytes)
- * CONFIG_STM32_OTG_DESCSIZE - Maximum size of a descriptor. Default: 128
- * CONFIG_STM32_OTG_SOFINTR - Enable SOF interrupts. Why would you ever
+ * CONFIG_STM32F7_OTG_DESCSIZE - Maximum size of a descriptor. Default: 128
+ * CONFIG_STM32F7_OTG_SOFINTR - Enable SOF interrupts. Why would you ever
* want to do that?
- * CONFIG_STM32_USBHOST_REGDEBUG - Enable very low-level register access
+ * CONFIG_STM32F7_USBHOST_REGDEBUG - Enable very low-level register access
* debug. Depends on CONFIG_DEBUG_FEATURES.
- * CONFIG_STM32_USBHOST_PKTDUMP - Dump all incoming and outgoing USB
+ * CONFIG_STM32F7_USBHOST_PKTDUMP - Dump all incoming and outgoing USB
* packets. Depends on CONFIG_DEBUG_FEATURES.
*/
/* Pre-requisites (partial) */
-#ifndef CONFIG_STM32_SYSCFG
-# error "CONFIG_STM32_SYSCFG is required"
+#ifndef CONFIG_STM32F7_SYSCFG
+# error "CONFIG_STM32F7_SYSCFG is required"
#endif
/* Default RxFIFO size */
-#ifndef CONFIG_STM32_OTG_RXFIFO_SIZE
-# define CONFIG_STM32_OTG_RXFIFO_SIZE 128
+#ifndef CONFIG_STM32F7_OTG_RXFIFO_SIZE
+# define CONFIG_STM32F7_OTG_RXFIFO_SIZE 128
#endif
/* Default host non-periodic Tx FIFO size */
-#ifndef CONFIG_STM32_OTG_NPTXFIFO_SIZE
-# define CONFIG_STM32_OTG_NPTXFIFO_SIZE 96
+#ifndef CONFIG_STM32F7_OTG_NPTXFIFO_SIZE
+# define CONFIG_STM32F7_OTG_NPTXFIFO_SIZE 96
#endif
/* Default host periodic Tx fifo size register */
-#ifndef CONFIG_STM32_OTG_PTXFIFO_SIZE
-# define CONFIG_STM32_OTG_PTXFIFO_SIZE 96
+#ifndef CONFIG_STM32F7_OTG_PTXFIFO_SIZE
+# define CONFIG_STM32F7_OTG_PTXFIFO_SIZE 96
#endif
/* Maximum size of a descriptor */
-#ifndef CONFIG_STM32_OTG_DESCSIZE
-# define CONFIG_STM32_OTG_DESCSIZE 128
+#ifndef CONFIG_STM32F7_OTG_DESCSIZE
+# define CONFIG_STM32F7_OTG_DESCSIZE 128
#endif
/* Register/packet debug depends on CONFIG_DEBUG_FEATURES */
#ifndef CONFIG_DEBUG_FEATURES
-# undef CONFIG_STM32_USBHOST_REGDEBUG
-# undef CONFIG_STM32_USBHOST_PKTDUMP
+# undef CONFIG_STM32F7_USBHOST_REGDEBUG
+# undef CONFIG_STM32F7_USBHOST_PKTDUMP
#endif
/* HCD Setup *******************************************************************/
@@ -283,7 +283,7 @@ struct stm32_usbhost_s
/* Register operations ********************************************************/
-#ifdef CONFIG_STM32_USBHOST_REGDEBUG
+#ifdef CONFIG_STM32F7_USBHOST_REGDEBUG
static void stm32_printreg(uint32_t addr, uint32_t val, bool iswrite);
static void stm32_checkreg(uint32_t addr, uint32_t val, bool iswrite);
static uint32_t stm32_getreg(uint32_t addr);
@@ -296,7 +296,7 @@ static void stm32_putreg(uint32_t addr, uint32_t value);
static inline void stm32_modifyreg(uint32_t addr, uint32_t clrbits,
uint32_t setbits);
-#ifdef CONFIG_STM32_USBHOST_PKTDUMP
+#ifdef CONFIG_STM32F7_USBHOST_PKTDUMP
# define stm32_pktdump(m,b,n) lib_dumpbuffer(m,b,n)
#else
# define stm32_pktdump(m,b,n)
@@ -390,7 +390,7 @@ static void stm32_gint_disconnected(FAR struct stm32_usbhost_s *priv);
/* Second level interrupt handlers */
-#ifdef CONFIG_STM32_OTG_SOFINTR
+#ifdef CONFIG_STM32F7_OTG_SOFINTR
static inline void stm32_gint_sofisr(FAR struct stm32_usbhost_s *priv);
#endif
static inline void stm32_gint_rxflvlisr(FAR struct stm32_usbhost_s *priv);
@@ -503,7 +503,7 @@ static struct usbhost_connection_s g_usbconn =
*
****************************************************************************/
-#ifdef CONFIG_STM32_USBHOST_REGDEBUG
+#ifdef CONFIG_STM32F7_USBHOST_REGDEBUG
static void stm32_printreg(uint32_t addr, uint32_t val, bool iswrite)
{
llerr("%08x%s%08x\n", addr, iswrite ? "<-" : "->", val);
@@ -518,7 +518,7 @@ static void stm32_printreg(uint32_t addr, uint32_t val, bool iswrite)
*
****************************************************************************/
-#ifdef CONFIG_STM32_USBHOST_REGDEBUG
+#ifdef CONFIG_STM32F7_USBHOST_REGDEBUG
static void stm32_checkreg(uint32_t addr, uint32_t val, bool iswrite)
{
static uint32_t prevaddr = 0;
@@ -582,7 +582,7 @@ static void stm32_checkreg(uint32_t addr, uint32_t val, bool iswrite)
*
****************************************************************************/
-#ifdef CONFIG_STM32_USBHOST_REGDEBUG
+#ifdef CONFIG_STM32F7_USBHOST_REGDEBUG
static uint32_t stm32_getreg(uint32_t addr)
{
/* Read the value from the register */
@@ -604,7 +604,7 @@ static uint32_t stm32_getreg(uint32_t addr)
*
****************************************************************************/
-#ifdef CONFIG_STM32_USBHOST_REGDEBUG
+#ifdef CONFIG_STM32F7_USBHOST_REGDEBUG
static void stm32_putreg(uint32_t addr, uint32_t val)
{
/* Check if we need to print this value */
@@ -2907,7 +2907,7 @@ static void stm32_gint_disconnected(FAR struct stm32_usbhost_s *priv)
*
****************************************************************************/
-#ifdef CONFIG_STM32_OTG_SOFINTR
+#ifdef CONFIG_STM32F7_OTG_SOFINTR
static inline void stm32_gint_sofisr(FAR struct stm32_usbhost_s *priv)
{
/* Handle SOF interrupt */
@@ -3469,7 +3469,7 @@ static int stm32_gint_isr(int irq, FAR void *context)
/* Handle the start of frame interrupt */
-#ifdef CONFIG_STM32_OTG_SOFINTR
+#ifdef CONFIG_STM32F7_OTG_SOFINTR
if ((pending & OTG_GINT_SOF) != 0)
{
usbhost_vtrace1(OTG_VTRACE1_GINT_SOF, 0);
@@ -3634,7 +3634,7 @@ static inline void stm32_hostinit_enable(void)
* OTG_GINT_DISC : Disconnect detected interrupt
*/
-#ifdef CONFIG_STM32_OTG_SOFINTR
+#ifdef CONFIG_STM32F7_OTG_SOFINTR
regval |= (OTG_GINT_SOF | OTG_GINT_RXFLVL | OTG_GINT_IISOOXFR |
OTG_GINT_HPRT | OTG_GINT_HC | OTG_GINT_DISC);
#else
@@ -4138,7 +4138,7 @@ static int stm32_alloc(FAR struct usbhost_driver_s *drvr,
/* There is no special memory requirement for the STM32. */
- alloc = (FAR uint8_t *)kmm_malloc(CONFIG_STM32_OTG_DESCSIZE);
+ alloc = (FAR uint8_t *)kmm_malloc(CONFIG_STM32F7_OTG_DESCSIZE);
if (!alloc)
{
return -ENOMEM;
@@ -4147,7 +4147,7 @@ static int stm32_alloc(FAR struct usbhost_driver_s *drvr,
/* Return the allocated address and size of the descriptor buffer */
*buffer = alloc;
- *maxlen = CONFIG_STM32_OTG_DESCSIZE;
+ *maxlen = CONFIG_STM32F7_OTG_DESCSIZE;
return OK;
}
@@ -4987,18 +4987,18 @@ static void stm32_host_initialize(FAR struct stm32_usbhost_s *priv)
/* Carve up FIFO memory for the Rx FIFO and the periodic and non-periodic Tx FIFOs */
/* Configure Rx FIFO size (GRXFSIZ) */
- stm32_putreg(STM32_OTG_GRXFSIZ, CONFIG_STM32_OTG_RXFIFO_SIZE);
- offset = CONFIG_STM32_OTG_RXFIFO_SIZE;
+ stm32_putreg(STM32_OTG_GRXFSIZ, CONFIG_STM32F7_OTG_RXFIFO_SIZE);
+ offset = CONFIG_STM32F7_OTG_RXFIFO_SIZE;
/* Setup the host non-periodic Tx FIFO size (HNPTXFSIZ) */
- regval = (offset | (CONFIG_STM32_OTG_NPTXFIFO_SIZE << OTG_HNPTXFSIZ_NPTXFD_SHIFT));
+ regval = (offset | (CONFIG_STM32F7_OTG_NPTXFIFO_SIZE << OTG_HNPTXFSIZ_NPTXFD_SHIFT));
stm32_putreg(STM32_OTG_HNPTXFSIZ, regval);
- offset += CONFIG_STM32_OTG_NPTXFIFO_SIZE;
+ offset += CONFIG_STM32F7_OTG_NPTXFIFO_SIZE;
/* Set up the host periodic Tx fifo size register (HPTXFSIZ) */
- regval = (offset | (CONFIG_STM32_OTG_PTXFIFO_SIZE << OTG_HPTXFSIZ_PTXFD_SHIFT));
+ regval = (offset | (CONFIG_STM32F7_OTG_PTXFIFO_SIZE << OTG_HPTXFSIZ_PTXFD_SHIFT));
stm32_putreg(STM32_OTG_HPTXFSIZ, regval);
/* If OTG were supported, we sould need to clear HNP enable bit in the
@@ -5173,7 +5173,7 @@ static inline int stm32_hw_initialize(FAR struct stm32_usbhost_s *priv)
#ifndef CONFIG_USBDEV_VBUSSENSING
regval |= OTG_GCCFG_NOVBUSSENS;
#endif
-#ifdef CONFIG_STM32_OTG_SOFOUTPUT
+#ifdef CONFIG_STM32F7_OTG_SOFOUTPUT
regval |= OTG_GCCFG_SOFOUTEN;
#endif
stm32_putreg(STM32_OTG_GCCFG, regval);
@@ -5277,7 +5277,7 @@ FAR struct usbhost_connection_s *stm32_otgfshost_initialize(int controller)
/* SOF output pin configuration is configurable */
-#ifdef CONFIG_STM32_OTG_SOFOUTPUT
+#ifdef CONFIG_STM32F7_OTG_SOFOUTPUT
stm32_configgpio(GPIO_OTG_SOF);
#endif
@@ -5303,4 +5303,4 @@ FAR struct usbhost_connection_s *stm32_otgfshost_initialize(int controller)
return &g_usbconn;
}
-#endif /* CONFIG_USBHOST && CONFIG_STM32_OTGFS */
+#endif /* CONFIG_USBHOST && CONFIG_STM32F7_OTGFS */
diff --git a/arch/arm/src/stm32f7/stm32_sdmmc.c b/arch/arm/src/stm32f7/stm32_sdmmc.c
index 58f7b7318d..4f2b7a8d01 100644
--- a/arch/arm/src/stm32f7/stm32_sdmmc.c
+++ b/arch/arm/src/stm32f7/stm32_sdmmc.c
@@ -964,6 +964,11 @@ static void stm32_dataconfig(uint32_t timeout, uint32_t dlen, uint32_t dctrl)
regval &= ~(SDIO_DCTRL_DTDIR | SDIO_DCTRL_DTMODE | SDIO_DCTRL_DBLOCKSIZE_MASK);
dctrl &= (SDIO_DCTRL_DTDIR | SDIO_DCTRL_DTMODE | SDIO_DCTRL_DBLOCKSIZE_MASK);
regval |= (dctrl | SDIO_DCTRL_DTEN);
+
+#ifdef CONFIG_SDIO_DMA
+ regval |= SDIO_DCTRL_DMAEN;
+#endif
+
putreg32(regval, STM32_SDMMC1_DCTRL);
}
diff --git a/configs/stm32f746-ws/nsh/defconfig b/configs/stm32f746-ws/nsh/defconfig
index 97b867c160..44a25aec95 100644
--- a/configs/stm32f746-ws/nsh/defconfig
+++ b/configs/stm32f746-ws/nsh/defconfig
@@ -52,6 +52,12 @@ CONFIG_ARCH_HAVE_CUSTOMOPT=y
CONFIG_DEBUG_NOOPT=y
# CONFIG_DEBUG_CUSTOMOPT is not set
# CONFIG_DEBUG_FULLOPT is not set
+CONFIG_DEBUG_ERROR=y
+CONFIG_DEBUG_INFO=y
+CONFIG_DEBUG_WARN=y
+CONFIG_DEBUG_FS_INFO=y
+CONFIG_DEBUG_FS_ERROR=y
+CONFIG_DEBUG_FS_WARN=y
#
# System Type
@@ -267,7 +273,7 @@ CONFIG_STM32F7_HAVE_DMA2D=y
CONFIG_STM32F7_ADC=y
# CONFIG_STM32F7_CAN is not set
# CONFIG_STM32F7_DAC is not set
-# CONFIG_STM32F7_DMA is not set
+CONFIG_STM32F7_DMA=y
CONFIG_STM32F7_I2C=y
# CONFIG_STM32F7_SAI is not set
CONFIG_STM32F7_SPI=y
@@ -282,7 +288,7 @@ CONFIG_STM32F7_ADC1=y
# CONFIG_STM32F7_CEC is not set
# CONFIG_STM32F7_CRC is not set
# CONFIG_STM32F7_DMA1 is not set
-# CONFIG_STM32F7_DMA2 is not set
+CONFIG_STM32F7_DMA2=y
# CONFIG_STM32F7_DAC1 is not set
# CONFIG_STM32F7_DAC2 is not set
# CONFIG_STM32F7_DCMI is not set
@@ -294,13 +300,13 @@ CONFIG_STM32F7_I2C1=y
# CONFIG_STM32F7_I2C3 is not set
# CONFIG_STM32F7_LPTIM1 is not set
# CONFIG_STM32F7_LTDC is not set
-# CONFIG_STM32F7_OTGFS is not set
+##CONFIG_STM32F7_OTGFS=y
# CONFIG_STM32F7_OTGHS is not set
# CONFIG_STM32F7_QUADSPI is not set
# CONFIG_STM32F7_RNG is not set
# CONFIG_STM32F7_SAI1 is not set
# CONFIG_STM32F7_SAI2 is not set
-# CONFIG_STM32F7_SDMMC1 is not set
+CONFIG_STM32F7_SDMMC1=y
# CONFIG_STM32F7_SPDIFRX is not set
CONFIG_STM32F7_SPI1=y
# CONFIG_STM32F7_SPI2 is not set
@@ -352,7 +358,7 @@ CONFIG_STM32F7_USART6=y
#
# CONFIG_ARCH_NOINTC is not set
# CONFIG_ARCH_VECNOTIRQ is not set
-# CONFIG_ARCH_DMA is not set
+CONFIG_ARCH_DMA=y
CONFIG_ARCH_HAVE_IRQPRIO=y
# CONFIG_ARCH_L2CACHE is not set
# CONFIG_ARCH_HAVE_COHERENT_DCACHE is not set
@@ -416,6 +422,7 @@ CONFIG_ARCH_BOARD="stm32f746-ws"
# Common Board Options
#
CONFIG_NSH_MMCSDMINOR=0
+CONFIG_NSH_MMCSDSLOTNO=0
#
# Board-Specific Options
@@ -427,6 +434,7 @@ CONFIG_LIB_BOARDCTL=y
# CONFIG_BOARDCTL_PWMTEST is not set
# CONFIG_BOARDCTL_GRAPHICS is not set
# CONFIG_BOARDCTL_IOCTL is not set
+##CONFIG_BOARDCTL_USBDEVCTRL=y
#
# RTOS Features
@@ -550,6 +558,17 @@ CONFIG_DEV_NULL=y
# CONFIG_DEV_ZERO is not set
# CONFIG_DEV_LOOP is not set
+CONFIG_MMCSD=y
+CONFIG_MMCSD_NSLOTS=1
+# CONFIG_MMCSD_READONLY is not set
+CONFIG_MMCSD_MULTIBLOCK_DISABLE=y
+# CONFIG_MMCSD_MMCSUPPORT is not set
+CONFIG_MMCSD_HAVECARDDETECT=y
+# CONFIG_MMCSD_SPI is not set
+CONFIG_ARCH_HAVE_SDIO=y
+CONFIG_ARCH_HAVE_SDIOWAIT_WRCOMPLETE=y
+CONFIG_MMCSD_SDIO=y
+
#
# Buffering
#
@@ -579,6 +598,8 @@ CONFIG_SPI_EXCHANGE=y
# CONFIG_SPI_CS_DELAY_CONTROL is not set
# CONFIG_I2S is not set
+CONFIG_SDIO_DMA=y
+
#
# Timer Driver Support
#
@@ -669,7 +690,50 @@ CONFIG_USART6_2STOP=0
# CONFIG_USART6_IFLOWCONTROL is not set
# CONFIG_USART6_OFLOWCONTROL is not set
# CONFIG_USART6_DMA is not set
-# CONFIG_USBDEV is not set
+##CONFIG_USBDEV=y
+# CONFIG_USBHOST is not set
+# CONFIG_DRIVERS_WIRELESS is not set
+
+
+#
+# USB Device Controller Driver Options
+#
+# CONFIG_USBDEV_ISOCHRONOUS is not set
+# CONFIG_USBDEV_DUALSPEED is not set
+##CONFIG_USBDEV_SELFPOWERED=y
+# CONFIG_USBDEV_BUSPOWERED is not set
+##CONFIG_USBDEV_MAXPOWER=100
+# CONFIG_USBDEV_DMA is not set
+# CONFIG_ARCH_USBDEV_STALLQUEUE is not set
+# CONFIG_USBDEV_TRACE is not set
+
+#
+# USB Device Class Driver Options
+#
+# CONFIG_USBDEV_COMPOSITE is not set
+# CONFIG_PL2303 is not set
+##CONFIG_CDCACM=y
+##CONFIG_CDCACM_CONSOLE=y
+##CONFIG_CDCACM_EP0MAXPACKET=64
+##CONFIG_CDCACM_EPINTIN=1
+##CONFIG_CDCACM_EPINTIN_FSSIZE=64
+##CONFIG_CDCACM_EPINTIN_HSSIZE=64
+##CONFIG_CDCACM_EPBULKOUT=3
+##CONFIG_CDCACM_EPBULKOUT_FSSIZE=64
+##CONFIG_CDCACM_EPBULKOUT_HSSIZE=512
+##CONFIG_CDCACM_EPBULKIN=2
+##CONFIG_CDCACM_EPBULKIN_FSSIZE=64
+##CONFIG_CDCACM_EPBULKIN_HSSIZE=512
+##CONFIG_CDCACM_NRDREQS=4
+##CONFIG_CDCACM_NWRREQS=4
+##CONFIG_CDCACM_BULKIN_REQLEN=96
+##CONFIG_CDCACM_RXBUFSIZE=256
+##CONFIG_CDCACM_TXBUFSIZE=256
+##CONFIG_CDCACM_VENDORID=0x0525
+##CONFIG_CDCACM_PRODUCTID=0xa4a7
+##CONFIG_CDCACM_VENDORSTR="NuttX"
+##CONFIG_CDCACM_PRODUCTSTR="CDC/ACM Serial"
+# CONFIG_USBMSC is not set
# CONFIG_USBHOST is not set
# CONFIG_DRIVERS_WIRELESS is not set
@@ -706,13 +770,17 @@ CONFIG_USART6_2STOP=0
# CONFIG_DISABLE_MOUNTPOINT is not set
# CONFIG_FS_AUTOMOUNTER is not set
# CONFIG_DISABLE_PSEUDOFS_OPERATIONS is not set
-# CONFIG_FS_READABLE is not set
-# CONFIG_FS_WRITABLE is not set
+CONFIG_FS_READABLE=y
+CONFIG_FS_WRITABLE=y
# CONFIG_FS_AIO is not set
# CONFIG_FS_NAMED_SEMAPHORES is not set
CONFIG_FS_MQUEUE_MPATH="/var/mqueue"
# CONFIG_FS_RAMMAP is not set
-# CONFIG_FS_FAT is not set
+CONFIG_FS_FAT=y
+CONFIG_FAT_LCNAMES=y
+CONFIG_FAT_LFN=y
+CONFIG_FAT_MAXFNAME=32
+CONFIG_FAT_DMAMEMORY=y
# CONFIG_FS_NXFFS is not set
# CONFIG_FS_ROMFS is not set
# CONFIG_FS_TMPFS is not set
diff --git a/configs/stm32f746-ws/src/Makefile b/configs/stm32f746-ws/src/Makefile
index b20f916b7e..4096729548 100644
--- a/configs/stm32f746-ws/src/Makefile
+++ b/configs/stm32f746-ws/src/Makefile
@@ -36,10 +36,18 @@
-include $(TOPDIR)/Make.defs
ASRCS =
-CSRCS = stm32_boot.c stm32_spi.c
+CSRCS = stm32_boot.c stm32_spi.c stm32_dma_alloc.c
ifeq ($(CONFIG_LIB_BOARDCTL),y)
CSRCS += stm32_appinitialize.c
endif
+ifeq ($(CONFIG_STM32F7_OTGFS),y)
+CSRCS += stm32_usb.c
+endif
+
+ifeq ($(CONFIG_STM32F7_SDMMC1),y)
+CSRCS += stm32_sdmmc.c
+endif
+
include $(TOPDIR)/configs/Board.mk
diff --git a/configs/stm32f746-ws/src/stm32_appinitialize.c b/configs/stm32f746-ws/src/stm32_appinitialize.c
index 734e35957a..689bea75fe 100644
--- a/configs/stm32f746-ws/src/stm32_appinitialize.c
+++ b/configs/stm32f746-ws/src/stm32_appinitialize.c
@@ -93,5 +93,23 @@ int board_app_initialize(void)
stm32_i2ctool();
+#if defined(CONFIG_FAT_DMAMEMORY)
+ if (stm32_dma_alloc_init() < 0)
+ {
+ syslog(LOG_ERR, "DMA alloc FAILED");
+ }
+#endif
+
+ /* Initialize the SDIO block driver */
+
+ int ret = OK;
+
+ ret = stm32_sdio_initialize();
+ if (ret != OK)
+ {
+ ferr("ERROR: Failed to initialize MMC/SD driver: %d\n", ret);
+ return ret;
+ }
+
return OK;
}
diff --git a/configs/stm32f746-ws/src/stm32_dma_alloc.c b/configs/stm32f746-ws/src/stm32_dma_alloc.c
new file mode 100644
index 0000000000..e6d2744529
--- /dev/null
+++ b/configs/stm32f746-ws/src/stm32_dma_alloc.c
@@ -0,0 +1,117 @@
+/****************************************************************************
+ * configs/nucleo-144/stc/stm32_dma_alloc.c
+ *
+ * Copyright (C) 2016 PX4 Development Team. All rights reserved.
+ *
+ * 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 PX4 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
+#include
+#include
+#include
+#include
+
+#include "stm32f746-ws.h"
+
+#if defined(CONFIG_FAT_DMAMEMORY)
+
+/************************************************************************************
+ * Pre-processor Definitions
+ ************************************************************************************/
+
+#if !defined(CONFIG_GRAN)
+# error microSD DMA support requires CONFIG_GRAN
+#endif
+
+#define BOARD_DMA_ALLOC_POOL_SIZE (8*512)
+
+/************************************************************************************
+ * Private Data
+ ************************************************************************************/
+
+static GRAN_HANDLE dma_allocator;
+
+/* The DMA heap size constrains the total number of things that can be
+ * ready to do DMA at a time.
+ *
+ * For example, FAT DMA depends on one sector-sized buffer per filesystem plus
+ * one sector-sized buffer per file.
+ *
+ * We use a fundamental alignment / granule size of 64B; this is sufficient
+ * to guarantee alignment for the largest STM32 DMA burst (16 beats x 32bits).
+ */
+
+static uint8_t g_dma_heap[BOARD_DMA_ALLOC_POOL_SIZE] __attribute__((aligned(64)));
+
+/************************************************************************************
+ * Public Functions
+ ************************************************************************************/
+
+/************************************************************************************
+ * Name: stm32_dma_alloc_init
+ *
+ * Description:
+ * All boards may optionally provide this API to instantiate a pool of
+ * memory for uses with FAST FS DMA operations.
+ *
+ ************************************************************************************/
+
+int stm32_dma_alloc_init(void)
+{
+ dma_allocator = gran_initialize(g_dma_heap,
+ sizeof(g_dma_heap),
+ 7, /* 128B granule - must be > alignment (XXX bug?) */
+ 6); /* 64B alignment */
+
+ if (dma_allocator == NULL)
+ {
+ return -ENOMEM;
+ }
+
+ return OK;
+}
+
+/* DMA-aware allocator stubs for the FAT filesystem. */
+
+void *fat_dma_alloc(size_t size)
+{
+ return gran_alloc(dma_allocator, size);
+}
+
+void fat_dma_free(FAR void *memory, size_t size)
+{
+ gran_free(dma_allocator, memory, size);
+}
+
+#endif /* CONFIG_FAT_DMAMEMORY */
diff --git a/configs/stm32f746-ws/src/stm32_sdmmc.c b/configs/stm32f746-ws/src/stm32_sdmmc.c
new file mode 100644
index 0000000000..bdbe7a7f65
--- /dev/null
+++ b/configs/stm32f746-ws/src/stm32_sdmmc.c
@@ -0,0 +1,171 @@
+/****************************************************************************
+ * config/stm32f746-ws/src/stm32_sdio.c
+ *
+ * Copyright (C) 2014 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * 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
+
+#include
+#include
+#include
+#include
+
+#include
+#include
+
+#include "stm32_sdmmc.h"
+#include "stm32f746-ws.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+/* Configuration ************************************************************/
+
+/* Card detections requires card support and a card detection GPIO */
+
+#define HAVE_NCD 1
+#if !defined(HAVE_SDIO) || !defined(GPIO_SDIO_NCD)
+# undef HAVE_NCD
+#endif
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static FAR struct sdio_dev_s *g_sdio_dev;
+#ifdef HAVE_NCD
+static bool g_sd_inserted = 0xff; /* Impossible value */
+#endif
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: stm32_ncd_interrupt
+ *
+ * Description:
+ * Card detect interrupt handler.
+ *
+ ****************************************************************************/
+
+#ifdef HAVE_NCD
+static int stm32_ncd_interrupt(int irq, FAR void *context)
+{
+ bool present;
+
+ present = !stm32_gpioread(GPIO_SDIO_NCD);
+ if (present != g_sd_inserted)
+ {
+ sdio_mediachange(g_sdio_dev, present);
+ g_sd_inserted = present;
+ }
+
+ return OK;
+}
+#endif
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: stm32_sdio_initialize
+ *
+ * Description:
+ * Initialize SDIO-based MMC/SD card support
+ *
+ ****************************************************************************/
+
+int stm32_sdio_initialize(void)
+{
+ int ret;
+
+#ifdef HAVE_NCD
+ /* Card detect */
+
+ bool cd_status;
+
+ /* Configure the card detect GPIO */
+
+ stm32_configgpio(GPIO_SDIO_NCD);
+
+ /* Register an interrupt handler for the card detect pin */
+
+ stm32_gpiosetevent(GPIO_SDIO_NCD, true, true, true, stm32_ncd_interrupt);
+#endif
+
+ /* Mount the SDIO-based MMC/SD block driver */
+ /* First, get an instance of the SDIO interface */
+
+ finfo("Initializing SDIO slot %d\n", SDIO_SLOTNO);
+
+ g_sdio_dev = sdio_initialize(SDIO_SLOTNO);
+ if (!g_sdio_dev)
+ {
+ ferr("ERROR: Failed to initialize SDIO slot %d\n", SDIO_SLOTNO);
+ return -ENODEV;
+ }
+
+ /* Now bind the SDIO interface to the MMC/SD driver */
+
+ finfo("Bind SDIO to the MMC/SD driver, minor=%d\n", SDIO_MINOR);
+
+ ret = mmcsd_slotinitialize(SDIO_MINOR, g_sdio_dev);
+ if (ret != OK)
+ {
+ ferr("ERROR: Failed to bind SDIO to the MMC/SD driver: %d\n", ret);
+ return ret;
+ }
+
+ finfo("Successfully bound SDIO to the MMC/SD driver\n");
+
+#ifdef HAVE_NCD
+ /* Use SD card detect pin to check if a card is g_sd_inserted */
+
+ cd_status = !stm32_gpioread(GPIO_SDIO_NCD);
+ finfo("Card detect : %d\n", cd_status);
+
+ sdio_mediachange(g_sdio_dev, cd_status);
+#else
+ /* Assume that the SD card is inserted. What choice do we have? */
+
+ sdio_mediachange(g_sdio_dev, true);
+#endif
+
+ return OK;
+}
diff --git a/configs/stm32f746-ws/src/stm32_usb.c b/configs/stm32f746-ws/src/stm32_usb.c
new file mode 100644
index 0000000000..b81aacd6ca
--- /dev/null
+++ b/configs/stm32f746-ws/src/stm32_usb.c
@@ -0,0 +1,340 @@
+/************************************************************************************
+ * configs/stm32f4discovery/src/stm32_usb.c
+ *
+ * Copyright (C) 2012-2013, 2015 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * 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
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include
+#include
+#include
+
+#include "up_arch.h"
+#include "stm32_otg.h"
+#include "stm32_gpio.h"
+#include "stm32f746-ws.h"
+
+#ifdef CONFIG_STM32F7_OTGFS
+
+/************************************************************************************
+ * Pre-processor Definitions
+ ************************************************************************************/
+
+#if defined(CONFIG_USBDEV) || defined(CONFIG_USBHOST)
+# define HAVE_USB 1
+#else
+# warning "CONFIG_STM32F7_OTGFS is enabled but neither CONFIG_USBDEV nor CONFIG_USBHOST"
+# undef HAVE_USB
+#endif
+
+#ifndef CONFIG_STM32F7F4DISCO_USBHOST_PRIO
+# define CONFIG_STM32F7F4DISCO_USBHOST_PRIO 100
+#endif
+
+#ifndef CONFIG_STM32F7F4DISCO_USBHOST_STACKSIZE
+# define CONFIG_STM32F7F4DISCO_USBHOST_STACKSIZE 1024
+#endif
+
+/************************************************************************************
+ * Private Data
+ ************************************************************************************/
+
+#ifdef CONFIG_USBHOST
+static struct usbhost_connection_s *g_usbconn;
+#endif
+
+/************************************************************************************
+ * Private Functions
+ ************************************************************************************/
+
+/************************************************************************************
+ * Name: usbhost_waiter
+ *
+ * Description:
+ * Wait for USB devices to be connected.
+ *
+ ************************************************************************************/
+
+#ifdef CONFIG_USBHOST
+static int usbhost_waiter(int argc, char *argv[])
+{
+ struct usbhost_hubport_s *hport;
+
+ uinfo("Running\n");
+ for (;;)
+ {
+ /* Wait for the device to change state */
+
+ DEBUGVERIFY(CONN_WAIT(g_usbconn, &hport));
+ uinfo("%s\n", hport->connected ? "connected" : "disconnected");
+
+ /* Did we just become connected? */
+
+ if (hport->connected)
+ {
+ /* Yes.. enumerate the newly connected device */
+
+ (void)CONN_ENUMERATE(g_usbconn, hport);
+ }
+ }
+
+ /* Keep the compiler from complaining */
+
+ return 0;
+}
+#endif
+
+/************************************************************************************
+ * Public Functions
+ ************************************************************************************/
+
+/************************************************************************************
+ * Name: stm32_usbinitialize
+ *
+ * Description:
+ * Called from stm32_usbinitialize very early in inialization to setup USB-related
+ * GPIO pins for the STM32F4Discovery board.
+ *
+ ************************************************************************************/
+
+void stm32_usbinitialize(void)
+{
+ /* The OTG FS has an internal soft pull-up. No GPIO configuration is required */
+
+ /* Configure the OTG FS VBUS sensing GPIO, Power On, and Overcurrent GPIOs */
+
+#ifdef CONFIG_STM32F7_OTGFS
+ stm32_configgpio(GPIO_OTGFS_VBUS);
+
+#ifdef CONFIG_USBHOST
+ stm32_configgpio(GPIO_OTGFS_PWRON);
+ stm32_configgpio(GPIO_OTGFS_OVER);
+#endif
+
+#endif
+}
+
+/***********************************************************************************
+ * Name: stm32_usbhost_initialize
+ *
+ * Description:
+ * Called at application startup time to initialize the USB host functionality.
+ * This function will start a thread that will monitor for device
+ * connection/disconnection events.
+ *
+ ***********************************************************************************/
+
+#ifdef CONFIG_USBHOST
+int stm32_usbhost_initialize(void)
+{
+ int pid;
+#if defined(CONFIG_USBHOST_HUB) || defined(CONFIG_USBHOST_MSC) || \
+ defined(CONFIG_USBHOST_HIDKBD) || defined(CONFIG_USBHOST_HIDMOUSE)
+ int ret;
+#endif
+
+ /* First, register all of the class drivers needed to support the drivers
+ * that we care about:
+ */
+
+ uinfo("Register class drivers\n");
+
+#ifdef CONFIG_USBHOST_HUB
+ /* Initialize USB hub class support */
+
+ ret = usbhost_hub_initialize();
+ if (ret < 0)
+ {
+ uerr("ERROR: usbhost_hub_initialize failed: %d\n", ret);
+ }
+#endif
+
+#ifdef CONFIG_USBHOST_MSC
+ /* Register the USB mass storage class class */
+
+ ret = usbhost_msc_initialize();
+ if (ret != OK)
+ {
+ uerr("ERROR: Failed to register the mass storage class: %d\n", ret);
+ }
+#endif
+
+#ifdef CONFIG_USBHOST_CDCACM
+ /* Register the CDC/ACM serial class */
+
+ ret = usbhost_cdcacm_initialize();
+ if (ret != OK)
+ {
+ uerr("ERROR: Failed to register the CDC/ACM serial class: %d\n", ret);
+ }
+#endif
+
+#ifdef CONFIG_USBHOST_HIDKBD
+ /* Initialize the HID keyboard class */
+
+ ret = usbhost_kbdinit();
+ if (ret != OK)
+ {
+ uerr("ERROR: Failed to register the HID keyboard class\n");
+ }
+#endif
+
+#ifdef CONFIG_USBHOST_HIDMOUSE
+ /* Initialize the HID mouse class */
+
+ ret = usbhost_mouse_init();
+ if (ret != OK)
+ {
+ uerr("ERROR: Failed to register the HID mouse class\n");
+ }
+#endif
+
+ /* Then get an instance of the USB host interface */
+
+ uinfo("Initialize USB host\n");
+ g_usbconn = stm32_otgfshost_initialize(0);
+ if (g_usbconn)
+ {
+ /* Start a thread to handle device connection. */
+
+ uinfo("Start usbhost_waiter\n");
+
+ pid = task_create("usbhost", CONFIG_STM32F7F4DISCO_USBHOST_PRIO,
+ CONFIG_STM32F7F4DISCO_USBHOST_STACKSIZE,
+ (main_t)usbhost_waiter, (FAR char * const *)NULL);
+ return pid < 0 ? -ENOEXEC : OK;
+ }
+
+ return -ENODEV;
+}
+#endif
+
+/***********************************************************************************
+ * Name: stm32_usbhost_vbusdrive
+ *
+ * Description:
+ * Enable/disable driving of VBUS 5V output. This function must be provided be
+ * each platform that implements the STM32 OTG FS host interface
+ *
+ * "On-chip 5 V VBUS generation is not supported. For this reason, a charge pump
+ * or, if 5 V are available on the application board, a basic power switch, must
+ * be added externally to drive the 5 V VBUS line. The external charge pump can
+ * be driven by any GPIO output. When the application decides to power on VBUS
+ * using the chosen GPIO, it must also set the port power bit in the host port
+ * control and status register (PPWR bit in OTG_FS_HPRT).
+ *
+ * "The application uses this field to control power to this port, and the core
+ * clears this bit on an overcurrent condition."
+ *
+ * Input Parameters:
+ * iface - For future growth to handle multiple USB host interface. Should be zero.
+ * enable - true: enable VBUS power; false: disable VBUS power
+ *
+ * Returned Value:
+ * None
+ *
+ ***********************************************************************************/
+
+#ifdef CONFIG_USBHOST
+void stm32_usbhost_vbusdrive(int iface, bool enable)
+{
+ DEBUGASSERT(iface == 0);
+
+ if (enable)
+ {
+ /* Enable the Power Switch by driving the enable pin low */
+
+ stm32_gpiowrite(GPIO_OTGFS_PWRON, false);
+ }
+ else
+ {
+ /* Disable the Power Switch by driving the enable pin high */
+
+ stm32_gpiowrite(GPIO_OTGFS_PWRON, true);
+ }
+}
+#endif
+
+/************************************************************************************
+ * Name: stm32_setup_overcurrent
+ *
+ * Description:
+ * Setup to receive an interrupt-level callback if an overcurrent condition is
+ * detected.
+ *
+ * Input Parameter:
+ * handler - New overcurrent interrupt handler
+ *
+ * Returned value:
+ * Old overcurrent interrupt handler
+ *
+ ************************************************************************************/
+
+#ifdef CONFIG_USBHOST
+xcpt_t stm32_setup_overcurrent(xcpt_t handler)
+{
+ return stm32_gpiosetevent(GPIO_OTGFS_OVER, true, true, true, handler);
+}
+#endif
+
+/************************************************************************************
+ * Name: stm32_usbsuspend
+ *
+ * Description:
+ * Board logic must provide the stm32_usbsuspend logic if the USBDEV driver is
+ * used. This function is called whenever the USB enters or leaves suspend mode.
+ * This is an opportunity for the board logic to shutdown clocks, power, etc.
+ * while the USB is suspended.
+ *
+ ************************************************************************************/
+
+#ifdef CONFIG_USBDEV
+void stm32_usbsuspend(FAR struct usbdev_s *dev, bool resume)
+{
+ ullinfo("resume: %d\n", resume);
+}
+#endif
+
+#endif /* CONFIG_STM32F7_OTGFS */
diff --git a/configs/stm32f746-ws/src/stm32f746-ws.h b/configs/stm32f746-ws/src/stm32f746-ws.h
index 07d2c6c11f..0a61a7b162 100644
--- a/configs/stm32f746-ws/src/stm32f746-ws.h
+++ b/configs/stm32f746-ws/src/stm32f746-ws.h
@@ -82,6 +82,12 @@
#define GPIO_BTN_USER (GPIO_INPUT | GPIO_FLOAT | GPIO_EXTI | GPIO_PORTC | GPIO_PIN13)
+#define GPIO_OTGFS_VBUS (GPIO_INPUT|GPIO_FLOAT|GPIO_SPEED_100MHz|\
+ GPIO_OPENDRAIN|GPIO_PORTA|GPIO_PIN9)
+
+#define SDIO_SLOTNO 0
+#define SDIO_MINOR 0
+
/****************************************************************************************************
* Public data
****************************************************************************************************/
@@ -102,5 +108,32 @@
void weak_function stm32_spidev_initialize(void);
+ /****************************************************************************
+ * Name: stm32_sdio_initialize
+ *
+ * Description:
+ * Initialize SDIO-based MMC/SD card support
+ *
+ ****************************************************************************/
+
+ #if !defined(CONFIG_DISABLE_MOUNTPOINT) && defined(CONFIG_STM32F7_SDMMC1)
+ int stm32_sdio_initialize(void);
+ #endif
+
+ /************************************************************************************
+ * Name: stm32_dma_alloc_init
+ *
+ * Description:
+ * Called to create a FAT DMA allocator
+ *
+ * Returned Value:
+ * 0 on success or -ENOMEM
+ *
+ ************************************************************************************/
+
+ #if defined (CONFIG_FAT_DMAMEMORY)
+ int stm32_dma_alloc_init(void);
+ #endif
+
#endif /* __ASSEMBLY__ */
#endif /* __CONFIGS_STM32F746_WS_SRC_STM32F746_WS_H */
--
GitLab
From 495e475357d8cf0e2219b116ee5fc935d108b216 Mon Sep 17 00:00:00 2001
From: Lok Tep
Date: Mon, 20 Jun 2016 10:55:38 +0200
Subject: [PATCH 004/734] ignore CRC for SD_CMD55
---
arch/arm/src/stm32f7/stm32_sdmmc.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/arch/arm/src/stm32f7/stm32_sdmmc.c b/arch/arm/src/stm32f7/stm32_sdmmc.c
index 4f2b7a8d01..c1eb3542d7 100644
--- a/arch/arm/src/stm32f7/stm32_sdmmc.c
+++ b/arch/arm/src/stm32f7/stm32_sdmmc.c
@@ -2093,7 +2093,7 @@ static int stm32_recvshortcrc(FAR struct sdio_dev_s *dev, uint32_t cmd, uint32_t
else
#endif
{
- /* Check if a timeout or CRC error occurred */
+ /* Check if a timeout or CRC error occurred (not for SD_CMD55 - see ERRATA) */
regval = getreg32(STM32_SDMMC1_STA);
if ((regval & SDIO_STA_CTIMEOUT) != 0)
@@ -2101,7 +2101,7 @@ static int stm32_recvshortcrc(FAR struct sdio_dev_s *dev, uint32_t cmd, uint32_t
ferr("ERROR: Command timeout: %08x\n", regval);
ret = -ETIMEDOUT;
}
- else if ((regval & SDIO_STA_CCRCFAIL) != 0)
+ else if (cmd != SD_CMD55 && (regval & SDIO_STA_CCRCFAIL) != 0)
{
ferr("ERROR: CRC failure: %08x\n", regval);
ret = -EIO;
--
GitLab
From e70ac97cef06b86b54af3e2c199b40695b8874b3 Mon Sep 17 00:00:00 2001
From: Lok Tep
Date: Tue, 21 Jun 2016 13:17:50 +0200
Subject: [PATCH 005/734] should be cmd5 not cmd55
---
arch/arm/src/stm32f7/stm32_sdmmc.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/arch/arm/src/stm32f7/stm32_sdmmc.c b/arch/arm/src/stm32f7/stm32_sdmmc.c
index c1eb3542d7..4f2b7a8d01 100644
--- a/arch/arm/src/stm32f7/stm32_sdmmc.c
+++ b/arch/arm/src/stm32f7/stm32_sdmmc.c
@@ -2093,7 +2093,7 @@ static int stm32_recvshortcrc(FAR struct sdio_dev_s *dev, uint32_t cmd, uint32_t
else
#endif
{
- /* Check if a timeout or CRC error occurred (not for SD_CMD55 - see ERRATA) */
+ /* Check if a timeout or CRC error occurred */
regval = getreg32(STM32_SDMMC1_STA);
if ((regval & SDIO_STA_CTIMEOUT) != 0)
@@ -2101,7 +2101,7 @@ static int stm32_recvshortcrc(FAR struct sdio_dev_s *dev, uint32_t cmd, uint32_t
ferr("ERROR: Command timeout: %08x\n", regval);
ret = -ETIMEDOUT;
}
- else if (cmd != SD_CMD55 && (regval & SDIO_STA_CCRCFAIL) != 0)
+ else if ((regval & SDIO_STA_CCRCFAIL) != 0)
{
ferr("ERROR: CRC failure: %08x\n", regval);
ret = -EIO;
--
GitLab
From bdfd3e824834b1faf47ffcb5b32a8a2bed202617 Mon Sep 17 00:00:00 2001
From: Lok Tep
Date: Tue, 21 Jun 2016 14:02:53 +0200
Subject: [PATCH 006/734] flush cache before setup
---
arch/arm/src/stm32f7/stm32_sdmmc.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/arch/arm/src/stm32f7/stm32_sdmmc.c b/arch/arm/src/stm32f7/stm32_sdmmc.c
index 4f2b7a8d01..dbeb880f93 100644
--- a/arch/arm/src/stm32f7/stm32_sdmmc.c
+++ b/arch/arm/src/stm32f7/stm32_sdmmc.c
@@ -2694,6 +2694,10 @@ static int stm32_dmasendsetup(FAR struct sdio_dev_s *dev,
stm32_sampleinit();
stm32_sample(priv, SAMPLENDX_BEFORE_SETUP);
+ /* Flush cache to physical memory */
+
+ arch_flush_dcache((uintptr_t)buffer, (uintptr_t)buffer + buflen);
+
/* Save the source buffer information for use by the interrupt handler */
priv->buffer = (uint32_t *)buffer;
@@ -2712,10 +2716,6 @@ static int stm32_dmasendsetup(FAR struct sdio_dev_s *dev,
stm32_sample(priv, SAMPLENDX_BEFORE_ENABLE);
- /* Flush cache to physical memory */
-
- arch_flush_dcache((uintptr_t)buffer, (uintptr_t)buffer + buflen);
-
/* Start the DMA */
stm32_dmastart(priv->dma, stm32_dmacallback, priv, false);
--
GitLab
From 0369bbff508bf93fad3413e839f7c7e33ecb9a9d Mon Sep 17 00:00:00 2001
From: Lok Tep
Date: Wed, 22 Jun 2016 10:54:06 +0200
Subject: [PATCH 007/734] styling
---
arch/arm/src/stm32f7/chip/stm32_sdmmc.h | 4 ++--
arch/arm/src/stm32f7/chip/stm32f74xx75xx_sdmmc.h | 4 ++--
arch/arm/src/stm32f7/stm32_sdmmc.c | 2 +-
arch/arm/src/stm32f7/stm32_sdmmc.h | 4 ++--
4 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/arch/arm/src/stm32f7/chip/stm32_sdmmc.h b/arch/arm/src/stm32f7/chip/stm32_sdmmc.h
index e04bdddc1e..10ed29f238 100644
--- a/arch/arm/src/stm32f7/chip/stm32_sdmmc.h
+++ b/arch/arm/src/stm32f7/chip/stm32_sdmmc.h
@@ -1,7 +1,7 @@
/************************************************************************************
- * arch/arm/src/stm32f7/chip/stm32_i2c.h
+ * arch/arm/src/stm32f7/chip/stm32_sdmmc.h
*
- * Copyright (C) 2015 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2016 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt
*
* Redistribution and use in source and binary forms, with or without
diff --git a/arch/arm/src/stm32f7/chip/stm32f74xx75xx_sdmmc.h b/arch/arm/src/stm32f7/chip/stm32f74xx75xx_sdmmc.h
index f710aed6d1..117c4da2fa 100644
--- a/arch/arm/src/stm32f7/chip/stm32f74xx75xx_sdmmc.h
+++ b/arch/arm/src/stm32f7/chip/stm32f74xx75xx_sdmmc.h
@@ -1,7 +1,7 @@
/************************************************************************************
- * arch/arm/src/stm32f7/chip/stm32_sdio.h
+ * arch/arm/src/stm32f7/chip/stm32_sdmmc.h
*
- * Copyright (C) 2009, 2011-2013 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2009, 2011-2016 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt
*
* Redistribution and use in source and binary forms, with or without
diff --git a/arch/arm/src/stm32f7/stm32_sdmmc.c b/arch/arm/src/stm32f7/stm32_sdmmc.c
index dbeb880f93..16473094b5 100644
--- a/arch/arm/src/stm32f7/stm32_sdmmc.c
+++ b/arch/arm/src/stm32f7/stm32_sdmmc.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * arch/arm/src/stm32f7/stm32_sdio.c
+ * arch/arm/src/stm32f7/stm32_sdmmc.c
*
* Copyright (C) 2009, 2011-2016 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt
diff --git a/arch/arm/src/stm32f7/stm32_sdmmc.h b/arch/arm/src/stm32f7/stm32_sdmmc.h
index 18e6c44601..12b6348559 100644
--- a/arch/arm/src/stm32f7/stm32_sdmmc.h
+++ b/arch/arm/src/stm32f7/stm32_sdmmc.h
@@ -1,7 +1,7 @@
/************************************************************************************
- * arch/arm/src/stm32f7/stm32_sdio.h
+ * arch/arm/src/stm32f7/stm32_sdmmc.h
*
- * Copyright (C) 2009, 2011, 2015 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2009, 2011, 2016 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt
*
* Redistribution and use in source and binary forms, with or without
--
GitLab
From 47a5f81a63bb408f691550283c844bd6f86c0c83 Mon Sep 17 00:00:00 2001
From: Lok Tep
Date: Sat, 25 Jun 2016 17:55:33 +0200
Subject: [PATCH 008/734] mmc1
---
configs/stm32f746-ws/src/stm32_appinitialize.c | 2 ++
configs/stm32f746-ws/src/stm32_sdmmc.c | 2 +-
2 files changed, 3 insertions(+), 1 deletion(-)
diff --git a/configs/stm32f746-ws/src/stm32_appinitialize.c b/configs/stm32f746-ws/src/stm32_appinitialize.c
index 689bea75fe..0a58e61e36 100644
--- a/configs/stm32f746-ws/src/stm32_appinitialize.c
+++ b/configs/stm32f746-ws/src/stm32_appinitialize.c
@@ -100,6 +100,7 @@ int board_app_initialize(void)
}
#endif
+#ifdef CONFIG_STM32F7_SDMMC1
/* Initialize the SDIO block driver */
int ret = OK;
@@ -110,6 +111,7 @@ int board_app_initialize(void)
ferr("ERROR: Failed to initialize MMC/SD driver: %d\n", ret);
return ret;
}
+#endif
return OK;
}
diff --git a/configs/stm32f746-ws/src/stm32_sdmmc.c b/configs/stm32f746-ws/src/stm32_sdmmc.c
index bdbe7a7f65..4169d511a2 100644
--- a/configs/stm32f746-ws/src/stm32_sdmmc.c
+++ b/configs/stm32f746-ws/src/stm32_sdmmc.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * config/stm32f746-ws/src/stm32_sdio.c
+ * config/stm32f746-ws/src/stm32_sdmmc.c
*
* Copyright (C) 2014 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt
--
GitLab
From 2723de9a09a1a16d1135afef193308dd27a11cff Mon Sep 17 00:00:00 2001
From: Lok Tep
Date: Sat, 25 Jun 2016 18:31:37 +0200
Subject: [PATCH 009/734] usb ep 0-8
---
arch/arm/src/stm32f7/chip/stm32_otg.h | 148 ---------------------
arch/arm/src/stm32f7/stm32_otg.h | 6 +-
arch/arm/src/stm32f7/stm32_otgdev.c | 182 +++++++++++++++++++-------
configs/stm32f746-ws/nsh/defconfig | 56 ++++----
4 files changed, 170 insertions(+), 222 deletions(-)
diff --git a/arch/arm/src/stm32f7/chip/stm32_otg.h b/arch/arm/src/stm32f7/chip/stm32_otg.h
index ee06497102..474d063026 100644
--- a/arch/arm/src/stm32f7/chip/stm32_otg.h
+++ b/arch/arm/src/stm32f7/chip/stm32_otg.h
@@ -78,9 +78,6 @@
#define STM32_OTG_HPTXFSIZ_OFFSET 0x0100 /* Host periodic transmit FIFO size register */
#define STM32_OTG_DIEPTXF_OFFSET(n) (104+(((n)-1) << 2))
-#define STM32_OTG_DIEPTXF1_OFFSET 0x0104 /* Device IN endpoint transmit FIFO1 size register */
-#define STM32_OTG_DIEPTXF2_OFFSET 0x0108 /* Device IN endpoint transmit FIFO2 size register */
-#define STM32_OTG_DIEPTXF3_OFFSET 0x010c /* Device IN endpoint transmit FIFO3 size register */
/* Host-mode control and status registers */
@@ -99,44 +96,12 @@
#define STM32_OTG_HCTSIZ_CHOFFSET 0x0010 /* Host channel interrupt register */
#define STM32_OTG_HCCHAR_OFFSET(n) (0x500 + ((n) << 5))
-#define STM32_OTG_HCCHAR0_OFFSET 0x0500 /* Host channel-0 characteristics register */
-#define STM32_OTG_HCCHAR1_OFFSET 0x0520 /* Host channel-1 characteristics register */
-#define STM32_OTG_HCCHAR2_OFFSET 0x0540 /* Host channel-2 characteristics register */
-#define STM32_OTG_HCCHAR3_OFFSET 0x0560 /* Host channel-3 characteristics register */
-#define STM32_OTG_HCCHAR4_OFFSET 0x0580 /* Host channel-4 characteristics register */
-#define STM32_OTG_HCCHAR5_OFFSET 0x05a0 /* Host channel-5 characteristics register */
-#define STM32_OTG_HCCHAR6_OFFSET 0x05c0 /* Host channel-6 characteristics register */
-#define STM32_OTG_HCCHAR7_OFFSET 0x05e0 /* Host channel-7 characteristics register */
#define STM32_OTG_HCINT_OFFSET(n) (0x508 + ((n) << 5))
-#define STM32_OTG_HCINT0_OFFSET 0x0508 /* Host channel-0 interrupt register */
-#define STM32_OTG_HCINT1_OFFSET 0x0528 /* Host channel-1 interrupt register */
-#define STM32_OTG_HCINT2_OFFSET 0x0548 /* Host channel-2 interrupt register */
-#define STM32_OTG_HCINT3_OFFSET 0x0568 /* Host channel-3 interrupt register */
-#define STM32_OTG_HCINT4_OFFSET 0x0588 /* Host channel-4 interrupt register */
-#define STM32_OTG_HCINT5_OFFSET 0x05a8 /* Host channel-5 interrupt register */
-#define STM32_OTG_HCINT6_OFFSET 0x05c8 /* Host channel-6 interrupt register */
-#define STM32_OTG_HCINT7_OFFSET 0x05e8 /* Host channel-7 interrupt register */
#define STM32_OTG_HCINTMSK_OFFSET(n) (0x50c + ((n) << 5))
-#define STM32_OTG_HCINTMSK0_OFFSET 0x050c /* Host channel-0 interrupt mask register */
-#define STM32_OTG_HCINTMSK1_OFFSET 0x052c /* Host channel-1 interrupt mask register */
-#define STM32_OTG_HCINTMSK2_OFFSET 0x054c /* Host channel-2 interrupt mask register */
-#define STM32_OTG_HCINTMSK3_OFFSET 0x056c /* Host channel-3 interrupt mask register */
-#define STM32_OTG_HCINTMSK4_OFFSET 0x058c /* Host channel-4 interrupt mask register */
-#define STM32_OTG_HCINTMSK5_OFFSET 0x05ac /* Host channel-5 interrupt mask register */
-#define STM32_OTG_HCINTMSK6_OFFSET 0x05cc /* Host channel-6 interrupt mask register */
-#define STM32_OTG_HCINTMSK7_OFFSET 0x05ec /* Host channel-7 interrupt mask register */
#define STM32_OTG_HCTSIZ_OFFSET(n) (0x510 + ((n) << 5))
-#define STM32_OTG_HCTSIZ0_OFFSET 0x0510 /* Host channel-0 interrupt register */
-#define STM32_OTG_HCTSIZ1_OFFSET 0x0530 /* Host channel-1 interrupt register */
-#define STM32_OTG_HCTSIZ2_OFFSET 0x0550 /* Host channel-2 interrupt register */
-#define STM32_OTG_HCTSIZ3_OFFSET 0x0570 /* Host channel-3 interrupt register */
-#define STM32_OTG_HCTSIZ4_OFFSET 0x0590 /* Host channel-4 interrupt register */
-#define STM32_OTG_HCTSIZ5_OFFSET 0x05b0 /* Host channel-5 interrupt register */
-#define STM32_OTG_HCTSIZ6_OFFSET 0x05d0 /* Host channel-6 interrupt register */
-#define STM32_OTG_HCTSIZ7_OFFSET 0x05f0 /* Host channel-7 interrupt register */
/* Device-mode control and status registers */
@@ -158,50 +123,22 @@
#define STM32_OTG_DTXFSTS_EPOFFSET 0x0018 /* Device IN endpoint transmit FIFO status register */
#define STM32_OTG_DIEPCTL_OFFSET(n) (0x0900 + ((n) << 5))
-#define STM32_OTG_DIEPCTL0_OFFSET 0x0900 /* Device control IN endpoint 0 control register */
-#define STM32_OTG_DIEPCTL1_OFFSET 0x0920 /* Device control IN endpoint 2 control register */
-#define STM32_OTG_DIEPCTL2_OFFSET 0x0940 /* Device control IN endpoint 3 control register */
-#define STM32_OTG_DIEPCTL3_OFFSET 0x0960 /* Device control IN endpoint 4 control register */
#define STM32_OTG_DIEPINT_OFFSET(n) (0x0908 + ((n) << 5))
-#define STM32_OTG_DIEPINT0_OFFSET 0x0908 /* Device endpoint-0 interrupt register */
-#define STM32_OTG_DIEPINT1_OFFSET 0x0928 /* Device endpoint-1 interrupt register */
-#define STM32_OTG_DIEPINT2_OFFSET 0x0948 /* Device endpoint-2 interrupt register */
-#define STM32_OTG_DIEPINT3_OFFSET 0x0968 /* Device endpoint-3 interrupt register */
#define STM32_OTG_DIEPTSIZ_OFFSET(n) (0x910 + ((n) << 5))
-#define STM32_OTG_DIEPTSIZ0_OFFSET 0x0910 /* Device IN endpoint 0 transfer size register */
-#define STM32_OTG_DIEPTSIZ1_OFFSET 0x0930 /* Device IN endpoint 1 transfer size register */
-#define STM32_OTG_DIEPTSIZ2_OFFSET 0x0950 /* Device IN endpoint 2 transfer size register */
-#define STM32_OTG_DIEPTSIZ3_OFFSET 0x0970 /* Device IN endpoint 3 transfer size register */
#define STM32_OTG_DTXFSTS_OFFSET(n) (0x0918 + ((n) << 5))
-#define STM32_OTG_DTXFSTS0_OFFSET 0x0918 /* Device OUT endpoint-0 TxFIFO status register */
-#define STM32_OTG_DTXFSTS1_OFFSET 0x0938 /* Device OUT endpoint-1 TxFIFO status register */
-#define STM32_OTG_DTXFSTS2_OFFSET 0x0958 /* Device OUT endpoint-2 TxFIFO status register */
-#define STM32_OTG_DTXFSTS3_OFFSET 0x0978 /* Device OUT endpoint-3 TxFIFO status register */
#define STM32_OTG_DOEP_OFFSET(n) (0x0b00 + ((n) << 5))
#define STM32_OTG_DOEPCTL_EPOFFSET 0x0000 /* Device control OUT endpoint 0 control register */
#define STM32_OTG_DOEPINT_EPOFFSET 0x0008 /* Device endpoint-x interrupt register */
#define STM32_OTG_DOEPCTL_OFFSET(n) (0x0b00 + ((n) << 5))
-#define STM32_OTG_DOEPCTL0_OFFSET 0x00b00 /* Device OUT endpoint 0 control register */
-#define STM32_OTG_DOEPCTL1_OFFSET 0x00b20 /* Device OUT endpoint 1 control register */
-#define STM32_OTG_DOEPCTL2_OFFSET 0x00b40 /* Device OUT endpoint 2 control register */
-#define STM32_OTG_DOEPCTL3_OFFSET 0x00b60 /* Device OUT endpoint 3 control register */
#define STM32_OTG_DOEPINT_OFFSET(n) (0x0b08 + ((n) << 5))
-#define STM32_OTG_DOEPINT0_OFFSET 0x00b08 /* Device endpoint-0 interrupt register */
-#define STM32_OTG_DOEPINT1_OFFSET 0x00b28 /* Device endpoint-1 interrupt register */
-#define STM32_OTG_DOEPINT2_OFFSET 0x00b48 /* Device endpoint-2 interrupt register */
-#define STM32_OTG_DOEPINT3_OFFSET 0x00b68 /* Device endpoint-3 interrupt register */
#define STM32_OTG_DOEPTSIZ_OFFSET(n) (0x0b10 + ((n) << 5))
-#define STM32_OTG_DOEPTSIZ0_OFFSET 0x00b10 /* Device OUT endpoint-0 transfer size register */
-#define STM32_OTG_DOEPTSIZ1_OFFSET 0x00b30 /* Device OUT endpoint-1 transfer size register */
-#define STM32_OTG_DOEPTSIZ2_OFFSET 0x00b50 /* Device OUT endpoint-2 transfer size register */
-#define STM32_OTG_DOEPTSIZ3_OFFSET 0x00b70 /* Device OUT endpoint-3 transfer size register */
/* Power and clock gating registers */
@@ -212,17 +149,6 @@
#define STM32_OTG_DFIFO_DEP_OFFSET(n) (0x1000 + ((n) << 12))
#define STM32_OTG_DFIFO_HCH_OFFSET(n) (0x1000 + ((n) << 12))
-#define STM32_OTG_DFIFO_DEP0_OFFSET 0x1000 /* 0x1000-0x1ffc Device IN/OUT Endpoint 0 DFIFO Write/Read Access */
-#define STM32_OTG_DFIFO_HCH0_OFFSET 0x1000 /* 0x1000-0x1ffc Host OUT/IN Channel 0 DFIFO Read/Write Access */
-
-#define STM32_OTG_DFIFO_DEP1_OFFSET 0x2000 /* 0x2000-0x2ffc Device IN/OUT Endpoint 1 DFIFO Write/Read Access */
-#define STM32_OTG_DFIFO_HCH1_OFFSET 0x2000 /* 0x2000-0x2ffc Host OUT/IN Channel 1 DFIFO Read/Write Access */
-
-#define STM32_OTG_DFIFO_DEP2_OFFSET 0x3000 /* 0x3000-0x3ffc Device IN/OUT Endpoint 2 DFIFO Write/Read Access */
-#define STM32_OTG_DFIFO_HCH2_OFFSET 0x3000 /* 0x3000-0x3ffc Host OUT/IN Channel 2 DFIFO Read/Write Access */
-
-#define STM32_OTG_DFIFO_DEP3_OFFSET 0x4000 /* 0x4000-0x4ffc Device IN/OUT Endpoint 3 DFIFO Write/Read Access */
-#define STM32_OTG_DFIFO_HCH3_OFFSET 0x4000 /* 0x4000-0x4ffc Host OUT/IN Channel 3 DFIFO Read/Write Access */
/* Register Addresses *******************************************************************************/
@@ -244,9 +170,6 @@
#define STM32_OTG_HPTXFSIZ (STM32_OTG_BASE+STM32_OTG_HPTXFSIZ_OFFSET)
#define STM32_OTG_DIEPTXF(n) (STM32_OTG_BASE+STM32_OTG_DIEPTXF_OFFSET(n))
-#define STM32_OTG_DIEPTXF1 (STM32_OTG_BASE+STM32_OTG_DIEPTXF1_OFFSET)
-#define STM32_OTG_DIEPTXF2 (STM32_OTG_BASE+STM32_OTG_DIEPTXF2_OFFSET)
-#define STM32_OTG_DIEPTXF3 (STM32_OTG_BASE+STM32_OTG_DIEPTXF3_OFFSET)
/* Host-mode control and status registers */
@@ -261,44 +184,12 @@
#define STM32_OTG_CHAN(n) (STM32_OTG_BASE+STM32_OTG_CHAN_OFFSET(n))
#define STM32_OTG_HCCHAR(n) (STM32_OTG_BASE+STM32_OTG_HCCHAR_OFFSET(n))
-#define STM32_OTG_HCCHAR0 (STM32_OTG_BASE+STM32_OTG_HCCHAR0_OFFSET)
-#define STM32_OTG_HCCHAR1 (STM32_OTG_BASE+STM32_OTG_HCCHAR1_OFFSET)
-#define STM32_OTG_HCCHAR2 (STM32_OTG_BASE+STM32_OTG_HCCHAR2_OFFSET)
-#define STM32_OTG_HCCHAR3 (STM32_OTG_BASE+STM32_OTG_HCCHAR3_OFFSET)
-#define STM32_OTG_HCCHAR4 (STM32_OTG_BASE+STM32_OTG_HCCHAR4_OFFSET)
-#define STM32_OTG_HCCHAR5 (STM32_OTG_BASE+STM32_OTG_HCCHAR5_OFFSET)
-#define STM32_OTG_HCCHAR6 (STM32_OTG_BASE+STM32_OTG_HCCHAR6_OFFSET)
-#define STM32_OTG_HCCHAR7 (STM32_OTG_BASE+STM32_OTG_HCCHAR7_OFFSET)
#define STM32_OTG_HCINT(n) (STM32_OTG_BASE+STM32_OTG_HCINT_OFFSET(n))
-#define STM32_OTG_HCINT0 (STM32_OTG_BASE+STM32_OTG_HCINT0_OFFSET)
-#define STM32_OTG_HCINT1 (STM32_OTG_BASE+STM32_OTG_HCINT1_OFFSET)
-#define STM32_OTG_HCINT2 (STM32_OTG_BASE+STM32_OTG_HCINT2_OFFSET)
-#define STM32_OTG_HCINT3 (STM32_OTG_BASE+STM32_OTG_HCINT3_OFFSET)
-#define STM32_OTG_HCINT4 (STM32_OTG_BASE+STM32_OTG_HCINT4_OFFSET)
-#define STM32_OTG_HCINT5 (STM32_OTG_BASE+STM32_OTG_HCINT5_OFFSET)
-#define STM32_OTG_HCINT6 (STM32_OTG_BASE+STM32_OTG_HCINT6_OFFSET)
-#define STM32_OTG_HCINT7 (STM32_OTG_BASE+STM32_OTG_HCINT7_OFFSET)
#define STM32_OTG_HCINTMSK(n) (STM32_OTG_BASE+STM32_OTG_HCINTMSK_OFFSET(n))
-#define STM32_OTG_HCINTMSK0 (STM32_OTG_BASE+STM32_OTG_HCINTMSK0_OFFSET)
-#define STM32_OTG_HCINTMSK1 (STM32_OTG_BASE+STM32_OTG_HCINTMSK1_OFFSET)
-#define STM32_OTG_HCINTMSK2 (STM32_OTG_BASE+STM32_OTG_HCINTMSK2_OFFSET)
-#define STM32_OTG_HCINTMSK3 (STM32_OTG_BASE+STM32_OTG_HCINTMSK3_OFFSET)
-#define STM32_OTG_HCINTMSK4 (STM32_OTG_BASE+STM32_OTG_HCINTMSK4_OFFSET)
-#define STM32_OTG_HCINTMSK5 (STM32_OTG_BASE+STM32_OTG_HCINTMSK5_OFFSET)
-#define STM32_OTG_HCINTMSK6 (STM32_OTG_BASE+STM32_OTG_HCINTMSK6_OFFSET)
-#define STM32_OTG_HCINTMSK7 (STM32_OTG_BASE+STM32_OTG_HCINTMSK7_OFFSET)_
#define STM32_OTG_HCTSIZ(n) (STM32_OTG_BASE+STM32_OTG_HCTSIZ_OFFSET(n))
-#define STM32_OTG_HCTSIZ0 (STM32_OTG_BASE+STM32_OTG_HCTSIZ0_OFFSET)
-#define STM32_OTG_HCTSIZ1 (STM32_OTG_BASE+STM32_OTG_HCTSIZ1_OFFSET)
-#define STM32_OTG_HCTSIZ2 (STM32_OTG_BASE+STM32_OTG_HCTSIZ2_OFFSET)
-#define STM32_OTG_HCTSIZ3 (STM32_OTG_BASE+STM32_OTG_HCTSIZ3_OFFSET)
-#define STM32_OTG_HCTSIZ4 (STM32_OTG_BASE+STM32_OTG_HCTSIZ4_OFFSET)
-#define STM32_OTG_HCTSIZ5 (STM32_OTG_BASE+STM32_OTG_HCTSIZ5_OFFSET)
-#define STM32_OTG_HCTSIZ6 (STM32_OTG_BASE+STM32_OTG_HCTSIZ6_OFFSET)
-#define STM32_OTG_HCTSIZ7 (STM32_OTG_BASE+STM32_OTG_HCTSIZ7_OFFSET)
/* Device-mode control and status registers */
@@ -316,48 +207,20 @@
#define STM32_OTG_DIEP(n) (STM32_OTG_BASE+STM32_OTG_DIEP_OFFSET(n))
#define STM32_OTG_DIEPCTL(n) (STM32_OTG_BASE+STM32_OTG_DIEPCTL_OFFSET(n))
-#define STM32_OTG_DIEPCTL0 (STM32_OTG_BASE+STM32_OTG_DIEPCTL0_OFFSET)
-#define STM32_OTG_DIEPCTL1 (STM32_OTG_BASE+STM32_OTG_DIEPCTL1_OFFSET)
-#define STM32_OTG_DIEPCTL2 (STM32_OTG_BASE+STM32_OTG_DIEPCTL2_OFFSET)
-#define STM32_OTG_DIEPCTL3 (STM32_OTG_BASE+STM32_OTG_DIEPCTL3_OFFSET)
#define STM32_OTG_DIEPINT(n) (STM32_OTG_BASE+STM32_OTG_DIEPINT_OFFSET(n))
-#define STM32_OTG_DIEPINT0 (STM32_OTG_BASE+STM32_OTG_DIEPINT0_OFFSET)
-#define STM32_OTG_DIEPINT1 (STM32_OTG_BASE+STM32_OTG_DIEPINT1_OFFSET)
-#define STM32_OTG_DIEPINT2 (STM32_OTG_BASE+STM32_OTG_DIEPINT2_OFFSET)
-#define STM32_OTG_DIEPINT3 (STM32_OTG_BASE+STM32_OTG_DIEPINT3_OFFSET)
#define STM32_OTG_DIEPTSIZ(n) (STM32_OTG_BASE+STM32_OTG_DIEPTSIZ_OFFSET(n))
-#define STM32_OTG_DIEPTSIZ0 (STM32_OTG_BASE+STM32_OTG_DIEPTSIZ0_OFFSET)
-#define STM32_OTG_DIEPTSIZ1 (STM32_OTG_BASE+STM32_OTG_DIEPTSIZ1_OFFSET)
-#define STM32_OTG_DIEPTSIZ2 (STM32_OTG_BASE+STM32_OTG_DIEPTSIZ2_OFFSET)
-#define STM32_OTG_DIEPTSIZ3 (STM32_OTG_BASE+STM32_OTG_DIEPTSIZ3_OFFSET)
#define STM32_OTG_DTXFSTS(n) (STM32_OTG_BASE+STM32_OTG_DTXFSTS_OFFSET(n))
-#define STM32_OTG_DTXFSTS0 (STM32_OTG_BASE+STM32_OTG_DTXFSTS0_OFFSET)
-#define STM32_OTG_DTXFSTS1 (STM32_OTG_BASE+STM32_OTG_DTXFSTS1_OFFSET)
-#define STM32_OTG_DTXFSTS2 (STM32_OTG_BASE+STM32_OTG_DTXFSTS2_OFFSET)
-#define STM32_OTG_DTXFSTS3 (STM32_OTG_BASE+STM32_OTG_DTXFSTS3_OFFSET)
#define STM32_OTG_DOEP(n) (STM32_OTG_BASE+STM32_OTG_DOEP_OFFSET(n))
#define STM32_OTG_DOEPCTL(n) (STM32_OTG_BASE+STM32_OTG_DOEPCTL_OFFSET(n))
-#define STM32_OTG_DOEPCTL0 (STM32_OTG_BASE+STM32_OTG_DOEPCTL0_OFFSET)
-#define STM32_OTG_DOEPCTL1 (STM32_OTG_BASE+STM32_OTG_DOEPCTL1_OFFSET)
-#define STM32_OTG_DOEPCTL2 (STM32_OTG_BASE+STM32_OTG_DOEPCTL2_OFFSET)
-#define STM32_OTG_DOEPCTL3 (STM32_OTG_BASE+STM32_OTG_DOEPCTL3_OFFSET)
#define STM32_OTG_DOEPINT(n) (STM32_OTG_BASE+STM32_OTG_DOEPINT_OFFSET(n))
-#define STM32_OTG_DOEPINT0 (STM32_OTG_BASE+STM32_OTG_DOEPINT0_OFFSET)
-#define STM32_OTG_DOEPINT1 (STM32_OTG_BASE+STM32_OTG_DOEPINT1_OFFSET)
-#define STM32_OTG_DOEPINT2 (STM32_OTG_BASE+STM32_OTG_DOEPINT2_OFFSET)
-#define STM32_OTG_DOEPINT3 (STM32_OTG_BASE+STM32_OTG_DOEPINT3_OFFSET)
#define STM32_OTG_DOEPTSIZ(n) (STM32_OTG_BASE+STM32_OTG_DOEPTSIZ_OFFSET(n))
-#define STM32_OTG_DOEPTSIZ0 (STM32_OTG_BASE+STM32_OTG_DOEPTSIZ0_OFFSET)
-#define STM32_OTG_DOEPTSIZ1 (STM32_OTG_BASE+STM32_OTG_DOEPTSIZ1_OFFSET)
-#define STM32_OTG_DOEPTSIZ2 (STM32_OTG_BASE+STM32_OTG_DOEPTSIZ2_OFFSET)
-#define STM32_OTG_DOEPTSIZ3 (STM32_OTG_BASE+STM32_OTG_DOEPTSIZ3_OFFSET)
/* Power and clock gating registers */
@@ -368,17 +231,6 @@
#define STM32_OTG_DFIFO_DEP(n) (STM32_OTG_BASE+STM32_OTG_DFIFO_DEP_OFFSET(n))
#define STM32_OTG_DFIFO_HCH(n) (STM32_OTG_BASE+STM32_OTG_DFIFO_HCH_OFFSET(n))
-#define STM32_OTG_DFIFO_DEP0 (STM32_OTG_BASE+STM32_OTG_DFIFO_DEP0_OFFSET)
-#define STM32_OTG_DFIFO_HCH0 (STM32_OTG_BASE+STM32_OTG_DFIFO_HCH0_OFFSET)
-
-#define STM32_OTG_DFIFO_DEP1 (STM32_OTG_BASE+STM32_OTG_DFIFO_DEP1_OFFSET)
-#define STM32_OTG_DFIFO_HCH1 (STM32_OTG_BASE+STM32_OTG_DFIFO_HCH1_OFFSET)
-
-#define STM32_OTG_DFIFO_DEP2 (STM32_OTG_BASE+STM32_OTG_DFIFO_DEP2_OFFSET)
-#define STM32_OTG_DFIFO_HCH2 (STM32_OTG_BASE+STM32_OTG_DFIFO_HCH2_OFFSET)
-
-#define STM32_OTG_DFIFO_DEP3 (STM32_OTG_BASE+STM32_OTG_DFIFO_DEP3_OFFSET)
-#define STM32_OTG_DFIFO_HCH3 (STM32_OTG_BASE+STM32_OTG_DFIFO_HCH3_OFFSET)
/* Register Bitfield Definitions ********************************************************************/
/* Core global control and status registers */
diff --git a/arch/arm/src/stm32f7/stm32_otg.h b/arch/arm/src/stm32f7/stm32_otg.h
index 0bb6b9b393..3c60683ea3 100644
--- a/arch/arm/src/stm32f7/stm32_otg.h
+++ b/arch/arm/src/stm32f7/stm32_otg.h
@@ -66,18 +66,18 @@
# define GPIO_OTG_DP GPIO_OTGFS_DP
# define GPIO_OTG_ID GPIO_OTGFS_ID
# define GPIO_OTG_SOF GPIO_OTGFS_SOF
-
+# define STM32_OTG_FIFO_SIZE 1280
#endif
#if defined(CONFIG_STM32F7_OTGHS)
# define STM32_IRQ_OTG STM32_IRQ_OTGHS
# define STM32_OTG_BASE STM32_USBOTGHS_BASE
-# define STM32_NENDPOINTS (8) /* ep0-7 x 2 for IN and OUT */
+# define STM32_NENDPOINTS (7) /* ep0-8 x 2 for IN and OUT but driver internals use byte to map + one bit for direction */
# define GPIO_OTG_DM GPIO_OTGHS_DM
# define GPIO_OTG_DP GPIO_OTGHS_DP
# define GPIO_OTG_ID GPIO_OTGHS_ID
# define GPIO_OTG_SOF GPIO_OTGHS_SOF
-
+# define STM32_OTG_FIFO_SIZE 4096
#endif
/************************************************************************************
diff --git a/arch/arm/src/stm32f7/stm32_otgdev.c b/arch/arm/src/stm32f7/stm32_otgdev.c
index d4d46c4efb..7b9db010ad 100644
--- a/arch/arm/src/stm32f7/stm32_otgdev.c
+++ b/arch/arm/src/stm32f7/stm32_otgdev.c
@@ -89,30 +89,82 @@
*/
#ifndef CONFIG_USBDEV_RXFIFO_SIZE
-# define CONFIG_USBDEV_RXFIFO_SIZE 512
+# define CONFIG_USBDEV_RXFIFO_SIZE (STM32_OTG_FIFO_SIZE - STM32_OTG_FIFO_SIZE/4/2/STM32_NENDPOINTS*4*STM32_NENDPOINTS)
#endif
-#ifndef CONFIG_USBDEV_EP0_TXFIFO_SIZE
-# define CONFIG_USBDEV_EP0_TXFIFO_SIZE 192
+#if STM32_NENDPOINTS > 0
+# ifndef CONFIG_USBDEV_EP0_TXFIFO_SIZE
+# define CONFIG_USBDEV_EP0_TXFIFO_SIZE ((STM32_OTG_FIFO_SIZE - CONFIG_USBDEV_RXFIFO_SIZE)/STM32_NENDPOINTS)
+# endif
+#else
+# define CONFIG_USBDEV_EP0_TXFIFO_SIZE 0
#endif
-#ifndef CONFIG_USBDEV_EP1_TXFIFO_SIZE
-# define CONFIG_USBDEV_EP1_TXFIFO_SIZE 192
+#if STM32_NENDPOINTS > 1
+# ifndef CONFIG_USBDEV_EP1_TXFIFO_SIZE
+# define CONFIG_USBDEV_EP1_TXFIFO_SIZE ((STM32_OTG_FIFO_SIZE - CONFIG_USBDEV_RXFIFO_SIZE)/STM32_NENDPOINTS)
+# endif
+#else
+# define CONFIG_USBDEV_EP1_TXFIFO_SIZE 0
#endif
-#ifndef CONFIG_USBDEV_EP2_TXFIFO_SIZE
-# define CONFIG_USBDEV_EP2_TXFIFO_SIZE 192
+#if STM32_NENDPOINTS > 2
+# ifndef CONFIG_USBDEV_EP2_TXFIFO_SIZE
+# define CONFIG_USBDEV_EP2_TXFIFO_SIZE ((STM32_OTG_FIFO_SIZE - CONFIG_USBDEV_RXFIFO_SIZE)/STM32_NENDPOINTS)
+# endif
+#else
+# define CONFIG_USBDEV_EP2_TXFIFO_SIZE 0
#endif
-#ifndef CONFIG_USBDEV_EP3_TXFIFO_SIZE
-# define CONFIG_USBDEV_EP3_TXFIFO_SIZE 192
+#if STM32_NENDPOINTS > 3
+# ifndef CONFIG_USBDEV_EP3_TXFIFO_SIZE
+# define CONFIG_USBDEV_EP3_TXFIFO_SIZE ((STM32_OTG_FIFO_SIZE - CONFIG_USBDEV_RXFIFO_SIZE)/STM32_NENDPOINTS)
+# endif
+#else
+# define CONFIG_USBDEV_EP3_TXFIFO_SIZE 0
#endif
-#if (CONFIG_USBDEV_RXFIFO_SIZE + CONFIG_USBDEV_EP0_TXFIFO_SIZE + \
- CONFIG_USBDEV_EP2_TXFIFO_SIZE + CONFIG_USBDEV_EP3_TXFIFO_SIZE) > 1280
-# error "FIFO allocations exceed FIFO memory size"
+#if STM32_NENDPOINTS > 4
+# ifndef CONFIG_USBDEV_EP4_TXFIFO_SIZE
+# define CONFIG_USBDEV_EP4_TXFIFO_SIZE ((STM32_OTG_FIFO_SIZE - CONFIG_USBDEV_RXFIFO_SIZE)/STM32_NENDPOINTS)
+# endif
+#else
+# define CONFIG_USBDEV_EP4_TXFIFO_SIZE 0
+#endif
+
+#if STM32_NENDPOINTS > 5
+# ifndef CONFIG_USBDEV_EP5_TXFIFO_SIZE
+# define CONFIG_USBDEV_EP5_TXFIFO_SIZE ((STM32_OTG_FIFO_SIZE - CONFIG_USBDEV_RXFIFO_SIZE)/STM32_NENDPOINTS)
+# endif
+#else
+# define CONFIG_USBDEV_EP5_TXFIFO_SIZE 0
+#endif
+
+#if STM32_NENDPOINTS > 6
+# ifndef CONFIG_USBDEV_EP6_TXFIFO_SIZE
+# define CONFIG_USBDEV_EP6_TXFIFO_SIZE ((STM32_OTG_FIFO_SIZE - CONFIG_USBDEV_RXFIFO_SIZE)/STM32_NENDPOINTS)
+# endif
+#else
+# define CONFIG_USBDEV_EP6_TXFIFO_SIZE 0
+#endif
+
+#if STM32_NENDPOINTS > 7
+# ifndef CONFIG_USBDEV_EP7_TXFIFO_SIZE
+# define CONFIG_USBDEV_EP7_TXFIFO_SIZE ((STM32_OTG_FIFO_SIZE - CONFIG_USBDEV_RXFIFO_SIZE)/STM32_NENDPOINTS)
+# endif
+#else
+# define CONFIG_USBDEV_EP7_TXFIFO_SIZE 0
+#endif
+
+#if STM32_NENDPOINTS > 8
+# ifndef CONFIG_USBDEV_EP8_TXFIFO_SIZE
+# define CONFIG_USBDEV_EP8_TXFIFO_SIZE ((STM32_OTG_FIFO_SIZE - CONFIG_USBDEV_RXFIFO_SIZE)/STM32_NENDPOINTS)
+# endif
+#else
+# define CONFIG_USBDEV_EP8_TXFIFO_SIZE 0
#endif
+
/* The actual FIFO addresses that we use must be aligned to 4-byte boundaries;
* FIFO sizes must be provided in units of 32-bit words.
*/
@@ -123,29 +175,36 @@
#define STM32_EP0_TXFIFO_BYTES ((CONFIG_USBDEV_EP0_TXFIFO_SIZE + 3) & ~3)
#define STM32_EP0_TXFIFO_WORDS ((CONFIG_USBDEV_EP0_TXFIFO_SIZE + 3) >> 2)
-#if STM32_EP0_TXFIFO_WORDS < 16 || STM32_EP0_TXFIFO_WORDS > 256
-# error "CONFIG_USBDEV_EP0_TXFIFO_SIZE is out of range"
-#endif
-
#define STM32_EP1_TXFIFO_BYTES ((CONFIG_USBDEV_EP1_TXFIFO_SIZE + 3) & ~3)
#define STM32_EP1_TXFIFO_WORDS ((CONFIG_USBDEV_EP1_TXFIFO_SIZE + 3) >> 2)
-#if STM32_EP1_TXFIFO_WORDS < 16
-# error "CONFIG_USBDEV_EP1_TXFIFO_SIZE is out of range"
-#endif
-
#define STM32_EP2_TXFIFO_BYTES ((CONFIG_USBDEV_EP2_TXFIFO_SIZE + 3) & ~3)
#define STM32_EP2_TXFIFO_WORDS ((CONFIG_USBDEV_EP2_TXFIFO_SIZE + 3) >> 2)
-#if STM32_EP2_TXFIFO_WORDS < 16
-# error "CONFIG_USBDEV_EP2_TXFIFO_SIZE is out of range"
-#endif
-
#define STM32_EP3_TXFIFO_BYTES ((CONFIG_USBDEV_EP3_TXFIFO_SIZE + 3) & ~3)
#define STM32_EP3_TXFIFO_WORDS ((CONFIG_USBDEV_EP3_TXFIFO_SIZE + 3) >> 2)
-#if STM32_EP3_TXFIFO_WORDS < 16
-# error "CONFIG_USBDEV_EP3_TXFIFO_SIZE is out of range"
+#define STM32_EP4_TXFIFO_BYTES ((CONFIG_USBDEV_EP4_TXFIFO_SIZE + 3) & ~3)
+#define STM32_EP4_TXFIFO_WORDS ((CONFIG_USBDEV_EP4_TXFIFO_SIZE + 3) >> 2)
+
+#define STM32_EP5_TXFIFO_BYTES ((CONFIG_USBDEV_EP5_TXFIFO_SIZE + 3) & ~3)
+#define STM32_EP5_TXFIFO_WORDS ((CONFIG_USBDEV_EP5_TXFIFO_SIZE + 3) >> 2)
+
+#define STM32_EP6_TXFIFO_BYTES ((CONFIG_USBDEV_EP6_TXFIFO_SIZE + 3) & ~3)
+#define STM32_EP6_TXFIFO_WORDS ((CONFIG_USBDEV_EP6_TXFIFO_SIZE + 3) >> 2)
+
+#define STM32_EP7_TXFIFO_BYTES ((CONFIG_USBDEV_EP7_TXFIFO_SIZE + 3) & ~3)
+#define STM32_EP7_TXFIFO_WORDS ((CONFIG_USBDEV_EP7_TXFIFO_SIZE + 3) >> 2)
+
+#define STM32_EP8_TXFIFO_BYTES ((CONFIG_USBDEV_EP8_TXFIFO_SIZE + 3) & ~3)
+#define STM32_EP8_TXFIFO_WORDS ((CONFIG_USBDEV_EP8_TXFIFO_SIZE + 3) >> 2)
+
+
+#if (STM32_RXFIFO_BYTES + \
+ STM32_EP0_TXFIFO_BYTES + STM32_EP1_TXFIFO_BYTES + STM32_EP2_TXFIFO_BYTES + STM32_EP3_TXFIFO_BYTES + \
+ STM32_EP4_TXFIFO_BYTES + STM32_EP5_TXFIFO_BYTES + STM32_EP6_TXFIFO_BYTES + STM32_EP7_TXFIFO_BYTES + CONFIG_USBDEV_EP8_TXFIFO_SIZE \
+ ) > STM32_OTG_FIFO_SIZE
+# error "FIFO allocations exceed FIFO memory size"
#endif
/* Debug ***********************************************************************/
@@ -962,7 +1021,7 @@ static void stm32_ep0in_activate(void)
/* Set the max packet size of the IN EP. */
- regval = stm32_getreg(STM32_OTG_DIEPCTL0);
+ regval = stm32_getreg(STM32_OTG_DIEPCTL(0));
regval &= ~OTG_DIEPCTL0_MPSIZ_MASK;
#if CONFIG_USBDEV_EP0_MAXSIZE == 8
@@ -977,7 +1036,7 @@ static void stm32_ep0in_activate(void)
# error "Unsupported value of CONFIG_USBDEV_EP0_MAXSIZE"
#endif
- stm32_putreg(regval, STM32_OTG_DIEPCTL0);
+ stm32_putreg(regval, STM32_OTG_DIEPCTL(0));
/* Clear global IN NAK */
@@ -1003,13 +1062,13 @@ static void stm32_ep0out_ctrlsetup(FAR struct stm32_usbdev_s *priv)
regval = (USB_SIZEOF_CTRLREQ * 3 << OTG_DOEPTSIZ0_XFRSIZ_SHIFT) |
(OTG_DOEPTSIZ0_PKTCNT) |
(3 << OTG_DOEPTSIZ0_STUPCNT_SHIFT);
- stm32_putreg(regval, STM32_OTG_DOEPTSIZ0);
+ stm32_putreg(regval, STM32_OTG_DOEPTSIZ(0));
/* Then clear NAKing and enable the transfer */
- regval = stm32_getreg(STM32_OTG_DOEPCTL0);
+ regval = stm32_getreg(STM32_OTG_DOEPCTL(0));
regval |= (OTG_DOEPCTL0_CNAK | OTG_DOEPCTL0_EPENA);
- stm32_putreg(regval, STM32_OTG_DOEPCTL0);
+ stm32_putreg(regval, STM32_OTG_DOEPCTL(0));
}
/****************************************************************************
@@ -3227,9 +3286,9 @@ static inline void stm32_rxinterrupt(FAR struct stm32_usbdev_s *priv)
{
/* Clear NAKSTS so that we can receive the data */
- regval = stm32_getreg(STM32_OTG_DOEPCTL0);
+ regval = stm32_getreg(STM32_OTG_DOEPCTL(0));
regval |= OTG_DOEPCTL0_CNAK;
- stm32_putreg(regval, STM32_OTG_DOEPCTL0);
+ stm32_putreg(regval, STM32_OTG_DOEPCTL(0));
/* Wait for the data phase. */
@@ -5235,33 +5294,68 @@ static void stm32_hwinitialize(FAR struct stm32_usbdev_s *priv)
stm32_putreg(STM32_RXFIFO_WORDS, STM32_OTG_GRXFSIZ);
- /* EP0 TX */
-
+#if STM32_NENDPOINTS > 0
address = STM32_RXFIFO_WORDS;
regval = (address << OTG_DIEPTXF0_TX0FD_SHIFT) |
(STM32_EP0_TXFIFO_WORDS << OTG_DIEPTXF0_TX0FSA_SHIFT);
stm32_putreg(regval, STM32_OTG_DIEPTXF0);
+#endif
- /* EP1 TX */
-
+#if STM32_NENDPOINTS > 1
address += STM32_EP0_TXFIFO_WORDS;
regval = (address << OTG_DIEPTXF_INEPTXSA_SHIFT) |
(STM32_EP1_TXFIFO_WORDS << OTG_DIEPTXF_INEPTXFD_SHIFT);
- stm32_putreg(regval, STM32_OTG_DIEPTXF1);
-
- /* EP2 TX */
+ stm32_putreg(regval, STM32_OTG_DIEPTXF(1));
+#endif
+#if STM32_NENDPOINTS > 2
address += STM32_EP1_TXFIFO_WORDS;
regval = (address << OTG_DIEPTXF_INEPTXSA_SHIFT) |
(STM32_EP2_TXFIFO_WORDS << OTG_DIEPTXF_INEPTXFD_SHIFT);
- stm32_putreg(regval, STM32_OTG_DIEPTXF2);
-
- /* EP3 TX */
+ stm32_putreg(regval, STM32_OTG_DIEPTXF(2));
+#endif
+#if STM32_NENDPOINTS > 3
address += STM32_EP2_TXFIFO_WORDS;
regval = (address << OTG_DIEPTXF_INEPTXSA_SHIFT) |
(STM32_EP3_TXFIFO_WORDS << OTG_DIEPTXF_INEPTXFD_SHIFT);
- stm32_putreg(regval, STM32_OTG_DIEPTXF3);
+ stm32_putreg(regval, STM32_OTG_DIEPTXF(3));
+#endif
+
+#if STM32_NENDPOINTS > 4
+ address += STM32_EP3_TXFIFO_WORDS;
+ regval = (address << OTG_DIEPTXF_INEPTXSA_SHIFT) |
+ (STM32_EP4_TXFIFO_WORDS << OTG_DIEPTXF_INEPTXFD_SHIFT);
+ stm32_putreg(regval, STM32_OTG_DIEPTXF(4));
+#endif
+
+#if STM32_NENDPOINTS > 5
+ address += STM32_EP4_TXFIFO_WORDS;
+ regval = (address << OTG_DIEPTXF_INEPTXSA_SHIFT) |
+ (STM32_EP5_TXFIFO_WORDS << OTG_DIEPTXF_INEPTXFD_SHIFT);
+ stm32_putreg(regval, STM32_OTG_DIEPTXF(5));
+#endif
+
+#if STM32_NENDPOINTS > 6
+ address += STM32_EP5_TXFIFO_WORDS;
+ regval = (address << OTG_DIEPTXF_INEPTXSA_SHIFT) |
+ (STM32_EP6_TXFIFO_WORDS << OTG_DIEPTXF_INEPTXFD_SHIFT);
+ stm32_putreg(regval, STM32_OTG_DIEPTXF(6));
+#endif
+
+#if STM32_NENDPOINTS > 7
+ address += STM32_EP6_TXFIFO_WORDS;
+ regval = (address << OTG_DIEPTXF_INEPTXSA_SHIFT) |
+ (STM32_EP7_TXFIFO_WORDS << OTG_DIEPTXF_INEPTXFD_SHIFT);
+ stm32_putreg(regval, STM32_OTG_DIEPTXF(7));
+#endif
+
+#if STM32_NENDPOINTS > 8
+ address += STM32_EP7_TXFIFO_WORDS;
+ regval = (address << OTG_DIEPTXF_INEPTXSA_SHIFT) |
+ (STM32_EP8_TXFIFO_WORDS << OTG_DIEPTXF_INEPTXFD_SHIFT);
+ stm32_putreg(regval, STM32_OTG_DIEPTXF(8));
+#endif
/* Flush the FIFOs */
diff --git a/configs/stm32f746-ws/nsh/defconfig b/configs/stm32f746-ws/nsh/defconfig
index 44a25aec95..653cccf1e6 100644
--- a/configs/stm32f746-ws/nsh/defconfig
+++ b/configs/stm32f746-ws/nsh/defconfig
@@ -300,13 +300,13 @@ CONFIG_STM32F7_I2C1=y
# CONFIG_STM32F7_I2C3 is not set
# CONFIG_STM32F7_LPTIM1 is not set
# CONFIG_STM32F7_LTDC is not set
-##CONFIG_STM32F7_OTGFS=y
+CONFIG_STM32F7_OTGFS=y
# CONFIG_STM32F7_OTGHS is not set
# CONFIG_STM32F7_QUADSPI is not set
# CONFIG_STM32F7_RNG is not set
# CONFIG_STM32F7_SAI1 is not set
# CONFIG_STM32F7_SAI2 is not set
-CONFIG_STM32F7_SDMMC1=y
+##CONFIG_STM32F7_SDMMC1=y
# CONFIG_STM32F7_SPDIFRX is not set
CONFIG_STM32F7_SPI1=y
# CONFIG_STM32F7_SPI2 is not set
@@ -434,7 +434,7 @@ CONFIG_LIB_BOARDCTL=y
# CONFIG_BOARDCTL_PWMTEST is not set
# CONFIG_BOARDCTL_GRAPHICS is not set
# CONFIG_BOARDCTL_IOCTL is not set
-##CONFIG_BOARDCTL_USBDEVCTRL=y
+CONFIG_BOARDCTL_USBDEVCTRL=y
#
# RTOS Features
@@ -690,7 +690,7 @@ CONFIG_USART6_2STOP=0
# CONFIG_USART6_IFLOWCONTROL is not set
# CONFIG_USART6_OFLOWCONTROL is not set
# CONFIG_USART6_DMA is not set
-##CONFIG_USBDEV=y
+CONFIG_USBDEV=y
# CONFIG_USBHOST is not set
# CONFIG_DRIVERS_WIRELESS is not set
@@ -700,9 +700,9 @@ CONFIG_USART6_2STOP=0
#
# CONFIG_USBDEV_ISOCHRONOUS is not set
# CONFIG_USBDEV_DUALSPEED is not set
-##CONFIG_USBDEV_SELFPOWERED=y
+CONFIG_USBDEV_SELFPOWERED=y
# CONFIG_USBDEV_BUSPOWERED is not set
-##CONFIG_USBDEV_MAXPOWER=100
+CONFIG_USBDEV_MAXPOWER=100
# CONFIG_USBDEV_DMA is not set
# CONFIG_ARCH_USBDEV_STALLQUEUE is not set
# CONFIG_USBDEV_TRACE is not set
@@ -712,27 +712,26 @@ CONFIG_USART6_2STOP=0
#
# CONFIG_USBDEV_COMPOSITE is not set
# CONFIG_PL2303 is not set
-##CONFIG_CDCACM=y
-##CONFIG_CDCACM_CONSOLE=y
-##CONFIG_CDCACM_EP0MAXPACKET=64
-##CONFIG_CDCACM_EPINTIN=1
-##CONFIG_CDCACM_EPINTIN_FSSIZE=64
-##CONFIG_CDCACM_EPINTIN_HSSIZE=64
-##CONFIG_CDCACM_EPBULKOUT=3
-##CONFIG_CDCACM_EPBULKOUT_FSSIZE=64
-##CONFIG_CDCACM_EPBULKOUT_HSSIZE=512
-##CONFIG_CDCACM_EPBULKIN=2
-##CONFIG_CDCACM_EPBULKIN_FSSIZE=64
-##CONFIG_CDCACM_EPBULKIN_HSSIZE=512
-##CONFIG_CDCACM_NRDREQS=4
-##CONFIG_CDCACM_NWRREQS=4
-##CONFIG_CDCACM_BULKIN_REQLEN=96
-##CONFIG_CDCACM_RXBUFSIZE=256
-##CONFIG_CDCACM_TXBUFSIZE=256
-##CONFIG_CDCACM_VENDORID=0x0525
-##CONFIG_CDCACM_PRODUCTID=0xa4a7
-##CONFIG_CDCACM_VENDORSTR="NuttX"
-##CONFIG_CDCACM_PRODUCTSTR="CDC/ACM Serial"
+CONFIG_CDCACM=y
+CONFIG_CDCACM_EP0MAXPACKET=64
+CONFIG_CDCACM_EPINTIN=1
+CONFIG_CDCACM_EPINTIN_FSSIZE=64
+CONFIG_CDCACM_EPINTIN_HSSIZE=64
+CONFIG_CDCACM_EPBULKOUT=2
+CONFIG_CDCACM_EPBULKOUT_FSSIZE=64
+CONFIG_CDCACM_EPBULKOUT_HSSIZE=512
+CONFIG_CDCACM_EPBULKIN=2
+CONFIG_CDCACM_EPBULKIN_FSSIZE=64
+CONFIG_CDCACM_EPBULKIN_HSSIZE=512
+CONFIG_CDCACM_NRDREQS=4
+CONFIG_CDCACM_NWRREQS=4
+CONFIG_CDCACM_BULKIN_REQLEN=96
+CONFIG_CDCACM_RXBUFSIZE=256
+CONFIG_CDCACM_TXBUFSIZE=256
+CONFIG_CDCACM_VENDORID=0x03EB
+CONFIG_CDCACM_PRODUCTID=0x2044
+CONFIG_CDCACM_VENDORSTR="NuttX"
+CONFIG_CDCACM_PRODUCTSTR="CDC/ACM Serial"
# CONFIG_USBMSC is not set
# CONFIG_USBHOST is not set
# CONFIG_DRIVERS_WIRELESS is not set
@@ -1128,3 +1127,6 @@ CONFIG_READLINE_ECHO=y
# CONFIG_SYSTEM_UBLOXMODEM is not set
# CONFIG_SYSTEM_VI is not set
# CONFIG_SYSTEM_ZMODEM is not set
+
+CONFIG_SYSTEM_CDCACM=y
+CONFIG_SYSTEM_CDCACM_DEVMINOR=0
--
GitLab
From 1905cb94a09d9f1d7cb8e247691382f817277c00 Mon Sep 17 00:00:00 2001
From: Lok Tep
Date: Tue, 27 Sep 2016 16:43:41 +0200
Subject: [PATCH 010/734] to uinfo
---
configs/stm32f746-ws/src/stm32_usb.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/configs/stm32f746-ws/src/stm32_usb.c b/configs/stm32f746-ws/src/stm32_usb.c
index b81aacd6ca..d0c118af89 100644
--- a/configs/stm32f746-ws/src/stm32_usb.c
+++ b/configs/stm32f746-ws/src/stm32_usb.c
@@ -333,7 +333,7 @@ xcpt_t stm32_setup_overcurrent(xcpt_t handler)
#ifdef CONFIG_USBDEV
void stm32_usbsuspend(FAR struct usbdev_s *dev, bool resume)
{
- ullinfo("resume: %d\n", resume);
+ uinfo("resume: %d\n", resume);
}
#endif
--
GitLab
From 9b7341b670194815d09713025c85cb2113b7d878 Mon Sep 17 00:00:00 2001
From: Lok Tep
Date: Tue, 27 Sep 2016 16:47:49 +0200
Subject: [PATCH 011/734] ignore eclipse .project
---
.gitignore | 2 ++
1 file changed, 2 insertions(+)
diff --git a/.gitignore b/.gitignore
index 3ec700458d..839c74cb5e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -28,3 +28,5 @@ cscope.out
/*.hex
/pcode
/tags
+.cproject
+.project
\ No newline at end of file
--
GitLab
From 1cbd7a0e5972ee6bf4d5fb04613de0278a494fd2 Mon Sep 17 00:00:00 2001
From: Lok Tep
Date: Fri, 30 Sep 2016 16:00:18 +0200
Subject: [PATCH 012/734] CONFIG_ARCH_IRQPRIO check
---
arch/arm/src/stm32f7/stm32_sdmmc.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/arch/arm/src/stm32f7/stm32_sdmmc.c b/arch/arm/src/stm32f7/stm32_sdmmc.c
index 3e6aff9620..9fa8d00b07 100644
--- a/arch/arm/src/stm32f7/stm32_sdmmc.c
+++ b/arch/arm/src/stm32f7/stm32_sdmmc.c
@@ -113,7 +113,7 @@
#endif
#ifdef CONFIG_STM32F7_SDMMC1
-# ifndef CONFIG_SDMMC1_PRI
+# if defined(CONFIG_ARCH_IRQPRIO) && !defined(CONFIG_SDMMC1_PRI)
# define CONFIG_SDMMC1_PRI NVIC_SYSH_PRIORITY_DEFAULT
# endif
@@ -130,7 +130,7 @@
#endif
#ifdef CONFIG_STM32F7_SDMMC2
-# ifndef CONFIG_SDMMC2_PRI
+# if defined(CONFIG_ARCH_IRQPRIO) && !defined(CONFIG_SDMMC2_PRI)
# define CONFIG_SDMMC2_PRI NVIC_SYSH_PRIORITY_DEFAULT
# endif
--
GitLab
From 4cb1ba493b64eb567e7b33261e4df18c15d55cfb Mon Sep 17 00:00:00 2001
From: Lok Tep
Date: Fri, 30 Sep 2016 16:00:28 +0200
Subject: [PATCH 013/734] mmc renames
---
configs/stm32f746-ws/include/board.h | 10 +++++-----
configs/stm32f746-ws/nsh/defconfig | 2 +-
2 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/configs/stm32f746-ws/include/board.h b/configs/stm32f746-ws/include/board.h
index ea5072ce20..17ca38417e 100644
--- a/configs/stm32f746-ws/include/board.h
+++ b/configs/stm32f746-ws/include/board.h
@@ -274,16 +274,16 @@
* SDIOCLK=48MHz, SDIO_CK=SDIOCLK/(118+2)=400 KHz
*/
-#define SDMMC1_INIT_CLKDIV (118 << SDIO_CLKCR_CLKDIV_SHIFT)
+#define STM32_SDMMC_INIT_CLKDIV (118 << STM32_SDMMC_CLKCR_CLKDIV_SHIFT)
/* DMA ON: SDIOCLK=48MHz, SDIO_CK=SDIOCLK/(1+2)=16 MHz
* DMA OFF: SDIOCLK=48MHz, SDIO_CK=SDIOCLK/(2+2)=12 MHz
*/
#ifdef CONFIG_SDIO_DMA
-# define SDMMC1_MMCXFR_CLKDIV (1 << SDIO_CLKCR_CLKDIV_SHIFT)
+# define STM32_SDMMC_MMCXFR_CLKDIV (1 << STM32_SDMMC_CLKCR_CLKDIV_SHIFT)
#else
-# define SDMMC1_MMCXFR_CLKDIV (2 << SDIO_CLKCR_CLKDIV_SHIFT)
+# define STM32_SDMMC_MMCXFR_CLKDIV (2 << STM32_SDMMC_CLKCR_CLKDIV_SHIFT)
#endif
/* DMA ON: SDIOCLK=48MHz, SDIO_CK=SDIOCLK/(1+2)=16 MHz
@@ -291,9 +291,9 @@
*/
#ifdef CONFIG_SDIO_DMA
-# define SDMMC1_SDXFR_CLKDIV (1 << SDIO_CLKCR_CLKDIV_SHIFT)
+# define STM32_SDMMC_SDXFR_CLKDIV (1 << STM32_SDMMC_CLKCR_CLKDIV_SHIFT)
#else
-# define SDMMC1_SDXFR_CLKDIV (2 << SDIO_CLKCR_CLKDIV_SHIFT)
+# define STM32_SDMMC_SDXFR_CLKDIV (2 << STM32_SDMMC_CLKCR_CLKDIV_SHIFT)
#endif
/************************************************************************************
diff --git a/configs/stm32f746-ws/nsh/defconfig b/configs/stm32f746-ws/nsh/defconfig
index c9598479e3..6fafd45558 100644
--- a/configs/stm32f746-ws/nsh/defconfig
+++ b/configs/stm32f746-ws/nsh/defconfig
@@ -312,7 +312,7 @@ CONFIG_STM32F7_OTGFS=y
# CONFIG_STM32F7_RNG is not set
# CONFIG_STM32F7_SAI1 is not set
# CONFIG_STM32F7_SAI2 is not set
-##CONFIG_STM32F7_SDMMC1=y
+CONFIG_STM32F7_SDMMC1=y
# CONFIG_STM32F7_SPDIFRX is not set
CONFIG_STM32F7_SPI1=y
# CONFIG_STM32F7_SPI2 is not set
--
GitLab
From fd1de920160304667a4edc9a4407486af9e3e90d Mon Sep 17 00:00:00 2001
From: Vytautas Lukenskas
Date: Fri, 30 Sep 2016 07:45:39 -0600
Subject: [PATCH 014/734] There are some small problems in LPC43xx RS485 mode
configuration. In particular: 1. UART0,2,3 do not have DTR pins (different
from UART1), so, Kconfig needs to be adjusted. 2. lpc43_uart.c in RS485 mode
only configures DIR pin, but doesn't enable pin output for UART0,2,3. 3.
should be option to reverse DIR control pin output polarity. 4.
lpc43xx/chip/lpc43_uart.h doesn't have USART3 definitions. NOTE: I didn't
modified and didn't tested USART1, as it has different hardware. From
Vytautas Lukenskas.
---
arch/arm/src/lpc43xx/Kconfig | 31 +++++++---
arch/arm/src/lpc43xx/chip/lpc43_uart.h | 22 ++++++++
arch/arm/src/lpc43xx/lpc43_config.h | 3 -
arch/arm/src/lpc43xx/lpc43_serial.c | 9 ---
arch/arm/src/lpc43xx/lpc43_uart.c | 78 +++++++++++++++++++++++++-
5 files changed, 119 insertions(+), 24 deletions(-)
diff --git a/arch/arm/src/lpc43xx/Kconfig b/arch/arm/src/lpc43xx/Kconfig
index 80da35c00c..7c9a89c49d 100644
--- a/arch/arm/src/lpc43xx/Kconfig
+++ b/arch/arm/src/lpc43xx/Kconfig
@@ -638,11 +638,16 @@ config USART0_RS485MODE
---help---
Enable RS-485 interface on USART0.
-config USART0_RS485_DTRDIR
- bool "USART0 DTR for DIR"
+if USART0_RS485_MODE
+ config USART0_RS485DIROIN
+ bool "Invert direction control pin polarity"
default n
---help---
- Use the USART DTR pin for the DIR pin
+ If disabled, control pin will be driven to logic 0 when the
+ transmitter has data to be sent. It will be driven to logic 1 after
+ the last bit of data has been transmitted.
+
+endif # USART0_RS485MODE
endif # LPC43_USART0
@@ -670,11 +675,15 @@ config USART2_RS485MODE
---help---
Enable RS-485 interface on USART2.
-config USART2_RS485_DTRDIR
- bool "USART2 DTR for DIR"
+if USART2_RS485MODE
+ config USART0_RS485DIROIN
+ bool "Invert direction control pin polarity"
default n
---help---
- Use the USART DTR pin for the DIR pin
+ If disabled, control pin will be driven to logic 0 when the transmitter has data to be sent.
+ It will be driven to logic 1 after the last bit of data has been transmitted.
+
+endif # USART2_RS485MODE
endif # LPC43_USART2
@@ -686,11 +695,15 @@ config USART3_RS485MODE
---help---
Enable RS-485 interface on USART3.
-config USART3_RS485_DTRDIR
- bool "USART3 DTR for DIR"
+if USART3_RS485MODE
+config USART3_RS485DIROIN
+ bool "Invert direction control pin polarity"
default n
---help---
- Use the USART DTR pin for the DIR pin
+ If disabled, control pin will be driven to logic 0 when the transmitter has data to be sent.
+ It will be driven to logic 1 after the last bit of data has been transmitted.
+
+endif # USART3_RS485MODE
endif # LPC43_USART3
endmenu # RS-485 Configuration
diff --git a/arch/arm/src/lpc43xx/chip/lpc43_uart.h b/arch/arm/src/lpc43xx/chip/lpc43_uart.h
index a0ea29718a..de6944030e 100644
--- a/arch/arm/src/lpc43xx/chip/lpc43_uart.h
+++ b/arch/arm/src/lpc43xx/chip/lpc43_uart.h
@@ -168,6 +168,28 @@
#define LPC43_USART2_SYNCCTRL (LPC43_USART2_BASE+LPC43_USART_SYNCCTRL_OFFSET)
#define LPC43_USART2_TER (LPC43_USART2_BASE+LPC43_USART_TER_OFFSET)
+#define LPC43_USART3_RBR (LPC43_USART3_BASE+LPC43_UART_RBR_OFFSET)
+#define LPC43_USART3_THR (LPC43_USART3_BASE+LPC43_UART_THR_OFFSET)
+#define LPC43_USART3_DLL (LPC43_USART3_BASE+LPC43_UART_DLL_OFFSET)
+#define LPC43_USART3_DLM (LPC43_USART3_BASE+LPC43_UART_DLM_OFFSET)
+#define LPC43_USART3_IER (LPC43_USART3_BASE+LPC43_UART_IER_OFFSET)
+#define LPC43_USART3_IIR (LPC43_USART3_BASE+LPC43_UART_IIR_OFFSET)
+#define LPC43_USART3_FCR (LPC43_USART3_BASE+LPC43_UART_FCR_OFFSET)
+#define LPC43_USART3_LCR (LPC43_USART3_BASE+LPC43_UART_LCR_OFFSET)
+#define LPC43_USART3_LSR (LPC43_USART3_BASE+LPC43_UART_LSR_OFFSET)
+#define LPC43_USART3_SCR (LPC43_USART3_BASE+LPC43_UART_SCR_OFFSET)
+#define LPC43_USART3_ACR (LPC43_USART3_BASE+LPC43_UART_ACR_OFFSET)
+#define LPC43_USART3_ICR (LPC43_USART3_BASE+LPC43_USART_ICR_OFFSET)
+#define LPC43_USART3_FDR (LPC43_USART3_BASE+LPC43_UART_FDR_OFFSET)
+#define LPC43_USART3_OSR (LPC43_USART3_BASE+LPC43_USART_OSR_OFFSET)
+#define LPC43_USART3_HDEM (LPC43_USART3_BASE+LPC43_USART_HDEN_OFFSET)
+#define LPC43_USART3_SCICTRL (LPC43_USART3_BASE+LPC43_USART_SCICTRL_OFFSET)
+#define LPC43_USART3_RS485CTRL (LPC43_USART3_BASE+LPC43_UART_RS485CTRL_OFFSET)
+#define LPC43_USART3_ADRMATCH (LPC43_USART3_BASE+LPC43_UART_ADRMATCH_OFFSET)
+#define LPC43_USART3_RS485DLY (LPC43_USART3_BASE+LPC43_UART_RS485DLY_OFFSET)
+#define LPC43_USART3_SYNCCTRL (LPC43_USART3_BASE+LPC43_USART_SYNCCTRL_OFFSET)
+#define LPC43_USART3_TER (LPC43_USART3_BASE+LPC43_USART_TER_OFFSET)
+
/* Register bit definitions *****************************************************************/
/* RBR (DLAB =0) Receiver Buffer Register */
diff --git a/arch/arm/src/lpc43xx/lpc43_config.h b/arch/arm/src/lpc43xx/lpc43_config.h
index 8a4509b8f0..528c900252 100644
--- a/arch/arm/src/lpc43xx/lpc43_config.h
+++ b/arch/arm/src/lpc43xx/lpc43_config.h
@@ -73,7 +73,6 @@
#ifndef CONFIG_LPC43_USART0
# undef CONFIG_USART0_SERIAL_CONSOLE
# undef CONFIG_USART0_RS485MODE
-# undef CONFIG_USART0_RS485_DTRDIR
#endif
#ifndef CONFIG_LPC43_UART1
@@ -85,13 +84,11 @@
#ifndef CONFIG_LPC43_USART2
# undef CONFIG_USART2_SERIAL_CONSOLE
# undef CONFIG_USART2_RS485MODE
-# undef CONFIG_USART2_RS485_DTRDIR
#endif
#ifndef CONFIG_LPC43_USART3
# undef CONFIG_USART3_SERIAL_CONSOLE
# undef CONFIG_USART3_RS485MODE
-# undef CONFIG_USART3_RS485_DTRDIR
#endif
/* Is there a serial console? There should be at most one defined. It could be on
diff --git a/arch/arm/src/lpc43xx/lpc43_serial.c b/arch/arm/src/lpc43xx/lpc43_serial.c
index 82ec6d690e..3fa30e87e2 100644
--- a/arch/arm/src/lpc43xx/lpc43_serial.c
+++ b/arch/arm/src/lpc43xx/lpc43_serial.c
@@ -169,9 +169,6 @@ static struct up_dev_s g_uart0priv =
.parity = CONFIG_USART0_PARITY,
.bits = CONFIG_USART0_BITS,
.stopbits2 = CONFIG_USART0_2STOP,
-#if defined(CONFIG_USART0_RS485MODE) && defined(CONFIG_USART0_RS485_DTRDIR)
- .dtrdir = true,
-#endif
};
static uart_dev_t g_uart0port =
@@ -239,9 +236,6 @@ static struct up_dev_s g_uart2priv =
.parity = CONFIG_USART2_PARITY,
.bits = CONFIG_USART2_BITS,
.stopbits2 = CONFIG_USART2_2STOP,
-#if defined(CONFIG_USART2_RS485MODE) && defined(CONFIG_USART2_RS485_DTRDIR)
- .dtrdir = true,
-#endif
};
static uart_dev_t g_uart2port =
@@ -274,9 +268,6 @@ static struct up_dev_s g_uart3priv =
.parity = CONFIG_USART3_PARITY,
.bits = CONFIG_USART3_BITS,
.stopbits2 = CONFIG_USART3_2STOP,
-#if defined(CONFIG_USART3_RS485MODE) && defined(CONFIG_USART3_RS485_DTRDIR)
- .dtrdir = true,
-#endif
};
static uart_dev_t g_uart3port =
diff --git a/arch/arm/src/lpc43xx/lpc43_uart.c b/arch/arm/src/lpc43xx/lpc43_uart.c
index 88d7950e6a..0aa983de90 100644
--- a/arch/arm/src/lpc43xx/lpc43_uart.c
+++ b/arch/arm/src/lpc43xx/lpc43_uart.c
@@ -364,7 +364,31 @@ void lpc43_usart0_setup(void)
#ifdef CONFIG_USART0_RS485MODE
lpc43_pin_config(PINCONF_U0_DIR);
-#endif
+
+ /* Enable direction output pin */
+
+ regval = getreg32(LPC43_USART0_RS485CTRL);
+ regval |= UART_RS485CTRL_DCTRL;
+ putreg32(regval, LPC43_USART0_RS485CTRL);
+
+#ifdef CONFIG_USART0_RS485DIROIN
+
+ /* Invert direction control output pin polarity */
+
+ regval = getreg32(LPC43_USART0_RS485CTRL);
+ regval |= UART_RS485CTRL_OINV;
+ putreg32(regval, LPC43_USART0_RS485CTRL);
+
+#else
+
+ /* Do not invert direction countrol output pin polarity */
+
+ regval = getreg32(LPC43_USART0_RS485CTRL);
+ regval &= ~(UART_RS485CTRL_OINV);
+ putreg32(regval, LPC43_USART0_RS485CTRL);
+
+#endif /* CONFIG_USART0_RS485DIROIN */
+#endif /* CONFIG_USART0_RS485MODE */
leave_critical_section(flags);
};
@@ -467,7 +491,31 @@ void lpc43_usart2_setup(void)
#ifdef CONFIG_USART2_RS485MODE
lpc43_pin_config(PINCONF_U2_DIR);
-#endif
+
+ /* Enable direction output pin */
+
+ regval = getreg32(LPC43_USART2_RS485CTRL);
+ regval |= UART_RS485CTRL_DCTRL;
+ putreg32(regval, LPC43_USART2_RS485CTRL);
+
+#ifdef CONFIG_USART2_RS485DIROIN
+
+ /* Invert direction control output pin polarity */
+
+ regval = getreg32(LPC43_USART2_RS485CTRL);
+ regval |= UART_RS485CTRL_OINV;
+ putreg32(regval, LPC43_USART2_RS485CTRL);
+
+#else
+
+ /* Do not invert direction countrol output pin polarity */
+
+ regval = getreg32(LPC43_USART2_RS485CTRL);
+ regval &= ~(UART_RS485CTRL_OINV);
+ putreg32(regval, LPC43_USART2_RS485CTRL);
+
+#endif /* CONFIG_USART2_RS485DIROIN */
+#endif /* CONFIG_USART2_RS485MODE */
leave_critical_section(flags);
};
@@ -516,7 +564,31 @@ void lpc43_usart3_setup(void)
#ifdef CONFIG_USART3_RS485MODE
lpc43_pin_config(PINCONF_U3_DIR);
-#endif
+
+ /* Enable direction output pin */
+
+ regval = getreg32(LPC43_USART3_RS485CTRL);
+ regval |= UART_RS485CTRL_DCTRL;
+ putreg32(regval, LPC43_USART3_RS485CTRL);
+
+#ifdef CONFIG_USART3_RS485DIROIN
+
+ /* Invert direction control output pin polarity */
+
+ regval = getreg32(LPC43_USART3_RS485CTRL);
+ regval |= UART_RS485CTRL_OINV;
+ putreg32(regval, LPC43_USART3_RS485CTRL);
+
+#else
+
+ /* Do not invert direction countrol output pin polarity */
+
+ regval = getreg32(LPC43_USART3_RS485CTRL);
+ regval &= ~(UART_RS485CTRL_OINV);
+ putreg32(regval, LPC43_USART3_RS485CTRL);
+
+#endif /* CONFIG_USART3_RS485DIROIN */
+#endif /* CONFIG_USART3_RS485MODE */
leave_critical_section(flags);
};
--
GitLab
From ef475eb6a98850c82bbcc69d1e26ffcc6d4885af Mon Sep 17 00:00:00 2001
From: Neil Hancock
Date: Sat, 1 Oct 2016 07:32:41 -0600
Subject: [PATCH 015/734] STM32 Ethernet: Correct typo in conditional logic
---
arch/arm/src/stm32/stm32_eth.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/arm/src/stm32/stm32_eth.c b/arch/arm/src/stm32/stm32_eth.c
index a7f6eaa26f..abf911f7ac 100644
--- a/arch/arm/src/stm32/stm32_eth.c
+++ b/arch/arm/src/stm32/stm32_eth.c
@@ -3278,7 +3278,7 @@ static inline int stm32_dm9161(FAR struct stm32_ethmac_s *priv)
static int stm32_phyinit(FAR struct stm32_ethmac_s *priv)
{
-#ifdef CONFIG_STM32_AUTOGEN
+#ifdef CONFIG_STM32_AUTONEG
volatile uint32_t timeout;
#endif
--
GitLab
From 0f7b9d643f30c26217575f1ae78cf6fa936aba07 Mon Sep 17 00:00:00 2001
From: Gregory Nutt
Date: Sat, 1 Oct 2016 10:13:37 -0600
Subject: [PATCH 016/734] Correct statment in a document
---
Documentation/NuttX.html | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/Documentation/NuttX.html b/Documentation/NuttX.html
index 700876be65..4d6823305e 100644
--- a/Documentation/NuttX.html
+++ b/Documentation/NuttX.html
@@ -8,7 +8,7 @@
NuttX RTOS
- Last Updated: July 25, 2016
+ Last Updated: September 30, 2016
|
@@ -146,13 +146,11 @@
to support a rich, multi-threaded development environment for deeply embedded
processors.
- NON-GOALS: (1) It is not a goal to provide the level of OS features like those provided by Linux.
+ NON-GOALS: It is not a goal to provide the level of OS features like those provided by Linux.
In order to work with smaller MCUs, small footprint must be more important than an extensive feature set.
But standard compliance is more important than small footprint.
Surely a smaller RTOS could be produced by ignoring standards.
Think of NuttX is a tiny Linux work-alike with a much reduced feature set.
- (2) There is no MMU-based support for processes.
- At present, NuttX assumes a flat address space.
--
GitLab
From 75104b080801a62dcf829a1c2b1cdc1be9f9fc6a Mon Sep 17 00:00:00 2001
From: Gregory Nutt
Date: Sat, 1 Oct 2016 10:56:42 -0600
Subject: [PATCH 017/734] Remove duplicate function prototype from wrong header
file
---
sched/task/task.h | 4 ----
1 file changed, 4 deletions(-)
diff --git a/sched/task/task.h b/sched/task/task.h
index b4967c799a..e81f0eaefc 100644
--- a/sched/task/task.h
+++ b/sched/task/task.h
@@ -80,8 +80,4 @@ int task_terminate(pid_t pid, bool nonblocking);
void task_exithook(FAR struct tcb_s *tcb, int status, bool nonblocking);
void task_recover(FAR struct tcb_s *tcb);
-/* Misc. */
-
-bool sched_addreadytorun(FAR struct tcb_s *rtrtcb);
-
#endif /* __SCHED_TASK_TASK_H */
--
GitLab
From 8669183852845f527d7761f6582bcc4d997eb812 Mon Sep 17 00:00:00 2001
From: Gregory Nutt
Date: Sat, 1 Oct 2016 11:38:22 -0600
Subject: [PATCH 018/734] sched/pthread and task: When a pthread is started,
there is a small bit of logic that will run on the thread of execution of the
new pthread. In the case where the new pthread has a lower priority than the
parent thread, then this could cause both the parent thread and the new
pthread to be blocked at the priority of the lower priority pthread (assuming
that CONFIG_PRIORITY_INHERITANCE is not selected).
This change temporarily boosts the priority of the new pthread to at least the priority of the new pthread to at least the priority of the parent thread. When that bit of logic has executed on the thread of execution of the new pthread, it will then drop to the correct priority (if necessary) before calling into the new pthread's entry point.
---
include/nuttx/sched.h | 4 ++--
sched/pthread/pthread_create.c | 32 +++++++++++++++++++++++++++++++-
sched/task/task_restart.c | 4 ++--
sched/task/task_setup.c | 15 +++------------
4 files changed, 38 insertions(+), 17 deletions(-)
diff --git a/include/nuttx/sched.h b/include/nuttx/sched.h
index 4d7bb88f11..ec438727f8 100644
--- a/include/nuttx/sched.h
+++ b/include/nuttx/sched.h
@@ -551,6 +551,7 @@ struct tcb_s
start_t start; /* Thread start function */
entry_t entry; /* Entry Point into the thread */
uint8_t sched_priority; /* Current priority of the thread */
+ uint8_t init_priority; /* Initial priority of the thread */
#ifdef CONFIG_PRIORITY_INHERITANCE
#if CONFIG_SEM_NNESTPRIO > 0
@@ -654,9 +655,8 @@ struct task_tcb_s
FAR void *starthookarg; /* The argument passed to the function */
#endif
- /* Values needed to restart a task ********************************************/
+ /* [Re-]start name + start-up parameters **************************************/
- uint8_t init_priority; /* Initial priority of the task */
FAR char **argv; /* Name+start-up parameters */
};
diff --git a/sched/pthread/pthread_create.c b/sched/pthread/pthread_create.c
index 487827fbcb..be81a5f0ff 100644
--- a/sched/pthread/pthread_create.c
+++ b/sched/pthread/pthread_create.c
@@ -183,6 +183,16 @@ static void pthread_start(void)
pjoin->started = true;
(void)pthread_givesemaphore(&pjoin->data_sem);
+ /* The priority of this thread may have been boosted to avoid priority
+ * inversion problems. If that is the case, then drop to the correct
+ * execution priority.
+ */
+
+ if (ptcb->cmn.sched_priority > ptcb->cmn.init_priority)
+ {
+ DEBUGVERIFY(sched_setpriority(&ptcb->cmn, ptcb->cmn.init_priority));
+ }
+
/* Pass control to the thread entry point. In the kernel build this has to
* be handled differently if we are starting a user-space pthread; we have
* to switch to user-mode before calling into the pthread.
@@ -488,7 +498,27 @@ int pthread_create(FAR pthread_t *thread, FAR const pthread_attr_t *attr,
ret = sem_init(&pjoin->exit_sem, 0, 0);
}
- /* Activate the task */
+ /* If the priority of the new pthread is lower than the priority of the
+ * parent thread, then starting the pthread could result in both the
+ * parent and the pthread to be blocked. This is a recipe for priority
+ * inversion issues.
+ *
+ * We avoid this here by boosting the priority of the (inactive) pthread
+ * so it has the same priority as the parent thread.
+ */
+
+ if (ret == OK)
+ {
+ FAR struct tcb_s *parent = this_task();
+ DEBUGASSERT(parent != NULL);
+
+ if (ptcb->cmn.sched_priority < parent->sched_priority)
+ {
+ ret = sched_setpriority(&ptcb->cmn, parent->sched_priority);
+ }
+ }
+
+ /* Then activate the task */
sched_lock();
if (ret == OK)
diff --git a/sched/task/task_restart.c b/sched/task/task_restart.c
index 5f3b76958f..70da24df57 100644
--- a/sched/task/task_restart.c
+++ b/sched/task/task_restart.c
@@ -169,12 +169,12 @@ int task_restart(pid_t pid)
/* Reset the current task priority */
- tcb->cmn.sched_priority = tcb->init_priority;
+ tcb->cmn.sched_priority = tcb->cmn.init_priority;
/* Reset the base task priority and the number of pending reprioritizations */
#ifdef CONFIG_PRIORITY_INHERITANCE
- tcb->cmn.base_priority = tcb->init_priority;
+ tcb->cmn.base_priority = tcb->cmn.init_priority;
# if CONFIG_SEM_NNESTPRIO > 0
tcb->cmn.npend_reprio = 0;
# endif
diff --git a/sched/task/task_setup.c b/sched/task/task_setup.c
index 0819049785..7b8b086434 100644
--- a/sched/task/task_setup.c
+++ b/sched/task/task_setup.c
@@ -363,6 +363,7 @@ static int thread_schedsetup(FAR struct tcb_s *tcb, int priority,
/* Save task priority and entry point in the TCB */
tcb->sched_priority = (uint8_t)priority;
+ tcb->init_priority = (uint8_t)priority;
#ifdef CONFIG_PRIORITY_INHERITANCE
tcb->base_priority = (uint8_t)priority;
#endif
@@ -633,20 +634,10 @@ static inline int task_stackargsetup(FAR struct task_tcb_s *tcb,
int task_schedsetup(FAR struct task_tcb_s *tcb, int priority, start_t start,
main_t main, uint8_t ttype)
{
- int ret;
-
/* Perform common thread setup */
- ret = thread_schedsetup((FAR struct tcb_s *)tcb, priority, start,
- (CODE void *)main, ttype);
- if (ret == OK)
- {
- /* Save task restart priority */
-
- tcb->init_priority = (uint8_t)priority;
- }
-
- return ret;
+ return thread_schedsetup((FAR struct tcb_s *)tcb, priority, start,
+ (CODE void *)main, ttype);
}
/****************************************************************************
--
GitLab
From 33cea5038f516d1b2bf57fe3badbafb6b3069d29 Mon Sep 17 00:00:00 2001
From: Lok Tep
Date: Sat, 1 Oct 2016 19:38:43 +0200
Subject: [PATCH 019/734] memory corruption, typo addr-value
---
arch/arm/src/stm32f7/stm32_otgdev.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/arch/arm/src/stm32f7/stm32_otgdev.c b/arch/arm/src/stm32f7/stm32_otgdev.c
index f06175cb5b..54a0232cdf 100644
--- a/arch/arm/src/stm32f7/stm32_otgdev.c
+++ b/arch/arm/src/stm32f7/stm32_otgdev.c
@@ -4230,7 +4230,10 @@ static void stm32_epin_disable(FAR struct stm32_ep_s *privep)
/* Clear the EPDISD interrupt indication */
- stm32_putreg(OTG_DIEPINT_EPDISD, stm32_getreg(regaddr));
+ regval = stm32_getreg(regaddr);
+ regval |= OTG_DIEPINT_EPDISD;
+ stm32_putreg(OTG_DIEPINT_EPDISD, regaddr);
+
/* Flush any data remaining in the TxFIFO */
--
GitLab
From a196f2968c9fe8697ca58717bb1ee56008055108 Mon Sep 17 00:00:00 2001
From: Lok Tep
Date: Sat, 1 Oct 2016 19:39:33 +0200
Subject: [PATCH 020/734] more stack size for Idle thread
---
configs/stm32f746-ws/nsh/defconfig | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/configs/stm32f746-ws/nsh/defconfig b/configs/stm32f746-ws/nsh/defconfig
index 6fafd45558..5c0a529820 100644
--- a/configs/stm32f746-ws/nsh/defconfig
+++ b/configs/stm32f746-ws/nsh/defconfig
@@ -312,7 +312,7 @@ CONFIG_STM32F7_OTGFS=y
# CONFIG_STM32F7_RNG is not set
# CONFIG_STM32F7_SAI1 is not set
# CONFIG_STM32F7_SAI2 is not set
-CONFIG_STM32F7_SDMMC1=y
+##CONFIG_STM32F7_SDMMC1=y
# CONFIG_STM32F7_SPDIFRX is not set
CONFIG_STM32F7_SPI1=y
# CONFIG_STM32F7_SPI2 is not set
@@ -416,7 +416,7 @@ CONFIG_BOARD_LOOPSPERMSEC=43103
# Interrupt options
#
CONFIG_ARCH_HAVE_INTERRUPTSTACK=y
-CONFIG_ARCH_INTERRUPTSTACK=600
+CONFIG_ARCH_INTERRUPTSTACK=2600
CONFIG_ARCH_HAVE_HIPRI_INTERRUPT=y
# CONFIG_ARCH_HIPRI_INTERRUPT is not set
@@ -571,7 +571,7 @@ CONFIG_SCHED_LPWORKSTACKSIZE=1800
#
# Stack and heap information
#
-CONFIG_IDLETHREAD_STACKSIZE=500
+CONFIG_IDLETHREAD_STACKSIZE=2500
CONFIG_USERMAIN_STACKSIZE=2500
CONFIG_PTHREAD_STACK_MIN=512
CONFIG_PTHREAD_STACK_DEFAULT=2048
--
GitLab
From 53fa8b72965420c4e2ee1fa42b8ca44bd609fd12 Mon Sep 17 00:00:00 2001
From: Alan Carvalho de Assis
Date: Sun, 2 Oct 2016 14:45:44 -0600
Subject: [PATCH 021/734] configs/stm32f103-minimum: Add stm32_bringup support
and userled example to STM32F103 Minimum board
---
configs/stm32f103-minimum/include/board.h | 15 +-
configs/stm32f103-minimum/src/Makefile | 8 +-
configs/stm32f103-minimum/src/stm32_appinit.c | 25 +-
.../stm32f103-minimum/src/stm32_autoleds.c | 4 +-
configs/stm32f103-minimum/src/stm32_boot.c | 24 +
configs/stm32f103-minimum/src/stm32_bringup.c | 142 ++
.../stm32f103-minimum/src/stm32_userleds.c | 112 ++
.../stm32f103-minimum/src/stm32f103_minimum.h | 22 +-
configs/stm32f103-minimum/userled/Make.defs | 113 ++
configs/stm32f103-minimum/userled/defconfig | 1143 +++++++++++++++++
configs/stm32f103-minimum/userled/setenv.sh | 100 ++
11 files changed, 1677 insertions(+), 31 deletions(-)
create mode 100644 configs/stm32f103-minimum/src/stm32_bringup.c
create mode 100644 configs/stm32f103-minimum/src/stm32_userleds.c
create mode 100644 configs/stm32f103-minimum/userled/Make.defs
create mode 100644 configs/stm32f103-minimum/userled/defconfig
create mode 100644 configs/stm32f103-minimum/userled/setenv.sh
diff --git a/configs/stm32f103-minimum/include/board.h b/configs/stm32f103-minimum/include/board.h
index 217e4dfd89..85bdf23464 100644
--- a/configs/stm32f103-minimum/include/board.h
+++ b/configs/stm32f103-minimum/include/board.h
@@ -43,11 +43,14 @@
#include
#ifndef __ASSEMBLY__
-# include
+# include
+#endif
+
+#ifdef __KERNEL__
+# include "stm32_rcc.h"
+# include "stm32_sdio.h"
+# include "stm32.h"
#endif
-#include "stm32_rcc.h"
-#include "stm32_sdio.h"
-#include "stm32.h"
/************************************************************************************
* Pre-processor Definitions
@@ -151,6 +154,10 @@
/* LED definitions ******************************************************************/
+/* Define how many LEDs this board has (needed by userleds) */
+
+#define BOARD_NLEDS 1
+
/* The board has only one controllable LED */
#define LED_STARTED 0 /* No LEDs */
diff --git a/configs/stm32f103-minimum/src/Makefile b/configs/stm32f103-minimum/src/Makefile
index 0e07041715..5876a6df68 100644
--- a/configs/stm32f103-minimum/src/Makefile
+++ b/configs/stm32f103-minimum/src/Makefile
@@ -37,12 +37,18 @@
-include $(TOPDIR)/Make.defs
ASRCS =
-CSRCS = stm32_boot.c stm32_autoleds.c stm32_spi.c stm32_usbdev.c
+CSRCS = stm32_boot.c stm32_bringup.c stm32_spi.c stm32_usbdev.c
ifeq ($(CONFIG_LIB_BOARDCTL),y)
CSRCS += stm32_appinit.c
endif
+ifeq ($(CONFIG_ARCH_LEDS),y)
+CSRCS += stm32_autoleds.c
+else
+CSRCS += stm32_userleds.c
+endif
+
ifeq ($(CONFIG_AUDIO_TONE),y)
CSRCS += stm32_tone.c
endif
diff --git a/configs/stm32f103-minimum/src/stm32_appinit.c b/configs/stm32f103-minimum/src/stm32_appinit.c
index a5fe60b616..e8d545ff66 100644
--- a/configs/stm32f103-minimum/src/stm32_appinit.c
+++ b/configs/stm32f103-minimum/src/stm32_appinit.c
@@ -81,28 +81,7 @@
int board_app_initialize(uintptr_t arg)
{
-#ifdef CONFIG_ONESHOT
- struct oneshot_lowerhalf_s *os = NULL;
-#endif
- int ret = OK;
+ /* Perform board initialization here */
-#ifdef CONFIG_AUDIO_TONE
- /* Configure and initialize the tone generator. */
-
- ret = stm32_tone_setup();
-#endif
-
-#ifdef CONFIG_WL_MFRC522
- ret = stm32_mfrc522initialize("/dev/rfid0");
-#endif
-
-#ifdef CONFIG_ONESHOT
- os = oneshot_initialize(1, 10);
- if (os)
- {
- ret = oneshot_register("/dev/oneshot", os);
- }
-#endif
-
- return ret;
+ return stm32_bringup();
}
diff --git a/configs/stm32f103-minimum/src/stm32_autoleds.c b/configs/stm32f103-minimum/src/stm32_autoleds.c
index b851c44053..b2c8b33576 100644
--- a/configs/stm32f103-minimum/src/stm32_autoleds.c
+++ b/configs/stm32f103-minimum/src/stm32_autoleds.c
@@ -59,7 +59,7 @@
static inline void set_led(bool v)
{
ledinfo("Turn LED %s\n", v? "on":"off");
- stm32_gpiowrite(GPIO_LED, !v);
+ stm32_gpiowrite(GPIO_LED1, !v);
}
/****************************************************************************
@@ -75,7 +75,7 @@ void board_autoled_initialize(void)
{
/* Configure LED GPIO for output */
- stm32_configgpio(GPIO_LED);
+ stm32_configgpio(GPIO_LED1);
}
/****************************************************************************
diff --git a/configs/stm32f103-minimum/src/stm32_boot.c b/configs/stm32f103-minimum/src/stm32_boot.c
index c7b9b4df99..92f321fbcb 100644
--- a/configs/stm32f103-minimum/src/stm32_boot.c
+++ b/configs/stm32f103-minimum/src/stm32_boot.c
@@ -87,3 +87,27 @@ void stm32_boardinitialize(void)
stm32_usbinitialize();
#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)
+{
+#ifndef CONFIG_LIB_BOARDCTL
+ /* Perform board initialization here instead of from the board_app_initialize(). */
+
+ (void)stm32_bringup();
+#endif
+}
+#endif
diff --git a/configs/stm32f103-minimum/src/stm32_bringup.c b/configs/stm32f103-minimum/src/stm32_bringup.c
new file mode 100644
index 0000000000..ec7d33db3f
--- /dev/null
+++ b/configs/stm32f103-minimum/src/stm32_bringup.c
@@ -0,0 +1,142 @@
+/****************************************************************************
+ * config/stm32f103-minimum/src/stm32_bringup.c
+ *
+ * Copyright (C) 2016 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * 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
+
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include
+#include
+
+#ifdef CONFIG_USBMONITOR
+# include
+#endif
+
+#include
+
+#include "stm32.h"
+
+#ifdef CONFIG_STM32_OTGFS
+# include "stm32_usbhost.h"
+#endif
+
+#ifdef CONFIG_USERLED
+# include
+#endif
+
+#include "stm32f103_minimum.h"
+
+/* Conditional logic in stm32f103_minimum.h will determine if certain features
+ * are supported. Tests for these features need to be made after including
+ * stm32f103_minimum.h.
+ */
+
+#ifdef HAVE_RTC_DRIVER
+# include
+# include "stm32_rtc.h"
+#endif
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: stm32_bringup
+ *
+ * Description:
+ * Perform architecture-specific initialization
+ *
+ * CONFIG_BOARD_INITIALIZE=y :
+ * Called from board_initialize().
+ *
+ * CONFIG_BOARD_INITIALIZE=n && CONFIG_LIB_BOARDCTL=y :
+ * Called from the NSH library
+ *
+ ****************************************************************************/
+
+int stm32_bringup(void)
+{
+#ifdef CONFIG_ONESHOT
+ struct oneshot_lowerhalf_s *os = NULL;
+#endif
+ int ret = OK;
+
+#ifdef CONFIG_AUDIO_TONE
+ /* Configure and initialize the tone generator. */
+
+ ret = stm32_tone_setup();
+ if (ret < 0)
+ {
+ syslog(LOG_ERR, "ERROR: stm32_tone_setup() failed: %d\n", ret);
+ }
+#endif
+
+#ifdef CONFIG_WL_MFRC522
+ ret = stm32_mfrc522initialize("/dev/rfid0");
+ if (ret < 0)
+ {
+ syslog(LOG_ERR, "ERROR: stm32_mfrc522initialize() failed: %d\n", ret);
+ }
+#endif
+
+#ifdef CONFIG_ONESHOT
+ os = oneshot_initialize(1, 10);
+ if (os)
+ {
+ ret = oneshot_register("/dev/oneshot", os);
+ }
+#endif
+
+#ifdef CONFIG_USERLED
+ /* Register the LED driver */
+
+ ret = userled_lower_initialize("/dev/userleds");
+ if (ret < 0)
+ {
+ syslog(LOG_ERR, "ERROR: userled_lower_initialize() failed: %d\n", ret);
+ }
+#endif
+
+ return ret;
+}
diff --git a/configs/stm32f103-minimum/src/stm32_userleds.c b/configs/stm32f103-minimum/src/stm32_userleds.c
new file mode 100644
index 0000000000..ac26d4d4d0
--- /dev/null
+++ b/configs/stm32f103-minimum/src/stm32_userleds.c
@@ -0,0 +1,112 @@
+/****************************************************************************
+ * configs/stm32f103-minimum/src/stm32_userleds.c
+ *
+ * Copyright (C) 2016 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * 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
+
+#include
+#include
+#include
+
+#include
+
+#include "chip.h"
+#include "stm32.h"
+#include "stm32f103_minimum.h"
+
+#ifndef CONFIG_ARCH_LEDS
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+/* This array maps an LED number to GPIO pin configuration */
+
+static const uint32_t g_ledcfg[BOARD_NLEDS] =
+{
+ GPIO_LED1,
+};
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: board_userled_initialize
+ ****************************************************************************/
+
+void board_userled_initialize(void)
+{
+ int i;
+
+ /* Configure LED1-8 GPIOs for output */
+
+ for (i = 0; i < BOARD_NLEDS; i++)
+ {
+ stm32_configgpio(g_ledcfg[i]);
+ }
+}
+
+/****************************************************************************
+ * Name: board_userled
+ ****************************************************************************/
+
+void board_userled(int led, bool ledon)
+{
+ if ((unsigned)led < BOARD_NLEDS)
+ {
+ stm32_gpiowrite(g_ledcfg[led], ledon);
+ }
+}
+
+/****************************************************************************
+ * Name: board_userled_all
+ ****************************************************************************/
+
+void board_userled_all(uint8_t ledset)
+{
+ int i;
+
+ /* Configure LED1-8 GPIOs for output */
+
+ for (i = 0; i < BOARD_NLEDS; i++)
+ {
+ stm32_gpiowrite(g_ledcfg[i], (ledset & (1 << i)) != 0);
+ }
+}
+
+#endif /* !CONFIG_ARCH_LEDS */
diff --git a/configs/stm32f103-minimum/src/stm32f103_minimum.h b/configs/stm32f103-minimum/src/stm32f103_minimum.h
index c023d22dc9..f3c083ac6b 100644
--- a/configs/stm32f103-minimum/src/stm32f103_minimum.h
+++ b/configs/stm32f103-minimum/src/stm32f103_minimum.h
@@ -63,7 +63,7 @@
/* GPIOs **************************************************************/
/* LEDs */
-#define GPIO_LED (GPIO_OUTPUT|GPIO_CNF_OUTPP|GPIO_MODE_50MHz|\
+#define GPIO_LED1 (GPIO_OUTPUT|GPIO_CNF_OUTPP|GPIO_MODE_50MHz|\
GPIO_OUTPUT_CLEAR|GPIO_PORTC|GPIO_PIN13)
/* SPI chip selects */
@@ -91,6 +91,26 @@
#ifndef __ASSEMBLY__
+/****************************************************************************
+ * Name: stm32_bringup
+ *
+ * Description:
+ * Perform architecture specific initialization
+ *
+ * CONFIG_LIB_BOARDCTL=y:
+ * If CONFIG_NSH_ARCHINITIALIZE=y:
+ * Called from the NSH library (or other application)
+ * Otherse, assumed to be called from some other application.
+ *
+ * Otherwise CONFIG_BOARD_INITIALIZE=y:
+ * Called from board_initialize().
+ *
+ * Otherise, bad news: Never called
+ *
+ ****************************************************************************/
+
+int stm32_bringup(void);
+
/************************************************************************************
* Name: stm32_spidev_initialize
*
diff --git a/configs/stm32f103-minimum/userled/Make.defs b/configs/stm32f103-minimum/userled/Make.defs
new file mode 100644
index 0000000000..d7974b005f
--- /dev/null
+++ b/configs/stm32f103-minimum/userled/Make.defs
@@ -0,0 +1,113 @@
+############################################################################
+# configs/stm32f103-minimum/userled/Make.defs
+#
+# Copyright (C) 2016 Gregory Nutt. All rights reserved.
+# Author: Gregory Nutt
+#
+# 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
+
+LDSCRIPT = ld.script
+
+ifeq ($(WINTOOL),y)
+ # Windows-native toolchains
+ DIRLINK = $(TOPDIR)/tools/copydir.sh
+ DIRUNLINK = $(TOPDIR)/tools/unlink.sh
+ MKDEP = $(TOPDIR)/tools/mkwindeps.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/$(LDSCRIPT)}"
+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/$(LDSCRIPT)
+endif
+
+CC = $(CROSSDEV)gcc
+CXX = $(CROSSDEV)g++
+CPP = $(CROSSDEV)gcc -E
+LD = $(CROSSDEV)ld
+AR = $(CROSSDEV)ar rcs
+NM = $(CROSSDEV)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
+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
+
+
+HOSTCC = gcc
+HOSTINCLUDES = -I.
+HOSTCFLAGS = -Wall -Wstrict-prototypes -Wshadow -Wundef -g -pipe
+HOSTLDFLAGS =
+
diff --git a/configs/stm32f103-minimum/userled/defconfig b/configs/stm32f103-minimum/userled/defconfig
new file mode 100644
index 0000000000..39ef59233b
--- /dev/null
+++ b/configs/stm32f103-minimum/userled/defconfig
@@ -0,0 +1,1143 @@
+#
+# Automatically generated file; DO NOT EDIT.
+# Nuttx/ Configuration
+#
+
+#
+# Build Setup
+#
+# CONFIG_EXPERIMENTAL is not set
+CONFIG_DEFAULT_SMALL=y
+CONFIG_HOST_LINUX=y
+# CONFIG_HOST_OSX is not set
+# CONFIG_HOST_WINDOWS is not set
+# CONFIG_HOST_OTHER is not set
+
+#
+# Build Configuration
+#
+# CONFIG_APPS_DIR="../apps"
+CONFIG_BUILD_FLAT=y
+# CONFIG_BUILD_2PASS is not set
+
+#
+# Binary Output Formats
+#
+# CONFIG_RRLOAD_BINARY is not set
+# CONFIG_INTELHEX_BINARY is not set
+# CONFIG_MOTOROLA_SREC is not set
+CONFIG_RAW_BINARY=y
+# CONFIG_UBOOT_UIMAGE is not set
+
+#
+# Customize Header Files
+#
+# CONFIG_ARCH_STDINT_H is not set
+# CONFIG_ARCH_STDBOOL_H is not set
+# CONFIG_ARCH_MATH_H is not set
+# CONFIG_ARCH_FLOAT_H is not set
+# CONFIG_ARCH_STDARG_H is not set
+# CONFIG_ARCH_DEBUG_H is not set
+
+#
+# Debug Options
+#
+CONFIG_DEBUG_ALERT=y
+# CONFIG_DEBUG_FEATURES is not set
+CONFIG_ARCH_HAVE_STACKCHECK=y
+# CONFIG_STACK_COLORATION is not set
+CONFIG_ARCH_HAVE_HEAPCHECK=y
+# CONFIG_HEAP_COLORATION is not set
+# CONFIG_DEBUG_SYMBOLS is not set
+CONFIG_ARCH_HAVE_CUSTOMOPT=y
+# CONFIG_DEBUG_NOOPT is not set
+# CONFIG_DEBUG_CUSTOMOPT is not set
+CONFIG_DEBUG_FULLOPT=y
+
+#
+# System Type
+#
+CONFIG_ARCH_ARM=y
+# CONFIG_ARCH_AVR is not set
+# CONFIG_ARCH_HC is not set
+# CONFIG_ARCH_MIPS is not set
+# CONFIG_ARCH_RGMP is not set
+# CONFIG_ARCH_RENESAS is not set
+# CONFIG_ARCH_SIM is not set
+# CONFIG_ARCH_X86 is not set
+# CONFIG_ARCH_Z16 is not set
+# CONFIG_ARCH_Z80 is not set
+CONFIG_ARCH="arm"
+
+#
+# ARM Options
+#
+# CONFIG_ARCH_CHIP_A1X is not set
+# CONFIG_ARCH_CHIP_C5471 is not set
+# CONFIG_ARCH_CHIP_CALYPSO is not set
+# CONFIG_ARCH_CHIP_DM320 is not set
+# CONFIG_ARCH_CHIP_EFM32 is not set
+# CONFIG_ARCH_CHIP_IMX1 is not set
+# CONFIG_ARCH_CHIP_IMX6 is not set
+# CONFIG_ARCH_CHIP_KINETIS is not set
+# CONFIG_ARCH_CHIP_KL is not set
+# CONFIG_ARCH_CHIP_LM is not set
+# CONFIG_ARCH_CHIP_TIVA is not set
+# CONFIG_ARCH_CHIP_LPC11XX is not set
+# CONFIG_ARCH_CHIP_LPC17XX is not set
+# CONFIG_ARCH_CHIP_LPC214X is not set
+# CONFIG_ARCH_CHIP_LPC2378 is not set
+# CONFIG_ARCH_CHIP_LPC31XX is not set
+# CONFIG_ARCH_CHIP_LPC43XX is not set
+# CONFIG_ARCH_CHIP_NUC1XX is not set
+# CONFIG_ARCH_CHIP_SAMA5 is not set
+# CONFIG_ARCH_CHIP_SAMD is not set
+# CONFIG_ARCH_CHIP_SAML is not set
+# CONFIG_ARCH_CHIP_SAM34 is not set
+# CONFIG_ARCH_CHIP_SAMV7 is not set
+CONFIG_ARCH_CHIP_STM32=y
+# CONFIG_ARCH_CHIP_STM32F7 is not set
+# CONFIG_ARCH_CHIP_STM32L4 is not set
+# CONFIG_ARCH_CHIP_STR71X is not set
+# CONFIG_ARCH_CHIP_TMS570 is not set
+# CONFIG_ARCH_CHIP_MOXART is not set
+# CONFIG_ARCH_ARM7TDMI is not set
+# CONFIG_ARCH_ARM926EJS is not set
+# CONFIG_ARCH_ARM920T is not set
+# CONFIG_ARCH_CORTEXM0 is not set
+CONFIG_ARCH_CORTEXM3=y
+# CONFIG_ARCH_CORTEXM4 is not set
+# CONFIG_ARCH_CORTEXM7 is not set
+# CONFIG_ARCH_CORTEXA5 is not set
+# CONFIG_ARCH_CORTEXA8 is not set
+# CONFIG_ARCH_CORTEXA9 is not set
+# CONFIG_ARCH_CORTEXR4 is not set
+# CONFIG_ARCH_CORTEXR4F is not set
+# CONFIG_ARCH_CORTEXR5 is not set
+# CONFIG_ARCH_CORTEX5F is not set
+# CONFIG_ARCH_CORTEXR7 is not set
+# CONFIG_ARCH_CORTEXR7F is not set
+CONFIG_ARCH_FAMILY="armv7-m"
+CONFIG_ARCH_CHIP="stm32"
+# CONFIG_ARM_TOOLCHAIN_IAR is not set
+CONFIG_ARM_TOOLCHAIN_GNU=y
+# CONFIG_ARMV7M_USEBASEPRI is not set
+CONFIG_ARCH_HAVE_CMNVECTOR=y
+# CONFIG_ARMV7M_CMNVECTOR is not set
+# CONFIG_ARMV7M_LAZYFPU is not set
+# CONFIG_ARCH_HAVE_FPU is not set
+# CONFIG_ARCH_HAVE_DPFPU is not set
+# CONFIG_ARCH_HAVE_TRUSTZONE is not set
+CONFIG_ARM_HAVE_MPU_UNIFIED=y
+# CONFIG_ARM_MPU is not set
+
+#
+# ARMV7M Configuration Options
+#
+# CONFIG_ARMV7M_HAVE_ICACHE is not set
+# CONFIG_ARMV7M_HAVE_DCACHE is not set
+# CONFIG_ARMV7M_HAVE_ITCM is not set
+# CONFIG_ARMV7M_HAVE_DTCM is not set
+# CONFIG_ARMV7M_TOOLCHAIN_IARL is not set
+# CONFIG_ARMV7M_TOOLCHAIN_BUILDROOT is not set
+# CONFIG_ARMV7M_TOOLCHAIN_CODEREDL is not set
+# CONFIG_ARMV7M_TOOLCHAIN_CODESOURCERYL is not set
+CONFIG_ARMV7M_TOOLCHAIN_GNU_EABIL=y
+CONFIG_ARMV7M_HAVE_STACKCHECK=y
+# CONFIG_ARMV7M_STACKCHECK is not set
+# CONFIG_ARMV7M_ITMSYSLOG is not set
+CONFIG_SERIAL_TERMIOS=y
+
+#
+# STM32 Configuration Options
+#
+# CONFIG_ARCH_CHIP_STM32L151C6 is not set
+# CONFIG_ARCH_CHIP_STM32L151C8 is not set
+# CONFIG_ARCH_CHIP_STM32L151CB is not set
+# CONFIG_ARCH_CHIP_STM32L151R6 is not set
+# CONFIG_ARCH_CHIP_STM32L151R8 is not set
+# CONFIG_ARCH_CHIP_STM32L151RB is not set
+# CONFIG_ARCH_CHIP_STM32L151V6 is not set
+# CONFIG_ARCH_CHIP_STM32L151V8 is not set
+# CONFIG_ARCH_CHIP_STM32L151VB is not set
+# CONFIG_ARCH_CHIP_STM32L152C6 is not set
+# CONFIG_ARCH_CHIP_STM32L152C8 is not set
+# CONFIG_ARCH_CHIP_STM32L152CB is not set
+# CONFIG_ARCH_CHIP_STM32L152R6 is not set
+# CONFIG_ARCH_CHIP_STM32L152R8 is not set
+# CONFIG_ARCH_CHIP_STM32L152RB is not set
+# CONFIG_ARCH_CHIP_STM32L152V6 is not set
+# CONFIG_ARCH_CHIP_STM32L152V8 is not set
+# CONFIG_ARCH_CHIP_STM32L152VB is not set
+# CONFIG_ARCH_CHIP_STM32L162ZD is not set
+# CONFIG_ARCH_CHIP_STM32L162VE is not set
+# CONFIG_ARCH_CHIP_STM32F100C8 is not set
+# CONFIG_ARCH_CHIP_STM32F100CB is not set
+# CONFIG_ARCH_CHIP_STM32F100R8 is not set
+# CONFIG_ARCH_CHIP_STM32F100RB is not set
+# CONFIG_ARCH_CHIP_STM32F100RC is not set
+# CONFIG_ARCH_CHIP_STM32F100RD is not set
+# CONFIG_ARCH_CHIP_STM32F100RE is not set
+# CONFIG_ARCH_CHIP_STM32F100V8 is not set
+# CONFIG_ARCH_CHIP_STM32F100VB is not set
+# CONFIG_ARCH_CHIP_STM32F100VC is not set
+# CONFIG_ARCH_CHIP_STM32F100VD is not set
+# CONFIG_ARCH_CHIP_STM32F100VE is not set
+# CONFIG_ARCH_CHIP_STM32F102CB is not set
+# CONFIG_ARCH_CHIP_STM32F103T8 is not set
+# CONFIG_ARCH_CHIP_STM32F103TB is not set
+# CONFIG_ARCH_CHIP_STM32F103C4 is not set
+CONFIG_ARCH_CHIP_STM32F103C8=y
+# CONFIG_ARCH_CHIP_STM32F103CB is not set
+# CONFIG_ARCH_CHIP_STM32F103R8 is not set
+# CONFIG_ARCH_CHIP_STM32F103RB is not set
+# CONFIG_ARCH_CHIP_STM32F103RC is not set
+# CONFIG_ARCH_CHIP_STM32F103RD is not set
+# CONFIG_ARCH_CHIP_STM32F103RE is not set
+# CONFIG_ARCH_CHIP_STM32F103RG is not set
+# CONFIG_ARCH_CHIP_STM32F103V8 is not set
+# CONFIG_ARCH_CHIP_STM32F103VB is not set
+# CONFIG_ARCH_CHIP_STM32F103VC is not set
+# CONFIG_ARCH_CHIP_STM32F103VE is not set
+# CONFIG_ARCH_CHIP_STM32F103ZE is not set
+# CONFIG_ARCH_CHIP_STM32F105VB is not set
+# CONFIG_ARCH_CHIP_STM32F105RB is not set
+# CONFIG_ARCH_CHIP_STM32F107VC is not set
+# CONFIG_ARCH_CHIP_STM32F205RG is not set
+# CONFIG_ARCH_CHIP_STM32F207IG is not set
+# CONFIG_ARCH_CHIP_STM32F207ZE is not set
+# CONFIG_ARCH_CHIP_STM32F302K6 is not set
+# CONFIG_ARCH_CHIP_STM32F302K8 is not set
+# CONFIG_ARCH_CHIP_STM32F302CB is not set
+# CONFIG_ARCH_CHIP_STM32F302CC is not set
+# CONFIG_ARCH_CHIP_STM32F302RB is not set
+# CONFIG_ARCH_CHIP_STM32F302RC is not set
+# CONFIG_ARCH_CHIP_STM32F302VB is not set
+# CONFIG_ARCH_CHIP_STM32F302VC is not set
+# CONFIG_ARCH_CHIP_STM32F303K6 is not set
+# CONFIG_ARCH_CHIP_STM32F303K8 is not set
+# CONFIG_ARCH_CHIP_STM32F303C6 is not set
+# CONFIG_ARCH_CHIP_STM32F303C8 is not set
+# CONFIG_ARCH_CHIP_STM32F303CB is not set
+# CONFIG_ARCH_CHIP_STM32F303CC is not set
+# CONFIG_ARCH_CHIP_STM32F303RB is not set
+# CONFIG_ARCH_CHIP_STM32F303RC is not set
+# CONFIG_ARCH_CHIP_STM32F303RD is not set
+# CONFIG_ARCH_CHIP_STM32F303RE is not set
+# CONFIG_ARCH_CHIP_STM32F303VB is not set
+# CONFIG_ARCH_CHIP_STM32F303VC is not set
+# CONFIG_ARCH_CHIP_STM32F372C8 is not set
+# CONFIG_ARCH_CHIP_STM32F372R8 is not set
+# CONFIG_ARCH_CHIP_STM32F372V8 is not set
+# CONFIG_ARCH_CHIP_STM32F372CB is not set
+# CONFIG_ARCH_CHIP_STM32F372RB is not set
+# CONFIG_ARCH_CHIP_STM32F372VB is not set
+# CONFIG_ARCH_CHIP_STM32F372CC is not set
+# CONFIG_ARCH_CHIP_STM32F372RC is not set
+# CONFIG_ARCH_CHIP_STM32F372VC is not set
+# CONFIG_ARCH_CHIP_STM32F373C8 is not set
+# CONFIG_ARCH_CHIP_STM32F373R8 is not set
+# CONFIG_ARCH_CHIP_STM32F373V8 is not set
+# CONFIG_ARCH_CHIP_STM32F373CB is not set
+# CONFIG_ARCH_CHIP_STM32F373RB is not set
+# CONFIG_ARCH_CHIP_STM32F373VB is not set
+# CONFIG_ARCH_CHIP_STM32F373CC is not set
+# CONFIG_ARCH_CHIP_STM32F373RC is not set
+# CONFIG_ARCH_CHIP_STM32F373VC is not set
+# CONFIG_ARCH_CHIP_STM32F401RE is not set
+# CONFIG_ARCH_CHIP_STM32F411RE is not set
+# CONFIG_ARCH_CHIP_STM32F411VE is not set
+# CONFIG_ARCH_CHIP_STM32F405RG is not set
+# CONFIG_ARCH_CHIP_STM32F405VG is not set
+# CONFIG_ARCH_CHIP_STM32F405ZG is not set
+# CONFIG_ARCH_CHIP_STM32F407VE is not set
+# CONFIG_ARCH_CHIP_STM32F407VG is not set
+# CONFIG_ARCH_CHIP_STM32F407ZE is not set
+# CONFIG_ARCH_CHIP_STM32F407ZG is not set
+# CONFIG_ARCH_CHIP_STM32F407IE is not set
+# CONFIG_ARCH_CHIP_STM32F407IG is not set
+# CONFIG_ARCH_CHIP_STM32F427V is not set
+# CONFIG_ARCH_CHIP_STM32F427Z is not set
+# CONFIG_ARCH_CHIP_STM32F427I is not set
+# CONFIG_ARCH_CHIP_STM32F429V is not set
+# CONFIG_ARCH_CHIP_STM32F429Z is not set
+# CONFIG_ARCH_CHIP_STM32F429I is not set
+# CONFIG_ARCH_CHIP_STM32F429B is not set
+# CONFIG_ARCH_CHIP_STM32F429N is not set
+# CONFIG_ARCH_CHIP_STM32F446M is not set
+# CONFIG_ARCH_CHIP_STM32F446R is not set
+# CONFIG_ARCH_CHIP_STM32F446V is not set
+# CONFIG_ARCH_CHIP_STM32F446Z is not set
+# CONFIG_ARCH_CHIP_STM32F469A is not set
+# CONFIG_ARCH_CHIP_STM32F469I is not set
+# CONFIG_ARCH_CHIP_STM32F469B is not set
+# CONFIG_ARCH_CHIP_STM32F469N is not set
+CONFIG_STM32_FLASH_CONFIG_DEFAULT=y
+# CONFIG_STM32_FLASH_CONFIG_4 is not set
+# CONFIG_STM32_FLASH_CONFIG_6 is not set
+# CONFIG_STM32_FLASH_CONFIG_8 is not set
+# CONFIG_STM32_FLASH_CONFIG_B is not set
+# CONFIG_STM32_FLASH_CONFIG_C is not set
+# CONFIG_STM32_FLASH_CONFIG_D is not set
+# CONFIG_STM32_FLASH_CONFIG_E is not set
+# CONFIG_STM32_FLASH_CONFIG_F is not set
+# CONFIG_STM32_FLASH_CONFIG_G is not set
+# CONFIG_STM32_FLASH_CONFIG_I is not set
+# CONFIG_STM32_STM32L15XX is not set
+# CONFIG_STM32_ENERGYLITE is not set
+CONFIG_STM32_STM32F10XX=y
+# CONFIG_STM32_VALUELINE is not set
+# CONFIG_STM32_CONNECTIVITYLINE is not set
+CONFIG_STM32_PERFORMANCELINE=y
+# CONFIG_STM32_USBACCESSLINE is not set
+# CONFIG_STM32_HIGHDENSITY is not set
+CONFIG_STM32_MEDIUMDENSITY=y
+# CONFIG_STM32_LOWDENSITY is not set
+# CONFIG_STM32_STM32F20XX is not set
+# CONFIG_STM32_STM32F205 is not set
+# CONFIG_STM32_STM32F207 is not set
+# CONFIG_STM32_STM32F30XX is not set
+# CONFIG_STM32_STM32F302 is not set
+# CONFIG_STM32_STM32F303 is not set
+# CONFIG_STM32_STM32F37XX is not set
+# CONFIG_STM32_STM32F40XX is not set
+# CONFIG_STM32_STM32F401 is not set
+# CONFIG_STM32_STM32F411 is not set
+# CONFIG_STM32_STM32F405 is not set
+# CONFIG_STM32_STM32F407 is not set
+# CONFIG_STM32_STM32F427 is not set
+# CONFIG_STM32_STM32F429 is not set
+# CONFIG_STM32_STM32F446 is not set
+# CONFIG_STM32_STM32F469 is not set
+# CONFIG_STM32_DFU is not set
+
+#
+# STM32 Peripheral Support
+#
+# CONFIG_STM32_HAVE_CCM is not set
+CONFIG_STM32_HAVE_USBDEV=y
+# CONFIG_STM32_HAVE_OTGFS is not set
+# CONFIG_STM32_HAVE_FSMC is not set
+# CONFIG_STM32_HAVE_LTDC is not set
+CONFIG_STM32_HAVE_USART3=y
+CONFIG_STM32_HAVE_UART4=y
+CONFIG_STM32_HAVE_UART5=y
+# CONFIG_STM32_HAVE_USART6 is not set
+# CONFIG_STM32_HAVE_UART7 is not set
+# CONFIG_STM32_HAVE_UART8 is not set
+CONFIG_STM32_HAVE_TIM1=y
+# CONFIG_STM32_HAVE_TIM2 is not set
+CONFIG_STM32_HAVE_TIM3=y
+CONFIG_STM32_HAVE_TIM4=y
+CONFIG_STM32_HAVE_TIM5=y
+CONFIG_STM32_HAVE_TIM6=y
+CONFIG_STM32_HAVE_TIM7=y
+CONFIG_STM32_HAVE_TIM8=y
+# CONFIG_STM32_HAVE_TIM9 is not set
+# CONFIG_STM32_HAVE_TIM10 is not set
+# CONFIG_STM32_HAVE_TIM11 is not set
+# CONFIG_STM32_HAVE_TIM12 is not set
+# CONFIG_STM32_HAVE_TIM13 is not set
+# CONFIG_STM32_HAVE_TIM14 is not set
+# CONFIG_STM32_HAVE_TIM15 is not set
+# CONFIG_STM32_HAVE_TIM16 is not set
+# CONFIG_STM32_HAVE_TIM17 is not set
+CONFIG_STM32_HAVE_ADC2=y
+CONFIG_STM32_HAVE_ADC3=y
+# CONFIG_STM32_HAVE_ADC4 is not set
+# CONFIG_STM32_HAVE_ADC1_DMA is not set
+# CONFIG_STM32_HAVE_ADC2_DMA is not set
+# CONFIG_STM32_HAVE_ADC3_DMA is not set
+# CONFIG_STM32_HAVE_ADC4_DMA is not set
+CONFIG_STM32_HAVE_CAN1=y
+# CONFIG_STM32_HAVE_CAN2 is not set
+# CONFIG_STM32_HAVE_DAC1 is not set
+# CONFIG_STM32_HAVE_DAC2 is not set
+# CONFIG_STM32_HAVE_RNG is not set
+# CONFIG_STM32_HAVE_ETHMAC is not set
+CONFIG_STM32_HAVE_I2C2=y
+# CONFIG_STM32_HAVE_I2C3 is not set
+CONFIG_STM32_HAVE_SPI2=y
+CONFIG_STM32_HAVE_SPI3=y
+# CONFIG_STM32_HAVE_SPI4 is not set
+# CONFIG_STM32_HAVE_SPI5 is not set
+# CONFIG_STM32_HAVE_SPI6 is not set
+# CONFIG_STM32_HAVE_SAIPLL is not set
+# CONFIG_STM32_HAVE_I2SPLL is not set
+# CONFIG_STM32_ADC1 is not set
+# CONFIG_STM32_ADC2 is not set
+# CONFIG_STM32_ADC3 is not set
+# CONFIG_STM32_BKP is not set
+# CONFIG_STM32_CAN1 is not set
+# CONFIG_STM32_CRC is not set
+# CONFIG_STM32_DMA1 is not set
+# CONFIG_STM32_DMA2 is not set
+# CONFIG_STM32_I2C1 is not set
+# CONFIG_STM32_I2C2 is not set
+# CONFIG_STM32_PWR is not set
+# CONFIG_STM32_SDIO is not set
+# CONFIG_STM32_SPI1 is not set
+# CONFIG_STM32_SPI2 is not set
+# CONFIG_STM32_SPI3 is not set
+# CONFIG_STM32_TIM1 is not set
+# CONFIG_STM32_TIM2 is not set
+# CONFIG_STM32_TIM3 is not set
+# CONFIG_STM32_TIM4 is not set
+# CONFIG_STM32_TIM5 is not set
+# CONFIG_STM32_TIM6 is not set
+# CONFIG_STM32_TIM7 is not set
+# CONFIG_STM32_TIM8 is not set
+CONFIG_STM32_USART1=y
+# CONFIG_STM32_USART2 is not set
+# CONFIG_STM32_USART3 is not set
+# CONFIG_STM32_UART4 is not set
+# CONFIG_STM32_UART5 is not set
+# CONFIG_STM32_USB is not set
+# CONFIG_STM32_IWDG is not set
+# CONFIG_STM32_WWDG is not set
+# CONFIG_STM32_NOEXT_VECTORS is not set
+
+#
+# Alternate Pin Mapping
+#
+# CONFIG_STM32_USART1_REMAP is not set
+# CONFIG_STM32_JTAG_DISABLE is not set
+CONFIG_STM32_JTAG_FULL_ENABLE=y
+# CONFIG_STM32_JTAG_NOJNTRST_ENABLE is not set
+# CONFIG_STM32_JTAG_SW_ENABLE is not set
+CONFIG_STM32_DISABLE_IDLE_SLEEP_DURING_DEBUG=y
+# CONFIG_STM32_FORCEPOWER is not set
+# CONFIG_ARCH_BOARD_STM32_CUSTOM_CLOCKCONFIG is not set
+
+#
+# Timer Configuration
+#
+# CONFIG_STM32_ONESHOT is not set
+# CONFIG_STM32_FREERUN is not set
+# CONFIG_STM32_TIM1_CAP is not set
+# CONFIG_STM32_TIM3_CAP is not set
+# CONFIG_STM32_TIM4_CAP is not set
+# CONFIG_STM32_TIM5_CAP is not set
+# CONFIG_STM32_TIM8_CAP is not set
+CONFIG_STM32_USART=y
+CONFIG_STM32_SERIALDRIVER=y
+
+#
+# U[S]ART Configuration
+#
+
+#
+# U[S]ART Device Configuration
+#
+CONFIG_STM32_USART1_SERIALDRIVER=y
+# CONFIG_STM32_USART1_1WIREDRIVER is not set
+# CONFIG_USART1_RS485 is not set
+
+#
+# Serial Driver Configuration
+#
+# CONFIG_SERIAL_DISABLE_REORDERING is not set
+# CONFIG_STM32_FLOWCONTROL_BROKEN is not set
+# CONFIG_STM32_USART_BREAKS is not set
+# CONFIG_STM32_USART_SINGLEWIRE is not set
+CONFIG_STM32_HAVE_RTC_COUNTER=y
+# CONFIG_STM32_HAVE_RTC_SUBSECONDS is not set
+
+#
+# USB FS Host Configuration
+#
+
+#
+# USB HS Host Configuration
+#
+
+#
+# USB Host Debug Configuration
+#
+
+#
+# USB Device Configuration
+#
+
+#
+# Architecture Options
+#
+# CONFIG_ARCH_NOINTC is not set
+# CONFIG_ARCH_VECNOTIRQ is not set
+# CONFIG_ARCH_DMA is not set
+CONFIG_ARCH_HAVE_IRQPRIO=y
+# CONFIG_ARCH_L2CACHE is not set
+# CONFIG_ARCH_HAVE_COHERENT_DCACHE is not set
+# CONFIG_ARCH_HAVE_ADDRENV is not set
+# CONFIG_ARCH_NEED_ADDRENV_MAPPING is not set
+# CONFIG_ARCH_HAVE_MULTICPU is not set
+CONFIG_ARCH_HAVE_VFORK=y
+# CONFIG_ARCH_HAVE_MMU is not set
+CONFIG_ARCH_HAVE_MPU=y
+# CONFIG_ARCH_NAND_HWECC is not set
+# CONFIG_ARCH_HAVE_EXTCLK is not set
+# CONFIG_ARCH_HAVE_POWEROFF is not set
+CONFIG_ARCH_HAVE_RESET=y
+# CONFIG_ARCH_USE_MPU is not set
+# CONFIG_ARCH_IRQPRIO is not set
+CONFIG_ARCH_STACKDUMP=y
+# CONFIG_ENDIAN_BIG is not set
+# CONFIG_ARCH_IDLE_CUSTOM is not set
+# CONFIG_ARCH_HAVE_RAMFUNCS is not set
+CONFIG_ARCH_HAVE_RAMVECTORS=y
+# CONFIG_ARCH_RAMVECTORS is not set
+
+#
+# Board Settings
+#
+CONFIG_BOARD_LOOPSPERMSEC=5483
+# CONFIG_ARCH_CALIBRATION is not set
+
+#
+# Interrupt options
+#
+CONFIG_ARCH_HAVE_INTERRUPTSTACK=y
+CONFIG_ARCH_INTERRUPTSTACK=0
+CONFIG_ARCH_HAVE_HIPRI_INTERRUPT=y
+# CONFIG_ARCH_HIPRI_INTERRUPT is not set
+
+#
+# Boot options
+#
+# CONFIG_BOOT_RUNFROMEXTSRAM is not set
+CONFIG_BOOT_RUNFROMFLASH=y
+# CONFIG_BOOT_RUNFROMISRAM is not set
+# CONFIG_BOOT_RUNFROMSDRAM is not set
+# CONFIG_BOOT_COPYTORAM is not set
+
+#
+# Boot Memory Configuration
+#
+CONFIG_RAM_START=0x20000000
+CONFIG_RAM_SIZE=20480
+# CONFIG_ARCH_HAVE_SDRAM is not set
+
+#
+# Board Selection
+#
+# CONFIG_ARCH_BOARD_STM32_TINY is not set
+CONFIG_ARCH_BOARD_STM32F103_MINIMUM=y
+# CONFIG_ARCH_BOARD_CUSTOM is not set
+CONFIG_ARCH_BOARD="stm32f103-minimum"
+
+#
+# Common Board Options
+#
+CONFIG_ARCH_HAVE_LEDS=y
+# CONFIG_ARCH_LEDS is not set
+
+#
+# Board-Specific Options
+#
+# CONFIG_BOARD_CRASHDUMP is not set
+CONFIG_LIB_BOARDCTL=y
+# CONFIG_BOARDCTL_RESET is not set
+# CONFIG_BOARDCTL_UNIQUEID is not set
+# CONFIG_BOARDCTL_TSCTEST is not set
+# CONFIG_BOARDCTL_ADCTEST is not set
+# CONFIG_BOARDCTL_PWMTEST is not set
+# CONFIG_BOARDCTL_GRAPHICS is not set
+# CONFIG_BOARDCTL_IOCTL is not set
+
+#
+# RTOS Features
+#
+# CONFIG_DISABLE_OS_API is not set
+
+#
+# Clocks and Timers
+#
+CONFIG_ARCH_HAVE_TICKLESS=y
+# CONFIG_SCHED_TICKLESS is not set
+CONFIG_USEC_PER_TICK=10000
+# CONFIG_SYSTEM_TIME64 is not set
+# CONFIG_CLOCK_MONOTONIC is not set
+CONFIG_ARCH_HAVE_TIMEKEEPING=y
+# CONFIG_JULIAN_TIME is not set
+CONFIG_START_YEAR=2011
+CONFIG_START_MONTH=7
+CONFIG_START_DAY=5
+CONFIG_MAX_WDOGPARMS=2
+CONFIG_PREALLOC_WDOGS=4
+CONFIG_WDOG_INTRESERVE=0
+CONFIG_PREALLOC_TIMERS=4
+
+#
+# Tasks and Scheduling
+#
+# CONFIG_INIT_NONE is not set
+CONFIG_INIT_ENTRYPOINT=y
+# CONFIG_INIT_FILEPATH is not set
+CONFIG_USER_ENTRYPOINT="nsh_main"
+CONFIG_RR_INTERVAL=200
+# CONFIG_SCHED_SPORADIC is not set
+CONFIG_TASK_NAME_SIZE=0
+CONFIG_MAX_TASKS=16
+# CONFIG_SCHED_HAVE_PARENT is not set
+CONFIG_SCHED_WAITPID=y
+
+#
+# Pthread Options
+#
+# CONFIG_MUTEX_TYPES is not set
+CONFIG_NPTHREAD_KEYS=4
+
+#
+# Performance Monitoring
+#
+# CONFIG_SCHED_CPULOAD is not set
+# CONFIG_SCHED_INSTRUMENTATION is not set
+
+#
+# Files and I/O
+#
+CONFIG_DEV_CONSOLE=y
+# CONFIG_FDCLONE_DISABLE is not set
+# CONFIG_FDCLONE_STDIO is not set
+CONFIG_SDCLONE_DISABLE=y
+CONFIG_NFILE_DESCRIPTORS=8
+CONFIG_NFILE_STREAMS=8
+CONFIG_NAME_MAX=32
+# CONFIG_PRIORITY_INHERITANCE is not set
+
+#
+# RTOS hooks
+#
+CONFIG_BOARD_INITIALIZE=y
+# CONFIG_BOARD_INITTHREAD is not set
+# CONFIG_SCHED_STARTHOOK is not set
+# CONFIG_SCHED_ATEXIT is not set
+# CONFIG_SCHED_ONEXIT is not set
+# CONFIG_SIG_EVTHREAD is not set
+
+#
+# Signal Numbers
+#
+CONFIG_SIG_SIGUSR1=1
+CONFIG_SIG_SIGUSR2=2
+CONFIG_SIG_SIGALARM=3
+CONFIG_SIG_SIGCONDTIMEDOUT=16
+CONFIG_SIG_SIGWORK=17
+
+#
+# POSIX Message Queue Options
+#
+CONFIG_PREALLOC_MQ_MSGS=4
+CONFIG_MQ_MAXMSGSIZE=32
+# CONFIG_MODULE is not set
+
+#
+# Work queue support
+#
+CONFIG_SCHED_WORKQUEUE=y
+CONFIG_SCHED_HPWORK=y
+CONFIG_SCHED_HPWORKPRIORITY=192
+CONFIG_SCHED_HPWORKPERIOD=50000
+CONFIG_SCHED_HPWORKSTACKSIZE=2048
+# CONFIG_SCHED_LPWORK is not set
+
+#
+# Stack and heap information
+#
+CONFIG_IDLETHREAD_STACKSIZE=1024
+CONFIG_USERMAIN_STACKSIZE=2048
+CONFIG_PTHREAD_STACK_MIN=256
+CONFIG_PTHREAD_STACK_DEFAULT=2048
+# CONFIG_LIB_SYSCALL is not set
+
+#
+# Device Drivers
+#
+# CONFIG_DISABLE_POLL is not set
+CONFIG_DEV_NULL=y
+# CONFIG_DEV_ZERO is not set
+# CONFIG_DEV_URANDOM is not set
+# CONFIG_DEV_LOOP is not set
+
+#
+# Buffering
+#
+# CONFIG_DRVR_WRITEBUFFER is not set
+# CONFIG_DRVR_READAHEAD is not set
+# CONFIG_RAMDISK is not set
+# CONFIG_CAN is not set
+# CONFIG_ARCH_HAVE_PWM_PULSECOUNT is not set
+# CONFIG_ARCH_HAVE_PWM_MULTICHAN is not set
+# CONFIG_PWM is not set
+CONFIG_ARCH_HAVE_I2CRESET=y
+# CONFIG_I2C is not set
+# CONFIG_SPI is not set
+CONFIG_ARCH_HAVE_SPI_BITORDER=y
+# CONFIG_I2S is not set
+
+#
+# Timer Driver Support
+#
+# CONFIG_TIMER is not set
+# CONFIG_ONESHOT is not set
+# CONFIG_RTC is not set
+# CONFIG_WATCHDOG is not set
+# CONFIG_ANALOG is not set
+# CONFIG_AUDIO_DEVICES is not set
+# CONFIG_VIDEO_DEVICES is not set
+# CONFIG_BCH is not set
+# CONFIG_INPUT is not set
+
+#
+# IO Expander/GPIO Support
+#
+# CONFIG_IOEXPANDER is not set
+# CONFIG_DEV_GPIO is not set
+
+#
+# LCD Driver Support
+#
+# CONFIG_LCD is not set
+# CONFIG_SLCD is not set
+
+#
+# LED Support
+#
+CONFIG_USERLED=y
+CONFIG_USERLED_LOWER=y
+# CONFIG_RGBLED is not set
+# CONFIG_PCA9635PW is not set
+# CONFIG_NCP5623C is not set
+# CONFIG_MMCSD is not set
+# CONFIG_MODEM is not set
+# CONFIG_MTD is not set
+# CONFIG_EEPROM is not set
+# CONFIG_PIPES is not set
+# CONFIG_PM is not set
+# CONFIG_POWER is not set
+# CONFIG_SENSORS is not set
+# CONFIG_SERCOMM_CONSOLE is not set
+CONFIG_SERIAL=y
+# CONFIG_DEV_LOWCONSOLE is not set
+# CONFIG_SERIAL_REMOVABLE is not set
+CONFIG_SERIAL_CONSOLE=y
+# CONFIG_16550_UART is not set
+# CONFIG_UART_SERIALDRIVER is not set
+# CONFIG_UART0_SERIALDRIVER is not set
+# CONFIG_UART1_SERIALDRIVER is not set
+# CONFIG_UART2_SERIALDRIVER is not set
+# CONFIG_UART3_SERIALDRIVER is not set
+# CONFIG_UART4_SERIALDRIVER is not set
+# CONFIG_UART5_SERIALDRIVER is not set
+# CONFIG_UART6_SERIALDRIVER is not set
+# CONFIG_UART7_SERIALDRIVER is not set
+# CONFIG_UART8_SERIALDRIVER is not set
+# CONFIG_SCI0_SERIALDRIVER is not set
+# CONFIG_SCI1_SERIALDRIVER is not set
+# CONFIG_USART0_SERIALDRIVER is not set
+CONFIG_USART1_SERIALDRIVER=y
+# CONFIG_USART2_SERIALDRIVER is not set
+# CONFIG_USART3_SERIALDRIVER is not set
+# CONFIG_USART4_SERIALDRIVER is not set
+# CONFIG_USART5_SERIALDRIVER is not set
+# CONFIG_USART6_SERIALDRIVER is not set
+# CONFIG_USART7_SERIALDRIVER is not set
+# CONFIG_USART8_SERIALDRIVER is not set
+# CONFIG_OTHER_UART_SERIALDRIVER is not set
+CONFIG_MCU_SERIAL=y
+CONFIG_STANDARD_SERIAL=y
+CONFIG_SERIAL_NPOLLWAITERS=2
+# CONFIG_SERIAL_IFLOWCONTROL is not set
+# CONFIG_SERIAL_OFLOWCONTROL is not set
+# CONFIG_SERIAL_DMA is not set
+CONFIG_ARCH_HAVE_SERIAL_TERMIOS=y
+CONFIG_USART1_SERIAL_CONSOLE=y
+# CONFIG_OTHER_SERIAL_CONSOLE is not set
+# CONFIG_NO_SERIAL_CONSOLE is not set
+
+#
+# USART1 Configuration
+#
+CONFIG_USART1_RXBUFSIZE=256
+CONFIG_USART1_TXBUFSIZE=256
+CONFIG_USART1_BAUD=115200
+CONFIG_USART1_BITS=8
+CONFIG_USART1_PARITY=0
+CONFIG_USART1_2STOP=0
+# CONFIG_USART1_IFLOWCONTROL is not set
+# CONFIG_USART1_OFLOWCONTROL is not set
+# CONFIG_USART1_DMA is not set
+# CONFIG_PSEUDOTERM is not set
+# CONFIG_USBDEV is not set
+# CONFIG_USBHOST is not set
+# CONFIG_HAVE_USBTRACE is not set
+# CONFIG_DRIVERS_WIRELESS is not set
+# CONFIG_DRIVERS_CONTACTLESS is not set
+
+#
+# System Logging
+#
+# CONFIG_ARCH_SYSLOG is not set
+# CONFIG_RAMLOG is not set
+# CONFIG_SYSLOG_INTBUFFER is not set
+# CONFIG_SYSLOG_TIMESTAMP is not set
+CONFIG_SYSLOG_SERIAL_CONSOLE=y
+# CONFIG_SYSLOG_CHAR is not set
+CONFIG_SYSLOG_CONSOLE=y
+# CONFIG_SYSLOG_NONE is not set
+# CONFIG_SYSLOG_FILE is not set
+# CONFIG_SYSLOG_CHARDEV is not set
+
+#
+# Networking Support
+#
+# CONFIG_ARCH_HAVE_NET is not set
+# CONFIG_ARCH_HAVE_PHY is not set
+# CONFIG_NET is not set
+
+#
+# Crypto API
+#
+# CONFIG_CRYPTO is not set
+
+#
+# File Systems
+#
+
+#
+# File system configuration
+#
+# CONFIG_DISABLE_MOUNTPOINT is not set
+# CONFIG_FS_AUTOMOUNTER is not set
+CONFIG_DISABLE_PSEUDOFS_OPERATIONS=y
+# CONFIG_FS_READABLE is not set
+# CONFIG_FS_WRITABLE is not set
+# CONFIG_FS_NAMED_SEMAPHORES is not set
+CONFIG_FS_MQUEUE_MPATH="/var/mqueue"
+# CONFIG_FS_RAMMAP is not set
+# CONFIG_FS_FAT is not set
+# CONFIG_FS_NXFFS is not set
+# CONFIG_FS_ROMFS is not set
+# CONFIG_FS_TMPFS is not set
+# CONFIG_FS_SMARTFS is not set
+# CONFIG_FS_BINFS is not set
+# CONFIG_FS_PROCFS is not set
+# CONFIG_FS_UNIONFS is not set
+
+#
+# Graphics Support
+#
+# CONFIG_NX is not set
+
+#
+# Memory Management
+#
+# CONFIG_MM_SMALL is not set
+CONFIG_MM_REGIONS=1
+# CONFIG_ARCH_HAVE_HEAP2 is not set
+# CONFIG_GRAN is not set
+
+#
+# Audio Support
+#
+# CONFIG_AUDIO is not set
+
+#
+# Wireless Support
+#
+
+#
+# Binary Loader
+#
+# CONFIG_BINFMT_DISABLE is not set
+# CONFIG_BINFMT_EXEPATH is not set
+# CONFIG_NXFLAT is not set
+# CONFIG_ELF is not set
+CONFIG_BUILTIN=y
+# CONFIG_PIC is not set
+CONFIG_SYMTAB_ORDEREDBYNAME=y
+
+#
+# Library Routines
+#
+
+#
+# Standard C Library Options
+#
+CONFIG_STDIO_BUFFER_SIZE=64
+CONFIG_STDIO_LINEBUFFER=y
+CONFIG_NUNGET_CHARS=2
+CONFIG_LIB_HOMEDIR="/"
+# CONFIG_LIBM is not set
+# CONFIG_NOPRINTF_FIELDWIDTH is not set
+# CONFIG_LIBC_FLOATINGPOINT is not set
+# CONFIG_LIBC_LONG_LONG is not set
+# CONFIG_LIBC_IOCTL_VARIADIC is not set
+CONFIG_LIB_RAND_ORDER=1
+# CONFIG_EOL_IS_CR is not set
+# CONFIG_EOL_IS_LF is not set
+# CONFIG_EOL_IS_BOTH_CRLF is not set
+CONFIG_EOL_IS_EITHER_CRLF=y
+# CONFIG_LIBC_EXECFUNCS is not set
+CONFIG_POSIX_SPAWN_PROXY_STACKSIZE=1024
+CONFIG_TASK_SPAWN_DEFAULT_STACKSIZE=2048
+# CONFIG_LIBC_STRERROR is not set
+# CONFIG_LIBC_PERROR_STDOUT is not set
+CONFIG_ARCH_LOWPUTC=y
+# CONFIG_LIBC_LOCALTIME is not set
+# CONFIG_TIME_EXTENDED is not set
+CONFIG_LIB_SENDFILE_BUFSIZE=512
+# CONFIG_ARCH_ROMGETC is not set
+# CONFIG_ARCH_OPTIMIZED_FUNCTIONS is not set
+CONFIG_ARCH_HAVE_TLS=y
+# CONFIG_TLS is not set
+# CONFIG_LIBC_NETDB is not set
+
+#
+# Non-standard Library Support
+#
+# CONFIG_LIB_CRC64_FAST is not set
+# CONFIG_LIB_KBDCODEC is not set
+# CONFIG_LIB_SLCDCODEC is not set
+# CONFIG_LIB_HEX2BIN is not set
+
+#
+# Basic CXX Support
+#
+# CONFIG_C99_BOOL8 is not set
+# CONFIG_HAVE_CXX is not set
+
+#
+# Application Configuration
+#
+
+#
+# Built-In Applications
+#
+CONFIG_BUILTIN_PROXY_STACKSIZE=1024
+
+#
+# CAN Utilities
+#
+
+#
+# Examples
+#
+# CONFIG_EXAMPLES_CHAT is not set
+# CONFIG_EXAMPLES_CONFIGDATA is not set
+# CONFIG_EXAMPLES_DHCPD is not set
+# CONFIG_EXAMPLES_ELF is not set
+# CONFIG_EXAMPLES_FTPC is not set
+# CONFIG_EXAMPLES_FTPD is not set
+# CONFIG_EXAMPLES_HELLO is not set
+# CONFIG_EXAMPLES_HIDKBD is not set
+# CONFIG_EXAMPLES_IGMP is not set
+# CONFIG_EXAMPLES_JSON is not set
+# CONFIG_EXAMPLES_KEYPADTEST is not set
+CONFIG_EXAMPLES_LEDS=y
+CONFIG_EXAMPLES_LEDS_PRIORITY=100
+CONFIG_EXAMPLES_LEDS_STACKSIZE=2048
+CONFIG_EXAMPLES_LEDS_DEVPATH="/dev/userleds"
+CONFIG_EXAMPLES_LEDS_LEDSET=0x0f
+# CONFIG_EXAMPLES_MEDIA is not set
+# CONFIG_EXAMPLES_MM is not set
+# CONFIG_EXAMPLES_MODBUS is not set
+# CONFIG_EXAMPLES_MOUNT is not set
+# CONFIG_EXAMPLES_NRF24L01TERM is not set
+CONFIG_EXAMPLES_NSH=y
+# CONFIG_EXAMPLES_NULL is not set
+# CONFIG_EXAMPLES_NX is not set
+# CONFIG_EXAMPLES_NXFFS is not set
+# CONFIG_EXAMPLES_NXHELLO is not set
+# CONFIG_EXAMPLES_NXIMAGE is not set
+# CONFIG_EXAMPLES_NXLINES is not set
+# CONFIG_EXAMPLES_NXTERM is not set
+# CONFIG_EXAMPLES_NXTEXT is not set
+# CONFIG_EXAMPLES_OSTEST is not set
+# CONFIG_EXAMPLES_PCA9635 is not set
+# CONFIG_EXAMPLES_POSIXSPAWN is not set
+# CONFIG_EXAMPLES_PPPD is not set
+# CONFIG_EXAMPLES_RFID_READUID is not set
+# CONFIG_EXAMPLES_RGBLED is not set
+# CONFIG_EXAMPLES_RGMP is not set
+# CONFIG_EXAMPLES_SENDMAIL is not set
+# CONFIG_EXAMPLES_SERIALBLASTER is not set
+# CONFIG_EXAMPLES_SERIALRX is not set
+# CONFIG_EXAMPLES_SERLOOP is not set
+# CONFIG_EXAMPLES_SLCD is not set
+# CONFIG_EXAMPLES_SMART is not set
+# CONFIG_EXAMPLES_SMART_TEST is not set
+# CONFIG_EXAMPLES_SMP is not set
+# CONFIG_EXAMPLES_TCPECHO is not set
+# CONFIG_EXAMPLES_TELNETD is not set
+# CONFIG_EXAMPLES_TIFF is not set
+# CONFIG_EXAMPLES_TOUCHSCREEN is not set
+# CONFIG_EXAMPLES_USBSERIAL is not set
+# CONFIG_EXAMPLES_USBTERM is not set
+# CONFIG_EXAMPLES_WATCHDOG is not set
+# CONFIG_EXAMPLES_WEBSERVER is not set
+
+#
+# File System Utilities
+#
+# CONFIG_FSUTILS_INIFILE is not set
+
+#
+# GPS Utilities
+#
+# CONFIG_GPSUTILS_MINMEA_LIB is not set
+
+#
+# Graphics Support
+#
+# CONFIG_TIFF is not set
+# CONFIG_GRAPHICS_TRAVELER is not set
+
+#
+# Interpreters
+#
+# CONFIG_INTERPRETERS_FICL is not set
+# CONFIG_INTERPRETERS_MICROPYTHON is not set
+# CONFIG_INTERPRETERS_MINIBASIC is not set
+# CONFIG_INTERPRETERS_PCODE is not set
+
+#
+# FreeModBus
+#
+# CONFIG_MODBUS is not set
+
+#
+# Network Utilities
+#
+# CONFIG_NETUTILS_CHAT is not set
+# CONFIG_NETUTILS_CODECS is not set
+# CONFIG_NETUTILS_ESP8266 is not set
+# CONFIG_NETUTILS_FTPC is not set
+# CONFIG_NETUTILS_JSON is not set
+# CONFIG_NETUTILS_SMTP is not set
+
+#
+# NSH Library
+#
+CONFIG_NSH_LIBRARY=y
+# CONFIG_NSH_MOTD is not set
+
+#
+# Command Line Configuration
+#
+CONFIG_NSH_READLINE=y
+# CONFIG_NSH_CLE is not set
+CONFIG_NSH_LINELEN=80
+CONFIG_NSH_DISABLE_SEMICOLON=y
+# CONFIG_NSH_CMDPARMS is not set
+CONFIG_NSH_MAXARGUMENTS=6
+# CONFIG_NSH_ARGCAT is not set
+CONFIG_NSH_NESTDEPTH=3
+CONFIG_NSH_DISABLEBG=y
+CONFIG_NSH_BUILTIN_APPS=y
+
+#
+# Disable Individual commands
+#
+CONFIG_NSH_DISABLE_ADDROUTE=y
+CONFIG_NSH_DISABLE_BASENAME=y
+# CONFIG_NSH_DISABLE_CAT is not set
+# CONFIG_NSH_DISABLE_CD is not set
+# CONFIG_NSH_DISABLE_CP is not set
+CONFIG_NSH_DISABLE_CMP=y
+CONFIG_NSH_DISABLE_DATE=y
+# CONFIG_NSH_DISABLE_DD is not set
+CONFIG_NSH_DISABLE_DF=y
+CONFIG_NSH_DISABLE_DELROUTE=y
+CONFIG_NSH_DISABLE_DIRNAME=y
+# CONFIG_NSH_DISABLE_ECHO is not set
+# CONFIG_NSH_DISABLE_EXEC is not set
+# CONFIG_NSH_DISABLE_EXIT is not set
+# CONFIG_NSH_DISABLE_FREE is not set
+# CONFIG_NSH_DISABLE_GET is not set
+# CONFIG_NSH_DISABLE_HELP is not set
+# CONFIG_NSH_DISABLE_HEXDUMP is not set
+CONFIG_NSH_DISABLE_IFCONFIG=y
+CONFIG_NSH_DISABLE_IFUPDOWN=y
+# CONFIG_NSH_DISABLE_KILL is not set
+CONFIG_NSH_DISABLE_LOSETUP=y
+CONFIG_NSH_DISABLE_LOSMART=y
+# CONFIG_NSH_DISABLE_LS is not set
+# CONFIG_NSH_DISABLE_MB is not set
+# CONFIG_NSH_DISABLE_MKDIR is not set
+# CONFIG_NSH_DISABLE_MKRD is not set
+# CONFIG_NSH_DISABLE_MH is not set
+# CONFIG_NSH_DISABLE_MOUNT is not set
+# CONFIG_NSH_DISABLE_MV is not set
+# CONFIG_NSH_DISABLE_MW is not set
+# CONFIG_NSH_DISABLE_PS is not set
+# CONFIG_NSH_DISABLE_PUT is not set
+# CONFIG_NSH_DISABLE_PWD is not set
+# CONFIG_NSH_DISABLE_RM is not set
+# CONFIG_NSH_DISABLE_RMDIR is not set
+# CONFIG_NSH_DISABLE_SET is not set
+# CONFIG_NSH_DISABLE_SH is not set
+# CONFIG_NSH_DISABLE_SLEEP is not set
+CONFIG_NSH_DISABLE_TIME=y
+# CONFIG_NSH_DISABLE_TEST is not set
+# CONFIG_NSH_DISABLE_UMOUNT is not set
+CONFIG_NSH_DISABLE_UNAME=y
+# CONFIG_NSH_DISABLE_UNSET is not set
+# CONFIG_NSH_DISABLE_USLEEP is not set
+# CONFIG_NSH_DISABLE_WGET is not set
+# CONFIG_NSH_DISABLE_XD is not set
+CONFIG_NSH_MMCSDMINOR=0
+
+#
+# Configure Command Options
+#
+CONFIG_NSH_CODECS_BUFSIZE=128
+# CONFIG_NSH_CMDOPT_HEXDUMP is not set
+CONFIG_NSH_FILEIOSIZE=1024
+
+#
+# Scripting Support
+#
+# CONFIG_NSH_DISABLESCRIPT is not set
+CONFIG_NSH_DISABLE_ITEF=y
+CONFIG_NSH_DISABLE_LOOPS=y
+
+#
+# Console Configuration
+#
+CONFIG_NSH_CONSOLE=y
+# CONFIG_NSH_ALTCONDEV is not set
+CONFIG_NSH_ARCHINIT=y
+# CONFIG_NSH_LOGIN is not set
+# CONFIG_NSH_CONSOLE_LOGIN is not set
+
+#
+# NxWidgets/NxWM
+#
+
+#
+# Platform-specific Support
+#
+# CONFIG_PLATFORM_CONFIGDATA is not set
+
+#
+# System Libraries and NSH Add-Ons
+#
+# CONFIG_SYSTEM_CLE is not set
+# CONFIG_SYSTEM_CUTERM is not set
+# CONFIG_SYSTEM_FREE is not set
+# CONFIG_SYSTEM_HEX2BIN is not set
+# CONFIG_SYSTEM_HEXED is not set
+# CONFIG_SYSTEM_INSTALL is not set
+# CONFIG_SYSTEM_RAMTEST is not set
+CONFIG_READLINE_HAVE_EXTMATCH=y
+CONFIG_SYSTEM_READLINE=y
+CONFIG_READLINE_ECHO=y
+# CONFIG_READLINE_TABCOMPLETION is not set
+# CONFIG_READLINE_CMD_HISTORY is not set
+# CONFIG_SYSTEM_SUDOKU is not set
+# CONFIG_SYSTEM_SYSTEM is not set
+# CONFIG_SYSTEM_TEE is not set
+# CONFIG_SYSTEM_UBLOXMODEM is not set
+# CONFIG_SYSTEM_VI is not set
+# CONFIG_SYSTEM_ZMODEM is not set
diff --git a/configs/stm32f103-minimum/userled/setenv.sh b/configs/stm32f103-minimum/userled/setenv.sh
new file mode 100644
index 0000000000..73dfab5a4d
--- /dev/null
+++ b/configs/stm32f103-minimum/userled/setenv.sh
@@ -0,0 +1,100 @@
+#!/bin/bash
+# configs//stm32f103-minimum/nsh/setenv.sh
+#
+# Copyright (C) 2016 Gregory Nutt. All rights reserved.
+# Author: Gregory Nutt
+#
+# 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.
+#
+
+# 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.
+#
+
+if [ "$_" = "$0" ] ; then
+ echo "You must source this script, not run it!" 1>&2
+ exit 1
+fi
+
+WD=`pwd`
+if [ ! -x "setenv.sh" ]; then
+ echo "This script must be executed from the top-level NuttX build directory"
+ exit 1
+fi
+
+if [ -z "${PATH_ORIG}" ]; then
+ export PATH_ORIG="${PATH}"
+fi
+
+# This is the Cygwin path to the location where I installed the CodeSourcery
+# toolchain under windows. You will also have to edit this if you install
+# the CodeSourcery toolchain in any other location
+#export TOOLCHAIN_BIN="/cygdrive/c/Program Files (x86)/CodeSourcery/Sourcery G++ Lite/bin"
+#export TOOLCHAIN_BIN="/cygdrive/c/Program Files (x86)/CodeSourcery/Sourcery_CodeBench_Lite_for_ARM_EABI/bin"
+# export TOOLCHAIN_BIN="/cygdrive/c/Users/MyName/MentorGraphics/Sourcery_CodeBench_Lite_for_ARM_EABI/bin"
+
+# This is the location where I installed the ARM "GNU Tools for ARM Embedded Processors"
+# You can this free toolchain here https://launchpad.net/gcc-arm-embedded
+export TOOLCHAIN_BIN="/cygdrive/c/Program Files (x86)/GNU Tools ARM Embedded/4.9 2015q2/bin"
+
+# This is the path to the location where I installed the devkitARM toolchain
+# You can get this free toolchain from http://devkitpro.org/ or http://sourceforge.net/projects/devkitpro/
+#export TOOLCHAIN_BIN="/cygdrive/c/Program Files (x86)/devkitARM/bin"
+
+# This is the Cygwin path to the location where I build the buildroot
+# toolchain.
+# export TOOLCHAIN_BIN="${WD}/../buildroot/build_arm_nofpu/staging_dir/bin"
+
+# Add the path to the toolchain to the PATH varialble
+export PATH="${TOOLCHAIN_BIN}:/sbin:/usr/sbin:${PATH_ORIG}"
+
+echo "PATH : ${PATH}"
--
GitLab
From d5ef349d9a555c307de0bb726c74e311acc6313d Mon Sep 17 00:00:00 2001
From: Sebastien Lorquet
Date: Sun, 2 Oct 2016 23:26:16 +0200
Subject: [PATCH 022/734] Add support for quadrature encoders on STM32L4
---
arch/arm/src/stm32l4/Kconfig | 303 +++-
arch/arm/src/stm32l4/Make.defs | 4 +
.../arm/src/stm32l4/chip/stm32l4x6xx_pinmap.h | 195 ++-
arch/arm/src/stm32l4/stm32l4_qencoder.c | 1248 +++++++++++++++++
arch/arm/src/stm32l4/stm32l4_qencoder.h | 141 ++
5 files changed, 1760 insertions(+), 131 deletions(-)
create mode 100644 arch/arm/src/stm32l4/stm32l4_qencoder.c
create mode 100644 arch/arm/src/stm32l4/stm32l4_qencoder.h
diff --git a/arch/arm/src/stm32l4/Kconfig b/arch/arm/src/stm32l4/Kconfig
index c511faaae6..83dbffe78c 100644
--- a/arch/arm/src/stm32l4/Kconfig
+++ b/arch/arm/src/stm32l4/Kconfig
@@ -721,8 +721,8 @@ if STM32L4_TIM1_CHANNEL1
config STM32L4_TIM1_CH1MODE
int "TIM1 Channel 1 Mode"
default 0
- range 0 5 if STM32_STM32F30XX
- range 0 1 if !STM32_STM32F30XX
+ range 0 5 if STM32L4_STM32F30XX
+ range 0 1 if !STM32L4_STM32F30XX
---help---
Specifies the channel mode.
@@ -745,8 +745,8 @@ if STM32L4_TIM1_CHANNEL2
config STM32L4_TIM1_CH2MODE
int "TIM1 Channel 2 Mode"
default 0
- range 0 5 if STM32_STM32F30XX
- range 0 1 if !STM32_STM32F30XX
+ range 0 5 if STM32L4_STM32F30XX
+ range 0 1 if !STM32L4_STM32F30XX
---help---
Specifies the channel mode.
@@ -769,8 +769,8 @@ if STM32L4_TIM1_CHANNEL3
config STM32L4_TIM1_CH3MODE
int "TIM1 Channel 3 Mode"
default 0
- range 0 5 if STM32_STM32F30XX
- range 0 1 if !STM32_STM32F30XX
+ range 0 5 if STM32L4_STM32F30XX
+ range 0 1 if !STM32L4_STM32F30XX
---help---
Specifies the channel mode.
@@ -793,8 +793,8 @@ if STM32L4_TIM1_CHANNEL4
config STM32L4_TIM1_CH4MODE
int "TIM1 Channel 4 Mode"
default 0
- range 0 5 if STM32_STM32F30XX
- range 0 1 if !STM32_STM32F30XX
+ range 0 5 if STM32L4_STM32F30XX
+ range 0 1 if !STM32L4_STM32F30XX
---help---
Specifies the channel mode.
@@ -821,8 +821,8 @@ config STM32L4_TIM1_CHANNEL
config STM32L4_TIM1_CHMODE
int "TIM1 Channel Mode"
default 0
- range 0 5 if STM32_STM32F30XX
- range 0 1 if !STM32_STM32F30XX
+ range 0 5 if STM32L4_STM32F30XX
+ range 0 1 if !STM32L4_STM32F30XX
---help---
Specifies the channel mode.
@@ -865,8 +865,8 @@ if STM32L4_TIM2_CHANNEL1
config STM32L4_TIM2_CH1MODE
int "TIM2 Channel 1 Mode"
default 0
- range 0 5 if STM32_STM32F30XX
- range 0 1 if !STM32_STM32F30XX
+ range 0 5 if STM32L4_STM32F30XX
+ range 0 1 if !STM32L4_STM32F30XX
---help---
Specifies the channel mode.
@@ -889,8 +889,8 @@ if STM32L4_TIM2_CHANNEL2
config STM32L4_TIM2_CH2MODE
int "TIM2 Channel 2 Mode"
default 0
- range 0 5 if STM32_STM32F30XX
- range 0 1 if !STM32_STM32F30XX
+ range 0 5 if STM32L4_STM32F30XX
+ range 0 1 if !STM32L4_STM32F30XX
---help---
Specifies the channel mode.
@@ -913,8 +913,8 @@ if STM32L4_TIM2_CHANNEL3
config STM32L4_TIM2_CH3MODE
int "TIM2 Channel 3 Mode"
default 0
- range 0 5 if STM32_STM32F30XX
- range 0 1 if !STM32_STM32F30XX
+ range 0 5 if STM32L4_STM32F30XX
+ range 0 1 if !STM32L4_STM32F30XX
---help---
Specifies the channel mode.
@@ -937,8 +937,8 @@ if STM32L4_TIM2_CHANNEL4
config STM32L4_TIM2_CH4MODE
int "TIM2 Channel 4 Mode"
default 0
- range 0 5 if STM32_STM32F30XX
- range 0 1 if !STM32_STM32F30XX
+ range 0 5 if STM32L4_STM32F30XX
+ range 0 1 if !STM32L4_STM32F30XX
---help---
Specifies the channel mode.
@@ -965,8 +965,8 @@ config STM32L4_TIM2_CHANNEL
config STM32L4_TIM2_CHMODE
int "TIM2 Channel Mode"
default 0
- range 0 5 if STM32_STM32F30XX
- range 0 1 if !STM32_STM32F30XX
+ range 0 5 if STM32L4_STM32F30XX
+ range 0 1 if !STM32L4_STM32F30XX
---help---
Specifies the channel mode.
@@ -1009,8 +1009,8 @@ if STM32L4_TIM3_CHANNEL1
config STM32L4_TIM3_CH1MODE
int "TIM3 Channel 1 Mode"
default 0
- range 0 5 if STM32_STM32F30XX
- range 0 1 if !STM32_STM32F30XX
+ range 0 5 if STM32L4_STM32F30XX
+ range 0 1 if !STM32L4_STM32F30XX
---help---
Specifies the channel mode.
@@ -1033,8 +1033,8 @@ if STM32L4_TIM3_CHANNEL2
config STM32L4_TIM3_CH2MODE
int "TIM3 Channel 2 Mode"
default 0
- range 0 5 if STM32_STM32F30XX
- range 0 1 if !STM32_STM32F30XX
+ range 0 5 if STM32L4_STM32F30XX
+ range 0 1 if !STM32L4_STM32F30XX
---help---
Specifies the channel mode.
@@ -1057,8 +1057,8 @@ if STM32L4_TIM3_CHANNEL3
config STM32L4_TIM3_CH3MODE
int "TIM3 Channel 3 Mode"
default 0
- range 0 5 if STM32_STM32F30XX
- range 0 1 if !STM32_STM32F30XX
+ range 0 5 if STM32L4_STM32F30XX
+ range 0 1 if !STM32L4_STM32F30XX
---help---
Specifies the channel mode.
@@ -1081,8 +1081,8 @@ if STM32L4_TIM3_CHANNEL4
config STM32L4_TIM3_CH4MODE
int "TIM3 Channel 4 Mode"
default 0
- range 0 5 if STM32_STM32F30XX
- range 0 1 if !STM32_STM32F30XX
+ range 0 5 if STM32L4_STM32F30XX
+ range 0 1 if !STM32L4_STM32F30XX
---help---
Specifies the channel mode.
@@ -1109,8 +1109,8 @@ config STM32L4_TIM3_CHANNEL
config STM32L4_TIM3_CHMODE
int "TIM3 Channel Mode"
default 0
- range 0 5 if STM32_STM32F30XX
- range 0 1 if !STM32_STM32F30XX
+ range 0 5 if STM32L4_STM32F30XX
+ range 0 1 if !STM32L4_STM32F30XX
---help---
Specifies the channel mode.
@@ -1153,8 +1153,8 @@ if STM32L4_TIM4_CHANNEL1
config STM32L4_TIM4_CH1MODE
int "TIM4 Channel 1 Mode"
default 0
- range 0 5 if STM32_STM32F30XX
- range 0 1 if !STM32_STM32F30XX
+ range 0 5 if STM32L4_STM32F30XX
+ range 0 1 if !STM32L4_STM32F30XX
---help---
Specifies the channel mode.
@@ -1177,8 +1177,8 @@ if STM32L4_TIM4_CHANNEL2
config STM32L4_TIM4_CH2MODE
int "TIM4 Channel 2 Mode"
default 0
- range 0 5 if STM32_STM32F30XX
- range 0 1 if !STM32_STM32F30XX
+ range 0 5 if STM32L4_STM32F30XX
+ range 0 1 if !STM32L4_STM32F30XX
---help---
Specifies the channel mode.
@@ -1201,8 +1201,8 @@ if STM32L4_TIM4_CHANNEL3
config STM32L4_TIM4_CH3MODE
int "TIM4 Channel 3 Mode"
default 0
- range 0 5 if STM32_STM32F30XX
- range 0 1 if !STM32_STM32F30XX
+ range 0 5 if STM32L4_STM32F30XX
+ range 0 1 if !STM32L4_STM32F30XX
---help---
Specifies the channel mode.
@@ -1225,8 +1225,8 @@ if STM32L4_TIM4_CHANNEL4
config STM32L4_TIM4_CH4MODE
int "TIM4 Channel 4 Mode"
default 0
- range 0 5 if STM32_STM32F30XX
- range 0 1 if !STM32_STM32F30XX
+ range 0 5 if STM32L4_STM32F30XX
+ range 0 1 if !STM32L4_STM32F30XX
---help---
Specifies the channel mode.
@@ -1253,8 +1253,8 @@ config STM32L4_TIM4_CHANNEL
config STM32L4_TIM4_CHMODE
int "TIM4 Channel Mode"
default 0
- range 0 5 if STM32_STM32F30XX
- range 0 1 if !STM32_STM32F30XX
+ range 0 5 if STM32L4_STM32F30XX
+ range 0 1 if !STM32L4_STM32F30XX
---help---
Specifies the channel mode.
@@ -1297,8 +1297,8 @@ if STM32L4_TIM5_CHANNEL1
config STM32L4_TIM5_CH1MODE
int "TIM5 Channel 1 Mode"
default 0
- range 0 5 if STM32_STM32F30XX
- range 0 1 if !STM32_STM32F30XX
+ range 0 5 if STM32L4_STM32F30XX
+ range 0 1 if !STM32L4_STM32F30XX
---help---
Specifies the channel mode.
@@ -1321,8 +1321,8 @@ if STM32L4_TIM5_CHANNEL2
config STM32L4_TIM5_CH2MODE
int "TIM5 Channel 2 Mode"
default 0
- range 0 5 if STM32_STM32F30XX
- range 0 1 if !STM32_STM32F30XX
+ range 0 5 if STM32L4_STM32F30XX
+ range 0 1 if !STM32L4_STM32F30XX
---help---
Specifies the channel mode.
@@ -1345,8 +1345,8 @@ if STM32L4_TIM5_CHANNEL3
config STM32L4_TIM5_CH3MODE
int "TIM5 Channel 3 Mode"
default 0
- range 0 5 if STM32_STM32F30XX
- range 0 1 if !STM32_STM32F30XX
+ range 0 5 if STM32L4_STM32F30XX
+ range 0 1 if !STM32L4_STM32F30XX
---help---
Specifies the channel mode.
@@ -1369,8 +1369,8 @@ if STM32L4_TIM5_CHANNEL4
config STM32L4_TIM5_CH4MODE
int "TIM5 Channel 4 Mode"
default 0
- range 0 5 if STM32_STM32F30XX
- range 0 1 if !STM32_STM32F30XX
+ range 0 5 if STM32L4_STM32F30XX
+ range 0 1 if !STM32L4_STM32F30XX
---help---
Specifies the channel mode.
@@ -1397,8 +1397,8 @@ config STM32L4_TIM5_CHANNEL
config STM32L4_TIM5_CHMODE
int "TIM5 Channel Mode"
default 0
- range 0 5 if STM32_STM32F30XX
- range 0 1 if !STM32_STM32F30XX
+ range 0 5 if STM32L4_STM32F30XX
+ range 0 1 if !STM32L4_STM32F30XX
---help---
Specifies the channel mode.
@@ -1441,8 +1441,8 @@ if STM32L4_TIM8_CHANNEL1
config STM32L4_TIM8_CH1MODE
int "TIM8 Channel 1 Mode"
default 0
- range 0 5 if STM32_STM32F30XX
- range 0 1 if !STM32_STM32F30XX
+ range 0 5 if STM32L4_STM32F30XX
+ range 0 1 if !STM32L4_STM32F30XX
---help---
Specifies the channel mode.
@@ -1465,8 +1465,8 @@ if STM32L4_TIM8_CHANNEL2
config STM32L4_TIM8_CH2MODE
int "TIM8 Channel 2 Mode"
default 0
- range 0 5 if STM32_STM32F30XX
- range 0 1 if !STM32_STM32F30XX
+ range 0 5 if STM32L4_STM32F30XX
+ range 0 1 if !STM32L4_STM32F30XX
---help---
Specifies the channel mode.
@@ -1489,8 +1489,8 @@ if STM32L4_TIM8_CHANNEL3
config STM32L4_TIM8_CH3MODE
int "TIM8 Channel 3 Mode"
default 0
- range 0 5 if STM32_STM32F30XX
- range 0 1 if !STM32_STM32F30XX
+ range 0 5 if STM32L4_STM32F30XX
+ range 0 1 if !STM32L4_STM32F30XX
---help---
Specifies the channel mode.
@@ -1513,8 +1513,8 @@ if STM32L4_TIM8_CHANNEL4
config STM32L4_TIM8_CH4MODE
int "TIM8 Channel 4 Mode"
default 0
- range 0 5 if STM32_STM32F30XX
- range 0 1 if !STM32_STM32F30XX
+ range 0 5 if STM32L4_STM32F30XX
+ range 0 1 if !STM32L4_STM32F30XX
---help---
Specifies the channel mode.
@@ -1541,8 +1541,8 @@ config STM32L4_TIM8_CHANNEL
config STM32L4_TIM8_CHMODE
int "TIM8 Channel Mode"
default 0
- range 0 5 if STM32_STM32F30XX
- range 0 1 if !STM32_STM32F30XX
+ range 0 5 if STM32L4_STM32F30XX
+ range 0 1 if !STM32L4_STM32F30XX
---help---
Specifies the channel mode.
@@ -1577,8 +1577,8 @@ if STM32L4_TIM15_CHANNEL1
config STM32L4_TIM15_CH1MODE
int "TIM15 Channel 1 Mode"
default 0
- range 0 3 if STM32_STM32F30XX
- range 0 1 if !STM32_STM32F30XX
+ range 0 3 if STM32L4_STM32F30XX
+ range 0 1 if !STM32L4_STM32F30XX
---help---
Specifies the channel mode.
@@ -1601,8 +1601,8 @@ if STM32L4_TIM15_CHANNEL2
config STM32L4_TIM15_CH2MODE
int "TIM15 Channel 2 Mode"
default 0
- range 0 3 if STM32_STM32F30XX
- range 0 1 if !STM32_STM32F30XX
+ range 0 3 if STM32L4_STM32F30XX
+ range 0 1 if !STM32L4_STM32F30XX
---help---
Specifies the channel mode.
@@ -1629,8 +1629,8 @@ config STM32L4_TIM15_CHANNEL
config STM32L4_TIM15_CHMODE
int "TIM15 Channel Mode"
default 0
- range 0 3 if STM32_STM32F30XX
- range 0 1 if !STM32_STM32F30XX
+ range 0 3 if STM32L4_STM32F30XX
+ range 0 1 if !STM32L4_STM32F30XX
---help---
Specifies the channel mode.
@@ -2750,4 +2750,175 @@ config STM32L4_CAN_REGDEBUG
endmenu
+menu "QEncoder Driver"
+ depends on QENCODER
+ depends on STM32L4_TIM1 || STM32L4_TIM2 || STM32L4_TIM3 || STM32L4_TIM4 || STM32L4_TIM5 || STM32L4_TIM8
+
+config STM32L4_TIM1_QE
+ bool "TIM1"
+ default n
+ depends on STM32L4_TIM1
+ ---help---
+ Reserve TIM1 for use by QEncoder.
+
+if STM32L4_TIM1_QE
+
+config STM32L4_TIM1_QECLKOUT
+ int "TIM1 output clock"
+ default 2800000
+ ---help---
+ The output clock of TIM1.
+
+endif
+
+config STM32L4_TIM2_QE
+ bool "TIM2"
+ default n
+ depends on STM32L4_TIM2
+ ---help---
+ Reserve TIM2 for use by QEncoder.
+
+if STM32L4_TIM2_QE
+
+config STM32L4_TIM2_QECLKOUT
+ int "TIM2 output clock"
+ default 2800000
+ ---help---
+ The output clock of TIM2.
+
+endif
+
+config STM32L4_TIM3_QE
+ bool "TIM3"
+ default n
+ depends on STM32L4_TIM3
+ ---help---
+ Reserve TIM3 for use by QEncoder.
+
+if STM32L4_TIM3_QE
+
+config STM32L4_TIM3_QECLKOUT
+ int "TIM3 output clock"
+ default 2800000
+ ---help---
+ The output clock of TIM3.
+
+endif
+
+config STM32L4_TIM4_QE
+ bool "TIM4"
+ default n
+ depends on STM32L4_TIM4
+ ---help---
+ Reserve TIM4 for use by QEncoder.
+
+if STM32L4_TIM4_QE
+
+config STM32L4_TIM4_QECLKOUT
+ int "TIM4 output clock"
+ default 2800000
+ ---help---
+ The output clock of TIM4.
+
+endif
+
+config STM32L4_TIM5_QE
+ bool "TIM5"
+ default n
+ depends on STM32L4_TIM5
+ ---help---
+ Reserve TIM5 for use by QEncoder.
+
+if STM32L4_TIM5_QE
+
+config STM32L4_TIM5_QECLKOUT
+ int "TIM5 output clock"
+ default 2800000
+ ---help---
+ The output clock of TIM5.
+
+endif
+
+config STM32L4_TIM8_QE
+ bool "TIM8"
+ default n
+ depends on STM32L4_TIM8
+ ---help---
+ Reserve TIM8 for use by QEncoder.
+
+if STM32L4_TIM8_QE
+
+config STM32L4_TIM8_QECLKOUT
+ int "TIM8 output clock"
+ default 2800000
+ ---help---
+ The output clock of TIM8.
+
+endif
+
+config STM32L4_QENCODER_FILTER
+ bool "Enable filtering on STM32 QEncoder input"
+ default y
+
+choice
+ depends on STM32L4_QENCODER_FILTER
+ prompt "Input channel sampling frequency"
+ default STM32L4_QENCODER_SAMPLE_FDTS_4
+
+config STM32L4_QENCODER_SAMPLE_FDTS
+ bool "fDTS"
+
+config STM32L4_QENCODER_SAMPLE_CKINT
+ bool "fCK_INT"
+
+config STM32L4_QENCODER_SAMPLE_FDTS_2
+ bool "fDTS/2"
+
+config STM32L4_QENCODER_SAMPLE_FDTS_4
+ bool "fDTS/4"
+
+config STM32L4_QENCODER_SAMPLE_FDTS_8
+ bool "fDTS/8"
+
+config STM32L4_QENCODER_SAMPLE_FDTS_16
+ bool "fDTS/16"
+
+config STM32L4_QENCODER_SAMPLE_FDTS_32
+ bool "fDTS/32"
+
+endchoice
+
+choice
+ depends on STM32L4_QENCODER_FILTER
+ prompt "Input channel event count"
+ default STM32L4_QENCODER_SAMPLE_EVENT_6
+
+config STM32L4_QENCODER_SAMPLE_EVENT_1
+ depends on STM32L4_QENCODER_SAMPLE_FDTS
+ bool "1"
+
+config STM32L4_QENCODER_SAMPLE_EVENT_2
+ depends on STM32L4_QENCODER_SAMPLE_CKINT
+ bool "2"
+
+config STM32L4_QENCODER_SAMPLE_EVENT_4
+ depends on STM32L4_QENCODER_SAMPLE_CKINT
+ bool "4"
+
+config STM32L4_QENCODER_SAMPLE_EVENT_5
+ depends on STM32L4_QENCODER_SAMPLE_FDTS_16 || STM32L4_QENCODER_SAMPLE_FDTS_32
+ bool "5"
+
+config STM32L4_QENCODER_SAMPLE_EVENT_6
+ depends on !STM32L4_QENCODER_SAMPLE_FDTS && !STM32L4_QENCODER_SAMPLE_CKINT
+ bool "6"
+
+config STM32L4_QENCODER_SAMPLE_EVENT_8
+ depends on !STM32L4_QENCODER_SAMPLE_FDTS
+ bool "8"
+
+endchoice
+
+endmenu
+
endif # ARCH_CHIP_STM32L4
diff --git a/arch/arm/src/stm32l4/Make.defs b/arch/arm/src/stm32l4/Make.defs
index d265c2a4f5..70199cceee 100644
--- a/arch/arm/src/stm32l4/Make.defs
+++ b/arch/arm/src/stm32l4/Make.defs
@@ -195,6 +195,10 @@ ifeq ($(CONFIG_PWM),y)
CHIP_CSRCS += stm32l4_pwm.c
endif
+ifeq ($(CONFIG_QENCODER),y)
+CHIP_CSRCS += stm32l4_qencoder.c
+endif
+
ifeq ($(CONFIG_STM32L4_QSPI),y)
CHIP_CSRCS += stm32l4_qspi.c
endif
diff --git a/arch/arm/src/stm32l4/chip/stm32l4x6xx_pinmap.h b/arch/arm/src/stm32l4/chip/stm32l4x6xx_pinmap.h
index c4ebc1413c..00fa2fa37a 100644
--- a/arch/arm/src/stm32l4/chip/stm32l4x6xx_pinmap.h
+++ b/arch/arm/src/stm32l4/chip/stm32l4x6xx_pinmap.h
@@ -500,14 +500,22 @@
/* Timers */
-#define GPIO_TIM1_CH1_1 (GPIO_ALT|GPIO_AF1 |GPIO_PORTA|GPIO_PIN8)
-#define GPIO_TIM1_CH1_2 (GPIO_ALT|GPIO_AF1 |GPIO_PORTE|GPIO_PIN9)
-#define GPIO_TIM1_CH2_1 (GPIO_ALT|GPIO_AF1 |GPIO_PORTA|GPIO_PIN9)
-#define GPIO_TIM1_CH2_2 (GPIO_ALT|GPIO_AF1 |GPIO_PORTE|GPIO_PIN11)
-#define GPIO_TIM1_CH3_1 (GPIO_ALT|GPIO_AF1 |GPIO_PORTA|GPIO_PIN10)
-#define GPIO_TIM1_CH3_2 (GPIO_ALT|GPIO_AF1 |GPIO_PORTE|GPIO_PIN13)
-#define GPIO_TIM1_CH4_1 (GPIO_ALT|GPIO_AF1 |GPIO_PORTA|GPIO_PIN11)
-#define GPIO_TIM1_CH4_2 (GPIO_ALT|GPIO_AF1 |GPIO_PORTE|GPIO_PIN14)
+#define GPIO_TIM1_CH1IN_1 (GPIO_ALT|GPIO_AF1 |GPIO_SPEED_50MHz|GPIO_FLOAT|GPIO_PORTA|GPIO_PIN8)
+#define GPIO_TIM1_CH1IN_2 (GPIO_ALT|GPIO_AF1 |GPIO_SPEED_50MHz|GPIO_FLOAT|GPIO_PORTE|GPIO_PIN9)
+#define GPIO_TIM1_CH1OUT_1 (GPIO_ALT|GPIO_AF1 |GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTA|GPIO_PIN8)
+#define GPIO_TIM1_CH1OUT_2 (GPIO_ALT|GPIO_AF1 |GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTE|GPIO_PIN9)
+#define GPIO_TIM1_CH2IN_1 (GPIO_ALT|GPIO_AF1 |GPIO_SPEED_50MHz|GPIO_FLOAT|GPIO_PORTA|GPIO_PIN9)
+#define GPIO_TIM1_CH2IN_2 (GPIO_ALT|GPIO_AF1 |GPIO_SPEED_50MHz|GPIO_FLOAT|GPIO_PORTE|GPIO_PIN11)
+#define GPIO_TIM1_CH2OUT_1 (GPIO_ALT|GPIO_AF1 |GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTA|GPIO_PIN9)
+#define GPIO_TIM1_CH2OUT_2 (GPIO_ALT|GPIO_AF1 |GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTE|GPIO_PIN11)
+#define GPIO_TIM1_CH3IN_1 (GPIO_ALT|GPIO_AF1 |GPIO_SPEED_50MHz|GPIO_FLOAT|GPIO_PORTA|GPIO_PIN10)
+#define GPIO_TIM1_CH3IN_2 (GPIO_ALT|GPIO_AF1 |GPIO_SPEED_50MHz|GPIO_FLOAT|GPIO_PORTE|GPIO_PIN13)
+#define GPIO_TIM1_CH3OUT_1 (GPIO_ALT|GPIO_AF1 |GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTA|GPIO_PIN10)
+#define GPIO_TIM1_CH3OUT_2 (GPIO_ALT|GPIO_AF1 |GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTE|GPIO_PIN13)
+#define GPIO_TIM1_CH4IN_1 (GPIO_ALT|GPIO_AF1 |GPIO_SPEED_50MHz|GPIO_FLOAT|GPIO_PORTA|GPIO_PIN11)
+#define GPIO_TIM1_CH4IN_2 (GPIO_ALT|GPIO_AF1 |GPIO_SPEED_50MHz|GPIO_FLOAT|GPIO_PORTE|GPIO_PIN14)
+#define GPIO_TIM1_CH4OUT_1 (GPIO_ALT|GPIO_AF1 |GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTA|GPIO_PIN11)
+#define GPIO_TIM1_CH4OUT_2 (GPIO_ALT|GPIO_AF1 |GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTE|GPIO_PIN14)
#define GPIO_TIM1_CH1N_1 (GPIO_ALT|GPIO_AF1 |GPIO_PORTA|GPIO_PIN7)
#define GPIO_TIM1_CH1N_2 (GPIO_ALT|GPIO_AF1 |GPIO_PORTB|GPIO_PIN13)
#define GPIO_TIM1_CH1N_3 (GPIO_ALT|GPIO_AF1 |GPIO_PORTE|GPIO_PIN8)
@@ -529,61 +537,104 @@
#define GPIO_TIM1_ETR_1 (GPIO_ALT|GPIO_AF1 |GPIO_PORTA|GPIO_PIN12)
#define GPIO_TIM1_ETR_2 (GPIO_ALT|GPIO_AF1 |GPIO_PORTE|GPIO_PIN7)
-#define GPIO_TIM2_CH1_1 (GPIO_ALT|GPIO_AF1 |GPIO_PORTA|GPIO_PIN0)
-#define GPIO_TIM2_CH1_2 (GPIO_ALT|GPIO_AF1 |GPIO_PORTA|GPIO_PIN5)
-#define GPIO_TIM2_CH1_3 (GPIO_ALT|GPIO_AF1 |GPIO_PORTA|GPIO_PIN15)
-#define GPIO_TIM2_CH2_1 (GPIO_ALT|GPIO_AF1 |GPIO_PORTA|GPIO_PIN1)
-#define GPIO_TIM2_CH2_2 (GPIO_ALT|GPIO_AF1 |GPIO_PORTB|GPIO_PIN3)
-#define GPIO_TIM2_CH3_1 (GPIO_ALT|GPIO_AF1 |GPIO_PORTA|GPIO_PIN2)
-#define GPIO_TIM2_CH3_2 (GPIO_ALT|GPIO_AF1 |GPIO_PORTB|GPIO_PIN10)
-#define GPIO_TIM2_CH4_1 (GPIO_ALT|GPIO_AF1 |GPIO_PORTA|GPIO_PIN3)
-#define GPIO_TIM2_CH4_2 (GPIO_ALT|GPIO_AF1 |GPIO_PORTB|GPIO_PIN11)
+#define GPIO_TIM2_CH1IN_1 (GPIO_ALT|GPIO_AF1 |GPIO_SPEED_50MHz|GPIO_FLOAT|GPIO_PORTA|GPIO_PIN0)
+#define GPIO_TIM2_CH1IN_2 (GPIO_ALT|GPIO_AF1 |GPIO_SPEED_50MHz|GPIO_FLOAT|GPIO_PORTA|GPIO_PIN5)
+#define GPIO_TIM2_CH1IN_3 (GPIO_ALT|GPIO_AF1 |GPIO_SPEED_50MHz|GPIO_FLOAT|GPIO_PORTA|GPIO_PIN15)
+#define GPIO_TIM2_CH1OUT_1 (GPIO_ALT|GPIO_AF1 |GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTA|GPIO_PIN0)
+#define GPIO_TIM2_CH1OUT_2 (GPIO_ALT|GPIO_AF1 |GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTA|GPIO_PIN5)
+#define GPIO_TIM2_CH1OUT_3 (GPIO_ALT|GPIO_AF1 |GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTA|GPIO_PIN15)
+#define GPIO_TIM2_CH2IN_1 (GPIO_ALT|GPIO_AF1 |GPIO_SPEED_50MHz|GPIO_FLOAT|GPIO_PORTA|GPIO_PIN1)
+#define GPIO_TIM2_CH2IN_2 (GPIO_ALT|GPIO_AF1 |GPIO_SPEED_50MHz|GPIO_FLOAT|GPIO_PORTB|GPIO_PIN3)
+#define GPIO_TIM2_CH2OUT_1 (GPIO_ALT|GPIO_AF1 |GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTA|GPIO_PIN1)
+#define GPIO_TIM2_CH2OUT_2 (GPIO_ALT|GPIO_AF1 |GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTB|GPIO_PIN3)
+#define GPIO_TIM2_CH3IN_1 (GPIO_ALT|GPIO_AF1 |GPIO_SPEED_50MHz|GPIO_FLOAT|GPIO_PORTA|GPIO_PIN2)
+#define GPIO_TIM2_CH3IN_2 (GPIO_ALT|GPIO_AF1 |GPIO_SPEED_50MHz|GPIO_FLOAT|GPIO_PORTB|GPIO_PIN10)
+#define GPIO_TIM2_CH3OUT_1 (GPIO_ALT|GPIO_AF1 |GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTA|GPIO_PIN2)
+#define GPIO_TIM2_CH3OUT_2 (GPIO_ALT|GPIO_AF1 |GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTB|GPIO_PIN10)
+#define GPIO_TIM2_CH4IN_1 (GPIO_ALT|GPIO_AF1 |GPIO_SPEED_50MHz|GPIO_FLOAT|GPIO_PORTA|GPIO_PIN3)
+#define GPIO_TIM2_CH4IN_2 (GPIO_ALT|GPIO_AF1 |GPIO_SPEED_50MHz|GPIO_FLOAT|GPIO_PORTB|GPIO_PIN11)
+#define GPIO_TIM2_CH4OUT_1 (GPIO_ALT|GPIO_AF1 |GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTA|GPIO_PIN3)
+#define GPIO_TIM2_CH4OUT_2 (GPIO_ALT|GPIO_AF1 |GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTB|GPIO_PIN11)
#define GPIO_TIM2_BKIN (GPIO_ALT|GPIO_AF2 |GPIO_PORTE|GPIO_PIN14)
#define GPIO_TIM2_ETR_1 (GPIO_ALT|GPIO_AF14|GPIO_PORTA|GPIO_PIN0)
#define GPIO_TIM2_ETR_2 (GPIO_ALT|GPIO_AF2 |GPIO_PORTA|GPIO_PIN5)
#define GPIO_TIM2_ETR_3 (GPIO_ALT|GPIO_AF2 |GPIO_PORTA|GPIO_PIN15)
-#define GPIO_TIM3_CH1_1 (GPIO_ALT|GPIO_AF2 |GPIO_PORTA|GPIO_PIN6)
-#define GPIO_TIM3_CH1_2 (GPIO_ALT|GPIO_AF2 |GPIO_PORTB|GPIO_PIN4)
-#define GPIO_TIM3_CH1_3 (GPIO_ALT|GPIO_AF2 |GPIO_PORTC|GPIO_PIN6)
-#define GPIO_TIM3_CH1_4 (GPIO_ALT|GPIO_AF2 |GPIO_PORTE|GPIO_PIN3)
-#define GPIO_TIM3_CH2_1 (GPIO_ALT|GPIO_AF2 |GPIO_PORTA|GPIO_PIN7)
-#define GPIO_TIM3_CH2_2 (GPIO_ALT|GPIO_AF2 |GPIO_PORTB|GPIO_PIN5)
-#define GPIO_TIM3_CH2_3 (GPIO_ALT|GPIO_AF2 |GPIO_PORTC|GPIO_PIN7)
-#define GPIO_TIM3_CH2_4 (GPIO_ALT|GPIO_AF2 |GPIO_PORTE|GPIO_PIN4)
-#define GPIO_TIM3_CH3_1 (GPIO_ALT|GPIO_AF2 |GPIO_PORTB|GPIO_PIN0)
-#define GPIO_TIM3_CH3_2 (GPIO_ALT|GPIO_AF2 |GPIO_PORTC|GPIO_PIN8)
-#define GPIO_TIM3_CH3_3 (GPIO_ALT|GPIO_AF2 |GPIO_PORTE|GPIO_PIN5)
-#define GPIO_TIM3_CH4_1 (GPIO_ALT|GPIO_AF2 |GPIO_PORTB|GPIO_PIN1)
-#define GPIO_TIM3_CH4_2 (GPIO_ALT|GPIO_AF2 |GPIO_PORTC|GPIO_PIN9)
-#define GPIO_TIM3_CH4_3 (GPIO_ALT|GPIO_AF2 |GPIO_PORTE|GPIO_PIN6)
+#define GPIO_TIM3_CH1IN_1 (GPIO_ALT|GPIO_AF2 |GPIO_SPEED_50MHz|GPIO_FLOAT|GPIO_PORTA|GPIO_PIN6)
+#define GPIO_TIM3_CH1IN_2 (GPIO_ALT|GPIO_AF2 |GPIO_SPEED_50MHz|GPIO_FLOAT|GPIO_PORTB|GPIO_PIN4)
+#define GPIO_TIM3_CH1IN_3 (GPIO_ALT|GPIO_AF2 |GPIO_SPEED_50MHz|GPIO_FLOAT|GPIO_PORTC|GPIO_PIN6)
+#define GPIO_TIM3_CH1IN_4 (GPIO_ALT|GPIO_AF2 |GPIO_SPEED_50MHz|GPIO_FLOAT|GPIO_PORTE|GPIO_PIN3)
+#define GPIO_TIM3_CH1OUT_1 (GPIO_ALT|GPIO_AF2 |GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTA|GPIO_PIN6)
+#define GPIO_TIM3_CH1OUT_2 (GPIO_ALT|GPIO_AF2 |GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTB|GPIO_PIN4)
+#define GPIO_TIM3_CH1OUT_3 (GPIO_ALT|GPIO_AF2 |GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTC|GPIO_PIN6)
+#define GPIO_TIM3_CH1OUT_4 (GPIO_ALT|GPIO_AF2 |GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTE|GPIO_PIN3)
+#define GPIO_TIM3_CH2IN_1 (GPIO_ALT|GPIO_AF2 |GPIO_SPEED_50MHz|GPIO_FLOAT|GPIO_PORTA|GPIO_PIN7)
+#define GPIO_TIM3_CH2IN_2 (GPIO_ALT|GPIO_AF2 |GPIO_SPEED_50MHz|GPIO_FLOAT|GPIO_PORTB|GPIO_PIN5)
+#define GPIO_TIM3_CH2IN_3 (GPIO_ALT|GPIO_AF2 |GPIO_SPEED_50MHz|GPIO_FLOAT|GPIO_PORTC|GPIO_PIN7)
+#define GPIO_TIM3_CH2IN_4 (GPIO_ALT|GPIO_AF2 |GPIO_SPEED_50MHz|GPIO_FLOAT|GPIO_PORTE|GPIO_PIN4)
+#define GPIO_TIM3_CH2OUT_1 (GPIO_ALT|GPIO_AF2 |GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTA|GPIO_PIN7)
+#define GPIO_TIM3_CH2OUT_2 (GPIO_ALT|GPIO_AF2 |GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTB|GPIO_PIN5)
+#define GPIO_TIM3_CH2OUT_3 (GPIO_ALT|GPIO_AF2 |GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTC|GPIO_PIN7)
+#define GPIO_TIM3_CH2OUT_4 (GPIO_ALT|GPIO_AF2 |GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTE|GPIO_PIN4)
+#define GPIO_TIM3_CH3IN_1 (GPIO_ALT|GPIO_AF2 |GPIO_SPEED_50MHz|GPIO_FLOAT|GPIO_PORTB|GPIO_PIN0)
+#define GPIO_TIM3_CH3IN_2 (GPIO_ALT|GPIO_AF2 |GPIO_SPEED_50MHz|GPIO_FLOAT|GPIO_PORTC|GPIO_PIN8)
+#define GPIO_TIM3_CH3IN_3 (GPIO_ALT|GPIO_AF2 |GPIO_SPEED_50MHz|GPIO_FLOAT|GPIO_PORTE|GPIO_PIN5)
+#define GPIO_TIM3_CH3OUT_1 (GPIO_ALT|GPIO_AF2 |GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTB|GPIO_PIN0)
+#define GPIO_TIM3_CH3OUT_2 (GPIO_ALT|GPIO_AF2 |GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTC|GPIO_PIN8)
+#define GPIO_TIM3_CH3OUT_3 (GPIO_ALT|GPIO_AF2 |GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTE|GPIO_PIN5)
+#define GPIO_TIM3_CH4IN_1 (GPIO_ALT|GPIO_AF2 |GPIO_SPEED_50MHz|GPIO_FLOAT|GPIO_PORTB|GPIO_PIN1)
+#define GPIO_TIM3_CH4IN_2 (GPIO_ALT|GPIO_AF2 |GPIO_SPEED_50MHz|GPIO_FLOAT|GPIO_PORTC|GPIO_PIN9)
+#define GPIO_TIM3_CH4IN_3 (GPIO_ALT|GPIO_AF2 |GPIO_SPEED_50MHz|GPIO_FLOAT|GPIO_PORTE|GPIO_PIN6)
+#define GPIO_TIM3_CH4OUT_1 (GPIO_ALT|GPIO_AF2 |GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTB|GPIO_PIN1)
+#define GPIO_TIM3_CH4OUT_2 (GPIO_ALT|GPIO_AF2 |GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTC|GPIO_PIN9)
+#define GPIO_TIM3_CH4OUT_3 (GPIO_ALT|GPIO_AF2 |GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTE|GPIO_PIN6)
#define GPIO_TIM3_ETR_1 (GPIO_ALT|GPIO_AF2 |GPIO_PORTD|GPIO_PIN2)
#define GPIO_TIM3_ETR_2 (GPIO_ALT|GPIO_AF2 |GPIO_PORTE|GPIO_PIN2)
-#define GPIO_TIM4_CH1_1 (GPIO_ALT|GPIO_AF2 |GPIO_PORTB|GPIO_PIN6)
-#define GPIO_TIM4_CH1_2 (GPIO_ALT|GPIO_AF2 |GPIO_PORTD|GPIO_PIN12)
-#define GPIO_TIM4_CH2_1 (GPIO_ALT|GPIO_AF2 |GPIO_PORTB|GPIO_PIN7)
-#define GPIO_TIM4_CH2_2 (GPIO_ALT|GPIO_AF2 |GPIO_PORTD|GPIO_PIN13)
-#define GPIO_TIM4_CH3_1 (GPIO_ALT|GPIO_AF2 |GPIO_PORTB|GPIO_PIN8)
-#define GPIO_TIM4_CH3_2 (GPIO_ALT|GPIO_AF2 |GPIO_PORTD|GPIO_PIN14)
-#define GPIO_TIM4_CH4_1 (GPIO_ALT|GPIO_AF2 |GPIO_PORTB|GPIO_PIN9)
-#define GPIO_TIM4_CH4_2 (GPIO_ALT|GPIO_AF2 |GPIO_PORTD|GPIO_PIN15)
+#define GPIO_TIM4_CH1IN_1 (GPIO_ALT|GPIO_AF2 |GPIO_SPEED_50MHz|GPIO_FLOAT|GPIO_PORTB|GPIO_PIN6)
+#define GPIO_TIM4_CH1IN_2 (GPIO_ALT|GPIO_AF2 |GPIO_SPEED_50MHz|GPIO_FLOAT|GPIO_PORTD|GPIO_PIN12)
+#define GPIO_TIM4_CH1OUT_1 (GPIO_ALT|GPIO_AF2 |GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTB|GPIO_PIN6)
+#define GPIO_TIM4_CH1OUT_2 (GPIO_ALT|GPIO_AF2 |GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTD|GPIO_PIN12)
+#define GPIO_TIM4_CH2IN_1 (GPIO_ALT|GPIO_AF2 |GPIO_SPEED_50MHz|GPIO_FLOAT|GPIO_PORTB|GPIO_PIN7)
+#define GPIO_TIM4_CH2IN_2 (GPIO_ALT|GPIO_AF2 |GPIO_SPEED_50MHz|GPIO_FLOAT|GPIO_PORTD|GPIO_PIN13)
+#define GPIO_TIM4_CH2OUT_1 (GPIO_ALT|GPIO_AF2 |GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTB|GPIO_PIN7)
+#define GPIO_TIM4_CH2OUT_2 (GPIO_ALT|GPIO_AF2 |GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTD|GPIO_PIN13)
+#define GPIO_TIM4_CH3IN_1 (GPIO_ALT|GPIO_AF2 |GPIO_SPEED_50MHz|GPIO_FLOAT|GPIO_PORTB|GPIO_PIN8)
+#define GPIO_TIM4_CH3IN_2 (GPIO_ALT|GPIO_AF2 |GPIO_SPEED_50MHz|GPIO_FLOAT|GPIO_PORTD|GPIO_PIN14)
+#define GPIO_TIM4_CH3OUT_1 (GPIO_ALT|GPIO_AF2 |GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTB|GPIO_PIN8)
+#define GPIO_TIM4_CH3OUT_2 (GPIO_ALT|GPIO_AF2 |GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTD|GPIO_PIN14)
+#define GPIO_TIM4_CH4IN_1 (GPIO_ALT|GPIO_AF2 |GPIO_SPEED_50MHz|GPIO_FLOAT|GPIO_PORTB|GPIO_PIN9)
+#define GPIO_TIM4_CH4IN_2 (GPIO_ALT|GPIO_AF2 |GPIO_SPEED_50MHz|GPIO_FLOAT|GPIO_PORTD|GPIO_PIN15)
+#define GPIO_TIM4_CH4OUT_1 (GPIO_ALT|GPIO_AF2 |GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTB|GPIO_PIN9)
+#define GPIO_TIM4_CH4OUT_2 (GPIO_ALT|GPIO_AF2 |GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTD|GPIO_PIN15)
#define GPIO_TIM4_ETR (GPIO_ALT|GPIO_AF2 |GPIO_PORTE|GPIO_PIN0)
-#define GPIO_TIM5_CH1_1 (GPIO_ALT|GPIO_AF2 |GPIO_PORTA|GPIO_PIN0)
-#define GPIO_TIM5_CH1_2 (GPIO_ALT|GPIO_AF2 |GPIO_PORTF|GPIO_PIN6)
-#define GPIO_TIM5_CH2_1 (GPIO_ALT|GPIO_AF2 |GPIO_PORTA|GPIO_PIN1)
-#define GPIO_TIM5_CH2_2 (GPIO_ALT|GPIO_AF2 |GPIO_PORTF|GPIO_PIN7)
-#define GPIO_TIM5_CH3_1 (GPIO_ALT|GPIO_AF2 |GPIO_PORTA|GPIO_PIN2)
-#define GPIO_TIM5_CH3_2 (GPIO_ALT|GPIO_AF2 |GPIO_PORTF|GPIO_PIN8)
-#define GPIO_TIM5_CH4_1 (GPIO_ALT|GPIO_AF2 |GPIO_PORTA|GPIO_PIN3)
-#define GPIO_TIM5_CH4_2 (GPIO_ALT|GPIO_AF2 |GPIO_PORTF|GPIO_PIN9)
+#define GPIO_TIM5_CH1IN_1 (GPIO_ALT|GPIO_AF2 |GPIO_SPEED_50MHz|GPIO_FLOAT|GPIO_PORTA|GPIO_PIN0)
+#define GPIO_TIM5_CH1IN_2 (GPIO_ALT|GPIO_AF2 |GPIO_SPEED_50MHz|GPIO_FLOAT|GPIO_PORTF|GPIO_PIN6)
+#define GPIO_TIM5_CH1OUT_1 (GPIO_ALT|GPIO_AF2 |GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTA|GPIO_PIN0)
+#define GPIO_TIM5_CH1OUT_2 (GPIO_ALT|GPIO_AF2 |GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTF|GPIO_PIN6)
+#define GPIO_TIM5_CH2IN_1 (GPIO_ALT|GPIO_AF2 |GPIO_SPEED_50MHz|GPIO_FLOAT|GPIO_PORTA|GPIO_PIN1)
+#define GPIO_TIM5_CH2IN_2 (GPIO_ALT|GPIO_AF2 |GPIO_SPEED_50MHz|GPIO_FLOAT|GPIO_PORTF|GPIO_PIN7)
+#define GPIO_TIM5_CH2OUT_1 (GPIO_ALT|GPIO_AF2 |GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTA|GPIO_PIN1)
+#define GPIO_TIM5_CH2OUT_2 (GPIO_ALT|GPIO_AF2 |GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTF|GPIO_PIN7)
+#define GPIO_TIM5_CH3IN_1 (GPIO_ALT|GPIO_AF2 |GPIO_SPEED_50MHz|GPIO_FLOAT|GPIO_PORTA|GPIO_PIN2)
+#define GPIO_TIM5_CH3IN_2 (GPIO_ALT|GPIO_AF2 |GPIO_SPEED_50MHz|GPIO_FLOAT|GPIO_PORTF|GPIO_PIN8)
+#define GPIO_TIM5_CH3OUT_1 (GPIO_ALT|GPIO_AF2 |GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTA|GPIO_PIN2)
+#define GPIO_TIM5_CH3OUT_2 (GPIO_ALT|GPIO_AF2 |GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTF|GPIO_PIN8)
+#define GPIO_TIM5_CH4IN_1 (GPIO_ALT|GPIO_AF2 |GPIO_SPEED_50MHz|GPIO_FLOAT|GPIO_PORTA|GPIO_PIN3)
+#define GPIO_TIM5_CH4IN_2 (GPIO_ALT|GPIO_AF2 |GPIO_SPEED_50MHz|GPIO_FLOAT|GPIO_PORTF|GPIO_PIN9)
+#define GPIO_TIM5_CH4OUT_1 (GPIO_ALT|GPIO_AF2 |GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTA|GPIO_PIN3)
+#define GPIO_TIM5_CH4OUT_2 (GPIO_ALT|GPIO_AF2 |GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTF|GPIO_PIN9)
#define GPIO_TIM5_ETR (GPIO_ALT|GPIO_AF1 |GPIO_PORTF|GPIO_PIN6)
-#define GPIO_TIM8_CH1 (GPIO_ALT|GPIO_AF3 |GPIO_PORTC|GPIO_PIN6)
-#define GPIO_TIM8_CH2 (GPIO_ALT|GPIO_AF3 |GPIO_PORTC|GPIO_PIN7)
-#define GPIO_TIM8_CH3 (GPIO_ALT|GPIO_AF3 |GPIO_PORTC|GPIO_PIN8)
-#define GPIO_TIM8_CH4 (GPIO_ALT|GPIO_AF3 |GPIO_PORTC|GPIO_PIN9)
+#define GPIO_TIM8_CH1IN (GPIO_ALT|GPIO_AF3 |GPIO_SPEED_50MHz|GPIO_FLOAT|GPIO_PORTC|GPIO_PIN6)
+#define GPIO_TIM8_CH1OUT (GPIO_ALT|GPIO_AF3 |GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTC|GPIO_PIN6)
+#define GPIO_TIM8_CH2IN (GPIO_ALT|GPIO_AF3 |GPIO_SPEED_50MHz|GPIO_FLOAT|GPIO_PORTC|GPIO_PIN7)
+#define GPIO_TIM8_CH2OUT (GPIO_ALT|GPIO_AF3 |GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTC|GPIO_PIN7)
+#define GPIO_TIM8_CH3IN (GPIO_ALT|GPIO_AF3 |GPIO_SPEED_50MHz|GPIO_FLOAT|GPIO_PORTC|GPIO_PIN8)
+#define GPIO_TIM8_CH3OUT (GPIO_ALT|GPIO_AF3 |GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTC|GPIO_PIN8)
+#define GPIO_TIM8_CH4IN (GPIO_ALT|GPIO_AF3 |GPIO_SPEED_50MHz|GPIO_FLOAT|GPIO_PORTC|GPIO_PIN9)
+#define GPIO_TIM8_CH4OUT (GPIO_ALT|GPIO_AF3 |GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTC|GPIO_PIN9)
#define GPIO_TIM8_CH1N_1 (GPIO_ALT|GPIO_AF3 |GPIO_PORTA|GPIO_PIN5)
#define GPIO_TIM8_CH1N_2 (GPIO_ALT|GPIO_AF3 |GPIO_PORTA|GPIO_PIN7)
#define GPIO_TIM8_CH2N_1 (GPIO_ALT|GPIO_AF3 |GPIO_PORTB|GPIO_PIN0)
@@ -600,29 +651,43 @@
#define GPIO_TIM8_BKIN2_COMP2 (GPIO_ALT|GPIO_AF12|GPIO_PORTB|GPIO_PIN6)
#define GPIO_TIM8_ETR (GPIO_ALT|GPIO_AF3 |GPIO_PORTA|GPIO_PIN0)
-#define GPIO_TIM15_CH1_1 (GPIO_ALT|GPIO_AF14|GPIO_PORTA|GPIO_PIN2)
-#define GPIO_TIM15_CH1_2 (GPIO_ALT|GPIO_AF14|GPIO_PORTB|GPIO_PIN14)
-#define GPIO_TIM15_CH1_3 (GPIO_ALT|GPIO_AF14|GPIO_PORTF|GPIO_PIN9)
-#define GPIO_TIM15_CH1_4 (GPIO_ALT|GPIO_AF14|GPIO_PORTG|GPIO_PIN10)
-#define GPIO_TIM15_CH2_1 (GPIO_ALT|GPIO_AF14|GPIO_PORTA|GPIO_PIN3)
-#define GPIO_TIM15_CH2_2 (GPIO_ALT|GPIO_AF14|GPIO_PORTB|GPIO_PIN15)
-#define GPIO_TIM15_CH2_3 (GPIO_ALT|GPIO_AF14|GPIO_PORTF|GPIO_PIN10)
-#define GPIO_TIM15_CH2_4 (GPIO_ALT|GPIO_AF14|GPIO_PORTG|GPIO_PIN11)
+#define GPIO_TIM15_CH1IN_1 (GPIO_ALT|GPIO_AF14|GPIO_SPEED_50MHz|GPIO_FLOAT|GPIO_PORTA|GPIO_PIN2)
+#define GPIO_TIM15_CH1IN_2 (GPIO_ALT|GPIO_AF14|GPIO_SPEED_50MHz|GPIO_FLOAT|GPIO_PORTB|GPIO_PIN14)
+#define GPIO_TIM15_CH1IN_3 (GPIO_ALT|GPIO_AF14|GPIO_SPEED_50MHz|GPIO_FLOAT|GPIO_PORTF|GPIO_PIN9)
+#define GPIO_TIM15_CH1IN_4 (GPIO_ALT|GPIO_AF14|GPIO_SPEED_50MHz|GPIO_FLOAT|GPIO_PORTG|GPIO_PIN10)
+#define GPIO_TIM15_CH1OUT_1 (GPIO_ALT|GPIO_AF14|GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTA|GPIO_PIN2)
+#define GPIO_TIM15_CH1OUT_2 (GPIO_ALT|GPIO_AF14|GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTB|GPIO_PIN14)
+#define GPIO_TIM15_CH1OUT_3 (GPIO_ALT|GPIO_AF14|GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTF|GPIO_PIN9)
+#define GPIO_TIM15_CH1OUT_4 (GPIO_ALT|GPIO_AF14|GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTG|GPIO_PIN10)
+#define GPIO_TIM15_CH2IN_1 (GPIO_ALT|GPIO_AF14|GPIO_SPEED_50MHz|GPIO_FLOAT|GPIO_PORTA|GPIO_PIN3)
+#define GPIO_TIM15_CH2IN_2 (GPIO_ALT|GPIO_AF14|GPIO_SPEED_50MHz|GPIO_FLOAT|GPIO_PORTB|GPIO_PIN15)
+#define GPIO_TIM15_CH2IN_3 (GPIO_ALT|GPIO_AF14|GPIO_SPEED_50MHz|GPIO_FLOAT|GPIO_PORTF|GPIO_PIN10)
+#define GPIO_TIM15_CH2IN_4 (GPIO_ALT|GPIO_AF14|GPIO_SPEED_50MHz|GPIO_FLOAT|GPIO_PORTG|GPIO_PIN11)
+#define GPIO_TIM15_CH2OUT_1 (GPIO_ALT|GPIO_AF14|GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTA|GPIO_PIN3)
+#define GPIO_TIM15_CH2OUT_2 (GPIO_ALT|GPIO_AF14|GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTB|GPIO_PIN15)
+#define GPIO_TIM15_CH2OUT_3 (GPIO_ALT|GPIO_AF14|GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTF|GPIO_PIN10)
+#define GPIO_TIM15_CH2OUT_4 (GPIO_ALT|GPIO_AF14|GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTG|GPIO_PIN11)
#define GPIO_TIM15_CH1N_1 (GPIO_ALT|GPIO_AF14|GPIO_PORTA|GPIO_PIN1)
#define GPIO_TIM15_CH1N_2 (GPIO_ALT|GPIO_AF14|GPIO_PORTB|GPIO_PIN13)
#define GPIO_TIM15_CH1N_3 (GPIO_ALT|GPIO_AF14|GPIO_PORTG|GPIO_PIN9)
#define GPIO_TIM15_BKIN_1 (GPIO_ALT|GPIO_AF14|GPIO_PORTA|GPIO_PIN9)
#define GPIO_TIM15_BKIN_2 (GPIO_ALT|GPIO_AF14|GPIO_PORTB|GPIO_PIN12)
-#define GPIO_TIM16_CH1_1 (GPIO_ALT|GPIO_AF14|GPIO_PORTA|GPIO_PIN6)
-#define GPIO_TIM16_CH1_2 (GPIO_ALT|GPIO_AF14|GPIO_PORTB|GPIO_PIN8)
-#define GPIO_TIM16_CH1_3 (GPIO_ALT|GPIO_AF14|GPIO_PORTE|GPIO_PIN0)
+#define GPIO_TIM16_CH1IN_1 (GPIO_ALT|GPIO_AF14|GPIO_SPEED_50MHz|GPIO_FLOAT|GPIO_PORTA|GPIO_PIN6)
+#define GPIO_TIM16_CH1IN_2 (GPIO_ALT|GPIO_AF14|GPIO_SPEED_50MHz|GPIO_FLOAT|GPIO_PORTB|GPIO_PIN8)
+#define GPIO_TIM16_CH1IN_3 (GPIO_ALT|GPIO_AF14|GPIO_SPEED_50MHz|GPIO_FLOAT|GPIO_PORTE|GPIO_PIN0)
+#define GPIO_TIM16_CH1OUT_1 (GPIO_ALT|GPIO_AF14|GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTA|GPIO_PIN6)
+#define GPIO_TIM16_CH1OUT_2 (GPIO_ALT|GPIO_AF14|GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTB|GPIO_PIN8)
+#define GPIO_TIM16_CH1OUT_3 (GPIO_ALT|GPIO_AF14|GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTE|GPIO_PIN0)
#define GPIO_TIM16_CH1N (GPIO_ALT|GPIO_AF14|GPIO_PORTB|GPIO_PIN6)
#define GPIO_TIM16_BKIN (GPIO_ALT|GPIO_AF14|GPIO_PORTB|GPIO_PIN5)
-#define GPIO_TIM17_CH1_1 (GPIO_ALT|GPIO_AF14|GPIO_PORTA|GPIO_PIN7)
-#define GPIO_TIM17_CH1_2 (GPIO_ALT|GPIO_AF14|GPIO_PORTB|GPIO_PIN9)
-#define GPIO_TIM17_CH1_3 (GPIO_ALT|GPIO_AF14|GPIO_PORTE|GPIO_PIN1)
+#define GPIO_TIM17_CH1IN_1 (GPIO_ALT|GPIO_AF14|GPIO_SPEED_50MHz|GPIO_FLOAT|GPIO_PORTA|GPIO_PIN7)
+#define GPIO_TIM17_CH1IN_2 (GPIO_ALT|GPIO_AF14|GPIO_SPEED_50MHz|GPIO_FLOAT|GPIO_PORTB|GPIO_PIN9)
+#define GPIO_TIM17_CH1IN_3 (GPIO_ALT|GPIO_AF14|GPIO_SPEED_50MHz|GPIO_FLOAT|GPIO_PORTE|GPIO_PIN1)
+#define GPIO_TIM17_CH1OUT_1 (GPIO_ALT|GPIO_AF14|GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTA|GPIO_PIN7)
+#define GPIO_TIM17_CH1OUT_2 (GPIO_ALT|GPIO_AF14|GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTB|GPIO_PIN9)
+#define GPIO_TIM17_CH1OUT_3 (GPIO_ALT|GPIO_AF14|GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTE|GPIO_PIN1)
#define GPIO_TIM17_CH1N (GPIO_ALT|GPIO_AF14|GPIO_PORTB|GPIO_PIN7)
#define GPIO_TIM17_BKIN_1 (GPIO_ALT|GPIO_AF14|GPIO_PORTA|GPIO_PIN10)
#define GPIO_TIM17_BKIN_2 (GPIO_ALT|GPIO_AF14|GPIO_PORTB|GPIO_PIN4)
diff --git a/arch/arm/src/stm32l4/stm32l4_qencoder.c b/arch/arm/src/stm32l4/stm32l4_qencoder.c
new file mode 100644
index 0000000000..7c9426de29
--- /dev/null
+++ b/arch/arm/src/stm32l4/stm32l4_qencoder.c
@@ -0,0 +1,1248 @@
+/************************************************************************************
+ * arch/arm/src/stm32l4/stm32;4_qencoder.c
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Authors: Gregory Nutt
+ * Diego Sanchez
+ *
+ * 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
+
+#include
+#include
+#include
+#include
+
+#include
+#include
+#include
+
+#include
+
+#include "chip.h"
+#include "up_internal.h"
+#include "up_arch.h"
+
+#include "stm32l4.h"
+#include "stm32l4_gpio.h"
+#include "stm32l4_tim.h"
+#include "stm32l4_qencoder.h"
+
+#ifdef CONFIG_QENCODER
+
+/************************************************************************************
+ * Pre-processor Definitions
+ ************************************************************************************/
+/* Clocking *************************************************************************/
+/* The CLKOUT value should not exceed the CLKIN value */
+
+#if defined(CONFIG_STM32L4_TIM1_QE) && CONFIG_STM32L4_TIM1_QECLKOUT > STM32L4_APB2_TIM1_CLKIN
+# warning "CONFIG_STM32L4_TIM1_QECLKOUT exceeds STM32L4_APB2_TIM1_CLKIN"
+#endif
+
+#if defined(CONFIG_STM32L4_TIM2_QE) && CONFIG_STM32L4_TIM2_QECLKOUT > STM32L4_APB1_TIM2_CLKIN
+# warning "CONFIG_STM32L4_TIM2_QECLKOUT exceeds STM32L4_APB2_TIM2_CLKIN"
+#endif
+
+#if defined(CONFIG_STM32L4_TIM3_QE) && CONFIG_STM32L4_TIM3_QECLKOUT > STM32L4_APB1_TIM3_CLKIN
+# warning "CONFIG_STM32L4_TIM3_QECLKOUT exceeds STM32L4_APB2_TIM3_CLKIN"
+#endif
+
+#if defined(CONFIG_STM32L4_TIM4_QE) && CONFIG_STM32L4_TIM4_QECLKOUT > STM32L4_APB1_TIM4_CLKIN
+# warning "CONFIG_STM32L4_TIM4_QECLKOUT exceeds STM32L4_APB2_TIM4_CLKIN"
+#endif
+
+#if defined(CONFIG_STM32L4_TIM5_QE) && CONFIG_STM32L4_TIM5_QECLKOUT > STM32L4_APB1_TIM5_CLKIN
+# warning "CONFIG_STM32L4_TIM5_QECLKOUT exceeds STM32L4_APB2_TIM5_CLKIN"
+#endif
+
+#if defined(CONFIG_STM32L4_TIM8_QE) && CONFIG_STM32L4_TIM8_QECLKOUT > STM32L4_APB2_TIM8_CLKIN
+# warning "CONFIG_STM32L4_TIM8_QECLKOUT exceeds STM32L4_APB2_TIM8_CLKIN"
+#endif
+
+/* Timers ***************************************************************************/
+
+#undef HAVE_32BIT_TIMERS
+#undef HAVE_16BIT_TIMERS
+
+/* On the L4 series, TIM2 and TIM5 are 32-bit. All of the rest are 16-bit */
+
+/* If TIM2 or TIM5 are enabled, then we have 32-bit timers */
+
+#if defined(CONFIG_STM32L4_TIM2_QE) || defined(CONFIG_STM32L4_TIM5_QE)
+# define HAVE_32BIT_TIMERS 1
+#endif
+
+/* If TIM1,3,4, or 8 are enabled, then we have 16-bit timers */
+
+#if defined(CONFIG_STM32L4_TIM1_QE) || defined(CONFIG_STM32L4_TIM3_QE) || \
+ defined(CONFIG_STM32L4_TIM4_QE) || defined(CONFIG_STM32L4_TIM8_QE)
+# define HAVE_16BIT_TIMERS 1
+#endif
+
+ /* The width in bits of each timer */
+
+#define TIM1_BITWIDTH 16
+#define TIM2_BITWIDTH 32
+#define TIM3_BITWIDTH 16
+#define TIM4_BITWIDTH 16
+#define TIM5_BITWIDTH 32
+#define TIM8_BITWIDTH 16
+
+/* Do we need to support mixed 16- and 32-bit timers */
+
+#undef HAVE_MIXEDWIDTH_TIMERS
+#if defined(HAVE_16BIT_TIMERS) && defined(HAVE_32BIT_TIMERS)
+# define HAVE_MIXEDWIDTH_TIMERS 1
+#endif
+
+/* Input filter *********************************************************************/
+
+#ifdef CONFIG_STM32L4_QENCODER_FILTER
+# if defined(CONFIG_STM32L4_QENCODER_SAMPLE_FDTS)
+# if defined(CONFIG_STM32L4_QENCODER_SAMPLE_EVENT_1)
+# define STM32L4_QENCODER_ICF GTIM_CCMR_ICF_NOFILT
+# endif
+# elif defined(CONFIG_STM32L4_QENCODER_SAMPLE_CKINT)
+# if defined(CONFIG_STM32L4_QENCODER_SAMPLE_EVENT_2)
+# define STM32L4_QENCODER_ICF GTIM_CCMR_ICF_FCKINT2
+# elif defined(CONFIG_STM32L4_QENCODER_SAMPLE_EVENT_4)
+# define STM32L4_QENCODER_ICF GTIM_CCMR_ICF_FCKINT4
+# elif defined(CONFIG_STM32L4_QENCODER_SAMPLE_EVENT_8)
+# define STM32L4_QENCODER_ICF GTIM_CCMR_ICF_FCKINT8
+# endif
+# elif defined(CONFIG_STM32L4_QENCODER_SAMPLE_FDTS_2)
+# if defined(CONFIG_STM32L4_QENCODER_SAMPLE_EVENT_6)
+# define STM32L4_QENCODER_ICF GTIM_CCMR_ICF_FDTSd26
+# elif defined(CONFIG_STM32L4_QENCODER_SAMPLE_EVENT_8)
+# define STM32L4_QENCODER_ICF GTIM_CCMR_ICF_FDTSd28
+# endif
+# elif defined(CONFIG_STM32L4_QENCODER_SAMPLE_FDTS_4)
+# if defined(CONFIG_STM32L4_QENCODER_SAMPLE_EVENT_6)
+# define STM32L4_QENCODER_ICF GTIM_CCMR_ICF_FDTSd46
+# elif defined(CONFIG_STM32L4_QENCODER_SAMPLE_EVENT_8)
+# define STM32L4_QENCODER_ICF GTIM_CCMR_ICF_FDTSd48
+# endif
+# elif defined(CONFIG_STM32L4_QENCODER_SAMPLE_FDTS_8)
+# if defined(CONFIG_STM32L4_QENCODER_SAMPLE_EVENT_6)
+# define STM32L4_QENCODER_ICF GTIM_CCMR_ICF_FDTSd86
+# elif defined(CONFIG_STM32L4_QENCODER_SAMPLE_EVENT_8)
+# define STM32L4_QENCODER_ICF GTIM_CCMR_ICF_FDTSd88
+# endif
+# elif defined(CONFIG_STM32L4_QENCODER_SAMPLE_FDTS_16)
+# if defined(CONFIG_STM32L4_QENCODER_SAMPLE_EVENT_5)
+# define STM32L4_QENCODER_ICF GTIM_CCMR_ICF_FDTSd165
+# elif defined(CONFIG_STM32L4_QENCODER_SAMPLE_EVENT_6)
+# define STM32L4_QENCODER_ICF GTIM_CCMR_ICF_FDTSd166
+# elif defined(CONFIG_STM32L4_QENCODER_SAMPLE_EVENT_8)
+# define STM32L4_QENCODER_ICF GTIM_CCMR_ICF_FDTSd168
+# endif
+# elif defined(CONFIG_STM32L4_QENCODER_SAMPLE_FDTS_32)
+# if defined(CONFIG_STM32L4_QENCODER_SAMPLE_EVENT_5)
+# define STM32L4_QENCODER_ICF GTIM_CCMR_ICF_FDTSd325
+# elif defined(CONFIG_STM32L4_QENCODER_SAMPLE_EVENT_6)
+# define STM32L4_QENCODER_ICF GTIM_CCMR_ICF_FDTSd326
+# elif defined(CONFIG_STM32L4_QENCODER_SAMPLE_EVENT_8)
+# define STM32L4_QENCODER_ICF GTIM_CCMR_ICF_FDTSd328
+# endif
+# endif
+
+# ifndef STM32L4_QENCODER_ICF
+# warning "Invalid encoder filter combination, filter disabled"
+# endif
+#endif
+
+#ifndef STM32L4_QENCODER_ICF
+# define STM32L4_QENCODER_ICF GTIM_CCMR_ICF_NOFILT
+#endif
+
+#define STM32L4_GPIO_INPUT_FLOAT (GPIO_INPUT | GPIO_FLOAT)
+
+/* Debug ****************************************************************************/
+/* Non-standard debug that may be enabled just for testing the quadrature encoder */
+
+#ifndef CONFIG_DEBUG_FEATURES
+# undef CONFIG_DEBUG_SENSORS
+#endif
+
+#ifdef CONFIG_DEBUG_SENSORS
+# ifdef CONFIG_DEBUG_INFO
+# define qe_dumpgpio(p,m) stm32l4_dumpgpio(p,m)
+# else
+# define qe_dumpgpio(p,m)
+# endif
+#else
+# define qe_dumpgpio(p,m)
+#endif
+
+/************************************************************************************
+ * Private Types
+ ************************************************************************************/
+
+/* Constant configuration structure that is retained in FLASH */
+
+struct stm32l4_qeconfig_s
+{
+ uint8_t timid; /* Timer ID {1,2,3,4,5,8} */
+ uint8_t irq; /* Timer update IRQ */
+#ifdef HAVE_MIXEDWIDTH_TIMERS
+ uint8_t width; /* Timer width (16- or 32-bits) */
+#endif
+ uint32_t ti1cfg; /* TI1 input pin configuration (20-bit encoding) */
+ uint32_t ti2cfg; /* TI2 input pin configuration (20-bit encoding) */
+ uint32_t base; /* Register base address */
+ uint32_t psc; /* Timer input clock prescaler */
+ xcpt_t handler; /* Interrupt handler for this IRQ */
+};
+
+/* Overall, RAM-based state structure */
+
+struct stm32l4_lowerhalf_s
+{
+ /* The first field of this state structure must be a pointer to the lower-
+ * half callback structure:
+ */
+
+ FAR const struct qe_ops_s *ops; /* Lower half callback structure */
+
+ /* STM32 driver-specific fields: */
+
+ FAR const struct stm32l4_qeconfig_s *config; /* static onfiguration */
+
+ bool inuse; /* True: The lower-half driver is in-use */
+
+#ifdef HAVE_16BIT_TIMERS
+ volatile int32_t position; /* The current position offset */
+#endif
+};
+
+/************************************************************************************
+ * Private Function Prototypes
+ ************************************************************************************/
+/* Helper functions */
+
+static uint16_t stm32l4_getreg16(FAR struct stm32l4_lowerhalf_s *priv, int offset);
+static void stm32l4_putreg16(FAR struct stm32l4_lowerhalf_s *priv, int offset, uint16_t value);
+static uint32_t stm32l4_getreg32(FAR struct stm32l4_lowerhalf_s *priv, int offset);
+static void stm32l4_putreg32(FAR struct stm32l4_lowerhalf_s *priv, int offset, uint32_t value);
+
+#if defined(CONFIG_DEBUG_SENSORS) && defined(CONFIG_DEBUG_INFO)
+static void stm32l4_dumpregs(FAR struct stm32l4_lowerhalf_s *priv, FAR const char *msg);
+#else
+# define stm32l4_dumpregs(priv,msg)
+#endif
+
+static FAR struct stm32l4_lowerhalf_s *stm32l4_tim2lower(int tim);
+
+/* Interrupt handling */
+
+#ifdef HAVE_16BIT_TIMERS
+static int stm32l4_interrupt(FAR struct stm32l4_lowerhalf_s *priv);
+#if defined(CONFIG_STM32L4_TIM1_QE) && TIM1_BITWIDTH == 16
+static int stm32l4_tim1interrupt(int irq, FAR void *context);
+#endif
+#if defined(CONFIG_STM32L4_TIM2_QE) && TIM2_BITWIDTH == 16
+static int stm32l4_tim2interrupt(int irq, FAR void *context);
+#endif
+#if defined(CONFIG_STM32L4_TIM3_QE) && TIM3_BITWIDTH == 16
+static int stm32l4_tim3interrupt(int irq, FAR void *context);
+#endif
+#if defined(CONFIG_STM32L4_TIM4_QE) && TIM4_BITWIDTH == 16
+static int stm32l4_tim4interrupt(int irq, FAR void *context);
+#endif
+#if defined(CONFIG_STM32L4_TIM5_QE) && TIM5_BITWIDTH == 16
+static int stm32l4_tim5interrupt(int irq, FAR void *context);
+#endif
+#if defined(CONFIG_STM32L4_TIM8_QE) && TIM8_BITWIDTH == 16
+static int stm32l4_tim8interrupt(int irq, FAR void *context);
+#endif
+#endif
+
+/* Lower-half Quadrature Encoder Driver Methods */
+
+static int stm32l4_setup(FAR struct qe_lowerhalf_s *lower);
+static int stm32l4_shutdown(FAR struct qe_lowerhalf_s *lower);
+static int stm32l4_position(FAR struct qe_lowerhalf_s *lower, FAR int32_t *pos);
+static int stm32l4_reset(FAR struct qe_lowerhalf_s *lower);
+static int stm32l4_ioctl(FAR struct qe_lowerhalf_s *lower, int cmd, unsigned long arg);
+
+/************************************************************************************
+ * Private Data
+ ************************************************************************************/
+/* The lower half callback structure */
+
+static const struct qe_ops_s g_qecallbacks =
+{
+ .setup = stm32l4_setup,
+ .shutdown = stm32l4_shutdown,
+ .position = stm32l4_position,
+ .reset = stm32l4_reset,
+ .ioctl = stm32l4_ioctl,
+};
+
+/* Per-timer state structures */
+
+#ifdef CONFIG_STM32L4_TIM1_QE
+static const struct stm32l4_qeconfig_s g_tim1config =
+{
+ .timid = 1,
+ .irq = STM32L4_IRQ_TIM1UP,
+#ifdef HAVE_MIXEDWIDTH_TIMERS
+ .width = TIM1_BITWIDTH,
+#endif
+ .base = STM32L4_TIM1_BASE,
+ .psc = (STM32L4_APB2_TIM1_CLKIN / CONFIG_STM32L4_TIM1_QECLKOUT) - 1,
+ .ti1cfg = GPIO_TIM1_CH1IN,
+ .ti2cfg = GPIO_TIM1_CH2IN,
+#if TIM1_BITWIDTH == 16
+ .handler = stm32l4_tim1interrupt,
+#endif
+};
+
+static struct stm32l4_lowerhalf_s g_tim1lower =
+{
+ .ops = &g_qecallbacks,
+ .config = &g_tim1config,
+ .inuse = false,
+};
+
+#endif
+
+#ifdef CONFIG_STM32L4_TIM2_QE
+static const struct stm32l4_qeconfig_s g_tim2config =
+{
+ .timid = 2,
+ .irq = STM32L4_IRQ_TIM2,
+#ifdef HAVE_MIXEDWIDTH_TIMERS
+ .width = TIM2_BITWIDTH,
+#endif
+ .base = STM32L4_TIM2_BASE,
+ .psc = (STM32L4_APB1_TIM2_CLKIN / CONFIG_STM32L4_TIM2_QECLKOUT) - 1,
+ .ti1cfg = GPIO_TIM2_CH1IN,
+ .ti2cfg = GPIO_TIM2_CH2IN,
+#if TIM2_BITWIDTH == 16
+ .handler = stm32l4_tim2interrupt,
+#endif
+};
+
+static struct stm32l4_lowerhalf_s g_tim2lower =
+{
+ .ops = &g_qecallbacks,
+ .config = &g_tim2config,
+ .inuse = false,
+};
+
+#endif
+
+#ifdef CONFIG_STM32L4_TIM3_QE
+static const struct stm32l4_qeconfig_s g_tim3config =
+{
+ .timid = 3,
+ .irq = STM32L4_IRQ_TIM3,
+#ifdef HAVE_MIXEDWIDTH_TIMERS
+ .width = TIM3_BITWIDTH,
+#endif
+ .base = STM32L4_TIM3_BASE,
+ .psc = (STM32L4_APB1_TIM3_CLKIN / CONFIG_STM32L4_TIM3_QECLKOUT) - 1,
+ .ti1cfg = GPIO_TIM3_CH1IN,
+ .ti2cfg = GPIO_TIM3_CH2IN,
+#if TIM3_BITWIDTH == 16
+ .handler = stm32l4_tim3interrupt,
+#endif
+};
+
+static struct stm32l4_lowerhalf_s g_tim3lower =
+{
+ .ops = &g_qecallbacks,
+ .config = &g_tim3config,
+ .inuse = false,
+};
+
+#endif
+
+#ifdef CONFIG_STM32L4_TIM4_QE
+static const struct stm32l4_qeconfig_s g_tim4config =
+{
+ .timid = 4,
+ .irq = STM32L4_IRQ_TIM4,
+#ifdef HAVE_MIXEDWIDTH_TIMERS
+ .width = TIM4_BITWIDTH,
+#endif
+ .base = STM32L4_TIM4_BASE,
+ .psc = (STM32L4_APB1_TIM4_CLKIN / CONFIG_STM32L4_TIM4_QECLKOUT) - 1,
+ .ti1cfg = GPIO_TIM4_CH1IN,
+ .ti2cfg = GPIO_TIM4_CH2IN,
+#if TIM4_BITWIDTH == 16
+ .handler = stm32l4_tim4interrupt,
+#endif
+};
+
+static struct stm32l4_lowerhalf_s g_tim4lower =
+{
+ .ops = &g_qecallbacks,
+ .config = &g_tim4config,
+ .inuse = false,
+};
+
+#endif
+
+#ifdef CONFIG_STM32L4_TIM5_QE
+static const struct stm32l4_qeconfig_s g_tim5config =
+{
+ .timid = 5,
+ .irq = STM32L4_IRQ_TIM5,
+#ifdef HAVE_MIXEDWIDTH_TIMERS
+ .width = TIM5_BITWIDTH,
+#endif
+ .base = STM32L4_TIM5_BASE,
+ .psc = (STM32L4_APB1_TIM5_CLKIN / CONFIG_STM32L4_TIM5_QECLKOUT) - 1,
+ .ti1cfg = GPIO_TIM5_CH1IN,
+ .ti2cfg = GPIO_TIM5_CH2IN,
+#if TIM5_BITWIDTH == 16
+ .handler = stm32l4_tim5interrupt,
+#endif
+};
+
+static struct stm32l4_lowerhalf_s g_tim5lower =
+{
+ .ops = &g_qecallbacks,
+ .config = &g_tim5config,
+ .inuse = false,
+};
+
+#endif
+
+#ifdef CONFIG_STM32L4_TIM8_QE
+static const struct stm32l4_qeconfig_s g_tim8config =
+{
+ .timid = 8,
+ .irq = STM32L4_IRQ_TIM8UP,
+#ifdef HAVE_MIXEDWIDTH_TIMERS
+ .width = TIM8_BITWIDTH,
+#endif
+ .base = STM32L4_TIM8_BASE,
+ .psc = (STM32L4_APB2_TIM8_CLKIN / CONFIG_STM32L4_TIM8_QECLKOUT) - 1,
+ .ti1cfg = GPIO_TIM8_CH1IN,
+ .ti2cfg = GPIO_TIM8_CH2IN,
+#if TIM8_BITWIDTH == 16
+ .handler = stm32l4_tim8interrupt,
+#endif
+};
+
+static struct stm32l4_lowerhalf_s g_tim8lower =
+{
+ .ops = &g_qecallbacks,
+ .config = &g_tim8config,
+ .inuse = false,
+};
+
+#endif
+
+/************************************************************************************
+ * Private Functions
+ ************************************************************************************/
+
+/************************************************************************************
+ * Name: stm32l4_getreg16
+ *
+ * Description:
+ * Read the value of a 16-bit timer register.
+ *
+ * Input Parameters:
+ * priv - A reference to the lower half status
+ * offset - The offset to the register to read
+ *
+ * Returned Value:
+ * The current contents of the specified register
+ *
+ ************************************************************************************/
+
+static uint16_t stm32l4_getreg16(struct stm32l4_lowerhalf_s *priv, int offset)
+{
+ return getreg16(priv->config->base + offset);
+}
+
+/************************************************************************************
+ * Name: stm32l4_putreg16
+ *
+ * Description:
+ * Write a value to a 16-bit timer register.
+ *
+ * Input Parameters:
+ * priv - A reference to the lower half status
+ * offset - The offset to the register to read
+ *
+ * Returned Value:
+ * None
+ *
+ ************************************************************************************/
+
+static void stm32l4_putreg16(FAR struct stm32l4_lowerhalf_s *priv, int offset,
+ uint16_t value)
+{
+ putreg16(value, priv->config->base + offset);
+}
+
+/************************************************************************************
+ * Name: stm32l4_getreg32
+ *
+ * Description:
+ * Read the value of a 32-bit timer register. This applies only for the STM32 F4
+ * 32-bit registers (CNT, ARR, CRR1-4) in the 32-bit timers TIM2-5 (but works OK
+ * with the 16-bit TIM1,8 and F1 registers as well).
+ *
+ * Input Parameters:
+ * priv - A reference to the lower half status
+ * offset - The offset to the register to read
+ *
+ * Returned Value:
+ * The current contents of the specified register
+ *
+ ************************************************************************************/
+
+static uint32_t stm32l4_getreg32(FAR struct stm32l4_lowerhalf_s *priv, int offset)
+{
+ return getreg32(priv->config->base + offset);
+}
+
+/************************************************************************************
+ * Name: stm32l4_putreg16
+ *
+ * Description:
+ * Write a value to a 32-bit timer register. This applies only for the STM32 F4
+ * 32-bit registers (CNT, ARR, CRR1-4) in the 32-bit timers TIM2-5 (but works OK
+ * with the 16-bit TIM1,8 and F1 registers).
+ *
+ * Input Parameters:
+ * priv - A reference to the lower half status
+ * offset - The offset to the register to read
+ *
+ * Returned Value:
+ * None
+ *
+ ************************************************************************************/
+
+static void stm32l4_putreg32(FAR struct stm32l4_lowerhalf_s *priv, int offset,
+ uint32_t value)
+{
+ putreg32(value, priv->config->base + offset);
+}
+
+/****************************************************************************
+ * Name: stm32l4_dumpregs
+ *
+ * Description:
+ * Dump all timer registers.
+ *
+ * Input parameters:
+ * priv - A reference to the QENCODER block status
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+#if defined(CONFIG_DEBUG_SENSORS) && defined(CONFIG_DEBUG_INFO)
+static void stm32l4_dumpregs(FAR struct stm32l4_lowerhalf_s *priv,
+ FAR const char *msg)
+{
+ sninfo("%s:\n", msg);
+ sninfo(" CR1: %04x CR2: %04x SMCR: %04x DIER: %04x\n",
+ stm32l4_getreg16(priv, STM32L4_GTIM_CR1_OFFSET),
+ stm32l4_getreg16(priv, STM32L4_GTIM_CR2_OFFSET),
+ stm32l4_getreg16(priv, STM32L4_GTIM_SMCR_OFFSET),
+ stm32l4_getreg16(priv, STM32L4_GTIM_DIER_OFFSET));
+ sninfo(" SR: %04x EGR: %04x CCMR1: %04x CCMR2: %04x\n",
+ stm32l4_getreg16(priv, STM32L4_GTIM_SR_OFFSET),
+ stm32l4_getreg16(priv, STM32L4_GTIM_EGR_OFFSET),
+ stm32l4_getreg16(priv, STM32L4_GTIM_CCMR1_OFFSET),
+ stm32l4_getreg16(priv, STM32L4_GTIM_CCMR2_OFFSET));
+ sninfo(" CCER: %04x CNT: %04x PSC: %04x ARR: %04x\n",
+ stm32l4_getreg16(priv, STM32L4_GTIM_CCER_OFFSET),
+ stm32l4_getreg16(priv, STM32L4_GTIM_CNT_OFFSET),
+ stm32l4_getreg16(priv, STM32L4_GTIM_PSC_OFFSET),
+ stm32l4_getreg16(priv, STM32L4_GTIM_ARR_OFFSET));
+ sninfo(" CCR1: %04x CCR2: %04x CCR3: %04x CCR4: %04x\n",
+ stm32l4_getreg16(priv, STM32L4_GTIM_CCR1_OFFSET),
+ stm32l4_getreg16(priv, STM32L4_GTIM_CCR2_OFFSET),
+ stm32l4_getreg16(priv, STM32L4_GTIM_CCR3_OFFSET),
+ stm32l4_getreg16(priv, STM32L4_GTIM_CCR4_OFFSET));
+#if defined(CONFIG_STM32L4_TIM1_QE) || defined(CONFIG_STM32L4_TIM8_QE)
+ if (priv->config->timid == 1 || priv->config->timid == 8)
+ {
+ sninfo(" RCR: %04x BDTR: %04x DCR: %04x DMAR: %04x\n",
+ stm32l4_getreg16(priv, STM32L4_ATIM_RCR_OFFSET),
+ stm32l4_getreg16(priv, STM32L4_ATIM_BDTR_OFFSET),
+ stm32l4_getreg16(priv, STM32L4_ATIM_DCR_OFFSET),
+ stm32l4_getreg16(priv, STM32L4_ATIM_DMAR_OFFSET));
+ }
+ else
+#endif
+ {
+ sninfo(" DCR: %04x DMAR: %04x\n",
+ stm32l4_getreg16(priv, STM32L4_GTIM_DCR_OFFSET),
+ stm32l4_getreg16(priv, STM32L4_GTIM_DMAR_OFFSET));
+ }
+}
+#endif
+
+/************************************************************************************
+ * Name: stm32l4_tim2lower
+ *
+ * Description:
+ * Map a timer number to a device structure
+ *
+ ************************************************************************************/
+
+static FAR struct stm32l4_lowerhalf_s *stm32l4_tim2lower(int tim)
+{
+ switch (tim)
+ {
+#ifdef CONFIG_STM32L4_TIM1_QE
+ case 1:
+ return &g_tim1lower;
+#endif
+#ifdef CONFIG_STM32L4_TIM2_QE
+ case 2:
+ return &g_tim2lower;
+#endif
+#ifdef CONFIG_STM32L4_TIM3_QE
+ case 3:
+ return &g_tim3lower;
+#endif
+#ifdef CONFIG_STM32L4_TIM4_QE
+ case 4:
+ return &g_tim4lower;
+#endif
+#ifdef CONFIG_STM32L4_TIM5_QE
+ case 5:
+ return &g_tim5lower;
+#endif
+#ifdef CONFIG_STM32L4_TIM8_QE
+ case 8:
+ return &g_tim8lower;
+#endif
+ default:
+ return NULL;
+ }
+}
+
+/************************************************************************************
+ * Name: stm32l4_interrupt
+ *
+ * Description:
+ * Common timer interrupt handling. NOTE: Only 16-bit timers require timer
+ * interrupts.
+ *
+ ************************************************************************************/
+
+#ifdef HAVE_16BIT_TIMERS
+static int stm32l4_interrupt(FAR struct stm32l4_lowerhalf_s *priv)
+{
+ uint16_t regval;
+
+ /* Verify that this is an update interrupt. Nothing else is expected. */
+
+ regval = stm32l4_getreg16(priv, STM32L4_GTIM_SR_OFFSET);
+ DEBUGASSERT((regval & ATIM_SR_UIF) != 0);
+
+ /* Clear the UIF interrupt bit */
+
+ stm32l4_putreg16(priv, STM32L4_GTIM_SR_OFFSET, regval & ~GTIM_SR_UIF);
+
+ /* Check the direction bit in the CR1 register and add or subtract the
+ * maximum value, as appropriate.
+ */
+
+ regval = stm32l4_getreg16(priv, STM32L4_GTIM_CR1_OFFSET);
+ if ((regval & ATIM_CR1_DIR) != 0)
+ {
+ priv->position -= (int32_t)0x0000ffff;
+ }
+ else
+ {
+ priv->position += (int32_t)0x0000ffff;
+ }
+
+ return OK;
+}
+#endif
+
+/************************************************************************************
+ * Name: stm32l4_timNinterrupt
+ *
+ * Description:
+ * TIMN interrupt handler
+ *
+ ************************************************************************************/
+
+#if defined(CONFIG_STM32L4_TIM1_QE) && TIM1_BITWIDTH == 16
+static int stm32l4_tim1interrupt(int irq, FAR void *context)
+{
+ return stm32l4_interrupt(&g_tim1lower);
+}
+#endif
+
+#if defined(CONFIG_STM32L4_TIM2_QE) && TIM2_BITWIDTH == 16
+static int stm32l4_tim2interrupt(int irq, FAR void *context)
+{
+ return stm32l4_interrupt(&g_tim2lower);
+}
+#endif
+
+#if defined(CONFIG_STM32L4_TIM3_QE) && TIM3_BITWIDTH == 16
+static int stm32l4_tim3interrupt(int irq, FAR void *context)
+{
+ return stm32l4_interrupt(&g_tim3lower);
+}
+#endif
+
+#if defined(CONFIG_STM32L4_TIM4_QE) && TIM4_BITWIDTH == 16
+static int stm32l4_tim4interrupt(int irq, FAR void *context)
+{
+ return stm32l4_interrupt(&g_tim4lower);
+}
+#endif
+
+#if defined(CONFIG_STM32L4_TIM5_QE) && TIM5_BITWIDTH == 16
+static int stm32l4_tim5interrupt(int irq, FAR void *context)
+{
+ return stm32l4_interrupt(&g_tim5lower);
+}
+#endif
+
+#if defined(CONFIG_STM32L4_TIM8_QE) && TIM8_BITWIDTH == 16
+static int stm32l4_tim8interrupt(int irq, FAR void *context)
+{
+ return stm32l4_interrupt(&g_tim8lower);
+}
+#endif
+
+/************************************************************************************
+ * Name: stm32l4_setup
+ *
+ * Description:
+ * This method is called when the driver is opened. The lower half driver
+ * should configure and initialize the device so that it is ready for use.
+ * The initial position value should be zero. *
+ *
+ ************************************************************************************/
+
+static int stm32l4_setup(FAR struct qe_lowerhalf_s *lower)
+{
+ FAR struct stm32l4_lowerhalf_s *priv = (FAR struct stm32l4_lowerhalf_s *)lower;
+ uint16_t dier;
+ uint16_t smcr;
+ uint16_t ccmr1;
+ uint16_t ccer;
+ uint16_t cr1;
+#ifdef HAVE_16BIT_TIMERS
+ uint16_t regval;
+ int ret;
+#endif
+
+ /* NOTE: Clocking should have been enabled in the low-level RCC logic at boot-up */
+
+ /* Timer base configuration */
+
+ cr1 = stm32l4_getreg16(priv, STM32L4_GTIM_CR1_OFFSET);
+
+ /* Clear the direction bit (0=count up) and select the Counter Mode (0=Edge aligned)
+ * (Timers 2-5 and 1-8 only)
+ */
+
+ cr1 &= ~(GTIM_CR1_DIR | GTIM_CR1_CMS_MASK);
+ stm32l4_putreg16(priv, STM32L4_GTIM_CR1_OFFSET, cr1);
+
+ /* Set the Autoreload value */
+
+#if defined(HAVE_MIXEDWIDTH_TIMERS)
+ if (priv->config->width == 32)
+ {
+ stm32l4_putreg32(priv, STM32L4_GTIM_ARR_OFFSET, 0xffffffff);
+ }
+ else
+ {
+ stm32l4_putreg16(priv, STM32L4_GTIM_ARR_OFFSET, 0xffff);
+ }
+#elif defined(HAVE_32BIT_TIMERS)
+ stm32l4_putreg32(priv, STM32L4_GTIM_ARR_OFFSET, 0xffffffff);
+#else
+ stm32l4_putreg16(priv, STM32L4_GTIM_ARR_OFFSET, 0xffff);
+#endif
+
+ /* Set the timer prescaler value. The clock input value (CLKIN) is based on the
+ * peripheral clock (PCLK) and a multiplier. These CLKIN values are provided in
+ * the board.h file. The prescaler value is then that CLKIN value divided by the
+ * configured CLKOUT value (minus one)
+ */
+
+ stm32l4_putreg16(priv, STM32L4_GTIM_PSC_OFFSET, (uint16_t)priv->config->psc);
+
+#if defined(CONFIG_STM32L4_TIM1_QE) || defined(CONFIG_STM32L4_TIM8_QE)
+ if (priv->config->timid == 1 || priv->config->timid == 8)
+ {
+ /* Clear the Repetition Counter value */
+
+ stm32l4_putreg16(priv, STM32L4_ATIM_RCR_OFFSET, 0);
+ }
+#endif
+
+ /* Generate an update event to reload the Prescaler
+ * and the repetition counter (only for TIM1 and TIM8) value immediately
+ */
+
+ stm32l4_putreg16(priv, STM32L4_GTIM_EGR_OFFSET, GTIM_EGR_UG);
+
+ /* GPIO pin configuration */
+
+ stm32l4_configgpio(priv->config->ti1cfg);
+ stm32l4_configgpio(priv->config->ti2cfg);
+
+ /* Set the encoder Mode 3 */
+
+ smcr = stm32l4_getreg16(priv, STM32L4_GTIM_SMCR_OFFSET);
+ smcr &= ~GTIM_SMCR_SMS_MASK;
+ smcr |= GTIM_SMCR_ENCMD3;
+ stm32l4_putreg16(priv, STM32L4_GTIM_SMCR_OFFSET, smcr);
+
+ /* TI1 Channel Configuration */
+ /* Disable the Channel 1: Reset the CC1E Bit */
+
+ ccer = stm32l4_getreg16(priv, STM32L4_GTIM_CCER_OFFSET);
+ ccer &= ~GTIM_CCER_CC1E;
+ stm32l4_putreg16(priv, STM32L4_GTIM_CCER_OFFSET, ccer);
+
+ ccmr1 = stm32l4_getreg16(priv, STM32L4_GTIM_CCMR1_OFFSET);
+ ccer = stm32l4_getreg16(priv, STM32L4_GTIM_CCER_OFFSET);
+
+ /* Select the Input IC1=TI1 and set the filter fSAMPLING=fDTS/4, N=6 */
+
+ ccmr1 &= ~(GTIM_CCMR1_CC1S_MASK | GTIM_CCMR1_IC1F_MASK);
+ ccmr1 |= GTIM_CCMR_CCS_CCIN1 << GTIM_CCMR1_CC1S_SHIFT;
+ ccmr1 |= STM32L4_QENCODER_ICF << GTIM_CCMR1_IC1F_SHIFT;
+
+ /* Select the Polarity=rising and set the CC1E Bit */
+
+ ccer &= ~(GTIM_CCER_CC1P | GTIM_CCER_CC1NP);
+ ccer |= GTIM_CCER_CC1E;
+
+ /* Write to TIM CCMR1 and CCER registers */
+
+ stm32l4_putreg16(priv, STM32L4_GTIM_CCMR1_OFFSET, ccmr1);
+ stm32l4_putreg16(priv, STM32L4_GTIM_CCER_OFFSET, ccer);
+
+ /* Set the Input Capture Prescaler value: Capture performed each time an
+ * edge is detected on the capture input.
+ */
+
+ ccmr1 = stm32l4_getreg16(priv, STM32L4_GTIM_CCMR1_OFFSET);
+ ccmr1 &= ~GTIM_CCMR1_IC1PSC_MASK;
+ ccmr1 |= (GTIM_CCMR_ICPSC_NOPSC << GTIM_CCMR1_IC1PSC_SHIFT);
+ stm32l4_putreg16(priv, STM32L4_GTIM_CCMR1_OFFSET, ccmr1);
+
+ /* TI2 Channel Configuration */
+ /* Disable the Channel 2: Reset the CC2E Bit */
+
+ ccer = stm32l4_getreg16(priv, STM32L4_GTIM_CCER_OFFSET);
+ ccer &= ~GTIM_CCER_CC2E;
+ stm32l4_putreg16(priv, STM32L4_GTIM_CCER_OFFSET, ccer);
+
+ ccmr1 = stm32l4_getreg16(priv, STM32L4_GTIM_CCMR1_OFFSET);
+ ccer = stm32l4_getreg16(priv, STM32L4_GTIM_CCER_OFFSET);
+
+ /* Select the Input IC2=TI2 and set the filter fSAMPLING=fDTS/4, N=6 */
+
+ ccmr1 &= ~(GTIM_CCMR1_CC2S_MASK | GTIM_CCMR1_IC2F_MASK);
+ ccmr1 |= GTIM_CCMR_CCS_CCIN1 << GTIM_CCMR1_CC2S_SHIFT;
+ ccmr1 |= STM32L4_QENCODER_ICF << GTIM_CCMR1_IC2F_SHIFT;
+
+ /* Select the Polarity=rising and set the CC2E Bit */
+
+ ccer &= ~(GTIM_CCER_CC2P | GTIM_CCER_CC2NP);
+ ccer |= GTIM_CCER_CC2E;
+
+ /* Write to TIM CCMR1 and CCER registers */
+
+ stm32l4_putreg16(priv, STM32L4_GTIM_CCMR1_OFFSET, ccmr1);
+ stm32l4_putreg16(priv, STM32L4_GTIM_CCER_OFFSET, ccer);
+
+ /* Set the Input Capture Prescaler value: Capture performed each time an
+ * edge is detected on the capture input.
+ */
+
+ ccmr1 = stm32l4_getreg16(priv, STM32L4_GTIM_CCMR1_OFFSET);
+ ccmr1 &= ~GTIM_CCMR1_IC2PSC_MASK;
+ ccmr1 |= (GTIM_CCMR_ICPSC_NOPSC << GTIM_CCMR1_IC2PSC_SHIFT);
+ stm32l4_putreg16(priv, STM32L4_GTIM_CCMR1_OFFSET, ccmr1);
+
+ /* Disable the update interrupt */
+
+ dier = stm32l4_getreg16(priv, STM32L4_GTIM_DIER_OFFSET);
+ dier &= ~GTIM_DIER_UIE;
+ stm32l4_putreg16(priv, STM32L4_GTIM_DIER_OFFSET, dier);
+
+ /* There is no need for interrupts with 32-bit timers */
+
+#ifdef HAVE_16BIT_TIMERS
+#ifdef HAVE_MIXEDWIDTH_TIMERS
+ if (priv->config->width != 32)
+#endif
+ {
+ /* Attach the interrupt handler */
+
+ ret = irq_attach(priv->config->irq, priv->config->handler);
+ if (ret < 0)
+ {
+ stm32l4_shutdown(lower);
+ return ret;
+ }
+
+ /* Enable the update/global interrupt at the NVIC */
+
+ up_enable_irq(priv->config->irq);
+ }
+#endif
+
+ /* Reset the Update Disable Bit */
+
+ cr1 = stm32l4_getreg16(priv, STM32L4_GTIM_CR1_OFFSET);
+ cr1 &= ~GTIM_CR1_UDIS;
+ stm32l4_putreg16(priv, STM32L4_GTIM_CR1_OFFSET, cr1);
+
+ /* Reset the URS Bit */
+
+ cr1 &= ~GTIM_CR1_URS;
+ stm32l4_putreg16(priv, STM32L4_GTIM_CR1_OFFSET, cr1);
+
+ /* There is no need for interrupts with 32-bit timers */
+
+#ifdef HAVE_16BIT_TIMERS
+#ifdef HAVE_MIXEDWIDTH_TIMERS
+ if (priv->config->width != 32)
+#endif
+ {
+ /* Clear any pending update interrupts */
+
+ regval = stm32l4_getreg16(priv, STM32L4_GTIM_SR_OFFSET);
+ stm32l4_putreg16(priv, STM32L4_GTIM_SR_OFFSET, regval & ~GTIM_SR_UIF);
+
+ /* Then enable the update interrupt */
+
+ dier = stm32l4_getreg16(priv, STM32L4_GTIM_DIER_OFFSET);
+ dier |= GTIM_DIER_UIE;
+ stm32l4_putreg16(priv, STM32L4_GTIM_DIER_OFFSET, dier);
+ }
+#endif
+
+ /* Enable the TIM Counter */
+
+ cr1 = stm32l4_getreg16(priv, STM32L4_GTIM_CR1_OFFSET);
+ cr1 |= GTIM_CR1_CEN;
+ stm32l4_putreg16(priv, STM32L4_GTIM_CR1_OFFSET, cr1);
+
+ return OK;
+}
+
+/************************************************************************************
+ * Name: stm32l4_shutdown
+ *
+ * Description:
+ * This method is called when the driver is closed. The lower half driver
+ * should stop data collection, free any resources, disable timer hardware, and
+ * put the system into the lowest possible power usage state *
+ *
+ ************************************************************************************/
+
+static int stm32l4_shutdown(FAR struct qe_lowerhalf_s *lower)
+{
+ FAR struct stm32l4_lowerhalf_s *priv = (FAR struct stm32l4_lowerhalf_s *)lower;
+ irqstate_t flags;
+ uint32_t regaddr;
+ uint32_t regval;
+ uint32_t resetbit;
+ uint32_t pincfg;
+
+ /* Disable the update/global interrupt at the NVIC */
+
+ flags = enter_critical_section();
+ up_disable_irq(priv->config->irq);
+
+ /* Detach the interrupt handler */
+
+ (void)irq_detach(priv->config->irq);
+
+ /* Disable interrupts momentary to stop any ongoing timer processing and
+ * to prevent any concurrent access to the reset register.
+ */
+
+ /* Disable further interrupts and stop the timer */
+
+ stm32l4_putreg16(priv, STM32L4_GTIM_DIER_OFFSET, 0);
+ stm32l4_putreg16(priv, STM32L4_GTIM_SR_OFFSET, 0);
+
+ /* Determine which timer to reset */
+
+ switch (priv->config->timid)
+ {
+#ifdef CONFIG_STM32L4_TIM1_QE
+ case 1:
+ regaddr = STM32L4_RCC_APB2RSTR;
+ resetbit = RCC_APB2RSTR_TIM1RST;
+ break;
+#endif
+#ifdef CONFIG_STM32L4_TIM2_QE
+ case 2:
+ regaddr = STM32L4_RCC_APB1RSTR1;
+ resetbit = RCC_APB1RSTR1_TIM2RST;
+ break;
+#endif
+#ifdef CONFIG_STM32L4_TIM3_QE
+ case 3:
+ regaddr = STM32L4_RCC_APB1RSTR1;
+ resetbit = RCC_APB1RSTR1_TIM3RST;
+ break;
+#endif
+#ifdef CONFIG_STM32L4_TIM4_QE
+ case 4:
+ regaddr = STM32L4_RCC_APB1RSTR1;
+ resetbit = RCC_APB1RSTR1_TIM4RST;
+ break;
+#endif
+#ifdef CONFIG_STM32L4_TIM5_QE
+ case 5:
+ regaddr = STM32L4_RCC_APB1RSTR1;
+ resetbit = RCC_APB1RSTR1_TIM5RST;
+ break;
+#endif
+#ifdef CONFIG_STM32L4_TIM8_QE
+ case 8:
+ regaddr = STM32L4_RCC_APB2RSTR;
+ resetbit = RCC_APB2RSTR_TIM8RST;
+ break;
+#endif
+ default:
+ return -EINVAL;
+ }
+
+ /* Reset the timer - stopping the output and putting the timer back
+ * into a state where stm32l4_start() can be called.
+ */
+
+ regval = getreg32(regaddr);
+ regval |= resetbit;
+ putreg32(regval, regaddr);
+
+ regval &= ~resetbit;
+ putreg32(regval, regaddr);
+ leave_critical_section(flags);
+
+ sninfo("regaddr: %08x resetbit: %08x\n", regaddr, resetbit);
+ stm32l4_dumpregs(priv, "After stop");
+
+ /* Put the TI1 GPIO pin back to its default state */
+
+ pincfg = priv->config->ti1cfg & (GPIO_PORT_MASK | GPIO_PIN_MASK);
+ pincfg |= STM32L4_GPIO_INPUT_FLOAT;
+
+ stm32l4_configgpio(pincfg);
+
+ /* Put the TI2 GPIO pin back to its default state */
+
+ pincfg = priv->config->ti2cfg & (GPIO_PORT_MASK | GPIO_PIN_MASK);
+ pincfg |= STM32L4_GPIO_INPUT_FLOAT;
+
+ stm32l4_configgpio(pincfg);
+ return OK;
+}
+
+/************************************************************************************
+ * Name: stm32l4_position
+ *
+ * Description:
+ * Return the current position measurement.
+ *
+ ************************************************************************************/
+
+static int stm32l4_position(FAR struct qe_lowerhalf_s *lower, FAR int32_t *pos)
+{
+ FAR struct stm32l4_lowerhalf_s *priv = (FAR struct stm32l4_lowerhalf_s *)lower;
+#ifdef HAVE_16BIT_TIMERS
+ int32_t position;
+ int32_t verify;
+ uint32_t count;
+
+ DEBUGASSERT(lower && priv->inuse);
+
+ /* Loop until we are certain that no interrupt occurred between samples */
+
+ do
+ {
+ /* Don't let another task pre-empt us until we get the measurement. The timer
+ * interrupt may still be processed
+ */
+
+ sched_lock();
+ position = priv->position;
+ count = stm32l4_getreg32(priv, STM32L4_GTIM_CNT_OFFSET);
+ verify = priv->position;
+ sched_unlock();
+ }
+ while (position != verify);
+
+ /* Return the position measurement */
+
+ *pos = position + (int32_t)count;
+#else
+ /* Return the counter value */
+
+ *pos = (int32_t)stm32l4_getreg32(priv, STM32L4_GTIM_CNT_OFFSET);
+#endif
+ return OK;
+}
+
+/************************************************************************************
+ * Name: stm32l4_reset
+ *
+ * Description:
+ * Reset the position measurement to zero.
+ *
+ ************************************************************************************/
+
+static int stm32l4_reset(FAR struct qe_lowerhalf_s *lower)
+{
+ FAR struct stm32l4_lowerhalf_s *priv = (FAR struct stm32l4_lowerhalf_s *)lower;
+#ifdef HAVE_16BIT_TIMERS
+ irqstate_t flags;
+
+ sninfo("Resetting position to zero\n");
+ DEBUGASSERT(lower && priv->inuse);
+
+ /* Reset the timer and the counter. Interrupts are disabled to make this atomic
+ * (if possible)
+ */
+
+ flags = enter_critical_section();
+ stm32l4_putreg32(priv, STM32L4_GTIM_CNT_OFFSET, 0);
+ priv->position = 0;
+ leave_critical_section(flags);
+#else
+ sninfo("Resetting position to zero\n");
+ DEBUGASSERT(lower && priv->inuse);
+
+ /* Reset the counter to zero */
+
+ stm32l4_putreg32(priv, STM32L4_GTIM_CNT_OFFSET, 0);
+#endif
+ return OK;
+}
+
+/************************************************************************************
+ * Name: stm32l4_ioctl
+ *
+ * Description:
+ * Lower-half logic may support platform-specific ioctl commands
+ *
+ ************************************************************************************/
+
+static int stm32l4_ioctl(FAR struct qe_lowerhalf_s *lower, int cmd, unsigned long arg)
+{
+ /* No ioctl commands supported */
+
+ return -ENOTTY;
+}
+
+/************************************************************************************
+ * Public Functions
+ ************************************************************************************/
+
+/************************************************************************************
+ * Name: stm32l4_qeinitialize
+ *
+ * Description:
+ * Initialize a quadrature encoder interface. This function must be called from
+ * board-specific logic.
+ *
+ * Input Parameters:
+ * devpath - The full path to the driver to register. E.g., "/dev/qe0"
+ * tim - The timer number to used. 'tim' must be an element of {1,2,3,4,5,8}
+ *
+ * Returned Values:
+ * Zero on success; A negated errno value is returned on failure.
+ *
+ ************************************************************************************/
+
+int stm32l4_qeinitialize(FAR const char *devpath, int tim)
+{
+ FAR struct stm32l4_lowerhalf_s *priv;
+ int ret;
+
+ /* Find the pre-allocated timer state structure corresponding to this timer */
+
+ priv = stm32l4_tim2lower(tim);
+ if (!priv)
+ {
+ snerr("ERROR: TIM%d support not configured\n", tim);
+ return -ENXIO;
+ }
+
+ /* Make sure that it is available */
+
+ if (priv->inuse)
+ {
+ snerr("ERROR: TIM%d is in-use\n", tim);
+ return -EBUSY;
+ }
+
+ /* Register the priv-half driver */
+
+ ret = qe_register(devpath, (FAR struct qe_lowerhalf_s *)priv);
+ if (ret < 0)
+ {
+ snerr("ERROR: qe_register failed: %d\n", ret);
+ return ret;
+ }
+
+ /* Make sure that the timer is in the shutdown state */
+
+ stm32l4_shutdown((FAR struct qe_lowerhalf_s *)priv);
+
+ /* The driver is now in-use */
+
+ priv->inuse = true;
+ return OK;
+}
+
+#endif /* CONFIG_QENCODER */
diff --git a/arch/arm/src/stm32l4/stm32l4_qencoder.h b/arch/arm/src/stm32l4/stm32l4_qencoder.h
new file mode 100644
index 0000000000..fca0b88b8b
--- /dev/null
+++ b/arch/arm/src/stm32l4/stm32l4_qencoder.h
@@ -0,0 +1,141 @@
+/************************************************************************************
+ * arch/arm/src/stm32l4/stm32l4_qencoder.h
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * 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.
+ *
+ ************************************************************************************/
+
+#ifndef __ARCH_ARM_SRC_STM32L4_STM32L4_QENCODER_H
+#define __ARCH_ARM_SRC_STM32L4_STM32L4_QENCODER_H
+
+/************************************************************************************
+ * Included Files
+ ************************************************************************************/
+
+#include
+
+#include "chip.h"
+
+#ifdef CONFIG_QENCODER
+
+/************************************************************************************
+ * Included Files
+ ************************************************************************************/
+/* Timer devices may be used for different purposes. One special purpose is as
+ * a quadrature encoder input device. If CONFIG_STM32L4_TIMn is defined then the
+ * CONFIG_STM32L4_TIMn_QE must also be defined to indicate that timer "n" is intended
+ * to be used for as a quadrature encoder.
+ */
+
+#ifndef CONFIG_STM32L4_TIM1
+# undef CONFIG_STM32L4_TIM1_QE
+#endif
+#ifndef CONFIG_STM32L4_TIM2
+# undef CONFIG_STM32L4_TIM2_QE
+#endif
+#ifndef CONFIG_STM32L4_TIM3
+# undef CONFIG_STM32L4_TIM3_QE
+#endif
+#ifndef CONFIG_STM32L4_TIM4
+# undef CONFIG_STM32L4_TIM4_QE
+#endif
+#ifndef CONFIG_STM32L4_TIM5
+# undef CONFIG_STM32L4_TIM5_QE
+#endif
+#ifndef CONFIG_STM32L4_TIM8
+# undef CONFIG_STM32L4_TIM8_QE
+#endif
+
+/* Only timers 2-5, and 1 & 8 can be used as a quadrature encoder
+ */
+
+#undef CONFIG_STM32L4_TIM6_QE
+#undef CONFIG_STM32L4_TIM7_QE
+#undef CONFIG_STM32L4_TIM9_QE
+#undef CONFIG_STM32L4_TIM10_QE
+#undef CONFIG_STM32L4_TIM11_QE
+#undef CONFIG_STM32L4_TIM12_QE
+#undef CONFIG_STM32L4_TIM13_QE
+#undef CONFIG_STM32L4_TIM14_QE
+
+/* Clock out frequency. This value is used to calculation the timer CLKIN in
+ * prescaler value.
+ */
+
+#ifndef CONFIG_STM32L4_TIM1_QECLKOUT
+# define CONFIG_STM32L4_TIM1_QECLKOUT 28000000
+#endif
+
+#ifndef CONFIG_STM32L4_TIM2_QECLKOUT
+# define CONFIG_STM32L4_TIM2_QECLKOUT 28000000
+#endif
+
+#ifndef CONFIG_STM32L4_TIM3_QECLKOUT
+# define CONFIG_STM32L4_TIM3_QECLKOUT 28000000
+#endif
+
+#ifndef CONFIG_STM32L4_TIM4_QECLKOUT
+# define CONFIG_STM32L4_TIM4_QECLKOUT 28000000
+#endif
+
+#ifndef CONFIG_STM32L4_TIM5_QECLKOUT
+# define CONFIG_STM32L4_TIM5_QECLKOUT 28000000
+#endif
+
+#ifndef CONFIG_STM32L4_TIM8_QECLKOUT
+# define CONFIG_STM32L4_TIM8_QECLKOUT 28000000
+#endif
+
+/************************************************************************************
+ * Included Files
+ ************************************************************************************/
+
+/************************************************************************************
+ * Name: stm32l4_qeinitialize
+ *
+ * Description:
+ * Initialize a quadrature encoder interface. This function must be called from
+ * board-specific logic..
+ *
+ * Input Parameters:
+ * devpath - The full path to the driver to register. E.g., "/dev/qe0"
+ * tim - The timer number to used. 'tim' must be an element of {1,2,3,4,5,8}
+ *
+ * Returned Values:
+ * Zero on success; A negated errno value is returned on failure.
+ *
+ ************************************************************************************/
+
+int stm32l4_qeinitialize(FAR const char *devpath, int tim);
+
+#endif /* CONFIG_QENCODER */
+#endif /* __ARCH_ARM_SRC_STM32L4_STM32L4_QENCODER_H */
+
--
GitLab
From 06c70129ed0bc9f6db4c30b0fa9adf870982c198 Mon Sep 17 00:00:00 2001
From: Gregory Nutt
Date: Sun, 2 Oct 2016 16:05:13 -0600
Subject: [PATCH 023/734] STM32L4: Remove dependencies on STM32 F3 from Kconfig
---
arch/arm/src/stm32l4/Kconfig | 99 ++++++++++++------------------------
1 file changed, 33 insertions(+), 66 deletions(-)
diff --git a/arch/arm/src/stm32l4/Kconfig b/arch/arm/src/stm32l4/Kconfig
index 83dbffe78c..3ccbfff8af 100644
--- a/arch/arm/src/stm32l4/Kconfig
+++ b/arch/arm/src/stm32l4/Kconfig
@@ -721,8 +721,7 @@ if STM32L4_TIM1_CHANNEL1
config STM32L4_TIM1_CH1MODE
int "TIM1 Channel 1 Mode"
default 0
- range 0 5 if STM32L4_STM32F30XX
- range 0 1 if !STM32L4_STM32F30XX
+ range 0 5
---help---
Specifies the channel mode.
@@ -745,8 +744,7 @@ if STM32L4_TIM1_CHANNEL2
config STM32L4_TIM1_CH2MODE
int "TIM1 Channel 2 Mode"
default 0
- range 0 5 if STM32L4_STM32F30XX
- range 0 1 if !STM32L4_STM32F30XX
+ range 0 5
---help---
Specifies the channel mode.
@@ -769,8 +767,7 @@ if STM32L4_TIM1_CHANNEL3
config STM32L4_TIM1_CH3MODE
int "TIM1 Channel 3 Mode"
default 0
- range 0 5 if STM32L4_STM32F30XX
- range 0 1 if !STM32L4_STM32F30XX
+ range 0 5
---help---
Specifies the channel mode.
@@ -793,8 +790,7 @@ if STM32L4_TIM1_CHANNEL4
config STM32L4_TIM1_CH4MODE
int "TIM1 Channel 4 Mode"
default 0
- range 0 5 if STM32L4_STM32F30XX
- range 0 1 if !STM32L4_STM32F30XX
+ range 0 5
---help---
Specifies the channel mode.
@@ -821,8 +817,7 @@ config STM32L4_TIM1_CHANNEL
config STM32L4_TIM1_CHMODE
int "TIM1 Channel Mode"
default 0
- range 0 5 if STM32L4_STM32F30XX
- range 0 1 if !STM32L4_STM32F30XX
+ range 0 5
---help---
Specifies the channel mode.
@@ -865,8 +860,7 @@ if STM32L4_TIM2_CHANNEL1
config STM32L4_TIM2_CH1MODE
int "TIM2 Channel 1 Mode"
default 0
- range 0 5 if STM32L4_STM32F30XX
- range 0 1 if !STM32L4_STM32F30XX
+ range 0 5
---help---
Specifies the channel mode.
@@ -889,8 +883,7 @@ if STM32L4_TIM2_CHANNEL2
config STM32L4_TIM2_CH2MODE
int "TIM2 Channel 2 Mode"
default 0
- range 0 5 if STM32L4_STM32F30XX
- range 0 1 if !STM32L4_STM32F30XX
+ range 0 5
---help---
Specifies the channel mode.
@@ -913,8 +906,7 @@ if STM32L4_TIM2_CHANNEL3
config STM32L4_TIM2_CH3MODE
int "TIM2 Channel 3 Mode"
default 0
- range 0 5 if STM32L4_STM32F30XX
- range 0 1 if !STM32L4_STM32F30XX
+ range 0 5
---help---
Specifies the channel mode.
@@ -937,8 +929,7 @@ if STM32L4_TIM2_CHANNEL4
config STM32L4_TIM2_CH4MODE
int "TIM2 Channel 4 Mode"
default 0
- range 0 5 if STM32L4_STM32F30XX
- range 0 1 if !STM32L4_STM32F30XX
+ range 0 5
---help---
Specifies the channel mode.
@@ -965,8 +956,7 @@ config STM32L4_TIM2_CHANNEL
config STM32L4_TIM2_CHMODE
int "TIM2 Channel Mode"
default 0
- range 0 5 if STM32L4_STM32F30XX
- range 0 1 if !STM32L4_STM32F30XX
+ range 0 5
---help---
Specifies the channel mode.
@@ -1009,8 +999,7 @@ if STM32L4_TIM3_CHANNEL1
config STM32L4_TIM3_CH1MODE
int "TIM3 Channel 1 Mode"
default 0
- range 0 5 if STM32L4_STM32F30XX
- range 0 1 if !STM32L4_STM32F30XX
+ range 0 5
---help---
Specifies the channel mode.
@@ -1033,8 +1022,7 @@ if STM32L4_TIM3_CHANNEL2
config STM32L4_TIM3_CH2MODE
int "TIM3 Channel 2 Mode"
default 0
- range 0 5 if STM32L4_STM32F30XX
- range 0 1 if !STM32L4_STM32F30XX
+ range 0 5
---help---
Specifies the channel mode.
@@ -1057,8 +1045,7 @@ if STM32L4_TIM3_CHANNEL3
config STM32L4_TIM3_CH3MODE
int "TIM3 Channel 3 Mode"
default 0
- range 0 5 if STM32L4_STM32F30XX
- range 0 1 if !STM32L4_STM32F30XX
+ range 0 5
---help---
Specifies the channel mode.
@@ -1081,8 +1068,7 @@ if STM32L4_TIM3_CHANNEL4
config STM32L4_TIM3_CH4MODE
int "TIM3 Channel 4 Mode"
default 0
- range 0 5 if STM32L4_STM32F30XX
- range 0 1 if !STM32L4_STM32F30XX
+ range 0 5
---help---
Specifies the channel mode.
@@ -1109,8 +1095,7 @@ config STM32L4_TIM3_CHANNEL
config STM32L4_TIM3_CHMODE
int "TIM3 Channel Mode"
default 0
- range 0 5 if STM32L4_STM32F30XX
- range 0 1 if !STM32L4_STM32F30XX
+ range 0 5
---help---
Specifies the channel mode.
@@ -1153,8 +1138,7 @@ if STM32L4_TIM4_CHANNEL1
config STM32L4_TIM4_CH1MODE
int "TIM4 Channel 1 Mode"
default 0
- range 0 5 if STM32L4_STM32F30XX
- range 0 1 if !STM32L4_STM32F30XX
+ range 0 5
---help---
Specifies the channel mode.
@@ -1177,8 +1161,7 @@ if STM32L4_TIM4_CHANNEL2
config STM32L4_TIM4_CH2MODE
int "TIM4 Channel 2 Mode"
default 0
- range 0 5 if STM32L4_STM32F30XX
- range 0 1 if !STM32L4_STM32F30XX
+ range 0 5
---help---
Specifies the channel mode.
@@ -1201,8 +1184,7 @@ if STM32L4_TIM4_CHANNEL3
config STM32L4_TIM4_CH3MODE
int "TIM4 Channel 3 Mode"
default 0
- range 0 5 if STM32L4_STM32F30XX
- range 0 1 if !STM32L4_STM32F30XX
+ range 0 5
---help---
Specifies the channel mode.
@@ -1225,8 +1207,7 @@ if STM32L4_TIM4_CHANNEL4
config STM32L4_TIM4_CH4MODE
int "TIM4 Channel 4 Mode"
default 0
- range 0 5 if STM32L4_STM32F30XX
- range 0 1 if !STM32L4_STM32F30XX
+ range 0 5
---help---
Specifies the channel mode.
@@ -1253,8 +1234,7 @@ config STM32L4_TIM4_CHANNEL
config STM32L4_TIM4_CHMODE
int "TIM4 Channel Mode"
default 0
- range 0 5 if STM32L4_STM32F30XX
- range 0 1 if !STM32L4_STM32F30XX
+ range 0 5
---help---
Specifies the channel mode.
@@ -1297,8 +1277,7 @@ if STM32L4_TIM5_CHANNEL1
config STM32L4_TIM5_CH1MODE
int "TIM5 Channel 1 Mode"
default 0
- range 0 5 if STM32L4_STM32F30XX
- range 0 1 if !STM32L4_STM32F30XX
+ range 0 5
---help---
Specifies the channel mode.
@@ -1321,8 +1300,7 @@ if STM32L4_TIM5_CHANNEL2
config STM32L4_TIM5_CH2MODE
int "TIM5 Channel 2 Mode"
default 0
- range 0 5 if STM32L4_STM32F30XX
- range 0 1 if !STM32L4_STM32F30XX
+ range 0 5
---help---
Specifies the channel mode.
@@ -1345,8 +1323,7 @@ if STM32L4_TIM5_CHANNEL3
config STM32L4_TIM5_CH3MODE
int "TIM5 Channel 3 Mode"
default 0
- range 0 5 if STM32L4_STM32F30XX
- range 0 1 if !STM32L4_STM32F30XX
+ range 0 5
---help---
Specifies the channel mode.
@@ -1369,8 +1346,7 @@ if STM32L4_TIM5_CHANNEL4
config STM32L4_TIM5_CH4MODE
int "TIM5 Channel 4 Mode"
default 0
- range 0 5 if STM32L4_STM32F30XX
- range 0 1 if !STM32L4_STM32F30XX
+ range 0 5
---help---
Specifies the channel mode.
@@ -1397,8 +1373,7 @@ config STM32L4_TIM5_CHANNEL
config STM32L4_TIM5_CHMODE
int "TIM5 Channel Mode"
default 0
- range 0 5 if STM32L4_STM32F30XX
- range 0 1 if !STM32L4_STM32F30XX
+ range 0 5
---help---
Specifies the channel mode.
@@ -1441,8 +1416,7 @@ if STM32L4_TIM8_CHANNEL1
config STM32L4_TIM8_CH1MODE
int "TIM8 Channel 1 Mode"
default 0
- range 0 5 if STM32L4_STM32F30XX
- range 0 1 if !STM32L4_STM32F30XX
+ range 0 5
---help---
Specifies the channel mode.
@@ -1465,8 +1439,7 @@ if STM32L4_TIM8_CHANNEL2
config STM32L4_TIM8_CH2MODE
int "TIM8 Channel 2 Mode"
default 0
- range 0 5 if STM32L4_STM32F30XX
- range 0 1 if !STM32L4_STM32F30XX
+ range 0 5
---help---
Specifies the channel mode.
@@ -1489,8 +1462,7 @@ if STM32L4_TIM8_CHANNEL3
config STM32L4_TIM8_CH3MODE
int "TIM8 Channel 3 Mode"
default 0
- range 0 5 if STM32L4_STM32F30XX
- range 0 1 if !STM32L4_STM32F30XX
+ range 0 5
---help---
Specifies the channel mode.
@@ -1513,8 +1485,7 @@ if STM32L4_TIM8_CHANNEL4
config STM32L4_TIM8_CH4MODE
int "TIM8 Channel 4 Mode"
default 0
- range 0 5 if STM32L4_STM32F30XX
- range 0 1 if !STM32L4_STM32F30XX
+ range 0 5
---help---
Specifies the channel mode.
@@ -1541,8 +1512,7 @@ config STM32L4_TIM8_CHANNEL
config STM32L4_TIM8_CHMODE
int "TIM8 Channel Mode"
default 0
- range 0 5 if STM32L4_STM32F30XX
- range 0 1 if !STM32L4_STM32F30XX
+ range 0 5
---help---
Specifies the channel mode.
@@ -1577,8 +1547,7 @@ if STM32L4_TIM15_CHANNEL1
config STM32L4_TIM15_CH1MODE
int "TIM15 Channel 1 Mode"
default 0
- range 0 3 if STM32L4_STM32F30XX
- range 0 1 if !STM32L4_STM32F30XX
+ range 0 3
---help---
Specifies the channel mode.
@@ -1601,8 +1570,7 @@ if STM32L4_TIM15_CHANNEL2
config STM32L4_TIM15_CH2MODE
int "TIM15 Channel 2 Mode"
default 0
- range 0 3 if STM32L4_STM32F30XX
- range 0 1 if !STM32L4_STM32F30XX
+ range 0 3
---help---
Specifies the channel mode.
@@ -1629,8 +1597,7 @@ config STM32L4_TIM15_CHANNEL
config STM32L4_TIM15_CHMODE
int "TIM15 Channel Mode"
default 0
- range 0 3 if STM32L4_STM32F30XX
- range 0 1 if !STM32L4_STM32F30XX
+ range 0 3
---help---
Specifies the channel mode.
--
GitLab
From 9dcecd4b152c2575fd21a9f5b2a0f1c8aeb6ee88 Mon Sep 17 00:00:00 2001
From: Sebastien Lorquet
Date: Mon, 3 Oct 2016 16:07:20 +0200
Subject: [PATCH 024/734] Add support for qencoders on various nucleo boards
---
arch/arm/src/stm32/stm32_qencoder.c | 2 +
arch/arm/src/stm32l4/stm32l4_qencoder.c | 53 +++----
configs/nucleo-f4x1re/include/board.h | 3 +
configs/nucleo-f4x1re/src/Makefile | 4 +
configs/nucleo-f4x1re/src/stm32_qencoder.c | 158 ++++++++++++++++++++
configs/nucleo-l476rg/include/board.h | 10 ++
configs/nucleo-l476rg/src/Makefile | 4 +
configs/nucleo-l476rg/src/stm32_qencoder.c | 161 +++++++++++++++++++++
8 files changed, 370 insertions(+), 25 deletions(-)
create mode 100644 configs/nucleo-f4x1re/src/stm32_qencoder.c
create mode 100644 configs/nucleo-l476rg/src/stm32_qencoder.c
diff --git a/arch/arm/src/stm32/stm32_qencoder.c b/arch/arm/src/stm32/stm32_qencoder.c
index 7d87debe33..69b0f9b2e0 100644
--- a/arch/arm/src/stm32/stm32_qencoder.c
+++ b/arch/arm/src/stm32/stm32_qencoder.c
@@ -1029,6 +1029,8 @@ static int stm32_setup(FAR struct qe_lowerhalf_s *lower)
cr1 |= GTIM_CR1_CEN;
stm32_putreg16(priv, STM32_GTIM_CR1_OFFSET, cr1);
+ stm32_dumpregs(priv, "After setup");
+
return OK;
}
diff --git a/arch/arm/src/stm32l4/stm32l4_qencoder.c b/arch/arm/src/stm32l4/stm32l4_qencoder.c
index 7c9426de29..19436b2e18 100644
--- a/arch/arm/src/stm32l4/stm32l4_qencoder.c
+++ b/arch/arm/src/stm32l4/stm32l4_qencoder.c
@@ -579,26 +579,27 @@ static void stm32l4_dumpregs(FAR struct stm32l4_lowerhalf_s *priv,
FAR const char *msg)
{
sninfo("%s:\n", msg);
- sninfo(" CR1: %04x CR2: %04x SMCR: %04x DIER: %04x\n",
+ sninfo(" CR1: %04x CR2: %04x SMCR: %08x DIER: %04x\n",
stm32l4_getreg16(priv, STM32L4_GTIM_CR1_OFFSET),
stm32l4_getreg16(priv, STM32L4_GTIM_CR2_OFFSET),
- stm32l4_getreg16(priv, STM32L4_GTIM_SMCR_OFFSET),
+ stm32l4_getreg32(priv, STM32L4_GTIM_SMCR_OFFSET),
stm32l4_getreg16(priv, STM32L4_GTIM_DIER_OFFSET));
- sninfo(" SR: %04x EGR: %04x CCMR1: %04x CCMR2: %04x\n",
+ sninfo(" SR: %04x EGR: %04x CCMR1: %08x CCMR2: %08x\n",
stm32l4_getreg16(priv, STM32L4_GTIM_SR_OFFSET),
stm32l4_getreg16(priv, STM32L4_GTIM_EGR_OFFSET),
- stm32l4_getreg16(priv, STM32L4_GTIM_CCMR1_OFFSET),
- stm32l4_getreg16(priv, STM32L4_GTIM_CCMR2_OFFSET));
- sninfo(" CCER: %04x CNT: %04x PSC: %04x ARR: %04x\n",
+ stm32l4_getreg32(priv, STM32L4_GTIM_CCMR1_OFFSET),
+ stm32l4_getreg32(priv, STM32L4_GTIM_CCMR2_OFFSET));
+ sninfo(" CCER: %04x CNT: %08x PSC: %04x ARR: %08x\n",
stm32l4_getreg16(priv, STM32L4_GTIM_CCER_OFFSET),
- stm32l4_getreg16(priv, STM32L4_GTIM_CNT_OFFSET),
+ stm32l4_getreg32(priv, STM32L4_GTIM_CNT_OFFSET),
stm32l4_getreg16(priv, STM32L4_GTIM_PSC_OFFSET),
- stm32l4_getreg16(priv, STM32L4_GTIM_ARR_OFFSET));
- sninfo(" CCR1: %04x CCR2: %04x CCR3: %04x CCR4: %04x\n",
- stm32l4_getreg16(priv, STM32L4_GTIM_CCR1_OFFSET),
- stm32l4_getreg16(priv, STM32L4_GTIM_CCR2_OFFSET),
- stm32l4_getreg16(priv, STM32L4_GTIM_CCR3_OFFSET),
- stm32l4_getreg16(priv, STM32L4_GTIM_CCR4_OFFSET));
+ stm32l4_getreg32(priv, STM32L4_GTIM_ARR_OFFSET));
+ sninfo(" CCR1: %08x CCR2: %08x\n",
+ stm32l4_getreg32(priv, STM32L4_GTIM_CCR1_OFFSET),
+ stm32l4_getreg32(priv, STM32L4_GTIM_CCR2_OFFSET));
+ sninfo(" CCR3: %08x CCR4: %08x\n",
+ stm32l4_getreg32(priv, STM32L4_GTIM_CCR3_OFFSET),
+ stm32l4_getreg32(priv, STM32L4_GTIM_CCR4_OFFSET));
#if defined(CONFIG_STM32L4_TIM1_QE) || defined(CONFIG_STM32L4_TIM8_QE)
if (priv->config->timid == 1 || priv->config->timid == 8)
{
@@ -764,8 +765,8 @@ static int stm32l4_setup(FAR struct qe_lowerhalf_s *lower)
{
FAR struct stm32l4_lowerhalf_s *priv = (FAR struct stm32l4_lowerhalf_s *)lower;
uint16_t dier;
- uint16_t smcr;
- uint16_t ccmr1;
+ uint32_t smcr;
+ uint32_t ccmr1;
uint16_t ccer;
uint16_t cr1;
#ifdef HAVE_16BIT_TIMERS
@@ -833,10 +834,10 @@ static int stm32l4_setup(FAR struct qe_lowerhalf_s *lower)
/* Set the encoder Mode 3 */
- smcr = stm32l4_getreg16(priv, STM32L4_GTIM_SMCR_OFFSET);
+ smcr = stm32l4_getreg32(priv, STM32L4_GTIM_SMCR_OFFSET);
smcr &= ~GTIM_SMCR_SMS_MASK;
smcr |= GTIM_SMCR_ENCMD3;
- stm32l4_putreg16(priv, STM32L4_GTIM_SMCR_OFFSET, smcr);
+ stm32l4_putreg32(priv, STM32L4_GTIM_SMCR_OFFSET, smcr);
/* TI1 Channel Configuration */
/* Disable the Channel 1: Reset the CC1E Bit */
@@ -845,7 +846,7 @@ static int stm32l4_setup(FAR struct qe_lowerhalf_s *lower)
ccer &= ~GTIM_CCER_CC1E;
stm32l4_putreg16(priv, STM32L4_GTIM_CCER_OFFSET, ccer);
- ccmr1 = stm32l4_getreg16(priv, STM32L4_GTIM_CCMR1_OFFSET);
+ ccmr1 = stm32l4_getreg32(priv, STM32L4_GTIM_CCMR1_OFFSET);
ccer = stm32l4_getreg16(priv, STM32L4_GTIM_CCER_OFFSET);
/* Select the Input IC1=TI1 and set the filter fSAMPLING=fDTS/4, N=6 */
@@ -861,17 +862,17 @@ static int stm32l4_setup(FAR struct qe_lowerhalf_s *lower)
/* Write to TIM CCMR1 and CCER registers */
- stm32l4_putreg16(priv, STM32L4_GTIM_CCMR1_OFFSET, ccmr1);
+ stm32l4_putreg32(priv, STM32L4_GTIM_CCMR1_OFFSET, ccmr1);
stm32l4_putreg16(priv, STM32L4_GTIM_CCER_OFFSET, ccer);
/* Set the Input Capture Prescaler value: Capture performed each time an
* edge is detected on the capture input.
*/
- ccmr1 = stm32l4_getreg16(priv, STM32L4_GTIM_CCMR1_OFFSET);
+ ccmr1 = stm32l4_getreg32(priv, STM32L4_GTIM_CCMR1_OFFSET);
ccmr1 &= ~GTIM_CCMR1_IC1PSC_MASK;
ccmr1 |= (GTIM_CCMR_ICPSC_NOPSC << GTIM_CCMR1_IC1PSC_SHIFT);
- stm32l4_putreg16(priv, STM32L4_GTIM_CCMR1_OFFSET, ccmr1);
+ stm32l4_putreg32(priv, STM32L4_GTIM_CCMR1_OFFSET, ccmr1);
/* TI2 Channel Configuration */
/* Disable the Channel 2: Reset the CC2E Bit */
@@ -880,7 +881,7 @@ static int stm32l4_setup(FAR struct qe_lowerhalf_s *lower)
ccer &= ~GTIM_CCER_CC2E;
stm32l4_putreg16(priv, STM32L4_GTIM_CCER_OFFSET, ccer);
- ccmr1 = stm32l4_getreg16(priv, STM32L4_GTIM_CCMR1_OFFSET);
+ ccmr1 = stm32l4_getreg32(priv, STM32L4_GTIM_CCMR1_OFFSET);
ccer = stm32l4_getreg16(priv, STM32L4_GTIM_CCER_OFFSET);
/* Select the Input IC2=TI2 and set the filter fSAMPLING=fDTS/4, N=6 */
@@ -896,17 +897,17 @@ static int stm32l4_setup(FAR struct qe_lowerhalf_s *lower)
/* Write to TIM CCMR1 and CCER registers */
- stm32l4_putreg16(priv, STM32L4_GTIM_CCMR1_OFFSET, ccmr1);
+ stm32l4_putreg32(priv, STM32L4_GTIM_CCMR1_OFFSET, ccmr1);
stm32l4_putreg16(priv, STM32L4_GTIM_CCER_OFFSET, ccer);
/* Set the Input Capture Prescaler value: Capture performed each time an
* edge is detected on the capture input.
*/
- ccmr1 = stm32l4_getreg16(priv, STM32L4_GTIM_CCMR1_OFFSET);
+ ccmr1 = stm32l4_getreg32(priv, STM32L4_GTIM_CCMR1_OFFSET);
ccmr1 &= ~GTIM_CCMR1_IC2PSC_MASK;
ccmr1 |= (GTIM_CCMR_ICPSC_NOPSC << GTIM_CCMR1_IC2PSC_SHIFT);
- stm32l4_putreg16(priv, STM32L4_GTIM_CCMR1_OFFSET, ccmr1);
+ stm32l4_putreg32(priv, STM32L4_GTIM_CCMR1_OFFSET, ccmr1);
/* Disable the update interrupt */
@@ -973,6 +974,8 @@ static int stm32l4_setup(FAR struct qe_lowerhalf_s *lower)
cr1 |= GTIM_CR1_CEN;
stm32l4_putreg16(priv, STM32L4_GTIM_CR1_OFFSET, cr1);
+ stm32l4_dumpregs(priv, "After setup");
+
return OK;
}
diff --git a/configs/nucleo-f4x1re/include/board.h b/configs/nucleo-f4x1re/include/board.h
index 8580b8045a..888e79c9a5 100644
--- a/configs/nucleo-f4x1re/include/board.h
+++ b/configs/nucleo-f4x1re/include/board.h
@@ -216,6 +216,9 @@
#define BUTTON_USER_BIT (1 << BUTTON_USER)
+#define GPIO_TIM2_CH1IN (GPIO_TIM2_CH1IN_1 | GPIO_PULLUP)
+#define GPIO_TIM2_CH2IN (GPIO_TIM2_CH2IN_1 | GPIO_PULLUP)
+
/************************************************************************************
* Public Data
************************************************************************************/
diff --git a/configs/nucleo-f4x1re/src/Makefile b/configs/nucleo-f4x1re/src/Makefile
index c5d250f03d..7778dd7f00 100644
--- a/configs/nucleo-f4x1re/src/Makefile
+++ b/configs/nucleo-f4x1re/src/Makefile
@@ -62,6 +62,10 @@ CSRCS += stm32_ajoystick.c
endif
endif
+ifeq ($(CONFIG_QENCODER),y)
+CSRCS += stm32_qencoder.c
+endif
+
ifeq ($(CONFIG_NSH_LIBRARY),y)
CSRCS += stm32_appinit.c
endif
diff --git a/configs/nucleo-f4x1re/src/stm32_qencoder.c b/configs/nucleo-f4x1re/src/stm32_qencoder.c
new file mode 100644
index 0000000000..6d72932844
--- /dev/null
+++ b/configs/nucleo-f4x1re/src/stm32_qencoder.c
@@ -0,0 +1,158 @@
+/************************************************************************************
+ * configs/stm32f4discovery/src/stm32_qencoder.c
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * 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
+
+#include
+#include
+
+#include
+#include
+
+#include "chip.h"
+#include "up_arch.h"
+#include "stm32_qencoder.h"
+#include "nucleo-f4x1re.h"
+
+/************************************************************************************
+ * Pre-processor Definitions
+ ************************************************************************************/
+/* Configuration *******************************************************************/
+/* Check if we have a timer configured for quadrature encoder -- assume YES. */
+
+#define HAVE_QENCODER 1
+
+/* If TIMn is not enabled (via CONFIG_STM32_TIMn), then the configuration cannot
+ * specify TIMn as a quadrature encoder (via CONFIG_STM32_TIMn_QE).
+ */
+
+#ifndef CONFIG_STM32_TIM1
+# undef CONFIG_STM32_TIM1_QE
+#endif
+#ifndef CONFIG_STM32_TIM2
+# undef CONFIG_STM32_TIM2_QE
+#endif
+#ifndef CONFIG_STM32_TIM3
+# undef CONFIG_STM32_TIM3_QE
+#endif
+#ifndef CONFIG_STM32_TIM4
+# undef CONFIG_STM32_TIM4_QE
+#endif
+#ifndef CONFIG_STM32_TIM5
+# undef CONFIG_STM32_TIM5_QE
+#endif
+#ifndef CONFIG_STM32_TIM8
+# undef CONFIG_STM32_TIM8_QE
+#endif
+
+/* If the upper-half quadrature encoder driver is not enabled, then we cannot
+ * support the quadrature encoder.
+ */
+
+#ifndef CONFIG_QENCODER
+# undef HAVE_QENCODER
+#endif
+
+/* Which Timer should we use, TIMID={1,2,3,4,5,8}. If multiple timers are
+ * configured as quadrature encoders, this logic will arbitrarily select
+ * the lowest numbered timer.
+ *
+ * At least one TIMn, n={1,2,3,4,5,8}, must be both enabled and configured
+ * as a quadrature encoder in order to support the lower half quadrature
+ * encoder driver. The above check assures that if CONFIG_STM32_TIMn_QE
+ * is defined, then the correspdonding TIMn is also enabled.
+ */
+
+#if defined CONFIG_STM32_TIM1_QE
+# define TIMID 1
+#elif defined CONFIG_STM32_TIM2_QE
+# define TIMID 2
+#elif defined CONFIG_STM32_TIM3_QE
+# define TIMID 3
+#elif defined CONFIG_STM32_TIM4_QE
+# define TIMID 4
+#elif defined CONFIG_STM32_TIM5_QE
+# define TIMID 5
+#elif defined CONFIG_STM32_TIM8_QE
+# define TIMID 8
+#else
+# undef HAVE_QENCODER
+#endif
+
+#ifdef HAVE_QENCODER
+
+/************************************************************************************
+ * Public Functions
+ ************************************************************************************/
+
+/************************************************************************************
+ * Name: qe_devinit
+ *
+ * Description:
+ * All STM32 architectures must provide the following interface to work with
+ * examples/qencoder.
+ *
+ ************************************************************************************/
+
+int qe_devinit(void)
+{
+ static bool initialized = false;
+ int ret;
+
+ /* Check if we are already initialized */
+
+ if (!initialized)
+ {
+ /* Initialize a quadrature encoder interface. */
+
+ sninfo("Initializing the quadrature encoder using TIM%d\n", TIMID);
+ ret = stm32_qeinitialize("/dev/qe0", TIMID);
+ if (ret < 0)
+ {
+ snerr("ERROR: stm32_qeinitialize failed: %d\n", ret);
+ return ret;
+ }
+
+ initialized = true;
+ }
+
+ return OK;
+}
+
+#endif /* HAVE_QENCODER */
diff --git a/configs/nucleo-l476rg/include/board.h b/configs/nucleo-l476rg/include/board.h
index f9ca1ada74..a7a983221d 100644
--- a/configs/nucleo-l476rg/include/board.h
+++ b/configs/nucleo-l476rg/include/board.h
@@ -202,6 +202,16 @@
#define BUTTON_USER_BIT (1 << BUTTON_USER)
+/* Quadrature encoder
+ * Default is to use timer 5 (32-bit) and encoder on PA0/PA1
+ */
+
+#define GPIO_TIM5_CH1IN GPIO_TIM5_CH1IN_1
+#define GPIO_TIM5_CH2IN GPIO_TIM5_CH2IN_1
+
+#define GPIO_TIM2_CH1IN GPIO_TIM2_CH1IN_1
+#define GPIO_TIM2_CH2IN GPIO_TIM2_CH2IN_1
+
/************************************************************************************
* Public Data
************************************************************************************/
diff --git a/configs/nucleo-l476rg/src/Makefile b/configs/nucleo-l476rg/src/Makefile
index 46faa0d565..771a34ffd6 100644
--- a/configs/nucleo-l476rg/src/Makefile
+++ b/configs/nucleo-l476rg/src/Makefile
@@ -62,6 +62,10 @@ CSRCS += stm32_ajoystick.c
endif
endif
+ifeq ($(CONFIG_QENCODER),y)
+CSRCS += stm32_qencoder.c
+endif
+
ifeq ($(CONFIG_LIB_BOARDCTL),y)
CSRCS += stm32_appinit.c
endif
diff --git a/configs/nucleo-l476rg/src/stm32_qencoder.c b/configs/nucleo-l476rg/src/stm32_qencoder.c
new file mode 100644
index 0000000000..308b674477
--- /dev/null
+++ b/configs/nucleo-l476rg/src/stm32_qencoder.c
@@ -0,0 +1,161 @@
+/************************************************************************************
+ * configs/nucleo-l476rg/src/stm32_qencoder.c
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * Copyright (C) 2016 Sebastien Lorquet. All rights reserved.
+ * Author: Sebastien Lorquet
+ *
+ * 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
+
+#include
+#include
+
+#include
+#include
+
+#include "chip.h"
+#include "up_arch.h"
+#include "stm32l4_qencoder.h"
+#include "nucleo-l476rg.h"
+
+/************************************************************************************
+ * Pre-processor Definitions
+ ************************************************************************************/
+/* Configuration *******************************************************************/
+/* Check if we have a timer configured for quadrature encoder -- assume YES. */
+
+#define HAVE_QENCODER 1
+
+/* If TIMn is not enabled (via CONFIG_STM32L4_TIMn), then the configuration cannot
+ * specify TIMn as a quadrature encoder (via CONFIG_STM32L4_TIMn_QE).
+ */
+
+#ifndef CONFIG_STM32L4_TIM1
+# undef CONFIG_STM32L4_TIM1_QE
+#endif
+#ifndef CONFIG_STM32L4_TIM2
+# undef CONFIG_STM32L4_TIM2_QE
+#endif
+#ifndef CONFIG_STM32L4_TIM3
+# undef CONFIG_STM32L4_TIM3_QE
+#endif
+#ifndef CONFIG_STM32L4_TIM4
+# undef CONFIG_STM32L4_TIM4_QE
+#endif
+#ifndef CONFIG_STM32L4_TIM5
+# undef CONFIG_STM32L4_TIM5_QE
+#endif
+#ifndef CONFIG_STM32L4_TIM8
+# undef CONFIG_STM32L4_TIM8_QE
+#endif
+
+/* If the upper-half quadrature encoder driver is not enabled, then we cannot
+ * support the quadrature encoder.
+ */
+
+#ifndef CONFIG_QENCODER
+# undef HAVE_QENCODER
+#endif
+
+/* Which Timer should we use, TIMID={1,2,3,4,5,8}. If multiple timers are
+ * configured as quadrature encoders, this logic will arbitrarily select
+ * the lowest numbered timer.
+ *
+ * At least one TIMn, n={1,2,3,4,5,8}, must be both enabled and configured
+ * as a quadrature encoder in order to support the lower half quadrature
+ * encoder driver. The above check assures that if CONFIG_STM32L4_TIMn_QE
+ * is defined, then the correspdonding TIMn is also enabled.
+ */
+
+#if defined CONFIG_STM32L4_TIM1_QE
+# define TIMID 1
+#elif defined CONFIG_STM32L4_TIM2_QE
+# define TIMID 2
+#elif defined CONFIG_STM32L4_TIM3_QE
+# define TIMID 3
+#elif defined CONFIG_STM32L4_TIM4_QE
+# define TIMID 4
+#elif defined CONFIG_STM32L4_TIM5_QE
+# define TIMID 5
+#elif defined CONFIG_STM32L4_TIM8_QE
+# define TIMID 8
+#else
+# undef HAVE_QENCODER
+#endif
+
+#ifdef HAVE_QENCODER
+
+/************************************************************************************
+ * Public Functions
+ ************************************************************************************/
+
+/************************************************************************************
+ * Name: qe_devinit
+ *
+ * Description:
+ * All STM32L4 architectures must provide the following interface to work with
+ * examples/qencoder.
+ *
+ ************************************************************************************/
+
+int qe_devinit(void)
+{
+ static bool initialized = false;
+ int ret;
+
+ /* Check if we are already initialized */
+
+ if (!initialized)
+ {
+ /* Initialize a quadrature encoder interface. */
+
+ sninfo("Initializing the quadrature encoder using TIM%d\n", TIMID);
+ ret = stm32l4_qeinitialize("/dev/qe0", TIMID);
+ if (ret < 0)
+ {
+ snerr("ERROR: stm32_qeinitialize failed: %d\n", ret);
+ return ret;
+ }
+
+ initialized = true;
+ }
+
+ return OK;
+}
+
+#endif /* HAVE_QENCODER */
--
GitLab
From e54a0cd3d0828add29a990323c036554296dc91f Mon Sep 17 00:00:00 2001
From: David Sidrane
Date: Thu, 29 Sep 2016 15:01:59 -1000
Subject: [PATCH 025/734] Header cleanup
---
arch/arm/src/stm32l4/chip/stm32l4x6xx_otgfs.h | 238 +-----------------
1 file changed, 7 insertions(+), 231 deletions(-)
diff --git a/arch/arm/src/stm32l4/chip/stm32l4x6xx_otgfs.h b/arch/arm/src/stm32l4/chip/stm32l4x6xx_otgfs.h
index 39065c0570..49874d7233 100644
--- a/arch/arm/src/stm32l4/chip/stm32l4x6xx_otgfs.h
+++ b/arch/arm/src/stm32l4/chip/stm32l4x6xx_otgfs.h
@@ -82,11 +82,6 @@
#define STM32L4_OTGFS_HPTXFSIZ_OFFSET 0x0100 /* Host periodic transmit FIFO size register */
#define STM32L4_OTGFS_DIEPTXF_OFFSET(n) (104+(((n)-1) << 2))
-#define STM32L4_OTGFS_DIEPTXF1_OFFSET 0x0104 /* Device IN endpoint transmit FIFO1 size register */
-#define STM32L4_OTGFS_DIEPTXF2_OFFSET 0x0108 /* Device IN endpoint transmit FIFO2 size register */
-#define STM32L4_OTGFS_DIEPTXF3_OFFSET 0x010c /* Device IN endpoint transmit FIFO3 size register */
-#define STM32L4_OTGFS_DIEPTXF4_OFFSET 0x0110 /* Device IN endpoint transmit FIFO4 size register */
-#define STM32L4_OTGFS_DIEPTXF5_OFFSET 0x0114 /* Device IN endpoint transmit FIFO5 size register */
/* Host-mode control and status registers */
@@ -105,60 +100,12 @@
#define STM32L4_OTGFS_HCTSIZ_CHOFFSET 0x0010 /* Host channel interrupt register */
#define STM32L4_OTGFS_HCCHAR_OFFSET(n) (0x500 + ((n) << 5))
-#define STM32L4_OTGFS_HCCHAR0_OFFSET 0x0500 /* Host channel-0 characteristics register */
-#define STM32L4_OTGFS_HCCHAR1_OFFSET 0x0520 /* Host channel-1 characteristics register */
-#define STM32L4_OTGFS_HCCHAR2_OFFSET 0x0540 /* Host channel-2 characteristics register */
-#define STM32L4_OTGFS_HCCHAR3_OFFSET 0x0560 /* Host channel-3 characteristics register */
-#define STM32L4_OTGFS_HCCHAR4_OFFSET 0x0580 /* Host channel-4 characteristics register */
-#define STM32L4_OTGFS_HCCHAR5_OFFSET 0x05a0 /* Host channel-5 characteristics register */
-#define STM32L4_OTGFS_HCCHAR6_OFFSET 0x05c0 /* Host channel-6 characteristics register */
-#define STM32L4_OTGFS_HCCHAR7_OFFSET 0x05e0 /* Host channel-7 characteristics register */
-#define STM32L4_OTGFS_HCCHAR8_OFFSET 0x0600 /* Host channel-8 characteristics register */
-#define STM32L4_OTGFS_HCCHAR9_OFFSET 0x0620 /* Host channel-9 characteristics register */
-#define STM32L4_OTGFS_HCCHAR10_OFFSET 0x0640 /* Host channel-10 characteristics register */
-#define STM32L4_OTGFS_HCCHAR11_OFFSET 0x0660 /* Host channel-11 characteristics register */
#define STM32L4_OTGFS_HCINT_OFFSET(n) (0x508 + ((n) << 5))
-#define STM32L4_OTGFS_HCINT0_OFFSET 0x0508 /* Host channel-0 interrupt register */
-#define STM32L4_OTGFS_HCINT1_OFFSET 0x0528 /* Host channel-1 interrupt register */
-#define STM32L4_OTGFS_HCINT2_OFFSET 0x0548 /* Host channel-2 interrupt register */
-#define STM32L4_OTGFS_HCINT3_OFFSET 0x0568 /* Host channel-3 interrupt register */
-#define STM32L4_OTGFS_HCINT4_OFFSET 0x0588 /* Host channel-4 interrupt register */
-#define STM32L4_OTGFS_HCINT5_OFFSET 0x05a8 /* Host channel-5 interrupt register */
-#define STM32L4_OTGFS_HCINT6_OFFSET 0x05c8 /* Host channel-6 interrupt register */
-#define STM32L4_OTGFS_HCINT7_OFFSET 0x05e8 /* Host channel-7 interrupt register */
-#define STM32L4_OTGFS_HCINT8_OFFSET 0x0608 /* Host channel-8 interrupt register */
-#define STM32L4_OTGFS_HCINT9_OFFSET 0x0628 /* Host channel-9 interrupt register */
-#define STM32L4_OTGFS_HCINT10_OFFSET 0x0648 /* Host channel-10 interrupt register */
-#define STM32L4_OTGFS_HCINT11_OFFSET 0x0668 /* Host channel-11 interrupt register */
#define STM32L4_OTGFS_HCINTMSK_OFFSET(n) (0x50c + ((n) << 5))
-#define STM32L4_OTGFS_HCINTMSK0_OFFSET 0x050c /* Host channel-0 interrupt mask register */
-#define STM32L4_OTGFS_HCINTMSK1_OFFSET 0x052c /* Host channel-1 interrupt mask register */
-#define STM32L4_OTGFS_HCINTMSK2_OFFSET 0x054c /* Host channel-2 interrupt mask register */
-#define STM32L4_OTGFS_HCINTMSK3_OFFSET 0x056c /* Host channel-3 interrupt mask register */
-#define STM32L4_OTGFS_HCINTMSK4_OFFSET 0x058c /* Host channel-4 interrupt mask register */
-#define STM32L4_OTGFS_HCINTMSK5_OFFSET 0x05ac /* Host channel-5 interrupt mask register */
-#define STM32L4_OTGFS_HCINTMSK6_OFFSET 0x05cc /* Host channel-6 interrupt mask register */
-#define STM32L4_OTGFS_HCINTMSK7_OFFSET 0x05ec /* Host channel-7 interrupt mask register */
-#define STM32L4_OTGFS_HCINTMSK8_OFFSET 0x060c /* Host channel-8 interrupt mask register */
-#define STM32L4_OTGFS_HCINTMSK9_OFFSET 0x062c /* Host channel-9 interrupt mask register */
-#define STM32L4_OTGFS_HCINTMSK10_OFFSET 0x064c /* Host channel-10 interrupt mask register */
-#define STM32L4_OTGFS_HCINTMSK11_OFFSET 0x066c /* Host channel-11 interrupt mask register */
#define STM32L4_OTGFS_HCTSIZ_OFFSET(n) (0x510 + ((n) << 5))
-#define STM32L4_OTGFS_HCTSIZ0_OFFSET 0x0510 /* Host channel-0 interrupt register */
-#define STM32L4_OTGFS_HCTSIZ1_OFFSET 0x0530 /* Host channel-1 interrupt register */
-#define STM32L4_OTGFS_HCTSIZ2_OFFSET 0x0550 /* Host channel-2 interrupt register */
-#define STM32L4_OTGFS_HCTSIZ3_OFFSET 0x0570 /* Host channel-3 interrupt register */
-#define STM32L4_OTGFS_HCTSIZ4_OFFSET 0x0590 /* Host channel-4 interrupt register */
-#define STM32L4_OTGFS_HCTSIZ5_OFFSET 0x05b0 /* Host channel-5 interrupt register */
-#define STM32L4_OTGFS_HCTSIZ6_OFFSET 0x05d0 /* Host channel-6 interrupt register */
-#define STM32L4_OTGFS_HCTSIZ7_OFFSET 0x05f0 /* Host channel-7 interrupt register */
-#define STM32L4_OTGFS_HCTSIZ8_OFFSET 0x0610 /* Host channel-8 interrupt register */
-#define STM32L4_OTGFS_HCTSIZ9_OFFSET 0x0630 /* Host channel-9 interrupt register */
-#define STM32L4_OTGFS_HCTSIZ10_OFFSET 0x0650 /* Host channel-10 interrupt register */
-#define STM32L4_OTGFS_HCTSIZ11_OFFSET 0x0670 /* Host channel-11 interrupt register */
/* Device-mode control and status registers */
@@ -180,36 +127,12 @@
#define STM32L4_OTGFS_DTXFSTS_EPOFFSET 0x0018 /* Device IN endpoint transmit FIFO status register */
#define STM32L4_OTGFS_DIEPCTL_OFFSET(n) (0x0900 + ((n) << 5))
-#define STM32L4_OTGFS_DIEPCTL0_OFFSET 0x0900 /* Device control IN endpoint 0 control register */
-#define STM32L4_OTGFS_DIEPCTL1_OFFSET 0x0920 /* Device control IN endpoint 2 control register */
-#define STM32L4_OTGFS_DIEPCTL2_OFFSET 0x0940 /* Device control IN endpoint 3 control register */
-#define STM32L4_OTGFS_DIEPCTL3_OFFSET 0x0960 /* Device control IN endpoint 4 control register */
-#define STM32L4_OTGFS_DIEPCTL4_OFFSET 0x0980 /* Device control IN endpoint 4 control register */
-#define STM32L4_OTGFS_DIEPCTL5_OFFSET 0x09a0 /* Device control IN endpoint 4 control register */
#define STM32L4_OTGFS_DIEPINT_OFFSET(n) (0x0908 + ((n) << 5))
-#define STM32L4_OTGFS_DIEPINT0_OFFSET 0x0908 /* Device endpoint-0 interrupt register */
-#define STM32L4_OTGFS_DIEPINT1_OFFSET 0x0928 /* Device endpoint-1 interrupt register */
-#define STM32L4_OTGFS_DIEPINT2_OFFSET 0x0948 /* Device endpoint-2 interrupt register */
-#define STM32L4_OTGFS_DIEPINT3_OFFSET 0x0968 /* Device endpoint-3 interrupt register */
-#define STM32L4_OTGFS_DIEPINT4_OFFSET 0x0988 /* Device endpoint-3 interrupt register */
-#define STM32L4_OTGFS_DIEPINT5_OFFSET 0x09a8 /* Device endpoint-3 interrupt register */
#define STM32L4_OTGFS_DIEPTSIZ_OFFSET(n) (0x910 + ((n) << 5))
-#define STM32L4_OTGFS_DIEPTSIZ0_OFFSET 0x0910 /* Device IN endpoint 0 transfer size register */
-#define STM32L4_OTGFS_DIEPTSIZ1_OFFSET 0x0930 /* Device IN endpoint 1 transfer size register */
-#define STM32L4_OTGFS_DIEPTSIZ2_OFFSET 0x0950 /* Device IN endpoint 2 transfer size register */
-#define STM32L4_OTGFS_DIEPTSIZ3_OFFSET 0x0970 /* Device IN endpoint 3 transfer size register */
-#define STM32L4_OTGFS_DIEPTSIZ4_OFFSET 0x0990 /* Device IN endpoint 3 transfer size register */
-#define STM32L4_OTGFS_DIEPTSIZ5_OFFSET 0x09b0 /* Device IN endpoint 3 transfer size register */
#define STM32L4_OTGFS_DTXFSTS_OFFSET(n) (0x0918 + ((n) << 5))
-#define STM32L4_OTGFS_DTXFSTS0_OFFSET 0x0918 /* Device OUT endpoint-0 TxFIFO status register */
-#define STM32L4_OTGFS_DTXFSTS1_OFFSET 0x0938 /* Device OUT endpoint-1 TxFIFO status register */
-#define STM32L4_OTGFS_DTXFSTS2_OFFSET 0x0958 /* Device OUT endpoint-2 TxFIFO status register */
-#define STM32L4_OTGFS_DTXFSTS3_OFFSET 0x0978 /* Device OUT endpoint-3 TxFIFO status register */
-#define STM32L4_OTGFS_DTXFSTS4_OFFSET 0x0998 /* Device OUT endpoint-3 TxFIFO status register */
-#define STM32L4_OTGFS_DTXFSTS5_OFFSET 0x09b8 /* Device OUT endpoint-3 TxFIFO status register */
#define STM32L4_OTGFS_DOEP_OFFSET(n) (0x0b00 + ((n) << 5))
#define STM32L4_OTGFS_DOEPCTL_EPOFFSET 0x0000 /* Device control OUT endpoint 0 control register */
@@ -217,28 +140,10 @@
#define STM32L4_OTGFS_DOEPTSIZ_EPOFFSET 0x0010 /* Device endpoint OUT transfer size register */
#define STM32L4_OTGFS_DOEPCTL_OFFSET(n) (0x0b00 + ((n) << 5))
-#define STM32L4_OTGFS_DOEPCTL0_OFFSET 0x00b00 /* Device OUT endpoint 0 control register */
-#define STM32L4_OTGFS_DOEPCTL1_OFFSET 0x00b20 /* Device OUT endpoint 1 control register */
-#define STM32L4_OTGFS_DOEPCTL2_OFFSET 0x00b40 /* Device OUT endpoint 2 control register */
-#define STM32L4_OTGFS_DOEPCTL3_OFFSET 0x00b60 /* Device OUT endpoint 3 control register */
-#define STM32L4_OTGFS_DOEPCTL4_OFFSET 0x00b80 /* Device OUT endpoint 4 control register */
-#define STM32L4_OTGFS_DOEPCTL5_OFFSET 0x00ba0 /* Device OUT endpoint 5 control register */
#define STM32L4_OTGFS_DOEPINT_OFFSET(n) (0x0b08 + ((n) << 5))
-#define STM32L4_OTGFS_DOEPINT0_OFFSET 0x00b08 /* Device endpoint-0 interrupt register */
-#define STM32L4_OTGFS_DOEPINT1_OFFSET 0x00b28 /* Device endpoint-1 interrupt register */
-#define STM32L4_OTGFS_DOEPINT2_OFFSET 0x00b48 /* Device endpoint-2 interrupt register */
-#define STM32L4_OTGFS_DOEPINT3_OFFSET 0x00b68 /* Device endpoint-3 interrupt register */
-#define STM32L4_OTGFS_DOEPINT4_OFFSET 0x00b88 /* Device endpoint-4 interrupt register */
-#define STM32L4_OTGFS_DOEPINT5_OFFSET 0x00ba8 /* Device endpoint-5 interrupt register */
#define STM32L4_OTGFS_DOEPTSIZ_OFFSET(n) (0x0b10 + ((n) << 5))
-#define STM32L4_OTGFS_DOEPTSIZ0_OFFSET 0x00b10 /* Device OUT endpoint-0 transfer size register */
-#define STM32L4_OTGFS_DOEPTSIZ1_OFFSET 0x00b30 /* Device OUT endpoint-1 transfer size register */
-#define STM32L4_OTGFS_DOEPTSIZ2_OFFSET 0x00b50 /* Device OUT endpoint-2 transfer size register */
-#define STM32L4_OTGFS_DOEPTSIZ3_OFFSET 0x00b70 /* Device OUT endpoint-3 transfer size register */
-#define STM32L4_OTGFS_DOEPTSIZ4_OFFSET 0x00b90 /* Device OUT endpoint-4 transfer size register */
-#define STM32L4_OTGFS_DOEPTSIZ5_OFFSET 0x00bb0 /* Device OUT endpoint-5 transfer size register */
/* Power and clock gating registers */
@@ -249,24 +154,6 @@
#define STM32L4_OTGFS_DFIFO_DEP_OFFSET(n) (0x1000 + ((n) << 12))
#define STM32L4_OTGFS_DFIFO_HCH_OFFSET(n) (0x1000 + ((n) << 12))
-#define STM32L4_OTGFS_DFIFO_DEP0_OFFSET 0x1000 /* 0x1000-0x1ffc Device IN/OUT Endpoint 0 DFIFO Write/Read Access */
-#define STM32L4_OTGFS_DFIFO_HCH0_OFFSET 0x1000 /* 0x1000-0x1ffc Host OUT/IN Channel 0 DFIFO Read/Write Access */
-
-#define STM32L4_OTGFS_DFIFO_DEP1_OFFSET 0x2000 /* 0x2000-0x2ffc Device IN/OUT Endpoint 1 DFIFO Write/Read Access */
-#define STM32L4_OTGFS_DFIFO_HCH1_OFFSET 0x2000 /* 0x2000-0x2ffc Host OUT/IN Channel 1 DFIFO Read/Write Access */
-
-#define STM32L4_OTGFS_DFIFO_DEP2_OFFSET 0x3000 /* 0x3000-0x3ffc Device IN/OUT Endpoint 2 DFIFO Write/Read Access */
-#define STM32L4_OTGFS_DFIFO_HCH2_OFFSET 0x3000 /* 0x3000-0x3ffc Host OUT/IN Channel 2 DFIFO Read/Write Access */
-
-#define STM32L4_OTGFS_DFIFO_DEP3_OFFSET 0x4000 /* 0x4000-0x4ffc Device IN/OUT Endpoint 3 DFIFO Write/Read Access */
-#define STM32L4_OTGFS_DFIFO_HCH3_OFFSET 0x4000 /* 0x4000-0x4ffc Host OUT/IN Channel 3 DFIFO Read/Write Access */
-
-#define STM32L4_OTGFS_DFIFO_DEP4_OFFSET 0x5000 /* 0x5000-0x5ffc Device IN/OUT Endpoint 4 DFIFO Write/Read Access */
-#define STM32L4_OTGFS_DFIFO_HCH4_OFFSET 0x5000 /* 0x5000-0x5ffc Host OUT/IN Channel 4 DFIFO Read/Write Access */
-
-#define STM32L4_OTGFS_DFIFO_DEP5_OFFSET 0x6000 /* 0x6000-0x6ffc Device IN/OUT Endpoint 5 DFIFO Write/Read Access */
-#define STM32L4_OTGFS_DFIFO_HCH5_OFFSET 0x6000 /* 0x6000-0x6ffc Host OUT/IN Channel 5 DFIFO Read/Write Access */
-
/* Register Addresses *******************************************************************************/
#define STM32L4_OTGFS_GOTGCTL (STM32L4_OTGFS_BASE+STM32L4_OTGFS_GOTGCTL_OFFSET)
@@ -290,11 +177,6 @@
#define STM32L4_OTGFS_HPTXFSIZ (STM32L4_OTGFS_BASE+STM32L4_OTGFS_HPTXFSIZ_OFFSET)
#define STM32L4_OTGFS_DIEPTXF(n) (STM32L4_OTGFS_BASE+STM32L4_OTGFS_DIEPTXF_OFFSET(n))
-#define STM32L4_OTGFS_DIEPTXF1 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_DIEPTXF1_OFFSET)
-#define STM32L4_OTGFS_DIEPTXF2 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_DIEPTXF2_OFFSET)
-#define STM32L4_OTGFS_DIEPTXF3 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_DIEPTXF3_OFFSET)
-#define STM32L4_OTGFS_DIEPTXF4 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_DIEPTXF4_OFFSET)
-#define STM32L4_OTGFS_DIEPTXF5 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_DIEPTXF5_OFFSET)
/* Host-mode control and status registers */
@@ -309,60 +191,12 @@
#define STM32L4_OTGFS_CHAN(n) (STM32L4_OTGFS_BASE+STM32L4_OTGFS_CHAN_OFFSET(n))
#define STM32L4_OTGFS_HCCHAR(n) (STM32L4_OTGFS_BASE+STM32L4_OTGFS_HCCHAR_OFFSET(n))
-#define STM32L4_OTGFS_HCCHAR0 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_HCCHAR0_OFFSET)
-#define STM32L4_OTGFS_HCCHAR1 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_HCCHAR1_OFFSET)
-#define STM32L4_OTGFS_HCCHAR2 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_HCCHAR2_OFFSET)
-#define STM32L4_OTGFS_HCCHAR3 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_HCCHAR3_OFFSET)
-#define STM32L4_OTGFS_HCCHAR4 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_HCCHAR4_OFFSET)
-#define STM32L4_OTGFS_HCCHAR5 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_HCCHAR5_OFFSET)
-#define STM32L4_OTGFS_HCCHAR6 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_HCCHAR6_OFFSET)
-#define STM32L4_OTGFS_HCCHAR7 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_HCCHAR7_OFFSET)
-#define STM32L4_OTGFS_HCCHAR8 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_HCCHAR8_OFFSET)
-#define STM32L4_OTGFS_HCCHAR9 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_HCCHAR9_OFFSET)
-#define STM32L4_OTGFS_HCCHAR10 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_HCCHAR10_OFFSET)
-#define STM32L4_OTGFS_HCCHAR11 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_HCCHAR11_OFFSET)
#define STM32L4_OTGFS_HCINT(n) (STM32L4_OTGFS_BASE+STM32L4_OTGFS_HCINT_OFFSET(n))
-#define STM32L4_OTGFS_HCINT0 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_HCINT0_OFFSET)
-#define STM32L4_OTGFS_HCINT1 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_HCINT1_OFFSET)
-#define STM32L4_OTGFS_HCINT2 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_HCINT2_OFFSET)
-#define STM32L4_OTGFS_HCINT3 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_HCINT3_OFFSET)
-#define STM32L4_OTGFS_HCINT4 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_HCINT4_OFFSET)
-#define STM32L4_OTGFS_HCINT5 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_HCINT5_OFFSET)
-#define STM32L4_OTGFS_HCINT6 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_HCINT6_OFFSET)
-#define STM32L4_OTGFS_HCINT7 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_HCINT7_OFFSET)
-#define STM32L4_OTGFS_HCINT8 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_HCINT8_OFFSET)
-#define STM32L4_OTGFS_HCINT9 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_HCINT9_OFFSET)
-#define STM32L4_OTGFS_HCINT10 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_HCINT10_OFFSET)
-#define STM32L4_OTGFS_HCINT11 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_HCINT11_OFFSET)
#define STM32L4_OTGFS_HCINTMSK(n) (STM32L4_OTGFS_BASE+STM32L4_OTGFS_HCINTMSK_OFFSET(n))
-#define STM32L4_OTGFS_HCINTMSK0 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_HCINTMSK0_OFFSET)
-#define STM32L4_OTGFS_HCINTMSK1 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_HCINTMSK1_OFFSET)
-#define STM32L4_OTGFS_HCINTMSK2 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_HCINTMSK2_OFFSET)
-#define STM32L4_OTGFS_HCINTMSK3 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_HCINTMSK3_OFFSET)
-#define STM32L4_OTGFS_HCINTMSK4 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_HCINTMSK4_OFFSET)
-#define STM32L4_OTGFS_HCINTMSK5 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_HCINTMSK5_OFFSET)
-#define STM32L4_OTGFS_HCINTMSK6 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_HCINTMSK6_OFFSET)
-#define STM32L4_OTGFS_HCINTMSK7 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_HCINTMSK7_OFFSET)
-#define STM32L4_OTGFS_HCINTMSK8 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_HCINTMSK8_OFFSET)
-#define STM32L4_OTGFS_HCINTMSK9 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_HCINTMSK9_OFFSET)
-#define STM32L4_OTGFS_HCINTMSK10 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_HCINTMSK10_OFFSET)
-#define STM32L4_OTGFS_HCINTMSK11 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_HCINTMSK11_OFFSET)
#define STM32L4_OTGFS_HCTSIZ(n) (STM32L4_OTGFS_BASE+STM32L4_OTGFS_HCTSIZ_OFFSET(n))
-#define STM32L4_OTGFS_HCTSIZ0 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_HCTSIZ0_OFFSET)
-#define STM32L4_OTGFS_HCTSIZ1 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_HCTSIZ1_OFFSET)
-#define STM32L4_OTGFS_HCTSIZ2 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_HCTSIZ2_OFFSET)
-#define STM32L4_OTGFS_HCTSIZ3 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_HCTSIZ3_OFFSET)
-#define STM32L4_OTGFS_HCTSIZ4 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_HCTSIZ4_OFFSET)
-#define STM32L4_OTGFS_HCTSIZ5 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_HCTSIZ5_OFFSET)
-#define STM32L4_OTGFS_HCTSIZ6 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_HCTSIZ6_OFFSET)
-#define STM32L4_OTGFS_HCTSIZ7 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_HCTSIZ7_OFFSET)
-#define STM32L4_OTGFS_HCTSIZ8 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_HCTSIZ8_OFFSET)
-#define STM32L4_OTGFS_HCTSIZ9 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_HCTSIZ9_OFFSET)
-#define STM32L4_OTGFS_HCTSIZ10 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_HCTSIZ10_OFFSET)
-#define STM32L4_OTGFS_HCTSIZ11 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_HCTSIZ11_OFFSET)
/* Device-mode control and status registers */
@@ -380,62 +214,20 @@
#define STM32L4_OTGFS_DIEP(n) (STM32L4_OTGFS_BASE+STM32L4_OTGFS_DIEP_OFFSET(n))
#define STM32L4_OTGFS_DIEPCTL(n) (STM32L4_OTGFS_BASE+STM32L4_OTGFS_DIEPCTL_OFFSET(n))
-#define STM32L4_OTGFS_DIEPCTL0 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_DIEPCTL0_OFFSET)
-#define STM32L4_OTGFS_DIEPCTL1 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_DIEPCTL1_OFFSET)
-#define STM32L4_OTGFS_DIEPCTL2 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_DIEPCTL2_OFFSET)
-#define STM32L4_OTGFS_DIEPCTL3 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_DIEPCTL3_OFFSET)
-#define STM32L4_OTGFS_DIEPCTL4 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_DIEPCTL4_OFFSET)
-#define STM32L4_OTGFS_DIEPCTL5 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_DIEPCTL5_OFFSET)
#define STM32L4_OTGFS_DIEPINT(n) (STM32L4_OTGFS_BASE+STM32L4_OTGFS_DIEPINT_OFFSET(n))
-#define STM32L4_OTGFS_DIEPINT0 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_DIEPINT0_OFFSET)
-#define STM32L4_OTGFS_DIEPINT1 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_DIEPINT1_OFFSET)
-#define STM32L4_OTGFS_DIEPINT2 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_DIEPINT2_OFFSET)
-#define STM32L4_OTGFS_DIEPINT3 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_DIEPINT3_OFFSET)
-#define STM32L4_OTGFS_DIEPINT4 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_DIEPINT4_OFFSET)
-#define STM32L4_OTGFS_DIEPINT5 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_DIEPINT5_OFFSET)
#define STM32L4_OTGFS_DIEPTSIZ(n) (STM32L4_OTGFS_BASE+STM32L4_OTGFS_DIEPTSIZ_OFFSET(n))
-#define STM32L4_OTGFS_DIEPTSIZ0 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_DIEPTSIZ0_OFFSET)
-#define STM32L4_OTGFS_DIEPTSIZ1 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_DIEPTSIZ1_OFFSET)
-#define STM32L4_OTGFS_DIEPTSIZ2 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_DIEPTSIZ2_OFFSET)
-#define STM32L4_OTGFS_DIEPTSIZ3 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_DIEPTSIZ3_OFFSET)
-#define STM32L4_OTGFS_DIEPTSIZ4 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_DIEPTSIZ4_OFFSET)
-#define STM32L4_OTGFS_DIEPTSIZ5 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_DIEPTSIZ5_OFFSET)
#define STM32L4_OTGFS_DTXFSTS(n) (STM32L4_OTGFS_BASE+STM32L4_OTGFS_DTXFSTS_OFFSET(n))
-#define STM32L4_OTGFS_DTXFSTS0 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_DTXFSTS0_OFFSET)
-#define STM32L4_OTGFS_DTXFSTS1 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_DTXFSTS1_OFFSET)
-#define STM32L4_OTGFS_DTXFSTS2 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_DTXFSTS2_OFFSET)
-#define STM32L4_OTGFS_DTXFSTS3 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_DTXFSTS3_OFFSET)
-#define STM32L4_OTGFS_DTXFSTS4 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_DTXFSTS4_OFFSET)
-#define STM32L4_OTGFS_DTXFSTS5 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_DTXFSTS5_OFFSET)
#define STM32L4_OTGFS_DOEP(n) (STM32L4_OTGFS_BASE+STM32L4_OTGFS_DOEP_OFFSET(n))
#define STM32L4_OTGFS_DOEPCTL(n) (STM32L4_OTGFS_BASE+STM32L4_OTGFS_DOEPCTL_OFFSET(n))
-#define STM32L4_OTGFS_DOEPCTL0 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_DOEPCTL0_OFFSET)
-#define STM32L4_OTGFS_DOEPCTL1 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_DOEPCTL1_OFFSET)
-#define STM32L4_OTGFS_DOEPCTL2 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_DOEPCTL2_OFFSET)
-#define STM32L4_OTGFS_DOEPCTL3 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_DOEPCTL3_OFFSET)
-#define STM32L4_OTGFS_DOEPCTL4 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_DOEPCTL4_OFFSET)
-#define STM32L4_OTGFS_DOEPCTL5 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_DOEPCTL5_OFFSET)
#define STM32L4_OTGFS_DOEPINT(n) (STM32L4_OTGFS_BASE+STM32L4_OTGFS_DOEPINT_OFFSET(n))
-#define STM32L4_OTGFS_DOEPINT0 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_DOEPINT0_OFFSET)
-#define STM32L4_OTGFS_DOEPINT1 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_DOEPINT1_OFFSET)
-#define STM32L4_OTGFS_DOEPINT2 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_DOEPINT2_OFFSET)
-#define STM32L4_OTGFS_DOEPINT3 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_DOEPINT3_OFFSET)
-#define STM32L4_OTGFS_DOEPINT4 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_DOEPINT4_OFFSET)
-#define STM32L4_OTGFS_DOEPINT5 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_DOEPINT5_OFFSET)
#define STM32L4_OTGFS_DOEPTSIZ(n) (STM32L4_OTGFS_BASE+STM32L4_OTGFS_DOEPTSIZ_OFFSET(n))
-#define STM32L4_OTGFS_DOEPTSIZ0 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_DOEPTSIZ0_OFFSET)
-#define STM32L4_OTGFS_DOEPTSIZ1 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_DOEPTSIZ1_OFFSET)
-#define STM32L4_OTGFS_DOEPTSIZ2 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_DOEPTSIZ2_OFFSET)
-#define STM32L4_OTGFS_DOEPTSIZ3 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_DOEPTSIZ3_OFFSET)
-#define STM32L4_OTGFS_DOEPTSIZ4 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_DOEPTSIZ4_OFFSET)
-#define STM32L4_OTGFS_DOEPTSIZ5 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_DOEPTSIZ5_OFFSET)
/* Power and clock gating registers */
@@ -446,23 +238,7 @@
#define STM32L4_OTGFS_DFIFO_DEP(n) (STM32L4_OTGFS_BASE+STM32L4_OTGFS_DFIFO_DEP_OFFSET(n))
#define STM32L4_OTGFS_DFIFO_HCH(n) (STM32L4_OTGFS_BASE+STM32L4_OTGFS_DFIFO_HCH_OFFSET(n))
-#define STM32L4_OTGFS_DFIFO_DEP0 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_DFIFO_DEP0_OFFSET)
-#define STM32L4_OTGFS_DFIFO_HCH0 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_DFIFO_HCH0_OFFSET)
-
-#define STM32L4_OTGFS_DFIFO_DEP1 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_DFIFO_DEP1_OFFSET)
-#define STM32L4_OTGFS_DFIFO_HCH1 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_DFIFO_HCH1_OFFSET)
-
-#define STM32L4_OTGFS_DFIFO_DEP2 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_DFIFO_DEP2_OFFSET)
-#define STM32L4_OTGFS_DFIFO_HCH2 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_DFIFO_HCH2_OFFSET)
-
-#define STM32L4_OTGFS_DFIFO_DEP3 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_DFIFO_DEP3_OFFSET)
-#define STM32L4_OTGFS_DFIFO_HCH3 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_DFIFO_HCH3_OFFSET)
-
-#define STM32L4_OTGFS_DFIFO_DEP4 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_DFIFO_DEP4_OFFSET)
-#define STM32L4_OTGFS_DFIFO_HCH4 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_DFIFO_HCH4_OFFSET)
-#define STM32L4_OTGFS_DFIFO_DEP5 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_DFIFO_DEP5_OFFSET)
-#define STM32L4_OTGFS_DFIFO_HCH5 (STM32L4_OTGFS_BASE+STM32L4_OTGFS_DFIFO_HCH5_OFFSET)
/* Register Bitfield Definitions ********************************************************************/
/* Core global control and status registers */
@@ -911,7 +687,7 @@
#define OTGFS_DCTL_CGONAK (1 << 10) /* Bit 10: Clear global OUT NAK */
#define OTGFS_DCTL_POPRGDNE (1 << 11) /* Bit 11: Power-on programming done */
/* Bits 12-17: Reserved, must be kept at reset value */
-#define OTGFS_DCTL_DSBESLRJCT (1 << 18) /* Bit 18: XXX */
+#define OTGFS_DCTL_DSBESLRJCT (1 << 18) /* Bit 18: Deep sleep BESL reject */
/* Bits 19-31: Reserved, must be kept at reset value */
/* Device status register */
@@ -939,9 +715,9 @@
#define OTGFS_DIEPMSK_ITTXFEMSK (1 << 4) /* Bit 4: IN token received when TxFIFO empty mask */
#define OTGFS_DIEPMSK_INEPNMM (1 << 5) /* Bit 5: IN token received with EP mismatch mask */
#define OTGFS_DIEPMSK_INEPNEM (1 << 6) /* Bit 6: IN endpoint NAK effective mask */
- /* Bits 7-11: Reserved, must be kept at reset value */
-#define OTGFS_DIEPMSK_NAKM (1 << 12) /* Bit 12: XXX mask */
- /* Bits 13-31: Reserved, must be kept at reset value */
+ /* Bits 7-12: Reserved, must be kept at reset value */
+#define OTGFS_DIEPMSK_NAKM (1 << 13) /* Bit 13: NAK interrupt mask */
+ /* Bits 14-31: Reserved, must be kept at reset value */
/* Device OUT endpoint common interrupt mask register */
#define OTGFS_DOEPMSK_XFRCM (1 << 0) /* Bit 0: Transfer completed interrupt mask */
@@ -1154,9 +930,9 @@
#define OTGFS_PCGCCTL_GATEHCLK (1 << 1) /* Bit 1: Gate HCLK */
/* Bits 2-3: Reserved, must be kept at reset value */
#define OTGFS_PCGCCTL_PHYSUSP (1 << 4) /* Bit 4: PHY Suspended */
-#define OTGFS_PCGCCTL_ENL1GTG (1 << 5) /* Bit 5: XXX */
-#define OTGFS_PCGCCTL_PHYSLEEP (1 << 6) /* Bit 6: XXX */
-#define OTGFS_PCGCCTL_SUSP (1 << 7) /* Bit 7: XXX */
+#define OTGFS_PCGCCTL_ENL1GTG (1 << 5) /* Bit 5: Enable Sleep clock gating */
+#define OTGFS_PCGCCTL_PHYSLEEP (1 << 6) /* Bit 6: PHY in Sleep */
+#define OTGFS_PCGCCTL_SUSP (1 << 7) /* Bit 7: Deep Sleep */
/* Bits 8-31: Reserved, must be kept at reset value */
#endif /* __ARCH_ARM_SRC_STM32L4_CHIP_STM32L4X6XX_OTGFS_H */
--
GitLab
From a416b304a3bc79104664552f6437177a5d764833 Mon Sep 17 00:00:00 2001
From: David Sidrane
Date: Fri, 30 Sep 2016 08:49:32 -1000
Subject: [PATCH 026/734] Code Cleanup and conform to upstrem debug config
---
arch/arm/src/stm32l4/stm32l4_otgfsdev.c | 79 ++++++++++++-------------
1 file changed, 37 insertions(+), 42 deletions(-)
diff --git a/arch/arm/src/stm32l4/stm32l4_otgfsdev.c b/arch/arm/src/stm32l4/stm32l4_otgfsdev.c
index 06bab127d3..e7c33c256b 100644
--- a/arch/arm/src/stm32l4/stm32l4_otgfsdev.c
+++ b/arch/arm/src/stm32l4/stm32l4_otgfsdev.c
@@ -336,7 +336,7 @@
#define CONFIG_USB_DUMPBUFFER
-#if !defined(CONFIG_DEBUG_INFO) || !defined(CONFIG_DEBUG_USB)
+#if !defined(CONFIG_DEBUG_INFO) || !defined(CONFIG_DEBUG_FEATURES)
# undef CONFIG_USB_DUMPBUFFER
#endif
#ifdef CONFIG_USB_DUMPBUFFER
@@ -582,7 +582,7 @@ struct stm32l4_usbdev_s
/* Register operations ********************************************************/
-#if defined(CONFIG_STM32L4_USBDEV_REGDEBUG) && defined(CONFIG_DEBUG_USB)
+#if defined(CONFIG_STM32L4_USBDEV_REGDEBUG) && defined(CONFIG_DEBUG_FEATURES)
static uint32_t stm32l4_getreg(uint32_t addr);
static void stm32l4_putreg(uint32_t val, uint32_t addr);
#else
@@ -902,7 +902,7 @@ const struct trace_msg_t g_usb_trace_strings_intdecode[] =
*
****************************************************************************/
-#if defined(CONFIG_STM32L4_USBDEV_REGDEBUG) && defined(CONFIG_DEBUG_USB)
+#if defined(CONFIG_STM32L4_USBDEV_REGDEBUG) && defined(CONFIG_DEBUG_FEATURES)
static uint32_t stm32l4_getreg(uint32_t addr)
{
static uint32_t prevaddr = 0;
@@ -923,7 +923,7 @@ static uint32_t stm32l4_getreg(uint32_t addr)
{
if (count == 4)
{
- lldbg("...\n");
+ uinfo("...\n");
}
return val;
@@ -940,7 +940,7 @@ static uint32_t stm32l4_getreg(uint32_t addr)
{
/* Yes.. then show how many times the value repeated */
- lldbg("[repeats %d more times]\n", count-3);
+ uinfo("[repeats %d more times]\n", count-3);
}
/* Save the new address, value, and count */
@@ -952,7 +952,7 @@ static uint32_t stm32l4_getreg(uint32_t addr)
/* Show the register value read */
- lldbg("%08x->%08x\n", addr, val);
+ uinfo("%08x->%08x\n", addr, val);
return val;
}
#endif
@@ -965,12 +965,12 @@ static uint32_t stm32l4_getreg(uint32_t addr)
*
****************************************************************************/
-#if defined(CONFIG_STM32L4_USBDEV_REGDEBUG) && defined(CONFIG_DEBUG_USB)
+#if defined(CONFIG_STM32L4_USBDEV_REGDEBUG) && defined(CONFIG_DEBUG_FEATURES)
static void stm32l4_putreg(uint32_t val, uint32_t addr)
{
/* Show the register value being written */
- lldbg("%08x<-%08x\n", addr, val);
+ uinfo("%08x<-%08x\n", addr, val);
/* Write the value */
@@ -1075,7 +1075,7 @@ static void stm32l4_ep0in_activate(void)
/* Set the max packet size of the IN EP. */
- regval = stm32l4_getreg(STM32L4_OTGFS_DIEPCTL0);
+ regval = stm32l4_getreg(STM32L4_OTGFS_DIEPCTL(0));
regval &= ~OTGFS_DIEPCTL0_MPSIZ_MASK;
#if CONFIG_USBDEV_EP0_MAXSIZE == 8
@@ -1090,7 +1090,7 @@ static void stm32l4_ep0in_activate(void)
# error "Unsupported value of CONFIG_USBDEV_EP0_MAXSIZE"
#endif
- stm32l4_putreg(regval, STM32L4_OTGFS_DIEPCTL0);
+ stm32l4_putreg(regval, STM32L4_OTGFS_DIEPCTL(0));
/* Clear global IN NAK */
@@ -1116,13 +1116,13 @@ static void stm32l4_ep0out_ctrlsetup(FAR struct stm32l4_usbdev_s *priv)
regval = (USB_SIZEOF_CTRLREQ * 3 << OTGFS_DOEPTSIZ0_XFRSIZ_SHIFT) |
(OTGFS_DOEPTSIZ0_PKTCNT) |
(3 << OTGFS_DOEPTSIZ0_STUPCNT_SHIFT);
- stm32l4_putreg(regval, STM32L4_OTGFS_DOEPTSIZ0);
+ stm32l4_putreg(regval, STM32L4_OTGFS_DOEPTSIZ(0));
/* Then clear NAKing and enable the transfer */
- regval = stm32l4_getreg(STM32L4_OTGFS_DOEPCTL0);
+ regval = stm32l4_getreg(STM32L4_OTGFS_DOEPCTL(0));
regval |= (OTGFS_DOEPCTL0_CNAK | OTGFS_DOEPCTL0_EPENA);
- stm32l4_putreg(regval, STM32L4_OTGFS_DOEPCTL0);
+ stm32l4_putreg(regval, STM32L4_OTGFS_DOEPCTL(0));
}
/****************************************************************************
@@ -2416,8 +2416,6 @@ static inline void stm32l4_ep0out_stdrequest(struct stm32l4_usbdev_s *priv,
stm32l4_setaddress(priv, (uint16_t)priv->ctrlreq.value[0]);
stm32l4_ep0in_transmitzlp(priv);
-
- uinfo("USB_REQ_SETADDRESS %02x\n",(uint16_t)priv->ctrlreq.value[0]);
}
else
{
@@ -2983,7 +2981,7 @@ static inline void stm32l4_epin_interrupt(FAR struct stm32l4_usbdev_s *priv)
{
if ((daint & 1) != 0)
{
- uinfo("DIEPINT(%d) = %08x\n",
+ uerr("DIEPINT(%d) = %08x\n",
epno, stm32l4_getreg(STM32L4_OTGFS_DIEPINT(epno)));
stm32l4_putreg(0xFF, STM32L4_OTGFS_DIEPINT(epno));
}
@@ -3240,8 +3238,6 @@ static inline void stm32l4_rxinterrupt(FAR struct stm32l4_usbdev_s *priv)
int bcnt;
int epphy;
- /* Disable the Rx status queue level interrupt */
-
while(0 != (stm32l4_getreg(STM32L4_OTGFS_GINTSTS) & OTGFS_GINT_RXFLVL))
{
@@ -3334,12 +3330,11 @@ static inline void stm32l4_rxinterrupt(FAR struct stm32l4_usbdev_s *priv)
{
/* Clear NAKSTS so that we can receive the data */
-
- regval = stm32l4_getreg(STM32L4_OTGFS_DOEPCTL0);
+ regval = stm32l4_getreg(STM32L4_OTGFS_DOEPCTL(0));
regval |= OTGFS_DOEPCTL0_CNAK;
- stm32l4_putreg(regval, STM32L4_OTGFS_DOEPCTL0);
+ stm32l4_putreg(regval, STM32L4_OTGFS_DOEPCTL(0));
- }
+ }
}
break;
@@ -3642,7 +3637,7 @@ static int stm32l4_usbinterrupt(int irq, FAR void *context)
uint32_t regval;
uint32_t reserved;
- usbtrace(TRACE_INTENTRY(STM32L4_TRACEINTID_USB), 0);
+ usbtrace(TRACE_INTENTRY(STM32L4_TRACEINTID_USB), priv->ep0state);
/* Assure that we are in device mode */
@@ -3699,7 +3694,7 @@ static int stm32l4_usbinterrupt(int irq, FAR void *context)
/* Host/device mode mismatch error interrupt */
-#ifdef CONFIG_DEBUG_USB
+#ifdef CONFIG_DEBUG_FEATURES
if ((regval & OTGFS_GINT_MMIS) != 0)
{
usbtrace(TRACE_INTDECODE(STM32L4_TRACEINTID_MISMATCH), (uint16_t)regval);
@@ -3750,7 +3745,7 @@ static int stm32l4_usbinterrupt(int irq, FAR void *context)
/* Perform the device reset */
stm32l4_usbreset(priv);
- usbtrace(TRACE_INTEXIT(STM32L4_TRACEINTID_USB), 0);
+ usbtrace(TRACE_INTEXIT(STM32L4_TRACEINTID_USB), priv->ep0state);
return OK;
}
@@ -3811,7 +3806,7 @@ static int stm32l4_usbinterrupt(int irq, FAR void *context)
#endif
}
- usbtrace(TRACE_INTEXIT(STM32L4_TRACEINTID_USB), 0);
+ usbtrace(TRACE_INTEXIT(STM32L4_TRACEINTID_USB), priv->ep0state);
return OK;
}
@@ -4317,7 +4312,7 @@ static int stm32l4_ep_disable(FAR struct usbdev_ep_s *ep)
{
FAR struct stm32l4_ep_s *privep = (FAR struct stm32l4_ep_s *)ep;
-#ifdef CONFIG_DEBUG_USB
+#ifdef CONFIG_DEBUG_FEATURES
if (!ep)
{
usbtrace(TRACE_DEVERROR(STM32L4_TRACEERR_INVALIDPARMS), 0);
@@ -4357,7 +4352,7 @@ static FAR struct usbdev_req_s *stm32l4_ep_allocreq(FAR struct usbdev_ep_s *ep)
{
FAR struct stm32l4_req_s *privreq;
-#ifdef CONFIG_DEBUG_USB
+#ifdef CONFIG_DEBUG_FEATURES
if (!ep)
{
usbtrace(TRACE_DEVERROR(STM32L4_TRACEERR_INVALIDPARMS), 0);
@@ -4390,7 +4385,7 @@ static void stm32l4_ep_freereq(FAR struct usbdev_ep_s *ep, FAR struct usbdev_req
{
FAR struct stm32l4_req_s *privreq = (FAR struct stm32l4_req_s *)req;
-#ifdef CONFIG_DEBUG_USB
+#ifdef CONFIG_DEBUG_FEATURES
if (!ep || !req)
{
usbtrace(TRACE_DEVERROR(STM32L4_TRACEERR_INVALIDPARMS), 0);
@@ -4463,7 +4458,7 @@ static int stm32l4_ep_submit(FAR struct usbdev_ep_s *ep,
/* Some sanity checking */
-#ifdef CONFIG_DEBUG_USB
+#ifdef CONFIG_DEBUG_FEATURES
if (!req || !req->callback || !req->buf || !ep)
{
usbtrace(TRACE_DEVERROR(STM32L4_TRACEERR_INVALIDPARMS), 0);
@@ -4475,7 +4470,7 @@ static int stm32l4_ep_submit(FAR struct usbdev_ep_s *ep,
usbtrace(TRACE_EPSUBMIT, privep->epphy);
priv = privep->dev;
-#ifdef CONFIG_DEBUG_USB
+#ifdef CONFIG_DEBUG_FEATURES
if (!priv->driver)
{
usbtrace(TRACE_DEVERROR(STM32L4_TRACEERR_NOTCONFIGURED), priv->usbdev.speed);
@@ -4553,7 +4548,7 @@ static int stm32l4_ep_cancel(FAR struct usbdev_ep_s *ep,
FAR struct stm32l4_ep_s *privep = (FAR struct stm32l4_ep_s *)ep;
irqstate_t flags;
-#ifdef CONFIG_DEBUG_USB
+#ifdef CONFIG_DEBUG_FEATURES
if (!ep || !req)
{
usbtrace(TRACE_DEVERROR(STM32L4_TRACEERR_INVALIDPARMS), 0);
@@ -5012,7 +5007,7 @@ static int stm32l4_selfpowered(struct usbdev_s *dev, bool selfpowered)
usbtrace(TRACE_DEVSELFPOWERED, (uint16_t)selfpowered);
-#ifdef CONFIG_DEBUG_USB
+#ifdef CONFIG_DEBUG_FEATURES
if (!dev)
{
usbtrace(TRACE_DEVERROR(STM32L4_TRACEERR_INVALIDPARMS), 0);
@@ -5366,7 +5361,7 @@ static void stm32l4_hwinitialize(FAR struct stm32l4_usbdev_s *priv)
address = STM32L4_RXFIFO_WORDS;
regval = (address << OTGFS_DIEPTXF0_TX0FD_SHIFT) |
(STM32L4_EP0_TXFIFO_WORDS << OTGFS_DIEPTXF0_TX0FSA_SHIFT);
- stm32l4_putreg(regval, STM32L4_OTGFS_DIEPTXF0);
+ stm32l4_putreg(regval, STM32L4_OTGFS_DIEPTXF(0));
#endif
#if STM32L4_NENDPOINTS > 1
@@ -5375,7 +5370,7 @@ static void stm32l4_hwinitialize(FAR struct stm32l4_usbdev_s *priv)
address += STM32L4_EP0_TXFIFO_WORDS;
regval = (address << OTGFS_DIEPTXF_INEPTXSA_SHIFT) |
(STM32L4_EP1_TXFIFO_WORDS << OTGFS_DIEPTXF_INEPTXFD_SHIFT);
- stm32l4_putreg(regval, STM32L4_OTGFS_DIEPTXF1);
+ stm32l4_putreg(regval, STM32L4_OTGFS_DIEPTXF(1));
#endif
#if STM32L4_NENDPOINTS > 2
@@ -5384,7 +5379,7 @@ static void stm32l4_hwinitialize(FAR struct stm32l4_usbdev_s *priv)
address += STM32L4_EP1_TXFIFO_WORDS;
regval = (address << OTGFS_DIEPTXF_INEPTXSA_SHIFT) |
(STM32L4_EP2_TXFIFO_WORDS << OTGFS_DIEPTXF_INEPTXFD_SHIFT);
- stm32l4_putreg(regval, STM32L4_OTGFS_DIEPTXF2);
+ stm32l4_putreg(regval, STM32L4_OTGFS_DIEPTXF(2));
#endif
#if STM32L4_NENDPOINTS > 3
@@ -5393,7 +5388,7 @@ static void stm32l4_hwinitialize(FAR struct stm32l4_usbdev_s *priv)
address += STM32L4_EP2_TXFIFO_WORDS;
regval = (address << OTGFS_DIEPTXF_INEPTXSA_SHIFT) |
(STM32L4_EP3_TXFIFO_WORDS << OTGFS_DIEPTXF_INEPTXFD_SHIFT);
- stm32l4_putreg(regval, STM32L4_OTGFS_DIEPTXF3);
+ stm32l4_putreg(regval, STM32L4_OTGFS_DIEPTXF(3));
#endif
#if STM32L4_NENDPOINTS > 4
@@ -5402,7 +5397,7 @@ static void stm32l4_hwinitialize(FAR struct stm32l4_usbdev_s *priv)
address += STM32L4_EP3_TXFIFO_WORDS;
regval = (address << OTGFS_DIEPTXF_INEPTXSA_SHIFT) |
(STM32L4_EP4_TXFIFO_WORDS << OTGFS_DIEPTXF_INEPTXFD_SHIFT);
- stm32l4_putreg(regval, STM32L4_OTGFS_DIEPTXF4);
+ stm32l4_putreg(regval, STM32L4_OTGFS_DIEPTXF(4));
#endif
#if STM32L4_NENDPOINTS > 5
@@ -5411,7 +5406,7 @@ static void stm32l4_hwinitialize(FAR struct stm32l4_usbdev_s *priv)
address += STM32L4_EP4_TXFIFO_WORDS;
regval = (address << OTGFS_DIEPTXF_INEPTXSA_SHIFT) |
(STM32L4_EP5_TXFIFO_WORDS << OTGFS_DIEPTXF_INEPTXFD_SHIFT);
- stm32l4_putreg(regval, STM32L4_OTGFS_DIEPTXF5);
+ stm32l4_putreg(regval, STM32L4_OTGFS_DIEPTXF(5));
#endif
@@ -5501,7 +5496,7 @@ static void stm32l4_hwinitialize(FAR struct stm32l4_usbdev_s *priv)
regval |= (OTGFS_GINT_OTG | OTGFS_GINT_SRQ);
#endif
-#ifdef CONFIG_DEBUG_USB
+#ifdef CONFIG_DEBUG_FEATURES
regval |= OTGFS_GINT_MMIS;
#endif
@@ -5709,7 +5704,7 @@ int usbdev_register(struct usbdevclass_driver_s *driver)
usbtrace(TRACE_DEVREGISTER, 0);
-#ifdef CONFIG_DEBUG_USB
+#ifdef CONFIG_DEBUG_FEATURES
if (!driver || !driver->ops->bind || !driver->ops->unbind ||
!driver->ops->disconnect || !driver->ops->setup)
{
@@ -5780,7 +5775,7 @@ int usbdev_unregister(struct usbdevclass_driver_s *driver)
usbtrace(TRACE_DEVUNREGISTER, 0);
-#ifdef CONFIG_DEBUG_USB
+#ifdef CONFIG_DEBUG_FEATURES
if (driver != priv->driver)
{
usbtrace(TRACE_DEVERROR(STM32L4_TRACEERR_INVALIDPARMS), 0);
--
GitLab
From d4a8585d6f2819f4c4b2c92262542219801ee652 Mon Sep 17 00:00:00 2001
From: David Sidrane
Date: Tue, 4 Oct 2016 16:35:59 -1000
Subject: [PATCH 027/734] Fixed L4 USB Driver by avoiding SETUPDONE and
EPOUT_SETUP
---
arch/arm/src/stm32l4/stm32l4_otgfsdev.c | 24 ++++++++++--------------
1 file changed, 10 insertions(+), 14 deletions(-)
diff --git a/arch/arm/src/stm32l4/stm32l4_otgfsdev.c b/arch/arm/src/stm32l4/stm32l4_otgfsdev.c
index e7c33c256b..407534f4fb 100644
--- a/arch/arm/src/stm32l4/stm32l4_otgfsdev.c
+++ b/arch/arm/src/stm32l4/stm32l4_otgfsdev.c
@@ -3321,20 +3321,10 @@ static inline void stm32l4_rxinterrupt(FAR struct stm32l4_usbdev_s *priv)
{
usbtrace(TRACE_INTDECODE(STM32L4_TRACEINTID_SETUPDONE), epphy);
- /* Now that the Setup Phase is complete if it was an OUT enable
- * the endpoint
- * (Doing this here prevents the loss of the first FIFO word)
+ /* On the L4 This event does not occur on the next SETUP
+ * after a SETUP OUT.
*/
- if (priv->ep0state == EP0STATE_SETUP_OUT)
- {
-
- /* Clear NAKSTS so that we can receive the data */
- regval = stm32l4_getreg(STM32L4_OTGFS_DOEPCTL(0));
- regval |= OTGFS_DOEPCTL0_CNAK;
- stm32l4_putreg(regval, STM32L4_OTGFS_DOEPCTL(0));
-
- }
}
break;
@@ -3370,17 +3360,23 @@ static inline void stm32l4_rxinterrupt(FAR struct stm32l4_usbdev_s *priv)
datlen = GETUINT16(priv->ctrlreq.len);
if (USB_REQ_ISOUT(priv->ctrlreq.type) && datlen > 0)
{
+ /* Reset the endpoint and Stop NAK-ing */
+
+ stm32l4_ep0out_ctrlsetup(priv);
+
/* Wait for the data phase. */
priv->ep0state = EP0STATE_SETUP_OUT;
}
else
{
- /* We can process the setup data as soon as SETUP done word is
- * popped of the RxFIFO.
+ /* We can process the setup data Now no need to wait for SETUP done word
+ * to be popped of the RxFIFO.
*/
priv->ep0state = EP0STATE_SETUP_READY;
+ stm32l4_ep0out_setup(priv);
+
}
}
break;
--
GitLab
From 796fbe834a6a181848fbedb18d71d74a4b60af25 Mon Sep 17 00:00:00 2001
From: Mateusz Szafoni
Date: Thu, 6 Oct 2016 11:13:10 +0200
Subject: [PATCH 028/734] configs/olimex-stm32-e407: Add some networking
configurations
---
configs/olimex-stm32-e407/discover/Make.defs | 112 ++
configs/olimex-stm32-e407/discover/defconfig | 1298 +++++++++++++++
configs/olimex-stm32-e407/discover/setenv.sh | 80 +
configs/olimex-stm32-e407/include/board.h | 2 +-
configs/olimex-stm32-e407/netnsh/Make.defs | 112 ++
configs/olimex-stm32-e407/netnsh/defconfig | 1429 +++++++++++++++++
configs/olimex-stm32-e407/netnsh/setenv.sh | 80 +
.../olimex-stm32-e407/src/olimex-stm32-e407.h | 37 +-
configs/olimex-stm32-e407/telnetd/Make.defs | 112 ++
configs/olimex-stm32-e407/telnetd/defconfig | 1304 +++++++++++++++
configs/olimex-stm32-e407/telnetd/setenv.sh | 80 +
configs/olimex-stm32-e407/webserver/Make.defs | 112 ++
configs/olimex-stm32-e407/webserver/defconfig | 1309 +++++++++++++++
configs/olimex-stm32-e407/webserver/setenv.sh | 80 +
14 files changed, 6135 insertions(+), 12 deletions(-)
create mode 100644 configs/olimex-stm32-e407/discover/Make.defs
create mode 100644 configs/olimex-stm32-e407/discover/defconfig
create mode 100755 configs/olimex-stm32-e407/discover/setenv.sh
create mode 100644 configs/olimex-stm32-e407/netnsh/Make.defs
create mode 100644 configs/olimex-stm32-e407/netnsh/defconfig
create mode 100755 configs/olimex-stm32-e407/netnsh/setenv.sh
create mode 100644 configs/olimex-stm32-e407/telnetd/Make.defs
create mode 100644 configs/olimex-stm32-e407/telnetd/defconfig
create mode 100755 configs/olimex-stm32-e407/telnetd/setenv.sh
create mode 100644 configs/olimex-stm32-e407/webserver/Make.defs
create mode 100644 configs/olimex-stm32-e407/webserver/defconfig
create mode 100755 configs/olimex-stm32-e407/webserver/setenv.sh
diff --git a/configs/olimex-stm32-e407/discover/Make.defs b/configs/olimex-stm32-e407/discover/Make.defs
new file mode 100644
index 0000000000..968dc2167b
--- /dev/null
+++ b/configs/olimex-stm32-e407/discover/Make.defs
@@ -0,0 +1,112 @@
+############################################################################
+# configs/olimex-stm32-e407/discover/Make.defs
+#
+# Copyright (C) 2011-2012, 2016 Gregory Nutt. All rights reserved.
+# Author: Gregory Nutt
+#
+# 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
+
+LDSCRIPT = ld.script
+
+ifeq ($(WINTOOL),y)
+ # Windows-native toolchains
+ DIRLINK = $(TOPDIR)/tools/copydir.sh
+ DIRUNLINK = $(TOPDIR)/tools/unlink.sh
+ MKDEP = $(TOPDIR)/tools/mkwindeps.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/$(LDSCRIPT)}"
+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/$(LDSCRIPT)
+endif
+
+CC = $(CROSSDEV)gcc
+CXX = $(CROSSDEV)g++
+CPP = $(CROSSDEV)gcc -E
+LD = $(CROSSDEV)ld
+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
+
+
+HOSTCC = gcc
+HOSTINCLUDES = -I.
+HOSTCFLAGS = -Wall -Wstrict-prototypes -Wshadow -Wundef -g -pipe
+HOSTLDFLAGS =
diff --git a/configs/olimex-stm32-e407/discover/defconfig b/configs/olimex-stm32-e407/discover/defconfig
new file mode 100644
index 0000000000..681313aec8
--- /dev/null
+++ b/configs/olimex-stm32-e407/discover/defconfig
@@ -0,0 +1,1298 @@
+#
+# Automatically generated file; DO NOT EDIT.
+# Nuttx/ Configuration
+#
+
+#
+# Build Setup
+#
+# CONFIG_EXPERIMENTAL is not set
+# CONFIG_DEFAULT_SMALL is not set
+CONFIG_HOST_LINUX=y
+# CONFIG_HOST_OSX is not set
+# CONFIG_HOST_WINDOWS is not set
+# CONFIG_HOST_OTHER is not set
+
+#
+# Build Configuration
+#
+CONFIG_APPS_DIR="../apps"
+CONFIG_BUILD_FLAT=y
+# CONFIG_BUILD_2PASS is not set
+
+#
+# Binary Output Formats
+#
+# CONFIG_RRLOAD_BINARY is not set
+CONFIG_INTELHEX_BINARY=y
+# CONFIG_MOTOROLA_SREC is not set
+CONFIG_RAW_BINARY=y
+# CONFIG_UBOOT_UIMAGE is not set
+
+#
+# Customize Header Files
+#
+# CONFIG_ARCH_STDINT_H is not set
+# CONFIG_ARCH_STDBOOL_H is not set
+# CONFIG_ARCH_MATH_H is not set
+# CONFIG_ARCH_FLOAT_H is not set
+# CONFIG_ARCH_STDARG_H is not set
+# CONFIG_ARCH_DEBUG_H is not set
+
+#
+# Debug Options
+#
+CONFIG_DEBUG_ALERT=y
+# CONFIG_DEBUG_FEATURES is not set
+CONFIG_ARCH_HAVE_STACKCHECK=y
+# CONFIG_STACK_COLORATION is not set
+CONFIG_ARCH_HAVE_HEAPCHECK=y
+# CONFIG_HEAP_COLORATION is not set
+CONFIG_DEBUG_SYMBOLS=y
+CONFIG_ARCH_HAVE_CUSTOMOPT=y
+# CONFIG_DEBUG_NOOPT is not set
+# CONFIG_DEBUG_CUSTOMOPT is not set
+CONFIG_DEBUG_FULLOPT=y
+
+#
+# System Type
+#
+CONFIG_ARCH_ARM=y
+# CONFIG_ARCH_AVR is not set
+# CONFIG_ARCH_HC is not set
+# CONFIG_ARCH_MIPS is not set
+# CONFIG_ARCH_RGMP is not set
+# CONFIG_ARCH_RENESAS is not set
+# CONFIG_ARCH_SIM is not set
+# CONFIG_ARCH_X86 is not set
+# CONFIG_ARCH_Z16 is not set
+# CONFIG_ARCH_Z80 is not set
+CONFIG_ARCH="arm"
+
+#
+# ARM Options
+#
+# CONFIG_ARCH_CHIP_A1X is not set
+# CONFIG_ARCH_CHIP_C5471 is not set
+# CONFIG_ARCH_CHIP_CALYPSO is not set
+# CONFIG_ARCH_CHIP_DM320 is not set
+# CONFIG_ARCH_CHIP_EFM32 is not set
+# CONFIG_ARCH_CHIP_IMX1 is not set
+# CONFIG_ARCH_CHIP_IMX6 is not set
+# CONFIG_ARCH_CHIP_KINETIS is not set
+# CONFIG_ARCH_CHIP_KL is not set
+# CONFIG_ARCH_CHIP_LM is not set
+# CONFIG_ARCH_CHIP_TIVA is not set
+# CONFIG_ARCH_CHIP_LPC11XX is not set
+# CONFIG_ARCH_CHIP_LPC17XX is not set
+# CONFIG_ARCH_CHIP_LPC214X is not set
+# CONFIG_ARCH_CHIP_LPC2378 is not set
+# CONFIG_ARCH_CHIP_LPC31XX is not set
+# CONFIG_ARCH_CHIP_LPC43XX is not set
+# CONFIG_ARCH_CHIP_NUC1XX is not set
+# CONFIG_ARCH_CHIP_SAMA5 is not set
+# CONFIG_ARCH_CHIP_SAMD is not set
+# CONFIG_ARCH_CHIP_SAML is not set
+# CONFIG_ARCH_CHIP_SAM34 is not set
+# CONFIG_ARCH_CHIP_SAMV7 is not set
+CONFIG_ARCH_CHIP_STM32=y
+# CONFIG_ARCH_CHIP_STM32F7 is not set
+# CONFIG_ARCH_CHIP_STM32L4 is not set
+# CONFIG_ARCH_CHIP_STR71X is not set
+# CONFIG_ARCH_CHIP_TMS570 is not set
+# CONFIG_ARCH_CHIP_MOXART is not set
+# CONFIG_ARCH_ARM7TDMI is not set
+# CONFIG_ARCH_ARM926EJS is not set
+# CONFIG_ARCH_ARM920T is not set
+# CONFIG_ARCH_CORTEXM0 is not set
+# CONFIG_ARCH_CORTEXM3 is not set
+CONFIG_ARCH_CORTEXM4=y
+# CONFIG_ARCH_CORTEXM7 is not set
+# CONFIG_ARCH_CORTEXA5 is not set
+# CONFIG_ARCH_CORTEXA8 is not set
+# CONFIG_ARCH_CORTEXA9 is not set
+# CONFIG_ARCH_CORTEXR4 is not set
+# CONFIG_ARCH_CORTEXR4F is not set
+# CONFIG_ARCH_CORTEXR5 is not set
+# CONFIG_ARCH_CORTEX5F is not set
+# CONFIG_ARCH_CORTEXR7 is not set
+# CONFIG_ARCH_CORTEXR7F is not set
+CONFIG_ARCH_FAMILY="armv7-m"
+CONFIG_ARCH_CHIP="stm32"
+# CONFIG_ARM_TOOLCHAIN_IAR is not set
+CONFIG_ARM_TOOLCHAIN_GNU=y
+# CONFIG_ARMV7M_USEBASEPRI is not set
+CONFIG_ARCH_HAVE_CMNVECTOR=y
+# CONFIG_ARMV7M_CMNVECTOR is not set
+# CONFIG_ARMV7M_LAZYFPU is not set
+CONFIG_ARCH_HAVE_FPU=y
+# CONFIG_ARCH_HAVE_DPFPU is not set
+# CONFIG_ARCH_FPU is not set
+# CONFIG_ARCH_HAVE_TRUSTZONE is not set
+CONFIG_ARM_HAVE_MPU_UNIFIED=y
+# CONFIG_ARM_MPU is not set
+
+#
+# ARMV7M Configuration Options
+#
+# CONFIG_ARMV7M_HAVE_ICACHE is not set
+# CONFIG_ARMV7M_HAVE_DCACHE is not set
+# CONFIG_ARMV7M_HAVE_ITCM is not set
+# CONFIG_ARMV7M_HAVE_DTCM is not set
+# CONFIG_ARMV7M_TOOLCHAIN_IARL is not set
+CONFIG_ARMV7M_TOOLCHAIN_BUILDROOT=y
+# CONFIG_ARMV7M_TOOLCHAIN_CODEREDL is not set
+# CONFIG_ARMV7M_TOOLCHAIN_CODESOURCERYL is not set
+# CONFIG_ARMV7M_TOOLCHAIN_GNU_EABIL is not set
+# CONFIG_ARMV7M_OABI_TOOLCHAIN is not set
+CONFIG_ARMV7M_HAVE_STACKCHECK=y
+# CONFIG_ARMV7M_STACKCHECK is not set
+# CONFIG_ARMV7M_ITMSYSLOG is not set
+# CONFIG_SERIAL_TERMIOS is not set
+
+#
+# STM32 Configuration Options
+#
+# CONFIG_ARCH_CHIP_STM32L151C6 is not set
+# CONFIG_ARCH_CHIP_STM32L151C8 is not set
+# CONFIG_ARCH_CHIP_STM32L151CB is not set
+# CONFIG_ARCH_CHIP_STM32L151R6 is not set
+# CONFIG_ARCH_CHIP_STM32L151R8 is not set
+# CONFIG_ARCH_CHIP_STM32L151RB is not set
+# CONFIG_ARCH_CHIP_STM32L151V6 is not set
+# CONFIG_ARCH_CHIP_STM32L151V8 is not set
+# CONFIG_ARCH_CHIP_STM32L151VB is not set
+# CONFIG_ARCH_CHIP_STM32L152C6 is not set
+# CONFIG_ARCH_CHIP_STM32L152C8 is not set
+# CONFIG_ARCH_CHIP_STM32L152CB is not set
+# CONFIG_ARCH_CHIP_STM32L152R6 is not set
+# CONFIG_ARCH_CHIP_STM32L152R8 is not set
+# CONFIG_ARCH_CHIP_STM32L152RB is not set
+# CONFIG_ARCH_CHIP_STM32L152V6 is not set
+# CONFIG_ARCH_CHIP_STM32L152V8 is not set
+# CONFIG_ARCH_CHIP_STM32L152VB is not set
+# CONFIG_ARCH_CHIP_STM32L162ZD is not set
+# CONFIG_ARCH_CHIP_STM32L162VE is not set
+# CONFIG_ARCH_CHIP_STM32F100C8 is not set
+# CONFIG_ARCH_CHIP_STM32F100CB is not set
+# CONFIG_ARCH_CHIP_STM32F100R8 is not set
+# CONFIG_ARCH_CHIP_STM32F100RB is not set
+# CONFIG_ARCH_CHIP_STM32F100RC is not set
+# CONFIG_ARCH_CHIP_STM32F100RD is not set
+# CONFIG_ARCH_CHIP_STM32F100RE is not set
+# CONFIG_ARCH_CHIP_STM32F100V8 is not set
+# CONFIG_ARCH_CHIP_STM32F100VB is not set
+# CONFIG_ARCH_CHIP_STM32F100VC is not set
+# CONFIG_ARCH_CHIP_STM32F100VD is not set
+# CONFIG_ARCH_CHIP_STM32F100VE is not set
+# CONFIG_ARCH_CHIP_STM32F102CB is not set
+# CONFIG_ARCH_CHIP_STM32F103T8 is not set
+# CONFIG_ARCH_CHIP_STM32F103TB is not set
+# CONFIG_ARCH_CHIP_STM32F103C4 is not set
+# CONFIG_ARCH_CHIP_STM32F103C8 is not set
+# CONFIG_ARCH_CHIP_STM32F103CB is not set
+# CONFIG_ARCH_CHIP_STM32F103R8 is not set
+# CONFIG_ARCH_CHIP_STM32F103RB is not set
+# CONFIG_ARCH_CHIP_STM32F103RC is not set
+# CONFIG_ARCH_CHIP_STM32F103RD is not set
+# CONFIG_ARCH_CHIP_STM32F103RE is not set
+# CONFIG_ARCH_CHIP_STM32F103RG is not set
+# CONFIG_ARCH_CHIP_STM32F103V8 is not set
+# CONFIG_ARCH_CHIP_STM32F103VB is not set
+# CONFIG_ARCH_CHIP_STM32F103VC is not set
+# CONFIG_ARCH_CHIP_STM32F103VE is not set
+# CONFIG_ARCH_CHIP_STM32F103ZE is not set
+# CONFIG_ARCH_CHIP_STM32F105VB is not set
+# CONFIG_ARCH_CHIP_STM32F105RB is not set
+# CONFIG_ARCH_CHIP_STM32F107VC is not set
+# CONFIG_ARCH_CHIP_STM32F205RG is not set
+# CONFIG_ARCH_CHIP_STM32F207IG is not set
+# CONFIG_ARCH_CHIP_STM32F207ZE is not set
+# CONFIG_ARCH_CHIP_STM32F302K6 is not set
+# CONFIG_ARCH_CHIP_STM32F302K8 is not set
+# CONFIG_ARCH_CHIP_STM32F302CB is not set
+# CONFIG_ARCH_CHIP_STM32F302CC is not set
+# CONFIG_ARCH_CHIP_STM32F302RB is not set
+# CONFIG_ARCH_CHIP_STM32F302RC is not set
+# CONFIG_ARCH_CHIP_STM32F302VB is not set
+# CONFIG_ARCH_CHIP_STM32F302VC is not set
+# CONFIG_ARCH_CHIP_STM32F303K6 is not set
+# CONFIG_ARCH_CHIP_STM32F303K8 is not set
+# CONFIG_ARCH_CHIP_STM32F303C6 is not set
+# CONFIG_ARCH_CHIP_STM32F303C8 is not set
+# CONFIG_ARCH_CHIP_STM32F303CB is not set
+# CONFIG_ARCH_CHIP_STM32F303CC is not set
+# CONFIG_ARCH_CHIP_STM32F303RB is not set
+# CONFIG_ARCH_CHIP_STM32F303RC is not set
+# CONFIG_ARCH_CHIP_STM32F303RD is not set
+# CONFIG_ARCH_CHIP_STM32F303RE is not set
+# CONFIG_ARCH_CHIP_STM32F303VB is not set
+# CONFIG_ARCH_CHIP_STM32F303VC is not set
+# CONFIG_ARCH_CHIP_STM32F372C8 is not set
+# CONFIG_ARCH_CHIP_STM32F372R8 is not set
+# CONFIG_ARCH_CHIP_STM32F372V8 is not set
+# CONFIG_ARCH_CHIP_STM32F372CB is not set
+# CONFIG_ARCH_CHIP_STM32F372RB is not set
+# CONFIG_ARCH_CHIP_STM32F372VB is not set
+# CONFIG_ARCH_CHIP_STM32F372CC is not set
+# CONFIG_ARCH_CHIP_STM32F372RC is not set
+# CONFIG_ARCH_CHIP_STM32F372VC is not set
+# CONFIG_ARCH_CHIP_STM32F373C8 is not set
+# CONFIG_ARCH_CHIP_STM32F373R8 is not set
+# CONFIG_ARCH_CHIP_STM32F373V8 is not set
+# CONFIG_ARCH_CHIP_STM32F373CB is not set
+# CONFIG_ARCH_CHIP_STM32F373RB is not set
+# CONFIG_ARCH_CHIP_STM32F373VB is not set
+# CONFIG_ARCH_CHIP_STM32F373CC is not set
+# CONFIG_ARCH_CHIP_STM32F373RC is not set
+# CONFIG_ARCH_CHIP_STM32F373VC is not set
+# CONFIG_ARCH_CHIP_STM32F401RE is not set
+# CONFIG_ARCH_CHIP_STM32F411RE is not set
+# CONFIG_ARCH_CHIP_STM32F411VE is not set
+# CONFIG_ARCH_CHIP_STM32F405RG is not set
+# CONFIG_ARCH_CHIP_STM32F405VG is not set
+# CONFIG_ARCH_CHIP_STM32F405ZG is not set
+# CONFIG_ARCH_CHIP_STM32F407VE is not set
+# CONFIG_ARCH_CHIP_STM32F407VG is not set
+# CONFIG_ARCH_CHIP_STM32F407ZE is not set
+CONFIG_ARCH_CHIP_STM32F407ZG=y
+# CONFIG_ARCH_CHIP_STM32F407IE is not set
+# CONFIG_ARCH_CHIP_STM32F407IG is not set
+# CONFIG_ARCH_CHIP_STM32F427V is not set
+# CONFIG_ARCH_CHIP_STM32F427Z is not set
+# CONFIG_ARCH_CHIP_STM32F427I is not set
+# CONFIG_ARCH_CHIP_STM32F429V is not set
+# CONFIG_ARCH_CHIP_STM32F429Z is not set
+# CONFIG_ARCH_CHIP_STM32F429I is not set
+# CONFIG_ARCH_CHIP_STM32F429B is not set
+# CONFIG_ARCH_CHIP_STM32F429N is not set
+# CONFIG_ARCH_CHIP_STM32F446M is not set
+# CONFIG_ARCH_CHIP_STM32F446R is not set
+# CONFIG_ARCH_CHIP_STM32F446V is not set
+# CONFIG_ARCH_CHIP_STM32F446Z is not set
+# CONFIG_ARCH_CHIP_STM32F469A is not set
+# CONFIG_ARCH_CHIP_STM32F469I is not set
+# CONFIG_ARCH_CHIP_STM32F469B is not set
+# CONFIG_ARCH_CHIP_STM32F469N is not set
+CONFIG_STM32_FLASH_CONFIG_DEFAULT=y
+# CONFIG_STM32_FLASH_CONFIG_4 is not set
+# CONFIG_STM32_FLASH_CONFIG_6 is not set
+# CONFIG_STM32_FLASH_CONFIG_8 is not set
+# CONFIG_STM32_FLASH_CONFIG_B is not set
+# CONFIG_STM32_FLASH_CONFIG_C is not set
+# CONFIG_STM32_FLASH_CONFIG_D is not set
+# CONFIG_STM32_FLASH_CONFIG_E is not set
+# CONFIG_STM32_FLASH_CONFIG_F is not set
+# CONFIG_STM32_FLASH_CONFIG_G is not set
+# CONFIG_STM32_FLASH_CONFIG_I is not set
+# CONFIG_STM32_STM32L15XX is not set
+# CONFIG_STM32_ENERGYLITE is not set
+# CONFIG_STM32_STM32F10XX is not set
+# CONFIG_STM32_VALUELINE is not set
+# CONFIG_STM32_CONNECTIVITYLINE is not set
+# CONFIG_STM32_PERFORMANCELINE is not set
+# CONFIG_STM32_USBACCESSLINE is not set
+# CONFIG_STM32_HIGHDENSITY is not set
+# CONFIG_STM32_MEDIUMDENSITY is not set
+# CONFIG_STM32_LOWDENSITY is not set
+# CONFIG_STM32_STM32F20XX is not set
+# CONFIG_STM32_STM32F205 is not set
+# CONFIG_STM32_STM32F207 is not set
+# CONFIG_STM32_STM32F30XX is not set
+# CONFIG_STM32_STM32F302 is not set
+# CONFIG_STM32_STM32F303 is not set
+# CONFIG_STM32_STM32F37XX is not set
+CONFIG_STM32_STM32F40XX=y
+# CONFIG_STM32_STM32F401 is not set
+# CONFIG_STM32_STM32F411 is not set
+# CONFIG_STM32_STM32F405 is not set
+CONFIG_STM32_STM32F407=y
+# CONFIG_STM32_STM32F427 is not set
+# CONFIG_STM32_STM32F429 is not set
+# CONFIG_STM32_STM32F446 is not set
+# CONFIG_STM32_STM32F469 is not set
+# CONFIG_STM32_DFU is not set
+
+#
+# STM32 Peripheral Support
+#
+CONFIG_STM32_HAVE_CCM=y
+# CONFIG_STM32_HAVE_USBDEV is not set
+CONFIG_STM32_HAVE_OTGFS=y
+CONFIG_STM32_HAVE_FSMC=y
+# CONFIG_STM32_HAVE_LTDC is not set
+CONFIG_STM32_HAVE_USART3=y
+CONFIG_STM32_HAVE_UART4=y
+CONFIG_STM32_HAVE_UART5=y
+CONFIG_STM32_HAVE_USART6=y
+# CONFIG_STM32_HAVE_UART7 is not set
+# CONFIG_STM32_HAVE_UART8 is not set
+CONFIG_STM32_HAVE_TIM1=y
+CONFIG_STM32_HAVE_TIM2=y
+CONFIG_STM32_HAVE_TIM3=y
+CONFIG_STM32_HAVE_TIM4=y
+CONFIG_STM32_HAVE_TIM5=y
+CONFIG_STM32_HAVE_TIM6=y
+CONFIG_STM32_HAVE_TIM7=y
+CONFIG_STM32_HAVE_TIM8=y
+CONFIG_STM32_HAVE_TIM9=y
+CONFIG_STM32_HAVE_TIM10=y
+CONFIG_STM32_HAVE_TIM11=y
+CONFIG_STM32_HAVE_TIM12=y
+CONFIG_STM32_HAVE_TIM13=y
+CONFIG_STM32_HAVE_TIM14=y
+# CONFIG_STM32_HAVE_TIM15 is not set
+# CONFIG_STM32_HAVE_TIM16 is not set
+# CONFIG_STM32_HAVE_TIM17 is not set
+CONFIG_STM32_HAVE_ADC2=y
+CONFIG_STM32_HAVE_ADC3=y
+# CONFIG_STM32_HAVE_ADC4 is not set
+# CONFIG_STM32_HAVE_ADC1_DMA is not set
+# CONFIG_STM32_HAVE_ADC2_DMA is not set
+# CONFIG_STM32_HAVE_ADC3_DMA is not set
+# CONFIG_STM32_HAVE_ADC4_DMA is not set
+CONFIG_STM32_HAVE_CAN1=y
+CONFIG_STM32_HAVE_CAN2=y
+CONFIG_STM32_HAVE_DAC1=y
+CONFIG_STM32_HAVE_DAC2=y
+CONFIG_STM32_HAVE_RNG=y
+CONFIG_STM32_HAVE_ETHMAC=y
+CONFIG_STM32_HAVE_I2C2=y
+CONFIG_STM32_HAVE_I2C3=y
+CONFIG_STM32_HAVE_SPI2=y
+CONFIG_STM32_HAVE_SPI3=y
+# CONFIG_STM32_HAVE_SPI4 is not set
+# CONFIG_STM32_HAVE_SPI5 is not set
+# CONFIG_STM32_HAVE_SPI6 is not set
+# CONFIG_STM32_HAVE_SAIPLL is not set
+# CONFIG_STM32_HAVE_I2SPLL is not set
+# CONFIG_STM32_ADC1 is not set
+# CONFIG_STM32_ADC2 is not set
+# CONFIG_STM32_ADC3 is not set
+# CONFIG_STM32_BKPSRAM is not set
+# CONFIG_STM32_CAN1 is not set
+# CONFIG_STM32_CAN2 is not set
+# CONFIG_STM32_CCMDATARAM is not set
+# CONFIG_STM32_CRC is not set
+# CONFIG_STM32_CRYP is not set
+# CONFIG_STM32_DMA1 is not set
+# CONFIG_STM32_DMA2 is not set
+# CONFIG_STM32_DAC1 is not set
+# CONFIG_STM32_DAC2 is not set
+# CONFIG_STM32_DCMI is not set
+CONFIG_STM32_ETHMAC=y
+# CONFIG_STM32_FSMC is not set
+# CONFIG_STM32_HASH is not set
+# CONFIG_STM32_I2C1 is not set
+# CONFIG_STM32_I2C2 is not set
+# CONFIG_STM32_I2C3 is not set
+# CONFIG_STM32_OTGFS is not set
+# CONFIG_STM32_OTGHS is not set
+CONFIG_STM32_PWR=y
+# CONFIG_STM32_RNG is not set
+# CONFIG_STM32_SDIO is not set
+# CONFIG_STM32_SPI1 is not set
+# CONFIG_STM32_SPI2 is not set
+# CONFIG_STM32_SPI3 is not set
+CONFIG_STM32_SYSCFG=y
+# CONFIG_STM32_TIM1 is not set
+# CONFIG_STM32_TIM2 is not set
+# CONFIG_STM32_TIM3 is not set
+# CONFIG_STM32_TIM4 is not set
+# CONFIG_STM32_TIM5 is not set
+# CONFIG_STM32_TIM6 is not set
+# CONFIG_STM32_TIM7 is not set
+# CONFIG_STM32_TIM8 is not set
+# CONFIG_STM32_TIM9 is not set
+# CONFIG_STM32_TIM10 is not set
+# CONFIG_STM32_TIM11 is not set
+# CONFIG_STM32_TIM12 is not set
+# CONFIG_STM32_TIM13 is not set
+# CONFIG_STM32_TIM14 is not set
+# CONFIG_STM32_USART1 is not set
+CONFIG_STM32_USART2=y
+# CONFIG_STM32_USART3 is not set
+# CONFIG_STM32_UART4 is not set
+# CONFIG_STM32_UART5 is not set
+# CONFIG_STM32_USART6 is not set
+# CONFIG_STM32_IWDG is not set
+# CONFIG_STM32_WWDG is not set
+# CONFIG_STM32_NOEXT_VECTORS is not set
+
+#
+# Alternate Pin Mapping
+#
+# CONFIG_STM32_FLASH_PREFETCH is not set
+# CONFIG_STM32_JTAG_DISABLE is not set
+CONFIG_STM32_JTAG_FULL_ENABLE=y
+# CONFIG_STM32_JTAG_NOJNTRST_ENABLE is not set
+# CONFIG_STM32_JTAG_SW_ENABLE is not set
+CONFIG_STM32_DISABLE_IDLE_SLEEP_DURING_DEBUG=y
+# CONFIG_STM32_FORCEPOWER is not set
+# CONFIG_ARCH_BOARD_STM32_CUSTOM_CLOCKCONFIG is not set
+# CONFIG_STM32_CCMEXCLUDE is not set
+
+#
+# Timer Configuration
+#
+# CONFIG_STM32_ONESHOT is not set
+# CONFIG_STM32_FREERUN is not set
+# CONFIG_STM32_TIM1_CAP is not set
+# CONFIG_STM32_TIM2_CAP is not set
+# CONFIG_STM32_TIM3_CAP is not set
+# CONFIG_STM32_TIM4_CAP is not set
+# CONFIG_STM32_TIM5_CAP is not set
+# CONFIG_STM32_TIM8_CAP is not set
+# CONFIG_STM32_TIM9_CAP is not set
+# CONFIG_STM32_TIM10_CAP is not set
+# CONFIG_STM32_TIM11_CAP is not set
+# CONFIG_STM32_TIM12_CAP is not set
+# CONFIG_STM32_TIM13_CAP is not set
+# CONFIG_STM32_TIM14_CAP is not set
+CONFIG_STM32_USART=y
+CONFIG_STM32_SERIALDRIVER=y
+
+#
+# U[S]ART Configuration
+#
+
+#
+# U[S]ART Device Configuration
+#
+CONFIG_STM32_USART2_SERIALDRIVER=y
+# CONFIG_STM32_USART2_1WIREDRIVER is not set
+# CONFIG_USART2_RS485 is not set
+
+#
+# Serial Driver Configuration
+#
+# CONFIG_SERIAL_DISABLE_REORDERING is not set
+# CONFIG_STM32_FLOWCONTROL_BROKEN is not set
+# CONFIG_STM32_USART_BREAKS is not set
+# CONFIG_STM32_USART_SINGLEWIRE is not set
+# CONFIG_STM32_HAVE_RTC_COUNTER is not set
+# CONFIG_STM32_HAVE_RTC_SUBSECONDS is not set
+
+#
+# Ethernet MAC configuration
+#
+CONFIG_STM32_PHYADDR=0
+# CONFIG_STM32_PHYINIT is not set
+# CONFIG_STM32_MII is not set
+CONFIG_STM32_AUTONEG=y
+CONFIG_STM32_PHYSR=31
+CONFIG_STM32_PHYSR_ALTCONFIG=y
+CONFIG_STM32_PHYSR_ALTMODE=0x001c
+CONFIG_STM32_PHYSR_10HD=0x0004
+CONFIG_STM32_PHYSR_100HD=0x0008
+CONFIG_STM32_PHYSR_10FD=0x0014
+CONFIG_STM32_PHYSR_100FD=0x0018
+# CONFIG_STM32_ETH_PTP is not set
+CONFIG_STM32_RMII=y
+# CONFIG_STM32_RMII_MCO1 is not set
+# CONFIG_STM32_RMII_MCO2 is not set
+CONFIG_STM32_RMII_EXTCLK=y
+
+#
+# USB FS Host Configuration
+#
+
+#
+# USB HS Host Configuration
+#
+
+#
+# USB Host Debug Configuration
+#
+
+#
+# USB Device Configuration
+#
+
+#
+# Architecture Options
+#
+# CONFIG_ARCH_NOINTC is not set
+# CONFIG_ARCH_VECNOTIRQ is not set
+# CONFIG_ARCH_DMA is not set
+CONFIG_ARCH_HAVE_IRQPRIO=y
+# CONFIG_ARCH_L2CACHE is not set
+# CONFIG_ARCH_HAVE_COHERENT_DCACHE is not set
+# CONFIG_ARCH_HAVE_ADDRENV is not set
+# CONFIG_ARCH_NEED_ADDRENV_MAPPING is not set
+# CONFIG_ARCH_HAVE_MULTICPU is not set
+CONFIG_ARCH_HAVE_VFORK=y
+# CONFIG_ARCH_HAVE_MMU is not set
+CONFIG_ARCH_HAVE_MPU=y
+# CONFIG_ARCH_NAND_HWECC is not set
+# CONFIG_ARCH_HAVE_EXTCLK is not set
+# CONFIG_ARCH_HAVE_POWEROFF is not set
+CONFIG_ARCH_HAVE_RESET=y
+# CONFIG_ARCH_USE_MPU is not set
+# CONFIG_ARCH_IRQPRIO is not set
+CONFIG_ARCH_STACKDUMP=y
+# CONFIG_ENDIAN_BIG is not set
+# CONFIG_ARCH_IDLE_CUSTOM is not set
+# CONFIG_ARCH_HAVE_RAMFUNCS is not set
+CONFIG_ARCH_HAVE_RAMVECTORS=y
+# CONFIG_ARCH_RAMVECTORS is not set
+
+#
+# Board Settings
+#
+CONFIG_BOARD_LOOPSPERMSEC=16717
+# CONFIG_ARCH_CALIBRATION is not set
+
+#
+# Interrupt options
+#
+CONFIG_ARCH_HAVE_INTERRUPTSTACK=y
+CONFIG_ARCH_INTERRUPTSTACK=0
+CONFIG_ARCH_HAVE_HIPRI_INTERRUPT=y
+# CONFIG_ARCH_HIPRI_INTERRUPT is not set
+
+#
+# Boot options
+#
+# CONFIG_BOOT_RUNFROMEXTSRAM is not set
+CONFIG_BOOT_RUNFROMFLASH=y
+# CONFIG_BOOT_RUNFROMISRAM is not set
+# CONFIG_BOOT_RUNFROMSDRAM is not set
+# CONFIG_BOOT_COPYTORAM is not set
+
+#
+# Boot Memory Configuration
+#
+CONFIG_RAM_START=0x20000000
+CONFIG_RAM_SIZE=114688
+# CONFIG_ARCH_HAVE_SDRAM is not set
+
+#
+# Board Selection
+#
+# CONFIG_ARCH_BOARD_OLIMEX_STM32H407 is not set
+CONFIG_ARCH_BOARD_OLIMEX_STM32E407=y
+# CONFIG_ARCH_BOARD_CUSTOM is not set
+CONFIG_ARCH_BOARD="olimex-stm32-e407"
+
+#
+# Common Board Options
+#
+CONFIG_ARCH_HAVE_LEDS=y
+CONFIG_ARCH_LEDS=y
+CONFIG_ARCH_HAVE_BUTTONS=y
+CONFIG_ARCH_BUTTONS=y
+CONFIG_ARCH_HAVE_IRQBUTTONS=y
+# CONFIG_ARCH_IRQBUTTONS is not set
+
+#
+# Board-Specific Options
+#
+# CONFIG_BOARD_CRASHDUMP is not set
+# CONFIG_LIB_BOARDCTL is not set
+
+#
+# RTOS Features
+#
+CONFIG_DISABLE_OS_API=y
+# CONFIG_DISABLE_POSIX_TIMERS is not set
+# CONFIG_DISABLE_PTHREAD is not set
+# CONFIG_DISABLE_SIGNALS is not set
+# CONFIG_DISABLE_MQUEUE is not set
+# CONFIG_DISABLE_ENVIRON is not set
+
+#
+# Clocks and Timers
+#
+CONFIG_ARCH_HAVE_TICKLESS=y
+# CONFIG_SCHED_TICKLESS is not set
+CONFIG_USEC_PER_TICK=10000
+# CONFIG_SYSTEM_TIME64 is not set
+# CONFIG_CLOCK_MONOTONIC is not set
+CONFIG_ARCH_HAVE_TIMEKEEPING=y
+# CONFIG_JULIAN_TIME is not set
+CONFIG_START_YEAR=2011
+CONFIG_START_MONTH=12
+CONFIG_START_DAY=6
+CONFIG_MAX_WDOGPARMS=2
+CONFIG_PREALLOC_WDOGS=16
+CONFIG_WDOG_INTRESERVE=4
+CONFIG_PREALLOC_TIMERS=4
+
+#
+# Tasks and Scheduling
+#
+# CONFIG_INIT_NONE is not set
+CONFIG_INIT_ENTRYPOINT=y
+# CONFIG_INIT_FILEPATH is not set
+CONFIG_USER_ENTRYPOINT="discover_main"
+CONFIG_RR_INTERVAL=200
+# CONFIG_SCHED_SPORADIC is not set
+CONFIG_TASK_NAME_SIZE=31
+CONFIG_MAX_TASKS=16
+# CONFIG_SCHED_HAVE_PARENT is not set
+CONFIG_SCHED_WAITPID=y
+
+#
+# Pthread Options
+#
+# CONFIG_MUTEX_TYPES is not set
+CONFIG_NPTHREAD_KEYS=4
+
+#
+# Performance Monitoring
+#
+# CONFIG_SCHED_CPULOAD is not set
+# CONFIG_SCHED_INSTRUMENTATION is not set
+
+#
+# Files and I/O
+#
+CONFIG_DEV_CONSOLE=y
+# CONFIG_FDCLONE_DISABLE is not set
+# CONFIG_FDCLONE_STDIO is not set
+CONFIG_SDCLONE_DISABLE=y
+CONFIG_NFILE_DESCRIPTORS=8
+CONFIG_NFILE_STREAMS=8
+CONFIG_NAME_MAX=32
+# CONFIG_PRIORITY_INHERITANCE is not set
+
+#
+# RTOS hooks
+#
+# CONFIG_BOARD_INITIALIZE is not set
+# CONFIG_SCHED_STARTHOOK is not set
+# CONFIG_SCHED_ATEXIT is not set
+# CONFIG_SCHED_ONEXIT is not set
+
+#
+# Signal Numbers
+#
+CONFIG_SIG_SIGUSR1=1
+CONFIG_SIG_SIGUSR2=2
+CONFIG_SIG_SIGALARM=3
+CONFIG_SIG_SIGCONDTIMEDOUT=16
+
+#
+# POSIX Message Queue Options
+#
+CONFIG_PREALLOC_MQ_MSGS=4
+CONFIG_MQ_MAXMSGSIZE=32
+# CONFIG_MODULE is not set
+
+#
+# Work queue support
+#
+# CONFIG_SCHED_WORKQUEUE is not set
+# CONFIG_SCHED_HPWORK is not set
+# CONFIG_SCHED_LPWORK is not set
+
+#
+# Stack and heap information
+#
+CONFIG_IDLETHREAD_STACKSIZE=1024
+CONFIG_USERMAIN_STACKSIZE=2048
+CONFIG_PTHREAD_STACK_MIN=256
+CONFIG_PTHREAD_STACK_DEFAULT=2048
+# CONFIG_LIB_SYSCALL is not set
+
+#
+# Device Drivers
+#
+# CONFIG_DISABLE_POLL is not set
+CONFIG_DEV_NULL=y
+# CONFIG_DEV_ZERO is not set
+# CONFIG_DEV_URANDOM is not set
+# CONFIG_DEV_LOOP is not set
+
+#
+# Buffering
+#
+# CONFIG_DRVR_WRITEBUFFER is not set
+# CONFIG_DRVR_READAHEAD is not set
+# CONFIG_RAMDISK is not set
+# CONFIG_CAN is not set
+# CONFIG_ARCH_HAVE_PWM_PULSECOUNT is not set
+# CONFIG_ARCH_HAVE_PWM_MULTICHAN is not set
+# CONFIG_PWM is not set
+CONFIG_ARCH_HAVE_I2CRESET=y
+# CONFIG_I2C is not set
+CONFIG_SPI=y
+# CONFIG_SPI_SLAVE is not set
+CONFIG_SPI_EXCHANGE=y
+# CONFIG_SPI_CMDDATA is not set
+# CONFIG_SPI_CALLBACK is not set
+# CONFIG_SPI_HWFEATURES is not set
+# CONFIG_ARCH_HAVE_SPI_CRCGENERATION is not set
+# CONFIG_ARCH_HAVE_SPI_CS_CONTROL is not set
+CONFIG_ARCH_HAVE_SPI_BITORDER=y
+# CONFIG_SPI_BITORDER is not set
+# CONFIG_SPI_CS_DELAY_CONTROL is not set
+# CONFIG_SPI_DRIVER is not set
+# CONFIG_SPI_BITBANG is not set
+# CONFIG_I2S is not set
+
+#
+# Timer Driver Support
+#
+# CONFIG_TIMER is not set
+# CONFIG_ONESHOT is not set
+# CONFIG_RTC is not set
+# CONFIG_WATCHDOG is not set
+# CONFIG_ANALOG is not set
+# CONFIG_AUDIO_DEVICES is not set
+# CONFIG_VIDEO_DEVICES is not set
+# CONFIG_BCH is not set
+# CONFIG_INPUT is not set
+
+#
+# IO Expander/GPIO Support
+#
+# CONFIG_IOEXPANDER is not set
+# CONFIG_DEV_GPIO is not set
+
+#
+# LCD Driver Support
+#
+# CONFIG_LCD is not set
+# CONFIG_SLCD is not set
+
+#
+# LED Support
+#
+# CONFIG_USERLED is not set
+# CONFIG_RGBLED is not set
+# CONFIG_PCA9635PW is not set
+# CONFIG_NCP5623C is not set
+# CONFIG_MMCSD is not set
+# CONFIG_MODEM is not set
+# CONFIG_MTD is not set
+# CONFIG_EEPROM is not set
+CONFIG_NETDEVICES=y
+
+#
+# General Ethernet MAC Driver Options
+#
+# CONFIG_NETDEV_LOOPBACK is not set
+# CONFIG_NETDEV_TELNET is not set
+# CONFIG_NETDEV_MULTINIC is not set
+# CONFIG_ARCH_HAVE_NETDEV_STATISTICS is not set
+# CONFIG_NETDEV_LATEINIT is not set
+
+#
+# External Ethernet MAC Device Support
+#
+# CONFIG_NET_DM90x0 is not set
+# CONFIG_ENC28J60 is not set
+# CONFIG_ENCX24J600 is not set
+# CONFIG_NET_E1000 is not set
+# CONFIG_NET_SLIP is not set
+# CONFIG_NET_FTMAC100 is not set
+# CONFIG_NET_VNET is not set
+
+#
+# External Ethernet PHY Device Support
+#
+# CONFIG_ARCH_PHY_INTERRUPT is not set
+# CONFIG_ETH0_PHY_NONE is not set
+# CONFIG_ETH0_PHY_AM79C874 is not set
+# CONFIG_ETH0_PHY_KS8721 is not set
+# CONFIG_ETH0_PHY_KSZ8041 is not set
+# CONFIG_ETH0_PHY_KSZ8051 is not set
+# CONFIG_ETH0_PHY_KSZ8061 is not set
+# CONFIG_ETH0_PHY_KSZ8081 is not set
+# CONFIG_ETH0_PHY_KSZ90x1 is not set
+# CONFIG_ETH0_PHY_DP83848C is not set
+CONFIG_ETH0_PHY_LAN8720=y
+# CONFIG_ETH0_PHY_LAN8740 is not set
+# CONFIG_ETH0_PHY_LAN8740A is not set
+# CONFIG_ETH0_PHY_LAN8742A is not set
+# CONFIG_ETH0_PHY_DM9161 is not set
+# CONFIG_PIPES is not set
+# CONFIG_PM is not set
+# CONFIG_POWER is not set
+# CONFIG_SENSORS is not set
+# CONFIG_SERCOMM_CONSOLE is not set
+CONFIG_SERIAL=y
+# CONFIG_DEV_LOWCONSOLE is not set
+# CONFIG_SERIAL_REMOVABLE is not set
+CONFIG_SERIAL_CONSOLE=y
+# CONFIG_16550_UART is not set
+# CONFIG_UART_SERIALDRIVER is not set
+# CONFIG_UART0_SERIALDRIVER is not set
+# CONFIG_UART1_SERIALDRIVER is not set
+# CONFIG_UART2_SERIALDRIVER is not set
+# CONFIG_UART3_SERIALDRIVER is not set
+# CONFIG_UART4_SERIALDRIVER is not set
+# CONFIG_UART5_SERIALDRIVER is not set
+# CONFIG_UART6_SERIALDRIVER is not set
+# CONFIG_UART7_SERIALDRIVER is not set
+# CONFIG_UART8_SERIALDRIVER is not set
+# CONFIG_SCI0_SERIALDRIVER is not set
+# CONFIG_SCI1_SERIALDRIVER is not set
+# CONFIG_USART0_SERIALDRIVER is not set
+# CONFIG_USART1_SERIALDRIVER is not set
+CONFIG_USART2_SERIALDRIVER=y
+# CONFIG_USART3_SERIALDRIVER is not set
+# CONFIG_USART4_SERIALDRIVER is not set
+# CONFIG_USART5_SERIALDRIVER is not set
+# CONFIG_USART6_SERIALDRIVER is not set
+# CONFIG_USART7_SERIALDRIVER is not set
+# CONFIG_USART8_SERIALDRIVER is not set
+# CONFIG_OTHER_UART_SERIALDRIVER is not set
+CONFIG_MCU_SERIAL=y
+CONFIG_STANDARD_SERIAL=y
+CONFIG_SERIAL_NPOLLWAITERS=2
+# CONFIG_SERIAL_IFLOWCONTROL is not set
+# CONFIG_SERIAL_OFLOWCONTROL is not set
+# CONFIG_SERIAL_DMA is not set
+CONFIG_ARCH_HAVE_SERIAL_TERMIOS=y
+CONFIG_USART2_SERIAL_CONSOLE=y
+# CONFIG_OTHER_SERIAL_CONSOLE is not set
+# CONFIG_NO_SERIAL_CONSOLE is not set
+
+#
+# USART2 Configuration
+#
+CONFIG_USART2_RXBUFSIZE=128
+CONFIG_USART2_TXBUFSIZE=128
+CONFIG_USART2_BAUD=115200
+CONFIG_USART2_BITS=8
+CONFIG_USART2_PARITY=0
+CONFIG_USART2_2STOP=0
+# CONFIG_USART2_IFLOWCONTROL is not set
+# CONFIG_USART2_OFLOWCONTROL is not set
+# CONFIG_USART2_DMA is not set
+# CONFIG_PSEUDOTERM is not set
+# CONFIG_USBDEV is not set
+# CONFIG_USBHOST is not set
+# CONFIG_HAVE_USBTRACE is not set
+# CONFIG_DRIVERS_WIRELESS is not set
+# CONFIG_DRIVERS_CONTACTLESS is not set
+
+#
+# System Logging
+#
+# CONFIG_ARCH_SYSLOG is not set
+# CONFIG_RAMLOG is not set
+# CONFIG_SYSLOG_INTBUFFER is not set
+# CONFIG_SYSLOG_TIMESTAMP is not set
+CONFIG_SYSLOG_SERIAL_CONSOLE=y
+# CONFIG_SYSLOG_CHAR is not set
+CONFIG_SYSLOG_CONSOLE=y
+# CONFIG_SYSLOG_NONE is not set
+# CONFIG_SYSLOG_FILE is not set
+# CONFIG_SYSLOG_CHARDEV is not set
+
+#
+# Networking Support
+#
+CONFIG_ARCH_HAVE_NET=y
+CONFIG_ARCH_HAVE_PHY=y
+CONFIG_NET=y
+# CONFIG_NET_NOINTS is not set
+# CONFIG_NET_PROMISCUOUS is not set
+
+#
+# Driver buffer configuration
+#
+CONFIG_NET_MULTIBUFFER=y
+CONFIG_NET_ETH_MTU=590
+CONFIG_NET_ETH_TCP_RECVWNDO=536
+CONFIG_NET_GUARDSIZE=2
+
+#
+# Data link support
+#
+# CONFIG_NET_MULTILINK is not set
+CONFIG_NET_ETHERNET=y
+# CONFIG_NET_LOOPBACK is not set
+# CONFIG_NET_TUN is not set
+
+#
+# Network Device Operations
+#
+# CONFIG_NETDEV_PHY_IOCTL is not set
+
+#
+# Internet Protocol Selection
+#
+CONFIG_NET_IPv4=y
+# CONFIG_NET_IPv6 is not set
+
+#
+# Socket Support
+#
+CONFIG_NSOCKET_DESCRIPTORS=10
+CONFIG_NET_NACTIVESOCKETS=16
+CONFIG_NET_SOCKOPTS=y
+CONFIG_NET_SOLINGER=y
+
+#
+# Raw Socket Support
+#
+# CONFIG_NET_PKT is not set
+
+#
+# Unix Domain Socket Support
+#
+# CONFIG_NET_LOCAL is not set
+
+#
+# TCP/IP Networking
+#
+CONFIG_NET_TCP=y
+# CONFIG_NET_TCPURGDATA is not set
+CONFIG_NET_TCP_CONNS=40
+CONFIG_NET_MAX_LISTENPORTS=40
+CONFIG_NET_TCP_READAHEAD=y
+# CONFIG_NET_TCP_WRITE_BUFFERS is not set
+CONFIG_NET_TCP_RECVDELAY=0
+CONFIG_NET_TCPBACKLOG=y
+# CONFIG_NET_TCP_SPLIT is not set
+# CONFIG_NET_SENDFILE is not set
+
+#
+# UDP Networking
+#
+CONFIG_NET_UDP=y
+CONFIG_NET_UDP_CHECKSUMS=y
+CONFIG_NET_UDP_CONNS=8
+CONFIG_NET_BROADCAST=y
+# CONFIG_NET_RXAVAIL is not set
+CONFIG_NET_UDP_READAHEAD=y
+
+#
+# ICMP Networking Support
+#
+CONFIG_NET_ICMP=y
+CONFIG_NET_ICMP_PING=y
+
+#
+# IGMPv2 Client Support
+#
+# CONFIG_NET_IGMP is not set
+
+#
+# ARP Configuration
+#
+CONFIG_NET_ARP=y
+CONFIG_NET_ARPTAB_SIZE=16
+CONFIG_NET_ARP_MAXAGE=120
+CONFIG_NET_ARP_IPIN=y
+# CONFIG_NET_ARP_SEND is not set
+
+#
+# Network I/O Buffer Support
+#
+CONFIG_NET_IOB=y
+CONFIG_IOB_NBUFFERS=24
+CONFIG_IOB_BUFSIZE=196
+CONFIG_IOB_NCHAINS=8
+# CONFIG_NET_ARCH_INCR32 is not set
+# CONFIG_NET_ARCH_CHKSUM is not set
+CONFIG_NET_STATISTICS=y
+
+#
+# Routing Table Configuration
+#
+# CONFIG_NET_ROUTE is not set
+CONFIG_NET_HOSTNAME=""
+
+#
+# Crypto API
+#
+# CONFIG_CRYPTO is not set
+
+#
+# File Systems
+#
+
+#
+# File system configuration
+#
+# CONFIG_DISABLE_MOUNTPOINT is not set
+# CONFIG_FS_AUTOMOUNTER is not set
+# CONFIG_DISABLE_PSEUDOFS_OPERATIONS is not set
+# CONFIG_FS_READABLE is not set
+# CONFIG_FS_WRITABLE is not set
+# CONFIG_FS_NAMED_SEMAPHORES is not set
+CONFIG_FS_MQUEUE_MPATH="/var/mqueue"
+# CONFIG_FS_RAMMAP is not set
+# CONFIG_FS_FAT is not set
+# CONFIG_NFS is not set
+# CONFIG_FS_NXFFS is not set
+# CONFIG_FS_ROMFS is not set
+# CONFIG_FS_TMPFS is not set
+# CONFIG_FS_SMARTFS is not set
+# CONFIG_FS_BINFS is not set
+# CONFIG_FS_PROCFS is not set
+# CONFIG_FS_UNIONFS is not set
+
+#
+# Graphics Support
+#
+# CONFIG_NX is not set
+
+#
+# Memory Management
+#
+# CONFIG_MM_SMALL is not set
+CONFIG_MM_REGIONS=2
+# CONFIG_ARCH_HAVE_HEAP2 is not set
+# CONFIG_GRAN is not set
+
+#
+# Audio Support
+#
+# CONFIG_AUDIO is not set
+
+#
+# Wireless Support
+#
+
+#
+# Binary Loader
+#
+# CONFIG_BINFMT_DISABLE is not set
+# CONFIG_BINFMT_EXEPATH is not set
+# CONFIG_NXFLAT is not set
+# CONFIG_ELF is not set
+CONFIG_BUILTIN=y
+# CONFIG_PIC is not set
+# CONFIG_SYMTAB_ORDEREDBYNAME is not set
+
+#
+# Library Routines
+#
+
+#
+# Standard C Library Options
+#
+CONFIG_STDIO_BUFFER_SIZE=64
+CONFIG_STDIO_LINEBUFFER=y
+CONFIG_NUNGET_CHARS=2
+CONFIG_LIB_HOMEDIR="/"
+# CONFIG_LIBM is not set
+# CONFIG_NOPRINTF_FIELDWIDTH is not set
+# CONFIG_LIBC_FLOATINGPOINT is not set
+CONFIG_LIBC_LONG_LONG=y
+# CONFIG_LIBC_IOCTL_VARIADIC is not set
+CONFIG_LIB_RAND_ORDER=1
+# CONFIG_EOL_IS_CR is not set
+# CONFIG_EOL_IS_LF is not set
+# CONFIG_EOL_IS_BOTH_CRLF is not set
+CONFIG_EOL_IS_EITHER_CRLF=y
+# CONFIG_LIBC_EXECFUNCS is not set
+CONFIG_POSIX_SPAWN_PROXY_STACKSIZE=1024
+CONFIG_TASK_SPAWN_DEFAULT_STACKSIZE=2048
+# CONFIG_LIBC_STRERROR is not set
+# CONFIG_LIBC_PERROR_STDOUT is not set
+CONFIG_ARCH_LOWPUTC=y
+# CONFIG_LIBC_LOCALTIME is not set
+# CONFIG_TIME_EXTENDED is not set
+CONFIG_LIB_SENDFILE_BUFSIZE=512
+# CONFIG_ARCH_ROMGETC is not set
+# CONFIG_ARCH_OPTIMIZED_FUNCTIONS is not set
+CONFIG_ARCH_HAVE_TLS=y
+# CONFIG_TLS is not set
+CONFIG_LIBC_NETDB=y
+CONFIG_NETDB_DNSCLIENT=y
+CONFIG_NETDB_DNSCLIENT_ENTRIES=8
+CONFIG_NETDB_DNSCLIENT_NAMESIZE=32
+CONFIG_NETDB_DNSCLIENT_LIFESEC=3600
+CONFIG_NETDB_DNSCLIENT_MAXRESPONSE=96
+# CONFIG_NETDB_DNSSERVER_NOADDR is not set
+CONFIG_NETDB_DNSSERVER_IPv4=y
+CONFIG_NETDB_DNSSERVER_IPv4ADDR=0x0a000001
+
+#
+# Non-standard Library Support
+#
+# CONFIG_LIB_CRC64_FAST is not set
+# CONFIG_LIB_KBDCODEC is not set
+# CONFIG_LIB_SLCDCODEC is not set
+# CONFIG_LIB_HEX2BIN is not set
+
+#
+# Basic CXX Support
+#
+# CONFIG_C99_BOOL8 is not set
+CONFIG_HAVE_CXX=y
+CONFIG_HAVE_CXXINITIALIZE=y
+# CONFIG_CXX_NEWLONG is not set
+
+#
+# uClibc++ Standard C++ Library
+#
+# CONFIG_UCLIBCXX is not set
+
+#
+# Application Configuration
+#
+
+#
+# NxWidgets/NxWM
+#
+
+#
+# Built-In Applications
+#
+CONFIG_BUILTIN_PROXY_STACKSIZE=1024
+
+#
+# CAN Utilities
+#
+
+#
+# Examples
+#
+# CONFIG_EXAMPLES_BUTTONS is not set
+# CONFIG_EXAMPLES_CHAT is not set
+# CONFIG_EXAMPLES_CONFIGDATA is not set
+# CONFIG_EXAMPLES_CXXTEST is not set
+# CONFIG_EXAMPLES_DHCPD is not set
+CONFIG_EXAMPLES_DISCOVER=y
+CONFIG_EXAMPLES_DISCOVER_DHCPC=y
+CONFIG_EXAMPLES_DISCOVER_NOMAC=y
+CONFIG_EXAMPLES_DISCOVER_DRIPADDR=0xc0a80101
+CONFIG_EXAMPLES_DISCOVER_NETMASK=0xffffff00
+# CONFIG_EXAMPLES_ELF is not set
+# CONFIG_EXAMPLES_FTPC is not set
+# CONFIG_EXAMPLES_FTPD is not set
+# CONFIG_EXAMPLES_HELLO is not set
+# CONFIG_EXAMPLES_HELLOXX is not set
+# CONFIG_EXAMPLES_HIDKBD is not set
+# CONFIG_EXAMPLES_IGMP is not set
+# CONFIG_EXAMPLES_JSON is not set
+# CONFIG_EXAMPLES_KEYPADTEST is not set
+# CONFIG_EXAMPLES_MEDIA is not set
+# CONFIG_EXAMPLES_MM is not set
+# CONFIG_EXAMPLES_MODBUS is not set
+# CONFIG_EXAMPLES_MOUNT is not set
+# CONFIG_EXAMPLES_NETTEST is not set
+# CONFIG_EXAMPLES_NRF24L01TERM is not set
+# CONFIG_EXAMPLES_NSH is not set
+# CONFIG_EXAMPLES_NULL is not set
+# CONFIG_EXAMPLES_NX is not set
+# CONFIG_EXAMPLES_NXFFS is not set
+# CONFIG_EXAMPLES_NXHELLO is not set
+# CONFIG_EXAMPLES_NXIMAGE is not set
+# CONFIG_EXAMPLES_NXLINES is not set
+# CONFIG_EXAMPLES_NXTERM is not set
+# CONFIG_EXAMPLES_NXTEXT is not set
+# CONFIG_EXAMPLES_OSTEST is not set
+# CONFIG_EXAMPLES_PCA9635 is not set
+# CONFIG_EXAMPLES_POSIXSPAWN is not set
+# CONFIG_EXAMPLES_PPPD is not set
+# CONFIG_EXAMPLES_RFID_READUID is not set
+# CONFIG_EXAMPLES_RGBLED is not set
+# CONFIG_EXAMPLES_RGMP is not set
+# CONFIG_EXAMPLES_SENDMAIL is not set
+# CONFIG_EXAMPLES_SERIALBLASTER is not set
+# CONFIG_EXAMPLES_SERIALRX is not set
+# CONFIG_EXAMPLES_SERLOOP is not set
+# CONFIG_EXAMPLES_SLCD is not set
+# CONFIG_EXAMPLES_SMART is not set
+# CONFIG_EXAMPLES_SMP is not set
+# CONFIG_EXAMPLES_TCPECHO is not set
+# CONFIG_EXAMPLES_TELNETD is not set
+# CONFIG_EXAMPLES_TIFF is not set
+# CONFIG_EXAMPLES_TOUCHSCREEN is not set
+# CONFIG_EXAMPLES_UDP is not set
+# CONFIG_EXAMPLES_UDPBLASTER is not set
+# CONFIG_EXAMPLES_USBTERM is not set
+# CONFIG_EXAMPLES_WATCHDOG is not set
+# CONFIG_EXAMPLES_WEBSERVER is not set
+# CONFIG_EXAMPLES_WGET is not set
+# CONFIG_EXAMPLES_XMLRPC is not set
+
+#
+# External
+#
+
+#
+# File System Utilities
+#
+# CONFIG_FSUTILS_INIFILE is not set
+
+#
+# GPS Utilities
+#
+# CONFIG_GPSUTILS_MINMEA_LIB is not set
+
+#
+# Graphics Support
+#
+# CONFIG_TIFF is not set
+# CONFIG_GRAPHICS_TRAVELER is not set
+
+#
+# Interpreters
+#
+# CONFIG_INTERPRETERS_FICL is not set
+# CONFIG_INTERPRETERS_MICROPYTHON is not set
+# CONFIG_INTERPRETERS_MINIBASIC is not set
+# CONFIG_INTERPRETERS_PCODE is not set
+
+#
+# FreeModBus
+#
+# CONFIG_MODBUS is not set
+
+#
+# Network Utilities
+#
+# CONFIG_NETUTILS_CHAT is not set
+# CONFIG_NETUTILS_CODECS is not set
+CONFIG_NETUTILS_DHCPC=y
+# CONFIG_NETUTILS_DHCPD is not set
+CONFIG_NETUTILS_DISCOVER=y
+CONFIG_DISCOVER_STACK_SIZE=1024
+CONFIG_DISCOVER_PRIORITY=50
+CONFIG_DISCOVER_PORT=96
+CONFIG_DISCOVER_INTERFACE="eth0"
+CONFIG_DISCOVER_DEVICE_CLASS=0xff
+CONFIG_DISCOVER_DESCR="NuttX"
+# CONFIG_NETUTILS_ESP8266 is not set
+# CONFIG_NETUTILS_FTPC is not set
+# CONFIG_NETUTILS_FTPD is not set
+# CONFIG_NETUTILS_JSON is not set
+CONFIG_NETUTILS_NETLIB=y
+# CONFIG_NETUTILS_NTPCLIENT is not set
+# CONFIG_NETUTILS_PPPD is not set
+# CONFIG_NETUTILS_SMTP is not set
+# CONFIG_NETUTILS_TELNETD is not set
+# CONFIG_NETUTILS_TFTPC is not set
+# CONFIG_NETUTILS_WEBCLIENT is not set
+# CONFIG_NETUTILS_WEBSERVER is not set
+# CONFIG_NETUTILS_XMLRPC is not set
+
+#
+# NSH Library
+#
+# CONFIG_NSH_LIBRARY is not set
+
+#
+# Platform-specific Support
+#
+# CONFIG_PLATFORM_CONFIGDATA is not set
+
+#
+# System Libraries and NSH Add-Ons
+#
+# CONFIG_SYSTEM_CLE is not set
+# CONFIG_SYSTEM_CUTERM is not set
+# CONFIG_SYSTEM_FREE is not set
+# CONFIG_SYSTEM_HEX2BIN is not set
+# CONFIG_SYSTEM_HEXED is not set
+# CONFIG_SYSTEM_INSTALL is not set
+# CONFIG_SYSTEM_NETDB is not set
+# CONFIG_SYSTEM_RAMTEST is not set
+# CONFIG_READLINE_HAVE_EXTMATCH is not set
+# CONFIG_SYSTEM_READLINE is not set
+# CONFIG_SYSTEM_SUDOKU is not set
+# CONFIG_SYSTEM_TEE is not set
+# CONFIG_SYSTEM_UBLOXMODEM is not set
+# CONFIG_SYSTEM_VI is not set
+# CONFIG_SYSTEM_ZMODEM is not set
diff --git a/configs/olimex-stm32-e407/discover/setenv.sh b/configs/olimex-stm32-e407/discover/setenv.sh
new file mode 100755
index 0000000000..528a4978e8
--- /dev/null
+++ b/configs/olimex-stm32-e407/discover/setenv.sh
@@ -0,0 +1,80 @@
+#!/bin/bash
+# configs/olimex-stm32-e407/discover/setenv.sh
+#
+# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved.
+# Author: Gregory Nutt
+#
+# 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.
+#
+
+if [ "$_" = "$0" ] ; then
+ echo "You must source this script, not run it!" 1>&2
+ exit 1
+fi
+
+WD=`pwd`
+if [ ! -x "setenv.sh" ]; then
+ echo "This script must be executed from the top-level NuttX build directory"
+ exit 1
+fi
+
+if [ -z "${PATH_ORIG}" ]; then
+ export PATH_ORIG="${PATH}"
+fi
+
+# This is the Cygwin path to the location where I installed the RIDE
+# toolchain under windows. You will also have to edit this if you install
+# the RIDE toolchain in any other location
+#export TOOLCHAIN_BIN="/cygdrive/c/Program Files (x86)/Raisonance/Ride/arm-gcc/bin"
+
+# This is the Cygwin path to the location where I installed the CodeSourcery
+# toolchain under windows. You will also have to edit this if you install
+# the CodeSourcery toolchain in any other location
+export TOOLCHAIN_BIN="/cygdrive/c/Program Files (x86)/CodeSourcery/Sourcery G++ Lite/bin"
+#export TOOLCHAIN_BIN="/cygdrive/c/Users/MyName/MentorGraphics/Sourcery_CodeBench_Lite_for_ARM_EABI/bin"
+
+# This is the location where I installed the ARM "GNU Tools for ARM Embedded Processors"
+# You can this free toolchain here https://launchpad.net/gcc-arm-embedded
+#export TOOLCHAIN_BIN="/cygdrive/c/Program Files (x86)/GNU Tools ARM Embedded/4.9 2015q2/bin"
+
+# These are the Cygwin paths to the locations where I installed the Atollic
+# toolchain under windows. You will also have to edit this if you install
+# the Atollic toolchain in any other location. /usr/bin is added before
+# the Atollic bin path because there is are binaries named gcc.exe and g++.exe
+# at those locations as well.
+#export TOOLCHAIN_BIN="/usr/bin:/cygdrive/c/Program Files (x86)/Atollic/TrueSTUDIO for ARM Pro 2.3.0/ARMTools/bin"
+#export TOOLCHAIN_BIN="/usr/bin:/cygdrive/c/Program Files (x86)/Atollic/TrueSTUDIO for STMicroelectronics STM32 Lite 2.3.0/ARMTools/bin"
+
+# This is the Cygwin path to the location where I build the buildroot
+# toolchain.
+#export TOOLCHAIN_BIN="${WD}/../buildroot/build_arm_nofpu/staging_dir/bin"
+
+# Add the path to the toolchain to the PATH variable
+export PATH="${TOOLCHAIN_BIN}:/sbin:/usr/sbin:${PATH_ORIG}"
+
+echo "PATH : ${PATH}"
diff --git a/configs/olimex-stm32-e407/include/board.h b/configs/olimex-stm32-e407/include/board.h
index d74fd06f76..b1dff5e69a 100644
--- a/configs/olimex-stm32-e407/include/board.h
+++ b/configs/olimex-stm32-e407/include/board.h
@@ -228,7 +228,7 @@
/* Ethernet *************************************************************************/
#if defined(CONFIG_STM32_ETHMAC)
-/* RMII interface to the LAN8720 PHY */
+/* RMII interface to the LAN8710 PHY (works with LAN8720 driver)*/
# ifndef CONFIG_STM32_RMII
# error CONFIG_STM32_RMII must be defined
diff --git a/configs/olimex-stm32-e407/netnsh/Make.defs b/configs/olimex-stm32-e407/netnsh/Make.defs
new file mode 100644
index 0000000000..78d74cf656
--- /dev/null
+++ b/configs/olimex-stm32-e407/netnsh/Make.defs
@@ -0,0 +1,112 @@
+############################################################################
+# configs/olimex-stm32-e407/netnsh/Make.defs
+#
+# Copyright (C) 2011-2012, 2016 Gregory Nutt. All rights reserved.
+# Author: Gregory Nutt
+#
+# 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
+
+LDSCRIPT = ld.script
+
+ifeq ($(WINTOOL),y)
+ # Windows-native toolchains
+ DIRLINK = $(TOPDIR)/tools/copydir.sh
+ DIRUNLINK = $(TOPDIR)/tools/unlink.sh
+ MKDEP = $(TOPDIR)/tools/mkwindeps.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/$(LDSCRIPT)}"
+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/$(LDSCRIPT)
+endif
+
+CC = $(CROSSDEV)gcc
+CXX = $(CROSSDEV)g++
+CPP = $(CROSSDEV)gcc -E
+LD = $(CROSSDEV)ld
+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
+
+
+HOSTCC = gcc
+HOSTINCLUDES = -I.
+HOSTCFLAGS = -Wall -Wstrict-prototypes -Wshadow -Wundef -g -pipe
+HOSTLDFLAGS =
diff --git a/configs/olimex-stm32-e407/netnsh/defconfig b/configs/olimex-stm32-e407/netnsh/defconfig
new file mode 100644
index 0000000000..4ee6b4b742
--- /dev/null
+++ b/configs/olimex-stm32-e407/netnsh/defconfig
@@ -0,0 +1,1429 @@
+#
+# Automatically generated file; DO NOT EDIT.
+# Nuttx/ Configuration
+#
+
+#
+# Build Setup
+#
+# CONFIG_EXPERIMENTAL is not set
+# CONFIG_DEFAULT_SMALL is not set
+CONFIG_HOST_LINUX=y
+# CONFIG_HOST_OSX is not set
+# CONFIG_HOST_WINDOWS is not set
+# CONFIG_HOST_OTHER is not set
+
+#
+# Build Configuration
+#
+CONFIG_APPS_DIR="../apps"
+CONFIG_BUILD_FLAT=y
+# CONFIG_BUILD_2PASS is not set
+
+#
+# Binary Output Formats
+#
+# CONFIG_RRLOAD_BINARY is not set
+CONFIG_INTELHEX_BINARY=y
+# CONFIG_MOTOROLA_SREC is not set
+CONFIG_RAW_BINARY=y
+# CONFIG_UBOOT_UIMAGE is not set
+
+#
+# Customize Header Files
+#
+# CONFIG_ARCH_STDINT_H is not set
+# CONFIG_ARCH_STDBOOL_H is not set
+# CONFIG_ARCH_MATH_H is not set
+# CONFIG_ARCH_FLOAT_H is not set
+# CONFIG_ARCH_STDARG_H is not set
+# CONFIG_ARCH_DEBUG_H is not set
+
+#
+# Debug Options
+#
+CONFIG_DEBUG_ALERT=y
+# CONFIG_DEBUG_FEATURES is not set
+CONFIG_ARCH_HAVE_STACKCHECK=y
+# CONFIG_STACK_COLORATION is not set
+CONFIG_ARCH_HAVE_HEAPCHECK=y
+# CONFIG_HEAP_COLORATION is not set
+CONFIG_DEBUG_SYMBOLS=y
+CONFIG_ARCH_HAVE_CUSTOMOPT=y
+# CONFIG_DEBUG_NOOPT is not set
+# CONFIG_DEBUG_CUSTOMOPT is not set
+CONFIG_DEBUG_FULLOPT=y
+
+#
+# System Type
+#
+CONFIG_ARCH_ARM=y
+# CONFIG_ARCH_AVR is not set
+# CONFIG_ARCH_HC is not set
+# CONFIG_ARCH_MIPS is not set
+# CONFIG_ARCH_RGMP is not set
+# CONFIG_ARCH_RENESAS is not set
+# CONFIG_ARCH_SIM is not set
+# CONFIG_ARCH_X86 is not set
+# CONFIG_ARCH_Z16 is not set
+# CONFIG_ARCH_Z80 is not set
+CONFIG_ARCH="arm"
+
+#
+# ARM Options
+#
+# CONFIG_ARCH_CHIP_A1X is not set
+# CONFIG_ARCH_CHIP_C5471 is not set
+# CONFIG_ARCH_CHIP_CALYPSO is not set
+# CONFIG_ARCH_CHIP_DM320 is not set
+# CONFIG_ARCH_CHIP_EFM32 is not set
+# CONFIG_ARCH_CHIP_IMX1 is not set
+# CONFIG_ARCH_CHIP_IMX6 is not set
+# CONFIG_ARCH_CHIP_KINETIS is not set
+# CONFIG_ARCH_CHIP_KL is not set
+# CONFIG_ARCH_CHIP_LM is not set
+# CONFIG_ARCH_CHIP_TIVA is not set
+# CONFIG_ARCH_CHIP_LPC11XX is not set
+# CONFIG_ARCH_CHIP_LPC17XX is not set
+# CONFIG_ARCH_CHIP_LPC214X is not set
+# CONFIG_ARCH_CHIP_LPC2378 is not set
+# CONFIG_ARCH_CHIP_LPC31XX is not set
+# CONFIG_ARCH_CHIP_LPC43XX is not set
+# CONFIG_ARCH_CHIP_NUC1XX is not set
+# CONFIG_ARCH_CHIP_SAMA5 is not set
+# CONFIG_ARCH_CHIP_SAMD is not set
+# CONFIG_ARCH_CHIP_SAML is not set
+# CONFIG_ARCH_CHIP_SAM34 is not set
+# CONFIG_ARCH_CHIP_SAMV7 is not set
+CONFIG_ARCH_CHIP_STM32=y
+# CONFIG_ARCH_CHIP_STM32F7 is not set
+# CONFIG_ARCH_CHIP_STM32L4 is not set
+# CONFIG_ARCH_CHIP_STR71X is not set
+# CONFIG_ARCH_CHIP_TMS570 is not set
+# CONFIG_ARCH_CHIP_MOXART is not set
+# CONFIG_ARCH_ARM7TDMI is not set
+# CONFIG_ARCH_ARM926EJS is not set
+# CONFIG_ARCH_ARM920T is not set
+# CONFIG_ARCH_CORTEXM0 is not set
+# CONFIG_ARCH_CORTEXM3 is not set
+CONFIG_ARCH_CORTEXM4=y
+# CONFIG_ARCH_CORTEXM7 is not set
+# CONFIG_ARCH_CORTEXA5 is not set
+# CONFIG_ARCH_CORTEXA8 is not set
+# CONFIG_ARCH_CORTEXA9 is not set
+# CONFIG_ARCH_CORTEXR4 is not set
+# CONFIG_ARCH_CORTEXR4F is not set
+# CONFIG_ARCH_CORTEXR5 is not set
+# CONFIG_ARCH_CORTEX5F is not set
+# CONFIG_ARCH_CORTEXR7 is not set
+# CONFIG_ARCH_CORTEXR7F is not set
+CONFIG_ARCH_FAMILY="armv7-m"
+CONFIG_ARCH_CHIP="stm32"
+# CONFIG_ARM_TOOLCHAIN_IAR is not set
+CONFIG_ARM_TOOLCHAIN_GNU=y
+# CONFIG_ARMV7M_USEBASEPRI is not set
+CONFIG_ARCH_HAVE_CMNVECTOR=y
+# CONFIG_ARMV7M_CMNVECTOR is not set
+# CONFIG_ARMV7M_LAZYFPU is not set
+CONFIG_ARCH_HAVE_FPU=y
+# CONFIG_ARCH_HAVE_DPFPU is not set
+# CONFIG_ARCH_FPU is not set
+# CONFIG_ARCH_HAVE_TRUSTZONE is not set
+CONFIG_ARM_HAVE_MPU_UNIFIED=y
+# CONFIG_ARM_MPU is not set
+
+#
+# ARMV7M Configuration Options
+#
+# CONFIG_ARMV7M_HAVE_ICACHE is not set
+# CONFIG_ARMV7M_HAVE_DCACHE is not set
+# CONFIG_ARMV7M_HAVE_ITCM is not set
+# CONFIG_ARMV7M_HAVE_DTCM is not set
+# CONFIG_ARMV7M_TOOLCHAIN_IARL is not set
+CONFIG_ARMV7M_TOOLCHAIN_BUILDROOT=y
+# CONFIG_ARMV7M_TOOLCHAIN_CODEREDL is not set
+# CONFIG_ARMV7M_TOOLCHAIN_CODESOURCERYL is not set
+# CONFIG_ARMV7M_TOOLCHAIN_GNU_EABIL is not set
+# CONFIG_ARMV7M_OABI_TOOLCHAIN is not set
+CONFIG_ARMV7M_HAVE_STACKCHECK=y
+# CONFIG_ARMV7M_STACKCHECK is not set
+# CONFIG_ARMV7M_ITMSYSLOG is not set
+# CONFIG_SERIAL_TERMIOS is not set
+
+#
+# STM32 Configuration Options
+#
+# CONFIG_ARCH_CHIP_STM32L151C6 is not set
+# CONFIG_ARCH_CHIP_STM32L151C8 is not set
+# CONFIG_ARCH_CHIP_STM32L151CB is not set
+# CONFIG_ARCH_CHIP_STM32L151R6 is not set
+# CONFIG_ARCH_CHIP_STM32L151R8 is not set
+# CONFIG_ARCH_CHIP_STM32L151RB is not set
+# CONFIG_ARCH_CHIP_STM32L151V6 is not set
+# CONFIG_ARCH_CHIP_STM32L151V8 is not set
+# CONFIG_ARCH_CHIP_STM32L151VB is not set
+# CONFIG_ARCH_CHIP_STM32L152C6 is not set
+# CONFIG_ARCH_CHIP_STM32L152C8 is not set
+# CONFIG_ARCH_CHIP_STM32L152CB is not set
+# CONFIG_ARCH_CHIP_STM32L152R6 is not set
+# CONFIG_ARCH_CHIP_STM32L152R8 is not set
+# CONFIG_ARCH_CHIP_STM32L152RB is not set
+# CONFIG_ARCH_CHIP_STM32L152V6 is not set
+# CONFIG_ARCH_CHIP_STM32L152V8 is not set
+# CONFIG_ARCH_CHIP_STM32L152VB is not set
+# CONFIG_ARCH_CHIP_STM32L162ZD is not set
+# CONFIG_ARCH_CHIP_STM32L162VE is not set
+# CONFIG_ARCH_CHIP_STM32F100C8 is not set
+# CONFIG_ARCH_CHIP_STM32F100CB is not set
+# CONFIG_ARCH_CHIP_STM32F100R8 is not set
+# CONFIG_ARCH_CHIP_STM32F100RB is not set
+# CONFIG_ARCH_CHIP_STM32F100RC is not set
+# CONFIG_ARCH_CHIP_STM32F100RD is not set
+# CONFIG_ARCH_CHIP_STM32F100RE is not set
+# CONFIG_ARCH_CHIP_STM32F100V8 is not set
+# CONFIG_ARCH_CHIP_STM32F100VB is not set
+# CONFIG_ARCH_CHIP_STM32F100VC is not set
+# CONFIG_ARCH_CHIP_STM32F100VD is not set
+# CONFIG_ARCH_CHIP_STM32F100VE is not set
+# CONFIG_ARCH_CHIP_STM32F102CB is not set
+# CONFIG_ARCH_CHIP_STM32F103T8 is not set
+# CONFIG_ARCH_CHIP_STM32F103TB is not set
+# CONFIG_ARCH_CHIP_STM32F103C4 is not set
+# CONFIG_ARCH_CHIP_STM32F103C8 is not set
+# CONFIG_ARCH_CHIP_STM32F103CB is not set
+# CONFIG_ARCH_CHIP_STM32F103R8 is not set
+# CONFIG_ARCH_CHIP_STM32F103RB is not set
+# CONFIG_ARCH_CHIP_STM32F103RC is not set
+# CONFIG_ARCH_CHIP_STM32F103RD is not set
+# CONFIG_ARCH_CHIP_STM32F103RE is not set
+# CONFIG_ARCH_CHIP_STM32F103RG is not set
+# CONFIG_ARCH_CHIP_STM32F103V8 is not set
+# CONFIG_ARCH_CHIP_STM32F103VB is not set
+# CONFIG_ARCH_CHIP_STM32F103VC is not set
+# CONFIG_ARCH_CHIP_STM32F103VE is not set
+# CONFIG_ARCH_CHIP_STM32F103ZE is not set
+# CONFIG_ARCH_CHIP_STM32F105VB is not set
+# CONFIG_ARCH_CHIP_STM32F105RB is not set
+# CONFIG_ARCH_CHIP_STM32F107VC is not set
+# CONFIG_ARCH_CHIP_STM32F205RG is not set
+# CONFIG_ARCH_CHIP_STM32F207IG is not set
+# CONFIG_ARCH_CHIP_STM32F207ZE is not set
+# CONFIG_ARCH_CHIP_STM32F302K6 is not set
+# CONFIG_ARCH_CHIP_STM32F302K8 is not set
+# CONFIG_ARCH_CHIP_STM32F302CB is not set
+# CONFIG_ARCH_CHIP_STM32F302CC is not set
+# CONFIG_ARCH_CHIP_STM32F302RB is not set
+# CONFIG_ARCH_CHIP_STM32F302RC is not set
+# CONFIG_ARCH_CHIP_STM32F302VB is not set
+# CONFIG_ARCH_CHIP_STM32F302VC is not set
+# CONFIG_ARCH_CHIP_STM32F303K6 is not set
+# CONFIG_ARCH_CHIP_STM32F303K8 is not set
+# CONFIG_ARCH_CHIP_STM32F303C6 is not set
+# CONFIG_ARCH_CHIP_STM32F303C8 is not set
+# CONFIG_ARCH_CHIP_STM32F303CB is not set
+# CONFIG_ARCH_CHIP_STM32F303CC is not set
+# CONFIG_ARCH_CHIP_STM32F303RB is not set
+# CONFIG_ARCH_CHIP_STM32F303RC is not set
+# CONFIG_ARCH_CHIP_STM32F303RD is not set
+# CONFIG_ARCH_CHIP_STM32F303RE is not set
+# CONFIG_ARCH_CHIP_STM32F303VB is not set
+# CONFIG_ARCH_CHIP_STM32F303VC is not set
+# CONFIG_ARCH_CHIP_STM32F372C8 is not set
+# CONFIG_ARCH_CHIP_STM32F372R8 is not set
+# CONFIG_ARCH_CHIP_STM32F372V8 is not set
+# CONFIG_ARCH_CHIP_STM32F372CB is not set
+# CONFIG_ARCH_CHIP_STM32F372RB is not set
+# CONFIG_ARCH_CHIP_STM32F372VB is not set
+# CONFIG_ARCH_CHIP_STM32F372CC is not set
+# CONFIG_ARCH_CHIP_STM32F372RC is not set
+# CONFIG_ARCH_CHIP_STM32F372VC is not set
+# CONFIG_ARCH_CHIP_STM32F373C8 is not set
+# CONFIG_ARCH_CHIP_STM32F373R8 is not set
+# CONFIG_ARCH_CHIP_STM32F373V8 is not set
+# CONFIG_ARCH_CHIP_STM32F373CB is not set
+# CONFIG_ARCH_CHIP_STM32F373RB is not set
+# CONFIG_ARCH_CHIP_STM32F373VB is not set
+# CONFIG_ARCH_CHIP_STM32F373CC is not set
+# CONFIG_ARCH_CHIP_STM32F373RC is not set
+# CONFIG_ARCH_CHIP_STM32F373VC is not set
+# CONFIG_ARCH_CHIP_STM32F401RE is not set
+# CONFIG_ARCH_CHIP_STM32F411RE is not set
+# CONFIG_ARCH_CHIP_STM32F411VE is not set
+# CONFIG_ARCH_CHIP_STM32F405RG is not set
+# CONFIG_ARCH_CHIP_STM32F405VG is not set
+# CONFIG_ARCH_CHIP_STM32F405ZG is not set
+# CONFIG_ARCH_CHIP_STM32F407VE is not set
+# CONFIG_ARCH_CHIP_STM32F407VG is not set
+# CONFIG_ARCH_CHIP_STM32F407ZE is not set
+CONFIG_ARCH_CHIP_STM32F407ZG=y
+# CONFIG_ARCH_CHIP_STM32F407IE is not set
+# CONFIG_ARCH_CHIP_STM32F407IG is not set
+# CONFIG_ARCH_CHIP_STM32F427V is not set
+# CONFIG_ARCH_CHIP_STM32F427Z is not set
+# CONFIG_ARCH_CHIP_STM32F427I is not set
+# CONFIG_ARCH_CHIP_STM32F429V is not set
+# CONFIG_ARCH_CHIP_STM32F429Z is not set
+# CONFIG_ARCH_CHIP_STM32F429I is not set
+# CONFIG_ARCH_CHIP_STM32F429B is not set
+# CONFIG_ARCH_CHIP_STM32F429N is not set
+# CONFIG_ARCH_CHIP_STM32F446M is not set
+# CONFIG_ARCH_CHIP_STM32F446R is not set
+# CONFIG_ARCH_CHIP_STM32F446V is not set
+# CONFIG_ARCH_CHIP_STM32F446Z is not set
+# CONFIG_ARCH_CHIP_STM32F469A is not set
+# CONFIG_ARCH_CHIP_STM32F469I is not set
+# CONFIG_ARCH_CHIP_STM32F469B is not set
+# CONFIG_ARCH_CHIP_STM32F469N is not set
+CONFIG_STM32_FLASH_CONFIG_DEFAULT=y
+# CONFIG_STM32_FLASH_CONFIG_4 is not set
+# CONFIG_STM32_FLASH_CONFIG_6 is not set
+# CONFIG_STM32_FLASH_CONFIG_8 is not set
+# CONFIG_STM32_FLASH_CONFIG_B is not set
+# CONFIG_STM32_FLASH_CONFIG_C is not set
+# CONFIG_STM32_FLASH_CONFIG_D is not set
+# CONFIG_STM32_FLASH_CONFIG_E is not set
+# CONFIG_STM32_FLASH_CONFIG_F is not set
+# CONFIG_STM32_FLASH_CONFIG_G is not set
+# CONFIG_STM32_FLASH_CONFIG_I is not set
+# CONFIG_STM32_STM32L15XX is not set
+# CONFIG_STM32_ENERGYLITE is not set
+# CONFIG_STM32_STM32F10XX is not set
+# CONFIG_STM32_VALUELINE is not set
+# CONFIG_STM32_CONNECTIVITYLINE is not set
+# CONFIG_STM32_PERFORMANCELINE is not set
+# CONFIG_STM32_USBACCESSLINE is not set
+# CONFIG_STM32_HIGHDENSITY is not set
+# CONFIG_STM32_MEDIUMDENSITY is not set
+# CONFIG_STM32_LOWDENSITY is not set
+# CONFIG_STM32_STM32F20XX is not set
+# CONFIG_STM32_STM32F205 is not set
+# CONFIG_STM32_STM32F207 is not set
+# CONFIG_STM32_STM32F30XX is not set
+# CONFIG_STM32_STM32F302 is not set
+# CONFIG_STM32_STM32F303 is not set
+# CONFIG_STM32_STM32F37XX is not set
+CONFIG_STM32_STM32F40XX=y
+# CONFIG_STM32_STM32F401 is not set
+# CONFIG_STM32_STM32F411 is not set
+# CONFIG_STM32_STM32F405 is not set
+CONFIG_STM32_STM32F407=y
+# CONFIG_STM32_STM32F427 is not set
+# CONFIG_STM32_STM32F429 is not set
+# CONFIG_STM32_STM32F446 is not set
+# CONFIG_STM32_STM32F469 is not set
+# CONFIG_STM32_DFU is not set
+
+#
+# STM32 Peripheral Support
+#
+CONFIG_STM32_HAVE_CCM=y
+# CONFIG_STM32_HAVE_USBDEV is not set
+CONFIG_STM32_HAVE_OTGFS=y
+CONFIG_STM32_HAVE_FSMC=y
+# CONFIG_STM32_HAVE_LTDC is not set
+CONFIG_STM32_HAVE_USART3=y
+CONFIG_STM32_HAVE_UART4=y
+CONFIG_STM32_HAVE_UART5=y
+CONFIG_STM32_HAVE_USART6=y
+# CONFIG_STM32_HAVE_UART7 is not set
+# CONFIG_STM32_HAVE_UART8 is not set
+CONFIG_STM32_HAVE_TIM1=y
+CONFIG_STM32_HAVE_TIM2=y
+CONFIG_STM32_HAVE_TIM3=y
+CONFIG_STM32_HAVE_TIM4=y
+CONFIG_STM32_HAVE_TIM5=y
+CONFIG_STM32_HAVE_TIM6=y
+CONFIG_STM32_HAVE_TIM7=y
+CONFIG_STM32_HAVE_TIM8=y
+CONFIG_STM32_HAVE_TIM9=y
+CONFIG_STM32_HAVE_TIM10=y
+CONFIG_STM32_HAVE_TIM11=y
+CONFIG_STM32_HAVE_TIM12=y
+CONFIG_STM32_HAVE_TIM13=y
+CONFIG_STM32_HAVE_TIM14=y
+# CONFIG_STM32_HAVE_TIM15 is not set
+# CONFIG_STM32_HAVE_TIM16 is not set
+# CONFIG_STM32_HAVE_TIM17 is not set
+CONFIG_STM32_HAVE_ADC2=y
+CONFIG_STM32_HAVE_ADC3=y
+# CONFIG_STM32_HAVE_ADC4 is not set
+# CONFIG_STM32_HAVE_ADC1_DMA is not set
+# CONFIG_STM32_HAVE_ADC2_DMA is not set
+# CONFIG_STM32_HAVE_ADC3_DMA is not set
+# CONFIG_STM32_HAVE_ADC4_DMA is not set
+CONFIG_STM32_HAVE_CAN1=y
+CONFIG_STM32_HAVE_CAN2=y
+CONFIG_STM32_HAVE_DAC1=y
+CONFIG_STM32_HAVE_DAC2=y
+CONFIG_STM32_HAVE_RNG=y
+CONFIG_STM32_HAVE_ETHMAC=y
+CONFIG_STM32_HAVE_I2C2=y
+CONFIG_STM32_HAVE_I2C3=y
+CONFIG_STM32_HAVE_SPI2=y
+CONFIG_STM32_HAVE_SPI3=y
+# CONFIG_STM32_HAVE_SPI4 is not set
+# CONFIG_STM32_HAVE_SPI5 is not set
+# CONFIG_STM32_HAVE_SPI6 is not set
+# CONFIG_STM32_HAVE_SAIPLL is not set
+# CONFIG_STM32_HAVE_I2SPLL is not set
+# CONFIG_STM32_ADC1 is not set
+# CONFIG_STM32_ADC2 is not set
+# CONFIG_STM32_ADC3 is not set
+# CONFIG_STM32_BKPSRAM is not set
+# CONFIG_STM32_CAN1 is not set
+# CONFIG_STM32_CAN2 is not set
+# CONFIG_STM32_CCMDATARAM is not set
+# CONFIG_STM32_CRC is not set
+# CONFIG_STM32_CRYP is not set
+# CONFIG_STM32_DMA1 is not set
+# CONFIG_STM32_DMA2 is not set
+# CONFIG_STM32_DAC1 is not set
+# CONFIG_STM32_DAC2 is not set
+# CONFIG_STM32_DCMI is not set
+CONFIG_STM32_ETHMAC=y
+# CONFIG_STM32_FSMC is not set
+# CONFIG_STM32_HASH is not set
+# CONFIG_STM32_I2C1 is not set
+# CONFIG_STM32_I2C2 is not set
+# CONFIG_STM32_I2C3 is not set
+# CONFIG_STM32_OTGFS is not set
+# CONFIG_STM32_OTGHS is not set
+CONFIG_STM32_PWR=y
+# CONFIG_STM32_RNG is not set
+# CONFIG_STM32_SDIO is not set
+# CONFIG_STM32_SPI1 is not set
+# CONFIG_STM32_SPI2 is not set
+# CONFIG_STM32_SPI3 is not set
+CONFIG_STM32_SYSCFG=y
+# CONFIG_STM32_TIM1 is not set
+# CONFIG_STM32_TIM2 is not set
+# CONFIG_STM32_TIM3 is not set
+# CONFIG_STM32_TIM4 is not set
+# CONFIG_STM32_TIM5 is not set
+# CONFIG_STM32_TIM6 is not set
+# CONFIG_STM32_TIM7 is not set
+# CONFIG_STM32_TIM8 is not set
+# CONFIG_STM32_TIM9 is not set
+# CONFIG_STM32_TIM10 is not set
+# CONFIG_STM32_TIM11 is not set
+# CONFIG_STM32_TIM12 is not set
+# CONFIG_STM32_TIM13 is not set
+# CONFIG_STM32_TIM14 is not set
+# CONFIG_STM32_USART1 is not set
+CONFIG_STM32_USART2=y
+# CONFIG_STM32_USART3 is not set
+# CONFIG_STM32_UART4 is not set
+# CONFIG_STM32_UART5 is not set
+# CONFIG_STM32_USART6 is not set
+# CONFIG_STM32_IWDG is not set
+# CONFIG_STM32_WWDG is not set
+# CONFIG_STM32_NOEXT_VECTORS is not set
+
+#
+# Alternate Pin Mapping
+#
+# CONFIG_STM32_FLASH_PREFETCH is not set
+# CONFIG_STM32_JTAG_DISABLE is not set
+CONFIG_STM32_JTAG_FULL_ENABLE=y
+# CONFIG_STM32_JTAG_NOJNTRST_ENABLE is not set
+# CONFIG_STM32_JTAG_SW_ENABLE is not set
+CONFIG_STM32_DISABLE_IDLE_SLEEP_DURING_DEBUG=y
+# CONFIG_STM32_FORCEPOWER is not set
+# CONFIG_ARCH_BOARD_STM32_CUSTOM_CLOCKCONFIG is not set
+# CONFIG_STM32_CCMEXCLUDE is not set
+
+#
+# Timer Configuration
+#
+# CONFIG_STM32_ONESHOT is not set
+# CONFIG_STM32_FREERUN is not set
+# CONFIG_STM32_TIM1_CAP is not set
+# CONFIG_STM32_TIM2_CAP is not set
+# CONFIG_STM32_TIM3_CAP is not set
+# CONFIG_STM32_TIM4_CAP is not set
+# CONFIG_STM32_TIM5_CAP is not set
+# CONFIG_STM32_TIM8_CAP is not set
+# CONFIG_STM32_TIM9_CAP is not set
+# CONFIG_STM32_TIM10_CAP is not set
+# CONFIG_STM32_TIM11_CAP is not set
+# CONFIG_STM32_TIM12_CAP is not set
+# CONFIG_STM32_TIM13_CAP is not set
+# CONFIG_STM32_TIM14_CAP is not set
+CONFIG_STM32_USART=y
+CONFIG_STM32_SERIALDRIVER=y
+
+#
+# U[S]ART Configuration
+#
+
+#
+# U[S]ART Device Configuration
+#
+CONFIG_STM32_USART2_SERIALDRIVER=y
+# CONFIG_STM32_USART2_1WIREDRIVER is not set
+# CONFIG_USART2_RS485 is not set
+
+#
+# Serial Driver Configuration
+#
+# CONFIG_SERIAL_DISABLE_REORDERING is not set
+# CONFIG_STM32_FLOWCONTROL_BROKEN is not set
+# CONFIG_STM32_USART_BREAKS is not set
+# CONFIG_STM32_USART_SINGLEWIRE is not set
+# CONFIG_STM32_HAVE_RTC_COUNTER is not set
+# CONFIG_STM32_HAVE_RTC_SUBSECONDS is not set
+
+#
+# Ethernet MAC configuration
+#
+CONFIG_STM32_PHYADDR=0
+# CONFIG_STM32_PHYINIT is not set
+# CONFIG_STM32_MII is not set
+CONFIG_STM32_AUTONEG=y
+CONFIG_STM32_PHYSR=31
+CONFIG_STM32_PHYSR_ALTCONFIG=y
+CONFIG_STM32_PHYSR_ALTMODE=0x001c
+CONFIG_STM32_PHYSR_10HD=0x0004
+CONFIG_STM32_PHYSR_100HD=0x0008
+CONFIG_STM32_PHYSR_10FD=0x0014
+CONFIG_STM32_PHYSR_100FD=0x0018
+# CONFIG_STM32_ETH_PTP is not set
+CONFIG_STM32_RMII=y
+# CONFIG_STM32_RMII_MCO1 is not set
+# CONFIG_STM32_RMII_MCO2 is not set
+CONFIG_STM32_RMII_EXTCLK=y
+
+#
+# USB FS Host Configuration
+#
+
+#
+# USB HS Host Configuration
+#
+
+#
+# USB Host Debug Configuration
+#
+
+#
+# USB Device Configuration
+#
+
+#
+# Architecture Options
+#
+# CONFIG_ARCH_NOINTC is not set
+# CONFIG_ARCH_VECNOTIRQ is not set
+# CONFIG_ARCH_DMA is not set
+CONFIG_ARCH_HAVE_IRQPRIO=y
+# CONFIG_ARCH_L2CACHE is not set
+# CONFIG_ARCH_HAVE_COHERENT_DCACHE is not set
+# CONFIG_ARCH_HAVE_ADDRENV is not set
+# CONFIG_ARCH_NEED_ADDRENV_MAPPING is not set
+# CONFIG_ARCH_HAVE_MULTICPU is not set
+CONFIG_ARCH_HAVE_VFORK=y
+# CONFIG_ARCH_HAVE_MMU is not set
+CONFIG_ARCH_HAVE_MPU=y
+# CONFIG_ARCH_NAND_HWECC is not set
+# CONFIG_ARCH_HAVE_EXTCLK is not set
+# CONFIG_ARCH_HAVE_POWEROFF is not set
+CONFIG_ARCH_HAVE_RESET=y
+# CONFIG_ARCH_USE_MPU is not set
+# CONFIG_ARCH_IRQPRIO is not set
+CONFIG_ARCH_STACKDUMP=y
+# CONFIG_ENDIAN_BIG is not set
+# CONFIG_ARCH_IDLE_CUSTOM is not set
+# CONFIG_ARCH_HAVE_RAMFUNCS is not set
+CONFIG_ARCH_HAVE_RAMVECTORS=y
+# CONFIG_ARCH_RAMVECTORS is not set
+
+#
+# Board Settings
+#
+CONFIG_BOARD_LOOPSPERMSEC=16717
+# CONFIG_ARCH_CALIBRATION is not set
+
+#
+# Interrupt options
+#
+CONFIG_ARCH_HAVE_INTERRUPTSTACK=y
+CONFIG_ARCH_INTERRUPTSTACK=0
+CONFIG_ARCH_HAVE_HIPRI_INTERRUPT=y
+# CONFIG_ARCH_HIPRI_INTERRUPT is not set
+
+#
+# Boot options
+#
+# CONFIG_BOOT_RUNFROMEXTSRAM is not set
+CONFIG_BOOT_RUNFROMFLASH=y
+# CONFIG_BOOT_RUNFROMISRAM is not set
+# CONFIG_BOOT_RUNFROMSDRAM is not set
+# CONFIG_BOOT_COPYTORAM is not set
+
+#
+# Boot Memory Configuration
+#
+CONFIG_RAM_START=0x20000000
+CONFIG_RAM_SIZE=114688
+# CONFIG_ARCH_HAVE_SDRAM is not set
+
+#
+# Board Selection
+#
+# CONFIG_ARCH_BOARD_OLIMEX_STM32H407 is not set
+CONFIG_ARCH_BOARD_OLIMEX_STM32E407=y
+# CONFIG_ARCH_BOARD_CUSTOM is not set
+CONFIG_ARCH_BOARD="olimex-stm32-e407"
+
+#
+# Common Board Options
+#
+CONFIG_ARCH_HAVE_LEDS=y
+CONFIG_ARCH_LEDS=y
+CONFIG_ARCH_HAVE_BUTTONS=y
+CONFIG_ARCH_BUTTONS=y
+CONFIG_ARCH_HAVE_IRQBUTTONS=y
+# CONFIG_ARCH_IRQBUTTONS is not set
+
+#
+# Board-Specific Options
+#
+# CONFIG_BOARD_CRASHDUMP is not set
+# CONFIG_LIB_BOARDCTL is not set
+
+#
+# RTOS Features
+#
+CONFIG_DISABLE_OS_API=y
+# CONFIG_DISABLE_POSIX_TIMERS is not set
+# CONFIG_DISABLE_PTHREAD is not set
+# CONFIG_DISABLE_SIGNALS is not set
+# CONFIG_DISABLE_MQUEUE is not set
+# CONFIG_DISABLE_ENVIRON is not set
+
+#
+# Clocks and Timers
+#
+CONFIG_ARCH_HAVE_TICKLESS=y
+# CONFIG_SCHED_TICKLESS is not set
+CONFIG_USEC_PER_TICK=10000
+# CONFIG_SYSTEM_TIME64 is not set
+# CONFIG_CLOCK_MONOTONIC is not set
+CONFIG_ARCH_HAVE_TIMEKEEPING=y
+# CONFIG_JULIAN_TIME is not set
+CONFIG_START_YEAR=2011
+CONFIG_START_MONTH=12
+CONFIG_START_DAY=6
+CONFIG_MAX_WDOGPARMS=2
+CONFIG_PREALLOC_WDOGS=16
+CONFIG_WDOG_INTRESERVE=4
+CONFIG_PREALLOC_TIMERS=4
+
+#
+# Tasks and Scheduling
+#
+# CONFIG_INIT_NONE is not set
+CONFIG_INIT_ENTRYPOINT=y
+# CONFIG_INIT_FILEPATH is not set
+CONFIG_USER_ENTRYPOINT="nsh_main"
+CONFIG_RR_INTERVAL=200
+# CONFIG_SCHED_SPORADIC is not set
+CONFIG_TASK_NAME_SIZE=31
+CONFIG_MAX_TASKS=16
+# CONFIG_SCHED_HAVE_PARENT is not set
+CONFIG_SCHED_WAITPID=y
+
+#
+# Pthread Options
+#
+# CONFIG_MUTEX_TYPES is not set
+CONFIG_NPTHREAD_KEYS=4
+
+#
+# Performance Monitoring
+#
+# CONFIG_SCHED_CPULOAD is not set
+# CONFIG_SCHED_INSTRUMENTATION is not set
+
+#
+# Files and I/O
+#
+CONFIG_DEV_CONSOLE=y
+# CONFIG_FDCLONE_DISABLE is not set
+# CONFIG_FDCLONE_STDIO is not set
+CONFIG_SDCLONE_DISABLE=y
+CONFIG_NFILE_DESCRIPTORS=8
+CONFIG_NFILE_STREAMS=8
+CONFIG_NAME_MAX=32
+# CONFIG_PRIORITY_INHERITANCE is not set
+
+#
+# RTOS hooks
+#
+# CONFIG_BOARD_INITIALIZE is not set
+# CONFIG_SCHED_STARTHOOK is not set
+# CONFIG_SCHED_ATEXIT is not set
+# CONFIG_SCHED_ONEXIT is not set
+
+#
+# Signal Numbers
+#
+CONFIG_SIG_SIGUSR1=1
+CONFIG_SIG_SIGUSR2=2
+CONFIG_SIG_SIGALARM=3
+CONFIG_SIG_SIGCONDTIMEDOUT=16
+
+#
+# POSIX Message Queue Options
+#
+CONFIG_PREALLOC_MQ_MSGS=4
+CONFIG_MQ_MAXMSGSIZE=32
+# CONFIG_MODULE is not set
+
+#
+# Work queue support
+#
+# CONFIG_SCHED_WORKQUEUE is not set
+# CONFIG_SCHED_HPWORK is not set
+# CONFIG_SCHED_LPWORK is not set
+
+#
+# Stack and heap information
+#
+CONFIG_IDLETHREAD_STACKSIZE=1024
+CONFIG_USERMAIN_STACKSIZE=2048
+CONFIG_PTHREAD_STACK_MIN=256
+CONFIG_PTHREAD_STACK_DEFAULT=2048
+# CONFIG_LIB_SYSCALL is not set
+
+#
+# Device Drivers
+#
+# CONFIG_DISABLE_POLL is not set
+CONFIG_DEV_NULL=y
+# CONFIG_DEV_ZERO is not set
+# CONFIG_DEV_URANDOM is not set
+# CONFIG_DEV_LOOP is not set
+
+#
+# Buffering
+#
+# CONFIG_DRVR_WRITEBUFFER is not set
+# CONFIG_DRVR_READAHEAD is not set
+# CONFIG_RAMDISK is not set
+# CONFIG_CAN is not set
+# CONFIG_ARCH_HAVE_PWM_PULSECOUNT is not set
+# CONFIG_ARCH_HAVE_PWM_MULTICHAN is not set
+# CONFIG_PWM is not set
+CONFIG_ARCH_HAVE_I2CRESET=y
+# CONFIG_I2C is not set
+CONFIG_SPI=y
+# CONFIG_SPI_SLAVE is not set
+CONFIG_SPI_EXCHANGE=y
+# CONFIG_SPI_CMDDATA is not set
+# CONFIG_SPI_CALLBACK is not set
+# CONFIG_SPI_HWFEATURES is not set
+# CONFIG_ARCH_HAVE_SPI_CRCGENERATION is not set
+# CONFIG_ARCH_HAVE_SPI_CS_CONTROL is not set
+CONFIG_ARCH_HAVE_SPI_BITORDER=y
+# CONFIG_SPI_BITORDER is not set
+# CONFIG_SPI_CS_DELAY_CONTROL is not set
+# CONFIG_SPI_DRIVER is not set
+# CONFIG_SPI_BITBANG is not set
+# CONFIG_I2S is not set
+
+#
+# Timer Driver Support
+#
+# CONFIG_TIMER is not set
+# CONFIG_ONESHOT is not set
+# CONFIG_RTC is not set
+# CONFIG_WATCHDOG is not set
+# CONFIG_ANALOG is not set
+# CONFIG_AUDIO_DEVICES is not set
+# CONFIG_VIDEO_DEVICES is not set
+# CONFIG_BCH is not set
+# CONFIG_INPUT is not set
+
+#
+# IO Expander/GPIO Support
+#
+# CONFIG_IOEXPANDER is not set
+# CONFIG_DEV_GPIO is not set
+
+#
+# LCD Driver Support
+#
+# CONFIG_LCD is not set
+# CONFIG_SLCD is not set
+
+#
+# LED Support
+#
+# CONFIG_USERLED is not set
+# CONFIG_RGBLED is not set
+# CONFIG_PCA9635PW is not set
+# CONFIG_NCP5623C is not set
+# CONFIG_MMCSD is not set
+# CONFIG_MODEM is not set
+# CONFIG_MTD is not set
+# CONFIG_EEPROM is not set
+CONFIG_NETDEVICES=y
+
+#
+# General Ethernet MAC Driver Options
+#
+# CONFIG_NETDEV_LOOPBACK is not set
+CONFIG_NETDEV_TELNET=y
+CONFIG_TELNET_RXBUFFER_SIZE=256
+CONFIG_TELNET_TXBUFFER_SIZE=256
+# CONFIG_NETDEV_MULTINIC is not set
+# CONFIG_ARCH_HAVE_NETDEV_STATISTICS is not set
+# CONFIG_NETDEV_LATEINIT is not set
+
+#
+# External Ethernet MAC Device Support
+#
+# CONFIG_NET_DM90x0 is not set
+# CONFIG_ENC28J60 is not set
+# CONFIG_ENCX24J600 is not set
+# CONFIG_NET_E1000 is not set
+# CONFIG_NET_SLIP is not set
+# CONFIG_NET_FTMAC100 is not set
+# CONFIG_NET_VNET is not set
+
+#
+# External Ethernet PHY Device Support
+#
+# CONFIG_ARCH_PHY_INTERRUPT is not set
+# CONFIG_ETH0_PHY_NONE is not set
+# CONFIG_ETH0_PHY_AM79C874 is not set
+# CONFIG_ETH0_PHY_KS8721 is not set
+# CONFIG_ETH0_PHY_KSZ8041 is not set
+# CONFIG_ETH0_PHY_KSZ8051 is not set
+# CONFIG_ETH0_PHY_KSZ8061 is not set
+# CONFIG_ETH0_PHY_KSZ8081 is not set
+# CONFIG_ETH0_PHY_KSZ90x1 is not set
+# CONFIG_ETH0_PHY_DP83848C is not set
+CONFIG_ETH0_PHY_LAN8720=y
+# CONFIG_ETH0_PHY_LAN8740 is not set
+# CONFIG_ETH0_PHY_LAN8740A is not set
+# CONFIG_ETH0_PHY_LAN8742A is not set
+# CONFIG_ETH0_PHY_DM9161 is not set
+# CONFIG_PIPES is not set
+# CONFIG_PM is not set
+# CONFIG_POWER is not set
+# CONFIG_SENSORS is not set
+# CONFIG_SERCOMM_CONSOLE is not set
+CONFIG_SERIAL=y
+# CONFIG_DEV_LOWCONSOLE is not set
+# CONFIG_SERIAL_REMOVABLE is not set
+CONFIG_SERIAL_CONSOLE=y
+# CONFIG_16550_UART is not set
+# CONFIG_UART_SERIALDRIVER is not set
+# CONFIG_UART0_SERIALDRIVER is not set
+# CONFIG_UART1_SERIALDRIVER is not set
+# CONFIG_UART2_SERIALDRIVER is not set
+# CONFIG_UART3_SERIALDRIVER is not set
+# CONFIG_UART4_SERIALDRIVER is not set
+# CONFIG_UART5_SERIALDRIVER is not set
+# CONFIG_UART6_SERIALDRIVER is not set
+# CONFIG_UART7_SERIALDRIVER is not set
+# CONFIG_UART8_SERIALDRIVER is not set
+# CONFIG_SCI0_SERIALDRIVER is not set
+# CONFIG_SCI1_SERIALDRIVER is not set
+# CONFIG_USART0_SERIALDRIVER is not set
+# CONFIG_USART1_SERIALDRIVER is not set
+CONFIG_USART2_SERIALDRIVER=y
+# CONFIG_USART3_SERIALDRIVER is not set
+# CONFIG_USART4_SERIALDRIVER is not set
+# CONFIG_USART5_SERIALDRIVER is not set
+# CONFIG_USART6_SERIALDRIVER is not set
+# CONFIG_USART7_SERIALDRIVER is not set
+# CONFIG_USART8_SERIALDRIVER is not set
+# CONFIG_OTHER_UART_SERIALDRIVER is not set
+CONFIG_MCU_SERIAL=y
+CONFIG_STANDARD_SERIAL=y
+CONFIG_SERIAL_NPOLLWAITERS=2
+# CONFIG_SERIAL_IFLOWCONTROL is not set
+# CONFIG_SERIAL_OFLOWCONTROL is not set
+# CONFIG_SERIAL_DMA is not set
+CONFIG_ARCH_HAVE_SERIAL_TERMIOS=y
+CONFIG_USART2_SERIAL_CONSOLE=y
+# CONFIG_OTHER_SERIAL_CONSOLE is not set
+# CONFIG_NO_SERIAL_CONSOLE is not set
+
+#
+# USART2 Configuration
+#
+CONFIG_USART2_RXBUFSIZE=128
+CONFIG_USART2_TXBUFSIZE=128
+CONFIG_USART2_BAUD=115200
+CONFIG_USART2_BITS=8
+CONFIG_USART2_PARITY=0
+CONFIG_USART2_2STOP=0
+# CONFIG_USART2_IFLOWCONTROL is not set
+# CONFIG_USART2_OFLOWCONTROL is not set
+# CONFIG_USART2_DMA is not set
+# CONFIG_PSEUDOTERM is not set
+# CONFIG_USBDEV is not set
+# CONFIG_USBHOST is not set
+# CONFIG_HAVE_USBTRACE is not set
+# CONFIG_DRIVERS_WIRELESS is not set
+# CONFIG_DRIVERS_CONTACTLESS is not set
+
+#
+# System Logging
+#
+# CONFIG_ARCH_SYSLOG is not set
+# CONFIG_RAMLOG is not set
+# CONFIG_SYSLOG_INTBUFFER is not set
+# CONFIG_SYSLOG_TIMESTAMP is not set
+CONFIG_SYSLOG_SERIAL_CONSOLE=y
+# CONFIG_SYSLOG_CHAR is not set
+CONFIG_SYSLOG_CONSOLE=y
+# CONFIG_SYSLOG_NONE is not set
+# CONFIG_SYSLOG_FILE is not set
+# CONFIG_SYSLOG_CHARDEV is not set
+
+#
+# Networking Support
+#
+CONFIG_ARCH_HAVE_NET=y
+CONFIG_ARCH_HAVE_PHY=y
+CONFIG_NET=y
+# CONFIG_NET_NOINTS is not set
+# CONFIG_NET_PROMISCUOUS is not set
+
+#
+# Driver buffer configuration
+#
+CONFIG_NET_MULTIBUFFER=y
+CONFIG_NET_ETH_MTU=590
+CONFIG_NET_ETH_TCP_RECVWNDO=536
+CONFIG_NET_GUARDSIZE=2
+
+#
+# Data link support
+#
+# CONFIG_NET_MULTILINK is not set
+CONFIG_NET_ETHERNET=y
+# CONFIG_NET_LOOPBACK is not set
+# CONFIG_NET_TUN is not set
+
+#
+# Network Device Operations
+#
+# CONFIG_NETDEV_PHY_IOCTL is not set
+
+#
+# Internet Protocol Selection
+#
+CONFIG_NET_IPv4=y
+# CONFIG_NET_IPv6 is not set
+
+#
+# Socket Support
+#
+CONFIG_NSOCKET_DESCRIPTORS=10
+CONFIG_NET_NACTIVESOCKETS=16
+CONFIG_NET_SOCKOPTS=y
+CONFIG_NET_SOLINGER=y
+
+#
+# Raw Socket Support
+#
+# CONFIG_NET_PKT is not set
+
+#
+# Unix Domain Socket Support
+#
+# CONFIG_NET_LOCAL is not set
+
+#
+# TCP/IP Networking
+#
+CONFIG_NET_TCP=y
+# CONFIG_NET_TCPURGDATA is not set
+CONFIG_NET_TCP_CONNS=40
+CONFIG_NET_MAX_LISTENPORTS=40
+CONFIG_NET_TCP_READAHEAD=y
+# CONFIG_NET_TCP_WRITE_BUFFERS is not set
+CONFIG_NET_TCP_RECVDELAY=0
+CONFIG_NET_TCPBACKLOG=y
+# CONFIG_NET_TCP_SPLIT is not set
+# CONFIG_NET_SENDFILE is not set
+
+#
+# UDP Networking
+#
+CONFIG_NET_UDP=y
+CONFIG_NET_UDP_CHECKSUMS=y
+CONFIG_NET_UDP_CONNS=8
+CONFIG_NET_BROADCAST=y
+# CONFIG_NET_RXAVAIL is not set
+CONFIG_NET_UDP_READAHEAD=y
+
+#
+# ICMP Networking Support
+#
+CONFIG_NET_ICMP=y
+CONFIG_NET_ICMP_PING=y
+
+#
+# IGMPv2 Client Support
+#
+# CONFIG_NET_IGMP is not set
+
+#
+# ARP Configuration
+#
+CONFIG_NET_ARP=y
+CONFIG_NET_ARPTAB_SIZE=16
+CONFIG_NET_ARP_MAXAGE=120
+CONFIG_NET_ARP_IPIN=y
+# CONFIG_NET_ARP_SEND is not set
+
+#
+# Network I/O Buffer Support
+#
+CONFIG_NET_IOB=y
+CONFIG_IOB_NBUFFERS=24
+CONFIG_IOB_BUFSIZE=196
+CONFIG_IOB_NCHAINS=8
+# CONFIG_NET_ARCH_INCR32 is not set
+# CONFIG_NET_ARCH_CHKSUM is not set
+CONFIG_NET_STATISTICS=y
+
+#
+# Routing Table Configuration
+#
+# CONFIG_NET_ROUTE is not set
+CONFIG_NET_HOSTNAME=""
+
+#
+# Crypto API
+#
+# CONFIG_CRYPTO is not set
+
+#
+# File Systems
+#
+
+#
+# File system configuration
+#
+# CONFIG_DISABLE_MOUNTPOINT is not set
+# CONFIG_FS_AUTOMOUNTER is not set
+# CONFIG_DISABLE_PSEUDOFS_OPERATIONS is not set
+# CONFIG_FS_READABLE is not set
+# CONFIG_FS_WRITABLE is not set
+# CONFIG_FS_NAMED_SEMAPHORES is not set
+CONFIG_FS_MQUEUE_MPATH="/var/mqueue"
+# CONFIG_FS_RAMMAP is not set
+# CONFIG_FS_FAT is not set
+# CONFIG_NFS is not set
+# CONFIG_FS_NXFFS is not set
+# CONFIG_FS_ROMFS is not set
+# CONFIG_FS_TMPFS is not set
+# CONFIG_FS_SMARTFS is not set
+# CONFIG_FS_BINFS is not set
+# CONFIG_FS_PROCFS is not set
+# CONFIG_FS_UNIONFS is not set
+
+#
+# Graphics Support
+#
+# CONFIG_NX is not set
+
+#
+# Memory Management
+#
+# CONFIG_MM_SMALL is not set
+CONFIG_MM_REGIONS=2
+# CONFIG_ARCH_HAVE_HEAP2 is not set
+# CONFIG_GRAN is not set
+
+#
+# Audio Support
+#
+# CONFIG_AUDIO is not set
+
+#
+# Wireless Support
+#
+
+#
+# Binary Loader
+#
+# CONFIG_BINFMT_DISABLE is not set
+# CONFIG_BINFMT_EXEPATH is not set
+# CONFIG_NXFLAT is not set
+# CONFIG_ELF is not set
+CONFIG_BUILTIN=y
+# CONFIG_PIC is not set
+# CONFIG_SYMTAB_ORDEREDBYNAME is not set
+
+#
+# Library Routines
+#
+
+#
+# Standard C Library Options
+#
+CONFIG_STDIO_BUFFER_SIZE=64
+CONFIG_STDIO_LINEBUFFER=y
+CONFIG_NUNGET_CHARS=2
+CONFIG_LIB_HOMEDIR="/"
+# CONFIG_LIBM is not set
+# CONFIG_NOPRINTF_FIELDWIDTH is not set
+# CONFIG_LIBC_FLOATINGPOINT is not set
+CONFIG_LIBC_LONG_LONG=y
+# CONFIG_LIBC_IOCTL_VARIADIC is not set
+CONFIG_LIB_RAND_ORDER=1
+# CONFIG_EOL_IS_CR is not set
+# CONFIG_EOL_IS_LF is not set
+# CONFIG_EOL_IS_BOTH_CRLF is not set
+CONFIG_EOL_IS_EITHER_CRLF=y
+# CONFIG_LIBC_EXECFUNCS is not set
+CONFIG_POSIX_SPAWN_PROXY_STACKSIZE=1024
+CONFIG_TASK_SPAWN_DEFAULT_STACKSIZE=2048
+# CONFIG_LIBC_STRERROR is not set
+# CONFIG_LIBC_PERROR_STDOUT is not set
+CONFIG_ARCH_LOWPUTC=y
+# CONFIG_LIBC_LOCALTIME is not set
+# CONFIG_TIME_EXTENDED is not set
+CONFIG_LIB_SENDFILE_BUFSIZE=512
+# CONFIG_ARCH_ROMGETC is not set
+# CONFIG_ARCH_OPTIMIZED_FUNCTIONS is not set
+CONFIG_ARCH_HAVE_TLS=y
+# CONFIG_TLS is not set
+CONFIG_LIBC_NETDB=y
+CONFIG_NETDB_DNSCLIENT=y
+CONFIG_NETDB_DNSCLIENT_ENTRIES=8
+CONFIG_NETDB_DNSCLIENT_NAMESIZE=32
+CONFIG_NETDB_DNSCLIENT_LIFESEC=3600
+CONFIG_NETDB_DNSCLIENT_MAXRESPONSE=96
+# CONFIG_NETDB_DNSSERVER_NOADDR is not set
+CONFIG_NETDB_DNSSERVER_IPv4=y
+CONFIG_NETDB_DNSSERVER_IPv4ADDR=0x0a000001
+
+#
+# Non-standard Library Support
+#
+# CONFIG_LIB_CRC64_FAST is not set
+# CONFIG_LIB_KBDCODEC is not set
+# CONFIG_LIB_SLCDCODEC is not set
+# CONFIG_LIB_HEX2BIN is not set
+
+#
+# Basic CXX Support
+#
+# CONFIG_C99_BOOL8 is not set
+CONFIG_HAVE_CXX=y
+CONFIG_HAVE_CXXINITIALIZE=y
+# CONFIG_CXX_NEWLONG is not set
+
+#
+# uClibc++ Standard C++ Library
+#
+# CONFIG_UCLIBCXX is not set
+
+#
+# Application Configuration
+#
+
+#
+# NxWidgets/NxWM
+#
+
+#
+# Built-In Applications
+#
+CONFIG_BUILTIN_PROXY_STACKSIZE=1024
+
+#
+# CAN Utilities
+#
+
+#
+# Examples
+#
+# CONFIG_EXAMPLES_BUTTONS is not set
+# CONFIG_EXAMPLES_CHAT is not set
+# CONFIG_EXAMPLES_CONFIGDATA is not set
+# CONFIG_EXAMPLES_CXXTEST is not set
+# CONFIG_EXAMPLES_DHCPD is not set
+# CONFIG_EXAMPLES_DISCOVER is not set
+# CONFIG_EXAMPLES_ELF is not set
+# CONFIG_EXAMPLES_FTPC is not set
+# CONFIG_EXAMPLES_FTPD is not set
+# CONFIG_EXAMPLES_HELLO is not set
+# CONFIG_EXAMPLES_HELLOXX is not set
+# CONFIG_EXAMPLES_HIDKBD is not set
+# CONFIG_EXAMPLES_IGMP is not set
+# CONFIG_EXAMPLES_JSON is not set
+# CONFIG_EXAMPLES_KEYPADTEST is not set
+# CONFIG_EXAMPLES_MEDIA is not set
+# CONFIG_EXAMPLES_MM is not set
+# CONFIG_EXAMPLES_MODBUS is not set
+# CONFIG_EXAMPLES_MOUNT is not set
+# CONFIG_EXAMPLES_NETTEST is not set
+# CONFIG_EXAMPLES_NRF24L01TERM is not set
+CONFIG_EXAMPLES_NSH=y
+CONFIG_EXAMPLES_NSH_CXXINITIALIZE=y
+# CONFIG_EXAMPLES_NULL is not set
+# CONFIG_EXAMPLES_NX is not set
+# CONFIG_EXAMPLES_NXFFS is not set
+# CONFIG_EXAMPLES_NXHELLO is not set
+# CONFIG_EXAMPLES_NXIMAGE is not set
+# CONFIG_EXAMPLES_NXLINES is not set
+# CONFIG_EXAMPLES_NXTERM is not set
+# CONFIG_EXAMPLES_NXTEXT is not set
+# CONFIG_EXAMPLES_OSTEST is not set
+# CONFIG_EXAMPLES_PCA9635 is not set
+# CONFIG_EXAMPLES_POSIXSPAWN is not set
+# CONFIG_EXAMPLES_PPPD is not set
+# CONFIG_EXAMPLES_RFID_READUID is not set
+# CONFIG_EXAMPLES_RGBLED is not set
+# CONFIG_EXAMPLES_RGMP is not set
+# CONFIG_EXAMPLES_SENDMAIL is not set
+# CONFIG_EXAMPLES_SERIALBLASTER is not set
+# CONFIG_EXAMPLES_SERIALRX is not set
+# CONFIG_EXAMPLES_SERLOOP is not set
+# CONFIG_EXAMPLES_SLCD is not set
+# CONFIG_EXAMPLES_SMART is not set
+# CONFIG_EXAMPLES_SMART_TEST is not set
+# CONFIG_EXAMPLES_SMP is not set
+# CONFIG_EXAMPLES_TCPECHO is not set
+# CONFIG_EXAMPLES_TELNETD is not set
+# CONFIG_EXAMPLES_TIFF is not set
+# CONFIG_EXAMPLES_TOUCHSCREEN is not set
+# CONFIG_EXAMPLES_UDP is not set
+# CONFIG_EXAMPLES_UDPBLASTER is not set
+# CONFIG_EXAMPLES_USBTERM is not set
+# CONFIG_EXAMPLES_WATCHDOG is not set
+# CONFIG_EXAMPLES_WEBSERVER is not set
+# CONFIG_EXAMPLES_XMLRPC is not set
+
+#
+# External
+#
+
+#
+# File System Utilities
+#
+# CONFIG_FSUTILS_INIFILE is not set
+
+#
+# GPS Utilities
+#
+# CONFIG_GPSUTILS_MINMEA_LIB is not set
+
+#
+# Graphics Support
+#
+# CONFIG_TIFF is not set
+# CONFIG_GRAPHICS_TRAVELER is not set
+
+#
+# Interpreters
+#
+# CONFIG_INTERPRETERS_FICL is not set
+# CONFIG_INTERPRETERS_MICROPYTHON is not set
+# CONFIG_INTERPRETERS_MINIBASIC is not set
+# CONFIG_INTERPRETERS_PCODE is not set
+
+#
+# FreeModBus
+#
+# CONFIG_MODBUS is not set
+
+#
+# Network Utilities
+#
+# CONFIG_NETUTILS_CHAT is not set
+# CONFIG_NETUTILS_CODECS is not set
+CONFIG_NETUTILS_DHCPC=y
+# CONFIG_NETUTILS_DHCPD is not set
+CONFIG_NETUTILS_DISCOVER=y
+CONFIG_DISCOVER_STACK_SIZE=1024
+CONFIG_DISCOVER_PRIORITY=50
+CONFIG_DISCOVER_PORT=96
+CONFIG_DISCOVER_INTERFACE="eth0"
+CONFIG_DISCOVER_DEVICE_CLASS=0xff
+CONFIG_DISCOVER_DESCR="NuttX"
+# CONFIG_NETUTILS_ESP8266 is not set
+# CONFIG_NETUTILS_FTPC is not set
+# CONFIG_NETUTILS_FTPD is not set
+# CONFIG_NETUTILS_JSON is not set
+CONFIG_NETUTILS_NETLIB=y
+# CONFIG_NETUTILS_NTPCLIENT is not set
+# CONFIG_NETUTILS_PPPD is not set
+# CONFIG_NETUTILS_SMTP is not set
+CONFIG_NETUTILS_TELNETD=y
+# CONFIG_NETUTILS_TFTPC is not set
+# CONFIG_NETUTILS_WEBCLIENT is not set
+# CONFIG_NETUTILS_WEBSERVER is not set
+# CONFIG_NETUTILS_XMLRPC is not set
+
+#
+# NSH Library
+#
+CONFIG_NSH_LIBRARY=y
+# CONFIG_NSH_MOTD is not set
+
+#
+# Command Line Configuration
+#
+# CONFIG_NSH_READLINE is not set
+CONFIG_NSH_CLE=y
+CONFIG_NSH_LINELEN=80
+# CONFIG_NSH_DISABLE_SEMICOLON is not set
+CONFIG_NSH_CMDPARMS=y
+CONFIG_NSH_MAXARGUMENTS=6
+CONFIG_NSH_ARGCAT=y
+CONFIG_NSH_NESTDEPTH=3
+# CONFIG_NSH_DISABLEBG is not set
+CONFIG_NSH_BUILTIN_APPS=y
+
+#
+# Disable Individual commands
+#
+# CONFIG_NSH_DISABLE_ADDROUTE is not set
+# CONFIG_NSH_DISABLE_ARP is not set
+# CONFIG_NSH_DISABLE_BASENAME is not set
+# CONFIG_NSH_DISABLE_CAT is not set
+# CONFIG_NSH_DISABLE_CD is not set
+# CONFIG_NSH_DISABLE_CP is not set
+# CONFIG_NSH_DISABLE_CMP is not set
+CONFIG_NSH_DISABLE_DATE=y
+# CONFIG_NSH_DISABLE_DD is not set
+# CONFIG_NSH_DISABLE_DF is not set
+# CONFIG_NSH_DISABLE_DELROUTE is not set
+# CONFIG_NSH_DISABLE_DIRNAME is not set
+# CONFIG_NSH_DISABLE_ECHO is not set
+# CONFIG_NSH_DISABLE_EXEC is not set
+# CONFIG_NSH_DISABLE_EXIT is not set
+# CONFIG_NSH_DISABLE_FREE is not set
+# CONFIG_NSH_DISABLE_GET is not set
+# CONFIG_NSH_DISABLE_HELP is not set
+# CONFIG_NSH_DISABLE_HEXDUMP is not set
+CONFIG_NSH_DISABLE_IFCONFIG=y
+CONFIG_NSH_DISABLE_IFUPDOWN=y
+# CONFIG_NSH_DISABLE_KILL is not set
+# CONFIG_NSH_DISABLE_LOSETUP is not set
+CONFIG_NSH_DISABLE_LOSMART=y
+# CONFIG_NSH_DISABLE_LS is not set
+# CONFIG_NSH_DISABLE_MB is not set
+# CONFIG_NSH_DISABLE_MKDIR is not set
+# CONFIG_NSH_DISABLE_MKRD is not set
+# CONFIG_NSH_DISABLE_MH is not set
+# CONFIG_NSH_DISABLE_MOUNT is not set
+# CONFIG_NSH_DISABLE_MV is not set
+# CONFIG_NSH_DISABLE_MW is not set
+# CONFIG_NSH_DISABLE_NSLOOKUP is not set
+CONFIG_NSH_DISABLE_PS=y
+# CONFIG_NSH_DISABLE_PING is not set
+# CONFIG_NSH_DISABLE_PUT is not set
+# CONFIG_NSH_DISABLE_PWD is not set
+# CONFIG_NSH_DISABLE_RM is not set
+# CONFIG_NSH_DISABLE_RMDIR is not set
+# CONFIG_NSH_DISABLE_SET is not set
+# CONFIG_NSH_DISABLE_SH is not set
+# CONFIG_NSH_DISABLE_SLEEP is not set
+# CONFIG_NSH_DISABLE_TIME is not set
+# CONFIG_NSH_DISABLE_TEST is not set
+# CONFIG_NSH_DISABLE_UMOUNT is not set
+# CONFIG_NSH_DISABLE_UNAME is not set
+# CONFIG_NSH_DISABLE_UNSET is not set
+# CONFIG_NSH_DISABLE_USLEEP is not set
+# CONFIG_NSH_DISABLE_WGET is not set
+# CONFIG_NSH_DISABLE_XD is not set
+CONFIG_NSH_MMCSDMINOR=0
+
+#
+# Configure Command Options
+#
+CONFIG_NSH_CMDOPT_DF_H=y
+CONFIG_NSH_CODECS_BUFSIZE=128
+CONFIG_NSH_CMDOPT_HEXDUMP=y
+CONFIG_NSH_FILEIOSIZE=1024
+
+#
+# Scripting Support
+#
+# CONFIG_NSH_DISABLESCRIPT is not set
+# CONFIG_NSH_DISABLE_ITEF is not set
+# CONFIG_NSH_DISABLE_LOOPS is not set
+
+#
+# Console Configuration
+#
+CONFIG_NSH_CONSOLE=y
+# CONFIG_NSH_ARCHINIT is not set
+
+#
+# Networking Configuration
+#
+CONFIG_NSH_NETINIT=y
+# CONFIG_NSH_NETINIT_THREAD is not set
+
+#
+# IP Address Configuration
+#
+CONFIG_NSH_DHCPC=y
+
+#
+# IPv4 Addresses
+#
+CONFIG_NSH_DRIPADDR=0xc0a80101
+CONFIG_NSH_NETMASK=0xffffff00
+# CONFIG_NSH_DNS is not set
+CONFIG_NSH_NOMAC=y
+CONFIG_NSH_SWMAC=y
+CONFIG_NSH_MACADDR=0x00e0deadbeef
+CONFIG_NSH_MAX_ROUNDTRIP=20
+
+#
+# Telnet Configuration
+#
+CONFIG_NSH_TELNET=y
+CONFIG_NSH_TELNETD_PORT=23
+CONFIG_NSH_TELNETD_DAEMONPRIO=100
+CONFIG_NSH_TELNETD_DAEMONSTACKSIZE=2048
+CONFIG_NSH_TELNETD_CLIENTPRIO=100
+CONFIG_NSH_TELNETD_CLIENTSTACKSIZE=2048
+CONFIG_NSH_IOBUFFER_SIZE=512
+# CONFIG_NSH_LOGIN is not set
+# CONFIG_NSH_CONSOLE_LOGIN is not set
+# CONFIG_NSH_TELNET_LOGIN is not set
+
+#
+# Platform-specific Support
+#
+# CONFIG_PLATFORM_CONFIGDATA is not set
+
+#
+# System Libraries and NSH Add-Ons
+#
+CONFIG_SYSTEM_CLE=y
+CONFIG_SYSTEM_CLE_DEBUGLEVEL=0
+# CONFIG_SYSTEM_CUTERM is not set
+# CONFIG_SYSTEM_FREE is not set
+# CONFIG_SYSTEM_HEX2BIN is not set
+# CONFIG_SYSTEM_HEXED is not set
+# CONFIG_SYSTEM_INSTALL is not set
+# CONFIG_SYSTEM_NETDB is not set
+# CONFIG_SYSTEM_RAMTEST is not set
+CONFIG_READLINE_HAVE_EXTMATCH=y
+CONFIG_SYSTEM_READLINE=y
+CONFIG_READLINE_ECHO=y
+# CONFIG_READLINE_TABCOMPLETION is not set
+# CONFIG_READLINE_CMD_HISTORY is not set
+# CONFIG_SYSTEM_SUDOKU is not set
+# CONFIG_SYSTEM_SYSTEM is not set
+# CONFIG_SYSTEM_TEE is not set
+# CONFIG_SYSTEM_UBLOXMODEM is not set
+# CONFIG_SYSTEM_VI is not set
+# CONFIG_SYSTEM_ZMODEM is not set
\ No newline at end of file
diff --git a/configs/olimex-stm32-e407/netnsh/setenv.sh b/configs/olimex-stm32-e407/netnsh/setenv.sh
new file mode 100755
index 0000000000..d6f071c221
--- /dev/null
+++ b/configs/olimex-stm32-e407/netnsh/setenv.sh
@@ -0,0 +1,80 @@
+#!/bin/bash
+# configs/olimex-stm32-e407/netnsh/setenv.sh
+#
+# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved.
+# Author: Gregory Nutt
+#
+# 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.
+#
+
+if [ "$_" = "$0" ] ; then
+ echo "You must source this script, not run it!" 1>&2
+ exit 1
+fi
+
+WD=`pwd`
+if [ ! -x "setenv.sh" ]; then
+ echo "This script must be executed from the top-level NuttX build directory"
+ exit 1
+fi
+
+if [ -z "${PATH_ORIG}" ]; then
+ export PATH_ORIG="${PATH}"
+fi
+
+# This is the Cygwin path to the location where I installed the RIDE
+# toolchain under windows. You will also have to edit this if you install
+# the RIDE toolchain in any other location
+#export TOOLCHAIN_BIN="/cygdrive/c/Program Files (x86)/Raisonance/Ride/arm-gcc/bin"
+
+# This is the Cygwin path to the location where I installed the CodeSourcery
+# toolchain under windows. You will also have to edit this if you install
+# the CodeSourcery toolchain in any other location
+export TOOLCHAIN_BIN="/cygdrive/c/Program Files (x86)/CodeSourcery/Sourcery G++ Lite/bin"
+#export TOOLCHAIN_BIN="/cygdrive/c/Users/MyName/MentorGraphics/Sourcery_CodeBench_Lite_for_ARM_EABI/bin"
+
+# This is the location where I installed the ARM "GNU Tools for ARM Embedded Processors"
+# You can this free toolchain here https://launchpad.net/gcc-arm-embedded
+#export TOOLCHAIN_BIN="/cygdrive/c/Program Files (x86)/GNU Tools ARM Embedded/4.9 2015q2/bin"
+
+# These are the Cygwin paths to the locations where I installed the Atollic
+# toolchain under windows. You will also have to edit this if you install
+# the Atollic toolchain in any other location. /usr/bin is added before
+# the Atollic bin path because there is are binaries named gcc.exe and g++.exe
+# at those locations as well.
+#export TOOLCHAIN_BIN="/usr/bin:/cygdrive/c/Program Files (x86)/Atollic/TrueSTUDIO for ARM Pro 2.3.0/ARMTools/bin"
+#export TOOLCHAIN_BIN="/usr/bin:/cygdrive/c/Program Files (x86)/Atollic/TrueSTUDIO for STMicroelectronics STM32 Lite 2.3.0/ARMTools/bin"
+
+# This is the Cygwin path to the location where I build the buildroot
+# toolchain.
+#export TOOLCHAIN_BIN="${WD}/../buildroot/build_arm_nofpu/staging_dir/bin"
+
+# Add the path to the toolchain to the PATH variable
+export PATH="${TOOLCHAIN_BIN}:/sbin:/usr/sbin:${PATH_ORIG}"
+
+echo "PATH : ${PATH}"
diff --git a/configs/olimex-stm32-e407/src/olimex-stm32-e407.h b/configs/olimex-stm32-e407/src/olimex-stm32-e407.h
index 3294e189e4..cc3eff460d 100644
--- a/configs/olimex-stm32-e407/src/olimex-stm32-e407.h
+++ b/configs/olimex-stm32-e407/src/olimex-stm32-e407.h
@@ -49,7 +49,7 @@
* Pre-processor Definitions
****************************************************************************/
-/* Configuration from stm32f4discovert*/
+/* Configuration from stm32f4discovery */
/* Assume that we have everything */
@@ -106,16 +106,6 @@
# undef HAVE_NETMONITOR
#endif
-/* The NSH Network Monitor cannot be used with the STM32F4DIS-BB base board.
- * That is because the LAN8720 is configured in REF_CLK OUT mode. In that
- * mode, the PHY interrupt is not supported. The NINT pin serves instead as
- * REFLCK0.
- */
-
-#ifdef CONFIG_STM32F4DISBB
-# undef HAVE_NETMONITOR
-#endif
-
/* procfs File System */
#ifdef CONFIG_FS_PROCFS
@@ -179,6 +169,31 @@
# define GPIO_OTGHS_OVER (GPIO_INPUT|GPIO_FLOAT|GPIO_SPEED_100MHz|GPIO_PUSHPULL|GPIO_PORTF|GPIO_PIN11)
#endif
+/* LAN8710 works with LAN8720 driver
+ *
+ * ---------- ------------- ------------
+ * PIO SIGNAL Comments
+ * ---------- ------------- ------------
+ * PG11 TXEN
+ * PG13 TXD0
+ * PG14 TXD1
+ * PC4 RXD0/MODE0
+ * PC5 RXD1/MODE1
+ * PA7 CRS_DIV/MODE2
+ * PA2 MDIO
+ * PC1 MDC
+ * PA3 NINT/REFCLK0
+ * PG6 NRST
+ * ---------- ------------- ------------
+ */
+
+#if defined(CONFIG_STM32_ETHMAC)
+# define GPIO_EMAC_NINT (GPIO_INPUT|GPIO_PULLUP|GPIO_EXTI| \
+ GPIO_PORTA|GPIO_PIN3)
+# define GPIO_EMAC_NRST (GPIO_OUTPUT|GPIO_PUSHPULL|GPIO_SPEED_50MHz| \
+ GPIO_OUTPUT_SET|GPIO_PORTG|GPIO_PIN6)
+#endif
+
/****************************************************************************
* Public Types
****************************************************************************/
diff --git a/configs/olimex-stm32-e407/telnetd/Make.defs b/configs/olimex-stm32-e407/telnetd/Make.defs
new file mode 100644
index 0000000000..efcd1c954b
--- /dev/null
+++ b/configs/olimex-stm32-e407/telnetd/Make.defs
@@ -0,0 +1,112 @@
+############################################################################
+# configs/olimex-stm32-e407/telnetd/Make.defs
+#
+# Copyright (C) 2011-2012, 2016 Gregory Nutt. All rights reserved.
+# Author: Gregory Nutt
+#
+# 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
+
+LDSCRIPT = ld.script
+
+ifeq ($(WINTOOL),y)
+ # Windows-native toolchains
+ DIRLINK = $(TOPDIR)/tools/copydir.sh
+ DIRUNLINK = $(TOPDIR)/tools/unlink.sh
+ MKDEP = $(TOPDIR)/tools/mkwindeps.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/$(LDSCRIPT)}"
+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/$(LDSCRIPT)
+endif
+
+CC = $(CROSSDEV)gcc
+CXX = $(CROSSDEV)g++
+CPP = $(CROSSDEV)gcc -E
+LD = $(CROSSDEV)ld
+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
+
+
+HOSTCC = gcc
+HOSTINCLUDES = -I.
+HOSTCFLAGS = -Wall -Wstrict-prototypes -Wshadow -Wundef -g -pipe
+HOSTLDFLAGS =
diff --git a/configs/olimex-stm32-e407/telnetd/defconfig b/configs/olimex-stm32-e407/telnetd/defconfig
new file mode 100644
index 0000000000..70071a6b4f
--- /dev/null
+++ b/configs/olimex-stm32-e407/telnetd/defconfig
@@ -0,0 +1,1304 @@
+#
+# Automatically generated file; DO NOT EDIT.
+# Nuttx/ Configuration
+#
+
+#
+# Build Setup
+#
+# CONFIG_EXPERIMENTAL is not set
+# CONFIG_DEFAULT_SMALL is not set
+CONFIG_HOST_LINUX=y
+# CONFIG_HOST_OSX is not set
+# CONFIG_HOST_WINDOWS is not set
+# CONFIG_HOST_OTHER is not set
+
+#
+# Build Configuration
+#
+CONFIG_APPS_DIR="../apps"
+CONFIG_BUILD_FLAT=y
+# CONFIG_BUILD_2PASS is not set
+
+#
+# Binary Output Formats
+#
+# CONFIG_RRLOAD_BINARY is not set
+CONFIG_INTELHEX_BINARY=y
+# CONFIG_MOTOROLA_SREC is not set
+CONFIG_RAW_BINARY=y
+# CONFIG_UBOOT_UIMAGE is not set
+
+#
+# Customize Header Files
+#
+# CONFIG_ARCH_STDINT_H is not set
+# CONFIG_ARCH_STDBOOL_H is not set
+# CONFIG_ARCH_MATH_H is not set
+# CONFIG_ARCH_FLOAT_H is not set
+# CONFIG_ARCH_STDARG_H is not set
+# CONFIG_ARCH_DEBUG_H is not set
+
+#
+# Debug Options
+#
+CONFIG_DEBUG_ALERT=y
+# CONFIG_DEBUG_FEATURES is not set
+CONFIG_ARCH_HAVE_STACKCHECK=y
+# CONFIG_STACK_COLORATION is not set
+CONFIG_ARCH_HAVE_HEAPCHECK=y
+# CONFIG_HEAP_COLORATION is not set
+CONFIG_DEBUG_SYMBOLS=y
+CONFIG_ARCH_HAVE_CUSTOMOPT=y
+# CONFIG_DEBUG_NOOPT is not set
+# CONFIG_DEBUG_CUSTOMOPT is not set
+CONFIG_DEBUG_FULLOPT=y
+
+#
+# System Type
+#
+CONFIG_ARCH_ARM=y
+# CONFIG_ARCH_AVR is not set
+# CONFIG_ARCH_HC is not set
+# CONFIG_ARCH_MIPS is not set
+# CONFIG_ARCH_RGMP is not set
+# CONFIG_ARCH_RENESAS is not set
+# CONFIG_ARCH_SIM is not set
+# CONFIG_ARCH_X86 is not set
+# CONFIG_ARCH_Z16 is not set
+# CONFIG_ARCH_Z80 is not set
+CONFIG_ARCH="arm"
+
+#
+# ARM Options
+#
+# CONFIG_ARCH_CHIP_A1X is not set
+# CONFIG_ARCH_CHIP_C5471 is not set
+# CONFIG_ARCH_CHIP_CALYPSO is not set
+# CONFIG_ARCH_CHIP_DM320 is not set
+# CONFIG_ARCH_CHIP_EFM32 is not set
+# CONFIG_ARCH_CHIP_IMX1 is not set
+# CONFIG_ARCH_CHIP_IMX6 is not set
+# CONFIG_ARCH_CHIP_KINETIS is not set
+# CONFIG_ARCH_CHIP_KL is not set
+# CONFIG_ARCH_CHIP_LM is not set
+# CONFIG_ARCH_CHIP_TIVA is not set
+# CONFIG_ARCH_CHIP_LPC11XX is not set
+# CONFIG_ARCH_CHIP_LPC17XX is not set
+# CONFIG_ARCH_CHIP_LPC214X is not set
+# CONFIG_ARCH_CHIP_LPC2378 is not set
+# CONFIG_ARCH_CHIP_LPC31XX is not set
+# CONFIG_ARCH_CHIP_LPC43XX is not set
+# CONFIG_ARCH_CHIP_NUC1XX is not set
+# CONFIG_ARCH_CHIP_SAMA5 is not set
+# CONFIG_ARCH_CHIP_SAMD is not set
+# CONFIG_ARCH_CHIP_SAML is not set
+# CONFIG_ARCH_CHIP_SAM34 is not set
+# CONFIG_ARCH_CHIP_SAMV7 is not set
+CONFIG_ARCH_CHIP_STM32=y
+# CONFIG_ARCH_CHIP_STM32F7 is not set
+# CONFIG_ARCH_CHIP_STM32L4 is not set
+# CONFIG_ARCH_CHIP_STR71X is not set
+# CONFIG_ARCH_CHIP_TMS570 is not set
+# CONFIG_ARCH_CHIP_MOXART is not set
+# CONFIG_ARCH_ARM7TDMI is not set
+# CONFIG_ARCH_ARM926EJS is not set
+# CONFIG_ARCH_ARM920T is not set
+# CONFIG_ARCH_CORTEXM0 is not set
+# CONFIG_ARCH_CORTEXM3 is not set
+CONFIG_ARCH_CORTEXM4=y
+# CONFIG_ARCH_CORTEXM7 is not set
+# CONFIG_ARCH_CORTEXA5 is not set
+# CONFIG_ARCH_CORTEXA8 is not set
+# CONFIG_ARCH_CORTEXA9 is not set
+# CONFIG_ARCH_CORTEXR4 is not set
+# CONFIG_ARCH_CORTEXR4F is not set
+# CONFIG_ARCH_CORTEXR5 is not set
+# CONFIG_ARCH_CORTEX5F is not set
+# CONFIG_ARCH_CORTEXR7 is not set
+# CONFIG_ARCH_CORTEXR7F is not set
+CONFIG_ARCH_FAMILY="armv7-m"
+CONFIG_ARCH_CHIP="stm32"
+# CONFIG_ARM_TOOLCHAIN_IAR is not set
+CONFIG_ARM_TOOLCHAIN_GNU=y
+# CONFIG_ARMV7M_USEBASEPRI is not set
+CONFIG_ARCH_HAVE_CMNVECTOR=y
+# CONFIG_ARMV7M_CMNVECTOR is not set
+# CONFIG_ARMV7M_LAZYFPU is not set
+CONFIG_ARCH_HAVE_FPU=y
+# CONFIG_ARCH_HAVE_DPFPU is not set
+# CONFIG_ARCH_FPU is not set
+# CONFIG_ARCH_HAVE_TRUSTZONE is not set
+CONFIG_ARM_HAVE_MPU_UNIFIED=y
+# CONFIG_ARM_MPU is not set
+
+#
+# ARMV7M Configuration Options
+#
+# CONFIG_ARMV7M_HAVE_ICACHE is not set
+# CONFIG_ARMV7M_HAVE_DCACHE is not set
+# CONFIG_ARMV7M_HAVE_ITCM is not set
+# CONFIG_ARMV7M_HAVE_DTCM is not set
+# CONFIG_ARMV7M_TOOLCHAIN_IARL is not set
+CONFIG_ARMV7M_TOOLCHAIN_BUILDROOT=y
+# CONFIG_ARMV7M_TOOLCHAIN_CODEREDL is not set
+# CONFIG_ARMV7M_TOOLCHAIN_CODESOURCERYL is not set
+# CONFIG_ARMV7M_TOOLCHAIN_GNU_EABIL is not set
+# CONFIG_ARMV7M_OABI_TOOLCHAIN is not set
+CONFIG_ARMV7M_HAVE_STACKCHECK=y
+# CONFIG_ARMV7M_STACKCHECK is not set
+# CONFIG_ARMV7M_ITMSYSLOG is not set
+# CONFIG_SERIAL_TERMIOS is not set
+
+#
+# STM32 Configuration Options
+#
+# CONFIG_ARCH_CHIP_STM32L151C6 is not set
+# CONFIG_ARCH_CHIP_STM32L151C8 is not set
+# CONFIG_ARCH_CHIP_STM32L151CB is not set
+# CONFIG_ARCH_CHIP_STM32L151R6 is not set
+# CONFIG_ARCH_CHIP_STM32L151R8 is not set
+# CONFIG_ARCH_CHIP_STM32L151RB is not set
+# CONFIG_ARCH_CHIP_STM32L151V6 is not set
+# CONFIG_ARCH_CHIP_STM32L151V8 is not set
+# CONFIG_ARCH_CHIP_STM32L151VB is not set
+# CONFIG_ARCH_CHIP_STM32L152C6 is not set
+# CONFIG_ARCH_CHIP_STM32L152C8 is not set
+# CONFIG_ARCH_CHIP_STM32L152CB is not set
+# CONFIG_ARCH_CHIP_STM32L152R6 is not set
+# CONFIG_ARCH_CHIP_STM32L152R8 is not set
+# CONFIG_ARCH_CHIP_STM32L152RB is not set
+# CONFIG_ARCH_CHIP_STM32L152V6 is not set
+# CONFIG_ARCH_CHIP_STM32L152V8 is not set
+# CONFIG_ARCH_CHIP_STM32L152VB is not set
+# CONFIG_ARCH_CHIP_STM32L162ZD is not set
+# CONFIG_ARCH_CHIP_STM32L162VE is not set
+# CONFIG_ARCH_CHIP_STM32F100C8 is not set
+# CONFIG_ARCH_CHIP_STM32F100CB is not set
+# CONFIG_ARCH_CHIP_STM32F100R8 is not set
+# CONFIG_ARCH_CHIP_STM32F100RB is not set
+# CONFIG_ARCH_CHIP_STM32F100RC is not set
+# CONFIG_ARCH_CHIP_STM32F100RD is not set
+# CONFIG_ARCH_CHIP_STM32F100RE is not set
+# CONFIG_ARCH_CHIP_STM32F100V8 is not set
+# CONFIG_ARCH_CHIP_STM32F100VB is not set
+# CONFIG_ARCH_CHIP_STM32F100VC is not set
+# CONFIG_ARCH_CHIP_STM32F100VD is not set
+# CONFIG_ARCH_CHIP_STM32F100VE is not set
+# CONFIG_ARCH_CHIP_STM32F102CB is not set
+# CONFIG_ARCH_CHIP_STM32F103T8 is not set
+# CONFIG_ARCH_CHIP_STM32F103TB is not set
+# CONFIG_ARCH_CHIP_STM32F103C4 is not set
+# CONFIG_ARCH_CHIP_STM32F103C8 is not set
+# CONFIG_ARCH_CHIP_STM32F103CB is not set
+# CONFIG_ARCH_CHIP_STM32F103R8 is not set
+# CONFIG_ARCH_CHIP_STM32F103RB is not set
+# CONFIG_ARCH_CHIP_STM32F103RC is not set
+# CONFIG_ARCH_CHIP_STM32F103RD is not set
+# CONFIG_ARCH_CHIP_STM32F103RE is not set
+# CONFIG_ARCH_CHIP_STM32F103RG is not set
+# CONFIG_ARCH_CHIP_STM32F103V8 is not set
+# CONFIG_ARCH_CHIP_STM32F103VB is not set
+# CONFIG_ARCH_CHIP_STM32F103VC is not set
+# CONFIG_ARCH_CHIP_STM32F103VE is not set
+# CONFIG_ARCH_CHIP_STM32F103ZE is not set
+# CONFIG_ARCH_CHIP_STM32F105VB is not set
+# CONFIG_ARCH_CHIP_STM32F105RB is not set
+# CONFIG_ARCH_CHIP_STM32F107VC is not set
+# CONFIG_ARCH_CHIP_STM32F205RG is not set
+# CONFIG_ARCH_CHIP_STM32F207IG is not set
+# CONFIG_ARCH_CHIP_STM32F207ZE is not set
+# CONFIG_ARCH_CHIP_STM32F302K6 is not set
+# CONFIG_ARCH_CHIP_STM32F302K8 is not set
+# CONFIG_ARCH_CHIP_STM32F302CB is not set
+# CONFIG_ARCH_CHIP_STM32F302CC is not set
+# CONFIG_ARCH_CHIP_STM32F302RB is not set
+# CONFIG_ARCH_CHIP_STM32F302RC is not set
+# CONFIG_ARCH_CHIP_STM32F302VB is not set
+# CONFIG_ARCH_CHIP_STM32F302VC is not set
+# CONFIG_ARCH_CHIP_STM32F303K6 is not set
+# CONFIG_ARCH_CHIP_STM32F303K8 is not set
+# CONFIG_ARCH_CHIP_STM32F303C6 is not set
+# CONFIG_ARCH_CHIP_STM32F303C8 is not set
+# CONFIG_ARCH_CHIP_STM32F303CB is not set
+# CONFIG_ARCH_CHIP_STM32F303CC is not set
+# CONFIG_ARCH_CHIP_STM32F303RB is not set
+# CONFIG_ARCH_CHIP_STM32F303RC is not set
+# CONFIG_ARCH_CHIP_STM32F303RD is not set
+# CONFIG_ARCH_CHIP_STM32F303RE is not set
+# CONFIG_ARCH_CHIP_STM32F303VB is not set
+# CONFIG_ARCH_CHIP_STM32F303VC is not set
+# CONFIG_ARCH_CHIP_STM32F372C8 is not set
+# CONFIG_ARCH_CHIP_STM32F372R8 is not set
+# CONFIG_ARCH_CHIP_STM32F372V8 is not set
+# CONFIG_ARCH_CHIP_STM32F372CB is not set
+# CONFIG_ARCH_CHIP_STM32F372RB is not set
+# CONFIG_ARCH_CHIP_STM32F372VB is not set
+# CONFIG_ARCH_CHIP_STM32F372CC is not set
+# CONFIG_ARCH_CHIP_STM32F372RC is not set
+# CONFIG_ARCH_CHIP_STM32F372VC is not set
+# CONFIG_ARCH_CHIP_STM32F373C8 is not set
+# CONFIG_ARCH_CHIP_STM32F373R8 is not set
+# CONFIG_ARCH_CHIP_STM32F373V8 is not set
+# CONFIG_ARCH_CHIP_STM32F373CB is not set
+# CONFIG_ARCH_CHIP_STM32F373RB is not set
+# CONFIG_ARCH_CHIP_STM32F373VB is not set
+# CONFIG_ARCH_CHIP_STM32F373CC is not set
+# CONFIG_ARCH_CHIP_STM32F373RC is not set
+# CONFIG_ARCH_CHIP_STM32F373VC is not set
+# CONFIG_ARCH_CHIP_STM32F401RE is not set
+# CONFIG_ARCH_CHIP_STM32F411RE is not set
+# CONFIG_ARCH_CHIP_STM32F411VE is not set
+# CONFIG_ARCH_CHIP_STM32F405RG is not set
+# CONFIG_ARCH_CHIP_STM32F405VG is not set
+# CONFIG_ARCH_CHIP_STM32F405ZG is not set
+# CONFIG_ARCH_CHIP_STM32F407VE is not set
+# CONFIG_ARCH_CHIP_STM32F407VG is not set
+# CONFIG_ARCH_CHIP_STM32F407ZE is not set
+CONFIG_ARCH_CHIP_STM32F407ZG=y
+# CONFIG_ARCH_CHIP_STM32F407IE is not set
+# CONFIG_ARCH_CHIP_STM32F407IG is not set
+# CONFIG_ARCH_CHIP_STM32F427V is not set
+# CONFIG_ARCH_CHIP_STM32F427Z is not set
+# CONFIG_ARCH_CHIP_STM32F427I is not set
+# CONFIG_ARCH_CHIP_STM32F429V is not set
+# CONFIG_ARCH_CHIP_STM32F429Z is not set
+# CONFIG_ARCH_CHIP_STM32F429I is not set
+# CONFIG_ARCH_CHIP_STM32F429B is not set
+# CONFIG_ARCH_CHIP_STM32F429N is not set
+# CONFIG_ARCH_CHIP_STM32F446M is not set
+# CONFIG_ARCH_CHIP_STM32F446R is not set
+# CONFIG_ARCH_CHIP_STM32F446V is not set
+# CONFIG_ARCH_CHIP_STM32F446Z is not set
+# CONFIG_ARCH_CHIP_STM32F469A is not set
+# CONFIG_ARCH_CHIP_STM32F469I is not set
+# CONFIG_ARCH_CHIP_STM32F469B is not set
+# CONFIG_ARCH_CHIP_STM32F469N is not set
+CONFIG_STM32_FLASH_CONFIG_DEFAULT=y
+# CONFIG_STM32_FLASH_CONFIG_4 is not set
+# CONFIG_STM32_FLASH_CONFIG_6 is not set
+# CONFIG_STM32_FLASH_CONFIG_8 is not set
+# CONFIG_STM32_FLASH_CONFIG_B is not set
+# CONFIG_STM32_FLASH_CONFIG_C is not set
+# CONFIG_STM32_FLASH_CONFIG_D is not set
+# CONFIG_STM32_FLASH_CONFIG_E is not set
+# CONFIG_STM32_FLASH_CONFIG_F is not set
+# CONFIG_STM32_FLASH_CONFIG_G is not set
+# CONFIG_STM32_FLASH_CONFIG_I is not set
+# CONFIG_STM32_STM32L15XX is not set
+# CONFIG_STM32_ENERGYLITE is not set
+# CONFIG_STM32_STM32F10XX is not set
+# CONFIG_STM32_VALUELINE is not set
+# CONFIG_STM32_CONNECTIVITYLINE is not set
+# CONFIG_STM32_PERFORMANCELINE is not set
+# CONFIG_STM32_USBACCESSLINE is not set
+# CONFIG_STM32_HIGHDENSITY is not set
+# CONFIG_STM32_MEDIUMDENSITY is not set
+# CONFIG_STM32_LOWDENSITY is not set
+# CONFIG_STM32_STM32F20XX is not set
+# CONFIG_STM32_STM32F205 is not set
+# CONFIG_STM32_STM32F207 is not set
+# CONFIG_STM32_STM32F30XX is not set
+# CONFIG_STM32_STM32F302 is not set
+# CONFIG_STM32_STM32F303 is not set
+# CONFIG_STM32_STM32F37XX is not set
+CONFIG_STM32_STM32F40XX=y
+# CONFIG_STM32_STM32F401 is not set
+# CONFIG_STM32_STM32F411 is not set
+# CONFIG_STM32_STM32F405 is not set
+CONFIG_STM32_STM32F407=y
+# CONFIG_STM32_STM32F427 is not set
+# CONFIG_STM32_STM32F429 is not set
+# CONFIG_STM32_STM32F446 is not set
+# CONFIG_STM32_STM32F469 is not set
+# CONFIG_STM32_DFU is not set
+
+#
+# STM32 Peripheral Support
+#
+CONFIG_STM32_HAVE_CCM=y
+# CONFIG_STM32_HAVE_USBDEV is not set
+CONFIG_STM32_HAVE_OTGFS=y
+CONFIG_STM32_HAVE_FSMC=y
+# CONFIG_STM32_HAVE_LTDC is not set
+CONFIG_STM32_HAVE_USART3=y
+CONFIG_STM32_HAVE_UART4=y
+CONFIG_STM32_HAVE_UART5=y
+CONFIG_STM32_HAVE_USART6=y
+# CONFIG_STM32_HAVE_UART7 is not set
+# CONFIG_STM32_HAVE_UART8 is not set
+CONFIG_STM32_HAVE_TIM1=y
+CONFIG_STM32_HAVE_TIM2=y
+CONFIG_STM32_HAVE_TIM3=y
+CONFIG_STM32_HAVE_TIM4=y
+CONFIG_STM32_HAVE_TIM5=y
+CONFIG_STM32_HAVE_TIM6=y
+CONFIG_STM32_HAVE_TIM7=y
+CONFIG_STM32_HAVE_TIM8=y
+CONFIG_STM32_HAVE_TIM9=y
+CONFIG_STM32_HAVE_TIM10=y
+CONFIG_STM32_HAVE_TIM11=y
+CONFIG_STM32_HAVE_TIM12=y
+CONFIG_STM32_HAVE_TIM13=y
+CONFIG_STM32_HAVE_TIM14=y
+# CONFIG_STM32_HAVE_TIM15 is not set
+# CONFIG_STM32_HAVE_TIM16 is not set
+# CONFIG_STM32_HAVE_TIM17 is not set
+CONFIG_STM32_HAVE_ADC2=y
+CONFIG_STM32_HAVE_ADC3=y
+# CONFIG_STM32_HAVE_ADC4 is not set
+# CONFIG_STM32_HAVE_ADC1_DMA is not set
+# CONFIG_STM32_HAVE_ADC2_DMA is not set
+# CONFIG_STM32_HAVE_ADC3_DMA is not set
+# CONFIG_STM32_HAVE_ADC4_DMA is not set
+CONFIG_STM32_HAVE_CAN1=y
+CONFIG_STM32_HAVE_CAN2=y
+CONFIG_STM32_HAVE_DAC1=y
+CONFIG_STM32_HAVE_DAC2=y
+CONFIG_STM32_HAVE_RNG=y
+CONFIG_STM32_HAVE_ETHMAC=y
+CONFIG_STM32_HAVE_I2C2=y
+CONFIG_STM32_HAVE_I2C3=y
+CONFIG_STM32_HAVE_SPI2=y
+CONFIG_STM32_HAVE_SPI3=y
+# CONFIG_STM32_HAVE_SPI4 is not set
+# CONFIG_STM32_HAVE_SPI5 is not set
+# CONFIG_STM32_HAVE_SPI6 is not set
+# CONFIG_STM32_HAVE_SAIPLL is not set
+# CONFIG_STM32_HAVE_I2SPLL is not set
+# CONFIG_STM32_ADC1 is not set
+# CONFIG_STM32_ADC2 is not set
+# CONFIG_STM32_ADC3 is not set
+# CONFIG_STM32_BKPSRAM is not set
+# CONFIG_STM32_CAN1 is not set
+# CONFIG_STM32_CAN2 is not set
+# CONFIG_STM32_CCMDATARAM is not set
+# CONFIG_STM32_CRC is not set
+# CONFIG_STM32_CRYP is not set
+# CONFIG_STM32_DMA1 is not set
+# CONFIG_STM32_DMA2 is not set
+# CONFIG_STM32_DAC1 is not set
+# CONFIG_STM32_DAC2 is not set
+# CONFIG_STM32_DCMI is not set
+CONFIG_STM32_ETHMAC=y
+# CONFIG_STM32_FSMC is not set
+# CONFIG_STM32_HASH is not set
+# CONFIG_STM32_I2C1 is not set
+# CONFIG_STM32_I2C2 is not set
+# CONFIG_STM32_I2C3 is not set
+# CONFIG_STM32_OTGFS is not set
+# CONFIG_STM32_OTGHS is not set
+CONFIG_STM32_PWR=y
+# CONFIG_STM32_RNG is not set
+# CONFIG_STM32_SDIO is not set
+# CONFIG_STM32_SPI1 is not set
+# CONFIG_STM32_SPI2 is not set
+# CONFIG_STM32_SPI3 is not set
+CONFIG_STM32_SYSCFG=y
+# CONFIG_STM32_TIM1 is not set
+# CONFIG_STM32_TIM2 is not set
+# CONFIG_STM32_TIM3 is not set
+# CONFIG_STM32_TIM4 is not set
+# CONFIG_STM32_TIM5 is not set
+# CONFIG_STM32_TIM6 is not set
+# CONFIG_STM32_TIM7 is not set
+# CONFIG_STM32_TIM8 is not set
+# CONFIG_STM32_TIM9 is not set
+# CONFIG_STM32_TIM10 is not set
+# CONFIG_STM32_TIM11 is not set
+# CONFIG_STM32_TIM12 is not set
+# CONFIG_STM32_TIM13 is not set
+# CONFIG_STM32_TIM14 is not set
+# CONFIG_STM32_USART1 is not set
+CONFIG_STM32_USART2=y
+# CONFIG_STM32_USART3 is not set
+# CONFIG_STM32_UART4 is not set
+# CONFIG_STM32_UART5 is not set
+# CONFIG_STM32_USART6 is not set
+# CONFIG_STM32_IWDG is not set
+# CONFIG_STM32_WWDG is not set
+# CONFIG_STM32_NOEXT_VECTORS is not set
+
+#
+# Alternate Pin Mapping
+#
+# CONFIG_STM32_FLASH_PREFETCH is not set
+# CONFIG_STM32_JTAG_DISABLE is not set
+CONFIG_STM32_JTAG_FULL_ENABLE=y
+# CONFIG_STM32_JTAG_NOJNTRST_ENABLE is not set
+# CONFIG_STM32_JTAG_SW_ENABLE is not set
+CONFIG_STM32_DISABLE_IDLE_SLEEP_DURING_DEBUG=y
+# CONFIG_STM32_FORCEPOWER is not set
+# CONFIG_ARCH_BOARD_STM32_CUSTOM_CLOCKCONFIG is not set
+# CONFIG_STM32_CCMEXCLUDE is not set
+
+#
+# Timer Configuration
+#
+# CONFIG_STM32_ONESHOT is not set
+# CONFIG_STM32_FREERUN is not set
+# CONFIG_STM32_TIM1_CAP is not set
+# CONFIG_STM32_TIM2_CAP is not set
+# CONFIG_STM32_TIM3_CAP is not set
+# CONFIG_STM32_TIM4_CAP is not set
+# CONFIG_STM32_TIM5_CAP is not set
+# CONFIG_STM32_TIM8_CAP is not set
+# CONFIG_STM32_TIM9_CAP is not set
+# CONFIG_STM32_TIM10_CAP is not set
+# CONFIG_STM32_TIM11_CAP is not set
+# CONFIG_STM32_TIM12_CAP is not set
+# CONFIG_STM32_TIM13_CAP is not set
+# CONFIG_STM32_TIM14_CAP is not set
+CONFIG_STM32_USART=y
+CONFIG_STM32_SERIALDRIVER=y
+
+#
+# U[S]ART Configuration
+#
+
+#
+# U[S]ART Device Configuration
+#
+CONFIG_STM32_USART2_SERIALDRIVER=y
+# CONFIG_STM32_USART2_1WIREDRIVER is not set
+# CONFIG_USART2_RS485 is not set
+
+#
+# Serial Driver Configuration
+#
+# CONFIG_SERIAL_DISABLE_REORDERING is not set
+# CONFIG_STM32_FLOWCONTROL_BROKEN is not set
+# CONFIG_STM32_USART_BREAKS is not set
+# CONFIG_STM32_USART_SINGLEWIRE is not set
+# CONFIG_STM32_HAVE_RTC_COUNTER is not set
+# CONFIG_STM32_HAVE_RTC_SUBSECONDS is not set
+
+#
+# Ethernet MAC configuration
+#
+CONFIG_STM32_PHYADDR=0
+# CONFIG_STM32_PHYINIT is not set
+# CONFIG_STM32_MII is not set
+CONFIG_STM32_AUTONEG=y
+CONFIG_STM32_PHYSR=31
+CONFIG_STM32_PHYSR_ALTCONFIG=y
+CONFIG_STM32_PHYSR_ALTMODE=0x001c
+CONFIG_STM32_PHYSR_10HD=0x0004
+CONFIG_STM32_PHYSR_100HD=0x0008
+CONFIG_STM32_PHYSR_10FD=0x0014
+CONFIG_STM32_PHYSR_100FD=0x0018
+# CONFIG_STM32_ETH_PTP is not set
+CONFIG_STM32_RMII=y
+# CONFIG_STM32_RMII_MCO1 is not set
+# CONFIG_STM32_RMII_MCO2 is not set
+CONFIG_STM32_RMII_EXTCLK=y
+
+#
+# USB FS Host Configuration
+#
+
+#
+# USB HS Host Configuration
+#
+
+#
+# USB Host Debug Configuration
+#
+
+#
+# USB Device Configuration
+#
+
+#
+# Architecture Options
+#
+# CONFIG_ARCH_NOINTC is not set
+# CONFIG_ARCH_VECNOTIRQ is not set
+# CONFIG_ARCH_DMA is not set
+CONFIG_ARCH_HAVE_IRQPRIO=y
+# CONFIG_ARCH_L2CACHE is not set
+# CONFIG_ARCH_HAVE_COHERENT_DCACHE is not set
+# CONFIG_ARCH_HAVE_ADDRENV is not set
+# CONFIG_ARCH_NEED_ADDRENV_MAPPING is not set
+# CONFIG_ARCH_HAVE_MULTICPU is not set
+CONFIG_ARCH_HAVE_VFORK=y
+# CONFIG_ARCH_HAVE_MMU is not set
+CONFIG_ARCH_HAVE_MPU=y
+# CONFIG_ARCH_NAND_HWECC is not set
+# CONFIG_ARCH_HAVE_EXTCLK is not set
+# CONFIG_ARCH_HAVE_POWEROFF is not set
+CONFIG_ARCH_HAVE_RESET=y
+# CONFIG_ARCH_USE_MPU is not set
+# CONFIG_ARCH_IRQPRIO is not set
+CONFIG_ARCH_STACKDUMP=y
+# CONFIG_ENDIAN_BIG is not set
+# CONFIG_ARCH_IDLE_CUSTOM is not set
+# CONFIG_ARCH_HAVE_RAMFUNCS is not set
+CONFIG_ARCH_HAVE_RAMVECTORS=y
+# CONFIG_ARCH_RAMVECTORS is not set
+
+#
+# Board Settings
+#
+CONFIG_BOARD_LOOPSPERMSEC=16717
+# CONFIG_ARCH_CALIBRATION is not set
+
+#
+# Interrupt options
+#
+CONFIG_ARCH_HAVE_INTERRUPTSTACK=y
+CONFIG_ARCH_INTERRUPTSTACK=0
+CONFIG_ARCH_HAVE_HIPRI_INTERRUPT=y
+# CONFIG_ARCH_HIPRI_INTERRUPT is not set
+
+#
+# Boot options
+#
+# CONFIG_BOOT_RUNFROMEXTSRAM is not set
+CONFIG_BOOT_RUNFROMFLASH=y
+# CONFIG_BOOT_RUNFROMISRAM is not set
+# CONFIG_BOOT_RUNFROMSDRAM is not set
+# CONFIG_BOOT_COPYTORAM is not set
+
+#
+# Boot Memory Configuration
+#
+CONFIG_RAM_START=0x20000000
+CONFIG_RAM_SIZE=114688
+# CONFIG_ARCH_HAVE_SDRAM is not set
+
+#
+# Board Selection
+#
+# CONFIG_ARCH_BOARD_OLIMEX_STM32H407 is not set
+CONFIG_ARCH_BOARD_OLIMEX_STM32E407=y
+# CONFIG_ARCH_BOARD_CUSTOM is not set
+CONFIG_ARCH_BOARD="olimex-stm32-e407"
+
+#
+# Common Board Options
+#
+CONFIG_ARCH_HAVE_LEDS=y
+CONFIG_ARCH_LEDS=y
+CONFIG_ARCH_HAVE_BUTTONS=y
+CONFIG_ARCH_BUTTONS=y
+CONFIG_ARCH_HAVE_IRQBUTTONS=y
+# CONFIG_ARCH_IRQBUTTONS is not set
+
+#
+# Board-Specific Options
+#
+# CONFIG_BOARD_CRASHDUMP is not set
+# CONFIG_LIB_BOARDCTL is not set
+
+#
+# RTOS Features
+#
+CONFIG_DISABLE_OS_API=y
+# CONFIG_DISABLE_POSIX_TIMERS is not set
+# CONFIG_DISABLE_PTHREAD is not set
+# CONFIG_DISABLE_SIGNALS is not set
+# CONFIG_DISABLE_MQUEUE is not set
+# CONFIG_DISABLE_ENVIRON is not set
+
+#
+# Clocks and Timers
+#
+CONFIG_ARCH_HAVE_TICKLESS=y
+# CONFIG_SCHED_TICKLESS is not set
+CONFIG_USEC_PER_TICK=10000
+# CONFIG_SYSTEM_TIME64 is not set
+# CONFIG_CLOCK_MONOTONIC is not set
+CONFIG_ARCH_HAVE_TIMEKEEPING=y
+# CONFIG_JULIAN_TIME is not set
+CONFIG_START_YEAR=2011
+CONFIG_START_MONTH=12
+CONFIG_START_DAY=6
+CONFIG_MAX_WDOGPARMS=2
+CONFIG_PREALLOC_WDOGS=16
+CONFIG_WDOG_INTRESERVE=4
+CONFIG_PREALLOC_TIMERS=4
+
+#
+# Tasks and Scheduling
+#
+# CONFIG_INIT_NONE is not set
+CONFIG_INIT_ENTRYPOINT=y
+# CONFIG_INIT_FILEPATH is not set
+CONFIG_USER_ENTRYPOINT="telnetd_main"
+CONFIG_RR_INTERVAL=200
+# CONFIG_SCHED_SPORADIC is not set
+CONFIG_TASK_NAME_SIZE=31
+CONFIG_MAX_TASKS=16
+# CONFIG_SCHED_HAVE_PARENT is not set
+CONFIG_SCHED_WAITPID=y
+
+#
+# Pthread Options
+#
+# CONFIG_MUTEX_TYPES is not set
+CONFIG_NPTHREAD_KEYS=4
+
+#
+# Performance Monitoring
+#
+# CONFIG_SCHED_CPULOAD is not set
+# CONFIG_SCHED_INSTRUMENTATION is not set
+
+#
+# Files and I/O
+#
+CONFIG_DEV_CONSOLE=y
+# CONFIG_FDCLONE_DISABLE is not set
+# CONFIG_FDCLONE_STDIO is not set
+CONFIG_SDCLONE_DISABLE=y
+CONFIG_NFILE_DESCRIPTORS=8
+CONFIG_NFILE_STREAMS=8
+CONFIG_NAME_MAX=32
+# CONFIG_PRIORITY_INHERITANCE is not set
+
+#
+# RTOS hooks
+#
+# CONFIG_BOARD_INITIALIZE is not set
+# CONFIG_SCHED_STARTHOOK is not set
+# CONFIG_SCHED_ATEXIT is not set
+# CONFIG_SCHED_ONEXIT is not set
+
+#
+# Signal Numbers
+#
+CONFIG_SIG_SIGUSR1=1
+CONFIG_SIG_SIGUSR2=2
+CONFIG_SIG_SIGALARM=3
+CONFIG_SIG_SIGCONDTIMEDOUT=16
+
+#
+# POSIX Message Queue Options
+#
+CONFIG_PREALLOC_MQ_MSGS=4
+CONFIG_MQ_MAXMSGSIZE=32
+# CONFIG_MODULE is not set
+
+#
+# Work queue support
+#
+# CONFIG_SCHED_WORKQUEUE is not set
+# CONFIG_SCHED_HPWORK is not set
+# CONFIG_SCHED_LPWORK is not set
+
+#
+# Stack and heap information
+#
+CONFIG_IDLETHREAD_STACKSIZE=1024
+CONFIG_USERMAIN_STACKSIZE=2048
+CONFIG_PTHREAD_STACK_MIN=256
+CONFIG_PTHREAD_STACK_DEFAULT=2048
+# CONFIG_LIB_SYSCALL is not set
+
+#
+# Device Drivers
+#
+# CONFIG_DISABLE_POLL is not set
+CONFIG_DEV_NULL=y
+# CONFIG_DEV_ZERO is not set
+# CONFIG_DEV_URANDOM is not set
+# CONFIG_DEV_LOOP is not set
+
+#
+# Buffering
+#
+# CONFIG_DRVR_WRITEBUFFER is not set
+# CONFIG_DRVR_READAHEAD is not set
+# CONFIG_RAMDISK is not set
+# CONFIG_CAN is not set
+# CONFIG_ARCH_HAVE_PWM_PULSECOUNT is not set
+# CONFIG_ARCH_HAVE_PWM_MULTICHAN is not set
+# CONFIG_PWM is not set
+CONFIG_ARCH_HAVE_I2CRESET=y
+# CONFIG_I2C is not set
+CONFIG_SPI=y
+# CONFIG_SPI_SLAVE is not set
+CONFIG_SPI_EXCHANGE=y
+# CONFIG_SPI_CMDDATA is not set
+# CONFIG_SPI_CALLBACK is not set
+# CONFIG_SPI_HWFEATURES is not set
+# CONFIG_ARCH_HAVE_SPI_CRCGENERATION is not set
+# CONFIG_ARCH_HAVE_SPI_CS_CONTROL is not set
+CONFIG_ARCH_HAVE_SPI_BITORDER=y
+# CONFIG_SPI_BITORDER is not set
+# CONFIG_SPI_CS_DELAY_CONTROL is not set
+# CONFIG_SPI_DRIVER is not set
+# CONFIG_SPI_BITBANG is not set
+# CONFIG_I2S is not set
+
+#
+# Timer Driver Support
+#
+# CONFIG_TIMER is not set
+# CONFIG_ONESHOT is not set
+# CONFIG_RTC is not set
+# CONFIG_WATCHDOG is not set
+# CONFIG_ANALOG is not set
+# CONFIG_AUDIO_DEVICES is not set
+# CONFIG_VIDEO_DEVICES is not set
+# CONFIG_BCH is not set
+# CONFIG_INPUT is not set
+
+#
+# IO Expander/GPIO Support
+#
+# CONFIG_IOEXPANDER is not set
+# CONFIG_DEV_GPIO is not set
+
+#
+# LCD Driver Support
+#
+# CONFIG_LCD is not set
+# CONFIG_SLCD is not set
+
+#
+# LED Support
+#
+# CONFIG_USERLED is not set
+# CONFIG_RGBLED is not set
+# CONFIG_PCA9635PW is not set
+# CONFIG_NCP5623C is not set
+# CONFIG_MMCSD is not set
+# CONFIG_MODEM is not set
+# CONFIG_MTD is not set
+# CONFIG_EEPROM is not set
+CONFIG_NETDEVICES=y
+
+#
+# General Ethernet MAC Driver Options
+#
+# CONFIG_NETDEV_LOOPBACK is not set
+CONFIG_NETDEV_TELNET=y
+CONFIG_TELNET_RXBUFFER_SIZE=256
+CONFIG_TELNET_TXBUFFER_SIZE=256
+# CONFIG_NETDEV_MULTINIC is not set
+# CONFIG_ARCH_HAVE_NETDEV_STATISTICS is not set
+# CONFIG_NETDEV_LATEINIT is not set
+
+#
+# External Ethernet MAC Device Support
+#
+# CONFIG_NET_DM90x0 is not set
+# CONFIG_ENC28J60 is not set
+# CONFIG_ENCX24J600 is not set
+# CONFIG_NET_E1000 is not set
+# CONFIG_NET_SLIP is not set
+# CONFIG_NET_FTMAC100 is not set
+# CONFIG_NET_VNET is not set
+
+#
+# External Ethernet PHY Device Support
+#
+# CONFIG_ARCH_PHY_INTERRUPT is not set
+# CONFIG_ETH0_PHY_NONE is not set
+# CONFIG_ETH0_PHY_AM79C874 is not set
+# CONFIG_ETH0_PHY_KS8721 is not set
+# CONFIG_ETH0_PHY_KSZ8041 is not set
+# CONFIG_ETH0_PHY_KSZ8051 is not set
+# CONFIG_ETH0_PHY_KSZ8061 is not set
+# CONFIG_ETH0_PHY_KSZ8081 is not set
+# CONFIG_ETH0_PHY_KSZ90x1 is not set
+# CONFIG_ETH0_PHY_DP83848C is not set
+CONFIG_ETH0_PHY_LAN8720=y
+# CONFIG_ETH0_PHY_LAN8740 is not set
+# CONFIG_ETH0_PHY_LAN8740A is not set
+# CONFIG_ETH0_PHY_LAN8742A is not set
+# CONFIG_ETH0_PHY_DM9161 is not set
+# CONFIG_PIPES is not set
+# CONFIG_PM is not set
+# CONFIG_POWER is not set
+# CONFIG_SENSORS is not set
+# CONFIG_SERCOMM_CONSOLE is not set
+CONFIG_SERIAL=y
+# CONFIG_DEV_LOWCONSOLE is not set
+# CONFIG_SERIAL_REMOVABLE is not set
+CONFIG_SERIAL_CONSOLE=y
+# CONFIG_16550_UART is not set
+# CONFIG_UART_SERIALDRIVER is not set
+# CONFIG_UART0_SERIALDRIVER is not set
+# CONFIG_UART1_SERIALDRIVER is not set
+# CONFIG_UART2_SERIALDRIVER is not set
+# CONFIG_UART3_SERIALDRIVER is not set
+# CONFIG_UART4_SERIALDRIVER is not set
+# CONFIG_UART5_SERIALDRIVER is not set
+# CONFIG_UART6_SERIALDRIVER is not set
+# CONFIG_UART7_SERIALDRIVER is not set
+# CONFIG_UART8_SERIALDRIVER is not set
+# CONFIG_SCI0_SERIALDRIVER is not set
+# CONFIG_SCI1_SERIALDRIVER is not set
+# CONFIG_USART0_SERIALDRIVER is not set
+# CONFIG_USART1_SERIALDRIVER is not set
+CONFIG_USART2_SERIALDRIVER=y
+# CONFIG_USART3_SERIALDRIVER is not set
+# CONFIG_USART4_SERIALDRIVER is not set
+# CONFIG_USART5_SERIALDRIVER is not set
+# CONFIG_USART6_SERIALDRIVER is not set
+# CONFIG_USART7_SERIALDRIVER is not set
+# CONFIG_USART8_SERIALDRIVER is not set
+# CONFIG_OTHER_UART_SERIALDRIVER is not set
+CONFIG_MCU_SERIAL=y
+CONFIG_STANDARD_SERIAL=y
+CONFIG_SERIAL_NPOLLWAITERS=2
+# CONFIG_SERIAL_IFLOWCONTROL is not set
+# CONFIG_SERIAL_OFLOWCONTROL is not set
+# CONFIG_SERIAL_DMA is not set
+CONFIG_ARCH_HAVE_SERIAL_TERMIOS=y
+CONFIG_USART2_SERIAL_CONSOLE=y
+# CONFIG_OTHER_SERIAL_CONSOLE is not set
+# CONFIG_NO_SERIAL_CONSOLE is not set
+
+#
+# USART2 Configuration
+#
+CONFIG_USART2_RXBUFSIZE=128
+CONFIG_USART2_TXBUFSIZE=128
+CONFIG_USART2_BAUD=115200
+CONFIG_USART2_BITS=8
+CONFIG_USART2_PARITY=0
+CONFIG_USART2_2STOP=0
+# CONFIG_USART2_IFLOWCONTROL is not set
+# CONFIG_USART2_OFLOWCONTROL is not set
+# CONFIG_USART2_DMA is not set
+# CONFIG_PSEUDOTERM is not set
+# CONFIG_USBDEV is not set
+# CONFIG_USBHOST is not set
+# CONFIG_HAVE_USBTRACE is not set
+# CONFIG_DRIVERS_WIRELESS is not set
+# CONFIG_DRIVERS_CONTACTLESS is not set
+
+#
+# System Logging
+#
+# CONFIG_ARCH_SYSLOG is not set
+# CONFIG_RAMLOG is not set
+# CONFIG_SYSLOG_INTBUFFER is not set
+# CONFIG_SYSLOG_TIMESTAMP is not set
+CONFIG_SYSLOG_SERIAL_CONSOLE=y
+# CONFIG_SYSLOG_CHAR is not set
+CONFIG_SYSLOG_CONSOLE=y
+# CONFIG_SYSLOG_NONE is not set
+# CONFIG_SYSLOG_FILE is not set
+# CONFIG_SYSLOG_CHARDEV is not set
+
+#
+# Networking Support
+#
+CONFIG_ARCH_HAVE_NET=y
+CONFIG_ARCH_HAVE_PHY=y
+CONFIG_NET=y
+# CONFIG_NET_NOINTS is not set
+# CONFIG_NET_PROMISCUOUS is not set
+
+#
+# Driver buffer configuration
+#
+CONFIG_NET_MULTIBUFFER=y
+CONFIG_NET_ETH_MTU=590
+CONFIG_NET_ETH_TCP_RECVWNDO=536
+CONFIG_NET_GUARDSIZE=2
+
+#
+# Data link support
+#
+# CONFIG_NET_MULTILINK is not set
+CONFIG_NET_ETHERNET=y
+# CONFIG_NET_LOOPBACK is not set
+# CONFIG_NET_TUN is not set
+
+#
+# Network Device Operations
+#
+# CONFIG_NETDEV_PHY_IOCTL is not set
+
+#
+# Internet Protocol Selection
+#
+CONFIG_NET_IPv4=y
+# CONFIG_NET_IPv6 is not set
+
+#
+# Socket Support
+#
+CONFIG_NSOCKET_DESCRIPTORS=10
+CONFIG_NET_NACTIVESOCKETS=16
+CONFIG_NET_SOCKOPTS=y
+CONFIG_NET_SOLINGER=y
+
+#
+# Raw Socket Support
+#
+# CONFIG_NET_PKT is not set
+
+#
+# Unix Domain Socket Support
+#
+# CONFIG_NET_LOCAL is not set
+
+#
+# TCP/IP Networking
+#
+CONFIG_NET_TCP=y
+# CONFIG_NET_TCPURGDATA is not set
+CONFIG_NET_TCP_CONNS=40
+CONFIG_NET_MAX_LISTENPORTS=40
+CONFIG_NET_TCP_READAHEAD=y
+# CONFIG_NET_TCP_WRITE_BUFFERS is not set
+CONFIG_NET_TCP_RECVDELAY=0
+CONFIG_NET_TCPBACKLOG=y
+# CONFIG_NET_TCP_SPLIT is not set
+# CONFIG_NET_SENDFILE is not set
+
+#
+# UDP Networking
+#
+CONFIG_NET_UDP=y
+CONFIG_NET_UDP_CHECKSUMS=y
+CONFIG_NET_UDP_CONNS=8
+CONFIG_NET_BROADCAST=y
+# CONFIG_NET_RXAVAIL is not set
+CONFIG_NET_UDP_READAHEAD=y
+
+#
+# ICMP Networking Support
+#
+CONFIG_NET_ICMP=y
+CONFIG_NET_ICMP_PING=y
+
+#
+# IGMPv2 Client Support
+#
+# CONFIG_NET_IGMP is not set
+
+#
+# ARP Configuration
+#
+CONFIG_NET_ARP=y
+CONFIG_NET_ARPTAB_SIZE=16
+CONFIG_NET_ARP_MAXAGE=120
+CONFIG_NET_ARP_IPIN=y
+# CONFIG_NET_ARP_SEND is not set
+
+#
+# Network I/O Buffer Support
+#
+CONFIG_NET_IOB=y
+CONFIG_IOB_NBUFFERS=24
+CONFIG_IOB_BUFSIZE=196
+CONFIG_IOB_NCHAINS=8
+# CONFIG_NET_ARCH_INCR32 is not set
+# CONFIG_NET_ARCH_CHKSUM is not set
+CONFIG_NET_STATISTICS=y
+
+#
+# Routing Table Configuration
+#
+# CONFIG_NET_ROUTE is not set
+CONFIG_NET_HOSTNAME=""
+
+#
+# Crypto API
+#
+# CONFIG_CRYPTO is not set
+
+#
+# File Systems
+#
+
+#
+# File system configuration
+#
+# CONFIG_DISABLE_MOUNTPOINT is not set
+# CONFIG_FS_AUTOMOUNTER is not set
+# CONFIG_DISABLE_PSEUDOFS_OPERATIONS is not set
+# CONFIG_FS_READABLE is not set
+# CONFIG_FS_WRITABLE is not set
+# CONFIG_FS_NAMED_SEMAPHORES is not set
+CONFIG_FS_MQUEUE_MPATH="/var/mqueue"
+# CONFIG_FS_RAMMAP is not set
+# CONFIG_FS_FAT is not set
+# CONFIG_NFS is not set
+# CONFIG_FS_NXFFS is not set
+# CONFIG_FS_ROMFS is not set
+# CONFIG_FS_TMPFS is not set
+# CONFIG_FS_SMARTFS is not set
+# CONFIG_FS_BINFS is not set
+# CONFIG_FS_PROCFS is not set
+# CONFIG_FS_UNIONFS is not set
+
+#
+# Graphics Support
+#
+# CONFIG_NX is not set
+
+#
+# Memory Management
+#
+# CONFIG_MM_SMALL is not set
+CONFIG_MM_REGIONS=2
+# CONFIG_ARCH_HAVE_HEAP2 is not set
+# CONFIG_GRAN is not set
+
+#
+# Audio Support
+#
+# CONFIG_AUDIO is not set
+
+#
+# Wireless Support
+#
+
+#
+# Binary Loader
+#
+# CONFIG_BINFMT_DISABLE is not set
+# CONFIG_BINFMT_EXEPATH is not set
+# CONFIG_NXFLAT is not set
+# CONFIG_ELF is not set
+CONFIG_BUILTIN=y
+# CONFIG_PIC is not set
+# CONFIG_SYMTAB_ORDEREDBYNAME is not set
+
+#
+# Library Routines
+#
+
+#
+# Standard C Library Options
+#
+CONFIG_STDIO_BUFFER_SIZE=64
+CONFIG_STDIO_LINEBUFFER=y
+CONFIG_NUNGET_CHARS=2
+CONFIG_LIB_HOMEDIR="/"
+# CONFIG_LIBM is not set
+# CONFIG_NOPRINTF_FIELDWIDTH is not set
+# CONFIG_LIBC_FLOATINGPOINT is not set
+CONFIG_LIBC_LONG_LONG=y
+# CONFIG_LIBC_IOCTL_VARIADIC is not set
+CONFIG_LIB_RAND_ORDER=1
+# CONFIG_EOL_IS_CR is not set
+# CONFIG_EOL_IS_LF is not set
+# CONFIG_EOL_IS_BOTH_CRLF is not set
+CONFIG_EOL_IS_EITHER_CRLF=y
+# CONFIG_LIBC_EXECFUNCS is not set
+CONFIG_POSIX_SPAWN_PROXY_STACKSIZE=1024
+CONFIG_TASK_SPAWN_DEFAULT_STACKSIZE=2048
+# CONFIG_LIBC_STRERROR is not set
+# CONFIG_LIBC_PERROR_STDOUT is not set
+CONFIG_ARCH_LOWPUTC=y
+# CONFIG_LIBC_LOCALTIME is not set
+# CONFIG_TIME_EXTENDED is not set
+CONFIG_LIB_SENDFILE_BUFSIZE=512
+# CONFIG_ARCH_ROMGETC is not set
+# CONFIG_ARCH_OPTIMIZED_FUNCTIONS is not set
+CONFIG_ARCH_HAVE_TLS=y
+# CONFIG_TLS is not set
+CONFIG_LIBC_NETDB=y
+CONFIG_NETDB_DNSCLIENT=y
+CONFIG_NETDB_DNSCLIENT_ENTRIES=8
+CONFIG_NETDB_DNSCLIENT_NAMESIZE=32
+CONFIG_NETDB_DNSCLIENT_LIFESEC=3600
+CONFIG_NETDB_DNSCLIENT_MAXRESPONSE=96
+# CONFIG_NETDB_DNSSERVER_NOADDR is not set
+CONFIG_NETDB_DNSSERVER_IPv4=y
+CONFIG_NETDB_DNSSERVER_IPv4ADDR=0x0a000001
+
+#
+# Non-standard Library Support
+#
+# CONFIG_LIB_CRC64_FAST is not set
+# CONFIG_LIB_KBDCODEC is not set
+# CONFIG_LIB_SLCDCODEC is not set
+# CONFIG_LIB_HEX2BIN is not set
+
+#
+# Basic CXX Support
+#
+# CONFIG_C99_BOOL8 is not set
+CONFIG_HAVE_CXX=y
+CONFIG_HAVE_CXXINITIALIZE=y
+# CONFIG_CXX_NEWLONG is not set
+
+#
+# uClibc++ Standard C++ Library
+#
+# CONFIG_UCLIBCXX is not set
+
+#
+# Application Configuration
+#
+
+#
+# NxWidgets/NxWM
+#
+
+#
+# Built-In Applications
+#
+CONFIG_BUILTIN_PROXY_STACKSIZE=1024
+
+#
+# CAN Utilities
+#
+
+#
+# Examples
+#
+# CONFIG_EXAMPLES_BUTTONS is not set
+# CONFIG_EXAMPLES_CHAT is not set
+# CONFIG_EXAMPLES_CONFIGDATA is not set
+# CONFIG_EXAMPLES_CXXTEST is not set
+# CONFIG_EXAMPLES_DHCPD is not set
+# CONFIG_EXAMPLES_DISCOVER is not set
+# CONFIG_EXAMPLES_ELF is not set
+# CONFIG_EXAMPLES_FTPC is not set
+# CONFIG_EXAMPLES_FTPD is not set
+# CONFIG_EXAMPLES_HELLO is not set
+# CONFIG_EXAMPLES_HELLOXX is not set
+# CONFIG_EXAMPLES_HIDKBD is not set
+# CONFIG_EXAMPLES_IGMP is not set
+# CONFIG_EXAMPLES_JSON is not set
+# CONFIG_EXAMPLES_KEYPADTEST is not set
+# CONFIG_EXAMPLES_MEDIA is not set
+# CONFIG_EXAMPLES_MM is not set
+# CONFIG_EXAMPLES_MODBUS is not set
+# CONFIG_EXAMPLES_MOUNT is not set
+# CONFIG_EXAMPLES_NETTEST is not set
+# CONFIG_EXAMPLES_NRF24L01TERM is not set
+# CONFIG_EXAMPLES_NSH is not set
+# CONFIG_EXAMPLES_NULL is not set
+# CONFIG_EXAMPLES_NX is not set
+# CONFIG_EXAMPLES_NXFFS is not set
+# CONFIG_EXAMPLES_NXHELLO is not set
+# CONFIG_EXAMPLES_NXIMAGE is not set
+# CONFIG_EXAMPLES_NXLINES is not set
+# CONFIG_EXAMPLES_NXTERM is not set
+# CONFIG_EXAMPLES_NXTEXT is not set
+# CONFIG_EXAMPLES_OSTEST is not set
+# CONFIG_EXAMPLES_PCA9635 is not set
+# CONFIG_EXAMPLES_POSIXSPAWN is not set
+# CONFIG_EXAMPLES_PPPD is not set
+# CONFIG_EXAMPLES_RFID_READUID is not set
+# CONFIG_EXAMPLES_RGBLED is not set
+# CONFIG_EXAMPLES_RGMP is not set
+# CONFIG_EXAMPLES_SENDMAIL is not set
+# CONFIG_EXAMPLES_SERIALBLASTER is not set
+# CONFIG_EXAMPLES_SERIALRX is not set
+# CONFIG_EXAMPLES_SERLOOP is not set
+# CONFIG_EXAMPLES_SLCD is not set
+# CONFIG_EXAMPLES_SMART is not set
+# CONFIG_EXAMPLES_SMP is not set
+# CONFIG_EXAMPLES_TCPECHO is not set
+CONFIG_EXAMPLES_TELNETD=y
+CONFIG_EXAMPLES_TELNETD_NOMAC=y
+CONFIG_EXAMPLES_TELNETD_IPADDR=0xc0a80185
+CONFIG_EXAMPLES_TELNETD_DRIPADDR=0xc0a80101
+CONFIG_EXAMPLES_TELNETD_NETMASK=0xffffff00
+CONFIG_EXAMPLES_TELNETD_DAEMONPRIO=128
+CONFIG_EXAMPLES_TELNETD_DAEMONSTACKSIZE=2048
+CONFIG_EXAMPLES_TELNETD_CLIENTPRIO=128
+CONFIG_EXAMPLES_TELNETD_CLIENTSTACKSIZE=2048
+# CONFIG_EXAMPLES_TIFF is not set
+# CONFIG_EXAMPLES_TOUCHSCREEN is not set
+# CONFIG_EXAMPLES_UDP is not set
+# CONFIG_EXAMPLES_UDPBLASTER is not set
+# CONFIG_EXAMPLES_USBTERM is not set
+# CONFIG_EXAMPLES_WATCHDOG is not set
+# CONFIG_EXAMPLES_WEBSERVER is not set
+# CONFIG_EXAMPLES_WGET is not set
+# CONFIG_EXAMPLES_XMLRPC is not set
+
+#
+# External
+#
+
+#
+# File System Utilities
+#
+# CONFIG_FSUTILS_INIFILE is not set
+
+#
+# GPS Utilities
+#
+# CONFIG_GPSUTILS_MINMEA_LIB is not set
+
+#
+# Graphics Support
+#
+# CONFIG_TIFF is not set
+# CONFIG_GRAPHICS_TRAVELER is not set
+
+#
+# Interpreters
+#
+# CONFIG_INTERPRETERS_FICL is not set
+# CONFIG_INTERPRETERS_MICROPYTHON is not set
+# CONFIG_INTERPRETERS_MINIBASIC is not set
+# CONFIG_INTERPRETERS_PCODE is not set
+
+#
+# FreeModBus
+#
+# CONFIG_MODBUS is not set
+
+#
+# Network Utilities
+#
+# CONFIG_NETUTILS_CHAT is not set
+# CONFIG_NETUTILS_CODECS is not set
+CONFIG_NETUTILS_DHCPC=y
+# CONFIG_NETUTILS_DHCPD is not set
+CONFIG_NETUTILS_DISCOVER=y
+CONFIG_DISCOVER_STACK_SIZE=1024
+CONFIG_DISCOVER_PRIORITY=50
+CONFIG_DISCOVER_PORT=96
+CONFIG_DISCOVER_INTERFACE="eth0"
+CONFIG_DISCOVER_DEVICE_CLASS=0xff
+CONFIG_DISCOVER_DESCR="NuttX"
+# CONFIG_NETUTILS_ESP8266 is not set
+# CONFIG_NETUTILS_FTPC is not set
+# CONFIG_NETUTILS_FTPD is not set
+# CONFIG_NETUTILS_JSON is not set
+CONFIG_NETUTILS_NETLIB=y
+# CONFIG_NETUTILS_NTPCLIENT is not set
+# CONFIG_NETUTILS_PPPD is not set
+# CONFIG_NETUTILS_SMTP is not set
+CONFIG_NETUTILS_TELNETD=y
+# CONFIG_NETUTILS_TFTPC is not set
+# CONFIG_NETUTILS_WEBCLIENT is not set
+# CONFIG_NETUTILS_WEBSERVER is not set
+# CONFIG_NETUTILS_XMLRPC is not set
+
+#
+# NSH Library
+#
+# CONFIG_NSH_LIBRARY is not set
+
+#
+# Platform-specific Support
+#
+# CONFIG_PLATFORM_CONFIGDATA is not set
+
+#
+# System Libraries and NSH Add-Ons
+#
+# CONFIG_SYSTEM_CLE is not set
+# CONFIG_SYSTEM_CUTERM is not set
+# CONFIG_SYSTEM_FREE is not set
+# CONFIG_SYSTEM_HEX2BIN is not set
+# CONFIG_SYSTEM_HEXED is not set
+# CONFIG_SYSTEM_INSTALL is not set
+# CONFIG_SYSTEM_NETDB is not set
+# CONFIG_SYSTEM_RAMTEST is not set
+# CONFIG_READLINE_HAVE_EXTMATCH is not set
+# CONFIG_SYSTEM_READLINE is not set
+# CONFIG_SYSTEM_SUDOKU is not set
+# CONFIG_SYSTEM_TEE is not set
+# CONFIG_SYSTEM_UBLOXMODEM is not set
+# CONFIG_SYSTEM_VI is not set
+# CONFIG_SYSTEM_ZMODEM is not set
\ No newline at end of file
diff --git a/configs/olimex-stm32-e407/telnetd/setenv.sh b/configs/olimex-stm32-e407/telnetd/setenv.sh
new file mode 100755
index 0000000000..62aa001c6e
--- /dev/null
+++ b/configs/olimex-stm32-e407/telnetd/setenv.sh
@@ -0,0 +1,80 @@
+#!/bin/bash
+# configs/olimex-stm32-e407/telnetd/setenv.sh
+#
+# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved.
+# Author: Gregory Nutt
+#
+# 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.
+#
+
+if [ "$_" = "$0" ] ; then
+ echo "You must source this script, not run it!" 1>&2
+ exit 1
+fi
+
+WD=`pwd`
+if [ ! -x "setenv.sh" ]; then
+ echo "This script must be executed from the top-level NuttX build directory"
+ exit 1
+fi
+
+if [ -z "${PATH_ORIG}" ]; then
+ export PATH_ORIG="${PATH}"
+fi
+
+# This is the Cygwin path to the location where I installed the RIDE
+# toolchain under windows. You will also have to edit this if you install
+# the RIDE toolchain in any other location
+#export TOOLCHAIN_BIN="/cygdrive/c/Program Files (x86)/Raisonance/Ride/arm-gcc/bin"
+
+# This is the Cygwin path to the location where I installed the CodeSourcery
+# toolchain under windows. You will also have to edit this if you install
+# the CodeSourcery toolchain in any other location
+export TOOLCHAIN_BIN="/cygdrive/c/Program Files (x86)/CodeSourcery/Sourcery G++ Lite/bin"
+#export TOOLCHAIN_BIN="/cygdrive/c/Users/MyName/MentorGraphics/Sourcery_CodeBench_Lite_for_ARM_EABI/bin"
+
+# This is the location where I installed the ARM "GNU Tools for ARM Embedded Processors"
+# You can this free toolchain here https://launchpad.net/gcc-arm-embedded
+#export TOOLCHAIN_BIN="/cygdrive/c/Program Files (x86)/GNU Tools ARM Embedded/4.9 2015q2/bin"
+
+# These are the Cygwin paths to the locations where I installed the Atollic
+# toolchain under windows. You will also have to edit this if you install
+# the Atollic toolchain in any other location. /usr/bin is added before
+# the Atollic bin path because there is are binaries named gcc.exe and g++.exe
+# at those locations as well.
+#export TOOLCHAIN_BIN="/usr/bin:/cygdrive/c/Program Files (x86)/Atollic/TrueSTUDIO for ARM Pro 2.3.0/ARMTools/bin"
+#export TOOLCHAIN_BIN="/usr/bin:/cygdrive/c/Program Files (x86)/Atollic/TrueSTUDIO for STMicroelectronics STM32 Lite 2.3.0/ARMTools/bin"
+
+# This is the Cygwin path to the location where I build the buildroot
+# toolchain.
+#export TOOLCHAIN_BIN="${WD}/../buildroot/build_arm_nofpu/staging_dir/bin"
+
+# Add the path to the toolchain to the PATH variable
+export PATH="${TOOLCHAIN_BIN}:/sbin:/usr/sbin:${PATH_ORIG}"
+
+echo "PATH : ${PATH}"
diff --git a/configs/olimex-stm32-e407/webserver/Make.defs b/configs/olimex-stm32-e407/webserver/Make.defs
new file mode 100644
index 0000000000..621d215e24
--- /dev/null
+++ b/configs/olimex-stm32-e407/webserver/Make.defs
@@ -0,0 +1,112 @@
+############################################################################
+# configs/olimex-stm32-e407/webserver/Make.defs
+#
+# Copyright (C) 2011-2012, 2016 Gregory Nutt. All rights reserved.
+# Author: Gregory Nutt
+#
+# 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
+
+LDSCRIPT = ld.script
+
+ifeq ($(WINTOOL),y)
+ # Windows-native toolchains
+ DIRLINK = $(TOPDIR)/tools/copydir.sh
+ DIRUNLINK = $(TOPDIR)/tools/unlink.sh
+ MKDEP = $(TOPDIR)/tools/mkwindeps.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/$(LDSCRIPT)}"
+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/$(LDSCRIPT)
+endif
+
+CC = $(CROSSDEV)gcc
+CXX = $(CROSSDEV)g++
+CPP = $(CROSSDEV)gcc -E
+LD = $(CROSSDEV)ld
+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
+
+
+HOSTCC = gcc
+HOSTINCLUDES = -I.
+HOSTCFLAGS = -Wall -Wstrict-prototypes -Wshadow -Wundef -g -pipe
+HOSTLDFLAGS =
diff --git a/configs/olimex-stm32-e407/webserver/defconfig b/configs/olimex-stm32-e407/webserver/defconfig
new file mode 100644
index 0000000000..9ba20f2d5c
--- /dev/null
+++ b/configs/olimex-stm32-e407/webserver/defconfig
@@ -0,0 +1,1309 @@
+#
+# Automatically generated file; DO NOT EDIT.
+# Nuttx/ Configuration
+#
+
+#
+# Build Setup
+#
+# CONFIG_EXPERIMENTAL is not set
+# CONFIG_DEFAULT_SMALL is not set
+CONFIG_HOST_LINUX=y
+# CONFIG_HOST_OSX is not set
+# CONFIG_HOST_WINDOWS is not set
+# CONFIG_HOST_OTHER is not set
+
+#
+# Build Configuration
+#
+CONFIG_APPS_DIR="../apps"
+CONFIG_BUILD_FLAT=y
+# CONFIG_BUILD_2PASS is not set
+
+#
+# Binary Output Formats
+#
+# CONFIG_RRLOAD_BINARY is not set
+CONFIG_INTELHEX_BINARY=y
+# CONFIG_MOTOROLA_SREC is not set
+CONFIG_RAW_BINARY=y
+# CONFIG_UBOOT_UIMAGE is not set
+
+#
+# Customize Header Files
+#
+# CONFIG_ARCH_STDINT_H is not set
+# CONFIG_ARCH_STDBOOL_H is not set
+# CONFIG_ARCH_MATH_H is not set
+# CONFIG_ARCH_FLOAT_H is not set
+# CONFIG_ARCH_STDARG_H is not set
+# CONFIG_ARCH_DEBUG_H is not set
+
+#
+# Debug Options
+#
+CONFIG_DEBUG_ALERT=y
+# CONFIG_DEBUG_FEATURES is not set
+CONFIG_ARCH_HAVE_STACKCHECK=y
+# CONFIG_STACK_COLORATION is not set
+CONFIG_ARCH_HAVE_HEAPCHECK=y
+# CONFIG_HEAP_COLORATION is not set
+CONFIG_DEBUG_SYMBOLS=y
+CONFIG_ARCH_HAVE_CUSTOMOPT=y
+# CONFIG_DEBUG_NOOPT is not set
+# CONFIG_DEBUG_CUSTOMOPT is not set
+CONFIG_DEBUG_FULLOPT=y
+
+#
+# System Type
+#
+CONFIG_ARCH_ARM=y
+# CONFIG_ARCH_AVR is not set
+# CONFIG_ARCH_HC is not set
+# CONFIG_ARCH_MIPS is not set
+# CONFIG_ARCH_RGMP is not set
+# CONFIG_ARCH_RENESAS is not set
+# CONFIG_ARCH_SIM is not set
+# CONFIG_ARCH_X86 is not set
+# CONFIG_ARCH_Z16 is not set
+# CONFIG_ARCH_Z80 is not set
+CONFIG_ARCH="arm"
+
+#
+# ARM Options
+#
+# CONFIG_ARCH_CHIP_A1X is not set
+# CONFIG_ARCH_CHIP_C5471 is not set
+# CONFIG_ARCH_CHIP_CALYPSO is not set
+# CONFIG_ARCH_CHIP_DM320 is not set
+# CONFIG_ARCH_CHIP_EFM32 is not set
+# CONFIG_ARCH_CHIP_IMX1 is not set
+# CONFIG_ARCH_CHIP_IMX6 is not set
+# CONFIG_ARCH_CHIP_KINETIS is not set
+# CONFIG_ARCH_CHIP_KL is not set
+# CONFIG_ARCH_CHIP_LM is not set
+# CONFIG_ARCH_CHIP_TIVA is not set
+# CONFIG_ARCH_CHIP_LPC11XX is not set
+# CONFIG_ARCH_CHIP_LPC17XX is not set
+# CONFIG_ARCH_CHIP_LPC214X is not set
+# CONFIG_ARCH_CHIP_LPC2378 is not set
+# CONFIG_ARCH_CHIP_LPC31XX is not set
+# CONFIG_ARCH_CHIP_LPC43XX is not set
+# CONFIG_ARCH_CHIP_NUC1XX is not set
+# CONFIG_ARCH_CHIP_SAMA5 is not set
+# CONFIG_ARCH_CHIP_SAMD is not set
+# CONFIG_ARCH_CHIP_SAML is not set
+# CONFIG_ARCH_CHIP_SAM34 is not set
+# CONFIG_ARCH_CHIP_SAMV7 is not set
+CONFIG_ARCH_CHIP_STM32=y
+# CONFIG_ARCH_CHIP_STM32F7 is not set
+# CONFIG_ARCH_CHIP_STM32L4 is not set
+# CONFIG_ARCH_CHIP_STR71X is not set
+# CONFIG_ARCH_CHIP_TMS570 is not set
+# CONFIG_ARCH_CHIP_MOXART is not set
+# CONFIG_ARCH_ARM7TDMI is not set
+# CONFIG_ARCH_ARM926EJS is not set
+# CONFIG_ARCH_ARM920T is not set
+# CONFIG_ARCH_CORTEXM0 is not set
+# CONFIG_ARCH_CORTEXM3 is not set
+CONFIG_ARCH_CORTEXM4=y
+# CONFIG_ARCH_CORTEXM7 is not set
+# CONFIG_ARCH_CORTEXA5 is not set
+# CONFIG_ARCH_CORTEXA8 is not set
+# CONFIG_ARCH_CORTEXA9 is not set
+# CONFIG_ARCH_CORTEXR4 is not set
+# CONFIG_ARCH_CORTEXR4F is not set
+# CONFIG_ARCH_CORTEXR5 is not set
+# CONFIG_ARCH_CORTEX5F is not set
+# CONFIG_ARCH_CORTEXR7 is not set
+# CONFIG_ARCH_CORTEXR7F is not set
+CONFIG_ARCH_FAMILY="armv7-m"
+CONFIG_ARCH_CHIP="stm32"
+# CONFIG_ARM_TOOLCHAIN_IAR is not set
+CONFIG_ARM_TOOLCHAIN_GNU=y
+# CONFIG_ARMV7M_USEBASEPRI is not set
+CONFIG_ARCH_HAVE_CMNVECTOR=y
+# CONFIG_ARMV7M_CMNVECTOR is not set
+# CONFIG_ARMV7M_LAZYFPU is not set
+CONFIG_ARCH_HAVE_FPU=y
+# CONFIG_ARCH_HAVE_DPFPU is not set
+# CONFIG_ARCH_FPU is not set
+# CONFIG_ARCH_HAVE_TRUSTZONE is not set
+CONFIG_ARM_HAVE_MPU_UNIFIED=y
+# CONFIG_ARM_MPU is not set
+
+#
+# ARMV7M Configuration Options
+#
+# CONFIG_ARMV7M_HAVE_ICACHE is not set
+# CONFIG_ARMV7M_HAVE_DCACHE is not set
+# CONFIG_ARMV7M_HAVE_ITCM is not set
+# CONFIG_ARMV7M_HAVE_DTCM is not set
+# CONFIG_ARMV7M_TOOLCHAIN_IARL is not set
+CONFIG_ARMV7M_TOOLCHAIN_BUILDROOT=y
+# CONFIG_ARMV7M_TOOLCHAIN_CODEREDL is not set
+# CONFIG_ARMV7M_TOOLCHAIN_CODESOURCERYL is not set
+# CONFIG_ARMV7M_TOOLCHAIN_GNU_EABIL is not set
+# CONFIG_ARMV7M_OABI_TOOLCHAIN is not set
+CONFIG_ARMV7M_HAVE_STACKCHECK=y
+# CONFIG_ARMV7M_STACKCHECK is not set
+# CONFIG_ARMV7M_ITMSYSLOG is not set
+# CONFIG_SERIAL_TERMIOS is not set
+
+#
+# STM32 Configuration Options
+#
+# CONFIG_ARCH_CHIP_STM32L151C6 is not set
+# CONFIG_ARCH_CHIP_STM32L151C8 is not set
+# CONFIG_ARCH_CHIP_STM32L151CB is not set
+# CONFIG_ARCH_CHIP_STM32L151R6 is not set
+# CONFIG_ARCH_CHIP_STM32L151R8 is not set
+# CONFIG_ARCH_CHIP_STM32L151RB is not set
+# CONFIG_ARCH_CHIP_STM32L151V6 is not set
+# CONFIG_ARCH_CHIP_STM32L151V8 is not set
+# CONFIG_ARCH_CHIP_STM32L151VB is not set
+# CONFIG_ARCH_CHIP_STM32L152C6 is not set
+# CONFIG_ARCH_CHIP_STM32L152C8 is not set
+# CONFIG_ARCH_CHIP_STM32L152CB is not set
+# CONFIG_ARCH_CHIP_STM32L152R6 is not set
+# CONFIG_ARCH_CHIP_STM32L152R8 is not set
+# CONFIG_ARCH_CHIP_STM32L152RB is not set
+# CONFIG_ARCH_CHIP_STM32L152V6 is not set
+# CONFIG_ARCH_CHIP_STM32L152V8 is not set
+# CONFIG_ARCH_CHIP_STM32L152VB is not set
+# CONFIG_ARCH_CHIP_STM32L162ZD is not set
+# CONFIG_ARCH_CHIP_STM32L162VE is not set
+# CONFIG_ARCH_CHIP_STM32F100C8 is not set
+# CONFIG_ARCH_CHIP_STM32F100CB is not set
+# CONFIG_ARCH_CHIP_STM32F100R8 is not set
+# CONFIG_ARCH_CHIP_STM32F100RB is not set
+# CONFIG_ARCH_CHIP_STM32F100RC is not set
+# CONFIG_ARCH_CHIP_STM32F100RD is not set
+# CONFIG_ARCH_CHIP_STM32F100RE is not set
+# CONFIG_ARCH_CHIP_STM32F100V8 is not set
+# CONFIG_ARCH_CHIP_STM32F100VB is not set
+# CONFIG_ARCH_CHIP_STM32F100VC is not set
+# CONFIG_ARCH_CHIP_STM32F100VD is not set
+# CONFIG_ARCH_CHIP_STM32F100VE is not set
+# CONFIG_ARCH_CHIP_STM32F102CB is not set
+# CONFIG_ARCH_CHIP_STM32F103T8 is not set
+# CONFIG_ARCH_CHIP_STM32F103TB is not set
+# CONFIG_ARCH_CHIP_STM32F103C4 is not set
+# CONFIG_ARCH_CHIP_STM32F103C8 is not set
+# CONFIG_ARCH_CHIP_STM32F103CB is not set
+# CONFIG_ARCH_CHIP_STM32F103R8 is not set
+# CONFIG_ARCH_CHIP_STM32F103RB is not set
+# CONFIG_ARCH_CHIP_STM32F103RC is not set
+# CONFIG_ARCH_CHIP_STM32F103RD is not set
+# CONFIG_ARCH_CHIP_STM32F103RE is not set
+# CONFIG_ARCH_CHIP_STM32F103RG is not set
+# CONFIG_ARCH_CHIP_STM32F103V8 is not set
+# CONFIG_ARCH_CHIP_STM32F103VB is not set
+# CONFIG_ARCH_CHIP_STM32F103VC is not set
+# CONFIG_ARCH_CHIP_STM32F103VE is not set
+# CONFIG_ARCH_CHIP_STM32F103ZE is not set
+# CONFIG_ARCH_CHIP_STM32F105VB is not set
+# CONFIG_ARCH_CHIP_STM32F105RB is not set
+# CONFIG_ARCH_CHIP_STM32F107VC is not set
+# CONFIG_ARCH_CHIP_STM32F205RG is not set
+# CONFIG_ARCH_CHIP_STM32F207IG is not set
+# CONFIG_ARCH_CHIP_STM32F207ZE is not set
+# CONFIG_ARCH_CHIP_STM32F302K6 is not set
+# CONFIG_ARCH_CHIP_STM32F302K8 is not set
+# CONFIG_ARCH_CHIP_STM32F302CB is not set
+# CONFIG_ARCH_CHIP_STM32F302CC is not set
+# CONFIG_ARCH_CHIP_STM32F302RB is not set
+# CONFIG_ARCH_CHIP_STM32F302RC is not set
+# CONFIG_ARCH_CHIP_STM32F302VB is not set
+# CONFIG_ARCH_CHIP_STM32F302VC is not set
+# CONFIG_ARCH_CHIP_STM32F303K6 is not set
+# CONFIG_ARCH_CHIP_STM32F303K8 is not set
+# CONFIG_ARCH_CHIP_STM32F303C6 is not set
+# CONFIG_ARCH_CHIP_STM32F303C8 is not set
+# CONFIG_ARCH_CHIP_STM32F303CB is not set
+# CONFIG_ARCH_CHIP_STM32F303CC is not set
+# CONFIG_ARCH_CHIP_STM32F303RB is not set
+# CONFIG_ARCH_CHIP_STM32F303RC is not set
+# CONFIG_ARCH_CHIP_STM32F303RD is not set
+# CONFIG_ARCH_CHIP_STM32F303RE is not set
+# CONFIG_ARCH_CHIP_STM32F303VB is not set
+# CONFIG_ARCH_CHIP_STM32F303VC is not set
+# CONFIG_ARCH_CHIP_STM32F372C8 is not set
+# CONFIG_ARCH_CHIP_STM32F372R8 is not set
+# CONFIG_ARCH_CHIP_STM32F372V8 is not set
+# CONFIG_ARCH_CHIP_STM32F372CB is not set
+# CONFIG_ARCH_CHIP_STM32F372RB is not set
+# CONFIG_ARCH_CHIP_STM32F372VB is not set
+# CONFIG_ARCH_CHIP_STM32F372CC is not set
+# CONFIG_ARCH_CHIP_STM32F372RC is not set
+# CONFIG_ARCH_CHIP_STM32F372VC is not set
+# CONFIG_ARCH_CHIP_STM32F373C8 is not set
+# CONFIG_ARCH_CHIP_STM32F373R8 is not set
+# CONFIG_ARCH_CHIP_STM32F373V8 is not set
+# CONFIG_ARCH_CHIP_STM32F373CB is not set
+# CONFIG_ARCH_CHIP_STM32F373RB is not set
+# CONFIG_ARCH_CHIP_STM32F373VB is not set
+# CONFIG_ARCH_CHIP_STM32F373CC is not set
+# CONFIG_ARCH_CHIP_STM32F373RC is not set
+# CONFIG_ARCH_CHIP_STM32F373VC is not set
+# CONFIG_ARCH_CHIP_STM32F401RE is not set
+# CONFIG_ARCH_CHIP_STM32F411RE is not set
+# CONFIG_ARCH_CHIP_STM32F411VE is not set
+# CONFIG_ARCH_CHIP_STM32F405RG is not set
+# CONFIG_ARCH_CHIP_STM32F405VG is not set
+# CONFIG_ARCH_CHIP_STM32F405ZG is not set
+# CONFIG_ARCH_CHIP_STM32F407VE is not set
+# CONFIG_ARCH_CHIP_STM32F407VG is not set
+# CONFIG_ARCH_CHIP_STM32F407ZE is not set
+CONFIG_ARCH_CHIP_STM32F407ZG=y
+# CONFIG_ARCH_CHIP_STM32F407IE is not set
+# CONFIG_ARCH_CHIP_STM32F407IG is not set
+# CONFIG_ARCH_CHIP_STM32F427V is not set
+# CONFIG_ARCH_CHIP_STM32F427Z is not set
+# CONFIG_ARCH_CHIP_STM32F427I is not set
+# CONFIG_ARCH_CHIP_STM32F429V is not set
+# CONFIG_ARCH_CHIP_STM32F429Z is not set
+# CONFIG_ARCH_CHIP_STM32F429I is not set
+# CONFIG_ARCH_CHIP_STM32F429B is not set
+# CONFIG_ARCH_CHIP_STM32F429N is not set
+# CONFIG_ARCH_CHIP_STM32F446M is not set
+# CONFIG_ARCH_CHIP_STM32F446R is not set
+# CONFIG_ARCH_CHIP_STM32F446V is not set
+# CONFIG_ARCH_CHIP_STM32F446Z is not set
+# CONFIG_ARCH_CHIP_STM32F469A is not set
+# CONFIG_ARCH_CHIP_STM32F469I is not set
+# CONFIG_ARCH_CHIP_STM32F469B is not set
+# CONFIG_ARCH_CHIP_STM32F469N is not set
+CONFIG_STM32_FLASH_CONFIG_DEFAULT=y
+# CONFIG_STM32_FLASH_CONFIG_4 is not set
+# CONFIG_STM32_FLASH_CONFIG_6 is not set
+# CONFIG_STM32_FLASH_CONFIG_8 is not set
+# CONFIG_STM32_FLASH_CONFIG_B is not set
+# CONFIG_STM32_FLASH_CONFIG_C is not set
+# CONFIG_STM32_FLASH_CONFIG_D is not set
+# CONFIG_STM32_FLASH_CONFIG_E is not set
+# CONFIG_STM32_FLASH_CONFIG_F is not set
+# CONFIG_STM32_FLASH_CONFIG_G is not set
+# CONFIG_STM32_FLASH_CONFIG_I is not set
+# CONFIG_STM32_STM32L15XX is not set
+# CONFIG_STM32_ENERGYLITE is not set
+# CONFIG_STM32_STM32F10XX is not set
+# CONFIG_STM32_VALUELINE is not set
+# CONFIG_STM32_CONNECTIVITYLINE is not set
+# CONFIG_STM32_PERFORMANCELINE is not set
+# CONFIG_STM32_USBACCESSLINE is not set
+# CONFIG_STM32_HIGHDENSITY is not set
+# CONFIG_STM32_MEDIUMDENSITY is not set
+# CONFIG_STM32_LOWDENSITY is not set
+# CONFIG_STM32_STM32F20XX is not set
+# CONFIG_STM32_STM32F205 is not set
+# CONFIG_STM32_STM32F207 is not set
+# CONFIG_STM32_STM32F30XX is not set
+# CONFIG_STM32_STM32F302 is not set
+# CONFIG_STM32_STM32F303 is not set
+# CONFIG_STM32_STM32F37XX is not set
+CONFIG_STM32_STM32F40XX=y
+# CONFIG_STM32_STM32F401 is not set
+# CONFIG_STM32_STM32F411 is not set
+# CONFIG_STM32_STM32F405 is not set
+CONFIG_STM32_STM32F407=y
+# CONFIG_STM32_STM32F427 is not set
+# CONFIG_STM32_STM32F429 is not set
+# CONFIG_STM32_STM32F446 is not set
+# CONFIG_STM32_STM32F469 is not set
+# CONFIG_STM32_DFU is not set
+
+#
+# STM32 Peripheral Support
+#
+CONFIG_STM32_HAVE_CCM=y
+# CONFIG_STM32_HAVE_USBDEV is not set
+CONFIG_STM32_HAVE_OTGFS=y
+CONFIG_STM32_HAVE_FSMC=y
+# CONFIG_STM32_HAVE_LTDC is not set
+CONFIG_STM32_HAVE_USART3=y
+CONFIG_STM32_HAVE_UART4=y
+CONFIG_STM32_HAVE_UART5=y
+CONFIG_STM32_HAVE_USART6=y
+# CONFIG_STM32_HAVE_UART7 is not set
+# CONFIG_STM32_HAVE_UART8 is not set
+CONFIG_STM32_HAVE_TIM1=y
+CONFIG_STM32_HAVE_TIM2=y
+CONFIG_STM32_HAVE_TIM3=y
+CONFIG_STM32_HAVE_TIM4=y
+CONFIG_STM32_HAVE_TIM5=y
+CONFIG_STM32_HAVE_TIM6=y
+CONFIG_STM32_HAVE_TIM7=y
+CONFIG_STM32_HAVE_TIM8=y
+CONFIG_STM32_HAVE_TIM9=y
+CONFIG_STM32_HAVE_TIM10=y
+CONFIG_STM32_HAVE_TIM11=y
+CONFIG_STM32_HAVE_TIM12=y
+CONFIG_STM32_HAVE_TIM13=y
+CONFIG_STM32_HAVE_TIM14=y
+# CONFIG_STM32_HAVE_TIM15 is not set
+# CONFIG_STM32_HAVE_TIM16 is not set
+# CONFIG_STM32_HAVE_TIM17 is not set
+CONFIG_STM32_HAVE_ADC2=y
+CONFIG_STM32_HAVE_ADC3=y
+# CONFIG_STM32_HAVE_ADC4 is not set
+# CONFIG_STM32_HAVE_ADC1_DMA is not set
+# CONFIG_STM32_HAVE_ADC2_DMA is not set
+# CONFIG_STM32_HAVE_ADC3_DMA is not set
+# CONFIG_STM32_HAVE_ADC4_DMA is not set
+CONFIG_STM32_HAVE_CAN1=y
+CONFIG_STM32_HAVE_CAN2=y
+CONFIG_STM32_HAVE_DAC1=y
+CONFIG_STM32_HAVE_DAC2=y
+CONFIG_STM32_HAVE_RNG=y
+CONFIG_STM32_HAVE_ETHMAC=y
+CONFIG_STM32_HAVE_I2C2=y
+CONFIG_STM32_HAVE_I2C3=y
+CONFIG_STM32_HAVE_SPI2=y
+CONFIG_STM32_HAVE_SPI3=y
+# CONFIG_STM32_HAVE_SPI4 is not set
+# CONFIG_STM32_HAVE_SPI5 is not set
+# CONFIG_STM32_HAVE_SPI6 is not set
+# CONFIG_STM32_HAVE_SAIPLL is not set
+# CONFIG_STM32_HAVE_I2SPLL is not set
+# CONFIG_STM32_ADC1 is not set
+# CONFIG_STM32_ADC2 is not set
+# CONFIG_STM32_ADC3 is not set
+# CONFIG_STM32_BKPSRAM is not set
+# CONFIG_STM32_CAN1 is not set
+# CONFIG_STM32_CAN2 is not set
+# CONFIG_STM32_CCMDATARAM is not set
+# CONFIG_STM32_CRC is not set
+# CONFIG_STM32_CRYP is not set
+# CONFIG_STM32_DMA1 is not set
+# CONFIG_STM32_DMA2 is not set
+# CONFIG_STM32_DAC1 is not set
+# CONFIG_STM32_DAC2 is not set
+# CONFIG_STM32_DCMI is not set
+CONFIG_STM32_ETHMAC=y
+# CONFIG_STM32_FSMC is not set
+# CONFIG_STM32_HASH is not set
+# CONFIG_STM32_I2C1 is not set
+# CONFIG_STM32_I2C2 is not set
+# CONFIG_STM32_I2C3 is not set
+# CONFIG_STM32_OTGFS is not set
+# CONFIG_STM32_OTGHS is not set
+CONFIG_STM32_PWR=y
+# CONFIG_STM32_RNG is not set
+# CONFIG_STM32_SDIO is not set
+# CONFIG_STM32_SPI1 is not set
+# CONFIG_STM32_SPI2 is not set
+# CONFIG_STM32_SPI3 is not set
+CONFIG_STM32_SYSCFG=y
+# CONFIG_STM32_TIM1 is not set
+# CONFIG_STM32_TIM2 is not set
+# CONFIG_STM32_TIM3 is not set
+# CONFIG_STM32_TIM4 is not set
+# CONFIG_STM32_TIM5 is not set
+# CONFIG_STM32_TIM6 is not set
+# CONFIG_STM32_TIM7 is not set
+# CONFIG_STM32_TIM8 is not set
+# CONFIG_STM32_TIM9 is not set
+# CONFIG_STM32_TIM10 is not set
+# CONFIG_STM32_TIM11 is not set
+# CONFIG_STM32_TIM12 is not set
+# CONFIG_STM32_TIM13 is not set
+# CONFIG_STM32_TIM14 is not set
+# CONFIG_STM32_USART1 is not set
+CONFIG_STM32_USART2=y
+# CONFIG_STM32_USART3 is not set
+# CONFIG_STM32_UART4 is not set
+# CONFIG_STM32_UART5 is not set
+# CONFIG_STM32_USART6 is not set
+# CONFIG_STM32_IWDG is not set
+# CONFIG_STM32_WWDG is not set
+# CONFIG_STM32_NOEXT_VECTORS is not set
+
+#
+# Alternate Pin Mapping
+#
+# CONFIG_STM32_FLASH_PREFETCH is not set
+# CONFIG_STM32_JTAG_DISABLE is not set
+CONFIG_STM32_JTAG_FULL_ENABLE=y
+# CONFIG_STM32_JTAG_NOJNTRST_ENABLE is not set
+# CONFIG_STM32_JTAG_SW_ENABLE is not set
+CONFIG_STM32_DISABLE_IDLE_SLEEP_DURING_DEBUG=y
+# CONFIG_STM32_FORCEPOWER is not set
+# CONFIG_ARCH_BOARD_STM32_CUSTOM_CLOCKCONFIG is not set
+# CONFIG_STM32_CCMEXCLUDE is not set
+
+#
+# Timer Configuration
+#
+# CONFIG_STM32_ONESHOT is not set
+# CONFIG_STM32_FREERUN is not set
+# CONFIG_STM32_TIM1_CAP is not set
+# CONFIG_STM32_TIM2_CAP is not set
+# CONFIG_STM32_TIM3_CAP is not set
+# CONFIG_STM32_TIM4_CAP is not set
+# CONFIG_STM32_TIM5_CAP is not set
+# CONFIG_STM32_TIM8_CAP is not set
+# CONFIG_STM32_TIM9_CAP is not set
+# CONFIG_STM32_TIM10_CAP is not set
+# CONFIG_STM32_TIM11_CAP is not set
+# CONFIG_STM32_TIM12_CAP is not set
+# CONFIG_STM32_TIM13_CAP is not set
+# CONFIG_STM32_TIM14_CAP is not set
+CONFIG_STM32_USART=y
+CONFIG_STM32_SERIALDRIVER=y
+
+#
+# U[S]ART Configuration
+#
+
+#
+# U[S]ART Device Configuration
+#
+CONFIG_STM32_USART2_SERIALDRIVER=y
+# CONFIG_STM32_USART2_1WIREDRIVER is not set
+# CONFIG_USART2_RS485 is not set
+
+#
+# Serial Driver Configuration
+#
+# CONFIG_SERIAL_DISABLE_REORDERING is not set
+# CONFIG_STM32_FLOWCONTROL_BROKEN is not set
+# CONFIG_STM32_USART_BREAKS is not set
+# CONFIG_STM32_USART_SINGLEWIRE is not set
+# CONFIG_STM32_HAVE_RTC_COUNTER is not set
+# CONFIG_STM32_HAVE_RTC_SUBSECONDS is not set
+
+#
+# Ethernet MAC configuration
+#
+CONFIG_STM32_PHYADDR=0
+# CONFIG_STM32_PHYINIT is not set
+# CONFIG_STM32_MII is not set
+CONFIG_STM32_AUTONEG=y
+CONFIG_STM32_PHYSR=31
+CONFIG_STM32_PHYSR_ALTCONFIG=y
+CONFIG_STM32_PHYSR_ALTMODE=0x001c
+CONFIG_STM32_PHYSR_10HD=0x0004
+CONFIG_STM32_PHYSR_100HD=0x0008
+CONFIG_STM32_PHYSR_10FD=0x0014
+CONFIG_STM32_PHYSR_100FD=0x0018
+# CONFIG_STM32_ETH_PTP is not set
+CONFIG_STM32_RMII=y
+# CONFIG_STM32_RMII_MCO1 is not set
+# CONFIG_STM32_RMII_MCO2 is not set
+CONFIG_STM32_RMII_EXTCLK=y
+
+#
+# USB FS Host Configuration
+#
+
+#
+# USB HS Host Configuration
+#
+
+#
+# USB Host Debug Configuration
+#
+
+#
+# USB Device Configuration
+#
+
+#
+# Architecture Options
+#
+# CONFIG_ARCH_NOINTC is not set
+# CONFIG_ARCH_VECNOTIRQ is not set
+# CONFIG_ARCH_DMA is not set
+CONFIG_ARCH_HAVE_IRQPRIO=y
+# CONFIG_ARCH_L2CACHE is not set
+# CONFIG_ARCH_HAVE_COHERENT_DCACHE is not set
+# CONFIG_ARCH_HAVE_ADDRENV is not set
+# CONFIG_ARCH_NEED_ADDRENV_MAPPING is not set
+# CONFIG_ARCH_HAVE_MULTICPU is not set
+CONFIG_ARCH_HAVE_VFORK=y
+# CONFIG_ARCH_HAVE_MMU is not set
+CONFIG_ARCH_HAVE_MPU=y
+# CONFIG_ARCH_NAND_HWECC is not set
+# CONFIG_ARCH_HAVE_EXTCLK is not set
+# CONFIG_ARCH_HAVE_POWEROFF is not set
+CONFIG_ARCH_HAVE_RESET=y
+# CONFIG_ARCH_USE_MPU is not set
+# CONFIG_ARCH_IRQPRIO is not set
+CONFIG_ARCH_STACKDUMP=y
+# CONFIG_ENDIAN_BIG is not set
+# CONFIG_ARCH_IDLE_CUSTOM is not set
+# CONFIG_ARCH_HAVE_RAMFUNCS is not set
+CONFIG_ARCH_HAVE_RAMVECTORS=y
+# CONFIG_ARCH_RAMVECTORS is not set
+
+#
+# Board Settings
+#
+CONFIG_BOARD_LOOPSPERMSEC=16717
+# CONFIG_ARCH_CALIBRATION is not set
+
+#
+# Interrupt options
+#
+CONFIG_ARCH_HAVE_INTERRUPTSTACK=y
+CONFIG_ARCH_INTERRUPTSTACK=0
+CONFIG_ARCH_HAVE_HIPRI_INTERRUPT=y
+# CONFIG_ARCH_HIPRI_INTERRUPT is not set
+
+#
+# Boot options
+#
+# CONFIG_BOOT_RUNFROMEXTSRAM is not set
+CONFIG_BOOT_RUNFROMFLASH=y
+# CONFIG_BOOT_RUNFROMISRAM is not set
+# CONFIG_BOOT_RUNFROMSDRAM is not set
+# CONFIG_BOOT_COPYTORAM is not set
+
+#
+# Boot Memory Configuration
+#
+CONFIG_RAM_START=0x20000000
+CONFIG_RAM_SIZE=114688
+# CONFIG_ARCH_HAVE_SDRAM is not set
+
+#
+# Board Selection
+#
+# CONFIG_ARCH_BOARD_OLIMEX_STM32H407 is not set
+CONFIG_ARCH_BOARD_OLIMEX_STM32E407=y
+# CONFIG_ARCH_BOARD_CUSTOM is not set
+CONFIG_ARCH_BOARD="olimex-stm32-e407"
+
+#
+# Common Board Options
+#
+CONFIG_ARCH_HAVE_LEDS=y
+CONFIG_ARCH_LEDS=y
+CONFIG_ARCH_HAVE_BUTTONS=y
+CONFIG_ARCH_BUTTONS=y
+CONFIG_ARCH_HAVE_IRQBUTTONS=y
+# CONFIG_ARCH_IRQBUTTONS is not set
+
+#
+# Board-Specific Options
+#
+# CONFIG_BOARD_CRASHDUMP is not set
+# CONFIG_LIB_BOARDCTL is not set
+
+#
+# RTOS Features
+#
+CONFIG_DISABLE_OS_API=y
+# CONFIG_DISABLE_POSIX_TIMERS is not set
+# CONFIG_DISABLE_PTHREAD is not set
+# CONFIG_DISABLE_SIGNALS is not set
+# CONFIG_DISABLE_MQUEUE is not set
+# CONFIG_DISABLE_ENVIRON is not set
+
+#
+# Clocks and Timers
+#
+CONFIG_ARCH_HAVE_TICKLESS=y
+# CONFIG_SCHED_TICKLESS is not set
+CONFIG_USEC_PER_TICK=10000
+# CONFIG_SYSTEM_TIME64 is not set
+# CONFIG_CLOCK_MONOTONIC is not set
+CONFIG_ARCH_HAVE_TIMEKEEPING=y
+# CONFIG_JULIAN_TIME is not set
+CONFIG_START_YEAR=2011
+CONFIG_START_MONTH=12
+CONFIG_START_DAY=6
+CONFIG_MAX_WDOGPARMS=2
+CONFIG_PREALLOC_WDOGS=16
+CONFIG_WDOG_INTRESERVE=4
+CONFIG_PREALLOC_TIMERS=4
+
+#
+# Tasks and Scheduling
+#
+# CONFIG_INIT_NONE is not set
+CONFIG_INIT_ENTRYPOINT=y
+# CONFIG_INIT_FILEPATH is not set
+CONFIG_USER_ENTRYPOINT="webserver_main"
+CONFIG_RR_INTERVAL=200
+# CONFIG_SCHED_SPORADIC is not set
+CONFIG_TASK_NAME_SIZE=31
+CONFIG_MAX_TASKS=16
+# CONFIG_SCHED_HAVE_PARENT is not set
+CONFIG_SCHED_WAITPID=y
+
+#
+# Pthread Options
+#
+# CONFIG_MUTEX_TYPES is not set
+CONFIG_NPTHREAD_KEYS=4
+
+#
+# Performance Monitoring
+#
+# CONFIG_SCHED_CPULOAD is not set
+# CONFIG_SCHED_INSTRUMENTATION is not set
+
+#
+# Files and I/O
+#
+CONFIG_DEV_CONSOLE=y
+# CONFIG_FDCLONE_DISABLE is not set
+# CONFIG_FDCLONE_STDIO is not set
+CONFIG_SDCLONE_DISABLE=y
+CONFIG_NFILE_DESCRIPTORS=8
+CONFIG_NFILE_STREAMS=8
+CONFIG_NAME_MAX=32
+# CONFIG_PRIORITY_INHERITANCE is not set
+
+#
+# RTOS hooks
+#
+# CONFIG_BOARD_INITIALIZE is not set
+# CONFIG_SCHED_STARTHOOK is not set
+# CONFIG_SCHED_ATEXIT is not set
+# CONFIG_SCHED_ONEXIT is not set
+
+#
+# Signal Numbers
+#
+CONFIG_SIG_SIGUSR1=1
+CONFIG_SIG_SIGUSR2=2
+CONFIG_SIG_SIGALARM=3
+CONFIG_SIG_SIGCONDTIMEDOUT=16
+
+#
+# POSIX Message Queue Options
+#
+CONFIG_PREALLOC_MQ_MSGS=4
+CONFIG_MQ_MAXMSGSIZE=32
+# CONFIG_MODULE is not set
+
+#
+# Work queue support
+#
+# CONFIG_SCHED_WORKQUEUE is not set
+# CONFIG_SCHED_HPWORK is not set
+# CONFIG_SCHED_LPWORK is not set
+
+#
+# Stack and heap information
+#
+CONFIG_IDLETHREAD_STACKSIZE=1024
+CONFIG_USERMAIN_STACKSIZE=2048
+CONFIG_PTHREAD_STACK_MIN=256
+CONFIG_PTHREAD_STACK_DEFAULT=2048
+# CONFIG_LIB_SYSCALL is not set
+
+#
+# Device Drivers
+#
+# CONFIG_DISABLE_POLL is not set
+CONFIG_DEV_NULL=y
+# CONFIG_DEV_ZERO is not set
+# CONFIG_DEV_URANDOM is not set
+# CONFIG_DEV_LOOP is not set
+
+#
+# Buffering
+#
+# CONFIG_DRVR_WRITEBUFFER is not set
+# CONFIG_DRVR_READAHEAD is not set
+# CONFIG_RAMDISK is not set
+# CONFIG_CAN is not set
+# CONFIG_ARCH_HAVE_PWM_PULSECOUNT is not set
+# CONFIG_ARCH_HAVE_PWM_MULTICHAN is not set
+# CONFIG_PWM is not set
+CONFIG_ARCH_HAVE_I2CRESET=y
+# CONFIG_I2C is not set
+CONFIG_SPI=y
+# CONFIG_SPI_SLAVE is not set
+CONFIG_SPI_EXCHANGE=y
+# CONFIG_SPI_CMDDATA is not set
+# CONFIG_SPI_CALLBACK is not set
+# CONFIG_SPI_HWFEATURES is not set
+# CONFIG_ARCH_HAVE_SPI_CRCGENERATION is not set
+# CONFIG_ARCH_HAVE_SPI_CS_CONTROL is not set
+CONFIG_ARCH_HAVE_SPI_BITORDER=y
+# CONFIG_SPI_BITORDER is not set
+# CONFIG_SPI_CS_DELAY_CONTROL is not set
+# CONFIG_SPI_DRIVER is not set
+# CONFIG_SPI_BITBANG is not set
+# CONFIG_I2S is not set
+
+#
+# Timer Driver Support
+#
+# CONFIG_TIMER is not set
+# CONFIG_ONESHOT is not set
+# CONFIG_RTC is not set
+# CONFIG_WATCHDOG is not set
+# CONFIG_ANALOG is not set
+# CONFIG_AUDIO_DEVICES is not set
+# CONFIG_VIDEO_DEVICES is not set
+# CONFIG_BCH is not set
+# CONFIG_INPUT is not set
+
+#
+# IO Expander/GPIO Support
+#
+# CONFIG_IOEXPANDER is not set
+# CONFIG_DEV_GPIO is not set
+
+#
+# LCD Driver Support
+#
+# CONFIG_LCD is not set
+# CONFIG_SLCD is not set
+
+#
+# LED Support
+#
+# CONFIG_USERLED is not set
+# CONFIG_RGBLED is not set
+# CONFIG_PCA9635PW is not set
+# CONFIG_NCP5623C is not set
+# CONFIG_MMCSD is not set
+# CONFIG_MODEM is not set
+# CONFIG_MTD is not set
+# CONFIG_EEPROM is not set
+CONFIG_NETDEVICES=y
+
+#
+# General Ethernet MAC Driver Options
+#
+# CONFIG_NETDEV_LOOPBACK is not set
+# CONFIG_NETDEV_TELNET is not set
+# CONFIG_NETDEV_MULTINIC is not set
+# CONFIG_ARCH_HAVE_NETDEV_STATISTICS is not set
+# CONFIG_NETDEV_LATEINIT is not set
+
+#
+# External Ethernet MAC Device Support
+#
+# CONFIG_NET_DM90x0 is not set
+# CONFIG_ENC28J60 is not set
+# CONFIG_ENCX24J600 is not set
+# CONFIG_NET_E1000 is not set
+# CONFIG_NET_SLIP is not set
+# CONFIG_NET_FTMAC100 is not set
+# CONFIG_NET_VNET is not set
+
+#
+# External Ethernet PHY Device Support
+#
+# CONFIG_ARCH_PHY_INTERRUPT is not set
+# CONFIG_ETH0_PHY_NONE is not set
+# CONFIG_ETH0_PHY_AM79C874 is not set
+# CONFIG_ETH0_PHY_KS8721 is not set
+# CONFIG_ETH0_PHY_KSZ8041 is not set
+# CONFIG_ETH0_PHY_KSZ8051 is not set
+# CONFIG_ETH0_PHY_KSZ8061 is not set
+# CONFIG_ETH0_PHY_KSZ8081 is not set
+# CONFIG_ETH0_PHY_KSZ90x1 is not set
+# CONFIG_ETH0_PHY_DP83848C is not set
+CONFIG_ETH0_PHY_LAN8720=y
+# CONFIG_ETH0_PHY_LAN8740 is not set
+# CONFIG_ETH0_PHY_LAN8740A is not set
+# CONFIG_ETH0_PHY_LAN8742A is not set
+# CONFIG_ETH0_PHY_DM9161 is not set
+# CONFIG_PIPES is not set
+# CONFIG_PM is not set
+# CONFIG_POWER is not set
+# CONFIG_SENSORS is not set
+# CONFIG_SERCOMM_CONSOLE is not set
+CONFIG_SERIAL=y
+# CONFIG_DEV_LOWCONSOLE is not set
+# CONFIG_SERIAL_REMOVABLE is not set
+CONFIG_SERIAL_CONSOLE=y
+# CONFIG_16550_UART is not set
+# CONFIG_UART_SERIALDRIVER is not set
+# CONFIG_UART0_SERIALDRIVER is not set
+# CONFIG_UART1_SERIALDRIVER is not set
+# CONFIG_UART2_SERIALDRIVER is not set
+# CONFIG_UART3_SERIALDRIVER is not set
+# CONFIG_UART4_SERIALDRIVER is not set
+# CONFIG_UART5_SERIALDRIVER is not set
+# CONFIG_UART6_SERIALDRIVER is not set
+# CONFIG_UART7_SERIALDRIVER is not set
+# CONFIG_UART8_SERIALDRIVER is not set
+# CONFIG_SCI0_SERIALDRIVER is not set
+# CONFIG_SCI1_SERIALDRIVER is not set
+# CONFIG_USART0_SERIALDRIVER is not set
+# CONFIG_USART1_SERIALDRIVER is not set
+CONFIG_USART2_SERIALDRIVER=y
+# CONFIG_USART3_SERIALDRIVER is not set
+# CONFIG_USART4_SERIALDRIVER is not set
+# CONFIG_USART5_SERIALDRIVER is not set
+# CONFIG_USART6_SERIALDRIVER is not set
+# CONFIG_USART7_SERIALDRIVER is not set
+# CONFIG_USART8_SERIALDRIVER is not set
+# CONFIG_OTHER_UART_SERIALDRIVER is not set
+CONFIG_MCU_SERIAL=y
+CONFIG_STANDARD_SERIAL=y
+CONFIG_SERIAL_NPOLLWAITERS=2
+# CONFIG_SERIAL_IFLOWCONTROL is not set
+# CONFIG_SERIAL_OFLOWCONTROL is not set
+# CONFIG_SERIAL_DMA is not set
+CONFIG_ARCH_HAVE_SERIAL_TERMIOS=y
+CONFIG_USART2_SERIAL_CONSOLE=y
+# CONFIG_OTHER_SERIAL_CONSOLE is not set
+# CONFIG_NO_SERIAL_CONSOLE is not set
+
+#
+# USART2 Configuration
+#
+CONFIG_USART2_RXBUFSIZE=128
+CONFIG_USART2_TXBUFSIZE=128
+CONFIG_USART2_BAUD=115200
+CONFIG_USART2_BITS=8
+CONFIG_USART2_PARITY=0
+CONFIG_USART2_2STOP=0
+# CONFIG_USART2_IFLOWCONTROL is not set
+# CONFIG_USART2_OFLOWCONTROL is not set
+# CONFIG_USART2_DMA is not set
+# CONFIG_PSEUDOTERM is not set
+# CONFIG_USBDEV is not set
+# CONFIG_USBHOST is not set
+# CONFIG_HAVE_USBTRACE is not set
+# CONFIG_DRIVERS_WIRELESS is not set
+# CONFIG_DRIVERS_CONTACTLESS is not set
+
+#
+# System Logging
+#
+# CONFIG_ARCH_SYSLOG is not set
+# CONFIG_RAMLOG is not set
+# CONFIG_SYSLOG_INTBUFFER is not set
+# CONFIG_SYSLOG_TIMESTAMP is not set
+CONFIG_SYSLOG_SERIAL_CONSOLE=y
+# CONFIG_SYSLOG_CHAR is not set
+CONFIG_SYSLOG_CONSOLE=y
+# CONFIG_SYSLOG_NONE is not set
+# CONFIG_SYSLOG_FILE is not set
+# CONFIG_SYSLOG_CHARDEV is not set
+
+#
+# Networking Support
+#
+CONFIG_ARCH_HAVE_NET=y
+CONFIG_ARCH_HAVE_PHY=y
+CONFIG_NET=y
+# CONFIG_NET_NOINTS is not set
+# CONFIG_NET_PROMISCUOUS is not set
+
+#
+# Driver buffer configuration
+#
+CONFIG_NET_MULTIBUFFER=y
+CONFIG_NET_ETH_MTU=590
+CONFIG_NET_ETH_TCP_RECVWNDO=536
+CONFIG_NET_GUARDSIZE=2
+
+#
+# Data link support
+#
+# CONFIG_NET_MULTILINK is not set
+CONFIG_NET_ETHERNET=y
+# CONFIG_NET_LOOPBACK is not set
+# CONFIG_NET_TUN is not set
+
+#
+# Network Device Operations
+#
+# CONFIG_NETDEV_PHY_IOCTL is not set
+
+#
+# Internet Protocol Selection
+#
+CONFIG_NET_IPv4=y
+# CONFIG_NET_IPv6 is not set
+
+#
+# Socket Support
+#
+CONFIG_NSOCKET_DESCRIPTORS=10
+CONFIG_NET_NACTIVESOCKETS=16
+CONFIG_NET_SOCKOPTS=y
+CONFIG_NET_SOLINGER=y
+
+#
+# Raw Socket Support
+#
+# CONFIG_NET_PKT is not set
+
+#
+# Unix Domain Socket Support
+#
+# CONFIG_NET_LOCAL is not set
+
+#
+# TCP/IP Networking
+#
+CONFIG_NET_TCP=y
+# CONFIG_NET_TCPURGDATA is not set
+CONFIG_NET_TCP_CONNS=40
+CONFIG_NET_MAX_LISTENPORTS=40
+CONFIG_NET_TCP_READAHEAD=y
+# CONFIG_NET_TCP_WRITE_BUFFERS is not set
+CONFIG_NET_TCP_RECVDELAY=0
+CONFIG_NET_TCPBACKLOG=y
+# CONFIG_NET_TCP_SPLIT is not set
+# CONFIG_NET_SENDFILE is not set
+
+#
+# UDP Networking
+#
+CONFIG_NET_UDP=y
+CONFIG_NET_UDP_CHECKSUMS=y
+CONFIG_NET_UDP_CONNS=8
+CONFIG_NET_BROADCAST=y
+# CONFIG_NET_RXAVAIL is not set
+CONFIG_NET_UDP_READAHEAD=y
+
+#
+# ICMP Networking Support
+#
+CONFIG_NET_ICMP=y
+CONFIG_NET_ICMP_PING=y
+
+#
+# IGMPv2 Client Support
+#
+# CONFIG_NET_IGMP is not set
+
+#
+# ARP Configuration
+#
+CONFIG_NET_ARP=y
+CONFIG_NET_ARPTAB_SIZE=16
+CONFIG_NET_ARP_MAXAGE=120
+CONFIG_NET_ARP_IPIN=y
+# CONFIG_NET_ARP_SEND is not set
+
+#
+# Network I/O Buffer Support
+#
+CONFIG_NET_IOB=y
+CONFIG_IOB_NBUFFERS=24
+CONFIG_IOB_BUFSIZE=196
+CONFIG_IOB_NCHAINS=8
+# CONFIG_NET_ARCH_INCR32 is not set
+# CONFIG_NET_ARCH_CHKSUM is not set
+CONFIG_NET_STATISTICS=y
+
+#
+# Routing Table Configuration
+#
+# CONFIG_NET_ROUTE is not set
+CONFIG_NET_HOSTNAME=""
+
+#
+# Crypto API
+#
+# CONFIG_CRYPTO is not set
+
+#
+# File Systems
+#
+
+#
+# File system configuration
+#
+# CONFIG_DISABLE_MOUNTPOINT is not set
+# CONFIG_FS_AUTOMOUNTER is not set
+# CONFIG_DISABLE_PSEUDOFS_OPERATIONS is not set
+# CONFIG_FS_READABLE is not set
+# CONFIG_FS_WRITABLE is not set
+# CONFIG_FS_NAMED_SEMAPHORES is not set
+CONFIG_FS_MQUEUE_MPATH="/var/mqueue"
+# CONFIG_FS_RAMMAP is not set
+# CONFIG_FS_FAT is not set
+# CONFIG_NFS is not set
+# CONFIG_FS_NXFFS is not set
+# CONFIG_FS_ROMFS is not set
+# CONFIG_FS_TMPFS is not set
+# CONFIG_FS_SMARTFS is not set
+# CONFIG_FS_BINFS is not set
+# CONFIG_FS_PROCFS is not set
+# CONFIG_FS_UNIONFS is not set
+
+#
+# Graphics Support
+#
+# CONFIG_NX is not set
+
+#
+# Memory Management
+#
+# CONFIG_MM_SMALL is not set
+CONFIG_MM_REGIONS=2
+# CONFIG_ARCH_HAVE_HEAP2 is not set
+# CONFIG_GRAN is not set
+
+#
+# Audio Support
+#
+# CONFIG_AUDIO is not set
+
+#
+# Wireless Support
+#
+
+#
+# Binary Loader
+#
+# CONFIG_BINFMT_DISABLE is not set
+# CONFIG_BINFMT_EXEPATH is not set
+# CONFIG_NXFLAT is not set
+# CONFIG_ELF is not set
+CONFIG_BUILTIN=y
+# CONFIG_PIC is not set
+# CONFIG_SYMTAB_ORDEREDBYNAME is not set
+
+#
+# Library Routines
+#
+
+#
+# Standard C Library Options
+#
+CONFIG_STDIO_BUFFER_SIZE=64
+CONFIG_STDIO_LINEBUFFER=y
+CONFIG_NUNGET_CHARS=2
+CONFIG_LIB_HOMEDIR="/"
+# CONFIG_LIBM is not set
+# CONFIG_NOPRINTF_FIELDWIDTH is not set
+# CONFIG_LIBC_FLOATINGPOINT is not set
+CONFIG_LIBC_LONG_LONG=y
+# CONFIG_LIBC_IOCTL_VARIADIC is not set
+CONFIG_LIB_RAND_ORDER=1
+# CONFIG_EOL_IS_CR is not set
+# CONFIG_EOL_IS_LF is not set
+# CONFIG_EOL_IS_BOTH_CRLF is not set
+CONFIG_EOL_IS_EITHER_CRLF=y
+# CONFIG_LIBC_EXECFUNCS is not set
+CONFIG_POSIX_SPAWN_PROXY_STACKSIZE=1024
+CONFIG_TASK_SPAWN_DEFAULT_STACKSIZE=2048
+# CONFIG_LIBC_STRERROR is not set
+# CONFIG_LIBC_PERROR_STDOUT is not set
+CONFIG_ARCH_LOWPUTC=y
+# CONFIG_LIBC_LOCALTIME is not set
+# CONFIG_TIME_EXTENDED is not set
+CONFIG_LIB_SENDFILE_BUFSIZE=512
+# CONFIG_ARCH_ROMGETC is not set
+# CONFIG_ARCH_OPTIMIZED_FUNCTIONS is not set
+CONFIG_ARCH_HAVE_TLS=y
+# CONFIG_TLS is not set
+CONFIG_LIBC_NETDB=y
+CONFIG_NETDB_DNSCLIENT=y
+CONFIG_NETDB_DNSCLIENT_ENTRIES=8
+CONFIG_NETDB_DNSCLIENT_NAMESIZE=32
+CONFIG_NETDB_DNSCLIENT_LIFESEC=3600
+CONFIG_NETDB_DNSCLIENT_MAXRESPONSE=96
+# CONFIG_NETDB_DNSSERVER_NOADDR is not set
+CONFIG_NETDB_DNSSERVER_IPv4=y
+CONFIG_NETDB_DNSSERVER_IPv4ADDR=0x0a000001
+
+#
+# Non-standard Library Support
+#
+# CONFIG_LIB_CRC64_FAST is not set
+# CONFIG_LIB_KBDCODEC is not set
+# CONFIG_LIB_SLCDCODEC is not set
+# CONFIG_LIB_HEX2BIN is not set
+
+#
+# Basic CXX Support
+#
+# CONFIG_C99_BOOL8 is not set
+CONFIG_HAVE_CXX=y
+CONFIG_HAVE_CXXINITIALIZE=y
+# CONFIG_CXX_NEWLONG is not set
+
+#
+# uClibc++ Standard C++ Library
+#
+# CONFIG_UCLIBCXX is not set
+
+#
+# Application Configuration
+#
+
+#
+# NxWidgets/NxWM
+#
+
+#
+# Built-In Applications
+#
+CONFIG_BUILTIN_PROXY_STACKSIZE=1024
+
+#
+# CAN Utilities
+#
+
+#
+# Examples
+#
+# CONFIG_EXAMPLES_BUTTONS is not set
+# CONFIG_EXAMPLES_CHAT is not set
+# CONFIG_EXAMPLES_CONFIGDATA is not set
+# CONFIG_EXAMPLES_CXXTEST is not set
+# CONFIG_EXAMPLES_DHCPD is not set
+# CONFIG_EXAMPLES_DISCOVER is not set
+# CONFIG_EXAMPLES_ELF is not set
+# CONFIG_EXAMPLES_FTPC is not set
+# CONFIG_EXAMPLES_FTPD is not set
+# CONFIG_EXAMPLES_HELLO is not set
+# CONFIG_EXAMPLES_HELLOXX is not set
+# CONFIG_EXAMPLES_HIDKBD is not set
+# CONFIG_EXAMPLES_IGMP is not set
+# CONFIG_EXAMPLES_JSON is not set
+# CONFIG_EXAMPLES_KEYPADTEST is not set
+# CONFIG_EXAMPLES_MEDIA is not set
+# CONFIG_EXAMPLES_MM is not set
+# CONFIG_EXAMPLES_MODBUS is not set
+# CONFIG_EXAMPLES_MOUNT is not set
+# CONFIG_EXAMPLES_NETTEST is not set
+# CONFIG_EXAMPLES_NRF24L01TERM is not set
+# CONFIG_EXAMPLES_NSH is not set
+# CONFIG_EXAMPLES_NULL is not set
+# CONFIG_EXAMPLES_NX is not set
+# CONFIG_EXAMPLES_NXFFS is not set
+# CONFIG_EXAMPLES_NXHELLO is not set
+# CONFIG_EXAMPLES_NXIMAGE is not set
+# CONFIG_EXAMPLES_NXLINES is not set
+# CONFIG_EXAMPLES_NXTERM is not set
+# CONFIG_EXAMPLES_NXTEXT is not set
+# CONFIG_EXAMPLES_OSTEST is not set
+# CONFIG_EXAMPLES_PCA9635 is not set
+# CONFIG_EXAMPLES_POSIXSPAWN is not set
+# CONFIG_EXAMPLES_PPPD is not set
+# CONFIG_EXAMPLES_RFID_READUID is not set
+# CONFIG_EXAMPLES_RGBLED is not set
+# CONFIG_EXAMPLES_RGMP is not set
+# CONFIG_EXAMPLES_SENDMAIL is not set
+# CONFIG_EXAMPLES_SERIALBLASTER is not set
+# CONFIG_EXAMPLES_SERIALRX is not set
+# CONFIG_EXAMPLES_SERLOOP is not set
+# CONFIG_EXAMPLES_SLCD is not set
+# CONFIG_EXAMPLES_SMART is not set
+# CONFIG_EXAMPLES_SMP is not set
+# CONFIG_EXAMPLES_TCPECHO is not set
+# CONFIG_EXAMPLES_TELNETD is not set
+# CONFIG_EXAMPLES_TIFF is not set
+# CONFIG_EXAMPLES_TOUCHSCREEN is not set
+# CONFIG_EXAMPLES_UDP is not set
+# CONFIG_EXAMPLES_UDPBLASTER is not set
+# CONFIG_EXAMPLES_USBTERM is not set
+# CONFIG_EXAMPLES_WATCHDOG is not set
+CONFIG_EXAMPLES_WEBSERVER=y
+CONFIG_EXAMPLES_WEBSERVER_DHCPC=y
+CONFIG_EXAMPLES_WEBSERVER_DRIPADDR=0xc0a80101
+CONFIG_EXAMPLES_WEBSERVER_NETMASK=0xffffff00
+CONFIG_EXAMPLES_WEBSERVER_NOMAC=y
+# CONFIG_EXAMPLES_WGET is not set
+# CONFIG_EXAMPLES_XMLRPC is not set
+
+#
+# External
+#
+
+#
+# File System Utilities
+#
+# CONFIG_FSUTILS_INIFILE is not set
+
+#
+# GPS Utilities
+#
+# CONFIG_GPSUTILS_MINMEA_LIB is not set
+
+#
+# Graphics Support
+#
+# CONFIG_TIFF is not set
+# CONFIG_GRAPHICS_TRAVELER is not set
+
+#
+# Interpreters
+#
+# CONFIG_INTERPRETERS_FICL is not set
+# CONFIG_INTERPRETERS_MICROPYTHON is not set
+# CONFIG_INTERPRETERS_MINIBASIC is not set
+# CONFIG_INTERPRETERS_PCODE is not set
+
+#
+# FreeModBus
+#
+# CONFIG_MODBUS is not set
+
+#
+# Network Utilities
+#
+# CONFIG_NETUTILS_CHAT is not set
+# CONFIG_NETUTILS_CODECS is not set
+CONFIG_NETUTILS_DHCPC=y
+# CONFIG_NETUTILS_DHCPD is not set
+CONFIG_NETUTILS_DISCOVER=y
+CONFIG_DISCOVER_STACK_SIZE=1024
+CONFIG_DISCOVER_PRIORITY=50
+CONFIG_DISCOVER_PORT=96
+CONFIG_DISCOVER_INTERFACE="eth0"
+CONFIG_DISCOVER_DEVICE_CLASS=0xff
+CONFIG_DISCOVER_DESCR="NuttX"
+# CONFIG_NETUTILS_ESP8266 is not set
+# CONFIG_NETUTILS_FTPC is not set
+# CONFIG_NETUTILS_FTPD is not set
+# CONFIG_NETUTILS_JSON is not set
+CONFIG_NETUTILS_NETLIB=y
+# CONFIG_NETUTILS_NTPCLIENT is not set
+# CONFIG_NETUTILS_PPPD is not set
+# CONFIG_NETUTILS_SMTP is not set
+# CONFIG_NETUTILS_TELNETD is not set
+# CONFIG_NETUTILS_TFTPC is not set
+# CONFIG_NETUTILS_WEBCLIENT is not set
+CONFIG_NETUTILS_WEBSERVER=y
+# CONFIG_NETUTILS_HTTPD_SINGLECONNECT is not set
+# CONFIG_NETUTILS_HTTPD_SCRIPT_DISABLE is not set
+CONFIG_NETUTILS_HTTPD_MAXPATH=64
+# CONFIG_NETUTILS_HTTPD_CGIPATH is not set
+CONFIG_NETUTILS_HTTPD_ERRPATH=""
+# CONFIG_NETUTILS_HTTPD_SERVERHEADER_DISABLE is not set
+CONFIG_NETUTILS_HTTPD_TIMEOUT=0
+CONFIG_NETUTILS_HTTPD_CLASSIC=y
+# CONFIG_NETUTILS_HTTPD_MMAP is not set
+# CONFIG_NETUTILS_HTTPD_SENDFILE is not set
+CONFIG_NETUTILS_HTTPD_KEEPALIVE_DISABLE=y
+# CONFIG_NETUTILS_XMLRPC is not set
+
+#
+# NSH Library
+#
+# CONFIG_NSH_LIBRARY is not set
+
+#
+# Platform-specific Support
+#
+# CONFIG_PLATFORM_CONFIGDATA is not set
+
+#
+# System Libraries and NSH Add-Ons
+#
+# CONFIG_SYSTEM_CLE is not set
+# CONFIG_SYSTEM_CUTERM is not set
+# CONFIG_SYSTEM_FREE is not set
+# CONFIG_SYSTEM_HEX2BIN is not set
+# CONFIG_SYSTEM_HEXED is not set
+# CONFIG_SYSTEM_INSTALL is not set
+# CONFIG_SYSTEM_NETDB is not set
+# CONFIG_SYSTEM_RAMTEST is not set
+# CONFIG_READLINE_HAVE_EXTMATCH is not set
+# CONFIG_SYSTEM_READLINE is not set
+# CONFIG_SYSTEM_SUDOKU is not set
+# CONFIG_SYSTEM_TEE is not set
+# CONFIG_SYSTEM_UBLOXMODEM is not set
+# CONFIG_SYSTEM_VI is not set
+# CONFIG_SYSTEM_ZMODEM is not set
diff --git a/configs/olimex-stm32-e407/webserver/setenv.sh b/configs/olimex-stm32-e407/webserver/setenv.sh
new file mode 100755
index 0000000000..3cffa68d40
--- /dev/null
+++ b/configs/olimex-stm32-e407/webserver/setenv.sh
@@ -0,0 +1,80 @@
+#!/bin/bash
+# configs/olimex-stm32-e407/webserver/setenv.sh
+#
+# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved.
+# Author: Gregory Nutt
+#
+# 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.
+#
+
+if [ "$_" = "$0" ] ; then
+ echo "You must source this script, not run it!" 1>&2
+ exit 1
+fi
+
+WD=`pwd`
+if [ ! -x "setenv.sh" ]; then
+ echo "This script must be executed from the top-level NuttX build directory"
+ exit 1
+fi
+
+if [ -z "${PATH_ORIG}" ]; then
+ export PATH_ORIG="${PATH}"
+fi
+
+# This is the Cygwin path to the location where I installed the RIDE
+# toolchain under windows. You will also have to edit this if you install
+# the RIDE toolchain in any other location
+#export TOOLCHAIN_BIN="/cygdrive/c/Program Files (x86)/Raisonance/Ride/arm-gcc/bin"
+
+# This is the Cygwin path to the location where I installed the CodeSourcery
+# toolchain under windows. You will also have to edit this if you install
+# the CodeSourcery toolchain in any other location
+export TOOLCHAIN_BIN="/cygdrive/c/Program Files (x86)/CodeSourcery/Sourcery G++ Lite/bin"
+#export TOOLCHAIN_BIN="/cygdrive/c/Users/MyName/MentorGraphics/Sourcery_CodeBench_Lite_for_ARM_EABI/bin"
+
+# This is the location where I installed the ARM "GNU Tools for ARM Embedded Processors"
+# You can this free toolchain here https://launchpad.net/gcc-arm-embedded
+#export TOOLCHAIN_BIN="/cygdrive/c/Program Files (x86)/GNU Tools ARM Embedded/4.9 2015q2/bin"
+
+# These are the Cygwin paths to the locations where I installed the Atollic
+# toolchain under windows. You will also have to edit this if you install
+# the Atollic toolchain in any other location. /usr/bin is added before
+# the Atollic bin path because there is are binaries named gcc.exe and g++.exe
+# at those locations as well.
+#export TOOLCHAIN_BIN="/usr/bin:/cygdrive/c/Program Files (x86)/Atollic/TrueSTUDIO for ARM Pro 2.3.0/ARMTools/bin"
+#export TOOLCHAIN_BIN="/usr/bin:/cygdrive/c/Program Files (x86)/Atollic/TrueSTUDIO for STMicroelectronics STM32 Lite 2.3.0/ARMTools/bin"
+
+# This is the Cygwin path to the location where I build the buildroot
+# toolchain.
+#export TOOLCHAIN_BIN="${WD}/../buildroot/build_arm_nofpu/staging_dir/bin"
+
+# Add the path to the toolchain to the PATH variable
+export PATH="${TOOLCHAIN_BIN}:/sbin:/usr/sbin:${PATH_ORIG}"
+
+echo "PATH : ${PATH}"
--
GitLab
From 4f4b709ef5a095fb9ba62cbeaba6a0b06d3b0ab1 Mon Sep 17 00:00:00 2001
From: Gregory Nutt
Date: Thu, 6 Oct 2016 07:08:50 -0600
Subject: [PATCH 029/734] configs/stm32l476-mdk/nsh: Remove
CONFIG_CXX_INITIALIZE. up_cxxinitialize is not provided in apps/platfor for
this board.
---
configs/stm32l476-mdk/nsh/defconfig | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/configs/stm32l476-mdk/nsh/defconfig b/configs/stm32l476-mdk/nsh/defconfig
index e1d92b95af..188e704f0b 100644
--- a/configs/stm32l476-mdk/nsh/defconfig
+++ b/configs/stm32l476-mdk/nsh/defconfig
@@ -770,7 +770,7 @@ CONFIG_ARCH_HAVE_TLS=y
#
# CONFIG_C99_BOOL8 is not set
CONFIG_HAVE_CXX=y
-CONFIG_HAVE_CXXINITIALIZE=y
+# CONFIG_HAVE_CXXINITIALIZE is not set
# CONFIG_CXX_NEWLONG is not set
#
@@ -817,7 +817,6 @@ CONFIG_BUILTIN_PROXY_STACKSIZE=1024
# CONFIG_EXAMPLES_MOUNT is not set
# CONFIG_EXAMPLES_NRF24L01TERM is not set
CONFIG_EXAMPLES_NSH=y
-CONFIG_EXAMPLES_NSH_CXXINITIALIZE=y
# CONFIG_EXAMPLES_NULL is not set
# CONFIG_EXAMPLES_NXFFS is not set
# CONFIG_EXAMPLES_NXHELLO is not set
@@ -948,6 +947,7 @@ CONFIG_NSH_DISABLE_LOSMART=y
# CONFIG_NSH_DISABLE_MOUNT is not set
# CONFIG_NSH_DISABLE_MV is not set
# CONFIG_NSH_DISABLE_MW is not set
+CONFIG_NSH_DISABLE_PRINTF=y
# CONFIG_NSH_DISABLE_PS is not set
# CONFIG_NSH_DISABLE_PUT is not set
# CONFIG_NSH_DISABLE_PWD is not set
@@ -1017,6 +1017,7 @@ CONFIG_READLINE_ECHO=y
# CONFIG_READLINE_TABCOMPLETION is not set
# CONFIG_READLINE_CMD_HISTORY is not set
# CONFIG_SYSTEM_SUDOKU is not set
+# CONFIG_SYSTEM_SYSTEM is not set
# CONFIG_SYSTEM_TEE is not set
# CONFIG_SYSTEM_UBLOXMODEM is not set
# CONFIG_SYSTEM_VI is not set
--
GitLab
From 6a0917ae7f6b301354030e8eb783351ca7eff274 Mon Sep 17 00:00:00 2001
From: Gregory Nutt
Date: Thu, 6 Oct 2016 07:27:19 -0600
Subject: [PATCH 030/734] Eliminate warnings
---
drivers/sensors/xen1210.c | 4 ----
1 file changed, 4 deletions(-)
diff --git a/drivers/sensors/xen1210.c b/drivers/sensors/xen1210.c
index ea4de97fff..0f7bfd2b1e 100644
--- a/drivers/sensors/xen1210.c
+++ b/drivers/sensors/xen1210.c
@@ -147,8 +147,6 @@ static ssize_t xen1210_read(FAR struct file *filep, FAR char *buffer,
{
FAR struct inode *inode;
FAR struct xen1210_dev_s *priv;
- struct xen1210_sample_s sample;
- uint32_t regval;
int ret;
sninfo("len=%d\n", len);
@@ -290,7 +288,6 @@ XEN1210_HANDLE xen1210_instantiate(FAR struct spi_dev_s *dev,
{
FAR struct xen1210_dev_s *priv;
uint32_t regval;
- int ret;
/* Allocate the XEN1210 driver instance */
@@ -445,7 +442,6 @@ void xen1210_getdata(FAR struct xen1210_dev_s *priv)
#ifdef CONFIG_XEN1210_REGDEBUG
_err("%02x->%02x\n", regaddr, regval);
#endif
- return regval;
}
/****************************************************************************
--
GitLab
From f55bee5325ee769f1a51ff35d78958d152787c5b Mon Sep 17 00:00:00 2001
From: Gregory Nutt
Date: Thu, 6 Oct 2016 07:42:13 -0600
Subject: [PATCH 031/734] Update defconfig files
---
configs/spark/composite/defconfig | 2 +-
configs/spark/nsh/defconfig | 2 +-
configs/spark/usbmsc/defconfig | 2 +-
configs/spark/usbserial/defconfig | 2 +-
configs/stm32_tiny/nsh/defconfig | 2 +-
configs/stm32f103-minimum/rfid-rc522/defconfig | 2 +-
6 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/configs/spark/composite/defconfig b/configs/spark/composite/defconfig
index 96c044fab9..490744f429 100644
--- a/configs/spark/composite/defconfig
+++ b/configs/spark/composite/defconfig
@@ -917,7 +917,7 @@ CONFIG_CC3000_SELECT_STACKSIZE=390
CONFIG_CC3000_UNSOLICED_STACKSIZE=264
# CONFIG_CC3000_PROBES is not set
# CONFIG_WL_NRF24L01 is not set
-# CONFIG_WL_MFRC522 is not set
+# CONFIG_CL_MFRC522 is not set
# CONFIG_WL_PN532 is not set
#
diff --git a/configs/spark/nsh/defconfig b/configs/spark/nsh/defconfig
index 93ace169f0..a32b364ed2 100644
--- a/configs/spark/nsh/defconfig
+++ b/configs/spark/nsh/defconfig
@@ -917,7 +917,7 @@ CONFIG_CC3000_SELECT_STACKSIZE=368
CONFIG_CC3000_UNSOLICED_STACKSIZE=264
# CONFIG_CC3000_PROBES is not set
# CONFIG_WL_NRF24L01 is not set
-# CONFIG_WL_MFRC522 is not set
+# CONFIG_CL_MFRC522 is not set
# CONFIG_WL_PN532 is not set
#
diff --git a/configs/spark/usbmsc/defconfig b/configs/spark/usbmsc/defconfig
index 0ab4fcd241..9ac901f2a1 100644
--- a/configs/spark/usbmsc/defconfig
+++ b/configs/spark/usbmsc/defconfig
@@ -882,7 +882,7 @@ CONFIG_CC3000_SELECT_STACKSIZE=390
CONFIG_CC3000_UNSOLICED_STACKSIZE=264
# CONFIG_CC3000_PROBES is not set
# CONFIG_WL_NRF24L01 is not set
-# CONFIG_WL_MFRC522 is not set
+# CONFIG_CL_MFRC522 is not set
# CONFIG_WL_PN532 is not set
#
diff --git a/configs/spark/usbserial/defconfig b/configs/spark/usbserial/defconfig
index a2bee31d24..da3d0c5e5d 100644
--- a/configs/spark/usbserial/defconfig
+++ b/configs/spark/usbserial/defconfig
@@ -892,7 +892,7 @@ CONFIG_CC3000_SELECT_STACKSIZE=390
CONFIG_CC3000_UNSOLICED_STACKSIZE=264
CONFIG_CC3000_PROBES=y
# CONFIG_WL_NRF24L01 is not set
-# CONFIG_WL_MFRC522 is not set
+# CONFIG_CL_MFRC522 is not set
# CONFIG_WL_PN532 is not set
#
diff --git a/configs/stm32_tiny/nsh/defconfig b/configs/stm32_tiny/nsh/defconfig
index c796e5e93d..8b9c4c1d86 100644
--- a/configs/stm32_tiny/nsh/defconfig
+++ b/configs/stm32_tiny/nsh/defconfig
@@ -795,7 +795,7 @@ CONFIG_WL_NRF24L01_DFLT_ADDR_WIDTH=5
CONFIG_WL_NRF24L01_CHECK_PARAMS=y
CONFIG_WL_NRF24L01_RXSUPPORT=y
CONFIG_WL_NRF24L01_RXFIFO_LEN=128
-# CONFIG_WL_MFRC522 is not set
+# CONFIG_CL_MFRC522 is not set
# CONFIG_WL_PN532 is not set
#
diff --git a/configs/stm32f103-minimum/rfid-rc522/defconfig b/configs/stm32f103-minimum/rfid-rc522/defconfig
index 140ef6a66f..6a74dc01de 100644
--- a/configs/stm32f103-minimum/rfid-rc522/defconfig
+++ b/configs/stm32f103-minimum/rfid-rc522/defconfig
@@ -791,7 +791,7 @@ CONFIG_DRIVERS_WIRELESS=y
# CONFIG_WL_CC1101 is not set
# CONFIG_WL_CC3000 is not set
# CONFIG_WL_NRF24L01 is not set
-CONFIG_WL_MFRC522=y
+CONFIG_CL_MFRC522=y
CONFIG_MFRC522_SPI_FREQ=1000000
CONFIG_MFRC522_DEBUG=y
# CONFIG_MFRC522_DEBUG_TX is not set
--
GitLab
From 1fda0523da7c5728d2afdb099ed99079015d4da9 Mon Sep 17 00:00:00 2001
From: Gregory Nutt
Date: Thu, 6 Oct 2016 07:44:00 -0600
Subject: [PATCH 032/734] CONFIG_CL_MFR522, not CONFIG_WL_MFR522
---
configs/stm32f103-minimum/src/Makefile | 2 +-
configs/stm32f103-minimum/src/stm32_bringup.c | 2 +-
configs/stm32f103-minimum/src/stm32_spi.c | 4 ++--
configs/stm32f103-minimum/src/stm32f103_minimum.h | 2 +-
4 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/configs/stm32f103-minimum/src/Makefile b/configs/stm32f103-minimum/src/Makefile
index 5876a6df68..c502b43a47 100644
--- a/configs/stm32f103-minimum/src/Makefile
+++ b/configs/stm32f103-minimum/src/Makefile
@@ -53,7 +53,7 @@ ifeq ($(CONFIG_AUDIO_TONE),y)
CSRCS += stm32_tone.c
endif
-ifeq ($(CONFIG_WL_MFRC522),y)
+ifeq ($(CONFIG_CL_MRFC522),y)
CSRCS += stm32_mfrc522.c
endif
diff --git a/configs/stm32f103-minimum/src/stm32_bringup.c b/configs/stm32f103-minimum/src/stm32_bringup.c
index ec7d33db3f..016e7149bd 100644
--- a/configs/stm32f103-minimum/src/stm32_bringup.c
+++ b/configs/stm32f103-minimum/src/stm32_bringup.c
@@ -112,7 +112,7 @@ int stm32_bringup(void)
}
#endif
-#ifdef CONFIG_WL_MFRC522
+#ifdef CONFIG_CL_MRFC522
ret = stm32_mfrc522initialize("/dev/rfid0");
if (ret < 0)
{
diff --git a/configs/stm32f103-minimum/src/stm32_spi.c b/configs/stm32f103-minimum/src/stm32_spi.c
index 2095e3e2af..10aabe207c 100644
--- a/configs/stm32f103-minimum/src/stm32_spi.c
+++ b/configs/stm32f103-minimum/src/stm32_spi.c
@@ -74,7 +74,7 @@ void stm32_spidev_initialize(void)
* architecture.
*/
-#ifdef CONFIG_WL_MFRC522
+#ifdef CONFIG_CL_MRFC522
(void)stm32_configgpio(GPIO_CS_MFRC522); /* MFRC522 chip select */
#endif
@@ -112,7 +112,7 @@ void stm32_spidev_initialize(void)
void stm32_spi1select(FAR struct spi_dev_s *dev, enum spi_dev_e devid,
bool selected)
{
-#if defined(CONFIG_WL_MFRC522)
+#if defined(CONFIG_CL_MRFC522)
if (devid == SPIDEV_WIRELESS)
{
stm32_gpiowrite(GPIO_CS_MFRC522, !selected);
diff --git a/configs/stm32f103-minimum/src/stm32f103_minimum.h b/configs/stm32f103-minimum/src/stm32f103_minimum.h
index f3c083ac6b..68c57ba3a1 100644
--- a/configs/stm32f103-minimum/src/stm32f103_minimum.h
+++ b/configs/stm32f103-minimum/src/stm32f103_minimum.h
@@ -139,7 +139,7 @@ void stm32_usbinitialize(void);
*
************************************************************************************/
-#ifdef CONFIG_WL_MFRC522
+#ifdef CONFIG_CL_MRFC522
int stm32_mfrc522initialize(FAR const char *devpath);
#endif
--
GitLab
From f34d5db09448cf142b9e3f61063c12b2625d5551 Mon Sep 17 00:00:00 2001
From: Gregory Nutt
Date: Thu, 6 Oct 2016 07:58:14 -0600
Subject: [PATCH 033/734] More fixed related to name changes from
CONFIG_WL_MFRC522 to CONFIG_CL_MFRC522. Also depends on CONFIG_CONTACTLESS.
not CONFIG_WIRELESS.
---
.../stm32f103-minimum/rfid-rc522/defconfig | 19 ++++++++++---------
configs/stm32f103-minimum/src/Makefile | 2 +-
configs/stm32f103-minimum/src/stm32_bringup.c | 2 +-
configs/stm32f103-minimum/src/stm32_spi.c | 4 ++--
.../stm32f103-minimum/src/stm32f103_minimum.h | 2 +-
5 files changed, 15 insertions(+), 14 deletions(-)
diff --git a/configs/stm32f103-minimum/rfid-rc522/defconfig b/configs/stm32f103-minimum/rfid-rc522/defconfig
index 6a74dc01de..0f41c12085 100644
--- a/configs/stm32f103-minimum/rfid-rc522/defconfig
+++ b/configs/stm32f103-minimum/rfid-rc522/defconfig
@@ -697,6 +697,7 @@ CONFIG_ARCH_HAVE_SPI_BITORDER=y
# Timer Driver Support
#
# CONFIG_TIMER is not set
+# CONFIG_ONESHOT is not set
# CONFIG_RTC is not set
# CONFIG_WATCHDOG is not set
# CONFIG_ANALOG is not set
@@ -787,16 +788,12 @@ CONFIG_USART1_2STOP=0
# CONFIG_USBDEV is not set
# CONFIG_USBHOST is not set
# CONFIG_HAVE_USBTRACE is not set
-CONFIG_DRIVERS_WIRELESS=y
-# CONFIG_WL_CC1101 is not set
-# CONFIG_WL_CC3000 is not set
-# CONFIG_WL_NRF24L01 is not set
+# CONFIG_DRIVERS_WIRELESS is not set
+CONFIG_DRIVERS_CONTACTLESS=y
CONFIG_CL_MFRC522=y
CONFIG_MFRC522_SPI_FREQ=1000000
-CONFIG_MFRC522_DEBUG=y
-# CONFIG_MFRC522_DEBUG_TX is not set
-# CONFIG_MFRC522_DEBUG_RX is not set
-# CONFIG_WL_PN532 is not set
+# CONFIG_CL_MFRC522_DEBUG is not set
+# CONFIG_CL_PN532 is not set
#
# System Logging
@@ -965,10 +962,10 @@ CONFIG_BUILTIN_PROXY_STACKSIZE=1024
# CONFIG_EXAMPLES_NRF24L01TERM is not set
CONFIG_EXAMPLES_NSH=y
# CONFIG_EXAMPLES_NULL is not set
-# CONFIG_EXAMPLES_NX is not set
# CONFIG_EXAMPLES_NXFFS is not set
# CONFIG_EXAMPLES_NXHELLO is not set
# CONFIG_EXAMPLES_NXIMAGE is not set
+# CONFIG_EXAMPLES_NX is not set
# CONFIG_EXAMPLES_NXLINES is not set
# CONFIG_EXAMPLES_NXTERM is not set
# CONFIG_EXAMPLES_NXTEXT is not set
@@ -1019,6 +1016,7 @@ CONFIG_EXAMPLES_RFID_READUID_STACKSIZE=2048
#
# CONFIG_INTERPRETERS_FICL is not set
# CONFIG_INTERPRETERS_MICROPYTHON is not set
+# CONFIG_INTERPRETERS_MINIBASIC is not set
# CONFIG_INTERPRETERS_PCODE is not set
#
@@ -1090,6 +1088,7 @@ CONFIG_NSH_DISABLE_LOSMART=y
# CONFIG_NSH_DISABLE_MOUNT is not set
# CONFIG_NSH_DISABLE_MV is not set
# CONFIG_NSH_DISABLE_MW is not set
+CONFIG_NSH_DISABLE_PRINTF=y
# CONFIG_NSH_DISABLE_PS is not set
# CONFIG_NSH_DISABLE_PUT is not set
# CONFIG_NSH_DISABLE_PWD is not set
@@ -1156,6 +1155,8 @@ CONFIG_READLINE_ECHO=y
# CONFIG_READLINE_TABCOMPLETION is not set
# CONFIG_READLINE_CMD_HISTORY is not set
# CONFIG_SYSTEM_SUDOKU is not set
+# CONFIG_SYSTEM_SYSTEM is not set
+# CONFIG_SYSTEM_TEE is not set
# CONFIG_SYSTEM_UBLOXMODEM is not set
# CONFIG_SYSTEM_VI is not set
# CONFIG_SYSTEM_ZMODEM is not set
diff --git a/configs/stm32f103-minimum/src/Makefile b/configs/stm32f103-minimum/src/Makefile
index c502b43a47..746f20edbc 100644
--- a/configs/stm32f103-minimum/src/Makefile
+++ b/configs/stm32f103-minimum/src/Makefile
@@ -53,7 +53,7 @@ ifeq ($(CONFIG_AUDIO_TONE),y)
CSRCS += stm32_tone.c
endif
-ifeq ($(CONFIG_CL_MRFC522),y)
+ifeq ($(CONFIG_CL_MFRC522),y)
CSRCS += stm32_mfrc522.c
endif
diff --git a/configs/stm32f103-minimum/src/stm32_bringup.c b/configs/stm32f103-minimum/src/stm32_bringup.c
index 016e7149bd..2843f67e5b 100644
--- a/configs/stm32f103-minimum/src/stm32_bringup.c
+++ b/configs/stm32f103-minimum/src/stm32_bringup.c
@@ -112,7 +112,7 @@ int stm32_bringup(void)
}
#endif
-#ifdef CONFIG_CL_MRFC522
+#ifdef CONFIG_CL_MFRC522
ret = stm32_mfrc522initialize("/dev/rfid0");
if (ret < 0)
{
diff --git a/configs/stm32f103-minimum/src/stm32_spi.c b/configs/stm32f103-minimum/src/stm32_spi.c
index 10aabe207c..98593be3ca 100644
--- a/configs/stm32f103-minimum/src/stm32_spi.c
+++ b/configs/stm32f103-minimum/src/stm32_spi.c
@@ -74,7 +74,7 @@ void stm32_spidev_initialize(void)
* architecture.
*/
-#ifdef CONFIG_CL_MRFC522
+#ifdef CONFIG_CL_MFRC522
(void)stm32_configgpio(GPIO_CS_MFRC522); /* MFRC522 chip select */
#endif
@@ -112,7 +112,7 @@ void stm32_spidev_initialize(void)
void stm32_spi1select(FAR struct spi_dev_s *dev, enum spi_dev_e devid,
bool selected)
{
-#if defined(CONFIG_CL_MRFC522)
+#if defined(CONFIG_CL_MFRC522)
if (devid == SPIDEV_WIRELESS)
{
stm32_gpiowrite(GPIO_CS_MFRC522, !selected);
diff --git a/configs/stm32f103-minimum/src/stm32f103_minimum.h b/configs/stm32f103-minimum/src/stm32f103_minimum.h
index 68c57ba3a1..a52b49b3a0 100644
--- a/configs/stm32f103-minimum/src/stm32f103_minimum.h
+++ b/configs/stm32f103-minimum/src/stm32f103_minimum.h
@@ -139,7 +139,7 @@ void stm32_usbinitialize(void);
*
************************************************************************************/
-#ifdef CONFIG_CL_MRFC522
+#ifdef CONFIG_CL_MFRC522
int stm32_mfrc522initialize(FAR const char *devpath);
#endif
--
GitLab
From d61239e38ff7329d651469df4b24ee876fe86709 Mon Sep 17 00:00:00 2001
From: Gregory Nutt
Date: Thu, 6 Oct 2016 08:50:52 -0600
Subject: [PATCH 034/734] stm32_modifycr2 should be available on all platforms
is DMA is enabled.
---
arch/arm/src/stm32/stm32_spi.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/arch/arm/src/stm32/stm32_spi.c b/arch/arm/src/stm32/stm32_spi.c
index d82b6eb3cb..c70bf8f6f1 100644
--- a/arch/arm/src/stm32/stm32_spi.c
+++ b/arch/arm/src/stm32/stm32_spi.c
@@ -1022,7 +1022,8 @@ static void spi_modifycr1(FAR struct stm32_spidev_s *priv, uint16_t setbits,
*
************************************************************************************/
-#if defined(CONFIG_STM32_STM32F30XX) || defined(CONFIG_STM32_STM32F37XX)
+#if defined(CONFIG_STM32_STM32F30XX) || defined(CONFIG_STM32_STM32F37XX) || \
+ defined(CONFIG_STM32_SPI_DMA)
static void spi_modifycr2(FAR struct stm32_spidev_s *priv, uint16_t setbits,
uint16_t clrbits)
{
--
GitLab
From 49ee2631f73891192d6b76ca0ca02f9d5ce91b2b Mon Sep 17 00:00:00 2001
From: Alan Carvalho de Assis
Date: Thu, 6 Oct 2016 13:33:31 -0600
Subject: [PATCH 035/734] Enable JTAG in stm32f103-minimum/userled
configuration
---
configs/stm32f103-minimum/userled/defconfig | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/configs/stm32f103-minimum/userled/defconfig b/configs/stm32f103-minimum/userled/defconfig
index 39ef59233b..9cdfdc6380 100644
--- a/configs/stm32f103-minimum/userled/defconfig
+++ b/configs/stm32f103-minimum/userled/defconfig
@@ -402,9 +402,9 @@ CONFIG_STM32_USART1=y
#
# CONFIG_STM32_USART1_REMAP is not set
# CONFIG_STM32_JTAG_DISABLE is not set
-CONFIG_STM32_JTAG_FULL_ENABLE=y
+# CONFIG_STM32_JTAG_FULL_ENABLE is not set
# CONFIG_STM32_JTAG_NOJNTRST_ENABLE is not set
-# CONFIG_STM32_JTAG_SW_ENABLE is not set
+CONFIG_STM32_JTAG_SW_ENABLE=y
CONFIG_STM32_DISABLE_IDLE_SLEEP_DURING_DEBUG=y
# CONFIG_STM32_FORCEPOWER is not set
# CONFIG_ARCH_BOARD_STM32_CUSTOM_CLOCKCONFIG is not set
--
GitLab
From 1d3abd17cc011857e542d42185de49b455afc2d8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jens=20Gr=C3=A4f?=
Date: Fri, 7 Oct 2016 13:42:24 +0200
Subject: [PATCH 036/734] dma2d: fix an error in up_dma2dcreatelayer where an
invalid pointer was returned when a certain underlying function failed.
---
arch/arm/src/stm32/stm32_dma2d.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/arch/arm/src/stm32/stm32_dma2d.c b/arch/arm/src/stm32/stm32_dma2d.c
index 5e5740e27b..db76245708 100644
--- a/arch/arm/src/stm32/stm32_dma2d.c
+++ b/arch/arm/src/stm32/stm32_dma2d.c
@@ -2069,6 +2069,7 @@ FAR struct dma2d_layer_s *up_dma2dcreatelayer(fb_coord_t width,
/* free the layer struture */
kmm_free(layer);
+ layer = NULL;
lcderr("ERROR: ENOMEM, Unable to allocate layer buffer\n");
errno = ENOMEM;
}
--
GitLab
From a2e4c0e898734ea78a9f22975aeea7eee0e38362 Mon Sep 17 00:00:00 2001
From: Lok Tep
Date: Fri, 7 Oct 2016 15:12:34 +0200
Subject: [PATCH 037/734] i2s rcc typo fix
---
arch/arm/src/stm32f7/stm32f74xx75xx_rcc.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/arch/arm/src/stm32f7/stm32f74xx75xx_rcc.c b/arch/arm/src/stm32f7/stm32f74xx75xx_rcc.c
index aac857b9c3..10e4fe2bb5 100644
--- a/arch/arm/src/stm32f7/stm32f74xx75xx_rcc.c
+++ b/arch/arm/src/stm32f7/stm32f74xx75xx_rcc.c
@@ -882,10 +882,10 @@ static void stm32_stdclockconfig(void)
| RCC_PLLI2SCFGR_PLLI2SP_MASK
| RCC_PLLI2SCFGR_PLLI2SQ_MASK
| RCC_PLLI2SCFGR_PLLI2SR_MASK);
- regval |= (STM32_RCC_PLLSAICFGR_PLLSAIN
- | STM32_RCC_PLLSAICFGR_PLLSAIP
- | STM32_RCC_PLLSAICFGR_PLLSAIQ
- | STM32_RCC_PLLSAICFGR_PLLSAIR);
+ regval |= (STM32_RCC_PLLI2SCFGR_PLLI2SN
+ | STM32_RCC_PLLI2SCFGR_PLLI2SP
+ | STM32_RCC_PLLI2SCFGR_PLLI2SQ
+ | STM32_RCC_PLLI2SCFGR_PLLI2SR);
putreg32(regval, STM32_RCC_PLLI2SCFGR);
regval = getreg32(STM32_RCC_DCKCFGR2);
--
GitLab
From fd92f01f556fbe5cf24365aa153af104469441e1 Mon Sep 17 00:00:00 2001
From: Lok Tep
Date: Fri, 7 Oct 2016 15:12:46 +0200
Subject: [PATCH 038/734] exact values for i2c clock
---
arch/arm/src/stm32f7/stm32_i2c.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/arch/arm/src/stm32f7/stm32_i2c.c b/arch/arm/src/stm32f7/stm32_i2c.c
index 3786e7d52c..8d5e4db7c0 100644
--- a/arch/arm/src/stm32f7/stm32_i2c.c
+++ b/arch/arm/src/stm32f7/stm32_i2c.c
@@ -1306,17 +1306,17 @@ static void stm32_i2c_setclock(FAR struct stm32_i2c_priv_s *priv, uint32_t frequ
if (frequency == 100000)
{
presc = 0;
- scl_delay = 3;
+ scl_delay = 5;
sda_delay = 0;
- scl_h_period = 30;
- scl_l_period = 120;
+ scl_h_period = 61;
+ scl_l_period = 89;
}
else if (frequency == 400000)
{
presc = 0;
scl_delay = 3;
- sda_delay = 9;
+ sda_delay = 0;
scl_h_period = 6;
scl_l_period = 24;
}
--
GitLab
From 74284aec14ab5824f2a76497fe72aae40cac9b81 Mon Sep 17 00:00:00 2001
From: Lok Tep
Date: Fri, 7 Oct 2016 15:13:07 +0200
Subject: [PATCH 039/734] enable i2c clock config
---
configs/stm32f746-ws/include/board.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/configs/stm32f746-ws/include/board.h b/configs/stm32f746-ws/include/board.h
index 17ca38417e..8cbd85bc92 100644
--- a/configs/stm32f746-ws/include/board.h
+++ b/configs/stm32f746-ws/include/board.h
@@ -144,7 +144,7 @@
/* Configure factors for PLLI2S clock */
-
+#define CONFIG_STM32F7_PLLI2S 1
#define STM32_RCC_PLLI2SCFGR_PLLI2SN RCC_PLLI2SCFGR_PLLI2SN(192)
#define STM32_RCC_PLLI2SCFGR_PLLI2SP RCC_PLLI2SCFGR_PLLI2SP(2)
#define STM32_RCC_PLLI2SCFGR_PLLI2SQ RCC_PLLI2SCFGR_PLLI2SQ(2)
--
GitLab
From bd08646768ab324fd220cdcf59ea7e385089c824 Mon Sep 17 00:00:00 2001
From: Lok Tep
Date: Fri, 7 Oct 2016 15:18:20 +0200
Subject: [PATCH 040/734] enable PLLSAI
---
configs/stm32f746-ws/include/board.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/configs/stm32f746-ws/include/board.h b/configs/stm32f746-ws/include/board.h
index 8cbd85bc92..65a27fc6b7 100644
--- a/configs/stm32f746-ws/include/board.h
+++ b/configs/stm32f746-ws/include/board.h
@@ -124,7 +124,7 @@
/* Configure factors for PLLSAI clock */
-
+#define CONFIG_STM32F7_PLLSAI 1
#define STM32_RCC_PLLSAICFGR_PLLSAIN RCC_PLLSAICFGR_PLLSAIN(192)
#define STM32_RCC_PLLSAICFGR_PLLSAIP RCC_PLLSAICFGR_PLLSAIP(2)
#define STM32_RCC_PLLSAICFGR_PLLSAIQ RCC_PLLSAICFGR_PLLSAIQ(2)
--
GitLab
From 9e3479555db056bb8c2c2f6868d9a6b4e5ae4b5b Mon Sep 17 00:00:00 2001
From: Lok Tep
Date: Fri, 7 Oct 2016 15:47:30 +0200
Subject: [PATCH 041/734] usb set value typo
---
arch/arm/src/stm32f7/stm32_otgdev.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/arm/src/stm32f7/stm32_otgdev.c b/arch/arm/src/stm32f7/stm32_otgdev.c
index 54a0232cdf..694cf713a8 100644
--- a/arch/arm/src/stm32f7/stm32_otgdev.c
+++ b/arch/arm/src/stm32f7/stm32_otgdev.c
@@ -4232,7 +4232,7 @@ static void stm32_epin_disable(FAR struct stm32_ep_s *privep)
regval = stm32_getreg(regaddr);
regval |= OTG_DIEPINT_EPDISD;
- stm32_putreg(OTG_DIEPINT_EPDISD, regaddr);
+ stm32_putreg(regval, regaddr);
/* Flush any data remaining in the TxFIFO */
--
GitLab
From 741e100dcfd0b0b99518e99bd182e045837b1a68 Mon Sep 17 00:00:00 2001
From: Gregory Nutt
Date: Fri, 7 Oct 2016 13:47:02 -0600
Subject: [PATCH 042/734] Eliminate some warnings
---
configs/tm4c1294-launchpad/src/tm4c_bringup.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/configs/tm4c1294-launchpad/src/tm4c_bringup.c b/configs/tm4c1294-launchpad/src/tm4c_bringup.c
index 1ac0b95e58..35e1f76027 100644
--- a/configs/tm4c1294-launchpad/src/tm4c_bringup.c
+++ b/configs/tm4c1294-launchpad/src/tm4c_bringup.c
@@ -44,6 +44,7 @@
#include
#include
+#include
#include
#include
@@ -65,7 +66,7 @@
# define HAVE_PWM
#endif
-#ifdef CONFIG_TM4C1294_LAUNCHPAD_QEI
+#if defined(CONFIG_TIVA_QEI0) || defined(CONFIG_TIVA_QEI1)
# define HAVE_QEI
#endif
@@ -247,6 +248,7 @@ static void tm4c_pwm(void)
*
****************************************************************************/
+#ifdef HAVE_QEI
static void tm4c_qei_register(int id)
{
FAR struct qe_lowerhalf_s *dev;
@@ -268,6 +270,7 @@ static void tm4c_qei_register(int id)
}
}
}
+#endif
/****************************************************************************
* Name: tm4c_qei
--
GitLab
From 6ac51cb70857ff34542085ca3b1a38348ea08256 Mon Sep 17 00:00:00 2001
From: Gregory Nutt
Date: Sat, 8 Oct 2016 07:38:56 -0600
Subject: [PATCH 043/734] Update ChangeLog
---
ChangeLog | 104 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 103 insertions(+), 1 deletion(-)
diff --git a/ChangeLog b/ChangeLog
index a8f56d1e8e..53e86da467 100755
--- a/ChangeLog
+++ b/ChangeLog
@@ -12393,7 +12393,7 @@
(2016-07-23).
* Freedom-K64F: Add PWM support. From Jordan MacIntyre (2016-07-25).
-7.18 2016-xx-xx Gregory Nutt
+7.18 2016-10-09 Gregory Nutt
* drivers/serial/pty.c, serial.c, usbdev/cdcacm.c, include/nuttx/fs/ioctl.h:
Fix FIONWRITE and add FIONSPACE. All implementations of FIONWRITE
@@ -12672,3 +12672,105 @@
Vyhovanec (2016-09-02).
* MTD: SPI-based driver for Macronix MX25L3233F or MX25L6433F. From
Aleksandr Vyhovanec (2016-09-02).
+ * sched/: The TCB nchildren field should not be incremented when
+ pthreads are created (2016-09-06).
+ * sched/: Move fields related to parent/child task relationship out of
+ TCB into group structure (2016-09-06).
+ * STM32L4: Add support for USART3-USART5. For STM32L4 parts, the higher
+ number USART ports supported varies. Add the HAVE_USARTx definitions
+ to the configuration to allow enabling the higher numbered USART ports.
+ From Jim Wylder (2016-09-15).
+ * configs/stm32l476-mdk: Support basic booting and nsh on Motorola MDK.
+ The Motorola MDK is based off of an earlier version of NuttX. This
+ only provides a basic NSH shell. From Jim Wylder (2016-09-15).
+ * STM32 USB: Set USB address to avoid a failed assertion. From Pierre-noel
+ Bouteville (2016-09-15).
+ * STM32 L4 and L7 USB: Pierre's assertion-avoidance change should also be
+ applied to STM32 F7 and L4 (2016-09-15).
+ * sched/: mq_send() was not setting the errno value on certain failures
+ to allocate a message (2016-09-15).
+ * include/nuttx/modem: Move all modem-related IOCTL commands to a common
+ file to assure that they will be unique (2016-09-16).
+ * STM32 F4 Discovery: Add support for XEN1210 3D-board. From Alan
+ Carvalho de Assis (2016-09-17).
+ * drivers/sensors: Adds support for the Sensixs XEN1210 3D-board. This
+ sensor is used on NANOSATC-BR2 a Brazillian CUBESAT project. From
+ Alan Carvalho de Assis (2016-09-16).
+ * include/analog/dac.h: Make DAC structure packed. From Marc Rechté
+ (2016-09-20).
+ * All SAM Ethernet Drivers: Add support so that the drivers can be built
+ with CONFIG_NET_MULTIBUFFER=y (2016-09-20).
+ * Tiva Ethernet: Needs support for CONFIG_NET_MULTIBUFFER=y (2016-09-20).
+ * drivers/net: NET_TUN=y => NET_MULTIBUFFER=y. From Vladimir
+ Komendantskiy (2016-09-20).
+ * SAM3/4: Fix GPIO pull-up/down code. Enabling the pull-down resistor
+ while the pull-up resistor is still enabled is not possible. In this
+ case, the write of PIO_PPDER for the relevant I/O line is discarded.
+ Likewise, enabling the pull-up resistor while the pull-down resistor
+ is still enabled is not possible. In this case, the write of PIO_PUER
+ for the relevant I/O line is discarded. From Wolfgang Reißnegger
+ (2016-09-20).
+ * SAM GPIO: Apply Wolfgang's change for SAM3/4 to SAMA5 and SAMV7
+ (2016-09-20).
+ * Tiva QEI: Add QEI lower-half driver impl. for Tiva series chip. From
+ Young (2016-09-21).
+ * STM32, L4, and F7: Remove GPIO_ETH_RMII_TX_CLK. TX_CLK is not present
+ in RMII. Mateusz Szafoni (2016-09-22).
+ * sched/: Define 'group' even if HAVE_GROUPID is not set. From Mateusz
+ Szafoni (2016-09-22).
+ * sched/: vector table should have dimension NR_IRQS, not NR_IRQS+1.
+ From Sagitta Li (2016-09-22).
+ * fs/mount: Corrects a bad assertion noted by Pierre-noel Bouteville.
+ Also fixes a reference counting problem in an error condition: When
+ the mountpoint inode is found but is not an appropriate mountpoint,
+ the reference count on the inode was not being decremented (2016-09-22).
+ * libnx/nxglib: Fix handling of near-horizontal lines of width 1 in
+ nxgl_splitline(). Missing handling for degenerate condition caused
+ width 1 lines such as (0, 0) - (100, 10) to have gaps in the drawing.
+ From Petteri Aimonen (2016-09-22).
+ * drivers/net/slip.c: Fix calculations using MSEC_PER_TICK. If
+ USEC_PER_TICK is less than 1000, then MSEC_PER_TICK will be zero. It
+ will be inaccurate in any case (2016-09-25).
+ * Tiva QEI: Add a new ioctl command (set MAXPOS) for tiva QEI. From
+ Young (2016-09-26).
+ * LPC43xx Serial: There are some small problems in LPC43xx RS485 mode
+ configuration. In particular: (1) UART0,2,3 do not have DTR pins
+ (different from UART1), so, Kconfig needs to be adjusted. (2)
+ lpc43_uart.c in RS485 mode only configures DIR pin, but doesn't enable
+ pin output for UART0,2,3. (3) should be option to reverse DIR control
+ pin output polarity. (4) lpc43xx/chip/lpc43_uart.h doesn't have USART3
+ definitions. NOTE: I didn't modified and didn't tested USART1, as it
+ has different hardware. From Vytautas Lukenskas. From Vytautas
+ Lukenskas (2016-09-30).
+ * STM32 Ethernet: Correct typo in conditional logic. From Neil Hancock
+ (2016-10-01).
+ * sched/pthread and task: When a pthread is started, there is a small
+ bit of logic that will run on the thread of execution of the new
+ pthread. In the case where the new pthread has a lower priority than
+ the parent thread, then this could cause both the parent thread and
+ the new pthread to be blocked at the priority of the lower priority
+ pthread (assuming that CONFIG_PRIORITY_INHERITANCE is not selected).
+ This change temporarily boosts the priority of the new pthread to at
+ least the priority of the new pthread to at least the priority of the
+ parent thread. When that bit of logic has executed on the thread of
+ execution of the new pthread, it will then drop to the correct
+ priority (if necessary) before calling into the new pthread's entry
+ point (2016-10-01).
+ * configs/stm32f103-minimum: Add stm32_bringup support and userled
+ example to STM32F103 Minimum board. From Alan Carvalho de Assis
+ (2016-10-02).
+ * STM32 L4: Add support for quadrature encoders on STM32L4. Sebastien
+ Lorquet (2016-10-02).
+ * configs: Add support for qencoders on various nucleo boards. From
+ Sebastien Lorquet (2016-10-03).
+ * STM32 L4 USB Device: Fixed L4 USB Driver by avoiding SETUPDONE and
+ EPOUT_SETUP. From David Sidrane (2016-10-04).
+ * configs/olimex-stm32-e407: Add some networking configurations. From
+ Mateusz Szafoni (2016-10-06).
+ * STM32 SPI: stm32_modifycr2 should be available on all platforms if DMA
+ is enabled. (2016-10-06).
+ * STM32 DMA2D: fix an error in up_dma2dcreatelayer where an invalid
+ pointer was returned when a certain underlying function failed. From
+ Jens Gräf (2016-10-07).
+
+7.19 2016-xx-xx Gregory Nutt
--
GitLab
From 693f5138697113ff698902ca34f05b23d61672e6 Mon Sep 17 00:00:00 2001
From: Gregory Nutt
Date: Sat, 8 Oct 2016 10:53:54 -0600
Subject: [PATCH 044/734] Update ReleaseNotes
---
ChangeLog | 2 +-
ReleaseNotes | 519 +++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 520 insertions(+), 1 deletion(-)
diff --git a/ChangeLog b/ChangeLog
index 53e86da467..2ff44a1710 100755
--- a/ChangeLog
+++ b/ChangeLog
@@ -12393,7 +12393,7 @@
(2016-07-23).
* Freedom-K64F: Add PWM support. From Jordan MacIntyre (2016-07-25).
-7.18 2016-10-09 Gregory Nutt
+7.18 2016-10-08 Gregory Nutt
* drivers/serial/pty.c, serial.c, usbdev/cdcacm.c, include/nuttx/fs/ioctl.h:
Fix FIONWRITE and add FIONSPACE. All implementations of FIONWRITE
diff --git a/ReleaseNotes b/ReleaseNotes
index 66e1c712c1..18b20f8b14 100644
--- a/ReleaseNotes
+++ b/ReleaseNotes
@@ -11775,3 +11775,522 @@ detailed bugfix information):
command line argument, or a compiled-in default value from config.
However, the default was ignored, leading to confusing error
messages. From ziggurat29.
+
+NuttX-7.18 Release Notes
+------------------------
+
+The 118th release of NuttX, Version 7.18, was made on October 8, 2016,
+and is available for download from the Bitbucket.org website. Note
+that release consists of two tarballs: nuttx-7.18.tar.gz and
+apps-7.18.tar.gz. These are available from:
+
+ https://bitbucket.org/nuttx/nuttx/downloads
+ https://bitbucket.org/nuttx/apps/downloads
+
+Both may be needed (see the top-level nuttx/README.txt file for build
+information).
+
+Additional new features and extended functionality:
+
+ * Core OS:
+
+ - Add standard adjtime() interface and basic timekeeping support.
+ Normally used with an NTP client to keep system time in
+ synchronization. From Max Neklyudov.
+ - Use the oneshot timer with optional entropy to measure CPU load if
+ so configured.
+
+ * File System and Block and MTD Drivers:
+
+ - Add Fujistu MB85RS256B ramtron support. From Beat Küng.
+ - SPI-based MTD driver for Macronix MX25L3233F or MX25L6433F. From
+ Aleksandr Vyhovanec.
+
+ * Graphics/Display Drivers:
+
+ - SH1106 0.96 OLED module support (SSD1306 compatible) + I2C fixes.
+ From v01d (phreakuencies).
+
+ * Sensor Drivers:
+
+ - Add KXJT9 Accelerometer driver from the Motorola Moto Z MDK.
+ - Add MFRC522 RFID ISO14443 and Mifare transceiver driver. From Alan
+ Carvalho de Assis.
+ - Add driver for the LIS3MDL 3 axis magnetometer. From Alexander
+ Entinger.
+ - Add driver for the MLX90393 3 axis magnetometer. From Alexander
+ Entinger.
+ - Add driver for the LIS3DSH 3 axis accelerometer. From Alexander
+ Entinger.
+ - Add driver for the Bosch BMG160 3 axis gyroscope. From Alexander
+ Entinger.
+ - Add support for the Sensixs XEN1210 3D-board. This sensor is used
+ on NANOSATC-BR2 a Brazillian CUBESAT project. From Alan Carvalho
+ de Assis.
+ - Add a new ioctl command (set MAXPOS) for Tiva QEI. From Young.
+
+ * Other Common Device Drivers:
+
+ - I/O Expander: Remove hard-coded PCA9555 fields from ioexpander.h
+ definitons. Add support for an attach() method that may be used
+ when any subset of pin interrupts occur.
+ - I/O Expander Interface: Encode and extend I/O expander options to
+ include interrupt configuration.
+ - PCA9555 Driver: Replace the signalling logic with a simple callback
+ using the new definitons of ioexpander.h. This repartitioning of
+ functionality is necessary because (1) the I/O expander driver is
+ the lower-lower part of any driver that uses GPIOs (include the GPIO
+ driver itself) and should not be interacting directly with the much
+ higher level application layer. And (2) in order to be compatible
+ with the GPIO driver (and any arbitrary upper half driver), the
+ PCA9555 should not directly signal, but should call back into the
+ upper half. The upper half driver that interacts directly with the
+ application is the appropriate place to be generating signal.
+ - Add a skeleton I/O Expander driver (based on the PCA9555 driver).
+ - Add PCF8574 I/O Expander driver.
+ - GPIO driver: Add IOCTLs to get the pin type and to unregister a
+ signal handler.
+ - Add a GPIO lower-half driver that can be used to register a GPIO
+ character driver for accessing pins on an I/O expander.
+ - Add an SPI helper function that encapsulates and manages a sequence
+ of SPI transfers.
+ - Add an SPI character driver that will permit access to the SPI bus
+ for testing purposes.
+ - Add oneshot timer lower half interface definition.
+ - Add an upper-half, oneshot timer character driver.
+ - Add Audio Tone Generator for NuttX. From Alan Carvalho de Assis.
+ - Add USB host support for composite devices. This feature is not
+ well tested.
+ - drivers/ioexpander: Add an (untested) TCA64XX I/O Expander driver
+ leveraged from Project Ara.
+
+ * Simulation Platform:
+
+ - Add a simulated I/O Expander driver.
+ - Add simulator-based test support for apps/examples/gpio.
+ - Add a configuration useful for testing Mini Basic.
+ - Add a simulated oneshot lowerhalf driver.
+
+ * Atmel SAM3/4 Drivers:
+
+ - SAM4CM: Add option to support oneshot timer without free-running
+ timer. Add oneshot lower half driver.
+
+ * Atmel SAMA5 Drivers:
+
+ - SAMA5D: Add option to support oneshot timer without free-running
+ timer. Add oneshot lower half driver.
+
+ * Atmel SAMV7 Drivers:
+
+ - SAMV71/SAME70: Add option to support oneshot timer without
+ free-running timer. Add oneshot lower half driver.
+ - Add support for SAMV7 DACC module. From Piotr Mienkowski.
+
+ * NXP Freescale Kinetis Drivers:
+
+ - Add support for I2C and RTC. From v01d (phreakuencies).
+
+ * NXP Freescale Kinetis Boards:
+
+ - Add teensy 3.x I2C support. From v01d (phreakuencies).
+
+ * STMicro STM32:
+
+ - Add IAR-style STM32F1xx vectors. Tested on STM32F103RB and
+ STM32F107RC. From Aleksandr Vyhovanec.
+
+ * STMicro STM32 Drivers:
+
+ - Add timekeeping support for the STM32 tickless mode. From Max
+ Neklyudov.
+ - Add a oneshot, lower-half driver for STM32.
+ - STM32 L4: Add oneshot lower half driver for STM32 L4.
+ - STM32 L4: Add support for quadrature encoders on STM32L4. Sebastien
+ Lorquet.
+
+ * STMicro STM32 Boards:
+
+ - stm32f103-minimum: Add board support to MFRC522 driver. From Alan
+ Carvalho de Assis.
+ - Add oneshot board initialization to stm32f103-minimum. From Alan
+ Carvalho de Assis.
+ - stm32f103-minimum: Add board configuration to initialize Audio Tone
+ Generator. From Alan Carvalho de Assis.
+ - stm32bufferfly2: Add support for the Kamami stm32butterfly2
+ development board with optional ETH phy. From Michal Lyszczek.
+ - stm32f103-minimum: Add board config support to SPI LCD module
+ JLX12864G-086. From Alan Carvalho de Assis.
+ - stm32l476-mdk: Support basic booting and nsh on Motorola MDK. The
+ Motorola MDK is based off of an earlier version of NuttX.
+ This only provides a basic NSH shell. From Jim Wylder.
+ - STM32 F4 Discovery: Add support for XEN1210 3D-board. From Alan
+ Carvalho de Assis.
+ - stm32f103-minimum: Add stm32_bringup support and userled example to
+ STM32F103 Minimum board. From Alan Carvalho de Assis.
+ - Add support for qencoders on various nucleo boards. From Sebastien
+ Lorquet.
+ - olimex-stm32-e407: Add some networking configurations. From Mateusz
+ Szafoni.
+
+ * TI Tiva Drivers:
+
+ - Add tiva PWM lower-half driver implementation. From Young.
+ - Tiva QEI: Add QEI lower-half driver for Tiva series chip. From
+ Young.
+
+ * C Library/Header Files:
+
+ - Separate XorShift128 PRNG from /dev/urandom and make it generally
+ available.
+ - Add POSIX type sig_atomic_t. From Sebastien Lorquet.
+ - Add the difftime() function. The function depends on the toolchain-
+ dependent CONFIG_HAVE_DOUBLE so is not available on tiny platforms.
+ From Sebastien Lorquet.
+ - Add support for remove(). From Sebastien Lorquet.
+ - Add system() to stdlib.h. Actual implementation is in
+ apps/system/system.
+
+ * Build/Configuration System:
+
+ - Rename arch/sh to arch/renesas.
+ - Remove contactless drivers from drivers/wireless to drivers
+ contactless. From Sebastien Lorquet.
+ - Move all modem-related IOCTL commands to a common file to assure
+ that they will be unique.
+
+ * Tools:
+
+ - Add sethost.sh. This is a script that you can use to quickly
+ change the host platform from Linux to Windows/Cygwin. Might save
+ you a lot of headaches.
+
+ * Applications: apps/nshlib:
+
+ - Add logic to support an NSH-specific system command.
+ - Add printf command to NSH, e.g., controlling /dev/userleds from
+ command line: nsh> printf \x01 > /dev/userleds. From Alan Carvalho
+ de Assis.
+
+ * Platforms: apps/system:
+
+ - Port tee command from NetBSD.
+ - Add a generic system command. Current implentation cannot use
+ /bin/sh and spawns the custom NSH system command directly.
+
+ * Platforms: apps/platform:
+
+ - Add C++ support for STM32L476-MDK.
+
+ * Platforms: apps/interpreters:
+
+ - Add a port of Mini Basic, version 1.0, written by Malcom McLean and
+ released under the Creative Commons Attribution license.
+
+ * Applications: apps/examples:
+
+ - Add a simple test of the GPIO driver.
+ - Add RFID_READUID sample application. From Alan Carvalho de Assis.
+ - Add Oneshot timer example.
+ - Add a simple test of the system command.
+
+Works-In-Progress:
+
+ * IEEE802.14.5/6LowPAN. Hooks and framework for this effort were
+ introduced in NuttX-7.15. Work has continued on this effort on
+ forks from the main repositories, albeit with many interruptions.
+ The completion of this wireless feature will postponed until at
+ least NuttX-7.19.
+
+Bugfixes. Only the most critical bugfixes are listed here (see the
+ChangeLog for the complete list of bugfixes and for additional, more
+detailed bugfix information):
+
+ * Core OS:
+
+ - Explicitly initialize the group tg_exitsem with sem_init(). The
+ existing logic worked because the correct initialization value is
+ all zero, but it is better to initialize the semaphore explicitly.
+ - The TCB nchildren field should not be incremented when pthreads are
+ created.
+ - Move fields related to parent/child task relationship out of TCB
+ into group structure where they belong. Child is a group, not a
+ thread.
+ - mq_send() was not setting the errno value on certain failures to
+ allocate a message.
+ - Define 'group' even if HAVE_GROUPID is not set. From Mateusz
+ Szafoni.
+ - Vector table should have dimension NR_IRQS, not NR_IRQS+1. From
+ Sagitta Li.
+ - pthreads: When a pthread is started, there is a small bit
+ of logic that will run on the thread of execution of the new
+ pthread. In the case where the new pthread has a lower
+ priority than the parent thread, then this could cause both the
+ parent thread and the new pthread to be blocked at the priority of
+ the lower priority pthread (assuming that CONFIG_PRIORITY_INHERITANCE
+ is not selected). This change temporarily boosts the priority of the
+ new pthread to at least the priority of the new pthread to at least
+ the priority of the parent thread. When that bit of logic has
+ executed on the thread of execution of the new pthread, it will then
+ drop to the correct priority (if necessary) before calling into the
+ new pthread's entry point.
+
+ * File System/Block Drivers/MTD Drivers:
+
+ - FAT performance improvement. In large files, seeking to a
+ position from the beginning of the file can be very time consuming.
+ ftell does lssek(fd, 0, SET_CURR). In that case, that is wasted
+ time since we are going to seek to the same position. This fix
+ short-circuits fat_seek() in all cases where we attempt to seek to
+ current position. Suggested by Nate Weibley.
+ - MTD: Fixed cloned typos in several FLASH drivers. From Aleksandr
+ Vyhovanec.
+ - mount: Corrects a bad assertion noted by Pierre-noel Bouteville.
+ Also fixes a reference counting problem in an error condition:
+ When the mountpoint inode is found but is not an appropriate
+ mountpoint, the reference count on the inode was not being
+ decremented.
+
+ * Common Drivers:
+
+ - Various serial drivers: Fix FIONWRITE and add FIONSPACE. All
+ implementations of FIONWRITE were wrong. FIONWRITE should return
+ the number of bytes waiting in the outgoing send queue, not the free
+ space. Rather, FIONSPACE should return the free space in the send
+ queue.
+ - Add missing prototype for btn_lower_initialize().
+ - Make DAC sample structure packed. From Marc Rechté.
+
+ * Networking:
+
+ - TCP: tcp_ipvX_bind() not actually using the port selected with
+ port==0. Also removes duplicate call to pkt_input(). Issues noted
+ by Pascal Speck.
+ - drivers/net: NET_TUN=y => NET_MULTIBUFFER=y. From Vladimir
+ Komendantskiy.
+ - slip driver: Fix calculations using MSEC_PER_TICK. If
+ USEC_PER_TICK is less than 1000, then MSEC_PER_TICK will be
+ zero. It will be inaccurate in any case.
+
+ * Atmel SAM3/4 Drivers:
+
+ - SAM3/4 GPIO: Enable peripheral clock for GPIO port when GPIO is
+ configured as input. The value of a GPIO input is only sampled when
+ the peripheral clock for the port controller the GPIO resides in is
+ enabled. Therefore we need to enable the clock even when polling a
+ GPIO. From Wolfgang Reissnegger.
+ - All SAM Ethernet Drivers: Add support so that the drivers can be
+ built with CONFIG_NET_MULTIBUFFER=y.
+ - SAM3/4: Fix GPIO pull-up/down code. Enabling the pull-down resistor
+ while the pull-up resistor is still enabled is not possible. In this
+ case, the write of PIO_PPDER for the relevant I/O line is discarded.
+ Likewise, enabling the pull-up resistor while the pull-down resistor
+ is still enabled is not possible. In this case, the write of
+ PIO_PUER for the relevant I/O line is discarded. From Wolfgang
+ Reißnegger.
+
+ * Atmel SAMV7 Drivers:
+
+ - All SAM Ethernet Drivers: Add support so that the drivers can be
+ built with CONFIG_NET_MULTIBUFFER=y.
+ - SAM GPIO: Apply Wolfgang's change for SAM3/4 to SAMA5 and SAMV7.
+
+ * Atmel SAMA5:
+
+ - Add missing oneshot max_delay method.
+ - All SAM Ethernet Drivers: Add support so that the drivers can be
+ built with CONFIG_NET_MULTIBUFFER=y.
+ - SAM GPIO: Apply Wolfgang's change for SAM3/4 to SAMA5 and SAMV7.
+
+ * NXP Freescale LPC43xx Drivers:
+
+ - LPC43xx serial: Fix typos in LPC43 serial driver. Found by Vytautas
+ Lukenskas.
+ - LPC43xx Serial: There are some small problems in LPC43xx RS485 mode
+ configuration. In particular: (1) UART0,2,3 do not have DTR pins
+ (different from UART1), so, Kconfig needs to be adjusted. (2)
+ lpc43_uart.c in RS485 mode only configures DIR pin, but doesn't
+ enable pin output for UART0,2,3. (3) should be option to reverse DIR
+ control pin output polarity. (4) lpc43xx/chip/lpc43_uart.h doesn't
+ have USART3 definitions. NOTE: I didn't modified and didn't tested
+ USART1, as it has different hardware. From Vytautas Lukenskas.
+ From Vytautas Lukenskas.
+
+ * SiLabs EFM32 Drivers:
+
+ - EFM32 SPI drivers adopted incompatible conventions (See STM32 for
+ details of the issue).
+
+ * STMicro STM32 Drivers:
+
+ - STM32, STM32 L4, and EFM32 SPI drivers adopted incompatible
+ conventions somewhere along the line. They set the number of bits
+ to negative when calling SPI_SETBITS which had the magical side-
+ effect of setting LSB first order of bit transmission. This is not
+ only a hokey way to pass control information but is supported by no
+ other SPI drivers. This change three things: (1) It adds
+ HWFEAT_LSBFIRST as a new H/W feature. (2) It changes the
+ implementations of SPI_SETBITS in the STM32 and EFM32 drivers so
+ that negated bit numbers are simply errors and it adds the
+ SPI_HWFEATURES method that can set the LSB bit order, and
+ (3) It changes all calls with negative number of bits from all
+ drivers: The number of bits is now always positive and
+ SPI_HWFEATURES is called with HWFEAT_LSBFIRST to set the bit order.
+ - Add missing SPI2 and SPI3 support for STM32F3F3. Add STM32F37XX DMA
+ channel configuration. For STM32F37XX, SYSCFG_EXTICR_PORTE defined
+ twice. From Alan Carvalho de Assis.
+ - STM32: Make stm32_pwr_enablebkp thread safe. From Max Neklyudov.
+ - Fix bad pllmul values for STM32F1XX connectivity line. STM32F1XX
+ connectivity line supports only x4, x5, x6, x7, x8, x9 and x6.5
+ values. From Michal Lyszczek.
+ - STM32F3 SPI: Fix the number of bit setting for the F3. That and
+ data packing work differently on the STM32F3 than for other STM32
+ parts.
+ - STM32 and STM32 L4: Enabling SPI DMA loses other bits in CR2.
+ - STM32F3 SPI: Cannot write always 16-bit value to DR register
+ because of how the F3 implements data packing.
+ - STM32F411 and STM32F446 map i2c2_sda_4 to different alternate
+ function numbers. From Konstantin Berezenko.
+ - STM32 DMA Fix: Change stm32 adc dma callback to send channel
+ number instead of index. From Konstantin Berezenko.
+ - STM32 OTGFS device: Fix for lost first word from FIFO
+
+ 1) Do not overwrite Reserved Bits in GINTSTS (per ref manual)*
+ 2) Acknowledge all pending int on entry to ISR that are Only rc_w1*
+ 3) Do not disable RXFVL*
+ 4) Loop until RXFVL is cleared*
+ 5) Only clear the NAK on the endpoint on the OTGFS_GRXSTSD_PKTSTS_SETUPDONE to not loose the first WORD of FIFO all the data (Bug Fix)
+
+ Changed marked *are just driver clean up and ensure ints are not lost. The bug fix is #5
+
+ Test case open putty and observer the Set/Get LineCoding. Without this fix #5 the Get will not match the Set, and in fact the data might be skewed by 4 bytes, that are lost from the FIFO if the OTGFS_DOEPCTL0_CNAK bit is set in the OTGFS_GRXSTSD_PKTSTS_SETUPRECVD as opposed to the OTGFS_GRXSTSD_PKTSTS_SETUPDONE
+
+ Set Line Coding DATA1: 4B | 00 c2 01 00 00 00 08 | c8 1B
+ Get Line Coding DATA1: 4B | .. .. .. .. 00 00 08 c8 .. 00 00 07 | 7a 72
+
+ From David Sidrane.
+ - STM32 L4 OTGFS device: Apply stm32 fix to stm32l4. From Sebastien
+ Lorquet.
+ - STM32 F7: Remove duplicate call to pkt_input from Ethernet driver.
+ Issues noted by Pascal Speck.
+ - STM32 L4: Add support for USART3-USART5. For STM32L4 parts, the
+ higher number USART ports supported varies. Add the HAVE_USARTx
+ definitions to the configuration to allow enabling the higher
+ numbered USART ports. From Jim Wylder.
+ - STM32 USB: Set USB address to avoid a failed assertion. From
+ Pierre-noel Bouteville.
+ - STM32 L4 and L7 USB: Pierre's assertion-avoidance change should
+ also be applied to STM32 F7 and L4.
+ - STM32, L4, and F7: Remove GPIO_ETH_RMII_TX_CLK. TX_CLK is not
+ present in RMII. Mateusz Szafoni.
+ - STM32 Ethernet: Correct typo in conditional logic. From Neil
+ Hancock.
+ - STM32 L4 USB Device: Fixed L4 USB Driver by avoiding SETUPDONE and
+ EPOUT_SETUP. From David Sidrane.
+ - STM32 SPI: stm32_modifycr2 should be available on all platforms if
+ DMA is enabled.
+ - STM32 DMA2D: fix an error in up_dma2dcreatelayer where an invalid
+ pointer was returned when a certain underlying function failed.
+ From Jens Gräf.
+
+ * TI Tiva Drivers:
+
+ - Fix two bugs of tiva pwm lower-half driver implementation. From
+ Young.
+ - Tiva Ethernet: Needs support for CONFIG_NET_MULTIBUFFER=y.
+
+ * C Library/Header Files:
+
+ - lib_dumpbuffer() now prints a large on-stack buffer first to avoid
+ problems when the syslog output is prefixed with time. From
+ Pierre-noel Bouteville.
+ - libc/math: This fixes the following libc/math issues: (1) asin[f l]()
+ use Newton’s method to converge on a solution. But Newton’s method
+ converges very slowly (> 500,000 iterations) for values of x close to
+ 1.0; and, in the case of asinl(), sometimes fails to converge (loops
+ forever). The attached patch uses an trig identity for values of
+ x > sqrt(2). The resultant functions converge in no more than 5
+ iterations, 6 for asinl(). (2) The NuttX erf[f l]() functions are
+ based on Chebyshev fitting to a good guess. The problem there’s a
+ bug in the implementation that causes the functions to blow up with
+ x near -3.0. This patch fixes that problem. It should be noted that
+ this method returns the error function erf(x) with fractional error
+ less than 1.2E-07 and that’s fine for the float version erff(), but
+ the same method is used for double and long double version which
+ will yield only slightly better precision. This patch doesn't
+ address the issue of lower precision for erf() and erfl(). (3) a
+ faster version of copysignf() for floats is included. From David S.
+ Alessio.
+ - strtod() was not returning endptr on error conditions.
+ - libc/math: floor(), floorf(), and floorl(): Fix logic error. Was
+ not correctly handling negative integral value.
+ - isatty() should be prototyped in unstid.h, not termios.h. From
+ Sebastien Lorquet.
+ - nxglib: Fix handling of near-horizontal lines of width 1 in
+ nxgl_splitline(). Missing handling for degenerate condition caused
+ width 1 lines such as (0, 0) - (100, 10) to have gaps in the
+ drawing. From Petteri Aimonen.
+
+ * Build/Configuration System:
+
+ - Top-Level Makefiles: Fix a chicken-and-egg problem. In the menuconfig
+ target, the context dependency was executed before kconfig-mconf. That
+ was necessary because the link at apps/platform/board needed to be set
+ up before creating the apps/Kconfig file. Otherwise, the platform
+ Kconfig files would not be included. But this introduces the chicken-
+ and-egg problem in some configurations. In particular: (1) An NX
+ graphics configuration is used that requires auto-generation of
+ source files using cpp, (2) the configuration is set for Linux, but
+ (3) we are running under Cygwin with (4) a Windows native toolchain.
+ In this case, POSIX-style symbolic links are set up but the Windows
+ native toolchain cannot follow them. The reason we are running
+ 'make menuconfig' is to change from Linux to Cygwin, but the target
+ fails. During the context phase, NX runs CPP to generate source files
+ but that fails because the Windows native toolchain cannot follow
+ the links. Checkmate. This was fixed by changing all of the make
+ menuconfig (and related) targets. They no longer depend on context
+ being run. Instead, they depend only on the dirlinks target. The
+ dirlinks target only sets up the directory links but does not try
+ to run all of the context setup; the compiler is never invoked; no
+ code is autogenerated and things work.
+ - CXXFLAGS: add -fcheck-new whenever -fno-exceptions is used. From
+ Beat Küng.
+
+ * Tools
+
+ - tools/refresh.sh: Recent complexities added to apps/ means that
+ configuration needs the correct Make.defs file in place in order to
+ configure properly.
+ - tools/kconfig2html.c: Update to handle absolute paths when sourcing
+ Kconfig files.
+ - tools/mkfsdata.pl was still generating the old-style apps/include
+ inclusion paths.
+
+ * Application Build/Configuration System:
+
+ - Add DIRLINK and DIRUNLINK tool definitions to apps/Make.defs.
+
+ * apps/nshlib:
+
+ - Fix FIFO_SIZE vs PIPE_SIZE.
+ - Fix hex representation of IP address in Kconfig. Noted by Michal
+ Lyszczek.
+ - nsh_syscmds.c: missing semicolon. From Mateusz Szafoni.
+ - In system command, don't try to flush output streams if stdio
+ buffered I/O is not supported.
+
+ * apps/canutils:
+
+ - libuavcan: Under certain circumstances, DELIM is not be defined in
+ Makefile.
+ - Add definition for APPNAME in apps/canutils/canlib. From Sebastien
+ Lorquet.
+
+ * apps/gpsutils:
+
+ - Fix an error minmea. From Aleksandr Vyhovanec.
+
+ * apps/examples:
+
+ - apps/examples/oneshot: If the requested delay is > max_delay, then
+ break the delay up into several pieces.
--
GitLab
From 0fa7c62bf4a5e168513ba04434cc4d075b71f45e Mon Sep 17 00:00:00 2001
From: Gregory Nutt
Date: Sat, 8 Oct 2016 11:47:19 -0600
Subject: [PATCH 045/734] Update NuttX.html for 7.18 release
---
Documentation/NuttX.html | 60 +++++++++++++++++++++++++++++++++-------
1 file changed, 50 insertions(+), 10 deletions(-)
diff --git a/Documentation/NuttX.html b/Documentation/NuttX.html
index 4d6823305e..c77315e797 100644
--- a/Documentation/NuttX.html
+++ b/Documentation/NuttX.html
@@ -8,7 +8,7 @@
NuttX RTOS
- Last Updated: September 30, 2016
+ Last Updated: October 8, 2016
|
@@ -1339,11 +1339,11 @@
Released Versions
In addition to the ever-changing GIT repository, there are frozen released versions of NuttX available.
- The current release is NuttX 7.17.
- NuttX 7.17 is the 117th release of NuttX.
- It was released on June 1, 2016, and is available for download from the
+ The current release is NuttX 7.18.
+ NuttX 7.18 is the 118th release of NuttX.
+ It was released on October 8, 2016, and is available for download from the
Bitbucket.org website.
- Note that the release consists of two tarballs: nuttx-7.17.tar.gz
and apps-7.17.tar.gz
.
+ Note that the release consists of two tarballs: nuttx-7.18.tar.gz
and apps-7.18.tar.gz
.
Both may be needed (see the top-level nuttx/README.txt
file for build information).
@@ -1352,7 +1352,7 @@
- nuttx.
- Release notes for NuttX 7.17 are available here.
+ Release notes for NuttX 7.18 are available here.
Release notes for all released versions on NuttX are available in the Bitbucket GIT.
The ChangeLog for all releases of NuttX is available in the ChangeLog file that can viewed in the Bitbucket GIT.
The ChangeLog for the current release is at the bottom of that file.
@@ -1360,7 +1360,7 @@
apps.
- Release notes for NuttX 7.17 are available here.
+ Release notes for NuttX 7.18 are available here.
Release notes for all released versions on NuttX are available in the Bitbucket GIT
The ChangeLog for the all releases of apps/
is available in the ChangeLog file that can viewed in the Bitbucket GIT.
The ChangeLog for the current release is at the bottom of that file.
@@ -2926,6 +2926,7 @@ nsh>
-
The other port is for a generic minimual STM32F103CBT6 "blue" board contributed by Alan Carvalho de Assis.
+ Alan added support for numerous sensors, tone generators, user LEDs, and LCD support in NuttX 7.18.
@@ -3099,7 +3100,7 @@ nsh>
STMicro STM32F107x (STM32 F1 "Connectivity Line" family).
- Chip support for the STM32 F1 "Connectivity Line" family has been present in NuttX for some time and users have reported that they have successful brought up NuttX on there proprietary boards using this logic.
+ Chip support for the STM32 F1 "Connectivity Line" family has been present in NuttX for some time and users have reported that they have successful brought up NuttX on theor proprietary boards using this logic.
-
@@ -3153,7 +3154,17 @@ nsh>
STATUS:
Networking and touchscreen support are well test.
But, at present, neither USB nor LCD functionality have been verified.
- Refer to the SViewtool STM32F103/F107 README file for further information.
+ Refer to the Viewtool STM32F103/F107 README file for further information.
+
+
+ -
+
+ Kamami STM32 Butterfly 2
+ Support for the Kamami STM32 Butterfly 2 was contributed by MichaÅ‚ Åyszczek in NuttX-7/18. That port features the STMicro STM32F107VC MCU.
+
+
+ STATUS:
+ A configuration for the NuttShell (NSH), NSH with networking, and NSH with USB host are available and verified.
|
@@ -3803,6 +3814,7 @@ nsh>
Olimex STM32 E407.
Support for the Olimex STM32 E407 development board was contributed by Mateusz Szafoni and appeared in NuttX-7.17.
+ Networking configurations were added in NuttX-7.18.
See the NuttX board README file for further information about the NuttX port.
@@ -3904,7 +3916,7 @@ nsh>
STMicro STM32 L476.
- Two boards are supported in this family:
+ Three boards are supported in this family:
Status:
@@ -3942,6 +3962,22 @@ nsh>
- CAN contributed by Sebastien Lorquet.
- I2C made functional by Dave (ziggurat29).
+
+ NuttX-7.17.
+ Additional drivers/features were contributed:
+
+
+ - Support for tickless mode.
+ - CAN driver enhancements.
+
+
+ NuttX-7.18.
+ Additional drivers were contributed:
+
+
+ - Oneshot timer driver.
+ - Quadrature encode contributed by Sebastien Lorquet.
+
|
@@ -4154,6 +4190,7 @@ nsh>
Support for the EK-TM4C1294XL was contributed by Frank Sautter and was released in NuttX 7.9.
This basic board support included a configuration for the NuttShell NSH) and a configuration for testing IPv6.
+ See drivers for the TI Tiva TM4C129X.
@@ -4189,6 +4226,9 @@ nsh>
Both are networked enabled: One configured to support IPv4 and one configured to supported IPv6.
Instructions are included in the board README file for configuring both IPv4 and IPv6 simultaneously..
+
+ Tiva PWM and Quadrature Encoder drivers were contributed to NuttX in 7.18 by Young.
+
Refer to the DK-TM4C129X board README file for more detailed information about this port.
--
GitLab
From e568b08b047652aac71e03e83769c4898d6a8f2d Mon Sep 17 00:00:00 2001
From: Gregory Nutt
Date: Sun, 9 Oct 2016 09:36:03 -0600
Subject: [PATCH 046/734] Update TODO list
---
TODO | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++----
1 file changed, 57 insertions(+), 4 deletions(-)
diff --git a/TODO b/TODO
index 5372b0aec5..3c187e017e 100644
--- a/TODO
+++ b/TODO
@@ -1,4 +1,4 @@
-NuttX TODO List (Last updated July 20, 2016)
+NuttX TODO List (Last updated October 9, 2016)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
This file summarizes known NuttX bugs, limitations, inconsistencies with
@@ -11,18 +11,19 @@ nuttx/:
(13) Task/Scheduler (sched/)
(1) Memory Management (mm/)
+ (1) Power Management (drivers/pm)
(3) Signals (sched/signal, arch/)
(2) pthreads (sched/pthread)
(0) Message Queues (sched/mqueue)
(9) Kernel/Protected Build
(3) C++ Support
(6) Binary loaders (binfmt/)
- (11) Network (net/, drivers/net)
+ (12) Network (net/, drivers/net)
(4) USB (drivers/usbdev, drivers/usbhost)
(0) Other drivers (drivers/)
(11) Libraries (libc/, libm/)
(11) File system/Generic drivers (fs/, drivers/)
- (8) Graphics subsystem (graphics/)
+ (9) Graphics Subsystem (graphics/)
(2) Build system / Toolchains
(3) Linux/Cywgin simulation (arch/sim)
(4) ARM (arch/arm/)
@@ -323,6 +324,34 @@ o Memory Management (mm/)
Priority: Medium/Low, a good feature to prevent memory leaks but would
have negative impact on memory usage and code size.
+o Power Management (drivers/pm)
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+ Title: PM CALLBACKS AREN'T BASED ON DOMAIN
+ Description: Recently support for different power domains was added. Prior
+ to this, only a single domain (the "IDLE" domain was supported).
+ Having multiple power domains extends the basic concept to
+ support power management for different functionality. For
+ example, a UI may be managed separately from, say, some network
+ functionality.
+
+ One thing that was missed when the PM domains was added was
+ support for domain-specific driver callbacks: Currently, all
+ callbacks will be invoked for all PM domain events making it
+ impossible to distinguish the domain in the driver.
+
+ Possibilities:
+ - Add a domain value to the PM registration function. In this
+ case, callbacks would be retained separately for each domain
+ and those callbacks would be invoked only for domain-specific
+ events.
+ - Add a domain value to the PM callback functions. In this case,
+ each driver would receive events from all domains and could
+ respond different (or ignore) events from other domains.
+ Status: Open
+ Priority: Currently low because I know of no use of the multiple PM
+ domains. But, obviously, this would become important if the
+ features were used.
o Signals (sched/signal, arch/)
^^^^^^^^^^^^^^^^^^^^^^^
@@ -1032,6 +1061,15 @@ o Network (net/, drivers/net)
Status: Open
Priority: Low
+ Title: REMOVE CONFIG_NET_MULTIBUFFER
+ Description: The CONFIG_NET_MULTIBUFFER controls some details in the layout
+ of the network device structure. This is really a unnecessary
+ complexity and should be removed. The cost for those network
+ drivers that currently do not support CONFIG_NET_MULTIBUFFER
+ is the size of one pointer.
+ Status: Open
+ Priority: Low
+
o USB (drivers/usbdev, drivers/usbhost)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -1501,7 +1539,7 @@ o File system / Generic drivers (fs/, drivers/)
ignored by readder() logic. This the file does not
appear in the 'ls'.
-o Graphics subsystem (graphics/)
+o Graphics Subsystem (graphics/)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
See also the NxWidgets TODO list file for related issues.
@@ -1621,6 +1659,21 @@ o Build system
Priority: Low, since I am not aware of anyone using the Windows Native build.
But, of course, very high if you want to use it.
+ Title: REMOVE SINGLE USER MODE
+ Description: The graphics sub-system can operate in either a single-user mode or
+ in a multi-user mode. In the multiple-user mode, a kernel thread
+ is used to support a graphics server. Multiple applications may then
+ communicate with the server using a message queue. This users only
+ standard POSIX interfaces and works in all build modes (FLAT,
+ PROTECTED, and KERNEL builds).
+
+ The single-user mode, on the hand, uses inappropriate calls directly
+ into the OS. This violates the POSIX interface and must, eventually,
+ be eliminated. These inappropriate calls can only be supported in
+ the FLAT build mode.
+ Status: Open
+ Priority: Medium-High
+
o Other drivers (drivers/)
^^^^^^^^^^^^^^^^^^^^^^^^
--
GitLab
From 79c9e25a123d33b211c01b43ea64895426ebd200 Mon Sep 17 00:00:00 2001
From: Gregory Nutt
Date: Sun, 9 Oct 2016 14:07:19 -0600
Subject: [PATCH 047/734] include/nuttx/fs/nxffs.h: Needs forward reference to
struct mtd_dev_s and needs to include stdbool.h
---
include/nuttx/fs/nxffs.h | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/include/nuttx/fs/nxffs.h b/include/nuttx/fs/nxffs.h
index edbaf190aa..53bec45cf5 100644
--- a/include/nuttx/fs/nxffs.h
+++ b/include/nuttx/fs/nxffs.h
@@ -41,6 +41,9 @@
****************************************************************************/
#include
+
+#include
+
#include
/****************************************************************************
@@ -134,6 +137,7 @@ extern "C"
*
****************************************************************************/
+struct mtd_dev_s;
int nxffs_initialize(FAR struct mtd_dev_s *mtd);
/****************************************************************************
@@ -154,6 +158,7 @@ int nxffs_initialize(FAR struct mtd_dev_s *mtd);
*
****************************************************************************/
+struct mtd_dev_s;
int nxffs_dump(FAR struct mtd_dev_s *mtd, bool verbose);
#undef EXTERN
--
GitLab
From 4703a231716be13eb4ab103040a26ce0d25442c1 Mon Sep 17 00:00:00 2001
From: David Sidrane
Date: Mon, 10 Oct 2016 15:56:02 +0000
Subject: [PATCH 048/734] kinetis.h edited online with Bitbucket
---
arch/arm/src/kinetis/kinetis.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/arch/arm/src/kinetis/kinetis.h b/arch/arm/src/kinetis/kinetis.h
index bb02f01e92..621b21a75c 100644
--- a/arch/arm/src/kinetis/kinetis.h
+++ b/arch/arm/src/kinetis/kinetis.h
@@ -143,8 +143,8 @@
#define PIN_ALT2_OUTPUT (_PIN_MODE_ALT2 | _PIN_OUTPUT)
#define PIN_ALT2_FAST (_PIN_MODE_ALT2 | _PIN_OUTPUT_FAST)
#define PIN_ALT2_SLOW (_PIN_MODE_ALT2 | _PIN_OUTPUT_SLOW)
-#define PIN_ALT2_OPENDRAIN (_PIN_MODE_ALT2 | _PIN_OUTPUT_LOWDRIVE)
-#define PIN_ALT2_LOWDRIVE (_PIN_MODE_ALT2 | _PIN_OUTPUT_OPENDRAIN)
+#define PIN_ALT2_OPENDRAIN (_PIN_MODE_ALT2 | _PIN_OUTPUT_OPENDRAIN)
+#define PIN_ALT2_LOWDRIVE (_PIN_MODE_ALT2 | _PIN_OUTPUT_LOWDRIVE)
#define PIN_ALT2_HIGHDRIVE (_PIN_MODE_ALT2 | _PIN_OUTPUT_HIGHDRIVE)
#define PIN_ALT3 _PIN_MODE_ALT3
--
GitLab
From 0476c4374806c68c3f876acc15f335697ee62bc4 Mon Sep 17 00:00:00 2001
From: David Sidrane
Date: Mon, 10 Oct 2016 15:58:21 +0000
Subject: [PATCH 049/734] kinetis.h edited online with Bitbucket
---
arch/arm/src/kinetis/kinetis.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/arm/src/kinetis/kinetis.h b/arch/arm/src/kinetis/kinetis.h
index bb02f01e92..c10abd9976 100644
--- a/arch/arm/src/kinetis/kinetis.h
+++ b/arch/arm/src/kinetis/kinetis.h
@@ -652,7 +652,7 @@ int kinetis_spi2cmddata(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool cm
*
****************************************************************************/
-#if defined(CONFIG_KINETIS_SPI0) || defined(CONFIG_KINETIS_SPI0) || defined(CONFIG_KINETIS_SPI2)
+#if defined(CONFIG_KINETIS_SPI0) || defined(CONFIG_KINETIS_SPI1) || defined(CONFIG_KINETIS_SPI2)
struct spi_dev_s;
void spi_flush(FAR struct spi_dev_s *dev);
#endif
--
GitLab
From df313581dbef0a22ba04ade1cde4298599ecde62 Mon Sep 17 00:00:00 2001
From: Alan Carvalho de Assis
Date: Tue, 11 Oct 2016 13:00:43 -0600
Subject: [PATCH 050/734] Correct typo in comments
---
include/nuttx/input/buttons.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/include/nuttx/input/buttons.h b/include/nuttx/input/buttons.h
index 901480bc8e..3012ba9857 100644
--- a/include/nuttx/input/buttons.h
+++ b/include/nuttx/input/buttons.h
@@ -69,7 +69,7 @@
* Description: Specify the set of button events that can cause a poll()
* to awaken. The default is all button depressions and all
* button releases (all supported buttons);
- * Argument: A read-only pointer to an instance of struct ajoy_pollevents_s
+ * Argument: A read-only pointer to an instance of struct btn_pollevents_s
* Return: Zero (OK) on success. Minus one will be returned on failure
* with the errno value set appropriately.
*/
--
GitLab
From 4825a8fc3fd8cb957c8735009a1daa902ef01a0d Mon Sep 17 00:00:00 2001
From: Alan Carvalho de Assis
Date: Tue, 11 Oct 2016 14:03:10 -0600
Subject: [PATCH 051/734] STM32 Minimum: Note in Kconfig that the board
supports buttons
---
configs/Kconfig | 2 ++
1 file changed, 2 insertions(+)
diff --git a/configs/Kconfig b/configs/Kconfig
index b4552dd05b..ca3b408285 100644
--- a/configs/Kconfig
+++ b/configs/Kconfig
@@ -959,6 +959,8 @@ config ARCH_BOARD_STM32F103_MINIMUM
bool "STM32F103C8T6 Minimum ARM Development Board"
depends on ARCH_CHIP_STM32F103C8
select ARCH_HAVE_LEDS
+ select ARCH_HAVE_BUTTONS
+ select ARCH_HAVE_IRQBUTTONS
---help---
A configuration for the STM32F103 Minimum board.
--
GitLab
From 91fa8ffaea7e2ae176d6a96031c1c912867da500 Mon Sep 17 00:00:00 2001
From: Alan Carvalho de Assis
Date: Tue, 11 Oct 2016 14:14:06 -0600
Subject: [PATCH 052/734] STM32F103 Minimum: Add button supprt
---
configs/stm32f103-minimum/buttons/Make.defs | 113 ++
configs/stm32f103-minimum/buttons/defconfig | 1160 +++++++++++++++++
configs/stm32f103-minimum/buttons/setenv.sh | 100 ++
configs/stm32f103-minimum/include/board.h | 9 +
configs/stm32f103-minimum/src/Makefile | 4 +
configs/stm32f103-minimum/src/stm32_bringup.c | 14 +
configs/stm32f103-minimum/src/stm32_buttons.c | 171 +++
.../stm32f103-minimum/src/stm32f103_minimum.h | 12 +
8 files changed, 1583 insertions(+)
create mode 100644 configs/stm32f103-minimum/buttons/Make.defs
create mode 100644 configs/stm32f103-minimum/buttons/defconfig
create mode 100644 configs/stm32f103-minimum/buttons/setenv.sh
create mode 100644 configs/stm32f103-minimum/src/stm32_buttons.c
diff --git a/configs/stm32f103-minimum/buttons/Make.defs b/configs/stm32f103-minimum/buttons/Make.defs
new file mode 100644
index 0000000000..d7974b005f
--- /dev/null
+++ b/configs/stm32f103-minimum/buttons/Make.defs
@@ -0,0 +1,113 @@
+############################################################################
+# configs/stm32f103-minimum/userled/Make.defs
+#
+# Copyright (C) 2016 Gregory Nutt. All rights reserved.
+# Author: Gregory Nutt
+#
+# 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
+
+LDSCRIPT = ld.script
+
+ifeq ($(WINTOOL),y)
+ # Windows-native toolchains
+ DIRLINK = $(TOPDIR)/tools/copydir.sh
+ DIRUNLINK = $(TOPDIR)/tools/unlink.sh
+ MKDEP = $(TOPDIR)/tools/mkwindeps.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/$(LDSCRIPT)}"
+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/$(LDSCRIPT)
+endif
+
+CC = $(CROSSDEV)gcc
+CXX = $(CROSSDEV)g++
+CPP = $(CROSSDEV)gcc -E
+LD = $(CROSSDEV)ld
+AR = $(CROSSDEV)ar rcs
+NM = $(CROSSDEV)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
+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
+
+
+HOSTCC = gcc
+HOSTINCLUDES = -I.
+HOSTCFLAGS = -Wall -Wstrict-prototypes -Wshadow -Wundef -g -pipe
+HOSTLDFLAGS =
+
diff --git a/configs/stm32f103-minimum/buttons/defconfig b/configs/stm32f103-minimum/buttons/defconfig
new file mode 100644
index 0000000000..b9acf84dce
--- /dev/null
+++ b/configs/stm32f103-minimum/buttons/defconfig
@@ -0,0 +1,1160 @@
+#
+# Automatically generated file; DO NOT EDIT.
+# Nuttx/ Configuration
+#
+
+#
+# Build Setup
+#
+# CONFIG_EXPERIMENTAL is not set
+CONFIG_DEFAULT_SMALL=y
+CONFIG_HOST_LINUX=y
+# CONFIG_HOST_OSX is not set
+# CONFIG_HOST_WINDOWS is not set
+# CONFIG_HOST_OTHER is not set
+
+#
+# Build Configuration
+#
+# CONFIG_APPS_DIR="../apps"
+CONFIG_BUILD_FLAT=y
+# CONFIG_BUILD_2PASS is not set
+
+#
+# Binary Output Formats
+#
+# CONFIG_RRLOAD_BINARY is not set
+# CONFIG_INTELHEX_BINARY is not set
+# CONFIG_MOTOROLA_SREC is not set
+CONFIG_RAW_BINARY=y
+# CONFIG_UBOOT_UIMAGE is not set
+
+#
+# Customize Header Files
+#
+# CONFIG_ARCH_STDINT_H is not set
+# CONFIG_ARCH_STDBOOL_H is not set
+# CONFIG_ARCH_MATH_H is not set
+# CONFIG_ARCH_FLOAT_H is not set
+# CONFIG_ARCH_STDARG_H is not set
+# CONFIG_ARCH_DEBUG_H is not set
+
+#
+# Debug Options
+#
+CONFIG_DEBUG_ALERT=y
+# CONFIG_DEBUG_FEATURES is not set
+CONFIG_ARCH_HAVE_STACKCHECK=y
+# CONFIG_STACK_COLORATION is not set
+CONFIG_ARCH_HAVE_HEAPCHECK=y
+# CONFIG_HEAP_COLORATION is not set
+# CONFIG_DEBUG_SYMBOLS is not set
+CONFIG_ARCH_HAVE_CUSTOMOPT=y
+# CONFIG_DEBUG_NOOPT is not set
+# CONFIG_DEBUG_CUSTOMOPT is not set
+CONFIG_DEBUG_FULLOPT=y
+
+#
+# System Type
+#
+CONFIG_ARCH_ARM=y
+# CONFIG_ARCH_AVR is not set
+# CONFIG_ARCH_HC is not set
+# CONFIG_ARCH_MIPS is not set
+# CONFIG_ARCH_RGMP is not set
+# CONFIG_ARCH_RENESAS is not set
+# CONFIG_ARCH_SIM is not set
+# CONFIG_ARCH_X86 is not set
+# CONFIG_ARCH_Z16 is not set
+# CONFIG_ARCH_Z80 is not set
+CONFIG_ARCH="arm"
+
+#
+# ARM Options
+#
+# CONFIG_ARCH_CHIP_A1X is not set
+# CONFIG_ARCH_CHIP_C5471 is not set
+# CONFIG_ARCH_CHIP_CALYPSO is not set
+# CONFIG_ARCH_CHIP_DM320 is not set
+# CONFIG_ARCH_CHIP_EFM32 is not set
+# CONFIG_ARCH_CHIP_IMX1 is not set
+# CONFIG_ARCH_CHIP_IMX6 is not set
+# CONFIG_ARCH_CHIP_KINETIS is not set
+# CONFIG_ARCH_CHIP_KL is not set
+# CONFIG_ARCH_CHIP_LM is not set
+# CONFIG_ARCH_CHIP_TIVA is not set
+# CONFIG_ARCH_CHIP_LPC11XX is not set
+# CONFIG_ARCH_CHIP_LPC17XX is not set
+# CONFIG_ARCH_CHIP_LPC214X is not set
+# CONFIG_ARCH_CHIP_LPC2378 is not set
+# CONFIG_ARCH_CHIP_LPC31XX is not set
+# CONFIG_ARCH_CHIP_LPC43XX is not set
+# CONFIG_ARCH_CHIP_NUC1XX is not set
+# CONFIG_ARCH_CHIP_SAMA5 is not set
+# CONFIG_ARCH_CHIP_SAMD is not set
+# CONFIG_ARCH_CHIP_SAML is not set
+# CONFIG_ARCH_CHIP_SAM34 is not set
+# CONFIG_ARCH_CHIP_SAMV7 is not set
+CONFIG_ARCH_CHIP_STM32=y
+# CONFIG_ARCH_CHIP_STM32F7 is not set
+# CONFIG_ARCH_CHIP_STM32L4 is not set
+# CONFIG_ARCH_CHIP_STR71X is not set
+# CONFIG_ARCH_CHIP_TMS570 is not set
+# CONFIG_ARCH_CHIP_MOXART is not set
+# CONFIG_ARCH_ARM7TDMI is not set
+# CONFIG_ARCH_ARM926EJS is not set
+# CONFIG_ARCH_ARM920T is not set
+# CONFIG_ARCH_CORTEXM0 is not set
+CONFIG_ARCH_CORTEXM3=y
+# CONFIG_ARCH_CORTEXM4 is not set
+# CONFIG_ARCH_CORTEXM7 is not set
+# CONFIG_ARCH_CORTEXA5 is not set
+# CONFIG_ARCH_CORTEXA8 is not set
+# CONFIG_ARCH_CORTEXA9 is not set
+# CONFIG_ARCH_CORTEXR4 is not set
+# CONFIG_ARCH_CORTEXR4F is not set
+# CONFIG_ARCH_CORTEXR5 is not set
+# CONFIG_ARCH_CORTEX5F is not set
+# CONFIG_ARCH_CORTEXR7 is not set
+# CONFIG_ARCH_CORTEXR7F is not set
+CONFIG_ARCH_FAMILY="armv7-m"
+CONFIG_ARCH_CHIP="stm32"
+# CONFIG_ARM_TOOLCHAIN_IAR is not set
+CONFIG_ARM_TOOLCHAIN_GNU=y
+# CONFIG_ARMV7M_USEBASEPRI is not set
+CONFIG_ARCH_HAVE_CMNVECTOR=y
+# CONFIG_ARMV7M_CMNVECTOR is not set
+# CONFIG_ARMV7M_LAZYFPU is not set
+# CONFIG_ARCH_HAVE_FPU is not set
+# CONFIG_ARCH_HAVE_DPFPU is not set
+# CONFIG_ARCH_HAVE_TRUSTZONE is not set
+CONFIG_ARM_HAVE_MPU_UNIFIED=y
+# CONFIG_ARM_MPU is not set
+
+#
+# ARMV7M Configuration Options
+#
+# CONFIG_ARMV7M_HAVE_ICACHE is not set
+# CONFIG_ARMV7M_HAVE_DCACHE is not set
+# CONFIG_ARMV7M_HAVE_ITCM is not set
+# CONFIG_ARMV7M_HAVE_DTCM is not set
+# CONFIG_ARMV7M_TOOLCHAIN_IARL is not set
+# CONFIG_ARMV7M_TOOLCHAIN_BUILDROOT is not set
+# CONFIG_ARMV7M_TOOLCHAIN_CODEREDL is not set
+# CONFIG_ARMV7M_TOOLCHAIN_CODESOURCERYL is not set
+CONFIG_ARMV7M_TOOLCHAIN_GNU_EABIL=y
+CONFIG_ARMV7M_HAVE_STACKCHECK=y
+# CONFIG_ARMV7M_STACKCHECK is not set
+# CONFIG_ARMV7M_ITMSYSLOG is not set
+CONFIG_SERIAL_TERMIOS=y
+
+#
+# STM32 Configuration Options
+#
+# CONFIG_ARCH_CHIP_STM32L151C6 is not set
+# CONFIG_ARCH_CHIP_STM32L151C8 is not set
+# CONFIG_ARCH_CHIP_STM32L151CB is not set
+# CONFIG_ARCH_CHIP_STM32L151R6 is not set
+# CONFIG_ARCH_CHIP_STM32L151R8 is not set
+# CONFIG_ARCH_CHIP_STM32L151RB is not set
+# CONFIG_ARCH_CHIP_STM32L151V6 is not set
+# CONFIG_ARCH_CHIP_STM32L151V8 is not set
+# CONFIG_ARCH_CHIP_STM32L151VB is not set
+# CONFIG_ARCH_CHIP_STM32L152C6 is not set
+# CONFIG_ARCH_CHIP_STM32L152C8 is not set
+# CONFIG_ARCH_CHIP_STM32L152CB is not set
+# CONFIG_ARCH_CHIP_STM32L152R6 is not set
+# CONFIG_ARCH_CHIP_STM32L152R8 is not set
+# CONFIG_ARCH_CHIP_STM32L152RB is not set
+# CONFIG_ARCH_CHIP_STM32L152V6 is not set
+# CONFIG_ARCH_CHIP_STM32L152V8 is not set
+# CONFIG_ARCH_CHIP_STM32L152VB is not set
+# CONFIG_ARCH_CHIP_STM32L162ZD is not set
+# CONFIG_ARCH_CHIP_STM32L162VE is not set
+# CONFIG_ARCH_CHIP_STM32F100C8 is not set
+# CONFIG_ARCH_CHIP_STM32F100CB is not set
+# CONFIG_ARCH_CHIP_STM32F100R8 is not set
+# CONFIG_ARCH_CHIP_STM32F100RB is not set
+# CONFIG_ARCH_CHIP_STM32F100RC is not set
+# CONFIG_ARCH_CHIP_STM32F100RD is not set
+# CONFIG_ARCH_CHIP_STM32F100RE is not set
+# CONFIG_ARCH_CHIP_STM32F100V8 is not set
+# CONFIG_ARCH_CHIP_STM32F100VB is not set
+# CONFIG_ARCH_CHIP_STM32F100VC is not set
+# CONFIG_ARCH_CHIP_STM32F100VD is not set
+# CONFIG_ARCH_CHIP_STM32F100VE is not set
+# CONFIG_ARCH_CHIP_STM32F102CB is not set
+# CONFIG_ARCH_CHIP_STM32F103T8 is not set
+# CONFIG_ARCH_CHIP_STM32F103TB is not set
+# CONFIG_ARCH_CHIP_STM32F103C4 is not set
+CONFIG_ARCH_CHIP_STM32F103C8=y
+# CONFIG_ARCH_CHIP_STM32F103CB is not set
+# CONFIG_ARCH_CHIP_STM32F103R8 is not set
+# CONFIG_ARCH_CHIP_STM32F103RB is not set
+# CONFIG_ARCH_CHIP_STM32F103RC is not set
+# CONFIG_ARCH_CHIP_STM32F103RD is not set
+# CONFIG_ARCH_CHIP_STM32F103RE is not set
+# CONFIG_ARCH_CHIP_STM32F103RG is not set
+# CONFIG_ARCH_CHIP_STM32F103V8 is not set
+# CONFIG_ARCH_CHIP_STM32F103VB is not set
+# CONFIG_ARCH_CHIP_STM32F103VC is not set
+# CONFIG_ARCH_CHIP_STM32F103VE is not set
+# CONFIG_ARCH_CHIP_STM32F103ZE is not set
+# CONFIG_ARCH_CHIP_STM32F105VB is not set
+# CONFIG_ARCH_CHIP_STM32F105RB is not set
+# CONFIG_ARCH_CHIP_STM32F107VC is not set
+# CONFIG_ARCH_CHIP_STM32F205RG is not set
+# CONFIG_ARCH_CHIP_STM32F207IG is not set
+# CONFIG_ARCH_CHIP_STM32F207ZE is not set
+# CONFIG_ARCH_CHIP_STM32F302K6 is not set
+# CONFIG_ARCH_CHIP_STM32F302K8 is not set
+# CONFIG_ARCH_CHIP_STM32F302CB is not set
+# CONFIG_ARCH_CHIP_STM32F302CC is not set
+# CONFIG_ARCH_CHIP_STM32F302RB is not set
+# CONFIG_ARCH_CHIP_STM32F302RC is not set
+# CONFIG_ARCH_CHIP_STM32F302VB is not set
+# CONFIG_ARCH_CHIP_STM32F302VC is not set
+# CONFIG_ARCH_CHIP_STM32F303K6 is not set
+# CONFIG_ARCH_CHIP_STM32F303K8 is not set
+# CONFIG_ARCH_CHIP_STM32F303C6 is not set
+# CONFIG_ARCH_CHIP_STM32F303C8 is not set
+# CONFIG_ARCH_CHIP_STM32F303CB is not set
+# CONFIG_ARCH_CHIP_STM32F303CC is not set
+# CONFIG_ARCH_CHIP_STM32F303RB is not set
+# CONFIG_ARCH_CHIP_STM32F303RC is not set
+# CONFIG_ARCH_CHIP_STM32F303RD is not set
+# CONFIG_ARCH_CHIP_STM32F303RE is not set
+# CONFIG_ARCH_CHIP_STM32F303VB is not set
+# CONFIG_ARCH_CHIP_STM32F303VC is not set
+# CONFIG_ARCH_CHIP_STM32F372C8 is not set
+# CONFIG_ARCH_CHIP_STM32F372R8 is not set
+# CONFIG_ARCH_CHIP_STM32F372V8 is not set
+# CONFIG_ARCH_CHIP_STM32F372CB is not set
+# CONFIG_ARCH_CHIP_STM32F372RB is not set
+# CONFIG_ARCH_CHIP_STM32F372VB is not set
+# CONFIG_ARCH_CHIP_STM32F372CC is not set
+# CONFIG_ARCH_CHIP_STM32F372RC is not set
+# CONFIG_ARCH_CHIP_STM32F372VC is not set
+# CONFIG_ARCH_CHIP_STM32F373C8 is not set
+# CONFIG_ARCH_CHIP_STM32F373R8 is not set
+# CONFIG_ARCH_CHIP_STM32F373V8 is not set
+# CONFIG_ARCH_CHIP_STM32F373CB is not set
+# CONFIG_ARCH_CHIP_STM32F373RB is not set
+# CONFIG_ARCH_CHIP_STM32F373VB is not set
+# CONFIG_ARCH_CHIP_STM32F373CC is not set
+# CONFIG_ARCH_CHIP_STM32F373RC is not set
+# CONFIG_ARCH_CHIP_STM32F373VC is not set
+# CONFIG_ARCH_CHIP_STM32F401RE is not set
+# CONFIG_ARCH_CHIP_STM32F411RE is not set
+# CONFIG_ARCH_CHIP_STM32F411VE is not set
+# CONFIG_ARCH_CHIP_STM32F405RG is not set
+# CONFIG_ARCH_CHIP_STM32F405VG is not set
+# CONFIG_ARCH_CHIP_STM32F405ZG is not set
+# CONFIG_ARCH_CHIP_STM32F407VE is not set
+# CONFIG_ARCH_CHIP_STM32F407VG is not set
+# CONFIG_ARCH_CHIP_STM32F407ZE is not set
+# CONFIG_ARCH_CHIP_STM32F407ZG is not set
+# CONFIG_ARCH_CHIP_STM32F407IE is not set
+# CONFIG_ARCH_CHIP_STM32F407IG is not set
+# CONFIG_ARCH_CHIP_STM32F427V is not set
+# CONFIG_ARCH_CHIP_STM32F427Z is not set
+# CONFIG_ARCH_CHIP_STM32F427I is not set
+# CONFIG_ARCH_CHIP_STM32F429V is not set
+# CONFIG_ARCH_CHIP_STM32F429Z is not set
+# CONFIG_ARCH_CHIP_STM32F429I is not set
+# CONFIG_ARCH_CHIP_STM32F429B is not set
+# CONFIG_ARCH_CHIP_STM32F429N is not set
+# CONFIG_ARCH_CHIP_STM32F446M is not set
+# CONFIG_ARCH_CHIP_STM32F446R is not set
+# CONFIG_ARCH_CHIP_STM32F446V is not set
+# CONFIG_ARCH_CHIP_STM32F446Z is not set
+# CONFIG_ARCH_CHIP_STM32F469A is not set
+# CONFIG_ARCH_CHIP_STM32F469I is not set
+# CONFIG_ARCH_CHIP_STM32F469B is not set
+# CONFIG_ARCH_CHIP_STM32F469N is not set
+CONFIG_STM32_FLASH_CONFIG_DEFAULT=y
+# CONFIG_STM32_FLASH_CONFIG_4 is not set
+# CONFIG_STM32_FLASH_CONFIG_6 is not set
+# CONFIG_STM32_FLASH_CONFIG_8 is not set
+# CONFIG_STM32_FLASH_CONFIG_B is not set
+# CONFIG_STM32_FLASH_CONFIG_C is not set
+# CONFIG_STM32_FLASH_CONFIG_D is not set
+# CONFIG_STM32_FLASH_CONFIG_E is not set
+# CONFIG_STM32_FLASH_CONFIG_F is not set
+# CONFIG_STM32_FLASH_CONFIG_G is not set
+# CONFIG_STM32_FLASH_CONFIG_I is not set
+# CONFIG_STM32_STM32L15XX is not set
+# CONFIG_STM32_ENERGYLITE is not set
+CONFIG_STM32_STM32F10XX=y
+# CONFIG_STM32_VALUELINE is not set
+# CONFIG_STM32_CONNECTIVITYLINE is not set
+CONFIG_STM32_PERFORMANCELINE=y
+# CONFIG_STM32_USBACCESSLINE is not set
+# CONFIG_STM32_HIGHDENSITY is not set
+CONFIG_STM32_MEDIUMDENSITY=y
+# CONFIG_STM32_LOWDENSITY is not set
+# CONFIG_STM32_STM32F20XX is not set
+# CONFIG_STM32_STM32F205 is not set
+# CONFIG_STM32_STM32F207 is not set
+# CONFIG_STM32_STM32F30XX is not set
+# CONFIG_STM32_STM32F302 is not set
+# CONFIG_STM32_STM32F303 is not set
+# CONFIG_STM32_STM32F37XX is not set
+# CONFIG_STM32_STM32F40XX is not set
+# CONFIG_STM32_STM32F401 is not set
+# CONFIG_STM32_STM32F411 is not set
+# CONFIG_STM32_STM32F405 is not set
+# CONFIG_STM32_STM32F407 is not set
+# CONFIG_STM32_STM32F427 is not set
+# CONFIG_STM32_STM32F429 is not set
+# CONFIG_STM32_STM32F446 is not set
+# CONFIG_STM32_STM32F469 is not set
+# CONFIG_STM32_DFU is not set
+
+#
+# STM32 Peripheral Support
+#
+# CONFIG_STM32_HAVE_CCM is not set
+CONFIG_STM32_HAVE_USBDEV=y
+# CONFIG_STM32_HAVE_OTGFS is not set
+# CONFIG_STM32_HAVE_FSMC is not set
+# CONFIG_STM32_HAVE_LTDC is not set
+CONFIG_STM32_HAVE_USART3=y
+CONFIG_STM32_HAVE_UART4=y
+CONFIG_STM32_HAVE_UART5=y
+# CONFIG_STM32_HAVE_USART6 is not set
+# CONFIG_STM32_HAVE_UART7 is not set
+# CONFIG_STM32_HAVE_UART8 is not set
+CONFIG_STM32_HAVE_TIM1=y
+# CONFIG_STM32_HAVE_TIM2 is not set
+CONFIG_STM32_HAVE_TIM3=y
+CONFIG_STM32_HAVE_TIM4=y
+CONFIG_STM32_HAVE_TIM5=y
+CONFIG_STM32_HAVE_TIM6=y
+CONFIG_STM32_HAVE_TIM7=y
+CONFIG_STM32_HAVE_TIM8=y
+# CONFIG_STM32_HAVE_TIM9 is not set
+# CONFIG_STM32_HAVE_TIM10 is not set
+# CONFIG_STM32_HAVE_TIM11 is not set
+# CONFIG_STM32_HAVE_TIM12 is not set
+# CONFIG_STM32_HAVE_TIM13 is not set
+# CONFIG_STM32_HAVE_TIM14 is not set
+# CONFIG_STM32_HAVE_TIM15 is not set
+# CONFIG_STM32_HAVE_TIM16 is not set
+# CONFIG_STM32_HAVE_TIM17 is not set
+CONFIG_STM32_HAVE_ADC2=y
+CONFIG_STM32_HAVE_ADC3=y
+# CONFIG_STM32_HAVE_ADC4 is not set
+# CONFIG_STM32_HAVE_ADC1_DMA is not set
+# CONFIG_STM32_HAVE_ADC2_DMA is not set
+# CONFIG_STM32_HAVE_ADC3_DMA is not set
+# CONFIG_STM32_HAVE_ADC4_DMA is not set
+CONFIG_STM32_HAVE_CAN1=y
+# CONFIG_STM32_HAVE_CAN2 is not set
+# CONFIG_STM32_HAVE_DAC1 is not set
+# CONFIG_STM32_HAVE_DAC2 is not set
+# CONFIG_STM32_HAVE_RNG is not set
+# CONFIG_STM32_HAVE_ETHMAC is not set
+CONFIG_STM32_HAVE_I2C2=y
+# CONFIG_STM32_HAVE_I2C3 is not set
+CONFIG_STM32_HAVE_SPI2=y
+CONFIG_STM32_HAVE_SPI3=y
+# CONFIG_STM32_HAVE_SPI4 is not set
+# CONFIG_STM32_HAVE_SPI5 is not set
+# CONFIG_STM32_HAVE_SPI6 is not set
+# CONFIG_STM32_HAVE_SAIPLL is not set
+# CONFIG_STM32_HAVE_I2SPLL is not set
+# CONFIG_STM32_ADC1 is not set
+# CONFIG_STM32_ADC2 is not set
+# CONFIG_STM32_ADC3 is not set
+# CONFIG_STM32_BKP is not set
+# CONFIG_STM32_CAN1 is not set
+# CONFIG_STM32_CRC is not set
+# CONFIG_STM32_DMA1 is not set
+# CONFIG_STM32_DMA2 is not set
+# CONFIG_STM32_I2C1 is not set
+# CONFIG_STM32_I2C2 is not set
+# CONFIG_STM32_PWR is not set
+# CONFIG_STM32_SDIO is not set
+# CONFIG_STM32_SPI1 is not set
+# CONFIG_STM32_SPI2 is not set
+# CONFIG_STM32_SPI3 is not set
+# CONFIG_STM32_TIM1 is not set
+# CONFIG_STM32_TIM2 is not set
+# CONFIG_STM32_TIM3 is not set
+# CONFIG_STM32_TIM4 is not set
+# CONFIG_STM32_TIM5 is not set
+# CONFIG_STM32_TIM6 is not set
+# CONFIG_STM32_TIM7 is not set
+# CONFIG_STM32_TIM8 is not set
+CONFIG_STM32_USART1=y
+# CONFIG_STM32_USART2 is not set
+# CONFIG_STM32_USART3 is not set
+# CONFIG_STM32_UART4 is not set
+# CONFIG_STM32_UART5 is not set
+# CONFIG_STM32_USB is not set
+# CONFIG_STM32_IWDG is not set
+# CONFIG_STM32_WWDG is not set
+# CONFIG_STM32_NOEXT_VECTORS is not set
+
+#
+# Alternate Pin Mapping
+#
+# CONFIG_STM32_USART1_REMAP is not set
+# CONFIG_STM32_JTAG_DISABLE is not set
+# CONFIG_STM32_JTAG_FULL_ENABLE is not set
+# CONFIG_STM32_JTAG_NOJNTRST_ENABLE is not set
+CONFIG_STM32_JTAG_SW_ENABLE=y
+CONFIG_STM32_DISABLE_IDLE_SLEEP_DURING_DEBUG=y
+# CONFIG_STM32_FORCEPOWER is not set
+# CONFIG_ARCH_BOARD_STM32_CUSTOM_CLOCKCONFIG is not set
+
+#
+# Timer Configuration
+#
+# CONFIG_STM32_ONESHOT is not set
+# CONFIG_STM32_FREERUN is not set
+# CONFIG_STM32_TIM1_CAP is not set
+# CONFIG_STM32_TIM3_CAP is not set
+# CONFIG_STM32_TIM4_CAP is not set
+# CONFIG_STM32_TIM5_CAP is not set
+# CONFIG_STM32_TIM8_CAP is not set
+CONFIG_STM32_USART=y
+CONFIG_STM32_SERIALDRIVER=y
+
+#
+# U[S]ART Configuration
+#
+
+#
+# U[S]ART Device Configuration
+#
+CONFIG_STM32_USART1_SERIALDRIVER=y
+# CONFIG_STM32_USART1_1WIREDRIVER is not set
+# CONFIG_USART1_RS485 is not set
+
+#
+# Serial Driver Configuration
+#
+# CONFIG_SERIAL_DISABLE_REORDERING is not set
+# CONFIG_STM32_FLOWCONTROL_BROKEN is not set
+# CONFIG_STM32_USART_BREAKS is not set
+# CONFIG_STM32_USART_SINGLEWIRE is not set
+CONFIG_STM32_HAVE_RTC_COUNTER=y
+# CONFIG_STM32_HAVE_RTC_SUBSECONDS is not set
+
+#
+# USB FS Host Configuration
+#
+
+#
+# USB HS Host Configuration
+#
+
+#
+# USB Host Debug Configuration
+#
+
+#
+# USB Device Configuration
+#
+
+#
+# Architecture Options
+#
+# CONFIG_ARCH_NOINTC is not set
+# CONFIG_ARCH_VECNOTIRQ is not set
+# CONFIG_ARCH_DMA is not set
+CONFIG_ARCH_HAVE_IRQPRIO=y
+# CONFIG_ARCH_L2CACHE is not set
+# CONFIG_ARCH_HAVE_COHERENT_DCACHE is not set
+# CONFIG_ARCH_HAVE_ADDRENV is not set
+# CONFIG_ARCH_NEED_ADDRENV_MAPPING is not set
+# CONFIG_ARCH_HAVE_MULTICPU is not set
+CONFIG_ARCH_HAVE_VFORK=y
+# CONFIG_ARCH_HAVE_MMU is not set
+CONFIG_ARCH_HAVE_MPU=y
+# CONFIG_ARCH_NAND_HWECC is not set
+# CONFIG_ARCH_HAVE_EXTCLK is not set
+# CONFIG_ARCH_HAVE_POWEROFF is not set
+CONFIG_ARCH_HAVE_RESET=y
+# CONFIG_ARCH_USE_MPU is not set
+# CONFIG_ARCH_IRQPRIO is not set
+CONFIG_ARCH_STACKDUMP=y
+# CONFIG_ENDIAN_BIG is not set
+# CONFIG_ARCH_IDLE_CUSTOM is not set
+# CONFIG_ARCH_HAVE_RAMFUNCS is not set
+CONFIG_ARCH_HAVE_RAMVECTORS=y
+# CONFIG_ARCH_RAMVECTORS is not set
+
+#
+# Board Settings
+#
+CONFIG_BOARD_LOOPSPERMSEC=5483
+# CONFIG_ARCH_CALIBRATION is not set
+
+#
+# Interrupt options
+#
+CONFIG_ARCH_HAVE_INTERRUPTSTACK=y
+CONFIG_ARCH_INTERRUPTSTACK=0
+CONFIG_ARCH_HAVE_HIPRI_INTERRUPT=y
+# CONFIG_ARCH_HIPRI_INTERRUPT is not set
+
+#
+# Boot options
+#
+# CONFIG_BOOT_RUNFROMEXTSRAM is not set
+CONFIG_BOOT_RUNFROMFLASH=y
+# CONFIG_BOOT_RUNFROMISRAM is not set
+# CONFIG_BOOT_RUNFROMSDRAM is not set
+# CONFIG_BOOT_COPYTORAM is not set
+
+#
+# Boot Memory Configuration
+#
+CONFIG_RAM_START=0x20000000
+CONFIG_RAM_SIZE=20480
+# CONFIG_ARCH_HAVE_SDRAM is not set
+
+#
+# Board Selection
+#
+# CONFIG_ARCH_BOARD_STM32_TINY is not set
+CONFIG_ARCH_BOARD_STM32F103_MINIMUM=y
+# CONFIG_ARCH_BOARD_CUSTOM is not set
+CONFIG_ARCH_BOARD="stm32f103-minimum"
+
+#
+# Common Board Options
+#
+CONFIG_ARCH_HAVE_LEDS=y
+# CONFIG_ARCH_LEDS is not set
+CONFIG_ARCH_HAVE_BUTTONS=y
+CONFIG_ARCH_BUTTONS=y
+CONFIG_ARCH_HAVE_IRQBUTTONS=y
+CONFIG_ARCH_IRQBUTTONS=y
+
+#
+# Board-Specific Options
+#
+# CONFIG_BOARD_CRASHDUMP is not set
+CONFIG_LIB_BOARDCTL=y
+# CONFIG_BOARDCTL_RESET is not set
+# CONFIG_BOARDCTL_UNIQUEID is not set
+# CONFIG_BOARDCTL_TSCTEST is not set
+# CONFIG_BOARDCTL_ADCTEST is not set
+# CONFIG_BOARDCTL_PWMTEST is not set
+# CONFIG_BOARDCTL_GRAPHICS is not set
+# CONFIG_BOARDCTL_IOCTL is not set
+
+#
+# RTOS Features
+#
+# CONFIG_DISABLE_OS_API is not set
+
+#
+# Clocks and Timers
+#
+CONFIG_ARCH_HAVE_TICKLESS=y
+# CONFIG_SCHED_TICKLESS is not set
+CONFIG_USEC_PER_TICK=10000
+# CONFIG_SYSTEM_TIME64 is not set
+# CONFIG_CLOCK_MONOTONIC is not set
+CONFIG_ARCH_HAVE_TIMEKEEPING=y
+# CONFIG_JULIAN_TIME is not set
+CONFIG_START_YEAR=2011
+CONFIG_START_MONTH=7
+CONFIG_START_DAY=5
+CONFIG_MAX_WDOGPARMS=2
+CONFIG_PREALLOC_WDOGS=4
+CONFIG_WDOG_INTRESERVE=0
+CONFIG_PREALLOC_TIMERS=4
+
+#
+# Tasks and Scheduling
+#
+# CONFIG_INIT_NONE is not set
+CONFIG_INIT_ENTRYPOINT=y
+# CONFIG_INIT_FILEPATH is not set
+CONFIG_USER_ENTRYPOINT="nsh_main"
+CONFIG_RR_INTERVAL=200
+# CONFIG_SCHED_SPORADIC is not set
+CONFIG_TASK_NAME_SIZE=0
+CONFIG_MAX_TASKS=16
+# CONFIG_SCHED_HAVE_PARENT is not set
+CONFIG_SCHED_WAITPID=y
+
+#
+# Pthread Options
+#
+# CONFIG_MUTEX_TYPES is not set
+CONFIG_NPTHREAD_KEYS=4
+
+#
+# Performance Monitoring
+#
+# CONFIG_SCHED_CPULOAD is not set
+# CONFIG_SCHED_INSTRUMENTATION is not set
+
+#
+# Files and I/O
+#
+CONFIG_DEV_CONSOLE=y
+# CONFIG_FDCLONE_DISABLE is not set
+# CONFIG_FDCLONE_STDIO is not set
+CONFIG_SDCLONE_DISABLE=y
+CONFIG_NFILE_DESCRIPTORS=8
+CONFIG_NFILE_STREAMS=8
+CONFIG_NAME_MAX=32
+# CONFIG_PRIORITY_INHERITANCE is not set
+
+#
+# RTOS hooks
+#
+CONFIG_BOARD_INITIALIZE=y
+# CONFIG_BOARD_INITTHREAD is not set
+# CONFIG_SCHED_STARTHOOK is not set
+# CONFIG_SCHED_ATEXIT is not set
+# CONFIG_SCHED_ONEXIT is not set
+# CONFIG_SIG_EVTHREAD is not set
+
+#
+# Signal Numbers
+#
+CONFIG_SIG_SIGUSR1=1
+CONFIG_SIG_SIGUSR2=2
+CONFIG_SIG_SIGALARM=3
+CONFIG_SIG_SIGCONDTIMEDOUT=16
+CONFIG_SIG_SIGWORK=17
+
+#
+# POSIX Message Queue Options
+#
+CONFIG_PREALLOC_MQ_MSGS=4
+CONFIG_MQ_MAXMSGSIZE=32
+# CONFIG_MODULE is not set
+
+#
+# Work queue support
+#
+CONFIG_SCHED_WORKQUEUE=y
+CONFIG_SCHED_HPWORK=y
+CONFIG_SCHED_HPWORKPRIORITY=192
+CONFIG_SCHED_HPWORKPERIOD=50000
+CONFIG_SCHED_HPWORKSTACKSIZE=2048
+# CONFIG_SCHED_LPWORK is not set
+
+#
+# Stack and heap information
+#
+CONFIG_IDLETHREAD_STACKSIZE=1024
+CONFIG_USERMAIN_STACKSIZE=2048
+CONFIG_PTHREAD_STACK_MIN=256
+CONFIG_PTHREAD_STACK_DEFAULT=2048
+# CONFIG_LIB_SYSCALL is not set
+
+#
+# Device Drivers
+#
+# CONFIG_DISABLE_POLL is not set
+CONFIG_DEV_NULL=y
+# CONFIG_DEV_ZERO is not set
+# CONFIG_DEV_URANDOM is not set
+# CONFIG_DEV_LOOP is not set
+
+#
+# Buffering
+#
+# CONFIG_DRVR_WRITEBUFFER is not set
+# CONFIG_DRVR_READAHEAD is not set
+# CONFIG_RAMDISK is not set
+# CONFIG_CAN is not set
+# CONFIG_ARCH_HAVE_PWM_PULSECOUNT is not set
+# CONFIG_ARCH_HAVE_PWM_MULTICHAN is not set
+# CONFIG_PWM is not set
+CONFIG_ARCH_HAVE_I2CRESET=y
+# CONFIG_I2C is not set
+# CONFIG_SPI is not set
+CONFIG_ARCH_HAVE_SPI_BITORDER=y
+# CONFIG_I2S is not set
+
+#
+# Timer Driver Support
+#
+# CONFIG_TIMER is not set
+# CONFIG_ONESHOT is not set
+# CONFIG_RTC is not set
+# CONFIG_WATCHDOG is not set
+# CONFIG_ANALOG is not set
+# CONFIG_AUDIO_DEVICES is not set
+# CONFIG_VIDEO_DEVICES is not set
+# CONFIG_BCH is not set
+CONFIG_INPUT=y
+# CONFIG_MOUSE is not set
+# CONFIG_INPUT_MAX11802 is not set
+# CONFIG_INPUT_TSC2007 is not set
+# CONFIG_INPUT_ADS7843E is not set
+# CONFIG_INPUT_MXT is not set
+# CONFIG_INPUT_STMPE811 is not set
+CONFIG_BUTTONS=y
+CONFIG_BUTTONS_LOWER=y
+CONFIG_BUTTONS_NPOLLWAITERS=2
+# CONFIG_DJOYSTICK is not set
+# CONFIG_AJOYSTICK is not set
+
+#
+# IO Expander/GPIO Support
+#
+# CONFIG_IOEXPANDER is not set
+# CONFIG_DEV_GPIO is not set
+
+#
+# LCD Driver Support
+#
+# CONFIG_LCD is not set
+# CONFIG_SLCD is not set
+
+#
+# LED Support
+#
+# CONFIG_USERLED is not set
+# CONFIG_RGBLED is not set
+# CONFIG_PCA9635PW is not set
+# CONFIG_NCP5623C is not set
+# CONFIG_MMCSD is not set
+# CONFIG_MODEM is not set
+# CONFIG_MTD is not set
+# CONFIG_EEPROM is not set
+# CONFIG_PIPES is not set
+# CONFIG_PM is not set
+# CONFIG_POWER is not set
+# CONFIG_SENSORS is not set
+# CONFIG_SERCOMM_CONSOLE is not set
+CONFIG_SERIAL=y
+# CONFIG_DEV_LOWCONSOLE is not set
+# CONFIG_SERIAL_REMOVABLE is not set
+CONFIG_SERIAL_CONSOLE=y
+# CONFIG_16550_UART is not set
+# CONFIG_UART_SERIALDRIVER is not set
+# CONFIG_UART0_SERIALDRIVER is not set
+# CONFIG_UART1_SERIALDRIVER is not set
+# CONFIG_UART2_SERIALDRIVER is not set
+# CONFIG_UART3_SERIALDRIVER is not set
+# CONFIG_UART4_SERIALDRIVER is not set
+# CONFIG_UART5_SERIALDRIVER is not set
+# CONFIG_UART6_SERIALDRIVER is not set
+# CONFIG_UART7_SERIALDRIVER is not set
+# CONFIG_UART8_SERIALDRIVER is not set
+# CONFIG_SCI0_SERIALDRIVER is not set
+# CONFIG_SCI1_SERIALDRIVER is not set
+# CONFIG_USART0_SERIALDRIVER is not set
+CONFIG_USART1_SERIALDRIVER=y
+# CONFIG_USART2_SERIALDRIVER is not set
+# CONFIG_USART3_SERIALDRIVER is not set
+# CONFIG_USART4_SERIALDRIVER is not set
+# CONFIG_USART5_SERIALDRIVER is not set
+# CONFIG_USART6_SERIALDRIVER is not set
+# CONFIG_USART7_SERIALDRIVER is not set
+# CONFIG_USART8_SERIALDRIVER is not set
+# CONFIG_OTHER_UART_SERIALDRIVER is not set
+CONFIG_MCU_SERIAL=y
+CONFIG_STANDARD_SERIAL=y
+CONFIG_SERIAL_NPOLLWAITERS=2
+# CONFIG_SERIAL_IFLOWCONTROL is not set
+# CONFIG_SERIAL_OFLOWCONTROL is not set
+# CONFIG_SERIAL_DMA is not set
+CONFIG_ARCH_HAVE_SERIAL_TERMIOS=y
+CONFIG_USART1_SERIAL_CONSOLE=y
+# CONFIG_OTHER_SERIAL_CONSOLE is not set
+# CONFIG_NO_SERIAL_CONSOLE is not set
+
+#
+# USART1 Configuration
+#
+CONFIG_USART1_RXBUFSIZE=256
+CONFIG_USART1_TXBUFSIZE=256
+CONFIG_USART1_BAUD=115200
+CONFIG_USART1_BITS=8
+CONFIG_USART1_PARITY=0
+CONFIG_USART1_2STOP=0
+# CONFIG_USART1_IFLOWCONTROL is not set
+# CONFIG_USART1_OFLOWCONTROL is not set
+# CONFIG_USART1_DMA is not set
+# CONFIG_PSEUDOTERM is not set
+# CONFIG_USBDEV is not set
+# CONFIG_USBHOST is not set
+# CONFIG_HAVE_USBTRACE is not set
+# CONFIG_DRIVERS_WIRELESS is not set
+# CONFIG_DRIVERS_CONTACTLESS is not set
+
+#
+# System Logging
+#
+# CONFIG_ARCH_SYSLOG is not set
+# CONFIG_RAMLOG is not set
+# CONFIG_SYSLOG_INTBUFFER is not set
+# CONFIG_SYSLOG_TIMESTAMP is not set
+CONFIG_SYSLOG_SERIAL_CONSOLE=y
+# CONFIG_SYSLOG_CHAR is not set
+CONFIG_SYSLOG_CONSOLE=y
+# CONFIG_SYSLOG_NONE is not set
+# CONFIG_SYSLOG_FILE is not set
+# CONFIG_SYSLOG_CHARDEV is not set
+
+#
+# Networking Support
+#
+# CONFIG_ARCH_HAVE_NET is not set
+# CONFIG_ARCH_HAVE_PHY is not set
+# CONFIG_NET is not set
+
+#
+# Crypto API
+#
+# CONFIG_CRYPTO is not set
+
+#
+# File Systems
+#
+
+#
+# File system configuration
+#
+# CONFIG_DISABLE_MOUNTPOINT is not set
+# CONFIG_FS_AUTOMOUNTER is not set
+CONFIG_DISABLE_PSEUDOFS_OPERATIONS=y
+# CONFIG_FS_READABLE is not set
+# CONFIG_FS_WRITABLE is not set
+# CONFIG_FS_NAMED_SEMAPHORES is not set
+CONFIG_FS_MQUEUE_MPATH="/var/mqueue"
+# CONFIG_FS_RAMMAP is not set
+# CONFIG_FS_FAT is not set
+# CONFIG_FS_NXFFS is not set
+# CONFIG_FS_ROMFS is not set
+# CONFIG_FS_TMPFS is not set
+# CONFIG_FS_SMARTFS is not set
+# CONFIG_FS_BINFS is not set
+# CONFIG_FS_PROCFS is not set
+# CONFIG_FS_UNIONFS is not set
+
+#
+# Graphics Support
+#
+# CONFIG_NX is not set
+
+#
+# Memory Management
+#
+# CONFIG_MM_SMALL is not set
+CONFIG_MM_REGIONS=1
+# CONFIG_ARCH_HAVE_HEAP2 is not set
+# CONFIG_GRAN is not set
+
+#
+# Audio Support
+#
+# CONFIG_AUDIO is not set
+
+#
+# Wireless Support
+#
+
+#
+# Binary Loader
+#
+# CONFIG_BINFMT_DISABLE is not set
+# CONFIG_BINFMT_EXEPATH is not set
+# CONFIG_NXFLAT is not set
+# CONFIG_ELF is not set
+CONFIG_BUILTIN=y
+# CONFIG_PIC is not set
+CONFIG_SYMTAB_ORDEREDBYNAME=y
+
+#
+# Library Routines
+#
+
+#
+# Standard C Library Options
+#
+CONFIG_STDIO_BUFFER_SIZE=64
+CONFIG_STDIO_LINEBUFFER=y
+CONFIG_NUNGET_CHARS=2
+CONFIG_LIB_HOMEDIR="/"
+# CONFIG_LIBM is not set
+# CONFIG_NOPRINTF_FIELDWIDTH is not set
+# CONFIG_LIBC_FLOATINGPOINT is not set
+# CONFIG_LIBC_LONG_LONG is not set
+# CONFIG_LIBC_IOCTL_VARIADIC is not set
+CONFIG_LIB_RAND_ORDER=1
+# CONFIG_EOL_IS_CR is not set
+# CONFIG_EOL_IS_LF is not set
+# CONFIG_EOL_IS_BOTH_CRLF is not set
+CONFIG_EOL_IS_EITHER_CRLF=y
+# CONFIG_LIBC_EXECFUNCS is not set
+CONFIG_POSIX_SPAWN_PROXY_STACKSIZE=1024
+CONFIG_TASK_SPAWN_DEFAULT_STACKSIZE=2048
+# CONFIG_LIBC_STRERROR is not set
+# CONFIG_LIBC_PERROR_STDOUT is not set
+CONFIG_ARCH_LOWPUTC=y
+# CONFIG_LIBC_LOCALTIME is not set
+# CONFIG_TIME_EXTENDED is not set
+CONFIG_LIB_SENDFILE_BUFSIZE=512
+# CONFIG_ARCH_ROMGETC is not set
+# CONFIG_ARCH_OPTIMIZED_FUNCTIONS is not set
+CONFIG_ARCH_HAVE_TLS=y
+# CONFIG_TLS is not set
+# CONFIG_LIBC_NETDB is not set
+
+#
+# Non-standard Library Support
+#
+# CONFIG_LIB_CRC64_FAST is not set
+# CONFIG_LIB_KBDCODEC is not set
+# CONFIG_LIB_SLCDCODEC is not set
+# CONFIG_LIB_HEX2BIN is not set
+
+#
+# Basic CXX Support
+#
+# CONFIG_C99_BOOL8 is not set
+# CONFIG_HAVE_CXX is not set
+
+#
+# Application Configuration
+#
+
+#
+# Built-In Applications
+#
+CONFIG_BUILTIN_PROXY_STACKSIZE=1024
+
+#
+# CAN Utilities
+#
+
+#
+# Examples
+#
+# CONFIG_EXAMPLES_ARCHBUTTONS is not set
+CONFIG_EXAMPLES_BUTTONS=y
+CONFIG_EXAMPLES_BUTTONS_PRIORITY=100
+CONFIG_EXAMPLES_BUTTONS_STACKSIZE=2048
+CONFIG_EXAMPLES_BUTTONS_DEVPATH="/dev/buttons"
+# CONFIG_EXAMPLES_BUTTONS_NAMES is not set
+# CONFIG_EXAMPLES_CHAT is not set
+# CONFIG_EXAMPLES_CONFIGDATA is not set
+# CONFIG_EXAMPLES_DHCPD is not set
+# CONFIG_EXAMPLES_ELF is not set
+# CONFIG_EXAMPLES_FTPC is not set
+# CONFIG_EXAMPLES_FTPD is not set
+# CONFIG_EXAMPLES_HELLO is not set
+# CONFIG_EXAMPLES_HIDKBD is not set
+# CONFIG_EXAMPLES_IGMP is not set
+# CONFIG_EXAMPLES_JSON is not set
+# CONFIG_EXAMPLES_KEYPADTEST is not set
+# CONFIG_EXAMPLES_LEDS is not set
+# CONFIG_EXAMPLES_MEDIA is not set
+# CONFIG_EXAMPLES_MM is not set
+# CONFIG_EXAMPLES_MODBUS is not set
+# CONFIG_EXAMPLES_MOUNT is not set
+# CONFIG_EXAMPLES_NRF24L01TERM is not set
+CONFIG_EXAMPLES_NSH=y
+# CONFIG_EXAMPLES_NULL is not set
+# CONFIG_EXAMPLES_NX is not set
+# CONFIG_EXAMPLES_NXFFS is not set
+# CONFIG_EXAMPLES_NXHELLO is not set
+# CONFIG_EXAMPLES_NXIMAGE is not set
+# CONFIG_EXAMPLES_NXLINES is not set
+# CONFIG_EXAMPLES_NXTERM is not set
+# CONFIG_EXAMPLES_NXTEXT is not set
+# CONFIG_EXAMPLES_OSTEST is not set
+# CONFIG_EXAMPLES_PCA9635 is not set
+# CONFIG_EXAMPLES_POSIXSPAWN is not set
+# CONFIG_EXAMPLES_PPPD is not set
+# CONFIG_EXAMPLES_RFID_READUID is not set
+# CONFIG_EXAMPLES_RGBLED is not set
+# CONFIG_EXAMPLES_RGMP is not set
+# CONFIG_EXAMPLES_SENDMAIL is not set
+# CONFIG_EXAMPLES_SERIALBLASTER is not set
+# CONFIG_EXAMPLES_SERIALRX is not set
+# CONFIG_EXAMPLES_SERLOOP is not set
+# CONFIG_EXAMPLES_SLCD is not set
+# CONFIG_EXAMPLES_SMART is not set
+# CONFIG_EXAMPLES_SMART_TEST is not set
+# CONFIG_EXAMPLES_SMP is not set
+# CONFIG_EXAMPLES_TCPECHO is not set
+# CONFIG_EXAMPLES_TELNETD is not set
+# CONFIG_EXAMPLES_TIFF is not set
+# CONFIG_EXAMPLES_TOUCHSCREEN is not set
+# CONFIG_EXAMPLES_USBSERIAL is not set
+# CONFIG_EXAMPLES_USBTERM is not set
+# CONFIG_EXAMPLES_WATCHDOG is not set
+# CONFIG_EXAMPLES_WEBSERVER is not set
+
+#
+# File System Utilities
+#
+# CONFIG_FSUTILS_INIFILE is not set
+
+#
+# GPS Utilities
+#
+# CONFIG_GPSUTILS_MINMEA_LIB is not set
+
+#
+# Graphics Support
+#
+# CONFIG_TIFF is not set
+# CONFIG_GRAPHICS_TRAVELER is not set
+
+#
+# Interpreters
+#
+# CONFIG_INTERPRETERS_FICL is not set
+# CONFIG_INTERPRETERS_MICROPYTHON is not set
+# CONFIG_INTERPRETERS_MINIBASIC is not set
+# CONFIG_INTERPRETERS_PCODE is not set
+
+#
+# FreeModBus
+#
+# CONFIG_MODBUS is not set
+
+#
+# Network Utilities
+#
+# CONFIG_NETUTILS_CHAT is not set
+# CONFIG_NETUTILS_CODECS is not set
+# CONFIG_NETUTILS_ESP8266 is not set
+# CONFIG_NETUTILS_FTPC is not set
+# CONFIG_NETUTILS_JSON is not set
+# CONFIG_NETUTILS_SMTP is not set
+
+#
+# NSH Library
+#
+CONFIG_NSH_LIBRARY=y
+# CONFIG_NSH_MOTD is not set
+
+#
+# Command Line Configuration
+#
+CONFIG_NSH_READLINE=y
+# CONFIG_NSH_CLE is not set
+CONFIG_NSH_LINELEN=80
+CONFIG_NSH_DISABLE_SEMICOLON=y
+# CONFIG_NSH_CMDPARMS is not set
+CONFIG_NSH_MAXARGUMENTS=6
+# CONFIG_NSH_ARGCAT is not set
+CONFIG_NSH_NESTDEPTH=3
+CONFIG_NSH_DISABLEBG=y
+CONFIG_NSH_BUILTIN_APPS=y
+
+#
+# Disable Individual commands
+#
+CONFIG_NSH_DISABLE_ADDROUTE=y
+CONFIG_NSH_DISABLE_BASENAME=y
+# CONFIG_NSH_DISABLE_CAT is not set
+# CONFIG_NSH_DISABLE_CD is not set
+# CONFIG_NSH_DISABLE_CP is not set
+CONFIG_NSH_DISABLE_CMP=y
+CONFIG_NSH_DISABLE_DATE=y
+# CONFIG_NSH_DISABLE_DD is not set
+CONFIG_NSH_DISABLE_DF=y
+CONFIG_NSH_DISABLE_DELROUTE=y
+CONFIG_NSH_DISABLE_DIRNAME=y
+# CONFIG_NSH_DISABLE_ECHO is not set
+# CONFIG_NSH_DISABLE_EXEC is not set
+# CONFIG_NSH_DISABLE_EXIT is not set
+# CONFIG_NSH_DISABLE_FREE is not set
+# CONFIG_NSH_DISABLE_GET is not set
+# CONFIG_NSH_DISABLE_HELP is not set
+# CONFIG_NSH_DISABLE_HEXDUMP is not set
+CONFIG_NSH_DISABLE_IFCONFIG=y
+CONFIG_NSH_DISABLE_IFUPDOWN=y
+# CONFIG_NSH_DISABLE_KILL is not set
+CONFIG_NSH_DISABLE_LOSETUP=y
+CONFIG_NSH_DISABLE_LOSMART=y
+# CONFIG_NSH_DISABLE_LS is not set
+# CONFIG_NSH_DISABLE_MB is not set
+# CONFIG_NSH_DISABLE_MKDIR is not set
+# CONFIG_NSH_DISABLE_MKRD is not set
+# CONFIG_NSH_DISABLE_MH is not set
+# CONFIG_NSH_DISABLE_MOUNT is not set
+# CONFIG_NSH_DISABLE_MV is not set
+# CONFIG_NSH_DISABLE_MW is not set
+CONFIG_NSH_DISABLE_PRINTF=y
+# CONFIG_NSH_DISABLE_PS is not set
+# CONFIG_NSH_DISABLE_PUT is not set
+# CONFIG_NSH_DISABLE_PWD is not set
+# CONFIG_NSH_DISABLE_RM is not set
+# CONFIG_NSH_DISABLE_RMDIR is not set
+# CONFIG_NSH_DISABLE_SET is not set
+# CONFIG_NSH_DISABLE_SH is not set
+# CONFIG_NSH_DISABLE_SLEEP is not set
+CONFIG_NSH_DISABLE_TIME=y
+# CONFIG_NSH_DISABLE_TEST is not set
+# CONFIG_NSH_DISABLE_UMOUNT is not set
+CONFIG_NSH_DISABLE_UNAME=y
+# CONFIG_NSH_DISABLE_UNSET is not set
+# CONFIG_NSH_DISABLE_USLEEP is not set
+# CONFIG_NSH_DISABLE_WGET is not set
+# CONFIG_NSH_DISABLE_XD is not set
+CONFIG_NSH_MMCSDMINOR=0
+
+#
+# Configure Command Options
+#
+CONFIG_NSH_CODECS_BUFSIZE=128
+# CONFIG_NSH_CMDOPT_HEXDUMP is not set
+CONFIG_NSH_FILEIOSIZE=1024
+
+#
+# Scripting Support
+#
+# CONFIG_NSH_DISABLESCRIPT is not set
+CONFIG_NSH_DISABLE_ITEF=y
+CONFIG_NSH_DISABLE_LOOPS=y
+
+#
+# Console Configuration
+#
+CONFIG_NSH_CONSOLE=y
+# CONFIG_NSH_ALTCONDEV is not set
+CONFIG_NSH_ARCHINIT=y
+# CONFIG_NSH_LOGIN is not set
+# CONFIG_NSH_CONSOLE_LOGIN is not set
+
+#
+# NxWidgets/NxWM
+#
+
+#
+# Platform-specific Support
+#
+# CONFIG_PLATFORM_CONFIGDATA is not set
+
+#
+# System Libraries and NSH Add-Ons
+#
+# CONFIG_SYSTEM_CLE is not set
+# CONFIG_SYSTEM_CUTERM is not set
+# CONFIG_SYSTEM_FREE is not set
+# CONFIG_SYSTEM_HEX2BIN is not set
+# CONFIG_SYSTEM_HEXED is not set
+# CONFIG_SYSTEM_INSTALL is not set
+# CONFIG_SYSTEM_RAMTEST is not set
+CONFIG_READLINE_HAVE_EXTMATCH=y
+CONFIG_SYSTEM_READLINE=y
+CONFIG_READLINE_ECHO=y
+# CONFIG_READLINE_TABCOMPLETION is not set
+# CONFIG_READLINE_CMD_HISTORY is not set
+# CONFIG_SYSTEM_SUDOKU is not set
+# CONFIG_SYSTEM_SYSTEM is not set
+# CONFIG_SYSTEM_TEE is not set
+# CONFIG_SYSTEM_UBLOXMODEM is not set
+# CONFIG_SYSTEM_VI is not set
+# CONFIG_SYSTEM_ZMODEM is not set
diff --git a/configs/stm32f103-minimum/buttons/setenv.sh b/configs/stm32f103-minimum/buttons/setenv.sh
new file mode 100644
index 0000000000..73dfab5a4d
--- /dev/null
+++ b/configs/stm32f103-minimum/buttons/setenv.sh
@@ -0,0 +1,100 @@
+#!/bin/bash
+# configs//stm32f103-minimum/nsh/setenv.sh
+#
+# Copyright (C) 2016 Gregory Nutt. All rights reserved.
+# Author: Gregory Nutt
+#
+# 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.
+#
+
+# 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.
+#
+
+if [ "$_" = "$0" ] ; then
+ echo "You must source this script, not run it!" 1>&2
+ exit 1
+fi
+
+WD=`pwd`
+if [ ! -x "setenv.sh" ]; then
+ echo "This script must be executed from the top-level NuttX build directory"
+ exit 1
+fi
+
+if [ -z "${PATH_ORIG}" ]; then
+ export PATH_ORIG="${PATH}"
+fi
+
+# This is the Cygwin path to the location where I installed the CodeSourcery
+# toolchain under windows. You will also have to edit this if you install
+# the CodeSourcery toolchain in any other location
+#export TOOLCHAIN_BIN="/cygdrive/c/Program Files (x86)/CodeSourcery/Sourcery G++ Lite/bin"
+#export TOOLCHAIN_BIN="/cygdrive/c/Program Files (x86)/CodeSourcery/Sourcery_CodeBench_Lite_for_ARM_EABI/bin"
+# export TOOLCHAIN_BIN="/cygdrive/c/Users/MyName/MentorGraphics/Sourcery_CodeBench_Lite_for_ARM_EABI/bin"
+
+# This is the location where I installed the ARM "GNU Tools for ARM Embedded Processors"
+# You can this free toolchain here https://launchpad.net/gcc-arm-embedded
+export TOOLCHAIN_BIN="/cygdrive/c/Program Files (x86)/GNU Tools ARM Embedded/4.9 2015q2/bin"
+
+# This is the path to the location where I installed the devkitARM toolchain
+# You can get this free toolchain from http://devkitpro.org/ or http://sourceforge.net/projects/devkitpro/
+#export TOOLCHAIN_BIN="/cygdrive/c/Program Files (x86)/devkitARM/bin"
+
+# This is the Cygwin path to the location where I build the buildroot
+# toolchain.
+# export TOOLCHAIN_BIN="${WD}/../buildroot/build_arm_nofpu/staging_dir/bin"
+
+# Add the path to the toolchain to the PATH varialble
+export PATH="${TOOLCHAIN_BIN}:/sbin:/usr/sbin:${PATH_ORIG}"
+
+echo "PATH : ${PATH}"
diff --git a/configs/stm32f103-minimum/include/board.h b/configs/stm32f103-minimum/include/board.h
index 85bdf23464..c2a17aff37 100644
--- a/configs/stm32f103-minimum/include/board.h
+++ b/configs/stm32f103-minimum/include/board.h
@@ -152,6 +152,15 @@
# define SDIO_SDXFR_CLKDIV (3 << SDIO_CLKCR_CLKDIV_SHIFT)
#endif
+/* BUTTON definitions ***************************************************************/
+
+#define NUM_BUTTONS 2
+
+#define BUTTON_USER1 0
+#define BUTTON_USER2 1
+#define BUTTON_USER1_BIT (1 << BUTTON_USER1)
+#define BUTTON_USER2_BIT (1 << BUTTON_USER2)
+
/* LED definitions ******************************************************************/
/* Define how many LEDs this board has (needed by userleds) */
diff --git a/configs/stm32f103-minimum/src/Makefile b/configs/stm32f103-minimum/src/Makefile
index 746f20edbc..5596fb6e43 100644
--- a/configs/stm32f103-minimum/src/Makefile
+++ b/configs/stm32f103-minimum/src/Makefile
@@ -43,6 +43,10 @@ ifeq ($(CONFIG_LIB_BOARDCTL),y)
CSRCS += stm32_appinit.c
endif
+ifeq ($(CONFIG_ARCH_BUTTONS),y)
+CSRCS += stm32_buttons.c
+endif
+
ifeq ($(CONFIG_ARCH_LEDS),y)
CSRCS += stm32_autoleds.c
else
diff --git a/configs/stm32f103-minimum/src/stm32_bringup.c b/configs/stm32f103-minimum/src/stm32_bringup.c
index 2843f67e5b..fac7292c58 100644
--- a/configs/stm32f103-minimum/src/stm32_bringup.c
+++ b/configs/stm32f103-minimum/src/stm32_bringup.c
@@ -61,6 +61,10 @@
# include "stm32_usbhost.h"
#endif
+#ifdef CONFIG_BUTTONS
+# include
+#endif
+
#ifdef CONFIG_USERLED
# include
#endif
@@ -128,6 +132,16 @@ int stm32_bringup(void)
}
#endif
+#ifdef CONFIG_BUTTONS
+ /* Register the BUTTON driver */
+
+ ret = btn_lower_initialize("/dev/buttons");
+ if (ret < 0)
+ {
+ syslog(LOG_ERR, "ERROR: btn_lower_initialize() failed: %d\n", ret);
+ }
+#endif
+
#ifdef CONFIG_USERLED
/* Register the LED driver */
diff --git a/configs/stm32f103-minimum/src/stm32_buttons.c b/configs/stm32f103-minimum/src/stm32_buttons.c
new file mode 100644
index 0000000000..d611bf44fb
--- /dev/null
+++ b/configs/stm32f103-minimum/src/stm32_buttons.c
@@ -0,0 +1,171 @@
+/****************************************************************************
+ * configs/stm32f103-minimum/src/stm32_buttons.c
+ *
+ * Copyright (C) 2016 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * 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
+
+#include
+
+#include
+#include
+#include
+
+#include "stm32f103_minimum.h"
+
+#if defined(CONFIG_ARCH_BUTTONS)
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#if defined(CONFIG_BUTTONS) && !defined(CONFIG_ARCH_IRQBUTTONS)
+# error "The NuttX Buttons Driver depends on IRQ support to work!\n"
+#endif
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/* Pin configuration for each STM32F3Discovery button. This array is indexed
+ * by the BUTTON_* definitions in board.h
+ */
+
+static const uint32_t g_buttons[NUM_BUTTONS] =
+{
+ GPIO_BTN_USER1, GPIO_BTN_USER2
+};
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: board_button_initialize
+ *
+ * Description:
+ * board_button_initialize() must be called to initialize button resources. After
+ * that, board_buttons() may be called to collect the current state of all
+ * buttons or board_button_irq() may be called to register button interrupt
+ * handlers.
+ *
+ ****************************************************************************/
+
+void board_button_initialize(void)
+{
+ int i;
+
+ /* Configure the GPIO pins as inputs. NOTE that EXTI interrupts are
+ * configured for all pins.
+ */
+
+ for (i = 0; i < NUM_BUTTONS; i++)
+ {
+ stm32_configgpio(g_buttons[i]);
+ }
+}
+
+/****************************************************************************
+ * Name: board_buttons
+ ****************************************************************************/
+
+uint8_t board_buttons(void)
+{
+ uint8_t ret = 0;
+ int i;
+
+ /* Check that state of each key */
+
+ for (i = 0; i < NUM_BUTTONS; i++)
+ {
+ /* A LOW value means that the key is pressed.
+ */
+
+ bool released = stm32_gpioread(g_buttons[i]);
+
+ /* Accumulate the set of depressed (not released) keys */
+
+ if (!released)
+ {
+ ret |= (1 << i);
+ }
+ }
+
+ return ret;
+}
+
+/****************************************************************************
+ * Button support.
+ *
+ * Description:
+ * board_button_initialize() must be called to initialize button resources.
+ * After that, board_buttons() may be called to collect the current state
+ * of all buttons or board_button_irq() may be called to register button
+ * interrupt handlers.
+ *
+ * After board_button_initialize() has been called, board_buttons() may be
+ * called to collect the state of all buttons. board_buttons() returns
+ * an 8-bit bit set with each bit associated with a button. See the
+ * BUTTON_*_BIT definitions in board.h for the meaning of each bit.
+ *
+ * board_button_irq() may be called to register an interrupt handler that
+ * will be called when a button is depressed or released. The ID value is
+ * a button enumeration value that uniquely identifies a button resource.
+ * See the BUTTON_* definitions in board.h for the meaning of enumeration
+ * value. The previous interrupt handler address is returned (so that it
+ * may be restored, if so desired).
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_ARCH_IRQBUTTONS
+xcpt_t board_button_irq(int id, xcpt_t irqhandler)
+{
+ xcpt_t oldhandler = NULL;
+
+ /* The following should be atomic */
+
+ if (id >= MIN_IRQBUTTON && id <= MAX_IRQBUTTON)
+ {
+ oldhandler = stm32_gpiosetevent(g_buttons[id], true, true, true,
+ irqhandler);
+ }
+
+ return oldhandler;
+}
+#endif
+
+#endif /* CONFIG_ARCH_BUTTONS */
diff --git a/configs/stm32f103-minimum/src/stm32f103_minimum.h b/configs/stm32f103-minimum/src/stm32f103_minimum.h
index a52b49b3a0..ec66bb5898 100644
--- a/configs/stm32f103-minimum/src/stm32f103_minimum.h
+++ b/configs/stm32f103-minimum/src/stm32f103_minimum.h
@@ -65,6 +65,18 @@
#define GPIO_LED1 (GPIO_OUTPUT|GPIO_CNF_OUTPP|GPIO_MODE_50MHz|\
GPIO_OUTPUT_CLEAR|GPIO_PORTC|GPIO_PIN13)
+/* BUTTONs */
+
+#define GPIO_BTN_USER1 (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_INPUT|\
+ GPIO_EXTI|GPIO_PORTA|GPIO_PIN0)
+
+#define GPIO_BTN_USER2 (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_INPUT|\
+ GPIO_EXTI|GPIO_PORTA|GPIO_PIN1)
+
+#define MIN_IRQBUTTON BUTTON_USER1
+#define MAX_IRQBUTTON BUTTON_USER2
+#define NUM_IRQBUTTONS (BUTTON_USER1 - BUTTON_USER2 + 1)
+
/* SPI chip selects */
--
GitLab
From 4195692bb4f22622bb9781958d2341b4f6fb716c Mon Sep 17 00:00:00 2001
From: Alan Carvalho de Assis
Date: Tue, 11 Oct 2016 14:29:27 -0600
Subject: [PATCH 053/734] Change "Board LED support" to "Board LED Status
support"
---
configs/Kconfig | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/configs/Kconfig b/configs/Kconfig
index ca3b408285..2b629c1a4f 100644
--- a/configs/Kconfig
+++ b/configs/Kconfig
@@ -1501,7 +1501,7 @@ config ARCH_HAVE_LEDS
bool
config ARCH_LEDS
- bool "Board LED support"
+ bool "Board LED Status support"
default y
depends on ARCH_HAVE_LEDS
---help---
--
GitLab
From 55523f5771f329d911e4f44a870d7f8d31c24fa8 Mon Sep 17 00:00:00 2001
From: Gregory Nutt
Date: Wed, 12 Oct 2016 13:11:05 -0600
Subject: [PATCH 054/734] arch/xtensa: Add a few basic XTENSA/LX6 files. Not
yet enough to do anything with
---
arch/xtensa/Kconfig | 31 ++
arch/xtensa/include/arch.h | 82 +++++
arch/xtensa/include/irq.h | 91 ++++++
arch/xtensa/include/limits.h | 87 ++++++
arch/xtensa/include/lx6/chip.h | 84 ++++++
arch/xtensa/include/lx6/irq.h | 85 ++++++
arch/xtensa/include/syscall.h | 82 +++++
arch/xtensa/include/types.h | 94 ++++++
arch/xtensa/src/common/up_arch.h | 90 ++++++
arch/xtensa/src/common/xtensa.h | 285 ++++++++++++++++++
arch/xtensa/src/common/xtensa_allocateheap.c | 88 ++++++
arch/xtensa/src/common/xtensa_createstack.c | 214 +++++++++++++
arch/xtensa/src/common/xtensa_etherstub.c | 86 ++++++
arch/xtensa/src/common/xtensa_exit.c | 188 ++++++++++++
arch/xtensa/src/common/xtensa_idle.c | 95 ++++++
arch/xtensa/src/common/xtensa_initialize.c | 261 ++++++++++++++++
.../src/common/xtensa_interruptcontext.c | 70 +++++
arch/xtensa/src/common/xtensa_lowputs.c | 74 +++++
arch/xtensa/src/common/xtensa_mdelay.c | 90 ++++++
arch/xtensa/src/common/xtensa_modifyreg16.c | 85 ++++++
arch/xtensa/src/common/xtensa_modifyreg32.c | 85 ++++++
arch/xtensa/src/common/xtensa_modifyreg8.c | 85 ++++++
arch/xtensa/src/common/xtensa_puts.c | 75 +++++
arch/xtensa/src/common/xtensa_releasestack.c | 122 ++++++++
arch/xtensa/src/common/xtensa_stackframe.c | 143 +++++++++
arch/xtensa/src/common/xtensa_udelay.c | 129 ++++++++
arch/xtensa/src/common/xtensa_usestack.c | 152 ++++++++++
arch/xtensa/src/lx6/Kconfig | 9 +
arch/xtensa/src/lx6/Make.defs | 67 ++++
29 files changed, 3129 insertions(+)
create mode 100644 arch/xtensa/Kconfig
create mode 100644 arch/xtensa/include/arch.h
create mode 100644 arch/xtensa/include/irq.h
create mode 100644 arch/xtensa/include/limits.h
create mode 100644 arch/xtensa/include/lx6/chip.h
create mode 100644 arch/xtensa/include/lx6/irq.h
create mode 100644 arch/xtensa/include/syscall.h
create mode 100644 arch/xtensa/include/types.h
create mode 100644 arch/xtensa/src/common/up_arch.h
create mode 100644 arch/xtensa/src/common/xtensa.h
create mode 100644 arch/xtensa/src/common/xtensa_allocateheap.c
create mode 100644 arch/xtensa/src/common/xtensa_createstack.c
create mode 100644 arch/xtensa/src/common/xtensa_etherstub.c
create mode 100644 arch/xtensa/src/common/xtensa_exit.c
create mode 100644 arch/xtensa/src/common/xtensa_idle.c
create mode 100644 arch/xtensa/src/common/xtensa_initialize.c
create mode 100644 arch/xtensa/src/common/xtensa_interruptcontext.c
create mode 100644 arch/xtensa/src/common/xtensa_lowputs.c
create mode 100644 arch/xtensa/src/common/xtensa_mdelay.c
create mode 100644 arch/xtensa/src/common/xtensa_modifyreg16.c
create mode 100644 arch/xtensa/src/common/xtensa_modifyreg32.c
create mode 100644 arch/xtensa/src/common/xtensa_modifyreg8.c
create mode 100644 arch/xtensa/src/common/xtensa_puts.c
create mode 100644 arch/xtensa/src/common/xtensa_releasestack.c
create mode 100644 arch/xtensa/src/common/xtensa_stackframe.c
create mode 100644 arch/xtensa/src/common/xtensa_udelay.c
create mode 100644 arch/xtensa/src/common/xtensa_usestack.c
create mode 100644 arch/xtensa/src/lx6/Kconfig
create mode 100644 arch/xtensa/src/lx6/Make.defs
diff --git a/arch/xtensa/Kconfig b/arch/xtensa/Kconfig
new file mode 100644
index 0000000000..d740939c1e
--- /dev/null
+++ b/arch/xtensa/Kconfig
@@ -0,0 +1,31 @@
+#
+# For a description of the syntax of this configuration file,
+# see the file kconfig-language.txt in the NuttX tools repository.
+#
+
+if ARCH_XTENSA
+
+choice
+ prompt "XTENSA architecture selection"
+ default ARCH_CHIP_LX6
+
+config ARCH_CHIP_LX6
+ bool "LX6 DPU"
+ select ARCH_LX6
+ ---help---
+ Cadence® Tensilica® Xtensa® LX6 data plane processing unit (DPU).
+ The LX6 is a configurable and extensible processor core.
+
+endchoice # XTENSA chip selection
+
+config ARCH_LX6
+ bool
+ default n
+
+config ARCH_CHIP
+ string
+ default "lx6" if ARCH_LX6
+
+source arch/xtensa/src/lx6/Kconfig
+
+endif # ARCH_XTENSA
diff --git a/arch/xtensa/include/arch.h b/arch/xtensa/include/arch.h
new file mode 100644
index 0000000000..760e52ff70
--- /dev/null
+++ b/arch/xtensa/include/arch.h
@@ -0,0 +1,82 @@
+/****************************************************************************
+ * arch/xtensa/include/arch.h
+ *
+ * Copyright (C) 2016 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+/* This file should never be included directed but, rather, only indirectly
+ * through nuttx/arch.h
+ */
+
+#ifndef __ARCH_XTENSA_INCLUDE_ARCH_H
+#define __ARCH_XTENSA_INCLUDE_ARCH_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Inline functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+#ifdef __cplusplus
+#define EXTERN extern "C"
+extern "C"
+{
+#else
+#define EXTERN extern
+#endif
+
+#undef EXTERN
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __ARCH_XTENSA_INCLUDE_ARCH_H */
diff --git a/arch/xtensa/include/irq.h b/arch/xtensa/include/irq.h
new file mode 100644
index 0000000000..d2af5ba4e4
--- /dev/null
+++ b/arch/xtensa/include/irq.h
@@ -0,0 +1,91 @@
+/****************************************************************************
+ * arch/xtensa/include/irq.h
+ *
+ * Copyright (C) 2016 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+/* This file should never be included directed but, rather, only indirectly
+ * through nuttx/irq.h
+ */
+
+#ifndef __ARCH_XTENSA_INCLUDE_IRQ_H
+#define __ARCH_XTENSA_INCLUDE_IRQ_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+/* Include NuttX-specific IRQ definitions */
+
+#include
+
+/* Include chip-specific IRQ definitions (including IRQ numbers) */
+
+#include
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+#ifndef __ASSEMBLY__
+
+/****************************************************************************
+ * Inline functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+#ifdef __cplusplus
+#define EXTERN extern "C"
+extern "C"
+{
+#else
+#define EXTERN extern
+#endif
+
+#undef EXTERN
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __ASSEMBLY__ */
+#endif /* __ARCH_XTENSA_INCLUDE_IRQ_H */
diff --git a/arch/xtensa/include/limits.h b/arch/xtensa/include/limits.h
new file mode 100644
index 0000000000..f3eb3b4795
--- /dev/null
+++ b/arch/xtensa/include/limits.h
@@ -0,0 +1,87 @@
+/****************************************************************************
+ * arch/xtensa/include/limits.h
+ *
+ * Copyright (C) 2011-2012 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+#ifndef __ARCH_XTENSA_INCLUDE_LIMITS_H
+#define __ARCH_XTENSA_INCLUDE_LIMITS_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define CHAR_BIT 8
+#define SCHAR_MIN (-SCHAR_MAX - 1)
+#define SCHAR_MAX 127
+#define UCHAR_MAX 255
+
+/* These could be different on machines where char is unsigned */
+
+#ifdef __CHAR_UNSIGNED__
+#define CHAR_MIN 0
+#define CHAR_MAX UCHAR_MAX
+#else
+#define CHAR_MIN SCHAR_MIN
+#define CHAR_MAX SCHAR_MAX
+#endif
+
+#define SHRT_MIN (-SHRT_MAX - 1)
+#define SHRT_MAX 32767
+#define USHRT_MAX 65535U
+
+#define INT_MIN (-INT_MAX - 1)
+#define INT_MAX 2147483647
+#define UINT_MAX 4294967295U
+
+/* These change on 32-bit and 64-bit platforms */
+
+#define LONG_MIN (-LONG_MAX - 1)
+#define LONG_MAX 2147483647L
+#define ULONG_MAX 4294967295UL
+
+#define LLONG_MIN (-LLONG_MAX - 1)
+#define LLONG_MAX 9223372036854775807LL
+#define ULLONG_MAX 18446744073709551615ULL
+
+/* A pointer is 4 bytes */
+
+#define PTR_MIN (-PTR_MAX - 1)
+#define PTR_MAX 2147483647
+#define UPTR_MAX 4294967295U
+
+#endif /* __ARCH_XTENSA_INCLUDE_LIMITS_H */
+
diff --git a/arch/xtensa/include/lx6/chip.h b/arch/xtensa/include/lx6/chip.h
new file mode 100644
index 0000000000..060d99e945
--- /dev/null
+++ b/arch/xtensa/include/lx6/chip.h
@@ -0,0 +1,84 @@
+/****************************************************************************
+ * arch/xtensa/include/lx6/chip.h
+ *
+ * Copyright (C) 2016 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+#ifndef __ARCH_XTENSA_INCLUDE_LX6_CHIP_H
+#define __ARCH_XTENSA_INCLUDE_LX6_CHIP_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+/* Configuration ************************************************************/
+
+#if defined(CONFIG_ARCH_CHIP_LX6)
+/* To be provided */
+#else
+# error "Unrecognized LX6 device
+#endif
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+#ifndef __ASSEMBLY__
+
+/****************************************************************************
+ * Inline Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+#ifdef __cplusplus
+#define EXTERN extern "C"
+extern "C"
+{
+#else
+#define EXTERN extern
+#endif
+
+#undef EXTERN
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __ASSEMBLY__ */
+#endif /* __ARCH_XTENSA_INCLUDE_LX6_CHIP_H */
diff --git a/arch/xtensa/include/lx6/irq.h b/arch/xtensa/include/lx6/irq.h
new file mode 100644
index 0000000000..ec2b218f58
--- /dev/null
+++ b/arch/xtensa/include/lx6/irq.h
@@ -0,0 +1,85 @@
+/****************************************************************************
+ * arch/xtensa/include/lx6/irq.h
+ *
+ * Copyright (C) 2016 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+/* This file should never be included directed but, rather, only indirectly
+ * through nuttx/irq.h
+ */
+
+#ifndef __ARCH_XTENSA_INCLUDE_LX6_IRQ_H
+#define __ARCH_XTENSA_INCLUDE_LX6_IRQ_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+#ifndef __ASSEMBLY__
+
+/****************************************************************************
+ * Inline functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+#ifdef __cplusplus
+#define EXTERN extern "C"
+extern "C"
+{
+#else
+#define EXTERN extern
+#endif
+
+#undef EXTERN
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __ASSEMBLY__ */
+#endif /* __ARCH_XTENSA_INCLUDE_LX6_IRQ_H */
diff --git a/arch/xtensa/include/syscall.h b/arch/xtensa/include/syscall.h
new file mode 100644
index 0000000000..fe2d71e6de
--- /dev/null
+++ b/arch/xtensa/include/syscall.h
@@ -0,0 +1,82 @@
+/****************************************************************************
+ * arch/xtensa/include/syscall.h
+ *
+ * Copyright (C) 2016 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+/* This file should never be included directed but, rather, only indirectly
+ * through include/syscall.h or include/sys/sycall.h
+ */
+
+#ifndef __ARCH_XTENSA_INCLUDE_SYSCALL_H
+#define __ARCH_XTENSA_INCLUDE_SYSCALL_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+/****************************************************************************
+ * Inline functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+#ifndef __ASSEMBLY__
+#ifdef __cplusplus
+#define EXTERN extern "C"
+extern "C"
+{
+#else
+#define EXTERN extern
+#endif
+
+#undef EXTERN
+#ifdef __cplusplus
+}
+#endif
+#endif
+
+#endif /* __ARCH_XTENSA_INCLUDE_SYSCALL_H */
diff --git a/arch/xtensa/include/types.h b/arch/xtensa/include/types.h
new file mode 100644
index 0000000000..aa987ff8bb
--- /dev/null
+++ b/arch/xtensa/include/types.h
@@ -0,0 +1,94 @@
+/****************************************************************************
+ * arch/xtensa/include/types.h
+ *
+ * Copyright (C) 2016 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+/* This file should never be included directed but, rather, only indirectly
+ * through stdint.h
+ */
+
+#ifndef __ARCH_XTENSA_INCLUDE_TYPES_H
+#define __ARCH_XTENSA_INCLUDE_TYPES_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Type Declarations
+ ****************************************************************************/
+
+#ifndef __ASSEMBLY__
+
+/* These are the sizes of the standard integer types. NOTE that these type
+ * names have a leading underscore character. This file will be included
+ * (indirectly) by include/stdint.h and typedef'ed to the final name without
+ * the underscore character. This roundabout way of doings things allows
+ * the stdint.h to be removed from the include/ directory in the event that
+ * the user prefers to use the definitions provided by their toolchain header
+ * files
+ */
+
+typedef signed char _int8_t;
+typedef unsigned char _uint8_t;
+
+typedef signed short _int16_t;
+typedef unsigned short _uint16_t;
+
+typedef signed int _int32_t;
+typedef unsigned int _uint32_t;
+
+typedef signed long long _int64_t;
+typedef unsigned long long _uint64_t;
+#define __INT64_DEFINED
+
+/* A pointer is 4 bytes */
+
+typedef signed int _intptr_t;
+typedef unsigned int _uintptr_t;
+
+/* This is the size of the interrupt state save returned by up_irq_save(). */
+
+typedef unsigned int irqstate_t;
+
+#endif /* __ASSEMBLY__ */
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+#endif /* __ARCH_XTENSA_INCLUDE_TYPES_H */
diff --git a/arch/xtensa/src/common/up_arch.h b/arch/xtensa/src/common/up_arch.h
new file mode 100644
index 0000000000..4fd625bf7a
--- /dev/null
+++ b/arch/xtensa/src/common/up_arch.h
@@ -0,0 +1,90 @@
+/****************************************************************************
+ * arch/xtensa/src/common/xtensa_arch.h
+ *
+ * Copyright (C) 2010, 2015 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+#ifndef ___ARCH_XTENSA_SRC_COMMON_XTENSA_ARCH_H
+#define ___ARCH_XTENSA_SRC_COMMON_XTENSA_ARCH_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include
+#ifndef __ASSEMBLY__
+# include
+#endif
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Inline Functions
+ ****************************************************************************/
+
+#ifndef __ASSEMBLY__
+
+# define getreg8(a) (*(volatile uint8_t *)(a))
+# define putreg8(v,a) (*(volatile uint8_t *)(a) = (v))
+# define getreg16(a) (*(volatile uint16_t *)(a))
+# define putreg16(v,a) (*(volatile uint16_t *)(a) = (v))
+# define getreg32(a) (*(volatile uint32_t *)(a))
+# define putreg32(v,a) (*(volatile uint32_t *)(a) = (v))
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+#undef EXTERN
+#if defined(__cplusplus)
+#define EXTERN extern "C"
+extern "C"
+{
+#else
+#define EXTERN extern
+#endif
+
+/* Atomic modification of registers */
+
+void modifyreg8(unsigned int addr, uint8_t clearbits, uint8_t setbits);
+void modifyreg16(unsigned int addr, uint16_t clearbits, uint16_t setbits);
+void modifyreg32(unsigned int addr, uint32_t clearbits, uint32_t setbits);
+
+#undef EXTERN
+#if defined(__cplusplus)
+}
+#endif
+
+#endif /* __ASSEMBLY__ */
+#endif /* ___ARCH_XTENSA_SRC_COMMON_XTENSA_ARCH_H */
diff --git a/arch/xtensa/src/common/xtensa.h b/arch/xtensa/src/common/xtensa.h
new file mode 100644
index 0000000000..cef80d3ae9
--- /dev/null
+++ b/arch/xtensa/src/common/xtensa.h
@@ -0,0 +1,285 @@
+/****************************************************************************
+ * arch/xtensa/common/xtensa_internal.h
+ *
+ * Copyright (C) 2011, 2012, 2015 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+#ifndef __ARCH_XTENSA_SRC_COMMON_XTENSA_INTERNAL_H
+#define __ARCH_XTENSA_SRC_COMMON_XTENSA_INTERNAL_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#ifndef __ASSEMBLY__
+# include
+# include
+#endif
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Bring-up debug configurations. These are here (vs defconfig)
+ * because these should only be controlled during low level
+ * board bring-up and not part of normal platform configuration.
+ */
+
+#undef CONFIG_SUPPRESS_INTERRUPTS /* DEFINED: Do not enable interrupts */
+#undef CONFIG_SUPPRESS_TIMER_INTS /* DEFINED: No timer */
+#undef CONFIG_SUPPRESS_SERIAL_INTS /* DEFINED: Console will poll */
+#undef CONFIG_SUPPRESS_UART_CONFIG /* DEFINED: Do not reconfig UART */
+#undef CONFIG_DUMP_ON_EXIT /* DEFINED: Dump task state on exit */
+
+#ifndef CONFIG_DEBUG_SCHED_INFO
+# undef CONFIG_DUMP_ON_EXIT /* Needs CONFIG_DEBUG_SCHED_INFO */
+#endif
+
+/* Determine which (if any) console driver to use. If a console is enabled
+ * and no other console device is specified, then a serial console is
+ * assumed.
+ */
+
+#if !defined(CONFIG_DEV_CONSOLE) || CONFIG_NFILE_DESCRIPTORS <= 0
+# undef USE_SERIALDRIVER
+# undef USE_EARLYSERIALINIT
+# undef CONFIG_DEV_LOWCONSOLE
+# undef CONFIG_RAMLOG_CONSOLE
+#else
+# if defined(CONFIG_RAMLOG_CONSOLE)
+# undef USE_SERIALDRIVER
+# undef USE_EARLYSERIALINIT
+# undef CONFIG_DEV_LOWCONSOLE
+# elif defined(CONFIG_DEV_LOWCONSOLE)
+# undef USE_SERIALDRIVER
+# undef USE_EARLYSERIALINIT
+# else
+# define USE_SERIALDRIVER 1
+# define USE_EARLYSERIALINIT 1
+# endif
+#endif
+
+/* If some other device is used as the console, then the serial driver may
+ * still be needed. Let's assume that if the upper half serial driver is
+ * built, then the lower half will also be needed. There is no need for
+ * the early serial initialization in this case.
+ */
+
+#if !defined(USE_SERIALDRIVER) && defined(CONFIG_STANDARD_SERIAL)
+# define USE_SERIALDRIVER 1
+#endif
+
+/* Check if an interrupt stack size is configured */
+
+#ifndef CONFIG_ARCH_INTERRUPTSTACK
+# define CONFIG_ARCH_INTERRUPTSTACK 0
+#endif
+
+/* In the XTENSA model, the state is copied from the stack to the TCB, but
+ * only a referenced is passed to get the state from the TCB.
+ */
+
+#define up_savestate(regs) up_copystate(regs, (uint32_t*)g_current_regs)
+#define up_restorestate(regs) (g_current_regs = regs)
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+#ifndef __ASSEMBLY__
+typedef void (*up_vector_t)(void);
+#endif
+
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+#ifndef __ASSEMBLY__
+/* This holds a references to the current interrupt level register storage
+ * structure. If is non-NULL only during interrupt processing.
+ */
+
+extern volatile uint32_t *g_current_regs;
+
+/* This is the beginning of heap as provided from up_head.S. This is the
+ * first address in DRAM after the loaded program+bss+idle stack. The end
+ * of the heap is CONFIG_RAM_END
+ */
+
+extern uint32_t g_idle_topstack;
+
+/* Address of the saved user stack pointer */
+
+#if CONFIG_ARCH_INTERRUPTSTACK > 3
+extern void g_intstackbase;
+#endif
+
+/* 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 recoved 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 _data_loaddr; /* Start of .data in FLASH */
+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 */
+#ifdef CONFIG_ARCH_RAMFUNCS
+extern uint32_t _sramfunc; /* Start of ramfuncs */
+extern uint32_t _eramfunc; /* End+1 of ramfuncs */
+extern uint32_t _ramfunc_loadaddr; /* Start of ramfuncs in FLASH */
+extern uint32_t _ramfunc_sizeof; /* Size of ramfuncs */
+extern uint32_t _bmxdkpba_address; /* BMX register setting */
+extern uint32_t _bmxdudba_address; /* BMX register setting */
+extern uint32_t _bmxdupba_address; /* BMX register setting */
+#endif /* CONFIG_ARCH_RAMFUNCS */
+#endif /* __ASSEMBLY__ */
+
+/****************************************************************************
+ * Inline Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+#ifndef __ASSEMBLY__
+/* Common Functions *********************************************************/
+/* Common functions define in arch/xtensa/src/common. These may be replaced
+ * with chip-specific functions of the same name if needed. See also
+ * functions prototyped in include/nuttx/arch.h.
+ */
+
+/* Context switching */
+
+void up_copystate(uint32_t *dest, uint32_t *src);
+
+/* Serial output */
+
+void up_puts(const char *str);
+void up_lowputs(const char *str);
+
+/* Defined in drivers/lowconsole.c */
+
+#ifdef CONFIG_DEV_LOWCONSOLE
+void lowconsole_init(void);
+#else
+# define lowconsole_init()
+#endif
+
+/* Debug */
+
+#ifdef CONFIG_ARCH_STACKDUMP
+void up_dumpstate(void);
+#else
+# define up_dumpstate()
+#endif
+
+/* Common XTENSA32 functions defined in arch/xtensa/src/XTENSA32 */
+/* IRQs */
+
+uint32_t *up_doirq(int irq, uint32_t *regs);
+
+/* Software interrupt 0 handler */
+
+int up_swint0(int irq, FAR void *context);
+
+/* Signals */
+
+void up_sigdeliver(void);
+
+/* Chip-specific functions **************************************************/
+/* Chip specific functions defined in arch/xtensa/src/ */
+/* IRQs */
+
+void up_irqinitialize(void);
+bool up_pending_irq(int irq);
+void up_clrpend_irq(int irq);
+
+/* DMA */
+
+#ifdef CONFIG_ARCH_DMA
+void weak_function up_dmainitialize(void);
+#endif
+
+/* Memory management */
+
+#if CONFIG_MM_REGIONS > 1
+void up_addregion(void);
+#else
+# define up_addregion()
+#endif
+
+/* Serial output */
+
+void up_lowputc(char ch);
+#if CONFIG_NFILE_DESCRIPTORS > 0
+void up_earlyserialinit(void);
+void up_serialinit(void);
+#else
+# define up_earlyserialinit()
+# define up_serialinit()
+#endif
+
+/* System timer */
+
+void up_timer_initialize(void);
+
+/* Network */
+
+#ifdef CONFIG_NET
+void up_netinitialize(void);
+#else
+# define up_netinitialize()
+#endif
+
+/* USB */
+
+#ifdef CONFIG_USBDEV
+void up_usbinitialize(void);
+void up_usbuninitialize(void);
+#else
+# define up_usbinitialize()
+# define up_usbuninitialize()
+#endif
+
+#endif /* __ASSEMBLY__ */
+#endif /* __ARCH_XTENSA_SRC_COMMON_XTENSA_INTERNAL_H */
diff --git a/arch/xtensa/src/common/xtensa_allocateheap.c b/arch/xtensa/src/common/xtensa_allocateheap.c
new file mode 100644
index 0000000000..fc2178b5d1
--- /dev/null
+++ b/arch/xtensa/src/common/xtensa_allocateheap.c
@@ -0,0 +1,88 @@
+/****************************************************************************
+ * arch/xtensa/src/common/xtensa_allocateheap.c
+ *
+ * Copyright (C) 2010, 2013, 2015 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * 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
+
+#include
+#include
+
+#include
+#include
+#include
+
+#include "up_arch.h"
+#include "up_internal.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: up_allocate_heap
+ *
+ * Description:
+ * This function will be called to dynamically set aside the heap region.
+ *
+ * For the kernel build (CONFIG_BUILD_KERNEL=y) with both kernel- and
+ * user-space heaps (CONFIG_MM_KERNEL_HEAP=y), this function provides the
+ * size of the unprotected, user-space heap.
+ *
+ * If a protected kernel-space heap is provided, the kernel heap must be
+ * allocated (and protected) by an analogous up_allocate_kheap().
+ *
+ ****************************************************************************/
+
+void up_allocate_heap(FAR void **heap_start, size_t *heap_size)
+{
+ board_autoled_on(LED_HEAPALLOCATE);
+ *heap_start = (FAR void *)g_idle_topstack;
+ *heap_size = CONFIG_RAM_END - g_idle_topstack;
+}
diff --git a/arch/xtensa/src/common/xtensa_createstack.c b/arch/xtensa/src/common/xtensa_createstack.c
new file mode 100644
index 0000000000..08d310e497
--- /dev/null
+++ b/arch/xtensa/src/common/xtensa_createstack.c
@@ -0,0 +1,214 @@
+/****************************************************************************
+ * arch/xtensa/src/common/xtensa_createstack.c
+ *
+ * Copyright (C) 2011, 2013, 2015 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * 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
+
+#include
+#include
+#include
+#include
+
+#include
+#include
+#include
+#include
+
+#include "up_arch.h"
+#include "up_internal.h"
+
+/****************************************************************************
+ * Pre-processor Macros
+ ****************************************************************************/
+
+/* XTENSA requires at least a 4-byte stack alignment. For floating point use,
+ * however, the stack must be aligned to 8-byte addresses.
+ */
+
+#ifdef CONFIG_LIBC_FLOATINGPOINT
+# define STACK_ALIGNMENT 8
+#else
+# define STACK_ALIGNMENT 4
+#endif
+
+/* Stack alignment macros */
+
+#define STACK_ALIGN_MASK (STACK_ALIGNMENT-1)
+#define STACK_ALIGN_DOWN(a) ((a) & ~STACK_ALIGN_MASK)
+#define STACK_ALIGN_UP(a) (((a) + STACK_ALIGN_MASK) & ~STACK_ALIGN_MASK)
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: up_create_stack
+ *
+ * Description:
+ * Allocate a stack for a new thread and setup up stack-related information
+ * in the TCB.
+ *
+ * The following TCB fields must be initialized by this function:
+ *
+ * - adj_stack_size: Stack size after adjustment for hardware, processor,
+ * etc. This value is retained only for debug purposes.
+ * - stack_alloc_ptr: Pointer to allocated stack
+ * - adj_stack_ptr: Adjusted stack_alloc_ptr for HW. The initial value of
+ * the stack pointer.
+ *
+ * Inputs:
+ * - tcb: The TCB of new task
+ * - stack_size: The requested stack size. At least this much
+ * must be allocated.
+ * - ttype: The thread type. This may be one of following (defined in
+ * include/nuttx/sched.h):
+ *
+ * TCB_FLAG_TTYPE_TASK Normal user task
+ * TCB_FLAG_TTYPE_PTHREAD User pthread
+ * TCB_FLAG_TTYPE_KERNEL Kernel thread
+ *
+ * This thread type is normally available in the flags field of the TCB,
+ * however, there are certain contexts where the TCB may not be fully
+ * initialized when up_create_stack is called.
+ *
+ * If CONFIG_BUILD_KERNEL is defined, then this thread type may affect
+ * how the stack is allocated. For example, kernel thread stacks should
+ * be allocated from protected kernel memory. Stacks for user tasks and
+ * threads must come from memory that is accessible to user code.
+ *
+ ****************************************************************************/
+
+int up_create_stack(FAR struct tcb_s *tcb, size_t stack_size, uint8_t ttype)
+{
+ /* Is there already a stack allocated of a different size? Because of
+ * alignment issues, stack_size might erroneously appear to be of a
+ * different size. Fortunately, this is not a critical operation.
+ */
+
+ if (tcb->stack_alloc_ptr && tcb->adj_stack_size != stack_size)
+ {
+ /* Yes.. Release the old stack */
+
+ up_release_stack(tcb, ttype);
+ }
+
+ /* Do we need to allocate a new stack? */
+
+ if (!tcb->stack_alloc_ptr)
+ {
+ /* Allocate the stack. If DEBUG is enabled (but not stack debug),
+ * then create a zeroed stack to make stack dumps easier to trace.
+ */
+
+#if defined(CONFIG_BUILD_KERNEL) && defined(CONFIG_MM_KERNEL_HEAP)
+ /* Use the kernel allocator if this is a kernel thread */
+
+ if (ttype == TCB_FLAG_TTYPE_KERNEL)
+ {
+ tcb->stack_alloc_ptr = (uint32_t *)kmm_malloc(stack_size);
+ }
+ else
+#endif
+ {
+ /* Use the user-space allocator if this is a task or pthread */
+
+ tcb->stack_alloc_ptr = (uint32_t *)kumm_malloc(stack_size);
+ }
+
+#ifdef CONFIG_DEBUG_FEATURES
+ /* Was the allocation successful? */
+
+ if (!tcb->stack_alloc_ptr)
+ {
+ serr("ERROR: Failed to allocate stack, size %d\n", stack_size);
+ }
+#endif
+ }
+
+ /* Did we successfully allocate a stack? */
+
+ if (tcb->stack_alloc_ptr)
+ {
+ size_t top_of_stack;
+ size_t size_of_stack;
+
+ /* Yes.. If stack debug is enabled, then fill the stack with a
+ * recognizable value that we can use later to test for high
+ * water marks.
+ */
+
+#ifdef CONFIG_STACK_COLORATION
+ memset(tcb->stack_alloc_ptr, 0xaa, stack_size);
+#endif
+
+ /* XTENSA uses a push-down stack: the stack grows toward lower
+ * addresses in memory. The stack pointer register points to the
+ * lowest, valid working address (the "top" of the stack). Items on
+ * the stack are referenced as positive word offsets from sp.
+ */
+
+ top_of_stack = (uint32_t)tcb->stack_alloc_ptr + stack_size - 4;
+
+ /* The XTENSA stack must be aligned at word (4 byte) boundaries; for
+ * floating point use, the stack must be aligned to 8-byte addresses.
+ * If necessary top_of_stack must be rounded down to the next
+ * boundary to meet these alignment requirements.
+ */
+
+ top_of_stack = STACK_ALIGN_DOWN(top_of_stack);
+ size_of_stack = top_of_stack - (uint32_t)tcb->stack_alloc_ptr + 4;
+
+ /* Save the adjusted stack values in the struct tcb_s */
+
+ tcb->adj_stack_ptr = (FAR uint32_t *)top_of_stack;
+ tcb->adj_stack_size = size_of_stack;
+
+ board_autoled_on(LED_STACKCREATED);
+ return OK;
+ }
+
+ return ERROR;
+}
diff --git a/arch/xtensa/src/common/xtensa_etherstub.c b/arch/xtensa/src/common/xtensa_etherstub.c
new file mode 100644
index 0000000000..e19b26a208
--- /dev/null
+++ b/arch/xtensa/src/common/xtensa_etherstub.c
@@ -0,0 +1,86 @@
+/****************************************************************************
+ * arch/xtensa/src/common/xtensa_etherstub.c
+ *
+ * Copyright (C) 2011-2012, 2015 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * 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
+
+#include "up_internal.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: up_netinitialize (stub)
+ *
+ * Description:
+ * This is a stub version os up_netinitialize. Normally, up_netinitialize
+ * is defined in board/xyz_network.c for board-specific Ethernet
+ * implementations, or chip/xyx_ethernet.c for chip-specific Ethernet
+ * implementations. The stub version here is used in the corner case where
+ * the network is enable yet there is no Ethernet driver to be initialized.
+ * In this case, up_initialize will still try to call up_netinitialize()
+ * when one does not exist. This corner case would occur if, for example,
+ * only a USB network interface is being used or perhaps if a SLIP is
+ * being used).
+ *
+ * Use of this stub is deprecated. The preferred mechanism is to use
+ * CONFIG_NETDEV_LATEINIT=y to suppress the call to up_netinitialize() in
+ * up_initialize(). Then this stub would not be needed.
+ *
+ ****************************************************************************/
+
+void up_netinitialize(void)
+{
+}
diff --git a/arch/xtensa/src/common/xtensa_exit.c b/arch/xtensa/src/common/xtensa_exit.c
new file mode 100644
index 0000000000..f300c9b89a
--- /dev/null
+++ b/arch/xtensa/src/common/xtensa_exit.c
@@ -0,0 +1,188 @@
+/****************************************************************************
+ * arch/xtensa/src/common/xtensa_exit.c
+ *
+ * Copyright (C) 2011, 2013-2014 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * 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
+
+#include
+#include
+#include
+#include
+#include
+
+#ifdef CONFIG_DUMP_ON_EXIT
+#include
+#endif
+
+#include "task/task.h"
+#include "sched/sched.h"
+#include "group/group.h"
+#include "up_internal.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#ifndef CONFIG_DEBUG_SCHED_INFO
+# undef CONFIG_DUMP_ON_EXIT
+#endif
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: _up_dumponexit
+ *
+ * Description:
+ * Dump the state of all tasks whenever on task exits. This is debug
+ * instrumentation that was added to check file-related reference counting
+ * but could be useful again sometime in the future.
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_DUMP_ON_EXIT
+static void _up_dumponexit(FAR struct tcb_s *tcb, FAR void *arg)
+{
+#if CONFIG_NFILE_DESCRIPTORS > 0
+ FAR struct filelist *filelist;
+#if CONFIG_NFILE_STREAMS > 0
+ FAR struct streamlist *streamlist;
+#endif
+ int i;
+#endif
+
+ sinfo(" TCB=%p name=%s pid=%d\n", tcb, tcb->argv[0], tcb->pid);
+ sinfo(" priority=%d state=%d\n", tcb->sched_priority, tcb->task_state);
+
+#if CONFIG_NFILE_DESCRIPTORS > 0
+ filelist = tcb->group->tg_filelist;
+ for (i = 0; i < CONFIG_NFILE_DESCRIPTORS; i++)
+ {
+ struct inode *inode = filelist->fl_files[i].f_inode;
+ if (inode)
+ {
+ sinfo(" fd=%d refcount=%d\n",
+ i, inode->i_crefs);
+ }
+ }
+#endif
+
+#if CONFIG_NFILE_STREAMS > 0
+ streamlist = tcb->group->tg_streamlist;
+ for (i = 0; i < CONFIG_NFILE_STREAMS; i++)
+ {
+ struct file_struct *filep = &streamlist->sl_streams[i];
+ if (filep->fs_fd >= 0)
+ {
+#if CONFIG_STDIO_BUFFER_SIZE > 0
+ sinfo(" fd=%d nbytes=%d\n",
+ filep->fs_fd,
+ filep->fs_bufpos - filep->fs_bufstart);
+#else
+ sinfo(" fd=%d\n", filep->fs_fd);
+#endif
+ }
+ }
+#endif
+}
+#endif
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: _exit
+ *
+ * Description:
+ * This function causes the currently executing task to cease
+ * to exist. This is a special case of task_delete() where the task to
+ * be deleted is the currently executing task. It is more complex because
+ * a context switch must be perform to the next ready to run task.
+ *
+ ****************************************************************************/
+
+void _exit(int status)
+{
+ struct tcb_s *tcb;
+
+ /* Disable interrupts. They will be restored when the next
+ * task is started.
+ */
+
+ (void)up_irq_save();
+
+ sinfo("TCB=%p exiting\n", this_task());
+
+#ifdef CONFIG_DUMP_ON_EXIT
+ sinfo("Other tasks:\n");
+ sched_foreach(_up_dumponexit, NULL);
+#endif
+
+ /* Destroy the task at the head of the ready to run list. */
+
+ (void)task_exit();
+
+ /* Now, perform the context switch to the new ready-to-run task at the
+ * head of the list.
+ */
+
+ tcb = this_task();
+
+#ifdef CONFIG_ARCH_ADDRENV
+ /* Make sure that the address environment for the previously running
+ * task is closed down gracefully (data caches dump, MMU flushed) and
+ * set up the address environment for the new thread at the head of
+ * the ready-to-run list.
+ */
+
+ (void)group_addrenv(tcb);
+#endif
+
+ /* Then switch contexts */
+
+ up_fullcontextrestore(tcb->xcp.regs);
+
+ /* up_fullcontextrestore() should not return but could if the software
+ * interrupts are disabled.
+ */
+
+ PANIC();
+}
+
diff --git a/arch/xtensa/src/common/xtensa_idle.c b/arch/xtensa/src/common/xtensa_idle.c
new file mode 100644
index 0000000000..e48441d5b4
--- /dev/null
+++ b/arch/xtensa/src/common/xtensa_idle.c
@@ -0,0 +1,95 @@
+/****************************************************************************
+ * arch/xtensa/src/common/xtensa_idle.c
+ *
+ * Copyright (C) 2011-2012, 2016 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * 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
+#include
+#include
+
+#include "up_internal.h"
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: up_idle
+ *
+ * Description:
+ * up_idle() is the logic that will be executed when their is no other
+ * ready-to-run task. This is processor idle time and will continue until
+ * some interrupt occurs to cause a context switch from the idle task.
+ *
+ * Processing in this state may be processor-specific. e.g., this is where
+ * power management operations might be performed.
+ *
+ ****************************************************************************/
+
+void up_idle(void)
+{
+#if defined(CONFIG_SUPPRESS_INTERRUPTS) || defined(CONFIG_SUPPRESS_TIMER_INTS)
+ /* If the system is idle and there are no timer interrupts, then process
+ * "fake" timer interrupts. Hopefully, something will wake up.
+ */
+
+ sched_process_timer();
+#else
+
+ /* This would be an appropriate place to put some MCU-specific logic to
+ * sleep in a reduced power mode until an interrupt occurs to save power
+ */
+
+ /* This is a kludge that I still don't understand. The call to kmm_trysemaphore()
+ * in the os_start.c IDLE loop seems necessary for the good health of the IDLE
+ * loop. When the work queue is enabled, this logic is removed from the IDLE
+ * loop and it appears that we are somehow left idling with interrupts non-
+ * functional. The following should be no-op, it just disables then re-enables
+ * interrupts. But it fixes the problem and will stay here until I understand
+ * the problem/fix better.
+ *
+ * And no, the contents of the CP0 status register are not incorrect. But for
+ * some reason the status register needs to be re-written again on this thread
+ * for it to take effect. This might be a PIC32-only issue?
+ */
+
+#ifdef CONFIG_SCHED_WORKQUEUE
+ irqstate_t flags = enter_critical_section();
+ leave_critical_section(flags);
+#endif
+#endif
+}
diff --git a/arch/xtensa/src/common/xtensa_initialize.c b/arch/xtensa/src/common/xtensa_initialize.c
new file mode 100644
index 0000000000..1fedf99149
--- /dev/null
+++ b/arch/xtensa/src/common/xtensa_initialize.c
@@ -0,0 +1,261 @@
+/****************************************************************************
+ * arch/xtensa/src/common/xtensa_initialize.c
+ *
+ * Copyright (C) 2011-2013, 2015-2016 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * 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
+
+#include
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include
+
+#include "up_arch.h"
+#include "up_internal.h"
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: up_calibratedelay
+ *
+ * Description:
+ * Delay loops are provided for short timing loops. This function, if
+ * enabled, will just wait for 100 seconds. Using a stopwatch, you can
+ * can then determine if the timing loops are properly calibrated.
+ *
+ ****************************************************************************/
+
+#if defined(CONFIG_ARCH_CALIBRATION) && defined(CONFIG_DEBUG_FEATURES)
+static void up_calibratedelay(void)
+{
+ int i;
+
+ _warn("Beginning 100s delay\n");
+ for (i = 0; i < 100; i++)
+ {
+ up_mdelay(1000);
+ }
+
+ _warn("End 100s delay\n");
+}
+#else
+# define up_calibratedelay()
+#endif
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: up_initialize
+ *
+ * Description:
+ * up_initialize will be called once during OS initialization after the
+ * basic OS services have been initialized. The architecture specific
+ * details of initializing the OS will be handled here. Such things as
+ * setting up interrupt service routines, starting the clock, and
+ * registering device drivers are some of the things that are different
+ * for each processor and hardware platform.
+ *
+ * up_initialize is called after the OS initialized but before the user
+ * initialization logic has been started and before the libraries have
+ * been initialized. OS services and driver services are available.
+ *
+ ****************************************************************************/
+
+void up_initialize(void)
+{
+ /* Initialize global variables */
+
+ g_current_regs = NULL;
+
+ /* Calibrate the timing loop */
+
+ up_calibratedelay();
+
+ /* Add any extra memory fragments to the memory manager */
+
+ up_addregion();
+
+ /* Initialize the interrupt subsystem */
+
+ up_irqinitialize();
+
+#ifdef CONFIG_PM
+ /* Initialize the power management subsystem. This MCU-specific function
+ * must be called *very* early in the initialization sequence *before* any
+ * other device drivers are initialized (since they may attempt to register
+ * with the power management subsystem).
+ */
+
+ up_pminitialize();
+#endif
+
+#ifdef CONFIG_ARCH_DMA
+ /* Initialize the DMA subsystem if the weak function up_dmainitialize has been
+ * brought into the build
+ */
+
+#ifdef CONFIG_HAVE_WEAKFUNCTIONS
+ if (up_dmainitialize)
+#endif
+ {
+ up_dmainitialize();
+ }
+#endif
+
+ /* Initialize the system timer interrupt */
+
+#if !defined(CONFIG_SUPPRESS_INTERRUPTS) && !defined(CONFIG_SUPPRESS_TIMER_INTS)
+ up_timer_initialize();
+#endif
+
+ /* Register devices */
+
+#if CONFIG_NFILE_DESCRIPTORS > 0
+
+#if defined(CONFIG_DEV_NULL)
+ devnull_register(); /* Standard /dev/null */
+#endif
+
+#if defined(CONFIG_DEV_RANDOM)
+ devrandom_register(); /* Standard /dev/random */
+#endif
+
+#if defined(CONFIG_DEV_URANDOM)
+ devurandom_register(); /* Standard /dev/urandom */
+#endif
+
+#if defined(CONFIG_DEV_ZERO)
+ devzero_register(); /* Standard /dev/zero */
+#endif
+
+#if defined(CONFIG_DEV_LOOP)
+ loop_register(); /* Standard /dev/loop */
+#endif
+#endif /* CONFIG_NFILE_DESCRIPTORS */
+
+#if defined(CONFIG_SCHED_INSTRUMENTATION_BUFFER) && \
+ defined(CONFIG_DRIVER_NOTE)
+ note_register(); /* Non-standard /dev/note */
+#endif
+
+ /* Initialize the serial device driver */
+
+#ifdef USE_SERIALDRIVER
+ up_serialinit();
+#endif
+
+ /* Initialize the console device driver (if it is other than the standard
+ * serial driver).
+ */
+
+#if defined(CONFIG_DEV_LOWCONSOLE)
+ lowconsole_init();
+#elif defined(CONFIG_CONSOLE_SYSLOG)
+ syslog_console_init();
+#elif defined(CONFIG_RAMLOG_CONSOLE)
+ ramlog_consoleinit();
+#endif
+
+#if CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_PSEUDOTERM_SUSV1)
+ /* Register the master pseudo-terminal multiplexor device */
+
+ (void)ptmx_register();
+#endif
+
+ /* Early initialization of the system logging device. Some SYSLOG channel
+ * can be initialized early in the initialization sequence because they
+ * depend on only minimal OS initialization.
+ */
+
+ syslog_initialize(SYSLOG_INIT_EARLY);
+
+#if defined(CONFIG_CRYPTO)
+ /* Initialize the HW crypto and /dev/crypto */
+
+ up_cryptoinitialize();
+#endif
+
+#if CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_CRYPTO_CRYPTODEV)
+ devcrypto_register();
+#endif
+
+#ifndef CONFIG_NETDEV_LATEINIT
+ /* Initialize the network */
+
+ up_netinitialize();
+#endif
+
+#ifdef CONFIG_NETDEV_LOOPBACK
+ /* Initialize the local loopback device */
+
+ (void)localhost_initialize();
+#endif
+
+#ifdef CONFIG_NET_TUN
+ /* Initialize the TUN device */
+
+ (void)tun_initialize();
+#endif
+
+#ifdef CONFIG_NETDEV_TELNET
+ /* Initialize the Telnet session factory */
+
+ (void)telnet_initialize();
+#endif
+
+ /* Initialize USB -- device and/or host */
+
+ up_usbinitialize();
+ board_autoled_on(LED_IRQSENABLED);
+}
diff --git a/arch/xtensa/src/common/xtensa_interruptcontext.c b/arch/xtensa/src/common/xtensa_interruptcontext.c
new file mode 100644
index 0000000000..c6d83d05e0
--- /dev/null
+++ b/arch/xtensa/src/common/xtensa_interruptcontext.c
@@ -0,0 +1,70 @@
+/****************************************************************************
+ * arch/xtensa/src/common/xtensa_interruptcontext.c
+ *
+ * Copyright (C) 2011 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * 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
+
+#include
+#include
+#include
+
+#include "up_internal.h"
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: up_interrupt_context
+ *
+ * Description: Return true is we are currently executing in
+ * the interrupt handler context.
+ ****************************************************************************/
+
+bool up_interrupt_context(void)
+{
+ return g_current_regs != NULL;
+}
diff --git a/arch/xtensa/src/common/xtensa_lowputs.c b/arch/xtensa/src/common/xtensa_lowputs.c
new file mode 100644
index 0000000000..764f8393a6
--- /dev/null
+++ b/arch/xtensa/src/common/xtensa_lowputs.c
@@ -0,0 +1,74 @@
+/****************************************************************************
+ * arch/xtensa/src/common/xtensa_lowputs.c
+ *
+ * Copyright (C) 2011 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * 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
+
+#include "up_internal.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: up_lowputs
+ *
+ * Description:
+ * This is a low-level helper function used to support debug.
+ *
+ ****************************************************************************/
+
+void up_lowputs(const char *str)
+{
+ while (*str)
+ {
+ up_lowputc(*str++);
+ }
+}
diff --git a/arch/xtensa/src/common/xtensa_mdelay.c b/arch/xtensa/src/common/xtensa_mdelay.c
new file mode 100644
index 0000000000..f6b728bcc6
--- /dev/null
+++ b/arch/xtensa/src/common/xtensa_mdelay.c
@@ -0,0 +1,90 @@
+/****************************************************************************
+ * arch/xtensa/src/common/xtensa_mdelay.c
+ *
+ * Copyright (C) 2011 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * 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
+#include
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: up_mdelay
+ *
+ * Description:
+ * Delay inline for the requested number of milliseconds.
+ * *** NOT multi-tasking friendly ***
+ *
+ * ASSUMPTIONS:
+ * The setting CONFIG_BOARD_LOOPSPERMSEC has been calibrated
+ *
+ ****************************************************************************/
+
+void up_mdelay(unsigned int milliseconds)
+{
+ volatile int i;
+ volatile int j;
+
+ for (i = 0; i < milliseconds; i++)
+ {
+ for (j = 0; j < CONFIG_BOARD_LOOPSPERMSEC; j++)
+ {
+ }
+ }
+}
diff --git a/arch/xtensa/src/common/xtensa_modifyreg16.c b/arch/xtensa/src/common/xtensa_modifyreg16.c
new file mode 100644
index 0000000000..98a51c86ba
--- /dev/null
+++ b/arch/xtensa/src/common/xtensa_modifyreg16.c
@@ -0,0 +1,85 @@
+/****************************************************************************
+ * arch/xtensa/src/common/xtensa_modifyreg16.c
+ *
+ * Copyright (C) 2011 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * 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
+
+#include
+#include
+
+#include
+#include
+
+#include "up_arch.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: modifyreg16
+ *
+ * Description:
+ * Atomically modify the specified bits in a memory mapped register
+ *
+ ****************************************************************************/
+
+void modifyreg16(unsigned int addr, uint16_t clearbits, uint16_t setbits)
+{
+ irqstate_t flags;
+ uint16_t regval;
+
+ flags = enter_critical_section();
+ regval = getreg16(addr);
+ regval &= ~clearbits;
+ regval |= setbits;
+ putreg16(regval, addr);
+ leave_critical_section(flags);
+}
diff --git a/arch/xtensa/src/common/xtensa_modifyreg32.c b/arch/xtensa/src/common/xtensa_modifyreg32.c
new file mode 100644
index 0000000000..5619e6f272
--- /dev/null
+++ b/arch/xtensa/src/common/xtensa_modifyreg32.c
@@ -0,0 +1,85 @@
+/****************************************************************************
+ * arch/xtensa/src/common/xtensa_modifyreg32.c
+ *
+ * Copyright (C) 2011 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * 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
+
+#include
+#include
+
+#include
+#include
+
+#include "up_arch.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: modifyreg32
+ *
+ * Description:
+ * Atomically modify the specified bits in a memory mapped register
+ *
+ ****************************************************************************/
+
+void modifyreg32(unsigned int addr, uint32_t clearbits, uint32_t setbits)
+{
+ irqstate_t flags;
+ uint32_t regval;
+
+ flags = enter_critical_section();
+ regval = getreg32(addr);
+ regval &= ~clearbits;
+ regval |= setbits;
+ putreg32(regval, addr);
+ leave_critical_section(flags);
+}
diff --git a/arch/xtensa/src/common/xtensa_modifyreg8.c b/arch/xtensa/src/common/xtensa_modifyreg8.c
new file mode 100644
index 0000000000..e3bc73843e
--- /dev/null
+++ b/arch/xtensa/src/common/xtensa_modifyreg8.c
@@ -0,0 +1,85 @@
+/****************************************************************************
+ * arch/xtensa/src/common/xtensa_modifyreg8.c
+ *
+ * Copyright (C) 2011 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * 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
+
+#include
+#include
+
+#include
+#include
+
+#include "up_arch.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: modifyreg8
+ *
+ * Description:
+ * Atomically modify the specified bits in a memory mapped register
+ *
+ ****************************************************************************/
+
+void modifyreg8(unsigned int addr, uint8_t clearbits, uint8_t setbits)
+{
+ irqstate_t flags;
+ uint8_t regval;
+
+ flags = enter_critical_section();
+ regval = getreg8(addr);
+ regval &= ~clearbits;
+ regval |= setbits;
+ putreg8(regval, addr);
+ leave_critical_section(flags);
+}
diff --git a/arch/xtensa/src/common/xtensa_puts.c b/arch/xtensa/src/common/xtensa_puts.c
new file mode 100644
index 0000000000..47675baa8d
--- /dev/null
+++ b/arch/xtensa/src/common/xtensa_puts.c
@@ -0,0 +1,75 @@
+/****************************************************************************
+ * arch/xtensa/src/common/xtensa_puts.c
+ *
+ * Copyright (C) 2011 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * 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
+#include
+
+#include "up_internal.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: up_puts
+ *
+ * Description:
+ * This is a low-level helper function used to support debug.
+ *
+ ****************************************************************************/
+
+void up_puts(const char *str)
+{
+ while (*str)
+ {
+ up_putc(*str++);
+ }
+}
diff --git a/arch/xtensa/src/common/xtensa_releasestack.c b/arch/xtensa/src/common/xtensa_releasestack.c
new file mode 100644
index 0000000000..76b3164bce
--- /dev/null
+++ b/arch/xtensa/src/common/xtensa_releasestack.c
@@ -0,0 +1,122 @@
+/****************************************************************************
+ * arch/xtensa/src/common/xtensa_releasestack.c
+ *
+ * Copyright (C) 2011, 2013 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * 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
+
+#include
+#include
+
+#include
+#include
+
+#include "up_internal.h"
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: up_release_stack
+ *
+ * Description:
+ * A task has been stopped. Free all stack related resources retained in
+ * the defunct TCB.
+ *
+ * Input Parmeters
+ * - dtcb: The TCB containing information about the stack to be released
+ * - ttype: The thread type. This may be one of following (defined in
+ * include/nuttx/sched.h):
+ *
+ * TCB_FLAG_TTYPE_TASK Normal user task
+ * TCB_FLAG_TTYPE_PTHREAD User pthread
+ * TCB_FLAG_TTYPE_KERNEL Kernel thread
+ *
+ * This thread type is normally available in the flags field of the TCB,
+ * however, there are certain error recovery contexts where the TCB may
+ * not be fully initialized when up_release_stack is called.
+ *
+ * If CONFIG_BUILD_KERNEL is defined, then this thread type may affect
+ * how the stack is freed. For example, kernel thread stacks may have
+ * been allocated from protected kernel memory. Stacks for user tasks
+ * and threads must have come from memory that is accessible to user
+ * code.
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+void up_release_stack(FAR struct tcb_s *dtcb, uint8_t ttype)
+{
+ /* Is there a stack allocated? */
+
+ if (dtcb->stack_alloc_ptr)
+ {
+#if defined(CONFIG_BUILD_KERNEL) && defined(CONFIG_MM_KERNEL_HEAP)
+ /* Use the kernel allocator if this is a kernel thread */
+
+ if (ttype == TCB_FLAG_TTYPE_KERNEL)
+ {
+ sched_kfree(dtcb->stack_alloc_ptr);
+ }
+ else
+#endif
+ {
+ /* Use the user-space allocator if this is a task or pthread */
+
+ sched_ufree(dtcb->stack_alloc_ptr);
+ }
+
+ /* Mark the stack freed */
+
+ dtcb->stack_alloc_ptr = NULL;
+ }
+
+ /* The size of the allocated stack is now zero */
+
+ dtcb->adj_stack_size = 0;
+}
diff --git a/arch/xtensa/src/common/xtensa_stackframe.c b/arch/xtensa/src/common/xtensa_stackframe.c
new file mode 100644
index 0000000000..f0a1da976d
--- /dev/null
+++ b/arch/xtensa/src/common/xtensa_stackframe.c
@@ -0,0 +1,143 @@
+/****************************************************************************
+ * arch/xtensa/src/common/xtensa_stackframe.c
+ *
+ * Copyright (C) 2013 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * 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
+
+#include
+#include
+#include
+#include
+
+#include
+
+#include "up_internal.h"
+
+/****************************************************************************
+ * Pre-processor Macros
+ ****************************************************************************/
+/* XTENSA requires at least a 4-byte stack alignment. For floating point use,
+ * however, the stack must be aligned to 8-byte addresses.
+ */
+
+#ifdef CONFIG_LIBC_FLOATINGPOINT
+# define STACK_ALIGNMENT 8
+#else
+# define STACK_ALIGNMENT 4
+#endif
+
+/* Stack alignment macros */
+
+#define STACK_ALIGN_MASK (STACK_ALIGNMENT-1)
+#define STACK_ALIGN_DOWN(a) ((a) & ~STACK_ALIGN_MASK)
+#define STACK_ALIGN_UP(a) (((a) + STACK_ALIGN_MASK) & ~STACK_ALIGN_MASK)
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: up_stack_frame
+ *
+ * Description:
+ * Allocate a stack frame in the TCB's stack to hold thread-specific data.
+ * This function may be called anytime after up_create_stack() or
+ * up_use_stack() have been called but before the task has been started.
+ *
+ * Thread data may be kept in the stack (instead of in the TCB) if it is
+ * accessed by the user code directly. This includes such things as
+ * argv[]. The stack memory is guaranteed to be in the same protection
+ * domain as the thread.
+ *
+ * The following TCB fields will be re-initialized:
+ *
+ * - adj_stack_size: Stack size after removal of the stack frame from
+ * the stack
+ * - adj_stack_ptr: Adjusted initial stack pointer after the frame has
+ * been removed from the stack. This will still be the initial value
+ * of the stack pointer when the task is started.
+ *
+ * Inputs:
+ * - tcb: The TCB of new task
+ * - frame_size: The size of the stack frame to allocate.
+ *
+ * Returned Value:
+ * - A pointer to bottom of the allocated stack frame. NULL will be
+ * returned on any failures. The alignment of the returned value is
+ * the same as the alignment of the stack itself.
+ *
+ ****************************************************************************/
+
+FAR void *up_stack_frame(FAR struct tcb_s *tcb, size_t frame_size)
+{
+ uintptr_t topaddr;
+
+ /* Align the frame_size */
+
+ frame_size = STACK_ALIGN_UP(frame_size);
+
+ /* Is there already a stack allocated? Is it big enough? */
+
+ if (!tcb->stack_alloc_ptr || tcb->adj_stack_size <= frame_size)
+ {
+ return NULL;
+ }
+
+ /* Save the adjusted stack values in the struct tcb_s */
+
+ topaddr = (uintptr_t)tcb->adj_stack_ptr - frame_size;
+ tcb->adj_stack_ptr = (FAR void *)topaddr;
+ tcb->adj_stack_size -= frame_size;
+
+ /* Reset the initial stack pointer */
+
+ tcb->xcp.regs[REG_SP] = (uint32_t)tcb->adj_stack_ptr;
+
+ /* And return the pointer to the allocated region */
+
+ return (FAR void *)(topaddr + sizeof(uint32_t));
+}
+
diff --git a/arch/xtensa/src/common/xtensa_udelay.c b/arch/xtensa/src/common/xtensa_udelay.c
new file mode 100644
index 0000000000..f18be5b891
--- /dev/null
+++ b/arch/xtensa/src/common/xtensa_udelay.c
@@ -0,0 +1,129 @@
+/****************************************************************************
+ * arch/xtensa/src/common/xtensa_udelay.c
+ *
+ * Copyright (C) 2011 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * 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
+#include
+#include
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define CONFIG_BOARD_LOOPSPER100USEC ((CONFIG_BOARD_LOOPSPERMSEC+5)/10)
+#define CONFIG_BOARD_LOOPSPER10USEC ((CONFIG_BOARD_LOOPSPERMSEC+50)/100)
+#define CONFIG_BOARD_LOOPSPERUSEC ((CONFIG_BOARD_LOOPSPERMSEC+500)/1000)
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: up_udelay
+ *
+ * Description:
+ * Delay inline for the requested number of microseconds. NOTE: Because
+ * of all of the setup, several microseconds will be lost before the actual
+ * timing looop begins. Thus, the delay will always be a few microseconds
+ * longer than requested.
+ *
+ * *** NOT multi-tasking friendly ***
+ *
+ * ASSUMPTIONS:
+ * The setting CONFIG_BOARD_LOOPSPERMSEC has been calibrated
+ *
+ ****************************************************************************/
+
+void up_udelay(useconds_t microseconds)
+{
+ volatile int i;
+
+ /* We'll do this a little at a time because we expect that the
+ * CONFIG_BOARD_LOOPSPERUSEC is very inaccurate during to truncation in
+ * the divisions of its calculation. We'll use the largest values that
+ * we can in order to prevent significant error buildup in the loops.
+ */
+
+ while (microseconds > 1000)
+ {
+ for (i = 0; i < CONFIG_BOARD_LOOPSPERMSEC; i++)
+ {
+ }
+ microseconds -= 1000;
+ }
+
+ while (microseconds > 100)
+ {
+ for (i = 0; i < CONFIG_BOARD_LOOPSPER100USEC; i++)
+ {
+ }
+ microseconds -= 100;
+ }
+
+ while (microseconds > 10)
+ {
+ for (i = 0; i < CONFIG_BOARD_LOOPSPER10USEC; i++)
+ {
+ }
+ microseconds -= 10;
+ }
+
+ while (microseconds > 0)
+ {
+ for (i = 0; i < CONFIG_BOARD_LOOPSPERUSEC; i++)
+ {
+ }
+ microseconds--;
+ }
+}
diff --git a/arch/xtensa/src/common/xtensa_usestack.c b/arch/xtensa/src/common/xtensa_usestack.c
new file mode 100644
index 0000000000..9b35e2d0a9
--- /dev/null
+++ b/arch/xtensa/src/common/xtensa_usestack.c
@@ -0,0 +1,152 @@
+/****************************************************************************
+ * arch/xtensa/src/common/xtensa_usestack.c
+ *
+ * Copyright (C) 2011, 2013 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * 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
+
+#include
+#include
+#include
+#include
+
+#include
+#include
+
+#include "up_internal.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* XTENSA requires at least a 4-byte stack alignment. For floating point use,
+ * however, the stack must be aligned to 8-byte addresses.
+ */
+
+#ifdef CONFIG_LIBC_FLOATINGPOINT
+# define STACK_ALIGNMENT 8
+#else
+# define STACK_ALIGNMENT 4
+#endif
+
+/* Stack alignment macros */
+
+#define STACK_ALIGN_MASK (STACK_ALIGNMENT-1)
+#define STACK_ALIGN_DOWN(a) ((a) & ~STACK_ALIGN_MASK)
+#define STACK_ALIGN_UP(a) (((a) + STACK_ALIGN_MASK) & ~STACK_ALIGN_MASK)
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: up_use_stack
+ *
+ * Description:
+ * Setup up stack-related information in the TCB using pre-allocated stack
+ * memory. This function is called only from task_init() when a task or
+ * kernel thread is started (never for pthreads).
+ *
+ * The following TCB fields must be initialized:
+ *
+ * - adj_stack_size: Stack size after adjustment for hardware,
+ * processor, etc. This value is retained only for debug
+ * purposes.
+ * - stack_alloc_ptr: Pointer to allocated stack
+ * - adj_stack_ptr: Adjusted stack_alloc_ptr for HW. The
+ * initial value of the stack pointer.
+ *
+ * Inputs:
+ * - tcb: The TCB of new task
+ * - stack_size: The allocated stack size.
+ *
+ * NOTE: Unlike up_stack_create() and up_stack_release, this function
+ * does not require the task type (ttype) parameter. The TCB flags will
+ * always be set to provide the task type to up_use_stack() if it needs
+ * that information.
+ *
+ ****************************************************************************/
+
+int up_use_stack(struct tcb_s *tcb, void *stack, size_t stack_size)
+{
+ size_t top_of_stack;
+ size_t size_of_stack;
+
+ /* Is there already a stack allocated? */
+
+ if (tcb->stack_alloc_ptr)
+ {
+ /* Yes.. Release the old stack allocation */
+
+ up_release_stack(tcb, tcb->flags & TCB_FLAG_TTYPE_MASK);
+ }
+
+ /* Save the new stack allocation */
+
+ tcb->stack_alloc_ptr = stack;
+
+ /* XTENSA uses a push-down stack: the stack grows toward loweraddresses in
+ * memory. The stack pointer register, points to the lowest, valid work
+ * address (the "top" of the stack). Items on the stack are referenced
+ * as positive word offsets from sp.
+ */
+
+ top_of_stack = (uint32_t)tcb->stack_alloc_ptr + stack_size - 4;
+
+ /* The XTENSA stack must be aligned at word (4 byte) or double word (8 byte)
+ * boundaries. If necessary top_of_stack must be rounded down to the
+ * next boundary
+ */
+
+ top_of_stack = STACK_ALIGN_DOWN(top_of_stack);
+ size_of_stack = top_of_stack - (uint32_t)tcb->stack_alloc_ptr + 4;
+
+ /* Save the adjusted stack values in the struct tcb_s */
+
+ tcb->adj_stack_ptr = (uint32_t *)top_of_stack;
+ tcb->adj_stack_size = size_of_stack;
+
+ return OK;
+}
diff --git a/arch/xtensa/src/lx6/Kconfig b/arch/xtensa/src/lx6/Kconfig
new file mode 100644
index 0000000000..8ccb4fe392
--- /dev/null
+++ b/arch/xtensa/src/lx6/Kconfig
@@ -0,0 +1,9 @@
+#
+# For a description of the syntax of this configuration file,
+# see the file kconfig-language.txt in the NuttX tools repository.
+#
+
+if ARCH_LX6
+
+endif # ARCH_LX6
+
diff --git a/arch/xtensa/src/lx6/Make.defs b/arch/xtensa/src/lx6/Make.defs
new file mode 100644
index 0000000000..06ba9cad86
--- /dev/null
+++ b/arch/xtensa/src/lx6/Make.defs
@@ -0,0 +1,67 @@
+############################################################################
+# arch/xtensa/src/lx6/Make.defs
+#
+# Copyright (C) 2016 Gregory Nutt. All rights reserved.
+# Author: Gregory Nutt
+#
+# 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.
+#
+############################################################################
+
+# The start-up, "head", file
+
+HEAD_ASRC =
+
+# Common XTENSA files (arch/xtensa/src/common)
+
+CMN_ASRCS =
+CMN_CSRCS = xtensa_allocateheap.c xtensa_createstack.c xtensa_exit.c
+CMN_CSRCS += xtensa_idle.c xtensa_initialize.c xtensa_interruptcontext.c
+CMN_CSRCS += xtensa_lowputs.c xtensa_mdelay.c xtensa_modifyreg8.c
+CMN_CSRCS += xtensa_modifyreg16.c xtensa_modifyreg32.c xtensa_puts.c
+CMN_CSRCS += xtensa_releasestack.c xtensa_stackframe.c xtensa_udelay.c
+CMN_CSRCS += xtensa_usestack.c
+
+# Configuration-dependent common XTENSA files
+
+# Use of common/xtensa_etherstub.c is deprecated. The preferred mechanism
+# is to use CONFIG_NETDEV_LATEINIT=y to suppress the call to up_netinitialize()
+# in xtensa_initialize.c. Then this stub would not be needed.
+
+ifneq ($(CONFIG_LX6_ETHERNET),y)
+ifeq ($(CONFIG_NET),y)
+ CMN_CSRCS += xtensa_etherstub.c
+endif
+endif
+
+# Required LX6 files (arch/xtensa/src/lx6)
+
+CHIP_ASRCS =
+CHIP_CSRCS =
+
+# Configuration-dependent LX6 files
--
GitLab
From 852330876b5aeff8ea777597eb5185ffe4e03eab Mon Sep 17 00:00:00 2001
From: Gregory Nutt
Date: Wed, 12 Oct 2016 14:50:28 -0600
Subject: [PATCH 055/734] arch/xtensa: A little more ESP32 configuration logic
---
arch/Kconfig | 7 ++
arch/xtensa/include/esp32/chip.h | 77 +++++++++++++++++++++
arch/xtensa/include/esp32/irq.h | 85 ++++++++++++++++++++++++
arch/xtensa/include/irq.h | 17 ++++-
arch/xtensa/include/lx6/chip.h | 7 --
arch/xtensa/include/lx6/irq.h | 2 -
arch/xtensa/src/esp32/Kconfig | 9 +++
arch/xtensa/src/{lx6 => esp32}/Make.defs | 0
arch/xtensa/src/lx6/Kconfig | 26 +++++++-
9 files changed, 217 insertions(+), 13 deletions(-)
create mode 100644 arch/xtensa/include/esp32/chip.h
create mode 100644 arch/xtensa/include/esp32/irq.h
create mode 100644 arch/xtensa/src/esp32/Kconfig
rename arch/xtensa/src/{lx6 => esp32}/Make.defs (100%)
diff --git a/arch/Kconfig b/arch/Kconfig
index 319419bb2d..ee252d2cbd 100644
--- a/arch/Kconfig
+++ b/arch/Kconfig
@@ -67,6 +67,11 @@ config ARCH_X86
---help---
Intel x86 architectures.
+config ARCH_XTENSA
+ bool "Xtensa"
+ ---help---
+ Cadence Cadence® Tensilica® Xtensa® actictures.
+
config ARCH_Z16
bool "ZNEO"
select ARCH_HAVE_HEAP2
@@ -91,6 +96,7 @@ config ARCH
default "renesas" if ARCH_RENESAS
default "sim" if ARCH_SIM
default "x86" if ARCH_X86
+ default "xtensa" if ARCH_XTENSA
default "z16" if ARCH_Z16
default "z80" if ARCH_Z80
@@ -102,6 +108,7 @@ source arch/rgmp/Kconfig
source arch/renesas/Kconfig
source arch/sim/Kconfig
source arch/x86/Kconfig
+source arch/xtensa/Kconfig
source arch/z16/Kconfig
source arch/z80/Kconfig
diff --git a/arch/xtensa/include/esp32/chip.h b/arch/xtensa/include/esp32/chip.h
new file mode 100644
index 0000000000..95e9e2cac3
--- /dev/null
+++ b/arch/xtensa/include/esp32/chip.h
@@ -0,0 +1,77 @@
+/****************************************************************************
+ * arch/xtensa/include/esp32/chip.h
+ *
+ * Copyright (C) 2016 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+#ifndef __ARCH_XTENSA_INCLUDE_ESP32_CHIP_H
+#define __ARCH_XTENSA_INCLUDE_ESP32_CHIP_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+#ifndef __ASSEMBLY__
+
+/****************************************************************************
+ * Inline Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+#ifdef __cplusplus
+#define EXTERN extern "C"
+extern "C"
+{
+#else
+#define EXTERN extern
+#endif
+
+#undef EXTERN
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __ASSEMBLY__ */
+#endif /* __ARCH_XTENSA_INCLUDE_ESP32_CHIP_H */
diff --git a/arch/xtensa/include/esp32/irq.h b/arch/xtensa/include/esp32/irq.h
new file mode 100644
index 0000000000..d67ea04794
--- /dev/null
+++ b/arch/xtensa/include/esp32/irq.h
@@ -0,0 +1,85 @@
+/****************************************************************************
+ * arch/xtensa/include/esp32/irq.h
+ *
+ * Copyright (C) 2016 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+/* This file should never be included directed but, rather, only indirectly
+ * through nuttx/irq.h
+ */
+
+#ifndef __ARCH_XTENSA_INCLUDE_ESP32_IRQ_H
+#define __ARCH_XTENSA_INCLUDE_ESP32_IRQ_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+#ifndef __ASSEMBLY__
+
+/****************************************************************************
+ * Inline functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+#ifdef __cplusplus
+#define EXTERN extern "C"
+extern "C"
+{
+#else
+#define EXTERN extern
+#endif
+
+#undef EXTERN
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __ASSEMBLY__ */
+#endif /* __ARCH_XTENSA_INCLUDE_ESP32_IRQ_H */
diff --git a/arch/xtensa/include/irq.h b/arch/xtensa/include/irq.h
index d2af5ba4e4..19739e7944 100644
--- a/arch/xtensa/include/irq.h
+++ b/arch/xtensa/include/irq.h
@@ -48,9 +48,22 @@
#include
-/* Include chip-specific IRQ definitions (including IRQ numbers) */
+/* Include architecture-specific IRQ definitions */
-#include
+#ifdef CONFIG_ARCH_CHIP_LX6
+# include
+
+/* Include implementation-specific IRQ definitions (including IRQ numbers) */
+
+# ifdef CONFIG_ARCH_CHIP_ESP32
+# include
+# else
+# error Unknown LX6 implementation
+# endif
+
+#else
+# error Unknown XTENSA architecture
+#endif
/****************************************************************************
* Pre-processor Definitions
diff --git a/arch/xtensa/include/lx6/chip.h b/arch/xtensa/include/lx6/chip.h
index 060d99e945..a3cb0e3e84 100644
--- a/arch/xtensa/include/lx6/chip.h
+++ b/arch/xtensa/include/lx6/chip.h
@@ -45,13 +45,6 @@
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
-/* Configuration ************************************************************/
-
-#if defined(CONFIG_ARCH_CHIP_LX6)
-/* To be provided */
-#else
-# error "Unrecognized LX6 device
-#endif
/****************************************************************************
* Public Types
diff --git a/arch/xtensa/include/lx6/irq.h b/arch/xtensa/include/lx6/irq.h
index ec2b218f58..ddc87e0c2b 100644
--- a/arch/xtensa/include/lx6/irq.h
+++ b/arch/xtensa/include/lx6/irq.h
@@ -44,8 +44,6 @@
* Included Files
****************************************************************************/
-#include
-
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
diff --git a/arch/xtensa/src/esp32/Kconfig b/arch/xtensa/src/esp32/Kconfig
new file mode 100644
index 0000000000..8ccb4fe392
--- /dev/null
+++ b/arch/xtensa/src/esp32/Kconfig
@@ -0,0 +1,9 @@
+#
+# For a description of the syntax of this configuration file,
+# see the file kconfig-language.txt in the NuttX tools repository.
+#
+
+if ARCH_LX6
+
+endif # ARCH_LX6
+
diff --git a/arch/xtensa/src/lx6/Make.defs b/arch/xtensa/src/esp32/Make.defs
similarity index 100%
rename from arch/xtensa/src/lx6/Make.defs
rename to arch/xtensa/src/esp32/Make.defs
diff --git a/arch/xtensa/src/lx6/Kconfig b/arch/xtensa/src/lx6/Kconfig
index 8ccb4fe392..073954b7d6 100644
--- a/arch/xtensa/src/lx6/Kconfig
+++ b/arch/xtensa/src/lx6/Kconfig
@@ -3,7 +3,29 @@
# see the file kconfig-language.txt in the NuttX tools repository.
#
-if ARCH_LX6
+if ARCH_CHIP_LX6
-endif # ARCH_LX6
+choice
+ prompt "LX6 implementation"
+ default ARCH_CHIP_ESP32
+config ARCH_CHIP_ESP32
+ bool "Expressif ESP32"
+ ---help---
+ The ESP32 is a dual-core system with two Harvard Architecture Xtensa
+ LX6 CPUs. All embedded memory, external memory and peripherals are
+ located on the data bus and/or the instruction bus of these CPUs.
+ With some minor exceptions the address mapping of two CPUs is
+ symmetric, meaning they use the same addresses to access the same
+ memory. Multiple peripherals in the system can access embedded
+ memory via DMA.
+
+ The two CPUs are named "PRO_CPU" and "APP_CPU" (for "protocol" and
+ "application"), however for most purposes the two CPUs are
+ interchangeable.
+
+endchoice # LX6 implementation
+
+source arch/xtensa/src/esp32/Kconfig
+
+endif # ARCH_CHIP_LX6
--
GitLab
From 52b1ca87477a593b125d75e236bcecc9a83e61c2 Mon Sep 17 00:00:00 2001
From: Gregory Nutt
Date: Wed, 12 Oct 2016 15:27:34 -0600
Subject: [PATCH 056/734] configs/esp32-core: Add basic directory to support
the ESP32 Core board V2
---
arch/README.txt | 15 +++++++++++++
configs/Kconfig | 19 +++++++++++-----
configs/README.txt | 8 +++++++
configs/esp32-core/Kconfig | 8 +++++++
configs/esp32-core/README.txt | 41 +++++++++++++++++++++++++++++++++++
5 files changed, 85 insertions(+), 6 deletions(-)
create mode 100644 configs/esp32-core/Kconfig
create mode 100644 configs/esp32-core/README.txt
diff --git a/arch/README.txt b/arch/README.txt
index bd49fb31a7..ffdb4ba317 100644
--- a/arch/README.txt
+++ b/arch/README.txt
@@ -244,6 +244,21 @@ arch/x86 - Intel x86 architectures
arch/x86/include/i486 and arch/x86/src/i486
arch/x86/include/qemu and arch/x86/src/qemu
+arch/xtensa
+
+ Implementations based on the Cadence® Tensilica® Xtensa® processors,
+ such as the Xtensa LX6 dataplane processing units (DPUs). At
+ present, this includes the following subdirectories:
+
+ Common XTENSA support:
+ arch/xtensa/include and arch/xtensa/src/common
+
+ LX6 DPU support:
+ arch/xtensa/include/lx6 and arch/xtensa/xtensa/lx6
+
+ Expressif ESP32 implemenation of the LX6 DPU:
+ arch/xtensa/include/esp32 and arch/xtensa/xtensa/esp32
+
arch/z16 - ZiLOG 16-bit processors
This directory holds related, 16-bit architectures from ZiLOG. At
present, this includes the following subdirectories:
diff --git a/configs/Kconfig b/configs/Kconfig
index 2b629c1a4f..2506d8c081 100644
--- a/configs/Kconfig
+++ b/configs/Kconfig
@@ -170,14 +170,17 @@ config ARCH_BOARD_EKKLM3S9B96
TI/Stellaris EKK-LM3S9B96 board. This board is based on the
an EKK-LM3S9B96 which is a Cortex-M3.
-config ARCH_BOARD_EZ80F910200KITG
- bool "ZiLOG ez80f910200kitg development kit"
- depends on ARCH_CHIP_EZ80F91
+config ARCH_BOARD_ESP32CORE
+ bool "Expressif ESP32 Core board V2"
+ depends on ARCH_CHIP_ESP32
select ARCH_HAVE_LEDS
---help---
- ez80Acclaim! Microcontroller. This port use the ZiLOG ez80f910200kitg
- development kit, eZ80F091 part, and the Zilog ZDS-II Windows command line
- tools. The development environment is Cygwin under WinXP.
+ The ESP32 is a dual-core system from Expressif with two Harvard
+ architecture Xtensa LX6 CPUs. All embedded memory, external memory
+ and peripherals are located on the data bus and/or the instruction
+ bus of these CPUs. With some minor exceptions, the address mapping
+ of two CPUs is symmetric, meaning they use the same addresses to
+ access the same memory.
config ARCH_BOARD_EZ80F910200ZCO
bool "ZiLOG ez80f910200zco development kit"
@@ -1383,6 +1386,7 @@ config ARCH_BOARD
default "efm32-g8xx-stk" if ARCH_BOARD_EFM32G8XXSTK
default "efm32gg-stk3700" if ARCH_BOARD_EFM32GG_STK3700
default "ekk-lm3s9b96" if ARCH_BOARD_EKKLM3S9B96
+ default "esp32-core" if ARCH_BOARD_ESP32CORE
default "ez80f910200kitg" if ARCH_BOARD_EZ80F910200KITG
default "ez80f910200zco" if ARCH_BOARD_EZ80F910200ZCO
default "fire-stm32v2" if ARCH_BOARD_FIRE_STM32
@@ -1581,6 +1585,9 @@ endif
if ARCH_BOARD_EKKLM3S9B96
source "configs/ekk-lm3s9b96/Kconfig"
endif
+if ARCH_BOARD_ESP32CORE
+source "configs/esp32-core/Kconfig"
+endif
if ARCH_BOARD_EZ80F910200KITG
source "configs/ez80f910200kitg/Kconfig"
endif
diff --git a/configs/README.txt b/configs/README.txt
index 8bf546a298..fa34391328 100644
--- a/configs/README.txt
+++ b/configs/README.txt
@@ -246,6 +246,14 @@ configs/ekk-lm3s9b96
TI/Stellaris EKK-LM3S9B96 board. This board is based on the
an EKK-LM3S9B96 which is a Cortex-M3.
+configs/esp-core
+ The ESP32 is a dual-core system from Expressif with two Harvard
+ architecture Xtensa LX6 CPUs. All embedded memory, external memory and
+ nd peripherals are located on the data bus and/or the instruction bus of
+ bus of these CPUs. With some minor exceptions, the address mapping of two
+ CPUs is symmetric, meaning they use the same addresses to access the same
+ memory.
+
configs/ez80f0910200kitg
ez80Acclaim! Microcontroller. This port use the Zilog ez80f0910200kitg
development kit, eZ80F091 part, and the Zilog ZDS-II Windows command line
diff --git a/configs/esp32-core/Kconfig b/configs/esp32-core/Kconfig
new file mode 100644
index 0000000000..719b83d1a5
--- /dev/null
+++ b/configs/esp32-core/Kconfig
@@ -0,0 +1,8 @@
+#
+# For a description of the syntax of this configuration file,
+# see the file kconfig-language.txt in the NuttX tools repository.
+#
+
+if ARCH_BOARD_ESP32CORE
+
+endif # ARCH_BOARD_ESP32CORE
diff --git a/configs/esp32-core/README.txt b/configs/esp32-core/README.txt
new file mode 100644
index 0000000000..84fd259b58
--- /dev/null
+++ b/configs/esp32-core/README.txt
@@ -0,0 +1,41 @@
+README for the Expressif ESP32 Core board (V2)
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+ The ESP32 is a dual-core system from Expressif with two Harvard
+ architecture Xtensa LX6 CPUs. All embedded memory, external memory and
+ peripherals are located on the data bus and/or the instruction bus of
+ these CPUs. With some minor exceptions, the address mapping of two CPUs
+ is symmetric, meaning they use the same addresses to access the same
+ memory. Multiple peripherals in the system can access embedded memory via
+ DMA.
+
+ The two CPUs are named "PRO_CPU" and "APP_CPU" (for "protocol" and
+ "application"), however for most purposes the two CPUs are
+ interchangeable.
+
+ Features:
+
+ * Address Space
+ - Symmetric address mapping
+ - 4 GB (32-bit) address space for both data bus and instruction bus
+ - 1296 KB embedded memory address space
+ - 19704 KB external memory address space
+ - 512 KB peripheral address space
+ - Some embedded and external memory regions can be accessed by either
+ data bus or instruction bus
+ - 328 KB DMA address space
+ * Embedded Memory
+ - 448 KB Internal ROM
+ - 520 KB Internal SRAM
+ - 8 KB RTC FAST Memory
+ - 8 KB RTC SLOW Memory
+ * External Memory
+ Off-chip SPI memory can be mapped into the available address space as
+ external memory. Parts of the embedded memory can be used as transparent
+ cache for this external memory.
+ - Supports up to 16 MB off-Chip SPI Flash.
+ - Supports up to 8 MB off-Chip SPI SRAM.
+ * Peripherals
+ - 41 peripherals
+ * DMA
+ - 13 modules are capable of DMA operation
\ No newline at end of file
--
GitLab
From 38d9436e42ca01e79651d09708faa7e6d68942d2 Mon Sep 17 00:00:00 2001
From: Gregory Nutt
Date: Thu, 13 Oct 2016 11:34:29 -0600
Subject: [PATCH 057/734] ESP32 Core board: Add a dummy board Makefile
---
configs/esp32-core/src/.gitignore | 2 ++
configs/esp32-core/src/Makefile | 41 +++++++++++++++++++++++++++++++
2 files changed, 43 insertions(+)
create mode 100644 configs/esp32-core/src/.gitignore
create mode 100644 configs/esp32-core/src/Makefile
diff --git a/configs/esp32-core/src/.gitignore b/configs/esp32-core/src/.gitignore
new file mode 100644
index 0000000000..726d936e1e
--- /dev/null
+++ b/configs/esp32-core/src/.gitignore
@@ -0,0 +1,2 @@
+/.depend
+/Make.dep
diff --git a/configs/esp32-core/src/Makefile b/configs/esp32-core/src/Makefile
new file mode 100644
index 0000000000..017d00f499
--- /dev/null
+++ b/configs/esp32-core/src/Makefile
@@ -0,0 +1,41 @@
+############################################################################
+# configs//srp32-core/Makefile
+#
+# Copyright (C) 2016 Gregory Nutt. All rights reserved.
+# Author: Gregory Nutt
+#
+# 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
+
+ASRCS =
+CSRCS =
+
+include $(TOPDIR)/configs/Board.mk
--
GitLab
From ae5ada0ec5284cff5f0bb80184d7211369d8d284 Mon Sep 17 00:00:00 2001
From: Gregory Nutt
Date: Thu, 13 Oct 2016 14:22:27 -0600
Subject: [PATCH 058/734] ESP32 Core: Add a dummy board.h header file
---
configs/esp32-core/include/board.h | 39 ++++++++++++++++++++++++++++++
1 file changed, 39 insertions(+)
create mode 100644 configs/esp32-core/include/board.h
diff --git a/configs/esp32-core/include/board.h b/configs/esp32-core/include/board.h
new file mode 100644
index 0000000000..d07ba907cf
--- /dev/null
+++ b/configs/esp32-core/include/board.h
@@ -0,0 +1,39 @@
+/****************************************************************************
+ * configs/esp32-core/include/board.h
+ *
+ * Copyright (C) 2016 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+#ifndef __CONFIGS_ESP32_CORE_INCLUDE_BOARD_H
+#define __CONFIGS_ESP32_CORE_INCLUDE_BOARD_H
+
+#endif /* __CONFIGS_ESP32_CORE_INCLUDE_BOARD_H */
--
GitLab
From 25331aeb631b1a72c0d60e6acd3b7137ebb82dd8 Mon Sep 17 00:00:00 2001
From: Gregory Nutt
Date: Thu, 13 Oct 2016 14:37:28 -0600
Subject: [PATCH 059/734] ESP32 Core: Add an NSH configuration for build
testing
---
arch/Kconfig | 2 +-
arch/xtensa/Kconfig | 23 +-
configs/esp32-core/nsh/Make.defs | 113 +++++
configs/esp32-core/nsh/defconfig | 750 +++++++++++++++++++++++++++++++
configs/esp32-core/nsh/setenv.sh | 80 ++++
5 files changed, 959 insertions(+), 9 deletions(-)
create mode 100644 configs/esp32-core/nsh/Make.defs
create mode 100644 configs/esp32-core/nsh/defconfig
create mode 100644 configs/esp32-core/nsh/setenv.sh
diff --git a/arch/Kconfig b/arch/Kconfig
index ee252d2cbd..dd873f9723 100644
--- a/arch/Kconfig
+++ b/arch/Kconfig
@@ -70,7 +70,7 @@ config ARCH_X86
config ARCH_XTENSA
bool "Xtensa"
---help---
- Cadence Cadence® Tensilica® Xtensa® actictures.
+ Cadence® Tensilica® Xtensa® actictures.
config ARCH_Z16
bool "ZNEO"
diff --git a/arch/xtensa/Kconfig b/arch/xtensa/Kconfig
index d740939c1e..3ba3a48ec3 100644
--- a/arch/xtensa/Kconfig
+++ b/arch/xtensa/Kconfig
@@ -7,24 +7,31 @@ if ARCH_XTENSA
choice
prompt "XTENSA architecture selection"
- default ARCH_CHIP_LX6
+ default ARCH_CHIP_ESP32
-config ARCH_CHIP_LX6
- bool "LX6 DPU"
- select ARCH_LX6
+config ARCH_CHIP_ESP32
+ bool "Expressif ESP32"
+ select ARCH_FAMILY_LX6
---help---
- Cadence® Tensilica® Xtensa® LX6 data plane processing unit (DPU).
- The LX6 is a configurable and extensible processor core.
+ The ESP32 is a dual-core system from Expressif with two Harvard
+ architecture Xtensa LX6 CPUs. All embedded memory, external memory
+ and peripherals are located on the data bus and/or the instruction
+ bus of these CPUs. With some minor exceptions, the address mapping
+ of two CPUs is symmetric, meaning they use the same addresses to
+ access the same memory.
endchoice # XTENSA chip selection
-config ARCH_LX6
+config ARCH_FAMILY_LX6
bool
default n
+ ---help---
+ Cadence® Tensilica® Xtensa® LX6 data plane processing unit (DPU).
+ The LX6 is a configurable and extensible processor core.
config ARCH_CHIP
string
- default "lx6" if ARCH_LX6
+ default "esp32" if ARCH_CHIP_ESP32
source arch/xtensa/src/lx6/Kconfig
diff --git a/configs/esp32-core/nsh/Make.defs b/configs/esp32-core/nsh/Make.defs
new file mode 100644
index 0000000000..02251501c8
--- /dev/null
+++ b/configs/esp32-core/nsh/Make.defs
@@ -0,0 +1,113 @@
+############################################################################
+# configs/stm32f4discovery/nsh/Make.defs
+#
+# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved.
+# Author: Gregory Nutt
+#
+# 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
+
+LDSCRIPT = ld.script
+
+ifeq ($(WINTOOL),y)
+ # Windows-native toolchains
+ DIRLINK = $(TOPDIR)/tools/copydir.sh
+ DIRUNLINK = $(TOPDIR)/tools/unlink.sh
+ MKDEP = $(TOPDIR)/tools/mkwindeps.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/$(LDSCRIPT)}"
+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/$(LDSCRIPT)
+endif
+
+CC = $(CROSSDEV)gcc
+CXX = $(CROSSDEV)g++
+CPP = $(CROSSDEV)gcc -E
+LD = $(CROSSDEV)ld
+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
+
+
+HOSTCC = gcc
+HOSTINCLUDES = -I.
+HOSTCFLAGS = -Wall -Wstrict-prototypes -Wshadow -Wundef -g -pipe
+HOSTLDFLAGS =
+
diff --git a/configs/esp32-core/nsh/defconfig b/configs/esp32-core/nsh/defconfig
new file mode 100644
index 0000000000..cee088cc3e
--- /dev/null
+++ b/configs/esp32-core/nsh/defconfig
@@ -0,0 +1,750 @@
+#
+# Automatically generated file; DO NOT EDIT.
+# Nuttx/ Configuration
+#
+
+#
+# Build Setup
+#
+# CONFIG_EXPERIMENTAL is not set
+# CONFIG_DEFAULT_SMALL is not set
+# CONFIG_HOST_LINUX is not set
+# CONFIG_HOST_OSX is not set
+CONFIG_HOST_WINDOWS=y
+# CONFIG_HOST_OTHER is not set
+# CONFIG_WINDOWS_NATIVE is not set
+CONFIG_WINDOWS_CYGWIN=y
+# CONFIG_WINDOWS_MSYS is not set
+# CONFIG_WINDOWS_OTHER is not set
+
+#
+# Build Configuration
+#
+# CONFIG_APPS_DIR="../apps"
+CONFIG_BUILD_FLAT=y
+# CONFIG_BUILD_2PASS is not set
+
+#
+# Binary Output Formats
+#
+# CONFIG_RRLOAD_BINARY is not set
+CONFIG_INTELHEX_BINARY=y
+# CONFIG_MOTOROLA_SREC is not set
+CONFIG_RAW_BINARY=y
+# CONFIG_UBOOT_UIMAGE is not set
+
+#
+# Customize Header Files
+#
+# CONFIG_ARCH_STDINT_H is not set
+# CONFIG_ARCH_STDBOOL_H is not set
+# CONFIG_ARCH_MATH_H is not set
+# CONFIG_ARCH_FLOAT_H is not set
+# CONFIG_ARCH_STDARG_H is not set
+# CONFIG_ARCH_DEBUG_H is not set
+
+#
+# Debug Options
+#
+CONFIG_DEBUG_ALERT=y
+# CONFIG_DEBUG_FEATURES is not set
+# CONFIG_ARCH_HAVE_STACKCHECK is not set
+# CONFIG_ARCH_HAVE_HEAPCHECK is not set
+# CONFIG_DEBUG_SYMBOLS is not set
+# CONFIG_ARCH_HAVE_CUSTOMOPT is not set
+# CONFIG_DEBUG_NOOPT is not set
+CONFIG_DEBUG_FULLOPT=y
+
+#
+# System Type
+#
+# CONFIG_ARCH_ARM is not set
+# CONFIG_ARCH_AVR is not set
+# CONFIG_ARCH_HC is not set
+# CONFIG_ARCH_MIPS is not set
+# CONFIG_ARCH_RGMP is not set
+# CONFIG_ARCH_RENESAS is not set
+# CONFIG_ARCH_SIM is not set
+# CONFIG_ARCH_X86 is not set
+CONFIG_ARCH_XTENSA=y
+# CONFIG_ARCH_Z16 is not set
+# CONFIG_ARCH_Z80 is not set
+CONFIG_ARCH="xtensa"
+CONFIG_ARCH_CHIP="esp32"
+CONFIG_ARCH_CHIP_ESP32=y
+CONFIG_ARCH_FAMILY_LX6=y
+
+#
+# Architecture Options
+#
+# CONFIG_ARCH_NOINTC is not set
+# CONFIG_ARCH_VECNOTIRQ is not set
+# CONFIG_ARCH_DMA is not set
+# CONFIG_ARCH_HAVE_IRQPRIO is not set
+# CONFIG_ARCH_L2CACHE is not set
+# CONFIG_ARCH_HAVE_COHERENT_DCACHE is not set
+# CONFIG_ARCH_HAVE_ADDRENV is not set
+# CONFIG_ARCH_NEED_ADDRENV_MAPPING is not set
+# CONFIG_ARCH_HAVE_MULTICPU is not set
+# CONFIG_ARCH_HAVE_VFORK is not set
+# CONFIG_ARCH_HAVE_MMU is not set
+# CONFIG_ARCH_HAVE_MPU is not set
+# CONFIG_ARCH_NAND_HWECC is not set
+# CONFIG_ARCH_HAVE_EXTCLK is not set
+# CONFIG_ARCH_HAVE_POWEROFF is not set
+# CONFIG_ARCH_HAVE_RESET is not set
+CONFIG_ARCH_STACKDUMP=y
+# CONFIG_ENDIAN_BIG is not set
+# CONFIG_ARCH_IDLE_CUSTOM is not set
+# CONFIG_ARCH_HAVE_RAMFUNCS is not set
+# CONFIG_ARCH_HAVE_RAMVECTORS is not set
+
+#
+# Board Settings
+#
+CONFIG_BOARD_LOOPSPERMSEC=16717
+# CONFIG_ARCH_CALIBRATION is not set
+
+#
+# Interrupt options
+#
+# CONFIG_ARCH_HAVE_INTERRUPTSTACK is not set
+# CONFIG_ARCH_HAVE_HIPRI_INTERRUPT is not set
+
+#
+# Boot options
+#
+# CONFIG_BOOT_RUNFROMEXTSRAM is not set
+CONFIG_BOOT_RUNFROMFLASH=y
+# CONFIG_BOOT_RUNFROMISRAM is not set
+# CONFIG_BOOT_RUNFROMSDRAM is not set
+# CONFIG_BOOT_COPYTORAM is not set
+
+#
+# Boot Memory Configuration
+#
+CONFIG_RAM_START=0x20000000
+CONFIG_RAM_SIZE=114688
+# CONFIG_ARCH_HAVE_SDRAM is not set
+
+#
+# Board Selection
+#
+CONFIG_ARCH_BOARD_ESP32CORE=y
+# CONFIG_ARCH_BOARD_CUSTOM is not set
+CONFIG_ARCH_BOARD="esp32-core"
+
+#
+# Common Board Options
+#
+CONFIG_ARCH_HAVE_LEDS=y
+CONFIG_ARCH_LEDS=y
+
+#
+# Board-Specific Options
+#
+# CONFIG_BOARD_CRASHDUMP is not set
+# CONFIG_LIB_BOARDCTL is not set
+
+#
+# RTOS Features
+#
+CONFIG_DISABLE_OS_API=y
+# CONFIG_DISABLE_POSIX_TIMERS is not set
+# CONFIG_DISABLE_PTHREAD is not set
+# CONFIG_DISABLE_SIGNALS is not set
+# CONFIG_DISABLE_MQUEUE is not set
+# CONFIG_DISABLE_ENVIRON is not set
+
+#
+# Clocks and Timers
+#
+CONFIG_USEC_PER_TICK=10000
+# CONFIG_SYSTEM_TIME64 is not set
+# CONFIG_CLOCK_MONOTONIC is not set
+# CONFIG_ARCH_HAVE_TIMEKEEPING is not set
+# CONFIG_JULIAN_TIME is not set
+CONFIG_START_YEAR=2011
+CONFIG_START_MONTH=12
+CONFIG_START_DAY=6
+CONFIG_MAX_WDOGPARMS=2
+CONFIG_PREALLOC_WDOGS=16
+CONFIG_WDOG_INTRESERVE=4
+CONFIG_PREALLOC_TIMERS=4
+
+#
+# Tasks and Scheduling
+#
+# CONFIG_INIT_NONE is not set
+CONFIG_INIT_ENTRYPOINT=y
+# CONFIG_INIT_FILEPATH is not set
+CONFIG_USER_ENTRYPOINT="nsh_main"
+CONFIG_RR_INTERVAL=200
+# CONFIG_SCHED_SPORADIC is not set
+CONFIG_TASK_NAME_SIZE=31
+CONFIG_MAX_TASKS=16
+# CONFIG_SCHED_HAVE_PARENT is not set
+CONFIG_SCHED_WAITPID=y
+
+#
+# Pthread Options
+#
+# CONFIG_MUTEX_TYPES is not set
+CONFIG_NPTHREAD_KEYS=4
+
+#
+# Performance Monitoring
+#
+# CONFIG_SCHED_CPULOAD is not set
+# CONFIG_SCHED_INSTRUMENTATION is not set
+
+#
+# Files and I/O
+#
+CONFIG_DEV_CONSOLE=y
+# CONFIG_FDCLONE_DISABLE is not set
+# CONFIG_FDCLONE_STDIO is not set
+CONFIG_SDCLONE_DISABLE=y
+CONFIG_NFILE_DESCRIPTORS=8
+CONFIG_NFILE_STREAMS=8
+CONFIG_NAME_MAX=32
+# CONFIG_PRIORITY_INHERITANCE is not set
+
+#
+# RTOS hooks
+#
+# CONFIG_BOARD_INITIALIZE is not set
+# CONFIG_SCHED_STARTHOOK is not set
+# CONFIG_SCHED_ATEXIT is not set
+# CONFIG_SCHED_ONEXIT is not set
+
+#
+# Signal Numbers
+#
+CONFIG_SIG_SIGUSR1=1
+CONFIG_SIG_SIGUSR2=2
+CONFIG_SIG_SIGALARM=3
+CONFIG_SIG_SIGCONDTIMEDOUT=16
+
+#
+# POSIX Message Queue Options
+#
+CONFIG_PREALLOC_MQ_MSGS=4
+CONFIG_MQ_MAXMSGSIZE=32
+# CONFIG_MODULE is not set
+
+#
+# Work queue support
+#
+# CONFIG_SCHED_WORKQUEUE is not set
+# CONFIG_SCHED_HPWORK is not set
+# CONFIG_SCHED_LPWORK is not set
+
+#
+# Stack and heap information
+#
+CONFIG_IDLETHREAD_STACKSIZE=1024
+CONFIG_USERMAIN_STACKSIZE=2048
+CONFIG_PTHREAD_STACK_MIN=256
+CONFIG_PTHREAD_STACK_DEFAULT=2048
+# CONFIG_LIB_SYSCALL is not set
+
+#
+# Device Drivers
+#
+CONFIG_DISABLE_POLL=y
+CONFIG_DEV_NULL=y
+# CONFIG_DEV_ZERO is not set
+# CONFIG_DEV_URANDOM is not set
+# CONFIG_DEV_LOOP is not set
+
+#
+# Buffering
+#
+# CONFIG_DRVR_WRITEBUFFER is not set
+# CONFIG_DRVR_READAHEAD is not set
+# CONFIG_RAMDISK is not set
+# CONFIG_CAN is not set
+# CONFIG_ARCH_HAVE_PWM_PULSECOUNT is not set
+# CONFIG_ARCH_HAVE_PWM_MULTICHAN is not set
+# CONFIG_PWM is not set
+# CONFIG_ARCH_HAVE_I2CRESET is not set
+# CONFIG_I2C is not set
+CONFIG_SPI=y
+# CONFIG_SPI_SLAVE is not set
+CONFIG_SPI_EXCHANGE=y
+# CONFIG_SPI_CMDDATA is not set
+# CONFIG_SPI_CALLBACK is not set
+# CONFIG_SPI_HWFEATURES is not set
+# CONFIG_ARCH_HAVE_SPI_CRCGENERATION is not set
+# CONFIG_ARCH_HAVE_SPI_CS_CONTROL is not set
+# CONFIG_ARCH_HAVE_SPI_BITORDER is not set
+# CONFIG_SPI_CS_DELAY_CONTROL is not set
+# CONFIG_SPI_DRIVER is not set
+# CONFIG_SPI_BITBANG is not set
+# CONFIG_I2S is not set
+
+#
+# Timer Driver Support
+#
+# CONFIG_TIMER is not set
+# CONFIG_ONESHOT is not set
+# CONFIG_RTC is not set
+# CONFIG_WATCHDOG is not set
+# CONFIG_ANALOG is not set
+# CONFIG_AUDIO_DEVICES is not set
+# CONFIG_VIDEO_DEVICES is not set
+# CONFIG_BCH is not set
+# CONFIG_INPUT is not set
+
+#
+# IO Expander/GPIO Support
+#
+# CONFIG_IOEXPANDER is not set
+# CONFIG_DEV_GPIO is not set
+
+#
+# LCD Driver Support
+#
+# CONFIG_LCD is not set
+# CONFIG_SLCD is not set
+
+#
+# LED Support
+#
+# CONFIG_USERLED is not set
+# CONFIG_RGBLED is not set
+# CONFIG_PCA9635PW is not set
+# CONFIG_NCP5623C is not set
+# CONFIG_MMCSD is not set
+# CONFIG_MODEM is not set
+# CONFIG_MTD is not set
+# CONFIG_EEPROM is not set
+# CONFIG_PIPES is not set
+# CONFIG_PM is not set
+# CONFIG_POWER is not set
+# CONFIG_SENSORS is not set
+# CONFIG_SERCOMM_CONSOLE is not set
+CONFIG_SERIAL=y
+# CONFIG_DEV_LOWCONSOLE is not set
+# CONFIG_SERIAL_REMOVABLE is not set
+# CONFIG_SERIAL_CONSOLE is not set
+# CONFIG_16550_UART is not set
+# CONFIG_UART_SERIALDRIVER is not set
+# CONFIG_UART0_SERIALDRIVER is not set
+# CONFIG_UART1_SERIALDRIVER is not set
+# CONFIG_UART2_SERIALDRIVER is not set
+# CONFIG_UART3_SERIALDRIVER is not set
+# CONFIG_UART4_SERIALDRIVER is not set
+# CONFIG_UART5_SERIALDRIVER is not set
+# CONFIG_UART6_SERIALDRIVER is not set
+# CONFIG_UART7_SERIALDRIVER is not set
+# CONFIG_UART8_SERIALDRIVER is not set
+# CONFIG_SCI0_SERIALDRIVER is not set
+# CONFIG_SCI1_SERIALDRIVER is not set
+# CONFIG_USART0_SERIALDRIVER is not set
+# CONFIG_USART1_SERIALDRIVER is not set
+# CONFIG_USART2_SERIALDRIVER is not set
+# CONFIG_USART3_SERIALDRIVER is not set
+# CONFIG_USART4_SERIALDRIVER is not set
+# CONFIG_USART5_SERIALDRIVER is not set
+# CONFIG_USART6_SERIALDRIVER is not set
+# CONFIG_USART7_SERIALDRIVER is not set
+# CONFIG_USART8_SERIALDRIVER is not set
+# CONFIG_OTHER_UART_SERIALDRIVER is not set
+# CONFIG_MCU_SERIAL is not set
+CONFIG_STANDARD_SERIAL=y
+# CONFIG_SERIAL_IFLOWCONTROL is not set
+# CONFIG_SERIAL_OFLOWCONTROL is not set
+# CONFIG_SERIAL_DMA is not set
+# CONFIG_ARCH_HAVE_SERIAL_TERMIOS is not set
+# CONFIG_PSEUDOTERM is not set
+# CONFIG_USBDEV is not set
+# CONFIG_USBHOST is not set
+# CONFIG_HAVE_USBTRACE is not set
+# CONFIG_DRIVERS_WIRELESS is not set
+# CONFIG_DRIVERS_CONTACTLESS is not set
+
+#
+# System Logging
+#
+# CONFIG_ARCH_SYSLOG is not set
+# CONFIG_RAMLOG is not set
+# CONFIG_SYSLOG_INTBUFFER is not set
+# CONFIG_SYSLOG_TIMESTAMP is not set
+# CONFIG_SYSLOG_SERIAL_CONSOLE is not set
+# CONFIG_SYSLOG_CHAR is not set
+CONFIG_SYSLOG_CONSOLE=y
+# CONFIG_SYSLOG_NONE is not set
+# CONFIG_SYSLOG_FILE is not set
+# CONFIG_SYSLOG_CHARDEV is not set
+
+#
+# Networking Support
+#
+# CONFIG_ARCH_HAVE_NET is not set
+# CONFIG_ARCH_HAVE_PHY is not set
+# CONFIG_NET is not set
+
+#
+# Crypto API
+#
+# CONFIG_CRYPTO is not set
+
+#
+# File Systems
+#
+
+#
+# File system configuration
+#
+# CONFIG_DISABLE_MOUNTPOINT is not set
+# CONFIG_FS_AUTOMOUNTER is not set
+# CONFIG_DISABLE_PSEUDOFS_OPERATIONS is not set
+CONFIG_FS_READABLE=y
+# CONFIG_FS_WRITABLE is not set
+# CONFIG_FS_NAMED_SEMAPHORES is not set
+CONFIG_FS_MQUEUE_MPATH="/var/mqueue"
+# CONFIG_FS_RAMMAP is not set
+# CONFIG_FS_FAT is not set
+# CONFIG_FS_NXFFS is not set
+# CONFIG_FS_ROMFS is not set
+# CONFIG_FS_TMPFS is not set
+# CONFIG_FS_SMARTFS is not set
+# CONFIG_FS_BINFS is not set
+CONFIG_FS_PROCFS=y
+# CONFIG_FS_PROCFS_REGISTER is not set
+
+#
+# Exclude individual procfs entries
+#
+# CONFIG_FS_PROCFS_EXCLUDE_PROCESS is not set
+# CONFIG_FS_PROCFS_EXCLUDE_UPTIME is not set
+# CONFIG_FS_PROCFS_EXCLUDE_MOUNTS is not set
+# CONFIG_FS_UNIONFS is not set
+
+#
+# Graphics Support
+#
+# CONFIG_NX is not set
+
+#
+# Memory Management
+#
+# CONFIG_MM_SMALL is not set
+CONFIG_MM_REGIONS=2
+# CONFIG_ARCH_HAVE_HEAP2 is not set
+# CONFIG_GRAN is not set
+
+#
+# Audio Support
+#
+# CONFIG_AUDIO is not set
+
+#
+# Wireless Support
+#
+
+#
+# Binary Loader
+#
+# CONFIG_BINFMT_DISABLE is not set
+# CONFIG_BINFMT_EXEPATH is not set
+# CONFIG_NXFLAT is not set
+# CONFIG_ELF is not set
+CONFIG_BUILTIN=y
+# CONFIG_PIC is not set
+# CONFIG_SYMTAB_ORDEREDBYNAME is not set
+
+#
+# Library Routines
+#
+
+#
+# Standard C Library Options
+#
+CONFIG_STDIO_BUFFER_SIZE=64
+CONFIG_STDIO_LINEBUFFER=y
+CONFIG_NUNGET_CHARS=2
+CONFIG_LIB_HOMEDIR="/"
+# CONFIG_LIBM is not set
+# CONFIG_NOPRINTF_FIELDWIDTH is not set
+# CONFIG_LIBC_FLOATINGPOINT is not set
+CONFIG_LIBC_LONG_LONG=y
+# CONFIG_LIBC_IOCTL_VARIADIC is not set
+CONFIG_LIB_RAND_ORDER=1
+# CONFIG_EOL_IS_CR is not set
+# CONFIG_EOL_IS_LF is not set
+# CONFIG_EOL_IS_BOTH_CRLF is not set
+CONFIG_EOL_IS_EITHER_CRLF=y
+# CONFIG_LIBC_EXECFUNCS is not set
+CONFIG_POSIX_SPAWN_PROXY_STACKSIZE=1024
+CONFIG_TASK_SPAWN_DEFAULT_STACKSIZE=2048
+# CONFIG_LIBC_STRERROR is not set
+# CONFIG_LIBC_PERROR_STDOUT is not set
+CONFIG_ARCH_LOWPUTC=y
+# CONFIG_LIBC_LOCALTIME is not set
+# CONFIG_TIME_EXTENDED is not set
+CONFIG_LIB_SENDFILE_BUFSIZE=512
+# CONFIG_ARCH_ROMGETC is not set
+# CONFIG_ARCH_OPTIMIZED_FUNCTIONS is not set
+# CONFIG_ARCH_HAVE_TLS is not set
+# CONFIG_LIBC_NETDB is not set
+# CONFIG_NETDB_HOSTFILE is not set
+
+#
+# Non-standard Library Support
+#
+# CONFIG_LIB_CRC64_FAST is not set
+# CONFIG_LIB_KBDCODEC is not set
+# CONFIG_LIB_SLCDCODEC is not set
+# CONFIG_LIB_HEX2BIN is not set
+
+#
+# Basic CXX Support
+#
+# CONFIG_C99_BOOL8 is not set
+CONFIG_HAVE_CXX=y
+CONFIG_HAVE_CXXINITIALIZE=y
+# CONFIG_CXX_NEWLONG is not set
+
+#
+# uClibc++ Standard C++ Library
+#
+# CONFIG_UCLIBCXX is not set
+
+#
+# Application Configuration
+#
+
+#
+# Built-In Applications
+#
+CONFIG_BUILTIN_PROXY_STACKSIZE=1024
+
+#
+# CAN Utilities
+#
+
+#
+# Examples
+#
+# CONFIG_EXAMPLES_CHAT is not set
+# CONFIG_EXAMPLES_CONFIGDATA is not set
+# CONFIG_EXAMPLES_CXXTEST is not set
+# CONFIG_EXAMPLES_DHCPD is not set
+# CONFIG_EXAMPLES_ELF is not set
+# CONFIG_EXAMPLES_FTPC is not set
+# CONFIG_EXAMPLES_FTPD is not set
+# CONFIG_EXAMPLES_HELLO is not set
+# CONFIG_EXAMPLES_HELLOXX is not set
+# CONFIG_EXAMPLES_HIDKBD is not set
+# CONFIG_EXAMPLES_IGMP is not set
+# CONFIG_EXAMPLES_JSON is not set
+# CONFIG_EXAMPLES_KEYPADTEST is not set
+# CONFIG_EXAMPLES_MEDIA is not set
+# CONFIG_EXAMPLES_MM is not set
+# CONFIG_EXAMPLES_MODBUS is not set
+# CONFIG_EXAMPLES_MOUNT is not set
+# CONFIG_EXAMPLES_NRF24L01TERM is not set
+CONFIG_EXAMPLES_NSH=y
+CONFIG_EXAMPLES_NSH_CXXINITIALIZE=y
+# CONFIG_EXAMPLES_NULL is not set
+# CONFIG_EXAMPLES_NX is not set
+# CONFIG_EXAMPLES_NXFFS is not set
+# CONFIG_EXAMPLES_NXHELLO is not set
+# CONFIG_EXAMPLES_NXIMAGE is not set
+# CONFIG_EXAMPLES_NXLINES is not set
+# CONFIG_EXAMPLES_NXTERM is not set
+# CONFIG_EXAMPLES_NXTEXT is not set
+# CONFIG_EXAMPLES_OSTEST is not set
+# CONFIG_EXAMPLES_PCA9635 is not set
+# CONFIG_EXAMPLES_POSIXSPAWN is not set
+# CONFIG_EXAMPLES_PPPD is not set
+# CONFIG_EXAMPLES_RFID_READUID is not set
+# CONFIG_EXAMPLES_RGBLED is not set
+# CONFIG_EXAMPLES_RGMP is not set
+# CONFIG_EXAMPLES_SENDMAIL is not set
+# CONFIG_EXAMPLES_SERIALBLASTER is not set
+# CONFIG_EXAMPLES_SERIALRX is not set
+# CONFIG_EXAMPLES_SERLOOP is not set
+# CONFIG_EXAMPLES_SLCD is not set
+# CONFIG_EXAMPLES_SMART is not set
+# CONFIG_EXAMPLES_SMART_TEST is not set
+# CONFIG_EXAMPLES_SMP is not set
+# CONFIG_EXAMPLES_TCPECHO is not set
+# CONFIG_EXAMPLES_TELNETD is not set
+# CONFIG_EXAMPLES_TIFF is not set
+# CONFIG_EXAMPLES_TOUCHSCREEN is not set
+# CONFIG_EXAMPLES_USBTERM is not set
+# CONFIG_EXAMPLES_WATCHDOG is not set
+# CONFIG_EXAMPLES_WEBSERVER is not set
+
+#
+# File System Utilities
+#
+# CONFIG_FSUTILS_INIFILE is not set
+# CONFIG_FSUTILS_PASSWD is not set
+
+#
+# GPS Utilities
+#
+# CONFIG_GPSUTILS_MINMEA_LIB is not set
+
+#
+# Graphics Support
+#
+# CONFIG_TIFF is not set
+# CONFIG_GRAPHICS_TRAVELER is not set
+
+#
+# Interpreters
+#
+# CONFIG_INTERPRETERS_BAS is not set
+# CONFIG_INTERPRETERS_FICL is not set
+# CONFIG_INTERPRETERS_MICROPYTHON is not set
+# CONFIG_INTERPRETERS_MINIBASIC is not set
+# CONFIG_INTERPRETERS_PCODE is not set
+
+#
+# FreeModBus
+#
+# CONFIG_MODBUS is not set
+
+#
+# Network Utilities
+#
+# CONFIG_NETUTILS_CODECS is not set
+# CONFIG_NETUTILS_ESP8266 is not set
+# CONFIG_NETUTILS_FTPC is not set
+# CONFIG_NETUTILS_JSON is not set
+# CONFIG_NETUTILS_SMTP is not set
+
+#
+# NSH Library
+#
+CONFIG_NSH_LIBRARY=y
+# CONFIG_NSH_MOTD is not set
+
+#
+# Command Line Configuration
+#
+CONFIG_NSH_READLINE=y
+# CONFIG_NSH_CLE is not set
+CONFIG_NSH_LINELEN=64
+# CONFIG_NSH_DISABLE_SEMICOLON is not set
+# CONFIG_NSH_CMDPARMS is not set
+CONFIG_NSH_MAXARGUMENTS=6
+# CONFIG_NSH_ARGCAT is not set
+CONFIG_NSH_NESTDEPTH=3
+# CONFIG_NSH_DISABLEBG is not set
+CONFIG_NSH_BUILTIN_APPS=y
+
+#
+# Disable Individual commands
+#
+# CONFIG_NSH_DISABLE_ADDROUTE is not set
+# CONFIG_NSH_DISABLE_BASENAME is not set
+# CONFIG_NSH_DISABLE_CAT is not set
+# CONFIG_NSH_DISABLE_CD is not set
+# CONFIG_NSH_DISABLE_CP is not set
+# CONFIG_NSH_DISABLE_CMP is not set
+CONFIG_NSH_DISABLE_DATE=y
+# CONFIG_NSH_DISABLE_DD is not set
+# CONFIG_NSH_DISABLE_DF is not set
+# CONFIG_NSH_DISABLE_DELROUTE is not set
+# CONFIG_NSH_DISABLE_DIRNAME is not set
+# CONFIG_NSH_DISABLE_ECHO is not set
+# CONFIG_NSH_DISABLE_EXEC is not set
+# CONFIG_NSH_DISABLE_EXIT is not set
+# CONFIG_NSH_DISABLE_FREE is not set
+# CONFIG_NSH_DISABLE_GET is not set
+# CONFIG_NSH_DISABLE_HELP is not set
+# CONFIG_NSH_DISABLE_HEXDUMP is not set
+# CONFIG_NSH_DISABLE_IFCONFIG is not set
+# CONFIG_NSH_DISABLE_IFUPDOWN is not set
+# CONFIG_NSH_DISABLE_KILL is not set
+# CONFIG_NSH_DISABLE_LOSETUP is not set
+CONFIG_NSH_DISABLE_LOSMART=y
+# CONFIG_NSH_DISABLE_LS is not set
+# CONFIG_NSH_DISABLE_MB is not set
+# CONFIG_NSH_DISABLE_MKDIR is not set
+# CONFIG_NSH_DISABLE_MKRD is not set
+# CONFIG_NSH_DISABLE_MH is not set
+# CONFIG_NSH_DISABLE_MOUNT is not set
+# CONFIG_NSH_DISABLE_MV is not set
+# CONFIG_NSH_DISABLE_MW is not set
+CONFIG_NSH_DISABLE_PRINTF=y
+# CONFIG_NSH_DISABLE_PS is not set
+# CONFIG_NSH_DISABLE_PUT is not set
+# CONFIG_NSH_DISABLE_PWD is not set
+# CONFIG_NSH_DISABLE_RM is not set
+# CONFIG_NSH_DISABLE_RMDIR is not set
+# CONFIG_NSH_DISABLE_SET is not set
+# CONFIG_NSH_DISABLE_SH is not set
+# CONFIG_NSH_DISABLE_SLEEP is not set
+# CONFIG_NSH_DISABLE_TIME is not set
+# CONFIG_NSH_DISABLE_TEST is not set
+# CONFIG_NSH_DISABLE_UMOUNT is not set
+# CONFIG_NSH_DISABLE_UNAME is not set
+# CONFIG_NSH_DISABLE_UNSET is not set
+# CONFIG_NSH_DISABLE_USLEEP is not set
+# CONFIG_NSH_DISABLE_WGET is not set
+# CONFIG_NSH_DISABLE_XD is not set
+CONFIG_NSH_MMCSDMINOR=0
+
+#
+# Configure Command Options
+#
+# CONFIG_NSH_CMDOPT_DF_H is not set
+CONFIG_NSH_CODECS_BUFSIZE=128
+# CONFIG_NSH_CMDOPT_HEXDUMP is not set
+CONFIG_NSH_PROC_MOUNTPOINT="/proc"
+CONFIG_NSH_FILEIOSIZE=512
+
+#
+# Scripting Support
+#
+# CONFIG_NSH_DISABLESCRIPT is not set
+# CONFIG_NSH_DISABLE_ITEF is not set
+# CONFIG_NSH_DISABLE_LOOPS is not set
+
+#
+# Console Configuration
+#
+CONFIG_NSH_CONSOLE=y
+# CONFIG_NSH_ALTCONDEV is not set
+# CONFIG_NSH_ARCHINIT is not set
+# CONFIG_NSH_LOGIN is not set
+# CONFIG_NSH_CONSOLE_LOGIN is not set
+
+#
+# NxWidgets/NxWM
+#
+
+#
+# Platform-specific Support
+#
+# CONFIG_PLATFORM_CONFIGDATA is not set
+
+#
+# System Libraries and NSH Add-Ons
+#
+# CONFIG_SYSTEM_CLE is not set
+# CONFIG_SYSTEM_CUTERM is not set
+# CONFIG_SYSTEM_FREE is not set
+# CONFIG_SYSTEM_HEX2BIN is not set
+# CONFIG_SYSTEM_HEXED is not set
+# CONFIG_SYSTEM_INSTALL is not set
+# CONFIG_SYSTEM_RAMTEST is not set
+CONFIG_READLINE_HAVE_EXTMATCH=y
+CONFIG_SYSTEM_READLINE=y
+CONFIG_READLINE_ECHO=y
+# CONFIG_READLINE_TABCOMPLETION is not set
+# CONFIG_READLINE_CMD_HISTORY is not set
+# CONFIG_SYSTEM_SUDOKU is not set
+# CONFIG_SYSTEM_SYSTEM is not set
+# CONFIG_SYSTEM_TEE is not set
+# CONFIG_SYSTEM_UBLOXMODEM is not set
+# CONFIG_SYSTEM_VI is not set
+# CONFIG_SYSTEM_ZMODEM is not set
diff --git a/configs/esp32-core/nsh/setenv.sh b/configs/esp32-core/nsh/setenv.sh
new file mode 100644
index 0000000000..d67e6fdc7d
--- /dev/null
+++ b/configs/esp32-core/nsh/setenv.sh
@@ -0,0 +1,80 @@
+#!/bin/bash
+# configs/stm32f4discovery/nsh/setenv.sh
+#
+# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved.
+# Author: Gregory Nutt
+#
+# 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.
+#
+
+if [ "$_" = "$0" ] ; then
+ echo "You must source this script, not run it!" 1>&2
+ exit 1
+fi
+
+WD=`pwd`
+if [ ! -x "setenv.sh" ]; then
+ echo "This script must be executed from the top-level NuttX build directory"
+ exit 1
+fi
+
+if [ -z "${PATH_ORIG}" ]; then
+ export PATH_ORIG="${PATH}"
+fi
+
+# This is the Cygwin path to the location where I installed the RIDE
+# toolchain under windows. You will also have to edit this if you install
+# the RIDE toolchain in any other location
+#export TOOLCHAIN_BIN="/cygdrive/c/Program Files (x86)/Raisonance/Ride/arm-gcc/bin"
+
+# This is the Cygwin path to the location where I installed the CodeSourcery
+# toolchain under windows. You will also have to edit this if you install
+# the CodeSourcery toolchain in any other location
+export TOOLCHAIN_BIN="/cygdrive/c/Program Files (x86)/CodeSourcery/Sourcery G++ Lite/bin"
+#export TOOLCHAIN_BIN="/cygdrive/c/Users/MyName/MentorGraphics/Sourcery_CodeBench_Lite_for_ARM_EABI/bin"
+
+# This is the location where I installed the ARM "GNU Tools for ARM Embedded Processors"
+# You can this free toolchain here https://launchpad.net/gcc-arm-embedded
+#export TOOLCHAIN_BIN="/cygdrive/c/Program Files (x86)/GNU Tools ARM Embedded/4.9 2015q2/bin"
+
+# These are the Cygwin paths to the locations where I installed the Atollic
+# toolchain under windows. You will also have to edit this if you install
+# the Atollic toolchain in any other location. /usr/bin is added before
+# the Atollic bin path because there is are binaries named gcc.exe and g++.exe
+# at those locations as well.
+#export TOOLCHAIN_BIN="/usr/bin:/cygdrive/c/Program Files (x86)/Atollic/TrueSTUDIO for ARM Pro 2.3.0/ARMTools/bin"
+#export TOOLCHAIN_BIN="/usr/bin:/cygdrive/c/Program Files (x86)/Atollic/TrueSTUDIO for STMicroelectronics STM32 Lite 2.3.0/ARMTools/bin"
+
+# This is the Cygwin path to the location where I build the buildroot
+# toolchain.
+#export TOOLCHAIN_BIN="${WD}/../buildroot/build_arm_nofpu/staging_dir/bin"
+
+# Add the path to the toolchain to the PATH variable
+export PATH="${TOOLCHAIN_BIN}:/sbin:/usr/sbin:${PATH_ORIG}"
+
+echo "PATH : ${PATH}"
--
GitLab
From 43c46fd34c12615221bbca1cb615d1c976a3d1b6 Mon Sep 17 00:00:00 2001
From: Gregory Nutt
Date: Thu, 13 Oct 2016 14:40:43 -0600
Subject: [PATCH 060/734] ESP32 Core: Add a dummy Toolchain.defs. Fix some
cloning errors left in the NSH configuration.
---
arch/xtensa/src/lx6/Toolchain.defs | 36 ++++++++++++++++++++++++++++++
configs/esp32-core/nsh/Make.defs | 15 +++++--------
configs/esp32-core/nsh/setenv.sh | 31 ++++---------------------
tools/sethost.sh | 0
4 files changed, 45 insertions(+), 37 deletions(-)
create mode 100644 arch/xtensa/src/lx6/Toolchain.defs
mode change 100644 => 100755 tools/sethost.sh
diff --git a/arch/xtensa/src/lx6/Toolchain.defs b/arch/xtensa/src/lx6/Toolchain.defs
new file mode 100644
index 0000000000..e58071c20d
--- /dev/null
+++ b/arch/xtensa/src/lx6/Toolchain.defs
@@ -0,0 +1,36 @@
+############################################################################
+# arch/xtensa/src/lx6/Toolchain.defs
+#
+# Copyright (C) 2016 Gregory Nutt. All rights reserved.
+# Author: Gregory Nutt
+#
+# 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.
+#
+############################################################################
+
+CROSSDEV = xtensa-esp32-
diff --git a/configs/esp32-core/nsh/Make.defs b/configs/esp32-core/nsh/Make.defs
index 02251501c8..75a3287f6e 100644
--- a/configs/esp32-core/nsh/Make.defs
+++ b/configs/esp32-core/nsh/Make.defs
@@ -1,7 +1,7 @@
############################################################################
-# configs/stm32f4discovery/nsh/Make.defs
+# configs/esp32-core/nsh/Make.defs
#
-# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved.
+# Copyright (C) 2016 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt
#
# Redistribution and use in source and binary forms, with or without
@@ -35,7 +35,7 @@
include ${TOPDIR}/.config
include ${TOPDIR}/tools/Config.mk
-include ${TOPDIR}/arch/arm/src/armv7-m/Toolchain.defs
+include ${TOPDIR}/arch/xtensa/src/lx6/Toolchain.defs
LDSCRIPT = ld.script
@@ -64,9 +64,6 @@ 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
@@ -80,7 +77,7 @@ 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
+ARCHPICFLAGS = -fpic
CFLAGS = $(ARCHCFLAGS) $(ARCHWARNINGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) $(ARCHDEFINES) $(EXTRADEFINES) -pipe
CPICFLAGS = $(ARCHPICFLAGS) $(CFLAGS)
@@ -98,9 +95,7 @@ OBJEXT = .o
LIBEXT = .a
EXEEXT =
-ifneq ($(CROSSDEV),arm-nuttx-elf-)
- LDFLAGS += -nostartfiles -nodefaultlibs
-endif
+LDFLAGS += -nostartfiles -nodefaultlibs
ifeq ($(CONFIG_DEBUG_SYMBOLS),y)
LDFLAGS += -g
endif
diff --git a/configs/esp32-core/nsh/setenv.sh b/configs/esp32-core/nsh/setenv.sh
index d67e6fdc7d..dedaec8923 100644
--- a/configs/esp32-core/nsh/setenv.sh
+++ b/configs/esp32-core/nsh/setenv.sh
@@ -1,5 +1,5 @@
#!/bin/bash
-# configs/stm32f4discovery/nsh/setenv.sh
+# configs/esp32-core/nsh/setenv.sh
#
# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt
@@ -47,32 +47,9 @@ if [ -z "${PATH_ORIG}" ]; then
export PATH_ORIG="${PATH}"
fi
-# This is the Cygwin path to the location where I installed the RIDE
-# toolchain under windows. You will also have to edit this if you install
-# the RIDE toolchain in any other location
-#export TOOLCHAIN_BIN="/cygdrive/c/Program Files (x86)/Raisonance/Ride/arm-gcc/bin"
-
-# This is the Cygwin path to the location where I installed the CodeSourcery
-# toolchain under windows. You will also have to edit this if you install
-# the CodeSourcery toolchain in any other location
-export TOOLCHAIN_BIN="/cygdrive/c/Program Files (x86)/CodeSourcery/Sourcery G++ Lite/bin"
-#export TOOLCHAIN_BIN="/cygdrive/c/Users/MyName/MentorGraphics/Sourcery_CodeBench_Lite_for_ARM_EABI/bin"
-
-# This is the location where I installed the ARM "GNU Tools for ARM Embedded Processors"
-# You can this free toolchain here https://launchpad.net/gcc-arm-embedded
-#export TOOLCHAIN_BIN="/cygdrive/c/Program Files (x86)/GNU Tools ARM Embedded/4.9 2015q2/bin"
-
-# These are the Cygwin paths to the locations where I installed the Atollic
-# toolchain under windows. You will also have to edit this if you install
-# the Atollic toolchain in any other location. /usr/bin is added before
-# the Atollic bin path because there is are binaries named gcc.exe and g++.exe
-# at those locations as well.
-#export TOOLCHAIN_BIN="/usr/bin:/cygdrive/c/Program Files (x86)/Atollic/TrueSTUDIO for ARM Pro 2.3.0/ARMTools/bin"
-#export TOOLCHAIN_BIN="/usr/bin:/cygdrive/c/Program Files (x86)/Atollic/TrueSTUDIO for STMicroelectronics STM32 Lite 2.3.0/ARMTools/bin"
-
-# This is the Cygwin path to the location where I build the buildroot
-# toolchain.
-#export TOOLCHAIN_BIN="${WD}/../buildroot/build_arm_nofpu/staging_dir/bin"
+# This is the path to the location where I installed the Expressif crosstools-NG
+# toolchaing
+export TOOLCHAIN_BIN="home/patacongo/projects/nuttx/crosstool-NG/builds/xtensa-esp32-elf/bin"
# Add the path to the toolchain to the PATH variable
export PATH="${TOOLCHAIN_BIN}:/sbin:/usr/sbin:${PATH_ORIG}"
diff --git a/tools/sethost.sh b/tools/sethost.sh
old mode 100644
new mode 100755
--
GitLab
From 04940840b6a8417d90b5c3c970b31e0f7c7888a0 Mon Sep 17 00:00:00 2001
From: Gregory Nutt
Date: Thu, 13 Oct 2016 14:48:29 -0600
Subject: [PATCH 061/734] ESP32 Core: Correct tool-related prefix and path
---
arch/xtensa/include/irq.h | 2 +-
arch/xtensa/include/types.h | 10 +++++-----
arch/xtensa/src/lx6/Toolchain.defs | 2 +-
configs/esp32-core/nsh/setenv.sh | 2 +-
4 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/arch/xtensa/include/irq.h b/arch/xtensa/include/irq.h
index 19739e7944..ed10e3bbb1 100644
--- a/arch/xtensa/include/irq.h
+++ b/arch/xtensa/include/irq.h
@@ -50,7 +50,7 @@
/* Include architecture-specific IRQ definitions */
-#ifdef CONFIG_ARCH_CHIP_LX6
+#ifdef CONFIG_ARCH_FAMILY_LX6
# include
/* Include implementation-specific IRQ definitions (including IRQ numbers) */
diff --git a/arch/xtensa/include/types.h b/arch/xtensa/include/types.h
index aa987ff8bb..ea8e19ff36 100644
--- a/arch/xtensa/include/types.h
+++ b/arch/xtensa/include/types.h
@@ -69,8 +69,8 @@ typedef unsigned char _uint8_t;
typedef signed short _int16_t;
typedef unsigned short _uint16_t;
-typedef signed int _int32_t;
-typedef unsigned int _uint32_t;
+typedef signed long _int32_t;
+typedef unsigned long _uint32_t;
typedef signed long long _int64_t;
typedef unsigned long long _uint64_t;
@@ -78,12 +78,12 @@ typedef unsigned long long _uint64_t;
/* A pointer is 4 bytes */
-typedef signed int _intptr_t;
-typedef unsigned int _uintptr_t;
+typedef signed long _intptr_t;
+typedef unsigned long _uintptr_t;
/* This is the size of the interrupt state save returned by up_irq_save(). */
-typedef unsigned int irqstate_t;
+typedef unsigned long irqstate_t;
#endif /* __ASSEMBLY__ */
diff --git a/arch/xtensa/src/lx6/Toolchain.defs b/arch/xtensa/src/lx6/Toolchain.defs
index e58071c20d..b18659fe55 100644
--- a/arch/xtensa/src/lx6/Toolchain.defs
+++ b/arch/xtensa/src/lx6/Toolchain.defs
@@ -33,4 +33,4 @@
#
############################################################################
-CROSSDEV = xtensa-esp32-
+CROSSDEV = xtensa-esp32-elf-
diff --git a/configs/esp32-core/nsh/setenv.sh b/configs/esp32-core/nsh/setenv.sh
index dedaec8923..3c57c18b55 100644
--- a/configs/esp32-core/nsh/setenv.sh
+++ b/configs/esp32-core/nsh/setenv.sh
@@ -49,7 +49,7 @@ fi
# This is the path to the location where I installed the Expressif crosstools-NG
# toolchaing
-export TOOLCHAIN_BIN="home/patacongo/projects/nuttx/crosstool-NG/builds/xtensa-esp32-elf/bin"
+export TOOLCHAIN_BIN="/home/patacongo/projects/nuttx/crosstool-NG/builds/xtensa-esp32-elf/bin"
# Add the path to the toolchain to the PATH variable
export PATH="${TOOLCHAIN_BIN}:/sbin:/usr/sbin:${PATH_ORIG}"
--
GitLab
From 1c383b665177814d49459f76092c728d6cb58295 Mon Sep 17 00:00:00 2001
From: Gregory Nutt
Date: Thu, 13 Oct 2016 16:29:54 -0600
Subject: [PATCH 062/734] Update README
---
configs/esp32-core/README.txt | 100 ++++++++++++++++++++--------------
1 file changed, 59 insertions(+), 41 deletions(-)
diff --git a/configs/esp32-core/README.txt b/configs/esp32-core/README.txt
index 84fd259b58..984d16f16a 100644
--- a/configs/esp32-core/README.txt
+++ b/configs/esp32-core/README.txt
@@ -1,41 +1,59 @@
-README for the Expressif ESP32 Core board (V2)
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-
- The ESP32 is a dual-core system from Expressif with two Harvard
- architecture Xtensa LX6 CPUs. All embedded memory, external memory and
- peripherals are located on the data bus and/or the instruction bus of
- these CPUs. With some minor exceptions, the address mapping of two CPUs
- is symmetric, meaning they use the same addresses to access the same
- memory. Multiple peripherals in the system can access embedded memory via
- DMA.
-
- The two CPUs are named "PRO_CPU" and "APP_CPU" (for "protocol" and
- "application"), however for most purposes the two CPUs are
- interchangeable.
-
- Features:
-
- * Address Space
- - Symmetric address mapping
- - 4 GB (32-bit) address space for both data bus and instruction bus
- - 1296 KB embedded memory address space
- - 19704 KB external memory address space
- - 512 KB peripheral address space
- - Some embedded and external memory regions can be accessed by either
- data bus or instruction bus
- - 328 KB DMA address space
- * Embedded Memory
- - 448 KB Internal ROM
- - 520 KB Internal SRAM
- - 8 KB RTC FAST Memory
- - 8 KB RTC SLOW Memory
- * External Memory
- Off-chip SPI memory can be mapped into the available address space as
- external memory. Parts of the embedded memory can be used as transparent
- cache for this external memory.
- - Supports up to 16 MB off-Chip SPI Flash.
- - Supports up to 8 MB off-Chip SPI SRAM.
- * Peripherals
- - 41 peripherals
- * DMA
- - 13 modules are capable of DMA operation
\ No newline at end of file
+README for the Expressif ESP32 Core board (V2)
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+ The ESP32 is a dual-core system from Expressif with two Harvard
+ architecture Xtensa LX6 CPUs. All embedded memory, external memory and
+ peripherals are located on the data bus and/or the instruction bus of
+ these CPUs. With some minor exceptions, the address mapping of two CPUs
+ is symmetric, meaning they use the same addresses to access the same
+ memory. Multiple peripherals in the system can access embedded memory via
+ DMA.
+
+ The two CPUs are named "PRO_CPU" and "APP_CPU" (for "protocol" and
+ "application"), however for most purposes the two CPUs are
+ interchangeable.
+
+ Features:
+
+ * Address Space
+ - Symmetric address mapping
+ - 4 GB (32-bit) address space for both data bus and instruction bus
+ - 1296 KB embedded memory address space
+ - 19704 KB external memory address space
+ - 512 KB peripheral address space
+ - Some embedded and external memory regions can be accessed by either
+ data bus or instruction bus
+ - 328 KB DMA address space
+ * Embedded Memory
+ - 448 KB Internal ROM
+ - 520 KB Internal SRAM
+ - 8 KB RTC FAST Memory
+ - 8 KB RTC SLOW Memory
+ * External Memory
+ Off-chip SPI memory can be mapped into the available address space as
+ external memory. Parts of the embedded memory can be used as transparent
+ cache for this external memory.
+ - Supports up to 16 MB off-Chip SPI Flash.
+ - Supports up to 8 MB off-Chip SPI SRAM.
+ * Peripherals
+ - 41 peripherals
+ * DMA
+ - 13 modules are capable of DMA operation
+
+ESP32 Toolchain
+===============
+
+ The steps to build toolchain with crosstool-NG on Linux are as follows:
+
+ git clone -b xtensa-1.22.x https://github.com/espressif/crosstool-NG.git
+ cd crosstool-NG
+ ./bootstrap && ./configure --prefix=$PWD && make install
+ ./ct-ng xtensa-esp32-elf
+ ./ct-ng build
+ chmod -R u+w builds/xtensa-esp32-elf
+
+ These steps are given in setup guide in ESP-IDF repository:
+ https://github.com/espressif/esp-idf/blob/master/docs/linux-setup.rst#alternative-step-1-compile-the-toolchain-from-source-using-crosstool-ng
+
+ NOTE: the xtensa-esp32-elf configuration is only available in the
+ xtensa-1.22.x branch.
--
GitLab
From c078573677de9af2889277ad5b6ba4465e442689 Mon Sep 17 00:00:00 2001
From: Gregory Nutt
Date: Thu, 13 Oct 2016 16:29:50 -0600
Subject: [PATCH 063/734] Add some .gitignore files
---
arch/xtensa/include/.gitignore | 3 +++
arch/xtensa/src/.gitignore | 4 ++++
2 files changed, 7 insertions(+)
create mode 100644 arch/xtensa/include/.gitignore
create mode 100644 arch/xtensa/src/.gitignore
diff --git a/arch/xtensa/include/.gitignore b/arch/xtensa/include/.gitignore
new file mode 100644
index 0000000000..e6460c4a67
--- /dev/null
+++ b/arch/xtensa/include/.gitignore
@@ -0,0 +1,3 @@
+/board
+/chip
+
diff --git a/arch/xtensa/src/.gitignore b/arch/xtensa/src/.gitignore
new file mode 100644
index 0000000000..8d209f76a4
--- /dev/null
+++ b/arch/xtensa/src/.gitignore
@@ -0,0 +1,4 @@
+/.depend
+/Make.dep
+/board
+/chip
--
GitLab
From 64b020f1a8fa3fbd1490fad45a3b370b2ad8f727 Mon Sep 17 00:00:00 2001
From: neilh10
Date: Thu, 13 Oct 2016 19:42:39 -0700
Subject: [PATCH 064/734] Add UID Unique ID
---
arch/arm/src/kinetis/Make.defs | 2 +-
arch/arm/src/kinetis/kinetis_uid.c | 68 +++++++++++++++++++++++
arch/arm/src/kinetis/kinetis_uid.h | 49 +++++++++++++++++
configs/freedom-k64f/README.txt | 2 +
configs/freedom-k64f/src/Makefile | 3 +
configs/freedom-k64f/src/k64_uid.c | 73 +++++++++++++++++++++++++
configs/freedom-k64f/src/k64_userleds.c | 1 +
7 files changed, 197 insertions(+), 1 deletion(-)
create mode 100644 arch/arm/src/kinetis/kinetis_uid.c
create mode 100644 arch/arm/src/kinetis/kinetis_uid.h
create mode 100644 configs/freedom-k64f/src/k64_uid.c
diff --git a/arch/arm/src/kinetis/Make.defs b/arch/arm/src/kinetis/Make.defs
index bb7f54d87b..b2f1046caa 100644
--- a/arch/arm/src/kinetis/Make.defs
+++ b/arch/arm/src/kinetis/Make.defs
@@ -90,7 +90,7 @@ CHIP_ASRCS =
CHIP_CSRCS = kinetis_allocateheap.c kinetis_clockconfig.c
CHIP_CSRCS += kinetis_clrpend.c kinetis_idle.c kinetis_irq.c
CHIP_CSRCS += kinetis_lowputc.c kinetis_pin.c kinetis_pingpio.c
-CHIP_CSRCS += kinetis_serial.c kinetis_start.c kinetis_wdog.c
+CHIP_CSRCS += kinetis_serial.c kinetis_start.c kinetis_uid.c kinetis_wdog.c
CHIP_CSRCS += kinetis_cfmconfig.c
# Configuration-dependent Kinetis files
diff --git a/arch/arm/src/kinetis/kinetis_uid.c b/arch/arm/src/kinetis/kinetis_uid.c
new file mode 100644
index 0000000000..3693b3507b
--- /dev/null
+++ b/arch/arm/src/kinetis/kinetis_uid.c
@@ -0,0 +1,68 @@
+/************************************************************************************
+ * arch/arm/src/kinetis/kinetis_uid.c
+ *
+ * Copyright (C) 2016 Neil Hancock. All rights reserved.
+ *
+ * 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
+
+#include
+#include
+#include "kinetis_uid.h"
+
+#ifdef CONFIG_BOARDCTL_UNIQUEID
+
+/************************************************************************************
+ * Public Functions
+ ************************************************************************************/
+
+void kinetis_get_uniqueid(uint8_t *uniqueid)
+{
+ int i;
+ uint32_t *unique_u32;
+ unique_u32 = (uint32_t *)uniqueid;
+
+ /*
+ * Copy into buffer LS first, which in the Kinetis is the highest memory
+ */
+
+ for (i = 0; i < (KINETIS_UID_SIZE/sizeof(uint32_t)); i++)
+ {
+ unique_u32[i] = *((uint32_t*)(KINETIS_SIM_UIDL)-i);
+ }
+}
+
+#endif /* CONFIG_BOARDCTL_UNIQUEID */
+
diff --git a/arch/arm/src/kinetis/kinetis_uid.h b/arch/arm/src/kinetis/kinetis_uid.h
new file mode 100644
index 0000000000..84620f53e5
--- /dev/null
+++ b/arch/arm/src/kinetis/kinetis_uid.h
@@ -0,0 +1,49 @@
+/************************************************************************************
+ * arch/arm/src/kinetis/kinetis_uid.h
+ *
+ * Copyright (C) 2016 Neil Hancock. All rights reserved.
+ *
+ * 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.
+ *
+ ************************************************************************************/
+
+#ifndef __ARCH_ARM_SRC_KINETIS_UID_H
+#define __ARCH_ARM_SRC_KINETIS_UID_H
+
+/************************************************************************************
+ * Included Files
+ ************************************************************************************/
+
+#include
+
+/************************************************************************************
+ * Public Function Prototypes
+ ************************************************************************************/
+#define KINETIS_UID_SIZE 16
+void kinetis_get_uniqueid(uint8_t *uniqueid);
+#endif /* __ARCH_ARM_SRC_KINETIS_UID_H */
diff --git a/configs/freedom-k64f/README.txt b/configs/freedom-k64f/README.txt
index 0b80b603d1..2c6666a7e6 100644
--- a/configs/freedom-k64f/README.txt
+++ b/configs/freedom-k64f/README.txt
@@ -56,6 +56,8 @@ OpenSDAv2
HDK-compatible debug interface preloaded with the open-source CMSIS-DAP
Interface firmware (mbed interface) for rapid prototyping and product
development.
+
+ To use set raw binary output for nuttx.bin
Serial Console
==============
diff --git a/configs/freedom-k64f/src/Makefile b/configs/freedom-k64f/src/Makefile
index 8c533ec849..7da96029aa 100644
--- a/configs/freedom-k64f/src/Makefile
+++ b/configs/freedom-k64f/src/Makefile
@@ -73,4 +73,7 @@ ifeq ($(CONFIG_PWM),y)
CSRCS += k64_pwm.c
endif
+ifeq ($(CONFIG_BOARDCTL_UNIQUEID),y)
+CSRCS += k64_uid.c
+endif
include $(TOPDIR)/configs/Board.mk
diff --git a/configs/freedom-k64f/src/k64_uid.c b/configs/freedom-k64f/src/k64_uid.c
new file mode 100644
index 0000000000..545de899c0
--- /dev/null
+++ b/configs/freedom-k64f/src/k64_uid.c
@@ -0,0 +1,73 @@
+/************************************************************************************
+ * configs/freedom-k64/src/kinetis_uid.c
+ *
+ * Copyright (C) 2016 Neil Hancock. All rights reserved.
+ *
+ * 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
+
+#include
+#include
+#include
+#include "kinetis_uid.h"
+
+#include
+
+/************************************************************************************
+ * Pre-processor Definitions
+ ************************************************************************************/
+
+#ifndef OK
+# define OK 0
+#endif
+
+/************************************************************************************
+ * Public Functions
+ ************************************************************************************/
+
+#if defined(CONFIG_BOARDCTL_UNIQUEID)
+
+int board_uniqueid(FAR uint8_t *uniqueid)
+{
+ if (uniqueid == 0)
+ {
+ return -EINVAL;
+ }
+
+ kinetis_get_uniqueid(uniqueid);
+ return OK;
+}
+
+#endif
diff --git a/configs/freedom-k64f/src/k64_userleds.c b/configs/freedom-k64f/src/k64_userleds.c
index 48a396a3ce..e75a2abb8e 100644
--- a/configs/freedom-k64f/src/k64_userleds.c
+++ b/configs/freedom-k64f/src/k64_userleds.c
@@ -107,3 +107,4 @@ void board_userled_all(uint8_t ledset)
kinetis_gpiowrite(GPIO_LED_G, (ledset & BOARD_LED_G_BIT) == 0);
kinetis_gpiowrite(GPIO_LED_B, (ledset & BOARD_LED_B_BIT) == 0);
}
+#endif
--
GitLab
From 6dca9a439033a311685260e008176cce8730f72b Mon Sep 17 00:00:00 2001
From: neilh10
Date: Thu, 13 Oct 2016 19:50:35 -0700
Subject: [PATCH 065/734] Add UID Unique ID
---
arch/arm/src/kinetis/kinetis_uid.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/arm/src/kinetis/kinetis_uid.c b/arch/arm/src/kinetis/kinetis_uid.c
index 3693b3507b..54a98d08ce 100644
--- a/arch/arm/src/kinetis/kinetis_uid.c
+++ b/arch/arm/src/kinetis/kinetis_uid.c
@@ -36,7 +36,7 @@
* Included Files
************************************************************************************/
-//#include
+#include
#include
#include
--
GitLab
From f7e0a36f55e5a3887cca2ac6bec82e7dba0fdd67 Mon Sep 17 00:00:00 2001
From: Sebastien Lorquet
Date: Fri, 14 Oct 2016 12:50:45 +0200
Subject: [PATCH 066/734] Multiple stm32l4 timer fixes: - too many parentheses
when calculating max chan count (???) - channel 4 does not have a
complementary output
---
arch/arm/src/stm32l4/stm32l4_pwm.c | 4 ++--
arch/arm/src/stm32l4/stm32l4_pwm.h | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/arch/arm/src/stm32l4/stm32l4_pwm.c b/arch/arm/src/stm32l4/stm32l4_pwm.c
index d3478ea0df..7d23582b17 100644
--- a/arch/arm/src/stm32l4/stm32l4_pwm.c
+++ b/arch/arm/src/stm32l4/stm32l4_pwm.c
@@ -1206,7 +1206,7 @@ static int stm32l4pwm_timer(FAR struct stm32l4_pwmtimer_s *priv,
*/
ccer &= ~(ATIM_CCER_CC1NE | ATIM_CCER_CC1NP | ATIM_CCER_CC2NE | ATIM_CCER_CC2NP |
- ATIM_CCER_CC3NE | ATIM_CCER_CC3NP | ATIM_CCER_CC4NP);
+ ATIM_CCER_CC3NE | ATIM_CCER_CC3NP);
/* Reset the output compare and output compare N IDLE State */
@@ -1225,7 +1225,7 @@ static int stm32l4pwm_timer(FAR struct stm32l4_pwmtimer_s *priv,
else
#endif
{
- ccer &= ~(GTIM_CCER_CC1NP | GTIM_CCER_CC2NP | GTIM_CCER_CC3NP | ATIM_CCER_CC4NP);
+ ccer &= ~(GTIM_CCER_CC1NP | GTIM_CCER_CC2NP | GTIM_CCER_CC3NP);
}
/* Save the modified register values */
diff --git a/arch/arm/src/stm32l4/stm32l4_pwm.h b/arch/arm/src/stm32l4/stm32l4_pwm.h
index 942aef0cfa..f2b17198c0 100644
--- a/arch/arm/src/stm32l4/stm32l4_pwm.h
+++ b/arch/arm/src/stm32l4/stm32l4_pwm.h
@@ -422,7 +422,7 @@
PWM_MAX(PWM_TIM8_NCHANNELS, \
PWM_MAX(PWM_TIM15_NCHANNELS, \
PWM_MAX(PWM_TIM16_NCHANNELS, \
- PWM_TIM17_NCHANNELS))))))))))))))
+ PWM_TIM17_NCHANNELS))))))))
#else
--
GitLab
From fb1f424e129010097f54f5635b1f1b74b1e06e59 Mon Sep 17 00:00:00 2001
From: Sebastien Lorquet
Date: Fri, 14 Oct 2016 18:06:11 +0200
Subject: [PATCH 067/734] Support Complementary PWM outputs on STM32L4
---
arch/arm/src/stm32l4/Kconfig | 63 ++++++++++++++++
arch/arm/src/stm32l4/stm32l4_pwm.c | 114 ++++++++++++++++++++++++++---
arch/arm/src/stm32l4/stm32l4_pwm.h | 45 ++++++++++++
3 files changed, 211 insertions(+), 11 deletions(-)
diff --git a/arch/arm/src/stm32l4/Kconfig b/arch/arm/src/stm32l4/Kconfig
index 3ccbfff8af..b6eba519cd 100644
--- a/arch/arm/src/stm32l4/Kconfig
+++ b/arch/arm/src/stm32l4/Kconfig
@@ -731,6 +731,13 @@ config STM32L4_TIM1_CH1OUT
---help---
Enables channel 1 output.
+config STM32L4_TIM1_CH1NOUT
+ bool "TIM1 Channel 1 Complementary Output"
+ default n
+ depends on STM32L4_TIM1_CH1OUT
+ ---help---
+ Enables channel 1 complementary output.
+
endif # STM32L4_TIM1_CHANNEL1
config STM32L4_TIM1_CHANNEL2
@@ -754,6 +761,13 @@ config STM32L4_TIM1_CH2OUT
---help---
Enables channel 2 output.
+config STM32L4_TIM1_CH2NOUT
+ bool "TIM1 Channel 2 Complemenrary Output"
+ default n
+ depends on STM32L4_TIM1_CH2OUT
+ ---help---
+ Enables channel 2 complementary output.
+
endif # STM32L4_TIM1_CHANNEL2
config STM32L4_TIM1_CHANNEL3
@@ -777,6 +791,13 @@ config STM32L4_TIM1_CH3OUT
---help---
Enables channel 3 output.
+config STM32L4_TIM1_CH3NOUT
+ bool "TIM1 Channel 3 Complementary Output"
+ default n
+ depends on STM32L4_TIM1_CH3OUT
+ ---help---
+ Enables channel 3 complementary output.
+
endif # STM32L4_TIM1_CHANNEL3
config STM32L4_TIM1_CHANNEL4
@@ -1426,6 +1447,13 @@ config STM32L4_TIM8_CH1OUT
---help---
Enables channel 1 output.
+config STM32L4_TIM8_CH1NOUT
+ bool "TIM8 Channel 1 Complementary Output"
+ default n
+ depends on STM32L4_TIM8_CH1OUT
+ ---help---
+ Enables channel 1 complementary output.
+
endif # STM32L4_TIM8_CHANNEL1
config STM32L4_TIM8_CHANNEL2
@@ -1449,6 +1477,13 @@ config STM32L4_TIM8_CH2OUT
---help---
Enables channel 2 output.
+config STM32L4_TIM8_CH2NOUT
+ bool "TIM8 Channel 2 Complementary Output"
+ default n
+ depends on STM32L4_TIM8_CH2OUT
+ ---help---
+ Enables channel 2 complementary output.
+
endif # STM32L4_TIM8_CHANNEL2
config STM32L4_TIM8_CHANNEL3
@@ -1472,6 +1507,13 @@ config STM32L4_TIM8_CH3OUT
---help---
Enables channel 3 output.
+config STM32L4_TIM8_CH3NOUT
+ bool "TIM8 Channel 3 Complementary Output"
+ default n
+ depends on STM32L4_TIM8_CH3OUT
+ ---help---
+ Enables channel 3 complementary output.
+
endif # STM32L4_TIM8_CHANNEL3
config STM32L4_TIM8_CHANNEL4
@@ -1557,6 +1599,13 @@ config STM32L4_TIM15_CH1OUT
---help---
Enables channel 1 output.
+config STM32L4_TIM15_CH1NOUT
+ bool "TIM15 Channel 1 Complementary Output"
+ default n
+ depends on STM32L4_TIM15_CH1OUT
+ ---help---
+ Enables channel 1 complementary output.
+
endif # STM32L4_TIM15_CHANNEL1
config STM32L4_TIM15_CHANNEL2
@@ -1642,6 +1691,13 @@ config STM32L4_TIM16_CH1OUT
---help---
Enables channel 1 output.
+config STM32L4_TIM16_CH1NOUT
+ bool "TIM16 Channel 1 Complementary Output"
+ default n
+ depends on STM32L4_TIM16_CH1OUT
+ ---help---
+ Enables channel 1 complementary output.
+
endif # STM32L4_TIM16_CHANNEL1
endif # STM32L4_PWM_MULTICHAN
@@ -1704,6 +1760,13 @@ config STM32L4_TIM17_CH1OUT
---help---
Enables channel 1 output.
+config STM32L4_TIM17_CH1NOUT
+ bool "TIM17 Channel 1 Complementary Output"
+ default n
+ depends on STM32L4_TIM17_CH1OUT
+ ---help---
+ Enables channel 1 complementary output.
+
endif # STM32L4_TIM17_CHANNEL1
endif # STM32L4_PWM_MULTICHAN
diff --git a/arch/arm/src/stm32l4/stm32l4_pwm.c b/arch/arm/src/stm32l4/stm32l4_pwm.c
index 7d23582b17..f45e4c1384 100644
--- a/arch/arm/src/stm32l4/stm32l4_pwm.c
+++ b/arch/arm/src/stm32l4/stm32l4_pwm.c
@@ -128,6 +128,7 @@ struct stm32l4_pwmchan_s
uint8_t channel; /* Timer output channel: {1,..4} */
uint32_t pincfg; /* Output pin configuration */
enum stm32l4_chanmode_e mode;
+ uint32_t npincfg; /* Complementary output pin configuration (only TIM1/8 CH1-3)*/
};
/* This structure represents the state of one PWM timer */
@@ -229,6 +230,7 @@ static struct stm32l4_pwmtimer_s g_pwm1dev =
.channel = 1,
.pincfg = PWM_TIM1_CH1CFG,
.mode = CONFIG_STM32L4_TIM1_CH1MODE,
+ .npincfg = PWM_TIM1_CH1NCFG,
},
#endif
#ifdef CONFIG_STM32L4_TIM1_CHANNEL2
@@ -236,6 +238,7 @@ static struct stm32l4_pwmtimer_s g_pwm1dev =
.channel = 2,
.pincfg = PWM_TIM1_CH2CFG,
.mode = CONFIG_STM32L4_TIM1_CH2MODE,
+ .npincfg = PWM_TIM1_CH2NCFG,
},
#endif
#ifdef CONFIG_STM32L4_TIM1_CHANNEL3
@@ -243,6 +246,7 @@ static struct stm32l4_pwmtimer_s g_pwm1dev =
.channel = 3,
.pincfg = PWM_TIM1_CH3CFG,
.mode = CONFIG_STM32L4_TIM1_CH3MODE,
+ .npincfg = PWM_TIM1_CH3NCFG,
},
#endif
#ifdef CONFIG_STM32L4_TIM1_CHANNEL4
@@ -250,6 +254,7 @@ static struct stm32l4_pwmtimer_s g_pwm1dev =
.channel = 4,
.pincfg = PWM_TIM1_CH4CFG,
.mode = CONFIG_STM32L4_TIM1_CH4MODE,
+ .npincfg = 0,
},
#endif
},
@@ -275,6 +280,7 @@ static struct stm32l4_pwmtimer_s g_pwm2dev =
.channel = 1,
.pincfg = PWM_TIM2_CH1CFG,
.mode = CONFIG_STM32L4_TIM2_CH1MODE,
+ .npincfg = 0,
},
#endif
#ifdef CONFIG_STM32L4_TIM2_CHANNEL2
@@ -282,6 +288,7 @@ static struct stm32l4_pwmtimer_s g_pwm2dev =
.channel = 2,
.pincfg = PWM_TIM2_CH2CFG,
.mode = CONFIG_STM32L4_TIM2_CH2MODE,
+ .npincfg = 0,
},
#endif
#ifdef CONFIG_STM32L4_TIM2_CHANNEL3
@@ -289,6 +296,7 @@ static struct stm32l4_pwmtimer_s g_pwm2dev =
.channel = 3,
.pincfg = PWM_TIM2_CH3CFG,
.mode = CONFIG_STM32L4_TIM2_CH3MODE,
+ .npincfg = 0,
},
#endif
#ifdef CONFIG_STM32L4_TIM2_CHANNEL4
@@ -296,6 +304,7 @@ static struct stm32l4_pwmtimer_s g_pwm2dev =
.channel = 4,
.pincfg = PWM_TIM2_CH4CFG,
.mode = CONFIG_STM32L4_TIM2_CH4MODE,
+ .npincfg = 0,
},
#endif
},
@@ -321,6 +330,7 @@ static struct stm32l4_pwmtimer_s g_pwm3dev =
.channel = 1,
.pincfg = PWM_TIM3_CH1CFG,
.mode = CONFIG_STM32L4_TIM3_CH1MODE,
+ .npincfg = 0,
},
#endif
#ifdef CONFIG_STM32L4_TIM3_CHANNEL2
@@ -328,6 +338,7 @@ static struct stm32l4_pwmtimer_s g_pwm3dev =
.channel = 2,
.pincfg = PWM_TIM3_CH2CFG,
.mode = CONFIG_STM32L4_TIM3_CH2MODE,
+ .npincfg = 0,
},
#endif
#ifdef CONFIG_STM32L4_TIM3_CHANNEL3
@@ -335,6 +346,7 @@ static struct stm32l4_pwmtimer_s g_pwm3dev =
.channel = 3,
.pincfg = PWM_TIM3_CH3CFG,
.mode = CONFIG_STM32L4_TIM3_CH3MODE,
+ .npincfg = 0,
},
#endif
#ifdef CONFIG_STM32L4_TIM3_CHANNEL4
@@ -342,6 +354,7 @@ static struct stm32l4_pwmtimer_s g_pwm3dev =
.channel = 4,
.pincfg = PWM_TIM3_CH4CFG,
.mode = CONFIG_STM32L4_TIM3_CH4MODE,
+ .npincfg = 0,
},
#endif
},
@@ -367,6 +380,7 @@ static struct stm32l4_pwmtimer_s g_pwm4dev =
.channel = 1,
.pincfg = PWM_TIM4_CH1CFG,
.mode = CONFIG_STM32L4_TIM4_CH1MODE,
+ .npincfg = 0,
},
#endif
#ifdef CONFIG_STM32L4_TIM4_CHANNEL2
@@ -374,6 +388,7 @@ static struct stm32l4_pwmtimer_s g_pwm4dev =
.channel = 2,
.pincfg = PWM_TIM4_CH2CFG,
.mode = CONFIG_STM32L4_TIM4_CH2MODE,
+ .npincfg = 0,
},
#endif
#ifdef CONFIG_STM32L4_TIM4_CHANNEL3
@@ -381,6 +396,7 @@ static struct stm32l4_pwmtimer_s g_pwm4dev =
.channel = 3,
.pincfg = PWM_TIM4_CH3CFG,
.mode = CONFIG_STM32L4_TIM4_CH3MODE,
+ .npincfg = 0,
},
#endif
#ifdef CONFIG_STM32L4_TIM4_CHANNEL4
@@ -388,6 +404,7 @@ static struct stm32l4_pwmtimer_s g_pwm4dev =
.channel = 4,
.pincfg = PWM_TIM4_CH4CFG,
.mode = CONFIG_STM32L4_TIM4_CH4MODE,
+ .npincfg = 0,
},
#endif
},
@@ -413,6 +430,7 @@ static struct stm32l4_pwmtimer_s g_pwm5dev =
.channel = 1,
.pincfg = PWM_TIM5_CH1CFG,
.mode = CONFIG_STM32L4_TIM5_CH1MODE,
+ .npincfg = 0,
},
#endif
#ifdef CONFIG_STM32L4_TIM5_CHANNEL2
@@ -420,6 +438,7 @@ static struct stm32l4_pwmtimer_s g_pwm5dev =
.channel = 2,
.pincfg = PWM_TIM5_CH2CFG,
.mode = CONFIG_STM32L4_TIM5_CH2MODE,
+ .npincfg = 0,
},
#endif
#ifdef CONFIG_STM32L4_TIM5_CHANNEL3
@@ -427,6 +446,7 @@ static struct stm32l4_pwmtimer_s g_pwm5dev =
.channel = 3,
.pincfg = PWM_TIM5_CH3CFG,
.mode = CONFIG_STM32L4_TIM5_CH3MODE,
+ .npincfg = 0,
},
#endif
#ifdef CONFIG_STM32L4_TIM5_CHANNEL4
@@ -434,6 +454,7 @@ static struct stm32l4_pwmtimer_s g_pwm5dev =
.channel = 4,
.pincfg = PWM_TIM5_CH4CFG,
.mode = CONFIG_STM32L4_TIM5_CH4MODE,
+ .npincfg = 0,
},
#endif
},
@@ -459,6 +480,7 @@ static struct stm32l4_pwmtimer_s g_pwm8dev =
.channel = 1,
.pincfg = PWM_TIM8_CH1CFG,
.mode = CONFIG_STM32L4_TIM8_CH1MODE,
+ .npincfg = PWM_TIM8_CH1NCFG,
},
#endif
#ifdef CONFIG_STM32L4_TIM8_CHANNEL2
@@ -466,6 +488,7 @@ static struct stm32l4_pwmtimer_s g_pwm8dev =
.channel = 2,
.pincfg = PWM_TIM8_CH2CFG,
.mode = CONFIG_STM32L4_TIM8_CH2MODE,
+ .npincfg = PWM_TIM8_CH2NCFG,
},
#endif
#ifdef CONFIG_STM32L4_TIM8_CHANNEL3
@@ -473,6 +496,7 @@ static struct stm32l4_pwmtimer_s g_pwm8dev =
.channel = 3,
.pincfg = PWM_TIM8_CH3CFG,
.mode = CONFIG_STM32L4_TIM8_CH3MODE,
+ .npincfg = PWM_TIM8_CH3NCFG,
},
#endif
#ifdef CONFIG_STM32L4_TIM8_CHANNEL4
@@ -480,6 +504,7 @@ static struct stm32l4_pwmtimer_s g_pwm8dev =
.channel = 4,
.pincfg = PWM_TIM8_CH4CFG,
.mode = CONFIG_STM32L4_TIM8_CH4MODE,
+ .npincfg = 0,
},
#endif
},
@@ -505,6 +530,7 @@ static struct stm32l4_pwmtimer_s g_pwm15dev =
.channel = 1,
.pincfg = PWM_TIM15_CH1CFG,
.mode = CONFIG_STM32L4_TIM15_CH1MODE,
+ .npincfg = PWM_TIM15_CH1NCFG,
},
#endif
#ifdef CONFIG_STM32L4_TIM15_CHANNEL2
@@ -512,6 +538,7 @@ static struct stm32l4_pwmtimer_s g_pwm15dev =
.channel = 2,
.pincfg = PWM_TIM15_CH2CFG,
.mode = CONFIG_STM32L4_TIM15_CH2MODE,
+ .npincfg = 0,
},
#endif
},
@@ -537,6 +564,7 @@ static struct stm32l4_pwmtimer_s g_pwm16dev =
.channel = 1,
.pincfg = PWM_TIM16_CH1CFG,
.mode = CONFIG_STM32L4_TIM16_CH1MODE,
+ .npincfg = PWM_TIM16_CH1NCFG,
},
#endif
},
@@ -562,6 +590,7 @@ static struct stm32l4_pwmtimer_s g_pwm17dev =
.channel = 1,
.pincfg = PWM_TIM17_CH1CFG,
.mode = CONFIG_STM32L4_TIM17_CH1MODE,
+ .npincfg = PWM_TIM17_CH1NCFG,
},
#endif
},
@@ -737,6 +766,7 @@ static int stm32l4pwm_timer(FAR struct stm32l4_pwmtimer_s *priv,
/* New timer register bit settings */
uint16_t ccenable;
+ uint16_t ccnenable;
uint32_t ocmode1;
uint32_t ocmode2;
@@ -967,6 +997,7 @@ static int stm32l4pwm_timer(FAR struct stm32l4_pwmtimer_s *priv,
/* Handle channel specific setup */
ccenable = 0;
+ ccnenable = 0;
ocmode1 = 0;
ocmode2 = 0;
@@ -976,6 +1007,7 @@ static int stm32l4pwm_timer(FAR struct stm32l4_pwmtimer_s *priv,
{
ub16_t duty;
uint32_t chanmode;
+ uint32_t compout; /* Complementary output config */
bool ocmbit = false;
uint8_t channel;
#ifdef CONFIG_PWM_MULTICHAN
@@ -1001,6 +1033,7 @@ static int stm32l4pwm_timer(FAR struct stm32l4_pwmtimer_s *priv,
if (priv->channels[j].channel == channel)
{
mode = priv->channels[j].mode;
+ compout = priv->channels[j].npincfg;
break;
}
}
@@ -1014,6 +1047,7 @@ static int stm32l4pwm_timer(FAR struct stm32l4_pwmtimer_s *priv,
duty = info->duty;
channel = priv->channels[0].channel;
mode = priv->channels[0].mode;
+ compout = priv->channels[0].npincfg;
#endif
/* Duty cycle:
@@ -1068,6 +1102,13 @@ static int stm32l4pwm_timer(FAR struct stm32l4_pwmtimer_s *priv,
ccenable |= ATIM_CCER_CC1E;
+ /* Conditionnaly enable the complementary output */
+
+ if(compout)
+ {
+ ccnenable |= ATIM_CCER_CC1NE;
+ }
+
/* Set the CCMR1 mode values (leave CCMR2 zero) */
ocmode1 |= (ATIM_CCMR_CCS_CCOUT << ATIM_CCMR1_CC1S_SHIFT) |
@@ -1091,6 +1132,13 @@ static int stm32l4pwm_timer(FAR struct stm32l4_pwmtimer_s *priv,
ccenable |= ATIM_CCER_CC2E;
+ /* Conditionnaly enable the complementary output */
+
+ if(compout)
+ {
+ ccnenable |= ATIM_CCER_CC2NE;
+ }
+
/* Set the CCMR1 mode values (leave CCMR2 zero) */
ocmode1 |= (ATIM_CCMR_CCS_CCOUT << ATIM_CCMR1_CC2S_SHIFT) |
@@ -1114,6 +1162,13 @@ static int stm32l4pwm_timer(FAR struct stm32l4_pwmtimer_s *priv,
ccenable |= ATIM_CCER_CC3E;
+ /* Conditionnaly enable the complementary output */
+
+ if(compout)
+ {
+ ccnenable |= ATIM_CCER_CC3NE;
+ }
+
/* Set the CCMR2 mode values (leave CCMR1 zero) */
ocmode2 |= (ATIM_CCMR_CCS_CCOUT << ATIM_CCMR2_CC3S_SHIFT) |
@@ -1208,6 +1263,8 @@ static int stm32l4pwm_timer(FAR struct stm32l4_pwmtimer_s *priv,
ccer &= ~(ATIM_CCER_CC1NE | ATIM_CCER_CC1NP | ATIM_CCER_CC2NE | ATIM_CCER_CC2NP |
ATIM_CCER_CC3NE | ATIM_CCER_CC3NP);
+ ccer |= ccnenable;
+
/* Reset the output compare and output compare N IDLE State */
cr2 &= ~(ATIM_CR2_OIS1 | ATIM_CR2_OIS1N | ATIM_CR2_OIS2 | ATIM_CR2_OIS2N |
@@ -1223,9 +1280,23 @@ static int stm32l4pwm_timer(FAR struct stm32l4_pwmtimer_s *priv,
stm32l4pwm_putreg(priv, STM32L4_ATIM_BDTR_OFFSET, bdtr);
}
else
+#if defined(CONFIG_STM32L4_TIM15_PWM) || defined(CONFIG_STM32L4_TIM15_PWM) || defined(CONFIG_STM32L4_TIM15_PWM)
+ if (priv->timtype == TIMTYPE_COUNTUP16)
+ {
+
+ /* Reset output N polarity level, output N state, output compare state,
+ * output compare N idle state.
+ */
+
+ ccer &= ~(ATIM_CCER_CC1NE | ATIM_CCER_CC1NP);
+
+ ccer |= ccnenable;
+ }
+ else
+#endif
#endif
{
- ccer &= ~(GTIM_CCER_CC1NP | GTIM_CCER_CC2NP | GTIM_CCER_CC3NP);
+ ccer &= ~(GTIM_CCER_CC1NP | GTIM_CCER_CC2NP | GTIM_CCER_CC3NP); //Not sure why ??
}
/* Save the modified register values */
@@ -1646,14 +1717,24 @@ static int stm32l4pwm_setup(FAR struct pwm_lowerhalf_s *dev)
for (i = 0; i < PWM_NCHANNELS; i++)
{
pincfg = priv->channels[i].pincfg;
- if (pincfg == 0)
+ if (pincfg != 0)
{
- continue;
+ pwminfo("pincfg: %08x\n", pincfg);
+
+ stm32l4_configgpio(pincfg);
}
- pwminfo("pincfg: %08x\n", pincfg);
- stm32l4_configgpio(pincfg);
+ /* Enable complementary channel if available */
+
+ pincfg = priv->channels[i].npincfg;
+ if (pincfg != 0)
+ {
+ pwminfo("npincfg: %08x\n", pincfg);
+
+ stm32l4_configgpio(pincfg);
+ }
+
pwm_dumpgpio(pincfg, "PWM setup");
}
@@ -1697,18 +1778,29 @@ static int stm32l4pwm_shutdown(FAR struct pwm_lowerhalf_s *dev)
for (i = 0; i < PWM_NCHANNELS; i++)
{
pincfg = priv->channels[i].pincfg;
- if (pincfg == 0)
+ if (pincfg != 0)
{
- continue;
+ pwminfo("pincfg: %08x\n", pincfg);
+
+ pincfg &= (GPIO_PORT_MASK | GPIO_PIN_MASK);
+
+ pincfg |= GPIO_INPUT | GPIO_FLOAT;
+
+ stm32l4_configgpio(pincfg);
}
- pwminfo("pincfg: %08x\n", pincfg);
+ pincfg = priv->channels[i].npincfg;
+ if (pincfg != 0)
+ {
+ pwminfo("npincfg: %08x\n", pincfg);
+
+ pincfg &= (GPIO_PORT_MASK | GPIO_PIN_MASK);
- pincfg &= (GPIO_PORT_MASK | GPIO_PIN_MASK);
+ pincfg |= GPIO_INPUT | GPIO_FLOAT;
- pincfg |= GPIO_INPUT | GPIO_FLOAT;
+ stm32l4_configgpio(pincfg);
+ }
- stm32l4_configgpio(pincfg);
}
return OK;
diff --git a/arch/arm/src/stm32l4/stm32l4_pwm.h b/arch/arm/src/stm32l4/stm32l4_pwm.h
index f2b17198c0..b314834520 100644
--- a/arch/arm/src/stm32l4/stm32l4_pwm.h
+++ b/arch/arm/src/stm32l4/stm32l4_pwm.h
@@ -114,6 +114,11 @@
# else
# define PWM_TIM1_CH1CFG 0
# endif
+# ifdef CONFIG_STM32L4_TIM1_CH1NOUT
+# define PWM_TIM1_CH1NCFG GPIO_TIM1_CH1NOUT
+# else
+# define PWM_TIM1_CH1NCFG 0
+# endif
# define PWM_TIM1_CHANNEL1 1
#else
# define PWM_TIM1_CHANNEL1 0
@@ -124,6 +129,11 @@
# else
# define PWM_TIM1_CH2CFG 0
# endif
+# ifdef CONFIG_STM32L4_TIM1_CH2NOUT
+# define PWM_TIM1_CH2NCFG GPIO_TIM1_CH2NOUT
+# else
+# define PWM_TIM1_CH2NCFG 0
+# endif
# define PWM_TIM1_CHANNEL2 1
#else
# define PWM_TIM1_CHANNEL2 0
@@ -134,6 +144,11 @@
# else
# define PWM_TIM1_CH3CFG 0
# endif
+# ifdef CONFIG_STM32L4_TIM1_CH3NOUT
+# define PWM_TIM1_CH3NCFG GPIO_TIM1_CH3NOUT
+# else
+# define PWM_TIM1_CH3NCFG 0
+# endif
# define PWM_TIM1_CHANNEL3 1
#else
# define PWM_TIM1_CHANNEL3 0
@@ -329,6 +344,11 @@
# else
# define PWM_TIM8_CH1CFG 0
# endif
+# ifdef CONFIG_STM32L4_TIM8_CH1OUT
+# define PWM_TIM8_CH1NCFG GPIO_TIM8_CH1NOUT
+# else
+# define PWM_TIM8_CH1NCFG 0
+# endif
# define PWM_TIM8_CHANNEL1 1
#else
# define PWM_TIM8_CHANNEL1 0
@@ -339,6 +359,11 @@
# else
# define PWM_TIM8_CH2CFG 0
# endif
+# ifdef CONFIG_STM32L4_TIM8_CH2NOUT
+# define PWM_TIM8_CH2NCFG GPIO_TIM8_CH2NOUT
+# else
+# define PWM_TIM8_CH2NCFG 0
+# endif
# define PWM_TIM8_CHANNEL2 1
#else
# define PWM_TIM8_CHANNEL2 0
@@ -349,6 +374,11 @@
# else
# define PWM_TIM8_CH3CFG 0
# endif
+# ifdef CONFIG_STM32L4_TIM8_CH3NOUT
+# define PWM_TIM8_CH3NCFG GPIO_TIM8_CH3NOUT
+# else
+# define PWM_TIM8_CH3NCFG 0
+# endif
# define PWM_TIM8_CHANNEL3 1
#else
# define PWM_TIM8_CHANNEL3 0
@@ -372,6 +402,11 @@
# else
# define PWM_TIM15_CH1CFG 0
# endif
+# ifdef CONFIG_STM32L4_TIM15_CH1NOUT
+# define PWM_TIM15_CH1NCFG GPIO_TIM15_CH1NOUT
+# else
+# define PWM_TIM15_CH1NCFG 0
+# endif
# define PWM_TIM15_CHANNEL1 1
#else
# define PWM_TIM15_CHANNEL1 0
@@ -394,6 +429,11 @@
# else
# define PWM_TIM16_CH1CFG 0
# endif
+# ifdef CONFIG_STM32L4_TIM16_CH1NOUT
+# define PWM_TIM16_CH1NCFG GPIO_TIM16_CH1NOUT
+# else
+# define PWM_TIM16_CH1NCFG 0
+# endif
# define PWM_TIM16_CHANNEL1 1
#else
# define PWM_TIM16_CHANNEL1 0
@@ -406,6 +446,11 @@
# else
# define PWM_TIM17_CH1CFG 0
# endif
+# ifdef CONFIG_STM32L4_TIM17_CH1NOUT
+# define PWM_TIM17_CH1NCFG GPIO_TIM17_CH1NOUT
+# else
+# define PWM_TIM17_CH1NCFG 0
+# endif
# define PWM_TIM17_CHANNEL1 1
#else
# define PWM_TIM17_CHANNEL1 0
--
GitLab
From 49238489fdf6040ff41661c89b6e5e3aee2d318b Mon Sep 17 00:00:00 2001
From: Sebastien Lorquet
Date: Fri, 14 Oct 2016 18:06:42 +0200
Subject: [PATCH 068/734] Support PWM testing on board nucleo-l476.
---
configs/nucleo-l476rg/include/board.h | 12 +
configs/nucleo-l476rg/src/Makefile | 4 +
configs/nucleo-l476rg/src/stm32_appinit.c | 21 ++
configs/nucleo-l476rg/src/stm32_pwm.c | 275 ++++++++++++++++++++++
4 files changed, 312 insertions(+)
create mode 100644 configs/nucleo-l476rg/src/stm32_pwm.c
diff --git a/configs/nucleo-l476rg/include/board.h b/configs/nucleo-l476rg/include/board.h
index a7a983221d..986844bf33 100644
--- a/configs/nucleo-l476rg/include/board.h
+++ b/configs/nucleo-l476rg/include/board.h
@@ -212,6 +212,18 @@
#define GPIO_TIM2_CH1IN GPIO_TIM2_CH1IN_1
#define GPIO_TIM2_CH2IN GPIO_TIM2_CH2IN_1
+/* PWM output for full bridge, uses config 1, because port E is N/A on QFP64
+ * CH1 | 1(A8) 2(E9)
+ * CH2 | 1(A9) 2(E11)
+ * CHN1 | 1(A7) 2(B13) 3(E8)
+ * CHN2 | 1(B0) 2(B14) 3(E10)
+ */
+
+#define GPIO_TIM1_CH1OUT GPIO_TIM1_CH1OUT_1
+#define GPIO_TIM1_CH1NOUT GPIO_TIM1_CH1N_1
+#define GPIO_TIM1_CH2OUT GPIO_TIM1_CH2OUT_1
+#define GPIO_TIM1_CH2NOUT GPIO_TIM1_CH2N_1
+
/************************************************************************************
* Public Data
************************************************************************************/
diff --git a/configs/nucleo-l476rg/src/Makefile b/configs/nucleo-l476rg/src/Makefile
index 771a34ffd6..c47701ba2c 100644
--- a/configs/nucleo-l476rg/src/Makefile
+++ b/configs/nucleo-l476rg/src/Makefile
@@ -66,6 +66,10 @@ ifeq ($(CONFIG_QENCODER),y)
CSRCS += stm32_qencoder.c
endif
+ifeq ($(CONFIG_PWM),y)
+CSRCS += stm32_pwm.c
+endif
+
ifeq ($(CONFIG_LIB_BOARDCTL),y)
CSRCS += stm32_appinit.c
endif
diff --git a/configs/nucleo-l476rg/src/stm32_appinit.c b/configs/nucleo-l476rg/src/stm32_appinit.c
index 9910184bf8..4f805ff147 100644
--- a/configs/nucleo-l476rg/src/stm32_appinit.c
+++ b/configs/nucleo-l476rg/src/stm32_appinit.c
@@ -207,3 +207,24 @@ int board_app_initialize(uintptr_t arg)
return OK;
}
+
+#ifdef CONFIG_BOARDCTL_IOCTL
+int board_ioctl(unsigned int cmd, uintptr_t arg)
+{
+ return -ENOTTY;
+}
+#endif
+
+#if defined(CONFIG_BOARDCTL_UNIQUEID)
+int board_uniqueid(uint8_t *uniqueid)
+{
+ if (uniqueid == 0)
+ {
+ return -EINVAL;
+ }
+
+ stm32l4_get_uniqueid(uniqueid);
+ return OK;
+}
+#endif
+
diff --git a/configs/nucleo-l476rg/src/stm32_pwm.c b/configs/nucleo-l476rg/src/stm32_pwm.c
new file mode 100644
index 0000000000..0f753844bb
--- /dev/null
+++ b/configs/nucleo-l476rg/src/stm32_pwm.c
@@ -0,0 +1,275 @@
+/************************************************************************************
+ * configs/nucleo-l476rg/src/stm32_pwm.c
+ *
+ * Copyright (C) 2011, 2015 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * Copyright (C) 2016 Sebastien Lorquet. All rights reserved.
+ * Author: Sebastien Lorquet
+ *
+ * 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
+
+#include
+#include
+
+#include
+#include
+
+#include
+
+#include "chip.h"
+#include "up_arch.h"
+#include "stm32l4_pwm.h"
+#include "nucleo-l476rg.h"
+
+/************************************************************************************
+ * Pre-processor Definitions
+ ************************************************************************************/
+/* Configuration *******************************************************************/
+/* PWM
+ *
+ * The STM3240G-Eval has no real on-board PWM devices, but the board can be
+ * configured to output a pulse train using variously unused pins on the board for
+ * PWM output (see board.h for details of pins).
+ */
+
+#ifdef CONFIG_PWM
+
+/************************************************************************************
+ * Private Functions
+ ************************************************************************************/
+
+/************************************************************************************
+ * Public Functions
+ ************************************************************************************/
+
+/************************************************************************************
+ * Name: board_pwm_setup
+ *
+ * Description:
+ * All STM32L4 architectures must provide the following interface to work with
+ * examples/pwm.
+ *
+ ************************************************************************************/
+
+int board_pwm_setup(void)
+{
+ static bool initialized = false;
+ struct pwm_lowerhalf_s *pwm;
+ int ret;
+
+ /* Have we already initialized? */
+
+ if (!initialized)
+ {
+ /* Call stm32l4_pwminitialize() to get an instance of the PWM interface */
+/* PWM
+ *
+ * The Nucleo-l476rg has no real on-board PWM devices, but the board can be
+ * configured to output a pulse train using TIM1 or 8, or others (see board.h).
+ * Let's figure out which the user has configured.
+ */
+
+# if defined(CONFIG_STM32L4_TIM1_PWM)
+ pwm = stm32l4_pwminitialize(1);
+ if (!pwm)
+ {
+ aerr("ERROR: Failed to get the STM32L4 PWM lower half\n");
+ return -ENODEV;
+ }
+
+ /* Register the PWM driver at "/dev/pwm0" */
+
+ ret = pwm_register("/dev/pwm0", pwm);
+ if (ret < 0)
+ {
+ aerr("ERROR: pwm_register failed: %d\n", ret);
+ return ret;
+ }
+#endif
+
+# if defined(CONFIG_STM32L4_TIM2_PWM)
+ pwm = stm32l4_pwminitialize(2);
+ if (!pwm)
+ {
+ aerr("ERROR: Failed to get the STM32L4 PWM lower half\n");
+ return -ENODEV;
+ }
+
+ /* Register the PWM driver at "/dev/pwm1" */
+
+ ret = pwm_register("/dev/pwm1", pwm);
+ if (ret < 0)
+ {
+ aerr("ERROR: pwm_register failed: %d\n", ret);
+ return ret;
+ }
+#endif
+
+# if defined(CONFIG_STM32L4_TIM3_PWM)
+ pwm = stm32l4_pwminitialize(3);
+ if (!pwm)
+ {
+ aerr("ERROR: Failed to get the STM32L4 PWM lower half\n");
+ return -ENODEV;
+ }
+
+ /* Register the PWM driver at "/dev/pwm2" */
+
+ ret = pwm_register("/dev/pwm2", pwm);
+ if (ret < 0)
+ {
+ aerr("ERROR: pwm_register failed: %d\n", ret);
+ return ret;
+ }
+#endif
+
+# if defined(CONFIG_STM32L4_TIM4_PWM)
+ pwm = stm32l4_pwminitialize(4);
+ if (!pwm)
+ {
+ aerr("ERROR: Failed to get the STM32L4 PWM lower half\n");
+ return -ENODEV;
+ }
+
+ /* Register the PWM driver at "/dev/pwm3" */
+
+ ret = pwm_register("/dev/pwm3", pwm);
+ if (ret < 0)
+ {
+ aerr("ERROR: pwm_register failed: %d\n", ret);
+ return ret;
+ }
+#endif
+
+# if defined(CONFIG_STM32L4_TIM5_PWM)
+ pwm = stm32l4_pwminitialize(5);
+ if (!pwm)
+ {
+ aerr("ERROR: Failed to get the STM32L4 PWM lower half\n");
+ return -ENODEV;
+ }
+
+ /* Register the PWM driver at "/dev/pwm4" */
+
+ ret = pwm_register("/dev/pwm4", pwm);
+ if (ret < 0)
+ {
+ aerr("ERROR: pwm_register failed: %d\n", ret);
+ return ret;
+ }
+#endif
+
+# if defined(CONFIG_STM32L4_TIM8_PWM)
+ pwm = stm32l4_pwminitialize(8);
+ if (!pwm)
+ {
+ aerr("ERROR: Failed to get the STM32L4 PWM lower half\n");
+ return -ENODEV;
+ }
+
+ /* Register the PWM driver at "/dev/pwm5" */
+
+ ret = pwm_register("/dev/pwm5", pwm);
+ if (ret < 0)
+ {
+ aerr("ERROR: pwm_register failed: %d\n", ret);
+ return ret;
+ }
+#endif
+
+# if defined(CONFIG_STM32L4_TIM15_PWM)
+ pwm = stm32l4_pwminitialize(15);
+ if (!pwm)
+ {
+ aerr("ERROR: Failed to get the STM32L4 PWM lower half\n");
+ return -ENODEV;
+ }
+
+ /* Register the PWM driver at "/dev/pwm6" */
+
+ ret = pwm_register("/dev/pwm6", pwm);
+ if (ret < 0)
+ {
+ aerr("ERROR: pwm_register failed: %d\n", ret);
+ return ret;
+ }
+#endif
+
+# if defined(CONFIG_STM32L4_TIM16_PWM)
+ pwm = stm32l4_pwminitialize(16);
+ if (!pwm)
+ {
+ aerr("ERROR: Failed to get the STM32L4 PWM lower half\n");
+ return -ENODEV;
+ }
+
+ /* Register the PWM driver at "/dev/pwm7" */
+
+ ret = pwm_register("/dev/pwm7", pwm);
+ if (ret < 0)
+ {
+ aerr("ERROR: pwm_register failed: %d\n", ret);
+ return ret;
+ }
+#endif
+
+# if defined(CONFIG_STM32L4_TIM17_PWM)
+ pwm = stm32l4_pwminitialize(17);
+ if (!pwm)
+ {
+ aerr("ERROR: Failed to get the STM32L4 PWM lower half\n");
+ return -ENODEV;
+ }
+
+ /* Register the PWM driver at "/dev/pwm8" */
+
+ ret = pwm_register("/dev/pwm8", pwm);
+ if (ret < 0)
+ {
+ aerr("ERROR: pwm_register failed: %d\n", ret);
+ return ret;
+ }
+#endif
+ /* Now we are initialized */
+
+ initialized = true;
+ }
+
+ return OK;
+}
+
+#endif /* CONFIG_PWM */
--
GitLab
From b669d78f8c7124083e167773afc5869bbe93d7c9 Mon Sep 17 00:00:00 2001
From: Gregory Nutt
Date: Fri, 14 Oct 2016 11:01:28 -0600
Subject: [PATCH 069/734] Trivial changes to README.txt
---
configs/esp32-core/README.txt | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/configs/esp32-core/README.txt b/configs/esp32-core/README.txt
index 984d16f16a..514c84cef9 100644
--- a/configs/esp32-core/README.txt
+++ b/configs/esp32-core/README.txt
@@ -1,5 +1,5 @@
README for the Expressif ESP32 Core board (V2)
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+==============================================
The ESP32 is a dual-core system from Expressif with two Harvard
architecture Xtensa LX6 CPUs. All embedded memory, external memory and
@@ -13,7 +13,8 @@ README for the Expressif ESP32 Core board (V2)
"application"), however for most purposes the two CPUs are
interchangeable.
- Features:
+ESP32 Features
+==============
* Address Space
- Symmetric address mapping
@@ -43,7 +44,9 @@ README for the Expressif ESP32 Core board (V2)
ESP32 Toolchain
===============
- The steps to build toolchain with crosstool-NG on Linux are as follows:
+ You must use the custom Xtensa toolchain in order to build the ESP32 Core
+ BSP. The steps to build toolchain with crosstool-NG on Linux are as
+ follows:
git clone -b xtensa-1.22.x https://github.com/espressif/crosstool-NG.git
cd crosstool-NG
@@ -55,5 +58,5 @@ ESP32 Toolchain
These steps are given in setup guide in ESP-IDF repository:
https://github.com/espressif/esp-idf/blob/master/docs/linux-setup.rst#alternative-step-1-compile-the-toolchain-from-source-using-crosstool-ng
- NOTE: the xtensa-esp32-elf configuration is only available in the
+ NOTE: The xtensa-esp32-elf configuration is only available in the
xtensa-1.22.x branch.
--
GitLab
From ad6856c931ed92929b607e5d22fec3d3c24e35b1 Mon Sep 17 00:00:00 2001
From: Gregory Nutt
Date: Fri, 14 Oct 2016 11:12:49 -0600
Subject: [PATCH 070/734] Trivial stylistic changes from review of last PR
---
arch/arm/src/stm32l4/stm32l4_pwm.c | 19 +++++++---------
configs/nucleo-l476rg/src/stm32_pwm.c | 32 ++++++++++++++-------------
2 files changed, 25 insertions(+), 26 deletions(-)
diff --git a/arch/arm/src/stm32l4/stm32l4_pwm.c b/arch/arm/src/stm32l4/stm32l4_pwm.c
index f45e4c1384..80214fb9e5 100644
--- a/arch/arm/src/stm32l4/stm32l4_pwm.c
+++ b/arch/arm/src/stm32l4/stm32l4_pwm.c
@@ -128,7 +128,7 @@ struct stm32l4_pwmchan_s
uint8_t channel; /* Timer output channel: {1,..4} */
uint32_t pincfg; /* Output pin configuration */
enum stm32l4_chanmode_e mode;
- uint32_t npincfg; /* Complementary output pin configuration (only TIM1/8 CH1-3)*/
+ uint32_t npincfg; /* Complementary output pin configuration (only TIM1/8 CH1-3)*/
};
/* This structure represents the state of one PWM timer */
@@ -996,10 +996,10 @@ static int stm32l4pwm_timer(FAR struct stm32l4_pwmtimer_s *priv,
/* Handle channel specific setup */
- ccenable = 0;
+ ccenable = 0;
ccnenable = 0;
- ocmode1 = 0;
- ocmode2 = 0;
+ ocmode1 = 0;
+ ocmode2 = 0;
#ifdef CONFIG_PWM_MULTICHAN
for (i = 0; i < CONFIG_PWM_NCHANNELS; i++)
@@ -1104,7 +1104,7 @@ static int stm32l4pwm_timer(FAR struct stm32l4_pwmtimer_s *priv,
/* Conditionnaly enable the complementary output */
- if(compout)
+ if (compout)
{
ccnenable |= ATIM_CCER_CC1NE;
}
@@ -1134,7 +1134,7 @@ static int stm32l4pwm_timer(FAR struct stm32l4_pwmtimer_s *priv,
/* Conditionnaly enable the complementary output */
- if(compout)
+ if (compout)
{
ccnenable |= ATIM_CCER_CC2NE;
}
@@ -1164,7 +1164,7 @@ static int stm32l4pwm_timer(FAR struct stm32l4_pwmtimer_s *priv,
/* Conditionnaly enable the complementary output */
- if(compout)
+ if (compout)
{
ccnenable |= ATIM_CCER_CC3NE;
}
@@ -1289,14 +1289,13 @@ static int stm32l4pwm_timer(FAR struct stm32l4_pwmtimer_s *priv,
*/
ccer &= ~(ATIM_CCER_CC1NE | ATIM_CCER_CC1NP);
-
ccer |= ccnenable;
}
else
#endif
#endif
{
- ccer &= ~(GTIM_CCER_CC1NP | GTIM_CCER_CC2NP | GTIM_CCER_CC3NP); //Not sure why ??
+ ccer &= ~(GTIM_CCER_CC1NP | GTIM_CCER_CC2NP | GTIM_CCER_CC3NP); /* Not sure why? */
}
/* Save the modified register values */
@@ -1783,7 +1782,6 @@ static int stm32l4pwm_shutdown(FAR struct pwm_lowerhalf_s *dev)
pwminfo("pincfg: %08x\n", pincfg);
pincfg &= (GPIO_PORT_MASK | GPIO_PIN_MASK);
-
pincfg |= GPIO_INPUT | GPIO_FLOAT;
stm32l4_configgpio(pincfg);
@@ -1795,7 +1793,6 @@ static int stm32l4pwm_shutdown(FAR struct pwm_lowerhalf_s *dev)
pwminfo("npincfg: %08x\n", pincfg);
pincfg &= (GPIO_PORT_MASK | GPIO_PIN_MASK);
-
pincfg |= GPIO_INPUT | GPIO_FLOAT;
stm32l4_configgpio(pincfg);
diff --git a/configs/nucleo-l476rg/src/stm32_pwm.c b/configs/nucleo-l476rg/src/stm32_pwm.c
index 0f753844bb..f5c00a1a64 100644
--- a/configs/nucleo-l476rg/src/stm32_pwm.c
+++ b/configs/nucleo-l476rg/src/stm32_pwm.c
@@ -96,14 +96,15 @@ int board_pwm_setup(void)
if (!initialized)
{
/* Call stm32l4_pwminitialize() to get an instance of the PWM interface */
-/* PWM
- *
- * The Nucleo-l476rg has no real on-board PWM devices, but the board can be
- * configured to output a pulse train using TIM1 or 8, or others (see board.h).
- * Let's figure out which the user has configured.
- */
-# if defined(CONFIG_STM32L4_TIM1_PWM)
+ /* PWM
+ *
+ * The Nucleo-l476rg has no real on-board PWM devices, but the board can be
+ * configured to output a pulse train using TIM1 or 8, or others (see board.h).
+ * Let's figure out which the user has configured.
+ */
+
+#if defined(CONFIG_STM32L4_TIM1_PWM)
pwm = stm32l4_pwminitialize(1);
if (!pwm)
{
@@ -121,7 +122,7 @@ int board_pwm_setup(void)
}
#endif
-# if defined(CONFIG_STM32L4_TIM2_PWM)
+#if defined(CONFIG_STM32L4_TIM2_PWM)
pwm = stm32l4_pwminitialize(2);
if (!pwm)
{
@@ -139,7 +140,7 @@ int board_pwm_setup(void)
}
#endif
-# if defined(CONFIG_STM32L4_TIM3_PWM)
+#if defined(CONFIG_STM32L4_TIM3_PWM)
pwm = stm32l4_pwminitialize(3);
if (!pwm)
{
@@ -157,7 +158,7 @@ int board_pwm_setup(void)
}
#endif
-# if defined(CONFIG_STM32L4_TIM4_PWM)
+#if defined(CONFIG_STM32L4_TIM4_PWM)
pwm = stm32l4_pwminitialize(4);
if (!pwm)
{
@@ -175,7 +176,7 @@ int board_pwm_setup(void)
}
#endif
-# if defined(CONFIG_STM32L4_TIM5_PWM)
+#if defined(CONFIG_STM32L4_TIM5_PWM)
pwm = stm32l4_pwminitialize(5);
if (!pwm)
{
@@ -193,7 +194,7 @@ int board_pwm_setup(void)
}
#endif
-# if defined(CONFIG_STM32L4_TIM8_PWM)
+#if defined(CONFIG_STM32L4_TIM8_PWM)
pwm = stm32l4_pwminitialize(8);
if (!pwm)
{
@@ -211,7 +212,7 @@ int board_pwm_setup(void)
}
#endif
-# if defined(CONFIG_STM32L4_TIM15_PWM)
+#if defined(CONFIG_STM32L4_TIM15_PWM)
pwm = stm32l4_pwminitialize(15);
if (!pwm)
{
@@ -229,7 +230,7 @@ int board_pwm_setup(void)
}
#endif
-# if defined(CONFIG_STM32L4_TIM16_PWM)
+#if defined(CONFIG_STM32L4_TIM16_PWM)
pwm = stm32l4_pwminitialize(16);
if (!pwm)
{
@@ -247,7 +248,7 @@ int board_pwm_setup(void)
}
#endif
-# if defined(CONFIG_STM32L4_TIM17_PWM)
+#if defined(CONFIG_STM32L4_TIM17_PWM)
pwm = stm32l4_pwminitialize(17);
if (!pwm)
{
@@ -273,3 +274,4 @@ int board_pwm_setup(void)
}
#endif /* CONFIG_PWM */
+
--
GitLab
From e3ead1db697c3397a46cb08a52e12374caf37c0a Mon Sep 17 00:00:00 2001
From: Gregory Nutt
Date: Fri, 14 Oct 2016 13:17:48 -0600
Subject: [PATCH 071/734] Xtensa: Add an initial guess at the form of struct
xcpcontext
---
arch/xtensa/Kconfig | 16 +++++++
arch/xtensa/include/irq.h | 97 +++++++++++++++++++++++++++++++++++++++
2 files changed, 113 insertions(+)
diff --git a/arch/xtensa/Kconfig b/arch/xtensa/Kconfig
index 3ba3a48ec3..1bd5c0f54d 100644
--- a/arch/xtensa/Kconfig
+++ b/arch/xtensa/Kconfig
@@ -29,6 +29,22 @@ config ARCH_FAMILY_LX6
Cadence® Tensilica® Xtensa® LX6 data plane processing unit (DPU).
The LX6 is a configurable and extensible processor core.
+config XTENSA_HAVE_LOOPS
+ bool "Zero overhead loops"
+ default n
+
+config XTENSA_USE_SWPRI
+ bool "Use SWPRI"
+ default n
+
+config XTENSA_CALL0_ABI
+ bool "CALL0 ABI"
+ default y
+
+config XTENSA_USE_OVLY
+ bool "Use overlay"
+ default n
+
config ARCH_CHIP
string
default "esp32" if ARCH_CHIP_ESP32
diff --git a/arch/xtensa/include/irq.h b/arch/xtensa/include/irq.h
index ed10e3bbb1..3e8dfd4666 100644
--- a/arch/xtensa/include/irq.h
+++ b/arch/xtensa/include/irq.h
@@ -69,12 +69,109 @@
* Pre-processor Definitions
****************************************************************************/
+/* IRQ Stack Frame Format. Each value is a uint32_t register index */
+
+#define REG_EXIT (0) /* Exit point for dispatch */
+#define REG_PC (1) /* Return PC */
+#define REG_PS (2) /* Return PS */
+#define REG_A0 (3)
+#define REG_A1 (4) /* Stack pointer before interrupt */
+#define REG_A2 (5)
+#define REG_A3 (6)
+#define REG_A4 (7)
+#define REG_A5 (8)
+#define REG_A6 (9)
+#define REG_A7 (10)
+#define REG_A8 (11)
+#define REG_A9 (12)
+#define REG_A10 (13)
+#define REG_A11 (14)
+#define REG_A12 (15)
+#define REG_A13 (16)
+#define REG_A14 (17)
+#define REG_A15 (18)
+#define REG_SAR (19)
+#define REG_EXCCAUSE (20)
+#define REG_EXCVADDR (21)
+#define _REG_LOOPS_START (22)
+
+#if CONFIG_XTENSA_HAVE_LOOPS
+# define REG_LBEG (_REG_LOOPS_START + 0)
+# define REG_LEND (_REG_LOOPS_START + 1)
+# define REG_LCOUNT (_REG_LOOPS_START + 2)
+# define _REG_CALL0_START (_REG_LOOPS_START + 3)
+#else
+# define _REG_CALL0_START _REG_LOOPS_START
+#endif
+
+#ifndef CONFIG_XTENSA_CALL0_ABI
+ /* Temporary space for saving stuff during window spill */
+
+# define REG_TMP0 (_REG_CALL0_START + 0)
+# define REG_TMP1 (_REG_CALL0_START + 1)
+# define REG_TMP2 (_REG_CALL0_START + 2)
+# define _REG_SWPRI_START (_REG_CALL0_START + 3)
+#else
+# define _REG_SWPRI_START _REG_CALL0_START
+#endif
+
+#ifdef CONFIG_XTENSA_USE_SWPRI
+ /* Storage for virtual priority mask */
+
+# define REG_VPRI (_REG_SWPRI_START + 0)
+# define _REG_OVLY_START (_REG_SWPRI_START + 1)
+#else
+# define _REG_OVLY_START _REG_SWPRI_START
+#endif
+
+#ifdef CONFIG_XTENSA_USE_OVLY
+/* Storage for overlay state */
+
+# define REG_OVLY (_REG_OVLY_START + 0)
+# define XCPTCONTEXT_REGS (_REG_OVLY_START + 1)
+#else
+# define XCPTCONTEXT_REGS _REG_OVLY_START
+#endif
+
+#define XCPTCONTEXT_SIZE (4 * XCPTCONTEXT_REGS)
+
/****************************************************************************
* Public Types
****************************************************************************/
#ifndef __ASSEMBLY__
+/* This struct defines the way the registers are stored. */
+
+struct xcptcontext
+{
+ /* The following function pointer is non-zero if there are pending signals
+ * to be processed.
+ */
+
+#ifndef CONFIG_DISABLE_SIGNALS
+ void *sigdeliver; /* Actual type is sig_deliver_t */
+
+ /* These are saved copies of registers used during signal processing. */
+
+ uint32_t saved_pc;
+ uint32_t saved_cpsr;
+#endif
+
+ /* Register save area */
+
+ uint32_t regs[XCPTCONTEXT_REGS];
+
+#ifdef CONFIG_LIB_SYSCALL
+ /* The following array holds the return address and the exc_return value
+ * needed to return from each nested system call.
+ */
+
+ uint8_t nsyscalls;
+ struct xcpt_syscall_s syscall[CONFIG_SYS_NNEST];
+#endif
+};
+
/****************************************************************************
* Inline functions
****************************************************************************/
--
GitLab
From 5b46ce4889e034bd2def7367563b62b4122dcb61 Mon Sep 17 00:00:00 2001
From: Gregory Nutt
Date: Fri, 14 Oct 2016 17:39:21 -0600
Subject: [PATCH 072/734] Cosmetic changes from review of last PR
---
arch/arm/src/kinetis/kinetis_uid.c | 28 +++++++++++++------------
arch/arm/src/kinetis/kinetis_uid.h | 21 ++++++++++++-------
configs/freedom-k64f/src/Makefile | 1 +
configs/freedom-k64f/src/k64_uid.c | 24 ++++++++++++---------
configs/freedom-k64f/src/k64_userleds.c | 3 ++-
5 files changed, 46 insertions(+), 31 deletions(-)
diff --git a/arch/arm/src/kinetis/kinetis_uid.c b/arch/arm/src/kinetis/kinetis_uid.c
index 54a98d08ce..954c667f41 100644
--- a/arch/arm/src/kinetis/kinetis_uid.c
+++ b/arch/arm/src/kinetis/kinetis_uid.c
@@ -1,4 +1,4 @@
-/************************************************************************************
+/****************************************************************************
* arch/arm/src/kinetis/kinetis_uid.c
*
* Copyright (C) 2016 Neil Hancock. All rights reserved.
@@ -30,11 +30,11 @@
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
- ************************************************************************************/
+ ****************************************************************************/
-/************************************************************************************
+/****************************************************************************
* Included Files
- ************************************************************************************/
+ ****************************************************************************/
#include
@@ -44,25 +44,27 @@
#ifdef CONFIG_BOARDCTL_UNIQUEID
-/************************************************************************************
+/****************************************************************************
* Public Functions
- ************************************************************************************/
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: kinetis_get_uniqueid
+ ****************************************************************************/
void kinetis_get_uniqueid(uint8_t *uniqueid)
{
- int i;
uint32_t *unique_u32;
+ int i;
+
unique_u32 = (uint32_t *)uniqueid;
- /*
- * Copy into buffer LS first, which in the Kinetis is the highest memory
- */
+ /* Copy into buffer LS first, which in the Kinetis is the highest memory */
- for (i = 0; i < (KINETIS_UID_SIZE/sizeof(uint32_t)); i++)
+ for (i = 0; i < (KINETIS_UID_SIZE / sizeof(uint32_t)); i++)
{
- unique_u32[i] = *((uint32_t*)(KINETIS_SIM_UIDL)-i);
+ unique_u32[i] = *((uint32_t*)(KINETIS_SIM_UIDL) - i);
}
}
#endif /* CONFIG_BOARDCTL_UNIQUEID */
-
diff --git a/arch/arm/src/kinetis/kinetis_uid.h b/arch/arm/src/kinetis/kinetis_uid.h
index 84620f53e5..29299da582 100644
--- a/arch/arm/src/kinetis/kinetis_uid.h
+++ b/arch/arm/src/kinetis/kinetis_uid.h
@@ -1,4 +1,4 @@
-/************************************************************************************
+/****************************************************************************
* arch/arm/src/kinetis/kinetis_uid.h
*
* Copyright (C) 2016 Neil Hancock. All rights reserved.
@@ -30,20 +30,27 @@
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
- ************************************************************************************/
+ ****************************************************************************/
#ifndef __ARCH_ARM_SRC_KINETIS_UID_H
#define __ARCH_ARM_SRC_KINETIS_UID_H
-/************************************************************************************
+/****************************************************************************
* Included Files
- ************************************************************************************/
+ ****************************************************************************/
#include
-/************************************************************************************
- * Public Function Prototypes
- ************************************************************************************/
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
#define KINETIS_UID_SIZE 16
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
void kinetis_get_uniqueid(uint8_t *uniqueid);
+
#endif /* __ARCH_ARM_SRC_KINETIS_UID_H */
diff --git a/configs/freedom-k64f/src/Makefile b/configs/freedom-k64f/src/Makefile
index 7da96029aa..e11590bbc1 100644
--- a/configs/freedom-k64f/src/Makefile
+++ b/configs/freedom-k64f/src/Makefile
@@ -76,4 +76,5 @@ endif
ifeq ($(CONFIG_BOARDCTL_UNIQUEID),y)
CSRCS += k64_uid.c
endif
+
include $(TOPDIR)/configs/Board.mk
diff --git a/configs/freedom-k64f/src/k64_uid.c b/configs/freedom-k64f/src/k64_uid.c
index 545de899c0..0fc1527637 100644
--- a/configs/freedom-k64f/src/k64_uid.c
+++ b/configs/freedom-k64f/src/k64_uid.c
@@ -1,4 +1,4 @@
-/************************************************************************************
+/****************************************************************************
* configs/freedom-k64/src/kinetis_uid.c
*
* Copyright (C) 2016 Neil Hancock. All rights reserved.
@@ -30,11 +30,11 @@
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
- ************************************************************************************/
+ ****************************************************************************/
-/************************************************************************************
+/****************************************************************************
* Included Files
- ************************************************************************************/
+ ****************************************************************************/
#include
@@ -45,19 +45,23 @@
#include
-/************************************************************************************
+#if defined(CONFIG_BOARDCTL_UNIQUEID)
+
+/****************************************************************************
* Pre-processor Definitions
- ************************************************************************************/
+ ****************************************************************************/
#ifndef OK
# define OK 0
#endif
-/************************************************************************************
+/****************************************************************************
* Public Functions
- ************************************************************************************/
+ ****************************************************************************/
-#if defined(CONFIG_BOARDCTL_UNIQUEID)
+/****************************************************************************
+ * Name: board_uniqueid
+ ****************************************************************************/
int board_uniqueid(FAR uint8_t *uniqueid)
{
@@ -70,4 +74,4 @@ int board_uniqueid(FAR uint8_t *uniqueid)
return OK;
}
-#endif
+#endif /* CONFIG_BOARDCTL_UNIQUEID */
diff --git a/configs/freedom-k64f/src/k64_userleds.c b/configs/freedom-k64f/src/k64_userleds.c
index e75a2abb8e..8b334823a5 100644
--- a/configs/freedom-k64f/src/k64_userleds.c
+++ b/configs/freedom-k64f/src/k64_userleds.c
@@ -107,4 +107,5 @@ void board_userled_all(uint8_t ledset)
kinetis_gpiowrite(GPIO_LED_G, (ledset & BOARD_LED_G_BIT) == 0);
kinetis_gpiowrite(GPIO_LED_B, (ledset & BOARD_LED_B_BIT) == 0);
}
-#endif
+
+#endif /* CONFIG_ARCH_LEDS */
--
GitLab
From 909ea5e8efbb57a9a37752dd1cae894fd051f1e8 Mon Sep 17 00:00:00 2001
From: David Sidrane
Date: Sat, 15 Oct 2016 03:55:48 -1000
Subject: [PATCH 073/734] F4 Support versampling by 8
---
arch/arm/src/stm32/stm32_serial.c | 56 ++++++++++++++++++++++++-------
1 file changed, 43 insertions(+), 13 deletions(-)
diff --git a/arch/arm/src/stm32/stm32_serial.c b/arch/arm/src/stm32/stm32_serial.c
index eeb5a846a7..381df6c016 100644
--- a/arch/arm/src/stm32/stm32_serial.c
+++ b/arch/arm/src/stm32/stm32_serial.c
@@ -1190,15 +1190,20 @@ static void up_set_format(struct uart_dev_s *dev)
{
struct up_dev_s *priv = (struct up_dev_s *)dev->priv;
uint32_t regval;
+ uint32_t brr;
+
+ /* Load CR1 */
+
+ regval = up_serialin(priv, STM32_USART_CR1_OFFSET);
#if defined(CONFIG_STM32_STM32F30XX) || defined(CONFIG_STM32_STM32F37XX)
/* This first implementation is for U[S]ARTs that support oversampling
* by 8 in additional to the standard oversampling by 16.
+ * With baud rate of fCK / Divider for oversampling by 16.
+ * and baud rate of 2 * fCK / Divider for oversampling by 8
*/
uint32_t usartdiv8;
- uint32_t cr1;
- uint32_t brr;
/* In case of oversampling by 8, the equation is:
*
@@ -1218,7 +1223,6 @@ static void up_set_format(struct uart_dev_s *dev)
/* Use oversamply by 8 only if the divisor is small. But what is small? */
- cr1 = up_serialin(priv, STM32_USART_CR1_OFFSET);
if (usartdiv8 > 100)
{
/* Use usartdiv16 */
@@ -1227,7 +1231,7 @@ static void up_set_format(struct uart_dev_s *dev)
/* Clear oversampling by 8 to enable oversampling by 16 */
- cr1 &= ~USART_CR1_OVER8;
+ regval &= ~USART_CR1_OVER8;
}
else
{
@@ -1239,12 +1243,9 @@ static void up_set_format(struct uart_dev_s *dev)
/* Set oversampling by 8 */
- cr1 |= USART_CR1_OVER8;
+ regval |= USART_CR1_OVER8;
}
- up_serialout(priv, STM32_USART_CR1_OFFSET, cr1);
- up_serialout(priv, STM32_USART_BRR_OFFSET, brr);
-
#else
/* This second implementation is for U[S]ARTs that support fractional
@@ -1254,7 +1255,6 @@ static void up_set_format(struct uart_dev_s *dev)
uint32_t usartdiv32;
uint32_t mantissa;
uint32_t fraction;
- uint32_t brr;
/* Configure the USART Baud Rate. The baud rate for the receiver and
* transmitter (Rx and Tx) are both set to the same value as programmed
@@ -1272,23 +1272,53 @@ static void up_set_format(struct uart_dev_s *dev)
* usartdiv32 = 32 * usartdiv = fCK / (baud/2)
*/
- usartdiv32 = priv->apbclock / (priv->baud >> 1);
+ usartdiv32 = priv->apbclock / (priv->baud >> 1);
/* The mantissa part is then */
mantissa = usartdiv32 >> 5;
- brr = mantissa << USART_BRR_MANT_SHIFT;
/* The fractional remainder (with rounding) */
fraction = (usartdiv32 - (mantissa << 5) + 1) >> 1;
+
+#if defined(CONFIG_STM32_STM32F40XX)
+
+ /* The F4 supports 8 X in oversampling additional to the
+ * standard oversampling by 16.
+ * With baud rate of fCK / (16 * Divider) for oversampling by 16.
+ * and baud rate of fCK / (8 * Divider) for oversampling by 8
+ */
+
+ /* Check if 8x oversampling is necessary */
+
+ if (mantissa == 0)
+ {
+ regval |= USART_CR1_OVER8;
+
+ /* Rescale the mantissa */
+
+ mantissa = usartdiv32 >> 4;
+
+ /* The fractional remainder (with rounding) */
+
+ fraction = (usartdiv32 - (mantissa << 4) + 1) >> 1;
+ }
+ else
+ {/* Use 16x Oversampling */
+ regval &= ~USART_CR1_OVER8;
+ }
+#endif
+
+ brr = mantissa << USART_BRR_MANT_SHIFT;
brr |= fraction << USART_BRR_FRAC_SHIFT;
- up_serialout(priv, STM32_USART_BRR_OFFSET, brr);
#endif
+ up_serialout(priv, STM32_USART_CR1_OFFSET, regval);
+ up_serialout(priv, STM32_USART_BRR_OFFSET, brr);
+
/* Configure parity mode */
- regval = up_serialin(priv, STM32_USART_CR1_OFFSET);
regval &= ~(USART_CR1_PCE | USART_CR1_PS | USART_CR1_M);
if (priv->parity == 1) /* Odd parity */
--
GitLab
From 6f35ced002226385c294c2410db00df607cd47c7 Mon Sep 17 00:00:00 2001
From: Gregory Nutt
Date: Sat, 15 Oct 2016 08:39:15 -0600
Subject: [PATCH 074/734] ESP32: Add peripheral interrupt IRQ numbers
---
arch/xtensa/include/esp32/irq.h | 133 ++++++++++++++++++++++++++++++++
1 file changed, 133 insertions(+)
diff --git a/arch/xtensa/include/esp32/irq.h b/arch/xtensa/include/esp32/irq.h
index d67ea04794..058833dc9b 100644
--- a/arch/xtensa/include/esp32/irq.h
+++ b/arch/xtensa/include/esp32/irq.h
@@ -49,6 +49,139 @@
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
+/* Exceptions
+ *
+ * IRAM Offset Description
+ * 0x0000 Windows
+ * 0x0180 Level 2 interrupt
+ * 0x01c0 Level 3 interrupt
+ * 0x0200 Level 4 interrupt
+ * 0x0240 Level 5 interrupt
+ * 0x0280 Debug exception
+ * 0x02c0 NMI exception
+ * 0x0300 Kernel exception
+ * 0x0340 User exception
+ * 0x03c0 Double exception
+ *
+ * REVISIT: In more architectures supported by NuttX, exception errors
+ * tie into the normal interrupt handling via special IRQ numbers. I
+ * is still to be determined what will be done for the the ESP32.
+ */
+
+/* Interrupt Matrix
+ *
+ * The Interrupt Matrix embedded in the ESP32 independently allocates
+ * peripheral interrupt sources to the two CPUs’ peripheral interrupts. This
+ * configuration is highly flexible in order to meet many different needs.
+ *
+ * Features
+ * - Accepts 71 peripheral interrupt sources as input.
+ * - Generates 26 peripheral interrupt sources per CPU as output (52 total).
+ * - CPU NMI Interrupt Mask.
+ * - Queries current interrupt status of peripheral interrupt sources.
+ *
+ * Peripheral Interrupt Source
+ *
+ * ESP32 has 71 peripheral interrupt sources in total. 67 of 71 ESP32
+ * peripheral interrupt sources can be allocated to either CPU. The four
+ * remaining peripheral interrupt sources are CPU-specific, two per CPU.
+ *
+ * - GPIO_INTERRUPT_PRO and GPIO_INTERRUPT_PRO_NMI can only be allocated to
+ * PRO_CPU.
+ * - GPIO_INTERRUPT_APP and GPIO_INTERRUPT_APP_NMI can only be allocated to
+ * APP_CPU.
+ *
+ * As a result, PRO_CPU and APP_CPU each have 69 peripheral interrupt
+ * sources.
+ */
+
+/* PRO_INTR_STATUS_REG_0 / APP_INTR_STATUS_REG_0 */
+
+#define XTENSA_IRQ_MAC 0 /* 1. *_INTR_STATUS_REG_0, bit 0 */
+#define XTENSA_IRQ_MAC_NMI 1 /* 2. *_INTR_STATUS_REG_0, bit 1 */
+#define XTENSA_IRQ_BB 2 /* 3. *_INTR_STATUS_REG_0, bit 2 */
+#define XTENSA_IRQ_BB_MAC 3 /* 4. *_INTR_STATUS_REG_0, bit 3 */
+#define XTENSA_IRQ_BT_BB 4 /* 5. *_INTR_STATUS_REG_0, bit 4 */
+#define XTENSA_IRQ_BT_BB_NMI 5 /* 6. *_INTR_STATUS_REG_0, bit 5 */
+#define XTENSA_IRQ_RWBT_IRQ 6 /* 7. *_INTR_STATUS_REG_0, bit 6 */
+#define XTENSA_IRQ_RWBLE_IRQ 7 /* 8. *_INTR_STATUS_REG_0, bit 7 */
+#define XTENSA_IRQ_RWBT_NMI 8 /* 9. *_INTR_STATUS_REG_0, bit 8 */
+#define XTENSA_IRQ_RWBLE_NMI 9 /* 10. *_INTR_STATUS_REG_0, bit 9 */
+
+#define XTENSA_IRQ_SLC0 10 /* 11. *_INTR_STATUS_REG_0, bit 10 */
+#define XTENSA_IRQ_SLC1 11 /* 12. *_INTR_STATUS_REG_0, bit 11 */
+#define XTENSA_IRQ_UHCI0 12 /* 13. *_INTR_STATUS_REG_0, bit 12 */
+#define XTENSA_IRQ_UHCI1 13 /* 14. *_INTR_STATUS_REG_0, bit 13 */
+#define XTENSA_IRQ_TG_T0_LEVEL 14 /* 15. *_INTR_STATUS_REG_0, bit 14 */
+#define XTENSA_IRQ_TG_T1_LEVEL 15 /* 16. *_INTR_STATUS_REG_0, bit 15 */
+#define XTENSA_IRQ_TG_WDT_LEVEL 16 /* 17. *_INTR_STATUS_REG_0, bit 16 */
+#define XTENSA_IRQ_TG_LACT_LEVEL 17 /* 18. *_INTR_STATUS_REG_0, bit 17 */
+#define XTENSA_IRQ_TG1_T0_LEVEL 18 /* 19. *_INTR_STATUS_REG_0, bit 18 */
+#define XTENSA_IRQ_TG1_T1_LEVEL 19 /* 20. *_INTR_STATUS_REG_0, bit 19 */
+
+#define XTENSA_IRQ_TG1_WDT_LEVEL 20 /* 21. *_INTR_STATUS_REG_0, bit 20 */
+#define XTENSA_IRQ_G1_LACT_LEVEL 21 /* 22. *_INTR_STATUS_REG_0, bit 21 */
+#define XTENSA_IRQ_CPU_GPIO 22 /* 23. *_INTR_STATUS_REG_0, bit 22 */
+#define XTENSA_IRQ_CPU_NMI 23 /* 24. *_INTR_STATUS_REG_0, bit 23 */
+#define XTENSA_IRQ_CPU_CPU0 24 /* 25. *_INTR_STATUS_REG_0, bit 24 */
+#define XTENSA_IRQ_CPU_CPU1 25 /* 26. *_INTR_STATUS_REG_0, bit 25 */
+#define XTENSA_IRQ_CPU_CPU2 26 /* 27. *_INTR_STATUS_REG_0, bit 26 */
+#define XTENSA_IRQ_CPU_CPU3 27 /* 28. *_INTR_STATUS_REG_0, bit 27 */
+#define XTENSA_IRQ_SPI0 28 /* 29. *_INTR_STATUS_REG_0, bit 28 */
+#define XTENSA_IRQ_SPI1 29 /* 30. *_INTR_STATUS_REG_0, bit 29 */
+
+#define XTENSA_IRQ_SPI2 30 /* 31. *_INTR_STATUS_REG_0, bit 30 */
+#define XTENSA_IRQ_SPI3 31 /* 32. *_INTR_STATUS_REG_0, bit 31 */
+
+/* PRO_INTR_STATUS_REG_1 / APP_INTR_STATUS_REG_1 */
+
+#define XTENSA_IRQ_I2S0 32 /* 33. *_INTR_STATUS_REG_1, bit 0 */
+#define XTENSA_IRQ_I2S1 33 /* 34. *_INTR_STATUS_REG_1, bit 1 */
+#define XTENSA_IRQ_UART 34 /* 35. *_INTR_STATUS_REG_1, bit 2 */
+#define XTENSA_IRQ_UART1 35 /* 36. *_INTR_STATUS_REG_1, bit 3 */
+#define XTENSA_IRQ_UART2 36 /* 37. *_INTR_STATUS_REG_1, bit 4 */
+#define XTENSA_IRQ_SDIO_HOST 37 /* 38. *_INTR_STATUS_REG_1, bit 5 */
+#define XTENSA_IRQ_EMAC 38 /* 39. *_INTR_STATUS_REG_1, bit 6 */
+#define XTENSA_IRQ_PWM0 39 /* 40. *_INTR_STATUS_REG_1, bit 7 */
+#define XTENSA_IRQ_PWM1 40 /* 41. *_INTR_STATUS_REG_1, bit 8 */
+#define XTENSA_IRQ_PWM2 41 /* 42. *_INTR_STATUS_REG_1, bit 9 */
+
+#define XTENSA_IRQ_PWM3 42 /* 43. *_INTR_STATUS_REG_1, bit 10 */
+#define XTENSA_IRQ_LEDC 43 /* 44. *_INTR_STATUS_REG_1, bit 11 */
+#define XTENSA_IRQ_EFUSE 44 /* 45. *_INTR_STATUS_REG_1, bit 12 */
+#define XTENSA_IRQ_CAN 45 /* 46. *_INTR_STATUS_REG_1, bit 13 */
+#define XTENSA_IRQ_RTC_CORE 46 /* 47. *_INTR_STATUS_REG_1, bit 14 */
+#define XTENSA_IRQ_RMT 47 /* 48. *_INTR_STATUS_REG_1, bit 15 */
+#define XTENSA_IRQ_PCNT 48 /* 49. *_INTR_STATUS_REG_1, bit 16 */
+#define XTENSA_IRQ_I2C_EXT0 49 /* 50. *_INTR_STATUS_REG_1, bit 17 */
+#define XTENSA_IRQ_I2C_EXT1 50 /* 51. *_INTR_STATUS_REG_1, bit 18 */
+#define XTENSA_IRQ_RSA 51 /* 52. *_INTR_STATUS_REG_1, bit 19 */
+
+#define XTENSA_IRQ_SPI1_DMA 52 /* 53. *_INTR_STATUS_REG_1, bit 20 */
+#define XTENSA_IRQ_SPI2_DMA 53 /* 54. *_INTR_STATUS_REG_1, bit 21 */
+#define XTENSA_IRQ_SPI3_DMA 54 /* 55. *_INTR_STATUS_REG_1, bit 22 */
+#define XTENSA_IRQ_WDG 55 /* 56. *_INTR_STATUS_REG_1, bit 23 */
+#define XTENSA_IRQ_TIMER1 56 /* 57. *_INTR_STATUS_REG_1, bit 24 */
+#define XTENSA_IRQ_TIMER2 57 /* 58. *_INTR_STATUS_REG_1, bit 25 */
+#define XTENSA_IRQ_TG_T0_EDGE 58 /* 59. *_INTR_STATUS_REG_1, bit 26 */
+#define XTENSA_IRQ_TG_T1_EDGE 59 /* 60. *_INTR_STATUS_REG_1, bit 27 */
+#define XTENSA_IRQ_TG_WDT_EDGE 60 /* 61. *_INTR_STATUS_REG_1, bit 28 */
+#define XTENSA_IRQ_TG_LACT_EDGE 61 /* 62. *_INTR_STATUS_REG_1, bit 29 */
+
+#define XTENSA_IRQ_TG1_T0_EDGE 62 /* 63. *_INTR_STATUS_REG_1, bit 30 */
+#define XTENSA_IRQ_TG1_T1_EDGE 63 /* 64. *_INTR_STATUS_REG_1, bit 31 */
+
+/* PRO_INTR_STATUS_REG_2 / APP_INTR_STATUS_REG_2 */
+
+#define XTENSA_IRQ_TG1_WDT_EDGE 64 /* 65. *_INTR_STATUS_REG_2, bit 0 */
+#define XTENSA_IRQ_TG1_LACT_EDGE 65 /* 66. *_INTR_STATUS_REG_2, bit 1 */
+#define XTENSA_IRQ_MMU_IA 66 /* 67. *_INTR_STATUS_REG_2, bit 2 */
+#define XTENSA_IRQ_MPU_IA 67 /* 68. *_INTR_STATUS_REG_2, bit 3 */
+#define XTENSA_IRQ_CACHE_IA 68 /* 69. *_INTR_STATUS_REG_2, bit 4 */
+
+/* Total number of interrupts */
+
+#define NR_IRQS 69
/****************************************************************************
* Public Types
--
GitLab
From 30598c005f59d40d56cb6eb5551b0fc0a2c2bbf7 Mon Sep 17 00:00:00 2001
From: Gregory Nutt
Date: Sat, 15 Oct 2016 08:56:11 -0600
Subject: [PATCH 075/734] Cosmetic changes from review of last PR
---
arch/arm/src/stm32/stm32_serial.c | 45 ++++++++++++++++---------------
1 file changed, 23 insertions(+), 22 deletions(-)
diff --git a/arch/arm/src/stm32/stm32_serial.c b/arch/arm/src/stm32/stm32_serial.c
index 381df6c016..6152d5795d 100644
--- a/arch/arm/src/stm32/stm32_serial.c
+++ b/arch/arm/src/stm32/stm32_serial.c
@@ -1189,6 +1189,13 @@ static int up_dma_nextrx(struct up_dev_s *priv)
static void up_set_format(struct uart_dev_s *dev)
{
struct up_dev_s *priv = (struct up_dev_s *)dev->priv;
+#if defined(CONFIG_STM32_STM32F30XX) || defined(CONFIG_STM32_STM32F37XX)
+ uint32_t usartdiv8;
+#else
+ uint32_t usartdiv32;
+ uint32_t mantissa;
+ uint32_t fraction;
+#endif
uint32_t regval;
uint32_t brr;
@@ -1201,11 +1208,8 @@ static void up_set_format(struct uart_dev_s *dev)
* by 8 in additional to the standard oversampling by 16.
* With baud rate of fCK / Divider for oversampling by 16.
* and baud rate of 2 * fCK / Divider for oversampling by 8
- */
-
- uint32_t usartdiv8;
-
- /* In case of oversampling by 8, the equation is:
+ *
+ * In case of oversampling by 8, the equation is:
*
* baud = 2 * fCK / usartdiv8
* usartdiv8 = 2 * fCK / baud
@@ -1219,10 +1223,10 @@ static void up_set_format(struct uart_dev_s *dev)
* baud = fCK / usartdiv16
* usartdiv16 = fCK / baud
* = 2 * usartdiv8
+ *
+ * Use oversamply by 8 only if the divisor is small. But what is small?
*/
- /* Use oversamply by 8 only if the divisor is small. But what is small? */
-
if (usartdiv8 > 100)
{
/* Use usartdiv16 */
@@ -1247,16 +1251,10 @@ static void up_set_format(struct uart_dev_s *dev)
}
#else
-
/* This second implementation is for U[S]ARTs that support fractional
* dividers.
- */
-
- uint32_t usartdiv32;
- uint32_t mantissa;
- uint32_t fraction;
-
- /* Configure the USART Baud Rate. The baud rate for the receiver and
+ *
+ * Configure the USART Baud Rate. The baud rate for the receiver and
* transmitter (Rx and Tx) are both set to the same value as programmed
* in the Mantissa and Fraction values of USARTDIV.
*
@@ -1283,9 +1281,9 @@ static void up_set_format(struct uart_dev_s *dev)
fraction = (usartdiv32 - (mantissa << 5) + 1) >> 1;
#if defined(CONFIG_STM32_STM32F40XX)
-
/* The F4 supports 8 X in oversampling additional to the
* standard oversampling by 16.
+ *
* With baud rate of fCK / (16 * Divider) for oversampling by 16.
* and baud rate of fCK / (8 * Divider) for oversampling by 8
*/
@@ -1300,18 +1298,20 @@ static void up_set_format(struct uart_dev_s *dev)
mantissa = usartdiv32 >> 4;
- /* The fractional remainder (with rounding) */
+ /* The fractional remainder (with rounding) */
- fraction = (usartdiv32 - (mantissa << 4) + 1) >> 1;
+ fraction = (usartdiv32 - (mantissa << 4) + 1) >> 1;
}
else
- {/* Use 16x Oversampling */
+ {
+ /* Use 16x Oversampling */
+
regval &= ~USART_CR1_OVER8;
}
#endif
- brr = mantissa << USART_BRR_MANT_SHIFT;
- brr |= fraction << USART_BRR_FRAC_SHIFT;
+ brr = mantissa << USART_BRR_MANT_SHIFT;
+ brr |= fraction << USART_BRR_FRAC_SHIFT;
#endif
up_serialout(priv, STM32_USART_CR1_OFFSET, regval);
@@ -1364,7 +1364,8 @@ static void up_set_format(struct uart_dev_s *dev)
regval = up_serialin(priv, STM32_USART_CR3_OFFSET);
regval &= ~(USART_CR3_CTSE | USART_CR3_RTSE);
-#if defined(CONFIG_SERIAL_IFLOWCONTROL) && !defined(CONFIG_STM32_FLOWCONTROL_BROKEN)
+#if defined(CONFIG_SERIAL_IFLOWCONTROL) && \
+ !defined(CONFIG_STM32_FLOWCONTROL_BROKEN)
if (priv->iflow && (priv->rts_gpio != 0))
{
regval |= USART_CR3_RTSE;
--
GitLab
From 0b3c75f6bd50908adb19ea37d5355fd18a60334e Mon Sep 17 00:00:00 2001
From: David Sidrane
Date: Sat, 15 Oct 2016 05:15:40 -1000
Subject: [PATCH 076/734] Fixes sscan %sn where strlen(data) < n
---
libc/stdio/lib_sscanf.c | 21 ++++++++++++++-------
1 file changed, 14 insertions(+), 7 deletions(-)
diff --git a/libc/stdio/lib_sscanf.c b/libc/stdio/lib_sscanf.c
index ae8774cc57..50125e9bff 100644
--- a/libc/stdio/lib_sscanf.c
+++ b/libc/stdio/lib_sscanf.c
@@ -164,7 +164,7 @@ int sscanf(FAR const char *buf, FAR const char *fmt, ...)
* ANSI standard vsscanf implementation.
*
****************************************************************************/
-
+#pragma GCC optimize ("O0")
int vsscanf(FAR const char *buf, FAR const char *fmt, va_list ap)
{
FAR const char *bufstart;
@@ -174,6 +174,7 @@ int vsscanf(FAR const char *buf, FAR const char *fmt, va_list ap)
bool noassign;
int count;
int width;
+ int fwidth;
int base = 10;
char tmp[MAXLN];
@@ -275,16 +276,22 @@ int vsscanf(FAR const char *buf, FAR const char *fmt, va_list ap)
buf++;
}
- /* Was a fieldwidth specified? */
+ /* Guess a field width using some heuristics */
- if (!width)
- {
- /* No... Guess a field width using some heuristics */
+ fwidth = findwidth(buf, fmt);
- int tmpwidth = findwidth(buf, fmt);
- width = MIN(sizeof(tmp) - 1, tmpwidth);
+ /* Use the actual field's width if 1) no fieldwidth
+ * specified or 2) the actual field's width is smaller
+ * than fieldwidth specified
+ */
+
+ if (!width || fwidth < width)
+ {
+ width = fwidth;
}
+ width = MIN(sizeof(tmp) - 1, width);
+
/* Copy the string (if we are making an assignment) */
if (!noassign)
--
GitLab
From 55b798c35758bd53f0ae8b499dca5869cdc6e75c Mon Sep 17 00:00:00 2001
From: David Sidrane
Date: Sat, 15 Oct 2016 05:23:18 -1000
Subject: [PATCH 077/734] Indented
---
libc/stdio/lib_sscanf.c | 201 +++++++++++++++++-----------------------
1 file changed, 87 insertions(+), 114 deletions(-)
diff --git a/libc/stdio/lib_sscanf.c b/libc/stdio/lib_sscanf.c
index 50125e9bff..3e8cd6c9ec 100644
--- a/libc/stdio/lib_sscanf.c
+++ b/libc/stdio/lib_sscanf.c
@@ -93,8 +93,7 @@ static int findwidth(FAR const char *buf, FAR const char *fmt)
FAR const char *next = fmt + 1;
/* No... is there a space after the format? Or does the format string end
- * here?
- */
+ * here? */
if (isspace(*next) || *next == 0)
{
@@ -103,15 +102,13 @@ static int findwidth(FAR const char *buf, FAR const char *fmt)
return strcspn(buf, spaces);
}
- /* No.. Another possibility is the format character is followed by
- * some recognizable delimiting value.
- */
+ /* No.. Another possibility is the format character is followed by some
+ * recognizable delimiting value. */
if (*next != '%')
{
/* If so we will say that the string ends there if we can find that
- * delimiter in the input string.
- */
+ * delimiter in the input string. */
FAR const char *ptr = strchr(buf, *next);
if (ptr)
@@ -120,16 +117,14 @@ static int findwidth(FAR const char *buf, FAR const char *fmt)
}
}
- /* No... the format has no delimiter and is back-to-back with the next
- * format (or is followed by a delimiter that does not exist in the
- * input string). At this point we just bail and Use the input up until
- * the first white space is encountered.
- *
- * NOTE: This means that values from the following format may be
- * concatenated with the first. This is a bug. We have no generic way of
- * determining the width of the data if there is no fieldwidth, no space
- * separating the input, and no usable delimiter character.
- */
+ /* No... the format has no delimiter and is back-to-back with the next format
+ * (or is followed by a delimiter that does not exist in the input string).
+ * At this point we just bail and Use the input up until the first white
+ * space is encountered. NOTE: This means that values from the following
+ * format may be concatenated with the first. This is a bug. We have no
+ * generic way of determining the width of the data if there is no
+ * fieldwidth, no space separating the input, and no usable delimiter
+ * character. */
return strcspn(buf, spaces);
}
@@ -149,7 +144,7 @@ static int findwidth(FAR const char *buf, FAR const char *fmt)
int sscanf(FAR const char *buf, FAR const char *fmt, ...)
{
va_list ap;
- int count;
+ int count;
va_start(ap, fmt);
count = vsscanf((FAR const char *)buf, fmt, ap);
@@ -168,35 +163,33 @@ int sscanf(FAR const char *buf, FAR const char *fmt, ...)
int vsscanf(FAR const char *buf, FAR const char *fmt, va_list ap)
{
FAR const char *bufstart;
- FAR char *tv;
+ FAR char *tv;
FAR const char *tc;
- bool lflag;
- bool noassign;
- int count;
- int width;
- int fwidth;
- int base = 10;
- char tmp[MAXLN];
+ bool lflag;
+ bool noassign;
+ int count;
+ int width;
+ int fwidth;
+ int base = 10;
+ char tmp[MAXLN];
linfo("vsscanf: buf=\"%s\" fmt=\"%s\"\n", buf, fmt);
/* Remember the start of the input buffer. We will need this for %n
- * calculations.
- */
+ * calculations. */
bufstart = buf;
/* Parse the format, extracting values from the input buffer as needed */
- count = 0;
- width = 0;
+ count = 0;
+ width = 0;
noassign = false;
- lflag = false;
+ lflag = false;
- /* Loop until all characters in the fmt string have been processed. We
- * may have to continue loop after reaching the end the input data in
- * order to handle trailing %n format specifiers.
- */
+ /* Loop until all characters in the fmt string have been processed. We may
+ * have to continue loop after reaching the end the input data in order to
+ * handle trailing %n format specifiers. */
while (*fmt)
{
@@ -245,27 +238,25 @@ int vsscanf(FAR const char *buf, FAR const char *fmt, va_list ap)
}
}
- /* Process %s: String conversion */
+ /* Process %s: String conversion */
if (*fmt == 's')
{
linfo("vsscanf: Performing string conversion\n");
- /* Get a pointer to the char * value. We need to do this even
- * if we have reached the end of the input data in order to
- * update the 'ap' variable.
- */
+ /* Get a pointer to the char * value. We need to do this even if
+ * we have reached the end of the input data in order to update
+ * the 'ap' variable. */
- tv = NULL; /* To avoid warnings about begin uninitialized */
+ tv = NULL; /* To avoid warnings about begin uninitialized */
if (!noassign)
{
- tv = va_arg(ap, FAR char *);
+ tv = va_arg(ap, FAR char *);
tv[0] = '\0';
}
- /* But we only perform the data conversion is we still have
- * bytes remaining in the input data stream.
- */
+ /* But we only perform the data conversion is we still have bytes
+ * remaining in the input data stream. */
if (*buf)
{
@@ -280,14 +271,13 @@ int vsscanf(FAR const char *buf, FAR const char *fmt, va_list ap)
fwidth = findwidth(buf, fmt);
- /* Use the actual field's width if 1) no fieldwidth
- * specified or 2) the actual field's width is smaller
- * than fieldwidth specified
- */
+ /* Use the actual field's width if 1) no fieldwidth specified
+ * or 2) the actual field's width is smaller than fieldwidth
+ * specified */
if (!width || fwidth < width)
{
- width = fwidth;
+ width = fwidth;
}
width = MIN(sizeof(tmp) - 1, width);
@@ -307,27 +297,25 @@ int vsscanf(FAR const char *buf, FAR const char *fmt, va_list ap)
}
}
- /* Process %c: Character conversion */
+ /* Process %c: Character conversion */
else if (*fmt == 'c')
{
linfo("vsscanf: Performing character conversion\n");
- /* Get a pointer to the char * value. We need to do this even
- * if we have reached the end of the input data in order to
- * update the 'ap' variable.
- */
+ /* Get a pointer to the char * value. We need to do this even if
+ * we have reached the end of the input data in order to update
+ * the 'ap' variable. */
- tv = NULL; /* To avoid warnings about beign uninitialized */
+ tv = NULL; /* To avoid warnings about beign uninitialized */
if (!noassign)
{
- tv = va_arg(ap, FAR char *);
+ tv = va_arg(ap, FAR char *);
tv[0] = '\0';
}
- /* But we only perform the data conversion is we still have
- * bytes remaining in the input data stream.
- */
+ /* But we only perform the data conversion is we still have bytes
+ * remaining in the input data stream. */
if (*buf)
{
@@ -350,33 +338,30 @@ int vsscanf(FAR const char *buf, FAR const char *fmt, va_list ap)
}
/* Update the buffer pointer past the character(s) in the
- * input
- */
+ * input */
buf += width;
}
}
- /* Process %d, %o, %b, %x, %u: Various integer conversions */
+ /* Process %d, %o, %b, %x, %u: Various integer conversions */
else if (strchr("dobxu", *fmt))
{
FAR long *plong = NULL;
- FAR int *pint = NULL;
+ FAR int *pint = NULL;
bool sign;
linfo("vsscanf: Performing integer conversion\n");
/* Get a pointer to the integer value. We need to do this even
* if we have reached the end of the input data in order to
- * update the 'ap' variable.
- */
+ * update the 'ap' variable. */
if (!noassign)
{
/* We have to check whether we need to return a long or an
- * int.
- */
+ * int. */
if (lflag)
{
@@ -390,15 +375,14 @@ int vsscanf(FAR const char *buf, FAR const char *fmt, va_list ap)
}
}
- /* But we only perform the data conversion if we still have
- * bytes remaining in the input data stream.
- */
+ /* But we only perform the data conversion if we still have bytes
+ * remaining in the input data stream. */
if (*buf)
{
FAR char *endptr;
- int errsave;
- long tmplong;
+ int errsave;
+ long tmplong;
/* Skip over any white space before the integer string */
@@ -407,9 +391,8 @@ int vsscanf(FAR const char *buf, FAR const char *fmt, va_list ap)
buf++;
}
- /* The base of the integer conversion depends on the
- * specific conversion specification.
- */
+ /* The base of the integer conversion depends on the specific
+ * conversion specification. */
sign = false;
switch (*fmt)
@@ -445,9 +428,7 @@ int vsscanf(FAR const char *buf, FAR const char *fmt, va_list ap)
width = MIN(sizeof(tmp) - 1, tmpwidth);
}
- /* Copy the numeric string into a temporary working
- * buffer.
- */
+ /* Copy the numeric string into a temporary working buffer. */
strncpy(tmp, buf, width);
tmp[width] = '\0';
@@ -482,9 +463,8 @@ int vsscanf(FAR const char *buf, FAR const char *fmt, va_list ap)
if (!noassign)
{
- /* We have to check whether we need to return a long
- * or an int.
- */
+ /* We have to check whether we need to return a long or
+ * an int. */
if (lflag)
{
@@ -494,8 +474,7 @@ int vsscanf(FAR const char *buf, FAR const char *fmt, va_list ap)
}
else
{
- linfo("vsscanf: Return %ld to 0x%p\n",
- tmplong, pint);
+ linfo("vsscanf: Return %ld to 0x%p\n", tmplong, pint);
*pint = (int)tmplong;
}
@@ -504,48 +483,44 @@ int vsscanf(FAR const char *buf, FAR const char *fmt, va_list ap)
}
}
- /* Process %a, %A, %f, %F, %e, %E, %g, and %G: Floating point
- * conversions
- */
+ /* Process %a, %A, %f, %F, %e, %E, %g, and %G: Floating point
+ * conversions */
else if (strchr("aAfFeEgG", *fmt) != NULL)
{
#ifdef CONFIG_HAVE_DOUBLE
FAR double_t *pd = NULL;
#endif
- FAR float *pf = NULL;
+ FAR float *pf = NULL;
linfo("vsscanf: Performing floating point conversion\n");
- /* Get a pointer to the double value. We need to do this even
- * if we have reached the end of the input data in order to
- * update the 'ap' variable.
- */
+ /* Get a pointer to the double value. We need to do this even if
+ * we have reached the end of the input data in order to update
+ * the 'ap' variable. */
if (!noassign)
{
/* We have to check whether we need to return a float or a
- * double.
- */
+ * double. */
#ifdef CONFIG_HAVE_DOUBLE
if (lflag)
{
- pd = va_arg(ap, FAR double_t *);
+ pd = va_arg(ap, FAR double_t *);
*pd = 0.0;
}
else
#endif
{
- pf = va_arg(ap, FAR float *);
+ pf = va_arg(ap, FAR float *);
*pf = 0.0;
}
}
#ifdef CONFIG_LIBC_FLOATINGPOINT
- /* But we only perform the data conversion is we still have
- * bytes remaining in the input data stream.
- */
+ /* But we only perform the data conversion is we still have bytes
+ * remaining in the input data stream. */
if (*buf)
{
@@ -580,14 +555,14 @@ int vsscanf(FAR const char *buf, FAR const char *fmt, va_list ap)
/* strtod always returns a double */
FAR char *endptr;
- int errsave;
- double_t dvalue;
+ int errsave;
+ double_t dvalue;
/* Preserve the errno value */
errsave = get_errno();
set_errno(0);
- dvalue = strtod(tmp, &endptr);
+ dvalue = strtod(tmp, &endptr);
/* Check if the number was successfully converted */
@@ -598,18 +573,17 @@ int vsscanf(FAR const char *buf, FAR const char *fmt, va_list ap)
set_errno(errsave);
- /* We have to check whether we need to return a float
- * or a double.
- */
+ /* We have to check whether we need to return a float or
+ * a double. */
-#ifdef CONFIG_HAVE_DOUBLE
+# ifdef CONFIG_HAVE_DOUBLE
if (lflag)
{
linfo("vsscanf: Return %f to %p\n", dvalue, pd);
*pd = dvalue;
}
else
-#endif
+# endif
{
linfo("vsscanf: Return %f to %p\n", dvalue, pf);
*pf = (float)dvalue;
@@ -621,7 +595,7 @@ int vsscanf(FAR const char *buf, FAR const char *fmt, va_list ap)
#endif
}
- /* Process %n: Character count */
+ /* Process %n: Character count */
else if (*fmt == 'n')
{
@@ -629,7 +603,7 @@ int vsscanf(FAR const char *buf, FAR const char *fmt, va_list ap)
if (!noassign)
{
- size_t nchars = (size_t)(buf - bufstart);
+ size_t nchars = (size_t) (buf - bufstart);
/* Note %n does not count as a conversion */
@@ -646,14 +620,14 @@ int vsscanf(FAR const char *buf, FAR const char *fmt, va_list ap)
}
}
- width = 0;
+ width = 0;
noassign = false;
- lflag = false;
+ lflag = false;
fmt++;
}
- /* It is not a conversion specifier */
+ /* It is not a conversion specifier */
else if (*buf)
{
@@ -685,8 +659,7 @@ int vsscanf(FAR const char *buf, FAR const char *fmt, va_list ap)
}
/* sscanf is required to return EOF if the input ends before the first
- * matching failure or conversion.
- */
+ * matching failure or conversion. */
return count ? count : EOF;
}
--
GitLab
From d538b6b3183d135f2d9d88dcfd77f71ba804c20a Mon Sep 17 00:00:00 2001
From: David Sidrane
Date: Sat, 15 Oct 2016 06:00:00 -1000
Subject: [PATCH 078/734] Removed debug pragma
---
libc/stdio/lib_sscanf.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libc/stdio/lib_sscanf.c b/libc/stdio/lib_sscanf.c
index 3e8cd6c9ec..7c73e476ea 100644
--- a/libc/stdio/lib_sscanf.c
+++ b/libc/stdio/lib_sscanf.c
@@ -159,7 +159,7 @@ int sscanf(FAR const char *buf, FAR const char *fmt, ...)
* ANSI standard vsscanf implementation.
*
****************************************************************************/
-#pragma GCC optimize ("O0")
+
int vsscanf(FAR const char *buf, FAR const char *fmt, va_list ap)
{
FAR const char *bufstart;
--
GitLab
From 0be3d12ba007fdcf6d5c330801ff83bb83824f8c Mon Sep 17 00:00:00 2001
From: Gregory Nutt
Date: Sat, 15 Oct 2016 10:11:35 -0600
Subject: [PATCH 079/734] ESP32: Add option for interrupt support
---
arch/xtensa/Kconfig | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/arch/xtensa/Kconfig b/arch/xtensa/Kconfig
index 1bd5c0f54d..6befe7eff2 100644
--- a/arch/xtensa/Kconfig
+++ b/arch/xtensa/Kconfig
@@ -12,6 +12,7 @@ choice
config ARCH_CHIP_ESP32
bool "Expressif ESP32"
select ARCH_FAMILY_LX6
+ select XTENSA_HAVE_INTERRUPTS
---help---
The ESP32 is a dual-core system from Expressif with two Harvard
architecture Xtensa LX6 CPUs. All embedded memory, external memory
@@ -33,6 +34,10 @@ config XTENSA_HAVE_LOOPS
bool "Zero overhead loops"
default n
+config XTENSA_HAVE_INTERRUPTS
+ bool
+ default n
+
config XTENSA_USE_SWPRI
bool "Use SWPRI"
default n
--
GitLab
From 887895bf165ec8d3199426eebb0ddf1d05cdc1cd Mon Sep 17 00:00:00 2001
From: Gregory Nutt
Date: Sat, 15 Oct 2016 10:23:42 -0600
Subject: [PATCH 080/734] Revert last merge. That merge addes too many coding
style violations.
---
libc/stdio/lib_sscanf.c | 73 +++++++++++++++++++++++++++--------------
1 file changed, 48 insertions(+), 25 deletions(-)
diff --git a/libc/stdio/lib_sscanf.c b/libc/stdio/lib_sscanf.c
index 7c73e476ea..8ba7f9bfe4 100644
--- a/libc/stdio/lib_sscanf.c
+++ b/libc/stdio/lib_sscanf.c
@@ -93,7 +93,8 @@ static int findwidth(FAR const char *buf, FAR const char *fmt)
FAR const char *next = fmt + 1;
/* No... is there a space after the format? Or does the format string end
- * here? */
+ * here?
+ */
if (isspace(*next) || *next == 0)
{
@@ -103,12 +104,14 @@ static int findwidth(FAR const char *buf, FAR const char *fmt)
}
/* No.. Another possibility is the format character is followed by some
- * recognizable delimiting value. */
+ * recognizable delimiting value.
+ */
if (*next != '%')
{
/* If so we will say that the string ends there if we can find that
- * delimiter in the input string. */
+ * delimiter in the input string.
+ */
FAR const char *ptr = strchr(buf, *next);
if (ptr)
@@ -124,7 +127,8 @@ static int findwidth(FAR const char *buf, FAR const char *fmt)
* format may be concatenated with the first. This is a bug. We have no
* generic way of determining the width of the data if there is no
* fieldwidth, no space separating the input, and no usable delimiter
- * character. */
+ * character.
+ */
return strcspn(buf, spaces);
}
@@ -176,7 +180,8 @@ int vsscanf(FAR const char *buf, FAR const char *fmt, va_list ap)
linfo("vsscanf: buf=\"%s\" fmt=\"%s\"\n", buf, fmt);
/* Remember the start of the input buffer. We will need this for %n
- * calculations. */
+ * calculations.
+ */
bufstart = buf;
@@ -189,7 +194,8 @@ int vsscanf(FAR const char *buf, FAR const char *fmt, va_list ap)
/* Loop until all characters in the fmt string have been processed. We may
* have to continue loop after reaching the end the input data in order to
- * handle trailing %n format specifiers. */
+ * handle trailing %n format specifiers.
+ */
while (*fmt)
{
@@ -246,7 +252,8 @@ int vsscanf(FAR const char *buf, FAR const char *fmt, va_list ap)
/* Get a pointer to the char * value. We need to do this even if
* we have reached the end of the input data in order to update
- * the 'ap' variable. */
+ * the 'ap' variable.
+ */
tv = NULL; /* To avoid warnings about begin uninitialized */
if (!noassign)
@@ -256,7 +263,8 @@ int vsscanf(FAR const char *buf, FAR const char *fmt, va_list ap)
}
/* But we only perform the data conversion is we still have bytes
- * remaining in the input data stream. */
+ * remaining in the input data stream.
+ */
if (*buf)
{
@@ -273,7 +281,8 @@ int vsscanf(FAR const char *buf, FAR const char *fmt, va_list ap)
/* Use the actual field's width if 1) no fieldwidth specified
* or 2) the actual field's width is smaller than fieldwidth
- * specified */
+ * specified
+ */
if (!width || fwidth < width)
{
@@ -305,7 +314,8 @@ int vsscanf(FAR const char *buf, FAR const char *fmt, va_list ap)
/* Get a pointer to the char * value. We need to do this even if
* we have reached the end of the input data in order to update
- * the 'ap' variable. */
+ * the 'ap' variable.
+ */
tv = NULL; /* To avoid warnings about beign uninitialized */
if (!noassign)
@@ -315,7 +325,8 @@ int vsscanf(FAR const char *buf, FAR const char *fmt, va_list ap)
}
/* But we only perform the data conversion is we still have bytes
- * remaining in the input data stream. */
+ * remaining in the input data stream.
+ */
if (*buf)
{
@@ -338,7 +349,8 @@ int vsscanf(FAR const char *buf, FAR const char *fmt, va_list ap)
}
/* Update the buffer pointer past the character(s) in the
- * input */
+ * input.
+ */
buf += width;
}
@@ -356,12 +368,14 @@ int vsscanf(FAR const char *buf, FAR const char *fmt, va_list ap)
/* Get a pointer to the integer value. We need to do this even
* if we have reached the end of the input data in order to
- * update the 'ap' variable. */
+ * update the 'ap' variable.
+ */
if (!noassign)
{
/* We have to check whether we need to return a long or an
- * int. */
+ * int.
+ */
if (lflag)
{
@@ -376,7 +390,8 @@ int vsscanf(FAR const char *buf, FAR const char *fmt, va_list ap)
}
/* But we only perform the data conversion if we still have bytes
- * remaining in the input data stream. */
+ * remaining in the input data stream.
+ */
if (*buf)
{
@@ -392,7 +407,8 @@ int vsscanf(FAR const char *buf, FAR const char *fmt, va_list ap)
}
/* The base of the integer conversion depends on the specific
- * conversion specification. */
+ * conversion specification.
+ */
sign = false;
switch (*fmt)
@@ -464,7 +480,8 @@ int vsscanf(FAR const char *buf, FAR const char *fmt, va_list ap)
{
/* We have to check whether we need to return a long or
- * an int. */
+ * an int.
+ */
if (lflag)
{
@@ -484,7 +501,8 @@ int vsscanf(FAR const char *buf, FAR const char *fmt, va_list ap)
}
/* Process %a, %A, %f, %F, %e, %E, %g, and %G: Floating point
- * conversions */
+ * conversions.
+ */
else if (strchr("aAfFeEgG", *fmt) != NULL)
{
@@ -497,12 +515,14 @@ int vsscanf(FAR const char *buf, FAR const char *fmt, va_list ap)
/* Get a pointer to the double value. We need to do this even if
* we have reached the end of the input data in order to update
- * the 'ap' variable. */
+ * the 'ap' variable.
+ */
if (!noassign)
{
/* We have to check whether we need to return a float or a
- * double. */
+ * double.
+ */
#ifdef CONFIG_HAVE_DOUBLE
if (lflag)
@@ -520,7 +540,8 @@ int vsscanf(FAR const char *buf, FAR const char *fmt, va_list ap)
#ifdef CONFIG_LIBC_FLOATINGPOINT
/* But we only perform the data conversion is we still have bytes
- * remaining in the input data stream. */
+ * remaining in the input data stream.
+ */
if (*buf)
{
@@ -574,16 +595,17 @@ int vsscanf(FAR const char *buf, FAR const char *fmt, va_list ap)
set_errno(errsave);
/* We have to check whether we need to return a float or
- * a double. */
+ * a double.
+ */
-# ifdef CONFIG_HAVE_DOUBLE
+#ifdef CONFIG_HAVE_DOUBLE
if (lflag)
{
linfo("vsscanf: Return %f to %p\n", dvalue, pd);
*pd = dvalue;
}
else
-# endif
+#endif
{
linfo("vsscanf: Return %f to %p\n", dvalue, pf);
*pf = (float)dvalue;
@@ -659,7 +681,8 @@ int vsscanf(FAR const char *buf, FAR const char *fmt, va_list ap)
}
/* sscanf is required to return EOF if the input ends before the first
- * matching failure or conversion. */
+ * matching failure or conversion.
+ */
return count ? count : EOF;
}
--
GitLab
From 7ee82c0168c0b8464aa6e36781d06f48a3eccee2 Mon Sep 17 00:00:00 2001
From: David Sidrane
Date: Sat, 15 Oct 2016 05:15:40 -1000
Subject: [PATCH 081/734] Fixes sscan %sn where strlen(data) < n
---
libc/stdio/lib_sscanf.c | 19 +++++++++++++------
1 file changed, 13 insertions(+), 6 deletions(-)
diff --git a/libc/stdio/lib_sscanf.c b/libc/stdio/lib_sscanf.c
index ae8774cc57..50bcd8956e 100644
--- a/libc/stdio/lib_sscanf.c
+++ b/libc/stdio/lib_sscanf.c
@@ -174,6 +174,7 @@ int vsscanf(FAR const char *buf, FAR const char *fmt, va_list ap)
bool noassign;
int count;
int width;
+ int fwidth;
int base = 10;
char tmp[MAXLN];
@@ -275,16 +276,22 @@ int vsscanf(FAR const char *buf, FAR const char *fmt, va_list ap)
buf++;
}
- /* Was a fieldwidth specified? */
+ /* Guess a field width using some heuristics */
- if (!width)
- {
- /* No... Guess a field width using some heuristics */
+ fwidth = findwidth(buf, fmt);
- int tmpwidth = findwidth(buf, fmt);
- width = MIN(sizeof(tmp) - 1, tmpwidth);
+ /* Use the actual field's width if 1) no fieldwidth
+ * specified or 2) the actual field's width is smaller
+ * than fieldwidth specified
+ */
+
+ if (!width || fwidth < width)
+ {
+ width = fwidth;
}
+ width = MIN(sizeof(tmp) - 1, width);
+
/* Copy the string (if we are making an assignment) */
if (!noassign)
--
GitLab
From 4034a23704cd204f6e6854317de447000beae75f Mon Sep 17 00:00:00 2001
From: Gregory Nutt
Date: Sat, 15 Oct 2016 10:42:15 -0600
Subject: [PATCH 082/734] Finish backing out the last PR that corrupted the
file coding standard
---
libc/stdio/lib_sscanf.c | 169 ++++++++++++++++++++--------------------
1 file changed, 83 insertions(+), 86 deletions(-)
diff --git a/libc/stdio/lib_sscanf.c b/libc/stdio/lib_sscanf.c
index 8ba7f9bfe4..ae8774cc57 100644
--- a/libc/stdio/lib_sscanf.c
+++ b/libc/stdio/lib_sscanf.c
@@ -103,8 +103,8 @@ static int findwidth(FAR const char *buf, FAR const char *fmt)
return strcspn(buf, spaces);
}
- /* No.. Another possibility is the format character is followed by some
- * recognizable delimiting value.
+ /* No.. Another possibility is the format character is followed by
+ * some recognizable delimiting value.
*/
if (*next != '%')
@@ -120,14 +120,15 @@ static int findwidth(FAR const char *buf, FAR const char *fmt)
}
}
- /* No... the format has no delimiter and is back-to-back with the next format
- * (or is followed by a delimiter that does not exist in the input string).
- * At this point we just bail and Use the input up until the first white
- * space is encountered. NOTE: This means that values from the following
- * format may be concatenated with the first. This is a bug. We have no
- * generic way of determining the width of the data if there is no
- * fieldwidth, no space separating the input, and no usable delimiter
- * character.
+ /* No... the format has no delimiter and is back-to-back with the next
+ * format (or is followed by a delimiter that does not exist in the
+ * input string). At this point we just bail and Use the input up until
+ * the first white space is encountered.
+ *
+ * NOTE: This means that values from the following format may be
+ * concatenated with the first. This is a bug. We have no generic way of
+ * determining the width of the data if there is no fieldwidth, no space
+ * separating the input, and no usable delimiter character.
*/
return strcspn(buf, spaces);
@@ -148,7 +149,7 @@ static int findwidth(FAR const char *buf, FAR const char *fmt)
int sscanf(FAR const char *buf, FAR const char *fmt, ...)
{
va_list ap;
- int count;
+ int count;
va_start(ap, fmt);
count = vsscanf((FAR const char *)buf, fmt, ap);
@@ -167,15 +168,14 @@ int sscanf(FAR const char *buf, FAR const char *fmt, ...)
int vsscanf(FAR const char *buf, FAR const char *fmt, va_list ap)
{
FAR const char *bufstart;
- FAR char *tv;
+ FAR char *tv;
FAR const char *tc;
- bool lflag;
- bool noassign;
- int count;
- int width;
- int fwidth;
- int base = 10;
- char tmp[MAXLN];
+ bool lflag;
+ bool noassign;
+ int count;
+ int width;
+ int base = 10;
+ char tmp[MAXLN];
linfo("vsscanf: buf=\"%s\" fmt=\"%s\"\n", buf, fmt);
@@ -187,14 +187,14 @@ int vsscanf(FAR const char *buf, FAR const char *fmt, va_list ap)
/* Parse the format, extracting values from the input buffer as needed */
- count = 0;
- width = 0;
+ count = 0;
+ width = 0;
noassign = false;
- lflag = false;
+ lflag = false;
- /* Loop until all characters in the fmt string have been processed. We may
- * have to continue loop after reaching the end the input data in order to
- * handle trailing %n format specifiers.
+ /* Loop until all characters in the fmt string have been processed. We
+ * may have to continue loop after reaching the end the input data in
+ * order to handle trailing %n format specifiers.
*/
while (*fmt)
@@ -244,26 +244,26 @@ int vsscanf(FAR const char *buf, FAR const char *fmt, va_list ap)
}
}
- /* Process %s: String conversion */
+ /* Process %s: String conversion */
if (*fmt == 's')
{
linfo("vsscanf: Performing string conversion\n");
- /* Get a pointer to the char * value. We need to do this even if
- * we have reached the end of the input data in order to update
- * the 'ap' variable.
+ /* Get a pointer to the char * value. We need to do this even
+ * if we have reached the end of the input data in order to
+ * update the 'ap' variable.
*/
- tv = NULL; /* To avoid warnings about begin uninitialized */
+ tv = NULL; /* To avoid warnings about begin uninitialized */
if (!noassign)
{
- tv = va_arg(ap, FAR char *);
+ tv = va_arg(ap, FAR char *);
tv[0] = '\0';
}
- /* But we only perform the data conversion is we still have bytes
- * remaining in the input data stream.
+ /* But we only perform the data conversion is we still have
+ * bytes remaining in the input data stream.
*/
if (*buf)
@@ -275,21 +275,15 @@ int vsscanf(FAR const char *buf, FAR const char *fmt, va_list ap)
buf++;
}
- /* Guess a field width using some heuristics */
-
- fwidth = findwidth(buf, fmt);
-
- /* Use the actual field's width if 1) no fieldwidth specified
- * or 2) the actual field's width is smaller than fieldwidth
- * specified
- */
+ /* Was a fieldwidth specified? */
- if (!width || fwidth < width)
+ if (!width)
{
- width = fwidth;
- }
+ /* No... Guess a field width using some heuristics */
- width = MIN(sizeof(tmp) - 1, width);
+ int tmpwidth = findwidth(buf, fmt);
+ width = MIN(sizeof(tmp) - 1, tmpwidth);
+ }
/* Copy the string (if we are making an assignment) */
@@ -306,26 +300,26 @@ int vsscanf(FAR const char *buf, FAR const char *fmt, va_list ap)
}
}
- /* Process %c: Character conversion */
+ /* Process %c: Character conversion */
else if (*fmt == 'c')
{
linfo("vsscanf: Performing character conversion\n");
- /* Get a pointer to the char * value. We need to do this even if
- * we have reached the end of the input data in order to update
- * the 'ap' variable.
+ /* Get a pointer to the char * value. We need to do this even
+ * if we have reached the end of the input data in order to
+ * update the 'ap' variable.
*/
- tv = NULL; /* To avoid warnings about beign uninitialized */
+ tv = NULL; /* To avoid warnings about beign uninitialized */
if (!noassign)
{
- tv = va_arg(ap, FAR char *);
+ tv = va_arg(ap, FAR char *);
tv[0] = '\0';
}
- /* But we only perform the data conversion is we still have bytes
- * remaining in the input data stream.
+ /* But we only perform the data conversion is we still have
+ * bytes remaining in the input data stream.
*/
if (*buf)
@@ -349,19 +343,19 @@ int vsscanf(FAR const char *buf, FAR const char *fmt, va_list ap)
}
/* Update the buffer pointer past the character(s) in the
- * input.
+ * input
*/
buf += width;
}
}
- /* Process %d, %o, %b, %x, %u: Various integer conversions */
+ /* Process %d, %o, %b, %x, %u: Various integer conversions */
else if (strchr("dobxu", *fmt))
{
FAR long *plong = NULL;
- FAR int *pint = NULL;
+ FAR int *pint = NULL;
bool sign;
linfo("vsscanf: Performing integer conversion\n");
@@ -389,15 +383,15 @@ int vsscanf(FAR const char *buf, FAR const char *fmt, va_list ap)
}
}
- /* But we only perform the data conversion if we still have bytes
- * remaining in the input data stream.
+ /* But we only perform the data conversion if we still have
+ * bytes remaining in the input data stream.
*/
if (*buf)
{
FAR char *endptr;
- int errsave;
- long tmplong;
+ int errsave;
+ long tmplong;
/* Skip over any white space before the integer string */
@@ -406,8 +400,8 @@ int vsscanf(FAR const char *buf, FAR const char *fmt, va_list ap)
buf++;
}
- /* The base of the integer conversion depends on the specific
- * conversion specification.
+ /* The base of the integer conversion depends on the
+ * specific conversion specification.
*/
sign = false;
@@ -444,7 +438,9 @@ int vsscanf(FAR const char *buf, FAR const char *fmt, va_list ap)
width = MIN(sizeof(tmp) - 1, tmpwidth);
}
- /* Copy the numeric string into a temporary working buffer. */
+ /* Copy the numeric string into a temporary working
+ * buffer.
+ */
strncpy(tmp, buf, width);
tmp[width] = '\0';
@@ -479,8 +475,8 @@ int vsscanf(FAR const char *buf, FAR const char *fmt, va_list ap)
if (!noassign)
{
- /* We have to check whether we need to return a long or
- * an int.
+ /* We have to check whether we need to return a long
+ * or an int.
*/
if (lflag)
@@ -491,7 +487,8 @@ int vsscanf(FAR const char *buf, FAR const char *fmt, va_list ap)
}
else
{
- linfo("vsscanf: Return %ld to 0x%p\n", tmplong, pint);
+ linfo("vsscanf: Return %ld to 0x%p\n",
+ tmplong, pint);
*pint = (int)tmplong;
}
@@ -500,8 +497,8 @@ int vsscanf(FAR const char *buf, FAR const char *fmt, va_list ap)
}
}
- /* Process %a, %A, %f, %F, %e, %E, %g, and %G: Floating point
- * conversions.
+ /* Process %a, %A, %f, %F, %e, %E, %g, and %G: Floating point
+ * conversions
*/
else if (strchr("aAfFeEgG", *fmt) != NULL)
@@ -509,13 +506,13 @@ int vsscanf(FAR const char *buf, FAR const char *fmt, va_list ap)
#ifdef CONFIG_HAVE_DOUBLE
FAR double_t *pd = NULL;
#endif
- FAR float *pf = NULL;
+ FAR float *pf = NULL;
linfo("vsscanf: Performing floating point conversion\n");
- /* Get a pointer to the double value. We need to do this even if
- * we have reached the end of the input data in order to update
- * the 'ap' variable.
+ /* Get a pointer to the double value. We need to do this even
+ * if we have reached the end of the input data in order to
+ * update the 'ap' variable.
*/
if (!noassign)
@@ -527,20 +524,20 @@ int vsscanf(FAR const char *buf, FAR const char *fmt, va_list ap)
#ifdef CONFIG_HAVE_DOUBLE
if (lflag)
{
- pd = va_arg(ap, FAR double_t *);
+ pd = va_arg(ap, FAR double_t *);
*pd = 0.0;
}
else
#endif
{
- pf = va_arg(ap, FAR float *);
+ pf = va_arg(ap, FAR float *);
*pf = 0.0;
}
}
#ifdef CONFIG_LIBC_FLOATINGPOINT
- /* But we only perform the data conversion is we still have bytes
- * remaining in the input data stream.
+ /* But we only perform the data conversion is we still have
+ * bytes remaining in the input data stream.
*/
if (*buf)
@@ -576,14 +573,14 @@ int vsscanf(FAR const char *buf, FAR const char *fmt, va_list ap)
/* strtod always returns a double */
FAR char *endptr;
- int errsave;
- double_t dvalue;
+ int errsave;
+ double_t dvalue;
/* Preserve the errno value */
errsave = get_errno();
set_errno(0);
- dvalue = strtod(tmp, &endptr);
+ dvalue = strtod(tmp, &endptr);
/* Check if the number was successfully converted */
@@ -594,8 +591,8 @@ int vsscanf(FAR const char *buf, FAR const char *fmt, va_list ap)
set_errno(errsave);
- /* We have to check whether we need to return a float or
- * a double.
+ /* We have to check whether we need to return a float
+ * or a double.
*/
#ifdef CONFIG_HAVE_DOUBLE
@@ -617,7 +614,7 @@ int vsscanf(FAR const char *buf, FAR const char *fmt, va_list ap)
#endif
}
- /* Process %n: Character count */
+ /* Process %n: Character count */
else if (*fmt == 'n')
{
@@ -625,7 +622,7 @@ int vsscanf(FAR const char *buf, FAR const char *fmt, va_list ap)
if (!noassign)
{
- size_t nchars = (size_t) (buf - bufstart);
+ size_t nchars = (size_t)(buf - bufstart);
/* Note %n does not count as a conversion */
@@ -642,14 +639,14 @@ int vsscanf(FAR const char *buf, FAR const char *fmt, va_list ap)
}
}
- width = 0;
+ width = 0;
noassign = false;
- lflag = false;
+ lflag = false;
fmt++;
}
- /* It is not a conversion specifier */
+ /* It is not a conversion specifier */
else if (*buf)
{
--
GitLab
From 43d08db1a0849a3e946d7b24b07a5d9963db08ed Mon Sep 17 00:00:00 2001
From: Gregory Nutt
Date: Sat, 15 Oct 2016 11:29:50 -0600
Subject: [PATCH 083/734] XTENSA: Add some interrupt controls
---
arch/xtensa/src/common/xtensa_irq.S | 148 ++++++++++++++++++++++
arch/xtensa/src/common/xtensa_macros.h | 108 ++++++++++++++++
arch/xtensa/src/common/xtensa_specregs.h | 154 +++++++++++++++++++++++
3 files changed, 410 insertions(+)
create mode 100644 arch/xtensa/src/common/xtensa_irq.S
create mode 100644 arch/xtensa/src/common/xtensa_macros.h
create mode 100644 arch/xtensa/src/common/xtensa_specregs.h
diff --git a/arch/xtensa/src/common/xtensa_irq.S b/arch/xtensa/src/common/xtensa_irq.S
new file mode 100644
index 0000000000..c2963b9aa5
--- /dev/null
+++ b/arch/xtensa/src/common/xtensa_irq.S
@@ -0,0 +1,148 @@
+/****************************************************************************
+ * arch/xtensa/src/common/xtensa_irq.S
+ *
+ * Adapted from use in NuttX by:
+ *
+ * Copyright (C) 2016 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * Derives from logic originally provided by Cadence Design Systems Inc.
+ *
+ * Copyright (c) 2006-2015 Cadence Design Systems Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include
+
+#include "xtensa_specregs.h"
+#include "xtensa_macros.h"
+
+#ifdef CONFIG_XTENSA_HAVE_INTERRUPTS
+
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+/* INTENABLE virtualization information. */
+
+ .data
+ .global _xtensa_intdata
+ .align 8
+_xtensa_intdata:
+
+ .global _xtensa_intenable
+ .type _xtensa_intenable, @object
+_xtensa_intenable:
+ .word 0 /* Virtual INTENABLE */
+ .size _xtensa_intenable,4
+
+ .global _xtensa_vprimask
+ .type _xtensa_vprimask, @object
+_xtensa_vprimask:
+ .word 0xffffffff /* Virtual priority mask */
+ .size _xtensa_vprimask, 4
+
+#endif /* XCHAL_HAVE_INTERRUPTS */
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * C Prototype:
+ * irqstate_t xtensa_enable_interrupts(irqstate_t mask)
+ *
+ * Description:
+ * Enables a set of interrupts. Does not simply set INTENABLE directly,
+ * but computes it as a function of the current virtual priority.
+ * Can be called from interrupt handlers.
+ *
+ ****************************************************************************/
+
+ .text
+ .align 4
+ .global xtensa_enable_interrupts
+ .type xtensa_enable_interrupts, @function
+
+xtensa_enable_interrupts:
+
+ ENTRY0
+#if XCHAL_HAVE_INTERRUPTS
+ movi a3, 0
+ movi a4, _xtensa_intdata
+ xsr a3, INTENABLE /* Disables all interrupts */
+ rsync
+ l32i a3, a4, 0 /* a3 = _xtensa_intenable */
+ l32i a6, a4, 4 /* a6 = _xtensa_vprimask */
+ or a5, a3, a2 /* a5 = _xtensa_intenable | mask */
+ s32i a5, a4, 0 /* _xtensa_intenable |= mask */
+ and a5, a5, a6 /* a5 = _xtensa_intenable & _xtensa_vprimask */
+ wsr a5, INTENABLE /* Reenable interrupts */
+ mov a2, a3 /* Previous mask */
+#else
+ movi a2, 0 /* Return zero */
+#endif
+ RET0
+
+ .size xtensa_enable_interrupts, . - xtensa_enable_interrupts
+
+/****************************************************************************
+ * C Prototype:
+ * irqstate_t xtensa_disable_interrupts(irqstate_t mask)
+ *
+ * Description:
+ * Disables a set of interrupts. Does not simply set INTENABLE directly,
+ * but computes it as a function of the current virtual priority.
+ * Can be called from interrupt handlers.
+ *
+ ****************************************************************************/
+
+ .text
+ .align 4
+ .global xtensa_disable_interrupts
+ .type xtensa_disable_interrupts,@function
+
+xtensa_disable_interrupts:
+
+ ENTRY0
+#if XCHAL_HAVE_INTERRUPTS
+ movi a3, 0
+ movi a4, _xtensa_intdata
+ xsr a3, INTENABLE /* Disables all interrupts */
+ rsync
+ l32i a3, a4, 0 /* a3 = _xtensa_intenable */
+ l32i a6, a4, 4 /* a6 = _xtensa_vprimask */
+ or a5, a3, a2 /* a5 = _xtensa_intenable | mask */
+ xor a5, a5, a2 /* a5 = _xtensa_intenable & ~mask */
+ s32i a5, a4, 0 /* _xtensa_intenable &= ~mask */
+ and a5, a5, a6 /* a5 = _xtensa_intenable & _xtensa_vprimask */
+ wsr a5, INTENABLE /* Reenable interrupts */
+ mov a2, a3 /* Previous mask */
+#else
+ movi a2, 0 /* return zero */
+#endif
+ RET0
+
+ .size xtensa_disable_interrupts, . - xtensa_disable_interrupts
diff --git a/arch/xtensa/src/common/xtensa_macros.h b/arch/xtensa/src/common/xtensa_macros.h
new file mode 100644
index 0000000000..cf83048109
--- /dev/null
+++ b/arch/xtensa/src/common/xtensa_macros.h
@@ -0,0 +1,108 @@
+/****************************************************************************
+ * arch/xtensa/src/common/xtensa_macros.h
+ *
+ * Adapted from use in NuttX by:
+ *
+ * Copyright (C) 2016 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * Derives from logic originally provided by Cadence Design Systems Inc.
+ *
+ * Copyright (c) 2006-2015 Cadence Design Systems Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ ****************************************************************************/
+
+#ifdef __ARCH_XTENSA_SRC_COMMON_XTENSA_MACROS_H
+#define __ARCH_XTENSA_SRC_COMMON_XTENSA_MACROS_H 1
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include
+
+/****************************************************************************
+ * Assembly Language Macros
+ ****************************************************************************/
+
+#ifdef __ASSEMBLY__
+
+/* Macro to get the current core ID. Only uses the reg given as an argument.
+ * Reading PRID on the ESP108 architecture gives us 0xcdcd on the PRO
+ * processor and 0xabab on the APP CPU. We distinguish between the two by
+ * simply checking bit 1: it's 1 on the APP and 0 on the PRO processor.
+ */
+
+ .macro getcoreid reg
+ rsr.prid \reg
+ bbci \reg,1,1f
+ movi \reg,1
+ j 2f
+1:
+ movi \reg,0
+2:
+ .endm
+
+/* Macros to handle ABI specifics of function entry and return.
+ *
+ * Convenient where the frame size requirements are the same for both ABIs.
+ * ENTRY(sz), RET(sz) are for framed functions (have locals or make calls).
+ * ENTRY0, RET0 are for frameless functions (no locals, no calls).
+ *
+ * where size = size of stack frame in bytes (must be >0 and aligned to 16).
+ * For framed functions the frame is created and the return address saved at
+ * base of frame (Call0 ABI) or as determined by hardware (Windowed ABI).
+ * For frameless functions, there is no frame and return address remains in a0.
+ * Note: Because CPP macros expand to a single line, macros requiring multi-line
+ * expansions are implemented as assembler macros.
+ */
+
+#ifdef CONFIG_XTENSA_CALL0_ABI
+ /* Call0 */
+
+ .macro entry1 size=0x10
+ addi sp, sp, -\size
+ s32i a0, sp, 0
+ .endm
+
+ .macro ret1 size=0x10
+ l32i a0, sp, 0
+ addi sp, sp, \size
+ ret
+ .endm
+
+# define ENTRY(sz) entry1 sz
+# define ENTRY0
+# define RET(sz) ret1 sz
+# define RET0 ret
+
+#else
+ /* Windowed */
+
+# define ENTRY(sz) entry sp, sz
+# define ENTRY0 entry sp, 0x10
+# define RET(sz) retw
+# define RET0 retw
+
+#endif /* CONFIG_XTENSA_CALL0_ABI */
+
+#endif /* __ASSEMBLY */
+#endif /* __ARCH_XTENSA_SRC_COMMON_XTENSA_MACROS_H */
diff --git a/arch/xtensa/src/common/xtensa_specregs.h b/arch/xtensa/src/common/xtensa_specregs.h
new file mode 100644
index 0000000000..0b8b880d80
--- /dev/null
+++ b/arch/xtensa/src/common/xtensa_specregs.h
@@ -0,0 +1,154 @@
+/****************************************************************************
+ * arch/xtensa/src/common/xtensa_macros.h
+ * Xtensa Special Register symbolic names
+ *
+ * Adapted from use in NuttX by:
+ *
+ * Copyright (C) 2016 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * Derives from logic originally provided by Tensilica Inc.
+ *
+ * Copyright (c) 2005-2011 Tensilica Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ ****************************************************************************/
+
+#ifndef __ARCH_XTENSA_SRC_COMMON_XTENSA_SPECREGS_H
+#define __ARCH_XTENSA_SRC_COMMON_XTENSA_SPECREGS_H
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Special registers: */
+
+#define LBEG 0
+#define LEND 1
+#define LCOUNT 2
+#define SAR 3
+#define BR 4
+#define LITBASE 5
+#define SCOMPARE1 12
+#define ACCLO 16
+#define ACCHI 17
+#define MR_0 32
+#define MR_1 33
+#define MR_2 34
+#define MR_3 35
+#define PREFCTL 40
+#define WINDOWBASE 72
+#define WINDOWSTART 73
+#define PTEVADDR 83
+#define RASID 90
+#define ITLBCFG 91
+#define DTLBCFG 92
+#define IBREAKENABLE 96
+#define MEMCTL 97
+#define CACHEATTR 98
+#define ATOMCTL 99
+#define DDR 104
+#define MECR 110
+#define IBREAKA_0 128
+#define IBREAKA_1 129
+#define DBREAKA_0 144
+#define DBREAKA_1 145
+#define DBREAKC_0 160
+#define DBREAKC_1 161
+#define CONFIGID0 176
+#define EPC_1 177
+#define EPC_2 178
+#define EPC_3 179
+#define EPC_4 180
+#define EPC_5 181
+#define EPC_6 182
+#define EPC_7 183
+#define DEPC 192
+#define EPS_2 194
+#define EPS_3 195
+#define EPS_4 196
+#define EPS_5 197
+#define EPS_6 198
+#define EPS_7 199
+#define CONFIGID1 208
+#define EXCSAVE_1 209
+#define EXCSAVE_2 210
+#define EXCSAVE_3 211
+#define EXCSAVE_4 212
+#define EXCSAVE_5 213
+#define EXCSAVE_6 214
+#define EXCSAVE_7 215
+#define CPENABLE 224
+#define INTERRUPT 226
+#define INTREAD INTERRUPT /* Alternate name for backward compatibility */
+#define INTSET INTERRUPT /* Alternate name for backward compatibility */
+#define INTCLEAR 227
+#define INTENABLE 228
+#define PS 230
+#define VECBASE 231
+#define EXCCAUSE 232
+#define DEBUGCAUSE 233
+#define CCOUNT 234
+#define PRID 235
+#define ICOUNT 236
+#define ICOUNTLEVEL 237
+#define EXCVADDR 238
+#define CCOMPARE_0 240
+#define CCOMPARE_1 241
+#define CCOMPARE_2 242
+#define MISC_REG_0 244
+#define MISC_REG_1 245
+#define MISC_REG_2 246
+#define MISC_REG_3 247
+
+/* Special cases (bases of special register series): */
+
+#define MR 32
+#define IBREAKA 128
+#define DBREAKA 144
+#define DBREAKC 160
+#define EPC 176
+#define EPS 192
+#define EXCSAVE 208
+#define CCOMPARE 240
+#define MISC_REG 244
+
+/* Tensilica-defined user registers: */
+
+#if 0
+/*#define ... 21..24 */ /* (545CK) */
+/*#define ... 140..143 */ /* (545CK) */
+#define EXPSTATE 230 /* Diamond */
+#define THREADPTR 231 /* threadptr option */
+#define FCR 232 /* FPU */
+#define FSR 233 /* FPU */
+#define AE_OVF_SAR 240 /* HiFi2 */
+#define AE_BITHEAD 241 /* HiFi2 */
+#define AE_TS_FTS_BU_BP 242 /* HiFi2 */
+#define AE_SD_NO 243 /* HiFi2 */
+#define VSAR 240 /* VectraLX */
+#define ROUND_LO 242 /* VectraLX */
+#define ROUND_HI 243 /* VectraLX */
+#define CBEGIN 246 /* VectraLX */
+#define CEND 247 /* VectraLX */
+#endif
+
+#endif /* __ARCH_XTENSA_SRC_COMMON_XTENSA_SPECREGS_H */
--
GitLab
From 0a0278a3ca92ba9730409317b24a75b38a2195d9 Mon Sep 17 00:00:00 2001
From: Gregory Nutt
Date: Sat, 15 Oct 2016 11:36:48 -0600
Subject: [PATCH 084/734] XTENSA: Add and architecture Makefile. Initial
verion is just the MIPS Makefile.
---
arch/xtensa/src/Makefile | 187 +++++++++++++++++++++++++++++++++++++++
1 file changed, 187 insertions(+)
create mode 100644 arch/xtensa/src/Makefile
diff --git a/arch/xtensa/src/Makefile b/arch/xtensa/src/Makefile
new file mode 100644
index 0000000000..0e22a4e010
--- /dev/null
+++ b/arch/xtensa/src/Makefile
@@ -0,0 +1,187 @@
+############################################################################
+# arch/xtensa/src/Makefile
+#
+# Copyright (C) 2016 Gregory Nutt. All rights reserved.
+# Author: Gregory Nutt
+#
+# 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
+-include chip/Make.defs
+
+ifeq ($(CONFIG_ARCH_FAMILY_LX6),y)
+ARCH_SUBDIR = lx6
+endif
+
+CPPFLAGS += $(EXTRADEFINES)
+CFLAGS += $(EXTRADEFINES)
+CXXFLAGS += $(EXTRADEFINES)
+
+ifeq ($(CONFIG_WINDOWS_NATIVE),y)
+ ARCH_SRCDIR = $(TOPDIR)\arch\$(CONFIG_ARCH)\src
+ NUTTX = $(TOPDIR)\nuttx$(EXEEXT)
+ CFLAGS += -I$(ARCH_SRCDIR)\chip
+ CFLAGS += -I$(ARCH_SRCDIR)\common
+ CFLAGS += -I$(ARCH_SRCDIR)\$(ARCH_SUBDIR)
+ CFLAGS += -I$(TOPDIR)\sched
+else
+ ARCH_SRCDIR = $(TOPDIR)/arch/$(CONFIG_ARCH)/src
+ifeq ($(WINTOOL),y)
+ NUTTX = "${shell cygpath -w $(TOPDIR)/nuttx$(EXEEXT)}"
+ CFLAGS += -I "${shell cygpath -w $(ARCH_SRCDIR)/chip}"
+ CFLAGS += -I "${shell cygpath -w $(ARCH_SRCDIR)/common}"
+ CFLAGS += -I "${shell cygpath -w $(ARCH_SRCDIR)/$(ARCH_SUBDIR)}"
+ CFLAGS += -I "${shell cygpath -w $(TOPDIR)/sched}"
+else
+ NUTTX = $(TOPDIR)/nuttx$(EXEEXT)
+ CFLAGS += -I$(ARCH_SRCDIR)/chip
+ CFLAGS += -I$(ARCH_SRCDIR)/common
+ CFLAGS += -I$(ARCH_SRCDIR)/$(ARCH_SUBDIR)
+ CFLAGS += -I$(TOPDIR)/sched
+endif
+endif
+
+HEAD_OBJ = $(HEAD_ASRC:.S=$(OBJEXT))
+STARTUP_OBJS ?= $(HEAD_OBJ)
+
+ASRCS = $(CHIP_ASRCS) $(CMN_ASRCS)
+AOBJS = $(ASRCS:.S=$(OBJEXT))
+
+CSRCS = $(CHIP_CSRCS) $(CMN_CSRCS)
+COBJS = $(CSRCS:.c=$(OBJEXT))
+
+SRCS = $(ASRCS) $(CSRCS)
+OBJS = $(AOBJS) $(COBJS)
+
+# Override in Make.defs if linker is not 'ld'
+
+LDSTARTGROUP ?= --start-group
+LDENDGROUP ?= --end-group
+
+LDFLAGS += $(ARCHSCRIPT)
+EXTRA_LIBS ?=
+LINKLIBS ?=
+
+ifeq ($(CONFIG_WINDOWS_NATIVE),y)
+ BOARDMAKE = $(if $(wildcard .\board\Makefile),y,)
+ LIBPATHS += -L"$(TOPDIR)\lib"
+ifeq ($(BOARDMAKE),y)
+ LIBPATHS += -L"$(TOPDIR)\arch\$(CONFIG_ARCH)\src\board"
+endif
+
+else
+ BOARDMAKE = $(if $(wildcard ./board/Makefile),y,)
+
+ifeq ($(WINTOOL),y)
+ LIBPATHS += -L"${shell cygpath -w "$(TOPDIR)/lib"}"
+ifeq ($(BOARDMAKE),y)
+ LIBPATHS += -L"${shell cygpath -w "$(TOPDIR)/arch/$(CONFIG_ARCH)/src/board"}"
+endif
+
+else
+ LIBPATHS += -L"$(TOPDIR)/lib"
+ifeq ($(BOARDMAKE),y)
+ LIBPATHS += -L"$(TOPDIR)/arch/$(CONFIG_ARCH)/src/board"
+endif
+endif
+endif
+
+LDLIBS = $(patsubst %.a,%,$(patsubst lib%,-l%,$(LINKLIBS)))
+ifeq ($(BOARDMAKE),y)
+ LDLIBS += -lboard
+endif
+
+LIBGCC = "${shell "$(CC)" $(ARCHCPUFLAGS) -print-libgcc-file-name}"
+
+VPATH = chip:common:$(ARCH_SUBDIR)
+
+all: $(HEAD_OBJ) libarch$(LIBEXT)
+
+.PHONY: board/libboard$(LIBEXT)
+
+$(AOBJS) $(HEAD_OBJ): %$(OBJEXT): %.S
+ $(call ASSEMBLE, $<, $@)
+
+$(COBJS): %$(OBJEXT): %.c
+ $(call COMPILE, $<, $@)
+
+libarch$(LIBEXT): $(OBJS)
+ $(call ARCHIVE, $@, $(OBJS))
+
+board/libboard$(LIBEXT):
+ $(Q) $(MAKE) -C board TOPDIR="$(TOPDIR)" libboard$(LIBEXT) EXTRADEFINES=$(EXTRADEFINES)
+
+nuttx$(EXEEXT): $(HEAD_OBJ) board/libboard$(LIBEXT)
+ @echo "LD: nuttx"
+ $(Q) $(LD) --entry=__start $(LDFLAGS) $(LIBPATHS) -o $(NUTTX)$(EXEEXT) $(HEAD_OBJ) $(EXTRA_OBJS) \
+ $(LDSTARTGROUP) $(LDLIBS) $(EXTRA_LIBS) $(LIBGCC) $(LDENDGROUP)
+ifneq ($(CONFIG_WINDOWS_NATIVE),y)
+ $(Q) $(NM) $(NUTTX)$(EXEEXT) | \
+ grep -v '\(compiled\)\|\(\$(OBJEXT)$$\)\|\( [aUw] \)\|\(\.\.ng$$\)\|\(LASH[RL]DI\)' | \
+ sort > $(TOPDIR)/System.map
+endif
+
+# This is part of the top-level export target
+
+export_startup: board/libboard$(LIBEXT) $(STARTUP_OBJS)
+ $(Q) if [ -d "$(EXPORT_DIR)/startup" ]; then \
+ cp -f $(STARTUP_OBJS) "$(EXPORT_DIR)/startup"; \
+ else \
+ echo "$(EXPORT_DIR)/startup does not exist"; \
+ exit 1; \
+ fi
+
+# Dependencies
+
+.depend: Makefile chip/Make.defs $(SRCS)
+ifeq ($(BOARDMAKE),y)
+ $(Q) $(MAKE) -C board TOPDIR="$(TOPDIR)" depend
+endif
+ $(Q) $(MKDEP) --dep-path chip --dep-path common --dep-path $(ARCH_SUBDIR) \
+ "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep
+ $(Q) touch $@
+
+depend: .depend
+
+clean:
+ifeq ($(BOARDMAKE),y)
+ $(Q) $(MAKE) -C board TOPDIR="$(TOPDIR)" clean
+endif
+ $(call DELFILE, libarch$(LIBEXT))
+ $(call CLEAN)
+
+distclean: clean
+ifeq ($(BOARDMAKE),y)
+ $(Q) $(MAKE) -C board TOPDIR="$(TOPDIR)" distclean
+endif
+ $(call DELFILE, Make.dep)
+ $(call DELFILE, .depend)
+
+-include Make.dep
--
GitLab
From 4621784617e8dcc41f76f6b47d6937a2f05de9b4 Mon Sep 17 00:00:00 2001
From: Gregory Nutt
Date: Sat, 15 Oct 2016 11:45:15 -0600
Subject: [PATCH 085/734] Add xtensa.h (which is call up_internal.h in other
architectures.
---
arch/xtensa/include/irq.h | 4 +--
arch/xtensa/src/common/xtensa.h | 28 +++++++++----------
arch/xtensa/src/common/xtensa_allocateheap.c | 2 +-
arch/xtensa/src/common/xtensa_createstack.c | 2 +-
arch/xtensa/src/common/xtensa_etherstub.c | 2 +-
arch/xtensa/src/common/xtensa_exit.c | 2 +-
arch/xtensa/src/common/xtensa_idle.c | 2 +-
arch/xtensa/src/common/xtensa_initialize.c | 2 +-
.../src/common/xtensa_interruptcontext.c | 2 +-
arch/xtensa/src/common/xtensa_lowputs.c | 2 +-
arch/xtensa/src/common/xtensa_puts.c | 2 +-
arch/xtensa/src/common/xtensa_releasestack.c | 2 +-
arch/xtensa/src/common/xtensa_stackframe.c | 2 +-
arch/xtensa/src/common/xtensa_usestack.c | 2 +-
14 files changed, 28 insertions(+), 28 deletions(-)
diff --git a/arch/xtensa/include/irq.h b/arch/xtensa/include/irq.h
index 3e8dfd4666..49bfc5b138 100644
--- a/arch/xtensa/include/irq.h
+++ b/arch/xtensa/include/irq.h
@@ -158,9 +158,9 @@ struct xcptcontext
uint32_t saved_cpsr;
#endif
- /* Register save area */
+ /* Pointer to the register save area on the stack*/
- uint32_t regs[XCPTCONTEXT_REGS];
+ uint32_t *regs;
#ifdef CONFIG_LIB_SYSCALL
/* The following array holds the return address and the exc_return value
diff --git a/arch/xtensa/src/common/xtensa.h b/arch/xtensa/src/common/xtensa.h
index cef80d3ae9..01a3ed9e06 100644
--- a/arch/xtensa/src/common/xtensa.h
+++ b/arch/xtensa/src/common/xtensa.h
@@ -1,7 +1,7 @@
/****************************************************************************
- * arch/xtensa/common/xtensa_internal.h
+ * arch/xtensa/common/xtensa.h
*
- * Copyright (C) 2011, 2012, 2015 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2016 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt
*
* Redistribution and use in source and binary forms, with or without
@@ -33,8 +33,8 @@
*
****************************************************************************/
-#ifndef __ARCH_XTENSA_SRC_COMMON_XTENSA_INTERNAL_H
-#define __ARCH_XTENSA_SRC_COMMON_XTENSA_INTERNAL_H
+#ifndef __ARCH_XTENSA_SRC_COMMON_XTENSA_H
+#define __ARCH_XTENSA_SRC_COMMON_XTENSA_H
/****************************************************************************
* Included Files
@@ -104,12 +104,12 @@
# define CONFIG_ARCH_INTERRUPTSTACK 0
#endif
-/* In the XTENSA model, the state is copied from the stack to the TCB, but
- * only a referenced is passed to get the state from the TCB.
+/* In the XTENSA model, only a pointer to register state on the stack is
+ * saved in the TCB.
*/
-#define up_savestate(regs) up_copystate(regs, (uint32_t*)g_current_regs)
-#define up_restorestate(regs) (g_current_regs = regs)
+#define up_savestate(regs) do { reg = g_current_regs; } while (0)
+#define up_restorestate(regs) do { g_current_regs = regs; } while (0)
/****************************************************************************
* Public Types
@@ -183,7 +183,7 @@ extern uint32_t _bmxdupba_address; /* BMX register setting */
#ifndef __ASSEMBLY__
/* Common Functions *********************************************************/
-/* Common functions define in arch/xtensa/src/common. These may be replaced
+/* Common functions define in arch/mips/src/common. These may be replaced
* with chip-specific functions of the same name if needed. See also
* functions prototyped in include/nuttx/arch.h.
*/
@@ -213,21 +213,21 @@ void up_dumpstate(void);
# define up_dumpstate()
#endif
-/* Common XTENSA32 functions defined in arch/xtensa/src/XTENSA32 */
+/* Common XTENSA functions */
/* IRQs */
uint32_t *up_doirq(int irq, uint32_t *regs);
-/* Software interrupt 0 handler */
+/* Software interrupt handler */
-int up_swint0(int irq, FAR void *context);
+int up_swint(int irq, FAR void *context);
/* Signals */
void up_sigdeliver(void);
/* Chip-specific functions **************************************************/
-/* Chip specific functions defined in arch/xtensa/src/ */
+/* Chip specific functions defined in arch/mips/src/ */
/* IRQs */
void up_irqinitialize(void);
@@ -282,4 +282,4 @@ void up_usbuninitialize(void);
#endif
#endif /* __ASSEMBLY__ */
-#endif /* __ARCH_XTENSA_SRC_COMMON_XTENSA_INTERNAL_H */
+#endif /* __ARCH_XTENSA_SRC_COMMON_XTENSA_H */
diff --git a/arch/xtensa/src/common/xtensa_allocateheap.c b/arch/xtensa/src/common/xtensa_allocateheap.c
index fc2178b5d1..b821eb4e34 100644
--- a/arch/xtensa/src/common/xtensa_allocateheap.c
+++ b/arch/xtensa/src/common/xtensa_allocateheap.c
@@ -47,7 +47,7 @@
#include
#include "up_arch.h"
-#include "up_internal.h"
+#include "xtensa.h"
/****************************************************************************
* Pre-processor Definitions
diff --git a/arch/xtensa/src/common/xtensa_createstack.c b/arch/xtensa/src/common/xtensa_createstack.c
index 08d310e497..f895f47a50 100644
--- a/arch/xtensa/src/common/xtensa_createstack.c
+++ b/arch/xtensa/src/common/xtensa_createstack.c
@@ -50,7 +50,7 @@
#include
#include "up_arch.h"
-#include "up_internal.h"
+#include "xtensa.h"
/****************************************************************************
* Pre-processor Macros
diff --git a/arch/xtensa/src/common/xtensa_etherstub.c b/arch/xtensa/src/common/xtensa_etherstub.c
index e19b26a208..b41b7bf6d4 100644
--- a/arch/xtensa/src/common/xtensa_etherstub.c
+++ b/arch/xtensa/src/common/xtensa_etherstub.c
@@ -39,7 +39,7 @@
#include
-#include "up_internal.h"
+#include "xtensa.h"
/****************************************************************************
* Pre-processor Definitions
diff --git a/arch/xtensa/src/common/xtensa_exit.c b/arch/xtensa/src/common/xtensa_exit.c
index f300c9b89a..4f451539d2 100644
--- a/arch/xtensa/src/common/xtensa_exit.c
+++ b/arch/xtensa/src/common/xtensa_exit.c
@@ -52,7 +52,7 @@
#include "task/task.h"
#include "sched/sched.h"
#include "group/group.h"
-#include "up_internal.h"
+#include "xtensa.h"
/****************************************************************************
* Pre-processor Definitions
diff --git a/arch/xtensa/src/common/xtensa_idle.c b/arch/xtensa/src/common/xtensa_idle.c
index e48441d5b4..672a0fae1c 100644
--- a/arch/xtensa/src/common/xtensa_idle.c
+++ b/arch/xtensa/src/common/xtensa_idle.c
@@ -41,7 +41,7 @@
#include
#include
-#include "up_internal.h"
+#include "xtensa.h"
/****************************************************************************
* Public Functions
diff --git a/arch/xtensa/src/common/xtensa_initialize.c b/arch/xtensa/src/common/xtensa_initialize.c
index 1fedf99149..46de907db4 100644
--- a/arch/xtensa/src/common/xtensa_initialize.c
+++ b/arch/xtensa/src/common/xtensa_initialize.c
@@ -58,7 +58,7 @@
#include
#include "up_arch.h"
-#include "up_internal.h"
+#include "xtensa.h"
/****************************************************************************
* Private Functions
diff --git a/arch/xtensa/src/common/xtensa_interruptcontext.c b/arch/xtensa/src/common/xtensa_interruptcontext.c
index c6d83d05e0..8b6bf802ec 100644
--- a/arch/xtensa/src/common/xtensa_interruptcontext.c
+++ b/arch/xtensa/src/common/xtensa_interruptcontext.c
@@ -43,7 +43,7 @@
#include
#include
-#include "up_internal.h"
+#include "xtensa.h"
/****************************************************************************
* Private Types
diff --git a/arch/xtensa/src/common/xtensa_lowputs.c b/arch/xtensa/src/common/xtensa_lowputs.c
index 764f8393a6..f1acb1059d 100644
--- a/arch/xtensa/src/common/xtensa_lowputs.c
+++ b/arch/xtensa/src/common/xtensa_lowputs.c
@@ -39,7 +39,7 @@
#include
-#include "up_internal.h"
+#include "xtensa.h"
/****************************************************************************
* Pre-processor Definitions
diff --git a/arch/xtensa/src/common/xtensa_puts.c b/arch/xtensa/src/common/xtensa_puts.c
index 47675baa8d..3eaa3078a4 100644
--- a/arch/xtensa/src/common/xtensa_puts.c
+++ b/arch/xtensa/src/common/xtensa_puts.c
@@ -40,7 +40,7 @@
#include
#include
-#include "up_internal.h"
+#include "xtensa.h"
/****************************************************************************
* Pre-processor Definitions
diff --git a/arch/xtensa/src/common/xtensa_releasestack.c b/arch/xtensa/src/common/xtensa_releasestack.c
index 76b3164bce..40b5bd7571 100644
--- a/arch/xtensa/src/common/xtensa_releasestack.c
+++ b/arch/xtensa/src/common/xtensa_releasestack.c
@@ -45,7 +45,7 @@
#include
#include
-#include "up_internal.h"
+#include "xtensa.h"
/****************************************************************************
* Private Types
diff --git a/arch/xtensa/src/common/xtensa_stackframe.c b/arch/xtensa/src/common/xtensa_stackframe.c
index f0a1da976d..6c1adc992b 100644
--- a/arch/xtensa/src/common/xtensa_stackframe.c
+++ b/arch/xtensa/src/common/xtensa_stackframe.c
@@ -46,7 +46,7 @@
#include
-#include "up_internal.h"
+#include "xtensa.h"
/****************************************************************************
* Pre-processor Macros
diff --git a/arch/xtensa/src/common/xtensa_usestack.c b/arch/xtensa/src/common/xtensa_usestack.c
index 9b35e2d0a9..83daf2729c 100644
--- a/arch/xtensa/src/common/xtensa_usestack.c
+++ b/arch/xtensa/src/common/xtensa_usestack.c
@@ -47,7 +47,7 @@
#include
#include
-#include "up_internal.h"
+#include "xtensa.h"
/****************************************************************************
* Pre-processor Definitions
--
GitLab
From 8ffbf6d95efdf21fd70faa1cbac825b4ef442e59 Mon Sep 17 00:00:00 2001
From: Gregory Nutt
Date: Sat, 15 Oct 2016 11:46:21 -0600
Subject: [PATCH 086/734] XTENSA: Hook xtensa_irq.S into build
---
arch/xtensa/src/common/xtensa_irq.S | 10 +++++-----
arch/xtensa/src/common/xtensa_macros.h | 2 +-
arch/xtensa/src/esp32/Make.defs | 2 +-
configs/esp32-core/nsh/defconfig | 7 ++++++-
4 files changed, 13 insertions(+), 8 deletions(-)
diff --git a/arch/xtensa/src/common/xtensa_irq.S b/arch/xtensa/src/common/xtensa_irq.S
index c2963b9aa5..4ecd099d10 100644
--- a/arch/xtensa/src/common/xtensa_irq.S
+++ b/arch/xtensa/src/common/xtensa_irq.S
@@ -39,12 +39,12 @@
#include "xtensa_specregs.h"
#include "xtensa_macros.h"
-#ifdef CONFIG_XTENSA_HAVE_INTERRUPTS
-
/****************************************************************************
* Public Data
****************************************************************************/
+#ifdef CONFIG_XTENSA_HAVE_INTERRUPTS
+
/* INTENABLE virtualization information. */
.data
@@ -64,7 +64,7 @@ _xtensa_vprimask:
.word 0xffffffff /* Virtual priority mask */
.size _xtensa_vprimask, 4
-#endif /* XCHAL_HAVE_INTERRUPTS */
+#endif /* CONFIG_XTENSA_HAVE_INTERRUPTS */
/****************************************************************************
* Public Functions
@@ -89,7 +89,7 @@ _xtensa_vprimask:
xtensa_enable_interrupts:
ENTRY0
-#if XCHAL_HAVE_INTERRUPTS
+#ifdef CONFIG_XTENSA_HAVE_INTERRUPTS
movi a3, 0
movi a4, _xtensa_intdata
xsr a3, INTENABLE /* Disables all interrupts */
@@ -127,7 +127,7 @@ xtensa_enable_interrupts:
xtensa_disable_interrupts:
ENTRY0
-#if XCHAL_HAVE_INTERRUPTS
+#ifdef CONFIG_XTENSA_HAVE_INTERRUPTS
movi a3, 0
movi a4, _xtensa_intdata
xsr a3, INTENABLE /* Disables all interrupts */
diff --git a/arch/xtensa/src/common/xtensa_macros.h b/arch/xtensa/src/common/xtensa_macros.h
index cf83048109..d988386059 100644
--- a/arch/xtensa/src/common/xtensa_macros.h
+++ b/arch/xtensa/src/common/xtensa_macros.h
@@ -30,7 +30,7 @@
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
****************************************************************************/
-#ifdef __ARCH_XTENSA_SRC_COMMON_XTENSA_MACROS_H
+#ifndef __ARCH_XTENSA_SRC_COMMON_XTENSA_MACROS_H
#define __ARCH_XTENSA_SRC_COMMON_XTENSA_MACROS_H 1
/****************************************************************************
diff --git a/arch/xtensa/src/esp32/Make.defs b/arch/xtensa/src/esp32/Make.defs
index 06ba9cad86..1312fd1cf6 100644
--- a/arch/xtensa/src/esp32/Make.defs
+++ b/arch/xtensa/src/esp32/Make.defs
@@ -39,7 +39,7 @@ HEAD_ASRC =
# Common XTENSA files (arch/xtensa/src/common)
-CMN_ASRCS =
+CMN_ASRCS = xtensa_irq.S
CMN_CSRCS = xtensa_allocateheap.c xtensa_createstack.c xtensa_exit.c
CMN_CSRCS += xtensa_idle.c xtensa_initialize.c xtensa_interruptcontext.c
CMN_CSRCS += xtensa_lowputs.c xtensa_mdelay.c xtensa_modifyreg8.c
diff --git a/configs/esp32-core/nsh/defconfig b/configs/esp32-core/nsh/defconfig
index cee088cc3e..082df28cc6 100644
--- a/configs/esp32-core/nsh/defconfig
+++ b/configs/esp32-core/nsh/defconfig
@@ -73,6 +73,11 @@ CONFIG_ARCH="xtensa"
CONFIG_ARCH_CHIP="esp32"
CONFIG_ARCH_CHIP_ESP32=y
CONFIG_ARCH_FAMILY_LX6=y
+# CONFIG_XTENSA_HAVE_LOOPS is not set
+CONFIG_XTENSA_HAVE_INTERRUPTS=y
+# CONFIG_XTENSA_USE_SWPRI is not set
+CONFIG_XTENSA_CALL0_ABI=y
+# CONFIG_XTENSA_USE_OVLY is not set
#
# Architecture Options
@@ -550,10 +555,10 @@ CONFIG_BUILTIN_PROXY_STACKSIZE=1024
CONFIG_EXAMPLES_NSH=y
CONFIG_EXAMPLES_NSH_CXXINITIALIZE=y
# CONFIG_EXAMPLES_NULL is not set
-# CONFIG_EXAMPLES_NX is not set
# CONFIG_EXAMPLES_NXFFS is not set
# CONFIG_EXAMPLES_NXHELLO is not set
# CONFIG_EXAMPLES_NXIMAGE is not set
+# CONFIG_EXAMPLES_NX is not set
# CONFIG_EXAMPLES_NXLINES is not set
# CONFIG_EXAMPLES_NXTERM is not set
# CONFIG_EXAMPLES_NXTEXT is not set
--
GitLab
From eada2bf8d8c7acdef8c020018522df2ebdb00c2e Mon Sep 17 00:00:00 2001
From: Gregory Nutt
Date: Sat, 15 Oct 2016 12:23:36 -0600
Subject: [PATCH 087/734] XTENSA: Add function prototypes
---
arch/xtensa/include/irq.h | 33 +++++++++++++++++++++++++++++----
arch/xtensa/include/types.h | 2 +-
2 files changed, 30 insertions(+), 5 deletions(-)
diff --git a/arch/xtensa/include/irq.h b/arch/xtensa/include/irq.h
index 49bfc5b138..7e47291618 100644
--- a/arch/xtensa/include/irq.h
+++ b/arch/xtensa/include/irq.h
@@ -47,6 +47,7 @@
/* Include NuttX-specific IRQ definitions */
#include
+#include
/* Include architecture-specific IRQ definitions */
@@ -180,10 +181,6 @@ struct xcptcontext
* Public Data
****************************************************************************/
-/****************************************************************************
- * Public Function Prototypes
- ****************************************************************************/
-
#ifdef __cplusplus
#define EXTERN extern "C"
extern "C"
@@ -192,6 +189,34 @@ extern "C"
#define EXTERN extern
#endif
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: xtensa_enable_interrupts
+ *
+ * Description:
+ * Enables a set of interrupts. Does not simply set INTENABLE directly,
+ * but computes it as a function of the current virtual priority.
+ * Can be called from interrupt handlers.
+ *
+ ****************************************************************************/
+
+irqstate_t xtensa_enable_interrupts(irqstate_t mask);
+
+/****************************************************************************
+ * Name: xtensa_disable_interrupts
+ *
+ * Description:
+ * Disables a set of interrupts. Does not simply set INTENABLE directly,
+ * but computes it as a function of the current virtual priority.
+ * Can be called from interrupt handlers.
+ *
+ ****************************************************************************/
+
+irqstate_t xtensa_disable_interrupts(irqstate_t mask);
+
#undef EXTERN
#ifdef __cplusplus
}
diff --git a/arch/xtensa/include/types.h b/arch/xtensa/include/types.h
index ea8e19ff36..55d2fee188 100644
--- a/arch/xtensa/include/types.h
+++ b/arch/xtensa/include/types.h
@@ -83,7 +83,7 @@ typedef unsigned long _uintptr_t;
/* This is the size of the interrupt state save returned by up_irq_save(). */
-typedef unsigned long irqstate_t;
+typedef unsigned int irqstate_t;
#endif /* __ASSEMBLY__ */
--
GitLab
From 275120a6d1c880c8e1331939950005a558d6ee0c Mon Sep 17 00:00:00 2001
From: Gregory Nutt
Date: Sat, 15 Oct 2016 14:57:06 -0600
Subject: [PATCH 088/734] XTENSA: Add some context switching definitions
(incomplete); ESP32: Add some dummy LED definitions
---
arch/xtensa/src/common/xtensa_context.S | 666 ++++++++++++++++++++++++
configs/esp32-core/README.txt | 109 ++++
configs/esp32-core/include/board.h | 25 +
3 files changed, 800 insertions(+)
create mode 100644 arch/xtensa/src/common/xtensa_context.S
diff --git a/arch/xtensa/src/common/xtensa_context.S b/arch/xtensa/src/common/xtensa_context.S
new file mode 100644
index 0000000000..60a4d6edb3
--- /dev/null
+++ b/arch/xtensa/src/common/xtensa_context.S
@@ -0,0 +1,666 @@
+/****************************************************************************
+ * arch/xtensa/src/common/xtensa_context.S
+ *
+ * Adapted from use in NuttX by:
+ *
+ * Copyright (C) 2016 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * Derives from logic originally provided by Cadence Design Systems Inc.
+ *
+ * Copyright (c) 2006-2015 Cadence Design Systems Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ ****************************************************************************/
+
+/* XTENSA CONTEXT SAVE AND RESTORE ROUTINES
+ *
+ * Low-level Call0 functions for handling generic context save and restore of
+ * registers not specifically addressed by the interrupt vectors and handlers.
+ * Those registers (not handled by these functions) are PC, PS, A0, A1 (SP).
+ * Except for the calls to RTOS functions, this code is generic to Xtensa.
+ *
+ * Note that in Call0 ABI, interrupt handlers are expected to preserve the callee-
+ * save regs (A12-A15), which is always the case if the handlers are coded in C.
+ * However A12, A13 are made available as scratch registers for interrupt dispatch
+ * code, so are presumed saved anyway, and are always restored even in Call0 ABI.
+ * Only A14, A15 are truly handled as callee-save regs.
+ *
+ * Because Xtensa is a configurable architecture, this port supports all user
+ * generated configurations (except restrictions stated in the release notes).
+ * This is accomplished by conditional compilation using macros and functions
+ * defined in the Xtensa HAL (hardware adaptation layer) for your configuration.
+ * Only the processor state included in your configuration is saved and restored,
+ * including any processor state added by user configuration options or TIE.
+ */
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include "xtensa_rtos.h"
+#include "xtensa_context.h"
+
+#ifdef CONFIG_XTENSA_USE_OVLY
+# include
+#endif
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+ .text
+
+/****************************************************************************
+ * Name: _xtensa_context_save
+ *
+ * Description:
+ *
+ * NOTE: MUST BE CALLED ONLY BY 'CALL0' INSTRUCTION!
+ *
+ * Saves all Xtensa processor state except PC, PS, A0, A1 (SP), A12, A13,
+ * in the interrupt stack frame defined in xtensa_rtos.h. Its counterpart
+ * is _xtensa_context_restore (which also restores A12, A13).
+ *
+ * Caller is expected to have saved PC, PS, A0, A1 (SP), A12, A13 in the
+ * frame. This function preserves A12 & A13 in order to provide the caller
+ * with 2 scratch regs that need not be saved over the call to this
+ * function. The choice of which 2 regs to provide is governed by
+ * xthal_window_spill_nw and xthal_save_extra_nw, to avoid moving data
+ * more than necessary. Caller can assign regs accordingly.
+ *
+ * Entry Conditions:
+ * - A0 = Return address in caller.
+ * - A1 = Stack pointer of interrupted thread or handler ("interruptee").
+ * - Original A12, A13 have already been saved in the interrupt stack
+ * frame.
+ * - Other processor state except PC, PS, A0, A1 (SP), A12, A13, is as a
+ * the point of interruption.
+ * - If windowed ABI, PS.EXCM = 1 (exceptions disabled).
+ *
+ * Exit conditions:
+ * - A0 = Return address in caller.
+ * - A1 = Stack pointer of interrupted thread or handler ("interruptee").
+ * - A12, A13 as at entry (preserved).
+ * - If windowed ABI, PS.EXCM = 1 (exceptions disabled).
+ *
+ ****************************************************************************/
+
+ .global _xtensa_context_save
+ .type _xtensa_context_save, @function
+ .align 4
+ .literal_position
+ .align 4
+_xtensa_context_save:
+
+ s32i a2, sp, (4 * REG_A2)
+ s32i a3, sp, (4 * REG_A3)
+ s32i a4, sp, (4 * REG_A4)
+ s32i a5, sp, (4 * REG_A5)
+ s32i a6, sp, (4 * REG_A6)
+ s32i a7, sp, (4 * REG_A7)
+ s32i a8, sp, (4 * REG_A8)
+ s32i a9, sp, (4 * REG_A9)
+ s32i a10, sp, (4 * REG_A10)
+ s32i a11, sp, (4 * REG_A11)
+
+ /* Call0 ABI callee-saved regs a12-15 do not need to be saved here.
+ * a12-13 are the caller's responsibility so it can use them as scratch.
+ * So only need to save a14-a15 here for Windowed ABI (not Call0).
+ */
+
+#ifndef CONFIG_XTENSA_CALL0_ABI
+ s32i a14, sp, (4 * REG_A14)
+ s32i a15, sp, (4 * REG_A15)
+#endif
+
+ rsr a3, SAR
+ s32i a3, sp, (4 * REG_SAR)
+
+#ifdef CONFIG_XTENSA_HAVE_LOOPS
+ rsr a3, LBEG
+ s32i a3, sp, (4 * REG_LBEG)
+ rsr a3, LEND
+ s32i a3, sp, (4 * REG_LEND)
+ rsr a3, LCOUNT
+ s32i a3, sp, (4 * REG_LCOUNT)
+#endif
+
+#ifdef CONFIG_XTENSA_USE_SWPRI
+ /* Save virtual priority mask */
+
+ movi a3, _xtensa_vprimask
+ l32i a3, a3, 0
+ s32i a3, sp, (4 * REG_VPRI)
+#endif
+
+#if XCHAL_EXTRA_SA_SIZE > 0 || !defined(CONFIG_XTENSA_CALL0_ABI)
+ mov a9, a0 /* Preserve ret addr */
+ #endif
+
+#ifndef CONFIG_XTENSA_CALL0_ABI
+ /* To spill the reg windows, temp. need pre-interrupt stack ptr and
+ * a4-15. Need to save a9,12,13 temporarily (in frame temps) and
+ * recover originals. Interrupts need to be disabled below
+ * XCHAL_EXCM_LEVEL and window overflow and underflow exceptions
+ * disabled (assured by PS.EXCM == 1).
+ */
+
+ s32i a12, sp, (4 * REG_TMP0) /* Temp. save stuff in stack frame */
+ s32i a13, sp, (4 * REG_TMP1)
+ s32i a9, sp, (4 * REG_TMP2)
+
+ /* Save the overlay state if we are supporting overlays. Since we just
+ * saved three registers, we can conveniently use them here. Note that
+ * as of now, overlays only work for windowed calling ABI.
+ */
+
+#ifdef CONFIG_XTENSA_USE_OVLY
+ l32i a9, sp, (4 * REG_PC) /* Recover saved PC */
+ _xt_overlay_get_state a9, a12, a13
+ s32i a9, sp, (4 * REG_OVLY) /* Save overlay state */
+#endif
+
+ l32i a12, sp, (4 * REG_A12) /* Recover original a9,12,13 */
+ l32i a13, sp, (4 * REG_A13)
+ l32i a9, sp, (4 * REG_A9)
+ addi sp, sp, (4 * REG_FRMSZ) /* Restore the interruptee's SP */
+ call0 xthal_window_spill_nw /* Preserves only a4,5,8,9,12,13 */
+ addi sp, sp, -(4 * REG_FRMSZ)
+ l32i a12, sp, (4 * REG_TMP0) /* Recover stuff from stack frame */
+ l32i a13, sp, (4 * REG_TMP1)
+ l32i a9, sp, (4 * REG_TMP2)
+#endif
+
+#if XCHAL_EXTRA_SA_SIZE > 0
+ /* NOTE: Normally the xthal_save_extra_nw macro only affects address
+ * registers a2-a5. It is theoretically possible for Xtensa processor
+ * designers to write TIE that causes more address registers to be
+ * affected, but it is generally unlikely. If that ever happens,
+ * more registers need to be saved/restored around this macro invocation.
+ * Here we assume a9,12,13 are preserved.
+ * Future Xtensa tools releases might limit the regs that can be affected.
+ */
+
+ addi a2, sp, (4 * REG_EXTRA) /* Where to save it */
+#if XCHAL_EXTRA_SA_ALIGN > 16
+ movi a3, -XCHAL_EXTRA_SA_ALIGN
+ and a2, a2, a3 /* Align dynamically >16 bytes */
+#endif
+ call0 xthal_save_extra_nw /* Destroys a0,2,3,4,5 */
+#endif
+
+#if XCHAL_EXTRA_SA_SIZE > 0 || !defined(CONFIG_XTENSA_CALL0_ABI)
+ mov a0, a9 /* Retrieve ret addr */
+#endif
+
+ ret
+
+/****************************************************************************
+ * Name: _xtensa_context_restore
+ *
+ * Description:
+ *
+ * NOTE: MUST BE CALLED ONLY BY 'CALL0' INSTRUCTION!
+ *
+ * Restores all Xtensa processor state except PC, PS, A0, A1 (SP) (and in
+ * Call0 ABI, A14, A15 which are preserved by all interrupt handlers) from
+ * an interrupt stack frame defined in xtensa_rtos.h.
+ * Its counterpart is _xtensa_context_save (whose caller saved A12, A13).
+ *
+ * Caller is responsible to restore PC, PS, A0, A1 (SP).
+ *
+ * Entry Conditions:
+ * - A0 = Return address in caller.
+ * - A1 = Stack pointer of interrupted thread or handler ("interruptee").
+ *
+ * Exit conditions:
+ * - A0 = Return address in caller.
+ * - A1 = Stack pointer of interrupted thread or handler ("interruptee").
+ * - Other processor state except PC, PS, A0, A1 (SP), is as at the point
+ * of interruption.
+ *
+ ****************************************************************************/
+
+ .global _xtensa_context_restore
+ .type _xtensa_context_restore,@function
+ .align 4
+ .literal_position
+ .align 4
+_xtensa_context_restore:
+
+#if XCHAL_EXTRA_SA_SIZE > 0
+ /* NOTE: Normally the xthal_restore_extra_nw macro only affects address
+ * registers a2-a5. It is theoretically possible for Xtensa processor
+ * designers to write TIE that causes more address registers to be
+ * affected, but it is generally unlikely. If that ever happens,
+ * more registers need to be saved/restored around this macro invocation.
+ * Here we only assume a13 is preserved.
+ * Future Xtensa tools releases might limit the regs that can be affected.
+ */
+
+ mov a13, a0 /* Preserve ret addr */
+ addi a2, sp, (4 * REG_EXTRA) /* Where to find it */
+#if XCHAL_EXTRA_SA_ALIGN > 16
+ movi a3, -XCHAL_EXTRA_SA_ALIGN
+ and a2, a2, a3 /* Align dynamically >16 bytes */
+#endif
+ call0 xthal_restore_extra_nw /* Destroys a0,2,3,4,5 */
+ mov a0, a13 /* Retrieve ret addr */
+#endif
+
+#ifdef CONFIG_XTENSA_HAVE_LOOPS
+ l32i a2, sp, (4 * REG_LBEG)
+ l32i a3, sp, (4 * REG_LEND)
+ wsr a2, LBEG
+ l32i a2, sp, (4 * REG_LCOUNT)
+ wsr a3, LEND
+ wsr a2, LCOUNT
+#endif
+
+#ifdef CONFIG_XTENSA_USE_OVLY
+ /* If we are using overlays, this is a good spot to check if we need
+ * to restore an overlay for the incoming task. Here we have a bunch
+ * of registers to spare. Note that this step is going to use a few
+ * bytes of storage below SP (SP-20 to SP-32) if an overlay is going
+ * to be restored.
+ */
+
+ l32i a2, sp, (4 * REG_PC) /* Retrieve PC */
+ l32i a3, sp, (4 * REG_PS) /* Retrieve PS */
+ l32i a4, sp, (4 * REG_OVLY) /* Retrieve overlay state */
+ l32i a5, sp, (4 * REG_A1) /* Retrieve stack ptr */
+ _xt_overlay_check_map a2, a3, a4, a5, a6
+ s32i a2, sp, (4 * REG_PC) /* Save updated PC */
+ s32i a3, sp, (4 * REG_PS) /* Save updated PS */
+#endif
+
+#ifdef CONFIG_XTENSA_USE_SWPRI
+ /* Restore virtual interrupt priority and interrupt enable */
+
+ movi a3, _xtensa_intdata
+ l32i a4, a3, 0 /* a4 = _xtensa_intenable */
+ l32i a5, sp, (4 * REG_VPRI) /* a5 = saved _xtensa_vprimask */
+ and a4, a4, a5
+ wsr a4, INTENABLE /* Update INTENABLE */
+ s32i a5, a3, 4 /* Restore _xtensa_vprimask */
+ #endif
+
+ l32i a3, sp, (4 * REG_SAR)
+ l32i a2, sp, (4 * REG_A2)
+ wsr a3, SAR
+ l32i a3, sp, (4 * REG_A3)
+ l32i a4, sp, (4 * REG_A4)
+ l32i a5, sp, (4 * REG_A5)
+ l32i a6, sp, (4 * REG_A6)
+ l32i a7, sp, (4 * REG_A7)
+ l32i a8, sp, (4 * REG_A8)
+ l32i a9, sp, (4 * REG_A9)
+ l32i a10, sp, (4 * REG_A10)
+ l32i a11, sp, (4 * REG_A11)
+
+ /* Call0 ABI callee-saved regs a12-15 do not need to be restored here.
+ * However a12-13 were saved for scratch before XT_RTOS_INT_ENTER(),
+ * so need to be restored anyway, despite being callee-saved in Call0.
+ */
+
+ l32i a12, sp, (4 * REG_A12)
+ l32i a13, sp, (4 * REG_A13)
+#ifndef CONFIG_XTENSA_CALL0_ABI
+ l32i a14, sp, (4 * REG_A14)
+ l32i a15, sp, (4 * REG_A15)
+#endif
+
+ ret
+
+/****************************************************************************
+ * Name: _xt_coproc_init
+ *
+ * Description:
+ *
+ *
+ ****************************************************************************/
+
+
+
+ * Initializes global co-processor management data, setting all co-
+ * processors to "unowned". Leaves CPENABLE as it found it (does NOT clear
+ * it).
+ *
+ * Called during initialization of the RTOS, before any threads run.
+ *
+ * This may be called from normal Xtensa single-threaded application code
+ * which might use co-processors. The Xtensa run-time initialization enables
+ * all co-processors. They must remain enabled here, else a co-processor
+ * exception might occur outside of a thread, which the exception handler
+ * doesn't expect.
+ *
+ * Entry Conditions:
+ * - Xtensa single-threaded run-time environment is in effect.
+ * No thread is yet running.
+ *
+ * Exit conditions:
+ * - None.
+ *
+ * Obeys ABI conventions per prototype:
+ * void _xt_coproc_init(void)
+ *
+ ****************************************************************************/
+
+#if XCHAL_CP_NUM > 0
+ .global _xt_coproc_init
+ .type _xt_coproc_init,@function
+ .align 4
+ .literal_position
+ .align 4
+_xt_coproc_init:
+ ENTRY0
+
+ /* Initialize thread co-processor ownerships to 0 (unowned). */
+
+ movi a2, _xt_coproc_owner_sa /* a2 = base of owner array */
+ addi a3, a2, (XCHAL_CP_MAX*portNUM_PROCESSORS) << 2 /* a3 = top+1 of owner array */
+ movi a4, 0 /* a4 = 0 (unowned) */
+1: s32i a4, a2, 0
+ addi a2, a2, 4
+ bltu a2, a3, 1b
+
+ RET0
+#endif
+
+/****************************************************************************
+ * Name: _xt_coproc_release
+ *
+ * Description:
+ * Releases any and all co-processors owned by a given thread. The thread
+ * is identified by it's co-processor state save area defined in
+ * xtensa_context.h.
+ *
+ * Must be called before a thread's co-proc save area is deleted to avoid
+ * memory corruption when the exception handler tries to save the state.
+ * May be called when a thread terminates or completes but does not delete
+ * the co-proc save area, to avoid the exception handler having to save
+ * the thread's co-proc state before another thread can use it
+ * (optimization).
+ *
+ * Entry Conditions:
+ * - A2 = Pointer to base of co-processor state save area.
+ *
+ * Exit conditions:
+ * - None.
+ *
+ * Obeys ABI conventions per prototype:
+ * void _xt_coproc_release(void * coproc_sa_base)
+ *
+ ****************************************************************************/
+
+#if XCHAL_CP_NUM > 0
+ .global _xt_coproc_release
+ .type _xt_coproc_release,@function
+ .align 4
+ .literal_position
+ .align 4
+_xt_coproc_release:
+ ENTRY0 /* a2 = base of save area */
+
+ getcoreid a5
+ movi a3, XCHAL_CP_MAX << 2
+ mull a5, a5, a3
+ movi a3, _xt_coproc_owner_sa /* a3 = base of owner array */
+ add a3, a3, a5
+
+ addi a4, a3, XCHAL_CP_MAX << 2 /* a4 = top+1 of owner array */
+ movi a5, 0 /* a5 = 0 (unowned) */
+
+ rsil a6, XCHAL_EXCM_LEVEL /* lock interrupts */
+
+1: l32i a7, a3, 0 /* a7 = owner at a3 */
+ bne a2, a7, 2f /* if (coproc_sa_base == owner) */
+ s32i a5, a3, 0 /* owner = unowned */
+2: addi a3, a3, 1<<2 /* a3 = next entry in owner array */
+ bltu a3, a4, 1b /* repeat until end of array */
+
+3: wsr a6, PS /* restore interrupts */
+
+ RET0
+#endif
+
+/****************************************************************************
+ * Name: _xt_coproc_savecs
+ *
+ * Description:
+ * If there is a current thread and it has a coprocessor state save area,
+ * then save all callee-saved state into this area. This function is called
+ * from the solicited context switch handler. It calls a system-specific
+ * function to get the coprocessor save area base address.
+ *
+ * Entry conditions:
+ * - The thread being switched out is still the current thread.
+ * - CPENABLE state reflects which coprocessors are active.
+ * - Registers have been saved/spilled already.
+ *
+ * Exit conditions:
+ * - All necessary CP callee-saved state has been saved.
+ * - Registers a2-a7, a13-a15 have been trashed.
+ *
+ * Must be called from assembly code only, using CALL0.
+ *
+ ****************************************************************************/
+
+#if XCHAL_CP_NUM > 0
+ .extern _xt_coproc_sa_offset /* external reference */
+ .global _xt_coproc_savecs
+ .type _xt_coproc_savecs,@function
+ .align 4
+ .literal_position
+ .align 4
+_xt_coproc_savecs:
+
+ /* At entry, CPENABLE should be showing which CPs are enabled. */
+
+ rsr a2, CPENABLE /* a2 = which CPs are enabled */
+ beqz a2, .Ldone /* quick exit if none */
+ mov a14, a0 /* save return address */
+ call0 XT_RTOS_CP_STATE /* get address of CP save area */
+ mov a0, a14 /* restore return address */
+ beqz a15, .Ldone /* if none then nothing to do */
+ s16i a2, a15, XT_CP_CS_ST /* save mask of CPs being stored */
+ movi a13, _xt_coproc_sa_offset /* array of CP save offsets */
+ l32i a15, a15, XT_CP_ASA /* a15 = base of aligned save area */
+
+#if XCHAL_CP0_SA_SIZE
+ bbci.l a2, 0, 2f /* CP 0 not enabled */
+ l32i a14, a13, 0 /* a14 = _xt_coproc_sa_offset[0] */
+ add a3, a14, a15 /* a3 = save area for CP 0 */
+ xchal_cp0_store a3, a4, a5, a6, a7 continue=0 ofs=-1 select=XTHAL_SAS_TIE|XTHAL_SAS_NOCC|XTHAL_SAS_CALE alloc=XTHAL_SAS_ALL
+2:
+#endif
+
+#if XCHAL_CP1_SA_SIZE
+ bbci.l a2, 1, 2f /* CP 1 not enabled */
+ l32i a14, a13, 4 /* a14 = _xt_coproc_sa_offset[1] */
+ add a3, a14, a15 /* a3 = save area for CP 1 */
+ xchal_cp1_store a3, a4, a5, a6, a7 continue=0 ofs=-1 select=XTHAL_SAS_TIE|XTHAL_SAS_NOCC|XTHAL_SAS_CALE alloc=XTHAL_SAS_ALL
+2:
+#endif
+
+#if XCHAL_CP2_SA_SIZE
+ bbci.l a2, 2, 2f
+ l32i a14, a13, 8
+ add a3, a14, a15
+ xchal_cp2_store a3, a4, a5, a6, a7 continue=0 ofs=-1 select=XTHAL_SAS_TIE|XTHAL_SAS_NOCC|XTHAL_SAS_CALE alloc=XTHAL_SAS_ALL
+2:
+#endif
+
+#if XCHAL_CP3_SA_SIZE
+ bbci.l a2, 3, 2f
+ l32i a14, a13, 12
+ add a3, a14, a15
+ xchal_cp3_store a3, a4, a5, a6, a7 continue=0 ofs=-1 select=XTHAL_SAS_TIE|XTHAL_SAS_NOCC|XTHAL_SAS_CALE alloc=XTHAL_SAS_ALL
+2:
+#endif
+
+#if XCHAL_CP4_SA_SIZE
+ bbci.l a2, 4, 2f
+ l32i a14, a13, 16
+ add a3, a14, a15
+ xchal_cp4_store a3, a4, a5, a6, a7 continue=0 ofs=-1 select=XTHAL_SAS_TIE|XTHAL_SAS_NOCC|XTHAL_SAS_CALE alloc=XTHAL_SAS_ALL
+2:
+#endif
+
+#if XCHAL_CP5_SA_SIZE
+ bbci.l a2, 5, 2f
+ l32i a14, a13, 20
+ add a3, a14, a15
+ xchal_cp5_store a3, a4, a5, a6, a7 continue=0 ofs=-1 select=XTHAL_SAS_TIE|XTHAL_SAS_NOCC|XTHAL_SAS_CALE alloc=XTHAL_SAS_ALL
+2:
+#endif
+
+#if XCHAL_CP6_SA_SIZE
+ bbci.l a2, 6, 2f
+ l32i a14, a13, 24
+ add a3, a14, a15
+ xchal_cp6_store a3, a4, a5, a6, a7 continue=0 ofs=-1 select=XTHAL_SAS_TIE|XTHAL_SAS_NOCC|XTHAL_SAS_CALE alloc=XTHAL_SAS_ALL
+2:
+#endif
+
+#if XCHAL_CP7_SA_SIZE
+ bbci.l a2, 7, 2f
+ l32i a14, a13, 28
+ add a3, a14, a15
+ xchal_cp7_store a3, a4, a5, a6, a7 continue=0 ofs=-1 select=XTHAL_SAS_TIE|XTHAL_SAS_NOCC|XTHAL_SAS_CALE alloc=XTHAL_SAS_ALL
+2:
+#endif
+
+.Ldone:
+ ret
+#endif
+
+/****************************************************************************
+ * Name: _xt_coproc_restorecs
+ *
+ * Description:
+ * Restore any callee-saved coprocessor state for the incoming thread.
+ * This function is called from coprocessor exception handling, when
+ * giving ownership to a thread that solicited a context switch earlier.
+ * It calls a system-specific function to get the coprocessor save area
+ * base address.
+ *
+ * Entry conditions:
+ * - The incoming thread is set as the current thread.
+ * - CPENABLE is set up correctly for all required coprocessors.
+ * - a2 = mask of coprocessors to be restored.
+ *
+ * Exit conditions:
+ * - All necessary CP callee-saved state has been restored.
+ * - CPENABLE - unchanged.
+ * - Registers a2-a7, a13-a15 have been trashed.
+ *
+ * Must be called from assembly code only, using CALL0.
+ *
+ ****************************************************************************/
+
+#if XCHAL_CP_NUM > 0
+ .global _xt_coproc_restorecs
+ .type _xt_coproc_restorecs,@function
+ .align 4
+ .literal_position
+ .align 4
+_xt_coproc_restorecs:
+
+ mov a14, a0 /* Save return address */
+ call0 XT_RTOS_CP_STATE /* Get address of CP save area */
+ mov a0, a14 /* Restore return address */
+ beqz a15, .Ldone2 /* If none then nothing to do */
+ l16ui a3, a15, XT_CP_CS_ST /* a3 = which CPs have been saved */
+ xor a3, a3, a2 /* Clear the ones being restored */
+ s32i a3, a15, XT_CP_CS_ST /* Update saved CP mask */
+ movi a13, _xt_coproc_sa_offset /* Array of CP save offsets */
+ l32i a15, a15, XT_CP_ASA /* a15 = base of aligned save area */
+
+#if XCHAL_CP0_SA_SIZE
+ bbci.l a2, 0, 2f /* CP 0 not enabled */
+ l32i a14, a13, 0 /* a14 = _xt_coproc_sa_offset[0] */
+ add a3, a14, a15 /* a3 = save area for CP 0 */
+ xchal_cp0_load a3, a4, a5, a6, a7 continue=0 ofs=-1 select=XTHAL_SAS_TIE|XTHAL_SAS_NOCC|XTHAL_SAS_CALE alloc=XTHAL_SAS_ALL
+2:
+#endif
+
+#if XCHAL_CP1_SA_SIZE
+ bbci.l a2, 1, 2f /* CP 1 not enabled */
+ l32i a14, a13, 4 /* a14 = _xt_coproc_sa_offset[1] */
+ add a3, a14, a15 /* a3 = save area for CP 1 */
+ xchal_cp1_load a3, a4, a5, a6, a7 continue=0 ofs=-1 select=XTHAL_SAS_TIE|XTHAL_SAS_NOCC|XTHAL_SAS_CALE alloc=XTHAL_SAS_ALL
+2:
+#endif
+
+#if XCHAL_CP2_SA_SIZE
+ bbci.l a2, 2, 2f
+ l32i a14, a13, 8
+ add a3, a14, a15
+ xchal_cp2_load a3, a4, a5, a6, a7 continue=0 ofs=-1 select=XTHAL_SAS_TIE|XTHAL_SAS_NOCC|XTHAL_SAS_CALE alloc=XTHAL_SAS_ALL
+2:
+#endif
+
+#if XCHAL_CP3_SA_SIZE
+ bbci.l a2, 3, 2f
+ l32i a14, a13, 12
+ add a3, a14, a15
+ xchal_cp3_load a3, a4, a5, a6, a7 continue=0 ofs=-1 select=XTHAL_SAS_TIE|XTHAL_SAS_NOCC|XTHAL_SAS_CALE alloc=XTHAL_SAS_ALL
+2:
+#endif
+
+#if XCHAL_CP4_SA_SIZE
+ bbci.l a2, 4, 2f
+ l32i a14, a13, 16
+ add a3, a14, a15
+ xchal_cp4_load a3, a4, a5, a6, a7 continue=0 ofs=-1 select=XTHAL_SAS_TIE|XTHAL_SAS_NOCC|XTHAL_SAS_CALE alloc=XTHAL_SAS_ALL
+2:
+#endif
+
+#if XCHAL_CP5_SA_SIZE
+ bbci.l a2, 5, 2f
+ l32i a14, a13, 20
+ add a3, a14, a15
+ xchal_cp5_load a3, a4, a5, a6, a7 continue=0 ofs=-1 select=XTHAL_SAS_TIE|XTHAL_SAS_NOCC|XTHAL_SAS_CALE alloc=XTHAL_SAS_ALL
+2:
+#endif
+
+#if XCHAL_CP6_SA_SIZE
+ bbci.l a2, 6, 2f
+ l32i a14, a13, 24
+ add a3, a14, a15
+ xchal_cp6_load a3, a4, a5, a6, a7 continue=0 ofs=-1 select=XTHAL_SAS_TIE|XTHAL_SAS_NOCC|XTHAL_SAS_CALE alloc=XTHAL_SAS_ALL
+2:
+#endif
+
+#if XCHAL_CP7_SA_SIZE
+ bbci.l a2, 7, 2f
+ l32i a14, a13, 28
+ add a3, a14, a15
+ xchal_cp7_load a3, a4, a5, a6, a7 continue=0 ofs=-1 select=XTHAL_SAS_TIE|XTHAL_SAS_NOCC|XTHAL_SAS_CALE alloc=XTHAL_SAS_ALL
+2:
+#endif
+
+.Ldone2:
+ ret
+
+#endif
diff --git a/configs/esp32-core/README.txt b/configs/esp32-core/README.txt
index 514c84cef9..2b8278dab3 100644
--- a/configs/esp32-core/README.txt
+++ b/configs/esp32-core/README.txt
@@ -13,6 +13,21 @@ README for the Expressif ESP32 Core board (V2)
"application"), however for most purposes the two CPUs are
interchangeable.
+Contents
+========
+
+ o STATUS
+ o ESP32 Features
+ o ESP32 Toolchain
+ o Serial Console
+ o Buttons and LEDs
+ o Configurations
+
+STATUS
+======
+
+ The basic port is underway. No testing has yet been performed.
+
ESP32 Features
==============
@@ -60,3 +75,97 @@ ESP32 Toolchain
NOTE: The xtensa-esp32-elf configuration is only available in the
xtensa-1.22.x branch.
+
+Serial Console
+==============
+
+ To be provided
+
+Buttons and LEDs
+================
+
+ NOTE: As of this writing, I have no schematic for the ESP32 Core board.
+ The following information derives only from examining the parts visible
+ on the board.
+
+ Buttons
+ -------
+ I see two buttons labelled Boot and EN. I suspect that neither is
+ available to software.
+
+ LEDs
+ A single LED labelled D1 is available.
+
+ When CONFIG_ARCH_LEDS is defined in the NuttX configuration, NuttX will
+ control the LED as follows:
+
+ SYMBOL Meaning LED
+ ------------------- ----------------------- ------
+ LED_STARTED NuttX has been started OFF
+ LED_HEAPALLOCATE Heap has been allocated OFF
+ LED_IRQSENABLED Interrupts enabled OFF
+ LED_STACKCREATED Idle stack created ON
+ LED_INIRQ In an interrupt N/C
+ LED_SIGNAL In a signal handler N/C
+ LED_ASSERTION An assertion failed N/C
+ LED_PANIC The system has crashed FLASH
+
+ Thus is LED is statically on, NuttX has successfully booted and is,
+ apparently, running normally. If LED is flashing at approximately
+ 2Hz, then a fatal error has been detected and the system has halted.
+
+Configurations
+==============
+
+ Common Configuration Information
+ --------------------------------
+ Each ESP32 core configuration is maintained in sub-directories and
+ can be selected as follow:
+
+ cd tools
+ ./configure.sh esp32-core/
+ cd -
+ make oldconfig
+ . ./setenv.sh
+
+ Before sourcing the setenv.sh file above, you should examine it and
+ perform edits as necessary so that TOOLCHAIN_BIN is the correct path to
+ the directory than holds your toolchain binaries.
+
+ If this is a Windows native build, then configure.bat should be used
+ instead of configure.sh:
+
+ configure.bat esp32-core\
+
+ And then build NuttX by simply typing the following. At the conclusion of
+ the make, the nuttx binary will reside in an ELF file called, simply,
+ nuttx.
+
+ make oldconfig
+ make
+
+ The