Hi @John41234
No, it's not possible to use any SAMD21 bootloader. Generally you can get away with using the Arduino Zero bootloader for different SAMD21 E, G & J sized variants, but this only works for those devices with the maximum 256KB flash and 32KB RAM.
Since you mention that you're using the SAMD21E15B with a reduced memory footprint of 32KB flash 4KB RAM, you'll either need to find a precompiled binary for a SAMD21x15A device, or create your own. Creating your own also has the advantage in that it allows you account for status LEDs on your custom board.
The Atmel Studio 7 solution/project files for the SAMD21 are stored in the Arduino Zero's bootloader directory. On my PC it's located here:
C:\Users\Computer\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.8.11\bootloaders\zero
I suggest first copying entire Zero bootloader folder to one with another name and use that, rather than modifying the Arduino Zero's bootloader files directly.
The solution to open in Atmel/Microchip Studio is the Atmel Solution or .atsln file.
The files you need to modify are:
1. board_definitions_arduino_zero.h
You'll need to change the address of the double tap reset "magic number". This is usually stored in the last 4 bytes of RAM, hence if you use the Arduino Zero's bootloader for a device with larger memory you double tap reset won't work. In the code below I've modified tha address to account for the SAMD21E15B's 4K of RAM:
/*
* If BOOT_DOUBLE_TAP_ADDRESS is defined the bootloader is started by
* quickly tapping two times on the reset button.
* BOOT_DOUBLE_TAP_ADDRESS must point to a free SRAM cell that must not
* be touched from the loaded application.
*/
//#define BOOT_DOUBLE_TAP_ADDRESS (0x20007FFCul)
#define BOOT_DOUBLE_TAP_ADDRESS (0x20000FFCul) // 4K RAM - 4 bytes
#define BOOT_DOUBLE_TAP_DATA (*((volatile uint32_t *) BOOT_DOUBLE_TAP_ADDRESS))
In this file you can also configure if you'd also like the option to upload from a serial port as well:
#define BOOT_USART_MODULE SERCOM0
#define BOOT_USART_BUS_CLOCK_INDEX PM_APBCMASK_SERCOM0
#define BOOT_USART_PER_CLOCK_INDEX GCLK_CLKCTRL_ID_SERCOM0_CORE_Val
#define BOOT_USART_PAD_SETTINGS UART_RX_PAD3_TX_PAD2
#define BOOT_USART_PAD3 PINMUX_PA11C_SERCOM0_PAD3
#define BOOT_USART_PAD2 PINMUX_PA10C_SERCOM0_PAD2
#define BOOT_USART_PAD1 PINMUX_UNUSED
#define BOOT_USART_PAD0 PINMUX_UNUSED
If your custom board is CRYSTALLESS, (uses the SAMD21's intenal 32k oscillator instead of an external 32k crystal):
/* Frequency of the board main oscillator */
#define VARIANT_MAINOSC (32768ul)
#define CRYSTALLESS (1)
If you need to change any of the status/communication LEDs:
/*
* LEDs definitions
*/
#define BOARD_LED_PORT (0)
#define BOARD_LED_PIN (17)
#define BOARD_LEDRX_PORT (1)
#define BOARD_LEDRX_PIN (3)
#define BOARD_LEDTX_PORT (0)
#define BOARD_LEDTX_PIN (27)
2. bootloader_samd21x18.ld
This is the linker script file that also need changing to account for the microcontroller's memory. Again I've modified the lines for the SAMD21E15B's 4KB RAM:
MEMORY
{
FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 0x2000 /* First 8KB used by bootloader */
RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00001000-0x0004 /* last 4 bytes used by bootloader to keep data between resets */
}
Once the files have been modified and saved, compile. This should create a binary (*.bin) that you can upload to your microcontroller.