SAMD20: Changes for clean build of SPI driver and SAMD20 Xplained Pro board with the I/O1 module installed

This commit is contained in:
Gregory Nutt 2014-02-20 11:27:59 -06:00
parent 51b484adb8
commit d3a6ad82b4
9 changed files with 121 additions and 72 deletions

View File

@ -712,7 +712,14 @@ Configuration sub-directories
4. If the I/O1 module is connected to the SAMD20 Xplained Pro, then
support for the SD card slot can be enabled by making the following
changes to the configuration:
changes to the configuration. These changes assume that the I/O1
modules is connected in EXT1. Most of the modifications necessary
to work with the I/O1 in a different connector are obvious.. except
for the selection of SERCOM SPI support:
EXT1: SPI is provided through SERCOM0
EXT2: SPI is provided through SERCOM1
EXT3: SPI is provided through SERCOM5
File Systems:
CONFIG_FS_FAT=y : Enable the FAT file system
@ -725,7 +732,8 @@ Configuration sub-directories
details.
System Type -> Peripherals:
To be provided : Enable the SAMD20 SPI peripheral
CONFIG_SAMD_SERCOM0=y : Use SERCOM0 if the I/O is in EXT1
CONFIG_SAMD_SERCOM0_ISSPI=y : Configure SERCOM0 as an SPI master
Device Drivers
CONFIG_SPI=y : Enable SPI support
@ -735,6 +743,7 @@ Configuration sub-directories
CONFIG_MMCSD=y : Enable MMC/SD support
CONFIG_MMCSD_NSLOTS=1 : Only one MMC/SD card slot
CONFIG_MMCSD_MULTIBLOCK_DISABLE=n : Should not need to disable multi-block transfers
CONFIG_MMCSD_MMCSUPPORT=n : May interfere with some SD cards
CONFIG_MMCSD_HAVECARDDETECT=y : I/O1 module as a card detect GPIO
CONFIG_MMCSD_SPI=y : Use the SPI interface to the MMC/SD card
CONFIG_MMCSD_SPICLOCK=20000000 : This is a guess for the optimal MMC/SD frequency
@ -742,13 +751,11 @@ Configuration sub-directories
Board Selection -> Common Board Options
CONFIG_NSH_MMCSDSLOTNO=0 : Only one MMC/SD slot, slot 0
CONFIG_NSH_MMCSDSPIPORTNO=0 : Use CS=0 if the I/O1 is in EXT1, OR
CONFIG_NSH_MMCSDSPIPORTNO=2 : Use CS=2 if the I/O1 is in EXT2
CONFIG_NSH_MMCSDSPIPORTNO=0 : Use port=0 -> SERCOM0 if the I/O1 is in EXT1
Board Selection -> SAMD20 Xplained Pro Modules
CONFIG_SAMD20_XPLAINED_IOMODULE=y : I/O1 module is connected
CONFIG_SAMD20_XPLAINED_IOMODULE_EXT1=y : In EXT1, or EXT2
CONFIG_SAMD20_XPLAINED_IOMODULE_EXT2=y
CONFIG_SAMD20_XPLAINED_IOMODULE_EXT1=y : I/O1 modules is in EXT1
Application Configuration -> NSH Library
CONFIG_NSH_ARCHINIT=y : Board has architecture-specific initialization
@ -776,10 +783,18 @@ Configuration sub-directories
5. If the OLED1 module is connected to the SAMD20 Xplained Pro, then
support for the OLED display can be enabled by making the following
changes to the configuration:
changes to the configuration. These changes assume that the I/O1
modules is connected in EXT1. Most of the modifications necessary
to work with the I/O1 in a different connector are obvious.. except
for the selection of SERCOM SPI support:
EXT1: SPI is provided through SERCOM0
EXT2: SPI is provided through SERCOM1
EXT3: SPI is provided through SERCOM5
System Type -> Peripherals:
To be provided : Enable the SAMD20 SPI peripheral
CONFIG_SAMD_SERCOM1=y : Use SERCOM1 if the I/O is in EXT2
CONFIG_SAMD_SERCOM1_ISSPI=y : Configure SERCOM1 as an SPI master
Device Drivers -> SPI
CONFIG_SPI=y : Enable SPI support
@ -797,8 +812,7 @@ Configuration sub-directories
Board Selection -> SAMD20 Xplained Pro Modules
CONFIG_SAMD20_XPLAINED_OLED1MODULE=y : OLED1 module is connected
CONFIG_SAMD20_XPLAINED_OLED1MODULE_EXT1=y : In EXT1, or EXT2
CONFIG_SAMD20_XPLAINED_OLED1MODULE_EXT2=y
CONFIG_SAMD20_XPLAINED_OLED1MODULE_EXT2=y : OLED1 modules is in EXT2
The NX graphics subsystem also needs to be configured:
@ -868,3 +882,9 @@ Configuration sub-directories
appears at different BAUD settings implying that this may not even
be clock related???
- The program seems to be running normally, just producing bad output.
3. The configuration suggests CONFIG_MMCSD_HAVECARDDETECT=y, but as of
this writing, there is no support for EIC pin interrupts.
4. OLED1 module is untested. These intructions were just ported from
the SAM4L Xplained Pro README.txt file.

