Hi rondrop,
The issue could be that the bootloader is configured for SAMD51J19A/SAMD51G19A with 512kB flash and 192kB RAM, while the SAMD51G18A uses 256kB flash and 128kB flash.
The following example are the changes I needed to make for my custom SAMD51J20A board with 1MB flash and 256kB RAM.
To account for this it's necessary to firstly change the location of the double tap (reset) address, that's stored in the the last RAM location. This is in the bootloader definition file (board_definitions_metro_m4.h) in the "bootloader" directory, you'll need to recompile the bootloader:
#define BOOT_DOUBLE_TAP_ADDRESS (0x2003FFFCul)
The address is 4 bytes back from the last location in RAM.
This file also contains the definitions for the bootloader's LEDs and serial port pins.
Secondly, you'll also need to change the flash and RAM memory configuration in the flash with and without bootloader linker scripts, (flash_with_bootloader.ld and flash_without_bootloader.ld files) in the "variant" directory:
MEMORY
{
FLASH (rx) : ORIGIN = 0x00000000+0x4000, LENGTH = 0x00100000-0x4000 /* First 16KB used by bootloader */
RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00040000
}
MEMORY
{
FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 0x00100000
RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00040000
}
Thirdly the memory configuration should also be specified in the "boards.txt" file:
adafruit_metro_m4.upload.maximum_size=1048576
... the "boards.txt" file should also specify the microcontroller itself:
adafruit_metro_m4.build.extra_flags=-D__SAMD51J20A__ -D__SAMD51__ {build.usb_flags} -D__FPU_PRESENT -DARM_MATH_CM4 -mfloat-abi=hard -mfpu=fpv4-sp-d16
The bootloader starting up, but the sketch stalling can also occur if there's a problem with the board's external 32.768kHz crystal. The bootloader runs crystalless so is unaffected and runs as normal, but stalls when switching over to the external oscillator.