0

Metro M4 Express and Atmel Studio 7
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Metro M4 Express and Atmel Studio 7

by KB1HFT on Wed Mar 06, 2019 5:31 pm

I am impressed with the capabilities of the Metro M4 Express (MM4E), and would like to use it in several projects. Before I do that tho, I want to be able to debug my Arduino code, built in the Arduino IDE, on Atmel's Studio 7 (AS7). Unfortunately, AS7 does not have the MM4E predefined. So it looks like I'll have to configure a "custom" "user" board, unless someone knows of where I can find an AS7 definition of the MM4E.

I remember reading in some Adafruit document a statement that using AS7 was recommended for the MM4E . I also see that the board is targeted for use with Circuit Python, and there IS documentation: Debugging CircuitPython On SAMD w/ Atmel Studio 7 ( https://cdn-learn.adafruit.com/download ... 1551895726).

By following that document I was able to gain some insight into the complexities of this endevour. However, the document is somewhat out of date in its depiction of the steps needed in AS7, and I'm looking for directions on how to use AS7 with an imported _Arduino_ sketch.

Are there plans for a similar document that focuses on Arduino sketches instead of Circuit Python?

Are there any other online resources that I might mine to resolve this dilemma? -- All advice is appreciated! --
Thanks & 73!

KB1HFT
 
Posts: 18
Joined: Mon Jun 11, 2018 4:20 pm

Re: Metro M4 Express and Atmel Studio 7

by westfw on Thu Mar 07, 2019 3:51 am

Does AS7 require a board-level definition? I thought you could say "I have a SAMD51mumble" chip, and get pretty far with that...
westfw
 
Posts: 1521
Joined: Fri Apr 27, 2007 1:01 pm
Location: SF Bay area

Re: Metro M4 Express and Atmel Studio 7

by KB1HFT on Thu Mar 07, 2019 8:39 am

westfw: Thanks you.

I have not yet delved into the process of defining the Metro M4 Express' layout around the SAMD51J19A, and was hoping that someone had gone down that particular road before me and might share.

I'll dig deeper into creating an ASF Board project today.

Onward!

KB1HFT
 
Posts: 18
Joined: Mon Jun 11, 2018 4:20 pm

Re: Metro M4 Express and Atmel Studio 7

by KB1HFT on Thu Mar 07, 2019 9:28 am

westfw:
I don’t yet know enough about AS7’s requirements & capabilities.

I’m assuming, perhaps incorrectly, that to debug an Arduino sketch via AS7, AS7 must know about the target board’s cpu/board pin mapping and other hardware features of the board that the Arduino code is to manipulate. Therefor, it seems to me, a definition of the board is needed.

Please correct me if I have mis-assumed.

KB1HFT
 
Posts: 18
Joined: Mon Jun 11, 2018 4:20 pm

Re: Metro M4 Express and Atmel Studio 7

by westfw on Sat Mar 09, 2019 5:46 am

I'm not sure. Normally, to use AS7 for Arduino development, you'd probably first create the Arduino Sketch, and then uses AS7 to "create project from Arduino Sketch" but as you said, there doesn't seem to be AS "configuration" for the M4 boards (nor for SOME of the SAMD21 boards. I'm not sure why it needs that info (when it's essentially present in the arduino files), and I don't see where it's getting its info from :-( (You get the same error trying to import an ITSYBITSY M0 sketch.)

You COULD create a SAMD51 project "from scratch" (or maybe by starting with an M0 sketch) and manually adding the Metro M4-specific files. Sounds unpleasant, though.

On the third hand, it's not clear that importing SAMD21 sketches works, either. :-(
westfw
 
Posts: 1521
Joined: Fri Apr 27, 2007 1:01 pm
Location: SF Bay area

Re: Metro M4 Express and Atmel Studio 7

by Adafruit_UMjT7KxnxP8YN8 on Sat Mar 09, 2019 3:13 pm

I tried to import an Arduino sketch for the Adafruit Metro M4 and after resolving a number of other issues learned that the import of sketches for the SAMD51 processor is not supported. I was, however, able to use AS7 to debug Arduino sketches I'd already loaded onto the board using the Arduino IDE.

Perhaps a more fruitful line of inquiry would be how to manually convert an Arduino sketch for the Metro M4 to an AS7 application? I'd be happy to help as time permits.

Adafruit_UMjT7KxnxP8YN8
 
Posts: 43
Joined: Tue Jul 17, 2018 1:28 pm

Re: Metro M4 Express and Atmel Studio 7

by KB1HFT on Thu Mar 14, 2019 11:14 am

Adafruit_UMjT7KxnxP8YN8:

How did you go about debugging your Metro M4 Express sketch via AS7? I. e., what steps did you perform?

I _can_ program the board via Arduino IDE, but want to be able to debug. I presume that AS7 is an appropriate debugging tool, since it is suggested for debugging Python projects.

If not AS7, then what tool does Adafruit suggest for debugging IDE C++ sketches on the Metro M4 Express?

All suggestions welcome!

KB1HFT
 
Posts: 18
Joined: Mon Jun 11, 2018 4:20 pm

Re: Metro M4 Express and Atmel Studio 7

by Adafruit_UMjT7KxnxP8YN8 on Sun Mar 17, 2019 11:34 am

I loaded the program I built with the Arduino IDE, then opened AS7 and did the following:

1. File->Open->Open file for debugging.
2. Navigate to the .elf file generated by the Arduino IDE (usually /temp/arduino_xxxxxx)
3. Enter name and location for AS7 to create a project
4. Debug->Attach to target (I use this; you may want to do it differently). It will fail because you haven't configured your debugger yet.

At this point AS7 will prompt you to set up your debugger. You must select the target device (ATSAMD51J19A) then set up your debugger. AS7 displays a list of the debuggers it detects and you just click on one. A dialog will open to configure its clock rate, connection method, etc. I use the Segger J-Trace. The J-Link Edu works just fine too.

I configured the debugger NOT to erase any target memory (skip) since I'd already loaded my program. If you want to overwrite your boot loader and render your Metro M4 unusable with Arduino, you may want to choose a different option. You can configure AS7 to only load program memory, but you'll have to figure that out on your own if you want to try it.

Next I select Debug->Attach to target again and viola, I''m debugging.

Note that if you're doing this as a hobbyist rather than as a for-profit business, you can also use Segger Ozone, a very nice debugger that's much faster than AS7.

Adafruit_UMjT7KxnxP8YN8
 
Posts: 43
Joined: Tue Jul 17, 2018 1:28 pm

Re: Metro M4 Express and Atmel Studio 7

by rtnate on Wed Mar 27, 2019 5:04 pm

What I have done with the M0 and the Atmega328p is created a bare AS7 solution and then a static library project that I call like M0ArduinoCore. There I copy in all the source code from Arduino15/packages/adafruit/hardware/samd/[version]/ into it. Basically you need all the source from cores/arduino and from the variant/[board]. The trick was then to figure out definitions needed to compile correctly. It's annoying, but then I create a second executable "sketch" project with my setup() and loop() functions in the solution, configure all the definitions and include directories. I then clone from this bare solution every time I start a new project. Anyway, I just did this process with the M4 in anticipation of messing around with a Metro M4 as soon they come back in stock and I can get one. (Updated link) My solution is here https://github.com/rtnate/MetroM4-AS7-Default if anyone wants to mess with it, I haven't tested it with the board yet, but I did get it to compile.
Last edited by rtnate on Thu May 16, 2019 1:57 pm, edited 1 time in total.

rtnate
 
Posts: 5
Joined: Wed Mar 27, 2019 4:52 pm

Re: Metro M4 Express and Atmel Studio 7

by svdbor on Wed Apr 03, 2019 11:03 am

I have been using Visual Micro for about 1 year (an extention in AS7, search for Arduino in extensions and updates) to import Arduino sketches for the Metro M4 and a custom board with the ATSAME54N20A. For debugging I used the Segger SAM-ICE for a while, but I switched to the Atmel-ICE since it is a little bit more reliable.
It works great since it will recognize all the functions from individual libraries, so you can look up the implementation very easy. I just have issues with recognizing registers on the MCU, these are always red underlined, but they do compile (for example REG_WDT_CONFIG = WDT_CONFIG_PER_CYC64 will all be red).

svdbor
 
Posts: 11
Joined: Tue Oct 31, 2017 4:08 pm

Re: Metro M4 Express and Atmel Studio 7

by KB1HFT on Wed Apr 03, 2019 11:20 am

Tnx to all who have replied to my query. I will attempt several of your suggestions & report back. I have an Atmel ICE and a Segger j-link mini -edu.

KB1HFT
 
Posts: 18
Joined: Mon Jun 11, 2018 4:20 pm

Re: Metro M4 Express and Atmel Studio 7

by PhillyG27 on Thu May 16, 2019 10:36 am

I am trying to accomplish the same as the OP, I will be trying all of the great leads many of you have posted.
Has there been any developments since the last post?

PhillyG27
 
Posts: 2
Joined: Thu May 16, 2019 10:33 am

Re: Metro M4 Express and Atmel Studio 7

by rtnate on Thu May 16, 2019 1:55 pm

I finally got my M4 and got an AS7 project up and running that I know works.

You can clone my repoif you want to get running. It's a bare bones working sketch with blink. I believe there are two configurations. Bootloader links the project for use with the bootloader and Debug links without it.

Any questions or issues let me know.

rtnate
 
Posts: 5
Joined: Wed Mar 27, 2019 4:52 pm

Re: Metro M4 Express and Atmel Studio 7

by PhillyG27 on Mon May 20, 2019 6:11 pm

Th
rtnate wrote:I finally got my M4 and got an AS7 project up and running that I know works.

You can clone my repoif you want to get running. It's a bare bones working sketch with blink. I believe there are two configurations. Bootloader links the project for use with the bootloader and Debug links without it.

Any questions or issues let me know.


I got the blink example running off of your repo, however, I am a bit concerned on how I would go about adding libraries.

I also wanted to know if you are flashing w/o a bootloader. My end goal is to fully develop the code here in AS7 and implement it on the M4. Then hand off the code and M4 to be used with solely the Arduino IDE to do simple changes.

PhillyG27
 
Posts: 2
Joined: Thu May 16, 2019 10:33 am

Re: Metro M4 Express and Atmel Studio 7

by rtnate on Wed May 22, 2019 1:00 pm

I add libraries manually. I create a folder in my project called libs or ArduinoLibs or something and copy the .h and .cpp file from the library there. I then add ../ArduinoLibs to the include directory list in the project settings. For larger libraries I give them their own folder, and then just add that folder to the include directory list.

Edit: To answer your second question I have been using the Bootloader configuration with my Atmel ICE setup up only to erase the program area. Start debugging and break launches perfect and breaks at main(). Start without debugging (my normal programming command) likes to jump into the bootloader on reset so when it does I just hit the button.
Last edited by rtnate on Wed May 22, 2019 7:24 pm, edited 1 time in total.

rtnate
 
Posts: 5
Joined: Wed Mar 27, 2019 4:52 pm

Please be positive and constructive with your questions and comments.