Makogan
Posts: 71
Joined: Tue May 16, 2017 9:17 pm

USB peripherals in bare metal?

Tue Jun 13, 2017 6:43 pm

First, I apologize for posting so much asking for help. I have 2 weeks left to do as much as I can in this project, so I am very desperate, thank you for your patience.

How exactly would I go about integrating USB peripherals into my code. For practical purposes, let's say I have an Xbox controller, how would I go about knowing when and which button is pressed. If an xbox controller is too complicated then any other common USB peripheral works.

dwelch67
Posts: 803
Joined: Sat May 26, 2012 5:32 pm

Re: USB peripherals in bare metal?

Tue Jun 13, 2017 9:15 pm

this is the massive one, two weeks is probably not enough if you want to do it yourself. circle I think is what I am remembering, someone here probably more than one someone here has baremetal usb code, you might be able to get it pulled in and working in time...much easier to just use a serial port and dumb terminal (and the dumb terminal has complete keyboard/display support and all you need to do on your side is uart/serial characters).

Makogan
Posts: 71
Joined: Tue May 16, 2017 9:17 pm

Re: USB peripherals in bare metal?

Tue Jun 13, 2017 9:27 pm

hmmm, that is a problem. The purpose of the project is no external libraries that do "OS" things for you, things like math, scheduling algorithms, font things like true type, are fine but memory management, hardware initialisation, I/O management I am supposed to do myself, it is not a problem to read and check someone else's code as long as I properly credit them,, but the implementation I have to do myself. I'll try and look around for anything, see if I can get things working.

User avatar
Gavinmc42
Posts: 1339
Joined: Wed Aug 28, 2013 3:31 am

Re: USB peripherals in bare metal?

Wed Jun 14, 2017 1:35 am

Baremetal USB has been done a few times, mostly for Mouse, Keyboard, MSD.
Look in the sticky
Anything else and you are pretty much on your own.

2 Weeks and in a hurry? hmm, you would not be a student by any chance?
From scratch, baremetal USB anything, allow 6+ months, if you have zero USB experience.
So is this VC4 baremetal or ARM baremetal. one could take ten times longer than the other.
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

Makogan
Posts: 71
Joined: Tue May 16, 2017 9:17 pm

Re: USB peripherals in bare metal?

Wed Jun 14, 2017 2:02 am

Yup as you guessed, I am a student, and one that got abandoned at that (out of 3 people taking the class everybody but me dropped, so I am now juggling a 3 man job on my own :C) and the class I am taking is very self directed, so I am also on my own for that.

User avatar
Gavinmc42
Posts: 1339
Joined: Wed Aug 28, 2013 3:31 am

Re: USB peripherals in bare metal?

Wed Jun 14, 2017 5:20 am

So the others are the smart ones and figured out how hard it was going to be :lol:

Not many choices, not many have made it to USB driver stage
http://www.cl.cam.ac.uk/projects/raspbe ... orials/os/
https://ultibo.org/
https://github.com/rsta2/circle
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

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

Re: USB peripherals in bare metal?

Wed Jun 14, 2017 7:53 am

Ask and you shall receive :-)

I offer the simplest baremetal USB you can just about do. It is my redux of CSUD to the nth degree in a single file USB.C.
No malloc required the driver blocks allocate static driver array blocks at startup.

It is reasonably well documented but as it is using only the control channel even for the HID comms not suitable if you wanted to do disk IO or anything heavy. It will however give you the basics of enumerating the bus, HID and what the fake host does.

I used it as a launch point to write a proper interrupt based USB system.

To try it so you get the idea put the files in the diskimg directory on your baremetal SD card. Plug in a mouse in the USB port and start it up. It has the most up todate firmware on it (I made sure after the other day) :-)

Download from
http://dropcanvas.com/24j23oEGhRw957
All being equal it should display something like
Image
I am guessing the X-Box controller will report as a HID and you should be able to see it and use it ;-)
Last edited by LdB on Wed Jun 14, 2017 8:28 am, edited 1 time in total.

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 17569
Joined: Sat Jul 30, 2011 7:41 pm

Re: USB peripherals in bare metal?

Wed Jun 14, 2017 8:27 am

Makogan wrote:Yup as you guessed, I am a student, and one that got abandoned at that (out of 3 people taking the class everybody but me dropped, so I am now juggling a 3 man job on my own :C) and the class I am taking is very self directed, so I am also on my own for that.
You need to talk to your lecturer. Bare metal USB code, as stated above, is a 1/2 man year project for someone who knows about USB, unless you use someone else's libraries. So I cannot believe the lecturer is expecting this level of work. Find out what the actual requirements for your project are.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Please direct all questions to the forum, I do not do support via PM.

User avatar
Gavinmc42
Posts: 1339
Joined: Wed Aug 28, 2013 3:31 am

Re: USB peripherals in bare metal?

Wed Jun 14, 2017 9:07 am

I really do need a baremetal wireless USB Xbox/PS gamepad driver for my Ultibo bots :(
It is on my list below the Zero Wifi/BT driver, above the baremetal camera driver. :lol:
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

Return to “Bare metal”

Who is online

Users browsing this forum: No registered users and 4 guests