mirror of
https://github.com/apache/nuttx.git
synced 2026-06-06 08:36:24 +08:00
Added: MT29F2G Nand Flash block driver for sam4s-xplained-pro.
Fixed: SDIO Interface hanging after inserted SD Card. Disabled the CONFIG_SYSTEMTICK_EXTCLK, using nxsig_usleep instead of usleep
This commit is contained in:
@@ -20,4 +20,43 @@ config SAM4S_XPLAINED_PRO_CPULOAD_TIMER_DEVPATH
|
||||
default "/dev/tc0"
|
||||
depends on TIMER && SCHED_CPULOAD && SCHED_CPULOAD_EXTCLK
|
||||
|
||||
config SAM34_NAND_BLOCKMOUNT
|
||||
bool "NAND FLASH auto-mount"
|
||||
default n
|
||||
depends on NSH_ARCHINIT && SAM34_EXTNAND
|
||||
---help---
|
||||
Automatically initialize the NAND FLASH driver when NSH starts.
|
||||
|
||||
choice
|
||||
prompt "NAND FLASH configuration"
|
||||
default SAM34_NAND_NXFFS
|
||||
depends on SAM34_NAND_BLOCKMOUNT
|
||||
|
||||
config SAM34_NAND_FTL
|
||||
bool "Create NAND FLASH block driver"
|
||||
depends on MTD && MTD_NAND
|
||||
---help---
|
||||
Create the MTD driver for the NAND and "wrap" the NAND as a standard
|
||||
block driver that could then, for example, be mounted using FAT or
|
||||
any other file system. Any file system may be used, but there will
|
||||
be no wear-leveling.
|
||||
|
||||
NOTE: This options is not currently recommended. There is not now
|
||||
NuttX file system that can handle the NAND back blocks or performs
|
||||
wear-leveling other than NXFFS and NXFFS does not use a block driver
|
||||
but, rather, operates directly upon the NAND MTD device.
|
||||
|
||||
config SAM34_NAND_NXFFS
|
||||
bool "Create NAND FLASH NXFFS file system"
|
||||
depends on MTD && MTD_NAND && FS_NXFFS && NXFFS_NAND
|
||||
---help---
|
||||
Create the MTD driver for the NAND and mount the NAND device as
|
||||
a wear-leveling, NuttX FLASH file system (NXFFS). The downside of
|
||||
NXFFS is that it can be very slow.
|
||||
|
||||
NOTE: NXFFS is recommended because (1) it can handle the NAND back
|
||||
blocks and (1) performs wear-leveling.
|
||||
|
||||
endchoice # NAND FLASH configuration
|
||||
|
||||
endif
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
#
|
||||
# This file is autogenerated: PLEASE DO NOT EDIT IT.
|
||||
#
|
||||
# You can use "make menuconfig" to make any modifications to the installed .config file.
|
||||
# You can then do "make savedefconfig" to generate a new defconfig file that includes your
|
||||
# modifications.
|
||||
#
|
||||
# CONFIG_ARCH_RAMFUNCS is not set
|
||||
# CONFIG_MTD_NAND_BLOCKCHECK is not set
|
||||
# CONFIG_MTD_NAND_SWECC is not set
|
||||
CONFIG_ARCH="arm"
|
||||
CONFIG_ARCH_BOARD="sam4s-xplained-pro"
|
||||
CONFIG_ARCH_BOARD_SAM4S_XPLAINED_PRO=y
|
||||
CONFIG_ARCH_CHIP="sam34"
|
||||
CONFIG_ARCH_CHIP_ATSAM4SD32C=y
|
||||
CONFIG_ARCH_CHIP_SAM34=y
|
||||
CONFIG_ARCH_CHIP_SAM4S=y
|
||||
CONFIG_ARCH_INTERRUPTSTACK=1024
|
||||
CONFIG_ARCH_STACKDUMP=y
|
||||
CONFIG_ARMV7M_USEBASEPRI=y
|
||||
CONFIG_ARM_MPU=y
|
||||
CONFIG_BOARDCTL_USBDEVCTRL=y
|
||||
CONFIG_BOARD_LATE_INITIALIZE=y
|
||||
CONFIG_BOARD_LOOPSPERMSEC=11401
|
||||
CONFIG_BUILTIN=y
|
||||
CONFIG_CDCACM=y
|
||||
CONFIG_CDCACM_BULKIN_REQLEN=250
|
||||
CONFIG_CDCACM_RXBUFSIZE=1024
|
||||
CONFIG_CDCACM_TXBUFSIZE=1024
|
||||
CONFIG_DEBUG_FULLOPT=y
|
||||
CONFIG_DEBUG_SYMBOLS=y
|
||||
CONFIG_DEV_ZERO=y
|
||||
CONFIG_FS_FAT=y
|
||||
CONFIG_FS_PROCFS=y
|
||||
CONFIG_HAVE_CXX=y
|
||||
CONFIG_HAVE_CXXINITIALIZE=y
|
||||
CONFIG_IDLETHREAD_STACKSIZE=2048
|
||||
CONFIG_INTELHEX_BINARY=y
|
||||
CONFIG_JULIAN_TIME=y
|
||||
CONFIG_LIBC_STRERROR=y
|
||||
CONFIG_LIBC_STRERROR_SHORT=y
|
||||
CONFIG_MAX_TASKS=16
|
||||
CONFIG_MMCSD_SDIO=y
|
||||
CONFIG_MTD=y
|
||||
CONFIG_MTD_NAND=y
|
||||
CONFIG_MTD_NAND_EMBEDDEDECC=y
|
||||
CONFIG_MTD_NAND_MAXNUMBLOCKS=2048
|
||||
CONFIG_MTD_NAND_MAXNUMPAGESPERBLOCK=64
|
||||
CONFIG_MTD_NAND_MAXPAGEDATASIZE=2048
|
||||
CONFIG_MTD_NAND_MAXPAGESPARESIZE=64
|
||||
CONFIG_MTD_NAND_MAXSPAREECCBYTES=64
|
||||
CONFIG_NSH_ARCHINIT=y
|
||||
CONFIG_NSH_BUILTIN_APPS=y
|
||||
CONFIG_NSH_DISABLE_IFCONFIG=y
|
||||
CONFIG_NSH_DISABLE_LOSETUP=y
|
||||
CONFIG_NSH_FILEIOSIZE=2048
|
||||
CONFIG_NSH_READLINE=y
|
||||
CONFIG_NSH_STRERROR=y
|
||||
CONFIG_PIPES=y
|
||||
CONFIG_PREALLOC_MQ_MSGS=8
|
||||
CONFIG_PREALLOC_TIMERS=4
|
||||
CONFIG_PTHREAD_STACK_DEFAULT=4096
|
||||
CONFIG_PTHREAD_STACK_MIN=512
|
||||
CONFIG_RAM_SIZE=163840
|
||||
CONFIG_RAM_START=0x20000000
|
||||
CONFIG_RAW_BINARY=y
|
||||
CONFIG_RR_INTERVAL=50
|
||||
CONFIG_RTC=y
|
||||
CONFIG_RTC_ALARM=y
|
||||
CONFIG_RTC_FREQUENCY=32768
|
||||
CONFIG_RTC_HIRES=y
|
||||
CONFIG_SAM34_EXTNAND=y
|
||||
CONFIG_SAM34_EXTNANDSIZE=268435456
|
||||
CONFIG_SAM34_GPIOC_IRQ=y
|
||||
CONFIG_SAM34_GPIO_IRQ=y
|
||||
CONFIG_SAM34_HSMCI=y
|
||||
CONFIG_SAM34_NAND_BLOCKMOUNT=y
|
||||
CONFIG_SAM34_PDCA=y
|
||||
CONFIG_SAM34_RTC=y
|
||||
CONFIG_SAM34_RTT=y
|
||||
CONFIG_SAM34_SMC=y
|
||||
CONFIG_SAM34_TC0=y
|
||||
CONFIG_SAM34_TC1=y
|
||||
CONFIG_SAM34_UART1=y
|
||||
CONFIG_SAM34_UDP=y
|
||||
CONFIG_SAM34_USART1=y
|
||||
CONFIG_SAM34_WDT=y
|
||||
CONFIG_SCHED_HPWORK=y
|
||||
CONFIG_SCHED_WAITPID=y
|
||||
CONFIG_SDCLONE_DISABLE=y
|
||||
CONFIG_SDIO_BLOCKSETUP=y
|
||||
CONFIG_STDIO_BUFFER_SIZE=256
|
||||
CONFIG_SYSTEM_NSH=y
|
||||
CONFIG_TASK_NAME_SIZE=15
|
||||
CONFIG_UART1_SERIAL_CONSOLE=y
|
||||
CONFIG_USBDEV=y
|
||||
CONFIG_USERMAIN_STACKSIZE=4096
|
||||
CONFIG_USER_ENTRYPOINT="nsh_main"
|
||||
CONFIG_WATCHDOG=y
|
||||
CONFIG_WDT_ENABLED_ON_RESET=y
|
||||
CONFIG_WDT_THREAD_STACKSIZE=512
|
||||
@@ -15,12 +15,11 @@ CONFIG_ARCH_CHIP_SAM34=y
|
||||
CONFIG_ARCH_CHIP_SAM4S=y
|
||||
CONFIG_ARCH_INTERRUPTSTACK=1024
|
||||
CONFIG_ARCH_STACKDUMP=y
|
||||
CONFIG_ARMV7M_TOOLCHAIN_BUILDROOT=y
|
||||
CONFIG_ARMV7M_USEBASEPRI=y
|
||||
CONFIG_ARM_MPU=y
|
||||
CONFIG_BOARDCTL_USBDEVCTRL=y
|
||||
CONFIG_BOARD_LATE_INITIALIZE=y
|
||||
CONFIG_BOARD_LOOPSPERMSEC=9186
|
||||
CONFIG_BOARD_LOOPSPERMSEC=11401
|
||||
CONFIG_BUILTIN=y
|
||||
CONFIG_CDCACM=y
|
||||
CONFIG_CDCACM_BULKIN_REQLEN=250
|
||||
@@ -29,7 +28,6 @@ CONFIG_CDCACM_TXBUFSIZE=1024
|
||||
CONFIG_DEBUG_FULLOPT=y
|
||||
CONFIG_DEBUG_SYMBOLS=y
|
||||
CONFIG_DEV_ZERO=y
|
||||
CONFIG_DISABLE_ENVIRON=y
|
||||
CONFIG_EXAMPLES_CPUHOG=y
|
||||
CONFIG_EXAMPLES_SERIALBLASTER=y
|
||||
CONFIG_EXAMPLES_SERIALRX=y
|
||||
@@ -81,15 +79,11 @@ CONFIG_SAM34_UART1=y
|
||||
CONFIG_SAM34_UDP=y
|
||||
CONFIG_SAM34_USART1=y
|
||||
CONFIG_SAM34_WDT=y
|
||||
CONFIG_SCHED_CPULOAD=y
|
||||
CONFIG_SCHED_CPULOAD_EXTCLK=y
|
||||
CONFIG_SCHED_CPULOAD_TICKSPERSEC=222
|
||||
CONFIG_SCHED_HPWORK=y
|
||||
CONFIG_SCHED_WAITPID=y
|
||||
CONFIG_SDCLONE_DISABLE=y
|
||||
CONFIG_SDIO_BLOCKSETUP=y
|
||||
CONFIG_STDIO_BUFFER_SIZE=256
|
||||
CONFIG_SYSTEMTICK_EXTCLK=y
|
||||
CONFIG_SYSTEM_NSH=y
|
||||
CONFIG_TASK_NAME_SIZE=15
|
||||
CONFIG_UART1_SERIAL_CONSOLE=y
|
||||
|
||||
@@ -261,4 +261,20 @@
|
||||
|
||||
#define BUTTON_SW0_BIT (1 << BUTTON_SW0)
|
||||
|
||||
/* NAND *********************************************************************/
|
||||
|
||||
#define GPIO_SMC_RB (GPIO_INPUT | GPIO_SMC_NWAIT)
|
||||
|
||||
/* Address for transferring command bytes to the nandflash, CLE A22 */
|
||||
|
||||
#define BOARD_NCS0_NAND_CMDADDR 0x60400000
|
||||
|
||||
/* Address for transferring address bytes to the nandflash, ALE A21 */
|
||||
|
||||
#define BOARD_NCS0_NAND_ADDRADDR 0x60200000
|
||||
|
||||
/* Address for transferring data bytes to the nandflash. */
|
||||
|
||||
#define BOARD_NCS0_NAND_DATAADDR 0x60000000
|
||||
|
||||
#endif /* __BOARDS_ARM_SAM34_SAM4S_XPLAINED_PRO_INCLUDE_BOARD_H */
|
||||
|
||||
@@ -37,10 +37,20 @@ include $(TOPDIR)/Make.defs
|
||||
|
||||
CSRCS = sam_boot.c
|
||||
|
||||
ifeq ($(CONFIG_MMCSD_SPI),y)
|
||||
CSRCS += sam_spi.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_LIB_BOARDCTL),y)
|
||||
CSRCS += sam_appinit.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_SAM34_EXTNAND),y)
|
||||
ifeq ($(CONFIG_MTD_NAND),y)
|
||||
CSRCS += sam_nandflash.c
|
||||
endif
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_SAM34_HSMCI),y)
|
||||
CSRCS += sam_hsmci.c
|
||||
endif
|
||||
|
||||
@@ -60,8 +60,16 @@
|
||||
#define HAVE_HSMCI 1
|
||||
#define HAVE_PROC 1
|
||||
#define HAVE_USBDEV 1
|
||||
|
||||
#if defined(CONFIG_MTD_NAND) && defined(CONFIG_SAM34_EXTNAND)
|
||||
#define HAVE_NAND 1
|
||||
#endif
|
||||
#undef HAVE_USBMONITOR
|
||||
|
||||
#if defined(CONFIG_MMCSD_SPI)
|
||||
# define HAVE_MMCSD_SPI 1
|
||||
#endif
|
||||
|
||||
/* HSMCI */
|
||||
|
||||
/* Can't support MMC/SD if the card interface is not enabled */
|
||||
@@ -93,6 +101,16 @@
|
||||
# undef HAVE_HSMCI
|
||||
#endif
|
||||
|
||||
/* MMC/SD minor numbers */
|
||||
|
||||
#ifndef CONFIG_NSH_MMCSDMINOR
|
||||
# define CONFIG_NSH_MMCSDMINOR 0
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_NSH_MMCSDSLOTNO
|
||||
# define CONFIG_NSH_MMCSDSLOTNO 0
|
||||
#endif
|
||||
|
||||
/* USB Device */
|
||||
|
||||
/* CONFIG_SAM34_UDP and CONFIG_USBDEV must be defined, or there is no USB
|
||||
@@ -173,11 +191,24 @@
|
||||
* Public data
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __ASSEMBLY__
|
||||
/* SPI0 */
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
#ifdef HAVE_MMCSD_SPI
|
||||
#define GPIO_SPISD_NPCS0 (GPIO_OUTPUT | GPIO_CFG_PULLUP | GPIO_OUTPUT_SET | \
|
||||
GPIO_PORT_PIOA | GPIO_PIN11)
|
||||
#define SPISD_PORT SPI0_CS0
|
||||
|
||||
#define GPIO_SPI_CD (GPIO_INPUT | GPIO_CFG_PULLUP | GPIO_PORT_PIOC | GPIO_PIN19)
|
||||
#define SD_SPI_IRQ SAM_IRQ_PC19
|
||||
#endif /* HAVE_MMCSD_SPI */
|
||||
|
||||
/* NAND */
|
||||
|
||||
#ifdef HAVE_NAND
|
||||
# define NAND_MINOR 0
|
||||
# define SAM_SMC_CS0 0 /* GPIO_SMC_NCS0 connect SAM_SMC_CS0_BASE */
|
||||
int sam_nand_automount(int minor);
|
||||
#endif /* HAVE_NAND */
|
||||
|
||||
/****************************************************************************
|
||||
* Name: sam_hsmci_initialize
|
||||
@@ -193,6 +224,8 @@ int sam_hsmci_initialize(void);
|
||||
# define sam_hsmci_initialize()
|
||||
#endif
|
||||
|
||||
int sam_sdinitialize(int port, int minor);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: sam_cardinserted
|
||||
*
|
||||
@@ -235,5 +268,4 @@ bool sam_writeprotected(int slotno);
|
||||
|
||||
int sam_watchdog_initialize(void);
|
||||
|
||||
#endif /* __ASSEMBLY__ */
|
||||
#endif /* __BOARDS_ARM_SAM34_SAM4S_XPLAINED_SRC_SAM4S_XPLAINED_H */
|
||||
|
||||
@@ -114,6 +114,17 @@ int board_app_initialize(uintptr_t arg)
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_NAND
|
||||
ret = sam_nand_automount(SAM_SMC_CS0);
|
||||
if (ret < 0)
|
||||
{
|
||||
syslog(LOG_ERR,
|
||||
"ERROR: Failed to initialize the NAND: %d (%d)\n",
|
||||
ret, errno);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_HSMCI
|
||||
/* Initialize the HSMCI driver */
|
||||
|
||||
@@ -157,6 +168,18 @@ int board_app_initialize(uintptr_t arg)
|
||||
}
|
||||
#endif
|
||||
|
||||
/* SPI */
|
||||
|
||||
#ifdef HAVE_MMCSD_SPI
|
||||
ret = sam_sdinitialize(0, 0);
|
||||
if (ret < 0)
|
||||
{
|
||||
syslog(LOG_ERR, "ERROR: Failed to initialize MMC/SD slot: %d\n",
|
||||
ret);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_USBMONITOR
|
||||
/* Start the USB Monitor */
|
||||
|
||||
|
||||
@@ -0,0 +1,245 @@
|
||||
/****************************************************************************
|
||||
* boards/arm/sam34/sam4s-xplained-pro/src/sam_nandflash.c
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <sys/mount.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <errno.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/mtd/mtd.h>
|
||||
#include <nuttx/fs/nxffs.h>
|
||||
#include <arch/board/board.h>
|
||||
|
||||
#include "arm_arch.h"
|
||||
#include "sam_periphclks.h"
|
||||
#include "sam4s_nand.h"
|
||||
#include "hardware/sam_smc.h"
|
||||
#include "hardware/sam4s_pinmap.h"
|
||||
#include "hardware/sam_matrix.h"
|
||||
|
||||
#include "sam4s-xplained-pro.h"
|
||||
|
||||
#ifdef HAVE_NAND
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
static const gpio_pinset_t g_nandpins[] =
|
||||
{
|
||||
GPIO_SMC_NCS0, GPIO_SMC_NANDALE, GPIO_SMC_NANDCLE,
|
||||
GPIO_SMC_NANDOE, GPIO_SMC_NANDWE, GPIO_SMC_RB,
|
||||
|
||||
GPIO_SMC_D0, GPIO_SMC_D1, GPIO_SMC_D2, GPIO_SMC_D3,
|
||||
GPIO_SMC_D4, GPIO_SMC_D5, GPIO_SMC_D6, GPIO_SMC_D7
|
||||
};
|
||||
|
||||
#define NAND_NPINS (sizeof(g_nandpins) / sizeof(gpio_pinset_t))
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: board_nandflash_config
|
||||
*
|
||||
* Description:
|
||||
* If CONFIG_SAM34_EXTNAND is defined, then NAND FLASH support is
|
||||
* enabled. This function provides the board-specific implementation of
|
||||
* the logic to reprogram the SMC to support NAND FLASH on the specified
|
||||
* CS.
|
||||
*
|
||||
* Input Parameters:
|
||||
* cs - Chip select number (in the event that multiple NAND devices
|
||||
* are connected on-board).
|
||||
*
|
||||
* Returned Value:
|
||||
* OK if the HSMC was successfully configured for this CS. A negated
|
||||
* errno value is returned on a failure. This would fail with -ENODEV,
|
||||
* for example, if the board does not support NAND FLASH on the requested
|
||||
* CS.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int board_nandflash_config(int cs)
|
||||
{
|
||||
/* The Embest and Ronetix CM boards and one Hynix NAND HY27UF(08/16)2G2B
|
||||
* Series NAND (MT29F2G08ABAEAWP).
|
||||
* This part has a capacity of 256Mx8bit () with spare 8Mx8 bit capacity.
|
||||
* The device contains 2048 blocks, composed by 64 x 2112 byte pages.
|
||||
* The effective size is approximately 256MiB.
|
||||
*
|
||||
* NAND is available on NCS0.
|
||||
*/
|
||||
|
||||
int i;
|
||||
|
||||
/* Configure GPIO pins (leaving SRAM in the disabled state) */
|
||||
|
||||
for (i = 0; i < NAND_NPINS; i++)
|
||||
{
|
||||
sam_configgpio(g_nandpins[i]);
|
||||
}
|
||||
|
||||
/* SMC NAND Flash Chip Select Configuration Register */
|
||||
|
||||
putreg32(MATRIX_CCFG_SMCNFCS_SMC_NFCS(cs), SAM_MATRIX_CCFG_SMCNFCS);
|
||||
|
||||
/* below from sam4s-xplained */
|
||||
|
||||
sam_smc_enableclk();
|
||||
|
||||
/* Configure SMC setup timing */
|
||||
|
||||
putreg32(SMCCS_SETUP_NWESETUP(3) | SMCCS_SETUP_NCSWRSETUP(1) |
|
||||
SMCCS_SETUP_NRDSETUP(2) | SMCCS_SETUP_NCSRDSETUP(1),
|
||||
SAM_SMCCS_SETUP(cs));
|
||||
|
||||
/* Configure the SMC pulse timing */
|
||||
|
||||
putreg32(SMCCS_PULSE_NWEPULSE(5) | SMCCS_PULSE_NCSWRPULSE(5) |
|
||||
SMCCS_PULSE_NRDPULSE(5) | SMCCS_PULSE_NCSRDPULSE(5),
|
||||
SAM_SMCCS_PULSE(cs));
|
||||
|
||||
/* Configure the SMC cycle timing */
|
||||
|
||||
/**
|
||||
* Select 0. Chip Select 0 has been programmed with:
|
||||
* NRD_HOLD = 4; READ_MODE = 1 (NRD controlled)
|
||||
* NWE_SETUP = 3; WRITE_MODE = 1 (NWE controlled)
|
||||
* TDF_CYCLES = 6; TDF_MODE = 1 (optimization enabled).
|
||||
*/
|
||||
|
||||
putreg32(SMCCS_CYCLE_NWECYCLE(12) | SMCCS_CYCLE_NRDCYCLE(11),
|
||||
SAM_SMCCS_CYCLE(cs));
|
||||
|
||||
/* Configure the SMC mode */
|
||||
|
||||
/**
|
||||
*
|
||||
* READ_MODE:
|
||||
* 0: The read operation is controlled by the NCS signal.
|
||||
* 1: The read operation is controlled by the NRD signal.
|
||||
*
|
||||
**/
|
||||
|
||||
putreg32(SMCCS_MODE_TDFCYCLES(6) | SMCCS_MODE_TDFMODE |
|
||||
SMCCS_MODE_WRITEMODE | SMCCS_MODE_READMODE,
|
||||
SAM_SMCCS_MODE(cs));
|
||||
|
||||
/* Configure NAND PIO pins
|
||||
*
|
||||
* NAND Interface NAND DESC
|
||||
*
|
||||
* NCS0 CE - Dedicated pin; no configuration needed
|
||||
* NANDCLE CLE - Dedicated pin; no configuration needed
|
||||
* NANDALE ALE - Dedicated pin; no configuration needed
|
||||
* NANDOE RE - Dedicated pin; no configuration needed
|
||||
* NANDWE WE - Dedicated pin; no configuration needed
|
||||
* NAND_RB RB - PC13
|
||||
* IO_D0-7 IO0-7 - Dedicated pins; no configuration needed
|
||||
*/
|
||||
|
||||
sam_configgpio(GPIO_SMC_NANDALE);
|
||||
sam_configgpio(GPIO_SMC_NANDCLE);
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: sam_nand_automount
|
||||
*
|
||||
* Description:
|
||||
* Initialize and configure the NAND on CS3
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int sam_nand_automount(int minor)
|
||||
{
|
||||
FAR struct mtd_dev_s *mtd;
|
||||
static bool initialized = false;
|
||||
|
||||
/* Have we already initialized? */
|
||||
|
||||
if (!initialized)
|
||||
{
|
||||
/* Create and initialize an NAND MATD device */
|
||||
|
||||
mtd = sam_nand_initialize(SAM_SMC_CS0);
|
||||
|
||||
if (!mtd)
|
||||
{
|
||||
ferr("ERROR: Failed to create the NAND driver on CS%d\n",
|
||||
SAM_SMC_CS0);
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
#if defined(CONFIG_SAM34_NAND_FTL)
|
||||
/* Use the FTL layer to wrap the MTD driver as a block driver */
|
||||
|
||||
int ret = OK;
|
||||
ret = ftl_initialize(NAND_MINOR, mtd);
|
||||
if (ret < 0)
|
||||
{
|
||||
ferr("ERROR: Failed to initialize the FTL layer: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#elif defined(CONFIG_SAM34_NAND_NXFFS)
|
||||
/* Initialize to provide NXFFS on the MTD interface */
|
||||
|
||||
int ret = OK;
|
||||
ret = nxffs_initialize(mtd);
|
||||
if (ret < 0)
|
||||
{
|
||||
ferr("ERROR: NXFFS initialization failed: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Mount the file system at /mnt/nand */
|
||||
|
||||
ret = mount(NULL, "/mnt/nand", "nxffs", 0, NULL);
|
||||
if (ret < 0)
|
||||
{
|
||||
ferr("ERROR: Failed to mount the NXFFS volume: %d\n", errno);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Now we are initialized */
|
||||
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
#endif /* HAVE_NAND */
|
||||
@@ -0,0 +1,195 @@
|
||||
/****************************************************************************
|
||||
* boards/arm/sam34/sam4s-xplained-pro/src/sam_spi.c
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <debug.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <nuttx/spi/spi.h>
|
||||
#include <arch/board/board.h>
|
||||
|
||||
#include "arm_arch.h"
|
||||
#include "chip.h"
|
||||
#include "sam_gpio.h"
|
||||
#include "sam_spi.h"
|
||||
#include "sam4s-xplained-pro.h"
|
||||
|
||||
#if defined(CONFIG_SAM34_SPI0)
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: sam_spidev_initialize
|
||||
*
|
||||
* Description:
|
||||
* Called to configure SPI chip select PIO pins for the SAM4S-Xplained-Pro
|
||||
* board.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void weak_function sam_spidev_initialize(void)
|
||||
{
|
||||
#ifdef CONFIG_SAM34_SPI0
|
||||
sam_configgpio(GPIO_SPI0_NPCS0);
|
||||
#endif
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: sam_spi[0|1]select, sam_spi[0|1]status, and sam_spi[0|1]cmddata
|
||||
*
|
||||
* Description:
|
||||
* These external functions must be provided by board-specific logic.
|
||||
* They include:
|
||||
*
|
||||
* o sam_spi[0|1]select is a functions tomanage the board-specific chip
|
||||
* selects
|
||||
* o sam_spi[0|1]status and sam_spi[0|1]cmddata:
|
||||
* Implementations of the status and cmddata methods of the SPI interface
|
||||
* defined by struct spi_ops_(see include/nuttx/spi/spi.h).
|
||||
* All other methods including sam_spibus_initialize()) are provided by
|
||||
* common SAM3/4 logic.
|
||||
*
|
||||
* To use this common SPI logic on your board:
|
||||
*
|
||||
* 1. Provide logic in sam_boardinitialize() to configure SPI chip select
|
||||
* pins.
|
||||
* 2. Provide sam_spi[0|1]select() and sam_spi[0|1]status() functions in
|
||||
* your board-specific logic.
|
||||
* These functions will perform chip selection and status operations
|
||||
* using PIOs in the way your board is configured.
|
||||
* 2. If CONFIG_SPI_CMDDATA is defined in the NuttX configuration, provide
|
||||
* sam_spi[0|1]cmddata() functions in your board-specific logic. This
|
||||
* function will perform cmd/data selection operations using PIOs in
|
||||
* the way your board is configured.
|
||||
* 3. Add a call to sam_spibus_initialize() in your low level application
|
||||
* initialization logic
|
||||
* 4. The handle returned by sam_spibus_initialize() may then be used to
|
||||
* bind the SPI driver to higher level logic (e.g., calling
|
||||
* mmcsd_spislotinitialize(), for example, will bind the SPI driver to
|
||||
* the SPI MMC/SD driver).
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: sam_spi[0|1]select
|
||||
*
|
||||
* Description:
|
||||
* PIO chip select pins may be programmed by the board specific logic in
|
||||
* one of two different ways. First, the pins may be programmed as SPI
|
||||
* peripherals. In that case, the pins are completely controlled by the
|
||||
* SPI driver. This method still needs to be provided, but it may be only
|
||||
* a stub.
|
||||
*
|
||||
* An alternative way to program the PIO chip select pins is as a normal
|
||||
* PIO output. In that case, the automatic control of the CS pins is
|
||||
* bypassed and this function must provide control of the chip select.
|
||||
* NOTE: In this case, the PIO output pin does *not* have to be the
|
||||
* same as the NPCS pin normal associated with the chip select number.
|
||||
*
|
||||
* Input Parameters:
|
||||
* devid - Identifies the (logical) device
|
||||
* selected - TRUE:Select the device, FALSE:De-select the device
|
||||
*
|
||||
* Returned Value:
|
||||
* None
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_SAM34_SPI0
|
||||
void sam_spi0select(uint32_t devid, bool selected)
|
||||
{
|
||||
#ifdef CONFIG_MMCSD_SPI
|
||||
/* The AT25 serial FLASH connects using NPCS0 */
|
||||
|
||||
if (devid == SPIDEV_MMCSD(0))
|
||||
{
|
||||
sam_gpiowrite(GPIO_SPI0_NPCS0, !selected);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: sam_spi[0|1]status
|
||||
*
|
||||
* Description:
|
||||
* Return status information associated with the SPI device.
|
||||
*
|
||||
* Input Parameters:
|
||||
* devid - Identifies the (logical) device
|
||||
*
|
||||
* Returned Value:
|
||||
* Bit-encoded SPI status (see include/nuttx/spi/spi.h.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_SAM34_SPI0
|
||||
uint8_t sam_spi0status(FAR struct spi_dev_s *dev, uint32_t devid)
|
||||
{
|
||||
return SPI_STATUS_PRESENT;
|
||||
}
|
||||
#endif
|
||||
|
||||
int sam_sdinitialize(int port, int minor)
|
||||
{
|
||||
FAR struct spi_dev_s *spi;
|
||||
int ret;
|
||||
|
||||
/* Get the SPI driver instance for the SD chip select */
|
||||
|
||||
finfo("Initializing SERCOM SPI%d\n", port);
|
||||
|
||||
spi = sam_spibus_initialize(port);
|
||||
if (!spi)
|
||||
{
|
||||
ferr("ERROR: Failed to initialize SPI%d\n", port);
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
finfo("Successfully initialized SPI%d\n", port);
|
||||
|
||||
/* Bind the SPI device for the chip select to the slot */
|
||||
|
||||
finfo("Binding SPI%d to MMC/SD slot %d\n", port, 0);
|
||||
|
||||
ret = mmcsd_spislotinitialize(minor, 0, spi);
|
||||
if (ret < 0)
|
||||
{
|
||||
ferr("ERROR: Failed to bind SPI%d to MMC/SD slot %d: %d\n",
|
||||
port, 0, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
finfo("Successfully bound SPI%d to MMC/SD slot %d\n",
|
||||
port, 0);
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_SAM34_SPI0 */
|
||||
Reference in New Issue
Block a user