Switching power supply reverse driving protection circuit
Reverse protection for regulators is easier than it sounds, but USB makes it harder

Fortunately, your problem (your regulator not liking being backpowered with its input off) is actually easy to solve, albeit not as easy as it initially looks.  On first guess, you'd think a diode from output to input of the regulator would solve the problem, and you're almost right:







simulate this circuit &ndash; Schematic created using CircuitLab

However, the fact we're dealing with a USB-powered device makes this a bit harder.  You see, one of the many rules in the USB specification is that devices shall never backfeed power onto their "upstream" USB connection.  In fact, some USB hosts can be damaged or confused by backfeed.

So, we need to toss another diode in to make sure that nothing bad happens to a turned-off USB host if the board is being powered by the programming dongle:







simulate this circuit

With the extra diode in there, now the regulator is safe from being powered up "backwards" and powering it up "backwards" won't backfeed the USB port, either.