Visual Studio Ide for Arduino
https://www.visualmicro.com/forums/YaBB.pl
Visual Micro >> Atmel Studio 7.0 >> Debugging using simulator or atmel-ice (attiny84a)
https://www.visualmicro.com/forums/YaBB.pl?num=1515952156

Message started by 0xCDCDCDCD on Jan 14th, 2018 at 5:49pm

Title: Debugging using simulator or atmel-ice (attiny84a)
Post by 0xCDCDCDCD on Jan 14th, 2018 at 5:49pm
Hi,

I'm kinda new to the embeded world and I tried to keep the arduino platform around to be able to use all those ready to go libraries.

I did build an arduino sketch from the Arduino IDE using a board for a attiny84a (without the bootloader) - without any serial port nor available pins.

So I found the AtmelStudio which should (Q1: i guess? or VisualStudio should be a better idea?) be a good IDE, allowing me to use the atmel-ice I got or just use the simulator, great ! My projects are still simples enough to be able to use the simulator right now, but with external input I guess it is going to be better soon to stick to the atmel-ice; Q2: right?)

After a couple of read I have to disable your debugger (by using the "AtmelStudio Debugger") because I have no serial port and would get an compilation error otherwise.

I know to be able to use the simulator I have to configure it in the AtmelStudio... but for whatever reason your plugin seem to force the targeted IC to ATSAM3X8E.

Issues
1) I can't set the target IC because it isn't supported (wtf!?)
2) Cause some "Object reference not set to an instance of an object" when trying to set the target debugger (I guess I have to set the IC first because sometime I am able to set the target IC and then I can select the debugger, unfortunatly it set back pretty fast to the wrong IC)

So plan B, I found that I could "Open Object file for debugging", so I opened a 2nd instance of AtmelStudio with this option. Ok now I can start debugging

Q3: Is it even possible to debug from within my main AtmelStudio instance - the one from where I compile the code in the first place?

Surprise, almost all my variables are "Unknown identifier"... I know this issue is because of the optimization flags.
So I tried -Og (and -O0). I saw the binary size get larger which is a good thing, now let's back to debugging.

Ok AtmelStudio detected a change in the binary, let reload it and start debugging again, uh still getting the "Unknown identifier".

Q4: Then how to debug variables easily? I'm a C# (and previously a C programmer), so i'm used to use debugger. I don't want to get back to the old age of sending (printing) manually all my data. It it still how embeded developper do?
I read a little about the dbg from VisualMicro which seem to do so (but at least it does it for me), but what other option do I have? (Q5: Using the VisualMicro dbg will work with the simulator?)

Thank and I hope it will not get in the internet void !

Title: Re: Debugging using simulator or atmel-ice (attiny84a)
Post by Visual Micro on Jan 28th, 2018 at 5:11am
Sorry I missed this thread before.

There are a few different settings depending on what you want to do.

There is also a bug in the current atmel version of visual micro that fails to perform an arduino upload if you have never had a com port available during operation of visual micro.

There are some points in red on the visual micro atmel studio page which are worth reading.

http://www.visualmicro.com/page/Arduino-for-Atmel-Studio-7.aspx

Tips

1) atmel 8bit or 32bit project type.

The first thing to note if you want to use atmel studio debug is that atmel studio has two project types 8bit and 32bit. When visual micro creates a project it uses the currently selected board to determine a type. If you have an 8 bit board and a 32 bit porject atmel will not show the correct programming devices or sim options.

Visual Micro doesn't really care about the atmel studio .cppproj other than it contains links to the source code. The proj file can be deleted and recreated if the wrong type exists with your source code. IT's also possible to drop and empty atmel .cppproj of the correct type into an arduino folder. Ensure the name matches the folder name and an .ino name then open and include the .ino/cpp sources. Visual Micro will then see it as an arduino project.

2)

If you enable "vMicro>Debugger>Atmel Studio Debugging", as per the docs, Visual Micro will pass debug requests to Atmel Studio. Atmel Studio will not find the debug symbols or be happy if you are using .ino files. You will read that you can create a project_name.cpp which includes the arduino.h and all your .ino code. In this case the project_name.ino must exist but can be empty because the compiler will ignore it. Using a .cpp file instead of .ino will cause atmel debug to work correctly.




Title: Re: Debugging using simulator or atmel-ice (attiny84a)
Post by 0xCDCDCDCD on Jan 28th, 2018 at 6:51pm
NOTE: If you could instead help me with the VS2017 issue instead of this it will be probably better. I had so much stability issue with AtmelStudio ...


Quote:
There are a few different settings depending on what you want to do.

[list bull-blackball]
  • Debug my code locally (no hardware at all involved, just the simulator)
  • Debug my code on the hardware (using the atmel-ice)


    In both case keep in mind I :
    [list bull-blackball]
  • Not using an arduino developpment board (I mean, not the standard arduino development board you buy but instead my final board - basicaly a attiny84 (without a bootloader, that need to be program from ISP) + their others hardware)
  • Except if i'm wrong I should be able to debug my code (with a real debugger (not with yours) instead of the old print way) without needing serials pins


    Quote:
    There is also a bug in the current atmel version of visual micro that fails to perform an arduino upload if you have never had a com port available during operation of visual micro.

    Read again, I had a compilation issue NOT an upload issue. The compilation is related to your own debugger using a serial port which I don't have ! (If you read again this post and the previous I asked to use the simulator and the atmel-ice as the debugging method, except if i'm really wrong/miss something). atmel-ice and the simulator should be better for debugging no?


    Quote:
    http://www.visualmicro.com/page/Arduino-for-Atmel-Studio-7.aspx

    I already read it.
    It still doesn't talk about
    [list bull-blackball]
  • Why setting optimization level to -Og/-O0 doesn't seem to work (well i'm not able to watch variable), you only talk about the "Use the Solution configuration" (aka Debug/Release) which may work if I used your debugging solution - not the atmel-ice or simulator.
    I know you aren't using the AtmelStudio projects settings so I tried to add the flag from your project settings


    Quote:
    1) [...]


    Quote:
    When visual micro creates a project it uses the currently selected board to determine a type.

    Don't think so, I set it as Attiny84a and it kept changing it to ATSAM3X8E.

    But, one thing I miss was I could set the programmer on "Atmel Studio Device Programming".

    Then I guess the AtmelStudio crappity smackup so bad when trying to debug because I didn't install this kind of IC. (I did try but it keep changing it for a different 32bits IC...)


    Quote:
    2) [...]

    I already read that as well, I already moved all code in the .cpp file. Deleting the .ino will generate compilation error.

  • Title: Re: Debugging using simulator or atmel-ice (attiny84a)
    Post by 0xCDCDCDCD on Jan 28th, 2018 at 7:06pm
    For whatever reason the target IC issue changing for no reason seem to be solved.

    EDIT: I created an empty arduino project and I still have the issue, not 100% the same, the device and programmer toolbar seem to be stuck on ATmega2560 (I think it was the original IC when created the project) but the device in the project option is right (and I can change it if i need to)

    Things I may did that could explain this:
    [list bull-blackball]
  • Reinstalled the plugin (yet again) - an update was available this time (but from the release note it shouldn't apply to atmel studio)
  • Make sure the file listed in the regedit "HKEY_CURRENT_USER\Software\Visual Micro\Options\Debug General\MicroGdb Location" does exist (which it wasn't).
    So I download the plugin, opened it with 7zip,
    copied all non xml/json file into the "HKEY_CURRENT_USER\Software\Visual Micro\Options\Debug General\MicroGdb Location".
  • Created a new empty C++ project set as ATTiny84a. (This project isn't an arduino one at all) then created an VisualMicro Arduino project as ATTINY84a (in the past I did create the arduino project then the other project)


    Also it (Atmelstudio) found an elf file but doesn't want to load symbols - uh. Would have to look at this...
    EDIT: Ok the modules windows is useless, with an AtmelStudio executable it still display symbols couldn't be loaded but I can debug. Still have to figure out why the .cpp in the arduino project can't be debugged

  • Title: Re: Debugging using simulator or atmel-ice (attiny84a)
    Post by Visual Micro on Jan 28th, 2018 at 11:26pm
    Hi,

    Thanks for all the great info. I think I have answers to all the questions along with links to new visual micro release at the end of this message ...

    1)

    VS is nicer in many respects but the GDB and sim are not available for avr boards so easily. So atmel wins for you with your requirements and VS will be a time waster for you.

    2)

    Atmel studio has two different .vcproj project file types. One for 8bit and one for 32bit.

    If you have a 32bit project and attempt to use an 8bit arduino board visual micro sets the atmel project device>mcu to a SAM board.

    If you have an 8bit project and attempt to set a not avr mcu visual micro sets the atmel project device>mcu to mega2560.

    Those defaults are because atmel will crash if we set an invalid mcu for the type of project we have. (It's easier in visual studio because it just has one c++ project type however VS does not know about the hardware so it's a trade off)

    3)

    When you use Visual Micro menu items such as "File>New>Arduino Project" and "File>Open>Arduino Project" Visual Micro inspects the currently selected arduino board and creates either an 8bit project (.cppproj) or a 32 bit project (.cccproj).

    Visual Micro assumes 32bit for any mcu type it does not know and did not until today's release properly cater for Attiny. Therefore you ended up with a 32 bit project and keep seeing the SAM device selected in the atmel project properties.

    This is where most of the confusion has come from for you. Sorry about that.

    4)

    Creating an 8bit project can be done in many ways. The .ccpproj file name simply has to match the folder and a .ino file name for visual micro to be happy.

    However, with the new release of visual micro you can delete the project_name.cpproj then open atmel studio and click "file>open>arduino project" and open the project_name.ino. This will create an 8bit project and your sources should be auto automatically re-included in the new project.

    5)

    When you have a valid 8 bit project you are ready to configure upload/start to use the atmel project device...

    [list bull-blueball]
  • Set the "vMicro>Uploader>Programmer" to "Atmel Device Programming"
  • Check the "vMicro>Uploader>Use Programmer for Upload" menu


    When you attempt to "Debug>Start" (or upload) Atmel will be in control and might open the device programming dialog, click cancel if using the sim or use the device programming tools as documented for your board.

    That should be upload working okay.

    6)

    Now we want to switch from Visual Micro serial debug to Atmel hardware debug.

    [list bull-blueball]
  • Check the "vMicro>Debugger>Atmel Studio Debugging" menu item.
  • Add a source code file called "Project_Name".cpp to your project.
  • Move all the code from .ino source files into a "Project_Name".cpp (atmel debug does not like .ino files)
  • To the top of the project_name.cpp add an #include <arduino.h>
  • In the project_name.cpp, if you have any methods other than setup() and loop() then optionally add prototypes.


    note: The .ino file must remain, can be empty, is ignored by the compiler when you have a .cpp of the same name in the project folder.


    tip: If you add libaries to your .cpp project visual micro will add example #includes into the .ino file for reference only.

    The above steps will give you upload and debug but debug symbols might be missing.

    7)
    Visual Micro does copy the .elf to the location atmel is expecting but the atmel solution explorer isn't so good at showing it (refreshing)

    All we might need to do it set optimization to debug

    [list bull-blueball]
  • Click "vMicro>Project Properties" and add the -Og switch to general (current configuration)>extra flags

    8)

    The latest release has been posted to the atmel gallery for approval that can take a few days.

    You can download and install the same version using one of the following two links. There are two links because Microsoft screwed up the installer for the vs shell that atmel uses. So depending on which microsoft ide you installed last one of the installs should find atmel studio 7 and prompt you to install visual micro.

    Normally, installing from inside atmel studio "tools>extensions and updates" uses the older microsoft installer which is why the download has "InsideIDE" in the name.

    Older installer normally inside ide (VM ver 1801.28)

    Outide ide when VS has been installed after atmel studio (VM ver 1801.28)

    I have bo comment about that one!!

    Summary

    With the update and the above points I hope you find things a bit smoother.






  • Title: Re: Debugging using simulator or atmel-ice (attiny84a)
    Post by 0xCDCDCDCD on Jan 29th, 2018 at 12:19am
    Wow, I expected a shitty and short answer as usual, I won't be surprise you are the developper :p

    2) 3) That explain my issue, I think I played with the arduino zero (a 32bits IC) before creating the project and then switching it to my target board. Thanks !

    7) I already did that unfortunatly :( (ConfigurationAdditionalCompilerFlags="-Og" right?)
    I seem to be able to debug (well do a step by step, I'm still unable to watch variables) the arduino SDK but not my setup()/loop()
    I opened the .elf with a text editor and found the variable name I created in my loop(), so this is somehow a good news.
    At this point i'm kinda clueless because I'm used to just use an old debugging file (.pdb in c#)

    8) I used the markplace (from outside the IDE) to download your plugin because the Microchip update for the gallery doesn't work. It did detect the Atmel Studio v7 as it should.
    I just installed the new version from your link in hope to have less issue.

    For other points well thanks

    Title: Re: Debugging using simulator or atmel-ice (attiny84a)
    Post by Visual Micro on Jan 29th, 2018 at 12:45am
    Did you create the combined .cpp and did you use the "vMicro>Project Properties" menu item to view the project properties tool window and set the -Og switch into (current configuration)>extra flags.

    If you have followed those two steps and still have an issue then click build>clean then click build.

    However a screen shot of your project solution explorer with properties tool window alongside would confirm there is no confusion.

    edit: vmicro>compiler>verbose will show the build commands during build. The -Og will be there is it has been entered into the correct location. I tested the sim with an attiny85 board and setup/loop in the project_name.cpp were fine for me.

    feel free to email your project if in doubt to info[at]visualmicro.com

    Title: Re: Debugging using simulator or atmel-ice (attiny84a)
    Post by 0xCDCDCDCD on Jan 30th, 2018 at 1:55am
    Just to let you know I send you an email with a dummy project (the one i'm using to test the dbg)

    [list bull-blackball]
  • I was already using -Og in the "extra flags" options of the "Micro general (current configuration)" group.
  • I did MOVE all code from the ino to the cpp (an keep the ino file empty).
  • Did add the include to arduino
  • Tried to clean the project (+ delete my debug folder)
  • I did see the -Og flag in the verbose mode

  • Title: Re: Debugging using simulator or atmel-ice (attiny84a)
    Post by Visual Micro on Jan 30th, 2018 at 2:26pm
    I found that -O0 works but not -Og

    I also reviewed the gdb overview on visualmiro.com and instead of using project properties you can just add this to the top of your master .ino code. It's the same but easier to implement and see.

    One other thing is to "click tools>show hidden files" so the core and libs have source code shortcuts in your project. Click the menu again to remove the short cuts of delete them yourself they are correctly ignored by the compiler.

    [code]    #pragma GCC optimize ("O0")[/code]

    Title: Re: Debugging using simulator or atmel-ice (attiny84a)
    Post by 0xCDCDCDCD on Jan 30th, 2018 at 11:19pm
    Crap I guess I tested -O0 the wrong way (only in the atmelstudio projects settings maybe?).

    Anyway, yeah I can debug step-by-step in my code ! but still can see any variables in the debugger... (hu that doesn't sound good)

    Title: Re: Debugging using simulator or atmel-ice (attiny84a)
    Post by Visual Micro on Jan 30th, 2018 at 11:23pm
    I can see variables okay. Some will not be available because optimization will have discarded them but most should be available.

    Hovering over local and global variables should show the value, adding watch expressions should also show values.

    If your code uses an object you will be more likely to view it in the watch window.

    If confused then show screen shot of issue

    Thanks

    Title: Re: Debugging using simulator or atmel-ice (attiny84a)
    Post by 0xCDCDCDCD on Jan 30th, 2018 at 11:35pm
    Well like in the source file I sent you

    Quote:
         uint8_t testDbg = digitalRead(1) ^ 1;

         digitalWrite(1, testDbg);


    testDbg is never available nor the two parameters from the digitalWrite() method (digitalWrite() seem to only display bit, port and oldSREG, ± one variable)

    Basicly I have no idea (except when looking in the I/O windows) of the potential value read.

    EDIT: Just to make it clear, i know reading pin 1 is useless since it is an output. This code is just to test and make sure I have all flags set to really be able to debug

    Title: Re: Debugging using simulator or atmel-ice (attiny84a)
    Post by Visual Micro on Jan 31st, 2018 at 10:15pm
    I had the digispark 16.mmhz Attiny 85 installed so tested with that

    -Og in the extra flags
    Full rebuild so that the core get the -Og flag
    Also added -O0 to te top of the cpp (ino) code
    Sim shows data types correctly.

    However I had to step into the loop() from main so that the ide opened the temp copy of the .cpp file during debug.

    All var were showing okay, your testDbg could only be viewed once the execution reached digitalWrite()



    Title: Re: Debugging using simulator or atmel-ice (attiny84a)
    Post by 0xCDCDCDCD on Feb 1st, 2018 at 12:38am
    Hum wierd, the optimization flag (in the project properties) doesn't seem to do anything on my side (in regard with the variables being optimized).

    However the pragma seem fine.

    Well thanks a lot ! That fixed my issues.

    Visual Studio Ide for Arduino » Powered by YaBB 2.5.2!
    YaBB Forum Software © 2000-2019. All Rights Reserved.