1-4 AVR Studio Tutorial

13
Using an archive in AVR Studio This tutorial focus on incorporating an archive of Arduino.cc core code in a AVR Studio project. This is the most portable way of using the Arduino.cc core code. Benefit: Fewer files to manage and easier to track individual contributions. Segregates application code from driver code. Makes source projects more modular and reuseable. Cons: Cannot debug source from the archive - is this really a bad thing? If you are programming via an API, either it works or doesn't. If it doesn't - tell the person who wrote it, don't fix it in one place leaving others with potentially the same problem. Step1: Open AVR Studio and choose new project (Project -> New Project)

Transcript of 1-4 AVR Studio Tutorial

Page 1: 1-4 AVR Studio Tutorial

Using an archive in AVR Studio This tutorial focus on incorporating an archive of Arduino.cc core code in a AVR Studio project. This is the most portable way of using the Arduino.cc core code. Benefit: Fewer files to manage and easier to track individual contributions. Segregates application code from driver code. Makes source projects more modular and reuseable. Cons: Cannot debug source from the archive - is this really a bad thing? If you are programming via an API, either it works or doesn't. If it doesn't - tell the person who wrote it, don't fix it in one place leaving others with potentially the same problem. Step1: Open AVR Studio and choose new project (Project -> New Project)

Page 2: 1-4 AVR Studio Tutorial

Step2: Configure the new project1. Do not create an initial file2. Create a folder to keep things organized

Step3: Select the Simulator and micro-controller that is on your Arduino, then click Finish

Page 3: 1-4 AVR Studio Tutorial

Step4: Open the directory where the project was made and create 4 new folders

1. source - this will contain the user generated source code files2. output - this is where the compiler and linker will barf3. library - this will contain the lib_test_arduino_archive.a archive and header files from the

lib_build folder4. docs - this will contain the output generated by Doxygen if it is used

Page 4: 1-4 AVR Studio Tutorial

Step5: Configure the

Page 5: 1-4 AVR Studio Tutorial

project Step6: Change the general settings

1. The output file directory should be pointed to the output file that was created in step42. The oscillator frequency of the Arduino is 16MHz (16000000Hz)3. Optimization for debugging needs to be -O0

a. The code size will be large but this is the only way that the debugger can be used to produce appropriate steps when jogging through the code.

Page 6: 1-4 AVR Studio Tutorial

Step7: Include Directories - point to the library and source folders that were created in

Page 7: 1-4 AVR Studio Tutorial

step4. Step8: Libraries

1. Add the library folder to the project (now the archive file that it contains is seen below)2. Add Library to the “Link with These Objects”

Page 8: 1-4 AVR Studio Tutorial

Step9: Custom Options

1. Click on -std=gnu99 and choose edit2. Change gnu99 to c993. Click Add4. Make sure that “Use AVR Toolchain” is selected and the path points to the installed tools5. Click OK

Page 9: 1-4 AVR Studio Tutorial

Step10: Create a new file. Right click on “Source Files” and “Create new source”

Page 10: 1-4 AVR Studio Tutorial

1. Name the file main.cpp. The most important thing is that the file extension is .cpp2. “Browse” to the “source” folder created in step4.3. Click

OK

Step12: Include the main resource file and setup the program entrance

1. The main header that must be included is WProgram.h. This will gather all core macros and functions.

Page 11: 1-4 AVR Studio Tutorial

2. Make sure to correct the linker error when using virtual functions.3. init() - this is an Arduino function that is used to configure timing routines4. setup() - this can be omitted or implemented. If it is used enter all setup code that is to

be called once otherwise just list the function calls in its place.5. loop() - Again this can be omitted or implemented. If it is used - all repetitious code is

to be placed in the the function below. Otherwise just list the code withing the while(1) brackets

Page 12: 1-4 AVR Studio Tutorial

Step13: Compile and shizam!