ST X-CUBE-SPN12 User manual

Introduction
The X-CUBE-SPN12 expansion software package for STM32Cube runs on the STM32 Nucleo providing management of
STSPIN240 to control dual brush DC motor driver.
The expansion is built on STM32Cube software technology to ease portability across different STM32 microcontrollers.
It is compatible with the NUCLEO-F401RE, NUCLEO-F334R8, NUCLEO-F030R8 or NUCLEO-L053R8 development boards
connected to an X-NUCLEO-IHM12A1 expansion board.
The software comes with a sample implementation driving two bidirectional low voltage dual brush DC motors.
RELATED LINKS
Visit the STM32Cube ecosystem web page on www.st.com for further information
Getting started with the X-CUBE-SPN12 low voltage dual brush DC motor driver
software expansion for STM32Cube
UM2110
User manual
UM2110 - Rev 2 - May 2021
For further information contact your local STMicroelectronics sales office.
www.st.com

1Acronyms and abbreviations
Table 1. List of acronyms
Acronym Description
API Application programming interface
BSP Board support package
CMSIS Cortex® microcontroller software interface standard
HAL Hardware abstraction layer
SPI Serial port interface
IDE Integrated development environment
LED Light emitting diode
UM2110
Acronyms and abbreviations
UM2110 - Rev 2 page 2/14

2X-CUBE-SPN12 software expansion for STM32Cube
2.1 Overview
The X-CUBE-SPN12 software package expands STM32Cube functionality, and features:
•STSPIN240 configuration (bridge input and enabling signals)
• flag interrupt handling (overcurrent and thermal alarm reporting)
• handling of up to two bidirectional dual brush DC motors
•STM32 Nucleo and expansion board configuration (GPIOs, PWMs, IRQs, etc.)
To use the STSPIN240 driver library, first call its initialization function to:
• set up the required GPIOs to handle the bridge enabling pins and the FLAG interrupt which reports
overcurrent detection or thermal protection
•set up the drivers
• load the driver parameters with the values in "stspin240_250_target_config.h", in order to program the PWM
frequency of the bridge inputs and the number of brush DC motors .
You can easily modify the driver parameters through specific functions able to change the bridge configuration,
the number of motors or the PWM frequency.
You can also use callback functions with:
• the flag interrupt handler, when a failure is reported by the STSPIN240;
• the error handler, called by the library when it reports an error.
Then, you can drive different brush DC motors by setting a specified running direction and by changing the
maximum speed. When a motor is requested to run, the related bridge is automatically enabled.
A motion command can be stopped at any moment:
• by a hard stop which immediately stops the motor
• or by a hardHiz command which immediately stops the motor and disables the bridge it uses.
The library also provides functions to disable or enable the bridges independently of the run or stop commands.
2.2 Architecture
This STM32Cube software expansion enables development of applications using low voltage dual brush DC
motor drivers.
Figure 1. X-CUBE-SPN12 software architecture
Application Example for 2 brush DC motors
STM32Cube Hardware Abstraction Layer (HAL)
Hardware
Abstraction
Hardware
NUCLEO-F401RE, NUCLEO-F334R8, NUCLEO-F030R8, NUCLEO-L053R8
X-NUCLEO-IHM12A1
STM32 Nucleo expansion boards
STM32 Nucleo development board
UM2110
X-CUBE-SPN12 software expansion for STM32Cube
UM2110 - Rev 2 page 3/14

The software is based on the STM32CubeHAL hardware abstraction layer for the STM32 microcontroller and
extends STM32Cube with a board support package (BSP) for the low voltage dual brush DC motor driver
expansion board (X-NUCLEO-IHM12A1) and a BSP component driver for STSPIN240 motor driver.
The software layers used by the application software to access and use the dual brush DC motor driver
expansion board are:
• STM32Cube HAL layer: provides a generic, multi-instance set of simple APIs (application programming
interfaces) to interact with the upper layers (application, libraries and stacks). These generic and extension
APIs are based on a common architecture and the layers above them like the middleware layer can function
without requiring specific hardware configuration data for a given microcontroller unit (MCU). This structure
improves the library code reusability and guarantees easy portability across other devices.
• Board support package (BSP) layer: supports the peripherals on the STM32 Nucleo board, except for
the MCU. This limited set of APIs provides a programming interface for certain board specific peripherals
like the user button, the LED, etc, and helps in identifying the specific board version. In case of motor
control expansion boards, the motor control BSP provides a programming interface for various motor driver
components. The BSP in the X-CUBE-SPN12 software provides the drivers to manage the STSPIN240
motor driver.
2.3 Folder structure
Figure 2. X-CUBE-SPN12 package folder structure
The software is packaged in the following main folders:
•Drivers:
–STM32Cube HAL driver files which directly derive from the STM32Cube framework.
– CMSIS folder with the CMSIS (Cortex® microcontroller software interface standard) files from ARM.
These files form a vendor-independent hardware abstraction layer for the Cortex-M processor series.
This folder is also unchanged from the STM32Cube framework.
– BSP folder with code files required for X-NUCLEO-IHM12A1 configuration, the STSPIN240 driver and
the motor control API. (see Section 2.3.1 BSP folder)
•Projects: contains a sample STSPIN240 application using two bidirectional brush DC motors.
2.3.1 BSP folder
2.3.1.1 STM32F4XX-Nucleo/STM32F3XX-Nucleo/STM32F0XX-Nucleo/STM32L0XX-Nucleo BSPs
Depending on the STM32 Nucleo development board, these BSPs provide an interface to configure and use the
development board peripherals with the X-NUCLEO-IHM12A1 expansion board.
Each subfolder (STM32F4XX-Nucleo/STM32F3XX-Nucleo/STM32F0XX-Nucleo/STM32L0XX-Nucleo) contains
two couples of .c/.h files:
•stm32XXxx_nucleo.c/h: these files derive from the STM32Cube framework (with no modification) and
provide the functions to handle the related STM32 Nucleo board user button and LEDs.
•stm32XXxx_nucleo_IHM12a1.c/h: these files are dedicated to the configuration of the PWMs, the GPIOs
and the interrupt enabling/disabling.
UM2110
Folder structure
UM2110 - Rev 2 page 4/14

2.3.1.2 Motor control BSP
This BSP provides a common interface to access the driver functions of various motor drivers, such as L6206,
L6474, powerSTEP01, STSPIN240, etc. This is done via a couple of c/h files: MotorControl/motorcontrol.c/h,
which defines all the functions to configure and control the motor driver. These functions are then mapped to
the functions of the motor driver component used on the given expansion board via the structure file: motorDrv_t
(defined in Components\Common\motor.h).
This structure defines a list of function pointers filled during its instantiation in the corresponding motor driver
component.
For X-CUBE-SPN12, the structure instance is called stspin240_250Drv (see file
BSP\Components\stspin240_250\stspin240_250.c)
As the motor control BSP is common for all motor driver expansion boards, some functions are not available for
all expansion boards. In this case, during the instantiation of the motorDrv_t structure in the driver component, the
unavailable functions are replaced by a null pointer.
2.3.1.3 Stspin240_250 BSP component
The stspin240_250 BSP component provides the driver functions of the STSPIN240 low voltage dual brush DC
motor driver in the folder stm32_cube\Drivers\BSP\Components\stspin240_250, which contains:
•stspin240_250.c: Stspin240_250 driver core functions
•stspin240_250.h: declaration of the Stspin240_250 driver functions and their associated definitions
•stspin240_250_target_config.h: parameter value setup for the STSPIN240 (bridge configuration, number
of brush DC motors, bridge input PWMs frequency)
When used with an STSPIN240 driver as in the case of the X-NUCLEO-IHM12A1 expansion board, this
component requires the compilation flag declaration: STSPIN_240.
2.3.2 Project folder
For each STM32 Nucleo development board, the example projects are in the folder
stm32_cube\Projects\Multi\Examples\MotionControl\: IHM12A1_ExampleFor2BiDirMotors (examples of control
functions for two bidirectional brush DC motor driving).
There is a dedicated folder for the target IDE:
•EWARM containing the project files for IAR
•MDK-ARM containing the project files for Keil
•STM32CubeIDE containing the project files for STM32CubeIDE
Each example also has the following code files:
•inc\main.h: main header file
•inc\ stm32xxxx_hal_conf.h: HAL configuration file
•inc\stm32xxxx_it.h : header for the interrupt handler
•src\main.c: main program (code of the example which is based on the motor control library for STSPIN240)
•src\stm32xxxx_hal_msp.c: HAL initialization routines
•src\stm32xxxx_it.c: interrupt handler
•src\system_stm32xxxx.c: system initialization
•src\clock_xx.c: clock initialization
2.4 Software required resources
STSPIN240 and the MCU communicate through GPIOs:
•1 common GPIO for the flag interrupt (overcurrent detection or overtemperature protection) and the enable
pin
• 2 GPIOs to generate a PWM for each bridge input (PWMA and PWMB)
• 2 GPIOs for the bridge input phase and to set the motor direction (PHA/DIR_A and PHB/DIR_B)
• 1 GPIO to generate a PWM for REF level setup
• 1 GPIO to set/reset the reset pin
UM2110
Software required resources
UM2110 - Rev 2 page 5/14

Table 2. Required resources for the X-CUBE-SPN12 software
Resources for F4xx/F3xx Resources for L0xx Resources for F0xx Pin Features
ext. line 10
GPIO PA10 D2 flag interrupt and enable pin
GPIO PB5
TIM3 CH2
GPIO PB5
TIM22 CH2 D4 PWM for B PWMB brige
GPIO PB4
TIM3 CH1
GPIO PB4
TIM22 CH1 D5 PWM for A PWMA brigde
GPIO PB10 D6 direction for A PHA/DIR_A bridge
GPIO PA8 D7 Direction for B PHB/DIR_B bridge
GPIO PA0
TIM2 CH1
GPIO PA9
TIM1 CH2
GPIO PA0
TIM2 CH1
A0 (or D8 for
F0) REF
GPIO PC7 D9 reset
2.5 APIs
Detailed function and parameter descriptions for the user-APIs are compiled in an HTML file in the software
package Documentation folder.
X-CUBE-SPN12 software API is defined in the BSP motor control (functions predefined through
BSP_MotorControl_).
Note: Not all the functions of this module are available for the STSPIN240 and, consequently, for the X-NUCLEO-
IHM12A1 expansion board.
UM2110
APIs
UM2110 - Rev 2 page 6/14

3System setup guide
3.1 Hardware description
This section describes the hardware components which are required to execute the X-CUBE-SPN12 software and
successfully drive one or two low voltage dual brush DC motors.
3.1.1 STM32 Nucleo
STM32 Nucleo development boards provide an affordable and flexible way for users to test solutions and build
prototypes with any STM32 microcontroller line.
The Arduino connectivity support and ST morpho connectors make it easy to expand the functionality of the
STM32 Nucleo open development platform with a wide range of specialized expansion boards to choose from.
The STM32 Nucleo board does not require separate probes as it integrates the ST-LINK/V2-1 debugger/
programmer.
The STM32 Nucleo board comes with the comprehensive STM32 software HAL library together with various
packaged software examples for different IDEs (IAR EWARM, Keil MDK-ARM, STM32CubeIDE, mbed and GCC/
LLVM).
All STM32 Nucleo users have free access to the mbed online resources (compiler, C/C++ SDK and developer
community) at www.mbed.org to easily build complete applications.
Figure 3. STM32 Nucleo board
UM2110
System setup guide
UM2110 - Rev 2 page 7/14

