rlatinov
rlatinov

Reputation: 61

Raspberry Pi 3 USB Bare Metal

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.

Upvotes: 1

Views: 1024

Answers (1)

Leon de Boer
Leon de Boer

Reputation: 21

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;
};

Upvotes: 1

Related Questions