kopia lustrzana https://github.com/OpenRTX/OpenRTX
Fix SPI Flash write function
rodzic
bfb1ad505f
commit
5f187bc76d
|
@ -233,7 +233,7 @@ bool W25Qx_writeData(uint32_t addr, void* buf, size_t len)
|
||||||
// If data in flash corresponds to the passed data, do not perform the write
|
// If data in flash corresponds to the passed data, do not perform the write
|
||||||
if(memcmp(buf, flashData, len) == 0)
|
if(memcmp(buf, flashData, len) == 0)
|
||||||
{
|
{
|
||||||
// Free the buffer buffer
|
// Free the buffer
|
||||||
free(flashData);
|
free(flashData);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -248,7 +248,7 @@ bool W25Qx_writeData(uint32_t addr, void* buf, size_t len)
|
||||||
W25Qx_readData(startBlockAddr, flashBlock, 4096);
|
W25Qx_readData(startBlockAddr, flashBlock, 4096);
|
||||||
uint32_t blockOffset = addr % 4096;
|
uint32_t blockOffset = addr % 4096;
|
||||||
// Overwrite changed portion
|
// Overwrite changed portion
|
||||||
memcpy(flashBlock + blockOffset, buf, len);
|
memcpy(&flashBlock[blockOffset], buf, len);
|
||||||
// Erase the 4K block
|
// Erase the 4K block
|
||||||
if(!W25Qx_eraseSector(startBlockAddr))
|
if(!W25Qx_eraseSector(startBlockAddr))
|
||||||
{
|
{
|
||||||
|
@ -259,7 +259,7 @@ bool W25Qx_writeData(uint32_t addr, void* buf, size_t len)
|
||||||
// Write back the modified 4K block in 256 bytes chunks
|
// Write back the modified 4K block in 256 bytes chunks
|
||||||
for(uint32_t offset = 0; offset < 4096; offset += 256)
|
for(uint32_t offset = 0; offset < 4096; offset += 256)
|
||||||
{
|
{
|
||||||
W25Qx_writePage(startBlockAddr + offset, flashBlock[offset], 256);
|
W25Qx_writePage(startBlockAddr + offset, &flashBlock[offset], 256);
|
||||||
}
|
}
|
||||||
// Free the 4K buffer
|
// Free the 4K buffer
|
||||||
free(flashBlock);
|
free(flashBlock);
|
||||||
|
|
Ładowanie…
Reference in New Issue