Skip to content

Commit

Permalink
Remove flash test code.
Browse files Browse the repository at this point in the history
  • Loading branch information
jakkra committed Oct 4, 2023
1 parent 1108985 commit 790040d
Showing 1 changed file with 0 additions and 59 deletions.
59 changes: 0 additions & 59 deletions app/src/zsw_flash.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,64 +17,6 @@ LOG_MODULE_REGISTER(zsw_flash, LOG_LEVEL_DBG);
#define SPI_FLASH_TEST_REGION_OFFSET 0xff000
#define SPI_FLASH_SECTOR_SIZE 4096

// Just to verify the HW. TODO use properly.
static void single_sector_test(const struct device *flash_dev)
{
const uint8_t expected[] = { 0x55, 0xaa, 0x66, 0x99 };
const size_t len = sizeof(expected);
uint8_t buf[sizeof(expected)];
int rc;

/* Write protection needs to be disabled before each write or
* erase, since the flash component turns on write protection
* automatically after completion of write and erase
* operations.
*/
LOG_DBG("Test 1: Flash erase");

/* Full flash erase if SPI_FLASH_TEST_REGION_OFFSET = 0 and
* SPI_FLASH_SECTOR_SIZE = flash size
*/
rc = flash_erase(flash_dev, SPI_FLASH_TEST_REGION_OFFSET,
SPI_FLASH_SECTOR_SIZE);
if (rc != 0) {
LOG_DBG("Flash erase failed! %d", rc);
} else {
LOG_DBG("Flash erase succeeded!");
}

LOG_DBG("Attempting to write %zu bytes", len);
rc = flash_write(flash_dev, SPI_FLASH_TEST_REGION_OFFSET, expected, len);
if (rc != 0) {
LOG_DBG("Flash write failed! %d", rc);
return;
}

memset(buf, 0, len);
rc = flash_read(flash_dev, SPI_FLASH_TEST_REGION_OFFSET, buf, len);
if (rc != 0) {
LOG_DBG("Flash read failed! %d", rc);
return;
}

if (memcmp(expected, buf, len) == 0) {
LOG_DBG("Data read matches data written. Good!!");
} else {
const uint8_t *wp = expected;
const uint8_t *rp = buf;
const uint8_t *rpe = rp + len;

LOG_DBG("Data read does not match data written!!");
while (rp < rpe) {
LOG_DBG("%08x wrote %02x read %02x %s",
(uint32_t)(SPI_FLASH_TEST_REGION_OFFSET + (rp - buf)),
*wp, *rp, (*rp == *wp) ? "match" : "MISMATCH");
++rp;
++wp;
}
}
}

static int zsw_flash_test(void)
{
const struct device *flash_dev = DEVICE_DT_GET_OR_NULL(DT_ALIAS(spi_flash0));
Expand All @@ -84,7 +26,6 @@ static int zsw_flash_test(void)
return 0;
}

single_sector_test(flash_dev);
return 0;
}

Expand Down

0 comments on commit 790040d

Please sign in to comment.