Skip to content

Commit 114d2f4

Browse files
committed
flash: make flash initialization as commom code
Merge flash initialization procedures in a single function so that it can be used across different socs. Signed-off-by: Sylvio Alves <[email protected]>
1 parent d673ce8 commit 114d2f4

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

zephyr/common/flash_init.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,19 @@
88

99
#include <stdbool.h>
1010
#include <bootloader_flash_priv.h>
11+
#include <esp_flash_internal.h>
12+
#include <esp_private/mspi_timing_tuning.h>
13+
#include <esp_private/esp_mmu_map_private.h>
1114
#include <hal/efuse_ll.h>
1215
#include <hal/efuse_hal.h>
1316
#include "esp_private/spi_flash_os.h"
17+
#include "esp_log.h"
1418
#if CONFIG_SOC_SERIES_ESP32S3
1519
#include <esp32s3/opi_flash_private.h>
1620
#endif
1721

22+
static const char *TAG = "flash_init";
23+
1824
bool flash_is_octal_mode_enabled(void)
1925
{
2026
#if SOC_SPI_MEM_SUPPORT_OPI_MODE
@@ -38,3 +44,26 @@ int spi_flash_init_chip_state(void)
3844
return 0;
3945
#endif /* CONFIG_SOC_SERIES_ESP32S3 */
4046
}
47+
48+
void esp_flash_config(void)
49+
{
50+
esp_err_t ret;
51+
52+
spi_flash_init_chip_state();
53+
54+
esp_flash_app_init();
55+
56+
ret = esp_flash_init_default_chip();
57+
if (ret != ESP_OK) {
58+
ESP_EARLY_LOGE(TAG, "Failed to init flash chip: %d ", ret);
59+
abort();
60+
}
61+
62+
esp_mspi_pin_init();
63+
64+
#if SOC_MEMSPI_SRC_FREQ_120M
65+
mspi_timing_flash_tuning();
66+
#endif
67+
68+
esp_mmu_map_init();
69+
}

zephyr/common/include/flash_init.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,8 @@
1111
int spi_flash_init_chip_state(void);
1212

1313
bool flash_is_octal_mode_enabled(void);
14+
15+
/**
16+
* @brief Common flash initialization code
17+
*/
18+
void esp_flash_config(void);

0 commit comments

Comments
 (0)