LUFA usb library

Go To Last Post
7 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,
I am tyring to use the LUFA serial to usb library I basically have an unbootloaded Arduino 2560 - and I dont want to use any bootloader at this stage for the mega16U2 that takes care of serial to usb.

I have downloaded the files from LUFA, and removed everything not to do with that project.

I get these errors:

Quote:

../LUFA-120730/Projects/USBtoSerial/../../LUFA/Drivers/USB/Core/AVR8/USBController_AVR8.h: In function 'USB_PLL_On':
../LUFA-120730/Projects/USBtoSerial/../../LUFA/Drivers/USB/Core/AVR8/USBController_AVR8.h:334: error: 'USB_PLL_PSC' undeclared (first use in this function)
../LUFA-120730/Projects/USBtoSerial/../../LUFA/Drivers/USB/Core/AVR8/USBController_AVR8.h:334: error: (Each undeclared identifier is reported only once
../LUFA-120730/Projects/USBtoSerial/../../LUFA/Drivers/USB/Core/AVR8/USBController_AVR8.h:334: error: for each function it appears in.)
In file included from ../LUFA-120730/Projects/USBtoSerial/Descriptors.c:38:
../LUFA-120730/Projects/USBtoSerial/Descriptors.h: At top level:
../LUFA-120730/Projects/USBtoSerial/Descriptors.h:83: error: conflicting types for 'CALLBACK_USB_GetDescriptor'
../LUFA-120730/Projects/USBtoSerial/../../LUFA/Drivers/USB/Core/AVR8/../Device.h:133: error: previous declaration of 'CALLBACK_USB_GetDescriptor' was here
../LUFA-120730/Projects/USBtoSerial/Descriptors.c:55: error: 'FIXED_CONTROL_ENDPOINT_SIZE' undeclared here (not in a function)
../LUFA-120730/Projects/USBtoSerial/Descriptors.c:65: error: 'FIXED_NUM_CONFIGURATIONS' undeclared here (not in a function)
../LUFA-120730/Projects/USBtoSerial/Descriptors.c:217: error: conflicting types for 'CALLBACK_USB_GetDescriptor'
../LUFA-120730/Projects/USBtoSerial/../../LUFA/Drivers/USB/Core/AVR8/../Device.h:133: error: previous declaration of 'CALLBACK_USB_GetDescriptor' was here

I dont understand why it says these things are undefined. Has anyone done this before?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Why would you remove any part of it? LUFA generally relies on building everything then throwing away the bits you don't need in the link.

The error you are getting sounds like the 16u2 you are building for doesn't have USB_PLL_PSC. Maybe you misconfigured the build?

EDIT: looking at it USB_PLL_PSC is defined as a result of this:

		#if (F_USB == 8000000)
			#if (defined(__AVR_AT90USB82__) || defined(__AVR_AT90USB162__) || \
			     defined(__AVR_ATmega8U2__) || defined(__AVR_ATmega16U2__) || \
			     defined(__AVR_ATmega32U2__))
				#define USB_PLL_PSC                0
			#elif (defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__))
				#define USB_PLL_PSC                0
			#elif (defined(__AVR_AT90USB646__)  || defined(__AVR_AT90USB1286__) || defined(__AVR_ATmega32U6__))
				#define USB_PLL_PSC                ((1 << PLLP1) | (1 << PLLP0))
			#elif (defined(__AVR_AT90USB647__)  || defined(__AVR_AT90USB1287__))
				#define USB_PLL_PSC                ((1 << PLLP1) | (1 << PLLP0))
			#endif
		#elif (F_USB == 16000000)
			#if (defined(__AVR_AT90USB82__) || defined(__AVR_AT90USB162__) || \
			     defined(__AVR_ATmega8U2__) || defined(__AVR_ATmega16U2__) || \
			     defined(__AVR_ATmega32U2__))
				#define USB_PLL_PSC                (1 << PLLP0)
			#elif (defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__))
				#define USB_PLL_PSC                (1 << PINDIV)
			#elif (defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB647__) || defined(__AVR_ATmega32U6__))
				#define USB_PLL_PSC                ((1 << PLLP2) | (1 << PLLP1))
			#elif (defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1287__))
				#define USB_PLL_PSC                ((1 << PLLP2) | (1 << PLLP0))
			#endif
		#endif

