Merge branch 'feature/spi_flash_enable_counters_on_esp_flash_driver' into 'master'

spi_flash: support  SPI_FLASH_ENABLE_COUNTERS on esp_flash driver and test this feature

Closes IDF-5623

See merge request espressif/esp-idf!19554
This commit is contained in:
Wan Lei
2023-04-06 15:48:42 +08:00
13 changed files with 211 additions and 101 deletions

View File

@@ -26,14 +26,14 @@ TEST_CASE("Test erase partition", "[spi_flash][esp_flash]")
const esp_partition_t *part = get_test_data_partition(); const esp_partition_t *part = get_test_data_partition();
#if CONFIG_SPI_FLASH_ENABLE_COUNTERS #if CONFIG_SPI_FLASH_ENABLE_COUNTERS
spi_flash_reset_counters(); esp_flash_reset_counters();
#endif #endif
// erase whole partition // erase whole partition
ESP_ERROR_CHECK( esp_partition_erase_range(part, 0, part->size) ); ESP_ERROR_CHECK( esp_partition_erase_range(part, 0, part->size) );
#if CONFIG_SPI_FLASH_ENABLE_COUNTERS #if CONFIG_SPI_FLASH_ENABLE_COUNTERS
spi_flash_dump_counters(); esp_flash_dump_counters(stdout);
#endif #endif
// put some dummy data on sector boundaries // put some dummy data on sector boundaries

View File

@@ -35,13 +35,13 @@ menu "SPI Flash driver"
config SPI_FLASH_ENABLE_COUNTERS config SPI_FLASH_ENABLE_COUNTERS
bool "Enable operation counters" bool "Enable operation counters"
default 0 default n
help help
This option enables the following APIs: This option enables the following APIs:
- spi_flash_reset_counters - esp_flash_reset_counters
- spi_flash_dump_counters - esp_flash_dump_counters
- spi_flash_get_counters - esp_flash_get_counters
These APIs may be used to collect performance data for spi_flash APIs These APIs may be used to collect performance data for spi_flash APIs
and to help understand behaviour of libraries which use SPI flash. and to help understand behaviour of libraries which use SPI flash.

View File

