STM32H735xx HAL User Manual
stm32h7xx_ll_swpmi.c
Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm32h7xx_ll_swpmi.c
00004   * @author  MCD Application Team
00005   * @brief   SWPMI LL module driver.
00006   ******************************************************************************
00007   * @attention
00008   *
00009   * Copyright (c) 2017 STMicroelectronics.
00010   * All rights reserved.
00011   *
00012   * This software is licensed under terms that can be found in the LICENSE file
00013   * in the root directory of this software component.
00014   * If no LICENSE file comes with this software, it is provided AS-IS.
00015   *
00016   ******************************************************************************
00017   */
00018 #if defined(USE_FULL_LL_DRIVER)
00019 
00020 /* Includes ------------------------------------------------------------------*/
00021 #include "stm32h7xx_ll_swpmi.h"
00022 #include "stm32h7xx_ll_bus.h"
00023 #ifdef  USE_FULL_ASSERT
00024 #include "stm32_assert.h"
00025 #else
00026 #define assert_param(expr) ((void)0U)
00027 #endif
00028 
00029 /** @addtogroup STM32H7xx_LL_Driver
00030   * @{
00031   */
00032 
00033 
00034 /** @addtogroup SWPMI_LL
00035   * @{
00036   */
00037 
00038 /* Private types -------------------------------------------------------------*/
00039 /* Private variables ---------------------------------------------------------*/
00040 /* Private constants ---------------------------------------------------------*/
00041 /* Private macros ------------------------------------------------------------*/
00042 /** @addtogroup SWPMI_LL_Private_Macros
00043   * @{
00044   */
00045 
00046 #define IS_LL_SWPMI_BITRATE_VALUE(__VALUE__) (((__VALUE__) <= 255U))
00047 
00048 #define IS_LL_SWPMI_SW_BUFFER_RX(__VALUE__) (((__VALUE__) == LL_SWPMI_SW_BUFFER_RX_SINGLE) \
00049                                           || ((__VALUE__) == LL_SWPMI_SW_BUFFER_RX_MULTI))
00050 
00051 #define IS_LL_SWPMI_SW_BUFFER_TX(__VALUE__) (((__VALUE__) == LL_SWPMI_SW_BUFFER_TX_SINGLE) \
00052                                           || ((__VALUE__) == LL_SWPMI_SW_BUFFER_TX_MULTI))
00053 
00054 #define IS_LL_SWPMI_VOLTAGE_CLASS(__VALUE__) (((__VALUE__) == LL_SWPMI_VOLTAGE_CLASS_C) \
00055                                            || ((__VALUE__) == LL_SWPMI_VOLTAGE_CLASS_B))
00056 
00057 /**
00058   * @}
00059   */
00060 
00061 /* Private function prototypes -----------------------------------------------*/
00062 
00063 /* Exported functions --------------------------------------------------------*/
00064 /** @addtogroup SWPMI_LL_Exported_Functions
00065   * @{
00066   */
00067 
00068 /** @addtogroup SWPMI_LL_EF_Init
00069   * @{
00070   */
00071 
00072 /**
00073   * @brief  De-initialize the SWPMI peripheral registers to their default reset values.
00074   * @param  SWPMIx SWPMI Instance
00075   * @retval An ErrorStatus enumeration value
00076   *          - SUCCESS: SWPMI registers are de-initialized
00077   *          - ERROR: Not applicable
00078   */
00079 ErrorStatus LL_SWPMI_DeInit(SWPMI_TypeDef *SWPMIx)
00080 {
00081   ErrorStatus status = SUCCESS;
00082 
00083   /* Check the parameter */
00084   assert_param(IS_SWPMI_INSTANCE(SWPMIx));
00085 
00086   if (SWPMIx == SWPMI1)
00087   {
00088     LL_APB1_GRP2_ForceReset(LL_APB1_GRP2_PERIPH_SWPMI1);
00089     LL_APB1_GRP2_ReleaseReset(LL_APB1_GRP2_PERIPH_SWPMI1);
00090   }
00091   else
00092   {
00093     status = ERROR;
00094   }
00095 
00096   return status;
00097 }
00098 
00099 /**
00100   * @brief  Initialize the SWPMI peripheral according to the specified parameters in the SWPMI_InitStruct.
00101   * @note   As some bits in SWPMI configuration registers can only be written when the SWPMI is deactivated
00102   *         (SWPMI_CR_SWPACT bit = 0), the SWPMI peripheral should be in deactivated state prior calling
00103   *         this function. Otherwise, ERROR result will be returned.
00104   * @param  SWPMIx           SWPMI Instance
00105   * @param  SWPMI_InitStruct pointer to a @ref LL_SWPMI_InitTypeDef structure that contains
00106   *                          the configuration information for the SWPMI peripheral.
00107   * @retval An ErrorStatus enumeration value
00108   *          - SUCCESS: SWPMI registers are initialized
00109   *          - ERROR: SWPMI registers are not initialized
00110   */
00111 ErrorStatus LL_SWPMI_Init(SWPMI_TypeDef *SWPMIx, LL_SWPMI_InitTypeDef *SWPMI_InitStruct)
00112 {
00113   ErrorStatus status = SUCCESS;
00114 
00115   /* Check the parameters */
00116   assert_param(IS_SWPMI_INSTANCE(SWPMIx));
00117   assert_param(IS_LL_SWPMI_BITRATE_VALUE(SWPMI_InitStruct->BitRatePrescaler));
00118   assert_param(IS_LL_SWPMI_SW_BUFFER_TX(SWPMI_InitStruct->TxBufferingMode));
00119   assert_param(IS_LL_SWPMI_SW_BUFFER_RX(SWPMI_InitStruct->RxBufferingMode));
00120   assert_param(IS_LL_SWPMI_VOLTAGE_CLASS(SWPMI_InitStruct->VoltageClass));
00121 
00122   /* SWPMI needs to be in deactivated state, in order to be able to configure some bits */
00123   if (LL_SWPMI_IsActivated(SWPMIx) == 0U)
00124   {
00125     /* Configure the BRR register (Bitrate) */
00126     LL_SWPMI_SetBitRatePrescaler(SWPMIx, SWPMI_InitStruct->BitRatePrescaler);
00127 
00128     /* Configure the voltage class */
00129     LL_SWPMI_SetVoltageClass(SWPMIx, SWPMI_InitStruct->VoltageClass);
00130 
00131     /* Set the new configuration of the SWPMI peripheral */
00132     MODIFY_REG(SWPMIx->CR,
00133                (SWPMI_CR_RXMODE | SWPMI_CR_TXMODE),
00134                (SWPMI_InitStruct->TxBufferingMode | SWPMI_InitStruct->RxBufferingMode));
00135   }
00136   /* Else (SWPMI not in deactivated state => return ERROR) */
00137   else
00138   {
00139     status = ERROR;
00140   }
00141 
00142   return status;
00143 }
00144 
00145 /**
00146   * @brief  Set each @ref LL_SWPMI_InitTypeDef field to default value.
00147   * @param  SWPMI_InitStruct pointer to a @ref LL_SWPMI_InitTypeDef structure that contains
00148   *                          the configuration information for the SWPMI peripheral.
00149   * @retval None
00150   */
00151 void LL_SWPMI_StructInit(LL_SWPMI_InitTypeDef *SWPMI_InitStruct)
00152 {
00153   /* Set SWPMI_InitStruct fields to default values */
00154   SWPMI_InitStruct->VoltageClass     = LL_SWPMI_VOLTAGE_CLASS_C;
00155   SWPMI_InitStruct->BitRatePrescaler = (uint32_t)0x00000001;
00156   SWPMI_InitStruct->TxBufferingMode  = LL_SWPMI_SW_BUFFER_TX_SINGLE;
00157   SWPMI_InitStruct->RxBufferingMode  = LL_SWPMI_SW_BUFFER_RX_SINGLE;
00158 }
00159 
00160 /**
00161   * @}
00162   */
00163 
00164 /**
00165   * @}
00166   */
00167 
00168 /**
00169   * @}
00170   */
00171 
00172 
00173 /**
00174   * @}
00175   */
00176 
00177 #endif /* USE_FULL_LL_DRIVER */