So either you have not got F_USB set to 8000000 or 16000000 or you aren't building for one of the listed USB AVRs

It couldn't be that you are trying to build for the 2560 could it?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Am I hallucinating, or has the OP been edited? (Wasn't there a message about F_USB not being defined just a few minutes ago?)

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

No you are right, I had an old error dialog in the clipboard, I only realised after posting. Sorry Johan, that must have been confusing.

I set F_USB as a -D option in compiler settings, and made it equal to 16000000 so now my only error is:

Quote:

../LUFA-120730/Projects/USBtoSerial/Descriptors.h:83: error: conflicting types for 'CALLBACK_USB_GetDescriptor'
../LUFA-120730/Projects/USBtoSerial/../../LUFA/Drivers/USB/Core/AVR8/../Device.h:133: error: previous declaration of 'CALLBACK_USB_GetDescriptor' was here
../LUFA-120730/Projects/USBtoSerial/Descriptors.c:55: error: 'FIXED_CONTROL_ENDPOINT_SIZE' undeclared here (not in a function)
../LUFA-120730/Projects/USBtoSerial/Descriptors.c:65: error: 'FIXED_NUM_CONFIGURATIONS' undeclared here (not in a function)
../LUFA-120730/Projects/USBtoSerial/Descriptors.c:217: error: conflicting types for 'CALLBACK_USB_GetDescriptor'
../LUFA-120730/Projects/USBtoSerial/../../LUFA/Drivers/USB/Core/AVR8/../Device.h:133: error: previous declaration of 'CALLBACK_USB_GetDescriptor' was here
make: *** [LUFA-120730/Projects/USBtoSerial/Descriptors.o] Error 1

I never have had an easy time with Callbacks on AVR?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Clawson:
Just verfied that I hadnt made a silly mistake like trying to build for the wrong device. Im not - definately 16U2.

Based on these errors, Im starting to wonder whether the issue is more of that garbage collection stuff, or other build parameters because it says that it has found the callback in device.c and in descriptors.c - which is the file specific to the project and therefore I cant imagine that its there - only to be removed as a mistake.

My errors are currently (for my 16U2):

../LUFA-120730/Projects/USBtoSerial/Descriptors.h:83: error: conflicting types for 'CALLBACK_USB_GetDescriptor'
../LUFA-120730/Projects/USBtoSerial/../../LUFA/Drivers/USB/Core/AVR8/../Device.h:133: error: previous declaration of 'CALLBACK_USB_GetDescriptor' was here
../LUFA-120730/Projects/USBtoSerial/Descriptors.c:55: error: 'FIXED_CONTROL_ENDPOINT_SIZE' undeclared here (not in a function)
../LUFA-120730/Projects/USBtoSerial/Descriptors.c:65: error: 'FIXED_NUM_CONFIGURATIONS' undeclared here (not in a function)
../LUFA-120730/Projects/USBtoSerial/Descriptors.c:217: error: conflicting types for 'CALLBACK_USB_GetDescriptor'
../LUFA-120730/Projects/USBtoSerial/../../LUFA/Drivers/USB/Core/AVR8/../Device.h:133: error: previous declaration of 'CALLBACK_USB_GetDescriptor' was here
make: *** [LUFA-120730/Projects/USBtoSerial/Descriptors.o] Error 1

So perhaps there is stuff that is meant to be stripped out by the compiler - or before the compiler?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi guys.
Had some success.
If I dont generate my own makefile, and use LUFA's makefile it builds successfully. However I want to change some of the properties of the makefile so that a) it generates the .hex and b) it uploads it.
I've tried "diff-ing" the two makefiles to try and add the relevant stuf to the LUFA makefile, but I cant seem to get it to do those two things.
I have attached the two makefiles, I was wondering if someone could help me work out what settings I need to setup to get my makefile to be like his?
Or how to add to his to generate hex and upload?
Thanks
Alex

LUFA makefile:

Quote:

MCU = at90usb1287
ARCH = AVR8
BOARD = USBKEY
F_CPU = 16000000
F_USB = $(F_CPU)
OPTIMIZATION = s
TARGET = USBtoSerial
SRC = $(TARGET).c Descriptors.c $(LUFA_SRC_USB) $(LUFA_SRC_USBCLASS)
LUFA_PATH = ../../LUFA
CC_FLAGS = -DUSE_LUFA_CONFIG_HEADER -IConfig/
LD_FLAGS =

