Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 7 May 2022 20:46:55 +0800
From:      Archimedes Gaviola <archimedes.gaviola@gmail.com>
To:        Hans Petter Selasky <hps@selasky.org>
Cc:        freebsd-arm@freebsd.org
Subject:   Re: Raspberry Pi 3B Over-current USB
Message-ID:  <CAJFbk7EHTyDs7%2BUEOkScJc%2BMDH-VaofqWWXSW7Vrw1unT6JpBA@mail.gmail.com>
In-Reply-To: <8542947f-a62d-08c8-bb0e-ba3b6b973fec@selasky.org>
References:  <CAJFbk7FgSnWvN9Z7gp1wqW1CFa8bYqrr6zccMWEhotk5HMR=Tg@mail.gmail.com> <5deaf68b-267c-56dd-603d-8ec0d82ceae2@selasky.org> <CAJFbk7Hv7BHDqmg6tFaGwgFvt6%2B2%2Bu0nkCBPrqvGiNN--Y63zQ@mail.gmail.com> <8dc68431-ad3d-84db-45b4-cd661d4a15df@selasky.org> <CAJFbk7EKpwMCav87nMg_5squJx_L-cO%2BeNfKSn5jA620uKT2YA@mail.gmail.com> <CAJFbk7HOUm74UGS0hchGg-w9RdbKj1k8B3fcfaq8i48C1CY42A@mail.gmail.com> <8542947f-a62d-08c8-bb0e-ba3b6b973fec@selasky.org>

next in thread | previous in thread | raw e-mail | index | archive | help
--00000000000055928a05de6b5fae
Content-Type: text/plain; charset="UTF-8"

On Sat, May 7, 2022 at 5:20 PM Hans Petter Selasky <hps@selasky.org> wrote:

> On 5/6/22 16:03, Archimedes Gaviola wrote:
> > On Tue, Apr 12, 2022 at 5:16 PM Archimedes Gaviola <
> > archimedes.gaviola@gmail.com> wrote:
> >
> >>
> >>
> >> On Mon, Apr 11, 2022 at 9:59 PM Hans Petter Selasky <hps@selasky.org>
> >> wrote:
> >>
> >>> On 4/11/22 15:59, Archimedes Gaviola wrote:
> >>>> Hi Hans,
> >>>>
> >>>> Noted on the self-powered hub, thanks for the suggestion, I will try.
> >>>>
> >>>> Just wanted to share the observation from the testing I've conducted
> >>> with
> >>>> my Raspberry Pi 4B with the same 14.0-CURRENT to check if overcurrent
> is
> >>>> also experienced and it did, there was overcurrent and each ports'
> power
> >>>> shut-off during the situation but it was able to recover back. I
> >>> initiated
> >>>> the command 'usbconfig reset' and each port gloriously came back alive
> >>> one
> >>>> by one and loaded my USB keyboard and Prolific uplcom(4) drivers into
> >>>> functional and operational states. My measuring device is showing the
> >>> same
> >>>> amount of current 460mA while the voltage stayed at 5.05 from a
> >>> baseline of
> >>>> 5.15 voltshttps://filebin.net/10vy575q6h2yl8og. Unlike my RPi 3B,
> >>> voltage
> >>>> dropped to 4.93 from a baseline of 5.19 volts. So, the difference I
> >>>> observed is when the voltage dropped below 5, the system will not
> give a
> >>>> chance to make the ports come back alive as a sort of protection
> >>> mechanism.
> >>>> Sharing to you the logs below (with hw.usb.uhub.debug=1).
> >>>
> >>> FreeBSD does not actively check and use "bMaxPower" .
> >>>
> >>
> >> Hi Hans,
> >>
> >> It's okay, just tried your recommendation on a self-powered USB hub, my
> >> Prolific device is now working. Thanks a lot!
> >>
> >> Archimedes
> >>
> >
> > Hi Hans,
> >
> > I got my Prolific PL2303 USB-serial device working in RPi 3B without the
> > self-powered USB hub. I've extended the code
> /usr/src/sys/dev/usb/usb_hub.c
> > in the uhub_explore() routine specific to handling overcurrent condition.
> > Below are the added lines of code.
> >
> > freebsd@generic:~ % diff -Nur /usr/src/sys/dev/usb/usb_hub.c.orig
> > /usr/src/sys/dev/usb/usb_hub.c
> > --- /usr/src/sys/dev/usb/usb_hub.c.orig 2022-04-29 10:52:44.787344000
> +0000
> > +++ /usr/src/sys/dev/usb/usb_hub.c      2022-05-03 07:29:45.159470000
> +0000
> > @@ -1045,6 +1045,25 @@
> >                              udev, NULL, portno,
> UHF_C_PORT_OVER_CURRENT);
> >                          if (err != USB_ERR_NORMAL_COMPLETION)
> >                                  retval = err;
> > +
> > +                       /* Turn on hub port power if current get
> > normalized. */
> > +                       DPRINTF("Turn on power on port %d.\n", portno);
> > +                       err = usbd_req_set_port_feature(
> > +                           udev, NULL, portno, UHF_PORT_POWER);
> > +                       if (err != USB_ERR_NORMAL_COMPLETION)
> > +                               retval = err;
>
> You need a sleep here, to wait for power to come back on.
>
> > +
> > +                       /* Re-validate if overcurrent still exists. */
> > +                       err = uhub_read_port_status(sc, portno);
> > +                       if (err != USB_ERR_NORMAL_COMPLETION)
> > +                               retval = err;
> > +                       if (sc->sc_st.port_change &
> > UPS_C_OVERCURRENT_INDICATOR) {
> > +                               DPRINTF("Overcurrent condition on port
> > %u.\n", portno);
> > +                               err = usbd_req_clear_port_feature(
> > +                                   udev, NULL, portno,
> > UHF_C_PORT_OVER_CURRENT);
> > +                               if (err != USB_ERR_NORMAL_COMPLETION)
> > +                                       retval = err;
> > +                       }
> >                  }
> >
>
> Can you upload the patch to https://reviews.freebsd.org and add
> "hselasky" as reviewer?
>

