cancel
Showing results for 
Search instead for 
Did you mean: 

CAN2 in STM32F407 is not working

Parvez Akhtar
Associate II

I wanted to us CAN2 interface in my project. I started with example application ("CAN_Networking"). This example application works very well with CAN1 but when CAN2 is configured in this application it doesn't work at all. No transmission and no reception.

I searched online for similar problem and I got many issues related to same. But I tried all the solution and nothing worked. Sharing links below

https://stackoverflow.com/questions/36311263/stm32f1xx-can2-receive-interrupt-not-being-called

https://stackoverflow.com/questions/65290032/using-both-can1-can2-both-in-stm32f446-properly

https://stackoverflow.com/questions/27315649/stm32f429-is-not-receiving-the-can-message

I am sure it has something to do with filter setting and driver being provided by STM team. But it seems they didn't test their example programs with CAN2.

  1. Why these application doesn't enable CAN1 clock by default whereas it is compulsory to enable CAN1 clock even if you are using only CAN2.
  2. Why their driver initializes register with CAN1 address in HAL_CAN_ConfigFilter().
  3. There is not interrupt at all from CAN even if I could see signal on Rx pin and Tx pin.

Please help me if anybody have solution of this problem.

5 REPLIES 5
SofLit
ST Employee

@Parvez Akhtar

If you want to use CAN2, you have to enable CAN1 clock even if it will be not used. CAN1 APB clock should be enabled since CAN1 instance is a master from peripheral integration point of view and it manages the filtering part. 

Regarding the filtering management between CAN1 and CAN2, I invite you to have a look at this thread:

https://community.st.com/s/question/0D73W000000bHEESA2/detail?fromEmail=1&s1oid=00Db0000000YtG6&s1nid=0DB0X000000DYbd&s1uid=0050X000007vx9R&s1ext=0&emkind=chatterCommentNotification&emtm=1685418050174

Hope it helps.

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

The filter bank is split in two halves (you define the split point), and CAN2 has to use the filters on it's half.

Typically split at 14 so 0..13 on CAN1 14..27 on CAN2

The F4 basically has 1.5x CAN hardware, CAN2 is dependent on CAN1 working.

Transmit should work, double check pin configurations, AF settings, routine of pins physically to the transceiver. If not your board, double check schematic, and options / solder-bridges.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Parvez Akhtar
Associate II

Hi Tesla,

Thank you for your reply.

I have seen that link but it didn't help much. In fact, I have seen all possible links and finally asked question here.

Did anybody try to run only CAN2 ? I know CAN1 clock has to be enabled.

---------

"The F4 basically has 1.5x CAN hardware, CAN2 is dependent on CAN1 working."

-----

What do you mean by this ? You mean, to make CAN2 work CAN1 also has to be configured (Clock, GPIO, FIFO, Filters etc) or only CAN1 clock is enough? Although I tried it already and it didn't work. I didn't try both together because CAN1 pins are being used for other purpose.

I have checked all my HW pins, connections even checked waveforms on Rx and Tx Pin. I am sure there is no issue of HW connections.

I have tried almost all combination of filter configuration I could find on internet but it still didn't work.

Like,

CAN2

filterBank=0,14,15,20

SlaveBank=0,14,15

I guess there is a a bug in STM32 MCU because so many people have reported it nobody got successful answer. I am talking about CAN2 only.

Regards,

Parvez Akhtar

I've had this working on a F407 RedDragon board back in the day, CAN1 to/from CAN2, used SPL, so pre-HAL

Also had CAN working on our own F2 / F4 boards.

Been a while, HW works adequately, but not invested in spending engineering time reproving it.

I mean it's not two complete CANbx instantiations, CAN2 adds perhaps 1/2 the transistors of the CAN1, so like a siamese twin, but sharing some critical organs, or like Intel's Pentium was 1.5x 80486, it got super-scalar by having two execution units, and occasionally it would have instructions only one could execute to completion.

CAN2

filterBank=14,15,... filters within the slave bank

SlaveBank=14

Filter's deal with reception.

Transmit mailboxes, limited resource. If there not completing / clearing, check error / status reporting to understand why.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Dear Parvez Akhtar,

Did you try CAN in loopback mode to discard any HW issue? if yes, could you please put a minimal FW with CAN2? If not, try to start with CAN in loopback mode and try again!

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.