# Default target
all:

# Include LUFA build script makefiles
include $(LUFA_PATH)/Build/lufa_core.mk
include $(LUFA_PATH)/Build/lufa_sources.mk
include $(LUFA_PATH)/Build/lufa_build.mk
include $(LUFA_PATH)/Build/lufa_cppcheck.mk
include $(LUFA_PATH)/Build/lufa_doxygen.mk
include $(LUFA_PATH)/Build/lufa_dfu.mk
include $(LUFA_PATH)/Build/lufa_hid.mk
include $(LUFA_PATH)/Build/lufa_avrdude.mk
include $(LUFA_PATH)/Build/lufa_atprogram.mk


Firstly he uses that device because his AVRDude doesnt have mega16U2, mine does so going to change that

MyMakefile:

Quote:

################################################################################
# Automatically-generated file. Do not edit!
################################################################################

-include ../makefile.init

RM := rm -rf

# All of the sources participating in the build are defined here
-include sources.mk
-include LUFA-120730/Projects/USBtoSerial/subdir.mk
-include LUFA-120730/LUFA/Platform/UC3/subdir.mk
-include LUFA-120730/LUFA/Drivers/USB/Core/AVR8/Template/subdir.mk
-include LUFA-120730/LUFA/Drivers/USB/Core/AVR8/subdir.mk
-include LUFA-120730/LUFA/Drivers/USB/Core/subdir.mk
-include LUFA-120730/LUFA/Drivers/USB/Class/Host/subdir.mk
-include LUFA-120730/LUFA/Drivers/USB/Class/Device/subdir.mk
-include LUFA-120730/LUFA/Drivers/USB/Class/Common/subdir.mk
-include LUFA-120730/LUFA/Drivers/Peripheral/XMEGA/subdir.mk
-include LUFA-120730/LUFA/Drivers/Peripheral/AVR8/subdir.mk
-include LUFA-120730/LUFA/Drivers/Board/subdir.mk
-include LUFA-120730/LUFA/Build/HID_EEPROM_Loader/subdir.mk
-include LUFA-120730/Demos/Host/LowLevel/VirtualSerialHost/subdir.mk
-include LUFA-120730/Demos/Host/LowLevel/StillImageHost/Lib/subdir.mk
-include LUFA-120730/Demos/Host/LowLevel/StillImageHost/subdir.mk
-include LUFA-120730/Demos/Host/LowLevel/RNDISEthernetHost/Lib/subdir.mk
-include LUFA-120730/Demos/Host/LowLevel/RNDISEthernetHost/subdir.mk
-include LUFA-120730/Demos/Host/LowLevel/PrinterHost/Lib/subdir.mk
-include LUFA-120730/Demos/Host/LowLevel/PrinterHost/subdir.mk
-include LUFA-120730/Demos/Host/LowLevel/MouseHostWithParser/subdir.mk
-include LUFA-120730/Demos/Host/LowLevel/MouseHost/subdir.mk
-include LUFA-120730/Demos/Host/LowLevel/MassStorageHost/Lib/subdir.mk
-include LUFA-120730/Demos/Host/LowLevel/MassStorageHost/subdir.mk
-include LUFA-120730/Demos/Host/LowLevel/MIDIHost/subdir.mk
-include LUFA-120730/Demos/Host/LowLevel/KeyboardHostWithParser/subdir.mk
-include LUFA-120730/Demos/Host/LowLevel/KeyboardHost/subdir.mk
-include LUFA-120730/Demos/Host/LowLevel/JoystickHostWithParser/subdir.mk
-include LUFA-120730/Demos/Host/LowLevel/GenericHIDHost/subdir.mk
-include LUFA-120730/Demos/Host/LowLevel/AudioOutputHost/subdir.mk
-include LUFA-120730/Demos/Host/LowLevel/AudioInputHost/subdir.mk
-include LUFA-120730/Demos/Host/LowLevel/AndroidAccessoryHost/Lib/subdir.mk
-include LUFA-120730/Demos/Host/LowLevel/AndroidAccessoryHost/subdir.mk
-include LUFA-120730/Demos/Host/ClassDriver/VirtualSerialHost/subdir.mk
-include LUFA-120730/Demos/Host/ClassDriver/StillImageHost/subdir.mk
-include LUFA-120730/Demos/Host/ClassDriver/RNDISEthernetHost/subdir.mk
-include LUFA-120730/Demos/Host/ClassDriver/PrinterHost/subdir.mk
-include LUFA-120730/Demos/Host/ClassDriver/MouseHostWithParser/subdir.mk
-include LUFA-120730/Demos/Host/ClassDriver/MouseHost/subdir.mk
-include LUFA-120730/Demos/Host/ClassDriver/MassStorageHost/subdir.mk
-include LUFA-120730/Demos/Host/ClassDriver/MIDIHost/subdir.mk
-include LUFA-120730/Demos/Host/ClassDriver/KeyboardHostWithParser/subdir.mk
-include LUFA-120730/Demos/Host/ClassDriver/KeyboardHost/subdir.mk
-include LUFA-120730/Demos/Host/ClassDriver/JoystickHostWithParser/subdir.mk
-include LUFA-120730/Demos/Host/ClassDriver/AudioOutputHost/subdir.mk
-include LUFA-120730/Demos/Host/ClassDriver/AudioInputHost/subdir.mk
-include LUFA-120730/Demos/Host/ClassDriver/AndroidAccessoryHost/subdir.mk
-include LUFA-120730/Demos/DualRole/ClassDriver/MouseHostDevice/subdir.mk
-include LUFA-120730/Demos/Device/LowLevel/VirtualSerial/subdir.mk
-include LUFA-120730/Demos/Device/LowLevel/RNDISEthernet/Lib/subdir.mk
-include LUFA-120730/Demos/Device/LowLevel/RNDISEthernet/subdir.mk
-include LUFA-120730/Demos/Device/LowLevel/Mouse/subdir.mk
-include LUFA-120730/Demos/Device/LowLevel/MassStorage/Lib/subdir.mk
-include LUFA-120730/Demos/Device/LowLevel/MassStorage/subdir.mk
-include LUFA-120730/Demos/Device/LowLevel/MIDI/subdir.mk
-include LUFA-120730/Demos/Device/LowLevel/KeyboardMouse/subdir.mk
-include LUFA-120730/Demos/Device/LowLevel/Keyboard/subdir.mk
-include LUFA-120730/Demos/Device/LowLevel/Joystick/subdir.mk
-include LUFA-120730/Demos/Device/LowLevel/GenericHID/subdir.mk
-include LUFA-120730/Demos/Device/LowLevel/DualVirtualSerial/subdir.mk
-include LUFA-120730/Demos/Device/LowLevel/AudioOutput/subdir.mk
-include LUFA-120730/Demos/Device/LowLevel/AudioInput/subdir.mk
-include LUFA-120730/Demos/Device/Incomplete/TestAndMeasurement/subdir.mk
-include LUFA-120730/Demos/Device/Incomplete/Sideshow/Lib/subdir.mk
-include LUFA-120730/Demos/Device/Incomplete/Sideshow/subdir.mk
-include LUFA-120730/Demos/Device/ClassDriver/VirtualSerialMouse/subdir.mk
-include LUFA-120730/Demos/Device/ClassDriver/VirtualSerialMassStorage/Lib/subdir.mk
-include LUFA-120730/Demos/Device/ClassDriver/VirtualSerialMassStorage/subdir.mk
-include LUFA-120730/Demos/Device/ClassDriver/VirtualSerial/subdir.mk
-include LUFA-120730/Demos/Device/ClassDriver/RNDISEthernet/Lib/subdir.mk
-include LUFA-120730/Demos/Device/ClassDriver/RNDISEthernet/subdir.mk
-include LUFA-120730/Demos/Device/ClassDriver/Mouse/subdir.mk
-include LUFA-120730/Demos/Device/ClassDriver/MassStorageKeyboard/Lib/subdir.mk
-include LUFA-120730/Demos/Device/ClassDriver/MassStorageKeyboard/subdir.mk
-include LUFA-120730/Demos/Device/ClassDriver/MassStorage/Lib/subdir.mk
-include LUFA-120730/Demos/Device/ClassDriver/MassStorage/subdir.mk
-include LUFA-120730/Demos/Device/ClassDriver/MIDI/subdir.mk
-include LUFA-120730/Demos/Device/ClassDriver/KeyboardMouseMultiReport/subdir.mk
-include LUFA-120730/Demos/Device/ClassDriver/KeyboardMouse/subdir.mk
-include LUFA-120730/Demos/Device/ClassDriver/Keyboard/subdir.mk
-include LUFA-120730/Demos/Device/ClassDriver/Joystick/subdir.mk
-include LUFA-120730/Demos/Device/ClassDriver/GenericHID/subdir.mk
-include LUFA-120730/Demos/Device/ClassDriver/DualVirtualSerial/subdir.mk
-include LUFA-120730/Demos/Device/ClassDriver/AudioOutput/subdir.mk
-include LUFA-120730/Demos/Device/ClassDriver/AudioInput/subdir.mk
-include LUFA-120730/BuildTests/SingleUSBModeTest/subdir.mk
-include LUFA-120730/BuildTests/ModuleTest/subdir.mk
-include LUFA-120730/BuildTests/BoardDriverTest/subdir.mk
-include LUFA-120730/Bootloaders/HID/HostLoaderApp/subdir.mk
-include LUFA-120730/Bootloaders/HID/subdir.mk
-include LUFA-120730/Bootloaders/DFU/subdir.mk
-include LUFA-120730/Bootloaders/CDC/subdir.mk
-include subdir.mk
-include objects.mk

