Page 1 of 2

Can't use CAN2 without CAN1, and filters  Topic is solved

Posted: Fri Nov 24, 2017 11:00 am
by steved
Using 32F767, but probably applies to all.

1. The hardware allows use of CAN2 without CAN1 being active; while there are interactions, these appear to be solely or largely in the area of filters. (See 40.9.4 in RM0410 makes it clear that this is a supported configuration). However the current driver requires CAN1 to be started, even if not used, before CAN2 can be started.

2. canSTM32SetFilters(), which I assume to be the 'official' API for setting of the filters clearly expects to be called before the driver is started. However it is possible to update the filters at run-time by setting FINIT in CAN_FMR register. (I've got other comments on the API to the filters, but since they're by way of enhancements, I'll post them elsewhere)

Re: Can't use CAN2 without CAN1, and filters

Posted: Fri Nov 24, 2017 11:12 am
by Giovanni
hi,

Could you post a patch for this?

Giovanni

Re: Can't use CAN2 without CAN1, and filters

Posted: Fri Nov 24, 2017 1:07 pm
by steved
Giovanni wrote:Could you post a patch for this?

Eventually - not expecting to have hardware to play with and test for a week or two. And it'll include some extensions to the API to support filter updates on the fly. (Code's pretty much done; just needs testing/debugging, so can make available if anyone else has this problem)

Re: Can't use CAN2 without CAN1, and filters

Posted: Sat Jan 20, 2018 4:35 pm
by Giovanni
Bump, is this still a thing?

Giovanni

Re: Can't use CAN2 without CAN1, and filters

Posted: Sun Jan 21, 2018 10:16 am
by steved
Giovanni wrote:Bump, is this still a thing?

Giovanni

Yes it is - working on CAN ATM, but not to the point of having anything to submit yet.

Re: Can't use CAN2 without CAN1, and filters

Posted: Sun Jan 21, 2018 5:49 pm
by hercek
CAN1 must be started before CAN2 (even when only CAN2 is used) on STM32F405 too.

Re: Can't use CAN2 without CAN1, and filters

Posted: Fri Jul 27, 2018 2:57 pm
by Giovanni
bump

Re: Can't use CAN2 without CAN1, and filters

Posted: Thu Aug 02, 2018 5:19 pm
by hercek
It is not fixed in stable_18.2.x.
See ChibiOS/os/hal/ports/STM32/LLD/CANv1/hal_can_lld.c

Code: Select all

689     #if STM32_CAN_USE_CAN2
690       if (&CAND2 == canp) {
691
692         osalDbgAssert(CAND1.state != CAN_STOP, "CAN1 must be started");
693
694         rccEnableCAN2(true);
695       }
696     #endif

Re: Can't use CAN2 without CAN1, and filters

Posted: Thu Aug 02, 2018 9:33 pm
by steved
It looks pretty definite that if CAN2 is enabled, CAN1 has to be also enabled within the HAL. Possibly this can be done automatically in the LLD.

Should have some proposed updates to the LLD eventually - one point being considered is where one draws the line between the standard LLD and optional 'helper' functions. These helpers are very ST-specific, so logically would go with the ST-specific driver. But its debateable whether they should be in the single LLD file, or in a separate file. Any thoughts?

Re: Can't use CAN2 without CAN1, and filters

Posted: Thu Aug 02, 2018 9:39 pm
by Giovanni
The assertion is correct even if less than optimal.

Probably it should be automatic like steved suggested, it should not be hard to do. Enable clock in canStart(), disable clock in canStop() if both instances are stopped, one "if".

Giovanni