Flash write fails after using lv_scr_load() on STM32F103RG with LVGL

I am integrating LVGL into my STM32F103RG project. Everything works fine until I try to write to Flash after loading a screen.

  • Before calling lv_scr_load(), I can successfully write data to a specific Flash location using my flash_writeWord function.
  • After calling lv_scr_load() to load a new screen, the same flash_writeWord function fails — the data is not written.

I suspect the issue is related to LVGL accessing Flash resources (such as images or fonts) after screen loading, which conflicts with the Flash write operation.

Has anyone encountered a similar issue? How do you safely write to Flash while using LVGL? Should I move my Flash write function to RAM, or is there a better approach?

Thank you for your help!

I think that LVGL and flash programming do not have nothing in common that can make this failure happens, but I need more context to understand what’s going on. I use STM32 a lot but never encountered flash_writeWord as function to write to flash, rather I use HAL_FLASH_Program all time.
Which IDE do you use to write your code? May you provide some more context on your code, or maybe the prototypes of the functions you are using?