Conditions for Setting the DTC
WARNING: This page is about a different car, the 2010 GMC Sierra, 2010 GMC Cab & Chassis Sierra, 2010 Chevrolet Silverado, and 2010 Chevrolet Cab & Chassis Silverado. However, it is still accessible from the selected car via links, so may be relevant.
DTC B3031 will set any time the TDM enters the learn coded keys state.