Skip to content

Commit 92f056d

Browse files
iabdalkaderdpgeorge
authored andcommitted
alif/ospi_flash: Add 16-bit words swap flash setting.
The byte order (endianness) seems to be swapped when read in 8D-8D-8D in XIP mode, for most flashes, with the exception of MX which seems to swap half-words. This commit adds a flash setting to allow parts to enable half-word swap when data is written, to fix this issue. By default, only endianness is fixed. Tested with both MX and ISSI parts on AE3, flash test and simple file write/read. Signed-off-by: iabdalkader <[email protected]>
1 parent 602bc86 commit 92f056d

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

ports/alif/ospi_flash.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -414,8 +414,16 @@ static int ospi_flash_write_page(uint32_t addr, uint32_t len, const uint8_t *src
414414
ospi_push(&self->cfg, addr);
415415

416416
const uint32_t *src32 = (const uint32_t *)src;
417-
for (; len; len -= 4) {
418-
ospi_push(&self->cfg, __ROR(*src32++, 16));
417+
if (self->set->bswap16) {
418+
// MX flashes swap 16-bit words when read in 8D-8D-8D.
419+
for (; len; len -= 4) {
420+
ospi_push(&self->cfg, __ROR(*src32++, 16));
421+
}
422+
} else {
423+
// For the rest of the flashes, we just correct the endianness.
424+
for (; len; len -= 4) {
425+
ospi_push(&self->cfg, __REV(*src32++));
426+
}
419427
}
420428

421429
ospi_writel((&self->cfg), ser, self->cfg.ser);

ports/alif/ospi_flash.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ typedef struct _ospi_flash_settings_t {
6161
int (*flash_init)(struct _ospi_flash_t *);
6262
uint8_t octal_mode;
6363
bool rxds;
64+
bool bswap16;
6465
uint8_t inst_len;
6566
uint8_t xip_data_len;
6667
uint16_t read_sr;

ports/alif/ospi_flash_settings.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
.flash_init = ospi_flash_mx_init, \
3535
.octal_mode = OSPI_FLASH_OCTAL_MODE_DDD, \
3636
.rxds = true, \
37+
.bswap16 = true, \
3738
.inst_len = OSPI_INST_L_16bit, \
3839
.xip_data_len = OSPI_DATA_L_16bit, \
3940
.read_sr = 0x05fa, \
@@ -50,6 +51,7 @@
5051
.flash_init = ospi_flash_issi_init, \
5152
.octal_mode = OSPI_FLASH_OCTAL_MODE_DDD, \
5253
.rxds = false, \
54+
.bswap16 = false, \
5355
.inst_len = OSPI_INST_L_8bit, \
5456
.xip_data_len = OSPI_DATA_L_16bit, \
5557
.read_sr = 0x05, \
@@ -65,7 +67,8 @@
6567
#define OSPI_FLASH_SETTINGS_IS25 \
6668
.flash_init = ospi_flash_issi_init, \
6769
.octal_mode = OSPI_FLASH_OCTAL_MODE_DDD, \
68-
.rxds = true, \
70+
.rxds = false, \
71+
.bswap16 = false, \
6972
.inst_len = OSPI_INST_L_8bit, \
7073
.xip_data_len = OSPI_DATA_L_16bit, \
7174
.read_sr = 0x05, \

0 commit comments

Comments
 (0)