[Tut][C][Code] LUFA & Studio5 - Beginner's Guide, Part 3

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

LUFA & Studio5 - Beginner's Guide, Part 3: Create New Project with USB CDC Connectivity

 

In Part 3, we create a Studio5 New Project and use LUFA to add USB CDC connectivity (Virtual Serial Port).

Part 1 can be found here: http://www.avrfreaks.net/index.p...

Part 2 can be found here: http://www.avrfreaks.net/index.p...

 

The tutorial is in the attached pdf and the software files in the attached .zip

(You need to be logged in to download the attached files.)

Attachment(s): 

Last Edited: Mon. Nov 3, 2014 - 11:25 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks!!! it works great with atmega32u2!!

I just wonder what is the optimization level?

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

Glad it worked for you.

protheusdk wrote:
I just wonder what is the optimization level?

From the makefile:

# Optimization level, can be [0, 1, 2, 3, s].
#     0 = turn off optimization. s = optimize for size.
#     (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
OPT = s

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

Thanks Chuck99 for your effort and nice tutorial.

/Chotan

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

Chuck99-
Thanks for the excellent tutorial & other material. Have you tried the LUFA demos with Studio6? I think they should work fine since S6 is a superset of S5 (I have read this elsewhere on the forum). I have tried the ASF stack and found it quite opaque & hard to set up, specially for XMEGA256A3BU on a custom board.
Thanks!

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

hsieber wrote:
Chuck99-
Have you tried the LUFA demos with Studio6?

I haven't tried Studio6 yet. I may wait for 6.1 :wink:

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

Chuck99-

I am following Part 1 of the tutorial and am stumped by the most basic of tasks- I can't get the path to the LUFA makefile right. This is quite frustrating since I think I'm doing everything per the example (which is quite clear and explicit, by the way).

Project path (moved from the LUFE Demo folder):
...My Documents\AVR_Sw\LUFA_HID_Test1\GenericHID
LUFA Path:
...My Documents\AVR_Sw\LUFA\LUFA-120219\LUFA-120219\LUFA\makefile

Altered project makefile in the project directory:
# Path to the LUFA library
LUFA_PATH =../../LUFA/LUFA-120219/LUFA-120129

Attempt to clean the project yields error message:
../../LUFA/LUFA-120219/LUFA-120219/LUFA/makefile: No such file or directory

This error comes from the local makefile so at least that's being read properly. If I manually change directories (back up two, down per the makefile), either in Windows or via a DOS box, I always seem to end up at the correct LUFA makefile OK, but the compiler can't find it.

You may notice that I have elected to do the generic HID rather than the CDC project, but otherwise the paths should be ok. This has all the earmarks of a really dumb mistake but I can't find it. Does Windows need back slashes rather than forward?? I would use an absolute path but I think C: is not permitted.

Aggravated in Annandale....

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

Chuck99-
Tried copying the original LUFA makefile into

..My Documents\AVR_Sw\LUFA_HID_Test1\LUFA

and changing the local makefile to:

# Path to the LUFA library
#LUFA_PATH =../../LUFA/LUFA-120219\LUFA-120129
LUFA_PATH =../

This allows a clean and compile. I would prefer to leave the LUFA makefile where it belongs, I must be doing something wrong with the path specifiers.

Thanks,
H

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

hsieber wrote:
If I manually change directories (back up two, down per the makefile), either in Windows or via a DOS box, I always seem to end up at the correct LUFA makefile OK, but the compiler can't find it.

Everything looks ok.

My only guess is that the make program (which is the one that can't find it) is not starting from where you think it is starting.

1) The make file you are editing should be located in the project folder. (Same folder as .c file.)
2) In the project properties, under build, specify the path to this makefile.

When I get a chance, I'll try compiling the HID demo.

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

That was my thought too, but there is only one image of the altered (from demo) makefile and it's in what I think is the project directory (the one with the relevant .c and .h files).

I have bigger problems, I was incorrect when I mentioned that the project would clean and build. It will clean but the build throws:

Task "RunCompilerTask"
C:\WinAVR-20100110\utils\bin\make.exe -C "C:\Documents and Settings\Harry Sieber\My Documents\AVR_SW\LUFA_HID_Test1\GenericHID" -f "makefile" all
make: Entering directory `C:/Documents and Settings/Harry Sieber/My Documents/AVR_SW/LUFA_HID_Test1/GenericHID'
-------- begin --------
avr-gcc (WinAVR 20100110) 4.3.3
make: Leaving directory `C:/Documents and Settings/Harry Sieber/My Documents/AVR_SW/LUFA_HID_Test1/GenericHID'
make: *** No rule to make target `GenericHID.elf', needed by `elf'. Stop.
Done executing task "RunCompilerTask" -- FAILED.
Done building target "CoreBuild" in project "GenericHID.cproj" -- FAILED.
Done building project "GenericHID.cproj" -- FAILED.

