Subversion Repositories LedShow

Rev

Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. /**
  2.   ******************************************************************************
  3.   * @file    stm32f1xx_hal_sram.c
  4.   * @author  MCD Application Team
  5.   * @brief   SRAM HAL module driver.
  6.   *          This file provides a generic firmware to drive SRAM memories  
  7.   *          mounted 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 SRAM memories. It uses the FSMC layer functions to interface
  16.     with SRAM devices.  
  17.     The following sequence should be followed to configure the FSMC to interface
  18.     with SRAM/PSRAM memories:
  19.      
  20.    (#) Declare a SRAM_HandleTypeDef handle structure, for example:
  21.           SRAM_HandleTypeDef  hsram; and:
  22.          
  23.        (++) Fill the SRAM_HandleTypeDef handle "Init" field with the allowed
  24.             values of the structure member.
  25.            
  26.        (++) Fill the SRAM_HandleTypeDef handle "Instance" field with a predefined
  27.             base register instance for NOR or SRAM device
  28.                          
  29.        (++) Fill the SRAM_HandleTypeDef handle "Extended" field with a predefined
  30.             base register instance for NOR or SRAM extended mode
  31.              
  32.    (#) Declare two FSMC_NORSRAM_TimingTypeDef structures, for both normal and extended
  33.        mode timings; for example:
  34.           FSMC_NORSRAM_TimingTypeDef  Timing and FSMC_NORSRAM_TimingTypeDef  ExTiming;
  35.       and fill its fields with the allowed values of the structure member.
  36.      
  37.    (#) Initialize the SRAM Controller by calling the function HAL_SRAM_Init(). This function
  38.        performs the following sequence:
  39.          
  40.        (##) MSP hardware layer configuration using the function HAL_SRAM_MspInit()
  41.        (##) Control register configuration using the FSMC NORSRAM interface function
  42.             FSMC_NORSRAM_Init()
  43.        (##) Timing register configuration using the FSMC NORSRAM interface function
  44.             FSMC_NORSRAM_Timing_Init()
  45.        (##) Extended mode Timing register configuration using the FSMC NORSRAM interface function
  46.             FSMC_NORSRAM_Extended_Timing_Init()
  47.        (##) Enable the SRAM device using the macro __FSMC_NORSRAM_ENABLE()    
  48.  
  49.    (#) At this stage you can perform read/write accesses from/to the memory connected
  50.        to the NOR/SRAM Bank. You can perform either polling or DMA transfer using the
  51.        following APIs:
  52.        (++) HAL_SRAM_Read()/HAL_SRAM_Write() for polling read/write access
  53.        (++) HAL_SRAM_Read_DMA()/HAL_SRAM_Write_DMA() for DMA read/write transfer
  54.        
  55.    (#) You can also control the SRAM device by calling the control APIs HAL_SRAM_WriteOperation_Enable()/
  56.        HAL_SRAM_WriteOperation_Disable() to respectively enable/disable the SRAM write operation  
  57.        
  58.    (#) You can continuously monitor the SRAM device HAL state by calling the function
  59.        HAL_SRAM_GetState()              
  60.                              
  61.   @endverbatim
  62.   ******************************************************************************
  63.   * @attention
  64.   *
  65.   * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
  66.   *
  67.   * Redistribution and use in source and binary forms, with or without modification,
  68.   * are permitted provided that the following conditions are met:
  69.   *   1. Redistributions of source code must retain the above copyright notice,
  70.   *      this list of conditions and the following disclaimer.
  71.   *   2. Redistributions in binary form must reproduce the above copyright notice,
  72.   *      this list of conditions and the following disclaimer in the documentation
  73.   *      and/or other materials provided with the distribution.
  74.   *   3. Neither the name of STMicroelectronics nor the names of its contributors
  75.   *      may be used to endorse or promote products derived from this software
  76.   *      without specific prior written permission.
  77.   *
  78.   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  79.   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  80.   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  81.   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  82.   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  83.   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  84.   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  85.   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  86.   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  87.   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  88.   *
  89.   ******************************************************************************
  90.   */
  91.  
  92. /* Includes ------------------------------------------------------------------*/
  93. #include "stm32f1xx_hal.h"
  94.  
  95. /** @addtogroup STM32F1xx_HAL_Driver
  96.   * @{
  97.   */
  98.  
  99. #ifdef HAL_SRAM_MODULE_ENABLED
  100.  
  101. #if defined (STM32F101xE) || defined(STM32F103xE) || defined(STM32F101xG) || defined(STM32F103xG) || defined(STM32F100xE)
  102.  
  103. /** @defgroup SRAM SRAM
  104.   * @brief SRAM driver modules
  105.   * @{
  106.   */
  107. /* Private typedef -----------------------------------------------------------*/
  108. /* Private define ------------------------------------------------------------*/
  109. /* Private macro -------------------------------------------------------------*/    
  110. /* Private variables ---------------------------------------------------------*/
  111. /* Private function prototypes -----------------------------------------------*/
  112. /* Exported functions --------------------------------------------------------*/
  113.  
  114. /** @defgroup SRAM_Exported_Functions SRAM Exported Functions
  115.   * @{
  116.   */
  117.  
  118. /** @defgroup SRAM_Exported_Functions_Group1 Initialization and de-initialization functions
  119.   * @brief    Initialization and Configuration functions.
  120.   *
  121.   @verbatim    
  122.   ==============================================================================
  123.            ##### SRAM Initialization and de_initialization functions #####
  124.   ==============================================================================
  125.     [..]  This section provides functions allowing to initialize/de-initialize
  126.           the SRAM memory
  127.  
  128. @endverbatim
  129.   * @{
  130.   */
  131.  
  132. /**
  133.   * @brief  Performs the SRAM device initialization sequence
  134.   * @param  hsram: pointer to a SRAM_HandleTypeDef structure that contains
  135.   *                the configuration information for SRAM module.
  136.   * @param  Timing: Pointer to SRAM control timing structure
  137.   * @param  ExtTiming: Pointer to SRAM extended mode timing structure  
  138.   * @retval HAL status
  139.   */
  140. HAL_StatusTypeDef HAL_SRAM_Init(SRAM_HandleTypeDef *hsram, FSMC_NORSRAM_TimingTypeDef *Timing, FSMC_NORSRAM_TimingTypeDef *ExtTiming)
  141. {
  142.   /* Check the SRAM handle parameter */
  143.   if(hsram == NULL)
  144.   {
  145.      return HAL_ERROR;
  146.   }
  147.  
  148.   if(hsram->State == HAL_SRAM_STATE_RESET)
  149.   {  
  150.     /* Allocate lock resource and initialize it */
  151.     hsram->Lock = HAL_UNLOCKED;
  152.    
  153.     /* Initialize the low level hardware (MSP) */
  154.     HAL_SRAM_MspInit(hsram);
  155.   }
  156.  
  157.   /* Initialize SRAM control Interface */
  158.   FSMC_NORSRAM_Init(hsram->Instance, &(hsram->Init));
  159.  
  160.   /* Initialize SRAM timing Interface */
  161.   FSMC_NORSRAM_Timing_Init(hsram->Instance, Timing, hsram->Init.NSBank);
  162.  
  163.   /* Initialize SRAM extended mode timing Interface */
  164.   FSMC_NORSRAM_Extended_Timing_Init(hsram->Extended, ExtTiming, hsram->Init.NSBank,  hsram->Init.ExtendedMode);  
  165.  
  166.   /* Enable the NORSRAM device */
  167.   __FSMC_NORSRAM_ENABLE(hsram->Instance, hsram->Init.NSBank);
  168.  
  169.   return HAL_OK;
  170. }
  171.  
  172. /**
  173.   * @brief  Performs the SRAM device De-initialization sequence.
  174.   * @param  hsram: pointer to a SRAM_HandleTypeDef structure that contains
  175.   *                the configuration information for SRAM module.
  176.   * @retval HAL status
  177.   */
  178. HAL_StatusTypeDef  HAL_SRAM_DeInit(SRAM_HandleTypeDef *hsram)
  179. {
  180.   /* De-Initialize the low level hardware (MSP) */
  181.   HAL_SRAM_MspDeInit(hsram);
  182.    
  183.   /* Configure the SRAM registers with their reset values */
  184.   FSMC_NORSRAM_DeInit(hsram->Instance, hsram->Extended, hsram->Init.NSBank);
  185.  
  186.   hsram->State = HAL_SRAM_STATE_RESET;
  187.  
  188.   /* Release Lock */
  189.   __HAL_UNLOCK(hsram);
  190.  
  191.   return HAL_OK;
  192. }
  193.  
  194. /**
  195.   * @brief  SRAM MSP Init.
  196.   * @param  hsram: pointer to a SRAM_HandleTypeDef structure that contains
  197.   *                the configuration information for SRAM module.
  198.   * @retval None
  199.   */
  200. __weak void HAL_SRAM_MspInit(SRAM_HandleTypeDef *hsram)
  201. {
  202.   /* Prevent unused argument(s) compilation warning */
  203.   UNUSED(hsram);
  204.   /* NOTE : This function Should not be modified, when the callback is needed,
  205.             the HAL_SRAM_MspInit could be implemented in the user file
  206.    */
  207. }
  208.  
  209. /**
  210.   * @brief  SRAM MSP DeInit.
  211.   * @param  hsram: pointer to a SRAM_HandleTypeDef structure that contains
  212.   *                the configuration information for SRAM module.
  213.   * @retval None
  214.   */
  215. __weak void HAL_SRAM_MspDeInit(SRAM_HandleTypeDef *hsram)
  216. {
  217.   /* Prevent unused argument(s) compilation warning */
  218.   UNUSED(hsram);
  219.   /* NOTE : This function Should not be modified, when the callback is needed,
  220.             the HAL_SRAM_MspDeInit could be implemented in the user file
  221.    */
  222. }
  223.  
  224. /**
  225.   * @brief  DMA transfer complete callback.
  226.   * @param  hdma: pointer to a SRAM_HandleTypeDef structure that contains
  227.   *                the configuration information for SRAM module.
  228.   * @retval None
  229.   */
  230. __weak void HAL_SRAM_DMA_XferCpltCallback(DMA_HandleTypeDef *hdma)
  231. {
  232.   /* Prevent unused argument(s) compilation warning */
  233.   UNUSED(hdma);
  234.   /* NOTE : This function Should not be modified, when the callback is needed,
  235.             the HAL_SRAM_DMA_XferCpltCallback could be implemented in the user file
  236.    */
  237. }
  238.  
  239. /**
  240.   * @brief  DMA transfer complete error callback.
  241.   * @param  hdma: pointer to a SRAM_HandleTypeDef structure that contains
  242.   *                the configuration information for SRAM module.
  243.   * @retval None
  244.   */
  245. __weak void HAL_SRAM_DMA_XferErrorCallback(DMA_HandleTypeDef *hdma)
  246. {
  247.   /* Prevent unused argument(s) compilation warning */
  248.   UNUSED(hdma);
  249.   /* NOTE : This function Should not be modified, when the callback is needed,
  250.             the HAL_SRAM_DMA_XferErrorCallback could be implemented in the user file
  251.    */
  252. }
  253.  
  254. /**
  255.   * @}
  256.   */
  257.  
  258. /** @defgroup SRAM_Exported_Functions_Group2 Input Output and memory control functions
  259.   * @brief    Input Output and memory control functions
  260.   *
  261.   @verbatim    
  262.   ==============================================================================
  263.                   ##### SRAM Input and Output functions #####
  264.   ==============================================================================
  265.   [..]  
  266.     This section provides functions allowing to use and control the SRAM memory
  267.  
  268. @endverbatim
  269.   * @{
  270.   */
  271.  
  272. /**
  273.   * @brief  Reads 8-bit buffer from SRAM memory.
  274.   * @param  hsram: pointer to a SRAM_HandleTypeDef structure that contains
  275.   *                the configuration information for SRAM module.
  276.   * @param  pAddress: Pointer to read start address
  277.   * @param  pDstBuffer: Pointer to destination buffer  
  278.   * @param  BufferSize: Size of the buffer to read from memory
  279.   * @retval HAL status
  280.   */
  281. HAL_StatusTypeDef HAL_SRAM_Read_8b(SRAM_HandleTypeDef *hsram, uint32_t *pAddress, uint8_t *pDstBuffer, uint32_t BufferSize)
  282. {
  283.   __IO uint8_t * psramaddress = (uint8_t *)pAddress;
  284.  
  285.   /* Process Locked */
  286.   __HAL_LOCK(hsram);
  287.  
  288.   /* Update the SRAM controller state */
  289.   hsram->State = HAL_SRAM_STATE_BUSY;  
  290.  
  291.   /* Read data from memory */
  292.   for(; BufferSize != 0U; BufferSize--)
  293.   {
  294.     *pDstBuffer = *(__IO uint8_t *)psramaddress;
  295.     pDstBuffer++;
  296.     psramaddress++;
  297.   }
  298.  
  299.   /* Update the SRAM controller state */
  300.   hsram->State = HAL_SRAM_STATE_READY;    
  301.  
  302.   /* Process unlocked */
  303.   __HAL_UNLOCK(hsram);
  304.    
  305.   return HAL_OK;  
  306. }
  307.  
  308. /**
  309.   * @brief  Writes 8-bit buffer to SRAM memory.
  310.   * @param  hsram: pointer to a SRAM_HandleTypeDef structure that contains
  311.   *                the configuration information for SRAM module.
  312.   * @param  pAddress: Pointer to write start address
  313.   * @param  pSrcBuffer: Pointer to source buffer to write  
  314.   * @param  BufferSize: Size of the buffer to write to memory
  315.   * @retval HAL status
  316.   */
  317. HAL_StatusTypeDef HAL_SRAM_Write_8b(SRAM_HandleTypeDef *hsram, uint32_t *pAddress, uint8_t *pSrcBuffer, uint32_t BufferSize)
  318. {
  319.   __IO uint8_t * psramaddress = (uint8_t *)pAddress;
  320.  
  321.   /* Check the SRAM controller state */
  322.   if(hsram->State == HAL_SRAM_STATE_PROTECTED)
  323.   {
  324.     return  HAL_ERROR;
  325.   }
  326.  
  327.   /* Process Locked */
  328.   __HAL_LOCK(hsram);
  329.  
  330.   /* Update the SRAM controller state */
  331.   hsram->State = HAL_SRAM_STATE_BUSY;
  332.  
  333.   /* Write data to memory */
  334.   for(; BufferSize != 0U; BufferSize--)
  335.   {
  336.     *(__IO uint8_t *)psramaddress = *pSrcBuffer;
  337.     pSrcBuffer++;
  338.     psramaddress++;    
  339.   }    
  340.  
  341.   /* Update the SRAM controller state */
  342.   hsram->State = HAL_SRAM_STATE_READY;
  343.  
  344.   /* Process unlocked */
  345.   __HAL_UNLOCK(hsram);
  346.    
  347.   return HAL_OK;  
  348. }
  349.  
  350. /**
  351.   * @brief  Reads 16-bit buffer from SRAM memory.
  352.   * @param  hsram: pointer to a SRAM_HandleTypeDef structure that contains
  353.   *                the configuration information for SRAM module.
  354.   * @param  pAddress: Pointer to read start address
  355.   * @param  pDstBuffer: Pointer to destination buffer  
  356.   * @param  BufferSize: Size of the buffer to read from memory
  357.   * @retval HAL status
  358.   */
  359. HAL_StatusTypeDef HAL_SRAM_Read_16b(SRAM_HandleTypeDef *hsram, uint32_t *pAddress, uint16_t *pDstBuffer, uint32_t BufferSize)
  360. {
  361.   __IO uint16_t * psramaddress = (uint16_t *)pAddress;
  362.  
  363.   /* Process Locked */
  364.   __HAL_LOCK(hsram);
  365.  
  366.   /* Update the SRAM controller state */
  367.   hsram->State = HAL_SRAM_STATE_BUSY;  
  368.  
  369.   /* Read data from memory */
  370.   for(; BufferSize != 0U; BufferSize--)
  371.   {
  372.     *pDstBuffer = *(__IO uint16_t *)psramaddress;
  373.     pDstBuffer++;
  374.     psramaddress++;
  375.   }
  376.  
  377.   /* Update the SRAM controller state */
  378.   hsram->State = HAL_SRAM_STATE_READY;    
  379.  
  380.   /* Process unlocked */
  381.   __HAL_UNLOCK(hsram);
  382.    
  383.   return HAL_OK;  
  384. }
  385.  
  386. /**
  387.   * @brief  Writes 16-bit buffer to SRAM memory.
  388.   * @param  hsram: pointer to a SRAM_HandleTypeDef structure that contains
  389.   *                the configuration information for SRAM module.
  390.   * @param  pAddress: Pointer to write start address
  391.   * @param  pSrcBuffer: Pointer to source buffer to write  
  392.   * @param  BufferSize: Size of the buffer to write to memory
  393.   * @retval HAL status
  394.   */
  395. HAL_StatusTypeDef HAL_SRAM_Write_16b(SRAM_HandleTypeDef *hsram, uint32_t *pAddress, uint16_t *pSrcBuffer, uint32_t BufferSize)
  396. {
  397.   __IO uint16_t * psramaddress = (uint16_t *)pAddress;
  398.  
  399.   /* Check the SRAM controller state */
  400.   if(hsram->State == HAL_SRAM_STATE_PROTECTED)
  401.   {
  402.     return  HAL_ERROR;
  403.   }
  404.  
  405.   /* Process Locked */
  406.   __HAL_LOCK(hsram);
  407.  
  408.   /* Update the SRAM controller state */
  409.   hsram->State = HAL_SRAM_STATE_BUSY;
  410.  
  411.   /* Write data to memory */
  412.   for(; BufferSize != 0U; BufferSize--)
  413.   {
  414.     *(__IO uint16_t *)psramaddress = *pSrcBuffer;
  415.     pSrcBuffer++;
  416.     psramaddress++;    
  417.   }    
  418.  
  419.   /* Update the SRAM controller state */
  420.   hsram->State = HAL_SRAM_STATE_READY;
  421.  
  422.   /* Process unlocked */
  423.   __HAL_UNLOCK(hsram);
  424.    
  425.   return HAL_OK;  
  426. }
  427.  
  428. /**
  429.   * @brief  Reads 32-bit buffer from SRAM memory.
  430.   * @param  hsram: pointer to a SRAM_HandleTypeDef structure that contains
  431.   *                the configuration information for SRAM module.
  432.   * @param  pAddress: Pointer to read start address
  433.   * @param  pDstBuffer: Pointer to destination buffer  
  434.   * @param  BufferSize: Size of the buffer to read from memory
  435.   * @retval HAL status
  436.   */
  437. HAL_StatusTypeDef HAL_SRAM_Read_32b(SRAM_HandleTypeDef *hsram, uint32_t *pAddress, uint32_t *pDstBuffer, uint32_t BufferSize)
  438. {
  439.   /* Process Locked */
  440.   __HAL_LOCK(hsram);
  441.  
  442.   /* Update the SRAM controller state */
  443.   hsram->State = HAL_SRAM_STATE_BUSY;  
  444.  
  445.   /* Read data from memory */
  446.   for(; BufferSize != 0U; BufferSize--)
  447.   {
  448.     *pDstBuffer = *(__IO uint32_t *)pAddress;
  449.     pDstBuffer++;
  450.     pAddress++;
  451.   }
  452.  
  453.   /* Update the SRAM controller state */
  454.   hsram->State = HAL_SRAM_STATE_READY;    
  455.  
  456.   /* Process unlocked */
  457.   __HAL_UNLOCK(hsram);
  458.    
  459.   return HAL_OK;  
  460. }
  461.  
  462. /**
  463.   * @brief  Writes 32-bit buffer to SRAM memory.
  464.   * @param  hsram: pointer to a SRAM_HandleTypeDef structure that contains
  465.   *                the configuration information for SRAM module.
  466.   * @param  pAddress: Pointer to write start address
  467.   * @param  pSrcBuffer: Pointer to source buffer to write  
  468.   * @param  BufferSize: Size of the buffer to write to memory
  469.   * @retval HAL status
  470.   */
  471. HAL_StatusTypeDef HAL_SRAM_Write_32b(SRAM_HandleTypeDef *hsram, uint32_t *pAddress, uint32_t *pSrcBuffer, uint32_t BufferSize)
  472. {
  473.   /* Check the SRAM controller state */
  474.   if(hsram->State == HAL_SRAM_STATE_PROTECTED)
  475.   {
  476.     return  HAL_ERROR;
  477.   }
  478.  
  479.   /* Process Locked */
  480.   __HAL_LOCK(hsram);
  481.  
  482.   /* Update the SRAM controller state */
  483.   hsram->State = HAL_SRAM_STATE_BUSY;
  484.  
  485.   /* Write data to memory */
  486.   for(; BufferSize != 0U; BufferSize--)
  487.   {
  488.     *(__IO uint32_t *)pAddress = *pSrcBuffer;
  489.     pSrcBuffer++;
  490.     pAddress++;    
  491.   }    
  492.  
  493.   /* Update the SRAM controller state */
  494.   hsram->State = HAL_SRAM_STATE_READY;
  495.  
  496.   /* Process unlocked */
  497.   __HAL_UNLOCK(hsram);
  498.    
  499.   return HAL_OK;  
  500. }
  501.  
  502. /**
  503.   * @brief  Reads a Words data from the SRAM memory using DMA transfer.
  504.   * @param  hsram: pointer to a SRAM_HandleTypeDef structure that contains
  505.   *                the configuration information for SRAM module.
  506.   * @param  pAddress: Pointer to read start address
  507.   * @param  pDstBuffer: Pointer to destination buffer  
  508.   * @param  BufferSize: Size of the buffer to read from memory
  509.   * @retval HAL status
  510.   */
  511. HAL_StatusTypeDef HAL_SRAM_Read_DMA(SRAM_HandleTypeDef *hsram, uint32_t *pAddress, uint32_t *pDstBuffer, uint32_t BufferSize)
  512. {
  513.   /* Process Locked */
  514.   __HAL_LOCK(hsram);  
  515.  
  516.   /* Update the SRAM controller state */
  517.   hsram->State = HAL_SRAM_STATE_BUSY;  
  518.  
  519.   /* Configure DMA user callbacks */
  520.   hsram->hdma->XferCpltCallback  = HAL_SRAM_DMA_XferCpltCallback;
  521.   hsram->hdma->XferErrorCallback = HAL_SRAM_DMA_XferErrorCallback;
  522.  
  523.   /* Enable the DMA Channel */
  524.   HAL_DMA_Start_IT(hsram->hdma, (uint32_t)pAddress, (uint32_t)pDstBuffer, (uint32_t)BufferSize);
  525.  
  526.   /* Update the SRAM controller state */
  527.   hsram->State = HAL_SRAM_STATE_READY;
  528.  
  529.   /* Process unlocked */
  530.   __HAL_UNLOCK(hsram);  
  531.  
  532.   return HAL_OK;
  533. }
  534.  
  535. /**
  536.   * @brief  Writes a Words data buffer to SRAM memory using DMA transfer.
  537.   * @param  hsram: pointer to a SRAM_HandleTypeDef structure that contains
  538.   *                the configuration information for SRAM module.
  539.   * @param  pAddress: Pointer to write start address
  540.   * @param  pSrcBuffer: Pointer to source buffer to write  
  541.   * @param  BufferSize: Size of the buffer to write to memory
  542.   * @retval HAL status
  543.   */
  544. HAL_StatusTypeDef HAL_SRAM_Write_DMA(SRAM_HandleTypeDef *hsram, uint32_t *pAddress, uint32_t *pSrcBuffer, uint32_t BufferSize)
  545. {
  546.   /* Check the SRAM controller state */
  547.   if(hsram->State == HAL_SRAM_STATE_PROTECTED)
  548.   {
  549.     return  HAL_ERROR;
  550.   }
  551.  
  552.   /* Process Locked */
  553.   __HAL_LOCK(hsram);
  554.  
  555.   /* Update the SRAM controller state */
  556.   hsram->State = HAL_SRAM_STATE_BUSY;
  557.  
  558.   /* Configure DMA user callbacks */
  559.   hsram->hdma->XferCpltCallback  = HAL_SRAM_DMA_XferCpltCallback;
  560.   hsram->hdma->XferErrorCallback = HAL_SRAM_DMA_XferErrorCallback;
  561.  
  562.   /* Enable the DMA Channel */
  563.   HAL_DMA_Start_IT(hsram->hdma, (uint32_t)pSrcBuffer, (uint32_t)pAddress, (uint32_t)BufferSize);
  564.  
  565.   /* Update the SRAM controller state */
  566.   hsram->State = HAL_SRAM_STATE_READY;  
  567.  
  568.   /* Process unlocked */
  569.   __HAL_UNLOCK(hsram);  
  570.  
  571.   return HAL_OK;
  572. }
  573.  
  574. /**
  575.   * @}
  576.   */
  577.  
  578. /** @defgroup SRAM_Exported_Functions_Group3 Control functions
  579.  *  @brief   Control functions
  580.  *
  581. @verbatim  
  582.   ==============================================================================
  583.                         ##### SRAM Control functions #####
  584.   ==============================================================================  
  585.   [..]
  586.     This subsection provides a set of functions allowing to control dynamically
  587.     the SRAM interface.
  588.  
  589. @endverbatim
  590.   * @{
  591.   */
  592.    
  593. /**
  594.   * @brief  Enables dynamically SRAM write operation.
  595.   * @param  hsram: pointer to a SRAM_HandleTypeDef structure that contains
  596.   *                the configuration information for SRAM module.
  597.   * @retval HAL status
  598.   */
  599. HAL_StatusTypeDef HAL_SRAM_WriteOperation_Enable(SRAM_HandleTypeDef *hsram)
  600. {
  601.   /* Process Locked */
  602.   __HAL_LOCK(hsram);
  603.  
  604.   /* Enable write operation */
  605.   FSMC_NORSRAM_WriteOperation_Enable(hsram->Instance, hsram->Init.NSBank);
  606.  
  607.   /* Update the SRAM controller state */
  608.   hsram->State = HAL_SRAM_STATE_READY;
  609.  
  610.   /* Process unlocked */
  611.   __HAL_UNLOCK(hsram);
  612.  
  613.   return HAL_OK;  
  614. }
  615.  
  616. /**
  617.   * @brief  Disables dynamically SRAM write operation.
  618.   * @param  hsram: pointer to a SRAM_HandleTypeDef structure that contains
  619.   *                the configuration information for SRAM module.
  620.   * @retval HAL status
  621.   */
  622. HAL_StatusTypeDef HAL_SRAM_WriteOperation_Disable(SRAM_HandleTypeDef *hsram)
  623. {
  624.   /* Process Locked */
  625.   __HAL_LOCK(hsram);
  626.  
  627.   /* Update the SRAM controller state */
  628.   hsram->State = HAL_SRAM_STATE_BUSY;
  629.    
  630.   /* Disable write operation */
  631.   FSMC_NORSRAM_WriteOperation_Disable(hsram->Instance, hsram->Init.NSBank);
  632.  
  633.   /* Update the SRAM controller state */
  634.   hsram->State = HAL_SRAM_STATE_PROTECTED;
  635.  
  636.   /* Process unlocked */
  637.   __HAL_UNLOCK(hsram);
  638.  
  639.   return HAL_OK;  
  640. }
  641.  
  642. /**
  643.   * @}
  644.   */
  645.  
  646. /** @defgroup SRAM_Exported_Functions_Group4 Peripheral State functions
  647.  *  @brief   Peripheral State functions
  648.  *
  649. @verbatim  
  650.   ==============================================================================
  651.                       ##### SRAM State functions #####
  652.   ==============================================================================  
  653.   [..]
  654.     This subsection permits to get in run-time the status of the SRAM controller
  655.     and the data flow.
  656.  
  657. @endverbatim
  658.   * @{
  659.   */
  660.  
  661. /**
  662.   * @brief  Returns the SRAM controller state
  663.   * @param  hsram: pointer to a SRAM_HandleTypeDef structure that contains
  664.   *                the configuration information for SRAM module.
  665.   * @retval HAL state
  666.   */
  667. HAL_SRAM_StateTypeDef HAL_SRAM_GetState(SRAM_HandleTypeDef *hsram)
  668. {
  669.   return hsram->State;
  670. }
  671.  
  672. /**
  673.   * @}
  674.   */
  675.  
  676. /**
  677.   * @}
  678.   */
  679.  
  680. /**
  681.   * @}
  682.   */
  683. #endif /* STM32F101xE || STM32F103xE || STM32F101xG || STM32F103xG || STM32F100xE */
  684. #endif /* HAL_SRAM_MODULE_ENABLED */
  685.  
  686. /**
  687.   * @}
  688.   */
  689.  
  690. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
  691.