From 9a713f9b7d1e9d555a43c07c371896776681e206 Mon Sep 17 00:00:00 2001 From: armando Date: Wed, 2 Apr 2025 15:00:13 +0800 Subject: [PATCH] refactor(mspi): improved timing tuning max consecutive success points calculation --- components/spi_flash/spi_flash_timing_tuning.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/components/spi_flash/spi_flash_timing_tuning.c b/components/spi_flash/spi_flash_timing_tuning.c index c157412e33..9d1abc7579 100644 --- a/components/spi_flash/spi_flash_timing_tuning.c +++ b/components/spi_flash/spi_flash_timing_tuning.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2019-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2019-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -171,8 +171,17 @@ static void find_max_consecutive_success_points(uint8_t *array, uint32_t size, u i++; } - *out_length = match_num > max ? match_num : max; - *out_end_index = match_num == size ? size : end; + /** + * this is to deal with the case when the last points are consecutive 1, e.g. + * {1, 0, 0, 1, 1, 1, 1, 1, 1} + */ + if (match_num > max) { + max = match_num; + end = i - 1; + } + + *out_length = max; + *out_end_index = end; } #if SPI_TIMING_FLASH_DTR_MODE || SPI_TIMING_PSRAM_DTR_MODE