![]() |
RZ Flexible Software Package Documentation
Release v4.2.0
|
|
Functions | |
| fsp_err_t | R_SPI_B_Open (spi_ctrl_t *p_api_ctrl, spi_cfg_t const *const p_cfg) |
| fsp_err_t | R_SPI_B_Read (spi_ctrl_t *const p_api_ctrl, void *p_dest, uint32_t const length, spi_bit_width_t const bit_width) |
| fsp_err_t | R_SPI_B_Write (spi_ctrl_t *const p_api_ctrl, void const *p_src, uint32_t const length, spi_bit_width_t const bit_width) |
| fsp_err_t | R_SPI_B_WriteRead (spi_ctrl_t *const p_api_ctrl, void const *p_src, void *p_dest, uint32_t const length, spi_bit_width_t const bit_width) |
| fsp_err_t | R_SPI_B_Close (spi_ctrl_t *const p_api_ctrl) |
| fsp_err_t | R_SPI_B_CalculateBitrate (uint32_t bitrate, spi_b_clock_source_t clock_source, rspck_div_setting_t *spck_div) |
| fsp_err_t | R_SPI_B_CallbackSet (spi_ctrl_t *const p_api_ctrl, void(*p_callback)(spi_callback_args_t *), void *const p_context, spi_callback_args_t *const p_callback_memory) |
Driver for the SPI peripheral on RZ MPUs. This module implements the SPI Interface.
| Configuration | Options | Default | Description |
|---|---|---|---|
| Parameter Checking |
| Default (BSP) | If selected code for parameter checking is included in the build. |
| Enable Support for using DMAC |
| Enabled | If enabled, DMAC instances will be included in the build for both transmission and reception. |
| Enable Transmitting from RXI Interrupt |
| Disabled | If enabled, all operations will be handled from the RX (receive) interrupt. This setting only provides a performance boost when DMAC is not used. In addition, Transmit Only mode is not supported when this configuration is enabled. |
| Configuration | Options | Default | Description |
|---|---|---|---|
| Name | Name must be a valid C symbol | g_spi0 | Module name. |
| Channel | Value must be a non-negative integer | 0 | Select the SPI channel. |
| Receive Interrupt Priority | Value must be an integer between 0 and 255 | 12 | Select the interrupt priority for all SPI interrupts. |
| Transmit Buffer Empty Interrupt Priority | Value must be an integer between 0 and 255 | 12 | Select the interrupt priority for all SPI interrupts. |
| Transfer Complete Interrupt Priority | Value must be an integer between 0 and 255 | 12 | Select the interrupt priority for all SPI interrupts. |
| Error Interrupt Priority | Value must be an integer between 0 and 255 | 12 | Select the interrupt priority for all SPI interrupts. |
| Operating Mode |
| Master | Select the SPI operating mode. |
| Clock Phase |
| Data sampling on odd edge, data variation on even edge | Select the clock edge to sample data. |
| Clock Polarity |
| Low when idle | Select clock level when idle. |
| Mode Fault Error |
| Disable | Detect master/slave mode conflicts. |
| Bit Order |
| MSB First | Select the data bit order. |
| Callback | Name must be a valid C symbol | spi_callback | A user callback function can be provided. If this callback function is provided, it will be called from the interrupt service routine (ISR). |
| SPI Mode |
| Clock Synchronous Operation | Select the clock sync mode. |
| Full or Transmit Only Mode |
| Full Duplex | Select Full Duplex or Transmit Only Mode. |
| Slave Select Polarity |
| Active Low | Select the slave select active level. |
| Select SSL(Slave Select) |
| SSL0 | Select which slave to use. |
| MOSI Idle State |
| MOSI Idle Value Fixing Disable | Select the MOSI idle level if MOSI idle is enabled. |
| Parity Mode |
| Disabled | Select the parity mode if parity is enabled. |
| Byte Swapping |
| Disable | Select the byte swap mode for 16/32-Bit Data Frames. |
| Clock Source | MCU Specific Options | Select the clock source for communication. | |
| Bitrate | Value must be an integer greater than 0 | 16000000 | Enter the desired bitrate, change the bitrate to a value supported by MPU. If the requested bitrate cannot be achieved, the settings with the largest possible value that is less than or equal to the requested bitrate is used. The actual bitrate is printed in a comment in the generated spi_extended_cfg_t structure. |
| Clock Delay |
| 1 Clock | Configure the number of SPI clock cycles before each data frame. |
| SSL Negation Delay |
| 1 Clock | Configure the number of SPI clock cycles after each data frame. |
| Next Access Delay |
| 1 Clock | Configure the number of SPI clock cycles between each data frame. |
| SSL Level Keep |
| Disable | Select whether to negate the SSL level for each frame transfer. |
| Transmit FIFO Threshold | Value must be an integer between 0 and 15 | 0 | Select the transmit FIFO threshold that is the basis for the transmit buffer empty interrupt generation. |
| Receive FIFO Threshold | Value must be an integer between 0 and 15 | 0 | Select the receive FIFO threshold that is the basis for the receive buffer empty interrupt generation. |
| Receive Data Ready Detect Adjustment | Value must be an integer between 0 and 255 | 0 | Configure the timing to detect the received data ready. |
| Master Receive Clock Delay Adjustment |
| Adjust with Analog Delay | Select the master receive clock. |
| Max Analog Delay |
| No delay | Select the max analog delay. |
| Digital Delay |
| 0 Clocks | Select the digital delay. |
The SPI peripheral uses the following clock for communication and internal operations.
| MPU Group | Peripheral Bus Clock | Communication Operation Clock |
|---|---|---|
| RZ/G3E | P4CLK | P4CLK |
| RZ/G3L | P3CLK | Channel 0: P17CLK Channel 1: P18CLK Channel 2: P19CLK |
| RZ/G3SE | P3CLK | Channel 0: P17CLK Channel 1: P18CLK Channel 2: P19CLK |
This module uses MOSI, MISO, RSPCK, and SSL pins to communicate with on board devices.
At high bitrates, interrupts may not be able to service transfers fast enough. In master mode this means there will be a delay between each data frame. In slave mode this could result in TX Underrun and RX Overflow errors.
In order to improve performance at high bitrates, it is recommended that the instance be configured to service transfers using the DMAC.
Another way to improve performance is to transfer the data in 16/32 bit wide data frames when possible. A typical use-case where this is possible is when reading/writing to a block device.
After every data frame the SPI peripheral generates a transmit buffer empty interrupt and a receive buffer full interrupt. It is possible to configure the driver to handle transmit buffer empty interrupts in the receive buffer full ISR. This only improves performance when the DMAC is not being used.
In master mode, if the Receive Buffer Full Interrupts are not handled fast enough, instead of generating a RX Overflow error, the last clock cycle will be stretched until the receive buffer is read.
When parity mode is configured, the LSB of each data frame is used as a parity bit. When odd parity is selected, the LSB is set such that there are an odd number of ones in the data frame. When even parity is selected, the LSB is set such that there are an even number of ones in the data frame.
Developers should be aware of the following limitations when using the SPI:
This is a basic example of minimal use of the SPI in an application.
This is an example of communicating with multiple slave devices by asserting SSL in software.
This example demonstrates how to set the SPI clock divisors at runtime.
Classes | |
| struct | st_rspck_div_setting |
| struct | st_spi_b_extended_cfg |
| struct | st_spi_b_instance_ctrl |
Typedefs | |
| typedef struct st_rspck_div_setting | rspck_div_setting_t |
| typedef struct st_spi_b_extended_cfg | spi_b_extended_cfg_t |
| typedef struct st_spi_b_instance_ctrl | spi_b_instance_ctrl_t |
Enumerations | |
| enum | spi_b_ssl_mode_t |
| enum | spi_b_communication_t |
| enum | spi_b_ssl_polarity_t |
| enum | spi_b_ssl_select_t |
| enum | spi_b_mosi_idle_value_fixing_t |
| enum | spi_b_parity_t |
| enum | spi_b_byte_swap_t |
| enum | spi_b_delay_count_t |
| enum | spi_b_clock_source_t |
| enum | spi_b_master_receive_clock_t |
| enum | spi_b_analog_delay_t |
| enum | spi_b_digital_delay_t |
| enum | spi_b_ssl_level_keep_t |
| struct RZG::st_rspck_div_setting |
| struct RZG::st_spi_b_extended_cfg |
Extended SPI interface configuration
| Class Members | ||
|---|---|---|
| spi_b_ssl_mode_t | spi_clksyn | Select SPI or Clock Synchronous mode operation. |
| spi_b_communication_t | spi_comm | Select full-duplex or transmit-only communication. |
| spi_b_ssl_polarity_t | ssl_polarity | Select SSLn signal polarity. |
| spi_b_ssl_select_t | ssl_select | Select which slave to use: 0-SSL0, 1-SSL1, 2-SSL2, 3-SSL3. |
| spi_b_mosi_idle_value_fixing_t | mosi_idle | Select MOSI idle fixed value and selection. |
| spi_b_parity_t | parity | Select parity and enable/disable parity. |
| spi_b_byte_swap_t | byte_swap | Select byte swap mode. |
| spi_b_clock_source_t | clock_source | Communication clock source (TCLK). |
| rspck_div_setting_t | spck_div | Register values for configuring the SPI Clock Divider. |
| spi_b_delay_count_t | spck_delay | SPI Clock Delay Register Setting. |
| spi_b_delay_count_t | ssl_negation_delay | SPI Slave Select Negation Delay Register Setting. |
| spi_b_delay_count_t | next_access_delay | SPI Next-Access Delay Register Setting. |
| spi_b_ssl_level_keep_t | ssl_level_keep | Select SSL signal level keep mode. |
| uint8_t | transmit_fifo_threshold | Transmit FIFO threshold (0~15) |
| uint8_t | receive_fifo_threshold | Receive FIFO threshold (0~15) |
| uint8_t | receive_data_ready_detect_adjustment | Receive data ready detect timing (0~255 counts of operation clock) |
| spi_b_master_receive_clock_t | master_receive_clock | SPI master receive clock. |
| spi_b_analog_delay_t | analog_delay | SPI max analog delay. |
| spi_b_digital_delay_t | digital_delay | SPI digital delay. |
| void * | p_reg | Register base address for specified channel. |
| struct RZG::st_spi_b_instance_ctrl |
Channel control block. DO NOT INITIALIZE. Initialization occurs when spi_api_t::open is called.
Public Attributes | |
| uint32_t | open |
| Indicates whether the open() API has been successfully called. | |
| spi_cfg_t const * | p_cfg |
| Pointer to instance configuration. | |
| R_SPI_B0_Type * | p_regs |
| Base register for this channel. | |
| void const * | p_tx_data |
| Buffer to transmit. | |
| void * | p_rx_data |
| Buffer to receive. | |
| uint32_t | tx_count |
| Number of Data Frames to transfer (8-bit, 16-bit, 32-bit) | |
| uint32_t | rx_count |
| Number of Data Frames to transfer (8-bit, 16-bit, 32-bit) | |
| uint32_t | count |
| Number of Data Frames to transfer (8-bit, 16-bit, 32-bit) | |
| spi_bit_width_t | bit_width |
| Bits per Data frame (8-bit, 16-bit, 32-bit) | |
| typedef struct st_rspck_div_setting rspck_div_setting_t |
SPI Clock Divider settings. Please refer to the struct st_rspck_div_setting.
| typedef struct st_spi_b_extended_cfg spi_b_extended_cfg_t |
Extended SPI interface configuration. Please refer to the struct st_spi_b_extended_cfg.
| typedef struct st_spi_b_instance_ctrl spi_b_instance_ctrl_t |
Channel control block. DO NOT INITIALIZE. Initialization occurs when spi_api_t::open is called. Please refer to the struct st_spi_b_instance_ctrl.
| enum spi_b_ssl_mode_t |
| enum spi_b_ssl_polarity_t |
| enum spi_b_ssl_select_t |
| enum spi_b_parity_t |
| enum spi_b_byte_swap_t |
| enum spi_b_delay_count_t |
Delay count for SPI delay settings.
| enum spi_b_clock_source_t |
SPI communication clock source.
| enum spi_b_analog_delay_t |
SPI max analog delay.
SPI digital delay.
| fsp_err_t R_SPI_B_Open | ( | spi_ctrl_t * | p_api_ctrl, |
| spi_cfg_t const *const | p_cfg | ||
| ) |
This functions initializes a channel for SPI communication mode. Implements spi_api_t::open.
This function performs the following tasks:
| FSP_SUCCESS | Channel initialized successfully. |
| FSP_ERR_ALREADY_OPEN | Instance was already initialized. |
| FSP_ERR_ASSERTION | An invalid argument was given in the configuration structure. |
| FSP_ERR_UNSUPPORTED | A requested setting is not possible on this device with the current build configuration. |
| FSP_ERR_IP_CHANNEL_NOT_PRESENT | The channel number is invalid. |
| fsp_err_t R_SPI_B_Read | ( | spi_ctrl_t *const | p_api_ctrl, |
| void * | p_dest, | ||
| uint32_t const | length, | ||
| spi_bit_width_t const | bit_width | ||
| ) |
This function receives data from a SPI device. Implements spi_api_t::read.
The function performs the following tasks:
| FSP_SUCCESS | Read operation successfully completed. |
| FSP_ERR_ASSERTION | NULL pointer to control or destination parameters or transfer length is zero. |
| FSP_ERR_NOT_OPEN | The channel has not been opened. Open channel first. |
| FSP_ERR_IN_USE | A transfer is already in progress. |
| fsp_err_t R_SPI_B_Write | ( | spi_ctrl_t *const | p_api_ctrl, |
| void const * | p_src, | ||
| uint32_t const | length, | ||
| spi_bit_width_t const | bit_width | ||
| ) |
This function transmits data to a SPI device using the TX Only Communications Operation Mode. Implements spi_api_t::write.
The function performs the following tasks:
| FSP_SUCCESS | Write operation successfully completed. |
| FSP_ERR_ASSERTION | NULL pointer to control or source parameters or transfer length is zero. |
| FSP_ERR_NOT_OPEN | The channel has not been opened. Open the channel first. |
| FSP_ERR_IN_USE | A transfer is already in progress. |
| fsp_err_t R_SPI_B_WriteRead | ( | spi_ctrl_t *const | p_api_ctrl, |
| void const * | p_src, | ||
| void * | p_dest, | ||
| uint32_t const | length, | ||
| spi_bit_width_t const | bit_width | ||
| ) |
This function simultaneously transmits and receive data. Implements spi_api_t::writeRead.
The function performs the following tasks:
| FSP_SUCCESS | Write operation successfully completed. |
| FSP_ERR_ASSERTION | NULL pointer to control, source or destination parameters or transfer length is zero. |
| FSP_ERR_NOT_OPEN | The channel has not been opened. Open the channel first. |
| FSP_ERR_IN_USE | A transfer is already in progress. |
| fsp_err_t R_SPI_B_Close | ( | spi_ctrl_t *const | p_api_ctrl | ) |
This function manages the closing of a channel by the following task. Implements spi_api_t::close.
Disables SPI operations by disabling the SPI bus.
| FSP_SUCCESS | Channel successfully closed. |
| FSP_ERR_ASSERTION | A required pointer argument is NULL. |
| FSP_ERR_NOT_OPEN | The channel has not been opened. Open the channel first. |
| fsp_err_t R_SPI_B_CalculateBitrate | ( | uint32_t | bitrate, |
| spi_b_clock_source_t | clock_source, | ||
| rspck_div_setting_t * | spck_div | ||
| ) |
Calculates the SPBR register value and the BRDV bits for a desired bitrate. If the desired bitrate is faster than the maximum bitrate, than the bitrate is set to the maximum bitrate. If the desired bitrate is slower than the minimum bitrate, than an error is returned.
| [in] | bitrate | Desired bitrate |
| [in] | clock_source | SPI communication clock source to be used |
| [out] | spck_div | Memory location to store bitrate register settings. |
| FSP_SUCCESS | Valid spbr and brdv values were calculated |
| FSP_ERR_UNSUPPORTED | Bitrate is not achievable |
| fsp_err_t R_SPI_B_CallbackSet | ( | spi_ctrl_t *const | p_api_ctrl, |
| void(*)(spi_callback_args_t *) | p_callback, | ||
| void *const | p_context, | ||
| spi_callback_args_t *const | p_callback_memory | ||
| ) |
Updates the user callback and has option of providing memory for callback structure. Implements spi_api_t::callbackSet
| FSP_SUCCESS | Callback updated successfully. |
| FSP_ERR_ASSERTION | A required pointer is NULL. |
| FSP_ERR_NOT_OPEN | The control block has not been opened. |
| FSP_ERR_NO_CALLBACK_MEMORY | p_callback is non-secure and p_callback_memory is either secure or NULL. |