stm32f4xx_hal_sram.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691
  1. /**
  2. ******************************************************************************
  3. * @file stm32f4xx_hal_sram.c
  4. * @author MCD Application Team
  5. * @version V1.4.3
  6. * @date 11-December-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) || defined(STM32F469xx) || defined(STM32F479xx)
  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. /* Prevent unused argument(s) compilation warning */
  174. UNUSED(hsram);
  175. /* NOTE : This function Should not be modified, when the callback is needed,
  176. the HAL_SRAM_MspInit could be implemented in the user file
  177. */
  178. }
  179. /**
  180. * @brief SRAM MSP DeInit.
  181. * @param hsram: pointer to a SRAM_HandleTypeDef structure that contains
  182. * the configuration information for SRAM module.
  183. * @retval None
  184. */
  185. __weak void HAL_SRAM_MspDeInit(SRAM_HandleTypeDef *hsram)
  186. {
  187. /* Prevent unused argument(s) compilation warning */
  188. UNUSED(hsram);
  189. /* NOTE : This function Should not be modified, when the callback is needed,
  190. the HAL_SRAM_MspDeInit could be implemented in the user file
  191. */
  192. }
  193. /**
  194. * @brief DMA transfer complete callback.
  195. * @param hdma: pointer to a SRAM_HandleTypeDef structure that contains
  196. * the configuration information for SRAM module.
  197. * @retval None
  198. */
  199. __weak void HAL_SRAM_DMA_XferCpltCallback(DMA_HandleTypeDef *hdma)
  200. {
  201. /* Prevent unused argument(s) compilation warning */
  202. UNUSED(hdma);
  203. /* NOTE : This function Should not be modified, when the callback is needed,
  204. the HAL_SRAM_DMA_XferCpltCallback could be implemented in the user file
  205. */
  206. }
  207. /**
  208. * @brief DMA transfer complete error callback.
  209. * @param hdma: pointer to a SRAM_HandleTypeDef structure that contains
  210. * the configuration information for SRAM module.
  211. * @retval None
  212. */
  213. __weak void HAL_SRAM_DMA_XferErrorCallback(DMA_HandleTypeDef *hdma)
  214. {
  215. /* Prevent unused argument(s) compilation warning */
  216. UNUSED(hdma);
  217. /* NOTE : This function Should not be modified, when the callback is needed,
  218. the HAL_SRAM_DMA_XferErrorCallback could be implemented in the user file
  219. */
  220. }
  221. /**
  222. * @}
  223. */
  224. /** @defgroup SRAM_Exported_Functions_Group2 Input and Output functions
  225. * @brief Input Output and memory control functions
  226. *
  227. @verbatim
  228. ==============================================================================
  229. ##### SRAM Input and Output functions #####
  230. ==============================================================================
  231. [..]
  232. This section provides functions allowing to use and control the SRAM memory
  233. @endverbatim
  234. * @{
  235. */
  236. /**
  237. * @brief Reads 8-bit buffer from SRAM memory.
  238. * @param hsram: pointer to a SRAM_HandleTypeDef structure that contains
  239. * the configuration information for SRAM module.
  240. * @param pAddress: Pointer to read start address
  241. * @param pDstBuffer: Pointer to destination buffer
  242. * @param BufferSize: Size of the buffer to read from memory
  243. * @retval HAL status
  244. */
  245. HAL_StatusTypeDef HAL_SRAM_Read_8b(SRAM_HandleTypeDef *hsram, uint32_t *pAddress, uint8_t *pDstBuffer, uint32_t BufferSize)
  246. {
  247. __IO uint8_t * pSramAddress = (uint8_t *)pAddress;
  248. /* Process Locked */
  249. __HAL_LOCK(hsram);
  250. /* Update the SRAM controller state */
  251. hsram->State = HAL_SRAM_STATE_BUSY;
  252. /* Read data from memory */
  253. for(; BufferSize != 0; BufferSize--)
  254. {
  255. *pDstBuffer = *(__IO uint8_t *)pSramAddress;
  256. pDstBuffer++;
  257. pSramAddress++;
  258. }
  259. /* Update the SRAM controller state */
  260. hsram->State = HAL_SRAM_STATE_READY;
  261. /* Process unlocked */
  262. __HAL_UNLOCK(hsram);
  263. return HAL_OK;
  264. }
  265. /**
  266. * @brief Writes 8-bit buffer to SRAM memory.
  267. * @param hsram: pointer to a SRAM_HandleTypeDef structure that contains
  268. * the configuration information for SRAM module.
  269. * @param pAddress: Pointer to write start address
  270. * @param pSrcBuffer: Pointer to source buffer to write
  271. * @param BufferSize: Size of the buffer to write to memory
  272. * @retval HAL status
  273. */
  274. HAL_StatusTypeDef HAL_SRAM_Write_8b(SRAM_HandleTypeDef *hsram, uint32_t *pAddress, uint8_t *pSrcBuffer, uint32_t BufferSize)
  275. {
  276. __IO uint8_t * pSramAddress = (uint8_t *)pAddress;
  277. /* Check the SRAM controller state */
  278. if(hsram->State == HAL_SRAM_STATE_PROTECTED)
  279. {
  280. return HAL_ERROR;
  281. }
  282. /* Process Locked */
  283. __HAL_LOCK(hsram);
  284. /* Update the SRAM controller state */
  285. hsram->State = HAL_SRAM_STATE_BUSY;
  286. /* Write data to memory */
  287. for(; BufferSize != 0; BufferSize--)
  288. {
  289. *(__IO uint8_t *)pSramAddress = *pSrcBuffer;
  290. pSrcBuffer++;
  291. pSramAddress++;
  292. }
  293. /* Update the SRAM controller state */
  294. hsram->State = HAL_SRAM_STATE_READY;
  295. /* Process unlocked */
  296. __HAL_UNLOCK(hsram);
  297. return HAL_OK;
  298. }
  299. /**
  300. * @brief Reads 16-bit buffer from SRAM memory.
  301. * @param hsram: pointer to a SRAM_HandleTypeDef structure that contains
  302. * the configuration information for SRAM module.
  303. * @param pAddress: Pointer to read start address
  304. * @param pDstBuffer: Pointer to destination buffer
  305. * @param BufferSize: Size of the buffer to read from memory
  306. * @retval HAL status
  307. */
  308. HAL_StatusTypeDef HAL_SRAM_Read_16b(SRAM_HandleTypeDef *hsram, uint32_t *pAddress, uint16_t *pDstBuffer, uint32_t BufferSize)
  309. {
  310. __IO uint16_t * pSramAddress = (uint16_t *)pAddress;
  311. /* Process Locked */
  312. __HAL_LOCK(hsram);
  313. /* Update the SRAM controller state */
  314. hsram->State = HAL_SRAM_STATE_BUSY;
  315. /* Read data from memory */
  316. for(; BufferSize != 0; BufferSize--)
  317. {
  318. *pDstBuffer = *(__IO uint16_t *)pSramAddress;
  319. pDstBuffer++;
  320. pSramAddress++;
  321. }
  322. /* Update the SRAM controller state */
  323. hsram->State = HAL_SRAM_STATE_READY;
  324. /* Process unlocked */
  325. __HAL_UNLOCK(hsram);
  326. return HAL_OK;
  327. }
  328. /**
  329. * @brief Writes 16-bit buffer to SRAM memory.
  330. * @param hsram: pointer to a SRAM_HandleTypeDef structure that contains
  331. * the configuration information for SRAM module.
  332. * @param pAddress: Pointer to write start address
  333. * @param pSrcBuffer: Pointer to source buffer to write
  334. * @param BufferSize: Size of the buffer to write to memory
  335. * @retval HAL status
  336. */
  337. HAL_StatusTypeDef HAL_SRAM_Write_16b(SRAM_HandleTypeDef *hsram, uint32_t *pAddress, uint16_t *pSrcBuffer, uint32_t BufferSize)
  338. {
  339. __IO uint16_t * pSramAddress = (uint16_t *)pAddress;
  340. /* Check the SRAM controller state */
  341. if(hsram->State == HAL_SRAM_STATE_PROTECTED)
  342. {
  343. return HAL_ERROR;
  344. }
  345. /* Process Locked */
  346. __HAL_LOCK(hsram);
  347. /* Update the SRAM controller state */
  348. hsram->State = HAL_SRAM_STATE_BUSY;
  349. /* Write data to memory */
  350. for(; BufferSize != 0; BufferSize--)
  351. {
  352. *(__IO uint16_t *)pSramAddress = *pSrcBuffer;
  353. pSrcBuffer++;
  354. pSramAddress++;
  355. }
  356. /* Update the SRAM controller state */
  357. hsram->State = HAL_SRAM_STATE_READY;
  358. /* Process unlocked */
  359. __HAL_UNLOCK(hsram);
  360. return HAL_OK;
  361. }
  362. /**
  363. * @brief Reads 32-bit buffer from SRAM memory.
  364. * @param hsram: pointer to a SRAM_HandleTypeDef structure that contains
  365. * the configuration information for SRAM module.
  366. * @param pAddress: Pointer to read start address
  367. * @param pDstBuffer: Pointer to destination buffer
  368. * @param BufferSize: Size of the buffer to read from memory
  369. * @retval HAL status
  370. */
  371. HAL_StatusTypeDef HAL_SRAM_Read_32b(SRAM_HandleTypeDef *hsram, uint32_t *pAddress, uint32_t *pDstBuffer, uint32_t BufferSize)
  372. {
  373. /* Process Locked */
  374. __HAL_LOCK(hsram);
  375. /* Update the SRAM controller state */
  376. hsram->State = HAL_SRAM_STATE_BUSY;
  377. /* Read data from memory */
  378. for(; BufferSize != 0; BufferSize--)
  379. {
  380. *pDstBuffer = *(__IO uint32_t *)pAddress;
  381. pDstBuffer++;
  382. pAddress++;
  383. }
  384. /* Update the SRAM controller state */
  385. hsram->State = HAL_SRAM_STATE_READY;
  386. /* Process unlocked */
  387. __HAL_UNLOCK(hsram);
  388. return HAL_OK;
  389. }
  390. /**
  391. * @brief Writes 32-bit buffer to SRAM memory.
  392. * @param hsram: pointer to a SRAM_HandleTypeDef structure that contains
  393. * the configuration information for SRAM module.
  394. * @param pAddress: Pointer to write start address
  395. * @param pSrcBuffer: Pointer to source buffer to write
  396. * @param BufferSize: Size of the buffer to write to memory
  397. * @retval HAL status
  398. */
  399. HAL_StatusTypeDef HAL_SRAM_Write_32b(SRAM_HandleTypeDef *hsram, uint32_t *pAddress, uint32_t *pSrcBuffer, uint32_t BufferSize)
  400. {
  401. /* Check the SRAM controller state */
  402. if(hsram->State == HAL_SRAM_STATE_PROTECTED)
  403. {
  404. return HAL_ERROR;
  405. }
  406. /* Process Locked */
  407. __HAL_LOCK(hsram);
  408. /* Update the SRAM controller state */
  409. hsram->State = HAL_SRAM_STATE_BUSY;
  410. /* Write data to memory */
  411. for(; BufferSize != 0; BufferSize--)
  412. {
  413. *(__IO uint32_t *)pAddress = *pSrcBuffer;
  414. pSrcBuffer++;
  415. pAddress++;
  416. }
  417. /* Update the SRAM controller state */
  418. hsram->State = HAL_SRAM_STATE_READY;
  419. /* Process unlocked */
  420. __HAL_UNLOCK(hsram);
  421. return HAL_OK;
  422. }
  423. /**
  424. * @brief Reads a Words data from the SRAM memory using DMA transfer.
  425. * @param hsram: pointer to a SRAM_HandleTypeDef structure that contains
  426. * the configuration information for SRAM module.
  427. * @param pAddress: Pointer to read start address
  428. * @param pDstBuffer: Pointer to destination buffer
  429. * @param BufferSize: Size of the buffer to read from memory
  430. * @retval HAL status
  431. */
  432. HAL_StatusTypeDef HAL_SRAM_Read_DMA(SRAM_HandleTypeDef *hsram, uint32_t *pAddress, uint32_t *pDstBuffer, uint32_t BufferSize)
  433. {
  434. /* Process Locked */
  435. __HAL_LOCK(hsram);
  436. /* Update the SRAM controller state */
  437. hsram->State = HAL_SRAM_STATE_BUSY;
  438. /* Configure DMA user callbacks */
  439. hsram->hdma->XferCpltCallback = HAL_SRAM_DMA_XferCpltCallback;
  440. hsram->hdma->XferErrorCallback = HAL_SRAM_DMA_XferErrorCallback;
  441. /* Enable the DMA Stream */
  442. HAL_DMA_Start_IT(hsram->hdma, (uint32_t)pAddress, (uint32_t)pDstBuffer, (uint32_t)BufferSize);
  443. /* Update the SRAM controller state */
  444. hsram->State = HAL_SRAM_STATE_READY;
  445. /* Process unlocked */
  446. __HAL_UNLOCK(hsram);
  447. return HAL_OK;
  448. }
  449. /**
  450. * @brief Writes a Words data buffer to SRAM memory using DMA transfer.
  451. * @param hsram: pointer to a SRAM_HandleTypeDef structure that contains
  452. * the configuration information for SRAM module.
  453. * @param pAddress: Pointer to write start address
  454. * @param pSrcBuffer: Pointer to source buffer to write
  455. * @param BufferSize: Size of the buffer to write to memory
  456. * @retval HAL status
  457. */
  458. HAL_StatusTypeDef HAL_SRAM_Write_DMA(SRAM_HandleTypeDef *hsram, uint32_t *pAddress, uint32_t *pSrcBuffer, uint32_t BufferSize)
  459. {
  460. /* Check the SRAM controller state */
  461. if(hsram->State == HAL_SRAM_STATE_PROTECTED)
  462. {
  463. return HAL_ERROR;
  464. }
  465. /* Process Locked */
  466. __HAL_LOCK(hsram);
  467. /* Update the SRAM controller state */
  468. hsram->State = HAL_SRAM_STATE_BUSY;
  469. /* Configure DMA user callbacks */
  470. hsram->hdma->XferCpltCallback = HAL_SRAM_DMA_XferCpltCallback;
  471. hsram->hdma->XferErrorCallback = HAL_SRAM_DMA_XferErrorCallback;
  472. /* Enable the DMA Stream */
  473. HAL_DMA_Start_IT(hsram->hdma, (uint32_t)pSrcBuffer, (uint32_t)pAddress, (uint32_t)BufferSize);
  474. /* Update the SRAM controller state */
  475. hsram->State = HAL_SRAM_STATE_READY;
  476. /* Process unlocked */
  477. __HAL_UNLOCK(hsram);
  478. return HAL_OK;
  479. }
  480. /**
  481. * @}
  482. */
  483. /** @defgroup SRAM_Exported_Functions_Group3 Control functions
  484. * @brief management functions
  485. *
  486. @verbatim
  487. ==============================================================================
  488. ##### SRAM Control functions #####
  489. ==============================================================================
  490. [..]
  491. This subsection provides a set of functions allowing to control dynamically
  492. the SRAM interface.
  493. @endverbatim
  494. * @{
  495. */
  496. /**
  497. * @brief Enables dynamically SRAM write operation.
  498. * @param hsram: pointer to a SRAM_HandleTypeDef structure that contains
  499. * the configuration information for SRAM module.
  500. * @retval HAL status
  501. */
  502. HAL_StatusTypeDef HAL_SRAM_WriteOperation_Enable(SRAM_HandleTypeDef *hsram)
  503. {
  504. /* Process Locked */
  505. __HAL_LOCK(hsram);
  506. /* Enable write operation */
  507. FMC_NORSRAM_WriteOperation_Enable(hsram->Instance, hsram->Init.NSBank);
  508. /* Update the SRAM controller state */
  509. hsram->State = HAL_SRAM_STATE_READY;
  510. /* Process unlocked */
  511. __HAL_UNLOCK(hsram);
  512. return HAL_OK;
  513. }
  514. /**
  515. * @brief Disables dynamically SRAM write operation.
  516. * @param hsram: pointer to a SRAM_HandleTypeDef structure that contains
  517. * the configuration information for SRAM module.
  518. * @retval HAL status
  519. */
  520. HAL_StatusTypeDef HAL_SRAM_WriteOperation_Disable(SRAM_HandleTypeDef *hsram)
  521. {
  522. /* Process Locked */
  523. __HAL_LOCK(hsram);
  524. /* Update the SRAM controller state */
  525. hsram->State = HAL_SRAM_STATE_BUSY;
  526. /* Disable write operation */
  527. FMC_NORSRAM_WriteOperation_Disable(hsram->Instance, hsram->Init.NSBank);
  528. /* Update the SRAM controller state */
  529. hsram->State = HAL_SRAM_STATE_PROTECTED;
  530. /* Process unlocked */
  531. __HAL_UNLOCK(hsram);
  532. return HAL_OK;
  533. }
  534. /**
  535. * @}
  536. */
  537. /** @defgroup SRAM_Exported_Functions_Group4 State functions
  538. * @brief Peripheral State functions
  539. *
  540. @verbatim
  541. ==============================================================================
  542. ##### SRAM State functions #####
  543. ==============================================================================
  544. [..]
  545. This subsection permits to get in run-time the status of the SRAM controller
  546. and the data flow.
  547. @endverbatim
  548. * @{
  549. */
  550. /**
  551. * @brief Returns the SRAM controller state
  552. * @param hsram: pointer to a SRAM_HandleTypeDef structure that contains
  553. * the configuration information for SRAM module.
  554. * @retval HAL state
  555. */
  556. HAL_SRAM_StateTypeDef HAL_SRAM_GetState(SRAM_HandleTypeDef *hsram)
  557. {
  558. return hsram->State;
  559. }
  560. /**
  561. * @}
  562. */
  563. /**
  564. * @}
  565. */
  566. #endif /* STM32F405xx || STM32F415xx || STM32F407xx || STM32F417xx || STM32F427xx || STM32F437xx ||\
  567. STM32F429xx || STM32F439xx || STM32F446xx || STM32F469xx || STM32F479xx */
  568. #endif /* HAL_SRAM_MODULE_ENABLED */
  569. /**
  570. * @}
  571. */
  572. /**
  573. * @}
  574. */
  575. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/