on 2024-07-22 05:00 AM
STM32 MCUs users may face an issue with CAN message reception mainly when the CAN2 instance is used. This issue may appear even if the hardware setup is correct, and CAN bit time and filters are configured correctly. If the value of Start Bank is not correctly set, no CAN message will be received.
In this article we explain the purpose of the Start Bank parameter and how it is managed when the STM32 has at least two CAN instances (Dual CAN).
Most of the STM32 MCUs feature a CAN interface. Some of them have one CAN instance like the STM32F103 MCU, others have two CAN instances like the STM32F429 MCU and others have 3 CAN instances like the STM32F769 MCU.
To optimize the internal architecture of the STM32, when two CAN instances are available, they share the same RAM (512 bytes), and filters. In that case, a mechanism to manage the resources is needed to handle this sharing mainly the filters resources. From an internal architecture standpoint, CAN1 is a master while CAN2 is a slave of CAN1. So, to use CAN2, CAN1 RCC clock shall be enabled.
The figure above (from RM0090 but does also appear in other reference manuals) illustrates the block diagram in a Dual-CAN implementation.
As shown in the figure the filters are shared between CAN1 and CAN2. The number of filters shared between the two instances is 28. When the two CAN instances are used at the same time in the application, the user can assign more filter resources to CAN1 than CAN2 and vice versa. The user can even assign all the filter resources to one instance. In that case the second instance is unusable. For this, the CAN2 Start Bank bits (CAN2SB[5:0]) in the CAN_FMR register are important to take in consideration to manage the shared filter resources. Note that in TRIPLE-bxCAN configuration, CAN3 is independent from CAN1 and CAN2. In this case, CAN3 is a master, and it has its own resources.
In the STM32Cube HAL, the member SlaveStartFilterBank of the CAN_FilterTypeDef structure, is the value that corresponds to CAN2SB to be set in the CAN_FMR register.
The value of CAN2SB can be seen as "a cursor" moving to the left or to the right to configure the number of filters allocated to CAN1 and CAN2. If the cursor is moved to the left more filters are allocated to CAN2. Conversely, if the cursor is moved to the right more filters are allocated to CAN2.
If SlaveStartFilterBank = 14: 14 filters are allocated to CAN1 (filter 0 to 13) and 14 filters are allocated to CAN2 (filter 14 to 27).
If SlaveStartFilterBank = 28: all filters are allocated to CAN1. In that case CAN2 are not used.
If SlaveStartFilterBank = 0: all filters are allocated to CAN2. In that case CAN1 is not usable, but CAN1 APB clock should be enabled since it is a master as mentioned previously.
The following figures illustrate the 28 available filters (from 0 to 27) and how the filters resources are split between the two CAN instances using the SlaveStartFilterBank (CAN2SB) parameter.
Case 1 - filter resources are shared equally between CAN1 and CAN2 (configuration after reset):
Case 2 - more filter resources are allocated to CAN2:
Case 3 - all the 28 filters are allocated to CAN2. CAN1 is no longer useful:
Case 4: All the 28 filters are allocated to CAN1. CAN2 is no longer useful:
This is an important parameter, because no CAN message will be received in the FIFO even if all CAN parameter settings, i.e., bitrate, filter configuration, and the hardware is correctly set up while SlaveStartFilterBank is not.
This is simply because when a filter is selected out of the range of what is selected by the cursor.
Example: A filter is configured, and its number is set to 17 (FilterBank = 17) and assigned to CAN1 while SlaveStartFilterBank = 14. 17 is out of range of CAN1 filter bank. This never works and neither FIFO0 or FIFO1 receives the CAN frame.
In conclusion, to make it functional, two parameters need to be care of SlaveStartFilterBank and FilterNumber. The following conditions need to be fitted: