STM32F769IDiscovery  1.00
uDANTE Audio Networking with STM32F7 DISCO board
stm32f7xx_hal_sram.c
Go to the documentation of this file.
1 
94 /* Includes ------------------------------------------------------------------*/
95 #include "stm32f7xx_hal.h"
96 
105 #ifdef HAL_SRAM_MODULE_ENABLED
106 /* Private typedef -----------------------------------------------------------*/
107 /* Private define ------------------------------------------------------------*/
108 /* Private macro -------------------------------------------------------------*/
109 /* Private variables ---------------------------------------------------------*/
110 /* Private function prototypes -----------------------------------------------*/
111 /* Exported functions --------------------------------------------------------*/
112 
140 {
141  /* Check the SRAM handle parameter */
142  if(hsram == NULL)
143  {
144  return HAL_ERROR;
145  }
146 
147  if(hsram->State == HAL_SRAM_STATE_RESET)
148  {
149  /* Allocate lock resource and initialize it */
150  hsram->Lock = HAL_UNLOCKED;
151  /* Initialize the low level hardware (MSP) */
152  HAL_SRAM_MspInit(hsram);
153  }
154 
155  /* Initialize SRAM control Interface */
156  FMC_NORSRAM_Init(hsram->Instance, &(hsram->Init));
157 
158  /* Initialize SRAM timing Interface */
159  FMC_NORSRAM_Timing_Init(hsram->Instance, Timing, hsram->Init.NSBank);
160 
161  /* Initialize SRAM extended mode timing Interface */
162  FMC_NORSRAM_Extended_Timing_Init(hsram->Extended, ExtTiming, hsram->Init.NSBank, hsram->Init.ExtendedMode);
163 
164  /* Enable the NORSRAM device */
165  __FMC_NORSRAM_ENABLE(hsram->Instance, hsram->Init.NSBank);
166 
167  return HAL_OK;
168 }
169 
177 {
178  /* De-Initialize the low level hardware (MSP) */
179  HAL_SRAM_MspDeInit(hsram);
180 
181  /* Configure the SRAM registers with their reset values */
182  FMC_NORSRAM_DeInit(hsram->Instance, hsram->Extended, hsram->Init.NSBank);
183 
184  hsram->State = HAL_SRAM_STATE_RESET;
185 
186  /* Release Lock */
187  __HAL_UNLOCK(hsram);
188 
189  return HAL_OK;
190 }
191 
198 __weak void HAL_SRAM_MspInit(SRAM_HandleTypeDef *hsram)
199 {
200  /* Prevent unused argument(s) compilation warning */
201  UNUSED(hsram);
202 
203  /* NOTE : This function Should not be modified, when the callback is needed,
204  the HAL_SRAM_MspInit could be implemented in the user file
205  */
206 }
207 
214 __weak void HAL_SRAM_MspDeInit(SRAM_HandleTypeDef *hsram)
215 {
216  /* Prevent unused argument(s) compilation warning */
217  UNUSED(hsram);
218 
219  /* NOTE : This function Should not be modified, when the callback is needed,
220  the HAL_SRAM_MspDeInit could be implemented in the user file
221  */
222 }
223 
231 {
232  /* Prevent unused argument(s) compilation warning */
233  UNUSED(hdma);
234 
235  /* NOTE : This function Should not be modified, when the callback is needed,
236  the HAL_SRAM_DMA_XferCpltCallback could be implemented in the user file
237  */
238 }
239 
247 {
248  /* Prevent unused argument(s) compilation warning */
249  UNUSED(hdma);
250 
251  /* NOTE : This function Should not be modified, when the callback is needed,
252  the HAL_SRAM_DMA_XferErrorCallback could be implemented in the user file
253  */
254 }
255 
283 HAL_StatusTypeDef HAL_SRAM_Read_8b(SRAM_HandleTypeDef *hsram, uint32_t *pAddress, uint8_t *pDstBuffer, uint32_t BufferSize)
284 {
285  __IO uint8_t * psramaddress = (uint8_t *)pAddress;
286 
287  /* Process Locked */
288  __HAL_LOCK(hsram);
289 
290  /* Update the SRAM controller state */
291  hsram->State = HAL_SRAM_STATE_BUSY;
292 
293  /* Read data from memory */
294  for(; BufferSize != 0; BufferSize--)
295  {
296  *pDstBuffer = *(__IO uint8_t *)psramaddress;
297  pDstBuffer++;
298  psramaddress++;
299  }
300 
301  /* Update the SRAM controller state */
302  hsram->State = HAL_SRAM_STATE_READY;
303 
304  /* Process unlocked */
305  __HAL_UNLOCK(hsram);
306 
307  return HAL_OK;
308 }
309 
319 HAL_StatusTypeDef HAL_SRAM_Write_8b(SRAM_HandleTypeDef *hsram, uint32_t *pAddress, uint8_t *pSrcBuffer, uint32_t BufferSize)
320 {
321  __IO uint8_t * psramaddress = (uint8_t *)pAddress;
322 
323  /* Check the SRAM controller state */
324  if(hsram->State == HAL_SRAM_STATE_PROTECTED)
325  {
326  return HAL_ERROR;
327  }
328 
329  /* Process Locked */
330  __HAL_LOCK(hsram);
331 
332  /* Update the SRAM controller state */
333  hsram->State = HAL_SRAM_STATE_BUSY;
334 
335  /* Write data to memory */
336  for(; BufferSize != 0; BufferSize--)
337  {
338  *(__IO uint8_t *)psramaddress = *pSrcBuffer;
339  pSrcBuffer++;
340  psramaddress++;
341  }
342 
343  /* Update the SRAM controller state */
344  hsram->State = HAL_SRAM_STATE_READY;
345 
346  /* Process unlocked */
347  __HAL_UNLOCK(hsram);
348 
349  return HAL_OK;
350 }
351 
361 HAL_StatusTypeDef HAL_SRAM_Read_16b(SRAM_HandleTypeDef *hsram, uint32_t *pAddress, uint16_t *pDstBuffer, uint32_t BufferSize)
362 {
363  __IO uint16_t * psramaddress = (uint16_t *)pAddress;
364 
365  /* Process Locked */
366  __HAL_LOCK(hsram);
367 
368  /* Update the SRAM controller state */
369  hsram->State = HAL_SRAM_STATE_BUSY;
370 
371  /* Read data from memory */
372  for(; BufferSize != 0; BufferSize--)
373  {
374  *pDstBuffer = *(__IO uint16_t *)psramaddress;
375  pDstBuffer++;
376  psramaddress++;
377  }
378 
379  /* Update the SRAM controller state */
380  hsram->State = HAL_SRAM_STATE_READY;
381 
382  /* Process unlocked */
383  __HAL_UNLOCK(hsram);
384 
385  return HAL_OK;
386 }
387 
397 HAL_StatusTypeDef HAL_SRAM_Write_16b(SRAM_HandleTypeDef *hsram, uint32_t *pAddress, uint16_t *pSrcBuffer, uint32_t BufferSize)
398 {
399  __IO uint16_t * psramaddress = (uint16_t *)pAddress;
400 
401  /* Check the SRAM controller state */
402  if(hsram->State == HAL_SRAM_STATE_PROTECTED)
403  {
404  return HAL_ERROR;
405  }
406 
407  /* Process Locked */
408  __HAL_LOCK(hsram);
409 
410  /* Update the SRAM controller state */
411  hsram->State = HAL_SRAM_STATE_BUSY;
412 
413  /* Write data to memory */
414  for(; BufferSize != 0; BufferSize--)
415  {
416  *(__IO uint16_t *)psramaddress = *pSrcBuffer;
417  pSrcBuffer++;
418  psramaddress++;
419  }
420 
421  /* Update the SRAM controller state */
422  hsram->State = HAL_SRAM_STATE_READY;
423 
424  /* Process unlocked */
425  __HAL_UNLOCK(hsram);
426 
427  return HAL_OK;
428 }
429 
439 HAL_StatusTypeDef HAL_SRAM_Read_32b(SRAM_HandleTypeDef *hsram, uint32_t *pAddress, uint32_t *pDstBuffer, uint32_t BufferSize)
440 {
441  /* Process Locked */
442  __HAL_LOCK(hsram);
443 
444  /* Update the SRAM controller state */
445  hsram->State = HAL_SRAM_STATE_BUSY;
446 
447  /* Read data from memory */
448  for(; BufferSize != 0; BufferSize--)
449  {
450  *pDstBuffer = *(__IO uint32_t *)pAddress;
451  pDstBuffer++;
452  pAddress++;
453  }
454 
455  /* Update the SRAM controller state */
456  hsram->State = HAL_SRAM_STATE_READY;
457 
458  /* Process unlocked */
459  __HAL_UNLOCK(hsram);
460 
461  return HAL_OK;
462 }
463 
473 HAL_StatusTypeDef HAL_SRAM_Write_32b(SRAM_HandleTypeDef *hsram, uint32_t *pAddress, uint32_t *pSrcBuffer, uint32_t BufferSize)
474 {
475  /* Check the SRAM controller state */
476  if(hsram->State == HAL_SRAM_STATE_PROTECTED)
477  {
478  return HAL_ERROR;
479  }
480 
481  /* Process Locked */
482  __HAL_LOCK(hsram);
483 
484  /* Update the SRAM controller state */
485  hsram->State = HAL_SRAM_STATE_BUSY;
486 
487  /* Write data to memory */
488  for(; BufferSize != 0; BufferSize--)
489  {
490  *(__IO uint32_t *)pAddress = *pSrcBuffer;
491  pSrcBuffer++;
492  pAddress++;
493  }
494 
495  /* Update the SRAM controller state */
496  hsram->State = HAL_SRAM_STATE_READY;
497 
498  /* Process unlocked */
499  __HAL_UNLOCK(hsram);
500 
501  return HAL_OK;
502 }
503 
513 HAL_StatusTypeDef HAL_SRAM_Read_DMA(SRAM_HandleTypeDef *hsram, uint32_t *pAddress, uint32_t *pDstBuffer, uint32_t BufferSize)
514 {
515  /* Process Locked */
516  __HAL_LOCK(hsram);
517 
518  /* Update the SRAM controller state */
519  hsram->State = HAL_SRAM_STATE_BUSY;
520 
521  /* Configure DMA user callbacks */
524 
525  /* Enable the DMA Stream */
526  HAL_DMA_Start_IT(hsram->hdma, (uint32_t)pAddress, (uint32_t)pDstBuffer, (uint32_t)BufferSize);
527 
528  /* Update the SRAM controller state */
529  hsram->State = HAL_SRAM_STATE_READY;
530 
531  /* Process unlocked */
532  __HAL_UNLOCK(hsram);
533 
534  return HAL_OK;
535 }
536 
546 HAL_StatusTypeDef HAL_SRAM_Write_DMA(SRAM_HandleTypeDef *hsram, uint32_t *pAddress, uint32_t *pSrcBuffer, uint32_t BufferSize)
547 {
548  /* Check the SRAM controller state */
549  if(hsram->State == HAL_SRAM_STATE_PROTECTED)
550  {
551  return HAL_ERROR;
552  }
553 
554  /* Process Locked */
555  __HAL_LOCK(hsram);
556 
557  /* Update the SRAM controller state */
558  hsram->State = HAL_SRAM_STATE_BUSY;
559 
560  /* Configure DMA user callbacks */
563 
564  /* Enable the DMA Stream */
565  HAL_DMA_Start_IT(hsram->hdma, (uint32_t)pSrcBuffer, (uint32_t)pAddress, (uint32_t)BufferSize);
566 
567  /* Update the SRAM controller state */
568  hsram->State = HAL_SRAM_STATE_READY;
569 
570  /* Process unlocked */
571  __HAL_UNLOCK(hsram);
572 
573  return HAL_OK;
574 }
575 
602 {
603  /* Process Locked */
604  __HAL_LOCK(hsram);
605 
606  /* Enable write operation */
608 
609  /* Update the SRAM controller state */
610  hsram->State = HAL_SRAM_STATE_READY;
611 
612  /* Process unlocked */
613  __HAL_UNLOCK(hsram);
614 
615  return HAL_OK;
616 }
617 
625 {
626  /* Process Locked */
627  __HAL_LOCK(hsram);
628 
629  /* Update the SRAM controller state */
630  hsram->State = HAL_SRAM_STATE_BUSY;
631 
632  /* Disable write operation */
634 
635  /* Update the SRAM controller state */
637 
638  /* Process unlocked */
639  __HAL_UNLOCK(hsram);
640 
641  return HAL_OK;
642 }
643 
670 {
671  return hsram->State;
672 }
673 
681 #endif /* HAL_SRAM_MODULE_ENABLED */
682 
690 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
HAL_StatusTypeDef HAL_SRAM_WriteOperation_Disable(SRAM_HandleTypeDef *hsram)
HAL_StatusTypeDef HAL_SRAM_Write_DMA(SRAM_HandleTypeDef *hsram, uint32_t *pAddress, uint32_t *pSrcBuffer, uint32_t BufferSize)
HAL_StatusTypeDef FMC_NORSRAM_Init(FMC_NORSRAM_TypeDef *Device, FMC_NORSRAM_InitTypeDef *Init)
HAL_StatusTypeDef HAL_SRAM_DeInit(SRAM_HandleTypeDef *hsram)
HAL_StatusTypeDef HAL_SRAM_WriteOperation_Enable(SRAM_HandleTypeDef *hsram)
#define __FMC_NORSRAM_ENABLE(__INSTANCE__, __BANK__)
Enable the NORSRAM device access.
__IO HAL_SRAM_StateTypeDef State
HAL_StatusTypeDef HAL_SRAM_Read_16b(SRAM_HandleTypeDef *hsram, uint32_t *pAddress, uint16_t *pDstBuffer, uint32_t BufferSize)
#define __HAL_UNLOCK(__HANDLE__)
HAL_StatusTypeDef HAL_DMA_Start_IT(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength)
HAL_SRAM_StateTypeDef
HAL SRAM State structures definition.
HAL_StatusTypeDef HAL_SRAM_Read_DMA(SRAM_HandleTypeDef *hsram, uint32_t *pAddress, uint32_t *pDstBuffer, uint32_t BufferSize)
void HAL_SRAM_MspInit(SRAM_HandleTypeDef *hsram)
DMA_HandleTypeDef * hdma
FMC NORSRAM Timing parameters structure definition.
void(* XferCpltCallback)(struct __DMA_HandleTypeDef *hdma)
#define __HAL_LOCK(__HANDLE__)
#define NULL
Definition: usbd_def.h:53
void HAL_SRAM_DMA_XferErrorCallback(DMA_HandleTypeDef *hdma)
#define __IO
Definition: core_cm0.h:213
HAL_StatusTypeDef FMC_NORSRAM_Timing_Init(FMC_NORSRAM_TypeDef *Device, FMC_NORSRAM_TimingTypeDef *Timing, uint32_t Bank)
HAL_LockTypeDef Lock
HAL_StatusTypeDef HAL_SRAM_Read_8b(SRAM_HandleTypeDef *hsram, uint32_t *pAddress, uint8_t *pDstBuffer, uint32_t BufferSize)
HAL_SRAM_StateTypeDef HAL_SRAM_GetState(SRAM_HandleTypeDef *hsram)
This file contains all the functions prototypes for the HAL module driver.
void HAL_SRAM_MspDeInit(SRAM_HandleTypeDef *hsram)
HAL_StatusTypeDef FMC_NORSRAM_WriteOperation_Disable(FMC_NORSRAM_TypeDef *Device, uint32_t Bank)
HAL_StatusTypeDef HAL_SRAM_Init(SRAM_HandleTypeDef *hsram, FMC_NORSRAM_TimingTypeDef *Timing, FMC_NORSRAM_TimingTypeDef *ExtTiming)
HAL_StatusTypeDef HAL_SRAM_Write_32b(SRAM_HandleTypeDef *hsram, uint32_t *pAddress, uint32_t *pSrcBuffer, uint32_t BufferSize)
#define UNUSED(x)
HAL_StatusTypeDef HAL_SRAM_Write_16b(SRAM_HandleTypeDef *hsram, uint32_t *pAddress, uint16_t *pSrcBuffer, uint32_t BufferSize)
SRAM handle Structure definition.
HAL_StatusTypeDef FMC_NORSRAM_WriteOperation_Enable(FMC_NORSRAM_TypeDef *Device, uint32_t Bank)
DMA handle Structure definition.
HAL_StatusTypeDef FMC_NORSRAM_Extended_Timing_Init(FMC_NORSRAM_EXTENDED_TypeDef *Device, FMC_NORSRAM_TimingTypeDef *Timing, uint32_t Bank, uint32_t ExtendedMode)
HAL_StatusTypeDef FMC_NORSRAM_DeInit(FMC_NORSRAM_TypeDef *Device, FMC_NORSRAM_EXTENDED_TypeDef *ExDevice, uint32_t Bank)
HAL_StatusTypeDef HAL_SRAM_Read_32b(SRAM_HandleTypeDef *hsram, uint32_t *pAddress, uint32_t *pDstBuffer, uint32_t BufferSize)
HAL_StatusTypeDef HAL_SRAM_Write_8b(SRAM_HandleTypeDef *hsram, uint32_t *pAddress, uint8_t *pSrcBuffer, uint32_t BufferSize)
HAL_StatusTypeDef
HAL Status structures definition.
void HAL_SRAM_DMA_XferCpltCallback(DMA_HandleTypeDef *hdma)
void(* XferErrorCallback)(struct __DMA_HandleTypeDef *hdma)
FMC_NORSRAM_InitTypeDef Init
FMC_NORSRAM_TypeDef * Instance
FMC_NORSRAM_EXTENDED_TypeDef * Extended