Python DFU util

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
iabdalkader
Posts: 14
Joined: Fri Mar 28, 2014 11:35 pm

Re: Python DFU util

Post by iabdalkader » Wed Oct 22, 2014 1:04 pm

Yes it doesn't matter where it lives, as long as it's somewhere in the same repo.

blmorris
Posts: 348
Joined: Fri May 02, 2014 3:43 pm
Location: Massachusetts, USA

Re: Python DFU util

Post by blmorris » Wed Oct 22, 2014 2:47 pm

Hey guys - nice work, and I'm excited to use this, but I can't get it to work on my Mac.

Running python3.4, I installed pyusb using "sudo pip3 install --pre pyusb"
This worked, eliminated the first error message I got:

Code: Select all

Traceback (most recent call last):
  File "pydfu.py", line 20, in <module>
    import usb.core
ImportError: No module named 'usb'
However now I get the following:

Code: Select all

stmhal bryan$ python3 pydfu.py -u build-PYBV10/firmware.dfu 
File: build-PYBV10/firmware.dfu
    b'DfuSe' v1, image size: 247553, targets: 1
Traceback (most recent call last):
  File "pydfu.py", line 527, in <module>
    main()
  File "pydfu.py", line 514, in main
    elements = read_dfu_file(args.path)
  File "pydfu.py", line 295, in read_dfu_file
    img_prefix['name'] = cstring(img_prefix['name'])
  File "pydfu.py", line 242, in cstring
    return string.split('\0', 1)[0]
TypeError: Type str doesn't support the buffer API
Any thoughts? I haven't tried to dig into the error message yet, just wondering if there is something obvious, maybe another library package, that I might be missing.
-Bryan

iabdalkader
Posts: 14
Joined: Fri Mar 28, 2014 11:35 pm

Re: Python DFU util

Post by iabdalkader » Wed Oct 22, 2014 3:07 pm

Line 242:

Code: Select all

    return string.decode('utf-8').split('\0', 1)[0]
Also fixed it in my repo and confirmed working with Py3

blmorris
Posts: 348
Joined: Fri May 02, 2014 3:43 pm
Location: Massachusetts, USA

Re: Python DFU util

Post by blmorris » Wed Oct 22, 2014 3:42 pm

@iabdalkader - That did it, and just as intended it jumped to application mode without me needing to remove the DFU jumper and press reset. Thanks, and nice work!
-Bryan

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

Re: Python DFU util

Post by dhylands » Wed Oct 22, 2014 9:07 pm

@blmorris: There is a pyb.bootloader() command so that you don't even need the DFU jumper any more (except in rare cases).

iabdalkader
Posts: 14
Joined: Fri Mar 28, 2014 11:35 pm

Re: Python DFU util

Post by iabdalkader » Thu Oct 23, 2014 4:11 am

dhylands wrote:@blmorris: There is a pyb.bootloader() command so that you don't even need the DFU jumper any more (except in rare cases).
I saw the tear-down approach and jump to DFU, we set a magic byte instead in SRAM and reset and branch on to dfu, much easier.

blmorris
Posts: 348
Joined: Fri May 02, 2014 3:43 pm
Location: Massachusetts, USA

Re: Python DFU util

Post by blmorris » Thu Oct 23, 2014 7:53 pm

dhylands wrote:@blmorris: There is a pyb.bootloader() command so that you don't even need the DFU jumper any more (except in rare cases).
True, but if you issue that command from a REPL over USB then it has the downside of clobbering the terminal program by eliminating the tty device it is connected to. Not a catastrophe usually, and it is certainly possible to type 'pyb.delay(10000); pyb.bootloader()' to give myself time to exit gracefully, but I have still found the jumper method to be convenient enough for my purposes ;)
Not to dismiss the utility, of course. I am sure that I will make heavy use of these features to jump back and forth between DFU and application mode once we start putting micropython into our products. For now I was just commenting that the automatic jump to application mode was a nice feature.
-Bryan

iabdalkader
Posts: 14
Joined: Fri Mar 28, 2014 11:35 pm

Re: Python DFU util

Post by iabdalkader » Fri Oct 24, 2014 4:48 am

blmorris wrote: True, but if you issue that command from a REPL over USB then it has the downside of clobbering the terminal program by eliminating the tty device it is connected to. Not a catastrophe usually, and it is certainly possible to type 'pyb.delay(10000); pyb.bootloader()' to give myself time to exit gracefully, but I have still found the jumper method to be convenient enough for my purposes ;)
Not to dismiss the utility, of course. I am sure that I will make heavy use of these features to jump back and forth between DFU and application mode once we start putting micropython into our products. For now I was just commenting that the automatic jump to application mode was a nice feature.
-Bryan
It's possible to add a vendor request to jump into DFU, which can be sent from the script, so the whole process (dfu->program->reset) can be done with a single command without ever touching the board.

Post Reply