STM32L4xx_HAL_Driver  1.14.0

SWPMI Transmit/Receive functions. More...

Functions

HAL_StatusTypeDef HAL_SWPMI_Transmit (SWPMI_HandleTypeDef *hswpmi, uint32_t *pData, uint16_t Size, uint32_t Timeout)
 Transmit an amount of data in blocking mode. More...
 
HAL_StatusTypeDef HAL_SWPMI_Receive (SWPMI_HandleTypeDef *hswpmi, uint32_t *pData, uint16_t Size, uint32_t Timeout)
 Receive an amount of data in blocking mode. More...
 
HAL_StatusTypeDef HAL_SWPMI_Transmit_IT (SWPMI_HandleTypeDef *hswpmi, uint32_t *pData, uint16_t Size)
 Transmit an amount of data in non-blocking mode with interrupt. More...
 
HAL_StatusTypeDef HAL_SWPMI_Receive_IT (SWPMI_HandleTypeDef *hswpmi, uint32_t *pData, uint16_t Size)
 Receive an amount of data in non-blocking mode with interrupt. More...
 
HAL_StatusTypeDef HAL_SWPMI_Transmit_DMA (SWPMI_HandleTypeDef *hswpmi, uint32_t *pData, uint16_t Size)
 Transmit an amount of data in non-blocking mode with DMA interrupt. More...
 
HAL_StatusTypeDef HAL_SWPMI_Receive_DMA (SWPMI_HandleTypeDef *hswpmi, uint32_t *pData, uint16_t Size)
 Receive an amount of data in non-blocking mode with DMA interrupt. More...
 
HAL_StatusTypeDef HAL_SWPMI_DMAStop (SWPMI_HandleTypeDef *hswpmi)
 Stop all DMA transfers. More...
 
HAL_StatusTypeDef HAL_SWPMI_EnableLoopback (SWPMI_HandleTypeDef *hswpmi)
 Enable the Loopback mode. More...
 
HAL_StatusTypeDef HAL_SWPMI_DisableLoopback (SWPMI_HandleTypeDef *hswpmi)
 Disable the Loopback mode. More...
 

Detailed Description

