X-CUBE-SPN1-20150128 example source code for one motor compiled under mbed. Tested OK on Nucleo F401. l6474.cpp is modified from original with defines in l6474_target_config.h to select the original behaviour (motor de-energised when halted), or new mode to continue powering with a (reduced) current in the coils (braking/position hold capability). On F401 avoid using mbed's InterruptIn on pins 10-15 (any port). Beware of other conflicts! L0 & F0 are included but untested.

Dependencies:   mbed

Committer:
gregeric
Date:
Tue Oct 13 10:46:01 2015 +0000
Revision:
6:19c1b4a04c24
Parent:
0:b9444a40a999
Ensure bridge is disabled before resetting the L6474.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
gregeric 0:b9444a40a999 1 /**
gregeric 0:b9444a40a999 2 ******************************************************************************
gregeric 0:b9444a40a999 3 * @file motorcontrol.h
gregeric 0:b9444a40a999 4 * @author IPC Rennes
gregeric 0:b9444a40a999 5 * @version V1.0.0
gregeric 0:b9444a40a999 6 * @date 12-November-2014
gregeric 0:b9444a40a999 7 * @brief This file provides common definitions for motor control
gregeric 0:b9444a40a999 8 ******************************************************************************
gregeric 0:b9444a40a999 9 * @attention
gregeric 0:b9444a40a999 10 *
gregeric 0:b9444a40a999 11 * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
gregeric 0:b9444a40a999 12 *
gregeric 0:b9444a40a999 13 * Redistribution and use in source and binary forms, with or without modification,
gregeric 0:b9444a40a999 14 * are permitted provided that the following conditions are met:
gregeric 0:b9444a40a999 15 * 1. Redistributions of source code must retain the above copyright notice,
gregeric 0:b9444a40a999 16 * this list of conditions and the following disclaimer.
gregeric 0:b9444a40a999 17 * 2. Redistributions in binary form must reproduce the above copyright notice,
gregeric 0:b9444a40a999 18 * this list of conditions and the following disclaimer in the documentation
gregeric 0:b9444a40a999 19 * and/or other materials provided with the distribution.
gregeric 0:b9444a40a999 20 * 3. Neither the name of STMicroelectronics nor the names of its contributors
gregeric 0:b9444a40a999 21 * may be used to endorse or promote products derived from this software
gregeric 0:b9444a40a999 22 * without specific prior written permission.
gregeric 0:b9444a40a999 23 *
gregeric 0:b9444a40a999 24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
gregeric 0:b9444a40a999 25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
gregeric 0:b9444a40a999 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
gregeric 0:b9444a40a999 27 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
gregeric 0:b9444a40a999 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
gregeric 0:b9444a40a999 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
gregeric 0:b9444a40a999 30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
gregeric 0:b9444a40a999 31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
gregeric 0:b9444a40a999 32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
gregeric 0:b9444a40a999 33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
gregeric 0:b9444a40a999 34 *
gregeric 0:b9444a40a999 35 ******************************************************************************
gregeric 0:b9444a40a999 36 */
gregeric 0:b9444a40a999 37
gregeric 0:b9444a40a999 38
gregeric 0:b9444a40a999 39 /* Define to prevent recursive inclusion -------------------------------------*/
gregeric 0:b9444a40a999 40 #ifndef __MOTOR_CONTROL_H
gregeric 0:b9444a40a999 41 #define __MOTOR_CONTROL_H
gregeric 0:b9444a40a999 42
gregeric 0:b9444a40a999 43 #ifdef __cplusplus
gregeric 0:b9444a40a999 44 extern "C" {
gregeric 0:b9444a40a999 45 #endif
gregeric 0:b9444a40a999 46
gregeric 0:b9444a40a999 47 /* Includes ------------------------------------------------------------------*/
gregeric 0:b9444a40a999 48 #include "motor.h"
gregeric 0:b9444a40a999 49
gregeric 0:b9444a40a999 50 /** @addtogroup BSP
gregeric 0:b9444a40a999 51 * @{
gregeric 0:b9444a40a999 52 */
gregeric 0:b9444a40a999 53
gregeric 0:b9444a40a999 54 /** @addtogroup MOTOR_CONTROL
gregeric 0:b9444a40a999 55 * @{
gregeric 0:b9444a40a999 56 */
gregeric 0:b9444a40a999 57
gregeric 0:b9444a40a999 58 /** @defgroup MOTOR_CONTROL_Exported_Types
gregeric 0:b9444a40a999 59 * @{
gregeric 0:b9444a40a999 60 */
gregeric 0:b9444a40a999 61
gregeric 0:b9444a40a999 62
gregeric 0:b9444a40a999 63
gregeric 0:b9444a40a999 64 /**
gregeric 0:b9444a40a999 65 * @}
gregeric 0:b9444a40a999 66 */
gregeric 0:b9444a40a999 67
gregeric 0:b9444a40a999 68 /** @defgroup MOTOR_CONTROL_Exported_Constants
gregeric 0:b9444a40a999 69 * @{
gregeric 0:b9444a40a999 70 */
gregeric 0:b9444a40a999 71 ///Motor control board id for L6474
gregeric 0:b9444a40a999 72 #define BSP_MOTOR_CONTROL_BOARD_ID_L6474 (6474)
gregeric 0:b9444a40a999 73 ///Motor control board id for Powerstep01
gregeric 0:b9444a40a999 74 #define BSP_MOTOR_CONTROL_BOARD_ID_POWERSTEP01 (0001)
gregeric 0:b9444a40a999 75
gregeric 0:b9444a40a999 76 /**
gregeric 0:b9444a40a999 77 * @}
gregeric 0:b9444a40a999 78 */
gregeric 0:b9444a40a999 79
gregeric 0:b9444a40a999 80
gregeric 0:b9444a40a999 81 /** @defgroup MOTOR_CONTROL_Exported_Macros
gregeric 0:b9444a40a999 82 * @{
gregeric 0:b9444a40a999 83 */
gregeric 0:b9444a40a999 84 #if defined ( __GNUC__ )
gregeric 0:b9444a40a999 85 #ifndef __weak
gregeric 0:b9444a40a999 86 #define __weak __attribute__((weak))
gregeric 0:b9444a40a999 87 #endif /* __weak */
gregeric 0:b9444a40a999 88 #endif /* __GNUC__ */
gregeric 0:b9444a40a999 89 /**
gregeric 0:b9444a40a999 90 * @}
gregeric 0:b9444a40a999 91 */
gregeric 0:b9444a40a999 92
gregeric 0:b9444a40a999 93 /** @defgroup MOTOR_CONTROL_Weak_Function_Prototypes
gregeric 0:b9444a40a999 94 * @{
gregeric 0:b9444a40a999 95 */
gregeric 0:b9444a40a999 96 __weak motorDrv_t* L6474_GetMotorHandle(void);
gregeric 0:b9444a40a999 97 __weak motorDrv_t* Powerstep01_GetMotorHandle(void);
gregeric 0:b9444a40a999 98 /**
gregeric 0:b9444a40a999 99 * @}
gregeric 0:b9444a40a999 100 */
gregeric 0:b9444a40a999 101
gregeric 0:b9444a40a999 102 /** @defgroup MOTOR_CONTROL_Exported_Functions
gregeric 0:b9444a40a999 103 * @{
gregeric 0:b9444a40a999 104 */
gregeric 0:b9444a40a999 105 void BSP_MotorControl_AttachErrorHandler(void (*callback)(uint16_t));
gregeric 0:b9444a40a999 106 void BSP_MotorControl_AttachFlagInterrupt(void (*callback)(void));
gregeric 0:b9444a40a999 107 void BSP_MotorControl_AttachBusyInterrupt(void (*callback)(void));
gregeric 0:b9444a40a999 108 void BSP_MotorControl_ErrorHandler(uint16_t error);
gregeric 0:b9444a40a999 109 void BSP_MotorControl_Init(uint16_t id, uint8_t nbDevices);
gregeric 0:b9444a40a999 110 void BSP_MotorControl_FlagInterruptHandler(void);
gregeric 0:b9444a40a999 111 uint16_t BSP_MotorControl_GetAcceleration(uint8_t deviceId);
gregeric 0:b9444a40a999 112 uint16_t BSP_MotorControl_GetBoardId(void);
gregeric 0:b9444a40a999 113 uint16_t BSP_MotorControl_GetCurrentSpeed(uint8_t deviceId);
gregeric 0:b9444a40a999 114 uint16_t BSP_MotorControl_GetDeceleration(uint8_t deviceId);
gregeric 0:b9444a40a999 115 motorState_t BSP_MotorControl_GetDeviceState(uint8_t deviceId);
gregeric 0:b9444a40a999 116 uint8_t BSP_MotorControl_GetFwVersion(void);
gregeric 0:b9444a40a999 117 int32_t BSP_MotorControl_GetMark(uint8_t deviceId);
gregeric 0:b9444a40a999 118 uint16_t BSP_MotorControl_GetMaxSpeed(uint8_t deviceId);
gregeric 0:b9444a40a999 119 uint16_t BSP_MotorControl_GetMinSpeed(uint8_t deviceId);
gregeric 0:b9444a40a999 120 int32_t BSP_MotorControl_GetPosition(uint8_t deviceId);
gregeric 0:b9444a40a999 121 void BSP_MotorControl_GoHome(uint8_t deviceId);
gregeric 0:b9444a40a999 122 void BSP_MotorControl_GoMark(uint8_t deviceId);
gregeric 0:b9444a40a999 123 void BSP_MotorControl_GoTo(uint8_t deviceId, int32_t targetPosition);
gregeric 0:b9444a40a999 124 void BSP_MotorControl_HardStop(uint8_t deviceId);
gregeric 0:b9444a40a999 125 void BSP_MotorControl_Move(uint8_t deviceId, motorDir_t direction, uint32_t stepCount);
gregeric 0:b9444a40a999 126 void BSP_MotorControl_ResetAllDevices(void);
gregeric 0:b9444a40a999 127 void BSP_MotorControl_Run(uint8_t deviceId, motorDir_t direction);
gregeric 0:b9444a40a999 128 bool BSP_MotorControl_SetAcceleration(uint8_t deviceId,uint16_t newAcc);
gregeric 0:b9444a40a999 129 bool BSP_MotorControl_SetDeceleration(uint8_t deviceId, uint16_t newDec);
gregeric 0:b9444a40a999 130 void BSP_MotorControl_SetHome(uint8_t deviceId);
gregeric 0:b9444a40a999 131 void BSP_MotorControl_SetMark(uint8_t deviceId);
gregeric 0:b9444a40a999 132 bool BSP_MotorControl_SetMaxSpeed(uint8_t deviceId, uint16_t newMaxSpeed);
gregeric 0:b9444a40a999 133 bool BSP_MotorControl_SetMinSpeed(uint8_t deviceId, uint16_t newMinSpeed);
gregeric 0:b9444a40a999 134 bool BSP_MotorControl_SoftStop(uint8_t deviceId);
gregeric 0:b9444a40a999 135 void BSP_MotorControl_StepClockHandler(uint8_t deviceId);
gregeric 0:b9444a40a999 136 void BSP_MotorControl_WaitWhileActive(uint8_t deviceId);
gregeric 0:b9444a40a999 137 void BSP_MotorControl_CmdDisable(uint8_t deviceId);
gregeric 0:b9444a40a999 138 void BSP_MotorControl_CmdEnable(uint8_t deviceId);
gregeric 0:b9444a40a999 139 uint32_t BSP_MotorControl_CmdGetParam(uint8_t deviceId, uint32_t param);
gregeric 0:b9444a40a999 140 uint16_t BSP_MotorControl_CmdGetStatus(uint8_t deviceId);
gregeric 0:b9444a40a999 141 void BSP_MotorControl_CmdNop(uint8_t deviceId);
gregeric 0:b9444a40a999 142 void BSP_MotorControl_CmdSetParam(uint8_t deviceId, uint32_t param, uint32_t value);
gregeric 0:b9444a40a999 143 uint16_t BSP_MotorControl_ReadStatusRegister(uint8_t deviceId);
gregeric 0:b9444a40a999 144 void BSP_MotorControl_ReleaseReset(void) ;
gregeric 0:b9444a40a999 145 void BSP_MotorControl_Reset(void);
gregeric 0:b9444a40a999 146 void BSP_MotorControl_SelectStepMode(uint8_t deviceId, motorStepMode_t stepMod);
gregeric 0:b9444a40a999 147 void BSP_MotorControl_SetDirection(uint8_t deviceId, motorDir_t dir);
gregeric 0:b9444a40a999 148 void BSP_MotorControl_CmdGoToDir(uint8_t deviceId, motorDir_t dir, int32_t abs_pos);
gregeric 0:b9444a40a999 149 uint8_t BSP_MotorControl_CheckBusyHw(void);
gregeric 0:b9444a40a999 150 uint8_t BSP_MotorControl_CheckStatusHw(void);
gregeric 0:b9444a40a999 151 void BSP_MotorControl_CmdGoUntil(uint8_t deviceId, motorAction_t action, motorDir_t dir, uint32_t speed);
gregeric 0:b9444a40a999 152 void BSP_MotorControl_CmdHardHiZ(uint8_t deviceId);
gregeric 0:b9444a40a999 153 void BSP_MotorControl_CmdReleaseSw(uint8_t deviceId, motorAction_t action, motorDir_t dir);
gregeric 0:b9444a40a999 154 void BSP_MotorControl_CmdResetDevice(uint8_t deviceId);
gregeric 0:b9444a40a999 155 void BSP_MotorControl_CmdResetPos(uint8_t deviceId);
gregeric 0:b9444a40a999 156 void BSP_MotorControl_CmdRun(uint8_t deviceId, motorDir_t dir, uint32_t speed);
gregeric 0:b9444a40a999 157 void BSP_MotorControl_CmdSoftHiZ(uint8_t deviceId);
gregeric 0:b9444a40a999 158 void BSP_MotorControl_CmdStepClock(uint8_t deviceId, motorDir_t dir);
gregeric 0:b9444a40a999 159 void BSP_MotorControl_FetchAndClearAllStatus(void);
gregeric 0:b9444a40a999 160 uint16_t BSP_MotorControl_GetFetchedStatus(uint8_t deviceId);
gregeric 0:b9444a40a999 161 uint8_t BSP_MotorControl_GetNbDevices(void);
gregeric 0:b9444a40a999 162 bool BSP_MotorControl_IsDeviceBusy(uint8_t deviceId);
gregeric 0:b9444a40a999 163 void BSP_MotorControl_SendQueuedCommands(void);
gregeric 0:b9444a40a999 164 void BSP_MotorControl_QueueCommands(uint8_t deviceId, uint8_t param, uint32_t value);
gregeric 0:b9444a40a999 165 void BSP_MotorControl_WaitForAllDevicesNotBusy(void);
gregeric 0:b9444a40a999 166 void BSP_MotorControl_BusyInterruptHandler(void);
gregeric 0:b9444a40a999 167 void BSP_MotorControl_CmdSoftStop(uint8_t deviceId);
gregeric 0:b9444a40a999 168 /**
gregeric 0:b9444a40a999 169 * @}
gregeric 0:b9444a40a999 170 */
gregeric 0:b9444a40a999 171
gregeric 0:b9444a40a999 172 /**
gregeric 0:b9444a40a999 173 * @}
gregeric 0:b9444a40a999 174 */
gregeric 0:b9444a40a999 175
gregeric 0:b9444a40a999 176 /**
gregeric 0:b9444a40a999 177 * @}
gregeric 0:b9444a40a999 178 */
gregeric 0:b9444a40a999 179
gregeric 0:b9444a40a999 180 #ifdef __cplusplus
gregeric 0:b9444a40a999 181 }
gregeric 0:b9444a40a999 182 #endif
gregeric 0:b9444a40a999 183
gregeric 0:b9444a40a999 184 #endif /* __MOTOR_CONTROL_H */
gregeric 0:b9444a40a999 185
gregeric 0:b9444a40a999 186
gregeric 0:b9444a40a999 187
gregeric 0:b9444a40a999 188 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/