mbed library sources modified for open wear
Dependents: openwear-lifelogger-example
Fork of mbed-src by
targets/cmsis/TARGET_STM/TARGET_NUCLEO_F401RE/stm32f4xx_hal_tim.c@106:ced8cbb51063, 2014-02-26 (annotated)
- Committer:
- mbed_official
- Date:
- Wed Feb 26 09:45:12 2014 +0000
- Revision:
- 106:ced8cbb51063
- Parent:
- 87:085cde657901
- Child:
- 226:b062af740e40
Synchronized with git revision 4222735eff5868389433f0e9271976b39c8115cd
Full URL: https://github.com/mbedmicro/mbed/commit/4222735eff5868389433f0e9271976b39c8115cd/
[NUCLEO_xxx] Update STM32CubeF4 driver V1.0.0 + update license
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 87:085cde657901 | 1 | /** |
mbed_official | 87:085cde657901 | 2 | ****************************************************************************** |
mbed_official | 87:085cde657901 | 3 | * @file stm32f4xx_hal_tim.c |
mbed_official | 87:085cde657901 | 4 | * @author MCD Application Team |
mbed_official | 106:ced8cbb51063 | 5 | * @version V1.0.0 |
mbed_official | 106:ced8cbb51063 | 6 | * @date 18-February-2014 |
mbed_official | 87:085cde657901 | 7 | * @brief TIM HAL module driver. |
mbed_official | 87:085cde657901 | 8 | * This file provides firmware functions to manage the following |
mbed_official | 87:085cde657901 | 9 | * functionalities of the Timer (TIM) peripheral: |
mbed_official | 87:085cde657901 | 10 | * + Time Base Initialization |
mbed_official | 87:085cde657901 | 11 | * + Time Base Start |
mbed_official | 87:085cde657901 | 12 | * + Time Base Start Interruption |
mbed_official | 87:085cde657901 | 13 | * + Time Base Start DMA |
mbed_official | 87:085cde657901 | 14 | * + Time Output Compare/PWM Initialization |
mbed_official | 87:085cde657901 | 15 | * + Time Output Compare/PWM Channel Configuration |
mbed_official | 87:085cde657901 | 16 | * + Time Output Compare/PWM Start |
mbed_official | 87:085cde657901 | 17 | * + Time Output Compare/PWM Start Interruption |
mbed_official | 87:085cde657901 | 18 | * + Time Output Compare/PWM Start DMA |
mbed_official | 87:085cde657901 | 19 | * + Time Input Capture Initialization |
mbed_official | 87:085cde657901 | 20 | * + Time Input Capture Channel Configuration |
mbed_official | 87:085cde657901 | 21 | * + Time Input Capture Start |
mbed_official | 87:085cde657901 | 22 | * + Time Input Capture Start Interruption |
mbed_official | 87:085cde657901 | 23 | * + Time Input Capture Start DMA |
mbed_official | 87:085cde657901 | 24 | * + Time One Pulse Initialization |
mbed_official | 87:085cde657901 | 25 | * + Time One Pulse Channel Configuration |
mbed_official | 87:085cde657901 | 26 | * + Time One Pulse Start |
mbed_official | 87:085cde657901 | 27 | * + Time Encoder Interface Initialization |
mbed_official | 87:085cde657901 | 28 | * + Time Encoder Interface Start |
mbed_official | 87:085cde657901 | 29 | * + Time Encoder Interface Start Interruption |
mbed_official | 87:085cde657901 | 30 | * + Time Encoder Interface Start DMA |
mbed_official | 87:085cde657901 | 31 | * + Commutation Event configuration with Interruption and DMA |
mbed_official | 87:085cde657901 | 32 | * + Time OCRef clear configuration |
mbed_official | 87:085cde657901 | 33 | * + Time External Clock configuration |
mbed_official | 87:085cde657901 | 34 | @verbatim |
mbed_official | 87:085cde657901 | 35 | ============================================================================== |
mbed_official | 87:085cde657901 | 36 | ##### TIMER Generic features ##### |
mbed_official | 87:085cde657901 | 37 | ============================================================================== |
mbed_official | 87:085cde657901 | 38 | [..] The Timer features include: |
mbed_official | 87:085cde657901 | 39 | (#) 16-bit up, down, up/down auto-reload counter. |
mbed_official | 87:085cde657901 | 40 | (#) 16-bit programmable prescaler allowing dividing (also on the fly) the |
mbed_official | 87:085cde657901 | 41 | counter clock frequency either by any factor between 1 and 65536. |
mbed_official | 87:085cde657901 | 42 | (#) Up to 4 independent channels for: |
mbed_official | 87:085cde657901 | 43 | (++) Input Capture |
mbed_official | 87:085cde657901 | 44 | (++) Output Compare |
mbed_official | 87:085cde657901 | 45 | (++) PWM generation (Edge and Center-aligned Mode) |
mbed_official | 87:085cde657901 | 46 | (++) One-pulse mode output |
mbed_official | 87:085cde657901 | 47 | |
mbed_official | 87:085cde657901 | 48 | ##### How to use this driver ##### |
mbed_official | 87:085cde657901 | 49 | ============================================================================== |
mbed_official | 87:085cde657901 | 50 | [..] |
mbed_official | 87:085cde657901 | 51 | (#) Initialize the TIM low level resources by implementing the following functions |
mbed_official | 87:085cde657901 | 52 | depending from feature used : |
mbed_official | 87:085cde657901 | 53 | (++) Time Base : HAL_TIM_Base_MspInit() |
mbed_official | 87:085cde657901 | 54 | (++) Input Capture : HAL_TIM_IC_MspInit() |
mbed_official | 87:085cde657901 | 55 | (++) Output Compare : HAL_TIM_OC_MspInit() |
mbed_official | 87:085cde657901 | 56 | (++) PWM generation : HAL_TIM_PWM_MspInit() |
mbed_official | 87:085cde657901 | 57 | (++) One-pulse mode output : HAL_TIM_OnePulse_MspInit() |
mbed_official | 87:085cde657901 | 58 | (++) Encoder mode output : HAL_TIM_Encoder_MspInit() |
mbed_official | 87:085cde657901 | 59 | |
mbed_official | 87:085cde657901 | 60 | (#) Initialize the TIM low level resources : |
mbed_official | 87:085cde657901 | 61 | (##) Enable the TIM interface clock using __TIMx_CLK_ENABLE(); |
mbed_official | 87:085cde657901 | 62 | (##) TIM pins configuration |
mbed_official | 87:085cde657901 | 63 | (+++) Enable the clock for the TIM GPIOs using the following function: |
mbed_official | 87:085cde657901 | 64 | __GPIOx_CLK_ENABLE(); |
mbed_official | 87:085cde657901 | 65 | (+++) Configure these TIM pins in Alternate function mode using HAL_GPIO_Init(); |
mbed_official | 87:085cde657901 | 66 | |
mbed_official | 87:085cde657901 | 67 | (#) The external Clock can be configured, if needed (the default clock is the |
mbed_official | 87:085cde657901 | 68 | internal clock from the APBx), using the following function: |
mbed_official | 87:085cde657901 | 69 | HAL_TIM_ConfigClockSource, the clock configuration should be done before |
mbed_official | 87:085cde657901 | 70 | any start function. |
mbed_official | 87:085cde657901 | 71 | |
mbed_official | 87:085cde657901 | 72 | (#) Configure the TIM in the desired functioning mode using one of the |
mbed_official | 87:085cde657901 | 73 | initialization function of this driver: |
mbed_official | 87:085cde657901 | 74 | (++) HAL_TIM_Base_Init: to use the Timer to generate a simple time base |
mbed_official | 87:085cde657901 | 75 | (++) HAL_TIM_OC_Init and HAL_TIM_OC_ConfigChannel: to use the Timer to generate an |
mbed_official | 87:085cde657901 | 76 | Output Compare signal. |
mbed_official | 87:085cde657901 | 77 | (++) HAL_TIM_PWM_Init and HAL_TIM_PWM_ConfigChannel: to use the Timer to generate a |
mbed_official | 87:085cde657901 | 78 | PWM signal. |
mbed_official | 87:085cde657901 | 79 | (++) HAL_TIM_IC_Init and HAL_TIM_IC_ConfigChannel: to use the Timer to measure an |
mbed_official | 87:085cde657901 | 80 | external signal. |
mbed_official | 87:085cde657901 | 81 | (++) HAL_TIM_OnePulse_Init and HAL_TIM_OnePulse_ConfigChannel: to use the Timer |
mbed_official | 87:085cde657901 | 82 | in One Pulse Mode. |
mbed_official | 87:085cde657901 | 83 | (++) HAL_TIM_Encoder_Init: to use the Timer Encoder Interface. |
mbed_official | 87:085cde657901 | 84 | |
mbed_official | 87:085cde657901 | 85 | (#) Activate the TIM peripheral using one of the start functions depending from the feature used: |
mbed_official | 87:085cde657901 | 86 | (++) Time Base : HAL_TIM_Base_Start(), HAL_TIM_Base_Start_DMA(), HAL_TIM_Base_Start_IT() |
mbed_official | 87:085cde657901 | 87 | (++) Input Capture : HAL_TIM_IC_Start(), HAL_TIM_IC_Start_DMA(), HAL_TIM_IC_Start_IT() |
mbed_official | 87:085cde657901 | 88 | (++) Output Compare : HAL_TIM_OC_Start(), HAL_TIM_OC_Start_DMA(), HAL_TIM_OC_Start_IT() |
mbed_official | 87:085cde657901 | 89 | (++) PWM generation : HAL_TIM_PWM_Start(), HAL_TIM_PWM_Start_DMA(), HAL_TIM_PWM_Start_IT() |
mbed_official | 87:085cde657901 | 90 | (++) One-pulse mode output : HAL_TIM_OnePulse_Start(), HAL_TIM_OnePulse_Start_IT() |
mbed_official | 87:085cde657901 | 91 | (++) Encoder mode output : HAL_TIM_Encoder_Start(), HAL_TIM_Encoder_Start_DMA(), HAL_TIM_Encoder_Start_IT(). |
mbed_official | 87:085cde657901 | 92 | |
mbed_official | 87:085cde657901 | 93 | (#) The DMA Burst is managed with the two following functions: |
mbed_official | 87:085cde657901 | 94 | HAL_TIM_DMABurst_WriteStart() |
mbed_official | 87:085cde657901 | 95 | HAL_TIM_DMABurst_ReadStart() |
mbed_official | 87:085cde657901 | 96 | |
mbed_official | 87:085cde657901 | 97 | @endverbatim |
mbed_official | 87:085cde657901 | 98 | ****************************************************************************** |
mbed_official | 87:085cde657901 | 99 | * @attention |
mbed_official | 87:085cde657901 | 100 | * |
mbed_official | 87:085cde657901 | 101 | * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2> |
mbed_official | 87:085cde657901 | 102 | * |
mbed_official | 87:085cde657901 | 103 | * Redistribution and use in source and binary forms, with or without modification, |
mbed_official | 87:085cde657901 | 104 | * are permitted provided that the following conditions are met: |
mbed_official | 87:085cde657901 | 105 | * 1. Redistributions of source code must retain the above copyright notice, |
mbed_official | 87:085cde657901 | 106 | * this list of conditions and the following disclaimer. |
mbed_official | 87:085cde657901 | 107 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
mbed_official | 87:085cde657901 | 108 | * this list of conditions and the following disclaimer in the documentation |
mbed_official | 87:085cde657901 | 109 | * and/or other materials provided with the distribution. |
mbed_official | 87:085cde657901 | 110 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
mbed_official | 87:085cde657901 | 111 | * may be used to endorse or promote products derived from this software |
mbed_official | 87:085cde657901 | 112 | * without specific prior written permission. |
mbed_official | 87:085cde657901 | 113 | * |
mbed_official | 87:085cde657901 | 114 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
mbed_official | 87:085cde657901 | 115 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
mbed_official | 87:085cde657901 | 116 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
mbed_official | 87:085cde657901 | 117 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
mbed_official | 87:085cde657901 | 118 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
mbed_official | 87:085cde657901 | 119 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
mbed_official | 87:085cde657901 | 120 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
mbed_official | 87:085cde657901 | 121 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
mbed_official | 87:085cde657901 | 122 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
mbed_official | 87:085cde657901 | 123 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
mbed_official | 87:085cde657901 | 124 | * |
mbed_official | 87:085cde657901 | 125 | ****************************************************************************** |
mbed_official | 87:085cde657901 | 126 | */ |
mbed_official | 87:085cde657901 | 127 | |
mbed_official | 87:085cde657901 | 128 | /* Includes ------------------------------------------------------------------*/ |
mbed_official | 87:085cde657901 | 129 | #include "stm32f4xx_hal.h" |
mbed_official | 87:085cde657901 | 130 | |
mbed_official | 87:085cde657901 | 131 | /** @addtogroup STM32F4xx_HAL_Driver |
mbed_official | 87:085cde657901 | 132 | * @{ |
mbed_official | 87:085cde657901 | 133 | */ |
mbed_official | 87:085cde657901 | 134 | |
mbed_official | 87:085cde657901 | 135 | /** @defgroup TIM |
mbed_official | 87:085cde657901 | 136 | * @brief TIM HAL module driver |
mbed_official | 87:085cde657901 | 137 | * @{ |
mbed_official | 87:085cde657901 | 138 | */ |
mbed_official | 87:085cde657901 | 139 | |
mbed_official | 87:085cde657901 | 140 | #ifdef HAL_TIM_MODULE_ENABLED |
mbed_official | 87:085cde657901 | 141 | |
mbed_official | 87:085cde657901 | 142 | /* Private typedef -----------------------------------------------------------*/ |
mbed_official | 87:085cde657901 | 143 | /* Private define ------------------------------------------------------------*/ |
mbed_official | 87:085cde657901 | 144 | /* Private macro -------------------------------------------------------------*/ |
mbed_official | 87:085cde657901 | 145 | /* Private variables ---------------------------------------------------------*/ |
mbed_official | 87:085cde657901 | 146 | /* Private function prototypes -----------------------------------------------*/ |
mbed_official | 87:085cde657901 | 147 | static void TIM_OC1_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config); |
mbed_official | 87:085cde657901 | 148 | static void TIM_OC3_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config); |
mbed_official | 87:085cde657901 | 149 | static void TIM_OC4_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config); |
mbed_official | 87:085cde657901 | 150 | |
mbed_official | 87:085cde657901 | 151 | static void TIM_TI1_ConfigInputStage(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICFilter); |
mbed_official | 87:085cde657901 | 152 | static void TIM_TI2_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection, |
mbed_official | 87:085cde657901 | 153 | uint32_t TIM_ICFilter); |
mbed_official | 87:085cde657901 | 154 | static void TIM_TI2_ConfigInputStage(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICFilter); |
mbed_official | 87:085cde657901 | 155 | static void TIM_TI3_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection, |
mbed_official | 87:085cde657901 | 156 | uint32_t TIM_ICFilter); |
mbed_official | 87:085cde657901 | 157 | static void TIM_TI4_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection, |
mbed_official | 87:085cde657901 | 158 | uint32_t TIM_ICFilter); |
mbed_official | 87:085cde657901 | 159 | |
mbed_official | 87:085cde657901 | 160 | static void TIM_ETR_SetConfig(TIM_TypeDef* TIMx, uint32_t TIM_ExtTRGPrescaler, |
mbed_official | 87:085cde657901 | 161 | uint32_t TIM_ExtTRGPolarity, uint32_t ExtTRGFilter); |
mbed_official | 87:085cde657901 | 162 | |
mbed_official | 87:085cde657901 | 163 | static void TIM_ITRx_SetConfig(TIM_TypeDef* TIMx, uint16_t TIM_ITRx); |
mbed_official | 87:085cde657901 | 164 | static void TIM_DMAPeriodElapsedCplt(DMA_HandleTypeDef *hdma); |
mbed_official | 87:085cde657901 | 165 | static void TIM_DMATriggerCplt(DMA_HandleTypeDef *hdma); |
mbed_official | 87:085cde657901 | 166 | /* Private functions ---------------------------------------------------------*/ |
mbed_official | 87:085cde657901 | 167 | |
mbed_official | 87:085cde657901 | 168 | /** @defgroup TIM_Private_Functions |
mbed_official | 87:085cde657901 | 169 | * @{ |
mbed_official | 87:085cde657901 | 170 | */ |
mbed_official | 87:085cde657901 | 171 | |
mbed_official | 87:085cde657901 | 172 | /** @defgroup TIM_Group1 Time Base functions |
mbed_official | 87:085cde657901 | 173 | * @brief Time Base functions |
mbed_official | 87:085cde657901 | 174 | * |
mbed_official | 87:085cde657901 | 175 | @verbatim |
mbed_official | 87:085cde657901 | 176 | ============================================================================== |
mbed_official | 87:085cde657901 | 177 | ##### Time Base functions ##### |
mbed_official | 87:085cde657901 | 178 | ============================================================================== |
mbed_official | 87:085cde657901 | 179 | [..] |
mbed_official | 87:085cde657901 | 180 | This section provides functions allowing to: |
mbed_official | 87:085cde657901 | 181 | (+) Initialize and configure the TIM base. |
mbed_official | 87:085cde657901 | 182 | (+) De-initialize the TIM base. |
mbed_official | 87:085cde657901 | 183 | (+) Start the Time Base. |
mbed_official | 87:085cde657901 | 184 | (+) Stop the Time Base. |
mbed_official | 87:085cde657901 | 185 | (+) Start the Time Base and enable interrupt. |
mbed_official | 87:085cde657901 | 186 | (+) Stop the Time Base and disable interrupt. |
mbed_official | 87:085cde657901 | 187 | (+) Start the Time Base and enable DMA transfer. |
mbed_official | 87:085cde657901 | 188 | (+) Stop the Time Base and disable DMA transfer. |
mbed_official | 87:085cde657901 | 189 | |
mbed_official | 87:085cde657901 | 190 | @endverbatim |
mbed_official | 87:085cde657901 | 191 | * @{ |
mbed_official | 87:085cde657901 | 192 | */ |
mbed_official | 87:085cde657901 | 193 | /** |
mbed_official | 87:085cde657901 | 194 | * @brief Initializes the TIM Time base Unit according to the specified |
mbed_official | 87:085cde657901 | 195 | * parameters in the TIM_HandleTypeDef and create the associated handle. |
mbed_official | 87:085cde657901 | 196 | * @param htim: TIM Base handle |
mbed_official | 87:085cde657901 | 197 | * @retval HAL status |
mbed_official | 87:085cde657901 | 198 | */ |
mbed_official | 87:085cde657901 | 199 | HAL_StatusTypeDef HAL_TIM_Base_Init(TIM_HandleTypeDef *htim) |
mbed_official | 87:085cde657901 | 200 | { |
mbed_official | 87:085cde657901 | 201 | /* Check the TIM handle allocation */ |
mbed_official | 87:085cde657901 | 202 | if(htim == NULL) |
mbed_official | 87:085cde657901 | 203 | { |
mbed_official | 87:085cde657901 | 204 | return HAL_ERROR; |
mbed_official | 87:085cde657901 | 205 | } |
mbed_official | 87:085cde657901 | 206 | |
mbed_official | 87:085cde657901 | 207 | /* Check the parameters */ |
mbed_official | 87:085cde657901 | 208 | assert_param(IS_TIM_INSTANCE(htim->Instance)); |
mbed_official | 87:085cde657901 | 209 | assert_param(IS_TIM_COUNTER_MODE(htim->Init.CounterMode)); |
mbed_official | 87:085cde657901 | 210 | assert_param(IS_TIM_CLOCKDIVISION_DIV(htim->Init.ClockDivision)); |
mbed_official | 87:085cde657901 | 211 | |
mbed_official | 87:085cde657901 | 212 | if(htim->State == HAL_TIM_STATE_RESET) |
mbed_official | 87:085cde657901 | 213 | { |
mbed_official | 87:085cde657901 | 214 | /* Init the low level hardware : GPIO, CLOCK, NVIC */ |
mbed_official | 87:085cde657901 | 215 | HAL_TIM_Base_MspInit(htim); |
mbed_official | 87:085cde657901 | 216 | } |
mbed_official | 87:085cde657901 | 217 | |
mbed_official | 87:085cde657901 | 218 | /* Set the TIM state */ |
mbed_official | 87:085cde657901 | 219 | htim->State= HAL_TIM_STATE_BUSY; |
mbed_official | 87:085cde657901 | 220 | |
mbed_official | 87:085cde657901 | 221 | /* Set the Time Base configuration */ |
mbed_official | 87:085cde657901 | 222 | TIM_Base_SetConfig(htim->Instance, &htim->Init); |
mbed_official | 87:085cde657901 | 223 | |
mbed_official | 87:085cde657901 | 224 | /* Initialize the TIM state*/ |
mbed_official | 87:085cde657901 | 225 | htim->State= HAL_TIM_STATE_READY; |
mbed_official | 87:085cde657901 | 226 | |
mbed_official | 87:085cde657901 | 227 | return HAL_OK; |
mbed_official | 87:085cde657901 | 228 | } |
mbed_official | 87:085cde657901 | 229 | |
mbed_official | 87:085cde657901 | 230 | /** |
mbed_official | 87:085cde657901 | 231 | * @brief DeInitializes the TIM Base peripheral |
mbed_official | 87:085cde657901 | 232 | * @param htim: TIM Base handle |
mbed_official | 87:085cde657901 | 233 | * @retval HAL status |
mbed_official | 87:085cde657901 | 234 | */ |
mbed_official | 87:085cde657901 | 235 | HAL_StatusTypeDef HAL_TIM_Base_DeInit(TIM_HandleTypeDef *htim) |
mbed_official | 87:085cde657901 | 236 | { |
mbed_official | 87:085cde657901 | 237 | /* Check the parameters */ |
mbed_official | 87:085cde657901 | 238 | assert_param(IS_TIM_INSTANCE(htim->Instance)); |
mbed_official | 87:085cde657901 | 239 | |
mbed_official | 87:085cde657901 | 240 | htim->State = HAL_TIM_STATE_BUSY; |
mbed_official | 87:085cde657901 | 241 | |
mbed_official | 87:085cde657901 | 242 | /* Disable the TIM Peripheral Clock */ |
mbed_official | 87:085cde657901 | 243 | __HAL_TIM_DISABLE(htim); |
mbed_official | 87:085cde657901 | 244 | |
mbed_official | 87:085cde657901 | 245 | /* DeInit the low level hardware: GPIO, CLOCK, NVIC */ |
mbed_official | 87:085cde657901 | 246 | HAL_TIM_Base_MspDeInit(htim); |
mbed_official | 87:085cde657901 | 247 | |
mbed_official | 87:085cde657901 | 248 | /* Change TIM state */ |
mbed_official | 87:085cde657901 | 249 | htim->State = HAL_TIM_STATE_RESET; |
mbed_official | 87:085cde657901 | 250 | |
mbed_official | 106:ced8cbb51063 | 251 | /* Release Lock */ |
mbed_official | 106:ced8cbb51063 | 252 | __HAL_UNLOCK(htim); |
mbed_official | 106:ced8cbb51063 | 253 | |
mbed_official | 87:085cde657901 | 254 | return HAL_OK; |
mbed_official | 87:085cde657901 | 255 | } |
mbed_official | 87:085cde657901 | 256 | |
mbed_official | 87:085cde657901 | 257 | /** |
mbed_official | 87:085cde657901 | 258 | * @brief Initializes the TIM Base MSP. |
mbed_official | 87:085cde657901 | 259 | * @param htim: TIM handle |
mbed_official | 87:085cde657901 | 260 | * @retval None |
mbed_official | 87:085cde657901 | 261 | */ |
mbed_official | 87:085cde657901 | 262 | __weak void HAL_TIM_Base_MspInit(TIM_HandleTypeDef *htim) |
mbed_official | 87:085cde657901 | 263 | { |
mbed_official | 87:085cde657901 | 264 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 87:085cde657901 | 265 | the HAL_TIM_Base_MspInit could be implemented in the user file |
mbed_official | 87:085cde657901 | 266 | */ |
mbed_official | 87:085cde657901 | 267 | } |
mbed_official | 87:085cde657901 | 268 | |
mbed_official | 87:085cde657901 | 269 | /** |
mbed_official | 87:085cde657901 | 270 | * @brief DeInitializes TIM Base MSP. |
mbed_official | 87:085cde657901 | 271 | * @param htim: TIM handle |
mbed_official | 87:085cde657901 | 272 | * @retval None |
mbed_official | 87:085cde657901 | 273 | */ |
mbed_official | 87:085cde657901 | 274 | __weak void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef *htim) |
mbed_official | 87:085cde657901 | 275 | { |
mbed_official | 87:085cde657901 | 276 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 87:085cde657901 | 277 | the HAL_TIM_Base_MspDeInit could be implemented in the user file |
mbed_official | 87:085cde657901 | 278 | */ |
mbed_official | 87:085cde657901 | 279 | } |
mbed_official | 87:085cde657901 | 280 | |
mbed_official | 87:085cde657901 | 281 | /** |
mbed_official | 87:085cde657901 | 282 | * @brief Starts the TIM Base generation. |
mbed_official | 87:085cde657901 | 283 | * @param htim : TIM handle |
mbed_official | 87:085cde657901 | 284 | * @retval HAL status |
mbed_official | 87:085cde657901 | 285 | */ |
mbed_official | 87:085cde657901 | 286 | HAL_StatusTypeDef HAL_TIM_Base_Start(TIM_HandleTypeDef *htim) |
mbed_official | 87:085cde657901 | 287 | { |
mbed_official | 87:085cde657901 | 288 | /* Check the parameters */ |
mbed_official | 87:085cde657901 | 289 | assert_param(IS_TIM_INSTANCE(htim->Instance)); |
mbed_official | 87:085cde657901 | 290 | |
mbed_official | 87:085cde657901 | 291 | /* Set the TIM state */ |
mbed_official | 87:085cde657901 | 292 | htim->State= HAL_TIM_STATE_BUSY; |
mbed_official | 87:085cde657901 | 293 | |
mbed_official | 87:085cde657901 | 294 | /* Enable the Peripheral */ |
mbed_official | 87:085cde657901 | 295 | __HAL_TIM_ENABLE(htim); |
mbed_official | 87:085cde657901 | 296 | |
mbed_official | 87:085cde657901 | 297 | /* Change the TIM state*/ |
mbed_official | 87:085cde657901 | 298 | htim->State= HAL_TIM_STATE_READY; |
mbed_official | 87:085cde657901 | 299 | |
mbed_official | 87:085cde657901 | 300 | /* Return function status */ |
mbed_official | 87:085cde657901 | 301 | return HAL_OK; |
mbed_official | 87:085cde657901 | 302 | } |
mbed_official | 87:085cde657901 | 303 | |
mbed_official | 87:085cde657901 | 304 | /** |
mbed_official | 87:085cde657901 | 305 | * @brief Stops the TIM Base generation. |
mbed_official | 87:085cde657901 | 306 | * @param htim : TIM handle |
mbed_official | 87:085cde657901 | 307 | * @retval HAL status |
mbed_official | 87:085cde657901 | 308 | */ |
mbed_official | 87:085cde657901 | 309 | HAL_StatusTypeDef HAL_TIM_Base_Stop(TIM_HandleTypeDef *htim) |
mbed_official | 87:085cde657901 | 310 | { |
mbed_official | 87:085cde657901 | 311 | /* Check the parameters */ |
mbed_official | 87:085cde657901 | 312 | assert_param(IS_TIM_INSTANCE(htim->Instance)); |
mbed_official | 87:085cde657901 | 313 | |
mbed_official | 87:085cde657901 | 314 | /* Set the TIM state */ |
mbed_official | 87:085cde657901 | 315 | htim->State= HAL_TIM_STATE_BUSY; |
mbed_official | 87:085cde657901 | 316 | |
mbed_official | 87:085cde657901 | 317 | /* Disable the Peripheral */ |
mbed_official | 87:085cde657901 | 318 | __HAL_TIM_DISABLE(htim); |
mbed_official | 87:085cde657901 | 319 | |
mbed_official | 87:085cde657901 | 320 | /* Change the TIM state*/ |
mbed_official | 87:085cde657901 | 321 | htim->State= HAL_TIM_STATE_READY; |
mbed_official | 87:085cde657901 | 322 | |
mbed_official | 87:085cde657901 | 323 | /* Return function status */ |
mbed_official | 87:085cde657901 | 324 | return HAL_OK; |
mbed_official | 87:085cde657901 | 325 | } |
mbed_official | 87:085cde657901 | 326 | |
mbed_official | 87:085cde657901 | 327 | /** |
mbed_official | 87:085cde657901 | 328 | * @brief Starts the TIM Base generation in interrupt mode. |
mbed_official | 87:085cde657901 | 329 | * @param htim : TIM handle |
mbed_official | 87:085cde657901 | 330 | * @retval HAL status |
mbed_official | 87:085cde657901 | 331 | */ |
mbed_official | 87:085cde657901 | 332 | HAL_StatusTypeDef HAL_TIM_Base_Start_IT(TIM_HandleTypeDef *htim) |
mbed_official | 87:085cde657901 | 333 | { |
mbed_official | 87:085cde657901 | 334 | /* Check the parameters */ |
mbed_official | 87:085cde657901 | 335 | assert_param(IS_TIM_INSTANCE(htim->Instance)); |
mbed_official | 87:085cde657901 | 336 | |
mbed_official | 87:085cde657901 | 337 | /* Enable the TIM Update interrupt */ |
mbed_official | 87:085cde657901 | 338 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_UPDATE); |
mbed_official | 87:085cde657901 | 339 | |
mbed_official | 87:085cde657901 | 340 | /* Enable the Peripheral */ |
mbed_official | 87:085cde657901 | 341 | __HAL_TIM_ENABLE(htim); |
mbed_official | 87:085cde657901 | 342 | |
mbed_official | 87:085cde657901 | 343 | /* Return function status */ |
mbed_official | 87:085cde657901 | 344 | return HAL_OK; |
mbed_official | 87:085cde657901 | 345 | } |
mbed_official | 87:085cde657901 | 346 | |
mbed_official | 87:085cde657901 | 347 | /** |
mbed_official | 87:085cde657901 | 348 | * @brief Stops the TIM Base generation in interrupt mode. |
mbed_official | 87:085cde657901 | 349 | * @param htim : TIM handle |
mbed_official | 87:085cde657901 | 350 | * @retval HAL status |
mbed_official | 87:085cde657901 | 351 | */ |
mbed_official | 87:085cde657901 | 352 | HAL_StatusTypeDef HAL_TIM_Base_Stop_IT(TIM_HandleTypeDef *htim) |
mbed_official | 87:085cde657901 | 353 | { |
mbed_official | 87:085cde657901 | 354 | /* Check the parameters */ |
mbed_official | 87:085cde657901 | 355 | assert_param(IS_TIM_INSTANCE(htim->Instance)); |
mbed_official | 87:085cde657901 | 356 | /* Disable the TIM Update interrupt */ |
mbed_official | 87:085cde657901 | 357 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_UPDATE); |
mbed_official | 87:085cde657901 | 358 | |
mbed_official | 87:085cde657901 | 359 | /* Disable the Peripheral */ |
mbed_official | 87:085cde657901 | 360 | __HAL_TIM_DISABLE(htim); |
mbed_official | 87:085cde657901 | 361 | |
mbed_official | 87:085cde657901 | 362 | /* Return function status */ |
mbed_official | 87:085cde657901 | 363 | return HAL_OK; |
mbed_official | 87:085cde657901 | 364 | } |
mbed_official | 87:085cde657901 | 365 | |
mbed_official | 87:085cde657901 | 366 | /** |
mbed_official | 87:085cde657901 | 367 | * @brief Starts the TIM Base generation in DMA mode. |
mbed_official | 87:085cde657901 | 368 | * @param htim : TIM handle |
mbed_official | 87:085cde657901 | 369 | * @param pData: The source Buffer address. |
mbed_official | 87:085cde657901 | 370 | * @param Length: The length of data to be transferred from memory to peripheral. |
mbed_official | 87:085cde657901 | 371 | * @retval HAL status |
mbed_official | 87:085cde657901 | 372 | */ |
mbed_official | 87:085cde657901 | 373 | HAL_StatusTypeDef HAL_TIM_Base_Start_DMA(TIM_HandleTypeDef *htim, uint32_t *pData, uint16_t Length) |
mbed_official | 87:085cde657901 | 374 | { |
mbed_official | 87:085cde657901 | 375 | /* Check the parameters */ |
mbed_official | 87:085cde657901 | 376 | assert_param(IS_TIM_DMA_INSTANCE(htim->Instance)); |
mbed_official | 87:085cde657901 | 377 | |
mbed_official | 87:085cde657901 | 378 | if((htim->State == HAL_TIM_STATE_BUSY)) |
mbed_official | 87:085cde657901 | 379 | { |
mbed_official | 87:085cde657901 | 380 | return HAL_BUSY; |
mbed_official | 87:085cde657901 | 381 | } |
mbed_official | 87:085cde657901 | 382 | else if((htim->State == HAL_TIM_STATE_READY)) |
mbed_official | 87:085cde657901 | 383 | { |
mbed_official | 87:085cde657901 | 384 | if((pData == 0 ) && (Length > 0)) |
mbed_official | 87:085cde657901 | 385 | { |
mbed_official | 87:085cde657901 | 386 | return HAL_ERROR; |
mbed_official | 87:085cde657901 | 387 | } |
mbed_official | 87:085cde657901 | 388 | else |
mbed_official | 87:085cde657901 | 389 | { |
mbed_official | 87:085cde657901 | 390 | htim->State = HAL_TIM_STATE_BUSY; |
mbed_official | 87:085cde657901 | 391 | } |
mbed_official | 87:085cde657901 | 392 | } |
mbed_official | 87:085cde657901 | 393 | /* Set the DMA Period elapsed callback */ |
mbed_official | 87:085cde657901 | 394 | htim->hdma[TIM_DMA_ID_UPDATE]->XferCpltCallback = TIM_DMAPeriodElapsedCplt; |
mbed_official | 87:085cde657901 | 395 | |
mbed_official | 87:085cde657901 | 396 | /* Set the DMA error callback */ |
mbed_official | 87:085cde657901 | 397 | htim->hdma[TIM_DMA_ID_UPDATE]->XferErrorCallback = HAL_TIM_DMAError ; |
mbed_official | 87:085cde657901 | 398 | |
mbed_official | 87:085cde657901 | 399 | /* Enable the DMA Stream */ |
mbed_official | 87:085cde657901 | 400 | HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_UPDATE], (uint32_t)pData, (uint32_t)&htim->Instance->ARR, Length); |
mbed_official | 87:085cde657901 | 401 | |
mbed_official | 87:085cde657901 | 402 | /* Enable the TIM Update DMA request */ |
mbed_official | 87:085cde657901 | 403 | __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_UPDATE); |
mbed_official | 87:085cde657901 | 404 | |
mbed_official | 87:085cde657901 | 405 | /* Enable the Peripheral */ |
mbed_official | 87:085cde657901 | 406 | __HAL_TIM_ENABLE(htim); |
mbed_official | 87:085cde657901 | 407 | |
mbed_official | 87:085cde657901 | 408 | /* Return function status */ |
mbed_official | 87:085cde657901 | 409 | return HAL_OK; |
mbed_official | 87:085cde657901 | 410 | } |
mbed_official | 87:085cde657901 | 411 | |
mbed_official | 87:085cde657901 | 412 | /** |
mbed_official | 87:085cde657901 | 413 | * @brief Stops the TIM Base generation in DMA mode. |
mbed_official | 87:085cde657901 | 414 | * @param htim : TIM handle |
mbed_official | 87:085cde657901 | 415 | * @retval HAL status |
mbed_official | 87:085cde657901 | 416 | */ |
mbed_official | 87:085cde657901 | 417 | HAL_StatusTypeDef HAL_TIM_Base_Stop_DMA(TIM_HandleTypeDef *htim) |
mbed_official | 87:085cde657901 | 418 | { |
mbed_official | 87:085cde657901 | 419 | /* Check the parameters */ |
mbed_official | 87:085cde657901 | 420 | assert_param(IS_TIM_DMA_INSTANCE(htim->Instance)); |
mbed_official | 87:085cde657901 | 421 | |
mbed_official | 87:085cde657901 | 422 | /* Disable the TIM Update DMA request */ |
mbed_official | 87:085cde657901 | 423 | __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_UPDATE); |
mbed_official | 87:085cde657901 | 424 | |
mbed_official | 87:085cde657901 | 425 | /* Disable the Peripheral */ |
mbed_official | 87:085cde657901 | 426 | __HAL_TIM_DISABLE(htim); |
mbed_official | 87:085cde657901 | 427 | |
mbed_official | 87:085cde657901 | 428 | /* Change the htim state */ |
mbed_official | 87:085cde657901 | 429 | htim->State = HAL_TIM_STATE_READY; |
mbed_official | 87:085cde657901 | 430 | |
mbed_official | 87:085cde657901 | 431 | /* Return function status */ |
mbed_official | 87:085cde657901 | 432 | return HAL_OK; |
mbed_official | 87:085cde657901 | 433 | } |
mbed_official | 87:085cde657901 | 434 | |
mbed_official | 87:085cde657901 | 435 | /** |
mbed_official | 87:085cde657901 | 436 | * @} |
mbed_official | 87:085cde657901 | 437 | */ |
mbed_official | 87:085cde657901 | 438 | |
mbed_official | 87:085cde657901 | 439 | /** @defgroup TIM_Group2 Time Output Compare functions |
mbed_official | 87:085cde657901 | 440 | * @brief Time Output Compare functions |
mbed_official | 87:085cde657901 | 441 | * |
mbed_official | 87:085cde657901 | 442 | @verbatim |
mbed_official | 87:085cde657901 | 443 | ============================================================================== |
mbed_official | 87:085cde657901 | 444 | ##### Time Output Compare functions ##### |
mbed_official | 87:085cde657901 | 445 | ============================================================================== |
mbed_official | 87:085cde657901 | 446 | [..] |
mbed_official | 87:085cde657901 | 447 | This section provides functions allowing to: |
mbed_official | 87:085cde657901 | 448 | (+) Initialize and configure the TIM Output Compare. |
mbed_official | 87:085cde657901 | 449 | (+) De-initialize the TIM Output Compare. |
mbed_official | 87:085cde657901 | 450 | (+) Start the Time Output Compare. |
mbed_official | 87:085cde657901 | 451 | (+) Stop the Time Output Compare. |
mbed_official | 87:085cde657901 | 452 | (+) Start the Time Output Compare and enable interrupt. |
mbed_official | 87:085cde657901 | 453 | (+) Stop the Time Output Compare and disable interrupt. |
mbed_official | 87:085cde657901 | 454 | (+) Start the Time Output Compare and enable DMA transfer. |
mbed_official | 87:085cde657901 | 455 | (+) Stop the Time Output Compare and disable DMA transfer. |
mbed_official | 87:085cde657901 | 456 | |
mbed_official | 87:085cde657901 | 457 | @endverbatim |
mbed_official | 87:085cde657901 | 458 | * @{ |
mbed_official | 87:085cde657901 | 459 | */ |
mbed_official | 87:085cde657901 | 460 | /** |
mbed_official | 87:085cde657901 | 461 | * @brief Initializes the TIM Output Compare according to the specified |
mbed_official | 87:085cde657901 | 462 | * parameters in the TIM_HandleTypeDef and create the associated handle. |
mbed_official | 87:085cde657901 | 463 | * @param htim: TIM Output Compare handle |
mbed_official | 87:085cde657901 | 464 | * @retval HAL status |
mbed_official | 87:085cde657901 | 465 | */ |
mbed_official | 87:085cde657901 | 466 | HAL_StatusTypeDef HAL_TIM_OC_Init(TIM_HandleTypeDef* htim) |
mbed_official | 87:085cde657901 | 467 | { |
mbed_official | 87:085cde657901 | 468 | /* Check the TIM handle allocation */ |
mbed_official | 87:085cde657901 | 469 | if(htim == NULL) |
mbed_official | 87:085cde657901 | 470 | { |
mbed_official | 87:085cde657901 | 471 | return HAL_ERROR; |
mbed_official | 87:085cde657901 | 472 | } |
mbed_official | 87:085cde657901 | 473 | |
mbed_official | 87:085cde657901 | 474 | /* Check the parameters */ |
mbed_official | 87:085cde657901 | 475 | assert_param(IS_TIM_INSTANCE(htim->Instance)); |
mbed_official | 87:085cde657901 | 476 | assert_param(IS_TIM_COUNTER_MODE(htim->Init.CounterMode)); |
mbed_official | 87:085cde657901 | 477 | assert_param(IS_TIM_CLOCKDIVISION_DIV(htim->Init.ClockDivision)); |
mbed_official | 87:085cde657901 | 478 | |
mbed_official | 87:085cde657901 | 479 | if(htim->State == HAL_TIM_STATE_RESET) |
mbed_official | 87:085cde657901 | 480 | { |
mbed_official | 87:085cde657901 | 481 | /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */ |
mbed_official | 87:085cde657901 | 482 | HAL_TIM_OC_MspInit(htim); |
mbed_official | 87:085cde657901 | 483 | } |
mbed_official | 87:085cde657901 | 484 | |
mbed_official | 87:085cde657901 | 485 | /* Set the TIM state */ |
mbed_official | 87:085cde657901 | 486 | htim->State= HAL_TIM_STATE_BUSY; |
mbed_official | 87:085cde657901 | 487 | |
mbed_official | 87:085cde657901 | 488 | /* Init the base time for the Output Compare */ |
mbed_official | 87:085cde657901 | 489 | TIM_Base_SetConfig(htim->Instance, &htim->Init); |
mbed_official | 87:085cde657901 | 490 | |
mbed_official | 87:085cde657901 | 491 | /* Initialize the TIM state*/ |
mbed_official | 87:085cde657901 | 492 | htim->State= HAL_TIM_STATE_READY; |
mbed_official | 87:085cde657901 | 493 | |
mbed_official | 87:085cde657901 | 494 | return HAL_OK; |
mbed_official | 87:085cde657901 | 495 | } |
mbed_official | 87:085cde657901 | 496 | |
mbed_official | 87:085cde657901 | 497 | /** |
mbed_official | 87:085cde657901 | 498 | * @brief DeInitializes the TIM peripheral |
mbed_official | 87:085cde657901 | 499 | * @param htim: TIM Output Compare handle |
mbed_official | 87:085cde657901 | 500 | * @retval HAL status |
mbed_official | 87:085cde657901 | 501 | */ |
mbed_official | 87:085cde657901 | 502 | HAL_StatusTypeDef HAL_TIM_OC_DeInit(TIM_HandleTypeDef *htim) |
mbed_official | 87:085cde657901 | 503 | { |
mbed_official | 87:085cde657901 | 504 | /* Check the parameters */ |
mbed_official | 87:085cde657901 | 505 | assert_param(IS_TIM_INSTANCE(htim->Instance)); |
mbed_official | 87:085cde657901 | 506 | |
mbed_official | 87:085cde657901 | 507 | htim->State = HAL_TIM_STATE_BUSY; |
mbed_official | 87:085cde657901 | 508 | |
mbed_official | 87:085cde657901 | 509 | /* Disable the TIM Peripheral Clock */ |
mbed_official | 87:085cde657901 | 510 | __HAL_TIM_DISABLE(htim); |
mbed_official | 87:085cde657901 | 511 | |
mbed_official | 87:085cde657901 | 512 | /* DeInit the low level hardware: GPIO, CLOCK, NVIC and DMA */ |
mbed_official | 87:085cde657901 | 513 | HAL_TIM_OC_MspDeInit(htim); |
mbed_official | 87:085cde657901 | 514 | |
mbed_official | 87:085cde657901 | 515 | /* Change TIM state */ |
mbed_official | 87:085cde657901 | 516 | htim->State = HAL_TIM_STATE_RESET; |
mbed_official | 106:ced8cbb51063 | 517 | |
mbed_official | 106:ced8cbb51063 | 518 | /* Release Lock */ |
mbed_official | 106:ced8cbb51063 | 519 | __HAL_UNLOCK(htim); |
mbed_official | 106:ced8cbb51063 | 520 | |
mbed_official | 87:085cde657901 | 521 | return HAL_OK; |
mbed_official | 87:085cde657901 | 522 | } |
mbed_official | 87:085cde657901 | 523 | |
mbed_official | 87:085cde657901 | 524 | /** |
mbed_official | 87:085cde657901 | 525 | * @brief Initializes the TIM Output Compare MSP. |
mbed_official | 87:085cde657901 | 526 | * @param htim: TIM handle |
mbed_official | 87:085cde657901 | 527 | * @retval None |
mbed_official | 87:085cde657901 | 528 | */ |
mbed_official | 87:085cde657901 | 529 | __weak void HAL_TIM_OC_MspInit(TIM_HandleTypeDef *htim) |
mbed_official | 87:085cde657901 | 530 | { |
mbed_official | 87:085cde657901 | 531 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 87:085cde657901 | 532 | the HAL_TIM_OC_MspInit could be implemented in the user file |
mbed_official | 87:085cde657901 | 533 | */ |
mbed_official | 87:085cde657901 | 534 | } |
mbed_official | 87:085cde657901 | 535 | |
mbed_official | 87:085cde657901 | 536 | /** |
mbed_official | 87:085cde657901 | 537 | * @brief DeInitializes TIM Output Compare MSP. |
mbed_official | 87:085cde657901 | 538 | * @param htim: TIM handle |
mbed_official | 87:085cde657901 | 539 | * @retval None |
mbed_official | 87:085cde657901 | 540 | */ |
mbed_official | 87:085cde657901 | 541 | __weak void HAL_TIM_OC_MspDeInit(TIM_HandleTypeDef *htim) |
mbed_official | 87:085cde657901 | 542 | { |
mbed_official | 87:085cde657901 | 543 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 87:085cde657901 | 544 | the HAL_TIM_OC_MspDeInit could be implemented in the user file |
mbed_official | 87:085cde657901 | 545 | */ |
mbed_official | 87:085cde657901 | 546 | } |
mbed_official | 87:085cde657901 | 547 | |
mbed_official | 87:085cde657901 | 548 | /** |
mbed_official | 87:085cde657901 | 549 | * @brief Starts the TIM Output Compare signal generation. |
mbed_official | 87:085cde657901 | 550 | * @param htim : TIM Output Compare handle |
mbed_official | 87:085cde657901 | 551 | * @param Channel : TIM Channel to be enabled |
mbed_official | 87:085cde657901 | 552 | * This parameter can be one of the following values: |
mbed_official | 87:085cde657901 | 553 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
mbed_official | 87:085cde657901 | 554 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
mbed_official | 87:085cde657901 | 555 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
mbed_official | 87:085cde657901 | 556 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
mbed_official | 87:085cde657901 | 557 | * @retval HAL status |
mbed_official | 87:085cde657901 | 558 | */ |
mbed_official | 87:085cde657901 | 559 | HAL_StatusTypeDef HAL_TIM_OC_Start(TIM_HandleTypeDef *htim, uint32_t Channel) |
mbed_official | 87:085cde657901 | 560 | { |
mbed_official | 87:085cde657901 | 561 | /* Check the parameters */ |
mbed_official | 87:085cde657901 | 562 | assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); |
mbed_official | 87:085cde657901 | 563 | |
mbed_official | 87:085cde657901 | 564 | /* Enable the Output compare channel */ |
mbed_official | 87:085cde657901 | 565 | TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE); |
mbed_official | 87:085cde657901 | 566 | |
mbed_official | 87:085cde657901 | 567 | if(IS_TIM_ADVANCED_INSTANCE(htim->Instance) != RESET) |
mbed_official | 87:085cde657901 | 568 | { |
mbed_official | 87:085cde657901 | 569 | /* Enable the main output */ |
mbed_official | 87:085cde657901 | 570 | __HAL_TIM_MOE_ENABLE(htim); |
mbed_official | 87:085cde657901 | 571 | } |
mbed_official | 87:085cde657901 | 572 | |
mbed_official | 87:085cde657901 | 573 | /* Enable the Peripheral */ |
mbed_official | 87:085cde657901 | 574 | __HAL_TIM_ENABLE(htim); |
mbed_official | 87:085cde657901 | 575 | |
mbed_official | 87:085cde657901 | 576 | /* Return function status */ |
mbed_official | 87:085cde657901 | 577 | return HAL_OK; |
mbed_official | 87:085cde657901 | 578 | } |
mbed_official | 87:085cde657901 | 579 | |
mbed_official | 87:085cde657901 | 580 | /** |
mbed_official | 87:085cde657901 | 581 | * @brief Stops the TIM Output Compare signal generation. |
mbed_official | 87:085cde657901 | 582 | * @param htim : TIM handle |
mbed_official | 87:085cde657901 | 583 | * @param Channel : TIM Channel to be disabled |
mbed_official | 87:085cde657901 | 584 | * This parameter can be one of the following values: |
mbed_official | 87:085cde657901 | 585 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
mbed_official | 87:085cde657901 | 586 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
mbed_official | 87:085cde657901 | 587 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
mbed_official | 87:085cde657901 | 588 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
mbed_official | 87:085cde657901 | 589 | * @retval HAL status |
mbed_official | 87:085cde657901 | 590 | */ |
mbed_official | 87:085cde657901 | 591 | HAL_StatusTypeDef HAL_TIM_OC_Stop(TIM_HandleTypeDef *htim, uint32_t Channel) |
mbed_official | 87:085cde657901 | 592 | { |
mbed_official | 87:085cde657901 | 593 | /* Check the parameters */ |
mbed_official | 87:085cde657901 | 594 | assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); |
mbed_official | 87:085cde657901 | 595 | |
mbed_official | 87:085cde657901 | 596 | /* Disable the Output compare channel */ |
mbed_official | 87:085cde657901 | 597 | TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE); |
mbed_official | 87:085cde657901 | 598 | |
mbed_official | 87:085cde657901 | 599 | if(IS_TIM_ADVANCED_INSTANCE(htim->Instance) != RESET) |
mbed_official | 87:085cde657901 | 600 | { |
mbed_official | 87:085cde657901 | 601 | /* Disable the Main Ouput */ |
mbed_official | 87:085cde657901 | 602 | __HAL_TIM_MOE_DISABLE(htim); |
mbed_official | 87:085cde657901 | 603 | } |
mbed_official | 87:085cde657901 | 604 | |
mbed_official | 87:085cde657901 | 605 | /* Disable the Peripheral */ |
mbed_official | 87:085cde657901 | 606 | __HAL_TIM_DISABLE(htim); |
mbed_official | 87:085cde657901 | 607 | |
mbed_official | 87:085cde657901 | 608 | /* Return function status */ |
mbed_official | 87:085cde657901 | 609 | return HAL_OK; |
mbed_official | 87:085cde657901 | 610 | } |
mbed_official | 87:085cde657901 | 611 | |
mbed_official | 87:085cde657901 | 612 | /** |
mbed_official | 87:085cde657901 | 613 | * @brief Starts the TIM Output Compare signal generation in interrupt mode. |
mbed_official | 87:085cde657901 | 614 | * @param htim : TIM OC handle |
mbed_official | 87:085cde657901 | 615 | * @param Channel : TIM Channel to be enabled |
mbed_official | 87:085cde657901 | 616 | * This parameter can be one of the following values: |
mbed_official | 87:085cde657901 | 617 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
mbed_official | 87:085cde657901 | 618 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
mbed_official | 87:085cde657901 | 619 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
mbed_official | 87:085cde657901 | 620 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
mbed_official | 87:085cde657901 | 621 | * @retval HAL status |
mbed_official | 87:085cde657901 | 622 | */ |
mbed_official | 87:085cde657901 | 623 | HAL_StatusTypeDef HAL_TIM_OC_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel) |
mbed_official | 87:085cde657901 | 624 | { |
mbed_official | 87:085cde657901 | 625 | /* Check the parameters */ |
mbed_official | 87:085cde657901 | 626 | assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); |
mbed_official | 87:085cde657901 | 627 | |
mbed_official | 87:085cde657901 | 628 | switch (Channel) |
mbed_official | 87:085cde657901 | 629 | { |
mbed_official | 87:085cde657901 | 630 | case TIM_CHANNEL_1: |
mbed_official | 87:085cde657901 | 631 | { |
mbed_official | 87:085cde657901 | 632 | /* Enable the TIM Capture/Compare 1 interrupt */ |
mbed_official | 87:085cde657901 | 633 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1); |
mbed_official | 87:085cde657901 | 634 | } |
mbed_official | 87:085cde657901 | 635 | break; |
mbed_official | 87:085cde657901 | 636 | |
mbed_official | 87:085cde657901 | 637 | case TIM_CHANNEL_2: |
mbed_official | 87:085cde657901 | 638 | { |
mbed_official | 87:085cde657901 | 639 | /* Enable the TIM Capture/Compare 2 interrupt */ |
mbed_official | 87:085cde657901 | 640 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2); |
mbed_official | 87:085cde657901 | 641 | } |
mbed_official | 87:085cde657901 | 642 | break; |
mbed_official | 87:085cde657901 | 643 | |
mbed_official | 87:085cde657901 | 644 | case TIM_CHANNEL_3: |
mbed_official | 87:085cde657901 | 645 | { |
mbed_official | 87:085cde657901 | 646 | /* Enable the TIM Capture/Compare 3 interrupt */ |
mbed_official | 87:085cde657901 | 647 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC3); |
mbed_official | 87:085cde657901 | 648 | } |
mbed_official | 87:085cde657901 | 649 | break; |
mbed_official | 87:085cde657901 | 650 | |
mbed_official | 87:085cde657901 | 651 | case TIM_CHANNEL_4: |
mbed_official | 87:085cde657901 | 652 | { |
mbed_official | 87:085cde657901 | 653 | /* Enable the TIM Capture/Compare 4 interrupt */ |
mbed_official | 87:085cde657901 | 654 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC4); |
mbed_official | 87:085cde657901 | 655 | } |
mbed_official | 87:085cde657901 | 656 | break; |
mbed_official | 87:085cde657901 | 657 | |
mbed_official | 87:085cde657901 | 658 | default: |
mbed_official | 87:085cde657901 | 659 | break; |
mbed_official | 87:085cde657901 | 660 | } |
mbed_official | 87:085cde657901 | 661 | |
mbed_official | 87:085cde657901 | 662 | /* Enable the Output compare channel */ |
mbed_official | 87:085cde657901 | 663 | TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE); |
mbed_official | 87:085cde657901 | 664 | |
mbed_official | 87:085cde657901 | 665 | if(IS_TIM_ADVANCED_INSTANCE(htim->Instance) != RESET) |
mbed_official | 87:085cde657901 | 666 | { |
mbed_official | 87:085cde657901 | 667 | /* Enable the main output */ |
mbed_official | 87:085cde657901 | 668 | __HAL_TIM_MOE_ENABLE(htim); |
mbed_official | 87:085cde657901 | 669 | } |
mbed_official | 87:085cde657901 | 670 | |
mbed_official | 87:085cde657901 | 671 | /* Enable the Peripheral */ |
mbed_official | 87:085cde657901 | 672 | __HAL_TIM_ENABLE(htim); |
mbed_official | 87:085cde657901 | 673 | |
mbed_official | 87:085cde657901 | 674 | /* Return function status */ |
mbed_official | 87:085cde657901 | 675 | return HAL_OK; |
mbed_official | 87:085cde657901 | 676 | } |
mbed_official | 87:085cde657901 | 677 | |
mbed_official | 87:085cde657901 | 678 | /** |
mbed_official | 87:085cde657901 | 679 | * @brief Stops the TIM Output Compare signal generation in interrupt mode. |
mbed_official | 87:085cde657901 | 680 | * @param htim : TIM Output Compare handle |
mbed_official | 87:085cde657901 | 681 | * @param Channel : TIM Channel to be disabled |
mbed_official | 87:085cde657901 | 682 | * This parameter can be one of the following values: |
mbed_official | 87:085cde657901 | 683 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
mbed_official | 87:085cde657901 | 684 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
mbed_official | 87:085cde657901 | 685 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
mbed_official | 87:085cde657901 | 686 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
mbed_official | 87:085cde657901 | 687 | * @retval HAL status |
mbed_official | 87:085cde657901 | 688 | */ |
mbed_official | 87:085cde657901 | 689 | HAL_StatusTypeDef HAL_TIM_OC_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel) |
mbed_official | 87:085cde657901 | 690 | { |
mbed_official | 87:085cde657901 | 691 | /* Check the parameters */ |
mbed_official | 87:085cde657901 | 692 | assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); |
mbed_official | 87:085cde657901 | 693 | |
mbed_official | 87:085cde657901 | 694 | switch (Channel) |
mbed_official | 87:085cde657901 | 695 | { |
mbed_official | 87:085cde657901 | 696 | case TIM_CHANNEL_1: |
mbed_official | 87:085cde657901 | 697 | { |
mbed_official | 87:085cde657901 | 698 | /* Disable the TIM Capture/Compare 1 interrupt */ |
mbed_official | 87:085cde657901 | 699 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1); |
mbed_official | 87:085cde657901 | 700 | } |
mbed_official | 87:085cde657901 | 701 | break; |
mbed_official | 87:085cde657901 | 702 | |
mbed_official | 87:085cde657901 | 703 | case TIM_CHANNEL_2: |
mbed_official | 87:085cde657901 | 704 | { |
mbed_official | 87:085cde657901 | 705 | /* Disable the TIM Capture/Compare 2 interrupt */ |
mbed_official | 87:085cde657901 | 706 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2); |
mbed_official | 87:085cde657901 | 707 | } |
mbed_official | 87:085cde657901 | 708 | break; |
mbed_official | 87:085cde657901 | 709 | |
mbed_official | 87:085cde657901 | 710 | case TIM_CHANNEL_3: |
mbed_official | 87:085cde657901 | 711 | { |
mbed_official | 87:085cde657901 | 712 | /* Disable the TIM Capture/Compare 3 interrupt */ |
mbed_official | 87:085cde657901 | 713 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC3); |
mbed_official | 87:085cde657901 | 714 | } |
mbed_official | 87:085cde657901 | 715 | break; |
mbed_official | 87:085cde657901 | 716 | |
mbed_official | 87:085cde657901 | 717 | case TIM_CHANNEL_4: |
mbed_official | 87:085cde657901 | 718 | { |
mbed_official | 87:085cde657901 | 719 | /* Disable the TIM Capture/Compare 4 interrupt */ |
mbed_official | 87:085cde657901 | 720 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC4); |
mbed_official | 87:085cde657901 | 721 | } |
mbed_official | 87:085cde657901 | 722 | break; |
mbed_official | 87:085cde657901 | 723 | |
mbed_official | 87:085cde657901 | 724 | default: |
mbed_official | 87:085cde657901 | 725 | break; |
mbed_official | 87:085cde657901 | 726 | } |
mbed_official | 87:085cde657901 | 727 | |
mbed_official | 87:085cde657901 | 728 | /* Disable the Output compare channel */ |
mbed_official | 87:085cde657901 | 729 | TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE); |
mbed_official | 87:085cde657901 | 730 | |
mbed_official | 87:085cde657901 | 731 | if(IS_TIM_ADVANCED_INSTANCE(htim->Instance) != RESET) |
mbed_official | 87:085cde657901 | 732 | { |
mbed_official | 87:085cde657901 | 733 | /* Disable the Main Ouput */ |
mbed_official | 87:085cde657901 | 734 | __HAL_TIM_MOE_DISABLE(htim); |
mbed_official | 87:085cde657901 | 735 | } |
mbed_official | 87:085cde657901 | 736 | |
mbed_official | 87:085cde657901 | 737 | /* Disable the Peripheral */ |
mbed_official | 87:085cde657901 | 738 | __HAL_TIM_DISABLE(htim); |
mbed_official | 87:085cde657901 | 739 | |
mbed_official | 87:085cde657901 | 740 | /* Return function status */ |
mbed_official | 87:085cde657901 | 741 | return HAL_OK; |
mbed_official | 87:085cde657901 | 742 | } |
mbed_official | 87:085cde657901 | 743 | |
mbed_official | 87:085cde657901 | 744 | /** |
mbed_official | 87:085cde657901 | 745 | * @brief Starts the TIM Output Compare signal generation in DMA mode. |
mbed_official | 87:085cde657901 | 746 | * @param htim : TIM Output Compare handle |
mbed_official | 87:085cde657901 | 747 | * @param Channel : TIM Channel to be enabled |
mbed_official | 87:085cde657901 | 748 | * This parameter can be one of the following values: |
mbed_official | 87:085cde657901 | 749 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
mbed_official | 87:085cde657901 | 750 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
mbed_official | 87:085cde657901 | 751 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
mbed_official | 87:085cde657901 | 752 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
mbed_official | 87:085cde657901 | 753 | * @param pData: The source Buffer address. |
mbed_official | 87:085cde657901 | 754 | * @param Length: The length of data to be transferred from memory to TIM peripheral |
mbed_official | 87:085cde657901 | 755 | * @retval HAL status |
mbed_official | 87:085cde657901 | 756 | */ |
mbed_official | 87:085cde657901 | 757 | HAL_StatusTypeDef HAL_TIM_OC_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length) |
mbed_official | 87:085cde657901 | 758 | { |
mbed_official | 87:085cde657901 | 759 | /* Check the parameters */ |
mbed_official | 87:085cde657901 | 760 | assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); |
mbed_official | 87:085cde657901 | 761 | |
mbed_official | 87:085cde657901 | 762 | if((htim->State == HAL_TIM_STATE_BUSY)) |
mbed_official | 87:085cde657901 | 763 | { |
mbed_official | 87:085cde657901 | 764 | return HAL_BUSY; |
mbed_official | 87:085cde657901 | 765 | } |
mbed_official | 87:085cde657901 | 766 | else if((htim->State == HAL_TIM_STATE_READY)) |
mbed_official | 87:085cde657901 | 767 | { |
mbed_official | 87:085cde657901 | 768 | if(((uint32_t)pData == 0 ) && (Length > 0)) |
mbed_official | 87:085cde657901 | 769 | { |
mbed_official | 87:085cde657901 | 770 | return HAL_ERROR; |
mbed_official | 87:085cde657901 | 771 | } |
mbed_official | 87:085cde657901 | 772 | else |
mbed_official | 87:085cde657901 | 773 | { |
mbed_official | 87:085cde657901 | 774 | htim->State = HAL_TIM_STATE_BUSY; |
mbed_official | 87:085cde657901 | 775 | } |
mbed_official | 87:085cde657901 | 776 | } |
mbed_official | 87:085cde657901 | 777 | switch (Channel) |
mbed_official | 87:085cde657901 | 778 | { |
mbed_official | 87:085cde657901 | 779 | case TIM_CHANNEL_1: |
mbed_official | 87:085cde657901 | 780 | { |
mbed_official | 87:085cde657901 | 781 | /* Set the DMA Period elapsed callback */ |
mbed_official | 87:085cde657901 | 782 | htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = HAL_TIM_DMADelayPulseCplt; |
mbed_official | 87:085cde657901 | 783 | |
mbed_official | 87:085cde657901 | 784 | /* Set the DMA error callback */ |
mbed_official | 87:085cde657901 | 785 | htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = HAL_TIM_DMAError ; |
mbed_official | 87:085cde657901 | 786 | |
mbed_official | 87:085cde657901 | 787 | /* Enable the DMA Stream */ |
mbed_official | 87:085cde657901 | 788 | HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)pData, (uint32_t)&htim->Instance->CCR1, Length); |
mbed_official | 87:085cde657901 | 789 | |
mbed_official | 87:085cde657901 | 790 | /* Enable the TIM Capture/Compare 1 DMA request */ |
mbed_official | 87:085cde657901 | 791 | __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1); |
mbed_official | 87:085cde657901 | 792 | } |
mbed_official | 87:085cde657901 | 793 | break; |
mbed_official | 87:085cde657901 | 794 | |
mbed_official | 87:085cde657901 | 795 | case TIM_CHANNEL_2: |
mbed_official | 87:085cde657901 | 796 | { |
mbed_official | 87:085cde657901 | 797 | /* Set the DMA Period elapsed callback */ |
mbed_official | 87:085cde657901 | 798 | htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = HAL_TIM_DMADelayPulseCplt; |
mbed_official | 87:085cde657901 | 799 | |
mbed_official | 87:085cde657901 | 800 | /* Set the DMA error callback */ |
mbed_official | 87:085cde657901 | 801 | htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = HAL_TIM_DMAError ; |
mbed_official | 87:085cde657901 | 802 | |
mbed_official | 87:085cde657901 | 803 | /* Enable the DMA Stream */ |
mbed_official | 87:085cde657901 | 804 | HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)pData, (uint32_t)&htim->Instance->CCR2, Length); |
mbed_official | 87:085cde657901 | 805 | |
mbed_official | 87:085cde657901 | 806 | /* Enable the TIM Capture/Compare 2 DMA request */ |
mbed_official | 87:085cde657901 | 807 | __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC2); |
mbed_official | 87:085cde657901 | 808 | } |
mbed_official | 87:085cde657901 | 809 | break; |
mbed_official | 87:085cde657901 | 810 | |
mbed_official | 87:085cde657901 | 811 | case TIM_CHANNEL_3: |
mbed_official | 87:085cde657901 | 812 | { |
mbed_official | 87:085cde657901 | 813 | /* Set the DMA Period elapsed callback */ |
mbed_official | 87:085cde657901 | 814 | htim->hdma[TIM_DMA_ID_CC3]->XferCpltCallback = HAL_TIM_DMADelayPulseCplt; |
mbed_official | 87:085cde657901 | 815 | |
mbed_official | 87:085cde657901 | 816 | /* Set the DMA error callback */ |
mbed_official | 87:085cde657901 | 817 | htim->hdma[TIM_DMA_ID_CC3]->XferErrorCallback = HAL_TIM_DMAError ; |
mbed_official | 87:085cde657901 | 818 | |
mbed_official | 87:085cde657901 | 819 | /* Enable the DMA Stream */ |
mbed_official | 87:085cde657901 | 820 | HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)pData, (uint32_t)&htim->Instance->CCR3,Length); |
mbed_official | 87:085cde657901 | 821 | |
mbed_official | 87:085cde657901 | 822 | /* Enable the TIM Capture/Compare 3 DMA request */ |
mbed_official | 87:085cde657901 | 823 | __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC3); |
mbed_official | 87:085cde657901 | 824 | } |
mbed_official | 87:085cde657901 | 825 | break; |
mbed_official | 87:085cde657901 | 826 | |
mbed_official | 87:085cde657901 | 827 | case TIM_CHANNEL_4: |
mbed_official | 87:085cde657901 | 828 | { |
mbed_official | 87:085cde657901 | 829 | /* Set the DMA Period elapsed callback */ |
mbed_official | 87:085cde657901 | 830 | htim->hdma[TIM_DMA_ID_CC4]->XferCpltCallback = HAL_TIM_DMADelayPulseCplt; |
mbed_official | 87:085cde657901 | 831 | |
mbed_official | 87:085cde657901 | 832 | /* Set the DMA error callback */ |
mbed_official | 87:085cde657901 | 833 | htim->hdma[TIM_DMA_ID_CC4]->XferErrorCallback = HAL_TIM_DMAError ; |
mbed_official | 87:085cde657901 | 834 | |
mbed_official | 87:085cde657901 | 835 | /* Enable the DMA Stream */ |
mbed_official | 87:085cde657901 | 836 | HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC4], (uint32_t)pData, (uint32_t)&htim->Instance->CCR4, Length); |
mbed_official | 87:085cde657901 | 837 | |
mbed_official | 87:085cde657901 | 838 | /* Enable the TIM Capture/Compare 4 DMA request */ |
mbed_official | 87:085cde657901 | 839 | __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC4); |
mbed_official | 87:085cde657901 | 840 | } |
mbed_official | 87:085cde657901 | 841 | break; |
mbed_official | 87:085cde657901 | 842 | |
mbed_official | 87:085cde657901 | 843 | default: |
mbed_official | 87:085cde657901 | 844 | break; |
mbed_official | 87:085cde657901 | 845 | } |
mbed_official | 87:085cde657901 | 846 | |
mbed_official | 87:085cde657901 | 847 | /* Enable the Output compare channel */ |
mbed_official | 87:085cde657901 | 848 | TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE); |
mbed_official | 87:085cde657901 | 849 | |
mbed_official | 87:085cde657901 | 850 | if(IS_TIM_ADVANCED_INSTANCE(htim->Instance) != RESET) |
mbed_official | 87:085cde657901 | 851 | { |
mbed_official | 87:085cde657901 | 852 | /* Enable the main output */ |
mbed_official | 87:085cde657901 | 853 | __HAL_TIM_MOE_ENABLE(htim); |
mbed_official | 87:085cde657901 | 854 | } |
mbed_official | 87:085cde657901 | 855 | |
mbed_official | 87:085cde657901 | 856 | /* Enable the Peripheral */ |
mbed_official | 87:085cde657901 | 857 | __HAL_TIM_ENABLE(htim); |
mbed_official | 87:085cde657901 | 858 | |
mbed_official | 87:085cde657901 | 859 | /* Return function status */ |
mbed_official | 87:085cde657901 | 860 | return HAL_OK; |
mbed_official | 87:085cde657901 | 861 | } |
mbed_official | 87:085cde657901 | 862 | |
mbed_official | 87:085cde657901 | 863 | /** |
mbed_official | 87:085cde657901 | 864 | * @brief Stops the TIM Output Compare signal generation in DMA mode. |
mbed_official | 87:085cde657901 | 865 | * @param htim : TIM Output Compare handle |
mbed_official | 87:085cde657901 | 866 | * @param Channel : TIM Channel to be disabled |
mbed_official | 87:085cde657901 | 867 | * This parameter can be one of the following values: |
mbed_official | 87:085cde657901 | 868 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
mbed_official | 87:085cde657901 | 869 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
mbed_official | 87:085cde657901 | 870 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
mbed_official | 87:085cde657901 | 871 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
mbed_official | 87:085cde657901 | 872 | * @retval HAL status |
mbed_official | 87:085cde657901 | 873 | */ |
mbed_official | 87:085cde657901 | 874 | HAL_StatusTypeDef HAL_TIM_OC_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel) |
mbed_official | 87:085cde657901 | 875 | { |
mbed_official | 87:085cde657901 | 876 | /* Check the parameters */ |
mbed_official | 87:085cde657901 | 877 | assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); |
mbed_official | 87:085cde657901 | 878 | |
mbed_official | 87:085cde657901 | 879 | switch (Channel) |
mbed_official | 87:085cde657901 | 880 | { |
mbed_official | 87:085cde657901 | 881 | case TIM_CHANNEL_1: |
mbed_official | 87:085cde657901 | 882 | { |
mbed_official | 87:085cde657901 | 883 | /* Disable the TIM Capture/Compare 1 DMA request */ |
mbed_official | 87:085cde657901 | 884 | __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1); |
mbed_official | 87:085cde657901 | 885 | } |
mbed_official | 87:085cde657901 | 886 | break; |
mbed_official | 87:085cde657901 | 887 | |
mbed_official | 87:085cde657901 | 888 | case TIM_CHANNEL_2: |
mbed_official | 87:085cde657901 | 889 | { |
mbed_official | 87:085cde657901 | 890 | /* Disable the TIM Capture/Compare 2 DMA request */ |
mbed_official | 87:085cde657901 | 891 | __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC2); |
mbed_official | 87:085cde657901 | 892 | } |
mbed_official | 87:085cde657901 | 893 | break; |
mbed_official | 87:085cde657901 | 894 | |
mbed_official | 87:085cde657901 | 895 | case TIM_CHANNEL_3: |
mbed_official | 87:085cde657901 | 896 | { |
mbed_official | 87:085cde657901 | 897 | /* Disable the TIM Capture/Compare 3 DMA request */ |
mbed_official | 87:085cde657901 | 898 | __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC3); |
mbed_official | 87:085cde657901 | 899 | } |
mbed_official | 87:085cde657901 | 900 | break; |
mbed_official | 87:085cde657901 | 901 | |
mbed_official | 87:085cde657901 | 902 | case TIM_CHANNEL_4: |
mbed_official | 87:085cde657901 | 903 | { |
mbed_official | 87:085cde657901 | 904 | /* Disable the TIM Capture/Compare 4 interrupt */ |
mbed_official | 87:085cde657901 | 905 | __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC4); |
mbed_official | 87:085cde657901 | 906 | } |
mbed_official | 87:085cde657901 | 907 | break; |
mbed_official | 87:085cde657901 | 908 | |
mbed_official | 87:085cde657901 | 909 | default: |
mbed_official | 87:085cde657901 | 910 | break; |
mbed_official | 87:085cde657901 | 911 | } |
mbed_official | 87:085cde657901 | 912 | |
mbed_official | 87:085cde657901 | 913 | /* Disable the Output compare channel */ |
mbed_official | 87:085cde657901 | 914 | TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE); |
mbed_official | 87:085cde657901 | 915 | |
mbed_official | 87:085cde657901 | 916 | if(IS_TIM_ADVANCED_INSTANCE(htim->Instance) != RESET) |
mbed_official | 87:085cde657901 | 917 | { |
mbed_official | 87:085cde657901 | 918 | /* Disable the Main Ouput */ |
mbed_official | 87:085cde657901 | 919 | __HAL_TIM_MOE_DISABLE(htim); |
mbed_official | 87:085cde657901 | 920 | } |
mbed_official | 87:085cde657901 | 921 | |
mbed_official | 87:085cde657901 | 922 | /* Disable the Peripheral */ |
mbed_official | 87:085cde657901 | 923 | __HAL_TIM_DISABLE(htim); |
mbed_official | 87:085cde657901 | 924 | |
mbed_official | 87:085cde657901 | 925 | /* Change the htim state */ |
mbed_official | 87:085cde657901 | 926 | htim->State = HAL_TIM_STATE_READY; |
mbed_official | 87:085cde657901 | 927 | |
mbed_official | 87:085cde657901 | 928 | /* Return function status */ |
mbed_official | 87:085cde657901 | 929 | return HAL_OK; |
mbed_official | 87:085cde657901 | 930 | } |
mbed_official | 87:085cde657901 | 931 | |
mbed_official | 87:085cde657901 | 932 | /** |
mbed_official | 87:085cde657901 | 933 | * @} |
mbed_official | 87:085cde657901 | 934 | */ |
mbed_official | 87:085cde657901 | 935 | |
mbed_official | 87:085cde657901 | 936 | /** @defgroup TIM_Group3 Time PWM functions |
mbed_official | 87:085cde657901 | 937 | * @brief Time PWM functions |
mbed_official | 87:085cde657901 | 938 | * |
mbed_official | 87:085cde657901 | 939 | @verbatim |
mbed_official | 87:085cde657901 | 940 | ============================================================================== |
mbed_official | 87:085cde657901 | 941 | ##### Time PWM functions ##### |
mbed_official | 87:085cde657901 | 942 | ============================================================================== |
mbed_official | 87:085cde657901 | 943 | [..] |
mbed_official | 87:085cde657901 | 944 | This section provides functions allowing to: |
mbed_official | 87:085cde657901 | 945 | (+) Initialize and configure the TIM OPWM. |
mbed_official | 87:085cde657901 | 946 | (+) De-initialize the TIM PWM. |
mbed_official | 87:085cde657901 | 947 | (+) Start the Time PWM. |
mbed_official | 87:085cde657901 | 948 | (+) Stop the Time PWM. |
mbed_official | 87:085cde657901 | 949 | (+) Start the Time PWM and enable interrupt. |
mbed_official | 87:085cde657901 | 950 | (+) Stop the Time PWM and disable interrupt. |
mbed_official | 87:085cde657901 | 951 | (+) Start the Time PWM and enable DMA transfer. |
mbed_official | 87:085cde657901 | 952 | (+) Stop the Time PWM and disable DMA transfer. |
mbed_official | 87:085cde657901 | 953 | |
mbed_official | 87:085cde657901 | 954 | @endverbatim |
mbed_official | 87:085cde657901 | 955 | * @{ |
mbed_official | 87:085cde657901 | 956 | */ |
mbed_official | 87:085cde657901 | 957 | /** |
mbed_official | 87:085cde657901 | 958 | * @brief Initializes the TIM PWM Time Base according to the specified |
mbed_official | 87:085cde657901 | 959 | * parameters in the TIM_HandleTypeDef and create the associated handle. |
mbed_official | 87:085cde657901 | 960 | * @param htim: TIM handle |
mbed_official | 87:085cde657901 | 961 | * @retval HAL status |
mbed_official | 87:085cde657901 | 962 | */ |
mbed_official | 87:085cde657901 | 963 | HAL_StatusTypeDef HAL_TIM_PWM_Init(TIM_HandleTypeDef *htim) |
mbed_official | 87:085cde657901 | 964 | { |
mbed_official | 87:085cde657901 | 965 | /* Check the TIM handle allocation */ |
mbed_official | 87:085cde657901 | 966 | if(htim == NULL) |
mbed_official | 87:085cde657901 | 967 | { |
mbed_official | 87:085cde657901 | 968 | return HAL_ERROR; |
mbed_official | 87:085cde657901 | 969 | } |
mbed_official | 87:085cde657901 | 970 | |
mbed_official | 87:085cde657901 | 971 | /* Check the parameters */ |
mbed_official | 87:085cde657901 | 972 | assert_param(IS_TIM_INSTANCE(htim->Instance)); |
mbed_official | 87:085cde657901 | 973 | assert_param(IS_TIM_COUNTER_MODE(htim->Init.CounterMode)); |
mbed_official | 87:085cde657901 | 974 | assert_param(IS_TIM_CLOCKDIVISION_DIV(htim->Init.ClockDivision)); |
mbed_official | 87:085cde657901 | 975 | |
mbed_official | 87:085cde657901 | 976 | if(htim->State == HAL_TIM_STATE_RESET) |
mbed_official | 87:085cde657901 | 977 | { |
mbed_official | 87:085cde657901 | 978 | /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */ |
mbed_official | 87:085cde657901 | 979 | HAL_TIM_PWM_MspInit(htim); |
mbed_official | 87:085cde657901 | 980 | } |
mbed_official | 87:085cde657901 | 981 | |
mbed_official | 87:085cde657901 | 982 | /* Set the TIM state */ |
mbed_official | 87:085cde657901 | 983 | htim->State= HAL_TIM_STATE_BUSY; |
mbed_official | 87:085cde657901 | 984 | |
mbed_official | 87:085cde657901 | 985 | /* Init the base time for the PWM */ |
mbed_official | 87:085cde657901 | 986 | TIM_Base_SetConfig(htim->Instance, &htim->Init); |
mbed_official | 87:085cde657901 | 987 | |
mbed_official | 87:085cde657901 | 988 | /* Initialize the TIM state*/ |
mbed_official | 87:085cde657901 | 989 | htim->State= HAL_TIM_STATE_READY; |
mbed_official | 87:085cde657901 | 990 | |
mbed_official | 87:085cde657901 | 991 | return HAL_OK; |
mbed_official | 87:085cde657901 | 992 | } |
mbed_official | 87:085cde657901 | 993 | |
mbed_official | 87:085cde657901 | 994 | /** |
mbed_official | 87:085cde657901 | 995 | * @brief DeInitializes the TIM peripheral |
mbed_official | 87:085cde657901 | 996 | * @param htim: TIM handle |
mbed_official | 87:085cde657901 | 997 | * @retval HAL status |
mbed_official | 87:085cde657901 | 998 | */ |
mbed_official | 87:085cde657901 | 999 | HAL_StatusTypeDef HAL_TIM_PWM_DeInit(TIM_HandleTypeDef *htim) |
mbed_official | 87:085cde657901 | 1000 | { |
mbed_official | 87:085cde657901 | 1001 | /* Check the parameters */ |
mbed_official | 87:085cde657901 | 1002 | assert_param(IS_TIM_INSTANCE(htim->Instance)); |
mbed_official | 87:085cde657901 | 1003 | |
mbed_official | 87:085cde657901 | 1004 | htim->State = HAL_TIM_STATE_BUSY; |
mbed_official | 87:085cde657901 | 1005 | |
mbed_official | 87:085cde657901 | 1006 | /* Disable the TIM Peripheral Clock */ |
mbed_official | 87:085cde657901 | 1007 | __HAL_TIM_DISABLE(htim); |
mbed_official | 87:085cde657901 | 1008 | |
mbed_official | 87:085cde657901 | 1009 | /* DeInit the low level hardware: GPIO, CLOCK, NVIC and DMA */ |
mbed_official | 87:085cde657901 | 1010 | HAL_TIM_PWM_MspDeInit(htim); |
mbed_official | 87:085cde657901 | 1011 | |
mbed_official | 87:085cde657901 | 1012 | /* Change TIM state */ |
mbed_official | 87:085cde657901 | 1013 | htim->State = HAL_TIM_STATE_RESET; |
mbed_official | 106:ced8cbb51063 | 1014 | |
mbed_official | 106:ced8cbb51063 | 1015 | /* Release Lock */ |
mbed_official | 106:ced8cbb51063 | 1016 | __HAL_UNLOCK(htim); |
mbed_official | 106:ced8cbb51063 | 1017 | |
mbed_official | 87:085cde657901 | 1018 | return HAL_OK; |
mbed_official | 87:085cde657901 | 1019 | } |
mbed_official | 87:085cde657901 | 1020 | |
mbed_official | 87:085cde657901 | 1021 | /** |
mbed_official | 87:085cde657901 | 1022 | * @brief Initializes the TIM PWM MSP. |
mbed_official | 87:085cde657901 | 1023 | * @param htim: TIM handle |
mbed_official | 87:085cde657901 | 1024 | * @retval None |
mbed_official | 87:085cde657901 | 1025 | */ |
mbed_official | 87:085cde657901 | 1026 | __weak void HAL_TIM_PWM_MspInit(TIM_HandleTypeDef *htim) |
mbed_official | 87:085cde657901 | 1027 | { |
mbed_official | 87:085cde657901 | 1028 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 87:085cde657901 | 1029 | the HAL_TIM_PWM_MspInit could be implemented in the user file |
mbed_official | 87:085cde657901 | 1030 | */ |
mbed_official | 87:085cde657901 | 1031 | } |
mbed_official | 87:085cde657901 | 1032 | |
mbed_official | 87:085cde657901 | 1033 | /** |
mbed_official | 87:085cde657901 | 1034 | * @brief DeInitializes TIM PWM MSP. |
mbed_official | 87:085cde657901 | 1035 | * @param htim: TIM handle |
mbed_official | 87:085cde657901 | 1036 | * @retval None |
mbed_official | 87:085cde657901 | 1037 | */ |
mbed_official | 87:085cde657901 | 1038 | __weak void HAL_TIM_PWM_MspDeInit(TIM_HandleTypeDef *htim) |
mbed_official | 87:085cde657901 | 1039 | { |
mbed_official | 87:085cde657901 | 1040 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 87:085cde657901 | 1041 | the HAL_TIM_PWM_MspDeInit could be implemented in the user file |
mbed_official | 87:085cde657901 | 1042 | */ |
mbed_official | 87:085cde657901 | 1043 | } |
mbed_official | 87:085cde657901 | 1044 | |
mbed_official | 87:085cde657901 | 1045 | /** |
mbed_official | 87:085cde657901 | 1046 | * @brief Starts the PWM signal generation. |
mbed_official | 87:085cde657901 | 1047 | * @param htim : TIM handle |
mbed_official | 87:085cde657901 | 1048 | * @param Channel : TIM Channels to be enabled |
mbed_official | 87:085cde657901 | 1049 | * This parameter can be one of the following values: |
mbed_official | 87:085cde657901 | 1050 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
mbed_official | 87:085cde657901 | 1051 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
mbed_official | 87:085cde657901 | 1052 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
mbed_official | 87:085cde657901 | 1053 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
mbed_official | 87:085cde657901 | 1054 | * @retval HAL status |
mbed_official | 87:085cde657901 | 1055 | */ |
mbed_official | 87:085cde657901 | 1056 | HAL_StatusTypeDef HAL_TIM_PWM_Start(TIM_HandleTypeDef *htim, uint32_t Channel) |
mbed_official | 87:085cde657901 | 1057 | { |
mbed_official | 87:085cde657901 | 1058 | /* Check the parameters */ |
mbed_official | 87:085cde657901 | 1059 | assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); |
mbed_official | 87:085cde657901 | 1060 | |
mbed_official | 87:085cde657901 | 1061 | /* Enable the Capture compare channel */ |
mbed_official | 87:085cde657901 | 1062 | TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE); |
mbed_official | 87:085cde657901 | 1063 | |
mbed_official | 87:085cde657901 | 1064 | if(IS_TIM_ADVANCED_INSTANCE(htim->Instance) != RESET) |
mbed_official | 87:085cde657901 | 1065 | { |
mbed_official | 87:085cde657901 | 1066 | /* Enable the main output */ |
mbed_official | 87:085cde657901 | 1067 | __HAL_TIM_MOE_ENABLE(htim); |
mbed_official | 87:085cde657901 | 1068 | } |
mbed_official | 87:085cde657901 | 1069 | |
mbed_official | 87:085cde657901 | 1070 | /* Enable the Peripheral */ |
mbed_official | 87:085cde657901 | 1071 | __HAL_TIM_ENABLE(htim); |
mbed_official | 87:085cde657901 | 1072 | |
mbed_official | 87:085cde657901 | 1073 | /* Return function status */ |
mbed_official | 87:085cde657901 | 1074 | return HAL_OK; |
mbed_official | 87:085cde657901 | 1075 | } |
mbed_official | 87:085cde657901 | 1076 | |
mbed_official | 87:085cde657901 | 1077 | /** |
mbed_official | 87:085cde657901 | 1078 | * @brief Stops the PWM signal generation. |
mbed_official | 87:085cde657901 | 1079 | * @param htim : TIM handle |
mbed_official | 87:085cde657901 | 1080 | * @param Channel : TIM Channels to be disabled |
mbed_official | 87:085cde657901 | 1081 | * This parameter can be one of the following values: |
mbed_official | 87:085cde657901 | 1082 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
mbed_official | 87:085cde657901 | 1083 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
mbed_official | 87:085cde657901 | 1084 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
mbed_official | 87:085cde657901 | 1085 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
mbed_official | 87:085cde657901 | 1086 | * @retval HAL status |
mbed_official | 87:085cde657901 | 1087 | */ |
mbed_official | 87:085cde657901 | 1088 | HAL_StatusTypeDef HAL_TIM_PWM_Stop(TIM_HandleTypeDef *htim, uint32_t Channel) |
mbed_official | 87:085cde657901 | 1089 | { |
mbed_official | 87:085cde657901 | 1090 | /* Check the parameters */ |
mbed_official | 87:085cde657901 | 1091 | assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); |
mbed_official | 87:085cde657901 | 1092 | |
mbed_official | 87:085cde657901 | 1093 | /* Disable the Capture compare channel */ |
mbed_official | 87:085cde657901 | 1094 | TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE); |
mbed_official | 87:085cde657901 | 1095 | |
mbed_official | 87:085cde657901 | 1096 | if(IS_TIM_ADVANCED_INSTANCE(htim->Instance) != RESET) |
mbed_official | 87:085cde657901 | 1097 | { |
mbed_official | 87:085cde657901 | 1098 | /* Disable the Main Ouput */ |
mbed_official | 87:085cde657901 | 1099 | __HAL_TIM_MOE_DISABLE(htim); |
mbed_official | 87:085cde657901 | 1100 | } |
mbed_official | 87:085cde657901 | 1101 | |
mbed_official | 87:085cde657901 | 1102 | /* Disable the Peripheral */ |
mbed_official | 87:085cde657901 | 1103 | __HAL_TIM_DISABLE(htim); |
mbed_official | 87:085cde657901 | 1104 | |
mbed_official | 87:085cde657901 | 1105 | /* Change the htim state */ |
mbed_official | 87:085cde657901 | 1106 | htim->State = HAL_TIM_STATE_READY; |
mbed_official | 87:085cde657901 | 1107 | |
mbed_official | 87:085cde657901 | 1108 | /* Return function status */ |
mbed_official | 87:085cde657901 | 1109 | return HAL_OK; |
mbed_official | 87:085cde657901 | 1110 | } |
mbed_official | 87:085cde657901 | 1111 | |
mbed_official | 87:085cde657901 | 1112 | /** |
mbed_official | 87:085cde657901 | 1113 | * @brief Starts the PWM signal generation in interrupt mode. |
mbed_official | 87:085cde657901 | 1114 | * @param htim : TIM handle |
mbed_official | 87:085cde657901 | 1115 | * @param Channel : TIM Channel to be disabled |
mbed_official | 87:085cde657901 | 1116 | * This parameter can be one of the following values: |
mbed_official | 87:085cde657901 | 1117 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
mbed_official | 87:085cde657901 | 1118 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
mbed_official | 87:085cde657901 | 1119 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
mbed_official | 87:085cde657901 | 1120 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
mbed_official | 87:085cde657901 | 1121 | * @retval HAL status |
mbed_official | 87:085cde657901 | 1122 | */ |
mbed_official | 87:085cde657901 | 1123 | HAL_StatusTypeDef HAL_TIM_PWM_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel) |
mbed_official | 87:085cde657901 | 1124 | { |
mbed_official | 87:085cde657901 | 1125 | /* Check the parameters */ |
mbed_official | 87:085cde657901 | 1126 | assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); |
mbed_official | 87:085cde657901 | 1127 | |
mbed_official | 87:085cde657901 | 1128 | switch (Channel) |
mbed_official | 87:085cde657901 | 1129 | { |
mbed_official | 87:085cde657901 | 1130 | case TIM_CHANNEL_1: |
mbed_official | 87:085cde657901 | 1131 | { |
mbed_official | 87:085cde657901 | 1132 | /* Enable the TIM Capture/Compare 1 interrupt */ |
mbed_official | 87:085cde657901 | 1133 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1); |
mbed_official | 87:085cde657901 | 1134 | } |
mbed_official | 87:085cde657901 | 1135 | break; |
mbed_official | 87:085cde657901 | 1136 | |
mbed_official | 87:085cde657901 | 1137 | case TIM_CHANNEL_2: |
mbed_official | 87:085cde657901 | 1138 | { |
mbed_official | 87:085cde657901 | 1139 | /* Enable the TIM Capture/Compare 2 interrupt */ |
mbed_official | 87:085cde657901 | 1140 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2); |
mbed_official | 87:085cde657901 | 1141 | } |
mbed_official | 87:085cde657901 | 1142 | break; |
mbed_official | 87:085cde657901 | 1143 | |
mbed_official | 87:085cde657901 | 1144 | case TIM_CHANNEL_3: |
mbed_official | 87:085cde657901 | 1145 | { |
mbed_official | 87:085cde657901 | 1146 | /* Enable the TIM Capture/Compare 3 interrupt */ |
mbed_official | 87:085cde657901 | 1147 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC3); |
mbed_official | 87:085cde657901 | 1148 | } |
mbed_official | 87:085cde657901 | 1149 | break; |
mbed_official | 87:085cde657901 | 1150 | |
mbed_official | 87:085cde657901 | 1151 | case TIM_CHANNEL_4: |
mbed_official | 87:085cde657901 | 1152 | { |
mbed_official | 87:085cde657901 | 1153 | /* Enable the TIM Capture/Compare 4 interrupt */ |
mbed_official | 87:085cde657901 | 1154 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC4); |
mbed_official | 87:085cde657901 | 1155 | } |
mbed_official | 87:085cde657901 | 1156 | break; |
mbed_official | 87:085cde657901 | 1157 | |
mbed_official | 87:085cde657901 | 1158 | default: |
mbed_official | 87:085cde657901 | 1159 | break; |
mbed_official | 87:085cde657901 | 1160 | } |
mbed_official | 87:085cde657901 | 1161 | |
mbed_official | 87:085cde657901 | 1162 | /* Enable the Capture compare channel */ |
mbed_official | 87:085cde657901 | 1163 | TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE); |
mbed_official | 87:085cde657901 | 1164 | |
mbed_official | 87:085cde657901 | 1165 | if(IS_TIM_ADVANCED_INSTANCE(htim->Instance) != RESET) |
mbed_official | 87:085cde657901 | 1166 | { |
mbed_official | 87:085cde657901 | 1167 | /* Enable the main output */ |
mbed_official | 87:085cde657901 | 1168 | __HAL_TIM_MOE_ENABLE(htim); |
mbed_official | 87:085cde657901 | 1169 | } |
mbed_official | 87:085cde657901 | 1170 | |
mbed_official | 87:085cde657901 | 1171 | /* Enable the Peripheral */ |
mbed_official | 87:085cde657901 | 1172 | __HAL_TIM_ENABLE(htim); |
mbed_official | 87:085cde657901 | 1173 | |
mbed_official | 87:085cde657901 | 1174 | /* Return function status */ |
mbed_official | 87:085cde657901 | 1175 | return HAL_OK; |
mbed_official | 87:085cde657901 | 1176 | } |
mbed_official | 87:085cde657901 | 1177 | |
mbed_official | 87:085cde657901 | 1178 | /** |
mbed_official | 87:085cde657901 | 1179 | * @brief Stops the PWM signal generation in interrupt mode. |
mbed_official | 87:085cde657901 | 1180 | * @param htim : TIM handle |
mbed_official | 87:085cde657901 | 1181 | * @param Channel : TIM Channels to be disabled |
mbed_official | 87:085cde657901 | 1182 | * This parameter can be one of the following values: |
mbed_official | 87:085cde657901 | 1183 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
mbed_official | 87:085cde657901 | 1184 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
mbed_official | 87:085cde657901 | 1185 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
mbed_official | 87:085cde657901 | 1186 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
mbed_official | 87:085cde657901 | 1187 | * @retval HAL status |
mbed_official | 87:085cde657901 | 1188 | */ |
mbed_official | 87:085cde657901 | 1189 | HAL_StatusTypeDef HAL_TIM_PWM_Stop_IT (TIM_HandleTypeDef *htim, uint32_t Channel) |
mbed_official | 87:085cde657901 | 1190 | { |
mbed_official | 87:085cde657901 | 1191 | /* Check the parameters */ |
mbed_official | 87:085cde657901 | 1192 | assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); |
mbed_official | 87:085cde657901 | 1193 | |
mbed_official | 87:085cde657901 | 1194 | switch (Channel) |
mbed_official | 87:085cde657901 | 1195 | { |
mbed_official | 87:085cde657901 | 1196 | case TIM_CHANNEL_1: |
mbed_official | 87:085cde657901 | 1197 | { |
mbed_official | 87:085cde657901 | 1198 | /* Disable the TIM Capture/Compare 1 interrupt */ |
mbed_official | 87:085cde657901 | 1199 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1); |
mbed_official | 87:085cde657901 | 1200 | } |
mbed_official | 87:085cde657901 | 1201 | break; |
mbed_official | 87:085cde657901 | 1202 | |
mbed_official | 87:085cde657901 | 1203 | case TIM_CHANNEL_2: |
mbed_official | 87:085cde657901 | 1204 | { |
mbed_official | 87:085cde657901 | 1205 | /* Disable the TIM Capture/Compare 2 interrupt */ |
mbed_official | 87:085cde657901 | 1206 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2); |
mbed_official | 87:085cde657901 | 1207 | } |
mbed_official | 87:085cde657901 | 1208 | break; |
mbed_official | 87:085cde657901 | 1209 | |
mbed_official | 87:085cde657901 | 1210 | case TIM_CHANNEL_3: |
mbed_official | 87:085cde657901 | 1211 | { |
mbed_official | 87:085cde657901 | 1212 | /* Disable the TIM Capture/Compare 3 interrupt */ |
mbed_official | 87:085cde657901 | 1213 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC3); |
mbed_official | 87:085cde657901 | 1214 | } |
mbed_official | 87:085cde657901 | 1215 | break; |
mbed_official | 87:085cde657901 | 1216 | |
mbed_official | 87:085cde657901 | 1217 | case TIM_CHANNEL_4: |
mbed_official | 87:085cde657901 | 1218 | { |
mbed_official | 87:085cde657901 | 1219 | /* Disable the TIM Capture/Compare 4 interrupt */ |
mbed_official | 87:085cde657901 | 1220 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC4); |
mbed_official | 87:085cde657901 | 1221 | } |
mbed_official | 87:085cde657901 | 1222 | break; |
mbed_official | 87:085cde657901 | 1223 | |
mbed_official | 87:085cde657901 | 1224 | default: |
mbed_official | 87:085cde657901 | 1225 | break; |
mbed_official | 87:085cde657901 | 1226 | } |
mbed_official | 87:085cde657901 | 1227 | |
mbed_official | 87:085cde657901 | 1228 | /* Disable the Capture compare channel */ |
mbed_official | 87:085cde657901 | 1229 | TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE); |
mbed_official | 87:085cde657901 | 1230 | |
mbed_official | 87:085cde657901 | 1231 | if(IS_TIM_ADVANCED_INSTANCE(htim->Instance) != RESET) |
mbed_official | 87:085cde657901 | 1232 | { |
mbed_official | 87:085cde657901 | 1233 | /* Disable the Main Ouput */ |
mbed_official | 87:085cde657901 | 1234 | __HAL_TIM_MOE_DISABLE(htim); |
mbed_official | 87:085cde657901 | 1235 | } |
mbed_official | 87:085cde657901 | 1236 | |
mbed_official | 87:085cde657901 | 1237 | /* Disable the Peripheral */ |
mbed_official | 87:085cde657901 | 1238 | __HAL_TIM_DISABLE(htim); |
mbed_official | 87:085cde657901 | 1239 | |
mbed_official | 87:085cde657901 | 1240 | /* Return function status */ |
mbed_official | 87:085cde657901 | 1241 | return HAL_OK; |
mbed_official | 87:085cde657901 | 1242 | } |
mbed_official | 87:085cde657901 | 1243 | |
mbed_official | 87:085cde657901 | 1244 | /** |
mbed_official | 87:085cde657901 | 1245 | * @brief Starts the TIM PWM signal generation in DMA mode. |
mbed_official | 87:085cde657901 | 1246 | * @param htim : TIM handle |
mbed_official | 87:085cde657901 | 1247 | * @param Channel : TIM Channels to be enabled |
mbed_official | 87:085cde657901 | 1248 | * This parameter can be one of the following values: |
mbed_official | 87:085cde657901 | 1249 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
mbed_official | 87:085cde657901 | 1250 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
mbed_official | 87:085cde657901 | 1251 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
mbed_official | 87:085cde657901 | 1252 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
mbed_official | 87:085cde657901 | 1253 | * @param pData: The source Buffer address. |
mbed_official | 87:085cde657901 | 1254 | * @param Length: The length of data to be transferred from memory to TIM peripheral |
mbed_official | 87:085cde657901 | 1255 | * @retval HAL status |
mbed_official | 87:085cde657901 | 1256 | */ |
mbed_official | 87:085cde657901 | 1257 | HAL_StatusTypeDef HAL_TIM_PWM_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length) |
mbed_official | 87:085cde657901 | 1258 | { |
mbed_official | 87:085cde657901 | 1259 | /* Check the parameters */ |
mbed_official | 87:085cde657901 | 1260 | assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); |
mbed_official | 87:085cde657901 | 1261 | |
mbed_official | 87:085cde657901 | 1262 | if((htim->State == HAL_TIM_STATE_BUSY)) |
mbed_official | 87:085cde657901 | 1263 | { |
mbed_official | 87:085cde657901 | 1264 | return HAL_BUSY; |
mbed_official | 87:085cde657901 | 1265 | } |
mbed_official | 87:085cde657901 | 1266 | else if((htim->State == HAL_TIM_STATE_READY)) |
mbed_official | 87:085cde657901 | 1267 | { |
mbed_official | 87:085cde657901 | 1268 | if(((uint32_t)pData == 0 ) && (Length > 0)) |
mbed_official | 87:085cde657901 | 1269 | { |
mbed_official | 87:085cde657901 | 1270 | return HAL_ERROR; |
mbed_official | 87:085cde657901 | 1271 | } |
mbed_official | 87:085cde657901 | 1272 | else |
mbed_official | 87:085cde657901 | 1273 | { |
mbed_official | 87:085cde657901 | 1274 | htim->State = HAL_TIM_STATE_BUSY; |
mbed_official | 87:085cde657901 | 1275 | } |
mbed_official | 87:085cde657901 | 1276 | } |
mbed_official | 87:085cde657901 | 1277 | switch (Channel) |
mbed_official | 87:085cde657901 | 1278 | { |
mbed_official | 87:085cde657901 | 1279 | case TIM_CHANNEL_1: |
mbed_official | 87:085cde657901 | 1280 | { |
mbed_official | 87:085cde657901 | 1281 | /* Set the DMA Period elapsed callback */ |
mbed_official | 87:085cde657901 | 1282 | htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = HAL_TIM_DMADelayPulseCplt; |
mbed_official | 87:085cde657901 | 1283 | |
mbed_official | 87:085cde657901 | 1284 | /* Set the DMA error callback */ |
mbed_official | 87:085cde657901 | 1285 | htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = HAL_TIM_DMAError ; |
mbed_official | 87:085cde657901 | 1286 | |
mbed_official | 87:085cde657901 | 1287 | /* Enable the DMA Stream */ |
mbed_official | 87:085cde657901 | 1288 | HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)pData, (uint32_t)&htim->Instance->CCR1, Length); |
mbed_official | 87:085cde657901 | 1289 | |
mbed_official | 87:085cde657901 | 1290 | /* Enable the TIM Capture/Compare 1 DMA request */ |
mbed_official | 87:085cde657901 | 1291 | __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1); |
mbed_official | 87:085cde657901 | 1292 | } |
mbed_official | 87:085cde657901 | 1293 | break; |
mbed_official | 87:085cde657901 | 1294 | |
mbed_official | 87:085cde657901 | 1295 | case TIM_CHANNEL_2: |
mbed_official | 87:085cde657901 | 1296 | { |
mbed_official | 87:085cde657901 | 1297 | /* Set the DMA Period elapsed callback */ |
mbed_official | 87:085cde657901 | 1298 | htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = HAL_TIM_DMADelayPulseCplt; |
mbed_official | 87:085cde657901 | 1299 | |
mbed_official | 87:085cde657901 | 1300 | /* Set the DMA error callback */ |
mbed_official | 87:085cde657901 | 1301 | htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = HAL_TIM_DMAError ; |
mbed_official | 87:085cde657901 | 1302 | |
mbed_official | 87:085cde657901 | 1303 | /* Enable the DMA Stream */ |
mbed_official | 87:085cde657901 | 1304 | HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)pData, (uint32_t)&htim->Instance->CCR2, Length); |
mbed_official | 87:085cde657901 | 1305 | |
mbed_official | 87:085cde657901 | 1306 | /* Enable the TIM Capture/Compare 2 DMA request */ |
mbed_official | 87:085cde657901 | 1307 | __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC2); |
mbed_official | 87:085cde657901 | 1308 | } |
mbed_official | 87:085cde657901 | 1309 | break; |
mbed_official | 87:085cde657901 | 1310 | |
mbed_official | 87:085cde657901 | 1311 | case TIM_CHANNEL_3: |
mbed_official | 87:085cde657901 | 1312 | { |
mbed_official | 87:085cde657901 | 1313 | /* Set the DMA Period elapsed callback */ |
mbed_official | 87:085cde657901 | 1314 | htim->hdma[TIM_DMA_ID_CC3]->XferCpltCallback = HAL_TIM_DMADelayPulseCplt; |
mbed_official | 87:085cde657901 | 1315 | |
mbed_official | 87:085cde657901 | 1316 | /* Set the DMA error callback */ |
mbed_official | 87:085cde657901 | 1317 | htim->hdma[TIM_DMA_ID_CC3]->XferErrorCallback = HAL_TIM_DMAError ; |
mbed_official | 87:085cde657901 | 1318 | |
mbed_official | 87:085cde657901 | 1319 | /* Enable the DMA Stream */ |
mbed_official | 87:085cde657901 | 1320 | HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)pData, (uint32_t)&htim->Instance->CCR3,Length); |
mbed_official | 87:085cde657901 | 1321 | |
mbed_official | 87:085cde657901 | 1322 | /* Enable the TIM Output Capture/Compare 3 request */ |
mbed_official | 87:085cde657901 | 1323 | __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC3); |
mbed_official | 87:085cde657901 | 1324 | } |
mbed_official | 87:085cde657901 | 1325 | break; |
mbed_official | 87:085cde657901 | 1326 | |
mbed_official | 87:085cde657901 | 1327 | case TIM_CHANNEL_4: |
mbed_official | 87:085cde657901 | 1328 | { |
mbed_official | 87:085cde657901 | 1329 | /* Set the DMA Period elapsed callback */ |
mbed_official | 87:085cde657901 | 1330 | htim->hdma[TIM_DMA_ID_CC4]->XferCpltCallback = HAL_TIM_DMADelayPulseCplt; |
mbed_official | 87:085cde657901 | 1331 | |
mbed_official | 87:085cde657901 | 1332 | /* Set the DMA error callback */ |
mbed_official | 87:085cde657901 | 1333 | htim->hdma[TIM_DMA_ID_CC4]->XferErrorCallback = HAL_TIM_DMAError ; |
mbed_official | 87:085cde657901 | 1334 | |
mbed_official | 87:085cde657901 | 1335 | /* Enable the DMA Stream */ |
mbed_official | 87:085cde657901 | 1336 | HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC4], (uint32_t)pData, (uint32_t)&htim->Instance->CCR4, Length); |
mbed_official | 87:085cde657901 | 1337 | |
mbed_official | 87:085cde657901 | 1338 | /* Enable the TIM Capture/Compare 4 DMA request */ |
mbed_official | 87:085cde657901 | 1339 | __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC4); |
mbed_official | 87:085cde657901 | 1340 | } |
mbed_official | 87:085cde657901 | 1341 | break; |
mbed_official | 87:085cde657901 | 1342 | |
mbed_official | 87:085cde657901 | 1343 | default: |
mbed_official | 87:085cde657901 | 1344 | break; |
mbed_official | 87:085cde657901 | 1345 | } |
mbed_official | 87:085cde657901 | 1346 | |
mbed_official | 87:085cde657901 | 1347 | /* Enable the Capture compare channel */ |
mbed_official | 87:085cde657901 | 1348 | TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE); |
mbed_official | 87:085cde657901 | 1349 | |
mbed_official | 87:085cde657901 | 1350 | if(IS_TIM_ADVANCED_INSTANCE(htim->Instance) != RESET) |
mbed_official | 87:085cde657901 | 1351 | { |
mbed_official | 87:085cde657901 | 1352 | /* Enable the main output */ |
mbed_official | 87:085cde657901 | 1353 | __HAL_TIM_MOE_ENABLE(htim); |
mbed_official | 87:085cde657901 | 1354 | } |
mbed_official | 87:085cde657901 | 1355 | |
mbed_official | 87:085cde657901 | 1356 | /* Enable the Peripheral */ |
mbed_official | 87:085cde657901 | 1357 | __HAL_TIM_ENABLE(htim); |
mbed_official | 87:085cde657901 | 1358 | |
mbed_official | 87:085cde657901 | 1359 | /* Return function status */ |
mbed_official | 87:085cde657901 | 1360 | return HAL_OK; |
mbed_official | 87:085cde657901 | 1361 | } |
mbed_official | 87:085cde657901 | 1362 | |
mbed_official | 87:085cde657901 | 1363 | /** |
mbed_official | 87:085cde657901 | 1364 | * @brief Stops the TIM PWM signal generation in DMA mode. |
mbed_official | 87:085cde657901 | 1365 | * @param htim : TIM handle |
mbed_official | 87:085cde657901 | 1366 | * @param Channel : TIM Channels to be disabled |
mbed_official | 87:085cde657901 | 1367 | * This parameter can be one of the following values: |
mbed_official | 87:085cde657901 | 1368 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
mbed_official | 87:085cde657901 | 1369 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
mbed_official | 87:085cde657901 | 1370 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
mbed_official | 87:085cde657901 | 1371 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
mbed_official | 87:085cde657901 | 1372 | * @retval HAL status |
mbed_official | 87:085cde657901 | 1373 | */ |
mbed_official | 87:085cde657901 | 1374 | HAL_StatusTypeDef HAL_TIM_PWM_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel) |
mbed_official | 87:085cde657901 | 1375 | { |
mbed_official | 87:085cde657901 | 1376 | /* Check the parameters */ |
mbed_official | 87:085cde657901 | 1377 | assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); |
mbed_official | 87:085cde657901 | 1378 | |
mbed_official | 87:085cde657901 | 1379 | switch (Channel) |
mbed_official | 87:085cde657901 | 1380 | { |
mbed_official | 87:085cde657901 | 1381 | case TIM_CHANNEL_1: |
mbed_official | 87:085cde657901 | 1382 | { |
mbed_official | 87:085cde657901 | 1383 | /* Disable the TIM Capture/Compare 1 DMA request */ |
mbed_official | 87:085cde657901 | 1384 | __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1); |
mbed_official | 87:085cde657901 | 1385 | } |
mbed_official | 87:085cde657901 | 1386 | break; |
mbed_official | 87:085cde657901 | 1387 | |
mbed_official | 87:085cde657901 | 1388 | case TIM_CHANNEL_2: |
mbed_official | 87:085cde657901 | 1389 | { |
mbed_official | 87:085cde657901 | 1390 | /* Disable the TIM Capture/Compare 2 DMA request */ |
mbed_official | 87:085cde657901 | 1391 | __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC2); |
mbed_official | 87:085cde657901 | 1392 | } |
mbed_official | 87:085cde657901 | 1393 | break; |
mbed_official | 87:085cde657901 | 1394 | |
mbed_official | 87:085cde657901 | 1395 | case TIM_CHANNEL_3: |
mbed_official | 87:085cde657901 | 1396 | { |
mbed_official | 87:085cde657901 | 1397 | /* Disable the TIM Capture/Compare 3 DMA request */ |
mbed_official | 87:085cde657901 | 1398 | __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC3); |
mbed_official | 87:085cde657901 | 1399 | } |
mbed_official | 87:085cde657901 | 1400 | break; |
mbed_official | 87:085cde657901 | 1401 | |
mbed_official | 87:085cde657901 | 1402 | case TIM_CHANNEL_4: |
mbed_official | 87:085cde657901 | 1403 | { |
mbed_official | 87:085cde657901 | 1404 | /* Disable the TIM Capture/Compare 4 interrupt */ |
mbed_official | 87:085cde657901 | 1405 | __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC4); |
mbed_official | 87:085cde657901 | 1406 | } |
mbed_official | 87:085cde657901 | 1407 | break; |
mbed_official | 87:085cde657901 | 1408 | |
mbed_official | 87:085cde657901 | 1409 | default: |
mbed_official | 87:085cde657901 | 1410 | break; |
mbed_official | 87:085cde657901 | 1411 | } |
mbed_official | 87:085cde657901 | 1412 | |
mbed_official | 87:085cde657901 | 1413 | /* Disable the Capture compare channel */ |
mbed_official | 87:085cde657901 | 1414 | TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE); |
mbed_official | 87:085cde657901 | 1415 | |
mbed_official | 87:085cde657901 | 1416 | if(IS_TIM_ADVANCED_INSTANCE(htim->Instance) != RESET) |
mbed_official | 87:085cde657901 | 1417 | { |
mbed_official | 87:085cde657901 | 1418 | /* Disable the Main Ouput */ |
mbed_official | 87:085cde657901 | 1419 | __HAL_TIM_MOE_DISABLE(htim); |
mbed_official | 87:085cde657901 | 1420 | } |
mbed_official | 87:085cde657901 | 1421 | |
mbed_official | 87:085cde657901 | 1422 | /* Disable the Peripheral */ |
mbed_official | 87:085cde657901 | 1423 | __HAL_TIM_DISABLE(htim); |
mbed_official | 87:085cde657901 | 1424 | |
mbed_official | 87:085cde657901 | 1425 | /* Change the htim state */ |
mbed_official | 87:085cde657901 | 1426 | htim->State = HAL_TIM_STATE_READY; |
mbed_official | 87:085cde657901 | 1427 | |
mbed_official | 87:085cde657901 | 1428 | /* Return function status */ |
mbed_official | 87:085cde657901 | 1429 | return HAL_OK; |
mbed_official | 87:085cde657901 | 1430 | } |
mbed_official | 87:085cde657901 | 1431 | |
mbed_official | 87:085cde657901 | 1432 | /** |
mbed_official | 87:085cde657901 | 1433 | * @} |
mbed_official | 87:085cde657901 | 1434 | */ |
mbed_official | 87:085cde657901 | 1435 | |
mbed_official | 87:085cde657901 | 1436 | /** @defgroup TIM_Group4 Time Input Capture functions |
mbed_official | 87:085cde657901 | 1437 | * @brief Time Input Capture functions |
mbed_official | 87:085cde657901 | 1438 | * |
mbed_official | 87:085cde657901 | 1439 | @verbatim |
mbed_official | 87:085cde657901 | 1440 | ============================================================================== |
mbed_official | 87:085cde657901 | 1441 | ##### Time Input Capture functions ##### |
mbed_official | 87:085cde657901 | 1442 | ============================================================================== |
mbed_official | 87:085cde657901 | 1443 | [..] |
mbed_official | 87:085cde657901 | 1444 | This section provides functions allowing to: |
mbed_official | 87:085cde657901 | 1445 | (+) Initialize and configure the TIM Input Capture. |
mbed_official | 87:085cde657901 | 1446 | (+) De-initialize the TIM Input Capture. |
mbed_official | 87:085cde657901 | 1447 | (+) Start the Time Input Capture. |
mbed_official | 87:085cde657901 | 1448 | (+) Stop the Time Input Capture. |
mbed_official | 87:085cde657901 | 1449 | (+) Start the Time Input Capture and enable interrupt. |
mbed_official | 87:085cde657901 | 1450 | (+) Stop the Time Input Capture and disable interrupt. |
mbed_official | 87:085cde657901 | 1451 | (+) Start the Time Input Capture and enable DMA transfer. |
mbed_official | 87:085cde657901 | 1452 | (+) Stop the Time Input Capture and disable DMA transfer. |
mbed_official | 87:085cde657901 | 1453 | |
mbed_official | 87:085cde657901 | 1454 | @endverbatim |
mbed_official | 87:085cde657901 | 1455 | * @{ |
mbed_official | 87:085cde657901 | 1456 | */ |
mbed_official | 87:085cde657901 | 1457 | /** |
mbed_official | 87:085cde657901 | 1458 | * @brief Initializes the TIM Input Capture Time base according to the specified |
mbed_official | 87:085cde657901 | 1459 | * parameters in the TIM_HandleTypeDef and create the associated handle. |
mbed_official | 87:085cde657901 | 1460 | * @param htim: TIM Input Capture handle |
mbed_official | 87:085cde657901 | 1461 | * @retval HAL status |
mbed_official | 87:085cde657901 | 1462 | */ |
mbed_official | 87:085cde657901 | 1463 | HAL_StatusTypeDef HAL_TIM_IC_Init(TIM_HandleTypeDef *htim) |
mbed_official | 87:085cde657901 | 1464 | { |
mbed_official | 87:085cde657901 | 1465 | /* Check the TIM handle allocation */ |
mbed_official | 87:085cde657901 | 1466 | if(htim == NULL) |
mbed_official | 87:085cde657901 | 1467 | { |
mbed_official | 87:085cde657901 | 1468 | return HAL_ERROR; |
mbed_official | 87:085cde657901 | 1469 | } |
mbed_official | 87:085cde657901 | 1470 | |
mbed_official | 87:085cde657901 | 1471 | /* Check the parameters */ |
mbed_official | 87:085cde657901 | 1472 | assert_param(IS_TIM_INSTANCE(htim->Instance)); |
mbed_official | 87:085cde657901 | 1473 | assert_param(IS_TIM_COUNTER_MODE(htim->Init.CounterMode)); |
mbed_official | 87:085cde657901 | 1474 | assert_param(IS_TIM_CLOCKDIVISION_DIV(htim->Init.ClockDivision)); |
mbed_official | 87:085cde657901 | 1475 | |
mbed_official | 87:085cde657901 | 1476 | if(htim->State == HAL_TIM_STATE_RESET) |
mbed_official | 87:085cde657901 | 1477 | { |
mbed_official | 87:085cde657901 | 1478 | /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */ |
mbed_official | 87:085cde657901 | 1479 | HAL_TIM_IC_MspInit(htim); |
mbed_official | 87:085cde657901 | 1480 | } |
mbed_official | 87:085cde657901 | 1481 | |
mbed_official | 87:085cde657901 | 1482 | /* Set the TIM state */ |
mbed_official | 87:085cde657901 | 1483 | htim->State= HAL_TIM_STATE_BUSY; |
mbed_official | 87:085cde657901 | 1484 | |
mbed_official | 87:085cde657901 | 1485 | /* Init the base time for the input capture */ |
mbed_official | 87:085cde657901 | 1486 | TIM_Base_SetConfig(htim->Instance, &htim->Init); |
mbed_official | 87:085cde657901 | 1487 | |
mbed_official | 87:085cde657901 | 1488 | /* Initialize the TIM state*/ |
mbed_official | 87:085cde657901 | 1489 | htim->State= HAL_TIM_STATE_READY; |
mbed_official | 87:085cde657901 | 1490 | |
mbed_official | 87:085cde657901 | 1491 | return HAL_OK; |
mbed_official | 87:085cde657901 | 1492 | } |
mbed_official | 87:085cde657901 | 1493 | |
mbed_official | 87:085cde657901 | 1494 | /** |
mbed_official | 87:085cde657901 | 1495 | * @brief DeInitializes the TIM peripheral |
mbed_official | 87:085cde657901 | 1496 | * @param htim: TIM Input Capture handle |
mbed_official | 87:085cde657901 | 1497 | * @retval HAL status |
mbed_official | 87:085cde657901 | 1498 | */ |
mbed_official | 87:085cde657901 | 1499 | HAL_StatusTypeDef HAL_TIM_IC_DeInit(TIM_HandleTypeDef *htim) |
mbed_official | 87:085cde657901 | 1500 | { |
mbed_official | 87:085cde657901 | 1501 | /* Check the parameters */ |
mbed_official | 87:085cde657901 | 1502 | assert_param(IS_TIM_INSTANCE(htim->Instance)); |
mbed_official | 87:085cde657901 | 1503 | |
mbed_official | 87:085cde657901 | 1504 | htim->State = HAL_TIM_STATE_BUSY; |
mbed_official | 87:085cde657901 | 1505 | |
mbed_official | 87:085cde657901 | 1506 | /* Disable the TIM Peripheral Clock */ |
mbed_official | 87:085cde657901 | 1507 | __HAL_TIM_DISABLE(htim); |
mbed_official | 87:085cde657901 | 1508 | |
mbed_official | 87:085cde657901 | 1509 | /* DeInit the low level hardware: GPIO, CLOCK, NVIC and DMA */ |
mbed_official | 87:085cde657901 | 1510 | HAL_TIM_IC_MspDeInit(htim); |
mbed_official | 87:085cde657901 | 1511 | |
mbed_official | 87:085cde657901 | 1512 | /* Change TIM state */ |
mbed_official | 87:085cde657901 | 1513 | htim->State = HAL_TIM_STATE_RESET; |
mbed_official | 106:ced8cbb51063 | 1514 | |
mbed_official | 106:ced8cbb51063 | 1515 | /* Release Lock */ |
mbed_official | 106:ced8cbb51063 | 1516 | __HAL_UNLOCK(htim); |
mbed_official | 106:ced8cbb51063 | 1517 | |
mbed_official | 87:085cde657901 | 1518 | return HAL_OK; |
mbed_official | 87:085cde657901 | 1519 | } |
mbed_official | 87:085cde657901 | 1520 | |
mbed_official | 87:085cde657901 | 1521 | /** |
mbed_official | 87:085cde657901 | 1522 | * @brief Initializes the TIM INput Capture MSP. |
mbed_official | 87:085cde657901 | 1523 | * @param htim: TIM handle |
mbed_official | 87:085cde657901 | 1524 | * @retval None |
mbed_official | 87:085cde657901 | 1525 | */ |
mbed_official | 87:085cde657901 | 1526 | __weak void HAL_TIM_IC_MspInit(TIM_HandleTypeDef *htim) |
mbed_official | 87:085cde657901 | 1527 | { |
mbed_official | 87:085cde657901 | 1528 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 87:085cde657901 | 1529 | the HAL_TIM_IC_MspInit could be implemented in the user file |
mbed_official | 87:085cde657901 | 1530 | */ |
mbed_official | 87:085cde657901 | 1531 | } |
mbed_official | 87:085cde657901 | 1532 | |
mbed_official | 87:085cde657901 | 1533 | /** |
mbed_official | 87:085cde657901 | 1534 | * @brief DeInitializes TIM Input Capture MSP. |
mbed_official | 87:085cde657901 | 1535 | * @param htim: TIM handle |
mbed_official | 87:085cde657901 | 1536 | * @retval None |
mbed_official | 87:085cde657901 | 1537 | */ |
mbed_official | 87:085cde657901 | 1538 | __weak void HAL_TIM_IC_MspDeInit(TIM_HandleTypeDef *htim) |
mbed_official | 87:085cde657901 | 1539 | { |
mbed_official | 87:085cde657901 | 1540 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 87:085cde657901 | 1541 | the HAL_TIM_IC_MspDeInit could be implemented in the user file |
mbed_official | 87:085cde657901 | 1542 | */ |
mbed_official | 87:085cde657901 | 1543 | } |
mbed_official | 87:085cde657901 | 1544 | |
mbed_official | 87:085cde657901 | 1545 | /** |
mbed_official | 87:085cde657901 | 1546 | * @brief Starts the TIM Input Capture measurement. |
mbed_official | 87:085cde657901 | 1547 | * @param hdma : TIM Input Capture handle |
mbed_official | 87:085cde657901 | 1548 | * @param Channel : TIM Channels to be enabled |
mbed_official | 87:085cde657901 | 1549 | * This parameter can be one of the following values: |
mbed_official | 87:085cde657901 | 1550 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
mbed_official | 87:085cde657901 | 1551 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
mbed_official | 87:085cde657901 | 1552 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
mbed_official | 87:085cde657901 | 1553 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
mbed_official | 87:085cde657901 | 1554 | * @retval HAL status |
mbed_official | 87:085cde657901 | 1555 | */ |
mbed_official | 87:085cde657901 | 1556 | HAL_StatusTypeDef HAL_TIM_IC_Start (TIM_HandleTypeDef *htim, uint32_t Channel) |
mbed_official | 87:085cde657901 | 1557 | { |
mbed_official | 87:085cde657901 | 1558 | /* Check the parameters */ |
mbed_official | 87:085cde657901 | 1559 | assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); |
mbed_official | 87:085cde657901 | 1560 | |
mbed_official | 87:085cde657901 | 1561 | /* Enable the Input Capture channel */ |
mbed_official | 87:085cde657901 | 1562 | TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE); |
mbed_official | 87:085cde657901 | 1563 | |
mbed_official | 87:085cde657901 | 1564 | /* Enable the Peripheral */ |
mbed_official | 87:085cde657901 | 1565 | __HAL_TIM_ENABLE(htim); |
mbed_official | 87:085cde657901 | 1566 | |
mbed_official | 87:085cde657901 | 1567 | /* Return function status */ |
mbed_official | 87:085cde657901 | 1568 | return HAL_OK; |
mbed_official | 87:085cde657901 | 1569 | } |
mbed_official | 87:085cde657901 | 1570 | |
mbed_official | 87:085cde657901 | 1571 | /** |
mbed_official | 87:085cde657901 | 1572 | * @brief Stops the TIM Input Capture measurement. |
mbed_official | 87:085cde657901 | 1573 | * @param htim : TIM handle |
mbed_official | 87:085cde657901 | 1574 | * @param Channel : TIM Channels to be disabled |
mbed_official | 87:085cde657901 | 1575 | * This parameter can be one of the following values: |
mbed_official | 87:085cde657901 | 1576 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
mbed_official | 87:085cde657901 | 1577 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
mbed_official | 87:085cde657901 | 1578 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
mbed_official | 87:085cde657901 | 1579 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
mbed_official | 87:085cde657901 | 1580 | * @retval HAL status |
mbed_official | 87:085cde657901 | 1581 | */ |
mbed_official | 87:085cde657901 | 1582 | HAL_StatusTypeDef HAL_TIM_IC_Stop(TIM_HandleTypeDef *htim, uint32_t Channel) |
mbed_official | 87:085cde657901 | 1583 | { |
mbed_official | 87:085cde657901 | 1584 | /* Check the parameters */ |
mbed_official | 87:085cde657901 | 1585 | assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); |
mbed_official | 87:085cde657901 | 1586 | |
mbed_official | 87:085cde657901 | 1587 | /* Disable the Input Capture channel */ |
mbed_official | 87:085cde657901 | 1588 | TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE); |
mbed_official | 87:085cde657901 | 1589 | |
mbed_official | 87:085cde657901 | 1590 | /* Disable the Peripheral */ |
mbed_official | 87:085cde657901 | 1591 | __HAL_TIM_DISABLE(htim); |
mbed_official | 87:085cde657901 | 1592 | |
mbed_official | 87:085cde657901 | 1593 | /* Return function status */ |
mbed_official | 87:085cde657901 | 1594 | return HAL_OK; |
mbed_official | 87:085cde657901 | 1595 | } |
mbed_official | 87:085cde657901 | 1596 | |
mbed_official | 87:085cde657901 | 1597 | /** |
mbed_official | 87:085cde657901 | 1598 | * @brief Starts the TIM Input Capture measurement in interrupt mode. |
mbed_official | 87:085cde657901 | 1599 | * @param hdma : TIM Input Capture handle |
mbed_official | 87:085cde657901 | 1600 | * @param Channel : TIM Channels to be enabled |
mbed_official | 87:085cde657901 | 1601 | * This parameter can be one of the following values: |
mbed_official | 87:085cde657901 | 1602 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
mbed_official | 87:085cde657901 | 1603 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
mbed_official | 87:085cde657901 | 1604 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
mbed_official | 87:085cde657901 | 1605 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
mbed_official | 87:085cde657901 | 1606 | * @retval HAL status |
mbed_official | 87:085cde657901 | 1607 | */ |
mbed_official | 87:085cde657901 | 1608 | HAL_StatusTypeDef HAL_TIM_IC_Start_IT (TIM_HandleTypeDef *htim, uint32_t Channel) |
mbed_official | 87:085cde657901 | 1609 | { |
mbed_official | 87:085cde657901 | 1610 | /* Check the parameters */ |
mbed_official | 87:085cde657901 | 1611 | assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); |
mbed_official | 87:085cde657901 | 1612 | |
mbed_official | 87:085cde657901 | 1613 | switch (Channel) |
mbed_official | 87:085cde657901 | 1614 | { |
mbed_official | 87:085cde657901 | 1615 | case TIM_CHANNEL_1: |
mbed_official | 87:085cde657901 | 1616 | { |
mbed_official | 87:085cde657901 | 1617 | /* Enable the TIM Capture/Compare 1 interrupt */ |
mbed_official | 87:085cde657901 | 1618 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1); |
mbed_official | 87:085cde657901 | 1619 | } |
mbed_official | 87:085cde657901 | 1620 | break; |
mbed_official | 87:085cde657901 | 1621 | |
mbed_official | 87:085cde657901 | 1622 | case TIM_CHANNEL_2: |
mbed_official | 87:085cde657901 | 1623 | { |
mbed_official | 87:085cde657901 | 1624 | /* Enable the TIM Capture/Compare 2 interrupt */ |
mbed_official | 87:085cde657901 | 1625 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2); |
mbed_official | 87:085cde657901 | 1626 | } |
mbed_official | 87:085cde657901 | 1627 | break; |
mbed_official | 87:085cde657901 | 1628 | |
mbed_official | 87:085cde657901 | 1629 | case TIM_CHANNEL_3: |
mbed_official | 87:085cde657901 | 1630 | { |
mbed_official | 87:085cde657901 | 1631 | /* Enable the TIM Capture/Compare 3 interrupt */ |
mbed_official | 87:085cde657901 | 1632 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC3); |
mbed_official | 87:085cde657901 | 1633 | } |
mbed_official | 87:085cde657901 | 1634 | break; |
mbed_official | 87:085cde657901 | 1635 | |
mbed_official | 87:085cde657901 | 1636 | case TIM_CHANNEL_4: |
mbed_official | 87:085cde657901 | 1637 | { |
mbed_official | 87:085cde657901 | 1638 | /* Enable the TIM Capture/Compare 4 interrupt */ |
mbed_official | 87:085cde657901 | 1639 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC4); |
mbed_official | 87:085cde657901 | 1640 | } |
mbed_official | 87:085cde657901 | 1641 | break; |
mbed_official | 87:085cde657901 | 1642 | |
mbed_official | 87:085cde657901 | 1643 | default: |
mbed_official | 87:085cde657901 | 1644 | break; |
mbed_official | 87:085cde657901 | 1645 | } |
mbed_official | 87:085cde657901 | 1646 | /* Enable the Input Capture channel */ |
mbed_official | 87:085cde657901 | 1647 | TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE); |
mbed_official | 87:085cde657901 | 1648 | |
mbed_official | 87:085cde657901 | 1649 | /* Enable the Peripheral */ |
mbed_official | 87:085cde657901 | 1650 | __HAL_TIM_ENABLE(htim); |
mbed_official | 87:085cde657901 | 1651 | |
mbed_official | 87:085cde657901 | 1652 | /* Return function status */ |
mbed_official | 87:085cde657901 | 1653 | return HAL_OK; |
mbed_official | 87:085cde657901 | 1654 | } |
mbed_official | 87:085cde657901 | 1655 | |
mbed_official | 87:085cde657901 | 1656 | /** |
mbed_official | 87:085cde657901 | 1657 | * @brief Stops the TIM Input Capture measurement in interrupt mode. |
mbed_official | 87:085cde657901 | 1658 | * @param htim : TIM handle |
mbed_official | 87:085cde657901 | 1659 | * @param Channel : TIM Channels to be disabled |
mbed_official | 87:085cde657901 | 1660 | * This parameter can be one of the following values: |
mbed_official | 87:085cde657901 | 1661 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
mbed_official | 87:085cde657901 | 1662 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
mbed_official | 87:085cde657901 | 1663 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
mbed_official | 87:085cde657901 | 1664 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
mbed_official | 87:085cde657901 | 1665 | * @retval HAL status |
mbed_official | 87:085cde657901 | 1666 | */ |
mbed_official | 87:085cde657901 | 1667 | HAL_StatusTypeDef HAL_TIM_IC_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel) |
mbed_official | 87:085cde657901 | 1668 | { |
mbed_official | 87:085cde657901 | 1669 | /* Check the parameters */ |
mbed_official | 87:085cde657901 | 1670 | assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); |
mbed_official | 87:085cde657901 | 1671 | |
mbed_official | 87:085cde657901 | 1672 | switch (Channel) |
mbed_official | 87:085cde657901 | 1673 | { |
mbed_official | 87:085cde657901 | 1674 | case TIM_CHANNEL_1: |
mbed_official | 87:085cde657901 | 1675 | { |
mbed_official | 87:085cde657901 | 1676 | /* Disable the TIM Capture/Compare 1 interrupt */ |
mbed_official | 87:085cde657901 | 1677 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1); |
mbed_official | 87:085cde657901 | 1678 | } |
mbed_official | 87:085cde657901 | 1679 | break; |
mbed_official | 87:085cde657901 | 1680 | |
mbed_official | 87:085cde657901 | 1681 | case TIM_CHANNEL_2: |
mbed_official | 87:085cde657901 | 1682 | { |
mbed_official | 87:085cde657901 | 1683 | /* Disable the TIM Capture/Compare 2 interrupt */ |
mbed_official | 87:085cde657901 | 1684 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2); |
mbed_official | 87:085cde657901 | 1685 | } |
mbed_official | 87:085cde657901 | 1686 | break; |
mbed_official | 87:085cde657901 | 1687 | |
mbed_official | 87:085cde657901 | 1688 | case TIM_CHANNEL_3: |
mbed_official | 87:085cde657901 | 1689 | { |
mbed_official | 87:085cde657901 | 1690 | /* Disable the TIM Capture/Compare 3 interrupt */ |
mbed_official | 87:085cde657901 | 1691 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC3); |
mbed_official | 87:085cde657901 | 1692 | } |
mbed_official | 87:085cde657901 | 1693 | break; |
mbed_official | 87:085cde657901 | 1694 | |
mbed_official | 87:085cde657901 | 1695 | case TIM_CHANNEL_4: |
mbed_official | 87:085cde657901 | 1696 | { |
mbed_official | 87:085cde657901 | 1697 | /* Disable the TIM Capture/Compare 4 interrupt */ |
mbed_official | 87:085cde657901 | 1698 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC4); |
mbed_official | 87:085cde657901 | 1699 | } |
mbed_official | 87:085cde657901 | 1700 | break; |
mbed_official | 87:085cde657901 | 1701 | |
mbed_official | 87:085cde657901 | 1702 | default: |
mbed_official | 87:085cde657901 | 1703 | break; |
mbed_official | 87:085cde657901 | 1704 | } |
mbed_official | 87:085cde657901 | 1705 | |
mbed_official | 87:085cde657901 | 1706 | /* Disable the Input Capture channel */ |
mbed_official | 87:085cde657901 | 1707 | TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE); |
mbed_official | 87:085cde657901 | 1708 | |
mbed_official | 87:085cde657901 | 1709 | /* Disable the Peripheral */ |
mbed_official | 87:085cde657901 | 1710 | __HAL_TIM_DISABLE(htim); |
mbed_official | 87:085cde657901 | 1711 | |
mbed_official | 87:085cde657901 | 1712 | /* Return function status */ |
mbed_official | 87:085cde657901 | 1713 | return HAL_OK; |
mbed_official | 87:085cde657901 | 1714 | } |
mbed_official | 87:085cde657901 | 1715 | |
mbed_official | 87:085cde657901 | 1716 | /** |
mbed_official | 87:085cde657901 | 1717 | * @brief Starts the TIM Input Capture measurement on in DMA mode. |
mbed_official | 87:085cde657901 | 1718 | * @param htim : TIM Input Capture handle |
mbed_official | 87:085cde657901 | 1719 | * @param Channel : TIM Channels to be enabled |
mbed_official | 87:085cde657901 | 1720 | * This parameter can be one of the following values: |
mbed_official | 87:085cde657901 | 1721 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
mbed_official | 87:085cde657901 | 1722 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
mbed_official | 87:085cde657901 | 1723 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
mbed_official | 87:085cde657901 | 1724 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
mbed_official | 87:085cde657901 | 1725 | * @param pData: The destination Buffer address. |
mbed_official | 87:085cde657901 | 1726 | * @param Length: The length of data to be transferred from TIM peripheral to memory. |
mbed_official | 87:085cde657901 | 1727 | * @retval HAL status |
mbed_official | 87:085cde657901 | 1728 | */ |
mbed_official | 87:085cde657901 | 1729 | HAL_StatusTypeDef HAL_TIM_IC_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length) |
mbed_official | 87:085cde657901 | 1730 | { |
mbed_official | 87:085cde657901 | 1731 | /* Check the parameters */ |
mbed_official | 87:085cde657901 | 1732 | assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); |
mbed_official | 87:085cde657901 | 1733 | assert_param(IS_TIM_DMA_CC_INSTANCE(htim->Instance)); |
mbed_official | 87:085cde657901 | 1734 | |
mbed_official | 87:085cde657901 | 1735 | if((htim->State == HAL_TIM_STATE_BUSY)) |
mbed_official | 87:085cde657901 | 1736 | { |
mbed_official | 87:085cde657901 | 1737 | return HAL_BUSY; |
mbed_official | 87:085cde657901 | 1738 | } |
mbed_official | 87:085cde657901 | 1739 | else if((htim->State == HAL_TIM_STATE_READY)) |
mbed_official | 87:085cde657901 | 1740 | { |
mbed_official | 87:085cde657901 | 1741 | if((pData == 0 ) && (Length > 0)) |
mbed_official | 87:085cde657901 | 1742 | { |
mbed_official | 87:085cde657901 | 1743 | return HAL_ERROR; |
mbed_official | 87:085cde657901 | 1744 | } |
mbed_official | 87:085cde657901 | 1745 | else |
mbed_official | 87:085cde657901 | 1746 | { |
mbed_official | 87:085cde657901 | 1747 | htim->State = HAL_TIM_STATE_BUSY; |
mbed_official | 87:085cde657901 | 1748 | } |
mbed_official | 87:085cde657901 | 1749 | } |
mbed_official | 87:085cde657901 | 1750 | |
mbed_official | 87:085cde657901 | 1751 | switch (Channel) |
mbed_official | 87:085cde657901 | 1752 | { |
mbed_official | 87:085cde657901 | 1753 | case TIM_CHANNEL_1: |
mbed_official | 87:085cde657901 | 1754 | { |
mbed_official | 87:085cde657901 | 1755 | /* Set the DMA Period elapsed callback */ |
mbed_official | 87:085cde657901 | 1756 | htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = HAL_TIM_DMACaptureCplt; |
mbed_official | 87:085cde657901 | 1757 | |
mbed_official | 87:085cde657901 | 1758 | /* Set the DMA error callback */ |
mbed_official | 87:085cde657901 | 1759 | htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = HAL_TIM_DMAError ; |
mbed_official | 87:085cde657901 | 1760 | |
mbed_official | 87:085cde657901 | 1761 | /* Enable the DMA Stream */ |
mbed_official | 87:085cde657901 | 1762 | HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)&htim->Instance->CCR1, (uint32_t)pData, Length); |
mbed_official | 87:085cde657901 | 1763 | |
mbed_official | 87:085cde657901 | 1764 | /* Enable the TIM Capture/Compare 1 DMA request */ |
mbed_official | 87:085cde657901 | 1765 | __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1); |
mbed_official | 87:085cde657901 | 1766 | } |
mbed_official | 87:085cde657901 | 1767 | break; |
mbed_official | 87:085cde657901 | 1768 | |
mbed_official | 87:085cde657901 | 1769 | case TIM_CHANNEL_2: |
mbed_official | 87:085cde657901 | 1770 | { |
mbed_official | 87:085cde657901 | 1771 | /* Set the DMA Period elapsed callback */ |
mbed_official | 87:085cde657901 | 1772 | htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = HAL_TIM_DMACaptureCplt; |
mbed_official | 87:085cde657901 | 1773 | |
mbed_official | 87:085cde657901 | 1774 | /* Set the DMA error callback */ |
mbed_official | 87:085cde657901 | 1775 | htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = HAL_TIM_DMAError ; |
mbed_official | 87:085cde657901 | 1776 | |
mbed_official | 87:085cde657901 | 1777 | /* Enable the DMA Stream */ |
mbed_official | 87:085cde657901 | 1778 | HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)&htim->Instance->CCR2, (uint32_t)pData, Length); |
mbed_official | 87:085cde657901 | 1779 | |
mbed_official | 87:085cde657901 | 1780 | /* Enable the TIM Capture/Compare 2 DMA request */ |
mbed_official | 87:085cde657901 | 1781 | __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC2); |
mbed_official | 87:085cde657901 | 1782 | } |
mbed_official | 87:085cde657901 | 1783 | break; |
mbed_official | 87:085cde657901 | 1784 | |
mbed_official | 87:085cde657901 | 1785 | case TIM_CHANNEL_3: |
mbed_official | 87:085cde657901 | 1786 | { |
mbed_official | 87:085cde657901 | 1787 | /* Set the DMA Period elapsed callback */ |
mbed_official | 87:085cde657901 | 1788 | htim->hdma[TIM_DMA_ID_CC3]->XferCpltCallback = HAL_TIM_DMACaptureCplt; |
mbed_official | 87:085cde657901 | 1789 | |
mbed_official | 87:085cde657901 | 1790 | /* Set the DMA error callback */ |
mbed_official | 87:085cde657901 | 1791 | htim->hdma[TIM_DMA_ID_CC3]->XferErrorCallback = HAL_TIM_DMAError ; |
mbed_official | 87:085cde657901 | 1792 | |
mbed_official | 87:085cde657901 | 1793 | /* Enable the DMA Stream */ |
mbed_official | 87:085cde657901 | 1794 | HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)&htim->Instance->CCR3, (uint32_t)pData, Length); |
mbed_official | 87:085cde657901 | 1795 | |
mbed_official | 87:085cde657901 | 1796 | /* Enable the TIM Capture/Compare 3 DMA request */ |
mbed_official | 87:085cde657901 | 1797 | __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC3); |
mbed_official | 87:085cde657901 | 1798 | } |
mbed_official | 87:085cde657901 | 1799 | break; |
mbed_official | 87:085cde657901 | 1800 | |
mbed_official | 87:085cde657901 | 1801 | case TIM_CHANNEL_4: |
mbed_official | 87:085cde657901 | 1802 | { |
mbed_official | 87:085cde657901 | 1803 | /* Set the DMA Period elapsed callback */ |
mbed_official | 87:085cde657901 | 1804 | htim->hdma[TIM_DMA_ID_CC4]->XferCpltCallback = HAL_TIM_DMACaptureCplt; |
mbed_official | 87:085cde657901 | 1805 | |
mbed_official | 87:085cde657901 | 1806 | /* Set the DMA error callback */ |
mbed_official | 87:085cde657901 | 1807 | htim->hdma[TIM_DMA_ID_CC4]->XferErrorCallback = HAL_TIM_DMAError ; |
mbed_official | 87:085cde657901 | 1808 | |
mbed_official | 87:085cde657901 | 1809 | /* Enable the DMA Stream */ |
mbed_official | 87:085cde657901 | 1810 | HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC4], (uint32_t)&htim->Instance->CCR4, (uint32_t)pData, Length); |
mbed_official | 87:085cde657901 | 1811 | |
mbed_official | 87:085cde657901 | 1812 | /* Enable the TIM Capture/Compare 4 DMA request */ |
mbed_official | 87:085cde657901 | 1813 | __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC4); |
mbed_official | 87:085cde657901 | 1814 | } |
mbed_official | 87:085cde657901 | 1815 | break; |
mbed_official | 87:085cde657901 | 1816 | |
mbed_official | 87:085cde657901 | 1817 | default: |
mbed_official | 87:085cde657901 | 1818 | break; |
mbed_official | 87:085cde657901 | 1819 | } |
mbed_official | 87:085cde657901 | 1820 | |
mbed_official | 87:085cde657901 | 1821 | /* Enable the Input Capture channel */ |
mbed_official | 87:085cde657901 | 1822 | TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE); |
mbed_official | 87:085cde657901 | 1823 | |
mbed_official | 87:085cde657901 | 1824 | /* Enable the Peripheral */ |
mbed_official | 87:085cde657901 | 1825 | __HAL_TIM_ENABLE(htim); |
mbed_official | 87:085cde657901 | 1826 | |
mbed_official | 87:085cde657901 | 1827 | /* Return function status */ |
mbed_official | 87:085cde657901 | 1828 | return HAL_OK; |
mbed_official | 87:085cde657901 | 1829 | } |
mbed_official | 87:085cde657901 | 1830 | |
mbed_official | 87:085cde657901 | 1831 | /** |
mbed_official | 87:085cde657901 | 1832 | * @brief Stops the TIM Input Capture measurement on in DMA mode. |
mbed_official | 87:085cde657901 | 1833 | * @param htim : TIM Input Capture handle |
mbed_official | 87:085cde657901 | 1834 | * @param Channel : TIM Channels to be disabled |
mbed_official | 87:085cde657901 | 1835 | * This parameter can be one of the following values: |
mbed_official | 87:085cde657901 | 1836 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
mbed_official | 87:085cde657901 | 1837 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
mbed_official | 87:085cde657901 | 1838 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
mbed_official | 87:085cde657901 | 1839 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
mbed_official | 87:085cde657901 | 1840 | * @retval HAL status |
mbed_official | 87:085cde657901 | 1841 | */ |
mbed_official | 87:085cde657901 | 1842 | HAL_StatusTypeDef HAL_TIM_IC_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel) |
mbed_official | 87:085cde657901 | 1843 | { |
mbed_official | 87:085cde657901 | 1844 | /* Check the parameters */ |
mbed_official | 87:085cde657901 | 1845 | assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); |
mbed_official | 87:085cde657901 | 1846 | assert_param(IS_TIM_DMA_CC_INSTANCE(htim->Instance)); |
mbed_official | 87:085cde657901 | 1847 | |
mbed_official | 87:085cde657901 | 1848 | switch (Channel) |
mbed_official | 87:085cde657901 | 1849 | { |
mbed_official | 87:085cde657901 | 1850 | case TIM_CHANNEL_1: |
mbed_official | 87:085cde657901 | 1851 | { |
mbed_official | 87:085cde657901 | 1852 | /* Disable the TIM Capture/Compare 1 DMA request */ |
mbed_official | 87:085cde657901 | 1853 | __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1); |
mbed_official | 87:085cde657901 | 1854 | } |
mbed_official | 87:085cde657901 | 1855 | break; |
mbed_official | 87:085cde657901 | 1856 | |
mbed_official | 87:085cde657901 | 1857 | case TIM_CHANNEL_2: |
mbed_official | 87:085cde657901 | 1858 | { |
mbed_official | 87:085cde657901 | 1859 | /* Disable the TIM Capture/Compare 2 DMA request */ |
mbed_official | 87:085cde657901 | 1860 | __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC2); |
mbed_official | 87:085cde657901 | 1861 | } |
mbed_official | 87:085cde657901 | 1862 | break; |
mbed_official | 87:085cde657901 | 1863 | |
mbed_official | 87:085cde657901 | 1864 | case TIM_CHANNEL_3: |
mbed_official | 87:085cde657901 | 1865 | { |
mbed_official | 87:085cde657901 | 1866 | /* Disable the TIM Capture/Compare 3 DMA request */ |
mbed_official | 87:085cde657901 | 1867 | __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC3); |
mbed_official | 87:085cde657901 | 1868 | } |
mbed_official | 87:085cde657901 | 1869 | break; |
mbed_official | 87:085cde657901 | 1870 | |
mbed_official | 87:085cde657901 | 1871 | case TIM_CHANNEL_4: |
mbed_official | 87:085cde657901 | 1872 | { |
mbed_official | 87:085cde657901 | 1873 | /* Disable the TIM Capture/Compare 4 DMA request */ |
mbed_official | 87:085cde657901 | 1874 | __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC4); |
mbed_official | 87:085cde657901 | 1875 | } |
mbed_official | 87:085cde657901 | 1876 | break; |
mbed_official | 87:085cde657901 | 1877 | |
mbed_official | 87:085cde657901 | 1878 | default: |
mbed_official | 87:085cde657901 | 1879 | break; |
mbed_official | 87:085cde657901 | 1880 | } |
mbed_official | 87:085cde657901 | 1881 | |
mbed_official | 87:085cde657901 | 1882 | /* Disable the Input Capture channel */ |
mbed_official | 87:085cde657901 | 1883 | TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE); |
mbed_official | 87:085cde657901 | 1884 | |
mbed_official | 87:085cde657901 | 1885 | /* Disable the Peripheral */ |
mbed_official | 87:085cde657901 | 1886 | __HAL_TIM_DISABLE(htim); |
mbed_official | 87:085cde657901 | 1887 | |
mbed_official | 87:085cde657901 | 1888 | /* Change the htim state */ |
mbed_official | 87:085cde657901 | 1889 | htim->State = HAL_TIM_STATE_READY; |
mbed_official | 87:085cde657901 | 1890 | |
mbed_official | 87:085cde657901 | 1891 | /* Return function status */ |
mbed_official | 87:085cde657901 | 1892 | return HAL_OK; |
mbed_official | 87:085cde657901 | 1893 | } |
mbed_official | 87:085cde657901 | 1894 | /** |
mbed_official | 87:085cde657901 | 1895 | * @} |
mbed_official | 87:085cde657901 | 1896 | */ |
mbed_official | 87:085cde657901 | 1897 | |
mbed_official | 87:085cde657901 | 1898 | /** @defgroup TIM_Group5 Time One Pulse functions |
mbed_official | 87:085cde657901 | 1899 | * @brief Time One Pulse functions |
mbed_official | 87:085cde657901 | 1900 | * |
mbed_official | 87:085cde657901 | 1901 | @verbatim |
mbed_official | 87:085cde657901 | 1902 | ============================================================================== |
mbed_official | 87:085cde657901 | 1903 | ##### Time One Pulse functions ##### |
mbed_official | 87:085cde657901 | 1904 | ============================================================================== |
mbed_official | 87:085cde657901 | 1905 | [..] |
mbed_official | 87:085cde657901 | 1906 | This section provides functions allowing to: |
mbed_official | 87:085cde657901 | 1907 | (+) Initialize and configure the TIM One Pulse. |
mbed_official | 87:085cde657901 | 1908 | (+) De-initialize the TIM One Pulse. |
mbed_official | 87:085cde657901 | 1909 | (+) Start the Time One Pulse. |
mbed_official | 87:085cde657901 | 1910 | (+) Stop the Time One Pulse. |
mbed_official | 87:085cde657901 | 1911 | (+) Start the Time One Pulse and enable interrupt. |
mbed_official | 87:085cde657901 | 1912 | (+) Stop the Time One Pulse and disable interrupt. |
mbed_official | 87:085cde657901 | 1913 | (+) Start the Time One Pulse and enable DMA transfer. |
mbed_official | 87:085cde657901 | 1914 | (+) Stop the Time One Pulse and disable DMA transfer. |
mbed_official | 87:085cde657901 | 1915 | |
mbed_official | 87:085cde657901 | 1916 | @endverbatim |
mbed_official | 87:085cde657901 | 1917 | * @{ |
mbed_official | 87:085cde657901 | 1918 | */ |
mbed_official | 87:085cde657901 | 1919 | /** |
mbed_official | 87:085cde657901 | 1920 | * @brief Initializes the TIM One Pulse Time Base according to the specified |
mbed_official | 87:085cde657901 | 1921 | * parameters in the TIM_HandleTypeDef and create the associated handle. |
mbed_official | 87:085cde657901 | 1922 | * @param htim: TIM OnePulse handle |
mbed_official | 87:085cde657901 | 1923 | * @param OnePulseMode: Select the One pulse mode. |
mbed_official | 87:085cde657901 | 1924 | * This parameter can be one of the following values: |
mbed_official | 87:085cde657901 | 1925 | * @arg TIM_OPMODE_SINGLE: Only one pulse will be generated. |
mbed_official | 87:085cde657901 | 1926 | * @arg TIM_OPMODE_REPETITIVE: Repetitive pulses wil be generated. |
mbed_official | 87:085cde657901 | 1927 | * @retval HAL status |
mbed_official | 87:085cde657901 | 1928 | */ |
mbed_official | 87:085cde657901 | 1929 | HAL_StatusTypeDef HAL_TIM_OnePulse_Init(TIM_HandleTypeDef *htim, uint32_t OnePulseMode) |
mbed_official | 87:085cde657901 | 1930 | { |
mbed_official | 87:085cde657901 | 1931 | /* Check the TIM handle allocation */ |
mbed_official | 87:085cde657901 | 1932 | if(htim == NULL) |
mbed_official | 87:085cde657901 | 1933 | { |
mbed_official | 87:085cde657901 | 1934 | return HAL_ERROR; |
mbed_official | 87:085cde657901 | 1935 | } |
mbed_official | 87:085cde657901 | 1936 | |
mbed_official | 87:085cde657901 | 1937 | /* Check the parameters */ |
mbed_official | 87:085cde657901 | 1938 | assert_param(IS_TIM_INSTANCE(htim->Instance)); |
mbed_official | 87:085cde657901 | 1939 | assert_param(IS_TIM_COUNTER_MODE(htim->Init.CounterMode)); |
mbed_official | 87:085cde657901 | 1940 | assert_param(IS_TIM_CLOCKDIVISION_DIV(htim->Init.ClockDivision)); |
mbed_official | 87:085cde657901 | 1941 | assert_param(IS_TIM_OPM_MODE(OnePulseMode)); |
mbed_official | 87:085cde657901 | 1942 | |
mbed_official | 87:085cde657901 | 1943 | if(htim->State == HAL_TIM_STATE_RESET) |
mbed_official | 87:085cde657901 | 1944 | { |
mbed_official | 87:085cde657901 | 1945 | /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */ |
mbed_official | 87:085cde657901 | 1946 | HAL_TIM_OnePulse_MspInit(htim); |
mbed_official | 87:085cde657901 | 1947 | } |
mbed_official | 87:085cde657901 | 1948 | |
mbed_official | 87:085cde657901 | 1949 | /* Set the TIM state */ |
mbed_official | 87:085cde657901 | 1950 | htim->State= HAL_TIM_STATE_BUSY; |
mbed_official | 87:085cde657901 | 1951 | |
mbed_official | 87:085cde657901 | 1952 | /* Configure the Time base in the One Pulse Mode */ |
mbed_official | 87:085cde657901 | 1953 | TIM_Base_SetConfig(htim->Instance, &htim->Init); |
mbed_official | 87:085cde657901 | 1954 | |
mbed_official | 87:085cde657901 | 1955 | /* Reset the OPM Bit */ |
mbed_official | 87:085cde657901 | 1956 | htim->Instance->CR1 &= ~TIM_CR1_OPM; |
mbed_official | 87:085cde657901 | 1957 | |
mbed_official | 87:085cde657901 | 1958 | /* Configure the OPM Mode */ |
mbed_official | 87:085cde657901 | 1959 | htim->Instance->CR1 |= OnePulseMode; |
mbed_official | 87:085cde657901 | 1960 | |
mbed_official | 87:085cde657901 | 1961 | /* Initialize the TIM state*/ |
mbed_official | 87:085cde657901 | 1962 | htim->State= HAL_TIM_STATE_READY; |
mbed_official | 87:085cde657901 | 1963 | |
mbed_official | 87:085cde657901 | 1964 | return HAL_OK; |
mbed_official | 87:085cde657901 | 1965 | } |
mbed_official | 87:085cde657901 | 1966 | |
mbed_official | 87:085cde657901 | 1967 | /** |
mbed_official | 87:085cde657901 | 1968 | * @brief DeInitializes the TIM One Pulse |
mbed_official | 87:085cde657901 | 1969 | * @param htim: TIM One Pulse handle |
mbed_official | 87:085cde657901 | 1970 | * @retval HAL status |
mbed_official | 87:085cde657901 | 1971 | */ |
mbed_official | 87:085cde657901 | 1972 | HAL_StatusTypeDef HAL_TIM_OnePulse_DeInit(TIM_HandleTypeDef *htim) |
mbed_official | 87:085cde657901 | 1973 | { |
mbed_official | 87:085cde657901 | 1974 | /* Check the parameters */ |
mbed_official | 87:085cde657901 | 1975 | assert_param(IS_TIM_INSTANCE(htim->Instance)); |
mbed_official | 87:085cde657901 | 1976 | |
mbed_official | 87:085cde657901 | 1977 | htim->State = HAL_TIM_STATE_BUSY; |
mbed_official | 87:085cde657901 | 1978 | |
mbed_official | 87:085cde657901 | 1979 | /* Disable the TIM Peripheral Clock */ |
mbed_official | 87:085cde657901 | 1980 | __HAL_TIM_DISABLE(htim); |
mbed_official | 87:085cde657901 | 1981 | |
mbed_official | 87:085cde657901 | 1982 | /* DeInit the low level hardware: GPIO, CLOCK, NVIC */ |
mbed_official | 87:085cde657901 | 1983 | HAL_TIM_OnePulse_MspDeInit(htim); |
mbed_official | 87:085cde657901 | 1984 | |
mbed_official | 87:085cde657901 | 1985 | /* Change TIM state */ |
mbed_official | 106:ced8cbb51063 | 1986 | htim->State = HAL_TIM_STATE_RESET; |
mbed_official | 106:ced8cbb51063 | 1987 | |
mbed_official | 106:ced8cbb51063 | 1988 | /* Release Lock */ |
mbed_official | 106:ced8cbb51063 | 1989 | __HAL_UNLOCK(htim); |
mbed_official | 106:ced8cbb51063 | 1990 | |
mbed_official | 87:085cde657901 | 1991 | return HAL_OK; |
mbed_official | 87:085cde657901 | 1992 | } |
mbed_official | 87:085cde657901 | 1993 | |
mbed_official | 87:085cde657901 | 1994 | /** |
mbed_official | 87:085cde657901 | 1995 | * @brief Initializes the TIM One Pulse MSP. |
mbed_official | 87:085cde657901 | 1996 | * @param htim: TIM handle |
mbed_official | 87:085cde657901 | 1997 | * @retval None |
mbed_official | 87:085cde657901 | 1998 | */ |
mbed_official | 87:085cde657901 | 1999 | __weak void HAL_TIM_OnePulse_MspInit(TIM_HandleTypeDef *htim) |
mbed_official | 87:085cde657901 | 2000 | { |
mbed_official | 87:085cde657901 | 2001 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 87:085cde657901 | 2002 | the HAL_TIM_OnePulse_MspInit could be implemented in the user file |
mbed_official | 87:085cde657901 | 2003 | */ |
mbed_official | 87:085cde657901 | 2004 | } |
mbed_official | 87:085cde657901 | 2005 | |
mbed_official | 87:085cde657901 | 2006 | /** |
mbed_official | 87:085cde657901 | 2007 | * @brief DeInitializes TIM One Pulse MSP. |
mbed_official | 87:085cde657901 | 2008 | * @param htim: TIM handle |
mbed_official | 87:085cde657901 | 2009 | * @retval None |
mbed_official | 87:085cde657901 | 2010 | */ |
mbed_official | 87:085cde657901 | 2011 | __weak void HAL_TIM_OnePulse_MspDeInit(TIM_HandleTypeDef *htim) |
mbed_official | 87:085cde657901 | 2012 | { |
mbed_official | 87:085cde657901 | 2013 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 87:085cde657901 | 2014 | the HAL_TIM_OnePulse_MspDeInit could be implemented in the user file |
mbed_official | 87:085cde657901 | 2015 | */ |
mbed_official | 87:085cde657901 | 2016 | } |
mbed_official | 87:085cde657901 | 2017 | |
mbed_official | 87:085cde657901 | 2018 | /** |
mbed_official | 87:085cde657901 | 2019 | * @brief Starts the TIM One Pulse signal generation. |
mbed_official | 87:085cde657901 | 2020 | * @param htim : TIM One Pulse handle |
mbed_official | 87:085cde657901 | 2021 | * @param OutputChannel : TIM Channels to be enabled |
mbed_official | 87:085cde657901 | 2022 | * This parameter can be one of the following values: |
mbed_official | 87:085cde657901 | 2023 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
mbed_official | 87:085cde657901 | 2024 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
mbed_official | 87:085cde657901 | 2025 | * @retval HAL status |
mbed_official | 87:085cde657901 | 2026 | */ |
mbed_official | 87:085cde657901 | 2027 | HAL_StatusTypeDef HAL_TIM_OnePulse_Start(TIM_HandleTypeDef *htim, uint32_t OutputChannel) |
mbed_official | 87:085cde657901 | 2028 | { |
mbed_official | 87:085cde657901 | 2029 | /* Enable the Capture compare and the Input Capture channels |
mbed_official | 87:085cde657901 | 2030 | (in the OPM Mode the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2) |
mbed_official | 87:085cde657901 | 2031 | if TIM_CHANNEL_1 is used as output, the TIM_CHANNEL_2 will be used as input and |
mbed_official | 87:085cde657901 | 2032 | if TIM_CHANNEL_1 is used as input, the TIM_CHANNEL_2 will be used as output |
mbed_official | 87:085cde657901 | 2033 | in all combinations, the TIM_CHANNEL_1 and TIM_CHANNEL_2 should be enabled together |
mbed_official | 87:085cde657901 | 2034 | |
mbed_official | 87:085cde657901 | 2035 | No need to enable the counter, it's enabled automatically by hardware |
mbed_official | 87:085cde657901 | 2036 | (the counter starts in response to a stimulus and generate a pulse */ |
mbed_official | 87:085cde657901 | 2037 | |
mbed_official | 87:085cde657901 | 2038 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE); |
mbed_official | 87:085cde657901 | 2039 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_ENABLE); |
mbed_official | 87:085cde657901 | 2040 | |
mbed_official | 87:085cde657901 | 2041 | if(IS_TIM_ADVANCED_INSTANCE(htim->Instance) != RESET) |
mbed_official | 87:085cde657901 | 2042 | { |
mbed_official | 87:085cde657901 | 2043 | /* Enable the main output */ |
mbed_official | 87:085cde657901 | 2044 | __HAL_TIM_MOE_ENABLE(htim); |
mbed_official | 87:085cde657901 | 2045 | } |
mbed_official | 87:085cde657901 | 2046 | |
mbed_official | 87:085cde657901 | 2047 | /* Return function status */ |
mbed_official | 87:085cde657901 | 2048 | return HAL_OK; |
mbed_official | 87:085cde657901 | 2049 | } |
mbed_official | 87:085cde657901 | 2050 | |
mbed_official | 87:085cde657901 | 2051 | /** |
mbed_official | 87:085cde657901 | 2052 | * @brief Stops the TIM One Pulse signal generation. |
mbed_official | 87:085cde657901 | 2053 | * @param htim : TIM One Pulse handle |
mbed_official | 87:085cde657901 | 2054 | * @param OutputChannel : TIM Channels to be disable |
mbed_official | 87:085cde657901 | 2055 | * This parameter can be one of the following values: |
mbed_official | 87:085cde657901 | 2056 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
mbed_official | 87:085cde657901 | 2057 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
mbed_official | 87:085cde657901 | 2058 | * @retval HAL status |
mbed_official | 87:085cde657901 | 2059 | */ |
mbed_official | 87:085cde657901 | 2060 | HAL_StatusTypeDef HAL_TIM_OnePulse_Stop(TIM_HandleTypeDef *htim, uint32_t OutputChannel) |
mbed_official | 87:085cde657901 | 2061 | { |
mbed_official | 87:085cde657901 | 2062 | /* Disable the Capture compare and the Input Capture channels |
mbed_official | 87:085cde657901 | 2063 | (in the OPM Mode the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2) |
mbed_official | 87:085cde657901 | 2064 | if TIM_CHANNEL_1 is used as output, the TIM_CHANNEL_2 will be used as input and |
mbed_official | 87:085cde657901 | 2065 | if TIM_CHANNEL_1 is used as input, the TIM_CHANNEL_2 will be used as output |
mbed_official | 87:085cde657901 | 2066 | in all combinations, the TIM_CHANNEL_1 and TIM_CHANNEL_2 should be disabled together */ |
mbed_official | 87:085cde657901 | 2067 | |
mbed_official | 87:085cde657901 | 2068 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE); |
mbed_official | 87:085cde657901 | 2069 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE); |
mbed_official | 87:085cde657901 | 2070 | |
mbed_official | 87:085cde657901 | 2071 | if(IS_TIM_ADVANCED_INSTANCE(htim->Instance) != RESET) |
mbed_official | 87:085cde657901 | 2072 | { |
mbed_official | 87:085cde657901 | 2073 | /* Disable the Main Ouput */ |
mbed_official | 87:085cde657901 | 2074 | __HAL_TIM_MOE_DISABLE(htim); |
mbed_official | 87:085cde657901 | 2075 | } |
mbed_official | 87:085cde657901 | 2076 | |
mbed_official | 87:085cde657901 | 2077 | /* Disable the Peripheral */ |
mbed_official | 87:085cde657901 | 2078 | __HAL_TIM_DISABLE(htim); |
mbed_official | 87:085cde657901 | 2079 | |
mbed_official | 87:085cde657901 | 2080 | /* Return function status */ |
mbed_official | 87:085cde657901 | 2081 | return HAL_OK; |
mbed_official | 87:085cde657901 | 2082 | } |
mbed_official | 87:085cde657901 | 2083 | |
mbed_official | 87:085cde657901 | 2084 | /** |
mbed_official | 87:085cde657901 | 2085 | * @brief Starts the TIM One Pulse signal generation in interrupt mode. |
mbed_official | 87:085cde657901 | 2086 | * @param htim : TIM One Pulse handle |
mbed_official | 87:085cde657901 | 2087 | * @param OutputChannel : TIM Channels to be enabled |
mbed_official | 87:085cde657901 | 2088 | * This parameter can be one of the following values: |
mbed_official | 87:085cde657901 | 2089 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
mbed_official | 87:085cde657901 | 2090 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
mbed_official | 87:085cde657901 | 2091 | * @retval HAL status |
mbed_official | 87:085cde657901 | 2092 | */ |
mbed_official | 87:085cde657901 | 2093 | HAL_StatusTypeDef HAL_TIM_OnePulse_Start_IT(TIM_HandleTypeDef *htim, uint32_t OutputChannel) |
mbed_official | 87:085cde657901 | 2094 | { |
mbed_official | 87:085cde657901 | 2095 | /* Enable the Capture compare and the Input Capture channels |
mbed_official | 87:085cde657901 | 2096 | (in the OPM Mode the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2) |
mbed_official | 87:085cde657901 | 2097 | if TIM_CHANNEL_1 is used as output, the TIM_CHANNEL_2 will be used as input and |
mbed_official | 87:085cde657901 | 2098 | if TIM_CHANNEL_1 is used as input, the TIM_CHANNEL_2 will be used as output |
mbed_official | 87:085cde657901 | 2099 | in all combinations, the TIM_CHANNEL_1 and TIM_CHANNEL_2 should be enabled together |
mbed_official | 87:085cde657901 | 2100 | |
mbed_official | 87:085cde657901 | 2101 | No need to enable the counter, it's enabled automatically by hardware |
mbed_official | 87:085cde657901 | 2102 | (the counter starts in response to a stimulus and generate a pulse */ |
mbed_official | 87:085cde657901 | 2103 | |
mbed_official | 87:085cde657901 | 2104 | /* Enable the TIM Capture/Compare 1 interrupt */ |
mbed_official | 87:085cde657901 | 2105 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1); |
mbed_official | 87:085cde657901 | 2106 | |
mbed_official | 87:085cde657901 | 2107 | /* Enable the TIM Capture/Compare 2 interrupt */ |
mbed_official | 87:085cde657901 | 2108 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2); |
mbed_official | 87:085cde657901 | 2109 | |
mbed_official | 87:085cde657901 | 2110 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE); |
mbed_official | 87:085cde657901 | 2111 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_ENABLE); |
mbed_official | 87:085cde657901 | 2112 | |
mbed_official | 87:085cde657901 | 2113 | if(IS_TIM_ADVANCED_INSTANCE(htim->Instance) != RESET) |
mbed_official | 87:085cde657901 | 2114 | { |
mbed_official | 87:085cde657901 | 2115 | /* Enable the main output */ |
mbed_official | 87:085cde657901 | 2116 | __HAL_TIM_MOE_ENABLE(htim); |
mbed_official | 87:085cde657901 | 2117 | } |
mbed_official | 87:085cde657901 | 2118 | |
mbed_official | 87:085cde657901 | 2119 | /* Return function status */ |
mbed_official | 87:085cde657901 | 2120 | return HAL_OK; |
mbed_official | 87:085cde657901 | 2121 | } |
mbed_official | 87:085cde657901 | 2122 | |
mbed_official | 87:085cde657901 | 2123 | /** |
mbed_official | 87:085cde657901 | 2124 | * @brief Stops the TIM One Pulse signal generation in interrupt mode. |
mbed_official | 87:085cde657901 | 2125 | * @param htim : TIM One Pulse handle |
mbed_official | 87:085cde657901 | 2126 | * @param OutputChannel : TIM Channels to be enabled |
mbed_official | 87:085cde657901 | 2127 | * This parameter can be one of the following values: |
mbed_official | 87:085cde657901 | 2128 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
mbed_official | 87:085cde657901 | 2129 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
mbed_official | 87:085cde657901 | 2130 | * @retval HAL status |
mbed_official | 87:085cde657901 | 2131 | */ |
mbed_official | 87:085cde657901 | 2132 | HAL_StatusTypeDef HAL_TIM_OnePulse_Stop_IT(TIM_HandleTypeDef *htim, uint32_t OutputChannel) |
mbed_official | 87:085cde657901 | 2133 | { |
mbed_official | 87:085cde657901 | 2134 | /* Disable the TIM Capture/Compare 1 interrupt */ |
mbed_official | 87:085cde657901 | 2135 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1); |
mbed_official | 87:085cde657901 | 2136 | |
mbed_official | 87:085cde657901 | 2137 | /* Disable the TIM Capture/Compare 2 interrupt */ |
mbed_official | 87:085cde657901 | 2138 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2); |
mbed_official | 87:085cde657901 | 2139 | |
mbed_official | 87:085cde657901 | 2140 | /* Disable the Capture compare and the Input Capture channels |
mbed_official | 87:085cde657901 | 2141 | (in the OPM Mode the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2) |
mbed_official | 87:085cde657901 | 2142 | if TIM_CHANNEL_1 is used as output, the TIM_CHANNEL_2 will be used as input and |
mbed_official | 87:085cde657901 | 2143 | if TIM_CHANNEL_1 is used as input, the TIM_CHANNEL_2 will be used as output |
mbed_official | 87:085cde657901 | 2144 | in all combinations, the TIM_CHANNEL_1 and TIM_CHANNEL_2 should be disabled together */ |
mbed_official | 87:085cde657901 | 2145 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE); |
mbed_official | 87:085cde657901 | 2146 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE); |
mbed_official | 87:085cde657901 | 2147 | |
mbed_official | 87:085cde657901 | 2148 | if(IS_TIM_ADVANCED_INSTANCE(htim->Instance) != RESET) |
mbed_official | 87:085cde657901 | 2149 | { |
mbed_official | 87:085cde657901 | 2150 | /* Disable the Main Ouput */ |
mbed_official | 87:085cde657901 | 2151 | __HAL_TIM_MOE_DISABLE(htim); |
mbed_official | 87:085cde657901 | 2152 | } |
mbed_official | 87:085cde657901 | 2153 | |
mbed_official | 87:085cde657901 | 2154 | /* Disable the Peripheral */ |
mbed_official | 87:085cde657901 | 2155 | __HAL_TIM_DISABLE(htim); |
mbed_official | 87:085cde657901 | 2156 | |
mbed_official | 87:085cde657901 | 2157 | /* Return function status */ |
mbed_official | 87:085cde657901 | 2158 | return HAL_OK; |
mbed_official | 87:085cde657901 | 2159 | } |
mbed_official | 87:085cde657901 | 2160 | |
mbed_official | 87:085cde657901 | 2161 | /** |
mbed_official | 87:085cde657901 | 2162 | * @} |
mbed_official | 87:085cde657901 | 2163 | */ |
mbed_official | 87:085cde657901 | 2164 | |
mbed_official | 87:085cde657901 | 2165 | /** @defgroup TIM_Group6 Time Encoder functions |
mbed_official | 87:085cde657901 | 2166 | * @brief Time Encoder functions |
mbed_official | 87:085cde657901 | 2167 | * |
mbed_official | 87:085cde657901 | 2168 | @verbatim |
mbed_official | 87:085cde657901 | 2169 | ============================================================================== |
mbed_official | 87:085cde657901 | 2170 | ##### Time Encoder functions ##### |
mbed_official | 87:085cde657901 | 2171 | ============================================================================== |
mbed_official | 87:085cde657901 | 2172 | [..] |
mbed_official | 87:085cde657901 | 2173 | This section provides functions allowing to: |
mbed_official | 87:085cde657901 | 2174 | (+) Initialize and configure the TIM Encoder. |
mbed_official | 87:085cde657901 | 2175 | (+) De-initialize the TIM Encoder. |
mbed_official | 87:085cde657901 | 2176 | (+) Start the Time Encoder. |
mbed_official | 87:085cde657901 | 2177 | (+) Stop the Time Encoder. |
mbed_official | 87:085cde657901 | 2178 | (+) Start the Time Encoder and enable interrupt. |
mbed_official | 87:085cde657901 | 2179 | (+) Stop the Time Encoder and disable interrupt. |
mbed_official | 87:085cde657901 | 2180 | (+) Start the Time Encoder and enable DMA transfer. |
mbed_official | 87:085cde657901 | 2181 | (+) Stop the Time Encoder and disable DMA transfer. |
mbed_official | 87:085cde657901 | 2182 | |
mbed_official | 87:085cde657901 | 2183 | @endverbatim |
mbed_official | 87:085cde657901 | 2184 | * @{ |
mbed_official | 87:085cde657901 | 2185 | */ |
mbed_official | 87:085cde657901 | 2186 | /** |
mbed_official | 87:085cde657901 | 2187 | * @brief Initializes the TIM Encoder Interface and create the associated handle. |
mbed_official | 87:085cde657901 | 2188 | * @param htim: TIM Encoder Interface handle |
mbed_official | 87:085cde657901 | 2189 | * @param sConfig: TIM Encoder Interface configuration structure |
mbed_official | 87:085cde657901 | 2190 | * @retval HAL status |
mbed_official | 87:085cde657901 | 2191 | */ |
mbed_official | 87:085cde657901 | 2192 | HAL_StatusTypeDef HAL_TIM_Encoder_Init(TIM_HandleTypeDef *htim, TIM_Encoder_InitTypeDef* sConfig) |
mbed_official | 87:085cde657901 | 2193 | { |
mbed_official | 87:085cde657901 | 2194 | uint32_t tmpsmcr = 0; |
mbed_official | 87:085cde657901 | 2195 | uint32_t tmpccmr1 = 0; |
mbed_official | 87:085cde657901 | 2196 | uint32_t tmpccer = 0; |
mbed_official | 87:085cde657901 | 2197 | |
mbed_official | 87:085cde657901 | 2198 | /* Check the TIM handle allocation */ |
mbed_official | 87:085cde657901 | 2199 | if(htim == NULL) |
mbed_official | 87:085cde657901 | 2200 | { |
mbed_official | 87:085cde657901 | 2201 | return HAL_ERROR; |
mbed_official | 87:085cde657901 | 2202 | } |
mbed_official | 87:085cde657901 | 2203 | |
mbed_official | 87:085cde657901 | 2204 | /* Check the parameters */ |
mbed_official | 87:085cde657901 | 2205 | assert_param(IS_TIM_CC2_INSTANCE(htim->Instance)); |
mbed_official | 87:085cde657901 | 2206 | assert_param(IS_TIM_ENCODER_MODE(sConfig->EncoderMode)); |
mbed_official | 87:085cde657901 | 2207 | assert_param(IS_TIM_IC_SELECTION(sConfig->IC1Selection)); |
mbed_official | 87:085cde657901 | 2208 | assert_param(IS_TIM_IC_SELECTION(sConfig->IC2Selection)); |
mbed_official | 87:085cde657901 | 2209 | assert_param(IS_TIM_IC_POLARITY(sConfig->IC1Polarity)); |
mbed_official | 87:085cde657901 | 2210 | assert_param(IS_TIM_IC_POLARITY(sConfig->IC2Polarity)); |
mbed_official | 87:085cde657901 | 2211 | assert_param(IS_TIM_IC_PRESCALER(sConfig->IC1Prescaler)); |
mbed_official | 87:085cde657901 | 2212 | assert_param(IS_TIM_IC_PRESCALER(sConfig->IC2Prescaler)); |
mbed_official | 87:085cde657901 | 2213 | assert_param(IS_TIM_IC_FILTER(sConfig->IC1Filter)); |
mbed_official | 87:085cde657901 | 2214 | assert_param(IS_TIM_IC_FILTER(sConfig->IC2Filter)); |
mbed_official | 87:085cde657901 | 2215 | |
mbed_official | 87:085cde657901 | 2216 | if(htim->State == HAL_TIM_STATE_RESET) |
mbed_official | 87:085cde657901 | 2217 | { |
mbed_official | 87:085cde657901 | 2218 | /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */ |
mbed_official | 87:085cde657901 | 2219 | HAL_TIM_Encoder_MspInit(htim); |
mbed_official | 87:085cde657901 | 2220 | } |
mbed_official | 87:085cde657901 | 2221 | |
mbed_official | 87:085cde657901 | 2222 | /* Set the TIM state */ |
mbed_official | 87:085cde657901 | 2223 | htim->State= HAL_TIM_STATE_BUSY; |
mbed_official | 87:085cde657901 | 2224 | |
mbed_official | 87:085cde657901 | 2225 | /* Reset the SMS bits */ |
mbed_official | 87:085cde657901 | 2226 | htim->Instance->SMCR &= ~TIM_SMCR_SMS; |
mbed_official | 87:085cde657901 | 2227 | |
mbed_official | 87:085cde657901 | 2228 | /* Configure the Time base in the Encoder Mode */ |
mbed_official | 87:085cde657901 | 2229 | TIM_Base_SetConfig(htim->Instance, &htim->Init); |
mbed_official | 87:085cde657901 | 2230 | |
mbed_official | 87:085cde657901 | 2231 | /* Get the TIMx SMCR register value */ |
mbed_official | 87:085cde657901 | 2232 | tmpsmcr = htim->Instance->SMCR; |
mbed_official | 87:085cde657901 | 2233 | |
mbed_official | 87:085cde657901 | 2234 | /* Get the TIMx CCMR1 register value */ |
mbed_official | 87:085cde657901 | 2235 | tmpccmr1 = htim->Instance->CCMR1; |
mbed_official | 87:085cde657901 | 2236 | |
mbed_official | 87:085cde657901 | 2237 | /* Get the TIMx CCER register value */ |
mbed_official | 87:085cde657901 | 2238 | tmpccer = htim->Instance->CCER; |
mbed_official | 87:085cde657901 | 2239 | |
mbed_official | 87:085cde657901 | 2240 | /* Set the encoder Mode */ |
mbed_official | 87:085cde657901 | 2241 | tmpsmcr |= sConfig->EncoderMode; |
mbed_official | 87:085cde657901 | 2242 | |
mbed_official | 87:085cde657901 | 2243 | /* Select the Capture Compare 1 and the Capture Compare 2 as input */ |
mbed_official | 87:085cde657901 | 2244 | tmpccmr1 &= ~(TIM_CCMR1_CC1S | TIM_CCMR1_CC2S); |
mbed_official | 87:085cde657901 | 2245 | tmpccmr1 |= (sConfig->IC1Selection | (sConfig->IC2Selection << 8)); |
mbed_official | 87:085cde657901 | 2246 | |
mbed_official | 87:085cde657901 | 2247 | /* Set the the Capture Compare 1 and the Capture Compare 2 prescalers and filters */ |
mbed_official | 87:085cde657901 | 2248 | tmpccmr1 &= ~(TIM_CCMR1_IC1PSC | TIM_CCMR1_IC2PSC); |
mbed_official | 87:085cde657901 | 2249 | tmpccmr1 &= ~(TIM_CCMR1_IC1F | TIM_CCMR1_IC2F); |
mbed_official | 87:085cde657901 | 2250 | tmpccmr1 |= sConfig->IC1Prescaler | (sConfig->IC2Prescaler << 8); |
mbed_official | 87:085cde657901 | 2251 | tmpccmr1 |= (sConfig->IC1Filter << 4) | (sConfig->IC2Filter << 12); |
mbed_official | 87:085cde657901 | 2252 | |
mbed_official | 87:085cde657901 | 2253 | /* Set the TI1 and the TI2 Polarities */ |
mbed_official | 87:085cde657901 | 2254 | tmpccer &= ~(TIM_CCER_CC1P | TIM_CCER_CC2P); |
mbed_official | 87:085cde657901 | 2255 | tmpccer &= ~(TIM_CCER_CC1NP | TIM_CCER_CC2NP); |
mbed_official | 87:085cde657901 | 2256 | tmpccer |= sConfig->IC1Polarity | (sConfig->IC2Polarity << 4); |
mbed_official | 87:085cde657901 | 2257 | |
mbed_official | 87:085cde657901 | 2258 | /* Write to TIMx SMCR */ |
mbed_official | 87:085cde657901 | 2259 | htim->Instance->SMCR = tmpsmcr; |
mbed_official | 87:085cde657901 | 2260 | |
mbed_official | 87:085cde657901 | 2261 | /* Write to TIMx CCMR1 */ |
mbed_official | 87:085cde657901 | 2262 | htim->Instance->CCMR1 = tmpccmr1; |
mbed_official | 87:085cde657901 | 2263 | |
mbed_official | 87:085cde657901 | 2264 | /* Write to TIMx CCER */ |
mbed_official | 87:085cde657901 | 2265 | htim->Instance->CCER = tmpccer; |
mbed_official | 87:085cde657901 | 2266 | |
mbed_official | 87:085cde657901 | 2267 | /* Initialize the TIM state*/ |
mbed_official | 87:085cde657901 | 2268 | htim->State= HAL_TIM_STATE_READY; |
mbed_official | 87:085cde657901 | 2269 | |
mbed_official | 87:085cde657901 | 2270 | return HAL_OK; |
mbed_official | 87:085cde657901 | 2271 | } |
mbed_official | 87:085cde657901 | 2272 | |
mbed_official | 87:085cde657901 | 2273 | /** |
mbed_official | 87:085cde657901 | 2274 | * @brief DeInitializes the TIM Encoder interface |
mbed_official | 87:085cde657901 | 2275 | * @param htim: TIM Encoder handle |
mbed_official | 87:085cde657901 | 2276 | * @retval HAL status |
mbed_official | 87:085cde657901 | 2277 | */ |
mbed_official | 87:085cde657901 | 2278 | HAL_StatusTypeDef HAL_TIM_Encoder_DeInit(TIM_HandleTypeDef *htim) |
mbed_official | 87:085cde657901 | 2279 | { |
mbed_official | 87:085cde657901 | 2280 | /* Check the parameters */ |
mbed_official | 87:085cde657901 | 2281 | assert_param(IS_TIM_INSTANCE(htim->Instance)); |
mbed_official | 87:085cde657901 | 2282 | |
mbed_official | 87:085cde657901 | 2283 | htim->State = HAL_TIM_STATE_BUSY; |
mbed_official | 87:085cde657901 | 2284 | |
mbed_official | 87:085cde657901 | 2285 | /* Disable the TIM Peripheral Clock */ |
mbed_official | 87:085cde657901 | 2286 | __HAL_TIM_DISABLE(htim); |
mbed_official | 87:085cde657901 | 2287 | |
mbed_official | 87:085cde657901 | 2288 | /* DeInit the low level hardware: GPIO, CLOCK, NVIC */ |
mbed_official | 87:085cde657901 | 2289 | HAL_TIM_Encoder_MspDeInit(htim); |
mbed_official | 87:085cde657901 | 2290 | |
mbed_official | 87:085cde657901 | 2291 | /* Change TIM state */ |
mbed_official | 106:ced8cbb51063 | 2292 | htim->State = HAL_TIM_STATE_RESET; |
mbed_official | 106:ced8cbb51063 | 2293 | |
mbed_official | 106:ced8cbb51063 | 2294 | /* Release Lock */ |
mbed_official | 106:ced8cbb51063 | 2295 | __HAL_UNLOCK(htim); |
mbed_official | 106:ced8cbb51063 | 2296 | |
mbed_official | 87:085cde657901 | 2297 | return HAL_OK; |
mbed_official | 87:085cde657901 | 2298 | } |
mbed_official | 87:085cde657901 | 2299 | |
mbed_official | 87:085cde657901 | 2300 | /** |
mbed_official | 87:085cde657901 | 2301 | * @brief Initializes the TIM Encoder Interface MSP. |
mbed_official | 87:085cde657901 | 2302 | * @param htim: TIM handle |
mbed_official | 87:085cde657901 | 2303 | * @retval None |
mbed_official | 87:085cde657901 | 2304 | */ |
mbed_official | 87:085cde657901 | 2305 | __weak void HAL_TIM_Encoder_MspInit(TIM_HandleTypeDef *htim) |
mbed_official | 87:085cde657901 | 2306 | { |
mbed_official | 87:085cde657901 | 2307 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 87:085cde657901 | 2308 | the HAL_TIM_Encoder_MspInit could be implemented in the user file |
mbed_official | 87:085cde657901 | 2309 | */ |
mbed_official | 87:085cde657901 | 2310 | } |
mbed_official | 87:085cde657901 | 2311 | |
mbed_official | 87:085cde657901 | 2312 | /** |
mbed_official | 87:085cde657901 | 2313 | * @brief DeInitializes TIM Encoder Interface MSP. |
mbed_official | 87:085cde657901 | 2314 | * @param htim: TIM handle |
mbed_official | 87:085cde657901 | 2315 | * @retval None |
mbed_official | 87:085cde657901 | 2316 | */ |
mbed_official | 87:085cde657901 | 2317 | __weak void HAL_TIM_Encoder_MspDeInit(TIM_HandleTypeDef *htim) |
mbed_official | 87:085cde657901 | 2318 | { |
mbed_official | 87:085cde657901 | 2319 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 87:085cde657901 | 2320 | the HAL_TIM_Encoder_MspDeInit could be implemented in the user file |
mbed_official | 87:085cde657901 | 2321 | */ |
mbed_official | 87:085cde657901 | 2322 | } |
mbed_official | 87:085cde657901 | 2323 | |
mbed_official | 87:085cde657901 | 2324 | /** |
mbed_official | 87:085cde657901 | 2325 | * @brief Starts the TIM Encoder Interface. |
mbed_official | 87:085cde657901 | 2326 | * @param htim : TIM Encoder Interface handle |
mbed_official | 87:085cde657901 | 2327 | * @param Channel : TIM Channels to be enabled |
mbed_official | 87:085cde657901 | 2328 | * This parameter can be one of the following values: |
mbed_official | 87:085cde657901 | 2329 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
mbed_official | 87:085cde657901 | 2330 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
mbed_official | 87:085cde657901 | 2331 | * @retval HAL status |
mbed_official | 87:085cde657901 | 2332 | */ |
mbed_official | 87:085cde657901 | 2333 | HAL_StatusTypeDef HAL_TIM_Encoder_Start(TIM_HandleTypeDef *htim, uint32_t Channel) |
mbed_official | 87:085cde657901 | 2334 | { |
mbed_official | 87:085cde657901 | 2335 | /* Check the parameters */ |
mbed_official | 87:085cde657901 | 2336 | assert_param(IS_TIM_CC2_INSTANCE(htim->Instance)); |
mbed_official | 87:085cde657901 | 2337 | |
mbed_official | 87:085cde657901 | 2338 | /* Enable the encoder interface channels */ |
mbed_official | 87:085cde657901 | 2339 | switch (Channel) |
mbed_official | 87:085cde657901 | 2340 | { |
mbed_official | 87:085cde657901 | 2341 | case TIM_CHANNEL_1: |
mbed_official | 87:085cde657901 | 2342 | { |
mbed_official | 87:085cde657901 | 2343 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE); |
mbed_official | 87:085cde657901 | 2344 | break; |
mbed_official | 87:085cde657901 | 2345 | } |
mbed_official | 87:085cde657901 | 2346 | case TIM_CHANNEL_2: |
mbed_official | 87:085cde657901 | 2347 | { |
mbed_official | 87:085cde657901 | 2348 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_ENABLE); |
mbed_official | 87:085cde657901 | 2349 | break; |
mbed_official | 87:085cde657901 | 2350 | } |
mbed_official | 87:085cde657901 | 2351 | default : |
mbed_official | 87:085cde657901 | 2352 | { |
mbed_official | 87:085cde657901 | 2353 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE); |
mbed_official | 87:085cde657901 | 2354 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_ENABLE); |
mbed_official | 87:085cde657901 | 2355 | break; |
mbed_official | 87:085cde657901 | 2356 | } |
mbed_official | 87:085cde657901 | 2357 | } |
mbed_official | 87:085cde657901 | 2358 | /* Enable the Peripheral */ |
mbed_official | 87:085cde657901 | 2359 | __HAL_TIM_ENABLE(htim); |
mbed_official | 87:085cde657901 | 2360 | |
mbed_official | 87:085cde657901 | 2361 | /* Return function status */ |
mbed_official | 87:085cde657901 | 2362 | return HAL_OK; |
mbed_official | 87:085cde657901 | 2363 | } |
mbed_official | 87:085cde657901 | 2364 | |
mbed_official | 87:085cde657901 | 2365 | /** |
mbed_official | 87:085cde657901 | 2366 | * @brief Stops the TIM Encoder Interface. |
mbed_official | 87:085cde657901 | 2367 | * @param htim : TIM Encoder Interface handle |
mbed_official | 87:085cde657901 | 2368 | * @param Channel : TIM Channels to be disabled |
mbed_official | 87:085cde657901 | 2369 | * This parameter can be one of the following values: |
mbed_official | 87:085cde657901 | 2370 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
mbed_official | 87:085cde657901 | 2371 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
mbed_official | 87:085cde657901 | 2372 | * @retval HAL status |
mbed_official | 87:085cde657901 | 2373 | */ |
mbed_official | 87:085cde657901 | 2374 | HAL_StatusTypeDef HAL_TIM_Encoder_Stop(TIM_HandleTypeDef *htim, uint32_t Channel) |
mbed_official | 87:085cde657901 | 2375 | { |
mbed_official | 87:085cde657901 | 2376 | /* Check the parameters */ |
mbed_official | 87:085cde657901 | 2377 | assert_param(IS_TIM_CC2_INSTANCE(htim->Instance)); |
mbed_official | 87:085cde657901 | 2378 | |
mbed_official | 87:085cde657901 | 2379 | /* Disable the Input Capture channels 1 and 2 |
mbed_official | 87:085cde657901 | 2380 | (in the EncoderInterface the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2) */ |
mbed_official | 87:085cde657901 | 2381 | switch (Channel) |
mbed_official | 87:085cde657901 | 2382 | { |
mbed_official | 87:085cde657901 | 2383 | case TIM_CHANNEL_1: |
mbed_official | 87:085cde657901 | 2384 | { |
mbed_official | 87:085cde657901 | 2385 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE); |
mbed_official | 87:085cde657901 | 2386 | break; |
mbed_official | 87:085cde657901 | 2387 | } |
mbed_official | 87:085cde657901 | 2388 | case TIM_CHANNEL_2: |
mbed_official | 87:085cde657901 | 2389 | { |
mbed_official | 87:085cde657901 | 2390 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE); |
mbed_official | 87:085cde657901 | 2391 | break; |
mbed_official | 87:085cde657901 | 2392 | } |
mbed_official | 87:085cde657901 | 2393 | default : |
mbed_official | 87:085cde657901 | 2394 | { |
mbed_official | 87:085cde657901 | 2395 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE); |
mbed_official | 87:085cde657901 | 2396 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE); |
mbed_official | 87:085cde657901 | 2397 | break; |
mbed_official | 87:085cde657901 | 2398 | } |
mbed_official | 87:085cde657901 | 2399 | } |
mbed_official | 87:085cde657901 | 2400 | /* Disable the Peripheral */ |
mbed_official | 87:085cde657901 | 2401 | __HAL_TIM_DISABLE(htim); |
mbed_official | 87:085cde657901 | 2402 | |
mbed_official | 87:085cde657901 | 2403 | /* Return function status */ |
mbed_official | 87:085cde657901 | 2404 | return HAL_OK; |
mbed_official | 87:085cde657901 | 2405 | } |
mbed_official | 87:085cde657901 | 2406 | |
mbed_official | 87:085cde657901 | 2407 | /** |
mbed_official | 87:085cde657901 | 2408 | * @brief Starts the TIM Encoder Interface in interrupt mode. |
mbed_official | 87:085cde657901 | 2409 | * @param htim : TIM Encoder Interface handle |
mbed_official | 87:085cde657901 | 2410 | * @param Channel : TIM Channels to be enabled |
mbed_official | 87:085cde657901 | 2411 | * This parameter can be one of the following values: |
mbed_official | 87:085cde657901 | 2412 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
mbed_official | 87:085cde657901 | 2413 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
mbed_official | 87:085cde657901 | 2414 | * @retval HAL status |
mbed_official | 87:085cde657901 | 2415 | */ |
mbed_official | 87:085cde657901 | 2416 | HAL_StatusTypeDef HAL_TIM_Encoder_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel) |
mbed_official | 87:085cde657901 | 2417 | { |
mbed_official | 87:085cde657901 | 2418 | /* Check the parameters */ |
mbed_official | 87:085cde657901 | 2419 | assert_param(IS_TIM_CC2_INSTANCE(htim->Instance)); |
mbed_official | 87:085cde657901 | 2420 | |
mbed_official | 87:085cde657901 | 2421 | /* Enable the encoder interface channels */ |
mbed_official | 87:085cde657901 | 2422 | /* Enable the capture compare Interrupts 1 and/or 2 */ |
mbed_official | 87:085cde657901 | 2423 | switch (Channel) |
mbed_official | 87:085cde657901 | 2424 | { |
mbed_official | 87:085cde657901 | 2425 | case TIM_CHANNEL_1: |
mbed_official | 87:085cde657901 | 2426 | { |
mbed_official | 87:085cde657901 | 2427 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE); |
mbed_official | 87:085cde657901 | 2428 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1); |
mbed_official | 87:085cde657901 | 2429 | break; |
mbed_official | 87:085cde657901 | 2430 | } |
mbed_official | 87:085cde657901 | 2431 | case TIM_CHANNEL_2: |
mbed_official | 87:085cde657901 | 2432 | { |
mbed_official | 87:085cde657901 | 2433 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_ENABLE); |
mbed_official | 87:085cde657901 | 2434 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2); |
mbed_official | 87:085cde657901 | 2435 | break; |
mbed_official | 87:085cde657901 | 2436 | } |
mbed_official | 87:085cde657901 | 2437 | default : |
mbed_official | 87:085cde657901 | 2438 | { |
mbed_official | 87:085cde657901 | 2439 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE); |
mbed_official | 87:085cde657901 | 2440 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_ENABLE); |
mbed_official | 87:085cde657901 | 2441 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1); |
mbed_official | 87:085cde657901 | 2442 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2); |
mbed_official | 87:085cde657901 | 2443 | break; |
mbed_official | 87:085cde657901 | 2444 | } |
mbed_official | 87:085cde657901 | 2445 | } |
mbed_official | 87:085cde657901 | 2446 | |
mbed_official | 87:085cde657901 | 2447 | /* Enable the Peripheral */ |
mbed_official | 87:085cde657901 | 2448 | __HAL_TIM_ENABLE(htim); |
mbed_official | 87:085cde657901 | 2449 | |
mbed_official | 87:085cde657901 | 2450 | /* Return function status */ |
mbed_official | 87:085cde657901 | 2451 | return HAL_OK; |
mbed_official | 87:085cde657901 | 2452 | } |
mbed_official | 87:085cde657901 | 2453 | |
mbed_official | 87:085cde657901 | 2454 | /** |
mbed_official | 87:085cde657901 | 2455 | * @brief Stops the TIM Encoder Interface in interrupt mode. |
mbed_official | 87:085cde657901 | 2456 | * @param htim : TIM Encoder Interface handle |
mbed_official | 87:085cde657901 | 2457 | * @param Channel : TIM Channels to be disabled |
mbed_official | 87:085cde657901 | 2458 | * This parameter can be one of the following values: |
mbed_official | 87:085cde657901 | 2459 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
mbed_official | 87:085cde657901 | 2460 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
mbed_official | 87:085cde657901 | 2461 | * @retval HAL status |
mbed_official | 87:085cde657901 | 2462 | */ |
mbed_official | 87:085cde657901 | 2463 | HAL_StatusTypeDef HAL_TIM_Encoder_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel) |
mbed_official | 87:085cde657901 | 2464 | { |
mbed_official | 87:085cde657901 | 2465 | /* Check the parameters */ |
mbed_official | 87:085cde657901 | 2466 | assert_param(IS_TIM_CC2_INSTANCE(htim->Instance)); |
mbed_official | 87:085cde657901 | 2467 | |
mbed_official | 87:085cde657901 | 2468 | /* Disable the Input Capture channels 1 and 2 |
mbed_official | 87:085cde657901 | 2469 | (in the EncoderInterface the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2) */ |
mbed_official | 87:085cde657901 | 2470 | if(Channel == TIM_CHANNEL_1) |
mbed_official | 87:085cde657901 | 2471 | { |
mbed_official | 87:085cde657901 | 2472 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE); |
mbed_official | 87:085cde657901 | 2473 | |
mbed_official | 87:085cde657901 | 2474 | /* Disable the capture compare Interrupts 1 */ |
mbed_official | 87:085cde657901 | 2475 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1); |
mbed_official | 87:085cde657901 | 2476 | } |
mbed_official | 87:085cde657901 | 2477 | else if(Channel == TIM_CHANNEL_2) |
mbed_official | 87:085cde657901 | 2478 | { |
mbed_official | 87:085cde657901 | 2479 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE); |
mbed_official | 87:085cde657901 | 2480 | |
mbed_official | 87:085cde657901 | 2481 | /* Disable the capture compare Interrupts 2 */ |
mbed_official | 87:085cde657901 | 2482 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2); |
mbed_official | 87:085cde657901 | 2483 | } |
mbed_official | 87:085cde657901 | 2484 | else |
mbed_official | 87:085cde657901 | 2485 | { |
mbed_official | 87:085cde657901 | 2486 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE); |
mbed_official | 87:085cde657901 | 2487 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE); |
mbed_official | 87:085cde657901 | 2488 | |
mbed_official | 87:085cde657901 | 2489 | /* Disable the capture compare Interrupts 1 and 2 */ |
mbed_official | 87:085cde657901 | 2490 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1); |
mbed_official | 87:085cde657901 | 2491 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2); |
mbed_official | 87:085cde657901 | 2492 | } |
mbed_official | 87:085cde657901 | 2493 | |
mbed_official | 87:085cde657901 | 2494 | /* Disable the Peripheral */ |
mbed_official | 87:085cde657901 | 2495 | __HAL_TIM_DISABLE(htim); |
mbed_official | 87:085cde657901 | 2496 | |
mbed_official | 87:085cde657901 | 2497 | /* Change the htim state */ |
mbed_official | 87:085cde657901 | 2498 | htim->State = HAL_TIM_STATE_READY; |
mbed_official | 87:085cde657901 | 2499 | |
mbed_official | 87:085cde657901 | 2500 | /* Return function status */ |
mbed_official | 87:085cde657901 | 2501 | return HAL_OK; |
mbed_official | 87:085cde657901 | 2502 | } |
mbed_official | 87:085cde657901 | 2503 | |
mbed_official | 87:085cde657901 | 2504 | /** |
mbed_official | 87:085cde657901 | 2505 | * @brief Starts the TIM Encoder Interface in DMA mode. |
mbed_official | 87:085cde657901 | 2506 | * @param htim : TIM Encoder Interface handle |
mbed_official | 87:085cde657901 | 2507 | * @param Channel : TIM Channels to be enabled |
mbed_official | 87:085cde657901 | 2508 | * This parameter can be one of the following values: |
mbed_official | 87:085cde657901 | 2509 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
mbed_official | 87:085cde657901 | 2510 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
mbed_official | 87:085cde657901 | 2511 | * @param pData1: The destination Buffer address for IC1. |
mbed_official | 87:085cde657901 | 2512 | * @param pData2: The destination Buffer address for IC2. |
mbed_official | 87:085cde657901 | 2513 | * @param Length: The length of data to be transferred from TIM peripheral to memory. |
mbed_official | 87:085cde657901 | 2514 | * @retval HAL status |
mbed_official | 87:085cde657901 | 2515 | */ |
mbed_official | 87:085cde657901 | 2516 | HAL_StatusTypeDef HAL_TIM_Encoder_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData1, uint32_t *pData2, uint16_t Length) |
mbed_official | 87:085cde657901 | 2517 | { |
mbed_official | 87:085cde657901 | 2518 | /* Check the parameters */ |
mbed_official | 87:085cde657901 | 2519 | assert_param(IS_TIM_DMA_CC_INSTANCE(htim->Instance)); |
mbed_official | 87:085cde657901 | 2520 | |
mbed_official | 87:085cde657901 | 2521 | if((htim->State == HAL_TIM_STATE_BUSY)) |
mbed_official | 87:085cde657901 | 2522 | { |
mbed_official | 87:085cde657901 | 2523 | return HAL_BUSY; |
mbed_official | 87:085cde657901 | 2524 | } |
mbed_official | 87:085cde657901 | 2525 | else if((htim->State == HAL_TIM_STATE_READY)) |
mbed_official | 87:085cde657901 | 2526 | { |
mbed_official | 87:085cde657901 | 2527 | if((((pData1 == 0) || (pData2 == 0) )) && (Length > 0)) |
mbed_official | 87:085cde657901 | 2528 | { |
mbed_official | 87:085cde657901 | 2529 | return HAL_ERROR; |
mbed_official | 87:085cde657901 | 2530 | } |
mbed_official | 87:085cde657901 | 2531 | else |
mbed_official | 87:085cde657901 | 2532 | { |
mbed_official | 87:085cde657901 | 2533 | htim->State = HAL_TIM_STATE_BUSY; |
mbed_official | 87:085cde657901 | 2534 | } |
mbed_official | 87:085cde657901 | 2535 | } |
mbed_official | 87:085cde657901 | 2536 | |
mbed_official | 87:085cde657901 | 2537 | switch (Channel) |
mbed_official | 87:085cde657901 | 2538 | { |
mbed_official | 87:085cde657901 | 2539 | case TIM_CHANNEL_1: |
mbed_official | 87:085cde657901 | 2540 | { |
mbed_official | 87:085cde657901 | 2541 | /* Set the DMA Period elapsed callback */ |
mbed_official | 87:085cde657901 | 2542 | htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = HAL_TIM_DMACaptureCplt; |
mbed_official | 87:085cde657901 | 2543 | |
mbed_official | 87:085cde657901 | 2544 | /* Set the DMA error callback */ |
mbed_official | 87:085cde657901 | 2545 | htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = HAL_TIM_DMAError ; |
mbed_official | 87:085cde657901 | 2546 | |
mbed_official | 87:085cde657901 | 2547 | /* Enable the DMA Stream */ |
mbed_official | 87:085cde657901 | 2548 | HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)&htim->Instance->CCR1, (uint32_t )pData1, Length); |
mbed_official | 87:085cde657901 | 2549 | |
mbed_official | 87:085cde657901 | 2550 | /* Enable the TIM Input Capture DMA request */ |
mbed_official | 87:085cde657901 | 2551 | __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1); |
mbed_official | 87:085cde657901 | 2552 | |
mbed_official | 87:085cde657901 | 2553 | /* Enable the Peripheral */ |
mbed_official | 87:085cde657901 | 2554 | __HAL_TIM_ENABLE(htim); |
mbed_official | 87:085cde657901 | 2555 | |
mbed_official | 87:085cde657901 | 2556 | /* Enable the Capture compare channel */ |
mbed_official | 87:085cde657901 | 2557 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE); |
mbed_official | 87:085cde657901 | 2558 | } |
mbed_official | 87:085cde657901 | 2559 | break; |
mbed_official | 87:085cde657901 | 2560 | |
mbed_official | 87:085cde657901 | 2561 | case TIM_CHANNEL_2: |
mbed_official | 87:085cde657901 | 2562 | { |
mbed_official | 87:085cde657901 | 2563 | /* Set the DMA Period elapsed callback */ |
mbed_official | 87:085cde657901 | 2564 | htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = HAL_TIM_DMACaptureCplt; |
mbed_official | 87:085cde657901 | 2565 | |
mbed_official | 87:085cde657901 | 2566 | /* Set the DMA error callback */ |
mbed_official | 87:085cde657901 | 2567 | htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = HAL_TIM_DMAError; |
mbed_official | 87:085cde657901 | 2568 | /* Enable the DMA Stream */ |
mbed_official | 87:085cde657901 | 2569 | HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)&htim->Instance->CCR2, (uint32_t)pData2, Length); |
mbed_official | 87:085cde657901 | 2570 | |
mbed_official | 87:085cde657901 | 2571 | /* Enable the TIM Input Capture DMA request */ |
mbed_official | 87:085cde657901 | 2572 | __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC2); |
mbed_official | 87:085cde657901 | 2573 | |
mbed_official | 87:085cde657901 | 2574 | /* Enable the Peripheral */ |
mbed_official | 87:085cde657901 | 2575 | __HAL_TIM_ENABLE(htim); |
mbed_official | 87:085cde657901 | 2576 | |
mbed_official | 87:085cde657901 | 2577 | /* Enable the Capture compare channel */ |
mbed_official | 87:085cde657901 | 2578 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_ENABLE); |
mbed_official | 87:085cde657901 | 2579 | } |
mbed_official | 87:085cde657901 | 2580 | break; |
mbed_official | 87:085cde657901 | 2581 | |
mbed_official | 87:085cde657901 | 2582 | case TIM_CHANNEL_ALL: |
mbed_official | 87:085cde657901 | 2583 | { |
mbed_official | 87:085cde657901 | 2584 | /* Set the DMA Period elapsed callback */ |
mbed_official | 87:085cde657901 | 2585 | htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = HAL_TIM_DMACaptureCplt; |
mbed_official | 87:085cde657901 | 2586 | |
mbed_official | 87:085cde657901 | 2587 | /* Set the DMA error callback */ |
mbed_official | 87:085cde657901 | 2588 | htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = HAL_TIM_DMAError ; |
mbed_official | 87:085cde657901 | 2589 | |
mbed_official | 87:085cde657901 | 2590 | /* Enable the DMA Stream */ |
mbed_official | 87:085cde657901 | 2591 | HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)&htim->Instance->CCR1, (uint32_t)pData1, Length); |
mbed_official | 87:085cde657901 | 2592 | |
mbed_official | 87:085cde657901 | 2593 | /* Set the DMA Period elapsed callback */ |
mbed_official | 87:085cde657901 | 2594 | htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = HAL_TIM_DMACaptureCplt; |
mbed_official | 87:085cde657901 | 2595 | |
mbed_official | 87:085cde657901 | 2596 | /* Set the DMA error callback */ |
mbed_official | 87:085cde657901 | 2597 | htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = HAL_TIM_DMAError ; |
mbed_official | 87:085cde657901 | 2598 | |
mbed_official | 87:085cde657901 | 2599 | /* Enable the DMA Stream */ |
mbed_official | 87:085cde657901 | 2600 | HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)&htim->Instance->CCR2, (uint32_t)pData2, Length); |
mbed_official | 87:085cde657901 | 2601 | |
mbed_official | 87:085cde657901 | 2602 | /* Enable the Peripheral */ |
mbed_official | 87:085cde657901 | 2603 | __HAL_TIM_ENABLE(htim); |
mbed_official | 87:085cde657901 | 2604 | |
mbed_official | 87:085cde657901 | 2605 | /* Enable the Capture compare channel */ |
mbed_official | 87:085cde657901 | 2606 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE); |
mbed_official | 87:085cde657901 | 2607 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_ENABLE); |
mbed_official | 87:085cde657901 | 2608 | |
mbed_official | 87:085cde657901 | 2609 | /* Enable the TIM Input Capture DMA request */ |
mbed_official | 87:085cde657901 | 2610 | __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1); |
mbed_official | 87:085cde657901 | 2611 | /* Enable the TIM Input Capture DMA request */ |
mbed_official | 87:085cde657901 | 2612 | __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC2); |
mbed_official | 87:085cde657901 | 2613 | } |
mbed_official | 87:085cde657901 | 2614 | break; |
mbed_official | 87:085cde657901 | 2615 | |
mbed_official | 87:085cde657901 | 2616 | default: |
mbed_official | 87:085cde657901 | 2617 | break; |
mbed_official | 87:085cde657901 | 2618 | } |
mbed_official | 87:085cde657901 | 2619 | /* Return function status */ |
mbed_official | 87:085cde657901 | 2620 | return HAL_OK; |
mbed_official | 87:085cde657901 | 2621 | } |
mbed_official | 87:085cde657901 | 2622 | |
mbed_official | 87:085cde657901 | 2623 | /** |
mbed_official | 87:085cde657901 | 2624 | * @brief Stops the TIM Encoder Interface in DMA mode. |
mbed_official | 87:085cde657901 | 2625 | * @param htim : TIM Encoder Interface handle |
mbed_official | 87:085cde657901 | 2626 | * @param Channel : TIM Channels to be enabled |
mbed_official | 87:085cde657901 | 2627 | * This parameter can be one of the following values: |
mbed_official | 87:085cde657901 | 2628 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
mbed_official | 87:085cde657901 | 2629 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
mbed_official | 87:085cde657901 | 2630 | * @retval HAL status |
mbed_official | 87:085cde657901 | 2631 | */ |
mbed_official | 87:085cde657901 | 2632 | HAL_StatusTypeDef HAL_TIM_Encoder_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel) |
mbed_official | 87:085cde657901 | 2633 | { |
mbed_official | 87:085cde657901 | 2634 | /* Check the parameters */ |
mbed_official | 87:085cde657901 | 2635 | assert_param(IS_TIM_DMA_CC_INSTANCE(htim->Instance)); |
mbed_official | 87:085cde657901 | 2636 | |
mbed_official | 87:085cde657901 | 2637 | /* Disable the Input Capture channels 1 and 2 |
mbed_official | 87:085cde657901 | 2638 | (in the EncoderInterface the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2) */ |
mbed_official | 87:085cde657901 | 2639 | if(Channel == TIM_CHANNEL_1) |
mbed_official | 87:085cde657901 | 2640 | { |
mbed_official | 87:085cde657901 | 2641 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE); |
mbed_official | 87:085cde657901 | 2642 | |
mbed_official | 87:085cde657901 | 2643 | /* Disable the capture compare DMA Request 1 */ |
mbed_official | 87:085cde657901 | 2644 | __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1); |
mbed_official | 87:085cde657901 | 2645 | } |
mbed_official | 87:085cde657901 | 2646 | else if(Channel == TIM_CHANNEL_2) |
mbed_official | 87:085cde657901 | 2647 | { |
mbed_official | 87:085cde657901 | 2648 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE); |
mbed_official | 87:085cde657901 | 2649 | |
mbed_official | 87:085cde657901 | 2650 | /* Disable the capture compare DMA Request 2 */ |
mbed_official | 87:085cde657901 | 2651 | __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC2); |
mbed_official | 87:085cde657901 | 2652 | } |
mbed_official | 87:085cde657901 | 2653 | else |
mbed_official | 87:085cde657901 | 2654 | { |
mbed_official | 87:085cde657901 | 2655 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE); |
mbed_official | 87:085cde657901 | 2656 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE); |
mbed_official | 87:085cde657901 | 2657 | |
mbed_official | 87:085cde657901 | 2658 | /* Disable the capture compare DMA Request 1 and 2 */ |
mbed_official | 87:085cde657901 | 2659 | __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1); |
mbed_official | 87:085cde657901 | 2660 | __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC2); |
mbed_official | 87:085cde657901 | 2661 | } |
mbed_official | 87:085cde657901 | 2662 | |
mbed_official | 87:085cde657901 | 2663 | /* Disable the Peripheral */ |
mbed_official | 87:085cde657901 | 2664 | __HAL_TIM_DISABLE(htim); |
mbed_official | 87:085cde657901 | 2665 | |
mbed_official | 87:085cde657901 | 2666 | /* Change the htim state */ |
mbed_official | 87:085cde657901 | 2667 | htim->State = HAL_TIM_STATE_READY; |
mbed_official | 87:085cde657901 | 2668 | |
mbed_official | 87:085cde657901 | 2669 | /* Return function status */ |
mbed_official | 87:085cde657901 | 2670 | return HAL_OK; |
mbed_official | 87:085cde657901 | 2671 | } |
mbed_official | 87:085cde657901 | 2672 | |
mbed_official | 87:085cde657901 | 2673 | /** |
mbed_official | 87:085cde657901 | 2674 | * @} |
mbed_official | 87:085cde657901 | 2675 | */ |
mbed_official | 87:085cde657901 | 2676 | /** @defgroup TIM_Group7 TIM IRQ handler management |
mbed_official | 87:085cde657901 | 2677 | * @brief IRQ handler management |
mbed_official | 87:085cde657901 | 2678 | * |
mbed_official | 87:085cde657901 | 2679 | @verbatim |
mbed_official | 87:085cde657901 | 2680 | ============================================================================== |
mbed_official | 87:085cde657901 | 2681 | ##### IRQ handler management ##### |
mbed_official | 87:085cde657901 | 2682 | ============================================================================== |
mbed_official | 87:085cde657901 | 2683 | [..] |
mbed_official | 87:085cde657901 | 2684 | This section provides Timer IRQ handler function. |
mbed_official | 87:085cde657901 | 2685 | |
mbed_official | 87:085cde657901 | 2686 | @endverbatim |
mbed_official | 87:085cde657901 | 2687 | * @{ |
mbed_official | 87:085cde657901 | 2688 | */ |
mbed_official | 87:085cde657901 | 2689 | /** |
mbed_official | 87:085cde657901 | 2690 | * @brief This function handles TIM interrupts requests. |
mbed_official | 87:085cde657901 | 2691 | * @param htim: TIM handle |
mbed_official | 87:085cde657901 | 2692 | * @retval None |
mbed_official | 87:085cde657901 | 2693 | */ |
mbed_official | 87:085cde657901 | 2694 | void HAL_TIM_IRQHandler(TIM_HandleTypeDef *htim) |
mbed_official | 87:085cde657901 | 2695 | { |
mbed_official | 87:085cde657901 | 2696 | /* Capture compare 1 event */ |
mbed_official | 87:085cde657901 | 2697 | if(__HAL_TIM_GET_FLAG(htim, TIM_FLAG_CC1) != RESET) |
mbed_official | 87:085cde657901 | 2698 | { |
mbed_official | 87:085cde657901 | 2699 | if(__HAL_TIM_GET_ITSTATUS(htim, TIM_IT_CC1) !=RESET) |
mbed_official | 87:085cde657901 | 2700 | { |
mbed_official | 87:085cde657901 | 2701 | { |
mbed_official | 87:085cde657901 | 2702 | __HAL_TIM_CLEAR_IT(htim, TIM_IT_CC1); |
mbed_official | 87:085cde657901 | 2703 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_1; |
mbed_official | 87:085cde657901 | 2704 | |
mbed_official | 87:085cde657901 | 2705 | /* Input capture event */ |
mbed_official | 87:085cde657901 | 2706 | if((htim->Instance->CCMR1 & TIM_CCMR1_CC1S) != 0x00) |
mbed_official | 87:085cde657901 | 2707 | { |
mbed_official | 87:085cde657901 | 2708 | HAL_TIM_IC_CaptureCallback(htim); |
mbed_official | 87:085cde657901 | 2709 | } |
mbed_official | 87:085cde657901 | 2710 | /* Output compare event */ |
mbed_official | 87:085cde657901 | 2711 | else |
mbed_official | 87:085cde657901 | 2712 | { |
mbed_official | 87:085cde657901 | 2713 | HAL_TIM_OC_DelayElapsedCallback(htim); |
mbed_official | 87:085cde657901 | 2714 | HAL_TIM_PWM_PulseFinishedCallback(htim); |
mbed_official | 87:085cde657901 | 2715 | } |
mbed_official | 87:085cde657901 | 2716 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_CLEARED; |
mbed_official | 87:085cde657901 | 2717 | } |
mbed_official | 87:085cde657901 | 2718 | } |
mbed_official | 87:085cde657901 | 2719 | } |
mbed_official | 87:085cde657901 | 2720 | /* Capture compare 2 event */ |
mbed_official | 87:085cde657901 | 2721 | if(__HAL_TIM_GET_FLAG(htim, TIM_FLAG_CC2) != RESET) |
mbed_official | 87:085cde657901 | 2722 | { |
mbed_official | 87:085cde657901 | 2723 | if(__HAL_TIM_GET_ITSTATUS(htim, TIM_IT_CC2) !=RESET) |
mbed_official | 87:085cde657901 | 2724 | { |
mbed_official | 87:085cde657901 | 2725 | __HAL_TIM_CLEAR_IT(htim, TIM_IT_CC2); |
mbed_official | 87:085cde657901 | 2726 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_2; |
mbed_official | 87:085cde657901 | 2727 | /* Input capture event */ |
mbed_official | 87:085cde657901 | 2728 | if((htim->Instance->CCMR1 & TIM_CCMR1_CC2S) != 0x00) |
mbed_official | 87:085cde657901 | 2729 | { |
mbed_official | 87:085cde657901 | 2730 | HAL_TIM_IC_CaptureCallback(htim); |
mbed_official | 87:085cde657901 | 2731 | } |
mbed_official | 87:085cde657901 | 2732 | /* Output compare event */ |
mbed_official | 87:085cde657901 | 2733 | else |
mbed_official | 87:085cde657901 | 2734 | { |
mbed_official | 87:085cde657901 | 2735 | HAL_TIM_OC_DelayElapsedCallback(htim); |
mbed_official | 87:085cde657901 | 2736 | HAL_TIM_PWM_PulseFinishedCallback(htim); |
mbed_official | 87:085cde657901 | 2737 | } |
mbed_official | 87:085cde657901 | 2738 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_CLEARED; |
mbed_official | 87:085cde657901 | 2739 | } |
mbed_official | 87:085cde657901 | 2740 | } |
mbed_official | 87:085cde657901 | 2741 | /* Capture compare 3 event */ |
mbed_official | 87:085cde657901 | 2742 | if(__HAL_TIM_GET_FLAG(htim, TIM_FLAG_CC3) != RESET) |
mbed_official | 87:085cde657901 | 2743 | { |
mbed_official | 87:085cde657901 | 2744 | if(__HAL_TIM_GET_ITSTATUS(htim, TIM_IT_CC3) !=RESET) |
mbed_official | 87:085cde657901 | 2745 | { |
mbed_official | 87:085cde657901 | 2746 | __HAL_TIM_CLEAR_IT(htim, TIM_IT_CC3); |
mbed_official | 87:085cde657901 | 2747 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_3; |
mbed_official | 87:085cde657901 | 2748 | /* Input capture event */ |
mbed_official | 87:085cde657901 | 2749 | if((htim->Instance->CCMR1 & TIM_CCMR2_CC3S) != 0x00) |
mbed_official | 87:085cde657901 | 2750 | { |
mbed_official | 87:085cde657901 | 2751 | HAL_TIM_IC_CaptureCallback(htim); |
mbed_official | 87:085cde657901 | 2752 | } |
mbed_official | 87:085cde657901 | 2753 | /* Output compare event */ |
mbed_official | 87:085cde657901 | 2754 | else |
mbed_official | 87:085cde657901 | 2755 | { |
mbed_official | 87:085cde657901 | 2756 | HAL_TIM_OC_DelayElapsedCallback(htim); |
mbed_official | 87:085cde657901 | 2757 | HAL_TIM_PWM_PulseFinishedCallback(htim); |
mbed_official | 87:085cde657901 | 2758 | } |
mbed_official | 87:085cde657901 | 2759 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_CLEARED; |
mbed_official | 87:085cde657901 | 2760 | } |
mbed_official | 87:085cde657901 | 2761 | } |
mbed_official | 87:085cde657901 | 2762 | /* Capture compare 4 event */ |
mbed_official | 87:085cde657901 | 2763 | if(__HAL_TIM_GET_FLAG(htim, TIM_FLAG_CC4) != RESET) |
mbed_official | 87:085cde657901 | 2764 | { |
mbed_official | 87:085cde657901 | 2765 | if(__HAL_TIM_GET_ITSTATUS(htim, TIM_IT_CC4) !=RESET) |
mbed_official | 87:085cde657901 | 2766 | { |
mbed_official | 87:085cde657901 | 2767 | __HAL_TIM_CLEAR_IT(htim, TIM_IT_CC4); |
mbed_official | 87:085cde657901 | 2768 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_4; |
mbed_official | 87:085cde657901 | 2769 | /* Input capture event */ |
mbed_official | 87:085cde657901 | 2770 | if((htim->Instance->CCMR1 & TIM_CCMR2_CC4S) != 0x00) |
mbed_official | 87:085cde657901 | 2771 | { |
mbed_official | 87:085cde657901 | 2772 | HAL_TIM_IC_CaptureCallback(htim); |
mbed_official | 87:085cde657901 | 2773 | } |
mbed_official | 87:085cde657901 | 2774 | /* Output compare event */ |
mbed_official | 87:085cde657901 | 2775 | else |
mbed_official | 87:085cde657901 | 2776 | { |
mbed_official | 87:085cde657901 | 2777 | HAL_TIM_OC_DelayElapsedCallback(htim); |
mbed_official | 87:085cde657901 | 2778 | HAL_TIM_PWM_PulseFinishedCallback(htim); |
mbed_official | 87:085cde657901 | 2779 | } |
mbed_official | 87:085cde657901 | 2780 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_CLEARED; |
mbed_official | 87:085cde657901 | 2781 | } |
mbed_official | 87:085cde657901 | 2782 | } |
mbed_official | 87:085cde657901 | 2783 | /* TIM Update event */ |
mbed_official | 87:085cde657901 | 2784 | if(__HAL_TIM_GET_FLAG(htim, TIM_FLAG_UPDATE) != RESET) |
mbed_official | 87:085cde657901 | 2785 | { |
mbed_official | 87:085cde657901 | 2786 | if(__HAL_TIM_GET_ITSTATUS(htim, TIM_IT_UPDATE) !=RESET) |
mbed_official | 87:085cde657901 | 2787 | { |
mbed_official | 87:085cde657901 | 2788 | __HAL_TIM_CLEAR_IT(htim, TIM_IT_UPDATE); |
mbed_official | 87:085cde657901 | 2789 | HAL_TIM_PeriodElapsedCallback(htim); |
mbed_official | 87:085cde657901 | 2790 | } |
mbed_official | 87:085cde657901 | 2791 | } |
mbed_official | 87:085cde657901 | 2792 | /* TIM Break input event */ |
mbed_official | 87:085cde657901 | 2793 | if(__HAL_TIM_GET_FLAG(htim, TIM_FLAG_BREAK) != RESET) |
mbed_official | 87:085cde657901 | 2794 | { |
mbed_official | 87:085cde657901 | 2795 | if(__HAL_TIM_GET_ITSTATUS(htim, TIM_IT_BREAK) !=RESET) |
mbed_official | 87:085cde657901 | 2796 | { |
mbed_official | 87:085cde657901 | 2797 | __HAL_TIM_CLEAR_IT(htim, TIM_IT_BREAK); |
mbed_official | 87:085cde657901 | 2798 | HAL_TIMEx_BreakCallback(htim); |
mbed_official | 87:085cde657901 | 2799 | } |
mbed_official | 87:085cde657901 | 2800 | } |
mbed_official | 87:085cde657901 | 2801 | /* TIM Trigger detection event */ |
mbed_official | 87:085cde657901 | 2802 | if(__HAL_TIM_GET_FLAG(htim, TIM_FLAG_TRIGGER) != RESET) |
mbed_official | 87:085cde657901 | 2803 | { |
mbed_official | 87:085cde657901 | 2804 | if(__HAL_TIM_GET_ITSTATUS(htim, TIM_IT_TRIGGER) !=RESET) |
mbed_official | 87:085cde657901 | 2805 | { |
mbed_official | 87:085cde657901 | 2806 | __HAL_TIM_CLEAR_IT(htim, TIM_IT_TRIGGER); |
mbed_official | 87:085cde657901 | 2807 | HAL_TIM_TriggerCallback(htim); |
mbed_official | 87:085cde657901 | 2808 | } |
mbed_official | 87:085cde657901 | 2809 | } |
mbed_official | 87:085cde657901 | 2810 | /* TIM commutation event */ |
mbed_official | 87:085cde657901 | 2811 | if(__HAL_TIM_GET_FLAG(htim, TIM_FLAG_COM) != RESET) |
mbed_official | 87:085cde657901 | 2812 | { |
mbed_official | 87:085cde657901 | 2813 | if(__HAL_TIM_GET_ITSTATUS(htim, TIM_IT_COM) !=RESET) |
mbed_official | 87:085cde657901 | 2814 | { |
mbed_official | 87:085cde657901 | 2815 | __HAL_TIM_CLEAR_IT(htim, TIM_FLAG_COM); |
mbed_official | 87:085cde657901 | 2816 | HAL_TIMEx_CommutationCallback(htim); |
mbed_official | 87:085cde657901 | 2817 | } |
mbed_official | 87:085cde657901 | 2818 | } |
mbed_official | 87:085cde657901 | 2819 | } |
mbed_official | 87:085cde657901 | 2820 | |
mbed_official | 87:085cde657901 | 2821 | /** |
mbed_official | 87:085cde657901 | 2822 | * @} |
mbed_official | 87:085cde657901 | 2823 | */ |
mbed_official | 87:085cde657901 | 2824 | |
mbed_official | 87:085cde657901 | 2825 | /** @defgroup TIM_Group8 Peripheral Control functions |
mbed_official | 87:085cde657901 | 2826 | * @brief Peripheral Control functions |
mbed_official | 87:085cde657901 | 2827 | * |
mbed_official | 87:085cde657901 | 2828 | @verbatim |
mbed_official | 87:085cde657901 | 2829 | ============================================================================== |
mbed_official | 87:085cde657901 | 2830 | ##### Peripheral Control functions ##### |
mbed_official | 87:085cde657901 | 2831 | ============================================================================== |
mbed_official | 87:085cde657901 | 2832 | [..] |
mbed_official | 87:085cde657901 | 2833 | This section provides functions allowing to: |
mbed_official | 87:085cde657901 | 2834 | (+) Configure The Input Output channels for OC, PWM, IC or One Pulse mode. |
mbed_official | 87:085cde657901 | 2835 | (+) Configure External Clock source. |
mbed_official | 87:085cde657901 | 2836 | (+) Configure Complementary channels, break features and dead time. |
mbed_official | 87:085cde657901 | 2837 | (+) Configure Master and the Slave synchronization. |
mbed_official | 87:085cde657901 | 2838 | (+) Configure the DMA Burst Mode. |
mbed_official | 87:085cde657901 | 2839 | |
mbed_official | 87:085cde657901 | 2840 | @endverbatim |
mbed_official | 87:085cde657901 | 2841 | * @{ |
mbed_official | 87:085cde657901 | 2842 | */ |
mbed_official | 87:085cde657901 | 2843 | |
mbed_official | 87:085cde657901 | 2844 | /** |
mbed_official | 87:085cde657901 | 2845 | * @brief Initializes the TIM Output Compare Channels according to the specified |
mbed_official | 87:085cde657901 | 2846 | * parameters in the TIM_OC_InitTypeDef. |
mbed_official | 87:085cde657901 | 2847 | * @param htim: TIM Output Compare handle |
mbed_official | 87:085cde657901 | 2848 | * @param sConfig: TIM Output Compare configuration structure |
mbed_official | 87:085cde657901 | 2849 | * @param Channel : TIM Channels to be enabled |
mbed_official | 87:085cde657901 | 2850 | * This parameter can be one of the following values: |
mbed_official | 87:085cde657901 | 2851 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
mbed_official | 87:085cde657901 | 2852 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
mbed_official | 87:085cde657901 | 2853 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
mbed_official | 87:085cde657901 | 2854 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
mbed_official | 87:085cde657901 | 2855 | * @retval HAL status |
mbed_official | 87:085cde657901 | 2856 | */ |
mbed_official | 87:085cde657901 | 2857 | HAL_StatusTypeDef HAL_TIM_OC_ConfigChannel(TIM_HandleTypeDef *htim, TIM_OC_InitTypeDef* sConfig, uint32_t Channel) |
mbed_official | 87:085cde657901 | 2858 | { |
mbed_official | 87:085cde657901 | 2859 | /* Check the parameters */ |
mbed_official | 87:085cde657901 | 2860 | assert_param(IS_TIM_CHANNELS(Channel)); |
mbed_official | 87:085cde657901 | 2861 | assert_param(IS_TIM_OC_MODE(sConfig->OCMode)); |
mbed_official | 87:085cde657901 | 2862 | assert_param(IS_TIM_OC_POLARITY(sConfig->OCPolarity)); |
mbed_official | 87:085cde657901 | 2863 | assert_param(IS_TIM_OCN_POLARITY(sConfig->OCNPolarity)); |
mbed_official | 87:085cde657901 | 2864 | assert_param(IS_TIM_FAST_STATE(sConfig->OCFastMode)); |
mbed_official | 87:085cde657901 | 2865 | assert_param(IS_TIM_OCNIDLE_STATE(sConfig->OCNIdleState)); |
mbed_official | 87:085cde657901 | 2866 | assert_param(IS_TIM_OCIDLE_STATE(sConfig->OCIdleState)); |
mbed_official | 87:085cde657901 | 2867 | |
mbed_official | 87:085cde657901 | 2868 | /* Check input state */ |
mbed_official | 87:085cde657901 | 2869 | __HAL_LOCK(htim); |
mbed_official | 87:085cde657901 | 2870 | |
mbed_official | 87:085cde657901 | 2871 | htim->State = HAL_TIM_STATE_BUSY; |
mbed_official | 87:085cde657901 | 2872 | |
mbed_official | 87:085cde657901 | 2873 | switch (Channel) |
mbed_official | 87:085cde657901 | 2874 | { |
mbed_official | 87:085cde657901 | 2875 | case TIM_CHANNEL_1: |
mbed_official | 87:085cde657901 | 2876 | { |
mbed_official | 87:085cde657901 | 2877 | assert_param(IS_TIM_CC1_INSTANCE(htim->Instance)); |
mbed_official | 87:085cde657901 | 2878 | /* Configure the TIM Channel 1 in Output Compare */ |
mbed_official | 87:085cde657901 | 2879 | TIM_OC1_SetConfig(htim->Instance, sConfig); |
mbed_official | 87:085cde657901 | 2880 | } |
mbed_official | 87:085cde657901 | 2881 | break; |
mbed_official | 87:085cde657901 | 2882 | |
mbed_official | 87:085cde657901 | 2883 | case TIM_CHANNEL_2: |
mbed_official | 87:085cde657901 | 2884 | { |
mbed_official | 87:085cde657901 | 2885 | assert_param(IS_TIM_CC2_INSTANCE(htim->Instance)); |
mbed_official | 87:085cde657901 | 2886 | /* Configure the TIM Channel 2 in Output Compare */ |
mbed_official | 87:085cde657901 | 2887 | TIM_OC2_SetConfig(htim->Instance, sConfig); |
mbed_official | 87:085cde657901 | 2888 | } |
mbed_official | 87:085cde657901 | 2889 | break; |
mbed_official | 87:085cde657901 | 2890 | |
mbed_official | 87:085cde657901 | 2891 | case TIM_CHANNEL_3: |
mbed_official | 87:085cde657901 | 2892 | { |
mbed_official | 87:085cde657901 | 2893 | assert_param(IS_TIM_CC3_INSTANCE(htim->Instance)); |
mbed_official | 87:085cde657901 | 2894 | /* Configure the TIM Channel 3 in Output Compare */ |
mbed_official | 87:085cde657901 | 2895 | TIM_OC3_SetConfig(htim->Instance, sConfig); |
mbed_official | 87:085cde657901 | 2896 | } |
mbed_official | 87:085cde657901 | 2897 | break; |
mbed_official | 87:085cde657901 | 2898 | |
mbed_official | 87:085cde657901 | 2899 | case TIM_CHANNEL_4: |
mbed_official | 87:085cde657901 | 2900 | { |
mbed_official | 87:085cde657901 | 2901 | assert_param(IS_TIM_CC4_INSTANCE(htim->Instance)); |
mbed_official | 87:085cde657901 | 2902 | /* Configure the TIM Channel 4 in Output Compare */ |
mbed_official | 87:085cde657901 | 2903 | TIM_OC4_SetConfig(htim->Instance, sConfig); |
mbed_official | 87:085cde657901 | 2904 | } |
mbed_official | 87:085cde657901 | 2905 | break; |
mbed_official | 87:085cde657901 | 2906 | |
mbed_official | 87:085cde657901 | 2907 | default: |
mbed_official | 87:085cde657901 | 2908 | break; |
mbed_official | 87:085cde657901 | 2909 | } |
mbed_official | 87:085cde657901 | 2910 | htim->State = HAL_TIM_STATE_READY; |
mbed_official | 87:085cde657901 | 2911 | |
mbed_official | 87:085cde657901 | 2912 | __HAL_UNLOCK(htim); |
mbed_official | 87:085cde657901 | 2913 | |
mbed_official | 87:085cde657901 | 2914 | return HAL_OK; |
mbed_official | 87:085cde657901 | 2915 | } |
mbed_official | 87:085cde657901 | 2916 | |
mbed_official | 87:085cde657901 | 2917 | /** |
mbed_official | 87:085cde657901 | 2918 | * @brief Initializes the TIM Input Capture Channels according to the specified |
mbed_official | 87:085cde657901 | 2919 | * parameters in the TIM_IC_InitTypeDef. |
mbed_official | 87:085cde657901 | 2920 | * @param htim: TIM IC handle |
mbed_official | 87:085cde657901 | 2921 | * @param sConfig: TIM Input Capture configuration structure |
mbed_official | 87:085cde657901 | 2922 | * @param Channel : TIM Channels to be enabled |
mbed_official | 87:085cde657901 | 2923 | * This parameter can be one of the following values: |
mbed_official | 87:085cde657901 | 2924 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
mbed_official | 87:085cde657901 | 2925 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
mbed_official | 87:085cde657901 | 2926 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
mbed_official | 87:085cde657901 | 2927 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
mbed_official | 87:085cde657901 | 2928 | * @retval HAL status |
mbed_official | 87:085cde657901 | 2929 | */ |
mbed_official | 87:085cde657901 | 2930 | HAL_StatusTypeDef HAL_TIM_IC_ConfigChannel(TIM_HandleTypeDef *htim, TIM_IC_InitTypeDef* sConfig, uint32_t Channel) |
mbed_official | 87:085cde657901 | 2931 | { |
mbed_official | 87:085cde657901 | 2932 | /* Check the parameters */ |
mbed_official | 87:085cde657901 | 2933 | assert_param(IS_TIM_CC1_INSTANCE(htim->Instance)); |
mbed_official | 87:085cde657901 | 2934 | assert_param(IS_TIM_IC_POLARITY(sConfig->ICPolarity)); |
mbed_official | 87:085cde657901 | 2935 | assert_param(IS_TIM_IC_SELECTION(sConfig->ICSelection)); |
mbed_official | 87:085cde657901 | 2936 | assert_param(IS_TIM_IC_PRESCALER(sConfig->ICPrescaler)); |
mbed_official | 87:085cde657901 | 2937 | assert_param(IS_TIM_IC_FILTER(sConfig->ICFilter)); |
mbed_official | 87:085cde657901 | 2938 | |
mbed_official | 87:085cde657901 | 2939 | __HAL_LOCK(htim); |
mbed_official | 87:085cde657901 | 2940 | |
mbed_official | 87:085cde657901 | 2941 | htim->State = HAL_TIM_STATE_BUSY; |
mbed_official | 87:085cde657901 | 2942 | |
mbed_official | 87:085cde657901 | 2943 | if (Channel == TIM_CHANNEL_1) |
mbed_official | 87:085cde657901 | 2944 | { |
mbed_official | 87:085cde657901 | 2945 | /* TI1 Configuration */ |
mbed_official | 87:085cde657901 | 2946 | TIM_TI1_SetConfig(htim->Instance, |
mbed_official | 87:085cde657901 | 2947 | sConfig->ICPolarity, |
mbed_official | 87:085cde657901 | 2948 | sConfig->ICSelection, |
mbed_official | 87:085cde657901 | 2949 | sConfig->ICFilter); |
mbed_official | 87:085cde657901 | 2950 | |
mbed_official | 87:085cde657901 | 2951 | /* Reset the IC1PSC Bits */ |
mbed_official | 87:085cde657901 | 2952 | htim->Instance->CCMR1 &= ~TIM_CCMR1_IC1PSC; |
mbed_official | 87:085cde657901 | 2953 | |
mbed_official | 87:085cde657901 | 2954 | /* Set the IC1PSC value */ |
mbed_official | 87:085cde657901 | 2955 | htim->Instance->CCMR1 |= sConfig->ICPrescaler; |
mbed_official | 87:085cde657901 | 2956 | } |
mbed_official | 87:085cde657901 | 2957 | else if (Channel == TIM_CHANNEL_2) |
mbed_official | 87:085cde657901 | 2958 | { |
mbed_official | 87:085cde657901 | 2959 | /* TI2 Configuration */ |
mbed_official | 87:085cde657901 | 2960 | assert_param(IS_TIM_CC2_INSTANCE(htim->Instance)); |
mbed_official | 87:085cde657901 | 2961 | |
mbed_official | 87:085cde657901 | 2962 | TIM_TI2_SetConfig(htim->Instance, |
mbed_official | 87:085cde657901 | 2963 | sConfig->ICPolarity, |
mbed_official | 87:085cde657901 | 2964 | sConfig->ICSelection, |
mbed_official | 87:085cde657901 | 2965 | sConfig->ICFilter); |
mbed_official | 87:085cde657901 | 2966 | |
mbed_official | 87:085cde657901 | 2967 | /* Reset the IC2PSC Bits */ |
mbed_official | 87:085cde657901 | 2968 | htim->Instance->CCMR1 &= ~TIM_CCMR1_IC2PSC; |
mbed_official | 87:085cde657901 | 2969 | |
mbed_official | 87:085cde657901 | 2970 | /* Set the IC2PSC value */ |
mbed_official | 87:085cde657901 | 2971 | htim->Instance->CCMR1 |= (sConfig->ICPrescaler << 8); |
mbed_official | 87:085cde657901 | 2972 | } |
mbed_official | 87:085cde657901 | 2973 | else if (Channel == TIM_CHANNEL_3) |
mbed_official | 87:085cde657901 | 2974 | { |
mbed_official | 87:085cde657901 | 2975 | /* TI3 Configuration */ |
mbed_official | 87:085cde657901 | 2976 | assert_param(IS_TIM_CC3_INSTANCE(htim->Instance)); |
mbed_official | 87:085cde657901 | 2977 | |
mbed_official | 87:085cde657901 | 2978 | TIM_TI3_SetConfig(htim->Instance, |
mbed_official | 87:085cde657901 | 2979 | sConfig->ICPolarity, |
mbed_official | 87:085cde657901 | 2980 | sConfig->ICSelection, |
mbed_official | 87:085cde657901 | 2981 | sConfig->ICFilter); |
mbed_official | 87:085cde657901 | 2982 | |
mbed_official | 87:085cde657901 | 2983 | /* Reset the IC3PSC Bits */ |
mbed_official | 87:085cde657901 | 2984 | htim->Instance->CCMR2 &= ~TIM_CCMR2_IC3PSC; |
mbed_official | 87:085cde657901 | 2985 | |
mbed_official | 87:085cde657901 | 2986 | /* Set the IC3PSC value */ |
mbed_official | 87:085cde657901 | 2987 | htim->Instance->CCMR2 |= sConfig->ICPrescaler; |
mbed_official | 87:085cde657901 | 2988 | } |
mbed_official | 87:085cde657901 | 2989 | else |
mbed_official | 87:085cde657901 | 2990 | { |
mbed_official | 87:085cde657901 | 2991 | /* TI4 Configuration */ |
mbed_official | 87:085cde657901 | 2992 | assert_param(IS_TIM_CC4_INSTANCE(htim->Instance)); |
mbed_official | 87:085cde657901 | 2993 | |
mbed_official | 87:085cde657901 | 2994 | TIM_TI4_SetConfig(htim->Instance, |
mbed_official | 87:085cde657901 | 2995 | sConfig->ICPolarity, |
mbed_official | 87:085cde657901 | 2996 | sConfig->ICSelection, |
mbed_official | 87:085cde657901 | 2997 | sConfig->ICFilter); |
mbed_official | 87:085cde657901 | 2998 | |
mbed_official | 87:085cde657901 | 2999 | /* Reset the IC4PSC Bits */ |
mbed_official | 87:085cde657901 | 3000 | htim->Instance->CCMR2 &= ~TIM_CCMR2_IC4PSC; |
mbed_official | 87:085cde657901 | 3001 | |
mbed_official | 87:085cde657901 | 3002 | /* Set the IC4PSC value */ |
mbed_official | 87:085cde657901 | 3003 | htim->Instance->CCMR2 |= (sConfig->ICPrescaler << 8); |
mbed_official | 87:085cde657901 | 3004 | } |
mbed_official | 87:085cde657901 | 3005 | |
mbed_official | 87:085cde657901 | 3006 | htim->State = HAL_TIM_STATE_READY; |
mbed_official | 87:085cde657901 | 3007 | |
mbed_official | 87:085cde657901 | 3008 | __HAL_UNLOCK(htim); |
mbed_official | 87:085cde657901 | 3009 | |
mbed_official | 87:085cde657901 | 3010 | return HAL_OK; |
mbed_official | 87:085cde657901 | 3011 | } |
mbed_official | 87:085cde657901 | 3012 | |
mbed_official | 87:085cde657901 | 3013 | /** |
mbed_official | 87:085cde657901 | 3014 | * @brief Initializes the TIM PWM channels according to the specified |
mbed_official | 87:085cde657901 | 3015 | * parameters in the TIM_OC_InitTypeDef. |
mbed_official | 87:085cde657901 | 3016 | * @param htim: TIM handle |
mbed_official | 87:085cde657901 | 3017 | * @param sConfig: TIM PWM configuration structure |
mbed_official | 87:085cde657901 | 3018 | * @param Channel : TIM Channels to be enabled |
mbed_official | 87:085cde657901 | 3019 | * This parameter can be one of the following values: |
mbed_official | 87:085cde657901 | 3020 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
mbed_official | 87:085cde657901 | 3021 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
mbed_official | 87:085cde657901 | 3022 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
mbed_official | 87:085cde657901 | 3023 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
mbed_official | 87:085cde657901 | 3024 | * @retval HAL status |
mbed_official | 87:085cde657901 | 3025 | */ |
mbed_official | 87:085cde657901 | 3026 | HAL_StatusTypeDef HAL_TIM_PWM_ConfigChannel(TIM_HandleTypeDef *htim, TIM_OC_InitTypeDef* sConfig, uint32_t Channel) |
mbed_official | 87:085cde657901 | 3027 | { |
mbed_official | 87:085cde657901 | 3028 | __HAL_LOCK(htim); |
mbed_official | 87:085cde657901 | 3029 | |
mbed_official | 87:085cde657901 | 3030 | /* Check the parameters */ |
mbed_official | 87:085cde657901 | 3031 | assert_param(IS_TIM_CHANNELS(Channel)); |
mbed_official | 87:085cde657901 | 3032 | assert_param(IS_TIM_PWM_MODE(sConfig->OCMode)); |
mbed_official | 87:085cde657901 | 3033 | assert_param(IS_TIM_OC_POLARITY(sConfig->OCPolarity)); |
mbed_official | 87:085cde657901 | 3034 | assert_param(IS_TIM_OCN_POLARITY(sConfig->OCNPolarity)); |
mbed_official | 87:085cde657901 | 3035 | assert_param(IS_TIM_OCNIDLE_STATE(sConfig->OCNIdleState)); |
mbed_official | 87:085cde657901 | 3036 | assert_param(IS_TIM_OCIDLE_STATE(sConfig->OCIdleState)); |
mbed_official | 87:085cde657901 | 3037 | |
mbed_official | 87:085cde657901 | 3038 | htim->State = HAL_TIM_STATE_BUSY; |
mbed_official | 87:085cde657901 | 3039 | |
mbed_official | 87:085cde657901 | 3040 | switch (Channel) |
mbed_official | 87:085cde657901 | 3041 | { |
mbed_official | 87:085cde657901 | 3042 | case TIM_CHANNEL_1: |
mbed_official | 87:085cde657901 | 3043 | { |
mbed_official | 87:085cde657901 | 3044 | assert_param(IS_TIM_CC1_INSTANCE(htim->Instance)); |
mbed_official | 87:085cde657901 | 3045 | /* Configure the Channel 1 in PWM mode */ |
mbed_official | 87:085cde657901 | 3046 | TIM_OC1_SetConfig(htim->Instance, sConfig); |
mbed_official | 87:085cde657901 | 3047 | |
mbed_official | 87:085cde657901 | 3048 | /* Set the Preload enable bit for channel1 */ |
mbed_official | 87:085cde657901 | 3049 | htim->Instance->CCMR1 |= TIM_CCMR1_OC1PE; |
mbed_official | 87:085cde657901 | 3050 | |
mbed_official | 87:085cde657901 | 3051 | /* Configure the Output Fast mode */ |
mbed_official | 87:085cde657901 | 3052 | htim->Instance->CCMR1 &= ~TIM_CCMR1_OC1FE; |
mbed_official | 87:085cde657901 | 3053 | htim->Instance->CCMR1 |= sConfig->OCFastMode; |
mbed_official | 87:085cde657901 | 3054 | } |
mbed_official | 87:085cde657901 | 3055 | break; |
mbed_official | 87:085cde657901 | 3056 | |
mbed_official | 87:085cde657901 | 3057 | case TIM_CHANNEL_2: |
mbed_official | 87:085cde657901 | 3058 | { |
mbed_official | 87:085cde657901 | 3059 | assert_param(IS_TIM_CC2_INSTANCE(htim->Instance)); |
mbed_official | 87:085cde657901 | 3060 | /* Configure the Channel 2 in PWM mode */ |
mbed_official | 87:085cde657901 | 3061 | TIM_OC2_SetConfig(htim->Instance, sConfig); |
mbed_official | 87:085cde657901 | 3062 | |
mbed_official | 87:085cde657901 | 3063 | /* Set the Preload enable bit for channel2 */ |
mbed_official | 87:085cde657901 | 3064 | htim->Instance->CCMR1 |= TIM_CCMR1_OC2PE; |
mbed_official | 87:085cde657901 | 3065 | |
mbed_official | 87:085cde657901 | 3066 | /* Configure the Output Fast mode */ |
mbed_official | 87:085cde657901 | 3067 | htim->Instance->CCMR1 &= ~TIM_CCMR1_OC2FE; |
mbed_official | 87:085cde657901 | 3068 | htim->Instance->CCMR1 |= sConfig->OCFastMode << 8; |
mbed_official | 87:085cde657901 | 3069 | } |
mbed_official | 87:085cde657901 | 3070 | break; |
mbed_official | 87:085cde657901 | 3071 | |
mbed_official | 87:085cde657901 | 3072 | case TIM_CHANNEL_3: |
mbed_official | 87:085cde657901 | 3073 | { |
mbed_official | 87:085cde657901 | 3074 | assert_param(IS_TIM_CC3_INSTANCE(htim->Instance)); |
mbed_official | 87:085cde657901 | 3075 | /* Configure the Channel 3 in PWM mode */ |
mbed_official | 87:085cde657901 | 3076 | TIM_OC3_SetConfig(htim->Instance, sConfig); |
mbed_official | 87:085cde657901 | 3077 | |
mbed_official | 87:085cde657901 | 3078 | /* Set the Preload enable bit for channel3 */ |
mbed_official | 87:085cde657901 | 3079 | htim->Instance->CCMR2 |= TIM_CCMR2_OC3PE; |
mbed_official | 87:085cde657901 | 3080 | |
mbed_official | 87:085cde657901 | 3081 | /* Configure the Output Fast mode */ |
mbed_official | 87:085cde657901 | 3082 | htim->Instance->CCMR2 &= ~TIM_CCMR2_OC3FE; |
mbed_official | 87:085cde657901 | 3083 | htim->Instance->CCMR2 |= sConfig->OCFastMode; |
mbed_official | 87:085cde657901 | 3084 | } |
mbed_official | 87:085cde657901 | 3085 | break; |
mbed_official | 87:085cde657901 | 3086 | |
mbed_official | 87:085cde657901 | 3087 | case TIM_CHANNEL_4: |
mbed_official | 87:085cde657901 | 3088 | { |
mbed_official | 87:085cde657901 | 3089 | assert_param(IS_TIM_CC4_INSTANCE(htim->Instance)); |
mbed_official | 87:085cde657901 | 3090 | /* Configure the Channel 4 in PWM mode */ |
mbed_official | 87:085cde657901 | 3091 | TIM_OC4_SetConfig(htim->Instance, sConfig); |
mbed_official | 87:085cde657901 | 3092 | |
mbed_official | 87:085cde657901 | 3093 | /* Set the Preload enable bit for channel4 */ |
mbed_official | 87:085cde657901 | 3094 | htim->Instance->CCMR2 |= TIM_CCMR2_OC4PE; |
mbed_official | 87:085cde657901 | 3095 | |
mbed_official | 87:085cde657901 | 3096 | /* Configure the Output Fast mode */ |
mbed_official | 87:085cde657901 | 3097 | htim->Instance->CCMR2 &= ~TIM_CCMR2_OC4FE; |
mbed_official | 87:085cde657901 | 3098 | htim->Instance->CCMR2 |= sConfig->OCFastMode << 8; |
mbed_official | 87:085cde657901 | 3099 | } |
mbed_official | 87:085cde657901 | 3100 | break; |
mbed_official | 87:085cde657901 | 3101 | |
mbed_official | 87:085cde657901 | 3102 | default: |
mbed_official | 87:085cde657901 | 3103 | break; |
mbed_official | 87:085cde657901 | 3104 | } |
mbed_official | 87:085cde657901 | 3105 | |
mbed_official | 87:085cde657901 | 3106 | htim->State = HAL_TIM_STATE_READY; |
mbed_official | 87:085cde657901 | 3107 | |
mbed_official | 87:085cde657901 | 3108 | __HAL_UNLOCK(htim); |
mbed_official | 87:085cde657901 | 3109 | |
mbed_official | 87:085cde657901 | 3110 | return HAL_OK; |
mbed_official | 87:085cde657901 | 3111 | } |
mbed_official | 87:085cde657901 | 3112 | |
mbed_official | 87:085cde657901 | 3113 | /** |
mbed_official | 87:085cde657901 | 3114 | * @brief Initializes the TIM One Pulse Channels according to the specified |
mbed_official | 87:085cde657901 | 3115 | * parameters in the TIM_OnePulse_InitTypeDef. |
mbed_official | 87:085cde657901 | 3116 | * @param htim: TIM One Pulse handle |
mbed_official | 87:085cde657901 | 3117 | * @param sConfig: TIM One Pulse configuration structure |
mbed_official | 87:085cde657901 | 3118 | * @param OutputChannel : TIM Channels to be enabled |
mbed_official | 87:085cde657901 | 3119 | * This parameter can be one of the following values: |
mbed_official | 87:085cde657901 | 3120 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
mbed_official | 87:085cde657901 | 3121 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
mbed_official | 87:085cde657901 | 3122 | * @param InputChannel : TIM Channels to be enabled |
mbed_official | 87:085cde657901 | 3123 | * This parameter can be one of the following values: |
mbed_official | 87:085cde657901 | 3124 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
mbed_official | 87:085cde657901 | 3125 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
mbed_official | 87:085cde657901 | 3126 | * @retval HAL status |
mbed_official | 87:085cde657901 | 3127 | */ |
mbed_official | 87:085cde657901 | 3128 | HAL_StatusTypeDef HAL_TIM_OnePulse_ConfigChannel(TIM_HandleTypeDef *htim, TIM_OnePulse_InitTypeDef* sConfig, uint32_t OutputChannel, uint32_t InputChannel) |
mbed_official | 87:085cde657901 | 3129 | { |
mbed_official | 87:085cde657901 | 3130 | TIM_OC_InitTypeDef temp1; |
mbed_official | 87:085cde657901 | 3131 | |
mbed_official | 87:085cde657901 | 3132 | /* Check the parameters */ |
mbed_official | 87:085cde657901 | 3133 | assert_param(IS_TIM_OPM_CHANNELS(OutputChannel)); |
mbed_official | 87:085cde657901 | 3134 | assert_param(IS_TIM_OPM_CHANNELS(InputChannel)); |
mbed_official | 87:085cde657901 | 3135 | |
mbed_official | 87:085cde657901 | 3136 | if(OutputChannel != InputChannel) |
mbed_official | 87:085cde657901 | 3137 | { |
mbed_official | 87:085cde657901 | 3138 | __HAL_LOCK(htim); |
mbed_official | 87:085cde657901 | 3139 | |
mbed_official | 87:085cde657901 | 3140 | htim->State = HAL_TIM_STATE_BUSY; |
mbed_official | 87:085cde657901 | 3141 | |
mbed_official | 87:085cde657901 | 3142 | /* Extract the Ouput compare configuration from sConfig structure */ |
mbed_official | 87:085cde657901 | 3143 | temp1.OCMode = sConfig->OCMode; |
mbed_official | 87:085cde657901 | 3144 | temp1.Pulse = sConfig->Pulse; |
mbed_official | 87:085cde657901 | 3145 | temp1.OCPolarity = sConfig->OCPolarity; |
mbed_official | 87:085cde657901 | 3146 | temp1.OCNPolarity = sConfig->OCNPolarity; |
mbed_official | 87:085cde657901 | 3147 | temp1.OCIdleState = sConfig->OCIdleState; |
mbed_official | 87:085cde657901 | 3148 | temp1.OCNIdleState = sConfig->OCNIdleState; |
mbed_official | 87:085cde657901 | 3149 | |
mbed_official | 87:085cde657901 | 3150 | switch (OutputChannel) |
mbed_official | 87:085cde657901 | 3151 | { |
mbed_official | 87:085cde657901 | 3152 | case TIM_CHANNEL_1: |
mbed_official | 87:085cde657901 | 3153 | { |
mbed_official | 87:085cde657901 | 3154 | assert_param(IS_TIM_CC1_INSTANCE(htim->Instance)); |
mbed_official | 87:085cde657901 | 3155 | |
mbed_official | 87:085cde657901 | 3156 | TIM_OC1_SetConfig(htim->Instance, &temp1); |
mbed_official | 87:085cde657901 | 3157 | } |
mbed_official | 87:085cde657901 | 3158 | break; |
mbed_official | 87:085cde657901 | 3159 | case TIM_CHANNEL_2: |
mbed_official | 87:085cde657901 | 3160 | { |
mbed_official | 87:085cde657901 | 3161 | assert_param(IS_TIM_CC2_INSTANCE(htim->Instance)); |
mbed_official | 87:085cde657901 | 3162 | |
mbed_official | 87:085cde657901 | 3163 | TIM_OC2_SetConfig(htim->Instance, &temp1); |
mbed_official | 87:085cde657901 | 3164 | } |
mbed_official | 87:085cde657901 | 3165 | break; |
mbed_official | 87:085cde657901 | 3166 | default: |
mbed_official | 87:085cde657901 | 3167 | break; |
mbed_official | 87:085cde657901 | 3168 | } |
mbed_official | 87:085cde657901 | 3169 | switch (InputChannel) |
mbed_official | 87:085cde657901 | 3170 | { |
mbed_official | 87:085cde657901 | 3171 | case TIM_CHANNEL_1: |
mbed_official | 87:085cde657901 | 3172 | { |
mbed_official | 87:085cde657901 | 3173 | assert_param(IS_TIM_CC1_INSTANCE(htim->Instance)); |
mbed_official | 87:085cde657901 | 3174 | |
mbed_official | 87:085cde657901 | 3175 | TIM_TI1_SetConfig(htim->Instance, sConfig->ICPolarity, |
mbed_official | 87:085cde657901 | 3176 | sConfig->ICSelection, sConfig->ICFilter); |
mbed_official | 87:085cde657901 | 3177 | |
mbed_official | 87:085cde657901 | 3178 | /* Reset the IC1PSC Bits */ |
mbed_official | 87:085cde657901 | 3179 | htim->Instance->CCMR1 &= ~TIM_CCMR1_IC1PSC; |
mbed_official | 87:085cde657901 | 3180 | |
mbed_official | 87:085cde657901 | 3181 | /* Select the Trigger source */ |
mbed_official | 87:085cde657901 | 3182 | htim->Instance->SMCR &= ~TIM_SMCR_TS; |
mbed_official | 87:085cde657901 | 3183 | htim->Instance->SMCR |= TIM_TS_TI1FP1; |
mbed_official | 87:085cde657901 | 3184 | |
mbed_official | 87:085cde657901 | 3185 | /* Select the Slave Mode */ |
mbed_official | 87:085cde657901 | 3186 | htim->Instance->SMCR &= ~TIM_SMCR_SMS; |
mbed_official | 87:085cde657901 | 3187 | htim->Instance->SMCR |= TIM_SLAVEMODE_TRIGGER; |
mbed_official | 87:085cde657901 | 3188 | } |
mbed_official | 87:085cde657901 | 3189 | break; |
mbed_official | 87:085cde657901 | 3190 | case TIM_CHANNEL_2: |
mbed_official | 87:085cde657901 | 3191 | { |
mbed_official | 87:085cde657901 | 3192 | assert_param(IS_TIM_CC2_INSTANCE(htim->Instance)); |
mbed_official | 87:085cde657901 | 3193 | |
mbed_official | 87:085cde657901 | 3194 | TIM_TI2_SetConfig(htim->Instance, sConfig->ICPolarity, |
mbed_official | 87:085cde657901 | 3195 | sConfig->ICSelection, sConfig->ICFilter); |
mbed_official | 87:085cde657901 | 3196 | |
mbed_official | 87:085cde657901 | 3197 | /* Reset the IC2PSC Bits */ |
mbed_official | 87:085cde657901 | 3198 | htim->Instance->CCMR1 &= ~TIM_CCMR1_IC2PSC; |
mbed_official | 87:085cde657901 | 3199 | |
mbed_official | 87:085cde657901 | 3200 | /* Select the Trigger source */ |
mbed_official | 87:085cde657901 | 3201 | htim->Instance->SMCR &= ~TIM_SMCR_TS; |
mbed_official | 87:085cde657901 | 3202 | htim->Instance->SMCR |= TIM_TS_TI2FP2; |
mbed_official | 87:085cde657901 | 3203 | |
mbed_official | 87:085cde657901 | 3204 | /* Select the Slave Mode */ |
mbed_official | 87:085cde657901 | 3205 | htim->Instance->SMCR &= ~TIM_SMCR_SMS; |
mbed_official | 87:085cde657901 | 3206 | htim->Instance->SMCR |= TIM_SLAVEMODE_TRIGGER; |
mbed_official | 87:085cde657901 | 3207 | } |
mbed_official | 87:085cde657901 | 3208 | break; |
mbed_official | 87:085cde657901 | 3209 | |
mbed_official | 87:085cde657901 | 3210 | default: |
mbed_official | 87:085cde657901 | 3211 | break; |
mbed_official | 87:085cde657901 | 3212 | } |
mbed_official | 87:085cde657901 | 3213 | |
mbed_official | 87:085cde657901 | 3214 | htim->State = HAL_TIM_STATE_READY; |
mbed_official | 87:085cde657901 | 3215 | |
mbed_official | 87:085cde657901 | 3216 | __HAL_UNLOCK(htim); |
mbed_official | 87:085cde657901 | 3217 | |
mbed_official | 87:085cde657901 | 3218 | return HAL_OK; |
mbed_official | 87:085cde657901 | 3219 | } |
mbed_official | 87:085cde657901 | 3220 | else |
mbed_official | 87:085cde657901 | 3221 | { |
mbed_official | 87:085cde657901 | 3222 | return HAL_ERROR; |
mbed_official | 87:085cde657901 | 3223 | } |
mbed_official | 87:085cde657901 | 3224 | } |
mbed_official | 87:085cde657901 | 3225 | |
mbed_official | 87:085cde657901 | 3226 | /** |
mbed_official | 87:085cde657901 | 3227 | * @brief Configure the DMA Burst to transfer Data from the memory to the TIM peripheral |
mbed_official | 87:085cde657901 | 3228 | * @param htim: TIM handle |
mbed_official | 87:085cde657901 | 3229 | * @param BurstBaseAddress: TIM Base address from when the DMA will starts the Data write |
mbed_official | 87:085cde657901 | 3230 | * This parameters can be on of the following values: |
mbed_official | 87:085cde657901 | 3231 | * @arg TIM_DMABase_CR1 |
mbed_official | 87:085cde657901 | 3232 | * @arg TIM_DMABase_CR2 |
mbed_official | 87:085cde657901 | 3233 | * @arg TIM_DMABase_SMCR |
mbed_official | 87:085cde657901 | 3234 | * @arg TIM_DMABase_DIER |
mbed_official | 87:085cde657901 | 3235 | * @arg TIM_DMABase_SR |
mbed_official | 87:085cde657901 | 3236 | * @arg TIM_DMABase_EGR |
mbed_official | 87:085cde657901 | 3237 | * @arg TIM_DMABase_CCMR1 |
mbed_official | 87:085cde657901 | 3238 | * @arg TIM_DMABase_CCMR2 |
mbed_official | 87:085cde657901 | 3239 | * @arg TIM_DMABase_CCER |
mbed_official | 87:085cde657901 | 3240 | * @arg TIM_DMABase_CNT |
mbed_official | 87:085cde657901 | 3241 | * @arg TIM_DMABase_PSC |
mbed_official | 87:085cde657901 | 3242 | * @arg TIM_DMABase_ARR |
mbed_official | 87:085cde657901 | 3243 | * @arg TIM_DMABase_RCR |
mbed_official | 87:085cde657901 | 3244 | * @arg TIM_DMABase_CCR1 |
mbed_official | 87:085cde657901 | 3245 | * @arg TIM_DMABase_CCR2 |
mbed_official | 87:085cde657901 | 3246 | * @arg TIM_DMABase_CCR3 |
mbed_official | 87:085cde657901 | 3247 | * @arg TIM_DMABase_CCR4 |
mbed_official | 87:085cde657901 | 3248 | * @arg TIM_DMABase_BDTR |
mbed_official | 87:085cde657901 | 3249 | * @arg TIM_DMABase_DCR |
mbed_official | 87:085cde657901 | 3250 | * @param BurstRequestSrc: TIM DMA Request sources |
mbed_official | 87:085cde657901 | 3251 | * This parameters can be on of the following values: |
mbed_official | 87:085cde657901 | 3252 | * @arg TIM_DMA_UPDATE: TIM update Interrupt source |
mbed_official | 87:085cde657901 | 3253 | * @arg TIM_DMA_CC1: TIM Capture Compare 1 DMA source |
mbed_official | 87:085cde657901 | 3254 | * @arg TIM_DMA_CC2: TIM Capture Compare 2 DMA source |
mbed_official | 87:085cde657901 | 3255 | * @arg TIM_DMA_CC3: TIM Capture Compare 3 DMA source |
mbed_official | 87:085cde657901 | 3256 | * @arg TIM_DMA_CC4: TIM Capture Compare 4 DMA source |
mbed_official | 87:085cde657901 | 3257 | * @arg TIM_DMA_COM: TIM Commutation DMA source |
mbed_official | 87:085cde657901 | 3258 | * @arg TIM_DMA_TRIGGER: TIM Trigger DMA source |
mbed_official | 87:085cde657901 | 3259 | * @param BurstBuffer: The Buffer address. |
mbed_official | 87:085cde657901 | 3260 | * @param BurstLength: DMA Burst length. This parameter can be one value |
mbed_official | 87:085cde657901 | 3261 | * between: TIM_DMABurstLength_1Transfer and TIM_DMABurstLength_18Transfers. |
mbed_official | 87:085cde657901 | 3262 | * @retval HAL status |
mbed_official | 87:085cde657901 | 3263 | */ |
mbed_official | 87:085cde657901 | 3264 | HAL_StatusTypeDef HAL_TIM_DMABurst_WriteStart(TIM_HandleTypeDef *htim, uint32_t BurstBaseAddress, uint32_t BurstRequestSrc, |
mbed_official | 87:085cde657901 | 3265 | uint32_t* BurstBuffer, uint32_t BurstLength) |
mbed_official | 87:085cde657901 | 3266 | { |
mbed_official | 87:085cde657901 | 3267 | /* Check the parameters */ |
mbed_official | 87:085cde657901 | 3268 | assert_param(IS_TIM_DMABURST_INSTANCE(htim->Instance)); |
mbed_official | 87:085cde657901 | 3269 | assert_param(IS_TIM_DMA_BASE(BurstBaseAddress)); |
mbed_official | 87:085cde657901 | 3270 | assert_param(IS_TIM_DMA_SOURCE(BurstRequestSrc)); |
mbed_official | 87:085cde657901 | 3271 | assert_param(IS_TIM_DMA_LENGTH(BurstLength)); |
mbed_official | 87:085cde657901 | 3272 | |
mbed_official | 87:085cde657901 | 3273 | if((htim->State == HAL_TIM_STATE_BUSY)) |
mbed_official | 87:085cde657901 | 3274 | { |
mbed_official | 87:085cde657901 | 3275 | return HAL_BUSY; |
mbed_official | 87:085cde657901 | 3276 | } |
mbed_official | 87:085cde657901 | 3277 | else if((htim->State == HAL_TIM_STATE_READY)) |
mbed_official | 87:085cde657901 | 3278 | { |
mbed_official | 87:085cde657901 | 3279 | if((BurstBuffer == 0 ) && (BurstLength > 0)) |
mbed_official | 87:085cde657901 | 3280 | { |
mbed_official | 87:085cde657901 | 3281 | return HAL_ERROR; |
mbed_official | 87:085cde657901 | 3282 | } |
mbed_official | 87:085cde657901 | 3283 | else |
mbed_official | 87:085cde657901 | 3284 | { |
mbed_official | 87:085cde657901 | 3285 | htim->State = HAL_TIM_STATE_BUSY; |
mbed_official | 87:085cde657901 | 3286 | } |
mbed_official | 87:085cde657901 | 3287 | } |
mbed_official | 87:085cde657901 | 3288 | switch(BurstRequestSrc) |
mbed_official | 87:085cde657901 | 3289 | { |
mbed_official | 87:085cde657901 | 3290 | case TIM_DMA_UPDATE: |
mbed_official | 87:085cde657901 | 3291 | { |
mbed_official | 87:085cde657901 | 3292 | /* Set the DMA Period elapsed callback */ |
mbed_official | 87:085cde657901 | 3293 | htim->hdma[TIM_DMA_ID_UPDATE]->XferCpltCallback = TIM_DMAPeriodElapsedCplt; |
mbed_official | 87:085cde657901 | 3294 | |
mbed_official | 87:085cde657901 | 3295 | /* Set the DMA error callback */ |
mbed_official | 87:085cde657901 | 3296 | htim->hdma[TIM_DMA_ID_UPDATE]->XferErrorCallback = HAL_TIM_DMAError ; |
mbed_official | 87:085cde657901 | 3297 | |
mbed_official | 87:085cde657901 | 3298 | /* Enable the DMA Stream */ |
mbed_official | 87:085cde657901 | 3299 | HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_UPDATE], (uint32_t)BurstBuffer, (uint32_t)&htim->Instance->DMAR, ((BurstLength) >> 8) + 1); |
mbed_official | 87:085cde657901 | 3300 | } |
mbed_official | 87:085cde657901 | 3301 | break; |
mbed_official | 87:085cde657901 | 3302 | case TIM_DMA_CC1: |
mbed_official | 87:085cde657901 | 3303 | { |
mbed_official | 87:085cde657901 | 3304 | /* Set the DMA Period elapsed callback */ |
mbed_official | 87:085cde657901 | 3305 | htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = HAL_TIM_DMADelayPulseCplt; |
mbed_official | 87:085cde657901 | 3306 | |
mbed_official | 87:085cde657901 | 3307 | /* Set the DMA error callback */ |
mbed_official | 87:085cde657901 | 3308 | htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = HAL_TIM_DMAError ; |
mbed_official | 87:085cde657901 | 3309 | |
mbed_official | 87:085cde657901 | 3310 | /* Enable the DMA Stream */ |
mbed_official | 87:085cde657901 | 3311 | HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)BurstBuffer, (uint32_t)&htim->Instance->DMAR, ((BurstLength) >> 8) + 1); |
mbed_official | 87:085cde657901 | 3312 | } |
mbed_official | 87:085cde657901 | 3313 | break; |
mbed_official | 87:085cde657901 | 3314 | case TIM_DMA_CC2: |
mbed_official | 87:085cde657901 | 3315 | { |
mbed_official | 87:085cde657901 | 3316 | /* Set the DMA Period elapsed callback */ |
mbed_official | 87:085cde657901 | 3317 | htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = HAL_TIM_DMADelayPulseCplt; |
mbed_official | 87:085cde657901 | 3318 | |
mbed_official | 87:085cde657901 | 3319 | /* Set the DMA error callback */ |
mbed_official | 87:085cde657901 | 3320 | htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = HAL_TIM_DMAError ; |
mbed_official | 87:085cde657901 | 3321 | |
mbed_official | 87:085cde657901 | 3322 | /* Enable the DMA Stream */ |
mbed_official | 87:085cde657901 | 3323 | HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)BurstBuffer, (uint32_t)&htim->Instance->DMAR, ((BurstLength) >> 8) + 1); |
mbed_official | 87:085cde657901 | 3324 | } |
mbed_official | 87:085cde657901 | 3325 | break; |
mbed_official | 87:085cde657901 | 3326 | case TIM_DMA_CC3: |
mbed_official | 87:085cde657901 | 3327 | { |
mbed_official | 87:085cde657901 | 3328 | /* Set the DMA Period elapsed callback */ |
mbed_official | 87:085cde657901 | 3329 | htim->hdma[TIM_DMA_ID_CC3]->XferCpltCallback = HAL_TIM_DMADelayPulseCplt; |
mbed_official | 87:085cde657901 | 3330 | |
mbed_official | 87:085cde657901 | 3331 | /* Set the DMA error callback */ |
mbed_official | 87:085cde657901 | 3332 | htim->hdma[TIM_DMA_ID_CC3]->XferErrorCallback = HAL_TIM_DMAError ; |
mbed_official | 87:085cde657901 | 3333 | |
mbed_official | 87:085cde657901 | 3334 | /* Enable the DMA Stream */ |
mbed_official | 87:085cde657901 | 3335 | HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)BurstBuffer, (uint32_t)&htim->Instance->DMAR, ((BurstLength) >> 8) + 1); |
mbed_official | 87:085cde657901 | 3336 | } |
mbed_official | 87:085cde657901 | 3337 | break; |
mbed_official | 87:085cde657901 | 3338 | case TIM_DMA_CC4: |
mbed_official | 87:085cde657901 | 3339 | { |
mbed_official | 87:085cde657901 | 3340 | /* Set the DMA Period elapsed callback */ |
mbed_official | 87:085cde657901 | 3341 | htim->hdma[TIM_DMA_ID_CC4]->XferCpltCallback = HAL_TIM_DMADelayPulseCplt; |
mbed_official | 87:085cde657901 | 3342 | |
mbed_official | 87:085cde657901 | 3343 | /* Set the DMA error callback */ |
mbed_official | 87:085cde657901 | 3344 | htim->hdma[TIM_DMA_ID_CC4]->XferErrorCallback = HAL_TIM_DMAError ; |
mbed_official | 87:085cde657901 | 3345 | |
mbed_official | 87:085cde657901 | 3346 | /* Enable the DMA Stream */ |
mbed_official | 87:085cde657901 | 3347 | HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC4], (uint32_t)BurstBuffer, (uint32_t)&htim->Instance->DMAR, ((BurstLength) >> 8) + 1); |
mbed_official | 87:085cde657901 | 3348 | } |
mbed_official | 87:085cde657901 | 3349 | break; |
mbed_official | 87:085cde657901 | 3350 | case TIM_DMA_COM: |
mbed_official | 87:085cde657901 | 3351 | { |
mbed_official | 87:085cde657901 | 3352 | /* Set the DMA Period elapsed callback */ |
mbed_official | 87:085cde657901 | 3353 | htim->hdma[TIM_DMA_ID_COMMUTATION]->XferCpltCallback = HAL_TIMEx_DMACommutationCplt; |
mbed_official | 87:085cde657901 | 3354 | |
mbed_official | 87:085cde657901 | 3355 | /* Set the DMA error callback */ |
mbed_official | 87:085cde657901 | 3356 | htim->hdma[TIM_DMA_ID_COMMUTATION]->XferErrorCallback = HAL_TIM_DMAError ; |
mbed_official | 87:085cde657901 | 3357 | |
mbed_official | 87:085cde657901 | 3358 | /* Enable the DMA Stream */ |
mbed_official | 87:085cde657901 | 3359 | HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_COMMUTATION], (uint32_t)BurstBuffer, (uint32_t)&htim->Instance->DMAR, ((BurstLength) >> 8) + 1); |
mbed_official | 87:085cde657901 | 3360 | } |
mbed_official | 87:085cde657901 | 3361 | break; |
mbed_official | 87:085cde657901 | 3362 | case TIM_DMA_TRIGGER: |
mbed_official | 87:085cde657901 | 3363 | { |
mbed_official | 87:085cde657901 | 3364 | /* Set the DMA Period elapsed callback */ |
mbed_official | 87:085cde657901 | 3365 | htim->hdma[TIM_DMA_ID_TRIGGER]->XferCpltCallback = TIM_DMATriggerCplt; |
mbed_official | 87:085cde657901 | 3366 | |
mbed_official | 87:085cde657901 | 3367 | /* Set the DMA error callback */ |
mbed_official | 87:085cde657901 | 3368 | htim->hdma[TIM_DMA_ID_TRIGGER]->XferErrorCallback = HAL_TIM_DMAError ; |
mbed_official | 87:085cde657901 | 3369 | |
mbed_official | 87:085cde657901 | 3370 | /* Enable the DMA Stream */ |
mbed_official | 87:085cde657901 | 3371 | HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_TRIGGER], (uint32_t)BurstBuffer, (uint32_t)&htim->Instance->DMAR, ((BurstLength) >> 8) + 1); |
mbed_official | 87:085cde657901 | 3372 | } |
mbed_official | 87:085cde657901 | 3373 | break; |
mbed_official | 87:085cde657901 | 3374 | default: |
mbed_official | 87:085cde657901 | 3375 | break; |
mbed_official | 87:085cde657901 | 3376 | } |
mbed_official | 87:085cde657901 | 3377 | /* configure the DMA Burst Mode */ |
mbed_official | 87:085cde657901 | 3378 | htim->Instance->DCR = BurstBaseAddress | BurstLength; |
mbed_official | 87:085cde657901 | 3379 | |
mbed_official | 87:085cde657901 | 3380 | /* Enable the TIM DMA Request */ |
mbed_official | 87:085cde657901 | 3381 | __HAL_TIM_ENABLE_DMA(htim, BurstRequestSrc); |
mbed_official | 87:085cde657901 | 3382 | |
mbed_official | 87:085cde657901 | 3383 | htim->State = HAL_TIM_STATE_READY; |
mbed_official | 87:085cde657901 | 3384 | |
mbed_official | 87:085cde657901 | 3385 | /* Return function status */ |
mbed_official | 87:085cde657901 | 3386 | return HAL_OK; |
mbed_official | 87:085cde657901 | 3387 | } |
mbed_official | 87:085cde657901 | 3388 | |
mbed_official | 87:085cde657901 | 3389 | /** |
mbed_official | 87:085cde657901 | 3390 | * @brief Stops the TIM DMA Burst mode |
mbed_official | 87:085cde657901 | 3391 | * @param htim: TIM handle |
mbed_official | 87:085cde657901 | 3392 | * @param BurstRequestSrc: TIM DMA Request sources to disable |
mbed_official | 87:085cde657901 | 3393 | * @retval HAL status |
mbed_official | 87:085cde657901 | 3394 | */ |
mbed_official | 87:085cde657901 | 3395 | HAL_StatusTypeDef HAL_TIM_DMABurst_WriteStop(TIM_HandleTypeDef *htim, uint32_t BurstRequestSrc) |
mbed_official | 87:085cde657901 | 3396 | { |
mbed_official | 87:085cde657901 | 3397 | /* Check the parameters */ |
mbed_official | 87:085cde657901 | 3398 | assert_param(IS_TIM_DMA_SOURCE(BurstRequestSrc)); |
mbed_official | 87:085cde657901 | 3399 | |
mbed_official | 87:085cde657901 | 3400 | /* Disable the TIM Update DMA request */ |
mbed_official | 87:085cde657901 | 3401 | __HAL_TIM_DISABLE_DMA(htim, BurstRequestSrc); |
mbed_official | 87:085cde657901 | 3402 | |
mbed_official | 87:085cde657901 | 3403 | /* Return function status */ |
mbed_official | 87:085cde657901 | 3404 | return HAL_OK; |
mbed_official | 87:085cde657901 | 3405 | } |
mbed_official | 87:085cde657901 | 3406 | |
mbed_official | 87:085cde657901 | 3407 | /** |
mbed_official | 87:085cde657901 | 3408 | * @brief Configure the DMA Burst to transfer Data from the TIM peripheral to the memory |
mbed_official | 87:085cde657901 | 3409 | * @param htim: TIM handle |
mbed_official | 87:085cde657901 | 3410 | * @param BurstBaseAddress: TIM Base address from when the DMA will starts the Data read |
mbed_official | 87:085cde657901 | 3411 | * This parameters can be on of the following values: |
mbed_official | 87:085cde657901 | 3412 | * @arg TIM_DMABase_CR1 |
mbed_official | 87:085cde657901 | 3413 | * @arg TIM_DMABase_CR2 |
mbed_official | 87:085cde657901 | 3414 | * @arg TIM_DMABase_SMCR |
mbed_official | 87:085cde657901 | 3415 | * @arg TIM_DMABase_DIER |
mbed_official | 87:085cde657901 | 3416 | * @arg TIM_DMABase_SR |
mbed_official | 87:085cde657901 | 3417 | * @arg TIM_DMABase_EGR |
mbed_official | 87:085cde657901 | 3418 | * @arg TIM_DMABase_CCMR1 |
mbed_official | 87:085cde657901 | 3419 | * @arg TIM_DMABase_CCMR2 |
mbed_official | 87:085cde657901 | 3420 | * @arg TIM_DMABase_CCER |
mbed_official | 87:085cde657901 | 3421 | * @arg TIM_DMABase_CNT |
mbed_official | 87:085cde657901 | 3422 | * @arg TIM_DMABase_PSC |
mbed_official | 87:085cde657901 | 3423 | * @arg TIM_DMABase_ARR |
mbed_official | 87:085cde657901 | 3424 | * @arg TIM_DMABase_RCR |
mbed_official | 87:085cde657901 | 3425 | * @arg TIM_DMABase_CCR1 |
mbed_official | 87:085cde657901 | 3426 | * @arg TIM_DMABase_CCR2 |
mbed_official | 87:085cde657901 | 3427 | * @arg TIM_DMABase_CCR3 |
mbed_official | 87:085cde657901 | 3428 | * @arg TIM_DMABase_CCR4 |
mbed_official | 87:085cde657901 | 3429 | * @arg TIM_DMABase_BDTR |
mbed_official | 87:085cde657901 | 3430 | * @arg TIM_DMABase_DCR |
mbed_official | 87:085cde657901 | 3431 | * @param BurstRequestSrc: TIM DMA Request sources |
mbed_official | 87:085cde657901 | 3432 | * This parameters can be on of the following values: |
mbed_official | 87:085cde657901 | 3433 | * @arg TIM_DMA_UPDATE: TIM update Interrupt source |
mbed_official | 87:085cde657901 | 3434 | * @arg TIM_DMA_CC1: TIM Capture Compare 1 DMA source |
mbed_official | 87:085cde657901 | 3435 | * @arg TIM_DMA_CC2: TIM Capture Compare 2 DMA source |
mbed_official | 87:085cde657901 | 3436 | * @arg TIM_DMA_CC3: TIM Capture Compare 3 DMA source |
mbed_official | 87:085cde657901 | 3437 | * @arg TIM_DMA_CC4: TIM Capture Compare 4 DMA source |
mbed_official | 87:085cde657901 | 3438 | * @arg TIM_DMA_COM: TIM Commutation DMA source |
mbed_official | 87:085cde657901 | 3439 | * @arg TIM_DMA_TRIGGER: TIM Trigger DMA source |
mbed_official | 87:085cde657901 | 3440 | * @param BurstBuffer: The Buffer address. |
mbed_official | 87:085cde657901 | 3441 | * @param BurstLength: DMA Burst length. This parameter can be one value |
mbed_official | 87:085cde657901 | 3442 | * between: TIM_DMABurstLength_1Transfer and TIM_DMABurstLength_18Transfers. |
mbed_official | 87:085cde657901 | 3443 | * @retval HAL status |
mbed_official | 87:085cde657901 | 3444 | */ |
mbed_official | 87:085cde657901 | 3445 | HAL_StatusTypeDef HAL_TIM_DMABurst_ReadStart(TIM_HandleTypeDef *htim, uint32_t BurstBaseAddress, uint32_t BurstRequestSrc, |
mbed_official | 87:085cde657901 | 3446 | uint32_t *BurstBuffer, uint32_t BurstLength) |
mbed_official | 87:085cde657901 | 3447 | { |
mbed_official | 87:085cde657901 | 3448 | /* Check the parameters */ |
mbed_official | 87:085cde657901 | 3449 | assert_param(IS_TIM_DMABURST_INSTANCE(htim->Instance)); |
mbed_official | 87:085cde657901 | 3450 | assert_param(IS_TIM_DMA_BASE(BurstBaseAddress)); |
mbed_official | 87:085cde657901 | 3451 | assert_param(IS_TIM_DMA_SOURCE(BurstRequestSrc)); |
mbed_official | 87:085cde657901 | 3452 | assert_param(IS_TIM_DMA_LENGTH(BurstLength)); |
mbed_official | 87:085cde657901 | 3453 | |
mbed_official | 87:085cde657901 | 3454 | if((htim->State == HAL_TIM_STATE_BUSY)) |
mbed_official | 87:085cde657901 | 3455 | { |
mbed_official | 87:085cde657901 | 3456 | return HAL_BUSY; |
mbed_official | 87:085cde657901 | 3457 | } |
mbed_official | 87:085cde657901 | 3458 | else if((htim->State == HAL_TIM_STATE_READY)) |
mbed_official | 87:085cde657901 | 3459 | { |
mbed_official | 87:085cde657901 | 3460 | if((BurstBuffer == 0 ) && (BurstLength > 0)) |
mbed_official | 87:085cde657901 | 3461 | { |
mbed_official | 87:085cde657901 | 3462 | return HAL_ERROR; |
mbed_official | 87:085cde657901 | 3463 | } |
mbed_official | 87:085cde657901 | 3464 | else |
mbed_official | 87:085cde657901 | 3465 | { |
mbed_official | 87:085cde657901 | 3466 | htim->State = HAL_TIM_STATE_BUSY; |
mbed_official | 87:085cde657901 | 3467 | } |
mbed_official | 87:085cde657901 | 3468 | } |
mbed_official | 87:085cde657901 | 3469 | switch(BurstRequestSrc) |
mbed_official | 87:085cde657901 | 3470 | { |
mbed_official | 87:085cde657901 | 3471 | case TIM_DMA_UPDATE: |
mbed_official | 87:085cde657901 | 3472 | { |
mbed_official | 87:085cde657901 | 3473 | /* Set the DMA Period elapsed callback */ |
mbed_official | 87:085cde657901 | 3474 | htim->hdma[TIM_DMA_ID_UPDATE]->XferCpltCallback = TIM_DMAPeriodElapsedCplt; |
mbed_official | 87:085cde657901 | 3475 | |
mbed_official | 87:085cde657901 | 3476 | /* Set the DMA error callback */ |
mbed_official | 87:085cde657901 | 3477 | htim->hdma[TIM_DMA_ID_UPDATE]->XferErrorCallback = HAL_TIM_DMAError ; |
mbed_official | 87:085cde657901 | 3478 | |
mbed_official | 87:085cde657901 | 3479 | /* Enable the DMA Stream */ |
mbed_official | 87:085cde657901 | 3480 | HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_UPDATE], (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer, ((BurstLength) >> 8) + 1); |
mbed_official | 87:085cde657901 | 3481 | } |
mbed_official | 87:085cde657901 | 3482 | break; |
mbed_official | 87:085cde657901 | 3483 | case TIM_DMA_CC1: |
mbed_official | 87:085cde657901 | 3484 | { |
mbed_official | 87:085cde657901 | 3485 | /* Set the DMA Period elapsed callback */ |
mbed_official | 87:085cde657901 | 3486 | htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = HAL_TIM_DMACaptureCplt; |
mbed_official | 87:085cde657901 | 3487 | |
mbed_official | 87:085cde657901 | 3488 | /* Set the DMA error callback */ |
mbed_official | 87:085cde657901 | 3489 | htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = HAL_TIM_DMAError ; |
mbed_official | 87:085cde657901 | 3490 | |
mbed_official | 87:085cde657901 | 3491 | /* Enable the DMA Stream */ |
mbed_official | 87:085cde657901 | 3492 | HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer, ((BurstLength) >> 8) + 1); |
mbed_official | 87:085cde657901 | 3493 | } |
mbed_official | 87:085cde657901 | 3494 | break; |
mbed_official | 87:085cde657901 | 3495 | case TIM_DMA_CC2: |
mbed_official | 87:085cde657901 | 3496 | { |
mbed_official | 87:085cde657901 | 3497 | /* Set the DMA Period elapsed callback */ |
mbed_official | 87:085cde657901 | 3498 | htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = HAL_TIM_DMACaptureCplt; |
mbed_official | 87:085cde657901 | 3499 | |
mbed_official | 87:085cde657901 | 3500 | /* Set the DMA error callback */ |
mbed_official | 87:085cde657901 | 3501 | htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = HAL_TIM_DMAError ; |
mbed_official | 87:085cde657901 | 3502 | |
mbed_official | 87:085cde657901 | 3503 | /* Enable the DMA Stream */ |
mbed_official | 87:085cde657901 | 3504 | HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer, ((BurstLength) >> 8) + 1); |
mbed_official | 87:085cde657901 | 3505 | } |
mbed_official | 87:085cde657901 | 3506 | break; |
mbed_official | 87:085cde657901 | 3507 | case TIM_DMA_CC3: |
mbed_official | 87:085cde657901 | 3508 | { |
mbed_official | 87:085cde657901 | 3509 | /* Set the DMA Period elapsed callback */ |
mbed_official | 87:085cde657901 | 3510 | htim->hdma[TIM_DMA_ID_CC3]->XferCpltCallback = HAL_TIM_DMACaptureCplt; |
mbed_official | 87:085cde657901 | 3511 | |
mbed_official | 87:085cde657901 | 3512 | /* Set the DMA error callback */ |
mbed_official | 87:085cde657901 | 3513 | htim->hdma[TIM_DMA_ID_CC3]->XferErrorCallback = HAL_TIM_DMAError ; |
mbed_official | 87:085cde657901 | 3514 | |
mbed_official | 87:085cde657901 | 3515 | /* Enable the DMA Stream */ |
mbed_official | 87:085cde657901 | 3516 | HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer, ((BurstLength) >> 8) + 1); |
mbed_official | 87:085cde657901 | 3517 | } |
mbed_official | 87:085cde657901 | 3518 | break; |
mbed_official | 87:085cde657901 | 3519 | case TIM_DMA_CC4: |
mbed_official | 87:085cde657901 | 3520 | { |
mbed_official | 87:085cde657901 | 3521 | /* Set the DMA Period elapsed callback */ |
mbed_official | 87:085cde657901 | 3522 | htim->hdma[TIM_DMA_ID_CC4]->XferCpltCallback = HAL_TIM_DMACaptureCplt; |
mbed_official | 87:085cde657901 | 3523 | |
mbed_official | 87:085cde657901 | 3524 | /* Set the DMA error callback */ |
mbed_official | 87:085cde657901 | 3525 | htim->hdma[TIM_DMA_ID_CC4]->XferErrorCallback = HAL_TIM_DMAError ; |
mbed_official | 87:085cde657901 | 3526 | |
mbed_official | 87:085cde657901 | 3527 | /* Enable the DMA Stream */ |
mbed_official | 87:085cde657901 | 3528 | HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC4], (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer, ((BurstLength) >> 8) + 1); |
mbed_official | 87:085cde657901 | 3529 | } |
mbed_official | 87:085cde657901 | 3530 | break; |
mbed_official | 87:085cde657901 | 3531 | case TIM_DMA_COM: |
mbed_official | 87:085cde657901 | 3532 | { |
mbed_official | 87:085cde657901 | 3533 | /* Set the DMA Period elapsed callback */ |
mbed_official | 87:085cde657901 | 3534 | htim->hdma[TIM_DMA_ID_COMMUTATION]->XferCpltCallback = HAL_TIMEx_DMACommutationCplt; |
mbed_official | 87:085cde657901 | 3535 | |
mbed_official | 87:085cde657901 | 3536 | /* Set the DMA error callback */ |
mbed_official | 87:085cde657901 | 3537 | htim->hdma[TIM_DMA_ID_COMMUTATION]->XferErrorCallback = HAL_TIM_DMAError ; |
mbed_official | 87:085cde657901 | 3538 | |
mbed_official | 87:085cde657901 | 3539 | /* Enable the DMA Stream */ |
mbed_official | 87:085cde657901 | 3540 | HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_COMMUTATION], (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer, ((BurstLength) >> 8) + 1); |
mbed_official | 87:085cde657901 | 3541 | } |
mbed_official | 87:085cde657901 | 3542 | break; |
mbed_official | 87:085cde657901 | 3543 | case TIM_DMA_TRIGGER: |
mbed_official | 87:085cde657901 | 3544 | { |
mbed_official | 87:085cde657901 | 3545 | /* Set the DMA Period elapsed callback */ |
mbed_official | 87:085cde657901 | 3546 | htim->hdma[TIM_DMA_ID_TRIGGER]->XferCpltCallback = TIM_DMATriggerCplt; |
mbed_official | 87:085cde657901 | 3547 | |
mbed_official | 87:085cde657901 | 3548 | /* Set the DMA error callback */ |
mbed_official | 87:085cde657901 | 3549 | htim->hdma[TIM_DMA_ID_TRIGGER]->XferErrorCallback = HAL_TIM_DMAError ; |
mbed_official | 87:085cde657901 | 3550 | |
mbed_official | 87:085cde657901 | 3551 | /* Enable the DMA Stream */ |
mbed_official | 87:085cde657901 | 3552 | HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_TRIGGER], (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer, ((BurstLength) >> 8) + 1); |
mbed_official | 87:085cde657901 | 3553 | } |
mbed_official | 87:085cde657901 | 3554 | break; |
mbed_official | 87:085cde657901 | 3555 | default: |
mbed_official | 87:085cde657901 | 3556 | break; |
mbed_official | 87:085cde657901 | 3557 | } |
mbed_official | 87:085cde657901 | 3558 | |
mbed_official | 87:085cde657901 | 3559 | /* configure the DMA Burst Mode */ |
mbed_official | 87:085cde657901 | 3560 | htim->Instance->DCR = BurstBaseAddress | BurstLength; |
mbed_official | 87:085cde657901 | 3561 | |
mbed_official | 87:085cde657901 | 3562 | /* Enable the TIM DMA Request */ |
mbed_official | 87:085cde657901 | 3563 | __HAL_TIM_ENABLE_DMA(htim, BurstRequestSrc); |
mbed_official | 87:085cde657901 | 3564 | |
mbed_official | 87:085cde657901 | 3565 | htim->State = HAL_TIM_STATE_READY; |
mbed_official | 87:085cde657901 | 3566 | |
mbed_official | 87:085cde657901 | 3567 | /* Return function status */ |
mbed_official | 87:085cde657901 | 3568 | return HAL_OK; |
mbed_official | 87:085cde657901 | 3569 | } |
mbed_official | 87:085cde657901 | 3570 | |
mbed_official | 87:085cde657901 | 3571 | /** |
mbed_official | 87:085cde657901 | 3572 | * @brief Stop the DMA burst reading |
mbed_official | 87:085cde657901 | 3573 | * @param htim: TIM handle |
mbed_official | 87:085cde657901 | 3574 | * @param BurstRequestSrc: TIM DMA Request sources to disable. |
mbed_official | 87:085cde657901 | 3575 | * @retval HAL status |
mbed_official | 87:085cde657901 | 3576 | */ |
mbed_official | 87:085cde657901 | 3577 | HAL_StatusTypeDef HAL_TIM_DMABurst_ReadStop(TIM_HandleTypeDef *htim, uint32_t BurstRequestSrc) |
mbed_official | 87:085cde657901 | 3578 | { |
mbed_official | 87:085cde657901 | 3579 | /* Check the parameters */ |
mbed_official | 87:085cde657901 | 3580 | assert_param(IS_TIM_DMA_SOURCE(BurstRequestSrc)); |
mbed_official | 87:085cde657901 | 3581 | |
mbed_official | 87:085cde657901 | 3582 | /* Disable the TIM Update DMA request */ |
mbed_official | 87:085cde657901 | 3583 | __HAL_TIM_DISABLE_DMA(htim, BurstRequestSrc); |
mbed_official | 87:085cde657901 | 3584 | |
mbed_official | 87:085cde657901 | 3585 | /* Return function status */ |
mbed_official | 87:085cde657901 | 3586 | return HAL_OK; |
mbed_official | 87:085cde657901 | 3587 | } |
mbed_official | 87:085cde657901 | 3588 | |
mbed_official | 87:085cde657901 | 3589 | /** |
mbed_official | 87:085cde657901 | 3590 | * @brief Generate a software event |
mbed_official | 87:085cde657901 | 3591 | * @param htim: TIM handle |
mbed_official | 87:085cde657901 | 3592 | * @param EventSource: specifies the event source. |
mbed_official | 87:085cde657901 | 3593 | * This parameter can be one of the following values: |
mbed_official | 87:085cde657901 | 3594 | * @arg TIM_EventSource_Update: Timer update Event source |
mbed_official | 87:085cde657901 | 3595 | * @arg TIM_EventSource_CC1: Timer Capture Compare 1 Event source |
mbed_official | 87:085cde657901 | 3596 | * @arg TIM_EventSource_CC2: Timer Capture Compare 2 Event source |
mbed_official | 87:085cde657901 | 3597 | * @arg TIM_EventSource_CC3: Timer Capture Compare 3 Event source |
mbed_official | 87:085cde657901 | 3598 | * @arg TIM_EventSource_CC4: Timer Capture Compare 4 Event source |
mbed_official | 87:085cde657901 | 3599 | * @arg TIM_EventSource_COM: Timer COM event source |
mbed_official | 87:085cde657901 | 3600 | * @arg TIM_EventSource_Trigger: Timer Trigger Event source |
mbed_official | 87:085cde657901 | 3601 | * @arg TIM_EventSource_Break: Timer Break event source |
mbed_official | 87:085cde657901 | 3602 | * @note TIM6 and TIM7 can only generate an update event. |
mbed_official | 87:085cde657901 | 3603 | * @note TIM_EventSource_COM and TIM_EventSource_Break are used only with TIM1 and TIM8. |
mbed_official | 87:085cde657901 | 3604 | * @retval HAL status |
mbed_official | 87:085cde657901 | 3605 | */ |
mbed_official | 87:085cde657901 | 3606 | |
mbed_official | 87:085cde657901 | 3607 | HAL_StatusTypeDef HAL_TIM_GenerateEvent(TIM_HandleTypeDef *htim, uint32_t EventSource) |
mbed_official | 87:085cde657901 | 3608 | { |
mbed_official | 87:085cde657901 | 3609 | /* Check the parameters */ |
mbed_official | 87:085cde657901 | 3610 | assert_param(IS_TIM_INSTANCE(htim->Instance)); |
mbed_official | 87:085cde657901 | 3611 | assert_param(IS_TIM_EVENT_SOURCE(EventSource)); |
mbed_official | 87:085cde657901 | 3612 | |
mbed_official | 87:085cde657901 | 3613 | /* Process Locked */ |
mbed_official | 87:085cde657901 | 3614 | __HAL_LOCK(htim); |
mbed_official | 87:085cde657901 | 3615 | |
mbed_official | 87:085cde657901 | 3616 | /* Change the TIM state */ |
mbed_official | 87:085cde657901 | 3617 | htim->State = HAL_TIM_STATE_BUSY; |
mbed_official | 87:085cde657901 | 3618 | |
mbed_official | 87:085cde657901 | 3619 | /* Set the event sources */ |
mbed_official | 87:085cde657901 | 3620 | htim->Instance->EGR = EventSource; |
mbed_official | 87:085cde657901 | 3621 | |
mbed_official | 87:085cde657901 | 3622 | /* Change the TIM state */ |
mbed_official | 87:085cde657901 | 3623 | htim->State = HAL_TIM_STATE_READY; |
mbed_official | 87:085cde657901 | 3624 | |
mbed_official | 87:085cde657901 | 3625 | __HAL_UNLOCK(htim); |
mbed_official | 87:085cde657901 | 3626 | |
mbed_official | 87:085cde657901 | 3627 | /* Return function status */ |
mbed_official | 87:085cde657901 | 3628 | return HAL_OK; |
mbed_official | 87:085cde657901 | 3629 | } |
mbed_official | 87:085cde657901 | 3630 | |
mbed_official | 87:085cde657901 | 3631 | /** |
mbed_official | 87:085cde657901 | 3632 | * @brief Configures the OCRef clear feature |
mbed_official | 87:085cde657901 | 3633 | * @param htim: TIM handle |
mbed_official | 87:085cde657901 | 3634 | * @param sClearInputConfig: pointer to a TIM_ClearInputConfigTypeDef structure that |
mbed_official | 87:085cde657901 | 3635 | * contains the OCREF clear feature and parameters for the TIM peripheral. |
mbed_official | 87:085cde657901 | 3636 | * @param Channel: specifies the TIM Channel |
mbed_official | 87:085cde657901 | 3637 | * This parameter can be one of the following values: |
mbed_official | 87:085cde657901 | 3638 | * @arg TIM_Channel_1: TIM Channel 1 |
mbed_official | 87:085cde657901 | 3639 | * @arg TIM_Channel_2: TIM Channel 2 |
mbed_official | 87:085cde657901 | 3640 | * @arg TIM_Channel_3: TIM Channel 3 |
mbed_official | 87:085cde657901 | 3641 | * @arg TIM_Channel_4: TIM Channel 4 |
mbed_official | 87:085cde657901 | 3642 | * @retval HAL status |
mbed_official | 87:085cde657901 | 3643 | */ |
mbed_official | 87:085cde657901 | 3644 | HAL_StatusTypeDef HAL_TIM_ConfigOCrefClear(TIM_HandleTypeDef *htim, TIM_ClearInputConfigTypeDef * sClearInputConfig, uint32_t Channel) |
mbed_official | 87:085cde657901 | 3645 | { |
mbed_official | 87:085cde657901 | 3646 | /* Check the parameters */ |
mbed_official | 87:085cde657901 | 3647 | assert_param(IS_TIM_CC1_INSTANCE(htim->Instance)); |
mbed_official | 87:085cde657901 | 3648 | assert_param(IS_TIM_CHANNELS(Channel)); |
mbed_official | 87:085cde657901 | 3649 | assert_param(IS_TIM_CLEARINPUT_SOURCE(sClearInputConfig->ClearInputSource)); |
mbed_official | 87:085cde657901 | 3650 | assert_param(IS_TIM_CLEARINPUT_POLARITY(sClearInputConfig->ClearInputPolarity)); |
mbed_official | 87:085cde657901 | 3651 | assert_param(IS_TIM_CLEARINPUT_PRESCALER(sClearInputConfig->ClearInputPrescaler)); |
mbed_official | 87:085cde657901 | 3652 | assert_param(IS_TIM_CLEARINPUT_FILTER(sClearInputConfig->ClearInputFilter)); |
mbed_official | 87:085cde657901 | 3653 | |
mbed_official | 87:085cde657901 | 3654 | /* Process Locked */ |
mbed_official | 87:085cde657901 | 3655 | __HAL_LOCK(htim); |
mbed_official | 87:085cde657901 | 3656 | |
mbed_official | 87:085cde657901 | 3657 | htim->State = HAL_TIM_STATE_BUSY; |
mbed_official | 87:085cde657901 | 3658 | |
mbed_official | 87:085cde657901 | 3659 | if(sClearInputConfig->ClearInputSource == TIM_CLEARINPUTSOURCE_ETR) |
mbed_official | 87:085cde657901 | 3660 | { |
mbed_official | 87:085cde657901 | 3661 | TIM_ETR_SetConfig(htim->Instance, |
mbed_official | 87:085cde657901 | 3662 | sClearInputConfig->ClearInputPrescaler, |
mbed_official | 87:085cde657901 | 3663 | sClearInputConfig->ClearInputPolarity, |
mbed_official | 87:085cde657901 | 3664 | sClearInputConfig->ClearInputFilter); |
mbed_official | 87:085cde657901 | 3665 | } |
mbed_official | 87:085cde657901 | 3666 | |
mbed_official | 87:085cde657901 | 3667 | switch (Channel) |
mbed_official | 87:085cde657901 | 3668 | { |
mbed_official | 87:085cde657901 | 3669 | case TIM_CHANNEL_1: |
mbed_official | 87:085cde657901 | 3670 | { |
mbed_official | 87:085cde657901 | 3671 | if(sClearInputConfig->ClearInputState != RESET) |
mbed_official | 87:085cde657901 | 3672 | { |
mbed_official | 87:085cde657901 | 3673 | /* Enable the Ocref clear feature for Channel 1 */ |
mbed_official | 87:085cde657901 | 3674 | htim->Instance->CCMR1 |= TIM_CCMR1_OC1CE; |
mbed_official | 87:085cde657901 | 3675 | } |
mbed_official | 87:085cde657901 | 3676 | else |
mbed_official | 87:085cde657901 | 3677 | { |
mbed_official | 87:085cde657901 | 3678 | /* Disable the Ocref clear feature for Channel 1 */ |
mbed_official | 87:085cde657901 | 3679 | htim->Instance->CCMR1 &= ~TIM_CCMR1_OC1CE; |
mbed_official | 87:085cde657901 | 3680 | } |
mbed_official | 87:085cde657901 | 3681 | } |
mbed_official | 87:085cde657901 | 3682 | break; |
mbed_official | 87:085cde657901 | 3683 | case TIM_CHANNEL_2: |
mbed_official | 87:085cde657901 | 3684 | { |
mbed_official | 87:085cde657901 | 3685 | assert_param(IS_TIM_CC2_INSTANCE(htim->Instance)); |
mbed_official | 87:085cde657901 | 3686 | if(sClearInputConfig->ClearInputState != RESET) |
mbed_official | 87:085cde657901 | 3687 | { |
mbed_official | 87:085cde657901 | 3688 | /* Enable the Ocref clear feature for Channel 2 */ |
mbed_official | 87:085cde657901 | 3689 | htim->Instance->CCMR1 |= TIM_CCMR1_OC2CE; |
mbed_official | 87:085cde657901 | 3690 | } |
mbed_official | 87:085cde657901 | 3691 | else |
mbed_official | 87:085cde657901 | 3692 | { |
mbed_official | 87:085cde657901 | 3693 | /* Disable the Ocref clear feature for Channel 2 */ |
mbed_official | 87:085cde657901 | 3694 | htim->Instance->CCMR1 &= ~TIM_CCMR1_OC2CE; |
mbed_official | 87:085cde657901 | 3695 | } |
mbed_official | 87:085cde657901 | 3696 | } |
mbed_official | 87:085cde657901 | 3697 | break; |
mbed_official | 87:085cde657901 | 3698 | case TIM_CHANNEL_3: |
mbed_official | 87:085cde657901 | 3699 | { |
mbed_official | 87:085cde657901 | 3700 | assert_param(IS_TIM_CC3_INSTANCE(htim->Instance)); |
mbed_official | 87:085cde657901 | 3701 | if(sClearInputConfig->ClearInputState != RESET) |
mbed_official | 87:085cde657901 | 3702 | { |
mbed_official | 87:085cde657901 | 3703 | /* Enable the Ocref clear feature for Channel 3 */ |
mbed_official | 87:085cde657901 | 3704 | htim->Instance->CCMR2 |= TIM_CCMR2_OC3CE; |
mbed_official | 87:085cde657901 | 3705 | } |
mbed_official | 87:085cde657901 | 3706 | else |
mbed_official | 87:085cde657901 | 3707 | { |
mbed_official | 87:085cde657901 | 3708 | /* Disable the Ocref clear feature for Channel 3 */ |
mbed_official | 87:085cde657901 | 3709 | htim->Instance->CCMR2 &= ~TIM_CCMR2_OC3CE; |
mbed_official | 87:085cde657901 | 3710 | } |
mbed_official | 87:085cde657901 | 3711 | } |
mbed_official | 87:085cde657901 | 3712 | break; |
mbed_official | 87:085cde657901 | 3713 | case TIM_CHANNEL_4: |
mbed_official | 87:085cde657901 | 3714 | { |
mbed_official | 87:085cde657901 | 3715 | assert_param(IS_TIM_CC4_INSTANCE(htim->Instance)); |
mbed_official | 87:085cde657901 | 3716 | if(sClearInputConfig->ClearInputState != RESET) |
mbed_official | 87:085cde657901 | 3717 | { |
mbed_official | 87:085cde657901 | 3718 | /* Enable the Ocref clear feature for Channel 4 */ |
mbed_official | 87:085cde657901 | 3719 | htim->Instance->CCMR2 |= TIM_CCMR2_OC4CE; |
mbed_official | 87:085cde657901 | 3720 | } |
mbed_official | 87:085cde657901 | 3721 | else |
mbed_official | 87:085cde657901 | 3722 | { |
mbed_official | 87:085cde657901 | 3723 | /* Disable the Ocref clear feature for Channel 4 */ |
mbed_official | 87:085cde657901 | 3724 | htim->Instance->CCMR2 &= ~TIM_CCMR2_OC4CE; |
mbed_official | 87:085cde657901 | 3725 | } |
mbed_official | 87:085cde657901 | 3726 | } |
mbed_official | 87:085cde657901 | 3727 | break; |
mbed_official | 87:085cde657901 | 3728 | default: |
mbed_official | 87:085cde657901 | 3729 | break; |
mbed_official | 87:085cde657901 | 3730 | } |
mbed_official | 87:085cde657901 | 3731 | |
mbed_official | 87:085cde657901 | 3732 | htim->State = HAL_TIM_STATE_READY; |
mbed_official | 87:085cde657901 | 3733 | |
mbed_official | 87:085cde657901 | 3734 | __HAL_UNLOCK(htim); |
mbed_official | 87:085cde657901 | 3735 | |
mbed_official | 87:085cde657901 | 3736 | return HAL_OK; |
mbed_official | 87:085cde657901 | 3737 | } |
mbed_official | 87:085cde657901 | 3738 | |
mbed_official | 87:085cde657901 | 3739 | /** |
mbed_official | 87:085cde657901 | 3740 | * @brief Configures the clock source to be used |
mbed_official | 87:085cde657901 | 3741 | * @param htim: TIM handle |
mbed_official | 87:085cde657901 | 3742 | * @param sClockSourceConfig: pointer to a TIM_ClockConfigTypeDef structure that |
mbed_official | 87:085cde657901 | 3743 | * contains the clock source information for the TIM peripheral. |
mbed_official | 87:085cde657901 | 3744 | * @retval HAL status |
mbed_official | 87:085cde657901 | 3745 | */ |
mbed_official | 87:085cde657901 | 3746 | HAL_StatusTypeDef HAL_TIM_ConfigClockSource(TIM_HandleTypeDef *htim, TIM_ClockConfigTypeDef * sClockSourceConfig) |
mbed_official | 87:085cde657901 | 3747 | { |
mbed_official | 87:085cde657901 | 3748 | uint32_t tmpsmcr = 0; |
mbed_official | 87:085cde657901 | 3749 | |
mbed_official | 87:085cde657901 | 3750 | /* Process Locked */ |
mbed_official | 87:085cde657901 | 3751 | __HAL_LOCK(htim); |
mbed_official | 87:085cde657901 | 3752 | |
mbed_official | 87:085cde657901 | 3753 | htim->State = HAL_TIM_STATE_BUSY; |
mbed_official | 87:085cde657901 | 3754 | |
mbed_official | 87:085cde657901 | 3755 | /* Check the parameters */ |
mbed_official | 87:085cde657901 | 3756 | assert_param(IS_TIM_CLOCKSOURCE(sClockSourceConfig->ClockSource)); |
mbed_official | 87:085cde657901 | 3757 | assert_param(IS_TIM_CLOCKPOLARITY(sClockSourceConfig->ClockPolarity)); |
mbed_official | 87:085cde657901 | 3758 | assert_param(IS_TIM_CLOCKPRESCALER(sClockSourceConfig->ClockPrescaler)); |
mbed_official | 87:085cde657901 | 3759 | assert_param(IS_TIM_CLOCKFILTER(sClockSourceConfig->ClockFilter)); |
mbed_official | 87:085cde657901 | 3760 | |
mbed_official | 87:085cde657901 | 3761 | /* Reset the SMS, TS, ECE, ETPS and ETRF bits */ |
mbed_official | 87:085cde657901 | 3762 | tmpsmcr = htim->Instance->SMCR; |
mbed_official | 87:085cde657901 | 3763 | tmpsmcr &= ~(TIM_SMCR_SMS | TIM_SMCR_TS); |
mbed_official | 87:085cde657901 | 3764 | tmpsmcr &= ~(TIM_SMCR_ETF | TIM_SMCR_ETPS | TIM_SMCR_ECE | TIM_SMCR_ETP); |
mbed_official | 87:085cde657901 | 3765 | htim->Instance->SMCR = tmpsmcr; |
mbed_official | 87:085cde657901 | 3766 | |
mbed_official | 87:085cde657901 | 3767 | switch (sClockSourceConfig->ClockSource) |
mbed_official | 87:085cde657901 | 3768 | { |
mbed_official | 87:085cde657901 | 3769 | case TIM_CLOCKSOURCE_INTERNAL: |
mbed_official | 87:085cde657901 | 3770 | { |
mbed_official | 87:085cde657901 | 3771 | assert_param(IS_TIM_INSTANCE(htim->Instance)); |
mbed_official | 87:085cde657901 | 3772 | /* Disable slave mode to clock the prescaler directly with the internal clock */ |
mbed_official | 87:085cde657901 | 3773 | htim->Instance->SMCR &= ~TIM_SMCR_SMS; |
mbed_official | 87:085cde657901 | 3774 | } |
mbed_official | 87:085cde657901 | 3775 | break; |
mbed_official | 87:085cde657901 | 3776 | |
mbed_official | 87:085cde657901 | 3777 | case TIM_CLOCKSOURCE_ETRMODE1: |
mbed_official | 87:085cde657901 | 3778 | { |
mbed_official | 87:085cde657901 | 3779 | assert_param(IS_TIM_ETR_INSTANCE(htim->Instance)); |
mbed_official | 87:085cde657901 | 3780 | /* Configure the ETR Clock source */ |
mbed_official | 87:085cde657901 | 3781 | TIM_ETR_SetConfig(htim->Instance, |
mbed_official | 87:085cde657901 | 3782 | sClockSourceConfig->ClockPrescaler, |
mbed_official | 87:085cde657901 | 3783 | sClockSourceConfig->ClockPolarity, |
mbed_official | 87:085cde657901 | 3784 | sClockSourceConfig->ClockFilter); |
mbed_official | 87:085cde657901 | 3785 | /* Get the TIMx SMCR register value */ |
mbed_official | 87:085cde657901 | 3786 | tmpsmcr = htim->Instance->SMCR; |
mbed_official | 87:085cde657901 | 3787 | /* Reset the SMS and TS Bits */ |
mbed_official | 87:085cde657901 | 3788 | tmpsmcr &= ~(TIM_SMCR_SMS | TIM_SMCR_TS); |
mbed_official | 87:085cde657901 | 3789 | /* Select the External clock mode1 and the ETRF trigger */ |
mbed_official | 87:085cde657901 | 3790 | tmpsmcr |= (TIM_SLAVEMODE_EXTERNAL1 | TIM_CLOCKSOURCE_ETRMODE1); |
mbed_official | 87:085cde657901 | 3791 | /* Write to TIMx SMCR */ |
mbed_official | 87:085cde657901 | 3792 | htim->Instance->SMCR = tmpsmcr; |
mbed_official | 87:085cde657901 | 3793 | } |
mbed_official | 87:085cde657901 | 3794 | break; |
mbed_official | 87:085cde657901 | 3795 | |
mbed_official | 87:085cde657901 | 3796 | case TIM_CLOCKSOURCE_ETRMODE2: |
mbed_official | 87:085cde657901 | 3797 | { |
mbed_official | 87:085cde657901 | 3798 | assert_param(IS_TIM_ETR_INSTANCE(htim->Instance)); |
mbed_official | 87:085cde657901 | 3799 | /* Configure the ETR Clock source */ |
mbed_official | 87:085cde657901 | 3800 | TIM_ETR_SetConfig(htim->Instance, |
mbed_official | 87:085cde657901 | 3801 | sClockSourceConfig->ClockPrescaler, |
mbed_official | 87:085cde657901 | 3802 | sClockSourceConfig->ClockPolarity, |
mbed_official | 87:085cde657901 | 3803 | sClockSourceConfig->ClockFilter); |
mbed_official | 87:085cde657901 | 3804 | /* Enable the External clock mode2 */ |
mbed_official | 87:085cde657901 | 3805 | htim->Instance->SMCR |= TIM_SMCR_ECE; |
mbed_official | 87:085cde657901 | 3806 | } |
mbed_official | 87:085cde657901 | 3807 | break; |
mbed_official | 87:085cde657901 | 3808 | |
mbed_official | 87:085cde657901 | 3809 | case TIM_CLOCKSOURCE_TI1: |
mbed_official | 87:085cde657901 | 3810 | { |
mbed_official | 87:085cde657901 | 3811 | assert_param(IS_TIM_CC1_INSTANCE(htim->Instance)); |
mbed_official | 87:085cde657901 | 3812 | TIM_TI1_ConfigInputStage(htim->Instance, |
mbed_official | 87:085cde657901 | 3813 | sClockSourceConfig->ClockPolarity, |
mbed_official | 87:085cde657901 | 3814 | sClockSourceConfig->ClockFilter); |
mbed_official | 87:085cde657901 | 3815 | TIM_ITRx_SetConfig(htim->Instance, TIM_CLOCKSOURCE_TI1); |
mbed_official | 87:085cde657901 | 3816 | } |
mbed_official | 87:085cde657901 | 3817 | break; |
mbed_official | 87:085cde657901 | 3818 | case TIM_CLOCKSOURCE_TI2: |
mbed_official | 87:085cde657901 | 3819 | { |
mbed_official | 87:085cde657901 | 3820 | assert_param(IS_TIM_CC2_INSTANCE(htim->Instance)); |
mbed_official | 87:085cde657901 | 3821 | TIM_TI2_ConfigInputStage(htim->Instance, |
mbed_official | 87:085cde657901 | 3822 | sClockSourceConfig->ClockPolarity, |
mbed_official | 87:085cde657901 | 3823 | sClockSourceConfig->ClockFilter); |
mbed_official | 87:085cde657901 | 3824 | TIM_ITRx_SetConfig(htim->Instance, TIM_CLOCKSOURCE_TI2); |
mbed_official | 87:085cde657901 | 3825 | } |
mbed_official | 87:085cde657901 | 3826 | break; |
mbed_official | 87:085cde657901 | 3827 | case TIM_CLOCKSOURCE_TI1ED: |
mbed_official | 87:085cde657901 | 3828 | { |
mbed_official | 87:085cde657901 | 3829 | assert_param(IS_TIM_CC1_INSTANCE(htim->Instance)); |
mbed_official | 87:085cde657901 | 3830 | TIM_TI1_ConfigInputStage(htim->Instance, |
mbed_official | 87:085cde657901 | 3831 | sClockSourceConfig->ClockPolarity, |
mbed_official | 87:085cde657901 | 3832 | sClockSourceConfig->ClockFilter); |
mbed_official | 87:085cde657901 | 3833 | TIM_ITRx_SetConfig(htim->Instance, TIM_CLOCKSOURCE_TI1ED); |
mbed_official | 87:085cde657901 | 3834 | } |
mbed_official | 87:085cde657901 | 3835 | break; |
mbed_official | 87:085cde657901 | 3836 | case TIM_CLOCKSOURCE_ITR0: |
mbed_official | 87:085cde657901 | 3837 | { |
mbed_official | 87:085cde657901 | 3838 | assert_param(IS_TIM_CC2_INSTANCE(htim->Instance)); |
mbed_official | 87:085cde657901 | 3839 | TIM_ITRx_SetConfig(htim->Instance, TIM_CLOCKSOURCE_ITR0); |
mbed_official | 87:085cde657901 | 3840 | } |
mbed_official | 87:085cde657901 | 3841 | break; |
mbed_official | 87:085cde657901 | 3842 | case TIM_CLOCKSOURCE_ITR1: |
mbed_official | 87:085cde657901 | 3843 | { |
mbed_official | 87:085cde657901 | 3844 | assert_param(IS_TIM_CC2_INSTANCE(htim->Instance)); |
mbed_official | 87:085cde657901 | 3845 | TIM_ITRx_SetConfig(htim->Instance, TIM_CLOCKSOURCE_ITR1); |
mbed_official | 87:085cde657901 | 3846 | } |
mbed_official | 87:085cde657901 | 3847 | break; |
mbed_official | 87:085cde657901 | 3848 | case TIM_CLOCKSOURCE_ITR2: |
mbed_official | 87:085cde657901 | 3849 | { |
mbed_official | 87:085cde657901 | 3850 | assert_param(IS_TIM_CC2_INSTANCE(htim->Instance)); |
mbed_official | 87:085cde657901 | 3851 | TIM_ITRx_SetConfig(htim->Instance, TIM_CLOCKSOURCE_ITR2); |
mbed_official | 87:085cde657901 | 3852 | } |
mbed_official | 87:085cde657901 | 3853 | break; |
mbed_official | 87:085cde657901 | 3854 | case TIM_CLOCKSOURCE_ITR3: |
mbed_official | 87:085cde657901 | 3855 | { |
mbed_official | 87:085cde657901 | 3856 | assert_param(IS_TIM_CC2_INSTANCE(htim->Instance)); |
mbed_official | 87:085cde657901 | 3857 | TIM_ITRx_SetConfig(htim->Instance, TIM_CLOCKSOURCE_ITR3); |
mbed_official | 87:085cde657901 | 3858 | } |
mbed_official | 87:085cde657901 | 3859 | break; |
mbed_official | 87:085cde657901 | 3860 | |
mbed_official | 87:085cde657901 | 3861 | default: |
mbed_official | 87:085cde657901 | 3862 | break; |
mbed_official | 87:085cde657901 | 3863 | } |
mbed_official | 87:085cde657901 | 3864 | htim->State = HAL_TIM_STATE_READY; |
mbed_official | 87:085cde657901 | 3865 | |
mbed_official | 87:085cde657901 | 3866 | __HAL_UNLOCK(htim); |
mbed_official | 87:085cde657901 | 3867 | |
mbed_official | 87:085cde657901 | 3868 | return HAL_OK; |
mbed_official | 87:085cde657901 | 3869 | } |
mbed_official | 87:085cde657901 | 3870 | |
mbed_official | 87:085cde657901 | 3871 | /** |
mbed_official | 87:085cde657901 | 3872 | * @brief Selects the signal connected to the TI1 input: direct from CH1_input |
mbed_official | 87:085cde657901 | 3873 | * or a XOR combination between CH1_input, CH2_input & CH3_input |
mbed_official | 87:085cde657901 | 3874 | * @param htim: TIM handle. |
mbed_official | 87:085cde657901 | 3875 | * @param TI1_Selection: Indicate whether or not channel 1 is connected to the |
mbed_official | 87:085cde657901 | 3876 | * output of a XOR gate. |
mbed_official | 87:085cde657901 | 3877 | * This parameter can be one of the following values: |
mbed_official | 87:085cde657901 | 3878 | * @arg TIM_TI1SELECTION_CH1: The TIMx_CH1 pin is connected to TI1 input |
mbed_official | 87:085cde657901 | 3879 | * @arg TIM_TI1SELECTION_XORCOMBINATION: The TIMx_CH1, CH2 and CH3 |
mbed_official | 87:085cde657901 | 3880 | * pins are connected to the TI1 input (XOR combination) |
mbed_official | 87:085cde657901 | 3881 | * @retval HAL status |
mbed_official | 87:085cde657901 | 3882 | */ |
mbed_official | 87:085cde657901 | 3883 | HAL_StatusTypeDef HAL_TIM_ConfigTI1Input(TIM_HandleTypeDef *htim, uint32_t TI1_Selection) |
mbed_official | 87:085cde657901 | 3884 | { |
mbed_official | 87:085cde657901 | 3885 | uint32_t tmpcr2 = 0; |
mbed_official | 87:085cde657901 | 3886 | |
mbed_official | 87:085cde657901 | 3887 | /* Check the parameters */ |
mbed_official | 87:085cde657901 | 3888 | assert_param(IS_TIM_XOR_INSTANCE(htim->Instance)); |
mbed_official | 87:085cde657901 | 3889 | assert_param(IS_TIM_TI1SELECTION(TI1_Selection)); |
mbed_official | 87:085cde657901 | 3890 | |
mbed_official | 87:085cde657901 | 3891 | /* Get the TIMx CR2 register value */ |
mbed_official | 87:085cde657901 | 3892 | tmpcr2 = htim->Instance->CR2; |
mbed_official | 87:085cde657901 | 3893 | |
mbed_official | 87:085cde657901 | 3894 | /* Reset the TI1 selection */ |
mbed_official | 87:085cde657901 | 3895 | tmpcr2 &= ~TIM_CR2_TI1S; |
mbed_official | 87:085cde657901 | 3896 | |
mbed_official | 87:085cde657901 | 3897 | /* Set the the TI1 selection */ |
mbed_official | 87:085cde657901 | 3898 | tmpcr2 |= TI1_Selection; |
mbed_official | 87:085cde657901 | 3899 | |
mbed_official | 87:085cde657901 | 3900 | /* Write to TIMxCR2 */ |
mbed_official | 87:085cde657901 | 3901 | htim->Instance->CR2 = tmpcr2; |
mbed_official | 87:085cde657901 | 3902 | |
mbed_official | 87:085cde657901 | 3903 | return HAL_OK; |
mbed_official | 87:085cde657901 | 3904 | } |
mbed_official | 87:085cde657901 | 3905 | |
mbed_official | 87:085cde657901 | 3906 | /** |
mbed_official | 87:085cde657901 | 3907 | * @brief Configures the TIM in Slave mode |
mbed_official | 87:085cde657901 | 3908 | * @param htim: TIM handle. |
mbed_official | 87:085cde657901 | 3909 | * @param sSlaveConfig: pointer to a TIM_SlaveConfigTypeDef structure that |
mbed_official | 87:085cde657901 | 3910 | * contains the selected trigger (internal trigger input, filtered |
mbed_official | 87:085cde657901 | 3911 | * timer input or external trigger input) and the ) and the Slave |
mbed_official | 87:085cde657901 | 3912 | * mode (Disable, Reset, Gated, Trigger, External clock mode 1). |
mbed_official | 87:085cde657901 | 3913 | * @retval HAL status |
mbed_official | 87:085cde657901 | 3914 | */ |
mbed_official | 87:085cde657901 | 3915 | HAL_StatusTypeDef HAL_TIM_SlaveConfigSynchronization(TIM_HandleTypeDef *htim, TIM_SlaveConfigTypeDef * sSlaveConfig) |
mbed_official | 87:085cde657901 | 3916 | { |
mbed_official | 87:085cde657901 | 3917 | uint32_t tmpsmcr = 0; |
mbed_official | 87:085cde657901 | 3918 | uint32_t tmpccmr1 = 0; |
mbed_official | 87:085cde657901 | 3919 | uint32_t tmpccer = 0; |
mbed_official | 87:085cde657901 | 3920 | |
mbed_official | 87:085cde657901 | 3921 | /* Check the parameters */ |
mbed_official | 87:085cde657901 | 3922 | assert_param(IS_TIM_SLAVE_INSTANCE(htim->Instance)); |
mbed_official | 87:085cde657901 | 3923 | assert_param(IS_TIM_SLAVE_MODE(sSlaveConfig->SlaveMode)); |
mbed_official | 87:085cde657901 | 3924 | assert_param(IS_TIM_TRIGGER_SELECTION(sSlaveConfig->InputTrigger)); |
mbed_official | 87:085cde657901 | 3925 | |
mbed_official | 87:085cde657901 | 3926 | __HAL_LOCK(htim); |
mbed_official | 87:085cde657901 | 3927 | |
mbed_official | 87:085cde657901 | 3928 | htim->State = HAL_TIM_STATE_BUSY; |
mbed_official | 87:085cde657901 | 3929 | |
mbed_official | 87:085cde657901 | 3930 | /* Get the TIMx SMCR register value */ |
mbed_official | 87:085cde657901 | 3931 | tmpsmcr = htim->Instance->SMCR; |
mbed_official | 87:085cde657901 | 3932 | |
mbed_official | 87:085cde657901 | 3933 | /* Reset the Trigger Selection Bits */ |
mbed_official | 87:085cde657901 | 3934 | tmpsmcr &= ~TIM_SMCR_TS; |
mbed_official | 87:085cde657901 | 3935 | /* Set the Input Trigger source */ |
mbed_official | 87:085cde657901 | 3936 | tmpsmcr |= sSlaveConfig->InputTrigger; |
mbed_official | 87:085cde657901 | 3937 | |
mbed_official | 87:085cde657901 | 3938 | /* Reset the slave mode Bits */ |
mbed_official | 87:085cde657901 | 3939 | tmpsmcr &= ~TIM_SMCR_SMS; |
mbed_official | 87:085cde657901 | 3940 | /* Set the slave mode */ |
mbed_official | 87:085cde657901 | 3941 | tmpsmcr |= sSlaveConfig->SlaveMode; |
mbed_official | 87:085cde657901 | 3942 | |
mbed_official | 87:085cde657901 | 3943 | /* Write to TIMx SMCR */ |
mbed_official | 87:085cde657901 | 3944 | htim->Instance->SMCR = tmpsmcr; |
mbed_official | 87:085cde657901 | 3945 | |
mbed_official | 87:085cde657901 | 3946 | /* Configure the trigger prescaler, filter, and polarity */ |
mbed_official | 87:085cde657901 | 3947 | switch (sSlaveConfig->InputTrigger) |
mbed_official | 87:085cde657901 | 3948 | { |
mbed_official | 87:085cde657901 | 3949 | case TIM_TS_ETRF: |
mbed_official | 87:085cde657901 | 3950 | { |
mbed_official | 87:085cde657901 | 3951 | /* Check the parameters */ |
mbed_official | 87:085cde657901 | 3952 | assert_param(IS_TIM_ETR_INSTANCE(htim->Instance)); |
mbed_official | 87:085cde657901 | 3953 | assert_param(IS_TIM_TRIGGERPRESCALER(sSlaveConfig->TriggerPrescaler)); |
mbed_official | 87:085cde657901 | 3954 | assert_param(IS_TIM_TRIGGERPOLARITY(sSlaveConfig->TriggerPolarity)); |
mbed_official | 87:085cde657901 | 3955 | assert_param(IS_TIM_TRIGGERFILTER(sSlaveConfig->TriggerFilter)); |
mbed_official | 87:085cde657901 | 3956 | /* Configure the ETR Trigger source */ |
mbed_official | 87:085cde657901 | 3957 | TIM_ETR_SetConfig(htim->Instance, |
mbed_official | 87:085cde657901 | 3958 | sSlaveConfig->TriggerPrescaler, |
mbed_official | 87:085cde657901 | 3959 | sSlaveConfig->TriggerPolarity, |
mbed_official | 87:085cde657901 | 3960 | sSlaveConfig->TriggerFilter); |
mbed_official | 87:085cde657901 | 3961 | } |
mbed_official | 87:085cde657901 | 3962 | break; |
mbed_official | 87:085cde657901 | 3963 | |
mbed_official | 87:085cde657901 | 3964 | case TIM_TS_TI1F_ED: |
mbed_official | 87:085cde657901 | 3965 | { |
mbed_official | 87:085cde657901 | 3966 | /* Check the parameters */ |
mbed_official | 87:085cde657901 | 3967 | assert_param(IS_TIM_CC1_INSTANCE(htim->Instance)); |
mbed_official | 87:085cde657901 | 3968 | assert_param(IS_TIM_TRIGGERFILTER(sSlaveConfig->TriggerFilter)); |
mbed_official | 87:085cde657901 | 3969 | |
mbed_official | 87:085cde657901 | 3970 | /* Disable the Channel 1: Reset the CC1E Bit */ |
mbed_official | 87:085cde657901 | 3971 | tmpccer = htim->Instance->CCER; |
mbed_official | 87:085cde657901 | 3972 | htim->Instance->CCER &= ~TIM_CCER_CC1E; |
mbed_official | 87:085cde657901 | 3973 | tmpccmr1 = htim->Instance->CCMR1; |
mbed_official | 87:085cde657901 | 3974 | |
mbed_official | 87:085cde657901 | 3975 | /* Set the filter */ |
mbed_official | 87:085cde657901 | 3976 | tmpccmr1 &= ~TIM_CCMR1_IC1F; |
mbed_official | 87:085cde657901 | 3977 | tmpccmr1 |= ((sSlaveConfig->TriggerFilter) << 4); |
mbed_official | 87:085cde657901 | 3978 | |
mbed_official | 87:085cde657901 | 3979 | /* Write to TIMx CCMR1 and CCER registers */ |
mbed_official | 87:085cde657901 | 3980 | htim->Instance->CCMR1 = tmpccmr1; |
mbed_official | 87:085cde657901 | 3981 | htim->Instance->CCER = tmpccer; |
mbed_official | 87:085cde657901 | 3982 | |
mbed_official | 87:085cde657901 | 3983 | } |
mbed_official | 87:085cde657901 | 3984 | break; |
mbed_official | 87:085cde657901 | 3985 | |
mbed_official | 87:085cde657901 | 3986 | case TIM_TS_TI1FP1: |
mbed_official | 87:085cde657901 | 3987 | { |
mbed_official | 87:085cde657901 | 3988 | /* Check the parameters */ |
mbed_official | 87:085cde657901 | 3989 | assert_param(IS_TIM_CC1_INSTANCE(htim->Instance)); |
mbed_official | 87:085cde657901 | 3990 | assert_param(IS_TIM_TRIGGERPOLARITY(sSlaveConfig->TriggerPolarity)); |
mbed_official | 87:085cde657901 | 3991 | assert_param(IS_TIM_TRIGGERFILTER(sSlaveConfig->TriggerFilter)); |
mbed_official | 87:085cde657901 | 3992 | |
mbed_official | 87:085cde657901 | 3993 | /* Configure TI1 Filter and Polarity */ |
mbed_official | 87:085cde657901 | 3994 | TIM_TI1_ConfigInputStage(htim->Instance, |
mbed_official | 87:085cde657901 | 3995 | sSlaveConfig->TriggerPolarity, |
mbed_official | 87:085cde657901 | 3996 | sSlaveConfig->TriggerFilter); |
mbed_official | 87:085cde657901 | 3997 | } |
mbed_official | 87:085cde657901 | 3998 | break; |
mbed_official | 87:085cde657901 | 3999 | |
mbed_official | 87:085cde657901 | 4000 | case TIM_TS_TI2FP2: |
mbed_official | 87:085cde657901 | 4001 | { |
mbed_official | 87:085cde657901 | 4002 | /* Check the parameters */ |
mbed_official | 87:085cde657901 | 4003 | assert_param(IS_TIM_CC2_INSTANCE(htim->Instance)); |
mbed_official | 87:085cde657901 | 4004 | assert_param(IS_TIM_TRIGGERPOLARITY(sSlaveConfig->TriggerPolarity)); |
mbed_official | 87:085cde657901 | 4005 | assert_param(IS_TIM_TRIGGERFILTER(sSlaveConfig->TriggerFilter)); |
mbed_official | 87:085cde657901 | 4006 | |
mbed_official | 87:085cde657901 | 4007 | /* Configure TI2 Filter and Polarity */ |
mbed_official | 87:085cde657901 | 4008 | TIM_TI2_ConfigInputStage(htim->Instance, |
mbed_official | 87:085cde657901 | 4009 | sSlaveConfig->TriggerPolarity, |
mbed_official | 87:085cde657901 | 4010 | sSlaveConfig->TriggerFilter); |
mbed_official | 87:085cde657901 | 4011 | } |
mbed_official | 87:085cde657901 | 4012 | break; |
mbed_official | 87:085cde657901 | 4013 | |
mbed_official | 87:085cde657901 | 4014 | case TIM_TS_ITR0: |
mbed_official | 87:085cde657901 | 4015 | { |
mbed_official | 87:085cde657901 | 4016 | /* Check the parameter */ |
mbed_official | 87:085cde657901 | 4017 | assert_param(IS_TIM_CC2_INSTANCE(htim->Instance)); |
mbed_official | 87:085cde657901 | 4018 | } |
mbed_official | 87:085cde657901 | 4019 | break; |
mbed_official | 87:085cde657901 | 4020 | |
mbed_official | 87:085cde657901 | 4021 | case TIM_TS_ITR1: |
mbed_official | 87:085cde657901 | 4022 | { |
mbed_official | 87:085cde657901 | 4023 | /* Check the parameter */ |
mbed_official | 87:085cde657901 | 4024 | assert_param(IS_TIM_CC2_INSTANCE(htim->Instance)); |
mbed_official | 87:085cde657901 | 4025 | } |
mbed_official | 87:085cde657901 | 4026 | break; |
mbed_official | 87:085cde657901 | 4027 | |
mbed_official | 87:085cde657901 | 4028 | case TIM_TS_ITR2: |
mbed_official | 87:085cde657901 | 4029 | { |
mbed_official | 87:085cde657901 | 4030 | /* Check the parameter */ |
mbed_official | 87:085cde657901 | 4031 | assert_param(IS_TIM_CC2_INSTANCE(htim->Instance)); |
mbed_official | 87:085cde657901 | 4032 | } |
mbed_official | 87:085cde657901 | 4033 | break; |
mbed_official | 87:085cde657901 | 4034 | |
mbed_official | 87:085cde657901 | 4035 | case TIM_TS_ITR3: |
mbed_official | 87:085cde657901 | 4036 | { |
mbed_official | 87:085cde657901 | 4037 | /* Check the parameter */ |
mbed_official | 87:085cde657901 | 4038 | assert_param(IS_TIM_CC2_INSTANCE(htim->Instance)); |
mbed_official | 87:085cde657901 | 4039 | } |
mbed_official | 87:085cde657901 | 4040 | break; |
mbed_official | 87:085cde657901 | 4041 | |
mbed_official | 87:085cde657901 | 4042 | default: |
mbed_official | 87:085cde657901 | 4043 | break; |
mbed_official | 87:085cde657901 | 4044 | } |
mbed_official | 87:085cde657901 | 4045 | |
mbed_official | 87:085cde657901 | 4046 | htim->State = HAL_TIM_STATE_READY; |
mbed_official | 87:085cde657901 | 4047 | |
mbed_official | 87:085cde657901 | 4048 | __HAL_UNLOCK(htim); |
mbed_official | 87:085cde657901 | 4049 | |
mbed_official | 87:085cde657901 | 4050 | return HAL_OK; |
mbed_official | 87:085cde657901 | 4051 | } |
mbed_official | 87:085cde657901 | 4052 | |
mbed_official | 87:085cde657901 | 4053 | /** |
mbed_official | 87:085cde657901 | 4054 | * @brief Read the captured value from Capture Compare unit |
mbed_official | 87:085cde657901 | 4055 | * @param htim: TIM handle. |
mbed_official | 87:085cde657901 | 4056 | * @param Channel : TIM Channels to be enabled |
mbed_official | 87:085cde657901 | 4057 | * This parameter can be one of the following values: |
mbed_official | 87:085cde657901 | 4058 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
mbed_official | 87:085cde657901 | 4059 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
mbed_official | 87:085cde657901 | 4060 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
mbed_official | 87:085cde657901 | 4061 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
mbed_official | 87:085cde657901 | 4062 | * @retval Captured value |
mbed_official | 87:085cde657901 | 4063 | */ |
mbed_official | 87:085cde657901 | 4064 | uint32_t HAL_TIM_ReadCapturedValue(TIM_HandleTypeDef *htim, uint32_t Channel) |
mbed_official | 87:085cde657901 | 4065 | { |
mbed_official | 87:085cde657901 | 4066 | uint32_t tmpreg = 0; |
mbed_official | 87:085cde657901 | 4067 | |
mbed_official | 87:085cde657901 | 4068 | __HAL_LOCK(htim); |
mbed_official | 87:085cde657901 | 4069 | |
mbed_official | 87:085cde657901 | 4070 | switch (Channel) |
mbed_official | 87:085cde657901 | 4071 | { |
mbed_official | 87:085cde657901 | 4072 | case TIM_CHANNEL_1: |
mbed_official | 87:085cde657901 | 4073 | { |
mbed_official | 87:085cde657901 | 4074 | /* Check the parameters */ |
mbed_official | 87:085cde657901 | 4075 | assert_param(IS_TIM_CC1_INSTANCE(htim->Instance)); |
mbed_official | 87:085cde657901 | 4076 | |
mbed_official | 87:085cde657901 | 4077 | /* Return the capture 1 value */ |
mbed_official | 87:085cde657901 | 4078 | tmpreg = htim->Instance->CCR1; |
mbed_official | 87:085cde657901 | 4079 | |
mbed_official | 87:085cde657901 | 4080 | break; |
mbed_official | 87:085cde657901 | 4081 | } |
mbed_official | 87:085cde657901 | 4082 | case TIM_CHANNEL_2: |
mbed_official | 87:085cde657901 | 4083 | { |
mbed_official | 87:085cde657901 | 4084 | /* Check the parameters */ |
mbed_official | 87:085cde657901 | 4085 | assert_param(IS_TIM_CC2_INSTANCE(htim->Instance)); |
mbed_official | 87:085cde657901 | 4086 | |
mbed_official | 87:085cde657901 | 4087 | /* Return the capture 2 value */ |
mbed_official | 87:085cde657901 | 4088 | tmpreg = htim->Instance->CCR2; |
mbed_official | 87:085cde657901 | 4089 | |
mbed_official | 87:085cde657901 | 4090 | break; |
mbed_official | 87:085cde657901 | 4091 | } |
mbed_official | 87:085cde657901 | 4092 | |
mbed_official | 87:085cde657901 | 4093 | case TIM_CHANNEL_3: |
mbed_official | 87:085cde657901 | 4094 | { |
mbed_official | 87:085cde657901 | 4095 | /* Check the parameters */ |
mbed_official | 87:085cde657901 | 4096 | assert_param(IS_TIM_CC3_INSTANCE(htim->Instance)); |
mbed_official | 87:085cde657901 | 4097 | |
mbed_official | 87:085cde657901 | 4098 | /* Return the capture 3 value */ |
mbed_official | 87:085cde657901 | 4099 | tmpreg = htim->Instance->CCR3; |
mbed_official | 87:085cde657901 | 4100 | |
mbed_official | 87:085cde657901 | 4101 | break; |
mbed_official | 87:085cde657901 | 4102 | } |
mbed_official | 87:085cde657901 | 4103 | |
mbed_official | 87:085cde657901 | 4104 | case TIM_CHANNEL_4: |
mbed_official | 87:085cde657901 | 4105 | { |
mbed_official | 87:085cde657901 | 4106 | /* Check the parameters */ |
mbed_official | 87:085cde657901 | 4107 | assert_param(IS_TIM_CC4_INSTANCE(htim->Instance)); |
mbed_official | 87:085cde657901 | 4108 | |
mbed_official | 87:085cde657901 | 4109 | /* Return the capture 4 value */ |
mbed_official | 87:085cde657901 | 4110 | tmpreg = htim->Instance->CCR4; |
mbed_official | 87:085cde657901 | 4111 | |
mbed_official | 87:085cde657901 | 4112 | break; |
mbed_official | 87:085cde657901 | 4113 | } |
mbed_official | 87:085cde657901 | 4114 | |
mbed_official | 87:085cde657901 | 4115 | default: |
mbed_official | 87:085cde657901 | 4116 | break; |
mbed_official | 87:085cde657901 | 4117 | } |
mbed_official | 87:085cde657901 | 4118 | |
mbed_official | 87:085cde657901 | 4119 | __HAL_UNLOCK(htim); |
mbed_official | 87:085cde657901 | 4120 | return tmpreg; |
mbed_official | 87:085cde657901 | 4121 | } |
mbed_official | 87:085cde657901 | 4122 | |
mbed_official | 87:085cde657901 | 4123 | /** |
mbed_official | 87:085cde657901 | 4124 | * @} |
mbed_official | 87:085cde657901 | 4125 | */ |
mbed_official | 87:085cde657901 | 4126 | |
mbed_official | 87:085cde657901 | 4127 | /** @defgroup TIM_Group9 TIM Callbacks functions |
mbed_official | 87:085cde657901 | 4128 | * @brief TIM Callbacks functions |
mbed_official | 87:085cde657901 | 4129 | * |
mbed_official | 87:085cde657901 | 4130 | @verbatim |
mbed_official | 87:085cde657901 | 4131 | ============================================================================== |
mbed_official | 87:085cde657901 | 4132 | ##### TIM Callbacks functions ##### |
mbed_official | 87:085cde657901 | 4133 | ============================================================================== |
mbed_official | 87:085cde657901 | 4134 | [..] |
mbed_official | 87:085cde657901 | 4135 | This section provides TIM callback functions: |
mbed_official | 87:085cde657901 | 4136 | (+) Timer Period elapsed callback |
mbed_official | 87:085cde657901 | 4137 | (+) Timer Output Compare callback |
mbed_official | 87:085cde657901 | 4138 | (+) Timer Input capture callback |
mbed_official | 87:085cde657901 | 4139 | (+) Timer Trigger callback |
mbed_official | 87:085cde657901 | 4140 | (+) Timer Error callback |
mbed_official | 87:085cde657901 | 4141 | |
mbed_official | 87:085cde657901 | 4142 | @endverbatim |
mbed_official | 87:085cde657901 | 4143 | * @{ |
mbed_official | 87:085cde657901 | 4144 | */ |
mbed_official | 87:085cde657901 | 4145 | |
mbed_official | 87:085cde657901 | 4146 | /** |
mbed_official | 87:085cde657901 | 4147 | * @brief Period elapsed callback in non blocking mode |
mbed_official | 87:085cde657901 | 4148 | * @param htim : TIM handle |
mbed_official | 87:085cde657901 | 4149 | * @retval None |
mbed_official | 87:085cde657901 | 4150 | */ |
mbed_official | 87:085cde657901 | 4151 | __weak void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) |
mbed_official | 87:085cde657901 | 4152 | { |
mbed_official | 87:085cde657901 | 4153 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 87:085cde657901 | 4154 | the __HAL_TIM_PeriodElapsedCallback could be implemented in the user file |
mbed_official | 87:085cde657901 | 4155 | */ |
mbed_official | 87:085cde657901 | 4156 | |
mbed_official | 87:085cde657901 | 4157 | } |
mbed_official | 87:085cde657901 | 4158 | /** |
mbed_official | 87:085cde657901 | 4159 | * @brief Output Compare callback in non blocking mode |
mbed_official | 87:085cde657901 | 4160 | * @param htim : TIM OC handle |
mbed_official | 87:085cde657901 | 4161 | * @retval None |
mbed_official | 87:085cde657901 | 4162 | */ |
mbed_official | 87:085cde657901 | 4163 | __weak void HAL_TIM_OC_DelayElapsedCallback(TIM_HandleTypeDef *htim) |
mbed_official | 87:085cde657901 | 4164 | { |
mbed_official | 87:085cde657901 | 4165 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 87:085cde657901 | 4166 | the __HAL_TIM_OC_DelayElapsedCallback could be implemented in the user file |
mbed_official | 87:085cde657901 | 4167 | */ |
mbed_official | 87:085cde657901 | 4168 | } |
mbed_official | 87:085cde657901 | 4169 | /** |
mbed_official | 87:085cde657901 | 4170 | * @brief Input Capture callback in non blocking mode |
mbed_official | 87:085cde657901 | 4171 | * @param htim : TIM IC handle |
mbed_official | 87:085cde657901 | 4172 | * @retval None |
mbed_official | 87:085cde657901 | 4173 | */ |
mbed_official | 87:085cde657901 | 4174 | __weak void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim) |
mbed_official | 87:085cde657901 | 4175 | { |
mbed_official | 87:085cde657901 | 4176 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 87:085cde657901 | 4177 | the __HAL_TIM_IC_CaptureCallback could be implemented in the user file |
mbed_official | 87:085cde657901 | 4178 | */ |
mbed_official | 87:085cde657901 | 4179 | } |
mbed_official | 87:085cde657901 | 4180 | |
mbed_official | 87:085cde657901 | 4181 | /** |
mbed_official | 87:085cde657901 | 4182 | * @brief PWM Pulse finished callback in non blocking mode |
mbed_official | 87:085cde657901 | 4183 | * @param htim : TIM handle |
mbed_official | 87:085cde657901 | 4184 | * @retval None |
mbed_official | 87:085cde657901 | 4185 | */ |
mbed_official | 87:085cde657901 | 4186 | __weak void HAL_TIM_PWM_PulseFinishedCallback(TIM_HandleTypeDef *htim) |
mbed_official | 87:085cde657901 | 4187 | { |
mbed_official | 87:085cde657901 | 4188 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 87:085cde657901 | 4189 | the __HAL_TIM_PWM_PulseFinishedCallback could be implemented in the user file |
mbed_official | 87:085cde657901 | 4190 | */ |
mbed_official | 87:085cde657901 | 4191 | } |
mbed_official | 87:085cde657901 | 4192 | |
mbed_official | 87:085cde657901 | 4193 | /** |
mbed_official | 87:085cde657901 | 4194 | * @brief Hall Trigger detection callback in non blocking mode |
mbed_official | 87:085cde657901 | 4195 | * @param htim : TIM handle |
mbed_official | 87:085cde657901 | 4196 | * @retval None |
mbed_official | 87:085cde657901 | 4197 | */ |
mbed_official | 87:085cde657901 | 4198 | __weak void HAL_TIM_TriggerCallback(TIM_HandleTypeDef *htim) |
mbed_official | 87:085cde657901 | 4199 | { |
mbed_official | 87:085cde657901 | 4200 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 87:085cde657901 | 4201 | the HAL_TIM_TriggerCallback could be implemented in the user file |
mbed_official | 87:085cde657901 | 4202 | */ |
mbed_official | 87:085cde657901 | 4203 | } |
mbed_official | 87:085cde657901 | 4204 | |
mbed_official | 87:085cde657901 | 4205 | /** |
mbed_official | 87:085cde657901 | 4206 | * @brief Timer error callback in non blocking mode |
mbed_official | 87:085cde657901 | 4207 | * @param htim : TIM handle |
mbed_official | 87:085cde657901 | 4208 | * @retval None |
mbed_official | 87:085cde657901 | 4209 | */ |
mbed_official | 87:085cde657901 | 4210 | __weak void HAL_TIM_ErrorCallback(TIM_HandleTypeDef *htim) |
mbed_official | 87:085cde657901 | 4211 | { |
mbed_official | 87:085cde657901 | 4212 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 87:085cde657901 | 4213 | the HAL_TIM_ErrorCallback could be implemented in the user file |
mbed_official | 87:085cde657901 | 4214 | */ |
mbed_official | 87:085cde657901 | 4215 | } |
mbed_official | 87:085cde657901 | 4216 | |
mbed_official | 87:085cde657901 | 4217 | /** |
mbed_official | 87:085cde657901 | 4218 | * @} |
mbed_official | 87:085cde657901 | 4219 | */ |
mbed_official | 87:085cde657901 | 4220 | |
mbed_official | 87:085cde657901 | 4221 | /** @defgroup TIM_Group10 Peripheral State functions |
mbed_official | 87:085cde657901 | 4222 | * @brief Peripheral State functions |
mbed_official | 87:085cde657901 | 4223 | * |
mbed_official | 87:085cde657901 | 4224 | @verbatim |
mbed_official | 87:085cde657901 | 4225 | ============================================================================== |
mbed_official | 87:085cde657901 | 4226 | ##### Peripheral State functions ##### |
mbed_official | 87:085cde657901 | 4227 | ============================================================================== |
mbed_official | 87:085cde657901 | 4228 | [..] |
mbed_official | 87:085cde657901 | 4229 | This subsection permit to get in run-time the status of the peripheral |
mbed_official | 87:085cde657901 | 4230 | and the data flow. |
mbed_official | 87:085cde657901 | 4231 | |
mbed_official | 87:085cde657901 | 4232 | @endverbatim |
mbed_official | 87:085cde657901 | 4233 | * @{ |
mbed_official | 87:085cde657901 | 4234 | */ |
mbed_official | 87:085cde657901 | 4235 | |
mbed_official | 87:085cde657901 | 4236 | /** |
mbed_official | 87:085cde657901 | 4237 | * @brief Return the TIM Base state |
mbed_official | 87:085cde657901 | 4238 | * @param htim: TIM Base handle |
mbed_official | 87:085cde657901 | 4239 | * @retval HAL state |
mbed_official | 87:085cde657901 | 4240 | */ |
mbed_official | 87:085cde657901 | 4241 | HAL_TIM_StateTypeDef HAL_TIM_Base_GetState(TIM_HandleTypeDef *htim) |
mbed_official | 87:085cde657901 | 4242 | { |
mbed_official | 87:085cde657901 | 4243 | return htim->State; |
mbed_official | 87:085cde657901 | 4244 | } |
mbed_official | 87:085cde657901 | 4245 | |
mbed_official | 87:085cde657901 | 4246 | /** |
mbed_official | 87:085cde657901 | 4247 | * @brief Return the TIM OC state |
mbed_official | 87:085cde657901 | 4248 | * @param htim: TIM Ouput Compare handle |
mbed_official | 87:085cde657901 | 4249 | * @retval HAL state |
mbed_official | 87:085cde657901 | 4250 | */ |
mbed_official | 87:085cde657901 | 4251 | HAL_TIM_StateTypeDef HAL_TIM_OC_GetState(TIM_HandleTypeDef *htim) |
mbed_official | 87:085cde657901 | 4252 | { |
mbed_official | 87:085cde657901 | 4253 | return htim->State; |
mbed_official | 87:085cde657901 | 4254 | } |
mbed_official | 87:085cde657901 | 4255 | |
mbed_official | 87:085cde657901 | 4256 | /** |
mbed_official | 87:085cde657901 | 4257 | * @brief Return the TIM PWM state |
mbed_official | 87:085cde657901 | 4258 | * @param htim: TIM handle |
mbed_official | 87:085cde657901 | 4259 | * @retval HAL state |
mbed_official | 87:085cde657901 | 4260 | */ |
mbed_official | 87:085cde657901 | 4261 | HAL_TIM_StateTypeDef HAL_TIM_PWM_GetState(TIM_HandleTypeDef *htim) |
mbed_official | 87:085cde657901 | 4262 | { |
mbed_official | 87:085cde657901 | 4263 | return htim->State; |
mbed_official | 87:085cde657901 | 4264 | } |
mbed_official | 87:085cde657901 | 4265 | |
mbed_official | 87:085cde657901 | 4266 | /** |
mbed_official | 87:085cde657901 | 4267 | * @brief Return the TIM Input Capture state |
mbed_official | 87:085cde657901 | 4268 | * @param htim: TIM IC handle |
mbed_official | 87:085cde657901 | 4269 | * @retval HAL state |
mbed_official | 87:085cde657901 | 4270 | */ |
mbed_official | 87:085cde657901 | 4271 | HAL_TIM_StateTypeDef HAL_TIM_IC_GetState(TIM_HandleTypeDef *htim) |
mbed_official | 87:085cde657901 | 4272 | { |
mbed_official | 87:085cde657901 | 4273 | return htim->State; |
mbed_official | 87:085cde657901 | 4274 | } |
mbed_official | 87:085cde657901 | 4275 | |
mbed_official | 87:085cde657901 | 4276 | /** |
mbed_official | 87:085cde657901 | 4277 | * @brief Return the TIM One Pulse Mode state |
mbed_official | 87:085cde657901 | 4278 | * @param htim: TIM OPM handle |
mbed_official | 87:085cde657901 | 4279 | * @retval HAL state |
mbed_official | 87:085cde657901 | 4280 | */ |
mbed_official | 87:085cde657901 | 4281 | HAL_TIM_StateTypeDef HAL_TIM_OnePulse_GetState(TIM_HandleTypeDef *htim) |
mbed_official | 87:085cde657901 | 4282 | { |
mbed_official | 87:085cde657901 | 4283 | return htim->State; |
mbed_official | 87:085cde657901 | 4284 | } |
mbed_official | 87:085cde657901 | 4285 | |
mbed_official | 87:085cde657901 | 4286 | /** |
mbed_official | 87:085cde657901 | 4287 | * @brief Return the TIM Encoder Mode state |
mbed_official | 87:085cde657901 | 4288 | * @param htim: TIM Encoder handle |
mbed_official | 87:085cde657901 | 4289 | * @retval HAL state |
mbed_official | 87:085cde657901 | 4290 | */ |
mbed_official | 87:085cde657901 | 4291 | HAL_TIM_StateTypeDef HAL_TIM_Encoder_GetState(TIM_HandleTypeDef *htim) |
mbed_official | 87:085cde657901 | 4292 | { |
mbed_official | 87:085cde657901 | 4293 | return htim->State; |
mbed_official | 87:085cde657901 | 4294 | } |
mbed_official | 87:085cde657901 | 4295 | |
mbed_official | 87:085cde657901 | 4296 | /** |
mbed_official | 87:085cde657901 | 4297 | * @} |
mbed_official | 87:085cde657901 | 4298 | */ |
mbed_official | 87:085cde657901 | 4299 | |
mbed_official | 87:085cde657901 | 4300 | /** |
mbed_official | 87:085cde657901 | 4301 | * @brief TIM DMA error callback |
mbed_official | 87:085cde657901 | 4302 | * @param hdma : pointer to DMA handle. |
mbed_official | 87:085cde657901 | 4303 | * @retval None |
mbed_official | 87:085cde657901 | 4304 | */ |
mbed_official | 87:085cde657901 | 4305 | void HAL_TIM_DMAError(DMA_HandleTypeDef *hdma) |
mbed_official | 87:085cde657901 | 4306 | { |
mbed_official | 87:085cde657901 | 4307 | TIM_HandleTypeDef* htim = ( TIM_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent; |
mbed_official | 87:085cde657901 | 4308 | |
mbed_official | 87:085cde657901 | 4309 | htim->State= HAL_TIM_STATE_READY; |
mbed_official | 87:085cde657901 | 4310 | |
mbed_official | 87:085cde657901 | 4311 | HAL_TIM_ErrorCallback(htim); |
mbed_official | 87:085cde657901 | 4312 | } |
mbed_official | 87:085cde657901 | 4313 | |
mbed_official | 87:085cde657901 | 4314 | /** |
mbed_official | 87:085cde657901 | 4315 | * @brief TIM DMA Delay Pulse complete callback. |
mbed_official | 87:085cde657901 | 4316 | * @param hdma : pointer to DMA handle. |
mbed_official | 87:085cde657901 | 4317 | * @retval None |
mbed_official | 87:085cde657901 | 4318 | */ |
mbed_official | 87:085cde657901 | 4319 | void HAL_TIM_DMADelayPulseCplt(DMA_HandleTypeDef *hdma) |
mbed_official | 87:085cde657901 | 4320 | { |
mbed_official | 87:085cde657901 | 4321 | TIM_HandleTypeDef* htim = ( TIM_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent; |
mbed_official | 87:085cde657901 | 4322 | |
mbed_official | 87:085cde657901 | 4323 | htim->State= HAL_TIM_STATE_READY; |
mbed_official | 87:085cde657901 | 4324 | |
mbed_official | 87:085cde657901 | 4325 | HAL_TIM_PWM_PulseFinishedCallback(htim); |
mbed_official | 87:085cde657901 | 4326 | } |
mbed_official | 87:085cde657901 | 4327 | /** |
mbed_official | 87:085cde657901 | 4328 | * @brief TIM DMA Capture complete callback. |
mbed_official | 87:085cde657901 | 4329 | * @param hdma : pointer to DMA handle. |
mbed_official | 87:085cde657901 | 4330 | * @retval None |
mbed_official | 87:085cde657901 | 4331 | */ |
mbed_official | 87:085cde657901 | 4332 | void HAL_TIM_DMACaptureCplt(DMA_HandleTypeDef *hdma) |
mbed_official | 87:085cde657901 | 4333 | { |
mbed_official | 87:085cde657901 | 4334 | TIM_HandleTypeDef* htim = ( TIM_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent; |
mbed_official | 87:085cde657901 | 4335 | |
mbed_official | 87:085cde657901 | 4336 | htim->State= HAL_TIM_STATE_READY; |
mbed_official | 87:085cde657901 | 4337 | |
mbed_official | 87:085cde657901 | 4338 | HAL_TIM_IC_CaptureCallback(htim); |
mbed_official | 87:085cde657901 | 4339 | |
mbed_official | 87:085cde657901 | 4340 | } |
mbed_official | 87:085cde657901 | 4341 | |
mbed_official | 87:085cde657901 | 4342 | /** |
mbed_official | 87:085cde657901 | 4343 | * @brief TIM DMA Period Elapse complete callback. |
mbed_official | 87:085cde657901 | 4344 | * @param hdma : pointer to DMA handle. |
mbed_official | 87:085cde657901 | 4345 | * @retval None |
mbed_official | 87:085cde657901 | 4346 | */ |
mbed_official | 87:085cde657901 | 4347 | static void TIM_DMAPeriodElapsedCplt(DMA_HandleTypeDef *hdma) |
mbed_official | 87:085cde657901 | 4348 | { |
mbed_official | 87:085cde657901 | 4349 | TIM_HandleTypeDef* htim = ( TIM_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent; |
mbed_official | 87:085cde657901 | 4350 | |
mbed_official | 87:085cde657901 | 4351 | htim->State= HAL_TIM_STATE_READY; |
mbed_official | 87:085cde657901 | 4352 | |
mbed_official | 87:085cde657901 | 4353 | HAL_TIM_PeriodElapsedCallback(htim); |
mbed_official | 87:085cde657901 | 4354 | } |
mbed_official | 87:085cde657901 | 4355 | |
mbed_official | 87:085cde657901 | 4356 | /** |
mbed_official | 87:085cde657901 | 4357 | * @brief TIM DMA Trigger callback. |
mbed_official | 87:085cde657901 | 4358 | * @param hdma : pointer to DMA handle. |
mbed_official | 87:085cde657901 | 4359 | * @retval None |
mbed_official | 87:085cde657901 | 4360 | */ |
mbed_official | 87:085cde657901 | 4361 | static void TIM_DMATriggerCplt(DMA_HandleTypeDef *hdma) |
mbed_official | 87:085cde657901 | 4362 | { |
mbed_official | 87:085cde657901 | 4363 | TIM_HandleTypeDef* htim = ( TIM_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent; |
mbed_official | 87:085cde657901 | 4364 | |
mbed_official | 87:085cde657901 | 4365 | htim->State= HAL_TIM_STATE_READY; |
mbed_official | 87:085cde657901 | 4366 | |
mbed_official | 87:085cde657901 | 4367 | HAL_TIM_TriggerCallback(htim); |
mbed_official | 87:085cde657901 | 4368 | } |
mbed_official | 87:085cde657901 | 4369 | |
mbed_official | 87:085cde657901 | 4370 | /** |
mbed_official | 87:085cde657901 | 4371 | * @brief Time Base configuration |
mbed_official | 87:085cde657901 | 4372 | * @param TIMx: TIM periheral |
mbed_official | 87:085cde657901 | 4373 | * @retval None |
mbed_official | 87:085cde657901 | 4374 | */ |
mbed_official | 87:085cde657901 | 4375 | void TIM_Base_SetConfig(TIM_TypeDef *TIMx, TIM_Base_InitTypeDef *Structure) |
mbed_official | 87:085cde657901 | 4376 | { |
mbed_official | 87:085cde657901 | 4377 | uint32_t tmpcr1 = 0; |
mbed_official | 87:085cde657901 | 4378 | tmpcr1 = TIMx->CR1; |
mbed_official | 87:085cde657901 | 4379 | |
mbed_official | 87:085cde657901 | 4380 | /* Set TIM Time Base Unit parameters ---------------------------------------*/ |
mbed_official | 87:085cde657901 | 4381 | if(IS_TIM_CC3_INSTANCE(TIMx) != RESET) |
mbed_official | 87:085cde657901 | 4382 | { |
mbed_official | 87:085cde657901 | 4383 | /* Select the Counter Mode */ |
mbed_official | 87:085cde657901 | 4384 | tmpcr1 &= ~(TIM_CR1_DIR | TIM_CR1_CMS); |
mbed_official | 87:085cde657901 | 4385 | tmpcr1 |= Structure->CounterMode; |
mbed_official | 87:085cde657901 | 4386 | } |
mbed_official | 87:085cde657901 | 4387 | |
mbed_official | 87:085cde657901 | 4388 | if(IS_TIM_CC1_INSTANCE(TIMx) != RESET) |
mbed_official | 87:085cde657901 | 4389 | { |
mbed_official | 87:085cde657901 | 4390 | /* Set the clock division */ |
mbed_official | 87:085cde657901 | 4391 | tmpcr1 &= ~TIM_CR1_CKD; |
mbed_official | 87:085cde657901 | 4392 | tmpcr1 |= (uint32_t)Structure->ClockDivision; |
mbed_official | 87:085cde657901 | 4393 | } |
mbed_official | 87:085cde657901 | 4394 | |
mbed_official | 87:085cde657901 | 4395 | TIMx->CR1 = tmpcr1; |
mbed_official | 87:085cde657901 | 4396 | |
mbed_official | 87:085cde657901 | 4397 | /* Set the Autoreload value */ |
mbed_official | 87:085cde657901 | 4398 | TIMx->ARR = (uint32_t)Structure->Period ; |
mbed_official | 87:085cde657901 | 4399 | |
mbed_official | 87:085cde657901 | 4400 | /* Set the Prescaler value */ |
mbed_official | 87:085cde657901 | 4401 | TIMx->PSC = (uint32_t)Structure->Prescaler; |
mbed_official | 87:085cde657901 | 4402 | |
mbed_official | 87:085cde657901 | 4403 | if(IS_TIM_ADVANCED_INSTANCE(TIMx) != RESET) |
mbed_official | 87:085cde657901 | 4404 | { |
mbed_official | 87:085cde657901 | 4405 | /* Set the Repetition Counter value */ |
mbed_official | 87:085cde657901 | 4406 | TIMx->RCR = Structure->RepetitionCounter; |
mbed_official | 87:085cde657901 | 4407 | } |
mbed_official | 87:085cde657901 | 4408 | |
mbed_official | 87:085cde657901 | 4409 | /* Generate an update event to reload the Prescaler |
mbed_official | 87:085cde657901 | 4410 | and the repetition counter(only for TIM1 and TIM8) value immediatly */ |
mbed_official | 87:085cde657901 | 4411 | TIMx->EGR = TIM_EGR_UG; |
mbed_official | 87:085cde657901 | 4412 | } |
mbed_official | 87:085cde657901 | 4413 | |
mbed_official | 87:085cde657901 | 4414 | /** |
mbed_official | 87:085cde657901 | 4415 | * @brief Time Ouput Compare 1 configuration |
mbed_official | 87:085cde657901 | 4416 | * @param TIMx to select the TIM peripheral |
mbed_official | 87:085cde657901 | 4417 | * @param OC_Config: The ouput configuration structure |
mbed_official | 87:085cde657901 | 4418 | * @retval None |
mbed_official | 87:085cde657901 | 4419 | */ |
mbed_official | 87:085cde657901 | 4420 | static void TIM_OC1_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config) |
mbed_official | 87:085cde657901 | 4421 | { |
mbed_official | 87:085cde657901 | 4422 | uint32_t tmpccmrx = 0; |
mbed_official | 87:085cde657901 | 4423 | uint32_t tmpccer = 0; |
mbed_official | 87:085cde657901 | 4424 | uint32_t tmpcr2 = 0; |
mbed_official | 87:085cde657901 | 4425 | |
mbed_official | 87:085cde657901 | 4426 | /* Disable the Channel 1: Reset the CC1E Bit */ |
mbed_official | 87:085cde657901 | 4427 | TIMx->CCER &= ~TIM_CCER_CC1E; |
mbed_official | 87:085cde657901 | 4428 | |
mbed_official | 87:085cde657901 | 4429 | /* Get the TIMx CCER register value */ |
mbed_official | 87:085cde657901 | 4430 | tmpccer = TIMx->CCER; |
mbed_official | 87:085cde657901 | 4431 | /* Get the TIMx CR2 register value */ |
mbed_official | 87:085cde657901 | 4432 | tmpcr2 = TIMx->CR2; |
mbed_official | 87:085cde657901 | 4433 | |
mbed_official | 87:085cde657901 | 4434 | /* Get the TIMx CCMR1 register value */ |
mbed_official | 87:085cde657901 | 4435 | tmpccmrx = TIMx->CCMR1; |
mbed_official | 87:085cde657901 | 4436 | |
mbed_official | 87:085cde657901 | 4437 | /* Reset the Output Compare Mode Bits */ |
mbed_official | 87:085cde657901 | 4438 | tmpccmrx &= ~TIM_CCMR1_OC1M; |
mbed_official | 87:085cde657901 | 4439 | tmpccmrx &= ~TIM_CCMR1_CC1S; |
mbed_official | 87:085cde657901 | 4440 | /* Select the Output Compare Mode */ |
mbed_official | 87:085cde657901 | 4441 | tmpccmrx |= OC_Config->OCMode; |
mbed_official | 87:085cde657901 | 4442 | |
mbed_official | 87:085cde657901 | 4443 | /* Reset the Output Polarity level */ |
mbed_official | 87:085cde657901 | 4444 | tmpccer &= ~TIM_CCER_CC1P; |
mbed_official | 87:085cde657901 | 4445 | /* Set the Output Compare Polarity */ |
mbed_official | 87:085cde657901 | 4446 | tmpccer |= OC_Config->OCPolarity; |
mbed_official | 87:085cde657901 | 4447 | |
mbed_official | 87:085cde657901 | 4448 | |
mbed_official | 87:085cde657901 | 4449 | if(IS_TIM_ADVANCED_INSTANCE(TIMx) != RESET) |
mbed_official | 87:085cde657901 | 4450 | { |
mbed_official | 87:085cde657901 | 4451 | /* Reset the Output N Polarity level */ |
mbed_official | 87:085cde657901 | 4452 | tmpccer &= ~TIM_CCER_CC1NP; |
mbed_official | 87:085cde657901 | 4453 | /* Set the Output N Polarity */ |
mbed_official | 87:085cde657901 | 4454 | tmpccer |= OC_Config->OCNPolarity; |
mbed_official | 87:085cde657901 | 4455 | /* Reset the Output N State */ |
mbed_official | 87:085cde657901 | 4456 | tmpccer &= ~TIM_CCER_CC1NE; |
mbed_official | 87:085cde657901 | 4457 | |
mbed_official | 87:085cde657901 | 4458 | /* Reset the Output Compare and Output Compare N IDLE State */ |
mbed_official | 87:085cde657901 | 4459 | tmpcr2 &= ~TIM_CR2_OIS1; |
mbed_official | 87:085cde657901 | 4460 | tmpcr2 &= ~TIM_CR2_OIS1N; |
mbed_official | 87:085cde657901 | 4461 | /* Set the Output Idle state */ |
mbed_official | 87:085cde657901 | 4462 | tmpcr2 |= OC_Config->OCIdleState; |
mbed_official | 87:085cde657901 | 4463 | /* Set the Output N Idle state */ |
mbed_official | 87:085cde657901 | 4464 | tmpcr2 |= OC_Config->OCNIdleState; |
mbed_official | 87:085cde657901 | 4465 | } |
mbed_official | 87:085cde657901 | 4466 | /* Write to TIMx CR2 */ |
mbed_official | 87:085cde657901 | 4467 | TIMx->CR2 = tmpcr2; |
mbed_official | 87:085cde657901 | 4468 | |
mbed_official | 87:085cde657901 | 4469 | /* Write to TIMx CCMR1 */ |
mbed_official | 87:085cde657901 | 4470 | TIMx->CCMR1 = tmpccmrx; |
mbed_official | 87:085cde657901 | 4471 | |
mbed_official | 87:085cde657901 | 4472 | /* Set the Capture Compare Register value */ |
mbed_official | 87:085cde657901 | 4473 | TIMx->CCR1 = OC_Config->Pulse; |
mbed_official | 87:085cde657901 | 4474 | |
mbed_official | 87:085cde657901 | 4475 | /* Write to TIMx CCER */ |
mbed_official | 87:085cde657901 | 4476 | TIMx->CCER = tmpccer; |
mbed_official | 87:085cde657901 | 4477 | } |
mbed_official | 87:085cde657901 | 4478 | |
mbed_official | 87:085cde657901 | 4479 | /** |
mbed_official | 87:085cde657901 | 4480 | * @brief Time Ouput Compare 2 configuration |
mbed_official | 87:085cde657901 | 4481 | * @param TIMx to select the TIM peripheral |
mbed_official | 87:085cde657901 | 4482 | * @param OC_Config: The ouput configuration structure |
mbed_official | 87:085cde657901 | 4483 | * @retval None |
mbed_official | 87:085cde657901 | 4484 | */ |
mbed_official | 87:085cde657901 | 4485 | void TIM_OC2_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config) |
mbed_official | 87:085cde657901 | 4486 | { |
mbed_official | 87:085cde657901 | 4487 | uint32_t tmpccmrx = 0; |
mbed_official | 87:085cde657901 | 4488 | uint32_t tmpccer = 0; |
mbed_official | 87:085cde657901 | 4489 | uint32_t tmpcr2 = 0; |
mbed_official | 87:085cde657901 | 4490 | |
mbed_official | 87:085cde657901 | 4491 | /* Disable the Channel 2: Reset the CC2E Bit */ |
mbed_official | 87:085cde657901 | 4492 | TIMx->CCER &= ~TIM_CCER_CC2E; |
mbed_official | 87:085cde657901 | 4493 | |
mbed_official | 87:085cde657901 | 4494 | /* Get the TIMx CCER register value */ |
mbed_official | 87:085cde657901 | 4495 | tmpccer = TIMx->CCER; |
mbed_official | 87:085cde657901 | 4496 | /* Get the TIMx CR2 register value */ |
mbed_official | 87:085cde657901 | 4497 | tmpcr2 = TIMx->CR2; |
mbed_official | 87:085cde657901 | 4498 | |
mbed_official | 87:085cde657901 | 4499 | /* Get the TIMx CCMR1 register value */ |
mbed_official | 87:085cde657901 | 4500 | tmpccmrx = TIMx->CCMR1; |
mbed_official | 87:085cde657901 | 4501 | |
mbed_official | 87:085cde657901 | 4502 | /* Reset the Output Compare mode and Capture/Compare selection Bits */ |
mbed_official | 87:085cde657901 | 4503 | tmpccmrx &= ~TIM_CCMR1_OC2M; |
mbed_official | 87:085cde657901 | 4504 | tmpccmrx &= ~TIM_CCMR1_CC2S; |
mbed_official | 87:085cde657901 | 4505 | |
mbed_official | 87:085cde657901 | 4506 | /* Select the Output Compare Mode */ |
mbed_official | 87:085cde657901 | 4507 | tmpccmrx |= (OC_Config->OCMode << 8); |
mbed_official | 87:085cde657901 | 4508 | |
mbed_official | 87:085cde657901 | 4509 | /* Reset the Output Polarity level */ |
mbed_official | 87:085cde657901 | 4510 | tmpccer &= ~TIM_CCER_CC2P; |
mbed_official | 87:085cde657901 | 4511 | /* Set the Output Compare Polarity */ |
mbed_official | 87:085cde657901 | 4512 | tmpccer |= (OC_Config->OCPolarity << 4); |
mbed_official | 87:085cde657901 | 4513 | |
mbed_official | 87:085cde657901 | 4514 | if(IS_TIM_ADVANCED_INSTANCE(TIMx) != RESET) |
mbed_official | 87:085cde657901 | 4515 | { |
mbed_official | 87:085cde657901 | 4516 | assert_param(IS_TIM_OCN_POLARITY(OC_Config->OCNPolarity)); |
mbed_official | 87:085cde657901 | 4517 | assert_param(IS_TIM_OCNIDLE_STATE(OC_Config->OCNIdleState)); |
mbed_official | 87:085cde657901 | 4518 | assert_param(IS_TIM_OCIDLE_STATE(OC_Config->OCIdleState)); |
mbed_official | 87:085cde657901 | 4519 | |
mbed_official | 87:085cde657901 | 4520 | /* Reset the Output N Polarity level */ |
mbed_official | 87:085cde657901 | 4521 | tmpccer &= ~TIM_CCER_CC2NP; |
mbed_official | 87:085cde657901 | 4522 | /* Set the Output N Polarity */ |
mbed_official | 87:085cde657901 | 4523 | tmpccer |= (OC_Config->OCNPolarity << 4); |
mbed_official | 87:085cde657901 | 4524 | /* Reset the Output N State */ |
mbed_official | 87:085cde657901 | 4525 | tmpccer &= ~TIM_CCER_CC2NE; |
mbed_official | 87:085cde657901 | 4526 | |
mbed_official | 87:085cde657901 | 4527 | /* Reset the Output Compare and Output Compare N IDLE State */ |
mbed_official | 87:085cde657901 | 4528 | tmpcr2 &= ~TIM_CR2_OIS2; |
mbed_official | 87:085cde657901 | 4529 | tmpcr2 &= ~TIM_CR2_OIS2N; |
mbed_official | 87:085cde657901 | 4530 | /* Set the Output Idle state */ |
mbed_official | 87:085cde657901 | 4531 | tmpcr2 |= (OC_Config->OCIdleState << 2); |
mbed_official | 87:085cde657901 | 4532 | /* Set the Output N Idle state */ |
mbed_official | 87:085cde657901 | 4533 | tmpcr2 |= (OC_Config->OCNIdleState << 2); |
mbed_official | 87:085cde657901 | 4534 | } |
mbed_official | 87:085cde657901 | 4535 | /* Write to TIMx CR2 */ |
mbed_official | 87:085cde657901 | 4536 | TIMx->CR2 = tmpcr2; |
mbed_official | 87:085cde657901 | 4537 | |
mbed_official | 87:085cde657901 | 4538 | /* Write to TIMx CCMR1 */ |
mbed_official | 87:085cde657901 | 4539 | TIMx->CCMR1 = tmpccmrx; |
mbed_official | 87:085cde657901 | 4540 | |
mbed_official | 87:085cde657901 | 4541 | /* Set the Capture Compare Register value */ |
mbed_official | 87:085cde657901 | 4542 | TIMx->CCR2 = OC_Config->Pulse; |
mbed_official | 87:085cde657901 | 4543 | |
mbed_official | 87:085cde657901 | 4544 | /* Write to TIMx CCER */ |
mbed_official | 87:085cde657901 | 4545 | TIMx->CCER = tmpccer; |
mbed_official | 87:085cde657901 | 4546 | } |
mbed_official | 87:085cde657901 | 4547 | |
mbed_official | 87:085cde657901 | 4548 | /** |
mbed_official | 87:085cde657901 | 4549 | * @brief Time Ouput Compare 3 configuration |
mbed_official | 87:085cde657901 | 4550 | * @param TIMx to select the TIM peripheral |
mbed_official | 87:085cde657901 | 4551 | * @param OC_Config: The ouput configuration structure |
mbed_official | 87:085cde657901 | 4552 | * @retval None |
mbed_official | 87:085cde657901 | 4553 | */ |
mbed_official | 87:085cde657901 | 4554 | static void TIM_OC3_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config) |
mbed_official | 87:085cde657901 | 4555 | { |
mbed_official | 87:085cde657901 | 4556 | uint32_t tmpccmrx = 0; |
mbed_official | 87:085cde657901 | 4557 | uint32_t tmpccer = 0; |
mbed_official | 87:085cde657901 | 4558 | uint32_t tmpcr2 = 0; |
mbed_official | 87:085cde657901 | 4559 | |
mbed_official | 87:085cde657901 | 4560 | /* Disable the Channel 3: Reset the CC2E Bit */ |
mbed_official | 87:085cde657901 | 4561 | TIMx->CCER &= ~TIM_CCER_CC3E; |
mbed_official | 87:085cde657901 | 4562 | |
mbed_official | 87:085cde657901 | 4563 | /* Get the TIMx CCER register value */ |
mbed_official | 87:085cde657901 | 4564 | tmpccer = TIMx->CCER; |
mbed_official | 87:085cde657901 | 4565 | /* Get the TIMx CR2 register value */ |
mbed_official | 87:085cde657901 | 4566 | tmpcr2 = TIMx->CR2; |
mbed_official | 87:085cde657901 | 4567 | |
mbed_official | 87:085cde657901 | 4568 | /* Get the TIMx CCMR2 register value */ |
mbed_official | 87:085cde657901 | 4569 | tmpccmrx = TIMx->CCMR2; |
mbed_official | 87:085cde657901 | 4570 | |
mbed_official | 87:085cde657901 | 4571 | /* Reset the Output Compare mode and Capture/Compare selection Bits */ |
mbed_official | 87:085cde657901 | 4572 | tmpccmrx &= ~TIM_CCMR2_OC3M; |
mbed_official | 87:085cde657901 | 4573 | tmpccmrx &= ~TIM_CCMR2_CC3S; |
mbed_official | 87:085cde657901 | 4574 | /* Select the Output Compare Mode */ |
mbed_official | 87:085cde657901 | 4575 | tmpccmrx |= OC_Config->OCMode; |
mbed_official | 87:085cde657901 | 4576 | |
mbed_official | 87:085cde657901 | 4577 | /* Reset the Output Polarity level */ |
mbed_official | 87:085cde657901 | 4578 | tmpccer &= ~TIM_CCER_CC3P; |
mbed_official | 87:085cde657901 | 4579 | /* Set the Output Compare Polarity */ |
mbed_official | 87:085cde657901 | 4580 | tmpccer |= (OC_Config->OCPolarity << 8); |
mbed_official | 87:085cde657901 | 4581 | |
mbed_official | 87:085cde657901 | 4582 | if(IS_TIM_ADVANCED_INSTANCE(TIMx) != RESET) |
mbed_official | 87:085cde657901 | 4583 | { |
mbed_official | 87:085cde657901 | 4584 | assert_param(IS_TIM_OCN_POLARITY(OC_Config->OCNPolarity)); |
mbed_official | 87:085cde657901 | 4585 | assert_param(IS_TIM_OCNIDLE_STATE(OC_Config->OCNIdleState)); |
mbed_official | 87:085cde657901 | 4586 | assert_param(IS_TIM_OCIDLE_STATE(OC_Config->OCIdleState)); |
mbed_official | 87:085cde657901 | 4587 | |
mbed_official | 87:085cde657901 | 4588 | /* Reset the Output N Polarity level */ |
mbed_official | 87:085cde657901 | 4589 | tmpccer &= ~TIM_CCER_CC3NP; |
mbed_official | 87:085cde657901 | 4590 | /* Set the Output N Polarity */ |
mbed_official | 87:085cde657901 | 4591 | tmpccer |= (OC_Config->OCNPolarity << 8); |
mbed_official | 87:085cde657901 | 4592 | /* Reset the Output N State */ |
mbed_official | 87:085cde657901 | 4593 | tmpccer &= ~TIM_CCER_CC3NE; |
mbed_official | 87:085cde657901 | 4594 | |
mbed_official | 87:085cde657901 | 4595 | /* Reset the Output Compare and Output Compare N IDLE State */ |
mbed_official | 87:085cde657901 | 4596 | tmpcr2 &= ~TIM_CR2_OIS3; |
mbed_official | 87:085cde657901 | 4597 | tmpcr2 &= ~TIM_CR2_OIS3N; |
mbed_official | 87:085cde657901 | 4598 | /* Set the Output Idle state */ |
mbed_official | 87:085cde657901 | 4599 | tmpcr2 |= (OC_Config->OCIdleState << 4); |
mbed_official | 87:085cde657901 | 4600 | /* Set the Output N Idle state */ |
mbed_official | 87:085cde657901 | 4601 | tmpcr2 |= (OC_Config->OCNIdleState << 4); |
mbed_official | 87:085cde657901 | 4602 | } |
mbed_official | 87:085cde657901 | 4603 | /* Write to TIMx CR2 */ |
mbed_official | 87:085cde657901 | 4604 | TIMx->CR2 = tmpcr2; |
mbed_official | 87:085cde657901 | 4605 | |
mbed_official | 87:085cde657901 | 4606 | /* Write to TIMx CCMR2 */ |
mbed_official | 87:085cde657901 | 4607 | TIMx->CCMR2 = tmpccmrx; |
mbed_official | 87:085cde657901 | 4608 | |
mbed_official | 87:085cde657901 | 4609 | /* Set the Capture Compare Register value */ |
mbed_official | 87:085cde657901 | 4610 | TIMx->CCR3 = OC_Config->Pulse; |
mbed_official | 87:085cde657901 | 4611 | |
mbed_official | 87:085cde657901 | 4612 | /* Write to TIMx CCER */ |
mbed_official | 87:085cde657901 | 4613 | TIMx->CCER = tmpccer; |
mbed_official | 87:085cde657901 | 4614 | } |
mbed_official | 87:085cde657901 | 4615 | |
mbed_official | 87:085cde657901 | 4616 | /** |
mbed_official | 87:085cde657901 | 4617 | * @brief Time Ouput Compare 4 configuration |
mbed_official | 87:085cde657901 | 4618 | * @param TIMx to select the TIM peripheral |
mbed_official | 87:085cde657901 | 4619 | * @param OC_Config: The ouput configuration structure |
mbed_official | 87:085cde657901 | 4620 | * @retval None |
mbed_official | 87:085cde657901 | 4621 | */ |
mbed_official | 87:085cde657901 | 4622 | static void TIM_OC4_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config) |
mbed_official | 87:085cde657901 | 4623 | { |
mbed_official | 87:085cde657901 | 4624 | uint32_t tmpccmrx = 0; |
mbed_official | 87:085cde657901 | 4625 | uint32_t tmpccer = 0; |
mbed_official | 87:085cde657901 | 4626 | uint32_t tmpcr2 = 0; |
mbed_official | 87:085cde657901 | 4627 | |
mbed_official | 87:085cde657901 | 4628 | /* Disable the Channel 4: Reset the CC4E Bit */ |
mbed_official | 87:085cde657901 | 4629 | TIMx->CCER &= ~TIM_CCER_CC4E; |
mbed_official | 87:085cde657901 | 4630 | |
mbed_official | 87:085cde657901 | 4631 | /* Get the TIMx CCER register value */ |
mbed_official | 87:085cde657901 | 4632 | tmpccer = TIMx->CCER; |
mbed_official | 87:085cde657901 | 4633 | /* Get the TIMx CR2 register value */ |
mbed_official | 87:085cde657901 | 4634 | tmpcr2 = TIMx->CR2; |
mbed_official | 87:085cde657901 | 4635 | |
mbed_official | 87:085cde657901 | 4636 | /* Get the TIMx CCMR2 register value */ |
mbed_official | 87:085cde657901 | 4637 | tmpccmrx = TIMx->CCMR2; |
mbed_official | 87:085cde657901 | 4638 | |
mbed_official | 87:085cde657901 | 4639 | /* Reset the Output Compare mode and Capture/Compare selection Bits */ |
mbed_official | 87:085cde657901 | 4640 | tmpccmrx &= ~TIM_CCMR2_OC4M; |
mbed_official | 87:085cde657901 | 4641 | tmpccmrx &= ~TIM_CCMR2_CC4S; |
mbed_official | 87:085cde657901 | 4642 | |
mbed_official | 87:085cde657901 | 4643 | /* Select the Output Compare Mode */ |
mbed_official | 87:085cde657901 | 4644 | tmpccmrx |= (OC_Config->OCMode << 8); |
mbed_official | 87:085cde657901 | 4645 | |
mbed_official | 87:085cde657901 | 4646 | /* Reset the Output Polarity level */ |
mbed_official | 87:085cde657901 | 4647 | tmpccer &= ~TIM_CCER_CC4P; |
mbed_official | 87:085cde657901 | 4648 | /* Set the Output Compare Polarity */ |
mbed_official | 87:085cde657901 | 4649 | tmpccer |= (OC_Config->OCPolarity << 12); |
mbed_official | 87:085cde657901 | 4650 | |
mbed_official | 87:085cde657901 | 4651 | /*if((TIMx == TIM1) || (TIMx == TIM8))*/ |
mbed_official | 87:085cde657901 | 4652 | if(IS_TIM_ADVANCED_INSTANCE(TIMx) != RESET) |
mbed_official | 87:085cde657901 | 4653 | { |
mbed_official | 87:085cde657901 | 4654 | assert_param(IS_TIM_OCIDLE_STATE(OC_Config->OCIdleState)); |
mbed_official | 87:085cde657901 | 4655 | /* Reset the Output Compare IDLE State */ |
mbed_official | 87:085cde657901 | 4656 | tmpcr2 &= ~TIM_CR2_OIS4; |
mbed_official | 87:085cde657901 | 4657 | /* Set the Output Idle state */ |
mbed_official | 87:085cde657901 | 4658 | tmpcr2 |= (OC_Config->OCIdleState << 6); |
mbed_official | 87:085cde657901 | 4659 | } |
mbed_official | 87:085cde657901 | 4660 | /* Write to TIMx CR2 */ |
mbed_official | 87:085cde657901 | 4661 | TIMx->CR2 = tmpcr2; |
mbed_official | 87:085cde657901 | 4662 | |
mbed_official | 87:085cde657901 | 4663 | /* Write to TIMx CCMR2 */ |
mbed_official | 87:085cde657901 | 4664 | TIMx->CCMR2 = tmpccmrx; |
mbed_official | 87:085cde657901 | 4665 | |
mbed_official | 87:085cde657901 | 4666 | /* Set the Capture Compare Register value */ |
mbed_official | 87:085cde657901 | 4667 | TIMx->CCR4 = OC_Config->Pulse; |
mbed_official | 87:085cde657901 | 4668 | |
mbed_official | 87:085cde657901 | 4669 | /* Write to TIMx CCER */ |
mbed_official | 87:085cde657901 | 4670 | TIMx->CCER = tmpccer; |
mbed_official | 87:085cde657901 | 4671 | } |
mbed_official | 87:085cde657901 | 4672 | |
mbed_official | 87:085cde657901 | 4673 | /** |
mbed_official | 87:085cde657901 | 4674 | * @brief Configure the TI1 as Input. |
mbed_official | 87:085cde657901 | 4675 | * @param TIMx to select the TIM peripheral. |
mbed_official | 87:085cde657901 | 4676 | * @param TIM_ICPolarity : The Input Polarity. |
mbed_official | 87:085cde657901 | 4677 | * This parameter can be one of the following values: |
mbed_official | 87:085cde657901 | 4678 | * @arg TIM_ICPolarity_Rising |
mbed_official | 87:085cde657901 | 4679 | * @arg TIM_ICPolarity_Falling |
mbed_official | 87:085cde657901 | 4680 | * @arg TIM_ICPolarity_BothEdge |
mbed_official | 87:085cde657901 | 4681 | * @param TIM_ICSelection: specifies the input to be used. |
mbed_official | 87:085cde657901 | 4682 | * This parameter can be one of the following values: |
mbed_official | 87:085cde657901 | 4683 | * @arg TIM_ICSelection_DirectTI: TIM Input 1 is selected to be connected to IC1. |
mbed_official | 87:085cde657901 | 4684 | * @arg TIM_ICSelection_IndirectTI: TIM Input 1 is selected to be connected to IC2. |
mbed_official | 87:085cde657901 | 4685 | * @arg TIM_ICSelection_TRC: TIM Input 1 is selected to be connected to TRC. |
mbed_official | 87:085cde657901 | 4686 | * @param TIM_ICFilter: Specifies the Input Capture Filter. |
mbed_official | 87:085cde657901 | 4687 | * This parameter must be a value between 0x00 and 0x0F. |
mbed_official | 87:085cde657901 | 4688 | * @retval None |
mbed_official | 87:085cde657901 | 4689 | */ |
mbed_official | 87:085cde657901 | 4690 | void TIM_TI1_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection, |
mbed_official | 87:085cde657901 | 4691 | uint32_t TIM_ICFilter) |
mbed_official | 87:085cde657901 | 4692 | { |
mbed_official | 87:085cde657901 | 4693 | uint32_t tmpccmr1 = 0; |
mbed_official | 87:085cde657901 | 4694 | uint32_t tmpccer = 0; |
mbed_official | 87:085cde657901 | 4695 | |
mbed_official | 87:085cde657901 | 4696 | /* Disable the Channel 1: Reset the CC1E Bit */ |
mbed_official | 87:085cde657901 | 4697 | TIMx->CCER &= ~TIM_CCER_CC1E; |
mbed_official | 87:085cde657901 | 4698 | tmpccmr1 = TIMx->CCMR1; |
mbed_official | 87:085cde657901 | 4699 | tmpccer = TIMx->CCER; |
mbed_official | 87:085cde657901 | 4700 | |
mbed_official | 87:085cde657901 | 4701 | /* Select the Input */ |
mbed_official | 87:085cde657901 | 4702 | if(IS_TIM_CC2_INSTANCE(TIMx) != RESET) |
mbed_official | 87:085cde657901 | 4703 | { |
mbed_official | 87:085cde657901 | 4704 | tmpccmr1 &= ~TIM_CCMR1_CC1S; |
mbed_official | 87:085cde657901 | 4705 | tmpccmr1 |= TIM_ICSelection; |
mbed_official | 87:085cde657901 | 4706 | } |
mbed_official | 87:085cde657901 | 4707 | else |
mbed_official | 87:085cde657901 | 4708 | { |
mbed_official | 87:085cde657901 | 4709 | tmpccmr1 &= ~TIM_CCMR1_CC1S; |
mbed_official | 87:085cde657901 | 4710 | tmpccmr1 |= TIM_CCMR1_CC1S_0; |
mbed_official | 87:085cde657901 | 4711 | } |
mbed_official | 87:085cde657901 | 4712 | |
mbed_official | 87:085cde657901 | 4713 | /* Set the filter */ |
mbed_official | 87:085cde657901 | 4714 | tmpccmr1 &= ~TIM_CCMR1_IC1F; |
mbed_official | 87:085cde657901 | 4715 | tmpccmr1 |= (TIM_ICFilter << 4); |
mbed_official | 87:085cde657901 | 4716 | |
mbed_official | 87:085cde657901 | 4717 | /* Select the Polarity and set the CC1E Bit */ |
mbed_official | 87:085cde657901 | 4718 | tmpccer &= ~(TIM_CCER_CC1P | TIM_CCER_CC1NP); |
mbed_official | 87:085cde657901 | 4719 | tmpccer |= TIM_ICPolarity; |
mbed_official | 87:085cde657901 | 4720 | |
mbed_official | 87:085cde657901 | 4721 | /* Write to TIMx CCMR1 and CCER registers */ |
mbed_official | 87:085cde657901 | 4722 | TIMx->CCMR1 = tmpccmr1; |
mbed_official | 87:085cde657901 | 4723 | TIMx->CCER = tmpccer; |
mbed_official | 87:085cde657901 | 4724 | } |
mbed_official | 87:085cde657901 | 4725 | |
mbed_official | 87:085cde657901 | 4726 | /** |
mbed_official | 87:085cde657901 | 4727 | * @brief Configure the Polarity and Filter for TI1. |
mbed_official | 87:085cde657901 | 4728 | * @param TIMx to select the TIM peripheral. |
mbed_official | 87:085cde657901 | 4729 | * @param TIM_ICPolarity : The Input Polarity. |
mbed_official | 87:085cde657901 | 4730 | * This parameter can be one of the following values: |
mbed_official | 87:085cde657901 | 4731 | * @arg TIM_ICPolarity_Rising |
mbed_official | 87:085cde657901 | 4732 | * @arg TIM_ICPolarity_Falling |
mbed_official | 87:085cde657901 | 4733 | * @arg TIM_ICPolarity_BothEdge |
mbed_official | 87:085cde657901 | 4734 | * @param TIM_ICFilter: Specifies the Input Capture Filter. |
mbed_official | 87:085cde657901 | 4735 | * This parameter must be a value between 0x00 and 0x0F. |
mbed_official | 87:085cde657901 | 4736 | * @retval None |
mbed_official | 87:085cde657901 | 4737 | */ |
mbed_official | 87:085cde657901 | 4738 | static void TIM_TI1_ConfigInputStage(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICFilter) |
mbed_official | 87:085cde657901 | 4739 | { |
mbed_official | 87:085cde657901 | 4740 | uint32_t tmpccmr1 = 0; |
mbed_official | 87:085cde657901 | 4741 | uint32_t tmpccer = 0; |
mbed_official | 87:085cde657901 | 4742 | |
mbed_official | 87:085cde657901 | 4743 | /* Disable the Channel 1: Reset the CC1E Bit */ |
mbed_official | 87:085cde657901 | 4744 | tmpccer = TIMx->CCER; |
mbed_official | 87:085cde657901 | 4745 | TIMx->CCER &= ~TIM_CCER_CC1E; |
mbed_official | 87:085cde657901 | 4746 | tmpccmr1 = TIMx->CCMR1; |
mbed_official | 87:085cde657901 | 4747 | |
mbed_official | 87:085cde657901 | 4748 | /* Set the filter */ |
mbed_official | 87:085cde657901 | 4749 | tmpccmr1 &= ~TIM_CCMR1_IC1F; |
mbed_official | 87:085cde657901 | 4750 | tmpccmr1 |= (TIM_ICFilter << 4); |
mbed_official | 87:085cde657901 | 4751 | |
mbed_official | 87:085cde657901 | 4752 | /* Select the Polarity and set the CC1E Bit */ |
mbed_official | 87:085cde657901 | 4753 | tmpccer &= ~(TIM_CCER_CC1P | TIM_CCER_CC1NP); |
mbed_official | 87:085cde657901 | 4754 | tmpccer |= TIM_ICPolarity; |
mbed_official | 87:085cde657901 | 4755 | |
mbed_official | 87:085cde657901 | 4756 | /* Write to TIMx CCMR1 and CCER registers */ |
mbed_official | 87:085cde657901 | 4757 | TIMx->CCMR1 = tmpccmr1; |
mbed_official | 87:085cde657901 | 4758 | TIMx->CCER = tmpccer; |
mbed_official | 87:085cde657901 | 4759 | } |
mbed_official | 87:085cde657901 | 4760 | |
mbed_official | 87:085cde657901 | 4761 | /** |
mbed_official | 87:085cde657901 | 4762 | * @brief Configure the TI2 as Input. |
mbed_official | 87:085cde657901 | 4763 | * @param TIMx to select the TIM peripheral |
mbed_official | 87:085cde657901 | 4764 | * @param TIM_ICPolarity : The Input Polarity. |
mbed_official | 87:085cde657901 | 4765 | * This parameter can be one of the following values: |
mbed_official | 87:085cde657901 | 4766 | * @arg TIM_ICPolarity_Rising |
mbed_official | 87:085cde657901 | 4767 | * @arg TIM_ICPolarity_Falling |
mbed_official | 87:085cde657901 | 4768 | * @arg TIM_ICPolarity_BothEdge |
mbed_official | 87:085cde657901 | 4769 | * @param TIM_ICSelection: specifies the input to be used. |
mbed_official | 87:085cde657901 | 4770 | * This parameter can be one of the following values: |
mbed_official | 87:085cde657901 | 4771 | * @arg TIM_ICSelection_DirectTI: TIM Input 2 is selected to be connected to IC2. |
mbed_official | 87:085cde657901 | 4772 | * @arg TIM_ICSelection_IndirectTI: TIM Input 2 is selected to be connected to IC1. |
mbed_official | 87:085cde657901 | 4773 | * @arg TIM_ICSelection_TRC: TIM Input 2 is selected to be connected to TRC. |
mbed_official | 87:085cde657901 | 4774 | * @param TIM_ICFilter: Specifies the Input Capture Filter. |
mbed_official | 87:085cde657901 | 4775 | * This parameter must be a value between 0x00 and 0x0F. |
mbed_official | 87:085cde657901 | 4776 | * @retval None |
mbed_official | 87:085cde657901 | 4777 | */ |
mbed_official | 87:085cde657901 | 4778 | static void TIM_TI2_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection, |
mbed_official | 87:085cde657901 | 4779 | uint32_t TIM_ICFilter) |
mbed_official | 87:085cde657901 | 4780 | { |
mbed_official | 87:085cde657901 | 4781 | uint32_t tmpccmr1 = 0; |
mbed_official | 87:085cde657901 | 4782 | uint32_t tmpccer = 0; |
mbed_official | 87:085cde657901 | 4783 | |
mbed_official | 87:085cde657901 | 4784 | /* Disable the Channel 2: Reset the CC2E Bit */ |
mbed_official | 87:085cde657901 | 4785 | TIMx->CCER &= ~TIM_CCER_CC2E; |
mbed_official | 87:085cde657901 | 4786 | tmpccmr1 = TIMx->CCMR1; |
mbed_official | 87:085cde657901 | 4787 | tmpccer = TIMx->CCER; |
mbed_official | 87:085cde657901 | 4788 | |
mbed_official | 87:085cde657901 | 4789 | /* Select the Input */ |
mbed_official | 87:085cde657901 | 4790 | tmpccmr1 &= ~TIM_CCMR1_CC2S; |
mbed_official | 87:085cde657901 | 4791 | tmpccmr1 |= (TIM_ICSelection << 8); |
mbed_official | 87:085cde657901 | 4792 | |
mbed_official | 87:085cde657901 | 4793 | /* Set the filter */ |
mbed_official | 87:085cde657901 | 4794 | tmpccmr1 &= ~TIM_CCMR1_IC2F; |
mbed_official | 87:085cde657901 | 4795 | tmpccmr1 |= (TIM_ICFilter << 12); |
mbed_official | 87:085cde657901 | 4796 | |
mbed_official | 87:085cde657901 | 4797 | /* Select the Polarity and set the CC2E Bit */ |
mbed_official | 87:085cde657901 | 4798 | tmpccer &= ~(TIM_CCER_CC2P | TIM_CCER_CC2NP); |
mbed_official | 87:085cde657901 | 4799 | tmpccer |= (TIM_ICPolarity << 4); |
mbed_official | 87:085cde657901 | 4800 | |
mbed_official | 87:085cde657901 | 4801 | /* Write to TIMx CCMR1 and CCER registers */ |
mbed_official | 87:085cde657901 | 4802 | TIMx->CCMR1 = tmpccmr1 ; |
mbed_official | 87:085cde657901 | 4803 | TIMx->CCER = tmpccer; |
mbed_official | 87:085cde657901 | 4804 | } |
mbed_official | 87:085cde657901 | 4805 | |
mbed_official | 87:085cde657901 | 4806 | /** |
mbed_official | 87:085cde657901 | 4807 | * @brief Configure the Polarity and Filter for TI2. |
mbed_official | 87:085cde657901 | 4808 | * @param TIMx to select the TIM peripheral. |
mbed_official | 87:085cde657901 | 4809 | * @param TIM_ICPolarity : The Input Polarity. |
mbed_official | 87:085cde657901 | 4810 | * This parameter can be one of the following values: |
mbed_official | 87:085cde657901 | 4811 | * @arg TIM_ICPolarity_Rising |
mbed_official | 87:085cde657901 | 4812 | * @arg TIM_ICPolarity_Falling |
mbed_official | 87:085cde657901 | 4813 | * @arg TIM_ICPolarity_BothEdge |
mbed_official | 87:085cde657901 | 4814 | * @param TIM_ICFilter: Specifies the Input Capture Filter. |
mbed_official | 87:085cde657901 | 4815 | * This parameter must be a value between 0x00 and 0x0F. |
mbed_official | 87:085cde657901 | 4816 | * @retval None |
mbed_official | 87:085cde657901 | 4817 | */ |
mbed_official | 87:085cde657901 | 4818 | static void TIM_TI2_ConfigInputStage(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICFilter) |
mbed_official | 87:085cde657901 | 4819 | { |
mbed_official | 87:085cde657901 | 4820 | uint32_t tmpccmr1 = 0; |
mbed_official | 87:085cde657901 | 4821 | uint32_t tmpccer = 0; |
mbed_official | 87:085cde657901 | 4822 | |
mbed_official | 87:085cde657901 | 4823 | /* Disable the Channel 2: Reset the CC2E Bit */ |
mbed_official | 87:085cde657901 | 4824 | TIMx->CCER &= ~TIM_CCER_CC2E; |
mbed_official | 87:085cde657901 | 4825 | tmpccmr1 = TIMx->CCMR1; |
mbed_official | 87:085cde657901 | 4826 | tmpccer = TIMx->CCER; |
mbed_official | 87:085cde657901 | 4827 | |
mbed_official | 87:085cde657901 | 4828 | /* Set the filter */ |
mbed_official | 87:085cde657901 | 4829 | tmpccmr1 &= ~TIM_CCMR1_IC2F; |
mbed_official | 87:085cde657901 | 4830 | tmpccmr1 |= (TIM_ICFilter << 12); |
mbed_official | 87:085cde657901 | 4831 | |
mbed_official | 87:085cde657901 | 4832 | /* Select the Polarity and set the CC2E Bit */ |
mbed_official | 87:085cde657901 | 4833 | tmpccer &= ~(TIM_CCER_CC2P | TIM_CCER_CC2NP); |
mbed_official | 87:085cde657901 | 4834 | tmpccer |= (TIM_ICPolarity << 4); |
mbed_official | 87:085cde657901 | 4835 | |
mbed_official | 87:085cde657901 | 4836 | /* Write to TIMx CCMR1 and CCER registers */ |
mbed_official | 87:085cde657901 | 4837 | TIMx->CCMR1 = tmpccmr1 ; |
mbed_official | 87:085cde657901 | 4838 | TIMx->CCER = tmpccer; |
mbed_official | 87:085cde657901 | 4839 | } |
mbed_official | 87:085cde657901 | 4840 | |
mbed_official | 87:085cde657901 | 4841 | /** |
mbed_official | 87:085cde657901 | 4842 | * @brief Configure the TI3 as Input. |
mbed_official | 87:085cde657901 | 4843 | * @param TIMx to select the TIM peripheral |
mbed_official | 87:085cde657901 | 4844 | * @param TIM_ICPolarity : The Input Polarity. |
mbed_official | 87:085cde657901 | 4845 | * This parameter can be one of the following values: |
mbed_official | 87:085cde657901 | 4846 | * @arg TIM_ICPolarity_Rising |
mbed_official | 87:085cde657901 | 4847 | * @arg TIM_ICPolarity_Falling |
mbed_official | 87:085cde657901 | 4848 | * @arg TIM_ICPolarity_BothEdge |
mbed_official | 87:085cde657901 | 4849 | * @param TIM_ICSelection: specifies the input to be used. |
mbed_official | 87:085cde657901 | 4850 | * This parameter can be one of the following values: |
mbed_official | 87:085cde657901 | 4851 | * @arg TIM_ICSelection_DirectTI: TIM Input 3 is selected to be connected to IC3. |
mbed_official | 87:085cde657901 | 4852 | * @arg TIM_ICSelection_IndirectTI: TIM Input 3 is selected to be connected to IC4. |
mbed_official | 87:085cde657901 | 4853 | * @arg TIM_ICSelection_TRC: TIM Input 3 is selected to be connected to TRC. |
mbed_official | 87:085cde657901 | 4854 | * @param TIM_ICFilter: Specifies the Input Capture Filter. |
mbed_official | 87:085cde657901 | 4855 | * This parameter must be a value between 0x00 and 0x0F. |
mbed_official | 87:085cde657901 | 4856 | * @retval None |
mbed_official | 87:085cde657901 | 4857 | */ |
mbed_official | 87:085cde657901 | 4858 | static void TIM_TI3_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection, |
mbed_official | 87:085cde657901 | 4859 | uint32_t TIM_ICFilter) |
mbed_official | 87:085cde657901 | 4860 | { |
mbed_official | 87:085cde657901 | 4861 | uint32_t tmpccmr2 = 0; |
mbed_official | 87:085cde657901 | 4862 | uint32_t tmpccer = 0; |
mbed_official | 87:085cde657901 | 4863 | |
mbed_official | 87:085cde657901 | 4864 | /* Disable the Channel 3: Reset the CC3E Bit */ |
mbed_official | 87:085cde657901 | 4865 | TIMx->CCER &= ~TIM_CCER_CC3E; |
mbed_official | 87:085cde657901 | 4866 | tmpccmr2 = TIMx->CCMR2; |
mbed_official | 87:085cde657901 | 4867 | tmpccer = TIMx->CCER; |
mbed_official | 87:085cde657901 | 4868 | |
mbed_official | 87:085cde657901 | 4869 | /* Select the Input */ |
mbed_official | 87:085cde657901 | 4870 | tmpccmr2 &= ~TIM_CCMR2_CC3S; |
mbed_official | 87:085cde657901 | 4871 | tmpccmr2 |= TIM_ICSelection; |
mbed_official | 87:085cde657901 | 4872 | |
mbed_official | 87:085cde657901 | 4873 | /* Set the filter */ |
mbed_official | 87:085cde657901 | 4874 | tmpccmr2 &= ~TIM_CCMR2_IC3F; |
mbed_official | 87:085cde657901 | 4875 | tmpccmr2 |= (TIM_ICFilter << 4); |
mbed_official | 87:085cde657901 | 4876 | |
mbed_official | 87:085cde657901 | 4877 | /* Select the Polarity and set the CC3E Bit */ |
mbed_official | 87:085cde657901 | 4878 | tmpccer &= ~(TIM_CCER_CC3P | TIM_CCER_CC3NP); |
mbed_official | 87:085cde657901 | 4879 | tmpccer |= (TIM_ICPolarity << 8); |
mbed_official | 87:085cde657901 | 4880 | |
mbed_official | 87:085cde657901 | 4881 | /* Write to TIMx CCMR2 and CCER registers */ |
mbed_official | 87:085cde657901 | 4882 | TIMx->CCMR2 = tmpccmr2; |
mbed_official | 87:085cde657901 | 4883 | TIMx->CCER = tmpccer; |
mbed_official | 87:085cde657901 | 4884 | } |
mbed_official | 87:085cde657901 | 4885 | |
mbed_official | 87:085cde657901 | 4886 | /** |
mbed_official | 87:085cde657901 | 4887 | * @brief Configure the TI4 as Input. |
mbed_official | 87:085cde657901 | 4888 | * @param TIMx to select the TIM peripheral |
mbed_official | 87:085cde657901 | 4889 | * @param TIM_ICPolarity : The Input Polarity. |
mbed_official | 87:085cde657901 | 4890 | * This parameter can be one of the following values: |
mbed_official | 87:085cde657901 | 4891 | * @arg TIM_ICPolarity_Rising |
mbed_official | 87:085cde657901 | 4892 | * @arg TIM_ICPolarity_Falling |
mbed_official | 87:085cde657901 | 4893 | * @arg TIM_ICPolarity_BothEdge |
mbed_official | 87:085cde657901 | 4894 | * @param TIM_ICSelection: specifies the input to be used. |
mbed_official | 87:085cde657901 | 4895 | * This parameter can be one of the following values: |
mbed_official | 87:085cde657901 | 4896 | * @arg TIM_ICSelection_DirectTI: TIM Input 4 is selected to be connected to IC4. |
mbed_official | 87:085cde657901 | 4897 | * @arg TIM_ICSelection_IndirectTI: TIM Input 4 is selected to be connected to IC3. |
mbed_official | 87:085cde657901 | 4898 | * @arg TIM_ICSelection_TRC: TIM Input 4 is selected to be connected to TRC. |
mbed_official | 87:085cde657901 | 4899 | * @param TIM_ICFilter: Specifies the Input Capture Filter. |
mbed_official | 87:085cde657901 | 4900 | * This parameter must be a value between 0x00 and 0x0F. |
mbed_official | 87:085cde657901 | 4901 | * @retval None |
mbed_official | 87:085cde657901 | 4902 | */ |
mbed_official | 87:085cde657901 | 4903 | static void TIM_TI4_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection, |
mbed_official | 87:085cde657901 | 4904 | uint32_t TIM_ICFilter) |
mbed_official | 87:085cde657901 | 4905 | { |
mbed_official | 87:085cde657901 | 4906 | uint32_t tmpccmr2 = 0; |
mbed_official | 87:085cde657901 | 4907 | uint32_t tmpccer = 0; |
mbed_official | 87:085cde657901 | 4908 | |
mbed_official | 87:085cde657901 | 4909 | /* Disable the Channel 4: Reset the CC4E Bit */ |
mbed_official | 87:085cde657901 | 4910 | TIMx->CCER &= ~TIM_CCER_CC4E; |
mbed_official | 87:085cde657901 | 4911 | tmpccmr2 = TIMx->CCMR2; |
mbed_official | 87:085cde657901 | 4912 | tmpccer = TIMx->CCER; |
mbed_official | 87:085cde657901 | 4913 | |
mbed_official | 87:085cde657901 | 4914 | /* Select the Input */ |
mbed_official | 87:085cde657901 | 4915 | tmpccmr2 &= ~TIM_CCMR2_CC4S; |
mbed_official | 87:085cde657901 | 4916 | tmpccmr2 |= (TIM_ICSelection << 8); |
mbed_official | 87:085cde657901 | 4917 | |
mbed_official | 87:085cde657901 | 4918 | /* Set the filter */ |
mbed_official | 87:085cde657901 | 4919 | tmpccmr2 &= ~TIM_CCMR2_IC4F; |
mbed_official | 87:085cde657901 | 4920 | tmpccmr2 |= (TIM_ICFilter << 12); |
mbed_official | 87:085cde657901 | 4921 | |
mbed_official | 87:085cde657901 | 4922 | /* Select the Polarity and set the CC4E Bit */ |
mbed_official | 87:085cde657901 | 4923 | tmpccer &= ~(TIM_CCER_CC4P | TIM_CCER_CC4NP); |
mbed_official | 87:085cde657901 | 4924 | tmpccer |= (TIM_ICPolarity << 12); |
mbed_official | 87:085cde657901 | 4925 | |
mbed_official | 87:085cde657901 | 4926 | /* Write to TIMx CCMR2 and CCER registers */ |
mbed_official | 87:085cde657901 | 4927 | TIMx->CCMR2 = tmpccmr2; |
mbed_official | 87:085cde657901 | 4928 | TIMx->CCER = tmpccer ; |
mbed_official | 87:085cde657901 | 4929 | } |
mbed_official | 87:085cde657901 | 4930 | |
mbed_official | 87:085cde657901 | 4931 | /** |
mbed_official | 87:085cde657901 | 4932 | * @brief Selects the Input Trigger source |
mbed_official | 87:085cde657901 | 4933 | * @param TIMx to select the TIM peripheral |
mbed_official | 87:085cde657901 | 4934 | * @param InputTriggerSource: The Input Trigger source. |
mbed_official | 87:085cde657901 | 4935 | * This parameter can be one of the following values: |
mbed_official | 87:085cde657901 | 4936 | * @arg TIM_TS_ITR0: Internal Trigger 0 |
mbed_official | 87:085cde657901 | 4937 | * @arg TIM_TS_ITR1: Internal Trigger 1 |
mbed_official | 87:085cde657901 | 4938 | * @arg TIM_TS_ITR2: Internal Trigger 2 |
mbed_official | 87:085cde657901 | 4939 | * @arg TIM_TS_ITR3: Internal Trigger 3 |
mbed_official | 87:085cde657901 | 4940 | * @arg TIM_TS_TI1F_ED: TI1 Edge Detector |
mbed_official | 87:085cde657901 | 4941 | * @arg TIM_TS_TI1FP1: Filtered Timer Input 1 |
mbed_official | 87:085cde657901 | 4942 | * @arg TIM_TS_TI2FP2: Filtered Timer Input 2 |
mbed_official | 87:085cde657901 | 4943 | * @arg TIM_TS_ETRF: External Trigger input |
mbed_official | 87:085cde657901 | 4944 | * @retval None |
mbed_official | 87:085cde657901 | 4945 | */ |
mbed_official | 87:085cde657901 | 4946 | static void TIM_ITRx_SetConfig(TIM_TypeDef *TIMx, uint16_t TIM_ITRx) |
mbed_official | 87:085cde657901 | 4947 | { |
mbed_official | 87:085cde657901 | 4948 | uint32_t tmpsmcr = 0; |
mbed_official | 87:085cde657901 | 4949 | |
mbed_official | 87:085cde657901 | 4950 | /* Get the TIMx SMCR register value */ |
mbed_official | 87:085cde657901 | 4951 | tmpsmcr = TIMx->SMCR; |
mbed_official | 87:085cde657901 | 4952 | /* Reset the TS Bits */ |
mbed_official | 87:085cde657901 | 4953 | tmpsmcr &= ~TIM_SMCR_TS; |
mbed_official | 87:085cde657901 | 4954 | /* Set the Input Trigger source and the slave mode*/ |
mbed_official | 87:085cde657901 | 4955 | tmpsmcr |= TIM_ITRx | TIM_SLAVEMODE_EXTERNAL1; |
mbed_official | 87:085cde657901 | 4956 | /* Write to TIMx SMCR */ |
mbed_official | 87:085cde657901 | 4957 | TIMx->SMCR = tmpsmcr; |
mbed_official | 87:085cde657901 | 4958 | } |
mbed_official | 87:085cde657901 | 4959 | /** |
mbed_official | 87:085cde657901 | 4960 | * @brief Configures the TIMx External Trigger (ETR). |
mbed_official | 87:085cde657901 | 4961 | * @param TIMx to select the TIM peripheral |
mbed_official | 87:085cde657901 | 4962 | * @param TIM_ExtTRGPrescaler: The external Trigger Prescaler. |
mbed_official | 87:085cde657901 | 4963 | * This parameter can be one of the following values: |
mbed_official | 87:085cde657901 | 4964 | * @arg TIM_ExtTRGPSC_DIV1: ETRP Prescaler OFF. |
mbed_official | 87:085cde657901 | 4965 | * @arg TIM_ExtTRGPSC_DIV2: ETRP frequency divided by 2. |
mbed_official | 87:085cde657901 | 4966 | * @arg TIM_ExtTRGPSC_DIV4: ETRP frequency divided by 4. |
mbed_official | 87:085cde657901 | 4967 | * @arg TIM_ExtTRGPSC_DIV8: ETRP frequency divided by 8. |
mbed_official | 87:085cde657901 | 4968 | * @param TIM_ExtTRGPolarity: The external Trigger Polarity. |
mbed_official | 87:085cde657901 | 4969 | * This parameter can be one of the following values: |
mbed_official | 87:085cde657901 | 4970 | * @arg TIM_ExtTRGPolarity_Inverted: active low or falling edge active. |
mbed_official | 87:085cde657901 | 4971 | * @arg TIM_ExtTRGPolarity_NonInverted: active high or rising edge active. |
mbed_official | 87:085cde657901 | 4972 | * @param ExtTRGFilter: External Trigger Filter. |
mbed_official | 87:085cde657901 | 4973 | * This parameter must be a value between 0x00 and 0x0F |
mbed_official | 87:085cde657901 | 4974 | * @retval None |
mbed_official | 87:085cde657901 | 4975 | */ |
mbed_official | 87:085cde657901 | 4976 | static void TIM_ETR_SetConfig(TIM_TypeDef* TIMx, uint32_t TIM_ExtTRGPrescaler, |
mbed_official | 87:085cde657901 | 4977 | uint32_t TIM_ExtTRGPolarity, uint32_t ExtTRGFilter) |
mbed_official | 87:085cde657901 | 4978 | { |
mbed_official | 87:085cde657901 | 4979 | uint32_t tmpsmcr = 0; |
mbed_official | 87:085cde657901 | 4980 | |
mbed_official | 87:085cde657901 | 4981 | tmpsmcr = TIMx->SMCR; |
mbed_official | 87:085cde657901 | 4982 | |
mbed_official | 87:085cde657901 | 4983 | /* Reset the ETR Bits */ |
mbed_official | 87:085cde657901 | 4984 | tmpsmcr &= ~(TIM_SMCR_ETF | TIM_SMCR_ETPS | TIM_SMCR_ECE | TIM_SMCR_ETP); |
mbed_official | 87:085cde657901 | 4985 | |
mbed_official | 87:085cde657901 | 4986 | /* Set the Prescaler, the Filter value and the Polarity */ |
mbed_official | 87:085cde657901 | 4987 | tmpsmcr |= (uint32_t)(TIM_ExtTRGPrescaler | (TIM_ExtTRGPolarity | (ExtTRGFilter << 8))); |
mbed_official | 87:085cde657901 | 4988 | |
mbed_official | 87:085cde657901 | 4989 | /* Write to TIMx SMCR */ |
mbed_official | 87:085cde657901 | 4990 | TIMx->SMCR = tmpsmcr; |
mbed_official | 87:085cde657901 | 4991 | } |
mbed_official | 87:085cde657901 | 4992 | |
mbed_official | 87:085cde657901 | 4993 | /** |
mbed_official | 87:085cde657901 | 4994 | * @brief Enables or disables the TIM Capture Compare Channel x. |
mbed_official | 87:085cde657901 | 4995 | * @param TIMx to select the TIM peripheral |
mbed_official | 87:085cde657901 | 4996 | * @param Channel: specifies the TIM Channel |
mbed_official | 87:085cde657901 | 4997 | * This parameter can be one of the following values: |
mbed_official | 87:085cde657901 | 4998 | * @arg TIM_Channel_1: TIM Channel 1 |
mbed_official | 87:085cde657901 | 4999 | * @arg TIM_Channel_2: TIM Channel 2 |
mbed_official | 87:085cde657901 | 5000 | * @arg TIM_Channel_3: TIM Channel 3 |
mbed_official | 87:085cde657901 | 5001 | * @arg TIM_Channel_4: TIM Channel 4 |
mbed_official | 87:085cde657901 | 5002 | * @param ChannelState: specifies the TIM Channel CCxE bit new state. |
mbed_official | 87:085cde657901 | 5003 | * This parameter can be: TIM_CCx_ENABLE or TIM_CCx_Disable. |
mbed_official | 87:085cde657901 | 5004 | * @retval None |
mbed_official | 87:085cde657901 | 5005 | */ |
mbed_official | 87:085cde657901 | 5006 | void TIM_CCxChannelCmd(TIM_TypeDef* TIMx, uint32_t Channel, uint32_t ChannelState) |
mbed_official | 87:085cde657901 | 5007 | { |
mbed_official | 87:085cde657901 | 5008 | uint32_t tmp = 0; |
mbed_official | 87:085cde657901 | 5009 | |
mbed_official | 87:085cde657901 | 5010 | /* Check the parameters */ |
mbed_official | 87:085cde657901 | 5011 | assert_param(IS_TIM_CC1_INSTANCE(TIMx)); |
mbed_official | 87:085cde657901 | 5012 | assert_param(IS_TIM_CHANNELS(Channel)); |
mbed_official | 87:085cde657901 | 5013 | |
mbed_official | 87:085cde657901 | 5014 | tmp = TIM_CCER_CC1E << Channel; |
mbed_official | 87:085cde657901 | 5015 | |
mbed_official | 87:085cde657901 | 5016 | /* Reset the CCxE Bit */ |
mbed_official | 87:085cde657901 | 5017 | TIMx->CCER &= ~tmp; |
mbed_official | 87:085cde657901 | 5018 | |
mbed_official | 87:085cde657901 | 5019 | /* Set or reset the CCxE Bit */ |
mbed_official | 87:085cde657901 | 5020 | TIMx->CCER |= (uint32_t)(ChannelState << Channel); |
mbed_official | 87:085cde657901 | 5021 | } |
mbed_official | 87:085cde657901 | 5022 | |
mbed_official | 87:085cde657901 | 5023 | |
mbed_official | 87:085cde657901 | 5024 | /** |
mbed_official | 87:085cde657901 | 5025 | * @} |
mbed_official | 87:085cde657901 | 5026 | */ |
mbed_official | 87:085cde657901 | 5027 | |
mbed_official | 87:085cde657901 | 5028 | #endif /* HAL_TIM_MODULE_ENABLED */ |
mbed_official | 87:085cde657901 | 5029 | /** |
mbed_official | 87:085cde657901 | 5030 | * @} |
mbed_official | 87:085cde657901 | 5031 | */ |
mbed_official | 87:085cde657901 | 5032 | |
mbed_official | 87:085cde657901 | 5033 | /** |
mbed_official | 87:085cde657901 | 5034 | * @} |
mbed_official | 87:085cde657901 | 5035 | */ |
mbed_official | 87:085cde657901 | 5036 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |