configs/max32660-evsys: Added support for an SPI-based micro-SD card. Does not yet work (SPI hangs with no data transferred).
This commit is contained in:
parent
86a67fa3e8
commit
67f196fcf8
@ -441,8 +441,8 @@ static int spi_poll(struct max326_spidev_s *priv)
|
||||
uint32_t length;
|
||||
uint32_t regval;
|
||||
uint32_t tmp;
|
||||
unsigned int txavail;
|
||||
unsigned int rxavail;
|
||||
int txavail;
|
||||
int rxavail;
|
||||
int remaining;
|
||||
|
||||
/* Get the transfer size in units of bytes */
|
||||
@ -477,7 +477,7 @@ static int spi_poll(struct max326_spidev_s *priv)
|
||||
/* Write Tx buffer data to the FIFO */
|
||||
|
||||
src = &((const uint8_t *)priv->txbuffer)[priv->txbytes];
|
||||
while (txavail)
|
||||
while (txavail > 0)
|
||||
{
|
||||
dest = (uint8_t *)(priv->base + MAX326_SPI_DATA_OFFSET);
|
||||
|
||||
@ -558,7 +558,7 @@ static int spi_poll(struct max326_spidev_s *priv)
|
||||
/* Read data from the Rx FIFO */
|
||||
|
||||
src = (const uint8_t *)(priv->base + MAX326_SPI_DATA_OFFSET);
|
||||
while (rxavail)
|
||||
while (rxavail > 0)
|
||||
{
|
||||
if (rxavail > 3)
|
||||
{
|
||||
@ -1123,7 +1123,7 @@ static void spi_exchange(struct spi_dev_s *dev, const void *txbuffer, void *rxbu
|
||||
|
||||
spiinfo("txbuffer=%p rxbuffer=%p nwords=%d\n", txbuffer, rxbuffer, nwords);
|
||||
DEBUGASSERT(priv != NULL && nwords > 0 && nwords <= UINT16_MAX);
|
||||
DEBUGASSERT(txbuffer != NULL || txbuffer != NULL);
|
||||
DEBUGASSERT(txbuffer != NULL || rxbuffer != NULL);
|
||||
|
||||
/* Setup for the transfer */
|
||||
|
||||
|
@ -55,6 +55,11 @@ Status
|
||||
now appears fully functional. Removed EXPERIMENTAL from configuration.
|
||||
Brought in the STM32 SPI driver as a starting point. It still does
|
||||
not build correctly. Due to conflicts, only SPI0 will be available.
|
||||
2018-11-30: Completed coding of the SPI driver. Added board support
|
||||
for SPI and for and SPI-based micro-SD card. Initial testing with no
|
||||
device attached shows that the first single byte SPI transfer hangs
|
||||
with 1 byte in the Tx FIFO and nothing in the Rx FIFO. Data is not
|
||||
moving.
|
||||
|
||||
Serial Console
|
||||
==============
|
||||
|
@ -58,4 +58,8 @@ ifeq ($(CONFIG_MAX326XX_HAVE_SPIM),y)
|
||||
CSRCS += max326_spi.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_MMCSD_SPI),y)
|
||||
CSRCS += max326_mmcsd.c
|
||||
endif
|
||||
|
||||
include $(TOPDIR)/configs/Board.mk
|
||||
|
@ -50,14 +50,55 @@
|
||||
* High illuminates, initial output is Low.
|
||||
*/
|
||||
|
||||
#define GPIO_LED (GPIO_OUTPUT | GPIO_VALUE_ZERO | GPIO_PORT0 | GPIO_PIN13)
|
||||
#define GPIO_LED (GPIO_OUTPUT | GPIO_VALUE_ZERO | GPIO_PORT0 | GPIO_PIN13)
|
||||
|
||||
/* An single button is available on GPIO P0.12 for use by software.
|
||||
* Interrupts are available on both edges.
|
||||
*/
|
||||
|
||||
#define GPIO_BUTTON (GPIO_INTBOTH | GPIO_PORT0 | GPIO_PIN12)
|
||||
#define BUTTON_IRQ MAX326_IRQ_P0_12
|
||||
#define GPIO_BUTTON (GPIO_INTBOTH | GPIO_PORT0 | GPIO_PIN12)
|
||||
#define BUTTON_IRQ MAX326_IRQ_P0_12
|
||||
|
||||
/* SPI0: No alternative pin configurations:
|
||||
*
|
||||
* PORT0 PIN SPI FUNCTION ALT FUNCTION COMMENT
|
||||
* ------ ---- ------------ ------------ ----------------------------
|
||||
* P0.4 5 MISO ALT1
|
||||
* P0.5 6 MOSI ALT1
|
||||
* P0.6 8 SCK ALT1
|
||||
* P0.7 10 SS0 ALT1
|
||||
*
|
||||
* I have connected a Sparkfun microSD breakout board via SPI0 using the
|
||||
* SPI0 SS pin (P0.7) as a GPIO push-pull output. We would like to pick
|
||||
* a pin for a card detect input the will not conflict with other
|
||||
* selections. The CS pin needs a pull-up resistor so that also limits
|
||||
* the options (P0.0-1, P0.4-7, and P0.10-13). Nothing is available:
|
||||
*
|
||||
* PIN HAS PULL_UP CONFLICTS
|
||||
* ----- ----------- ------------------
|
||||
* P0.0 Y JTAG/SWD
|
||||
* P0.1 Y JTAG/SWD
|
||||
* P0.2 N I2C1
|
||||
* P0.3 N I2C1
|
||||
* P0.4 Y SPI0/UART0
|
||||
* P0.5 Y SPI0/UART0
|
||||
* P0.6 Y SPI0/UART0
|
||||
* P0.7 Y SPI0/UART0
|
||||
* P0.8 N I2C0/UART0
|
||||
* P0.9 N I2C0
|
||||
* P0.10 Y UART1 (serial console)
|
||||
* P0.11 Y UART1 (serial console)
|
||||
* P0.12 Y Button
|
||||
* P0.13 Y LED
|
||||
*
|
||||
* For now, we must either (1) configure with no card detect (2) add an
|
||||
* external pull-up to P0.2, P0.3, P0.8, or P0.9 (and don't use
|
||||
* corresponding I2C), or (3) get creative with pins associated with JTAG,
|
||||
* LEDs or Buttons.
|
||||
*/
|
||||
|
||||
#define MICROSD_CS (GPIO_OUTPUT | GPIO_VALUE_ONE | GPIO_PORT0 | GPIO_PIN7)
|
||||
#undef MICROSD_CD
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
@ -95,4 +136,16 @@ int max326_bringup(void);
|
||||
void max326_spidev_initialize(void);
|
||||
#endif
|
||||
|
||||
/*****************************************************************************
|
||||
* Name: max326_mmcsd_initialize
|
||||
*
|
||||
* Description:
|
||||
* Initialize SPI-based SD card and card detect thread.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_MMCSD_SPI
|
||||
int max326_mmcsd_initialize(int minor);
|
||||
#endif
|
||||
|
||||
#endif /* __CONFIG_NUCLEO_F303ZE_INCLUDE_BOARD_H */
|
||||
|
@ -45,6 +45,18 @@
|
||||
|
||||
#include "max32660-evsys.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* Checking needed by MMC/SDCard */
|
||||
|
||||
#ifdef CONFIG_NSH_MMCSDMINOR
|
||||
# define MMCSD_MINOR CONFIG_NSH_MMCSDMINOR
|
||||
#else
|
||||
# define MMCSD_MINOR 0
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
@ -81,6 +93,14 @@ int max326_bringup(void)
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_MMCSD_SPI
|
||||
ret = max326_mmcsd_initialize(MMCSD_MINOR);
|
||||
if (ret < 0)
|
||||
{
|
||||
syslog(LOG_ERR, "Failed to initialize SD slot %d: %d\n", ret);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* If we got here then perhaps not all initialization was successful, but
|
||||
* at least enough succeeded to bring-up NSH with perhaps reduced
|
||||
* capabilities.
|
||||
|
151
configs/max32660-evsys/src/max326_mmcsd.c
Normal file
151
configs/max32660-evsys/src/max326_mmcsd.c
Normal file
@ -0,0 +1,151 @@
|
||||
/*****************************************************************************
|
||||
* configs/max32660-evsys/src/max326_mmcsd.c
|
||||
*
|
||||
* Copyright (C) 2018 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* 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 <nuttx/config.h>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <sched.h>
|
||||
#include <semaphore.h>
|
||||
#include <time.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <nuttx/mmcsd.h>
|
||||
#include <nuttx/spi/spi.h>
|
||||
|
||||
#include "max326_spim.h"
|
||||
|
||||
#ifdef CONFIG_MMCSD_SPI
|
||||
|
||||
/*****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef CONFIG_MAX326XX_HAVE_SPIM
|
||||
# error "SD driver requires SPI master mode support"
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_DISABLE_MOUNTPOINT
|
||||
# error "SD driver requires CONFIG_DISABLE_MOUNTPOINT to be disabled"
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_MAX326XX_SPIM0)
|
||||
# define MMCSD_PORT 0
|
||||
#elif defined(CONFIG_MAX326XX_SPIM1)
|
||||
# define MMCSD_PORT 1
|
||||
#endif
|
||||
|
||||
#define MMCSD_SLOT 0
|
||||
|
||||
/*****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef MICROSD_CD
|
||||
/* NOTE: We are using a SDCard adapter/module without Card Detect pin!
|
||||
* Then we don't need to Card Detect callback here.
|
||||
*/
|
||||
|
||||
#ifdef CONFIG_MMCSD_HAVE_CARDDETECT
|
||||
# error "No card detect pin"
|
||||
#endif
|
||||
#else
|
||||
# error "Missing card detect logic"
|
||||
#endif
|
||||
|
||||
/*****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/*****************************************************************************
|
||||
* Name: max326_spiregister
|
||||
*
|
||||
* Description:
|
||||
* Media change callback
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_SPI_CALLBACK
|
||||
#if defined(CONFIG_MAX326XX_SPIM0)
|
||||
int max326_spi0register(struct spi_dev_s *dev, spi_mediachange_t callback,
|
||||
void *arg)
|
||||
#elif defined(CONFIG_MAX326XX_SPIM1)
|
||||
int max326_spi1register(struct spi_dev_s *dev, spi_mediachange_t callback,
|
||||
void *arg)
|
||||
#endif
|
||||
{
|
||||
spiinfo("INFO: SPI callback\n");
|
||||
return OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*****************************************************************************
|
||||
* Name: max326_mmcsd_initialize
|
||||
*
|
||||
* Description:
|
||||
* Initialize SPI-based SD card and card detect thread.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int max326_mmcsd_initialize(int minor)
|
||||
{
|
||||
struct spi_dev_s *spi;
|
||||
int rv;
|
||||
|
||||
mcinfo("INFO: Initializing mmcsd card\n");
|
||||
|
||||
spi = max326_spibus_initialize(MMCSD_PORT);
|
||||
if (spi == NULL)
|
||||
{
|
||||
mcerr("ERROR: Failed to initialize SPI port %d\n", MMCSD_PORT);
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
rv = mmcsd_spislotinitialize(minor, MMCSD_SLOT, spi);
|
||||
if (rv < 0)
|
||||
{
|
||||
mcerr("ERROR: Failed to bind SPI port %d to SD slot %d\n",
|
||||
MMCSD_PORT, MMCSD_SLOT);
|
||||
return rv;
|
||||
}
|
||||
|
||||
spiinfo("INFO: mmcsd card has been initialized successfully\n");
|
||||
return OK;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_MMCSD_SPI */
|
Loading…
Reference in New Issue
Block a user