diff options
| -rw-r--r-- | ports/alif/ospi_ext.c | 28 | ||||
| -rw-r--r-- | ports/alif/ospi_ext.h | 1 | ||||
| -rw-r--r-- | ports/alif/ospi_flash.c | 16 |
3 files changed, 34 insertions, 11 deletions
diff --git a/ports/alif/ospi_ext.c b/ports/alif/ospi_ext.c index e3389d8bd..6ddaaf4e5 100644 --- a/ports/alif/ospi_ext.c +++ b/ports/alif/ospi_ext.c @@ -206,20 +206,22 @@ void ospi_setup_write_ext(ospi_flash_cfg_t *ospi_cfg, bool rxds, uint32_t inst_l spi_enable(ospi_cfg); } +static inline uint32_t ospi_xip_ctrlr0(uint32_t data_len) { + return CTRLR0_IS_MST + | (OCTAL << CTRLR0_SPI_FRF_OFFSET) + | (0 << CTRLR0_SCPOL_OFFSET) + | (0 << CTRLR0_SCPH_OFFSET) + | (0 << CTRLR0_SSTE_OFFSET) + | (TMOD_RO << CTRLR0_TMOD_OFFSET) + | (data_len << CTRLR0_DFS_OFFSET); +} + void ospi_xip_enter_ext(ospi_flash_cfg_t *ospi_cfg, uint32_t inst_len, uint32_t data_len, uint16_t incr_command, uint16_t wrap_command, uint16_t read_dummy_cycles) { spi_disable(ospi_cfg); - uint32_t val = CTRLR0_IS_MST - | (OCTAL << CTRLR0_SPI_FRF_OFFSET) - | (0 << CTRLR0_SCPOL_OFFSET) - | (0 << CTRLR0_SCPH_OFFSET) - | (0 << CTRLR0_SSTE_OFFSET) - | (TMOD_RO << CTRLR0_TMOD_OFFSET) - | (data_len << CTRLR0_DFS_OFFSET); - - ospi_writel(ospi_cfg, ctrlr0, val); + ospi_writel(ospi_cfg, ctrlr0, ospi_xip_ctrlr0(data_len)); - val = (OCTAL << XIP_CTRL_FRF_OFFSET) + uint32_t val = (OCTAL << XIP_CTRL_FRF_OFFSET) | (0x2 << XIP_CTRL_TRANS_TYPE_OFFSET) | (ADDR_L32bit << XIP_CTRL_ADDR_L_OFFSET) | (inst_len << XIP_CTRL_INST_L_OFFSET) @@ -292,3 +294,9 @@ void ospi_xip_exit_ext(ospi_flash_cfg_t *ospi_cfg, uint32_t inst_len, uint16_t i ospi_xip_enable(ospi_cfg); ospi_xip_disable(ospi_cfg); } + +void ospi_xip_restore_ext(ospi_flash_cfg_t *ospi_cfg, uint32_t data_len) { + spi_disable(ospi_cfg); + ospi_writel(ospi_cfg, ctrlr0, ospi_xip_ctrlr0(data_len)); + spi_enable(ospi_cfg); +} diff --git a/ports/alif/ospi_ext.h b/ports/alif/ospi_ext.h index e5a2b50be..65e2ced1f 100644 --- a/ports/alif/ospi_ext.h +++ b/ports/alif/ospi_ext.h @@ -53,5 +53,6 @@ void ospi_setup_write_ext(ospi_flash_cfg_t *ospi_cfg, bool rxds, uint32_t inst_l void ospi_xip_enter_ext(ospi_flash_cfg_t *ospi_cfg, uint32_t inst_len, uint32_t data_len, uint16_t incr_command, uint16_t wrap_command, uint16_t read_dummy_cycles); void ospi_xip_exit_ext(ospi_flash_cfg_t *ospi_cfg, uint32_t inst_len, uint16_t incr_command, uint16_t wrap_command); +void ospi_xip_restore_ext(ospi_flash_cfg_t *ospi_cfg, uint32_t data_len); #endif // MICROPY_INCLUDED_ALIF_OSPI_EXT_H diff --git a/ports/alif/ospi_flash.c b/ports/alif/ospi_flash.c index 8bcd1fb5b..f78002eb0 100644 --- a/ports/alif/ospi_flash.c +++ b/ports/alif/ospi_flash.c @@ -354,8 +354,9 @@ int ospi_flash_init(void) { } } - // Enter XIP mode. It will be disabled during flash read/erase/write. + // Enter XIP mode. ospi_flash_xip_enter(self); + return 0; } @@ -385,6 +386,13 @@ int ospi_flash_xip_exit(ospi_flash_t *self) { return 0; } +int ospi_flash_xip_restore(ospi_flash_t *self) { + if (self->xip_active) { + ospi_xip_restore_ext(&self->cfg, self->set->xip_data_len); + } + return 0; +} + /******************************************************************************/ // Top-level read/erase/write functions. @@ -398,6 +406,8 @@ int ospi_flash_erase_sector(uint32_t addr) { ret = ospi_flash_wait_wip0(self); } + ospi_flash_xip_restore(self); + return ret; } @@ -442,6 +452,8 @@ static int ospi_flash_write_page(uint32_t addr, uint32_t len, const uint8_t *src } int ospi_flash_write(uint32_t addr, uint32_t len, const uint8_t *src) { + ospi_flash_t *self = &global_flash; + int ret = 0; uint32_t offset = addr & (PAGE_SIZE - 1); @@ -460,6 +472,8 @@ int ospi_flash_write(uint32_t addr, uint32_t len, const uint8_t *src) { offset = 0; } + ospi_flash_xip_restore(self); + return ret; } |
