2 ******************************************************************************
3 * @file stm32h7xx_ll_swpmi.c
4 * @author MCD Application Team
5 * @brief SWPMI LL module driver.
6 ******************************************************************************
9 * <h2><center>© Copyright (c) 2017 STMicroelectronics.
10 * All rights reserved.</center></h2>
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
17 ******************************************************************************
19 #if defined(USE_FULL_LL_DRIVER)
21 /* Includes ------------------------------------------------------------------*/
22 #include "stm32h7xx_ll_swpmi.h"
23 #include "stm32h7xx_ll_bus.h"
24 #ifdef USE_FULL_ASSERT
25 #include "stm32_assert.h"
27 #define assert_param(expr) ((void)0U)
30 /** @addtogroup STM32H7xx_LL_Driver
35 /** @addtogroup SWPMI_LL
39 /* Private types -------------------------------------------------------------*/
40 /* Private variables ---------------------------------------------------------*/
41 /* Private constants ---------------------------------------------------------*/
42 /* Private macros ------------------------------------------------------------*/
43 /** @addtogroup SWPMI_LL_Private_Macros
47 #define IS_LL_SWPMI_BITRATE_VALUE(__VALUE__) (((__VALUE__) <= 255U))
49 #define IS_LL_SWPMI_SW_BUFFER_RX(__VALUE__) (((__VALUE__) == LL_SWPMI_SW_BUFFER_RX_SINGLE) \
50 || ((__VALUE__) == LL_SWPMI_SW_BUFFER_RX_MULTI))
52 #define IS_LL_SWPMI_SW_BUFFER_TX(__VALUE__) (((__VALUE__) == LL_SWPMI_SW_BUFFER_TX_SINGLE) \
53 || ((__VALUE__) == LL_SWPMI_SW_BUFFER_TX_MULTI))
55 #define IS_LL_SWPMI_VOLTAGE_CLASS(__VALUE__) (((__VALUE__) == LL_SWPMI_VOLTAGE_CLASS_C) \
56 || ((__VALUE__) == LL_SWPMI_VOLTAGE_CLASS_B))
62 /* Private function prototypes -----------------------------------------------*/
64 /* Exported functions --------------------------------------------------------*/
65 /** @addtogroup SWPMI_LL_Exported_Functions
69 /** @addtogroup SWPMI_LL_EF_Init
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
80 ErrorStatus
LL_SWPMI_DeInit(SWPMI_TypeDef
*SWPMIx
)
82 ErrorStatus status
= SUCCESS
;
84 /* Check the parameter */
85 assert_param(IS_SWPMI_INSTANCE(SWPMIx
));
89 LL_APB1_GRP2_ForceReset(LL_APB1_GRP2_PERIPH_SWPMI1
);
90 LL_APB1_GRP2_ReleaseReset(LL_APB1_GRP2_PERIPH_SWPMI1
);
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 (SWPMI_CR_SWPACT bit = 0),
103 * SWPMI IP should be in deactivated state prior calling this function. Otherwise, ERROR result will be returned.
104 * @param SWPMIx SWPMI Instance
105 * @param SWPMI_InitStruct pointer to a @ref LL_SWPMI_InitTypeDef structure that contains
106 * the configuration information for the SWPMI peripheral.
107 * @retval An ErrorStatus enumeration value
108 * - SUCCESS: SWPMI registers are initialized
109 * - ERROR: SWPMI registers are not initialized
111 ErrorStatus
LL_SWPMI_Init(SWPMI_TypeDef
*SWPMIx
, LL_SWPMI_InitTypeDef
*SWPMI_InitStruct
)
113 ErrorStatus status
= SUCCESS
;
115 /* Check the parameters */
116 assert_param(IS_SWPMI_INSTANCE(SWPMIx
));
117 assert_param(IS_LL_SWPMI_BITRATE_VALUE(SWPMI_InitStruct
->BitRatePrescaler
));
118 assert_param(IS_LL_SWPMI_SW_BUFFER_TX(SWPMI_InitStruct
->TxBufferingMode
));
119 assert_param(IS_LL_SWPMI_SW_BUFFER_RX(SWPMI_InitStruct
->RxBufferingMode
));
120 assert_param(IS_LL_SWPMI_VOLTAGE_CLASS(SWPMI_InitStruct
->VoltageClass
));
122 /* SWPMI needs to be in deactivated state, in order to be able to configure some bits */
123 if (LL_SWPMI_IsActivated(SWPMIx
) == 0U)
125 /* Configure the BRR register (Bitrate) */
126 LL_SWPMI_SetBitRatePrescaler(SWPMIx
, SWPMI_InitStruct
->BitRatePrescaler
);
128 /* Configure the voltage class */
129 LL_SWPMI_SetVoltageClass(SWPMIx
, SWPMI_InitStruct
->VoltageClass
);
131 /* Set the new configuration of the SWPMI peripheral */
132 MODIFY_REG(SWPMIx
->CR
,
133 (SWPMI_CR_RXMODE
| SWPMI_CR_TXMODE
),
134 (SWPMI_InitStruct
->TxBufferingMode
| SWPMI_InitStruct
->RxBufferingMode
));
136 /* Else (SWPMI not in deactivated state => return ERROR) */
146 * @brief Set each @ref LL_SWPMI_InitTypeDef field to default value.
147 * @param SWPMI_InitStruct pointer to a @ref LL_SWPMI_InitTypeDef structure that contains
148 * the configuration information for the SWPMI peripheral.
151 void LL_SWPMI_StructInit(LL_SWPMI_InitTypeDef
*SWPMI_InitStruct
)
153 /* Set SWPMI_InitStruct fields to default values */
154 SWPMI_InitStruct
->VoltageClass
= LL_SWPMI_VOLTAGE_CLASS_C
;
155 SWPMI_InitStruct
->BitRatePrescaler
= (uint32_t)0x00000001;
156 SWPMI_InitStruct
->TxBufferingMode
= LL_SWPMI_SW_BUFFER_TX_SINGLE
;
157 SWPMI_InitStruct
->RxBufferingMode
= LL_SWPMI_SW_BUFFER_RX_SINGLE
;
177 #endif /* USE_FULL_LL_DRIVER */
179 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/