vthielen
Posts: 35
Joined: Wed Mar 05, 2014 9:32 am

usb problem with GSM modem

Tue Feb 17, 2015 9:42 am

I am using a RPI B+ (3.12.22+) with a huawei USB GSM modem (GPRS) and I have the following problem:
My program switches the stick off and on using "hub-ctrl -h 0 -P 2 -p 0/1" to spare power and so the RF signal does not interfere with measurements.
This goes will for some time, but after some tens of on/off cycles the USB stick stops working.
When this is the case, unplugging and re-plugging into the same connector doesn't help, but when I plug it into a different USB connector it works again.

When it doesn't work, lsusb doesn't show it any more, and when I look into /var/messages, I see the following:

[email protected]:/home/pi/cabineMonitor# dmesg
[62504.064198] usb 1-1.5: new full-speed USB device number 114 using dwc_otg
[62504.144238] usb 1-1.5: device descriptor read/64, error -71
[62504.334232] usb 1-1.5: device descriptor read/64, error -71
[62504.524229] usb 1-1.5: new full-speed USB device number 115 using dwc_otg
[62504.604238] usb 1-1.5: device descriptor read/64, error -71
[62504.794233] usb 1-1.5: device descriptor read/64, error -71
[62504.984289] usb 1-1.5: new full-speed USB device number 116 using dwc_otg
[62505.404118] usb 1-1.5: device not accepting address 116, error -71
[62505.484293] usb 1-1.5: new full-speed USB device number 117 using dwc_otg
[62505.904101] usb 1-1.5: device not accepting address 117, error -71
[62505.904324] hub 1-1:1.0: unable to enumerate USB device on port 5

lsusb -t shows:
[email protected]:/home/pi/cabineMonitor# lsusb -t
/: Bus 01.Port 1: Dev 1, Class=root_hub, Driver=dwc_otg/1p, 480M
|__ Port 1: Dev 2, If 0, Class=hub, Driver=hub/5p, 480M
|__ Port 1: Dev 3, If 0, Class=vend., Driver=smsc95xx, 480M

After resetting the RPI by shorting the P5 header pins, everything works again, and lsusb shows:

[email protected]:~# lsusb -t
/: Bus 01.Port 1: Dev 1, Class=root_hub, Driver=dwc_otg/1p, 480M
|__ Port 1: Dev 2, If 0, Class=hub, Driver=hub/5p, 480M
|__ Port 1: Dev 3, If 0, Class=vend., Driver=smsc95xx, 480M
|__ Port 5: Dev 36, If 0, Class=vend., Driver=option, 12M
|__ Port 5: Dev 36, If 1, Class=vend., Driver=option, 12M
|__ Port 5: Dev 36, If 2, Class=vend., Driver=option, 12M
|__ Port 5: Dev 36, If 3, Class=vend., Driver=option, 12M
|__ Port 5: Dev 36, If 4, Class=stor., Driver=usb-storage, 12M

This can't be a power issue, because after reboot, it works consistently for many USB power cycles, and when it starts to fail, it also fails consistently until reboot.

I would like to solve this problem using a software command, when it happens.
Is there any command with which I can reset the internal USB hub? (I think that might solve the problem)

jdb
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 2123
Joined: Thu Jul 11, 2013 2:37 pm

Re: usb problem with GSM modem

Tue Feb 17, 2015 2:25 pm

How long are you powering off the device for?

It's possible you are leaving it in a funny state by switching it on/off quickly.
Rockets are loud.
https://astro-pi.org

vthielen
Posts: 35
Joined: Wed Mar 05, 2014 9:32 am

Re: usb problem with GSM modem

Wed Feb 18, 2015 1:02 pm

I have increased all delaytimes in the python script, so now there is 20 seconds between switching off and switching on again, then 20 more seconds before it starts wvdial.
The result is still the same: the usb bus locks up after switching the modem on and of about 40 times.

