Skip to main content
Associate III
January 31, 2025
Solved

CAN communication on STM32MP157f-dk2 in Classical CAN (CAN2.0)

  • January 31, 2025
  • 8 replies
  • 3582 views

Hi,

I would like to use CAN communication on my devboard : STM32MP157f-DK2.

So I prepared OS, unfortunatelly I have to flash STM32MP157c-DK2 version according with problem described below:

Faulty boards out of the box 

So, after run OS, I edited *.dts file, by initialized &m_can1 device on PA11 and PA12 pins, which one exposed  on the board connector - CN2, and connected "MCP2542 click CAN bus transceiver" board.

In OpenSTlinux userspace I try recive CAN frames by command: candump can0, and there is any problem, because when I send full frame with 8 bytes that it doesn't arrive to device. Maksimum only 5 bytes in frame arrives, like below:

 

sendData.jpg

What can be wrong with CAN in STM ?
Please for any tips.

Best answer by ienecode

@mƎALLEm  Success , All frames arrived to STM32 from   ECU, and USB converter, when I set interface like below:

 

ip link set can0 up type can bitrate 500000 sample-point 0.750

But I do not know why...

 

8 replies

Ozone
Principal
January 31, 2025

I assume the problem is in your interpretation of the output.

A standard CAN frame always contains an 8 byet payload. However, it is preceeded by a length code (DLC)  which tells the receiver how many of this 8 bytes are valid.

I would say, check with the documentation of the "host" (STM32MP157) CAN application, and the connected device(s).

My company e.g. extensively uses CANopen, were several defined frames have just a 1 or 2 byte payload.

ienecodeAuthor
Associate III
January 31, 2025

@Ozone 
Interpretation of the output ? In OpenStlinux The BOSCH M_CAN driver is enabled by default, to read frames by CAN I am susing can-utils (This repository contains some userspace utilities for Linux CAN subsystem (aka SocketCAN)).

To send frames from host I use below USB converter :

isCAN<->usb 

Ozone
Principal
February 3, 2025

Do you have a PC CAN adapter, and some monitoring software ?
Something like the relatively affordable PCAN dongle and the free PCAN-View do the job quite well.

I didn't work with STLinux can-utils yet, but the CAN standard is pretty clear.
The CAN low-level protocol is relatively complex compared to e.g. UART, I2C or SPI, and frame reception is usually handled by the peripheral (IP) alone. CAN frames with errors like incorrect length will be rejected/discarded immediately, and not passed into the "CAN mailbox" buffer or to the application.

ienecodeAuthor
Associate III
February 4, 2025

I do not use 120 ohm resistor because twice 60 ohm are included in transceiver MCP2542 Click. - please look on the below schematic:

schemat.png

 

Ozone
Principal
February 4, 2025

This is most probably not a signal issue.

If that was the case, no message reception would be reported by candump, and the MP157 CAN node would quickly run into error-passive and finally bus-off mode.

mƎALLEm
Technical Moderator
February 4, 2025

Hello,

if you can let me intervene even I'm not MPU products expert.

From your first post, you shared a figure where the frame sent by your host contains 5 bytes and are received well by the MP157. Which is expected. But STM32MP1 has FDCAN interface supporting CAN-FD frames.

You didn't show the behavior where data length > 5 bytes.

Note that the data length with FDCAN can reach 64 bytes if you are using the peripheral in CANFD mode and the data length is included in the frame in the DLC field. So the application needs to read that field to extract the exact number of bytes received.

So the question here, how did you configure FDCAN from the MPU side? in CAN2.0 or in CANFD mode? from your transmitter screen shot I conclude you are sending data in CAN2.0 format. Are you sure you set FDCAN peripheral in Classical mode (CAN2.0)?

 

"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."
Ozone
Principal
February 4, 2025

> Note that the data length with FDCAN can reach 64 bytes if you are using the peripheral in CANFD mode  ...

I suspect now you confused the OP even more ...

I would definitely recommend to consult someone with CAN experience directly, perhaps a work mate or friend.

