stm32f7xx_hal_sram.c 22 KB

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