Something else that I noticed, it that in the beginning, the problem is more subtle: the modem still connects and gets an IP address, but 'hangs up' a couple of seconds later, before anything useful can be done.
After a few more power cycles it disappears from the usb bus: lsusb doesn't show it any more when on, and additional power cycles don't bring it back.

I also put a 4700uF capacitor over the USB bus supply. The scope now shows only 200mV drops during transmit, so I am quite sure it is not a supply problem.

Is there a way to completely reset the RPI USB bus soft- and hardware when this happens, without issuing a reboot command?

User avatar
topguy
Posts: 5901
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: usb problem with GSM modem

Wed Feb 18, 2015 1:28 pm

I wonder if you really break the power to the USB device with hub-crtl or just disconnects it. Have you measured the 5V output from the hub and see that it really drops to 0V ? This could easily be a bug (or safety feature) in the USB-firmware in the modem.

vthielen
Posts: 35
Joined: Wed Mar 05, 2014 9:32 am

Re: usb problem with GSM modem

Wed Feb 18, 2015 2:06 pm

Yes, I see the voltage drop, and I also see the modem re-initialising when I turn it back on (it blinks a blue led when it powers up)
physically removing it from the USB connector and re-plugging it into the SAME connector gives the same result.
Plugging it into another the other USB connector solves the problem, but the system should run without human slaves. (a monkey might be ok though, have to ask my boss about it...)

jdb
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 2123
Joined: Thu Jul 11, 2013 2:37 pm

Re: usb problem with GSM modem

Wed Feb 18, 2015 4:09 pm

Is the modem still commercially available?
Rockets are loud.
https://astro-pi.org

vthielen
Posts: 35
Joined: Wed Mar 05, 2014 9:32 am

Re: usb problem with GSM modem

Wed Feb 18, 2015 4:18 pm

