stm32l4xx_hal_sram.c 22 KB

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