RA Flexible Software Package Documentation
Release v5.6.0
|
|
Driver for the OSPI peripheral on RA MCUs. This module implements the SPI Flash Interface.
The OSPI peripheral interfaces with an external OctaFlash and/or OctaRAM chip(s) to perform data I/O Operations. When both OctaFlash and OctaRAM devices are interfaced, they must be connected to their own chip-select lines. The devices cannot share a single chip-select line.
The OSPI driver has the following key features to support the OctaFlash device:
The OSPI driver has the following key features to support the OctaRAM device:
Additional build-time features:
Configuration | Options | Default | Description |
---|---|---|---|
Parameter Checking |
| Default (BSP) | If selected code for parameter checking is included in the build. |
DMAC Support |
| Disable | Enable DMAC support for the OSPI module. |
Configuration | Options | Default | Description |
---|---|---|---|
General | |||
General > Single Continuous Mode | |||
Read Idle Time | Must be an integer greater than 0 with maximum configurable value of 127 | 100 | Specify the read idle time. |
Write Idle Time | Must be an integer greater than 0 with maximum configurable value of 127 | 100 | Specify the write idle time. |
Name | Name must be a valid C symbol | g_ospi0 | Module name. |
Channel | Channel should be 0 or 1 | 0 | Specify the OSPI chip select line to use. |
Flash Size | Must be an integer greater than 0 with maximum configurable value of 0x3FFFFFFF | 0x04000000 | Specify the OctaFlash size in bytes. |
SPI Protocol |
| SPI | Select the initial SPI protocol. SPI protocol can be changed on the OctaFlash using R_OSPI_DirectTransfer(). |
Address Bytes |
| 4 | Select the number of address bytes. |
OPI Mode | |||
OPI Mode > Auto-Calibration | |||
Data latching delay | Must be a valid non-negative integer with maximum configurable value of 0xFF | 0x80 | Set this to 0 to enable auto-calibration. 0x80 is the default value calculated at 3.3V and 25°C |
Auto-Calibration Address | Must be a valid non-negative integer with maximum configurable value of 0xFFFFFFFF | 0x00 | Set the address of the read/write destination to be performed for auto-calibration. |
OPI Mode > Command Definitions | |||
Page Program Command | Must be a 16-bit OSPI Page Program Command under OPI Mode|Command Definitions | 0x12ED | The command to program a page in OPI mode. |
Read Command | Must be a 16-bit OSPI Read Command under OPI Mode|Command Definitions | 0xEC13 | The command to read in SOPI mode (8READ). |
Dual Read Command | Must be a 16-bit OSPI Dual Read Command under OPI Mode|Command Definitions | 0xEE11 | The command to read in DOPI mode (8DTRD). |
Write Enable Command | Must be a 16-bit OSPI Write Enable Command under OPI Mode|Command Definitions | 0x06F9 | The command to enable write in OPI mode. |
Status Command | Must be a 16-bit OSPI Status Command under OPI Mode|Command Definitions | 0x05FA | The command to query the status of a write or erase command in OPI mode. |
OPI Mode > OM_DQS Enable Counter | |||
SOPI | Must be an integer between 0 and 255 | 9 | OM_DQS enable counter for memory access. Setting for SOPI mode. |
DOPI | Must be an integer between 0 and 255 | 6 | OM_DQS enable counter for memory access. Setting for DOPI mode. |
Command Length Bytes | Must be an integer between 1 and 2 | 2 | Command length in bytes |
Memory Read Dummy Cycles | Must be an integer between 6 and 10 | 10 | Memory read dummy cycles |
Status Read Dummy Cycles | Must be an integer between 0 and 255 | 4 | Status read dummy cycles |
DOPI Byte Order |
| Byte0, Byte1, Byte2, Byte3 | Byte order on the external bus |
SPI Mode | |||
SPI Mode > Command Definitions | |||
Page Program Command | Must be a 8-bit OSPI Page Program Command under SPI Mode|Command Definitions | 0x12 | The command to program a page in SPI mode. |
Read Command | Must be a 8-bit OSPI Read Command under SPI Mode|Command Definitions | 0x13 | The command to read in SPI mode. |
Write Enable Command | Must be a 16-bit OSPI Write Enable Command under SPI Mode|Command Definitions | 0x06 | The command to enable write in SPI mode. |
Status Command | Must be a 16-bit OSPI Status Command under SPI Mode|Command Definitions | 0x05 | The command to query the status of a write or erase command in SPI mode. |
Common Command Definitions | |||
Sector Erase Command | Must be a value greater than or equal to 0 | 0x21DE | The command to erase a sector. Set Sector Erase Size to 0 if unused. |
Block Erase Command | Must be a value greater than or equal to 0 | 0xDC23 | The command to erase a block. Set Block Erase Size to 0 if unused. |
Chip Erase Command | Must be a value greater than or equal to 0 | 0xC738 | The command to erase the entire chip. Set Chip Erase Command to 0 if unused. |
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. |
Write Enable Bit | Must be an integer between 0 and 7 | 1 | Which bit contains the write enable status returned from the Write Enable Command. |
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 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. |
Chip Select Timing Setting | |||
Memory Mapped Read Command Interval |
| 2 | Memory mapped read command execution interval setting in OCTACLK units |
Memory Mapped Write Command Interval |
| 2 | Memory mapped write command execution interval setting in OCTACLK units |
Command Interval |
| 2 | Command execution interval setting in OCTACLK units |
Memory Mapped Read Pull-up Timing |
| 5 SPI/SOPI | Memory mapped read signal pull-up timing setting in OCTACLK units |
Memory Mapped Write Pull-up Timing |
| 2 SPI/SOPI, 1.5 DOPI | Memory mapped write signal pull-up timing setting in OCTACLK units |
Pull-up Timing |
| 5 SPI/SOPI | Signal pull-up timing setting in OCTACLK units |
Memory Mapped Read Pull-down Timing |
| 3 SPI/SOPI, 2.5 DOPI | Memory mapped read signal pull-down timing setting in OCTACLK units |
Memory Mapped Write Pull-down Timing |
| 3 SPI/SOPI, 2.5 DOPI | Memory mapped write signal pull-down timing setting in OCTACLK units |
Pull-down Timing |
| 3 SPI/SOPI, 2.5 DOPI | Signal pull-down timing setting in OCTACLK units |
Configuration | Options | Default | Description |
---|---|---|---|
Parameter Checking |
| Default (BSP) | If selected code for parameter checking is included in the build. |
DMAC Support |
| Disable | Enable DMAC support for the OSPI module. |
Configuration | Options | Default | Description |
---|---|---|---|
General | |||
General > Single Continuous Mode | |||
Read Idle Time | Must be an integer greater than 0 with maximum configurable value of 127 | 127 | Specify the read idle time. |
Write Idle Time | Must be an integer greater than 0 with maximum configurable value of 127 | 127 | Specify the write idle time. |
Name | Name must be a valid C symbol | g_ospi_ram0 | Module name. |
Channel | Channel should be 0 or 1 [Channel 0 recommended] | 0 | Specify the OSPI chip select line to use. |
RAM Size | Must be an integer greater than 0 with maximum configurable value of 0x00800000 | 0x00800000 | Specify the OctaRam size in bytes. |
SPI Protocol | Dual data rate OPI | Dual data rate OPI | Select the initial SPI protocol. OctaRAM only supports DOPI mode. |
Address Bytes | 4 | 4 | Select the number of address bytes. OctaRAM only supports 4 byte addresses in DOPI mode. |
Auto-Calibration | |||
Data latching delay | Must be a valid non-negative integer with maximum configurable value of 0xFF | 0x80 | Set this to 0 to enable auto-calibration. 0x80 is the default value calculated at 3.3V and 25°C |
Auto-Calibration Address | Must be a valid non-negative integer with maximum configurable value of 0xFFFFFFFF | 0x00 | Set the address of the read/write destination to be performed for auto-calibration. |
Command Definitions | |||
Memory Read Command | Must be a 16-bit OSPI Dual Read Command under Command Definitions | 0xA000 | The command to read in DOPI mode. |
Memory Write Command | Must be a 16-bit OSPI Write Command under Command Definitions | 0x2000 | The command to write in DOPI mode. |
OM_DQS Enable Counter | |||
DOPI | Must be an integer between 0 and 255 | 3 | OM_DQS enable counter for memory access. Setting for DOPI mode. |
Chip Select Timing Setting | |||
Memory Mapped Read Command Interval |
| 2 | Memory mapped read command execution interval setting in OCTACLK units |
Memory Mapped Write Command Interval |
| 2 | Memory mapped write command execution interval setting in OCTACLK units |
Command Interval |
| 2 | Command execution interval setting in OCTACLK units |
Memory Mapped Read Pull-up Timing |
| 6.5 DOPI | Memory mapped read signal pull-up timing setting in OCTACLK units |
Memory Mapped Write Pull-up Timing |
| 1.5 DOPI | Memory mapped write signal pull-up timing setting in OCTACLK units |
Pull-up Timing |
| 6.5 DOPI | Signal pull-up timing setting in OCTACLK units |
Memory Mapped Read Pull-down Timing |
| 2.5 DOPI | Memory mapped read signal pull-down timing setting in OCTACLK units |
Memory Mapped Write Pull-down Timing |
| 2.5 DOPI | Memory mapped write signal pull-down timing setting in OCTACLK units |
Pull-down Timing |
| 2.5 DOPI | Signal pull-down timing setting in OCTACLK units |
Command Length Bytes | Must be an integer between 1 and 2 | 2 | Command length in bytes |
Memory Read Dummy Cycles | Must be an integer between 3 and 8 | 4 | Memory read dummy cycles |
Memory Write Dummy Cycles | Must be an integer between 3 and 8 | 4 | Memory write dummy cycles |
DOPI Byte Order |
| Byte1, Byte0, Byte3, Byte2 | Byte order on the external bus |
Chip Select Maximum Low Time (us) | Must be an integer between 0 to 511 | 4 | Chip Select Maximum Low Time (tCSM). |
PCLKA is the Octal-SPI bus interface, and PCLKB is used to set OSPI registers.
The signals to the OSPI device are derived from OCTASPICLK. The OMSCLK signal is OCTASPICLK / 2. Data can be output at the OCTASPICLK rate if SPI Protocol is set to Dual Data Rate OPI.
The PCLKB, PCLKA, and OCTASPICLK frequencies can be set on the Clocks tab of the RA Configuration editor.
The following pins are available to connect to an external OSPI device:
DMAC data transmission support is configurable for OSPI Flash and is disabled from the build by default. Use of a high-priority (low channel number) DMAC for data transmission is strongly recommended.
For further details on DMAC please refer Transfer (r_dmac).
After R_OSPI_Open() completes successfully, the OctaFlash device contents are mapped to address 0x68000000 (channel 0) or 0x70000000 (channel 1) based on the channel configured and can be read like on-chip flash. Channel 0 supports 128 MB while Channel 1 supports 256 MB of address space.
Auto-calibration procedure is triggered automatically when the 'Data latching delay' field in the configurator properties is set to 0. The user application is responsible for setting the appropriate preamble pattern before calling R_OSPI_Open() with SOPI/DOPI mode or changing the SPI protocol to SOPI/DOPI using R_OSPI_SpiProtocolSet() API. The appropriate preamble pattern can be written to the desired address using the R_OSPI_Write() API while in the SPI mode (recommended). Ensure that the same address is passed through the configurator. If the OctaFlash chip is already in SOPI/DOPI mode, the preamble pattern must be programmed using the debugger before calling R_OSPI_Open().
Chip select latencies can be set through the configurator. The default settings support SOPI and SPI at minimum latency. In case the driver is opened in SPI mode and will be switched to DOPI mode later using R_OSPI_SpiProtocolSet(), please select latencies required for DOPI before calling R_OSPI_Open().
After R_OSPI_Open() completes successfully, the OctaRAM device contents are mapped to address 0x68000000 (channel 0) or 0x70000000 (channel 1) based on the channel configured and can be written to or read from like on-chip RAM. Channel 0 and 1 support 8 MB of address space.
Since the OctaRAM only supports DOPI mode, the driver allows the user to call R_OSPI_Open() without performing the auto-calibration procedure automatically when 'Data latching delay' field is set to 0 in the configurator properties. This is done so that the user can write the appropriate preamble pattern to the desired address using memory mapped writes while in DOPI mode. Ensure that the same address is passed through the configurator. R_OSPI_AutoCalibrate() should be then called to perform auto-calibration.
Chip select latencies can be set through the configurator. The default settings support DOPI at minimum latency.
Developers should be aware of the following limitations when using the OSPI driver:
This is a basic example of minimal use of the OSPI in an application with OctaFlash.
This is an example of using R_OSPI_DirectWrite followed by R_OSPI_DirectRead to send the read status register command and read back the status register from the device.
This is an example of using R_OSPI_SpiProtocolSet to change the operating mode from SPI to SOPI and allow the driver to initiate auto-calibration.
This is an example of using R_BSP_OctaclkUpdate to change the Octal-SPI clock frequency during run time. The OCTACLK frequency must be updated before calling the R_OSPI_SpiProtocolSet with appropriate clock source and divider settings required to be set for the new SPI protocol mode. Ensure that the clock source selected is started.
When using the IAR compiler, OSPI data must be const
qualified to be downloaded by the debugger.
This is a basic example of minimal use of the OSPI in an application with OctaRAM.
This is an example of using R_OSPI_AutoCalibrate to calibrate OSPI peripheral to read data from the OctaRAM device.
Data Structures | |
struct | ospi_instance_ctrl_t |
Enumerations | |
enum | ospi_device_number_t |
enum | ospi_device_type_t |
enum | ospi_command_cs_pullup_clocks_t |
enum | ospi_command_cs_pulldown_clocks_t |
enum | ospi_dopi_byte_order_t |
struct ospi_instance_ctrl_t |
Instance control block. DO NOT INITIALIZE. Initialization occurs when spi_flash_api_t::open is called
enum ospi_device_number_t |
enum ospi_device_type_t |
fsp_err_t R_OSPI_Open | ( | spi_flash_ctrl_t *const | p_ctrl, |
spi_flash_cfg_t const *const | p_cfg | ||
) |
Open the OSPI driver module. After the driver is open, the OSPI can be accessed like internal flash memory.
Implements spi_flash_api_t::open.
Example:
FSP_SUCCESS | Configuration was successful. |
FSP_ERR_ASSERTION | The parameter p_ctrl or p_cfg is NULL. |
FSP_ERR_ALREADY_OPEN | Driver has already been opened with the same p_ctrl. |
FSP_ERR_CALIBRATE_FAILED | Failed to perform auto-calibrate. |
FSP_ERR_INVALID_ARGUMENT | Attempting to open the driver with an invalid SPI protocol for OctaRAM. |
fsp_err_t R_OSPI_DirectWrite | ( | spi_flash_ctrl_t *const | p_ctrl, |
uint8_t const *const | p_src, | ||
uint32_t const | bytes, | ||
bool const | read_after_write | ||
) |
Writes raw data directly to the OctaFlash. API not supported. Use R_OSPI_DirectTransfer
Implements spi_flash_api_t::directWrite.
FSP_ERR_UNSUPPORTED | API not supported by OSPI. |
fsp_err_t R_OSPI_DirectRead | ( | spi_flash_ctrl_t *const | p_ctrl, |
uint8_t *const | p_dest, | ||
uint32_t const | bytes | ||
) |
Reads raw data directly from the OctaFlash. API not supported. Use R_OSPI_DirectTransfer.
Implements spi_flash_api_t::directRead.
FSP_ERR_UNSUPPORTED | API not supported by OSPI. |
fsp_err_t R_OSPI_DirectTransfer | ( | spi_flash_ctrl_t *const | 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.
Implements spi_flash_api_t::directTransfer.
Example:
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_OSPI_XipEnter | ( | spi_flash_ctrl_t *const | p_ctrl | ) |
Enters Single Continuous Read/Write 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_UNSUPPORTED | API not supported by OSPI - OctaRAM. |
fsp_err_t R_OSPI_XipExit | ( | spi_flash_ctrl_t *const | 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_UNSUPPORTED | API not supported by OSPI - OctaRAM. |
fsp_err_t R_OSPI_Write | ( | spi_flash_ctrl_t *const | 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.
Example:
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_DEVICE_BUSY | Another Write/Erase transaction is in progress. |
FSP_ERR_INVALID_SIZE | Write operation crosses page-boundary. |
FSP_ERR_UNSUPPORTED | API not supported by OSPI - OctaRAM. |
FSP_ERR_WRITE_FAILED | The write enable bit was not set. |
fsp_err_t R_OSPI_Erase | ( | spi_flash_ctrl_t *const | 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, byte_count doesn't match an erase size defined in spi_flash_cfg_t, or byte_count is set to 0. |
FSP_ERR_NOT_OPEN | Driver is not opened. |
FSP_ERR_DEVICE_BUSY | The device is busy. |
FSP_ERR_UNSUPPORTED | API not supported by OSPI - OctaRAM. |
FSP_ERR_WRITE_FAILED | The write enable bit was not set. |
fsp_err_t R_OSPI_StatusGet | ( | spi_flash_ctrl_t *const | p_ctrl, |
spi_flash_status_t *const | p_status | ||
) |
Gets the write or erase status of the flash.
Implements spi_flash_api_t::statusGet.
Example:
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_UNSUPPORTED | API not supported by OSPI - OctaRAM. |
fsp_err_t R_OSPI_BankSet | ( | spi_flash_ctrl_t *const | p_ctrl, |
uint32_t | bank | ||
) |
Selects the bank to access.
Implements spi_flash_api_t::bankSet.
FSP_ERR_UNSUPPORTED | API not supported by OSPI. |
fsp_err_t R_OSPI_SpiProtocolSet | ( | spi_flash_ctrl_t *const | 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_CALIBRATE_FAILED | Failed to perform auto-calibrate. |
FSP_ERR_INVALID_ARGUMENT | Attempting to set an invalid SPI protocol for OctaRAM. |
fsp_err_t R_OSPI_AutoCalibrate | ( | spi_flash_ctrl_t *const | p_ctrl | ) |
Auto-calibrate the OctaRAM device using the preamble pattern.
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_CALIBRATE_FAILED | Failed to perform auto-calibrate. |
FSP_ERR_UNSUPPORTED | API not supported by OSPI - OctaFlash. |
fsp_err_t R_OSPI_Close | ( | spi_flash_ctrl_t *const | p_ctrl | ) |
Close the OSPI 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. |