@@ -19,6 +19,9 @@
#include "spi_flash_mmap.h" #include "spi_flash_mmap.h"
#include "esp_rom_caps.h" #include "esp_rom_caps.h"
#include "esp_rom_spiflash.h" #include "esp_rom_spiflash.h"
#include "esp_private/esp_clk.h"
#include "esp_spi_flash_counters.h"
#if CONFIG_IDF_TARGET_ESP32S2 #if CONFIG_IDF_TARGET_ESP32S2
#include "esp_crypto_lock.h" // for locking flash encryption peripheral #include "esp_crypto_lock.h" // for locking flash encryption peripheral
#endif //CONFIG_IDF_TARGET_ESP32S2 #endif //CONFIG_IDF_TARGET_ESP32S2
@@ -65,6 +68,66 @@ DRAM_ATTR static const char TAG[] = "spi_flash";
} \ } \
} while (0) } while (0)
#if CONFIG_SPI_FLASH_ENABLE_COUNTERS
static esp_flash_counters_t esp_flash_stats;
#define COUNTER_START() uint32_t ts_begin = esp_cpu_get_cycle_count()
#define COUNTER_STOP(counter) \
do{ \
esp_flash_stats.counter.count++; \
esp_flash_stats.counter.time += (esp_cpu_get_cycle_count() - ts_begin) / (esp_clk_cpu_freq() / 1000000); \
} while(0)
#define COUNTER_ADD_BYTES(counter, size) \
do { \
esp_flash_stats.counter.bytes += size; \
} while (0)
const esp_flash_counters_t *esp_flash_get_counters(void)
{
return &esp_flash_stats;
}
void esp_flash_reset_counters(void)
{
memset(&esp_flash_stats, 0, sizeof(esp_flash_stats));
}
void esp_flash_dump_counters(FILE* stream)
{
if (stream != NULL) {
fprintf(stream, " read: count=%8ld time=%8ldus bytes=%8ld\n", esp_flash_stats.read.count, esp_flash_stats.read.time, esp_flash_stats.read.bytes);
fprintf(stream, "write: count=%8ld time=%8ldus bytes=%8ld\n", esp_flash_stats.write.count, esp_flash_stats.write.time, esp_flash_stats.write.bytes);
fprintf(stream, "erase: count=%8ld time=%8ldus bytes=%8ld\n", esp_flash_stats.erase.count, esp_flash_stats.erase.time, esp_flash_stats.erase.bytes);
}
}
const spi_flash_counters_t *spi_flash_get_counters(void)
{
return (spi_flash_counters_t *)esp_flash_get_counters();
}
void spi_flash_reset_counters(void)
{
esp_flash_reset_counters();
}
void spi_flash_dump_counters(void)
{
esp_flash_dump_counters(stdout);
}
#else
#define COUNTER_START()
#define COUNTER_STOP(counter)
#define COUNTER_ADD_BYTES(counter, size)
#endif //CONFIG_SPI_FLASH_ENABLE_COUNTERS
#define IO_STR_LEN 10 #define IO_STR_LEN 10
static const char io_mode_str[][IO_STR_LEN] = { static const char io_mode_str[][IO_STR_LEN] = {
@@ -534,6 +597,8 @@ esp_err_t IRAM_ATTR esp_flash_erase_region(esp_flash_t *chip, uint32_t start, ui
uint32_t block_erase_size = chip->chip_drv->erase_block == NULL ? 0 : chip->chip_drv->block_erase_size; uint32_t block_erase_size = chip->chip_drv->erase_block == NULL ? 0 : chip->chip_drv->block_erase_size;
uint32_t sector_size = chip->chip_drv->sector_size; uint32_t sector_size = chip->chip_drv->sector_size;
COUNTER_START();
if (sector_size == 0 || (block_erase_size % sector_size) != 0) { if (sector_size == 0 || (block_erase_size % sector_size) != 0) {
return ESP_ERR_FLASH_NOT_INITIALISED; return ESP_ERR_FLASH_NOT_INITIALISED;
} }
@@ -600,6 +665,7 @@ esp_err_t IRAM_ATTR esp_flash_erase_region(esp_flash_t *chip, uint32_t start, ui
err = chip->chip_drv->erase_block(chip, erase_addr); err = chip->chip_drv->erase_block(chip, erase_addr);
erase_addr += block_erase_size; erase_addr += block_erase_size;
len_remain -= block_erase_size; len_remain -= block_erase_size;
COUNTER_ADD_BYTES(erase, block_erase_size);
} else } else
#endif #endif
{ {
@@ -607,6 +673,7 @@ esp_err_t IRAM_ATTR esp_flash_erase_region(esp_flash_t *chip, uint32_t start, ui
err = chip->chip_drv->erase_sector(chip, erase_addr); err = chip->chip_drv->erase_sector(chip, erase_addr);
erase_addr += sector_size; erase_addr += sector_size;
len_remain -= sector_size; len_remain -= sector_size;
COUNTER_ADD_BYTES(erase, sector_size);
} }
assert(len_remain < len); assert(len_remain < len);
@@ -626,6 +693,8 @@ esp_err_t IRAM_ATTR esp_flash_erase_region(esp_flash_t *chip, uint32_t start, ui
bus_acquired = false; bus_acquired = false;
} }
COUNTER_STOP(erase);
return rom_spiflash_api_funcs->flash_end_flush_cache(chip, err, bus_acquired, start, len); return rom_spiflash_api_funcs->flash_end_flush_cache(chip, err, bus_acquired, start, len);
} }
@@ -811,6 +880,8 @@ esp_err_t IRAM_ATTR esp_flash_read(esp_flash_t *chip, void *buffer, uint32_t add
} }
} }
COUNTER_START();
err = ESP_OK; err = ESP_OK;
do { do {
err = rom_spiflash_api_funcs->start(chip); err = rom_spiflash_api_funcs->start(chip);
@@ -840,11 +911,14 @@ esp_err_t IRAM_ATTR esp_flash_read(esp_flash_t *chip, void *buffer, uint32_t add
address += length_to_read; address += length_to_read;
length -= length_to_read; length -= length_to_read;
buffer = (void*)((intptr_t)buffer + length_to_read); buffer = (void*)((intptr_t)buffer + length_to_read);
COUNTER_ADD_BYTES(read, length_to_read);
} while (err == ESP_OK && length > 0); } while (err == ESP_OK && length > 0);
if (chip->os_func->release_temp_buffer != NULL) { if (chip->os_func->release_temp_buffer != NULL) {
chip->os_func->release_temp_buffer(chip->os_func_data, temp_buffer); chip->os_func->release_temp_buffer(chip->os_func_data, temp_buffer);
} }
COUNTER_STOP(read);
return err; return err;
} }
@@ -953,6 +1027,9 @@ esp_err_t IRAM_ATTR esp_flash_write(esp_flash_t *chip, const void *buffer, uint3
// Indicate whether the bus is acquired by the driver, needs to be released before return // Indicate whether the bus is acquired by the driver, needs to be released before return
bool bus_acquired = false; bool bus_acquired = false;
err = ESP_OK; err = ESP_OK;
COUNTER_START();
/* Write output in chunks, either by buffering on stack or /* Write output in chunks, either by buffering on stack or
by artificially cutting into MAX_WRITE_CHUNK parts (in an OS by artificially cutting into MAX_WRITE_CHUNK parts (in an OS
environment, this prevents writing from causing interrupt or higher priority task environment, this prevents writing from causing interrupt or higher priority task
@@ -997,6 +1074,7 @@ esp_err_t IRAM_ATTR esp_flash_write(esp_flash_t *chip, const void *buffer, uint3
err = chip->chip_drv->write(chip, write_buf, write_addr, write_len); err = chip->chip_drv->write(chip, write_buf, write_addr, write_len);
len_remain -= write_len; len_remain -= write_len;
assert(len_remain < length); assert(len_remain < length);
COUNTER_ADD_BYTES(write, write_len);
if (err != ESP_OK) { if (err != ESP_OK) {
//Error happens, we end flash operation. Re-enable cache and flush it //Error happens, we end flash operation. Re-enable cache and flush it
@@ -1028,12 +1106,13 @@ esp_err_t IRAM_ATTR esp_flash_write(esp_flash_t *chip, const void *buffer, uint3
buffer = (void *)((intptr_t)buffer + write_len); buffer = (void *)((intptr_t)buffer + write_len);
} }
COUNTER_STOP(write);
err = rom_spiflash_api_funcs->flash_end_flush_cache(chip, err, bus_acquired, address, length); err = rom_spiflash_api_funcs->flash_end_flush_cache(chip, err, bus_acquired, address, length);
return err; return err;
restore_cache: restore_cache:
COUNTER_STOP(write);
ret = rom_spiflash_api_funcs->flash_end_flush_cache(chip, err, bus_acquired, address, length); ret = rom_spiflash_api_funcs->flash_end_flush_cache(chip, err, bus_acquired, address, length);
if (ret != ESP_OK) { if (ret != ESP_OK) {
ESP_DRAM_LOGE(TAG, "restore cache fail\n"); ESP_DRAM_LOGE(TAG, "restore cache fail\n");
@@ -1078,6 +1157,8 @@ esp_err_t IRAM_ATTR esp_flash_write_encrypted(esp_flash_t *chip, uint32_t addres
const uint8_t *ssrc = (const uint8_t *)buffer; const uint8_t *ssrc = (const uint8_t *)buffer;
COUNTER_START();
/* On ESP32, write_encrypted encrypts data in RAM as it writes, /* On ESP32, write_encrypted encrypts data in RAM as it writes,
so copy to a temporary buffer - 32 bytes at a time. so copy to a temporary buffer - 32 bytes at a time.
@@ -1168,6 +1249,7 @@ esp_err_t IRAM_ATTR esp_flash_write_encrypted(esp_flash_t *chip, uint32_t addres
goto restore_cache; goto restore_cache;
} }
err = rom_spiflash_api_funcs->end(chip, ESP_OK); err = rom_spiflash_api_funcs->end(chip, ESP_OK);
COUNTER_ADD_BYTES(write, encrypt_byte);
#if CONFIG_IDF_TARGET_ESP32S2 #if CONFIG_IDF_TARGET_ESP32S2
esp_crypto_dma_lock_release(); esp_crypto_dma_lock_release();
#endif //CONFIG_IDF_TARGET_ESP32S2 #endif //CONFIG_IDF_TARGET_ESP32S2
@@ -1187,12 +1269,13 @@ esp_err_t IRAM_ATTR esp_flash_write_encrypted(esp_flash_t *chip, uint32_t addres
#endif //CONFIG_SPI_FLASH_VERIFY_WRITE #endif //CONFIG_SPI_FLASH_VERIFY_WRITE
} }
COUNTER_STOP(write);
err = rom_spiflash_api_funcs->flash_end_flush_cache(chip, err, bus_acquired, address, length); err = rom_spiflash_api_funcs->flash_end_flush_cache(chip, err, bus_acquired, address, length);
return err; return err;
restore_cache: restore_cache:
COUNTER_STOP(write);
ret = rom_spiflash_api_funcs->flash_end_flush_cache(chip, err, bus_acquired, address, length); ret = rom_spiflash_api_funcs->flash_end_flush_cache(chip, err, bus_acquired, address, length);
if (ret != ESP_OK) { if (ret != ESP_OK) {
ESP_DRAM_LOGE(TAG, "restore cache fail\n"); ESP_DRAM_LOGE(TAG, "restore cache fail\n");
@@ -1222,6 +1305,7 @@ esp_err_t IRAM_ATTR esp_flash_read_encrypted(esp_flash_t *chip, uint32_t address
return ESP_ERR_INVALID_ARG; return ESP_ERR_INVALID_ARG;
} }
COUNTER_START();
const uint8_t *map; const uint8_t *map;
spi_flash_mmap_handle_t map_handle; spi_flash_mmap_handle_t map_handle;
size_t map_src = address & ~(SPI_FLASH_MMU_PAGE_SIZE - 1); size_t map_src = address & ~(SPI_FLASH_MMU_PAGE_SIZE - 1);
@@ -1233,6 +1317,9 @@ esp_err_t IRAM_ATTR esp_flash_read_encrypted(esp_flash_t *chip, uint32_t address
} }
memcpy(out_buffer, map + (address - map_src), length); memcpy(out_buffer, map + (address - map_src), length);
spi_flash_munmap(map_handle); spi_flash_munmap(map_handle);
COUNTER_ADD_BYTES(read, length);
COUNTER_STOP(read);
return err; return err;
} }

View File

@@ -439,7 +439,7 @@ esp_err_t esp_flash_app_init(void)
spi_flash_init_lock(); spi_flash_init_lock();
spi_flash_guard_set(&g_flash_guard_default_ops); spi_flash_guard_set(&g_flash_guard_default_ops);
#if CONFIG_SPI_FLASH_ENABLE_COUNTERS #if CONFIG_SPI_FLASH_ENABLE_COUNTERS
spi_flash_reset_counters(); esp_flash_reset_counters();
#endif #endif
#if CONFIG_SPI_FLASH_SHARE_SPI1_BUS #if CONFIG_SPI_FLASH_SHARE_SPI1_BUS
err = esp_flash_init_main_bus_lock(); err = esp_flash_init_main_bus_lock();

View File

@@ -77,28 +77,6 @@
static const char *TAG __attribute__((unused)) = "spi_flash"; static const char *TAG __attribute__((unused)) = "spi_flash";
#if CONFIG_SPI_FLASH_ENABLE_COUNTERS
static spi_flash_counters_t s_flash_stats;
#define COUNTER_START() uint32_t ts_begin = esp_cpu_get_cycle_count()
#define COUNTER_STOP(counter) \
do{ \
s_flash_stats.counter.count++; \
s_flash_stats.counter.time += (esp_cpu_get_cycle_count() - ts_begin) / (esp_clk_cpu_freq() / 1000000); \
} while(0)
#define COUNTER_ADD_BYTES(counter, size) \
do { \
s_flash_stats.counter.bytes += size; \
} while (0)
#else
#define COUNTER_START()
#define COUNTER_STOP(counter)
#define COUNTER_ADD_BYTES(counter, size)
#endif //CONFIG_SPI_FLASH_ENABLE_COUNTERS
const DRAM_ATTR spi_flash_guard_funcs_t g_flash_guard_default_ops = { const DRAM_ATTR spi_flash_guard_funcs_t g_flash_guard_default_ops = {
.start = spi_flash_disable_interrupts_caches_and_other_cpu, .start = spi_flash_disable_interrupts_caches_and_other_cpu,
.end = spi_flash_enable_interrupts_caches_and_other_cpu, .end = spi_flash_enable_interrupts_caches_and_other_cpu,
@@ -197,33 +175,6 @@ esp_err_t IRAM_ATTR spi_flash_init_chip_state(void)
} }
} }
#if CONFIG_SPI_FLASH_ENABLE_COUNTERS
static inline void dump_counter(spi_flash_counter_t *counter, const char *name)
{
ESP_LOGI(TAG, "%s count=%8d time=%8dus bytes=%8d\n", name,
counter->count, counter->time, counter->bytes);
}
const spi_flash_counters_t *spi_flash_get_counters(void)
{
return &s_flash_stats;
}
void spi_flash_reset_counters(void)
{
memset(&s_flash_stats, 0, sizeof(s_flash_stats));
}
void spi_flash_dump_counters(void)
{
dump_counter(&s_flash_stats.read, "read ");
dump_counter(&s_flash_stats.write, "write");
dump_counter(&s_flash_stats.erase, "erase");
}
#endif //CONFIG_SPI_FLASH_ENABLE_COUNTERS
void IRAM_ATTR spi_flash_set_rom_required_regs(void) void IRAM_ATTR spi_flash_set_rom_required_regs(void)
{ {
#if SOC_SPI_MEM_SUPPORT_OPI_MODE #if SOC_SPI_MEM_SUPPORT_OPI_MODE

View File

@@ -1,16 +1,8 @@
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD /*
// * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
// Licensed under the Apache License, Version 2.0 (the "License"); *
// you may not use this file except in compliance with the License. * SPDX-License-Identifier: Apache-2.0
// You may obtain a copy of the License at */
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once #pragma once
@@ -32,31 +24,38 @@ typedef struct {
uint32_t count; // number of times operation was executed uint32_t count; // number of times operation was executed
uint32_t time; // total time taken, in microseconds uint32_t time; // total time taken, in microseconds
uint32_t bytes; // total number of bytes uint32_t bytes; // total number of bytes
} spi_flash_counter_t; } esp_flash_counter_t;
typedef struct { typedef struct {
spi_flash_counter_t read; esp_flash_counter_t read;
spi_flash_counter_t write; esp_flash_counter_t write;
spi_flash_counter_t erase; esp_flash_counter_t erase;
} spi_flash_counters_t; } esp_flash_counters_t;
// for deprecate old api
typedef esp_flash_counter_t spi_flash_counter_t;
typedef esp_flash_counters_t spi_flash_counters_t;
/** /**
* @brief Reset SPI flash operation counters * @brief Reset SPI flash operation counters
*/ */
void spi_flash_reset_counters(void); void esp_flash_reset_counters(void);
void spi_flash_reset_counters(void) __attribute__((deprecated("Please use 'esp_flash_reset_counters' instead")));
/** /**
* @brief Print SPI flash operation counters * @brief Print SPI flash operation counters
*/ */
void spi_flash_dump_counters(void); void esp_flash_dump_counters(FILE* stream);
void spi_flash_dump_counters(void) __attribute__((deprecated("Please use 'esp_flash_dump_counters' instead")));
/** /**
* @brief Return current SPI flash operation counters * @brief Return current SPI flash operation counters
* *
* @return pointer to the spi_flash_counters_t structure holding values * @return pointer to the esp_flash_counters_t structure holding values
* of the operation counters * of the operation counters
*/ */
const spi_flash_counters_t* spi_flash_get_counters(void); const esp_flash_counters_t* esp_flash_get_counters(void);
const spi_flash_counters_t* spi_flash_get_counters(void) __attribute__((deprecated("Please use 'esp_flash_get_counters' instead")));
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@@ -11,22 +11,14 @@
// Some resources are lazy allocated in flash encryption, the threadhold is left for that case // Some resources are lazy allocated in flash encryption, the threadhold is left for that case
#define TEST_MEMORY_LEAK_THRESHOLD (400) #define TEST_MEMORY_LEAK_THRESHOLD (400)
static size_t before_free_8bit;
static size_t before_free_32bit;
void setUp(void) void setUp(void)
{ {
before_free_8bit = heap_caps_get_free_size(MALLOC_CAP_8BIT); unity_utils_record_free_mem();
before_free_32bit = heap_caps_get_free_size(MALLOC_CAP_32BIT);
} }
void tearDown(void) void tearDown(void)
{ {
size_t after_free_8bit = heap_caps_get_free_size(MALLOC_CAP_8BIT); unity_utils_evaluate_leaks_direct(TEST_MEMORY_LEAK_THRESHOLD);
size_t after_free_32bit = heap_caps_get_free_size(MALLOC_CAP_32BIT);
unity_utils_check_leak(before_free_8bit, after_free_8bit, "8BIT", TEST_MEMORY_LEAK_THRESHOLD);
unity_utils_check_leak(before_free_32bit, after_free_32bit, "32BIT", TEST_MEMORY_LEAK_THRESHOLD);
} }
void app_main(void) void app_main(void)

