Analog Devices EE231v01 Application Notes

Engineer-to-Engineer Note EE-231
a
Technical notes on using Analog Devices DSPs, processors and development tools
Contact our technical support at dsp.support@analog.com and at dsptools.support@analog.com Or vi sit our o n-li ne r esou rces htt p:/ /www.analog.com/ee-notes and http://www.analog.com/processors
In-Circuit Programming of an SPI Flash with ADSP-2126x SHARC® DSPs
Contributed by Brian M. Rev 1 – March 2, 2004

Introduction

Unlike previous SHARC® DSPs, ADSP-2126x DSPs are able to boot from SPI Flash devices, providing a cheap booting alternative to parallel flash, SPI EEPROM, or host processor schemes. Since the details of the general booting process are discussed in the System Design chapter of the ADSP-2126x SHARC DSP Peripheral Manual [2], this EE-Note describes how to program the desired code or data into the SPI Flash in-circuit.

Default SPI Settings

The defaults of the ADSP-21262 SHARC DSP do not match those supported by most SPI Flash devices. Two issues arise when interfacing an SPI memory device to this DSP: word transfer order and SPI mode.
The ADSP-21262 DSP defaults to transfer words in least significant bit first (LSBF) format, while most SPI memory devices transfer in most significant bit first (MSBF) format. In most applications, this will not be a problem because the SPI of the DSP can be set up to transfer in MSBF format. However, while booting, the word format setting cannot be changed. Therefore, it is necessary to program boot data into the SPI memory device in a bit-reversed manner for devices that support MSBF format only.
There are two ways to transfer bit-reversed words to the flash. The loader tool included with VisualDSP++® 3.0 SP1 has an option to automatically bit-reverse the boot data. The SPI
Master and SPI Prom loader options both use this format. This format should be used only when the SPI memory will be programmed by a dedicated memory programmer (such as those used to program an SPI EEPROM).
Alternatively, it is possible to communicate with the SPI Flash in an LSBF format, while bit reversing the commands to look like they are in MSBF format. For debugging purposes, this format is much easier to read, since this matches the format shown in the VisualDSP++ memory windows. This is the method used in this example.
The other issue is much more problematic, but does not apply to the ST M25P80 SPI flash used in this example. By default, the ADSP-21262 SHARC DSP uses SPI mode 3 (the SPI clock toggles at the start of the first data bit, and the SPI clock is active-low). Some SPI memory devices support SPI mode 0 only, or provide only partial mode 3 support. If the device does not support SPI mode 3 at all, the part can not boot the ADSP-21262 DSP.
If partial support for SPI mode 3 is available (as in the Atmel AT25F512 found on the ADSP­21262 EZ-KIT Lite™ development board), a workaround may be available. For the Atmel part mentioned above, reading from the flash in SPI mode 3 works correctly, but programming to the flash exhibits a bit error on the last word of each page if a certain pattern exists in the previous word. This can be addressed in two ways. The easiest way to avoid this problem is to append a
Copyright 2004, Analog Devices, Inc. All rights reserved. Analog Devices assumes no responsibility for customer product design or the use or application of customers’ products or for any infringements of patents or rights of others which may result from Analog Devices assistance. All trademarks and logos are property of their respective holders. Information furnished by Analog Devices applications and development tools engineers is believed to be accurate and reliable, however no responsibility is assumed by Analog Devices regarding technical accuracy and topicality of the content provided in Analog Devices’ Engineer-to-Engineer Notes.
a
final (8- or 32-bit) word, each bit existing entirely of 1s (0xFF or 0xFFFFFFFF). If this final word wraps around to the beginning of the page, it will not overwrite what was previously programmed there, nor does it waste that word, since the flash cannot overwrite bits that are set to 1 without an erase command. This method is used by the Flash Programmer utility included with VisualDSP++. The alternate method presented herein avoids using problematic words. Since the SPI Flash is programmed on a page-by­page basis, it is possible to shift the position of the starting word to ensure that the offending bit pattern will not be matched. For an example of how to accomplish this, refer to the Atmel SPI Flash Programmer code included with the ADSP-21262 EZ-KIT Lite installation.

Flash Programmer Functions

An SPI flash operates by receiving commands from the Master Out Slave In (MOSI) line, and returning any response on the Master In Slave Out (MISO) line. The following is a quick discussion of the commands implemented in the included example code. The code is attached in the Appendix.

Write Enable (0x06)

This function enables modification to the status register settings or contents of the flash. Since no address or additional data is required, this command is sent directly by the core as a 1-byte, MSBF word. The Write Enable function is called automatically by each function that requires the Write Enable Latch bit in the flash’s status register to be set to function properly. These functions are the Write Status Register, Page Program, and Erase (Bulk and Sector) commands.

