Atmel 42238 Uart Based Sam Ba Bootloader For Sam d20 AP Note At04189
Atmel 42238 Uart Based Sam Ba Bootloader For Sam d20 AP Note At04189
Description
Features
Allows to program, verify, and secure a SAM D20 device without debugger
UART connection (RS232)
Allows the end user to update firmware in application
Configurable I/O start condition
Source code available, can be customized to users needs
Compatible with SAM-BA v2.12 with patch 7 or above
Atmel-42238B-UART-based-SAM-BA-Bootloader-for-SAM-D20_ApplicationNote_AT04189_062014
Requirements
1.1
Hardware Requirements
The Atmel SAM D20 SAM-BA Boot Assistant supports serial communication via the UART interface.
Table 1-1.
Signal name
Description
PA25
PA24
Table 1-2.
Signal name
Description
PA15
1.2
Software Requirements
1.2.1
Application Constraints
Unlike existing SAM products using a ROM monitor, on the Atmel SAM D20 SAM-BA is stored in flash memory at
[0x0 0x800] and started on reset.
Since SAM-BA is stored in flash memory, if the application requires the entire flash space and does not need the
bootloading feature, SAM-BA can be erased using a SWD debugger.
To use SAM-BA together with an application, the user needs to link the application starting at 0x800. The below
procedure explains how to modify the start address in an IAR project and an Atmel Studio project.
AT04189: UART Based SAM-BA Bootloader for SAM D20 [APPLICATION NOTE]
Atmel-42238B-UART-based-SAM-BA-Bootloader-for-SAM-D20_ApplicationNote_AT04189_062014
Figure 1-1.
Figure 1-2.
AT04189: UART Based SAM-BA Bootloader for SAM D20 [APPLICATION NOTE]
Atmel-42238B-UART-based-SAM-BA-Bootloader-for-SAM-D20_ApplicationNote_AT04189_062014
Select Edit
Set ROM start in Memory Regions tab to 0x00000800 and end to original ROM length minus 0x800.
Figure 1-2 shows modified example for ATSAMD20J18
Figure 1-3.
AT04189: UART Based SAM-BA Bootloader for SAM D20 [APPLICATION NOTE]
Atmel-42238B-UART-based-SAM-BA-Bootloader-for-SAM-D20_ApplicationNote_AT04189_062014
Figure 1-4.
When loading the application binary image to the device, only the part of flash starting from 0x800 address
should be programmed.
Any attempt to write to the SAM-BA region using SAM-BA commands will be aborted and will throw an error.
2.1
The samd20_sam-ba_image.hex file in folder load sam-ba in AT04189.zip is built for ATSAMD20J18
device. For other devices the SAM-BA monitor has to be re-built. Refer Chapter 4 for more details.
AT04189: UART Based SAM-BA Bootloader for SAM D20 [APPLICATION NOTE]
Atmel-42238B-UART-based-SAM-BA-Bootloader-for-SAM-D20_ApplicationNote_AT04189_062014
Figure 2-1.
Device Programming
Alternatively command-line programming tool atprogram can also be used for programming the hex file.
Example:
2.2
External condition: Reset the part and make sure the Hardware Bootloader Entry pin (PA15) is pulled low
when reset is released. A common usage is to use a push button accessible by the user as a bootloader
trigger. The user simply has to hold the push button when powering up the device.
Internal condition: On erased devices or when the application reset vector (@0x804) is blank
(0xFFFFFFFF)
AT04189: UART Based SAM-BA Bootloader for SAM D20 [APPLICATION NOTE]
Atmel-42238B-UART-based-SAM-BA-Bootloader-for-SAM-D20_ApplicationNote_AT04189_062014
Figure 2-2.
Code security concerns: When SAM-BA monitor is entered, it allows read and write access to the entire memory
map of the device. It also allows the host to upload and execute software (applets) on the device.
After these preliminary steps, the monitor will enter a loop and test whether a # (sharp) character is received on
PA25 (SERCOM3 PAD3) line. PA24 (SERCOM3 PAD2) becomes an output driven by the SAM D20 device
according to the MUX setting.
2.3
2.3.1
AT04189: UART Based SAM-BA Bootloader for SAM D20 [APPLICATION NOTE]
Atmel-42238B-UART-based-SAM-BA-Bootloader-for-SAM-D20_ApplicationNote_AT04189_062014
Figure 2-3.
2.3.2
Flash Loading
Loading the flash content is done by using the Flash tab. When uploading a program to flash memory, the start
address needs to be above 0x800, otherwise the transfer will abort.
Figure 2-4.
Flash Programming
AT04189: UART Based SAM-BA Bootloader for SAM D20 [APPLICATION NOTE]
Atmel-42238B-UART-based-SAM-BA-Bootloader-for-SAM-D20_ApplicationNote_AT04189_062014
2.3.3
Scripts
Atmel SAM-BA application comes with the following predefined scripts (see Table 2-1):
Table 2-1.
Predefined Scripts
Script name
Description
Set the security bit to secure the device (Refer to NVMCTRL chapter in the device datasheet
for more information)
Invalidate application
Read Fuses
Returns the values of fuse settings (Refer to NVM User Row Mapping section in the device
datasheet for more information)
Read DeviceID
Set the specified lock bit to prevent any erasure of flash memory region (Refer to NVMCTRL
chapter in the device datasheet for more information)
Unlock all
Source code of SAM D20 SAM-BA monitor and the associated IAR project.
2.
Example binary image of an application which starts at 0x800 The application continuously toggles LED0
on SAM D20 Xplained Pro.
3.
Note:
To ensure minimal size for the bootloader, the source code as well as the project file is available only for
the IAR compiler.
Open SAM-BA monitor IAR project and go to Project -> Options -> General Options -> Target tab ->
Processor Variant -> select the required SAM D20 device.
2.
Now go to C/C++ Compiler -> Preprocessor tab -> under Defined Symbols box, edit the device name
macro. For example, for ATSAMD20G18 device, change the macro to __SAMD20G18__
(Note: Double underscores should be used).
3.
Now go to Linker -> Config tab -> Linker Configuration File -> change the file name to required device. For
example, for ATSAMD20G18 device, use $PROJ_DIR$\linker\samd20g18_flash.icf.
AT04189: UART Based SAM-BA Bootloader for SAM D20 [APPLICATION NOTE]
Atmel-42238B-UART-based-SAM-BA-Bootloader-for-SAM-D20_ApplicationNote_AT04189_062014
Supported Devices
Following devices in SAM D20 family are supported by the SAM-BA version 2.12 patch 7 or above.
1.
ATSAMD20E15
2.
ATSAMD20E16
3.
ATSAMD20E17
4.
ATSAMD20E18
5.
ATSAMD20G15
6.
ATSAMD20G16
7.
ATSAMD20G17
8.
ATSAMD20G18
9.
ATSAMD20J15
10. ATSAMD20J16
11. ATSAMD20J17
12. ATSAMD20J18
ATSAMD20E14/G14/J14 devices are not supported by SAM-BA.
References
6.1
Device Datasheet
The device datasheet contains the block diagrams of the peripherals and details about implementing firmware for
the device. It also contains the electrical specifications and expected characteristics of the device.
Datasheet is available on www.atmel.com in the Documents section of Atmel SAM D20 product page.
6.2
6.3
6.4
6.5
Atmel Studio
The latest version of Atmel Studio can be downloaded from http://www.atmel.com/tools/atmelstudio.aspx.
10
AT04189: UART Based SAM-BA Bootloader for SAM D20 [APPLICATION NOTE]
Atmel-42238B-UART-based-SAM-BA-Bootloader-for-SAM-D20_ApplicationNote_AT04189_062014
Revision History
Doc Rev.
Date
42238B
06/2014
42238A
01/2014
Comments
1.
2.
3.
4.
AT04189: UART Based SAM-BA Bootloader for SAM D20 [APPLICATION NOTE]
Atmel-42238B-UART-based-SAM-BA-Bootloader-for-SAM-D20_ApplicationNote_AT04189_062014
11
Atmel Corporation
T: (+1)(408) 441.0311
F: (+1)(408) 436.4200
www.atmel.com
12
AT04189: UART Based SAM-BA Bootloader for SAM D20 [APPLICATION NOTE]