summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ports/alif/ospi_flash.c12
-rw-r--r--ports/alif/ospi_flash.h1
-rw-r--r--ports/alif/ospi_flash_settings.h5
3 files changed, 15 insertions, 3 deletions
diff --git a/ports/alif/ospi_flash.c b/ports/alif/ospi_flash.c
index 7400a678b..f2f95a04c 100644
--- a/ports/alif/ospi_flash.c
+++ b/ports/alif/ospi_flash.c
@@ -414,8 +414,16 @@ static int ospi_flash_write_page(uint32_t addr, uint32_t len, const uint8_t *src
ospi_push(&self->cfg, addr);
const uint32_t *src32 = (const uint32_t *)src;
- for (; len; len -= 4) {
- ospi_push(&self->cfg, __ROR(*src32++, 16));
+ if (self->set->bswap16) {
+ // MX flashes swap 16-bit words when read in 8D-8D-8D.
+ for (; len; len -= 4) {
+ ospi_push(&self->cfg, __ROR(*src32++, 16));
+ }
+ } else {
+ // For the rest of the flashes, we just correct the endianness.
+ for (; len; len -= 4) {
+ ospi_push(&self->cfg, __REV(*src32++));
+ }
}
ospi_writel((&self->cfg), ser, self->cfg.ser);
diff --git a/ports/alif/ospi_flash.h b/ports/alif/ospi_flash.h
index 0095ee2d4..f909f4a43 100644
--- a/ports/alif/ospi_flash.h
+++ b/ports/alif/ospi_flash.h
@@ -61,6 +61,7 @@ typedef struct _ospi_flash_settings_t {
int (*flash_init)(struct _ospi_flash_t *);
uint8_t octal_mode;
bool rxds;
+ bool bswap16;
uint8_t inst_len;
uint8_t xip_data_len;
uint16_t read_sr;
diff --git a/ports/alif/ospi_flash_settings.h b/ports/alif/ospi_flash_settings.h
index c8605275c..72403c26b 100644
--- a/ports/alif/ospi_flash_settings.h
+++ b/ports/alif/ospi_flash_settings.h
@@ -34,6 +34,7 @@
.flash_init = ospi_flash_mx_init, \
.octal_mode = OSPI_FLASH_OCTAL_MODE_DDD, \
.rxds = true, \
+ .bswap16 = true, \
.inst_len = OSPI_INST_L_16bit, \
.xip_data_len = OSPI_DATA_L_16bit, \
.read_sr = 0x05fa, \
@@ -50,6 +51,7 @@
.flash_init = ospi_flash_issi_init, \
.octal_mode = OSPI_FLASH_OCTAL_MODE_DDD, \
.rxds = false, \
+ .bswap16 = false, \
.inst_len = OSPI_INST_L_8bit, \
.xip_data_len = OSPI_DATA_L_16bit, \
.read_sr = 0x05, \
@@ -65,7 +67,8 @@
#define OSPI_FLASH_SETTINGS_IS25 \
.flash_init = ospi_flash_issi_init, \
.octal_mode = OSPI_FLASH_OCTAL_MODE_DDD, \
- .rxds = true, \
+ .rxds = false, \
+ .bswap16 = false, \
.inst_len = OSPI_INST_L_8bit, \
.xip_data_len = OSPI_DATA_L_16bit, \
.read_sr = 0x05, \