Page 1 of 1

STM32F4-DISCOVERY Can Filters Problem

Posted: Wed May 21, 2014 12:39 pm
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?

Re: STM32F4-DISCOVERY Can Filters Problem

Posted: Wed May 21, 2014 1:01 pm
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

Re: STM32F4-DISCOVERY Can Filters Problem

Posted: Wed May 21, 2014 1:29 pm
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

Re: STM32F4-DISCOVERY Can Filters Problem

Posted: Wed May 21, 2014 1:57 pm
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