Custom MetroM4 Samd51J18 crashes on Sketch upload

Please tell us which board you are using.
For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
sheldonctt
 
Posts: 7
Joined: Fri May 11, 2018 12:39 pm

Custom MetroM4 Samd51J18 crashes on Sketch upload

Post by sheldonctt »

I am making a new pcb based heavily on the MetroM4 design except I am using the SAMD51J18 instead of the SAMD51J19. The main differences between the two parts are the J19 has 512KB flash and 192KB RAM, and the J18 has 256KB flash and 128 KB RAM. I went into the Adafruit Core and modified the MetroM4 linker file (with bootloader) to reflect these values as well as modified the Atmel supplied CMSIS file for the J19 to match the J18. I recompiled the uf2 bootloader from https://github.com/adafruit/uf2-samdx1 with the same modifications as the adafruit core. I then flash the bootloader onto the board using a Jlink and Microchip studio. Everything appears to work correctly as I can type V# into a terminal program and get the version string. When I deploy a basic Blinky script that says Hello World repeatedly, the Com Port collapses and the program crashes.

Other Observations:
I am compiling the adafruit core for the M4 In CRYSTALESS Mode.
If I deploy the Blinky program without a bootloader installed (App goes in 0x000000 Flash), it works perfectly.
The Metro M4 dev board works perfectly with all of the mods above.

Has anyone experienced this or have insight into the issue?

User avatar
User_UMjT7KxnxP8YN8
 
Posts: 323
Joined: Tue Jul 17, 2018 1:28 pm

Re: Custom MetroM4 Samd51J18 crashes on Sketch upload

Post by User_UMjT7KxnxP8YN8 »

Sadly, I don't have an answer for you. But I wonder, given that your mods work on a Metro M4 but not your board, whether you may have a hardware rather than a software problem.

From a software perspective, I think I'd have copied the ATSAMD51J19 CMSIS files, created a new ATSAMD51J18 variant and added it to boards.txt rather than changing ATSAMD51J19. If you missed anything in your changes, it's more likely to be identified when you build application code, as well as the boot loader. Insert #ifdef ATSAMD51J18 blocks to support your new board. If I recall correctly, the loader starts up in crystal-less mode but switches to crystal mode before starting the application. If your board doesn't have an external crystal you'll want to make sure that doesn't happen.

It's not clear to me what you mean by "the Com Port collapses". More details about what you're seeing and posting your modified files may help others provide useful feedback. Having fiddled with some of this stuff myself, there's lots to get right in order for it to work properly.

Good luck with your project!

User avatar
sheldonctt
 
Posts: 7
Joined: Fri May 11, 2018 12:39 pm

Re: Custom MetroM4 Samd51J18 crashes on Sketch upload

Post by sheldonctt »

Thanks for the reply.

From a software perspective, I think I'd have copied the ATSAMD51J19 CMSIS files, created a new ATSAMD51J18 variant and added it to boards.txt rather than changing ATSAMD51J19. If you missed anything in your changes, it's more likely to be identified when you build application code, as well as the boot loader. Insert #ifdef ATSAMD51J18 blocks to support your new board. If I recall correctly, the loader starts up in crystal-less mode but switches to crystal mode before starting the application. If your board doesn't have an external crystal you'll want to make sure that doesn't happen.
I'm going to look into this and will get back to you.

