Arduino HEX file not working on a custom SAMD21G18A board

Hello,

I have made a custom PCB board SAMD21G18A (without EDBG and similar to MKRZero) and I am currently programming it using a J-Link EDU Segger debugger and Atmel Studio 7. The blink example code works fine.

Now, I want to only use the Arduino IDE and generate a HEX file which then I can just download using the software from J-Link. I do not want to use AS7.

Thus, simply, what I did was on Arduin IDE to choose board as MKRZero and export a compiled binary file. Then I uploaded the HEX file generated using J-Link lite programmer application.

This did not work and the MCU did not booted up. No leds were blinking.

Does the HEX file generated by Arduino and AS7 different? Could that be the reason OR my custom board should have some specific pin pulled-up in order to start the program.

Any help is appreciated.

Thanks.

The arduino hex file will be built to be loaded after a bootloader. If the bootloader isn’t present, it probably won’t work.

There were two kinds of HEX files which were generated - one was sketch sketch_feb03a.ino.hex while the other was sketch_feb03a.ino.with_bootloader.hex

I assume the first one is without bootloader and should work.

Is there any way to make it work without bootloader?

Any help appreciated. Thanks.

I assume the first one is without bootloader and should work.

Actually, the one without the bootloader will assume that the bootloader is already present on the chip.
The "with_bootloader" contains the sketch AND the bootloader, and might work ok (I'm not sure whether there are other settings required, but it would address the specific failure mode I'm thinking of.)

I tried the "wih_bootloader" file but the J-Link flasher software gives an error - "not able to parse". Not sure why the software does not takes the with_bootloader file. The without one uploads without any errors. Any clue or should I use a different programmer. I am currently using J-Link Segger EDU.

It's possible the bootloader merge functionality doesn't even work for the SAMD boards. From reading this:

and the links from that issue, it sounds like this feature was specifically added for the Yun, and perhaps not currently designed in a way that is portable to other architectures.

Thanks for pointing out @pert and @westfw. Yes, you are right, I cannot currently trust the with_bootloader.hex file.

So the question still remains:

is there any way I can make the hex file generated from ARduino IDE to get uploaded and boot on a custom SAMD board (without bootloader)?

Hi halfroboprince,

In your board's "boards.txt" file it's possible to change the linker script from "flash_with_bootloader.ld" to "flash_without_bootloader.ld":

arduino_zero_native.build.ldscript=linker_scripts/gcc/flash_with_bootloader.ld
The "flash_without_bootloader.ld" file will set the head of your program to address 0x00000000 and won't reserve the 8KB of flash memory for the bootloader:

MEMORY
{
  FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 0x00040000
  RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00008000
}

Another issue might be the SAMD21's BOOTPROT fuse designed to protect the bootloader from being overwritten. This fuse can be read in AS7 and should be set to 0x07 (the default setting) to turn off protection. The Arduino Zero bootloader doesn't change the BOOTPROT fuse, while Adafruit's UF2 bootloader does.

When using "Export complied Binary" with the Arduino IDE and the SAMD21, I usually get a .bin file rather than .hex.