You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

stm32l1xx_hal_sram.c 21KB

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