STM32L4xx_HAL_Driver  1.14.0
stm32l4xx_hal_sram.c
Go to the documentation of this file.
1 
76 /* Includes ------------------------------------------------------------------*/
77 #include "stm32l4xx_hal.h"
78 
79 #if defined(FMC_BANK1)
80 
85 #ifdef HAL_SRAM_MODULE_ENABLED
86 
92 /* Private typedef -----------------------------------------------------------*/
93 /* Private define ------------------------------------------------------------*/
94 /* Private macro -------------------------------------------------------------*/
95 /* Private variables ---------------------------------------------------------*/
96 /* Private function prototypes -----------------------------------------------*/
97 /* Exported functions --------------------------------------------------------*/
98 
126 {
127  /* Check the SRAM handle parameter */
128  if(hsram == NULL)
129  {
130  return HAL_ERROR;
131  }
132 
133  if(hsram->State == HAL_SRAM_STATE_RESET)
134  {
135  /* Allocate lock resource and initialize it */
136  hsram->Lock = HAL_UNLOCKED;
137  /* Initialize the low level hardware (MSP) */
138  HAL_SRAM_MspInit(hsram);
139  }
140 
141  /* Initialize SRAM control Interface */
142  FMC_NORSRAM_Init(hsram->Instance, &(hsram->Init));
143 
144  /* Initialize SRAM timing Interface */
145  FMC_NORSRAM_Timing_Init(hsram->Instance, Timing, hsram->Init.NSBank);
146 
147  /* Initialize SRAM extended mode timing Interface */
148  FMC_NORSRAM_Extended_Timing_Init(hsram->Extended, ExtTiming, hsram->Init.NSBank, hsram->Init.ExtendedMode);
149 
150  /* Enable the NORSRAM device */
151  __FMC_NORSRAM_ENABLE(hsram->Instance, hsram->Init.NSBank);
152 
153  return HAL_OK;
154 }
155 
162 HAL_StatusTypeDef HAL_SRAM_DeInit(SRAM_HandleTypeDef *hsram)
163 {
164  /* De-Initialize the low level hardware (MSP) */
165  HAL_SRAM_MspDeInit(hsram);
166 
167  /* Configure the SRAM registers with their reset values */
168  FMC_NORSRAM_DeInit(hsram->Instance, hsram->Extended, hsram->Init.NSBank);
169 
170  hsram->State = HAL_SRAM_STATE_RESET;
171 
172  /* Release Lock */
173  __HAL_UNLOCK(hsram);
174 
175  return HAL_OK;
176 }
177 
185 {
186  /* Prevent unused argument(s) compilation warning */
187  UNUSED(hsram);
188 
189  /* NOTE : This function should not be modified, when the callback is needed,
190  the HAL_SRAM_MspInit could be implemented in the user file
191  */
192 }
193 
201 {
202  /* Prevent unused argument(s) compilation warning */
203  UNUSED(hsram);
204 
205  /* NOTE : This function should not be modified, when the callback is needed,
206  the HAL_SRAM_MspDeInit could be implemented in the user file
207  */
208 }
209 
217 {
218  /* Prevent unused argument(s) compilation warning */
219  UNUSED(hdma);
220 
221  /* NOTE : This function should not be modified, when the callback is needed,
222  the HAL_SRAM_DMA_XferCpltCallback could be implemented in the user file
223  */
224 }
225 
233 {
234  /* Prevent unused argument(s) compilation warning */
235  UNUSED(hdma);
236 
237  /* NOTE : This function should not be modified, when the callback is needed,
238  the HAL_SRAM_DMA_XferErrorCallback could be implemented in the user file
239  */
240 }
241 
269 HAL_StatusTypeDef HAL_SRAM_Read_8b(SRAM_HandleTypeDef *hsram, uint32_t *pAddress, uint8_t *pDstBuffer, uint32_t BufferSize)
270 {
271  __IO uint8_t * psramaddress = (uint8_t *)pAddress;
272 
273  /* Process Locked */
274  __HAL_LOCK(hsram);
275 
276  /* Update the SRAM controller state */
277  hsram->State = HAL_SRAM_STATE_BUSY;
278 
279  /* Read data from memory */
280  for(; BufferSize != 0; BufferSize--)
281  {
282  *pDstBuffer = *(__IO uint8_t *)psramaddress;
283  pDstBuffer++;
284  psramaddress++;
285  }
286 
287  /* Update the SRAM controller state */
288  hsram->State = HAL_SRAM_STATE_READY;
289 
290  /* Process unlocked */
291  __HAL_UNLOCK(hsram);
292 
293  return HAL_OK;
294 }
295 
305 HAL_StatusTypeDef HAL_SRAM_Write_8b(SRAM_HandleTypeDef *hsram, uint32_t *pAddress, uint8_t *pSrcBuffer, uint32_t BufferSize)
306 {
307  __IO uint8_t * psramaddress = (uint8_t *)pAddress;
308 
309  /* Check the SRAM controller state */
310  if(hsram->State == HAL_SRAM_STATE_PROTECTED)
311  {
312  return HAL_ERROR;
313  }
314 
315  /* Process Locked */
316  __HAL_LOCK(hsram);
317 
318  /* Update the SRAM controller state */
319  hsram->State = HAL_SRAM_STATE_BUSY;
320 
321  /* Write data to memory */
322  for(; BufferSize != 0; BufferSize--)
323  {
324  *(__IO uint8_t *)psramaddress = *pSrcBuffer;
325  pSrcBuffer++;
326  psramaddress++;
327  }
328 
329  /* Update the SRAM controller state */
330  hsram->State = HAL_SRAM_STATE_READY;
331 
332  /* Process unlocked */
333  __HAL_UNLOCK(hsram);
334 
335  return HAL_OK;
336 }
337 
347 HAL_StatusTypeDef HAL_SRAM_Read_16b(SRAM_HandleTypeDef *hsram, uint32_t *pAddress, uint16_t *pDstBuffer, uint32_t BufferSize)
348 {
349  __IO uint16_t * psramaddress = (uint16_t *)pAddress;
350 
351  /* Process Locked */
352  __HAL_LOCK(hsram);
353 
354  /* Update the SRAM controller state */
355  hsram->State = HAL_SRAM_STATE_BUSY;
356 
357  /* Read data from memory */
358  for(; BufferSize != 0; BufferSize--)
359  {
360  *pDstBuffer = *(__IO uint16_t *)psramaddress;
361  pDstBuffer++;
362  psramaddress++;
363  }
364 
365  /* Update the SRAM controller state */
366  hsram->State = HAL_SRAM_STATE_READY;
367 
368  /* Process unlocked */
369  __HAL_UNLOCK(hsram);
370 
371  return HAL_OK;
372 }
373 
383 HAL_StatusTypeDef HAL_SRAM_Write_16b(SRAM_HandleTypeDef *hsram, uint32_t *pAddress, uint16_t *pSrcBuffer, uint32_t BufferSize)
384 {
385  __IO uint16_t * psramaddress = (uint16_t *)pAddress;
386 
387  /* Check the SRAM controller state */
388  if(hsram->State == HAL_SRAM_STATE_PROTECTED)
389  {
390  return HAL_ERROR;
391  }
392 
393  /* Process Locked */
394  __HAL_LOCK(hsram);
395 
396  /* Update the SRAM controller state */
397  hsram->State = HAL_SRAM_STATE_BUSY;
398 
399  /* Write data to memory */
400  for(; BufferSize != 0; BufferSize--)
401  {
402  *(__IO uint16_t *)psramaddress = *pSrcBuffer;
403  pSrcBuffer++;
404  psramaddress++;
405  }
406 
407  /* Update the SRAM controller state */
408  hsram->State = HAL_SRAM_STATE_READY;
409 
410  /* Process unlocked */
411  __HAL_UNLOCK(hsram);
412 
413  return HAL_OK;
414 }
415 
425 HAL_StatusTypeDef HAL_SRAM_Read_32b(SRAM_HandleTypeDef *hsram, uint32_t *pAddress, uint32_t *pDstBuffer, uint32_t BufferSize)
426 {
427  /* Process Locked */
428  __HAL_LOCK(hsram);
429 
430  /* Update the SRAM controller state */
431  hsram->State = HAL_SRAM_STATE_BUSY;
432 
433  /* Read data from memory */
434  for(; BufferSize != 0; BufferSize--)
435  {
436  *pDstBuffer = *(__IO uint32_t *)pAddress;
437  pDstBuffer++;
438  pAddress++;
439  }
440 
441  /* Update the SRAM controller state */
442  hsram->State = HAL_SRAM_STATE_READY;
443 
444  /* Process unlocked */
445  __HAL_UNLOCK(hsram);
446 
447  return HAL_OK;
448 }
449 
459 HAL_StatusTypeDef HAL_SRAM_Write_32b(SRAM_HandleTypeDef *hsram, uint32_t *pAddress, uint32_t *pSrcBuffer, uint32_t BufferSize)
460 {
461  /* Check the SRAM controller state */
462  if(hsram->State == HAL_SRAM_STATE_PROTECTED)
463  {
464  return HAL_ERROR;
465  }
466 
467  /* Process Locked */
468  __HAL_LOCK(hsram);
469 
470  /* Update the SRAM controller state */
471  hsram->State = HAL_SRAM_STATE_BUSY;
472 
473  /* Write data to memory */
474  for(; BufferSize != 0; BufferSize--)
475  {
476  *(__IO uint32_t *)pAddress = *pSrcBuffer;
477  pSrcBuffer++;
478  pAddress++;
479  }
480 
481  /* Update the SRAM controller state */
482  hsram->State = HAL_SRAM_STATE_READY;
483 
484  /* Process unlocked */
485  __HAL_UNLOCK(hsram);
486 
487  return HAL_OK;
488 }
489 
499 HAL_StatusTypeDef HAL_SRAM_Read_DMA(SRAM_HandleTypeDef *hsram, uint32_t *pAddress, uint32_t *pDstBuffer, uint32_t BufferSize)
500 {
501  /* Process Locked */
502  __HAL_LOCK(hsram);
503 
504  /* Update the SRAM controller state */
505  hsram->State = HAL_SRAM_STATE_BUSY;
506 
507  /* Configure DMA user callbacks */
510 
511  /* Enable the DMA Channel */
512  HAL_DMA_Start_IT(hsram->hdma, (uint32_t)pAddress, (uint32_t)pDstBuffer, (uint32_t)BufferSize);
513 
514  /* Update the SRAM controller state */
515  hsram->State = HAL_SRAM_STATE_READY;
516 
517  /* Process unlocked */
518  __HAL_UNLOCK(hsram);
519 
520  return HAL_OK;
521 }
522 
532 HAL_StatusTypeDef HAL_SRAM_Write_DMA(SRAM_HandleTypeDef *hsram, uint32_t *pAddress, uint32_t *pSrcBuffer, uint32_t BufferSize)
533 {
534  /* Check the SRAM controller state */
535  if(hsram->State == HAL_SRAM_STATE_PROTECTED)
536  {
537  return HAL_ERROR;
538  }
539 
540  /* Process Locked */
541  __HAL_LOCK(hsram);
542 
543  /* Update the SRAM controller state */
544  hsram->State = HAL_SRAM_STATE_BUSY;
545 
546  /* Configure DMA user callbacks */
549 
550  /* Enable the DMA Channel */
551  HAL_DMA_Start_IT(hsram->hdma, (uint32_t)pSrcBuffer, (uint32_t)pAddress, (uint32_t)BufferSize);
552 
553  /* Update the SRAM controller state */
554  hsram->State = HAL_SRAM_STATE_READY;
555 
556  /* Process unlocked */
557  __HAL_UNLOCK(hsram);
558 
559  return HAL_OK;
560 }
561 
588 {
589  /* Process Locked */
590  __HAL_LOCK(hsram);
591 
592  /* Enable write operation */
594 
595  /* Update the SRAM controller state */
596  hsram->State = HAL_SRAM_STATE_READY;
597 
598  /* Process unlocked */
599  __HAL_UNLOCK(hsram);
600 
601  return HAL_OK;
602 }
603 
611 {
612  /* Process Locked */
613  __HAL_LOCK(hsram);
614 
615  /* Update the SRAM controller state */
616  hsram->State = HAL_SRAM_STATE_BUSY;
617 
618  /* Disable write operation */
620 
621  /* Update the SRAM controller state */
622  hsram->State = HAL_SRAM_STATE_PROTECTED;
623 
624  /* Process unlocked */
625  __HAL_UNLOCK(hsram);
626 
627  return HAL_OK;
628 }
629 
655 HAL_SRAM_StateTypeDef HAL_SRAM_GetState(SRAM_HandleTypeDef *hsram)
656 {
657  /* Return SRAM handle state */
658  return hsram->State;
659 }
660 
673 #endif /* HAL_SRAM_MODULE_ENABLED */
674 
679 #endif /* FMC_BANK1 */
680 
681 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
HAL_StatusTypeDef HAL_SRAM_DeInit(SRAM_HandleTypeDef *hsram)
Perform the SRAM device de-initialization sequence.
DMA_HandleTypeDef * hdma
void HAL_SRAM_MspInit(SRAM_HandleTypeDef *hsram)
Initialize the SRAM MSP.
HAL_StatusTypeDef HAL_SRAM_Write_DMA(SRAM_HandleTypeDef *hsram, uint32_t *pAddress, uint32_t *pSrcBuffer, uint32_t BufferSize)
Write a Word data buffer to SRAM memory using DMA transfer.
HAL_LockTypeDef Lock
DMA handle Structure definition.
void(* XferCpltCallback)(struct __DMA_HandleTypeDef *hdma)
__weak void HAL_SRAM_DMA_XferCpltCallback(DMA_HandleTypeDef *hdma)
DMA transfer complete callback.
This file contains all the functions prototypes for the HAL module driver.
HAL_SRAM_StateTypeDef HAL_SRAM_GetState(SRAM_HandleTypeDef *hsram)
Return the SRAM controller state.
HAL_StatusTypeDef HAL_SRAM_Init(SRAM_HandleTypeDef *hsram, FMC_NORSRAM_TimingTypeDef *Timing, FMC_NORSRAM_TimingTypeDef *ExtTiming)
Perform the SRAM device initialization sequence.
void(* XferErrorCallback)(struct __DMA_HandleTypeDef *hdma)
__HAL_UNLOCK(hrtc)
HAL_StatusTypeDef HAL_DMA_Start_IT(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength)
Start the DMA Transfer with interrupt enabled.
FMC_NORSRAM_TypeDef * Instance
__HAL_LOCK(hrtc)
HAL_StatusTypeDef FMC_NORSRAM_DeInit(FMC_NORSRAM_TypeDef *Device, FMC_NORSRAM_EXTENDED_TypeDef *ExDevice, uint32_t Bank)
DeInitialize the FMC_NORSRAM peripheral.
return HAL_OK
HAL_StatusTypeDef HAL_SRAM_Write_16b(SRAM_HandleTypeDef *hsram, uint32_t *pAddress, uint16_t *pSrcBuffer, uint32_t BufferSize)
Write 16-bit buffer to SRAM memory.
__weak void HAL_SRAM_DMA_XferErrorCallback(DMA_HandleTypeDef *hdma)
DMA transfer complete error callback.
HAL_StatusTypeDef HAL_SRAM_Read_8b(SRAM_HandleTypeDef *hsram, uint32_t *pAddress, uint8_t *pDstBuffer, uint32_t BufferSize)
Read 8-bit buffer from SRAM memory.
HAL_StatusTypeDef FMC_NORSRAM_Extended_Timing_Init(FMC_NORSRAM_EXTENDED_TypeDef *Device, FMC_NORSRAM_TimingTypeDef *Timing, uint32_t Bank, uint32_t ExtendedMode)
Initialize the FMC_NORSRAM Extended mode Timing according to the specified parameters in the FMC_NORS...
HAL_StatusTypeDef HAL_SRAM_Write_32b(SRAM_HandleTypeDef *hsram, uint32_t *pAddress, uint32_t *pSrcBuffer, uint32_t BufferSize)
Write 32-bit buffer to SRAM memory.
FMC NORSRAM Timing parameters structure definition.
HAL_StatusTypeDef FMC_NORSRAM_Init(FMC_NORSRAM_TypeDef *Device, FMC_NORSRAM_InitTypeDef *Init)
Initialize the FMC_NORSRAM device according to the specified control parameters in the FMC_NORSRAM_In...
SRAM handle Structure definition.
HAL_StatusTypeDef HAL_SRAM_Read_DMA(SRAM_HandleTypeDef *hsram, uint32_t *pAddress, uint32_t *pDstBuffer, uint32_t BufferSize)
Read a Word data buffer from the SRAM memory using DMA transfer.
FMC_NORSRAM_EXTENDED_TypeDef * Extended
HAL_StatusTypeDef HAL_SRAM_Read_16b(SRAM_HandleTypeDef *hsram, uint32_t *pAddress, uint16_t *pDstBuffer, uint32_t BufferSize)
Read 16-bit buffer from SRAM memory.
HAL_StatusTypeDef HAL_SRAM_Write_8b(SRAM_HandleTypeDef *hsram, uint32_t *pAddress, uint8_t *pSrcBuffer, uint32_t BufferSize)
Write 8-bit buffer to SRAM memory.
HAL_StatusTypeDef FMC_NORSRAM_WriteOperation_Disable(FMC_NORSRAM_TypeDef *Device, uint32_t Bank)
Disables dynamically FMC_NORSRAM write operation.
void HAL_SRAM_MspDeInit(SRAM_HandleTypeDef *hsram)
DeInitialize the SRAM MSP.
FMC_NORSRAM_InitTypeDef Init
HAL_StatusTypeDef HAL_SRAM_WriteOperation_Enable(SRAM_HandleTypeDef *hsram)
Enable dynamically SRAM write operation.
HAL_StatusTypeDef FMC_NORSRAM_Timing_Init(FMC_NORSRAM_TypeDef *Device, FMC_NORSRAM_TimingTypeDef *Timing, uint32_t Bank)
Initialize the FMC_NORSRAM Timing according to the specified parameters in the FMC_NORSRAM_TimingType...
HAL_StatusTypeDef FMC_NORSRAM_WriteOperation_Enable(FMC_NORSRAM_TypeDef *Device, uint32_t Bank)
Enables dynamically FMC_NORSRAM write operation.
HAL_StatusTypeDef HAL_SRAM_WriteOperation_Disable(SRAM_HandleTypeDef *hsram)
Disable dynamically SRAM write operation.
__IO HAL_SRAM_StateTypeDef State
HAL_StatusTypeDef HAL_SRAM_Read_32b(SRAM_HandleTypeDef *hsram, uint32_t *pAddress, uint32_t *pDstBuffer, uint32_t BufferSize)
Read 32-bit buffer from SRAM memory.