1 /**
2 ******************************************************************************
3 * @file stm32l4xx_ll_swpmi.c
4 * @author MCD Application Team
5 * @brief SWPMI LL module driver.
6 ******************************************************************************
7 * @attention
8 *
9 * Copyright (c) 2017 STMicroelectronics.
10 * All rights reserved.
11 *
12 * This software is licensed under terms that can be found in the LICENSE file
13 * in the root directory of this software component.
14 * If no LICENSE file comes with this software, it is provided AS-IS.
15 *
16 ******************************************************************************
17 */
18 #if defined(USE_FULL_LL_DRIVER)
19
20 /* Includes ------------------------------------------------------------------*/
21 #include "stm32l4xx_ll_swpmi.h"
22 #include "stm32l4xx_ll_bus.h"
23 #ifdef USE_FULL_ASSERT
24 #include "stm32_assert.h"
25 #else
26 #define assert_param(expr) ((void)0U)
27 #endif
28
29 /** @addtogroup STM32L4xx_LL_Driver
30 * @{
31 */
32
33 #if defined(SWPMI1)
34
35 /** @addtogroup SWPMI_LL
36 * @{
37 */
38
39 /* Private types -------------------------------------------------------------*/
40 /* Private variables ---------------------------------------------------------*/
41 /* Private constants ---------------------------------------------------------*/
42 /* Private macros ------------------------------------------------------------*/
43 /** @addtogroup SWPMI_LL_Private_Macros
44 * @{
45 */
46
47 #define IS_LL_SWPMI_BITRATE_VALUE(__VALUE__) (((__VALUE__) <= 63U))
48
49 #define IS_LL_SWPMI_SW_BUFFER_RX(__VALUE__) (((__VALUE__) == LL_SWPMI_SW_BUFFER_RX_SINGLE) \
50 || ((__VALUE__) == LL_SWPMI_SW_BUFFER_RX_MULTI))
51
52 #define IS_LL_SWPMI_SW_BUFFER_TX(__VALUE__) (((__VALUE__) == LL_SWPMI_SW_BUFFER_TX_SINGLE) \
53 || ((__VALUE__) == LL_SWPMI_SW_BUFFER_TX_MULTI))
54
55 #define IS_LL_SWPMI_VOLTAGE_CLASS(__VALUE__) (((__VALUE__) == LL_SWPMI_VOLTAGE_CLASS_C) \
56 || ((__VALUE__) == LL_SWPMI_VOLTAGE_CLASS_B))
57
58 /**
59 * @}
60 */
61
62 /* Private function prototypes -----------------------------------------------*/
63
64 /* Exported functions --------------------------------------------------------*/
65 /** @addtogroup SWPMI_LL_Exported_Functions
66 * @{
67 */
68
69 /** @addtogroup SWPMI_LL_EF_Init
70 * @{
71 */
72
73 /**
74 * @brief De-initialize the SWPMI peripheral registers to their default reset values.
75 * @param SWPMIx SWPMI Instance
76 * @retval An ErrorStatus enumeration value
77 * - SUCCESS: SWPMI registers are de-initialized
78 * - ERROR: Not applicable
79 */
LL_SWPMI_DeInit(SWPMI_TypeDef * SWPMIx)80 ErrorStatus LL_SWPMI_DeInit(SWPMI_TypeDef *SWPMIx)
81 {
82 ErrorStatus status = SUCCESS;
83
84 /* Check the parameter */
85 assert_param(IS_SWPMI_INSTANCE(SWPMIx));
86
87 if (SWPMIx == SWPMI1)
88 {
89 LL_APB1_GRP2_ForceReset(LL_APB1_GRP2_PERIPH_SWPMI1);
90 LL_APB1_GRP2_ReleaseReset(LL_APB1_GRP2_PERIPH_SWPMI1);
91 }
92 else
93 {
94 status = ERROR;
95 }
96
97 return status;
98 }
99
100 /**
101 * @brief Initialize the SWPMI peripheral according to the specified parameters in the SWPMI_InitStruct.
102 * @note As some bits in SWPMI configuration registers can only be written when the SWPMI is deactivated
103 * (SWPMI_CR_SWPACT bit = 0), the SWPMI peripheral should be in deactivated state prior calling
104 * 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