SAMA7G54-EK – Writing MPLAB® Harmony v3 Application and at91bootstrap to NOR Flash (QSPI) Memory using SAM-BA ISP

Last modified by Microchip on 2023/11/21 22:27

Introduction

In this training topic, you will write two binary images, harmony.bin (an MPLAB® Harmony v3 Application) and boot.bin (Second-stage bootloader, at91bootstrap), to NOR Flash (QSPI) memory on the SAMA7G54-EK Evaluation Kit using the SAM-BA® In-System Programmer (ISP). Next, you will place the SAMA7G54 into OTPC Emulation Mode and configure the Boot Configuration Packet to boot from NOR Flash (QSPI) Memory. Once these steps are completed, and upon reset, the SAMA7G54 will boot and run the MPLAB Harmony v3 application. 

For this exercise, you will write the binaries that were created in the training topics: 

Prerequisites

This training topic was developed with SAM-BA ISP v3.7 

Hardware

For this training, you will use the SAMA7G54-EK Evaluation Kit.

SAMA7G54-EK Evaluation Kit

Set up the SAMA7G54-EK as listed below to the host computer running the SAM-BA Host Application. 

Jumpers

SD Memory Cards

  • Ensure no SD memory cards are plugged into the SD card (J4) slot.

Power

Back to Top

NOR Flash (QSPI) Memory

The SAMA7G54-EK has a 1 Gb octal interface serial NOR Flash memory (U9) (Macronix MX66LM1G45G) configured as 8 bits x 128 MB. It is connected to the Quad Serial Peripheral Interface port 0 (QSPI0 IOSET1) of the SAMA7G54. This Non-Volatile Memory (NVM) can be used for booting the system. 

Back to Top

Setup Console Serial Communications

To view the target console, connect the host computer running a terminal emulation program in accordance with “SAMA7G54-EK – Console Serial Communications”. 

Back to Top

Setup SAM-BA Host to Monitor Communications

In this section, you will establish SAM-BA Host Application communications with the target’s (SAMA7G54) SAM-BA Monitor.  

Be certain that the SAM-BA host application has been added to the path. 

To communicate with the SAM-BA Monitor on the target, you must 

  • Installed the SAM-BA Host on a Host Computer, and  
  • Connect a Micro-B USB cable to USB-A port (J7) on the SAMA7G54-EK. 

The USB-A port (J7) also functions as a secondary source to power the SAMA7G54-EK. The port is limited to 500 mA. If greater current is required, the SAMA7G54-EK should be powered via J1 (see “Power Options” section on the “SAMA7G54-EK – Features” page.). 


Ensure there is no SD memory card inserted in slot J4.

Ensure jumper the DISABLE_BOOT (J22) jumper is open.  

This will allow booting from the onboard memories.  

With no SD memory card installed, the SAMA7G54 will boot to the monitor program. The SD memory card is the default NVM boot memory provided the Boot Configuration Packet has not been written to One-Time Programmable (OTP) memory or emulation memory. 


Press the nSTART (SW3) push button to wake up the MPU. 

The SAMA7G54-EK will boot to the SAM-BA Monitor. This action will also activate the USB-A port (J7).  


Observe RomBOOT on the Console (terminal emulator) indicating the SAM-BA Monitor is running on the target device.

Back to Top

Erase NOR Flash Memory

In this section, you will erase the contents of the NOR Flash Memory. This is a necessary step before writing data. 

For more information on the SAM-BA Applet qspiflash, see SAM-BA In-System Programmer - Applets 

Erase the contents of the NOR Flash memory using the following SAM-BA Host Applet command: 

sam-ba -p serial -b sama7g5-ek -a qspiflash -c erase 

This will take a while. 

Command Window: qspi erase 1 of 2

Command Window: qspi erase 2 of 2

Console: qspi erase

Back to Top

Write boot.bin to NOR Flash (QSPI) Memory

In this section, you will write the at91bootstrap binary image, boot.bin, to NOR Flash (QSPI) Memory. 

Change the directory to the location of boot.bin

<project_directory>\at91bootstrap\build\binaries\boot.bin 


Write boot.bin to NOR Flash (QSPI) Memory using the following SAM-BA Host Applet command: 

$ sam-ba -p serial -b sama7g5-ek -a qspiflash -c writeboot:boot.bin 

The writeboot command is used to write a bootstrap file into an external NVM memory boot partition. 

Command Window: qspiflash writeboot boot.bin

Console: qspiflash writeboot boot.bin

Back to Top

Write harmony.bin to NOR Flash (QSPI) Memory

In this section, you will write the MPLAB Harmony v3 application binary image, harmony.bin, to NOR Flash (QSPI) Memory. 

Change directory to the location of harmony.bin

C:\Users\<user>\Harmony3\csp_apps_sam_a7g5\apps\pio\pio_led_on_off_interrupt\firmware\sam_a7g5_ek.X\dist\sam_a7g5_ek\production\ 


