Skip to main content
Graduate II
November 22, 2022
Solved

How to setup FDCAN on STM32MP157F-DK2?

  • November 22, 2022
  • 4 replies
  • 6406 views

Hi everyone!

I'm here with my devkit and trying to have FDCAN working properly! I compiled the Yocto distribution for the board and I followed all the tutorials in the wiki ( https://wiki.st.com/stm32mpu/wiki/Category:CAN ) and here's what I came up with:

I initialized m_can1

&m_can1 {

pinctrl-names = "default", "sleep";

pinctrl-0 = <&m_can1_pins_b>;

pinctrl-1 = <&m_can1_sleep_pins_b>;

status = "okay";

};

I used the pins_b configuration because looking at the datasheet they were the only possible exposed pins on the PI_GPIO extender (CN2) on the board (overwriting I2C5 pins for the Arduino). I also removed the pullup resistors for i2c (R166 and R167).

On the kernel side I tried the loopback and seems to work fine:

root@stm32mp1:~# ip link set can0 up type can bitrate 1000000 dbitrate 2000000 fd on

[ 1602.982564] m_can_platform 4400e000.can can0: bitrate error 0.3%

[ 1602.988958] m_can_platform 4400e000.can can0: bitrate error 0.3%

[ 1602.994593] IPv6: ADDRCONF(NETDEV_CHANGE): can0: link becomes ready

(the second bitrate error is different from the tutorials...) and seems working ok

root@stm32mp1:~# candump can0 -L &

root@stm32mp1:~# cansend can0 300#AC.AB.AD.AE.75.49.AD.D1

(1669130989.509567) can0 300#ACABADAE7549ADD1

(1669130989.509533) can0 300#ACABADAE7549ADD1

Now, I'm trying to get some data on the physical bus but it seems not working, I attached the oscilloscope on the pin PA12 (EXP_GPIO2) which should be the FDCAN tx, and enabled the bus as the example :

ip link set can0 up type can bitrate 1000000 dbitrate 2000000 fd on

But I can see absolutely nothing on the pin if I send any packet with cansend.

I also tried to attach a proper transceiver ( I used mikro CAN FD 3 click https://www.mikroe.com/can-fd-3-click --> TLE9251V based) , and after the cansend, the bus goes instantly bus-off :

root@stm32mp1:~# cansend can0 01a#11223344AABBCCFF

[ 706.810510] m_can_platform 4400e000.can can0: bus-off

Do you have any suggestions to make the protocol work properly? Do you have tried it yourself?

Huge thanks!

Simone

    This topic has been closed for replies.
    Best answer by GLaure

    For transceiver MCP2542 following pins have to be connected:

    * 3.3V

    * 5V

    * GND

    * TX to MC2542 RX

    * RX to MC2542 TX

    Note: Do not forget to cross TX/RX!

    Function	STM32 pin	Pin		To MCP
    3V3			-			1		3V3
    5V			-			2		5V
    GPIO2		PA12		3		RX
    GPIO3		PA11		4		TX
    GND		-			9		GND

    This worked for me.

    Bye Gunther

    4 replies

    GLaureAnswer
    Explorer
    November 23, 2022

    For transceiver MCP2542 following pins have to be connected:

    * 3.3V

    * 5V

    * GND

    * TX to MC2542 RX

    * RX to MC2542 TX

    Note: Do not forget to cross TX/RX!

    Function	STM32 pin	Pin		To MCP
    3V3			-			1		3V3
    5V			-			2		5V
    GPIO2		PA12		3		RX
    GPIO3		PA11		4		TX
    GND		-			9		GND

    This worked for me.

    Bye Gunther

    SScar.2Author
    Graduate II
    November 23, 2022

    Hi @GLaure​ 

    thanks for the answer! I din't attach both alimetations, I'll try that.

    I have some questions: did you enable m_can only in the kernel dts just like me, or also in uboot? Also, did you removed the resistors as I did? Did you follow the same steps I did?

    Thank you SO MUCH

    simone

    Explorer
    November 23, 2022

    Just in the kernel dts. It does not have to be configured by u-boot.

    I did not remove any resistors.

    SScar.2Author
    Graduate II
    November 23, 2022

    Ok thanks... i'll try then

    Explorer
    January 31, 2025

    @Javier1 

    Hi, I am trying run CAN. But I have weird problem, which one described below:

    can-communication-on-stm32mp157f-dk2 

    Do you have any idea what can be wrong ?

     

    Graduate II
    January 31, 2025

    Never touched openlinux or any MP board, sorry

    Explorer
    February 1, 2025

    @SScar.2maybe do you have any idea what can be wrong with my CAN communication described below ?

    can-communication-on-stm32mp157f-dk2 

    I noticed that we use different transceiver. You used CAN FD 3 Click , and I used MCP2542 Click .

    @SScar.2  Do you think it might have something to do with my problem ?