Build FAILED.
========== Build: 0 succeeded or up-to-date, 1 failed, 0 skipped ==========

Looks like a makefile problem. I'm not used to using external makefiles and I think something is very wrong- need to decode the 'No rule to make target `GenericHID.elf' statement. Normally I get a long string of compiler results, in this case it's jumping out almost immediately. Oh well, time to look for an app note on constructing makefiles... I might try doing the CDC example with Studio 5.1 as a sanity check.

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

hsieber wrote:
I have bigger problems, I was incorrect when I mentioned that the project would clean and build. It will clean but [not build]

It is important that LUFA_PATH points to the LUFA library. The Studio5 project makefile (which is the one that we edit) "include"s the makefile located in LUFA/

# Create the LUFA source path variables by including the LUFA root makefile
include $(LUFA_PATH)/LUFA/makefile

This included makefile references other files in LUFA by specifying directories relative to its own location.

LUFA_ROOT_PATH = $(LUFA_PATH)/LUFA
LUFA_SRC_USB          = $(LUFA_ROOT_PATH)/Drivers/USB/Core/$(ARCH)/Device_$(ARCH).c 

If you use a copy of this makefile located in another directory, it messes this up. The files referenced can't be found.

The solution is to specify LUFA_PATH so that the LUFA makefile can be found where it is.

Using Studio5 (5.1.208) I was able to import the GernericHID Demo and compile it.
Initially it failed. It turns out that I had mixed '/' and '\' in the path specifications. Easy to do when you copy and paste from Windows. Once that was corrected, it cleaned and built with no errors.

Always use '/' in the makefile for specifying a directory.

Here is the LUFA_PATH:

LUFA_PATH = ../../../Atmel_Studio_Libraries/LUFA/LUFA-120219/LUFA-120219

Here is the directory structure on the computer:

makefile in the Studio5 project folder:
I:\_Files\Programming\Atmel_Studio_Projects\GenericHID_Demo\GenericHID
	makefile

makefile in LUFA library:
I:\_Files\Programming\Atmel_Studio_Libraries\LUFA\LUFA-120219\LUFA-120219
	LUFA\makefile

You can instruct the makefile to display files in a directory, and thus test the LUFA_PATH as specified.

In the project makefile, find the "begin:" section.

# Eye candy.
# AVR Studio 3.x does not check make's exit code but relies on
# the following magic strings to be generated by the compile job.
begin:
	@echo
	@echo $(MSG_BEGIN)

end:
	@echo $(MSG_END)
	@echo

Insert the "# Test:" code as shown below
(be sure that a TAB character precedes @echo and ls, not spaces)

# Eye candy.
# AVR Studio 3.x does not check make's exit code but relies on
# the following magic strings to be generated by the compile job.
begin:

# Test:
	@echo " "
	@echo Show LUFA Directory
	ls $(LUFA_PATH)/LUFA/ 
	@echo " "
# End Test

	@echo
	@echo $(MSG_BEGIN)

end:
	@echo $(MSG_END)
	@echo

When you clean or build, the output will show the directory and files.

		Show LUFA Directory
		ls ../../../Atmel_Studio_Libraries/LUFA/LUFA-120219/LUFA-120219/LUFA/ 
		CodeTemplates
		Common
		Doxygen.conf
		DoxygenPages
		Drivers
		LUFA - Shortcut.lnk
		License.txt
		Platform
		Scheduler
		Version.h
		makefile
		 
		-------- begin --------
		Cleaning project:

If there is a problem with files not found, this will show you what the make program is finding and thus help you debug.

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

Chuck, have you seen the new LUFA build system currently in trunk?

- Dean :twisted:

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

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

Great points! I was afraid that moving things around would foul up relative paths so I managed to point to the right LUFA directory, still the dreaded 'no rule to make target' message. I also requested tech support on this issue, and the inestimable Mr. Camera indicated that there were new LUFA files available for XMEGA support. I plan to download those & try again.

One little nugget- contrary to various posts, spaces in makefile filenames will not respond to double quotes or double slashes. I found that a single forward slash will escape the spaces in the filenames.

Thanks for taking so much time to assist with this!!!

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

abcminiuser wrote:
Chuck, have you seen the new LUFA build system currently in trunk?

- Dean :twisted:


No, I haven't. Where do I find it?

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

Quote:

Where do I find it?

The website seems to suggest:

SVN: http://www.lufa-lib.org/svn
GIT: http://www.lufa-lib.org/git
src archive: https://github.com/abcminiuser/l...

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

clawson wrote:
Quote:

Where do I find it?

The website seems to suggest:

SVN: http://www.lufa-lib.org/svn
GIT: http://www.lufa-lib.org/git
src archive: https://github.com/abcminiuser/l...


Thanks Clawson.
I was looking in fourwalledcubicle.com. I forgot about lufa-lib.org.

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

Specifically, what I mean are these new makefile modules:

https://github.com/abcminiuser/l...

Which are used in user projects thusly:

https://github.com/abcminiuser/l...

Which means much, much easier to understand and edit project makefiles (no more 1000+ line makefiles for each project). Try "make help" from the project makefiles, which will print out information about the included build module targets.

You can find information on the new build system in the manual (run "make doxygen" on the core) in the new chapter. Also note the new chapter on how to easily export the core and import it into a new AVR Studio 5/Atmel Studio 6 project in the documentation.

- Dean :twisted:

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

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

Looks interesting. Is there going to be a new release soon?

abcminiuser wrote:
You can find information on the new build system in the manual (run "make doxygen" on the core) in the new chapter.

I'm not sure what run "make doxygen" on the core means. What directory do I switch to to run it?
Quote:
Also note the new chapter on how to easily export the core and import it into a new AVR Studio 5/Atmel Studio 6 project in the documentation.

That will be very nice. :)

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

Quote:

Looks interesting. Is there going to be a new release soon?

I'm tossing up whether to wait for more improvements (preliminary IAR support, proper board driver init system) or whether I should release now and potentially change up the APIs yet again. Given that I've never had a release without API changes I suppose it's not a huge issue, but I don't want to upset users more than I have to.

Quote:

I'm not sure what run "make doxygen" on the core means. What directory do I switch to to run it?

To re-make the documentation for the library, navigate inside the core library folder (the "LUFA" folder with the "Drivers", "Common", etc. subfolders) and run "make doxygen". You will need to install Doxygen from www.doxygen.org .

- Dean :twisted:

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

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

abcminiuser wrote:
I'm tossing up whether to wait for more improvements ...

I didn't mean to press you. I'm quite happy with LUFA-120219.
It gives me the USB CDC which is what I was after.
I will be looking at the "import to Studio5" capability that you mentioned.

Any plans to extend LUFA to the ATSAM3S series?

Also, thanks for the explanation on how to generate the documentation.

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

Quote:

Any plans to extend LUFA to the ATSAM3S series?

I've still got to finish the UC3 and XMEGA support, as well as (potentially) add in IAR compatibility -- as well as improve the current code, so while I want to I won't start it yet as I already have enough of a headache.

- Dean :twisted:

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

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

Chuck99-
Thanks for the nice tutorial. After programming the microcontroller atmega32u4 with .hex file for the program (Simple_Cmd_Proc_CDC_Demo), i connected microcontroller custom board to PC via usb. PC is detecting it as "Widget 1000" and asks to install device driver for it. Using hyperterminal i tried but it PC doesn't show any virtual terminal i.e., only COM1 and COM2 are shown. I am using Windows XP. Please suggest.

--Sandeep

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

Quote:

Using hyperterminal i tried but it PC doesn't show any virtual terminal i.e., only COM1 and COM2 are shown.

Look in Device Manager. Not just under COM & LPT but also for anything with a yellow triangle.

Also Google, download and install a copy of usbdeview.exe which tells you loads about USB devices in Windows.

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

sandeepduhan wrote:
Chuck99-
PC is detecting it as "Widget 1000" and asks to install device driver for it. Using hyperterminal i tried but it PC doesn't show any virtual terminal i.e., only COM1 and COM2 are shown. I am using Windows XP. Please suggest.--Sandeep

The "Widget 1000" is from the file Descriptors.c in folder USB_Stuff, so the PC is communicating with your board.

When the PC asked you to install the device driver, you should point to the file Widget_CDC_Setup.inf, which is included in the downloaded .zip file. Is that what you did? The Windows device driver for CDC was discussed in part 2 of the tutorial.

In the past, if Hyperterminal can't find the device, I shut down Hperterminal and unplug the device's usb connection, then reconnect the device and restart Hyperterminal. The device then usually shows up in Device Manager and Hyperterminal will connect.

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

Thanks Chuck99 for quick reply. After pointing to Widget_CDC_Setup.inf, hyperterminal could find the device without shutdown of PC. Finally program tested OK.
Thanks!

--Sandeep

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

sandeepduhan wrote:
Finally program tested OK.

Glad you got it working.

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

Hi!
Excellent tutorial.

I can also verify it works with the atmega32u4, and on the adafruit breakout board with their bootloader.

For reference of other readers.
I just did it on Ubutntu. with make.

JUST MAKE SURE:
MCU = atmega32u4
BOARD = NONE
F_CPU = 16000000

And for fun:
AVRDUDE_PROGRAMMER = avr109
AVRDUDE_PORT = /dev/ttyACM0
AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex

now you can do make program and it will program it aswell.

Other important node. the adafruit bootloader only give you the first 5 seconds (while the green light it flashing)

I spent AGES messing around before realizing that I had somehow set the lock bits and was not actually programming the chip. The error message is about the varify not working. Look it up on avrfreaks, Dean Cameara explains how you need to reflash the boot loader in this case.

I tested with the Simple_Cmd_Proc_CDC_Demo.txt (renamed to Widget_CDC.c) and connected to the serial port using the Eclipse terminal program. (its a plugin, I think i found the instruction on Arduino pages somewhere when getting their stuff to work on Eclipse)

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

Quote:

AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex

That line shouldn't be required, as the default value for that parameter should be equivalent for flash programming. Nice to see someone actually using the new build system I made :).

- Dean :twisted:

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

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

Quote:
Nice to see someone actually using the new build system I made .

Am I? What is that?

I honestly have no idea what I'm doing : P
b.t.w I only managed to get this working with LUFA-120219
it complains about missing .in files with 120730. I expexted to see them in the migrating from 120219 document, but gave up and thought it wiser to just ask here. : )

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

Hi Chuck

 

Thanks for your tutorial, I just finished with part two.

 

Did you remove the pdf of part3? I don't see it on you post. Only the program files...

 

But thanks again for your good work...

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

delcon wrote:
Did you remove the pdf of part3?

Apparently the new forum software dumped the pdf for part 3.

I've attached a copy to this post.

Attachment(s): 

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

yesyesyes

Your tutorial is of great help to me!

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

delcon wrote:

yesyesyes

Your tutorial is of great help to me!

I'm glad you found it useful.

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

Ta Muchly!
Now I can maybe get my (work experience) project going. Maybe they'll give this geriatric,fledgeling AVR programmer a job in 5 months!

-Cheers Chuck99 and Dean Camera.

 

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

Hi,Chuck99-

 

I am following Part 3 of the tutorial.

i am doing a project, which contains AT90USB1286 and EXTERNAL ADC

I made the hardware circuit on general purpose Board and it's working functionality is quite good. 

I want to transfer the data from micro controller to PC via USB.

i stuck at STEP 4 in Part 3 of the tutorial.

 

i am unable to understand what is  "LUFA_PATH".

let me tell about my project file path: C:\Users\BMS\Desktop\TRY_USBB\Widget_CDC\Widget_CDC\makefile.

here, TRY_USBB is the project's folder name and Widget_CDC is the project file name.

 

i downloaded the LUFA-120219 and i found several folders(Bootloaders,BuildTests,Demos,LUFA,Projects) and files(LUFA.pnproj,makefile,README) 

and its Path in my computer is :C:\Users\BMS\Desktop\TRY_USBB\LUFA_lib.

 

 

please tell me what i have to do and give me reply as early as possible.

 

thanking you,

regards,

ldrvasu

 

 

 

 

 

 

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

This thread is about LUFA and Atmel Studio so is it those two things you are using. If so have you downloaded the LUFA extension for AS7? That is 1,000 times easier than worrying about Makefiles and PATHs
 

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

ldr vasu wrote:

I am following Part 3 of the tutorial.

i am doing a project, which contains AT90USB1286 and EXTERNAL ADC

I made the hardware circuit on general purpose Board and it's working functionality is quite good. 

I want to transfer the data from micro controller to PC via USB.

i stuck at STEP 4 in Part 3 of the tutorial.

 

i am unable to understand what is  "LUFA_PATH".

 

Look in: LUFA & Studio5 Beginner’s Guide Part 1, Step 3.  This is where specifying LUFA_PATH is explained in detail.

 

LUFA_PATH tells the makefile in your project where to find the other makefile for the LUFA library, which is "included" by your project makefile.

 

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

thanks Chuck,

i am newbie to this type of micro controller.

 

let me know about what does the LUFA library contain?. Because, there are several folders and files in LUFA-120219. which one helps for my need.

 

 

excuse me for bad english

regards,

ldr vasu

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

 

 

You need to make a list as shown in Figure 20 above.  LUFA_PATH tells the makefile how to get from the Project directory to the library directory

that has the library makefile.