PE Serial SPI Memory Programming For ARM Devices
PE Serial SPI Memory Programming For ARM Devices
PE Serial SPI Memory Programming For ARM Devices
1
2 Serial Peripheral Interfaces. ............................................................................... 1
3 SPI Serial Memory Devices................................................................................ 2
4 P&E’s Serial SPI Algorithms............................................................................... 3
5 Hardware Setup ................................................................................................. 5
6 Algorithm Configuration...................................................................................... 6
6.1 Identification Section ....................................................................................................... 6
6.2 Turn Off Watchdog Timer Section ................................................................................... 6
6.3 Set Up System Clock and Frequency Section ................................................................ 7
6.4 Clock Distribution / Power Section .................................................................................. 7
6.5 Write Protect and Hold Section ....................................................................................... 7
6.6 Ports and Direction Section............................................................................................. 7
6.7 Port Addresses and Pin Number Section ........................................................................ 7
6.8 Programmer Control Section ........................................................................................... 8
6.9 Test Pattern Command Section ...................................................................................... 9
6.10 Disable Protection Command Section............................................................................. 9
6.11 Write Status Command Section .................................................................................... 10
6.12 Block Erase Commands Section ................................................................................... 10
6.13 S-Record Code Section................................................................................................. 10
6.14 Checksum Section ........................................................................................................ 11
7 Algorithm Header Setup Examples .................................................................. 11
7.1 Freescale PKL25Z128VLK4 / Atmel AT25640B............................................................ 11
7.2 Texas Instruments® LM3S301 / Atmel AT25F1024...................................................... 13
7.3 Freescale K20DX128VFM5 / Adesto AT45DB161E-512 .............................................. 15
7.4 Toshiba TMPM364F10FG / Adesto AT25DF041A ........................................................ 17
7.5 NXP® LPC1769 / Adesto AT25DL081 .......................................................................... 19
7.6 STMicroelectronics® STM32F207 / ST 95M02............................................................. 21
7.7 Spansion MB9AF312 / Spansion S25FL164K .............................................................. 22
7.8 Standalone Programming..............................................................................................25
8 Conclusions...................................................................................................... 27
9 P&E’s ARM Hardware Interfaces ..................................................................... 28
9.1 P&E’s Cyclone for ARM® devices................................................................................. 28
9.2 P&E’s USB Multilink Universal FX................................................................................. 28
10 P&E’s ARM Programming Software................................................................. 30
10.1 P&E’s PROG for ARM devices...................................................................................... 30
10.2 Library Routines for ARM® Cortex™-M processors ARM Cortex Library Routines...... 31
11 Contact P&E..................................................................................................... 31
12 References ....................................................................................................... 32
Historically, the SPI interface has been used to transfer a single bit per clock pulse, to and from the master and
slave. Recently the SPI interface has been expanded to provide for multiple bits to be transferred on a single
clock pulse. These interfaces are called Dual and Quad SPI.
Both the 8- and 16-bit packages can support Dual and Quad SPI transfers. However, all Flash and EEPROM
devices can be programmed using just single-bit SPI transfers. The Dual and Quad SPI interfaces use
different commands than the single SPI interface when programming the devices. The Dual and Quad SPI
provide for higher-speed transfers, but as stated, all serial devices can be programmed using the single SPI
configuration, even though the device is capable of either Dual or Quad communications. Notice that both the
8- and 16-pin packages have a common set of signals:
• /CS - Not Chip Select, active low, connected to /SS of the microcontroller
• D0 - Data Output, connected to MISO of the processor/microcontroller
• /WP - Not Write Protect, active low, pulled high during programming
• GND - Ground
• VCC - Power, voltage dependent on chip type
• /HOLD - /RESET on some parts, active low, pulled high during programming
• CLK - Clock, connected to SCLK of the processor/microcontroller
• DI - Data Input, connected to MOSI of the processor/microcontroller
• IO1, IO0 - Alternate designations used by Dual and Quad SPI devices
The master processor/microcontroller programs the slave Flash/EEPROM slave device by sending a set of
commands, addresses, and data to the slave. The processor/microcontroller reads the slave Flash/EEPROM
device by sending a command and address to the slave and receiving back data. The commands used and
their sequences are dependent on the particular Flash/EEPROM device and vary by manufacturer. In addition,
there are commands, usually called page, sector, or block erase, that erase the entire Flash/EEPROM or
erase only certain subdivisions of the flash. Names of the subsections of the flash vary greatly between
different manufacturers. To prevent confusion, P&E uses the terms “A Blocks”, “B Blocks” and, “C Blocks”
which are defined by quantity and block size in each individual programming algorithm. Many Flash/EEPROM
devices such as the GigaDevice GD25Q10 [2.], have A Blocks which are uniform 4K bytes, B Blocks which are
uniform 32K bytes, and C Blocks which are uniform 64K bytes.
If you set up an algorithm to run on the particular microcontroller configuration, P&E suggests that you append
the name of the microcontroller to the source file name to indicate this change. This is important since you may
use the same algorithm in different microcontroller setups.
The header has additional information about the part to be programmed and its size. In addition, the header
has sections where the user inputs information used in configuring the part for their application. The header is
readable using a standard ASCII text editor/reader. For example, the range of parameters for different
commands is usually specified with comments in the header file.
The header may include descriptions of up to three block erasing commands. When a block erase command is
selected, it prompts the user for a beginning block number and an ending block number. Block numbers are
input by the user in hex. These block numbers must range between zero and the total number of blocks -1. For
example, if there are 32 blocks the user could assign beginning and ending block numbers from 0-1F.
This command will erase all blocks between the selected beginning block number and ending block number,
inclusive. The programming software translates these hex block numbers into addresses used to erase the
corresponding blocks in the device. A part’s block numbers are described in the manufacturer’s part
specification sheet for the part and in a comment line just before the erase command. The header, shown
below in blue, uses the erase commands and block structure for the GigaDevice GD25Q10 device [2.].
The S-Records contain the code and constant data for the programming algorithm which gets loaded into the
RAM of the target ARM microcontroller. The S-Records appear at the end of the algorithm file as indicated
below.
5 Hardware Setup
For consistency and ease of operation, P&E’s programming approach does not use any special on-chip
hardware on your microcontroller. Instead, it assumes that your SPI serial memory device is connected to port
pins of your microcontroller and a bit-banging algorithm is used to program the SPI memory device. This
means you do not have to setup the SPI module of your microcontroller, but instead setup your port pins as if
for normal GPIO operations. This is not a problem if you used internal microcontroller SPI hardware in your
design. All port pins associated with the on-chip hardware are also configurable as I/O port pins. It is
necessary to insert, in the programming algorithm header, definitions of which ports and port pins are used to
connect your SPI serial memory to the microcontroller. This is accomplished by specifying the port addresses
and pin numbers.
Port pins must be configured in the algorithm header with the correct direction, either input or output. The
default direction of the I/O port pin may be incorrect for the associated SPI signal. For example, the MOSI
signal needs to be configured as an output, and the MISO needs to be configured as an input. If the port pin
direction is not properly configured, the transmission will be unsuccessful.
If necessary, any watchdog timers which are running after a reset need to be turned off by putting appropriate
statements in the algorithm’s header. For many microcontrollers this is not necessary since the watchdogs are
not enabled after a reset. Some watchdogs can be disabled by a simple write to a memory register. In some
circumstances, code must be run on the microcontroller to disable watchdog. A provision is made to do this
within the header of the algorithm.
On some microcontrollers it is necessary to supply power or clock to some submodules before they can be
used. This is accomplished by simple memory writes inserted in the header of the algorithm file.
Although it is not necessary, it may be desirable to set up the PLL (phase locked loop) or FFL (frequency
locked loop) of the microcontroller since the data transfer rate between the microcontroller and the serial
memory device increases with processor CPU clock speed. Completing this setup can significantly reduce the
programming time for large serial memory devices. However, this setup is usually not worth the effort for small-
to-medium serial memory devices. As mentioned later in this manual, it is important to note that in some cases
the clock that is output to the serial device may actually be too fast. In this case you must slow down the serial
clock so it does not exceed the maximum clock allowed for the serial device.
Before attempting to erase or program your SPI memory device, it may be necessary to un-protect the device.
Please refer to the documentation with your SPI memory device for more details on how to do this.
This is all that is needed to set up a particular device-programming algorithm for your microcontroller-based
hardware configuration. At first this may seem a little daunting, however if you look at the examples in this
manual you will see that it is relatively straightforward. If you have any problems getting your setup to work,
create a Support Request via P&E’s website. If necessary, P&E can configure an algorithm for your hardware.
You will need to provide the processor pins you are using, the name of the microcontroller, and the name of the
serial memory device you are using. If you supply P&E with a test board, we can guarantee that it works
properly.
WRITE_LONG=dddddddd/aaaaaaaa/
WRITE_WORD=dddd/aaaaaaaa/
WRITE_BYTE=dd/aaaaaaaa/
SET_PC_AND_RUN=aaaaaaaa/
DELAY=dddd/
These memory writes should begin in column 1 and not be preceded by any other characters. Comments can
be added at the end of the memory writes lines by proceeding them with a ; character (semicolon).
;end_cs represents the end of the chip set up area. The rest of the statements are needed by the
programming software to set up proper operation for programming serial SPI memory devices and to assure
that the necessary revision of the programming software is being used.
These statements are used to tell the PROG software how to set itself up to properly talk to the microcontroller
and the attached SPI device. If you remove or change these statements, the programming algorithms will not
operate properly.
REQUIRES_PROG_VERSION=5.00/
This is the revision number of P&E's programming software that is required for this algorithm to operate
properly. If you have an earlier version number you should contact P&E to upgrade your programming
software.
NO_TIMING_TEST
This tells the programming software that it is not required to test the speed at which the Microcontroller is
running.
PROGRAMMING_ALSO_DOES_VERIFY
This tells the programming software to put a message on the screen that programming also just a verify the
data as it is programed. This is always the case for serial flash devices and hence it is not necessary to do a
separate verify unless It is required to double-check the programming operation.
NO_BASE_ADDRESS
This specifies that addressing always starts at address 0 within the serial memory device.
Some SPI flash devices, such as the Atmel/Adesto 45DBxxx series, have special 4-byte commands which
may not be implemented in P&E’s standard programming algorithms. The test pattern command can be used
to implement these commands. Even though the test pattern command always sends four bytes, it can be
used to implement commands with less than four bytes. Simply send the command bytes first, followed by
either FF (or 00) bytes. FF (or 00) bytes are not valid commands for SPI memory devices and hence they are
ignored. For example, to send a typical write enable command (0x06) followed by a typical chip erase
command (0xC7), use the following test commands with a repeat 1 time for each: 06FFFFFF followed by
C7FFFFF. The reason that these commands need to be in separate test pattern commands is that both
commands need to be separate transmissions with the chip select framing each separate transmission. Note
that on most serial SPI parts you must do a write enable command before you can do a chip erase command.
On most devices, protection is turned off by writing 0 to the status register. However, some devices such as
45DBxx require a special sequence. This command uses the type of diable protection needed for the particular
device.
; Disable Sector Protection.
USER=DP Disable Protection 0 /00000000/00000000/
;;
Warning: P&E does not automatically turn off protection because in some circumstances it may
be required to leave certain sections protected.
Shown below is the original Atmel AT25640B header in blue. The changes made to attach to the MKL25Z128
microcontroller are shown in red. First, the watchdog is disabled. Then the internal clock oscillator is set up for
48 MHz. The clock is turned on for Port C. The address of Port C and the pin numbers are provided for all 4
SPI pins. All the SPI signals are on the same port. However, the output bit port address is different than the
input bit port address since, on this microcontroller, the same port is read and written at different addresses.
The Port C Data Direction Register (DDR) is set up for the bits which are outputs. P&E’s programming
software can now use this algorithm to talk to the KL25Z microcontroller with an Atmel AT25640B serial SPI
EEPROM attached as indicated.
Before trying to program or erase this serial device you should unprotect it by writing 00 hex to the status
register protection bits using the WS (Write Status) USER Command.
Actual measurements indicate that the bit rate between the microprocessor and the EEPROM is approximately
1.86 MegaBits per second. Since there is a small overhead delay between bytes, the actual byte rate turns out
to be approximately 204 KiloBytes per second.
;version 1.00, 03/15/2014, Copyright P&E Microcomputer Systems, www.pemicro.com
;device Atmel, AT25640B, 8x8k, proc=Freescale_Freedom_MKL25Z128VLK4, desc=sw_spi
;begin_cs device=$00000000, length=$00002000, ram=$20000000
;
;******************************************************************************
;Disable Watchdog Timer, if one exists and is enabled at Reset
WRITE_LONG=00000000/40048100/ ;SIM_COPC=0
;
;******************************************************************************
;Set up system clock source and frequency if different from defaults
WRITE_BYTE=A0/40064003/ ;MCG_C4 48MHz
;
;******************************************************************************
;Turn on clock distribution and power to needed microcontroller modules
WRITE_LONG=00040982/40048038/ ;scgc5=portc clock on
;
;******************************************************************************
;Set up serial part /WP and /HOLD to the inactive high state if necessary
;
;******************************************************************************
;Set up Ports, Data Direction, and Mapping as necessary
WRITE_LONG=00000143/4004B008/ ;Set pin as port ptc2 - /ss
WRITE_LONG=00000143/4004B014/ ;Set pin as port ptc5 - clk
WRITE_LONG=00000143/4004B01C/ ;Set pin as port ptc7 - sdi
WRITE_LONG=00000143/4004B018/ ;Set pin as port ptc6 - sdo
WRITE_LONG=00000064/400FF094/ ;Set portc pins 2, 5, and 6 as outputs
On this microcontroller it is not necessary to turn off the watchdog timer since it is off after a reset. The PLL is
set up for 100 MHz. There is a 1ms delay included to allow time for the PLL to stabilize before it is selected as
the system clock. The clock is enabled for Port F and is used to connect to the external SPI EEPROM. The
output pins are then configured for the SPI outputs on Port F. Finally, the port pin addresses and the pin
numbers are established. You can see that this is a very simple set up which would be even simpler if the PLL
was not used.
Before trying to program or erase this serial device, you should unprotect it by writing 00 hex to the status
register protection bits using the WS (Write Status) USER Command.
File Spansion.bat
C:\pemicro\progacmp\CPROGACMP ? Spansion.cfg bdm_speed 20 interface=USBMULTILINK port=USB1
File Spansion.cfg
:device=NXP ;Select Mfg Interface
:useswd 1 ;Select SDI
CM Spansion_MB9AF312K_1x16x64k.arp ;Select Algorithm
SS 128k.s19 ;Select Micro Data File
EM ;Erase Micro
PM ;Program Micro
CM Spansion_S25FL164K_8x8Meg_Spansion_MB9AF312_sw_spi.arp ;Select SPI Algorithm
SS 1meg.s19 ;Select SPI Data File
WS 00 ;Disable SPI Protection
PM ;Program SPI Device
Running the batch file produces the following output. Notice that both the microcontroller and the attached SPI
REM>
CM C:\PEMicro\cyclone_arm\Adesto_AT45DB161E-512_8x2Meg_sw_spi.arp
- This command selects the algorithm created in Section 7.3 - Freescale K20DX128VFM5 / Adesto
AT45DB161E-512.
SS C:\PEMicro\cyclone_arm\1MB_base_0.s9
8 Conclusions
P&E’s approach to production programming of SPI memory devices allows you to use our tools on any of your
designs. Even those designs which have the SPI memory connected to whatever pins you had left over to
implement the SPI interface can easily be set up and programmed in a universal manner. Using P&E’s tools,
you can program the internal microcontroller memory and the external SPI memory in one simple
manufacturing step. Even though the algorithms with the SPI memory are implemented with the bit banging
software, they run fast enough to not slow down the manufacturing process. From the examples above we see
that the transfer speed from the microcontroller to the serial SPI memory is typically faster than the transfer
speed from the host processor microcontroller via the SWD/JTAG interface. In addition, the actual
programming time on the SPI devices is greater than the data transfer. The following table derived from the
prior examples indicates very reasonable data transfer times over the Bit Bang SPI interface. These measured
numbers are only approximate since internal clocks and PLLs were used.
~Freq ~KByte
Ex Micro SPI memory ~MBit/S ~KByte/S
MHz /S/MHz
The speeds shown vary somewhat by the particular microcontroller implementation, accuracy of the clock,
By connecting to a debug header on the target, the Cyclone can program internal memory on an ARM Cortex-
M processor. SWD/JTAG protocol is used for programming, which requires only 2 pins. The processor or
memory device can be mounted on the final printed circuit board before programming.
The Cyclone may be operated interactively via Windows based programming applications as well as under
batch or dll commands from a PC. Once loaded with data by a PC it can be disconnected and operated
manually in a completely stand-alone mode via the LCD menu and control buttons. The Cyclone has over
7Mbytes of non-volatile memory, which allows for the onboard storage of multiple programming images. When
connected to a PC for programming or loading it can communicate via the ethernet, USB, or serial interfaces.
The Cyclone comes with intuitive configuration software, as well as easy to use automated control software.
Support is currently available for various ARM Cortex devices - you may view a list of supported devices by
clicking here.
Click to view P&E's Cyclone for ARM User Manual.
The USB Multilink Universal FX includes all the features of P&E's standard Multilink interfaces, plus these
additional benefits:
• Lightning fast! Up to 10X faster communications speed than P&E's other Multilinks
• Can provide power to the target MCU
• I/O line clamping for added protection
By using the USB Multilink Universal FX, the user can take advantage of the background debug mode to halt
normal processor execution and use a PC to control the processor. The user can then directly control the
target’s execution, read/write registers and memory values, debug code on the processor, and program
internal or external FLASH memory devices. The USB Multilink Universal FX can also provide power to your
target MCU, either 3.3V or 5V.
The USB Multilink Universal FX is natively supported by all current P&E software applications, and tool chains
from many P&E partners including Freescale .IAR, Keil, Cosmic, Atollic, and Green Hills (check with the
vendor for device compatibility). A list of supported software can be found here.
For many of the supported processors, P&E has a set of interface libraries allowing the user to write their own
Windows-based application which interacts with P&E's debug interface.
This interface is USB 2.0 compatible, and it is also backwards compatible with USB 1.1 ports.
NOTE: For production usage, see either the Cyclone PRO or Cyclone MAX standalone programmer and
debug interface, depending on which processor you are working with. A comparison chart is available below to
help you choose the appropriate interface.
FEATURES:
• High-speed USB interface from PC to Multilink allows for fast, easy programming and debugging -
- with the ease and compatibility of the USB interface.
• Draws power from USB interface-- no separate power supply required (draws less than 1mA from
the target).
• Can be used to power target MCU.
• Target Voltage: 1.6V-5.25V
PROG for ARM Cortex processors also includes the command-line version of the programmer software.
CPROGACMP. Together they are perfect for development, production line programming, or field firmware
upgrades.
In addition, the programmer comes with P&E's entire library of ARM programming algorithms.
P&E has a resource page describing different methodologies for programming target flash in both
development and production environments: Flash Programming Resource Page
10.2 Library Routines for ARM® Cortex™-M processors ARM Cortex Library Routines
The software package consists of an interface DLL and sample code which allows a custom application to be
built which can interact with and debug an ARM® Cortex™-M processors (ACMP) based system via one of
P&E's hardware interfaces. This includes Freescale's Kinetis® and other vendor’s devices. The package
includes both C/C++ and Delphi example routines as well as detailed calling information for the DLL/SO. The C
and Delphi modules in the ACMP Hardware Interface Library Routines come as source code which interfaces
with a DLL/SO to interface to the hardware. The ACMP Hardware Interface Library Routines library are very
useful for building your own custom application to do such functions as product test, calibration, and update.
The demo programs included in the package show you how to initialize the interface, program registers,
download code to RAM and step through code. Starting with these programs it is easy to customize them to
your specific requirements. Applications created with the included 32-bit .DLL will also operate on the 64-bit
operating systems listed below under System Requirements.
Read more about simplifying product testing in P&E's Expert's Corner.
Key Features:
• Works with ARM Cortex-M devices, including the Kinetis L-Series
• Works through P&E's USB Multilink Universal, USB Multilink Universal FX, and Cyclone for ARM
• Provides Interface to Background Debug Mode
• Included in the package are C/C++ and PASCAL modules
• Source and executables provided for both C and PASCAL demos
• Compilers supported:
• UNITACMP and UNITACMP_DIST: MicrosoftVisual C++ 5.0 or greater, Delphi 2.0 or greater
• Development platform: Windows 32-bit, Windows 64-bit (XP, Vista, 7).
• Very useful for building production line testers
Learn more about customer test applications in P&E’s resource guide. (link)
UNITACMP includes a license to distribute the binaries (DLL/so and Drivers) of UNITACMP to up to five target
PCs subject to the conditions of the license agreement. For a license to distribute to an unlimited number of
PCs, see UNITACMP_DIST.
11 Contact P&E
P&E Microcomputer Systems, Inc.
98 Galen St – 2nd Fl.
Watertown, MA 02472-4502, USA
www.pemicro.com
12 References
1. Winbond Electronics Corp, W25Q256FV SPIFLASH Data Sheet
2. GigaDevice. GD25Q10 Data Sheet
3. P&E Microcomputer Systems, PROGACMP User Guide
4. Atmel , AT25640B SPI Serial Memory Date Sheet
5. Freescale, KL25 Sub-Family Reference Manual
6. Freescale, FRDM-KL25Z User's Manual
7. Atmel , AT25F1024 SPI Serial Memory Date Sheet
8. Texas Instruments, Stellaris® LM3S301 Microcontroller Data Sheet
9. Texas Instruments, Stellaris® Family Development Board Users Manual
10. Freescale, K20 Sub-Family Reference Manual
11. Toshiba, TMPM364F10FG Data Sheet
12. Keil, Toshiba MCBTMPM364 Evaluation Board
13. NXP, LPC176x/5x User manual
14. Embedded Artists, LPCXpressoLPC1769revB Development Board
15. ST Microelectronics, STM32F207 microcontroller reference manual
16. ST Microelectronics, STM3220F-EVAL board manual
17. Spansion S25FL164K, 64 Mbit (8 Mbyte) CMOS SPI Flash Memory
18. Spansion MB9AF312 Microcontroller Specification
19. Spansion SK-FM3-48PMC-USBSTICK, MB9AF312 Eval Board
20. P&E Microcomputer Systems CPROGACMP User Guide