![]() |
Synergy Software Package User's Manual
|
The RSPI HAL module provides a high-level API for serial communication using the SPI protocol. The module supports the SPI (formerly known as RSPI) peripheral available on the Synergy microcontroller hardware. The RSPI HAL module supports standard SPI master and Slave mode communications functions. Callbacks are provided for transfer events. The RSPI HAL module is enabled with data transfer support by incorporating the data transfer controller module of the MCU; this performs SPI transfers through the DTC without requiring interrupt processing for each frame.
The following hardware features are, or are not, supported by SSP for the RSPI.
Legend:
| Symbol | Meaning |
|---|---|
| ✓ | Available (Tested) |
| ⌧ | Not Available (Not tested/not functional or both) |
| N/A | Not supported by MCU |
| MCU Group | SPI Operation mode | Clock Syn mode | Full-duplex or transmit-only can be selected | Switching of the polarity and phase | Master and Slave mode | MSB first/LSB first selectable |
|---|---|---|---|---|---|---|
| S124 | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| S128 | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| S1JA | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| S3A1 | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| S3A3 | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| S3A6 | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| S3A7 | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| S5D3 | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| S5D5 | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| S5D9 | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| S7G2 | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| MCU Group | Transfer length - 8/16/32 | Up to four frames can be transferred in one round | Bit rate configuration | Double buffer configuration | Error detection | SSL control function |
|---|---|---|---|---|---|---|
| S124 | ✓ | ⌧ | ✓ | ⌧ | ✓ | ✓ |
| S128 | ✓ | ⌧ | ✓ | ⌧ | ✓ | ✓ |
| S1JA | ✓ | ⌧ | ✓ | ⌧ | ✓ | ✓ |
| S3A1 | ✓ | ⌧ | ✓ | ⌧ | ✓ | ✓ |
| S3A3 | ✓ | ⌧ | ✓ | ⌧ | ✓ | ✓ |
| S3A6 | ✓ | ⌧ | ✓ | ⌧ | ✓ | ✓ |
| S3A7 | ✓ | ⌧ | ✓ | ⌧ | ✓ | ✓ |
| S5D3 | ✓ | ⌧ | ✓ | ⌧ | ✓ | ✓ |
| S5D5 | ✓ | ⌧ | ✓ | ⌧ | ✓ | ✓ |
| S5D9 | ✓ | ⌧ | ✓ | ⌧ | ✓ | ✓ |
| S7G2 | ✓ | ⌧ | ✓ | ⌧ | ✓ | ✓ |
| MCU Group | Transfer of up to eight commands | All Interrupt sources | DTC Support | Event link function through ELC HAL driver | Function for switching between CMOS output and open drain output | Loopback mode |
|---|---|---|---|---|---|---|
| S124 | ⌧ | ✓ | ✓32-bit transfer | ⌧ | ✓ | ✓ |
| S128 | ⌧ | ✓ | ✓32-bit transfer | ⌧ | ✓ | ✓ |
| S1JA | ⌧ | ✓ | ✓32-bit transfer | ⌧ | ✓ | ✓ |
| S3A1 | ⌧ | ✓ | ✓32-bit transfer | ⌧ | ✓ | ✓ |
| S3A3 | ⌧ | ✓ | ✓32-bit transfer | ⌧ | ✓ | ✓ |
| S3A6 | ⌧ | ✓ | ✓32-bit transfer | ⌧ | ✓ | ✓ |
| S3A7 | ⌧ | ✓ | ✓32-bit transfer | ⌧ | ✓ | ✓ |
| S5D3 | ⌧ | ✓ | ✓32-bit transfer | ⌧ | ✓ | ✓ |
| S5D5 | ⌧ | ✓ | ✓32-bit transfer | ⌧ | ✓ | ✓ |
| S5D9 | ⌧ | ✓ | ✓32-bit transfer | ⌧ | ✓ | ✓ |
| S7G2 | ⌧ | ✓ | ✓32-bit transfer | ⌧ | ✓ | ✓ |
| MCU Group | Module Stop Function | Multi-master mode |
|---|---|---|
| S124 | ⌧ | ⌧ |
| S128 | ⌧ | ⌧ |
| S1JA | ⌧ | ⌧ |
| S3A1 | ⌧ | ⌧ |
| S3A3 | ⌧ | ⌧ |
| S3A6 | ⌧ | ⌧ |
| S3A7 | ⌧ | ⌧ |
| S5D3 | ⌧ | ⌧ |
| S5D5 | ⌧ | ⌧ |
| S5D9 | ⌧ | ⌧ |
| S7G2 | ⌧ | ⌧ |
The RSPI HAL module defines API functions for opening, closing, reading, writing and other useful functions. A complete list of the available APIs, an example API call and a short description of each can be found in the following table. A table of status return values follows the API summary table.
RSPI HAL Module API Summary
| Function Name | Example API Call and Description |
|---|---|
| .open | g_spi.p_api ->open(g_spi.p_cntl, g_spi.p_cfg);Open a designated SPI device. |
| .read | g_spi.p_api->read(g_spi.p_ctrl, dst16, length, SPI_BIT_WIDTH_16_BITS);Receive data from SPI device. |
| .write | g_spi.p_api->write (g_spi.p_ctrl, source, length, SPI_BIT_WIDTH_8_BITS);Transmit data to SPI device |
| .writeRead | g_spi.p_api ->writeRead (g_spi.p_cntl, &source, &destination, length, SPI_BIT_WIDTH_8_BITS, TX_WAIT_FOREVER);Simultaneously transmits data to an SPI device, while receiving data from an SPI device (full duplex). The writeRead API fetches the mutex object, handles SPI data transmission at SPI HAL layer, and receives data from the SPI HAL layer. The API uses the event flag wait to synchronize to complete the data transfer. |
| .close | g_spi.p_api->close(g_spi,p_ctrl)Disable the SPI device designated by the control handle and close the RTOS services used by the bus if no devices are connected to the bus. This function removes power to the SPI channel designated by the handle and disables the associated interrupts. |
| .versionGet | g_spi.p_api ->versionGet (&version);Get the version information of the underlying driver. |
Status Return Values
| Name | Description |
|---|---|
| SSP_SUCCESS | Function completed successfully |
| SSP_ERR_INVALID_MODE | Invalid mode |
| SSP_ERR_INVALID_CHANNEL | Invalid channel |
| SSP_ERR_IN_USE | In-use error |
| SSP_ERR_INVALID_ARGUMENT | Invalid argument |
| SSP_ERR_QUEUE_UNAVAILABLE | Queue unavailable |
| SSP_ERR_INVALID_POINTER | Invalid pointer |
| SSP_ERR_INTERNAL | Internal error |
| SSP_ERR_TRANSFER_ABORTED | Transfer aborted |
| SSP_ERR_MODE_FAULT | Mode fault |
| SSP_ERR_READ_OVF | Read overflow |
| SSP_ERR_PARITY | Parity error |
| SSP_ERR_OVERRUN | Overrun error |
| SSP_ERR_UNDEF | Unknown error |
| SSP_ERR_TIMEOUT | Timeout error |
| SSP_ERR_NOT_OPEN | Device not opened |
The RSPI HAL module enables communication with a peripheral device using the SPI communications protocol. After opening the module instance, the module handle is used to perform various transfer operations. The device control handle will be used within the API calls to indicate the specific SPI device with which to communicate.
The Driver allows the application program to:
The module also provides support for callbacks. The callback functions are called with the following events spi_event_t
The RSPI HAL module supports 8, 16 and 32-bit data transfers. The module supports GPIO pins configured as chip selects. In addition, the SPI peripheral supports dedicated chip select signal, SSL. When the SSL pin is enabled in the SPI peripheral, chip select handling is performed by the hardware.
Clock settings:
The SPI peripheral uses the PCLKA as its clock source. You can set the PCLKA frequency using the clock configurator in e2 studio or the CGC Interface at run-time.
IO Port settings:
To use with the SPI peripheral, the I/O port pin(s) used as output pins must be configured as SPI peripheral pins in the pin configurator. If you are using an external chip select, configure Chip select pin as GPIO output.
Extended configuration:
A number of extended hardware specific configurations are present for SPI Driver.
While configuring the RSPI HAL drivers, setting the interrupts to different priority levels could result in improper operation.
The module is enabled with a data transfer support by incorporating the Data Transfer Controller module of the MCU. This performs SPI transfers through the DTC without the intervention of the CPU.
In the application, data transfers over the DTC are used in the same way as normal SPI transfers. To enable DTC transfers, add the DTC module under the RSPI HAL module.
The RSPI HAL module supports 8-, 16-, and 32-bit data transfers in both CPU and DTC-based transfer modes. 16- and 32-bit transfers will be endian swapped.
The RSPI HAL drivers also provide supports swapping oftransmit/receive data in byte units for both 16-bit and 32-bit data transfer (big endian to little endian).This feature is applicable only for S5 series MCUs.
The RSPI HAL module supports run time configuration of 8-, 16- and 32-bit data transfers for both CPU and DTC data transfer modes. The DTC transfer size can be any irrespective of user API bit-width.
Performance Notes
The RSPI HAL module can be configured for several different modes, each with different performance characteristics. DTC transfers take slightly longer to setup than CPU-based transfers due to resetting the DTC, but DTC transfers offer greater performance for transfers larger than 1 frame because no intervention is required from the CPU.
Write operations will configure the module for transmit-only mode, disabling the receive interrupt and ignoring incoming data. CPU-based write operations at high bitrates can result in the transmit ISR being constantly called, blocking other code from running. spi_api_t::writeRead and spi_api_t::read operations will configure the module for full duplex mode.
There is a lower limit of 3 SPI clock cycles between transfers resulting in an effective bitrate slower than configured. At high bitrates, the time between transfers can be longer, especially for CPU-based transfers.
The module will wait for the hardware to enter an idle state when in master mode, or all data to be transmitted or received when in slave mode, before invoking the callback.
This section describes how to include the SPI HAL Module in an application using the SSP configurator.
To add the SPI Driver to an application, simply add it to a thread using the stacks selection sequence given in the following table. (The default name for the SPI Driver is g_spi0. This name can be changed in the associated Properties window.)
RSPI HAL Module Selection Sequence
| Resource | ISDE Tab | Stacks Selection Sequence |
|---|---|---|
| g_spi0 SPI Driver on r_rspi | Threads | New Stack> Driver> Connectivity> SPI Driver on r_rspi |
When the SPI Driver on r_rspi is added to the thread stack as shown in the following figure, the configurator automatically adds any needed lower‑level modules. Any modules needing additional configuration information have the box text highlighted in Red. Modules with a Gray band are individual modules that stand alone. Modules with a Blue band are shared or common; they need only be added once and can be used by multiple stacks. Modules with a Pink band can require the selection of lower-level modules; these are either optional or recommended. (This is indicated in the block with the inclusion of this text.) If the addition of lower-level modules is required, the module description include Add in the text. Clicking on any Pink banded modules brings up the New icon and displays possible choices.
The SPI HAL Module must be configured by the user for the desired operation. The available configuration settings and defaults for all the user-accessible properties are given in the properties tab within the SSP configurator and are shown in the following tables for easy reference. Only properties that can be changed without causing conflicts are available for modification. Other properties are locked and not available for changes and are identified with a lock icon for the locked property in the Properties window in the ISDE. This approach simplifies the configuration process and makes it much less error-prone than previous manual approaches to configuration. The available configuration settings and defaults for all the user-accessible properties are given in the Properties tab within the SSP Configurator and are shown in the following tables for easy reference.
Configuration Settings for the RSPI HAL Module on r_rspi
| ISDE Property | Value | Description |
|---|---|---|
| Parameter Checking | BSP, Enabled, Disabled Default: BSP | Enable or disable the parameter error checking. |
| Name | g_spi0 | Module name. |
| Channel | 0 | SCI or SPI Channel number to which the device has been connected. |
| Operating Mode | Master, Slave Default: Master | Configure as a Master or Slave device. |
| Clock Phase | Data sampling on odd edge, data variation on even edge/Data sampling on even edge, data variation on odd edge Default: Data sampling on odd edge, data variation on even edge | Data sampling on odd or even clock edge. Note: If CPHA is set to 0 in slave mode, slave select should not be fixed at active state and burst transfer should not be performed. |
| Clock Polarity | Low when idle, High when idle Default: Low when idle | Clock level when idle. |
| Mode Fault Error | Enable, Disable Default: Disable | Indicates Mode fault error (master/slave conflict) flag. |
| Bit Order | MSB First, LSB First Default: MSB First | Select transmit order MSB/LSB first |
| Bitrate | 500000 | Transmission or reception rate. Bits per second. |
| Callback | NULL | Optional Callback function pointer. |
| SPI Mode | SPI Operation, Clock synchronous operation Default: SPI Operation | Select spi or clock syn mode operation. |
| SPI Communication Mode | Full Duplex, Transmit Only Default: Full Duplex | Select full-duplex or transmit-only communication. |
| Slave Select Polarity(SSL) | Active Low, Active High Default: Active Low | Select SSL signal polarity. |
| Select Loopback1 | Normal, Inverted Default: Normal | Select loopback1. |
| Select Loopback2 | Normal, Inverted Default: Normal | Select loopback2. |
| Enable MOSI Idle State | Enable, Disable Default: Disable | Select MOSI idle fixed value and selection. |
| MOSI Ildle State | MOSI Low, MOSI High Default: MOSI Low | Select mosi idle fixed value and selection. |
| Enable Parity | Enable, Disable Default: Disable | Enable/disable parity. |
| Parity Mode | Parity Odd, Parity Even Default: Parity Odd | Select parity. |
| Select SSL Level After Transfer | SSL Level Keep, SSL Level Do Not Keep Default: SSL Level Do Not Keep | Select SSL level after transfer completion; 0-negate; 1-keep. Note: If CPHA = 0 in slave mode, slave select level after transfer should not be set to SSL level Keep. |
| Clock Delay Enable | Clock Delay Enable, Clock Delay Disable Default: Clock Delay Disable | Clock delay enable selection. |
| Clock Delay Count | Clock Delay 1 thru 8 RSPCK Default: Clock Delay 1 RSPCK | Clock delay count selection. |
| SSL Negation Delay Enable | Negation Delay Enable, Negation Delay Disable Default: Negation Delay Disable | SSL negation delay enable selection. |
| Negation Delay Count | Negation Delay 1 thru 8 RSPCK Default: Negation Delay 1 RSPCK | Negation delay count selection. |
| Next Access Delay Enable | Next Access Delay Enable, Next Access Delay Disable Default: Next Access Delay Disable | Next access delay enable selection. |
| Next Access Delay Count | Next Access Delay 1 thru 8 RSPCK Default: Next Access Delay 1 RSPCK | Next access delay count selection. |
| Receive Interrupt Priority | Priority 0 (highest), Priority 1:2, Priority 3 (lowest - not valid if using ThreadX) Default: Priority 2 | Receive interrupt priority selection. |
| Transmit Interrupt Priority | Priority 0 (highest), Priority 1:2, Priority 3 (lowest - not valid if using ThreadX) Default: Priority 2 | Transmit interrupt priority selection. |
| Transmit End Interrupt Priority | Priority 0 (highest), Priority 1:2, Priority 3 (lowest - not valid if using ThreadX) Default: Priority 2 | Transmit end interrupt priority selection. |
| Error Interrupt Priority | Priority 0 (highest), Priority 1:2, Priority 3 (lowest - not valid if using ThreadX) Default: Priority 2 | Error interrupt priority selection. |
| Byte Swap(Only for S5 series MCUs)Disable | Enable, Disable Default: Disable | Enable byte swapping (applicable only for S5 series MCUs). |
Typically, only a small number of settings must be modified from the default for lower level drivers as indicated via the red text in the thread stack block. Notice that some of the configuration properties must be set to a certain value for proper framework operation and will be locked to prevent user modification. The following tables identify all the settings within the properties section for the module:
Configuration Settings for the Transfer Driver on r_dtc Event SPI0 TXI
| ISDE Property | Value | Description |
|---|---|---|
| Parameter Checking | BSP, Enabled, Disabled Default: BSP | Selects if code for parameter checking is to be included in the build. |
| Software Start | Enabled, Disabled Default: Disabled | Software start selection. |
| Linker section to keep DTC vector table | .ssp_dtc_vector_table | Linker section to keep DTC vector table selection. |
| Name | g_transfer0 | Module name. |
| Mode | Normal | Mode selection. |
| Transfer Size | 1 Byte, 2 Bytes, 4 Bytes Default: 2 Bytes | Transfer size selection. |
| Destination Address Mode | Fixed | Destination address mode selection. |
| Source Address Mode | Incremented | Source address mode selection. |
| Repeat Area (Unused in Normal Mode | Source | Repeat area selection. |
| Interrupt Frequency | After all transfers have completed | |
| Destination Pointer | NULL | Destination pointer selection. |
| Source Pointer | NULL | Source pointer selection. |
| Number of Transfers | 0 | Number of transfers selection. |
| Number of Blocks (Valid only in Block Mode) | 0 | Number of blocks selection. |
| Activation Source (Must enable IRQ) | Event SPI0 TXI | Activation source selection. |
| Auto Enable | False | Auto enable selection. |
| Callback (Only valid with Software start) | NULL | Callback selection. |
| ELC Software Event Interrupt Priority | Priority 0 (highest), Priority 1:2, Priority 3 (lowest - not valid if using ThreadX) Default: Disabled | ELC Software Event interrupt priority selection. |
Configuration Settings for the Transfer Driver on r_dtc Event SPI0 RXI
| ISDE Property | Value | Description |
|---|---|---|
| Parameter Checking | BSP, Enabled, Disabled Default: BSP | Selects if code for parameter checking is to be included in the build. |
| Software Start | Enabled, Disabled Default: Disabled | Software start selection. |
| Linker section to keep DTC vector table | .ssp_dtc_vector_table | Linker section to keep DTC vector table selection. |
| Name | g_transfer1 | Module name. |
| Mode | Normal | Mode selection. |
| Transfer Size | 1 Byte, 2 Bytes, 4 Bytes Default: 2 Bytes | Transfer size selection. |
| Destination Address Mode | Incremented | Destination address mode selection. |
| Source Address Mode | Fixed | Source address mode selection. |
| Repeat Area (Unused in Normal Mode | Destination | Repeat area selection. |
| Interrupt Frequency | After all transfers have completed | Interrupt frequency selection. |
| Destination Pointer | NULL | Destination pointer selection. |
| Source Pointer | NULL | Source pointer selection. |
| Number of Transfers | 0 | Number of transfers selection. |
| Number of Blocks (Valid only in Block Mode) | 0 | Number of blocks selection. |
| Activation Source (Must enable IRQ) | Event SPI0 RXI | Activation source selection. |
| Auto Enable | FALSE | Auto enable selection. |
| Callback (Only valid with Software start) | NULL | Callback selection. |
| ELC Software Event Interrupt Priority | Priority 0 (highest), Priority 1:2, Priority 3 (lowest - not valid if using ThreadX) Default: Disabled | ELC Software Event interrupt priority selection. |
The SPI peripheral is clocked via Peripheral Clock A (PCLKA). The clock frequencies are configurable in the ISDE by using the Clocks Tab in the configurator. Invalid selections are indicated in red when selected. Ensure that desired SPI bitrate can be achieved with the stated value of PCLKA. The ISDE will not be indicated if the specified bitrate is not achievable. At run time, the SPI driver will attempt to configure the SPI peripheral to the correct bitrate and will return an error if the desired bitrate cannot be set. The bitrate is calculated via the equations in the table below. If the result of the equation (n) is in the range of 0 to 255, then the bit rate can be achieved.
Baud Rate Calculation Equations
| SPI HAL | Bitrate calculation | Description |
|---|---|---|
| SPI on SPI |
| n = Peripheral register value. This has to be in the range of 0 to 255 PLCKA = value of PLCKA in MHz N = 0, 1, 2 or 3 B = Desired Bit Rate |
The SPI peripheral module uses pins on the MCU to communicate to external devices. I/O pins must be selected and configured as required by the external device. The following table illustrates the method for selecting the pins within the SSP configuration window and the subsequent table illustrates an example listing a selection for SPI pins:
Pin Selection Sequence for SPI HAL Module on r_riic
| Resource | ISDE Tab | Pin selection Sequence |
|---|---|---|
| RSPI | Pins | Select Peripherals> RSPI> SPI0_Pin_Option_A/B. |
Pin Configuration Settings for the SPI HAL Module on r_sci_uart
| Pin Configuration Property | Value | Description |
|---|---|---|
| Operation Mode | Disabled, Custom, Enabled Default: Disabled | Select Enabled for SPI Operation. |
| MISO | None, P100, P410 Default: None | MISO Pin selection. |
| MOSI | None, P101, P411 Default: None | MOSI Pin selection. |
| RSPCLK | None, P102, P412 Default: None | RSPCLK Pin selection. |
| SSL0:3 | None, P103:106, P413:415 Default: None | SSL0:3 Pin selections. |
The steps in using the SPI HAL module in a typical application are:
These common steps are illustrated in a typical operational flow diagram in the following figure: