I'm using MDK-Lite Version 5.23 with a STMicroelectronics STM32F072B-Disco "Discovery" board and I am trying to use the Flash Example provided by the Discovery samples.
I've used this board and toolchain for other examples and I have coded some SPI and GPIO work. The IDE works like a champ. However, for this particular project I can build the code and run it by downloading and using the reset button. I cannot use the debugger on the project as soon as I use the HAL_FLASHEx_Erase() routine. Once I execute that routine the IDE pops up a dialog "Cannot access target. Shutting down debug session."
For what it's worth, I know it's not a programming error because if I download the code and then execute the code by pressing the reset button it will work. I've used this same debugger with a TI board and it was able to program flash and execute flash routines as well. I'm pretty sure I'm not erasing the portion of flash where the code is stored, so it's not that.
If I step over this line in main.c
if (HAL_FLASHEx_Erase(&EraseInitStruct, &PageError) != HAL_OK)
then it drops the debug session. If I instead step into the same line and then step over each of the calls in the flash erase routine, then it will work and eventually step out of the routine and I can debug the rest of the code.