HAL FDCAN How to Use

group FDCAN_How_To_Use

How to use this driver

1.Declare a hal_fdcan_handle_t handle structure and initialize the FDCAN driver with an FDCAN instance.

2.Initialize the FDCAN peripheral using HAL_FDCAN_Init() function. The FDCAN clock is enabled inside HAL_FDCAN_Init() if USE_HAL_FDCAN_CLK_ENABLE_MODEL > HAL_CLK_ENABLE_NO.

3.Configure the low level hardware (GPIO, CLOCK, NVIC…etc)

  • Enable the FDCAN clock if USE_HAL_FDCAN_CLK_ENABLE_MODEL = HAL_CLK_ENABLE_NO

  • FDCAN pins configuration:

    • Enable the clock for the FDCAN GPIOs

    • NVIC configuration if you need to use interrupt process

4.Configure the peripheral using the HAL_FDCAN_SetConfig()

5.The control functions allow the user application to initiate Rx/TX transfer over the FDCAN bus, either sending frames or receiving frames or checking and managing the whole transfer process and resources (status, buffers, events). Most of the control functions can be called in IDLE, ACTIVE or POWER_DOWN states, however some control functions are restricted to given states, for example HAL_FDCAN_Start() can be called in IDLE and ACTIVE but not in POWER_DOWN. The control functions include the following set of functions:

To start the FDCAN module, the user application must call HAL_FDCAN_Start() function. At this level the node is active on the bus.

6.Polling mode operation.

7.Interrupt mode operation.

8.Callback registration

9.Acquire/Release the FDCAN bus

  • When the compilation flag USE_HAL_MUTEX is set to 1, it allows the user to acquire/reserve the whole FDCAN bus for executing process. The HAL_FDCAN_Acquire and HAL_FDCAN_Release are based on the HAL OS abstraction layer (stm32_hal_os.c/.h osal):

  • When the compilation flag USE_HAL_MUTEX is set to 0 or not defined, HAL_FDCAN_AcquireBus/HAL_FDCAN_ReleaseBus are not available.