kevinmehall / usb

Minimalist portable USB device stack for SAMD21, LPC1800, LPC4300, Xmega
MIT License
100 stars 20 forks source link

Minimal xmega example not working on atxmega128a4u #3

Closed Risca closed 7 years ago

Risca commented 7 years ago

Hello,

Just tried your library on my atxmega128a4u chipset but couldn't get it to work. Here are my local changes:

diff --git a/usb_requests.c b/usb_requests.c
index 91c5cf5..3b67889 100644
--- a/usb_requests.c
+++ b/usb_requests.c
@@ -8,7 +8,7 @@ volatile uint8_t usb_configuration;
 uint16_t usb_ep0_in_size;
 const uint8_t* usb_ep0_in_ptr;

-void usb_ep0_in_multi() {
+void usb_ep0_in_multi(void) {
    uint16_t tsize = usb_ep0_in_size;

    if (tsize > USB_EP0_SIZE) {
diff --git a/xmega/example/minimal/makefile b/xmega/example/minimal/makefile
index ef27902..965e2d2 100644
--- a/xmega/example/minimal/makefile
+++ b/xmega/example/minimal/makefile
@@ -5,7 +5,8 @@ HW_VERSION=1.0
 FW_VERSION=$(shell git describe --always --dirty='*')

 # MCU name
-MCU = atxmega32a4u
+#MCU = atxmega32a4u
+MCU = atxmega128a4u
 ARCH = XMEGA

 VID = 9999
@@ -22,7 +23,8 @@ PID = ffff
 #     does not *change* the processor frequency - it should merely be updated to
 #     reflect the processor speed set externally so that the code can use accurate
 #     software delays.
-F_CPU = 32000000
+#F_CPU = 32000000
+F_CPU = 24000000

 # Input clock frequency.
@@ -143,7 +145,7 @@ CFLAGS += -Wstrict-prototypes
 CFLAGS += -Wa,-adhlns=$(<:%.c=$(OBJDIR)/%.lst)
 CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
 CFLAGS += $(CSTANDARD)
-CFLAGS += -flto
+#CFLAGS += -flto

 #---------------- Compiler Options C++ ----------------

I'm running

avr-gcc (AVR_8_bit_GNU_Toolchain_3.4.5_1522) 4.8.1
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

and had to remove the -flto flag (see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59396). When I plugin the board to the PC (Sabayon Linux), I get:

Feb 14 01:28:07 sabayon kernel: usb 3-1.2: new full-speed USB device number 32 using ehci-pci
Feb 14 01:28:12 sabayon kernel: usb 3-1.2: device descriptor read/64, error -110

I'm afraid I don't know where to begin to debug this problem. Could you help me out?

kevinmehall commented 7 years ago

That error is fairly nonspecific, and basically means the device never answered one of the first few requests.

Hope that helps. I haven't used the xmega port in a couple of years, so that's about all I have to suggest.

Risca commented 7 years ago

I'll port my clock setup code from my LUFA experiments and see what happens. I'll check out that flag as well when I get home.

Risca commented 7 years ago

Well, what do you know: adding -fno-jump-tables made a difference. It now enumerates correctly when I plug it in. The AVR-GCC manual says:

NOTE: The tablejump instructions use the LPM assembler instruction for access to jump tables. Always use -fno-jump-tables switch, if compiling a bootloader for devices with more than 64 KB of code memory.

Do you want me to add the flag to the example makefile and submit a pull request?

kevinmehall commented 7 years ago

That would be great, thanks!