4.20. SPI Module

4.20.1. Acronyms and Definitions

Abbreviation/Term

Explanation

AUTOSAR

Automotive Open System Architecture

BSW

Basic Software

MCAL

Micro Controller Abstraction Layer

API

Application Programming Interface

DET

Default Error Tracer

SPI

Serial Peripheral Interface

MCU

Micro Controller Unit

OS

Operating System

SW

Software

HW

Hardware

4.20.2. Introduction

This document describes MCAL SPI Driver functionality, its application interfaces and configuration details as per AUTOSAR version 4.3.1.

Supported AUTOSAR Release

4.3.1

Supported Configuration Variants

Post-build, Pre-Compile, Link-Time

Vendor ID

SPI_VENDOR_ID (44)

Module ID

SPI_MODULE_ID (83)

Supported Platform

AM263Px

4.20.3. Functional Overview

The SPI driver provides services for basic communication with external components. These components can be used by an application.

The main tasks of the SPI are:

  1. Handle data transmission to the components connected via SPI

  2. Take care of the settings required by external components (baud rate etc.)

4.20.3.1. SPI Driver Architecture

The following figure shows where the SPI is located in the AUTOSAR architecture

SPI in AUTOSAR architecture

Fig. 4.90 SPI in AUTOSAR architecture

The next figure shows the interfaces to adjacent modules of the SPI. These interfaces are described in further chapters.

SPI Interfaces

Fig. 4.91 SPI Interfaces

4.20.3.2. Initialization

The SPI driver is initialized by calling Spi_Init(), with parameter ConfigPtr referencing a runtime configuration set. Spi_DeInit() will deinitialize the driver.

4.20.3.3. States

There are 3 states in which the SPI driver can be in.

  1. SPI_UNINIT: The SPI Handler/Driver is not initialized or not usable.

  2. SPI_IDLE : The SPI Handler/Driver is not currently transmitting any Job.

  3. SPI_BUSY : The SPI Handler/Driver is performing a SPI Job (transmit).

So the user knows the ongoing action of the driver during a transmission.

4.20.3.4. Baudrate calculation

SPI Baud Rate Calculation is as follows:

Baud rate = fSPI / CLKD

Where fSPI – SPI Functional clock frequency. fSPI can be set from MCU clocksetting configuration, where user can configure clock source(as per TRM) and clock division value for required fSPI (fSPI=clk/clkdiv+1).

Refer the figure below:

MCU Clock setting in Ebtresos

Fig. 4.92 MCU Clock setting in Ebtresos

CLKD – Prescalar clock divider (SpiExtDeviceClockDivider value as per EBtresos Configuration). SpiExtDeviceClockDivider can be set from EBtresos as in below figure:

SpiExtDeviceClockDivider value as per EBtresos Configuration

Fig. 4.93 SpiExtDeviceClockDivider value as per EBtresos Configuration

CLKD value should be set such a way to get the expected baudrate as per calculation below:

For example, if fSPI of MCSPI is 50 MHz:

1.For Baudrate = 50Mbps , CLKD should be given as 0 , calculation will be as following

Baudrate = 50/(0+1) = 50Mbps

2.For Baudrate =25Mbps ,CLKD should be given as 1 , calculation will be as following

Baudrate = 50/(1+1) = 25Mbps

4.20.3.5. Assumptions

  1. For using DMA feature, driver assumes that cache initialization is done in application only and not done by the driver.

4.20.3.6. Limitations

  1. A job queued in a sequence cannot be queued via another sequence. This is a design limitation to reduce driver complexity.

  2. A channel in a job in a sequence cannot be part of another active job or sequence. This is a design limitation to reduce driver complexity.

  3. If a sequence is started, another high priority job belonging to another sequence cannot
    interrupt the job belonging to the same hardware unit. But the job can be scheduled ahead of another pending job of the started sequence if it belongs to another HW queue.

4.20.3.7. Design overview

Will be updated in future release:

4.20.4. Hardware Features

4.20.4.1. SPI IP Supported Features

  • Serial clock with programmable frequency, polarity and phase for each channel

  • Wide selection of SPI word lengths, ranging from 4 to 32 bits

  • Each SPI controller operates at up to 50 MHz

  • SPI0 and SPI4 support 2 chip selects while SPI1, SPI2, and SPI3 support 1 chip select

  • Interruptible Sequences

  • Controller multichannel mode

    • Transmit only/transmit and receive modes

    • Flexible input/output(I/O) port controls per channel

    • Programmable clock granularity

    • Per channel configuration for clock definition, polarity enabling and word width

  • Enable the addition of a programmable start-bit for MCSPI transfer per channel (start-bit mode)