Thank you Hans for the feedback! Just created an account and once approved
and activated then I'll upload it. Meanwhile, for the sleep you've
mentioned what particular function should be used? I tried these two,
sleep(3) and usleep(3) but seems to encounter errors during compilation.

--00000000000055928a05de6b5fae
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div dir=3D"ltr"><br></div><br><div class=3D"gmail_quote">=
<div dir=3D"ltr" class=3D"gmail_attr">On Sat, May 7, 2022 at 5:20 PM Hans P=
etter Selasky &lt;<a href=3D"mailto:hps@selasky.org">hps@selasky.org</a>&gt=
; wrote:<br></div><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px=
 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On 5/6/=
22 16:03, Archimedes Gaviola wrote:<br>
&gt; On Tue, Apr 12, 2022 at 5:16 PM Archimedes Gaviola &lt;<br>
&gt; <a href=3D"mailto:archimedes.gaviola@gmail.com" target=3D"_blank">arch=
imedes.gaviola@gmail.com</a>&gt; wrote:<br>
&gt; <br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; On Mon, Apr 11, 2022 at 9:59 PM Hans Petter Selasky &lt;<a href=3D=
"mailto:hps@selasky.org" target=3D"_blank">hps@selasky.org</a>&gt;<br>
&gt;&gt; wrote:<br>
&gt;&gt;<br>
&gt;&gt;&gt; On 4/11/22 15:59, Archimedes Gaviola wrote:<br>
&gt;&gt;&gt;&gt; Hi Hans,<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; Noted on the self-powered hub, thanks for the suggestion, =
I will try.<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; Just wanted to share the observation from the testing I&#3=
9;ve conducted<br>
&gt;&gt;&gt; with<br>
&gt;&gt;&gt;&gt; my Raspberry Pi 4B with the same 14.0-CURRENT to check if =
overcurrent is<br>
&gt;&gt;&gt;&gt; also experienced and it did, there was overcurrent and eac=
h ports&#39; power<br>
&gt;&gt;&gt;&gt; shut-off during the situation but it was able to recover b=
ack. I<br>
&gt;&gt;&gt; initiated<br>
&gt;&gt;&gt;&gt; the command &#39;usbconfig reset&#39; and each port glorio=
usly came back alive<br>
&gt;&gt;&gt; one<br>
&gt;&gt;&gt;&gt; by one and loaded my USB keyboard and Prolific uplcom(4) d=
rivers into<br>
&gt;&gt;&gt;&gt; functional and operational states. My measuring device is =
showing the<br>
&gt;&gt;&gt; same<br>
&gt;&gt;&gt;&gt; amount of current 460mA while the voltage stayed at 5.05 f=
rom a<br>
&gt;&gt;&gt; baseline of<br>
&gt;&gt;&gt;&gt; 5.15 voltshttps://<a href=3D"http://filebin.net/10vy575q6h=
2yl8og" rel=3D"noreferrer" target=3D"_blank">filebin.net/10vy575q6h2yl8og</=
a>. Unlike my RPi 3B,<br>
&gt;&gt;&gt; voltage<br>
&gt;&gt;&gt;&gt; dropped to 4.93 from a baseline of 5.19 volts. So, the dif=
ference I<br>
&gt;&gt;&gt;&gt; observed is when the voltage dropped below 5, the system w=
ill not give a<br>
&gt;&gt;&gt;&gt; chance to make the ports come back alive as a sort of prot=
ection<br>
&gt;&gt;&gt; mechanism.<br>
&gt;&gt;&gt;&gt; Sharing to you the logs below (with hw.usb.uhub.debug=3D1)=
.<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; FreeBSD does not actively check and use &quot;bMaxPower&quot; =
.<br>
&gt;&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; Hi Hans,<br>
&gt;&gt;<br>
&gt;&gt; It&#39;s okay, just tried your recommendation on a self-powered US=
B hub, my<br>
&gt;&gt; Prolific device is now working. Thanks a lot!<br>
&gt;&gt;<br>
&gt;&gt; Archimedes<br>
&gt;&gt;<br>
&gt; <br>
&gt; Hi Hans,<br>
&gt; <br>
&gt; I got my Prolific PL2303 USB-serial device working in RPi 3B without t=
he<br>
&gt; self-powered USB hub. I&#39;ve extended the code /usr/src/sys/dev/usb/=
usb_hub.c<br>
&gt; in the uhub_explore() routine specific to handling overcurrent conditi=
on.<br>
&gt; Below are the added lines of code.<br>
&gt; <br>
&gt; freebsd@generic:~ % diff -Nur /usr/src/sys/dev/usb/usb_hub.c.orig<br>
&gt; /usr/src/sys/dev/usb/usb_hub.c<br>
&gt; --- /usr/src/sys/dev/usb/usb_hub.c.orig 2022-04-29 10:52:44.787344000 =
+0000<br>
&gt; +++ /usr/src/sys/dev/usb/usb_hub.c=C2=A0 =C2=A0 =C2=A0 2022-05-03 07:2=
9:45.159470000 +0000<br>
&gt; @@ -1045,6 +1045,25 @@<br>
&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 udev, NULL, portno, UHF_C_PORT_OVER_CURR=
ENT);<br>
&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 if (err !=3D USB_ERR_NORMAL_COMPLETION)<br>
&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 retval =3D err;<br>
&gt; +<br>
&gt; +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=
 =C2=A0 =C2=A0/* Turn on hub port power if current get<br>
&gt; normalized. */<br>
&gt; +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=
 =C2=A0 =C2=A0DPRINTF(&quot;Turn on power on port %d.\n&quot;, portno);<br>
