stm32f4xx_hal_sram.c 22 KB

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