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 Multi/Examples/MotionControl/IHM01A1_ExampleFor1Motor/Src/stm32f4xx_it.c
gregeric 0:b9444a40a999 4 * @author IPC Rennes
gregeric 0:b9444a40a999 5 * @version V1.5.0
gregeric 0:b9444a40a999 6 * @date November 12, 2014
gregeric 0:b9444a40a999 7 * @brief Main Interrupt Service Routines.
gregeric 0:b9444a40a999 8 * This file provides template for all exceptions handler and
gregeric 0:b9444a40a999 9 * peripherals interrupt service routine.
gregeric 0:b9444a40a999 10 ******************************************************************************
gregeric 0:b9444a40a999 11 * @attention
gregeric 0:b9444a40a999 12 *
gregeric 0:b9444a40a999 13 * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
gregeric 0:b9444a40a999 14 *
gregeric 0:b9444a40a999 15 * Redistribution and use in source and binary forms, with or without modification,
gregeric 0:b9444a40a999 16 * are permitted provided that the following conditions are met:
gregeric 0:b9444a40a999 17 * 1. Redistributions of source code must retain the above copyright notice,
gregeric 0:b9444a40a999 18 * this list of conditions and the following disclaimer.
gregeric 0:b9444a40a999 19 * 2. Redistributions in binary form must reproduce the above copyright notice,
gregeric 0:b9444a40a999 20 * this list of conditions and the following disclaimer in the documentation
gregeric 0:b9444a40a999 21 * and/or other materials provided with the distribution.
gregeric 0:b9444a40a999 22 * 3. Neither the name of STMicroelectronics nor the names of its contributors
gregeric 0:b9444a40a999 23 * may be used to endorse or promote products derived from this software
gregeric 0:b9444a40a999 24 * without specific prior written permission.
gregeric 0:b9444a40a999 25 *
gregeric 0:b9444a40a999 26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
gregeric 0:b9444a40a999 27 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
gregeric 0:b9444a40a999 28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
gregeric 0:b9444a40a999 29 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
gregeric 0:b9444a40a999 30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
gregeric 0:b9444a40a999 31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
gregeric 0:b9444a40a999 32 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
gregeric 0:b9444a40a999 33 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
gregeric 0:b9444a40a999 34 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
gregeric 0:b9444a40a999 35 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
gregeric 0:b9444a40a999 36 *
gregeric 0:b9444a40a999 37 ******************************************************************************
gregeric 0:b9444a40a999 38 */
gregeric 0:b9444a40a999 39 #ifdef TARGET_STM32F4
gregeric 0:b9444a40a999 40 /* Includes ------------------------------------------------------------------*/
gregeric 0:b9444a40a999 41 #include "mbed.h"
gregeric 0:b9444a40a999 42 #include "stm32f4xx_it.h"
gregeric 0:b9444a40a999 43 #include "motorcontrol.h"
gregeric 0:b9444a40a999 44
gregeric 0:b9444a40a999 45 /** @addtogroup Interrupt_Handlers
gregeric 0:b9444a40a999 46 * @{
gregeric 0:b9444a40a999 47 */
gregeric 0:b9444a40a999 48
gregeric 0:b9444a40a999 49 /* Private typedef -----------------------------------------------------------*/
gregeric 0:b9444a40a999 50 /* Private define ------------------------------------------------------------*/
gregeric 0:b9444a40a999 51 /* Private macro -------------------------------------------------------------*/
gregeric 0:b9444a40a999 52 /* Private variables ---------------------------------------------------------*/
gregeric 0:b9444a40a999 53 extern TIM_HandleTypeDef hTimPwm1;
gregeric 0:b9444a40a999 54 extern TIM_HandleTypeDef hTimPwm2;
gregeric 0:b9444a40a999 55 extern TIM_HandleTypeDef hTimPwm3;
gregeric 0:b9444a40a999 56
gregeric 0:b9444a40a999 57 /* Private function prototypes -----------------------------------------------*/
gregeric 0:b9444a40a999 58 /* Private functions ---------------------------------------------------------*/
gregeric 0:b9444a40a999 59
gregeric 0:b9444a40a999 60
gregeric 0:b9444a40a999 61 /******************************************************************************/
gregeric 0:b9444a40a999 62 /* Cortex-M4 Processor Exceptions Handlers */
gregeric 0:b9444a40a999 63 /******************************************************************************/
gregeric 0:b9444a40a999 64
gregeric 0:b9444a40a999 65 /**
gregeric 0:b9444a40a999 66 * @brief This function handles NMI exception.
gregeric 0:b9444a40a999 67 * @param None
gregeric 0:b9444a40a999 68 * @retval None
gregeric 0:b9444a40a999 69 */
gregeric 0:b9444a40a999 70 void NMI_Handler(void)
gregeric 0:b9444a40a999 71 {
gregeric 0:b9444a40a999 72 }
gregeric 0:b9444a40a999 73
gregeric 0:b9444a40a999 74 /**
gregeric 0:b9444a40a999 75 * @brief This function handles Hard Fault exception.
gregeric 0:b9444a40a999 76 * @param None
gregeric 0:b9444a40a999 77 * @retval None
gregeric 0:b9444a40a999 78 */
gregeric 0:b9444a40a999 79 void HardFault_Handler(void)
gregeric 0:b9444a40a999 80 {
gregeric 0:b9444a40a999 81 /* Go to infinite loop when Hard Fault exception occurs */
gregeric 0:b9444a40a999 82 while (1)
gregeric 0:b9444a40a999 83 {
gregeric 0:b9444a40a999 84 }
gregeric 0:b9444a40a999 85 }
gregeric 0:b9444a40a999 86
gregeric 0:b9444a40a999 87 /**
gregeric 0:b9444a40a999 88 * @brief This function handles Memory Manage exception.
gregeric 0:b9444a40a999 89 * @param None
gregeric 0:b9444a40a999 90 * @retval None
gregeric 0:b9444a40a999 91 */
gregeric 0:b9444a40a999 92 void MemManage_Handler(void)
gregeric 0:b9444a40a999 93 {
gregeric 0:b9444a40a999 94 /* Go to infinite loop when Memory Manage exception occurs */
gregeric 0:b9444a40a999 95 while (1)
gregeric 0:b9444a40a999 96 {
gregeric 0:b9444a40a999 97 }
gregeric 0:b9444a40a999 98 }
gregeric 0:b9444a40a999 99
gregeric 0:b9444a40a999 100 /**
gregeric 0:b9444a40a999 101 * @brief This function handles Bus Fault exception.
gregeric 0:b9444a40a999 102 * @param None
gregeric 0:b9444a40a999 103 * @retval None
gregeric 0:b9444a40a999 104 */
gregeric 0:b9444a40a999 105 void BusFault_Handler(void)
gregeric 0:b9444a40a999 106 {
gregeric 0:b9444a40a999 107 /* Go to infinite loop when Bus Fault exception occurs */
gregeric 0:b9444a40a999 108 while (1)
gregeric 0:b9444a40a999 109 {
gregeric 0:b9444a40a999 110 }
gregeric 0:b9444a40a999 111 }
gregeric 0:b9444a40a999 112
gregeric 0:b9444a40a999 113 /**
gregeric 0:b9444a40a999 114 * @brief This function handles Usage Fault exception.
gregeric 0:b9444a40a999 115 * @param None
gregeric 0:b9444a40a999 116 * @retval None
gregeric 0:b9444a40a999 117 */
gregeric 0:b9444a40a999 118 void UsageFault_Handler(void)
gregeric 0:b9444a40a999 119 {
gregeric 0:b9444a40a999 120 /* Go to infinite loop when Usage Fault exception occurs */
gregeric 0:b9444a40a999 121 while (1)
gregeric 0:b9444a40a999 122 {
gregeric 0:b9444a40a999 123 }
gregeric 0:b9444a40a999 124 }
gregeric 0:b9444a40a999 125
gregeric 0:b9444a40a999 126 /**
gregeric 0:b9444a40a999 127 * @brief This function handles SVCall exception.
gregeric 0:b9444a40a999 128 * @param None
gregeric 0:b9444a40a999 129 * @retval None
gregeric 0:b9444a40a999 130 */
gregeric 0:b9444a40a999 131 void SVC_Handler(void)
gregeric 0:b9444a40a999 132 {
gregeric 0:b9444a40a999 133 }
gregeric 0:b9444a40a999 134
gregeric 0:b9444a40a999 135 /**
gregeric 0:b9444a40a999 136 * @brief This function handles Debug Monitor exception.
gregeric 0:b9444a40a999 137 * @param None
gregeric 0:b9444a40a999 138 * @retval None
gregeric 0:b9444a40a999 139 */
gregeric 0:b9444a40a999 140 void DebugMon_Handler(void)
gregeric 0:b9444a40a999 141 {
gregeric 0:b9444a40a999 142 }
gregeric 0:b9444a40a999 143
gregeric 0:b9444a40a999 144 /**
gregeric 0:b9444a40a999 145 * @brief This function handles PendSVC exception.
gregeric 0:b9444a40a999 146 * @param None
gregeric 0:b9444a40a999 147 * @retval None
gregeric 0:b9444a40a999 148 */
gregeric 0:b9444a40a999 149 void PendSV_Handler(void)
gregeric 0:b9444a40a999 150 {
gregeric 0:b9444a40a999 151 }
gregeric 0:b9444a40a999 152
gregeric 0:b9444a40a999 153 /**
gregeric 0:b9444a40a999 154 * @brief This function handles SysTick Handler.
gregeric 0:b9444a40a999 155 * @param None
gregeric 0:b9444a40a999 156 * @retval None
gregeric 0:b9444a40a999 157 */
gregeric 0:b9444a40a999 158 void SysTick_Handler(void)
gregeric 0:b9444a40a999 159 {
gregeric 0:b9444a40a999 160 HAL_IncTick();
gregeric 0:b9444a40a999 161 }
gregeric 0:b9444a40a999 162
gregeric 0:b9444a40a999 163 /******************************************************************************/
gregeric 0:b9444a40a999 164 /* STM32F4xx Peripherals Interrupt Handlers */
gregeric 0:b9444a40a999 165 /* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */
gregeric 0:b9444a40a999 166 /* available peripheral interrupt handler's name please refer to the startup */
gregeric 0:b9444a40a999 167 /* file (startup_stm32f4xx.s). */
gregeric 0:b9444a40a999 168 /******************************************************************************/
gregeric 0:b9444a40a999 169
gregeric 0:b9444a40a999 170 /**
gregeric 0:b9444a40a999 171 * @brief This function handles interrupt for External lines 10 to 15
gregeric 0:b9444a40a999 172 * @param None
gregeric 0:b9444a40a999 173 * @retval None
gregeric 0:b9444a40a999 174 */
gregeric 0:b9444a40a999 175 void EXTI15_10_IRQHandler(void)
gregeric 0:b9444a40a999 176 {
gregeric 0:b9444a40a999 177 HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_10);
gregeric 0:b9444a40a999 178 }
gregeric 0:b9444a40a999 179
gregeric 0:b9444a40a999 180 /**
gregeric 0:b9444a40a999 181 * @brief This function handles TIM2 interrupt request.
gregeric 0:b9444a40a999 182 * @param None
gregeric 0:b9444a40a999 183 * @retval None
gregeric 0:b9444a40a999 184 */
gregeric 0:b9444a40a999 185 void TIM2_IRQHandler(void)
gregeric 0:b9444a40a999 186 {
gregeric 0:b9444a40a999 187 HAL_TIM_IRQHandler(&hTimPwm2);
gregeric 0:b9444a40a999 188 }
gregeric 0:b9444a40a999 189
gregeric 0:b9444a40a999 190 /**
gregeric 0:b9444a40a999 191 * @brief This function handles TIM3 interrupt request.
gregeric 0:b9444a40a999 192 * @param None
gregeric 0:b9444a40a999 193 * @retval None
gregeric 0:b9444a40a999 194 */
gregeric 0:b9444a40a999 195 void TIM3_IRQHandler(void)
gregeric 0:b9444a40a999 196 {
gregeric 0:b9444a40a999 197 HAL_TIM_IRQHandler(&hTimPwm1);
gregeric 0:b9444a40a999 198 }
gregeric 0:b9444a40a999 199
gregeric 0:b9444a40a999 200 /**
gregeric 0:b9444a40a999 201 * @brief This function handles TIM4 interrupt request.
gregeric 0:b9444a40a999 202 * @param None
gregeric 0:b9444a40a999 203 * @retval None
gregeric 0:b9444a40a999 204 */
gregeric 0:b9444a40a999 205 void TIM4_IRQHandler(void)
gregeric 0:b9444a40a999 206 {
gregeric 0:b9444a40a999 207 HAL_TIM_IRQHandler(&hTimPwm3);
gregeric 0:b9444a40a999 208 }
gregeric 0:b9444a40a999 209 /**
gregeric 0:b9444a40a999 210 * @brief This function handles PPP interrupt request.
gregeric 0:b9444a40a999 211 * @param None
gregeric 0:b9444a40a999 212 * @retval None
gregeric 0:b9444a40a999 213 */
gregeric 0:b9444a40a999 214 /*void PPP_IRQHandler(void)
gregeric 0:b9444a40a999 215 {
gregeric 0:b9444a40a999 216 }*/
gregeric 0:b9444a40a999 217
gregeric 0:b9444a40a999 218 /**
gregeric 0:b9444a40a999 219 * @}
gregeric 0:b9444a40a999 220 */
gregeric 0:b9444a40a999 221 #endif
gregeric 0:b9444a40a999 222 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/