3.1.2 X-NUCLEO-IHM12A1 low voltage dual brush DC motor driver expansion board
The X-NUCLEO-IHM12A1 is a low voltage dual brush DC motor driver expansion board based on the STSPIN240
for STM32 Nucleo.
It provides an affordable and easy-to-use solution for the implementation of portable motor driving applications
such as thermal printers, robotics and toys.
Thanks to its programmable current limiter and complete set of protection features, it offers high levels of
performance and robustness.
The X-NUCLEO-IHM12A1 is compatible with the Arduino UNO R3 connector and most STM32 Nucleo
development boards.
Figure 4. X-NUCLEO-IHM12A1 expansion board
3.2 Hardware requirements
To complete the hardware setup, you need:
•one or two low voltage dual brush DC motor
• an external DC power supply with two electric cables (up to 10 V)
• a USB type A to mini-B USB cable to connect the STM32 Nucleo to a PC/laptop
• a Windows™ (v. 7 and above) – laptop or PC
3.3 Software requirements
The following software components are needed for a suitable development environment for applications based on
the motor driver expansion board:
•ST-LINK/V2-1 USB driver
• ST-LINK/V2-1 firmware upgrade
•X-CUBE-SPN12 expansion for STM32Cube dedicated to STSPIN240 low voltage dual brush motor driver
application development. The X-CUBE-SPN12 firmware and related documentation are available on
www.st.com.
• One of the following development tool-chain and compilers:
– Keil RealView Microcontroller Development Kit (MDK-ARM) toolchain V5.12
– IAR Embedded Workbench for ARM (EWARM) toolchain V7.20
– Integrated Development Environment for STM32 (STM32CubeIDE)
UM2110
Hardware requirements
UM2110 - Rev 2 page 8/14

3.4 Hardware and software setup
This section describes the hardware and software setup procedure for executing the provided examples and to
develop new applications based on the motor driver expansion board.
3.4.1 Common setup for all configurations
The STM32 Nucleo development board has to be configured with the following jumper position:
•JP1 off
• JP5 (PWR) on UV5 side
• JP6 (IDD) on
3.4.2 REF pin setup on X-NUCLEO-IHM12A1 expansion board
Depending on the STM32 Nucleo development board, the REF pin setup has to be adapted to the X-NUCLEO-
IHM12A1 expansion board.
With NUCLEO-F401RE, NUCLEO-F334R8 or NUCLEO-L053R8, the default configuration of the board is: R22
(200 kΩ) mounted and R23 not mounted.
With NUCLEO-F030R8, R23 (200 kΩ) has to be mounted and R22 not mounted. If you want to keep the default
board configuration, you can simply put a wire between the Arduino UNO R3 CN5-1 and CN8-1 connector pins.
3.4.3 Setup to drive two bidirectional brush DC motors
Step 1. Plug the X-NUCLEO-IHM12A1 expansion board on top of the STM32 Nucleo development board via
the Arduino UNO R3 connectors.
Step 2. Connect the STM32 Nucleo development board to a PC with the USB cable through USB connector
CN1 to power the board.
Step 3. Connect the leads of the first dual brush DC motor to the X-NUCLEO-IHM12A1 bridge output
connector A+/A- and the second to connectors B+/B-.
Step 4. Power on theX-NUCLEO-IHM12A1 expansion board by connecting its connectors Vin and Gnd to
the DC power supply. The DC supply must be set to deliver the required voltage to the three-phase
brushless motor.
Step 5. Open your preferred toolchain.
Step 6. Depending on the used STM32 Nucleo board, open the software project from:
– \stm32_cube\Projects\Multi\Examples\MotionControl\IHM12A1_ExampleFor2BiDirMotors\YourTo
olChainName\STM32F401RE-Nucleo for NUCLEO-F401RE
– \stm32_cube\Projects\Multi\Examples\MotionControl\IHM12A1_ExampleFor2BiDirMotors\YourTo
olChainName\STM32F334R8-Nucleo for NUCLEO-F334R8
– \stm32_cube\Projects\Multi\Examples\MotionControl\IHM12A1_ExampleFor2BiDirMotors\YourTo
olChainName\STM32F030R8-Nucleo for NUCLEO-F030R8
– \stm32_cube\Projects\Multi\Examples\MotionControl\IHM12A1_ExampleFor2BiDirMotorsYourTool
ChainName\STM32L053R8-Nucleo for NUCLEO-L053R8
Step 7. Adapt the default parameters used by the STSPIN240 to your motor characteristics by modifying the
parameters in stm32_cube\Drivers\BSP\Components\stspin240_250\stspin240_250_target_config. h.
Step 8. Rebuild all files and load your image into target memory.
Step 9. Run the sample application.
Step 10. Push the user button to start the motor.
Step 11. Open main.c to watch the detailed demo sequence. Each time you press the user button, a different
demo sequence step appears.
UM2110
Hardware and software setup
UM2110 - Rev 2 page 9/14

