STMicroelectronics device having dfu mode i want to detect serial number using python. i'm not getting any soluton.

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
premannd8
Posts: 2
Joined: Tue May 05, 2020 10:00 pm

STMicroelectronics device having dfu mode i want to detect serial number using python. i'm not getting any soluton.

Post by premannd8 » Tue May 05, 2020 10:12 pm

Hi,
I'm having STMicroelectronics device which is in dfu mode i want to do upgrade but i'm unable to get python code to solve this problem. please help me.

User avatar
jimmo
Posts: 1633
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: STMicroelectronics device having dfu mode i want to detect serial number using python. i'm not getting any soluton.

Post by jimmo » Thu May 07, 2020 3:47 am

premannd8 wrote:
Tue May 05, 2020 10:12 pm
Hi,
I'm having STMicroelectronics device which is in dfu mode i want to do upgrade but i'm unable to get python code to solve this problem. please help me.
Hi,

Which ST device do you have? What sort of board? Are you able to get it into DFU mode with the BOOT0 pin?

Your best bet is to use dfu-util (see https://www.hanselman.com/blog/HowToFix ... ndows.aspx if you're using Windows), or the official ST tools.

Otherwise you can use pydfu.py which is part of hte MicroPython repo. https://github.com/micropython/micropyt ... s/pydfu.py

premannd8
Posts: 2
Joined: Tue May 05, 2020 10:00 pm

Re: STMicroelectronics device having dfu mode i want to detect serial number using python. i'm not getting any soluton.

Post by premannd8 » Sun May 17, 2020 2:29 pm

https://github.com/premananda8/usb/blob ... _libusb.py
please see above code using libusb in that code i want solution i'm not getting serial number when device is DFU, code is working perfectly when device is not in dfu mode. please help me.

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

Re: STMicroelectronics device having dfu mode i want to detect serial number using python. i'm not getting any soluton.

Post by dhylands » Sun May 17, 2020 4:08 pm

When the device is in DFU mode,

Code: Select all

dfu-util --list
shows the serial number at the end of each memory region:

Code: Select all

$ dfu-util --list
dfu-util 0.9

Copyright 2005-2009 Weston Schmidt, Harald Welte and OpenMoko Inc.
Copyright 2010-2016 Tormod Volden and Stefan Schmidt
This program is Free Software and has ABSOLUTELY NO WARRANTY
Please report bugs to http://sourceforge.net/p/dfu-util/tickets/

Found DFU: [0483:df11] ver=2200, devnum=2, cfg=1, intf=0, path="20-2", alt=3, name="@Device Feature/0xFFFF0000/01*004 e", serial="336133663433"
Found DFU: [0483:df11] ver=2200, devnum=2, cfg=1, intf=0, path="20-2", alt=2, name="@OTP Memory /0x1FFF7800/01*512 e,01*016 e", serial="336133663433"
Found DFU: [0483:df11] ver=2200, devnum=2, cfg=1, intf=0, path="20-2", alt=1, name="@Option Bytes  /0x1FFFC000/01*016 e", serial="336133663433"
Found DFU: [0483:df11] ver=2200, devnum=2, cfg=1, intf=0, path="20-2", alt=0, name="@Internal Flash  /0x08000000/04*016Kg,01*064Kg,07*128Kg", serial="336133663433"

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

Re: STMicroelectronics device having dfu mode i want to detect serial number using python. i'm not getting any soluton.

Post by dhylands » Sun May 17, 2020 4:25 pm

With the following change to micropython/tools/pydfu.py running pydfu.py --list will show the serial number:

Code: Select all

diff --git a/tools/pydfu.py b/tools/pydfu.py
index 658ce59ae..7236f838c 100755
--- a/tools/pydfu.py
+++ b/tools/pydfu.py
@@ -462,9 +462,10 @@ def list_dfu_devices(*args, **kwargs):
         print("No DFU capable devices found")
         return
     for device in devices:
-        print("Bus {} Device {:03d}: ID {:04x}:{:04x}"
+        print("Bus {} Device {:03d}: ID {:04x}:{:04x} Serial {}"
               .format(device.bus, device.address,
-                      device.idVendor, device.idProduct))
+                      device.idVendor, device.idProduct,
+                      get_string(device, device.iSerialNumber)))
         layout = get_memory_layout(device)
         print("Memory Layout")
         for entry in layout:
Here's the output of pydfu.py --list with the above change:

Code: Select all

$ ./pydfu.py --list
Bus 3 Device 005: ID 0483:df11 Serial 336133663433
Memory Layout
    0x8000000  4 pages of  16K bytes
    0x8010000  1 pages of  64K bytes
    0x8020000  7 pages of 128K bytes

Post Reply