HAL SRAM Functions

Initialization and de-initialization functions

group SRAM_Exported_Functions_Group1

This subsection provides a set of functions allowing to initialize and de-initialize the SRAM driver :

  • The HAL_SRAM_Init() API : allows to initialize the SRAM handle and enable the peripheral clock when USE_FMC_CLK_ENABLE_MODEL is different from HAL_CLK_ENABLE_NO.

  • The HAL_SRAM_DeInit() API : allows to de-init the HAL SRAM driver for the given handle and disable the write protection and the corresponding SRAM sub-bank.

Functions

hal_status_t HAL_SRAM_Init ( hal_sram_handle_t * hsram , hal_sram_t instance )

Initialize the SRAM handle field and associate a physical instance.

Note

The FMC clock can be activated within the HAL_SRAM_Init() function by setting the USE_FMC_CLK_ENABLE_MODEL flag to HAL_CLK_ENABLE_PERIPH_ONLY in the configuration file stm32u5xx_hal_conf.h or by explicitly calling the HAL_RCC_FSMC_EnableClock() API within the application when the USE_FMC_CLK_ENABLE_MODEL is not defined or defined to flag HAL_CLK_ENABLE_NO

Parameters :
Return values :
  • HAL_INVALID_PARAM – Invalid parameter return when the SRAM handle is NULL.

  • HAL_OK – The HAL SRAM driver is initialized according to the given handle and instance.

void HAL_SRAM_DeInit ( hal_sram_handle_t * hsram )

De-init the HAL SRAM driver for the given handle and disable the write protection and the corresponding SRAM sub-bank.

Parameters :

hsram – Pointer to a hal_sram_handle_t structure.

Configuration functions

group SRAM_Exported_Functions_Group2

This subsection provides a set of functions allowing to configure the the FMC SRAM sub-banks and to retrieve the current configuration.

The full configuration is done through three steps and following the order below :

The configuration parameters are retrieved through these APIs :

Note

when separate timing configuration for read and write transactions is needed, the HAL_SRAM_SetWrAsyncTimings() API must be called after HAL_SRAM_SetConfigRdWrAsyncMemory() , to set the write timing parameters. In this case, the HAL_SRAM_SetConfigRdWrAsyncMemory() function sets timing only for read accesses.

Functions

hal_status_t HAL_SRAM_SetConfig ( hal_sram_handle_t * hsram , const hal_sram_config_t * p_config )

Set the static configuration of FMC peripheral.

Note

This API is the first API to call once the HAL SRAM driver is initialized.

Parameters :
Return values :
  • HAL_INVALID_PARAM – Invalid parameter return when the configuration structure pointer is NULL.

  • HAL_OK – The static FMC configuration is successfully configured.

void HAL_SRAM_GetConfig ( const hal_sram_handle_t * hsram , hal_sram_config_t * p_config )

Retrieve the static configuration of FMC peripheral.

Parameters :
hal_status_t HAL_SRAM_SetConfigRdWrAsyncMemory ( hal_sram_handle_t * hsram , const hal_sram_rd_wr_async_memory_config_t * p_config )

Set the memory configuration for memories with asynchronous read and asynchronous write access mode.

Note

The first use of this API must be done after calling HAL_SRAM_SetConfig() API for SRAM, PSRAM and CRAM memories then, it can be reused multi-time to adjust memory configuration when needed.

Parameters :
Return values :
  • HAL_INVALID_PARAM – Invalid parameter return when the memory configuration structure pointer is NULL.

  • HAL_OK – The memory is successfully configured.

void HAL_SRAM_GetConfigRdWrAsyncMemory ( const hal_sram_handle_t * hsram , hal_sram_rd_wr_async_memory_config_t * p_config )

Retrieve the memory configuration for memories with asynchronous read and asynchronous write access mode.

Parameters :
hal_status_t HAL_SRAM_SetWrAsyncTimings ( hal_sram_handle_t * hsram , const hal_sram_wr_async_timings_t * p_timings )

Set the timing configuration for asynchronous write transactions.

Note

