chadderz121 / csud Goto Github PK
View Code? Open in Web Editor NEWChadderz's Simple USB Driver for Raspberry Pi
License: MIT License
Chadderz's Simple USB Driver for Raspberry Pi
License: MIT License
I struggled many hours today to find out why the csud driver would initialize correctly but then fail to iterate the root hub. The problem was that since GCC4.4(?) the packed attribute has to be set on nested structs too if they need to be bit-packed. Example:
struct UsbConfigurationDescriptor {
u8 DescriptorLength; // +0x0
enum DescriptorType DescriptorType : 8; // +0x1
u16 TotalLength; // +0x2
u8 InterfaceCount; // +0x4
u8 ConfigurationValue; // +0x5
u8 StringIndex; // +0x6
struct {
unsigned _reserved0_4 : 5; // @0
bool RemoteWakeup : 1; // @5
bool SelfPowered : 1; // @6
unsigned _reserved7 : 1; // @7
} Attributes; // +0x7
u8 MaximumPower; // +0x8
} __attribute__ ((__packed__));
sizeof(struct UsbConfigurationDescriptor) returns 12 for me, not 9 as the code implies. This breaks the descriptor discovery loop in UsbConfigure() because of wrong offsets.
Adding the packed attribute on the inner struct "Attributes" fixed the problem for me:
...
struct {
unsigned _reserved0_4 : 5; // @0
bool RemoteWakeup : 1; // @5
bool SelfPowered : 1; // @6
unsigned _reserved7 : 1; // @7
} __attribute__ ((__packed__)) Attributes; // +0x7
u8 MaximumPower; // +0x8
} __attribute__ ((__packed__));
For reference, I am running GCC 4.7.4:
arm-none-eabi-gcc (GNU Tools for ARM Embedded Processors) 4.7.4 20130913 (release) [ARM/embedded-4_7-branch revision 202601]
Cheers,
Lukas
It has been reported that the KeyboardPoll method has the side effect of overwritting addresses 0 and 4. Have not tested this myself, said to occur if the keyboard has no activiy for a short time. Not always written as 0. Presumably due to writing to a NULL pointer.
Debug log:
CSUD: USB driver version 1.0
CSUD: HID driver version 1.0
CSUD: Hub driver version 1.0
CSUD: Keyboard driver version 1.0
CSUD: Mouse driver version 1.0
HCD: Reserving memory.
Platform: First memory allocation, reserving 16KiB of heap, 256 entries.
Platform: malloc(0x400) = 0xa9db8. (1023/16384)
Platform: Out of memory! We should've had more allocations in platform.c.
Platform: Out of memory! We should've had more allocations in platform.c.
HCD: Hardware: OT2.80a (BCM2708a)
HCD: Internal DMA mode.
HCD: Hardware configuration: 00000000 228ddd50 0ff000e8 1ff00020
HCD: Host configuration: 00200000
HCD: Disabling interrupts.
HCD: Powering USB on.
HCD: Load completed.
HCD: Start core.
Platform: Out of memory! We should've had more allocations in platform.c.
USBD: Abort, HCD failed to start.
Platform: free(0xa9db8) (-1/16384)
When I attempt to compile using "make driver config=FINAL type=LOWLEVEL target=RPI config=FINAL gnu=arm-none-eabi " I get the following:
make: *** No rule to make target 'build', needed by 'libcsud.a'. Stop.
Am I missing something? or is it just a misconfiguration?
Thanks in advance.
Got a few of these warnings when compiling it into my code based on BakingPi.
arm-none-eabi-ld --no-undefined build/_start.o build/mailbox.o build/printk.o build/fb.o b
uild/gpio.o build/font_8x8.o build/fb_test.o build/main.o build/led.o build/timer.o -Map k
ernel.map -L libs -lcsud -o build/output.elf -T kernel.ld
arm-none-eabi-ld: warning: libs/libcsud.a(device.keyboard.c.o) uses 2-byte wchar_t yet the
output is to use 4-byte wchar_t; use of wchar_t values across objects may fail
arm-none-eabi-ld: Warning: libs/libcsud.a(device.keyboard.c.o): Unknown EABI object attrib
ute 44
I see -fshort-wchar
is used. Any reason for that? Should I include it also in my makefile?
Thanks for this driver (and your tutorial!). (Hit ctrl-enter accidentally.. Sorry for the partial submit)
source/device/hid/keyboard.c:163:7: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
csud/source/device/hid/keyboard.c
Lines 163 to 167 in e13b935
Are both lines supposed to be guarded by the if statement, or only the LOG_DEBUGF?
Hey Alex,
I'm writing a micro kernel os, and trying to use your source code(https://github.com/MisaZhu/EwokOS/tree/master/system/platforms/raspix/drivers/usbd) . It works pretty well ,just wanna know do you have any plan to support more devices ?
Misa.Z
had a quick glance over the readme and other issues, and dont see a clear answer
does this driver support both host and device modes? or only host mode?
i'm interested in using it to emulate a usb device on an rpi4, where the dwc controller is routed to the USB-C port
It can't input smoothly on my Raspberry b+1.2v I tried so many people's os for raspberry and It always Input a word then stuck :<
So I thought It could my keyboard problem.I want your keyboard and mouse model
you guys can help me @_@
On MacOS, apostrophes and parens in the makefile intro text (shown by the 'all' target) cause errors in the shell. eg:
James-MacBook:csud jamescone$ make
/bin/sh: -c: line 0: unexpected EOF while looking for matching `''
/bin/sh: -c: line 1: syntax error: unexpected end of file
make: *** [all] Error 2
James-MacBook:csud jamescone$
I ahve a patch, but the markup mangles it. I've failed to work out how to attach it.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.