Convert Atmel START project to C++

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

I'm porting a project from a different vendor to an Atmel G55 using Studio 7 and Atmel START to pull in all of the drivers I need.  I would like to bring as much code over from the prior project as possible and most of that code is C++.   I've tried renaming the initial files created by importing the Atmel START project into Studio from .c to .cpp but that didn't work.  I also tried unloading the project and editing the .cproj file changing ToolchainName from com.Atmel.ARMGCC.C to com.Atmel.ARMGCC.CPP and Language from C to CPP but that also didn't work and attempting to change it back gave me some odd error at link time.  I ended up having to start from scratch by re-importing my ATZIP file.

Is there a known/recommended way to create a C++ project by importing an ATZIP from Atmel START?

 As a side note, I can't use Atmel START from within Studio 7.  I completely lose the ability to scroll and all of the elements.  Instead I have to go to start.atmel.com and export my project.

-- Mike

Michael A. Fallavollita
Vice President of Research and Development
mikef@valentpower.com

Valent Power, Inc.
5617 Scotts Valley Dr. Suite 100
Scotts Valley, CA  95066
   

 

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

Are any Atmel/Microchip engineers watching these forums?   Either I've asked such a simple question that everyone thinks the answer is obvious or no one has any idea?  Its hard to believe that I'm the only one trying to use C++ with Atmel START.  Perhaps I've asked this in the wrong forum?

-- Mike

Michael A. Fallavollita
Vice President of Research and Development
mikef@valentpower.com

Valent Power, Inc.
5617 Scotts Valley Dr. Suite 100
Scotts Valley, CA  95066
   

 

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

MFallavol wrote:
Are any Atmel/Microchip engineers watching these forums?

Not officially - they are end-user forums

 

'C' does remain by far the majority language for microcontroller development - so, yes, you will be in something of a minority with C++

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
Last Edited: Tue. Apr 25, 2017 - 04:22 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

In case anyone else is trying this, here is the official response from Microchip support. "Please note Atmel start drivers has been written in C only, you can't import it as C++ project in Atmel Studio."

Based on the poor English we can guess that Microchip support is not domestically based.

-- Mike

Michael A. Fallavollita
Vice President of Research and Development
mikef@valentpower.com

Valent Power, Inc.
5617 Scotts Valley Dr. Suite 100
Scotts Valley, CA  95066
   

 

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

I solved this. You need to compile Atmel Start project as a static library, and then link it to an exectable that may be created in C++. Thanks to this, you can use C++ in your project while Atmel Start project is still in C.

Instruction:

 

Project: ATStart_FeatherM0

 

1. Created from ATmel Start creator.

2. Change project type in: Project Properties -> Build -> Artifact type: Static library

3. Theoretically main.c and Device_Setup can be removed from project.

4. Static library will be compiled by: arm-none-eabi-gcc.exe.

5. Override project files when you generate new one in creator.

 

Project: FeatherApp

 

1. Created from Visual Studio (GCC C++ Executable Project)

2. Add library reference to static library project: Libraries -> Add Library -> Project Libraries -> ATStart_FeatherM0.

3. Include the same headers as in static library. 

3.1 Go to ATStart_FeatherM0 project properties -> Toolchain -> ARM/GNU C Compiler -> Directories.

3.2 Copy every path to application project. FeatherApp project properties -> Toolchain -> ARM/GNU C++ Compiler -> Directories.

3.3 Example: "../hal/utils/include" will become "../../ATStart_FeatherM0/hal/utils/include"

4. Enable C++ 11. FeatherApp project properties -> Toolchain -> ARM/GNU C++ Compiler -> Miscellaneous -> Other Flags: -std=c++0x

5. Add linker flag: FeatherApp project properties -> Toolchain -> ARM/GNU Linker -> Miscellaneous -> Linker Flags, add: -Wl,--section-start=.text=0x2000

6. Make sure your files have .cpp extensions.

7. Set FeatherApp as startup project.

6. Application will be compiled by: arm-none-eabi-g++.exe.

 

Edit:

I forgot to mention that I used ATSAMD21G18A built into Adafruit Feather M0 board. Useful links:

https://learn.adafruit.com/adafr...

https://reprapdad.wordpress.com/...

Last Edited: Wed. Jun 13, 2018 - 02:58 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I actually got this to work the way I wanted it to.   I did it by creating a basic C project and a basic C++ project and comparing the .cproj files. Mostly it means copying or moving things from the C toolchain to the CPP toolchain.  eg  <ToolchainName>com.Atmel.ARMGCC.C</ToolchainName>

becomes

<ToolchainName>com.Atmel.ARMGCC.CPP</ToolchainName>

 

<ToolchainSettings>
      <ArmGcc>

changes to 

   <ToolchainSettings>
      <ArmGccCpp>

 

Mostly I copied sections like <armgcc.linker.libraries.Libraries> and created cpp counterparts <armgcccpp.linker.libraries.Libraries>

 

It was a pain and I wouldn't want to do it too often but it did get the job done.  I've done it for multiple projects.

 

  -- Mike

 

 

 

-- Mike

Michael A. Fallavollita
Vice President of Research and Development
mikef@valentpower.com

Valent Power, Inc.
5617 Scotts Valley Dr. Suite 100
Scotts Valley, CA  95066
   

 

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

Thanks for the instructions. Following these steps, I couldn't run a program on a SAMC21. I removed the linker flag (i.e. don't do step 5 in FeatherApp) so that it does not start at 0x2000 and that seemed to do that trick.

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

I'm trying to do the same.  I'm porting an ATSAMD11C14A project from Arduino (using the Mattairtech generic SAMD11C14A target) to Atmel START, and just found that renaming main.c to main.cpp resulted in it not getting compiled at all.  For my first attempt, which just results in an error about the url attribute when trying to load the solution file into Atmel Studio 7, I did this:

 

- renamed the .cproj to .cppproj

- changed ToolchainName to com.Atmel.ARMGCC.CPP

- replaced ArmGcc> with <ArmGccCpp>

- replaced armgcc with armgccpp

 

I'll update here when I have more...

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

Hi!

I converted the START project to library and used the library in a new C++ project. COmpiled very well.

I wrote a article to Portal Embarcados describing this procedure (in portuguese) : https://www.embarcados.com.br/in...