diff --git a/arch/arm/src/kinetis/kinetis_sdhc.c b/arch/arm/src/kinetis/kinetis_sdhc.c index afc85f59892..144007c9c3e 100644 --- a/arch/arm/src/kinetis/kinetis_sdhc.c +++ b/arch/arm/src/kinetis/kinetis_sdhc.c @@ -1,7 +1,7 @@ /**************************************************************************** * arch/arm/src/kinetis/kinetis_sdhc.c * - * Copyright (C) 2011-2012, 2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2011-2012, 2014, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without diff --git a/configs/freedom-k64f/Kconfig b/configs/freedom-k64f/Kconfig index 7c0f1fe281d..e1c32bbfb04 100644 --- a/configs/freedom-k64f/Kconfig +++ b/configs/freedom-k64f/Kconfig @@ -4,4 +4,34 @@ # if ARCH_BOARD_FREEDOM_K64F + +config FRDMK64F_SDHC_AUTOMOUNT + bool "SDHC automounter" + default n + depends on FS_AUTOMOUNTER && SAMA5_SDHC + +if FRDMK64F_SDHC_AUTOMOUNT + +config FRDMK64F_SDHC_AUTOMOUNT_FSTYPE + string "SDHC file system type" + default "vfat" + +config FRDMK64F_SDHC_AUTOMOUNT_BLKDEV + string "SDHC block device" + default "/dev/mmcsd0" + +config FRDMK64F_SDHC_AUTOMOUNT_MOUNTPOINT + string "SDHC mount point" + default "/mnt/sdcard0" + +config FRDMK64F_SDHC_AUTOMOUNT_DDELAY + int "SDHC debounce delay (milliseconds)" + default 1000 + +config FRDMK64F_SDHC_AUTOMOUNT_UDELAY + int "SDHC unmount retry delay (milliseconds)" + default 2000 + +endif # FRDMK64F_SDHC_AUTOMOUNT + endif diff --git a/configs/freedom-k64f/README.txt b/configs/freedom-k64f/README.txt index 0aaeb99a9cc..96594370910 100644 --- a/configs/freedom-k64f/README.txt +++ b/configs/freedom-k64f/README.txt @@ -11,6 +11,7 @@ Contents o Serial Console o LEDs and Buttons o Networking Support + o SD Card Support o Development Environment o GNU Toolchain Options o Freedom K64F Configuration Options @@ -409,6 +410,134 @@ f Application Configuration -> Network Utilities CONFIG_NSH_NETINIT_RETRYMSEC=2000 : Configure the network monitor as you like CONFIG_NSH_NETINIT_SIGNO=18 +SD Card Support +=============== + + Card Slot + --------- + A micro Secure Digital (SD) card slot is available on the FRDM-K64F connected to + the SD Host Controller (SDHC) signals of the MCU. This slot will accept micro + format SD memory cards. The SD card detect pin (PTE6) is an open switch that + shorts with VDD when card is inserted. + + ------------ ------------- -------- + SD Card Slot Board Signal K64F Pin + ------------ ------------- -------- + DAT0 SDHC0_D0 PTE0 + DAT1 SDHC0_D1 PTE1 + DAT2 SDHC0_D2 PTE5 + CD/DAT3 SDHC0_D3 PTE4 + CMD SDHC0_CMD PTE3 + CLK SDHC0_DCLK PTE2 + SWITCH D_CARD_DETECT PTE6 + ------------ ------------- -------- + + There is no Write Protect pin available to the K64F. + + Configuration Settings + ---------------------- + Enabling SDHC support. The Freedom K64F provides one microSD memory card + slot. Support for the SD slots can be enabled with the following + settings: + + System Type->Kinetic Peripheral Selection + CONFIG_KINETIS_SDHC=y : To enable SDHC0 support + + System Type + CONFIG_GPIO_IRQ=y : GPIO interrupts needed + CONFIG_KINETIS_PORTEINTS=y : Card detect pin is on PTE6 + + Device Drivers -> MMC/SD Driver Support + CONFIG_MMCSD=y : Enable MMC/SD support + CONFIG_MMSCD_NSLOTS=1 : One slot per driver instance + CONFIG_MMCSD_MULTIBLOCK_DISABLE=y : (REVISIT) + CONFIG_MMCSD_HAVECARDDETECT=y : Supports card-detect PIOs + CONFIG_MMCSD_MMCSUPPORT=n : Interferes with some SD cards + CONFIG_MMCSD_SPI=n : No SPI-based MMC/SD support + CONFIG_MMCSD_SDIO=y : SDIO-based MMC/SD support + CONFIG_SDIO_DMA=y : Use SDIO DMA + CONFIG_SDIO_BLOCKSETUP=y : Needs to know block sizes + + RTOS Features -> Work Queue Support + CONFIG_SCHED_WORKQUEUE=y : Driver needs work queue support + CONFIG_SCHED_HPWORK=y + + Application Configuration -> NSH Library + CONFIG_NSH_ARCHINIT=y : NSH board-initialization, and + CONFIG_LIB_BOARDCTL=y : Or + CONFIG_BOARD_INITIALIZE=y + + Using the SD card + ----------------- + + 1. After booting, the SDHC device will appear as /dev/mmcsd0. + 2. If you try mounting an SD card with nothing in the slot, the mount will + fail: + + nsh> mount -t vfat /dev/mmcsd0 /mnt/sd0 + nsh: mount: mount failed: 19 + + NSH can be configured to provide errors as strings instead of + numbers. But in this case, only the error number is reported. The + error numbers can be found in nuttx/include/errno.h: + + #define ENODEV 19 + #define ENODEV_STR "No such device" + + So the mount command is saying that there is no device or, more + correctly, that there is no card in the SD card slot. + + 3. Insert the SD card. Then the mount should succeed. + + nsh> mount -t vfat /dev/mmcsd0 /mnt/sd0 + nsh> ls /mnt/sd1 + /mnt/sd1: + atest.txt + nsh> cat /mnt/sd1/atest.txt + This is a test + + NOTE: See the next section entitled "Auto-Mounter" for another way + to mount your SD card. + + 4. Before removing the card, you must umount the file system. This is + equivalent to "ejecting" or "safely removing" the card on Windows: It + flushes any cached data to an SD card and makes the SD card unavailable + to the applications. + + nsh> umount -t /mnt/sd0 + + It is now safe to remove the card. NuttX provides into callbacks + that can be used by an application to automatically unmount the + volume when it is removed. But those callbacks are not used in + these configurations. + + Auto-Mounter + ------------ + NuttX implements an auto-mounter than can make working with SD cards + easier. With the auto-mounter, the file system will be automatically + mounted when the SD card is inserted into the SDHC slot and automatically + unmounted when the SD card is removed. + + Here is a sample configuration for the auto-mounter: + + File System Configuration + CONFIG_FS_AUTOMOUNTER=y + + Board-Specific Options + CONFIG_FRDMK64F_SDHC_AUTOMOUNT=y + CONFIG_FRDMK64F_SDHC_AUTOMOUNT_FSTYPE="vfat" + CONFIG_FRDMK64F_SDHC_AUTOMOUNT_BLKDEV="/dev/mmcsd0" + CONFIG_FRDMK64F_SDHC_AUTOMOUNT_MOUNTPOINT="/mnt/sdcard" + CONFIG_FRDMK64F_SDHC_AUTOMOUNT_DDELAY=1000 + CONFIG_FRDMK64F_SDHC_AUTOMOUNT_UDELAY=2000 + + WARNING: SD cards should never be removed without first unmounting + them. This is to avoid data and possible corruption of the file + system. Certainly this is the case if you are writing to the SD card + at the time of the removal. If you use the SD card for read-only access, + however, then I cannot think of any reason why removing the card without + mounting would be harmful. + Development Environment ======================= @@ -639,13 +768,6 @@ Where is one of the following: 1. Most of the notes associated with the nsh configuration apply here as well (see below). - 2. Default platform/toolchain: - - CONFIG_HOST_WINDOWS=y : Cygwin under Windows - CONFIG_WINDOWS_CYGWIN=y - CONFIG_ARMV7M_TOOLCHAIN_GNU_EABIW=y : ARM/mbed toolcahin (arm-none-elf-gcc) - CONFIG_INTELHEX_BINARY=y : Output formats: Intel hex binary - 3. No external pullup is available on MDIO signal when MK64FN1M0VLL12 MCU is requests status of the Ethernet link connection. Internal pullup is required when port configuration for MDIO signal is enabled: @@ -682,9 +804,9 @@ Where is one of the following: 2. Default platform/toolchain: - CONFIG_HOST_LINUX=y : Linux (Cygwin under Windows okay too). - CONFIG_ARMV7M_TOOLCHAIN_BUILDROOT=y : Buildroot (arm-nuttx-elf-gcc) - CONFIG_ARMV7M_OABI_TOOLCHAIN=y : The older OABI version + CONFIG_HOST_WINDOWS=y : Cygwin under Windows + CONFIG_WINDOWS_CYGWIN=y + CONFIG_ARMV7M_TOOLCHAIN_GNU_EABIW=y : ARM/mbed toolcahin (arm-none-elf-gcc) CONFIG_INTELHEX_BINARY=y : Output formats: Intel hex binary 3. The Serial Console is provided on UART3 with the correct pin @@ -723,7 +845,7 @@ Status 2016-07-12: Added support for the KSZ8081 PHY and added the netnsh configuration. The network is basically functional, but a lot more testing is needed to confirm that. - + In testing, I notice a strange thing. If I run at full optimization the code runs (albeit with bugs-to-be-solved). But with no optimization or even at -O1, the system fails to boot. This seems to be related to the diff --git a/configs/freedom-k64f/nsh/defconfig b/configs/freedom-k64f/nsh/defconfig index 7fb687ca4a6..4dd783b2264 100644 --- a/configs/freedom-k64f/nsh/defconfig +++ b/configs/freedom-k64f/nsh/defconfig @@ -8,10 +8,14 @@ # # CONFIG_EXPERIMENTAL is not set # CONFIG_DEFAULT_SMALL is not set -CONFIG_HOST_LINUX=y +# CONFIG_HOST_LINUX is not set # CONFIG_HOST_OSX is not set -# CONFIG_HOST_WINDOWS 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 @@ -135,12 +139,18 @@ CONFIG_ARM_HAVE_MPU_UNIFIED=y # CONFIG_ARMV7M_HAVE_DCACHE is not set # CONFIG_ARMV7M_HAVE_ITCM is not set # CONFIG_ARMV7M_HAVE_DTCM is not set +# CONFIG_ARMV7M_TOOLCHAIN_IARW is not set # CONFIG_ARMV7M_TOOLCHAIN_IARL is not set -CONFIG_ARMV7M_TOOLCHAIN_BUILDROOT=y +# CONFIG_ARMV7M_TOOLCHAIN_ATOLLIC is not set +# CONFIG_ARMV7M_TOOLCHAIN_BUILDROOT is not set # CONFIG_ARMV7M_TOOLCHAIN_CODEREDL is not set +# CONFIG_ARMV7M_TOOLCHAIN_CODEREDW is not set # CONFIG_ARMV7M_TOOLCHAIN_CODESOURCERYL is not set +# CONFIG_ARMV7M_TOOLCHAIN_CODESOURCERYW is not set +# CONFIG_ARMV7M_TOOLCHAIN_DEVKITARM is not set # CONFIG_ARMV7M_TOOLCHAIN_GNU_EABIL is not set -CONFIG_ARMV7M_OABI_TOOLCHAIN=y +CONFIG_ARMV7M_TOOLCHAIN_GNU_EABIW=y +# CONFIG_ARMV7M_TOOLCHAIN_RAISONANCE is not set # CONFIG_ARMV7M_HAVE_STACKCHECK is not set # CONFIG_ARMV7M_ITMSYSLOG is not set diff --git a/configs/freedom-k64f/nsh/setenv.sh b/configs/freedom-k64f/nsh/setenv.sh index 45d7f9dd118..abb64617f41 100644 --- a/configs/freedom-k64f/nsh/setenv.sh +++ b/configs/freedom-k64f/nsh/setenv.sh @@ -61,7 +61,7 @@ fi # 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" +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/ @@ -69,7 +69,7 @@ fi # 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" +# 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}" diff --git a/configs/freedom-k64f/src/Makefile b/configs/freedom-k64f/src/Makefile index 65cba8c536c..3538dc384be 100644 --- a/configs/freedom-k64f/src/Makefile +++ b/configs/freedom-k64f/src/Makefile @@ -54,6 +54,13 @@ else ifeq ($(CONFIG_BOARD_INITIALIZE),y) CSRCS += k64_bringup.c endif +ifeq ($(CONFIG_KINETIS_SDHC),y) +CSRCS += k64_sdhc.c +ifeq ($(CONFIG_FS_AUTOMOUNTER),y) +CSRCS += k64_automount.c +endif +endif + ifeq ($(CONFIG_USBDEV),y) CSRCS += k64_usbdev.c endif diff --git a/configs/freedom-k64f/src/freedom-k64f.h b/configs/freedom-k64f/src/freedom-k64f.h index a6758ebb0f6..227a6c71a22 100644 --- a/configs/freedom-k64f/src/freedom-k64f.h +++ b/configs/freedom-k64f/src/freedom-k64f.h @@ -53,9 +53,10 @@ /* Assume we have everything */ -#define HAVE_PROC 1 -#define NSH_HAVEUSBDEV 1 -#define NSH_HAVEMMCSD 1 +#define HAVE_PROC 1 +#define HAVE_MMCSD 1 +#define HAVE_AUTOMOUNTER 1 +#define HAVE_USBDEV 1 /* Automount procfs */ @@ -83,12 +84,18 @@ */ #if defined(CONFIG_DISABLE_MOUNTPOINT) || !defined(CONFIG_KINETIS_SDHC) -# undef NSH_HAVEMMCSD +# undef HAVE_MMCSD #endif -#ifdef NSH_HAVEMMCSD +#ifdef HAVE_MMCSD # if defined(CONFIG_NSH_MMCSDSLOTNO) && CONFIG_NSH_MMCSDSLOTNO != 0 -# error "Only one MMC/SD slot, slot 0" +# error Only one MMC/SD slot, slot 0 +# endif + +# ifdef CONFIG_NSH_MMCSDMINOR +# define MMSCD_MINOR CONFIG_NSH_MMCSDMINOR +# else +# define MMSCD_MINOR 0 # endif /* We expect to receive GPIO interrupts for card insertion events */ @@ -100,12 +107,49 @@ # ifndef CONFIG_KINETIS_PORTEINTS # error "CONFIG_KINETIS_PORTEINTS required for card detect interrupt" # endif + #endif +/* Automounter */ + +#if !defined(CONFIG_FS_AUTOMOUNTER) || !defined(HAVE_MMCSD) +# undef HAVE_AUTOMOUNTER +# undef CONFIG_FRDMK64F_SDHC_AUTOMOUNT +#endif + +#ifndef CONFIG_FRDMK64F_SDHC_AUTOMOUNT +# undef HAVE_AUTOMOUNTER +#endif + +/* Automounter defaults */ + +#ifdef HAVE_AUTOMOUNTER + +# ifndef CONFIG_FRDMK64F_SDHC_AUTOMOUNT_FSTYPE +# define CONFIG_FRDMK64F_SDHC_AUTOMOUNT_FSTYPE "vfat" +# endif + +# ifndef CONFIG_FRDMK64F_SDHC_AUTOMOUNT_BLKDEV +# define CONFIG_FRDMK64F_SDHC_AUTOMOUNT_BLKDEV "/dev/mmcds0" +# endif + +# ifndef CONFIG_FRDMK64F_SDHC_AUTOMOUNT_MOUNTPOINT +# define CONFIG_FRDMK64F_SDHC_AUTOMOUNT_MOUNTPOINT "/mnt/sdcard0" +# endif + +# ifndef CONFIG_FRDMK64F_SDHC_AUTOMOUNT_DDELAY +# define CONFIG_FRDMK64F_SDHC_AUTOMOUNT_DDELAY 1000 +# endif + +# ifndef CONFIG_FRDMK64F_SDHC_AUTOMOUNT_UDELAY +# define CONFIG_FRDMK64F_SDHC_AUTOMOUNT_UDELAY 2000 +# endif +#endif /* HAVE_AUTOMOUNTER */ + /* Can't support USB features if USB is not enabled */ #ifndef CONFIG_USBDEV -# undef NSH_HAVEUSBDEV +# undef HAVE_USBDEV #endif /* How many SPI modules does this chip support? The LM3S6918 supports 2 SPI @@ -126,6 +170,18 @@ * format SD memory cards. The SD card detect pin (PTE6) is an open switch that * shorts with VDD when card is inserted. * + * ------------ ------------- -------- + * SD Card Slot Board Signal K64F Pin + * ------------ ------------- -------- + * DAT0 SDHC0_D0 PTE0 + * DAT1 SDHC0_D1 PTE1 + * DAT2 SDHC0_D2 PTE5 + * CD/DAT3 SDHC0_D3 PTE4 + * CMD SDHC0_CMD PTE3 + * CLK SDHC0_DCLK PTE2 + * SWITCH D_CARD_DETECT PTE6 + * ------------ ------------- -------- + * * There is no Write Protect pin available to the K64F. */ @@ -200,5 +256,89 @@ void weak_function k64_usbinitialize(void); int k64_bringup(void); #endif +/**************************************************************************** + * Name: k64_sdhc_initialize + * + * Description: + * Inititialize the SDHC SD card slot + * + ****************************************************************************/ + +#ifdef HAVE_MMCSD +int k64_sdhc_initialize(void); +#else +# define k64_sdhc_initialize() (OK) +#endif + +/************************************************************************************ + * Name: k64_cardinserted + * + * Description: + * Check if a card is inserted into the SDHC slot + * + ************************************************************************************/ + +#ifdef HAVE_AUTOMOUNTER +bool k64_cardinserted(void); +#else +# define k64_cardinserted() (false) +#endif + +/************************************************************************************ + * Name: k64_writeprotected + * + * Description: + * Check if the card in the MMC/SD slot is write protected + * + ************************************************************************************/ + +#ifdef HAVE_AUTOMOUNTER +bool k64_writeprotected(void); +#else +# define k64_writeprotected() (false) +#endif + +/************************************************************************************ + * Name: k64_automount_initialize + * + * Description: + * Configure auto-mounter for the configured SDHC slot + * + * Input Parameters: + * None + * + * Returned Value: + * None + * + ************************************************************************************/ + +#ifdef HAVE_AUTOMOUNTER +void k64_automount_initialize(void); +#endif + +/************************************************************************************ + * Name: k64_automount_event + * + * Description: + * The SDHC card detection logic has detected an insertion or removal event. It + * has already scheduled the MMC/SD block driver operations. Now we need to + * schedule the auto-mount event which will occur with a substantial delay to make + * sure that everything has settle down. + * + * Input Parameters: + * inserted - True if the card is inserted in the slot. False otherwise. + * + * Returned Value: + * None + * + * Assumptions: + * Interrupts are disabled. + * + ************************************************************************************/ + +#ifdef HAVE_AUTOMOUNTER +void k64_automount_event(bool inserted); +#endif + #endif /* __ASSEMBLY__ */ #endif /* __CONFIGS_FREEDOM_K64F_SRC_FREEDOM_K64F_H */ diff --git a/configs/freedom-k64f/src/k64_bringup.c b/configs/freedom-k64f/src/k64_bringup.c index 0cbbb1bb280..9cfa47b1183 100644 --- a/configs/freedom-k64f/src/k64_bringup.c +++ b/configs/freedom-k64f/src/k64_bringup.c @@ -39,112 +39,26 @@ #include +#include #include -#include -#include #include #include -#ifdef CONFIG_KINETIS_SDHC -# include -# include -#endif - -#include "kinetis.h" #include "freedom-k64f.h" #if defined(CONFIG_LIB_BOARDCTL) || defined(CONFIG_BOARD_INITIALIZE) -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/* This structure encapsulates the global variable used in this file and - * reduces the probability of name collistions. - */ - -#ifdef NSH_HAVEMMCSD -struct k64_nsh_s -{ - FAR struct sdio_dev_s *sdhc; /* SDIO driver handle */ - bool inserted; /* True: card is inserted */ -}; -#endif - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -#ifdef NSH_HAVEMMCSD -static struct k64_nsh_s g_nsh; -#endif - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: k64_mediachange - ****************************************************************************/ - -#ifdef NSH_HAVEMMCSD -static void k64_mediachange(void) -{ - bool inserted; - - /* Get the current value of the card detect pin. This pin is pulled up on - * board. So low means that a card is present. - */ - - inserted = !kinetis_gpioread(GPIO_SD_CARDDETECT); - - /* Has the pin changed state? */ - - if (inserted != g_nsh.inserted) - { - /* Yes.. perform the appropriate action (this might need some debounce). */ - - g_nsh.inserted = inserted; - sdhc_mediachange(g_nsh.sdhc, inserted); - - /* If the card has been inserted, then check if it is write protected - * as well. The pin is pulled up, but apparently logic high means - * write protected. - */ - - if (inserted) - { - sdhc_wrprotect(g_nsh.sdhc, kinetis_gpioread(GPIO_SD_WRPROTECT)); - } - } -} -#endif - -/**************************************************************************** - * Name: k64_cdinterrupt - ****************************************************************************/ - -#ifdef NSH_HAVEMMCSD -static int k64_cdinterrupt(int irq, FAR void *context) -{ - /* All of the work is done by k64_mediachange() */ - - k64_mediachange(); - return OK; -} -#endif - /**************************************************************************** * Public Functions ****************************************************************************/ -/************************************************************************************ +/**************************************************************************** * Name: k64_bringup * * Description: * Bring up board features * - ************************************************************************************/ + ****************************************************************************/ int k64_bringup(void) { @@ -165,52 +79,40 @@ int k64_bringup(void) } #endif -#ifdef NSH_HAVEMMCSD - /* Configure GPIO pins */ +#ifdef HAVE_MMCSD + /* Initialize the SDHC driver */ - /* Attached the card detect interrupt (but don't enable it yet) */ - - kinetis_pinconfig(GPIO_SD_CARDDETECT); - kinetis_pinirqattach(GPIO_SD_CARDDETECT, k64_cdinterrupt); - - /* Configure the write protect GPIO */ - - //kinetis_pinconfig(GPIO_SD_WRPROTECT); - - /* Mount the SDHC-based MMC/SD block driver */ - /* First, get an instance of the SDHC interface */ - - syslog(LOG_INFO, "Initializing SDHC slot %d\n", MMCSD_SLOTNO); - - g_nsh.sdhc = sdhc_initialize(MMCSD_SLOTNO); - if (!g_nsh.sdhc) + ret = k64_sdhc_initialize(0); + if (ret < 0) { - syslog(LOG_ERR, "ERROR: Failed to initialize SDHC slot %d\n", - MMCSD_SLOTNO); - return -ENODEV; + mcerr("ERROR: k64_sdhc_initialize(%d,%d) failed: %d\n", HSMCI0_SLOTNO, 0, ret); } - /* Now bind the SDHC interface to the MMC/SD driver */ - - syslog(LOG_INFO, "Bind SDHC to the MMC/SD driver, minor=%d\n", - CONFIG_NSH_MMCSDMINOR); - - ret = mmcsd_slotinitialize(CONFIG_NSH_MMCSDMINOR, g_nsh.sdhc); - if (ret != OK) +#ifdef CONFIG_FRDMK64F_SDHC_MOUNT + else { - syslog(LOG_ERR, "ERROR: Failed to bind SDHC to the MMC/SD driver: %d\n", ret); - return ret; + /* REVISIT: A delay seems to be required here or the mount will fail. */ + /* Mount the volume on HSMCI0 */ + + ret = mount(CONFIG_FRDMK64F_SDHC_MOUNT_BLKDEV, + CONFIG_FRDMK64F_SDHC_MOUNT_MOUNTPOINT, + CONFIG_FRDMK64F_SDHC_MOUNT_FSTYPE, + 0, NULL); + + if (ret < 0) + { + mcerr("ERROR: Failed to mount %s: %d\n", + CONFIG_FRDMK64F_SDHC_MOUNT_MOUNTPOINT, errno); + } } - syslog(LOG_INFO, "Successfully bound SDHC to the MMC/SD driver\n"); +#endif /* CONFIG_FRDMK64F_SDHC_MOUNT */ +#endif /* HAVE_MMCSD */ - /* Handle the initial card state */ +#ifdef HAVE_AUTOMOUNTER + /* Initialize the auto-mounter */ - k64_mediachange(); - - /* Enable CD interrupts to handle subsequent media changes */ - - kinetis_pinirqenable(GPIO_SD_CARDDETECT); + k64_automount_initialize(); #endif UNUSED(ret); diff --git a/configs/samv71-xult/src/sam_hsmci.c b/configs/samv71-xult/src/sam_hsmci.c index 85e66b048d5..2b4cb3295f8 100644 --- a/configs/samv71-xult/src/sam_hsmci.c +++ b/configs/samv71-xult/src/sam_hsmci.c @@ -129,7 +129,7 @@ bool sam_cardinserted_internal(struct sam_hsmci_state_s *state) /* Get the state of the PIO pin */ inserted = sam_gpioread(state->cdcfg); - finfo("Slot %d inserted: %s\n", state->slotno, inserted ? "NO" : "YES"); + mcinfo("Slot %d inserted: %s\n", state->slotno, inserted ? "NO" : "YES"); return !inserted; } @@ -221,12 +221,12 @@ int sam_hsmci_initialize(int slotno, int minor) struct sam_hsmci_state_s *state; int ret; - /* Get the static HSMI description */ + /* Get the static HSMCI description */ state = sam_hsmci_state(slotno); if (!state) { - ferr("ERROR: No state for slotno %d\n", slotno); + mcerr("ERROR: No state for slotno %d\n", slotno); return -EINVAL; } @@ -247,7 +247,7 @@ int sam_hsmci_initialize(int slotno, int minor) state->hsmci = sdio_initialize(slotno); if (!state->hsmci) { - ferr("ERROR: Failed to initialize SDIO slot %d\n", slotno); + mcerr("ERROR: Failed to initialize SDIO slot %d\n", slotno); return -ENODEV; } @@ -256,7 +256,7 @@ int sam_hsmci_initialize(int slotno, int minor) ret = mmcsd_slotinitialize(minor, state->hsmci); if (ret != OK) { - ferr("ERROR: Failed to bind SDIO to the MMC/SD driver: %d\n", ret); + mcerr("ERROR: Failed to bind SDIO to the MMC/SD driver: %d\n", ret); return ret; } @@ -293,7 +293,7 @@ bool sam_cardinserted(int slotno) state = sam_hsmci_state(slotno); if (!state) { - ferr("ERROR: No state for slotno %d\n", slotno); + mcerr("ERROR: No state for slotno %d\n", slotno); return false; }