Skip to main content
srinath mallikarjunan
Associate II
February 25, 2022
Question

Incompatibility in CAN implementation between HAL and SPL due to possible bug in HAL

  • February 25, 2022
  • 4 replies
  • 2220 views

Hi

We are trying to communicate between an F407 Discovery using SPL's CAN implementation and F756 Nucleo running HAL's CAN implementation.

Here is the calculation for time quanta and Baud rate...

Baudrate = 1 / Nominal Bit Time

Nominal Bit Time = 1 x Tq x Tbs1 x Tbs2

Time Quanta(tq) = 1/ (Frequency of CAN APB CLOCK / Prescalar)

Time Quanta(tq) = Period of CAN APB CLOCK x Prescalar

BAUDRATE = 1 / Nominal Bitrate (Time for one Bit)

Nominal Bitrate or Nominal BitTime (Time for one Bit) = 1 x Tq x Tbs1 x Tbs2

===============================================

F407 Dicovery Board:

SYS-CLK : 168MHz

APB1 CLK : 42MHz

CAN Prescalar : 7

TImeSeg1 : CAN_BS1_4TQ

TImeSeg2 : CAN_BS2_1TQ

SyncJumpWidth : CAN_SJW_1TQ

Sampling Point : 75%

BAUDRATE : 1MBps

CALCULATION:

tq = 1/(42MHz/7) = 166.667 nS

tBS1 = 4 x tq = 666.667 nS

tBS1 = 1 x tq = 166.667 nS

NominalBitTime = 1 tq + tBS1 + tBS2 = 1uS

Baudrate = 1/NominalBitTime = 1Mbps

samplingpoint (%) = tBS1/(tBS1 + tBS2)*100

(4/5)*100= 75%

===============================================

===============================================

F756 Nucleo Board:

SYS-CLK : 216MHz

APB1 CLK : 54MHz

CAN Prescalar : 9

TImeSeg1 : CAN_BS1_4TQ

TImeSeg2 : CAN_BS2_1TQ

SyncJumpWidth : CAN_SJW_1TQ

Sampling Point : 75%

BAUDRATE : 1MBps

CALCULATION:

tq = 1/(54MHz/9) = 166.66 nS

tBS1 = 4 x tq = 666.667 nS

tBS1 = 1 x tq = 166.667 nS

NominalBitTime = 1 tq + tBS1 + tBS2 = 1uS

Baudrate = 1/NominalBitTime = 1Mbps

samplingpoint (%) = tBS1/(tBS1 + tBS2)*100

(4/5)*100= 75%

Code for both is attached. No messages leave F407 or F756. Something very basic is wrong or the problem lies deep within HAL. Any help will be greatly appreciated.

Both codes are attached.

Regards

Srinath

This topic has been closed for replies.

4 replies

JPeac.1
Visitor II
February 25, 2022

Any time there's a CAN problem the best place to start are the CAN error registers. From your description the two nodes act as if they are not connected, which causes a bus timeout, disconnect and no messages.

I assume you have CAN transceivers, twisted-pair wire for the bus and termination resistors at each end?

Jack Peacock

srinath mallikarjunan
Associate II
February 25, 2022

Hi Jack

Yes we have can transceivers with 120 Ohm bus termination resistors at both ends.

I would like to add that with the same physical setup, both MCU's are able to communicate if both use HAL.

However the moment we change the F407 MCU code to use SPL, all communication between the MCU's stop.

The reason for our 'obsession' with SPL is that we have a lot of F407 based units installed with SPL. So changing the firmware on installed systems to HAL is not an option.

Srinath

Tesla DeLorean
Guru
February 25, 2022

Your settings in canF4 don't match those of your top post, and don't look to be consistent with 1Mbps

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
srinath mallikarjunan
Associate II
February 26, 2022

CAN_InitStructure.CAN_BS1 = CAN_BS1_4tq;

 CAN_InitStructure.CAN_BS2 = CAN_BS2_1tq;

 CAN_InitStructure.CAN_Prescaler = 7;

 CAN_Init(CANx, &CAN_InitStructure);

These are the settings in the canF4 code and match what is in the top post. So could you explain what/where the discrepancy is ?

Tesla DeLorean
Guru
February 26, 2022

 CAN_InitStructure.CAN_SJW = CAN_SJW_2tq; // WRONG

 /* CAN Baudrate = 1 MBps (CAN clocked at 24 MHz) */ // APB1 42 MHz

 CAN_InitStructure.CAN_BS1 = CAN_BS1_4tq;

 CAN_InitStructure.CAN_BS2 = CAN_BS2_1tq;

 CAN_InitStructure.CAN_Prescaler = 7;

 CAN_Init(CANx, &CAN_InitStructure);

Currently 857 Kbps not 1 Mbps

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
srinath mallikarjunan
Associate II
March 3, 2022

Changed SJW to 1tq on both boards. So both boards should theoretically be communicating at 1Mbps

However there are still no messages on the bus.