ST AN3980 APPLICATION NOTE

1 Introduction

This application note describes the implementation of the STM32 firmware library for the dSPIN stepper motor control product (L6470). It provides a guide on how to use the library for final application development. The L6470 is a fully integrated microstepping motor driver with embedded motion engine and SPI communication interface. A low R supports different operating modes including a 128-microstep resolution. It is based on digital control core surrounded with a number of different peripherals and protections. Chip operating mode, motion profiles, and all the other parameters are memorized in an embedded set of registers. Communication with the IC is done through an integrated 5 MHz SPI periphery in determined data format according to the documentation. See the L6470 datasheet for more details about registers, application commands, etc. The firmware library speeds up the application development process and saves time consumed by register constant definitions and command routine implementation in the microcontroller source code.
AN3980
Application note
STM32™ firmware library for dSPIN L6470
DMOS power stage is also a part of the IC. The chip
DSON
Firmware library main features
Designed for the STM32F1xx microcontroller family
STEVAL-PCC009V2 + STM32 value line Discovery demonstration boards supported with library configuration (dspin.h) and development tools project files
Easy portability due to ANSI C standard compliance – Only HAL (“Hardware Abstraction Layer”) routines should be modified when used with
another platform
– Simple portability to STM8™ families thanks to similar HAL routines for peripherals - SPI,
GPIOs, etc.
Library contains project folders (files) for development tools: – IAR™ - EWARM v5
J-Link for STEVAL-PCC009V2
ST-Link for STM32 VL Discovery
– IAR - EWARM v6
J-Link for STEVAL-PCC009V2
– KEIL - µVision
ULINK2
ULINK Pro for STEVAL-PCC009V2
ST-Link for STM32 VL Discovery
– Raisonance - RIDE v7
®
v4.03, v4.20
®
for STEVAL-PCC009V2
R-Link for STEVAL-PCC009V2
November 2011 Doc ID 022200 Rev 1 1/18
www.st.com
AN3980 Contents
Contents
1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
2 Library file structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
3 Demonstration board electrical connection . . . . . . . . . . . . . . . . . . . . . . 6
4 dSPIN.h file content . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
4.1 Demonstration board related signal assignments . . . . . . . . . . . . . . . . . . . 7
4.2 dSPIN Init structure definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
4.3 Register options / mask definition (enumerated types) . . . . . . . . . . . . . . . 9
4.4 L6470 register addresses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
4.5 L6470 command set definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
4.6 Macros definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
5 dSPIN.c file content . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
6 main.c file content . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Appendix A Demonstration board images . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
References. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Doc ID 022200 Rev 1 2/18
List of figures AN3980
List of figures
Figure 1. Firmware library folder structure. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
Figure 2. Firmware library file list. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Figure 3. Demonstration board selection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Figure 4. Demonstration board signal assignment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Figure 5. L6470 registers structure type definition. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Figure 6. Step select parameter definition for “Step Mode” register . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Figure 7. Configuration register mask definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Figure 8. Register addresses. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Figure 9. L6470 command set type definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Figure 10. List of defined macros. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Figure 11. Demonstration board STEVAL-PCC009V2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Figure 12. Demonstration board STM32F100 value line Discovery kit . . . . . . . . . . . . . . . . . . . . . . . . 15
Figure 13. L6470 demonstration board (EVAL6470) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
3/18 Doc ID 022200 Rev 1
AN3980 Library file structure

2 Library file structure

Firmware implementation is split between the following files:
dspin.c
Microcontroller peripherals initialization
dSPIN application commands implementation
Library support functions implementation
dspin.h
Function prototypes for implemented commands and support functions
Register value (options) definition
Register mask definition
Macros for selected function parameter conversions
Demonstration board related definitions - GPIO signals and peripherals
assignment
main.c
Example of library usage - system configuration / function calls
Other microcontroller configuration files, such as
clock.c, -.h, stm32f10x_conf.h (peripherals configuration), stm32f10x_it.c, -.h
(interrupt routines) and standard library for GPIO and SPI
Firmware is available for download in compressed zip format. By decompressing the archive the following folder structure is created on a drive:

Figure 1. Firmware library folder structure

The “Libraries” folder contains microcontroller related files like peripheral source/header files, startup file, etc.
Doc ID 022200 Rev 1 4/18
Library file structure AN3980
The “Project” folder contains demonstration board related subfolders. dSPIN library source and header files and other subfolders with project files for different development tools appear in each of the demonstration board subfolders. A list of the source/header files can be seen in Figure 2:

Figure 2. Firmware library file list

5/18 Doc ID 022200 Rev 1
AN3980 Demonstration board electrical connection

3 Demonstration board electrical connection

The firmware library supports two demonstration boards:
1. STEVAL-PCC009V2 universal USB to serial bus interface
2. STM32F100 value line Discovery kit
In the case of STEVAL-PCC009V2, the connection of the L6470 demonstration board is simple. It is only necessary to use a 10-wire flat cable connection line inserted into J1 on STEVAL-PCC009V2 and J10 on the L6470 demonstration board. The signals are assigned according to the appropriate section in the dSPIN.h file, see Table 1 :

Table 1. Microcontroller signal assignment for STEVAL-PCC009V2

L6470 demonstration board signal Microcontroller periphery
SPI Clock PB 13
SPI MOSI PB 15
SPI MISO PB 14
SPI nSS PB 12
BUSY PB 10
FLAG PB 11
PWM 1 PB 0
PWM 2 PB 1
STEVAL-PCC009V2 Power LED PC 4
Microcontroller peripherals for the STM32F100 value line Discovery kit connection have been selected according to Table 2. The user is free to modify the assignment according to their needs. The condition for correct functionality is consistency between physical connection and dSPIN.h file content.

Table 2. Microcontroller signal assignment for STM32F100 value line Discovery kit

L6470 demonstration board signal Microcontroller periphery
SPI Clock PA 5
SPI MOSI PA 7
SPI MISO PA 6
SPI nSS PA 4
BUSY PC 4
FLAG PC 5
PWM 1 PA 1
PWM 2 PB 0
Doc ID 022200 Rev 1 6/18
Loading...
+ 13 hidden pages