Library to handle the X_NUCLEO_IHM02A1 Motor Control Expansion Board based on the L6470 component.

Dependencies:   X_NUCLEO_COMMON ST_INTERFACES

Dependents:   HelloWorld_IHM02A1 ConcorsoFinal HelloWorld_IHM02A1_mbedOS HelloWorld_IHM02A1-Serialinterpreter ... more

Fork of X_NUCLEO_IHM02A1 by ST Expansion SW Team

Motor Control Library

Introduction

Library to handle the X-NUCLEO-IHM02A1 Motor Control Expansion Board based on the the L6470 component.

Daisy-Chain Configuration

The two L6470 components mounted on this board are connected in daisy-chain configuration. This board can be stacked up to four times so that the eight L6470 components will be connected two-by-two in daisy-chain configuration.

Concerning the SSEL pin of the SPI communication, each expansion board must be in one of the following configuration:

  • SB_23 resistor connected only: SSEL on pin A2;
  • SB_7 resistor connected only: SSEL on pin D2;
  • SB_8 resistor connected only: SSEL on pin D10;
  • SB_9 resistor connected only: SSEL on pin D5.

Arduino Connector Compatibility Warning

X-NUCLEO-IHM02A1 is Arduino compatible with one exception: instead of using D13 pin to drive the SPI clock, it uses D3 pin, hence the default configuration for this library is with the SPI clock on D3 pin.

To be fully Arduino compatible the following patch is required:

  • to remove the SB34 resistor;
  • to solder the SB12 resistor.

Alternatively, you can route the Nucleo board’s D13 pin directly to the expansion board’s D3 pin with a wire. In case you patch your expansion board or route the pin, the SPI clock will be driven on D13 pin rather than on D3 pin, and you have also to initialize the sclk PinName variable with D13 rather than D3. This patch is known to be required, for example, on the following boards: NUCLEO-F103RB, NUCLEO-F302RB, NUCLEO-F411RE, and NUCLEO-F429ZI.

If you use D13 pin for the SPI clock, please be aware that on STM32 Nucleo boards you may not drive the LED, otherwise you will get a conflict: the LED on STM32 Nucleo boards is connected to the D13 pin.

Example Applications

Revision:
14:e614697ebf34
Parent:
11:1aca63b2f034
--- a/Components/Common/microstepping_motor.h	Tue Jan 19 16:07:00 2016 +0000
+++ b/Components/Common/microstepping_motor.h	Tue Feb 09 16:01:30 2016 +0000
@@ -1,42 +1,44 @@
 /**
-  ******************************************************************************
-  * @file    microstepping_motor.h
-  * @author  IPD SYSTEM LAB & TECH MKTG
-  * @version V0.0.1
-  * @date    04-June-2015
-  * @brief   This file contains all the functions prototypes for the microstepping
-  *          motor driver with motion engine.   
-  ******************************************************************************
-  * @attention
-  *
-  * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
-  *
-  * Redistribution and use in source and binary forms, with or without modification,
-  * are permitted provided that the following conditions are met:
-  *   1. Redistributions of source code must retain the above copyright notice,
-  *      this list of conditions and the following disclaimer.
-  *   2. Redistributions in binary form must reproduce the above copyright notice,
-  *      this list of conditions and the following disclaimer in the documentation
-  *      and/or other materials provided with the distribution.
-  *   3. Neither the name of STMicroelectronics nor the names of its contributors
-  *      may be used to endorse or promote products derived from this software
-  *      without specific prior written permission.
-  *
-  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-  *
-  ******************************************************************************
-  */ 
+ ******************************************************************************
+ * @file    microstepping_motor.h
+ * @author  IPD SYSTEM LAB & TECH MKTG
+ * @version V0.0.1
+ * @date    04-June-2015
+ * @brief   This file contains all the functions prototypes for the microstepping
+ *          motor driver with motion engine.   
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *   1. Redistributions of source code must retain the above copyright notice,
+ *      this list of conditions and the following disclaimer.
+ *   2. Redistributions in binary form must reproduce the above copyright notice,
+ *      this list of conditions and the following disclaimer in the documentation
+ *      and/or other materials provided with the distribution.
+ *   3. Neither the name of STMicroelectronics nor the names of its contributors
+ *      may be used to endorse or promote products derived from this software
+ *      without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ ******************************************************************************
+ */ 
+
 
 /* Define to prevent recursive inclusion -------------------------------------*/
+
 #ifndef __MICROSTEPPINGMOTOR_H
 #define __MICROSTEPPINGMOTOR_H
 
