186 #include "stm32f4xx_hal.h"
197 #ifdef HAL_TIM_MODULE_ENABLED
210 static void TIM_TI1_ConfigInputStage(
TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICFilter);
211 static void TIM_TI2_SetConfig(
TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection,
212 uint32_t TIM_ICFilter);
213 static void TIM_TI2_ConfigInputStage(
TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICFilter);
214 static void TIM_TI3_SetConfig(
TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection,
215 uint32_t TIM_ICFilter);
216 static void TIM_TI4_SetConfig(
TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection,
217 uint32_t TIM_ICFilter);
218 static void TIM_ITRx_SetConfig(
TIM_TypeDef *TIMx, uint32_t InputTriggerSource);
284 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
286 TIM_ResetCallback(htim);
288 if (htim->Base_MspInitCallback ==
NULL)
293 htim->Base_MspInitCallback(htim);
327 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
328 if (htim->Base_MspDeInitCallback ==
NULL)
333 htim->Base_MspDeInitCallback(htim);
496 if ((pData ==
NULL) && (Length > 0U))
616 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
618 TIM_ResetCallback(htim);
620 if (htim->OC_MspInitCallback ==
NULL)
625 htim->OC_MspInitCallback(htim);
659 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
660 if (htim->OC_MspDeInitCallback ==
NULL)
665 htim->OC_MspDeInitCallback(htim);
944 if ((pData ==
NULL) && (Length > 0U))
1189 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
1191 TIM_ResetCallback(htim);
1193 if (htim->PWM_MspInitCallback ==
NULL)
1198 htim->PWM_MspInitCallback(htim);
1232 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
1233 if (htim->PWM_MspDeInitCallback ==
NULL)
1238 htim->PWM_MspDeInitCallback(htim);
1519 if ((pData ==
NULL) && (Length > 0U))
1763 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
1765 TIM_ResetCallback(htim);
1767 if (htim->IC_MspInitCallback ==
NULL)
1772 htim->IC_MspInitCallback(htim);
1806 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
1807 if (htim->IC_MspDeInitCallback ==
NULL)
1812 htim->IC_MspDeInitCallback(htim);
2067 if ((pData ==
NULL) && (Length > 0U))
2303 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
2305 TIM_ResetCallback(htim);
2307 if (htim->OnePulse_MspInitCallback ==
NULL)
2312 htim->OnePulse_MspInitCallback(htim);
2352 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
2353 if (htim->OnePulse_MspDeInitCallback ==
NULL)
2358 htim->OnePulse_MspDeInitCallback(htim);
2628 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
2630 TIM_ResetCallback(htim);
2632 if (htim->Encoder_MspInitCallback ==
NULL)
2637 htim->Encoder_MspInitCallback(htim);
2711 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
2712 if (htim->Encoder_MspDeInitCallback ==
NULL)
2717 htim->Encoder_MspDeInitCallback(htim);
2967 uint32_t *pData2, uint16_t Length)
2978 if ((((pData1 ==
NULL) || (pData2 ==
NULL))) && (Length > 0U))
3181 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
3182 htim->IC_CaptureCallback(htim);
3190 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
3191 htim->OC_DelayElapsedCallback(htim);
3192 htim->PWM_PulseFinishedCallback(htim);
3212 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
3213 htim->IC_CaptureCallback(htim);
3221 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
3222 htim->OC_DelayElapsedCallback(htim);
3223 htim->PWM_PulseFinishedCallback(htim);
3242 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
3243 htim->IC_CaptureCallback(htim);
3251 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
3252 htim->OC_DelayElapsedCallback(htim);
3253 htim->PWM_PulseFinishedCallback(htim);
3272 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
3273 htim->IC_CaptureCallback(htim);
3281 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
3282 htim->OC_DelayElapsedCallback(htim);
3283 htim->PWM_PulseFinishedCallback(htim);
3298 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
3299 htim->PeriodElapsedCallback(htim);
3311 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
3312 htim->BreakCallback(htim);
3324 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
3325 htim->TriggerCallback(htim);
3337 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
3338 htim->CommutationCallback(htim);
3404 TIM_OC1_SetConfig(htim->
Instance, sConfig);
3424 TIM_OC3_SetConfig(htim->
Instance, sConfig);
3434 TIM_OC4_SetConfig(htim->
Instance, sConfig);
3582 TIM_OC1_SetConfig(htim->
Instance, sConfig);
3616 TIM_OC3_SetConfig(htim->
Instance, sConfig);
3633 TIM_OC4_SetConfig(htim->
Instance, sConfig);
3675 uint32_t OutputChannel, uint32_t InputChannel)
3683 if (OutputChannel != InputChannel)
3698 switch (OutputChannel)
3704 TIM_OC1_SetConfig(htim->
Instance, &temp1);
3718 switch (InputChannel)
3814 uint32_t *BurstBuffer, uint32_t BurstLength)
3828 if ((BurstBuffer ==
NULL) && (BurstLength > 0U))
3841 switch (BurstRequestSrc)
3965 htim->
Instance->
DCR = (BurstBaseAddress | BurstLength);
3989 switch (BurstRequestSrc)
4079 uint32_t BurstRequestSrc, uint32_t *BurstBuffer, uint32_t BurstLength)
4093 if ((BurstBuffer ==
NULL) && (BurstLength > 0U))
4106 switch (BurstRequestSrc)
4225 htim->
Instance->
DCR = (BurstBaseAddress | BurstLength);
4249 switch (BurstRequestSrc)
4560 TIM_TI1_ConfigInputStage(htim->
Instance,
4576 TIM_TI2_ConfigInputStage(htim->
Instance,
4592 TIM_TI1_ConfigInputStage(htim->
Instance,
4648 tmpcr2 |= TI1_Selection;
4676 if (TIM_SlaveTimer_SetConfig(htim, sSlaveConfig) !=
HAL_OK)
4717 if (TIM_SlaveTimer_SetConfig(htim, sSlaveConfig) !=
HAL_OK)
4750 uint32_t tmpreg = 0U;
4977 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
5014 pTIM_CallbackTypeDef pCallback)
5018 if (pCallback ==
NULL)
5029 case HAL_TIM_BASE_MSPINIT_CB_ID :
5030 htim->Base_MspInitCallback = pCallback;
5033 case HAL_TIM_BASE_MSPDEINIT_CB_ID :
5034 htim->Base_MspDeInitCallback = pCallback;
5037 case HAL_TIM_IC_MSPINIT_CB_ID :
5038 htim->IC_MspInitCallback = pCallback;
5041 case HAL_TIM_IC_MSPDEINIT_CB_ID :
5042 htim->IC_MspDeInitCallback = pCallback;
5045 case HAL_TIM_OC_MSPINIT_CB_ID :
5046 htim->OC_MspInitCallback = pCallback;
5049 case HAL_TIM_OC_MSPDEINIT_CB_ID :
5050 htim->OC_MspDeInitCallback = pCallback;
5053 case HAL_TIM_PWM_MSPINIT_CB_ID :
5054 htim->PWM_MspInitCallback = pCallback;
5057 case HAL_TIM_PWM_MSPDEINIT_CB_ID :
5058 htim->PWM_MspDeInitCallback = pCallback;
5061 case HAL_TIM_ONE_PULSE_MSPINIT_CB_ID :
5062 htim->OnePulse_MspInitCallback = pCallback;
5065 case HAL_TIM_ONE_PULSE_MSPDEINIT_CB_ID :
5066 htim->OnePulse_MspDeInitCallback = pCallback;
5069 case HAL_TIM_ENCODER_MSPINIT_CB_ID :
5070 htim->Encoder_MspInitCallback = pCallback;
5073 case HAL_TIM_ENCODER_MSPDEINIT_CB_ID :
5074 htim->Encoder_MspDeInitCallback = pCallback;
5077 case HAL_TIM_HALL_SENSOR_MSPINIT_CB_ID :
5078 htim->HallSensor_MspInitCallback = pCallback;
5081 case HAL_TIM_HALL_SENSOR_MSPDEINIT_CB_ID :
5082 htim->HallSensor_MspDeInitCallback = pCallback;
5085 case HAL_TIM_PERIOD_ELAPSED_CB_ID :
5086 htim->PeriodElapsedCallback = pCallback;
5089 case HAL_TIM_PERIOD_ELAPSED_HALF_CB_ID :
5090 htim->PeriodElapsedHalfCpltCallback = pCallback;
5093 case HAL_TIM_TRIGGER_CB_ID :
5094 htim->TriggerCallback = pCallback;
5097 case HAL_TIM_TRIGGER_HALF_CB_ID :
5098 htim->TriggerHalfCpltCallback = pCallback;
5101 case HAL_TIM_IC_CAPTURE_CB_ID :
5102 htim->IC_CaptureCallback = pCallback;
5105 case HAL_TIM_IC_CAPTURE_HALF_CB_ID :
5106 htim->IC_CaptureHalfCpltCallback = pCallback;
5109 case HAL_TIM_OC_DELAY_ELAPSED_CB_ID :
5110 htim->OC_DelayElapsedCallback = pCallback;
5113 case HAL_TIM_PWM_PULSE_FINISHED_CB_ID :
5114 htim->PWM_PulseFinishedCallback = pCallback;
5117 case HAL_TIM_PWM_PULSE_FINISHED_HALF_CB_ID :
5118 htim->PWM_PulseFinishedHalfCpltCallback = pCallback;
5121 case HAL_TIM_ERROR_CB_ID :
5122 htim->ErrorCallback = pCallback;
5125 case HAL_TIM_COMMUTATION_CB_ID :
5126 htim->CommutationCallback = pCallback;
5129 case HAL_TIM_COMMUTATION_HALF_CB_ID :
5130 htim->CommutationHalfCpltCallback = pCallback;
5133 case HAL_TIM_BREAK_CB_ID :
5134 htim->BreakCallback = pCallback;
5147 case HAL_TIM_BASE_MSPINIT_CB_ID :
5148 htim->Base_MspInitCallback = pCallback;
5151 case HAL_TIM_BASE_MSPDEINIT_CB_ID :
5152 htim->Base_MspDeInitCallback = pCallback;
5155 case HAL_TIM_IC_MSPINIT_CB_ID :
5156 htim->IC_MspInitCallback = pCallback;
5159 case HAL_TIM_IC_MSPDEINIT_CB_ID :
5160 htim->IC_MspDeInitCallback = pCallback;
5163 case HAL_TIM_OC_MSPINIT_CB_ID :
5164 htim->OC_MspInitCallback = pCallback;
5167 case HAL_TIM_OC_MSPDEINIT_CB_ID :
5168 htim->OC_MspDeInitCallback = pCallback;
5171 case HAL_TIM_PWM_MSPINIT_CB_ID :
5172 htim->PWM_MspInitCallback = pCallback;
5175 case HAL_TIM_PWM_MSPDEINIT_CB_ID :
5176 htim->PWM_MspDeInitCallback = pCallback;
5179 case HAL_TIM_ONE_PULSE_MSPINIT_CB_ID :
5180 htim->OnePulse_MspInitCallback = pCallback;
5183 case HAL_TIM_ONE_PULSE_MSPDEINIT_CB_ID :
5184 htim->OnePulse_MspDeInitCallback = pCallback;
5187 case HAL_TIM_ENCODER_MSPINIT_CB_ID :
5188 htim->Encoder_MspInitCallback = pCallback;
5191 case HAL_TIM_ENCODER_MSPDEINIT_CB_ID :
5192 htim->Encoder_MspDeInitCallback = pCallback;
5195 case HAL_TIM_HALL_SENSOR_MSPINIT_CB_ID :
5196 htim->HallSensor_MspInitCallback = pCallback;
5199 case HAL_TIM_HALL_SENSOR_MSPDEINIT_CB_ID :
5200 htim->HallSensor_MspDeInitCallback = pCallback;
5267 case HAL_TIM_BASE_MSPINIT_CB_ID :
5271 case HAL_TIM_BASE_MSPDEINIT_CB_ID :
5275 case HAL_TIM_IC_MSPINIT_CB_ID :
5279 case HAL_TIM_IC_MSPDEINIT_CB_ID :
5283 case HAL_TIM_OC_MSPINIT_CB_ID :
5287 case HAL_TIM_OC_MSPDEINIT_CB_ID :
5291 case HAL_TIM_PWM_MSPINIT_CB_ID :
5295 case HAL_TIM_PWM_MSPDEINIT_CB_ID :
5299 case HAL_TIM_ONE_PULSE_MSPINIT_CB_ID :
5303 case HAL_TIM_ONE_PULSE_MSPDEINIT_CB_ID :
5307 case HAL_TIM_ENCODER_MSPINIT_CB_ID :
5311 case HAL_TIM_ENCODER_MSPDEINIT_CB_ID :
5315 case HAL_TIM_HALL_SENSOR_MSPINIT_CB_ID :
5319 case HAL_TIM_HALL_SENSOR_MSPDEINIT_CB_ID :
5323 case HAL_TIM_PERIOD_ELAPSED_CB_ID :
5327 case HAL_TIM_PERIOD_ELAPSED_HALF_CB_ID :
5331 case HAL_TIM_TRIGGER_CB_ID :
5335 case HAL_TIM_TRIGGER_HALF_CB_ID :
5339 case HAL_TIM_IC_CAPTURE_CB_ID :
5343 case HAL_TIM_IC_CAPTURE_HALF_CB_ID :
5347 case HAL_TIM_OC_DELAY_ELAPSED_CB_ID :
5351 case HAL_TIM_PWM_PULSE_FINISHED_CB_ID :
5355 case HAL_TIM_PWM_PULSE_FINISHED_HALF_CB_ID :
5359 case HAL_TIM_ERROR_CB_ID :
5363 case HAL_TIM_COMMUTATION_CB_ID :
5367 case HAL_TIM_COMMUTATION_HALF_CB_ID :
5371 case HAL_TIM_BREAK_CB_ID :
5385 case HAL_TIM_BASE_MSPINIT_CB_ID :
5389 case HAL_TIM_BASE_MSPDEINIT_CB_ID :
5393 case HAL_TIM_IC_MSPINIT_CB_ID :
5397 case HAL_TIM_IC_MSPDEINIT_CB_ID :
5401 case HAL_TIM_OC_MSPINIT_CB_ID :
5405 case HAL_TIM_OC_MSPDEINIT_CB_ID :
5409 case HAL_TIM_PWM_MSPINIT_CB_ID :
5413 case HAL_TIM_PWM_MSPDEINIT_CB_ID :
5417 case HAL_TIM_ONE_PULSE_MSPINIT_CB_ID :
5421 case HAL_TIM_ONE_PULSE_MSPDEINIT_CB_ID :
5425 case HAL_TIM_ENCODER_MSPINIT_CB_ID :
5429 case HAL_TIM_ENCODER_MSPDEINIT_CB_ID :
5433 case HAL_TIM_HALL_SENSOR_MSPINIT_CB_ID :
5437 case HAL_TIM_HALL_SENSOR_MSPDEINIT_CB_ID :
5562 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
5563 htim->ErrorCallback(htim);
5601 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
5602 htim->PWM_PulseFinishedCallback(htim);
5642 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
5643 htim->PWM_PulseFinishedHalfCpltCallback(htim);
5683 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
5684 htim->IC_CaptureCallback(htim);
5724 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
5725 htim->IC_CaptureHalfCpltCallback(htim);
5744 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
5745 htim->PeriodElapsedCallback(htim);
5762 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
5763 htim->PeriodElapsedHalfCpltCallback(htim);
5780 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
5781 htim->TriggerCallback(htim);
5798 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
5799 htim->TriggerHalfCpltCallback(htim);
5837 TIMx->
ARR = (uint32_t)Structure->
Period ;
5869 tmpccer = TIMx->
CCER;
5874 tmpccmrx = TIMx->
CCMR1;
5880 tmpccmrx |= OC_Config->
OCMode;
5919 TIMx->
CCMR1 = tmpccmrx;
5925 TIMx->
CCER = tmpccer;
5944 tmpccer = TIMx->
CCER;
5949 tmpccmrx = TIMx->
CCMR1;
5956 tmpccmrx |= (OC_Config->
OCMode << 8U);
5995 TIMx->
CCMR1 = tmpccmrx;
6001 TIMx->
CCER = tmpccer;
6020 tmpccer = TIMx->
CCER;
6025 tmpccmrx = TIMx->
CCMR2;
6031 tmpccmrx |= OC_Config->
OCMode;
6069 TIMx->
CCMR2 = tmpccmrx;
6075 TIMx->
CCER = tmpccer;
6094 tmpccer = TIMx->
CCER;
6099 tmpccmrx = TIMx->
CCMR2;
6106 tmpccmrx |= (OC_Config->
OCMode << 8U);
6129 TIMx->
CCMR2 = tmpccmrx;
6135 TIMx->
CCER = tmpccer;
6219 TIM_TI1_ConfigInputStage(htim->
Instance,
6233 TIM_TI2_ConfigInputStage(htim->
Instance,
6276 uint32_t TIM_ICFilter)
6283 tmpccmr1 = TIMx->
CCMR1;
6284 tmpccer = TIMx->
CCER;
6290 tmpccmr1 |= TIM_ICSelection;
6306 TIMx->
CCMR1 = tmpccmr1;
6307 TIMx->
CCER = tmpccer;
6322 static void TIM_TI1_ConfigInputStage(
TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICFilter)
6328 tmpccer = TIMx->
CCER;
6330 tmpccmr1 = TIMx->
CCMR1;
6334 tmpccmr1 |= (TIM_ICFilter << 4U);
6338 tmpccer |= TIM_ICPolarity;
6341 TIMx->
CCMR1 = tmpccmr1;
6342 TIMx->
CCER = tmpccer;
6365 static void TIM_TI2_SetConfig(
TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection,
6366 uint32_t TIM_ICFilter)
6373 tmpccmr1 = TIMx->
CCMR1;
6374 tmpccer = TIMx->
CCER;
6378 tmpccmr1 |= (TIM_ICSelection << 8U);
6389 TIMx->
CCMR1 = tmpccmr1 ;
6390 TIMx->
CCER = tmpccer;
6405 static void TIM_TI2_ConfigInputStage(
TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICFilter)
6412 tmpccmr1 = TIMx->
CCMR1;
6413 tmpccer = TIMx->
CCER;
6417 tmpccmr1 |= (TIM_ICFilter << 12U);
6421 tmpccer |= (TIM_ICPolarity << 4U);
6424 TIMx->
CCMR1 = tmpccmr1 ;
6425 TIMx->
CCER = tmpccer;
6448 static void TIM_TI3_SetConfig(
TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection,
6449 uint32_t TIM_ICFilter)
6456 tmpccmr2 = TIMx->
CCMR2;
6457 tmpccer = TIMx->
CCER;
6461 tmpccmr2 |= TIM_ICSelection;
6472 TIMx->
CCMR2 = tmpccmr2;
6473 TIMx->
CCER = tmpccer;
6496 static void TIM_TI4_SetConfig(
TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection,
6497 uint32_t TIM_ICFilter)
6504 tmpccmr2 = TIMx->
CCMR2;
6505 tmpccer = TIMx->
CCER;
6509 tmpccmr2 |= (TIM_ICSelection << 8U);
6520 TIMx->
CCMR2 = tmpccmr2;
6521 TIMx->
CCER = tmpccer ;
6539 static void TIM_ITRx_SetConfig(
TIM_TypeDef *TIMx, uint32_t InputTriggerSource)
6544 tmpsmcr = TIMx->
SMCR;
6550 TIMx->
SMCR = tmpsmcr;
6570 uint32_t TIM_ExtTRGPolarity, uint32_t ExtTRGFilter)
6574 tmpsmcr = TIMx->
SMCR;
6580 tmpsmcr |= (uint32_t)(TIM_ExtTRGPrescaler | (TIM_ExtTRGPolarity | (ExtTRGFilter << 8U)));
6583 TIMx->
SMCR = tmpsmcr;
6613 TIMx->
CCER |= (uint32_t)(ChannelState << (Channel & 0x1FU));
6616 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)