Atmel Studio 7 Create Project From Arduino Sketch Build Failure

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

BACKGROUND: While I've found answers on AVR Freaks in the past, I'm having some difficulty with AS7 and some Arduino functions, and its finally driven me over the edge to make my first post here. I have some experience with Microchip's ecosystem (XC8, MPLAB X, PIC enhanced 8-bit micros) but am now evaluating other micros for two projects, one of which is a relatively simple embedded system and the other is an IoT application. I've played with Arduino personally and am interested in learning more about how Atmel's ecosystem works on a professional scale. Documentation indicates that Atmel Studio 7 now supports the direct creation of AS projects based on an Arduino sketch which seems like a reasonable way to get my feet wet as I learn more about AVR and SAM. I am not an experienced EE, but I have done PIC work from whole cloth and have some experience with C, but the majority of my programming has been in Python and C#/.NET. 

 

ISSUE: Creating a project from Arduino sketch fails to build correctly for Arduino Zero and Arduino Due, but succeeds when building for Arduino Uno.

 

ENVIRONMENT: Atmel Studio 7.0.188, Arduino.cc 1.6.9/1.6.13/1.8.0, Arduino Due Libraries 1.6.10, Arduino Zero Libraries 1.6.11, Visual Studio 2015 (14.0.25420.1) on same system with support for C/C++, Windows 10 Anniversary Update.

 

Test Case 1: Importing Blink example sketch for programming to Arduino Zero. This was repeated for Arduino.cc IDE 1.6.9, 1.6.13, and 1.8.0 with the same result. Each Arduino installation was removed between attempts and there has never been a concurrent install of two different versions of Arduino or AS on this machine.

 

STEPS TAKEN:

 

  1. Open Atmel Studio
  2. Select File | New | Project
  3. Select "Create project from Arduino sketch" ( leaving default location, "create directory for solution" checked)
  4. In "Create C++ project from Arduino sketch" popup, set Sketch File to "C:\Program Files (x86)\Arduino\examples\01.Basics\Blink\Blink.ino", Arduino IDE Path to "C:\Program Files (x86)\Arduino", Board to "Arduino/Genuino Zero (Programming Port)", and Device to the only option, "ATSAMD21G18A". 
  5. Once Solution is loaded, press F7 to build solution.
  6. Build fails with error list citing "sam.h: No such file or directory", full output text attached as Arduino Zero Output Failure 1.txt.

 

ATTEMPTED SOLUTIONS:

 

  1. Other forum members indicate that sam.h can be located from Arduino's AppData folder, in my case, "C:\Users\exova\AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.10\system\CMSIS\Device\ATMEL\sam.h". After finding the file, I expanded ArduinoCore | include | core, right clicked the "core" folder, selected Add | Existing Item, and provided it the sam.h file in AppData. Selecting Build | Rebuild Solution does result in a new Error List and Output file, just not for the better (Arduino Zero Output Failure 2.txt and png).
  2. Another forum suggested removing all included header files and replacing them with the output of the Arduino build. I attempted this but it also did not succeed, I can reattempt if someone needs the information and record it if necessary. 
  3. Uninstalled Atmel Studio and reinstalled. No effect.
  4. Uninstalled Arduino IDEs and reinstalled. No effect.
  5. Uninstalled Visual Studio and attempted procedure. No effect.
  6. Formatted computer (just kidding, I upgraded my SSD, but it is a clean Windows 10 install) and attempted procedure with clean installs. Also same behavior.

 

I want to believe it's something stupid that I'm just not seeing or thinking of, but I've been messing with this for two days now and I can't get it to work. Doing the same steps but targeting an Arduino UNO builds fine. And while I have seen some people state that AS doesn't support this feature on ARM micros, both Adafruit and Atmel themselves have YouTube videos of them using AS 7 to do exactly this on an Arduino Zero (Adafruit: https://www.youtube.com/watch?v=... ; Atmel: https://www.youtube.com/watch?v=...) as well as written documentation from Adafruit explaining this procedure here: https://learn.adafruit.com/prope... . AS7 is able to read information from the Arduino Zero (see screenshot) and if I create a new blank C or C++ executable, I can write it to the device with the expected behavior. Arduino IDE can successfully program the Blink sketch as well as write a new bootloader to the device.

 

The Due has the same behavior but complains about a different header file. I can write down the specifics, but I get the feeling that if we can solve the Zero, the Due might also be solved, so I'm going to hold off writing unless someone asks. Sorry this came out to be so long, but thanks for reading and any help is greatly, greatly appreciated. Thanks!

Attachment(s): 

This topic has a solution.
Last Edited: Tue. Jan 3, 2017 - 01:50 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

surprise so is this an AVR related question or an ARM related question or both?? You have posted in the AVR related Studio forum but we also have an ARM related Studio forum, I know confusing but that's how it is. Trying to keep posts in the correct forum if possible.

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

Ah, my mistake. Yes, it belongs in the ARM forum. What's the preferred way of getting this question to the right spot, delete and repost?

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

I'll move it.

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

I had the same problem. The issue is that the Arduino SAMD core started using the CMSIS-Atmel package as of version 1.6.9. This moved the location of sam.h and all of its dependencies to a different directory and Atmel Studio can't find it using the built-in template for creating projects from Arduino sketches.

I have not been able to find a way to tell Atmel Studio where the new location is, but I worked around this by creating a Windows "junction" link using the old pathname to point to the new pathname:

mkdir C:\Users\xxx\AppData\Local\Arduino15\packages\arduino\tools\CMSIS\4.0.0-atmel\Device
cd C:\Users\xxx\AppData\Local\Arduino15\packages\arduino\tools\CMSIS\4.0.0-atmel\Device
mklink /J ATMEL C:\Users\xxx\AppData\Local\Arduino15\packages\arduino\tools\CMSIS-Atmel\1.0.0\CMSIS\Device\ATMEL

After that, creating new SAMD projects in Atmel Studio 7 using the Arduino template will compile and debug as expected.

SAMD core 1.6.8 and prior
C:\Users\jrsmi\AppData\Local\Arduino15\packages\arduino\tools\CMSIS\4.0.0-atmel\Device\ATMEL

SAMD core 1.6.9 and later
C:\Users\jrsmi\AppData\Local\Arduino15\packages\arduino\tools\CMSIS-Atmel\1.0.0\CMSIS\Device\ATMEL

From the changelog

SAMD CORE 1.6.9 2016.12.12
* MKR1000: Enabled PWM on pin 11, it is shared with pin A4
* SPI: Optimized SPI.transfer(...)
* Added linker flags for the ARM Math library
* Added new I2S library
* Bootloader: Check sketch vectors before waiting for double tap
* Upgraded CMSIS version to 4.5.0, and use new CMSIS-Atmel package
* Added Arduino MKRZero board.

