![]() |
|
|||
File indexing completed on 2025-05-11 08:23:09
0001 /** 0002 ****************************************************************************** 0003 * @file stm32h7xx_hal_sram.c 0004 * @author MCD Application Team 0005 * @brief SRAM HAL module driver. 0006 * This file provides a generic firmware to drive SRAM memories 0007 * mounted as external device. 0008 * 0009 ****************************************************************************** 0010 * @attention 0011 * 0012 * Copyright (c) 2017 STMicroelectronics. 0013 * All rights reserved. 0014 * 0015 * This software is licensed under terms that can be found in the LICENSE file 0016 * in the root directory of this software component. 0017 * If no LICENSE file comes with this software, it is provided AS-IS. 0018 * 0019 ****************************************************************************** 0020 @verbatim 0021 ============================================================================== 0022 ##### How to use this driver ##### 0023 ============================================================================== 0024 [..] 0025 This driver is a generic layered driver which contains a set of APIs used to 0026 control SRAM memories. It uses the FMC layer functions to interface 0027 with SRAM devices. 0028 The following sequence should be followed to configure the FMC to interface 0029 with SRAM/PSRAM memories: 0030 0031 (#) Declare a SRAM_HandleTypeDef handle structure, for example: 0032 SRAM_HandleTypeDef hsram; and: 0033 0034 (++) Fill the SRAM_HandleTypeDef handle "Init" field with the allowed 0035 values of the structure member. 0036 0037 (++) Fill the SRAM_HandleTypeDef handle "Instance" field with a predefined 0038 base register instance for NOR or SRAM device 0039 0040 (++) Fill the SRAM_HandleTypeDef handle "Extended" field with a predefined 0041 base register instance for NOR or SRAM extended mode 0042 0043 (#) Declare two FMC_NORSRAM_TimingTypeDef structures, for both normal and extended 0044 mode timings; for example: 0045 FMC_NORSRAM_TimingTypeDef Timing and FMC_NORSRAM_TimingTypeDef ExTiming; 0046 and fill its fields with the allowed values of the structure member. 0047 0048 (#) Initialize the SRAM Controller by calling the function HAL_SRAM_Init(). This function 0049 performs the following sequence: 0050 0051 (##) MSP hardware layer configuration using the function HAL_SRAM_MspInit() 0052 (##) Control register configuration using the FMC NORSRAM interface function 0053 FMC_NORSRAM_Init() 0054 (##) Timing register configuration using the FMC NORSRAM interface function 0055 FMC_NORSRAM_Timing_Init() 0056 (##) Extended mode Timing register configuration using the FMC NORSRAM interface function 0057 FMC_NORSRAM_Extended_Timing_Init() 0058 (##) Enable the SRAM device using the macro __FMC_NORSRAM_ENABLE() 0059 0060 (#) At this stage you can perform read/write accesses from/to the memory connected 0061 to the NOR/SRAM Bank. You can perform either polling or DMA transfer using the 0062 following APIs: 0063 (++) HAL_SRAM_Read()/HAL_SRAM_Write() for polling read/write access 0064 (++) HAL_SRAM_Read_DMA()/HAL_SRAM_Write_DMA() for DMA read/write transfer 0065 0066 (#) You can also control the SRAM device by calling the control APIs HAL_SRAM_WriteOperation_Enable()/ 0067 HAL_SRAM_WriteOperation_Disable() to respectively enable/disable the SRAM write operation 0068 0069 (#) You can continuously monitor the SRAM device HAL state by calling the function 0070 HAL_SRAM_GetState() 0071 0072 *** Callback registration *** 0073 ============================================= 0074 [..] 0075 The compilation define USE_HAL_SRAM_REGISTER_CALLBACKS when set to 1 0076 allows the user to configure dynamically the driver callbacks. 0077 0078 Use Functions HAL_SRAM_RegisterCallback() to register a user callback, 0079 it allows to register following callbacks: 0080 (+) MspInitCallback : SRAM MspInit. 0081 (+) MspDeInitCallback : SRAM MspDeInit. 0082 This function takes as parameters the HAL peripheral handle, the Callback ID 0083 and a pointer to the user callback function. 0084 0085 Use function HAL_SRAM_UnRegisterCallback() to reset a callback to the default 0086 weak (overridden) function. It allows to reset following callbacks: 0087 (+) MspInitCallback : SRAM MspInit. 0088 (+) MspDeInitCallback : SRAM MspDeInit. 0089 This function) takes as parameters the HAL peripheral handle and the Callback ID. 0090 0091 By default, after the HAL_SRAM_Init and if the state is HAL_SRAM_STATE_RESET 0092 all callbacks are reset to the corresponding legacy weak (overridden) functions. 0093 Exception done for MspInit and MspDeInit callbacks that are respectively 0094 reset to the legacy weak (overridden) functions in the HAL_SRAM_Init 0095 and HAL_SRAM_DeInit only when these callbacks are null (not registered beforehand). 0096 If not, MspInit or MspDeInit are not null, the HAL_SRAM_Init and HAL_SRAM_DeInit 0097 keep and use the user MspInit/MspDeInit callbacks (registered beforehand) 0098 0099 Callbacks can be registered/unregistered in READY state only. 0100 Exception done for MspInit/MspDeInit callbacks that can be registered/unregistered 0101 in READY or RESET state, thus registered (user) MspInit/DeInit callbacks can be used 0102 during the Init/DeInit. 0103 In that case first register the MspInit/MspDeInit user callbacks 0104 using HAL_SRAM_RegisterCallback before calling HAL_SRAM_DeInit 0105 or HAL_SRAM_Init function. 0106 0107 When The compilation define USE_HAL_SRAM_REGISTER_CALLBACKS is set to 0 or 0108 not defined, the callback registering feature is not available 0109 and weak (overridden) callbacks are used. 0110 0111 @endverbatim 0112 ****************************************************************************** 0113 */ 0114 0115 /* Includes ------------------------------------------------------------------*/ 0116 #include "stm32h7xx_hal.h" 0117 0118 0119 /** @addtogroup STM32H7xx_HAL_Driver 0120 * @{ 0121 */ 0122 0123 #ifdef HAL_SRAM_MODULE_ENABLED 0124 0125 /** @defgroup SRAM SRAM 0126 * @ingroup RTEMSBSPsARMSTM32H7 0127 * @brief SRAM driver modules 0128 * @{ 0129 */ 0130 0131 /* Private typedef -----------------------------------------------------------*/ 0132 /* Private define ------------------------------------------------------------*/ 0133 /* Private macro -------------------------------------------------------------*/ 0134 /* Private variables ---------------------------------------------------------*/ 0135 /* Private function prototypes -----------------------------------------------*/ 0136 /** @addtogroup SRAM_Private_Functions SRAM Private Functions 0137 * @{ 0138 */ 0139 static void SRAM_DMACplt(MDMA_HandleTypeDef *hmdma); 0140 static void SRAM_DMACpltProt(MDMA_HandleTypeDef *hmdma); 0141 static void SRAM_DMAError(MDMA_HandleTypeDef *hmdma); 0142 /** 0143 * @} 0144 */ 0145 0146 /* Exported functions --------------------------------------------------------*/ 0147 0148 /** @defgroup SRAM_Exported_Functions SRAM Exported Functions 0149 * @ingroup RTEMSBSPsARMSTM32H7 0150 * @{ 0151 */ 0152 0153 /** @defgroup SRAM_Exported_Functions_Group1 Initialization and de-initialization functions 0154 * @ingroup RTEMSBSPsARMSTM32H7 0155 * @brief Initialization and Configuration functions. 0156 * 0157 @verbatim 0158 ============================================================================== 0159 ##### SRAM Initialization and de_initialization functions ##### 0160 ============================================================================== 0161 [..] This section provides functions allowing to initialize/de-initialize 0162 the SRAM memory 0163 0164 @endverbatim 0165 * @{ 0166 */ 0167 0168 /** 0169 * @brief Performs the SRAM device initialization sequence 0170 * @param hsram pointer to a SRAM_HandleTypeDef structure that contains 0171 * the configuration information for SRAM module. 0172 * @param Timing Pointer to SRAM control timing structure 0173 * @param ExtTiming Pointer to SRAM extended mode timing structure 0174 * @retval HAL status 0175 */ 0176 HAL_StatusTypeDef HAL_SRAM_Init(SRAM_HandleTypeDef *hsram, FMC_NORSRAM_TimingTypeDef *Timing, 0177 FMC_NORSRAM_TimingTypeDef *ExtTiming) 0178 { 0179 /* Check the SRAM handle parameter */ 0180 if (hsram == NULL) 0181 { 0182 return HAL_ERROR; 0183 } 0184 0185 if (hsram->State == HAL_SRAM_STATE_RESET) 0186 { 0187 /* Allocate lock resource and initialize it */ 0188 hsram->Lock = HAL_UNLOCKED; 0189 0190 #if (USE_HAL_SRAM_REGISTER_CALLBACKS == 1) 0191 if (hsram->MspInitCallback == NULL) 0192 { 0193 hsram->MspInitCallback = HAL_SRAM_MspInit; 0194 } 0195 hsram->DmaXferCpltCallback = HAL_SRAM_DMA_XferCpltCallback; 0196 hsram->DmaXferErrorCallback = HAL_SRAM_DMA_XferErrorCallback; 0197 0198 /* Init the low level hardware */ 0199 hsram->MspInitCallback(hsram); 0200 #else 0201 /* Initialize the low level hardware (MSP) */ 0202 HAL_SRAM_MspInit(hsram); 0203 #endif /* USE_HAL_SRAM_REGISTER_CALLBACKS */ 0204 } 0205 0206 /* Initialize SRAM control Interface */ 0207 (void)FMC_NORSRAM_Init(hsram->Instance, &(hsram->Init)); 0208 0209 /* Initialize SRAM timing Interface */ 0210 (void)FMC_NORSRAM_Timing_Init(hsram->Instance, Timing, hsram->Init.NSBank); 0211 0212 /* Initialize SRAM extended mode timing Interface */ 0213 (void)FMC_NORSRAM_Extended_Timing_Init(hsram->Extended, ExtTiming, hsram->Init.NSBank, 0214 hsram->Init.ExtendedMode); 0215 0216 /* Enable the NORSRAM device */ 0217 __FMC_NORSRAM_ENABLE(hsram->Instance, hsram->Init.NSBank); 0218 0219 /* Enable FMC Peripheral */ 0220 __FMC_ENABLE(); 0221 0222 /* Initialize the SRAM controller state */ 0223 hsram->State = HAL_SRAM_STATE_READY; 0224 0225 return HAL_OK; 0226 } 0227 0228 /** 0229 * @brief Performs the SRAM device De-initialization sequence. 0230 * @param hsram pointer to a SRAM_HandleTypeDef structure that contains 0231 * the configuration information for SRAM module. 0232 * @retval HAL status 0233 */ 0234 HAL_StatusTypeDef HAL_SRAM_DeInit(SRAM_HandleTypeDef *hsram) 0235 { 0236 #if (USE_HAL_SRAM_REGISTER_CALLBACKS == 1) 0237 if (hsram->MspDeInitCallback == NULL) 0238 { 0239 hsram->MspDeInitCallback = HAL_SRAM_MspDeInit; 0240 } 0241 0242 /* DeInit the low level hardware */ 0243 hsram->MspDeInitCallback(hsram); 0244 #else 0245 /* De-Initialize the low level hardware (MSP) */ 0246 HAL_SRAM_MspDeInit(hsram); 0247 #endif /* USE_HAL_SRAM_REGISTER_CALLBACKS */ 0248 0249 /* Configure the SRAM registers with their reset values */ 0250 (void)FMC_NORSRAM_DeInit(hsram->Instance, hsram->Extended, hsram->Init.NSBank); 0251 0252 /* Reset the SRAM controller state */ 0253 hsram->State = HAL_SRAM_STATE_RESET; 0254 0255 /* Release Lock */ 0256 __HAL_UNLOCK(hsram); 0257 0258 return HAL_OK; 0259 } 0260 0261 /** 0262 * @brief SRAM MSP Init. 0263 * @param hsram pointer to a SRAM_HandleTypeDef structure that contains 0264 * the configuration information for SRAM module. 0265 * @retval None 0266 */ 0267 __weak void HAL_SRAM_MspInit(SRAM_HandleTypeDef *hsram) 0268 { 0269 /* Prevent unused argument(s) compilation warning */ 0270 UNUSED(hsram); 0271 0272 /* NOTE : This function Should not be modified, when the callback is needed, 0273 the HAL_SRAM_MspInit could be implemented in the user file 0274 */ 0275 } 0276 0277 /** 0278 * @brief SRAM MSP DeInit. 0279 * @param hsram pointer to a SRAM_HandleTypeDef structure that contains 0280 * the configuration information for SRAM module. 0281 * @retval None 0282 */ 0283 __weak void HAL_SRAM_MspDeInit(SRAM_HandleTypeDef *hsram) 0284 { 0285 /* Prevent unused argument(s) compilation warning */ 0286 UNUSED(hsram); 0287 0288 /* NOTE : This function Should not be modified, when the callback is needed, 0289 the HAL_SRAM_MspDeInit could be implemented in the user file 0290 */ 0291 } 0292 0293 /** 0294 * @brief DMA transfer complete callback. 0295 * @param hmdma pointer to a SRAM_HandleTypeDef structure that contains 0296 * the configuration information for SRAM module. 0297 * @retval None 0298 */ 0299 __weak void HAL_SRAM_DMA_XferCpltCallback(MDMA_HandleTypeDef *hmdma) 0300 { 0301 /* Prevent unused argument(s) compilation warning */ 0302 UNUSED(hmdma); 0303 0304 /* NOTE : This function Should not be modified, when the callback is needed, 0305 the HAL_SRAM_DMA_XferCpltCallback could be implemented in the user file 0306 */ 0307 } 0308 0309 /** 0310 * @brief DMA transfer complete error callback. 0311 * @param hmdma pointer to a SRAM_HandleTypeDef structure that contains 0312 * the configuration information for SRAM module. 0313 * @retval None 0314 */ 0315 __weak void HAL_SRAM_DMA_XferErrorCallback(MDMA_HandleTypeDef *hmdma) 0316 { 0317 /* Prevent unused argument(s) compilation warning */ 0318 UNUSED(hmdma); 0319 0320 /* NOTE : This function Should not be modified, when the callback is needed, 0321 the HAL_SRAM_DMA_XferErrorCallback could be implemented in the user file 0322 */ 0323 } 0324 0325 /** 0326 * @} 0327 */ 0328 0329 /** @defgroup SRAM_Exported_Functions_Group2 Input Output and memory control functions 0330 * @ingroup RTEMSBSPsARMSTM32H7 0331 * @brief Input Output and memory control functions 0332 * 0333 @verbatim 0334 ============================================================================== 0335 ##### SRAM Input and Output functions ##### 0336 ============================================================================== 0337 [..] 0338 This section provides functions allowing to use and control the SRAM memory 0339 0340 @endverbatim 0341 * @{ 0342 */ 0343 0344 /** 0345 * @brief Reads 8-bit buffer from SRAM memory. 0346 * @param hsram pointer to a SRAM_HandleTypeDef structure that contains 0347 * the configuration information for SRAM module. 0348 * @param pAddress Pointer to read start address 0349 * @param pDstBuffer Pointer to destination buffer 0350 * @param BufferSize Size of the buffer to read from memory 0351 * @retval HAL status 0352 */ 0353 HAL_StatusTypeDef HAL_SRAM_Read_8b(SRAM_HandleTypeDef *hsram, uint32_t *pAddress, uint8_t *pDstBuffer, 0354 uint32_t BufferSize) 0355 { 0356 uint32_t size; 0357 __IO uint8_t *psramaddress = (uint8_t *)pAddress; 0358 uint8_t *pdestbuff = pDstBuffer; 0359 HAL_SRAM_StateTypeDef state = hsram->State; 0360 0361 /* Check the SRAM controller state */ 0362 if ((state == HAL_SRAM_STATE_READY) || (state == HAL_SRAM_STATE_PROTECTED)) 0363 { 0364 /* Process Locked */ 0365 __HAL_LOCK(hsram); 0366 0367 /* Update the SRAM controller state */ 0368 hsram->State = HAL_SRAM_STATE_BUSY; 0369 0370 /* Read data from memory */ 0371 for (size = BufferSize; size != 0U; size--) 0372 { 0373 *pdestbuff = *psramaddress; 0374 pdestbuff++; 0375 psramaddress++; 0376 } 0377 0378 /* Update the SRAM controller state */ 0379 hsram->State = state; 0380 0381 /* Process unlocked */ 0382 __HAL_UNLOCK(hsram); 0383 } 0384 else 0385 { 0386 return HAL_ERROR; 0387 } 0388 0389 return HAL_OK; 0390 } 0391 0392 /** 0393 * @brief Writes 8-bit buffer to SRAM memory. 0394 * @param hsram pointer to a SRAM_HandleTypeDef structure that contains 0395 * the configuration information for SRAM module. 0396 * @param pAddress Pointer to write start address 0397 * @param pSrcBuffer Pointer to source buffer to write 0398 * @param BufferSize Size of the buffer to write to memory 0399 * @retval HAL status 0400 */ 0401 HAL_StatusTypeDef HAL_SRAM_Write_8b(SRAM_HandleTypeDef *hsram, uint32_t *pAddress, uint8_t *pSrcBuffer, 0402 uint32_t BufferSize) 0403 { 0404 uint32_t size; 0405 __IO uint8_t *psramaddress = (uint8_t *)pAddress; 0406 uint8_t *psrcbuff = pSrcBuffer; 0407 0408 /* Check the SRAM controller state */ 0409 if (hsram->State == HAL_SRAM_STATE_READY) 0410 { 0411 /* Process Locked */ 0412 __HAL_LOCK(hsram); 0413 0414 /* Update the SRAM controller state */ 0415 hsram->State = HAL_SRAM_STATE_BUSY; 0416 0417 /* Write data to memory */ 0418 for (size = BufferSize; size != 0U; size--) 0419 { 0420 *psramaddress = *psrcbuff; 0421 psrcbuff++; 0422 psramaddress++; 0423 } 0424 0425 /* Update the SRAM controller state */ 0426 hsram->State = HAL_SRAM_STATE_READY; 0427 0428 /* Process unlocked */ 0429 __HAL_UNLOCK(hsram); 0430 } 0431 else 0432 { 0433 return HAL_ERROR; 0434 } 0435 0436 return HAL_OK; 0437 } 0438 0439 /** 0440 * @brief Reads 16-bit buffer from SRAM memory. 0441 * @param hsram pointer to a SRAM_HandleTypeDef structure that contains 0442 * the configuration information for SRAM module. 0443 * @param pAddress Pointer to read start address 0444 * @param pDstBuffer Pointer to destination buffer 0445 * @param BufferSize Size of the buffer to read from memory 0446 * @retval HAL status 0447 */ 0448 HAL_StatusTypeDef HAL_SRAM_Read_16b(SRAM_HandleTypeDef *hsram, uint32_t *pAddress, uint16_t *pDstBuffer, 0449 uint32_t BufferSize) 0450 { 0451 uint32_t size; 0452 __IO uint32_t *psramaddress = pAddress; 0453 uint16_t *pdestbuff = pDstBuffer; 0454 uint8_t limit; 0455 HAL_SRAM_StateTypeDef state = hsram->State; 0456 0457 /* Check the SRAM controller state */ 0458 if ((state == HAL_SRAM_STATE_READY) || (state == HAL_SRAM_STATE_PROTECTED)) 0459 { 0460 /* Process Locked */ 0461 __HAL_LOCK(hsram); 0462 0463 /* Update the SRAM controller state */ 0464 hsram->State = HAL_SRAM_STATE_BUSY; 0465 0466 /* Check if the size is a 32-bits multiple */ 0467 limit = (((BufferSize % 2U) != 0U) ? 1U : 0U); 0468 0469 /* Read data from memory */ 0470 for (size = BufferSize; size != limit; size -= 2U) 0471 { 0472 *pdestbuff = (uint16_t)((*psramaddress) & 0x0000FFFFU); 0473 pdestbuff++; 0474 *pdestbuff = (uint16_t)(((*psramaddress) & 0xFFFF0000U) >> 16U); 0475 pdestbuff++; 0476 psramaddress++; 0477 } 0478 0479 /* Read last 16-bits if size is not 32-bits multiple */ 0480 if (limit != 0U) 0481 { 0482 *pdestbuff = (uint16_t)((*psramaddress) & 0x0000FFFFU); 0483 } 0484 0485 /* Update the SRAM controller state */ 0486 hsram->State = state; 0487 0488 /* Process unlocked */ 0489 __HAL_UNLOCK(hsram); 0490 } 0491 else 0492 { 0493 return HAL_ERROR; 0494 } 0495 0496 return HAL_OK; 0497 } 0498 0499 /** 0500 * @brief Writes 16-bit buffer to SRAM memory. 0501 * @param hsram pointer to a SRAM_HandleTypeDef structure that contains 0502 * the configuration information for SRAM module. 0503 * @param pAddress Pointer to write start address 0504 * @param pSrcBuffer Pointer to source buffer to write 0505 * @param BufferSize Size of the buffer to write to memory 0506 * @retval HAL status 0507 */ 0508 HAL_StatusTypeDef HAL_SRAM_Write_16b(SRAM_HandleTypeDef *hsram, uint32_t *pAddress, uint16_t *pSrcBuffer, 0509 uint32_t BufferSize) 0510 { 0511 uint32_t size; 0512 __IO uint32_t *psramaddress = pAddress; 0513 uint16_t *psrcbuff = pSrcBuffer; 0514 uint8_t limit; 0515 0516 /* Check the SRAM controller state */ 0517 if (hsram->State == HAL_SRAM_STATE_READY) 0518 { 0519 /* Process Locked */ 0520 __HAL_LOCK(hsram); 0521 0522 /* Update the SRAM controller state */ 0523 hsram->State = HAL_SRAM_STATE_BUSY; 0524 0525 /* Check if the size is a 32-bits multiple */ 0526 limit = (((BufferSize % 2U) != 0U) ? 1U : 0U); 0527 0528 /* Write data to memory */ 0529 for (size = BufferSize; size != limit; size -= 2U) 0530 { 0531 *psramaddress = (uint32_t)(*psrcbuff); 0532 psrcbuff++; 0533 *psramaddress |= ((uint32_t)(*psrcbuff) << 16U); 0534 psrcbuff++; 0535 psramaddress++; 0536 } 0537 0538 /* Write last 16-bits if size is not 32-bits multiple */ 0539 if (limit != 0U) 0540 { 0541 *psramaddress = ((uint32_t)(*psrcbuff) & 0x0000FFFFU) | ((*psramaddress) & 0xFFFF0000U); 0542 } 0543 0544 /* Update the SRAM controller state */ 0545 hsram->State = HAL_SRAM_STATE_READY; 0546 0547 /* Process unlocked */ 0548 __HAL_UNLOCK(hsram); 0549 } 0550 else 0551 { 0552 return HAL_ERROR; 0553 } 0554 0555 return HAL_OK; 0556 } 0557 0558 /** 0559 * @brief Reads 32-bit buffer from SRAM memory. 0560 * @param hsram pointer to a SRAM_HandleTypeDef structure that contains 0561 * the configuration information for SRAM module. 0562 * @param pAddress Pointer to read start address 0563 * @param pDstBuffer Pointer to destination buffer 0564 * @param BufferSize Size of the buffer to read from memory 0565 * @retval HAL status 0566 */ 0567 HAL_StatusTypeDef HAL_SRAM_Read_32b(SRAM_HandleTypeDef *hsram, uint32_t *pAddress, uint32_t *pDstBuffer, 0568 uint32_t BufferSize) 0569 { 0570 uint32_t size; 0571 __IO uint32_t *psramaddress = pAddress; 0572 uint32_t *pdestbuff = pDstBuffer; 0573 HAL_SRAM_StateTypeDef state = hsram->State; 0574 0575 /* Check the SRAM controller state */ 0576 if ((state == HAL_SRAM_STATE_READY) || (state == HAL_SRAM_STATE_PROTECTED)) 0577 { 0578 /* Process Locked */ 0579 __HAL_LOCK(hsram); 0580 0581 /* Update the SRAM controller state */ 0582 hsram->State = HAL_SRAM_STATE_BUSY; 0583 0584 /* Read data from memory */ 0585 for (size = BufferSize; size != 0U; size--) 0586 { 0587 *pdestbuff = *psramaddress; 0588 pdestbuff++; 0589 psramaddress++; 0590 } 0591 0592 /* Update the SRAM controller state */ 0593 hsram->State = state; 0594 0595 /* Process unlocked */ 0596 __HAL_UNLOCK(hsram); 0597 } 0598 else 0599 { 0600 return HAL_ERROR; 0601 } 0602 0603 return HAL_OK; 0604 } 0605 0606 /** 0607 * @brief Writes 32-bit buffer to SRAM memory. 0608 * @param hsram pointer to a SRAM_HandleTypeDef structure that contains 0609 * the configuration information for SRAM module. 0610 * @param pAddress Pointer to write start address 0611 * @param pSrcBuffer Pointer to source buffer to write 0612 * @param BufferSize Size of the buffer to write to memory 0613 * @retval HAL status 0614 */ 0615 HAL_StatusTypeDef HAL_SRAM_Write_32b(SRAM_HandleTypeDef *hsram, uint32_t *pAddress, uint32_t *pSrcBuffer, 0616 uint32_t BufferSize) 0617 { 0618 uint32_t size; 0619 __IO uint32_t *psramaddress = pAddress; 0620 uint32_t *psrcbuff = pSrcBuffer; 0621 0622 /* Check the SRAM controller state */ 0623 if (hsram->State == HAL_SRAM_STATE_READY) 0624 { 0625 /* Process Locked */ 0626 __HAL_LOCK(hsram); 0627 0628 /* Update the SRAM controller state */ 0629 hsram->State = HAL_SRAM_STATE_BUSY; 0630 0631 /* Write data to memory */ 0632 for (size = BufferSize; size != 0U; size--) 0633 { 0634 *psramaddress = *psrcbuff; 0635 psrcbuff++; 0636 psramaddress++; 0637 } 0638 0639 /* Update the SRAM controller state */ 0640 hsram->State = HAL_SRAM_STATE_READY; 0641 0642 /* Process unlocked */ 0643 __HAL_UNLOCK(hsram); 0644 } 0645 else 0646 { 0647 return HAL_ERROR; 0648 } 0649 0650 return HAL_OK; 0651 } 0652 0653 /** 0654 * @brief Reads a Words data from the SRAM memory using DMA transfer. 0655 * @param hsram pointer to a SRAM_HandleTypeDef structure that contains 0656 * the configuration information for SRAM module. 0657 * @param pAddress Pointer to read start address 0658 * @param pDstBuffer Pointer to destination buffer 0659 * @param BufferSize Size of the buffer to read from memory 0660 * @retval HAL status 0661 */ 0662 HAL_StatusTypeDef HAL_SRAM_Read_DMA(SRAM_HandleTypeDef *hsram, uint32_t *pAddress, uint32_t *pDstBuffer, 0663 uint32_t BufferSize) 0664 { 0665 HAL_StatusTypeDef status; 0666 HAL_SRAM_StateTypeDef state = hsram->State; 0667 0668 /* Check the SRAM controller state */ 0669 if ((state == HAL_SRAM_STATE_READY) || (state == HAL_SRAM_STATE_PROTECTED)) 0670 { 0671 /* Process Locked */ 0672 __HAL_LOCK(hsram); 0673 0674 /* Update the SRAM controller state */ 0675 hsram->State = HAL_SRAM_STATE_BUSY; 0676 0677 /* Configure DMA user callbacks */ 0678 if (state == HAL_SRAM_STATE_READY) 0679 { 0680 hsram->hmdma->XferCpltCallback = SRAM_DMACplt; 0681 } 0682 else 0683 { 0684 hsram->hmdma->XferCpltCallback = SRAM_DMACpltProt; 0685 } 0686 hsram->hmdma->XferErrorCallback = SRAM_DMAError; 0687 0688 /* Enable the DMA Stream */ 0689 status = HAL_MDMA_Start_IT(hsram->hmdma, (uint32_t)pAddress, (uint32_t)pDstBuffer, (uint32_t)(BufferSize * 4U), 1); 0690 0691 /* Process unlocked */ 0692 __HAL_UNLOCK(hsram); 0693 } 0694 else 0695 { 0696 status = HAL_ERROR; 0697 } 0698 0699 return status; 0700 } 0701 0702 /** 0703 * @brief Writes a Words data buffer to SRAM memory using DMA transfer. 0704 * @param hsram pointer to a SRAM_HandleTypeDef structure that contains 0705 * the configuration information for SRAM module. 0706 * @param pAddress Pointer to write start address 0707 * @param pSrcBuffer Pointer to source buffer to write 0708 * @param BufferSize Size of the buffer to write to memory 0709 * @retval HAL status 0710 */ 0711 HAL_StatusTypeDef HAL_SRAM_Write_DMA(SRAM_HandleTypeDef *hsram, uint32_t *pAddress, uint32_t *pSrcBuffer, 0712 uint32_t BufferSize) 0713 { 0714 HAL_StatusTypeDef status; 0715 0716 /* Check the SRAM controller state */ 0717 if (hsram->State == HAL_SRAM_STATE_READY) 0718 { 0719 /* Process Locked */ 0720 __HAL_LOCK(hsram); 0721 0722 /* Update the SRAM controller state */ 0723 hsram->State = HAL_SRAM_STATE_BUSY; 0724 0725 /* Configure DMA user callbacks */ 0726 hsram->hmdma->XferCpltCallback = SRAM_DMACplt; 0727 hsram->hmdma->XferErrorCallback = SRAM_DMAError; 0728 0729 /* Enable the DMA Stream */ 0730 status = HAL_MDMA_Start_IT(hsram->hmdma, (uint32_t)pSrcBuffer, (uint32_t)pAddress, (uint32_t)(BufferSize * 4U), 1); 0731 0732 /* Process unlocked */ 0733 __HAL_UNLOCK(hsram); 0734 } 0735 else 0736 { 0737 status = HAL_ERROR; 0738 } 0739 0740 return status; 0741 } 0742 0743 #if (USE_HAL_SRAM_REGISTER_CALLBACKS == 1) 0744 /** 0745 * @brief Register a User SRAM Callback 0746 * To be used to override the weak predefined callback 0747 * @param hsram : SRAM handle 0748 * @param CallbackId : ID of the callback to be registered 0749 * This parameter can be one of the following values: 0750 * @arg @ref HAL_SRAM_MSP_INIT_CB_ID SRAM MspInit callback ID 0751 * @arg @ref HAL_SRAM_MSP_DEINIT_CB_ID SRAM MspDeInit callback ID 0752 * @param pCallback : pointer to the Callback function 0753 * @retval status 0754 */ 0755 HAL_StatusTypeDef HAL_SRAM_RegisterCallback(SRAM_HandleTypeDef *hsram, HAL_SRAM_CallbackIDTypeDef CallbackId, 0756 pSRAM_CallbackTypeDef pCallback) 0757 { 0758 HAL_StatusTypeDef status = HAL_OK; 0759 HAL_SRAM_StateTypeDef state; 0760 0761 if (pCallback == NULL) 0762 { 0763 return HAL_ERROR; 0764 } 0765 0766 state = hsram->State; 0767 if ((state == HAL_SRAM_STATE_READY) || (state == HAL_SRAM_STATE_RESET) || (state == HAL_SRAM_STATE_PROTECTED)) 0768 { 0769 switch (CallbackId) 0770 { 0771 case HAL_SRAM_MSP_INIT_CB_ID : 0772 hsram->MspInitCallback = pCallback; 0773 break; 0774 case HAL_SRAM_MSP_DEINIT_CB_ID : 0775 hsram->MspDeInitCallback = pCallback; 0776 break; 0777 default : 0778 /* update return status */ 0779 status = HAL_ERROR; 0780 break; 0781 } 0782 } 0783 else 0784 { 0785 /* update return status */ 0786 status = HAL_ERROR; 0787 } 0788 0789 return status; 0790 } 0791 0792 /** 0793 * @brief Unregister a User SRAM Callback 0794 * SRAM Callback is redirected to the weak predefined callback 0795 * @param hsram : SRAM handle 0796 * @param CallbackId : ID of the callback to be unregistered 0797 * This parameter can be one of the following values: 0798 * @arg @ref HAL_SRAM_MSP_INIT_CB_ID SRAM MspInit callback ID 0799 * @arg @ref HAL_SRAM_MSP_DEINIT_CB_ID SRAM MspDeInit callback ID 0800 * @arg @ref HAL_SRAM_DMA_XFER_CPLT_CB_ID SRAM DMA Xfer Complete callback ID 0801 * @arg @ref HAL_SRAM_DMA_XFER_ERR_CB_ID SRAM DMA Xfer Error callback ID 0802 * @retval status 0803 */ 0804 HAL_StatusTypeDef HAL_SRAM_UnRegisterCallback(SRAM_HandleTypeDef *hsram, HAL_SRAM_CallbackIDTypeDef CallbackId) 0805 { 0806 HAL_StatusTypeDef status = HAL_OK; 0807 HAL_SRAM_StateTypeDef state; 0808 0809 state = hsram->State; 0810 if ((state == HAL_SRAM_STATE_READY) || (state == HAL_SRAM_STATE_PROTECTED)) 0811 { 0812 switch (CallbackId) 0813 { 0814 case HAL_SRAM_MSP_INIT_CB_ID : 0815 hsram->MspInitCallback = HAL_SRAM_MspInit; 0816 break; 0817 case HAL_SRAM_MSP_DEINIT_CB_ID : 0818 hsram->MspDeInitCallback = HAL_SRAM_MspDeInit; 0819 break; 0820 case HAL_SRAM_DMA_XFER_CPLT_CB_ID : 0821 hsram->DmaXferCpltCallback = HAL_SRAM_DMA_XferCpltCallback; 0822 break; 0823 case HAL_SRAM_DMA_XFER_ERR_CB_ID : 0824 hsram->DmaXferErrorCallback = HAL_SRAM_DMA_XferErrorCallback; 0825 break; 0826 default : 0827 /* update return status */ 0828 status = HAL_ERROR; 0829 break; 0830 } 0831 } 0832 else if (state == HAL_SRAM_STATE_RESET) 0833 { 0834 switch (CallbackId) 0835 { 0836 case HAL_SRAM_MSP_INIT_CB_ID : 0837 hsram->MspInitCallback = HAL_SRAM_MspInit; 0838 break; 0839 case HAL_SRAM_MSP_DEINIT_CB_ID : 0840 hsram->MspDeInitCallback = HAL_SRAM_MspDeInit; 0841 break; 0842 default : 0843 /* update return status */ 0844 status = HAL_ERROR; 0845 break; 0846 } 0847 } 0848 else 0849 { 0850 /* update return status */ 0851 status = HAL_ERROR; 0852 } 0853 0854 return status; 0855 } 0856 0857 /** 0858 * @brief Register a User SRAM Callback for DMA transfers 0859 * To be used to override the weak predefined callback 0860 * @param hsram : SRAM handle 0861 * @param CallbackId : ID of the callback to be registered 0862 * This parameter can be one of the following values: 0863 * @arg @ref HAL_SRAM_DMA_XFER_CPLT_CB_ID SRAM DMA Xfer Complete callback ID 0864 * @arg @ref HAL_SRAM_DMA_XFER_ERR_CB_ID SRAM DMA Xfer Error callback ID 0865 * @param pCallback : pointer to the Callback function 0866 * @retval status 0867 */ 0868 HAL_StatusTypeDef HAL_SRAM_RegisterDmaCallback(SRAM_HandleTypeDef *hsram, HAL_SRAM_CallbackIDTypeDef CallbackId, 0869 pSRAM_DmaCallbackTypeDef pCallback) 0870 { 0871 HAL_StatusTypeDef status = HAL_OK; 0872 HAL_SRAM_StateTypeDef state; 0873 0874 if (pCallback == NULL) 0875 { 0876 return HAL_ERROR; 0877 } 0878 0879 /* Process locked */ 0880 __HAL_LOCK(hsram); 0881 0882 state = hsram->State; 0883 if ((state == HAL_SRAM_STATE_READY) || (state == HAL_SRAM_STATE_PROTECTED)) 0884 { 0885 switch (CallbackId) 0886 { 0887 case HAL_SRAM_DMA_XFER_CPLT_CB_ID : 0888 hsram->DmaXferCpltCallback = pCallback; 0889 break; 0890 case HAL_SRAM_DMA_XFER_ERR_CB_ID : 0891 hsram->DmaXferErrorCallback = pCallback; 0892 break; 0893 default : 0894 /* update return status */ 0895 status = HAL_ERROR; 0896 break; 0897 } 0898 } 0899 else 0900 { 0901 /* update return status */ 0902 status = HAL_ERROR; 0903 } 0904 0905 /* Release Lock */ 0906 __HAL_UNLOCK(hsram); 0907 return status; 0908 } 0909 #endif /* USE_HAL_SRAM_REGISTER_CALLBACKS */ 0910 0911 /** 0912 * @} 0913 */ 0914 0915 /** @defgroup SRAM_Exported_Functions_Group3 Control functions 0916 * @ingroup RTEMSBSPsARMSTM32H7 0917 * @brief Control functions 0918 * 0919 @verbatim 0920 ============================================================================== 0921 ##### SRAM Control functions ##### 0922 ============================================================================== 0923 [..] 0924 This subsection provides a set of functions allowing to control dynamically 0925 the SRAM interface. 0926 0927 @endverbatim 0928 * @{ 0929 */ 0930 0931 /** 0932 * @brief Enables dynamically SRAM write operation. 0933 * @param hsram pointer to a SRAM_HandleTypeDef structure that contains 0934 * the configuration information for SRAM module. 0935 * @retval HAL status 0936 */ 0937 HAL_StatusTypeDef HAL_SRAM_WriteOperation_Enable(SRAM_HandleTypeDef *hsram) 0938 { 0939 /* Check the SRAM controller state */ 0940 if (hsram->State == HAL_SRAM_STATE_PROTECTED) 0941 { 0942 /* Process Locked */ 0943 __HAL_LOCK(hsram); 0944 0945 /* Update the SRAM controller state */ 0946 hsram->State = HAL_SRAM_STATE_BUSY; 0947 0948 /* Enable write operation */ 0949 (void)FMC_NORSRAM_WriteOperation_Enable(hsram->Instance, hsram->Init.NSBank); 0950 0951 /* Update the SRAM controller state */ 0952 hsram->State = HAL_SRAM_STATE_READY; 0953 0954 /* Process unlocked */ 0955 __HAL_UNLOCK(hsram); 0956 } 0957 else 0958 { 0959 return HAL_ERROR; 0960 } 0961 0962 return HAL_OK; 0963 } 0964 0965 /** 0966 * @brief Disables dynamically SRAM write operation. 0967 * @param hsram pointer to a SRAM_HandleTypeDef structure that contains 0968 * the configuration information for SRAM module. 0969 * @retval HAL status 0970 */ 0971 HAL_StatusTypeDef HAL_SRAM_WriteOperation_Disable(SRAM_HandleTypeDef *hsram) 0972 { 0973 /* Check the SRAM controller state */ 0974 if (hsram->State == HAL_SRAM_STATE_READY) 0975 { 0976 /* Process Locked */ 0977 __HAL_LOCK(hsram); 0978 0979 /* Update the SRAM controller state */ 0980 hsram->State = HAL_SRAM_STATE_BUSY; 0981 0982 /* Disable write operation */ 0983 (void)FMC_NORSRAM_WriteOperation_Disable(hsram->Instance, hsram->Init.NSBank); 0984 0985 /* Update the SRAM controller state */ 0986 hsram->State = HAL_SRAM_STATE_PROTECTED; 0987 0988 /* Process unlocked */ 0989 __HAL_UNLOCK(hsram); 0990 } 0991 else 0992 { 0993 return HAL_ERROR; 0994 } 0995 0996 return HAL_OK; 0997 } 0998 0999 /** 1000 * @} 1001 */ 1002 1003 /** @defgroup SRAM_Exported_Functions_Group4 Peripheral State functions 1004 * @ingroup RTEMSBSPsARMSTM32H7 1005 * @brief Peripheral State functions 1006 * 1007 @verbatim 1008 ============================================================================== 1009 ##### SRAM State functions ##### 1010 ============================================================================== 1011 [..] 1012 This subsection permits to get in run-time the status of the SRAM controller 1013 and the data flow. 1014 1015 @endverbatim 1016 * @{ 1017 */ 1018 1019 /** 1020 * @brief Returns the SRAM controller state 1021 * @param hsram pointer to a SRAM_HandleTypeDef structure that contains 1022 * the configuration information for SRAM module. 1023 * @retval HAL state 1024 */ 1025 HAL_SRAM_StateTypeDef HAL_SRAM_GetState(const SRAM_HandleTypeDef *hsram) 1026 { 1027 return hsram->State; 1028 } 1029 1030 /** 1031 * @} 1032 */ 1033 1034 /** 1035 * @} 1036 */ 1037 1038 /** @addtogroup SRAM_Private_Functions SRAM Private Functions 1039 * @{ 1040 */ 1041 1042 /** 1043 * @brief MDMA SRAM process complete callback. 1044 * @param hmdma : MDMA handle 1045 * @retval None 1046 */ 1047 static void SRAM_DMACplt(MDMA_HandleTypeDef *hmdma) 1048 { 1049 SRAM_HandleTypeDef *hsram = (SRAM_HandleTypeDef *)(hmdma->Parent); 1050 1051 /* Disable the MDMA channel */ 1052 __HAL_MDMA_DISABLE(hmdma); 1053 1054 /* Update the SRAM controller state */ 1055 hsram->State = HAL_SRAM_STATE_READY; 1056 1057 #if (USE_HAL_SRAM_REGISTER_CALLBACKS == 1) 1058 hsram->DmaXferCpltCallback(hmdma); 1059 #else 1060 HAL_SRAM_DMA_XferCpltCallback(hmdma); 1061 #endif /* USE_HAL_SRAM_REGISTER_CALLBACKS */ 1062 } 1063 1064 /** 1065 * @brief MDMA SRAM process complete callback. 1066 * @param hmdma : MDMA handle 1067 * @retval None 1068 */ 1069 static void SRAM_DMACpltProt(MDMA_HandleTypeDef *hmdma) 1070 { 1071 SRAM_HandleTypeDef *hsram = (SRAM_HandleTypeDef *)(hmdma->Parent); 1072 1073 /* Disable the MDMA channel */ 1074 __HAL_MDMA_DISABLE(hmdma); 1075 1076 /* Update the SRAM controller state */ 1077 hsram->State = HAL_SRAM_STATE_PROTECTED; 1078 1079 #if (USE_HAL_SRAM_REGISTER_CALLBACKS == 1) 1080 hsram->DmaXferCpltCallback(hmdma); 1081 #else 1082 HAL_SRAM_DMA_XferCpltCallback(hmdma); 1083 #endif /* USE_HAL_SRAM_REGISTER_CALLBACKS */ 1084 } 1085 1086 /** 1087 * @brief MDMA SRAM error callback. 1088 * @param hmdma : MDMA handle 1089 * @retval None 1090 */ 1091 static void SRAM_DMAError(MDMA_HandleTypeDef *hmdma) 1092 { 1093 SRAM_HandleTypeDef *hsram = (SRAM_HandleTypeDef *)(hmdma->Parent); 1094 1095 /* Disable the MDMA channel */ 1096 __HAL_MDMA_DISABLE(hmdma); 1097 1098 /* Update the SRAM controller state */ 1099 hsram->State = HAL_SRAM_STATE_ERROR; 1100 1101 #if (USE_HAL_SRAM_REGISTER_CALLBACKS == 1) 1102 hsram->DmaXferErrorCallback(hmdma); 1103 #else 1104 HAL_SRAM_DMA_XferErrorCallback(hmdma); 1105 #endif /* USE_HAL_SRAM_REGISTER_CALLBACKS */ 1106 } 1107 1108 /** 1109 * @} 1110 */ 1111 1112 /** 1113 * @} 1114 */ 1115 1116 #endif /* HAL_SRAM_MODULE_ENABLED */ 1117 1118 /** 1119 * @} 1120 */ 1121
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |