diff --git a/configs/README.txt b/configs/README.txt index 36c422f466..5443eb75e3 100644 --- a/configs/README.txt +++ b/configs/README.txt @@ -287,6 +287,7 @@ defconfig -- This is a configuration file similar to the Linux Read/Write CONFIG_MMCSD_SPICLOCK - Maximum SPI clock to drive MMC/SD card. Default is 20MHz. + CONFIG_MMCSD_SYNCHRONIZE - Special synchronization logic needed TCP/IP and UDP support via uIP CONFIG_NET - Enable or disable all network features diff --git a/configs/eagle100/httpd/defconfig b/configs/eagle100/httpd/defconfig index 8f410917db..9c42f6583d 100644 --- a/configs/eagle100/httpd/defconfig +++ b/configs/eagle100/httpd/defconfig @@ -359,10 +359,13 @@ CONFIG_FS_ROMFS=n # Provide read-only access (default is read/write) # CONFIG_MMCSD_SPICLOCK - Maximum SPI clock to drive MMC/SD card. # Default is 20MHz. +# CONFIG_MMCSD_SYNCHRONIZE +# Special synchronization logic needed # CONFIG_MMCSD_NSLOTS=1 CONFIG_MMCSD_READONLY=n CONFIG_MMCSD_SPICLOCK=12500000 +CONFIG_MMCSD_SYNCHRONIZE=n # # TCP/IP and UDP support via uIP diff --git a/configs/eagle100/nettest/defconfig b/configs/eagle100/nettest/defconfig index 96d82f693d..8b501a9d14 100644 --- a/configs/eagle100/nettest/defconfig +++ b/configs/eagle100/nettest/defconfig @@ -359,10 +359,13 @@ CONFIG_FS_ROMFS=n # Provide read-only access (default is read/write) # CONFIG_MMCSD_SPICLOCK - Maximum SPI clock to drive MMC/SD card. # Default is 20MHz. +# CONFIG_MMCSD_SYNCHRONIZE +# Special synchronization logic needed # CONFIG_MMCSD_NSLOTS=1 CONFIG_MMCSD_READONLY=n CONFIG_MMCSD_SPICLOCK=12500000 +CONFIG_MMCSD_SYNCHRONIZE=n # # TCP/IP and UDP support via uIP diff --git a/configs/eagle100/nsh/defconfig b/configs/eagle100/nsh/defconfig index cbd62632f1..6bd803948b 100644 --- a/configs/eagle100/nsh/defconfig +++ b/configs/eagle100/nsh/defconfig @@ -358,10 +358,13 @@ CONFIG_FS_ROMFS=n # Provide read-only access (default is read/write) # CONFIG_MMCSD_SPICLOCK - Maximum SPI clock to drive MMC/SD card. # Default is 20MHz. +# CONFIG_MMCSD_SYNCHRONIZE +# Special synchronization logic needed # CONFIG_MMCSD_NSLOTS=1 CONFIG_MMCSD_READONLY=n CONFIG_MMCSD_SPICLOCK=12500000 +CONFIG_MMCSD_SYNCHRONIZE=n # # TCP/IP and UDP support via uIP diff --git a/configs/eagle100/ostest/defconfig b/configs/eagle100/ostest/defconfig index 0667030544..2abbbb648f 100644 --- a/configs/eagle100/ostest/defconfig +++ b/configs/eagle100/ostest/defconfig @@ -358,10 +358,13 @@ CONFIG_FS_ROMFS=n # Provide read-only access (default is read/write) # CONFIG_MMCSD_SPICLOCK - Maximum SPI clock to drive MMC/SD card. # Default is 20MHz. +# CONFIG_MMCSD_SYNCHRONIZE +# Special synchronization logic needed # CONFIG_MMCSD_NSLOTS=1 CONFIG_MMCSD_READONLY=n CONFIG_MMCSD_SPICLOCK=12500000 +CONFIG_MMCSD_SYNCHRONIZE=n # # TCP/IP and UDP support via uIP diff --git a/configs/mcu123-lpc214x/nsh/defconfig b/configs/mcu123-lpc214x/nsh/defconfig index 36a939f455..fd55a8f22b 100644 --- a/configs/mcu123-lpc214x/nsh/defconfig +++ b/configs/mcu123-lpc214x/nsh/defconfig @@ -301,9 +301,21 @@ CONFIG_FS_FAT=y CONFIG_FS_ROMFS=n # -# MMC/SD configuration +# SPI-based MMC/SD driver +# +# CONFIG_MMCSD_NSLOTS +# Number of MMC/SD slots supported by the driver +# CONFIG_MMCSD_READONLY +# Provide read-only access (default is read/write) +# CONFIG_MMCSD_SPICLOCK - Maximum SPI clock to drive MMC/SD card. +# Default is 20MHz. +# CONFIG_MMCSD_SYNCHRONIZE +# Special synchronization logic needed +# CONFIG_MMCSD_NSLOTS=1 CONFIG_MMCSD_READONLY=n +#CONFIG_MMCSD_SPICLOCK=20000000 +CONFIG_MMCSD_SYNCHRONIZE=y # # SPI-based MMC/SD driver diff --git a/configs/mcu123-lpc214x/ostest/defconfig b/configs/mcu123-lpc214x/ostest/defconfig index a842b82c02..28dac142bf 100644 --- a/configs/mcu123-lpc214x/ostest/defconfig +++ b/configs/mcu123-lpc214x/ostest/defconfig @@ -303,8 +303,15 @@ CONFIG_FS_ROMFS=n # Number of MMC/SD slots supported by the driver # CONFIG_MMCSD_READONLY # Provide read-only access (default is read/write) +# CONFIG_MMCSD_SPICLOCK - Maximum SPI clock to drive MMC/SD card. +# Default is 20MHz. +# CONFIG_MMCSD_SYNCHRONIZE +# Special synchronization logic needed +# CONFIG_MMCSD_NSLOTS=1 CONFIG_MMCSD_READONLY=n +#CONFIG_MMCSD_SPICLOCK=20000000 +CONFIG_MMCSD_SYNCHRONIZE=y # # TCP/IP and UDP support via uIP diff --git a/configs/mcu123-lpc214x/src/up_spi.c b/configs/mcu123-lpc214x/src/up_spi.c index 59818748a7..f2ca5196d6 100644 --- a/configs/mcu123-lpc214x/src/up_spi.c +++ b/configs/mcu123-lpc214x/src/up_spi.c @@ -62,6 +62,7 @@ #include #include +#include #include #include @@ -79,9 +80,31 @@ * Definitions ****************************************************************************/ +/* Enables debug output from this file (needs CONFIG_DEBUG too) */ + +#undef SPI_DEBUG /* Define to enable debug */ +#undef SPI_VERBOSE /* Define to enable verbose debug */ + +#ifdef SPI_DEBUG +# define spidbg lldbg +# ifdef SPI_VERBOSE +# define spivdbg lldbg +# else +# define spivdbg(x...) +# endif +#else +# undef SPI_VERBOSE +# define spidbg(x...) +# define spivdbg(x...) +#endif + +/* Clocking */ + #define LPC214X_CCLKFREQ (LPC214X_FOSC*LPC214X_PLL_M) #define LPC214X_PCLKFREQ (LPC214X_CCLKFREQ/LPC214X_APB_DIV) +/* Use either FIO or legacy GPIO */ + #ifdef CONFIG_LPC214x_FIO # define CS_SET_REGISTER (LPC214X_FIO0_BASE+LPC214X_FIO_SET_OFFSET) # define CS_CLR_REGISTER (LPC214X_FIO0_BASE+LPC214X_FIO_CLR_OFFSET) @@ -153,12 +176,14 @@ static void spi_select(FAR struct spi_dev_s *dev, enum spi_dev_e devid, boolean { /* Enable slave select (low enables) */ + spidbg("CD asserted\n"); putreg32(bit, CS_CLR_REGISTER); } else { /* Disable slave select (low enables) */ + spidbg("CD de-asserted\n"); putreg32(bit, CS_SET_REGISTER); /* Wait for the TX FIFO not full indication */ @@ -214,6 +239,8 @@ static uint32 spi_setfrequency(FAR struct spi_dev_s *dev, uint32 frequency) divisor = (divisor + 1) & ~1; putreg8(divisor, LPC214X_SPI1_CPSR); + + spidbg("Frequency %d->%d\n", frequency, LPC214X_PCLKFREQ / divisor); return LPC214X_PCLKFREQ / divisor; } @@ -238,6 +265,7 @@ static ubyte spi_status(FAR struct spi_dev_s *dev, enum spi_dev_e devid) * board. */ + spidbg("Return SPI_STATUS_PRESENT\n"); return SPI_STATUS_PRESENT; } @@ -259,6 +287,8 @@ static ubyte spi_status(FAR struct spi_dev_s *dev, enum spi_dev_e devid) static uint16 spi_send(FAR struct spi_dev_s *dev, uint16 wd) { + register uint16 regval; + /* Wait while the TX FIFO is full */ while (!(getreg8(LPC214X_SPI1_SR) & LPC214X_SPI1SR_TNF)); @@ -273,7 +303,9 @@ static uint16 spi_send(FAR struct spi_dev_s *dev, uint16 wd) /* Get the value from the RX FIFO and return it */ - return (uint16)getreg16(LPC214X_SPI1_DR); + regval = getreg16(LPC214X_SPI1_DR); + spidbg("%04x->%04x\n", wd, regval); + return regval; } /************************************************************************* @@ -302,6 +334,7 @@ static void spi_sndblock(FAR struct spi_dev_s *dev, FAR const void *buffer, size /* Loop while thre are bytes remaining to be sent */ + spidbg("nwords: %d\n", nwords); while (nwords > 0) { /* While the TX FIFO is not full and there are bytes left to send */ @@ -318,6 +351,7 @@ static void spi_sndblock(FAR struct spi_dev_s *dev, FAR const void *buffer, size /* Then discard all card responses until the RX & TX FIFOs are emptied. */ + spidbg("discarding\n"); do { /* Is there anything in the RX fifo? */ @@ -367,11 +401,12 @@ static void spi_sndblock(FAR struct spi_dev_s *dev, FAR const void *buffer, size static void spi_recvblock(FAR struct spi_dev_s *dev, FAR void *buffer, size_t nwords) { FAR ubyte *ptr = (FAR ubyte*)buffer; - uint32 fifobytes = 0; + uint32 rxpending = 0; /* While there is remaining to be sent (and no synchronization error has occurred) */ - while (ptr || fifobytes) + spidbg("nwords: %d\n", nwords); + while (nwords || rxpending) { /* Fill the transmit FIFO with 0xff... * Write 0xff to the data register while (1) the TX FIFO is @@ -379,20 +414,22 @@ static void spi_recvblock(FAR struct spi_dev_s *dev, FAR void *buffer, size_t nw * and (3) there are more bytes to be sent. */ + spivdbg("TX: rxpending: %d nwords: %d\n", rxpending, nwords); while ((getreg8(LPC214X_SPI1_SR) & LPC214X_SPI1SR_TNF) && - (fifobytes < LPC214X_SPI1_FIFOSZ) && nwords) + (rxpending < LPC214X_SPI1_FIFOSZ) && nwords) { putreg16(0xff, LPC214X_SPI1_DR); nwords--; - fifobytes++; + rxpending++; } /* Now, read the RX data from the RX FIFO while the RX FIFO is not empty */ + spivdbg("RX: rxpending: %d\n", rxpending); while (getreg8(LPC214X_SPI1_SR) & LPC214X_SPI1SR_RNE) { *ptr++ = (ubyte)getreg16(LPC214X_SPI1_DR); - fifobytes--; + rxpending--; } } } diff --git a/configs/mcu123-lpc214x/usbserial/defconfig b/configs/mcu123-lpc214x/usbserial/defconfig index a9a41bfad9..445cbac4ef 100644 --- a/configs/mcu123-lpc214x/usbserial/defconfig +++ b/configs/mcu123-lpc214x/usbserial/defconfig @@ -308,8 +308,15 @@ CONFIG_FS_ROMFS=n # Number of MMC/SD slots supported by the driver # CONFIG_MMCSD_READONLY # Provide read-only access (default is read/write) +# CONFIG_MMCSD_SPICLOCK - Maximum SPI clock to drive MMC/SD card. +# Default is 20MHz. +# CONFIG_MMCSD_SYNCHRONIZE +# Special synchronization logic needed +# CONFIG_MMCSD_NSLOTS=1 CONFIG_MMCSD_READONLY=n +#CONFIG_MMCSD_SPICLOCK=20000000 +CONFIG_MMCSD_SYNCHRONIZE=y # # TCP/IP and UDP support via uIP diff --git a/configs/mcu123-lpc214x/usbstorage/defconfig b/configs/mcu123-lpc214x/usbstorage/defconfig index 170acc2369..da601a98ff 100644 --- a/configs/mcu123-lpc214x/usbstorage/defconfig +++ b/configs/mcu123-lpc214x/usbstorage/defconfig @@ -308,8 +308,15 @@ CONFIG_FS_ROMFS=n # Number of MMC/SD slots supported by the driver # CONFIG_MMCSD_READONLY # Provide read-only access (default is read/write) +# CONFIG_MMCSD_SPICLOCK - Maximum SPI clock to drive MMC/SD card. +# Default is 20MHz. +# CONFIG_MMCSD_SYNCHRONIZE +# Special synchronization logic needed +# CONFIG_MMCSD_NSLOTS=1 CONFIG_MMCSD_READONLY=n +#CONFIG_MMCSD_SPICLOCK=20000000 +CONFIG_MMCSD_SYNCHRONIZE=y # # TCP/IP and UDP support via uIP