Write Disable (0x04)

This function disables modification of the status register settings or the contents of the flash after the Write Enable command has already been
registered. Since no address or additional data is required, this command is sent directly by the core as a 1-byte, MSBF word.

Read Status Register (0x05)

This function fetches the value of the byte-wide status register. It is implemented as a 2-word DMA using a 1-byte MSBF word. The first returned byte corresponds to the command sent from the DSP, and can be ignored. The second returned byte contains the value of the status register placed in the lowest byte of the destination.

Write Status Register (0x01)

This function writes to the byte-wide status register. It is implemented as a 2-word DMA using a 1-byte MSBF word. The first byte sent is the command from the DSP, and second byte is the desired value of the status register. The Write Enable command must be sent before using the this command. Before calling this function, place the desired value of the status register in the second location of the status register buffer. This is the same location that returns the value of the status register in the Read Status Register function. The first location in this buffer is reserved for the command being sent to the device.

Read Data Bytes (0x03)

This function reads any number of words from the flash. The destination address in the DSP's internal memory, the source address in the flash, and the number of 32-bit words to be read are passed to the function using the dedicated memory locations. It is implemented as an N­word DMA using 32-bit LSBF words, where N is the number of words passed to the function. The first word in the destination buffer will be garbage corresponding to the 1-byte command plus 3-byte address that must precede the data (one 32-bit word).
In-Circuit Programming of an SPI Flash with ADSP-2126x SHARC® DSPs (EE-231) Page 2 of 18
a

Page Program (0x02)

This function complements the Read function. The destination address in the flash, source address in the internal memory of the DSP, and number of 32-bit words are passed to this function using the dedicated memory locations.
The flash requires that it be programmed one page at a time. Before being sent to the flash, the buffer referenced in the call is transferred into a temporary buffer corresponding to the page size.
After each page has been sent, the lowest bit in the flash’s status register, Write-In-Progress (WIP), is tested in a loop to determine when the flash has finished programming the new data into memory.
The function included in this example also verifies each page after completing the write by calling the Read Data Bytes function and comparing the result of the call to what was sent. The number of 32-bit words that do not match is tracked.
Because this example programs the flash for booting, which requires LSBF format, both the Read Data Bytes command and the Page Program command use LSBF format. Therefore, the command and address need to be bit-reversed before transfer so that the flash receives them in MSBF format. (This is accomplished using the BITREV instruction. See the ADSP-2126x SHARC DSP Core Reference Manual [1] for more information.)

Sector Erase (0xD8)

This function erases one sector of the flash according to the memory layout in the SPI flash’s data sheet. An address in the sector to be erased is passed to the function with the call. This command uses a 1-byte command and 3­byte address, comprising one 32-bit word. Since the Page Program and Read Data Bytes function use a function that joins the command and address into a single 32-bit word, the Sector Erase command is sent in LSBF format. After
sending the command, the status register is polled until the WIP bit is clear.

Bulk Erase (0xC7)

This function erases the entire flash. No address is passed to this function. Therefore, the function is implemented as a 1-byte command sent in MSBF format. After sending the command, the status register is polled until the WIP bit is clear.

Deep Powerdown (0xB9)

This function puts the flash into a low-power state. Since no address or additional data is required, this command is sent directly by the core as a 1-byte, MSBF word.

Deep Powerdown Release/Electronic Signature (0xAB)

This function returns the flash from the low­power state. It is also used when the flash is not in the low-power state to retrieve the electronic signature of the part. It is implemented as a 5­word DMA using a 1-byte MSBF word. The first byte corresponds to the command from the DSP, and can be ignored. The middle three bytes, which are garbage returned by the flash, can also be ignored. The final byte contains the value of the status register placed in the lowest byte of the destination. For the M25P80, the lowest byte is 0x13.

Generating the Loader File

To generate a loader file compatible with this example, it is necessary to use SPI Slave format. Though it may seem logical to use the SPI PROM format, SPI PROM format produces an image that is bit-reversed. In addition, an SPI PROM only uses a 16-bit address; thus, an extra byte is prepended to the image to make the boot stream compatible with the DSP. For details, refer to the booting section in the ADSP-2126x SHARC DSP Peripheral Manual [2].
In-Circuit Programming of an SPI Flash with ADSP-2126x SHARC® DSPs (EE-231) Page 3 of 18
a

Conclusion

SPI Flash Programmer included with the ADSP­21262 EZ-KIT Lite installation for the
This document provides an example project used
VisualDSP++ development tools.
to program the SPI flash. Each function included in the example is described. To compare this project to a similar example, refer to the Atmel

Appendix

main.asm

