80. Serial peripheral interface (SPI)

80.1 Introduction

The serial peripheral interface (SPI) can be used to communicate with external devices while using the specific synchronous protocol. The SPI protocol supports half-duplex, full-duplex, and simplex synchronous, serial communication with external devices. The interface can be configured as master or slave and can operate in multislave or multimaster configurations. The device configured as master provides a communication clock (SCK) to the slave device. The slave select (SS) and ready (RDY) signals can be applied optionally just to set up communication with a concrete slave and to ensure it handles the data flow properly. The Motorola data format is used by default, but some other specific modes are supported as well.

80.2 SPI main features

80.3 SPI implementation

The table below describes the SPI implementation. The instances have either a full or a limited set of features.

Table 792. SPI features

SPI featureSPI2S1, SPI2S2, SPI2S3
(full-featured instances)
SPI4, SPI5, SPI6, SPI7
(full-featured instances)
SPI8 (limited-featured
instance)
Data and CRC sizeConfigurable
from 4 to 32 bits
Configurable
from 4 to 16 bits
8/16 bits
CRC computationCRC polynomial length
configurable from 5 to 33 bits
CRC polynomial length
configurable from 5 to 17 bits
CRC polynomial length
9/17 bits
Size of FIFOs16x8 bits8x8 bits8x8 bits
Number of data control
(TSIZE)
Up to 65535Up to 65535Up to 1023, no remaining
data counter (CTIZE)
I2S featureYesNoNo
Autonomous in Stop modes
with wake-up capability
YesYesYes
Autonomous in LP-Stop and
Standby modes
with wake-up capability
NoNoYes

Note: For detailed information about instances capabilities to exit from Stop and Standby modes, refer to Table 797: SPI wake-up and interrupt requests and Table 94: Functionalities depending on system operating mode.

80.4 SPI functional description

80.4.1 SPI block diagram

The SPI enables synchronous, serial communications between the MCU and external devices. The application software can manage the communication by polling the status flag or using a dedicated SPI interrupt. The main SPI elements and their interactions are shown in Figure 953.

Figure 953. SPI/I2S block diagram

Figure 953: SPI/I2S block diagram. The diagram shows the internal architecture of the SPI/I2S peripheral, divided into three clock domains: Serial interface clock domain, spi_pclk clock domain, and spi_ker_ck clock domain. The Serial interface clock domain contains the IRQ Interface, DMA Interface, COM Controller (with registers SPI_IER, SPI_SR, SPI_IFCR, SPI_CRCPOLY, SPI_TXCRC, SPI_RXCRC), RDY Logic, SS Logic, CRC Controller, TX Shift Reg, RX Shift Reg, and a multiplexer. The spi_pclk clock domain contains the Tx FIFO, UDR Controller, and Rx FIFO. The spi_ker_ck clock domain contains the Clock Generator and Prescaler. External signals include spi_wkup, spi_it, spi_pclk_req, spi_tx_dma, spi_rx_dma, 32-bit APB bus, spi_trg[15:0], spi_pclk, spi_ker_ck, and spi_ker_ck_req. The peripheral outputs RDY, SS / WS, MOSI / SDO, MISO / SDI, SCK / CK, and MCK. A note indicates that bold text represents I2S signal names.

SPI/I2S

Serial interface clock domain

irq_wkup, spi_it, spi_pclk_req, spi_tx_dma, spi_rx_dma → IRQ Interface, DMA Interface

COM Controller: SPI_IER, SPI_SR, SPI_IFCR, SPI_CRCPOLY, SPI_TXCRC, SPI_RXCRC

RDY Logic → RDY

SS Logic → SS / WS

CRC Controller, TX Shift Reg → MOSI / SDO

MISO / SDI → RX Shift Reg

spi_pclk clock domain

32-bit APB bus → Tx FIFO, UDR Controller, Rx FIFO

spi_trg[15:0] → SPI_AUTOCR

spi_ker_ck clock domain

spi_pclk → Clock Generator, Prescaler

spi_ker_ck, spi_ker_ck_req → Clock Generator

Output signals: RDY, SS / WS, MOSI / SDO, MISO / SDI, SCK / CK, MCK

Bold: I2S signal names

MSv63429V1

Figure 953: SPI/I2S block diagram. The diagram shows the internal architecture of the SPI/I2S peripheral, divided into three clock domains: Serial interface clock domain, spi_pclk clock domain, and spi_ker_ck clock domain. The Serial interface clock domain contains the IRQ Interface, DMA Interface, COM Controller (with registers SPI_IER, SPI_SR, SPI_IFCR, SPI_CRCPOLY, SPI_TXCRC, SPI_RXCRC), RDY Logic, SS Logic, CRC Controller, TX Shift Reg, RX Shift Reg, and a multiplexer. The spi_pclk clock domain contains the Tx FIFO, UDR Controller, and Rx FIFO. The spi_ker_ck clock domain contains the Clock Generator and Prescaler. External signals include spi_wkup, spi_it, spi_pclk_req, spi_tx_dma, spi_rx_dma, 32-bit APB bus, spi_trg[15:0], spi_pclk, spi_ker_ck, and spi_ker_ck_req. The peripheral outputs RDY, SS / WS, MOSI / SDO, MISO / SDI, SCK / CK, and MCK. A note indicates that bold text represents I2S signal names.

The simplified scheme of Figure 953 shows three fully independent clock domains:

All the control and status signals between these domains are strictly synchronized. There is no specific constraint concerning the frequency ratio between these clock signals. The user has to consider a ratio compatible with the data flow speed to avoid data underrun or overrun events.

The spi_pclk clock signal feeds the peripheral bus interface. It must be active when accesses to the SPI registers are required.

The SPI working in slave mode handles a data flow using the serial interface clock derived from the external SCK signal provided by the external master SPI device. That is why the SPI slave is able to receive and send data even when the spi_pclk and spi_ker_ck clock signals are inactive. As a consequence, a specific slave logic working within the serial interface clock domain needs some additional traffic to be set up correctly (for example when underrun or overrun is evaluated, see Section 80.5.2 for details). This cannot be done when the bus becomes idle. In some specific cases, the slave even requires the clock generator working (see Section 80.5.1).

When the SPI works as a master, the RCC must provide the spi_ker_ck kernel clock to the peripheral during communication to feed the serial interface clock via the clock generator where it can be divided by prescaler or bypassed. The signal is then provided to the slaves via the SCK pin and internally to the serial interface domain of the master.

80.4.2 SPI pins and internal signals

Up to five I/O pins are dedicated to SPI communication with external devices.

All these pins (except RDY) are shared in the I2S mode. This mode features an additional I2S specific MCK signal. For more details about I2S signals, see Section 80.9.2.

The SPI bus enables the communication between one master device and one or more slave devices. The bus consists of at least two wires: one for the clock signal and the other for synchronous data transfer. Other signals are optional and can be added depending on the data exchange between SPI nodes and their communication control management.

Refer to Table 793 and Table 794 for the list of SPI input / output pins and internal signals.

Table 793. SPI/I2S input/output pins(1)

Pin nameI/O typeDescription
MISO/SDI(2)Input/outputMaster data input / slave data output
MOSI/SDO(2)Input/outputMaster data output / slave data input
SCK/CKInput/outputMaster clock output / slave clock input
Table 793. SPI/I2S input/output pins(1)
Pin nameI/O typeDescription
SS/WSInput/outputMaster output / slave selection input
RDYInput/outputSPI master input / slave FIFOs status occupancy output
MCKOutputI2S master frequency output
  1. 1. Refer to the section Section 80.9.2: Pin sharing with SPI function for details.
  2. 2. Functionality of MOSI/SDO and MISO/SDI pins can be swapped. Their directions may vary in SPI bidirectional half-duplex mode.

Description of SPI input/output signals

Table 794. SPI internal input/output signals

Signal nameSignal typeDescription
spi_pclkInputSPI clock signal feeds the peripheral bus interface
spi_ker_ckInputSPI kernel clock
spi_ker_ck_reqOutputSPI kernel clock request
spi_pclk_reqOutputSPI clock request
spi_wkupOutputSPI provides a wake-up interrupt
spi_itOutputSPI global interrupt
spi_tx_dmaInput/outputSPI transmit DMA request
spi_rx_dmaInput/outputSPI receive DMA request
spi_trg[15:0]InputSPI triggers

Description of SPI interconnections

Table 795. SPI interconnection (SPI8)

Signal nameTrigger source
spi_trg0lpdma1_ch0_tcf
spi_trg1lpdma1_ch1_tcf
spi_trg2lpdma1_ch2_tcf
spi_trg3lpdma1_ch3_tcf
spi_trg4exti4
spi_trg5exti5
spi_trg6-
spi_trg7lptim3_ch1
spi_trg8lptim4_ch1
spi_trg9lptim5_ch1
spi_trg10rtc_alra_trg
spi_trg11rtc_wut_trg

Table 795. SPI interconnection (SPI8) (continued)

Signal nameTrigger source
spi_trg12-
spi_trg13-
spi_trg14-
spi_trg15-

80.4.3 SPI communication general aspects

The SPI allows the MCU to communicate using different configurations, depending on the device targeted and the application requirements. These configurations use two or three wires (with software SS management) or three or four wires (with hardware SS management). The communication is always initiated and controlled by the master. The master provides a clock signal on the SCK line and selects or synchronizes slaves for communication by SS line when it is managed by hardware. The data between the master and the slave flow on the MOSI and/or MISO lines.

80.4.4 Communications between one master and one slave

The communication flow can use one of three possible modes: the full-duplex (three wires) mode, half-duplex (two wires) mode, or the simplex (two wires) mode. The SS signal is optional in single master-slave configuration and is often not connected between the two communication nodes. Nevertheless, the SS signal can be helpful in this configuration to synchronize the data flow and it is used by default for some specific SPI modes (for example the TI mode).

The next optional RDY signal can help to ensure the correct management of all the transacted data at slave side.

Full-duplex communication

By default, the SPI is configured for full-duplex communication (bits COMM[1:0] = 00 in the SPI_CFG2 register). In this configuration, the shift registers of the master and slave are linked using two unidirectional lines between the MOSI and the MISO pins. During the SPI communication, the data are shifted synchronously on the SCK clock edges provided by the master. The master transmits the data to be sent to the slave via the MOSI line and receives data from the slave via the MISO line simultaneously. When the data frame transfer is complete (all the bits are shifted) the information between the master and slave is exchanged.

Figure 954. Full-duplex single master/ single slave application Figure 954: Full-duplex single master/ single slave application diagram. Master has Rx shift register, Tx shift register, SPI clock generator. Slave has Tx shift register, Rx shift register. Connections: MISO from Slave to Master, MOSI from Master to Slave, SCK from Master to Slave, optional SS from Master to Slave, optional RDY from Slave to Master.

MSv50504V1

Figure 954: Full-duplex single master/ single slave application diagram. Master has Rx shift register, Tx shift register, SPI clock generator. Slave has Tx shift register, Rx shift register. Connections: MISO from Slave to Master, MOSI from Master to Slave, SCK from Master to Slave, optional SS from Master to Slave, optional RDY from Slave to Master.
  1. 1. The SS pin interconnection is optional. The slave can be configured to be permanently selected to operate in a single master-slave pair (see Section 80.4.7).
  2. 2. The RDY signal provided by the slave can be read by the master optionally.

Half-duplex communication

The SPI can communicate in half-duplex mode by setting COMM[1:0] = 11 in the SPI_CFG2 register. In this configuration, one single cross-connection line is used to link the shift registers of the master and slave together. During this communication, the data are synchronously shifted between the shift registers on the SCK clock edge in the transfer direction selected reciprocally by both master and slave with the HDDIR bit in their SPI_CR1 registers. Note that the SPI must be disabled when changing the direction of the communication. In this configuration, the MISO pin at master and the MOSI pin at slave are free for other application uses and act as GPIOs.

Figure 955. Half-duplex single master/ single slave application Figure 955: Half-duplex single master/ single slave application diagram. Master has Rx and Tx shift registers connected to MOSI via a 1kΩ resistor, bidirectional line connecting to Slave MISO; SPI clock generator to SCK line; SS line; RDY line. Master MISO and Slave MOSI are unused/free (marked as GPIOs).

MSv50505V1

Figure 955: Half-duplex single master/ single slave application diagram. Master has Rx and Tx shift registers connected to MOSI via a 1kΩ resistor, bidirectional line connecting to Slave MISO; SPI clock generator to SCK line; SS line; RDY line. Master MISO and Slave MOSI are unused/free (marked as GPIOs).
  1. 1. The SS pin interconnection is optional. The slave can be configured to be permanently selected to operate in a single master-slave pair (see Section 80.4.7).
  2. 2. In this configuration, the MISO pin at master and MOSI pin at slave can be used as GPIOs
  3. 3. A critical situation can happen when the communication direction is not changed synchronously between two nodes working in bidirectional mode. The new transmitter accesses the common data line while the former transmitter still keeps an opposite value on the line (the value depends on the SPI configuration and communicated data). The nodes can conflict temporarily with opposite output levels on the line until the former transmitter changes its data direction setting. It is suggested to insert a serial resistance between MISO and MOSI pins in this mode to protect the conflicting outputs and limit the current flow between them.
  4. 4. The RDY signal provided by the slave can be read by the master optionally.

Simplex communications

The SPI can communicate in simplex mode by setting the SPI in transmit-only or in receive-only using the COMM[1:0] field in the SPI_CFG2 register. In this configuration, only one line is used for the transfer between the shift registers of the master and slave. The remaining MISO or MOSI pin pair is not used for communication and can be used as standard GPIOs.

The master in transmit-only mode generates the clock as long as there are data available in the TxFIFO and the master transfer is ongoing.

The slave in transmit-only mode sends data as long as it receives a clock on the SCK pin and the SS pin (or software managed internal signal) is active (see Section 80.4.7).

In master mode, the MOSI output is disabled and can be used as a GPIO. The clock signal is generated continuously as long as the SPI is enabled and the CSTART bit in the SPI_CR1 register is set. The clock is stopped either by software explicitly requesting this by setting the CSUSP bit in the SPI_CR1 register or automatically when the RxFIFO is full, when the MASRX bit in the SPI_CR1 is set.

In slave configuration, the MISO output is disabled and the pin can be used as a GPIO. The slave continues to receive data from the MOSI pin while its slave select signal is active (see Section 80.4.7).

Note: In whatever master and slave modes, the data pin dedicated for transmission can be replaced by the data pin dedicated for reception and vice versa by changing the IOSWP bit value in the SPI_CFG2 register (this bit can only be modified when the SPI is disabled).

Any simplex communication can be replaced by a variant of the half-duplex communication with a constant setting of the transaction direction (bidirectional mode is enabled, while the HDDIR bit is never changed) or by full-duplex control when unused data line and corresponding data flow is ignored.

Figure 956. Simplex single master / single slave application
(master in transmit-only / slave in receive-only mode)

Block diagram of a simplex single master / single slave application. The Master (left) contains an SPI clock generator, a Tx shift register, and an Rx shift register. The Slave (right) contains a Tx shift register and an Rx shift register. The Master's Tx shift register is connected to the Slave's Rx shift register via the MOSI line. The Master's Rx shift register is connected to the Slave's Tx shift register via the MISO line. The SCK line connects the Master's SPI clock generator to the Slave's SCK input. The SS line connects the Master's SS output to the Slave's SS input. The RDY line connects the Slave's RDY output to the Master's RDY input. The diagram shows data flow from Master Tx to Slave Rx and from Slave Tx to Master Rx. The SS line is shown as a dashed line with a dotted arrow pointing from Master to Slave. The RDY line is shown as a dashed line with a dotted arrow pointing from Slave to Master.

MSv50506V2

Block diagram of a simplex single master / single slave application. The Master (left) contains an SPI clock generator, a Tx shift register, and an Rx shift register. The Slave (right) contains a Tx shift register and an Rx shift register. The Master's Tx shift register is connected to the Slave's Rx shift register via the MOSI line. The Master's Rx shift register is connected to the Slave's Tx shift register via the MISO line. The SCK line connects the Master's SPI clock generator to the Slave's SCK input. The SS line connects the Master's SS output to the Slave's SS input. The RDY line connects the Slave's RDY output to the Master's RDY input. The diagram shows data flow from Master Tx to Slave Rx and from Slave Tx to Master Rx. The SS line is shown as a dashed line with a dotted arrow pointing from Master to Slave. The RDY line is shown as a dashed line with a dotted arrow pointing from Slave to Master.
  1. 1. The SS pin interconnection is optional. The slave can be configured to be permanently selected to operate in a single master-slave pair (see Section 80.4.7).
  2. 2. In this configuration, both the MISO pins can be used as GPIOs.
  3. 3. The RDY signal provided by the slave can be read by the master optionally.

80.4.5 Standard multislave communication

In a configuration with two or more independent slaves, the master uses a star topology with dedicated GPIO pins to manage the chip select lines for each slave separately (see Figure 957.).

The master must select one of the slaves individually by pulling low the GPIO connected to the slave SS input (only one slave can control data on a common MISO line at a given time).

When this is done, a communication between the master and the selected slave is established. In addition to the simplicity, the advantage of this topology is that a specific SPI configuration can be applied for each slave as all the communication sessions are performed separately just within a single master-slave pair. Optionally, when there is no need to read any information from slaves, the master can transmit the same information to the multiple slaves.

Figure 957. Master and three independent slaves connected in star topology

Schematic diagram of a master and three independent slaves connected in star topology. The master has SS^(1) unconnected, MISO input connected to Rx shift register, MOSI output connected from Tx shift register, SCK output from SPI clock generator, and IO1, IO2, IO3 GPIO outputs. The shared lines MISO, MOSI, and SCK are connected to Slave 1, Slave 2, and Slave 3. IO1 connects to Slave 1 SS, IO2 connects to Slave 2 SS, and IO3 connects to Slave 3 SS. Each slave contains MISO (from Tx shift register), MOSI (to Rx shift register), SCK, and SS inputs.

MSv50508V1

Schematic diagram of a master and three independent slaves connected in star topology. The master has SS^(1) unconnected, MISO input connected to Rx shift register, MOSI output connected from Tx shift register, SCK output from SPI clock generator, and IO1, IO2, IO3 GPIO outputs. The shared lines MISO, MOSI, and SCK are connected to Slave 1, Slave 2, and Slave 3. IO1 connects to Slave 1 SS, IO2 connects to Slave 2 SS, and IO3 connects to Slave 3 SS. Each slave contains MISO (from Tx shift register), MOSI (to Rx shift register), SCK, and SS inputs.
  1. 1. The master single SS pin hardware output functionality cannot support this topology (to be replaced by a set of GPIOs under software control). The SS pin is free for other application uses (such as GPIO or other
  1. alternate functions). Refer to Section 80.4.7 for details.
  2. 2. If the application cannot ensure that no more than a single SS active signal is provided by the master at a given time, it is better to configure the MISO pins in an open-drain configuration with an external pull-up on the MISO line to prevent conflicts between the interconnected outputs of the slaves. Else, a push-pull configuration can be applied without an extra resistor (see I/O alternate function input/output (GPIO) section).
  3. 3. The RDY signals can be read by the master from the slaves optionally.

The master can handle the SPI communication with all the slaves in time when a circular topology is applied (see Figure 958). All the slaves behave like simple shift registers applied in serial chain under control of common slave select (SS) and clock (SCK) signals. All the information is shifted simultaneously around the circle while returning back to the master. Sessions have fixed the length where the number of data frames transacted by the master is equal to the number of slaves.

Then when a first data frame is transacted in the chain, the master just sends the information dedicated for the last slave node in the chain, via the first slave node input, while the first information received by the master comes from the last node output at this time. Correspondingly, the last transacted data finishing the session is dedicated for the first slave node while its first outgoing data just reaches the master input, after its circling around the chain passing through all the other slaves during the session.

The data format configuration and clock setting must be the same for all the nodes in the chain in this topology. As the receive and transmit shift registers are separated internally, a trick with intentional underrun must be applied to the TxFIFO slaves when the information is transacted between the receiver and the transmitter by hardware.

In this case, the transmission underrun feature is configured in a mode repeating the last received data frame (UDRCFG=1). A session can start optionally with a single data pattern written into the TxFIFO by each slave (usually slave status information is applied) before the session starts. In this case, the underrun happens in fact after this first data frame is transacted. To be able to clear the internal underrun condition immediately and restart the session by the TxFIFO content again, the user must disable and enable the SPI between the sessions and must fill the TxFIFO by a new single data pattern (to overcome the propagating delay of the clearing raised in case the underrun is cleared in a standard way by the UDRC bit).

Figure 958. Master and three slaves connected in circular (daisy chain) topology Master and three slaves connected in circular (daisy chain) topology

The diagram illustrates a circular (daisy chain) SPI topology. A Master block on the left contains an Rx shift register, a Tx shift register, and an SPI clock generator. The Master's MOSI output connects to Slave 1's MOSI input. Slave 1's MISO output connects to Slave 2's MOSI input. Slave 2's MISO output connects to Slave 3's MOSI input. Slave 3's MISO output connects back to the Master's Rx shift register. All slaves share a common SCK line connected to the Master's SCK output. Each slave has its own SS line connected to the Master's SS output. Each slave block contains a Tx shift register (labeled with a superscript 1) and an Rx shift register. Arrows indicate the flow of data: Master Tx to Slave 1 Rx, Slave 1 Tx to Slave 2 Rx, Slave 2 Tx to Slave 3 Rx, and Slave 3 Tx back to Master Rx. The SCK signal flows from the Master to all slaves. The SS signal flows from the Master to each slave's SS input.

MSv50507V1

Master and three slaves connected in circular (daisy chain) topology
  1. 1. The underrun feature is used by the slaves in this configuration when the slaves are able to transmit data received previously into the Rx shift register once their TxFIFOs become empty.
  2. 2. The RDY signals can be read by the master optionally, either separately or configured as open drain outputs (while RDIOP = 0) and connected with a pull-up resistor as a common chain ready status overdriven by the slowest device.

80.4.6 Multimaster communication

Unless the SPI bus is not designed primarily for a multimaster capability, the user can use a built-in feature that detects a potential conflict between two nodes trying to master the bus at the same time. For this detection, the SS pin is configured in hardware input mode. The connection of more than two SPI nodes working in this mode is impossible, as only one node can apply its output on a common data line at a given time.

When the nodes are not active, both stay in slave mode by default. Once a node wants to overtake control on the bus, it switches itself into master mode and applies active level on the slave select input of the other node via the dedicated GPIO pin. After the session is completed, the active slave select signal is released and the node mastering the bus temporarily returns back to passive slave mode waiting for the next session to start.

If both nodes raise their mastering request at the same time, a bus conflict event appears (see mode fault MODF event). The user can apply some simple arbitration process (for example postpone the next attempt by different predefined timeouts applied to both nodes).

Figure 959. Multimaster application

Figure 959: Multimaster application diagram. Two nodes, each labeled 'Master (Slave)', are connected via a shared bus. Each node contains an 'Rx (Tx) shift register', a 'Tx (Rx) shift register', and an 'SPI clock generator'. The bus lines are MISO, MOSI, SCK, GPIO, and SS(1). MISO and MOSI lines are bidirectional. SCK is bidirectional. GPIO is a dashed line with a right-pointing arrow. SS(1) is a dashed line with a left-pointing arrow. The diagram is labeled MSv50502V1 in the bottom right corner.
Figure 959: Multimaster application diagram. Two nodes, each labeled 'Master (Slave)', are connected via a shared bus. Each node contains an 'Rx (Tx) shift register', a 'Tx (Rx) shift register', and an 'SPI clock generator'. The bus lines are MISO, MOSI, SCK, GPIO, and SS(1). MISO and MOSI lines are bidirectional. SCK is bidirectional. GPIO is a dashed line with a right-pointing arrow. SS(1) is a dashed line with a left-pointing arrow. The diagram is labeled MSv50502V1 in the bottom right corner.
  1. 1. The SS pin is configured at hardware input mode at both nodes. Its active level enables the MISO line output control as the passive node is configured as a slave.
  2. 2. The RDY signal is not used in this communication.

80.4.7 Slave select (SS) pin management

In slave mode, the SS works as a standard 'chip select' input and lets the slave communicate with the master. In master mode, the SS can be used either as an output or an input. As an input it can prevent a multimaster bus collision, and as an output it can drive a slave select signal of a single slave. The SS signal can be managed internally (software management of the SS input) or externally when both the SS input and output are associated with the SS pin (hardware SS management). The user can configure which level of this input/output external signal (present on the SS pin) is considered as active by the SSIOP bit setting. SS level is considered as active if it is equal to SSIOP.

The hardware or software slave select management can be set using the SSM bit in the SPI_CFG2 register:

input of the master SS internal logic applicable at a multimaster topology exclusively.

Note: The purpose of automatic switching into slave mode when a mode fault occurs is to avoid the possible conflicts on data and clock lines. As the SPE is automatically reset in this condition, both Rx and Tx FIFOs are flushed and current data is lost.

When the SPI slave is enabled in the hardware SS management mode, all the transfers are ignored even in case of the SS is found at active level. They are ignored until the slave detects a start of the SS signal (transition from nonactive to active level) just synchronizing the slave with the master. This is because the hardware management mode cannot be used when the external SS pin is fixed. There is no such protection in the SS software management. Then the SSI bit must be changed when there is no traffic on the bus and the SCK signal is in idle state level between transfers exclusively in this case.

Figure 960. Scheme of SS control logic

Block diagram of SS control logic showing the interaction between SS pin, GPIO logic, multiplexers, and control blocks (SS output control, SS output logic) with SS_IN and SS_OUT signals. It includes a table for SS_IN modes.

The diagram illustrates the SS control logic, divided into SS external logic and SS internal logic. The SS pin connects to GPIO logic, which then interfaces with a multiplexer. The multiplexer's output is SS_IN, which feeds into the SS output control block. The SS output control block also receives SSIOP control, SSI control, and SSM control. Its output, SS_OUT, is connected to the SS output logic block, which also receives SSOM, MIDI, and MSSI control. The SS output logic block's output is SS_OUT. A note indicates that Master mode & HW SS management (SSM=0) only applies to the SS output control block. The SS output control block also receives SSOE control.

SS_INMaster modeSlave mode
SS(SSI) <> SSIOPOKNon active
SS(SSI) = SSIOPConflictActive

MSv40470V2

Block diagram of SS control logic showing the interaction between SS pin, GPIO logic, multiplexers, and control blocks (SS output control, SS output logic) with SS_IN and SS_OUT signals. It includes a table for SS_IN modes.

When the hardware output SS control is applied (SSM = 0, SSOE = 1), by configuration of the MIDI[3:0] and MSSI[3:0] bitfields, the user can control the timing of the SS signal between data frames and can insert an extra delay at the beginning of every transaction (to separate the SS and clock starts). This can be useful when the slave needs to slow down the flow to obtain sufficient room for correct data handling (see Figure 961).

Figure 961. Data flow timing control (SSOE = 1, SSOM = 0, SSM = 0)

Timing diagram showing the relationship between SS, SCK, MOSI, and MISO signals. It highlights data frame lengths (DSIZE[4:0] + 1), idle periods (MIDI[3:0]), and the clock period (t_sck).

The timing diagram shows the SS, SCK, MOSI, and MISO signals. The SS signal is high during idle periods and low during data frames. The SCK signal is a clock signal. The MOSI and MISO signals show data frames with MSB and LSB. The data frame length is DSIZE[4:0] + 1. The idle period length is MIDI[3:0]. The clock period is t_sck. The diagram is labeled MSv40472V1.

Timing diagram showing the relationship between SS, SCK, MOSI, and MISO signals. It highlights data frame lengths (DSIZE[4:0] + 1), idle periods (MIDI[3:0]), and the clock period (t_sck).
  1. 1. MSSI[3:0] = 0011, MIDI[3:0] = 0011 (SCK flow is continuous when MIDI[3:0] = 0).
  2. 2. CPHA = 0, CPOL = 0, SSIOP = 0, LSBFRST = 0.

Additionally, setting the SSOM bit invokes a specific mode, which interleaves pulses between data frames if there is a sufficient space to provide them (MIDI[3:0] must be set greater than one SPI period). Some configuration examples are shown in Figure 962.

Figure 962. SS interleaving pulses between data (SSOE = 1, SSOM = 1, SSM = 0)

Figure 962: Timing diagrams for SS interleaving pulses between data (SSOE = 1, SSOM = 1, SSM = 0) showing four SPI timing modes: I. CPHA=0, CPOL=0, SSIOP=0, LSBFRST=0; II. CPHA=1, CPOL=0, SSIOP=0, LSBFRST=0; III. CPHA=0, CPOL=1, SSIOP=1, LSBFRST=1; IV. CPHA=1, CPOL=1, SSIOP=1, LSBFRST=1.

I. CPHA=0, CPOL=0, SSIOP=0, LSBFRST=0

Timing parameters: MSSI[3:0], \(t_{\text{SCK}}\), DSIZE[4:0] + 1, MIDI[3:0], MIDI[3:0] - 1, DSIZE[4:0] + 1.
Signals shown: SS, SCK, MOSI (X, MSB, ..., LSB, X, MSB, ...), MISO (X, MSB, ..., LSB, X, X, MSB, ...).

II. CPHA=1, CPOL=0, SSIOP=0, LSBFRST=0

Timing parameters: MSSI[3:0], \(t_{\text{SCK}}/2\), DSIZE[4:0] + 1, MIDI[3:0], MIDI[3:0] - 1, DSIZE[4:0] + 1.
Signals shown: SS, SCK, MOSI (X, MSB, ..., LSB, X, MSB, ...), MISO (X, MSB, ..., LSB, X, MSB, ...).

III. CPHA=0, CPOL=1, SSIOP=1, LSBFRST=1

Timing parameters: MSSI[3:0], \(t_{\text{SCK}}\), DSIZE[4:0] + 1, MIDI[3:0], MIDI[3:0] - 1, DSIZE[4:0] + 1.
Signals shown: SS, SCK, MOSI (X, LSB, ..., MSB, X, LSB, ...), MISO (X, LSB, ..., MSB, X, X, LSB, ...).

IV. CPHA=1, CPOL=1, SSIOP=1, LSBFRST=1

Timing parameters: MSSI[3:0], \(t_{\text{SCK}}/2\), DSIZE[4:0] + 1, MIDI[3:0], MIDI[3:0] - 1, DSIZE[4:0] + 1.
Signals shown: SS, SCK, MOSI (X, LSB, ..., MSB, X, LSB, ...), MISO (X, LSB, ..., MSB, X, LSB, ...).

MSv40471V2

Figure 962: Timing diagrams for SS interleaving pulses between data (SSOE = 1, SSOM = 1, SSM = 0) showing four SPI timing modes: I. CPHA=0, CPOL=0, SSIOP=0, LSBFRST=0; II. CPHA=1, CPOL=0, SSIOP=0, LSBFRST=0; III. CPHA=0, CPOL=1, SSIOP=1, LSBFRST=1; IV. CPHA=1, CPOL=1, SSIOP=1, LSBFRST=1.
  1. 1. MSSI[3:0] = 0010, MIDI[3:0] = 0010.
  2. 2. SS interleaves between data when MIDI[3:0] > 1 wide of the interleaving pulse is always one SCK period less than the gap provided between the frames (defined by the MIDI parameter). If MIDI is set, the frames are separated by a single SCK period but no interleaving pulse appears on SS.

80.4.8 Ready pin (RDY) management

The status of the slave capability to handle data can be checked on the RDY pin. By default, a low level indicates that the slave is not ready for transaction. The reason can be that the slave TxFIFO is empty, RxFIFO full or the SPI is disabled. An active level of the signal can be selected by the RDIOP bit. If the master continues or starts to communicate with the slave when it indicates a not ready status, it is highly probable that the transaction fails.

The logic to control the RDY output is rather complex, tied closely with the TSIZE and DSIZE settings. The RDY reaction is more pessimistic and sensitive to TxFIFO becoming nearly empty and/or RxFIFO nearly full during a frame transaction. This pessimistic logic is suppressed at the end of a transaction only when RDY stays active, despite TxFIFO becomes fully empty and/or RxFIFO becomes fully occupied. The target is to prevent any data corruption and inform the master in time that it is necessary to suspend the transaction temporarily until the next transacted data can be processed safely again. When the RDY signal input is enabled at master side, the master suspends the communication once the slave indicates not ready status. This prevents the master to complete the transaction of an ongoing frame, which just empties the slave TxFIFO or full fills its RxFIFO until a next data is written and/or read there (despite the frame still can be completed without any constraint). It can make a problem if the TSIZE = 0 configuration is applied at slave because slave then never evaluates the end of the transaction (which suppresses the not ready status just when the last data is sent). Then the user has to release the RxFIFO and/or write additional (even dummy) data to TxFIFO by software at slave side to release the not RDY signal, unblock ST master and so enable it to continue at the communication suspended at middle of a frame occasionally.

When RDY is not used by the master, it must be disabled (RDIOM = 0). Then an internal logic of the master simulates the slave status always ready. In this case, the RDIOP bit setting has no meaning.

Due to synchronization between clock domains and evaluation of the RDY logic on both master and slave sides, the RDY pin feature is not reliable and cannot be used when the size of data frames is configured shorter than 8-bit.

80.4.9 Communication formats

During SPI communication, receive and transmit operations are performed simultaneously. The serial clock (SCK) synchronizes the shifting and sampling of the information on the data lines. The communication format depends on the clock phase, the clock polarity, and the data frame format. To be able to communicate together, the master and slave devices must follow the same communication format and be synchronized correctly.

Clock phase and polarity controls

Four possible timing relationships can be chosen by software, using the CPOL and CPHA bits in the SPI_CFG2 register. The CPOL (clock polarity) bit controls the idle state value of the clock when no data are being transferred. This bit affects both master and slave modes. If CPOL is reset, the SCK pin has a low-level idle state. If CPOL is set, the SCK pin has a high-level idle state.

If the CPHA bit is set, the second edge on the SCK pin captures the first data bit transacted (falling edge if the CPOL bit is reset, rising edge if the CPOL bit is set). Data are latched on each occurrence of this clock transition type. If the CPHA bit is reset, the first edge on the SCK pin captures the first data bit transacted (falling edge if the CPOL bit is set, rising edge if the CPOL bit is reset). Data are latched on each occurrence of this clock transition type.

The combination of the CPOL (clock polarity) and CPHA (clock phase) bits selects the data capture clock edges (dotted lines in Figure 963).

Figure 963 shows an SPI full-duplex transfer with the four combinations of the CPHA and CPOL bits.

Note: Prior to changing the CPOL/CPHA bits the SPI must be disabled by resetting the SPE bit. The idle state of SCK must correspond to the polarity selected in the SPI_CFG2 register (by pulling the SCK pin up if CPOL = 1 or pulling it down if CPOL = 0).

Figure 963. Data clock timing diagram

Figure 963: Data clock timing diagram showing four combinations of CPOL and CPHA. The top half shows CPHA = 1, and the bottom half shows CPHA = 0. Each half includes timing for CPOL = 1, CPOL = 0, MOSI, MISO, and NSS (to slave). Data bits are shown as MSBit and LSBit. Dotted lines indicate the clock edges used for data capture. The diagram shows a full-duplex transfer where MOSI and MISO are active simultaneously. The NSS signal is active low and is shown as a single pulse for the duration of the transfer.

The diagram illustrates the timing relationships between the SCK clock, data lines (MOSI and MISO), and the NSS (to slave) signal for four different SPI configurations. The top section is for CPHA = 1, and the bottom section is for CPHA = 0. In each section, the CPOL = 1 and CPOL = 0 cases are shown. The MOSI and MISO lines show data bits being shifted, with MSBit and LSBit labeled. The NSS signal is shown as a low pulse that spans the entire data transfer period. Dotted vertical lines indicate the specific clock edges (rising or falling) on which data is captured, based on the CPOL and CPHA settings.

Figure 963: Data clock timing diagram showing four combinations of CPOL and CPHA. The top half shows CPHA = 1, and the bottom half shows CPHA = 0. Each half includes timing for CPOL = 1, CPOL = 0, MOSI, MISO, and NSS (to slave). Data bits are shown as MSBit and LSBit. Dotted lines indicate the clock edges used for data capture. The diagram shows a full-duplex transfer where MOSI and MISO are active simultaneously. The NSS signal is active low and is shown as a single pulse for the duration of the transfer.

ai17154f

  1. 1. The order of data bits depends on the LSBFRST bit setting.

Data frame format

The SPI shift register can be set up to shift out MSB-first or LSB-first, depending on the value of the LSBFRST bit of the SPI_CFG2 register.

For instances with a full set of features, the data frame size is chosen by using the DSIZE[4:0] bits of the SPI_CFG1 register. It can be set from 4-bit up to 32-bit length and the setting applies for both transmission and reception. When the SPI_TXDR/SPI_RXDR registers are accessed, the data frames are always right-aligned into either a byte (if the data fit into a byte), a half-word, or a word (see Figure 964).

If the access is a multiple of the configured data size, data packing is applied automatically. During communication, only bits within the data frame are clocked and transferred.

Figure 964. Data alignment when data size is not equal to 8, 16 or 32 bits

Figure 964: Data alignment when data size is not equal to 8, 16 or 32 bits. The diagram shows three scenarios for data alignment based on the DSIZE register value. For each scenario, it shows the Tx (transmit) and Rx (receive) data frames. The Tx frames show the data bits (X) and the rest of the frame is padded with 0s. The Rx frames show the data bits (0) and the rest of the frame is padded with 0s. The scenarios are: 1) DSIZE ≤ 8-bits, data is right aligned on byte (Example: DSIZE[4:0]=00011). 2) 9-bits ≤ DSIZE ≤ 16-bits, data is right aligned on half-word (Example: DSIZE[4:0]=01101). 3) 17-bits ≤ DSIZE ≤ 32-bits, data is right aligned on word (Example: DSIZE[4:0]=11010).
DSIZE ≤ 8-bits
data is right aligned on byte
Example: DSIZE[4:0]=00011
9-bits ≤ DSIZE ≤ 16-bits
data is right aligned on half-word
Example: DSIZE[4:0]=01101
17-bits ≤ DSIZE ≤ 32-bits
data is right aligned on word
Example: DSIZE[4:0]=11010
Tx7 4 3 0
XXXX
15 14 13 0
XX
31 27 26 0
XXXXX
Rx7 4 3 0
0000
15 13 12 0
00
31 27 26 0
00000

MSv40473V1

Figure 964: Data alignment when data size is not equal to 8, 16 or 32 bits. The diagram shows three scenarios for data alignment based on the DSIZE register value. For each scenario, it shows the Tx (transmit) and Rx (receive) data frames. The Tx frames show the data bits (X) and the rest of the frame is padded with 0s. The Rx frames show the data bits (0) and the rest of the frame is padded with 0s. The scenarios are: 1) DSIZE ≤ 8-bits, data is right aligned on byte (Example: DSIZE[4:0]=00011). 2) 9-bits ≤ DSIZE ≤ 16-bits, data is right aligned on half-word (Example: DSIZE[4:0]=01101). 3) 17-bits ≤ DSIZE ≤ 32-bits, data is right aligned on word (Example: DSIZE[4:0]=11010).

Note: The minimum data length is 4 bits. If a data length of less than 4 bits is selected, it is forced to a 4-bit data frame size.

For instances with a limited set of features, the data size is fixed to a multiple of 8 bits up to the maximum data length (depends on instance) according to DSIZE[4:3] bits value. If the SPI_TXDR or SPI_RXDR is accessed by wider access (a multiple of the configured the data size), data packing is applied automatically.

80.4.10 Configuring the SPI

The configuration procedure is almost the same for the master and the slave. For specific mode setups, follow the dedicated chapters. When a standard communication must be initialized, perform these steps:

  1. 1. Write the proper GPIO registers: configure GPIO alternate functions at MOSI, MISO, SCK, SS, and RDY pins if applied.
  2. 2. Write into the SPI_CFG1 and SPI_CFG2 registers and set up the proper values of all 'not reserved' bits and bitfields, prior to enabling the SPI, with the following exceptions:
    1. a) The SSOM, MASRX, SSOE, RDIOM, MBR[2:0], BPASS, MIDI[3:0], MSSI[3:0] bits are taken into account in master mode only, the MSSI[3:0] bits take effect when the SSOE bit is set, the RDIOP bit takes no effect when the RDIOM bit is not set in master mode. When the slave is configured in TI mode, the MBR[2:0] setting is also considered.
    2. b) UDRCFG is taken into account in slave mode only.
    3. c) CRCSIZE[4:0] is required if CRCEN is set.
  1. d) CPOL, CPHA, LSBFRST, SSOM, SSOE, SSIOP, SSM, RDIOP, RDIOM, MSSI, and MIDI are not required in TI mode.
  2. e) Once the AFCNTR bit is set in the SPI_CFG2 register, all the SPI outputs start to be propagated onto the associated GPIO pins regardless of the peripheral enable. So, any later configuration changes of the SPI_CFG1 and SPI_CFG2 registers can affect the level of signals on these pins.
  3. 3. Write to the SPI_CR2 register to select the length of the transfer, if it is not known TSIZE must be programmed to zero.
  4. 4. Write to the SPI_CRCPOLY and into the TCRCINI, RCRCINI, and CRC33_17 bits of the SPI_CR1 register to configure the CRC polynomial and CRC calculation if needed.
  5. 5. Configure DMA streams dedicated for the SPI Tx and Rx in DMA registers if the DMA streams are used (see Section 80.4.15: Communication using DMA (direct memory addressing)).
  6. 6. Configure SSI, HDDIR, and MASRX in the SPI_CR1 register if required.
  7. 7. Program the IOLOCK bit in the SPI_CR1 register if the configuration protection is required (for safety).

80.4.11 Enabling the SPI

It is recommended to configure and enable the SPI slave before the master sends the clock. But there is no impact if the configuration and enabling procedure is done while traffic is ongoing on the bus, assuming that the SS signal is managed by hardware at slave or kept inactive by the slave software when the software management of the SS signal is applied (see Section 80.4.7). To prevent any risk of any data underrun, all the data to be sent have to be written to the slave transmitter data register before the master starts its clocking. The SCK signal must be settled to the idle state level corresponding to the selected polarity, before the SPI slave is selected by SS, else the following transaction may be desynchronized.

When the SPI slave is enabled at the hardware SS management mode, all the transfers are ignored even in case of the SS is found at active level. They are ignored until the slave detects a start of the SS signal (its transition from nonactive to active level) just synchronizing the slave with the master. That is why the hardware management mode cannot be used when the external SS pin is fixed. There is no such protection at the SS software management. In this case, the SSI bit must be changed when there is no traffic on the bus and the SCK signal is at idle state level between transfers exclusively in this case.

The master in full duplex (or in any transmit-only mode) starts to communicate when the SPI is enabled, the CSTART bit is set, and the TxFIFO is not empty, or with the next write to TxFIFO.

In any master receive-only mode, the master starts to communicate and the clock starts running after the SPI is enabled and the CSTART bit is set.

For handling DMA, see Section 80.4.15.

80.4.12 SPI data transmission and reception procedures

The setting of data communication format follows the basic principle that sure number of data with a flexible size must be transferred within a session (transaction) while, optionally, the data handling can be cumulated effectively into a single access of the SPI data registers (data packing) or even grouped into a sequence of such services if data is collected at consistent bigger data packets. The data handling services are based upon FIFO packet occupancy events. That is why the complete data packet must be serviced exclusively upon a dedicated packet flag.

