Commit Graph

3 Commits (737bb55f76b610b08298a575a316c010f64d9d3e)

Author SHA1 Message Date
Daniele Lacamera 737bb55f76 ls1028a: wait for the NOR program/erase cycle to finish
XSPI_IPCMDDONE only says the controller finished driving the sequence
on the bus. The device keeps WIP set for the ~ms the cycle takes and
ignores Write Enable while it is set, so the per-page WREN this PR
added was dropped for pages 2..N and their Page Programs with it.

The erase loops polled the same bit with inverted polarity: they
exited as soon as WIP read *set*, i.e. once the erase had started, and
would spin forever if they missed the busy window. FLASH_READY_MSK is
renamed FLASH_SR_WIP_MSK so the sense is not guessable, and both paths
now share xspi_wait_ready().

The test device models WIP, so a missing wait shows up as a rejected
Write Enable.
2026-08-18 09:10:13 +02:00
Daniele Lacamera 43890cfb39 F-7978: keep LS1028A xSPI Page Programs inside a physical NOR page
xspi_flash_write() capped each chunk to XSPI_IP_BUF_SIZE (256, the NOR
page size) but not to the bytes remaining in the current physical
page, so a write starting mid-page sent one Page Program across the
page boundary. NOR wraps the write pointer to the page start, so the
excess bytes clobbered the beginning of the next page (and the
programmed data was corrupted to match).

Cap each chunk to min(len, page room left in the current page).
Aligned or page-start writes are unchanged; a mid-page start now
sends a short first program plus the remaining full pages.

The unit-ls1028a-xspi-write harness now models the NOR wrap (a
crossing program clobbers the page start it wraps into), and gains
test_write_crossing_page_no_wrap: a 256 byte write starting 16 bytes
before a boundary must not touch the first 16 bytes of the next page
(pre-fix the emulator shows the clobber and a 240+256 program).
test_write_unaligned's expectations are updated to the correct
156/256/188 chunking.

Verified: unit-ls1028a-xspi-write 5/5 green post-fix (2/5 fail
pre-fix), tools/unit-tests suite green (113 binaries).
2026-08-18 04:13:36 +02:00
Daniele Lacamera 55adf955d6 F-7977: issue Write Enable for every page in LS1028A xSPI flash writes
hal_flash_write() and ext_flash_write() issued xspi_write_en() once
before xspi_flash_write(), but that function emits one 256-byte Page
Program command per chunk when len > XSPI_IP_BUF_SIZE. NOR flash
clears its write-enable latch after each program operation, so a
write larger than 256 bytes programmed the first page and was
rejected by the flash for every remaining page, while the wrapper
still returned success.

Move the Write Enable into the page loop in xspi_flash_write(),
after the prior program has completed and before each Page Program
command, and drop it from the two wrappers.

Added tools/unit-tests/unit-ls1028a-xspi-write: the XSPI driver is
plain C register access (a few bare asm barrier statements are
blanked out in the Makefile-generated host copy), so the test
includes the real HAL file, rebases XSPI_BASE onto host memory, and
emulates the FlexSPI controller at the XSPI_IPCMD_START() boundary.
The emulated NOR keeps the write-enable latch of real NOR (set by
WEN, consumed by each Page Program, program rejected without it) and
captures the TX FIFO byte stream in the order the driver hands it
over, since the controller drains the FIFO while the command runs.
The test checks the WEN/PP command sequence and the resulting flash
contents; it fails against the pre-fix single-WEN code.

Verified: unit-ls1028a-xspi-write 4/4 green post-fix (3 fail
pre-fix), tools/unit-tests suite green (107 binaries).
2026-08-18 01:41:30 +02:00