STM32L4xx_HAL_Driver  1.14.0
Extended Timer Complementary PWM functions

Timer Complementary PWM functions. More...

Functions

HAL_StatusTypeDef HAL_TIMEx_PWMN_Start (TIM_HandleTypeDef *htim, uint32_t Channel)
 Starts the PWM signal generation on the complementary output. More...
 
HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop (TIM_HandleTypeDef *htim, uint32_t Channel)
 Stops the PWM signal generation on the complementary output. More...
 
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. More...
 
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. More...
 
HAL_StatusTypeDef HAL_TIMEx_PWMN_Start_DMA (TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length)
 Starts the TIM PWM signal generation in DMA mode on the complementary output. More...
 
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. More...
 

Detailed Description

Timer Complementary PWM functions.

  ==============================================================================
                 ##### Timer Complementary PWM functions #####
  ==============================================================================
  [..]
    This section provides functions allowing to:
    (+) Start the Complementary PWM.
    (+) Stop the Complementary PWM.
    (+) Start the Complementary PWM and enable interrupts.
    (+) Stop the Complementary PWM and disable interrupts.
    (+) Start the Complementary PWM and enable DMA transfers.
    (+) Stop the Complementary PWM and disable DMA transfers.
    (+) Start the Complementary Input Capture measurement.
    (+) Stop the Complementary Input Capture.
    (+) Start the Complementary Input Capture and enable interrupts.
    (+) Stop the Complementary Input Capture and disable interrupts.
    (+) Start the Complementary Input Capture and enable DMA transfers.
    (+) Stop the Complementary Input Capture and disable DMA transfers.
    (+) Start the Complementary One Pulse generation.
    (+) Stop the Complementary One Pulse.
    (+) Start the Complementary One Pulse and enable interrupts.
    (+) Stop the Complementary One Pulse and disable interrupts.

Function Documentation

◆ HAL_TIMEx_PWMN_Start()

HAL_StatusTypeDef HAL_TIMEx_PWMN_Start ( TIM_HandleTypeDef htim,
uint32_t  Channel 
)

Starts the PWM signal generation on the complementary output.

Parameters
htimTIM handle
ChannelTIM Channel to be enabled This parameter can be one of the following values:
  • TIM_CHANNEL_1: TIM Channel 1 selected
  • TIM_CHANNEL_2: TIM Channel 2 selected
  • TIM_CHANNEL_3: TIM Channel 3 selected
Return values
HALstatus

Definition at line 919 of file stm32l4xx_hal_tim_ex.c.

920 {
921  uint32_t tmpsmcr;
922 
923  /* Check the parameters */
924  assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
925 
926  /* Enable the complementary PWM output */
927  TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_ENABLE);
928 
929  /* Enable the Main Output */
930  __HAL_TIM_MOE_ENABLE(htim);
931 
932  /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
933  tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
934  if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr))
935  {
936  __HAL_TIM_ENABLE(htim);
937  }
938 
939  /* Return function status */
940  return HAL_OK;
941 }
return HAL_OK
static void TIM_CCxNChannelCmd(TIM_TypeDef *TIMx, uint32_t Channel, uint32_t ChannelNState)
Enables or disables the TIM Capture Compare Channel xN.
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))

◆ HAL_TIMEx_PWMN_Start_DMA()

HAL_StatusTypeDef HAL_TIMEx_PWMN_Start_DMA ( TIM_HandleTypeDef htim,
uint32_t  Channel,
uint32_t *  pData,
uint16_t  Length 
)

Starts the TIM PWM signal generation in DMA mode on the complementary output.

Parameters
htimTIM handle
ChannelTIM Channel to be enabled This parameter can be one of the following values:
  • TIM_CHANNEL_1: TIM Channel 1 selected
  • TIM_CHANNEL_2: TIM Channel 2 selected
  • TIM_CHANNEL_3: TIM Channel 3 selected
pDataThe source Buffer address.
LengthThe length of data to be transferred from memory to TIM peripheral
Return values
HALstatus

