2016-11-17 08:36:10 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <freertos/FreeRTOS.h>
|
|
|
|
#include <freertos/task.h>
|
|
|
|
#include <freertos/semphr.h>
|
|
|
|
|
|
|
|
#include <unity.h>
|
|
|
|
#include <esp_spi_flash.h>
|
|
|
|
#include <esp_attr.h>
|
|
|
|
|
2017-01-05 04:51:02 +00:00
|
|
|
#include "test_config.h"
|
|
|
|
|
2016-11-17 08:36:10 +00:00
|
|
|
struct flash_test_ctx {
|
2017-01-18 07:07:27 +00:00
|
|
|
uint32_t offset;
|
|
|
|
bool fail;
|
2016-11-17 08:36:10 +00:00
|
|
|
SemaphoreHandle_t done;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void flash_test_task(void *arg)
|
|
|
|
{
|
|
|
|
struct flash_test_ctx *ctx = (struct flash_test_ctx *) arg;
|
|
|
|
vTaskDelay(100 / portTICK_PERIOD_MS);
|
2017-01-18 07:07:27 +00:00
|
|
|
const uint32_t sector = ctx->offset;
|
|
|
|
printf("t%d\n", sector);
|
|
|
|
printf("es%d\n", sector);
|
2016-11-17 08:36:10 +00:00
|
|
|
if (spi_flash_erase_sector(sector) != ESP_OK) {
|
2017-01-18 07:07:27 +00:00
|
|
|
ctx->fail = true;
|
|
|
|
printf("Erase failed\r\n");
|
2016-11-17 08:36:10 +00:00
|
|
|
xSemaphoreGive(ctx->done);
|
|
|
|
vTaskDelete(NULL);
|
|
|
|
}
|
2017-01-18 07:07:27 +00:00
|
|
|
printf("ed%d\n", sector);
|
2016-11-17 08:36:10 +00:00
|
|
|
|
|
|
|
vTaskDelay(0 / portTICK_PERIOD_MS);
|
|
|
|
|
|
|
|
uint32_t val = 0xabcd1234;
|
2017-01-05 04:51:02 +00:00
|
|
|
for (uint32_t offset = 0; offset < SPI_FLASH_SEC_SIZE; offset += 4) {
|
2016-11-17 08:36:10 +00:00
|
|
|
if (spi_flash_write(sector * SPI_FLASH_SEC_SIZE + offset, (const uint8_t *) &val, 4) != ESP_OK) {
|
2017-01-18 07:07:27 +00:00
|
|
|
printf("Write failed at offset=%d\r\n", offset);
|
|
|
|
ctx->fail = true;
|
2016-11-17 08:36:10 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2017-01-18 07:07:27 +00:00
|
|
|
printf("wd%d\n", sector);
|
2016-11-17 08:36:10 +00:00
|
|
|
|
|
|
|
vTaskDelay(0 / portTICK_PERIOD_MS);
|
|
|
|
|
|
|
|
uint32_t val_read;
|
2017-01-05 04:51:02 +00:00
|
|
|
for (uint32_t offset = 0; offset < SPI_FLASH_SEC_SIZE; offset += 4) {
|
2016-11-17 08:36:10 +00:00
|
|
|
if (spi_flash_read(sector * SPI_FLASH_SEC_SIZE + offset, (uint8_t *) &val_read, 4) != ESP_OK) {
|
2017-01-18 07:07:27 +00:00
|
|
|
printf("Read failed at offset=%d\r\n", offset);
|
|
|
|
ctx->fail = true;
|
2016-11-17 08:36:10 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (val_read != val) {
|
2017-01-18 07:07:27 +00:00
|
|
|
printf("Read invalid value=%08x at offset=%d\r\n", val_read, offset);
|
|
|
|
ctx->fail = true;
|
2016-11-17 08:36:10 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2017-01-18 07:07:27 +00:00
|
|
|
printf("td%d\n", sector);
|
2016-11-17 08:36:10 +00:00
|
|
|
xSemaphoreGive(ctx->done);
|
|
|
|
vTaskDelete(NULL);
|
|
|
|
}
|
|
|
|
|
2016-12-14 08:38:45 +00:00
|
|
|
TEST_CASE("flash write and erase work both on PRO CPU and on APP CPU", "[spi_flash][ignore]")
|
2016-11-17 08:36:10 +00:00
|
|
|
{
|
2017-01-18 07:07:27 +00:00
|
|
|
SemaphoreHandle_t done = xSemaphoreCreateCounting(4, 0);
|
2017-02-21 13:57:53 +00:00
|
|
|
struct flash_test_ctx ctx[] = {
|
2017-01-18 07:07:27 +00:00
|
|
|
{ .offset = 0x100 + 6, .done = done },
|
|
|
|
{ .offset = 0x100 + 7, .done = done },
|
|
|
|
{ .offset = 0x100 + 8, .done = done },
|
2017-02-21 13:57:53 +00:00
|
|
|
#ifndef CONFIG_FREERTOS_UNICORE
|
2017-01-18 07:07:27 +00:00
|
|
|
{ .offset = 0x100 + 9, .done = done }
|
2017-02-21 13:57:53 +00:00
|
|
|
#endif
|
2017-01-18 07:07:27 +00:00
|
|
|
};
|
2016-11-17 08:36:10 +00:00
|
|
|
|
2017-02-21 13:57:53 +00:00
|
|
|
xTaskCreatePinnedToCore(flash_test_task, "t0", 2048, &ctx[0], 3, NULL, 0);
|
|
|
|
xTaskCreatePinnedToCore(flash_test_task, "t1", 2048, &ctx[1], 3, NULL, tskNO_AFFINITY);
|
|
|
|
xTaskCreatePinnedToCore(flash_test_task, "t2", 2048, &ctx[2], 3, NULL, tskNO_AFFINITY);
|
|
|
|
#ifndef CONFIG_FREERTOS_UNICORE
|
|
|
|
xTaskCreatePinnedToCore(flash_test_task, "t3", 2048, &ctx[3], 3, NULL, 1);
|
|
|
|
#endif
|
2016-11-17 08:36:10 +00:00
|
|
|
|
2017-02-21 13:57:53 +00:00
|
|
|
const size_t task_count = sizeof(ctx)/sizeof(ctx[0]);
|
|
|
|
for (int i = 0; i < task_count; ++i) {
|
2017-01-18 07:07:27 +00:00
|
|
|
xSemaphoreTake(done, portMAX_DELAY);
|
|
|
|
TEST_ASSERT_FALSE(ctx[i].fail);
|
2016-11-17 08:36:10 +00:00
|
|
|
}
|
2017-01-18 07:07:27 +00:00
|
|
|
vSemaphoreDelete(done);
|
2016-11-17 08:36:10 +00:00
|
|
|
}
|
|
|
|
|