Leverage the LPC54xx back to the LPC43xx (where it came from originally)

Squashed commit of the following:

    arch/arm/src/lpc43xx:  SDMMC driver now builds for the LPC43 (provided that the proper definitions appear in the board.h file).
    arch/arm/src/lpc43xx:  Update basic changes to the ported lpc54xx driver for lpc43xx clocking and GPIOs.
    arch/arm/src/lpc43xx:  Brings in the LPC54xx SD/MMC driver with absolutely no changes other than changing all occurences of 54 to 43.
    arm/arm/src/lpc43xx:  Add build support for the lpc54 SDMMC driver.
    lpc54 SDMMC:  Check for successful data transfer last.  Checking first means that we miss errors.
This commit is contained in:
Gregory Nutt 2017-12-22 08:16:19 -06:00
parent 7add46bab5
commit 6ed875a63b
8 changed files with 2928 additions and 28 deletions

View File

@ -254,6 +254,8 @@ config LPC43_SCT
config LPC43_SDMMC
bool "SD/MMC"
default n
select ARCH_HAVE_SDIO
depends on EXPERIMENTAL
config LPC43_SPI
bool "SPI"
@ -338,19 +340,6 @@ config LPC43_WWDT
endmenu # LPC43xx Peripheral Support
menu "ADC driver options"
depends on LPC43_ADC0 || LPC43_ADC1
config ADC0_MASK
hex "ADC0 mask"
default 0x01
config ADC0_FREQ
int "ADC0 frequency"
default 4500000
endmenu # ADC driver options
config LPC43_GPIO_IRQ
bool "GPIO interrupt support"
default n
@ -509,6 +498,32 @@ endif # LCP43_EXTSDRAM3
endmenu # External Memory Configuration
menu "SD/MMC Configuration"
depends on LPC43_SDMMC
config LPC43_SDMMC_PWRCTRL
bool "Power-enable pin"
default n
---help---
Select if the board supports a power-enable pin that must be selected
to provide power to the SD card.
config LPC43_SDMMC_DMA
bool "Support DMA data transfers"
default y
select SDIO_DMA
---help---
Support DMA data transfers.
config LPC43_SDMMC_REGDEBUG
bool "Register level debug"
default n
depends on DEBUG_MEMCARD_INFO
---help---
Output detailed register-level SD/MMC debug information.
endmenu # SD/MMC Configuration
menu "Ethernet MAC configuration"
depends on LPC43_ETHERNET
@ -672,6 +687,19 @@ config LPC43_ETHERNET_REGDEBUG
endmenu # Ethernet MAC configuration
menu "ADC driver options"
depends on LPC43_ADC0 || LPC43_ADC1
config ADC0_MASK
hex "ADC0 mask"
default 0x01
config ADC0_FREQ
int "ADC0 frequency"
default 4500000
endmenu # ADC driver options
menu "RS-485 Configuration"
if LPC43_USART0

View File

@ -116,6 +116,10 @@ ifeq ($(CONFIG_LPC43_WWDT),y)
CHIP_CSRCS += lpc43_wwdt.c
endif
ifeq ($(CONFIG_LPC43_SDMMC),y)
CHIP_CSRCS += lpc43_sdmmc.c
endif
ifeq ($(CONFIG_LPC43_ETHERNET),y)
CHIP_CSRCS += lpc43_ethernet.c
endif

View File

