STM32F4-DISCOVERY Can Filters Problem

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderator: RoccoMarco

Post Reply
franek.bmw
Posts: 57
Joined: Thu Mar 13, 2014 11:15 am
Has thanked: 2 times

STM32F4-DISCOVERY Can Filters Problem

Post by franek.bmw »

Hi,
I wanted to run the filters on the CAN bus (for double FIFO on can rx).I use both CAN1 and CAN2. Both has to be filtered equally. For example, they only accept a frame with ID 0x05. I tried to use function canSTM32SetFilters but with no result. Frames are not received or only one CAN recives but all frames.
I tried to use this code:

Code: Select all

const CANFilter testfilter_struct = {1, 1, 1, 0, 5, 5};
void canDriver_CAN1_CAN2_Configure(const CANConfig *config)
{
   chThdYield();

   canStop(&CAND2);
   canStop(&CAND1);

   canSTM32SetFilters(2, 1, &testfilter_struct);

   palSetPadMode(GPIOD, 0, PAL_MODE_ALTERNATE(9));
   palSetPadMode(GPIOD, 1, PAL_MODE_ALTERNATE(9));

   palSetPadMode(GPIOB, 5, PAL_MODE_ALTERNATE(9));
   palSetPadMode(GPIOB, 6, PAL_MODE_ALTERNATE(9));

   canStart(&CAND1, config);
   canStart(&CAND2, config);
}



Does anyone know what is wrong in my program?
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: STM32F4-DISCOVERY Can Filters Problem

Post by Giovanni »

Hi,

The STM32 has one set of filters assigned to both CAN1 and CAN2, the function parameters are:

can2sb - The index of the first filter assigned to CAN2. Filters will be 0...(can2sb-1) for CAN 1, (can2sb...STM32_CAN_MAX_FILTERS) for CAN2.
num - The number of filters in the filters array.
cfp - The filters array.

Looking at your code it seems you program filter 1 but the first filter for CAN2 is 2, apparently CAN2 has no filters assigned.

The function is very close to the STM32 CAN inner working, please refer to the Reference Manual about the filter settings, their logic is a bit complex.

Giovanni
franek.bmw
Posts: 57
Joined: Thu Mar 13, 2014 11:15 am
Has thanked: 2 times

Re: STM32F4-DISCOVERY Can Filters Problem

Post by franek.bmw »

Hi,
thanks a lot for you anserw.
Could you show me a program in which the filter is working properly? With the use of the function of ChibiOS. No matter how filters are configured.
Best regards,
Franek
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: STM32F4-DISCOVERY Can Filters Problem

Post by Giovanni »

Hi,

I don't have an example with filters right now. The matter has been discussed here but I haven't heard anything back yet.

You could try setting your filters and then inspect the filter-related registers and see if those have been initialized according to the manual.

Giovanni
Post Reply