diff --git a/usb-loader/samba_applets/at91lib/memories/spi-flash/at45.c b/usb-loader/samba_applets/at91lib/memories/spi-flash/at45.c index 142e7ed3e0a2bfcc7ff74ecf5508995ef512d0a9..fd079e2c8d19c08380780a9385ce55d7c3b999cd 100644 --- a/usb-loader/samba_applets/at91lib/memories/spi-flash/at45.c +++ b/usb-loader/samba_applets/at91lib/memories/spi-flash/at45.c @@ -55,17 +55,20 @@ static unsigned char configuredBinaryPage; // Internal variables //------------------------------------------------------------------------------ + /// pageNumber, hasBinaryPage, pageSize, pageOffset, id, name, jedec + //TODO: Same density, use JEDEC instead and then check if new ID found. static const At45Desc at45Devices[] = { - { 512, 1, 264, 9, 0x0C, "AT45DB011D"}, - { 1024, 1, 264, 9, 0x14, "AT45DB021D"}, - { 2048, 1, 264, 9, 0x1C, "AT45DB041D"}, - { 4096, 1, 264, 9, 0x24, "AT45DB081D"}, - { 4096, 1, 528, 10, 0x2C, "AT45DB161D"}, - { 8192, 1, 528, 10, 0x34, "AT45DB321D"}, - { 8192, 1, 1056, 11, 0x3C, "AT45DB642D"}, - {16384, 1, 1056, 11, 0x10, "AT45DB1282"}, - {16384, 1, 2112, 12, 0x18, "AT45DB2562"}, - {32768, 1, 2112, 12, 0x20, "AT45DB5122"} + { 512, 1, 264, 9, 0x0C, "AT45DB011D",0}, + { 1024, 1, 264, 9, 0x14, "AT45DB021D",0}, + { 2048, 1, 264, 9, 0x1C, "AT45DB041D",0}, + { 4096, 1, 264, 9, 0x24, "AT45DB081D",0}, + { 4096, 1, 528, 10, 0x2C, "AT45DB161D",0}, + { 8192, 1, 528, 10, 0x34, "AT45DB321D",0}, + { 8192, 1, 1056, 11, 0x3C, "AT45DB642D",0x1F280000}, //v3.[0-3] + {16384, 1, 1056, 11, 0x10, "AT45DB1282",0}, + {16384, 1, 2112, 12, 0x18, "AT45DB2562",0}, + {32768, 1, 2112, 12, 0x20, "AT45DB5122",0}, + {32768, 1, 264, 9, 0x3C, "AT45DB641E",0x1F280001} //v3.[4-x] }; //------------------------------------------------------------------------------ @@ -144,8 +147,8 @@ unsigned char AT45_SendCommand( // Sanity checks ASSERT(pAt45, "AT45_Command: pAt45 is 0.\n\r"); - ASSERT(pDesc || (cmd == AT45_STATUS_READ), - "AT45_Command: Device has no descriptor, only STATUS_READ command allowed\n\r"); + ASSERT(pDesc || (cmd == AT45_STATUS_READ) || (cmd == AT45_ID_READ), + "AT45_Command: Device has no descriptor, only STATUS_READ & ID_READ command allowed\n\r"); // Check if the SPI driver is available if (AT45_IsBusy(pAt45)) { @@ -218,7 +221,7 @@ unsigned char AT45_SendCommand( //------------------------------------------------------------------------------ const At45Desc * AT45_FindDevice(At45 *pAt45, unsigned char status) { - unsigned int i; + unsigned int i, jedec; unsigned char id = AT45_STATUS_ID(status); // Check if status is all one; in which case, it is assumed that no device @@ -227,18 +230,39 @@ const At45Desc * AT45_FindDevice(At45 *pAt45, unsigned char status) return 0; } - - // Look in device array - i = 0; - pAt45->pDesc = 0; - while ((i < NUMDATAFLASH) && !(pAt45->pDesc)) { - - if (at45Devices[i].id == id) { - - pAt45->pDesc = &(at45Devices[i]); - } - i++; - } + + //AT45DB642D & AT45DB641E have same ID, using JEDEC + if (id == 0x3C) + { + jedec=AT45D_GetJEDEC(pAt45); + TRACE_INFO("\tJEDEC=0x%x\n\r",jedec); + + // Look in device array + i = 0; + pAt45->pDesc = 0; + while ((i < NUMDATAFLASH) && !(pAt45->pDesc)) { + + if ((at45Devices[i].id == id) && (at45Devices[i].jedec == jedec)) { + + pAt45->pDesc = &(at45Devices[i]); + } + i++; + } + } + else + { + // Look in device array + i = 0; + pAt45->pDesc = 0; + while ((i < NUMDATAFLASH) && !(pAt45->pDesc)) { + + if (at45Devices[i].id == id) { + + pAt45->pDesc = &(at45Devices[i]); + } + i++; + } + } configuredBinaryPage = AT45_STATUS_BINARY(status); return pAt45->pDesc; } diff --git a/usb-loader/samba_applets/at91lib/memories/spi-flash/at45.h b/usb-loader/samba_applets/at91lib/memories/spi-flash/at45.h index ef7ef26ba371052a337ef34b031594bc258052da..1ee09b7d527908f33d0f47de582a5a6c080c0022 100644 --- a/usb-loader/samba_applets/at91lib/memories/spi-flash/at45.h +++ b/usb-loader/samba_applets/at91lib/memories/spi-flash/at45.h @@ -206,6 +206,8 @@ typedef struct { unsigned char id; /// Identifier. const char *name; + /// JEDEC (Optional). + unsigned int jedec; } At45Desc; diff --git a/usb-loader/samba_applets/at91lib/memories/spi-flash/at45d.c b/usb-loader/samba_applets/at91lib/memories/spi-flash/at45d.c index f7eab1491741045ca164ebacd78a0d4560e55d46..8c078087991475336f5546065935217bb3938918 100644 --- a/usb-loader/samba_applets/at91lib/memories/spi-flash/at45d.c +++ b/usb-loader/samba_applets/at91lib/memories/spi-flash/at45d.c @@ -105,6 +105,42 @@ unsigned char AT45D_GetStatus(At45 *pAt45) return status; } + +//------------------------------------------------------------------------------ +/// Retrieves and returns the At45 JEDEC code into a unsigned int, or 0 if an error +/// happened. +/// \param pAt45 Pointer to a At45 driver instance. +//------------------------------------------------------------------------------ +unsigned int AT45D_GetJEDEC(At45 *pAt45) +{ + unsigned char error; + unsigned char buff[4]={0}; + unsigned int id; + + + SANITY_CHECK(pAt45); + + // Issue a status register read command + error = AT45_SendCommand(pAt45, AT45_ID_READ, 1, &buff, 4, 0, 0, 0); + ASSERT(!error, "-F- AT45_GetJEDEC: Failed to issue command.\n\r"); + + // Wait for command to terminate + while (AT45_IsBusy(pAt45)) { + + AT45D_Wait(pAt45); + } + + //Swap byte (BE to LE) to fit JEDEC u32 format + id=0; + id |= ((buff[0] & 0xFF) << 24); + id |= ((buff[1] & 0xFF) << 16); + id |= ((buff[2] & 0xFF) << 8) ; + id |= ((buff[3] & 0xFF) <<0 ) ; + + return id; +} + + //------------------------------------------------------------------------------ /// Reads data from the At45 inside the provided buffer. Since a continuous /// read command is used, there is no restriction on the buffer size and read diff --git a/usb-loader/samba_applets/at91lib/memories/spi-flash/at45d.h b/usb-loader/samba_applets/at91lib/memories/spi-flash/at45d.h index b5124459bde9710f12bd04455eba44a744373fbb..3a69ee2e8fe9949550f214ac2f711480b514d012 100644 --- a/usb-loader/samba_applets/at91lib/memories/spi-flash/at45d.h +++ b/usb-loader/samba_applets/at91lib/memories/spi-flash/at45d.h @@ -65,6 +65,7 @@ extern void AT45D_WaitReady(At45 *pAt45); extern unsigned char AT45D_GetStatus(At45 *pAt45); +extern unsigned int AT45D_GetJEDEC(At45 *pAt45); extern void AT45D_Read( At45 *pAt45, diff --git a/usb-loader/samba_applets/isp-dataflash-at91sam9g45.bin b/usb-loader/samba_applets/isp-dataflash-at91sam9g45.bin index fb18c7d6bf747bc8febdf7ded0374b717038732a..a57117aae521a2fcd6b0e0def90d6ee83489fbb3 100755 Binary files a/usb-loader/samba_applets/isp-dataflash-at91sam9g45.bin and b/usb-loader/samba_applets/isp-dataflash-at91sam9g45.bin differ