SAMA7G54-EK – Writing MPLAB® Harmony v3 Application and at91bootstrap to e.MMC Flash Memory using SAM-BA® ISP
- Introduction
- Prerequisites
- Hardware
- Embedded MultiMediaCard (e.MMC) Flash Memory
- Setup Console Serial Communications
- Setup SAM-BA Host to Monitor Communications
- Create Image File
- Write sdcard.img to e.MMC Flash Memory
- Enable OTPC Emulation Mode
- Set Boot Configuration Packet to boot from e.MMC Flash Memory
- Run MPLAB Harmony v3 Application on the Target
- Summary
- Learn More
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:
- SAMA7G54-EK – Configure and Build at91bootstrap to Load a MPLAB® Harmony v3 Application from e.MMC Flash Memory
- SAMA7G54-EK – Getting Started with MPLAB® Harmony v3 Development: CSP Application: pio_led_on_off_interrupt
Prerequisites
- SAMA7G5 Series Boot Process
- SAMA7G5 Series Data Sheet 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
Setup the SAMA7G54-EK as listed below to the host computer running 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 memory card slot (J4).
Power
- Apply power as shown in the “Power Options” section of the “SAMA7G54-EK - Features” page.
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.
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.
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).
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.
Partition SD Memory Card with DiskPart Utility
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.
Type the command: select disk n where “n” is the SD memory card.
Type the command: list partition
Observe the partitions on the SD memory card. Identify the partition(s).
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.
Type the command: delete partition
The selected partition will be deleted.
Type the command: create partition primary size=4
Format SD memory card 4 MB Partition.
The DiskPart command below will format the partition in the FAT file system:
Type the command: format
Create Image with Win32 Disk Imager Utility
Select the drive letter of the SD memory card under the Device drop-down menu.
Enter the path and the filename "sdcard.img" into the Image File box. This will be the location where the image will be written.
Check the box next to Read Only Allocated Partitions.
Click on the Read button.
A Read Successful dialog box will appear.
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.
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
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.
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.
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.
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
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.
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.
Learn More
For training topics on configuring at91boostrap for other Non-Volatile Memories (NVM), see:
Second-Stage Bootloader at91bootstrap
- SAMA7G54-EK – Configure and Build at91bootstrap to Load a MPLAB® Harmony v3 Application from NOR Flash (QSPI) Memory
- SAMA7G54-EK – Configure and Build at91bootstrap to Load a MPLAB® Harmony v3 Application from SD Memory Card
Writing to Non-Volatile Memory (NVM)