s29gl128p Norflash Drive Read-write analysis
2014-2-25
s29gl128p is often seen in embedded systems of a Norflash chip, storage structure of (sectors) X128 (Kbytes) =16mbytes, support CFI interface, fortunately in the project, the simple discussion of its operating principle.
First, the hardware connection
FSMC bus connection between s29gl128p and stm32f407, with independent 16M addressing space, 0x64000000-0x64ffffff,16bit access. Because the FSMC bus is AHB3 through SYSCLK 1, up to 168MHz, when hardware is also concerned about the data bus and address bus cabling, such as long-time problem, now seems to be completely unused, timing can be adjusted by adjusting the address settling times, hold time and other parameters to adjust, but for debugging convenience, The data line and clock line should be treated as long as possible respectively. In addition, the STM32F407FSMC bus can mount 4bank Norflash, the design will norflash mounted to BANK2, the network card chip mounted to the BANK3, 4 banks have independent control and time settings register, do not worry about bus conflict.
Second, initialize
First of all, the FSMC bus is initialized to the reuse state, set the bank on the bus to establish and maintain the data access mode and other parameters, these time parameters can refer to the s29gl128p manual in the corresponding parameters to set.
Third, Norflash chip ID read, in fact, the chip manual is the best reference, just through the simple unlock into the ID read mode, read ID, exit register read mode can be, in order to facilitate user development, the manual even directly give the program.
If you successfully read the Flash ID, then it means that Norflash has been transferred.
Iv. Norflash Condition Detection
s29gl128p in the programming process, not only can output the read signal, but also to make certain DQ signal line state output changes, such as DQ6 in the programming of the flip, DQ2 in the erase state has been flipped, DQ5 and DQ1 can output programming errors and timeouts, and so on.
Five, block erase, piece erase
Norflash mechanism is unlocked can enter the register area, by its command set can be seen, for the chip erase, the required operation as follows, unlock write 0x80, and then unlock write 0x10, began to perform the chip erase algorithm, block erase is similar, is to write the 0x30 command and write the address to erase.
Nor_write (Addr_shift (0x0555), 0X00AA);
Nor_write (Addr_shift (0X02AA), 0x0055);
Nor_write (Addr_shift (0x0555), 0x0080);
Nor_write (Addr_shift (0x0555), 0X00AA);
Nor_write (Addr_shift (0X02AA), 0x0055);
Nor_write (Addr_shift (0x0555), 0x0010);
It is noted here that the address is processed when the data is read and written:
#define Addr_shift (a) (Nor_flash_addr + (2 * (a)))
See the write address multiplied by a 2, what is the reason? Take 0x0555 address For example, actually point to is a byte data, not a half word of data, and the Flash is read and write by 16bit, the intention is to put 0x0555 this half word address to the correct position, it must be shifted to address, respectively write high and low. When writing data, if you define a uint16_t * Type of address pointer, then you can directly read and write to Flash. (Refer to http://blog.csdn.net/daniellee_ustb/article/details/7453273 for details)
Vi. Flash Read and write
Norflash is a random read command to write the device, but must each read and write is two bytes, the method is very simple, here test the continuous reading and writing, there is no test in-page programming.
Attached Access Command table