Merged in jjlange/nuttx/mx25l_4B (pull request #1016)

Add support for 4-byte addressing on >128Mb Macronix flash parts

* Save CONFIG_ARCH_BOARD_CUSTOM when running 'make savedefconfig'

* Only use PCLKSEL0 for ADC on LPC176x family.

* Made grep search expression more specific.

* Added missing '=' to second grep

* Revert "Only use PCLKSEL0 for ADC on LPC176x family."

    This reverts commit 835b5e9d6fcbea02cb0203c063b0e121fa57ba9e.

* Revert "Added missing '=' to second grep"

    This reverts commit 38b51f0c6d9612de755c102a53846ca7488cdf14.

* Added a missing '=' in the second grep statement

* Added support for 4-byte addressing on >128Mb Macronix flash parts

Approved-by: Gregory Nutt <gnutt@nuttx.org>
This commit is contained in:
jjlange 2019-08-21 22:09:45 +00:00 committed by Gregory Nutt
parent 6ddd4752b0
commit 7b6cff6f84

View File

@ -100,6 +100,11 @@
#define MX25L_MX25L25635F_NSECTORS 8192
#define MX25L_MX25L25635F_PAGE_SHIFT 8 /* Page size 1 << 8 = 256 */
/* Parts larger than 128Mbit require 4-byte addressing */
#define MX25L_ADDRESSBYTES_3 3
#define MX25L_ADDRESSBYTES_4 4
#ifdef CONFIG_MX25L_SECTOR512 /* Simulate a 512 byte sector */
# define MX25L_SECTOR512_SHIFT 9 /* Sector size 1 << 9 = 512 bytes */
#endif
@ -122,24 +127,24 @@
#define CLR_DIRTY(p) do { (p)->flags &= ~MX25L_CACHE_DIRTY; } while (0)
#define CLR_ERASED(p) do { (p)->flags &= ~MX25L_CACHE_ERASED; } while (0)
/* MX25L Instructions *****************************************************************/
/* MX25L Instructions *******************************************************************/
/* Command Value Description Addr Data */
/* Dummy */
#define MX25L_READ 0x03 /* Read data bytes 3 0 >=1 */
#define MX25L_FAST_READ 0x0b /* Higher speed read 3 1 >=1 */
#define MX25L_READ 0x03 /* Read data bytes 3/4 0 >=1 */
#define MX25L_FAST_READ 0x0b /* Higher speed read 3/4 1 >=1 */
#define MX25L_2READ 0xbb /* 2 x I/O read command */
#define MX25L_DREAD 0x3b /* 1I / 2O read command 3 1 >=1 */
#define MX25L_DREAD 0x3b /* 1I / 2O read command 3/4 1 >=1 */
#define MX25L_4READ 0xeb /* 4 x I/O read command */
#define MX25L_QREAD 0x6b /* 1I / 4O read command 3 1 >=1 */
#define MX25L_QREAD 0x6b /* 1I / 4O read command 3/4 1 >=1 */
#define MX25L_WREN 0x06 /* Write Enable 0 0 0 */
#define MX25L_WRDI 0x04 /* Write Disable 0 0 0 */
#define MX25L_RDSR 0x05 /* Read status register 0 0 >=1 */
#define MX25L_RDCR 0x15 /* Read config register 0 0 >=1 */
#define MX25L_WRSR 0x01 /* Write stat/conf register 0 0 2 */
#define MX25L_4PP 0x38 /* Quad page program 3 0 1-256 */
#define MX25L_SE 0x20 /* 4Kb Sector erase 3 0 0 */
#define MX25L_BE32 0x52 /* 32Kbit block Erase 3 0 0 */
#define MX25L_BE64 0xd8 /* 64Kbit block Erase 3 0 0 */
#define MX25L_4PP 0x38 /* Quad page program 3/4 0 1-256 */
#define MX25L_SE 0x20 /* 4Kb Sector erase 3/4 0 0 */
#define MX25L_BE32 0x52 /* 32Kbit block Erase 3/4 0 0 */
#define MX25L_BE64 0xd8 /* 64Kbit block Erase 3/4 0 0 */
#define MX25L_CE 0xc7 /* Chip erase 0 0 0 */
#define MX25L_CE_ALT 0x60 /* Chip erase (alternate) 0 0 0 */
#define MX25L_PP 0x02 /* Page program 3 0 1-256 */
@ -158,6 +163,19 @@
#define MX25L_WRSCUR 0x2f /* Write security register 0 0 0 */
#define MX25L_RSTEN 0x66 /* Reset Enable 0 0 0 */
#define MX25L_RST 0x99 /* Reset Memory 0 0 0 */
#define MX25L_EN4B 0xb7 /* Enter 4-byte mode 0 0 0 */
#define MX25L_EX4B 0xe9 /* Exit 4-byte mode 0 0 0 */
#define MX25L_READ4B 0x13 /* Read data (4 Byte mode) 4 0 >=1 */
#define MX25L_FAST_READ4B 0x0c /* Higher speed read (4B) 4 1 >=1 */
#define MX25L_2READ4B 0xbc /* 2 x I/O read command (4B) */
#define MX25L_DREAD4B 0x3c /* 1I / 2O read command (4B) 4 1 >=1 */
#define MX25L_4READ4B 0xec /* 4 x I/O read command (4B) */
#define MX25L_QREAD4B 0x6c /* 1I / 4O read command (4B) 4 1 >=1 */
#define MX25L_4PP4B 0x3e /* Quad page program (4B) 4 0 1-256 */
#define MX25L_SE4B 0x21 /* 4Kb Sector erase (4B) 4 0 0 */
#define MX25L_BE32K4B 0x5c /* 32Kbit block Erase (4B) 4 0 0 */
#define MX25L_BE64K4B 0xdc /* 64Kbit block Erase (4B) 4 0 0 */
#define MX25L_PP4B 0x12 /* Page program (4B) 4 0 1-256 */
#define MX25L_RDSFDP 0x5a /* read out until CS# high */
#define MX25L_SBL 0xc0 /* Set Burst Length */
#define MX25L_SBL_ALT 0x77 /* Set Burst Length */
@ -186,7 +204,7 @@
#define MX25L_SR_QE (1 << 6) /* Bit 6: Quad enable */
#define MX25L_SR_SRWD (1 << 7) /* Bit 7: Status register write protect */
/* Configuration registerregister bit definitions */
/* Configuration register bit definitions */
#define MX25L_CR_ODS (1 << 0) /* Bit 0: Output driver strength */
#define MX25L_CR_TB (1 << 3) /* Bit 3: Top/bottom selected */
@ -219,6 +237,7 @@ struct mx25l_dev_s
FAR struct spi_dev_s *dev; /* Saved SPI interface instance */
uint8_t sectorshift;
uint8_t pageshift;
uint8_t addressbytes; /*Number of address bytes required */
uint16_t nsectors;
#if defined(CONFIG_MX25L_SECTOR512)
uint8_t flags; /* Buffered sector flags */
@ -352,6 +371,7 @@ static inline int mx25l_readid(FAR struct mx25l_dev_s *priv)
priv->sectorshift = MX25L_MX25L3233F_SECTOR_SHIFT;
priv->nsectors = MX25L_MX25L3233F_NSECTORS;
priv->pageshift = MX25L_MX25L3233F_PAGE_SHIFT;
priv->addressbytes = MX25L_ADDRESSBYTES_3;
return OK;
}
else if (capacity == MX25L_JEDEC_MX25L6433F_CAPACITY)
@ -361,6 +381,7 @@ static inline int mx25l_readid(FAR struct mx25l_dev_s *priv)
priv->sectorshift = MX25L_MX25L6433F_SECTOR_SHIFT;
priv->nsectors = MX25L_MX25L6433F_NSECTORS;
priv->pageshift = MX25L_MX25L6433F_PAGE_SHIFT;
priv->addressbytes = MX25L_ADDRESSBYTES_3;
return OK;
}
else if (capacity == MX25L_JEDEC_MX25L25635F_CAPACITY)
@ -370,6 +391,7 @@ static inline int mx25l_readid(FAR struct mx25l_dev_s *priv)
priv->sectorshift = MX25L_MX25L25635F_SECTOR_SHIFT;
priv->nsectors = MX25L_MX25L25635F_NSECTORS;
priv->pageshift = MX25L_MX25L25635F_PAGE_SHIFT;
priv->addressbytes = MX25L_ADDRESSBYTES_4;
return OK;
}
}
@ -488,6 +510,20 @@ static void mx25l_sectorerase(FAR struct mx25l_dev_s *priv, off_t sector)
* that was passed in as the erase type.
*/
/* The command we send varies depending on if we need 3 or 4 address bytes */
if (priv->addressbytes == MX25L_ADDRESSBYTES_4)
{
(void)SPI_SEND(priv->dev, MX25L_SE4B);
/* Send the sector offset high byte first. */
(void)SPI_SEND(priv->dev, (offset >> 24) & 0xff);
(void)SPI_SEND(priv->dev, (offset >> 16) & 0xff);
(void)SPI_SEND(priv->dev, (offset >> 8) & 0xff);
(void)SPI_SEND(priv->dev, offset & 0xff);
}
else
{
(void)SPI_SEND(priv->dev, MX25L_SE);
/* Send the sector offset high byte first. For all of the supported
@ -498,6 +534,7 @@ static void mx25l_sectorerase(FAR struct mx25l_dev_s *priv, off_t sector)
(void)SPI_SEND(priv->dev, (offset >> 16) & 0xff);
(void)SPI_SEND(priv->dev, (offset >> 8) & 0xff);
(void)SPI_SEND(priv->dev, offset & 0xff);
}
/* Deselect the FLASH */
@ -559,6 +596,23 @@ static void mx25l_byteread(FAR struct mx25l_dev_s *priv, FAR uint8_t *buffer,
SPI_SELECT(priv->dev, SPIDEV_FLASH(0), true);
/* The command we send varies depending on if we need 3 or 4 address bytes */
if (priv->addressbytes == MX25L_ADDRESSBYTES_4)
{
/* Send "Read from Memory - 4 byte mode" instruction */
(void)SPI_SEND(priv->dev, MX25L_FAST_READ4B);
/* Send the address high byte first. */
(void)SPI_SEND(priv->dev, (address >> 24) & 0xff);
(void)SPI_SEND(priv->dev, (address >> 16) & 0xff);
(void)SPI_SEND(priv->dev, (address >> 8) & 0xff);
(void)SPI_SEND(priv->dev, address & 0xff);
}
else
{
/* Send "Read from Memory " instruction */
(void)SPI_SEND(priv->dev, MX25L_FAST_READ);
@ -568,6 +622,7 @@ static void mx25l_byteread(FAR struct mx25l_dev_s *priv, FAR uint8_t *buffer,
(void)SPI_SEND(priv->dev, (address >> 16) & 0xff);
(void)SPI_SEND(priv->dev, (address >> 8) & 0xff);
(void)SPI_SEND(priv->dev, address & 0xff);
}
/* Send a dummy byte */
@ -602,6 +657,21 @@ static inline void mx25l_pagewrite(FAR struct mx25l_dev_s *priv,
SPI_SELECT(priv->dev, SPIDEV_FLASH(0), true);
if (priv->addressbytes == MX25L_ADDRESSBYTES_4)
{
/* Send the "Page Program - 4 byte mode (MX25L_PP4B)" Command */
SPI_SEND(priv->dev, MX25L_PP4B);
/* Send the address high byte first. */
(void)SPI_SEND(priv->dev, (address >> 24) & 0xff);
(void)SPI_SEND(priv->dev, (address >> 16) & 0xff);
(void)SPI_SEND(priv->dev, (address >> 8) & 0xff);
(void)SPI_SEND(priv->dev, address & 0xff);
}
else
{
/* Send the "Page Program (MX25L_PP)" Command */
SPI_SEND(priv->dev, MX25L_PP);
@ -611,7 +681,7 @@ static inline void mx25l_pagewrite(FAR struct mx25l_dev_s *priv,
(void)SPI_SEND(priv->dev, (address >> 16) & 0xff);
(void)SPI_SEND(priv->dev, (address >> 8) & 0xff);
(void)SPI_SEND(priv->dev, address & 0xff);
}
/* Then send the page of data */
SPI_SNDBLOCK(priv->dev, buffer, 1 << priv->pageshift);