Pyboard switches to DFU mode by itself

The official pyboard running MicroPython.
This is the reference design and main target board for MicroPython.
You can buy one at the store.
Target audience: Users with a pyboard.
Post Reply
Posts: 1
Joined: Thu May 09, 2019 9:46 pm

Pyboard switches to DFU mode by itself

Post by mnik » Mon May 20, 2019 12:06 pm


I came across a DFU issue in my project. Basic information:
- two buttons are connected to the pyboard 1.1's digital inputs, the user can move a stepper motor manually by pressing them. This code is located in
- user can also provide a PWM frequency and time delay and pyboard will move the motor according to that. This piece of code runs on PC:

Code: Select all

import pyboard 

def serial(f1, t1):

    t_ser = str(int(t1)) 
    f_ser = str(f1)
    pyb = pyboard.Pyboard('com7') 
    pyb.exec('from pyb import Pin, Timer')
    pyb.exec("import time")
    pyb.exec("import machine")
    pyb.exec("step = Pin('X1')")
    pyb.exec("direction = Pin('X2', Pin.OUT_PP)")
    pyb.exec("tim = Timer(2, freq=" + f_ser + ")")
    pyb.exec("ch =, Timer.PWM, pin=step)")
    pyb.exec("pyb.delay("+ t_ser + ")") 
I found out that after I run the code above without resetting the machine at the end, doesn't run again so the manual movement doesn't work anymore. I tried with sys.exit(), didn't solve the problem, so I went with machine.reset() which works. I noticed that after doing this a couple of times in a row, pyboard sometimes switches to DFU mode by itself, the number of resets after this happens looks random. Disconnecting pyboard's USB cable and connecting it again puts it back into normal mode. Any clues how I can correct that?

User avatar
Posts: 3246
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada

Re: Pyboard switches to DFU mode by itself

Post by dhylands » Mon May 20, 2019 12:58 pm

The only reason that the pyboard should be entering DFU mode is if the BOOT0 pin (which is labeled DFU on the back of the pyboard) is being pulled high during reset. The schematic shows a pulldown on that pin, but if it had a cold solder joint or something then that could happen. You might want to try connecting DFU directly to ground and see if that helps.

Post Reply