1 /**
2 ******************************************************************************
3 * @file stm32l4xx_ll_swpmi.c
4 * @author MCD Application Team
5 * @brief SWPMI LL module driver.
6 ******************************************************************************
7 * @attention
8 *
9 * <h2><center>© 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
21 /* Includes ------------------------------------------------------------------*/
22 #include "stm32l4xx_ll_swpmi.h"
23 #include "stm32l4xx_ll_bus.h"
24 #ifdef USE_FULL_ASSERT
25 #include "stm32_assert.h"
26 #else
27 #define assert_param(expr) ((void)0U)
28 #endif
29
30 /** @addtogroup STM32L4xx_LL_Driver
31 * @{
32 */
33
34 #if defined(SWPMI1)
35
36 /** @addtogroup SWPMI_LL
37 * @{
38 */
39
40 /* Private types -------------------------------------------------------------*/
41 /* Private variables ---------------------------------------------------------*/
42 /* Private constants ---------------------------------------------------------*/
43 /* Private macros ------------------------------------------------------------*/
44 /** @addtogroup SWPMI_LL_Private_Macros
45 * @{
46 */
47
48 #define IS_LL_SWPMI_BITRATE_VALUE(__VALUE__) (((__VALUE__) <= 63U))
49
50 #define IS_LL_SWPMI_SW_BUFFER_RX(__VALUE__) (((__VALUE__) == LL_SWPMI_SW_BUFFER_RX_SINGLE) \
51 || ((__VALUE__) == LL_SWPMI_SW_BUFFER_RX_MULTI))
52
53 #define IS_LL_SWPMI_SW_BUFFER_TX(__VALUE__) (((__VALUE__) == LL_SWPMI_SW_BUFFER_TX_SINGLE) \
54 || ((__VALUE__) == LL_SWPMI_SW_BUFFER_TX_MULTI))
55
56 #define IS_LL_SWPMI_VOLTAGE_CLASS(__VALUE__) (((__VALUE__) == LL_SWPMI_VOLTAGE_CLASS_C) \
57 || ((__VALUE__) == LL_SWPMI_VOLTAGE_CLASS_B))
58
59 /**
60 * @}
61 */
62
63 /* Private function prototypes -----------------------------------------------*/
64
65 /* Exported functions --------------------------------------------------------*/
66 /** @addtogroup SWPMI_LL_Exported_Functions
67 * @{
68 */
69
70 /** @addtogroup SWPMI_LL_EF_Init
71 * @{
72 */
73
74 /**
75 * @brief De-initialize the SWPMI peripheral registers to their default reset values.
76 * @param SWPMIx SWPMI Instance
77 * @retval An ErrorStatus enumeration value
78 * - SUCCESS: SWPMI registers are de-initialized
79 * - ERROR: Not applicable
80 */
LL_SWPMI_DeInit(SWPMI_TypeDef * SWPMIx)81 ErrorStatus LL_SWPMI_DeInit(SWPMI_TypeDef *SWPMIx)
82 {
83 ErrorStatus status = SUCCESS;
84
85 /* Check the parameter */
86 assert_param(IS_SWPMI_INSTANCE(SWPMIx));
87
88 if (SWPMIx == SWPMI1)
89 {
90 LL_APB1_GRP2_ForceReset(LL_APB1_GRP2_PERIPH_SWPMI1);
91 LL_APB1_GRP2_ReleaseReset(LL_APB1_GRP2_PERIPH_SWPMI1);
92 }
93 else
94 {
95 status = ERROR;
96 }
97
98 return status;
99 }
100
101 /**
102 * @brief Initialize the SWPMI peripheral according to the specified parameters in the SWPMI_InitStruct.
103 * @note As some bits in SWPMI configuration registers can only be written when the SWPMI is deactivated (SWPMI_CR_SWPACT bit = 0),
104 * SWPMI IP should be in deactivated state prior calling this function. Otherwise, ERROR result will be returned.
105 * @param SWPMIx SWPMI Instance
106 * @param SWPMI_InitStruct pointer to a @ref LL_SWPMI_InitTypeDef structure that contains
107 * the configuration information for the SWPMI peripheral.
108 * @retval An ErrorStatus enumeration value
109 * - SUCCESS: SWPMI registers are initialized
110 * - ERROR: SWPMI registers are not initialized
111 */
LL_SWPMI_Init(SWPMI_TypeDef * SWPMIx,LL_SWPMI_InitTypeDef * SWPMI_InitStruct)112 ErrorStatus LL_SWPMI_Init(SWPMI_TypeDef *SWPMIx, LL_SWPMI_InitTypeDef *SWPMI_InitStruct)
113 {
114 ErrorStatus status = SUCCESS;
115
116 /* Check the parameters */
117 assert_param(IS_SWPMI_INSTANCE(SWPMIx));
118 assert_param(IS_LL_SWPMI_BITRATE_VALUE(SWPMI_InitStruct->BitRatePrescaler));
119 assert_param(IS_LL_SWPMI_SW_BUFFER_TX(SWPMI_InitStruct->TxBufferingMode));
120 assert_param(IS_LL_SWPMI_SW_BUFFER_RX(SWPMI_InitStruct->RxBufferingMode));
121 assert_param(IS_LL_SWPMI_VOLTAGE_CLASS(SWPMI_InitStruct->VoltageClass));
122
123 /* SWPMI needs to be in deactivated state, in order to be able to configure some bits */
124 if (LL_SWPMI_IsActivated(SWPMIx) == 0U)
125 {
126 /* Configure the BRR register (Bitrate) */
127 LL_SWPMI_SetBitRatePrescaler(SWPMIx, SWPMI_InitStruct->BitRatePrescaler);
128
129 /* Configure the voltage class */
130 LL_SWPMI_SetVoltageClass(SWPMIx, SWPMI_InitStruct->VoltageClass);
131
132 /* Set the new configuration of the SWPMI peripheral */
133 MODIFY_REG(SWPMIx->CR,
134 (SWPMI_CR_RXMODE | SWPMI_CR_TXMODE),
135 (SWPMI_InitStruct->TxBufferingMode | SWPMI_InitStruct->RxBufferingMode));
136 }
137 /* Else (SWPMI not in deactivated state => return ERROR) */
138 else
139 {
140 status = ERROR;
141 }
142
143 return status;
144 }
145
146 /**
147 * @brief Set each @ref LL_SWPMI_InitTypeDef field to default value.
148 * @param SWPMI_InitStruct pointer to a @ref LL_SWPMI_InitTypeDef structure that contains
149 * the configuration information for the SWPMI peripheral.
150 * @retval None
151 */
LL_SWPMI_StructInit(LL_SWPMI_InitTypeDef * SWPMI_InitStruct)152 void LL_SWPMI_StructInit(LL_SWPMI_InitTypeDef *SWPMI_InitStruct)
153 {
154 /* Set SWPMI_InitStruct fields to default values */
155 SWPMI_InitStruct->VoltageClass = LL_SWPMI_VOLTAGE_CLASS_C;
156 SWPMI_InitStruct->BitRatePrescaler = (uint32_t)0x00000001;
157 SWPMI_InitStruct->TxBufferingMode = LL_SWPMI_SW_BUFFER_TX_SINGLE;
158 SWPMI_InitStruct->RxBufferingMode = LL_SWPMI_SW_BUFFER_RX_SINGLE;
159 }
160
161 /**
162 * @}
163 */
164
165 /**
166 * @}
167 */
168
169 /**
170 * @}
171 */
172
173 #endif /* SWPMI1 */
174
175 /**
176 * @}
177 */
178
179 #endif /* USE_FULL_LL_DRIVER */
180
181 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
182