4.20.4.2. AUTOSAR Supported Features

  • Spi initilaizes all features required for transmission and reception.

  • Spi Supports using of internal buffers for transfer and receiving of data

  • Spi supports asynchronous transmission and reception

  • Spi supports synchronous transmission and reception.

  • Spi supports setting of external buffers.

  • Spi Supports getting the status of

    • Hwunit

    • Job Result

    • Sequence result

  • Spi Supports setting mode of the communication

  • Spi Supports cancel of sequence

4.20.4.3. Not supported Features

  • Slave Mode not supported

4.20.5. Source files

Description of static files is provided below:

📦AM263Px
┣ 📂build
┣ 📂mcal
┃ ┣ 📂Spi
┃ ┃ ┣ 📂include
┃ ┃ ┃ ┗ 📜Spi.h : Contains the API’s of the SPI driver to be used by upper layers
┃ ┃ ┣ 📂src
┃ ┃ ┃ ┗ 📜Spi.c : Contains the implementation of the API’s for SPI driver
┃ ┃ ┣ 📂V0
┃ ┃ ┃ ┣ 📜hw_mcspi.h : Contains Internal functions declaration of SPI driver
┃ ┃ ┃ ┣ 📜lldr_mcspi.h : Contains Register definition
┃ ┃ ┃ ┣ 📜Spi_Dbg.h : Contains Internal functions definition of SPI driver
┃ ┃ ┃ ┣ 📜Spi_Dma.c : Contains SPI MCAL driver functions for using EDMA
┃ ┃ ┃ ┣ 📜Spi_Irq.h : Contains ISR function declaration
┃ ┃ ┃ ┣ 📜Spi_Irq.c : Contains ISR function definitions
┃ ┃ ┃ ┣ 📜Spi_Mcspi.c : Contains Internal functions definition of SPI driver
┃ ┃ ┃ ┣ 📜Spi_Priv.c : Contains Internal functions definition of SPI driver
┃ ┃ ┃ ┣ 📜Spi_Priv.h : Contains Internal functions declaration of SPI driver
┃ ┃ ┃ ┣ 📜Spi_Utils.c : Contains Internal functions definition of SPI driver
┃ ┃ ┃ ┗ 📜Spi_Utils.h : Contains Internal functions declaration of SPI driver
┃ ┃ ┗ 📜Makefile
┣ 📂mcal_config
┣ 📂mcal_docs
┗ 📜README.txt

Description of generated files is provided below:

Plugin Files

Description

Spi_Cfg.h

Contains the Precompile switches, Symbolic names of Group, channels and hardware units, Configured maximum number Groups and hardware units

Spi_PBcfg.c

Contains all channels Post-Build Configured parameters

Spi_Lcfg.c

Contains all channels Link time Configured parameters

Spi_Cfg.c

Contains all channels Pre-Compile Configured parameters

The below diagram shows the files structure for the SPI driver.

SPI header file include structure

Fig. 4.94 SPI header file include structure

4.20.6. Module requirements

Will be updated in future release:

4.20.6.1. Memory Mapping

Memory Mapping Sections

SPI_CODE

SPI_VAR

SPI_VAR_NOINIT

SPI_CONST

SPI_APPL_DATA

SPI_APPL_CODE

SPI_START_SEC_VAR_INIT_UNSPECIFIED (.data)

x

SPI_STOP_SEC_VAR_INIT_UNSPECIFIED

x

SPI_START_SEC_CODE (.text)

x

SPI_STOP_SEC_CODE

x

SPI_START_SEC_VAR_NO_INIT_UNSPECIFIED (.bss)

x

SPI_STOP_SEC_VAR_NO_INIT_UNSPECIFIED

x

SPI_START_SEC_CONST_UNSPECIFIED(.rodata)

x

SPI_STOP_SEC_CONST_UNSPECIFIED

x

SPI_START_SEC_ISR_CODE (.text)

x

SPI_STOP_SEC_ISR_CODE

x

For application code used by SPI (like callback functions)

x

4.20.6.2. Scheduling

4.20.6.2.1. SchM (Optional)

Beside the OS the BSW Scheduler provides functions that SPI calls at begin and end of critical sections.

Example: SchM_Enter_Spi_SPI_EXCLUSIVE_AREA_0(), SchM_Exit_Spi_SPI_EXCLUSIVE_AREA_0().

4.20.6.2.2. Critical Sections

There is only one kind of critical sections in this driver. Within these sections all read /modify / write accesses to internal SPI driver data structures must be protected. Therefore switching to tasks that also access SPI has to be avoided and all SPI interrupts have to be suspended.

4.20.6.3. Error handling

4.20.6.3.1. Development Error Reporting

The module SPI depends on the DET (by default) in order to report development errors.

