1
votes

I am working on the new Raspberry Pi 3 B+ board in a bare metal environment (32-bit). I have a working USB driver for the older Pi 1 boards. From what I understand, the Pi 1 and the Pi 3 B+ have the same USB host controller (Synopsis DesignWare 2.0 USB Host Controller; or dwc for short), yet the USB driver that works on the Pi 1 does not work for me on the Pi 3 B+ (or the Pi 3 B either).

After going through some debugging messages, I found that the problem is that when the DWC is enumerating the devices, it will try to read the device descriptor of, what I am guessing is, the on-board USB hub/ethernet device (LAN7515), but it will return a transfer error, and then therefore is unable to enumerate the device.

My question is why does this happen? If the Pi 1 and the Pi 3 have the same host controller then it should, in theory, at least be able to properly enumerate a device.

If someone can point me in the right direction as to why this happens, it would be greatly appreciated.

Thank you in advance.

1
I'd be very curious to see the solution to this enumeration issue. I have seen a few bare metal USB repositories on GitHub (e.g. github.com/rsta2/uspi). I have worked with bare metal Pi projects in the past, and you are correct that enumeration should work in theory, since the DWC peripheral has not changed. My guess is: your Pi 3 driver has some quirk in the initialization process where device attachment is made impossible.pmcg521

1 Answers

1
votes

The Pi3 is having an alignment issue because some of the USB structures are not natively aligned and they are packed. It generally requires inserting some pack and alignment attributes "attribute((packed, aligned(1)))" on some of the structures that are unaligned.

The rule goes uint16_t* pointers must be reading/writing align 2 addresses uint32_t* pointers must be reading/writing align 4 addresses

So a struct like this is misaligned.

struct BadStruct __attribute__((__packed__)){
     uint8_t a;
     uint16_t b;
};