Incompatibility in CAN implementation between HAL and SPL due to possible bug in HAL
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-02-25 1:50 AM
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
- Labels:
-
CAN
-
STM32F4 Series
-
STM32F7 Series
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-02-25 7:18 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-02-25 7:33 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-02-25 9:18 AM
Your settings in canF4 don't match those of your top post, and don't look to be consistent with 1Mbps
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-02-25 4:34 PM
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 ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-02-26 7:48 AM
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
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-02-26 8:48 PM
Hi Tesla
Even if CAN_SJW where changed to 1tq instead of the present 2tq, the baud rates on both boards will still match. (Though not at 1Mbps as you have pointed out in your post)
I should point out that the manual gives the formula for bit timing differently
https://www.manualslib.com/manual/1249201/Stmicroelectronics-Stm32f405.html?page=1085#manual
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-03-02 10:48 PM
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.
