Saturday, July 4, 2015

Updating the Firmware on my Pyboard


Before I begin the post proper, an aside...

Larry Cuban just made a wonderful blog post titled Fixing Schools Again, and Again in which he says,
"If amnesia were like aphrodisiac pills, policymakers have been popping capsules for years. Memory loss about past school reforms permits policymakers to forge ahead with a new brace of reforms and feel good."
To an educator of 24 years these words ring so true!  Time and time again I've watched my own school system move from one initiative to another, never stopping for a moment to look back at where we've been so that we might learn something from our journey.



In this intensive Summer of learning, I've been trying to juggle several learning goals, each associated with either NOVA Web Development or the future IT curriculum at Arlington Tech (or hopefully, both):
  1. GIS, specially web GIS mapping of LIDAR data
  2. Firefox OS App development
  3. Django and django CMS
  4. MicroPython programming on the pyboard
This post will document the process of updating the firmware on the pyboard.

I'll be using the Pyboard Firmware Update guide my dear friend and co-conspirator Kevin Cole mentioned in a blog post, along with the instructions Kevin documented in the same post.

The first step in the process is to connect my pyboard physically to my to my desktop workstation by USB cable and verify that I can interact with it. When I connected the cable, a filesystem named PYBFLASH auto-mounted, showing these contents:
Kevin says to run screen, when I checked, I didn't have screen installed, so I ran:
$ sudo aptitude install screen dfu-util
    When I tried to connect to the pyboard using screen, it failed:
    $ screen /dev/ttyACM0
    [screen is terminating]
    $
    
    So I checked to see if the device was there:.
    $ ls -l /dev/ttyACM*
    crw-rw---- 1 root dialout 166, 0 Jul 4 15:39 /dev/ttyACM0
    $
    Ahh, I bet I'm not in the dialout group.
    $ groups [username]
    [username] : [username] adm cdrom sudo dip plugdev lpadmin sambashare
    $ sudo adduser [username] dialout
    [sudo] password for [username]:
    Adding user `[username]' to group `dialout' ...
    Adding user [username] to group dialout
    Done.
    $ groups [username]
    [username] : [username] adm dialout cdrom sudo dip plugdev lpadmin sambashare
    That's better.  I still needed to restart my machine before I could connect, but after that screen /dev/ttyACM0 gave me a blank screen, and after I hit <Enter> I saw:
    Traceback (most recent call last):
      File "", line 1
    SyntaxError: invalid syntax
    >>> 
    
    I'm in! Now let me move on upgrading the firmware.  Typing ^D (that's Ctrl+D) at the python prompt gave me:
    PYB: sync filesystems
    PYB: soft reboot
    Micro Python v1.3.10 on 2015-02-13; PYBv1.0 with STM32F405RG
    Type "help()" for more information.
    >>>
    Kevin's next instruction says, "Next, disconnect the USB cable, jumper the BOOT0 and 3V3 pins, and reconnect the USB cable".  There is a picture of this on the Pyboard Firmware Update guide:
    The problem is that I'm at my grandmother's house in a rural part of South Jersey without a car. Just how am I going to "jumper"?  Kevin and I asked our friend Paul Flint in Vermont, who has a knack for solving these sorts of problems.  He suggested a paper clip.  Why didn't I think of that?
    My pyboard with paper clip jumper
    I downloaded the latest micropython image (pybv10-2015-07-04-v1.4.4-65-gb19d273.dfu at the time of this writing) and reconnected by pyboard by USB.
    $ lsusb
    Bus 003 Device 002: ID 8087:8001 Intel Corp.
    Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
    Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
    Bus 001 Device 003: ID 8087:0a2a Intel Corp.
    Bus 001 Device 009: ID 0424:2228 Standard Microsystems Corp. 9-in-2 Card Reader
    Bus 001 Device 008: ID 0424:2602 Standard Microsystems Corp. USB 2.0 Hub
    Bus 001 Device 007: ID 0424:2514 Standard Microsystems Corp. USB 2.0 Hub
    Bus 001 Device 006: ID 413c:3016 Dell Computer Corp. Optical 5-Button Wheel Mouse
    Bus 001 Device 005: ID 046d:0825 Logitech, Inc. Webcam C270
    Bus 001 Device 004: ID 413c:2003 Dell Computer Corp. Keyboard
    Bus 001 Device 002: ID 050d:0234 Belkin Components F5U234 USB 2.0 4-Port Hub
    Bus 001 Device 012: ID 0483:df11 STMicroelectronics STM Device in DFU Mode
    Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
    I've highlighted in green the line we are interested in.
    $ sudo dfu-util -l
    [sudo] password for [username]:
    dfu-util 0.8

    Copyright 2005-2009 Weston Schmidt, Harald Welte and OpenMoko Inc.
    Copyright 2010-2014 Tormod Volden and Stefan Schmidt
    This program is Free Software and has ABSOLUTELY NO WARRANTY
    Please report bugs to dfu-util@lists.gnumonks.org

    Found DFU: [0483:df11] ver=2200, devnum=12, cfg=1, intf=0, alt=3, name="@Device Feature/0xFFFF0000/01*004 e", serial="346135523333"
    Found DFU: [0483:df11] ver=2200, devnum=12, cfg=1, intf=0, alt=2, name="@OTP Memory /0x1FFF7800/01*512 e,01*016 e", serial="346135523333"
    Found DFU: [0483:df11] ver=2200, devnum=12, cfg=1, intf=0, alt=1, name="@Option Bytes  /0x1FFFC000/01*016 e", serial="346135523333"
    Found DFU: [0483:df11] ver=2200, devnum=12, cfg=1, intf=0, alt=0, name="@Internal Flash  /0x08000000/04*016Kg,01*064Kg,07*128Kg", serial="346135523333"
    Again, I highlighted in green the line we are looking for, the internal flash.
    $ sudo dfu-util --alt 0 -D pybv10-2015-07-04-v1.4.4-65-gb19d273.dfu 
    dfu-util 0.8
    
    Copyright 2005-2009 Weston Schmidt, Harald Welte and OpenMoko Inc.
    Copyright 2010-2014 Tormod Volden and Stefan Schmidt
    This program is Free Software and has ABSOLUTELY NO WARRANTY
    Please report bugs to dfu-util@lists.gnumonks.org
    
    Match vendor ID from file: 0483
    Match product ID from file: df11
    Opening DFU capable USB device...
    ID 0483:df11
    Run-time device DFU version 011a
    Claiming USB DFU Interface...
    Setting Alternate Setting #0 ...
    Determining device status: state = dfuERROR, status = 10
    dfuERROR, clearing status
    Determining device status: state = dfuIDLE, status = 0
    dfuIDLE, continuing
    DFU mode device DFU version 011a
    Device returned transfer size 2048
    DfuSe interface name: "Internal Flash  "
    file contains 1 DFU images
    parsing DFU image 1
    image for alternate setting 0, (2 elements, total size = 273128)
    parsing element 1, address = 0x08000000, size = 13580
    Download [=========================] 100%        13580 bytes
    Download done.
    parsing element 2, address = 0x08020000, size = 259532
    Download [=========================] 100%       259532 bytes
    Download done.
    done parsing DfuSe file
    $ 
    
    After disconnecting the pyboard, removing the jumper (paper clip), and reconnecting the pyboard and starting a screen session to it, and typing ^D, I was rewarded for my efforts when I saw:
    PYB: sync filesystems
    PYB: soft reboot
    Micro Python v1.4.4-65-gb19d273 on 2015-07-04; PYBv1.0 with STM32F405RG
    Type "help()" for more information.
    >>> 
    
    Now let's see what Kevin and the MicroPython interns can do with our newly flashed pyboards...



    1 comment: