HAL CRS Functions

Initialization and DeInitialization functions

group CRS_Exported_Functions_Group1

This section provides a set of functions allowing to initialize and deinitialize the CRS peripheral:

Functions

hal_status_t HAL_CRS_Init ( hal_crs_handle_t * hcrs , hal_crs_t instance )

Initialize the CRS according to the associated handle.

Parameters :
  • hcrs – Pointer to a hal_crs_handle_t structure that contains the handle information for the specified CRS.

  • instance – CRS instance.

Return values :
  • HAL_INVALID_PARAM – When the handle is NULL.

  • HAL_OK – HAL CRS driver correctly initialized for the given CRS instance.

void HAL_CRS_DeInit ( hal_crs_handle_t * hcrs )

DeInitialize the CRS.

Parameters :

hcrs – Pointer to a hal_crs_handle_t structure that contains the handle information for the specified CRS instance.

Configuration functions

group CRS_Exported_Functions_Group2

This section provides a set of functions allowing to configure the CRS driver:

Functions

hal_status_t HAL_CRS_SetConfig ( hal_crs_handle_t * hcrs , const hal_crs_config_t * p_config )

Configure the CRS driver.

Note

This function is optional, the user can start the driver with the default configuration.

Parameters :
Return values :
  • HAL_OK – CRS instance has been correctly configured.

  • HAL_INVALID_PARAM – When the p_config pointer is NULL.

void HAL_CRS_GetConfig ( const hal_crs_handle_t * hcrs , hal_crs_config_t * p_config )

Get the configuration.

Parameters :
void HAL_CRS_ResetConfig ( hal_crs_handle_t * hcrs )

Reset the following fields to their default values:

  • The divider is set to not divided.

  • The source is set to signal source 3.

  • The polarity is set to rising edge.

  • The reload is set to 0xBB7FU.

  • The felim is set to 0x22U.

  • The trimming is set to 0x40U.

  • The auto trimming is disabled.

Parameters :

hcrs – Pointer to a hal_crs_handle_t structure that contains the handle information for the specified CRS instance.

hal_status_t HAL_CRS_SetTrimming ( hal_crs_handle_t * hcrs , uint32_t trimming )

Set the trimming value.

Parameters :
  • hcrs – Pointer to a hal_crs_handle_t structure that contains the handle information for the specified CRS instance.

  • trimming – Trimming value.

Return values :
  • HAL_OK – CRS instance has been correctly configured.

  • HAL_ERROR – Auto trimming enabled, configuration not possible.

uint32_t HAL_CRS_GetTrimming ( const hal_crs_handle_t * hcrs )

Get the trimming value.

Parameters :

hcrs – Pointer to a hal_crs_handle_t structure that contains the handle information for the specified CRS instance.

Return values :

uint32_t – Trimming value.

void HAL_CRS_GetFrequencyErrorInfo ( const hal_crs_handle_t * hcrs , hal_crs_frequency_error_info_t * p_frequency_error_info )

Get frequency error information (frequency error capture and direction).

Parameters :

Control functions

group CRS_Exported_Functions_Group3

This section provides a set of functions allowing to start/stop the CRS driver and control the auto trimming:

Functions

hal_status_t HAL_CRS_EnableAutoTrimming ( hal_crs_handle_t * hcrs )

Enable the auto trimming.

Parameters :

hcrs – Pointer to a hal_crs_handle_t structure that contains the handle information for the specified CRS instance.

Return values :

HAL_OK – CRS auto trimming has been correctly activated.

hal_status_t HAL_CRS_DisableAutoTrimming ( hal_crs_handle_t * hcrs )

Disable the auto trimming.

Parameters :

hcrs – Pointer to a hal_crs_handle_t structure that contains the handle information for the specified CRS instance.

Return values :

HAL_OK – CRS auto trimming has been correctly de-activated.

hal_crs_auto_trimming_status_t HAL_CRS_IsEnabledAutoTrimming ( const hal_crs_handle_t * hcrs )

Get the auto trimming status.