View File

@@ -916,6 +916,83 @@ static void test_flash_read_large_psram_buffer_low_internal_mem(const esp_partit
} }
TEST_CASE_FLASH("esp_flash_read large PSRAM buffer low memory", test_flash_read_large_psram_buffer_low_internal_mem); TEST_CASE_FLASH("esp_flash_read large PSRAM buffer low memory", test_flash_read_large_psram_buffer_low_internal_mem);
#endif #endif
#if CONFIG_SPI_FLASH_ENABLE_COUNTERS
#define TEST_CNT_RW_TIMES 4
#define TEST_CNT_RW_LEN 64
#define TEST_CNT_ERASE_LEN 8192
void test_flash_counter(const esp_partition_t* part)
{
esp_flash_t* chip = part->flash_chip;
uint32_t offs = part->address;
esp_flash_counters_t flash_counter;
static uint8_t write_buf[TEST_CNT_RW_LEN * TEST_CNT_RW_TIMES];
static uint8_t read_buf[TEST_CNT_RW_LEN * TEST_CNT_RW_TIMES];
for(int i = 0;i < TEST_CNT_RW_LEN * TEST_CNT_RW_TIMES; i ++){
write_buf[i] = i;
}
esp_flash_reset_counters();
flash_counter = *esp_flash_get_counters();
// check for resset_counter and get_counter API
TEST_ASSERT_EACH_EQUAL_HEX8(0, &flash_counter, sizeof(esp_flash_counters_t));
TEST_ASSERT_EQUAL(ESP_OK, esp_flash_erase_region(chip, offs, TEST_CNT_ERASE_LEN));
flash_counter = *esp_flash_get_counters();
// check for erase_counter API
TEST_ASSERT_EQUAL_UINT32(0, flash_counter.read.count);
TEST_ASSERT_EQUAL_UINT32(0, flash_counter.write.count);
TEST_ASSERT_EQUAL_UINT32(1, flash_counter.erase.count);
TEST_ASSERT_EQUAL_UINT32(0 * TEST_CNT_RW_LEN, flash_counter.read.bytes);
TEST_ASSERT_EQUAL_UINT32(0 * TEST_CNT_RW_LEN, flash_counter.write.bytes);
TEST_ASSERT_EQUAL_UINT32(TEST_CNT_ERASE_LEN, flash_counter.erase.bytes);
int count;
for(count = 0; count < TEST_CNT_RW_TIMES; count ++) {
// check counter on write option
TEST_ASSERT_EQUAL(ESP_OK, esp_flash_write(chip, write_buf + TEST_CNT_RW_LEN * count, offs + TEST_CNT_RW_LEN * count, TEST_CNT_RW_LEN) );
flash_counter = *esp_flash_get_counters();
TEST_ASSERT_EQUAL_UINT32((count + 1), flash_counter.write.count);
TEST_ASSERT_EQUAL_UINT32((count + 1) * TEST_CNT_RW_LEN, flash_counter.write.bytes);
// check counter on read option
TEST_ASSERT_EQUAL(ESP_OK, esp_flash_read(chip, read_buf + TEST_CNT_RW_LEN * count, offs + TEST_CNT_RW_LEN * count, TEST_CNT_RW_LEN) );
flash_counter = *esp_flash_get_counters();
TEST_ASSERT_EQUAL_UINT32((count + 1), flash_counter.read.count);
TEST_ASSERT_EQUAL_UINT32((count + 1) * TEST_CNT_RW_LEN, flash_counter.read.bytes);
esp_flash_dump_counters(stdout);
}
TEST_ASSERT_EQUAL_HEX8_ARRAY(write_buf, read_buf, TEST_CNT_RW_LEN * TEST_CNT_RW_TIMES);
// check remain value
flash_counter = *esp_flash_get_counters();
TEST_ASSERT_EQUAL_UINT32(1, flash_counter.erase.count);
TEST_ASSERT_EQUAL_UINT32(TEST_CNT_ERASE_LEN, flash_counter.erase.bytes);
esp_flash_reset_counters();
flash_counter = *esp_flash_get_counters();
// check for resset_counter after used
TEST_ASSERT_EACH_EQUAL_HEX8(0, &flash_counter, sizeof(esp_flash_counters_t));
TEST_ASSERT_EQUAL(ESP_OK, esp_flash_write_encrypted(chip, offs, write_buf, TEST_CNT_RW_LEN) );
TEST_ASSERT_EQUAL(ESP_OK, esp_flash_read_encrypted(chip, offs, read_buf, TEST_CNT_RW_LEN) );
printf("\ntest for encrypted write/read\n");
esp_flash_dump_counters(stdout);
flash_counter = *esp_flash_get_counters();
// As we do one time of encrypted RW, no erase option
TEST_ASSERT_EQUAL_UINT32(1, flash_counter.read.count);
TEST_ASSERT_EQUAL_UINT32(1, flash_counter.write.count);
TEST_ASSERT_EQUAL_UINT32(0, flash_counter.erase.count);
TEST_ASSERT_EQUAL_UINT32(1 * TEST_CNT_RW_LEN, flash_counter.read.bytes);
TEST_ASSERT_EQUAL_UINT32(1 * TEST_CNT_RW_LEN, flash_counter.write.bytes);
TEST_ASSERT_EQUAL_UINT32(0, flash_counter.erase.bytes);
}
TEST_CASE_FLASH("SPI flash counter test", test_flash_counter);
#endif //CONFIG_SPI_FLASH_ENABLE_COUNTERS

