This is driving me mad. One day with no changes to code or hardware when I try to start debugging with F5 the AVR erases and programs fine, but then AStudio stops with the error "leaveProgMode failed".
My processor is an ATMega16 on a custom board. Debugger is a Dragon and a JTAGICE2.
The weird thing is that the error does not depend on the debugger, I get the same result with wither of my debuggers. I can program the part with JTAG fine with either debugger so I know the connections are OK. The JTAG signals are nice looking on the CRO.
The same problem happens with an identical different target board, and a target board for a different project with the same processor, and even with a different PC running AStudio.
Even weirder is that I can debug a different project on the board, this one uses about 8K of the Flash, the real project is only 3K of the Flash.
I have even gone over the .cproject file line by line and made it identical to a working project, apart from the set of files included. This didn't help.
And I've reinstalled AStudio and the USB drivers.
This problem seems to crop up sporadically with no clear solution, people seem to change a few random settings and it clears.