LeMury
Posts: 33
Joined: Mon Jun 11, 2018 3:06 pm

LdB's USB driver

Thu Jul 26, 2018 2:20 pm

Hello,

I'm trying to get LdB's 32-bit USB driver to work on Pi2/3.

https://github.com/LdB-ECM/Raspberry-Pi ... m32_64_USB

The included binary seems to work but after compiling the source code the produced binary does not!
It simply repeats HDC: Unable to clear halt on channel 2 and a connected USB mouse doesn't get powered up.

Tools/compiler used:
gcc-arm-none-eabi-7-2018-q2-update-win32

Any thoughts?

LdB
Posts: 874
Joined: Wed Dec 07, 2016 2:29 pm

Re: LdB's USB driver

Thu Aug 02, 2018 7:05 am

Just got back from conference and holiday.

It will be an alignment issue with the struct I haven't dealt with correctly that the new compiler version is hitting .. my bad will fix.

I was playing around with the Xinu driver as well on here
viewtopic.php?f=72&t=215928&start=25
It has the interrupt implementation done so I will add that in as well so you don't have to software poll the driver.

Will try to get it updated tonight.

LdB
Posts: 874
Joined: Wed Dec 07, 2016 2:29 pm

Re: LdB's USB driver

Thu Aug 02, 2018 10:46 pm

Fixed, I am working on new interrupt version now.

Note, I have changed to using makefiles as I found the wonderful conversion of the GNU tools under the ezwinports project.
https://sourceforge.net/projects/ezwinports/files/
I simply download "make-4.2.1-without-guile-w32-bin.zip" which gives me make 4.2.1 on a windows executable and set it on the enviroment path

the makefile supports 4 builds
make Pi1
make Pi2
make Pi3
make Pi3-64

the clean is the usual
make clean

I left a sample Pi3-32.bat if you want to do it the old way.

LeMury
Posts: 33
Joined: Mon Jun 11, 2018 3:06 pm

Re: LdB's USB driver

Fri Aug 03, 2018 3:51 pm

Great!
I'm on vacation myself now. Will check asap.
Thanks for your work!

LeMury
Posts: 33
Joined: Mon Jun 11, 2018 3:06 pm

Re: LdB's USB driver

Sun Aug 19, 2018 9:32 am

Hi LdB,

Your USB/HID driver example now works as is, but fails as soon as MMU caches are enabled.
I have put the driver buffers in uncached memory but that didn't seem to help.
Any pointers which parts of the driver code might need additional cache flushes?

LdB
Posts: 874
Joined: Wed Dec 07, 2016 2:29 pm

Re: LdB's USB driver

Sun Aug 19, 2018 10:15 am

It was designed as a redux for me when learning it and there are no memory barriers in the code at all.
You know the standard rule, barrier before the first hardware access and after the last .. you need to start there.
If you turn on the full dump log you can easily work out where it crashes and patch it.

I would also suggest if you are serious about using the code you might want to look at the xinu driver which I modified around that code and does have memory barriers and interrupt polling. It will be out on my GIT later tonight.

LeMury
Posts: 33
Joined: Mon Jun 11, 2018 3:06 pm

Re: LdB's USB driver

Sun Aug 19, 2018 12:39 pm

Ok, I got it to work with caches enabled
As I suspected I needed to flush the data buffers in HCDChannelTransfer().

I'll have a look at the Xinu code.

Btw, what's with the custom myMemCopy() function?
Seems superfluous to me.
Good ol memcpy() works fine.

Cheers.

LdB
Posts: 874
Joined: Wed Dec 07, 2016 2:29 pm

Re: LdB's USB driver

Sun Aug 19, 2018 1:41 pm

Memcpy is problematic depending on your compiler because it isn't clear that the code produced is alignment aware in the opcode it produces and the pointers are void* so no hint from them.

The better libraries and compilers know to check the void* pointers for 1/2/4byte alignment and call different optimized code for the copy but I ran into a lot that don't. Writing code that specifically transfers byte by byte means the code generated has to work byte aligned and gets around poor libraries crashing out with alignment faults. The unaligned transfers are tiny on headers etc, the big transfer go thru DMA and have to be 4 byte aligned or the PI DMA won't work.

The comment on it was my frustration with the state of GCC and libraries especially with early CortexA53 AARCH64 where you used to hit it continually. GCC used to have a bad habit of inlining the memcpy code with an alignment fault code.

Since GCC 6.2 or there about, it seems to have improved dramatically and I rarely see the problem.