View File

@@ -16,14 +16,12 @@ from pytest_embedded import Dut
[ [
'release', 'release',
'flash_qio', 'flash_qio',
'verify' 'verify',
], ],
indirect=True, indirect=True,
) )
def test_esp_flash(dut: Dut) -> None: def test_esp_flash(dut: Dut) -> None:
dut.expect_exact('Press ENTER to see the list of tests') dut.run_all_single_board_cases(group='esp_flash')
dut.write('[esp_flash]')
dut.expect_unity_test_output()
@pytest.mark.esp32s3 @pytest.mark.esp32s3
@@ -38,9 +36,7 @@ def test_esp_flash(dut: Dut) -> None:
indirect=True, indirect=True,
) )
def test_esp_flash_rom(dut: Dut) -> None: def test_esp_flash_rom(dut: Dut) -> None:
dut.expect_exact('Press ENTER to see the list of tests') dut.run_all_single_board_cases(group='esp_flash')
dut.write('[esp_flash]')
dut.expect_unity_test_output()
@pytest.mark.esp32 @pytest.mark.esp32

View File

@@ -3,3 +3,4 @@ CONFIG_FREERTOS_USE_TICKLESS_IDLE=y
CONFIG_COMPILER_OPTIMIZATION_SIZE=y CONFIG_COMPILER_OPTIMIZATION_SIZE=y
CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_SIZE=y CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_SIZE=y
CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_SILENT=y CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_SILENT=y
CONFIG_SPI_FLASH_ENABLE_COUNTERS=y

