You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

211 lines
6.4 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32h7xx_ll_delayblock.c
  4. * @author MCD Application Team
  5. * @brief DelayBlock Low Layer HAL module driver.
  6. *
  7. * This file provides firmware functions to manage the following
  8. * functionalities of the Delay Block peripheral:
  9. * + input clock frequency range 25MHz to 208MHz
  10. * + up to 12 oversampling phases
  11. *
  12. @verbatim
  13. ==============================================================================
  14. ##### DelayBlock peripheral features #####
  15. ==============================================================================
  16. [..] The Delay block is used to generate an Output clock which is de-phased from the Input
  17. clock. The phase of the Output clock is programmed by FW. The Output clock is then used
  18. to clock the receive data in i.e. a SDMMC or QSPI interface.
  19. The delay is Voltage and Temperature dependent, which may require FW to do re-tuning
  20. and recenter the Output clock phase to the receive data.
  21. [..] The Delay Block features include the following:
  22. (+) Input clock frequency range 25MHz to 208MHz.
  23. (+) Up to 12 oversampling phases.
  24. ##### How to use this driver #####
  25. ==============================================================================
  26. [..]
  27. This driver is a considered as a driver of service for external devices drivers
  28. that interfaces with the DELAY peripheral.
  29. The DelayBlock_Enable() function, enables the DelayBlock instance, configure the delay line length
  30. and configure the Output clock phase.
  31. The DelayBlock_Disable() function, disables the DelayBlock instance by setting DEN flag to 0.
  32. @endverbatim
  33. ******************************************************************************
  34. * @attention
  35. *
  36. * <h2><center>&copy; Copyright (c) 2017 STMicroelectronics.
  37. * All rights reserved.</center></h2>
  38. *
  39. * This software component is licensed by ST under BSD 3-Clause license,
  40. * the "License"; You may not use this file except in compliance with the
  41. * License. You may obtain a copy of the License at:
  42. * opensource.org/licenses/BSD-3-Clause
  43. *
  44. ******************************************************************************
  45. */
  46. /* Includes ------------------------------------------------------------------*/
  47. #include "stm32h7xx_hal.h"
  48. /** @addtogroup STM32H7xx_HAL_Driver
  49. * @{
  50. */
  51. /** @defgroup DELAYBLOCK_LL DELAYBLOCK_LL
  52. * @brief Low layer module for Delay Block
  53. * @{
  54. */
  55. #if defined(HAL_SD_MODULE_ENABLED) || defined(HAL_QSPI_MODULE_ENABLED)
  56. /* Private typedef -----------------------------------------------------------*/
  57. /* Private define ------------------------------------------------------------*/
  58. #define DLYB_TIMEOUT 0xFFU
  59. /* Private macro -------------------------------------------------------------*/
  60. /* Private variables ---------------------------------------------------------*/
  61. /* Private function prototypes -----------------------------------------------*/
  62. /* Exported functions --------------------------------------------------------*/
  63. /** @defgroup DelayBlock_LL_Exported_Functions Delay Block Low Layer Exported Functions
  64. * @{
  65. */
  66. /** @defgroup HAL_DELAY_LL_Group1 Initialization de-initialization functions
  67. * @brief Initialization and Configuration functions
  68. *
  69. @verbatim
  70. ===============================================================================
  71. ##### Initialization and de-initialization functions #####
  72. ===============================================================================
  73. [..] This section provides functions allowing to:
  74. @endverbatim
  75. * @{
  76. */
  77. /**
  78. * @brief Enable the Delay Block instance.
  79. * @param DLYBx: Pointer to DLYB instance.
  80. * @retval HAL status
  81. */
  82. HAL_StatusTypeDef DelayBlock_Enable(DLYB_TypeDef *DLYBx)
  83. {
  84. uint32_t unit = 0U;
  85. uint32_t sel = 0U;
  86. uint32_t sel_current;
  87. uint32_t unit_current;
  88. uint32_t tuning;
  89. uint32_t lng_mask;
  90. uint32_t tickstart;
  91. DLYBx->CR = DLYB_CR_DEN | DLYB_CR_SEN;
  92. for (sel_current = 0U; sel_current < DLYB_MAX_SELECT; sel_current++)
  93. {
  94. /* lng_mask is the mask bit for the LNG field to check the output of the UNITx*/
  95. lng_mask = DLYB_CFGR_LNG_0 << sel_current;
  96. tuning = 0U;
  97. for (unit_current = 0U; unit_current < DLYB_MAX_UNIT; unit_current++)
  98. {
  99. /* Set the Delay of the UNIT(s)*/
  100. DLYBx->CFGR = DLYB_MAX_SELECT | (unit_current << DLYB_CFGR_UNIT_Pos);
  101. /* Waiting for a LNG valid value */
  102. tickstart = HAL_GetTick();
  103. while ((DLYBx->CFGR & DLYB_CFGR_LNGF) == 0U)
  104. {
  105. if((HAL_GetTick() - tickstart) >= DLYB_TIMEOUT)
  106. {
  107. return HAL_TIMEOUT;
  108. }
  109. }
  110. if (tuning == 0U)
  111. {
  112. if ((DLYBx->CFGR & lng_mask) != 0U)
  113. {
  114. /* 1/2 period HIGH is detected */
  115. tuning = 1U;
  116. }
  117. }
  118. else
  119. {
  120. /* 1/2 period LOW detected after the HIGH 1/2 period => FULL PERIOD passed*/
  121. if((DLYBx->CFGR & lng_mask ) == 0U)
  122. {
  123. /* Save the first result */
  124. if( unit == 0U )
  125. {
  126. unit = unit_current;
  127. sel = sel_current + 1U;
  128. }
  129. break;
  130. }
  131. }
  132. }
  133. }
  134. /* Apply the Tuning settings */
  135. DLYBx->CR = 0U;
  136. DLYBx->CR = DLYB_CR_DEN | DLYB_CR_SEN;
  137. DLYBx->CFGR = sel | (unit << DLYB_CFGR_UNIT_Pos);
  138. DLYBx->CR = DLYB_CR_DEN;
  139. return HAL_OK;
  140. }
  141. /**
  142. * @brief Disable the Delay Block instance.
  143. * @param DLYBx: Pointer to DLYB instance.
  144. * @retval HAL status
  145. */
  146. HAL_StatusTypeDef DelayBlock_Disable(DLYB_TypeDef *DLYBx)
  147. {
  148. /* Disable DLYB */
  149. DLYBx->CR = 0U;
  150. return HAL_OK;
  151. }
  152. /**
  153. * @brief Configure the Delay Block instance.
  154. * @param DLYBx: Pointer to DLYB instance.
  155. * @param PhaseSel: Phase selection [0..11].
  156. * @param Units: Delay units[0..127].
  157. * @retval HAL status
  158. */
  159. HAL_StatusTypeDef DelayBlock_Configure(DLYB_TypeDef *DLYBx,uint32_t PhaseSel, uint32_t Units )
  160. {
  161. /* Apply the delay settings */
  162. DLYBx->CR = 0U;
  163. DLYBx->CR = DLYB_CR_DEN | DLYB_CR_SEN;
  164. DLYBx->CFGR = PhaseSel | (Units << DLYB_CFGR_UNIT_Pos);
  165. DLYBx->CR = DLYB_CR_DEN;
  166. return HAL_OK;
  167. }
  168. /**
  169. * @}
  170. */
  171. /**
  172. * @}
  173. */
  174. #endif /* (HAL_SD_MODULE_ENABLED) & (HAL_QSPI_MODULE_ENABLED)*/
  175. /**
  176. * @}
  177. */
  178. /**
  179. * @}
  180. */
  181. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/