/*--------------------------------------------------------------------------------­// // NAME: main.asm (ST SPI Flash) // DATE: 2/20/04 // PURPOSE: Program the SPI Flash for the ADSP-21262 // // USAGE: Use this file to call the chip functions contained in SPIflash.asm. //
---------------------------------------------------------------------------------*/
#include "SPIflash.h"
.global main;
.extern flash_curr_page; .extern sector_base_addr; .extern read_base_addr; .extern read_buffer_addr; .extern read_buffer_length; .extern write_buffer_addr; .extern write_base_addr; .extern write_buffer_length; .extern file_data; .extern file_data_verf; .extern flash_data_out; .extern flash_data_verf; .extern spi_setting; .extern spi_dma_setting; .extern status_register; .extern electronic_signature; .extern curr_command; .extern verf_errors;
.extern write_enable; .extern write_disable; .extern read_status_register; .extern write_status_register; .extern read_data_bytes; .extern read_data_bytes_hs; .extern page_program; .extern flash_program; .extern sector_erase; .extern bulk_erase; .extern deep_powerdown; .extern deep_powerdown_release;
In-Circuit Programming of an SPI Flash with ADSP-2126x SHARC® DSPs (EE-231) Page 4 of 18
.extern setup_spi; .extern setup_spi_dma; .extern wait_for_SPIF; .extern wait_for_WIP; .extern bit_reverse_command;
.section/pm seg_pmco; main: r15=0; r11=0;
// ---------------------------------------­// Choose FLASH algorithms to run here.
// Reset the state of the device with a dummy read call read_status_register;
// Check to make sure that the correct flash is being used // Deep_powerdown_release also reads the electronic signature // of the device. call deep_powerdown_release; r0=dm(electronic_signature+4); r1=0x13; // For ST M25P80, electronic signature is hex13 comp(r0,r1); if EQ jump (pc,2); jump(pc,0);
// Sector erase call // Either use chip_erase for the entire device // or use sector_erase to erase sectors individually // This example uses sector erase. r0=0; // Initialize address of sector to be erased. dm(sector_base_addr)=r0; call sector_erase;
// Bulk Erase Call // call bulk_erase;
// Write to FLASH // The flash_program subroutine requires the user to pass: // write_base_addr - the base address to write to in the SPI Flash // write_buffer_addr - the address of buffer holding the data to program // write_buffer_length - the length of the buffer to program in 32-bit words // This routine also returns a number of errors encountered in the programming // process. // This is stored in the verf_errors with units in 32-bit words. r0=0; // Address to write to in the flash dm(write_base_addr)=r0; r0=file_data; // Address of the buffer to write from the DSP dm(write_buffer_addr)=r0; r0=@file_data; // Length of the buffer to write from the DSP dm(write_buffer_length)=r0; call flash_program;
// Read from FLASH // The read_data_bytes subroutine requires the user to pass: // read_base_addr - the base address to write to in the SPI Flash // read_buffer_addr - the address of buffer holding the data to program // read_buffer_length - the length of the buffer to program in 32-bit words
a
In-Circuit Programming of an SPI Flash with ADSP-2126x SHARC® DSPs (EE-231) Page 5 of 18
r0=0; // Address to read from in the flash dm(read_base_addr)=r0; r0=file_data_verf; // Address of the buffer to read from in the DSP dm(read_buffer_addr)=r0; r0=@file_data_verf; // Length of the buffer to read from in DSP dm(read_buffer_length)=r0; call read_data_bytes;
// ---------------------------------------­// Use FLAGS to show that the process completed. // Indicate whether the process was error-free r0=dm(verf_errors); r0=pass r0; if ne jump error_detected; BIT SET FLAGS 0xAAAAAAAA; BIT SET FLAGS 0x55555555; main.end: jump(pc,0);
error_detected: BIT SET FLAGS 0xAAAAAAAA; BIT CLR FLAGS 0x55555555; error_detected.end: nop; jump(pc,0);
Listing 1. main.asm
a

buffers.asm

/*---------------------------------------------------------------------------------
// NAME: buffers.asm (ST SPI Flash) // DATE: 2/20/04 // PURPOSE: Program the SPI Flash for the ADSP-21262 // // USAGE: This file contains the buffer declarations for use in this project. //
---------------------------------------------------------------------------------*/
#include "SPIflash.h"
.global flash_curr_page; .global sector_base_addr; .global read_base_addr; .global read_buffer_addr; .global read_buffer_length; .global write_buffer_addr; .global write_base_addr; .global write_buffer_length; .global file_data; .global file_data_verf; .global flash_data_out; .global flash_data_verf; .global spi_setting; .global spi_dma_setting; .global status_register; .global electronic_signature; .global curr_command;
In-Circuit Programming of an SPI Flash with ADSP-2126x SHARC® DSPs (EE-231) Page 6 of 18
Loading...
+ 12 hidden pages