SAMA7G54-EK – Writing MPLAB® Harmony v3 Application and at91bootstrap to e.MMC Flash Memory using SAM-BA® ISP

Last modified by Microchip on 2024/01/03 21:51

Introduction

In this training you will write two binary images, harmony.bin (an MPLAB® Harmony v3 Application) and boot.bin (Second-stage bootloader, at91bootstrap), to e.MMC Flash 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 Embedded MultiMediaCard (e.MMC) Flash 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 was developed with SAM-BA ISP v3.7.

Hardware

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

SAMA7G54-EK Evaluation Kit

Setup the SAMA7G54-EK as listed below to the host computer running SAM-BA host application. 

Jumpers

SD Memory Cards

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

Power

Back to Top

Embedded MultiMediaCard (e.MMC) Flash Memory

The SAM9XA7G54-EK has a 4 GB e.MMC managed NAND Flash memory (U10) (SkyHigh Memory S40FC004C1B1C00000). It is connected to the Secure Digital Multimedia Controller port 0 (SDMMC0) of the SAMA7G54.

Back to Top

Setup Console Serial Communications

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

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

Create Image File

In this section, you will create a sdcard.img file from the boot.bin and harmony.bin files using Windows® utilities DiskPart and Win32 Disk Imager. You will need an SD memory card for this section.

First, you will partition the SD memory card for 4 MB and format it with the FAT file system. Second, you will copy the boot.bin and harmony.bin images to the SD memory card and use the Win32 Disk Imager utility to create a sdcard.img file. Then in the next section, you will write the sdcard.img file to e.MMC Flash Memory using the SAM-BA In-System Programmer.

Back to Top

Partition SD Memory Card with DiskPart Utility

DiskPart requires admin privileges.

The Windows Disk Management utility is unable to partition a volume to 4 MB (8 MB is the minimum), therefore we must use the DiskPart utility.

Insert SD memory card into your computer.

Open the DiskPart utility from the Windows search bar or command window.

Type the command: list disk

Observe the listing of disk drives on your computer. Identify the SD memory card. In the screen capture below, Disk 0 is the main disk and Disk 1 is the SD memory card.

Tip: Remove all removable memory from your computer to make it easier to identify the SD memory card.

Command Window; Diskpart list command

Type the command: select disk n where “n” is the SD memory card.

Be sure to select the SD memory card disk! The operations you type from here on out will be on the disk you select.

Command Window; Diskpart select disk

Type the command: list partition

Observe the partitions on the SD memory card. Identify the partition(s).

Command Window; Diskpart list partition command

Type the command: select partition n where “n” is the partition to be deleted.

Select the partition to be deleted so that you can create a new partition in the next steps.

Command Window; Diskpart select partition command

Type the command: delete partition

The selected partition will be deleted.

Command Window; Diskpart delete partition command

Type the command: create partition primary size=4

Command Window; Diskpart create partition primary command


Format SD memory card 4 MB Partition.

You may format the SD memory card using a method that is most comfortable to you. Format in either the FAT or FAT32 file system.

The DiskPart command below will format the partition in the FAT file system:

Type the command: format

Command Window; Diskpart format command


Copy boot.bin and harmony.bin to the 4 MB SD memory card partition you just created.

Create Image with Win32 Disk Imager Utility

Win32 Disk Imager requires admin privileges.

Download and install the Win32 Disk Imager utility program.

Select the drive letter of the SD memory card under the Device drop-down menu.

Win32 Disk Imager: select device


Enter the path and the filename "sdcard.img" into the Image File box. This will be the location where the image will be written. 

Win32 Disk Imager: enter path and filename


Check the box next to Read Only Allocated Partitions.

Win32 Disk Imager: read


Click on the Read button.

A Read Successful dialog box will appear.

Win32 Disk Imager: read successful

The sdcard.img file will be in the path that you indicated in Step 3 above.

Back to Top

Write sdcard.img to e.MMC Flash Memory

In this next section, you will write the sdcard.img file to e.MMC Flash Memory using the SAM-BA In-System Programmer.

Change directory to the location of sdcard.img.

Write sdcard.img to e.MMC Flash Memory using the following SAM-BA host applet command:

$ sam-ba -p serial -b sama7g5-ek -a sdmmc -c write:sdcard.img

Command Window; emmc write sdcard image (1 of 2)

Command Window; emmc write sdcard image (2 of 2)

Console: emmc write sdcard image

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 test the Boot Configuration Packet, including Secure Boot mode, without having to commit permanently to One-Time Programmable (OTP) Memory. In this mode, the one-time programmable memory is emulated by OTPC Emulation Memory.

In production, the Boot Configuration Packet is normally stored in the device’s internal One-Time Programmable (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 and you will have to reissue the above commands to re-enable emulation mode. 

Set Boot Configuration Packet to boot from e.MMC Flash Memory

In this section, you will configure the Boot Configuration Packet to boot from e.MMC Flash 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 e.MMC Flash Memory.

$ sam-ba -p serial -b sama7g5-ek -a bootconfig -c writecfg:bcp-emul:SDMMC0_IOSET1

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) lights up blue. Release the USER BUTTON and the RGB LED will turn off.  

The application uses the PIO Peripheral library to generate 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, you established Console and SAM-BA Host to Monitor communications. Next, you partitioned and formatted an SD memory card and created a bootable image. This image was written to the e.MMC FLash Memory on the SAMA7G54-EK. Then you placed the SAMA7G54 into OTPC Emulation Mode and configured the Boot Configuration Packet to boot from e.MMC Flash Memory. Finally, upon reset, the SAMA7G54-EK boots the MPLAB Harmony v3 application.

Back to Top

Learn More

For training topics on configuring at91boostrap for other Non-Volatile Memories (NVM), see: 

Second-Stage Bootloader at91bootstrap

Writing to Non-Volatile Memory (NVM)

Back to Top