The DET can be replaced optionally by an equivalent component which is responsible to recognize development errors, if no DET component is available.

The DET error is reported with Module ID.

The reported service IDs identify the services which are described earlier.

The following table represents the service IDs:

Service ID

Service

SPI_SID_INIT = 0x00

Spi_Init

SPI_SID_DEINIT = 0x01

Spi_DeInit

SPI_SID_WRITEIB = 0x02

Spi_WriteIB

SPI_SID_ASYNCTRANSMIT = 0x03

Spi_AsyncTransmit

SPI_SID_READIB = 0x04

Spi_ReadIB

SPI_SID_SETUPEB = 0x05

Spi_SetupEB

SPI_SID_GETSTATUS = 0x06

Spi_GetStatus

SPI_SID_GETJOBRESULT = 0x07

Spi_GetJobResult

SPI_SID_GETSEQUENCERESULT = 0x08

Spi_GetSequenceResult

SPI_SID_GETVERSIONINFO = 0x09

Spi_GetVersionInfo

SPI_SID_SYNCTRANSMIT = 0x0A

Spi_SyncTransmit

SPI_SID_GETHWUNITSTATUS = 0x0B

Spi_GetHwUnitStatus

SPI_SID_CANCEL = 0x0C

Spi_Cancel

SPI_SID_SETASYNCMODE = 0x0D

Spi_SetAsyncMode

SPI_SID_MAINFUNCTION_HANDLING = 0x10

Spi_MainfunctionHandling

4.20.6.4. Error codes

4.20.6.4.1. Development Errors

The errors reported to DET module are described in the following table:

Type of Error

Related Error code

Value (Hex)

Channel out of bounds, exceeds the maximum number of configured channels

SPI_E_PARAM_CHANNEL

0x0A

Job out of bounds, exceeds the maximum number of configured jobs

SPI_E_PARAM_JOB

0x0B

Sequence out of bounds, exceeds the maximum number of configured sequences

SPI_E_PARAM_SEQ

0x0C

Length out of bounds, exceeds the maximum number of configured EB- or IB- buffer length

SPI_E_PARAM_LENGTH

0x0D

The requested hardware unit does not exist

SPI_E_PARAM_UNIT

0x0E

An invalid configuration has been passed (i.e., a NULL_PTR).This is an extension to AUTOSAR.

SPI_E_PARAM_POINTER

0x10

A service was requested, but the driver has not been initialized

SPI_E_UNINIT

0x1A

The requested sequence is still pending

SPI_E_SEQ_PENDING

0x2A

Transmission of synchronous sequence in progress (not supported)

SPI_E_SEQ_IN_PROCESS

0x3A

The driver is already initialized

SPI_E_ALREADY_INITIALIZED

0x4A

AUTOSAR requires to check the validity of function parameters. These checks are for development error reporting and can be en/dis-abled separately. En/dis-abling of single checks is an addition to the AUTOSAR standard which requires to en/dis-able the complete parameter checking via the parameter SPI_DEV_ERROR_DETECT. The following table shows which parameter checks are performed on which services:

Check Services

SPI_E_PARAM_CHANNEL

SPI_E_PARAM_JOB

SPI_E_PARAM_SEQ

SPI_E_PARAM_LENGTH

SPI_E_PARAM_UNIT

SPI_E_PARAM__POINTER

SPI_E_PARAM_UNINIT

SPI_E_SEQ_PENDING

SPI_E_SEQ_PROCESS

SPI_E_ALREADY_INITILAIZE

Spi_Init

x

x

x

x

x

Spi_DeInit

x

Spi_AsyncTransmit

x

x

x

Spi_SetupEB

x

x

x

x

Spi_GetStatus

Spi_GetJobResult

x

x

Spi_GetSequenceResult

x

x

Spi_GetVersionInfo

x

Spi_GetHwUnitStatus

x

x

Spi_Cancel

x

x

4.20.6.4.2. DEM Errors

The errors reported to DEM are described in the following table:

Error Code

Error Macro

Description

Assigned by DEM

SPI_E_HARDWARE_ERROR

This error is raised when McSPI RX FIFO overflows

Assigned by DEM

SPI_E_BIT_ERROR

A bit error was detected

Assigned by DEM

SPI_E_DESYNC_ERROR

Slave desynchronized

Assigned by DEM

SPI_E_DLEN_ERROR

Data length mismatch detected during transmission

Assigned by DEM

SPI_E_TXSTALL_ERROR

This error occurs if the driver tries to write data which has not been transmitted yet

Assigned by DEM

SPI_E_RXSTALL_ERROR

The driver tries to read data, but no data has been provided by the hardware

Assigned by DEM

SPI_E_DOVR_ERROR

