Hello,
I would like to add a couple of findings.
The first finding is obvious. Interrupts absolutely must be off when executing flash IP commands. This makes sense. We even store the interrupt vectors on the flash; so I can understand why this would cause problems.
Trick #1 then is
__asm("cpsid i");
... immediately at boot (for this instance -- so the plan is to generally disable it).
How-ever, this is strangely not insufficient to avoid hangs when erasing or writing. The second requirement, and this is where I am fully stumped; is to disable AHB prefetching on the FlexSPI module after calling the NOR Initialization code:
status = ROM_FLEXSPI_NorFlash_Init(flexspi_instance, &g_nor_config);
// disable ahb prefetching here to avoid hangs
base->AHBCR |= FLEXSPI_AHBCR_PREFETCHEN_MASK;
base->AHBCR &= ~(FLEXSPI_AHBCR_PREFETCHEN_MASK);
...
status = ROM_FLEXSPI_NorFlash_Erase(flexspi_instance, &g_nor_config, 0x0F0000, 4096);
...etc.
where base is just a pointer to FLEXSPI2 module interface.
So far I have re-run this code 10 times and it does not fail.
But this approach seems fragile; and I absolutely must understand *why* this works. I can get a vague sense of the problem; since FLEXSPI module will read more data and put it into AHB prefetch buffers, the IP commands interfering with this data somehow makes sense.
Is this a known errata?