Python TypeError bug in efm8loadusb for P2D2 - help!

One of the best ways IMO for learning any language is to dive in head first. Unlike shallow waters you can't injure yourself but you sure learn a lot splashing about.
Wanting to bypass SIlabs Simplicity Studio when I just want to access the EMF8 chip's bootloader directly on my P2D2 board I found some Python code that seems to work in that it can identify the chip and even dump it's internal memory, and with a little modification it now handles the 48k of the EFMUB3 that I use. However there is one bug that I haven't worked around yet although I have learnt a few things in the process, so I am reaching out for some help just to get things going, since I need to get other things going too.

When I run this code, this is what happens.
efm8boot-master$ python efm8loadusb.py identify
The device identifies as EFM8UB31F40G_QFN24 [36: 1].
efm8boot-master$ python efm8loadusb.py upload vcp.hex
Traceback (most recent call last):
  File "efm8loadusb.py", line 422, in <module>
    sys.exit(main())
  File "efm8loadusb.py", line 419, in main
    return opts.cmd(device, opts)
  File "efm8loadusb.py", line 146, in cmd_flash
    write_chunked(dev, segment, a, chunksize=128)
  File "efm8loadusb.py", line 165, in write_chunked
    do_write(dev, addr, chunk)
  File "efm8loadusb.py", line 209, in do_write
    hid_set_report(dev, [36, dlen + 3, 0x33, addrH, addrL] + data)
  File "efm8loadusb.py", line 47, in hid_set_report
    report)
  File "/home/peter/.local/lib/python2.7/site-packages/usb/core.py", line 1023, in ctrl_transfer
    buff = _interop.as_array(data_or_wLength)
  File "/home/peter/.local/lib/python2.7/site-packages/usb/_interop.py", line 97, in as_array
    a.fromstring(data) # deprecated since 3.2
TypeError: fromstring() argument 1 must be string or read-only buffer, not list
efm8boot-master$

I have gone back into the backend packages too and tried several things on the loader to get it to work. Any ideas?

Tachyon Forth - compact, fast, forthwright and interactive
useforthlogo-s.png
--->CLICK THE LOGO for more links<---
P2 +++++ TAQOZ INTRO & LINKS +++++ P2 SHORTFORM DATASHEET
P1 +++++ Latest binary V5.4 includes EASYFILE +++++ Tachyon Forth News Blog
Brisbane, Australia