The hardware reported an internal receive buffer overrun

Assigned by DEM

SPI_E_TO_ERROR

The hardware reported a Timeout error because of non-activation of ENA pin

4.20.7. Used resources

4.20.7.1. Interrupt Handling

For interrupt notification, ISR’s are provided in SPI driver. There are two ISR for each SPI hardware unit. Depending on hardware unit configured, it will call group notify function. The interrupt service routines shall be mapped to the interrupt sources of the respective cross bar interrupt. The supported ISR’s are part of the Spi_Irq.h file.

Following are SPI module ISRs for each hardware unit:

1.SPI HW UNIT 0

  • Spi_IrqUnitMcspi0TxRx()

  • ISR(Spi_IrqUnitMcspi0TxRx)

2.SPI HW UNIT 1

  • Spi_IrqUnitMcspi1TxRx()

  • ISR(Spi_IrqUnitMcspi1TxRx)

3.SPI HW UNIT 2

  • Spi_IrqUnitMcspi2TxRx()

  • ISR(Spi_IrqUnitMcspi2TxRx)

4.SPI HW UNIT 3

  • Spi_IrqUnitMcspi3TxRx()

  • ISR(Spi_IrqUnitMcspi3TxRx)

5.SPI HW UNIT 4

  • Spi_IrqUnitMcspi4TxRx()

  • ISR(Spi_IrqUnitMcspi4TxRx)

6.SPI HW UNIT 5

  • Spi_IrqUnitMcspi5TxRx()

  • ISR(Spi_IrqUnitMcspi5TxRx)

7.SPI HW UNIT 6

  • Spi_IrqUnitMcspi6TxRx()

  • ISR(Spi_IrqUnitMcspi6TxRx)

8.SPI HW UNIT 7

  • Spi_IrqUnitMcspi7TxRx()

  • ISR(Spi_IrqUnitMcspi7TxRx)

For using SPI wth DMA mode, register CDD_EDMA_lld_transferCompletionMasterIsrFxn with appropriate INTAGG line.

4.20.8. Integration description

4.20.8.1. Dependent modules

4.20.8.1.1. MCU

The module MCU powers up the microcontroller’s peripherals at startup time and initializes the PLL and the internal clock domains which go to the SPI unit. The SPI module also supports an internal divider which can be changed at configuration time using the ‘clkDivider’ member of Spi_McSPIExternalDeviceConfigType structure to configure the actual SPI functional clock.

4.20.8.1.2. PORT

The module PORT enables the SPI lines at startup time. To operate the SPI properly, the PORT driver must be configured. The PORT driver sets the PINs to the required mux values for the SPI to operate.

4.20.8.1.3. OSEK / AUTOSAR OS (Optional)

An operating system can be used for task scheduling, interrupt handling, global suspend and restore of interrupts and creating of the Interrupt Vector Table. The SPI module may use OSEK/AUTOSAR OS to suspend and restore global interrupts.

4.20.8.1.4. DET

This implementation depends on the DET in order to report development errors. The detection of development errors is configurable (ON / OFF).

4.20.8.1.5. DEM

By default, production code related errors are reported to the DEM using the service DEM_ReportErrorStatus ().

Note

Dem Event is enable only if $(Module_Name)DemEventParameterRefs is enabled.

4.20.8.1.6. Callback Functions

The SPI driver does not provide any call back functions.

4.20.8.1.7. Callback Notification

At its configurable interfaces, the SPI defines notifications that can be mapped to callback functions provided by other modules. The mapping is not statically defined by the SPI but can be performed at configuration time. The function prototypes that can be used for the configuration have to match the appropriate function prototype signatures, which are described in the following.

Example:Spi_JobEndNotification:

4.20.8.2. Multi-core and Resource allocator

Not Supported

4.20.9. Configuration

4.20.9.1. Configuration Variants

The SPI can be configured as Post-Build or Pre-Compile or Link-time variant, using EB tresos tool.

Variants

Generated Files

PostBuild

Spi_PBcfg.c , Spi_Cfg.h

Link-time

Spi_Lcfg.c , Spi_Cfg.h

Pre-Compile

Spi_Cfg.c , Spi_Cfg.h

4.20.9.2. Parameter Description

4.20.9.2.1. Standard Configuration

Standard Parameters

Description

Default Value

Range

Unit

SPI_E_HARDWARE_ERROR

Reference to configured DEM event to report “Hardware failure”. If the reference is not configured the error shall not be reported.

NA

ASPathDataOfSchema:/AUTOSAR/EcucDefs/Dem/DemConfigSet/DemEventParameter

Reference

SpiMaxChannel

This parameter contains the number of Channels configured.

It will be gathered by tools during the configuration stage.