SWPMI Transmit/Receive functions.

 ===============================================================================
                      ##### IO operation methods #####
 ===============================================================================
 [..]
    This subsection provides a set of functions allowing to manage the SWPMI
     data transfers.

    (#) There are two modes of transfer:
       (++) Blocking mode: The communication is performed in polling mode.
            The HAL status of all data processing is returned by the same function
            after finishing transfer.
       (++) Non-Blocking mode: The communication is performed using Interrupts
           or DMA. The end of the data processing will be indicated through the
           dedicated SWPMI Interrupt handler (HAL_SWPMI_IRQHandler()) when using Interrupt mode or
           the selected DMA channel interrupt handler when using DMA mode.
           The HAL_SWPMI_TxCpltCallback(), HAL_SWPMI_RxCpltCallback() user callbacks
           will be executed respectively at the end of the transmit or receive process.
           The HAL_SWPMI_ErrorCallback() user callback will be executed when a communication error is detected.

    (#) Blocking mode API's are:
        (++) HAL_SWPMI_Transmit()
        (++) HAL_SWPMI_Receive()

    (#) Non-Blocking mode API's with Interrupt are:
        (++) HAL_SWPMI_Transmit_IT()
        (++) HAL_SWPMI_Receive_IT()
        (++) HAL_SWPMI_IRQHandler()

    (#) Non-Blocking mode API's with DMA are:
        (++) HAL_SWPMI_Transmit_DMA()
        (++) HAL_SWPMI_Receive_DMA()
        (++) HAL_SWPMI_DMAPause()
        (++) HAL_SWPMI_DMAResume()
        (++) HAL_SWPMI_DMAStop()

    (#) A set of Transfer Complete Callbacks are provided in Non-Blocking mode:
        (++) HAL_SWPMI_TxHalfCpltCallback()
        (++) HAL_SWPMI_TxCpltCallback()
        (++) HAL_SWPMI_RxHalfCpltCallback()
        (++) HAL_SWPMI_RxCpltCallback()
        (++) HAL_SWPMI_ErrorCallback()

    (#) The capability to launch the above IO operations in loopback mode for
        user application verification:
        (++) HAL_SWPMI_EnableLoopback()
        (++) HAL_SWPMI_DisableLoopback()

Function Documentation

◆ HAL_SWPMI_DisableLoopback()

HAL_StatusTypeDef HAL_SWPMI_DisableLoopback ( SWPMI_HandleTypeDef hswpmi)

Disable the Loopback mode.

Parameters
hswpmiSWPMI handle
Note
Loopback mode is to be used only for test purposes
Return values
HAL_OK/ HAL_BUSY

Definition at line 1237 of file stm32l4xx_hal_swpmi.c.

1238 {
1239  HAL_StatusTypeDef status = HAL_OK;
1240 
1241  /* Process Locked */
1242  __HAL_LOCK(hswpmi);
1243 
1244  /* Make sure the SWPMI interface is not enabled to reset the loopback mode */
1245  CLEAR_BIT(hswpmi->Instance->CR, SWPMI_CR_SWPACT);
1246 
1247  /* Reset Loopback */
1248  CLEAR_BIT(hswpmi->Instance->CR, SWPMI_CR_LPBK);
1249 
1250  /* Re-enable SWPMI interface in normal mode */
1251  SET_BIT(hswpmi->Instance->CR, SWPMI_CR_SWPACT);
1252 
1253  /* Process Unlocked */
1254  __HAL_UNLOCK(hswpmi);
1255 
1256  return status;
1257 }
__HAL_UNLOCK(hrtc)
CLEAR_BIT(hrtc->Instance->CR, RTC_CR_WUTE)
__HAL_LOCK(hrtc)
return HAL_OK

◆ HAL_SWPMI_DMAStop()

HAL_StatusTypeDef HAL_SWPMI_DMAStop ( SWPMI_HandleTypeDef hswpmi)

Stop all DMA transfers.

Parameters
hswpmiSWPMI handle
Return values
HALstatus

Definition at line 1162 of file stm32l4xx_hal_swpmi.c.

1163 {
1164  HAL_StatusTypeDef status = HAL_OK;
1165 
1166  /* Process Locked */
1167  __HAL_LOCK(hswpmi);
1168 
1169  /* Disable the SWPMI Tx/Rx DMA requests */
1170  CLEAR_BIT(hswpmi->Instance->CR, (SWPMI_CR_TXDMA | SWPMI_CR_RXDMA));
1171 
1172  /* Abort the SWPMI DMA tx channel */
1173  if(hswpmi->hdmatx != NULL)
1174  {
1175  if(HAL_DMA_Abort(hswpmi->hdmatx) != HAL_OK)
1176  {
1177  hswpmi->ErrorCode |= HAL_SWPMI_ERROR_DMA;
1178  status = HAL_ERROR;
1179  }
1180  }
1181  /* Abort the SWPMI DMA rx channel */
1182  if(hswpmi->hdmarx != NULL)
1183  {
1184  if(HAL_DMA_Abort(hswpmi->hdmarx) != HAL_OK)
1185  {
1186  hswpmi->ErrorCode |= HAL_SWPMI_ERROR_DMA;
1187  status = HAL_ERROR;
1188  }
1189  }
1190 
1191  /* Disable SWPMI interface */
1192  CLEAR_BIT(hswpmi->Instance->CR, SWPMI_CR_SWPACT);
1193 
1194  hswpmi->State = HAL_SWPMI_STATE_READY;
1195 
1196  /* Process Unlocked */
1197  __HAL_UNLOCK(hswpmi);
1198 
1199  return status;
1200 }
__HAL_UNLOCK(hrtc)
CLEAR_BIT(hrtc->Instance->CR, RTC_CR_WUTE)
__HAL_LOCK(hrtc)
return HAL_OK
HAL_StatusTypeDef HAL_DMA_Abort(DMA_HandleTypeDef *hdma)
Abort the DMA Transfer.

◆ HAL_SWPMI_EnableLoopback()

HAL_StatusTypeDef HAL_SWPMI_EnableLoopback ( SWPMI_HandleTypeDef hswpmi)

Enable the Loopback mode.

Parameters
hswpmiSWPMI handle
Note
Loopback mode is to be used only for test purposes
Return values
HAL_OK/ HAL_BUSY

Definition at line 1209 of file stm32l4xx_hal_swpmi.c.

1210 {
1211  HAL_StatusTypeDef status = HAL_OK;
1212 
1213  /* Process Locked */
1214  __HAL_LOCK(hswpmi);
1215 
1216  /* Make sure the SWPMI interface is not enabled to set the loopback mode */
1217  CLEAR_BIT(hswpmi->Instance->CR, SWPMI_CR_SWPACT);
1218 
1219  /* Set Loopback */
1220  SET_BIT(hswpmi->Instance->CR, SWPMI_CR_LPBK);
1221 
1222  /* Enable SWPMI interface in loopback mode */
1223  SET_BIT(hswpmi->Instance->CR, SWPMI_CR_SWPACT);
1224 
1225  /* Process Unlocked */
1226  __HAL_UNLOCK(hswpmi);
1227 
1228  return status;
1229 }
__HAL_UNLOCK(hrtc)
CLEAR_BIT(hrtc->Instance->CR, RTC_CR_WUTE)
__HAL_LOCK(hrtc)
return HAL_OK

◆ HAL_SWPMI_Receive()

HAL_StatusTypeDef HAL_SWPMI_Receive ( SWPMI_HandleTypeDef hswpmi,
uint32_t *  pData,
uint16_t  Size,
uint32_t  Timeout 
)

Receive an amount of data in blocking mode.

Parameters
hswpmipointer to a SWPMI_HandleTypeDef structure that contains the configuration information for SWPMI module.
pDataPointer to data buffer
SizeAmount of data to be received
TimeoutTimeout duration
Return values
HALstatus

Definition at line 757 of file stm32l4xx_hal_swpmi.c.

758 {
759  uint32_t tickstart = HAL_GetTick();
760  HAL_StatusTypeDef status = HAL_OK;
761  HAL_SWPMI_StateTypeDef tmp_state;
762  uint32_t *ptmp_data;
763  uint32_t tmp_size;
764 
765  if((pData == NULL ) || (Size == 0U))
766  {
767  status = HAL_ERROR;
768  }
769  else
770  {
771  /* Process Locked */
772  __HAL_LOCK(hswpmi);
773 
774  tmp_state = hswpmi->State;
775  if((tmp_state == HAL_SWPMI_STATE_READY) || (tmp_state == HAL_SWPMI_STATE_BUSY_TX))
776  {
777  /* Check if a non-blocking transmit process is ongoing or not */
778  if(tmp_state == HAL_SWPMI_STATE_READY)
779  {
780  hswpmi->State = HAL_SWPMI_STATE_BUSY_RX;
781 
782  /* Disable any receiver interrupts */
783  CLEAR_BIT(hswpmi->Instance->IER, SWPMI_IT_SRIE | SWPMI_IT_RIE | SWPMI_IT_RXBERIE | SWPMI_IT_RXOVRIE | SWPMI_IT_RXBFIE);
784 
785  /* Enable SWPMI peripheral if not */
786  SET_BIT(hswpmi->Instance->CR, SWPMI_CR_SWPACT);
787  }
788  else
789  {
790  hswpmi->State = HAL_SWPMI_STATE_BUSY_TX_RX;
791  }
792 
793  ptmp_data = pData;
794  tmp_size = Size;
795  do
796  {
797  /* Wait the RXNE to read data */
798  if(HAL_IS_BIT_SET(hswpmi->Instance->ISR, SWPMI_FLAG_RXNE))
799  {
800  *ptmp_data = hswpmi->Instance->RDR;
801  ptmp_data++;
802  tmp_size--;
803  }
804  else
805  {
806  /* Check for the Timeout */
807  if(Timeout != HAL_MAX_DELAY)
808  {
809  if(((HAL_GetTick() - tickstart) > Timeout) || (Timeout == 0U))
810  {
811  status = HAL_TIMEOUT;
812  break;
813  }
814  }
815  }
816  } while(tmp_size != 0U);
817 
818  if(status == HAL_OK)
819  {
820  if(HAL_IS_BIT_SET(hswpmi->Instance->ISR, SWPMI_FLAG_RXBFF))
821  {
822  /* Clear RXBFF at end of reception */
823  WRITE_REG(hswpmi->Instance->ICR, SWPMI_FLAG_RXBFF);
824  }
825 
826  /* Check if a non-blocking transmit Process is ongoing or not */
827  if(hswpmi->State == HAL_SWPMI_STATE_BUSY_TX_RX)
828  {
829  hswpmi->State = HAL_SWPMI_STATE_BUSY_TX;
830  }
831  else
832  {
833  hswpmi->State = HAL_SWPMI_STATE_READY;
834  }
835  }
836  }
837  else
838  {
839  status = HAL_BUSY;
840  }
841  }
842 
843  if((status != HAL_OK) && (status != HAL_BUSY))
844  {
845  hswpmi->State = HAL_SWPMI_STATE_READY;
846  }
847  /* Process Unlocked */
848  __HAL_UNLOCK(hswpmi);
849 
850  return status;
851 }
uint32_t HAL_GetTick(void)
Provide a tick value in millisecond.
__HAL_UNLOCK(hrtc)
CLEAR_BIT(hrtc->Instance->CR, RTC_CR_WUTE)
__HAL_LOCK(hrtc)
return HAL_OK
HAL_SWPMI_StateTypeDef
HAL SWPMI State structures definition.

◆ HAL_SWPMI_Receive_DMA()

HAL_StatusTypeDef HAL_SWPMI_Receive_DMA ( SWPMI_HandleTypeDef hswpmi,
uint32_t *  pData,
uint16_t  Size 
)

Receive an amount of data in non-blocking mode with DMA interrupt.

Parameters
hswpmiSWPMI handle
pDataPointer to data buffer
SizeAmount of data to be received
Return values
HALstatus

Definition at line 1078 of file stm32l4xx_hal_swpmi.c.

1079 {
1080  HAL_StatusTypeDef status = HAL_OK;
1081  HAL_SWPMI_StateTypeDef tmp_state;
1082 
1083  if((pData == NULL ) || (Size == 0U))
1084  {
1085  status = HAL_ERROR;
1086  }
1087  else
1088  {
1089  /* Process Locked */
1090  __HAL_LOCK(hswpmi);
1091 
1092  tmp_state = hswpmi->State;
1093  if((tmp_state == HAL_SWPMI_STATE_READY) || (tmp_state == HAL_SWPMI_STATE_BUSY_TX))
1094  {
1095  /* Update handle */
1096  hswpmi->pRxBuffPtr = pData;
1097  hswpmi->RxXferSize = Size;
1098  hswpmi->ErrorCode = HAL_SWPMI_ERROR_NONE;
1099 
1100  /* Check if a transmit process is ongoing or not */
1101  if(tmp_state == HAL_SWPMI_STATE_READY)
1102  {
1103  hswpmi->State = HAL_SWPMI_STATE_BUSY_RX;
1104 
1105  /* Enable SWPMI peripheral if not */
1106  SET_BIT(hswpmi->Instance->CR, SWPMI_CR_SWPACT);
1107  }
1108  else
1109  {
1110  hswpmi->State = HAL_SWPMI_STATE_BUSY_TX_RX;
1111  }
1112 
1113  /* Set the SWPMI DMA transfer complete callback */
1114  hswpmi->hdmarx->XferCpltCallback = SWPMI_DMAReceiveCplt;
1115 
1116  /* Set the SWPMI DMA Half transfer complete callback */
1117  hswpmi->hdmarx->XferHalfCpltCallback = SWPMI_DMARxHalfCplt;
1118 
1119  /* Set the DMA error callback */
1120  hswpmi->hdmarx->XferErrorCallback = SWPMI_DMAError;
1121 
1122  /* Enable the DMA request */
1123  if(HAL_DMA_Start_IT(hswpmi->hdmarx, (uint32_t)&hswpmi->Instance->RDR, (uint32_t)hswpmi->pRxBuffPtr, Size) != HAL_OK)
1124  {
1125  hswpmi->State = tmp_state; /* Back to previous state */
1126  hswpmi->ErrorCode = HAL_SWPMI_ERROR_DMA;
1127  status = HAL_ERROR;
1128 
1129  /* Process Unlocked */
1130  __HAL_UNLOCK(hswpmi);
1131  }
1132  else
1133  {
1134  /* Process Unlocked */
1135  __HAL_UNLOCK(hswpmi);
1136 
1137  /* Enable the SWPMI receive CRC Error and receive overrun interrupts */
1138  __HAL_SWPMI_ENABLE_IT(hswpmi, SWPMI_IT_RXBERIE | SWPMI_IT_RXOVRIE);
1139 
1140  /* Enable the DMA transfer for the receiver request by setting the RXDMA bit
1141  in the SWPMI CR register */
1142  SET_BIT(hswpmi->Instance->CR, SWPMI_CR_RXDMA);
1143  }
1144  }
1145  else
1146  {
1147  status = HAL_BUSY;
1148 
1149  /* Process Unlocked */
1150  __HAL_UNLOCK(hswpmi);
1151  }
1152  }
1153 
1154  return status;
1155 }
__HAL_UNLOCK(hrtc)
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.
__HAL_LOCK(hrtc)
static void SWPMI_DMAReceiveCplt(DMA_HandleTypeDef *hdma)
DMA SWPMI receive process complete callback.
return HAL_OK
static void SWPMI_DMAError(DMA_HandleTypeDef *hdma)
DMA SWPMI communication error callback.
static void SWPMI_DMARxHalfCplt(DMA_HandleTypeDef *hdma)
DMA SWPMI receive process half complete callback.
HAL_SWPMI_StateTypeDef
HAL SWPMI State structures definition.

◆ HAL_SWPMI_Receive_IT()

HAL_StatusTypeDef HAL_SWPMI_Receive_IT ( SWPMI_HandleTypeDef hswpmi,
uint32_t *  pData,
uint16_t  Size 
)

Receive an amount of data in non-blocking mode with interrupt.

Parameters
hswpmiSWPMI handle
pDataPointer to data buffer
SizeAmount of data to be received
Return values
HALstatus

Definition at line 928 of file stm32l4xx_hal_swpmi.c.

929 {
930  HAL_StatusTypeDef status = HAL_OK;
931  HAL_SWPMI_StateTypeDef tmp_state;
932 
933  if((pData == NULL ) || (Size == 0U))
934  {
935  status = HAL_ERROR;
936  }
937  else
938  {
939  /* Process Locked */
940  __HAL_LOCK(hswpmi);
941 
942  tmp_state = hswpmi->State;
943  if((tmp_state == HAL_SWPMI_STATE_READY) || (tmp_state == HAL_SWPMI_STATE_BUSY_TX))
944  {
945  /* Update handle */
946  hswpmi->pRxBuffPtr = pData;
947  hswpmi->RxXferSize = Size;
948  hswpmi->RxXferCount = Size;
949  hswpmi->ErrorCode = HAL_SWPMI_ERROR_NONE;
950 
951  /* Check if a transmit process is ongoing or not */
952  if(tmp_state == HAL_SWPMI_STATE_READY)
953  {
954  hswpmi->State = HAL_SWPMI_STATE_BUSY_RX;
955 
956  /* Enable SWPMI peripheral if not */
957  SET_BIT(hswpmi->Instance->CR, SWPMI_CR_SWPACT);
958  }
959  else
960  {
961  hswpmi->State = HAL_SWPMI_STATE_BUSY_TX_RX;
962  }
963 
964  /* Process Unlocked */
965  __HAL_UNLOCK(hswpmi);
966 
967  /* Enable the SWPMI slave resume */
968  /* Enable the SWPMI Data Register not empty Interrupt, receive CRC Error, receive overrun and RxBuf Interrupt */
969  /* Enable the SWPMI Transmit/Reception completion */
970  __HAL_SWPMI_ENABLE_IT(hswpmi, SWPMI_IT_RIE | SWPMI_IT_RXBERIE | SWPMI_IT_RXOVRIE | SWPMI_IT_RXBFIE);
971  }
972  else
973  {
974  status = HAL_BUSY;
975 
976  /* Process Unlocked */
977  __HAL_UNLOCK(hswpmi);
978  }
979  }
980 
981  return status;
982 }
__HAL_UNLOCK(hrtc)
__HAL_LOCK(hrtc)
return HAL_OK
HAL_SWPMI_StateTypeDef
HAL SWPMI State structures definition.

◆ HAL_SWPMI_Transmit()

HAL_StatusTypeDef HAL_SWPMI_Transmit ( SWPMI_HandleTypeDef hswpmi,
uint32_t *  pData,
uint16_t  Size,
uint32_t  Timeout 
)

Transmit an amount of data in blocking mode.

Parameters
hswpmipointer to a SWPMI_HandleTypeDef structure that contains the configuration information for SWPMI module.
pDataPointer to data buffer
SizeAmount of data to be sent
TimeoutTimeout duration
Return values
HALstatus

Definition at line 646 of file stm32l4xx_hal_swpmi.c.

647 {
648  uint32_t tickstart = HAL_GetTick();
649  HAL_StatusTypeDef status = HAL_OK;
650  HAL_SWPMI_StateTypeDef tmp_state;
651  uint32_t *ptmp_data;
652  uint32_t tmp_size;
653 
654  if((pData == NULL ) || (Size == 0U))
655  {
656  status = HAL_ERROR;
657  }
658  else
659  {
660  /* Process Locked */
661  __HAL_LOCK(hswpmi);
662 
663  tmp_state = hswpmi->State;
664  if((tmp_state == HAL_SWPMI_STATE_READY) || (tmp_state == HAL_SWPMI_STATE_BUSY_RX))
665  {
666  /* Check if a non-blocking receive process is ongoing or not */
667  if(tmp_state == HAL_SWPMI_STATE_READY)
668  {
669  hswpmi->State = HAL_SWPMI_STATE_BUSY_TX;
670 
671  /* Disable any transmitter interrupts */
672  __HAL_SWPMI_DISABLE_IT(hswpmi, SWPMI_IT_TCIE | SWPMI_IT_TIE | SWPMI_IT_TXUNRIE | SWPMI_IT_TXBEIE);
673 
674  /* Disable any transmitter flags */
675  __HAL_SWPMI_CLEAR_FLAG(hswpmi, SWPMI_FLAG_TXBEF | SWPMI_FLAG_TXUNRF | SWPMI_FLAG_TCF);
676 
677  /* Enable SWPMI peripheral if not */
678  SET_BIT(hswpmi->Instance->CR, SWPMI_CR_SWPACT);
679  }
680  else
681  {
682  hswpmi->State = HAL_SWPMI_STATE_BUSY_TX_RX;
683  }
684 
685  ptmp_data = pData;
686  tmp_size = Size;
687  do
688  {
689  /* Wait the TXE to write data */
690  if(HAL_IS_BIT_SET(hswpmi->Instance->ISR, SWPMI_FLAG_TXE))
691  {
692  hswpmi->Instance->TDR = *ptmp_data;
693  ptmp_data++;
694  tmp_size--;
695  }
696  else
697  {
698  /* Check for the Timeout */
699  if(Timeout != HAL_MAX_DELAY)
700  {
701  if(((HAL_GetTick() - tickstart) > Timeout) || (Timeout == 0U))
702  {
703  status = HAL_TIMEOUT;
704  break;
705  }
706  }
707  }
708  } while(tmp_size != 0U);
709 
710  /* Wait on TXBEF flag to be able to start a second transfer */
711  if(SWPMI_WaitOnFlagSetUntilTimeout(hswpmi, SWPMI_FLAG_TXBEF, tickstart, Timeout) != HAL_OK)
712  {
713  /* Timeout occurred */
714  hswpmi->ErrorCode |= HAL_SWPMI_ERROR_TXBEF_TIMEOUT;
715 
716  status = HAL_TIMEOUT;
717  }
718 
719  if(status == HAL_OK)
720  {
721  /* Check if a non-blocking receive Process is ongoing or not */
722  if(hswpmi->State == HAL_SWPMI_STATE_BUSY_TX_RX)
723  {
724  hswpmi->State = HAL_SWPMI_STATE_BUSY_RX;
725  }
726  else
727  {
728  hswpmi->State = HAL_SWPMI_STATE_READY;
729  }
730  }
731  }
732  else
733  {
734  status = HAL_BUSY;
735  }
736  }
737 
738  if((status != HAL_OK) && (status != HAL_BUSY))
739  {
740  hswpmi->State = HAL_SWPMI_STATE_READY;
741  }
742  /* Process Unlocked */
743  __HAL_UNLOCK(hswpmi);
744 
745  return status;
746 }
uint32_t HAL_GetTick(void)
Provide a tick value in millisecond.
__HAL_UNLOCK(hrtc)
__HAL_LOCK(hrtc)
return HAL_OK
HAL_SWPMI_StateTypeDef
HAL SWPMI State structures definition.
static HAL_StatusTypeDef SWPMI_WaitOnFlagSetUntilTimeout(SWPMI_HandleTypeDef *hswpmi, uint32_t Flag, uint32_t Tickstart, uint32_t Timeout)
Handle SWPMI Communication Timeout.

◆ HAL_SWPMI_Transmit_DMA()

HAL_StatusTypeDef HAL_SWPMI_Transmit_DMA ( SWPMI_HandleTypeDef hswpmi,
uint32_t *  pData,
uint16_t  Size 
)

Transmit an amount of data in non-blocking mode with DMA interrupt.

Parameters
hswpmiSWPMI handle
pDataPointer to data buffer
SizeAmount of data to be sent
Return values
HALstatus

Definition at line 991 of file stm32l4xx_hal_swpmi.c.

992 {
993  HAL_StatusTypeDef status = HAL_OK;
994  HAL_SWPMI_StateTypeDef tmp_state;
995 
996  if((pData == NULL ) || (Size == 0U))
997  {
998  status = HAL_ERROR;
999  }
1000  else
1001  {
1002  /* Process Locked */
1003  __HAL_LOCK(hswpmi);
1004 
1005  tmp_state = hswpmi->State;
1006  if((tmp_state == HAL_SWPMI_STATE_READY) || (tmp_state == HAL_SWPMI_STATE_BUSY_RX))
1007  {
1008  /* Update handle */
1009  hswpmi->pTxBuffPtr = pData;
1010  hswpmi->TxXferSize = Size;
1011  hswpmi->TxXferCount = Size;
1012  hswpmi->ErrorCode = HAL_SWPMI_ERROR_NONE;
1013 
1014  /* Check if a receive process is ongoing or not */
1015  if(tmp_state == HAL_SWPMI_STATE_READY)
1016  {
1017  hswpmi->State = HAL_SWPMI_STATE_BUSY_TX;
1018 
1019  /* Enable SWPMI peripheral if not */
1020  SET_BIT(hswpmi->Instance->CR, SWPMI_CR_SWPACT);
1021  }
1022  else
1023  {
1024  hswpmi->State = HAL_SWPMI_STATE_BUSY_TX_RX;
1025  }
1026 
1027  /* Set the SWPMI DMA transfer complete callback */
1028  hswpmi->hdmatx->XferCpltCallback = SWPMI_DMATransmitCplt;
1029 
1030  /* Set the SWPMI DMA Half transfer complete callback */
1031  hswpmi->hdmatx->XferHalfCpltCallback = SWPMI_DMATxHalfCplt;
1032 
1033  /* Set the DMA error callback */
1034  hswpmi->hdmatx->XferErrorCallback = SWPMI_DMAError;
1035 
1036  /* Enable the SWPMI transmit DMA channel */
1037  if(HAL_DMA_Start_IT(hswpmi->hdmatx, (uint32_t)hswpmi->pTxBuffPtr, (uint32_t)&hswpmi->Instance->TDR, Size) != HAL_OK)
1038  {
1039  hswpmi->State = tmp_state; /* Back to previous state */
1040  hswpmi->ErrorCode = HAL_SWPMI_ERROR_DMA;
1041  status = HAL_ERROR;
1042 
1043  /* Process Unlocked */
1044  __HAL_UNLOCK(hswpmi);
1045  }
1046  else
1047  {
1048  /* Process Unlocked */
1049  __HAL_UNLOCK(hswpmi);
1050 
1051  /* Enable the SWPMI transmit underrun error */
1052  __HAL_SWPMI_ENABLE_IT(hswpmi, SWPMI_IT_TXUNRIE);
1053 
1054  /* Enable the DMA transfer for transmit request by setting the TXDMA bit
1055  in the SWPMI CR register */
1056  SET_BIT(hswpmi->Instance->CR, SWPMI_CR_TXDMA);
1057  }
1058  }
1059  else
1060  {
1061  status = HAL_BUSY;
1062 
1063  /* Process Unlocked */
1064  __HAL_UNLOCK(hswpmi);
1065  }
1066  }
1067 
1068  return status;
1069 }
__HAL_UNLOCK(hrtc)
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.
static void SWPMI_DMATransmitCplt(DMA_HandleTypeDef *hdma)
DMA SWPMI transmit process complete callback.
__HAL_LOCK(hrtc)
return HAL_OK
static void SWPMI_DMAError(DMA_HandleTypeDef *hdma)
DMA SWPMI communication error callback.
static void SWPMI_DMATxHalfCplt(DMA_HandleTypeDef *hdma)
DMA SWPMI transmit process half complete callback.
HAL_SWPMI_StateTypeDef
HAL SWPMI State structures definition.

◆ HAL_SWPMI_Transmit_IT()

HAL_StatusTypeDef HAL_SWPMI_Transmit_IT ( SWPMI_HandleTypeDef hswpmi,
uint32_t *  pData,
uint16_t  Size 
)

Transmit an amount of data in non-blocking mode with interrupt.

Parameters
hswpmipointer to a SWPMI_HandleTypeDef structure that contains the configuration information for SWPMI module.
pDataPointer to data buffer
SizeAmount of data to be sent
Return values
HALstatus

Definition at line 861 of file stm32l4xx_hal_swpmi.c.

862 {
863  HAL_StatusTypeDef status = HAL_OK;
864  HAL_SWPMI_StateTypeDef tmp_state;
865 
866  if((pData == NULL ) || (Size == 0U))
867  {
868  status = HAL_ERROR;
869  }
870  else
871  {
872  /* Process Locked */
873  __HAL_LOCK(hswpmi);
874 
875  tmp_state = hswpmi->State;
876  if((tmp_state == HAL_SWPMI_STATE_READY) || (tmp_state == HAL_SWPMI_STATE_BUSY_RX))
877  {
878  /* Update handle */
879  hswpmi->pTxBuffPtr = pData;
880  hswpmi->TxXferSize = Size;
881  hswpmi->TxXferCount = Size;
882  hswpmi->ErrorCode = HAL_SWPMI_ERROR_NONE;
883 
884  /* Check if a receive process is ongoing or not */
885  if(tmp_state == HAL_SWPMI_STATE_READY)
886  {
887  hswpmi->State = HAL_SWPMI_STATE_BUSY_TX;
888 
889  /* Enable SWPMI peripheral if not */
890  SET_BIT(hswpmi->Instance->CR, SWPMI_CR_SWPACT);
891  }
892  else
893  {
894  hswpmi->State = HAL_SWPMI_STATE_BUSY_TX_RX;
895  }
896 
897  /* Enable the SWPMI transmit underrun error */
898  __HAL_SWPMI_ENABLE_IT(hswpmi, SWPMI_IT_TXUNRIE);
899 
900  /* Process Unlocked */
901  __HAL_UNLOCK(hswpmi);
902 
903  /* Enable the SWPMI interrupts: */
904  /* - Transmit data register empty */
905  /* - Transmit buffer empty */
906  /* - Transmit/Reception completion */
907  __HAL_SWPMI_ENABLE_IT(hswpmi, SWPMI_IT_TIE | SWPMI_IT_TXBEIE | SWPMI_IT_TCIE);
908  }
909  else
910  {
911  status = HAL_BUSY;
912 
913  /* Process Unlocked */
914  __HAL_UNLOCK(hswpmi);
915  }
916  }
917 
918  return status;
919 }
__HAL_UNLOCK(hrtc)
__HAL_LOCK(hrtc)
return HAL_OK
HAL_SWPMI_StateTypeDef
HAL SWPMI State structures definition.