@ -643,6 +643,31 @@
# define BASE_VADC_CLKSEL_IDIVD (15 << BASE_VADC_CLK_CLKSEL_SHIFT) /* IDIVD */
# define BASE_VADC_CLKSEL_IDIVE (16 << BASE_VADC_CLK_CLKSEL_SHIFT) /* IDIVE */
/* Bits 29-31: Reserved */
/* Output stage 13 control register (BASE_SDIO_CLK) */
/* NOTE: Clocks 4-19 are identical */
#define BASE_SDIO_CLK_PD (1 << 0) /* Bit 0: Output stage power down */
/* Bits 1-10: Reserved */
#define BASE_SDIO_CLK_AUTOBLOCK (1 << 11) /* Bit 11: Block clock during frequency change */
/* Bits 12-23: Reserved */
#define BASE_SDIO_CLK_CLKSEL_SHIFT (24) /* Bits 24-28: Clock source selection */
#define BASE_SDIO_CLK_CLKSEL_MASK (31 << BASE_SDIO_CLK_CLKSEL_SHIFT)
# define BASE_SDIO_CLKSEL_32KHZOSC (0 << BASE_SDIO_CLK_CLKSEL_SHIFT) /* 32 kHz oscillator */
# define BASE_SDIO_CLKSEL_IRC (1 << BASE_SDIO_CLK_CLKSEL_SHIFT) /* IRC (default) */
# define BASE_SDIO_CLKSEL_ENET_RXCLK (2 << BASE_SDIO_CLK_CLKSEL_SHIFT) /* ENET_RX_CLK */
# define BASE_SDIO_CLKSEL_ENET_TXCLK (3 << BASE_SDIO_CLK_CLKSEL_SHIFT) /* ENET_TX_CLK */
# define BASE_SDIO_CLKSEL_GPCLKIN (4 << BASE_SDIO_CLK_CLKSEL_SHIFT) /* GP_CLKIN */
# define BASE_SDIO_CLKSEL_XTAL (6 << BASE_SDIO_CLK_CLKSEL_SHIFT) /* Crystal oscillator */
# define BASE_SDIO_CLKSEL_PLL0AUDIO (8 << BASE_SDIO_CLK_CLKSEL_SHIFT) /* PLL0AUDIO */
# define BASE_SDIO_CLKSEL_PLL1 (9 << BASE_SDIO_CLK_CLKSEL_SHIFT) /* PLL1 */
# define BASE_SDIO_CLKSEL_IDIVA (12 << BASE_SDIO_CLK_CLKSEL_SHIFT) /* IDIVA */
# define BASE_SDIO_CLKSEL_IDIVB (13 << BASE_SDIO_CLK_CLKSEL_SHIFT) /* IDIVB */
# define BASE_SDIO_CLKSEL_IDIVC (14 << BASE_SDIO_CLK_CLKSEL_SHIFT) /* IDIVC */
# define BASE_SDIO_CLKSEL_IDIVD (15 << BASE_SDIO_CLK_CLKSEL_SHIFT) /* IDIVD */
# define BASE_SDIO_CLKSEL_IDIVE (16 << BASE_SDIO_CLK_CLKSEL_SHIFT) /* IDIVE */
/* Bits 29-31: Reserved */
/* Output stage 14 control register (BASE_SSP0_CLK) */
/* NOTE: Clocks 4-19 are identical */

View File