24

1..255

Integer

SpiMaxJob

Total number of Jobs configured.

10

1–65535

Integer

SpiMaxSequence

Total number of Sequences configured.

10

1..255

Integer

SpiChannelId

SPI Channel ID, used as parameter in SPI API functions.

0

0..255

Integer

SpiChannelType

Buffer usage with EB/IB channel.

EB

EB

IB

Enumeration

SpiDataWidth

This parameter is the width of a transmitted data unit.

8

1..32

Integer

SpiDefaultData

The default data to be transmitted when (for internal buffer or external buffer) the pointer passed to Spi_WriteIB (for internal buffer) or to Spi_SetupEB (for external buffer) is NULL.

0

0..4294967295

Integer

SpiEbMaxLength

This parameter contains the maximum size (number of data elements) of data buffers in case of EB Channels and only.

255

0..65535

Integer

SpiIbNBuffers

This parameter contains the maximum number of data buffers in case of IB Channels and only.

10

0..65535

Integer

SpiTransferStart

This parameter defines the first starting bit for transmission.

MSB

LSB

MSB

Enumeration

SpiBaudrate

This parameter is the communication baudrate - This parameter allows

500

0..INF

Float

SpiCsIdentifier

This parameter is the symbolic name to identify the Chip Select (CS) allocated to this Job (CS0 to CS3).

SCS0

String

SpiCsPolarity

This parameter defines the active polarity of Chip Select.

HIGH

LOW

HIGH

Enumeration

SpiCsSelection

When the Chip select handling is enabled (see SpiEnableCs), then this parameter specifies if the chip select is handled automatically by Peripheral HW engine or via general purpose IO by Spi driver.

CS_VIA_PERIPHERAL_ENGINE

CS_VIA_GPIO

CS_VIA_PERIPHERAL_ENGINE

Enumeration

SpiDataShiftEdge

This parameter defines the SPI data shift edge.

LEADING

LEADING

TRAILING

Enumeration

SpiEnableCs

This parameter enables or not the Chip Select handling functions. If this parameter is enabled then parameter SpiCsSelection further details the type of chip selection.

TRUE

TRUE/ FALSE

Boolean

SpiHwUnit

This parameter is the symbolic name to identify the HW SPI Hardware

CSIB0

CSIB0

CSIB1

CSIB2

CSIB3

CSIB4

Enumeration

SpiShiftClockIdleLevel

This parameter defines the SPI shift clock idle level.

LOW

LOW

HIGH

Boolean

SpiTimeClk2Cs

Timing between clock and chip select (in seconds) - This parameter allows to use a range of values from 0 up to 0.0001 seconds.

0.0001

0.0 .. 1.0E-4

Float

SpiHwUnitSynchronous

If SpiHwUnitSynchronous is set to “SYNCHRONOUS”,the SpiJob uses its containing SpiDriver in a synchronous manner.

If it is set to “ASYNCHRONOUS”, it uses the driver in an asynchronous way. If the parameter is not set, the SpiChannel uses the driver also in an asynchronous way.

ASYNCHRONOUS

ASYNCHRONOUS

SYNCHRONOUS

Enumeration

SpiJobEndNotification

This parameter is a reference to a notification function.

NULL_PTR

NA

Function

SpiJobId

SPI Job ID, used as parameter in SPI API functions.

NA

0..65535

Integer

SpiJobPriority

Priority set accordingly to SPI093: 0, lowest, 3, highest priority

3

0..3

Integer

SpiDeviceAssignment

Reference to the external device used by this job

NA

ASPathDataOfSchema:/AUTOSAR/EcucDefs/Spi/SpiDriver/SpiExternalDevice

Reference

SpiChannelIndex

This parameter specifies the order of Channels within the Job.

0

0..255

Integer

SpiChannelAssignment

A job reference to a SPI channel.

NA

ASPathDataOfSchema:/AUTOSAR/EcucDefs/Spi/SpiDriver/SpiChannel

Reference

SpiInterruptibleSequence

This parameter allows or not this Sequence to be suspended by another one.

TRUE

TRUE/ FALSE

Boolean

SpiSeqEndNotification

This parameter is a reference to a notification function.

NULL_PTR

NA

Function

SpiSequenceId

SPI Sequence ID, used as parameter in SPI API functions.

NA

0..255

Integer

SpiJobAssignment

A sequence references several jobs, which are executed during a communication sequence

NA

ASPathDataOfSchema:/AUTOSAR/EcucDefs/Spi/SpiDriver/SpiJob

Reference

SpiCancelApi

Switches the Spi_Cancel function ON or OFF.

TRUE

TRUE/ FALSE

Boolean

SpiChannelBuffersAllowed