To understand better the next detailed content of this section, the user must capture the configuration impact and meaning of the following items at first:

Data size (DSIZE): defines the data frame size (sets the number of bits at single data frame).

FIFO threshold (FTHLV): defines the data packet, sets the number of data frames at single data packet and so the occurrence of the packet occupancy events to handle SPI data registers either by software or by DMA.

Data access: a way how to handle the SPI data register content when the transfer data between the application and the SPI FIFOs upon a packet event. It depends on the packet size configuration. Optionally, multiple data can be handled effectively by a single access of the register (by data packing) or by sequence of such accesses (when servicing a bigger data packet).

FIFO size: capacity or space to absorb available data. It depends on the data size and the internal hardware efficiency how the data is compressed and organized within this space. The FTHLV setting must respect the FIFO capacity to store two data packets at least.

Transaction size (TSIZE): defines the total number of data frames involved at a transaction session overall possibly covered by several data packet services. There is no need to align this number with the packet size (handling of a last not aligned data packet is supported if TSIZE is programmed properly).

Data handling via Rx FIFO and Tx FIFO

All SPI data transactions pass through the embedded FIFOs organized by bytes (N × 8-bit). The size of the FIFOs (N) is dependent on the product and the peripheral instance. This enables the SPI to work in a continuous flow, and prevents overruns when the data frame size is short or the interrupt/DMA latency is too long. Each direction has its own FIFO called Tx FIFO and Rx FIFO, respectively.

The handling of the FIFO content is based on servicing data packet events exclusively raised by dedicated FIFO packet occupancy flags (TXP, RXP, or DXP). The flags occurrence depends on the data exchange mode (duplex, simplex), the data frame size (number of bits in the frame) and how data are organized at data packets. The frequency of the packet events can be decreased significantly when data are organized into packets by defining the FIFO threshold. Several data frames grouped at packet can then be handled effectively based on a single FIFO occupancy packet event either by a single SPI data register access or their sequence what consumes less system performance. The user can control the access type by casting the data register address to force a concrete CPU instruction applied for the register read or write. The access width can be 8, 16, or 32 bits, but a single data frame must be always accessed at least. It is crucial to keep the settings of the packet size (FTHLV) and data size (DSIZE) always balanced with the applied data register access (no matter if a single access or their sequence is applied) just to apply and

complete service of a single data packet upon its event. This principle, occurrence, and clearing capabilities of the FIFO occupancy flags are common no matter if DMA, interrupt, or polling is applied.

A read access to the SPI_RXDR register returns the oldest value stored in the Rx FIFO that has not been read yet. A write access to the SPI_TXDR stores the written data in the Tx FIFO at the end of a send queue.

A read access to the SPI_RXDR register must be managed by the RXP event. This flag is set by hardware when at least one complete data packet (defined as the receiver threshold by FTHLV[3:0] bits at the SPI_CFG1 register) is available at the reception FIFO while reception is active. The RXP is cleared as soon as less data than the complete single packet is available in the Rx FIFO, when reading from SPI_RXDR by software or by DMA.

The RXP triggers an interrupt if the RXPIE bit is set and/or a DMA request if the RXDMAEN bit is set.

Upon setting of the RXP flag, the application performs the due number of SPI data register reads to download the content of one data packet. Once a complete data packet is downloaded, the application software or DMA checks the RXP value to see if other packets are pending into the receive FIFO and, if so, downloads them packet by packet until the RXP reads 0. Rx FIFO can store up to N data frames (for frame size ≤ 8-bit), N/2 data frames (for 8-bit < frame ≤ 16-bit), N/3 data frames (for 16-bit < frame ≤ 24-bit) or N/4 data frames (if data frame > 24-bit) where N is the size of the FIFO in bytes.

At the end of a reception, it may happen that some data are still available in the Rx FIFO, without reaching the FTHLV level, thus the RXP is not set. In this case, the number of remaining RX data frames in the FIFO is indicated by the RXWNE and RXPLVL fields of the SPI_SR register. It happens when the number of the last data received in a transfer cannot fully accomplish the configured packet size. In this case, the transfer size and the packet size are not aligned. Nevertheless, the application software can still perform the standard number of reads from the Rx FIFO used for the previous complete data packets without drawbacks: only the consistent data (complete data frames) are popped from the Rx FIFO while redundant reads (or any incomplete data) are read as 0. Thanks to that, the application software can treat all the data in a transfer in the same way, and is off-loaded to foresee the reception of the last data in a transfer and to calculate the due number of reads to be popped from Rx FIFO.

In a similar way, the write access of a data frame to be transmitted is managed by the TXP event. This flag is set by hardware when there is enough space for the application to push at least one complete data packet (defined at FTHLV[3:0] bits of the SPI_CFG1 register) into the transmission FIFO while transmission is active. The TXP is cleared as soon as the Tx FIFO is filled by software and/or by the DMA. The space currently available for any next complete data packet is lost. This can lead to oscillations of the TXP signal when data are released out from the Tx FIFO while a new packet is stored frame by frame. Any write to the Tx FIFO is ignored when there is no sufficient room to store at least a single data frame (TXP event is not respected), when TXTF is set or when the SPI is disabled.

The TXP triggers an interrupt if the TXPIE bit is set and/or with a DMA request if the TXDMAEN bit is set. The TXPIE mask is cleared by hardware when the TXTF flag is set.

Upon setting of the TXP flag, the application performs the due number of SPI data register writes to upload the content of one entire data packet. Once a new complete data packet is uploaded, the application software or DMA checks the TXP value to see if other packets can be pushed into the Tx FIFO and, if so, uploads them packet by packet until TXP reads 0.

The number of last data in a transfer can be shorter than the configured packet size in the case when the transfer size and the packet size are not aligned. Nevertheless, the application software can still perform the standard number of data register writes used for the previous packets without drawbacks: only the consistent data are pushed into the TxFIFO while redundant writes are discarded. Thanks to that, the application software can treat all the data in a transfer in the same way and is off-loaded to foresee the transmission of the last data in a transfer and from calculating the due number of writes to push the last data into TxFIFO. Just for the last data case, the TXP event is asserted by SPI once there is enough space into TxFIFO to store the remaining data to complete the current transfer.

Both TXP and RXP events can be polled or handled by interrupts. The DXP bit can be monitored as a common TXP and RXP event at full-duplex mode.

Upon setting of the DXP flag, the application performs the due number of writes to the SPI data register to upload the content of one entire data packet for transmission, followed by the same number of reads from the SPI data register to download the content of one data packet. Once one data packet is uploaded and one is downloaded, the application software or DMA checks the DXP value to see if other packets can be pushed and popped in sequence and, if so, uploads/downloads them packet by packet until DXP reads 0.

The DXP triggers an interrupt if the DXPIE bit is set. The DXPIE mask is cleared by hardware when the TXTF flag is set.

The DXP is useful in full-duplex communication to optimize performance in data uploading/downloading, and reducing the number of interrupts or DMA sequences required to support an SPI transfer thus minimizing the request for CPU bandwidth and system power especially when SPI is operated in Stop mode.

When rely on the DXP interrupt exclusively, the user must consider the drawback of such a simplification when TXP and RXP events are serviced by common procedures because the TXP services are delayed by purpose in this case. This is because the TXP events precede the reception RXP ones normally to allow the TXP servicing prior to the transaction of the last frame fully emptying the TxFIFO else the master cannot provide a continuous SCK clock flow and the slave can even face an underrun condition. The possible solution is to prefill the TxFIFO by a few data packets ahead prior to starting the session, and to handle all the data received after the TXTF event by EOT exclusively at the end of the transaction (as TXTF suppresses the DXP interrupts at the end of the transaction). If CRC computation is enabled, the user must calculate with additional space to accommodate the CRC frame at Rx FIFO when relying on EOT exclusively at the end of the transaction.

Another way to manage the data exchange is to use DMA (see Section 80.4.15).

If the next data is received when the Rx FIFO is full, an overrun event occurs (see description of OVR flag in Section 80.5.2). An overrun event can be polled or handled by an interrupt.

This may happen in slave mode or in a master receive mode when MASRX = 0. If the MASRX bit is set at a master receiver, the generated clock stops automatically when the Rx FIFO is full, therefore overrun is prevented.

Both Rx FIFO and TxFIFO content are kept flushed and cannot be accessed when SPI is disabled (SPE = 0).

Transaction handling

A few data frames can be passed at single sequence to complete a message. The user can handle a number of data within a message thanks to the value stored into TSIZE. In

principle, the transaction of a message starts when the SPI is enabled by setting the CSTART bit and finishes when the total number of required data is transacted. The end of the transaction controls the CRC and the hardware SS management when applied. To restart the internal state machine properly, SPI is strongly suggested to be disabled and reenabled before the next transaction starts despite its setting is not changed.

If TSIZE is kept at zero while CSTART is set, an endless transaction is initialized (no control of transfer size is applied). During an endless transaction, the number of transacted data aligned with the FIFO threshold is supported exclusively. If the number of data (or its grouping into packets) is unpredictable, the user must keep the FIFO threshold setting (packet size) at single data (FTHLV = 0) to ensure that each data frame raises its own packet event to be serviced by the application or DMA. The transaction can be suspended at any time thanks to CSUSP, which clears the CSTART bit. SPI must always be disabled after such software suspension and reenabled before the next transaction starts.

When the transmission is enabled, a sequence begins and continues while any data is present in the TxFIFO of the master. The clock signal is provided permanently by the master until TxFIFO becomes empty, then it stops, waiting for additional data.

In receive-only modes, half-duplex (COMM[1:0] = 11, HDDIR = 0) or simplex (COMM[1:0] = 10) modes, the master starts the sequence when the SPI is enabled and the transaction is released by setting the CSTART bit. The clock signal is provided by the master and it does not stop until either SPI or receive-only mode is disabled/suspended by the master. The master receives data frames permanently up to this moment. The reception can be suspended either by software control, writing 1 to the CSUSP bit in the SPI_CR1 register, or automatically when MASRX = 1 and RxFIFO becomes full or upon the RDY status if this signal is applied (see Section 80.4.8). The reception is automatically stopped also when the number of frames programmed in TSIZE has been completed.

To disable the master receive-only mode, the SPI must first be suspended. When the SPI is suspended, the current frame is completed, before changing the configuration.

Caution: If the SPE bit is cleared in master mode, while the reception is ongoing without any suspending, the clock is stopped without completing the current frame, and the RxFIFO is flushed.

While the master can provide all the transactions in continuous mode (SCK signal is continuous) it must respect the slave capability to handle data flow and its content at any time. If the slave features the RDY signal option, the master can monitor the RDY signal issued by the slave, to control the communication flow. If the RDY pin is not used, the slave is considered always ready for communication with the master.

When necessary, the master must slow down the communication and provide either a slower clock or separate frames or data sessions with sufficient delays by MIDI[3:0] bits setting or provide an initial delay by setting MSSI[1:0], which postpones any transaction start to give the slave sufficient room for preparing data. Be aware that data from the slave are always transacted and processed by the master even if the slave cannot prepare it correctly in time. It is preferable for the slave to use DMA, especially when data frames are short, FIFO is accessed by bytes and the SPI bus rate is high.

To add some software control on the SPI communication flow from a slave transmitter node, a specific value written to the SPI_UDRDR register (SPI underrun data register) can be used. On the slave side, when TxFIFO becomes empty, this value is sent out automatically as the next data and may be interpreted by software on the master receiver side (either simply dropped or interpreted as an XOFF like command, to suspend the master receiver by software).

In the multislave star topology, only a single slave can be enabled to output data at a given time. The slave just selected for the communication with the master needs to detect a change of its SS input into active level before communication with the master starts. In a single slave system it is not necessary to control the slave with SS, but it is often better to provide the pulse here too, to synchronize the slave with the beginning of each data sequence. The SS can be managed by both software and hardware (Section 80.4.7).

80.4.13 Disabling the SPI

To disable the SPI, it is mandatory to follow the disable procedures described in this paragraph.

In the master mode, it is important to do this before the system enters a low-power mode when the peripheral clock is stopped, otherwise, ongoing transactions may be corrupted.

In slave mode, the SPI communication can continue when the spi_pclk and spi_ker_ck clocks are stopped, without interruption, until any end of communication or data service request condition is reached. The spi_pclk can generally be stopped by setting the system into Stop mode. Refer to the RCC section for further information.

The master in full-duplex or transmit-only mode can finish any transaction when it stops providing data for transmission. In this case, the clock stops after the last data transaction. TXC flag can be polled (or interrupt enabled with EOTIE = 1) in order to wait for the last data frame to be sent.

When the master is in any receive-only mode, to stop the peripheral, the SPI communication must first be suspended, by setting the CSUSP bit.

The data received but not read remain stored in RxFIFO when the SPI is suspended.

After such a software suspension, SPI must always be disabled to restart the internal state machine properly.

When SPI is disabled, RxFIFO is flushed. To prevent losing unread data, the user must ensure that RxFIFO is empty when disabling the SPI, by reading all remaining data (as indicated by the RXP, RXWNE, and RXPLVL fields in the SPI_SR register).

The standard disable procedure is based on polling EOT and/or TXC status to check if a transmission session is (fully) completed. This check can be done in specific cases, too, when it is necessary to identify the end of ongoing transactions, for example:

When TSIZE > 0, EOT and TXC signals are equal so polling of EOT is reliable at whatever SPI communication mode to check the end of the bus activity. When TSIZE = 0, the user has to check TXC, SUSP, or FIFO occupancy flags according to the applied SPI mode and the way of the data flow termination.

The correct disable procedure in master mode, except when receive-only mode is used, is:

  1. 1. Wait until TXC = 1 and/or EOT = 1 (no more data to transmit and last data frame sent). When CRC is used, it is sent automatically after the last data in the block is processed.

TXC/EOT is set when the CRC frame is completed in this case. When a transmission is suspended the software has to wait until the CSTART bit is cleared.

  1. 2. Read all RxFIFO data (until RXWNE = 0 and RXPLVL = 00).
  2. 3. Disable the SPI (SPE = 0).

The correct disable procedure for master receive-only modes is:

  1. 1. Wait on EOT or break the receive flow by suspending SPI (CSUSP = 1).
  2. 2. Wait until SUSP = 1 (the last data frame is processed) if the receive flow is suspended.
  3. 3. Read all RxFIFO data (until RXWNE = 0 and RXPLVL = 00).
  4. 4. Disable the SPI (SPE = 0).

In slave mode, any ongoing data are lost when disabling the SPI.

Controlling the I/Os

As soon as the SPI is disabled, the associated and enabled AF outputs can still be driven by the device depending on the AFCNTR setting. When active output control is applied (AFCNTR = 1) and SPI has just been disabled (SPE = 0), the enabled outputs associated with SPI control signals (like SS and SCK at master and RDY at slave) can immediately toggle to inactive level (according to SSIOP and CPOL settings at master and RDIOP at slave respectively). Instead, the data line output (MOSI at master and MISO at slave) can immediately change its level depending on the actual TxFIFO content, with the effect of potentially making invalid and no more guaranteed the value of the latest transacted bit on the bus. If necessary, the user has to take care about proper data hold time at the data line and avoid any eventual fast SPI disable just after the last data transaction is completed.

Note: Despite stability of the latest bit is guaranteed by design during the sampling edge of the clock, some devices can require even extension of this data bit stability interval during the sampling. It can be done, for example by inserting a small software delay between EOT event occurrence and SPI disable action.

80.4.14 Data packing

From the user point of view there are two ways of data packing, which can overlay each other:

When the data frame size fits into one byte (less than or equal to 8 bits), the data packing is used automatically when any read or write 16-bit or 32-bit access is performed from/to the SPI_RXDR/SPI_TXDR registers. The multiple data frame pattern is handled in parallel in this case. At first, the SPI operates using the pattern stored in the LSB of the accessed word, then with the other data stored in the MSB.

Figure 965 provides an example of data packing mode sequence handling for a full-featured instance. While DSIZE[4:0] is configured to 4-bit there, two or four data frames are written to

the TxFIFO after the single 16-bit or 32-bit access to the SPI_TXDR register of the transmitter. When the data frame size is between 9-bit and 16-bit, data packing is used automatically when a 32-bit access is done. The least significant half-word is used first (regardless of the LSBFRST value).

This sequence can generate two or four RXP events in the receiver if the RxFIFO threshold is set to one frame (and data is read on a frame basis, unpacked), or it can generate a single RXP event if the FTHLV[3:0] field of the SPI_CFG1 register is programmed to a multiple of the frames to be read in a packed mode (16-bit or 32-bit read access).

The data are aligned in accordance with Figure 964. The valid bits are performed on the bus exclusively. Unused bits are not cared at transmitter while padded by zeros at receiver.

When short data frames (< 8-bit or < 16-bit) are used together with a larger data access mode (16-bit or 32-bit), the FTHLV value must be programmed as a multiple of the number of frames/data access (multiple of 4 if 32-bit access is used to up to 8-bit frames or multiple of 2 if 16-bit access is used to up to 8-bit frames or 32-bit access to up to 16-bit frames.).

The RxFIFO threshold setting must always be higher or equal at least than the following read access size, as spurious extra data would be read otherwise.

The FIFO data access less than the configured data size is forbidden. One complete data frame must be always accessed at a minimum.

A specific problem appears if an incomplete data packet is available at FIFO: less than the threshold set through the FTHLV bits.

There are two ways of dealing with this problem:

Figure 965. Packing data in FIFO for transmission and reception for a full-featured instance

Diagram showing SPI data flow from TX_FIFO to TX_FIFO and RX_FIFO to RX_FIFO, including SS, SCK, and MOSI signals, and SPI fsm & shift blocks. It details data packing for 8-bit, 16-bit, and 32-bit transfers.

The diagram illustrates the SPI data flow for a full-featured instance. It shows the SS (Slave Select) signal, the SCK (Serial Clock) signal, and the MOSI (Master Out Slave In) signal. Data is packed into the TX_FIFO (address 0x0007040A) and RX_FIFO (address 0x0007040A). The TX_FIFO is populated by the SPI_TXDR register, and the RX_FIFO is populated by the SPI_RXDR register. The SPI fsm & shift block is responsible for shifting data in and out of the FIFOs. The diagram also shows the data packing for 8-bit, 16-bit, and 32-bit transfers. For 8-bit transfers, the data is packed as 0x0A, 0x04, 0x07, 0x00. For 16-bit transfers, the data is packed as 0x040A, 0x0007. For 32-bit transfers, the data is packed as 0x0007040A. The diagram also includes the configuration parameters: (CPHA=0, CPOL=0, LSBFRST=0, DSIZE[4:0]=00011).

TX_FIFO after write access to SPI_TXDR:
4x 8-bit (0x0A, 0x04, 0x07, 0x00) or
2x 16-bit (0x040A, 0x0007) or
1x 32-bit (0x0007040A)

RX_FIFO before read access from SPI_RXDR:
4x 8-bit (0x0A, 0x04, 0x07, 0x00) or
2x 16-bit (0x040A, 0x0007) or
1x 32-bit (0x0007040A)

MSv40474V2

Diagram showing SPI data flow from TX_FIFO to TX_FIFO and RX_FIFO to RX_FIFO, including SS, SCK, and MOSI signals, and SPI fsm & shift blocks. It details data packing for 8-bit, 16-bit, and 32-bit transfers.
  1. 1. DSIZE[4:0] is configured to 4-bit, data is right aligned, valid bits are performed only on the bus. Their order depends on LSBFRST. If it is set, the order is reversed at all the data frames.

80.4.15 Communication using DMA (direct memory addressing)

To operate at its maximum speed and to facilitate the data register read/write process required to avoid overrun, the SPI features a DMA capability, which implements a simple request/acknowledge protocol.

A DMA access is requested when the TXDMAEN or RXDMAEN enable bits of the SPI_CFG1 register are set. Separate requests must be issued to the Tx and Rx buffers to fulfill the service of the defined packet.

If the SPI is programmed in receive-only mode, UDR is never set.

If the SPI is programmed in a transmit mode, TXP and UDR can be eventually set at slave side, because transmit data may not be available. In this case, some data are sent on the TX line according with the UDR management selection.

When the SPI is used at a simplex mode, the user must enable the adequate DMA channel only while keeping the complementary unused channel disabled.

If the SPI is programmed in transmit-only mode, RXP and OVR are never set.

If the SPI is programmed in full-duplex mode, RXP and OVR are eventually set, because received data are not read.

In transmission mode, when the DMA or the user has written all the data to be transmitted (the TXTF flag is set in the SPI_SR register), the EOT (or TXC at case TSIZE = 0) flag can be monitored to ensure that the SPI communication is complete. This is required to avoid

corrupting the last transmission before disabling the SPI or before disabling the spi_pclk in master mode. The software must first wait until EOT = 1 and/or TXC = 1.

When starting communication using DMA, to prevent DMA channel management raising error events, these steps must be followed in order:

  1. 1. Enable the DMA Rx buffer in the RXDMAEN bit of the SPI_CFG1 register, if DMA Rx is used.
  2. 2. Enable DMA requests for Tx and Rx in DMA registers, if the DMA is used.
  3. 3. Enable the DMA Tx buffer in the TXDMAEN bit of the SPI_CFG1 register, if DMA Tx is used.
  4. 4. Enable the SPI by setting the SPE bit.

To close communication, it is mandatory to follow these steps in order:

  1. 1. Disable DMA requests for Tx and Rx in the DMA registers, if the DMA issued.
  2. 2. Disable the SPI by following the SPI disable procedure.
  3. 3. Disable DMA Tx and Rx buffers by clearing the TXDMAEN and RXDMAEN bits of the SPI_CFG1 register, if DMA Tx and/or DMA Rx are used.

Data packing with DMA

If the transfers are managed by DMA (TXDMAEN and RXDMAEN set in the SPI_CFG1 register) the packing mode is enabled/disabled automatically depending on the PSIZE value configured for SPI TX and the SPI RX DMA channel.

