Page 1 of 1

Pyboard switches to DFU mode by itself

Posted: Mon May 20, 2019 12:06 pm
by mnik
Hi,

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 main.py
- 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.enter_raw_repl()
    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("direction.low()")
    pyb.exec("tim = Timer(2, freq=" + f_ser + ")")
    pyb.exec("ch = tim.channel(1, Timer.PWM, pin=step)")
    pyb.exec("ch.pulse_width_percent(50)")
    pyb.exec("pyb.delay("+ t_ser + ")") 
    pyb.exec("tim.deinit()")
    pyb.exec("machine.reset()")
    pyb.exit_raw_repl()
    pyb.close()
I found out that after I run the code above without resetting the machine at the end, main.py 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?

Re: Pyboard switches to DFU mode by itself

Posted: Mon May 20, 2019 12:58 pm
by dhylands
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.