Sunteți pe pagina 1din 5

H-JTAG

SPI FLASH DRIVER


ADDING GUIDE

Doc Edition K

Release Date: 2012-02-15

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.

2. SPI FLASH DEVICE DESCRIPTOR

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

The detailed definitions are given below.

 FLASH_TYPE=4
Used to specify the flash type. Type 4 represents SPI flash.

Copyright © 2012 WWW.HJTAG.COM All Rights Reserved 1


 FLASH_SIZE=256K
Used to specify the size of the flash device, the unit is BYTE. In this example, the size is 256K Bytes.

 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.

3. SPI FLASH DRIVER

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.

Under the installation directory of H-JTAG ( H-JTAG\FDevice\SPI-FLASH\SourceCodes (ADS1.2) ), a

Copyright © 2012 WWW.HJTAG.COM All Rights Reserved 2


driver template can be found. User can develop your own flash driver based on this template. Please note that the
size of the generated binary flash driver should be less than 16K Bytes.

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.

void spi_read_mem(U32 addr, U32 size8)


This is the function used to read data from the flash memory. The arguments include the address and size
(BYTE). This function should read the data from the specified address and return the data to H-Flasher by
calling write_to_host().
Notes:
A. The input argument addr is always aligned to 4 Bytes.
B. The input argument size8 is always 4*N, where N >= 1.
C. Each call of write_to_host() should return 4 Bytes of data to host.

U32 spi_check_blank(U32 addr, U32 size8)


This is the function used to check if the specified area is blank (0xFF). The arguments include the address
and the size (BYTE).
Notes:
A. The input argument addr is always aligned to 4 Bytes.
B. The input argument size8 is always 4*N, where N >= 1.

U32 spi_erase_chip(U32 size8)


This is the function used to erase the entire flash device. The argument includes the size (BYTE) of the
device. This function should erase the entire device and return the result.

U32 spi_erase_sector(U32 addr, U32 size8)


This is the function used to erase the specified sector. The arguments include the starting address of the sector
and its size (BYTE) This function should erase the specified sector and return the result.

U32 spi_program_segment(U32 addr, U32 size8)


This is the function used to program/write a segment of data into the flash. The size of the segment is equal

Copyright © 2012 WWW.HJTAG.COM All Rights Reserved 3


to FLASH_PGMSIZE as defined in the device descriptor. The argument includes the address and the size
(BYTE). This function should receive a segment of data by calling read_from_host() and program/write them
into the specified address.
Notes:
A. The input armament addr is always aligned to the FLASH_PGMSIZE as defined in the device descriptor.
B. The input argument size8 is always equal to the FLASH_PGMSIZE as defined in the device descriptor.
C. Each call of read_from_host() receives 4 Bytes of data from host.

4. MORE INFORMATION AND HELP

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.

Copyright © 2012 WWW.HJTAG.COM All Rights Reserved 4

S-ar putea să vă placă și