flashing pico with stm32loader.py

Posted on
  • starting to work with a pico attached to USB.

    o connected WebIDE to pico and did a reset() and disconnected

     _____                 _
    |   __|___ ___ ___ _ _|_|___ ___
    |   __|_ -| . |  _| | | |   | . |
    |_____|___|  _|_| |___|_|_|_|___|
              |_| http://espruino.com
     1v80 Copyright 2015 G.Williams
    

    o next step: update to 1v87

    python -V
    Python 2.7.10
    
    python stm32loader.py -k -p /dev/cu.usbmodem1421 espruino_1v87_espruino_1r3.bin 
    Can't init. Ensure BOOT0=1, BOOT1=0, and reset device
    Traceback (most recent call last):
      File "stm32loader.py", line 554, in <module>
        bootversion = cmd.cmdGet()
      File "stm32loader.py", line 140, in cmdGet
        if self.cmdGeneric(0x00):
      File "stm32loader.py", line 137, in cmdGeneric
        return self._wait_for_ack(hex(cmd))
      File "stm32loader.py", line 101, in _wait_for_ack
        raise CmdException("Unrecognised response 0x%x to %s" % (ask, info))
    __main__.CmdException: Unrecognised response 0xff to 0x0
    
    

    what is missing ?

  • Unplug, and re-plug with the button held down?

  • ok - now the red and green led alternately blink

    python stm32loader.py -k -p /dev/cu.usbmodem1421 espruino_1v87_espruino_1r3.bin 
    Bootloader version 0x30
    Chip id 0x414, STM32F1, performance, high-density
    Modifying PCLK speed at 0x40021004
    

    ok - no more errors - led red and green alternately blink

    re-plug - permanent red led , usb device does not show up in WebIDE

    hmm - what else is missing ?

  • You probably want to erase first as well? see http://www.espruino.com/Serial+Bootloade­r

    python stm32loader.py -p /dev/cu.usbmodem1421 -evw espruino_1v87_espruino_1r3.bin 
    

    Hopefully on the Pico you don't need -k - not that it'll do any harm.

    If this a binary that you built yourself? If so, you need to offset the address as well with -a 0x8004000, since the Espruino binary sits on top of the bootloader in memory (images from the Espruino site contain the bootloader as well)

  • using a official build

    240488 13 Sep 11:44 espruino_1v87_espruino_1r3.bin

    python stm32loader.py -p /dev/cu.usbmodem1421 -evw espruino_1v87_espruino_1r3.bin 
    Reading data from espruino_1v87_espruino_1r3.bin
    Bootloader version 0x30
    Chip id 0x414, STM32F1, performance, high-density
    Global mass erase; this may take a while
    Writing 240488 bytes to start address 0x8000000
    Write 256 bytes at 0x8000000
    ........
    Read 256 bytes at 0x803AB00
    Verification FAILED
    240488 vs 240488
    0x1: 0xc0 vs 0x80
    .......
    0x3fff: 0xe0 vs 0xff
    

    tried a different usb cable - same result

  • Ahh, yes you could leave off the v.

    That's expected. It's because (luckily :) ) the USB bootloader won't overwrite itself - so everything between 0 and 0x3fff is the bootloader and won't match what's in the binary.

    Did you check to see if the Pico worked after this?

    (Also, are you doing this for a reason? You could just use the flasher that's built into the Web IDE...)

  • hmm, replaced -v with -X and tested some images:

    err : espruino_1v87_espruino_1r3.bin

    ok : espruino_1v87_pico_1r3_wiznet.bin

    ok : and espruino_1v87_pico_1r3_wiznet.bin

    Is there a reason why espruino_1v87_espruino_1r3.bin is not working for pico

    Which image is needed for pico + shim with esp01 ?

    WebIDE works fine, just a fan of command line tools ;-)

  • Is there a reason why espruino_1v87_espruino_1r3.bin is not working for pico

    Yes, it's the image for the Original Espruino board (not the pico), and it uses a totally different processor.

    Which image is needed for pico + shim with esp01 ?

    Either the WIZnet or CC3000 works fine. I'd say use the WIZnet one though - the code is nicer :)

  • Thanks a lot for your great support !

  • I am trying to flash an STM32F0 device and added the ID to the list by modifying the python source as follows:

    # Takes chip IDs (obtained via Get ID command) to human-readable names
    CHIP_ID_STRS = {0x410: 'STM32F1, performance, medium-density',
                    0x411: 'STM32F2',
                    0x412: 'STM32F1, performance, low-density',
                    0x413: 'STM32F4',
                    0x414: 'STM32F1, performance, high-density',
                    0x416: 'STM32L1, performance, medium-density',
                    0x418: 'STM32F1, connectivity',
                    0x420: 'STM32F1, value, medium-density',
                    0x428: 'STM32F1, value, high-density',
    		0x430: 'STM32F1, performance, XL-density',
    		0x448: 'STM32F0, performance, hi-density'
    		}
    

    Then I invoke the python script as follows:

    Proton:STM32 wayne$ python ./stm32loader.py -b 115200 -V -p /dev/tty.usbserial-FTGVKLRW -evw ./BL.bin
    

    then I get the response:

    Open port /dev/tty.usbserial-FTGVKLRW, baud 115200
    Reading data from ./BL.bin
    Traceback (most recent call last):
      File "./stm32loader.py", line 548, in <module>
        data = read(args[0])
      File "./stm32loader.py", line 442, in read
        if bytes.startswith('\x7FELF'):
    TypeError: startswith first arg must be bytes or a tuple of bytes, not str
    

    Any thoughts on whether this is python script problem? or something with the device I am trying to program? I have held the boot pin button while resetting the device.

    I should note that I am on macOS Sierra (10.12.1)

  • The indentation of the source code segment is all correct (even though this site is showing the last two entries as being indented less than the previous lines).

  • What board are you using? Sounds like this must be a custom build? I didn't realize Espruino was working on any STM32F0 parts yet!

    As for that error - could it be the python version? The python 2.7.x and 3.x versions are not entirely code compatible. When there's code that other people claim works, which you try to use and are get errors implying it could never work, that's something you should check. IME, lots of code you download doesn't work in python 3.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

flashing pico with stm32loader.py

Posted by Avatar for MaBe @MaBe

Actions