kopia lustrzana https://github.com/OpenRTX/OpenRTX
Improved SPI Flash overwrite test
rodzic
29b56f8dbd
commit
bfb1ad505f
|
@ -18,13 +18,15 @@
|
||||||
* along with this program; if not, see <http://www.gnu.org/licenses/> *
|
* along with this program; if not, see <http://www.gnu.org/licenses/> *
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
|
// ####### DISCLAIMER #########
|
||||||
|
// This test overwrites a portion of the SPI flash memory
|
||||||
|
// Run this only if you know what you are doing!
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include "W25Qx.h"
|
#include "W25Qx.h"
|
||||||
|
|
||||||
uint8_t block[256] = {0};
|
|
||||||
|
|
||||||
void printChunk(void *chunk)
|
void printChunk(void *chunk)
|
||||||
{
|
{
|
||||||
uint8_t *ptr = ((uint8_t *) chunk);
|
uint8_t *ptr = ((uint8_t *) chunk);
|
||||||
|
@ -41,30 +43,62 @@ int main()
|
||||||
W25Qx_init();
|
W25Qx_init();
|
||||||
W25Qx_wakeup();
|
W25Qx_wakeup();
|
||||||
|
|
||||||
|
uint8_t testData[16] = {0};
|
||||||
|
uint8_t buffer[256] = {0};
|
||||||
|
|
||||||
while(1)
|
while(1)
|
||||||
{
|
{
|
||||||
getchar();
|
getchar();
|
||||||
|
|
||||||
// On UV380 flash at 0x5F60 there are 36032 bytes of 0xFF
|
// On UV380 flash at 0x6000 there are 36032 bytes of 0xFF
|
||||||
uint32_t addr = 0x5F60;
|
uint32_t addr = 0x6000;
|
||||||
printf("Read memory @ 0x5F60\r\n");
|
printf("Read memory @ 0x%x\r\n", addr);
|
||||||
W25Qx_readData(addr, block, 256);
|
W25Qx_readData(addr, buffer, 256);
|
||||||
for (int offset = 0; offset < 256; offset += 16)
|
for (int offset = 0; offset < 256; offset += 16)
|
||||||
{
|
{
|
||||||
printf("\r\n%lx: ", addr + offset);
|
printf("\r\n%lx: ", addr + offset);
|
||||||
printChunk(block + offset);
|
printChunk(buffer + offset);
|
||||||
}
|
}
|
||||||
block[3] = 0xAA;
|
// Prepare test data
|
||||||
printf("\r\nWrite memory @ 0x5F60... ");
|
for(int i = 0; i < 16; i++)
|
||||||
bool success = W25Qx_writeData(addr, block, 16);
|
{
|
||||||
|
testData[i] = 'a' + (i % 16);
|
||||||
|
}
|
||||||
|
printf("\r\nOverwrite memory @ 0x6000... ");
|
||||||
|
bool success = W25Qx_writeData(addr, testData, 16);
|
||||||
printf("%s\r\n", success ? "success" : "failed");
|
printf("%s\r\n", success ? "success" : "failed");
|
||||||
|
|
||||||
printf("Read memory @ 0x5F60\r\n");
|
printf("Read memory @ 0x%x\r\n", addr);
|
||||||
W25Qx_readData(addr, block, 256);
|
W25Qx_readData(addr, buffer, 256);
|
||||||
for (int offset = 0; offset < 256; offset += 16)
|
for (int offset = 0; offset < 256; offset += 16)
|
||||||
{
|
{
|
||||||
printf("\r\n%lx: ", addr + offset);
|
printf("\r\n%lx: ", addr + offset);
|
||||||
printChunk(block + offset);
|
printChunk(buffer + offset);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t blockAddr = addr / 4096 * 4096;
|
||||||
|
printf("\r\nErase memory @ 0x%x... ", blockAddr);
|
||||||
|
success = W25Qx_eraseSector(blockAddr);
|
||||||
|
printf("%s\r\n", success ? "success" : "failed");
|
||||||
|
|
||||||
|
printf("Read memory @ 0x%x\r\n", addr);
|
||||||
|
W25Qx_readData(addr, buffer, 256);
|
||||||
|
for (int offset = 0; offset < 256; offset += 16)
|
||||||
|
{
|
||||||
|
printf("\r\n%lx: ", addr + offset);
|
||||||
|
printChunk(buffer + offset);
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("\r\nWrite memory @ 0x%x... ", addr);
|
||||||
|
success = W25Qx_writePage(addr, testData, 16);
|
||||||
|
printf("%s\r\n", success ? "success" : "failed");
|
||||||
|
|
||||||
|
printf("Read memory @ 0x%x\r\n", addr);
|
||||||
|
W25Qx_readData(addr, buffer, 256);
|
||||||
|
for (int offset = 0; offset < 256; offset += 16)
|
||||||
|
{
|
||||||
|
printf("\r\n%lx: ", addr + offset);
|
||||||
|
printChunk(buffer + offset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue