This is an automated email from the ASF dual-hosted git repository. xiaoxiang pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push: new accfb3609b7 boards/sama5d3-xplained: Fix mmc card detection. accfb3609b7 is described below commit accfb3609b72baf42dc7ed572c5a0a258bb23677 Author: Lwazi Dube <lwa...@gmail.com> AuthorDate: Fri May 16 11:04:59 2025 -0400 boards/sama5d3-xplained: Fix mmc card detection. Use the pins specified in the SAMA5D3 Xplained User Guide. Rename config macros from SAMA5D4EK to SAMA5D3XPLAINED. Add SDMMC support to defconfig. Boot mount is disabled by default. --- boards/arm/sama5/sama5d3-xplained/Kconfig | 29 ++++++++++ .../sama5/sama5d3-xplained/configs/nsh/defconfig | 6 ++ .../sama5/sama5d3-xplained/include/boot_romfsimg.h | 37 ++++++++++++ .../arm/sama5/sama5d3-xplained/src/sam_appinit.c | 9 +-- boards/arm/sama5/sama5d3-xplained/src/sam_boot.c | 6 +- .../arm/sama5/sama5d3-xplained/src/sam_bringup.c | 66 ++++++++++------------ .../sama5/sama5d3-xplained/src/sama5d3-xplained.h | 22 ++++---- 7 files changed, 118 insertions(+), 57 deletions(-) diff --git a/boards/arm/sama5/sama5d3-xplained/Kconfig b/boards/arm/sama5/sama5d3-xplained/Kconfig index cf8baeb97e4..506223386ae 100644 --- a/boards/arm/sama5/sama5d3-xplained/Kconfig +++ b/boards/arm/sama5/sama5d3-xplained/Kconfig @@ -110,6 +110,35 @@ config SAMA5D3XPLAINED_AT25_NXFFS endchoice # AT25 serial FLASH configuration +config SAMA5D3XPLAINED_HSMCI0_MOUNT + bool "HSMCI0 boot mount" + default n + depends on SAMA5_HSMCI0 + +if SAMA5D3XPLAINED_HSMCI0_MOUNT + +config SAMA5D3XPLAINED_HSMCI0_MOUNT_FSTYPE + string "HSMCI0 file system type" + default "vfat" + +config SAMA5D3XPLAINED_HSMCI0_MOUNT_BLKDEV + string "HSMCI0 block device" + default "/dev/mmcsd0" + +config SAMA5D3XPLAINED_HSMCI0_MOUNT_MOUNTPOINT + string "HSMCI0 mount point" + default "/bin" + +endif # SAMA5D3XPLAINED_HSMCI0_MOUNT + +config SAMA5D3XPLAINED_ROMFS_ROMDISK_MINOR + int "ROM disk minor device number" + default 0 + +config SAMA5D3XPLAINED_ROMFS_ROMDISK_SECTSIZE + int "ROM disk sector size" + default 512 + config SAMA5D3XPLAINED_USBHOST_STACKSIZE int "USB host waiter stack size" default 1536 if USBHOST_HUB diff --git a/boards/arm/sama5/sama5d3-xplained/configs/nsh/defconfig b/boards/arm/sama5/sama5d3-xplained/configs/nsh/defconfig index 0682bf110af..2b72e0dfd54 100644 --- a/boards/arm/sama5/sama5d3-xplained/configs/nsh/defconfig +++ b/boards/arm/sama5/sama5d3-xplained/configs/nsh/defconfig @@ -18,6 +18,7 @@ CONFIG_ARCH_CHIP_SAMA5D3=y CONFIG_ARCH_INTERRUPTSTACK=2048 CONFIG_ARCH_LOWVECTORS=y CONFIG_ARCH_STACKDUMP=y +CONFIG_BOARD_LATE_INITIALIZE=y CONFIG_BOARD_LOOPSPERMSEC=65775 CONFIG_BOOT_RUNFROMSDRAM=y CONFIG_BUILTIN=y @@ -44,7 +45,12 @@ CONFIG_SAMA5_BOOT_SDRAM=y CONFIG_SAMA5_DBGU=y CONFIG_SAMA5_DBGU_CONSOLE=y CONFIG_SAMA5_DBGU_NOCONFIG=y +CONFIG_SAMA5_DMAC0=y CONFIG_SAMA5_HSMC=y +CONFIG_SAMA5_HSMCI0=y +CONFIG_SAMA5_PIOE_IRQ=y +CONFIG_SAMA5_PIO_IRQ=y +CONFIG_SAMA5_SDMMC=y CONFIG_SCHED_WAITPID=y CONFIG_START_DAY=31 CONFIG_START_MONTH=7 diff --git a/boards/arm/sama5/sama5d3-xplained/include/boot_romfsimg.h b/boards/arm/sama5/sama5d3-xplained/include/boot_romfsimg.h new file mode 100644 index 00000000000..b6d4fe5f9fd --- /dev/null +++ b/boards/arm/sama5/sama5d3-xplained/include/boot_romfsimg.h @@ -0,0 +1,37 @@ +/**************************************************************************** + * boards/arm/sama5/sama5d3-xplained/include/boot_romfsimg.h + * + * SPDX-License-Identifier: Apache-2.0 + * + * 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. + * + ****************************************************************************/ + +#ifndef __BOARDS_ARM_SAMA5_SAMA5D3_XPLAINED_BOOT_ROMFSIMG_H +#define __BOARDS_ARM_SAMA5_SAMA5D3_XPLAINED_BOOT_ROMFSIMG_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/compiler.h> +const unsigned char aligned_data(4) romfs_img[] = +{ + 0x00 +}; +unsigned int romfs_img_len = 1; + +#endif /* __BOARDS_ARM_SAMA5_SAMA5D3_XPLAINED_BOOT_ROMFSIMG_H */ diff --git a/boards/arm/sama5/sama5d3-xplained/src/sam_appinit.c b/boards/arm/sama5/sama5d3-xplained/src/sam_appinit.c index 267bc11a71b..4339b5f01c5 100644 --- a/boards/arm/sama5/sama5d3-xplained/src/sam_appinit.c +++ b/boards/arm/sama5/sama5d3-xplained/src/sam_appinit.c @@ -50,6 +50,8 @@ * Perform application specific initialization. This function is never * called directly from application code, but only indirectly via the * (non-standard) boardctl() interface using the command BOARDIOC_INIT. + * This function is also called by board_late_initialize if + * CONFIG_BOARD_LATE_INITIALIZE is defined. * * Input Parameters: * arg - The boardctl() argument is passed to the board_app_initialize() @@ -70,14 +72,7 @@ int board_app_initialize(uintptr_t arg) { - int ret; - - UNUSED(ret); -#ifndef CONFIG_BOARD_LATE_INITIALIZE /* Perform board initialization */ return sam_bringup(); -#else - return OK; -#endif } diff --git a/boards/arm/sama5/sama5d3-xplained/src/sam_boot.c b/boards/arm/sama5/sama5d3-xplained/src/sam_boot.c index c8fd5f6481c..7b1e8a4072d 100644 --- a/boards/arm/sama5/sama5d3-xplained/src/sam_boot.c +++ b/boards/arm/sama5/sama5d3-xplained/src/sam_boot.c @@ -90,7 +90,7 @@ void sam_boardinitialize(void) /* Initialize USB if the 1) the HS host or device controller is in the * configuration and 2) the weak function sam_usbinitialize() has been * brought into the build. - * Presumeably either CONFIG_USBDEV or CONFIG_USBHOST is also selected. + * Presumably either CONFIG_USBDEV or CONFIG_USBHOST is also selected. */ #if defined(CONFIG_SAMA5_UHPHS) || defined(CONFIG_SAMA5_UDPHS) @@ -139,8 +139,10 @@ void board_late_initialize(void) * This alternative NSH initialization is necessary when NSH is ran in * user-space but the initialization function must run in kernel space. */ +#if defined(CONFIG_NSH_ARCHINIT) +# error Both BOARD_LATE_INITIALIZE and NSH_ARCHINIT enabled +#elif defined(CONFIG_NSH_LIBRARY) -#if defined(CONFIG_NSH_LIBRARY) && !defined(CONFIG_BOARDCTL) board_app_initialize(0); #endif } diff --git a/boards/arm/sama5/sama5d3-xplained/src/sam_bringup.c b/boards/arm/sama5/sama5d3-xplained/src/sam_bringup.c index 3d1b51e1d5a..a5b95c755dc 100644 --- a/boards/arm/sama5/sama5d3-xplained/src/sam_bringup.c +++ b/boards/arm/sama5/sama5d3-xplained/src/sam_bringup.c @@ -33,6 +33,8 @@ #include <errno.h> #include <debug.h> +#include <nuttx/signal.h> + #include <nuttx/fs/fs.h> #ifdef CONFIG_USBMONITOR @@ -45,7 +47,7 @@ #include "sam_twi.h" #include "sama5d3-xplained.h" -#ifdef HAVE_ROMFS +#if defined(CONFIG_FS_ROMFS) && defined(CONFIG_INIT_MOUNT) # include <arch/board/boot_romfsimg.h> #endif @@ -59,8 +61,8 @@ ****************************************************************************/ #define NSECTORS(n) \ - (((n)+CONFIG_SAMA5D4EK_ROMFS_ROMDISK_SECTSIZE-1) / \ - CONFIG_SAMA5D4EK_ROMFS_ROMDISK_SECTSIZE) + (((n)+CONFIG_SAMA5D3XPLAINED_ROMFS_ROMDISK_SECTSIZE-1) / \ + CONFIG_SAMA5D3XPLAINED_ROMFS_ROMDISK_SECTSIZE) /**************************************************************************** * Private Functions @@ -156,24 +158,28 @@ int sam_bringup(void) HSMCI0_SLOTNO, HSMCI0_MINOR, ret); } -#ifdef CONFIG_SAMA5D4EK_HSMCI0_MOUNT - else +#ifdef CONFIG_SAMA5D3XPLAINED_HSMCI0_MOUNT + else if (sam_cardinserted(0)) { - /* REVISIT: - * A delay seems to be required here or the mount will fail. - */ + ret = 1; + for (int retry = 0; ret != 0 && retry < 3; ++retry) + { + /* Wait for mmc block driver to be registered. */ - /* Mount the volume on HSMCI0 */ + nxsig_sleep(1); - ret = nx_mount(CONFIG_SAMA5D4EK_HSMCI0_MOUNT_BLKDEV, - CONFIG_SAMA5D4EK_HSMCI0_MOUNT_MOUNTPOINT, - CONFIG_SAMA5D4EK_HSMCI0_MOUNT_FSTYPE, - 0, NULL); + /* Mount the volume on HSMCI0 */ + + ret = nx_mount(CONFIG_SAMA5D3XPLAINED_HSMCI0_MOUNT_BLKDEV, + CONFIG_SAMA5D3XPLAINED_HSMCI0_MOUNT_MOUNTPOINT, + CONFIG_SAMA5D3XPLAINED_HSMCI0_MOUNT_FSTYPE, + 0, NULL); + } if (ret < 0) { _err("ERROR: Failed to mount %s: %d\n", - CONFIG_SAMA5D4EK_HSMCI0_MOUNT_MOUNTPOINT, ret); + CONFIG_SAMA5D3XPLAINED_HSMCI0_MOUNT_MOUNTPOINT, ret); } } #endif @@ -189,22 +195,22 @@ int sam_bringup(void) HSMCI1_SLOTNO, HSMCI1_MINOR, ret); } -#ifdef CONFIG_SAMA5D4EK_HSMCI1_MOUNT +#ifdef CONFIG_SAMA5D3XPLAINED_HSMCI1_MOUNT else { /* REVISIT: A delay seems to be required here or the mount will fail */ /* Mount the volume on HSMCI1 */ - ret = nx_mount(CONFIG_SAMA5D4EK_HSMCI1_MOUNT_BLKDEV, - CONFIG_SAMA5D4EK_HSMCI1_MOUNT_MOUNTPOINT, - CONFIG_SAMA5D4EK_HSMCI1_MOUNT_FSTYPE, + ret = nx_mount(CONFIG_SAMA5D3XPLAINED_HSMCI1_MOUNT_BLKDEV, + CONFIG_SAMA5D3XPLAINED_HSMCI1_MOUNT_MOUNTPOINT, + CONFIG_SAMA5D3XPLAINED_HSMCI1_MOUNT_FSTYPE, 0, NULL); if (ret < 0) { _err("ERROR: Failed to mount %s: %d\n", - CONFIG_SAMA5D4EK_HSMCI1_MOUNT_MOUNTPOINT, ret); + CONFIG_SAMA5D3XPLAINED_HSMCI1_MOUNT_MOUNTPOINT, ret); } } #endif @@ -217,30 +223,16 @@ int sam_bringup(void) sam_automount_initialize(); #endif -#ifdef HAVE_ROMFS +#if defined(CONFIG_FS_ROMFS) && defined(CONFIG_INIT_MOUNT) /* Create a ROM disk for the /etc filesystem */ - ret = romdisk_register(CONFIG_SAMA5D4EK_ROMFS_ROMDISK_MINOR, romfs_img, - NSECTORS(romfs_img_len), - CONFIG_SAMA5D4EK_ROMFS_ROMDISK_SECTSIZE); + ret = romdisk_register(CONFIG_SAMA5D3XPLAINED_ROMFS_ROMDISK_MINOR, + romfs_img, NSECTORS(romfs_img_len), + CONFIG_SAMA5D3XPLAINED_ROMFS_ROMDISK_SECTSIZE); if (ret < 0) { _err("ERROR: romdisk_register failed: %d\n", -ret); } - else - { - /* Mount the file system */ - - ret = nx_mount(CONFIG_SAMA5D4EK_ROMFS_ROMDISK_DEVNAME, - CONFIG_SAMA5D4EK_ROMFS_MOUNT_MOUNTPOINT, - "romfs", MS_RDONLY, NULL); - if (ret < 0) - { - _err("ERROR: nx_mount(%s,%s,romfs) failed: %d\n", - CONFIG_SAMA5D4EK_ROMFS_ROMDISK_DEVNAME, - CONFIG_SAMA5D4EK_ROMFS_MOUNT_MOUNTPOINT, ret); - } - } #endif #ifdef HAVE_USBHOST diff --git a/boards/arm/sama5/sama5d3-xplained/src/sama5d3-xplained.h b/boards/arm/sama5/sama5d3-xplained/src/sama5d3-xplained.h index 8b949c8b72b..d23b58ca502 100644 --- a/boards/arm/sama5/sama5d3-xplained/src/sama5d3-xplained.h +++ b/boards/arm/sama5/sama5d3-xplained/src/sama5d3-xplained.h @@ -66,10 +66,10 @@ # undef HAVE_HSMCI #endif -/* We need PIO interrupts on PIOD to support card detect interrupts */ +/* We need PIO interrupts on PIOE to support card detect interrupts */ -#if defined(HAVE_HSMCI) && !defined(CONFIG_SAMA5_PIOD_IRQ) -# warning PIOD interrupts not enabled. No MMC/SD support. +#if defined(HAVE_HSMCI) && !defined(CONFIG_SAMA5_PIOE_IRQ) +# warning PIOE interrupts not enabled. No MMC/SD support. # undef HAVE_HSMCI #endif @@ -311,12 +311,12 @@ * (2) a microSD memory card slot (J11). * * The full size SD card slot connects via HSMCI0. The card detect discrete - * is available on PD17 (pulled high). The write protect discrete is tied to + * is available on PE0 (pulled high). The write protect discrete is tied to * ground (via PP6) and not available to software. The slot supports 8-bit * wide transfer mode, but the NuttX driver currently uses only the 4-bit * wide transfer mode * - * PD17 MCI0_CD + * PE0 MCI0_CD * PD1 MCI0_DA0 * PD2 MCI0_DA1 * PD3 MCI0_DA2 @@ -330,13 +330,13 @@ */ #define PIO_MCI0_CD (PIO_INPUT | PIO_CFG_DEFAULT | PIO_CFG_DEGLITCH | \ - PIO_INT_BOTHEDGES | PIO_PORT_PIOD | PIO_PIN17) -#define IRQ_MCI0_CD SAM_IRQ_PD17 + PIO_INT_BOTHEDGES | PIO_PORT_PIOE | PIO_PIN0) +#define IRQ_MCI0_CD SAM_IRQ_PE0 /* The microSD connects vi HSMCI1. The card detect discrete is available on - * PBD8 (pulled high): + * PE1 (pulled high): * - * PD18 MCI1_CD + * PE1 MCI1_CD * PB20 MCI1_DA0 * PB21 MCI1_DA1 * PB22 MCI1_DA2 @@ -346,8 +346,8 @@ */ #define PIO_MCI1_CD (PIO_INPUT | PIO_CFG_DEFAULT | PIO_CFG_DEGLITCH | \ - PIO_INT_BOTHEDGES | PIO_PORT_PIOD | PIO_PIN18) -#define IRQ_MCI1_CD SAM_IRQ_PD18 + PIO_INT_BOTHEDGES | PIO_PORT_PIOE | PIO_PIN1) +#define IRQ_MCI1_CD SAM_IRQ_PE1 /* USB Ports ****************************************************************/