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