I'm working with STM32f027B discovery board, Keil uVision 5.23 MDK and the FLASH_EraseProgram FLASH Erase and Program example. When I try to step through the flash programming example in the debugger, it disconnects from the debugger when it executes the first HAL routine associated with Flash. The precise routine is HAL_FLASHEx_Erase() . Once that line is executed, the IDE displays a message "Cannot access target. Shutting down debug session" and then the debugger detaches. Any idea how to modify the example code so I can run it in the MDK debugger?