Problems flashing bootloader to SAMD51 using Segger J-Link EDU and Microchip studio

Also posted on reddit and Microchip forum, but couldn’t really get anything there.

I have a custom board I designed using the SAMD51J20A (same pinout as the SparkFun SAMD51 thing plus).

I have been trying to upload the bootloader .bin file (that I got from the Sparkfun github page) but I keep having problems uploading it to the board. The J-Link EDU is able to read the device signature, change the fuses, read the flash, etc., but when I go to upload the binary it gets stuck at some point (gives the same error every time, but sometimes the address is different). Photos of the error attached below.

Things I have tried:

-SWD speed at 400kHz, 100kHz, 32kHz, other various

-NVM_BOOTPROT fuse at 0kB
-NVMCTRL_REGION_LOCKS at 0x00000000 and 0xFFFFFFFF

-using a .elf file instead of .bin

-programming address at 0x0000, 0x2000, and 0x4000

Here are the current fuse settings:

AC_BIAS0 = 0x01

ADC0_BIASCOMP = 0x07

ADC0_BIASREFBUF = 0x04

ADC0_BIASR2R = 0x07

ADC1_BIASCOMP = 0x07

ADC1_BIASREFBUF = 0x04

ADC1_BIASR2R = 0x07

USB_TRANSN = 0x09

USB_TRANSP = 0x19

USB_TRIM = 0x06

ROOM_TEMP_VAL_INT = 0x1E

ROOM_TEMP_VAL_DEC = 0x00

HOT_TEMP_VAL_INT = 0x68

HOT_TEMP_VAL_DEC = 0x09

ROOM_INT1V_VAL = 0x00

HOT_INT1V_VAL = 0x00

ROOM_ADC_VAL_PTAT = 0xACF

HOT_ADC_VAL_PTAT = 0xD4F

ROOM_ADC_VAL_CTAT = 0xB62

HOT_ADC_VAL_CTAT = 0x952

BOD33_DIS =

BOD33USERLEVEL = 0x00

BOD33_ACTION = NONE

BOD33_HYST = 0x00

NVMCTRL_BOOTPROT = 0

NVMCTRL_SEESBLK = 0x06

NVMCTRL_SEEPSZ = 0x00

RAMECC_ECCDIS =

WDT_ENABLE =

WDT_ALWAYSON =

WDT_PER = CYC16384

WDT_WINDOW = CYC16384

WDT_EWOFFSET = CYC16384

WDT_WEN =

NVMCTRL_REGION_LOCKS = 0xFFFFFFFF

SW0_WORD_0 = 0x1E7079D (valid)

SW0_WORD_1 = 0x1B29 (valid)

TEMP_LOG_WORD_0 = 0x96801E (valid)

TEMP_LOG_WORD_1 = 0xD4FACF00 (valid)

TEMP_LOG_WORD_2 = 0xFF952B62 (valid)

USER_WORD_0 = 0xFF9A8000 (valid)

USER_WORD_1 = 0xAEECFF86 (valid)

USER_WORD_2 = 0xFFFFFFFF (valid)

Bootloaders I have tried uploading

Photos:

Gets to somewhere on the Program and verify bar and stops, then this error appears:

Also, does anyone have the uncompiled bootloader file? I might try to compile it myself because at this point I have tried just about everything I can think of.

Hi @BarrettT123 ,

I’d suggest double-checking the NVMCTRL_BOOTPROT value… On the SAMD21G18A, you need to set it to 0x07 to allow programming. 0 sounds wrong to me.

I hope this helps,
Paul

“Bits 11:8 – BOOTPROT[3:0] Boot Loader Protection Size This bitfield is loaded from the NVM User page during the device startup (See the Memories chapter). Defines the size of the BOOTPROT region which is protected against write or erase or Chip-Erase operations. This size is given by the following formula (15-BOOTPROT)*8KB.”

So, if I’m reading this right, 0 maximises the size of the write- and erase-protected region?

I suggest setting it to 15, then erase, then write, then set it back to 0.

Best,
Paul