If the DMA channel PSIZE value is equal to 16-bit and the SPI data size is less than or equal to 8-bit, then the packing mode is enabled. Similarly, if the DMA channel PSIZE value is equal to 32-bit and the SPI data size is less than or equal to 16-bit, then the packing mode is enabled. The DMA then automatically manages the write operations to the SPI_TXDR register.

The DMA completes the transfer automatically according to the TSIZE field setting, whatever the data packing mode used, and even if the number of data to transfer is not a multiple of the DMA data size (16 bits or 32 bits) while the frame size is smaller.

Alternatively, the last data frames can be written by software, in the single/unpacked mode.

Configuring any DMA data access to less than the configured data size is forbidden. One complete data frame must be always accessed at minimum.

80.4.16 Autonomous mode

The SPI is capable of handling and initializing transactions autonomously. It requires no specific system execution interaction until the ongoing transaction ends.

Such autonomous transactions can be handled not only in Run or Sleep mode but even in Stop mode when the SPI logic is able to provide temporary clock requests addressed to the reset and clock controller (RCC) to ensure clocking of those SPI domains just necessary for handling the data flow between the memory and the peripheral interface at dependency in the SPI mode.

In Stop mode, the APB clock is requested by the peripheral each time the SPI registers need to be updated based on specific traffic events (mainly TXP and RXp). The required clock is provided by RCC if SPI autonomous mode is enabled at the RCC configuration and the SPI is clocked by an internal oscillator available in Stop mode.

Interrupts or DMA requests are then generated, depending on the SPI configuration. If no interrupt is enabled, the device remains in Stop mode. If DMA requests are enabled, the data are directly transferred to/from the SRAM thanks to the DMA while the device remains in Stop mode. If an enabled interrupt occurs, the device wakes up from Stop mode.

Note: The peripheral clock request stays pending until the flag with enabled interrupt is set. This is why it is important to service these pending requests and clear their flag as soon as possible at system sensitive to the low-power consumption especially, and the application must acknowledge all pending interrupts events before switching the SPI to low-power mode.

Slave mode

When the SPI is configured as a standard slave and the device is at Stop mode, the SPI kernel clock and the SPI APB clock are not provided permanently. All the data flow between the SPI interface and associated FIFOs is handled by an external SCK clock provided by the outer master device within the serial interface clock domain. APB clock temporal requests are then based upon specific traffic events at dependency on the SPI configuration. As the slave never initializes a transaction, there is no need to synchronize any transaction start in this mode.

Note: The peripheral clock request stays pending until the flag with enabled interrupt stays set. This is why it is important to service these pending requests and clear their flag as soon as possible to achieve the lowest power consumption, and the application must acknowledge all pending interrupt events before switching the SPI to low-power mode.

Master mode

The SPI operating in master mode provides the SCK signal for outer slaves until the transaction is completed. The SCK signal is derived from the SPI clock generator running within the kernel clock domain fed from the RCC upon kernel clock request provided by the SPI when the device is in Stop mode. Temporal requests for the APB clock are then based upon specific traffic events, depending on the SPI configuration. The SPI master always initializes a transaction.

To minimize consumption in Stop mode, it is suggested to combine communication starts triggered by hardware (the TRIGEN bit is set in the SPI_AUTOCR register) and transfers of predefined data size (TSIZE > 0 in the SPI_CR2 register). This ensures that any APB clock request is suppressed between EOT handling and the next trigger event.

A transaction starts once the CSTART bit is set. In the case of master transmitter, the TxFIFO must be filled by data, too. The CSTART bit can be written either by software or by hardware when a synchronous trigger is detected at Run, Sleep, or Stop mode. The trigger source is selected by the TRIGSEL bits and enabled by the TRIGEN bit of the SPI_AUTOCR register. When the enabled trigger is detected, the transfer starts and continues by handling data until the EOT event or the transaction suspension. When the TRIGEN bit is changed, the user must prevent any trigger event occurrence. If the user cannot prevent that, the TRIGEN bit must be written while the SPI is disabled otherwise the peripheral behavior is not guaranteed.

80.5 SPI specific modes and control

80.5.1 TI mode

With a specific SP[2:0] bitfield setting of the SPI_CFG2 register, the SPI can be configured compliant with the TI protocol. The SCK and SS signals polarity, phase and flow, as well as the bit order are fixed, so the setting of CPOL, CPHA, LSBFRST, SSOM, SSOE, SSIOP, SSM, RDIOP, RDIOM, MSSI, and MIDI is not required when the SPI is in TI mode configuration. The SS signal synchronizes the protocol by pulses over the LSB data bit as it is shown in Figure 966.

Figure 966. TI mode transfer

Timing diagram for TI mode transfer showing SS, SCK, MOSI, and MISO signals. SS is an active-high strobe. SCK is a clock signal. MOSI and MISO show data transfer with MSB and LSB labels. The diagram indicates data size (DSIZE[4:0] + 1) and the TRELEASE delay after the last bit transfer.

The diagram illustrates the timing for TI mode transfer. It shows four signals: SS (Slave Select), SCK (Serial Clock), MOSI (Master Out Slave In), and MISO (Master In Slave Out). SS is an active-high pulse that starts and ends a data transaction. SCK provides the clock for data transfer. MOSI and MISO show the data being transferred, with MSB (Most Significant Bit) and LSB (Least Significant Bit) labels. The data size is indicated as DSIZE[4:0] + 1. The TRELEASE delay is shown after the last bit transfer, indicating the time for the MISO signal to become high-Z.

Timing diagram for TI mode transfer showing SS, SCK, MOSI, and MISO signals. SS is an active-high strobe. SCK is a clock signal. MOSI and MISO show data transfer with MSB and LSB labels. The diagram indicates data size (DSIZE[4:0] + 1) and the TRELEASE delay after the last bit transfer.

In slave mode, the clock generator is used to define the time when the slave output at MISO pin becomes high-Z when the current transaction finishes. The master baud rate setting (MBR[2:0] of SPI_CFG1) is applied and any baud rate can be used to determine this moment with optimal flexibility. The delay for the MISO signal to become high-Z (TRELEASE) depends on internal resynchronization, too, which takes the next additional 2-4 periods of the clock signal feeding the generator. It is given by the following formula:

\[\frac{T_{\text{baud}}}{2} + 2 \times T_{\text{spi\_ker\_ck}} \leq T_{\text{release}} \leq \frac{T_{\text{baud}}}{2} + 4 \times T_{\text{spi\_ker\_ck}}\]

If the slave detects a misplaced SS pulse during a data transaction the TIFRE flag is set.

80.5.2 SPI error flags

An SPI interrupt is generated if one of the following error flags is set and the interrupt is enabled by setting the corresponding interrupt enable bit.

Overrun flag (OVR)

An overrun condition occurs when data are received by a master or slave and the RxFIFO has not enough space to store these received data. This can happen if the software or the DMA did not have enough time to read the previously received data (stored in the RxFIFO).

When an overrun condition occurs, the OVR flag is set and the newly received value does not overwrite the previous one in the RxFIFO. The newly received value is discarded and all

data transmitted subsequently are lost. The OVR flag triggers an interrupt if the OVRIE bit is set. Clearing the OVR bit is done by setting the OVRC bit of the SPI_IFCR register. Clearing the RxFIFO content by performing software reads before the OVR bit is cleared reduces the risk of any immediate repetition of its next overrun. It is suggested to release the RxFIFO space as much as possible, this means to read out all the available data packets based on RXP flag indication.

In master mode, the user can prevent the RxFIFO overrun by automatic communication suspend (MASRX bit).

Underrun flag (UDR)

In a slave-transmitting mode, the underrun condition is captured internally by hardware if no data is available for transmission in the slave TxFIFO commonly. The UDR flag setting is then propagated into the status register by hardware (see note below). UDR triggers an interrupt if the UDRIE bit is set.

Underrun detection logic and system behavior depend on the UDRCFG bit. When an underrun is detected by the slave, it can provide out either a constant pattern stored by the user at the UDRDR register or the data received previously from the master. When the first configuration (UDRCFG = 0) is applied, the underrun condition is evaluated whenever the master starts to communicate a new data frame while TxFIFO is empty. Then single additional dummy (accidental) data is always inserted between the last valid data and the constant pattern defined at the UDRDR register (see Figure 967). The second configuration (UDRCFG=1) can be used in circular topography structures (see Figure 958). Assuming that TxFIFO is not empty when the master starts the communication, the underrun condition is evaluated just once the FIFO becomes empty during the next data flow. Valid data from TxFIFO is then upended by the lastly received data immediately.

The standard transmission is reenabled once the software clears the UDR flag and this clearing is propagated into SPI logic by hardware. Writing some data to the TxFIFO before the UVR bit is cleared reduces the risk of any immediate repetition of its next underrun.

The data transacted by the slave is unpredictable especially when the transaction starts or continues while TxFIFO is empty and the underrun condition is either not yet captured or just cleared. Typically, this is the case when SPI is just enabled or when a transaction with a defined size just starts. First bits can be corrupted in this case, as well, when the slave software writes the first data into the empty TxFIFO too close prior to starting the data transaction (propagation of the data into TxFIFO takes a few APB clock cycles).

Figure 967. Optional configurations of the slave behavior when an underrun condition is detected

Timing diagram showing optional configurations of slave behavior when an underrun condition is detected. The diagram is split into two sections: UDRCFG=0 and UDRCFG=1. In both sections, SCK is a continuous clock signal. MOSI shows data frames DI1, DI2, and DI3. TxFIFO occupancy starts at 1 and drops to 0 after DI1. In the UDRCFG=0 section, MISO shows DO1, then a 'Dummy' frame, then [UDRDR]. In the UDRCFG=1 section, MISO shows DO1, then DI1, then DI2. The UDR signal shows a propagation latency after the underrun event.

UDRCFG=0

SCK

MOSI

MISO

TxFIFO occupancy

UDR

UDRCFG=1

SCK

MOSI

MISO

TxFIFO occupancy

UDR

MSv63460V1

Timing diagram showing optional configurations of slave behavior when an underrun condition is detected. The diagram is split into two sections: UDRCFG=0 and UDRCFG=1. In both sections, SCK is a continuous clock signal. MOSI shows data frames DI1, DI2, and DI3. TxFIFO occupancy starts at 1 and drops to 0 after DI1. In the UDRCFG=0 section, MISO shows DO1, then a 'Dummy' frame, then [UDRDR]. In the UDRCFG=1 section, MISO shows DO1, then DI1, then DI2. The UDR signal shows a propagation latency after the underrun event.

Note: The hardware propagation of an UDR event needs additional traffic on the bus. It always takes a few extra SPI clock cycles after the event happens (both underrun captured by hardware and cleared by software). If clearing of the UDR flag by software is applied close to the end of the data frame transaction or when the SCK line is at idle in between the frames, the next extra underrun pattern is sent initially by the slave before the valid data from TxFIFO becomes transacted again. The user can prevent this by SPI disable/enable action between sessions to restart the underrun logic and so initiate the next session by the valid data.

Mode fault (MODF)

Mode fault occurs when the master device has its internal SS signal (SS pin in SS hardware mode, or SSI bit in SS software mode) pulled low. This automatically affects the SPI interface in the following ways:

MODF is cleared by writing 1 to the MODFC bit of the SPI_IFCR register.

To avoid any multiple slave conflicts in a system comprising several MCUs, the SS pin must be pulled to its nonactive level before reenabling the SPI, by setting the SPE bit.

As a security, the hardware does not allow the SPE bit to be set while the MODF bit is set. In a slave device, the MODF bit cannot be set except as the result of a previous multimaster conflict.

A correct software procedure when a master overtakes the bus in multimaster systems must be the following one:

  1. 1. Switch into master mode while SSOE = 0 (potential conflict can appear when another master occupies the bus. In this case, MODF is raised, which prevents any next node switching into master mode)
  2. 2. Put GPIO pin dedicated for another master SS control into active level
  3. 3. Perform a data transaction
  4. 4. Put GPIO pin dedicated for another master SS control into nonactive level
  5. 5. Switch back to slave mode

CRC error (CRCE)

This flag is used to verify the validity of the value received when the CRCEN bit of the SPI_CFG1 register is set. The CRCE flag of the SPI_SR register is set if the value received in the shift register does not match the receiver SPI_RXCRC value, after the last data is received (as defined by TSIZE). The CRCE flag triggers an interrupt if the CRCEIE bit is set. Clearing the bit CRCE is done by a writing 1 to the CRCEC bit of the SPI_IFCR register.

TI mode frame format error (TIFRE)

A TI mode frame format error is detected when an SS pulse occurs during an ongoing communication when the SPI is operating in slave mode and configured to conform to the TI mode protocol. When this error occurs, the TIFRE flag is set in the SPI_SR register. The SPI is not disabled when an error occurs, the SS pulse is ignored, and the SPI waits for the next SS pulse before starting a new transfer. The data may be corrupted since the error detection may result in the loss of a few data frames.

The TIFRE flag is cleared by writing 1 to the TIFREC bit of the SPI_IFCR register. If the TIFREIE bit is set, an interrupt is generated on the SS error detection. As data consistency is no longer guaranteed, communication must be reinitiated by software between master and slave.

80.5.3 CRC computation

Two separate 33-bit or two separate 17-bit CRC calculators are implemented to check the reliability of transmitted and received data. For instances with a full set of features, the SPI offers CRC polynomial length from 5 to 33 bits when the maximum data size is 32-bit and from 9 to 17 bits for the peripheral instances with data size limited to 16 bits. For instances with a limited set of features, the CRC polynomial length can be set either to 9 or 17 only when data size is limited to 16 bit and optionally to 33 when data size is extended to 32-bit.

The length of the polynomial is defined by the most significant bit of the value stored in the SPI_CRCPOLY register. It must be greater than the data frame size (in bits) defined in the DSIZE[4:0] bitfield of the SPI_CFG1 register. To obtain a full-size polynomial, the polynomial length must exceed the maximum data size of the peripheral instance, and the CRC33_17 bit of the SPI_CR1 register must be set to select the most significant bit of the polynomial string. For example, to select the standard CRC16-CCITT (XMODEM) polynomial x¹⁶+

x¹²+x⁵+1, write 0x11021 to the SPI_CRCPOLY register for a 32-bit instance, whereas to obtain the full size for a 16-bit instance, write 0x1021 with the CRC33_17 bit set.

The CRCSIZE field of the SPI_CFG1 register then defines how many most significant bits from the CRC calculation registers are transacted and compared as CRC frame. It is defined independently from the data frame length, but it must be either equal or an integer multiple of the data frame size. Its size cannot exceed the maximum data size of the instance.

To fully benefit from the CRC calculation capability, the polynomial length setting must correspond to the CRC pattern size, else the bits unused at the calculation are transacted and expected all zero at the end of the CRC pattern if its size is set greater than the polynomial length.

CRC principle

The CRC calculation is enabled by setting the CRCEN bit of the SPI_CFG1 register before the SPI is enabled (SPE = 1). The CRC value is then calculated using the CRC polynomial defined by the CRCPOLY register and CRC33_17 bit. When SPI is enabled, the CRC polynomial can be changed but only in the case when there is no traffic on the bus.

The CRC computation is done, bit by bit, on the sampling clock edge defined by the CPHA and CPOL bits of the SPI_CR1 register. The calculated CRC value is checked automatically at the end of the data block defined by the SPI_CR2 register exclusively.

When a mismatch is detected between the CRC calculated internally on the received data and the CRC received from the transmitter, a CRCE flag is set to indicate a data corruption error. The right procedure for handling the CRC depends on the SPI configuration and the chosen transfer management.

CRC transfer management

Communication starts and continues normally until the last data frame has been sent or received in the SPI_DR register.

The length of the transfer must be defined by TSIZE. When the desired number of data is transacted, the TXCRC is transmitted and the data received on the line are compared to the RXCRC value.

Whatever the CRCSIZE configuration, TSIZE cannot be set to 0xFFFF for a full-featured instance, and to 0x3FF for a limited-featured instance, if CRC is enabled.

In transmission, the CRC computation is frozen during the CRC transaction and the TXCRC is transmitted, in a frame of length equal to the CRCSIZE field value.

In reception, the RXCRC is also frozen when the desired number of data is transacted. Information to be compared with the RXCRC register content is then received in a frame of length equal to the CRCSIZE value.

Once the CRC frame is completed, an automatic check is performed comparing the received CRC value and the value calculated in the SPI_RXCRC register. The software has to check the CRCE flag of the SPI_SR register to determine if the data transfers were corrupted or not. Software clears the CRCE flag by writing 1 to the CRCEC.

The user takes no care about any flushing redundant CRC information, it is done automatically.

Resetting the SPI_TXCRC and SPI_RXCRC values

The SPI_TXCRC and SPI_RXCRC values are initialized automatically when new data is sampled after a CRC phase. This allows the use of DMA circular mode to transfer data without any interruption (several data blocks covered by intermediate CRC checking phases). Initialization patterns for receiver and transmitter can be configured either to zero or to all ones in dependency on setting bits TCRCINI and RCRCINI of the SPI_CR1 register.

The CRC values are reset when the SPI is disabled.

80.6 SPI in low-power modes

The SPI supports autonomous operation down to Stop mode, refer to Section 80.4.16: Autonomous mode.

Table 796. Effect of low-power modes on the SPI

ModeDescription
SleepNo effect. SPI interrupts cause the device to exit Sleep mode.
Stop(1)The SPI registers content is kept.
If the autonomous mode is enabled at RCC configuration, and SPI is clocked by an internal oscillator available in Stop mode, transfers are functional. The DMA requests are functional, and the interrupts in this mode cause the device to exit Stop mode.
StandbyThe SPI instance is not functional in this mode. It is powered down, and must be reinitialized after exiting Standby mode.
  1. 1. Refer to Section 80.3: SPI implementation for information about wake-up from Stop mode support per instance as well as Standby mode availability. If an instance is not functional in a Stop mode, it must be disabled before entering this Stop mode.

80.7 SPI interrupts

Table 797 gives an overview of the SPI events capable of generating interrupts if enabled. Some of them feature wake-up from low-power mode capability, additionally. Most of them can be enabled and disabled independently while using specific interrupt enable control bits. The flags associated with the events are cleared by specific methods. Refer to the description of SPI registers for more details about the event flags. When SPI is disabled, all the pending interrupt requests are blocked to prevent their propagation into the interrupt services, except the MODF interrupt request.

Table 797. SPI wake-up and interrupt requests

Interrupt vectorInterrupt eventEvent flagEnable Control bitEvent clear methodExit from Stop and Standby modes capability(1)(2)
SPITxFIFO ready to be loaded (space available for one data packet - FIFO threshold)TXPTXPIETXP cleared by hardware when TxFIFO contains less than FTHLV empty locationsYes
Data received in RxFIFO (one data packet available - FIFO threshold)RXPRXPIERXP cleared by hardware when RxFIFO contains less than FTHLV samplesYes
Both TXP and RXP activeDXPDXPIEWhen TXP or RXP are clearedYes
Transmission Transfer FilledTXTFTXTFIEWriting TXTFC to 1No
UnderrunUDRUDRIEWriting UDRC to 1Yes
OverrunOVROVRIEWriting OVRC to 1Yes
CRC ErrorCRCECRCEIEWriting CRCEC to 1Yes
TI Frame Format ErrorTIFRETIFREIEWriting TIFREC to 1No
Mode FaultMODFMODFIEWriting MODFC to 1No
End Of Transfer (full transfer sequence completed - based on TSIZE value)EOTEOTIEWriting EOTC to 1Yes
Master mode suspendedSUSPWriting SUSPC to 1Yes
TxFIFO transmission complete (TxFIFO empty)TXC(3)TXC cleared by hardware when a transmission activity starts on the busNo
  1. 1. All the interrupt events can wake up the system from Sleep mode at each instance. For detailed information about instances capabilities to exit from concrete Stop and Standby mode refer to the Functionalities depending on the working mode table.
  2. 2. Refer to Section 80.3: SPI implementation for information about Standby mode availability.
  3. 3. The TXC flag behavior depends on the TSIZE setting. When TSIZE>0, the flag fully follows the EOT one including its clearing by EOTC.

80.8 I2S main features

Note: \(F_{MCK}\) is the master clock frequency and \(F_{WS}\) is the audio sampling frequency.

80.9 I2S functional description

80.9.1 I2S general description

The block diagram shown on Figure 953 also applies for I2S mode.

The SPI/I2S block can work in I2S/PCM mode, when the bit I2SMOD is set. A dedicated register (SPI_I2SCFGR) is available for configuring the dedicated I2S parameters, which include the clock generator, and the serial link interface.

The I2S/PCM function uses the clock generator to produce the communication clock when the SPI/I2S is set in master mode. This clock generator is also the source of the master clock output (MCK).

Resources such as RxFIFO, TxFIFO, DMA, and parts of interrupt signaling are shared with the SPI function. The low-power mode function is also available in I2S mode (refer to Section 80.6: SPI in low-power modes and Section 80.10: I2S interrupts).


a. Not always available, refer to Section 80.3: SPI implementation in order to check if 24 and 32-bit data widths are supported.

80.9.2 Pin sharing with SPI function

The I2S shares four common pins with the SPI:

An additional pin can be used when a master clock output is needed for some external audio devices:

80.9.3 Bitfields usable in I2S/PCM mode

When the I2S/PCM mode is selected (I2SMOD = '1'), some bitfields are no longer relevant, and must be forced to a specific value to guarantee the behavior of the I2S/PCM function. Table 798 shows the list of bits and fields available in the I2S/PCM mode, and indicates which must be forced to a specific value.

Table 798. Bitfields usable in PCM/I2S mode

