Hello,
Almost the same question asked in this post.
You can't write to that memory while executing from it. You said it yourself: you need to switch from memory-mapped mode to indirect/command mode so the instruction fetch is no more available.
Need either:
- To use two external XSPI memories: one for execution and one for the data storage so you don't have a such issue. Refer to the AN6228 "How to implement XSPI read-while-write feature on STM32 MCUs"
- Or to execute that code that writes to the external flash from the internal Flash (could be a bit tricky).
Hope I've answered your question.
To give better visibility on the answered topics, please click "Best answer" on the reply which solved your issue or answered your question.