(a) On the entry of a plea of guilty or nolo contendere, the justice or municipal court may hear proof regarding the offense and assess the punishment.
(b) A justice or judge may not accept a plea of guilty or nolo contendere from a defendant in open court unless it appears to the justice or judge that the defendant is mentally competent and the plea is free and voluntary.