Introduction
This knowledge base article is intended to provide guidelines for programming a sector in the SPI Flash M25P32 in the SPI Flash Demo Board using the Cheetah adapter and Flash Center.
Overview
Using the Aardvark I2C/SPI Host Adapter or the Cheetah SPI Host Adapter with the Flash Center software makes it extremely easy to program EEPROM and flash devices. With one click the user can erase, program, and verify an entire device. But what if you only need to program a single sector of a flash memory? This article explains how to use Flash Center to modify a single sector of the device, while not affecting the other sectors.
It's first helpful to understand the different programming options provided by Flash Center. Specifically, there are three programming modes: Program + Verify, Program, and Program (No Erase).
- Program + Verify - Writes data to one or more attached memory devices and then reads back the data to verify it for correctness. If the device is an SPI Flash, an erase cycle will be performed first. The erase will cover only those sectors which will be written. Note that it is possible to erase more data than is written if a write ends in the middle of a sector. A warning will be logged if this is the case. Also, if the data to be written is large enough to require the entire device to be erase, and the memory device has an “erase all” instruction, the software will use the “erase all” instruction.
- Program - Writes data to the device, but does not perform the verification step. If the device is an SPI Flash, an erase cycle will be performed first, with the same caveats as Program + Verify.
- Program (No Erase) - A special mode for SPI Flash devices. It writes data to the device, but does not perform an erase cycle. This is useful if multiple memory images are to be programmed to the device. Use FF as the pad value when loading each memory image to avoid corrupting previously written data. Because the device may have been programmed prior to this operation, it does not perform the verification step.
For additional information about the Flash Center program modes, take a look at the Flash Center manual.
To program a single sector with Flash Center, we will take advantage of the following properties of flash devices:
- Programming a flash device can only change the value of a bit from 1 to 0 and has no affect when attempting to change a bit from 0 to 1.
- Erasing a flash device changes all the bits in a sector (or the entire device) to 1.
By manually erasing specific sectors along with using the Program (No Erase) mode, data can be written to any sector of a flash device.
M25P32 Details
The 32 Mbit (4M bytes) SPI Flash M25P32 found on the SPI Flash Demo Board has 64 sectors. Each sector has 256 pages or 65,536 (64K, 0x10000) bytes. Each page has 256 bytes. Therefore, the memory has 16,384 pages or 4,194,304 (0x400000) bytes. The whole memory can be erased using the Bulk Erase instruction, or a sector at a time, using the Sector Erase instruction. For additional information about the SPI Flash M25P32 take a look at the M25P32 datasheet.
Programming Instructions
The following instructions describe how to use the Cheetah SPI Host Adapter to program data to the first sector, then program data to the second sector without overwriting the data in the first.
- Download and run the latest version of the Total Phase USB Drivers Installer.
- Download and unzip the latest version of Flash Center. (?)
- Connect the Cheetah adapter to the PC via the USB connector.
- Connect the Cheetah adapter to the SPI flash demo board via the 10-pin header. (?)
- Launch Flash Center. (?)
- Connect the Cheetah adapter to Flash Center. (?)
- Click Adapters > Add Adapters.
- Select the Cheetah adapter.
- Click Add to connect to the adapter.
- Enable Target Power to provide power to the SPI Flash Demo Board. (?)
- Click Operations > Choose Target and choose STMicro M25P32. (?)
- Read the contents of the memory device (?).
- Click Operations > Read Target.
- Write zeros to the first two sectors of the device.
- Clear the data buffer by clicking on the Clear button. This only clears the software buffer and doesn't change the data on the device.(?)
- Enter "00" in the Pad field. (?)
- Click the "Fill..." button, enter a byte count of 131072 (64k x 2 = size of first two sectors), and click OK. (?)
- Click Operations > Program + Verify to commit the new buffer to the device.
- Program 8 bytes to the start of the device to see how Flash Center erases only the necessary sectors.
- Clear the data buffer by clicking on the Clear button
- Type 00 11 22 33 44 55 66 77 in the first 8 bytes in the Data section.
- Click Operations > Program + Verify > Click Yes. (The warning is displayed because the data supplied does not end on a sector boundary and the entire sector will be erased before programming.)
- Click Operations > Read Target.
- Note how the first 8 bytes are as expected and the rest of the first sectors is all 0xFF. Also note that the second sector remains all 0x00.
- In order to program data to the second sector and not affect the first, the Program (No Erase) option can be used. However, before doing so, you need to ensure the target sector has been erased.
- Click Operations > Erase... and select a specific address range starting at 0x10000 with a length of 1. (Flash Center will erase only the necessary sectors to cover the supplied range. In this case, only the second sector will be erased.)
- Click OK > Yes to erase the entire second sector.
- Program 8 bytes to the start of the second sector while not affecting the contents in the first sector.
- Clear the data buffer by clicking on the Clear button
- Enter "FF" in the Pad field.
- Click the "Fill..." button, enter a byte count of 65536, and click OK. (This data fills the entire first sector and is used as padding since programming 1s, without first erasing, will not affect the existing data.)
- Type 88 99 AA BB CC DD EE FF at the start of the second sector (address 0x10000).
- Click Operations > Program (No Erase) to commit the new buffer to the device without first performaing an erase.
- Click Operations > Read Target.
- Note how the first 8 bytes of the device remain 00 11 22 33 44 55 66 77 and the first 8 bytes of the second sector are 88 99 AA BB CC DD EE FF.
Notes
For additional information, take a look at the Cheetah adapter user manual, Flash Center manual and High Speed SPI Flash Demo Board User Manual.