stm32l4xx_ll_swpmi.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /**
  2. ******************************************************************************
  3. * @file stm32l4xx_ll_swpmi.c
  4. * @author MCD Application Team
  5. * @brief SWPMI LL module driver.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * Copyright (c) 2017 STMicroelectronics.
  10. * All rights reserved.
  11. *
  12. * This software is licensed under terms that can be found in the LICENSE file
  13. * in the root directory of this software component.
  14. * If no LICENSE file comes with this software, it is provided AS-IS.
  15. *
  16. ******************************************************************************
  17. */
  18. #if defined(USE_FULL_LL_DRIVER)
  19. /* Includes ------------------------------------------------------------------*/
  20. #include "stm32l4xx_ll_swpmi.h"
  21. #include "stm32l4xx_ll_bus.h"
  22. #ifdef USE_FULL_ASSERT
  23. #include "stm32_assert.h"
  24. #else
  25. #define assert_param(expr) ((void)0U)
  26. #endif
  27. /** @addtogroup STM32L4xx_LL_Driver
  28. * @{
  29. */
  30. #if defined(SWPMI1)
  31. /** @addtogroup SWPMI_LL
  32. * @{
  33. */
  34. /* Private types -------------------------------------------------------------*/
  35. /* Private variables ---------------------------------------------------------*/
  36. /* Private constants ---------------------------------------------------------*/
  37. /* Private macros ------------------------------------------------------------*/
  38. /** @addtogroup SWPMI_LL_Private_Macros
  39. * @{
  40. */
  41. #define IS_LL_SWPMI_BITRATE_VALUE(__VALUE__) (((__VALUE__) <= 63U))
  42. #define IS_LL_SWPMI_SW_BUFFER_RX(__VALUE__) (((__VALUE__) == LL_SWPMI_SW_BUFFER_RX_SINGLE) \
  43. || ((__VALUE__) == LL_SWPMI_SW_BUFFER_RX_MULTI))
  44. #define IS_LL_SWPMI_SW_BUFFER_TX(__VALUE__) (((__VALUE__) == LL_SWPMI_SW_BUFFER_TX_SINGLE) \
  45. || ((__VALUE__) == LL_SWPMI_SW_BUFFER_TX_MULTI))
  46. #define IS_LL_SWPMI_VOLTAGE_CLASS(__VALUE__) (((__VALUE__) == LL_SWPMI_VOLTAGE_CLASS_C) \
  47. || ((__VALUE__) == LL_SWPMI_VOLTAGE_CLASS_B))
  48. /**
  49. * @}
  50. */
  51. /* Private function prototypes -----------------------------------------------*/
  52. /* Exported functions --------------------------------------------------------*/
  53. /** @addtogroup SWPMI_LL_Exported_Functions
  54. * @{
  55. */
  56. /** @addtogroup SWPMI_LL_EF_Init
  57. * @{
  58. */
  59. /**
  60. * @brief De-initialize the SWPMI peripheral registers to their default reset values.
  61. * @param SWPMIx SWPMI Instance
  62. * @retval An ErrorStatus enumeration value
  63. * - SUCCESS: SWPMI registers are de-initialized
  64. * - ERROR: Not applicable
  65. */
  66. ErrorStatus LL_SWPMI_DeInit(const SWPMI_TypeDef *SWPMIx)
  67. {
  68. ErrorStatus status = SUCCESS;
  69. /* Check the parameter */
  70. assert_param(IS_SWPMI_INSTANCE(SWPMIx));
  71. if (SWPMIx == SWPMI1)
  72. {
  73. LL_APB1_GRP2_ForceReset(LL_APB1_GRP2_PERIPH_SWPMI1);
  74. LL_APB1_GRP2_ReleaseReset(LL_APB1_GRP2_PERIPH_SWPMI1);
  75. }
  76. else
  77. {
  78. status = ERROR;
  79. }
  80. return status;
  81. }
  82. /**
  83. * @brief Initialize the SWPMI peripheral according to the specified parameters in the SWPMI_InitStruct.
  84. * @note As some bits in SWPMI configuration registers can only be written when the SWPMI is deactivated
  85. * (SWPMI_CR_SWPACT bit = 0), the SWPMI peripheral should be in deactivated state prior calling
  86. * this function. Otherwise, ERROR result will be returned.
  87. * @param SWPMIx SWPMI Instance
  88. * @param SWPMI_InitStruct pointer to a @ref LL_SWPMI_InitTypeDef structure that contains
  89. * the configuration information for the SWPMI peripheral.
  90. * @retval An ErrorStatus enumeration value
  91. * - SUCCESS: SWPMI registers are initialized
  92. * - ERROR: SWPMI registers are not initialized
  93. */
  94. ErrorStatus LL_SWPMI_Init(SWPMI_TypeDef *SWPMIx, const LL_SWPMI_InitTypeDef *SWPMI_InitStruct)
  95. {
  96. ErrorStatus status = SUCCESS;
  97. /* Check the parameters */
  98. assert_param(IS_SWPMI_INSTANCE(SWPMIx));
  99. assert_param(IS_LL_SWPMI_BITRATE_VALUE(SWPMI_InitStruct->BitRatePrescaler));
  100. assert_param(IS_LL_SWPMI_SW_BUFFER_TX(SWPMI_InitStruct->TxBufferingMode));
  101. assert_param(IS_LL_SWPMI_SW_BUFFER_RX(SWPMI_InitStruct->RxBufferingMode));
  102. assert_param(IS_LL_SWPMI_VOLTAGE_CLASS(SWPMI_InitStruct->VoltageClass));
  103. /* SWPMI needs to be in deactivated state, in order to be able to configure some bits */
  104. if (LL_SWPMI_IsActivated(SWPMIx) == 0U)
  105. {
  106. /* Configure the BRR register (Bitrate) */
  107. LL_SWPMI_SetBitRatePrescaler(SWPMIx, SWPMI_InitStruct->BitRatePrescaler);
  108. /* Configure the voltage class */
  109. LL_SWPMI_SetVoltageClass(SWPMIx, SWPMI_InitStruct->VoltageClass);
  110. /* Set the new configuration of the SWPMI peripheral */
  111. MODIFY_REG(SWPMIx->CR,
  112. (SWPMI_CR_RXMODE | SWPMI_CR_TXMODE),
  113. (SWPMI_InitStruct->TxBufferingMode | SWPMI_InitStruct->RxBufferingMode));
  114. }
  115. /* Else (SWPMI not in deactivated state => return ERROR) */
  116. else
  117. {
  118. status = ERROR;
  119. }
  120. return status;
  121. }
  122. /**
  123. * @brief Set each @ref LL_SWPMI_InitTypeDef field to default value.
  124. * @param SWPMI_InitStruct pointer to a @ref LL_SWPMI_InitTypeDef structure that contains
  125. * the configuration information for the SWPMI peripheral.
  126. * @retval None
  127. */
  128. void LL_SWPMI_StructInit(LL_SWPMI_InitTypeDef *SWPMI_InitStruct)
  129. {
  130. /* Set SWPMI_InitStruct fields to default values */
  131. SWPMI_InitStruct->VoltageClass = LL_SWPMI_VOLTAGE_CLASS_C;
  132. SWPMI_InitStruct->BitRatePrescaler = (uint32_t)0x00000001;
  133. SWPMI_InitStruct->TxBufferingMode = LL_SWPMI_SW_BUFFER_TX_SINGLE;
  134. SWPMI_InitStruct->RxBufferingMode = LL_SWPMI_SW_BUFFER_RX_SINGLE;
  135. }
  136. /**
  137. * @}
  138. */
  139. /**
  140. * @}
  141. */
  142. /**
  143. * @}
  144. */
  145. #endif /* SWPMI1 */
  146. /**
  147. * @}
  148. */
  149. #endif /* USE_FULL_LL_DRIVER */