@ -46,6 +46,11 @@
* Pre-processor Definitions
************************************************************************************************/
#define LPC43_TXFIFO_DEPTH 32
#define LPC43_TXFIFO_WIDTH 4
#define LPC43_RXFIFO_DEPTH 32
#define LPC43_RXFIFO_WIDTH 4
/* MCI register offsets (with respect to the MCI base) ******************************************/
#define LPC43_SDMMC_CTRL_OFFSET 0x0000 /* Control register */
@ -156,12 +161,16 @@
#define SDMMC_CLKDIV0_SHIFT (0) /* Bits 0-7: Clock divider 0 value */
#define SDMMC_CLKDIV0_MASK (255 << SDMMC_CLKDIV0_SHIFT)
# define SDMMC_CLKDIV0(n) ((((n) + 1) >> 1) << SDMMC_CLKDIV0_SHIFT)
#define SDMMC_CLKDIV1_SHIFT (8) /* Bits 8-15: Clock divider 1 value */
#define SDMMC_CLKDIV1_MASK (255 << SDMMC_CLKDIV1_SHIFT)
# define SDMMC_CLKDIV1(n) ((((n) + 1) >> 1) << SDMMC_CLKDIV1_SHIFT)
#define SDMMC_CLKDIV2_SHIFT (16) /* Bits 16-23: Clock divider 2 value */
#define SDMMC_CLKDIV2_MASK (255 << SDMMC_CLKDIV2_SHIFT)
# define SDMMC_CLKDIV2(n) ((((n) + 1) >> 1) << SDMMC_CLKDIV2_SHIFT)
#define SDMMC_CLKDIV3_SHIFT (24) /* Bits 24-31: Clock divider 3 value */
#define SDMMC_CLKDIV3_MASK (255 << SDMMC_CLKDIV3_SHIFT)
# define SDMMC_CLKDIV3(n) ((((n) + 1) >> 1) << SDMMC_CLKDIV3_SHIFT)
/* Clock source register CLKSRC */
@ -217,7 +226,7 @@
#define SDMMC_INT_SBE (1 << 13) /* Bit 13: Start-bit error */
#define SDMMC_INT_ACD (1 << 14) /* Bit 14: Auto command done */
#define SDMMC_INT_EBE (1 << 15) /* Bit 15: End-bit error (read)/Write no CRC */
#define SDMMC_INT_SDIO (1 << 16) /* Bit 16: Mask SDIO interrupt */
#define SDMMC_INT_SDIO (1 << 16) /* Bit 16: SDIO interrupt */
/* Bits 17-31: Reserved */
#define SDMMC_INT_ALL (0x1ffff)
@ -227,6 +236,11 @@
#define SDMMC_CMD_CMDINDEX_MASK (63 << SDMMC_CMD_CMDINDEX_SHIFT)
#define SDMMC_CMD_RESPONSE (1 << 6) /* Bit 6: Response expected from card */
#define SDMMC_CMD_LONGRESP (1 << 7) /* Bit 7: Long response expected from card */
#define SDMMC_CMD_WAITRESP_SHIFT (6) /* Bits 6-7: Response expected */
#define SDMMC_CMD_WAITRESP_MASK (3 << SDMMC_CMD_WAITRESP_SHIFT)
# define SDMMC_CMD_NORESPONSE (0 << SDMMC_CMD_WAITRESP_SHIFT) /* x0: No response */
# define SDMMC_CMD_SHORTRESPONSE (1 << SDMMC_CMD_WAITRESP_SHIFT) /* 01: Short response */
# define SDMMC_CMD_LONGRESPONSE (3 << SDMMC_CMD_WAITRESP_SHIFT) /* 11: Long response */
#define SDMMC_CMD_RESPCRC (1 << 8) /* Bit 8: Check response CRC */
#define SDMMC_CMD_DATAXFREXPTD (1 << 9) /* Bit 9: Data transfer expected (read/write) */
#define SDMMC_CMD_WRITE (1 << 10) /* Bit 10: Write to card */
@ -285,9 +299,11 @@
#define SDMMC_FIFOTH_TXWMARK_SHIFT (0) /* Bits 0-11: FIFO threshold level when transmitting */
#define SDMMC_FIFOTH_TXWMARK_MASK (0xfff << SDMMC_FIFOTH_TXWMARK_SHIFT)
# define SDMMC_FIFOTH_TXWMARK(n) ((uint32_t)(n) << SDMMC_FIFOTH_TXWMARK_SHIFT)
/* Bits 12-15: Reserved */
#define SDMMC_FIFOTH_RXWMARK_SHIFT (16) /* Bits 16-27: FIFO threshold level when receiving */
#define SDMMC_FIFOTH_RXWMARK_MASK (0xfff << SDMMC_FIFOTH_RXWMARK_SHIFT)
# define SDMMC_FIFOTH_RXWMARK(n) ((uint32_t)(n) << SDMMC_FIFOTH_RXWMARK_SHIFT)
#define SDMMC_FIFOTH_DMABURST_SHIFT (28) /* Bits 28-30: Burst size for multiple transaction */
#define SDMMC_FIFOTH_DMABURST_MASK (7 << SDMMC_FIFOTH_DMABURST_SHIFT)
# define SDMMC_FIFOTH_DMABURST_1XFR (0 << SDMMC_FIFOTH_DMABURST_SHIFT) /* 1 transfer */
@ -323,6 +339,7 @@
#define SDMMC_BMOD_FB (1 << 1) /* Bit 1: Fixed Burst */
#define SDMMC_BMOD_DSL_SHIFT (2) /* Bits 2-6: Descriptor Skip Length */
#define SDMMC_BMOD_DSL_MASK (31 << SDMMC_BMOD_DSL_SHIFT)
# define SDMMC_BMOD_DSL(n) ((uint32_t)(n) << SDMMC_BMOD_DSL_SHIFT)
#define SDMMC_BMOD_DE (1 << 7) /* Bit 7: SD/MMC DMA Enable */
#define SDMMC_BMOD_PBL_SHIFT (8) /* Bits 8-10: Programmable Burst Length */
#define SDMMC_BMOD_PBL_MASK (7 << SDMMC_BMOD_PBL_SHIFT)

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,88 @@
/************************************************************************************
* arch/arm/src/lpc43xx/lpc43_sdmmc.h
*
* Copyright (C) 2017 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
************************************************************************************/
#ifndef __ARCH_ARM_SRC_LPC43XX_LPC43_SDMMC_H
#define __ARCH_ARM_SRC_LPC43XX_LPC43_SDMMC_H
/************************************************************************************
* Included Files
************************************************************************************/
#include <nuttx/config.h>
#include <sys/types.h>
#include <stdbool.h>
#include "chip.h"
#include "chip/lpc43_sdmmc.h"
/************************************************************************************
* Public Functions
************************************************************************************/
#ifndef __ASSEMBLY__
#undef EXTERN
#if defined(__cplusplus)
#define EXTERN extern "C"
extern "C"
{
#else
#define EXTERN extern
#endif
/****************************************************************************
* Name: lpc43_sdmmc_initialize
*
* Description:
* Initialize the SD/MMC peripheral for normal operation.
*
* Input Parameters:
* slotno - Not used.
*
* Returned Values:
* A reference to an SDIO interface structure. NULL is returned on failures.
*
****************************************************************************/
struct lpc43_sdmmc_dev_s; /* See include/nuttx/sdio.h */
FAR struct sdio_dev_s *lpc43_sdmmc_initialize(int slotno);
#undef EXTERN
#if defined(__cplusplus)
}
#endif
#endif /* __ASSEMBLY__ */
#endif /* __ARCH_ARM_SRC_LPC43XX_LPC43_SDMMC_H */

