STM32H735xx HAL User Manual
|
00001 /** 00002 ****************************************************************************** 00003 * @file stm32h7xx_hal_i2c_ex.c 00004 * @author MCD Application Team 00005 * @brief I2C Extended HAL module driver. 00006 * This file provides firmware functions to manage the following 00007 * functionalities of I2C Extended peripheral: 00008 * + Filter Mode Functions 00009 * + WakeUp Mode Functions 00010 * + FastModePlus Functions 00011 * 00012 ****************************************************************************** 00013 * @attention 00014 * 00015 * Copyright (c) 2017 STMicroelectronics. 00016 * All rights reserved. 00017 * 00018 * This software is licensed under terms that can be found in the LICENSE file 00019 * in the root directory of this software component. 00020 * If no LICENSE file comes with this software, it is provided AS-IS. 00021 * 00022 ****************************************************************************** 00023 @verbatim 00024 ============================================================================== 00025 ##### I2C peripheral Extended features ##### 00026 ============================================================================== 00027 00028 [..] Comparing to other previous devices, the I2C interface for STM32H7xx 00029 devices contains the following additional features 00030 00031 (+) Possibility to disable or enable Analog Noise Filter 00032 (+) Use of a configured Digital Noise Filter 00033 (+) Disable or enable wakeup from Stop mode(s) 00034 (+) Disable or enable Fast Mode Plus 00035 00036 ##### How to use this driver ##### 00037 ============================================================================== 00038 [..] This driver provides functions to configure Noise Filter and Wake Up Feature 00039 (#) Configure I2C Analog noise filter using the function HAL_I2CEx_ConfigAnalogFilter() 00040 (#) Configure I2C Digital noise filter using the function HAL_I2CEx_ConfigDigitalFilter() 00041 (#) Configure the enable or disable of I2C Wake Up Mode using the functions : 00042 (++) HAL_I2CEx_EnableWakeUp() 00043 (++) HAL_I2CEx_DisableWakeUp() 00044 (#) Configure the enable or disable of fast mode plus driving capability using the functions : 00045 (++) HAL_I2CEx_EnableFastModePlus() 00046 (++) HAL_I2CEx_DisableFastModePlus() 00047 @endverbatim 00048 */ 00049 00050 /* Includes ------------------------------------------------------------------*/ 00051 #include "stm32h7xx_hal.h" 00052 00053 /** @addtogroup STM32H7xx_HAL_Driver 00054 * @{ 00055 */ 00056 00057 /** @defgroup I2CEx I2CEx 00058 * @brief I2C Extended HAL module driver 00059 * @{ 00060 */ 00061 00062 #ifdef HAL_I2C_MODULE_ENABLED 00063 00064 /* Private typedef -----------------------------------------------------------*/ 00065 /* Private define ------------------------------------------------------------*/ 00066 /* Private macro -------------------------------------------------------------*/ 00067 /* Private variables ---------------------------------------------------------*/ 00068 /* Private function prototypes -----------------------------------------------*/ 00069 /* Private functions ---------------------------------------------------------*/ 00070 00071 /** @defgroup I2CEx_Exported_Functions I2C Extended Exported Functions 00072 * @{ 00073 */ 00074 00075 /** @defgroup I2CEx_Exported_Functions_Group1 Filter Mode Functions 00076 * @brief Filter Mode Functions 00077 * 00078 @verbatim 00079 =============================================================================== 00080 ##### Filter Mode Functions ##### 00081 =============================================================================== 00082 [..] This section provides functions allowing to: 00083 (+) Configure Noise Filters 00084 00085 @endverbatim 00086 * @{ 00087 */ 00088 00089 /** 00090 * @brief Configure I2C Analog noise filter. 00091 * @param hi2c Pointer to a I2C_HandleTypeDef structure that contains 00092 * the configuration information for the specified I2Cx peripheral. 00093 * @param AnalogFilter New state of the Analog filter. 00094 * @retval HAL status 00095 */ 00096 HAL_StatusTypeDef HAL_I2CEx_ConfigAnalogFilter(I2C_HandleTypeDef *hi2c, uint32_t AnalogFilter) 00097 { 00098 /* Check the parameters */ 00099 assert_param(IS_I2C_ALL_INSTANCE(hi2c->Instance)); 00100 assert_param(IS_I2C_ANALOG_FILTER(AnalogFilter)); 00101 00102 if (hi2c->State == HAL_I2C_STATE_READY) 00103 { 00104 /* Process Locked */ 00105 __HAL_LOCK(hi2c); 00106 00107 hi2c->State = HAL_I2C_STATE_BUSY; 00108 00109 /* Disable the selected I2C peripheral */ 00110 __HAL_I2C_DISABLE(hi2c); 00111 00112 /* Reset I2Cx ANOFF bit */ 00113 hi2c->Instance->CR1 &= ~(I2C_CR1_ANFOFF); 00114 00115 /* Set analog filter bit*/ 00116 hi2c->Instance->CR1 |= AnalogFilter; 00117 00118 __HAL_I2C_ENABLE(hi2c); 00119 00120 hi2c->State = HAL_I2C_STATE_READY; 00121 00122 /* Process Unlocked */ 00123 __HAL_UNLOCK(hi2c); 00124 00125 return HAL_OK; 00126 } 00127 else 00128 { 00129 return HAL_BUSY; 00130 } 00131 } 00132 00133 /** 00134 * @brief Configure I2C Digital noise filter. 00135 * @param hi2c Pointer to a I2C_HandleTypeDef structure that contains 00136 * the configuration information for the specified I2Cx peripheral. 00137 * @param DigitalFilter Coefficient of digital noise filter between Min_Data=0x00 and Max_Data=0x0F. 00138 * @retval HAL status 00139 */ 00140 HAL_StatusTypeDef HAL_I2CEx_ConfigDigitalFilter(I2C_HandleTypeDef *hi2c, uint32_t DigitalFilter) 00141 { 00142 uint32_t tmpreg; 00143 00144 /* Check the parameters */ 00145 assert_param(IS_I2C_ALL_INSTANCE(hi2c->Instance)); 00146 assert_param(IS_I2C_DIGITAL_FILTER(DigitalFilter)); 00147 00148 if (hi2c->State == HAL_I2C_STATE_READY) 00149 { 00150 /* Process Locked */ 00151 __HAL_LOCK(hi2c); 00152 00153 hi2c->State = HAL_I2C_STATE_BUSY; 00154 00155 /* Disable the selected I2C peripheral */ 00156 __HAL_I2C_DISABLE(hi2c); 00157 00158 /* Get the old register value */ 00159 tmpreg = hi2c->Instance->CR1; 00160 00161 /* Reset I2Cx DNF bits [11:8] */ 00162 tmpreg &= ~(I2C_CR1_DNF); 00163 00164 /* Set I2Cx DNF coefficient */ 00165 tmpreg |= DigitalFilter << 8U; 00166 00167 /* Store the new register value */ 00168 hi2c->Instance->CR1 = tmpreg; 00169 00170 __HAL_I2C_ENABLE(hi2c); 00171 00172 hi2c->State = HAL_I2C_STATE_READY; 00173 00174 /* Process Unlocked */ 00175 __HAL_UNLOCK(hi2c); 00176 00177 return HAL_OK; 00178 } 00179 else 00180 { 00181 return HAL_BUSY; 00182 } 00183 } 00184 /** 00185 * @} 00186 */ 00187 00188 /** @defgroup I2CEx_Exported_Functions_Group2 WakeUp Mode Functions 00189 * @brief WakeUp Mode Functions 00190 * 00191 @verbatim 00192 =============================================================================== 00193 ##### WakeUp Mode Functions ##### 00194 =============================================================================== 00195 [..] This section provides functions allowing to: 00196 (+) Configure Wake Up Feature 00197 00198 @endverbatim 00199 * @{ 00200 */ 00201 00202 /** 00203 * @brief Enable I2C wakeup from Stop mode(s). 00204 * @param hi2c Pointer to a I2C_HandleTypeDef structure that contains 00205 * the configuration information for the specified I2Cx peripheral. 00206 * @retval HAL status 00207 */ 00208 HAL_StatusTypeDef HAL_I2CEx_EnableWakeUp(I2C_HandleTypeDef *hi2c) 00209 { 00210 /* Check the parameters */ 00211 assert_param(IS_I2C_WAKEUP_FROMSTOP_INSTANCE(hi2c->Instance)); 00212 00213 if (hi2c->State == HAL_I2C_STATE_READY) 00214 { 00215 /* Process Locked */ 00216 __HAL_LOCK(hi2c); 00217 00218 hi2c->State = HAL_I2C_STATE_BUSY; 00219 00220 /* Disable the selected I2C peripheral */ 00221 __HAL_I2C_DISABLE(hi2c); 00222 00223 /* Enable wakeup from stop mode */ 00224 hi2c->Instance->CR1 |= I2C_CR1_WUPEN; 00225 00226 __HAL_I2C_ENABLE(hi2c); 00227 00228 hi2c->State = HAL_I2C_STATE_READY; 00229 00230 /* Process Unlocked */ 00231 __HAL_UNLOCK(hi2c); 00232 00233 return HAL_OK; 00234 } 00235 else 00236 { 00237 return HAL_BUSY; 00238 } 00239 } 00240 00241 /** 00242 * @brief Disable I2C wakeup from Stop mode(s). 00243 * @param hi2c Pointer to a I2C_HandleTypeDef structure that contains 00244 * the configuration information for the specified I2Cx peripheral. 00245 * @retval HAL status 00246 */ 00247 HAL_StatusTypeDef HAL_I2CEx_DisableWakeUp(I2C_HandleTypeDef *hi2c) 00248 { 00249 /* Check the parameters */ 00250 assert_param(IS_I2C_WAKEUP_FROMSTOP_INSTANCE(hi2c->Instance)); 00251 00252 if (hi2c->State == HAL_I2C_STATE_READY) 00253 { 00254 /* Process Locked */ 00255 __HAL_LOCK(hi2c); 00256 00257 hi2c->State = HAL_I2C_STATE_BUSY; 00258 00259 /* Disable the selected I2C peripheral */ 00260 __HAL_I2C_DISABLE(hi2c); 00261 00262 /* Enable wakeup from stop mode */ 00263 hi2c->Instance->CR1 &= ~(I2C_CR1_WUPEN); 00264 00265 __HAL_I2C_ENABLE(hi2c); 00266 00267 hi2c->State = HAL_I2C_STATE_READY; 00268 00269 /* Process Unlocked */ 00270 __HAL_UNLOCK(hi2c); 00271 00272 return HAL_OK; 00273 } 00274 else 00275 { 00276 return HAL_BUSY; 00277 } 00278 } 00279 /** 00280 * @} 00281 */ 00282 00283 /** @defgroup I2CEx_Exported_Functions_Group3 Fast Mode Plus Functions 00284 * @brief Fast Mode Plus Functions 00285 * 00286 @verbatim 00287 =============================================================================== 00288 ##### Fast Mode Plus Functions ##### 00289 =============================================================================== 00290 [..] This section provides functions allowing to: 00291 (+) Configure Fast Mode Plus 00292 00293 @endverbatim 00294 * @{ 00295 */ 00296 00297 /** 00298 * @brief Enable the I2C fast mode plus driving capability. 00299 * @param ConfigFastModePlus Selects the pin. 00300 * This parameter can be one of the @ref I2CEx_FastModePlus values 00301 * @note For I2C1, fast mode plus driving capability can be enabled on all selected 00302 * I2C1 pins using I2C_FASTMODEPLUS_I2C1 parameter or independently 00303 * on each one of the following pins PB6, PB7, PB8 and PB9. 00304 * @note For remaining I2C1 pins (PA14, PA15...) fast mode plus driving capability 00305 * can be enabled only by using I2C_FASTMODEPLUS_I2C1 parameter. 00306 * @note For all I2C2 pins fast mode plus driving capability can be enabled 00307 * only by using I2C_FASTMODEPLUS_I2C2 parameter. 00308 * @note For all I2C3 pins fast mode plus driving capability can be enabled 00309 * only by using I2C_FASTMODEPLUS_I2C3 parameter. 00310 * @note For all I2C4 pins fast mode plus driving capability can be enabled 00311 * only by using I2C_FASTMODEPLUS_I2C4 parameter. 00312 * @note For all I2C5 pins fast mode plus driving capability can be enabled 00313 * only by using I2C_FASTMODEPLUS_I2C5 parameter. 00314 * @retval None 00315 */ 00316 void HAL_I2CEx_EnableFastModePlus(uint32_t ConfigFastModePlus) 00317 { 00318 /* Check the parameter */ 00319 assert_param(IS_I2C_FASTMODEPLUS(ConfigFastModePlus)); 00320 00321 /* Enable SYSCFG clock */ 00322 __HAL_RCC_SYSCFG_CLK_ENABLE(); 00323 00324 /* Enable fast mode plus driving capability for selected pin */ 00325 SET_BIT(SYSCFG->PMCR, (uint32_t)ConfigFastModePlus); 00326 } 00327 00328 /** 00329 * @brief Disable the I2C fast mode plus driving capability. 00330 * @param ConfigFastModePlus Selects the pin. 00331 * This parameter can be one of the @ref I2CEx_FastModePlus values 00332 * @note For I2C1, fast mode plus driving capability can be disabled on all selected 00333 * I2C1 pins using I2C_FASTMODEPLUS_I2C1 parameter or independently 00334 * on each one of the following pins PB6, PB7, PB8 and PB9. 00335 * @note For remaining I2C1 pins (PA14, PA15...) fast mode plus driving capability 00336 * can be disabled only by using I2C_FASTMODEPLUS_I2C1 parameter. 00337 * @note For all I2C2 pins fast mode plus driving capability can be disabled 00338 * only by using I2C_FASTMODEPLUS_I2C2 parameter. 00339 * @note For all I2C3 pins fast mode plus driving capability can be disabled 00340 * only by using I2C_FASTMODEPLUS_I2C3 parameter. 00341 * @note For all I2C4 pins fast mode plus driving capability can be disabled 00342 * only by using I2C_FASTMODEPLUS_I2C4 parameter. 00343 * @note For all I2C5 pins fast mode plus driving capability can be disabled 00344 * only by using I2C_FASTMODEPLUS_I2C5 parameter. 00345 * @retval None 00346 */ 00347 void HAL_I2CEx_DisableFastModePlus(uint32_t ConfigFastModePlus) 00348 { 00349 /* Check the parameter */ 00350 assert_param(IS_I2C_FASTMODEPLUS(ConfigFastModePlus)); 00351 00352 /* Enable SYSCFG clock */ 00353 __HAL_RCC_SYSCFG_CLK_ENABLE(); 00354 00355 /* Disable fast mode plus driving capability for selected pin */ 00356 CLEAR_BIT(SYSCFG->PMCR, (uint32_t)ConfigFastModePlus); 00357 } 00358 /** 00359 * @} 00360 */ 00361 /** 00362 * @} 00363 */ 00364 00365 #endif /* HAL_I2C_MODULE_ENABLED */ 00366 /** 00367 * @} 00368 */ 00369 00370 /** 00371 * @} 00372 */