ifneq ($(MAKECMDGOALS),clean)
ifneq ($(strip $(C_DEPS)),)
-include $(C_DEPS)
endif
ifneq ($(strip $(ASM_DEPS)),)
-include $(ASM_DEPS)
endif
ifneq ($(strip $(S_DEPS)),)
-include $(S_DEPS)
endif
ifneq ($(strip $(S_UPPER_DEPS)),)
-include $(S_UPPER_DEPS)
endif
endif

-include ../makefile.defs

# Add inputs and outputs from these tool invocations to the build variables
FLASH_IMAGE += \
Mega16U2.hex \

SIZEDUMMY += \
sizedummy \

AVRDUDEDUMMY += \
avrdudedummy \

# All Target
all: Mega16U2.elf secondary-outputs

# Tool invocations
Mega16U2.elf: $(OBJS) $(USER_OBJS)
@echo 'Building target: $@'
@echo 'Invoking: AVR C Linker'
avr-gcc -Wl,-Map,Mega16U2.map -mmcu=atmega16u2 -o "Mega16U2.elf" $(OBJS) $(USER_OBJS) $(LIBS)
@echo 'Finished building target: $@'
@echo ' '

Mega16U2.hex: Mega16U2.elf
@echo 'Create Flash image (ihex format)'
-avr-objcopy -R .eeprom -O ihex Mega16U2.elf "Mega16U2.hex"
@echo 'Finished building: $@'
@echo ' '

