Commit Graph

76 Commits

Author SHA1 Message Date
Xiao Xufeng 230ee88d99 feat(spi_flash): implement dynamic CPU frequency switching workaround for encrypted writes
This commit implements a workaround that allows ESP32-C5 to run at 240MHz CPU frequency
normally, while automatically reducing CPU frequency during encrypted flash writes to
ensure correct operation. The frequency limit is chip revision dependent:
- v1.2 and above: limited to 160MHz during encrypted writes
- v1.0 and below: limited to 80MHz during encrypted writes

Key implementation details:
- Frequency limiting is triggered automatically when esp_flash_write_encrypted() is called
- Uses start() flags (ESP_FLASH_START_FLAG_LIMIT_CPU_FREQ) to integrate with OS layer
- Works with both PM enabled and disabled configurations
- Frequency is automatically restored after encrypted write completes
- For ESP32-C5 with 120MHz flash, Flash clock and timing registers are adjusted when
  CPU frequency is reduced to 80MHz
- SPI1 timing registers are configured during frequency switching since encrypted writes
  use SPI1 and must work correctly at reduced CPU frequencies

Code improvements:
- Use SOC_MSPI_FREQ_AXI_CONSTRAINED capability macro instead of hardcoded chip checks
- Control workaround via Kconfig (CONFIG_PM_WORKAROUND_FREQ_LIMIT_ENABLED) instead of
  hardcoded macros
- Add comprehensive test cases covering various PM configurations and edge cases

This workaround enables ESP32-C5 applications to benefit from 240MHz CPU performance
while maintaining reliable encrypted flash write functionality.
2025-12-16 17:42:44 +08:00
Mahavir Jain c4fda6cb2f fix(spi_flash): limit CPU clock to 160MHz for encrypted flash writes 2025-12-16 17:41:25 +08:00
C.S.M d5054072eb ci(header_check): Add check for public header should not include freertos 2025-11-28 19:15:17 +08:00
radek.tandler fffef09b50 fix(spi-flash): Fixed missing flash write check of non 4-byte aligned data 2025-10-30 12:20:32 +08:00
radek.tandler c16f82b367 fix(spi-flash): Fixed wrong offset calculation in s_verify_write log message 2025-10-30 11:38:40 +08:00
Konstantin Kondrashov b7da740f12 Merge branch 'feature/log_v2_optimization' into 'master'
feat(log): Optimize idf components for binary logging

Closes IDF-12775

See merge request espressif/esp-idf!40289
2025-09-19 14:45:43 +08:00
Konstantin Kondrashov 16d73cdab3 feat(log): Adds ESP_LOG_ATTR macro to control section placement 2025-09-15 15:59:52 +03:00
armando 00022a379a change: remove deprecated items 2025-09-15 10:52:28 +08:00
Xiao Xufeng 83ca12c8e0 fix(esp_flash): fixed issue of escaping boundary check
Also patched corresponding ROM functions
2025-06-24 15:30:11 +08:00
C.S.M 6c3d67b234 fix(spi_flash): Add suspend check on esp32c6 and esp32h2 for some reason 2025-03-11 11:11:39 +08:00
C.S.M ae50c71222 fix(spi_flash): Return false directly in suspend caps check 2025-03-11 11:11:39 +08:00
C.S.M add27dfbd3 fix(spi_flash): Fix flash encryption write verify,
Closes https://github.com/espressif/esp-idf/issues/15380
2025-02-28 15:57:24 +08:00
C.S.M b66e140fbc refactor(spi_flash): optimize flash functions to save iram memory 2025-02-26 18:28:49 +08:00
C.S.M c9d481c6d2 feat(spi_flash): support software resume after suspend in unicore 2024-11-22 13:48:45 +08:00
Cao Sen Miao 44e16a6401 fix(spi_flash): Fix issue that flash encryption failed while rom_impl config is enabled
The issue is `esp_flash_write_encryped` function in ROM on ESP32C3, ESP32S3
calls legacy implementation, which uses old configuration. And this causes
write fails.
The solution in this commit is to compile and link this function(and related)
in IRAM instead of the ROM one.
The IRAM cost increases around 1.2KB after the fix
2024-02-28 10:07:53 +08:00
Mahavir Jain 58efbf4894 fix(spi_flash): check for safe write address in encrypted flash API 2024-02-14 13:45:11 +05:30
Cao Sen Miao e7dd6bbcdf fix(spi_flash): Fix spi_flash counter test on CI 2023-12-18 19:03:30 +08:00
Cao Sen Miao a5a29882ef fix(spi_flash): Fix that internal RAM has no enough space to put all stuff inside 2023-12-14 17:05:59 +08:00
Cao Sen Miao 6953b51b3a fix(spi_flash): Improve encryption write performance, Closes https://github.com/espressif/esp-idf/issues/12553 2023-11-22 10:33:05 +08:00
Adam Múdry ab1eb37fe8 feat(partition_table): Add read-only partition flag and functionality 2023-10-11 00:01:05 +02:00
gaoxu 542a61b6cb support SPI_FLASH_ENABLE_COUNTERS feature on esp_flash driver and rename the functions to esp_flash_xx 2023-04-06 11:40:40 +08:00
Cao Sen Miao 5bac46b3e8 MMU: Fix stale data being read on memory mapped instruction page 2023-03-24 18:59:57 +08:00
Armando d35b6dd852 spi_flash: support write verify feature on esp_flash_write_encrypted API 2023-03-09 14:55:13 +08:00
Armando 110853517a spi_flash: support write verify feature on esp_flash_write API 2023-03-09 14:55:13 +08:00
gaoxu 44dd14dde4 support SPI_FLASH_VERIFY_WRITE feature on esp_flash driver and add config to test it 2023-03-09 14:55:13 +08:00
Adam Múdry cfc8332833 spi: Mask esp_flash_erase chip with esp_flash_erase_sector
add: Fix to prevent WDT trigger
add: comments to better explain SPI API

