2021-10-15 08:05 AM
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
}
Solved! Go to Solution.
2021-10-18 05:23 AM
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.
2021-10-18 05:23 AM
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.