sizedummy: Mega16U2.elf
@echo 'Invoking: Print Size'
-avr-size --format=avr --mcu=atmega16u2 Mega16U2.elf
@echo 'Finished building: $@'
@echo ' '

avrdudedummy: Mega16U2.elf
@echo 'Invoking: AVRDude'
C:\WinAVR-20100110\bin\avrdude -pm16u2 -cavrisp2 -Pusb -u -Uflash:w:Mega16U2.hex:a -Ulfuse:w:0xff:m -Uhfuse:w:0xd9:m -Uefuse:w:0xf7:m
@echo 'Finished building: $@'
@echo ' '

# Other Targets
clean:
-$(RM) $(OBJS)$(C_DEPS)$(ASM_DEPS)$(FLASH_IMAGE)$(ELFS)$(AVRDUDEDUMMY)$(S_DEPS)$(SIZEDUMMY)$(S_UPPER_DEPS) Mega16U2.elf
-@echo ' '

secondary-outputs: $(FLASH_IMAGE) $(SIZEDUMMY) $(AVRDUDEDUMMY)

.PHONY: all clean dependents
.SECONDARY:

-include ../makefile.targets

Thanks

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Holy moley, that's one heck of a makefile. If you are just wanting to compile and use AVRDude, the LUFA build system has that built in - see:

http://www.fourwalledcubicle.com...

All you need to do is add this to your LUFA makefile:

AVRDUDE_PROGRAMMER = avrispmkii
ATPROGRAM_PORT = usb
ATPROGRAM_FLAGS = Ulfuse:w:0xff:m -Uhfuse:w:0xd9:m -Uefuse:w:0xf7:m

Then run "make all avrdude".

- Dean :twisted:

Make Atmel Studio better with my free extensions. Open source and feedback welcome!