Register nameBitfields usable in PCM/I2S ModeConstraints on other bitfields
SPI/I2S control register 1 (SPI_CR1)IOLOCK, CSUSP, CSTART, SPEOther fields set to their reset values
SPI/I2S control register 2 (SPI_CR2)-Set to reset value
SPI/I2S configuration register 1 (SPI_CFG1)TXDMAEN, RXDMAEN, FTHLVOther fields set to their reset values
SPI/I2S configuration register 2 (SPI_CFG2)AFCNTR, LSBFRST, IOSWPOther fields set to their reset values
SPI/I2S interrupt enable register (SPI_IER)TIFREIE, OVRIE, UDRIE, TXPIE, RXPIE
SPI/I2S status register (SPI_SR)SUSP, TIFRE, OVR, UDR, TXP, RXPOther flags not relevant
SPI/I2S interrupt/status flags clear register (SPI_IFCR)SUSPC, TIFREC, OVRC, UDRCOther fields set to their reset values
SPI/I2S autonomous mode control register (SPI_AUTOCR)The complete register-
SPI/I2S receive data register (SPI_RXDR)The complete register-

Table 798. Bitfields usable in PCM/I2S mode (continued)

Register nameBitfields usable in PCM/I2S ModeConstraints on other bitfields
SPI/I2S polynomial register (SPI_CRCPOLY)-Set to reset value
SPI/I2S transmitter CRC register (SPI_TXCRC)-
SPI/I2S receiver CRC register (SPI_RXCRC)-
SPI/I2S underrun data register (SPI_UDRDR)-
SPI/I2S configuration register (SPI_I2SCFGR)The complete register-

80.9.4 Slave and master modes

The SPI/I2S block supports master and slave modes for both I2S and PCM protocols. In master mode, both CK, WS and MCK signals are set to output.

In slave mode, both CK and WS signals are set to input. The signal MCK cannot be used in slave mode.

To improve the robustness of the SPI/I2S block in slave mode, the peripheral resynchronizes each reception and transmission on WS signal. This means that:

Note: This resynchronization mechanism is not available for the I2S LSB-justified standard.

Note as well that there is no need to provide a kernel clock when the SPI/I2S is configured in slave mode.

80.9.5 Supported audio protocols

The I2S/PCM interface supports four audio standards, configurable using the I2SSTD[1:0] and PCMSYNC bits of the SPI_I2SCFGR register.

In the I2S protocol, the audio data are time-multiplexed on two channels: the left channel and the right channel. The WS signal is used to indicate which channel must be considered as the left, and which one is the right.

In I2S master mode, four frame formats are supported:

In PCM master mode, three frame formats are supported:

The figure hereafter shows the main definition used in this section: data length, channel length and frame length.

Figure 968. Waveform examples

Figure 968: Waveform examples for I2S and PCM modes showing MCK, WS, CK, and SD (In or Out) timing with Data length, Channel length, and Frame length annotations.

MSv40477V3

Figure 968: Waveform examples for I2S and PCM modes showing MCK, WS, CK, and SD (In or Out) timing with Data length, Channel length, and Frame length annotations.

For simplicity sake, in the next figures, SDI represents the serial data input and SDO the serial data output. Refer to Section : Serial data line swapping for details about the direction control of serial data lines.

I2S Philips standard

The I2S Philips standard is selected by setting I2SSTD to 0b00. This standard is supported in master and slave mode.

In this standard, the WS signal toggles one CK clock cycle before the first bit (MSb in I2S Philips standard) is available. A falling edge transition of WS indicates that the next data transferred is the left channel, and a rising edge transition indicates that the next data transferred is the right channel.

a. Not always available, refer to Section 80.3: SPI implementation to check if 24 and 32-bit data widths are supported.

Figure 969. Master I2S Philips protocol waveforms (16/32-bit full accuracy) Figure 969. Master I2S Philips protocol waveforms (16/32-bit full accuracy). Timing diagram showing WS (WSINV = 0), CK (CKPOL = 0), and SDO or SDI (LSBFRST = 0) signals for Left and Right channels (can be 16 or 32 bits), with data stable markers at transitions.
Figure 969. Master I2S Philips protocol waveforms (16/32-bit full accuracy). Timing diagram showing WS (WSINV = 0), CK (CKPOL = 0), and SDO or SDI (LSBFRST = 0) signals for Left and Right channels (can be 16 or 32 bits), with data stable markers at transitions.
  1. 1. Data width of 24 and 32 bits are not always supported (DATLEN = 01 or 10). Refer to Section 80.3: SPI implementation for the supported data sizes.

CKPOL is cleared to match the I2S Philips protocol. See Selection of the CK sampling edge for information concerning the handling of the WS signal.

Figure 969 shows an example of waveform generated by the SPI/I2S in the case where the channel length is equal to the data length. More precisely, this is true when CHLEN = 0 and DATLEN = 0b00 or when CHLEN = 1 and DATLEN = 0b10.

See Control of the WS inversion for information concerning the handling of the WS signal.

Figure 970. I2S Philips standard waveforms Figure 970. I2S Philips standard waveforms. Timing diagram showing WS (I/O) (WSINV = 0), CK (I/O) (CKPOL = 0), SDO, and SDI (LSBFRST = 0) signals with 16 or 24-bit length data followed by remaining bits not significant / not taken into account, across Left and Right channels for 32-bit channel (master) and other length (slave).
Figure 970. I2S Philips standard waveforms. Timing diagram showing WS (I/O) (WSINV = 0), CK (I/O) (CKPOL = 0), SDO, and SDI (LSBFRST = 0) signals with 16 or 24-bit length data followed by remaining bits not significant / not taken into account, across Left and Right channels for 32-bit channel (master) and other length (slave).
  1. 1. Data width of 24 and 32 bits are not always supported (DATLEN = 01 or 10). Refer to Section 80.3: SPI implementation for the supported data sizes.

In the case where the channel length is bigger than the data length, the remaining bits are not significant when the SPI/I2S is configured in transmit mode. This is applicable for both master and slave mode.

MSB-justified standard

For this standard, the WS signal toggles when the first data bit is provided. The data transferred represents the left channel if WS is high and the right channel if WS is low.

Figure 971. Master MSB-justified 16- or 32-bit full-accuracy length

Timing diagram for Figure 971: Master MSB-justified 16- or 32-bit full-accuracy length showing waveforms for WS (O) (WSINV = 0), CK (O) (CKPOL = 0), and SDO or SDI (LSBFRST = 0). It illustrates Left channel (16 or 32 bits) and Right channel (16 or 32 bits). Data stable point marked on the falling edge of WS / rising edge of CK. Labeled MSv40480V2.
Timing diagram for Figure 971: Master MSB-justified 16- or 32-bit full-accuracy length showing waveforms for WS (O) (WSINV = 0), CK (O) (CKPOL = 0), and SDO or SDI (LSBFRST = 0). It illustrates Left channel (16 or 32 bits) and Right channel (16 or 32 bits). Data stable point marked on the falling edge of WS / rising edge of CK. Labeled MSv40480V2.
  1. 1. Data width of 24 and 32 bits are not always supported (DATLEN = 01 or 10). Refer to Section 80.3: SPI implementation to check the supported data size.

CKPOL is cleared to match the I2S MSB-justified protocol. See Selection of the CK sampling edge for information concerning the handling of the WS signal.

See Control of the WS inversion for information concerning the handling of the WS signal.

Figure 972. Master MSB-justified 16- or 24-bit data length

Timing diagram for Figure 972: Master MSB-justified 16- or 24-bit data length showing waveforms for WS (O) (WSINV = 0), CK (O) (CKPOL = 0), SDO (LSBFRST = 0), and SDI (LSBFRST = 0). For 32-bit channel length, data length is 16 or 24-bit length, with remaining bits marked as 'remaining bits not significant' for SDO and 'not taken into account' for SDI. Labeled MSv40479V4.
Timing diagram for Figure 972: Master MSB-justified 16- or 24-bit data length showing waveforms for WS (O) (WSINV = 0), CK (O) (CKPOL = 0), SDO (LSBFRST = 0), and SDI (LSBFRST = 0). For 32-bit channel length, data length is 16 or 24-bit length, with remaining bits marked as 'remaining bits not significant' for SDO and 'not taken into account' for SDI. Labeled MSv40479V4.
  1. 1. Data width of 24 and 32 bits are not always supported (DATLEN = 01 or 10). Refer to Section 80.3: SPI implementation to check the supported data size.

In the case where the channel length is bigger than the data length, the remaining bits are not significant when the SPI/I2S is configured in master transmit mode. In slave transmit mode, the remaining bits are forced to the value of the first bit of the next data to be generated to avoid timing issues (see Figure 973).

Figure 973. Slave MSB-justified 16-, 24- or 32-bit data length

Figure 973. Timing diagram for Slave MSB-justified 16-, 24- or 32-bit data length showing WS (WSINV = 0), CK (CKPOL = 0), (LSBFRST = 0), SDO, and SDI signals across Left channel and Right channel.
Figure 973. Timing diagram for Slave MSB-justified 16-, 24- or 32-bit data length showing WS (WSINV = 0), CK (CKPOL = 0), (LSBFRST = 0), SDO, and SDI signals across Left channel and Right channel.

MSv40478V3

  1. 1. Data width of 24 and 32 bits are not always supported (DATLEN = 01 or 10). Refer to Section 80.3: SPI implementation to check the supported data size.

LSB-justified standard

This standard is similar to the MSB-justified standard in master mode (no difference for the 16- and 32-bit full-accuracy frame formats). The LSB-justified 16- or 32-bit full-accuracy format gives similar waveforms to MSB-justified mode (see Figure 971) because the channel and data have the same length.

Note: In the LSB-justified format, only 16- and 32-bit channel lengths are supported in master and slave mode. This is because it is not possible to transfer properly the data if the channel length is not known by the transmitter and receiver side.

Figure 974. LSB-justified 16 or 24-bit data length

Figure 974. Timing diagram for LSB-justified 16 or 24-bit data length within 32-bit channels, showing WS (WSINV = 0), CK (CKPOL = 0), (LSBFRST = 0), SDO, and SDI signals.
Figure 974. Timing diagram for LSB-justified 16 or 24-bit data length within 32-bit channels, showing WS (WSINV = 0), CK (CKPOL = 0), (LSBFRST = 0), SDO, and SDI signals.

MSv40483V4

  1. 1. Data width of 24 and 32 bits are not always supported (DATLEN = 01 or 10). Refer to Section 80.3: SPI implementation to check the supported data size.

CKPOL is cleared in order to match the I2S LSB-justified protocol. See Selection of the CK sampling edge for information concerning the handling of the WS signal.

See Control of the WS inversion for information concerning the handling of the WS signal.

PCM standard

For the PCM standard, there is no need to use channel-side information. The two PCM modes (short and long frame) are available and can be selected using the PCMSYNC bit of SPI_I2SCFGR register.

In PCM long frame:

In PCM short frame:

For both PCM modes:

Figure 975. Master PCM when the frame length is equal the data length

Timing diagram: Master PCM when the frame length is equal the data length (MSv40484V2)
Timing diagram: Master PCM when the frame length is equal the data length (MSv40484V2)

A data size of 16 or 24 bits can be used when the channel length is set to 32 bits.

Figure 976. Master PCM standard waveforms (16 or 24-bit data length)

Timing diagram: Master PCM standard waveforms (16 or 24-bit data length) (MSv40485V3)
Timing diagram: Master PCM standard waveforms (16 or 24-bit data length) (MSv40485V3)
  1. 1. Data width of 24 and 32 bits are not always supported (DATLEN = 01 or 10). Refer to Section 80.3: SPI implementation to check the supported data size.

If the PCM protocol is used in slave mode, frame lengths can be different from 16 or 32 bits. As shown in Figure 977, in slave mode various pulse widths of WS can be accepted as the start of frame is detected by a rising edge of WS. The only constraint is that the WS must go back to its inactive state for at least one CK cycle.

Figure 977. Slave PCM waveforms

Figure 977: Slave PCM waveforms showing PCM Short and PCM Long timing diagrams with signals WS (I) (WSINV = 0), CK (I) (CKPOL = 0), (LSBFRST = 0) SDO and SDI.

MSv68392V1

Figure 977: Slave PCM waveforms showing PCM Short and PCM Long timing diagrams with signals WS (I) (WSINV = 0), CK (I) (CKPOL = 0), (LSBFRST = 0) SDO and SDI.
  1. 1. Data width of 24 and 32 bits are not always supported (DATLEN = 01 or 10). Refer to Section 80.3: SPI implementation to check the supported data size.

Note: In the case where the channel length is bigger than the data length, in slave PCM long, the transmission of the remaining bits is forced to the value of the first bit of the next data to be generated if the TXFIFO contains the next data to be transmitted.

In slave mode, CHLEN must be always programmed properly (whatever FIXCH value). For example, if CHLEN is cleared (16-bit length), the data transfer is truncated to 16 bits even if DATLEN is different from 0. To avoid this situation, CHLEN must be set, if DATLEN = 1 or 2.

80.9.6 Additional serial interface flexibility

Variable frame length in slave

In slave mode, channel lengths different from 16 or 32 bits can be accepted, as long as the channel length is bigger than the data length. This is true for all protocols except for the I2S LSB-justified protocol.

Data ordering

For all data formats and communication standards, it is possible to select the data ordering (MSb or LSb first) thanks to the bit LSBFRST located into SPI/I2S configuration register 2 (SPI_CFG2).

Selection of the CK sampling edge

The CKPOL bit located into SPI/I2S configuration register (SPI_I2SCFGR) allows the user to choose the sampling edge polarity of the CK for slave and master modes, for all protocols.

Control of the WS inversion

It is possible to invert the default WS signal polarity for master and slave modes, for all protocols, by setting WSINV. By default the WS polarity is the following:

When WSINV is set, the WS polarity is inverted, then:

WSINV is located in the SPI/I2S configuration register (SPI_I2SCFGR).

Control of the I/Os

The SPI/I2S block allows the settling of the WS and CK signals to their inactive state before enabling the SPI/I2S thanks to the AFCNTR bit of SPI/I2S configuration register 2 (SPI_CFG2).

This can be done by programming CKPOL and WSINV using the following sequence:

Assuming that AFCNTR is initially cleared:

Table 799 shows the level of WS and CK signals, when the AFCNTR bit is set, and before the SPI/I2S block is enabled (that is inactive level). Note that the level of WS also depends on the protocol selected.

Table 799. WS and CK level before SPI/I2S is enabled when AFCNTR = 1

WSINVI2SSTDWS level before SPI/I2S is enabledCKPOLCK level before SPI/I2S is enabled
0I2S Std (00)→High0→Low
Others→Low→High
1I2S Std (00)→Low1→Low
Others→High→High

Note: The bit AFCNTR must not be set when the SPI2S is in slave mode.

Serial data line swapping

The direction of SDI and SDO depends on the IOSWP bit of SPI/I2S configuration register 2 (SPI_CFG2), and on the slave/master mode. Table 800 gives details on this feature.

Table 800. Serial data line swapping

DirectionIOSWPMaster modeSlave mode
Input lineOutput lineInput lineOutput line
RX0SDI-SDO-
1SDO-SDI-
TX0-SDO-SDI
1-SDI-SDO
Full-duplex0SDISDOSDOSDI
1SDOSDISDISDO

80.9.7 Startup sequence

When the bit SPE is cleared, the user is not allowed to read and write from/to the SPI_RXDR and SPI_TXDR registers, but the access to other registers is allowed.

When the application wants to use the SPI/I2S block the user has to proceed as follows:

  1. 1. Ensure that the SPE is cleared, otherwise write SPE to 0.
  2. 2. Program all the configuration and control registers according to the wanted configuration. Refer to Section 80.9.17 for detailed programming examples.
  3. 3. Clear all the status flags by setting the USPC, TIFREC, OVRC, and UDRC bits of the SPI_IFCR register. Note that if the flag SUSP is not cleared (via the SUSPC bit) the CSTART control bit has no effect.
  4. 4. Set the SPE bit to activate the SPI/I2S block. When this bit is set, the serial interface is still disabled, but the DMA and interrupt services are working, allowing for example, the data transfer into the TxFIFO. The generation of MCK can also be started when SPE goes to 1.
  5. 5. Set bit CSTART to activate the serial interface.

As shown in Figure 978, in I2S Philips standard master TX, the generation of the WS and CK signals starts after a resynchronization delay (SYNC_DLY2) when CSTART goes to 1

and the TxFIFO is not empty. Note that the CK bit clock is activated four rising edges before the falling edge of WS in order to ensure that the external slave device can detect properly WS transition. Other standards behave similarly.

Figure 978. Startup sequence, I2S Philips standard, master

Timing diagram for I2S Philips standard, master mode. It shows the relationship between AFCNTR, MCK(O), WS(O), CK(O), SDO, CSTART, and SPE signals. The diagram is divided into three phases: SPI2S configuration, Data transfer to the TX_FIFO, and Enabling of the serial interface. Key delays shown are SYNC_DLY1 and SYNC_DLY2. The SDO signal shows data bits (MSb to LSb) being shifted out. A dashed line indicates the signal interfaces when AFCNTR is 0.

Figure 978 is a timing diagram illustrating the startup sequence for the I2S Philips standard in master mode. The diagram shows the following signals and their transitions:

The diagram is divided into three phases:

A dashed line represents the signal interfaces in the case where AFCNTR is kept to 0.

Timing diagram for I2S Philips standard, master mode. It shows the relationship between AFCNTR, MCK(O), WS(O), CK(O), SDO, CSTART, and SPE signals. The diagram is divided into three phases: SPI2S configuration, Data transfer to the TX_FIFO, and Enabling of the serial interface. Key delays shown are SYNC_DLY1 and SYNC_DLY2. The SDO signal shows data bits (MSb to LSb) being shifted out. A dashed line indicates the signal interfaces when AFCNTR is 0.
  1. 1. As shown in the figure, MCK can be enabled as soon as the bit SPE is set. It is generated after a synchronization delay (SYNC_DLY1). See MCK generation in Section 80.9.9: Clock generator for more information.
  2. 2. Note that the level of WS and CK signals are controlled by the SPI/I2S block during the configuration phase as soon as the AFCNTR bit is set.

Note: Due to clock domain resynchronization, the CSTART bit is taken into account by the hardware after about three periods of CK clock (SYNC_DLY2).

In slave mode, once the bit CSTART is set, the data transfer starts when the start-of-frame condition is met:

Figure 979 shows an example of startup sequence in I2S Philips standard, slave mode.

Figure 979. Startup sequence, I2S Philips standard, slave

Timing diagram for I2S Philips standard slave startup sequence. It shows signals WS(I) (WSINV = 0), CK (I), SDO, SDI, CSTART, SPE, and SYNC_DLY. A shaded region indicates 'Searching for the start of frame'. Data blocks L0_IN, R0_IN, L1_IN, R1_IN, L2_IN are shown on SDI, and L1_OUT, R1_OUT, L2_OUT on SDO. A note indicates that L0_IN and R0_IN are 'Not stored into the RX-FIFO'. Another note states 'Start-of-frame condition found, the reception and transmission of data can start.' The diagram is labeled MSv40487V1.
Timing diagram for I2S Philips standard slave startup sequence. It shows signals WS(I) (WSINV = 0), CK (I), SDO, SDI, CSTART, SPE, and SYNC_DLY. A shaded region indicates 'Searching for the start of frame'. Data blocks L0_IN, R0_IN, L1_IN, R1_IN, L2_IN are shown on SDI, and L1_OUT, R1_OUT, L2_OUT on SDO. A note indicates that L0_IN and R0_IN are 'Not stored into the RX-FIFO'. Another note states 'Start-of-frame condition found, the reception and transmission of data can start.' The diagram is labeled MSv40487V1.

Note: Due to clock domain resynchronization, the CSTART bit is taken into account by the hardware after two periods of CK clock (SYNC_DLY).

80.9.8 Stop sequence

The application can stop the I2S/PCM transfers by clearing the SPE bit. In that case the communication is stopped immediately, without waiting for the end of the current frame.

In master mode it is also possible to stop the I2S/PCM transfers at the end of the current frame. For that purpose, the user has to set the bit CSUSP, and polls the CSTART bit until it goes to 0. The CSTART bit goes to 0 when the current stereo (if an I2S mode was selected) or mono sample are completely shifted in or out. Then the SPE bit can be cleared.

Figure 980 shows an example of stop sequence in the case of master mode. The CSUSP bit is set during the transmission of the left sample, the transfer continue until the last bit of the right sample is transferred. Then CSTART and CSUSP go back to 0, CK and WS signals go back to their inactive state, and the user can clear the SPE bit.

Figure 980. Stop sequence, I2S Philips standard, master

Timing diagram for I2S Philips standard master stop sequence. It shows signals WS(O) (WSINV = 0), CK(O) (CKPOL = 0), SDO (LSBFRST = 0), CSUSP, CSTART, and SPE. Data blocks are shown on SDO with MSb and LSb labels. The diagram shows the transition from left (L) to right (R) sample transmission. CSUSP is set during the left sample transmission. After the right sample is fully transferred, CSUSP and CSTART return to 0, and WS and CK return to inactive states. The diagram is labeled MSv40489V3.
Timing diagram for I2S Philips standard master stop sequence. It shows signals WS(O) (WSINV = 0), CK(O) (CKPOL = 0), SDO (LSBFRST = 0), CSUSP, CSTART, and SPE. Data blocks are shown on SDO with MSb and LSb labels. The diagram shows the transition from left (L) to right (R) sample transmission. CSUSP is set during the left sample transmission. After the right sample is fully transferred, CSUSP and CSTART return to 0, and WS and CK return to inactive states. The diagram is labeled MSv40489V3.

Note: In slave mode, the stop sequence is only controlled by the SPE bit.

80.9.9 Clock generator

When the I2S or PCM is configured in master mode, the user needs to program the clock generator in order to produce the frame synchronization (WS), the bit clock (CK) and the master clock (MCK) at the desired frequency.