Parameters :

hcrs – Pointer to a hal_crs_handle_t structure that contains the handle information for the specified CRS instance.

Return values :
  • HAL_CRS_AUTO_TRIMMING_DISABLED

  • HAL_CRS_AUTO_TRIMMING_ENABLED

hal_status_t HAL_CRS_StartSync ( hal_crs_handle_t * hcrs )

Start the CRS in Polling mode.

Note

This function enables the frequency error counter.

Parameters :

hcrs – Pointer to a hal_crs_handle_t structure that contains the handle information for the specified CRS instance.

Return values :

HAL_OK – Operation completed successfully.

hal_status_t HAL_CRS_StopSync ( hal_crs_handle_t * hcrs )

Stop the CRS in Polling mode.

Note

This function disables the frequency error counter.

Parameters :

hcrs – Pointer to a hal_crs_handle_t structure that contains the handle information for the specified CRS instance.

Return values :

HAL_OK – Operation completed successfully.

hal_status_t HAL_CRS_StartSync_IT ( hal_crs_handle_t * hcrs )

Start the CRS in Interrupt mode.

Note

This function enables the interrupt sources and the frequency error counter.

Parameters :

hcrs – Pointer to a hal_crs_handle_t structure that contains the handle information for the specified CRS instance.

Return values :

HAL_OK – Operation completed successfully.

hal_status_t HAL_CRS_StopSync_IT ( hal_crs_handle_t * hcrs )

Stop the CRS in Interrupt mode.

Note

This function disables the interrupt sources and the frequency error counter.

Parameters :

hcrs – Pointer to a hal_crs_handle_t structure that contains the handle information for the specified CRS instance.

Return values :

HAL_OK – Operation completed successfully.

Process functions

group CRS_Exported_Functions_Group4

This section provides a set of process functions:

Functions

hal_status_t HAL_CRS_GenerateSoftwareSync ( hal_crs_handle_t * hcrs )

Generate the software synchronization event.

Parameters :

hcrs – Pointer to a hal_crs_handle_t structure that contains the handle information for the specified CRS instance.

Return values :

HAL_OK – Operation completed successfully.

hal_status_t HAL_CRS_PollForSync ( hal_crs_handle_t * hcrs , uint32_t timeout_ms )

Retrieve the status of synchronization.

Note

timeout_ms is based on the maximum time to receive a SYNC event based on synchronization frequency.

Warning

If timeout_ms set to HAL_MAX_DELAY, HAL_TIMEOUT is never returned.

Parameters :
  • hcrs – Pointer to a hal_crs_handle_t structure that contains the handle information for the specified CRS instance.

  • timeout_ms – Duration of the timeout in milliseconds.

Return values :
  • HAL_OK – Synchronization event OK (SYNCOK).

  • HAL_ERROR – Synchronization error or warning (SYNCERR, TRIMOVF, SYNCMISS or SYNCWARN).

  • HAL_TIMEOUT – Timeout elapsed.

IRQHandler and Callbacks functions

group CRS_Exported_Functions_Group5

This section provides functions allowing to:

Functions

void HAL_CRS_IRQHandler ( hal_crs_handle_t * hcrs )

Handle the Clock Recovery System interrupt request.

Note

This function must be called from CRS_IRQHandler().

Parameters :

hcrs – Pointer to a hal_crs_handle_t structure that contains the handle information for the specified CRS instance.

void HAL_CRS_SyncOkCallback ( hal_crs_handle_t * hcrs )

Clock Recovery System SYNCOK interrupt callback.

Note

This function must not be modified in this file, but must preferably be implemented in the user file.

Parameters :

hcrs – Pointer to a hal_crs_handle_t structure that contains the handle information for the specified CRS instance.

void HAL_CRS_SyncWarnCallback ( hal_crs_handle_t * hcrs )

Clock Recovery System SYNCWARN interrupt callback.

Note

This function must not be modified in this file, but must preferably be implemented in the user file.

Parameters :

