TUKS MCU Introductory course / TUKS-COURSE-THERMOMETER

Fork of TUKS-COURSE-TIMER by TUKS MCU Introductory course

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers stm32l4xx_ll_swpmi.c Source File

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