Main Content

Migrate SPI Block Usage to STM32 Processor Based Library Block

When you migrate SPI block usage in STMicroelectronics hardware board models from using Simulink Coder support package blocks to using Embedded Coder support package blocks, there is a workflow you should use. This table lists the blocks that should be migrated with this workflow.

Migrate Block Usage

Migrate from Blocks in Simulink Coder Support Package for STMicroelectronics Nucleo Boards Library

Migrate to Blocks in Embedded Coder Support Package for STMicroelectronics STM32 Processor Library

SPI Register Read

SPI Receive

SPI Register Write

SPI Transmit

To migrate your model from using these blocks to using the corresponding blocks in an STM32Fxx Based Board block library, follow these steps. These example steps show the process for migrating usage from the Nucleo library SPI Register Read block and SPI Register Write block to the STM32 processor library SPI Receive block and SPI Transmit block:

  1. Open the Simulink model in which you are migrating block usage.

  2. From Configuration Parameters > Hardware Implementation > Target hardware resources > Group, select the SPI0 (default) resource. Note the pin selections for SDO (D11 corresponds to external pin PA_7), SDI (D12 corresponds to external pin PA_6), and SCK (D13 corresponds to external pin PA_5).

    Model configuration parameters for selecting SPI resource and pins on Nucleo board

    The pin selection for the CS (D7 corresponds to external pin PF_13) is selected from the SPI Register Read block and SPI Register Write block parameters. D7 is connected as shown. To get more info on SPI modes, see Support SPI Communication.

    Mode

    Clock Polarity (CPOL)

    Clock Phase (CPHA)

    0

    0

    0

    1

    0

    1

    2

    1

    0

    3

    1

    1

  3. Change Hardware board selection to STM32F7xx Based (Double Precision). After the dialog box updates to match this selection, From Target hardware resources > Build options, use the Browse or Create buttons to select an STM32CubMX project file.

    Model configuration parameters for selecting SPI resource on STM32F4xx Based processor board

  4. To open the STM32 CubeMX configuration software and configure pin selections, click the Launch button.

  5. In the STM32 CubeMX configuration software, configure the SPI1 port options.

    Port configuration for SPI resource in STM32 CubeMX configuration software

  6. In the STM32 CubeMX configuration software, configure the SPI1_SCK (PA5), SPI1_MISO (PA6), SPI1_MOSI (PA7), and GPIO_Output (PF13) pin usage.

    Pin map configuration for SPI port and pins in STM32 CubeMX configuration software

  7. In the Simulink model, replace the SPI Register Read block and SPI Register Write block from the Nucleo library with a SPI Receive block and SPI Transmit block from the STM32F4xx Based Boards library or STM32F7xx Based Boards library.

  8. View the block configuration parameters. Confirm that the SPI chip select features are setup as shown. This setting matches the options that you assigned in the CubeMX configuration IOC file.

    Block configuration parameters for SPI block in STM32 library

See Also

Topics