Power mode and program stm32 device
For those who face the same problem, i solved this using st-link utility
1)First go to settings and change the connection setting to jtag.
2)Upgrade de firmware, change back to SWD.
3)Go to option bytes, put Read Out Protection in Level 0 and unselect all sectors(this will disable the protection and allow the flash to be erased).
After some research i found that &quot;low power modes disable the debugger and some other parts of the circuitry that i try to communicate with&quot; (Author: clive1, in https://community.st.com/s/ )