RA Flexible Software Package Documentation
Release v5.6.0
|
|
Driver for the QSPI peripheral on RA MCUs. This module implements the SPI Flash Interface.
The QSPI driver has the following key features:
Configuration | Options | Default | Description |
---|---|---|---|
Parameter Checking |
| Default (BSP) | If selected code for parameter checking is included in the build. |
Support Multiple Line Program in Extended SPI Mode |
| Disabled | If selected code for programming on multiple lines in extended SPI mode is included in the build. |
Configuration | Options | Default | Description |
---|---|---|---|
General | |||
Name | Name must be a valid C symbol | g_qspi0 | Module name. |
SPI Protocol |
| Extended SPI | Select the initial SPI protocol. SPI protocol can be changed in R_QSPI_Direct(). |
Address Bytes |
| 3 | Select the number of address bytes. Selecting '4 with 4-byte read code' converts the default read code determined in Read Mode to the 4-byte version. If 4-byte mode is selected without using 4-byte commands, the application must issue the EN4B command using R_QSPI_Direct(). |
Read Mode |
| Fast Read Quad I/O | Select the read mode for memory mapped access. |
Dummy Clocks for Fast Read | Refer to the RA Configuration tool for available options. | Default | Select the number of dummy clocks for fast read operations. Default is 6 clocks for Fast Read Quad I/O, 4 clocks for Fast Read Dual I/O, and 8 clocks for other fast read instructions including Fast Read Quad Output, Fast Read Dual Output, and Fast Read |
Page Size Bytes | Must be an integer greater than 0 | 256 | The maximum number of bytes allowed for a single write. |
Command Definitions | |||
Page Program Command | Must be an 8-bit QSPI Page Program Command under Command Definitions | 0x02 | The command to program a page. If 'Support Multiple Line Program in Extended SPI Mode' is Enabled, this command must use the same number of data lines as the selected read mode. |
Page Program Address Lines |
| 1 | Select the number of lines to use for the address bytes during write operations. This can be determined by referencing the datasheet for the external QSPI. It should either be 1 or match the number of data lines used for memory mapped fast read operations. |
Write Enable Command | Must be an 8-bit QSPI Write Enable Command under Command Definitions | 0x06 | The command to enable write. |
Status Command | Must be an 8-bit QSPI Status Command under Command Definitions | 0x05 | The command to query the status of a write or erase command. |
Write Status Bit | Must be an integer between 0 and 7 | 0 | Which bit contains the write in progress status returned from the Write Status Command. |
Sector Erase Command | Must be an 8-bit QSPI Sector Erase Command under Command Definitions | 0x20 | The command to erase a sector. Set Sector Erase Size to 0 if unused. |
Sector Erase Size | Must be an integer greater than or equal to 0 | 4096 | The sector erase size. Set Sector Erase Size to 0 if Sector Erase is not supported. |
Block Erase Command | Must be an 8-bit QSPI Block Erase Command under Command Definitions | 0xD8 | The command to erase a block. Set Block Erase Size to 0 if unused. |
Block Erase Size | Must be an integer greater than or equal to 0 | 65536 | The block erase size. Set Block Erase Size to 0 if Block Erase is not supported. |
Block Erase 32KB Command | Must be an 8-bit QSPI Block Erase 32KB Command under Command Definitions | 0x52 | The command to erase a 32KB block. Set Block Erase Size to 0 if unused. |
Block Erase 32KB Size | Must be an integer greater than or equal to 0 | 32768 | The block erase 32KB size. Set Block Erase 32KB Size to 0 if Block Erase 32KB is not supported. |
Chip Erase Command | Must be an 8-bit QSPI Chip Erase Command under Command Definitions | 0xC7 | The command to erase the entire chip. Set Chip Erase Command to 0 if unused. |
XIP Enter M7-M0 | Must be an 8-bit QSPI XIP Enter M7-M0 command under Command Definitions | 0x20 | How to set M7-M0 to enter XIP mode. |
XIP Exit M7-M0 | Must be an 8-bit QSPI XIP Exit M7-M0 command under Command Definitions | 0xFF | How to set M7-M0 exit XIP mode. |
Bus Timing | |||
QSPKCLK Divisor | Refer to the RA Configuration tool for available options. | 2 | Select the divisor to apply to PCLK to get QSPCLK. |
Minimum QSSL Deselect Cycles | Refer to the RA Configuration tool for available options. | 4 QSPCLK | Define the minimum number of QSPCLK cycles for QSSL to remain high beween operations. |
The QSPI clock is derived from PCLKA.
The following pins are available to connect to an external QSPI device:
After R_QSPI_Open() completes successfully, the QSPI flash device contents are mapped to address 0x60000000 and can be read like on-chip flash.
Developers should be aware of the following limitations when using the QSPI driver:
This is a basic example of minimal use of the QSPI in an application.
This is an example of the types of commands that can be used to initialize the QSPI.
This is an example of using R_QSPI_DirectWrite followed by R_QSPI_DirectRead to send the read status register command and read back the status register from the device.
This is an example of using R_QSPI_DirectWrite followed by R_QSPI_DirectRead to query the device size.
Data Structures | |
struct | qspi_instance_ctrl_t |
Enumerations | |
enum | qspi_qssl_min_high_level_t |
enum | qspi_qspclk_div_t |
struct qspi_instance_ctrl_t |
Instance control block. DO NOT INITIALIZE. Initialization occurs when spi_flash_api_t::open is called
enum qspi_qspclk_div_t |
fsp_err_t R_QSPI_Open | ( | spi_flash_ctrl_t * | p_ctrl, |
spi_flash_cfg_t const *const | p_cfg | ||
) |
Open the QSPI driver module. After the driver is open, the QSPI can be accessed like internal flash memory starting at address 0x60000000.
Implements spi_flash_api_t::open.
FSP_SUCCESS | Configuration was successful. |
FSP_ERR_ASSERTION | The parameter p_instance_ctrl or p_cfg is NULL. |
FSP_ERR_ALREADY_OPEN | Driver has already been opened with the same p_instance_ctrl. |
fsp_err_t R_QSPI_DirectWrite | ( | spi_flash_ctrl_t * | p_ctrl, |
uint8_t const *const | p_src, | ||
uint32_t const | bytes, | ||
bool const | read_after_write | ||
) |
Writes raw data directly to the QSPI.
Implements spi_flash_api_t::directWrite.
FSP_SUCCESS | The flash was programmed successfully. |
FSP_ERR_ASSERTION | A required pointer is NULL. |
FSP_ERR_NOT_OPEN | Driver is not opened. |
FSP_ERR_INVALID_MODE | This function can't be called when XIP mode is enabled. |
FSP_ERR_DEVICE_BUSY | The device is busy. |
fsp_err_t R_QSPI_DirectRead | ( | spi_flash_ctrl_t * | p_ctrl, |
uint8_t *const | p_dest, | ||
uint32_t const | bytes | ||
) |
Reads raw data directly from the QSPI. This API can only be called after R_QSPI_DirectWrite with read_after_write set to true.
Implements spi_flash_api_t::directRead.
FSP_SUCCESS | The flash was programmed successfully. |
FSP_ERR_ASSERTION | A required pointer is NULL. |
FSP_ERR_NOT_OPEN | Driver is not opened. |
FSP_ERR_INVALID_MODE | This function must be called after R_QSPI_DirectWrite with read_after_write set to true. |
fsp_err_t R_QSPI_DirectTransfer | ( | spi_flash_ctrl_t * | p_ctrl, |
spi_flash_direct_transfer_t *const | p_transfer, | ||
spi_flash_direct_transfer_dir_t | direction | ||
) |
Read/Write raw data directly with the OctaFlash/OctaRAM device. Unsupported by QSPI.
Implements spi_flash_api_t::directTransfer.
FSP_ERR_UNSUPPORTED | API not supported by QSPI. |
fsp_err_t R_QSPI_XipEnter | ( | spi_flash_ctrl_t * | p_ctrl | ) |
Enters XIP (execute in place) mode.
Implements spi_flash_api_t::xipEnter.
FSP_SUCCESS | The flash was programmed successfully. |
FSP_ERR_ASSERTION | A required pointer is NULL. |
FSP_ERR_NOT_OPEN | Driver is not opened. |
fsp_err_t R_QSPI_XipExit | ( | spi_flash_ctrl_t * | p_ctrl | ) |
Exits XIP (execute in place) mode.
Implements spi_flash_api_t::xipExit.
FSP_SUCCESS | The flash was programmed successfully. |
FSP_ERR_ASSERTION | A required pointer is NULL. |
FSP_ERR_NOT_OPEN | Driver is not opened. |
fsp_err_t R_QSPI_Write | ( | spi_flash_ctrl_t * | p_ctrl, |
uint8_t const *const | p_src, | ||
uint8_t *const | p_dest, | ||
uint32_t | byte_count | ||
) |
Program a page of data to the flash.
Implements spi_flash_api_t::write.
FSP_SUCCESS | The flash was programmed successfully. |
FSP_ERR_ASSERTION | p_instance_ctrl, p_dest or p_src is NULL, or byte_count crosses a page boundary. |
FSP_ERR_NOT_OPEN | Driver is not opened. |
FSP_ERR_INVALID_MODE | This function can't be called when XIP mode is enabled. |
FSP_ERR_DEVICE_BUSY | The device is busy. |
fsp_err_t R_QSPI_Erase | ( | spi_flash_ctrl_t * | p_ctrl, |
uint8_t *const | p_device_address, | ||
uint32_t | byte_count | ||
) |
Erase a block or sector of flash. The byte_count must exactly match one of the erase sizes defined in spi_flash_cfg_t. For chip erase, byte_count must be SPI_FLASH_ERASE_SIZE_CHIP_ERASE.
Implements spi_flash_api_t::erase.
FSP_SUCCESS | The command to erase the flash was executed successfully. |
FSP_ERR_ASSERTION | p_instance_ctrl or p_device_address is NULL, or byte_count doesn't match an erase size defined in spi_flash_cfg_t, or device is in XIP mode. |
FSP_ERR_NOT_OPEN | Driver is not opened. |
FSP_ERR_INVALID_MODE | This function can't be called when XIP mode is enabled. |
FSP_ERR_DEVICE_BUSY | The device is busy. |
fsp_err_t R_QSPI_StatusGet | ( | spi_flash_ctrl_t * | p_ctrl, |
spi_flash_status_t *const | p_status | ||
) |
Gets the write or erase status of the flash.
Implements spi_flash_api_t::statusGet.
FSP_SUCCESS | The write status is in p_status. |
FSP_ERR_ASSERTION | p_instance_ctrl or p_status is NULL. |
FSP_ERR_NOT_OPEN | Driver is not opened. |
FSP_ERR_INVALID_MODE | This function can't be called when XIP mode is enabled. |
fsp_err_t R_QSPI_BankSet | ( | spi_flash_ctrl_t * | p_ctrl, |
uint32_t | bank | ||
) |
Selects the bank to access. A bank is a 64MB sliding access window into the QSPI device flash memory space. To access chip address 0x4000000, select bank 1, then read from internal flash address 0x60000000. To access chip address 0x8001000, select bank 2, then read from internal flash address 0x60001000.
This function is not required for memory devices less than or equal to 512 Mb (64MB).
Implements spi_flash_api_t::bankSet.
FSP_SUCCESS | Bank successfully selected. |
FSP_ERR_ASSERTION | A required pointer is NULL. |
FSP_ERR_NOT_OPEN | Driver is not opened. |
fsp_err_t R_QSPI_SpiProtocolSet | ( | spi_flash_ctrl_t * | p_ctrl, |
spi_flash_protocol_t | spi_protocol | ||
) |
Sets the SPI protocol.
Implements spi_flash_api_t::spiProtocolSet.
FSP_SUCCESS | SPI protocol updated on MCU peripheral. |
FSP_ERR_ASSERTION | A required pointer is NULL. |
FSP_ERR_NOT_OPEN | Driver is not opened. |
FSP_ERR_INVALID_ARGUMENT | Invalid SPI protocol requested. |
fsp_err_t R_QSPI_AutoCalibrate | ( | spi_flash_ctrl_t * | p_ctrl | ) |
Auto-calibrate the OctaRAM device using the preamble pattern. Unsupported by QSPI. Implements spi_flash_api_t::autoCalibrate.
FSP_ERR_UNSUPPORTED | API not supported by QSPI |
fsp_err_t R_QSPI_Close | ( | spi_flash_ctrl_t * | p_ctrl | ) |
Close the QSPI driver module.
Implements spi_flash_api_t::close.
FSP_SUCCESS | Configuration was successful. |
FSP_ERR_ASSERTION | p_instance_ctrl is NULL. |
FSP_ERR_NOT_OPEN | Driver is not opened. |