SAMA5D29-Curiosity – Read and Write Boot Configuration Word Using SAM-BA® In System Programmer (ISP)
Content
Introduction
In this training topic, you will learn how to read and write the Boot Configuration Word from the Secure Fuse Controller (SFC) and Backup Registers (BUREGn) using the SAM-BA® In System Programmer (ISP) on the SAMA5D29-Curiosity Development Board (P/N: EV07R15A).
The SAMA5D29-Curiosity has been designed with peripheral connections that require a custom Boot Configuration Word to configure the input/output settings (IOSET). The peripherals are:
- Quad Serial Peripheral Interface 1 (QSPI1) peripheral – connected to a 64 Mb Serial Quad I/O (SQI) Flash (U9).
- Universal Asynchronous Receiver Transmitter (UART) Console – configured to UART0 and is connected to the Serial Debug Port 6-pin connector (J28).
- JTAG interface – connected to JTAG 20-pin connector (J27).
At manufacture, the SAMA5D29-Curiosity has been pre-programmed with a custom Boot Configuration Word located in the SFC to configure these peripherals. This training topic will show you how to read and explain its settings.
A Boot Configuration Word written to SFC cannot be changed. However, for prototyping and development purposes, a custom Boot Configuration Word can be written into one of four Backup Registers (BUREGn) to override the SFC setting. This gives the developer a method to test different configurations, including Secure Boot mode, and finalize the Boot Configuration Word for their product. We show you how to enable the boot sequence to read from a Backup Register.
Prerequisites
- Knowledgeable of the SAMA5D2 Series Boot Process.
- SAMA5D29 Datasheet – Section 17. Standard Boot Strategies.
- Familiarity with the features of the SAMA5D29-Curiosity Development Board.
- Knowledgeable of the SAM-BA ISP.
Hardware
For this training, you will use the SAMA5D29-Curiosity Development Board (P/N: EV07R15A) and a USB Type-C cable.
SAMA5D29-Curiosity Development Board
Set up the SAMA5D29-Curiosity as detailed in this tutorial to the host computer running the SAM-BA Host Application.
Jumpers
- Set the jumpers to their default positions as shown in the “Jumper Summary” section of the “SAMA5D29-Curiosity - Features” page.
SD Memory Cards
- Ensure no SD Memory Cards are plugged into SD Memory Card slots (J6 or J7).
USB-A Port (J1)
- Connect a USB Type-C cable to the USB-A port (J1) and the host computer running the SAM-BA Host Application.
- This will be the serial communications path for the SAM-BA Host to communicate with the SAM-BA Monitor on the SAMA5D29-Curiosity (otherwise known as the target).
Power
- The SAMA5D29-Curiosity will power on when a USB Type-C cable is plugged into the USB-A port (J1) and the host computer.
Console Serial Communications
- Connect a USB-to-Serial 3.3 or 5.0 VDC TTL Level adapter with a 6-pin single-in-line 0.1” pitch connector to a Serial Debug connector (J28) and establish serial communications with the host computer running a terminal emulation program.
- This connection will allow you to observe that the SAMA5D29 is in monitor mode waiting for commands from the SAM-BA Host Application.
First-Stage Bootloader
Microprocessor Units (MPUs) contain an internal ROM (also known as Boot ROM) that contains the first-stage bootloader. It is the program that begins executing when the MPU is reset.
The boot process steps are:
- Initialize processor and master clocks.
- Read the Boot Configuration Word.
- If (valid code found) in external NVM, then:
- Load second-stage bootloader at91bootstrap into internal SRAM.
- Remap internal SRAM to address 0x0.
- Reset the PC to 0x0 and jump.
- Else if (no valid code found) start the SAM-BA Monitor.
Our focus in this training topic is on the Boot Configuration Word. You will use the SAM-BA ISP Applet bootconfig to read, write, and customize the Boot Configuration Word.
Boot Process Flow
The boot process flow for reading the Boot Configuration Word on the SAMA5D2 Series is shown in the accompanying figure. The first step is to read the Boot Configuration Word from the Secure Fuse Controller (SFC).
Read the Boot Configuration Word from the Secure Fuse Controller (SFC)
The SAM-BA Host Application command to read the Boot Configuration Word from the SFC is:
Observe the Boot Configuration Word setting in SFC is 0x00061004.
The individual bit settings are explained in the following section. Note that a bit = 0 is the default setting (reset).
Bits 1:0 – QSPI_0[0b00] = QSPI0_IOSET1
Default setting. The QSPI0 peripheral is not used on the SAMA5D29-Curiosity.
Bits 3:2 – QSPI_1[0b01] = QSPI1_IOSET2
- The QSPI1 peripheral is connected to a 64 Mb Serial Quad I/O (SQI) Flash with EUI-48 and EUI-64 memory (U9).
Bits 5:4 – SPI_0[0b00] = SPI0_IOSET1
- Default setting. The SPI0 peripheral is not used on the SAMA5D29-Curiosity.
Bits 7:6 – SPI_1[0b00] = SPI1_IOSET1
- Default setting. The SPI1 peripheral is connected to mikroBUS-1, mikroBUS-2, 10/100 RMII Ethernet, and LCD Interface.
Bits 9:8 – NFC[0b00] = NFC_IOSET1
- Default setting. The NAND Flash Interface is available on the 20-pin Multifunction Connector (J26).
Bit 10 – SDMMC_0[0b0] = Boots on SDMMC_0 using SDMMC_0 PIO Set 1.
- Default setting. The SDMMC0 peripheral is connected to a micro Secure Digital (SD) Memory Card (J6) slot (mounted on the bottom side of the development board).
Bit 11 – SDMMC_1[0b0] = Boots on SDMMC_1 using SDMMC_1 PIO Set 1.
- Default setting. The SDMMC1 peripheral is connected to a Secure Digital (SD) or MultiMediaCard (MMC) Memory Card slot (J7).
Bits 15:12 – UART_CONSOLE[0b0001] = UART0_IOSET1
- The UART0 peripheral is connected to the Serial Debug Port (J28). This is the serial communications for the Console.
Bits 17:16 – JTAG_IO_SET[0b10] = JTAG_IOSET3
- The JTAG port is connected to the JTAG connector (J27).
Bit 18 – EXT_MEM_BOOT_ENABLE[0b1]
- Booting from external non-volatile memory (NVM) is enabled.
Bit 21 – QSPI_XIP_MODE[0b0]
- Default setting. The QSPI peripherals are configured to read from external serial memory and copy data to internal SRAM.
Bit 22 – DISABLE_BSCR[0b0]
- Default setting. Allows reading the Boot Configuration Word from a Backup Register (BUREGn) if the Backup Register Valid (BUREG_VALID) bit is set in the Boot Sequence Controller Configuration Register (BSC_CR).
Bit 24 – DISABLE_MONITOR[0b0]
- Default setting. If no valid code is found, start the SAM-BA Monitor.
Bit 29 – SECURE_MODE[0b0]
- Default setting. Boot using the standard boot sequence.
Read the Boot Sequence Controller Configuration Register (BSC_CR)
Once the Boot Configuration Word has been read, the second step is to check the Disable Boot Sequence Controller Configuration Register (DISABLE_BSCR) bit 22.
- If bit = 0, read the Boot Sequence Controller Configuration Register (BSC_CR)
- If bit = 1, use the Boot Configuration Word from the SFC
When the Boot Configuration Word was read from SFC above, we observed bit 22 = 0. Thus, the third step in the boot process will be to read the BSC_CR.
The SAM-BA Host Application command to read the BSC_CR is:
Observe BSC_CR = 0x0, as would be expected from a power-on reset.
The fourth step is to check the Backup Register Valid (BUREG_VALID) bit 2.
- If bit = 0, no backup register will be read, therefore use the Boot Configuration Word from SFC
- If bit = 1, read the Backup Register Index (BUREG_INDEX) bits 1:0 and read the Boot Configuration Word from BUREGn.
Since BUREG_VALID = 0, no backup register will be read and the Boot Configuration Word from SFC will be used in the boot process. The result is the SAMA5D29-Curiosity will boot with the pre-programmed Boot Configuration Word and configure the IOSETs for the peripherals as designed on the development board.
Customize the Boot Configuration Word
Let’s say you want to boot with your own version of the Boot Configuration Word for prototyping and development. In this case, you will need to write to the Boot Sequence Controller Configuration Register (BSC_CR) and set the BUREG_VALID bit = 1, and choose one of the four Backup Registers (BUREGn) and set the appropriate value in the Backup Register Index (BUREG_INDEX) register.
Write to Boot Sequence Controller Configuration Register (BSC_CR)
The SAM-BA Host Application command to write to the BSC_CR register and set BUREG_VALID is:
You can read the BSC_CR (bscr) register to verify the value was written.
Note that BUREG_INDEX = 0b00 is the default if no token is given. For each of the BUREG_INDEX values, the BSC_CR (bscr) tokens are:
- bureg0 (default)
- bureg 1
- bureg 2
- bureg 3
Write to Backup Register n (BUREGn)
The SAM-BA Host Application command to write to the BUREG0 register and set UART 1 to IOSET 1 and JTAG to IOSET 1:
Read Backup Register n (BUREGn)
The SAM-BA Host Application command to read the BUREG0 register:
Backup Registers 1, 2, and 3 can be read using the appropriate token in the command.
Backup Power VDDBU
When the SAMA5D29-Curiosity is powered off, the supercapacitor (C13) maintains the Backup Power, VDDBU provided jumper J3 is closed (the default). With VDDBU voltage applied, the MPU maintains the contents of the Backup Registers (BUREG).
To erase the contents of the BUREGs, open jumper J3 and power off the SAMA5D29-Curiosity.
Summary
In this training, you read and wrote values to registers associated with the Boot Configuration Word and learned how to boot using a customized version from the Backup Registers (BUREGn) using the SAM-BA ISP on the SAMA5D29-Curiosity Development Board (P/N: EV07R15A).