Also note that older versions of the Arduino IDE (1.6.8 and prior) will not work with SAMD Core versions 1.6.9 or later due to a similar issue (the old IDE can't find sam.h).

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

This solved my problem! Incredible work finding a sensible workaround. I really appreciate the response. Thank you very, very much.

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

I am trying to import Blink.ino from Arduino examples, gives following error:

 

------ Rebuild All started: Project: Blink, Configuration: Debug ARM ------
Build started.
Project "Blink.cppproj" (default targets):
Target "PreBuildEvent" skipped, due to false condition; ('$(PreBuildEvent)'!='') was evaluated as (''!='').
Target "CoreBuild" in file "C:\Program Files (x86)\Atmel\Studio\7.0\Vs\Compiler.targets" from project "C:\Users\user\Documents\Development\ArduinoSketch1\ArduinoSketch1\Blink\Blink.cppproj" (target "Build" depends on it):
	Task "RunCompilerTask"
		Shell Utils Path C:\Program Files (x86)\Atmel\Studio\7.0\shellUtils
		C:\Program Files (x86)\Atmel\Studio\7.0\shellUtils\make.exe all --jobs 4 --output-sync 
		Building file: .././Sketch.cpp
		Invoking: ARM/GNU C Compiler : 5.3.1
		In file included from ..\\..\ArduinoCore\include\core/Arduino.h:41:0,
		                 from .././Sketch.cpp:2:
C:\Users\user\Documents\Development\ArduinoSketch1\ArduinoSketch1\ArduinoCore\include\core\itoa.h(29,65): error: conflicting declaration of C function 'char* utoa(long unsigned int, char*, int)'
		 extern char* utoa( unsigned long value, char *string, int radix ) ;
		                                                                 ^
		In file included from c:\program files (x86)\atmel\studio\7.0\toolchain\arm\arm-gnu-toolchain\arm-none-eabi\include\stdlib.h:11:0,
		                 from ..\\..\ArduinoCore\include\core/Arduino.h:25,
		                 from .././Sketch.cpp:2:
c:\program files (x86)\atmel\studio\7.0\toolchain\arm\arm-gnu-toolchain\arm-none-eabi\include\stdlib.h(201,8): info: previous declaration 'char* utoa(unsigned int, char*, int)'
		 char * _EXFUN(utoa,(unsigned, char *, int));
		        ^
		make: *** [Sketch.o] Error 1
		"C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\arm\arm-gnu-toolchain\bin\arm-none-eabi-g++.exe" -mthumb -D__SAMD21G18A__ -DDEBUG -DF_CPU=48000000L -DARDUINO= -DARDUINO_SAMD_MKRZERO -DARDUINO_ARCH_SAMD -DUSB_VID=0x2341 -DUSB_PID=0x804f -DUSB_PRODUCT="\"Arduino MKRZero\"" -DUSB_MANUFACTURER="\"Arduino LLC\"" -DUSBCON -DSAMD_SERIES  -I"C:\Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\SAMD21_DFP\1.1.271\samd21a\include" -I"C:\Program Files (x86)\Atmel\Studio\7.0\Packs\arm\cmsis\4.2.0\CMSIS\Include" -I"..\\..\ArduinoCore\include\core" -I"..\\..\ArduinoCore\include\variants" -I"..\\..\ArduinoCore\include\core\avr" -I"..\\..\ArduinoCore\include\core\samd21" -I"..\\..\ArduinoCore\include\core\USB" -I"..\\..\ArduinoCore\include\core\samd21\include" -I"..\\..\ArduinoCore\include\core\samd21\include\component" -I"..\\..\ArduinoCore\include\core\samd21\include\instance" -I"..\\..\ArduinoCore\include\core\samd21\include\pio"  -Os -fno-threadsafe-statics -fno-exceptions -ffunction-sections -fdata-sections -fno-rtti -fno-exceptions -g3 -w -mcpu=cortex-m0plus -c -std=gnu++11 --param max-inline-insns-single=500 -nostdlib -MD -MP -MF "Sketch.d" -MT"Sketch.d" -MT"Sketch.o"   -o "Sketch.o" ".././Sketch.cpp" 
C:\Users\user\Documents\Development\ArduinoSketch1\ArduinoSketch1\Blink\Debug\Makefile(87,1): error: recipe for target 'Sketch.o' failed
	Done executing task "RunCompilerTask" -- FAILED.
Done building target "CoreBuild" in project "Blink.cppproj" -- FAILED.
Done building project "Blink.cppproj" -- FAILED.

Build FAILED.
========== Rebuild All: 0 succeeded, 2 failed, 0 skipped ==========

I am using Arduino 1.8.0 and Atmel Studio 7.0.1188

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

Hi,

 

I have the same issue when trying to compile blink.ino in Atmel Studio 7.

 

My system already has the following directory:

 

C:\Users\timothy.ellis\AppData\Local\Arduino15\packages\arduino\tools\CMSIS\4.0.0-atmel\Device\ATMEL

 

so when I type:

 

mkdir C:\Users\xxx\AppData\Local\Arduino15\packages\arduino\tools\CMSIS\4.0.0-atmel\Device

 

It complains and says the directory already exists.

 

then when I type this it says the folder already exists too:

mklink /J ATMEL C:\Users\xxx\AppData\Local\Arduino15\packages\arduino\tools\CMSIS-Atmel\1.0.0\CMSIS\Device\ATMEL

 

Could you please advise how to work around this?

 

Thanks

 

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

I have the same problem like described by Rookie.

Windows 8, AVR 7.0.1188, Arduino IDE 1.6.13

Adafruit Feather M0

 

With vMicro in the same AVR 7 it works. But I want to use my new ICE debugger and this don't work that nicely in vMicro.

 

Rainer from Hannover, Germany

Last Edited: Mon. Feb 6, 2017 - 09:43 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I found a better way!

 

For any other newbies like me who don't already know how to add an Include path in Atmel Studio 7:

 

When you created the AS7 project from the Arduino sketch, it creates a Solution with two Projects, one named "ArduinoCore" and one with the name you chose for your Arduino sketch.  In order to get AS7 to build correctly with SAMD-based projects (Zero, MKR1000, MKRZero, M0, Tian, etc.) you need to add the path to the Atmel CMSIS library in four places: one for the C compiler and one for the C++ compiler in the ArduinoCore project plus one for the C compiler and one for the C++ compiler in the project associated with your Arduino sketch.

 

To do this, in the Solution Explorer pane, right click the ArduinoCore project and select Properties.  This will open the Properties pane.  On the left, select Toolchain.  Then under ARM/GNU C Compiler select Directories.  Click the Add Item button and then enter the full path to the SAMD CMSIS files.  Uncheck the Relative Path box and click on OK.  Repeat this for the ARM/GNU C++ Compiler.  Then repeat the process again starting with right clicking on the project associated with your Arduino sketch.

 

The path will look something like this:
C:\Users\<myWindowsName>\AppData\Local\Arduino15\packages\arduino\tools\CMSIS-Atmel\1.1.0\CMSIS\Device\ATMEL

 

These files are installed by the Arduino IDE when you use the board manager to install support for SAMD boards.  Note that the path name may change with new releases of the Arduino IDE or board support packages, so verify the location on your system.

Last Edited: Sat. Feb 18, 2017 - 11:01 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello jrsmiley

Thanks for this hint - I did it like you described above - with the arduino fade example i get this error messages now - what to do?

Thanks in advance!!

x cannot open linker script file flash.ld: No such file or directory
x recipe for target 'Fading-elf' failed
x ld returned 1 exit status

 

Rainer from Hannover, Germany

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

Wood-Walker wrote:

Hello jrsmiley

Thanks for this hint - I did it like you described above - with the arduino fade example i get this error messages now - what to do?

Thanks in advance!!

x cannot open linker script file flash.ld: No such file or directory
x recipe for target 'Fading-elf' failed
x ld returned 1 exit status

 

Those errors aren't related to the sam.h / Atmel CMSIS issue.  I would go back and check the basics:

1. SAMD board support package installed in the Arduino IDE

2. The appropriate SAMD-based board is selected in the Arduino IDE

3. You have saved the Fade demo program as your own sketch in the Arduino IDE (ex: myFade)

4. The sketch compiles and loads correctly in the Arduino IDE
5. The AS7 project was created from the Arduino sketch (ex: myFade) and not from the Arduino Example library

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

hello,

can i use arduino library in Atmel studio 7 for ATSAMD21 xplained PRO board.If yes then how??

I have tried  to create project in AS7 by importing arduino sketch but it is not working for ATSAMD21J18A xplained pro board.