Introduction
Hello everybody!
I'm back to my blog with several interesting articles. Now I'm working on telepresence robot, actually I'm using it from 04/12 and doing improvements all the time. Well.. long story short - my mother survived a stroke and now as a reault she has troubles with health, so I need an ability to stay at home, but I'm working at Betsson Tech in Kiev and it is nearly 400km from home. I love, yeah.. really love, my job so after discussion with management I had an approval to work remotely from home (thank you very much guys!).
It is cool, but new trouble arised - I need an ability to attend daily standups, plannings etc in Betsson Tech in Kiev. That is how idea to create telepresence robot arised. I'll write about the robot with some video and description of social aspects of using such a telebot in one of the future articles.
And today I want to start serie of articles about using Atmel Studio 6 with Arduino Mega 2560 development board. The Plan is to write about:
Part 1. Common project configuration + precompilation of Arduino Core and some Libraries
Part 2. freeRTOS for Arduino
Part 3. Google Protocol Buffers for Arduino + STL
Part 4. NanoPB for Arduino
So, lets start.
Common project configuration + precompilation of Arduino Core
First of all you need to download and install Atmel Studio 6. Then create a solution named Arduino.Precompiled (File -> New project... -> Atmel studio solution -> Blank Solution) and one static library named Arduino.Precompiled.Core (Right click on solution in Solution Explorer -> Add -> New project):
Create new project |
Then you will be asked to select your device. I'm using Arduino Mega 2560 board with MCU ATmega2560:
Select device |
Add core files |
Set library name |
Now go to Build Events tab:
Setting post-build event |
Now we are ready to configure our Toolchain. Go to Toolchain tab, and select Symbols item for C or C++ compiler:
Configure toolchain: symbols |
- F_CPU - frequency of MCU you use. In case of Arduino Mega 2560 it is 16MHz or 16,000,000 Hz.
- ARDUINO is for version of Arduino framework, as you can see I use 1.0.3. Used for examle in Firmata library. But in our case it is optional and you can skip this definition at all.
- USB_VID and USB_PID is for vendor ID and peripheral ID, we are not using it. You can search for actual values in USBCore.cpp.
- __AVR_LIBC_DEPRECATED_ENABLE__ - use this definition to prevent compilation errors with Arduino libraries. Sorry, had no time to dig into it...
Next configure include directories (all configurations too):
Configure toolchain: directories |
In case you use another board, not Mega 2560, choose appropriate subfolder in variants folder.
Now we are ready to configure optimization section for Debug and Release modes separately:
Configure toolchain: miscellaneous |
With compillers we done, and now we should configure linker. Only in Release mode do next:
Configure toolchain: linker |
So, we are nearly done. Just remove unneccessary file that Atmel Studio created automagically:
Remove unneccessary file |
- Right click on project and choose Unload Project
- Right click on project and choose Edit Arduino.Precompiled.Core.cppproj
- Change your project file as shown on the image below:
Change name of library in project file |
After you done, just right click again and choose Reload Project. Thats it, now you have precompiled arduino static library in your Arduino.Precompiled.Release and\or Debug folders:
Library in the folder |
And here is small video that show you how to create project with precompiled Arduino Core library in Atmel Studio 6:
And here is flushing and testing:
Do you noticed memory statistics in the log? It shows how much you program takes in Flash (Program Memory Usage) and in RAM (Data Memory Usage). So make sure that Data Memory Usage is not more than you board can handle. For Arduino Mega it is 8KB.
Also I'm using avrdude to flush program into board, here is contents of flush.cmd:
Also I'm using avrdude to flush program into board, here is contents of flush.cmd:
c:\Users\User1\Downloads\arduino-1.0.1\hardware\tools\avr\bin\avrdude.exe -CC:\Users\User1\Downloads\arduino-1.0.1\hardware\tools\avr\etc\avrdude.conf -p m2560 -c wiring -P COM4 -b 115200 -F -U flash:w:%1%:i pause
That's all for today. Next article will be about precompiling Arduino Libraries.
thanks.
ReplyDeleteNice article, very detailed!
ReplyDeleteHave you seen the add-in for Arduino programming with Atmel Studio 6.1 over at visualmicro.com?
It includes a software debugger that is sweet.
Thank you for this article, I learned a lot!
ReplyDeleteI was trying to build the Arduino 1.5.5-r2 core library with Atmel Studio 6.1, but it seems that the Atmel Studio's native avr-g++ compiler is not happy about the sources. I get strage Errors on WString.cpp:
WString.cpp(189,26): ISO C++ forbids declaration of 'type name' with no type [-fpermissive]
I tried to run the WinAVR's avr-g++ compiler with the same arguments, Atmel Studio generated, and that worked (in a terminal window).
There is an option in Tools->Options...->Toolchain to change the Toolchain Path. For AVR 8-bit C language, there even was a predefined Toolchain Flavor called WinAVR. I added one for the CPP language and pushed the "Set As Default" button, but Atmel Studio does not seem to care about that.
Do you have any idea, how to get the Atmel Studio g++ compiler compile this library's version?
cheers, Niun
I just discoverd that there is an "Advanced" tab in project properties. There you can change the Toolchain Flavor. Setting this to WinAVR makes my Arduino 1.5.5-r2 core compiling.
DeleteIs there a way to get this to work with the Arduino Due?
ReplyDeleteI have tried to do it but keep getting errors. I changed all of the locations to the correct Due folders but still nothing.