You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by ag...@apache.org on 2020/05/15 22:11:44 UTC
[incubator-nuttx] 01/07: boards/arm/stm32h7/stm32h747i-disco: bring
support for SDMMC
This is an automated email from the ASF dual-hosted git repository.
aguettouche pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
commit 369293dd840127c55061340c76d1fa83233c7818
Author: Pierre-Olivier Vauboin <po...@lambdaconcept.com>
AuthorDate: Tue Mar 31 17:35:20 2020 +0200
boards/arm/stm32h7/stm32h747i-disco: bring support for SDMMC
---
arch/arm/src/stm32h7/hardware/stm32_sdmmc.h | 2 +
boards/arm/stm32h7/stm32h747i-disco/src/Makefile | 4 +
.../stm32h7/stm32h747i-disco/src/stm32_bringup.c | 10 ++
.../src/{stm32h747i-disco.h => stm32_sdmmc.c} | 185 ++++++++++++---------
.../stm32h747i-disco/src/stm32h747i-disco.h | 25 +++
5 files changed, 144 insertions(+), 82 deletions(-)
diff --git a/arch/arm/src/stm32h7/hardware/stm32_sdmmc.h b/arch/arm/src/stm32h7/hardware/stm32_sdmmc.h
index 752b226..5f56274 100644
--- a/arch/arm/src/stm32h7/hardware/stm32_sdmmc.h
+++ b/arch/arm/src/stm32h7/hardware/stm32_sdmmc.h
@@ -47,6 +47,8 @@
#if defined(CONFIG_STM32H7_STM32H7X3XX)
# include "stm32h7x3xx_sdmmc.h"
+#elif defined(CONFIG_STM32H7_STM32H7X7XX)
+# include "stm32h7x3xx_sdmmc.h"
#else
# error "Unsupported STM32 H7 part"
#endif
diff --git a/boards/arm/stm32h7/stm32h747i-disco/src/Makefile b/boards/arm/stm32h7/stm32h747i-disco/src/Makefile
index d82ebb1..9518e4f 100644
--- a/boards/arm/stm32h7/stm32h747i-disco/src/Makefile
+++ b/boards/arm/stm32h7/stm32h747i-disco/src/Makefile
@@ -68,4 +68,8 @@ ifeq ($(CONFIG_LIB_BOARDCTL),y)
CSRCS += stm32_appinitialize.c
endif
+ifeq ($(CONFIG_STM32H7_SDMMC), y)
+CSRCS += stm32_sdmmc.c
+endif
+
include $(TOPDIR)/boards/Board.mk
diff --git a/boards/arm/stm32h7/stm32h747i-disco/src/stm32_bringup.c b/boards/arm/stm32h7/stm32h747i-disco/src/stm32_bringup.c
index 80ae17a..28c1939 100644
--- a/boards/arm/stm32h7/stm32h747i-disco/src/stm32_bringup.c
+++ b/boards/arm/stm32h7/stm32h747i-disco/src/stm32_bringup.c
@@ -215,5 +215,15 @@ int stm32_bringup(void)
}
#endif /* CONFIG_ADC */
+#ifdef HAVE_SDIO
+ /* Initialize the SDIO block driver */
+
+ ret = stm32_sdio_initialize();
+ if (ret < 0)
+ {
+ syslog(LOG_ERR, "ERROR: Failed to initialize MMC/SD driver: %d\n", ret);
+ }
+#endif
+
return OK;
}
diff --git a/boards/arm/stm32h7/stm32h747i-disco/src/stm32h747i-disco.h b/boards/arm/stm32h7/stm32h747i-disco/src/stm32_sdmmc.c
similarity index 51%
copy from boards/arm/stm32h7/stm32h747i-disco/src/stm32h747i-disco.h
copy to boards/arm/stm32h7/stm32h747i-disco/src/stm32_sdmmc.c
index 7bc2e30..6546d69 100644
--- a/boards/arm/stm32h7/stm32h747i-disco/src/stm32h747i-disco.h
+++ b/boards/arm/stm32h7/stm32h747i-disco/src/stm32_sdmmc.c
@@ -1,9 +1,8 @@
/****************************************************************************
- * boards/arm/stm32h7/stm32h747i-disco/src/stm32h747i-disco.h
+ * boards/arm/stm32h7/stm32h747i-disco/src/stm32_sdmmc.c
*
-# Copyright (C) 2017, 2019 Gwenhael Goavec-Merou. All rights reserved.
-# Authors: Gwenhael Goavec-Merou<gw...@trabucayre.com>
- * David Sidrane <da...@nscdg.com>
+ * Copyright (C) 2016-2019 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <gn...@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -34,17 +33,23 @@
*
****************************************************************************/
-#ifndef __BOARDS_ARM_STM32H7_STM32H747I_DISCO_SRC_STM32H747I_DISCO_H
-#define __BOARDS_ARM_STM32H7_STM32H747I_DISCO_SRC_STM32H747I_DISCO_H
-
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
-#include <nuttx/compiler.h>
-#include <stdint.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <debug.h>
+#include <errno.h>
+
+#include <nuttx/sdio.h>
+#include <nuttx/mmcsd.h>
+
+#include "stm32_gpio.h"
+#include "stm32_sdmmc.h"
+#include "stm32h747i-disco.h"
/****************************************************************************
* Pre-processor Definitions
@@ -52,103 +57,119 @@
/* Configuration ************************************************************/
-/* procfs File System */
+/* Card detections requires card support and a card detection GPIO */
-#ifdef CONFIG_FS_PROCFS
-# ifdef CONFIG_NSH_PROC_MOUNTPOINT
-# define STM32_PROCFS_MOUNTPOINT CONFIG_NSH_PROC_MOUNTPOINT
-# else
-# define STM32_PROCFS_MOUNTPOINT "/proc"
-# endif
+#define HAVE_NCD 1
+#if !defined(HAVE_SDIO) || !defined(GPIO_SDIO_NCD)
+# undef HAVE_NCD
#endif
-/* Check if we can support the RTC driver */
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
-#define HAVE_RTC_DRIVER 1
-#if !defined(CONFIG_RTC) || !defined(CONFIG_RTC_DRIVER)
-# undef HAVE_RTC_DRIVER
+static FAR struct sdio_dev_s *g_sdio_dev;
+#ifdef HAVE_NCD
+static bool g_sd_inserted = 0xff; /* Impossible value */
#endif
-/* LED
- *
- * LD1 Green PI12
- * LD2 Orange PI13
- * LD3 Red PI14
- * LD4 Blue PI15
- */
-
-#define GPIO_LD1 (GPIO_OUTPUT | GPIO_PUSHPULL | GPIO_SPEED_50MHz | GPIO_OUTPUT_SET | \
- GPIO_PORTI | GPIO_PIN12)
-#define GPIO_LD2 (GPIO_OUTPUT | GPIO_PUSHPULL | GPIO_SPEED_50MHz | GPIO_OUTPUT_SET | \
- GPIO_PORTI | GPIO_PIN13)
-#define GPIO_LD3 (GPIO_OUTPUT | GPIO_PUSHPULL | GPIO_SPEED_50MHz | GPIO_OUTPUT_SET | \
- GPIO_PORTI | GPIO_PIN14)
-#define GPIO_LD4 (GPIO_OUTPUT | GPIO_PUSHPULL | GPIO_SPEED_50MHz | GPIO_OUTPUT_SET | \
- GPIO_PORTI | GPIO_PIN15)
-
-#define GPIO_LED_GREEN GPIO_LD1
-#define GPIO_LED_ORANGE GPIO_LD2
-#define GPIO_LED_RED GPIO_LD3
-#define GPIO_LED_BLUE GPIO_LD4
-
-#define LED_DRIVER_PATH "/dev/userleds"
-
-/* BUTTONS
- *
- * The Blue pushbutton B1, labeled "Wakeup", is connected to GPIO PC13. A
- * high value will be sensed when the button is depressed.
- *
- * Notes:
- * 1) That the EXTI is included in the definition to enable an interrupt
- * on this IO.
- * 2) The following definitions assume the default Solder Bridges are
- * installed.
- */
-
-#define GPIO_BTN_USER (GPIO_INPUT | GPIO_FLOAT | GPIO_EXTI | GPIO_PORTC | GPIO_PIN13)
-
/****************************************************************************
- * Public Functions
+ * Private Functions
****************************************************************************/
/****************************************************************************
- * Name: stm32_bringup
+ * Name: stm32_ncd_interrupt
*
* Description:
- * Perform architecture-specific initialization
- *
- * CONFIG_BOARD_LATE_INITIALIZE=y :
- * Called from board_late_initialize().
- *
- * CONFIG_BOARD_LATE_INITIALIZE=y && CONFIG_LIB_BOARDCTL=y :
- * Called from the NSH library
+ * Card detect interrupt handler.
*
****************************************************************************/
-int stm32_bringup(void);
+#ifdef HAVE_NCD
+static int stm32_ncd_interrupt(int irq, FAR void *context, FAR void *param)
+{
+ bool present;
-/****************************************************************************
- * Name: stm32_spidev_initialize
- *
- * Description:
- * Called to configure SPI chip select GPIO pins for the board.
- *
- ****************************************************************************/
+ present = !stm32_gpioread(GPIO_SDIO_NCD);
+ if (present != g_sd_inserted)
+ {
+ sdio_mediachange(g_sdio_dev, present);
+ g_sd_inserted = present;
+ }
-#ifdef CONFIG_STM32H7_SPI
-void stm32_spidev_initialize(void);
+ return OK;
+}
#endif
/****************************************************************************
- * Name: stm32_adc_setup
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: stm32_sdio_initialize
*
* Description:
- * Initialize ADC and register the ADC driver.
+ * Initialize SDIO-based MMC/SD card support
*
****************************************************************************/
-#ifdef CONFIG_ADC
-int stm32_adc_setup(void);
+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 */
+
+ (void)stm32_gpiosetevent(GPIO_SDIO_NCD, true, true, true,
+ stm32_ncd_interrupt, NULL);
+#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
-#endif /* __BOARDS_ARM_STM32H7_STM32H747I_DISCO_SRC_STM32H747I_DISCO_H */
+ return OK;
+}
diff --git a/boards/arm/stm32h7/stm32h747i-disco/src/stm32h747i-disco.h b/boards/arm/stm32h7/stm32h747i-disco/src/stm32h747i-disco.h
index 7bc2e30..a5c43ad7 100644
--- a/boards/arm/stm32h7/stm32h747i-disco/src/stm32h747i-disco.h
+++ b/boards/arm/stm32h7/stm32h747i-disco/src/stm32h747i-disco.h
@@ -107,6 +107,19 @@
#define GPIO_BTN_USER (GPIO_INPUT | GPIO_FLOAT | GPIO_EXTI | GPIO_PORTC | GPIO_PIN13)
+/* SD/TF Card'detected pin */
+
+#if defined(CONFIG_STM32H7_SDMMC1)
+# define HAVE_SDIO
+#endif
+
+#if defined(CONFIG_DISABLE_MOUNTPOINT) || !defined(CONFIG_MMCSD_SDIO)
+# undef HAVE_SDIO
+#endif
+
+#define SDIO_SLOTNO 0
+#define SDIO_MINOR 0
+
/****************************************************************************
* Public Functions
****************************************************************************/
@@ -151,4 +164,16 @@ void stm32_spidev_initialize(void);
int stm32_adc_setup(void);
#endif
+/****************************************************************************
+ * Name: stm32_sdio_initialize
+ *
+ * Description:
+ * Initialize SDIO-based MMC/SD card support
+ *
+ ****************************************************************************/
+
+#ifdef HAVE_SDIO
+int stm32_sdio_initialize(void);
+#endif
+
#endif /* __BOARDS_ARM_STM32H7_STM32H747I_DISCO_SRC_STM32H747I_DISCO_H */