How to upload arduino bootloader to a custom samd21 usig Jlink mini

I realised port0 pin 0 is a pin that im using and i do not have an unused pin (i used all the pins) so commenting out is my only option

on my board PA11 and PA10 are being routed somewhere else, only PA24 and PA25 are routed to the USB header?

Are the those line of code for if you are not going to use the native one? so if i am going to go only native usb should i comment that out?

Im sorry for the stupid question, but how do i build this thing so that the .bin file will be updated?

From the Atmel Studio 7 menu, select: Build->Build Solution or press F7.

This will build the binary file called: samd21_sam_ba.bin, located in the same directory as the other bootloader solution/project files.

I finally tracked down the source of the flag to turn off the UART option. Open the project's Makefile and in the "Compiler Options" section, change the following line from:

SAM_BA_INTERFACES?=SAM_BA_BOTH_INTERFACES

to:

SAM_BA_INTERFACES?=SAM_BA_USBCDC_ONLY

This will exclude the code to generate the UART bootload option. It's probably OK just to leave the UART defines as they are.

I have finished modifying the makefile. upon building it though its looking for a "sam.h" file where do i get this? and i probably assume it also needs a sam.c file too

Are you getting errors in Atmel Studio when compiling?

On my machine I'm compiling the Arduino Zero bootloader on Atmel Studio 7 without any errors.

The Makefile looks for the "sam.h" file from the Arduino IDE's CMSIS (Common Microcontroller Software Interface Standard) files, located (on my PC) here:

C:\Users\Computer\AppData\Local\Arduino15\packages\arduino\tools\CMSIS-Atmel\1.2.0\CMSIS\Device\ATMEL

I presume that since you're already using that Arduino Zero bootloader that you have loaded the Arduino SAMD Boards suport package in the Arduino IDE. (Arduino IDE Menu: Tools->Boards->Boards Manager, in the Boards Manager search bar type "Arduino Zero", current version 1.8.11).

Yes i installed the samd boad support using the arduino IDE under board manager as you mentioned,

I have forgotten that i have made a copy and placed it somewhere else, so the includes in the make file does not match anymore

My sam.h is found in

C:\Users\mycomputer\Documents\ArduinoData\packages\arduino\tools\CMSIS-Atmel\1.2.0\CMSIS\Device\ATMEL

How would i change this line in the makefile to point into that folder?

INCLUDES=-I"$(MODULE_PATH)/tools/CMSIS/4.5.0/CMSIS/Include/" -I"$(MODULE_PATH)/tools/CMSIS-Atmel/1.2.0/CMSIS/Device/ATMEL/"

in the makefile also there is this complicated looking lines which I THINK is setting the base path

ifeq ($(OS),Windows_NT)
  # Are we using mingw/msys/msys2/cygwin?
  ifeq ($(TERM),xterm)
    T=$(shell cygpath -u $(LOCALAPPDATA))
    MODULE_PATH?=$(T)/Arduino15/packages/arduino
    RM=rm
    SEP=/
  else
    MODULE_PATH?=$(LOCALAPPDATA)/Arduino15/packages/arduino
    RM=rm
    SEP=\\
  endif
else
  UNAME_S := $(shell uname -s)

  ifeq ($(UNAME_S),Linux)
    MODULE_PATH?=$(HOME)/.arduino15/packages/arduino
    RM=rm
    SEP=/
  endif

  ifeq ($(UNAME_S),Darwin)
    MODULE_PATH?=$(HOME)/Library/Arduino15/packages/arduino/
    RM=rm
    SEP=/
  endif
endif

which one should i change? my base path is

C:\Users\mycomputer\Documents\ArduinoData\packages\arduino

The thing is, you shouldn't need to change anything to do with the paths in the Makefile. The Arduino bootloader solution for the Atmel Studio should just compile.

Might I ask what the compiler's error message is saying?

Here is what the full error is saying:

A bit of background, so i went and copy the zero folder inside the bootloader and pasted inside another folder that is in the desktop. The copied zero bootloader is the one that i modified. I think why it could not find the thing is because if you notice in my previous comment

the arduino files are in documents and not app data.

The original zero bootloader seems to compile fine. I will modify the original files i dont mind corrupting it as i can reinstall arduino again very easily and It would be rude for me to waste your time on a trivial thing.

So i went ahead and modified the original zero bootloader and now there is only 1 error remaining

the output error is