It's not clear to me what you mean by "the Com Port collapses".
When I flash the bootloader onto the board a COM port enumerates. I can open a terminal and send the bootloader commands and get responses (V# requests the board version). When I load an application on the board using the Arduino IDE, the COM port immediately closes and I can no longer access the board. I also can no longer get access to the bootloader using the reset button.
More details about what you're seeing and posting your modified files may help others provide useful feedback.
I will try to aggregate my changes in a concise way then post them. More coming soon!.

User avatar
User_UMjT7KxnxP8YN8
 
Posts: 323
Joined: Tue Jul 17, 2018 1:28 pm

Re: Custom MetroM4 Samd51J18 crashes on Sketch upload

Post by User_UMjT7KxnxP8YN8 »

I looked at the SAMD51 startup code this morning (startup.c) and realized that you misspelled "CRYSTALLESS" in your post, leading me to wonder if you may have done the same in your modified loader. It wouldn't cause a compiler error if you did, but would prevent the right code from compiling.

User avatar
sheldonctt
 
Posts: 7
Joined: Fri May 11, 2018 12:39 pm

Re: Custom MetroM4 Samd51J18 crashes on Sketch upload

Post by sheldonctt »

Sorry, I have it set correctly in my program.

I don't think the problem is related to the crystal because I have two Metro-M4's. One I have removed the crystal entirely, and the other hasn't been altered. Both Metros are functioning correctly when I flash the bootloader and application that works without a crystal and board settings configured for the SAMD51J18A (This makes sense because the SAMD51J18A is a subset of the SAMD51J19A with respect to FLASH/RAM). When I load the same app on my custom PCB (Via the Arduino IDE), I am no longer able to communicate with the board as I mentioned in a previous post.

I did a memory dump of the Metros and my custom PCB and they have the exact program.

I'm still working on a list of changes I have made to the Adafruit/SAMD folder.

User avatar
User_UMjT7KxnxP8YN8
 
Posts: 323
Joined: Tue Jul 17, 2018 1:28 pm

Re: Custom MetroM4 Samd51J18 crashes on Sketch upload

Post by User_UMjT7KxnxP8YN8 »

I'm a big fan of the "CodeCompare" software. The licensed version compares directories, which makes the type of thing you're doing go much faster.

User avatar
sheldonctt
 
Posts: 7
Joined: Fri May 11, 2018 12:39 pm

Re: Custom MetroM4 Samd51J18 crashes on Sketch upload

Post by sheldonctt »

Sorry for the radio silence.

I ultimately started over by making a new board file within the Adafruit Samd package that was based on the metro_m4, but I changed the board to samd51j18A and to run without a crystal (within the boards.txt). When I made these changes there were a million errors thrown by the compiler that I ultimately attributed to missing defines for the SAMD51J18A within a few files in "Arduino15\packages\adafruit\tools\CMSIS-Atmel\1.2.2\CMSIS\Device\ATMEL". I'm not sure if these were manually removed, or 1.2.2 of CMSIS-Atmel didn't fully support the chip. Regardless, after fixing several of the headers I was able to make the program compile.

Sadly, I am still running into my original problem, where I attempt to load a sketch using Arduino and the program becomes unresponsive and the COM port becomes no longer available.

It seems like there is some problem in the handoff between the bootloader and the app, but I can't seem to figure out what it is. I have attached all of my custom files below.
Attachments
samd51j18a_files.zip
(12.1 KiB) Downloaded 12 times

User avatar
User_UMjT7KxnxP8YN8
 
Posts: 323
Joined: Tue Jul 17, 2018 1:28 pm

Re: Custom MetroM4 Samd51J18 crashes on Sketch upload

Post by User_UMjT7KxnxP8YN8 »

Does your new build still work on both Metro M4s?

User avatar
sheldonctt
 
Posts: 7
Joined: Fri May 11, 2018 12:39 pm

Re: Custom MetroM4 Samd51J18 crashes on Sketch upload

Post by sheldonctt »

Yes, the new board works with both Metro M4's (One without a crystal).

User avatar
User_UMjT7KxnxP8YN8
 
Posts: 323
Joined: Tue Jul 17, 2018 1:28 pm

Re: Custom MetroM4 Samd51J18 crashes on Sketch upload

Post by User_UMjT7KxnxP8YN8 »

Could your problem be in the hardware rather than software?

User avatar
sheldonctt
 
Posts: 7
Joined: Fri May 11, 2018 12:39 pm

Re: Custom MetroM4 Samd51J18 crashes on Sketch upload

Post by sheldonctt »

It's possible, but when I export the sketch:

Arduino -> Sketch -> Export compiled binary

then upload it using microchip studio at address 0, the program runs as expected (without the bootloader).

User avatar
User_UMjT7KxnxP8YN8
 
Posts: 323
Joined: Tue Jul 17, 2018 1:28 pm

Re: Custom MetroM4 Samd51J18 crashes on Sketch upload

Post by User_UMjT7KxnxP8YN8 »

When you build to run with bootloader, you're using Arduino IDE?

User avatar
sheldonctt
 
Posts: 7
Joined: Fri May 11, 2018 12:39 pm

Re: Custom MetroM4 Samd51J18 crashes on Sketch upload

Post by sheldonctt »

I use the Arduino IDE to compile the program. I upload the program also with the Arduino IDE, however I have also tried exporting the binary and doing the physical loading with a JTAG device at address 0x4000. Neither route produces a good result.

User avatar
User_UMjT7KxnxP8YN8
 
Posts: 323
Joined: Tue Jul 17, 2018 1:28 pm

Re: Custom MetroM4 Samd51J18 crashes on Sketch upload

Post by User_UMjT7KxnxP8YN8 »

Tried stepping through the bootloader on your custom board with a debugger to see where it goes south?

User avatar
westfw
 
Posts: 2010
Joined: Fri Apr 27, 2007 1:01 pm

Re: Custom MetroM4 Samd51J18 crashes on Sketch upload

Post by westfw »

modified the Atmel supplied CMSIS file for the J19 to match the J18
That seems like a bad idea, and ought not be necessary.
Find someplace to download the proper j18 CMSIS file (probably in the form of a “pack”)

Locked
Please be positive and constructive with your questions and comments.

Return to “Metro, Metro Express, and Grand Central Boards”