When separate timing configuration for read and write transactions is needed, this API must be called after HAL_SRAM_SetConfigRdWrAsyncMemory() , to set the write timing parameters, it can be reused multi-time to adjust timings for write transactions when needed.

Parameters :
Return values :
  • HAL_INVALID_PARAM – Invalid parameter return when the timing configuration structure pointer is NULL.

  • HAL_OK – The timing is successfully configured.

void HAL_SRAM_GetWrAsyncTimings ( const hal_sram_handle_t * hsram , hal_sram_wr_async_timings_t * p_timings )

Retrieve the timing configuration for asynchronous write transactions.

Parameters :
hal_status_t HAL_SRAM_SetConfigRdWrSyncMemory ( hal_sram_handle_t * hsram , const hal_sram_rd_wr_sync_memory_config_t * p_config )

Set the memory configuration for memories with synchronous read and synchronous write access mode.

Note

The first use of this API must be done after calling HAL_SRAM_SetConfig() API for PSRAM and CRAM memories then, it can be reused multi-time to adjust memory configuration when needed.

Parameters :
Return values :
  • HAL_INVALID_PARAM – Invalid parameter return when the memory configuration structure pointer is NULL.

  • HAL_OK – The memory is successfully configured.

void HAL_SRAM_GetConfigRdWrSyncMemory ( const hal_sram_handle_t * hsram , hal_sram_rd_wr_sync_memory_config_t * p_config )

Retrieve the memory configuration for memories with synchronous read and synchronous write access mode.

Parameters :
hal_status_t HAL_SRAM_SetConfigRdSyncWrAsyncMemory ( hal_sram_handle_t * hsram , const hal_sram_rd_sync_wr_async_memory_config_t * p_config )

Set the memory configuration for memories with synchronous read and asynchronous write access mode.

Note

The first use of this API must be done after calling HAL_SRAM_SetConfig() API for PSRAM and CRAM memories then, it can be reused multi-time to adjust memory configuration when needed.

Parameters :
Return values :
  • HAL_INVALID_PARAM – Invalid parameter return when the memory configuration structure pointer is NULL.

  • HAL_OK – The memory is successfully configured.

void HAL_SRAM_GetConfigRdSyncWrAsyncMemory ( const hal_sram_handle_t * hsram , hal_sram_rd_sync_wr_async_memory_config_t * p_config )

Retrieve the memory configuration for memories with synchronous read and asynchronous write access mode.

Parameters :
hal_status_t HAL_SRAM_SetConfigRdAsyncWrSyncMemory ( hal_sram_handle_t * hsram , const hal_sram_rd_async_wr_sync_memory_config_t * p_config )

Set the memory configuration for memories with asynchronous read and synchronous write access mode.

Note

The first use of this API must be done after calling HAL_SRAM_SetConfig() API for PSRAM and CRAM memories then, it can be reused multi-time to adjust memory configuration when needed.

Parameters :
Return values :
  • HAL_INVALID_PARAM – Invalid parameter return when the memory configuration structure pointer is NULL.

  • HAL_OK – The memory is successfully configured.

void HAL_SRAM_GetConfigRdAsyncWrSyncMemory ( const hal_sram_handle_t * hsram , hal_sram_rd_async_wr_sync_memory_config_t * p_config )

Retrieve the memory configuration for memories with asynchronous read and synchronous write access mode.

Parameters :
hal_status_t HAL_SRAM_EnableMemory ( hal_sram_handle_t * hsram )

Enable the corresponding SRAM device.

Note

This API can be used once the SRAM is fully configured.

Parameters :

hsram – Pointer to a hal_sram_handle_t structure.

Return values :

HAL_OK – The SRAM is successfully enabled.

hal_status_t HAL_SRAM_DisableMemory ( hal_sram_handle_t * hsram )

Disable the corresponding SRAM device.

Note

This API must be called when a memory configuration adjustment is needed.

Parameters :

hsram – Pointer to a hal_sram_handle_t structure.

Return values :

HAL_OK – The SRAM is successfully disabled.

Control functions

group SRAM_Exported_Functions_Group3

This subsection provides a set of functions allowing to control the SRAM device :

Functions

hal_status_t HAL_SRAM_EnableWriteProtection ( hal_sram_handle_t * hsram )

