How To Save A Matrix In Flash Memory In STM32
Every part of your program code is stored in flash on that microcontroller – that's the only programmable memory it has.
It's up to your compiler and linker to either leave data that you don't modify if flash and read it at runtime directly from there when you use it, or to load it into RAM first and use it from there – if you modify that data structure at runtime, you will have to have it in RAM, so non-constant things always get loaded from flash into RAM (in fact, the compiler adds code that does that loading at an appropriate time &quot;behind the scenes&quot;).
If you want some changed data to persist after a power-off, you'll have to indeed write it to flash. That requires a specific routine of system functions that you use (unlocking a flash page, erasing it, writing it, locking it again).
If you just need some constant matrix, that's in flash, anyway, and adding const will not change its storage position per se – the question is whether it gets loaded from flash to RAM first or gets directly used. Unless your matrix is too large for RAM, I'd recommend, however, just letting the compiler and linker scripts do that decision for you – flash and RAM typically have different access times.