This is what is logged in /var/messages when it starts failing by disconnecting too soon (see below)
I am seeing messages about usb mass storage, and I know that these modem sticks on first use behave as a memory stick, that holds their installation program.
For linux, you need to use "usb_modeswitch" (see https://wiki.archlinux.org/index.php/US ... _switching) to get the modem to behave as an actual modem.
I am starting to think that at some point, the RPI is trying to access it as a memory stick anyway, thereby interrupting the ppp deamon, which hangs up.

I have tried resetting all USB using “echo '1-1' | tee /sys/bus/usb/drivers/usb/unbind” but that didn't help either.

Feb 18 17:03:55 aardbei pppd[9504]: pppd 2.4.5 started by root, uid 0
Feb 18 17:03:55 aardbei pppd[9504]: Using interface ppp0
Feb 18 17:03:55 aardbei pppd[9504]: Connect: ppp0 <--> /dev/ttyUSB0
Feb 18 17:03:59 aardbei pppd[9504]: CHAP authentication succeeded
Feb 18 17:03:59 aardbei pppd[9504]: CHAP authentication succeeded
Feb 18 17:04:04 aardbei pppd[9504]: Could not determine remote IP address: defaulting to 10.64.64.64
Feb 18 17:04:04 aardbei pppd[9504]: local IP address 188.5.90.172
Feb 18 17:04:04 aardbei pppd[9504]: remote IP address 10.64.64.64
Feb 18 17:04:04 aardbei pppd[9504]: primary DNS address 80.201.237.239
Feb 18 17:04:04 aardbei pppd[9504]: secondary DNS address 80.201.237.238
Feb 18 17:04:21 aardbei pppd[9504]: Modem hangup
Feb 18 17:04:21 aardbei kernel: [ 8406.086655] option1 ttyUSB0: GSM modem (1-port) converter now disconnected from ttyUSB0
Feb 18 17:04:21 aardbei kernel: [ 8406.086743] option 1-1.5:1.0: device disconnected
Feb 18 17:04:21 aardbei kernel: [ 8406.090446] option1 ttyUSB1: GSM modem (1-port) converter now disconnected from ttyUSB1
Feb 18 17:04:21 aardbei kernel: [ 8406.090553] option 1-1.5:1.1: device disconnected
Feb 18 17:04:21 aardbei kernel: [ 8406.090895] option1 ttyUSB2: GSM modem (1-port) converter now disconnected from ttyUSB2
Feb 18 17:04:21 aardbei kernel: [ 8406.090976] option 1-1.5:1.2: device disconnected
Feb 18 17:04:21 aardbei kernel: [ 8406.091287] option1 ttyUSB3: GSM modem (1-port) converter now disconnected from ttyUSB3
Feb 18 17:04:21 aardbei kernel: [ 8406.091374] option 1-1.5:1.3: device disconnected
Feb 18 17:04:21 aardbei pppd[9504]: Connect time 0.3 minutes.
Feb 18 17:04:21 aardbei pppd[9504]: Sent 0 bytes, received 0 bytes.
Feb 18 17:04:21 aardbei pppd[9504]: Connection terminated.
Feb 18 17:04:21 aardbei kernel: [ 8406.184695] usb 1-1.5: reset full-speed USB device number 69 using dwc_otg
Feb 18 17:04:21 aardbei pppd[9504]: Exit.
Feb 18 17:04:21 aardbei kernel: [ 8406.290339] usb-storage 1-1.5:1.0: USB Mass Storage device detected
Feb 18 17:04:21 aardbei kernel: [ 8406.295228] option 1-1.5:1.0: GSM modem (1-port) converter detected
Feb 18 17:04:21 aardbei kernel: [ 8406.298527] usb 1-1.5: GSM modem (1-port) converter now attached to ttyUSB1
Feb 18 17:04:21 aardbei kernel: [ 8406.298697] usb-storage 1-1.5:1.1: USB Mass Storage device detected
Feb 18 17:04:21 aardbei kernel: [ 8406.305357] option 1-1.5:1.1: GSM modem (1-port) converter detected
Feb 18 17:04:21 aardbei kernel: [ 8406.305966] usb 1-1.5: GSM modem (1-port) converter now attached to ttyUSB2
Feb 18 17:04:21 aardbei kernel: [ 8406.306127] usb-storage 1-1.5:1.2: USB Mass Storage device detected
Feb 18 17:04:21 aardbei kernel: [ 8406.307405] option 1-1.5:1.2: GSM modem (1-port) converter detected
Feb 18 17:04:21 aardbei kernel: [ 8406.307878] usb 1-1.5: GSM modem (1-port) converter now attached to ttyUSB3
Feb 18 17:04:21 aardbei kernel: [ 8406.308028] usb-storage 1-1.5:1.3: USB Mass Storage device detected
Feb 18 17:04:21 aardbei kernel: [ 8406.308655] option 1-1.5:1.3: GSM modem (1-port) converter detected
Feb 18 17:04:21 aardbei kernel: [ 8406.309165] usb 1-1.5: GSM modem (1-port) converter now attached to ttyUSB4


vthielen
Posts: 35
Joined: Wed Mar 05, 2014 9:32 am

Re: usb problem with GSM modem

Thu Feb 19, 2015 2:34 pm

I have now updated all software and I am at kernel version 3.18.7+, but I still have the same problem:
When I plug unplug something in the failing USB port I only get this in the /var/log/messages:

Feb 19 15:32:43 aardbei kernel: [ 8195.531922] usb 1-1.5: new full-speed USB device number 82 using dwc_otg
Feb 19 15:32:43 aardbei kernel: [ 8195.991933] usb 1-1.5: new full-speed USB device number 83 using dwc_otg
Feb 19 15:32:43 aardbei kernel: [ 8196.451884] usb 1-1.5: new full-speed USB device number 84 using dwc_otg
Feb 19 15:32:44 aardbei kernel: [ 8196.951966] usb 1-1.5: new full-speed USB device number 85 using dwc_otg

Why it finds 4 new devices is a mystery to me, but it is not reading/ enumerating any of them, and as a result it doesn't appear on lsusb

vthielen
Posts: 35
Joined: Wed Mar 05, 2014 9:32 am

Re: usb problem with GSM modem

Thu Feb 19, 2015 4:17 pm

update:
I have written a python script (see at bottom) that does nothing else but turning the usb port on and off.
I put another USB device (a TI launchpad experimenter board) on the USB bus.
I notice that the device ID keeps increasing, and after it reached 82, it no longer appeared on the bus.
I have the impression that the hub thinks there are actually 82 devices on the bus, and I should have somehow released the device from the bus each time that I turn it off.
Is there any way to do this?

The output of the script when it starts to fail is:
Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp.
Bus 001 Device 081: ID 0451:f432 Texas Instruments, Inc. eZ430 Development Tool
Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp.
Bus 001 Device 082: ID 0451:f432 Texas Instruments, Inc. eZ430 Development Tool
Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp.
Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp.
Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

the script itself is:

#!/usr/bin/python
from subprocess import call
import time

while True:
call(["hub-ctrl", "-h", "0", "-P", "2", "-p", "0"]) # turn off the USB modem
time.sleep(1)
call(["hub-ctrl", "-h", "0", "-P", "2", "-p", "1"]) # turn off the USB modem
time.sleep(2)
call(["lsusb"]) # print

kuki21
Posts: 1
Joined: Tue Jul 14, 2015 8:52 am

Re: usb problem with GSM modem

Tue Jul 14, 2015 8:55 am

Hi

I can confirm that i have same issue on my PI. Any news about this ?

vthielen
Posts: 35
Joined: Wed Mar 05, 2014 9:32 am

Re: usb problem with GSM modem

Tue Apr 05, 2016 11:58 am

sorry for the late reply.
I changed and recompiled the hub-ctrl command a bit, so it does a FULL reset of the USB hub.
I run this (USBreset) command each time when I detect the problem.
If it 's still relevant, then I can send you the changes to the sourcecode of hub-ctrl

edo1
Posts: 136
Joined: Sun Jun 15, 2014 3:33 pm
Location: Russia

Re: usb problem with GSM modem

Fri Apr 08, 2016 1:24 pm

IMHO it is better to publish your patch on github or something like that.

itsagoodquestion
Posts: 47
Joined: Sat Mar 05, 2016 10:30 pm

Re: usb problem with GSM modem

Fri Apr 08, 2016 3:37 pm

If I am understand everything correctly, all you wants to do is disable modem to reduce power consumption? If this is case there is AT commands you can send (if supported by your firmware, +CFUN= low power mode, turn radio off mode, offline mode, and more) that will physically turn radio off, but obviously you can no use it in this state and must turn back on again.

vthielen
Posts: 35
Joined: Wed Mar 05, 2014 9:32 am

Re: usb problem with GSM modem

Tue Oct 04, 2016 9:16 am

Somebody asked me for the reset program, so I will put it here also:
This reset clears the problems that are mentioned above.

/* usbreset -- send a USB port reset to a USB device */

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/ioctl.h>

#include <linux/usbdevice_fs.h>


int main(int argc, char **argv)
{
const char *filename;
int fd;
int rc;

if (argc != 2) {
fprintf(stderr, "Usage: usbreset device-filename\n");
return 1;
}
filename = argv[1];

fd = open(filename, O_WRONLY);
if (fd < 0) {
perror("Error opening output file");
return 1;
}

printf("Resetting USB device %s\n", filename);
rc = ioctl(fd, USBDEVFS_RESET, 0);
if (rc < 0) {
perror("Error in ioctl");
return 1;
}
printf("Reset successful\n");

close(fd);
return 0;
}

Return to “Interfacing (DSI, CSI, I2C, etc.)”