&gt; +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=
 =C2=A0 =C2=A0err =3D usbd_req_set_port_feature(<br>
&gt; +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=
 =C2=A0 =C2=A0 =C2=A0 =C2=A0udev, NULL, portno, UHF_PORT_POWER);<br>
&gt; +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=
 =C2=A0 =C2=A0if (err !=3D USB_ERR_NORMAL_COMPLETION)<br>
&gt; +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=
 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0retval =3D err;<br>
<br>
You need a sleep here, to wait for power to come back on.<br>
<br>
&gt; +<br>
&gt; +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=
 =C2=A0 =C2=A0/* Re-validate if overcurrent still exists. */<br>
&gt; +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=
 =C2=A0 =C2=A0err =3D uhub_read_port_status(sc, portno);<br>
&gt; +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=
 =C2=A0 =C2=A0if (err !=3D USB_ERR_NORMAL_COMPLETION)<br>
&gt; +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=
 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0retval =3D err;<br>
&gt; +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=
 =C2=A0 =C2=A0if (sc-&gt;sc_st.port_change &amp;<br>
&gt; UPS_C_OVERCURRENT_INDICATOR) {<br>
&gt; +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=
 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0DPRINTF(&quot;Overcurrent conditi=
on on port<br>
&gt; %u.\n&quot;, portno);<br>
&gt; +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=
 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0err =3D usbd_req_clear_port_featu=
re(<br>
&gt; +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=
 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0udev, NULL, portno,=
<br>
&gt; UHF_C_PORT_OVER_CURRENT);<br>
&gt; +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=
 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if (err !=3D USB_ERR_NORMAL_COMPL=
ETION)<br>
&gt; +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=
 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0retva=
l =3D err;<br>
&gt; +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=
 =C2=A0 =C2=A0}<br>
&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 }<br>
&gt; <br>
<br>
Can you upload the patch to <a href=3D"https://reviews.freebsd.org" rel=3D"=
noreferrer" target=3D"_blank">https://reviews.freebsd.org</a>; and add <br>
&quot;hselasky&quot; as reviewer?<br></blockquote><div><br></div></div><div=
 class=3D"gmail_quote">Thank you Hans for the feedback! Just created an acc=
ount and once approved and activated then I&#39;ll upload it. Meanwhile, fo=
r the sleep you&#39;ve mentioned what particular function should be used? I=
 tried these two, sleep(3) and usleep(3) but seems to encounter errors duri=
ng compilation.<br></div></div>

--00000000000055928a05de6b5fae--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAJFbk7EHTyDs7%2BUEOkScJc%2BMDH-VaofqWWXSW7Vrw1unT6JpBA>