aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpatacongo <patacongo@7fd9a85b-ad96-42d3-883c-3090e2eb8679>2012-06-02 17:57:39 +0000
committerpatacongo <patacongo@7fd9a85b-ad96-42d3-883c-3090e2eb8679>2012-06-02 17:57:39 +0000
commitdc1b82ed5d391c7826e5ac2ce37f1a9a4afd05ac (patch)
tree8fbbbac14a995c8ffe8efaf86aa850ebb6299dc4
parente02ce9e19d180928c61f58d78b8add3ed37da9a5 (diff)
downloadpx4-firmware-dc1b82ed5d391c7826e5ac2ce37f1a9a4afd05ac.tar.gz
px4-firmware-dc1b82ed5d391c7826e5ac2ce37f1a9a4afd05ac.tar.bz2
px4-firmware-dc1b82ed5d391c7826e5ac2ce37f1a9a4afd05ac.zip
Add SD card support to the PIC32MX7 MMB board; Add regiser level debug instrumentatin for the PIC32 SPI driver
git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@4797 7fd9a85b-ad96-42d3-883c-3090e2eb8679
-rw-r--r--nuttx/ChangeLog4
-rw-r--r--nuttx/arch/mips/src/pic32mx/pic32mx-spi.c85
-rw-r--r--nuttx/configs/pic32mx7mmb/README.txt26
-rw-r--r--nuttx/configs/pic32mx7mmb/nsh/defconfig3
-rw-r--r--nuttx/configs/pic32mx7mmb/src/pic32mx7mmb_internal.h20
-rw-r--r--nuttx/configs/pic32mx7mmb/src/up_nsh.c11
-rw-r--r--nuttx/configs/pic32mx7mmb/src/up_spi.c101
7 files changed, 200 insertions, 50 deletions
diff --git a/nuttx/ChangeLog b/nuttx/ChangeLog
index 60e3ff539..ad6349e02 100644
--- a/nuttx/ChangeLog
+++ b/nuttx/ChangeLog
@@ -2870,5 +2870,9 @@
the search loop missed the PHY address needed by the Mikroelektronika
PIC32MX7 MMB board.
* configs/pic32mx7mmb/nsh: Configuration now supports a network by default.
+ * configs/pic32mx7mmb/src: Add support for the MMC/SD slot on board
+ the Mikroelektronika PIC32MX7 MMB board (not working on initial check-in).
+ * arch/mips/src/pic32/pic32mx-spi.c: Add support for very low-level,
+ register access debug output.
diff --git a/nuttx/arch/mips/src/pic32mx/pic32mx-spi.c b/nuttx/arch/mips/src/pic32mx/pic32mx-spi.c
index fc81f3d25..ee7cea9eb 100644
--- a/nuttx/arch/mips/src/pic32mx/pic32mx-spi.c
+++ b/nuttx/arch/mips/src/pic32mx/pic32mx-spi.c
@@ -72,6 +72,7 @@
#ifndef CONFIG_DEBUG
# undef CONFIG_DEBUG_SPI
# undef CONFIG_DEBUG_VERBOSE
+# undef CONFIG_SPI_REGDEBUG
#endif
#ifdef CONFIG_DEBUG_SPI
@@ -309,13 +310,75 @@ static struct pic32mx_dev_s g_spi4dev =
*
****************************************************************************/
+#ifdef CONFIG_SPI_REGDEBUG
+static uint32_t spi_getreg(FAR struct pic32mx_dev_s *priv, unsigned int offset)
+{
+ /* Last address, value, and count */
+
+ static uint32_t prevaddr = 0;
+ static uint32_t prevalue = 0;
+ static uint32_t count = 0;
+
+ /* New address and value */
+
+ uint32_t addr;
+ uint32_t value;
+
+ /* Read the value from the register */
+
+ addr = priv->base + offset;
+ value = getreg32(addr);
+
+ /* Is this the same value that we read from the same register last time?
+ * Are we polling the register? If so, suppress some of the output.
+ */
+
+ if (addr == prevaddr && value == prevalue)
+ {
+ if (count == 0xffffffff || ++count > 3)
+ {
+ if (count == 4)
+ {
+ lldbg("...\n");
+ }
+ return value;
+ }
+ }
+
+ /* No this is a new address or value */
+
+ else
+ {
+ /* Did we print "..." for the previous value? */
+
+ if (count > 3)
+ {
+ /* Yes.. then show how many times the value repeated */
+
+ lldbg("[repeats %d more times]\n", count-3);
+ }
+
+ /* Save the new address, value, and count */
+
+ prevaddr = addr;
+ prevalue = value;
+ count = 1;
+ }
+
+ /* Show the register value read */
+
+ lldbg("%08x->%08x\n", addr, value);
+ return value;
+}
+#else
static uint32_t spi_getreg(FAR struct pic32mx_dev_s *priv, unsigned int offset)
{
return getreg32(priv->base + offset);
}
+#endif
/****************************************************************************
- * Name: spi_getreg
+ * Name: spi_putreg
*
* Description:
* Write a value to one, 32-bit SPI register
@@ -330,11 +393,31 @@ static uint32_t spi_getreg(FAR struct pic32mx_dev_s *priv, unsigned int offset)
*
****************************************************************************/
+#ifdef CONFIG_SPI_REGDEBUG
+static void spi_putreg(FAR struct pic32mx_dev_s *priv, unsigned int offset,
+ uint32_t value)
+{
+ uint32_t addr;
+
+ /* Get the address to write to */
+
+ addr = priv->base + offset;
+
+ /* Show the register value being written */
+
+ lldbg("%08x<-%08x\n", addr, value);
+
+ /* Then do the write */
+
+ putreg32(value, addr);
+}
+#else
static void spi_putreg(FAR struct pic32mx_dev_s *priv, unsigned int offset,
uint32_t value)
{
putreg32(value, priv->base + offset);
}
+#endif
/****************************************************************************
* Name: spi_lock
diff --git a/nuttx/configs/pic32mx7mmb/README.txt b/nuttx/configs/pic32mx7mmb/README.txt
index bbf62ab8f..3f47e0233 100644
--- a/nuttx/configs/pic32mx7mmb/README.txt
+++ b/nuttx/configs/pic32mx7mmb/README.txt
@@ -32,8 +32,8 @@ PIN CONFIGURATIONS SIGNAL NAME ON-BOARD CONNE
7 RC2/AC2TX/T3CK EE_CS# M25P80 CS
8 RC3/AC2RX/T4CK ACL_CS# ADXL345 CS and VCC
9 RC4/SDI1/T5CK SDI1 SPI1 data IN
- 10 PMA5/CN8/ECOL/RG6/SCK2/U3RTS/U6TX RG6 ?
- 11 PMA4/CN9/ECRS/RG7/SDA4/SDI2/U3RX SD_CD# SD Connector
+ 10 PMA5/CN8/ECOL/RG6/SCK2/U3RTS/U6TX SD_WP SD card, write protect
+ 11 PMA4/CN9/ECRS/RG7/SDA4/SDI2/U3RX SD_CD# SD card, card detect (not)
12 PMA3/AECRSDV/AERXDV/CN10/ECRSDV/ AECRSDV LAN8720A SRS_DIV
ERXDV/RG8/SCL4/SDO2/U3TX
13 MCLR MCLR Debug connector
@@ -636,14 +636,19 @@ Where <subdir> is one of the following:
before the networking finally gives up and decides that no network is
available.
- 2. This example can support an FTP client. In order to build in FTP client
+ 2. To add SPI-based support for the SD card slot:
+
+ CONFIG_PIC32MX_SPI1=y
+ CONFIG_NSH_ARCHINIT=y
+
+ 3. This example can support an FTP client. In order to build in FTP client
support simply uncomment the following lines in the appconfig file (before
configuring) or in the apps/.config file (after configuring):
#CONFIGURED_APPS += netutils/ftpc
#CONFIGURED_APPS += examples/ftpc
- 3. This example can support an FTP server. In order to build in FTP server
+ 4. This example can support an FTP server. In order to build in FTP server
support simply uncomment the following lines in the appconfig file (before
configuring) or in the apps/.config file (after configuring):
@@ -654,11 +659,10 @@ Where <subdir> is one of the following:
CONFIG_DISABLE_POLL=n
- Using a RAM disk and the USB MSC device with nsh and nsh2
- ---------------------------------------------------------
- Here is an experimental change to either examples/nsh or examples/nsh2
- that will create a RAM disk and attempt to export that RAM disk as a
- USB mass storage device.
+ Using a RAM disk and the USB MSC device to the nsh configuration
+ ----------------------------------------------------------------
+ Here is an experimental change to examples/nsh that will create a RAM
+ disk and attempt to export that RAM disk as a USB mass storage device.
1. Changes to nuttx/.config
@@ -737,8 +741,8 @@ Where <subdir> is one of the following:
Status: Open
Priority: High
- Adding LCD and graphics support:
- -------------------------------
+ Adding LCD and graphics support to the nsh configuration:
+ --------------------------------------------------------
appconfig (apps/.config): Enable the application configurations that you
want to use. Asexamples:
diff --git a/nuttx/configs/pic32mx7mmb/nsh/defconfig b/nuttx/configs/pic32mx7mmb/nsh/defconfig
index 35bcbd89d..0e63ccfe8 100644
--- a/nuttx/configs/pic32mx7mmb/nsh/defconfig
+++ b/nuttx/configs/pic32mx7mmb/nsh/defconfig
@@ -445,6 +445,9 @@ CONFIG_DEBUG_NET=n
CONFIG_DEBUG_LCD=n
CONFIG_DEBUG_GRAPHICS=n
CONFIG_DEBUG_INPUT=n
+CONFIG_DEBUG_FS=n
+CONFIG_DEBUG_SPI=n
+CONFIG_SPI_REGDEBUG=n
CONFIG_HAVE_CXX=n
CONFIG_HAVE_CXXINITIALIZE=n
diff --git a/nuttx/configs/pic32mx7mmb/src/pic32mx7mmb_internal.h b/nuttx/configs/pic32mx7mmb/src/pic32mx7mmb_internal.h
index db523b67f..f44e04258 100644
--- a/nuttx/configs/pic32mx7mmb/src/pic32mx7mmb_internal.h
+++ b/nuttx/configs/pic32mx7mmb/src/pic32mx7mmb_internal.h
@@ -83,6 +83,20 @@
* RD2 LCD-BLED Backlight Light Low value turns off
*/
+/* SPI1 and SD Card
+ *
+ * ------ -------- ------------------------- --------------------------------
+ * GPIO SIGNAL BOARD CONNECTION NOTES
+ * ------ -------- ------------------------- --------------------------------
+ * RC4 SPI1 SD card slot SPI1 data IN
+ * RD0 SPO1 SD card slot SPI1 data OUT
+ * RD10 SCK1 SD card slot SD card, SPI clock
+ *
+ * RA9 SD_CS# SD card slot SD card, SPI chip select (active low)
+ * RG6 SD_WP SD card slot SD card, write protect
+ * RG7 SD_CD# SD card slot SD card, card detect (not)
+ */
+
/****************************************************************************
* Public Types
****************************************************************************/
@@ -108,11 +122,13 @@ extern "C" {
* Name: pic32mx_spiinitialize
*
* Description:
- * Called to configure SPI chip select GPIO pins for the PCB Logic board.
+ * Called to configure SPI chip select GPIO pins for the Mikroelektronika PIC32MX7
+ * MMB board.
*
************************************************************************************/
-#if defined(CONFIG_PIC32MX_SPI2)
+#if defined(CONFIG_PIC32MX_SPI1) || defined(CONFIG_PIC32MX_SPI2) || \
+ defined(CONFIG_PIC32MX_SPI3) || defined(CONFIG_PIC32MX_SPI4)
EXTERN void weak_function pic32mx_spiinitialize(void);
#endif
diff --git a/nuttx/configs/pic32mx7mmb/src/up_nsh.c b/nuttx/configs/pic32mx7mmb/src/up_nsh.c
index e5a192b1c..0d022531f 100644
--- a/nuttx/configs/pic32mx7mmb/src/up_nsh.c
+++ b/nuttx/configs/pic32mx7mmb/src/up_nsh.c
@@ -61,13 +61,10 @@
#define CONFIG_NSH_HAVEMMCSD 1
#define CONFIG_NSH_HAVEUSBHOST 1
-/* TheMikroelektronika PIC32MX7 MMB does not have an SD slot on board. If one
- * is added, then it must be specified by defining which SPI bus that it
- * is connected on.
- */
+/* The Mikroelektronika PIC32MX7 MMB has one SD slot on board, connected to SPI 1. */
#ifndef CONFIG_PIC32MX_MMCSDSPIPORTNO
-# undef CONFIG_NSH_HAVEMMCSD
+# define CONFIG_PIC32MX_MMCSDSPIPORTNO 1
#endif
/* Make sure that the configuration will support the SD card */
@@ -84,7 +81,9 @@
# define CONFIG_NSH_MMCSDSPIPORTNO CONFIG_PIC32MX_MMCSDSPIPORTNO
# endif
- /* Make sure that the NSH configuration uses the slot */
+ /* Make sure that the NSH configuration uses slot 0 (there is only one
+ * SD slot on the Mikroelektronica PIC32MX7 MMB).
+ */
# if !defined(CONFIG_NSH_MMCSDSLOTNO) || CONFIG_NSH_MMCSDSLOTNO != 0
# warning "The Mikroelektronika PIC32MX7 MMB has only one slot (0)"
diff --git a/nuttx/configs/pic32mx7mmb/src/up_spi.c b/nuttx/configs/pic32mx7mmb/src/up_spi.c
index 48e059294..407279fd1 100644
--- a/nuttx/configs/pic32mx7mmb/src/up_spi.c
+++ b/nuttx/configs/pic32mx7mmb/src/up_spi.c
@@ -58,24 +58,35 @@
/************************************************************************************
* Definitions
************************************************************************************/
+/* SPI1 and SD Card
+ *
+ * ------ -------- ------------------------- --------------------------------
+ * GPIO SIGNAL BOARD CONNECTION NOTES
+ * ------ -------- ------------------------- --------------------------------
+ * RC4 SPI1 SD card slot SPI1 data IN
+ * RD0 SPO1 SD card slot SPI1 data OUT
+ * RD10 SCK1 SD card slot SD card, SPI clock
+ *
+ * RA9 SD_CS# SD card slot SD card, SPI chip select (active low)
+ * RG6 SD_WP SD card slot SD card, write protect
+ * RG7 SD_CD# SD card slot SD card, card detect (not)
+ */
+
+#define GPIO_SD_CS (GPIO_OUTPUT|GPIO_VALUE_ONE|GPIO_PORTA|GPIO_PIN9)
+#define GPIO_SD_WP (GPIO_INPUT|GPIO_PORTG|GPIO_PIN6)
+#define GPIO_SD_CD (GPIO_INPUT|GPIO_INT|GPIO_PORTG|GPIO_PIN7)
/* The following enable debug output from this file (needs CONFIG_DEBUG too).
*
- * CONFIG_SPI_DEBUG - Define to enable basic SPI debug
- * CONFIG_SPI_VERBOSE - Define to enable verbose SPI debug
+ * CONFIG_DEBUG_SPI - Define to enable basic SPI debug
*/
-#ifdef CONFIG_SPI_DEBUG
-# define sspdbg lldbg
-# ifdef CONFIG_SPI_VERBOSE
-# define sspvdbg lldbg
-# else
-# define sspvdbg(x...)
-# endif
+#ifdef CONFIG_DEBUG_SPI
+# define spidbg lldbg
+# define spivdbg llvdbg
#else
-# undef CONFIG_SPI_VERBOSE
-# define sspdbg(x...)
-# define sspvdbg(x...)
+# define spidbg(x...)
+# define spivdbg(x...)
#endif
/************************************************************************************
@@ -90,15 +101,20 @@
* Name: pic32mx_sspinitialize
*
* Description:
- * Called to configure SPI chip select GPIO pins for the Sure PIC32MX board.
+ * Called to configure SPI chip select GPIO pins for the Mikroelektronka PIC32MX7
+ * MMB board.
*
************************************************************************************/
void weak_function pic32mx_sspinitialize(void)
{
- /* Configure the SPI chip select GPIOs */
+ /* Configure the SPI chip select, write protect, and card detect GPIOs */
-#warning "Missing logic"
+#ifdef CONFIG_PIC32MX_SPI1
+ pic32mx_configgpio(GPIO_SD_CS);
+ pic32mx_configgpio(GPIO_SD_WP);
+ pic32mx_configgpio(GPIO_SD_CD);
+#endif
}
/************************************************************************************
@@ -135,15 +151,37 @@ enum spi_dev_e;
#ifdef CONFIG_PIC32MX_SPI1
void pic32mx_spi1select(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool selected)
{
- sspdbg("devid: %d CS: %s\n", (int)devid, selected ? "assert" : "de-assert");
-#warning "Missing logic"
+ spidbg("devid: %d CS: %s\n", (int)devid, selected ? "assert" : "de-assert");
+
+ if (devid == SPIDEV_MMCSD)
+ {
+ pic32mx_gpiowrite(GPIO_SD_CS, !selected);
+ }
}
uint8_t pic32mx_spi1status(FAR struct spi_dev_s *dev, enum spi_dev_e devid)
{
- sspdbg("Returning nothing\n");
-#warning "Missing logic"
- return 0;
+ uint8_t ret = 0;
+
+ /* Card detect active low. */
+
+ if (devid == SPIDEV_MMCSD)
+ {
+ if (!pic32mx_gpioread(GPIO_SD_CD))
+ {
+ ret = SPI_STATUS_PRESENT;
+
+ /* A high value indicates the the card is write protected. */
+
+ if (pic32mx_gpioread(GPIO_SD_WP))
+ {
+ ret |= SPI_STATUS_WRPROTECTED;
+ }
+ }
+ }
+
+ spidbg("Returning %02x\n", ret);
+ return ret;
}
#ifdef CONFIG_SPI_CMDDATA
int pic32mx_spi1cmddata(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool cmd)
@@ -154,21 +192,22 @@ int pic32mx_spi1cmddata(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool cm
#endif
#endif
-#ifdef CONFIG_PIC31MX_SPI1
-void pic31mx_spi1select(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool selected)
+#ifdef CONFIG_PIC31MX_SPI2
+void pic31mx_spi2select(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool selected)
{
- sspdbg("devid: %d CS: %s\n", (int)devid, selected ? "assert" : "de-assert");
+ spidbg("devid: %d CS: %s\n", (int)devid, selected ? "assert" : "de-assert");
#warning "Missing logic"
}
-uint8_t pic31mx_spi1status(FAR struct spi_dev_s *dev, enum spi_dev_e devid)
+uint8_t pic31mx_spi2status(FAR struct spi_dev_s *dev, enum spi_dev_e devid)
{
- sspdbg("Returning nothing\n");
+ spidbg("Returning nothing\n");
#warning "Missing logic"
return 0;
}
+
#ifdef CONFIG_SPI_CMDDATA
-int pic31mx_spi1cmddata(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool cmd)
+int pic31mx_spi2cmddata(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool cmd)
{
#warning "Missing logic"
return 0;
@@ -179,16 +218,17 @@ int pic31mx_spi1cmddata(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool cm
#ifdef CONFIG_PIC31MX_SPI3
void pic32mx_spi3select(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool selected)
{
- sspdbg("devid: %d CS: %s\n", (int)devid, selected ? "assert" : "de-assert");
+ spidbg("devid: %d CS: %s\n", (int)devid, selected ? "assert" : "de-assert");
#warning "Missing logic"
}
uint8_t pic32mx_spi3status(FAR struct spi_dev_s *dev, enum spi_dev_e devid)
{
- sspdbg("Returning nothing\n");
+ spidbg("Returning nothing\n");
#warning "Missing logic"
return 0;
}
+
#ifdef CONFIG_SPI_CMDDATA
int pic32mx_spi3cmddata(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool cmd)
{
@@ -201,16 +241,17 @@ int pic32mx_spi3cmddata(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool cm
#ifdef CONFIG_PIC32MX_SPI4
void pic32mx_spi4select(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool selected)
{
- sspdbg("devid: %d CS: %s\n", (int)devid, selected ? "assert" : "de-assert");
+ spidbg("devid: %d CS: %s\n", (int)devid, selected ? "assert" : "de-assert");
#warning "Missing logic"
}
uint8_t pic32mx_spi4status(FAR struct spi_dev_s *dev, enum spi_dev_e devid)
{
- sspdbg("Returning nothing\n");
+ spidbg("Returning nothing\n");
#warning "Missing logic"
return 0;
}
+
#ifdef CONFIG_SPI_CMDDATA
int pic32mx_spi4cmddata(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool cmd)
{