Anybody that DID compile a modified bootloader for SAMD21 might like this ...
I managed to port the Atmel ASF samd20 SPI bootloader ( SAMD20J18 to the SAMD21G18 )
- remapped the SPI sercom , the bootpin & the LED
- Also mapped sercom4 for UART debug
Celebrated after I was able to bootload BLINK sketch stored on my SDcard
( compiled on Arduino IDE with modified start address to 0x8000 instead of 0x2000 ).
But i am stuck not able to run slightly more complex sketches
ex: my main sketch that uses WiFi to download new BIN file.
ex: even the simple ASCIItable dump on the serial port.
they 'did' worked a few 'random' times based on unknown connect/disconnect / reset or else ...
so the process is 99% good BUT i might be missing an Interupt Vector init or something ...
Does anyone know of some limitations in what to DO / DON'T in a bootloader when jumping to the main sketch ?
I think the problem is with reset_handler / Vector table remapping ...
I want to share this bootloader for the greater good of the community
BUT want to clean it first so it would be easier for anyone who may want to contribute.
( i.e : provide easy guidelines for PINs / sercom mapping of current and future M0 platforms )
I did manually read the content of Flash 0x8000 and does match the sketch bin file ( content and length )
so the issue may just be with the "switch over"
The bootloader got modified from the Atmel ASF with the samd20_xplained_pro.h
- proven working solution ( or Atmel wouldn't publish it ... )
What the bootloader does :
- init the Reset_handler
( pretty much identical to the one used in the Arduino reset_handler of the bootlooader ) - call main()
main()
-
if bootpin not asserted or memory at addr 0x8000 ( start of sketch ) is 0xFFFF (unprogrammed ) go for bootload_process()
-
otherwise, start the sketch:
-
set MSP to 0x8000 ( sketch start address 0x8000 )
-
set Vector_table to sketch start_Address
-
jump to sketch startaddress + 4
Using Atmel Studio 7.0 & Segger JLINK
I am currently using the Adafruit M0 winc1500 ( mkr1000 was not available back then ) with SD card interface.