Hi Vitaly,
Hope you are doing well. Could you please clarify what your main objective is? From my understanding , it seems to me that you would like to implement flash security. Is this correct?
In the section 8.3.1 of the Reference Manual, it says that when flash security is active, the SWD port cannot access the memory resources of the MCU, this may be causing you isses. However, what can be done, is a mass erase.
If you have any questions please don't hesitate to ask.
Best Regards,
Ricardo