Escolar Documentos
Profissional Documentos
Cultura Documentos
Doc Edition K
WWW.HJTAG.COM
SPI FLASH DRIVER ADDING GUIDE
This document introduces how to add a new SPI flash driver into H-Flasher. User can use this guide as a
reference to add a new driver or modify existing ones.
1. BASIC INTRODUCTION
The access of SPI flash and NOR flash are quite different. NOR flash can be accessed directly through the
address bus and data bus. It means that a general flash driver can be made for a specific NOR flash device, which
can be used for different MCUs. For SPI flash, the access needs to be done through SPI controller. For different
MCUs, the SPI controllers are totally different. It means that no general flash driver can be made for a specific
SPI flash. Hence, the driver for SPI flash can only be developed based on a specific SPI flash and MCU
combination.
To add a new SPI flash driver into H- Flasher, both a flash device descriptor and the corresponding flash
driver need to be provided. The flash device descriptor contains all the basic information about the SPI flash
device, like the size, the organization, FLASH ID, driver, etc. The flash driver is a small piece of binary code,
which can be used to operate on the flash device, like read, write and erase. H-Flasher communicates with the
driver to achieve the basic flash operations. For more details about the flash device descriptor and flash driver,
please refer to the following sections.
The SPI flash device descriptor contains all the basic information about the flash device. H-Flasher can obtain
all the details by parsing the descriptor. Following is an illustrative descriptor based on W25X20 from
WINBOND.
FLASH_TYPE=4
FLASH_SIZE=256K
FLASH_ID=0x001100EF
FLASH_ADDRESS=0x0
FLASH_SECTOR=64x4K
FLASH_PGMSIZE=256
FLASH_WIDTH=8/0/0
FLASH_DRIVER=1/0/0
FLASH_TYPE=4
Used to specify the flash type. Type 4 represents SPI flash.
FLASH_ID=0x001100EF
Used to specify the flash ID. In this example, 0x11 is the device ID and 0xEF is the manufacturer ID.
FLASH_ADDRESS=0x0
Used to specify the starting address. For SPI flash, this should always be 0x0.
FLASH_SECTOR=64x4K
Used to specify the flash organization, which includes the sector number and sector size. The format of
FLASH_SECTOR is Sector-Number x Sector-Size + Sector-Number x Sector-Size + and so on. In this
example, the flash device contains 64 sectors and the size of each sector is 4K Bytes. For all the erasing
except chip erasing, sector is used as the basic operation unit.
FLASH_PGMSIZE=256
Used to specify how many bytes of data will be written for a single programming command. The definition
of FLASH_PGMSIZE must be 4*N, where N >= 1. In this example, the programming size is 256 Bytes. For
a basic programming operation, H-Flasher sends 256 Bytes of data to the driver. Meanwhile, the
programming address is guaranteed to be aligned to 256 Bytes. Generally, smaller FLASH_PGMSIZE means
slower programming speed. SPI flash devices might support different programming modes, like single byte
programming, page programming and AAI programming. User can define the FLASH_PGMSIZE flexibly
with well developed flash driver.
FLASH_WIDTH=8/0/0
Used to specify the bus width. For SPI flash, the bus width should be specified as FLASH_WIDTH=8/0/0.
FLASH_DRIVER=1/0/0
Used to specify the driver. In this example, the flash driver is 1. For SPI flash, the driver should always be
specified as FLASH_DRIVER=DRIVER/0/0. Please note that the driver can only be named with digits,
otherwise, H-Flasher can’t recognize it.
To add a new SPI flash into H-Flasher, create a new flash device descriptor and fill in all the details. Then
copy it to H-JTAG\FDEVICE\SPI-FLASH\. After restarting H-Flasher, the new device will be shown in the flash
list under the SPI-FLASH folder. The name of the device is the file name of the descriptor.
SPI flash driver is a piece of binary code, which implements all the basic flash operations. H-Flasher achieves
all the operations by talking to the driver. Besides the descriptor, the corresponding driver also needs to be
provided.
First, the binary code needs to be compiled and generated. After that, rename the binary driver according to
the name specified in the descriptor and copy the driver to H-JTAG\FDEVICE\SPI-FLASH\DRIVERS. Then,
H-Flasher can find the driver according the obtained information from the descriptor.
In the template, all the flash operations are defined and implemented in Flash.H and Flash.C. To develop your
own driver, only these two files need to be changed. Flash.H contains all the definitions about the flash and MCU.
Flash.C contains all the implementation of the basic flash operations. All the functions implemented in Flash.C are
listed below.
void spi_init(void)
This is the function used for initialization. User can put any initialization code in this function.
U32 spi_read_id(void)
This is the function used for the read of flash ID. This function should read the flash ID and return it.
If you need any further information or help, please feel free to contact us through email or telephone. We will
always try to provide as much help as possible. Our contacts can be obtained from our website www.hjtag.com.