stm32f4xx_hal_sram.c 23 KB

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