FlexSPI Driver Design
FlexSPI Driver Design
FlexSPI controller is new IP from Microcontroller group and it will replace QSPI in all future
SoCs.
FlexSPI is superset and superior to QSPI. Most of the feature set of FlexSPI and QSPI are
same, but there are few difference related to IO signal width, command set, default LUT
programming and Hyperflash support.
FlexSPI has AHB and IP bus interface. AHB 64-bit interface and is mainly use for READ and
WRITE flash operation whereas IP is 32-bit interface and it supports all flash operation – READ,
WRITE, STATUS CHECK, GET PARAMS etc.
FlexSPI programs various commands in LUT and these commands sequence are trigger when
we do AHB/IP bus READ/WRITE operation.
This documents introduces FlexSPI controller, FlexSPI serial NOR driver implementation and
FlexSPI serial NAND driver implementation.
FlexSPI is a flexible SPI host controller which supports TWO SPI channels and up to 4 external
devices.
Each SPI channel support Single/Dual/Quad/Octal mode bi-directional data lines.
FlexSPI controller supports following memory devices
a) Serial NOR flash
b) Serial NAND flash
c) HyperBus devices (Hyperflash/HyperRAM)
d) FPGA devices
AHB command interface supports only two command – READ and WRITE to flash memory
devices.
Whereas IP CMD interfaces support a lot of commands like – READ, WRITE, STATUS CHECK,
GET PARAMS etc.
Another difference between AHB and IP CMD interface is that AHB is 64-bit interface whereas
IP is 32-bit interface.
AHB command is normally used to access serial Flash memory space. IP command should be
used to access the control and status registers in external flash device.
Flash could be accessed by AHB bus directly on AHB address space:0~10000000. This
address space is mapped to Serial Flash Memory in FlexSPI. AHB bus access to this address
space may trigger Flash access command sequence as needed.
For AHB read access to Serial Flash Memory, FlexSPI will fetch data from SFM into AHB RX
Buffers and then return the data on AHB Bus. For AHB write access to Serial Flash Memory,
FlexSPI will buffer AHB Bus write data into AHB TX Buffer and then transmit to Serial Flash
memory.
There is no software configuration or polling need for AHB command except FlexSPI
initialization. AHB master access external flash device transparently similar as normal AHB
slave.
Serial NOR flash memory can be access in different mode viz serial, dual, quad or octal
(x1/x2/x4/x8).
FlexSPI serial NOR driver will implement mainly TWO functionalities for SP BootROM
(1) flexspi_nor_init –
This will initialize FlexSPI controller for AHB read access, program LUT with READ_SDR
command sequence and initialize serial NOR memory (if required).
(2) flexspi_nor_read –
flexspi_nor_read will access serial nor memory from AHB interface and return read data to
Service process (SP).
FlexSPI controller
Common specific
functionality
FlexSPI controller
1. Enable controller clocks (AHB clock/IP Bus clock/Serial root clock) in System level.
2. Set MCR0.MDIS to 0x1 (Make sure controller is configured in module stop mode)
3. Configure module control registers: MCR0, MCR1, MCR2. (Don't change MCR0.MDIS)
4. Configure AHB bus control register (AHBCR) and AHB RX Buffer control registers
5. (AHBRXBUFxCR) optionally if AHB command will be used
6. Configure Flash control registers (FLSHxCR0/1/2) according to external device type
7. Set MCR0.MDIS to 0x0 (Exit module stop mode)
8. Reset controller optionally (by set MCR0.SWRESET to 0x1)
FlexSPI_NOR_INIT Function
Function Name u32 flexspi_nor_init()
Input Parameter void *p
Description Initialize FlexSPI controller, program LUT table and initialize serial Flash for AHB read
Algorithm
(1) Get FlexSPI CCSR register address in variable “base”
(2) Call flexspi_init(base)
(3) Call flexspi_update_lut(base, nor_lut, startindex, len)
(4) return SUCCESS
Flowchart
FlexSPI_NOR_READ Function
Function Name u32 flexspi_nor_read()
u32 src_offset
u8 *dst
u32 size
Input Parameter void *x
Description Read data via AHB bus from Serial NOR flash from src_offset to dst of len bytes
Algorithm
(1) Read only when src_offset < 0xFFFFFF
(2) rom_memcpy(dst, src, size)
(3) return SUCCESS
Flowchart
3 FlexSPI serial NAND driver implementation
Serial NAND flash memory can be access in different mode viz serial, dual or quad (x1/x2/x4).
FlexSPI serial NAND driver will implement mainly TWO broad functions for SP BootROM
1. flexspi_nand_init –
Flexspi_nand_init performance
(1) FlexSPI controller initialization
(2) Programs LUT table with various serial NAND command sequences
(3) Get NAND parameters from serial NAND flash and get values for
a. Page size
b. Spare size
c. Number of pages per block
d. Is multiplane supported?
(4) Bad block table initialization
2. flexspi_nand_read –
flexspi_nor_read reads data from serial NAND flash. Following functionality has been
implemented in the function
(1) Read EVEN pages via AHB interface
(2) Read ODD pages via IP command interface
(3) Does bad block handling
FlexSPI controller
Common specific
functionality
FlexSPI
controller
FlexSPI_NAND_INIT Function
Function Name u32 flexspi_nand_init()
Input Parameter void *nandinfo
This function initializes and set FlexSPI module, AHB bus and Flash
Description Configuration, LUT programming, get paramaters and initialize bad block table
FlexSPI_NAND_READ Function
Function Name u32 flexspi_nand_read()
Input Parameter u32 src_addr, u8 *dst, u32 size, void *nandinfo
Description This function read data from serial NAND memory