Merged in masayuki2009/nuttx.nuttx/stm32f4dis-mmcsdspi (pull request #1053)

boards: stm32f4discovery: Add support for MMCSD_SPI

This PR works with STM32F4 Discovery Shield plus microSD click

Signed-off-by: Masayuki Ishikawa <Masayuki.Ishikawa@jp.sony.com>

Approved-by: Gregory Nutt <gnutt@nuttx.org>
This commit is contained in:
Masayuki Ishikawa 2019-10-18 02:38:16 +00:00 committed by Gregory Nutt
parent f063d7f386
commit c3b6a2892d
7 changed files with 263 additions and 1 deletions

View File

@ -0,0 +1,80 @@
#
# 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_FPU is not set
# CONFIG_MMCSD_HAVE_CARDDETECT is not set
# CONFIG_MMCSD_HAVE_WRITEPROTECT is not set
# CONFIG_NSH_ARGCAT is not set
# CONFIG_NSH_CMDOPT_HEXDUMP is not set
# CONFIG_NSH_CMDPARMS is not set
# CONFIG_SPI_CALLBACK is not set
# CONFIG_STM32_CCMEXCLUDE is not set
CONFIG_ARCH="arm"
CONFIG_ARCH_BOARD="stm32f4discovery"
CONFIG_ARCH_BOARD_STM32F4_DISCOVERY=y
CONFIG_ARCH_BUTTONS=y
CONFIG_ARCH_CHIP="stm32"
CONFIG_ARCH_CHIP_STM32=y
CONFIG_ARCH_CHIP_STM32F407VG=y
CONFIG_ARCH_STACKDUMP=y
CONFIG_BOARDCTL_RESET=y
CONFIG_BOARD_LOOPSPERMSEC=16717
CONFIG_BUILTIN=y
CONFIG_CODECS_HASH_MD5=y
CONFIG_DEBUG_FULLOPT=y
CONFIG_DEBUG_SYMBOLS=y
CONFIG_EXAMPLES_HELLO=y
CONFIG_FAT_LFN=y
CONFIG_FS_FAT=y
CONFIG_FS_FATTIME=y
CONFIG_FS_PROCFS=y
CONFIG_HAVE_CXX=y
CONFIG_HAVE_CXXINITIALIZE=y
CONFIG_HEAP_COLORATION=y
CONFIG_INTELHEX_BINARY=y
CONFIG_LIB_SENDFILE_BUFSIZE=1024
CONFIG_MAX_TASKS=16
CONFIG_MAX_WDOGPARMS=2
CONFIG_MMCSD=y
CONFIG_MM_REGIONS=2
CONFIG_NETUTILS_CODECS=y
CONFIG_NFILE_DESCRIPTORS=8
CONFIG_NFILE_STREAMS=8
CONFIG_NSH_ARCHINIT=y
CONFIG_NSH_BUILTIN_APPS=y
CONFIG_NSH_FILEIOSIZE=512
CONFIG_NSH_LINELEN=64
CONFIG_NSH_READLINE=y
CONFIG_PREALLOC_MQ_MSGS=4
CONFIG_PREALLOC_TIMERS=4
CONFIG_PREALLOC_WDOGS=16
CONFIG_RAM_SIZE=114688
CONFIG_RAM_START=0x20000000
CONFIG_RAW_BINARY=y
CONFIG_READLINE_CMD_HISTORY=y
CONFIG_RR_INTERVAL=200
CONFIG_SCHED_LPWORK=y
CONFIG_SCHED_LPWORKPRIORITY=30
CONFIG_SCHED_WAITPID=y
CONFIG_SDCLONE_DISABLE=y
CONFIG_STACK_COLORATION=y
CONFIG_START_DAY=17
CONFIG_START_MONTH=10
CONFIG_START_YEAR=2019
CONFIG_STM32_DMA1=y
CONFIG_STM32_DMA2=y
CONFIG_STM32_JTAG_SW_ENABLE=y
CONFIG_STM32_PWR=y
CONFIG_STM32_SPI2=y
CONFIG_STM32_USART2=y
CONFIG_SYSTEM_NSH=y
CONFIG_SYSTEM_NSH_CXXINITIALIZE=y
CONFIG_TESTING_OSTEST=y
CONFIG_USART2_RXBUFSIZE=128
CONFIG_USART2_SERIAL_CONSOLE=y
CONFIG_USART2_TXBUFSIZE=128
CONFIG_USER_ENTRYPOINT="nsh_main"

View File

@ -335,6 +335,11 @@
#define GPIO_SPI2_MOSI GPIO_SPI2_MOSI_1
#define GPIO_SPI2_SCK GPIO_SPI2_SCK_1
/* SPI2 DMA -- As used for MMC/SD SPI */
#define DMACHAN_SPI2_RX DMAMAP_SPI2_RX
#define DMACHAN_SPI2_TX DMAMAP_SPI2_TX
/* SPI3 DMA -- As used for I2S DMA transfer with the audio configuration */
#define GPIO_SPI3_MISO GPIO_SPI3_MISO_1
@ -395,6 +400,14 @@
#endif
#ifdef CONFIG_MMCSD_SPI
#define GPIO_MMCSD_NSS (GPIO_OUTPUT | GPIO_PUSHPULL | GPIO_SPEED_50MHz | \
GPIO_OUTPUT_SET | GPIO_PORTB | GPIO_PIN12)
#define GPIO_MMCSD_NCD (GPIO_INPUT | GPIO_FLOAT | GPIO_EXTI | \
GPIO_PORTC | GPIO_PIN1)
#endif
/* DMA Channl/Stream Selections *****************************************************/
/* Stream selections are arbitrary for now but might become important in the future

View File

@ -216,4 +216,8 @@ CSRCS += stm32_netinit.c
endif
endif
ifeq ($(CONFIG_MMCSD_SPI),y)
CSRCS += stm32_mmcsd.c
endif
include $(TOPDIR)/boards/Board.mk

View File

@ -233,6 +233,17 @@ int stm32_bringup(void)
}
#endif
#ifdef CONFIG_MMCSD_SPI
/* Initialize the MMC/SD SPI driver (SPI2 is used) */
ret = stm32_mmcsd_initialize(2, CONFIG_NSH_MMCSDMINOR);
if (ret < 0)
{
syslog(LOG_ERR, "Failed to initialize SD slot %d: %d\n",
CONFIG_NSH_MMCSDMINOR, ret);
}
#endif
#ifdef HAVE_USBHOST
/* Initialize USB host operation. stm32_usbhost_initialize() starts a
* thread will monitor for USB connection and disconnection events.

View File

@ -0,0 +1,126 @@
/*****************************************************************************
* boards/arm/stm32/stm32f4discovery/src/stm32_mmcsd.c
*
* Copyright 2019 Sony Home Entertainment & Sound Products Inc.
* Author: Masayuki Ishikawa <Masayuki.Ishikawa@jp.sony.com>
*
* Based on omnibusf4/src/stm32_mmcsd.c
* Copyright (C) 2019 Bill Gatliff. All rights reserved.
* Copyright (C) 2017 Greg Nutt. All rights reserved.
* Author: Bill Gatliff <bgat@billgatliff.com>
* Author: Alan Carvalho de Assis <acassis@gmail.com>
*
* 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.
****************************************************************************/
/*****************************************************************************
* Included Files
****************************************************************************/
#include <debug.h>
#include <nuttx/config.h>
#include <nuttx/mmcsd.h>
#include <nuttx/spi/spi.h>
#include <pthread.h>
#include <sched.h>
#include <semaphore.h>
#include <time.h>
#include <unistd.h>
#include "up_arch.h"
#include "chip.h"
#include "stm32.h"
#include <arch/board/board.h>
#include "stm32f4discovery.h"
/*****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#ifdef CONFIG_DISABLE_MOUNTPOINT
# error "SD driver requires CONFIG_DISABLE_MOUNTPOINT to be disabled"
#endif
/*****************************************************************************
* Public Functions
****************************************************************************/
/*****************************************************************************
* Name: stm32_spi1register
*
* Description:
* Registers media change callback
****************************************************************************/
int stm32_spi2register(struct spi_dev_s *dev, spi_mediachange_t callback,
void *arg)
{
/* TODO: media change callback */
return OK;
}
/*****************************************************************************
* Name: stm32_mmcsd_initialize
*
* Description:
* Initialize SPI-based SD card and card detect thread.
****************************************************************************/
int stm32_mmcsd_initialize(int port, int minor)
{
struct spi_dev_s *spi;
int rv;
stm32_configgpio(GPIO_MMCSD_NCD); /* Assign SD_DET */
stm32_configgpio(GPIO_SPI2_SCK_2); /* Assign PB13 as SPI2_SCK */
stm32_configgpio(GPIO_MMCSD_NSS); /* Assign CS */
stm32_gpiowrite(GPIO_MMCSD_NSS, 1); /* Ensure the CS is inactive */
mcinfo("INFO: Initializing mmcsd port %d minor %d \n",
port, minor);
spi = stm32_spibus_initialize(port);
if (spi == NULL)
{
mcerr("ERROR: Failed to initialize SPI port %d\n", port);
return -ENODEV;
}
rv = mmcsd_spislotinitialize(minor, minor, spi);
if (rv < 0)
{
mcerr("ERROR: Failed to bind SPI port %d to SD slot %d\n",
port, minor);
return rv;
}
spiinfo("INFO: mmcsd card has been initialized successfully\n");
return OK;
}