mƎALLEm
Technical Moderator
February 4, 2025

@Ozone wrote:

> Note that the data length with FDCAN can reach 64 bytes if you are using the peripheral in CANFD mode  

I suspect now you confused the OP even more ...


Sorry? 

This is to warn him about the usage of the FDCAN cell in incorrect mode. That's why I asked him about his FDCAN peripheral configuration: CAN2.0: max 8 bytes or CANFD: max 64 bytes.

"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."
mƎALLEm
Technical Moderator
February 4, 2025

See this thread:

ip link set can0 type can bitrate 500000
ifconfig can0 up
"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."
ienecodeAuthor
Associate III
February 5, 2025

@mƎALLEm Thanks for many tips but the problem is still.

Now I disconnected my USB to CAN2.0 converter, and connected ECU from old car to STM32MP1.

I prepared simple application in Qt to run cansocket on STM32mp1 and deployed.

Sometime several first frames arrived to STM when the ECU is power on, and the bus goes to error, below my log

:

 

 

Warning: Identity file not accessible: No such file or directory.
id: 'weston': no such user
id: 'weston': no such user
id: 'weston': no such user
QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-root'
No modes available for output "HDMI1"
qt.qpa.input: xkbcommon not available, not performing key mapping
RTNETLINK answers: Device or resource busy
qt.canbus.plugins.socketcan: Cannot apply parameter: 4 with value: 500000.
libpng warning: iCCP: known incorrect sRGB profile
CAN bus status: Good.
CAN bus status: Good.
CAN bus status: Good.
CAN bus status: Good.
CAN bus status: Good.
CAN bus status: Good.
CAN bus status: Good.
CAN bus status: Good.
CAN bus status: Good.
CAN bus status: Good.
CAN bus status: Good.
CAN bus status: Good.
CAN bus status: Good.
CAN bus status: Good.
CAN bus status: Good.
CAN bus status: Good.
CAN bus status: Good.
CAN bus status: Good.
CAN bus status: Good.
CAN bus status: Good.
Some frames received
Received message: "1738768824.2952 --- Controller problem:\n reached warning level for RX errors"
Received message: "1738768824.2952 --- Controller problem:\n reached warning level for RX errors1738768824.2895 --- 010 [8] AA 62 3B 45 F9 12 6D 5B"
Received message: "1738768824.2952 --- Controller problem:\n reached warning level for RX errors1738768824.2895 --- 010 [8] AA 62 3B 45 F9 12 6D 5B1738768824.2899 --- Controller problem:\n reached error passive status RX"
CAN bus status: Error.
CAN bus status: Error.
CAN bus status: Error.
CAN bus status: Error.
CAN bus status: Error.
16:20:34: User requested stop. Shutting down...
16:20:34: Application finished with exit code 1.

 

 

mƎALLEm
Technical Moderator
February 5, 2025

As I said I'm not familiar with STM32MP products but with CAN interface in general. At this level I don't recommend to use another CAN node like the ECU. Keep the USB/CAN converter. For such communication CAN needs a precise clock source like a crystal/crystal oscillator. Check in your project if the FDCAN is clocked from a precise clock (sorry I can't help you on this point).

Did you try to probe the CAN bus? do you have a CAN analyzer?

"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."
ienecodeAuthorBest answer
Associate III
February 5, 2025

@mƎALLEm  Success , All frames arrived to STM32 from   ECU, and USB converter, when I set interface like below:

 

ip link set can0 up type can bitrate 500000 sample-point 0.750

But I do not know why...

 

mƎALLEm
Technical Moderator
February 5, 2025

Did you succeed to read more than 5 bytes on STM32MP with the USB converter with that config?

For the sample point, see this thread (on MCU products).

"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."
ienecodeAuthor
Associate III
February 5, 2025

@mƎALLEmExactly , also the USB converter works fine. The CAN2.0 frames on 500k baud rate and arriving to STM32MP1 !

mƎALLEm
Technical Moderator
February 5, 2025

Ok glad to hear that..

"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."