Compiling bootloader using
		BASE PATH = C:\Users\myComp\AppData\Local/Arduino15/packages/arduino
		GCC  PATH = C:\Users\myComp\AppData\Local/Arduino15/packages/arduino/tools/arm-none-eabi-gcc/7-2017q4/bin/arm-none-eabi-
		----------------------------------------------------------
		Compiling board_driver_i2c.c to build/board_driver_i2c.o
		"C:\Users\myComp\AppData\Local/Arduino15/packages/arduino/tools/arm-none-eabi-gcc/7-2017q4/bin/arm-none-eabi-gcc" -mthumb -mcpu=cortex-m0plus -Wall -c -std=gnu99 -ffunction-sections -fdata-sections -nostdlib -nostartfiles --param max-inline-insns-single=500 -g3 -O1 -DDEBUG=1 -D__SAMD21G18A__ -DBOARD_ID_arduino_zero -DSAM_BA_USBCDC_ONLY -I"C:\Users\myComp\AppData\Local/Arduino15/packages/arduino/tools/CMSIS/4.5.0/CMSIS/Include/" -I"C:\Users\myComp\AppData\Local/Arduino15/packages/arduino/tools/CMSIS-Atmel/1.2.0/CMSIS/Device/ATMEL/" board_driver_i2c.c -o build/board_driver_i2c.o
C:\Users\myComp\Documents\ArduinoData\packages\arduino\hardware\samd\1.8.11\bootloaders\zero\Makefile(139,1): error: recipe for target 'build/board_driver_i2c.o' failed
		make: Leaving directory 'C:/Users/myComp/Documents/ArduinoData/packages/arduino/hardware/samd/1.8.11/bootloaders/zero'
		process_begin: CreateProcess(NULL, C:\Users\myComp\AppData\Local/Arduino15/packages/arduino/tools/arm-none-eabi-gcc/7-2017q4/bin/arm-none-eabi-gcc -mthumb -mcpu=cortex-m0plus -Wall -c -std=gnu99 -ffunction-sections -fdata-sections -nostdlib -nostartfiles --param max-inline-insns-single=500 -g3 -O1 -DDEBUG=1 -D__SAMD21G18A__ -DBOARD_ID_arduino_zero -DSAM_BA_USBCDC_ONLY -IC:\Users\myComp\AppData\Local/Arduino15/packages/arduino/tools/CMSIS/4.5.0/CMSIS/Include/ -IC:\Users\myComp\AppData\Local/Arduino15/packages/arduino/tools/CMSIS-Atmel/1.2.0/CMSIS/Device/ATMEL/ board_driver_i2c.c -o build/board_driver_i2c.o, ...) failed.
		make (e=2): The system cannot find the file specified.
		make: *** [build/board_driver_i2c.o] Error 2
	Done executing task "RunCompilerTask" -- FAILED.
Done building target "CoreBuild" in project "samd21_sam_ba.cproj" -- FAILED.
Done building project "samd21_sam_ba.cproj" -- FAILED.

Build FAILED.
========== Build: 0 succeeded or up-to-date, 1 failed, 0 skipped ==========

If its a tricky problem can we make it to just ignore i2c for now?

@MartinL I have had the arduino IDE uninstalled and even made sure to delete all files it left, and have the IDE reinstall all files including the samd21 board under board manager. and still getting this error

@John41234 Did you by any chance download your Arduino IDE as Windows App (from the Microsoft App Store)?

I just saw this: https://support.arduino.cc/hc/en-us/articles/360018448279-Where-can-I-find-the-Arduino15-folder-.

Yes, i got mine from the microsoft store.

I just noticed the paths on errors are for the non microsoft store arduino. Alright then ill uninstall it again and use the from the website.

I suggest unintalling the Arduino IDE oncemore then reintalling it again (version 1.8.16) using this option:

Arduino IDE Download

Finally the build was successfull. So is this the step where we will upload the .bin .

I will place it in the flash ?

Fingers crossed...

I could not make the verifying stage a success...

I have tried reducing the clock of the swd to 10Khz and now the error happens quite far ahead in the addrress , 10Khz fails at address 0x0400.

Could it be the circuit?

PA30 (SWCLK) is pulled to 3.3v by a 1k resistor and PA31(SWDIO) is directky connected to the jtag

I don't think it is. The device erase and program wouldn't have taken place if this were the case.

Is the BOOTPROT fuse set to 0 bytes?

Indeed boot prot is set to 0

Whats weird is that it happens at always the same addresses for a given SWCLK frequency

1-4 Mhz its always Verifying Flash...Failed! address=0x0041 expected=0xb5 actual=0xb7