Write harmony.bin to NOR Flash Memory using the following SAM-BA Host Applet command: 

$ sam-ba -p serial -b sama7g5-ek -a qspiflash -c write:harmony.bin:0x200000 

The write command syntax is write:<filename>:[<addr>] where <addr> is the Flash Offset for Demo App value in the at91bootstrap configuration (Kconfig). The value 0x200000 you took note of in the training: SAMA7G54-EK – Configure and Build at91bootstrap to Load a MPLAB® Harmony v3 Application from NOR Flash (QSPI) Memory 

Project Properties: kconfig

Command Window: qspiflash write harmony.bin

Console: qspiflash write harmony.bin

Back to Top

Enable OTPC Emulation Mode

When prototyping, the One-Time Programmable Memory Controller (OTPC) can be placed into Emulation mode. Emulation mode allows you to customize the Boot Configuration Packet without having to commit it to OTP Memory. In this mode, the OTP memory is emulated by OTPC Emulation Memory. 

In production, the Boot Configuration Packet is normally stored in the device’s internal OTP Memory. 

The OTPC Emulation Memory uses a portion of Secure backup SRAM (SECURAM) located inside the Security Module (SECUMOD) and is powered by VDDBU. Therefore, if the power is removed from the MPU, and VDDBU is available, data will remain. 

The Emulation mode can only be enabled when OTP Memory has not been previously programmed. 

To place the SAMA7G54 into Emulation mode, you will use the SAM-BA Applet bootconfig writecfg command to program the Boot Sequence Control Register (BSCR) to configure the first-stage bootloader (ROM code) to enable the emulation mode before reading the Boot Configuration Packet (BCP). 

For more information on SAM-BA Host Applets, see  

To enable Emulation mode, perform the following steps: 

Set the Boot Sequence Configuration Register (BSC_CR), Emulation Enable (EMUL_EN) bit to ‘1’: 

$ sam-ba -p serial -b sama7g5-ek -a bootconfig -c writecfg:bscr:EMULATION_ENABLED 

Setting the EMUL_EN bit in the BSC_CR register does not enable the OTPC Emulation mode immediately. It only tells the first-stage bootloader (ROM code) to enable the OTPC Emulation mode on the next reset before fetching the Boot Configuration Packet and any other user area packet.

Command Window: bootconfig writecfg bscr EMUL_EN

Console: bootconfig writecfg bscr EMUL_EN


Reset Emulation Memory in SECURAM to zero.  

$ sam-ba -p serial -b sama7g5-ek -a bootconfig -c resetemul  

The resetemul command must be called once before any other command accessing SECURAM. 

Command Window: bootconfig resetemul

Console: bootconfig resetemul


Refresh the Emulation mode. 

$ sam-ba -p serial -b sama7g5-ek -a bootconfig -c refreshcfg:emul  

The refreshcfg:emul command tells the OTPC to enable its Emulation mode before scanning all packets in the User Area.  

Command Window: bootconfig refreshcfg emul

Console: bootconfig refreshcfg emul

The OTPC Emulation mode is now enabled immediately. It will remain enabled until the next power-on-reset or it has been disabled by the refreshcfg:otp command. 

As SECURAM is powered by VDDBU, data is kept after reset. However, if the value in the BSC_CR register is reset you will have to reissue the above commands to re-enable emulation mode. 

Back to Top

Set Boot Configuration Packet to boot from NOR Flash (QSPI) Memory

In this section, you will configure the Boot Configuration Packet to boot from NOR Flash (QSPI) Memory. 

For more information on the Boot Configuration Packet, see Section 19. Boot Strategies in the SAMA7G5 Series Datasheet 

Write boot configuration to boot from NOR Flash (QSPI) Memory.  

​​​​Command Window: bootconfig writecfg bcp-emul

Console: bootconfig writecfg bcp-emul

Back to Top

Run MPLAB Harmony v3 Application on the Target

To run the application, press the nRST (Reset) (SW2) push button. It will take a moment for the SAMA7G54 to boot. Observe the RGB LED (D7) lights green (during boot) and then turns off.  

Press the USER BUTTON (SW1) and observe the RGB LED (D7) light blue. Release the USER BUTTON and the RGB LED will turn off.  

The application uses the PIO Peripheral library to generate a callback on switch press and release and drives the GPIO pin connected to the RGB LED to indicate the switch status. 

Console: application running

Back to Top

Summary

In this training topic, after you established console and SAM-BA Host to Monitor communications, you first erased and then wrote boot.bin and harmony.bin to NOR Flash (QSPI) Memory. Then you placed the SAMA7G54 into OTPC Emulation mode and configured the Boot Configuration Packet to boot from NOR Flash (QSPI) Memory. Finally, upon reset, the SAMA7G54-EK boots the MPLAB Harmony v3 application. 

Back to Top