Add initial LFS support for IMXRT

This commit is contained in:
robert committed 2026-12-03 16:55:51 +02:00
1 parent f3189519d8
commit cdd6681f40
5 files changed
+114 -8

No files matched your search

+37
View File
@@ -12900,9 +12900,40 @@ MG_IRAM static bool mg_imxrt_erase(void *addr) {
}
#endif
#if MG_OTA == MG_OTA_RT1180
MG_IRAM static void flash_sync(void *addr, size_t len) {
// Include any sectors erased while programming their first page.
size_t ss = s_mg_flash_imxrt.secsz;
uintptr_t start = MG_ROUND_DOWN((uintptr_t) addr, ss);
uintptr_t end = MG_ROUND_UP((uintptr_t) addr + len, ss);
volatile uint32_t *cache = (volatile uint32_t *) 0x44400000; // XCACHE_PC
#if defined(__GNUC__) && defined(__arm__)
__asm__ __volatile__("dsb 0xf\nisb 0xf" : : : "memory");
#endif
// Reset the FlexSPI2 AHB read buffers and IP FIFOs, with the bus idle.
while ((MG_REG(MG_FLEXSPI_BASE + 0xe0) & 3U) != 3U) (void) 0; // STS0
MG_REG(MG_FLEXSPI_BASE) |= MG_BIT(0); // MCR0 SWRESET
while (MG_REG(MG_FLEXSPI_BASE) & MG_BIT(0)) (void) 0;
// CLCR: invalidate by physical address. CM33 cache lines are 16 bytes.
MG_SET_BITS(cache[1], 3U << 24, MG_BIT(24) | MG_BIT(26));
for (; start < end; start += 16) {
cache[2] = (uint32_t) start | MG_BIT(0); // CSAR: address | LGO
while (cache[2] & MG_BIT(0)) (void) 0;
}
#if defined(__GNUC__) && defined(__arm__)
__asm__ __volatile__("dsb 0xf\nisb 0xf" : : : "memory");
#endif
}
#endif
MG_IRAM static bool mg_imxrt_write(void *addr, const void *buf, size_t len) {
struct mg_flexspi_nor_config config, *config_ptr = &config;
bool ok = false;
#if MG_OTA == MG_OTA_RT1180
bool modified = false;
#endif
// Interrupts must be disabled before calls to ROM API in RT1020 and 1060
MG_ARM_DISABLE_IRQ();
if (flexspi_nor_get_config(&config_ptr) != 0) goto fwxit;
@@ -12923,6 +12954,9 @@ MG_IRAM static bool mg_imxrt_write(void *addr, const void *buf, size_t len) {
ok = true;
while (ok && src < end) {
#if MG_OTA == MG_OTA_RT1180
modified = true; // Erase/program may modify flash even on failure
#endif
if (flash_page_start(dst) && flash_erase(config_ptr, dst) == false) {
ok = false;
break;
@@ -12964,6 +12998,9 @@ MG_IRAM static bool mg_imxrt_write(void *addr, const void *buf, size_t len) {
}
MG_DEBUG(("Flash write %lu bytes @ %p: %s.", len, dst, ok ? "ok" : "fail"));
fwxit:
#if MG_OTA == MG_OTA_RT1180
if (modified) flash_sync(addr, len);
#endif
if (!s_flash_irq_disabled) MG_ARM_ENABLE_IRQ();
return ok;
}