Import Arduino sketch from Arduino IDE 1.8.16 to Atmel Studio 7.0.542 - "Failed to import..."

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

I need to import a (large) existing Arduino project (single INO file) from it's home in Arduino IDE 1.8.16 into Atmel Studio 7, bringing along whatever (standard) Arduino library/support files are necessary to build the project in Atmel Studio 7.0.2542

 

I started out as follows:

 

File -> New Project

choose "Create project from Arduino sketch"

Change name and folder as needed

New dialog box "Create C++ project from Arduino sketch"

Supply sketch file name/path

Confirm Arduino IDE path

Board is "Arduino Uno" (correct for this project)

Device is correct for this project

Click "OK"

After a few moments, I encounter:

 

Failed to import Arduino sketch. 'NoneType' object has no attribute 'token_type'

 

Can this error be narrowed down (i.e., to where the error was encountered)?

 

The INO project file builds properly under Arduino IDE 1.8.16, and has not been modified since, however, it is quite large and I clearly need some help to focus my troubleshooting!

 

Thanks very much for any advice.

 

 

This topic has a solution.
Last Edited: Wed. Dec 15, 2021 - 10:01 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Why do you need to import it?  It's the same compiler!

What is shown in the error tab?

 

FF = PI > S.E.T

 

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

I intended to use import as I would like to have any required Arduino library/support files brought over along with the source .ino file.

 