View File

@ -174,11 +174,27 @@ void stm32_spi2select(FAR struct spi_dev_s *dev, uint32_t devid, bool selected)
stm32_gpiowrite(GPIO_MAX6675_CS, !selected);
}
#endif
#if defined(CONFIG_MMCSD_SPI)
if (devid == SPIDEV_MMCSD(0))
{
stm32_gpiowrite(GPIO_MMCSD_NSS, !selected);
}
#endif
}
uint8_t stm32_spi2status(FAR struct spi_dev_s *dev, uint32_t devid)
{
return 0;
uint8_t ret = 0;
#if defined(CONFIG_MMCSD_SPI)
if (devid == SPIDEV_MMCSD(0))
{
/* Note: SD_DET is pulled high when there's no SD card present. */
ret = stm32_gpioread(GPIO_MMCSD_NCD) ? 0 : 1;
}
#endif
return ret;
}
#endif

View File

@ -474,6 +474,18 @@ int stm32_bmp180initialize(FAR const char *devpath);
int stm32_lis3dshinitialize(FAR const char *devpath);
#endif
/****************************************************************************
* Name: stm32_mmcsdinitialize
*
* Description:
* Sets up MMC/SD interface.
*
****************************************************************************/
#ifdef CONFIG_MMCSD_SPI
int stm32_mmcsd_initialize(int port, int minor);
#endif
/****************************************************************************
* Name: nunchuck_initialize
*