Skip to content

Commit

Permalink
Update flash tools to support winbond W25Q128JW flash chips
Browse files Browse the repository at this point in the history
  • Loading branch information
mmarn authored and zioven committed Mar 7, 2024
1 parent 963db85 commit cdb57cd
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
45 changes: 43 additions & 2 deletions mrfCommon/src/flash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,19 @@ CFIFlash::readID(ID *id)
}
}
}
else if(id->vendor == 0xef)
{
id->vendorName = "Winbond";

switch(id->dev_type) {
case 0x60: // W25Q128JW-IQ
case 0x80: // W25Q128JW-IM
id->capacity = 1u<<(id->dev_id);
id->sectorSize = 256*16u;
id->pageSize = 256;
break;
}
}

// we only use 24-bit read/write/erase ops
// so capacity beyond 16MB is not accessible.
Expand Down Expand Up @@ -182,6 +195,20 @@ void CFIFlash::write(const epicsUInt32 start,
throw std::runtime_error("end address not aligned to page & sector sizes");
}

epicsUInt8 sectorEraseCmd;
if (strcmp(info.vendorName, "Micron") == 0)
{
sectorEraseCmd = 0xd8; // SECTOR ERASE
}
else if (strcmp(info.vendorName, "Winbond") == 0)
{
sectorEraseCmd = 0x20; // SECTOR ERASE
}
else
{
throw std::runtime_error("unknown vendor name");
}

const epicsUInt32 end = start+count;

const double timeout = dev.interface()->timeout();
Expand All @@ -198,7 +225,7 @@ void CFIFlash::write(const epicsUInt32 start,
WE.enable();

epicsUInt8 cmd[4];
cmd[0] = 0xd8; // SECTOR ERASE
cmd[0] = sectorEraseCmd;
cmd[1] = (addr>>16)&0xff;
cmd[2] = (addr>> 8)&0xff;
cmd[3] = (addr>> 0)&0xff;
Expand Down Expand Up @@ -296,6 +323,20 @@ void CFIFlash::erase(epicsUInt32 start, epicsUInt32 count, bool strict)
throw std::runtime_error("end address not aligned to page & sector sizes");
}

epicsUInt8 sectorEraseCmd;
if (strcmp(info.vendorName, "Micron") == 0)
{
sectorEraseCmd = 0xd8; // SECTOR ERASE
}
else if (strcmp(info.vendorName, "Winbond") == 0)
{
sectorEraseCmd = 0x20; // SECTOR ERASE
}
else
{
throw std::runtime_error("unknown vendor name");
}

const epicsUInt32 end = start+count;

const double timeout = dev.interface()->timeout();
Expand All @@ -311,7 +352,7 @@ void CFIFlash::erase(epicsUInt32 start, epicsUInt32 count, bool strict)
WE.enable();

epicsUInt8 cmd[4];
cmd[0] = 0xd8; // SECTOR ERASE
cmd[0] = sectorEraseCmd;
cmd[1] = (addr>>16)&0xff;
cmd[2] = (addr>> 8)&0xff;
cmd[3] = (addr>> 0)&0xff;
Expand Down
3 changes: 2 additions & 1 deletion mrfCommon/src/mrf/flash.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,15 @@ class epicsShareClass CFIFlash
struct ID {
/* vendors
* 0x20 - Micron
* 0xef - Winbond
*/
epicsUInt8 vendor,
dev_type,
dev_id;

const char *vendorName;
epicsUInt32 capacity, //!< total capacity in bytes
sectorSize, //!< SECTOR ERASE (0xd8) size in bytes. Always a power of 2
sectorSize, //!< SECTOR ERASE (0xd8 / 0x20) size in bytes. Always a power of 2
pageSize; //!< PAGE PROGRAM (0x02) size in bytes. Always a power of 2

std::vector<epicsUInt8> SN;
Expand Down

0 comments on commit cdb57cd

Please sign in to comment.