Definition at line 1114 of file stm32l4xx_hal_tim_ex.c.

1115 {
1116  uint32_t tmpsmcr;
1117 
1118  /* Check the parameters */
1119  assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
1120 
1121  if ((htim->State == HAL_TIM_STATE_BUSY))
1122  {
1123  return HAL_BUSY;
1124  }
1125  else if ((htim->State == HAL_TIM_STATE_READY))
1126  {
1127  if (((uint32_t)pData == 0U) && (Length > 0U))
1128  {
1129  return HAL_ERROR;
1130  }
1131  else
1132  {
1133  htim->State = HAL_TIM_STATE_BUSY;
1134  }
1135  }
1136  else
1137  {
1138  /* nothing to do */
1139  }
1140  switch (Channel)
1141  {
1142  case TIM_CHANNEL_1:
1143  {
1144  /* Set the DMA compare callbacks */
1145  htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMADelayPulseCplt;
1146  htim->hdma[TIM_DMA_ID_CC1]->XferHalfCpltCallback = TIM_DMADelayPulseHalfCplt;
1147 
1148  /* Set the DMA error callback */
1149  htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError ;
1150 
1151  /* Enable the DMA channel */
1152  if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)pData, (uint32_t)&htim->Instance->CCR1, Length) != HAL_OK)
1153  {
1154  return HAL_ERROR;
1155  }
1156  /* Enable the TIM Capture/Compare 1 DMA request */
1157  __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1);
1158  break;
1159  }
1160 
1161  case TIM_CHANNEL_2:
1162  {
1163  /* Set the DMA compare callbacks */
1164  htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = TIM_DMADelayPulseCplt;
1165  htim->hdma[TIM_DMA_ID_CC2]->XferHalfCpltCallback = TIM_DMADelayPulseHalfCplt;
1166 
1167  /* Set the DMA error callback */
1168  htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = TIM_DMAError ;
1169 
1170  /* Enable the DMA channel */
1171  if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)pData, (uint32_t)&htim->Instance->CCR2, Length) != HAL_OK)
1172  {
1173  return HAL_ERROR;
1174  }
1175  /* Enable the TIM Capture/Compare 2 DMA request */
1176  __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC2);
1177  break;
1178  }
1179 
1180  case TIM_CHANNEL_3:
1181  {
1182  /* Set the DMA compare callbacks */
1183  htim->hdma[TIM_DMA_ID_CC3]->XferCpltCallback = TIM_DMADelayPulseCplt;
1184  htim->hdma[TIM_DMA_ID_CC3]->XferHalfCpltCallback = TIM_DMADelayPulseHalfCplt;
1185 
1186  /* Set the DMA error callback */
1187  htim->hdma[TIM_DMA_ID_CC3]->XferErrorCallback = TIM_DMAError ;
1188 
1189  /* Enable the DMA channel */
1190  if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)pData, (uint32_t)&htim->Instance->CCR3, Length) != HAL_OK)
1191  {
1192  return HAL_ERROR;
1193  }
1194  /* Enable the TIM Capture/Compare 3 DMA request */
1195  __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC3);
1196  break;
1197  }
1198 
1199  default:
1200  break;
1201  }
1202 
1203  /* Enable the complementary PWM output */
1204  TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_ENABLE);
1205 
1206  /* Enable the Main Output */
1207  __HAL_TIM_MOE_ENABLE(htim);
1208 
1209  /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
1210  tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
1211  if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr))
1212  {
1213  __HAL_TIM_ENABLE(htim);
1214  }
1215 
1216  /* Return function status */
1217  return HAL_OK;
1218 }
void TIM_DMADelayPulseCplt(DMA_HandleTypeDef *hdma)
TIM DMA Delay Pulse complete callback.
void TIM_DMADelayPulseHalfCplt(DMA_HandleTypeDef *hdma)
TIM DMA Delay Pulse half complete callback.
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.
void TIM_DMAError(DMA_HandleTypeDef *hdma)
TIM DMA error callback.
return HAL_OK
static void TIM_CCxNChannelCmd(TIM_TypeDef *TIMx, uint32_t Channel, uint32_t ChannelNState)
Enables or disables the TIM Capture Compare Channel xN.
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))