View File

@@ -20,7 +20,7 @@ Feature Supported by ESP-IDF but not in Chip-ROM
- :ref:`CONFIG_SPI_FLASH_LOG_FAILED_WRITE`, enabling this option will print the bad writing. - :ref:`CONFIG_SPI_FLASH_LOG_FAILED_WRITE`, enabling this option will print the bad writing.
- :ref:`CONFIG_SPI_FLASH_WARN_SETTING_ZERO_TO_ONE`, enabling this option will check if you're writing zero to one. - :ref:`CONFIG_SPI_FLASH_WARN_SETTING_ZERO_TO_ONE`, enabling this option will check if you're writing zero to one.
- :ref:`CONFIG_SPI_FLASH_DANGEROUS_WRITE`, enabling this option will check for flash programming to certain protected regions like bootloader, partition table or application itself. - :ref:`CONFIG_SPI_FLASH_DANGEROUS_WRITE`, enabling this option will check for flash programming to certain protected regions like bootloader, partition table or application itself.
- :ref:`CONFIG_SPI_FLASH_ENABLE_COUNTERS`, enabling this option to collect performance data for ESP-IDF SPI Flash driver APIs.
Bugfixes Introduced in ESP-IDF but not in Chip-ROM Bugfixes Introduced in ESP-IDF but not in Chip-ROM
-------------------------------------------------- --------------------------------------------------