Selects the SPI Handler/Driver Channel Buffers usage allowed

2

0..2

Integer

SpiDevErrorDetect

Switches the Development Error Detection and Notification ON or OFF.

TRUE

TRUE/ FALSE

Boolean

SpiHwStatusApi

Switches the Spi_GetHWUnitStatus function ON or OFF.

TRUE

TRUE/ FALSE

Boolean

SpiInterruptibleSeqAllowed

Switches the Interruptible Sequences handling functionality ON or OFF.

TRUE

TRUE/ FALSE

Boolean

SpiLevelDelivered

Selects the SPI Handler/Driver level of scalable functionality: SYNC ONLY(0), ASYNC ONLY (1), SYNC/ASYNC(2)

2

0..2

Integer

SpiMainFunctionPeriod

This parameter defines the cycle time of the function Spi_MainFunction_Handling in seconds.

0.01

0..INF

Float

SpiSupportConcurrentSyncTransmit

Specifies whether concurrent Spi_SyncTransmit() calls for different sequences shall be configurable.

FALSE

TRUE/ FALSE

Boolean

SpiUserCallbackHeaderFile

Header file name which will be included by the Spi. The value of this parameter shall be used as h-char-sequence or q-char-sequence according to ISO C90 section 6.10.2 “source file inclusion”.

FALSE

TRUE/ FALSE

Boolean

SpiVersionInfoApi

Switches the Spi_GetVersionInfo function ON or OFF.

TRUE

TRUE/ FALSE

Boolean

SpiMaxHwUnit

Number of different SPI hardware microcontroller peripherals (units/busses) available and handled by this SPI Handler/Driver module.

8

1..8

Integer

Standard Parameters

Description

Default Value

Range

Unit

SpiMaxHwUnit

Maximum number of HW unit

8

1..8

Integer

SpiMaxExternalDeviceConfig

Maximum Number of different SPI hardware microcontroller peripherals available and handled by this SPI Handler/Driver module.Max range is derived from SpiMaxExternalDevices.

8

1..8

Integer

SpiExternalDeviceId

The index of the corresponding external device config associated with job.

NA

0..65535

Integer

SpiCsMode

This selects which CS mode the device should enter.

SPI_SINGLE: the CS will return to default level after one transmission unit has been sent.

SPI_CONTINUOUS: the CS will remain active during the whole transmission.

SPI_CONTINUOUS

SPI_SINGLE

SPI_CONTINUOUS

Enumeration

SpiCsIdleTime

CS idle time (Timing between clock and chip select) if single mode is chosen.

SPI_DATADELAY_0

SPI_DATADELAY_0

SPI_DATADELAY_1

SPI_DATADELAY_2

SPI_DATADELAY_3

Enumeration

SpiExtDeviceClockDivider

Clock divider. This is used to derive the required baudrate from the QSPI functional clock.

0

0..65535

Integer

SpiExtDeviceMCSPITxRxMode

TX and RX mode. Data is transmitted (shifted out serially on SPIDAT[0]) and received (shifted in serially on SPIDAT[1]) simultaneously on separate data lines.Tx only mode - Data is only transmiited (shifted out serially on SPIDAT).

SPI_TX_RX_MODE_BOTH

SPI_TX_RX_MODE_BOTH

SPI_TX_RX_MODE_TX_ONLY

Enumeration

SpiExtDeviceMCSPIStartBitEnable

Start bit D/CX added before SPI transfer. Polarity is defined by StartBitLevel

TRUE

TRUE/ FALSE

Boolean

SpiExtDeviceMCSPIStartBitLevel

Start-bit polarity used when startBitEnable is TRUE.

SPI_LOW

SPI_LOW

SPI_HIGH

Enumeration

SpiExtDeviceMCSPIDataLineSelectReception

Data Line 0 or 1 selected for reception

DATA_LINE_0_RECEPTION

DATA_LINE_0_RECEPTION

DATA_LINE_1_RECEPTION

Enumeration

SpiExtDeviceMCSPIDataLineSelectTransmission

Data Line 0 or 1 or both selected for transmission.No transmission on data lines if DATA_LINE_NO_TRANSMISSION is selected

DATA_LINE_1_TRANSMISSION

DATA_LINE_NO_TRANSMISSION

DATA_LINE_0_TRANSMISSION

DATA_LINE_1_TRANSMISSION

DATA_LINE_BOTH_TRANSMISSION

Enumeration

SpiHwUnitAssignment

Reference to the HW unit used by this job

NA

ASPathDataOfSchema:/TI_AM263Px/Spi/SpiDriver/SpiHwUnitConfig

Reference

SpiHwUnitType

SPI HW unit to use

SPI_UNIT_MCSPI0

