Hello,
I am continuing to work on my project with the nRF54L15 DK and have run into another challenge. Currently, the issue is storing images (320 × 492 bytes) in an external flash memory (MX66L2G45GXRI00-T). The write process works but takes significantly longer than expected.
Do you have any suggestions on which parameters or approaches could be optimized here?
At the moment, I am using SPIM with jedec,spi-nor. From my online research, it seems that for higher write speeds, switching to QSPI with the Nordic driver (nordic,qspi-nor) is recommended. Is this correct? How could this be implemented? And is it even possible on the nRF54L15 DK?
Thank you in advance for your support!
Below is a snippet of my overlay file:
&spi21{
status = "okay";
cs-gpios = <&gpio1 12 GPIO_ACTIVE_LOW>;
pinctrl-0 = <&spi21_default>;
pinctrl-1 = <&spi21_sleep>;
pinctrl-names = "default", "sleep";
flash0: flash@0 {
compatible = "jedec,spi-nor";
reg = <0x00000000 0x10000000>; /* Offset = 0x0, Size = 256 MB */
spi-max-frequency = <8000000>;
jedec-id = [c2 20 1c];
size = <2147483648>;
enter-4byte-addr = <1>;
};
compatible = "nordic,nrf-spim";
};
In my main, I use the flash device as follows (also just a snippet):
#define FRAME_SIZE (320 * 492)
#define FLASH_START 0x00000
#define BLOCK_SIZE_UART 128
#define PAGE_SIZE 256
const struct device *flash_dev = DEVICE_DT_GET(DT_NODELABEL(flash0));
void write_frame(const struct device *flash_dev, const uint8_t *data, size_t len)
{
off_t write_addr = FLASH_START + flash_write_offset;
for (size_t offset = 0; offset < len; offset += PAGE_SIZE)
{
size_t chunk = MIN(PAGE_SIZE, len - offset);
int rc = flash_write(flash_dev,
write_addr + offset,
&data[offset],
chunk);
if (rc != 0)
{
LOG_ERR("Flash write failed at 0x%06lx: %d",
(unsigned long)(write_addr + offset), rc);
return;
}
}
LOG_INF("Frame written at offset 0x%06lx (%zu bytes)",
(unsigned long)flash_write_offset, len);
flash_write_offset =
((flash_write_offset + len + ERASE_BLOCK_SIZE - 1) /
ERASE_BLOCK_SIZE) * ERASE_BLOCK_SIZE;
last_block_end = flash_write_offset;
LOG_INF("Last block end set to 0x%06zx", last_block_end);
frames_written++;
}