Write on QuadSPI memory with SAM-BA

SAM-BA® is a programming tool for the Microchip MPUs/MCUs. This article illustrates how to use it to transfer the at91bootstrap bootloader on the QuadSPI memory mounted on the RoadRunner SOM

SAM-BA is freely downloadable in two versions:

  • A graphicaly version called SAM-BA 2.16
  • A pure command line version called SAM-BA 3.1.4

In this article we refer to the command line version that is the only version compatible with the QuadSPI memory used on the RoadRunner module. We will illustrate the use of the Linux version but probably the Windows version will work in the same way.

Installation

Open the SAM-BA web site and download the package: SAM-BA 3.1.4 Package for Linux 64-bits or 32-bits.

Uncompress the tar.gz file:

$ tar xvzf sam-ba_3.1.4-linux_x86_64.tar.gz

Download and save, inside the directory just created by tar, this file:

QML is a scripting language to give istructions to SAM-BA on how and what tranfer inside the QuadSPI memory and much more.

SAM-BA can be used only when on the MCU is running RomBOOT. When the CPU is running other codes like at91bootstrap, uboot or linux it is completely unuseful.

RomBOOT is the first piece of code running by the MCU at startup. It is burned directly by Microchip factory inside the ROM MPU.

At startup RomBOOT looks for a bootable code from any external memory memories available, if nothing is available, it waits for any serial commands incoming from the USB device port or from the serial debug port this is the way used by SAM-BA to talk with RomBOOT.

The RoadRunner with QuadSPI on board (Model Q16/Q128/Q256) are already programmed to boot from QuadSPI. The default code put on it is at91bootstrap.

In case you want to reflash it just press the push-button BOOTOFF on the Berta D2 board and the press the RESET botton to restart the MPU.

In this situation a new USB device is announced on the USB port of your PC:

$ lsusb
...
Bus 002 Device 004: ID 03eb:6124 Atmel Corp. at91sam SAMBA bootloader
...

and a new serial device is available with the name /dev/ttyACM0:

$ dmesg
...
[ 4676.045662] cdc_acm 2-2.1:1.0: ttyACM0: USB ACM device
[ 4676.046800] usbcore: registered new interface driver cdc_acm
[ 4676.046803] cdc_acm: USB Abstract Control Model driver for USB modems and ISDN adapters
...
$ ls -al /dev/ttyACM0
crw-rw---- 1 root dialout 166, 0 Aug  2 12:53 /dev/ttyACM0

The device name /dev/ttyACM0 is used inside roadrunner.qml script.

Save the at91bootstrap.bin file inside the SAM-BA directory and launch SAM-BA with this command:

$ ./sam-ba -x roadrunner.qml

Notes about SAM-BA Applet customization

An applet is a small program which is used by SAM-BA in order to be able to program non-volatile memories, low-level initialization, or other peripherals. For each Microchip AT91SAM device, there is one dedicated applet to each external memory device the chip can deal with. Each applet contains the programming algorithm for its dedicated memory. This article illustrates how to compile it to add new memory type or just to check the memory already implemented by the Microchip team.

I wrote this article as personal notes during my tests to add the 256MB QuadSPI flash avaiable on the RoadRunner Q256 module. More info about SAM-BA and te Applet are available from this Microchip doc:

These procedure has been tested on Linux Ubuntu version 16.04.2

The Microchip Software package

The SAMA5D2 software package consists of microcontroller drivers, software services and libraries. Each software module is provided with full source code, examples of usage, rich html documentation and ready-to-use projects for the GNU GCC and IAR EWARM compilers.

Instal the Microchip Software package on your Linux PC

Clone the Microchip Software Package repository from GitHub:

$ git clone https://github.com/atmelcorp/atmel-software-package.git
$ cd atmel-software-package
$ git checkout tags/v2.5

Download the GNU ARM Embedded Toolchain for Linux:

Move to the Applet source directory you need to change:

$ cd samba_applets/qspiflash

Try the Applet compilation:

$ make TARGET=sama5d2-generic RELEASE=1 CROSS_COMPILE=~/gcc-arm-none-eabi/bin/arm-none-eabi-

Copy the executable file to sam-ba directory where is located the old Applet binary file:

$ cp build/applet-qspiflash_sama5d2-generic_sram.bin  ~/roadrunner/sam-ba_3.1.4/qml/SAMBA/Device/SAMA5D2/applets

Enable the applet qspiflash to manage new QuadSPI chips

Enable the 256MByte QuadSPI used on RoadRunner Q256:

Edit the file atmel-software-package/samba_applets/drivers/memories/spi-nor.c at row 69 and add this line:

Launch the Applet compilation:

$ make TARGET=sama5d2-generic RELEASE=1 CROSS_COMPILE=~/gcc-arm-none-eabi/bin/arm-none-eabi-

Copy the executable file to sam-ba directory where is located the old Applet binary file:

$ cp build/applet-qspiflash_sama5d2-generic_sram.bin  ~/roadrunner/sam-ba_3.1.4/qml/SAMBA/Device/SAMA5D2/applets

How to set the trace level debug

Five level of debug messages are available (https://github.com/atmelcorp/atmel-software-package/blob/master/utils/trace.h#L35)

/// !Trace level description
/// -# TRACE_DEBUG (5): Traces whose only purpose is for debugging the program, 
///    and which do not produce meaningful information otherwise.
/// -# TRACE_INFO (4): Informational trace about the program execution. Should  
///    enable the user to see the execution flow.
/// -# TRACE_WARNING (3): Indicates that a minor error has happened. In most case
///    it can be discarded safely; it may even be expected.
/// -# TRACE_ERROR (2): Indicates an error which may not stop the program execution, 
///    but which indicates there is a problem with the code.
/// -# TRACE_FATAL (1): Indicates a major error which prevents the program from going
///    any further.

To set the trace level add this file in samba_applets/qspiflash/Makefile:

TRACE_LEVEL = 5

Then compile the applet.

Debug messages

QuadSPI 16MB

Applet 'QSPI Flash' from softpack 2.5 (v2.5-dirty).
Initializing QSPI0 IOSet3 at 66000000Hz
-D- ../../drivers/memories/qspiflash.c:722 Trying protocol 0 opcode 0x9f
-D- ../../drivers/memories/qspiflash.c:737 Found memory with JEDEC ID 0x0018ba20.
-D- ../../drivers/memories/qspiflash.c:757 Found supported memory with JEDEC ID 0x0018ba20 (N25Q128A).
-D- ../../drivers/memories/qspiflash.c:315 QSPI Flash: Micron Quad mode disabled, will enable it
Found Device N25Q128A
Size: 16777216 bytes
Page Size: 256 bytes
Supports 4K block erase
Supports 64K block erase
Buffer Address: 0x00228020
Buffer Size: 98048 bytes
QSPI applet initialized successfully

QuadSPI 64MB

Applet 'QSPI Flash' from softpack 2.5 (v2.5-dirty).
Initializing QSPI0 IOSet3 at 66000000Hz
-D- ../../drivers/memories/qspiflash.c:722 Trying protocol 0 opcode 0x9f
-D- ../../drivers/memories/qspiflash.c:722 Trying protocol 6 opcode 0xaf
-D- ../../drivers/memories/qspiflash.c:737 Found memory with JEDEC ID 0x0020ba20.
-D- ../../drivers/memories/qspiflash.c:757 Found supported memory with JEDEC ID 0x0020ba20 (7RA17RW181).
-D- ../../drivers/memories/qspiflash.c:311 QSPI Flash: Micron Quad mode already enabled
Found Device 7RA17RW181
Size: 67108864 bytes
Page Size: 256 bytes
Supports 4K block erase
Supports 64K block erase
Buffer Address: 0x00228040
Buffer Size: 98048 bytes
QSPI applet initialized successfully.

QuadSPI 256MB

Applet 'QSPI Flash' from softpack 2.5 (v2.5-dirty).
Initializing QSPI0 IOSet3 at 66000000Hz
-D- ../../drivers/memories/qspiflash.c:722 Trying protocol 0 opcode 0x9f
-D- ../../drivers/memories/qspiflash.c:737 Found memory with JEDEC ID 0x0022ba20.
-D- ../../drivers/memories/qspiflash.c:757 Found supported memory with JEDEC ID 0x0022ba20 (MT25Q02G).
-D- ../../drivers/memories/qspiflash.c:315 QSPI Flash: Micron Quad mode disabled, will enable it
Found Device MT25Q02G
Size: 268435456 bytes
Page Size: 256 bytes
Supports 4K block erase
Supports 64K block erase
Buffer Address: 0x00228040
Buffer Size: 98048 bytes
QSPI applet initialized successfully.

How to generate test pattern

dd bs=1K count=64 < /dev/urandom > test64KB.bin
dd bs=1M count=16 < /dev/urandom > test16MB.bin
dd bs=1M count=64 < /dev/urandom > test64MB.bin

Links

Sergio Tanzilli
System designer and Acme co-founder
Personal email: tanzilli@acmesystems.it
Webpages: https://www.acmesystems.it - http://www.tanzolab.it - http://www.tanzilli.com
Github repositories: https://github.com/tanzilli and https://github.com/acmesystems