cancel
Showing results for 
Search instead for 
Did you mean: 

Example for Dual CAN filter bank configuration (using two CAN)

JDeck.1
Associate

Is there any example for using CAN1 and CAN2 in a dual CAN MCU like the STM32F777, especially how to configure the filter bank using the ST HAL (cube) ??

As I understand the filter bank is shared. Are the FIFO0 and FIFO1 also shared?

Why is there a CAN2_FMR register ? CAN2SB of CAN1_FMR is used the specify the number of filters used for CAN1. The rest of the 27 filters is assigned to CAN2. What for is then CAN2SB of CAN1_FMR ?

If I excecute my pice of software, the FINIT of CAN1_FMR.FINIT goes to 0 (filters active), but CAN2_FMR.FINIT stays at 1 (init mode for the filters).

Here is my code:

  //##-2- Configure the CAN Filter ###########################################

  filterCfg.FilterFIFOAssignment  = CAN_RX_FIFO0;//CAN_RX_FIFO1 for CAN2 ???

  if(hcan->Instance == CAN1){

   filterCfg.FilterBank     = 0;

  }

  else{ // CAN2

   filterCfg.FilterBank     = 14;  

  }

// CAN_FILTER_MODE_LIST

   if(initCfg.idSizeType == CAN_EXT_ID){

     tmp = (initCfg.SystemCanId & 0x1FFFFFFF) << 3;

     // Shift um 3, denn die oberen Bits [31:3] werden verwendet für Vgl 

     // mit der Ext.ID[0:29], 

     // siehe Reference manual: Figure 500. Filter bank scale configuration   

   }

   else{ // CAN_STD_ID     

     tmp = (initCfg.SystemCanId & 0x000003FF) << 21;

     // Links Shift um 21, denn die oberen Bits [31:21] werden verwendet 

     // für den Vgl mit der Std.ID[0:11] 

     // siehe Reference manual: Figure 500. Filter bank scale configuration      

   } 

   tmp = (initCfg.SystemCanId & 0x1FFFFFFF) << 3;

   filterCfg.FilterIdHigh      = (uint16_t)(tmp >> 16);

   filterCfg.FilterIdLow      = (uint16_t) tmp;

   filterCfg.FilterMaskIdHigh    = 0x0000;//(uint16_t)(tmp >> 16);

   filterCfg.FilterMaskIdLow    = 0x0000;//(uint16_t) tmp;

   filterCfg.FilterMode     = CAN_FILTERMODE_IDLIST;  

  filterCfg.FilterScale      = CAN_FILTERSCALE_32BIT;

  filterCfg.FilterActivation    = ENABLE;

  filterCfg.SlaveStartFilterBank  = 14;

  if (HAL_CAN_ConfigFilter(hcan, &filterCfg) != HAL_OK){

   return CAN_ERROR_INIT;   // Filter configuration Error

  }

1 ACCEPTED SOLUTION

Accepted Solutions
JDeck.1
Associate

I solved these issue now. By debugging the ST HAL code, I understood, that in CAN dual mode, CAN2 is the slave and the filter settings for CAN2 are found also in the filter registers for CAN1.

CAN1_FMR.FINIT does apply to CAN1 and CAN2 and CAN2_FMR.FINIT has no relevance. Thats why CAN2_FMR.FINIT stays at 1 (init mode for the filters).

I also forgot to take care about the IDE-Bit, while using CAN_FILTER_MODE_LIST. That was the reason that I didn't got the incoming messages when I used the Filter Mode List.

View solution in original post

1 REPLY 1
JDeck.1
Associate

I solved these issue now. By debugging the ST HAL code, I understood, that in CAN dual mode, CAN2 is the slave and the filter settings for CAN2 are found also in the filter registers for CAN1.

CAN1_FMR.FINIT does apply to CAN1 and CAN2 and CAN2_FMR.FINIT has no relevance. Thats why CAN2_FMR.FINIT stays at 1 (init mode for the filters).

I also forgot to take care about the IDE-Bit, while using CAN_FILTER_MODE_LIST. That was the reason that I didn't got the incoming messages when I used the Filter Mode List.