View File

@ -1062,22 +1062,9 @@ static int lpc54_sdmmc_interrupt(int irq, void *context, FAR void *arg)
}
}
/* Handle data end events. Note that RXDR may accompany DTO, DTO
* will be set on received while there is still data in the FIFO.
* So for the case of receiving, we don't actually even enable the
* DTO interrupt.
*/
if ((pending & SDMMC_INT_DTO) != 0)
{
/* Finish the transfer */
lpc54_endtransfer(priv, SDIOWAIT_TRANSFERDONE);
}
/* Handle data block send/receive CRC failure */
else if ((pending & SDMMC_INT_DCRC) != 0)
if ((pending & SDMMC_INT_DCRC) != 0)
{
/* Terminate the transfer with an error */
@ -1125,6 +1112,20 @@ static int lpc54_sdmmc_interrupt(int irq, void *context, FAR void *arg)
mcerr("ERROR: Start bit, remaining: %d\n", priv->remaining);
lpc54_endtransfer(priv, SDIOWAIT_TRANSFERDONE | SDIOWAIT_ERROR);
}
/* Handle data end events. Note that RXDR may accompany DTO, DTO
* will be set on received while there is still data in the FIFO.
* So for the case of receiving, we don't actually even enable the
* DTO interrupt.
*/
else if ((pending & SDMMC_INT_DTO) != 0)
{
/* Finish the transfer */
lpc54_endtransfer(priv, SDIOWAIT_TRANSFERDONE);
}
}
/* Handle wait events *************************************************/

View File

@ -79,5 +79,10 @@ extern "C"
struct lpc54_sdmmc_dev_s; /* See include/nuttx/sdio.h */
FAR struct sdio_dev_s *lpc54_sdmmc_initialize(int slotno);
#undef EXTERN
#if defined(__cplusplus)
}
#endif
#endif /* __ASSEMBLY__ */
#endif /* __ARCH_ARM_SRC_LPC54XX_LPC54_SDMMC_H */