Hi Yan Sun,
How do you test it, do you just debug the code and check the memory data?
If yes, it's the IDE's problem, when you use the __attribute__ ((section(".mysection1"))) uint32_t flash_data[128]; The IDE seems protect the memory according address.
Actually, I also use the printf to see the data, I find the flash erase and program all works.
Please check my test result and the attached code:
1. Erase

You can find the memory still 0 after erase, but the printf data is 0XFF, it's correct.
2. Program.

Please use my attached project.
In the optimization, please don't select the data section, do it like the following code:
