spi_flash: change argument types
spi_flash_read and spi_flash_write currently have a limitation that source and destination must be word-aligned. This can be fixed by adding code paths for various unaligned scenarios, but function signatures also need to be adjusted. As a first step (since we are pre-1.0 and can still change function signatures) alignment checks are added, and pointer types are relaxed to uint8_t. Later we will add handling of unaligned operations. This change also introduces spi_flash_erase_range and spi_flash_get_chip_size functions. We probably need something like spi_flash_chip_size_detect which will detect actual chip size. This is to allow single application binary to be used on a variety of boards and modules.
This commit is contained in:
@@ -30,7 +30,7 @@ TEST_CASE("flash starts with all bytes == 0xff", "[spi_flash_emu]")
|
||||
uint8_t sector[SPI_FLASH_SEC_SIZE];
|
||||
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
CHECK(spi_flash_read(0, reinterpret_cast<uint32_t*>(sector), sizeof(sector)) == ESP_OK);
|
||||
CHECK(spi_flash_read(0, sector, sizeof(sector)) == ESP_OK);
|
||||
for (auto v: sector) {
|
||||
CHECK(v == 0xff);
|
||||
}
|
||||
@@ -42,9 +42,9 @@ TEST_CASE("invalid writes are checked", "[spi_flash_emu]")
|
||||
SpiFlashEmulator emu(1);
|
||||
|
||||
uint32_t val = 0;
|
||||
CHECK(spi_flash_write(0, &val, 4) == ESP_OK);
|
||||
CHECK(spi_flash_write(0, reinterpret_cast<const uint8_t*>(&val), 4) == ESP_OK);
|
||||
val = 1;
|
||||
CHECK(spi_flash_write(0, &val, 4) == ESP_ERR_FLASH_OP_FAIL);
|
||||
CHECK(spi_flash_write(0, reinterpret_cast<const uint8_t*>(&val), 4) == ESP_ERR_FLASH_OP_FAIL);
|
||||
}
|
||||
|
||||
|
||||
@@ -53,11 +53,11 @@ TEST_CASE("out of bounds writes fail", "[spi_flash_emu]")
|
||||
SpiFlashEmulator emu(4);
|
||||
uint32_t vals[8];
|
||||
std::fill_n(vals, 8, 0);
|
||||
CHECK(spi_flash_write(0, vals, sizeof(vals)) == ESP_OK);
|
||||
CHECK(spi_flash_write(0, reinterpret_cast<const uint8_t*>(vals), sizeof(vals)) == ESP_OK);
|
||||
|
||||
CHECK(spi_flash_write(4*4096 - sizeof(vals), vals, sizeof(vals)) == ESP_OK);
|
||||
CHECK(spi_flash_write(4*4096 - sizeof(vals), reinterpret_cast<const uint8_t*>(vals), sizeof(vals)) == ESP_OK);
|
||||
|
||||
CHECK(spi_flash_write(4*4096 - sizeof(vals) + 4, vals, sizeof(vals)) == ESP_ERR_FLASH_OP_FAIL);
|
||||
CHECK(spi_flash_write(4*4096 - sizeof(vals) + 4, reinterpret_cast<const uint8_t*>(vals), sizeof(vals)) == ESP_ERR_FLASH_OP_FAIL);
|
||||
}
|
||||
|
||||
|
||||
@@ -65,9 +65,9 @@ TEST_CASE("after erase the sector is set to 0xff", "[spi_flash_emu]")
|
||||
{
|
||||
SpiFlashEmulator emu(4);
|
||||
uint32_t val1 = 0xab00cd12;
|
||||
CHECK(spi_flash_write(0, &val1, sizeof(val1)) == ESP_OK);
|
||||
CHECK(spi_flash_write(0, reinterpret_cast<const uint8_t*>(&val1), sizeof(val1)) == ESP_OK);
|
||||
uint32_t val2 = 0x5678efab;
|
||||
CHECK(spi_flash_write(4096 - 4, &val2, sizeof(val2)) == ESP_OK);
|
||||
CHECK(spi_flash_write(4096 - 4, reinterpret_cast<const uint8_t*>(&val2), sizeof(val2)) == ESP_OK);
|
||||
|
||||
CHECK(emu.words()[0] == val1);
|
||||
CHECK(range_empty_n(emu.words() + 1, 4096 / 4 - 2));
|
||||
@@ -83,7 +83,7 @@ TEST_CASE("after erase the sector is set to 0xff", "[spi_flash_emu]")
|
||||
TEST_CASE("read/write/erase operation times are calculated correctly", "[spi_flash_emu]")
|
||||
{
|
||||
SpiFlashEmulator emu(1);
|
||||
uint32_t data[128];
|
||||
uint8_t data[512];
|
||||
spi_flash_read(0, data, 4);
|
||||
CHECK(emu.getTotalTime() == 7);
|
||||
CHECK(emu.getReadOps() == 1);
|
||||
@@ -141,7 +141,7 @@ TEST_CASE("read/write/erase operation times are calculated correctly", "[spi_fla
|
||||
CHECK(emu.getTotalTime() == 37142);
|
||||
}
|
||||
|
||||
TEST_CASE("data is randomized predicatbly", "[spi_flash_emu]")
|
||||
TEST_CASE("data is randomized predictably", "[spi_flash_emu]")
|
||||
{
|
||||
SpiFlashEmulator emu1(3);
|
||||
emu1.randomize(0x12345678);
|
||||
|
||||
Reference in New Issue
Block a user