1
0

stm32f7xx_hal_sram.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688
  1. /**
  2. ******************************************************************************
  3. * @file stm32f7xx_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 "stm32f7xx_hal.h"
  82. /** @addtogroup STM32F7xx_HAL_Driver
  83. * @{
  84. */
  85. /** @defgroup SRAM SRAM
  86. * @brief SRAM driver modules
  87. * @{
  88. */
  89. #ifdef HAL_SRAM_MODULE_ENABLED
  90. /* Private typedef -----------------------------------------------------------*/
  91. /* Private define ------------------------------------------------------------*/
  92. /* Private macro -------------------------------------------------------------*/
  93. /* Private variables ---------------------------------------------------------*/
  94. /* Private function prototypes -----------------------------------------------*/
  95. /* Exported functions --------------------------------------------------------*/
  96. /** @defgroup SRAM_Exported_Functions SRAM Exported Functions
  97. * @{
  98. */
  99. /** @defgroup SRAM_Exported_Functions_Group1 Initialization and de-initialization functions
  100. * @brief Initialization and Configuration functions.
  101. *
  102. @verbatim
  103. ==============================================================================
  104. ##### SRAM Initialization and de_initialization functions #####
  105. ==============================================================================
  106. [..] This section provides functions allowing to initialize/de-initialize
  107. the SRAM memory
  108. @endverbatim
  109. * @{
  110. */
  111. /**
  112. * @brief Performs the SRAM device initialization sequence
  113. * @param hsram pointer to a SRAM_HandleTypeDef structure that contains
  114. * the configuration information for SRAM module.
  115. * @param Timing Pointer to SRAM control timing structure
  116. * @param ExtTiming Pointer to SRAM extended mode timing structure
  117. * @retval HAL status
  118. */
  119. HAL_StatusTypeDef HAL_SRAM_Init(SRAM_HandleTypeDef *hsram, FMC_NORSRAM_TimingTypeDef *Timing, FMC_NORSRAM_TimingTypeDef *ExtTiming)
  120. {
  121. /* Check the SRAM handle parameter */
  122. if(hsram == NULL)
  123. {
  124. return HAL_ERROR;
  125. }
  126. if(hsram->State == HAL_SRAM_STATE_RESET)
  127. {
  128. /* Allocate lock resource and initialize it */
  129. hsram->Lock = HAL_UNLOCKED;
  130. /* Initialize the low level hardware (MSP) */
  131. HAL_SRAM_MspInit(hsram);
  132. }
  133. /* Initialize SRAM control Interface */
  134. FMC_NORSRAM_Init(hsram->Instance, &(hsram->Init));
  135. /* Initialize SRAM timing Interface */
  136. FMC_NORSRAM_Timing_Init(hsram->Instance, Timing, hsram->Init.NSBank);
  137. /* Initialize SRAM extended mode timing Interface */
  138. FMC_NORSRAM_Extended_Timing_Init(hsram->Extended, ExtTiming, hsram->Init.NSBank, hsram->Init.ExtendedMode);
  139. /* Enable the NORSRAM device */
  140. __FMC_NORSRAM_ENABLE(hsram->Instance, hsram->Init.NSBank);
  141. return HAL_OK;
  142. }
  143. /**
  144. * @brief Performs the SRAM device De-initialization sequence.
  145. * @param hsram pointer to a SRAM_HandleTypeDef structure that contains
  146. * the configuration information for SRAM module.
  147. * @retval HAL status
  148. */
  149. HAL_StatusTypeDef HAL_SRAM_DeInit(SRAM_HandleTypeDef *hsram)
  150. {
  151. /* De-Initialize the low level hardware (MSP) */
  152. HAL_SRAM_MspDeInit(hsram);
  153. /* Configure the SRAM registers with their reset values */
  154. FMC_NORSRAM_DeInit(hsram->Instance, hsram->Extended, hsram->Init.NSBank);
  155. hsram->State = HAL_SRAM_STATE_RESET;
  156. /* Release Lock */
  157. __HAL_UNLOCK(hsram);
  158. return HAL_OK;
  159. }
  160. /**
  161. * @brief SRAM MSP Init.
  162. * @param hsram pointer to a SRAM_HandleTypeDef structure that contains
  163. * the configuration information for SRAM module.
  164. * @retval None
  165. */
  166. __weak void HAL_SRAM_MspInit(SRAM_HandleTypeDef *hsram)
  167. {
  168. /* Prevent unused argument(s) compilation warning */
  169. UNUSED(hsram);
  170. /* NOTE : This function Should not be modified, when the callback is needed,
  171. the HAL_SRAM_MspInit could be implemented in the user file
  172. */
  173. }
  174. /**
  175. * @brief SRAM MSP DeInit.
  176. * @param hsram pointer to a SRAM_HandleTypeDef structure that contains
  177. * the configuration information for SRAM module.
  178. * @retval None
  179. */
  180. __weak void HAL_SRAM_MspDeInit(SRAM_HandleTypeDef *hsram)
  181. {
  182. /* Prevent unused argument(s) compilation warning */
  183. UNUSED(hsram);
  184. /* NOTE : This function Should not be modified, when the callback is needed,
  185. the HAL_SRAM_MspDeInit could be implemented in the user file
  186. */
  187. }
  188. /**
  189. * @brief DMA transfer complete callback.
  190. * @param hdma pointer to a SRAM_HandleTypeDef structure that contains
  191. * the configuration information for SRAM module.
  192. * @retval None
  193. */
  194. __weak void HAL_SRAM_DMA_XferCpltCallback(DMA_HandleTypeDef *hdma)
  195. {
  196. /* Prevent unused argument(s) compilation warning */
  197. UNUSED(hdma);
  198. /* NOTE : This function Should not be modified, when the callback is needed,
  199. the HAL_SRAM_DMA_XferCpltCallback could be implemented in the user file
  200. */
  201. }
  202. /**
  203. * @brief DMA transfer complete error callback.
  204. * @param hdma pointer to a SRAM_HandleTypeDef structure that contains
  205. * the configuration information for SRAM module.
  206. * @retval None
  207. */
  208. __weak void HAL_SRAM_DMA_XferErrorCallback(DMA_HandleTypeDef *hdma)
  209. {
  210. /* Prevent unused argument(s) compilation warning */
  211. UNUSED(hdma);
  212. /* NOTE : This function Should not be modified, when the callback is needed,
  213. the HAL_SRAM_DMA_XferErrorCallback could be implemented in the user file
  214. */
  215. }
  216. /**
  217. * @}
  218. */
  219. /** @defgroup SRAM_Exported_Functions_Group2 Input Output and memory control functions
  220. * @brief Input Output and memory control functions
  221. *
  222. @verbatim
  223. ==============================================================================
  224. ##### SRAM Input and Output functions #####
  225. ==============================================================================
  226. [..]
  227. This section provides functions allowing to use and control the SRAM memory
  228. @endverbatim
  229. * @{
  230. */
  231. /**
  232. * @brief Reads 8-bit buffer from SRAM memory.
  233. * @param hsram pointer to a SRAM_HandleTypeDef structure that contains
  234. * the configuration information for SRAM module.
  235. * @param pAddress Pointer to read start address
  236. * @param pDstBuffer Pointer to destination buffer
  237. * @param BufferSize Size of the buffer to read from memory
  238. * @retval HAL status
  239. */
  240. HAL_StatusTypeDef HAL_SRAM_Read_8b(SRAM_HandleTypeDef *hsram, uint32_t *pAddress, uint8_t *pDstBuffer, uint32_t BufferSize)
  241. {
  242. __IO uint8_t * psramaddress = (uint8_t *)pAddress;
  243. /* Process Locked */
  244. __HAL_LOCK(hsram);
  245. /* Update the SRAM controller state */
  246. hsram->State = HAL_SRAM_STATE_BUSY;
  247. /* Read data from memory */
  248. for(; BufferSize != 0; BufferSize--)
  249. {
  250. *pDstBuffer = *(__IO uint8_t *)psramaddress;
  251. pDstBuffer++;
  252. psramaddress++;
  253. }
  254. /* Update the SRAM controller state */
  255. hsram->State = HAL_SRAM_STATE_READY;
  256. /* Process unlocked */
  257. __HAL_UNLOCK(hsram);
  258. return HAL_OK;
  259. }
  260. /**
  261. * @brief Writes 8-bit buffer to SRAM memory.
  262. * @param hsram pointer to a SRAM_HandleTypeDef structure that contains
  263. * the configuration information for SRAM module.
  264. * @param pAddress Pointer to write start address
  265. * @param pSrcBuffer Pointer to source buffer to write
  266. * @param BufferSize Size of the buffer to write to memory
  267. * @retval HAL status
  268. */
  269. HAL_StatusTypeDef HAL_SRAM_Write_8b(SRAM_HandleTypeDef *hsram, uint32_t *pAddress, uint8_t *pSrcBuffer, uint32_t BufferSize)
  270. {
  271. __IO uint8_t * psramaddress = (uint8_t *)pAddress;
  272. /* Check the SRAM controller state */
  273. if(hsram->State == HAL_SRAM_STATE_PROTECTED)
  274. {
  275. return HAL_ERROR;
  276. }
  277. /* Process Locked */
  278. __HAL_LOCK(hsram);
  279. /* Update the SRAM controller state */
  280. hsram->State = HAL_SRAM_STATE_BUSY;
  281. /* Write data to memory */
  282. for(; BufferSize != 0; BufferSize--)
  283. {
  284. *(__IO uint8_t *)psramaddress = *pSrcBuffer;
  285. pSrcBuffer++;
  286. psramaddress++;
  287. }
  288. /* Update the SRAM controller state */
  289. hsram->State = HAL_SRAM_STATE_READY;
  290. /* Process unlocked */
  291. __HAL_UNLOCK(hsram);
  292. return HAL_OK;
  293. }
  294. /**
  295. * @brief Reads 16-bit buffer from SRAM memory.
  296. * @param hsram pointer to a SRAM_HandleTypeDef structure that contains
  297. * the configuration information for SRAM module.
  298. * @param pAddress Pointer to read start address
  299. * @param pDstBuffer Pointer to destination buffer
  300. * @param BufferSize Size of the buffer to read from memory
  301. * @retval HAL status
  302. */
  303. HAL_StatusTypeDef HAL_SRAM_Read_16b(SRAM_HandleTypeDef *hsram, uint32_t *pAddress, uint16_t *pDstBuffer, uint32_t BufferSize)
  304. {
  305. __IO uint16_t * psramaddress = (uint16_t *)pAddress;
  306. /* Process Locked */
  307. __HAL_LOCK(hsram);
  308. /* Update the SRAM controller state */
  309. hsram->State = HAL_SRAM_STATE_BUSY;
  310. /* Read data from memory */
  311. for(; BufferSize != 0; BufferSize--)
  312. {
  313. *pDstBuffer = *(__IO uint16_t *)psramaddress;
  314. pDstBuffer++;
  315. psramaddress++;
  316. }
  317. /* Update the SRAM controller state */
  318. hsram->State = HAL_SRAM_STATE_READY;
  319. /* Process unlocked */
  320. __HAL_UNLOCK(hsram);
  321. return HAL_OK;
  322. }
  323. /**
  324. * @brief Writes 16-bit buffer to SRAM memory.
  325. * @param hsram pointer to a SRAM_HandleTypeDef structure that contains
  326. * the configuration information for SRAM module.
  327. * @param pAddress Pointer to write start address
  328. * @param pSrcBuffer Pointer to source buffer to write
  329. * @param BufferSize Size of the buffer to write to memory
  330. * @retval HAL status
  331. */
  332. HAL_StatusTypeDef HAL_SRAM_Write_16b(SRAM_HandleTypeDef *hsram, uint32_t *pAddress, uint16_t *pSrcBuffer, uint32_t BufferSize)
  333. {
  334. __IO uint16_t * psramaddress = (uint16_t *)pAddress;
  335. /* Check the SRAM controller state */
  336. if(hsram->State == HAL_SRAM_STATE_PROTECTED)
  337. {
  338. return HAL_ERROR;
  339. }
  340. /* Process Locked */
  341. __HAL_LOCK(hsram);
  342. /* Update the SRAM controller state */
  343. hsram->State = HAL_SRAM_STATE_BUSY;
  344. /* Write data to memory */
  345. for(; BufferSize != 0; BufferSize--)
  346. {
  347. *(__IO uint16_t *)psramaddress = *pSrcBuffer;
  348. pSrcBuffer++;
  349. psramaddress++;
  350. }
  351. /* Update the SRAM controller state */
  352. hsram->State = HAL_SRAM_STATE_READY;
  353. /* Process unlocked */
  354. __HAL_UNLOCK(hsram);
  355. return HAL_OK;
  356. }
  357. /**
  358. * @brief Reads 32-bit buffer from SRAM memory.
  359. * @param hsram pointer to a SRAM_HandleTypeDef structure that contains
  360. * the configuration information for SRAM module.
  361. * @param pAddress Pointer to read start address
  362. * @param pDstBuffer Pointer to destination buffer
  363. * @param BufferSize Size of the buffer to read from memory
  364. * @retval HAL status
  365. */
  366. HAL_StatusTypeDef HAL_SRAM_Read_32b(SRAM_HandleTypeDef *hsram, uint32_t *pAddress, uint32_t *pDstBuffer, uint32_t BufferSize)
  367. {
  368. /* Process Locked */
  369. __HAL_LOCK(hsram);
  370. /* Update the SRAM controller state */
  371. hsram->State = HAL_SRAM_STATE_BUSY;
  372. /* Read data from memory */
  373. for(; BufferSize != 0; BufferSize--)
  374. {
  375. *pDstBuffer = *(__IO uint32_t *)pAddress;
  376. pDstBuffer++;
  377. pAddress++;
  378. }
  379. /* Update the SRAM controller state */
  380. hsram->State = HAL_SRAM_STATE_READY;
  381. /* Process unlocked */
  382. __HAL_UNLOCK(hsram);
  383. return HAL_OK;
  384. }
  385. /**
  386. * @brief Writes 32-bit buffer to SRAM memory.
  387. * @param hsram pointer to a SRAM_HandleTypeDef structure that contains
  388. * the configuration information for SRAM module.
  389. * @param pAddress Pointer to write start address
  390. * @param pSrcBuffer Pointer to source buffer to write
  391. * @param BufferSize Size of the buffer to write to memory
  392. * @retval HAL status
  393. */
  394. HAL_StatusTypeDef HAL_SRAM_Write_32b(SRAM_HandleTypeDef *hsram, uint32_t *pAddress, uint32_t *pSrcBuffer, uint32_t BufferSize)
  395. {
  396. /* Check the SRAM controller state */
  397. if(hsram->State == HAL_SRAM_STATE_PROTECTED)
  398. {
  399. return HAL_ERROR;
  400. }
  401. /* Process Locked */
  402. __HAL_LOCK(hsram);
  403. /* Update the SRAM controller state */
  404. hsram->State = HAL_SRAM_STATE_BUSY;
  405. /* Write data to memory */
  406. for(; BufferSize != 0; BufferSize--)
  407. {
  408. *(__IO uint32_t *)pAddress = *pSrcBuffer;
  409. pSrcBuffer++;
  410. pAddress++;
  411. }
  412. /* Update the SRAM controller state */
  413. hsram->State = HAL_SRAM_STATE_READY;
  414. /* Process unlocked */
  415. __HAL_UNLOCK(hsram);
  416. return HAL_OK;
  417. }
  418. /**
  419. * @brief Reads a Words data from the SRAM memory using DMA transfer.
  420. * @param hsram pointer to a SRAM_HandleTypeDef structure that contains
  421. * the configuration information for SRAM module.
  422. * @param pAddress Pointer to read start address
  423. * @param pDstBuffer Pointer to destination buffer
  424. * @param BufferSize Size of the buffer to read from memory
  425. * @retval HAL status
  426. */
  427. HAL_StatusTypeDef HAL_SRAM_Read_DMA(SRAM_HandleTypeDef *hsram, uint32_t *pAddress, uint32_t *pDstBuffer, uint32_t BufferSize)
  428. {
  429. /* Process Locked */
  430. __HAL_LOCK(hsram);
  431. /* Update the SRAM controller state */
  432. hsram->State = HAL_SRAM_STATE_BUSY;
  433. /* Configure DMA user callbacks */
  434. hsram->hdma->XferCpltCallback = HAL_SRAM_DMA_XferCpltCallback;
  435. hsram->hdma->XferErrorCallback = HAL_SRAM_DMA_XferErrorCallback;
  436. /* Enable the DMA Stream */
  437. HAL_DMA_Start_IT(hsram->hdma, (uint32_t)pAddress, (uint32_t)pDstBuffer, (uint32_t)BufferSize);
  438. /* Update the SRAM controller state */
  439. hsram->State = HAL_SRAM_STATE_READY;
  440. /* Process unlocked */
  441. __HAL_UNLOCK(hsram);
  442. return HAL_OK;
  443. }
  444. /**
  445. * @brief Writes a Words data buffer to SRAM memory using DMA transfer.
  446. * @param hsram pointer to a SRAM_HandleTypeDef structure that contains
  447. * the configuration information for SRAM module.
  448. * @param pAddress Pointer to write start address
  449. * @param pSrcBuffer Pointer to source buffer to write
  450. * @param BufferSize Size of the buffer to write to memory
  451. * @retval HAL status
  452. */
  453. HAL_StatusTypeDef HAL_SRAM_Write_DMA(SRAM_HandleTypeDef *hsram, uint32_t *pAddress, uint32_t *pSrcBuffer, uint32_t BufferSize)
  454. {
  455. /* Check the SRAM controller state */
  456. if(hsram->State == HAL_SRAM_STATE_PROTECTED)
  457. {
  458. return HAL_ERROR;
  459. }
  460. /* Process Locked */
  461. __HAL_LOCK(hsram);
  462. /* Update the SRAM controller state */
  463. hsram->State = HAL_SRAM_STATE_BUSY;
  464. /* Configure DMA user callbacks */
  465. hsram->hdma->XferCpltCallback = HAL_SRAM_DMA_XferCpltCallback;
  466. hsram->hdma->XferErrorCallback = HAL_SRAM_DMA_XferErrorCallback;
  467. /* Enable the DMA Stream */
  468. HAL_DMA_Start_IT(hsram->hdma, (uint32_t)pSrcBuffer, (uint32_t)pAddress, (uint32_t)BufferSize);
  469. /* Update the SRAM controller state */
  470. hsram->State = HAL_SRAM_STATE_READY;
  471. /* Process unlocked */
  472. __HAL_UNLOCK(hsram);
  473. return HAL_OK;
  474. }
  475. /**
  476. * @}
  477. */
  478. /** @defgroup SRAM_Exported_Functions_Group3 Control functions
  479. * @brief Control functions
  480. *
  481. @verbatim
  482. ==============================================================================
  483. ##### SRAM Control functions #####
  484. ==============================================================================
  485. [..]
  486. This subsection provides a set of functions allowing to control dynamically
  487. the SRAM interface.
  488. @endverbatim
  489. * @{
  490. */
  491. /**
  492. * @brief Enables dynamically SRAM write operation.
  493. * @param hsram pointer to a SRAM_HandleTypeDef structure that contains
  494. * the configuration information for SRAM module.
  495. * @retval HAL status
  496. */
  497. HAL_StatusTypeDef HAL_SRAM_WriteOperation_Enable(SRAM_HandleTypeDef *hsram)
  498. {
  499. /* Process Locked */
  500. __HAL_LOCK(hsram);
  501. /* Enable write operation */
  502. FMC_NORSRAM_WriteOperation_Enable(hsram->Instance, hsram->Init.NSBank);
  503. /* Update the SRAM controller state */
  504. hsram->State = HAL_SRAM_STATE_READY;
  505. /* Process unlocked */
  506. __HAL_UNLOCK(hsram);
  507. return HAL_OK;
  508. }
  509. /**
  510. * @brief Disables dynamically SRAM write operation.
  511. * @param hsram pointer to a SRAM_HandleTypeDef structure that contains
  512. * the configuration information for SRAM module.
  513. * @retval HAL status
  514. */
  515. HAL_StatusTypeDef HAL_SRAM_WriteOperation_Disable(SRAM_HandleTypeDef *hsram)
  516. {
  517. /* Process Locked */
  518. __HAL_LOCK(hsram);
  519. /* Update the SRAM controller state */
  520. hsram->State = HAL_SRAM_STATE_BUSY;
  521. /* Disable write operation */
  522. FMC_NORSRAM_WriteOperation_Disable(hsram->Instance, hsram->Init.NSBank);
  523. /* Update the SRAM controller state */
  524. hsram->State = HAL_SRAM_STATE_PROTECTED;
  525. /* Process unlocked */
  526. __HAL_UNLOCK(hsram);
  527. return HAL_OK;
  528. }
  529. /**
  530. * @}
  531. */
  532. /** @defgroup SRAM_Exported_Functions_Group4 Peripheral State functions
  533. * @brief Peripheral State functions
  534. *
  535. @verbatim
  536. ==============================================================================
  537. ##### SRAM State functions #####
  538. ==============================================================================
  539. [..]
  540. This subsection permits to get in run-time the status of the SRAM controller
  541. and the data flow.
  542. @endverbatim
  543. * @{
  544. */
  545. /**
  546. * @brief Returns the SRAM controller state
  547. * @param hsram pointer to a SRAM_HandleTypeDef structure that contains
  548. * the configuration information for SRAM module.
  549. * @retval HAL state
  550. */
  551. HAL_SRAM_StateTypeDef HAL_SRAM_GetState(SRAM_HandleTypeDef *hsram)
  552. {
  553. return hsram->State;
  554. }
  555. /**
  556. * @}
  557. */
  558. /**
  559. * @}
  560. */
  561. #endif /* HAL_SRAM_MODULE_ENABLED */
  562. /**
  563. * @}
  564. */
  565. /**
  566. * @}
  567. */
  568. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/