Update driver and template to fix APB state issue introduced by while loop