STM32F4xx HAL Driver master
STM32CubeF4 HAL / LL Drivers API Reference
Loading...
Searching...
No Matches
stm32f4xx_hal_tim.c
Go to the documentation of this file.
1
184
185/* Includes ------------------------------------------------------------------*/
186#include "stm32f4xx_hal.h"
187
191
196
197#ifdef HAL_TIM_MODULE_ENABLED
198
199/* Private typedef -----------------------------------------------------------*/
200/* Private define ------------------------------------------------------------*/
201/* Private macros ------------------------------------------------------------*/
202/* Private variables ---------------------------------------------------------*/
203/* Private function prototypes -----------------------------------------------*/
207static void TIM_OC1_SetConfig(TIM_TypeDef *TIMx, const TIM_OC_InitTypeDef *OC_Config);
208static void TIM_OC3_SetConfig(TIM_TypeDef *TIMx, const TIM_OC_InitTypeDef *OC_Config);
209static void TIM_OC4_SetConfig(TIM_TypeDef *TIMx, const TIM_OC_InitTypeDef *OC_Config);
210static void TIM_TI1_ConfigInputStage(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICFilter);
211static void TIM_TI2_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection,
212 uint32_t TIM_ICFilter);
213static void TIM_TI2_ConfigInputStage(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICFilter);
214static void TIM_TI3_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection,
215 uint32_t TIM_ICFilter);
216static void TIM_TI4_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection,
217 uint32_t TIM_ICFilter);
218static void TIM_ITRx_SetConfig(TIM_TypeDef *TIMx, uint32_t InputTriggerSource);
219static void TIM_DMAPeriodElapsedCplt(DMA_HandleTypeDef *hdma);
220static void TIM_DMAPeriodElapsedHalfCplt(DMA_HandleTypeDef *hdma);
221static void TIM_DMADelayPulseCplt(DMA_HandleTypeDef *hdma);
222static void TIM_DMATriggerCplt(DMA_HandleTypeDef *hdma);
223static void TIM_DMATriggerHalfCplt(DMA_HandleTypeDef *hdma);
224static HAL_StatusTypeDef TIM_SlaveTimer_SetConfig(TIM_HandleTypeDef *htim,
225 const TIM_SlaveConfigTypeDef *sSlaveConfig);
229/* Exported functions --------------------------------------------------------*/
230
234
267{
268 /* Check the TIM handle allocation */
269 if (htim == NULL)
270 {
271 return HAL_ERROR;
272 }
273
274 /* Check the parameters */
275 assert_param(IS_TIM_INSTANCE(htim->Instance));
280
281 if (htim->State == HAL_TIM_STATE_RESET)
282 {
283 /* Allocate lock resource and initialize it */
284 htim->Lock = HAL_UNLOCKED;
285
286#if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
287 /* Reset interrupt callbacks to legacy weak callbacks */
288 TIM_ResetCallback(htim);
289
290 if (htim->Base_MspInitCallback == NULL)
291 {
292 htim->Base_MspInitCallback = HAL_TIM_Base_MspInit;
293 }
294 /* Init the low level hardware : GPIO, CLOCK, NVIC */
295 htim->Base_MspInitCallback(htim);
296#else
297 /* Init the low level hardware : GPIO, CLOCK, NVIC */
299#endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
300 }
301
302 /* Set the TIM state */
304
305 /* Set the Time Base configuration */
306 TIM_Base_SetConfig(htim->Instance, &htim->Init);
307
308 /* Initialize the DMA burst operation state */
310
311 /* Initialize the TIM channels state */
314
315 /* Initialize the TIM state*/
317
318 return HAL_OK;
319}
320
327{
328 /* Check the parameters */
329 assert_param(IS_TIM_INSTANCE(htim->Instance));
330
332
333 /* Disable the TIM Peripheral Clock */
334 __HAL_TIM_DISABLE(htim);
335
336#if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
337 if (htim->Base_MspDeInitCallback == NULL)
338 {
339 htim->Base_MspDeInitCallback = HAL_TIM_Base_MspDeInit;
340 }
341 /* DeInit the low level hardware */
342 htim->Base_MspDeInitCallback(htim);
343#else
344 /* DeInit the low level hardware: GPIO, CLOCK, NVIC */
346#endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
347
348 /* Change the DMA burst operation state */
350
351 /* Change the TIM channels state */
354
355 /* Change TIM state */
357
358 /* Release Lock */
359 __HAL_UNLOCK(htim);
360
361 return HAL_OK;
362}
363
370{
371 /* Prevent unused argument(s) compilation warning */
372 UNUSED(htim);
373
374 /* NOTE : This function should not be modified, when the callback is needed,
375 the HAL_TIM_Base_MspInit could be implemented in the user file
376 */
377}
378
385{
386 /* Prevent unused argument(s) compilation warning */
387 UNUSED(htim);
388
389 /* NOTE : This function should not be modified, when the callback is needed,
390 the HAL_TIM_Base_MspDeInit could be implemented in the user file
391 */
392}
393
394
401{
402 uint32_t tmpsmcr;
403
404 /* Check the parameters */
405 assert_param(IS_TIM_INSTANCE(htim->Instance));
406
407 /* Check the TIM state */
408 if (htim->State != HAL_TIM_STATE_READY)
409 {
410 return HAL_ERROR;
411 }
412
413 /* Set the TIM state */
415
416 /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
417 if (IS_TIM_SLAVE_INSTANCE(htim->Instance))
418 {
419 tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
421 {
422 __HAL_TIM_ENABLE(htim);
423 }
424 }
425 else
426 {
427 __HAL_TIM_ENABLE(htim);
428 }
429
430 /* Return function status */
431 return HAL_OK;
432}
433
440{
441 /* Check the parameters */
442 assert_param(IS_TIM_INSTANCE(htim->Instance));
443
444 /* Disable the Peripheral */
445 __HAL_TIM_DISABLE(htim);
446
447 /* Set the TIM state */
449
450 /* Return function status */
451 return HAL_OK;
452}
453
460{
461 uint32_t tmpsmcr;
462
463 /* Check the parameters */
464 assert_param(IS_TIM_INSTANCE(htim->Instance));
465
466 /* Check the TIM state */
467 if (htim->State != HAL_TIM_STATE_READY)
468 {
469 return HAL_ERROR;
470 }
471
472 /* Set the TIM state */
474
475 /* Enable the TIM Update interrupt */
477
478 /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
479 if (IS_TIM_SLAVE_INSTANCE(htim->Instance))
480 {
481 tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
483 {
484 __HAL_TIM_ENABLE(htim);
485 }
486 }
487 else
488 {
489 __HAL_TIM_ENABLE(htim);
490 }
491
492 /* Return function status */
493 return HAL_OK;
494}
495
502{
503 /* Check the parameters */
504 assert_param(IS_TIM_INSTANCE(htim->Instance));
505
506 /* Disable the TIM Update interrupt */
508
509 /* Disable the Peripheral */
510 __HAL_TIM_DISABLE(htim);
511
512 /* Set the TIM state */
514
515 /* Return function status */
516 return HAL_OK;
517}
518
526HAL_StatusTypeDef HAL_TIM_Base_Start_DMA(TIM_HandleTypeDef *htim, const uint32_t *pData, uint16_t Length)
527{
528 uint32_t tmpsmcr;
529
530 /* Check the parameters */
531 assert_param(IS_TIM_DMA_INSTANCE(htim->Instance));
532
533 /* Set the TIM state */
534 if (htim->State == HAL_TIM_STATE_BUSY)
535 {
536 return HAL_BUSY;
537 }
538 else if (htim->State == HAL_TIM_STATE_READY)
539 {
540 if ((pData == NULL) || (Length == 0U))
541 {
542 return HAL_ERROR;
543 }
544 else
545 {
547 }
548 }
549 else
550 {
551 return HAL_ERROR;
552 }
553
554 /* Set the DMA Period elapsed callbacks */
555 htim->hdma[TIM_DMA_ID_UPDATE]->XferCpltCallback = TIM_DMAPeriodElapsedCplt;
556 htim->hdma[TIM_DMA_ID_UPDATE]->XferHalfCpltCallback = TIM_DMAPeriodElapsedHalfCplt;
557
558 /* Set the DMA error callback */
560
561 /* Enable the DMA stream */
562 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_UPDATE], (uint32_t)pData, (uint32_t)&htim->Instance->ARR,
563 Length) != HAL_OK)
564 {
565 /* Return error status */
566 return HAL_ERROR;
567 }
568
569 /* Enable the TIM Update DMA request */
571
572 /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
573 if (IS_TIM_SLAVE_INSTANCE(htim->Instance))
574 {
575 tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
577 {
578 __HAL_TIM_ENABLE(htim);
579 }
580 }
581 else
582 {
583 __HAL_TIM_ENABLE(htim);
584 }
585
586 /* Return function status */
587 return HAL_OK;
588}
589
596{
597 /* Check the parameters */
598 assert_param(IS_TIM_DMA_INSTANCE(htim->Instance));
599
600 /* Disable the TIM Update DMA request */
602
604
605 /* Disable the Peripheral */
606 __HAL_TIM_DISABLE(htim);
607
608 /* Set the TIM state */
610
611 /* Return function status */
612 return HAL_OK;
613}
614
618
651{
652 /* Check the TIM handle allocation */
653 if (htim == NULL)
654 {
655 return HAL_ERROR;
656 }
657
658 /* Check the parameters */
659 assert_param(IS_TIM_INSTANCE(htim->Instance));
664
665 if (htim->State == HAL_TIM_STATE_RESET)
666 {
667 /* Allocate lock resource and initialize it */
668 htim->Lock = HAL_UNLOCKED;
669
670#if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
671 /* Reset interrupt callbacks to legacy weak callbacks */
672 TIM_ResetCallback(htim);
673
674 if (htim->OC_MspInitCallback == NULL)
675 {
676 htim->OC_MspInitCallback = HAL_TIM_OC_MspInit;
677 }
678 /* Init the low level hardware : GPIO, CLOCK, NVIC */
679 htim->OC_MspInitCallback(htim);
680#else
681 /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */
682 HAL_TIM_OC_MspInit(htim);
683#endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
684 }
685
686 /* Set the TIM state */
688
689 /* Init the base time for the Output Compare */
690 TIM_Base_SetConfig(htim->Instance, &htim->Init);
691
692 /* Initialize the DMA burst operation state */
694
695 /* Initialize the TIM channels state */
698
699 /* Initialize the TIM state*/
701
702 return HAL_OK;
703}
704
711{
712 /* Check the parameters */
713 assert_param(IS_TIM_INSTANCE(htim->Instance));
714
716
717 /* Disable the TIM Peripheral Clock */
718 __HAL_TIM_DISABLE(htim);
719
720#if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
721 if (htim->OC_MspDeInitCallback == NULL)
722 {
723 htim->OC_MspDeInitCallback = HAL_TIM_OC_MspDeInit;
724 }
725 /* DeInit the low level hardware */
726 htim->OC_MspDeInitCallback(htim);
727#else
728 /* DeInit the low level hardware: GPIO, CLOCK, NVIC and DMA */
730#endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
731
732 /* Change the DMA burst operation state */
734
735 /* Change the TIM channels state */
738
739 /* Change TIM state */
741
742 /* Release Lock */
743 __HAL_UNLOCK(htim);
744
745 return HAL_OK;
746}
747
753__weak void HAL_TIM_OC_MspInit(TIM_HandleTypeDef *htim)
754{
755 /* Prevent unused argument(s) compilation warning */
756 UNUSED(htim);
757
758 /* NOTE : This function should not be modified, when the callback is needed,
759 the HAL_TIM_OC_MspInit could be implemented in the user file
760 */
761}
762
769{
770 /* Prevent unused argument(s) compilation warning */
771 UNUSED(htim);
772
773 /* NOTE : This function should not be modified, when the callback is needed,
774 the HAL_TIM_OC_MspDeInit could be implemented in the user file
775 */
776}
777
790{
791 uint32_t tmpsmcr;
792
793 /* Check the parameters */
794 assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
795
796 /* Check the TIM channel state */
798 {
799 return HAL_ERROR;
800 }
801
802 /* Set the TIM channel state */
804
805 /* Enable the Output compare channel */
807
808 if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
809 {
810 /* Enable the main output */
812 }
813
814 /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
815 if (IS_TIM_SLAVE_INSTANCE(htim->Instance))
816 {
817 tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
819 {
820 __HAL_TIM_ENABLE(htim);
821 }
822 }
823 else
824 {
825 __HAL_TIM_ENABLE(htim);
826 }
827
828 /* Return function status */
829 return HAL_OK;
830}
831
844{
845 /* Check the parameters */
846 assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
847
848 /* Disable the Output compare channel */
850
851 if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
852 {
853 /* Disable the Main Output */
855 }
856
857 /* Disable the Peripheral */
858 __HAL_TIM_DISABLE(htim);
859
860 /* Set the TIM channel state */
862
863 /* Return function status */
864 return HAL_OK;
865}
866
879{
880 HAL_StatusTypeDef status = HAL_OK;
881 uint32_t tmpsmcr;
882
883 /* Check the parameters */
884 assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
885
886 /* Check the TIM channel state */
888 {
889 return HAL_ERROR;
890 }
891
892 /* Set the TIM channel state */
894
895 switch (Channel)
896 {
897 case TIM_CHANNEL_1:
898 {
899 /* Enable the TIM Capture/Compare 1 interrupt */
901 break;
902 }
903
904 case TIM_CHANNEL_2:
905 {
906 /* Enable the TIM Capture/Compare 2 interrupt */
908 break;
909 }
910
911 case TIM_CHANNEL_3:
912 {
913 /* Enable the TIM Capture/Compare 3 interrupt */
915 break;
916 }
917
918 case TIM_CHANNEL_4:
919 {
920 /* Enable the TIM Capture/Compare 4 interrupt */
922 break;
923 }
924
925 default:
926 status = HAL_ERROR;
927 break;
928 }
929
930 if (status == HAL_OK)
931 {
932 /* Enable the Output compare channel */
934
935 if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
936 {
937 /* Enable the main output */
939 }
940
941 /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
942 if (IS_TIM_SLAVE_INSTANCE(htim->Instance))
943 {
944 tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
946 {
947 __HAL_TIM_ENABLE(htim);
948 }
949 }
950 else
951 {
952 __HAL_TIM_ENABLE(htim);
953 }
954 }
955
956 /* Return function status */
957 return status;
958}
959
972{
973 HAL_StatusTypeDef status = HAL_OK;
974
975 /* Check the parameters */
976 assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
977
978 switch (Channel)
979 {
980 case TIM_CHANNEL_1:
981 {
982 /* Disable the TIM Capture/Compare 1 interrupt */
984 break;
985 }
986
987 case TIM_CHANNEL_2:
988 {
989 /* Disable the TIM Capture/Compare 2 interrupt */
991 break;
992 }
993
994 case TIM_CHANNEL_3:
995 {
996 /* Disable the TIM Capture/Compare 3 interrupt */
998 break;
999 }
1000
1001 case TIM_CHANNEL_4:
1002 {
1003 /* Disable the TIM Capture/Compare 4 interrupt */
1005 break;
1006 }
1007
1008 default:
1009 status = HAL_ERROR;
1010 break;
1011 }
1012
1013 if (status == HAL_OK)
1014 {
1015 /* Disable the Output compare channel */
1017
1018 if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
1019 {
1020 /* Disable the Main Output */
1022 }
1023
1024 /* Disable the Peripheral */
1025 __HAL_TIM_DISABLE(htim);
1026
1027 /* Set the TIM channel state */
1029 }
1030
1031 /* Return function status */
1032 return status;
1033}
1034
1048HAL_StatusTypeDef HAL_TIM_OC_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, const uint32_t *pData,
1049 uint16_t Length)
1050{
1051 HAL_StatusTypeDef status = HAL_OK;
1052 uint32_t tmpsmcr;
1053
1054 /* Check the parameters */
1055 assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
1056
1057 /* Set the TIM channel state */
1059 {
1060 return HAL_BUSY;
1061 }
1062 else if (TIM_CHANNEL_STATE_GET(htim, Channel) == HAL_TIM_CHANNEL_STATE_READY)
1063 {
1064 if ((pData == NULL) || (Length == 0U))
1065 {
1066 return HAL_ERROR;
1067 }
1068 else
1069 {
1071 }
1072 }
1073 else
1074 {
1075 return HAL_ERROR;
1076 }
1077
1078 switch (Channel)
1079 {
1080 case TIM_CHANNEL_1:
1081 {
1082 /* Set the DMA compare callbacks */
1083 htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMADelayPulseCplt;
1085
1086 /* Set the DMA error callback */
1088
1089 /* Enable the DMA stream */
1090 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)pData, (uint32_t)&htim->Instance->CCR1,
1091 Length) != HAL_OK)
1092 {
1093 /* Return error status */
1094 return HAL_ERROR;
1095 }
1096
1097 /* Enable the TIM Capture/Compare 1 DMA request */
1099 break;
1100 }
1101
1102 case TIM_CHANNEL_2:
1103 {
1104 /* Set the DMA compare callbacks */
1105 htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = TIM_DMADelayPulseCplt;
1107
1108 /* Set the DMA error callback */
1110
1111 /* Enable the DMA stream */
1112 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)pData, (uint32_t)&htim->Instance->CCR2,
1113 Length) != HAL_OK)
1114 {
1115 /* Return error status */
1116 return HAL_ERROR;
1117 }
1118
1119 /* Enable the TIM Capture/Compare 2 DMA request */
1121 break;
1122 }
1123
1124 case TIM_CHANNEL_3:
1125 {
1126 /* Set the DMA compare callbacks */
1127 htim->hdma[TIM_DMA_ID_CC3]->XferCpltCallback = TIM_DMADelayPulseCplt;
1129
1130 /* Set the DMA error callback */
1132
1133 /* Enable the DMA stream */
1134 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)pData, (uint32_t)&htim->Instance->CCR3,
1135 Length) != HAL_OK)
1136 {
1137 /* Return error status */
1138 return HAL_ERROR;
1139 }
1140 /* Enable the TIM Capture/Compare 3 DMA request */
1142 break;
1143 }
1144
1145 case TIM_CHANNEL_4:
1146 {
1147 /* Set the DMA compare callbacks */
1148 htim->hdma[TIM_DMA_ID_CC4]->XferCpltCallback = TIM_DMADelayPulseCplt;
1150
1151 /* Set the DMA error callback */
1153
1154 /* Enable the DMA stream */
1155 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC4], (uint32_t)pData, (uint32_t)&htim->Instance->CCR4,
1156 Length) != HAL_OK)
1157 {
1158 /* Return error status */
1159 return HAL_ERROR;
1160 }
1161 /* Enable the TIM Capture/Compare 4 DMA request */
1163 break;
1164 }
1165
1166 default:
1167 status = HAL_ERROR;
1168 break;
1169 }
1170
1171 if (status == HAL_OK)
1172 {
1173 /* Enable the Output compare channel */
1174 TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE);
1175
1176 if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
1177 {
1178 /* Enable the main output */
1180 }
1181
1182 /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
1183 if (IS_TIM_SLAVE_INSTANCE(htim->Instance))
1184 {
1185 tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
1187 {
1188 __HAL_TIM_ENABLE(htim);
1189 }
1190 }
1191 else
1192 {
1193 __HAL_TIM_ENABLE(htim);
1194 }
1195 }
1196
1197 /* Return function status */
1198 return status;
1199}
1200
1213{
1214 HAL_StatusTypeDef status = HAL_OK;
1215
1216 /* Check the parameters */
1217 assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
1218
1219 switch (Channel)
1220 {
1221 case TIM_CHANNEL_1:
1222 {
1223 /* Disable the TIM Capture/Compare 1 DMA request */
1225 (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC1]);
1226 break;
1227 }
1228
1229 case TIM_CHANNEL_2:
1230 {
1231 /* Disable the TIM Capture/Compare 2 DMA request */
1233 (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC2]);
1234 break;
1235 }
1236
1237 case TIM_CHANNEL_3:
1238 {
1239 /* Disable the TIM Capture/Compare 3 DMA request */
1241 (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC3]);
1242 break;
1243 }
1244
1245 case TIM_CHANNEL_4:
1246 {
1247 /* Disable the TIM Capture/Compare 4 interrupt */
1249 (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC4]);
1250 break;
1251 }
1252
1253 default:
1254 status = HAL_ERROR;
1255 break;
1256 }
1257
1258 if (status == HAL_OK)
1259 {
1260 /* Disable the Output compare channel */
1262
1263 if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
1264 {
1265 /* Disable the Main Output */
1267 }
1268
1269 /* Disable the Peripheral */
1270 __HAL_TIM_DISABLE(htim);
1271
1272 /* Set the TIM channel state */
1274 }
1275
1276 /* Return function status */
1277 return status;
1278}
1279
1283
1316{
1317 /* Check the TIM handle allocation */
1318 if (htim == NULL)
1319 {
1320 return HAL_ERROR;
1321 }
1322
1323 /* Check the parameters */
1324 assert_param(IS_TIM_INSTANCE(htim->Instance));
1327 assert_param(IS_TIM_PERIOD(htim, htim->Init.Period));
1329
1330 if (htim->State == HAL_TIM_STATE_RESET)
1331 {
1332 /* Allocate lock resource and initialize it */
1333 htim->Lock = HAL_UNLOCKED;
1334
1335#if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
1336 /* Reset interrupt callbacks to legacy weak callbacks */
1337 TIM_ResetCallback(htim);
1338
1339 if (htim->PWM_MspInitCallback == NULL)
1340 {
1341 htim->PWM_MspInitCallback = HAL_TIM_PWM_MspInit;
1342 }
1343 /* Init the low level hardware : GPIO, CLOCK, NVIC */
1344 htim->PWM_MspInitCallback(htim);
1345#else
1346 /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */
1347 HAL_TIM_PWM_MspInit(htim);
1348#endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
1349 }
1350
1351 /* Set the TIM state */
1352 htim->State = HAL_TIM_STATE_BUSY;
1353
1354 /* Init the base time for the PWM */
1355 TIM_Base_SetConfig(htim->Instance, &htim->Init);
1356
1357 /* Initialize the DMA burst operation state */
1359
1360 /* Initialize the TIM channels state */
1363
1364 /* Initialize the TIM state*/
1365 htim->State = HAL_TIM_STATE_READY;
1366
1367 return HAL_OK;
1368}
1369
1376{
1377 /* Check the parameters */
1378 assert_param(IS_TIM_INSTANCE(htim->Instance));
1379
1380 htim->State = HAL_TIM_STATE_BUSY;
1381
1382 /* Disable the TIM Peripheral Clock */
1383 __HAL_TIM_DISABLE(htim);
1384
1385#if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
1386 if (htim->PWM_MspDeInitCallback == NULL)
1387 {
1388 htim->PWM_MspDeInitCallback = HAL_TIM_PWM_MspDeInit;
1389 }
1390 /* DeInit the low level hardware */
1391 htim->PWM_MspDeInitCallback(htim);
1392#else
1393 /* DeInit the low level hardware: GPIO, CLOCK, NVIC and DMA */
1395#endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
1396
1397 /* Change the DMA burst operation state */
1399
1400 /* Change the TIM channels state */
1403
1404 /* Change TIM state */
1405 htim->State = HAL_TIM_STATE_RESET;
1406
1407 /* Release Lock */
1408 __HAL_UNLOCK(htim);
1409
1410 return HAL_OK;
1411}
1412
1418__weak void HAL_TIM_PWM_MspInit(TIM_HandleTypeDef *htim)
1419{
1420 /* Prevent unused argument(s) compilation warning */
1421 UNUSED(htim);
1422
1423 /* NOTE : This function should not be modified, when the callback is needed,
1424 the HAL_TIM_PWM_MspInit could be implemented in the user file
1425 */
1426}
1427
1434{
1435 /* Prevent unused argument(s) compilation warning */
1436 UNUSED(htim);
1437
1438 /* NOTE : This function should not be modified, when the callback is needed,
1439 the HAL_TIM_PWM_MspDeInit could be implemented in the user file
1440 */
1441}
1442
1455{
1456 uint32_t tmpsmcr;
1457
1458 /* Check the parameters */
1459 assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
1460
1461 /* Check the TIM channel state */
1463 {
1464 return HAL_ERROR;
1465 }
1466
1467 /* Set the TIM channel state */
1469
1470 /* Enable the Capture compare channel */
1471 TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE);
1472
1473 if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
1474 {
1475 /* Enable the main output */
1477 }
1478
1479 /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
1480 if (IS_TIM_SLAVE_INSTANCE(htim->Instance))
1481 {
1482 tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
1484 {
1485 __HAL_TIM_ENABLE(htim);
1486 }
1487 }
1488 else
1489 {
1490 __HAL_TIM_ENABLE(htim);
1491 }
1492
1493 /* Return function status */
1494 return HAL_OK;
1495}
1496
1509{
1510 /* Check the parameters */
1511 assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
1512
1513 /* Disable the Capture compare channel */
1515
1516 if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
1517 {
1518 /* Disable the Main Output */
1520 }
1521
1522 /* Disable the Peripheral */
1523 __HAL_TIM_DISABLE(htim);
1524
1525 /* Set the TIM channel state */
1527
1528 /* Return function status */
1529 return HAL_OK;
1530}
1531
1544{
1545 HAL_StatusTypeDef status = HAL_OK;
1546 uint32_t tmpsmcr;
1547
1548 /* Check the parameters */
1549 assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
1550
1551 /* Check the TIM channel state */
1553 {
1554 return HAL_ERROR;
1555 }
1556
1557 /* Set the TIM channel state */
1559
1560 switch (Channel)
1561 {
1562 case TIM_CHANNEL_1:
1563 {
1564 /* Enable the TIM Capture/Compare 1 interrupt */
1566 break;
1567 }
1568
1569 case TIM_CHANNEL_2:
1570 {
1571 /* Enable the TIM Capture/Compare 2 interrupt */
1573 break;
1574 }
1575
1576 case TIM_CHANNEL_3:
1577 {
1578 /* Enable the TIM Capture/Compare 3 interrupt */
1580 break;
1581 }
1582
1583 case TIM_CHANNEL_4:
1584 {
1585 /* Enable the TIM Capture/Compare 4 interrupt */
1587 break;
1588 }
1589
1590 default:
1591 status = HAL_ERROR;
1592 break;
1593 }
1594
1595 if (status == HAL_OK)
1596 {
1597 /* Enable the Capture compare channel */
1598 TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE);
1599
1600 if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
1601 {
1602 /* Enable the main output */
1604 }
1605
1606 /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
1607 if (IS_TIM_SLAVE_INSTANCE(htim->Instance))
1608 {
1609 tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
1611 {
1612 __HAL_TIM_ENABLE(htim);
1613 }
1614 }
1615 else
1616 {
1617 __HAL_TIM_ENABLE(htim);
1618 }
1619 }
1620
1621 /* Return function status */
1622 return status;
1623}
1624
1637{
1638 HAL_StatusTypeDef status = HAL_OK;
1639
1640 /* Check the parameters */
1641 assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
1642
1643 switch (Channel)
1644 {
1645 case TIM_CHANNEL_1:
1646 {
1647 /* Disable the TIM Capture/Compare 1 interrupt */
1649 break;
1650 }
1651
1652 case TIM_CHANNEL_2:
1653 {
1654 /* Disable the TIM Capture/Compare 2 interrupt */
1656 break;
1657 }
1658
1659 case TIM_CHANNEL_3:
1660 {
1661 /* Disable the TIM Capture/Compare 3 interrupt */
1663 break;
1664 }
1665
1666 case TIM_CHANNEL_4:
1667 {
1668 /* Disable the TIM Capture/Compare 4 interrupt */
1670 break;
1671 }
1672
1673 default:
1674 status = HAL_ERROR;
1675 break;
1676 }
1677
1678 if (status == HAL_OK)
1679 {
1680 /* Disable the Capture compare channel */
1682
1683 if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
1684 {
1685 /* Disable the Main Output */
1687 }
1688
1689 /* Disable the Peripheral */
1690 __HAL_TIM_DISABLE(htim);
1691
1692 /* Set the TIM channel state */
1694 }
1695
1696 /* Return function status */
1697 return status;
1698}
1699
1713HAL_StatusTypeDef HAL_TIM_PWM_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, const uint32_t *pData,
1714 uint16_t Length)
1715{
1716 HAL_StatusTypeDef status = HAL_OK;
1717 uint32_t tmpsmcr;
1718
1719 /* Check the parameters */
1720 assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
1721
1722 /* Set the TIM channel state */
1724 {
1725 return HAL_BUSY;
1726 }
1727 else if (TIM_CHANNEL_STATE_GET(htim, Channel) == HAL_TIM_CHANNEL_STATE_READY)
1728 {
1729 if ((pData == NULL) || (Length == 0U))
1730 {
1731 return HAL_ERROR;
1732 }
1733 else
1734 {
1736 }
1737 }
1738 else
1739 {
1740 return HAL_ERROR;
1741 }
1742
1743 switch (Channel)
1744 {
1745 case TIM_CHANNEL_1:
1746 {
1747 /* Set the DMA compare callbacks */
1748 htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMADelayPulseCplt;
1750
1751 /* Set the DMA error callback */
1753
1754 /* Enable the DMA stream */
1755 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)pData, (uint32_t)&htim->Instance->CCR1,
1756 Length) != HAL_OK)
1757 {
1758 /* Return error status */
1759 return HAL_ERROR;
1760 }
1761
1762 /* Enable the TIM Capture/Compare 1 DMA request */
1764 break;
1765 }
1766
1767 case TIM_CHANNEL_2:
1768 {
1769 /* Set the DMA compare callbacks */
1770 htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = TIM_DMADelayPulseCplt;
1772
1773 /* Set the DMA error callback */
1775
1776 /* Enable the DMA stream */
1777 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)pData, (uint32_t)&htim->Instance->CCR2,
1778 Length) != HAL_OK)
1779 {
1780 /* Return error status */
1781 return HAL_ERROR;
1782 }
1783 /* Enable the TIM Capture/Compare 2 DMA request */
1785 break;
1786 }
1787
1788 case TIM_CHANNEL_3:
1789 {
1790 /* Set the DMA compare callbacks */
1791 htim->hdma[TIM_DMA_ID_CC3]->XferCpltCallback = TIM_DMADelayPulseCplt;
1793
1794 /* Set the DMA error callback */
1796
1797 /* Enable the DMA stream */
1798 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)pData, (uint32_t)&htim->Instance->CCR3,
1799 Length) != HAL_OK)
1800 {
1801 /* Return error status */
1802 return HAL_ERROR;
1803 }
1804 /* Enable the TIM Output Capture/Compare 3 request */
1806 break;
1807 }
1808
1809 case TIM_CHANNEL_4:
1810 {
1811 /* Set the DMA compare callbacks */
1812 htim->hdma[TIM_DMA_ID_CC4]->XferCpltCallback = TIM_DMADelayPulseCplt;
1814
1815 /* Set the DMA error callback */
1817
1818 /* Enable the DMA stream */
1819 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC4], (uint32_t)pData, (uint32_t)&htim->Instance->CCR4,
1820 Length) != HAL_OK)
1821 {
1822 /* Return error status */
1823 return HAL_ERROR;
1824 }
1825 /* Enable the TIM Capture/Compare 4 DMA request */
1827 break;
1828 }
1829
1830 default:
1831 status = HAL_ERROR;
1832 break;
1833 }
1834
1835 if (status == HAL_OK)
1836 {
1837 /* Enable the Capture compare channel */
1838 TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE);
1839
1840 if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
1841 {
1842 /* Enable the main output */
1844 }
1845
1846 /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
1847 if (IS_TIM_SLAVE_INSTANCE(htim->Instance))
1848 {
1849 tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
1851 {
1852 __HAL_TIM_ENABLE(htim);
1853 }
1854 }
1855 else
1856 {
1857 __HAL_TIM_ENABLE(htim);
1858 }
1859 }
1860
1861 /* Return function status */
1862 return status;
1863}
1864
1877{
1878 HAL_StatusTypeDef status = HAL_OK;
1879
1880 /* Check the parameters */
1881 assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
1882
1883 switch (Channel)
1884 {
1885 case TIM_CHANNEL_1:
1886 {
1887 /* Disable the TIM Capture/Compare 1 DMA request */
1889 (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC1]);
1890 break;
1891 }
1892
1893 case TIM_CHANNEL_2:
1894 {
1895 /* Disable the TIM Capture/Compare 2 DMA request */
1897 (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC2]);
1898 break;
1899 }
1900
1901 case TIM_CHANNEL_3:
1902 {
1903 /* Disable the TIM Capture/Compare 3 DMA request */
1905 (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC3]);
1906 break;
1907 }
1908
1909 case TIM_CHANNEL_4:
1910 {
1911 /* Disable the TIM Capture/Compare 4 interrupt */
1913 (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC4]);
1914 break;
1915 }
1916
1917 default:
1918 status = HAL_ERROR;
1919 break;
1920 }
1921
1922 if (status == HAL_OK)
1923 {
1924 /* Disable the Capture compare channel */
1926
1927 if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
1928 {
1929 /* Disable the Main Output */
1931 }
1932
1933 /* Disable the Peripheral */
1934 __HAL_TIM_DISABLE(htim);
1935
1936 /* Set the TIM channel state */
1938 }
1939
1940 /* Return function status */
1941 return status;
1942}
1943
1947
1980{
1981 /* Check the TIM handle allocation */
1982 if (htim == NULL)
1983 {
1984 return HAL_ERROR;
1985 }
1986
1987 /* Check the parameters */
1988 assert_param(IS_TIM_INSTANCE(htim->Instance));
1991 assert_param(IS_TIM_PERIOD(htim, htim->Init.Period));
1993
1994 if (htim->State == HAL_TIM_STATE_RESET)
1995 {
1996 /* Allocate lock resource and initialize it */
1997 htim->Lock = HAL_UNLOCKED;
1998
1999#if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
2000 /* Reset interrupt callbacks to legacy weak callbacks */
2001 TIM_ResetCallback(htim);
2002
2003 if (htim->IC_MspInitCallback == NULL)
2004 {
2005 htim->IC_MspInitCallback = HAL_TIM_IC_MspInit;
2006 }
2007 /* Init the low level hardware : GPIO, CLOCK, NVIC */
2008 htim->IC_MspInitCallback(htim);
2009#else
2010 /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */
2011 HAL_TIM_IC_MspInit(htim);
2012#endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
2013 }
2014
2015 /* Set the TIM state */
2016 htim->State = HAL_TIM_STATE_BUSY;
2017
2018 /* Init the base time for the input capture */
2019 TIM_Base_SetConfig(htim->Instance, &htim->Init);
2020
2021 /* Initialize the DMA burst operation state */
2023
2024 /* Initialize the TIM channels state */
2027
2028 /* Initialize the TIM state*/
2029 htim->State = HAL_TIM_STATE_READY;
2030
2031 return HAL_OK;
2032}
2033
2040{
2041 /* Check the parameters */
2042 assert_param(IS_TIM_INSTANCE(htim->Instance));
2043
2044 htim->State = HAL_TIM_STATE_BUSY;
2045
2046 /* Disable the TIM Peripheral Clock */
2047 __HAL_TIM_DISABLE(htim);
2048
2049#if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
2050 if (htim->IC_MspDeInitCallback == NULL)
2051 {
2052 htim->IC_MspDeInitCallback = HAL_TIM_IC_MspDeInit;
2053 }
2054 /* DeInit the low level hardware */
2055 htim->IC_MspDeInitCallback(htim);
2056#else
2057 /* DeInit the low level hardware: GPIO, CLOCK, NVIC and DMA */
2059#endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
2060
2061 /* Change the DMA burst operation state */
2063
2064 /* Change the TIM channels state */
2067
2068 /* Change TIM state */
2069 htim->State = HAL_TIM_STATE_RESET;
2070
2071 /* Release Lock */
2072 __HAL_UNLOCK(htim);
2073
2074 return HAL_OK;
2075}
2076
2082__weak void HAL_TIM_IC_MspInit(TIM_HandleTypeDef *htim)
2083{
2084 /* Prevent unused argument(s) compilation warning */
2085 UNUSED(htim);
2086
2087 /* NOTE : This function should not be modified, when the callback is needed,
2088 the HAL_TIM_IC_MspInit could be implemented in the user file
2089 */
2090}
2091
2097__weak void HAL_TIM_IC_MspDeInit(TIM_HandleTypeDef *htim)
2098{
2099 /* Prevent unused argument(s) compilation warning */
2100 UNUSED(htim);
2101
2102 /* NOTE : This function should not be modified, when the callback is needed,
2103 the HAL_TIM_IC_MspDeInit could be implemented in the user file
2104 */
2105}
2106
2119{
2120 uint32_t tmpsmcr;
2121 HAL_TIM_ChannelStateTypeDef channel_state = TIM_CHANNEL_STATE_GET(htim, Channel);
2122 HAL_TIM_ChannelStateTypeDef complementary_channel_state = TIM_CHANNEL_N_STATE_GET(htim, Channel);
2123
2124 /* Check the parameters */
2125 assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
2126
2127 /* Check the TIM channel state */
2128 if ((channel_state != HAL_TIM_CHANNEL_STATE_READY)
2129 || (complementary_channel_state != HAL_TIM_CHANNEL_STATE_READY))
2130 {
2131 return HAL_ERROR;
2132 }
2133
2134 /* Set the TIM channel state */
2137
2138 /* Enable the Input Capture channel */
2139 TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE);
2140
2141 /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
2142 if (IS_TIM_SLAVE_INSTANCE(htim->Instance))
2143 {
2144 tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
2146 {
2147 __HAL_TIM_ENABLE(htim);
2148 }
2149 }
2150 else
2151 {
2152 __HAL_TIM_ENABLE(htim);
2153 }
2154
2155 /* Return function status */
2156 return HAL_OK;
2157}
2158
2171{
2172 /* Check the parameters */
2173 assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
2174
2175 /* Disable the Input Capture channel */
2177
2178 /* Disable the Peripheral */
2179 __HAL_TIM_DISABLE(htim);
2180
2181 /* Set the TIM channel state */
2184
2185 /* Return function status */
2186 return HAL_OK;
2187}
2188
2201{
2202 HAL_StatusTypeDef status = HAL_OK;
2203 uint32_t tmpsmcr;
2204
2205 HAL_TIM_ChannelStateTypeDef channel_state = TIM_CHANNEL_STATE_GET(htim, Channel);
2206 HAL_TIM_ChannelStateTypeDef complementary_channel_state = TIM_CHANNEL_N_STATE_GET(htim, Channel);
2207
2208 /* Check the parameters */
2209 assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
2210
2211 /* Check the TIM channel state */
2212 if ((channel_state != HAL_TIM_CHANNEL_STATE_READY)
2213 || (complementary_channel_state != HAL_TIM_CHANNEL_STATE_READY))
2214 {
2215 return HAL_ERROR;
2216 }
2217
2218 /* Set the TIM channel state */
2221
2222 switch (Channel)
2223 {
2224 case TIM_CHANNEL_1:
2225 {
2226 /* Enable the TIM Capture/Compare 1 interrupt */
2228 break;
2229 }
2230
2231 case TIM_CHANNEL_2:
2232 {
2233 /* Enable the TIM Capture/Compare 2 interrupt */
2235 break;
2236 }
2237
2238 case TIM_CHANNEL_3:
2239 {
2240 /* Enable the TIM Capture/Compare 3 interrupt */
2242 break;
2243 }
2244
2245 case TIM_CHANNEL_4:
2246 {
2247 /* Enable the TIM Capture/Compare 4 interrupt */
2249 break;
2250 }
2251
2252 default:
2253 status = HAL_ERROR;
2254 break;
2255 }
2256
2257 if (status == HAL_OK)
2258 {
2259 /* Enable the Input Capture channel */
2260 TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE);
2261
2262 /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
2263 if (IS_TIM_SLAVE_INSTANCE(htim->Instance))
2264 {
2265 tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
2267 {
2268 __HAL_TIM_ENABLE(htim);
2269 }
2270 }
2271 else
2272 {
2273 __HAL_TIM_ENABLE(htim);
2274 }
2275 }
2276
2277 /* Return function status */
2278 return status;
2279}
2280
2293{
2294 HAL_StatusTypeDef status = HAL_OK;
2295
2296 /* Check the parameters */
2297 assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
2298
2299 switch (Channel)
2300 {
2301 case TIM_CHANNEL_1:
2302 {
2303 /* Disable the TIM Capture/Compare 1 interrupt */
2305 break;
2306 }
2307
2308 case TIM_CHANNEL_2:
2309 {
2310 /* Disable the TIM Capture/Compare 2 interrupt */
2312 break;
2313 }
2314
2315 case TIM_CHANNEL_3:
2316 {
2317 /* Disable the TIM Capture/Compare 3 interrupt */
2319 break;
2320 }
2321
2322 case TIM_CHANNEL_4:
2323 {
2324 /* Disable the TIM Capture/Compare 4 interrupt */
2326 break;
2327 }
2328
2329 default:
2330 status = HAL_ERROR;
2331 break;
2332 }
2333
2334 if (status == HAL_OK)
2335 {
2336 /* Disable the Input Capture channel */
2338
2339 /* Disable the Peripheral */
2340 __HAL_TIM_DISABLE(htim);
2341
2342 /* Set the TIM channel state */
2345 }
2346
2347 /* Return function status */
2348 return status;
2349}
2350
2364HAL_StatusTypeDef HAL_TIM_IC_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length)
2365{
2366 HAL_StatusTypeDef status = HAL_OK;
2367 uint32_t tmpsmcr;
2368
2369 HAL_TIM_ChannelStateTypeDef channel_state = TIM_CHANNEL_STATE_GET(htim, Channel);
2370 HAL_TIM_ChannelStateTypeDef complementary_channel_state = TIM_CHANNEL_N_STATE_GET(htim, Channel);
2371
2372 /* Check the parameters */
2373 assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
2374 assert_param(IS_TIM_DMA_CC_INSTANCE(htim->Instance));
2375
2376 /* Set the TIM channel state */
2377 if ((channel_state == HAL_TIM_CHANNEL_STATE_BUSY)
2378 || (complementary_channel_state == HAL_TIM_CHANNEL_STATE_BUSY))
2379 {
2380 return HAL_BUSY;
2381 }
2382 else if ((channel_state == HAL_TIM_CHANNEL_STATE_READY)
2383 && (complementary_channel_state == HAL_TIM_CHANNEL_STATE_READY))
2384 {
2385 if ((pData == NULL) || (Length == 0U))
2386 {
2387 return HAL_ERROR;
2388 }
2389 else
2390 {
2393 }
2394 }
2395 else
2396 {
2397 return HAL_ERROR;
2398 }
2399
2400 /* Enable the Input Capture channel */
2401 TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE);
2402
2403 switch (Channel)
2404 {
2405 case TIM_CHANNEL_1:
2406 {
2407 /* Set the DMA capture callbacks */
2410
2411 /* Set the DMA error callback */
2413
2414 /* Enable the DMA stream */
2415 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)&htim->Instance->CCR1, (uint32_t)pData,
2416 Length) != HAL_OK)
2417 {
2418 /* Return error status */
2419 return HAL_ERROR;
2420 }
2421 /* Enable the TIM Capture/Compare 1 DMA request */
2423 break;
2424 }
2425
2426 case TIM_CHANNEL_2:
2427 {
2428 /* Set the DMA capture callbacks */
2431
2432 /* Set the DMA error callback */
2434
2435 /* Enable the DMA stream */
2436 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)&htim->Instance->CCR2, (uint32_t)pData,
2437 Length) != HAL_OK)
2438 {
2439 /* Return error status */
2440 return HAL_ERROR;
2441 }
2442 /* Enable the TIM Capture/Compare 2 DMA request */
2444 break;
2445 }
2446
2447 case TIM_CHANNEL_3:
2448 {
2449 /* Set the DMA capture callbacks */
2452
2453 /* Set the DMA error callback */
2455
2456 /* Enable the DMA stream */
2457 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)&htim->Instance->CCR3, (uint32_t)pData,
2458 Length) != HAL_OK)
2459 {
2460 /* Return error status */
2461 return HAL_ERROR;
2462 }
2463 /* Enable the TIM Capture/Compare 3 DMA request */
2465 break;
2466 }
2467
2468 case TIM_CHANNEL_4:
2469 {
2470 /* Set the DMA capture callbacks */
2473
2474 /* Set the DMA error callback */
2476
2477 /* Enable the DMA stream */
2478 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC4], (uint32_t)&htim->Instance->CCR4, (uint32_t)pData,
2479 Length) != HAL_OK)
2480 {
2481 /* Return error status */
2482 return HAL_ERROR;
2483 }
2484 /* Enable the TIM Capture/Compare 4 DMA request */
2486 break;
2487 }
2488
2489 default:
2490 status = HAL_ERROR;
2491 break;
2492 }
2493
2494 /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
2495 if (IS_TIM_SLAVE_INSTANCE(htim->Instance))
2496 {
2497 tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
2499 {
2500 __HAL_TIM_ENABLE(htim);
2501 }
2502 }
2503 else
2504 {
2505 __HAL_TIM_ENABLE(htim);
2506 }
2507
2508 /* Return function status */
2509 return status;
2510}
2511
2524{
2525 HAL_StatusTypeDef status = HAL_OK;
2526
2527 /* Check the parameters */
2528 assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
2529 assert_param(IS_TIM_DMA_CC_INSTANCE(htim->Instance));
2530
2531 /* Disable the Input Capture channel */
2533
2534 switch (Channel)
2535 {
2536 case TIM_CHANNEL_1:
2537 {
2538 /* Disable the TIM Capture/Compare 1 DMA request */
2540 (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC1]);
2541 break;
2542 }
2543
2544 case TIM_CHANNEL_2:
2545 {
2546 /* Disable the TIM Capture/Compare 2 DMA request */
2548 (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC2]);
2549 break;
2550 }
2551
2552 case TIM_CHANNEL_3:
2553 {
2554 /* Disable the TIM Capture/Compare 3 DMA request */
2556 (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC3]);
2557 break;
2558 }
2559
2560 case TIM_CHANNEL_4:
2561 {
2562 /* Disable the TIM Capture/Compare 4 DMA request */
2564 (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC4]);
2565 break;
2566 }
2567
2568 default:
2569 status = HAL_ERROR;
2570 break;
2571 }
2572
2573 if (status == HAL_OK)
2574 {
2575 /* Disable the Peripheral */
2576 __HAL_TIM_DISABLE(htim);
2577
2578 /* Set the TIM channel state */
2581 }
2582
2583 /* Return function status */
2584 return status;
2585}
2589
2628HAL_StatusTypeDef HAL_TIM_OnePulse_Init(TIM_HandleTypeDef *htim, uint32_t OnePulseMode)
2629{
2630 /* Check the TIM handle allocation */
2631 if (htim == NULL)
2632 {
2633 return HAL_ERROR;
2634 }
2635
2636 /* Check the parameters */
2637 assert_param(IS_TIM_INSTANCE(htim->Instance));
2640 assert_param(IS_TIM_OPM_MODE(OnePulseMode));
2641 assert_param(IS_TIM_PERIOD(htim, htim->Init.Period));
2643
2644 if (htim->State == HAL_TIM_STATE_RESET)
2645 {
2646 /* Allocate lock resource and initialize it */
2647 htim->Lock = HAL_UNLOCKED;
2648
2649#if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
2650 /* Reset interrupt callbacks to legacy weak callbacks */
2651 TIM_ResetCallback(htim);
2652
2653 if (htim->OnePulse_MspInitCallback == NULL)
2654 {
2655 htim->OnePulse_MspInitCallback = HAL_TIM_OnePulse_MspInit;
2656 }
2657 /* Init the low level hardware : GPIO, CLOCK, NVIC */
2658 htim->OnePulse_MspInitCallback(htim);
2659#else
2660 /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */
2662#endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
2663 }
2664
2665 /* Set the TIM state */
2666 htim->State = HAL_TIM_STATE_BUSY;
2667
2668 /* Configure the Time base in the One Pulse Mode */
2669 TIM_Base_SetConfig(htim->Instance, &htim->Init);
2670
2671 /* Reset the OPM Bit */
2672 htim->Instance->CR1 &= ~TIM_CR1_OPM;
2673
2674 /* Configure the OPM Mode */
2675 htim->Instance->CR1 |= OnePulseMode;
2676
2677 /* Initialize the DMA burst operation state */
2679
2680 /* Initialize the TIM channels state */
2685
2686 /* Initialize the TIM state*/
2687 htim->State = HAL_TIM_STATE_READY;
2688
2689 return HAL_OK;
2690}
2691
2698{
2699 /* Check the parameters */
2700 assert_param(IS_TIM_INSTANCE(htim->Instance));
2701
2702 htim->State = HAL_TIM_STATE_BUSY;
2703
2704 /* Disable the TIM Peripheral Clock */
2705 __HAL_TIM_DISABLE(htim);
2706
2707#if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
2708 if (htim->OnePulse_MspDeInitCallback == NULL)
2709 {
2710 htim->OnePulse_MspDeInitCallback = HAL_TIM_OnePulse_MspDeInit;
2711 }
2712 /* DeInit the low level hardware */
2713 htim->OnePulse_MspDeInitCallback(htim);
2714#else
2715 /* DeInit the low level hardware: GPIO, CLOCK, NVIC */
2717#endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
2718
2719 /* Change the DMA burst operation state */
2721
2722 /* Set the TIM channel state */
2727
2728 /* Change TIM state */
2729 htim->State = HAL_TIM_STATE_RESET;
2730
2731 /* Release Lock */
2732 __HAL_UNLOCK(htim);
2733
2734 return HAL_OK;
2735}
2736
2743{
2744 /* Prevent unused argument(s) compilation warning */
2745 UNUSED(htim);
2746
2747 /* NOTE : This function should not be modified, when the callback is needed,
2748 the HAL_TIM_OnePulse_MspInit could be implemented in the user file
2749 */
2750}
2751
2758{
2759 /* Prevent unused argument(s) compilation warning */
2760 UNUSED(htim);
2761
2762 /* NOTE : This function should not be modified, when the callback is needed,
2763 the HAL_TIM_OnePulse_MspDeInit could be implemented in the user file
2764 */
2765}
2766
2777HAL_StatusTypeDef HAL_TIM_OnePulse_Start(TIM_HandleTypeDef *htim, uint32_t OutputChannel)
2778{
2781 HAL_TIM_ChannelStateTypeDef complementary_channel_1_state = TIM_CHANNEL_N_STATE_GET(htim, TIM_CHANNEL_1);
2782 HAL_TIM_ChannelStateTypeDef complementary_channel_2_state = TIM_CHANNEL_N_STATE_GET(htim, TIM_CHANNEL_2);
2783
2784 /* Prevent unused argument(s) compilation warning */
2785 UNUSED(OutputChannel);
2786
2787 /* Check the TIM channels state */
2788 if ((channel_1_state != HAL_TIM_CHANNEL_STATE_READY)
2789 || (channel_2_state != HAL_TIM_CHANNEL_STATE_READY)
2790 || (complementary_channel_1_state != HAL_TIM_CHANNEL_STATE_READY)
2791 || (complementary_channel_2_state != HAL_TIM_CHANNEL_STATE_READY))
2792 {
2793 return HAL_ERROR;
2794 }
2795
2796 /* Set the TIM channels state */
2801
2802 /* Enable the Capture compare and the Input Capture channels
2803 (in the OPM Mode the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2)
2804 if TIM_CHANNEL_1 is used as output, the TIM_CHANNEL_2 will be used as input and
2805 if TIM_CHANNEL_1 is used as input, the TIM_CHANNEL_2 will be used as output
2806 whatever the combination, the TIM_CHANNEL_1 and TIM_CHANNEL_2 should be enabled together
2807
2808 No need to enable the counter, it's enabled automatically by hardware
2809 (the counter starts in response to a stimulus and generate a pulse */
2810
2813
2814 if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
2815 {
2816 /* Enable the main output */
2818 }
2819
2820 /* Return function status */
2821 return HAL_OK;
2822}
2823
2834HAL_StatusTypeDef HAL_TIM_OnePulse_Stop(TIM_HandleTypeDef *htim, uint32_t OutputChannel)
2835{
2836 /* Prevent unused argument(s) compilation warning */
2837 UNUSED(OutputChannel);
2838
2839 /* Disable the Capture compare and the Input Capture channels
2840 (in the OPM Mode the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2)
2841 if TIM_CHANNEL_1 is used as output, the TIM_CHANNEL_2 will be used as input and
2842 if TIM_CHANNEL_1 is used as input, the TIM_CHANNEL_2 will be used as output
2843 whatever the combination, the TIM_CHANNEL_1 and TIM_CHANNEL_2 should be disabled together */
2844
2847
2848 if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
2849 {
2850 /* Disable the Main Output */
2852 }
2853
2854 /* Disable the Peripheral */
2855 __HAL_TIM_DISABLE(htim);
2856
2857 /* Set the TIM channels state */
2862
2863 /* Return function status */
2864 return HAL_OK;
2865}
2866
2878{
2881 HAL_TIM_ChannelStateTypeDef complementary_channel_1_state = TIM_CHANNEL_N_STATE_GET(htim, TIM_CHANNEL_1);
2882 HAL_TIM_ChannelStateTypeDef complementary_channel_2_state = TIM_CHANNEL_N_STATE_GET(htim, TIM_CHANNEL_2);
2883
2884 /* Prevent unused argument(s) compilation warning */
2885 UNUSED(OutputChannel);
2886
2887 /* Check the TIM channels state */
2888 if ((channel_1_state != HAL_TIM_CHANNEL_STATE_READY)
2889 || (channel_2_state != HAL_TIM_CHANNEL_STATE_READY)
2890 || (complementary_channel_1_state != HAL_TIM_CHANNEL_STATE_READY)
2891 || (complementary_channel_2_state != HAL_TIM_CHANNEL_STATE_READY))
2892 {
2893 return HAL_ERROR;
2894 }
2895
2896 /* Set the TIM channels state */
2901
2902 /* Enable the Capture compare and the Input Capture channels
2903 (in the OPM Mode the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2)
2904 if TIM_CHANNEL_1 is used as output, the TIM_CHANNEL_2 will be used as input and
2905 if TIM_CHANNEL_1 is used as input, the TIM_CHANNEL_2 will be used as output
2906 whatever the combination, the TIM_CHANNEL_1 and TIM_CHANNEL_2 should be enabled together
2907
2908 No need to enable the counter, it's enabled automatically by hardware
2909 (the counter starts in response to a stimulus and generate a pulse */
2910
2911 /* Enable the TIM Capture/Compare 1 interrupt */
2913
2914 /* Enable the TIM Capture/Compare 2 interrupt */
2916
2919
2920 if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
2921 {
2922 /* Enable the main output */
2924 }
2925
2926 /* Return function status */
2927 return HAL_OK;
2928}
2929
2941{
2942 /* Prevent unused argument(s) compilation warning */
2943 UNUSED(OutputChannel);
2944
2945 /* Disable the TIM Capture/Compare 1 interrupt */
2947
2948 /* Disable the TIM Capture/Compare 2 interrupt */
2950
2951 /* Disable the Capture compare and the Input Capture channels
2952 (in the OPM Mode the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2)
2953 if TIM_CHANNEL_1 is used as output, the TIM_CHANNEL_2 will be used as input and
2954 if TIM_CHANNEL_1 is used as input, the TIM_CHANNEL_2 will be used as output
2955 whatever the combination, the TIM_CHANNEL_1 and TIM_CHANNEL_2 should be disabled together */
2958
2959 if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
2960 {
2961 /* Disable the Main Output */
2963 }
2964
2965 /* Disable the Peripheral */
2966 __HAL_TIM_DISABLE(htim);
2967
2968 /* Set the TIM channels state */
2973
2974 /* Return function status */
2975 return HAL_OK;
2976}
2977
2981
3020{
3021 uint32_t tmpsmcr;
3022 uint32_t tmpccmr1;
3023 uint32_t tmpccer;
3024
3025 /* Check the TIM handle allocation */
3026 if (htim == NULL)
3027 {
3028 return HAL_ERROR;
3029 }
3030
3031 /* Check the parameters */
3032 assert_param(IS_TIM_ENCODER_INTERFACE_INSTANCE(htim->Instance));
3045 assert_param(IS_TIM_PERIOD(htim, htim->Init.Period));
3046
3047 if (htim->State == HAL_TIM_STATE_RESET)
3048 {
3049 /* Allocate lock resource and initialize it */
3050 htim->Lock = HAL_UNLOCKED;
3051
3052#if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
3053 /* Reset interrupt callbacks to legacy weak callbacks */
3054 TIM_ResetCallback(htim);
3055
3056 if (htim->Encoder_MspInitCallback == NULL)
3057 {
3058 htim->Encoder_MspInitCallback = HAL_TIM_Encoder_MspInit;
3059 }
3060 /* Init the low level hardware : GPIO, CLOCK, NVIC */
3061 htim->Encoder_MspInitCallback(htim);
3062#else
3063 /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */
3065#endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
3066 }
3067
3068 /* Set the TIM state */
3069 htim->State = HAL_TIM_STATE_BUSY;
3070
3071 /* Reset the SMS and ECE bits */
3072 htim->Instance->SMCR &= ~(TIM_SMCR_SMS | TIM_SMCR_ECE);
3073
3074 /* Configure the Time base in the Encoder Mode */
3075 TIM_Base_SetConfig(htim->Instance, &htim->Init);
3076
3077 /* Get the TIMx SMCR register value */
3078 tmpsmcr = htim->Instance->SMCR;
3079
3080 /* Get the TIMx CCMR1 register value */
3081 tmpccmr1 = htim->Instance->CCMR1;
3082
3083 /* Get the TIMx CCER register value */
3084 tmpccer = htim->Instance->CCER;
3085
3086 /* Set the encoder Mode */
3087 tmpsmcr |= sConfig->EncoderMode;
3088
3089 /* Select the Capture Compare 1 and the Capture Compare 2 as input */
3090 tmpccmr1 &= ~(TIM_CCMR1_CC1S | TIM_CCMR1_CC2S);
3091 tmpccmr1 |= (sConfig->IC1Selection | (sConfig->IC2Selection << 8U));
3092
3093 /* Set the Capture Compare 1 and the Capture Compare 2 prescalers and filters */
3094 tmpccmr1 &= ~(TIM_CCMR1_IC1PSC | TIM_CCMR1_IC2PSC);
3095 tmpccmr1 &= ~(TIM_CCMR1_IC1F | TIM_CCMR1_IC2F);
3096 tmpccmr1 |= sConfig->IC1Prescaler | (sConfig->IC2Prescaler << 8U);
3097 tmpccmr1 |= (sConfig->IC1Filter << 4U) | (sConfig->IC2Filter << 12U);
3098
3099 /* Set the TI1 and the TI2 Polarities */
3100 tmpccer &= ~(TIM_CCER_CC1P | TIM_CCER_CC2P);
3101 tmpccer &= ~(TIM_CCER_CC1NP | TIM_CCER_CC2NP);
3102 tmpccer |= sConfig->IC1Polarity | (sConfig->IC2Polarity << 4U);
3103
3104 /* Write to TIMx SMCR */
3105 htim->Instance->SMCR = tmpsmcr;
3106
3107 /* Write to TIMx CCMR1 */
3108 htim->Instance->CCMR1 = tmpccmr1;
3109
3110 /* Write to TIMx CCER */
3111 htim->Instance->CCER = tmpccer;
3112
3113 /* Initialize the DMA burst operation state */
3115
3116 /* Set the TIM channels state */
3121
3122 /* Initialize the TIM state*/
3123 htim->State = HAL_TIM_STATE_READY;
3124
3125 return HAL_OK;
3126}
3127
3128
3135{
3136 /* Check the parameters */
3137 assert_param(IS_TIM_INSTANCE(htim->Instance));
3138
3139 htim->State = HAL_TIM_STATE_BUSY;
3140
3141 /* Disable the TIM Peripheral Clock */
3142 __HAL_TIM_DISABLE(htim);
3143
3144#if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
3145 if (htim->Encoder_MspDeInitCallback == NULL)
3146 {
3147 htim->Encoder_MspDeInitCallback = HAL_TIM_Encoder_MspDeInit;
3148 }
3149 /* DeInit the low level hardware */
3150 htim->Encoder_MspDeInitCallback(htim);
3151#else
3152 /* DeInit the low level hardware: GPIO, CLOCK, NVIC */
3154#endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
3155
3156 /* Change the DMA burst operation state */
3158
3159 /* Set the TIM channels state */
3164
3165 /* Change TIM state */
3166 htim->State = HAL_TIM_STATE_RESET;
3167
3168 /* Release Lock */
3169 __HAL_UNLOCK(htim);
3170
3171 return HAL_OK;
3172}
3173
3180{
3181 /* Prevent unused argument(s) compilation warning */
3182 UNUSED(htim);
3183
3184 /* NOTE : This function should not be modified, when the callback is needed,
3185 the HAL_TIM_Encoder_MspInit could be implemented in the user file
3186 */
3187}
3188
3195{
3196 /* Prevent unused argument(s) compilation warning */
3197 UNUSED(htim);
3198
3199 /* NOTE : This function should not be modified, when the callback is needed,
3200 the HAL_TIM_Encoder_MspDeInit could be implemented in the user file
3201 */
3202}
3203
3215{
3218 HAL_TIM_ChannelStateTypeDef complementary_channel_1_state = TIM_CHANNEL_N_STATE_GET(htim, TIM_CHANNEL_1);
3219 HAL_TIM_ChannelStateTypeDef complementary_channel_2_state = TIM_CHANNEL_N_STATE_GET(htim, TIM_CHANNEL_2);
3220
3221 /* Check the parameters */
3222 assert_param(IS_TIM_ENCODER_INTERFACE_INSTANCE(htim->Instance));
3223
3224 /* Set the TIM channel(s) state */
3225 if (Channel == TIM_CHANNEL_1)
3226 {
3227 if ((channel_1_state != HAL_TIM_CHANNEL_STATE_READY)
3228 || (complementary_channel_1_state != HAL_TIM_CHANNEL_STATE_READY))
3229 {
3230 return HAL_ERROR;
3231 }
3232 else
3233 {
3236 }
3237 }
3238 else if (Channel == TIM_CHANNEL_2)
3239 {
3240 if ((channel_2_state != HAL_TIM_CHANNEL_STATE_READY)
3241 || (complementary_channel_2_state != HAL_TIM_CHANNEL_STATE_READY))
3242 {
3243 return HAL_ERROR;
3244 }
3245 else
3246 {
3249 }
3250 }
3251 else
3252 {
3253 if ((channel_1_state != HAL_TIM_CHANNEL_STATE_READY)
3254 || (channel_2_state != HAL_TIM_CHANNEL_STATE_READY)
3255 || (complementary_channel_1_state != HAL_TIM_CHANNEL_STATE_READY)
3256 || (complementary_channel_2_state != HAL_TIM_CHANNEL_STATE_READY))
3257 {
3258 return HAL_ERROR;
3259 }
3260 else
3261 {
3266 }
3267 }
3268
3269 /* Enable the encoder interface channels */
3270 switch (Channel)
3271 {
3272 case TIM_CHANNEL_1:
3273 {
3275 break;
3276 }
3277
3278 case TIM_CHANNEL_2:
3279 {
3281 break;
3282 }
3283
3284 default :
3285 {
3288 break;
3289 }
3290 }
3291 /* Enable the Peripheral */
3292 __HAL_TIM_ENABLE(htim);
3293
3294 /* Return function status */
3295 return HAL_OK;
3296}
3297
3309{
3310 /* Check the parameters */
3311 assert_param(IS_TIM_ENCODER_INTERFACE_INSTANCE(htim->Instance));
3312
3313 /* Disable the Input Capture channels 1 and 2
3314 (in the EncoderInterface the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2) */
3315 switch (Channel)
3316 {
3317 case TIM_CHANNEL_1:
3318 {
3320 break;
3321 }
3322
3323 case TIM_CHANNEL_2:
3324 {
3326 break;
3327 }
3328
3329 default :
3330 {
3333 break;
3334 }
3335 }
3336
3337 /* Disable the Peripheral */
3338 __HAL_TIM_DISABLE(htim);
3339
3340 /* Set the TIM channel(s) state */
3341 if ((Channel == TIM_CHANNEL_1) || (Channel == TIM_CHANNEL_2))
3342 {
3345 }
3346 else
3347 {
3352 }
3353
3354 /* Return function status */
3355 return HAL_OK;
3356}
3357
3369{
3372 HAL_TIM_ChannelStateTypeDef complementary_channel_1_state = TIM_CHANNEL_N_STATE_GET(htim, TIM_CHANNEL_1);
3373 HAL_TIM_ChannelStateTypeDef complementary_channel_2_state = TIM_CHANNEL_N_STATE_GET(htim, TIM_CHANNEL_2);
3374
3375 /* Check the parameters */
3376 assert_param(IS_TIM_ENCODER_INTERFACE_INSTANCE(htim->Instance));
3377
3378 /* Set the TIM channel(s) state */
3379 if (Channel == TIM_CHANNEL_1)
3380 {
3381 if ((channel_1_state != HAL_TIM_CHANNEL_STATE_READY)
3382 || (complementary_channel_1_state != HAL_TIM_CHANNEL_STATE_READY))
3383 {
3384 return HAL_ERROR;
3385 }
3386 else
3387 {
3390 }
3391 }
3392 else if (Channel == TIM_CHANNEL_2)
3393 {
3394 if ((channel_2_state != HAL_TIM_CHANNEL_STATE_READY)
3395 || (complementary_channel_2_state != HAL_TIM_CHANNEL_STATE_READY))
3396 {
3397 return HAL_ERROR;
3398 }
3399 else
3400 {
3403 }
3404 }
3405 else
3406 {
3407 if ((channel_1_state != HAL_TIM_CHANNEL_STATE_READY)
3408 || (channel_2_state != HAL_TIM_CHANNEL_STATE_READY)
3409 || (complementary_channel_1_state != HAL_TIM_CHANNEL_STATE_READY)
3410 || (complementary_channel_2_state != HAL_TIM_CHANNEL_STATE_READY))
3411 {
3412 return HAL_ERROR;
3413 }
3414 else
3415 {
3420 }
3421 }
3422
3423 /* Enable the encoder interface channels */
3424 /* Enable the capture compare Interrupts 1 and/or 2 */
3425 switch (Channel)
3426 {
3427 case TIM_CHANNEL_1:
3428 {
3431 break;
3432 }
3433
3434 case TIM_CHANNEL_2:
3435 {
3438 break;
3439 }
3440
3441 default :
3442 {
3447 break;
3448 }
3449 }
3450
3451 /* Enable the Peripheral */
3452 __HAL_TIM_ENABLE(htim);
3453
3454 /* Return function status */
3455 return HAL_OK;
3456}
3457
3469{
3470 /* Check the parameters */
3471 assert_param(IS_TIM_ENCODER_INTERFACE_INSTANCE(htim->Instance));
3472
3473 /* Disable the Input Capture channels 1 and 2
3474 (in the EncoderInterface the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2) */
3475 if (Channel == TIM_CHANNEL_1)
3476 {
3478
3479 /* Disable the capture compare Interrupts 1 */
3481 }
3482 else if (Channel == TIM_CHANNEL_2)
3483 {
3485
3486 /* Disable the capture compare Interrupts 2 */
3488 }
3489 else
3490 {
3493
3494 /* Disable the capture compare Interrupts 1 and 2 */
3497 }
3498
3499 /* Disable the Peripheral */
3500 __HAL_TIM_DISABLE(htim);
3501
3502 /* Set the TIM channel(s) state */
3503 if ((Channel == TIM_CHANNEL_1) || (Channel == TIM_CHANNEL_2))
3504 {
3507 }
3508 else
3509 {
3514 }
3515
3516 /* Return function status */
3517 return HAL_OK;
3518}
3519
3533HAL_StatusTypeDef HAL_TIM_Encoder_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData1,
3534 uint32_t *pData2, uint16_t Length)
3535{
3538 HAL_TIM_ChannelStateTypeDef complementary_channel_1_state = TIM_CHANNEL_N_STATE_GET(htim, TIM_CHANNEL_1);
3539 HAL_TIM_ChannelStateTypeDef complementary_channel_2_state = TIM_CHANNEL_N_STATE_GET(htim, TIM_CHANNEL_2);
3540
3541 /* Check the parameters */
3542 assert_param(IS_TIM_ENCODER_INTERFACE_INSTANCE(htim->Instance));
3543
3544 /* Set the TIM channel(s) state */
3545 if (Channel == TIM_CHANNEL_1)
3546 {
3547 if ((channel_1_state == HAL_TIM_CHANNEL_STATE_BUSY)
3548 || (complementary_channel_1_state == HAL_TIM_CHANNEL_STATE_BUSY))
3549 {
3550 return HAL_BUSY;
3551 }
3552 else if ((channel_1_state == HAL_TIM_CHANNEL_STATE_READY)
3553 && (complementary_channel_1_state == HAL_TIM_CHANNEL_STATE_READY))
3554 {
3555 if ((pData1 == NULL) || (Length == 0U))
3556 {
3557 return HAL_ERROR;
3558 }
3559 else
3560 {
3563 }
3564 }
3565 else
3566 {
3567 return HAL_ERROR;
3568 }
3569 }
3570 else if (Channel == TIM_CHANNEL_2)
3571 {
3572 if ((channel_2_state == HAL_TIM_CHANNEL_STATE_BUSY)
3573 || (complementary_channel_2_state == HAL_TIM_CHANNEL_STATE_BUSY))
3574 {
3575 return HAL_BUSY;
3576 }
3577 else if ((channel_2_state == HAL_TIM_CHANNEL_STATE_READY)
3578 && (complementary_channel_2_state == HAL_TIM_CHANNEL_STATE_READY))
3579 {
3580 if ((pData2 == NULL) || (Length == 0U))
3581 {
3582 return HAL_ERROR;
3583 }
3584 else
3585 {
3588 }
3589 }
3590 else
3591 {
3592 return HAL_ERROR;
3593 }
3594 }
3595 else
3596 {
3597 if ((channel_1_state == HAL_TIM_CHANNEL_STATE_BUSY)
3598 || (channel_2_state == HAL_TIM_CHANNEL_STATE_BUSY)
3599 || (complementary_channel_1_state == HAL_TIM_CHANNEL_STATE_BUSY)
3600 || (complementary_channel_2_state == HAL_TIM_CHANNEL_STATE_BUSY))
3601 {
3602 return HAL_BUSY;
3603 }
3604 else if ((channel_1_state == HAL_TIM_CHANNEL_STATE_READY)
3605 && (channel_2_state == HAL_TIM_CHANNEL_STATE_READY)
3606 && (complementary_channel_1_state == HAL_TIM_CHANNEL_STATE_READY)
3607 && (complementary_channel_2_state == HAL_TIM_CHANNEL_STATE_READY))
3608 {
3609 if ((((pData1 == NULL) || (pData2 == NULL))) || (Length == 0U))
3610 {
3611 return HAL_ERROR;
3612 }
3613 else
3614 {
3619 }
3620 }
3621 else
3622 {
3623 return HAL_ERROR;
3624 }
3625 }
3626
3627 switch (Channel)
3628 {
3629 case TIM_CHANNEL_1:
3630 {
3631 /* Set the DMA capture callbacks */
3634
3635 /* Set the DMA error callback */
3637
3638 /* Enable the DMA stream */
3639 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)&htim->Instance->CCR1, (uint32_t)pData1,
3640 Length) != HAL_OK)
3641 {
3642 /* Return error status */
3643 return HAL_ERROR;
3644 }
3645 /* Enable the TIM Input Capture DMA request */
3647
3648 /* Enable the Capture compare channel */
3650
3651 /* Enable the Peripheral */
3652 __HAL_TIM_ENABLE(htim);
3653
3654 break;
3655 }
3656
3657 case TIM_CHANNEL_2:
3658 {
3659 /* Set the DMA capture callbacks */
3662
3663 /* Set the DMA error callback */
3665 /* Enable the DMA stream */
3666 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)&htim->Instance->CCR2, (uint32_t)pData2,
3667 Length) != HAL_OK)
3668 {
3669 /* Return error status */
3670 return HAL_ERROR;
3671 }
3672 /* Enable the TIM Input Capture DMA request */
3674
3675 /* Enable the Capture compare channel */
3677
3678 /* Enable the Peripheral */
3679 __HAL_TIM_ENABLE(htim);
3680
3681 break;
3682 }
3683
3684 default:
3685 {
3686 /* Set the DMA capture callbacks */
3689
3690 /* Set the DMA error callback */
3692
3693 /* Enable the DMA stream */
3694 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)&htim->Instance->CCR1, (uint32_t)pData1,
3695 Length) != HAL_OK)
3696 {
3697 /* Return error status */
3698 return HAL_ERROR;
3699 }
3700
3701 /* Set the DMA capture callbacks */
3704
3705 /* Set the DMA error callback */
3707
3708 /* Enable the DMA stream */
3709 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)&htim->Instance->CCR2, (uint32_t)pData2,
3710 Length) != HAL_OK)
3711 {
3712 /* Return error status */
3713 return HAL_ERROR;
3714 }
3715
3716 /* Enable the TIM Input Capture DMA request */
3718 /* Enable the TIM Input Capture DMA request */
3720
3721 /* Enable the Capture compare channel */
3724
3725 /* Enable the Peripheral */
3726 __HAL_TIM_ENABLE(htim);
3727
3728 break;
3729 }
3730 }
3731
3732 /* Return function status */
3733 return HAL_OK;
3734}
3735
3747{
3748 /* Check the parameters */
3749 assert_param(IS_TIM_ENCODER_INTERFACE_INSTANCE(htim->Instance));
3750
3751 /* Disable the Input Capture channels 1 and 2
3752 (in the EncoderInterface the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2) */
3753 if (Channel == TIM_CHANNEL_1)
3754 {
3756
3757 /* Disable the capture compare DMA Request 1 */
3759 (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC1]);
3760 }
3761 else if (Channel == TIM_CHANNEL_2)
3762 {
3764
3765 /* Disable the capture compare DMA Request 2 */
3767 (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC2]);
3768 }
3769 else
3770 {
3773
3774 /* Disable the capture compare DMA Request 1 and 2 */
3777 (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC1]);
3778 (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC2]);
3779 }
3780
3781 /* Disable the Peripheral */
3782 __HAL_TIM_DISABLE(htim);
3783
3784 /* Set the TIM channel(s) state */
3785 if ((Channel == TIM_CHANNEL_1) || (Channel == TIM_CHANNEL_2))
3786 {
3789 }
3790 else
3791 {
3796 }
3797
3798 /* Return function status */
3799 return HAL_OK;
3800}
3801
3824{
3825 uint32_t itsource = htim->Instance->DIER;
3826 uint32_t itflag = htim->Instance->SR;
3827
3828 /* Capture compare 1 event */
3829 if ((itflag & (TIM_FLAG_CC1)) == (TIM_FLAG_CC1))
3830 {
3831 if ((itsource & (TIM_IT_CC1)) == (TIM_IT_CC1))
3832 {
3833 {
3836
3837 /* Input capture event */
3838 if ((htim->Instance->CCMR1 & TIM_CCMR1_CC1S) != 0x00U)
3839 {
3840#if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
3841 htim->IC_CaptureCallback(htim);
3842#else
3844#endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
3845 }
3846 /* Output compare event */
3847 else
3848 {
3849#if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
3850 htim->OC_DelayElapsedCallback(htim);
3851 htim->PWM_PulseFinishedCallback(htim);
3852#else
3855#endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
3856 }
3858 }
3859 }
3860 }
3861 /* Capture compare 2 event */
3862 if ((itflag & (TIM_FLAG_CC2)) == (TIM_FLAG_CC2))
3863 {
3864 if ((itsource & (TIM_IT_CC2)) == (TIM_IT_CC2))
3865 {
3868 /* Input capture event */
3869 if ((htim->Instance->CCMR1 & TIM_CCMR1_CC2S) != 0x00U)
3870 {
3871#if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
3872 htim->IC_CaptureCallback(htim);
3873#else
3875#endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
3876 }
3877 /* Output compare event */
3878 else
3879 {
3880#if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
3881 htim->OC_DelayElapsedCallback(htim);
3882 htim->PWM_PulseFinishedCallback(htim);
3883#else
3886#endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
3887 }
3889 }
3890 }
3891 /* Capture compare 3 event */
3892 if ((itflag & (TIM_FLAG_CC3)) == (TIM_FLAG_CC3))
3893 {
3894 if ((itsource & (TIM_IT_CC3)) == (TIM_IT_CC3))
3895 {
3898 /* Input capture event */
3899 if ((htim->Instance->CCMR2 & TIM_CCMR2_CC3S) != 0x00U)
3900 {
3901#if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
3902 htim->IC_CaptureCallback(htim);
3903#else
3905#endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
3906 }
3907 /* Output compare event */
3908 else
3909 {
3910#if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
3911 htim->OC_DelayElapsedCallback(htim);
3912 htim->PWM_PulseFinishedCallback(htim);
3913#else
3916#endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
3917 }
3919 }
3920 }
3921 /* Capture compare 4 event */
3922 if ((itflag & (TIM_FLAG_CC4)) == (TIM_FLAG_CC4))
3923 {
3924 if ((itsource & (TIM_IT_CC4)) == (TIM_IT_CC4))
3925 {
3928 /* Input capture event */
3929 if ((htim->Instance->CCMR2 & TIM_CCMR2_CC4S) != 0x00U)
3930 {
3931#if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
3932 htim->IC_CaptureCallback(htim);
3933#else
3935#endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
3936 }
3937 /* Output compare event */
3938 else
3939 {
3940#if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
3941 htim->OC_DelayElapsedCallback(htim);
3942 htim->PWM_PulseFinishedCallback(htim);
3943#else
3946#endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
3947 }
3949 }
3950 }
3951 /* TIM Update event */
3952 if ((itflag & (TIM_FLAG_UPDATE)) == (TIM_FLAG_UPDATE))
3953 {
3954 if ((itsource & (TIM_IT_UPDATE)) == (TIM_IT_UPDATE))
3955 {
3957#if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
3958 htim->PeriodElapsedCallback(htim);
3959#else
3961#endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
3962 }
3963 }
3964 /* TIM Break input event */
3965 if ((itflag & (TIM_FLAG_BREAK)) == (TIM_FLAG_BREAK))
3966 {
3967 if ((itsource & (TIM_IT_BREAK)) == (TIM_IT_BREAK))
3968 {
3970#if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
3971 htim->BreakCallback(htim);
3972#else
3974#endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
3975 }
3976 }
3977 /* TIM Trigger detection event */
3978 if ((itflag & (TIM_FLAG_TRIGGER)) == (TIM_FLAG_TRIGGER))
3979 {
3980 if ((itsource & (TIM_IT_TRIGGER)) == (TIM_IT_TRIGGER))
3981 {
3983#if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
3984 htim->TriggerCallback(htim);
3985#else
3987#endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
3988 }
3989 }
3990 /* TIM commutation event */
3991 if ((itflag & (TIM_FLAG_COM)) == (TIM_FLAG_COM))
3992 {
3993 if ((itsource & (TIM_IT_COM)) == (TIM_IT_COM))
3994 {
3996#if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
3997 htim->CommutationCallback(htim);
3998#else
4000#endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
4001 }
4002 }
4003}
4004
4008
4027
4042 const TIM_OC_InitTypeDef *sConfig,
4043 uint32_t Channel)
4044{
4045 HAL_StatusTypeDef status = HAL_OK;
4046
4047 /* Check the parameters */
4048 assert_param(IS_TIM_CHANNELS(Channel));
4051
4052 /* Process Locked */
4053 __HAL_LOCK(htim);
4054
4055 switch (Channel)
4056 {
4057 case TIM_CHANNEL_1:
4058 {
4059 /* Check the parameters */
4060 assert_param(IS_TIM_CC1_INSTANCE(htim->Instance));
4061
4062 /* Configure the TIM Channel 1 in Output Compare */
4063 TIM_OC1_SetConfig(htim->Instance, sConfig);
4064 break;
4065 }
4066
4067 case TIM_CHANNEL_2:
4068 {
4069 /* Check the parameters */
4070 assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
4071
4072 /* Configure the TIM Channel 2 in Output Compare */
4073 TIM_OC2_SetConfig(htim->Instance, sConfig);
4074 break;
4075 }
4076
4077 case TIM_CHANNEL_3:
4078 {
4079 /* Check the parameters */
4080 assert_param(IS_TIM_CC3_INSTANCE(htim->Instance));
4081
4082 /* Configure the TIM Channel 3 in Output Compare */
4083 TIM_OC3_SetConfig(htim->Instance, sConfig);
4084 break;
4085 }
4086
4087 case TIM_CHANNEL_4:
4088 {
4089 /* Check the parameters */
4090 assert_param(IS_TIM_CC4_INSTANCE(htim->Instance));
4091
4092 /* Configure the TIM Channel 4 in Output Compare */
4093 TIM_OC4_SetConfig(htim->Instance, sConfig);
4094 break;
4095 }
4096
4097 default:
4098 status = HAL_ERROR;
4099 break;
4100 }
4101
4102 __HAL_UNLOCK(htim);
4103
4104 return status;
4105}
4106
4121{
4122 HAL_StatusTypeDef status = HAL_OK;
4123
4124 /* Check the parameters */
4125 assert_param(IS_TIM_CC1_INSTANCE(htim->Instance));
4130
4131 /* Process Locked */
4132 __HAL_LOCK(htim);
4133
4134 if (Channel == TIM_CHANNEL_1)
4135 {
4136 /* TI1 Configuration */
4138 sConfig->ICPolarity,
4139 sConfig->ICSelection,
4140 sConfig->ICFilter);
4141
4142 /* Reset the IC1PSC Bits */
4143 htim->Instance->CCMR1 &= ~TIM_CCMR1_IC1PSC;
4144
4145 /* Set the IC1PSC value */
4146 htim->Instance->CCMR1 |= sConfig->ICPrescaler;
4147 }
4148 else if (Channel == TIM_CHANNEL_2)
4149 {
4150 /* TI2 Configuration */
4151 assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
4152
4153 TIM_TI2_SetConfig(htim->Instance,
4154 sConfig->ICPolarity,
4155 sConfig->ICSelection,
4156 sConfig->ICFilter);
4157
4158 /* Reset the IC2PSC Bits */
4159 htim->Instance->CCMR1 &= ~TIM_CCMR1_IC2PSC;
4160
4161 /* Set the IC2PSC value */
4162 htim->Instance->CCMR1 |= (sConfig->ICPrescaler << 8U);
4163 }
4164 else if (Channel == TIM_CHANNEL_3)
4165 {
4166 /* TI3 Configuration */
4167 assert_param(IS_TIM_CC3_INSTANCE(htim->Instance));
4168
4169 TIM_TI3_SetConfig(htim->Instance,
4170 sConfig->ICPolarity,
4171 sConfig->ICSelection,
4172 sConfig->ICFilter);
4173
4174 /* Reset the IC3PSC Bits */
4175 htim->Instance->CCMR2 &= ~TIM_CCMR2_IC3PSC;
4176
4177 /* Set the IC3PSC value */
4178 htim->Instance->CCMR2 |= sConfig->ICPrescaler;
4179 }
4180 else if (Channel == TIM_CHANNEL_4)
4181 {
4182 /* TI4 Configuration */
4183 assert_param(IS_TIM_CC4_INSTANCE(htim->Instance));
4184
4185 TIM_TI4_SetConfig(htim->Instance,
4186 sConfig->ICPolarity,
4187 sConfig->ICSelection,
4188 sConfig->ICFilter);
4189
4190 /* Reset the IC4PSC Bits */
4191 htim->Instance->CCMR2 &= ~TIM_CCMR2_IC4PSC;
4192
4193 /* Set the IC4PSC value */
4194 htim->Instance->CCMR2 |= (sConfig->ICPrescaler << 8U);
4195 }
4196 else
4197 {
4198 status = HAL_ERROR;
4199 }
4200
4201 __HAL_UNLOCK(htim);
4202
4203 return status;
4204}
4205
4220 const TIM_OC_InitTypeDef *sConfig,
4221 uint32_t Channel)
4222{
4223 HAL_StatusTypeDef status = HAL_OK;
4224
4225 /* Check the parameters */
4226 assert_param(IS_TIM_CHANNELS(Channel));
4230
4231 /* Process Locked */
4232 __HAL_LOCK(htim);
4233
4234 switch (Channel)
4235 {
4236 case TIM_CHANNEL_1:
4237 {
4238 /* Check the parameters */
4239 assert_param(IS_TIM_CC1_INSTANCE(htim->Instance));
4240
4241 /* Configure the Channel 1 in PWM mode */
4242 TIM_OC1_SetConfig(htim->Instance, sConfig);
4243
4244 /* Set the Preload enable bit for channel1 */
4245 htim->Instance->CCMR1 |= TIM_CCMR1_OC1PE;
4246
4247 /* Configure the Output Fast mode */
4248 htim->Instance->CCMR1 &= ~TIM_CCMR1_OC1FE;
4249 htim->Instance->CCMR1 |= sConfig->OCFastMode;
4250 break;
4251 }
4252
4253 case TIM_CHANNEL_2:
4254 {
4255 /* Check the parameters */
4256 assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
4257
4258 /* Configure the Channel 2 in PWM mode */
4259 TIM_OC2_SetConfig(htim->Instance, sConfig);
4260
4261 /* Set the Preload enable bit for channel2 */
4262 htim->Instance->CCMR1 |= TIM_CCMR1_OC2PE;
4263
4264 /* Configure the Output Fast mode */
4265 htim->Instance->CCMR1 &= ~TIM_CCMR1_OC2FE;
4266 htim->Instance->CCMR1 |= sConfig->OCFastMode << 8U;
4267 break;
4268 }
4269
4270 case TIM_CHANNEL_3:
4271 {
4272 /* Check the parameters */
4273 assert_param(IS_TIM_CC3_INSTANCE(htim->Instance));
4274
4275 /* Configure the Channel 3 in PWM mode */
4276 TIM_OC3_SetConfig(htim->Instance, sConfig);
4277
4278 /* Set the Preload enable bit for channel3 */
4279 htim->Instance->CCMR2 |= TIM_CCMR2_OC3PE;
4280
4281 /* Configure the Output Fast mode */
4282 htim->Instance->CCMR2 &= ~TIM_CCMR2_OC3FE;
4283 htim->Instance->CCMR2 |= sConfig->OCFastMode;
4284 break;
4285 }
4286
4287 case TIM_CHANNEL_4:
4288 {
4289 /* Check the parameters */
4290 assert_param(IS_TIM_CC4_INSTANCE(htim->Instance));
4291
4292 /* Configure the Channel 4 in PWM mode */
4293 TIM_OC4_SetConfig(htim->Instance, sConfig);
4294
4295 /* Set the Preload enable bit for channel4 */
4296 htim->Instance->CCMR2 |= TIM_CCMR2_OC4PE;
4297
4298 /* Configure the Output Fast mode */
4299 htim->Instance->CCMR2 &= ~TIM_CCMR2_OC4FE;
4300 htim->Instance->CCMR2 |= sConfig->OCFastMode << 8U;
4301 break;
4302 }
4303
4304 default:
4305 status = HAL_ERROR;
4306 break;
4307 }
4308
4309 __HAL_UNLOCK(htim);
4310
4311 return status;
4312}
4313
4334 uint32_t OutputChannel, uint32_t InputChannel)
4335{
4336 HAL_StatusTypeDef status = HAL_OK;
4337 TIM_OC_InitTypeDef temp1;
4338
4339 /* Check the parameters */
4340 assert_param(IS_TIM_OPM_CHANNELS(OutputChannel));
4341 assert_param(IS_TIM_OPM_CHANNELS(InputChannel));
4342
4343 if (OutputChannel != InputChannel)
4344 {
4345 /* Process Locked */
4346 __HAL_LOCK(htim);
4347
4348 htim->State = HAL_TIM_STATE_BUSY;
4349
4350 /* Extract the Output compare configuration from sConfig structure */
4351 temp1.OCMode = sConfig->OCMode;
4352 temp1.Pulse = sConfig->Pulse;
4353 temp1.OCPolarity = sConfig->OCPolarity;
4354 temp1.OCNPolarity = sConfig->OCNPolarity;
4355 temp1.OCIdleState = sConfig->OCIdleState;
4356 temp1.OCNIdleState = sConfig->OCNIdleState;
4357
4358 switch (OutputChannel)
4359 {
4360 case TIM_CHANNEL_1:
4361 {
4362 assert_param(IS_TIM_CC1_INSTANCE(htim->Instance));
4363
4364 TIM_OC1_SetConfig(htim->Instance, &temp1);
4365 break;
4366 }
4367
4368 case TIM_CHANNEL_2:
4369 {
4370 assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
4371
4372 TIM_OC2_SetConfig(htim->Instance, &temp1);
4373 break;
4374 }
4375
4376 default:
4377 status = HAL_ERROR;
4378 break;
4379 }
4380
4381 if (status == HAL_OK)
4382 {
4383 switch (InputChannel)
4384 {
4385 case TIM_CHANNEL_1:
4386 {
4387 assert_param(IS_TIM_CC1_INSTANCE(htim->Instance));
4388
4389 TIM_TI1_SetConfig(htim->Instance, sConfig->ICPolarity,
4390 sConfig->ICSelection, sConfig->ICFilter);
4391
4392 /* Reset the IC1PSC Bits */
4393 htim->Instance->CCMR1 &= ~TIM_CCMR1_IC1PSC;
4394
4395 /* Select the Trigger source */
4396 htim->Instance->SMCR &= ~TIM_SMCR_TS;
4397 htim->Instance->SMCR |= TIM_TS_TI1FP1;
4398
4399 /* Select the Slave Mode */
4400 htim->Instance->SMCR &= ~TIM_SMCR_SMS;
4401 htim->Instance->SMCR |= TIM_SLAVEMODE_TRIGGER;
4402 break;
4403 }
4404
4405 case TIM_CHANNEL_2:
4406 {
4407 assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
4408
4409 TIM_TI2_SetConfig(htim->Instance, sConfig->ICPolarity,
4410 sConfig->ICSelection, sConfig->ICFilter);
4411
4412 /* Reset the IC2PSC Bits */
4413 htim->Instance->CCMR1 &= ~TIM_CCMR1_IC2PSC;
4414
4415 /* Select the Trigger source */
4416 htim->Instance->SMCR &= ~TIM_SMCR_TS;
4417 htim->Instance->SMCR |= TIM_TS_TI2FP2;
4418
4419 /* Select the Slave Mode */
4420 htim->Instance->SMCR &= ~TIM_SMCR_SMS;
4421 htim->Instance->SMCR |= TIM_SLAVEMODE_TRIGGER;
4422 break;
4423 }
4424
4425 default:
4426 status = HAL_ERROR;
4427 break;
4428 }
4429 }
4430
4431 htim->State = HAL_TIM_STATE_READY;
4432
4433 __HAL_UNLOCK(htim);
4434
4435 return status;
4436 }
4437 else
4438 {
4439 return HAL_ERROR;
4440 }
4441}
4442
4481HAL_StatusTypeDef HAL_TIM_DMABurst_WriteStart(TIM_HandleTypeDef *htim, uint32_t BurstBaseAddress,
4482 uint32_t BurstRequestSrc, const uint32_t *BurstBuffer,
4483 uint32_t BurstLength)
4484{
4485 HAL_StatusTypeDef status;
4486
4487 status = HAL_TIM_DMABurst_MultiWriteStart(htim, BurstBaseAddress, BurstRequestSrc, BurstBuffer, BurstLength,
4488 ((BurstLength) >> 8U) + 1U);
4489
4490
4491 return status;
4492}
4493
4534 uint32_t BurstRequestSrc, const uint32_t *BurstBuffer,
4535 uint32_t BurstLength, uint32_t DataLength)
4536{
4537 HAL_StatusTypeDef status = HAL_OK;
4538
4539 /* Check the parameters */
4540 assert_param(IS_TIM_DMABURST_INSTANCE(htim->Instance));
4541 assert_param(IS_TIM_DMA_BASE(BurstBaseAddress));
4542 assert_param(IS_TIM_DMA_SOURCE(BurstRequestSrc));
4543 assert_param(IS_TIM_DMA_LENGTH(BurstLength));
4545
4547 {
4548 return HAL_BUSY;
4549 }
4550 else if (htim->DMABurstState == HAL_DMA_BURST_STATE_READY)
4551 {
4552 if ((BurstBuffer == NULL) && (BurstLength > 0U))
4553 {
4554 return HAL_ERROR;
4555 }
4556 else
4557 {
4559 }
4560 }
4561 else
4562 {
4563 /* nothing to do */
4564 }
4565
4566 switch (BurstRequestSrc)
4567 {
4568 case TIM_DMA_UPDATE:
4569 {
4570 /* Set the DMA Period elapsed callbacks */
4571 htim->hdma[TIM_DMA_ID_UPDATE]->XferCpltCallback = TIM_DMAPeriodElapsedCplt;
4572 htim->hdma[TIM_DMA_ID_UPDATE]->XferHalfCpltCallback = TIM_DMAPeriodElapsedHalfCplt;
4573
4574 /* Set the DMA error callback */
4576
4577 /* Enable the DMA stream */
4578 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_UPDATE], (uint32_t)BurstBuffer,
4579 (uint32_t)&htim->Instance->DMAR, DataLength) != HAL_OK)
4580 {
4581 /* Return error status */
4582 return HAL_ERROR;
4583 }
4584 break;
4585 }
4586 case TIM_DMA_CC1:
4587 {
4588 /* Set the DMA compare callbacks */
4589 htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMADelayPulseCplt;
4591
4592 /* Set the DMA error callback */
4594
4595 /* Enable the DMA stream */
4596 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)BurstBuffer,
4597 (uint32_t)&htim->Instance->DMAR, DataLength) != HAL_OK)
4598 {
4599 /* Return error status */
4600 return HAL_ERROR;
4601 }
4602 break;
4603 }
4604 case TIM_DMA_CC2:
4605 {
4606 /* Set the DMA compare callbacks */
4607 htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = TIM_DMADelayPulseCplt;
4609
4610 /* Set the DMA error callback */
4612
4613 /* Enable the DMA stream */
4614 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)BurstBuffer,
4615 (uint32_t)&htim->Instance->DMAR, DataLength) != HAL_OK)
4616 {
4617 /* Return error status */
4618 return HAL_ERROR;
4619 }
4620 break;
4621 }
4622 case TIM_DMA_CC3:
4623 {
4624 /* Set the DMA compare callbacks */
4625 htim->hdma[TIM_DMA_ID_CC3]->XferCpltCallback = TIM_DMADelayPulseCplt;
4627
4628 /* Set the DMA error callback */
4630
4631 /* Enable the DMA stream */
4632 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)BurstBuffer,
4633 (uint32_t)&htim->Instance->DMAR, DataLength) != HAL_OK)
4634 {
4635 /* Return error status */
4636 return HAL_ERROR;
4637 }
4638 break;
4639 }
4640 case TIM_DMA_CC4:
4641 {
4642 /* Set the DMA compare callbacks */
4643 htim->hdma[TIM_DMA_ID_CC4]->XferCpltCallback = TIM_DMADelayPulseCplt;
4645
4646 /* Set the DMA error callback */
4648
4649 /* Enable the DMA stream */
4650 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC4], (uint32_t)BurstBuffer,
4651 (uint32_t)&htim->Instance->DMAR, DataLength) != HAL_OK)
4652 {
4653 /* Return error status */
4654 return HAL_ERROR;
4655 }
4656 break;
4657 }
4658 case TIM_DMA_COM:
4659 {
4660 /* Set the DMA commutation callbacks */
4663
4664 /* Set the DMA error callback */
4666
4667 /* Enable the DMA stream */
4668 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_COMMUTATION], (uint32_t)BurstBuffer,
4669 (uint32_t)&htim->Instance->DMAR, DataLength) != HAL_OK)
4670 {
4671 /* Return error status */
4672 return HAL_ERROR;
4673 }
4674 break;
4675 }
4676 case TIM_DMA_TRIGGER:
4677 {
4678 /* Set the DMA trigger callbacks */
4679 htim->hdma[TIM_DMA_ID_TRIGGER]->XferCpltCallback = TIM_DMATriggerCplt;
4680 htim->hdma[TIM_DMA_ID_TRIGGER]->XferHalfCpltCallback = TIM_DMATriggerHalfCplt;
4681
4682 /* Set the DMA error callback */
4684
4685 /* Enable the DMA stream */
4686 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_TRIGGER], (uint32_t)BurstBuffer,
4687 (uint32_t)&htim->Instance->DMAR, DataLength) != HAL_OK)
4688 {
4689 /* Return error status */
4690 return HAL_ERROR;
4691 }
4692 break;
4693 }
4694 default:
4695 status = HAL_ERROR;
4696 break;
4697 }
4698
4699 if (status == HAL_OK)
4700 {
4701 /* Configure the DMA Burst Mode */
4702 htim->Instance->DCR = (BurstBaseAddress | BurstLength);
4703 /* Enable the TIM DMA Request */
4704 __HAL_TIM_ENABLE_DMA(htim, BurstRequestSrc);
4705 }
4706
4707 /* Return function status */
4708 return status;
4709}
4710
4717HAL_StatusTypeDef HAL_TIM_DMABurst_WriteStop(TIM_HandleTypeDef *htim, uint32_t BurstRequestSrc)
4718{
4719 HAL_StatusTypeDef status = HAL_OK;
4720
4721 /* Check the parameters */
4722 assert_param(IS_TIM_DMA_SOURCE(BurstRequestSrc));
4723
4724 /* Abort the DMA transfer (at least disable the DMA stream) */
4725 switch (BurstRequestSrc)
4726 {
4727 case TIM_DMA_UPDATE:
4728 {
4730 break;
4731 }
4732 case TIM_DMA_CC1:
4733 {
4734 (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC1]);
4735 break;
4736 }
4737 case TIM_DMA_CC2:
4738 {
4739 (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC2]);
4740 break;
4741 }
4742 case TIM_DMA_CC3:
4743 {
4744 (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC3]);
4745 break;
4746 }
4747 case TIM_DMA_CC4:
4748 {
4749 (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC4]);
4750 break;
4751 }
4752 case TIM_DMA_COM:
4753 {
4755 break;
4756 }
4757 case TIM_DMA_TRIGGER:
4758 {
4760 break;
4761 }
4762 default:
4763 status = HAL_ERROR;
4764 break;
4765 }
4766
4767 if (status == HAL_OK)
4768 {
4769 /* Disable the TIM Update DMA request */
4770 __HAL_TIM_DISABLE_DMA(htim, BurstRequestSrc);
4771
4772 /* Change the DMA burst operation state */
4774 }
4775
4776 /* Return function status */
4777 return status;
4778}
4779
4818HAL_StatusTypeDef HAL_TIM_DMABurst_ReadStart(TIM_HandleTypeDef *htim, uint32_t BurstBaseAddress,
4819 uint32_t BurstRequestSrc, uint32_t *BurstBuffer, uint32_t BurstLength)
4820{
4821 HAL_StatusTypeDef status;
4822
4823 status = HAL_TIM_DMABurst_MultiReadStart(htim, BurstBaseAddress, BurstRequestSrc, BurstBuffer, BurstLength,
4824 ((BurstLength) >> 8U) + 1U);
4825
4826
4827 return status;
4828}
4829
4870 uint32_t BurstRequestSrc, uint32_t *BurstBuffer,
4871 uint32_t BurstLength, uint32_t DataLength)
4872{
4873 HAL_StatusTypeDef status = HAL_OK;
4874
4875 /* Check the parameters */
4876 assert_param(IS_TIM_DMABURST_INSTANCE(htim->Instance));
4877 assert_param(IS_TIM_DMA_BASE(BurstBaseAddress));
4878 assert_param(IS_TIM_DMA_SOURCE(BurstRequestSrc));
4879 assert_param(IS_TIM_DMA_LENGTH(BurstLength));
4881
4883 {
4884 return HAL_BUSY;
4885 }
4886 else if (htim->DMABurstState == HAL_DMA_BURST_STATE_READY)
4887 {
4888 if ((BurstBuffer == NULL) && (BurstLength > 0U))
4889 {
4890 return HAL_ERROR;
4891 }
4892 else
4893 {
4895 }
4896 }
4897 else
4898 {
4899 /* nothing to do */
4900 }
4901 switch (BurstRequestSrc)
4902 {
4903 case TIM_DMA_UPDATE:
4904 {
4905 /* Set the DMA Period elapsed callbacks */
4906 htim->hdma[TIM_DMA_ID_UPDATE]->XferCpltCallback = TIM_DMAPeriodElapsedCplt;
4907 htim->hdma[TIM_DMA_ID_UPDATE]->XferHalfCpltCallback = TIM_DMAPeriodElapsedHalfCplt;
4908
4909 /* Set the DMA error callback */
4911
4912 /* Enable the DMA stream */
4913 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_UPDATE], (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer,
4914 DataLength) != HAL_OK)
4915 {
4916 /* Return error status */
4917 return HAL_ERROR;
4918 }
4919 break;
4920 }
4921 case TIM_DMA_CC1:
4922 {
4923 /* Set the DMA capture callbacks */
4926
4927 /* Set the DMA error callback */
4929
4930 /* Enable the DMA stream */
4931 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer,
4932 DataLength) != HAL_OK)
4933 {
4934 /* Return error status */
4935 return HAL_ERROR;
4936 }
4937 break;
4938 }
4939 case TIM_DMA_CC2:
4940 {
4941 /* Set the DMA capture callbacks */
4944
4945 /* Set the DMA error callback */
4947
4948 /* Enable the DMA stream */
4949 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer,
4950 DataLength) != HAL_OK)
4951 {
4952 /* Return error status */
4953 return HAL_ERROR;
4954 }
4955 break;
4956 }
4957 case TIM_DMA_CC3:
4958 {
4959 /* Set the DMA capture callbacks */
4962
4963 /* Set the DMA error callback */
4965
4966 /* Enable the DMA stream */
4967 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer,
4968 DataLength) != HAL_OK)
4969 {
4970 /* Return error status */
4971 return HAL_ERROR;
4972 }
4973 break;
4974 }
4975 case TIM_DMA_CC4:
4976 {
4977 /* Set the DMA capture callbacks */
4980
4981 /* Set the DMA error callback */
4983
4984 /* Enable the DMA stream */
4985 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC4], (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer,
4986 DataLength) != HAL_OK)
4987 {
4988 /* Return error status */
4989 return HAL_ERROR;
4990 }
4991 break;
4992 }
4993 case TIM_DMA_COM:
4994 {
4995 /* Set the DMA commutation callbacks */
4998
4999 /* Set the DMA error callback */
5001
5002 /* Enable the DMA stream */
5003 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_COMMUTATION], (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer,
5004 DataLength) != HAL_OK)
5005 {
5006 /* Return error status */
5007 return HAL_ERROR;
5008 }
5009 break;
5010 }
5011 case TIM_DMA_TRIGGER:
5012 {
5013 /* Set the DMA trigger callbacks */
5014 htim->hdma[TIM_DMA_ID_TRIGGER]->XferCpltCallback = TIM_DMATriggerCplt;
5015 htim->hdma[TIM_DMA_ID_TRIGGER]->XferHalfCpltCallback = TIM_DMATriggerHalfCplt;
5016
5017 /* Set the DMA error callback */
5019
5020 /* Enable the DMA stream */
5021 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_TRIGGER], (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer,
5022 DataLength) != HAL_OK)
5023 {
5024 /* Return error status */
5025 return HAL_ERROR;
5026 }
5027 break;
5028 }
5029 default:
5030 status = HAL_ERROR;
5031 break;
5032 }
5033
5034 if (status == HAL_OK)
5035 {
5036 /* Configure the DMA Burst Mode */
5037 htim->Instance->DCR = (BurstBaseAddress | BurstLength);
5038
5039 /* Enable the TIM DMA Request */
5040 __HAL_TIM_ENABLE_DMA(htim, BurstRequestSrc);
5041 }
5042
5043 /* Return function status */
5044 return status;
5045}
5046
5053HAL_StatusTypeDef HAL_TIM_DMABurst_ReadStop(TIM_HandleTypeDef *htim, uint32_t BurstRequestSrc)
5054{
5055 HAL_StatusTypeDef status = HAL_OK;
5056
5057 /* Check the parameters */
5058 assert_param(IS_TIM_DMA_SOURCE(BurstRequestSrc));
5059
5060 /* Abort the DMA transfer (at least disable the DMA stream) */
5061 switch (BurstRequestSrc)
5062 {
5063 case TIM_DMA_UPDATE:
5064 {
5066 break;
5067 }
5068 case TIM_DMA_CC1:
5069 {
5070 (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC1]);
5071 break;
5072 }
5073 case TIM_DMA_CC2:
5074 {
5075 (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC2]);
5076 break;
5077 }
5078 case TIM_DMA_CC3:
5079 {
5080 (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC3]);
5081 break;
5082 }
5083 case TIM_DMA_CC4:
5084 {
5085 (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC4]);
5086 break;
5087 }
5088 case TIM_DMA_COM:
5089 {
5091 break;
5092 }
5093 case TIM_DMA_TRIGGER:
5094 {
5096 break;
5097 }
5098 default:
5099 status = HAL_ERROR;
5100 break;
5101 }
5102
5103 if (status == HAL_OK)
5104 {
5105 /* Disable the TIM Update DMA request */
5106 __HAL_TIM_DISABLE_DMA(htim, BurstRequestSrc);
5107
5108 /* Change the DMA burst operation state */
5110 }
5111
5112 /* Return function status */
5113 return status;
5114}
5115
5135
5137{
5138 /* Check the parameters */
5139 assert_param(IS_TIM_INSTANCE(htim->Instance));
5140 assert_param(IS_TIM_EVENT_SOURCE(EventSource));
5141
5142 /* Process Locked */
5143 __HAL_LOCK(htim);
5144
5145 /* Change the TIM state */
5146 htim->State = HAL_TIM_STATE_BUSY;
5147
5148 /* Set the event sources */
5149 htim->Instance->EGR = EventSource;
5150
5151 /* Change the TIM state */
5152 htim->State = HAL_TIM_STATE_READY;
5153
5154 __HAL_UNLOCK(htim);
5155
5156 /* Return function status */
5157 return HAL_OK;
5158}
5159
5174 const TIM_ClearInputConfigTypeDef *sClearInputConfig,
5175 uint32_t Channel)
5176{
5177 HAL_StatusTypeDef status = HAL_OK;
5178
5179 /* Check the parameters */
5180 assert_param(IS_TIM_OCXREF_CLEAR_INSTANCE(htim->Instance));
5182
5183 /* Process Locked */
5184 __HAL_LOCK(htim);
5185
5186 htim->State = HAL_TIM_STATE_BUSY;
5187
5188 switch (sClearInputConfig->ClearInputSource)
5189 {
5191 {
5192 /* Clear the OCREF clear selection bit and the the ETR Bits */
5193 CLEAR_BIT(htim->Instance->SMCR, (TIM_SMCR_ETF | TIM_SMCR_ETPS | TIM_SMCR_ECE | TIM_SMCR_ETP));
5194 break;
5195 }
5196
5198 {
5199 /* Check the parameters */
5203
5204 /* When OCRef clear feature is used with ETR source, ETR prescaler must be off */
5205 if (sClearInputConfig->ClearInputPrescaler != TIM_CLEARINPUTPRESCALER_DIV1)
5206 {
5207 htim->State = HAL_TIM_STATE_READY;
5208 __HAL_UNLOCK(htim);
5209 return HAL_ERROR;
5210 }
5211
5213 sClearInputConfig->ClearInputPrescaler,
5214 sClearInputConfig->ClearInputPolarity,
5215 sClearInputConfig->ClearInputFilter);
5216 break;
5217 }
5218
5219 default:
5220 status = HAL_ERROR;
5221 break;
5222 }
5223
5224 if (status == HAL_OK)
5225 {
5226 switch (Channel)
5227 {
5228 case TIM_CHANNEL_1:
5229 {
5230 if (sClearInputConfig->ClearInputState != (uint32_t)DISABLE)
5231 {
5232 /* Enable the OCREF clear feature for Channel 1 */
5233 SET_BIT(htim->Instance->CCMR1, TIM_CCMR1_OC1CE);
5234 }
5235 else
5236 {
5237 /* Disable the OCREF clear feature for Channel 1 */
5238 CLEAR_BIT(htim->Instance->CCMR1, TIM_CCMR1_OC1CE);
5239 }
5240 break;
5241 }
5242 case TIM_CHANNEL_2:
5243 {
5244 if (sClearInputConfig->ClearInputState != (uint32_t)DISABLE)
5245 {
5246 /* Enable the OCREF clear feature for Channel 2 */
5247 SET_BIT(htim->Instance->CCMR1, TIM_CCMR1_OC2CE);
5248 }
5249 else
5250 {
5251 /* Disable the OCREF clear feature for Channel 2 */
5252 CLEAR_BIT(htim->Instance->CCMR1, TIM_CCMR1_OC2CE);
5253 }
5254 break;
5255 }
5256 case TIM_CHANNEL_3:
5257 {
5258 if (sClearInputConfig->ClearInputState != (uint32_t)DISABLE)
5259 {
5260 /* Enable the OCREF clear feature for Channel 3 */
5261 SET_BIT(htim->Instance->CCMR2, TIM_CCMR2_OC3CE);
5262 }
5263 else
5264 {
5265 /* Disable the OCREF clear feature for Channel 3 */
5266 CLEAR_BIT(htim->Instance->CCMR2, TIM_CCMR2_OC3CE);
5267 }
5268 break;
5269 }
5270 case TIM_CHANNEL_4:
5271 {
5272 if (sClearInputConfig->ClearInputState != (uint32_t)DISABLE)
5273 {
5274 /* Enable the OCREF clear feature for Channel 4 */
5275 SET_BIT(htim->Instance->CCMR2, TIM_CCMR2_OC4CE);
5276 }
5277 else
5278 {
5279 /* Disable the OCREF clear feature for Channel 4 */
5280 CLEAR_BIT(htim->Instance->CCMR2, TIM_CCMR2_OC4CE);
5281 }
5282 break;
5283 }
5284 default:
5285 break;
5286 }
5287 }
5288
5289 htim->State = HAL_TIM_STATE_READY;
5290
5291 __HAL_UNLOCK(htim);
5292
5293 return status;
5294}
5295
5304{
5305 HAL_StatusTypeDef status = HAL_OK;
5306 uint32_t tmpsmcr;
5307
5308 /* Process Locked */
5309 __HAL_LOCK(htim);
5310
5311 htim->State = HAL_TIM_STATE_BUSY;
5312
5313 /* Check the parameters */
5314 assert_param(IS_TIM_CLOCKSOURCE(sClockSourceConfig->ClockSource));
5315
5316 /* Reset the SMS, TS, ECE, ETPS and ETRF bits */
5317 tmpsmcr = htim->Instance->SMCR;
5318 tmpsmcr &= ~(TIM_SMCR_SMS | TIM_SMCR_TS);
5319 tmpsmcr &= ~(TIM_SMCR_ETF | TIM_SMCR_ETPS | TIM_SMCR_ECE | TIM_SMCR_ETP);
5320 htim->Instance->SMCR = tmpsmcr;
5321
5322 switch (sClockSourceConfig->ClockSource)
5323 {
5325 {
5326 assert_param(IS_TIM_INSTANCE(htim->Instance));
5327 break;
5328 }
5329
5331 {
5332 /* Check whether or not the timer instance supports external trigger input mode 1 (ETRF)*/
5333 assert_param(IS_TIM_CLOCKSOURCE_ETRMODE1_INSTANCE(htim->Instance));
5334
5335 /* Check ETR input conditioning related parameters */
5337 assert_param(IS_TIM_CLOCKPOLARITY(sClockSourceConfig->ClockPolarity));
5338 assert_param(IS_TIM_CLOCKFILTER(sClockSourceConfig->ClockFilter));
5339
5340 /* Configure the ETR Clock source */
5342 sClockSourceConfig->ClockPrescaler,
5343 sClockSourceConfig->ClockPolarity,
5344 sClockSourceConfig->ClockFilter);
5345
5346 /* Select the External clock mode1 and the ETRF trigger */
5347 tmpsmcr = htim->Instance->SMCR;
5349 /* Write to TIMx SMCR */
5350 htim->Instance->SMCR = tmpsmcr;
5351 break;
5352 }
5353
5355 {
5356 /* Check whether or not the timer instance supports external trigger input mode 2 (ETRF)*/
5357 assert_param(IS_TIM_CLOCKSOURCE_ETRMODE2_INSTANCE(htim->Instance));
5358
5359 /* Check ETR input conditioning related parameters */
5361 assert_param(IS_TIM_CLOCKPOLARITY(sClockSourceConfig->ClockPolarity));
5362 assert_param(IS_TIM_CLOCKFILTER(sClockSourceConfig->ClockFilter));
5363
5364 /* Configure the ETR Clock source */
5366 sClockSourceConfig->ClockPrescaler,
5367 sClockSourceConfig->ClockPolarity,
5368 sClockSourceConfig->ClockFilter);
5369 /* Enable the External clock mode2 */
5370 htim->Instance->SMCR |= TIM_SMCR_ECE;
5371 break;
5372 }
5373
5375 {
5376 /* Check whether or not the timer instance supports external clock mode 1 */
5377 assert_param(IS_TIM_CLOCKSOURCE_TIX_INSTANCE(htim->Instance));
5378
5379 /* Check TI1 input conditioning related parameters */
5380 assert_param(IS_TIM_CLOCKPOLARITY(sClockSourceConfig->ClockPolarity));
5381 assert_param(IS_TIM_CLOCKFILTER(sClockSourceConfig->ClockFilter));
5382
5383 TIM_TI1_ConfigInputStage(htim->Instance,
5384 sClockSourceConfig->ClockPolarity,
5385 sClockSourceConfig->ClockFilter);
5386 TIM_ITRx_SetConfig(htim->Instance, TIM_CLOCKSOURCE_TI1);
5387 break;
5388 }
5389
5391 {
5392 /* Check whether or not the timer instance supports external clock mode 1 (ETRF)*/
5393 assert_param(IS_TIM_CLOCKSOURCE_TIX_INSTANCE(htim->Instance));
5394
5395 /* Check TI2 input conditioning related parameters */
5396 assert_param(IS_TIM_CLOCKPOLARITY(sClockSourceConfig->ClockPolarity));
5397 assert_param(IS_TIM_CLOCKFILTER(sClockSourceConfig->ClockFilter));
5398
5399 TIM_TI2_ConfigInputStage(htim->Instance,
5400 sClockSourceConfig->ClockPolarity,
5401 sClockSourceConfig->ClockFilter);
5402 TIM_ITRx_SetConfig(htim->Instance, TIM_CLOCKSOURCE_TI2);
5403 break;
5404 }
5405
5407 {
5408 /* Check whether or not the timer instance supports external clock mode 1 */
5409 assert_param(IS_TIM_CLOCKSOURCE_TIX_INSTANCE(htim->Instance));
5410
5411 /* Check TI1 input conditioning related parameters */
5412 assert_param(IS_TIM_CLOCKPOLARITY(sClockSourceConfig->ClockPolarity));
5413 assert_param(IS_TIM_CLOCKFILTER(sClockSourceConfig->ClockFilter));
5414
5415 TIM_TI1_ConfigInputStage(htim->Instance,
5416 sClockSourceConfig->ClockPolarity,
5417 sClockSourceConfig->ClockFilter);
5418 TIM_ITRx_SetConfig(htim->Instance, TIM_CLOCKSOURCE_TI1ED);
5419 break;
5420 }
5421
5426 {
5427 /* Check whether or not the timer instance supports internal trigger input */
5428 assert_param(IS_TIM_CLOCKSOURCE_ITRX_INSTANCE(htim->Instance));
5429
5430 TIM_ITRx_SetConfig(htim->Instance, sClockSourceConfig->ClockSource);
5431 break;
5432 }
5433
5434 default:
5435 status = HAL_ERROR;
5436 break;
5437 }
5438 htim->State = HAL_TIM_STATE_READY;
5439
5440 __HAL_UNLOCK(htim);
5441
5442 return status;
5443}
5444
5457HAL_StatusTypeDef HAL_TIM_ConfigTI1Input(TIM_HandleTypeDef *htim, uint32_t TI1_Selection)
5458{
5459 uint32_t tmpcr2;
5460
5461 /* Check the parameters */
5462 assert_param(IS_TIM_XOR_INSTANCE(htim->Instance));
5463 assert_param(IS_TIM_TI1SELECTION(TI1_Selection));
5464
5465 /* Get the TIMx CR2 register value */
5466 tmpcr2 = htim->Instance->CR2;
5467
5468 /* Reset the TI1 selection */
5469 tmpcr2 &= ~TIM_CR2_TI1S;
5470
5471 /* Set the TI1 selection */
5472 tmpcr2 |= TI1_Selection;
5473
5474 /* Write to TIMxCR2 */
5475 htim->Instance->CR2 = tmpcr2;
5476
5477 return HAL_OK;
5478}
5479
5490{
5491 /* Check the parameters */
5492 assert_param(IS_TIM_SLAVE_INSTANCE(htim->Instance));
5495
5496 __HAL_LOCK(htim);
5497
5498 htim->State = HAL_TIM_STATE_BUSY;
5499
5500 if (TIM_SlaveTimer_SetConfig(htim, sSlaveConfig) != HAL_OK)
5501 {
5502 htim->State = HAL_TIM_STATE_READY;
5503 __HAL_UNLOCK(htim);
5504 return HAL_ERROR;
5505 }
5506
5507 /* Disable Trigger Interrupt */
5509
5510 /* Disable Trigger DMA request */
5512
5513 htim->State = HAL_TIM_STATE_READY;
5514
5515 __HAL_UNLOCK(htim);
5516
5517 return HAL_OK;
5518}
5519
5530 const TIM_SlaveConfigTypeDef *sSlaveConfig)
5531{
5532 /* Check the parameters */
5533 assert_param(IS_TIM_SLAVE_INSTANCE(htim->Instance));
5536
5537 __HAL_LOCK(htim);
5538
5539 htim->State = HAL_TIM_STATE_BUSY;
5540
5541 if (TIM_SlaveTimer_SetConfig(htim, sSlaveConfig) != HAL_OK)
5542 {
5543 htim->State = HAL_TIM_STATE_READY;
5544 __HAL_UNLOCK(htim);
5545 return HAL_ERROR;
5546 }
5547
5548 /* Enable Trigger Interrupt */
5550
5551 /* Disable Trigger DMA request */
5553
5554 htim->State = HAL_TIM_STATE_READY;
5555
5556 __HAL_UNLOCK(htim);
5557
5558 return HAL_OK;
5559}
5560
5572uint32_t HAL_TIM_ReadCapturedValue(const TIM_HandleTypeDef *htim, uint32_t Channel)
5573{
5574 uint32_t tmpreg = 0U;
5575
5576 switch (Channel)
5577 {
5578 case TIM_CHANNEL_1:
5579 {
5580 /* Check the parameters */
5581 assert_param(IS_TIM_CC1_INSTANCE(htim->Instance));
5582
5583 /* Return the capture 1 value */
5584 tmpreg = htim->Instance->CCR1;
5585
5586 break;
5587 }
5588 case TIM_CHANNEL_2:
5589 {
5590 /* Check the parameters */
5591 assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
5592
5593 /* Return the capture 2 value */
5594 tmpreg = htim->Instance->CCR2;
5595
5596 break;
5597 }
5598
5599 case TIM_CHANNEL_3:
5600 {
5601 /* Check the parameters */
5602 assert_param(IS_TIM_CC3_INSTANCE(htim->Instance));
5603
5604 /* Return the capture 3 value */
5605 tmpreg = htim->Instance->CCR3;
5606
5607 break;
5608 }
5609
5610 case TIM_CHANNEL_4:
5611 {
5612 /* Check the parameters */
5613 assert_param(IS_TIM_CC4_INSTANCE(htim->Instance));
5614
5615 /* Return the capture 4 value */
5616 tmpreg = htim->Instance->CCR4;
5617
5618 break;
5619 }
5620
5621 default:
5622 break;
5623 }
5624
5625 return tmpreg;
5626}
5627
5631
5650
5657{
5658 /* Prevent unused argument(s) compilation warning */
5659 UNUSED(htim);
5660
5661 /* NOTE : This function should not be modified, when the callback is needed,
5662 the HAL_TIM_PeriodElapsedCallback could be implemented in the user file
5663 */
5664}
5665
5672{
5673 /* Prevent unused argument(s) compilation warning */
5674 UNUSED(htim);
5675
5676 /* NOTE : This function should not be modified, when the callback is needed,
5677 the HAL_TIM_PeriodElapsedHalfCpltCallback could be implemented in the user file
5678 */
5679}
5680
5687{
5688 /* Prevent unused argument(s) compilation warning */
5689 UNUSED(htim);
5690
5691 /* NOTE : This function should not be modified, when the callback is needed,
5692 the HAL_TIM_OC_DelayElapsedCallback could be implemented in the user file
5693 */
5694}
5695
5702{
5703 /* Prevent unused argument(s) compilation warning */
5704 UNUSED(htim);
5705
5706 /* NOTE : This function should not be modified, when the callback is needed,
5707 the HAL_TIM_IC_CaptureCallback could be implemented in the user file
5708 */
5709}
5710
5717{
5718 /* Prevent unused argument(s) compilation warning */
5719 UNUSED(htim);
5720
5721 /* NOTE : This function should not be modified, when the callback is needed,
5722 the HAL_TIM_IC_CaptureHalfCpltCallback could be implemented in the user file
5723 */
5724}
5725
5732{
5733 /* Prevent unused argument(s) compilation warning */
5734 UNUSED(htim);
5735
5736 /* NOTE : This function should not be modified, when the callback is needed,
5737 the HAL_TIM_PWM_PulseFinishedCallback could be implemented in the user file
5738 */
5739}
5740
5747{
5748 /* Prevent unused argument(s) compilation warning */
5749 UNUSED(htim);
5750
5751 /* NOTE : This function should not be modified, when the callback is needed,
5752 the HAL_TIM_PWM_PulseFinishedHalfCpltCallback could be implemented in the user file
5753 */
5754}
5755
5762{
5763 /* Prevent unused argument(s) compilation warning */
5764 UNUSED(htim);
5765
5766 /* NOTE : This function should not be modified, when the callback is needed,
5767 the HAL_TIM_TriggerCallback could be implemented in the user file
5768 */
5769}
5770
5777{
5778 /* Prevent unused argument(s) compilation warning */
5779 UNUSED(htim);
5780
5781 /* NOTE : This function should not be modified, when the callback is needed,
5782 the HAL_TIM_TriggerHalfCpltCallback could be implemented in the user file
5783 */
5784}
5785
5792{
5793 /* Prevent unused argument(s) compilation warning */
5794 UNUSED(htim);
5795
5796 /* NOTE : This function should not be modified, when the callback is needed,
5797 the HAL_TIM_ErrorCallback could be implemented in the user file
5798 */
5799}
5800
5801#if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
5837HAL_StatusTypeDef HAL_TIM_RegisterCallback(TIM_HandleTypeDef *htim, HAL_TIM_CallbackIDTypeDef CallbackID,
5838 pTIM_CallbackTypeDef pCallback)
5839{
5840 HAL_StatusTypeDef status = HAL_OK;
5841
5842 if (pCallback == NULL)
5843 {
5844 return HAL_ERROR;
5845 }
5846
5847 if (htim->State == HAL_TIM_STATE_READY)
5848 {
5849 switch (CallbackID)
5850 {
5851 case HAL_TIM_BASE_MSPINIT_CB_ID :
5852 htim->Base_MspInitCallback = pCallback;
5853 break;
5854
5855 case HAL_TIM_BASE_MSPDEINIT_CB_ID :
5856 htim->Base_MspDeInitCallback = pCallback;
5857 break;
5858
5859 case HAL_TIM_IC_MSPINIT_CB_ID :
5860 htim->IC_MspInitCallback = pCallback;
5861 break;
5862
5863 case HAL_TIM_IC_MSPDEINIT_CB_ID :
5864 htim->IC_MspDeInitCallback = pCallback;
5865 break;
5866
5867 case HAL_TIM_OC_MSPINIT_CB_ID :
5868 htim->OC_MspInitCallback = pCallback;
5869 break;
5870
5871 case HAL_TIM_OC_MSPDEINIT_CB_ID :
5872 htim->OC_MspDeInitCallback = pCallback;
5873 break;
5874
5875 case HAL_TIM_PWM_MSPINIT_CB_ID :
5876 htim->PWM_MspInitCallback = pCallback;
5877 break;
5878
5879 case HAL_TIM_PWM_MSPDEINIT_CB_ID :
5880 htim->PWM_MspDeInitCallback = pCallback;
5881 break;
5882
5883 case HAL_TIM_ONE_PULSE_MSPINIT_CB_ID :
5884 htim->OnePulse_MspInitCallback = pCallback;
5885 break;
5886
5887 case HAL_TIM_ONE_PULSE_MSPDEINIT_CB_ID :
5888 htim->OnePulse_MspDeInitCallback = pCallback;
5889 break;
5890
5891 case HAL_TIM_ENCODER_MSPINIT_CB_ID :
5892 htim->Encoder_MspInitCallback = pCallback;
5893 break;
5894
5895 case HAL_TIM_ENCODER_MSPDEINIT_CB_ID :
5896 htim->Encoder_MspDeInitCallback = pCallback;
5897 break;
5898
5899 case HAL_TIM_HALL_SENSOR_MSPINIT_CB_ID :
5900 htim->HallSensor_MspInitCallback = pCallback;
5901 break;
5902
5903 case HAL_TIM_HALL_SENSOR_MSPDEINIT_CB_ID :
5904 htim->HallSensor_MspDeInitCallback = pCallback;
5905 break;
5906
5907 case HAL_TIM_PERIOD_ELAPSED_CB_ID :
5908 htim->PeriodElapsedCallback = pCallback;
5909 break;
5910
5911 case HAL_TIM_PERIOD_ELAPSED_HALF_CB_ID :
5912 htim->PeriodElapsedHalfCpltCallback = pCallback;
5913 break;
5914
5915 case HAL_TIM_TRIGGER_CB_ID :
5916 htim->TriggerCallback = pCallback;
5917 break;
5918
5919 case HAL_TIM_TRIGGER_HALF_CB_ID :
5920 htim->TriggerHalfCpltCallback = pCallback;
5921 break;
5922
5923 case HAL_TIM_IC_CAPTURE_CB_ID :
5924 htim->IC_CaptureCallback = pCallback;
5925 break;
5926
5927 case HAL_TIM_IC_CAPTURE_HALF_CB_ID :
5928 htim->IC_CaptureHalfCpltCallback = pCallback;
5929 break;
5930
5931 case HAL_TIM_OC_DELAY_ELAPSED_CB_ID :
5932 htim->OC_DelayElapsedCallback = pCallback;
5933 break;
5934
5935 case HAL_TIM_PWM_PULSE_FINISHED_CB_ID :
5936 htim->PWM_PulseFinishedCallback = pCallback;
5937 break;
5938
5939 case HAL_TIM_PWM_PULSE_FINISHED_HALF_CB_ID :
5940 htim->PWM_PulseFinishedHalfCpltCallback = pCallback;
5941 break;
5942
5943 case HAL_TIM_ERROR_CB_ID :
5944 htim->ErrorCallback = pCallback;
5945 break;
5946
5947 case HAL_TIM_COMMUTATION_CB_ID :
5948 htim->CommutationCallback = pCallback;
5949 break;
5950
5951 case HAL_TIM_COMMUTATION_HALF_CB_ID :
5952 htim->CommutationHalfCpltCallback = pCallback;
5953 break;
5954
5955 case HAL_TIM_BREAK_CB_ID :
5956 htim->BreakCallback = pCallback;
5957 break;
5958
5959 default :
5960 /* Return error status */
5961 status = HAL_ERROR;
5962 break;
5963 }
5964 }
5965 else if (htim->State == HAL_TIM_STATE_RESET)
5966 {
5967 switch (CallbackID)
5968 {
5969 case HAL_TIM_BASE_MSPINIT_CB_ID :
5970 htim->Base_MspInitCallback = pCallback;
5971 break;
5972
5973 case HAL_TIM_BASE_MSPDEINIT_CB_ID :
5974 htim->Base_MspDeInitCallback = pCallback;
5975 break;
5976
5977 case HAL_TIM_IC_MSPINIT_CB_ID :
5978 htim->IC_MspInitCallback = pCallback;
5979 break;
5980
5981 case HAL_TIM_IC_MSPDEINIT_CB_ID :
5982 htim->IC_MspDeInitCallback = pCallback;
5983 break;
5984
5985 case HAL_TIM_OC_MSPINIT_CB_ID :
5986 htim->OC_MspInitCallback = pCallback;
5987 break;
5988
5989 case HAL_TIM_OC_MSPDEINIT_CB_ID :
5990 htim->OC_MspDeInitCallback = pCallback;
5991 break;
5992
5993 case HAL_TIM_PWM_MSPINIT_CB_ID :
5994 htim->PWM_MspInitCallback = pCallback;
5995 break;
5996
5997 case HAL_TIM_PWM_MSPDEINIT_CB_ID :
5998 htim->PWM_MspDeInitCallback = pCallback;
5999 break;
6000
6001 case HAL_TIM_ONE_PULSE_MSPINIT_CB_ID :
6002 htim->OnePulse_MspInitCallback = pCallback;
6003 break;
6004
6005 case HAL_TIM_ONE_PULSE_MSPDEINIT_CB_ID :
6006 htim->OnePulse_MspDeInitCallback = pCallback;
6007 break;
6008
6009 case HAL_TIM_ENCODER_MSPINIT_CB_ID :
6010 htim->Encoder_MspInitCallback = pCallback;
6011 break;
6012
6013 case HAL_TIM_ENCODER_MSPDEINIT_CB_ID :
6014 htim->Encoder_MspDeInitCallback = pCallback;
6015 break;
6016
6017 case HAL_TIM_HALL_SENSOR_MSPINIT_CB_ID :
6018 htim->HallSensor_MspInitCallback = pCallback;
6019 break;
6020
6021 case HAL_TIM_HALL_SENSOR_MSPDEINIT_CB_ID :
6022 htim->HallSensor_MspDeInitCallback = pCallback;
6023 break;
6024
6025 default :
6026 /* Return error status */
6027 status = HAL_ERROR;
6028 break;
6029 }
6030 }
6031 else
6032 {
6033 /* Return error status */
6034 status = HAL_ERROR;
6035 }
6036
6037 return status;
6038}
6039
6075HAL_StatusTypeDef HAL_TIM_UnRegisterCallback(TIM_HandleTypeDef *htim, HAL_TIM_CallbackIDTypeDef CallbackID)
6076{
6077 HAL_StatusTypeDef status = HAL_OK;
6078
6079 if (htim->State == HAL_TIM_STATE_READY)
6080 {
6081 switch (CallbackID)
6082 {
6083 case HAL_TIM_BASE_MSPINIT_CB_ID :
6084 /* Legacy weak Base MspInit Callback */
6085 htim->Base_MspInitCallback = HAL_TIM_Base_MspInit;
6086 break;
6087
6088 case HAL_TIM_BASE_MSPDEINIT_CB_ID :
6089 /* Legacy weak Base Msp DeInit Callback */
6090 htim->Base_MspDeInitCallback = HAL_TIM_Base_MspDeInit;
6091 break;
6092
6093 case HAL_TIM_IC_MSPINIT_CB_ID :
6094 /* Legacy weak IC Msp Init Callback */
6095 htim->IC_MspInitCallback = HAL_TIM_IC_MspInit;
6096 break;
6097
6098 case HAL_TIM_IC_MSPDEINIT_CB_ID :
6099 /* Legacy weak IC Msp DeInit Callback */
6100 htim->IC_MspDeInitCallback = HAL_TIM_IC_MspDeInit;
6101 break;
6102
6103 case HAL_TIM_OC_MSPINIT_CB_ID :
6104 /* Legacy weak OC Msp Init Callback */
6105 htim->OC_MspInitCallback = HAL_TIM_OC_MspInit;
6106 break;
6107
6108 case HAL_TIM_OC_MSPDEINIT_CB_ID :
6109 /* Legacy weak OC Msp DeInit Callback */
6110 htim->OC_MspDeInitCallback = HAL_TIM_OC_MspDeInit;
6111 break;
6112
6113 case HAL_TIM_PWM_MSPINIT_CB_ID :
6114 /* Legacy weak PWM Msp Init Callback */
6115 htim->PWM_MspInitCallback = HAL_TIM_PWM_MspInit;
6116 break;
6117
6118 case HAL_TIM_PWM_MSPDEINIT_CB_ID :
6119 /* Legacy weak PWM Msp DeInit Callback */
6120 htim->PWM_MspDeInitCallback = HAL_TIM_PWM_MspDeInit;
6121 break;
6122
6123 case HAL_TIM_ONE_PULSE_MSPINIT_CB_ID :
6124 /* Legacy weak One Pulse Msp Init Callback */
6125 htim->OnePulse_MspInitCallback = HAL_TIM_OnePulse_MspInit;
6126 break;
6127
6128 case HAL_TIM_ONE_PULSE_MSPDEINIT_CB_ID :
6129 /* Legacy weak One Pulse Msp DeInit Callback */
6130 htim->OnePulse_MspDeInitCallback = HAL_TIM_OnePulse_MspDeInit;
6131 break;
6132
6133 case HAL_TIM_ENCODER_MSPINIT_CB_ID :
6134 /* Legacy weak Encoder Msp Init Callback */
6135 htim->Encoder_MspInitCallback = HAL_TIM_Encoder_MspInit;
6136 break;
6137
6138 case HAL_TIM_ENCODER_MSPDEINIT_CB_ID :
6139 /* Legacy weak Encoder Msp DeInit Callback */
6140 htim->Encoder_MspDeInitCallback = HAL_TIM_Encoder_MspDeInit;
6141 break;
6142
6143 case HAL_TIM_HALL_SENSOR_MSPINIT_CB_ID :
6144 /* Legacy weak Hall Sensor Msp Init Callback */
6145 htim->HallSensor_MspInitCallback = HAL_TIMEx_HallSensor_MspInit;
6146 break;
6147
6148 case HAL_TIM_HALL_SENSOR_MSPDEINIT_CB_ID :
6149 /* Legacy weak Hall Sensor Msp DeInit Callback */
6150 htim->HallSensor_MspDeInitCallback = HAL_TIMEx_HallSensor_MspDeInit;
6151 break;
6152
6153 case HAL_TIM_PERIOD_ELAPSED_CB_ID :
6154 /* Legacy weak Period Elapsed Callback */
6155 htim->PeriodElapsedCallback = HAL_TIM_PeriodElapsedCallback;
6156 break;
6157
6158 case HAL_TIM_PERIOD_ELAPSED_HALF_CB_ID :
6159 /* Legacy weak Period Elapsed half complete Callback */
6160 htim->PeriodElapsedHalfCpltCallback = HAL_TIM_PeriodElapsedHalfCpltCallback;
6161 break;
6162
6163 case HAL_TIM_TRIGGER_CB_ID :
6164 /* Legacy weak Trigger Callback */
6165 htim->TriggerCallback = HAL_TIM_TriggerCallback;
6166 break;
6167
6168 case HAL_TIM_TRIGGER_HALF_CB_ID :
6169 /* Legacy weak Trigger half complete Callback */
6170 htim->TriggerHalfCpltCallback = HAL_TIM_TriggerHalfCpltCallback;
6171 break;
6172
6173 case HAL_TIM_IC_CAPTURE_CB_ID :
6174 /* Legacy weak IC Capture Callback */
6175 htim->IC_CaptureCallback = HAL_TIM_IC_CaptureCallback;
6176 break;
6177
6178 case HAL_TIM_IC_CAPTURE_HALF_CB_ID :
6179 /* Legacy weak IC Capture half complete Callback */
6180 htim->IC_CaptureHalfCpltCallback = HAL_TIM_IC_CaptureHalfCpltCallback;
6181 break;
6182
6183 case HAL_TIM_OC_DELAY_ELAPSED_CB_ID :
6184 /* Legacy weak OC Delay Elapsed Callback */
6185 htim->OC_DelayElapsedCallback = HAL_TIM_OC_DelayElapsedCallback;
6186 break;
6187
6188 case HAL_TIM_PWM_PULSE_FINISHED_CB_ID :
6189 /* Legacy weak PWM Pulse Finished Callback */
6190 htim->PWM_PulseFinishedCallback = HAL_TIM_PWM_PulseFinishedCallback;
6191 break;
6192
6193 case HAL_TIM_PWM_PULSE_FINISHED_HALF_CB_ID :
6194 /* Legacy weak PWM Pulse Finished half complete Callback */
6195 htim->PWM_PulseFinishedHalfCpltCallback = HAL_TIM_PWM_PulseFinishedHalfCpltCallback;
6196 break;
6197
6198 case HAL_TIM_ERROR_CB_ID :
6199 /* Legacy weak Error Callback */
6200 htim->ErrorCallback = HAL_TIM_ErrorCallback;
6201 break;
6202
6203 case HAL_TIM_COMMUTATION_CB_ID :
6204 /* Legacy weak Commutation Callback */
6205 htim->CommutationCallback = HAL_TIMEx_CommutCallback;
6206 break;
6207
6208 case HAL_TIM_COMMUTATION_HALF_CB_ID :
6209 /* Legacy weak Commutation half complete Callback */
6210 htim->CommutationHalfCpltCallback = HAL_TIMEx_CommutHalfCpltCallback;
6211 break;
6212
6213 case HAL_TIM_BREAK_CB_ID :
6214 /* Legacy weak Break Callback */
6215 htim->BreakCallback = HAL_TIMEx_BreakCallback;
6216 break;
6217
6218 default :
6219 /* Return error status */
6220 status = HAL_ERROR;
6221 break;
6222 }
6223 }
6224 else if (htim->State == HAL_TIM_STATE_RESET)
6225 {
6226 switch (CallbackID)
6227 {
6228 case HAL_TIM_BASE_MSPINIT_CB_ID :
6229 /* Legacy weak Base MspInit Callback */
6230 htim->Base_MspInitCallback = HAL_TIM_Base_MspInit;
6231 break;
6232
6233 case HAL_TIM_BASE_MSPDEINIT_CB_ID :
6234 /* Legacy weak Base Msp DeInit Callback */
6235 htim->Base_MspDeInitCallback = HAL_TIM_Base_MspDeInit;
6236 break;
6237
6238 case HAL_TIM_IC_MSPINIT_CB_ID :
6239 /* Legacy weak IC Msp Init Callback */
6240 htim->IC_MspInitCallback = HAL_TIM_IC_MspInit;
6241 break;
6242
6243 case HAL_TIM_IC_MSPDEINIT_CB_ID :
6244 /* Legacy weak IC Msp DeInit Callback */
6245 htim->IC_MspDeInitCallback = HAL_TIM_IC_MspDeInit;
6246 break;
6247
6248 case HAL_TIM_OC_MSPINIT_CB_ID :
6249 /* Legacy weak OC Msp Init Callback */
6250 htim->OC_MspInitCallback = HAL_TIM_OC_MspInit;
6251 break;
6252
6253 case HAL_TIM_OC_MSPDEINIT_CB_ID :
6254 /* Legacy weak OC Msp DeInit Callback */
6255 htim->OC_MspDeInitCallback = HAL_TIM_OC_MspDeInit;
6256 break;
6257
6258 case HAL_TIM_PWM_MSPINIT_CB_ID :
6259 /* Legacy weak PWM Msp Init Callback */
6260 htim->PWM_MspInitCallback = HAL_TIM_PWM_MspInit;
6261 break;
6262
6263 case HAL_TIM_PWM_MSPDEINIT_CB_ID :
6264 /* Legacy weak PWM Msp DeInit Callback */
6265 htim->PWM_MspDeInitCallback = HAL_TIM_PWM_MspDeInit;
6266 break;
6267
6268 case HAL_TIM_ONE_PULSE_MSPINIT_CB_ID :
6269 /* Legacy weak One Pulse Msp Init Callback */
6270 htim->OnePulse_MspInitCallback = HAL_TIM_OnePulse_MspInit;
6271 break;
6272
6273 case HAL_TIM_ONE_PULSE_MSPDEINIT_CB_ID :
6274 /* Legacy weak One Pulse Msp DeInit Callback */
6275 htim->OnePulse_MspDeInitCallback = HAL_TIM_OnePulse_MspDeInit;
6276 break;
6277
6278 case HAL_TIM_ENCODER_MSPINIT_CB_ID :
6279 /* Legacy weak Encoder Msp Init Callback */
6280 htim->Encoder_MspInitCallback = HAL_TIM_Encoder_MspInit;
6281 break;
6282
6283 case HAL_TIM_ENCODER_MSPDEINIT_CB_ID :
6284 /* Legacy weak Encoder Msp DeInit Callback */
6285 htim->Encoder_MspDeInitCallback = HAL_TIM_Encoder_MspDeInit;
6286 break;
6287
6288 case HAL_TIM_HALL_SENSOR_MSPINIT_CB_ID :
6289 /* Legacy weak Hall Sensor Msp Init Callback */
6290 htim->HallSensor_MspInitCallback = HAL_TIMEx_HallSensor_MspInit;
6291 break;
6292
6293 case HAL_TIM_HALL_SENSOR_MSPDEINIT_CB_ID :
6294 /* Legacy weak Hall Sensor Msp DeInit Callback */
6295 htim->HallSensor_MspDeInitCallback = HAL_TIMEx_HallSensor_MspDeInit;
6296 break;
6297
6298 default :
6299 /* Return error status */
6300 status = HAL_ERROR;
6301 break;
6302 }
6303 }
6304 else
6305 {
6306 /* Return error status */
6307 status = HAL_ERROR;
6308 }
6309
6310 return status;
6311}
6312#endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
6313
6317
6332
6339{
6340 return htim->State;
6341}
6342
6349{
6350 return htim->State;
6351}
6352
6359{
6360 return htim->State;
6361}
6362
6369{
6370 return htim->State;
6371}
6372
6379{
6380 return htim->State;
6381}
6382
6389{
6390 return htim->State;
6391}
6392
6399{
6400 return htim->Channel;
6401}
6402
6417{
6418 HAL_TIM_ChannelStateTypeDef channel_state;
6419
6420 /* Check the parameters */
6421 assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
6422
6423 channel_state = TIM_CHANNEL_STATE_GET(htim, Channel);
6424
6425 return channel_state;
6426}
6427
6434{
6435 /* Check the parameters */
6436 assert_param(IS_TIM_DMABURST_INSTANCE(htim->Instance));
6437
6438 return htim->DMABurstState;
6439}
6440
6444
6448
6452
6459{
6460 TIM_HandleTypeDef *htim = (TIM_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
6461
6462 if (hdma == htim->hdma[TIM_DMA_ID_CC1])
6463 {
6466 }
6467 else if (hdma == htim->hdma[TIM_DMA_ID_CC2])
6468 {
6471 }
6472 else if (hdma == htim->hdma[TIM_DMA_ID_CC3])
6473 {
6476 }
6477 else if (hdma == htim->hdma[TIM_DMA_ID_CC4])
6478 {
6481 }
6482 else
6483 {
6484 htim->State = HAL_TIM_STATE_READY;
6485 }
6486
6487#if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
6488 htim->ErrorCallback(htim);
6489#else
6491#endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
6492
6494}
6495
6501static void TIM_DMADelayPulseCplt(DMA_HandleTypeDef *hdma)
6502{
6503 TIM_HandleTypeDef *htim = (TIM_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
6504
6505 if (hdma == htim->hdma[TIM_DMA_ID_CC1])
6506 {
6508
6509 if (hdma->Init.Mode == DMA_NORMAL)
6510 {
6512 }
6513 }
6514 else if (hdma == htim->hdma[TIM_DMA_ID_CC2])
6515 {
6517
6518 if (hdma->Init.Mode == DMA_NORMAL)
6519 {
6521 }
6522 }
6523 else if (hdma == htim->hdma[TIM_DMA_ID_CC3])
6524 {
6526
6527 if (hdma->Init.Mode == DMA_NORMAL)
6528 {
6530 }
6531 }
6532 else if (hdma == htim->hdma[TIM_DMA_ID_CC4])
6533 {
6535
6536 if (hdma->Init.Mode == DMA_NORMAL)
6537 {
6539 }
6540 }
6541 else
6542 {
6543 /* nothing to do */
6544 }
6545
6546#if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
6547 htim->PWM_PulseFinishedCallback(htim);
6548#else
6550#endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
6551
6553}
6554
6561{
6562 TIM_HandleTypeDef *htim = (TIM_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
6563
6564 if (hdma == htim->hdma[TIM_DMA_ID_CC1])
6565 {
6567 }
6568 else if (hdma == htim->hdma[TIM_DMA_ID_CC2])
6569 {
6571 }
6572 else if (hdma == htim->hdma[TIM_DMA_ID_CC3])
6573 {
6575 }
6576 else if (hdma == htim->hdma[TIM_DMA_ID_CC4])
6577 {
6579 }
6580 else
6581 {
6582 /* nothing to do */
6583 }
6584
6585#if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
6586 htim->PWM_PulseFinishedHalfCpltCallback(htim);
6587#else
6589#endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
6590
6592}
6593
6600{
6601 TIM_HandleTypeDef *htim = (TIM_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
6602
6603 if (hdma == htim->hdma[TIM_DMA_ID_CC1])
6604 {
6606
6607 if (hdma->Init.Mode == DMA_NORMAL)
6608 {
6611 }
6612 }
6613 else if (hdma == htim->hdma[TIM_DMA_ID_CC2])
6614 {
6616
6617 if (hdma->Init.Mode == DMA_NORMAL)
6618 {
6621 }
6622 }
6623 else if (hdma == htim->hdma[TIM_DMA_ID_CC3])
6624 {
6626
6627 if (hdma->Init.Mode == DMA_NORMAL)
6628 {
6631 }
6632 }
6633 else if (hdma == htim->hdma[TIM_DMA_ID_CC4])
6634 {
6636
6637 if (hdma->Init.Mode == DMA_NORMAL)
6638 {
6641 }
6642 }
6643 else
6644 {
6645 /* nothing to do */
6646 }
6647
6648#if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
6649 htim->IC_CaptureCallback(htim);
6650#else
6652#endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
6653
6655}
6656
6663{
6664 TIM_HandleTypeDef *htim = (TIM_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
6665
6666 if (hdma == htim->hdma[TIM_DMA_ID_CC1])
6667 {
6669 }
6670 else if (hdma == htim->hdma[TIM_DMA_ID_CC2])
6671 {
6673 }
6674 else if (hdma == htim->hdma[TIM_DMA_ID_CC3])
6675 {
6677 }
6678 else if (hdma == htim->hdma[TIM_DMA_ID_CC4])
6679 {
6681 }
6682 else
6683 {
6684 /* nothing to do */
6685 }
6686
6687#if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
6688 htim->IC_CaptureHalfCpltCallback(htim);
6689#else
6691#endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
6692
6694}
6695
6701static void TIM_DMAPeriodElapsedCplt(DMA_HandleTypeDef *hdma)
6702{
6703 TIM_HandleTypeDef *htim = (TIM_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
6704
6705 if (htim->hdma[TIM_DMA_ID_UPDATE]->Init.Mode == DMA_NORMAL)
6706 {
6707 htim->State = HAL_TIM_STATE_READY;
6708 }
6709
6710#if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
6711 htim->PeriodElapsedCallback(htim);
6712#else
6714#endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
6715}
6716
6722static void TIM_DMAPeriodElapsedHalfCplt(DMA_HandleTypeDef *hdma)
6723{
6724 TIM_HandleTypeDef *htim = (TIM_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
6725
6726#if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
6727 htim->PeriodElapsedHalfCpltCallback(htim);
6728#else
6730#endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
6731}
6732
6738static void TIM_DMATriggerCplt(DMA_HandleTypeDef *hdma)
6739{
6740 TIM_HandleTypeDef *htim = (TIM_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
6741
6743 {
6744 htim->State = HAL_TIM_STATE_READY;
6745 }
6746
6747#if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
6748 htim->TriggerCallback(htim);
6749#else
6751#endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
6752}
6753
6759static void TIM_DMATriggerHalfCplt(DMA_HandleTypeDef *hdma)
6760{
6761 TIM_HandleTypeDef *htim = (TIM_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
6762
6763#if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
6764 htim->TriggerHalfCpltCallback(htim);
6765#else
6767#endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
6768}
6769
6776void TIM_Base_SetConfig(TIM_TypeDef *TIMx, const TIM_Base_InitTypeDef *Structure)
6777{
6778 uint32_t tmpcr1;
6779 tmpcr1 = TIMx->CR1;
6780
6781 /* Set TIM Time Base Unit parameters ---------------------------------------*/
6782 if (IS_TIM_COUNTER_MODE_SELECT_INSTANCE(TIMx))
6783 {
6784 /* Select the Counter Mode */
6785 tmpcr1 &= ~(TIM_CR1_DIR | TIM_CR1_CMS);
6786 tmpcr1 |= Structure->CounterMode;
6787 }
6788
6789 if (IS_TIM_CLOCK_DIVISION_INSTANCE(TIMx))
6790 {
6791 /* Set the clock division */
6792 tmpcr1 &= ~TIM_CR1_CKD;
6793 tmpcr1 |= (uint32_t)Structure->ClockDivision;
6794 }
6795
6796 /* Set the auto-reload preload */
6797 MODIFY_REG(tmpcr1, TIM_CR1_ARPE, Structure->AutoReloadPreload);
6798
6799 /* Set the Autoreload value */
6800 TIMx->ARR = (uint32_t)Structure->Period ;
6801
6802 /* Set the Prescaler value */
6803 TIMx->PSC = Structure->Prescaler;
6804
6805 if (IS_TIM_REPETITION_COUNTER_INSTANCE(TIMx))
6806 {
6807 /* Set the Repetition Counter value */
6808 TIMx->RCR = Structure->RepetitionCounter;
6809 }
6810
6811 /* Disable Update Event (UEV) with Update Generation (UG)
6812 by changing Update Request Source (URS) to avoid Update flag (UIF) */
6813 SET_BIT(TIMx->CR1, TIM_CR1_URS);
6814
6815 /* Generate an update event to reload the Prescaler
6816 and the repetition counter (only for advanced timer) value immediately */
6817 TIMx->EGR = TIM_EGR_UG;
6818
6819 TIMx->CR1 = tmpcr1;
6820}
6821
6828static void TIM_OC1_SetConfig(TIM_TypeDef *TIMx, const TIM_OC_InitTypeDef *OC_Config)
6829{
6830 uint32_t tmpccmrx;
6831 uint32_t tmpccer;
6832 uint32_t tmpcr2;
6833
6834 /* Get the TIMx CCER register value */
6835 tmpccer = TIMx->CCER;
6836
6837 /* Disable the Channel 1: Reset the CC1E Bit */
6838 TIMx->CCER &= ~TIM_CCER_CC1E;
6839
6840 /* Get the TIMx CR2 register value */
6841 tmpcr2 = TIMx->CR2;
6842
6843 /* Get the TIMx CCMR1 register value */
6844 tmpccmrx = TIMx->CCMR1;
6845
6846 /* Reset the Output Compare Mode Bits */
6847 tmpccmrx &= ~TIM_CCMR1_OC1M;
6848 tmpccmrx &= ~TIM_CCMR1_CC1S;
6849 /* Select the Output Compare Mode */
6850 tmpccmrx |= OC_Config->OCMode;
6851
6852 /* Reset the Output Polarity level */
6853 tmpccer &= ~TIM_CCER_CC1P;
6854 /* Set the Output Compare Polarity */
6855 tmpccer |= OC_Config->OCPolarity;
6856
6857 if (IS_TIM_CCXN_INSTANCE(TIMx, TIM_CHANNEL_1))
6858 {
6859 /* Check parameters */
6861
6862 /* Disable the Channel 1N: Reset the CC1NE Bit */
6863 TIMx->CCER &= ~TIM_CCER_CC1NE;
6864
6865 /* Reset the Output N Polarity level */
6866 tmpccer &= ~TIM_CCER_CC1NP;
6867 /* Set the Output N Polarity */
6868 tmpccer |= OC_Config->OCNPolarity;
6869 }
6870
6871 if (IS_TIM_BREAK_INSTANCE(TIMx))
6872 {
6873 /* Check parameters */
6876
6877 /* Reset the Output Compare and Output Compare N IDLE State */
6878 tmpcr2 &= ~TIM_CR2_OIS1;
6879 tmpcr2 &= ~TIM_CR2_OIS1N;
6880 /* Set the Output Idle state */
6881 tmpcr2 |= OC_Config->OCIdleState;
6882 /* Set the Output N Idle state */
6883 tmpcr2 |= OC_Config->OCNIdleState;
6884 }
6885
6886 /* Write to TIMx CR2 */
6887 TIMx->CR2 = tmpcr2;
6888
6889 /* Write to TIMx CCMR1 */
6890 TIMx->CCMR1 = tmpccmrx;
6891
6892 /* Set the Capture Compare Register value */
6893 TIMx->CCR1 = OC_Config->Pulse;
6894
6895 /* Write to TIMx CCER */
6896 TIMx->CCER = tmpccer;
6897}
6898
6905void TIM_OC2_SetConfig(TIM_TypeDef *TIMx, const TIM_OC_InitTypeDef *OC_Config)
6906{
6907 uint32_t tmpccmrx;
6908 uint32_t tmpccer;
6909 uint32_t tmpcr2;
6910
6911 /* Get the TIMx CCER register value */
6912 tmpccer = TIMx->CCER;
6913
6914 /* Disable the Channel 2: Reset the CC2E Bit */
6915 TIMx->CCER &= ~TIM_CCER_CC2E;
6916
6917 /* Get the TIMx CR2 register value */
6918 tmpcr2 = TIMx->CR2;
6919
6920 /* Get the TIMx CCMR1 register value */
6921 tmpccmrx = TIMx->CCMR1;
6922
6923 /* Reset the Output Compare mode and Capture/Compare selection Bits */
6924 tmpccmrx &= ~TIM_CCMR1_OC2M;
6925 tmpccmrx &= ~TIM_CCMR1_CC2S;
6926
6927 /* Select the Output Compare Mode */
6928 tmpccmrx |= (OC_Config->OCMode << 8U);
6929
6930 /* Reset the Output Polarity level */
6931 tmpccer &= ~TIM_CCER_CC2P;
6932 /* Set the Output Compare Polarity */
6933 tmpccer |= (OC_Config->OCPolarity << 4U);
6934
6935 if (IS_TIM_CCXN_INSTANCE(TIMx, TIM_CHANNEL_2))
6936 {
6938
6939 /* Disable the Channel 2N: Reset the CC2NE Bit */
6940 TIMx->CCER &= ~TIM_CCER_CC2NE;
6941
6942 /* Reset the Output N Polarity level */
6943 tmpccer &= ~TIM_CCER_CC2NP;
6944 /* Set the Output N Polarity */
6945 tmpccer |= (OC_Config->OCNPolarity << 4U);
6946 }
6947
6948 if (IS_TIM_BREAK_INSTANCE(TIMx))
6949 {
6950 /* Check parameters */
6953
6954 /* Reset the Output Compare and Output Compare N IDLE State */
6955 tmpcr2 &= ~TIM_CR2_OIS2;
6956 tmpcr2 &= ~TIM_CR2_OIS2N;
6957 /* Set the Output Idle state */
6958 tmpcr2 |= (OC_Config->OCIdleState << 2U);
6959 /* Set the Output N Idle state */
6960 tmpcr2 |= (OC_Config->OCNIdleState << 2U);
6961 }
6962
6963 /* Write to TIMx CR2 */
6964 TIMx->CR2 = tmpcr2;
6965
6966 /* Write to TIMx CCMR1 */
6967 TIMx->CCMR1 = tmpccmrx;
6968
6969 /* Set the Capture Compare Register value */
6970 TIMx->CCR2 = OC_Config->Pulse;
6971
6972 /* Write to TIMx CCER */
6973 TIMx->CCER = tmpccer;
6974}
6975
6982static void TIM_OC3_SetConfig(TIM_TypeDef *TIMx, const TIM_OC_InitTypeDef *OC_Config)
6983{
6984 uint32_t tmpccmrx;
6985 uint32_t tmpccer;
6986 uint32_t tmpcr2;
6987
6988 /* Get the TIMx CCER register value */
6989 tmpccer = TIMx->CCER;
6990
6991 /* Disable the Channel 3: Reset the CC2E Bit */
6992 TIMx->CCER &= ~TIM_CCER_CC3E;
6993
6994 /* Get the TIMx CR2 register value */
6995 tmpcr2 = TIMx->CR2;
6996
6997 /* Get the TIMx CCMR2 register value */
6998 tmpccmrx = TIMx->CCMR2;
6999
7000 /* Reset the Output Compare mode and Capture/Compare selection Bits */
7001 tmpccmrx &= ~TIM_CCMR2_OC3M;
7002 tmpccmrx &= ~TIM_CCMR2_CC3S;
7003 /* Select the Output Compare Mode */
7004 tmpccmrx |= OC_Config->OCMode;
7005
7006 /* Reset the Output Polarity level */
7007 tmpccer &= ~TIM_CCER_CC3P;
7008 /* Set the Output Compare Polarity */
7009 tmpccer |= (OC_Config->OCPolarity << 8U);
7010
7011 if (IS_TIM_CCXN_INSTANCE(TIMx, TIM_CHANNEL_3))
7012 {
7014
7015 /* Disable the Channel 3N: Reset the CC3NE Bit */
7016 TIMx->CCER &= ~TIM_CCER_CC3NE;
7017
7018 /* Reset the Output N Polarity level */
7019 tmpccer &= ~TIM_CCER_CC3NP;
7020 /* Set the Output N Polarity */
7021 tmpccer |= (OC_Config->OCNPolarity << 8U);
7022 }
7023
7024 if (IS_TIM_BREAK_INSTANCE(TIMx))
7025 {
7026 /* Check parameters */
7029
7030 /* Reset the Output Compare and Output Compare N IDLE State */
7031 tmpcr2 &= ~TIM_CR2_OIS3;
7032 tmpcr2 &= ~TIM_CR2_OIS3N;
7033 /* Set the Output Idle state */
7034 tmpcr2 |= (OC_Config->OCIdleState << 4U);
7035 /* Set the Output N Idle state */
7036 tmpcr2 |= (OC_Config->OCNIdleState << 4U);
7037 }
7038
7039 /* Write to TIMx CR2 */
7040 TIMx->CR2 = tmpcr2;
7041
7042 /* Write to TIMx CCMR2 */
7043 TIMx->CCMR2 = tmpccmrx;
7044
7045 /* Set the Capture Compare Register value */
7046 TIMx->CCR3 = OC_Config->Pulse;
7047
7048 /* Write to TIMx CCER */
7049 TIMx->CCER = tmpccer;
7050}
7051
7058static void TIM_OC4_SetConfig(TIM_TypeDef *TIMx, const TIM_OC_InitTypeDef *OC_Config)
7059{
7060 uint32_t tmpccmrx;
7061 uint32_t tmpccer;
7062 uint32_t tmpcr2;
7063
7064 /* Get the TIMx CCER register value */
7065 tmpccer = TIMx->CCER;
7066
7067 /* Disable the Channel 4: Reset the CC4E Bit */
7068 TIMx->CCER &= ~TIM_CCER_CC4E;
7069
7070 /* Get the TIMx CR2 register value */
7071 tmpcr2 = TIMx->CR2;
7072
7073 /* Get the TIMx CCMR2 register value */
7074 tmpccmrx = TIMx->CCMR2;
7075
7076 /* Reset the Output Compare mode and Capture/Compare selection Bits */
7077 tmpccmrx &= ~TIM_CCMR2_OC4M;
7078 tmpccmrx &= ~TIM_CCMR2_CC4S;
7079
7080 /* Select the Output Compare Mode */
7081 tmpccmrx |= (OC_Config->OCMode << 8U);
7082
7083 /* Reset the Output Polarity level */
7084 tmpccer &= ~TIM_CCER_CC4P;
7085 /* Set the Output Compare Polarity */
7086 tmpccer |= (OC_Config->OCPolarity << 12U);
7087
7088 if (IS_TIM_BREAK_INSTANCE(TIMx))
7089 {
7090 /* Check parameters */
7092
7093 /* Reset the Output Compare IDLE State */
7094 tmpcr2 &= ~TIM_CR2_OIS4;
7095
7096 /* Set the Output Idle state */
7097 tmpcr2 |= (OC_Config->OCIdleState << 6U);
7098 }
7099
7100 /* Write to TIMx CR2 */
7101 TIMx->CR2 = tmpcr2;
7102
7103 /* Write to TIMx CCMR2 */
7104 TIMx->CCMR2 = tmpccmrx;
7105
7106 /* Set the Capture Compare Register value */
7107 TIMx->CCR4 = OC_Config->Pulse;
7108
7109 /* Write to TIMx CCER */
7110 TIMx->CCER = tmpccer;
7111}
7112
7119static HAL_StatusTypeDef TIM_SlaveTimer_SetConfig(TIM_HandleTypeDef *htim,
7120 const TIM_SlaveConfigTypeDef *sSlaveConfig)
7121{
7122 HAL_StatusTypeDef status = HAL_OK;
7123 uint32_t tmpsmcr;
7124 uint32_t tmpccmr1;
7125 uint32_t tmpccer;
7126
7127 /* Get the TIMx SMCR register value */
7128 tmpsmcr = htim->Instance->SMCR;
7129
7130 /* Reset the Trigger Selection Bits */
7131 tmpsmcr &= ~TIM_SMCR_TS;
7132 /* Set the Input Trigger source */
7133 tmpsmcr |= sSlaveConfig->InputTrigger;
7134
7135 /* Reset the slave mode Bits */
7136 tmpsmcr &= ~TIM_SMCR_SMS;
7137 /* Set the slave mode */
7138 tmpsmcr |= sSlaveConfig->SlaveMode;
7139
7140 /* Write to TIMx SMCR */
7141 htim->Instance->SMCR = tmpsmcr;
7142
7143 /* Configure the trigger prescaler, filter, and polarity */
7144 switch (sSlaveConfig->InputTrigger)
7145 {
7146 case TIM_TS_ETRF:
7147 {
7148 /* Check the parameters */
7149 assert_param(IS_TIM_CLOCKSOURCE_ETRMODE1_INSTANCE(htim->Instance));
7153 /* Configure the ETR Trigger source */
7155 sSlaveConfig->TriggerPrescaler,
7156 sSlaveConfig->TriggerPolarity,
7157 sSlaveConfig->TriggerFilter);
7158 break;
7159 }
7160
7161 case TIM_TS_TI1F_ED:
7162 {
7163 /* Check the parameters */
7164 assert_param(IS_TIM_CC1_INSTANCE(htim->Instance));
7166
7167 if (sSlaveConfig->SlaveMode == TIM_SLAVEMODE_GATED)
7168 {
7169 return HAL_ERROR;
7170 }
7171
7172 /* Disable the Channel 1: Reset the CC1E Bit */
7173 tmpccer = htim->Instance->CCER;
7174 htim->Instance->CCER &= ~TIM_CCER_CC1E;
7175 tmpccmr1 = htim->Instance->CCMR1;
7176
7177 /* Set the filter */
7178 tmpccmr1 &= ~TIM_CCMR1_IC1F;
7179 tmpccmr1 |= ((sSlaveConfig->TriggerFilter) << 4U);
7180
7181 /* Write to TIMx CCMR1 and CCER registers */
7182 htim->Instance->CCMR1 = tmpccmr1;
7183 htim->Instance->CCER = tmpccer;
7184 break;
7185 }
7186
7187 case TIM_TS_TI1FP1:
7188 {
7189 /* Check the parameters */
7190 assert_param(IS_TIM_CC1_INSTANCE(htim->Instance));
7193
7194 /* Configure TI1 Filter and Polarity */
7195 TIM_TI1_ConfigInputStage(htim->Instance,
7196 sSlaveConfig->TriggerPolarity,
7197 sSlaveConfig->TriggerFilter);
7198 break;
7199 }
7200
7201 case TIM_TS_TI2FP2:
7202 {
7203 /* Check the parameters */
7204 assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
7207
7208 /* Configure TI2 Filter and Polarity */
7209 TIM_TI2_ConfigInputStage(htim->Instance,
7210 sSlaveConfig->TriggerPolarity,
7211 sSlaveConfig->TriggerFilter);
7212 break;
7213 }
7214
7215 case TIM_TS_ITR0:
7216 case TIM_TS_ITR1:
7217 case TIM_TS_ITR2:
7218 case TIM_TS_ITR3:
7219 {
7220 /* Check the parameter */
7221 assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
7222 break;
7223 }
7224
7225 default:
7226 status = HAL_ERROR;
7227 break;
7228 }
7229
7230 return status;
7231}
7232
7253void TIM_TI1_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection,
7254 uint32_t TIM_ICFilter)
7255{
7256 uint32_t tmpccmr1;
7257 uint32_t tmpccer;
7258
7259 /* Get the TIMx CCER register value */
7260 tmpccer = TIMx->CCER;
7261
7262 /* Disable the Channel 1: Reset the CC1E Bit */
7263 TIMx->CCER &= ~TIM_CCER_CC1E;
7264 /* Disable the Channel 1N: Reset the CC1NE Bit */
7265 if (IS_TIM_CCXN_INSTANCE(TIMx, TIM_CHANNEL_1))
7266 {
7267 TIMx->CCER &= ~TIM_CCER_CC1NE;
7268 }
7269
7270 /* Get the TIMx CCMR1 register value */
7271 tmpccmr1 = TIMx->CCMR1;
7272
7273 /* Select the Input */
7274 if (IS_TIM_CC2_INSTANCE(TIMx) != RESET)
7275 {
7276 tmpccmr1 &= ~TIM_CCMR1_CC1S;
7277 tmpccmr1 |= TIM_ICSelection;
7278 }
7279 else
7280 {
7281 tmpccmr1 |= TIM_CCMR1_CC1S_0;
7282 }
7283
7284 /* Set the filter */
7285 tmpccmr1 &= ~TIM_CCMR1_IC1F;
7286 tmpccmr1 |= ((TIM_ICFilter << 4U) & TIM_CCMR1_IC1F);
7287
7288 /* Select the Polarity and set the CC1E Bit */
7289 tmpccer &= ~(TIM_CCER_CC1P | TIM_CCER_CC1NP);
7290 tmpccer |= (TIM_ICPolarity & (TIM_CCER_CC1P | TIM_CCER_CC1NP));
7291
7292 /* Write to TIMx CCMR1 and CCER registers */
7293 TIMx->CCMR1 = tmpccmr1;
7294 TIMx->CCER = tmpccer;
7295}
7296
7309static void TIM_TI1_ConfigInputStage(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICFilter)
7310{
7311 uint32_t tmpccmr1;
7312 uint32_t tmpccer;
7313
7314 /* Get the TIMx CCER register value */
7315 tmpccer = TIMx->CCER;
7316
7317 /* Disable the Channel 1: Reset the CC1E Bit */
7318 TIMx->CCER &= ~TIM_CCER_CC1E;
7319 /* Disable the Channel 1N: Reset the CC1NE Bit */
7320 if (IS_TIM_CCXN_INSTANCE(TIMx, TIM_CHANNEL_1))
7321 {
7322 TIMx->CCER &= ~TIM_CCER_CC1NE;
7323 }
7324
7325 /* Get the TIMx CCMR1 register value */
7326 tmpccmr1 = TIMx->CCMR1;
7327
7328 /* Set the filter */
7329 tmpccmr1 &= ~TIM_CCMR1_IC1F;
7330 tmpccmr1 |= (TIM_ICFilter << 4U);
7331
7332 /* Select the Polarity and set the CC1E Bit */
7333 tmpccer &= ~(TIM_CCER_CC1P | TIM_CCER_CC1NP);
7334 tmpccer |= TIM_ICPolarity;
7335
7336 /* Write to TIMx CCMR1 and CCER registers */
7337 TIMx->CCMR1 = tmpccmr1;
7338 TIMx->CCER = tmpccer;
7339}
7340
7361static void TIM_TI2_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection,
7362 uint32_t TIM_ICFilter)
7363{
7364 uint32_t tmpccmr1;
7365 uint32_t tmpccer;
7366
7367 /* Get the TIMx CCER register value */
7368 tmpccer = TIMx->CCER;
7369
7370 /* Disable the Channel 2: Reset the CC2E Bit */
7371 TIMx->CCER &= ~TIM_CCER_CC2E;
7372 /* Disable the Channel 2N: Reset the CC2NE Bit */
7373 if (IS_TIM_CCXN_INSTANCE(TIMx, TIM_CHANNEL_2))
7374 {
7375 TIMx->CCER &= ~TIM_CCER_CC2NE;
7376 }
7377
7378 /* Get the TIMx CCMR1 register value */
7379 tmpccmr1 = TIMx->CCMR1;
7380
7381 /* Select the Input */
7382 tmpccmr1 &= ~TIM_CCMR1_CC2S;
7383 tmpccmr1 |= (TIM_ICSelection << 8U);
7384
7385 /* Set the filter */
7386 tmpccmr1 &= ~TIM_CCMR1_IC2F;
7387 tmpccmr1 |= ((TIM_ICFilter << 12U) & TIM_CCMR1_IC2F);
7388
7389 /* Select the Polarity and set the CC2E Bit */
7390 tmpccer &= ~(TIM_CCER_CC2P | TIM_CCER_CC2NP);
7391 tmpccer |= ((TIM_ICPolarity << 4U) & (TIM_CCER_CC2P | TIM_CCER_CC2NP));
7392
7393 /* Write to TIMx CCMR1 and CCER registers */
7394 TIMx->CCMR1 = tmpccmr1 ;
7395 TIMx->CCER = tmpccer;
7396}
7397
7410static void TIM_TI2_ConfigInputStage(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICFilter)
7411{
7412 uint32_t tmpccmr1;
7413 uint32_t tmpccer;
7414
7415 /* Get the TIMx CCER register value */
7416 tmpccer = TIMx->CCER;
7417
7418 /* Disable the Channel 2: Reset the CC2E Bit */
7419 TIMx->CCER &= ~TIM_CCER_CC2E;
7420 /* Disable the Channel 2N: Reset the CC2NE Bit */
7421 if (IS_TIM_CCXN_INSTANCE(TIMx, TIM_CHANNEL_2))
7422 {
7423 TIMx->CCER &= ~TIM_CCER_CC2NE;
7424 }
7425
7426 /* Get the TIMx CCMR1 register value */
7427 tmpccmr1 = TIMx->CCMR1;
7428
7429 /* Set the filter */
7430 tmpccmr1 &= ~TIM_CCMR1_IC2F;
7431 tmpccmr1 |= (TIM_ICFilter << 12U);
7432
7433 /* Select the Polarity and set the CC2E Bit */
7434 tmpccer &= ~(TIM_CCER_CC2P | TIM_CCER_CC2NP);
7435 tmpccer |= (TIM_ICPolarity << 4U);
7436
7437 /* Write to TIMx CCMR1 and CCER registers */
7438 TIMx->CCMR1 = tmpccmr1 ;
7439 TIMx->CCER = tmpccer;
7440}
7441
7462static void TIM_TI3_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection,
7463 uint32_t TIM_ICFilter)
7464{
7465 uint32_t tmpccmr2;
7466 uint32_t tmpccer;
7467
7468 /* Get the TIMx CCER register value */
7469 tmpccer = TIMx->CCER;
7470
7471 /* Disable the Channel 3: Reset the CC3E Bit */
7472 TIMx->CCER &= ~TIM_CCER_CC3E;
7473 /* Disable the Channel 3N: Reset the CC3NE Bit */
7474 if (IS_TIM_CCXN_INSTANCE(TIMx, TIM_CHANNEL_3))
7475 {
7476 TIMx->CCER &= ~TIM_CCER_CC3NE;
7477 }
7478
7479 /* Get the TIMx CCMR2 register value */
7480 tmpccmr2 = TIMx->CCMR2;
7481
7482 /* Select the Input */
7483 tmpccmr2 &= ~TIM_CCMR2_CC3S;
7484 tmpccmr2 |= TIM_ICSelection;
7485
7486 /* Set the filter */
7487 tmpccmr2 &= ~TIM_CCMR2_IC3F;
7488 tmpccmr2 |= ((TIM_ICFilter << 4U) & TIM_CCMR2_IC3F);
7489
7490 /* Select the Polarity and set the CC3E Bit */
7491 tmpccer &= ~(TIM_CCER_CC3P | TIM_CCER_CC3NP);
7492 tmpccer |= ((TIM_ICPolarity << 8U) & (TIM_CCER_CC3P | TIM_CCER_CC3NP));
7493
7494 /* Write to TIMx CCMR2 and CCER registers */
7495 TIMx->CCMR2 = tmpccmr2;
7496 TIMx->CCER = tmpccer;
7497}
7498
7519static void TIM_TI4_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection,
7520 uint32_t TIM_ICFilter)
7521{
7522 uint32_t tmpccmr2;
7523 uint32_t tmpccer;
7524
7525 /* Get the TIMx CCER register value */
7526 tmpccer = TIMx->CCER;
7527
7528 /* Disable the Channel 4: Reset the CC4E Bit */
7529 TIMx->CCER &= ~TIM_CCER_CC4E;
7530
7531 /* Get the TIMx CCMR2 register value */
7532 tmpccmr2 = TIMx->CCMR2;
7533
7534 /* Select the Input */
7535 tmpccmr2 &= ~TIM_CCMR2_CC4S;
7536 tmpccmr2 |= (TIM_ICSelection << 8U);
7537
7538 /* Set the filter */
7539 tmpccmr2 &= ~TIM_CCMR2_IC4F;
7540 tmpccmr2 |= ((TIM_ICFilter << 12U) & TIM_CCMR2_IC4F);
7541
7542 /* Select the Polarity and set the CC4E Bit */
7543 tmpccer &= ~(TIM_CCER_CC4P | TIM_CCER_CC4NP);
7544 tmpccer |= ((TIM_ICPolarity << 12U) & (TIM_CCER_CC4P | TIM_CCER_CC4NP));
7545
7546 /* Write to TIMx CCMR2 and CCER registers */
7547 TIMx->CCMR2 = tmpccmr2;
7548 TIMx->CCER = tmpccer ;
7549}
7550
7566static void TIM_ITRx_SetConfig(TIM_TypeDef *TIMx, uint32_t InputTriggerSource)
7567{
7568 uint32_t tmpsmcr;
7569
7570 /* Get the TIMx SMCR register value */
7571 tmpsmcr = TIMx->SMCR;
7572 /* Reset the TS Bits */
7573 tmpsmcr &= ~TIM_SMCR_TS;
7574 /* Set the Input Trigger source and the slave mode*/
7575 tmpsmcr |= (InputTriggerSource | TIM_SLAVEMODE_EXTERNAL1);
7576 /* Write to TIMx SMCR */
7577 TIMx->SMCR = tmpsmcr;
7578}
7596void TIM_ETR_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ExtTRGPrescaler,
7597 uint32_t TIM_ExtTRGPolarity, uint32_t ExtTRGFilter)
7598{
7599 uint32_t tmpsmcr;
7600
7601 tmpsmcr = TIMx->SMCR;
7602
7603 /* Reset the ETR Bits */
7604 tmpsmcr &= ~(TIM_SMCR_ETF | TIM_SMCR_ETPS | TIM_SMCR_ECE | TIM_SMCR_ETP);
7605
7606 /* Set the Prescaler, the Filter value and the Polarity */
7607 tmpsmcr |= (uint32_t)(TIM_ExtTRGPrescaler | (TIM_ExtTRGPolarity | (ExtTRGFilter << 8U)));
7608
7609 /* Write to TIMx SMCR */
7610 TIMx->SMCR = tmpsmcr;
7611}
7612
7626void TIM_CCxChannelCmd(TIM_TypeDef *TIMx, uint32_t Channel, uint32_t ChannelState)
7627{
7628 uint32_t tmp;
7629
7630 /* Check the parameters */
7631 assert_param(IS_TIM_CC1_INSTANCE(TIMx));
7632 assert_param(IS_TIM_CHANNELS(Channel));
7633
7634 tmp = TIM_CCER_CC1E << (Channel & 0x1FU); /* 0x1FU = 31 bits max shift */
7635
7636 /* Reset the CCxE Bit */
7637 TIMx->CCER &= ~tmp;
7638
7639 /* Set or reset the CCxE Bit */
7640 TIMx->CCER |= (uint32_t)(ChannelState << (Channel & 0x1FU)); /* 0x1FU = 31 bits max shift */
7641}
7642
7643#if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
7650void TIM_ResetCallback(TIM_HandleTypeDef *htim)
7651{
7652 /* Reset the TIM callback to the legacy weak callbacks */
7653 htim->PeriodElapsedCallback = HAL_TIM_PeriodElapsedCallback;
7654 htim->PeriodElapsedHalfCpltCallback = HAL_TIM_PeriodElapsedHalfCpltCallback;
7655 htim->TriggerCallback = HAL_TIM_TriggerCallback;
7656 htim->TriggerHalfCpltCallback = HAL_TIM_TriggerHalfCpltCallback;
7657 htim->IC_CaptureCallback = HAL_TIM_IC_CaptureCallback;
7658 htim->IC_CaptureHalfCpltCallback = HAL_TIM_IC_CaptureHalfCpltCallback;
7659 htim->OC_DelayElapsedCallback = HAL_TIM_OC_DelayElapsedCallback;
7660 htim->PWM_PulseFinishedCallback = HAL_TIM_PWM_PulseFinishedCallback;
7661 htim->PWM_PulseFinishedHalfCpltCallback = HAL_TIM_PWM_PulseFinishedHalfCpltCallback;
7662 htim->ErrorCallback = HAL_TIM_ErrorCallback;
7663 htim->CommutationCallback = HAL_TIMEx_CommutCallback;
7664 htim->CommutationHalfCpltCallback = HAL_TIMEx_CommutHalfCpltCallback;
7665 htim->BreakCallback = HAL_TIMEx_BreakCallback;
7666}
7667#endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
7668
7672
7673#endif /* HAL_TIM_MODULE_ENABLED */
7677
#define TIM_CCx_DISABLE
#define TIM_CCx_ENABLE
HAL_StatusTypeDef HAL_DMA_Abort_IT(DMA_HandleTypeDef *hdma)
HAL_StatusTypeDef HAL_DMA_Start_IT(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength)
struct __DMA_HandleTypeDef DMA_HandleTypeDef
DMA handle Structure definition.
#define TIM_DMA_ID_UPDATE
#define TIM_DMA_ID_CC4
#define TIM_DMA_ID_TRIGGER
#define TIM_DMA_ID_CC3
#define TIM_DMA_ID_CC1
#define TIM_DMA_ID_CC2
#define TIM_DMA_ID_COMMUTATION
#define DMA_NORMAL
void HAL_TIMEx_HallSensor_MspInit(TIM_HandleTypeDef *htim)
void HAL_TIMEx_HallSensor_MspDeInit(TIM_HandleTypeDef *htim)
void HAL_TIMEx_BreakCallback(TIM_HandleTypeDef *htim)
void HAL_TIMEx_CommutHalfCpltCallback(TIM_HandleTypeDef *htim)
void HAL_TIMEx_CommutCallback(TIM_HandleTypeDef *htim)
void TIMEx_DMACommutationHalfCplt(DMA_HandleTypeDef *hdma)
void TIMEx_DMACommutationCplt(DMA_HandleTypeDef *hdma)
#define TIM_CHANNEL_2
#define TIM_CHANNEL_3
#define TIM_CHANNEL_1
#define TIM_CHANNEL_4
#define TIM_CLEARINPUTPRESCALER_DIV1
#define TIM_CLEARINPUTSOURCE_NONE
#define TIM_CLEARINPUTSOURCE_ETR
#define TIM_CLOCKSOURCE_TI1
#define TIM_CLOCKSOURCE_ITR3
#define TIM_CLOCKSOURCE_ITR0
#define TIM_CLOCKSOURCE_TI2
#define TIM_CLOCKSOURCE_INTERNAL
#define TIM_CLOCKSOURCE_ETRMODE1
#define TIM_CLOCKSOURCE_ETRMODE2
#define TIM_CLOCKSOURCE_TI1ED
#define TIM_CLOCKSOURCE_ITR1
#define TIM_CLOCKSOURCE_ITR2
#define TIM_DMA_TRIGGER
#define TIM_DMA_CC1
#define TIM_DMA_CC3
#define TIM_DMA_UPDATE
#define TIM_DMA_CC4
#define TIM_DMA_CC2
#define TIM_DMA_COM
HAL_TIM_StateTypeDef HAL_TIM_OnePulse_GetState(const TIM_HandleTypeDef *htim)
HAL_TIM_StateTypeDef HAL_TIM_IC_GetState(const TIM_HandleTypeDef *htim)
HAL_TIM_ChannelStateTypeDef HAL_TIM_GetChannelState(const TIM_HandleTypeDef *htim, uint32_t Channel)
HAL_TIM_StateTypeDef HAL_TIM_Base_GetState(const TIM_HandleTypeDef *htim)
HAL_TIM_StateTypeDef HAL_TIM_Encoder_GetState(const TIM_HandleTypeDef *htim)
HAL_TIM_StateTypeDef HAL_TIM_PWM_GetState(const TIM_HandleTypeDef *htim)
HAL_TIM_ActiveChannel HAL_TIM_GetActiveChannel(const TIM_HandleTypeDef *htim)
HAL_TIM_DMABurstStateTypeDef HAL_TIM_DMABurstState(const TIM_HandleTypeDef *htim)
HAL_TIM_StateTypeDef HAL_TIM_OC_GetState(const TIM_HandleTypeDef *htim)
void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef *htim)
HAL_StatusTypeDef HAL_TIM_Base_Stop_IT(TIM_HandleTypeDef *htim)
HAL_StatusTypeDef HAL_TIM_Base_Init(TIM_HandleTypeDef *htim)
HAL_StatusTypeDef HAL_TIM_Base_Start_DMA(TIM_HandleTypeDef *htim, const uint32_t *pData, uint16_t Length)
HAL_StatusTypeDef HAL_TIM_Base_Stop_DMA(TIM_HandleTypeDef *htim)
HAL_StatusTypeDef HAL_TIM_Base_Stop(TIM_HandleTypeDef *htim)
void HAL_TIM_Base_MspInit(TIM_HandleTypeDef *htim)
HAL_StatusTypeDef HAL_TIM_Base_DeInit(TIM_HandleTypeDef *htim)
HAL_StatusTypeDef HAL_TIM_Base_Start_IT(TIM_HandleTypeDef *htim)
HAL_StatusTypeDef HAL_TIM_Base_Start(TIM_HandleTypeDef *htim)
HAL_StatusTypeDef HAL_TIM_OC_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, const uint32_t *pData, uint16_t Length)
HAL_StatusTypeDef HAL_TIM_OC_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel)
void HAL_TIM_OC_MspDeInit(TIM_HandleTypeDef *htim)
HAL_StatusTypeDef HAL_TIM_OC_Start(TIM_HandleTypeDef *htim, uint32_t Channel)
HAL_StatusTypeDef HAL_TIM_OC_Init(TIM_HandleTypeDef *htim)
HAL_StatusTypeDef HAL_TIM_OC_DeInit(TIM_HandleTypeDef *htim)
HAL_StatusTypeDef HAL_TIM_OC_Stop(TIM_HandleTypeDef *htim, uint32_t Channel)
void HAL_TIM_OC_MspInit(TIM_HandleTypeDef *htim)
HAL_StatusTypeDef HAL_TIM_OC_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
HAL_StatusTypeDef HAL_TIM_OC_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
HAL_StatusTypeDef HAL_TIM_PWM_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
HAL_StatusTypeDef HAL_TIM_PWM_Start(TIM_HandleTypeDef *htim, uint32_t Channel)
HAL_StatusTypeDef HAL_TIM_PWM_Init(TIM_HandleTypeDef *htim)
HAL_StatusTypeDef HAL_TIM_PWM_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, const uint32_t *pData, uint16_t Length)
void HAL_TIM_PWM_MspDeInit(TIM_HandleTypeDef *htim)
HAL_StatusTypeDef HAL_TIM_PWM_DeInit(TIM_HandleTypeDef *htim)
HAL_StatusTypeDef HAL_TIM_PWM_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
HAL_StatusTypeDef HAL_TIM_PWM_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel)
HAL_StatusTypeDef HAL_TIM_PWM_Stop(TIM_HandleTypeDef *htim, uint32_t Channel)
void HAL_TIM_PWM_MspInit(TIM_HandleTypeDef *htim)
HAL_StatusTypeDef HAL_TIM_IC_Stop(TIM_HandleTypeDef *htim, uint32_t Channel)
void HAL_TIM_IC_MspInit(TIM_HandleTypeDef *htim)
HAL_StatusTypeDef HAL_TIM_IC_DeInit(TIM_HandleTypeDef *htim)
HAL_StatusTypeDef HAL_TIM_IC_Init(TIM_HandleTypeDef *htim)
HAL_StatusTypeDef HAL_TIM_IC_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel)
HAL_StatusTypeDef HAL_TIM_IC_Start(TIM_HandleTypeDef *htim, uint32_t Channel)
HAL_StatusTypeDef HAL_TIM_IC_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
HAL_StatusTypeDef HAL_TIM_IC_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length)
void HAL_TIM_IC_MspDeInit(TIM_HandleTypeDef *htim)
HAL_StatusTypeDef HAL_TIM_IC_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
HAL_StatusTypeDef HAL_TIM_OnePulse_Start(TIM_HandleTypeDef *htim, uint32_t OutputChannel)
HAL_StatusTypeDef HAL_TIM_OnePulse_Init(TIM_HandleTypeDef *htim, uint32_t OnePulseMode)
void HAL_TIM_OnePulse_MspInit(TIM_HandleTypeDef *htim)
HAL_StatusTypeDef HAL_TIM_OnePulse_Stop_IT(TIM_HandleTypeDef *htim, uint32_t OutputChannel)
void HAL_TIM_OnePulse_MspDeInit(TIM_HandleTypeDef *htim)
HAL_StatusTypeDef HAL_TIM_OnePulse_Stop(TIM_HandleTypeDef *htim, uint32_t OutputChannel)
HAL_StatusTypeDef HAL_TIM_OnePulse_DeInit(TIM_HandleTypeDef *htim)
HAL_StatusTypeDef HAL_TIM_OnePulse_Start_IT(TIM_HandleTypeDef *htim, uint32_t OutputChannel)
HAL_StatusTypeDef HAL_TIM_Encoder_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel)
void HAL_TIM_Encoder_MspInit(TIM_HandleTypeDef *htim)
HAL_StatusTypeDef HAL_TIM_Encoder_Stop(TIM_HandleTypeDef *htim, uint32_t Channel)
HAL_StatusTypeDef HAL_TIM_Encoder_Start(TIM_HandleTypeDef *htim, uint32_t Channel)
void HAL_TIM_Encoder_MspDeInit(TIM_HandleTypeDef *htim)
HAL_StatusTypeDef HAL_TIM_Encoder_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData1, uint32_t *pData2, uint16_t Length)
HAL_StatusTypeDef HAL_TIM_Encoder_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
HAL_StatusTypeDef HAL_TIM_Encoder_DeInit(TIM_HandleTypeDef *htim)
HAL_StatusTypeDef HAL_TIM_Encoder_Init(TIM_HandleTypeDef *htim, const TIM_Encoder_InitTypeDef *sConfig)
HAL_StatusTypeDef HAL_TIM_Encoder_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
void HAL_TIM_IRQHandler(TIM_HandleTypeDef *htim)
HAL_StatusTypeDef HAL_TIM_IC_ConfigChannel(TIM_HandleTypeDef *htim, const TIM_IC_InitTypeDef *sConfig, uint32_t Channel)
HAL_StatusTypeDef HAL_TIM_DMABurst_MultiWriteStart(TIM_HandleTypeDef *htim, uint32_t BurstBaseAddress, uint32_t BurstRequestSrc, const uint32_t *BurstBuffer, uint32_t BurstLength, uint32_t DataLength)
HAL_StatusTypeDef HAL_TIM_PWM_ConfigChannel(TIM_HandleTypeDef *htim, const TIM_OC_InitTypeDef *sConfig, uint32_t Channel)
HAL_StatusTypeDef HAL_TIM_DMABurst_WriteStart(TIM_HandleTypeDef *htim, uint32_t BurstBaseAddress, uint32_t BurstRequestSrc, const uint32_t *BurstBuffer, uint32_t BurstLength)
HAL_StatusTypeDef HAL_TIM_DMABurst_ReadStart(TIM_HandleTypeDef *htim, uint32_t BurstBaseAddress, uint32_t BurstRequestSrc, uint32_t *BurstBuffer, uint32_t BurstLength)
HAL_StatusTypeDef HAL_TIM_DMABurst_ReadStop(TIM_HandleTypeDef *htim, uint32_t BurstRequestSrc)
HAL_StatusTypeDef HAL_TIM_SlaveConfigSynchro(TIM_HandleTypeDef *htim, const TIM_SlaveConfigTypeDef *sSlaveConfig)
HAL_StatusTypeDef HAL_TIM_SlaveConfigSynchro_IT(TIM_HandleTypeDef *htim, const TIM_SlaveConfigTypeDef *sSlaveConfig)
uint32_t HAL_TIM_ReadCapturedValue(const TIM_HandleTypeDef *htim, uint32_t Channel)
HAL_StatusTypeDef HAL_TIM_DMABurst_MultiReadStart(TIM_HandleTypeDef *htim, uint32_t BurstBaseAddress, uint32_t BurstRequestSrc, uint32_t *BurstBuffer, uint32_t BurstLength, uint32_t DataLength)
HAL_StatusTypeDef HAL_TIM_ConfigTI1Input(TIM_HandleTypeDef *htim, uint32_t TI1_Selection)
HAL_StatusTypeDef HAL_TIM_DMABurst_WriteStop(TIM_HandleTypeDef *htim, uint32_t BurstRequestSrc)
HAL_StatusTypeDef HAL_TIM_OC_ConfigChannel(TIM_HandleTypeDef *htim, const TIM_OC_InitTypeDef *sConfig, uint32_t Channel)
HAL_StatusTypeDef HAL_TIM_ConfigClockSource(TIM_HandleTypeDef *htim, const TIM_ClockConfigTypeDef *sClockSourceConfig)
HAL_StatusTypeDef HAL_TIM_GenerateEvent(TIM_HandleTypeDef *htim, uint32_t EventSource)
HAL_StatusTypeDef HAL_TIM_ConfigOCrefClear(TIM_HandleTypeDef *htim, const TIM_ClearInputConfigTypeDef *sClearInputConfig, uint32_t Channel)
HAL_StatusTypeDef HAL_TIM_OnePulse_ConfigChannel(TIM_HandleTypeDef *htim, TIM_OnePulse_InitTypeDef *sConfig, uint32_t OutputChannel, uint32_t InputChannel)
void HAL_TIM_PWM_PulseFinishedCallback(TIM_HandleTypeDef *htim)
void HAL_TIM_TriggerCallback(TIM_HandleTypeDef *htim)
void HAL_TIM_PeriodElapsedHalfCpltCallback(TIM_HandleTypeDef *htim)
void HAL_TIM_OC_DelayElapsedCallback(TIM_HandleTypeDef *htim)
void HAL_TIM_IC_CaptureHalfCpltCallback(TIM_HandleTypeDef *htim)
void HAL_TIM_ErrorCallback(TIM_HandleTypeDef *htim)
void HAL_TIM_TriggerHalfCpltCallback(TIM_HandleTypeDef *htim)
void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim)
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
Period elapsed callback in non blocking mode.
void HAL_TIM_PWM_PulseFinishedHalfCpltCallback(TIM_HandleTypeDef *htim)
#define __HAL_TIM_MOE_ENABLE(__HANDLE__)
Enable the TIM main Output.
#define __HAL_TIM_DISABLE_DMA(__HANDLE__, __DMA__)
Disable the specified DMA request.
#define __HAL_TIM_ENABLE(__HANDLE__)
Enable the TIM peripheral.
#define __HAL_TIM_CLEAR_FLAG(__HANDLE__, __FLAG__)
Clear the specified TIM interrupt flag.
#define __HAL_TIM_DISABLE_IT(__HANDLE__, __INTERRUPT__)
Disable the specified TIM interrupt.
#define __HAL_TIM_ENABLE_IT(__HANDLE__, __INTERRUPT__)
Enable the specified TIM interrupt.
#define __HAL_TIM_MOE_DISABLE(__HANDLE__)
Disable the TIM main Output.
#define __HAL_TIM_DISABLE(__HANDLE__)
Disable the TIM peripheral.
#define __HAL_TIM_ENABLE_DMA(__HANDLE__, __DMA__)
Enable the specified DMA request.
HAL_TIM_ChannelStateTypeDef
TIM Channel States definition.
HAL_TIM_DMABurstStateTypeDef
DMA Burst States definition.
HAL_TIM_ActiveChannel
HAL Active channel structures definition.
HAL_TIM_StateTypeDef
HAL State structures definition.
@ HAL_TIM_CHANNEL_STATE_READY
@ HAL_TIM_CHANNEL_STATE_RESET
@ HAL_TIM_CHANNEL_STATE_BUSY
@ HAL_DMA_BURST_STATE_BUSY
@ HAL_DMA_BURST_STATE_READY
@ HAL_DMA_BURST_STATE_RESET
@ HAL_TIM_ACTIVE_CHANNEL_1
@ HAL_TIM_ACTIVE_CHANNEL_CLEARED
@ HAL_TIM_ACTIVE_CHANNEL_4
@ HAL_TIM_ACTIVE_CHANNEL_3
@ HAL_TIM_ACTIVE_CHANNEL_2
@ HAL_TIM_STATE_BUSY
@ HAL_TIM_STATE_RESET
@ HAL_TIM_STATE_READY
#define TIM_FLAG_BREAK
#define TIM_FLAG_CC3
#define TIM_FLAG_CC2
#define TIM_FLAG_CC1
#define TIM_FLAG_UPDATE
#define TIM_FLAG_TRIGGER
#define TIM_FLAG_COM
#define TIM_FLAG_CC4
#define TIM_IT_CC1
#define TIM_IT_CC4
#define TIM_IT_TRIGGER
#define TIM_IT_BREAK
#define TIM_IT_CC2
#define TIM_IT_UPDATE
#define TIM_IT_CC3
#define TIM_IT_COM
void TIM_ETR_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ExtTRGPrescaler, uint32_t TIM_ExtTRGPolarity, uint32_t ExtTRGFilter)
void TIM_DMACaptureHalfCplt(DMA_HandleTypeDef *hdma)
void TIM_OC2_SetConfig(TIM_TypeDef *TIMx, const TIM_OC_InitTypeDef *OC_Config)
void TIM_DMACaptureCplt(DMA_HandleTypeDef *hdma)
void TIM_CCxChannelCmd(TIM_TypeDef *TIMx, uint32_t Channel, uint32_t ChannelState)
void TIM_TI1_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection, uint32_t TIM_ICFilter)
void TIM_DMADelayPulseHalfCplt(DMA_HandleTypeDef *hdma)
void TIM_DMAError(DMA_HandleTypeDef *hdma)
void TIM_Base_SetConfig(TIM_TypeDef *TIMx, const TIM_Base_InitTypeDef *Structure)
#define IS_TIM_CLEARINPUT_POLARITY(__POLARITY__)
#define IS_TIM_CLEARINPUT_SOURCE(__MODE__)
#define IS_TIM_TRIGGER_SELECTION(__SELECTION__)
#define IS_TIM_IC_POLARITY(__POLARITY__)
#define IS_TIM_CHANNELS(__CHANNEL__)
#define IS_TIM_IC_FILTER(__ICFILTER__)
#define IS_TIM_OPM_MODE(__MODE__)
#define IS_TIM_IC_SELECTION(__SELECTION__)
#define TIM_CHANNEL_N_STATE_GET(__HANDLE__, __CHANNEL__)
#define IS_TIM_TRIGGERPOLARITY(__POLARITY__)
#define IS_TIM_SLAVEMODE_TRIGGER_ENABLED(__TRIGGER__)
#define IS_TIM_ENCODER_MODE(__MODE__)
#define IS_TIM_COUNTER_MODE(__MODE__)
#define IS_TIM_DMA_LENGTH(__LENGTH__)
#define IS_TIM_TI1SELECTION(__TI1SELECTION__)
#define IS_TIM_DMA_SOURCE(__SOURCE__)
#define IS_TIM_ENCODERINPUT_POLARITY(__POLARITY__)
#define IS_TIM_OCNIDLE_STATE(__STATE__)
#define IS_TIM_PWM_MODE(__MODE__)
#define TIM_CHANNEL_N_STATE_SET_ALL(__HANDLE__, __CHANNEL_STATE__)
#define IS_TIM_OCIDLE_STATE(__STATE__)
#define IS_TIM_CLOCKFILTER(__ICFILTER__)
#define IS_TIM_DMA_DATA_LENGTH(LENGTH)
#define IS_TIM_CLEARINPUT_PRESCALER(__PRESCALER__)
#define IS_TIM_IC_PRESCALER(__PRESCALER__)
#define IS_TIM_CLOCKPOLARITY(__POLARITY__)
#define TIM_CHANNEL_STATE_SET(__HANDLE__, __CHANNEL__, __CHANNEL_STATE__)
#define IS_TIM_OCN_POLARITY(__POLARITY__)
#define IS_TIM_TRIGGERFILTER(__ICFILTER__)
#define IS_TIM_OPM_CHANNELS(__CHANNEL__)
#define IS_TIM_AUTORELOAD_PRELOAD(PRELOAD)
#define TIM_CHANNEL_N_STATE_SET(__HANDLE__, __CHANNEL__, __CHANNEL_STATE__)
#define IS_TIM_TRIGGERPRESCALER(__PRESCALER__)
#define IS_TIM_OC_MODE(__MODE__)
#define IS_TIM_CLOCKDIVISION_DIV(__DIV__)
#define IS_TIM_CLOCKPRESCALER(__PRESCALER__)
#define IS_TIM_EVENT_SOURCE(__SOURCE__)
#define IS_TIM_CLOCKSOURCE(__CLOCK__)
#define TIM_CHANNEL_STATE_GET(__HANDLE__, __CHANNEL__)
#define TIM_CHANNEL_STATE_SET_ALL(__HANDLE__, __CHANNEL_STATE__)
#define IS_TIM_FAST_STATE(__STATE__)
#define IS_TIM_DMA_BASE(__BASE__)
#define IS_TIM_PERIOD(__HANDLE__, __PERIOD__)
#define IS_TIM_CLEARINPUT_FILTER(__ICFILTER__)
#define IS_TIM_SLAVE_MODE(__MODE__)
#define IS_TIM_OC_POLARITY(__POLARITY__)
#define TIM_SLAVEMODE_TRIGGER
#define TIM_SLAVEMODE_GATED
#define TIM_SLAVEMODE_EXTERNAL1
#define TIM_TS_TI2FP2
#define TIM_TS_TI1FP1
#define TIM_TS_ITR3
#define TIM_TS_ITR2
#define TIM_TS_TI1F_ED
#define TIM_TS_ITR0
#define TIM_TS_ITR1
#define TIM_TS_ETRF
#define assert_param(expr)
This file contains all the functions prototypes for the HAL module driver.
HAL_StatusTypeDef
HAL Status structures definition.
@ HAL_ERROR
@ HAL_OK
@ HAL_BUSY
#define __HAL_UNLOCK(__HANDLE__)
@ HAL_UNLOCKED
#define __HAL_LOCK(__HANDLE__)
TIM Time base Configuration Structure definition.
TIM Clear Input Configuration Handle Structure definition.
Clock Configuration Handle Structure definition.
TIM Encoder Configuration Structure definition.
TIM Time Base Handle Structure definition.
DMA_HandleTypeDef * hdma[7]
HAL_LockTypeDef Lock
volatile HAL_TIM_StateTypeDef State
volatile HAL_TIM_DMABurstStateTypeDef DMABurstState
TIM_Base_InitTypeDef Init
HAL_TIM_ActiveChannel Channel
TIM Input Capture Configuration Structure definition.
TIM Output Compare Configuration Structure definition.
TIM One Pulse Mode Configuration Structure definition.
TIM Slave configuration Structure definition.
void(* XferCpltCallback)(struct __DMA_HandleTypeDef *hdma)
void(* XferErrorCallback)(struct __DMA_HandleTypeDef *hdma)
void(* XferHalfCpltCallback)(struct __DMA_HandleTypeDef *hdma)