SPI_UNIT_MCSPI0

SPI_UNIT_MCSPI1

SPI_UNIT_MCSPI2

SPI_UNIT_MCSPI3

SPI_UNIT_MCSPI4

SPI_UNIT_MCSPI5

SPI_UNIT_MCSPI6

SPI_UNIT_MCSPI7

Enumeration

SpiHwUnitDmaEnable

Enables DMA support for MCSPI instance

FALSE

TRUE FALSE

BOOLEAN

SpiHwUnitCddDmaTxHandler

References the CDD DMA handler used for MCSPI transmission

NA

ASPathDataOfSchema:/TI_AM263Px/Cdd_Dma/CddDmaDriverHandler

Reference

SpiHwUnitCddDmaRxHandler

References the CDD DMA handler used for MCSPI reception

NA

ASPathDataOfSchema:/TI_AM263Px/Cdd_Dma/CddDmaDriverHandler

Reference

SpiEnableJobLog

Enable/disable SPI job log

TRUE

TRUE FALSE

Boolean

SpiMaxExternalDevices

Number of different SPI hardware microcontroller peripherals (units/busses) available and handled by this SPI Handler/Driver module.

8

1..8

Integer

SpiMaxJobLogLength

Maximum job log entries when logging is ON

100

1.65535

Integer

SpiMaxTimeoutDuration

Maximum time duration for SPI transmission.Unit is clock ticks.

10000

1..4294967295

Integer

SpiMaxChannelsPerJob

Maximum channels allowed per job

4

1..255

Integer

SpiMaxJobsPerSequence

Maximum jobs allowed per sequence

4

1..255

Integer

SpiMaxChannels

Maximum channels across all jobs/sequence/hwunit

24

1..255

Integer

SpiMaxJobs

Maximum jobs across all sequence/hwunit

10

1..65535

Integer

SpiMaxSequences

Maximum sequence across all hwunit

10

1..255

Integer

SpiIrqType

Type of Isr function: void functionname(void)

1.CAT1 : interrupt void func(void)

2.CAT2 : ISR(func)

SPI_ISR_CAT2

SPI_ISR_VOID

SPI_ISR_CAT1

SPI_ISR_CAT2

Enumeration

SpiDefaultOSCounterId

Default Os Counter Id if node reference to OsCounter ref SpiOsCounterRef is not set

0

0..16

Integer

SpiOsCounterRef

This parameter contains a reference to the OsCounter, which is used by the SPI driver.

NA

/AUTOSAR/EcucDefs/Os/OsCounter

Reference

SpiTimeoutDuration

SPI timeout - used in SPI busy wait

32000

1..4294967295

Integer

SpiRegisterReadbackApi

Specifies whether RegisterReadback API is enabled

TRUE

TRUE FALSE

Boolean

SpiSafetyApi

Enable API to do safety diagnostic

TRUE

TRUE FALSE

Boolean

SpiChannelInternalBufferMaxLength

Internal Buffer length in bytes - applicable for SpiChannelBuffer type - SPI_IB. This is the maximum length that can be allocated by each channel and it is fixed.Can vary buffer length per channel by configuring SpiIbNBuffers and SpiDataWidth.

64

1..4294967295

Integer

SpiDeviceVariant

Select SOC variant

AM263Px

AM263Px

Enumeration

SpiHwUnitEnabledFlag

Group configurations

SPI_HWUNIT_MCSPI0

SPI_HWUNIT_MCSPI0

SPI_HWUNIT_MCSPI1

SPI_HWUNIT_MCSPI2

SPI_HWUNIT_MCSPI3

SPI_HWUNIT_MCSPI4

SPI_HWUNIT_MCSPI5

SPI_HWUNIT_MCSPI6

SPI_HWUNIT_MCSPI7

Enumeration

Note

SpiTimeoutDuration and SpiMaxTimeoutDuration parameter value should be passed as number of ticks according to clock frequency. The clock source have changed from RTI timers which used 200MHz clock frequency to R5f timers which uses 400MHz clock frequency, so the timeout values need to be configured accordingly.

4.20.9.3. Symbolic Names deviations

None

4.20.9.4. Configuration rules and constraints to enable plausibility checks

SPI DMA Tx and Rx Handler should be configured to match Channel IDs with the EDMA TRIG XBAR MODULE number selected with appropriate CDD DMA channel trigger source selected from the dropdown as per the instance. Channel crossbar and channel crossbar map can be left to default as SPI driver doesn’t make use of those parameters.

CDD DMA Crossbar configuration matching Channel ID for SPI Handle

Fig. 4.95 CDD DMA Crossbar configuration matching Channel ID for SPI Handle

4.20.10. Examples

4.20.10.1. Overview

Will be updated in future release:

4.20.10.2. Setup required to run example

Will be updated in future release:

4.20.10.3. How to run examples

4.20.10.3.1. Steps to build and run example

Spi example application demonstrating the MCAL SPI driver features is in folder <MCAL_ROOT>/examples/Spi.

This application can be built from the root folder by giving gmake –s mcspi_app PLATFORM=am263px.

Then launch TI Code Composer Studio (CCS) and connect the Board with it using an appropriate target configuration, load the application binary in to R5_0 core and execute the binary.

4.20.10.3.2. Document external set up Information

None

4.20.10.3.3. Flow of the example application

  1. In example application,the status of spi is checked,whether it is idle or busy.

  2. After checking the status,it sets the external buffer as per requirement.

  3. Then the mode of transmission is set and post that async transmission takes place with loopback enable.

  4. After the transmission is completed,the recieve and transmit data is compared and the datas should be same.

4.20.10.3.4. Configuration used to test this example

The example application is configured with the following Parametrs:

Max Channels :10U

Max channels per Sequence :4U

Max Jobs per seq:4U

Max HwUnit :8U

Max External Devices:8U

Channel BufferType :SPI_EB

Maximum Buffer Length :1120U

Transfer Type :SPI_MSB

Mode of Transmission:Asynchronous

Method of Testing :Loopback

4.20.10.3.4.1. Program changes with DMA mode

For DMA mode support, DMA TPCC0 Interrupt aggregation (INTR) line number 72 gets used to register ISR with EDMA and Cache write back for source buffer before data transmission as well as Cache invalidation before validating destination buffers should happen using respective Mcal_CacheP_wb and Mcal_CacheP_inv APIs.

4.20.10.4. Sample Log


 SPI_APP: Variant - Post Build being used !!!
 SPI_APP
 : Sample Application - STARTS !!!
 
 SPI MCAL Version Info
 ---------------------
 Vendor ID           : 44
 Module ID           : 83
 SW Major Version    : 9
 SW Minor Version    : 1
 SW Patch Version    : 0
 
  SPI_APP: CH 10: JOBS 4: SEQ 3: HWUNIT 8: NUM OF WORDS 1120:!!!
 SPI_APP: SPI Async transmit in progress!!

 SPI_APP: SPI Loopback Test Passed!!!

 SPI Stack Usage: 1000 bytes

4.20.10.5. File Structure

📦AM263Px
┣ 📂build
┣ 📂mcal
┃ ┣ 📂examples
┃ ┃ ┣ 📂Spi
┃ ┃ ┃ ┣ 📂mcspi_app
┃ ┃ ┃ ┃ ┣ 📂soc
┃ ┃ ┃ ┃ ┣ 📜McspiApp.c : Contains the SPI test example for McSPI
┃ ┃ ┃ ┃ ┣ 📜McspiApp.h : Contains McSPI example header file
┃ ┃ ┃ ┃ ┗ 📜Makefile
┃ ┃ ┃ ┣ 📂mibspi_app
┃ ┃ ┃ ┃ ┣ 📂soc
┃ ┃ ┃ ┃ ┣ 📜MibspiApp.c : Contains the SPI test example for MibSPI
┃ ┃ ┃ ┃ ┣ 📜MibspiApp.h : Contains MiBSPI example header file
┃ ┃ ┃ ┃ ┗ 📜Makefile
┃ ┣ 📂examples_config
┃ ┃ ┣ 📂Spi_Demo_Cfg
┃ ┃ ┃ ┗ 📂soc
┃ ┃ ┃ ┃ ┣ 📂am263px
┃ ┃ ┃ ┃ ┃ ┗ 📂r5f0_0
┃ ┃ ┃ ┃ ┃ ┃ ┣ 📂include
┃ ┃ ┃ ┃ ┃ ┃ ┃ ┗📜Spi_Cfg.h : Contains the configuration parameters
┃ ┃ ┃ ┃ ┃ ┃ ┗ 📂src
┃ ┃ ┃ ┃ ┃ ┃ ┃ ┣📜Spi_Cfg.c : Contains all Pre-Compile Configured parameters
┃ ┃ ┃ ┃ ┃ ┃ ┃ ┣📜Spi_Lcfg.c : Contains all Link time configured parameters
┃ ┃ ┃ ┃ ┃ ┃ ┃ ┗ 📜Spi_PBcfg.c : Contains all Post build configured parameters
┃ 📂mcal_config
┃ 📂mcal_docs
┗ 📜README.txt

4.20.10.6. Test Report

Please refer AM26x SPI Driver Test Case Report as part of CSP provided in the release package.

4.20.11. References

AUTOSAR_SWS_SPIHandlerDriver
Technical Reference Manual