HAL CORDIC functions

Initialization and de-initialization functions

group CORDIC_Exported_Functions_Group1

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

Functions

hal_status_t HAL_CORDIC_Init ( hal_cordic_handle_t * hcordic , hal_cordic_t instance )

Initialize the HAL CORDIC handle and associate it to an instance of the CORDIC peripheral.

Parameters :
Return values :
  • HAL_OK – CORDIC instance has been correctly initialized.

  • HAL_INVALID_PARAM – Pointer to HAL CORDIC handle is NULL.

void HAL_CORDIC_DeInit ( hal_cordic_handle_t * hcordic )

DeInitialize the CORDIC peripheral.

Parameters :

hcordic – Pointer to a hal_cordic_handle_t.

Configuration functions

group CORDIC_Exported_Functions_Group2

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

Functions

hal_status_t HAL_CORDIC_SetConfig ( hal_cordic_handle_t * hcordic , const hal_cordic_config_t * p_config )

Configure the CORDIC driver.

Parameters :
Return values :
  • HAL_OK – CORDIC block has been correctly configured.

  • HAL_INVALID_PARAM – When the p_config pointer is NULL.

void HAL_CORDIC_GetConfig ( const hal_cordic_handle_t * hcordic , hal_cordic_config_t * p_config )

Retrieve the CORDIC global configuration.

Parameters :
hal_status_t HAL_CORDIC_SetFunction ( hal_cordic_handle_t * hcordic , hal_cordic_function_t function )

Set the CORDIC function.

Parameters :
Return values :

HAL_OK – CORDIC function was successfully set.

hal_cordic_function_t HAL_CORDIC_GetFunction ( const hal_cordic_handle_t * hcordic )

Retrieve the current CORDIC function.

Parameters :

hcordic – Pointer to a hal_cordic_handle_t structure.

Return values :

hal_cordic_function_t – CORDIC function.

hal_status_t HAL_CORDIC_SetPrecision ( const hal_cordic_handle_t * hcordic , const hal_cordic_precision_t precision )

Set the CORDIC precision in multiple of 4 cycles number.

Parameters :
Return values :
  • HAL_OK – CORDIC precision was successfully configured.

  • HAL_INVALID_PARAM – The precision does not match the function requirements.

hal_cordic_precision_t HAL_CORDIC_GetPrecision ( const hal_cordic_handle_t * hcordic )

Retrieve the CORDIC precision.

Parameters :

hcordic – Pointer to a hal_cordic_handle_t.

Return values :

hal_cordic_precision_t – CORDIC precision.

hal_status_t HAL_CORDIC_SetScalingFactor ( const hal_cordic_handle_t * hcordic , const hal_cordic_scaling_factor_t scaling_factor )

Set the CORDIC scaling factor.

Parameters :
Return values :
  • HAL_OK – CORDIC scaling factor was successfully configured.

  • HAL_INVALID_PARAM – The scaling_factor does not match the function requirements.

hal_cordic_scaling_factor_t HAL_CORDIC_GetScalingFactor ( const hal_cordic_handle_t * hcordic )

Retrieve the CORDIC scaling factor.

Parameters :

hcordic – Pointer to a hal_cordic_handle_t.

Return values :

hal_cordic_scaling_factor_t – CORDIC scaling factor.

hal_status_t HAL_CORDIC_SetInputWidth ( const hal_cordic_handle_t * hcordic , const hal_cordic_in_width_t input_width )

Set the CORDIC argument width.

Parameters :
Return values :

HAL_OK – Data arguments width was successfully configured.

hal_cordic_in_width_t HAL_CORDIC_GetInputWidth ( const hal_cordic_handle_t * hcordic )

Retrieve the CORDIC argument width.

Parameters :

hcordic – Pointer to a hal_cordic_handle_t.

Return values :

hal_cordic_in_width_t – CORDIC argument width.

hal_status_t HAL_CORDIC_SetOutputWidth ( const hal_cordic_handle_t * hcordic , const hal_cordic_out_width_t output_width )

Set the CORDIC result width.

Parameters :
Return values :

HAL_OK – Results width was successfully configured.

hal_cordic_out_width_t HAL_CORDIC_GetOutputWidth ( const hal_cordic_handle_t * hcordic )

Retrieve the CORDIC result width.

Parameters :

hcordic – Pointer to a hal_cordic_handle_t.

Return values :

hal_cordic_out_width_t – CORDIC results width.

hal_status_t HAL_CORDIC_SetNumberArguments ( const hal_cordic_handle_t * hcordic , const hal_cordic_nb_arg_t nb_argument )

Set the CORDIC number of arguments expected.

Parameters :
Return values :

HAL_OK – Number of arguments was successfully configured.

hal_cordic_nb_arg_t HAL_CORDIC_GetNumberArguments ( const hal_cordic_handle_t * hcordic )

Retrieve the CORDIC number of arguments.

Parameters :

hcordic – Pointer to a hal_cordic_handle_t.

Return values :

hal_cordic_nb_arg_t – CORDIC number of arguments.

hal_status_t HAL_CORDIC_SetNumberResults ( const hal_cordic_handle_t * hcordic , const hal_cordic_nb_result_t nb_result )

Set the CORDIC number of results expected.

Parameters :
Return values :

HAL_OK – Number of results was successfully configured.

hal_cordic_nb_result_t HAL_CORDIC_GetNumberResults ( const hal_cordic_handle_t * hcordic )

Retrieve the CORDIC number of results.

Parameters :

hcordic – Pointer to a hal_cordic_handle_t.

Return values :

HAL – status.

volatile uint32_t * HAL_CORDIC_GetWriteAddress ( const hal_cordic_handle_t * hcordic )

Get the input arguments address. Arguments can be directly driven by a timer or other peripheral such as an ADC.

Parameters :

hcordic – Pointer to a hal_cordic_handle_t.

Return values :

input – argument address.

volatile uint32_t * HAL_CORDIC_GetReadAddress ( const hal_cordic_handle_t * hcordic )

Get the output results address. results can be directly driven by a timer or other peripheral such as a DAC.

Parameters :

hcordic – Pointer to a hal_cordic_handle_t.

Return values :

the – output results address.

hal_status_t HAL_CORDIC_SetWriteDMA ( hal_cordic_handle_t * hcordic , hal_dma_handle_t * hdma_wr )

Set DMA channel for writing arguments.

Parameters :
Return values :
  • HAL_OK – The channel has been correctly set.

  • HAL_INVALID_PARAM – hdma_wr is NULL.

hal_status_t HAL_CORDIC_SetReadDMA ( hal_cordic_handle_t * hcordic , hal_dma_handle_t * hdma_rd )

Set DMA channel for reading results.

Parameters :
Return values :
  • HAL_OK – The channel has been correctly set.

  • HAL_INVALID_PARAM – hdma_rd is NULL.

Process functions

group CORDIC_Exported_Functions_Group4

This section provides a set of functions for the calculation modes of the CORDIC.

There are four calculation modes:

  • Blocking mode: Communication is performed in polling mode.

  • Non-blocking mode functions with interrupts are:

  • Non-blocking mode functions with DMA are:

    • HAL_CORDIC_Write_DMA() : Write input arguments in DMA mode (the corresponding read stream is handled by another peripheral).

    • HAL_CORDIC_Write_DMA_opt() : Write input arguments in DMA mode and optional interrupt (the corresponding read stream is handled by another peripheral).

    • HAL_CORDIC_Read_DMA() : Read output results in DMA mode (the corresponding write stream is handled by another peripheral).

    • HAL_CORDIC_Read_DMA_opt() : Read output results in DMA mode and optional interrupt (the corresponding read stream is handled by another peripheral).

    • HAL_CORDIC_Calculate_DMA() : Perform a write and read operations in DMA mode.

Note that some functions require one or two arguments for the selected calculation function. The list hereafter summarizes the number of arguments needed by each function of the CORDIC IP driver.

  • Cosine 2 arguments

  • Sine 2 arguments

  • Phase 2 arguments

  • Modulus 2 arguments

  • Arctangent 1 argument

  • Hyperbolic cosine 1 argument

  • Hyperbolic sine 1 argument

  • Hyperbolic arctangent 1 argument

  • natural logarithm 1 argument

  • Square root 1 argument

Keep in mind that invoking a function that requires two arguments and setting only one argument can generate erroneous results. To prevent that case, set the unused argument to the default value +1 (0x7FFFFFFF).

Remember that some functions require a scaling factor to produce correct results. Refer to the reference manual to configure the required parameters correctly for the selected functions.

Functions

hal_status_t HAL_CORDIC_Calculate ( hal_cordic_handle_t * hcordic , const hal_cordic_buffer_desc_t * p_in_buff , const hal_cordic_buffer_desc_t * p_out_buff , uint32_t timeout_ms )

Perform CORDIC processing in polling mode, according to the existing CORDIC configuration.

Parameters :
  • hcordic – Pointer to a hal_cordic_handle_t.

  • p_in_buff – Pointer to buffer descriptor containing pointer to the input data buffer and the buffer size.

  • p_out_buff – Pointer to buffer descriptor containing pointer to the output data buffer and the buffer size.

  • timeout_ms – Specify timeout value in milliseconds.

Return values :
  • HAL_OK – Operation completed successfully.

  • HAL_TIMEOUT – Operation cancelled due to timeout.

  • HAL_BUSY – Concurrent process ongoing.

  • HAL_INVALID_PARAM – Invalid parameter.

hal_status_t HAL_CORDIC_CalculateZeroOverhead ( hal_cordic_handle_t * hcordic , const hal_cordic_buffer_desc_t * p_in_buff , const hal_cordic_buffer_desc_t * p_out_buff , uint32_t timeout_ms )

Perform CORDIC processing in Zero-Overhead mode (output data being read. soon as input data are written), according to the existing CORDIC configuration.

Parameters :
  • hcordic – Pointer to a hal_cordic_handle_t.

  • p_in_buff – Pointer to buffer descriptor containing pointer to the input data buffer and the buffer size.

  • p_out_buff – Pointer to buffer descriptor containing pointer to the output data buffer and the buffer size.

  • timeout_ms – Specify timeout value in milliseconds.

Return values :
  • HAL_OK – Operation completed successfully.

  • HAL_TIMEOUT – Operation cancelled due to timeout.

  • HAL_BUSY – Concurrent process ongoing.

hal_status_t HAL_CORDIC_Calculate_IT ( hal_cordic_handle_t * hcordic , const hal_cordic_buffer_desc_t * p_in_buff , const hal_cordic_buffer_desc_t * p_out_buff )

Perform CORDIC processing in interrupt mode, according to the existing CORDIC configuration.

Parameters :
  • hcordic – Pointer to a hal_cordic_handle_t.

  • p_in_buff – Pointer to buffer descriptor containing pointer to the input data buffer and the buffer size.

  • p_out_buff – Pointer to buffer descriptor containing pointer to the output data buffer and the buffer size.

Return values :
  • HAL_OK – Operation completed successfully.

  • HAL_BUSY – Concurrent process ongoing.

hal_status_t HAL_CORDIC_Write_DMA ( hal_cordic_handle_t * hcordic , const hal_cordic_buffer_desc_t * p_in_buff )

Write input arguments in DMA mode.

Parameters :
  • hcordic – Pointer to a hal_cordic_handle_t

  • p_in_buff – Pointer to buffer descriptor containing pointer to the input data buffer and the buffer size.

Return values :
  • HAL_OK – Operation completed successfully.

  • HAL_ERROR – Operation completed with error.

  • HAL_BUSY – Concurrent process ongoing.

  • HAL_INVALID_PARAM – Invalid parameter.

hal_status_t HAL_CORDIC_Write_DMA_opt ( hal_cordic_handle_t * hcordic , const hal_cordic_buffer_desc_t * p_in_buff , uint32_t opt_it )

Write input arguments in DMA mode with option. Global state must be IDLE.

Parameters :
Return values :
  • HAL_OK – Operation completed successfully.

  • HAL_ERROR – Operation completed with error.

  • HAL_BUSY – Concurrent process ongoing.

  • HAL_INVALID_PARAM – Invalid parameter.

hal_status_t HAL_CORDIC_Read_DMA ( hal_cordic_handle_t * hcordic , hal_cordic_buffer_desc_t * p_out_buff )

Read output results in DMA mode.

Parameters :
  • hcordic – Pointer to a hal_cordic_handle_t.

  • p_out_buff – Pointer to buffer descriptor containing pointer to the output data buffer and the buffer size.

Return values :
  • HAL_OK – Operation completed successfully.

  • HAL_ERROR – Operation completed with error.

  • HAL_BUSY – Concurrent process ongoing.

  • HAL_INVALID_PARAM – Invalid parameter.

hal_status_t HAL_CORDIC_Read_DMA_opt ( hal_cordic_handle_t * hcordic , hal_cordic_buffer_desc_t * p_out_buff , uint32_t opt_it )

Read output result in DMA mode. Global state must be IDLE.

Parameters :
Return values :
  • HAL_OK – Operation completed successfully.

  • HAL_ERROR – Operation completed with error.

  • HAL_BUSY – Concurrent process ongoing.

  • HAL_INVALID_PARAM – Invalid parameter.

hal_status_t HAL_CORDIC_Calculate_DMA ( hal_cordic_handle_t * hcordic , const hal_cordic_buffer_desc_t * p_in_buff , hal_cordic_buffer_desc_t * p_out_buff )

Perform input data and output data of CORDIC processing in DMA mode according to the existing CORDIC configuration.

Note

p_in_buff and output_buffer buffers must be 32-bit aligned to ensure a correct DMA transfer to and from the Peripheral. The function requires to configure the 2 DMA channels (Input and Output).

Parameters :
  • hcordic – Pointer to a hal_cordic_handle_t.

  • p_in_buff – Pointer to buffer descriptor containing pointer to the input data buffer and the buffer size.

  • p_out_buff – Pointer to buffer descriptor containing pointer to the output data buffer and the buffer size.

Return values :
  • HAL_OK – Operation completed successfully.

  • HAL_INVALID_PARAM – Invalid parameter.

  • HAL_ERROR – Operation error.

  • HAL_BUSY – Concurrent process ongoing.

hal_status_t HAL_CORDIC_Abort ( hal_cordic_handle_t * hcordic )

Abort the ongoing transfer (blocking process).

Parameters :

hcordic – Pointer to a hal_cordic_handle_t.

Return values :

HAL_OK – Operation completed successfully.

hal_status_t HAL_CORDIC_Abort_IT ( hal_cordic_handle_t * hcordic )

Abort a CORDIC process (non-blocking process).

Parameters :

hcordic – Pointer to a hal_cordic_handle_t.

Return values :

HAL_OK – Operation completed successfully.

IRQHandler and Callbacks functions

group CORDIC_Exported_Functions_Group5

This section provides functions to:

There are two ways to use callbacks: override weak callback functions or register user callback functions. They are used to indicate:

Depending on the process function you use, different callbacks might be triggered:

Process API

\

Callbacks

HAL_CORDIC_Calculate_IT

HAL_CORDIC_CalculateCpltCallback

x

HAL_CORDIC_ErrorCallback

x

Process API

\

Callbacks

HAL_CORDIC_Calculate_DMA

HAL_CORDIC_Write_DMA

HAL_CORDIC_Read_DMA

HAL_CORDIC_CalculateCpltCallback

x

x

HAL_CORDIC_WriteCpltCallback

x

x

HAL_CORDIC_ErrorCallback

x

x

x

Process API

\

Callbacks

HAL_CORDIC_Write_DMA_opt

HAL_CORDIC_Read_DMA_opt

HAL_CORDIC_CalculateCpltCallback

x

HAL_CORDIC_WriteCpltCallback

x

HAL_CORDIC_ReadHalfCpltCallback*

x

HAL_CORDIC_WriteHalfCpltCallback*

x

HAL_CORDIC_ErrorCallback

x

x

Process API

\

Callbacks

HAL_CORDIC_Abort_IT

HAL_CORDIC_AbortCpltCallback

x

Note

with HAL_CORDIC_OPT_DMA_IT_HALF_CPLT argument value for interrupts parameter

Functions

void HAL_CORDIC_IRQHandler ( hal_cordic_handle_t * hcordic )

Handle CORDIC interrupt request.

Parameters :

hcordic – Pointer to a hal_cordic_handle_t.

void HAL_CORDIC_ErrorCallback ( hal_cordic_handle_t * hcordic )

CORDIC error callback.

Warning

This weak function must not be modified. When the callback is needed, it is overridden in the user file.

Parameters :

hcordic – Pointer to a hal_cordic_handle_t.

void HAL_CORDIC_CalculateCpltCallback ( hal_cordic_handle_t * hcordic )

CORDIC calculate complete callback.

Warning

This weak function must not be modified. When the callback is needed, it is overridden in the user file.

Parameters :

hcordic – Pointer to a hal_cordic_handle_t.

void HAL_CORDIC_WriteHalfCpltCallback ( hal_cordic_handle_t * hcordic )

CORDIC Write data half complete callback.

Warning

This weak function must not be modified. When the callback is needed, it is overridden in the user file.

Parameters :

hcordic – Pointer to a hal_cordic_handle_t.

void HAL_CORDIC_ReadHalfCpltCallback ( hal_cordic_handle_t * hcordic )

CORDIC Read data half complete callback.

Warning

This weak function must not be modified. When the callback is needed, it is overridden in the user file.

Parameters :

hcordic – Pointer to a hal_cordic_handle_t.

void HAL_CORDIC_WriteCpltCallback ( hal_cordic_handle_t * hcordic )

CORDIC Write data complete callback.

Warning

This weak function must not be modified. When the callback is needed, it is overridden in the user file.

Parameters :

hcordic – Pointer to a hal_cordic_handle_t.

void HAL_CORDIC_AbortCpltCallback ( hal_cordic_handle_t * hcordic )

Abort completed callback.

Warning

This weak function must not be modified. When the callback is needed, it is overridden in the user file.

Parameters :

hcordic – Pointer to a hal_cordic_handle_t.

hal_status_t HAL_CORDIC_RegisterErrorCallback ( hal_cordic_handle_t * hcordic , hal_cordic_cb_t p_callback )

Register a User CORDIC callback for Error.

Parameters :
  • hcordic – Pointer to a hal_cordic_handle_t.

  • p_callback – Pointer to the callback function.

Return values :
  • HAL_OK – Register completed successfully.

  • HAL_INVALID_PARAM – p_callback pointer is NULL.

hal_status_t HAL_CORDIC_RegisterAbortCpltCallback ( hal_cordic_handle_t * hcordic , hal_cordic_cb_t p_callback )

Register a User CORDIC callback for DMA Abort complete.

Parameters :
  • hcordic – Pointer to a hal_cordic_handle_t.

  • p_callback – Pointer to the callback function.

Return values :
  • HAL_OK – Register completed successfully.

  • HAL_INVALID_PARAM – p_callback pointer is NULL.

hal_status_t HAL_CORDIC_RegisterWriteCpltCallback ( hal_cordic_handle_t * hcordic , hal_cordic_cb_t p_callback )

Register a User CORDIC callback for write data complete.

Parameters :
  • hcordic – Pointer to a hal_cordic_handle_t.

  • p_callback – Pointer to the callback function.

Return values :
  • HAL_OK – Register completed successfully.

  • HAL_INVALID_PARAM – p_callback pointer is NULL.

hal_status_t HAL_CORDIC_RegisterWriteHalfCpltCallback ( hal_cordic_handle_t * hcordic , hal_cordic_cb_t p_callback )

Register the CORDIC Write Half complete callback.

Parameters :
  • hcordic – Pointer to a hal_cordic_handle_t.

  • p_callback – Pointer to the callback function.

Return values :

HAL_OK – Register completed successfully.

hal_status_t HAL_CORDIC_RegisterReadHalfCpltCallback ( hal_cordic_handle_t * hcordic , hal_cordic_cb_t p_callback )

Register the CORDIC Read Half complete callback.

Parameters :
  • hcordic – Pointer to a hal_cordic_handle_t.

  • p_callback – Pointer to the callback function.

Return values :

HAL_OK – Register completed successfully.

hal_status_t HAL_CORDIC_RegisterCalculateCpltCallback ( hal_cordic_handle_t * hcordic , hal_cordic_cb_t p_callback )

Register a User CORDIC callback for calculation complete.

Parameters :
  • hcordic – Pointer to a hal_cordic_handle_t.

  • p_callback – Pointer to the callback function.

Return values :
  • HAL_OK – Register completed successfully.

  • HAL_INVALID_PARAM – p_callback pointer is NULL.

Error function

group CORDIC_Exported_Functions_Group6

This section permits retrieving at runtime the last error codes of the CORDIC peripheral with HAL_CORDIC_GetLastErrorCodes().

Functions

uint32_t HAL_CORDIC_GetLastErrorCodes ( const hal_cordic_handle_t * hcordic )

Return the CORDIC peripheral error.

Parameters :

hcordic – Pointer to a hal_cordic_handle_t.

Return values :

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

State function

group CORDIC_Exported_Functions_Group7

This section permits retrieving at runtime the state of the CORDIC peripheral using HAL_CORDIC_GetState().

Functions

hal_cordic_state_t HAL_CORDIC_GetState ( const hal_cordic_handle_t * hcordic )

Return the CORDIC handle state.

Parameters :

hcordic – Pointer to a hal_cordic_handle_t.

Return values :

hal_cordic_state_t – CORDIC state.

User Data and retrieve functions

group CORDIC_Exported_Functions_Group8

This section provides functions to set user-specific data to a CORDIC instance:

Functions

void HAL_CORDIC_SetUserData ( hal_cordic_handle_t * hcordic , const void * p_user_data )

Store user data pointer into the handle.

Parameters :
const void * HAL_CORDIC_GetUserData ( const hal_cordic_handle_t * hcordic )

Retrieve user data pointer from the handle.

Parameters :

hcordic – Pointer to a hal_cordic_handle_t.

Return values :

void – Pointer to the user data.

hal_cordic_t HAL_CORDIC_GetInstance ( const hal_cordic_handle_t * hcordic )

Get the CORDIC instance.

Parameters :

hcordic – Pointer to a hal_cordic_handle_t structure.

Return values :

HAL_CORDIC – HAL CORDIC instance.

CORDIC_TypeDef * HAL_CORDIC_GetLLInstance ( const hal_cordic_handle_t * hcordic )

Get the hardware CORDIC instance.

Parameters :

hcordic – Pointer to a hal_cordic_handle_t structure.

Return values :

CORDIC – CORDIC peripheral instance.