You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

180 lines
5.7 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32h7xx_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.
  10. * All rights reserved.</center></h2>
  11. *
  12. * This software component is licensed by ST under BSD 3-Clause license,
  13. * the "License"; You may not use this file except in compliance with the
  14. * License. You may obtain a copy of the License at:
  15. * opensource.org/licenses/BSD-3-Clause
  16. *
  17. ******************************************************************************
  18. */
  19. #if defined(USE_FULL_LL_DRIVER)
  20. /* Includes ------------------------------------------------------------------*/
  21. #include "stm32h7xx_ll_swpmi.h"
  22. #include "stm32h7xx_ll_bus.h"
  23. #ifdef USE_FULL_ASSERT
  24. #include "stm32_assert.h"
  25. #else
  26. #define assert_param(expr) ((void)0U)
  27. #endif
  28. /** @addtogroup STM32H7xx_LL_Driver
  29. * @{
  30. */
  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__) <= 255U))
  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(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 (SWPMI_CR_SWPACT bit = 0),
  85. * SWPMI IP should be in deactivated state prior calling this function. Otherwise, ERROR result will be returned.
  86. * @param SWPMIx SWPMI Instance
  87. * @param SWPMI_InitStruct pointer to a @ref LL_SWPMI_InitTypeDef structure that contains
  88. * the configuration information for the SWPMI peripheral.
  89. * @retval An ErrorStatus enumeration value
  90. * - SUCCESS: SWPMI registers are initialized
  91. * - ERROR: SWPMI registers are not initialized
  92. */
  93. ErrorStatus LL_SWPMI_Init(SWPMI_TypeDef *SWPMIx, LL_SWPMI_InitTypeDef *SWPMI_InitStruct)
  94. {
  95. ErrorStatus status = SUCCESS;
  96. /* Check the parameters */
  97. assert_param(IS_SWPMI_INSTANCE(SWPMIx));
  98. assert_param(IS_LL_SWPMI_BITRATE_VALUE(SWPMI_InitStruct->BitRatePrescaler));
  99. assert_param(IS_LL_SWPMI_SW_BUFFER_TX(SWPMI_InitStruct->TxBufferingMode));
  100. assert_param(IS_LL_SWPMI_SW_BUFFER_RX(SWPMI_InitStruct->RxBufferingMode));
  101. assert_param(IS_LL_SWPMI_VOLTAGE_CLASS(SWPMI_InitStruct->VoltageClass));
  102. /* SWPMI needs to be in deactivated state, in order to be able to configure some bits */
  103. if (LL_SWPMI_IsActivated(SWPMIx) == 0U)
  104. {
  105. /* Configure the BRR register (Bitrate) */
  106. LL_SWPMI_SetBitRatePrescaler(SWPMIx, SWPMI_InitStruct->BitRatePrescaler);
  107. /* Configure the voltage class */
  108. LL_SWPMI_SetVoltageClass(SWPMIx, SWPMI_InitStruct->VoltageClass);
  109. /* Set the new configuration of the SWPMI peripheral */
  110. MODIFY_REG(SWPMIx->CR,
  111. (SWPMI_CR_RXMODE | SWPMI_CR_TXMODE),
  112. (SWPMI_InitStruct->TxBufferingMode | SWPMI_InitStruct->RxBufferingMode));
  113. }
  114. /* Else (SWPMI not in deactivated state => return ERROR) */
  115. else
  116. {
  117. status = ERROR;
  118. }
  119. return status;
  120. }
  121. /**
  122. * @brief Set each @ref LL_SWPMI_InitTypeDef field to default value.
  123. * @param SWPMI_InitStruct pointer to a @ref LL_SWPMI_InitTypeDef structure that contains
  124. * the configuration information for the SWPMI peripheral.
  125. * @retval None
  126. */
  127. void LL_SWPMI_StructInit(LL_SWPMI_InitTypeDef *SWPMI_InitStruct)
  128. {
  129. /* Set SWPMI_InitStruct fields to default values */
  130. SWPMI_InitStruct->VoltageClass = LL_SWPMI_VOLTAGE_CLASS_C;
  131. SWPMI_InitStruct->BitRatePrescaler = (uint32_t)0x00000001;
  132. SWPMI_InitStruct->TxBufferingMode = LL_SWPMI_SW_BUFFER_TX_SINGLE;
  133. SWPMI_InitStruct->RxBufferingMode = LL_SWPMI_SW_BUFFER_RX_SINGLE;
  134. }
  135. /**
  136. * @}
  137. */
  138. /**
  139. * @}
  140. */
  141. /**
  142. * @}
  143. */
  144. /**
  145. * @}
  146. */
  147. #endif /* USE_FULL_LL_DRIVER */
  148. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/