@@ -44,10 +46,15 @@
  extern "C" {
 #endif 
 
+
 /* Includes ------------------------------------------------------------------*/
+
 #include <stdint.h>
 #include "component.h"
    
+
+/* Types ---------------------------------------------------------------------*/
+
 /** @addtogroup BSP
   * @{
   */
@@ -92,7 +99,7 @@
   L6470_STEP_MODE_ID,           //!< Step mode
   L6470_ALARM_EN_ID,            //!< Alarm enable
   L6470_CONFIG_ID,              //!< IC configuration
-  L6470_STATUS_ID               //!< Status, (the reset value is according to startup conditions)
+  L6470_STATUS_ID               //!< Status, (the reset value is according to startup conditions)  
 } eL6470_RegId_t;
 
 /**
@@ -305,9 +312,9 @@
   uint16_t  STATUS;                 //!< Status Register
 } StepperMotorRegister_t;
 
-/**
-  * @brief Stepper Motor Driver Structure
-  */
+/** 
+ * @brief  MICROSTEPPING_MOTOR driver virtual table structure definition.
+ */
 typedef struct
 {
   /* ACTION ----------------------------------------------------------------*
@@ -319,12 +326,12 @@
    * specified exactly in the given way.                                    *
    *                                                                        *
    * Example:                                                               *
-   *   DrvStatusTypeDef (*Init)(void *handle, void *init);                  *
-   *   DrvStatusTypeDef (*ReadID)(void *handle, uint8_t *id);               *
+   *   Status_t (*Init)   (void *handle, void *init);                       *
+   *   Status_t (*ReadID) (void *handle, uint8_t *id);                      *
    *------------------------------------------------------------------------*/
   /* Generic */
-  DrvStatusTypeDef (*Init)(void *handle, void *init);
-  DrvStatusTypeDef (*ReadID)(void *handle, uint8_t *id);
+  Status_t (*Init)(void *handle, void *init);
+  Status_t (*ReadID)(void *handle, uint8_t *id);
   
   /* ACTION ----------------------------------------------------------------*
    * Declare here the component's specific functions.                       *
@@ -332,7 +339,7 @@
    * Do not specify any function if not required.                           *
    *                                                                        *
    * Example:                                                               *
-   *   DrvStatusTypeDef (*GetValue)(void *handle, float *pfData);           *
+   *   Status_t (*GetValue) (void *handle, float *f);                       *
    *------------------------------------------------------------------------*/
   /* Specific */
   void     (*SetParam)(void *handle, eL6470_RegId_t L6470_RegId, uint32_t Value);
@@ -400,7 +407,8 @@
   uint8_t  (*mA_2_OcdTh)(void *handle, float mA);
   float    (*StallTh_2_mA)(void *handle, uint8_t StallTh);
   uint8_t  (*mA_2_StallTh)(void *handle, float mA);
-} MICROSTEPPING_MOTOR_DrvVTableTypeDef;
+  uint32_t (*ExtractReturnedData)(void *handle, uint8_t* pL6470_DaisyChainSpiRxStruct, uint8_t LengthByte);
+} MICROSTEPPING_MOTOR_VTable_t;
 
 /**
   * @brief Stepper Motor Board Driver Structure
@@ -427,7 +435,7 @@
   uint16_t (*GetStatus)(uint8_t, uint8_t);
   uint8_t  (*CheckStatusRegisterFlag)(uint8_t, uint8_t, uint8_t);
   uint8_t* (*PerformPreparedApplicationCommand)(uint8_t);
-} MICROSTEPPING_MOTOR_EB_DrvVTableTypeDef;
+} MICROSTEPPING_MOTOR_EB_VTable_t;
 
 /**
   * @brief  Stepper Motor Handle Structure
@@ -435,7 +443,8 @@
 typedef struct __StepperMotorDriver_HandleTypeDef
 {
   uint8_t DaisyChainPosition;
-  MICROSTEPPING_MOTOR_DrvVTableTypeDef *Command;
+  void (*Config)(void*);
+  MICROSTEPPING_MOTOR_VTable_t *Command;
 } StepperMotorDriverHandle_t;
 
 /**
@@ -444,7 +453,8 @@
 typedef struct __StepperMotorBoard_HandleTypeDef
 {
   uint8_t StackedPosition;
-  MICROSTEPPING_MOTOR_EB_DrvVTableTypeDef *Command;
+  void (*Config)(void*);
+  MICROSTEPPING_MOTOR_EB_VTable_t *Command;
   StepperMotorDriverHandle_t *StepperMotorDriverHandle[2];
   uint8_t (*Select)(uint8_t);
 } StepperMotorBoardHandle_t;