You are not logged in.

#1 2021-07-31 21:51:11

Popolon
Member
Registered: 2020-09-28
Posts: 18

[SOLVED] Bug with dfu and Longan Nano

I have a problem to upload image with dfu protocol on my current Arch Linux on x86_64 platform. Other people reported it worked with them with the same configuration. It work for me from an Arch Linux ARM on a Cubieboard2 (Allwinner A20 SoC) so exclude a problem with Longan Nano board, and on the same computer and same tools on a  Debian 10, so exclude the x86_64  hardware problem too.

I tried in root and user, anyway the right for flashing it as user should be ok, as I installed (as on Arch Linux ARM) platformio rules (from the package with the same name) in /etc/udev/rules.d/99-platformio-udev.rules. The relevant lines about this board in DFU Bootloader mode is:

#GD32V DFU Bootloader
ATTRS{idVendor}=="28e9", ATTRS{idProduct}=="0189", MODE="0666", ENV{ID_MM_DEVICE_IGNORE}="1", ENV{ID_MM_PORT_IGNORE}="1"

The problem: I see the Longan Nano board with lsusb, when I boot it in dfu bootloader mode (pressing flash mode button+reset button on the board)

Bus 001 Device 004: ID 28e9:0189 GDMicroelectronics GD32 DFU Bootloader (Longan Nano)

But when I try any dfu tool, it fail and device disappear from lsusb listing. I looked in my blacklist, I only have the intel integrated audio chipset from my Asus x86_64 board (too much noise, I use a cheap headset with DSP in USB connector that have far better quality).

I tried with both dfu-tool, platformio gd32v package (use own version of dfu-util), GD32V version of dfu-util (should be integrated in mainline now ?)  and  Bronzebeard  (I packaged the AUR and use it on ArchLinux ARM) an assembler+bare metal base system that use its own python dfu system (that use pyusb/pyserial).

For example, with bronzebeard when I try to flash a mandelbrot example (works from ArchLinux ARM, with the same PKGBUILD/updated system), when I

make flash

I have a:

python3 -m bronzebeard.dfu 28e9:0189 mandelbrot.bin
device not found: 28e9:0189

And then the device isn't displayed anymore, until, I reset it, and reset in bootloader again.

Here are the outputs during the flash sequence in dmesg:

[32976.310910] usb 1-1.5: New USB device found, idVendor=28e9, idProduct=0189, bcdDevice= 1.00
[32976.310918] usb 1-1.5: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[32976.310920] usb 1-1.5: SerialNumber: 䌳䩂
[32985.398712] usb 1-1.5: reset full-speed USB device number 9 using ehci-pci
[32985.472123] usb 1-1.5: device descriptor read/64, error -32
[32985.652077] usb 1-1.5: device descriptor read/64, error -32
[32985.832088] usb 1-1.5: reset full-speed USB device number 9 using ehci-pci
[32985.905444] usb 1-1.5: device descriptor read/64, error -32
[32986.085378] usb 1-1.5: device descriptor read/64, error -32
[32986.265392] usb 1-1.5: reset full-speed USB device number 9 using ehci-pci
[32986.678714] usb 1-1.5: device not accepting address 9, error -32
[32986.752058] usb 1-1.5: reset full-speed USB device number 9 using ehci-pci
[32987.165387] usb 1-1.5: device not accepting address 9, error -32
[32987.165876] usb 1-1.5: USB disconnect, device number 9
[32987.238780] usb 1-1.5: new full-speed USB device number 10 using ehci-pci
[32987.312051] usb 1-1.5: device descriptor read/64, error -32
[32987.492049] usb 1-1.5: device descriptor read/64, error -32
[32987.672084] usb 1-1.5: new full-speed USB device number 11 using ehci-pci
[32987.745375] usb 1-1.5: device descriptor read/64, error -32
[32987.925390] usb 1-1.5: device descriptor read/64, error -32
[32988.032258] usb 1-1-port5: attempt power cycle
[32988.628714] usb 1-1.5: new full-speed USB device number 12 using ehci-pci
[32989.042044] usb 1-1.5: device not accepting address 12, error -32
[32989.115386] usb 1-1.5: new full-speed USB device number 13 using ehci-pci
[32989.528712] usb 1-1.5: device not accepting address 13, error -32
[32989.528857] usb 1-1-port5: unable to enumerate USB device

I also have the following error:

sudo make flash
python3 -m bronzebeard.dfu 28e9:0189 mandelbrot.bin
Found GD32 device, overriding page size and count
Traceback (most recent call last):
  File "/usr/lib/python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/usr/lib/python3.9/site-packages/bronzebeard/dfu.py", line 299, in <module>
    main()
  File "/usr/lib/python3.9/site-packages/bronzebeard/dfu.py", line 198, in main
    sn = dev.serial_number.encode('utf-16-le').decode('utf-8')
  File "/usr/lib/python3.9/site-packages/usb/core.py", line 864, in serial_number
    self._serial_number = util.get_string(self, self.iSerialNumber)
  File "/usr/lib/python3.9/site-packages/usb/util.py", line 313, in get_string
    raise ValueError("The device has no langid"
ValueError: The device has no langid (permission issue, no string descriptors supported or device error)
make: *** [Makefile:9 : flash] Erreur 1

Does someone have any clue or an idea of somewhere to search?

Last edited by Popolon (2021-08-01 08:12:56)

Offline

#2 2021-08-01 08:12:16

Popolon
Member
Registered: 2020-09-28
Posts: 18

Re: [SOLVED] Bug with dfu and Longan Nano

I searched for "device descriptor read/64, error -32", didn't find what the error code is. There are some error code referenced in kernel doc here, but not their numerical values: https://www.kernel.org/doc/html/v4.17/d … codes.html

anyway by searching this I found some other people having several sort of USB problems with different error codes (-110, -71,...)

Their solution resolved my problem too, this is a bug with USB autosuspend. It should be disabled by -1 (or 0 depending on systems)

To test immediately, added the value in sys (need root access, sudo should not work as the redirection is outside the sudoed command:

sudo bash
echo -1 >/sys/module/usbcore/parameters/autosuspend

And now it works:

$ make flash
python3 -m bronzebeard.dfu 28e9:0189 mandelbrot.bin
Found GD32 device, overriding page size and count
page_size: 1024
page_count: 128
old size: 918
new size: 1024
padding: 106
pages: 1
erasing: 0x08000000
writing: 0x08000000
done!

For disabled autosuspend permanently, see the Wiki
I have autosuspend at different places:
* /etc/tlp.conf (default: #USB_AUTOSUSPEND=1)

For permanent autosuspend disabled for this board in DFU + my Logitech mouse, I used this method

sudo bash
cat >/etc/udev/rules.d/50-usb_power_save.rules <<EOF
# blacklist for usb autosuspend
# Longan Nano
ACTION=="add", SUBSYSTEM=="usb", ATTRS{idVendor}=="28e9", ATTRS{idProduct}=="0189", GOTO="power_usb_rules_end"
# Logitech mouse
ACTION=="add", SUBSYSTEM=="usb", ATTRS{idVendor}=="046d", ATTRS{idProduct}=="c077", GOTO="power_usb_rules_end"

# Default other devices to autosuspend
ACTION=="add", SUBSYSTEM=="usb", TEST=="power/control", ATTR{power/control}="auto"
LABEL="power_usb_rules_end"
EOF

Last edited by Popolon (2021-08-01 09:32:33)

Offline

Board footer

Powered by FluxBB