RA Flexible Software Package Documentation
Release v5.7.0
|
|
Driver for the OSPI_B peripheral on RA MCUs. This module implements the SPI Flash Interface.
The OSPI_B peripheral supports xSPI (or OSPI) compatible external memory devices, and it interfaces with these devices to perform data I/O Operations. The OSPI_B peripheral does not support addressable devices, so all connected memory devices must be connected to an individual chip-select pin. Please note that this document will reference the xSPI protocol to which OSPI is a subset. The OSPI_B peripheral is compatible with a variety of xSPI protocol operating modes.
The OSPI_B driver has the following key features to support the xSPI device:
Additional build-time features:
Configuration | Options | Default | Description |
---|---|---|---|
Memory-mapping Support | |||
Prefetch Function |
| Enable | Enable prefetch function on memory-mapped reads. |
Combination Function | Refer to the RA Configuration tool for available options. | 64 Byte | Enable combination function on memory-mapped writes. |
XiP Support |
| Disable | Enable the use of XiP enter and exit codes. |
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. |
Autocalibration Support |
| Disable | Enable DS autocalibration for dual-data-rate modes. |
DOTF Support |
| Disable | Enable DOTF support for the OSPI module. |
Configuration | Options | Default | Description |
---|---|---|---|
General | |||
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. |
Initial Protocol Mode |
| SPI (1S-1S-1S) | Select the initial protocol mode of the xSPI target device. Please see the documentation for examples of changing the protocol mode. |
Initial Address Bytes |
| 4 | Select the number of address bytes. |
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 | 262144 | The block erase size. Set Block Erase Size to 0 if Block Erase is not supported. |
Command Set Table | Must be a vaild C symbol | Specify the custom command set table (ospi_b_xspi_command_set_t[]) to use. If provided, all properties for High-speed Mode will be ignored. | |
Command Set Table Length | Length must be an integer greater than or equal to zero. | 0 | Length of the custom command set table. |
Defaults | |||
Defaults > Command Definitions | |||
Page Program Command | Must be a 8-bit OSPI Page Program Command under SPI Mode|Command Definitions | 0x12 | Default command to program a page. |
Read Command | Must be a 8-bit OSPI Read Command under SPI Mode|Command Definitions | 0x13 | Default command to read. |
Write Enable Command | Must be a 16-bit OSPI Write Enable Command under SPI Mode|Command Definitions | 0x06 | Default command to enable write. |
Status Command | Must be a 16-bit OSPI Status Command under SPI Mode|Command Definitions | 0x05 | Default command to query the status of a write or erase command. |
Defaults > Erase Command Definitions | |||
Sector Erase Command | Must be an integer between 0x01 and 0xFFFF, inclusive. | 0x2121 | Default command to erase a sector. The lowwer byte will be used for 1-byte commands. Set to 0 if unused. |
Block Erase Command | Must be an integer between 0x01 and 0xFFFF, inclusive. | 0xDCDC | Default command to erase a block. The lowwer byte will be used for 1-byte commands. Set to 0 if unused. |
Chip Erase Command | Must be an integer between 0x01 and 0xFFFF, inclusive. | 0x6060 | Default command to erase the entire chip. The lowwer byte will be used for 1-byte commands. Set to 0 if unused. |
Defaults > Dummy Cycles | |||
Memory Read Dummy Cycles | Must be an integer between 0 and 31 | 0 | Default memory read dummy cycles |
Status Read Dummy Cycles | Must be an integer between 0 and 31 | 0 | Default status read dummy cycles |
High-speed Mode | |||
High-speed Mode > Auto-Calibration | |||
Data latching delay | Must be a valid non-negative integer with maximum configurable value of 0x1F | 0x08 | If auto-calibration support is enabled, set this to 0 to trigger auto-calibration when appropriate. |
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. |
High-speed Mode > Command Definitions | |||
Page Program Command | Must be a 16-bit OSPI Page Program Command under High-speed Mode|Command Definitions | 0x1212 | The command to program a page in OPI mode. |
Dual Read Command | Must be a 16-bit OSPI Dual Read Command under High-speed Mode|Command Definitions | 0xEEEE | The command to read in High-speed mode (8DTRD). |
Write Enable Command | Must be a 16-bit OSPI Write Enable Command under High-speed Mode|Command Definitions | 0x0606 | The command to enable write in OPI mode. Set to 0 to ignore. |
Status Command | Must be a 16-bit OSPI Status Command under High-speed Mode|Command Definitions | 0x0505 | The command to query the status of a write or erase command in OPI mode. Set to 0 to ignore. |
Sector Erase Command | Must be an integer between 0x01 and 0xFFFF, inclusive. | 0 | The command to erase a sector for high-speed mode. Set to 0 if unused. |
Block Erase Command | Must be an integer between 0x01 and 0xFFFF, inclusive. | 0 | The command to erase a block for high-speed mode. Set to 0 if unused. |
Chip Erase Command | Must be an integer between 0x01 and 0xFFFF, inclusive. | 0 | The command to erase the entire chip for high-speed mode. Set to 0 if unused. |
Protocol |
| Dual data rate OPI (8D-8D-8D) | Select the High-Speed xSPI protocol. |
Command Length Bytes |
| 2 | Command length in bytes |
Memory Read Dummy Cycles | Must be an integer between 0 and 31 | 20 | Memory read dummy cycles |
Status Read Dummy Cycles | Must be an integer between 0 and 31 | 3 | Status read dummy cycles |
Chip Select Timing Setting | |||
Command Interval | Refer to the RA Configuration tool for available options. | 2 | Command execution interval setting in OCTACLK units |
Pull-up Timing |
| No Extension | Signal pull-up timing (CS asserting extention) setting in OCTACLK units |
Pull-down Timing |
| No Extension | Signal pull-down timing (CS negating extention) setting in OCTACLK units |
XiP Mode | |||
XiP Enter Code | Must be an integer between 0 and 255 | 0 | XiP enter code. |
XiP Exit Code | Must be an integer between 0 and 255 | 0 | XiP exit code. |
DOTF | |||
Name | Name must be a valid C symbol | g_ospi_dotf | DOTF Configuration name. |
AES Key | Name must be a valid C symbol | g_ospi_dotf_key | Name of Key variable. |
AES IV | Name must be a valid C symbol | g_ospi_dotf_iv | Name of IV variable |
AES Key Length | MCU Specific Options | Select AES key length | |
Key Format | MCU Specific Options | Select key format | |
Decryption start address | Value must be an integer between 0x80000000 and 0x9FFFFFFF | 0x90000000 | OSPI decryption start address |
Decryption end address | Value must be an integer between 0x80000000 and 0x9FFFFFFF | 0x90001FFF | OSPI decryption end address |
PCLKA is the Octal-SPI bus interface, and PCLKB is used to set OSPI registers.
The signals to the xSPI target device are derived from OCTASPICLK. The OMSCLK signal is OCTASPICLK / 2. Data can be output at the OCTASPICLK rate if protocol mode is set to a Dual Data Rate mode (8D-8D-8D or 4S-4D-4D).
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:
After R_OSPI_B_Open() completes successfully, the xSPI device contents are mapped to address 0x80000000 (bank CS0) or 0x90000000 (bank CS1) and can be read like on-chip flash. Bank CS0 is only accessible from OSPI_B channel/slave 0 and likewise, bank CS1 is only accessible from OSPI_B channel/slave 1. Bank CS0 and CS1 support up to 256 MB of address space each.
If support is enabled, auto-calibration procedures are 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_B_Open() when using a data strobe (DS) mode or changing the SPI protocol to a DS mode using the R_OSPI_B_SpiProtocolSet() API. The appropriate preamble pattern can be written to the desired address using the R_OSPI_B_Write() API while in simple SPI mode (recommended), or a non-DS mode. Ensure that the same address is passed through the configurator. If the xSPI device is already in a DS mode, the preamble pattern must be programmed using the debugger before calling R_OSPI_B_Open().
The preamble pattern is expected to be { 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0x08, 0x00, 0x00, 0xF7, 0xFF, 0x00, 0x08, 0xF7, 0x00, 0xF7 }
.
Chip select latencies can be set through the configurator. The default settings support SPI at minimum latency. In case the driver is opened in SPI mode and will be switched to DOPI mode later using R_OSPI_B_SpiProtocolSet(), please select latencies required for DOPI before calling R_OSPI_B_Open().
OSPI_B supports eXecute in Place (XiP) modes of operation. This can be used for read-only memory-mapped accesses to reduce overall read latency by skipping the command sequence in the xSPI transaction. Separate XiP enter and exit codes may be specified for either attached target device. Upon calling R_OSPI_B_XipEnter(), the associated memory region for the target device is switched to read-only mode and the enter code sent to the device. Calling R_OSPI_B_XipExit() will transmit the exit code and transition the memory region back to read-write access.
Only one flash device should be used after entering XiP mode. Once entered, XiP codes will be transmitted to all attached devices.
Command sets and erase commands may be specified individually for each supported protocol mode. By default, the configurator only supports an alternative command set for DOPI (8D-8D-8D) mode. The command sets cannot be changed during run-time. The appropriate command set will be selected when changing protocol modes. If a command set is not found, it defaults to the SPI command set.
If custom DOPI erase commands are not specified, ensure the erase commands are the appropriate 2-byte DOPI commands. The lower byte will be used for 1-byte command protocols.
Decryption-On-The-Fly is configurable for OSPI Flash and is disabled from the build by default.
When configuring the DOTF options, make sure that the key format is specified.
Using the DOTF feature requires first creating the encrypted blob on the PC and then configuring the DOTF module with the appropriate parameters to allow decryption of the blob once it is programmed into OSPI. Use the Security Key Management Tool (https://www.renesas.com/us/en/software-tool/security-key-management-tool) to create the encrypted blob. Example: To encrypt a 4096 byte area in a input srec file from 0x90000000 to 0x90000FFF using a 128 AES encryption key "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" and iv "00000000000000000000000000000000" use SKMT with the following arguments: skmt.exe /encdotf /keytype "AES-128" /enckey "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" /nonce "00000000000000000000000000000000" /startaddr "90000000" /endaddr "90000FFF" /prg "input.srec" /incplain /output "encrypted_output.srec"
The values for key, iv and decryption area start and end addresses that were used to create the blob using SKMT must be set in the DOTF configuration in FSP.
Make sure that the Key and IV passed into DOTF configuration are 4 byte aligned. This can be done using a compiler alignment attribute as shown below: uint8_t aes_key[] attribute((aligned(4))) = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f };
Developers should be aware of the following limitations when using the OSPI_B driver:
const
) data used with R_OSPI_B_Write()
is word (4-byte) aligned if the DMAC is not being used. If parameter checking is enabled, the source pointer alignment will be verified for calls to R_OSPI_B_Write()
.This is a basic example of minimal use of the OSPI in an application with OctaFlash.
This is an example of using R_OSPI_B_DirectWrite followed by R_OSPI_B_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_B_SpiProtocolSet to change the operating mode from SPI to DOPI 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_B_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.
This is an example of using R_OSPI_B_DirectTransfer to change the attached flash device to a new protocol mode during run time.
This is an example of using custom command sets for 8D-8D-8D and 4S-4S-4S protocol modes.
When using the IAR compiler, OSPI data must be const
qualified to be downloaded by the debugger.
Data Structures | |
struct | ospi_b_timing_setting_t |
struct | ospi_b_xspi_command_set_t |
struct | ospi_b_extended_cfg_t |
struct | ospi_b_instance_ctrl_t |
Enumerations | |
enum | ospi_b_device_number_t |
enum | ospi_b_command_bytes_t |
enum | ospi_b_command_interval_clocks_t |
enum | ospi_b_command_cs_pullup_clocks_t |
enum | ospi_b_command_cs_pulldown_clocks_t |
enum | ospi_b_prefetch_function_t |
enum | ospi_b_combination_function_t |
struct ospi_b_timing_setting_t |
Memory mapped timing
Data Fields | ||
---|---|---|
ospi_b_command_interval_clocks_t | command_to_command_interval | Interval between 2 consecutive commands. |
ospi_b_command_cs_pullup_clocks_t | cs_pullup_lag | Duration to de-assert CS line after the last command. |
ospi_b_command_cs_pulldown_clocks_t | cs_pulldown_lead | Duration to assert CS line before the first command. |
struct ospi_b_xspi_command_set_t |
Command set used for a protocol mode other than normal (1S-1S-1S) SPI.
Data Fields | ||
---|---|---|
spi_flash_protocol_t | protocol | Protocol mode associated with this command set. |
ospi_b_command_bytes_t | command_bytes | Number of command bytes for each command code. |
uint16_t | read_command | Read command. |
uint16_t | page_program_command | Page program/write command. |
uint16_t | write_enable_command | Command to enable write or erase, set to 0x00 to ignore. |
uint16_t | status_command | Command to read the write status, set to 0x00 to ignore. |
uint8_t | read_dummy_cycles | Dummy cycles to be inserted for read commands. |
uint8_t | program_dummy_cycles | Dummy cycles to be inserted for page program commands. |
uint8_t | status_dummy_cycles | Dummy cycles to be inserted for status read commands. |
uint8_t | erase_command_list_length | Length of erase command list. |
spi_flash_erase_command_t const * | p_erase_command_list | List of all erase commands and associated sizes. |
struct ospi_b_extended_cfg_t |
OSPI_B Extended configuration.
Data Fields | ||
---|---|---|
ospi_b_device_number_t | channel | Device number to be used for memory device. |
ospi_b_timing_setting_t const * | p_timing_settings | Memory-mapped timing settings. |
ospi_b_xspi_command_set_t const * | p_xspi_command_set_list | Additional protocol command sets; if additional protocol commands set are not used set this to NULL. |
uint8_t | xspi_command_set_list_length | Number of additional protocol command set defined. |
uint8_t * | p_autocalibration_preamble_pattern_addr | OctaFlash memory address holding the preamble pattern. |
uint8_t | data_latch_delay_clocks | Specify delay between OM_DQS and OM_DQS Strobe. Set to 0 to auto-calibrate. Typical value is 0x80. |
transfer_instance_t const * | p_lower_lvl_transfer | DMA Transfer instance used for data transmission. |
uint8_t | read_dummy_cycles | Dummy cycles to be inserted for read commands. |
uint8_t | program_dummy_cycles | Dummy cycles to be inserted for page program commands. |
uint8_t | status_dummy_cycles | Dummy cycles to be inserted for status read commands. |
struct ospi_b_instance_ctrl_t |
Instance control block. DO NOT INITIALIZE. Initialization occurs when spi_flash_api_t::open is called
OSPI frame to frame interval
Combination function settings
fsp_err_t R_OSPI_B_Open | ( | spi_flash_ctrl_t *const | p_ctrl, |
spi_flash_cfg_t const *const | p_cfg | ||
) |
Open the xSPI device. After the driver is open, the xSPI device can be accessed like internal flash memory.
Implements spi_flash_api_t::open.
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_t R_OSPI_B_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 OctaFlash. API not supported. Use R_OSPI_B_DirectTransfer
Implements spi_flash_api_t::directWrite.
FSP_ERR_UNSUPPORTED | API not supported by OSPI. |
fsp_err_t R_OSPI_B_DirectRead | ( | spi_flash_ctrl_t * | p_ctrl, |
uint8_t *const | p_dest, | ||
uint32_t const | bytes | ||
) |
Reads raw data directly from the OctaFlash. API not supported. Use R_OSPI_B_DirectTransfer.
Implements spi_flash_api_t::directRead.
FSP_ERR_UNSUPPORTED | API not supported by OSPI. |
fsp_err_t R_OSPI_B_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.
Implements spi_flash_api_t::directTransfer.
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_B_XipEnter | ( | spi_flash_ctrl_t * | p_ctrl | ) |
Enters XIP (execute in place) mode.
Implements spi_flash_api_t::xipEnter.
FSP_SUCCESS | XiP mode was entered successfully. |
FSP_ERR_ASSERTION | A required pointer is NULL. |
FSP_ERR_NOT_OPEN | Driver is not opened. |
FSP_ERR_UNSUPPORTED | XiP support is not enabled. |
fsp_err_t R_OSPI_B_XipExit | ( | spi_flash_ctrl_t * | p_ctrl | ) |
Exits XIP (execute in place) mode.
Implements spi_flash_api_t::xipExit.
FSP_SUCCESS | XiP mode was entered successfully. |
FSP_ERR_ASSERTION | A required pointer is NULL. |
FSP_ERR_NOT_OPEN | Driver is not opened. |
FSP_ERR_UNSUPPORTED | XiP support is not enabled. |
fsp_err_t R_OSPI_B_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_SIZE | Insufficient space remaining in page or write length is not a multiple of CPU access size when not using the DMAC. |
FSP_ERR_DEVICE_BUSY | Another Write/Erase transaction is in progress. |
FSP_ERR_WRITE_FAILED | Write operation failed. |
FSP_ERR_INVALID_ADDRESS | Destination or source is not aligned to CPU access alignment when not using the DMAC. |
fsp_err_t R_OSPI_B_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, 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_WRITE_FAILED | Write operation failed. |
fsp_err_t R_OSPI_B_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_t R_OSPI_B_BankSet | ( | spi_flash_ctrl_t * | p_ctrl, |
uint32_t | bank | ||
) |
Selects the bank to access. Use ospi_b_bank_select_t as the bank value.
Implements spi_flash_api_t::bankSet.
FSP_ERR_UNSUPPORTED | This function is unsupported. |
fsp_err_t R_OSPI_B_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 MPU 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_t R_OSPI_B_Close | ( | spi_flash_ctrl_t * | 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. |
fsp_err_t R_OSPI_B_AutoCalibrate | ( | spi_flash_ctrl_t *const | p_ctrl | ) |
AutoCalibrate the OSPI_B DS signal.
Implements spi_flash_api_t::autoCalibrate.
FSP_SUCCESS | Autocalibration completed successfully. |
FSP_ERR_ASSERTION | A required pointer is NULL. |
FSP_ERR_NOT_OPEN | Driver is not opened. |
FSP_ERR_UNSUPPORTED | Autocalibration support is not enabled. |
FSP_ERR_CALIBRATE_FAILED | Failed to perform auto-calibrate. |
fsp_err_t R_OSPI_B_DOTF_Configure | ( | spi_flash_ctrl_t *const | p_ctrl, |
ospi_b_dotf_cfg_t *const | p_dotf_cfg | ||
) |
Configure DOTF
[in] | p_ctrl | Pointer to OSPI specific control structure |
[in] | p_dotf_cfg | Pointer to DOTF configuration structure |
FSP_SUCCESS | DOTF enabled successfully |
FSP_ERR_CRYPTO_SCE_KEY_SET_FAIL | Key initialization failed. |
FSP_ERR_CRYPTO_SCE_FAIL | Key wrapping failed. |
FSP_ERR_INVALID_ARGUMENT | Invalid key type argument. |
FSP_ERR_UNSUPPORTED | DOTF support is not enabled |