2025-01-31 01:43 AM - last edited on 2025-02-05 08:36 AM by SofLit
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:
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:
What can be wrong with CAN in STM ?
Please for any tips.
Solved! Go to Solution.
2025-02-04 08:41 AM - edited 2025-02-04 08:53 AM
@SofLit you're right. The STM32MP1 support FDCAN interface, and when I try turn off I get message:
root@stm32mp1:~# ip link set can0 type can bitrate 500000 dbitrate 1000000 fd off
RTNETLINK answers: Operation not supported
According with my knowledge frames with CAN2.0 can send to CAN FD. If I'm wrong please correct me.
What I discovered during the tests....
Originally I test my CAN communication with according with below set up socketCan interface:
ip link set can0 type can bitrate 500000 dbitrate 2000000 fd on
And Like I descirbed I had a problem, where only max 5 bytes data in frame arrive to STM32 from my test application.
Now I test communication on 1M bitrate:
ip link set can0 type can bitrate 1000000 dbitrate 2000000 fd on
and the communication working, the CAN2.0 frames with 8 bytes payload data arrvied to STM32!
So, maybe now anybody can help me solve problem with 500kBaud transmission problem ? what could it be caused by?
2025-02-04 11:58 AM - edited 2025-02-04 12:02 PM
I don't have idea how to configure the MPU environnement. But according to
ip link set can0 type can bitrate 500000 dbitrate 2000000 fd on
Seems the FDCAN is activated: 500000b/s is the nominal bitrate and the 200000b/s is for the data phase bitrate. And your sender doesn't support that frame. SO you need to find how to set the FDCAN interface in CAN2.0.
So, you need to trun off the FDCAN mode: I think (I'm not sure):
ip link set can0 type can bitrate 500000 dbitrate 2000000 fd off
-> for a nominal bitrate of 500kb/s where fd mode is off.
or try:
ip link set can0 type can bitrate 500000 fd off
or
ip link set can0 type can bitrate 500000
2025-02-04 12:03 PM
See this thread:
ip link set can0 type can bitrate 500000
ifconfig can0 up
2025-02-05 07:27 AM - edited 2025-02-05 07:28 AM
@SofLit 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.
2025-02-05 07:55 AM
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?
2025-02-05 08:14 AM - edited 2025-02-05 08:15 AM
@SofLit 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...
2025-02-05 08:17 AM - edited 2025-02-05 08:23 AM
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).
2025-02-05 08:27 AM - edited 2025-02-05 08:30 AM
@SofLitExactly , also the USB converter works fine. The CAN2.0 frames on 500k baud rate and arriving to STM32MP1 !
2025-02-05 08:30 AM
Ok glad to hear that..