cancel
Showing results for 
Search instead for 
Did you mean: 

How to setup FDCAN on STM32MP157F-DK2?

SScar.2
Senior

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

1 ACCEPTED SOLUTION

Accepted Solutions
GLaure
Senior

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

View solution in original post

10 REPLIES 10
GLaure
Senior

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

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

GLaure
Senior

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

I did not remove any resistors.

Ok thanks... i'll try then

Hi @GLaure​,

You were right! I reattached the resistors, plug both powers 3v3 and 5v, inverted tx and rx and got the CAN working! I have to fine tuning the sample-points and all others stuff but it works! So we assume that the double alimentation is kinda standard for transcievers. Again, I'm using CAN FD 3 Click an a add-on board based on TLE9251V CAN.

thanks again

When working with a CAN transceiver and and MCPU you do not cross TX/RX. It may appear to work, but it will fail as the CAN network grows and there are multiple senders/receivers.

0693W00000aJQE6QAO.png

Yes you're right! Thanks

However, I want to warn who will watch this post saying that with this MPU (also for all MP1 family?) you will loose a lot of time calibrating the clock for FDCAN, by default is imprecise at high baudrates! My suggestion is to initialize the peripheral under the M4 and handling it inside the firmware and not in Linux user space. It's just easier, but it's not mandatory.

See ya

I have also found that I can get higher, reliable speeds using the Cortex M7 and M4 cores on the H745 for instance. In this instance I am using 1Mb arbitration and 1Mb data rate and it's working acceptably.

hi @GLaure 
help me out the FDCAN where i saw manual where i unable to find the FDCAN pins how you get the exact location of the pin and i want to receive the data only