View File

@ -371,12 +371,14 @@
* 18 PA7 SERCOM0 PAD3 SPI SCK
*/
#define BOARD_SERCOM0_CLKGEN GCLK_CLKCTRL_GEN0
#define BOARD_SERCOM0_MUX_SETTING (SPI_CTRLA_DOPO_DOPAD231 | SPI_CTRLA_DIPAD0)
#define BOARD_SERCOM0_PINMUX_PAD0 PINMUX_PA04D_SERCOM0_PAD0 /* SPI_MISO */
#define BOARD_SERCOM0_PINMUX_PAD1 0 /* microSD_SS */
#define BOARD_SERCOM0_PINMUX_PAD2 PINMUX_PA06D_SERCOM0_PAD2 /* SPI_MOSI */
#define BOARD_SERCOM0_PINMUX_PAD3 PINMUX_PA07D_SERCOM0_PAD3 /* SPI_SCK */
#define BOARD_SERCOM0_GCLKGEN GCLK_CLKCTRL_GEN0
#define BOARD_SERCOM0_MUXCONFIG (SPI_CTRLA_DOPO_DOPAD231 | SPI_CTRLA_DIPAD0)
#define BOARD_SERCOM0_PINMAP_PAD0 PORT_SERCOM0_PAD0_2 /* SPI_MISO */
#define BOARD_SERCOM0_PINMAP_PAD1 0 /* microSD_SS */
#define BOARD_SERCOM0_PINMAP_PAD2 PORT_SERCOM0_PAD2_2 /* SPI_MOSI */
#define BOARD_SERCOM0_PINMAP_PAD3 PORT_SERCOM0_PAD3_2 /* SPI_SCK */
#define BOARD_SERCOM0_FREQUENCY BOARD_GCLK0_FREQUENCY
/* SERCOM1 SPI is available on EXT2
*
@ -388,12 +390,14 @@
* 18 PA19 SERCOM1 PAD3 SPI SCK
*/
#define BOARD_SERCOM1_CLKGEN GCLK_CLKCTRL_GEN0
#define BOARD_SERCOM1_MUX_SETTING (SPI_CTRLA_DOPO_DOPAD231 | SPI_CTRLA_DIPAD0)
#define BOARD_SERCOM1_PINMUX_PAD0 PINMUX_PA16C_SERCOM1_PAD0 /* SPI_MISO */
#define BOARD_SERCOM1_PINMUX_PAD1 0 /* microSD_SS */
#define BOARD_SERCOM1_PINMUX_PAD2 PINMUX_PA18C_SERCOM1_PAD2 /* SPI_MOSI */
#define BOARD_SERCOM1_PINMUX_PAD3 PINMUX_PA19C_SERCOM1_PAD3 /* SPI_SCK */
#define BOARD_SERCOM1_GCLKGEN GCLK_CLKCTRL_GEN0
#define BOARD_SERCOM1_MUXCONFIG (SPI_CTRLA_DOPO_DOPAD231 | SPI_CTRLA_DIPAD0)
#define BOARD_SERCOM1_PINMAP_PAD0 PORT_SERCOM1_PAD0_1 /* SPI_MISO */
#define BOARD_SERCOM1_PINMAP_PAD1 0 /* microSD_SS */
#define BOARD_SERCOM1_PINMAP_PAD2 PORT_SERCOM1_PAD2_1 /* SPI_MOSI */
#define BOARD_SERCOM1_PINMAP_PAD3 PORT_SERCOM1_PAD3_1 /* SPI_SCK */
#define BOARD_SERCOM1_FREQUENCY BOARD_GCLK0_FREQUENCY
/* The SAMD20 Xplained Pro contains an Embedded Debugger (EDBG) that can be
* used to program and debug the ATSAMD20J18A using Serial Wire Debug (SWD).
@ -462,12 +466,14 @@
* 18 PB23 SERCOM5 PAD3 SPI SCK
*/
#define BOARD_SERCOM5_CLKGEN GCLK_CLKCTRL_GEN0
#define BOARD_SERCOM5_MUX_SETTING (SPI_CTRLA_DOPO_DOPAD231 | SPI_CTRLA_DIPAD0)
#define BOARD_SERCOM5_PINMUX_PAD0 PINMUX_PB16C_SERCOM5_PAD0 /* SPI_MISO */
#define BOARD_SERCOM5_PINMUX_PAD1 0 /* microSD_SS */
#define BOARD_SERCOM5_PINMUX_PAD2 PINMUX_PB22D_SERCOM5_PAD2 /* SPI_MOSI */
#define BOARD_SERCOM5_PINMUX_PAD3 PINMUX_PB23D_SERCOM5_PAD3 /* SPI_SCK */
#define BOARD_SERCOM5_GCLKGEN GCLK_CLKCTRL_GEN0
#define BOARD_SERCOM5_MUXCONFIG (SPI_CTRLA_DOPO_DOPAD231 | SPI_CTRLA_DIPAD0)
#define BOARD_SERCOM5_PINMAP_PAD0 PORT_SERCOM5_PAD0_1 /* SPI_MISO */
#define BOARD_SERCOM5_PINMAP_PAD1 0 /* microSD_SS */
#define BOARD_SERCOM5_PINMAP_PAD2 PORT_SERCOM5_PAD2_4 /* SPI_MOSI */
#define BOARD_SERCOM5_PINMAP_PAD3 PORT_SERCOM5_PAD3_4 /* SPI_SCK */
#define BOARD_SERCOM5_FREQUENCY BOARD_GCLK0_FREQUENCY
/* LED definitions ******************************************************************/
/* There are three LEDs on board the SAMD20 Xplained Pro board: The EDBG

View File

@ -64,19 +64,15 @@ ifeq ($(CONFIG_NSH_ARCHINIT),y)
CSRCS += sam_nsh.c
endif
ifeq ($(CONFIG_SAMD_SERCOM0),y)
ifeq ($(CONFIG_SAM4L_XPLAINED_IOMODULE),y)
ifeq ($(CONFIG_SAMD20_XPLAINED_IOMODULE),y)
CSRCS += sam_mmcsd.c
endif
endif
ifeq ($(CONFIG_SAMD_SERCOM0),y)
ifeq ($(CONFIG_SAM4L_XPLAINED_OLED1MODULE),y)
ifeq ($(CONFIG_SAMD20_XPLAINED_OLED1MODULE),y)
ifeq ($(CONFIG_LCD_UG2832HSWEG04),y)
CSRCS += sam_ug2832hsweg04.c
endif
endif
endif
COBJS = $(CSRCS:.c=$(OBJEXT))

View File

@ -72,7 +72,7 @@ void sam_boardinitialize(void)
* sam_spiinitialize() has been brought into the link.
*/
#ifdef SAMD_HAVE_SPI0
#ifdef SAMD_HAVE_SPI
if (sam_spiinitialize)
{
sam_spiinitialize();

View File

@ -49,7 +49,7 @@
#include "sam_config.h"
#include "samd20-xplained.h"
#ifdef CONFIG_SAM4L_XPLAINED_IOMODULE
#ifdef CONFIG_SAMD20_XPLAINED_IOMODULE
/****************************************************************************
* Pre-Processor Definitions
@ -79,48 +79,47 @@
*
* Description:
* Initialize the SPI-based SD card. Requires
* - CONFIG_SAM4L_XPLAINED_IOMODULE=y,
* - CONFIG_SAMD20_XPLAINED_IOMODULE=y,
* - CONFIG_DISABLE_MOUNTPOINT=n,
* - CONFIG_MMCSD=y, and
* - SAMD_HAVE_SPI0=y (CONFIG_SAMD_SERCOM0 && CONFIG_SAMD_SERCOM0_ISSPI)
*
*****************************************************************************/
int sam_sdinitialize(int minor)
int sam_sdinitialize(int port, int minor)
{
FAR struct spi_dev_s *spi;
int ret;
/* Get the SPI driver instance for the SD chip select */
fvdbg("Initializing SPI chip select %d\n", SD_CSNO);
fvdbg("Initializing SERCOM SPI%d\n", port);
spi = up_spiinitialize(SD_CSNO);
spi = up_spiinitialize(port);
if (!spi)
{
fdbg("Failed to initialize SPI chip select %d\n", SD_CSNO);
fdbg("Failed to initialize SPI%d\n", port);
return -ENODEV;
}
fvdbg("Successfully initialized SPI chip select %d\n", SD_CSNO);
fvdbg("Successfully initialized SPI%d\n", port);
/* Bind the SPI device for the chip select to the slot */
fvdbg("Binding SPI chip select %d to MMC/SD slot %d\n",
SD_CSNO, SAMD_MMCSDSLOTNO);
fvdbg("Binding SPI%d to MMC/SD slot %d\n", port, SAMD_MMCSDSLOTNO);
ret = mmcsd_spislotinitialize(minor, SAMD_MMCSDSLOTNO, spi);
if (ret < 0)
{
fdbg("Failed to bind SPI chip select %d to MMC/SD slot %d: %d\n",
SD_CSNO, SAMD_MMCSDSLOTNO, ret);
fdbg("Failed to bind SPI%d to MMC/SD slot %d: %d\n",
port, SAMD_MMCSDSLOTNO, ret);
return ret;
}
fvdbg("Successfuly bound SPI chip select %d to MMC/SD slot %d\n",
SD_CSNO, SAMD_MMCSDSLOTNO);
fvdbg("Successfuly bound SPI%d to MMC/SD slot %d\n",
port, SAMD_MMCSDSLOTNO);
return OK;
}
#endif /* CONFIG_SAM4L_XPLAINED_IOMODULE */
#endif /* CONFIG_SAMD20_XPLAINED_IOMODULE */

View File

@ -48,8 +48,25 @@
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
/* Some configuration checks */
#ifdef CONFIG_SAM4L_XPLAINED_IOMODULE
#ifdef CONFIG_SAMD20_XPLAINED_IOMODULE_EXT1
# ifndef SAMD_HAVE_SPI0
# error I/O1 module on EXT1 requires SERCOM SPI0
# undef CONFIG_SAMD20_XPLAINED_IOMODULE
# endif
# define SPI_PORTNO 0
#endif
#ifdef CONFIG_SAMD20_XPLAINED_IOMODULE_EXT2
# ifndef SAMD_HAVE_SPI1
# error I/O1 module on EXT2 requires SERCOM SPI1
# undef CONFIG_SAMD20_XPLAINED_IOMODULE
# endif
# define SPI_PORTNO 1
#endif
#ifdef CONFIG_SAMD20_XPLAINED_IOMODULE
/* Support for the SD card slot on the I/O1 module */
/* Verify NSH PORT and SLOT settings */
@ -57,10 +74,14 @@
# if defined(CONFIG_NSH_MMCSDSLOTNO) && CONFIG_NSH_MMCSDSLOTNO != SAMD_MMCSDSLOTNO
# error Only one MMC/SD slot: Slot 0 (CONFIG_NSH_MMCSDSLOTNO)
# undef CONFIG_NSH_MMCSDSLOTNO
# define CONFIG_NSH_MMCSDSLOTNO SAMD_MMCSDSLOTNO
# endif
# if defined(CONFIG_NSH_MMCSDSPIPORTNO) && CONFIG_NSH_MMCSDSPIPORTNO != SD_CSNO
# error CONFIG_NSH_MMCSDSPIPORTNO must have the same value as SD_CSNO
# if defined(CONFIG_NSH_MMCSDSPIPORTNO) && CONFIG_NSH_MMCSDSPIPORTNO != SPI_PORTNO
# error CONFIG_NSH_MMCSDSPIPORTNO must have the same value as SPI_PORTNO
# undef CONFIG_NSH_MMCSDSPIPORTNO
# define CONFIG_NSH_MMCSDSPIPORTNO SPI_PORTNO
# endif
/* Default MMC/SD minor number */
@ -100,11 +121,11 @@
int nsh_archinitialize(void)
{
#if defined(SAMD_HAVE_SPI0) && defined(CONFIG_SAM4L_XPLAINED_IOMODULE)
#if defined(SAMD_HAVE_SPI0) && defined(CONFIG_SAMD20_XPLAINED_IOMODULE)
/* Initialize the SPI-based MMC/SD slot */
{
int ret = sam_sdinitialize(CONFIG_NSH_MMCSDMINOR);
int ret = sam_sdinitialize(SPI_PORTNO, CONFIG_NSH_MMCSDMINOR);
if (ret < 0)
{
message("nsh_archinitialize: Failed to initialize MMC/SD slot: %d\n",

View File

@ -58,8 +58,8 @@
****************************************************************************/
/* Configuration ************************************************************/
#if defined(CONFIG_SAM4L_XPLAINED_IOMODULE) && \
defined(CONFIG_SAM4L_XPLAINED_OLED1MODULE) && defined(CONFIG_SPI_OWNBUS)
#if defined(CONFIG_SAMD20_XPLAINED_IOMODULE) && \
defined(CONFIG_SAMD20_XPLAINED_OLED1MODULE) && defined(CONFIG_SPI_OWNBUS)
# error CONFIG_SPI_OWNBUS must not defined if using both I/O1 and OLED1 modules
#endif
@ -104,14 +104,14 @@ void weak_function sam_spiinitialize(void)
* it is installed, it may be in connector EXT1 or EXT2.
*/
#ifdef CONFIG_SAM4L_XPLAINED_IOMODULE
#ifdef CONFIG_SAMD20_XPLAINED_IOMODULE
/* TODO: enable interrupt on card detect */
sam_configport(PORT_SD_CD); /* Card detect input */
sam_configport(PORT_SD_CS); /* Chip select output */
#endif
#ifdef CONFIG_SAM4L_XPLAINED_OLED1MODULE
#ifdef CONFIG_SAMD20_XPLAINED_OLED1MODULE
sam_configport(PORT_OLED_DATA); /* Command/data */
sam_configport(PORT_OLED_CS); /* Card detect input */
#endif
@ -180,7 +180,8 @@ void weak_function sam_spiinitialize(void)
****************************************************************************/
#ifdef SAMD_HAVE_SPI0
void sam_spi0select(enum spi_dev_e devid, bool selected)
void sam_spi0select(FAR struct spi_dev_s *dev, enum spi_dev_e devid,
bool selected)
{
#ifdef CONFIG_SAMD20_XPLAINED_IOMODULE_EXT1
/* Select/de-select the SD card */
@ -207,7 +208,8 @@ void sam_spi0select(enum spi_dev_e devid, bool selected)
#endif
#ifdef SAMD_HAVE_SPI1
void sam_spi1select(enum spi_dev_e devid, bool selected)
void sam_spi1select(FAR struct spi_dev_s *dev, enum spi_dev_e devid,
bool selected)
{
#ifdef CONFIG_SAMD20_XPLAINED_IOMODULE_EXT2
/* Select/de-select the SD card */
@ -234,25 +236,29 @@ void sam_spi1select(enum spi_dev_e devid, bool selected)
#endif
#ifdef SAMD_HAVE_SPI2
void sam_spi2select(enum spi_dev_e devid, bool selected)
void sam_spi2select(FAR struct spi_dev_s *dev, enum spi_dev_e devid,
bool selected)
{
}
#endif
#ifdef SAMD_HAVE_SPI3
void sam_spi3select(enum spi_dev_e devid, bool selected)
void sam_spi3select(FAR struct spi_dev_s *dev, enum spi_dev_e devid,
bool selected)
{
}
#endif
#ifdef SAMD_HAVE_SPI4
void sam_spi4select(enum spi_dev_e devid, bool selected)
void sam_spi4select(FAR struct spi_dev_s *dev, enum spi_dev_e devid,
bool selected)
{
}
#endif
#ifdef SAMD_HAVE_SPI5
void sam_spi5select(enum spi_dev_e devid, bool selected)
void sam_spi5select(FAR struct spi_dev_s *dev, enum spi_dev_e devid,
bool selected)
{
}
#endif

View File

@ -117,7 +117,7 @@
#include "sam_port.h"
#include "samd20-xplained.h"
#ifdef CONFIG_SAM4L_XPLAINED_OLED1MODULE
#ifdef CONFIG_SAMD20_XPLAINED_OLED1MODULE
/****************************************************************************
* Pre-Processor Definitions
@ -208,4 +208,4 @@ FAR struct lcd_dev_s *up_nxdrvinit(unsigned int devno)
return NULL;
}
#endif /* CONFIG_SAM4L_XPLAINED_OLED1MODULE */
#endif /* CONFIG_SAMD20_XPLAINED_OLED1MODULE */

View File

@ -127,7 +127,7 @@
# endif
# define PORT_SD_CD (PORT_INTERRUPT | PORT_INT_CHANGE | PORT_PULL_UP | \
PORTF | PORT_PIN5)
PORTB | PORT_PIN5)
# define PORT_SD_CS (PORT_OUTPUT | PORT_PULL_NONE | PORT_OUTPUT_SET | \
PORTA | PORT_PIN5)
@ -139,8 +139,8 @@
# error I/O1 and OLED1 modules cannot both reside in EXT2
# endif
# define PORT_CD (PORT_INTERRUPT | PORT_INT_CHANGE | PORT_PULL_UP | \
PORTB | PORT_PIN15)
# define PORT_SD_CD (PORT_INTERRUPT | PORT_INT_CHANGE | PORT_PULL_UP | \
PORTB | PORT_PIN15)
# define PORT_SD_CS (PORT_OUTPUT | PORT_PULL_NONE | PORT_OUTPUT_SET | \
PORTA | PORT_PIN17)
@ -250,12 +250,13 @@ void weak_function sam_spiinitialize(void);
*
* Description:
* Initialize the SPI-based SD card. Requires CONFIG_SAMD20_XPLAINED_IOMODULE=y,
* CONFIG_DISABLE_MOUNTPOINT=n, CONFIG_MMCSD=y, and SAMD_HAVE_SPI0
* CONFIG_DISABLE_MOUNTPOINT=n, CONFIG_MMCSD=y, and the appropriate SERCOM SPI
* port enabled.
*
************************************************************************************/
#if defined(SAMD_HAVE_SPI0) && defined(CONFIG_SAMD20_XPLAINED_IOMODULE)
int sam_sdinitialize(int minor);
#ifdef CONFIG_SAMD20_XPLAINED_IOMODULE
int sam_sdinitialize(int port, int minor);
#endif
/************************************************************************************