Commit 71df0536 authored by Benoit Rat's avatar Benoit Rat Committed by Alessandro Rubini

usb-loader: update to write in new AT45DB641E

AT45DB642D is now obsolete and AT45DB641E will replace it
They have the same status ID (same density). Therefore we need to read
the JEDEC code instead.
parent 7aa7aef1
......@@ -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;
}
......
......@@ -206,6 +206,8 @@ typedef struct {
unsigned char id;
/// Identifier.
const char *name;
/// JEDEC (Optional).
unsigned int jedec;
} At45Desc;
......
......@@ -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
......
......@@ -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,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment