0

Metro M4 Grand Central board
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Metro M4 Grand Central board

by akki0075 on Tue Sep 29, 2020 7:25 pm

Hi,

I am Akshay and I've got feather M4 grand central board plus J-link SEGGER debugger. I want to debug the program using J-link debugger on this board using Arduino IDE platform. I cannot find much resources which can help me out. Can someone help me here whosoever has experience with it. That would be very much appreciated.

Thanks,
Akshay

akki0075
 
Posts: 49
Joined: Fri Jan 17, 2020 6:51 pm

Re: Metro M4 Grand Central board

by westfw on Tue Sep 29, 2020 10:34 pm

I'll assume that "feather" is a typo, and you actually have a Grand Central M4, which has a 10pin SWD connector on it?

What debugger (software) do you want to use? Many different debuggers support the J-link.
The (normal) Arduino IDE does NOT support any hardware debugging probes :-(

westfw
 
Posts: 1781
Joined: Fri Apr 27, 2007 1:01 pm
Location: SF Bay area

Re: Metro M4 Grand Central board

by akki0075 on Tue Sep 29, 2020 11:10 pm

Earlier we have been flashing the Embedded-C firmware to the feathers/board using USB on Arduino IDE. But now we want to shift to debugging using J-link SEGGER. Since Arduino IDE doesn't support J-link debugging, then which IDE/software I should switch to, for flashing the Embedded C firmware onto any board?

-Thanks,
Akshay

akki0075
 
Posts: 49
Joined: Fri Jan 17, 2020 6:51 pm

Re: Metro M4 Grand Central board

by RCohenQubiq on Wed Sep 30, 2020 2:14 pm

Hello,

I would like to recommend PlatformIO, because I find that it has very good integration. However I cannot recommend it at this time for the Grand Central M4, due to the problems I've been having.

See this thread:

viewtopic.php?f=63&t=167384

Another user in the thread above recommends "Segger Ozone". You might also try "Atmel Studio 7".

Good luck and let us know if you find a solution that works for you.

RCohenQubiq
 
Posts: 12
Joined: Wed Jul 15, 2020 1:38 pm

Re: Metro M4 Grand Central board

by akki0075 on Wed Sep 30, 2020 9:49 pm

Hi,

I read your thread. So did you finally get success in flashing the "Blink" firmware using J-link to the board?

I have been trying to test the same common example using Atmel Studio 7 onto the same board through J-link, but I'm having issue with Flash verification.

I have contacted Microchip support for the help since they own the MCU being used on the board as well as the Atmel Studio 7. Fingers crossed.

-Akshay

akki0075
 
Posts: 49
Joined: Fri Jan 17, 2020 6:51 pm

Re: Metro M4 Grand Central board

by RCohenQubiq on Wed Sep 30, 2020 10:37 pm

Hello Akshay,

I am running VSCode with the PlatformIO extension under Linux. The PlatformIO software uses the standard Segger libraries and programs to communicate with the J-Link Edu.

I have had good success with downloading my executable code to the GCM4, through the J-Link, from within PlatformIO. I can even set breakpoints and run to them. However, in order to get the Blink code running correctly (with the correct timing for the blinks), I have to disconnect the J-Link from the computer and restart the GCM4 in "standalone" mode.

I have a thread open on the PlatformIO community forums as well.

Take care.

RCohenQubiq
 
Posts: 12
Joined: Wed Jul 15, 2020 1:38 pm

Re: Metro M4 Grand Central board

by User_UMjT7KxnxP8YN8 on Thu Oct 01, 2020 9:54 am

You may find this to be helpful: viewtopic.php?f=63&t=140725&hilit=+ozone

User_UMjT7KxnxP8YN8
 
Posts: 235
Joined: Tue Jul 17, 2018 1:28 pm

Re: Metro M4 Grand Central board

by akki0075 on Mon Oct 05, 2020 2:04 pm

Hi,

I followed the steps you have given in your thread, but it gave me a Cortex-M hardfault exception. They have given the cause in some CPU registers. Actually what I did was I erased the bootloader for j-link programming/debugging( Microchip support guy told me to do that). Is that the reason why I am getting this error. Do we need the same bootloader back in the Metro M4 in order to program via J-link on Ozone platform? If Yes, I can put that again and re-try the steps.

Thanks,
Akshay

akki0075
 
Posts: 49
Joined: Fri Jan 17, 2020 6:51 pm

Re: Metro M4 Grand Central board

by User_UMjT7KxnxP8YN8 on Mon Oct 05, 2020 3:42 pm

The bootloader provides interrupt handler vectors and jumps to your application, so you do need it. Follow the instructions at https://learn.adafruit.com/how-to-program-samd-bootloaders/programming-the-bootloader-with-atmel-studio, EXCEPT that bootprot is disabled by setting boot loader size to 0 KB in drop-down instead of setting it to 0x0F as in instructions. I recommend resetting bootprot back to 16 KB after you program the boot loader.

Now you can program your application either using the Arduino IDE or by opening the .elf file with Ozone then clicking Debug->Start Debug Session->Download and Reset Program.

If you use the Arduino IDE, you connect Ozone to your Grand Central by clicking Debug->Start Debug Session->Attach to Running Program.

Incidentally, if you haven't already done so, in Ozone you'll need to enter Tools->J-Link Settings select your processor (ATSAMD51P20), Target Interface and Host Interface. I recommend saving a Project File that you can reload every time Ozone starts (by double-clicking 'Open Recent Project') rather than doing it manually every time.

User_UMjT7KxnxP8YN8
 
Posts: 235
Joined: Tue Jul 17, 2018 1:28 pm

Re: Metro M4 Grand Central board

by akki0075 on Mon Oct 05, 2020 4:25 pm

Yes before your response I did put the bootloader back into the board using Atmel Studio 7 and flashed the firmware by following your steps using Ozone, then I can see the output of blinking a LED. I have also re-checked the output by making changes to the firmware itself and change in the output is clearly seen. Thanks a ton for the help.

I just learnt how to program a firmware using J-link.

The quick questions though!!

We are going to get our own custom PCB having ATSAMD51J19 MCU with a JTAG connector on the board. So we are planning to flash the firmware using the same technique via J-link programming/debugging. My question to you is that if the MCU comes w/o the bootloader, in that case, shall I put the Feather M4 express (having the same MCU though) bootloader into that blank MCU using Atmel Studio 7 and then flash the firmware using Ozone (via J-link)?? (OR) Is there anyway to flash the firmware w/o having the bootloader via J-link programming?

If my questions are not clear, please let me know.

Thanks,
Akshay

akki0075
 
Posts: 49
Joined: Fri Jan 17, 2020 6:51 pm

Re: Metro M4 Grand Central board

by User_UMjT7KxnxP8YN8 on Tue Oct 06, 2020 9:39 am

Glad to hear that worked for you!

Regarding your custom board, you can do exactly what you just did, or you can use Segger J-Flash to install the boot loader, but I haven't done so myself. As I recall, doing this requires you to configure J-Flash to set up the system clock in a manner similar to what is done in the boot loader and program the fuses appropriately. If you're planning to produce thousands of these boards you may want to consider buying the MCUs with the boot loader pre-programmed by Microchip.

There's no reason you must have a boot loader, but it's awfully handy if you want to upgrade your application firmware. If you don't want a boot loader, just put the interrupt vectors and handler(s) and startup code right in your application. You can find the source code for the Adafruit boot loader at https://github.com/adafruit/uf2-samdx1/releases/tag/v3.10.0 (scroll all the way to the bottom for the source).

I recommend using the Watchdog Timer to keep your application from hanging. You can use my code if you like, at https://github.com/SapientHetero/Watchdog-Timer-for-ATSAMD51J19A.

User_UMjT7KxnxP8YN8
 
Posts: 235
Joined: Tue Jul 17, 2018 1:28 pm

Re: Metro M4 Grand Central board

by akki0075 on Tue Oct 06, 2020 12:51 pm

Thanks a lot for the links.

I understand your point. But I tried erasing the bootloader and then flashing the classic example Blink.hex file on Atmel Studio 7. Both were a success but I didn't get the output of blinking of a LED (as I got it with having the bootloader on Ozone). I do not what went wrong in the process.

I looked into the source code.zip at https://github.com/adafruit/uf2-samdx1/ ... ag/v3.10.0. But I am confused here. If I want to flash the firmware w/o having the bootloader, how will these files in a .zip folder help me here? Secondly, how am I going to include these files in order to test the .ino firmware? Can you please give me a little detailed info. on that?

My first step is to flash the firmware w/ bootloader via j-link programming/debugging, which is cleared. Now the second step is to do the same w/o bootloader. Also, We are going to have 100s of custom boards soon.

Thanks,
Akshay

akki0075
 
Posts: 49
Joined: Fri Jan 17, 2020 6:51 pm

Re: Metro M4 Grand Central board

by User_UMjT7KxnxP8YN8 on Tue Oct 06, 2020 7:38 pm

Did you flash your app to 0x4000 with AS7? If you overwrite the bootloader (at 0x0000) your app isn't going to work right unless it provides interrupt vectors and goes through the MCU startup sequence. Look at startup_samd51.c in the bootloader source for guidance.

User_UMjT7KxnxP8YN8
 
Posts: 235
Joined: Tue Jul 17, 2018 1:28 pm

Re: Metro M4 Grand Central board

by akki0075 on Tue Oct 06, 2020 7:46 pm

I did erase the bootloader by USER_WORD_0.NVMCTRL_BOOTPROT to 0 kbytes. Then I tried to flash both the application's hex files generated by Arduino IDE as well as AS7. Ofcourse, one at a time. But didn't work out. Where do you want me to set 0x4000 in AS7?

I have uploaded an image of fuses. Can you tell 0x4000 will go to which fuse name?

Thanks,
Akshay
Attachments
fuses.PNG
fuses.PNG (56.18 KiB) Viewed 136 times

akki0075
 
Posts: 49
Joined: Fri Jan 17, 2020 6:51 pm

Re: Metro M4 Grand Central board

by User_UMjT7KxnxP8YN8 on Wed Oct 07, 2020 12:52 am

Let me clarify my previous response, which I think may have been misleading. You have two options:

1. Flash the bootloader, then protect the first 16K, then upload your application to 0x4000, or

2. Include the interrupt vectors and startup code in your application and build it to start at 0x00000000 and program that at 0x00000000 instead of the bootloader.

It would be very useful for you to reflash the boot loader, build your application with the Arduino IDE or whatever you're using to develop your app, upload it with the bootloader still in place, then use the debugger to reset and halt the processor. Then step through the code to see what happens. You can build the bootloader then point your debugger at its .elf file so you don't have to step through assembly code.

Your application will need to do the same things you see, including setting up the system clock, initializing global variables, zeroing memory as needed, setting the stack pointer, setting the start of the heap, etc. Without that startup code your application isn't going to work properly.

Hope that helps.

If you don't mind my asking, why do you want to eliminate the bootloader? The Grand Central's processor has a whopping 1MB of program memory, and there are lots of advantages to allocating 16K of it a bootloader.

User_UMjT7KxnxP8YN8
 
Posts: 235
Joined: Tue Jul 17, 2018 1:28 pm

Please be positive and constructive with your questions and comments.