stm32l4xx_hal_sram.c 23 KB

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