hcrs – Pointer to a hal_crs_handle_t structure that contains the handle information for the specified CRS instance.

void HAL_CRS_ExpectedSyncCallback ( hal_crs_handle_t * hcrs )

Clock Recovery System Expected SYNC interrupt callback.

Note

This function must not be modified in this file, but must preferably be implemented in the user file.

Parameters :

hcrs – Pointer to a hal_crs_handle_t structure that contains the handle information for the specified CRS instance.

void HAL_CRS_ErrorCallback ( hal_crs_handle_t * hcrs )

Clock Recovery System Error interrupt callback.

Note

This function must not be modified in this file, but must preferably be implemented in the user file.

Parameters :

hcrs – Pointer to a hal_crs_handle_t structure that contains the handle information for the specified CRS instance.

hal_status_t HAL_CRS_RegisterSyncOkCallback ( hal_crs_handle_t * hcrs , hal_crs_cb_t p_callback )

Register a User CRS callback for synchronization ok.

Parameters :
  • hcrs – Pointer to the CRS handle.

  • p_callback – Pointer to the synchronization ok callback function.

Return values :
  • HAL_OK – Register completed successfully.

  • HAL_INVALID_PARAM – p_callback pointer is NULL.

hal_status_t HAL_CRS_RegisterSyncWarnCallback ( hal_crs_handle_t * hcrs , hal_crs_cb_t p_callback )

Register a User CRS callback for synchronization warning.

Parameters :
  • hcrs – Pointer to the CRS handle.

  • p_callback – Pointer to the synchronization warning callback function.

Return values :
  • HAL_OK – Register completed successfully.

  • HAL_INVALID_PARAM – p_callback pointer is NULL.

hal_status_t HAL_CRS_RegisterExpectedSyncCallback ( hal_crs_handle_t * hcrs , hal_crs_cb_t p_callback )

Register a User CRS callback for expected synchronization.

Parameters :
  • hcrs – Pointer to the CRS handle.

  • p_callback – Pointer to the expected synchronization callback function.

Return values :
  • HAL_OK – Register completed successfully.

  • HAL_INVALID_PARAM – p_callback pointer is NULL.

hal_status_t HAL_CRS_RegisterErrorCallback ( hal_crs_handle_t * hcrs , hal_crs_cb_t p_callback )

Register a User CRS callback for error.

Parameters :
  • hcrs – Pointer to the CRS handle.

  • p_callback – Pointer to the error callback function.

Return values :
  • HAL_OK – Register completed successfully.

  • HAL_INVALID_PARAM – p_callback pointer is NULL.

State functions

group CRS_Exported_Functions_Group6

This section permits to get in runtime the state of the peripheral CRS with HAL_CRS_GetState() .

Functions

hal_crs_state_t HAL_CRS_GetState ( const hal_crs_handle_t * hcrs )

Get the CRS state.

Parameters :

hcrs – Pointer to the CRS handle.

Return values :

hal_crs_state_t – HAL CRS state.

Error functions

group CRS_Exported_Functions_Group7

This section permits to get in runtime the last error codes of the peripheral CRS with HAL_CRS_GetLastErrorCodes() .

Functions

uint32_t HAL_CRS_GetLastErrorCodes ( const hal_crs_handle_t * hcrs )

Get the CRS last error codes.

Parameters :

hcrs – Pointer to the CRS handle.

Return values :

uint32_t – This return value can be a combination of the following values:

Set/Get user data functions

group CRS_Exported_Functions_Group8

This section provides functions allowing to Set and Get user data:

Functions

void HAL_CRS_SetUserData ( hal_crs_handle_t * hcrs , const void * p_user_data )

Store the user data into the CRS handle.

Parameters :
  • hcrs – Pointer to CRS handle.

  • p_user_data – Pointer to the user data.

const void * HAL_CRS_GetUserData ( const hal_crs_handle_t * hcrs )

Retrieve the user data from the CRS handle.

Parameters :

hcrs – Pointer to CRS handle.

Return values :

Pointer – to the user data.