Onboard early detection and mitigation of lithium plating in fast-charging batteries