Gas versus solid-phase deuterated chemistry: HDCO and D₂CO in massive star-forming regions