logo资料库

UM1911用户手册(DM00207127).pdf

第1页 / 共63页
第2页 / 共63页
第3页 / 共63页
第4页 / 共63页
第5页 / 共63页
第6页 / 共63页
第7页 / 共63页
第8页 / 共63页
资料共63页,剩余部分请下载后查看
Heading1 - 1 What is STM32Cube?
Heading2 - 1.1 STM32Cube overview
Heading2 - 1.2 STM32Cube architecture
Heading1 - 2 X-CUBE-SPN3 software expansion for STM32Cube
Heading2 - 2.1 Overview
Heading2 - 2.2 Architecture
Heading2 - 2.3 Folder structure
Heading3 - 2.3.1 BSP folder
Heading3 - 2.3.2 Projects folder
Heading2 - 2.4 Software required resources
Heading2 - 2.5 APIs
Heading3 - 2.5.1 BSP_MotorControl_AttachBusyInterrupt()
Heading3 - 2.5.2 BSP_MotorControl_AttachErrorHandler()
Heading3 - 2.5.3 BSP_MotorControl_AttachFlagInterrupt()
Heading3 - 2.5.4 BSP_MotorControl_BusyInterruptHandler()
Heading3 - 2.5.5 BSP_MotorControl_CheckBusyHw()
Heading3 - 2.5.6 BSP_MotorControl_CheckStatusHw()
Heading3 - 2.5.7 BSP_MotorControl_CmdGetParam()
Heading3 - 2.5.8 BSP_MotorControl_CmdGetStatus()
Heading3 - 2.5.9 BSP_MotorControl_CmdGoToDir()
Heading3 - 2.5.10 BSP_MotorControl_CmdGoUntil()
Heading3 - 2.5.11 BSP_MotorControl_CmdHardHiZ()
Heading3 - 2.5.12 BSP_MotorControl_CmdNop()
Heading3 - 2.5.13 BSP_MotorControl_CmdReleaseSw()
Heading3 - 2.5.14 BSP_MotorControl_CmdResetDevice()
Heading3 - 2.5.15 BSP_MotorControl_CmdResetPos()
Heading3 - 2.5.16 BSP_MotorControl_CmdRun()
Heading3 - 2.5.17 BSP_MotorControl_CmdSetParam()
Heading3 - 2.5.18 BSP_MotorControl_CmdSoftHiZ()
Heading3 - 2.5.19 BSP_MotorControl_CmdSoftStop()
Heading3 - 2.5.20 BSP_MotorControl_CmdStepClock()
Heading3 - 2.5.21 BSP_MotorControl_ErrorHandler()
Heading3 - 2.5.22 BSP_MotorControl_FetchAndClearAllStatus()
Heading3 - 2.5.23 BSP_MotorControl_FlagInterruptHandler()
Heading3 - 2.5.24 BSP_MotorControl_GetBoardId()
Heading3 - 2.5.25 BSP_MotorControl_GetFetchedStatus()
Heading3 - 2.5.26 BSP_MotorControl_GetFwVersion()
Heading3 - 2.5.27 BSP_MotorControl_GetMark()
Heading3 - 2.5.28 BSP_MotorControl_GetNbDevices()
Heading3 - 2.5.29 BSP_MotorControl_GetPosition()
Heading3 - 2.5.30 BSP_MotorControl_GoHome()
Heading3 - 2.5.31 BSP_MotorControl_GoMark()
Heading3 - 2.5.32 BSP_MotorControl_GoTo()
Heading3 - 2.5.33 BSP_MotorControl_HardStop()
Heading3 - 2.5.34 BSP_MotorControl_Init()
Heading3 - 2.5.35 BSP_MotorControl_IsDeviceBusy()
Heading3 - 2.5.36 BSP_MotorControl_Move()
Heading3 - 2.5.37 BSP_MotorControl_QueueCommands()
Heading3 - 2.5.38 BSP_MotorControl_ReleaseReset()
Heading3 - 2.5.39 BSP_MotorControl_Reset()
Heading3 - 2.5.40 BSP_MotorControl_SelectStepMode()
Heading3 - 2.5.41 BSP_MotorControl_SendQueuedCommands()
Heading3 - 2.5.42 BSP_MotorControl_SetHome()
Heading3 - 2.5.43 BSP_MotorControl_SetMark()
Heading3 - 2.5.44 BSP_MotorControl_StartStepClock()
Heading3 - 2.5.45 BSP_MotorControl_StopStepClock()
Heading3 - 2.5.46 BSP_MotorControl_WaitForAllDevicesNotBusy()
Heading3 - 2.5.47 BSP_MotorControl_WaitWhileActive()
Heading2 - 2.6 Sample application description
Heading1 - 3 System setup guide
Heading2 - 3.1 Hardware description
Heading3 - 3.1.1 STM32 Nucleo platform
Heading3 - 3.1.2 X-NUCLEO-IHM03A1 expansion board
Heading3 - 3.1.3 Miscellaneous HW components
Heading2 - 3.2 Software description
Heading2 - 3.3 Hardware and software setup
Heading3 - 3.3.1 Common setup to drive 1, 2 or 3 motors
Heading3 - 3.3.2 Setup to drive 1 motor
Heading3 - 3.3.3 Setup to drive 2 motors
Heading3 - 3.3.4 Setup to drive 3 motors
Heading1 - 4 Acronyms and abbreviations
Heading1 - 5 Revision history
UM1911 User manual Getting started with the X-CUBE-SPN3 high power stepper motor driver software expansion for STM32Cube Introduction This user manual presents how to use the X-CUBE-SPN3 expansion software within the STM32Cube software environment. Combined with the use of one or several X-NUCLEO- IHM03A1 boards, this software allows an STM32 Nucleo board to control one or more stepper motors. The X-NUCLEO-IHM03A1 high power stepper motor driver expansion board is designed around STMicroelectronics’ powerSTEP01, a system-in-package micro- stepping controller with power MOSFETs. This document does not cover the powerSTEP01 device operation. For this please refer to the powerSTEP01 datasheet “DS9836: System-in-package integrating microstepping controller and 10 A power MOSFETs”, which is available on www.st.com The software is based on STM32Cube technology and expands STM32Cube based packages. July 2015 DocID027992 Rev 1 1/63 www.st.com 63
Contents Contents UM1911 1 2 What is STM32Cube? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 STM32Cube overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 1.1 1.2 STM32Cube architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 X-CUBE-SPN3 software expansion for STM32Cube . . . . . . . . . . . . . . . 7 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 2.1 2.2 2.3 2.4 2.5 Architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 Folder structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 BSP folder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 2.3.1 2.3.2 Projects folder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 Software required resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 APIs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 BSP_MotorControl_AttachBusyInterrupt() . . . . . . . . . . . . . . . . . . . . . . . 13 2.5.1 2.5.2 BSP_MotorControl_AttachErrorHandler() . . . . . . . . . . . . . . . . . . . . . . . 14 BSP_MotorControl_AttachFlagInterrupt() . . . . . . . . . . . . . . . . . . . . . . . 15 2.5.3 BSP_MotorControl_BusyInterruptHandler() . . . . . . . . . . . . . . . . . . . . . 16 2.5.4 2.5.5 BSP_MotorControl_CheckBusyHw() . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 BSP_MotorControl_CheckStatusHw() . . . . . . . . . . . . . . . . . . . . . . . . . . 18 2.5.6 BSP_MotorControl_CmdGetParam() . . . . . . . . . . . . . . . . . . . . . . . . . . 18 2.5.7 2.5.8 BSP_MotorControl_CmdGetStatus() . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 BSP_MotorControl_CmdGoToDir() . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 2.5.9 BSP_MotorControl_CmdGoUntil() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 2.5.10 2.5.11 BSP_MotorControl_CmdHardHiZ() . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 BSP_MotorControl_CmdNop() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 2.5.12 BSP_MotorControl_CmdReleaseSw() . . . . . . . . . . . . . . . . . . . . . . . . . . 23 2.5.13 2.5.14 BSP_MotorControl_CmdResetDevice() . . . . . . . . . . . . . . . . . . . . . . . . 24 BSP_MotorControl_CmdResetPos() . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 2.5.15 BSP_MotorControl_CmdRun() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 2.5.16 2.5.17 BSP_MotorControl_CmdSetParam() . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 BSP_MotorControl_CmdSoftHiZ() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 2.5.18 BSP_MotorControl_CmdSoftStop() . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 2.5.19 2.5.20 BSP_MotorControl_CmdStepClock() . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 BSP_MotorControl_ErrorHandler() . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 2.5.21 2.5.22 BSP_MotorControl_FetchAndClearAllStatus() . . . . . . . . . . . . . . . . . . . 31 2/63 DocID027992 Rev 1
UM1911 Contents 2.5.23 BSP_MotorControl_FlagInterruptHandler() . . . . . . . . . . . . . . . . . . . . . . 31 2.5.24 BSP_MotorControl_GetBoardId() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 2.5.25 BSP_MotorControl_GetFetchedStatus() . . . . . . . . . . . . . . . . . . . . . . . . 33 2.5.26 BSP_MotorControl_GetFwVersion() . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 2.5.27 BSP_MotorControl_GetMark() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 2.5.28 BSP_MotorControl_GetNbDevices() . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 2.5.29 BSP_MotorControl_GetPosition() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36 2.5.30 BSP_MotorControl_GoHome() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36 2.5.31 BSP_MotorControl_GoMark() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37 2.5.32 BSP_MotorControl_GoTo() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38 2.5.33 BSP_MotorControl_HardStop() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 2.5.34 BSP_MotorControl_Init() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 2.5.35 BSP_MotorControl_IsDeviceBusy() . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40 2.5.36 BSP_MotorControl_Move() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 2.5.37 BSP_MotorControl_QueueCommands() . . . . . . . . . . . . . . . . . . . . . . . . 42 2.5.38 BSP_MotorControl_ReleaseReset() . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 2.5.39 BSP_MotorControl_Reset() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44 2.5.40 BSP_MotorControl_SelectStepMode() . . . . . . . . . . . . . . . . . . . . . . . . . 44 2.5.41 BSP_MotorControl_SendQueuedCommands() . . . . . . . . . . . . . . . . . . . 45 2.5.42 BSP_MotorControl_SetHome() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46 2.5.43 BSP_MotorControl_SetMark() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 2.5.44 BSP_MotorControl_StartStepClock() . . . . . . . . . . . . . . . . . . . . . . . . . . . 48 2.5.45 BSP_MotorControl_StopStepClock() . . . . . . . . . . . . . . . . . . . . . . . . . . . 48 2.5.46 BSP_MotorControl_WaitForAllDevicesNotBusy() . . . . . . . . . . . . . . . . . 49 2.5.47 BSP_MotorControl_WaitWhileActive() . . . . . . . . . . . . . . . . . . . . . . . . . . 50 Sample application description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 2.6 3 System setup guide . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52 Hardware description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52 3.1 STM32 Nucleo platform . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52 3.1.1 X-NUCLEO-IHM03A1 expansion board . . . . . . . . . . . . . . . . . . . . . . . . 52 3.1.2 3.1.3 Miscellaneous HW components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 Software description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 3.2 3.3 Hardware and software setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 3.3.1 Common setup to drive 1, 2 or 3 motors . . . . . . . . . . . . . . . . . . . . . . . . 54 Setup to drive 1 motor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54 3.3.2 3.3.3 Setup to drive 2 motors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55 DocID027992 Rev 1 3/63 63
Contents 4 5 UM1911 3.3.4 Setup to drive 3 motors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58 Acronyms and abbreviations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61 Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62 4/63 DocID027992 Rev 1
UM1911 1 1.1 What is STM32Cube? What is STM32Cube? STM32Cube overview The STM32Cube™ initiative was originated by STMicroelectronics to ease developers’ life by reducing development effort, time and cost. STM32Cube covers the STM32 portfolio. STM32Cube version 1.x includes: • The STM32CubeMX, a graphical software configuration tool that allows the generation of C initialization code using graphical wizards A comprehensive embedded software platform, delivered per series (such as STM32CubeF4 for the STM32F4 series) The STM32Cube HAL, an STM32 abstraction layer embedded software, which ensures maximized portability across the STM32 portfolio A consistent set of middleware components such as RTOS, USB, TCP/IP, graphics All embedded software utilities with a full set of examples • • • • Information about the STM32Cube is available at: http://www.st.com/stm32cube. 1.2 STM32Cube architecture The STM32Cube firmware solution is built on three independent levels that can easily interact with each other, as shown in the diagram below: Figure 1. Firmware architecture DocID027992 Rev 1 5/63 63
What is STM32Cube? UM1911 Level 0: This level is divided into three sub-layers: • Board support package (BSP): this layer offers a set of APIs relative to the hardware components in the hardware boards (audio codec, IO expander, touchscreen, SRAM driver, LCD drivers, etc.) and is composed of two parts: – Component: the driver relative to the external device on the board and not related to the STM32. The component driver provides specific APIs to the BSP driver external components and could be portable to any other board. BSP driver: permits linking of the component driver to a specific board and provides a set of user-friendly APIs. The API naming rule is BSP_FUNCT_Action(): ex. BSP_LED_Init(),BSP_LED_On() – It’s based on modular architecture allowing easy porting to any hardware simply by implementing the low level routines. • Hardware abstraction layer (HAL): this layer provides the low level drivers and the hardware interfacing methods to interact with the upper layers (application, libraries and stacks). It provides generic, multi-instance and functionality-oriented APIs which permit offloading of the user’s application implementation by providing a ready-to-use process. For example, for the communication peripherals (I²S, UART, etc.) it provides APIs that allow initialization and configuration of the peripheral, management of data transfer based on polling, interrupt or DMA processes, and management of communication errors that may arise during communication. The HAL driver APIs are split into two categories: generic APIs which provide common and generic functions to all the STM32 series, and extension APIs which provides customized functions for a specific family or a specific part number. Basic peripheral usage examples: this layer encloses the examples build over the STM32 peripheral using only the HAL and BSP resources. • • Level 1: This level is divided into two sub-layers: • Middleware components: set of libraries covering USB host and device libraries STemWin, FreeRTOS, FatFS, LwIP and PolarSSL. Horizontal interaction between the components of this layer is done directly by calling the feature APIs while the vertical interaction with the low level drivers is done through specific callbacks and static macros implemented in the library system call interface. For example, the FatFs implements the disk I/O driver to access the microSD drive or the USB mass storage class. Examples based on the middleware components: each middleware component comes with one or more examples (also called Applications) showing how to use it. Integration examples that use several middleware components are provided as well. Level 2: This level is composed of a single layer which is a global real-time and graphical demonstration based on the middleware service layer, the low level abstraction layer and the basic peripheral usage applications for board-based functionalities. 6/63 DocID027992 Rev 1
UM1911 2 2.1 X-CUBE-SPN3 software expansion for STM32Cube X-CUBE-SPN3 software expansion for STM32Cube Overview X-CUBE-SPN3 is a software package that expands the functionality provided by STM32Cube. The key features of the package are: • • • • • powerSTEP01 read/write registers Nucleo and expansion board configuration (GPIOs, PWMs, IRQs, etc.) Application commands FLAG and BUSY interrupt handling (alarm reporting) Daisy chain handling The registers allow the user to easily: • set or monitor the motor positions • set home position and mark another position • set minimum and maximum speed • monitor current speed • set acceleration and deceleration • set parameters for voltage mode driving • read the ADCIN voltage • set the overcurrent threshold • set the step mode and control method • enable/disable alarms • set current control parameters for gate driving • configure various operating options • read system status The application commands allow the user to easily: • • • • handle micro-stepping (up to 1/128) handle step-clock perform various positioning, moves and stops get system status When starting the powerSTEP01 driver, the user specifies the number of powerSTEP01 devices connected to the STM32 Nucleo board (i.e. the number of X-NUCLEO-IHM03A1 expansion boards). Once set, the number of devices must not be changed. Depending on the number of devices, the driver: • • • • • sets up the required GPIOs to handle the motor direction and FLAG and BUSY interrupts starts the SPI driver to communicate with the powerSTEP01 devices releases the reset of each of the powerSTEP01 devices disables the power bridge and clears the status flags of the powerSTEP01 devices loads the registers of each powerSTEP01 device with the predefined values from “powerstep01_target_config.h”, in order to program speed profile boundaries, step mode, voltage or current mode, current decay settings, overcurrent protection, etc. DocID027992 Rev 1 7/63 63
X-CUBE-SPN3 software expansion for STM32Cube UM1911 Once the initialization is done, the user can modify the powerSTEP01 registers as desired. Most of the functions of the driver take a device ID (from 0 to 254) as input parameter. It gives the user the possibility to specify which of the device configurations to modify. The user can also write callback functions and attach them to: • the flag interrupt handler depending on the actions to perform when an alarms is reported (read the flags, clear and read the flags, etc.) the busy interrupt handler which is called each time the busy pin position is changed the error handler which is called by the library when it reports an error. • • Then, the user can request the movement of one or several motors (still using the principle of device ID). This request can be to: • • • • • move for a given number of steps in a specified direction go to a specific position run until reception of a new instruction go at a constant speed until an external switch is closed triggering a soft stop go at minimum speed until an external switch is opened triggering a hard stop The speed profile is completely handled by the powerstep01. The motor starts moving by using the programmed minimum speed (set in MIN_SPEED register). At each step, the speed is increased using the acceleration value (ACC register). If the target position of a motion command is far enough, the motor will perform a trapezoidal move: • • • • accelerating phase using the device acceleration parameter steady phase where the motor turns at maximum speed decelerating phase using the device deceleration parameter stop at the targeted position Otherwise, if the target position does not allow it to reach the max speed, the motor will perform a triangular move: • • • accelerating phase using the device acceleration parameter decelerating phase using the device deceleration parameter stop at the targeted position A motion command can be stopped at any moment: • either by a soft stop or softHiz, which progressively decreases the speed using the deceleration parameter. Once the minimum speed is reached, the motor is stopped. or by a hard stop or hardHiz command which immediately stops the motor. • When the motor is stopped using the softHiz or hardHiz command, the power bridge is automatically disabled. To avoid sending a new command to a device before the completion of the previous one, the driver offers a Powerstep01_WaitWhileActive() command which locks program execution until the motor stops moving. The library also offers the possibility to change the step mode (from full step until 1/128 micro-step mode) for a given device. When the step mode is changed, the current position (ABS_POSITION register) is automatically reset. 8/63 DocID027992 Rev 1
分享到:
收藏