This may be difficult to do. You want a switching device that turns on by default when the supply voltage is low. The microcontroller cannot be in the circuit at such a time (I think).
Your switching device could be a transistor (or mosfet), with a pullup/pulldown resistor at the bias.
Then when the supply voltage rises, the microcontroller comes to life. Eventually it sends a signal to the transistor, overriding the pullup/down resistor, in order to shut off charging current.
There is a question which is more convenient to use, a P-device or N-device. It will depend on whether your microcontroller needs to sense voltage referenced to 0V ground, or whether it can do so in reference to the positive supply.
In fact you may not necessarily need a microcontroller, but just a comparator, op amp, etc.