2019-08-19 15:16:08 +00:00
|
|
|
/****************************************************************************
|
|
|
|
* boards/arm/stm32/olimexino-stm32/src/stm32_usbmsc.c
|
2015-03-20 18:00:10 -06:00
|
|
|
*
|
2021-03-20 20:13:13 +01:00
|
|
|
* 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
|
2015-03-20 18:00:10 -06:00
|
|
|
*
|
2021-03-20 20:13:13 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2015-03-20 18:00:10 -06:00
|
|
|
*
|
2021-03-20 20:13:13 +01:00
|
|
|
* 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.
|
2015-03-20 18:00:10 -06:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <syslog.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
2016-03-25 12:09:37 -06:00
|
|
|
#include <nuttx/board.h>
|
2015-03-20 18:00:10 -06:00
|
|
|
#include <nuttx/mmcsd.h>
|
2016-03-25 12:09:37 -06:00
|
|
|
#include <nuttx/spi/spi.h>
|
2015-03-20 18:00:10 -06:00
|
|
|
|
|
|
|
#include "stm32.h"
|
|
|
|
#include "olimexino-stm32.h"
|
|
|
|
|
|
|
|
/* There is nothing to do here if SPI support is not selected. */
|
|
|
|
|
|
|
|
#ifdef CONFIG_STM32_SPI
|
|
|
|
|
|
|
|
/****************************************************************************
|
2015-04-08 09:15:17 -06:00
|
|
|
* Pre-processor Definitions
|
2015-03-20 18:00:10 -06:00
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/* Configuration ************************************************************/
|
|
|
|
|
|
|
|
#ifndef CONFIG_SYSTEM_USBMSC_DEVMINOR1
|
|
|
|
# define CONFIG_SYSTEM_USBMSC_DEVMINOR1 0
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* SLOT number(s) could depend on the board configuration */
|
|
|
|
|
|
|
|
#ifdef CONFIG_ARCH_BOARD_OLIMEXINO_STM32
|
|
|
|
# undef OLIMEXINO_STM32_MMCSDSLOTNO
|
|
|
|
# define OLIMEXINO_STM32_MMCSDSLOTNO 0
|
|
|
|
# undef OLIMEXINO_STM32_MMCSDSPIPORTNO
|
|
|
|
# define OLIMEXINO_STM32_MMCSDSPIPORTNO 2
|
|
|
|
#else
|
2021-03-21 15:41:45 +01:00
|
|
|
/* Add configuration for new STM32 boards here */
|
|
|
|
|
2015-03-20 18:00:10 -06:00
|
|
|
# error "Unrecognized STM32 board"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
2016-03-25 12:09:37 -06:00
|
|
|
* Name: board_usbmsc_initialize
|
2015-03-20 18:00:10 -06:00
|
|
|
*
|
|
|
|
* Description:
|
2016-03-25 12:09:37 -06:00
|
|
|
* Perform architecture specific initialization of the USB MSC device.
|
2015-03-20 18:00:10 -06:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2016-03-25 12:09:37 -06:00
|
|
|
int board_usbmsc_initialize(int port)
|
2015-03-20 18:00:10 -06:00
|
|
|
{
|
|
|
|
/* If system/usbmsc is built as an NSH command, then SD slot should
|
2021-03-21 15:41:45 +01:00
|
|
|
* already have been initialized in board_app_initialize()
|
|
|
|
* (see stm32_appinit.c).
|
2015-03-20 18:00:10 -06:00
|
|
|
* In this case, there is nothing further to be done here.
|
|
|
|
*/
|
|
|
|
|
2022-04-17 14:01:48 +08:00
|
|
|
struct spi_dev_s *spi;
|
2015-03-20 18:00:10 -06:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* First, get an instance of the SPI interface */
|
|
|
|
|
|
|
|
syslog(LOG_INFO, "Initializing SPI port %d\n",
|
|
|
|
OLIMEXINO_STM32_MMCSDSPIPORTNO);
|
|
|
|
|
2016-01-26 12:21:39 -06:00
|
|
|
spi = stm32_spibus_initialize(OLIMEXINO_STM32_MMCSDSPIPORTNO);
|
2015-03-20 18:00:10 -06:00
|
|
|
if (!spi)
|
|
|
|
{
|
|
|
|
syslog(LOG_ERR, "ERROR: Failed to initialize SPI port %d\n",
|
|
|
|
OLIMEXINO_STM32_MMCSDSPIPORTNO);
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
syslog(LOG_INFO, "Successfully initialized SPI port %d\n",
|
|
|
|
OLIMEXINO_STM32_MMCSDSPIPORTNO);
|
|
|
|
|
|
|
|
/* Now bind the SPI interface to the MMC/SD driver */
|
|
|
|
|
|
|
|
syslog(LOG_INFO, "Bind SPI to the MMC/SD driver, minor=%d slot=%d\n",
|
|
|
|
CONFIG_SYSTEM_USBMSC_DEVMINOR1, OLIMEXINO_STM32_MMCSDSLOTNO);
|
|
|
|
|
|
|
|
ret = mmcsd_spislotinitialize(CONFIG_SYSTEM_USBMSC_DEVMINOR1,
|
|
|
|
OLIMEXINO_STM32_MMCSDSLOTNO, spi);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
syslog(LOG_ERR,
|
2021-03-21 15:41:45 +01:00
|
|
|
"ERROR: Failed to bind SPI port %d to MMC/SD minor=%d slot=%d %d\n",
|
|
|
|
OLIMEXINO_STM32_MMCSDSPIPORTNO, CONFIG_SYSTEM_USBMSC_DEVMINOR1,
|
|
|
|
OLIMEXINO_STM32_MMCSDSLOTNO, ret);
|
2015-03-20 18:00:10 -06:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
syslog(LOG_INFO, "Successfully bound SPI to the MMC/SD driver\n");
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* CONFIG_STM32_SPI */
|