Since Keil MDK 5.25 does not have the bug anymore, we recommend to update (see Downloads section)
As this question is being asked from time to time in H8 mini thread, I'll write a short answer here:
Note: If you're trying to erase a “fresh” board, the time between battery plug-in and erase is limited, be aware of that and do it as fast as you can / repeat if it didn't work!
Here is how krillex does it: Link to post
Regarding flashing the blue board for the first time I also have some problems but this is what I do:
1. Connect usb-programmer and battery to fc.
2. Run the “st-link upgrade tool” and update firmware (even if it's already updated). Close the upgrade software.
3. Erase memory from within Keil.
4. Disconnect usb-programmer from PC and battery from fc.
5. Reconnect programmer to PC and battery to fc.
6. Run the “upgrade tool” again. Close upgrade tool.
7. Download software from within Keil.
Any flashings after that, just use download in Keil (use “upgrade tool” first).
It's the first time with a new blue board that is problematic.
I'm sure there are other ways to get it working but that procedure works good for me.
Another version from Ian444: Link to post
Yet another recipe. Must be carried out in this order. Keil can be open, but minimised on the PC.
1. Open the ST-Link Utility program.
2. Connect ST-Link to USB port. Do not connect ST-Link to quad yet.
3. Click “connect” in ST-Link Utility program.
4. You get a “cannot connect” message.
5. Close the message and close the ST-Link Utility program. Now the ST-Link is “initialised”.
6. Open (or maximise) Keil, connect the quad, connect the quad's battery and flash it.
Note for first erase and flash - usually it is needed to disconnect and then reconnect the battery after the erase and before the flash. No need to disconnect the quad or the ST-Link (or do anything in Keil) when doing this.