Revision history
Table 3. Document revision history
Date Version Changes
04-Oct-2016 1 Initial release.
21-May-2021 2
Updated Introduction, Section 2.1 Overview, Section 2.2 Architecture, Section 2.3 Folder
structure, Section 2.3.2 Project folder, Section 3.3 Software requirements and
Section 3.4.3 Setup to drive two bidirectional brush DC motors.
Removed Section 2. What is STM32Cube? and Section 2.1 STM32Cube architecture and replaced
them with a link in the Introduction.
UM2110
UM2110 - Rev 2 page 10/14

Contents
1Acronyms and abbreviations ......................................................2
2X-CUBE-SPN12 software expansion for STM32Cube................................3
2.1 Overview .....................................................................3
2.2 Architecture ...................................................................3
2.3 Folder structure ................................................................4
2.3.1 BSP folder..............................................................4
2.3.2 Project folder............................................................5
2.4 Software required resources .....................................................5
2.5 APIs .........................................................................6
3System setup guide................................................................7
3.1 Hardware description ...........................................................7
3.1.1 STM32 Nucleo ..........................................................7
3.1.2 X-NUCLEO-IHM12A1 low voltage dual brush DC motor driver expansion board ........8
3.2 Hardware requirements .........................................................8
3.3 Software requirements ..........................................................8
3.4 Hardware and software setup ....................................................9
3.4.1 Common setup for all configurations ..........................................9
3.4.2 REF pin setup on X-NUCLEO-IHM12A1 expansion board .........................9
3.4.3 Setup to drive two bidirectional brush DC motors ................................9
Revision history .......................................................................10
Contents ..............................................................................11
List of tables ..........................................................................12
List of figures..........................................................................13
@NA ..................................................................................14
UM2110
Contents
UM2110 - Rev 2 page 11/14

List of tables
Table 1. List of acronyms ....................................................................2
Table 2. Required resources for the X-CUBE-SPN12 software ...........................................6
Table 3. Document revision history ............................................................. 10
UM2110
List of tables
UM2110 - Rev 2 page 12/14

List of figures
Figure 1. X-CUBE-SPN12 software architecture ....................................................3
Figure 2. X-CUBE-SPN12 package folder structure .................................................4
Figure 3. STM32 Nucleo board ...............................................................7
Figure 4. X-NUCLEO-IHM12A1 expansion board ...................................................8
UM2110
List of figures
UM2110 - Rev 2 page 13/14

IMPORTANT NOTICE – PLEASE READ CAREFULLY
STMicroelectronics NV and its subsidiaries (“ST”) reserve the right to make changes, corrections, enhancements, modifications, and improvements to ST
products and/or to this document at any time without notice. Purchasers should obtain the latest relevant information on ST products before placing orders. ST
products are sold pursuant to ST’s terms and conditions of sale in place at the time of order acknowledgement.
Purchasers are solely responsible for the choice, selection, and use of ST products and ST assumes no liability for application assistance or the design of
Purchasers’ products.
No license, express or implied, to any intellectual property right is granted by ST herein.
Resale of ST products with provisions different from the information set forth herein shall void any warranty granted by ST for such product.
ST and the ST logo are trademarks of ST. For additional information about ST trademarks, please refer to www.st.com/trademarks. All other product or service
names are the property of their respective owners.
Information in this document supersedes and replaces information previously supplied in any prior versions of this document.
© 2021 STMicroelectronics – All rights reserved
UM2110
UM2110 - Rev 2 page 14/14
Table of contents
Popular DC Drive manuals by other brands

Rockwell Automation
Rockwell Automation Allen-Bradley PowerFlex 755TS Series Hardware service

ETC
ETC F-Drive R12 Series installation manual

ABB
ABB ACQ550-U1-015A-4 Series user manual

Unidrive
Unidrive M70 Series Installation sheet

Eaton
Eaton SC9000 EP installation manual

Danfoss
Danfoss AME 23 installation guide