Microchip® Advanced Software Framework

SAM I2C Slave Bootloader

Overview:

Features

  • Application for self programming
  • Uses I2C Slave interface
  • I2C Master sends the data to be programmed over I2C bus
  • Resets the device after programming and starts executing application

Introduction

As many electronic designs evolve rapidly there is a growing need for being able to update products, which have already been shipped or sold. Microcontrollers that support boot loader facilitates updating the application flash section without the need of an external programmer, are of great use in situations where the application has to be updated on the field. The boot loader may use various interfaces like SPI, UART, TWI, Ethernet etc.

This application implements a I2C Slave bootloader for SAM devices.

This application has been tested on following boards:

  • SAM D20/D21/R21/D11/L22/L21 Xplained Pro

Program Memory Organization

This bootloader implementation consumes around 8000 bytes (approximately), which is 32 rows of Program Memory space starting from 0x00000000. BOOTPROT fuses on the device can be set to protect first 32 rows of the program memory which are allocated for the BOOT section. So, the end user application should be generated with starting address as 0x00002000.

Prerequisites

There are no prerequisites for this implementation

Hardware Setup

SAM device in SAM Xplained Pro kit is used as the I2C Slave. I2C master should be connected to PIN11 (PA08 - SDA) and PIN12 (PA09 - SCL) on External header 1 (EXT1) of SAM D20/D21 Xplained Pro. I2C master should be connected to PIN11 (PA16 - SDA) and PIN12 (PA17 - SCL) on External header 1 (EXT1) of SAM R21 Xplained Pro. I2C master should be connected to PIN11 (PA22 - SDA) and PIN12 (PA23 - SCL) on External header 1 (EXT1) of SAM D10/D11 Xplained Pro. I2C master should be connected to PIN11 (PB30 - SDA) and PIN12 (PB31 - SCL) on External header 1 (EXT1) of SAM L22 Xplained Pro. I2C master should be connected to PIN11 (PA08 - SDA) and PIN12 (PA09 - SCL) on External header 1 (EXT1) of SAM L21 Xplained Pro. SW0 will be configured as BOOT_LOAD_PIN and LED0 will be used to display the bootloader status. LED0 will be ON when the device is in bootloader mode.

Bootloader Process

Boot Check

The bootloader is located at the start of the program memory and is executed at each reset/power-on sequence. Initially check the status of a user configurable BOOT_LOAD_PIN.

  • If the pin is pulled low continue execution in bootloader mode.
  • Else read the first location of application section (0x00002000) which contains the stack pointer address and check whether it is 0xFFFFFFFF.
    • If yes, application section is empty and wait indefinitely there.
    • If not, jump to the application section and start execution from there.
      Note
      Configuring the BOOT_LOAD_PIN and disabling watchdog in this boot mode check routine are made with direct peripheral register access to enable quick decision on application or bootloader mode.

Initialization

Initialize the following

  • Board
  • System clock
  • I2C Slave module
  • NVM module

Boot Protocol

  • I2C Master first sends 4 bytes of data which contains the length of the data to be programmed
  • Read a block from I2C Master of size NVMCTRL_PAGE_SIZE
  • Program the data to Program memory starting APP_START_ADDRESS
  • Send an acknowledgement byte 's' to I2C Master to indicate it has received the data and finished programming
  • Repeat till entire length of data has been programmed to the device

Start Application

Once the programming is completed, enable Watchdog Timer with a timeout period of 256 clock cycles and wait in a loop for Watchdog to reset the device.

Compilation Info

This software was written for the GNU GCC and IAR for ARM. Other compilers may or may not work.

Contact Information

For further information, visit http://www.microchip.com.