STM32H735xx HAL User Manual
|
00001 /** 00002 ****************************************************************************** 00003 * @file stm32h7xx_ll_delayblock.c 00004 * @author MCD Application Team 00005 * @brief DelayBlock Low Layer HAL module driver. 00006 * 00007 * This file provides firmware functions to manage the following 00008 * functionalities of the Delay Block peripheral: 00009 * + input clock frequency range 25MHz to 208MHz 00010 * + up to 12 oversampling phases 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 ##### DelayBlock peripheral features ##### 00026 ============================================================================== 00027 [..] The Delay block is used to generate an Output clock which is de-phased from the Input 00028 clock. The phase of the Output clock is programmed by FW. The Output clock is then used 00029 to clock the receive data in i.e. a SDMMC or QSPI interface. 00030 The delay is Voltage and Temperature dependent, which may require FW to do re-tuning 00031 and recenter the Output clock phase to the receive data. 00032 00033 [..] The Delay Block features include the following: 00034 (+) Input clock frequency range 25MHz to 208MHz. 00035 (+) Up to 12 oversampling phases. 00036 00037 ##### How to use this driver ##### 00038 ============================================================================== 00039 [..] 00040 This driver is a considered as a driver of service for external devices drivers 00041 that interfaces with the DELAY peripheral. 00042 The DelayBlock_Enable() function, enables the DelayBlock instance, configure the delay line length 00043 and configure the Output clock phase. 00044 The DelayBlock_Disable() function, disables the DelayBlock instance by setting DEN flag to 0. 00045 00046 00047 @endverbatim 00048 */ 00049 00050 /* Includes ------------------------------------------------------------------*/ 00051 #include "stm32h7xx_hal.h" 00052 00053 /** @addtogroup STM32H7xx_HAL_Driver 00054 * @{ 00055 */ 00056 00057 /** @defgroup DELAYBLOCK_LL DELAYBLOCK_LL 00058 * @brief Low layer module for Delay Block 00059 * @{ 00060 */ 00061 00062 #if defined(HAL_SD_MODULE_ENABLED) || defined(HAL_QSPI_MODULE_ENABLED) 00063 00064 /* Private typedef -----------------------------------------------------------*/ 00065 /* Private define ------------------------------------------------------------*/ 00066 #define DLYB_TIMEOUT 0xFFU 00067 /* Private macro -------------------------------------------------------------*/ 00068 /* Private variables ---------------------------------------------------------*/ 00069 /* Private function prototypes -----------------------------------------------*/ 00070 /* Exported functions --------------------------------------------------------*/ 00071 00072 /** @defgroup DelayBlock_LL_Exported_Functions Delay Block Low Layer Exported Functions 00073 * @{ 00074 */ 00075 00076 /** @defgroup HAL_DELAY_LL_Group1 Initialization de-initialization functions 00077 * @brief Initialization and Configuration functions 00078 * 00079 @verbatim 00080 =============================================================================== 00081 ##### Initialization and de-initialization functions ##### 00082 =============================================================================== 00083 [..] This section provides functions allowing to: 00084 00085 @endverbatim 00086 * @{ 00087 */ 00088 00089 00090 /** 00091 * @brief Enable the Delay Block instance. 00092 * @param DLYBx: Pointer to DLYB instance. 00093 * @retval HAL status 00094 */ 00095 HAL_StatusTypeDef DelayBlock_Enable(DLYB_TypeDef *DLYBx) 00096 { 00097 uint32_t unit = 0U; 00098 uint32_t sel = 0U; 00099 uint32_t sel_current; 00100 uint32_t unit_current; 00101 uint32_t tuning; 00102 uint32_t lng_mask; 00103 uint32_t tickstart; 00104 00105 DLYBx->CR = DLYB_CR_DEN | DLYB_CR_SEN; 00106 00107 for (sel_current = 0U; sel_current < DLYB_MAX_SELECT; sel_current++) 00108 { 00109 /* lng_mask is the mask bit for the LNG field to check the output of the UNITx*/ 00110 lng_mask = DLYB_CFGR_LNG_0 << sel_current; 00111 tuning = 0U; 00112 for (unit_current = 0U; unit_current < DLYB_MAX_UNIT; unit_current++) 00113 { 00114 /* Set the Delay of the UNIT(s)*/ 00115 DLYBx->CFGR = DLYB_MAX_SELECT | (unit_current << DLYB_CFGR_UNIT_Pos); 00116 00117 /* Waiting for a LNG valid value */ 00118 tickstart = HAL_GetTick(); 00119 while ((DLYBx->CFGR & DLYB_CFGR_LNGF) == 0U) 00120 { 00121 if((HAL_GetTick() - tickstart) >= DLYB_TIMEOUT) 00122 { 00123 return HAL_TIMEOUT; 00124 } 00125 } 00126 if (tuning == 0U) 00127 { 00128 if ((DLYBx->CFGR & lng_mask) != 0U) 00129 { 00130 /* 1/2 period HIGH is detected */ 00131 tuning = 1U; 00132 } 00133 } 00134 else 00135 { 00136 /* 1/2 period LOW detected after the HIGH 1/2 period => FULL PERIOD passed*/ 00137 if((DLYBx->CFGR & lng_mask ) == 0U) 00138 { 00139 /* Save the first result */ 00140 if( unit == 0U ) 00141 { 00142 unit = unit_current; 00143 sel = sel_current + 1U; 00144 } 00145 break; 00146 } 00147 } 00148 } 00149 } 00150 00151 /* Apply the Tuning settings */ 00152 DLYBx->CR = 0U; 00153 DLYBx->CR = DLYB_CR_DEN | DLYB_CR_SEN; 00154 DLYBx->CFGR = sel | (unit << DLYB_CFGR_UNIT_Pos); 00155 DLYBx->CR = DLYB_CR_DEN; 00156 00157 return HAL_OK; 00158 } 00159 00160 /** 00161 * @brief Disable the Delay Block instance. 00162 * @param DLYBx: Pointer to DLYB instance. 00163 * @retval HAL status 00164 */ 00165 HAL_StatusTypeDef DelayBlock_Disable(DLYB_TypeDef *DLYBx) 00166 { 00167 /* Disable DLYB */ 00168 DLYBx->CR = 0U; 00169 return HAL_OK; 00170 } 00171 00172 /** 00173 * @brief Configure the Delay Block instance. 00174 * @param DLYBx: Pointer to DLYB instance. 00175 * @param PhaseSel: Phase selection [0..11]. 00176 * @param Units: Delay units[0..127]. 00177 * @retval HAL status 00178 */ 00179 HAL_StatusTypeDef DelayBlock_Configure(DLYB_TypeDef *DLYBx,uint32_t PhaseSel, uint32_t Units ) 00180 { 00181 /* Apply the delay settings */ 00182 00183 DLYBx->CR = 0U; 00184 DLYBx->CR = DLYB_CR_DEN | DLYB_CR_SEN; 00185 DLYBx->CFGR = PhaseSel | (Units << DLYB_CFGR_UNIT_Pos); 00186 DLYBx->CR = DLYB_CR_DEN; 00187 00188 return HAL_OK; 00189 } 00190 00191 00192 /** 00193 * @} 00194 */ 00195 00196 /** 00197 * @} 00198 */ 00199 00200 #endif /* (HAL_SD_MODULE_ENABLED) & (HAL_QSPI_MODULE_ENABLED)*/ 00201 /** 00202 * @} 00203 */ 00204 00205 /** 00206 * @} 00207 */ 00208