SAMA7G54-EK – Writing MPLAB® Harmony v3 Application and at91bootstrap to NOR Flash (QSPI) Memory using SAM-BA ISP
- Introduction
- Prerequisites
- Hardware
- NOR Flash (QSPI) Memory
- Setup Console Serial Communications
- Setup SAM-BA Host to Monitor Communications
- Erase NOR Flash Memory
- Write boot.bin to NOR Flash (QSPI) Memory
- Write harmony.bin to NOR Flash (QSPI) Memory
- Enable OTPC Emulation Mode
- Set Boot Configuration Packet to boot from NOR Flash (QSPI) Memory
- Run MPLAB Harmony v3 Application on the Target
- Summary
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:
- SAMA7G54-EK – Configure and Build at91bootstrap to Load a MPLAB® Harmony 3 Application from NOR Flash (QSPI) Memory
- SAMA7G54-EK – Getting Started with MPLAB® Harmony v3 Development: CSP Application: pio_led_on_off_interrupt
Prerequisites
- SAMA7G5 Series Boot Process
- SAMA7G5 Series Datasheet Section 19. Boot Strategies
- SAM-BA In-System Programmer (ISP) Host Application installed on the host computer
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
- Set the jumpers to their default positions as shown in the “Jumper Summary” section of the “SAMA7G54-EK - Features” page.
SD Memory Cards
- Ensure no SD memory cards are plugged into the SD card (J4) slot.
Power
- Apply power as shown in the “Power Options” section of the “SAMA7G54-EK - Features” page.
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.
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”.
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.
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.
Ensure jumper the DISABLE_BOOT (J22) jumper is open.
This will allow booting from the onboard memories.
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).
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
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
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
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.
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.
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).
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
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.
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.
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.
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.
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.
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.