mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-05-27 18:27:05 +08:00
Update driver to work with and external SPIFI library (vs. ROM)
git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@4952 7fd9a85b-ad96-42d3-883c-3090e2eb8679
This commit is contained in:
@@ -187,6 +187,7 @@ struct spifi_operands_s
|
|||||||
|
|
||||||
/* Interface to SPIFI ROM driver */
|
/* Interface to SPIFI ROM driver */
|
||||||
|
|
||||||
|
#ifndef CONFIG_SPIFI_LIBRARY
|
||||||
struct spifi_driver_s
|
struct spifi_driver_s
|
||||||
{
|
{
|
||||||
int32_t (*spifi_init)(struct spifi_dev_s *dev, uint32_t cshigh,
|
int32_t (*spifi_init)(struct spifi_dev_s *dev, uint32_t cshigh,
|
||||||
@@ -233,6 +234,7 @@ struct spifi_driver_s
|
|||||||
uint16_t value);
|
uint16_t value);
|
||||||
int32_t (*wait_busy)(struct spifi_dev_s *dev, uint8_t prog_or_erase);
|
int32_t (*wait_busy)(struct spifi_dev_s *dev, uint8_t prog_or_erase);
|
||||||
};
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Private Data
|
* Private Data
|
||||||
@@ -246,5 +248,14 @@ struct spifi_driver_s
|
|||||||
* Public Functions
|
* Public Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifdef CONFIG_SPIFI_LIBRARY
|
||||||
|
EXTERN int32_t spifi_init(struct spifi_dev_s *dev, uint32_t cshigh,
|
||||||
|
uint32_t options, uint32_t mhz);
|
||||||
|
EXTERN int32_t spifi_program(struct spifi_dev_s *dev, const uint8_t *source,
|
||||||
|
struct spifi_operands_s *opers);
|
||||||
|
EXTERN int32_t spifi_erase(struct spifi_dev_s *dev,
|
||||||
|
struct spifi_operands_s *opers);
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* __ARCH_ARM_SRC_LPC43XX_CHIP_LPC43_SPIFI_H */
|
#endif /* __ARCH_ARM_SRC_LPC43XX_CHIP_LPC43_SPIFI_H */
|
||||||
|
|
||||||
|
|||||||
@@ -86,7 +86,7 @@
|
|||||||
/* This is where the LPC43xx address where random-access reads begin */
|
/* This is where the LPC43xx address where random-access reads begin */
|
||||||
|
|
||||||
#define SPIFI_BASE \
|
#define SPIFI_BASE \
|
||||||
(FAR uint8_t *)(LPC43_LOCSRAM_SPIFI_BASE + CONFIG_SPIFI_OFFSET)
|
(FAR uint8_t *)(LPC43_SPIFI_DATA_BASE + CONFIG_SPIFI_OFFSET)
|
||||||
|
|
||||||
/* Check if we are using a hard-coded block size */
|
/* Check if we are using a hard-coded block size */
|
||||||
|
|
||||||
@@ -114,7 +114,7 @@
|
|||||||
# elif CONFIG_SPIFI_BLKSIZE == (256*1024)
|
# elif CONFIG_SPIFI_BLKSIZE == (256*1024)
|
||||||
# define SPIFI_BLKSHIFT 18
|
# define SPIFI_BLKSHIFT 18
|
||||||
# else
|
# else
|
||||||
# error "Unsupported value of CONFIG_SPIFI_BLKSIZE
|
# error "Unsupported value of CONFIG_SPIFI_BLKSIZE"
|
||||||
# endif
|
# endif
|
||||||
# define SPIFI_BLKSIZE CONFIG_SPIFI_BLKSIZE
|
# define SPIFI_BLKSIZE CONFIG_SPIFI_BLKSIZE
|
||||||
#else
|
#else
|
||||||
@@ -122,6 +122,24 @@
|
|||||||
# define SPIFI_BLKSHIFT priv->blkshift
|
# define SPIFI_BLKSHIFT priv->blkshift
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* Can use ROM driver or an external driver library */
|
||||||
|
|
||||||
|
#ifndef CONFIG_SPIFI_LIBRARY
|
||||||
|
# define SPIFI_INIT(priv, rom, cshigh, options, mhz) \
|
||||||
|
priv->spifi->spifi_init(rom, cshigh, options, mhz)
|
||||||
|
# define SPIFI_PROGRAM(priv, rom, src, operands) \
|
||||||
|
priv->spifi->spifi_program(rom, src, operands)
|
||||||
|
# define SPIFI_ERASE(priv, rom, operands) \
|
||||||
|
priv->spifi->spifi_erase(rom, operands)
|
||||||
|
#else
|
||||||
|
# define SPIFI_INIT(priv, rom, cshigh, options, mhz) \
|
||||||
|
spifi_init(rom, cshigh, options, mhz)
|
||||||
|
# define SPIFI_PROGRAM(priv, rom, src, operands) \
|
||||||
|
spifi_program(rom, src, operands)
|
||||||
|
# define SPIFI_ERASE(priv, rom, operands) \
|
||||||
|
spifi_erase(rom, operands)
|
||||||
|
#endif
|
||||||
|
|
||||||
/* 512 byte sector simulation */
|
/* 512 byte sector simulation */
|
||||||
|
|
||||||
#ifdef CONFIG_SPIFI_SECTOR512 /* Emulate a 512 byte sector */
|
#ifdef CONFIG_SPIFI_SECTOR512 /* Emulate a 512 byte sector */
|
||||||
@@ -240,7 +258,9 @@
|
|||||||
struct lpc43_dev_s
|
struct lpc43_dev_s
|
||||||
{
|
{
|
||||||
struct mtd_dev_s mtd; /* MTD interface */
|
struct mtd_dev_s mtd; /* MTD interface */
|
||||||
|
#ifndef CONFIG_SPIFI_LIBRARY
|
||||||
FAR struct spifi_driver_s *spifi; /* Pointer to ROM driver table */
|
FAR struct spifi_driver_s *spifi; /* Pointer to ROM driver table */
|
||||||
|
#endif
|
||||||
FAR struct spifi_dev_s rom; /* Needed for communication with ROM driver */
|
FAR struct spifi_dev_s rom; /* Needed for communication with ROM driver */
|
||||||
struct spifi_operands_s operands; /* Needed for program and erase ROM calls */
|
struct spifi_operands_s operands; /* Needed for program and erase ROM calls */
|
||||||
uint16_t nblocks; /* Number of blocks of size blksize */
|
uint16_t nblocks; /* Number of blocks of size blksize */
|
||||||
@@ -331,10 +351,10 @@ static void lpc43_blockerase(struct lpc43_dev_s *priv, off_t sector)
|
|||||||
priv->operands.dest = SPIFI_BASE + (sector << SPIFI_BLKSHIFT);
|
priv->operands.dest = SPIFI_BASE + (sector << SPIFI_BLKSHIFT);
|
||||||
priv->operands.length = SPIFI_BLKSIZE;
|
priv->operands.length = SPIFI_BLKSIZE;
|
||||||
|
|
||||||
result = priv->spifi->spifi_erase(&priv->rom, &priv->operands);
|
result = SPIFI_ERASE(priv, &priv->rom, &priv->operands);
|
||||||
if (result != 0)
|
if (result != 0)
|
||||||
{
|
{
|
||||||
fdbg("ERROR: spifi_erase failed: %05x\n", result);
|
fdbg("ERROR: SPIFI_ERASE failed: %05x\n", result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -357,10 +377,10 @@ static inline int lpc43_chiperase(struct lpc43_dev_s *priv)
|
|||||||
priv->operands.dest = SPIFI_BASE;
|
priv->operands.dest = SPIFI_BASE;
|
||||||
priv->operands.length = SPIFI_BLKSIZE * priv->nblocks;
|
priv->operands.length = SPIFI_BLKSIZE * priv->nblocks;
|
||||||
|
|
||||||
result = priv->spifi->spifi_erase(&priv->rom, &priv->operands);
|
result = SPIFI_ERASE(priv, &priv->rom, &priv->operands);
|
||||||
if (result != 0)
|
if (result != 0)
|
||||||
{
|
{
|
||||||
fdbg("ERROR: spifi_erase failed: %05x\n", result);
|
fdbg("ERROR: SPIFI_ERASE failed: %05x\n", result);
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -388,10 +408,10 @@ static int lpc43_pagewrite(FAR struct lpc43_dev_s *priv, FAR uint8_t *dest,
|
|||||||
priv->operands.dest = dest;
|
priv->operands.dest = dest;
|
||||||
priv->operands.length = nbytes;
|
priv->operands.length = nbytes;
|
||||||
|
|
||||||
result = priv->spifi->spifi_program(&priv->rom, src, &priv->operands);
|
result = SPIFI_PROGRAM(priv, &priv->rom, src, &priv->operands);
|
||||||
if (result != 0)
|
if (result != 0)
|
||||||
{
|
{
|
||||||
fdbg("ERROR: spifi_program failed: %05x\n", result);
|
fdbg("ERROR: SPIFI_PROGRAM failed: %05x\n", result);
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -891,7 +911,6 @@ static inline void lpc43_spifi_pinconfig(void)
|
|||||||
|
|
||||||
static inline int lpc43_rominit(FAR struct lpc43_dev_s *priv)
|
static inline int lpc43_rominit(FAR struct lpc43_dev_s *priv)
|
||||||
{
|
{
|
||||||
FAR struct spifi_driver_s *spifi;
|
|
||||||
#ifndef CONFIG_SPIFI_BLKSIZE
|
#ifndef CONFIG_SPIFI_BLKSIZE
|
||||||
FAR struct spfi_desc_s *desc;
|
FAR struct spfi_desc_s *desc;
|
||||||
uint16_t sectors;
|
uint16_t sectors;
|
||||||
@@ -901,8 +920,9 @@ static inline int lpc43_rominit(FAR struct lpc43_dev_s *priv)
|
|||||||
|
|
||||||
/* Get the pointer to the SPIFI ROM driver table. */
|
/* Get the pointer to the SPIFI ROM driver table. */
|
||||||
|
|
||||||
spifi = *((struct spifi_driver_s **)SPIFI_ROM_PTR);
|
#ifndef CONFIG_SPIFI_LIBRARY
|
||||||
priv->spifi = spifi;
|
priv->spifi = *((struct spifi_driver_s **)SPIFI_ROM_PTR);
|
||||||
|
#endif
|
||||||
|
|
||||||
/* The final parameter of the spifi_init() ROM driver call should be the
|
/* The final parameter of the spifi_init() ROM driver call should be the
|
||||||
* serial clock rate divided by 1000000, rounded to an integer. The SPIFI
|
* serial clock rate divided by 1000000, rounded to an integer. The SPIFI
|
||||||
@@ -923,19 +943,19 @@ static inline int lpc43_rominit(FAR struct lpc43_dev_s *priv)
|
|||||||
* 0x20004 Operand error: S_MODE3+S_FULLCLK+S_RCVCLK in options
|
* 0x20004 Operand error: S_MODE3+S_FULLCLK+S_RCVCLK in options
|
||||||
*/
|
*/
|
||||||
|
|
||||||
result = spifi->spifi_init(&priv->rom, SPIFI_CSHIGH,
|
result = SPIFI_INIT(priv, &priv->rom, SPIFI_CSHIGH,
|
||||||
S_RCVCLK | S_FULLCLK, SCLK_MHZ);
|
S_RCVCLK | S_FULLCLK, SCLK_MHZ);
|
||||||
if (result != 0)
|
if (result != 0)
|
||||||
{
|
{
|
||||||
fdbg("ERROR: spifi_init failed: %05x\n", result);
|
fdbg("ERROR: SPIFI_INIT failed: %05x\n", result);
|
||||||
|
|
||||||
/* Try again */
|
/* Try again */
|
||||||
|
|
||||||
result = spifi->spifi_init(&priv->rom, SPIFI_CSHIGH,
|
result = SPIFI_INIT(priv, &priv->rom, SPIFI_CSHIGH,
|
||||||
S_RCVCLK | S_FULLCLK, SCLK_MHZ);
|
S_RCVCLK | S_FULLCLK, SCLK_MHZ);
|
||||||
if (result != 0)
|
if (result != 0)
|
||||||
{
|
{
|
||||||
fdbg("ERROR: spifi_init failed: %05x\n", result);
|
fdbg("ERROR: SPIFI_INIT failed: %05x\n", result);
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1114,4 +1134,60 @@ FAR struct mtd_dev_s *lpc43_spifi_initialize(void)
|
|||||||
return (FAR struct mtd_dev_s *)priv;
|
return (FAR struct mtd_dev_s *)priv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: pullMISO
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* hardware-control routine used by spifi_rom_api.c
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* high
|
||||||
|
*
|
||||||
|
* Returned value:
|
||||||
|
* None.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifdef CONFIG_SPIFI_LIBRARY
|
||||||
|
void pullMISO(int high)
|
||||||
|
{
|
||||||
|
uint32_t pinconfig;
|
||||||
|
|
||||||
|
/* Control MISO pull-up/down state Assume pull down by clearing:
|
||||||
|
*
|
||||||
|
* EPD = Enable pull-down connect (bit
|
||||||
|
*/
|
||||||
|
|
||||||
|
pinconfig = PINCONF_SPIFI_MISO & ~(PINCONF_PULLUP | PINCONF_PULLDOWN);
|
||||||
|
switch (high)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
{
|
||||||
|
/* Pull down */
|
||||||
|
|
||||||
|
pinconfig |= PINCONF_PULLDOWN;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 1:
|
||||||
|
{
|
||||||
|
/* Pull up */
|
||||||
|
|
||||||
|
pinconfig |= PINCONF_PULLUP;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
/* Neither */
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Reconfigure MISO */
|
||||||
|
|
||||||
|
lpc43_pin_config(pinconfig);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* CONFIG_LPC43_SPIFI */
|
#endif /* CONFIG_LPC43_SPIFI */
|
||||||
|
|||||||
@@ -69,6 +69,8 @@
|
|||||||
*
|
*
|
||||||
* Other SPIFI options
|
* Other SPIFI options
|
||||||
*
|
*
|
||||||
|
* CONFIG_SPIFI_LIBRARY - Don't use the LPC43xx ROM routines but, instead,
|
||||||
|
* use an external library implementation of the SPIFI interface.
|
||||||
* CONFIG_SPIFI_SECTOR512 - If defined, then the driver will report a more
|
* CONFIG_SPIFI_SECTOR512 - If defined, then the driver will report a more
|
||||||
* FAT friendly 512 byte sector size and will manage the read-modify-write
|
* FAT friendly 512 byte sector size and will manage the read-modify-write
|
||||||
* operations on the larger erase block.
|
* operations on the larger erase block.
|
||||||
|
|||||||
@@ -920,3 +920,5 @@ Where <subdir> is one of the following:
|
|||||||
FAT friendly 512 byte sector size and will manage the read-modify-write
|
FAT friendly 512 byte sector size and will manage the read-modify-write
|
||||||
operations on the larger erase block.
|
operations on the larger erase block.
|
||||||
CONFIG_SPIFI_READONLY - Define to support only read-only operations.
|
CONFIG_SPIFI_READONLY - Define to support only read-only operations.
|
||||||
|
CONFIG_SPIFI_LIBRARY - Don't use the LPC43xx ROM routines but, instead,
|
||||||
|
use an external library implementation of the SPIFI interface.
|
||||||
|
|||||||
@@ -678,11 +678,14 @@ CONFIG_MMCSD_HAVECARDDETECT=n
|
|||||||
# FAT friendly 512 byte sector size and will manage the read-modify-write
|
# FAT friendly 512 byte sector size and will manage the read-modify-write
|
||||||
# operations on the larger erase block.
|
# operations on the larger erase block.
|
||||||
# CONFIG_SPIFI_READONLY - Define to support only read-only operations.
|
# CONFIG_SPIFI_READONLY - Define to support only read-only operations.
|
||||||
|
# CONFIG_SPIFI_LIBRARY - Don't use the LPC43xx ROM routines but, instead,
|
||||||
|
# use an external library implementation of the SPIFI interface.
|
||||||
#
|
#
|
||||||
CONFIG_SPIFI_OFFSET=0
|
CONFIG_SPIFI_OFFSET=0
|
||||||
CONFIG_SPIFI_BLKSIZE=4096
|
CONFIG_SPIFI_BLKSIZE=4096
|
||||||
CONFIG_SPIFI_SECTOR512=y
|
CONFIG_SPIFI_SECTOR512=y
|
||||||
CONFIG_SPIFI_RDONLY=n
|
CONFIG_SPIFI_RDONLY=n
|
||||||
|
CONFIG_SPIFI_LIBRARY=n
|
||||||
|
|
||||||
# TCP/IP and UDP support via uIP
|
# TCP/IP and UDP support via uIP
|
||||||
# CONFIG_NET - Enable or disable all network features
|
# CONFIG_NET - Enable or disable all network features
|
||||||
|
|||||||
Reference in New Issue
Block a user