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.
 
 
 

1313 lines
38 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32h7xx_hal_sdram.c
  4. * @author MCD Application Team
  5. * @brief SDRAM HAL module driver.
  6. * This file provides a generic firmware to drive SDRAM memories mounted
  7. * as external device.
  8. *
  9. @verbatim
  10. ==============================================================================
  11. ##### How to use this driver #####
  12. ==============================================================================
  13. [..]
  14. This driver is a generic layered driver which contains a set of APIs used to
  15. control SDRAM memories. It uses the FMC layer functions to interface
  16. with SDRAM devices.
  17. The following sequence should be followed to configure the FMC to interface
  18. with SDRAM memories:
  19. (#) Declare a SDRAM_HandleTypeDef handle structure, for example:
  20. SDRAM_HandleTypeDef hsdram
  21. (++) Fill the SDRAM_HandleTypeDef handle "Init" field with the allowed
  22. values of the structure member.
  23. (++) Fill the SDRAM_HandleTypeDef handle "Instance" field with a predefined
  24. base register instance for NOR or SDRAM device
  25. (#) Declare a FMC_SDRAM_TimingTypeDef structure; for example:
  26. FMC_SDRAM_TimingTypeDef Timing;
  27. and fill its fields with the allowed values of the structure member.
  28. (#) Initialize the SDRAM Controller by calling the function HAL_SDRAM_Init(). This function
  29. performs the following sequence:
  30. (##) MSP hardware layer configuration using the function HAL_SDRAM_MspInit()
  31. (##) Control register configuration using the FMC SDRAM interface function
  32. FMC_SDRAM_Init()
  33. (##) Timing register configuration using the FMC SDRAM interface function
  34. FMC_SDRAM_Timing_Init()
  35. (##) Program the SDRAM external device by applying its initialization sequence
  36. according to the device plugged in your hardware. This step is mandatory
  37. for accessing the SDRAM device.
  38. (#) At this stage you can perform read/write accesses from/to the memory connected
  39. to the SDRAM Bank. You can perform either polling or DMA transfer using the
  40. following APIs:
  41. (++) HAL_SDRAM_Read()/HAL_SDRAM_Write() for polling read/write access
  42. (++) HAL_SDRAM_Read_DMA()/HAL_SDRAM_Write_DMA() for DMA read/write transfer
  43. (#) You can also control the SDRAM device by calling the control APIs HAL_SDRAM_WriteOperation_Enable()/
  44. HAL_SDRAM_WriteOperation_Disable() to respectively enable/disable the SDRAM write operation or
  45. the function HAL_SDRAM_SendCommand() to send a specified command to the SDRAM
  46. device. The command to be sent must be configured with the FMC_SDRAM_CommandTypeDef
  47. structure.
  48. (#) You can continuously monitor the SDRAM device HAL state by calling the function
  49. HAL_SDRAM_GetState()
  50. *** Callback registration ***
  51. =============================================
  52. [..]
  53. The compilation define USE_HAL_SDRAM_REGISTER_CALLBACKS when set to 1
  54. allows the user to configure dynamically the driver callbacks.
  55. Use Functions @ref HAL_SDRAM_RegisterCallback() to register a user callback,
  56. it allows to register following callbacks:
  57. (+) MspInitCallback : SDRAM MspInit.
  58. (+) MspDeInitCallback : SDRAM MspDeInit.
  59. This function takes as parameters the HAL peripheral handle, the Callback ID
  60. and a pointer to the user callback function.
  61. Use function @ref HAL_SDRAM_UnRegisterCallback() to reset a callback to the default
  62. weak (surcharged) function. It allows to reset following callbacks:
  63. (+) MspInitCallback : SDRAM MspInit.
  64. (+) MspDeInitCallback : SDRAM MspDeInit.
  65. This function) takes as parameters the HAL peripheral handle and the Callback ID.
  66. By default, after the @ref HAL_SDRAM_Init and if the state is HAL_SDRAM_STATE_RESET
  67. all callbacks are reset to the corresponding legacy weak (surcharged) functions.
  68. Exception done for MspInit and MspDeInit callbacks that are respectively
  69. reset to the legacy weak (surcharged) functions in the @ref HAL_SDRAM_Init
  70. and @ref HAL_SDRAM_DeInit only when these callbacks are null (not registered beforehand).
  71. If not, MspInit or MspDeInit are not null, the @ref HAL_SDRAM_Init and @ref HAL_SDRAM_DeInit
  72. keep and use the user MspInit/MspDeInit callbacks (registered beforehand)
  73. Callbacks can be registered/unregistered in READY state only.
  74. Exception done for MspInit/MspDeInit callbacks that can be registered/unregistered
  75. in READY or RESET state, thus registered (user) MspInit/DeInit callbacks can be used
  76. during the Init/DeInit.
  77. In that case first register the MspInit/MspDeInit user callbacks
  78. using @ref HAL_SDRAM_RegisterCallback before calling @ref HAL_SDRAM_DeInit
  79. or @ref HAL_SDRAM_Init function.
  80. When The compilation define USE_HAL_SDRAM_REGISTER_CALLBACKS is set to 0 or
  81. not defined, the callback registering feature is not available
  82. and weak (surcharged) callbacks are used.
  83. @endverbatim
  84. ******************************************************************************
  85. * @attention
  86. *
  87. * <h2><center>&copy; Copyright (c) 2017 STMicroelectronics.
  88. * All rights reserved.</center></h2>
  89. *
  90. * This software component is licensed by ST under BSD 3-Clause license,
  91. * the "License"; You may not use this file except in compliance with the
  92. * License. You may obtain a copy of the License at:
  93. * opensource.org/licenses/BSD-3-Clause
  94. *
  95. ******************************************************************************
  96. */
  97. /* Includes ------------------------------------------------------------------*/
  98. #include "stm32h7xx_hal.h"
  99. /** @addtogroup STM32H7xx_HAL_Driver
  100. * @{
  101. */
  102. #ifdef HAL_SDRAM_MODULE_ENABLED
  103. /** @defgroup SDRAM SDRAM
  104. * @brief SDRAM driver modules
  105. * @{
  106. */
  107. /**
  108. @cond 0
  109. */
  110. /* Private typedef -----------------------------------------------------------*/
  111. /* Private define ------------------------------------------------------------*/
  112. /* Private macro -------------------------------------------------------------*/
  113. /* Private variables ---------------------------------------------------------*/
  114. /* Private function prototypes -----------------------------------------------*/
  115. static void SDRAM_DMACplt (MDMA_HandleTypeDef *hmdma);
  116. static void SDRAM_DMACpltProt(MDMA_HandleTypeDef *hmdma);
  117. static void SDRAM_DMAError (MDMA_HandleTypeDef *hmdma);
  118. /**
  119. @endcond
  120. */
  121. /* Exported functions --------------------------------------------------------*/
  122. /** @defgroup SDRAM_Exported_Functions SDRAM Exported Functions
  123. * @{
  124. */
  125. /** @defgroup SDRAM_Exported_Functions_Group1 Initialization and de-initialization functions
  126. * @brief Initialization and Configuration functions
  127. *
  128. @verbatim
  129. ==============================================================================
  130. ##### SDRAM Initialization and de_initialization functions #####
  131. ==============================================================================
  132. [..]
  133. This section provides functions allowing to initialize/de-initialize
  134. the SDRAM memory
  135. @endverbatim
  136. * @{
  137. */
  138. /**
  139. * @brief Performs the SDRAM device initialization sequence.
  140. * @param hsdram pointer to a SDRAM_HandleTypeDef structure that contains
  141. * the configuration information for SDRAM module.
  142. * @param Timing Pointer to SDRAM control timing structure
  143. * @retval HAL status
  144. */
  145. HAL_StatusTypeDef HAL_SDRAM_Init(SDRAM_HandleTypeDef *hsdram, FMC_SDRAM_TimingTypeDef *Timing)
  146. {
  147. /* Check the SDRAM handle parameter */
  148. if (hsdram == NULL)
  149. {
  150. return HAL_ERROR;
  151. }
  152. if (hsdram->State == HAL_SDRAM_STATE_RESET)
  153. {
  154. /* Allocate lock resource and initialize it */
  155. hsdram->Lock = HAL_UNLOCKED;
  156. #if (USE_HAL_SDRAM_REGISTER_CALLBACKS == 1)
  157. if(hsdram->MspInitCallback == NULL)
  158. {
  159. hsdram->MspInitCallback = HAL_SDRAM_MspInit;
  160. }
  161. hsdram->RefreshErrorCallback = HAL_SDRAM_RefreshErrorCallback;
  162. hsdram->DmaXferCpltCallback = HAL_SDRAM_DMA_XferCpltCallback;
  163. hsdram->DmaXferErrorCallback = HAL_SDRAM_DMA_XferErrorCallback;
  164. /* Init the low level hardware */
  165. hsdram->MspInitCallback(hsdram);
  166. #else
  167. /* Initialize the low level hardware (MSP) */
  168. HAL_SDRAM_MspInit(hsdram);
  169. #endif
  170. }
  171. /* Initialize the SDRAM controller state */
  172. hsdram->State = HAL_SDRAM_STATE_BUSY;
  173. /* Initialize SDRAM control Interface */
  174. (void)FMC_SDRAM_Init(hsdram->Instance, &(hsdram->Init));
  175. /* Initialize SDRAM timing Interface */
  176. (void)FMC_SDRAM_Timing_Init(hsdram->Instance, Timing, hsdram->Init.SDBank);
  177. /* Enable FMC Peripheral */
  178. __FMC_ENABLE();
  179. /* Update the SDRAM controller state */
  180. hsdram->State = HAL_SDRAM_STATE_READY;
  181. return HAL_OK;
  182. }
  183. /**
  184. * @brief Perform the SDRAM device initialization sequence.
  185. * @param hsdram pointer to a SDRAM_HandleTypeDef structure that contains
  186. * the configuration information for SDRAM module.
  187. * @retval HAL status
  188. */
  189. HAL_StatusTypeDef HAL_SDRAM_DeInit(SDRAM_HandleTypeDef *hsdram)
  190. {
  191. #if (USE_HAL_SDRAM_REGISTER_CALLBACKS == 1)
  192. if(hsdram->MspDeInitCallback == NULL)
  193. {
  194. hsdram->MspDeInitCallback = HAL_SDRAM_MspDeInit;
  195. }
  196. /* DeInit the low level hardware */
  197. hsdram->MspDeInitCallback(hsdram);
  198. #else
  199. /* Initialize the low level hardware (MSP) */
  200. HAL_SDRAM_MspDeInit(hsdram);
  201. #endif
  202. /* Configure the SDRAM registers with their reset values */
  203. (void)FMC_SDRAM_DeInit(hsdram->Instance, hsdram->Init.SDBank);
  204. /* Reset the SDRAM controller state */
  205. hsdram->State = HAL_SDRAM_STATE_RESET;
  206. /* Release Lock */
  207. __HAL_UNLOCK(hsdram);
  208. return HAL_OK;
  209. }
  210. /**
  211. * @brief SDRAM MSP Init.
  212. * @param hsdram pointer to a SDRAM_HandleTypeDef structure that contains
  213. * the configuration information for SDRAM module.
  214. * @retval None
  215. */
  216. __weak void HAL_SDRAM_MspInit(SDRAM_HandleTypeDef *hsdram)
  217. {
  218. /* Prevent unused argument(s) compilation warning */
  219. UNUSED(hsdram);
  220. /* NOTE: This function Should not be modified, when the callback is needed,
  221. the HAL_SDRAM_MspInit could be implemented in the user file
  222. */
  223. }
  224. /**
  225. * @brief SDRAM MSP DeInit.
  226. * @param hsdram pointer to a SDRAM_HandleTypeDef structure that contains
  227. * the configuration information for SDRAM module.
  228. * @retval None
  229. */
  230. __weak void HAL_SDRAM_MspDeInit(SDRAM_HandleTypeDef *hsdram)
  231. {
  232. /* Prevent unused argument(s) compilation warning */
  233. UNUSED(hsdram);
  234. /* NOTE: This function Should not be modified, when the callback is needed,
  235. the HAL_SDRAM_MspDeInit could be implemented in the user file
  236. */
  237. }
  238. /**
  239. * @brief This function handles SDRAM refresh error interrupt request.
  240. * @param hsdram pointer to a SDRAM_HandleTypeDef structure that contains
  241. * the configuration information for SDRAM module.
  242. * @retval HAL status
  243. */
  244. void HAL_SDRAM_IRQHandler(SDRAM_HandleTypeDef *hsdram)
  245. {
  246. /* Check SDRAM interrupt Rising edge flag */
  247. if (__FMC_SDRAM_GET_FLAG(hsdram->Instance, FMC_SDRAM_FLAG_REFRESH_IT))
  248. {
  249. /* SDRAM refresh error interrupt callback */
  250. #if (USE_HAL_SDRAM_REGISTER_CALLBACKS == 1)
  251. hsdram->RefreshErrorCallback(hsdram);
  252. #else
  253. HAL_SDRAM_RefreshErrorCallback(hsdram);
  254. #endif
  255. /* Clear SDRAM refresh error interrupt pending bit */
  256. __FMC_SDRAM_CLEAR_FLAG(hsdram->Instance, FMC_SDRAM_FLAG_REFRESH_ERROR);
  257. }
  258. }
  259. /**
  260. * @brief SDRAM Refresh error callback.
  261. * @param hsdram pointer to a SDRAM_HandleTypeDef structure that contains
  262. * the configuration information for SDRAM module.
  263. * @retval None
  264. */
  265. __weak void HAL_SDRAM_RefreshErrorCallback(SDRAM_HandleTypeDef *hsdram)
  266. {
  267. /* Prevent unused argument(s) compilation warning */
  268. UNUSED(hsdram);
  269. /* NOTE: This function Should not be modified, when the callback is needed,
  270. the HAL_SDRAM_RefreshErrorCallback could be implemented in the user file
  271. */
  272. }
  273. /**
  274. * @brief DMA transfer complete callback.
  275. * @param hmdma pointer to a DMA_HandleTypeDef structure that contains
  276. * the configuration information for the specified DMA module.
  277. * @retval None
  278. */
  279. __weak void HAL_SDRAM_DMA_XferCpltCallback(MDMA_HandleTypeDef *hmdma)
  280. {
  281. /* Prevent unused argument(s) compilation warning */
  282. UNUSED(hmdma);
  283. /* NOTE: This function Should not be modified, when the callback is needed,
  284. the HAL_SDRAM_DMA_XferCpltCallback could be implemented in the user file
  285. */
  286. }
  287. /**
  288. * @brief DMA transfer complete error callback.
  289. * @param hmdma DMA handle
  290. * @retval None
  291. */
  292. __weak void HAL_SDRAM_DMA_XferErrorCallback(MDMA_HandleTypeDef *hmdma)
  293. {
  294. /* Prevent unused argument(s) compilation warning */
  295. UNUSED(hmdma);
  296. /* NOTE: This function Should not be modified, when the callback is needed,
  297. the HAL_SDRAM_DMA_XferErrorCallback could be implemented in the user file
  298. */
  299. }
  300. /**
  301. * @}
  302. */
  303. /** @defgroup SDRAM_Exported_Functions_Group2 Input and Output functions
  304. * @brief Input Output and memory control functions
  305. *
  306. @verbatim
  307. ==============================================================================
  308. ##### SDRAM Input and Output functions #####
  309. ==============================================================================
  310. [..]
  311. This section provides functions allowing to use and control the SDRAM memory
  312. @endverbatim
  313. * @{
  314. */
  315. /**
  316. * @brief Reads 8-bit data buffer from the SDRAM memory.
  317. * @param hsdram pointer to a SDRAM_HandleTypeDef structure that contains
  318. * the configuration information for SDRAM module.
  319. * @param pAddress Pointer to read start address
  320. * @param pDstBuffer Pointer to destination buffer
  321. * @param BufferSize Size of the buffer to read from memory
  322. * @retval HAL status
  323. */
  324. HAL_StatusTypeDef HAL_SDRAM_Read_8b(SDRAM_HandleTypeDef *hsdram, uint32_t *pAddress, uint8_t *pDstBuffer, uint32_t BufferSize)
  325. {
  326. uint32_t size;
  327. __IO uint8_t *pSdramAddress = (uint8_t *)pAddress;
  328. uint8_t * pdestbuff = pDstBuffer;
  329. HAL_SDRAM_StateTypeDef state = hsdram->State;
  330. /* Check the SDRAM controller state */
  331. if (state == HAL_SDRAM_STATE_BUSY)
  332. {
  333. return HAL_BUSY;
  334. }
  335. else if ((state == HAL_SDRAM_STATE_READY) || (state == HAL_SDRAM_STATE_WRITE_PROTECTED))
  336. {
  337. /* Process Locked */
  338. __HAL_LOCK(hsdram);
  339. /* Update the SDRAM controller state */
  340. hsdram->State = HAL_SDRAM_STATE_BUSY;
  341. /* Read data from source */
  342. for (size = BufferSize; size != 0U; size--)
  343. {
  344. *pdestbuff = *(__IO uint8_t *)pSdramAddress;
  345. pdestbuff++;
  346. pSdramAddress++;
  347. }
  348. /* Update the SDRAM controller state */
  349. hsdram->State = state;
  350. /* Process Unlocked */
  351. __HAL_UNLOCK(hsdram);
  352. }
  353. else
  354. {
  355. return HAL_ERROR;
  356. }
  357. return HAL_OK;
  358. }
  359. /**
  360. * @brief Writes 8-bit data buffer to SDRAM memory.
  361. * @param hsdram pointer to a SDRAM_HandleTypeDef structure that contains
  362. * the configuration information for SDRAM module.
  363. * @param pAddress Pointer to write start address
  364. * @param pSrcBuffer Pointer to source buffer to write
  365. * @param BufferSize Size of the buffer to write to memory
  366. * @retval HAL status
  367. */
  368. HAL_StatusTypeDef HAL_SDRAM_Write_8b(SDRAM_HandleTypeDef *hsdram, uint32_t *pAddress, uint8_t *pSrcBuffer, uint32_t BufferSize)
  369. {
  370. uint32_t size;
  371. __IO uint8_t *pSdramAddress = (uint8_t *)pAddress;
  372. uint8_t * psrcbuff = pSrcBuffer;
  373. /* Check the SDRAM controller state */
  374. if (hsdram->State == HAL_SDRAM_STATE_BUSY)
  375. {
  376. return HAL_BUSY;
  377. }
  378. else if (hsdram->State == HAL_SDRAM_STATE_READY)
  379. {
  380. /* Process Locked */
  381. __HAL_LOCK(hsdram);
  382. /* Update the SDRAM controller state */
  383. hsdram->State = HAL_SDRAM_STATE_BUSY;
  384. /* Write data to memory */
  385. for (size = BufferSize; size != 0U; size--)
  386. {
  387. *(__IO uint8_t *)pSdramAddress = *psrcbuff;
  388. psrcbuff++;
  389. pSdramAddress++;
  390. }
  391. /* Update the SDRAM controller state */
  392. hsdram->State = HAL_SDRAM_STATE_READY;
  393. /* Process Unlocked */
  394. __HAL_UNLOCK(hsdram);
  395. }
  396. else
  397. {
  398. return HAL_ERROR;
  399. }
  400. return HAL_OK;
  401. }
  402. /**
  403. * @brief Reads 16-bit data buffer from the SDRAM memory.
  404. * @param hsdram pointer to a SDRAM_HandleTypeDef structure that contains
  405. * the configuration information for SDRAM module.
  406. * @param pAddress Pointer to read start address
  407. * @param pDstBuffer Pointer to destination buffer
  408. * @param BufferSize Size of the buffer to read from memory
  409. * @retval HAL status
  410. */
  411. HAL_StatusTypeDef HAL_SDRAM_Read_16b(SDRAM_HandleTypeDef *hsdram, uint32_t *pAddress, uint16_t *pDstBuffer, uint32_t BufferSize)
  412. {
  413. uint32_t size;
  414. __IO uint32_t *pSdramAddress = pAddress;
  415. uint16_t *pdestbuff = pDstBuffer;
  416. HAL_SDRAM_StateTypeDef state = hsdram->State;
  417. /* Check the SDRAM controller state */
  418. if (state == HAL_SDRAM_STATE_BUSY)
  419. {
  420. return HAL_BUSY;
  421. }
  422. else if ((state == HAL_SDRAM_STATE_READY) || (state == HAL_SDRAM_STATE_WRITE_PROTECTED))
  423. {
  424. /* Process Locked */
  425. __HAL_LOCK(hsdram);
  426. /* Update the SDRAM controller state */
  427. hsdram->State = HAL_SDRAM_STATE_BUSY;
  428. /* Read data from memory */
  429. for (size = BufferSize; size >= 2U ; size-=2U)
  430. {
  431. *pdestbuff = (uint16_t)((*pSdramAddress) & 0x0000FFFFU);
  432. pdestbuff++;
  433. *pdestbuff = (uint16_t)(((*pSdramAddress) & 0xFFFF0000U) >> 16U);
  434. pdestbuff++;
  435. pSdramAddress++;
  436. }
  437. /* Read last 16-bits if size is not 32-bits multiple */
  438. if ((BufferSize % 2U)!= 0U)
  439. {
  440. *pdestbuff = (uint16_t)((*pSdramAddress) & 0x0000FFFFU);
  441. }
  442. /* Update the SDRAM controller state */
  443. hsdram->State = state;
  444. /* Process Unlocked */
  445. __HAL_UNLOCK(hsdram);
  446. }
  447. else
  448. {
  449. return HAL_ERROR;
  450. }
  451. return HAL_OK;
  452. }
  453. /**
  454. * @brief Writes 16-bit data buffer to SDRAM memory.
  455. * @param hsdram pointer to a SDRAM_HandleTypeDef structure that contains
  456. * the configuration information for SDRAM module.
  457. * @param pAddress Pointer to write start address
  458. * @param pSrcBuffer Pointer to source buffer to write
  459. * @param BufferSize Size of the buffer to write to memory
  460. * @retval HAL status
  461. */
  462. HAL_StatusTypeDef HAL_SDRAM_Write_16b(SDRAM_HandleTypeDef *hsdram, uint32_t *pAddress, uint16_t *pSrcBuffer, uint32_t BufferSize)
  463. {
  464. uint32_t size;
  465. __IO uint32_t *psdramaddress = pAddress;
  466. uint16_t * psrcbuff = pSrcBuffer;
  467. /* Check the SDRAM controller state */
  468. if (hsdram->State == HAL_SDRAM_STATE_BUSY)
  469. {
  470. return HAL_BUSY;
  471. }
  472. else if (hsdram->State == HAL_SDRAM_STATE_READY)
  473. {
  474. /* Process Locked */
  475. __HAL_LOCK(hsdram);
  476. /* Update the SDRAM controller state */
  477. hsdram->State = HAL_SDRAM_STATE_BUSY;
  478. /* Write data to memory */
  479. for (size = BufferSize; size >= 2U ; size-=2U)
  480. {
  481. *psdramaddress = (uint32_t)(*psrcbuff);
  482. psrcbuff++;
  483. *psdramaddress |= ((uint32_t)(*psrcbuff) << 16U);
  484. psrcbuff++;
  485. psdramaddress++;
  486. }
  487. /* Write last 16-bits if size is not 32-bits multiple */
  488. if ((BufferSize % 2U)!= 0U)
  489. {
  490. *psdramaddress = ((uint32_t)(*psrcbuff) & 0x0000FFFFU) | ((*psdramaddress) & 0xFFFF0000U);
  491. }
  492. /* Update the SDRAM controller state */
  493. hsdram->State = HAL_SDRAM_STATE_READY;
  494. /* Process Unlocked */
  495. __HAL_UNLOCK(hsdram);
  496. }
  497. else
  498. {
  499. return HAL_ERROR;
  500. }
  501. return HAL_OK;
  502. }
  503. /**
  504. * @brief Reads 32-bit data buffer from the SDRAM memory.
  505. * @param hsdram pointer to a SDRAM_HandleTypeDef structure that contains
  506. * the configuration information for SDRAM module.
  507. * @param pAddress Pointer to read start address
  508. * @param pDstBuffer Pointer to destination buffer
  509. * @param BufferSize Size of the buffer to read from memory
  510. * @retval HAL status
  511. */
  512. HAL_StatusTypeDef HAL_SDRAM_Read_32b(SDRAM_HandleTypeDef *hsdram, uint32_t *pAddress, uint32_t *pDstBuffer, uint32_t BufferSize)
  513. {
  514. uint32_t size;
  515. __IO uint32_t *pSdramAddress = (uint32_t *)pAddress;
  516. uint32_t * pdestbuff = pDstBuffer;
  517. HAL_SDRAM_StateTypeDef state = hsdram->State;
  518. /* Check the SDRAM controller state */
  519. if (state == HAL_SDRAM_STATE_BUSY)
  520. {
  521. return HAL_BUSY;
  522. }
  523. else if ((state == HAL_SDRAM_STATE_READY) || (state == HAL_SDRAM_STATE_WRITE_PROTECTED))
  524. {
  525. /* Process Locked */
  526. __HAL_LOCK(hsdram);
  527. /* Update the SDRAM controller state */
  528. hsdram->State = HAL_SDRAM_STATE_BUSY;
  529. /* Read data from source */
  530. for (size = BufferSize; size != 0U; size--)
  531. {
  532. *pdestbuff = *(__IO uint32_t *)pSdramAddress;
  533. pdestbuff++;
  534. pSdramAddress++;
  535. }
  536. /* Update the SDRAM controller state */
  537. hsdram->State = state;
  538. /* Process Unlocked */
  539. __HAL_UNLOCK(hsdram);
  540. }
  541. else
  542. {
  543. return HAL_ERROR;
  544. }
  545. return HAL_OK;
  546. }
  547. /**
  548. * @brief Writes 32-bit data buffer to SDRAM memory.
  549. * @param hsdram pointer to a SDRAM_HandleTypeDef structure that contains
  550. * the configuration information for SDRAM module.
  551. * @param pAddress Pointer to write start address
  552. * @param pSrcBuffer Pointer to source buffer to write
  553. * @param BufferSize Size of the buffer to write to memory
  554. * @retval HAL status
  555. */
  556. HAL_StatusTypeDef HAL_SDRAM_Write_32b(SDRAM_HandleTypeDef *hsdram, uint32_t *pAddress, uint32_t *pSrcBuffer, uint32_t BufferSize)
  557. {
  558. uint32_t size;
  559. __IO uint32_t *pSdramAddress = pAddress;
  560. uint32_t * psrcbuff = pSrcBuffer;
  561. /* Check the SDRAM controller state */
  562. if (hsdram->State == HAL_SDRAM_STATE_BUSY)
  563. {
  564. return HAL_BUSY;
  565. }
  566. else if (hsdram->State == HAL_SDRAM_STATE_READY)
  567. {
  568. /* Process Locked */
  569. __HAL_LOCK(hsdram);
  570. /* Update the SDRAM controller state */
  571. hsdram->State = HAL_SDRAM_STATE_BUSY;
  572. /* Write data to memory */
  573. for (size = BufferSize; size != 0U; size--)
  574. {
  575. *pSdramAddress = *psrcbuff;
  576. psrcbuff++;
  577. pSdramAddress++;
  578. }
  579. /* Update the SDRAM controller state */
  580. hsdram->State = HAL_SDRAM_STATE_READY;
  581. /* Process Unlocked */
  582. __HAL_UNLOCK(hsdram);
  583. }
  584. else
  585. {
  586. return HAL_ERROR;
  587. }
  588. return HAL_OK;
  589. }
  590. /**
  591. * @brief Reads a Words data from the SDRAM memory using DMA transfer.
  592. * @param hsdram pointer to a SDRAM_HandleTypeDef structure that contains
  593. * the configuration information for SDRAM module.
  594. * @param pAddress Pointer to read start address
  595. * @param pDstBuffer Pointer to destination buffer
  596. * @param BufferSize Size of the buffer to read from memory
  597. * @retval HAL status
  598. */
  599. HAL_StatusTypeDef HAL_SDRAM_Read_DMA(SDRAM_HandleTypeDef *hsdram, uint32_t *pAddress, uint32_t *pDstBuffer, uint32_t BufferSize)
  600. {
  601. HAL_StatusTypeDef status;
  602. HAL_SDRAM_StateTypeDef state = hsdram->State;
  603. /* Check the SDRAM controller state */
  604. if (state == HAL_SDRAM_STATE_BUSY)
  605. {
  606. return HAL_BUSY;
  607. }
  608. else if ((state == HAL_SDRAM_STATE_READY) || (state == HAL_SDRAM_STATE_WRITE_PROTECTED))
  609. {
  610. /* Process Locked */
  611. __HAL_LOCK(hsdram);
  612. /* Update the SDRAM controller state */
  613. hsdram->State = HAL_SDRAM_STATE_BUSY;
  614. /* Configure DMA user callbacks */
  615. if (state == HAL_SDRAM_STATE_READY)
  616. {
  617. hsdram->hmdma->XferCpltCallback = SDRAM_DMACplt;
  618. }
  619. else
  620. {
  621. hsdram->hmdma->XferCpltCallback = SDRAM_DMACpltProt;
  622. }
  623. hsdram->hmdma->XferErrorCallback = SDRAM_DMAError;
  624. /* Enable the DMA Stream */
  625. status = HAL_MDMA_Start_IT(hsdram->hmdma, (uint32_t)pAddress, (uint32_t)pDstBuffer, (uint32_t)(BufferSize * 4U), 1);
  626. /* Process Unlocked */
  627. __HAL_UNLOCK(hsdram);
  628. }
  629. else
  630. {
  631. return HAL_ERROR;
  632. }
  633. return status;
  634. }
  635. /**
  636. * @brief Writes a Words data buffer to SDRAM memory using DMA transfer.
  637. * @param hsdram pointer to a SDRAM_HandleTypeDef structure that contains
  638. * the configuration information for SDRAM module.
  639. * @param pAddress Pointer to write start address
  640. * @param pSrcBuffer Pointer to source buffer to write
  641. * @param BufferSize Size of the buffer to write to memory
  642. * @retval HAL status
  643. */
  644. HAL_StatusTypeDef HAL_SDRAM_Write_DMA(SDRAM_HandleTypeDef *hsdram, uint32_t *pAddress, uint32_t *pSrcBuffer, uint32_t BufferSize)
  645. {
  646. HAL_StatusTypeDef status;
  647. /* Check the SDRAM controller state */
  648. if (hsdram->State == HAL_SDRAM_STATE_BUSY)
  649. {
  650. return HAL_BUSY;
  651. }
  652. else if (hsdram->State == HAL_SDRAM_STATE_READY)
  653. {
  654. /* Process Locked */
  655. __HAL_LOCK(hsdram);
  656. /* Update the SDRAM controller state */
  657. hsdram->State = HAL_SDRAM_STATE_BUSY;
  658. /* Configure DMA user callbacks */
  659. hsdram->hmdma->XferCpltCallback = SDRAM_DMACplt;
  660. hsdram->hmdma->XferErrorCallback = SDRAM_DMAError;
  661. /* Enable the DMA Stream */
  662. status = HAL_MDMA_Start_IT(hsdram->hmdma, (uint32_t)pSrcBuffer, (uint32_t)pAddress, (uint32_t)(BufferSize * 4U), 1);
  663. /* Process Unlocked */
  664. __HAL_UNLOCK(hsdram);
  665. }
  666. else
  667. {
  668. return HAL_ERROR;
  669. }
  670. return status;
  671. }
  672. #if (USE_HAL_SDRAM_REGISTER_CALLBACKS == 1)
  673. /**
  674. * @brief Register a User SDRAM Callback
  675. * To be used instead of the weak (surcharged) predefined callback
  676. * @param hsdram : SDRAM handle
  677. * @param CallbackId : ID of the callback to be registered
  678. * This parameter can be one of the following values:
  679. * @arg @ref HAL_SDRAM_MSP_INIT_CB_ID SDRAM MspInit callback ID
  680. * @arg @ref HAL_SDRAM_MSP_DEINIT_CB_ID SDRAM MspDeInit callback ID
  681. * @arg @ref HAL_SDRAM_REFRESH_ERR_CB_ID SDRAM Refresh Error callback ID
  682. * @param pCallback : pointer to the Callback function
  683. * @retval status
  684. */
  685. HAL_StatusTypeDef HAL_SDRAM_RegisterCallback (SDRAM_HandleTypeDef *hsdram, HAL_SDRAM_CallbackIDTypeDef CallbackId, pSDRAM_CallbackTypeDef pCallback)
  686. {
  687. HAL_StatusTypeDef status = HAL_OK;
  688. HAL_SDRAM_StateTypeDef state;
  689. if(pCallback == NULL)
  690. {
  691. return HAL_ERROR;
  692. }
  693. /* Process locked */
  694. __HAL_LOCK(hsdram);
  695. state = hsdram->State;
  696. if((state == HAL_SDRAM_STATE_READY) || (state == HAL_SDRAM_STATE_WRITE_PROTECTED))
  697. {
  698. switch (CallbackId)
  699. {
  700. case HAL_SDRAM_MSP_INIT_CB_ID :
  701. hsdram->MspInitCallback = pCallback;
  702. break;
  703. case HAL_SDRAM_MSP_DEINIT_CB_ID :
  704. hsdram->MspDeInitCallback = pCallback;
  705. break;
  706. case HAL_SDRAM_REFRESH_ERR_CB_ID :
  707. hsdram->RefreshErrorCallback = pCallback;
  708. break;
  709. default :
  710. /* update return status */
  711. status = HAL_ERROR;
  712. break;
  713. }
  714. }
  715. else if(hsdram->State == HAL_SDRAM_STATE_RESET)
  716. {
  717. switch (CallbackId)
  718. {
  719. case HAL_SDRAM_MSP_INIT_CB_ID :
  720. hsdram->MspInitCallback = pCallback;
  721. break;
  722. case HAL_SDRAM_MSP_DEINIT_CB_ID :
  723. hsdram->MspDeInitCallback = pCallback;
  724. break;
  725. default :
  726. /* update return status */
  727. status = HAL_ERROR;
  728. break;
  729. }
  730. }
  731. else
  732. {
  733. /* update return status */
  734. status = HAL_ERROR;
  735. }
  736. /* Release Lock */
  737. __HAL_UNLOCK(hsdram);
  738. return status;
  739. }
  740. /**
  741. * @brief Unregister a User SDRAM Callback
  742. * SDRAM Callback is redirected to the weak (surcharged) predefined callback
  743. * @param hsdram : SDRAM handle
  744. * @param CallbackId : ID of the callback to be unregistered
  745. * This parameter can be one of the following values:
  746. * @arg @ref HAL_SDRAM_MSP_INIT_CB_ID SDRAM MspInit callback ID
  747. * @arg @ref HAL_SDRAM_MSP_DEINIT_CB_ID SDRAM MspDeInit callback ID
  748. * @arg @ref HAL_SDRAM_REFRESH_ERR_CB_ID SDRAM Refresh Error callback ID
  749. * @arg @ref HAL_SDRAM_DMA_XFER_CPLT_CB_ID SDRAM DMA Xfer Complete callback ID
  750. * @arg @ref HAL_SDRAM_DMA_XFER_ERR_CB_ID SDRAM DMA Xfer Error callback ID
  751. * @retval status
  752. */
  753. HAL_StatusTypeDef HAL_SDRAM_UnRegisterCallback (SDRAM_HandleTypeDef *hsdram, HAL_SDRAM_CallbackIDTypeDef CallbackId)
  754. {
  755. HAL_StatusTypeDef status = HAL_OK;
  756. HAL_SDRAM_StateTypeDef state;
  757. /* Process locked */
  758. __HAL_LOCK(hsdram);
  759. state = hsdram->State;
  760. if((state == HAL_SDRAM_STATE_READY) || (state == HAL_SDRAM_STATE_WRITE_PROTECTED))
  761. {
  762. switch (CallbackId)
  763. {
  764. case HAL_SDRAM_MSP_INIT_CB_ID :
  765. hsdram->MspInitCallback = HAL_SDRAM_MspInit;
  766. break;
  767. case HAL_SDRAM_MSP_DEINIT_CB_ID :
  768. hsdram->MspDeInitCallback = HAL_SDRAM_MspDeInit;
  769. break;
  770. case HAL_SDRAM_REFRESH_ERR_CB_ID :
  771. hsdram->RefreshErrorCallback = HAL_SDRAM_RefreshErrorCallback;
  772. break;
  773. case HAL_SDRAM_DMA_XFER_CPLT_CB_ID :
  774. hsdram->DmaXferCpltCallback = HAL_SDRAM_DMA_XferCpltCallback;
  775. break;
  776. case HAL_SDRAM_DMA_XFER_ERR_CB_ID :
  777. hsdram->DmaXferErrorCallback = HAL_SDRAM_DMA_XferErrorCallback;
  778. break;
  779. default :
  780. /* update return status */
  781. status = HAL_ERROR;
  782. break;
  783. }
  784. }
  785. else if(hsdram->State == HAL_SDRAM_STATE_RESET)
  786. {
  787. switch (CallbackId)
  788. {
  789. case HAL_SDRAM_MSP_INIT_CB_ID :
  790. hsdram->MspInitCallback = HAL_SDRAM_MspInit;
  791. break;
  792. case HAL_SDRAM_MSP_DEINIT_CB_ID :
  793. hsdram->MspDeInitCallback = HAL_SDRAM_MspDeInit;
  794. break;
  795. default :
  796. /* update return status */
  797. status = HAL_ERROR;
  798. break;
  799. }
  800. }
  801. else
  802. {
  803. /* update return status */
  804. status = HAL_ERROR;
  805. }
  806. /* Release Lock */
  807. __HAL_UNLOCK(hsdram);
  808. return status;
  809. }
  810. /**
  811. * @brief Register a User SDRAM Callback for DMA transfers
  812. * To be used instead of the weak (surcharged) predefined callback
  813. * @param hsdram : SDRAM handle
  814. * @param CallbackId : ID of the callback to be registered
  815. * This parameter can be one of the following values:
  816. * @arg @ref HAL_SDRAM_DMA_XFER_CPLT_CB_ID SDRAM DMA Xfer Complete callback ID
  817. * @arg @ref HAL_SDRAM_DMA_XFER_ERR_CB_ID SDRAM DMA Xfer Error callback ID
  818. * @param pCallback : pointer to the Callback function
  819. * @retval status
  820. */
  821. HAL_StatusTypeDef HAL_SDRAM_RegisterDmaCallback(SDRAM_HandleTypeDef *hsdram, HAL_SDRAM_CallbackIDTypeDef CallbackId, pSDRAM_DmaCallbackTypeDef pCallback)
  822. {
  823. HAL_StatusTypeDef status = HAL_OK;
  824. HAL_SDRAM_StateTypeDef state;
  825. if(pCallback == NULL)
  826. {
  827. return HAL_ERROR;
  828. }
  829. /* Process locked */
  830. __HAL_LOCK(hsdram);
  831. state = hsdram->State;
  832. if((state == HAL_SDRAM_STATE_READY) || (state == HAL_SDRAM_STATE_WRITE_PROTECTED))
  833. {
  834. switch (CallbackId)
  835. {
  836. case HAL_SDRAM_DMA_XFER_CPLT_CB_ID :
  837. hsdram->DmaXferCpltCallback = pCallback;
  838. break;
  839. case HAL_SDRAM_DMA_XFER_ERR_CB_ID :
  840. hsdram->DmaXferErrorCallback = pCallback;
  841. break;
  842. default :
  843. /* update return status */
  844. status = HAL_ERROR;
  845. break;
  846. }
  847. }
  848. else
  849. {
  850. /* update return status */
  851. status = HAL_ERROR;
  852. }
  853. /* Release Lock */
  854. __HAL_UNLOCK(hsdram);
  855. return status;
  856. }
  857. #endif
  858. /**
  859. * @}
  860. */
  861. /** @defgroup SDRAM_Exported_Functions_Group3 Control functions
  862. * @brief management functions
  863. *
  864. @verbatim
  865. ==============================================================================
  866. ##### SDRAM Control functions #####
  867. ==============================================================================
  868. [..]
  869. This subsection provides a set of functions allowing to control dynamically
  870. the SDRAM interface.
  871. @endverbatim
  872. * @{
  873. */
  874. /**
  875. * @brief Enables dynamically SDRAM write protection.
  876. * @param hsdram pointer to a SDRAM_HandleTypeDef structure that contains
  877. * the configuration information for SDRAM module.
  878. * @retval HAL status
  879. */
  880. HAL_StatusTypeDef HAL_SDRAM_WriteProtection_Enable(SDRAM_HandleTypeDef *hsdram)
  881. {
  882. /* Check the SDRAM controller state */
  883. if (hsdram->State == HAL_SDRAM_STATE_BUSY)
  884. {
  885. return HAL_BUSY;
  886. }
  887. else if (hsdram->State == HAL_SDRAM_STATE_READY)
  888. {
  889. /* Update the SDRAM state */
  890. hsdram->State = HAL_SDRAM_STATE_BUSY;
  891. /* Enable write protection */
  892. (void)FMC_SDRAM_WriteProtection_Enable(hsdram->Instance, hsdram->Init.SDBank);
  893. /* Update the SDRAM state */
  894. hsdram->State = HAL_SDRAM_STATE_WRITE_PROTECTED;
  895. }
  896. else
  897. {
  898. return HAL_ERROR;
  899. }
  900. return HAL_OK;
  901. }
  902. /**
  903. * @brief Disables dynamically SDRAM write protection.
  904. * @param hsdram pointer to a SDRAM_HandleTypeDef structure that contains
  905. * the configuration information for SDRAM module.
  906. * @retval HAL status
  907. */
  908. HAL_StatusTypeDef HAL_SDRAM_WriteProtection_Disable(SDRAM_HandleTypeDef *hsdram)
  909. {
  910. HAL_SDRAM_StateTypeDef state = hsdram->State;
  911. /* Check the SDRAM controller state */
  912. if (state == HAL_SDRAM_STATE_BUSY)
  913. {
  914. return HAL_BUSY;
  915. }
  916. else if (state == HAL_SDRAM_STATE_WRITE_PROTECTED)
  917. {
  918. /* Update the SDRAM state */
  919. hsdram->State = HAL_SDRAM_STATE_BUSY;
  920. /* Disable write protection */
  921. (void)FMC_SDRAM_WriteProtection_Disable(hsdram->Instance, hsdram->Init.SDBank);
  922. /* Update the SDRAM state */
  923. hsdram->State = HAL_SDRAM_STATE_READY;
  924. }
  925. else
  926. {
  927. return HAL_ERROR;
  928. }
  929. return HAL_OK;
  930. }
  931. /**
  932. * @brief Sends Command to the SDRAM bank.
  933. * @param hsdram pointer to a SDRAM_HandleTypeDef structure that contains
  934. * the configuration information for SDRAM module.
  935. * @param Command SDRAM command structure
  936. * @param Timeout Timeout duration
  937. * @retval HAL status
  938. */
  939. HAL_StatusTypeDef HAL_SDRAM_SendCommand(SDRAM_HandleTypeDef *hsdram, FMC_SDRAM_CommandTypeDef *Command, uint32_t Timeout)
  940. {
  941. HAL_SDRAM_StateTypeDef state = hsdram->State;
  942. /* Check the SDRAM controller state */
  943. if (state == HAL_SDRAM_STATE_BUSY)
  944. {
  945. return HAL_BUSY;
  946. }
  947. else if((state == HAL_SDRAM_STATE_READY) || (state == HAL_SDRAM_STATE_PRECHARGED))
  948. {
  949. /* Update the SDRAM state */
  950. hsdram->State = HAL_SDRAM_STATE_BUSY;
  951. /* Send SDRAM command */
  952. (void)FMC_SDRAM_SendCommand(hsdram->Instance, Command, Timeout);
  953. /* Update the SDRAM controller state state */
  954. if (Command->CommandMode == FMC_SDRAM_CMD_PALL)
  955. {
  956. hsdram->State = HAL_SDRAM_STATE_PRECHARGED;
  957. }
  958. else
  959. {
  960. hsdram->State = HAL_SDRAM_STATE_READY;
  961. }
  962. }
  963. else
  964. {
  965. return HAL_ERROR;
  966. }
  967. return HAL_OK;
  968. }
  969. /**
  970. * @brief Programs the SDRAM Memory Refresh rate.
  971. * @param hsdram pointer to a SDRAM_HandleTypeDef structure that contains
  972. * the configuration information for SDRAM module.
  973. * @param RefreshRate The SDRAM refresh rate value
  974. * @retval HAL status
  975. */
  976. HAL_StatusTypeDef HAL_SDRAM_ProgramRefreshRate(SDRAM_HandleTypeDef *hsdram, uint32_t RefreshRate)
  977. {
  978. /* Check the SDRAM controller state */
  979. if (hsdram->State == HAL_SDRAM_STATE_BUSY)
  980. {
  981. return HAL_BUSY;
  982. }
  983. else if (hsdram->State == HAL_SDRAM_STATE_READY)
  984. {
  985. /* Update the SDRAM state */
  986. hsdram->State = HAL_SDRAM_STATE_BUSY;
  987. /* Program the refresh rate */
  988. (void)FMC_SDRAM_ProgramRefreshRate(hsdram->Instance, RefreshRate);
  989. /* Update the SDRAM state */
  990. hsdram->State = HAL_SDRAM_STATE_READY;
  991. }
  992. else
  993. {
  994. return HAL_ERROR;
  995. }
  996. return HAL_OK;
  997. }
  998. /**
  999. * @brief Sets the Number of consecutive SDRAM Memory auto Refresh commands.
  1000. * @param hsdram pointer to a SDRAM_HandleTypeDef structure that contains
  1001. * the configuration information for SDRAM module.
  1002. * @param AutoRefreshNumber The SDRAM auto Refresh number
  1003. * @retval HAL status
  1004. */
  1005. HAL_StatusTypeDef HAL_SDRAM_SetAutoRefreshNumber(SDRAM_HandleTypeDef *hsdram, uint32_t AutoRefreshNumber)
  1006. {
  1007. /* Check the SDRAM controller state */
  1008. if (hsdram->State == HAL_SDRAM_STATE_BUSY)
  1009. {
  1010. return HAL_BUSY;
  1011. }
  1012. else if (hsdram->State == HAL_SDRAM_STATE_READY)
  1013. {
  1014. /* Update the SDRAM state */
  1015. hsdram->State = HAL_SDRAM_STATE_BUSY;
  1016. /* Set the Auto-Refresh number */
  1017. (void)FMC_SDRAM_SetAutoRefreshNumber(hsdram->Instance, AutoRefreshNumber);
  1018. /* Update the SDRAM state */
  1019. hsdram->State = HAL_SDRAM_STATE_READY;
  1020. }
  1021. else
  1022. {
  1023. return HAL_ERROR;
  1024. }
  1025. return HAL_OK;
  1026. }
  1027. /**
  1028. * @brief Returns the SDRAM memory current mode.
  1029. * @param hsdram pointer to a SDRAM_HandleTypeDef structure that contains
  1030. * the configuration information for SDRAM module.
  1031. * @retval The SDRAM memory mode.
  1032. */
  1033. uint32_t HAL_SDRAM_GetModeStatus(SDRAM_HandleTypeDef *hsdram)
  1034. {
  1035. /* Return the SDRAM memory current mode */
  1036. return (FMC_SDRAM_GetModeStatus(hsdram->Instance, hsdram->Init.SDBank));
  1037. }
  1038. /**
  1039. * @}
  1040. */
  1041. /** @defgroup SDRAM_Exported_Functions_Group4 State functions
  1042. * @brief Peripheral State functions
  1043. *
  1044. @verbatim
  1045. ==============================================================================
  1046. ##### SDRAM State functions #####
  1047. ==============================================================================
  1048. [..]
  1049. This subsection permits to get in run-time the status of the SDRAM controller
  1050. and the data flow.
  1051. @endverbatim
  1052. * @{
  1053. */
  1054. /**
  1055. * @brief Returns the SDRAM state.
  1056. * @param hsdram pointer to a SDRAM_HandleTypeDef structure that contains
  1057. * the configuration information for SDRAM module.
  1058. * @retval HAL state
  1059. */
  1060. HAL_SDRAM_StateTypeDef HAL_SDRAM_GetState(SDRAM_HandleTypeDef *hsdram)
  1061. {
  1062. return hsdram->State;
  1063. }
  1064. /**
  1065. * @}
  1066. */
  1067. /**
  1068. * @}
  1069. */
  1070. /**
  1071. @cond 0
  1072. */
  1073. /**
  1074. * @brief MDMA SDRAM process complete callback.
  1075. * @param hmdma : MDMA handle
  1076. * @retval None
  1077. */
  1078. static void SDRAM_DMACplt(MDMA_HandleTypeDef *hmdma)
  1079. {
  1080. SDRAM_HandleTypeDef* hsdram = ( SDRAM_HandleTypeDef* )(hmdma->Parent);
  1081. /* Disable the MDMA channel */
  1082. __HAL_MDMA_DISABLE(hmdma);
  1083. /* Update the SDRAM controller state */
  1084. hsdram->State = HAL_SDRAM_STATE_READY;
  1085. #if (USE_HAL_SDRAM_REGISTER_CALLBACKS == 1)
  1086. hsdram->DmaXferCpltCallback(hmdma);
  1087. #else
  1088. HAL_SDRAM_DMA_XferCpltCallback(hmdma);
  1089. #endif
  1090. }
  1091. /**
  1092. * @brief MDMA SRAM process complete callback.
  1093. * @param hmdma : MDMA handle
  1094. * @retval None
  1095. */
  1096. static void SDRAM_DMACpltProt(MDMA_HandleTypeDef *hmdma)
  1097. {
  1098. SDRAM_HandleTypeDef* hsdram = ( SDRAM_HandleTypeDef* )(hmdma->Parent);
  1099. /* Disable the MDMA channel */
  1100. __HAL_MDMA_DISABLE(hmdma);
  1101. /* Update the SDRAM controller state */
  1102. hsdram->State = HAL_SDRAM_STATE_WRITE_PROTECTED;
  1103. #if (USE_HAL_SDRAM_REGISTER_CALLBACKS == 1)
  1104. hsdram->DmaXferCpltCallback(hmdma);
  1105. #else
  1106. HAL_SDRAM_DMA_XferCpltCallback(hmdma);
  1107. #endif
  1108. }
  1109. /**
  1110. * @brief MDMA SDRAM error callback.
  1111. * @param hmdma : MDMA handle
  1112. * @retval None
  1113. */
  1114. static void SDRAM_DMAError(MDMA_HandleTypeDef *hmdma)
  1115. {
  1116. SDRAM_HandleTypeDef* hsdram = ( SDRAM_HandleTypeDef* )(hmdma->Parent);
  1117. /* Disable the MDMA channel */
  1118. __HAL_MDMA_DISABLE(hmdma);
  1119. /* Update the SDRAM controller state */
  1120. hsdram->State = HAL_SDRAM_STATE_ERROR;
  1121. #if (USE_HAL_SDRAM_REGISTER_CALLBACKS == 1)
  1122. hsdram->DmaXferErrorCallback(hmdma);
  1123. #else
  1124. HAL_SDRAM_DMA_XferErrorCallback(hmdma);
  1125. #endif
  1126. }
  1127. /**
  1128. @endcond
  1129. */
  1130. /**
  1131. * @}
  1132. */
  1133. #endif /* HAL_SDRAM_MODULE_ENABLED */
  1134. /**
  1135. * @}
  1136. */
  1137. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/