◆ HAL_TIMEx_PWMN_Start_IT()

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.

Parameters
htimTIM handle
ChannelTIM Channel to be disabled This parameter can be one of the following values:
  • TIM_CHANNEL_1: TIM Channel 1 selected
  • TIM_CHANNEL_2: TIM Channel 2 selected
  • TIM_CHANNEL_3: TIM Channel 3 selected
Return values
HALstatus

Definition at line 982 of file stm32l4xx_hal_tim_ex.c.

983 {
984  uint32_t tmpsmcr;
985 
986  /* Check the parameters */
987  assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
988 
989  switch (Channel)
990  {
991  case TIM_CHANNEL_1:
992  {
993  /* Enable the TIM Capture/Compare 1 interrupt */
994  __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1);
995  break;
996  }
997 
998  case TIM_CHANNEL_2:
999  {
1000  /* Enable the TIM Capture/Compare 2 interrupt */
1001  __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2);
1002  break;
1003  }
1004 
1005  case TIM_CHANNEL_3:
1006  {
1007  /* Enable the TIM Capture/Compare 3 interrupt */
1008  __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC3);
1009  break;
1010  }
1011 
1012  default:
1013  break;
1014  }
1015 
1016  /* Enable the TIM Break interrupt */
1017  __HAL_TIM_ENABLE_IT(htim, TIM_IT_BREAK);
1018 
1019  /* Enable the complementary PWM output */
1020  TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_ENABLE);
1021 
1022  /* Enable the Main Output */
1023  __HAL_TIM_MOE_ENABLE(htim);
1024 
1025  /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
1026  tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
1027  if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr))
1028  {
1029  __HAL_TIM_ENABLE(htim);
1030  }
1031 
1032  /* Return function status */
1033  return HAL_OK;
1034 }
return HAL_OK
static void TIM_CCxNChannelCmd(TIM_TypeDef *TIMx, uint32_t Channel, uint32_t ChannelNState)
Enables or disables the TIM Capture Compare Channel xN.
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))

◆ HAL_TIMEx_PWMN_Stop()

HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop ( TIM_HandleTypeDef htim,
uint32_t  Channel 
)

Stops the PWM signal generation on the complementary output.

Parameters
htimTIM handle
ChannelTIM Channel to be disabled This parameter can be one of the following values:
  • TIM_CHANNEL_1: TIM Channel 1 selected
  • TIM_CHANNEL_2: TIM Channel 2 selected
  • TIM_CHANNEL_3: TIM Channel 3 selected
Return values
HALstatus

Definition at line 953 of file stm32l4xx_hal_tim_ex.c.

954 {
955  /* Check the parameters */
956  assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
957 
958  /* Disable the complementary PWM output */
959  TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_DISABLE);
960 
961  /* Disable the Main Output */
962  __HAL_TIM_MOE_DISABLE(htim);
963 
964  /* Disable the Peripheral */
965  __HAL_TIM_DISABLE(htim);
966 
967  /* Return function status */
968  return HAL_OK;
969 }
return HAL_OK
static void TIM_CCxNChannelCmd(TIM_TypeDef *TIMx, uint32_t Channel, uint32_t ChannelNState)
Enables or disables the TIM Capture Compare Channel xN.
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))

◆ HAL_TIMEx_PWMN_Stop_DMA()

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.

Parameters
htimTIM handle
ChannelTIM Channel to be disabled This parameter can be one of the following values:
  • TIM_CHANNEL_1: TIM Channel 1 selected
  • TIM_CHANNEL_2: TIM Channel 2 selected
  • TIM_CHANNEL_3: TIM Channel 3 selected
Return values
HALstatus

Definition at line 1231 of file stm32l4xx_hal_tim_ex.c.

