stm32f1xx_hal_sram.c 22 KB

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