LeMury
Posts: 33
Joined: Mon Jun 11, 2018 3:06 pm

Re: LdB's USB driver

Sat Aug 25, 2018 1:01 pm

@LdB,

I am trying to expand your USB driver to support the MIDI device class.
However, if I attach an USB device other then some HID device it fails on the "get device descriptor" setup phase.

That is;

EnumerateDevice()->HCDSumbitControlMessage()->HCDChannelTransfer()
Result: -8 Action: 0x10000001 tempInt: 0x82 tempSplit: -2147483648 Bytes sent: 0

HCD: SETUP packet to device: 0 req: 6 req Type: 80 Speed: 1 PacketSize: 0 LowNode: 0 LowPort: 0 Error: -10
Enumeration: Step 1 on device 4 failed, Result: 0, transferred: 0

+-USB Root Hub id: 1 port: 0 speed: Full packetsize: 64
À-USB 2.0 Hub id: 2 port: 0 speed: High packetsize: 64
Ã-USB 2.0 Hub id: 3 port: 0 speed: High packetsize: 64
À-New Device (Not Ready) id: 0 port: 1 speed: Full packetsize: 8

I know your driver only supports HID devices but shouldn't the get_device_desciptor phase work regardless?

LdB
Posts: 874
Joined: Wed Dec 07, 2016 2:29 pm

Re: LdB's USB driver

Sat Aug 25, 2018 2:56 pm

Yes it should still enumerate even things it doesn't know ... I have thrown USB hard drives, USB sound headsets and all sorts of weird stuff.
The error is a response timeout by the way.

Does the device work on the PI running linux?

The only thing I know you can't do on the Pi is attach a slow peripheral behind the back of a USB 3 hub as it physically locks the BUS up. The USB 3 is not an issue it just gets set as a USB2 but it's have a slow peripheral behind it that causes the problem .

The other thing you could try is just stick my currrent Xinu binary on and see what it makes of the device as it is my most up todate USB driver.
You can either use a keyboard or stick the a uart terminal on and type "usbinfo" and tell me if it enumerates it.
https://github.com/LdB-ECM/Exchange/tree/master/Xinu

I will update the CSUD redux driver with the those changes to bring it up todate on git just as a thing anyhow. That will give you interrupt polling if you want anyhow.

Oh are you working in 32bit or 64bit ?

LeMury
Posts: 33
Joined: Mon Jun 11, 2018 3:06 pm

Re: LdB's USB driver

Sat Aug 25, 2018 4:31 pm

Thanks LdB!

Ok, I will try Linux on the pi and test the USB devices.

I work in 32-bit, Rpi3

LeMury
Posts: 33
Joined: Mon Jun 11, 2018 3:06 pm

Re: LdB's USB driver

Sat Aug 25, 2018 7:11 pm

Ok, I have tried your currrent Xinu binary and the usb midi interface is enumerated properly.
However, your kernel8-32.img binary at
https://github.com/LdB-ECM/Raspberry-Pi ... SB/DiskImg
does not enumerate anything other then HID keyboard and mouse.

LdB
Posts: 874
Joined: Wed Dec 07, 2016 2:29 pm

Re: LdB's USB driver

Sat Aug 25, 2018 7:51 pm

It's something I have already fixed then :-)

It's to late to deal with tonight but I will add all the changes in tomorrow. I really need to spend some time cleaning up some of these drivers, I have been playing around connecting them up in various ways. Originally I just added an interrupt handler but later added a call back handler and and then an event drive system to it. I am playing around with different worker thread schemes at the moment. When you start doing bulk transfers off hard drives it gets interesting.

Do you have any preference how you want to connect it as I might as well setup what you want?

LeMury
Posts: 33
Joined: Mon Jun 11, 2018 3:06 pm

Re: LdB's USB driver

Sat Aug 25, 2018 8:02 pm

That's ok LdB, tomorrow or whenever you get to it is fine.
Thanks a lot for your time and work!!

I don't have huge USB demands.
I need a USB touch screen driver and USB midi Interface driver.
Polling is just fine. No interrupts needed. No hot swap etc.

I think the Touch screen driver shouldn't be to hard as it probably is just a mouse HID variant with absolute coords.
The midi interface driver I'm not sure yet, but I have seen some code on the net.

LeMury
Posts: 33
Joined: Mon Jun 11, 2018 3:06 pm

Re: LdB's USB driver

Tue Aug 28, 2018 4:01 pm

Not to rush you or anything,
but did you perhaps get to updating your CSUD redux USB driver?

On a different matter;
could you look at my question here: https://www.raspberrypi.org/forums/view ... 2&t=220945.
I got no replies. Perhaps you know something on the subject?

Cheers!

LeMury
Posts: 33
Joined: Mon Jun 11, 2018 3:06 pm

Re: LdB's USB driver

Mon Sep 03, 2018 9:35 am

Hi LdB,
Any progress on updating your CSUD redux USB driver?
Or perhaps could you point me to you latest xinu usb code so I can try fix it myself?
Thank you.

LdB
Posts: 874
Joined: Wed Dec 07, 2016 2:29 pm

Re: LdB's USB driver

Mon Sep 03, 2018 10:29 am

My xinu repo
https://github.com/LdB-ECM/Xinu

Sorry I forgot all about it, I will have a look tonight.

LeMury
Posts: 33
Joined: Mon Jun 11, 2018 3:06 pm

Re: LdB's USB driver

Thu Sep 06, 2018 4:22 pm

Hi LdB,

It seems that your CSUD redux USB driver only enumerates Low-speed USB devices.
Any other device speed e.g. Full-speed, fails as mentioned.
I hope this helps solving this issue.

Cheers!

PS: I wunder if the original CSUD driver also had this issue/limitation?

LdB
Posts: 874
Joined: Wed Dec 07, 2016 2:29 pm

Re: LdB's USB driver

Thu Sep 06, 2018 4:46 pm

No I am enumerating high speed devices like hard drives etc, I can read and write to them :-)

It's actually slower devices that are technically harder because you have to install a relay split on the nearest parent port that supports high speed. So when you first start out you can usually enumerate high speed devices and find you can't enumerate low speed devices. That is a very common problem with new implementations.

I have been going thru it, something strange with the fake roothub message implementation. Just changing it to my newer implementation as we speak. Specifically it is HcdProcessRootHubMessage that seems to be causing the problem on that code. It's supposed to do a power and reset on the port with the new device and it seems clunky.

The newer implementation is cleaner in that it is broken into two calls a standard request and a class request in

dwc_root_hub_standard_request(struct usb_xfer_request *req)
dwc_root_hub_class_request(struct usb_xfer_request *req)

You can still see my links etc to beyond logic in the old code, I had not refactored it as I was still working out how it worked. Those two equal the original code if you look just different names on the calls .. that is the Fake root hub(tm) message handlers anyhow :-)

LeMury
Posts: 33
Joined: Mon Jun 11, 2018 3:06 pm

Re: LdB's USB driver

Fri Sep 07, 2018 7:38 am

No I am enumerating high speed devices like hard drives etc, I can read and write to them
Perhaps so, but all the Full-speed devices I have tried fail to enumerate using your 32-bit binary from https://github.com/LdB-ECM/Raspberry-Pi ... m32_64_USB

LeMury
Posts: 33
Joined: Mon Jun 11, 2018 3:06 pm

Re: LdB's USB driver

Sun Sep 16, 2018 11:58 am

@LdB. Any updates on your USB driver?

LdB
Posts: 874
Joined: Wed Dec 07, 2016 2:29 pm

Re: LdB's USB driver

Sun Sep 16, 2018 2:14 pm

Yep .. done just cleaning up atm .. will be all shiny and new :-)
Will merge up tonight when done.

WMN
Posts: 2
Joined: Sat Sep 22, 2018 6:05 pm

Re: LdB's USB driver

Sat Sep 22, 2018 6:36 pm

Hi LdB,

I'm was getting a little out of sorts trying the usb support working in my application.
Had usb flying in no time on STM32-arch but running into brick walls with Raspbarry Pi, that is up until I found this thread and your driver code.
Thanks for your work, but now it seems that I'm on par with some of the folks here, e.g Lemurie's enum problem with a full-speed device.
HID-devices works fine though.
Hope that your "shiny" ;-) update will also solve my usb-nightmares.

Thanks again for your work.

Kind regards,
WMN

LdB
Posts: 874
Joined: Wed Dec 07, 2016 2:29 pm

Re: LdB's USB driver

Sun Sep 23, 2018 2:43 am

Been down with flu for couple of days, should be up tonight just sorting out some samples .. I am up an alive :-)

WMN
Posts: 2
Joined: Sat Sep 22, 2018 6:05 pm

Re: LdB's USB driver

Sun Sep 23, 2018 9:39 am

LdB, first things first.
Take care of your health first then your code.
Good to here you are feeling better.

Will try your update as soon as it comes available and report my findings back to you.

Best regards,
WMN

Return to “Bare metal, Assembly language”