1232 {
1233  /* Check the parameters */
1234  assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
1235 
1236  switch (Channel)
1237  {
1238  case TIM_CHANNEL_1:
1239  {
1240  /* Disable the TIM Capture/Compare 1 DMA request */
1241  __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1);
1242  (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC1]);
1243  break;
1244  }
1245 
1246  case TIM_CHANNEL_2:
1247  {
1248  /* Disable the TIM Capture/Compare 2 DMA request */
1249  __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC2);
1250  (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC2]);
1251  break;
1252  }
1253 
1254  case TIM_CHANNEL_3:
1255  {
1256  /* Disable the TIM Capture/Compare 3 DMA request */
1257  __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC3);
1258  (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC3]);
1259  break;
1260  }
1261 
1262  default:
1263  break;
1264  }
1265 
1266  /* Disable the complementary PWM output */
1267  TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_DISABLE);
1268 
1269  /* Disable the Main Output */
1270  __HAL_TIM_MOE_DISABLE(htim);
1271 
1272  /* Disable the Peripheral */
1273  __HAL_TIM_DISABLE(htim);
1274 
1275  /* Change the htim state */
1276  htim->State = HAL_TIM_STATE_READY;
1277 
1278  /* Return function status */
1279  return HAL_OK;
1280 }
HAL_StatusTypeDef HAL_DMA_Abort_IT(DMA_HandleTypeDef *hdma)
Aborts the DMA Transfer in Interrupt mode.
return HAL_OK
static void TIM_CCxNChannelCmd(TIM_TypeDef *TIMx, uint32_t Channel, uint32_t ChannelNState)
Enables or disables the TIM Capture Compare Channel xN.
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))

◆ HAL_TIMEx_PWMN_Stop_IT()

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.

Parameters
htimTIM handle
ChannelTIM Channel to be disabled This parameter can be one of the following values:
  • TIM_CHANNEL_1: TIM Channel 1 selected
  • TIM_CHANNEL_2: TIM Channel 2 selected
  • TIM_CHANNEL_3: TIM Channel 3 selected
Return values
HALstatus

Definition at line 1047 of file stm32l4xx_hal_tim_ex.c.

1048 {
1049  uint32_t tmpccer;
1050 
1051  /* Check the parameters */
1052  assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
1053 
1054  switch (Channel)
1055  {
1056  case TIM_CHANNEL_1:
1057  {
1058  /* Disable the TIM Capture/Compare 1 interrupt */
1059  __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1);
1060  break;
1061  }
1062 
1063  case TIM_CHANNEL_2:
1064  {
1065  /* Disable the TIM Capture/Compare 2 interrupt */
1066  __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2);
1067  break;
1068  }
1069 
1070  case TIM_CHANNEL_3:
1071  {
1072  /* Disable the TIM Capture/Compare 3 interrupt */
1073  __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC3);
1074  break;
1075  }
1076 
1077  default:
1078  break;
1079  }
1080 
1081  /* Disable the complementary PWM output */
1082  TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_DISABLE);
1083 
1084  /* Disable the TIM Break interrupt (only if no more channel is active) */
1085  tmpccer = htim->Instance->CCER;
1086  if ((tmpccer & (TIM_CCER_CC1NE | TIM_CCER_CC2NE | TIM_CCER_CC3NE)) == (uint32_t)RESET)
1087  {
1088  __HAL_TIM_DISABLE_IT(htim, TIM_IT_BREAK);
1089  }
1090 
1091  /* Disable the Main Output */
1092  __HAL_TIM_MOE_DISABLE(htim);
1093 
1094  /* Disable the Peripheral */
1095  __HAL_TIM_DISABLE(htim);
1096 
1097  /* Return function status */
1098  return HAL_OK;
1099 }
return HAL_OK
static void TIM_CCxNChannelCmd(TIM_TypeDef *TIMx, uint32_t Channel, uint32_t ChannelNState)
Enables or disables the TIM Capture Compare Channel xN.
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))