The ASFv3 SAM-BA bootloader provides a way to program Cortex-M0+ microcontrollers in-system through USB or a UART host, without requiring an external programming interface. Unlike SAM microcontrollers with a ROM-based SAM-BA monitor, Cortex-M0+ devices covered by this approach load the monitor firmware into Flash. Adapting it for a custom board or a different device means coordinating changes across the bootloader, memory layout, host-side scripts and SRAM-based applet.
How the SAM-BA programming flow works
The SAM-BA system has several parts that work together. The bootloader firmware in Flash receives requests from the SAM-BA host application and handles the commands it supports. The host GUI uses a TCL script to validate the selected device and assist with applet commands. The applet is firmware that the monitor loads into SRAM; it performs the requested operations, such as Flash programming.
This separation matters when customizing a project. Changing only the bootloader may leave the host script identifying the wrong device or the applet using an incompatible memory map or peripheral. Treat the components as one programming path, and check that their device and interface assumptions agree.
Adapting an ASF project to a user board
ASFv3 SAM-BA examples were supplied for supported Xplained Pro boards. To adapt the SAMD21 example for a user board using a SAMD21E16B, the project configuration and board support need to reflect the new target. In the Atmel Studio workflow described for ASFv3, the key steps are:
- Select the target device: Change the project device from SAMD21J18A to SAMD21E16B in the project properties.
- Update the compiler symbol: Replace the existing __SAMD21J18A__ definition with __SAMD21E16B__.
- Identify the project as a user-board build: Remove the Xplained Pro BOARD definition and define BOARD=USER_BOARD.
- Provide board definitions: Add a user_board.h file under the ASF boards directory with the required components and pin definitions, following the structure of the relevant board header.
- Adjust board initialization: Copy the example board’s board_init.c to the boards directory and remove the Xplained Pro board folder from the project.
- Review the linker script: Match RAM, Flash and default stack allocation to the selected device. A linker script for the target can be obtained by creating a project for that device in Atmel Studio.
Other board-specific changes, such as adding or removing LED support, depend on the design. These steps are not simply a device-name substitution: the board definitions, startup behavior and linker memory regions must all describe the actual hardware.
Configure the bootloader and communication interface
The ASF bootloader configuration file, conf_bootloader.h, includes options for the bootloader’s memory boundary, entry behavior and communication hardware. For example, APP_START_ADDRESS must be selected based on the bootloader firmware size. BOOT_LOAD_PIN can specify a user-defined GPIO used to request bootloader mode, while BOOT_LED and DEBUG_ENABLE control optional status indication.
For UART operation, configure the SERCOM instance and associated settings to match the board. Relevant options include BOOT_USART_MODULE, the SERCOM mux selection, TX/RX pad assignments and the generic clock source. USB CDC support is controlled separately through CONF_USBCDC_INTERFACE_SUPPORT. Change only the options needed for the design; the source guidance cautions against modifying unrelated bootloader settings.
Keep the TCL script and applet aligned
The host-side files also need updates when changing device variants. In the SAM-BA installation’s device-specific TCL script, add the target to the supported devices list. Then review appletAddr and appletMailboxAddr in light of the selected device and the SRAM occupied by the bootloader.
The applet’s SRAM linker script must likewise reflect the target’s memory layout and the space used by the bootloader. If changing the UART interface—for example, from SERCOM3 to SERCOM0—update the applet source as well as the bootloader configuration. The applet Makefile also needs the correct chip name and ASF branch path. After these edits, rebuild the applet using the command-line process provided with the development environment.
Memory limits and troubleshooting considerations
Several constraints can affect whether a customized setup works as expected:
- The ASF SAM-BA bootloader is not optimized for memory-constrained Cortex-M0+ variants and may not work on devices with less than 8 KB of SRAM.
- Some device-specific monitor firmware, TCL scripts or applets may not be included in a given SAM-BA release. The documented example notes that these files were unavailable for some devices in SAM-BA v2.18.
- Large downloads, such as files greater than 32 KB, may make the GUI appear unresponsive while the request continues in the background.
- Some GCC versions may cause optimization-related issues that can also make the GUI appear to hang; GCC 6.3.1.508 is cited as an example.
For USB-to-serial use, the EDBG device on Xplained Pro boards provides a full-speed USB-serial bridge. A full-speed USB-serial converter is suggested when seeking similar interface performance.
Account for application memory and Flash contents
The application linker script also affects resource use. Stack space is allocated at startup, and the default allocation may be larger than a particular application requires. Review and configure that value for the application rather than assuming the default is appropriate.
If a programming or validation workflow requires unused Flash locations to contain a known value, the linker can be configured to fill a dedicated region. One approach is to create a dummy section in the application, retain it in the linker script, and use a fill directive to extend the chosen value—such as 0xFF—to the end of the ROM region. The section and region boundaries must be defined carefully in the linker script.
Build a consistent programming path
Customizing an ASFv3 SAM-BA bootloader is a coordinated engineering task: verify the target and board definitions, match the linker memory regions to the device, configure the correct SERCOM or USB option, and align the host TCL script and SRAM applet. Checking these pieces together helps expose mismatches before they complicate firmware programming. For resource-constrained devices, confirm SRAM suitability and review stack allocation as part of the same design process.