|
|
@@ -14,6 +14,7 @@
|
|
|
#include "soc/spi_mem_reg.h"
|
|
|
#include "spi_timing_config.h"
|
|
|
#include "esp_private/spi_flash_os.h"
|
|
|
+#include "bootloader_flash.h"
|
|
|
|
|
|
#define OPI_PSRAM_SYNC_READ 0x0000
|
|
|
#define OPI_PSRAM_SYNC_WRITE 0x8080
|
|
|
@@ -106,9 +107,7 @@ typedef enum {
|
|
|
PSRAM_CMD_SPI,
|
|
|
} psram_cmd_mode_t;
|
|
|
|
|
|
-#if !CONFIG_ESPTOOLPY_OCT_FLASH
|
|
|
static uint8_t s_rom_flash_extra_dummy[2] = {NOT_INIT_INT, NOT_INIT_INT};
|
|
|
-#endif
|
|
|
|
|
|
#if CONFIG_SPIRAM_MODE_QUAD
|
|
|
static uint8_t s_psram_extra_dummy;
|
|
|
@@ -137,7 +136,6 @@ void spi_timing_config_flash_set_din_mode_num(uint8_t spi_num, uint8_t din_mode,
|
|
|
REG_WRITE(SPI_MEM_DIN_NUM_REG(spi_num), reg_val);
|
|
|
}
|
|
|
|
|
|
-#ifndef CONFIG_ESPTOOLPY_OCT_FLASH
|
|
|
static uint32_t spi_timing_config_get_dummy(void)
|
|
|
{
|
|
|
uint32_t ctrl_reg = READ_PERI_REG(SPI_MEM_CTRL_REG(0));
|
|
|
@@ -185,21 +183,21 @@ static uint32_t spi_timing_config_get_dummy(void)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-#endif
|
|
|
|
|
|
void spi_timing_config_flash_set_extra_dummy(uint8_t spi_num, uint8_t extra_dummy)
|
|
|
{
|
|
|
-#if CONFIG_ESPTOOLPY_OCT_FLASH
|
|
|
- if (extra_dummy > 0) {
|
|
|
- SET_PERI_REG_MASK(SPI_MEM_TIMING_CALI_REG(spi_num), SPI_MEM_TIMING_CALI_M);
|
|
|
- SET_PERI_REG_BITS(SPI_MEM_TIMING_CALI_REG(spi_num), SPI_MEM_EXTRA_DUMMY_CYCLELEN_V, extra_dummy,
|
|
|
- SPI_MEM_EXTRA_DUMMY_CYCLELEN_S);
|
|
|
- } else {
|
|
|
- CLEAR_PERI_REG_MASK(SPI_MEM_TIMING_CALI_REG(spi_num), SPI_MEM_TIMING_CALI_M);
|
|
|
- SET_PERI_REG_BITS(SPI_MEM_TIMING_CALI_REG(spi_num), SPI_MEM_EXTRA_DUMMY_CYCLELEN_V, 0,
|
|
|
- SPI_MEM_EXTRA_DUMMY_CYCLELEN_S);
|
|
|
+ if (bootloader_flash_is_octal_mode_enabled()) {
|
|
|
+ if (extra_dummy > 0) {
|
|
|
+ SET_PERI_REG_MASK(SPI_MEM_TIMING_CALI_REG(spi_num), SPI_MEM_TIMING_CALI_M);
|
|
|
+ SET_PERI_REG_BITS(SPI_MEM_TIMING_CALI_REG(spi_num), SPI_MEM_EXTRA_DUMMY_CYCLELEN_V, extra_dummy,
|
|
|
+ SPI_MEM_EXTRA_DUMMY_CYCLELEN_S);
|
|
|
+ } else {
|
|
|
+ CLEAR_PERI_REG_MASK(SPI_MEM_TIMING_CALI_REG(spi_num), SPI_MEM_TIMING_CALI_M);
|
|
|
+ SET_PERI_REG_BITS(SPI_MEM_TIMING_CALI_REG(spi_num), SPI_MEM_EXTRA_DUMMY_CYCLELEN_V, 0,
|
|
|
+ SPI_MEM_EXTRA_DUMMY_CYCLELEN_S);
|
|
|
+ }
|
|
|
+ return;
|
|
|
}
|
|
|
-#else
|
|
|
/**
|
|
|
* The `SPI_MEM_TIMING_CALI_REG` register is only used for OPI on 728
|
|
|
* Here we only need to update this global variable for extra dummy. Since we use the ROM Flash API, which will set the dummy based on this.
|
|
|
@@ -213,7 +211,6 @@ void spi_timing_config_flash_set_extra_dummy(uint8_t spi_num, uint8_t extra_dumm
|
|
|
// Only Quad Flash will run into this branch.
|
|
|
uint32_t dummy = spi_timing_config_get_dummy();
|
|
|
SET_PERI_REG_BITS(SPI_MEM_USER1_REG(0), SPI_MEM_USR_DUMMY_CYCLELEN_V, dummy + g_rom_spiflash_dummy_len_plus[spi_num], SPI_MEM_USR_DUMMY_CYCLELEN_S);
|
|
|
-#endif
|
|
|
}
|
|
|
|
|
|
//-------------------------------------PSRAM timing tuning register config-------------------------------------//
|
|
|
@@ -252,17 +249,17 @@ void spi_timing_config_psram_set_extra_dummy(uint8_t spi_num, uint8_t extra_dumm
|
|
|
//-------------------------------------------FLASH/PSRAM Read/Write------------------------------------------//
|
|
|
void spi_timing_config_flash_read_data(uint8_t spi_num, uint8_t *buf, uint32_t addr, uint32_t len)
|
|
|
{
|
|
|
-#if CONFIG_ESPTOOLPY_OCT_FLASH
|
|
|
- // note that in spi_flash_read API, there is a wait-idle stage, since flash can only be read in idle state.
|
|
|
- // but after we change the timing settings, we might not read correct idle status via RDSR.
|
|
|
- // so, here we should use a read API that won't check idle status.
|
|
|
- for (int i = 0; i < 16; i++) {
|
|
|
- REG_WRITE(SPI_MEM_W0_REG(1) + i*4, 0);
|
|
|
+ if (bootloader_flash_is_octal_mode_enabled()) {
|
|
|
+ // note that in spi_flash_read API, there is a wait-idle stage, since flash can only be read in idle state.
|
|
|
+ // but after we change the timing settings, we might not read correct idle status via RDSR.
|
|
|
+ // so, here we should use a read API that won't check idle status.
|
|
|
+ for (int i = 0; i < 16; i++) {
|
|
|
+ REG_WRITE(SPI_MEM_W0_REG(1) + i*4, 0);
|
|
|
+ }
|
|
|
+ esp_rom_opiflash_read_raw(addr, buf, len);
|
|
|
+ } else {
|
|
|
+ esp_rom_spiflash_read(addr, (uint32_t *)buf, len);
|
|
|
}
|
|
|
- esp_rom_opiflash_read_raw(addr, buf, len);
|
|
|
-#else
|
|
|
- esp_rom_spiflash_read(addr, (uint32_t *)buf, len);
|
|
|
-#endif
|
|
|
}
|
|
|
|
|
|
static void s_psram_write_data(uint8_t spi_num, uint8_t *buf, uint32_t addr, uint32_t len)
|