View File

@@ -7,3 +7,11 @@ FatFs
----- -----
``esp_vfs_fat_sdmmc_unmount()`` is now deprecated, you can use :cpp:func:`esp_vfs_fat_sdcard_unmount()` instead. This API is deprecated in previous IDF versions, but without deprecation warning and migration guide. Since IDF v5.1, calling this ``esp_vfs_fat_sdmmc_unmount()`` API will generate deprecation warning. ``esp_vfs_fat_sdmmc_unmount()`` is now deprecated, you can use :cpp:func:`esp_vfs_fat_sdcard_unmount()` instead. This API is deprecated in previous IDF versions, but without deprecation warning and migration guide. Since IDF v5.1, calling this ``esp_vfs_fat_sdmmc_unmount()`` API will generate deprecation warning.
SPI_FLASH
---------
- :cpp:func:`spi_flash_get_counters` is deprecated, please use :cpp:func:`esp_flash_get_counters` instead.
- :cpp:func:`spi_flash_dump_counters` is deprecated, please use :cpp:func:`esp_flash_dump_counters` instead.
- :cpp:func:`spi_flash_reset_counters` is deprecated, please use :cpp:func:`esp_flash_reset_counters` instead.

View File

@@ -1017,7 +1017,6 @@ components/soc/include/soc/uhci_periph.h
components/soc/lldesc.c components/soc/lldesc.c
components/soc/soc_include_legacy_warn.c components/soc/soc_include_legacy_warn.c
components/spi_flash/cache_utils.h components/spi_flash/cache_utils.h
components/spi_flash/include/esp_spi_flash_counters.h
components/spi_flash/include/spi_flash_chip_boya.h components/spi_flash/include/spi_flash_chip_boya.h
components/spi_flash/include/spi_flash_chip_driver.h components/spi_flash/include/spi_flash_chip_driver.h
components/spi_flash/include/spi_flash_chip_gd.h components/spi_flash/include/spi_flash_chip_gd.h