If the I2S or PCM is used in slave mode, there is no need to configure the clock generator.

Figure 981. I2S clock generator architecture

Block diagram of the I2S clock generator architecture (CLKGEN). The diagram shows the internal structure of the CLKGEN block. Inputs include spi_ker_ck, I2SDIV[7:0], ODD, I2SMOD, CHLEN, and MCKOE. Inside the block, spi_ker_ck goes to an 8-bit linear divider + reshaping stage. The output of this stage goes to a ÷4 divider, then a ÷2 divider, and finally a multiplexer (MUX) with inputs 0 and 1. The output of the MUX is CK. The output of the ÷4 divider goes to an AND gate along with MCKOE. The output of the AND gate is MCK. The output of the ÷2 divider also goes to the MUX. The MUX is controlled by CHLEN and MCKOE. The diagram is labeled MSv68394V1.
Block diagram of the I2S clock generator architecture (CLKGEN). The diagram shows the internal structure of the CLKGEN block. Inputs include spi_ker_ck, I2SDIV[7:0], ODD, I2SMOD, CHLEN, and MCKOE. Inside the block, spi_ker_ck goes to an 8-bit linear divider + reshaping stage. The output of this stage goes to a ÷4 divider, then a ÷2 divider, and finally a multiplexer (MUX) with inputs 0 and 1. The output of the MUX is CK. The output of the ÷4 divider goes to an AND gate along with MCKOE. The output of the AND gate is MCK. The output of the ÷2 divider also goes to the MUX. The MUX is controlled by CHLEN and MCKOE. The diagram is labeled MSv68394V1.

The frequency generated on MCK, CK and WS depends mainly on I2SDIV, ODD, CHLEN, and MCKOE. The bit MCKOE indicates if a master clock need to be generated or not. The master clock has a frequency 256 or 128 times higher than the frame synchronization. This master clock is often required to provide a reference clock to external audio codecs.

Note: In master mode, there are no specific constraints on the ratio between the bus clock rate (\(F_{pclk}\)) and the bit clock (\(F_{CK}\)). The bus clock frequency must be high enough in order to support the data throughput.

When the master clock is generated (MCKOE = 1), the frequency of the frame synchronization is given by the following formula in I2S mode:

\[F_{WS} = \frac{F_{i2s\_clk}}{256 \times \{(2 \times I2SDIV) + ODD\}}\]

And by this formula in PCM mode:

\[F_{WS} = \frac{F_{i2s\_clk}}{128 \times \{(2 \times I2SDIV) + ODD\}}\]

In addition, the frequency of the MCK (\(F_{MCK}\)) is given by the formula:

\[F_{MCK} = \frac{F_{i2s\_clk}}{\{(2 \times I2SDIV) + ODD\}}\]

When the master clock is disabled (MCKOE = 0), the frequency of the frame synchronization is given by the following formula in I2S mode:

\[F_{WS} = \frac{F_{i2s\_clk}}{32 \times (CHLEN + 1) \times \{(2 \times I2SDIV) + ODD\}}\]

And by this formula in PCM mode:

\[F_{WS} = \frac{F_{i2s\_clk}}{16 \times (CHLEN + 1) \times \{(2 \times I2SDIV) + ODD\}}\]

Where \(F_{WS}\) is the frequency of the frame synchronization, and \(F_{i2s\_clk}\) is the frequency of the kernel clock provided to the SPI/I2S block.

Note: CHLEN and ODD can be either 0 or 1.

I2SDIV can take any values from 0 to 255 when ODD = 0, but when ODD = 1, the value I2SDIV = 1 is not allowed.

When I2SDIV = 0, then {(2 × I2SDIV)+ODD} is forced to 1.

Note: When {(2 × I2SDIV)+ODD} is odd, the duty cycle of the MCK or the CK signal is not 50%. Care must be taken when an odd ratio is used: it can impact margin on setup and hold time. For example if {(2 × I2SDIV)+ODD} = 5, then the duty cycle can be 40%.

Table 801 provides examples of clock generator programming for I2S modes.

MCK generation

The master clock MCK is generated when the following conditions are met:

Table 801. CLKGEN programming examples for usual I2S frequencies

i2s_clk (MHz)Channel length (bits)I2SDIVODDMCKSampling rate: \(F_{WS}\) (kHz)
12.28816120No16
12.288326016
12.288166032
12.288323032
49.1521616048
49.152328048
49.152168096
49.152324096
49.1521640192
49.1523220192

Table 801. CLKGEN programming examples for usual I2S frequencies (continued)

i2s_clk (MHz)Channel length (bits)I2SDIVODDMCKSampling rate: FWS (kHz)
4.09616 or 320-Yes16
24.57616 or 323032
49.15216 or 323048
12.28816 or 320-96
49.15216 or 3220192
61.4416 or 3221
98.30416 or 3220
196.60816 or 3220

80.9.10 Internal FIFOs

The I2S interface can use a dedicated FIFO for the RX and the TX path. The samples to transmit can be written into the Tx FIFO via the SPI_TXDR register. The reading of Rx FIFO is performed via the SPI_RXDR register.

Data alignment and ordering

It is possible to select the data alignment into the SPI_RXDR and SPI_TXDR registers thanks to the DATFMT bit.

Note as well that the format of the data located into the SPI_RXDR or SPI_TXDR depends as well on the way those registers are accessed via the APB bus.

Figure 982 shows the allowed settings between APB access sizes, DATFMT, and DATLEN.

Note: Caution must be taken when the APB access size is 32 bits, and DATLEN = 0. For read operation the Rx FIFO must contain at least two data, otherwise the read data are invalid. In the same way, for write operation, the Tx FIFO must have at least two empty locations, otherwise a data can be lost.

Figure 982. Data Format

APB Access SizeDATLENSPI_RXDR, SPI_TXDR (DATFMT = 0)SPI_RXDR, SPI_TXDR (DATFMT = 1)
16 bits0b00 (16 bits)
15 0
valid sample
15 0
valid sample
32 bits0b00 (16 bits)
31 16 15 0
valid sample N+1 | valid sample N
31 16 15 0
valid sample N+1 | valid sample N
32 bits0b01 (24 bits)
31 24 23 0
zeros | valid sample
31 8 7 0
valid sample | zeros
32 bits0b10 (32 bits)
31 0
valid sample
31 0
valid sample

MSv40491V1

  1. 1. In I2S mode, the sample N represents the left sample, and the sample N+1 is the right sample.
  2. 2. Data width of 24 and 32 bits are not always supported (DATLEN = 01 or 10). Refer to Section 80.3: SPI implementation to check the supported data size.

It is possible to generate an interrupt or a DMA request according to a programmable FIFO threshold levels. The FIFO threshold is common to RX and TxFIFOs can be adjusted via FTHLV.

In I2S mode, the left and right audio samples are interleaved into the FIFOs. It means that for transmit operations, the user has to start to fill-up the TxFIFO with a left sample, followed by a right sample, and so on. For receive mode, the first data read from the RxFIFO is supposed to represent a left channel, the next one is a right channel, and so on.

Note that the read and write pointers of the FIFOs are reset when the bit SPE is cleared.

Refer to Section 80.9.11 and Section 80.9.15 for additional information.

FIFO size optimization

The basic element of the FIFO is the byte. This allows an optimization of the FIFO locations. For example when the data size is fixed to 24 bits, each audio sample takes three basic FIFO elements.

For example, a FIFO with 16 basic elements can have a depth of:

80.9.11 FIFO status flags

Two status flags are provided for the application to fully monitor the state of the I2S interface. Both flags can generate an interrupt request. The receive interrupt is generated if RXPIE bit is enabled, the transmit interrupt is generated if TXPIE bit is enabled. Those bits are located into the SPI_IER register.

TxFIFO threshold reached (TXP)

When set, this flag indicates that the TxFIFO contains at least FTHLV empty locations. Thus, FTHLV new data to be transmitted can be written to SPI_TXDR. The TXP flag is reset when the number of empty locations is lower than FTHLV. Note that TXP = 1, when the I2S is disabled (SPE bit is reset).

RxFIFO threshold reached (RXF)

When set, this flag indicates that there is at least FTHLV valid data into the RxFIFO, thus the user can read those data via SPI_RXDR. It is reset when the RxFIFO contains less than FTHLV data.

See Section 80.10 for additional information on the interrupt function in I2S mode.

80.9.12 Handling of underrun situation

In transmit mode, an underrun situation is detected when a new data needs to be loaded into the shift register while the TxFIFO is already empty. In such a situation the UDR flag is set, and at least one audio frame contains unexpected data.


a. Not always available, refer to Section 80.3: SPI implementation in order to check if 24 and 32-bit data widths are supported.

For I2S modes, there is a hardware mechanism to prevent misalignment situations (left and right channel swapped). When an underrun situation is detected, the last valid data present in the shift register is repeated if the real channel length matches the length selected by the CHLEN bit. In the other cases, an undefined data is repeated. Typically, if the block is programmed in slave TX mode, and the external master audio device is using channel lengths other than 16 or 32 bits, the repeated data value is undefined in case of underrun.

The following figure shows the case where an underrun occurs and the peripheral replays the last valid data on left and right channels as long as conditions of restart are not met. The transmission restarts:

Figure 983. Handling of underrun situation

Figure 983: Handling of underrun situation. Timing diagram showing TX-FIFO fill levels, WS, SD(o), CK, and UDR flag over frames N through N+4, highlighting underrun detection, last valid data repeated (L4), software acknowledgment, and restart on right channel (R4).
Figure 983: Handling of underrun situation. Timing diagram showing TX-FIFO fill levels, WS, SD(o), CK, and UDR flag over frames N through N+4, highlighting underrun detection, last valid data repeated (L4), software acknowledgment, and restart on right channel (R4).

When the block is configured in one of the PCM modes, the transmission restarts at the start of the next frame, when there is enough data in the TxFIFO, and the UDR flag is cleared.

The UDR flag can trigger an interrupt if the UDRIE bit of the SPI_IER register is set. The UDR bit is cleared by setting the UDRC bit of the SPI_IFCR register.

Note: An underrun situation can occur in master or slave mode. In master mode, when an underrun occurs, the WS, CK, and MCK signals are not gated.

Due to resynchronization, any change of the UDR flag is taken into account by the hardware after at least two periods of CK clock.

80.9.13 Handling of overrun situation

In receive mode, an overrun situation is detected when the shift register needs to store a new data into the RxFIFO, while the RxFIFO is full. In such a situation the OVR flag is set, and the incoming data is lost.

In I2S mode, there is a hardware mechanism in to prevent misalignment situations (left and right channel swapped). As shown in the following figure, when an overrun occurs, the peripheral stops writing data into the RxFIFO as long as restart conditions are not met.

The reception restarts when there is enough room into the RxFIFO, and the OVR flag is cleared. The block starts by writing next the right channel into the RxFIFO if the overrun occurs when a right channel data is received or by writing the next left channel if the overrun occurs when a left channel data is received.

Figure 984. Handling of overrun situation

Timing diagram showing RX-FIFO, WS, SD(i), CK, and OVR flag over frames N to N+4. It illustrates an overrun event where the RX-FIFO is full, causing data loss (L4) and subsequent re-start logic.

The diagram illustrates the handling of an overrun situation in I2S mode. It shows the following signals over five frames (N, N+1, N+2, N+3, N+4):

Annotations in the diagram include:

Timing diagram showing RX-FIFO, WS, SD(i), CK, and OVR flag over frames N to N+4. It illustrates an overrun event where the RX-FIFO is full, causing data loss (L4) and subsequent re-start logic.

When the block is configured in PCM mode, after an overrun error, the block stops writing data in the RxFIFO as long as conditions of restart are not met. When there is enough room in the RxFIFO, and the OVR flag is cleared, the next received data are written in the RxFIFO.

An interrupt can be generated if the OVRIE bit of the SPI_IER register is set. The OVR bit is cleared by setting the OVRC bit of the SPI_IFCR register.

Note: An overrun situation can occur in master or slave mode. In master mode when an overrun occurs, the WS, CK, and MCK signals are not gated.

80.9.14 Frame error detection

When configured in slave mode, the SPI/I2S block detects two kinds of frame errors:

In slave mode, if the frame length provided by the external master device is different from 32 or 64 bits, the user has to clear FIXCH. As the SPI/I2S synchronize each transfer with the WS there is no misalignment risk, but in a noisy environment, if a glitch occurs in the CK signal, a sample may be affected and the application is not aware of this.

If the frame length provided by the external master device is equal to 32 or 64 bits, then the user can set FIXCH and adjust accordingly CHLEN. As the SPI/I2S synchronize each transfer with the WS there is still no misalignment risk, and if the amount of bit clock between each channel boundary is different from CHLEN, the frame error flag (TIFRE) is set.

Figure 985 shows an example of frame error detection. The SPI/I2S block is in slave mode and the number of bit clock periods for the left channel are not enough to shift-in or shift-out the data. The figure shows that the ongoing transfer is interrupted and the next one is started in order to remain aligned to the WS signal.

Figure 985. Frame error detection, with FIXCH = 0

Timing diagram for Figure 985 showing frame error detection with FIXCH = 0. It displays WS (I), CK (I), SD (I/O), and TIFRE flag signals. The WS signal is a square wave. CK is a clock signal. SD shows data being shifted in (L15 to L0) and out (R0 to R15). A frame error occurs when the left channel is not completely shifted in or out while it is requested to shift-in or out the right channel. The TIFRE flag is set to indicate the error and is acknowledged by SW.

The diagram illustrates a frame error in slave mode with FIXCH = 0. The WS (I) signal is a square wave. The CK (I) signal is a clock. The SD (I/O) signal shows data being shifted in (L15 to L0) and out (R0 to R15). A frame error occurs when the left channel is not completely shifted in or out while it is requested to shift-in or out the right channel. The TIFRE flag is set to indicate the error and is acknowledged by SW.

Timing diagram for Figure 985 showing frame error detection with FIXCH = 0. It displays WS (I), CK (I), SD (I/O), and TIFRE flag signals. The WS signal is a square wave. CK is a clock signal. SD shows data being shifted in (L15 to L0) and out (R0 to R15). A frame error occurs when the left channel is not completely shifted in or out while it is requested to shift-in or out the right channel. The TIFRE flag is set to indicate the error and is acknowledged by SW.

An interrupt can be generated if the TIFREIE bit is set. The frame error flag (TIFRE) is cleared by writing the TIFREC bit of the SPI_IFCR register to 1.

It is possible to extend the coverage of the frame error flag by setting the bit FIXCH. When this bit is set, then the SPI/I2S is expecting fixed channel lengths in slave mode. This means that the expected channel length can be 16 or 32 bits, according to CHLEN. As shown in Figure 986, in this mode, the SPI/I2S block is able to detect if the WS signal is changing at the expected moment (too early or too late).

Note: Figure 985 and Figure 986 show the mechanism for the slave transmit mode, but this is also true for slave receive and slave full-duplex.

Figure 986. Frame error detection, with FIXCH = 1

Timing diagram for Figure 986 showing frame error detection with FIXCH = 1. It displays WS (I), CK (I), SD (O), and TIFRE flag signals. The WS signal is a square wave. CK is a clock signal. SD shows data being shifted out (R0 to R15). A frame error occurs when the WS signal is changing after 31 clock periods instead of 32, or after 33 clock periods instead of 32. The TIFRE flag is set to indicate the error and is acknowledged by SW.

The diagram illustrates frame error detection in slave mode with FIXCH = 1. The WS (I) signal is a square wave. The CK (I) signal is a clock. The SD (O) signal shows data being shifted out (R0 to R15). A frame error occurs when the WS signal is changing after 31 clock periods instead of 32, or after 33 clock periods instead of 32. The TIFRE flag is set to indicate the error and is acknowledged by SW.

Timing diagram for Figure 986 showing frame error detection with FIXCH = 1. It displays WS (I), CK (I), SD (O), and TIFRE flag signals. The WS signal is a square wave. CK is a clock signal. SD shows data being shifted out (R0 to R15). A frame error occurs when the WS signal is changing after 31 clock periods instead of 32, or after 33 clock periods instead of 32. The TIFRE flag is set to indicate the error and is acknowledged by SW.

The frame error detection can be generally due to noisy environment disturbing the good reception of WS or CK signals.

Note: The SPI/I2S is not able to recover properly if an overrun and an early frame occur within the same frame. In this case the user has to disable and re-enable the SPI/I2S.

80.9.15 DMA interface

The I2S/PCM mode shares the same DMA requests lines than the SPI function. There is a separated DMA channel for TX and RX paths. Each DMA channel can be enabled via RXDMAEN and TXDMAEN bits of the SPI_CFG1 register.

In receive mode, the DMA interface is working as follows:

  1. 1. The hardware evaluates the RxFIFO level,
  2. 2. If the RxFIFO contains at least FTHLV samples, then FTHLV DMA requests are generated,
    • – When the FTHLV DMA requests are completed, the hardware loops to step 1
  3. 3. If the RxFIFO contains less than FTHLV samples, no DMA request is generated, and the hardware loop to step 1

In transmit mode, the DMA interface is working as follows:

  1. 1. The hardware evaluates the TxFIFO level,
  2. 2. If the TxFIFO contains at least FTHLV empty locations, then FTHLV DMA requests are generated,
    • – When the FTHLV DMA requests are completed, the hardware loops to step 1
  3. 3. If the TxFIFO contains less than FTHLV empty locations, no DMA request is generated, and the hardware loop to step 1

80.9.16 Autonomous mode

The I2S can request the kernel clock to the reset and clock controller (RCC), when a transfer is ongoing. So, even in Stop mode, it is possible to transfer samples from the TxFIFO to the serial interface, or from the serial interface to the RxFIFO. This mechanism only works when supported by the RCC and when an oscillator is selected as kernel clock.

When the APB clock is requested by the I2S, for example to transfer the samples from the memory to the TxFIFO or from the RxFIFO to the memory, a wake-up event is asserted. When the system is in Run, the APB clock is present, then the I2S asserts the interrupt line.

80.9.17 Programing examples

Master I2S Philips standard, full-duplex

This example shows how to program the interface for supporting the I2S Philips standard protocol in master full-duplex mode, with a sampling rate of 48 kHz, using the master clock. The assumption has been taken that the SPI/I2S is receiving a kernel clock (i2s_clk) of 61.44 MHz from the clock controller of the circuit. In the example above we took the assumption that the external audio codec needs to be programmed, for example via an I2C interface before starting the transfer. In addition, it is supposed that this external audio codec needs the MCK to accept I2C commands.

Procedure

  1. 1. Via the RCC block, enable the bus interface and the kernel clocks, assert and release the reset signal if needed.
  2. 2. Program the AFMUX in order to select the wanted I/Os. In the current example MCK, CK, WS, SDO, SDI are needed.
  3. 3. Program the clock generator to provide the MCK clock, and to have a frame synchronization rate at exactly 48 kHz. Set I2SDIV to 2, ODD to 1, and MCKOE to 1.
  4. 4. Program the serial interface protocol: CKPOL = 0, WSINV = 0, LSBFRST = 0, CHLEN = 1 (32 bits per channel) DATLEN = 1 (24 bits), I2SSTD = 0 (I2S Philips standard), I2SCFG = 5 (master full-duplex), I2SMOD = 1, for I2S/PCM mode.
  5. 5. Adjust the FIFO threshold by setting the wanted value into FTHLV. For example, if a threshold of two audio samples is required, FTHLV = 1.
  6. 6. If the application wishes to perform data transfer via DMA, set the bits TXDMAEN and RXDMAEN.
  7. 7. Clear all interrupt enable fields located in the SPI_IER register.
  8. 8. Clear all status flags, by setting SUSPC, TIFREC, OVRC, UDRC of the SPI_IFCR register.
  9. 9. Set the SPE bit, then the MCK is generated. In the example presented here, the TxFIFO is not filled-up as soon as SPE = 1. The application can then configure the external audio codec via an I2C interface even if audio samples to transmit are not yet available. An Alternative sequence is proposed hereafter.
  10. 10. When the application wants to start the data transfer:
    • – If the data transfer uses DMA:
      1. a) Program the DMA peripheral: two channels, one for RX and one for TX.
      2. b) Initialize the memory buffer with valid audio samples for TX path.
      3. c) Enable the DMA channels.
      4. d) Enable interrupt events such as UDRIE and OVRIE if needed in order to detect transfer errors.
      5. e) Enable the DMA channel. If TXDMAEN was set, the TxFIFO is filled up.
    • – If the data transfer is done via interrupt:

      Enable the interrupt events UDRIE, OVRIE, TXPIE, and RXPIE (by writing 1). An interrupt request is immediately activated allowing the interrupt handler to fill-up the TxFIFO.

  11. 11. Finally, the SPI/I2S serial interface can be enabled by setting the bit CSTART. CSTART bit is located into the SPI_CR1 register.

Alternative sequence

Stop procedure in master mode

  1. 1. Set the bit CSUSP, in order to stop ongoing transfers
  2. 2. Check the value of the CSTART bit until it goes to 0
  3. 3. Clear the SUSP flag by setting SUSPC
  4. 4. Stop DMA peripheral, bus clock...
  5. 5. Clear bit SPE in order to disable the SPI/I2S block

Slave I2S Philips standard, receive

This example shows how to program the interface for supporting the I2S Philips standard protocol in slave receiver mode, with a sampling rate of 48 kHz. Note that in slave mode the SPI/I2S block cannot control the sample rate of the received samples. In this example we took the assumption that the external master device is delivering an I2S frame structure with a channel length of 24 bits. So, we cannot use the capability offered for frame error detection when FIXCH is set.