As the project file is rather large, it would be preferable if Atmel Studio could/would bring across whatever files are needed (presumably .h files and whatever libraries get linked, or for that matter, all such files) so that I could then build the project in Atmel Studio without having to manually figure out which components of Arduino IDE (which I'm seeking to migrate from, not to!) are required.

 

After the dialog box I cited in the original posting is dismissed, there do not appear to be any errors generated (in the Error List bar for Entire Solution the buttons indicate 0 Errors, 0 Warnings, and 0 messages, which I suspect are normally populated by the build process, not the import tool.)

 

Atmel Studio does create a directory (using the name I selected), and a subolder within it of the same name, however, there are no files created in either place.

 

Thanks for the quick reply, hope this provides some additional background to help get me pointed in the right direction!

 

Dave

 

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

WHY ?

 

The Arduino IDE works 100%.

 

AS7.0 is a bit flaky when "importing" a Uno sketch.

AS7.0 is plain useless when importing a Due or Zero sketch.

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

There are a few Arduino wizards here, I'm not one, can you 7-zip your ino file and post it here for others to try to import it and help you trouble shoot the importing of it?

Jim

 

 

FF = PI > S.E.T

 

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

As for Why, I am seeking to create a version of the project with no direct Arduino dependencies (that is, I'll replace the few existing Arduiino dependencies with project-specific equivalents.)

 

I am not in a position to post the source code for the project (and in any event, it's on the large side, so I think given any additional error description beyond a one sentence error message, I should be able fix the issue.)

 

I just created a trivial application (blink the LED on the target's PC board with delay() in loop, which makes use of the Arduino's run-time environment for timer 0) with Arduino IDE, imported it into Atmel Studio 7 using the procedure I noted first above, and it important, built and ran just as expected (creating the simple main/init/setup/loop construct that populates Arduino applications.)

 

It appears Atmel Studio copied the referenced Arduino Core directory into the project (and for my project, all of the dependencies of concern live there), so I now have a feel for how the process should work, but am still concerned about the unhelpful error message (several thousand lines of code means there are plenty of places for something the import utility is rejecting!)

 

Thanks again!

Dave

 

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

Well if that is your goal, then create a cpp project in studio, create your main() with a call to startup(), with a call to loop() in your while(1) loop, then start adding your other files and lib's in as .cpp files to the solution explorer and fix any errors as needed. That is basically what the import task does, you should have a compilable  project by the end of the day....  

 

I have found the import task works ok for simpler sketches, but chokes on the more complex Arduino projects.  So it comes down to use what works, or start from a fresh cpp project and start adding your sketch files to build the project out.  This may mean starting over with a new mind set and project algorithm that does not depend on Arduino methods, otherwise your just duplicating the Arduino method with your own code.

 

I'm still unsure why the need to move to Studio?   Is it just for bragging rights?   If that is the case then don't start with an Arduino sketch.....

 

73 GUD LUCK with your project.

Jim

 

 

FF = PI > S.E.T

 

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

ki0bk wrote:
I have found the import task works ok for simpler sketches, but chokes on the more complex Arduino projects.

That does seem to be the general consensus on these forums.

 

Also, that it chokes on the more "esoteric" Arduino models.

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...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

wb0gaz wrote:
As for Why, I am seeking to create a version of the project with no direct Arduino dependencies

Does this "non-Arduino" IDE have to be specifically  Atmel  Microchip Studio ?

 

If not, I believe there are other IDEs that can take in Arduino "sketches"; eg, VS Code? PlatformIO? Maybe someone's done an Eclipse plugin?

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...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

David, I tried to send you an offer to help with the conversion to your QRZ email address but it bounced!

Jim

 

FF = PI > S.E.T

 

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

Yikes! Thank you ki0bk for the offer and your effort to contact!

 

I just looked at my configuration on qrz.com and the correct/current e-mail address is there, which is my callsign @ yahoo.com. There may be some other enabling behavior in qrz.com I've not configured properly, so I appreciate the heads-up.

 

Since my last posting (and log-in here) and spinning wheels with the import utility, I ended up doing something like what you suggested a few posts back - I created a minimal Arduino application using the delay() function (so as to leverage TIMER0 Overflow interrupt in Arduino library), imported that to Microchip/Atmel Studio 7.0.2542 (that completed OK); that ran that (trivial blink LED with delay() on the target. Then I copied the application I'm working with over into that project, and it compiled and ran on the target.

 

This leads to the next challenge which is a separate/different problem than I cited in the original post (so I'm not sure if I should hijack my own thread or start another question/topic?)

 

In any event, Microchip/Atmel Studio 7.0.2542 produced a binary - occupancy of flash on the ATMEGA328P - somewhat (maybe 10%, I wrapped last night and haven't gotten back to it since to create an exact side-by-side comparison) larger byte count than what was produced with Arduino IDE 1.8.16, which is a problem as the application is right at the capacity limit of the part anyway. I had been assuming that the same underlying compiler (GCC) was involved, but I've not yet been able verify if the compilation settings are the same between the two environments.

 

Continuing work on this!

 

Thanks again for all of the help/comments - greatly appreciated!

 

Dave

 

 

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

Great, glad to hear, you got it working, or at least it compiles....

 

As for the email, I did the classic O for a zero error, Duh!!!   crying

That was why it bounced! 

 

Jim

 

 

 

FF = PI > S.E.T

 

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

You can configure Arduino to be verbose at compile time then see all the switches passed. The tricky thing then is to work out where in Studio 7 all the tick boxes and radio buttons are to set the same switches (ultimately you could just type them in under "Miscellaneous") 

 

If build sizes are radically different it's probably the optimization setting. Arduino doesn't have debugging so it can pick tight optimization like -O3 or -Os. You could start by flipping Studio 7 from "Debug" to "Release". 

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

Thanks, Clawson - I've found the .o files produced by the two different build environments; they're almost all significantly larger with Atmel Studio 7's build.

 

Current problem: I think I am not successfully setting Atmel Studio 7 to "release" configuration for the solution and it's two projects (one project is the sketch, the other project is Arduino core.)

 

Solution Explorer -> Solution (first item) -> Properties -> Configuration Properties, I have Configuration: set to Release, and both project contexts reflect Configuration (drop down list) Release

 

When I go to Arduino Core (one of the two projects in the solution) > Properties, then go to the tab Arduino Core, I find the following

 

Build section > Configuration > Active (Debug)

Build events section > Configuration > Active (Debug)

Toolchain section > Configuration > Active (Debug)

 

I then changed Build section to Release (this caused the other two sections to change to Release), found the same and did the same for my imported Sketch part of the solution (so all of the places I have looked now have Release configuration, not Debug configuration), then did File > Save All, exited Atmel Studio 7, then restarted it.

 

After restart,

 

Solution Explorer -> Solution (first item) -> Properties -> Configuration Properties, it is set to Release.

 

When I go to Arduino Core (one of the two projects in the solution) -> Properties, then go to the tab Arduino Core, I find the following

 

Build section > Configuration > Active (Debug)

Build events section > Configuration > Active (Debug)

Toolchain section > Configuration > Active (Debug)

 

Same for the Sketch part of the solution.

 

When I set both Build sections to Release (again), and then look at the two "Debugging" option areas for AVR/GNU C and AVR/GNU C++, I find they are set at Debug level: Default (-g2). I manually changed these to None (in all four places, two for each project), while the Build sections were set for Release, re-did the build, and got the same flash memory size as I had from the beginning, as if nothing I've done so far has any effectd.

 

For this reason, I'm not certain if I'm successfully building for Debug or Release configuration (I'd imagine Debug creates larger flash sections.)

 

Thanks for any pointer as to where to look next!

 

Dave

 

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

Doesn't Arduino use LTO (https://gcc.gnu.org/wiki/LinkTim...)? That is not default enabled in Studio since it pretty much breaks debugging.

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

wb0gaz wrote:
I manually changed these to None

Don't ever do that! No optimization is only for compiler writers, it produces huge code!  for debug use -Og, for Release use -Os

It's no wonder your code size is larger!!!

 

 

 

FF = PI > S.E.T

 

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

je_ruud - I went into Arduino and removed (most/all) of the flags pertaining to link time optimization (which I've never investigated before); that caused Arduino's build to grow closer to size of the Atmel Studio version, so that is clearly the major difference between the two environments. I will fix it back, but this gives me a path forward.

 

If I can turn on link time optimization for the "release" configuration in Atmel Studio 7, that would be a considerable improvement and allow apples-to-applies comparison (and would almost certainly produce a workable result so I can proceed forward with Studio.)

 

KI0BK - I didn't keep the settings changed there (thanks for the heads-up!), as they didn't cause any change anyway.

 

I would now like to be sure I can set Debug vs Release configuration properly (do you know what I'm doing wrong so that after a restart of Atmel Studio 7 it seems to revert to Debug configuration?) If I can get this (release vs debug) under control, then I should be able add link time optimization flags to the build instructions for "Release" version (I think I saw place for extra flags to be added), and with that, be able go forward with AS7.

 

Thanks very much, this is first forward progress today!

Dave

 

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

Got the problem of Debug vs Release fixed - user error - the place I realized to set this is in the "ribbon" at the top of the main window, not in the project or solution properties. I now can switch configurations; Debug adds about 3% to the flash size requirement which seems reasonable.

 

Now on to the question of how I can enable link time optimization to my Atmel Studio 7 project Release settings.

 

After je_ruud posting (I hadn't encountered this option before), I was able to disable Link Time Optimizaiton in Arduino IDE and that caused the flash requirement to expand significantly (close enough to the Atmel Studio 7 current result that I'm pretty sure this has been the culprit).

 

Now I would like to enable link time optimization in Atmel Studio Release configuration. As je_ruud pointed out, this would break debugging, but for release there's no need for debugging, but a significant need to minimize flash occupancy, so that seems like a reasonable trade-off to me.

 

I've looked through the Toolchain settings and found the following (same for the two projects in the solution, so just examining the settings for the application's project as this is the bulk of the code):

 

AVR/GNU C Compiler All Options:

 

-x c -funsigned-char -funsigned-bitfields -DNDEBUG -DF_CPU=16000000L -DARDUINO=108016 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -DUSB_VID=0x2341 -DUSB_PID=0x0043 -DUSB_MANUFACTURER="\"Arduino LLC\""  -I"C:\Program Files (x86)\Atmel\Studio\7.0\Packs\Atmel\ATmega_DFP\1.7.374\include" -I"C:\Users\user\Desktop\r102w-ms7\r102w-ms7\r102w-2\..\ArduinoCore\include\core" -I"C:\Users\user\Desktop\r102w-ms7\r102w-ms7\r102w-2\..\ArduinoCore\include\variants\standard"  -Os -fno-threadsafe-statics -ffunction-sections -fdata-sections -fpack-struct -fshort-enums -g2 -w -mmcu=atmega328p -B "C:\Program Files (x86)\Atmel\Studio\7.0\Packs\Atmel\ATmega_DFP\1.7.374\gcc\dev\atmega328p" -c -std=gnu99 -std=gnu11 -MD -MP -MF "$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -MT"$(@:%.o=%.o)"

 

AVR/GNU C++ Compiler All Options:

 

-funsigned-char -funsigned-bitfields -DNDEBUG -DF_CPU=16000000L -DARDUINO=108016 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -DUSB_VID=0x2341 -DUSB_PID=0x0043 -DUSB_MANUFACTURER="\"Arduino LLC\""  -I"C:\Program Files (x86)\Atmel\Studio\7.0\Packs\Atmel\ATmega_DFP\1.7.374\include" -I"C:\Users\user\Desktop\r102w-ms7\r102w-ms7\r102w-2\..\ArduinoCore\include\core" -I"C:\Users\user\Desktop\r102w-ms7\r102w-ms7\r102w-2\..\ArduinoCore\include\variants\standard"  -Os -fno-threadsafe-statics -ffunction-sections -fdata-sections -fpack-struct -fshort-enums -g2 -w -mmcu=atmega328p -B "C:\Program Files (x86)\Atmel\Studio\7.0\Packs\Atmel\ATmega_DFP\1.7.374\gcc\dev\atmega328p" -c -std=gnu++11 -MD -MP -MF "$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -MT"$(@:%.o=%.o)"

 

AVR/GNU Linker All Options:

 

-Wl,-Map="$(OutputFileName).map" -Wl,--start-group -Wl,-lm  -Wl,--end-group -Wl,--gc-sections -mmcu=atmega328p -B "C:\Program Files (x86)\Atmel\Studio\7.0\Packs\Atmel\ATmega_DFP\1.7.374\gcc\dev\atmega328p" -Os

 

I didn't find any references to link time optimization among these.

 

Here's where I found enough clues about Link Time Optimization for Arduino IDE to enable me to remove those options temporarily:

 

https://forum.mysensors.org/topi...

 

As the person writing this page was seeking to add Link Time Optimization, the following changes were made (to Arduino IDE at the time):

compiler.c.extra_flags=-flto -fno-fat-lto-objects
compiler.c.elf.extra_flags=-flto -fuse-linker-plugin
compiler.S.extra_flags=-flto
compiler.cpp.extra_flags=-flto
compiler.ar.cmd=avr-gcc-ar

 

Does this provide appropriate guidance for enabling -flto and friends in Atmel Studio 7's GCC settings?

 

Thanks again!

Dave

 

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

Success :-)

 

Added -flto and -fno-fat-lto-objects to the C and C++ compiler "Other optimization flags" and this got very close to the result from Arduino's compiler in it's default settings.

 

Thanks very much to all that have helped here - the import to Atmel Studio 7 is successful (special thanks to catching the "Link Time Optimization" difference - that was key and I wouldn't have found that on my own any time soon).

 

I'm now heading off to use it in lieu of Arduino.

 

 

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

If you aren't using debugging what is the point of moving from Arduino IDE to Studio 7 in the first place? You might actually be better off looking to move from Arduino IDE to Arduino IDE v2.0