Where is sam.h?

I just spent an hour installing Atmel Studio 7 so that I could load the project file for the bootloader only to have to tell me it can't find sam.h. :frowning:

I found a sam.h in the SAM directory, but this is a SAMD chip and there is no sam.h in the SAMD directory and I'm pretty sure the other one is not the correct file as it does not appear to have definitions in it for SAMD processors.

I have three of them in the Arduino15 directory, but the first one is for the SAM package (Due). The two other are more possibly related to the samd core. I've encountered the same error once in AS7, and I think I used to add the last path to the includes of the project if I remember well.

./Arduino15/packages/arduino/hardware/sam/1.6.6/system/CMSIS/Device/ATMEL/sam.h
./Arduino15/packages/arduino/tools/CMSIS_Devices/ATMEL/sam.h
./Arduino15/packages/arduino/tools/CMSIS/4.0.0-atmel/Device/ATMEL/sam.h

Strangely it seems you need to install the Arduino IDE, open it, run the boards manager, and download the cortext M0 boards package. It seems a bit circular that the bootloader build depends on the Arduino SDK but I guess one could argue it.

Also of note; the build fails if you open the solution over a network share. I had to copy it to my C: to get it to build.

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.

It seems a bit circular that the bootloader build depends on the Arduino SDK but I guess one could argue it.

Heh. Even more-so when you notice that the bootloader was written mostly by Atmel... :slight_smile:

Including sam.h is indicative of projects that used the old "libsam" Atmel libraries. These have been replaced by "asf", and more modern source code will include "asf.h" instead (yeah, even if they aren't actually using the asf library functions. I'm pretty sure that sam.h and/or asf.h preform the same function as avr/io.h - based on the compile-line options, they suck in all the .h definitions for the particular chip and all its peripherals...)

I seem to have a SAMD21 sam.h in "C:\Program Files\Atmel\Studio\7.0\packs\atmel\SAMD21_DFP\1.1.271\samd21a\include\sam.h"
I'm not sure what you tell AS in order to include it...

ASF is just another layer on top of the sam files. sam.h is part of CMSIS and depending the defined part SN, the file link to the correct includes/sources of the CMSIS package. That's why the bootloader relies on sam.h : it is part of the CMSIS package. It has nothing to do with the Arduino framework. CMSIS is needed for any ARM Cortex based application (if you don't want to use direct addressing for peripherals). I think libsam was before the CMSIS standard.

As for the Arduino Sketch import function of AS, I personally prefer to use the Visual Micro plugin with VS Community, it works better.

Hmm. yeah, I overstated the age of "#include "sam.h"" - with my current install of AS7, starting a SAMD21 project produces a skeleton program that does include sam.h. I'm not sure why you're having a problem.
Which bootloader are you trying to build, based on which "project", exactly? The default Zero bootloader has extensive comments about how it's set up to be built using a makefile...
(did you try to import the bootloader as an Arduino project? It isn't an arduino project...)

Hello, was this problem resolved? I am running into the same error after downloading the latest SAM and SAMD versions from the board manager.

Doing what? I don't think anyone even pretends that the board-manager-installed packages are "sufficient" to build the bootloader...

> find . -name sam.h
./hardware/sam/1.6.11/system/CMSIS/Device/ATMEL/sam.h
./tools/CMSIS/4.0.0-atmel/Device/ATMEL/sam.h
./tools/CMSIS-Atmel/1.0.0/CMSIS/Device/ATMEL/sam.h

On the latest version of Atmel Studio 7, there is a bug that appears when you build a solution based on an Arduino sketch in Atmel Studio 7 (V7.0.1417). It complains about sam.h.

Thanks to Bob Martin from Microchip, there is a fix:

The solution has two targets: Arduino Core and the one that comes from the sketch. Repeat the next steps for each.

  • Select the project in the Solution Navigator
  • Choose properties from the Project Menu
  • In the dialog that appears, select Toolchain in the list on the left
  • Scroll through list that now appears and select Directories in the section for the C Compiler
  • Click the green button to add an item to the list of directories
  • Paste in something like C:\Users\Danny\AppData\Local\Arduino15\packages\arduino\tools\CMSIS-Atmel\1.1.0\CMSIS\Device\ATMEL, substituting your username for Danny.
  • If the new entry doesn't appear in the directory list, you may have to figure out where a path like this exists on your system and navigate to it in the dialog box
  • Add the same path to the C++ Directories list

Oops. jrsmiley said this in February. Sorry for the duplication.