Enable the corresponding SRAM device write protection.

Note

This API can be used once the SRAM is fully configured and ready to use.

Parameters :

hsram – Pointer to a hal_sram_handle_t structure.

Return values :

HAL_OK – The write protection is successfully enabled.

hal_status_t HAL_SRAM_DisableWriteProtection ( hal_sram_handle_t * hsram )

Disable the corresponding SRAM device write protection.

Note

This API can be used once the SRAM is fully configured and ready to use.

Parameters :

hsram – Pointer to a hal_sram_handle_t structure.

Return values :

HAL_OK – The write protection is successfully disabled.

hal_sram_wr_protection_status_t HAL_SRAM_IsEnabledWriteProtection ( const hal_sram_handle_t * hsram )

Get the corresponding SRAM device write protection status.

Parameters :

hsram – Pointer to a hal_sram_handle_t structure.

Return values :
  • HAL_SRAM_WR_NOT_PROTECTED – The SRAM write protection is disabled.

  • HAL_SRAM_WR_PROTECTED – The SRAM write protection is enabled.

hal_status_t HAL_SRAM_Enable ( hal_sram_handle_t * hsram )

Enable the corresponding SRAM device.

Note

This API can be used once the SRAM is fully configured and ready to use.

Parameters :

hsram – Pointer to a hal_sram_handle_t structure.

Return values :

HAL_OK – The SRAM is successfully enabled.

hal_status_t HAL_SRAM_Disable ( hal_sram_handle_t * hsram )

Disable the corresponding SRAM device.

Note

This API can be used once the SRAM is fully configured and ready to use. In case no write or read access is running, this API can be called to save power and maintain the current configuration instead of calling HAL_SRAM_DeInit() API then resuming the configuration sequence.

Parameters :

hsram – Pointer to a hal_sram_handle_t structure.

Return values :

HAL_OK – The SRAM is successfully disabled.

hal_sram_status_t HAL_SRAM_IsEnabled ( const hal_sram_handle_t * hsram )

Get the corresponding SRAM device status.

Parameters :

hsram – Pointer to a hal_sram_handle_t structure.

Return values :
  • HAL_SRAM_DISABLED – The SRAM is disabled.

  • HAL_SRAM_ENABLED – The SRAM is enabled.

User data functions

group SRAM_Exported_Functions_Group4

This subsection provides a set of functions allowing to set and retrieve user specific data :

Functions

void HAL_SRAM_SetUserData ( hal_sram_handle_t * hsram , const void * p_user_data )

Store user data pointer into the handle.

Parameters :
  • hsram – Pointer to a hal_sram_handle_t structure.

  • p_user_data – Pointer to the user data.

const void * HAL_SRAM_GetUserData ( const hal_sram_handle_t * hsram )

Retrieve user data pointer from the handle.

Parameters :

hsram – Pointer to a hal_sram_handle_t structure.

Return values :

Pointer – to the user data.

Peripheral state functions, Clock Frequency

group SRAM_Exported_Functions_Group5

This subsection provides a set of functions allowing to retrieve the SRAM global state and the clock frequency :

Functions

uint32_t HAL_SRAM_GetClockFreq ( const hal_sram_handle_t * hsram )

Get the clock frequency.

Parameters :

hsram – Pointer to a hal_sram_handle_t structure.

Return values :

uint32_t – Frequency in Hz.

hal_sram_state_t HAL_SRAM_GetState ( const hal_sram_handle_t * hsram )

Get the current global state.

Parameters :

hsram – Pointer to a hal_sram_handle_t structure.

Return values :
  • HAL_SRAM_STATE_RESET – The SRAM not yet initialized.

  • HAL_SRAM_STATE_INIT – The SRAM initialized but not yet configured.

  • HAL_SRAM_STATE_CONFIGURED – The SRAM initialized, FMC peripheral configured but not yet ready to use.

  • HAL_SRAM_STATE_MEMORY_CONFIGURED – The SRAM initialized, FMC, memory configured but not yet ready to use.

  • HAL_SRAM_STATE_IDLE – The SRAM initialized, FMC, memory configured, SRAM is enabled and ready to use.