stm32f1xx_hal_sram.c 22 KB

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