[SOLVED] Importing complex Arduino .ino sketch in Atmel Studio 7

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

Hi All,

I'm trying to convert an .ino sketch to Atmel Studio 7.

The sketch compiles in Arduino IDE without errors and with the following messages:
 

d:\Users\Paul\Documents\Arduino\libraries\XpressNetMaster\XpressNetMaster.cpp: In member function 'void XpressNetMasterClass::SetLocoBusy(uint8_t, uint16_t)':

d:\Users\Paul\Documents\Arduino\libraries\XpressNetMaster\XpressNetMaster.cpp:342:38: warning: narrowing conversion of '(((int)UserOps) | 256)' from 'int' to 'unsigned int' inside { } [-Wnarrowing]

  unsigned int LocoInfo[] = { UserOps | 0x100, 0xE3, 0x40, Adr >> 8, Adr & 0xFF, 0x00 };

                                      ^

d:\Users\Paul\Documents\Arduino\libraries\XpressNetMaster\XpressNetMaster.cpp: In member function 'void XpressNetMasterClass::SetLocoInfo(uint8_t, uint8_t, uint8_t, uint8_t, uint8_t)':

d:\Users\Paul\Documents\Arduino\libraries\XpressNetMaster\XpressNetMaster.cpp:356:38: warning: narrowing conversion of '(((int)UserOps) | 256)' from 'int' to 'unsigned int' inside { } [-Wnarrowing]

  unsigned int LocoInfo[] = { UserOps | 0x100, 0xE4, B00001000 | Steps, Speed, F0, F1, 0x00 };

                                      ^

d:\Users\Paul\Documents\Arduino\libraries\XpressNetMaster\XpressNetMaster.cpp:356:63: warning: narrowing conversion of '(int)(Steps | 8u)' from 'int' to 'unsigned int' inside { } [-Wnarrowing]

  unsigned int LocoInfo[] = { UserOps | 0x100, 0xE4, B00001000 | Steps, Speed, F0, F1, 0x00 };

                                                               ^

d:\Users\Paul\Documents\Arduino\libraries\XpressNetMaster\XpressNetMaster.cpp: In member function 'void XpressNetMasterClass::SetFktStatus(uint8_t, uint8_t, uint8_t)':

d:\Users\Paul\Documents\Arduino\libraries\XpressNetMaster\XpressNetMaster.cpp:366:37: warning: narrowing conversion of '(((int)UserOps) | 256)' from 'int' to 'unsigned int' inside { } [-Wnarrowing]

  unsigned int LocoFkt[] = { UserOps | 0x100, 0xE3, 0x52, F4, F5, 0x00 };

                                     ^

d:\Users\Paul\Documents\Arduino\libraries\XpressNetMaster\XpressNetMaster.cpp: In member function 'void XpressNetMasterClass::SetTrntStatus(uint8_t, uint8_t, uint8_t)':

d:\Users\Paul\Documents\Arduino\libraries\XpressNetMaster\XpressNetMaster.cpp:380:38: warning: narrowing conversion of '(((int)UserOps) | 256)' from 'int' to 'unsigned int' inside { } [-Wnarrowing]

  unsigned int TrntInfo[] = { UserOps | 0x100, 0x42, Address, Data, 0x00 };

                                      ^

d:\Users\Paul\Documents\Arduino\libraries\DCCInterfaceMaster\DCCPacketScheduler.cpp: In member function 'bool DCCPacketScheduler::setBasicAccessoryPos(uint16_t, bool, bool)':

d:\Users\Paul\Documents\Arduino\libraries\DCCInterfaceMaster\DCCPacketScheduler.cpp:508:53: warning: narrowing conversion of '(((address + ((uint16_t)((DCCPacketScheduler*)this)->DCCPacketScheduler::TrntFormat)) & 3u) << 1)' from 'uint16_t {aka unsigned int}' to 'uint8_t {aka unsigned char}' inside { } [-Wnarrowing]

  uint8_t data[] = { ((address + TrntFormat) & 0x03) << 1 }; //0000-CDDX

                                                     ^

Sketch uses 37,130 bytes (14%) of program storage space. Maximum is 253,952 bytes.
Global variables use 2,703 bytes (32%) of dynamic memory, leaving 5,489 bytes for local variables. Maximum is 8,192 bytes.

Creating a new project in Atmel Studio 7 (File -> New -> Project -> C/C++ -> Create project from Arduino sketch -> Create C++ project from Arduino sketch -> filling Sketch File, Arduino IDE Path, Board and Device-> OK) gives an error
 

not enough arguments for format string

A Simple sketch gives no problems.

The project's documentation and sketch files and necessary libraries can be found here : http://pgahtow.de/wiki/index.php?title=Zentrale

Any suggestions are very welcome !

Thanks in advance,

Paul

This topic has a solution.

"As simple as possible, but not simpler"

GUI Framework for Atmel Xplained Pro

Last Edited: Mon. Jul 25, 2016 - 09:29 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Don't investigate any further on this situation....

I now see that

 

uint8_t data[] = { (address & 0x03) << 1 }; //0000-CDDX

 

is indeed not conform the C/C++ standards. (address is a 16-bits value).

That this line of code is marked as simply a warning in Arduino confuses me. IMHO this MUST BE flagged as an error (as I suppose AS is doing while importing the .ino file, but AS simply quits the import with the aforementioned dialog box, which is not very helpful in my situation).  That this erroneous line of code works is imho just great luck!  I think the reason that it works in the situation at hand is, since a pointer (to any type of data) in AVR is a 16-bits value, and I'm reasonably sure you assign it a 16-bits value, there is no problem at run-time.  BUT, if you port this code to another architecture it will absolutely run hocus pocus..

Depending on the endianness of the underlying architecture one could write ?better? code, for example
 

uint8_t data[2];

data[0] = uint8_t(((address & 0x03) << 1) >> 8);
data[1] = uint8_t(((address & 0x03) << 1) & 0xFF);

 

or
 

uint8_t data[2];

data[1] = uint8_t(((address & 0x03) << 1) >> 8);
data[0] = uint8_t(((address & 0x03) << 1) & 0xFF);

 

Although that this code is not portable since it's depending on the underlying architecture…

Please warn me when I'm wrong… ;)

I'm further browsing the Arduino code to make it in accordance to the C/C++ standard, or start all over again and create a new project in AS7.  (the original Arduino code is public on the www, is relative complex so I hope I'm able to reuse this Arduino code and modify/debug it with Atmel Studio using an Atmel ICE as debugger.  AFAIK, there are no debugging facilities at all in the Arduino IDE, aside from the printf(...) method which make the original code a mess to debug/run later on, worse after a few years.

Great thanks for all your replies.

Paul

"As simple as possible, but not simpler"

GUI Framework for Atmel Xplained Pro

Last Edited: Sat. Sep 10, 2016 - 11:00 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

PaulVdBergh wrote:
AFAIK, there are no debugging facilities at all in the Arduino IDE, aside from the printf(...) method which make the original code a mess to debug/run later on, worse after a few years.
Can only recall the relatively new GDB interface in Visual Micro but that's currently only for Arduino ZERO (hopefully in the future for Arduino UNO).

Visual Micro has a non-GDB debugger interface that's at least something instead of nothing for Arduino UNO and etc. (AVR Arduino)

http://playground.arduino.cc/Main/DevelopmentTools

to

Arduino for Visual Studio :

http://playground.arduino.cc/Main/DevelopmentTools#VMVS

, or, Arduino for Atmel Studio :

http://playground.arduino.cc/Main/DevelopmentTools#VMAS

which was very recently updated for Atmel Studio 7 (that version was recently added to Atmel Gallery) :

http://www.visualmicro.com/page/Visual-Micro-Product-Version-History-Fixes-and-Additions.aspx (go to "24th June 2016" and "7th July 2016")


Visual Micro - Arduino IDE for Visual Studio

Arduino IDE for Visual Studio and Atmel Studio

Debugging Explained

http://www.visualmicro.com/page/User-Guide.aspx?doc=Debugging-Explained.html

...

Debugging support with the Visual Micro Debugger

With most boards, the Visual Micro debugger uses Hardware Serial or Software Serial to operate.

For newer 32 bit boards, such as the Arduino Zero, a GDB based option is also available ...

...

Atmel Corporation

Atmel Gallery

Arduino IDE for Atmel Studio 7

https://gallery.atmel.com/Products/Details/35ff0eff-9ee9-4a98-a48b-ff24fc4077a0

Edit : Visual Micro debugging via serial port URL, Visual Micro for Atmel Studio in Atmel Gallery URL

 

"Dare to be naïve." - Buckminster Fuller

Last Edited: Tue. Jul 19, 2016 - 02:49 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

PaulVdBergh wrote:
I'm further browsing the Arduino code to make it in accordance to the C/C++ standard, or start all over again and create a new project in AS7.
Other ways :

  • Microsoft Visual Studio Community 2015 plus Visual Micro
  • Microsoft Visual Studio Community 2015 plus PlatformIO

Hackster.io

Hackster.io

Setting up Visual Studio and Visual Micro for Coding the ...

by Kurt Roesener

https://www.hackster.io/SalvorinFex/setting-up-visual-studio-and-visual-micro-for-coding-the-6c3d17

...

Using the power of VS Community 2015 and the ability to program for Arduinos and other compatible boards.

...

July 15, 2016

...

That is a brief Tutorial on how to setup these tools for a coding experience that is lacking in the Arduino IDE.

...

via https://plus.google.com/+KurtRoesener/posts/56KAXpoyaN4

Visual Studio — PlatformIO 2.11.1 documentation

http://docs.platformio.org/en/latest/ide/visualstudio.html (search for Arduino)

If want to use mega328PB instead of mega328P then the toolchain will need to be updated to AVR GCC 4.9.2 :

https://community.platformio.org/t/support-for-atmega328pb/314

Follow the link in Ivan's post to the toolchain; a link there to a cool second party mega328PB board made in Germany :

http://static.watterott.com/logo.jpg

Watterott electronic

Wattuino Pro Mini PB 5V/16MHz (ATmega328PB)

http://www.watterott.com/en/Wattuino-pro-mini-PB-5V-16MHz

Edit : PlatformIO

 

"Dare to be naïve." - Buckminster Fuller

Last Edited: Tue. Jul 19, 2016 - 08:01 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

gchapman, thanks for response.

 

I investigate on the VS & PlatformIO solution.  Nice that it is open source and hence free !!

 

Paul

 

Edit :  I just ask myself if Visual Studio 2015 Community Edition has the same debug capabilities as Atmel Studio has...  Or can I combine Platform IO and AS 7.0 ??

"As simple as possible, but not simpler"

GUI Framework for Atmel Xplained Pro

Last Edited: Tue. Jul 19, 2016 - 01:16 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello. I checked for a solution for a long time. MY problem was that I wanted the use the programming in Atmel studio with some libraries from Arduino. I have a feather M0 and i wasn't able to create a setup to do this. If anyone knows I would be very glad. 

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

PaulVdBergh wrote:
I just ask myself if Visual Studio 2015 Community Edition has the same debug capabilities as Atmel Studio has...
No though there is a GDB extension for Visual Studio; not certain that's a fit for MCU as it appears that's for embedded Linux GDB server to a GDB client extension of Visual Studio.

Second party additions to Visual Studio are a much better fit for MCU; Atmel Studio being the obvious one though there are others.

That's cohesive for Microsoft due to Microsoft initiatives into Linux and embedded Linux.

PaulVdBergh wrote:
Or can I combine Platform IO and AS 7.0 ??
Yes because PlatformIO is a Python wrapper of the toolchain.

AVR PlatformIO contains AVaRICE as the GDB server; that would not work in Atmel Studio.


Visual C++ Team Blog

Announcing the VS GDB Debugger extension

November 18, 2015

by Marc Goodner - MSFT

https://blogs.msdn.microsoft.com/vcblog/2015/11/18/announcing-the-vs-gdb-debugger-extension/

VisualGDB

Version History

http://visualgdb.com/history/

...

17 Jul 2016

  v5.2 Preview 1
Added support for unit tests for Embedded, Linux and Android projects

http://partners.ubuntu.com/microsoft

"Dare to be naïve." - Buckminster Fuller

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

Update:

 

I changed arduino's compiler options (see this article), fixed all the errors and warnings shown in the arduino's output window, but to no avail, Atmel Studio refuses to convert the sketch into a AS solution...  sad

 

Anyone a suggestion ?

"As simple as possible, but not simpler"

GUI Framework for Atmel Xplained Pro

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

Do you still get the same error message as post #1?

 

Try converting a simple Blink sketch first, to verify the basic operation.

 

AFAIK the "conversion" doesn't change your source files, it just sets up the AS project to build the files. So you might be able to add files into the basic sketch after conversion.

Bob. Engineer and trainee Rocket Scientist.

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

Hi Bob,

 

1 - Yes

2 - I'll try that.

 

Thanks,

 

Paul

"As simple as possible, but not simpler"

GUI Framework for Atmel Xplained Pro

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

I upgraded to AS7.0.1006 this morning.
I can import Uno sketches from both v1.6.6 and v1.7.8 and build them.
I can even import Zero sketches now from v1.6.6. They don't build yet.
.
I will do some testing later this week.
.
David.

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

Hi David,

 

I'm using AS v7.0.1006 and Arduino 1.6.9.  (that's the version Arduino proposes to download on there site)

 

I try importing a MEGA2560 sketch (see OP for link).

 

thanks tor your testing smiley

 

Paul

"As simple as possible, but not simpler"

GUI Framework for Atmel Xplained Pro

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

Studio Arduino parser has issues to parse such constructors while importing Arduino sketches

 

comment the below lines in the sketch(.ino)

 

SoftwareSerial SoftSerial(TXvWiFi, RXvWiFi); // init Soft Serial

z21Class z21;

EthernetUDP Udp; 

IPAddress ip(192, 168, 0, 111);

EthernetServer server(80);

DCCPacketScheduler dcc;

 

Import the modified .ino file

 

After successfull import of the sketch file,uncomment the above lines in sketch.cpp

 

PFA modified sketch file for your reference.

 

Attachment(s): 

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

Hello Usha,

 

Nice done !!  Thanks for your reply, that did it.  You made my day,  and week,  and month !!!

 

Paul.

"As simple as possible, but not simpler"

GUI Framework for Atmel Xplained Pro