STM32F4xx HAL Documentation
Hardware Abstraction Layer for STM32F4 familiy
Loading...
Searching...
No Matches
stm32f4xx_hal_tim_ex.c
Go to the documentation of this file.
1
80/* Includes ------------------------------------------------------------------*/
81#include "stm32f4xx_hal.h"
82
92#ifdef HAL_TIM_MODULE_ENABLED
93
94/* Private typedef -----------------------------------------------------------*/
95/* Private define ------------------------------------------------------------*/
96/* Private macros ------------------------------------------------------------*/
97/* Private variables ---------------------------------------------------------*/
98/* Private function prototypes -----------------------------------------------*/
100static void TIM_DMAErrorCCxN(DMA_HandleTypeDef *hdma);
101static void TIM_CCxNChannelCmd(TIM_TypeDef *TIMx, uint32_t Channel, uint32_t ChannelNState);
102
103/* Exported functions --------------------------------------------------------*/
139{
140 TIM_OC_InitTypeDef OC_Config;
141
142 /* Check the TIM handle allocation */
143 if (htim == NULL)
144 {
145 return HAL_ERROR;
146 }
147
148 /* Check the parameters */
149 assert_param(IS_TIM_HALL_SENSOR_INTERFACE_INSTANCE(htim->Instance));
157
158 if (htim->State == HAL_TIM_STATE_RESET)
159 {
160 /* Allocate lock resource and initialize it */
161 htim->Lock = HAL_UNLOCKED;
162
163#if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
164 /* Reset interrupt callbacks to legacy week callbacks */
165 TIM_ResetCallback(htim);
166
167 if (htim->HallSensor_MspInitCallback == NULL)
168 {
169 htim->HallSensor_MspInitCallback = HAL_TIMEx_HallSensor_MspInit;
170 }
171 /* Init the low level hardware : GPIO, CLOCK, NVIC */
172 htim->HallSensor_MspInitCallback(htim);
173#else
174 /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */
176#endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
177 }
178
179 /* Set the TIM state */
181
182 /* Configure the Time base in the Encoder Mode */
183 TIM_Base_SetConfig(htim->Instance, &htim->Init);
184
185 /* Configure the Channel 1 as Input Channel to interface with the three Outputs of the Hall sensor */
187
188 /* Reset the IC1PSC Bits */
189 htim->Instance->CCMR1 &= ~TIM_CCMR1_IC1PSC;
190 /* Set the IC1PSC value */
191 htim->Instance->CCMR1 |= sConfig->IC1Prescaler;
192
193 /* Enable the Hall sensor interface (XOR function of the three inputs) */
194 htim->Instance->CR2 |= TIM_CR2_TI1S;
195
196 /* Select the TIM_TS_TI1F_ED signal as Input trigger for the TIM */
197 htim->Instance->SMCR &= ~TIM_SMCR_TS;
198 htim->Instance->SMCR |= TIM_TS_TI1F_ED;
199
200 /* Use the TIM_TS_TI1F_ED signal to reset the TIM counter each edge detection */
201 htim->Instance->SMCR &= ~TIM_SMCR_SMS;
202 htim->Instance->SMCR |= TIM_SLAVEMODE_RESET;
203
204 /* Program channel 2 in PWM 2 mode with the desired Commutation_Delay*/
205 OC_Config.OCFastMode = TIM_OCFAST_DISABLE;
207 OC_Config.OCMode = TIM_OCMODE_PWM2;
211 OC_Config.Pulse = sConfig->Commutation_Delay;
212
213 TIM_OC2_SetConfig(htim->Instance, &OC_Config);
214
215 /* Select OC2REF as trigger output on TRGO: write the MMS bits in the TIMx_CR2
216 register to 101 */
217 htim->Instance->CR2 &= ~TIM_CR2_MMS;
218 htim->Instance->CR2 |= TIM_TRGO_OC2REF;
219
220 /* Initialize the DMA burst operation state */
222
223 /* Initialize the TIM channels state */
228
229 /* Initialize the TIM state*/
231
232 return HAL_OK;
233}
234
241{
242 /* Check the parameters */
243 assert_param(IS_TIM_INSTANCE(htim->Instance));
244
246
247 /* Disable the TIM Peripheral Clock */
248 __HAL_TIM_DISABLE(htim);
249
250#if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
251 if (htim->HallSensor_MspDeInitCallback == NULL)
252 {
253 htim->HallSensor_MspDeInitCallback = HAL_TIMEx_HallSensor_MspDeInit;
254 }
255 /* DeInit the low level hardware */
256 htim->HallSensor_MspDeInitCallback(htim);
257#else
258 /* DeInit the low level hardware: GPIO, CLOCK, NVIC */
260#endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
261
262 /* Change the DMA burst operation state */
264
265 /* Change the TIM channels state */
270
271 /* Change TIM state */
273
274 /* Release Lock */
275 __HAL_UNLOCK(htim);
276
277 return HAL_OK;
278}
279
286{
287 /* Prevent unused argument(s) compilation warning */
288 UNUSED(htim);
289
290 /* NOTE : This function should not be modified, when the callback is needed,
291 the HAL_TIMEx_HallSensor_MspInit could be implemented in the user file
292 */
293}
294
301{
302 /* Prevent unused argument(s) compilation warning */
303 UNUSED(htim);
304
305 /* NOTE : This function should not be modified, when the callback is needed,
306 the HAL_TIMEx_HallSensor_MspDeInit could be implemented in the user file
307 */
308}
309
316{
317 uint32_t tmpsmcr;
320 HAL_TIM_ChannelStateTypeDef complementary_channel_1_state = TIM_CHANNEL_N_STATE_GET(htim, TIM_CHANNEL_1);
321 HAL_TIM_ChannelStateTypeDef complementary_channel_2_state = TIM_CHANNEL_N_STATE_GET(htim, TIM_CHANNEL_2);
322
323 /* Check the parameters */
324 assert_param(IS_TIM_HALL_SENSOR_INTERFACE_INSTANCE(htim->Instance));
325
326 /* Check the TIM channels state */
327 if ((channel_1_state != HAL_TIM_CHANNEL_STATE_READY)
328 || (channel_2_state != HAL_TIM_CHANNEL_STATE_READY)
329 || (complementary_channel_1_state != HAL_TIM_CHANNEL_STATE_READY)
330 || (complementary_channel_2_state != HAL_TIM_CHANNEL_STATE_READY))
331 {
332 return HAL_ERROR;
333 }
334
335 /* Set the TIM channels state */
340
341 /* Enable the Input Capture channel 1
342 (in the Hall Sensor Interface the three possible channels that can be used are TIM_CHANNEL_1,
343 TIM_CHANNEL_2 and TIM_CHANNEL_3) */
345
346 /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
347 if (IS_TIM_SLAVE_INSTANCE(htim->Instance))
348 {
349 tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
351 {
352 __HAL_TIM_ENABLE(htim);
353 }
354 }
355 else
356 {
357 __HAL_TIM_ENABLE(htim);
358 }
359
360 /* Return function status */
361 return HAL_OK;
362}
363
370{
371 /* Check the parameters */
372 assert_param(IS_TIM_HALL_SENSOR_INTERFACE_INSTANCE(htim->Instance));
373
374 /* Disable the Input Capture channels 1, 2 and 3
375 (in the Hall Sensor Interface the three possible channels that can be used are TIM_CHANNEL_1,
376 TIM_CHANNEL_2 and TIM_CHANNEL_3) */
378
379 /* Disable the Peripheral */
380 __HAL_TIM_DISABLE(htim);
381
382 /* Set the TIM channels state */
387
388 /* Return function status */
389 return HAL_OK;
390}
391
398{
399 uint32_t tmpsmcr;
402 HAL_TIM_ChannelStateTypeDef complementary_channel_1_state = TIM_CHANNEL_N_STATE_GET(htim, TIM_CHANNEL_1);
403 HAL_TIM_ChannelStateTypeDef complementary_channel_2_state = TIM_CHANNEL_N_STATE_GET(htim, TIM_CHANNEL_2);
404
405 /* Check the parameters */
406 assert_param(IS_TIM_HALL_SENSOR_INTERFACE_INSTANCE(htim->Instance));
407
408 /* Check the TIM channels state */
409 if ((channel_1_state != HAL_TIM_CHANNEL_STATE_READY)
410 || (channel_2_state != HAL_TIM_CHANNEL_STATE_READY)
411 || (complementary_channel_1_state != HAL_TIM_CHANNEL_STATE_READY)
412 || (complementary_channel_2_state != HAL_TIM_CHANNEL_STATE_READY))
413 {
414 return HAL_ERROR;
415 }
416
417 /* Set the TIM channels state */
422
423 /* Enable the capture compare Interrupts 1 event */
425
426 /* Enable the Input Capture channel 1
427 (in the Hall Sensor Interface the three possible channels that can be used are TIM_CHANNEL_1,
428 TIM_CHANNEL_2 and TIM_CHANNEL_3) */
430
431 /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
432 if (IS_TIM_SLAVE_INSTANCE(htim->Instance))
433 {
434 tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
436 {
437 __HAL_TIM_ENABLE(htim);
438 }
439 }
440 else
441 {
442 __HAL_TIM_ENABLE(htim);
443 }
444
445 /* Return function status */
446 return HAL_OK;
447}
448
455{
456 /* Check the parameters */
457 assert_param(IS_TIM_HALL_SENSOR_INTERFACE_INSTANCE(htim->Instance));
458
459 /* Disable the Input Capture channel 1
460 (in the Hall Sensor Interface the three possible channels that can be used are TIM_CHANNEL_1,
461 TIM_CHANNEL_2 and TIM_CHANNEL_3) */
463
464 /* Disable the capture compare Interrupts event */
466
467 /* Disable the Peripheral */
468 __HAL_TIM_DISABLE(htim);
469
470 /* Set the TIM channels state */
475
476 /* Return function status */
477 return HAL_OK;
478}
479
488{
489 uint32_t tmpsmcr;
491 HAL_TIM_ChannelStateTypeDef complementary_channel_1_state = TIM_CHANNEL_N_STATE_GET(htim, TIM_CHANNEL_1);
492
493 /* Check the parameters */
494 assert_param(IS_TIM_HALL_SENSOR_INTERFACE_INSTANCE(htim->Instance));
495
496 /* Set the TIM channel state */
497 if ((channel_1_state == HAL_TIM_CHANNEL_STATE_BUSY)
498 || (complementary_channel_1_state == HAL_TIM_CHANNEL_STATE_BUSY))
499 {
500 return HAL_BUSY;
501 }
502 else if ((channel_1_state == HAL_TIM_CHANNEL_STATE_READY)
503 && (complementary_channel_1_state == HAL_TIM_CHANNEL_STATE_READY))
504 {
505 if ((pData == NULL) || (Length == 0U))
506 {
507 return HAL_ERROR;
508 }
509 else
510 {
513 }
514 }
515 else
516 {
517 return HAL_ERROR;
518 }
519
520 /* Enable the Input Capture channel 1
521 (in the Hall Sensor Interface the three possible channels that can be used are TIM_CHANNEL_1,
522 TIM_CHANNEL_2 and TIM_CHANNEL_3) */
524
525 /* Set the DMA Input Capture 1 Callbacks */
528 /* Set the DMA error callback */
530
531 /* Enable the DMA stream for Capture 1*/
532 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)&htim->Instance->CCR1, (uint32_t)pData, Length) != HAL_OK)
533 {
534 /* Return error status */
535 return HAL_ERROR;
536 }
537 /* Enable the capture compare 1 Interrupt */
539
540 /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
541 if (IS_TIM_SLAVE_INSTANCE(htim->Instance))
542 {
543 tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
545 {
546 __HAL_TIM_ENABLE(htim);
547 }
548 }
549 else
550 {
551 __HAL_TIM_ENABLE(htim);
552 }
553
554 /* Return function status */
555 return HAL_OK;
556}
557
564{
565 /* Check the parameters */
566 assert_param(IS_TIM_HALL_SENSOR_INTERFACE_INSTANCE(htim->Instance));
567
568 /* Disable the Input Capture channel 1
569 (in the Hall Sensor Interface the three possible channels that can be used are TIM_CHANNEL_1,
570 TIM_CHANNEL_2 and TIM_CHANNEL_3) */
572
573
574 /* Disable the capture compare Interrupts 1 event */
576
578
579 /* Disable the Peripheral */
580 __HAL_TIM_DISABLE(htim);
581
582 /* Set the TIM channel state */
585
586 /* Return function status */
587 return HAL_OK;
588}
589
626{
627 uint32_t tmpsmcr;
628
629 /* Check the parameters */
630 assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
631
632 /* Check the TIM complementary channel state */
634 {
635 return HAL_ERROR;
636 }
637
638 /* Set the TIM complementary channel state */
640
641 /* Enable the Capture compare channel N */
643
644 /* Enable the Main Output */
646
647 /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
648 if (IS_TIM_SLAVE_INSTANCE(htim->Instance))
649 {
650 tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
652 {
653 __HAL_TIM_ENABLE(htim);
654 }
655 }
656 else
657 {
658 __HAL_TIM_ENABLE(htim);
659 }
660
661 /* Return function status */
662 return HAL_OK;
663}
664
677{
678 /* Check the parameters */
679 assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
680
681 /* Disable the Capture compare channel N */
683
684 /* Disable the Main Output */
686
687 /* Disable the Peripheral */
688 __HAL_TIM_DISABLE(htim);
689
690 /* Set the TIM complementary channel state */
692
693 /* Return function status */
694 return HAL_OK;
695}
696
709{
710 HAL_StatusTypeDef status = HAL_OK;
711 uint32_t tmpsmcr;
712
713 /* Check the parameters */
714 assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
715
716 /* Check the TIM complementary channel state */
718 {
719 return HAL_ERROR;
720 }
721
722 /* Set the TIM complementary channel state */
724
725 switch (Channel)
726 {
727 case TIM_CHANNEL_1:
728 {
729 /* Enable the TIM Output Compare interrupt */
731 break;
732 }
733
734 case TIM_CHANNEL_2:
735 {
736 /* Enable the TIM Output Compare interrupt */
738 break;
739 }
740
741 case TIM_CHANNEL_3:
742 {
743 /* Enable the TIM Output Compare interrupt */
745 break;
746 }
747
748
749 default:
750 status = HAL_ERROR;
751 break;
752 }
753
754 if (status == HAL_OK)
755 {
756 /* Enable the TIM Break interrupt */
758
759 /* Enable the Capture compare channel N */
761
762 /* Enable the Main Output */
764
765 /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
766 if (IS_TIM_SLAVE_INSTANCE(htim->Instance))
767 {
768 tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
770 {
771 __HAL_TIM_ENABLE(htim);
772 }
773 }
774 else
775 {
776 __HAL_TIM_ENABLE(htim);
777 }
778 }
779
780 /* Return function status */
781 return status;
782}
783
796{
797 HAL_StatusTypeDef status = HAL_OK;
798 uint32_t tmpccer;
799
800 /* Check the parameters */
801 assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
802
803 switch (Channel)
804 {
805 case TIM_CHANNEL_1:
806 {
807 /* Disable the TIM Output Compare interrupt */
809 break;
810 }
811
812 case TIM_CHANNEL_2:
813 {
814 /* Disable the TIM Output Compare interrupt */
816 break;
817 }
818
819 case TIM_CHANNEL_3:
820 {
821 /* Disable the TIM Output Compare interrupt */
823 break;
824 }
825
826 default:
827 status = HAL_ERROR;
828 break;
829 }
830
831 if (status == HAL_OK)
832 {
833 /* Disable the Capture compare channel N */
835
836 /* Disable the TIM Break interrupt (only if no more channel is active) */
837 tmpccer = htim->Instance->CCER;
838 if ((tmpccer & TIM_CCER_CCxNE_MASK) == (uint32_t)RESET)
839 {
841 }
842
843 /* Disable the Main Output */
845
846 /* Disable the Peripheral */
847 __HAL_TIM_DISABLE(htim);
848
849 /* Set the TIM complementary channel state */
851 }
852
853 /* Return function status */
854 return status;
855}
856
870HAL_StatusTypeDef HAL_TIMEx_OCN_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, const uint32_t *pData,
871 uint16_t Length)
872{
873 HAL_StatusTypeDef status = HAL_OK;
874 uint32_t tmpsmcr;
875
876 /* Check the parameters */
877 assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
878
879 /* Set the TIM complementary channel state */
881 {
882 return HAL_BUSY;
883 }
884 else if (TIM_CHANNEL_N_STATE_GET(htim, Channel) == HAL_TIM_CHANNEL_STATE_READY)
885 {
886 if ((pData == NULL) || (Length == 0U))
887 {
888 return HAL_ERROR;
889 }
890 else
891 {
893 }
894 }
895 else
896 {
897 return HAL_ERROR;
898 }
899
900 switch (Channel)
901 {
902 case TIM_CHANNEL_1:
903 {
904 /* Set the DMA compare callbacks */
907
908 /* Set the DMA error callback */
910
911 /* Enable the DMA stream */
912 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)pData, (uint32_t)&htim->Instance->CCR1,
913 Length) != HAL_OK)
914 {
915 /* Return error status */
916 return HAL_ERROR;
917 }
918 /* Enable the TIM Output Compare DMA request */
920 break;
921 }
922
923 case TIM_CHANNEL_2:
924 {
925 /* Set the DMA compare callbacks */
928
929 /* Set the DMA error callback */
931
932 /* Enable the DMA stream */
933 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)pData, (uint32_t)&htim->Instance->CCR2,
934 Length) != HAL_OK)
935 {
936 /* Return error status */
937 return HAL_ERROR;
938 }
939 /* Enable the TIM Output Compare DMA request */
941 break;
942 }
943
944 case TIM_CHANNEL_3:
945 {
946 /* Set the DMA compare callbacks */
949
950 /* Set the DMA error callback */
952
953 /* Enable the DMA stream */
954 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)pData, (uint32_t)&htim->Instance->CCR3,
955 Length) != HAL_OK)
956 {
957 /* Return error status */
958 return HAL_ERROR;
959 }
960 /* Enable the TIM Output Compare DMA request */
962 break;
963 }
964
965 default:
966 status = HAL_ERROR;
967 break;
968 }
969
970 if (status == HAL_OK)
971 {
972 /* Enable the Capture compare channel N */
974
975 /* Enable the Main Output */
977
978 /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
979 if (IS_TIM_SLAVE_INSTANCE(htim->Instance))
980 {
981 tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
983 {
984 __HAL_TIM_ENABLE(htim);
985 }
986 }
987 else
988 {
989 __HAL_TIM_ENABLE(htim);
990 }
991 }
992
993 /* Return function status */
994 return status;
995}
996
1009{
1010 HAL_StatusTypeDef status = HAL_OK;
1011
1012 /* Check the parameters */
1013 assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
1014
1015 switch (Channel)
1016 {
1017 case TIM_CHANNEL_1:
1018 {
1019 /* Disable the TIM Output Compare DMA request */
1021 (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC1]);
1022 break;
1023 }
1024
1025 case TIM_CHANNEL_2:
1026 {
1027 /* Disable the TIM Output Compare DMA request */
1029 (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC2]);
1030 break;
1031 }
1032
1033 case TIM_CHANNEL_3:
1034 {
1035 /* Disable the TIM Output Compare DMA request */
1037 (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC3]);
1038 break;
1039 }
1040
1041 default:
1042 status = HAL_ERROR;
1043 break;
1044 }
1045
1046 if (status == HAL_OK)
1047 {
1048 /* Disable the Capture compare channel N */
1050
1051 /* Disable the Main Output */
1053
1054 /* Disable the Peripheral */
1055 __HAL_TIM_DISABLE(htim);
1056
1057 /* Set the TIM complementary channel state */
1059 }
1060
1061 /* Return function status */
1062 return status;
1063}
1064
1099{
1100 uint32_t tmpsmcr;
1101
1102 /* Check the parameters */
1103 assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
1104
1105 /* Check the TIM complementary channel state */
1107 {
1108 return HAL_ERROR;
1109 }
1110
1111 /* Set the TIM complementary channel state */
1113
1114 /* Enable the complementary PWM output */
1116
1117 /* Enable the Main Output */
1119
1120 /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
1121 if (IS_TIM_SLAVE_INSTANCE(htim->Instance))
1122 {
1123 tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
1125 {
1126 __HAL_TIM_ENABLE(htim);
1127 }
1128 }
1129 else
1130 {
1131 __HAL_TIM_ENABLE(htim);
1132 }
1133
1134 /* Return function status */
1135 return HAL_OK;
1136}
1137
1149{
1150 /* Check the parameters */
1151 assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
1152
1153 /* Disable the complementary PWM output */
1155
1156 /* Disable the Main Output */
1158
1159 /* Disable the Peripheral */
1160 __HAL_TIM_DISABLE(htim);
1161
1162 /* Set the TIM complementary channel state */
1164
1165 /* Return function status */
1166 return HAL_OK;
1167}
1168
1181{
1182 HAL_StatusTypeDef status = HAL_OK;
1183 uint32_t tmpsmcr;
1184
1185 /* Check the parameters */
1186 assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
1187
1188 /* Check the TIM complementary channel state */
1190 {
1191 return HAL_ERROR;
1192 }
1193
1194 /* Set the TIM complementary channel state */
1196
1197 switch (Channel)
1198 {
1199 case TIM_CHANNEL_1:
1200 {
1201 /* Enable the TIM Capture/Compare 1 interrupt */
1203 break;
1204 }
1205
1206 case TIM_CHANNEL_2:
1207 {
1208 /* Enable the TIM Capture/Compare 2 interrupt */
1210 break;
1211 }
1212
1213 case TIM_CHANNEL_3:
1214 {
1215 /* Enable the TIM Capture/Compare 3 interrupt */
1217 break;
1218 }
1219
1220 default:
1221 status = HAL_ERROR;
1222 break;
1223 }
1224
1225 if (status == HAL_OK)
1226 {
1227 /* Enable the TIM Break interrupt */
1229
1230 /* Enable the complementary PWM output */
1232
1233 /* Enable the Main Output */
1235
1236 /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
1237 if (IS_TIM_SLAVE_INSTANCE(htim->Instance))
1238 {
1239 tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
1241 {
1242 __HAL_TIM_ENABLE(htim);
1243 }
1244 }
1245 else
1246 {
1247 __HAL_TIM_ENABLE(htim);
1248 }
1249 }
1250
1251 /* Return function status */
1252 return status;
1253}
1254
1267{
1268 HAL_StatusTypeDef status = HAL_OK;
1269 uint32_t tmpccer;
1270
1271 /* Check the parameters */
1272 assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
1273
1274 switch (Channel)
1275 {
1276 case TIM_CHANNEL_1:
1277 {
1278 /* Disable the TIM Capture/Compare 1 interrupt */
1280 break;
1281 }
1282
1283 case TIM_CHANNEL_2:
1284 {
1285 /* Disable the TIM Capture/Compare 2 interrupt */
1287 break;
1288 }
1289
1290 case TIM_CHANNEL_3:
1291 {
1292 /* Disable the TIM Capture/Compare 3 interrupt */
1294 break;
1295 }
1296
1297 default:
1298 status = HAL_ERROR;
1299 break;
1300 }
1301
1302 if (status == HAL_OK)
1303 {
1304 /* Disable the complementary PWM output */
1306
1307 /* Disable the TIM Break interrupt (only if no more channel is active) */
1308 tmpccer = htim->Instance->CCER;
1309 if ((tmpccer & TIM_CCER_CCxNE_MASK) == (uint32_t)RESET)
1310 {
1312 }
1313
1314 /* Disable the Main Output */
1316
1317 /* Disable the Peripheral */
1318 __HAL_TIM_DISABLE(htim);
1319
1320 /* Set the TIM complementary channel state */
1322 }
1323
1324 /* Return function status */
1325 return status;
1326}
1327
1341HAL_StatusTypeDef HAL_TIMEx_PWMN_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, const uint32_t *pData,
1342 uint16_t Length)
1343{
1344 HAL_StatusTypeDef status = HAL_OK;
1345 uint32_t tmpsmcr;
1346
1347 /* Check the parameters */
1348 assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
1349
1350 /* Set the TIM complementary channel state */
1352 {
1353 return HAL_BUSY;
1354 }
1355 else if (TIM_CHANNEL_N_STATE_GET(htim, Channel) == HAL_TIM_CHANNEL_STATE_READY)
1356 {
1357 if ((pData == NULL) || (Length == 0U))
1358 {
1359 return HAL_ERROR;
1360 }
1361 else
1362 {
1364 }
1365 }
1366 else
1367 {
1368 return HAL_ERROR;
1369 }
1370
1371 switch (Channel)
1372 {
1373 case TIM_CHANNEL_1:
1374 {
1375 /* Set the DMA compare callbacks */
1378
1379 /* Set the DMA error callback */
1381
1382 /* Enable the DMA stream */
1383 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)pData, (uint32_t)&htim->Instance->CCR1,
1384 Length) != HAL_OK)
1385 {
1386 /* Return error status */
1387 return HAL_ERROR;
1388 }
1389 /* Enable the TIM Capture/Compare 1 DMA request */
1391 break;
1392 }
1393
1394 case TIM_CHANNEL_2:
1395 {
1396 /* Set the DMA compare callbacks */
1399
1400 /* Set the DMA error callback */
1402
1403 /* Enable the DMA stream */
1404 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)pData, (uint32_t)&htim->Instance->CCR2,
1405 Length) != HAL_OK)
1406 {
1407 /* Return error status */
1408 return HAL_ERROR;
1409 }
1410 /* Enable the TIM Capture/Compare 2 DMA request */
1412 break;
1413 }
1414
1415 case TIM_CHANNEL_3:
1416 {
1417 /* Set the DMA compare callbacks */
1420
1421 /* Set the DMA error callback */
1423
1424 /* Enable the DMA stream */
1425 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)pData, (uint32_t)&htim->Instance->CCR3,
1426 Length) != HAL_OK)
1427 {
1428 /* Return error status */
1429 return HAL_ERROR;
1430 }
1431 /* Enable the TIM Capture/Compare 3 DMA request */
1433 break;
1434 }
1435
1436 default:
1437 status = HAL_ERROR;
1438 break;
1439 }
1440
1441 if (status == HAL_OK)
1442 {
1443 /* Enable the complementary PWM output */
1445
1446 /* Enable the Main Output */
1448
1449 /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
1450 if (IS_TIM_SLAVE_INSTANCE(htim->Instance))
1451 {
1452 tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
1454 {
1455 __HAL_TIM_ENABLE(htim);
1456 }
1457 }
1458 else
1459 {
1460 __HAL_TIM_ENABLE(htim);
1461 }
1462 }
1463
1464 /* Return function status */
1465 return status;
1466}
1467
1480{
1481 HAL_StatusTypeDef status = HAL_OK;
1482
1483 /* Check the parameters */
1484 assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
1485
1486 switch (Channel)
1487 {
1488 case TIM_CHANNEL_1:
1489 {
1490 /* Disable the TIM Capture/Compare 1 DMA request */
1492 (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC1]);
1493 break;
1494 }
1495
1496 case TIM_CHANNEL_2:
1497 {
1498 /* Disable the TIM Capture/Compare 2 DMA request */
1500 (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC2]);
1501 break;
1502 }
1503
1504 case TIM_CHANNEL_3:
1505 {
1506 /* Disable the TIM Capture/Compare 3 DMA request */
1508 (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC3]);
1509 break;
1510 }
1511
1512 default:
1513 status = HAL_ERROR;
1514 break;
1515 }
1516
1517 if (status == HAL_OK)
1518 {
1519 /* Disable the complementary PWM output */
1521
1522 /* Disable the Main Output */
1524
1525 /* Disable the Peripheral */
1526 __HAL_TIM_DISABLE(htim);
1527
1528 /* Set the TIM complementary channel state */
1530 }
1531
1532 /* Return function status */
1533 return status;
1534}
1535
1571{
1572 uint32_t input_channel = (OutputChannel == TIM_CHANNEL_1) ? TIM_CHANNEL_2 : TIM_CHANNEL_1;
1575 HAL_TIM_ChannelStateTypeDef complementary_channel_1_state = TIM_CHANNEL_N_STATE_GET(htim, TIM_CHANNEL_1);
1576 HAL_TIM_ChannelStateTypeDef complementary_channel_2_state = TIM_CHANNEL_N_STATE_GET(htim, TIM_CHANNEL_2);
1577
1578 /* Check the parameters */
1579 assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, OutputChannel));
1580
1581 /* Check the TIM channels state */
1582 if ((channel_1_state != HAL_TIM_CHANNEL_STATE_READY)
1583 || (channel_2_state != HAL_TIM_CHANNEL_STATE_READY)
1584 || (complementary_channel_1_state != HAL_TIM_CHANNEL_STATE_READY)
1585 || (complementary_channel_2_state != HAL_TIM_CHANNEL_STATE_READY))
1586 {
1587 return HAL_ERROR;
1588 }
1589
1590 /* Set the TIM channels state */
1595
1596 /* Enable the complementary One Pulse output channel and the Input Capture channel */
1597 TIM_CCxNChannelCmd(htim->Instance, OutputChannel, TIM_CCxN_ENABLE);
1598 TIM_CCxChannelCmd(htim->Instance, input_channel, TIM_CCx_ENABLE);
1599
1600 /* Enable the Main Output */
1602
1603 /* Return function status */
1604 return HAL_OK;
1605}
1606
1620{
1621 uint32_t input_channel = (OutputChannel == TIM_CHANNEL_1) ? TIM_CHANNEL_2 : TIM_CHANNEL_1;
1622
1623 /* Check the parameters */
1624 assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, OutputChannel));
1625
1626 /* Disable the complementary One Pulse output channel and the Input Capture channel */
1627 TIM_CCxNChannelCmd(htim->Instance, OutputChannel, TIM_CCxN_DISABLE);
1628 TIM_CCxChannelCmd(htim->Instance, input_channel, TIM_CCx_DISABLE);
1629
1630 /* Disable the Main Output */
1632
1633 /* Disable the Peripheral */
1634 __HAL_TIM_DISABLE(htim);
1635
1636 /* Set the TIM channels state */
1641
1642 /* Return function status */
1643 return HAL_OK;
1644}
1645
1659{
1660 uint32_t input_channel = (OutputChannel == TIM_CHANNEL_1) ? TIM_CHANNEL_2 : TIM_CHANNEL_1;
1663 HAL_TIM_ChannelStateTypeDef complementary_channel_1_state = TIM_CHANNEL_N_STATE_GET(htim, TIM_CHANNEL_1);
1664 HAL_TIM_ChannelStateTypeDef complementary_channel_2_state = TIM_CHANNEL_N_STATE_GET(htim, TIM_CHANNEL_2);
1665
1666 /* Check the parameters */
1667 assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, OutputChannel));
1668
1669 /* Check the TIM channels state */
1670 if ((channel_1_state != HAL_TIM_CHANNEL_STATE_READY)
1671 || (channel_2_state != HAL_TIM_CHANNEL_STATE_READY)
1672 || (complementary_channel_1_state != HAL_TIM_CHANNEL_STATE_READY)
1673 || (complementary_channel_2_state != HAL_TIM_CHANNEL_STATE_READY))
1674 {
1675 return HAL_ERROR;
1676 }
1677
1678 /* Set the TIM channels state */
1683
1684 /* Enable the TIM Capture/Compare 1 interrupt */
1686
1687 /* Enable the TIM Capture/Compare 2 interrupt */
1689
1690 /* Enable the complementary One Pulse output channel and the Input Capture channel */
1691 TIM_CCxNChannelCmd(htim->Instance, OutputChannel, TIM_CCxN_ENABLE);
1692 TIM_CCxChannelCmd(htim->Instance, input_channel, TIM_CCx_ENABLE);
1693
1694 /* Enable the Main Output */
1696
1697 /* Return function status */
1698 return HAL_OK;
1699}
1700
1714{
1715 uint32_t input_channel = (OutputChannel == TIM_CHANNEL_1) ? TIM_CHANNEL_2 : TIM_CHANNEL_1;
1716
1717 /* Check the parameters */
1718 assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, OutputChannel));
1719
1720 /* Disable the TIM Capture/Compare 1 interrupt */
1722
1723 /* Disable the TIM Capture/Compare 2 interrupt */
1725
1726 /* Disable the complementary One Pulse output channel and the Input Capture channel */
1727 TIM_CCxNChannelCmd(htim->Instance, OutputChannel, TIM_CCxN_DISABLE);
1728 TIM_CCxChannelCmd(htim->Instance, input_channel, TIM_CCx_DISABLE);
1729
1730 /* Disable the Main Output */
1732
1733 /* Disable the Peripheral */
1734 __HAL_TIM_DISABLE(htim);
1735
1736 /* Set the TIM channels state */
1741
1742 /* Return function status */
1743 return HAL_OK;
1744}
1745
1793 uint32_t CommutationSource)
1794{
1795 /* Check the parameters */
1796 assert_param(IS_TIM_COMMUTATION_EVENT_INSTANCE(htim->Instance));
1798
1799 __HAL_LOCK(htim);
1800
1801 if ((InputTrigger == TIM_TS_ITR0) || (InputTrigger == TIM_TS_ITR1) ||
1802 (InputTrigger == TIM_TS_ITR2) || (InputTrigger == TIM_TS_ITR3))
1803 {
1804 /* Select the Input trigger */
1805 htim->Instance->SMCR &= ~TIM_SMCR_TS;
1806 htim->Instance->SMCR |= InputTrigger;
1807 }
1808
1809 /* Select the Capture Compare preload feature */
1810 htim->Instance->CR2 |= TIM_CR2_CCPC;
1811 /* Select the Commutation event source */
1812 htim->Instance->CR2 &= ~TIM_CR2_CCUS;
1813 htim->Instance->CR2 |= CommutationSource;
1814
1815 /* Disable Commutation Interrupt */
1817
1818 /* Disable Commutation DMA request */
1820
1821 __HAL_UNLOCK(htim);
1822
1823 return HAL_OK;
1824}
1825
1849 uint32_t CommutationSource)
1850{
1851 /* Check the parameters */
1852 assert_param(IS_TIM_COMMUTATION_EVENT_INSTANCE(htim->Instance));
1854
1855 __HAL_LOCK(htim);
1856
1857 if ((InputTrigger == TIM_TS_ITR0) || (InputTrigger == TIM_TS_ITR1) ||
1858 (InputTrigger == TIM_TS_ITR2) || (InputTrigger == TIM_TS_ITR3))
1859 {
1860 /* Select the Input trigger */
1861 htim->Instance->SMCR &= ~TIM_SMCR_TS;
1862 htim->Instance->SMCR |= InputTrigger;
1863 }
1864
1865 /* Select the Capture Compare preload feature */
1866 htim->Instance->CR2 |= TIM_CR2_CCPC;
1867 /* Select the Commutation event source */
1868 htim->Instance->CR2 &= ~TIM_CR2_CCUS;
1869 htim->Instance->CR2 |= CommutationSource;
1870
1871 /* Disable Commutation DMA request */
1873
1874 /* Enable the Commutation Interrupt */
1876
1877 __HAL_UNLOCK(htim);
1878
1879 return HAL_OK;
1880}
1881
1906 uint32_t CommutationSource)
1907{
1908 /* Check the parameters */
1909 assert_param(IS_TIM_COMMUTATION_EVENT_INSTANCE(htim->Instance));
1911
1912 __HAL_LOCK(htim);
1913
1914 if ((InputTrigger == TIM_TS_ITR0) || (InputTrigger == TIM_TS_ITR1) ||
1915 (InputTrigger == TIM_TS_ITR2) || (InputTrigger == TIM_TS_ITR3))
1916 {
1917 /* Select the Input trigger */
1918 htim->Instance->SMCR &= ~TIM_SMCR_TS;
1919 htim->Instance->SMCR |= InputTrigger;
1920 }
1921
1922 /* Select the Capture Compare preload feature */
1923 htim->Instance->CR2 |= TIM_CR2_CCPC;
1924 /* Select the Commutation event source */
1925 htim->Instance->CR2 &= ~TIM_CR2_CCUS;
1926 htim->Instance->CR2 |= CommutationSource;
1927
1928 /* Enable the Commutation DMA Request */
1929 /* Set the DMA Commutation Callback */
1932 /* Set the DMA error callback */
1934
1935 /* Disable Commutation Interrupt */
1937
1938 /* Enable the Commutation DMA Request */
1940
1941 __HAL_UNLOCK(htim);
1942
1943 return HAL_OK;
1944}
1945
1955 const TIM_MasterConfigTypeDef *sMasterConfig)
1956{
1957 uint32_t tmpcr2;
1958 uint32_t tmpsmcr;
1959
1960 /* Check the parameters */
1961 assert_param(IS_TIM_MASTER_INSTANCE(htim->Instance));
1964
1965 /* Check input state */
1966 __HAL_LOCK(htim);
1967
1968 /* Change the handler state */
1969 htim->State = HAL_TIM_STATE_BUSY;
1970
1971 /* Get the TIMx CR2 register value */
1972 tmpcr2 = htim->Instance->CR2;
1973
1974 /* Get the TIMx SMCR register value */
1975 tmpsmcr = htim->Instance->SMCR;
1976
1977 /* Reset the MMS Bits */
1978 tmpcr2 &= ~TIM_CR2_MMS;
1979 /* Select the TRGO source */
1980 tmpcr2 |= sMasterConfig->MasterOutputTrigger;
1981
1982 /* Update TIMx CR2 */
1983 htim->Instance->CR2 = tmpcr2;
1984
1985 if (IS_TIM_SLAVE_INSTANCE(htim->Instance))
1986 {
1987 /* Reset the MSM Bit */
1988 tmpsmcr &= ~TIM_SMCR_MSM;
1989 /* Set master mode */
1990 tmpsmcr |= sMasterConfig->MasterSlaveMode;
1991
1992 /* Update TIMx SMCR */
1993 htim->Instance->SMCR = tmpsmcr;
1994 }
1995
1996 /* Change the htim state */
1997 htim->State = HAL_TIM_STATE_READY;
1998
1999 __HAL_UNLOCK(htim);
2000
2001 return HAL_OK;
2002}
2003
2016 const TIM_BreakDeadTimeConfigTypeDef *sBreakDeadTimeConfig)
2017{
2018 /* Keep this variable initialized to 0 as it is used to configure BDTR register */
2019 uint32_t tmpbdtr = 0U;
2020
2021 /* Check the parameters */
2022 assert_param(IS_TIM_BREAK_INSTANCE(htim->Instance));
2023 assert_param(IS_TIM_OSSR_STATE(sBreakDeadTimeConfig->OffStateRunMode));
2024 assert_param(IS_TIM_OSSI_STATE(sBreakDeadTimeConfig->OffStateIDLEMode));
2025 assert_param(IS_TIM_LOCK_LEVEL(sBreakDeadTimeConfig->LockLevel));
2026 assert_param(IS_TIM_DEADTIME(sBreakDeadTimeConfig->DeadTime));
2027 assert_param(IS_TIM_BREAK_STATE(sBreakDeadTimeConfig->BreakState));
2028 assert_param(IS_TIM_BREAK_POLARITY(sBreakDeadTimeConfig->BreakPolarity));
2030
2031 /* Check input state */
2032 __HAL_LOCK(htim);
2033
2034 /* Set the Lock level, the Break enable Bit and the Polarity, the OSSR State,
2035 the OSSI State, the dead time value and the Automatic Output Enable Bit */
2036
2037 /* Set the BDTR bits */
2038 MODIFY_REG(tmpbdtr, TIM_BDTR_DTG, sBreakDeadTimeConfig->DeadTime);
2039 MODIFY_REG(tmpbdtr, TIM_BDTR_LOCK, sBreakDeadTimeConfig->LockLevel);
2040 MODIFY_REG(tmpbdtr, TIM_BDTR_OSSI, sBreakDeadTimeConfig->OffStateIDLEMode);
2041 MODIFY_REG(tmpbdtr, TIM_BDTR_OSSR, sBreakDeadTimeConfig->OffStateRunMode);
2042 MODIFY_REG(tmpbdtr, TIM_BDTR_BKE, sBreakDeadTimeConfig->BreakState);
2043 MODIFY_REG(tmpbdtr, TIM_BDTR_BKP, sBreakDeadTimeConfig->BreakPolarity);
2044 MODIFY_REG(tmpbdtr, TIM_BDTR_AOE, sBreakDeadTimeConfig->AutomaticOutput);
2045
2046
2047 /* Set TIMx_BDTR */
2048 htim->Instance->BDTR = tmpbdtr;
2049
2050 __HAL_UNLOCK(htim);
2051
2052 return HAL_OK;
2053}
2054
2092{
2093 /* Check parameters */
2094 assert_param(IS_TIM_REMAP(htim->Instance, Remap));
2095
2096 __HAL_LOCK(htim);
2097
2098#if defined(LPTIM_OR_TIM1_ITR2_RMP) && defined(LPTIM_OR_TIM5_ITR1_RMP) && defined(LPTIM_OR_TIM9_ITR1_RMP)
2099 if ((Remap & LPTIM_REMAP_MASK) == LPTIM_REMAP_MASK)
2100 {
2101 /* Connect TIMx internal trigger to LPTIM1 output */
2102 __HAL_RCC_LPTIM1_CLK_ENABLE();
2103 MODIFY_REG(LPTIM1->OR,
2104 (LPTIM_OR_TIM1_ITR2_RMP | LPTIM_OR_TIM5_ITR1_RMP | LPTIM_OR_TIM9_ITR1_RMP),
2105 Remap & ~(LPTIM_REMAP_MASK));
2106 }
2107 else
2108 {
2109 /* Set the Timer remapping configuration */
2110 WRITE_REG(htim->Instance->OR, Remap);
2111 }
2112#else
2113 /* Set the Timer remapping configuration */
2114 WRITE_REG(htim->Instance->OR, Remap);
2115#endif /* LPTIM_OR_TIM1_ITR2_RMP && LPTIM_OR_TIM5_ITR1_RMP && LPTIM_OR_TIM9_ITR1_RMP */
2116
2117 __HAL_UNLOCK(htim);
2118
2119 return HAL_OK;
2120}
2121
2148{
2149 /* Prevent unused argument(s) compilation warning */
2150 UNUSED(htim);
2151
2152 /* NOTE : This function should not be modified, when the callback is needed,
2153 the HAL_TIMEx_CommutCallback could be implemented in the user file
2154 */
2155}
2162{
2163 /* Prevent unused argument(s) compilation warning */
2164 UNUSED(htim);
2165
2166 /* NOTE : This function should not be modified, when the callback is needed,
2167 the HAL_TIMEx_CommutHalfCpltCallback could be implemented in the user file
2168 */
2169}
2170
2177{
2178 /* Prevent unused argument(s) compilation warning */
2179 UNUSED(htim);
2180
2181 /* NOTE : This function should not be modified, when the callback is needed,
2182 the HAL_TIMEx_BreakCallback could be implemented in the user file
2183 */
2184}
2213
2225{
2226 HAL_TIM_ChannelStateTypeDef channel_state;
2227
2228 /* Check the parameters */
2229 assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, ChannelN));
2230
2231 channel_state = TIM_CHANNEL_N_STATE_GET(htim, ChannelN);
2232
2233 return channel_state;
2234}
2243/* Private functions ---------------------------------------------------------*/
2254{
2255 TIM_HandleTypeDef *htim = (TIM_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
2256
2257 /* Change the htim state */
2258 htim->State = HAL_TIM_STATE_READY;
2259
2260#if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
2261 htim->CommutationCallback(htim);
2262#else
2264#endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
2265}
2266
2273{
2274 TIM_HandleTypeDef *htim = (TIM_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
2275
2276 /* Change the htim state */
2277 htim->State = HAL_TIM_STATE_READY;
2278
2279#if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
2280 htim->CommutationHalfCpltCallback(htim);
2281#else
2283#endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
2284}
2285
2286
2293{
2294 TIM_HandleTypeDef *htim = (TIM_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
2295
2296 if (hdma == htim->hdma[TIM_DMA_ID_CC1])
2297 {
2299
2300 if (hdma->Init.Mode == DMA_NORMAL)
2301 {
2303 }
2304 }
2305 else if (hdma == htim->hdma[TIM_DMA_ID_CC2])
2306 {
2308
2309 if (hdma->Init.Mode == DMA_NORMAL)
2310 {
2312 }
2313 }
2314 else if (hdma == htim->hdma[TIM_DMA_ID_CC3])
2315 {
2317
2318 if (hdma->Init.Mode == DMA_NORMAL)
2319 {
2321 }
2322 }
2323 else
2324 {
2325 /* nothing to do */
2326 }
2327
2328#if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
2329 htim->PWM_PulseFinishedCallback(htim);
2330#else
2332#endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
2333
2335}
2336
2343{
2344 TIM_HandleTypeDef *htim = (TIM_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
2345
2346 if (hdma == htim->hdma[TIM_DMA_ID_CC1])
2347 {
2350 }
2351 else if (hdma == htim->hdma[TIM_DMA_ID_CC2])
2352 {
2355 }
2356 else if (hdma == htim->hdma[TIM_DMA_ID_CC3])
2357 {
2360 }
2361 else
2362 {
2363 /* nothing to do */
2364 }
2365
2366#if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
2367 htim->ErrorCallback(htim);
2368#else
2370#endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
2371
2373}
2374
2387static void TIM_CCxNChannelCmd(TIM_TypeDef *TIMx, uint32_t Channel, uint32_t ChannelNState)
2388{
2389 uint32_t tmp;
2390
2391 tmp = TIM_CCER_CC1NE << (Channel & 0xFU); /* 0xFU = 15 bits max shift */
2392
2393 /* Reset the CCxNE Bit */
2394 TIMx->CCER &= ~tmp;
2395
2396 /* Set or reset the CCxNE Bit */
2397 TIMx->CCER |= (uint32_t)(ChannelNState << (Channel & 0xFU)); /* 0xFU = 15 bits max shift */
2398}
2403#endif /* HAL_TIM_MODULE_ENABLED */
#define TIM_CCxN_DISABLE
#define TIM_CCx_DISABLE
#define TIM_CCxN_ENABLE
#define TIM_CCx_ENABLE
HAL_StatusTypeDef HAL_DMA_Abort_IT(DMA_HandleTypeDef *hdma)
Aborts the DMA Transfer in Interrupt mode.
HAL_StatusTypeDef HAL_DMA_Start_IT(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength)
Start the DMA Transfer with interrupt enabled.
#define TIM_DMA_ID_CC3
#define TIM_DMA_ID_CC1
#define TIM_DMA_ID_CC2
#define TIM_DMA_ID_COMMUTATION
#define DMA_NORMAL
HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start_DMA(TIM_HandleTypeDef *htim, uint32_t *pData, uint16_t Length)
Starts the TIM Hall Sensor Interface in DMA mode.
HAL_StatusTypeDef HAL_TIMEx_HallSensor_DeInit(TIM_HandleTypeDef *htim)
DeInitializes the TIM Hall Sensor interface.
HAL_StatusTypeDef HAL_TIMEx_HallSensor_Init(TIM_HandleTypeDef *htim, const TIM_HallSensor_InitTypeDef *sConfig)
Initializes the TIM Hall Sensor Interface and initialize the associated handle.
HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop(TIM_HandleTypeDef *htim)
Stops the TIM Hall sensor Interface.
HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start(TIM_HandleTypeDef *htim)
Starts the TIM Hall Sensor Interface.
void HAL_TIMEx_HallSensor_MspInit(TIM_HandleTypeDef *htim)
Initializes the TIM Hall Sensor MSP.
HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop_DMA(TIM_HandleTypeDef *htim)
Stops the TIM Hall Sensor Interface in DMA mode.
void HAL_TIMEx_HallSensor_MspDeInit(TIM_HandleTypeDef *htim)
DeInitializes TIM Hall Sensor MSP.
HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop_IT(TIM_HandleTypeDef *htim)
Stops the TIM Hall Sensor Interface in interrupt mode.
HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start_IT(TIM_HandleTypeDef *htim)
Starts the TIM Hall Sensor Interface in interrupt mode.
HAL_StatusTypeDef HAL_TIMEx_OCN_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel)
Stops the TIM Output Compare signal generation in DMA mode on the complementary output.
HAL_StatusTypeDef HAL_TIMEx_OCN_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
Starts the TIM Output Compare signal generation in interrupt mode on the complementary output.
HAL_StatusTypeDef HAL_TIMEx_OCN_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, const uint32_t *pData, uint16_t Length)
Starts the TIM Output Compare signal generation in DMA mode on the complementary output.
HAL_StatusTypeDef HAL_TIMEx_OCN_Start(TIM_HandleTypeDef *htim, uint32_t Channel)
Starts the TIM Output Compare signal generation on the complementary output.
HAL_StatusTypeDef HAL_TIMEx_OCN_Stop(TIM_HandleTypeDef *htim, uint32_t Channel)
Stops the TIM Output Compare signal generation on the complementary output.
HAL_StatusTypeDef HAL_TIMEx_OCN_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
Stops the TIM Output Compare signal generation in interrupt mode on the complementary output.
HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop(TIM_HandleTypeDef *htim, uint32_t Channel)
Stops the PWM signal generation on the complementary output.
HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel)
Stops the TIM PWM signal generation in DMA mode on the complementary output.
HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
Stops the PWM signal generation in interrupt mode on the complementary output.
HAL_StatusTypeDef HAL_TIMEx_PWMN_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, const uint32_t *pData, uint16_t Length)
Starts the TIM PWM signal generation in DMA mode on the complementary output.
HAL_StatusTypeDef HAL_TIMEx_PWMN_Start(TIM_HandleTypeDef *htim, uint32_t Channel)
Starts the PWM signal generation on the complementary output.
HAL_StatusTypeDef HAL_TIMEx_PWMN_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
Starts the PWM signal generation in interrupt mode on the complementary output.
HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Start_IT(TIM_HandleTypeDef *htim, uint32_t OutputChannel)
Starts the TIM One Pulse signal generation in interrupt mode on the complementary channel.
HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Start(TIM_HandleTypeDef *htim, uint32_t OutputChannel)
Starts the TIM One Pulse signal generation on the complementary output.
HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Stop_IT(TIM_HandleTypeDef *htim, uint32_t OutputChannel)
Stops the TIM One Pulse signal generation in interrupt mode on the complementary channel.
HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Stop(TIM_HandleTypeDef *htim, uint32_t OutputChannel)
Stops the TIM One Pulse signal generation on the complementary output.
HAL_StatusTypeDef HAL_TIMEx_ConfigBreakDeadTime(TIM_HandleTypeDef *htim, const TIM_BreakDeadTimeConfigTypeDef *sBreakDeadTimeConfig)
Configures the Break feature, dead time, Lock level, OSSI/OSSR State and the AOE(automatic output ena...
HAL_StatusTypeDef HAL_TIMEx_RemapConfig(TIM_HandleTypeDef *htim, uint32_t Remap)
Configures the TIMx Remapping input capabilities.
HAL_StatusTypeDef HAL_TIMEx_ConfigCommutEvent_DMA(TIM_HandleTypeDef *htim, uint32_t InputTrigger, uint32_t CommutationSource)
Configure the TIM commutation event sequence with DMA.
HAL_StatusTypeDef HAL_TIMEx_MasterConfigSynchronization(TIM_HandleTypeDef *htim, const TIM_MasterConfigTypeDef *sMasterConfig)
Configures the TIM in master mode.
HAL_StatusTypeDef HAL_TIMEx_ConfigCommutEvent(TIM_HandleTypeDef *htim, uint32_t InputTrigger, uint32_t CommutationSource)
Configure the TIM commutation event sequence.
HAL_StatusTypeDef HAL_TIMEx_ConfigCommutEvent_IT(TIM_HandleTypeDef *htim, uint32_t InputTrigger, uint32_t CommutationSource)
Configure the TIM commutation event sequence with interrupt.
void HAL_TIMEx_BreakCallback(TIM_HandleTypeDef *htim)
Break detection callback in non-blocking mode.
void HAL_TIMEx_CommutCallback(TIM_HandleTypeDef *htim)
Commutation callback in non-blocking mode.
void HAL_TIMEx_CommutHalfCpltCallback(TIM_HandleTypeDef *htim)
Commutation half complete callback in non-blocking mode.
HAL_TIM_ChannelStateTypeDef HAL_TIMEx_GetChannelNState(const TIM_HandleTypeDef *htim, uint32_t ChannelN)
Return actual state of the TIM complementary channel.
HAL_TIM_StateTypeDef HAL_TIMEx_HallSensor_GetState(const TIM_HandleTypeDef *htim)
Return the TIM Hall Sensor interface handle state.
void TIMEx_DMACommutationHalfCplt(DMA_HandleTypeDef *hdma)
TIM DMA Commutation half complete callback.
void TIMEx_DMACommutationCplt(DMA_HandleTypeDef *hdma)
TIM DMA Commutation callback.
#define IS_TIM_REMAP(INSTANCE, TIM_REMAP)
static void TIM_DMADelayPulseNCplt(DMA_HandleTypeDef *hdma)
TIM DMA Delay Pulse complete callback (complementary channel).
static void TIM_DMAErrorCCxN(DMA_HandleTypeDef *hdma)
TIM DMA error callback (complementary channel)
static void TIM_CCxNChannelCmd(TIM_TypeDef *TIMx, uint32_t Channel, uint32_t ChannelNState)
Enables or disables the TIM Capture Compare Channel xN.
#define TIM_CHANNEL_2
#define TIM_CHANNEL_3
#define TIM_CHANNEL_1
#define TIM_DMA_CC1
#define TIM_DMA_CC3
#define TIM_DMA_CC2
#define TIM_DMA_COM
void HAL_TIM_ErrorCallback(TIM_HandleTypeDef *htim)
Timer error callback in non-blocking mode.
void HAL_TIM_PWM_PulseFinishedCallback(TIM_HandleTypeDef *htim)
PWM Pulse finished callback in non-blocking mode.
#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_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_StateTypeDef
HAL State structures definition.
@ HAL_TIM_CHANNEL_STATE_READY
@ HAL_TIM_CHANNEL_STATE_RESET
@ HAL_TIM_CHANNEL_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_3
@ HAL_TIM_ACTIVE_CHANNEL_2
@ HAL_TIM_STATE_BUSY
@ HAL_TIM_STATE_RESET
@ HAL_TIM_STATE_READY
#define TIM_ICSELECTION_TRC
#define TIM_IT_CC1
#define TIM_IT_BREAK
#define TIM_IT_CC2
#define TIM_IT_CC3
#define TIM_IT_COM
#define TIM_TRGO_OC2REF
#define TIM_OCIDLESTATE_RESET
#define TIM_OCNIDLESTATE_RESET
#define TIM_OCNPOLARITY_HIGH
#define TIM_OCPOLARITY_HIGH
#define TIM_OCMODE_PWM2
#define TIM_OCFAST_DISABLE
#define TIM_CCER_CCxNE_MASK
void TIM_DMACaptureHalfCplt(DMA_HandleTypeDef *hdma)
TIM DMA Capture half complete callback.
void TIM_OC2_SetConfig(TIM_TypeDef *TIMx, const TIM_OC_InitTypeDef *OC_Config)
Timer Output Compare 2 configuration.
void TIM_DMACaptureCplt(DMA_HandleTypeDef *hdma)
TIM DMA Capture complete callback.
void TIM_CCxChannelCmd(TIM_TypeDef *TIMx, uint32_t Channel, uint32_t ChannelState)
Enables or disables the TIM Capture Compare Channel x.
void TIM_TI1_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection, uint32_t TIM_ICFilter)
Configure the TI1 as Input.
void TIM_DMADelayPulseHalfCplt(DMA_HandleTypeDef *hdma)
TIM DMA Delay Pulse half complete callback.
void TIM_DMAError(DMA_HandleTypeDef *hdma)
TIM DMA error callback.
void TIM_Base_SetConfig(TIM_TypeDef *TIMx, const TIM_Base_InitTypeDef *Structure)
Time Base configuration.
#define IS_TIM_DEADTIME(__DEADTIME__)
#define IS_TIM_IC_POLARITY(__POLARITY__)
#define IS_TIM_IC_FILTER(__ICFILTER__)
#define TIM_CHANNEL_N_STATE_GET(__HANDLE__, __CHANNEL__)
#define IS_TIM_BREAK_POLARITY(__POLARITY__)
#define IS_TIM_SLAVEMODE_TRIGGER_ENABLED(__TRIGGER__)
#define IS_TIM_INTERNAL_TRIGGEREVENT_SELECTION(__SELECTION__)
#define IS_TIM_COUNTER_MODE(__MODE__)
#define IS_TIM_BREAK_STATE(__STATE__)
#define IS_TIM_IC_PRESCALER(__PRESCALER__)
#define IS_TIM_OSSR_STATE(__STATE__)
#define TIM_CHANNEL_STATE_SET(__HANDLE__, __CHANNEL__, __CHANNEL_STATE__)
#define IS_TIM_TRGO_SOURCE(__SOURCE__)
#define IS_TIM_AUTOMATIC_OUTPUT_STATE(__STATE__)
#define IS_TIM_AUTORELOAD_PRELOAD(PRELOAD)
#define TIM_CHANNEL_N_STATE_SET(__HANDLE__, __CHANNEL__, __CHANNEL_STATE__)
#define IS_TIM_CLOCKDIVISION_DIV(__DIV__)
#define IS_TIM_LOCK_LEVEL(__LEVEL__)
#define TIM_CHANNEL_STATE_GET(__HANDLE__, __CHANNEL__)
#define IS_TIM_OSSI_STATE(__STATE__)
#define IS_TIM_PERIOD(__HANDLE__, __PERIOD__)
#define IS_TIM_MSM_STATE(__STATE__)
#define TIM_SLAVEMODE_RESET
#define TIM_TS_ITR3
#define TIM_TS_ITR2
#define TIM_TS_TI1F_ED
#define TIM_TS_ITR0
#define TIM_TS_ITR1
#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 UNUSED(X)
#define __HAL_UNLOCK(__HANDLE__)
@ HAL_UNLOCKED
#define __HAL_LOCK(__HANDLE__)
TIM Break input(s) and Dead time configuration Structure definition.
TIM Hall sensor Configuration Structure definition.
TIM Time Base Handle Structure definition.
DMA_HandleTypeDef * hdma[7]
HAL_LockTypeDef Lock
__IO HAL_TIM_StateTypeDef State
TIM_Base_InitTypeDef Init
__IO HAL_TIM_DMABurstStateTypeDef DMABurstState
HAL_TIM_ActiveChannel Channel
TIM Master configuration Structure definition.
TIM Output Compare Configuration Structure definition.
DMA handle Structure definition.
void(* XferCpltCallback)(struct __DMA_HandleTypeDef *hdma)
void(* XferErrorCallback)(struct __DMA_HandleTypeDef *hdma)
void(* XferHalfCpltCallback)(struct __DMA_HandleTypeDef *hdma)