Procedure

  1. 1. Via the RCC block, enable the bus interface and the kernel clocks, assert and release the reset signal if needed,
  2. 2. Program the AFMUX in order to select the wanted I/Os. In the current example CK, WS, SDI,
  3. 3. Program the serial interface protocol: CKPOL = 0, WSINV = 0, LSBFRST = 0, FIXCH = 0 (because channel length is different from 16 and 32 bits), DATLEN = 0 (16 bits), I2SSTD = 0 (Philips protocol), I2SCFG = 1 (slave RX), I2SMOD = 1, for I2S mode.
  4. 4. Adjust the FIFO threshold by setting the wanted value into FTHLV. For example if a threshold of two audio samples is required, FTHLV = 1.
  5. 5. Clear all status flag registers.
  6. 6. Enable the flags that generate an interrupt such as OVRIE and TIFRE.
  7. 7. If the data transfer uses DMA:
    • – Program the DMA peripheral: one RX channel
    • – Enable the DMA channel,
    • – In the SPI/I2S block, enable the DMA by setting the RXDMAEN bit.
  1. 8. If the data transfer is done via interrupt, then the user has to enable the interrupt by setting the RXPIE bit.
  2. 9. Set SPE.
  3. 10. Finally, the user can set the bit CSTART in order to enable the serial interface. The SPI/I2S starts to store data into the RxFIFO on the next occurrence of left data transmitted by the external master device.

Stop procedure in slave mode

  1. 1. Clear bit SPE in order to disable the SPI/I2S block
  2. 2. Stop DMA peripheral, bus clock...

80.10 I2S interrupts

In PCM/I2S mode an interrupt (spi_it) or a wake-up event signal (spi_wkup) can be generated according to the events described in the Table 802.

Interrupt events can be enabled and disabled separately.

Table 802. I2S interrupt requests

Interrupt vectorInterrupt eventEvent flagEvent/Interrupt clearing methodExit Sleep modeExit Stop modesExit Standby mode
SPITxFIFO threshold reachedTXPWhen the TxFIFO contains less than FTHLV empty locationsYesYesNo
RxFIFO threshold reachedRXPWhen the RxFIFO contains less than FTHLV samples
Overrun errorOVRWrite OVRC to 1
Underrun errorUDRWrite UDRC to 1
Frame error flagTIFREWrite TIFREC to 1No

80.11 SPI/I2S registers

80.11.1 SPI/I2S control register 1 (SPI_CR1)

Address offset: 0x000

Reset value: 0x0000 0000

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.IOLOCK
rs
1514131211109876543210
TCRCINIRCRCINICRC33_17SSIHDDIRCSUSPCSTARTMASRXRes.Res.Res.Res.Res.Res.Res.SPE
rwrwrwrwrwwrsrwrw

Bits 31:17 Reserved, must be kept at reset value.

Bit 16 IOLOCK: locking the AF configuration of associated I/Os

This bit can be changed by software only when SPI is disabled (SPE = 0). It is cleared by hardware if a MODF event occurs

When this bit is set, the SPI_CFG2 register content cannot be modified. This bit is write-protected when SPI is enabled (SPE = 1).

0: AF configuration is not locked

1: AF configuration is locked

Bit 15 TCRCINI: CRC calculation initialization pattern control for transmitter

0: all zero pattern is applied

1: all ones pattern is applied

Bit 14 RCRCINI: CRC calculation initialization pattern control for receiver

0: All zero pattern is applied

1: All ones pattern is applied

Bit 13 CRC33_17: Full size (33-bit or 17-bit) CRC polynomial configuration

0: Full size (33-bit or 17-bit) CRC polynomial is not used

1: Full size (33-bit or 17-bit) CRC polynomial is used

Bit 12 SSI: internal SS signal input level

This bit has an effect only when the SSM bit is set. The value of this bit is forced onto the peripheral SS input internally and the I/O value of the SS pin is ignored.

Bit 11 HDDIR: Rx/Tx direction at half-duplex mode

In half-duplex configuration the HDDIR bit establishes the Rx/Tx direction of the data transfer.

This bit is ignored in Full-Duplex or any Simplex configuration.

0: SPI is receiver

1: SPI is transmitter

Bit 10 CSUSP: master suspend request

This bit reads as zero.

In master mode, when this bit is set by software, the CSTART bit is reset at the end of the current frame and communication is suspended. The user has to check SUSP flag to check end of the frame transaction.

The master mode communication must be suspended (using this bit or keeping TXDR empty) before going to Low-power mode.

After software suspension, SUSP flag must be cleared and SPI disabled and re-enabled before the next transaction starts.

Bit 9 CSTART: master transfer start

This bit can be set by software if SPI is enabled only to start an SPI or I2S/PCM

communication. In SPI mode, it is cleared by hardware when end of transfer (EOT) flag is set or when a transaction suspend request is accepted. In I2S/PCM mode, it is also cleared by hardware as described in the Section 80.9.8: Stop sequence.

In SPI mode, the bit is taken into account at master mode only. If transmission is enabled, communication starts or continues only if any data is available in the transmission FIFO.

0: master transfer is at idle

1: master transfer is ongoing or temporary suspended by automatic suspend

Bit 8 MASRX: master automatic suspension in Receive mode

This bit is set and cleared by software to control continuous SPI transfer in master receiver mode and automatic management in order to avoid overrun condition.

When SPI communication is suspended by hardware automatically, it may happen that few bits of next frame are already clocked out due to internal synchronization delay.

This is why, the automatic suspension is not quite reliable when size of data drops below 8 bits. In this case, a safe suspension can be achieved by combination with delay inserted between data frames applied when MIDI parameter keeps a non zero value; sum of data size and the interleaved SPI cycles must always produce interval at length of 8 SPI clock periods at minimum. After software clearing of the SUSP bit, the communication resumes and continues by subsequent bits transaction without any next constraint. Before the SUSP bit is cleared, the user must release the RxFIFO space as much as possible by reading out all the data packets available at RxFIFO based on the RXP flag indication to prevent any subsequent suspension.

0: SPI flow/clock generation is continuous, regardless of overrun condition. (data are lost)

1: SPI flow is suspended temporary on RxFIFO full condition, before reaching overrun condition. The SUSP flag is set when the SPI communication is suspended.

Bits 7:1 Reserved, must be kept at reset value.

Bit 0 SPE: serial peripheral enable

This bit is set by and cleared by software.

When SPE = 1, SPI data transfer is enabled, the SPI_CFG1 and SPI_CFG2 configuration registers, CRCPOLY, UDRDR, part of the SPI_AUTOCR register and IOLOCK bit in the SPI_CR1 register are write protected. They can be changed only when SPE = 0.

When SPE = 0 any SPI operation is stopped and disabled, all the pending requests of the events with enabled interrupt are blocked except the MODF interrupt request (but their pending still propagates the request of the spi_plck clock), the SS output is deactivated at master, the RDY signal keeps not ready status at slave, the internal state machine is reseted, all the FIFOs content is flushed, CRC calculation initialized, receive data register is read zero. SPE is cleared and cannot be set when MODF error flag is active.

0: Serial peripheral disabled.

1: Serial peripheral enabled

80.11.2 SPI/I2S control register 2 (SPI_CR2)

Address offset: 0x004

Reset value: 0x0000 0000

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
1514131211109876543210
TSIZE[15:0]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw

Bits 31:16 Reserved, must be kept at reset value.

Bits 15:0 TSIZE[15:0]: number of data at current transfer

When these bits are changed by software, the SPI must be disabled.

Endless transaction is initialized when CSTART is set while zero value is stored at TSIZE.

TSIZE cannot be set to 0xFFFF respective 0x3FF value when CRC is enabled.

Note: TSIZE[15:10] bits are reserved for limited-featured instances, and must be kept at reset value.

80.11.3 SPI/I2S configuration register 1 (SPI_CFG1)

Address offset: 0x008

Reset value: 0x0007 0007

The content of this register is write protected when SPI is enabled.

31302928272625242322212019181716
BPASSMBR[2:0]Res.Res.Res.Res.Res.CRCENRes.CRCSIZE[4:0]
rwrwrwrwrwrwrwrwrwrw
1514131211109876543210
TXDMA ENRXDMA ENRes.Res.Res.Res.UDRCF GFTHLV[3:0]DSIZE[4:0]
rwrwrwrwrwrwrwrwrwrwrwrw

Bit 31 BPASS: bypass of the prescaler at master baud rate clock generator

0: bypass is disabled

1: bypass is enabled

Bits 30:28 MBR[2:0]: master baud rate prescaler setting

000: SPI master clock/2

001: SPI master clock/4

010: SPI master clock/8

011: SPI master clock/16

100: SPI master clock/32

101: SPI master clock/64

110: SPI master clock/128

111: SPI master clock/256

Note: MBR setting is considered at slave working at TI mode, too (see Section 80.5.1: TI mode).

Bits 27:23 Reserved, must be kept at reset value.

Bit 22 CRCEN: hardware CRC computation enable

0: CRC calculation disabled

1: CRC calculation enabled

Bit 21 Reserved, must be kept at reset value.

Bits 20:16 CRCSIZE[4:0]: length of CRC frame to be transacted and compared

Most significant bits are taken into account from polynomial calculation when CRC result is transacted or compared. The length of the polynomial is not affected by this setting.

The value must be equal or a multiple of the data size (DSIZE[4:0]). Its maximum size corresponds to the instance maximum DSIZE value.

00000: reserved

00001: reserved

00010: reserved

00011: 4-bits

00100: 5-bits

00101: 6-bits

00110: 7-bits

00111: 8-bits

.....

11101: 30-bits

11110: 31-bits

11111: 32-bits

Note: The most significant bit at CRCSIZE bit field is reserved at the peripheral instances where data size is limited to 16-bit.

Bit 15 TXDMAEN: Tx DMA stream enable

0: Tx DMA disabled

1: Tx DMA enabled

Bit 14 RXDMAEN: Rx DMA stream enable

0: Rx-DMA disabled

1: Rx-DMA enabled

Bits 13:10 Reserved, must be kept at reset value.

Bit 9 UDRCFG: behavior of slave transmitter at underrun condition

For more details see Figure 967: Optional configurations of the slave behavior when an underrun condition is detected.

0: slave sends a constant pattern defined by the user in the SPI_UDRDR register

1: Slave repeats lastly received data from master. When slave is configured at transmit only mode (COMM[1:0] = 01), all zeros pattern is repeated.

Bits 8:5 FTHLV[3:0]: FIFO threshold level

Defines number of data frames in a single data packet. It is recommended that the size of the packet does not exceed 1/2 of FIFO space.

SPI interface is more efficient if configured packet sizes are aligned with data register access parallelism:

0000: 1-data
0001: 2-data
0010: 3-data
0011: 4-data
0100: 5-data
0101: 6-data
0110: 7-data
0111: 8-data
1000: 9-data
1001: 10-data
1010: 11-data
1011: 12-data
1100: 13-data
1101: 14-data
1110: 15-data
1111: 16-data

Note: FTHLV[3:2] bits are reserved for instances with a limited set of features

Bits 4:0 DSIZE[4:0]: number of bits in a single SPI data frame

00000: not used
00001: not used
00010: not used
00011: 4 bits
00100: 5 bits
00101: 6 bits
00110: 7 bits
00111: 8 bits
.....
11101: 30 bits
11110: 31 bits
11111: 32 bits

Note: Maximum data size can be limited up to 16-bits at some instances. For instances with a limited set of features, DSIZE[2:0] bits are reserved and must be kept at reset state.

DSIZE[4:3] bits then control next settings of data size:

00xxx: 8-bits
01xxx: 16-bits
10xxx: 24-bits
11xxx: 32-bits.

80.11.4 SPI/I2S configuration register 2 (SPI_CFG2)

Address offset: 0x00C

Reset value: 0x0000 0000

The content of this register is write-protected when SPI is enabled or the IOLOCK bit is set in the SPI_CR1 register.

31302928272625242322212019181716
AFCNTRSSOMSSOESSIOPRes.SSMCPOLCPHALSBFRSTMASTERSP[2:0]COMM[1:0]Res.
rwrwrwrwrwrwrwrwrwrwrwrwrwrw
1514131211109876543210
IOSWPRDIOPRDIOMRes.Res.Res.Res.Res.MIDI[3:0]MSSI[3:0]
rwrwrwrwrwrwrwrwrwrwrw

Bit 31 AFCNTR: alternate function GPIOs control

This bit is taken into account when SPE = 0 only.

When SPI must be disabled temporary for a specific configuration reason (for example CRC reset, CPHA or HDDIR change) setting this bit prevents any glitches on the associated outputs configured at alternate function mode by keeping them forced at state corresponding the current SPI configuration.

0: The peripheral takes no control of GPIOs while it is disabled

1: The peripheral keeps always control of all associated GPIOs

Note: This bit can be also used in PCM and I2S modes.

The bit AFCNTR must not be set, when the block is in slave mode.

Bit 30 SSOM: SS output management in master mode

This bit is taken into account in master mode when SSOE is enabled. It allows the SS output to be configured between two consecutive data transfers.

0: SS is kept at active level until data transfer is completed, it becomes inactive with EOT flag

1: SPI data frames are interleaved with SS nonactive pulses when MIDI[3:0] > 1

Bit 29 SSOE: SS output enable

This bit is taken into account in master mode only

0: SS output is disabled and the SPI can work in multimaster configuration

1: SS output is enabled. The SPI cannot work in a multimaster environment. It forces the SS pin at inactive level after the transfer is completed or SPI is disabled with respect to SSOM, MIDI, MSSI, SSIOP bits setting

Bit 28 SSIOP: SS input/output polarity

0: low level is active for SS signal

1: high level is active for SS signal

Bit 27 Reserved, must be kept at reset value.

Bit 26 SSM: software management of SS signal input

0: SS input value is determined by the SS PAD

1: SS input value is determined by the SSI bit

Note: When master uses hardware SS output (SSM = 0 and SSOE = 1) the SS signal input is forced to not active state internally to prevent master mode fault error.

Bits 7:4 MIDI[3:0]: Master Inter-Data Idleness

Specifies minimum time delay (expressed in SPI clock cycles periods) inserted between two consecutive data frames in master mode.

0000: no delay

0001: 1 clock cycle period delay

...

1111: 15 clock cycle periods delay

Note: This feature is not supported in TI mode.

Bits 3:0 MSSI[3:0]: Master SS Idleness

Specifies an extra delay, expressed in number of SPI clock cycle periods, inserted additionally between active edge of SS opening a session and the beginning of the first data frame of the session in master mode when SSOE is enabled.

0000: no extra delay

0001: 1 clock cycle period delay added

...

1111: 15 clock cycle periods delay added

Note: This feature is not supported in TI mode.

To include the delay, the SPI must be disabled and re-enabled between sessions.

80.11.5 SPI/I2S interrupt enable register (SPI_IER)

Address offset: 0x010

Reset value: 0x0000 0000

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
1514131211109876543210
Res.Res.Res.Res.Res.Res.MODFIETIFREIECRCEIEOVRIEUDRIETXTFIEEOTIEDXPIETXPIERXPIE
rwrwrwrwrwrwrwrwrwrw

Bits 31:10 Reserved, must be kept at reset value.

Bit 9 MODFIE: mode Fault interrupt enable

0: MODF interrupt disabled

1: MODF interrupt enabled

Bit 8 TIFREIE: TIFRE interrupt enable

0: TIFRE interrupt disabled

1: TIFRE interrupt enabled

Bit 7 CRCEIE: CRC error interrupt enable

0: CRC interrupt disabled

1: CRC interrupt enabled

Bit 6 OVRIE: OVR interrupt enable

0: OVR interrupt disabled

1: OVR interrupt enabled

80.11.6 SPI/I2S status register (SPI_SR)

Address offset: 0x014

Reset value: 0x0000 1002

All the flags of this register are not cleared automatically when the SPI is reenabled. They require specific clearing access exclusively via the flag clearing register as noted in the bits descriptions below.

31302928272625242322212019181716
CTSIZE[15:0]
rrrrrrrrrrrrrrrr
1514131211109876543210
RXWNERXPLVL[1:0]TXCSUSPRes.MODFTIFRECRCEOVRUDRTXTFEOTDXPTXPRXP
rrrrrrrrrrrrrrr

Bits 31:16 CTSIZE[15:0]: number of data frames remaining in current TSIZE session

The value is not quite reliable when traffic is ongoing on bus or during autonomous operation in low-power mode.

Note: CTSIZE[15:0] bits are not available in instances with limited set of features.

Bit 15 RXWNE: Rx FIFO word not empty

Note: This bit value does not depend on DSIZE setting and keeps together with RXPLVL[1:0] information about Rx FIFO occupancy by residual data.

Bits 14:13 RXPLVL[1:0]: RxFIFO packing level

When RXWNE = 0 and data size is set up to 16-bit, the value gives number of remaining data frames persisting at RxFIFO.

When data size is greater than 16-bit, these bits are always read as 00. In that consequence, the single data frame received at the FIFO cannot be detected neither by RWNE nor by RXPLVL bits if data size is set from 17 to 24 bits. The user must then apply other methods to detect the number of data received, such as monitor the EOT event when TSIZE > 0 or RXP events when FTHLV = 0.

00: no next frame is available at RxFIFO

01: 1 frame is available

10: 2 frames are available*

11: 3 frames are available*

Note: (*) : Possible value when data size is set up to 8-bit only.

Bit 12 TXC: TxFIFO transmission complete

The flag behavior depends on TSIZE setting.

When TSIZE = 0, the TXC is changed by hardware exclusively and it raises each time the TxFIFO becomes empty and there is no activity on the bus.

If TSIZE ≠ 0 there is no specific reason to monitor TXC as it just copies the EOT flag value including its software clearing. The TXC generates an interrupt when EOTIE is set.

This flag is set when SPI is reset or disabled.

0: current data transaction is still ongoing, data is available in TxFIFO or last frame transmission is on going.

1: last TxFIFO frame transmission complete

Bit 11 SUSP: suspension status

In master mode, SUSP is set by hardware either as soon as the current frame is completed after CSUSP request is done or at master automatic suspend receive mode (the MASRX bit is set in the SPI_CR1 register) on RxFIFO full condition.

SUSP generates an interrupt when EOTIE is set.

This bit must be cleared prior to disabling the SPI. This is done by setting the SUSPC bit of SPI_IFCR exclusively.

0: SPI not suspended (master mode active or other mode).

1: master mode is suspended (current frame completed).

Bit 10 Reserved, must be kept at reset value.

Bit 9 MODF: mode fault

When MODF is set, SPE and IOLOCK bits of the SPI_CR1 register are reset and setting SPE again is blocked until MODF is cleared.

This bit is cleared by writing 1 to the MODFC bit of the SPI_IFCR exclusively.

0: no mode fault

1: mode fault detected.

Bit 8 TIFRE: TI frame format error

This bit is cleared by writing 1 to the TIFREC bit of the SPI_IFCR exclusively.

0: no TI Frame Error

1: TI frame error detected

Bit 7 CRCE: CRC error

This bit is cleared when SPI is re-enabled or by writing 1 to the CRCEC bit of the SPI_IFCR optionally.

0: no CRC error

1: CRC error detected

Bit 6 OVR: overrun

This bit is cleared when SPI is re-enabled or by writing 1 to the OVRC bit of the SPI_IFCR optionally.

0: no overrun

1: overrun detected

Bit 5 UDR: underrun

This bit is cleared when SPI is re-enabled or by writing 1 to the UDRC bit of the SPI_IFCR optionally.

0: no underrun

1: underrun detected

Note: In SPI mode, the UDR flag applies to slave mode only. In I2S/PCM mode, (when available) this flag applies to master and slave mode.

Bit 4 TXTF: transmission transfer filled

TXTF is set by hardware as soon as all of the data packets in a transfer have been submitted for transmission by application software or DMA, that is when TSIZE number of data have been pushed into the Tx FIFO.

This bit is cleared by software write 1 to the TXTFC bit of the SPI_IFCR exclusively.

The TXTF flag triggers an interrupt if the TXTFIE bit is set.

TXTF setting clears the TXPIE and DXPIE masks so to off-load application software from calculating when to disable TXP and DXP interrupts.

0: upload of Tx FIFO is ongoing or not started

1: Tx FIFO upload is finished

Bit 3 EOT: end of transfer

EOT is set by hardware as soon as a full transfer is complete, that is when SPI is re-enabled or when TSIZE number of data have been transmitted and/or received on the SPI. EOT is cleared when SPI is re-enabled or by writing 1 to the EOTC bit of the SPI_IFCR register optionally.

EOT flag triggers an interrupt if the EOTIE bit is set.

If DXP flag is used until TXTF flag is set and DXPIE is cleared, EOT can be used to download the last packets contained into Rx FIFO in one-shot.

In master, EOT event terminates the data transaction and handles SS output optionally.

When CRC is applied, the EOT event is extended over the CRC frame transaction.

To restart the internal state machine properly, SPI is strongly suggested to be disabled and re-enabled before next transaction starts despite its setting is not changed.

0: transfer is ongoing or not started

1: transfer complete

Bit 2 DXP: duplex packet

DXP flag is set whenever both TXP and RX flags are set regardless SPI mode.

0: Tx FIFO is Full and/or Rx FIFO is Empty

1: both Tx FIFO has space for write and Rx FIFO contains for read a single packet at least

Bit 1 TXP: Tx-packet space available

TXP flag can be changed only by hardware. Its value depends on the physical size of the FIFO and its threshold (FTHLV[3:0]), data frame size (DSIZE[4:0] in SPI mode and respective DATLEN[1:0] in I2S/PCM mode), and actual communication flow. If the data packet is stored by performing consecutive write operations to SPI_TXDR, TXP flag must be checked again once a complete data packet is stored at Tx FIFO. TXP is set despite SPI Tx FIFO becomes inaccessible when SPI is reset or disabled.

0: not enough free space at Tx FIFO to host next data packet

1: enough free space at Tx FIFO to host at least one data packet

Bit 0 RXP: Rx-packet available

The flag is changed by hardware. It monitors the total number of data currently available at RxFIFO if SPI is enabled. RXP value depends on the FIFO threshold (FTHLV[3:0]), data frame size (DSIZE[4:0] in SPI mode and DATLEN[1:0] in I2S/PCM mode), and actual communication flow. If the data packet is read by performing consecutive read operations from SPI_RXDR, RXP flag must be checked again once a complete data packet is read out from RxFIFO.

0: RxFIFO is empty or an incomplete data packet is received

1: RxFIFO contains at least one data packet

80.11.7 SPI/I2S interrupt/status flags clear register (SPI_IFCR)

Address offset: 0x018

Reset value: 0x0000 0000

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
1514131211109876543210
Res.Res.Res.Res.SUSPCRes.MODFCTIFRECCRCECOVRCUDRCTXTFCEOTCRes.Res.Res.
wwwwwwww

Bits 31:12 Reserved, must be kept at reset value.

Bit 11 SUSPC: Suspend flag clear

Writing a 1 into this bit clears SUSP flag of the SPI_SR register

Bit 10 Reserved, must be kept at reset value.

Bit 9 MODFC: mode fault flag clear

Writing a 1 into this bit clears MODF flag of the SPI_SR register

Bit 8 TIFREC: TI frame format error flag clear

Writing a 1 into this bit clears TIFRE flag of the SPI_SR register

Bit 7 CRCEC: CRC error flag clear

Writing a 1 into this bit clears CRCE flag of the SPI_SR register

Bit 6 OVRC: overrun flag clear

Writing a 1 into this bit clears OVR flag of the SPI_SR register

Bit 5 UDRC: underrun flag clear

Writing a 1 into this bit clears UDR flag of the SPI_SR register

Bit 4 TXTFC: transmission transfer filled flag clear

Writing a 1 into this bit clears TXTF flag of the SPI_SR register

Bit 3 EOTC: end of transfer flag clear

Writing a 1 into this bit clears EOT flag of the SPI_SR register

Bits 2:0 Reserved, must be kept at reset value.

80.11.8 SPI/I2S autonomous mode control register (SPI_AUTOCR)

Address offset: 0x01C

Reset value: 0x0000 0000

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.TRIGENTRIGPOLTRIGSEL[3:0]
rwrwrwrwrwrw
1514131211109876543210
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.

Bits 31:22 Reserved, must be kept at reset value.

Bit 21 TRIGEN: Hardware control of CSTART triggering enable

0: Hardware control disabled

1: Hardware control enabled

Note: if user cannot prevent trigger event during write, the TRIGEN must be changed when SPI is disabled

Bit 20 TRIGPOL: Trigger polarity

0: trigger is active on raising edge

1: trigger is active on falling edge

Note: This bit can be written only when SPE = 0.

Bits 19:16 TRIGSEL[3:0]: Trigger selection (refer Section : Description of SPI interconnections).

0000: spi_trg0 is selected

0001: spi_trg1 is selected

...

1111: spi_trg15 is selected

Note: these bits can be written only when SPE = 0.

Bits 15:0 Reserved, must be kept at reset value.

80.11.9 SPI/I2S transmit data register (SPI_TXDR)

Address offset: 0x020

Reset value: 0x0000 0000

31302928272625242322212019181716
TXDR[31:16]
wwwwwwwwwwwwwwww
1514131211109876543210
TXDR[15:0]
wwwwwwwwwwwwwwww

Bits 31:0 TXDR[31:0]: transmit data register

The register serves as an interface with Tx FIFO. A write to it accesses Tx FIFO.

Note: In SPI mode, data is always right-aligned. Alignment of data at I2S mode depends on DATLEN and DATFMT setting. Unused bits are ignored when writing to the register, and read as zero when the register is read.

Note: DR can be accessed byte-wise (8-bit access): in this case only one data-byte is written by single access.

half-word-wise (16 bit access) in this case 2 data-bytes or 1 half-word-data can be written by single access.

word-wise (32 bit access). In this case 4 data-bytes or 2 half-word-data or word-data can be written by single access.

Write access of this register less than the configured data size is forbidden.

80.11.10 SPI/I2S receive data register (SPI_RXDR)

Address offset: 0x030

Reset value: 0x0000 0000

31302928272625242322212019181716
RXDR[31:16]
rrrrrrrrrrrrrrrr
1514131211109876543210
RXDR[15:0]
rrrrrrrrrrrrrrrr

Bits 31:0 RXDR[31:0]: receive data register

The register serves as an interface with Rx FIFO. When it is read, Rx FIFO is accessed.

Note: In SPI mode, data is always right-aligned. Alignment of data at I2S mode depends on DATLEN and DATFMT setting. Unused bits are read as zero when the register is read. Writing to the register is ignored.

Note: DR can be accessed byte-wise (8-bit access): in this case only one data-byte is read by single access

half-word-wise (16 bit access) in this case 2 data-bytes or 1 half-word data can be read by single access

word-wise (32 bit access). In this case 4 data-bytes or 2 half-word data or word-data can be read by single access.

Read access of this register less than the configured data size is forbidden.

80.11.11 SPI/I2S polynomial register (SPI_CRCPOLY)

Address offset: 0x040

Reset value: 0x0000 0107

The content of this register is write protected when SPI is enabled.

31302928272625242322212019181716
CRCPOLY[31:16]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw
1514131211109876543210
CRCPOLY[15:0]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw

Bits 31:0 CRCPOLY[31:0]: CRC polynomial register

This register contains the polynomial for the CRC calculation.

The default 9-bit polynomial setting 0x107 corresponds to default 8-bit setting of DSIZE. It is compatible with setting 0x07 used in other ST products with fixed length of the polynomial string, where the most significant bit of the string is always kept hidden.

Length of the polynomial is given by the most significant bit of the value stored in this register. It must be set greater than DSIZE. CRC33_17 bit must be set additionally with CRCPOLY register when DSIZE is configured to maximum 32-bit or 16-bit size and CRC is enabled (to keep polynomial length grater than data size).

Note: CRCPOLY[31:16] bits are reserved for instances with data size limited to 16-bit. There is no constrain when 32-bit access is applied at these addresses. Reserved bits 31-16 are always read zero while any write to them is ignored.

80.11.12 SPI/I2S transmitter CRC register (SPI_TXCRC)

Address offset: 0x044

Reset value: 0x0000 0000

31302928272625242322212019181716
TXCRC[31:16]
rrrrrrrrrrrrrrrr
1514131211109876543210
TXCRC[15:0]
rrrrrrrrrrrrrrrr

Bits 31:0 TXCRC[31:0]: CRC register for transmitter

When CRC calculation is enabled, the TXCRC[31:0] bits contain the computed CRC value of the subsequently transmitted bytes. CRC calculation is initialized when the CRCEN bit of the SPI_CR1 register is set or when a data block is transacted completely. The CRC is calculated serially using the polynomial programmed in the SPI_CRCPOLY register.

The number of bits considered at calculation depends on the SPI_CRCPOLY register and CRCSIZE bits settings in the SPI_CFG1 register.

Note: A read to this register when the communication is ongoing may return an incorrect value.

Note: This bitfield is not used in I2S mode.

Note: TXCRC[31-16] bits are reserved for instances with data size limited to 16-bit. There is no constrain when 32-bit access is applied at these addresses. Reserved bits 31-16 are always read zero while any write to them is ignored.

Note: The configuration of the CRCSIZE bitfield is not taken into account when the content of this register is read by software. No masking is applied for unused bits in this case.

80.11.13 SPI/I2S receiver CRC register (SPI_RXCRC)

Address offset: 0x048

Reset value: 0x0000 0000

31302928272625242322212019181716
RXCRC[31:16]
rrrrrrrrrrrrrrrr
1514131211109876543210
RXCRC[15:0]
rrrrrrrrrrrrrrrr

Bits 31:0 RXCRC[31:0]: CRC register for receiver

When CRC calculation is enabled, the RXCRC[31:0] bits contain the computed CRC value of the subsequently received bytes. CRC calculation is initialized when the CRCEN bit of the SPI_CR1 register is set or when a data block is transacted completely. The CRC is calculated serially using the polynomial programmed in the SPI_CRCPOLY register.

The number of bits considered at calculation depends on the SPI_CRCPOLY register and CRCSIZE bits settings in the SPI_CFG1 register.

Note: A read to this register when the communication is ongoing may return an incorrect value.

This bitfield is not used in I2S mode.

RXCRC[31-16] bits are reserved at the peripheral instances with data size limited to 16-bit. There is no constrain when 32-bit access is applied at these addresses.

Reserved bits 31-16 are always read zero while any write to them is ignored.

Note: The configuration of CRCSIZE bit field is not taken into account when the content of this register is read by software. No masking is applied for unused bits in this case.

80.11.14 SPI/I2S underrun data register (SPI_UDRDR)

Address offset: 0x04C

Reset value: 0x0000 0000

The content of this register is write protected when SPI is enabled.

31302928272625242322212019181716
UDRDR[31:16]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw
1514131211109876543210
UDRDR[15:0]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw

Bits 31:0 UDRDR[31:0]: data at slave underrun condition

The register is taken into account in slave mode and at underrun condition only. The number of bits considered depends on the DSIZE bit setting in the SPI_CFG1 register. Underrun condition handling depends on the UDRCFG bit setting in the SPI_CFG1 register.

Note: UDRDR[31-16] bits are reserved at the peripheral instances with data size limited to 16-bit. There is no constraint when 32-bit access is applied at these addresses. Reserved bits 31-16 are always read zero while any write to them is ignored.

80.11.15 SPI/I2S configuration register (SPI_I2SCFGR)

Address offset: 0x050

Reset value: 0x0000 0000

This register must be configured when the I2S is disabled (SPE = 0). The content of this register is not taken into account in SPI mode except for the I2SMOD bit, which needs to be kept at 0.

This register is reserved for instances not supporting I2S mode.

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.MCKOEODDI2SDIV[7:0]
rwrwrwrwrwrwrwrwrwrw
1514131211109876543210
Res.DATFMTWSINVFIXCHCKPOLCHLENDATLEN[1:0]PCMSYNCRes.I2SSTD[1:0]I2SCFG[2:0]I2SMOD
rwrwrwrwrwrwrwrwrwrwrwrwrwrw

Bits 31:26 Reserved, must be kept at reset value.

Bit 25 MCKOE: master clock output enable

Bit 24 ODD: odd factor for the prescaler

Refer to Section 80.9.9: Clock generator for details

Bits 23:16 I2SDIV[7:0]: I2S linear prescaler

I2SDIV can take any values except the value 1, when ODD is also equal to 1.
Refer to Section 80.9.9: Clock generator for details

Bit 15 Reserved, must be kept at reset value.

Bit 14 DATFMT: data format

0: The data inside the SPI_RXDR or SPI_TXDR register are right aligned
1: The data inside the SPI_RXDR or SPI_TXDR register are left aligned.

Bit 13 WSINV: word select inversion

This bit is used to invert the default polarity of WS signal.

0: In I2S Philips standard, the left channel transfer starts one CK cycle after the WS falling edge, and the right channel one CK cycle after the WS rising edge.

In MSB- or LSB-justified mode, the left channel is transferred when WS is HIGH, and the right channel when WS is LOW.

In PCM short mode the data transfer starts at the falling edge of WS, while it starts at the rising edge of WS in PCM long mode.

1: In I2S Philips standard, the left channel transfer starts one CK cycle after the WS rising edge, and the right channel one CK cycle after the WS falling edge.

In MSB- or LSB-justified mode, the left channel is transferred when WS is LOW, and right channel when WS is HIGH.

In PCM short mode the data transfer starts at the rising edge of WS, while it starts at the falling edge of WS in PCM long mode.

Bit 12 FIXCH: fixed channel length in slave

0: the channel length in slave mode is different from 16 or 32 bits (CHLEN must be set)

1: the channel length in slave mode is supposed to be 16 or 32 bits (according to CHLEN)

Bit 11 CKPOL: serial audio clock polarity

0: the signals generated by the SPI/I2S (that is SDO and WS) are changed on the falling edge of CK and the signals received by the SPI/I2S (that is SDI and WS) are read of the rising edge of CK.

1: the signals generated by the SPI/I2S (that is SDO and WS) are changed on the rising edge of CK and the signals received by the SPI/I2S (that is SDI and WS) are read of the falling edge of CK.

Bit 10 CHLEN: channel length (number of bits per audio channel)

0: 16-bit wide

1: 32-bit wide

Bits 9:8 DATLEN[1:0]: data length to be transferred.

00: 16-bit data length

01: 24-bit data length

10: 32-bit data length

11: Not allowed

Note: Data width of 24 and 32 bits are not always supported, (DATLEN = 01 or 10), refer to Section 80.3: SPI implementation to check the supported data size.

Bit 7 PCMSYNC: PCM frame synchronization

0: short frame synchronization

1: long frame synchronization

Bit 6 Reserved, must be kept at reset value.

Bits 5:4 I2SSTD[1:0]: I2S standard selection

For more details on I2S standards, refer to Section 80.9.5: Supported audio protocols

00: I2S Philips standard.

01: MSB-justified standard (left justified)

10: LSB-justified standard (right justified)

11: PCM standard

Bits 3:1 I2SCFG[2:0]: I2S configuration mode

000: slave - transmit

001: slave - receive

010: master - transmit

011: master - receive

100: slave - Full Duplex

101: master - Full Duplex

others: not used

Bit 0 I2SMOD: I2S mode selection

0: SPI mode is selected

1: I2S/PCM mode is selected

80.11.16 SPI/I2S hardware configuration register (SPI_HWCFGR2)

Address offset: 0x3EC

Reset value: 0x0000 0000

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
1514131211109876543210
Res.Res.Res.Res.Res.Res.Res.Res.OPBCFG[7:0]
rrrrrrrr

Bits 31:8 Reserved, must be kept at reset value.

Bits 7:0 OPBCFG[7:0]: Number of option bits available

0000 0000: No option bit is available.

0000 0001: One option bit is available.

....

0001 1111: 31 option bits are available.

0010 0000: 32 option bits are available.

Others: Reserved.

80.11.17 SPI/I2S hardware configuration register (SPI_HWCFGR1)

Address offset: 0x3F0

Reset value: 0x0101 1144 (SPI1_2_3)

Reset value: 0x0100 0133 (SPI4_5_6_7)

Reset value: 0x0010 0133 (SPI8)

31302928272625242322212019181716
Res.Res.Res.Res.FULLCFG[3:0]TRGCFG[3:0]DSCFG[3:0]
rrrrrrrrrrrr
1514131211109876543210
I2SCFG[3:0]CRCCFG[3:0]RXFCFG[3:0]TXFCFG[3:0]
rrrrrrrrrrrrrrrr

Bits 31:28 Reserved, must be kept at reset value.

Bits 27:24 FULLCFG[3:0]: SPI2S full-featured version configuration

0000: Limited-featured version is applied.

0001: Full-featured version is applied.

Others: Reserved.

Bits 23:20 TRGCFG[3:0]: Autonomous trigger feature configuration

0000: Trigger feature is disabled at autonomous mode.

0001: Trigger feature is enabled at autonomous mode.

Others: Reserved.

Bits 19:16 DSCFG[3:0]: SPI data size configuration

All the other combinations are reserved.

0000: maximum data size is 16-bits

0001: maximum data size is 32-bits

Bits 15:12 I2SCFG[3:0]: I2S configuration

All the other combinations are reserved.

0000: I2S support is not implemented

0001: I2S support is implemented

Bits 11:8 CRCCFG[3:0]: CRC configuration for SPI
All the other combinations are reserved.
0000: CRC support is not implemented
0001: CRC support is implemented

Bits 7:4 RXFCFG[3:0]: RxFIFO size
All the other combinations are reserved.
0002: the FIFO size is 4 bytes
0003: the FIFO size is 8 bytes
0004: the FIFO size is 16 bytes
0005: the FIFO size is 32 bytes

Bits 3:0 TXFCFG[3:0]: TxFIFO size
All the other combinations are reserved.
0002: the FIFO size is 4 bytes
0003: the FIFO size is 8 bytes
0004: the FIFO size is 16 bytes
0005: the FIFO size is 32 bytes

80.11.18 SPI/I2S version register (SPI_VERR)

Address offset: 0x3F4

Reset value: 0x0000 0022

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
1514131211109876543210
Res.Res.Res.Res.Res.Res.Res.Res.MAJREV[3:0]MINREV[3:0]
rrrrrrrr

Bits 31:8 Reserved, must be kept at reset value.

Bits 7:4 MAJREV[3:0]: major version

Bits 3:0 MINREV[3:0]: minor version

80.11.19 SPI/I2S identification register (SPI_IPIDR)

Address offset: 0x3F8

Reset value: 0x0013 0023

31302928272625242322212019181716
ID[31:16]
rrrrrrrrrrrrrrrr
1514131211109876543210
ID[15:0]
rrrrrrrrrrrrrrrr
ST logo
ST logo

Bits 31:0 ID[31:0]: Identification

80.11.20 SPI/I2S size identification register (SPI_SIDR)

Address offset: 0x3FC

Reset value: 0xA3C5 DD01

31302928272625242322212019181716
SID[31:16]
rrrrrrrrrrrrrrrr
1514131211109876543210
SID[15:0]
rrrrrrrrrrrrrrrr

Bits 31:0 SID[31:0]: Size identification

Bits[31:8]: fixed code 0xA3C5 DD0

Bits[7:0]: range of address decoding boundary

0x01: 1 Kbyte.

0x02: 2 Kbytes.

0x04: 4 Kbytes.

0x08: 8 Kbytes.

Others: Reserved.

80.11.21 SPI/I2S register map

Table 803. SPI register map and reset values

OffsetRegister name313029282726252423222120191817161514131211109876543210
0x000SPI_CR1Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.IOLOCKTCRCINIRCRCINICRC33_17SSIHDDIRCSUSPCSTARTMASRXRes.Res.Res.Res.Res.Res.Res.SPE
Reset value0000000000
0x004SPI_CR2Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.TSIZE[15:0]
Reset value0(1)0(1)0(1)0(1)0(1)0(1)0(1)000000000
0x008SPI_CFG1BPASSMBR[2:0]Res.Res.Res.CRCENRes.CRCSIZE[4:0]TXDMAENRXDMAENRes.Res.Res.Res.Res.UDRCFGRes.FTHLV[3:0]DSIZE[4:0]
Reset value00000111110000(1)0(1)0000(1)1(1)1(1)1(1)1(1)
0x00CSPI_CFG2AFCNTRSSOMSSOESSIOPRes.SSMCPOLCPHALSBFRSTMASTERSP[2:0]COMM[1:0]Res.IOSWPRDIOPRDIOMRes.Res.Res.Res.Res.MIDI[3:0]MSSI[3:0]
Reset value0000000000000000000000000
0x010SPI_IERRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.MODFIETIFREIECRCEIEOVRIEUDRIETXTFIEEOTIEDXPIETXPIERXPIE
Reset value0000000000
0x014SPI_SRCTSIZE[15:0](1)RXWNERXPLVL[1:0]TXCSUSPRes.MODFTIFRECRCEOVRUDRTXTFEOTDPXPTXPRXP
Reset value0000000000000000000100000000010

Table 803. SPI register map and reset values (continued)

OffsetRegister name313029282726252423222120191817161514131211109876543210
0x018SPI_IFCRRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.SUSPCRes.MODFCTIFRECCRCECOVRCUDRCTXTCEOTCRes.Res.Res.
Reset value00000000
0x01CSPI_AUTOCRRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.TRIGENTRIGPOLTRIGSEL[3:0]Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
Reset value000000
0x020SPI_TXDRTXDR[31:16]TXDR[15:0]
Reset value00000000000000000000000000000000
0x024-0x02CReservedRes.
0x030SPI_RXDRRXDR[31:16]RXDR[15:0]
Reset value00000000000000000000000000000000
0x034-0x03CReservedRes.
0x040SPI_CRCPOLYCRCPOLY[31:16](2)CRCPOLY[15:0]
Reset value00000000000000000000001000000111
0x044SPI_TXCRCTXCRC[31:16](2)TXCRC[15:0]
Reset value00000000000000000000000000000000
0x048SPI_RXCRCRXCRC[31:16](2)RXCRC[15:0]
Reset value00000000000000000000000000000000
0x04CSPI_UDRDRUDRDR[31:16](2)UDRDR[15:0]
Reset value00000000000000000000000000000000
0x050SPI_I2SCFGRRes.Res.Res.Res.Res.Res.MCKOEODDI2SDIV[7:0]Res.Res.WSINVFIXCHCKPOLCHLENDATLEN[1:0]PCMSYNCRes.I2SSTD[1:0]I2SCFG[2:0]I2SMOD
Reset value0000000000000000000
0x0E4-0x3E8ReservedRes.
0x3ECSPI_HWCFGR2Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.OPBCFG[7:0]
Reset value0x0000 0000
0x3F0SPI_HWCFGR1Res.Res.Res.Res.Res.Res.FULLCFG[3:0]TRGCFG[3:0]DSCFG[3:0]I2SCFG[3:0]CRCCFG[3:0]RXF CFG[3:0]TXF CFG[3:0]
Reset value0x0101 1144 (SPI2S1_2_3)
0x0100 0133 (SPI4_5_6_7)
0x0010 0133 (SPI8)
0x3F4SPI_VERRRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.MAJREV[3:0]MINREV[3:0]
Reset value0x0000 0022
0x3F8SPI_IPIDRID[31:0]
Reset value0x0013 0023
0x3FCSPI_SIDRSID[31:0]
Reset value0xA3C5 DD01
  1. 1. The bitfield is reserved for instances with a limited set of features and it must be kept at reset value. For more details, refer to the concrete register description in Section 80.11: SPI/I2S registers.
  2. 2. The bits 31-16 are reserved for the peripheral instances with data size limited to 16-bit. There is no constraint when the 32-bit access is applied at these addresses. The bits 31-16, when reserved, are always read to zero while any write to them is ignored.

Refer to Section 2.4 for the register boundary addresses.