STM32L486xx 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   * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
00010   *
00011   * Redistribution and use in source and binary forms, with or without modification,
00012   * are permitted provided that the following conditions are met:
00013   *   1. Redistributions of source code must retain the above copyright notice,
00014   *      this list of conditions and the following disclaimer.
00015   *   2. Redistributions in binary form must reproduce the above copyright notice,
00016   *      this list of conditions and the following disclaimer in the documentation
00017   *      and/or other materials provided with the distribution.
00018   *   3. Neither the name of STMicroelectronics nor the names of its contributors
00019   *      may be used to endorse or promote products derived from this software
00020   *      without specific prior written permission.
00021   *
00022   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00023   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00024   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00025   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00026   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00027   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00028   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00030   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00031   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00032   *
00033   ******************************************************************************
00034   */
00035 #if defined(USE_FULL_LL_DRIVER)
00036 
00037 /* Includes ------------------------------------------------------------------*/
00038 #include "stm32l4xx_ll_swpmi.h"
00039 #include "stm32l4xx_ll_bus.h"
00040 #ifdef  USE_FULL_ASSERT
00041 #include "stm32_assert.h"
00042 #else
00043 #define assert_param(expr) ((void)0U)
00044 #endif
00045 
00046 /** @addtogroup STM32L4xx_LL_Driver
00047   * @{
00048   */
00049 
00050 #if defined(SWPMI1)
00051 
00052 /** @addtogroup SWPMI_LL
00053   * @{
00054   */
00055 
00056 /* Private types -------------------------------------------------------------*/
00057 /* Private variables ---------------------------------------------------------*/
00058 /* Private constants ---------------------------------------------------------*/
00059 /* Private macros ------------------------------------------------------------*/
00060 /** @addtogroup SWPMI_LL_Private_Macros
00061   * @{
00062   */
00063 
00064 #define IS_LL_SWPMI_BITRATE_VALUE(__VALUE__) (((__VALUE__) <= 63))
00065 
00066 #define IS_LL_SWPMI_SW_BUFFER_RX(__VALUE__) (((__VALUE__) == LL_SWPMI_SW_BUFFER_RX_SINGLE) \
00067                                           || ((__VALUE__) == LL_SWPMI_SW_BUFFER_RX_MULTI))
00068 
00069 #define IS_LL_SWPMI_SW_BUFFER_TX(__VALUE__) (((__VALUE__) == LL_SWPMI_SW_BUFFER_TX_SINGLE) \
00070                                           || ((__VALUE__) == LL_SWPMI_SW_BUFFER_TX_MULTI))
00071 
00072 #define IS_LL_SWPMI_VOLTAGE_CLASS(__VALUE__) (((__VALUE__) == LL_SWPMI_VOLTAGE_CLASS_C) \
00073                                            || ((__VALUE__) == LL_SWPMI_VOLTAGE_CLASS_B))
00074 
00075 /**
00076   * @}
00077   */
00078 
00079 /* Private function prototypes -----------------------------------------------*/
00080 
00081 /* Exported functions --------------------------------------------------------*/
00082 /** @addtogroup SWPMI_LL_Exported_Functions
00083   * @{
00084   */
00085 
00086 /** @addtogroup SWPMI_LL_EF_Init
00087   * @{
00088   */
00089 
00090 /**
00091   * @brief  De-initialize the SWPMI peripheral registers to their default reset values.
00092   * @param  SWPMIx SWPMI Instance
00093   * @retval An ErrorStatus enumeration value
00094   *          - SUCCESS: SWPMI registers are de-initialized
00095   *          - ERROR: Not applicable
00096   */
00097 ErrorStatus LL_SWPMI_DeInit(SWPMI_TypeDef *SWPMIx)
00098 {
00099   /* Check the parameter */
00100   assert_param(IS_SWPMI_INSTANCE(SWPMIx));
00101 
00102   LL_APB1_GRP2_ForceReset(LL_APB1_GRP2_PERIPH_SWPMI1);
00103   LL_APB1_GRP2_ReleaseReset(LL_APB1_GRP2_PERIPH_SWPMI1);
00104 
00105   return SUCCESS;
00106 }
00107 
00108 /**
00109   * @brief  Initialize the SWPMI peripheral according to the specified parameters in the SWPMI_InitStruct.
00110   * @note   As some bits in SWPMI configuration registers can only be written when the SWPMI is deactivated (SWPMI_CR_SWPACT bit = 0),
00111   *         SWPMI IP should be in deactivated state prior calling this function. Otherwise, ERROR result will be returned.
00112   * @param  SWPMIx           SWPMI Instance
00113   * @param  SWPMI_InitStruct pointer to a @ref LL_SWPMI_InitTypeDef structure that contains
00114   *                          the configuration information for the SWPMI peripheral.
00115   * @retval An ErrorStatus enumeration value
00116   *          - SUCCESS: SWPMI registers are initialized
00117   *          - ERROR: SWPMI registers are not initialized
00118   */
00119 ErrorStatus LL_SWPMI_Init(SWPMI_TypeDef *SWPMIx, LL_SWPMI_InitTypeDef *SWPMI_InitStruct)
00120 {
00121   ErrorStatus status = SUCCESS;
00122 
00123   /* Check the parameters */
00124   assert_param(IS_SWPMI_INSTANCE(SWPMIx));
00125   assert_param(IS_LL_SWPMI_BITRATE_VALUE(SWPMI_InitStruct->BitRatePrescaler));
00126   assert_param(IS_LL_SWPMI_SW_BUFFER_TX(SWPMI_InitStruct->TxBufferingMode));
00127   assert_param(IS_LL_SWPMI_SW_BUFFER_RX(SWPMI_InitStruct->RxBufferingMode));
00128   assert_param(IS_LL_SWPMI_VOLTAGE_CLASS(SWPMI_InitStruct->VoltageClass));
00129 
00130   /* SWPMI needs to be in deactivated state, in order to be able to configure some bits */
00131   if (LL_SWPMI_IsActivated(SWPMIx) == 0)
00132   {
00133     /* Configure the BRR register (Bitrate) */
00134     LL_SWPMI_SetBitRatePrescaler(SWPMIx, SWPMI_InitStruct->BitRatePrescaler);
00135 
00136     /* Configure the voltage class */
00137     LL_SWPMI_SetVoltageClass(SWPMIx, SWPMI_InitStruct->VoltageClass);
00138 
00139     /* Set the new configuration of the SWPMI peripheral */
00140     MODIFY_REG(SWPMIx->CR,
00141               (SWPMI_CR_RXMODE | SWPMI_CR_TXMODE),
00142               (SWPMI_InitStruct->TxBufferingMode | SWPMI_InitStruct->RxBufferingMode));
00143   }
00144   /* Else (SWPMI not in deactivated state => return ERROR) */
00145   else
00146   {
00147     status = ERROR;
00148   }
00149 
00150   return status;
00151 }
00152 
00153 /**
00154   * @brief  Set each @ref LL_SWPMI_InitTypeDef field to default value.
00155   * @param  SWPMI_InitStruct pointer to a @ref LL_SWPMI_InitTypeDef structure that contains
00156   *                          the configuration information for the SWPMI peripheral.
00157   * @retval None
00158   */
00159 void LL_SWPMI_StructInit(LL_SWPMI_InitTypeDef *SWPMI_InitStruct)
00160 {
00161   /* Set SWPMI_InitStruct fields to default values */
00162   SWPMI_InitStruct->VoltageClass     = LL_SWPMI_VOLTAGE_CLASS_C;
00163   SWPMI_InitStruct->BitRatePrescaler = (uint32_t)0x00000001;
00164   SWPMI_InitStruct->TxBufferingMode  = LL_SWPMI_SW_BUFFER_TX_SINGLE;
00165   SWPMI_InitStruct->RxBufferingMode  = LL_SWPMI_SW_BUFFER_RX_SINGLE;
00166 }
00167 
00168 /**
00169   * @}
00170   */
00171 
00172 /**
00173   * @}
00174   */
00175 
00176 /**
00177   * @}
00178   */
00179 
00180 #endif /* SWPMI1 */
00181 
00182 /**
00183   * @}
00184   */
00185 
00186 #endif /* USE_FULL_LL_DRIVER */
00187 
00188 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/