Comments

  • jmgjmg Posts: 13,609
    I've never tried the bootloader, but AN945 has command line tools, I think are python-derived-exes, so I created this batch file
    windows\hex2boot.exe -o EFM8UB3.bf EFM8UB3_2M0_8n1_ASM_UART1.hex
    windows\efm8load.exe -t EFM8UB3.bf
    pause 
    
    and that runs giving this - seems to Auto-sense the HID port, and I need to jumper P2.0-GND then RST to engage the bootloader, (and remember to remove jumper.. )
    C:\SiliconLabs\AN945SW\AN945SW\Tools>windows\hex2boot.exe -o EFM8UB3.bf EFM8UB3_2M0_8n1_ASM_UART1.hex
    
    C:\SiliconLabs\AN945SW\AN945SW\Tools>windows\efm8load.exe -t EFM8UB3.bf
    Download over port: HID:10C4:EACB
    
    $ 04 31 A5 F1 00 -> @
    $ 83 32 00 00 FF 12 CD 75 -> @
    $ 83 33 00 80 78 76 E6 FE -> @
    $ 83 33 01 00 00 00 00 00 -> @
    $ 83 33 01 80 03 F2 90 00 -> @
    $ 83 32 02 00 FF FA 90 00 -> @
    $ 83 33 02 80 00 79 00 90 -> @
    $ 83 33 03 00 F0 7B FF 7A -> @
    $ 83 33 03 80 05 0C 90 00 -> @
    $ 83 32 04 00 FE 01 F3 22 -> @
    $ 83 33 04 80 83 E9 93 F5 -> @
    $ 83 33 05 00 E9 F6 22 E0 -> @
    $ 83 33 05 80 74 02 93 68 -> @
    $ 83 32 06 00 89 32 90 00 -> @
    $ 83 33 06 80 80 F6 ED 4C -> @
    $ 83 33 07 00 50 43 78 7A -> @
    $ 83 33 07 80 AF 02 E5 AE -> @
    $ 83 32 08 00 5F 80 71 12 -> @
    $ 83 33 08 80 E0 0F 90 00 -> @
    $ 83 33 09 00 00 C3 78 8C -> @
    $ 83 33 09 80 20 E7 FB 78 -> @
    $ 83 32 0A 00 21 A3 80 11 -> @
    $ 83 33 0A 80 FE F0 90 00 -> @
    $ 83 33 0B 00 82 85 58 83 -> @
    $ 83 33 0B 80 30 19 1F 85 -> @
    $ 83 32 0C 00 A8 60 12 04 -> @
    $ 83 33 0C 80 78 E6 18 46 -> @
    $ 83 33 0D 00 78 74 E6 18 -> @
    $ 83 33 0D 80 E6 FF AC 06 -> @
    $ 83 32 0E 00 E5 2A 30 E3 -> @
    $ 83 33 0E 80 01 01 00 00 -> @
    $ 83 33 0F 00 00 01 01 02 -> @
    $ 83 33 0F 80 D4 78 76 E6 -> @
    $ 83 32 10 00 AA 27 A9 28 -> @
    $ 83 33 10 80 AE 11 E4 F5 -> @
    $ 83 33 11 00 1C 15 E5 2E -> @
    $ 83 33 11 80 1D E5 1E 24 -> @
    $ 83 32 12 00 40 60 16 75 -> @
    $ 83 33 12 80 06 70 47 F5 -> @
    $ 83 33 13 00 20 C8 83 40 -> @
    $ 83 33 13 80 33 70 1F 90 -> @
    $ 83 32 14 00 13 AF 06 74 -> @
    $ 83 33 14 80 46 12 1B 25 -> @
    $ 83 33 15 00 E6 54 F0 60 -> @
    $ 83 33 15 80 E5 34 75 F0 -> @
    $ 83 32 16 00 66 AF 63 12 -> @
    $ 83 33 16 80 82 85 50 83 -> @
    $ 83 33 17 00 75 8C 44 75 -> @
    $ 83 33 17 80 F5 83 EF F0 -> @
    $ 83 32 18 00 F8 A6 06 08 -> @
    $ 83 33 18 80 45 F0 7B 01 -> @
    $ 83 33 19 00 79 44 90 00 -> @
    $ 83 33 19 80 59 82 85 58 -> @
    $ 83 32 1A 00 AD 35 AB 31 -> @
    $ 83 33 1A 80 90 00 3E 12 -> @
    $ 83 33 1B 00 78 74 E6 18 -> @
    $ 83 33 1B 80 C5 FF 90 00 -> @
    $ 83 32 1C 00 02 20 95 90 -> @
    $ 83 33 1C 80 E7 FB E5 AF -> @
    $ 83 33 1D 00 1A 65 22 78 -> @
    $ 83 33 1D 80 00 75 5F 02 -> @
    $ 83 32 1E 00 79 44 75 5E -> @
    $ 83 33 1E 80 7B 01 7A 00 -> @
    $ 83 33 1F 00 90 00 3E 12 -> @
    $ 83 33 1F 80 70 22 90 00 -> @
    $ 83 32 20 00 79 44 75 5E -> @
    $ 83 33 20 80 FB E5 AF F0 -> @
    $ 83 33 21 00 90 00 3E 12 -> @
    $ 83 33 21 80 60 0B E5 AE -> @
    $ 83 32 22 00 20 E4 FF 02 -> @
    $ 83 33 22 80 20 E7 FB E5 -> @
    $ 83 33 23 00 75 AE 8E E5 -> @
    $ 36 33 23 80 00 52 00 54 -> @
    $ 07 34 00 00 23 B2 19 24 -> @
    $ 04 33 00 00 02 -> @
    $ 03 36 00 00 -> @
    
    Download complete with [ 0 ] errors
    
    C:\SiliconLabs\AN945SW\AN945SW\Tools>pause
    Press any key to continue . . .
    

    and the baud rate did change, so it looks like that all worked.
  • rosco_pcrosco_pc Posts: 323
    edited 2019-06-24 - 03:56:11
      ...
      File "/home/peter/.local/lib/python2.7/site-packages/usb/core.py", line 1023, in ctrl_transfer
        buff = _interop.as_array(data_or_wLength)
      File "/home/peter/.local/lib/python2.7/site-packages/usb/_interop.py", line 97, in as_array
        a.fromstring(data) # deprecated since 3.2
    TypeError: fromstring() argument 1 must be string or read-only buffer, not list
    efm8boot-master$ 
    
    mmm, pyusb is trying to convert a list to an array.array object which is failing. That means that one of the elements in the data is not an integer
    run the code with --trace to see what they try to actually send

    edit: failing that add a print(data) statement before line 208 (right before the hid_set_report(..) line)
    Stockholm, Sweden
    I am only an egg -- Stranger in a Strange land, Robert A. Heinlein
  • jmgjmg Posts: 13,609
    edited 2019-06-25 - 01:23:32
    ...
    Wanting to bypass SIlabs Simplicity Studio when I just want to access the EMF8 chip's bootloader directly on my P2D2 board I found some Python code that seems to work in that it can identify the chip and even dump it's internal memory, and with a little modification it now handles the 48k of the EFMUB3 that I use...
    The Win EXE versions of AN945SW worked as above, so I then tried the AN945SW Python sources, that proved more of a challenge...
    Some cryptic error messages later and I find it needs 64b versions of the DLL's
     https://www.silabs.com/documents/public/software/CP2112_Windows.exe
    install &  search for 
    SLABHIDDevice.dll
    SLABHIDtoSMBus.dll
    finds those copies here 
    C:\SiliconLabs\CP2112\CP2112_SDK\Library\Windows\x64
    

    and copy those to source directory...then run hex2boot.py efm8load.py
    C:\SiliconLabs\AN945SW\AN945SW\Tools\Source>"C:\Program Files\Python36\python.exe" hex2boot.py -o ..\EFM8UB3.bfy ..\EFM8UB3_2M0_8n1_ASM_UART1.hex
    C:\SiliconLabs\AN945SW\AN945SW\Tools\Source>"C:\Program Files\Python36\python.exe" efm8load.py -t ..\EFM8UB3.bfy
    Download over port: HID:10C4:EACB
    
    $ 04 31 A5 F1 00 -> @
    $ 83 32 00 00 FF 12 CD 75 -> @
    $ 83 33 00 80 78 76 E6 FE -> @
    $ 83 33 01 00 00 00 00 00 -> @
    $ 83 33 01 80 03 F2 90 00 -> @
    $ 83 32 02 00 FF FA 90 00 -> @
    $ 83 33 02 80 00 79 00 90 -> @
    $ 83 33 03 00 F0 7B FF 7A -> @
    $ 83 33 03 80 05 0C 90 00 -> @
    $ 83 32 04 00 FE 01 F3 22 -> @
    $ 83 33 04 80 83 E9 93 F5 -> @
    $ 83 33 05 00 E9 F6 22 E0 -> @
    $ 83 33 05 80 74 02 93 68 -> @
    $ 83 32 06 00 89 32 90 00 -> @
    $ 83 33 06 80 80 F6 ED 4C -> @
    $ 83 33 07 00 50 43 78 7A -> @
    $ 83 33 07 80 AF 02 E5 AE -> @
    $ 83 32 08 00 5F 80 71 12 -> @
    $ 83 33 08 80 E0 0F 90 00 -> @
    $ 83 33 09 00 00 C3 78 8C -> @
    $ 83 33 09 80 20 E7 FB 78 -> @
    $ 83 32 0A 00 21 A3 80 11 -> @
    $ 83 33 0A 80 FE F0 90 00 -> @
    $ 83 33 0B 00 82 85 58 83 -> @
    $ 83 33 0B 80 30 19 1F 85 -> @
    $ 83 32 0C 00 A8 60 12 04 -> @
    $ 83 33 0C 80 78 E6 18 46 -> @
    $ 83 33 0D 00 78 74 E6 18 -> @
    $ 83 33 0D 80 E6 FF AC 06 -> @
    $ 83 32 0E 00 E5 2A 30 E3 -> @
    $ 83 33 0E 80 01 01 00 00 -> @
    $ 83 33 0F 00 00 01 01 02 -> @
    $ 83 33 0F 80 D4 78 76 E6 -> @
    $ 83 32 10 00 AA 27 A9 28 -> @
    $ 83 33 10 80 AE 11 E4 F5 -> @
    $ 83 33 11 00 1C 15 E5 2E -> @
    $ 83 33 11 80 1D E5 1E 24 -> @
    $ 83 32 12 00 40 60 16 75 -> @
    $ 83 33 12 80 06 70 47 F5 -> @
    $ 83 33 13 00 20 C8 83 40 -> @
    $ 83 33 13 80 33 70 1F 90 -> @
    $ 83 32 14 00 13 AF 06 74 -> @
    $ 83 33 14 80 46 12 1B 25 -> @
    $ 83 33 15 00 E6 54 F0 60 -> @
    $ 83 33 15 80 E5 34 75 F0 -> @
    $ 83 32 16 00 66 AF 63 12 -> @
    $ 83 33 16 80 82 85 50 83 -> @
    $ 83 33 17 00 75 8C 44 75 -> @
    $ 83 33 17 80 F5 83 EF F0 -> @
    $ 83 32 18 00 F8 A6 06 08 -> @
    $ 83 33 18 80 45 F0 7B 01 -> @
    $ 83 33 19 00 79 44 90 00 -> @
    $ 83 33 19 80 59 82 85 58 -> @
    $ 83 32 1A 00 AD 35 AB 31 -> @
    $ 83 33 1A 80 90 00 3E 12 -> @
    $ 83 33 1B 00 78 74 E6 18 -> @
    $ 83 33 1B 80 C5 FF 90 00 -> @
    $ 83 32 1C 00 02 20 95 90 -> @
    $ 83 33 1C 80 E7 FB E5 AF -> @
    $ 83 33 1D 00 1A 65 22 78 -> @
    $ 83 33 1D 80 00 75 5F 02 -> @
    $ 83 32 1E 00 79 44 75 5E -> @
    $ 83 33 1E 80 7B 01 7A 00 -> @
    $ 83 33 1F 00 90 00 3E 12 -> @
    $ 83 33 1F 80 70 22 90 00 -> @
    $ 83 32 20 00 79 44 75 5E -> @
    $ 83 33 20 80 FB E5 AF F0 -> @
    $ 83 33 21 00 90 00 3E 12 -> @
    $ 83 33 21 80 60 0B E5 AE -> @
    $ 83 32 22 00 20 E4 FF 02 -> @
    $ 83 33 22 80 20 E7 FB E5 -> @
    $ 83 33 23 00 75 AE 8E E5 -> @
    $ 36 33 23 80 00 52 00 54 -> @
    $ 07 34 00 00 23 B2 19 24 -> @
    $ 04 33 00 00 02 -> @
    $ 03 36 00 00 -> @
    
    Download complete with [ 0 ] errors
    

    Linux notes on the same source code is here :
    https://www.silabs.com/community/mcu/8-bit/knowledge-base.entry.html/2017/10/23/how_to_use_efm8_uart-qTQD
    with a link
    https://www.silabs.com/content/usergenerated/asi/cloud/attachments/siliconlabs/en/community/mcu/8-bit/knowledge-base/jcr:content/content/primary/blog/how_to_use_efm8_uart-qTQD/AN945SW-uart-bootloader-linux.zip
Sign In or Register to comment.