stm32l4xx_ll_swpmi.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /**
  2. ******************************************************************************
  3. * @file stm32l4xx_ll_swpmi.c
  4. * @author MCD Application Team
  5. * @brief SWPMI LL module driver.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
  10. *
  11. * Redistribution and use in source and binary forms, with or without modification,
  12. * are permitted provided that the following conditions are met:
  13. * 1. Redistributions of source code must retain the above copyright notice,
  14. * this list of conditions and the following disclaimer.
  15. * 2. Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  19. * may be used to endorse or promote products derived from this software
  20. * without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  23. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  25. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  26. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  27. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  28. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  29. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  30. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  31. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. *
  33. ******************************************************************************
  34. */
  35. #if defined(USE_FULL_LL_DRIVER)
  36. /* Includes ------------------------------------------------------------------*/
  37. #include "stm32l4xx_ll_swpmi.h"
  38. #include "stm32l4xx_ll_bus.h"
  39. #ifdef USE_FULL_ASSERT
  40. #include "stm32_assert.h"
  41. #else
  42. #define assert_param(expr) ((void)0U)
  43. #endif
  44. /** @addtogroup STM32L4xx_LL_Driver
  45. * @{
  46. */
  47. #if defined (SWPMI1)
  48. /** @addtogroup SWPMI_LL
  49. * @{
  50. */
  51. /* Private types -------------------------------------------------------------*/
  52. /* Private variables ---------------------------------------------------------*/
  53. /* Private constants ---------------------------------------------------------*/
  54. /* Private macros ------------------------------------------------------------*/
  55. /** @addtogroup SWPMI_LL_Private_Macros
  56. * @{
  57. */
  58. #define IS_LL_SWPMI_BITRATE_VALUE(__VALUE__) (((__VALUE__) <= 63))
  59. #define IS_LL_SWPMI_SW_BUFFER_RX(__VALUE__) (((__VALUE__) == LL_SWPMI_SW_BUFFER_RX_SINGLE) \
  60. || ((__VALUE__) == LL_SWPMI_SW_BUFFER_RX_MULTI))
  61. #define IS_LL_SWPMI_SW_BUFFER_TX(__VALUE__) (((__VALUE__) == LL_SWPMI_SW_BUFFER_TX_SINGLE) \
  62. || ((__VALUE__) == LL_SWPMI_SW_BUFFER_TX_MULTI))
  63. #define IS_LL_SWPMI_VOLTAGE_CLASS(__VALUE__) (((__VALUE__) == LL_SWPMI_VOLTAGE_CLASS_C) \
  64. || ((__VALUE__) == LL_SWPMI_VOLTAGE_CLASS_B))
  65. /**
  66. * @}
  67. */
  68. /* Private function prototypes -----------------------------------------------*/
  69. /* Exported functions --------------------------------------------------------*/
  70. /** @addtogroup SWPMI_LL_Exported_Functions
  71. * @{
  72. */
  73. /** @addtogroup SWPMI_LL_EF_Init
  74. * @{
  75. */
  76. /**
  77. * @brief De-initialize the SWPMI peripheral registers to their default reset values.
  78. * @param SWPMIx SWPMI Instance
  79. * @retval An ErrorStatus enumeration value
  80. * - SUCCESS: SWPMI registers are de-initialized
  81. * - ERROR: Not applicable
  82. */
  83. ErrorStatus LL_SWPMI_DeInit(SWPMI_TypeDef *SWPMIx)
  84. {
  85. /* Check the parameter */
  86. assert_param(IS_SWPMI_INSTANCE(SWPMIx));
  87. LL_APB1_GRP2_ForceReset(LL_APB1_GRP2_PERIPH_SWPMI1);
  88. LL_APB1_GRP2_ReleaseReset(LL_APB1_GRP2_PERIPH_SWPMI1);
  89. return SUCCESS;
  90. }
  91. /**
  92. * @brief Initialize the SWPMI peripheral according to the specified parameters in the SWPMI_InitStruct.
  93. * @note As some bits in SWPMI configuration registers can only be written when the SWPMI is deactivated (SWPMI_CR_SWPACT bit = 0),
  94. * SWPMI IP should be in deactivated state prior calling this function. Otherwise, ERROR result will be returned.
  95. * @param SWPMIx SWPMI Instance
  96. * @param SWPMI_InitStruct pointer to a @ref LL_SWPMI_InitTypeDef structure that contains
  97. * the configuration information for the SWPMI peripheral.
  98. * @retval An ErrorStatus enumeration value
  99. * - SUCCESS: SWPMI registers are initialized
  100. * - ERROR: SWPMI registers are not initialized
  101. */
  102. ErrorStatus LL_SWPMI_Init(SWPMI_TypeDef *SWPMIx, LL_SWPMI_InitTypeDef *SWPMI_InitStruct)
  103. {
  104. ErrorStatus status = SUCCESS;
  105. /* Check the parameters */
  106. assert_param(IS_SWPMI_INSTANCE(SWPMIx));
  107. assert_param(IS_LL_SWPMI_BITRATE_VALUE(SWPMI_InitStruct->BitRatePrescaler));
  108. assert_param(IS_LL_SWPMI_SW_BUFFER_TX(SWPMI_InitStruct->TxBufferingMode));
  109. assert_param(IS_LL_SWPMI_SW_BUFFER_RX(SWPMI_InitStruct->RxBufferingMode));
  110. assert_param(IS_LL_SWPMI_VOLTAGE_CLASS(SWPMI_InitStruct->VoltageClass));
  111. /* SWPMI needs to be in deactivated state, in order to be able to configure some bits */
  112. if (LL_SWPMI_IsActivated(SWPMIx) == 0)
  113. {
  114. /* Configure the BRR register (Bitrate) */
  115. LL_SWPMI_SetBitRatePrescaler(SWPMIx, SWPMI_InitStruct->BitRatePrescaler);
  116. /* Configure the voltage class */
  117. LL_SWPMI_SetVoltageClass(SWPMIx, SWPMI_InitStruct->VoltageClass);
  118. /* Set the new configuration of the SWPMI peripheral */
  119. MODIFY_REG(SWPMIx->CR,
  120. (SWPMI_CR_RXMODE | SWPMI_CR_TXMODE),
  121. (SWPMI_InitStruct->TxBufferingMode | SWPMI_InitStruct->RxBufferingMode));
  122. }
  123. /* Else (SWPMI not in deactivated state => return ERROR) */
  124. else
  125. {
  126. status = ERROR;
  127. }
  128. return status;
  129. }
  130. /**
  131. * @brief Set each @ref LL_SWPMI_InitTypeDef field to default value.
  132. * @param SWPMI_InitStruct pointer to a @ref LL_SWPMI_InitTypeDef structure that contains
  133. * the configuration information for the SWPMI peripheral.
  134. * @retval None
  135. */
  136. void LL_SWPMI_StructInit(LL_SWPMI_InitTypeDef *SWPMI_InitStruct)
  137. {
  138. /* Set SWPMI_InitStruct fields to default values */
  139. SWPMI_InitStruct->VoltageClass = LL_SWPMI_VOLTAGE_CLASS_C;
  140. SWPMI_InitStruct->BitRatePrescaler = (uint32_t)0x00000001;
  141. SWPMI_InitStruct->TxBufferingMode = LL_SWPMI_SW_BUFFER_TX_SINGLE;
  142. SWPMI_InitStruct->RxBufferingMode = LL_SWPMI_SW_BUFFER_RX_SINGLE;
  143. }
  144. /**
  145. * @}
  146. */
  147. /**
  148. * @}
  149. */
  150. /**
  151. * @}
  152. */
  153. #endif /* defined (SWPMI1) */
  154. /**
  155. * @}
  156. */
  157. #endif /* USE_FULL_LL_DRIVER */
  158. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/