MCP2515 - ifconfig can0 up hangs -- was: Disabling Certain MPU Pins

This forum is for users of Microchip MPUs and who are interested in using Linux OS.

Moderator: nferre

methos
Posts: 6
Joined: Fri Jan 04, 2019 5:37 pm

MCP2515 - ifconfig can0 up hangs -- was: Disabling Certain MPU Pins

Wed May 22, 2019 5:56 pm

I am working with a prototype based on the AT91SAMA5D4. While testing this device, I came across a problem with the MCP2515 Can Controller IC. The reference design for this particular CAN Controller I tested with the Xplained board did not have the RX0BF, RX1BF, TX0RTS, TX1RTS and TX2RTS pins connected to the MPU.

The prototype has all these connected to the MPU at PB26, PB27, PB28, PB29 and PB30 respectively. It would seem that the mainline linux kernel driver for the MCP2515 is hanging when the command ifconfig can0 up is called. A system call does not return, so the ifconfig process is stuck in an uninterruptible sleep state.

Other than these pins being connected to the MPU, there is no difference at all from my test bed with the Xplained board. I was wondering if there is a way to disable MPU pins, perhaps in the DTS file such that I can confirm if the addition of these connections is causing an issue with the driver. Thank you in advance!
Last edited by blue_z on Thu May 30, 2019 9:58 pm, edited 1 time in total.
Reason: change subject
blue_z
Location: USA
Posts: 1957
Joined: Thu Apr 19, 2007 10:15 pm

Re: Disabling Certain MPU Pins

Wed May 22, 2019 9:15 pm

Multiplexing the pins of the SoC is performed by the pinctrl subsystem of the Linux kernel.
In the DT disabling the device node (i.e. "status = "disabled") or nullifying the pinctrl definitions would prevent any SoC pin assignment.
You could enable debug mode for the pinctrl subsystem in the kernel configuration to get runtime information.

Regards
methos
Posts: 6
Joined: Fri Jan 04, 2019 5:37 pm

Re: Disabling Certain MPU Pins

Tue May 28, 2019 7:03 pm

Thank you for pointing me in the right direction blue_z. I was able to set those particular pins to active high as instructed by our engineering team to bring the device more in line with the test suite I used in the past. The issue with the Can Bus however is still persistent.

It hangs during the call to ifconfig can0 up. I added strace to the image to diagnose exactly what is going on.

Code: Select all

root@sama5d4-xplained-sd:~# strace ifconfig can0 up
execve("/sbin/ifconfig", ["ifconfig", "can0", "up"], 0xbefe2d98 /* 15 vars */) = 0
brk(NULL)                               = 0x2c000
uname({sysname="Linux", nodename="sama5d4-xplained-sd", ...}) = 0
access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
fstat64(3, {st_mode=S_IFREG|0644, st_size=9457, ...}) = 0
mmap2(NULL, 9457, PROT_READ, MAP_PRIVATE, 3, 0) = 0xb6f6c000
close(3)                                = 0
openat(AT_FDCWD, "/lib/tls/v7l/neon/vfp/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat64("/lib/tls/v7l/neon/vfp", 0xbefd75c8) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/lib/tls/v7l/neon/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat64("/lib/tls/v7l/neon", 0xbefd75c8) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/lib/tls/v7l/vfp/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat64("/lib/tls/v7l/vfp", 0xbefd75c8)  = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/lib/tls/v7l/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat64("/lib/tls/v7l", 0xbefd75c8)      = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/lib/tls/neon/vfp/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat64("/lib/tls/neon/vfp", 0xbefd75c8) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/lib/tls/neon/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat64("/lib/tls/neon", 0xbefd75c8)     = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/lib/tls/vfp/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat64("/lib/tls/vfp", 0xbefd75c8)      = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/lib/tls/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat64("/lib/tls", 0xbefd75c8)          = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/lib/v7l/neon/vfp/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat64("/lib/v7l/neon/vfp", 0xbefd75c8) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/lib/v7l/neon/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat64("/lib/v7l/neon", 0xbefd75c8)     = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/lib/v7l/vfp/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat64("/lib/v7l/vfp", 0xbefd75c8)      = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/lib/v7l/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat64("/lib/v7l", 0xbefd75c8)          = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/lib/neon/vfp/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat64("/lib/neon/vfp", 0xbefd75c8)     = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/lib/neon/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat64("/lib/neon", 0xbefd75c8)         = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/lib/vfp/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat64("/lib/vfp", 0xbefd75c8)          = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/lib/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0(\0\1\0\0\0\\r\1\0004\0\0\0"..., 512) = 512
fstat64(3, {st_mode=S_IFREG|0755, st_size=1251084, ...}) = 0
mmap2(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb6f6a000
mmap2(NULL, 1320304, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0xb6dfc000
mprotect(0xb6f29000, 65536, PROT_NONE)  = 0
mmap2(0xb6f39000, 12288, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x12d000) = 0xb6f39000
mmap2(0xb6f3c000, 9584, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0xb6f3c000
close(3)                                = 0
set_tls(0xb6f6abb0, 0xb6f6b2a8, 0xb6f70000, 0xb6f6abb0, 0xb6f70000) = 0
mprotect(0xb6f39000, 8192, PROT_READ)   = 0
mprotect(0x2a000, 4096, PROT_READ)      = 0
mprotect(0xb6f6f000, 4096, PROT_READ)   = 0
munmap(0xb6f6c000, 9457)                = 0
brk(NULL)                               = 0x2c000
brk(0x4d000)                            = 0x4d000
uname({sysname="Linux", nodename="sama5d4-xplained-sd", ...}) = 0
access("/proc/net", R_OK)               = 0
access("/proc/net/unix", R_OK)          = 0
socket(AF_UNIX, SOCK_DGRAM, 0)          = 3
socket(AF_INET, SOCK_DGRAM, IPPROTO_IP) = 4
access("/proc/net/if_inet6", R_OK)      = 0
socket(AF_INET6, SOCK_DGRAM, IPPROTO_IP) = 5
access("/proc/net/nr", R_OK)            = -1 ENOENT (No such file or directory)
ioctl(4, SIOCGIFFLAGS, {ifr_name="can0", ifr_flags=IFF_NOARP}) = 0
ioctl(4, SIOCSIFFLAGS, {ifr_name="can0", ifr_flags=IFF_UP|IFF_RUNNING|IFF_NOARP}
The attached image represents the current schematic for the MCP2515 module in our prototype board. I have removed resistor R587, and I have set TX0RTS, TX1RTS, TX2RTS to active high. This is an exact analogue to the CAN Bus module I used with the xplained board, which is able to run the command ifconfig can0 up with no issues even as a write this.

Assuming no one really knows what the issue may be, where should I go next to seek help? Could it perhaps be a driver issue?
blue_z
Location: USA
Posts: 1957
Joined: Thu Apr 19, 2007 10:15 pm

Re: Disabling Certain MPU Pins

Wed May 29, 2019 12:07 am

methos wrote: Assuming no one really knows what the issue may be, where should I go next to seek help? Could it perhaps be a driver issue?
With prototype hardware, there could be more than just one issue, and they could be in hardware as well as software.

Linux is a poor choice for bringing up new/untested hardware, especially when you're unsure about the proper configuration.
Have you tried to adapt the CAN example from the Atmel Softpack for your board?
Executing "standalone" programs from U-Boot can be a powerful tool; you can easily examine registers to see what the HW state is.

If you're concerned about the Linux driver, then insert printk() statements to inform you of what is going on.

Regards
methos
Posts: 6
Joined: Fri Jan 04, 2019 5:37 pm

Re: Disabling Certain MPU Pins

Thu May 30, 2019 9:32 pm

Thank you for the suggestion of adding printk statements throughout the mcp251x driver.

I was able to determine there was an issue with the SPI write function, namely that it would not actually write the values to the registers of the MCP2515 module at all. This caused the CANSTAT register to stay in 0x08 state, which is the setup state.

Eventually the driver reaches a while loop that checks to see whether or not the module is in the normal state 0x00, and if it is not it continue loops and attempts to write the normal state to the CANSTAT register. This is what caused the entire process to hang.

After consulting with the electrical engineering team, it turned out that the crystal clock took 12ms to initialize. The creators of the driver anticipated the clock delay, and hard coded a 5 ms delay in the mcp251x_hw_reset function. The hardcoded definition is on line 220 of kernel version 4.14:

#define MCP251X_OST_DELAY_MS (5)

After changing this hard coded definition to 20 ms, to give the crystal clock ample time to start, everything started working perfectly. The engineering team believe that the 18 pF capacitors are the cause of the slow clock startup, and changing them to 16 pF should solve the problem. However, this issue can be addressed in software as well.

Would it be possible to change the subject of this thread to "MCP2515 - ifconfig can0 up hangs"? That way individuals who may be facing a similar issue can more easily find it?

Thank you again for the help!

Return to “LINUX”

Who is online

Users browsing this forum: Majestic-12 [Bot] and 3 guests