Merge pull request #10558 from iNavFlight/MrD_Correct-comments-on-OSD-symbols
[inav.git] / lib / main / STM32F7 / Drivers / STM32F7xx_HAL_Driver / Src / stm32f7xx_hal_sdram.c
blob55181aae7762d9e13752387aa8c81cca563b9193
1 /**
2 ******************************************************************************
3 * @file stm32f7xx_hal_sdram.c
4 * @author MCD Application Team
5 * @version V1.2.2
6 * @date 14-April-2017
7 * @brief SDRAM HAL module driver.
8 * This file provides a generic firmware to drive SDRAM memories mounted
9 * as external device.
11 @verbatim
12 ==============================================================================
13 ##### How to use this driver #####
14 ==============================================================================
15 [..]
16 This driver is a generic layered driver which contains a set of APIs used to
17 control SDRAM memories. It uses the FMC layer functions to interface
18 with SDRAM devices.
19 The following sequence should be followed to configure the FMC to interface
20 with SDRAM memories:
22 (#) Declare a SDRAM_HandleTypeDef handle structure, for example:
23 SDRAM_HandleTypeDef hdsram
25 (++) Fill the SDRAM_HandleTypeDef handle "Init" field with the allowed
26 values of the structure member.
28 (++) Fill the SDRAM_HandleTypeDef handle "Instance" field with a predefined
29 base register instance for NOR or SDRAM device
31 (#) Declare a FMC_SDRAM_TimingTypeDef structure; for example:
32 FMC_SDRAM_TimingTypeDef Timing;
33 and fill its fields with the allowed values of the structure member.
35 (#) Initialize the SDRAM Controller by calling the function HAL_SDRAM_Init(). This function
36 performs the following sequence:
38 (##) MSP hardware layer configuration using the function HAL_SDRAM_MspInit()
39 (##) Control register configuration using the FMC SDRAM interface function
40 FMC_SDRAM_Init()
41 (##) Timing register configuration using the FMC SDRAM interface function
42 FMC_SDRAM_Timing_Init()
43 (##) Program the SDRAM external device by applying its initialization sequence
44 according to the device plugged in your hardware. This step is mandatory
45 for accessing the SDRAM device.
47 (#) At this stage you can perform read/write accesses from/to the memory connected
48 to the SDRAM Bank. You can perform either polling or DMA transfer using the
49 following APIs:
50 (++) HAL_SDRAM_Read()/HAL_SDRAM_Write() for polling read/write access
51 (++) HAL_SDRAM_Read_DMA()/HAL_SDRAM_Write_DMA() for DMA read/write transfer
53 (#) You can also control the SDRAM device by calling the control APIs HAL_SDRAM_WriteOperation_Enable()/
54 HAL_SDRAM_WriteOperation_Disable() to respectively enable/disable the SDRAM write operation or
55 the function HAL_SDRAM_SendCommand() to send a specified command to the SDRAM
56 device. The command to be sent must be configured with the FMC_SDRAM_CommandTypeDef
57 structure.
59 (#) You can continuously monitor the SDRAM device HAL state by calling the function
60 HAL_SDRAM_GetState()
62 @endverbatim
63 ******************************************************************************
64 * @attention
66 * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
68 * Redistribution and use in source and binary forms, with or without modification,
69 * are permitted provided that the following conditions are met:
70 * 1. Redistributions of source code must retain the above copyright notice,
71 * this list of conditions and the following disclaimer.
72 * 2. Redistributions in binary form must reproduce the above copyright notice,
73 * this list of conditions and the following disclaimer in the documentation
74 * and/or other materials provided with the distribution.
75 * 3. Neither the name of STMicroelectronics nor the names of its contributors
76 * may be used to endorse or promote products derived from this software
77 * without specific prior written permission.
79 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
80 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
81 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
82 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
83 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
84 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
85 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
86 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
87 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
88 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
90 ******************************************************************************
91 */
93 /* Includes ------------------------------------------------------------------*/
94 #include "stm32f7xx_hal.h"
96 /** @addtogroup STM32F7xx_HAL_Driver
97 * @{
100 /** @defgroup SDRAM SDRAM
101 * @brief SDRAM driver modules
102 * @{
104 #ifdef HAL_SDRAM_MODULE_ENABLED
106 /* Private typedef -----------------------------------------------------------*/
107 /* Private define ------------------------------------------------------------*/
108 /* Private macro -------------------------------------------------------------*/
109 /* Private variables ---------------------------------------------------------*/
110 /* Private functions ---------------------------------------------------------*/
111 /* Exported functions --------------------------------------------------------*/
112 /** @defgroup SDRAM_Exported_Functions SDRAM Exported Functions
113 * @{
116 /** @defgroup SDRAM_Exported_Functions_Group1 Initialization and de-initialization functions
117 * @brief Initialization and Configuration functions
119 @verbatim
120 ==============================================================================
121 ##### SDRAM Initialization and de_initialization functions #####
122 ==============================================================================
123 [..]
124 This section provides functions allowing to initialize/de-initialize
125 the SDRAM memory
127 @endverbatim
128 * @{
132 * @brief Performs the SDRAM device initialization sequence.
133 * @param hsdram: pointer to a SDRAM_HandleTypeDef structure that contains
134 * the configuration information for SDRAM module.
135 * @param Timing: Pointer to SDRAM control timing structure
136 * @retval HAL status
138 HAL_StatusTypeDef HAL_SDRAM_Init(SDRAM_HandleTypeDef *hsdram, FMC_SDRAM_TimingTypeDef *Timing)
140 /* Check the SDRAM handle parameter */
141 if(hsdram == NULL)
143 return HAL_ERROR;
146 if(hsdram->State == HAL_SDRAM_STATE_RESET)
148 /* Allocate lock resource and initialize it */
149 hsdram->Lock = HAL_UNLOCKED;
150 /* Initialize the low level hardware (MSP) */
151 HAL_SDRAM_MspInit(hsdram);
154 /* Initialize the SDRAM controller state */
155 hsdram->State = HAL_SDRAM_STATE_BUSY;
157 /* Initialize SDRAM control Interface */
158 FMC_SDRAM_Init(hsdram->Instance, &(hsdram->Init));
160 /* Initialize SDRAM timing Interface */
161 FMC_SDRAM_Timing_Init(hsdram->Instance, Timing, hsdram->Init.SDBank);
163 /* Update the SDRAM controller state */
164 hsdram->State = HAL_SDRAM_STATE_READY;
166 return HAL_OK;
170 * @brief Perform the SDRAM device initialization sequence.
171 * @param hsdram: pointer to a SDRAM_HandleTypeDef structure that contains
172 * the configuration information for SDRAM module.
173 * @retval HAL status
175 HAL_StatusTypeDef HAL_SDRAM_DeInit(SDRAM_HandleTypeDef *hsdram)
177 /* Initialize the low level hardware (MSP) */
178 HAL_SDRAM_MspDeInit(hsdram);
180 /* Configure the SDRAM registers with their reset values */
181 FMC_SDRAM_DeInit(hsdram->Instance, hsdram->Init.SDBank);
183 /* Reset the SDRAM controller state */
184 hsdram->State = HAL_SDRAM_STATE_RESET;
186 /* Release Lock */
187 __HAL_UNLOCK(hsdram);
189 return HAL_OK;
193 * @brief SDRAM MSP Init.
194 * @param hsdram: pointer to a SDRAM_HandleTypeDef structure that contains
195 * the configuration information for SDRAM module.
196 * @retval None
198 __weak void HAL_SDRAM_MspInit(SDRAM_HandleTypeDef *hsdram)
200 /* Prevent unused argument(s) compilation warning */
201 UNUSED(hsdram);
203 /* NOTE: This function Should not be modified, when the callback is needed,
204 the HAL_SDRAM_MspInit could be implemented in the user file
209 * @brief SDRAM MSP DeInit.
210 * @param hsdram: pointer to a SDRAM_HandleTypeDef structure that contains
211 * the configuration information for SDRAM module.
212 * @retval None
214 __weak void HAL_SDRAM_MspDeInit(SDRAM_HandleTypeDef *hsdram)
216 /* Prevent unused argument(s) compilation warning */
217 UNUSED(hsdram);
219 /* NOTE: This function Should not be modified, when the callback is needed,
220 the HAL_SDRAM_MspDeInit could be implemented in the user file
225 * @brief This function handles SDRAM refresh error interrupt request.
226 * @param hsdram: pointer to a SDRAM_HandleTypeDef structure that contains
227 * the configuration information for SDRAM module.
228 * @retval HAL status
230 void HAL_SDRAM_IRQHandler(SDRAM_HandleTypeDef *hsdram)
232 /* Check SDRAM interrupt Rising edge flag */
233 if(__FMC_SDRAM_GET_FLAG(hsdram->Instance, FMC_SDRAM_FLAG_REFRESH_IT))
235 /* SDRAM refresh error interrupt callback */
236 HAL_SDRAM_RefreshErrorCallback(hsdram);
238 /* Clear SDRAM refresh error interrupt pending bit */
239 __FMC_SDRAM_CLEAR_FLAG(hsdram->Instance, FMC_SDRAM_FLAG_REFRESH_ERROR);
244 * @brief SDRAM Refresh error callback.
245 * @param hsdram: pointer to a SDRAM_HandleTypeDef structure that contains
246 * the configuration information for SDRAM module.
247 * @retval None
249 __weak void HAL_SDRAM_RefreshErrorCallback(SDRAM_HandleTypeDef *hsdram)
251 /* Prevent unused argument(s) compilation warning */
252 UNUSED(hsdram);
254 /* NOTE: This function Should not be modified, when the callback is needed,
255 the HAL_SDRAM_RefreshErrorCallback could be implemented in the user file
260 * @brief DMA transfer complete callback.
261 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
262 * the configuration information for the specified DMA module.
263 * @retval None
265 __weak void HAL_SDRAM_DMA_XferCpltCallback(DMA_HandleTypeDef *hdma)
267 /* Prevent unused argument(s) compilation warning */
268 UNUSED(hdma);
270 /* NOTE: This function Should not be modified, when the callback is needed,
271 the HAL_SDRAM_DMA_XferCpltCallback could be implemented in the user file
276 * @brief DMA transfer complete error callback.
277 * @param hdma: DMA handle
278 * @retval None
280 __weak void HAL_SDRAM_DMA_XferErrorCallback(DMA_HandleTypeDef *hdma)
282 /* Prevent unused argument(s) compilation warning */
283 UNUSED(hdma);
285 /* NOTE: This function Should not be modified, when the callback is needed,
286 the HAL_SDRAM_DMA_XferErrorCallback could be implemented in the user file
291 * @}
294 /** @defgroup SDRAM_Exported_Functions_Group2 Input and Output functions
295 * @brief Input Output and memory control functions
297 @verbatim
298 ==============================================================================
299 ##### SDRAM Input and Output functions #####
300 ==============================================================================
301 [..]
302 This section provides functions allowing to use and control the SDRAM memory
304 @endverbatim
305 * @{
309 * @brief Reads 8-bit data buffer from the SDRAM memory.
310 * @param hsdram: pointer to a SDRAM_HandleTypeDef structure that contains
311 * the configuration information for SDRAM module.
312 * @param pAddress: Pointer to read start address
313 * @param pDstBuffer: Pointer to destination buffer
314 * @param BufferSize: Size of the buffer to read from memory
315 * @retval HAL status
317 HAL_StatusTypeDef HAL_SDRAM_Read_8b(SDRAM_HandleTypeDef *hsdram, uint32_t *pAddress, uint8_t *pDstBuffer, uint32_t BufferSize)
319 __IO uint8_t *pSdramAddress = (uint8_t *)pAddress;
321 /* Process Locked */
322 __HAL_LOCK(hsdram);
324 /* Check the SDRAM controller state */
325 if(hsdram->State == HAL_SDRAM_STATE_BUSY)
327 return HAL_BUSY;
329 else if(hsdram->State == HAL_SDRAM_STATE_PRECHARGED)
331 return HAL_ERROR;
334 /* Read data from source */
335 for(; BufferSize != 0; BufferSize--)
337 *pDstBuffer = *(__IO uint8_t *)pSdramAddress;
338 pDstBuffer++;
339 pSdramAddress++;
342 /* Process Unlocked */
343 __HAL_UNLOCK(hsdram);
345 return HAL_OK;
350 * @brief Writes 8-bit data buffer to SDRAM memory.
351 * @param hsdram: pointer to a SDRAM_HandleTypeDef structure that contains
352 * the configuration information for SDRAM module.
353 * @param pAddress: Pointer to write start address
354 * @param pSrcBuffer: Pointer to source buffer to write
355 * @param BufferSize: Size of the buffer to write to memory
356 * @retval HAL status
358 HAL_StatusTypeDef HAL_SDRAM_Write_8b(SDRAM_HandleTypeDef *hsdram, uint32_t *pAddress, uint8_t *pSrcBuffer, uint32_t BufferSize)
360 __IO uint8_t *pSdramAddress = (uint8_t *)pAddress;
361 uint32_t tmp = 0;
363 /* Process Locked */
364 __HAL_LOCK(hsdram);
366 /* Check the SDRAM controller state */
367 tmp = hsdram->State;
369 if(tmp == HAL_SDRAM_STATE_BUSY)
371 return HAL_BUSY;
373 else if((tmp == HAL_SDRAM_STATE_PRECHARGED) || (tmp == HAL_SDRAM_STATE_WRITE_PROTECTED))
375 return HAL_ERROR;
378 /* Write data to memory */
379 for(; BufferSize != 0; BufferSize--)
381 *(__IO uint8_t *)pSdramAddress = *pSrcBuffer;
382 pSrcBuffer++;
383 pSdramAddress++;
386 /* Process Unlocked */
387 __HAL_UNLOCK(hsdram);
389 return HAL_OK;
394 * @brief Reads 16-bit data buffer from the SDRAM memory.
395 * @param hsdram: pointer to a SDRAM_HandleTypeDef structure that contains
396 * the configuration information for SDRAM module.
397 * @param pAddress: Pointer to read start address
398 * @param pDstBuffer: Pointer to destination buffer
399 * @param BufferSize: Size of the buffer to read from memory
400 * @retval HAL status
402 HAL_StatusTypeDef HAL_SDRAM_Read_16b(SDRAM_HandleTypeDef *hsdram, uint32_t *pAddress, uint16_t *pDstBuffer, uint32_t BufferSize)
404 __IO uint16_t *pSdramAddress = (uint16_t *)pAddress;
406 /* Process Locked */
407 __HAL_LOCK(hsdram);
409 /* Check the SDRAM controller state */
410 if(hsdram->State == HAL_SDRAM_STATE_BUSY)
412 return HAL_BUSY;
414 else if(hsdram->State == HAL_SDRAM_STATE_PRECHARGED)
416 return HAL_ERROR;
419 /* Read data from source */
420 for(; BufferSize != 0; BufferSize--)
422 *pDstBuffer = *(__IO uint16_t *)pSdramAddress;
423 pDstBuffer++;
424 pSdramAddress++;
427 /* Process Unlocked */
428 __HAL_UNLOCK(hsdram);
430 return HAL_OK;
434 * @brief Writes 16-bit data buffer to SDRAM memory.
435 * @param hsdram: pointer to a SDRAM_HandleTypeDef structure that contains
436 * the configuration information for SDRAM module.
437 * @param pAddress: Pointer to write start address
438 * @param pSrcBuffer: Pointer to source buffer to write
439 * @param BufferSize: Size of the buffer to write to memory
440 * @retval HAL status
442 HAL_StatusTypeDef HAL_SDRAM_Write_16b(SDRAM_HandleTypeDef *hsdram, uint32_t *pAddress, uint16_t *pSrcBuffer, uint32_t BufferSize)
444 __IO uint16_t *pSdramAddress = (uint16_t *)pAddress;
445 uint32_t tmp = 0;
447 /* Process Locked */
448 __HAL_LOCK(hsdram);
450 /* Check the SDRAM controller state */
451 tmp = hsdram->State;
453 if(tmp == HAL_SDRAM_STATE_BUSY)
455 return HAL_BUSY;
457 else if((tmp == HAL_SDRAM_STATE_PRECHARGED) || (tmp == HAL_SDRAM_STATE_WRITE_PROTECTED))
459 return HAL_ERROR;
462 /* Write data to memory */
463 for(; BufferSize != 0; BufferSize--)
465 *(__IO uint16_t *)pSdramAddress = *pSrcBuffer;
466 pSrcBuffer++;
467 pSdramAddress++;
470 /* Process Unlocked */
471 __HAL_UNLOCK(hsdram);
473 return HAL_OK;
477 * @brief Reads 32-bit data buffer from the SDRAM memory.
478 * @param hsdram: pointer to a SDRAM_HandleTypeDef structure that contains
479 * the configuration information for SDRAM module.
480 * @param pAddress: Pointer to read start address
481 * @param pDstBuffer: Pointer to destination buffer
482 * @param BufferSize: Size of the buffer to read from memory
483 * @retval HAL status
485 HAL_StatusTypeDef HAL_SDRAM_Read_32b(SDRAM_HandleTypeDef *hsdram, uint32_t *pAddress, uint32_t *pDstBuffer, uint32_t BufferSize)
487 __IO uint32_t *pSdramAddress = (uint32_t *)pAddress;
489 /* Process Locked */
490 __HAL_LOCK(hsdram);
492 /* Check the SDRAM controller state */
493 if(hsdram->State == HAL_SDRAM_STATE_BUSY)
495 return HAL_BUSY;
497 else if(hsdram->State == HAL_SDRAM_STATE_PRECHARGED)
499 return HAL_ERROR;
502 /* Read data from source */
503 for(; BufferSize != 0; BufferSize--)
505 *pDstBuffer = *(__IO uint32_t *)pSdramAddress;
506 pDstBuffer++;
507 pSdramAddress++;
510 /* Process Unlocked */
511 __HAL_UNLOCK(hsdram);
513 return HAL_OK;
517 * @brief Writes 32-bit data buffer to SDRAM memory.
518 * @param hsdram: pointer to a SDRAM_HandleTypeDef structure that contains
519 * the configuration information for SDRAM module.
520 * @param pAddress: Pointer to write start address
521 * @param pSrcBuffer: Pointer to source buffer to write
522 * @param BufferSize: Size of the buffer to write to memory
523 * @retval HAL status
525 HAL_StatusTypeDef HAL_SDRAM_Write_32b(SDRAM_HandleTypeDef *hsdram, uint32_t *pAddress, uint32_t *pSrcBuffer, uint32_t BufferSize)
527 __IO uint32_t *pSdramAddress = (uint32_t *)pAddress;
528 uint32_t tmp = 0;
530 /* Process Locked */
531 __HAL_LOCK(hsdram);
533 /* Check the SDRAM controller state */
534 tmp = hsdram->State;
536 if(tmp == HAL_SDRAM_STATE_BUSY)
538 return HAL_BUSY;
540 else if((tmp == HAL_SDRAM_STATE_PRECHARGED) || (tmp == HAL_SDRAM_STATE_WRITE_PROTECTED))
542 return HAL_ERROR;
545 /* Write data to memory */
546 for(; BufferSize != 0; BufferSize--)
548 *(__IO uint32_t *)pSdramAddress = *pSrcBuffer;
549 pSrcBuffer++;
550 pSdramAddress++;
553 /* Process Unlocked */
554 __HAL_UNLOCK(hsdram);
556 return HAL_OK;
560 * @brief Reads a Words data from the SDRAM memory using DMA transfer.
561 * @param hsdram: pointer to a SDRAM_HandleTypeDef structure that contains
562 * the configuration information for SDRAM module.
563 * @param pAddress: Pointer to read start address
564 * @param pDstBuffer: Pointer to destination buffer
565 * @param BufferSize: Size of the buffer to read from memory
566 * @retval HAL status
568 HAL_StatusTypeDef HAL_SDRAM_Read_DMA(SDRAM_HandleTypeDef *hsdram, uint32_t *pAddress, uint32_t *pDstBuffer, uint32_t BufferSize)
570 uint32_t tmp = 0;
572 /* Process Locked */
573 __HAL_LOCK(hsdram);
575 /* Check the SDRAM controller state */
576 tmp = hsdram->State;
578 if(tmp == HAL_SDRAM_STATE_BUSY)
580 return HAL_BUSY;
582 else if(tmp == HAL_SDRAM_STATE_PRECHARGED)
584 return HAL_ERROR;
587 /* Configure DMA user callbacks */
588 hsdram->hdma->XferCpltCallback = HAL_SDRAM_DMA_XferCpltCallback;
589 hsdram->hdma->XferErrorCallback = HAL_SDRAM_DMA_XferErrorCallback;
591 /* Enable the DMA Stream */
592 HAL_DMA_Start_IT(hsdram->hdma, (uint32_t)pAddress, (uint32_t)pDstBuffer, (uint32_t)BufferSize);
594 /* Process Unlocked */
595 __HAL_UNLOCK(hsdram);
597 return HAL_OK;
601 * @brief Writes a Words data buffer to SDRAM memory using DMA transfer.
602 * @param hsdram: pointer to a SDRAM_HandleTypeDef structure that contains
603 * the configuration information for SDRAM module.
604 * @param pAddress: Pointer to write start address
605 * @param pSrcBuffer: Pointer to source buffer to write
606 * @param BufferSize: Size of the buffer to write to memory
607 * @retval HAL status
609 HAL_StatusTypeDef HAL_SDRAM_Write_DMA(SDRAM_HandleTypeDef *hsdram, uint32_t *pAddress, uint32_t *pSrcBuffer, uint32_t BufferSize)
611 uint32_t tmp = 0;
613 /* Process Locked */
614 __HAL_LOCK(hsdram);
616 /* Check the SDRAM controller state */
617 tmp = hsdram->State;
619 if(tmp == HAL_SDRAM_STATE_BUSY)
621 return HAL_BUSY;
623 else if((tmp == HAL_SDRAM_STATE_PRECHARGED) || (tmp == HAL_SDRAM_STATE_WRITE_PROTECTED))
625 return HAL_ERROR;
628 /* Configure DMA user callbacks */
629 hsdram->hdma->XferCpltCallback = HAL_SDRAM_DMA_XferCpltCallback;
630 hsdram->hdma->XferErrorCallback = HAL_SDRAM_DMA_XferErrorCallback;
632 /* Enable the DMA Stream */
633 HAL_DMA_Start_IT(hsdram->hdma, (uint32_t)pSrcBuffer, (uint32_t)pAddress, (uint32_t)BufferSize);
635 /* Process Unlocked */
636 __HAL_UNLOCK(hsdram);
638 return HAL_OK;
642 * @}
645 /** @defgroup SDRAM_Exported_Functions_Group3 Control functions
646 * @brief management functions
648 @verbatim
649 ==============================================================================
650 ##### SDRAM Control functions #####
651 ==============================================================================
652 [..]
653 This subsection provides a set of functions allowing to control dynamically
654 the SDRAM interface.
656 @endverbatim
657 * @{
661 * @brief Enables dynamically SDRAM write protection.
662 * @param hsdram: pointer to a SDRAM_HandleTypeDef structure that contains
663 * the configuration information for SDRAM module.
664 * @retval HAL status
666 HAL_StatusTypeDef HAL_SDRAM_WriteProtection_Enable(SDRAM_HandleTypeDef *hsdram)
668 /* Check the SDRAM controller state */
669 if(hsdram->State == HAL_SDRAM_STATE_BUSY)
671 return HAL_BUSY;
674 /* Update the SDRAM state */
675 hsdram->State = HAL_SDRAM_STATE_BUSY;
677 /* Enable write protection */
678 FMC_SDRAM_WriteProtection_Enable(hsdram->Instance, hsdram->Init.SDBank);
680 /* Update the SDRAM state */
681 hsdram->State = HAL_SDRAM_STATE_WRITE_PROTECTED;
683 return HAL_OK;
687 * @brief Disables dynamically SDRAM write protection.
688 * @param hsdram: pointer to a SDRAM_HandleTypeDef structure that contains
689 * the configuration information for SDRAM module.
690 * @retval HAL status
692 HAL_StatusTypeDef HAL_SDRAM_WriteProtection_Disable(SDRAM_HandleTypeDef *hsdram)
694 /* Check the SDRAM controller state */
695 if(hsdram->State == HAL_SDRAM_STATE_BUSY)
697 return HAL_BUSY;
700 /* Update the SDRAM state */
701 hsdram->State = HAL_SDRAM_STATE_BUSY;
703 /* Disable write protection */
704 FMC_SDRAM_WriteProtection_Disable(hsdram->Instance, hsdram->Init.SDBank);
706 /* Update the SDRAM state */
707 hsdram->State = HAL_SDRAM_STATE_READY;
709 return HAL_OK;
713 * @brief Sends Command to the SDRAM bank.
714 * @param hsdram: pointer to a SDRAM_HandleTypeDef structure that contains
715 * the configuration information for SDRAM module.
716 * @param Command: SDRAM command structure
717 * @param Timeout: Timeout duration
718 * @retval HAL status
720 HAL_StatusTypeDef HAL_SDRAM_SendCommand(SDRAM_HandleTypeDef *hsdram, FMC_SDRAM_CommandTypeDef *Command, uint32_t Timeout)
722 /* Check the SDRAM controller state */
723 if(hsdram->State == HAL_SDRAM_STATE_BUSY)
725 return HAL_BUSY;
728 /* Update the SDRAM state */
729 hsdram->State = HAL_SDRAM_STATE_BUSY;
731 /* Send SDRAM command */
732 FMC_SDRAM_SendCommand(hsdram->Instance, Command, Timeout);
734 /* Update the SDRAM controller state state */
735 if(Command->CommandMode == FMC_SDRAM_CMD_PALL)
737 hsdram->State = HAL_SDRAM_STATE_PRECHARGED;
739 else
741 hsdram->State = HAL_SDRAM_STATE_READY;
744 return HAL_OK;
748 * @brief Programs the SDRAM Memory Refresh rate.
749 * @param hsdram: pointer to a SDRAM_HandleTypeDef structure that contains
750 * the configuration information for SDRAM module.
751 * @param RefreshRate: The SDRAM refresh rate value
752 * @retval HAL status
754 HAL_StatusTypeDef HAL_SDRAM_ProgramRefreshRate(SDRAM_HandleTypeDef *hsdram, uint32_t RefreshRate)
756 /* Check the SDRAM controller state */
757 if(hsdram->State == HAL_SDRAM_STATE_BUSY)
759 return HAL_BUSY;
762 /* Update the SDRAM state */
763 hsdram->State = HAL_SDRAM_STATE_BUSY;
765 /* Program the refresh rate */
766 FMC_SDRAM_ProgramRefreshRate(hsdram->Instance ,RefreshRate);
768 /* Update the SDRAM state */
769 hsdram->State = HAL_SDRAM_STATE_READY;
771 return HAL_OK;
775 * @brief Sets the Number of consecutive SDRAM Memory auto Refresh commands.
776 * @param hsdram: pointer to a SDRAM_HandleTypeDef structure that contains
777 * the configuration information for SDRAM module.
778 * @param AutoRefreshNumber: The SDRAM auto Refresh number
779 * @retval HAL status
781 HAL_StatusTypeDef HAL_SDRAM_SetAutoRefreshNumber(SDRAM_HandleTypeDef *hsdram, uint32_t AutoRefreshNumber)
783 /* Check the SDRAM controller state */
784 if(hsdram->State == HAL_SDRAM_STATE_BUSY)
786 return HAL_BUSY;
789 /* Update the SDRAM state */
790 hsdram->State = HAL_SDRAM_STATE_BUSY;
792 /* Set the Auto-Refresh number */
793 FMC_SDRAM_SetAutoRefreshNumber(hsdram->Instance ,AutoRefreshNumber);
795 /* Update the SDRAM state */
796 hsdram->State = HAL_SDRAM_STATE_READY;
798 return HAL_OK;
802 * @brief Returns the SDRAM memory current mode.
803 * @param hsdram: pointer to a SDRAM_HandleTypeDef structure that contains
804 * the configuration information for SDRAM module.
805 * @retval The SDRAM memory mode.
807 uint32_t HAL_SDRAM_GetModeStatus(SDRAM_HandleTypeDef *hsdram)
809 /* Return the SDRAM memory current mode */
810 return(FMC_SDRAM_GetModeStatus(hsdram->Instance, hsdram->Init.SDBank));
814 * @}
817 /** @defgroup SDRAM_Exported_Functions_Group4 State functions
818 * @brief Peripheral State functions
820 @verbatim
821 ==============================================================================
822 ##### SDRAM State functions #####
823 ==============================================================================
824 [..]
825 This subsection permits to get in run-time the status of the SDRAM controller
826 and the data flow.
828 @endverbatim
829 * @{
833 * @brief Returns the SDRAM state.
834 * @param hsdram: pointer to a SDRAM_HandleTypeDef structure that contains
835 * the configuration information for SDRAM module.
836 * @retval HAL state
838 HAL_SDRAM_StateTypeDef HAL_SDRAM_GetState(SDRAM_HandleTypeDef *hsdram)
840 return hsdram->State;
844 * @}
848 * @}
850 #endif /* HAL_SDRAM_MODULE_ENABLED */
852 * @}
856 * @}
859 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/