Closes https://github.com/espressif/esp-idf/issues/9945
Closes https://github.com/espressif/esp-idf/issues/9212
Closes https://github.com/espressif/esp-idf/issues/8135
2023-01-08 13:58:37 +00:00
C.S.M 54d9da987a Merge branch 'bugfix/flash_large_memory_size' into 'master'
spi_flash: Fix issue that cannot get accurate flash size when encounter large size memory

Closes IDFGH-8063

See merge request espressif/esp-idf!20738
2022-11-22 16:07:17 +08:00
Darian Leung cf4fea3206 hal: Fix incorrect spi_hal log usage
esp_flash_init_main() can be during startup before the OS has started, thus should use
the EARLY version of logging.
2022-11-04 09:07:30 +01:00
Cao Sen Miao b4964279d4 spi_flash: Fix issue that cannot get accurate flash size when encounter large size memory,
Closes https://github.com/espressif/esp-idf/pull/9566
2022-10-31 11:05:36 +08:00
Cao Sen Miao a690a87829 spi_flash: Remove legacy spi_flash drivers 2022-07-01 11:01:34 +08:00
Sudeep Mohanty 3cd2b67f84 Revert "hal: Fix incorrect spi_hal log usage"
This reverts commit a65165dd52.
2022-06-29 14:52:28 +00:00
Darian Leung a65165dd52 hal: Fix incorrect spi_hal log usage
esp_flash_init_main() can be during startup before the OS has started, thus should use
the EARLY version of logging.
2022-06-08 19:19:44 +08:00
Armando a8a47a61f5 spi_flash: move buffer check from hal layer to driver layer
Prior to this change, `spi_flash_hal_supports_direct_write` and
`spi_flash_hal_supports_direct_read` will check the buffer pointer
place, which should be done in driver layer, instead of HAL layer.
2022-04-08 11:46:10 +08:00
Cao Sen Miao 3a4db97cec spi_flash: move patch files to common rom patch folder 2021-12-30 14:05:12 +08:00
Cao Sen Miao 3dd1cfea18 spi_flash: refactor spi_flash.h to decline duplicated code 2021-12-30 14:05:12 +08:00
Mahavir Jain 203f82cc49 Fix various warnings generated from Coverity scan
esp_timer:
Control flow issues  (DEADCODE)
    Execution cannot reach this statement: "break;".

protocomm_httpd:
(UNUSED_VALUE)
    Assigning value from "cookie_session_id" to "cur_cookie_session_id" here, but that stored value is overwritten before it can be used.

esp_flash_api:
Null pointer dereferences  (REVERSE_INULL)
    Null-checking "chip" suggests that it may be null, but it has already been dereferenced on all paths leading to the check.
2021-12-09 09:38:53 +05:30
Cao Sen Miao 3934e24d22 ESP8684: add spi_flash, efuse, hw_support support 2021-11-06 17:33:44 +08:00
Cao Sen Miao 6c0aebe279 esp_flash: add opi flash support in esp_flash chip driver, for MXIC 2021-09-07 14:44:40 +08:00
Ivan Grokhotkov 7534c4467f rom, spi_flash: add a patch for esp_flash_erase_region for C3, S3, H2 2021-07-24 13:28:25 +02:00
negativekelvin 8e6700c156 esp_flash_api fixes 2021-07-23 02:35:27 -07:00
Cao Sen Miao fecf27e54c spi_flash: add support for 32Mbit address GD flash, for GD25Q256 2021-07-02 17:13:51 +08:00
Cao Sen Miao 0d81edb174 spi_flash: refactoring flash encryption into new api 2021-04-25 17:09:25 +08:00
Cao Sen Miao c54ea54d98 spi_flash: make suspend off by default and add more information for using suspend 2021-03-26 13:57:14 +08:00
Cao Sen Miao 78a2dbe42a spi_flash: add a new function to support read the unique id
Close https://github.com/espressif/esp-idf/pull/4255
2021-03-15 11:40:33 +08:00
Cao Sen Miao 9905da46e0 spi_flash: Add auto suspend mode on esp32c3 2021-01-25 11:14:02 +08:00
KonstantinKondrashov 60e58eaddb spi_flash: Add auto-suspend mode for ESP32-S2
Uses HW auto_wait_idle, HW auto_suspend and SW resume
2021-01-25 11:13:38 +08:00
Angus Gratton d4c9a45675 spi_flash: Add ESP32-C3 support
Based on internal commit 3ef01301fff
2020-12-17 15:34:13 +11:00
Michael (XIAO Xufeng) 8ae09194ac esp_flash: refactor to support various type of yield
There is a periodically yield in the esp_flash driver, to ensure the
cache will not be disabled for too long on ESP32.

On ESP32-S2 and later, we need to support more different kind of yield:

1. polling conditions, including timeout, SW read request, etc.
2. wait for events, including HW done/error/auto-suspend, timeout
semaphore, etc.

The check_yield() and yield() is separated into two parts, because we
may need to insert suspend, etc. between them.
2020-11-10 19:05:22 +08:00
Michael (XIAO Xufeng) 3bacf35310 esp_flash: support high capacity flash chips (32-bit address) 2020-10-29 18:20:11 +08:00
Renz Bagaporo b3a7c6e27e components: remove some unneeded headers from source files 2020-10-22 19:37:10 +08:00