stm32f4xx_hal_sram.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692
  1. /**
  2. ******************************************************************************
  3. * @file stm32f4xx_hal_sram.c
  4. * @author MCD Application Team
  5. * @brief SRAM HAL module driver.
  6. * This file provides a generic firmware to drive SRAM memories
  7. * mounted as external device.
  8. *
  9. @verbatim
  10. ==============================================================================
  11. ##### How to use this driver #####
  12. ==============================================================================
  13. [..]
  14. This driver is a generic layered driver which contains a set of APIs used to
  15. control SRAM memories. It uses the FMC layer functions to interface
  16. with SRAM devices.
  17. The following sequence should be followed to configure the FMC/FSMC to interface
  18. with SRAM/PSRAM memories:
  19. (#) Declare a SRAM_HandleTypeDef handle structure, for example:
  20. SRAM_HandleTypeDef hsram; and:
  21. (++) Fill the SRAM_HandleTypeDef handle "Init" field with the allowed
  22. values of the structure member.
  23. (++) Fill the SRAM_HandleTypeDef handle "Instance" field with a predefined
  24. base register instance for NOR or SRAM device
  25. (++) Fill the SRAM_HandleTypeDef handle "Extended" field with a predefined
  26. base register instance for NOR or SRAM extended mode
  27. (#) Declare two FMC_NORSRAM_TimingTypeDef structures, for both normal and extended
  28. mode timings; for example:
  29. FMC_NORSRAM_TimingTypeDef Timing and FMC_NORSRAM_TimingTypeDef ExTiming;
  30. and fill its fields with the allowed values of the structure member.
  31. (#) Initialize the SRAM Controller by calling the function HAL_SRAM_Init(). This function
  32. performs the following sequence:
  33. (##) MSP hardware layer configuration using the function HAL_SRAM_MspInit()
  34. (##) Control register configuration using the FMC NORSRAM interface function
  35. FMC_NORSRAM_Init()
  36. (##) Timing register configuration using the FMC NORSRAM interface function
  37. FMC_NORSRAM_Timing_Init()
  38. (##) Extended mode Timing register configuration using the FMC NORSRAM interface function
  39. FMC_NORSRAM_Extended_Timing_Init()
  40. (##) Enable the SRAM device using the macro __FMC_NORSRAM_ENABLE()
  41. (#) At this stage you can perform read/write accesses from/to the memory connected
  42. to the NOR/SRAM Bank. You can perform either polling or DMA transfer using the
  43. following APIs:
  44. (++) HAL_SRAM_Read()/HAL_SRAM_Write() for polling read/write access
  45. (++) HAL_SRAM_Read_DMA()/HAL_SRAM_Write_DMA() for DMA read/write transfer
  46. (#) You can also control the SRAM device by calling the control APIs HAL_SRAM_WriteOperation_Enable()/
  47. HAL_SRAM_WriteOperation_Disable() to respectively enable/disable the SRAM write operation
  48. (#) You can continuously monitor the SRAM device HAL state by calling the function
  49. HAL_SRAM_GetState()
  50. @endverbatim
  51. ******************************************************************************
  52. * @attention
  53. *
  54. * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
  55. *
  56. * Redistribution and use in source and binary forms, with or without modification,
  57. * are permitted provided that the following conditions are met:
  58. * 1. Redistributions of source code must retain the above copyright notice,
  59. * this list of conditions and the following disclaimer.
  60. * 2. Redistributions in binary form must reproduce the above copyright notice,
  61. * this list of conditions and the following disclaimer in the documentation
  62. * and/or other materials provided with the distribution.
  63. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  64. * may be used to endorse or promote products derived from this software
  65. * without specific prior written permission.
  66. *
  67. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  68. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  69. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  70. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  71. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  72. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  73. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  74. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  75. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  76. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  77. *
  78. ******************************************************************************
  79. */
  80. /* Includes ------------------------------------------------------------------*/
  81. #include "stm32f4xx_hal.h"
  82. /** @addtogroup STM32F4xx_HAL_Driver
  83. * @{
  84. */
  85. /** @defgroup SRAM SRAM
  86. * @brief SRAM driver modules
  87. * @{
  88. */
  89. #ifdef HAL_SRAM_MODULE_ENABLED
  90. #if defined(STM32F405xx) || defined(STM32F415xx) || defined(STM32F407xx) || defined(STM32F417xx) ||\
  91. defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx) ||\
  92. defined(STM32F446xx) || defined(STM32F469xx) || defined(STM32F479xx) || defined(STM32F412Zx) ||\
  93. defined(STM32F412Vx) || defined(STM32F412Rx) || defined(STM32F413xx) || defined(STM32F423xx)
  94. /* Private typedef -----------------------------------------------------------*/
  95. /* Private define ------------------------------------------------------------*/
  96. /* Private macro -------------------------------------------------------------*/
  97. /* Private variables ---------------------------------------------------------*/
  98. /* Private functions ---------------------------------------------------------*/
  99. /* Exported functions --------------------------------------------------------*/
  100. /** @defgroup SRAM_Exported_Functions SRAM Exported Functions
  101. * @{
  102. */
  103. /** @defgroup SRAM_Exported_Functions_Group1 Initialization and de-initialization functions
  104. * @brief Initialization and Configuration functions
  105. *
  106. @verbatim
  107. ==============================================================================
  108. ##### SRAM Initialization and de_initialization functions #####
  109. ==============================================================================
  110. [..] This section provides functions allowing to initialize/de-initialize
  111. the SRAM memory
  112. @endverbatim
  113. * @{
  114. */
  115. /**
  116. * @brief Performs the SRAM device initialization sequence
  117. * @param hsram pointer to a SRAM_HandleTypeDef structure that contains
  118. * the configuration information for SRAM module.
  119. * @param Timing Pointer to SRAM control timing structure
  120. * @param ExtTiming Pointer to SRAM extended mode timing structure
  121. * @retval HAL status
  122. */
  123. HAL_StatusTypeDef HAL_SRAM_Init(SRAM_HandleTypeDef *hsram, FMC_NORSRAM_TimingTypeDef *Timing, FMC_NORSRAM_TimingTypeDef *ExtTiming)
  124. {
  125. /* Check the SRAM handle parameter */
  126. if(hsram == NULL)
  127. {
  128. return HAL_ERROR;
  129. }
  130. if(hsram->State == HAL_SRAM_STATE_RESET)
  131. {
  132. /* Allocate lock resource and initialize it */
  133. hsram->Lock = HAL_UNLOCKED;
  134. /* Initialize the low level hardware (MSP) */
  135. HAL_SRAM_MspInit(hsram);
  136. }
  137. /* Initialize SRAM control Interface */
  138. FMC_NORSRAM_Init(hsram->Instance, &(hsram->Init));
  139. /* Initialize SRAM timing Interface */
  140. FMC_NORSRAM_Timing_Init(hsram->Instance, Timing, hsram->Init.NSBank);
  141. /* Initialize SRAM extended mode timing Interface */
  142. FMC_NORSRAM_Extended_Timing_Init(hsram->Extended, ExtTiming, hsram->Init.NSBank, hsram->Init.ExtendedMode);
  143. /* Enable the NORSRAM device */
  144. __FMC_NORSRAM_ENABLE(hsram->Instance, hsram->Init.NSBank);
  145. return HAL_OK;
  146. }
  147. /**
  148. * @brief Performs the SRAM device De-initialization sequence.
  149. * @param hsram pointer to a SRAM_HandleTypeDef structure that contains
  150. * the configuration information for SRAM module.
  151. * @retval HAL status
  152. */
  153. HAL_StatusTypeDef HAL_SRAM_DeInit(SRAM_HandleTypeDef *hsram)
  154. {
  155. /* De-Initialize the low level hardware (MSP) */
  156. HAL_SRAM_MspDeInit(hsram);
  157. /* Configure the SRAM registers with their reset values */
  158. FMC_NORSRAM_DeInit(hsram->Instance, hsram->Extended, hsram->Init.NSBank);
  159. hsram->State = HAL_SRAM_STATE_RESET;
  160. /* Release Lock */
  161. __HAL_UNLOCK(hsram);
  162. return HAL_OK;
  163. }
  164. /**
  165. * @brief SRAM MSP Init.
  166. * @param hsram pointer to a SRAM_HandleTypeDef structure that contains
  167. * the configuration information for SRAM module.
  168. * @retval None
  169. */
  170. __weak void HAL_SRAM_MspInit(SRAM_HandleTypeDef *hsram)
  171. {
  172. /* Prevent unused argument(s) compilation warning */
  173. UNUSED(hsram);
  174. /* NOTE : This function Should not be modified, when the callback is needed,
  175. the HAL_SRAM_MspInit could be implemented in the user file
  176. */
  177. }
  178. /**
  179. * @brief SRAM MSP DeInit.
  180. * @param hsram pointer to a SRAM_HandleTypeDef structure that contains
  181. * the configuration information for SRAM module.
  182. * @retval None
  183. */
  184. __weak void HAL_SRAM_MspDeInit(SRAM_HandleTypeDef *hsram)
  185. {
  186. /* Prevent unused argument(s) compilation warning */
  187. UNUSED(hsram);
  188. /* NOTE : This function Should not be modified, when the callback is needed,
  189. the HAL_SRAM_MspDeInit could be implemented in the user file
  190. */
  191. }
  192. /**
  193. * @brief DMA transfer complete callback.
  194. * @param hdma pointer to a SRAM_HandleTypeDef structure that contains
  195. * the configuration information for SRAM module.
  196. * @retval None
  197. */
  198. __weak void HAL_SRAM_DMA_XferCpltCallback(DMA_HandleTypeDef *hdma)
  199. {
  200. /* Prevent unused argument(s) compilation warning */
  201. UNUSED(hdma);
  202. /* NOTE : This function Should not be modified, when the callback is needed,
  203. the HAL_SRAM_DMA_XferCpltCallback could be implemented in the user file
  204. */
  205. }
  206. /**
  207. * @brief DMA transfer complete error callback.
  208. * @param hdma pointer to a SRAM_HandleTypeDef structure that contains
  209. * the configuration information for SRAM module.
  210. * @retval None
  211. */
  212. __weak void HAL_SRAM_DMA_XferErrorCallback(DMA_HandleTypeDef *hdma)
  213. {
  214. /* Prevent unused argument(s) compilation warning */
  215. UNUSED(hdma);
  216. /* NOTE : This function Should not be modified, when the callback is needed,
  217. the HAL_SRAM_DMA_XferErrorCallback could be implemented in the user file
  218. */
  219. }
  220. /**
  221. * @}
  222. */
  223. /** @defgroup SRAM_Exported_Functions_Group2 Input and Output functions
  224. * @brief Input Output and memory control functions
  225. *
  226. @verbatim
  227. ==============================================================================
  228. ##### SRAM Input and Output functions #####
  229. ==============================================================================
  230. [..]
  231. This section provides functions allowing to use and control the SRAM memory
  232. @endverbatim
  233. * @{
  234. */
  235. /**
  236. * @brief Reads 8-bit buffer from SRAM memory.
  237. * @param hsram pointer to a SRAM_HandleTypeDef structure that contains
  238. * the configuration information for SRAM module.
  239. * @param pAddress Pointer to read start address
  240. * @param pDstBuffer Pointer to destination buffer
  241. * @param BufferSize Size of the buffer to read from memory
  242. * @retval HAL status
  243. */
  244. HAL_StatusTypeDef HAL_SRAM_Read_8b(SRAM_HandleTypeDef *hsram, uint32_t *pAddress, uint8_t *pDstBuffer, uint32_t BufferSize)
  245. {
  246. __IO uint8_t * pSramAddress = (uint8_t *)pAddress;
  247. /* Process Locked */
  248. __HAL_LOCK(hsram);
  249. /* Update the SRAM controller state */
  250. hsram->State = HAL_SRAM_STATE_BUSY;
  251. /* Read data from memory */
  252. for(; BufferSize != 0U; BufferSize--)
  253. {
  254. *pDstBuffer = *(__IO uint8_t *)pSramAddress;
  255. pDstBuffer++;
  256. pSramAddress++;
  257. }
  258. /* Update the SRAM controller state */
  259. hsram->State = HAL_SRAM_STATE_READY;
  260. /* Process unlocked */
  261. __HAL_UNLOCK(hsram);
  262. return HAL_OK;
  263. }
  264. /**
  265. * @brief Writes 8-bit buffer to SRAM memory.
  266. * @param hsram pointer to a SRAM_HandleTypeDef structure that contains
  267. * the configuration information for SRAM module.
  268. * @param pAddress Pointer to write start address
  269. * @param pSrcBuffer Pointer to source buffer to write
  270. * @param BufferSize Size of the buffer to write to memory
  271. * @retval HAL status
  272. */
  273. HAL_StatusTypeDef HAL_SRAM_Write_8b(SRAM_HandleTypeDef *hsram, uint32_t *pAddress, uint8_t *pSrcBuffer, uint32_t BufferSize)
  274. {
  275. __IO uint8_t * pSramAddress = (uint8_t *)pAddress;
  276. /* Check the SRAM controller state */
  277. if(hsram->State == HAL_SRAM_STATE_PROTECTED)
  278. {
  279. return HAL_ERROR;
  280. }
  281. /* Process Locked */
  282. __HAL_LOCK(hsram);
  283. /* Update the SRAM controller state */
  284. hsram->State = HAL_SRAM_STATE_BUSY;
  285. /* Write data to memory */
  286. for(; BufferSize != 0U; BufferSize--)
  287. {
  288. *(__IO uint8_t *)pSramAddress = *pSrcBuffer;
  289. pSrcBuffer++;
  290. pSramAddress++;
  291. }
  292. /* Update the SRAM controller state */
  293. hsram->State = HAL_SRAM_STATE_READY;
  294. /* Process unlocked */
  295. __HAL_UNLOCK(hsram);
  296. return HAL_OK;
  297. }
  298. /**
  299. * @brief Reads 16-bit buffer from SRAM memory.
  300. * @param hsram pointer to a SRAM_HandleTypeDef structure that contains
  301. * the configuration information for SRAM module.
  302. * @param pAddress Pointer to read start address
  303. * @param pDstBuffer Pointer to destination buffer
  304. * @param BufferSize Size of the buffer to read from memory
  305. * @retval HAL status
  306. */
  307. HAL_StatusTypeDef HAL_SRAM_Read_16b(SRAM_HandleTypeDef *hsram, uint32_t *pAddress, uint16_t *pDstBuffer, uint32_t BufferSize)
  308. {
  309. __IO uint16_t * pSramAddress = (uint16_t *)pAddress;
  310. /* Process Locked */
  311. __HAL_LOCK(hsram);
  312. /* Update the SRAM controller state */
  313. hsram->State = HAL_SRAM_STATE_BUSY;
  314. /* Read data from memory */
  315. for(; BufferSize != 0U; BufferSize--)
  316. {
  317. *pDstBuffer = *(__IO uint16_t *)pSramAddress;
  318. pDstBuffer++;
  319. pSramAddress++;
  320. }
  321. /* Update the SRAM controller state */
  322. hsram->State = HAL_SRAM_STATE_READY;
  323. /* Process unlocked */
  324. __HAL_UNLOCK(hsram);
  325. return HAL_OK;
  326. }
  327. /**
  328. * @brief Writes 16-bit buffer to SRAM memory.
  329. * @param hsram pointer to a SRAM_HandleTypeDef structure that contains
  330. * the configuration information for SRAM module.
  331. * @param pAddress Pointer to write start address
  332. * @param pSrcBuffer Pointer to source buffer to write
  333. * @param BufferSize Size of the buffer to write to memory
  334. * @retval HAL status
  335. */
  336. HAL_StatusTypeDef HAL_SRAM_Write_16b(SRAM_HandleTypeDef *hsram, uint32_t *pAddress, uint16_t *pSrcBuffer, uint32_t BufferSize)
  337. {
  338. __IO uint16_t * pSramAddress = (uint16_t *)pAddress;
  339. // printk("addr: %p\n", pSramAddress);
  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 != 0U; 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 != 0U; 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 != 0U; 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 || STM32F412Zx ||\
  568. STM32F412Vx || STM32F412Rx || STM32F412Cx || STM32F413xx || STM32F423xx */
  569. #endif /* HAL_SRAM_MODULE_ENABLED */
  570. /**
  571. * @}
  572. */
  573. /**
  574. * @}
  575. */
  576. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/