HAL SRAM How to Use ¶
- group SRAM_How_To_Use
-
How to use the SRAM HAL module driver ¶
The FMC SRAM main features : ¶
This SRAM HAL driver is a generic driver which contains a set of APIs used to configure the FMC SRAM sub-banks to interface with SRAM, PSRAM and CRAM memories.
The FMC SRAM peripheral supports the following read and write access modes :
SRAM memories :
Asynchronous read and asynchronous write with identical timing for both operations.
Asynchronous read and asynchronous write with distinct timing for each operation.
PSRAM/CRAM memories :
Asynchronous read and asynchronous write with identical timing for both operations.
Asynchronous read and asynchronous write with distinct timing for each operation.
Synchronous read and synchronous write.
Synchronous read and asynchronous write.
Asynchronous read and synchronous write.
The FMC SRAM peripheral supports the write protection feature.
The SRAM HAL driver can be used as follows : ¶
This module provides 5 different set of APIs that allows to :
Initialize and de-initialize the logical FMC SRAM object ( hal_sram_handle_t), retrieve the associated SRAM peripheral instance, set and get region remap :
Initialize the logical FMC SRAM object and associate it to a physical instance (sub-bank). This functionality is ensured by HAL_SRAM_Init() function.
De-initialize the logical FMC SRAM object and disable the SRAM sub-bank. This functionality is ensured by HAL_SRAM_DeInit() function.
Retrieve the SRAM instance by calling HAL_SRAM_GetInstance().
At this stage, the mapping of FMC SRAM regions can be modified, if required, allowing to access the SRAM memory at two different address mappings by calling HAL_SRAM_SetRegionRemap().
Retrieve the current memory region remap by calling HAL_SRAM_GetRegionRemap().
Configure the FMC SRAM to be ready to use and retrieve the current configuration :
Configure the FMC SRAM through three steps by following the order below :
Step 1 (FMC configuration) : is the first step to perform once the HAL SRAM driver is initialized. This functionality is ensured by HAL_SRAM_SetConfig() function.
At this stage, the SRAM is partially configured but not yet ready to use.
Step 2 (Memory configuration) : is the second step to perform once the FMC is configured. This functionality is ensured by one of these 5 functions depending on the external device access mode :
HAL_SRAM_SetConfigRdWrAsyncMemory() function to set the configuration for memories with asynchronous read and asynchronous write access mode. This API sets identical timing for both access.
HAL_SRAM_SetWrAsyncTimings() function to be called after HAL_SRAM_SetConfigRdWrAsyncMemory(), when memory with asynchronous read and asynchronous write access mode requires a different timing configuration for write transactions.
HAL_SRAM_SetConfigRdWrSyncMemory() function to set the configuration for memories with synchronous read and synchronous write access mode.
HAL_SRAM_SetConfigRdSyncWrAsyncMemory() function to set the configuration for memories with synchronous read and asynchronous write access mode.
HAL_SRAM_SetConfigRdAsyncWrSyncMemory() function to set the configuration for memories with asynchronous read and synchronous write access mode.
At this stage, the SRAM is fully configured but not yet ready to use.
Step 3 (Memory enable/disable) : is the third step to perform once the SRAM is fully configured. This functionality is ensured by HAL_SRAM_EnableMemory() and HAL_SRAM_DisableMemory() functions.
HAL_SRAM_EnableMemory() : function to enable the SRAM sub-bank and make it accessible for read and write operations.
HAL_SRAM_DisableMemory() : function to disable the SRAM sub-bank which is useful when memory configuration adjustments are needed or to save power. The HAL_SRAM_EnableMemory() must be recalled to enable the memory and make it accessible.
At this stage, the SRAM is fully configured, enabled and ready for use.
Retrieve the current configuration through the following functions :
Retrieve the FMC configuration : This functionality is ensured by HAL_SRAM_GetConfig().
Retrieve the memory configuration : This functionality is ensured by one of these 5 functions depending on the external device access mode :
HAL_SRAM_GetConfigRdWrAsyncMemory() function to get the memory configuration for memories with asynchronous read and asynchronous write access mode.
HAL_SRAM_GetWrAsyncTimings() function to get the timing configuration for write operations, when the memory with asynchronous read and asynchronous write access mode has a different timing configuration for write transactions.
HAL_SRAM_GetConfigRdWrSyncMemory() function to get the memory configuration for memories with synchronous read and synchronous write access mode.
HAL_SRAM_GetConfigRdSyncWrAsyncMemory() function to get the memory configuration for memories with synchronous read and asynchronous write access mode.
HAL_SRAM_GetConfigRdAsyncWrSyncMemory() function to get the memory configuration for memories with asynchronous read and synchronous write access mode.
To identify the base address of the FMC SRAM memory region before performing any read or write operations, the region start address can be retrieved by calling HAL_SRAM_GetRegionBaseAddress().
Manage the FMC SRAM peripheral access when it is fully configured :
Enable the FMC SRAM write protection (when disabled) to prevent any write access to the external device. This functionality is ensured by HAL_SRAM_EnableWriteProtection() function.
Disable the FMC SRAM write protection (when enabled) to allow any write access to the external device. This functionality is ensured by HAL_SRAM_DisableWriteProtection() function.
Retrieve the FMC SRAM sub-bank write protection state. This functionality is ensured by HAL_SRAM_IsEnabledWriteProtection() function.
Store and retrieve user data :
Store user data pointer into the handle. This functionality is ensured by HAL_SRAM_SetUserData() function.
Retrieve user data pointer from the handle. This functionality is ensured by HAL_SRAM_GetUserData() function.
Retrieve the HAL SRAM state and clock frequency :
Retrieve the HAL SRAM state. This functionality is ensured by HAL_SRAM_GetState() function.
Retrieve the clock frequency. This functionality is ensured by HAL_SRAM_GetClockFreq() function.
The read and write process must be managed within the application side (outside the HAL SRAM module) after fully configuring the FMC SRAM.