Skip to content

2 MCP2515 dont work at the same time #1018

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
petit-miner opened this issue Jun 10, 2015 · 23 comments
Closed

2 MCP2515 dont work at the same time #1018

petit-miner opened this issue Jun 10, 2015 · 23 comments

Comments

@petit-miner
Copy link

Two MCP2515 Can Bus Controller IC dont work at the same time.
The PI has two SPI CE Pins so this shouldnt a problem.

@pelwell
Copy link
Contributor

pelwell commented Jun 15, 2015

@msperl Any thoughts?

@msperl
Copy link
Contributor

msperl commented Jun 15, 2015

I have a setup with 2 mcp2515 and it works fine for me (together with mmc-spi(with patch), fbtft and enc28j26)
I guess it may depend on the dt-overlay...

One thing that I had seen originally was: does it get detected properly after:
rmmod mcp251x;modprobe mcp251x

@msperl
Copy link
Contributor

msperl commented Jun 15, 2015

There is an issue upstream that could be the root-cause...
As a workaround it might be sufficient to add:
cs-gpios=<&gpio 8 1> <&gpio 7 1>;
(Or similar) to the spi device in dt to set up CS-gpio immediately and not when the device is probed first...
(That would also remove those warnings)

@pelwell
Copy link
Contributor

pelwell commented Jun 15, 2015

@petit-miner Which kernel are you using? The 3.18 tree is still using the bcm2708-spi driver, while the 4.0 tree has switched to the upstreamed bcm2835-spi driver.

@petit-miner
Copy link
Author

@msperl It would be very nice if you make a short tutorial for me and tell me which kernel version you are using.
That would help me a lot.

@msperl
Copy link
Contributor

msperl commented Jun 22, 2015

I am running my own build of the kernel based on the 4.0 (otherwise i can not create patches), so you will have to do that as well if you want to use the latest driver.

Note that the foundation seems to be moving to 4.0 already, as their kernel default branch is 4.0.y now...

Besides that you will also need to create a new overlay for can1 by copying:
https://github.com/raspberrypi/linux/blob/rpi-4.0.y/arch/arm/boot/dts/overlays/mcp2515-can0-overlay.dts

and replacing:

  • can0 with can1
  • spidev0 with spidev1
  • default interrupt lines
  • reg = <0> with reg = <1>

then compile it with dtc (say as mcp2515-can1-overlay) and then you can load it as well via /boot/config.txt...

@pelwell
Copy link
Contributor

pelwell commented Jun 22, 2015

@petit-miner If you do this and can verify that it works (not that I'm doubting you, @msperl) then we can add the new overlay to the standard distributions.

@petit-miner
Copy link
Author

I am a little bit confused, there are 2 Kernels one for the PI B+ and the PI 2.
Where is the Kernel sourcecode for the PI 2?
But the self build new Kernel isn't necessary?
And how I can compile the dts file?
or @msperl could you upload the .dtb to dropbox or something else that would be very nice.

@pelwell
Copy link
Contributor

pelwell commented Jun 22, 2015

The two kernels are built from the same source tree, using the same tools, but with a few differences in the configurations. For a Pi 1 we build using bcmrpi_defconfig, but for Pi 2 we use bcm2709_defconfig. See here for details.
You can compile the dts file either by adding it into the kernel source tree and using the included version of dtc, or by running:

sudo apt-get update
sudo apt-get install device-tree-compiler

Once this is done you just need to:

dtc -@ -I dts -O dtb -o mcp2515-can1-overlay.dtb mcp2515-can1-overlay.dts

You can find more documentation about Device Tree on the Pi here.

@petit-miner
Copy link
Author

Thank you for the Information 👍
I have to replace every can0 with can1 in the file and every spidev0?
What I have to change at the default interrupt lines?

@msperl
Copy link
Contributor

msperl commented Jun 22, 2015

well with the interrupt line you are using for the second controller - maybe use 24 or 26 as the second interrupt line... (you can override it anyway in config.txt via additional parameters)

@petit-miner
Copy link
Author

I think I made a mistake while editing the file,
it would be easier when you upload the file to dropbox or something else or post the content here.
I get this error:
001046.751: dterror: can't find symbol 'spi1'
001046.768: dtoverlay_merge_overlay('mcp2515-can1-overlay') failed - err 1

@msperl
Copy link
Contributor

msperl commented Jun 22, 2015

@pelwell: one point maybe: Is it possible to include the SAME overlay twice (but with distinct parameters)?
If so then we could modify the overlay to allow to add additional parameters.

example usage could be:

dtoverlay=mcp2515-canX-overlay,cs=0,oscillator=20000000,interrupt=25
dtoverlay=mcp2515-canX-overlay,cs=1,oscillator=16000000,interrupt=24

Which would create 2 can interfaces: can0 and can1 based on chipselect 0 and 1.

The downside obviously would be that you would need to add some code to the firmware parser to modify also the identifiers by some scheme (spidev0 translate to spidev1, can0 to can1, can0_osc to can1_osc, can0_pins to can1_pins...).

@petit-miner
Copy link
Author

That would be a great idea, but I am not a programmer. :/
But you said that it works with two MCP2515?

@pelwell
Copy link
Contributor

pelwell commented Jun 22, 2015

@petit-miner There is no spi1 - that should still say spi0, but the 0s in reg = <0> and mcp2515@0 should be changed to 1s.

@msperl There is nothing stopping an overlay being loaded twice, but as you have worked out the names of the nodes and properties can not be changed based on parameters. I understand that this can result in a proliferation of overlays, but I don't want to spend time on adding a slightly esoteric feature now when I could be working on dynamic Device Tree support.

@msperl
Copy link
Contributor

msperl commented Jun 22, 2015

I am fine with that - I just wanted to let you know that this could also be an option...

@pelwell
Copy link
Contributor

pelwell commented Jun 22, 2015

I understand, and suggestions are welcome. It sounds like something I could return to at a later date.

@msperl
Copy link
Contributor

msperl commented Jun 22, 2015

Side-note: Actually there is also spi1 and spi2 - the issue is that the foundation kernel does not have a driver yet and a patch to upstream a working driver has just been posted today...

@pelwell
Copy link
Contributor

pelwell commented Jun 22, 2015

I'll look forward to a PR...

@petit-miner
Copy link
Author

I am not at home, I can't test it out sorry.

@petit-miner
Copy link
Author

It works! 👍
How I can submit the source code?

pelwell pushed a commit that referenced this issue Jul 10, 2015
pelwell pushed a commit that referenced this issue Jul 10, 2015
@pelwell
Copy link
Contributor

pelwell commented Jul 10, 2015

I've pushed your patch to rpi-4.0.y and rpi-4.1.y. Thank you for your efforts.

@petit-miner
Copy link
Author

Ok, thanks for your help 👍

popcornmix added a commit to raspberrypi/firmware that referenced this issue Jul 13, 2015
kernel: w1_therm: Back-port locking improvements from 4.2-rc1
See: raspberrypi/linux#1059

kernel: Added support for 2 mcp2515 CAN Bus IC
See: raspberrypi/linux#1018

kernel: BCM270X_DT: Overlay for the Fen Logic VGA666 board
(really added this time)

firmware: di_adv: Add qpu shader code to implement deinterlace
firmware: image_fx: Support YUV_UV as destination format if requested
firmware: dmalib: Reduce default priority and burst size of 2d memcpy

arm_loader: Ensure reserved qpus are freed and ISR blocks until interrupt cleared

gpioman: If dt-blob.bin file is incompatible, use built-in
See: https://www.raspberrypi.org/forums/viewtopic.php?f=29&t=113753&start=75#p788079
neuschaefer pushed a commit to neuschaefer/raspi-binary-firmware that referenced this issue Feb 27, 2017
kernel: w1_therm: Back-port locking improvements from 4.2-rc1
See: raspberrypi/linux#1059

kernel: Added support for 2 mcp2515 CAN Bus IC
See: raspberrypi/linux#1018

kernel: BCM270X_DT: Overlay for the Fen Logic VGA666 board
(really added this time)

firmware: di_adv: Add qpu shader code to implement deinterlace
firmware: image_fx: Support YUV_UV as destination format if requested
firmware: dmalib: Reduce default priority and burst size of 2d memcpy

arm_loader: Ensure reserved qpus are freed and ISR blocks until interrupt cleared

gpioman: If dt-blob.bin file is incompatible, use built-in
See: https://www.raspberrypi.org/forums/viewtopic.php?f=29&t=113753&start=75#p788079
popcornmix pushed a commit that referenced this issue May 19, 2021
commit 784daf2 upstream.

The fstests test case generic/475 creates a dm-linear device that gets
changed to a dm-error device. This leads to errors in loading the block
group's zone information when running on a zoned file system, ultimately
resulting in a list corruption. When running on a kernel with list
debugging enabled this leads to the following crash.

 BTRFS: error (device dm-2) in cleanup_transaction:1953: errno=-5 IO failure
 kernel BUG at lib/list_debug.c:54!
 invalid opcode: 0000 [#1] SMP PTI
 CPU: 1 PID: 2433 Comm: umount Tainted: G        W         5.12.0+ #1018
 RIP: 0010:__list_del_entry_valid.cold+0x1d/0x47
 RSP: 0018:ffffc90001473df0 EFLAGS: 00010296
 RAX: 0000000000000054 RBX: ffff8881038fd000 RCX: ffffc90001473c90
 RDX: 0000000100001a31 RSI: 0000000000000003 RDI: 0000000000000003
 RBP: ffff888308871108 R08: 0000000000000003 R09: 0000000000000001
 R10: 3961373532383838 R11: 6666666620736177 R12: ffff888308871000
 R13: ffff8881038fd088 R14: ffff8881038fdc78 R15: dead000000000100
 FS:  00007f353c9b1540(0000) GS:ffff888627d00000(0000) knlGS:0000000000000000
 CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
 CR2: 00007f353cc2c710 CR3: 000000018e13c000 CR4: 00000000000006a0
 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
 DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
 Call Trace:
  btrfs_free_block_groups+0xc9/0x310 [btrfs]
  close_ctree+0x2ee/0x31a [btrfs]
  ? call_rcu+0x8f/0x270
  ? mutex_lock+0x1c/0x40
  generic_shutdown_super+0x67/0x100
  kill_anon_super+0x14/0x30
  btrfs_kill_super+0x12/0x20 [btrfs]
  deactivate_locked_super+0x31/0x90
  cleanup_mnt+0x13e/0x1b0
  task_work_run+0x63/0xb0
  exit_to_user_mode_loop+0xd9/0xe0
  exit_to_user_mode_prepare+0x3e/0x60
  syscall_exit_to_user_mode+0x1d/0x50
  entry_SYSCALL_64_after_hwframe+0x44/0xae

As dm-error has no support for zones, btrfs will run it's zone emulation
mode on this device. The zone emulation mode emulates conventional zones,
so bail out if the zone bitmap that gets populated on mount sees the zone
as sequential while we're thinking it's a conventional zone when creating
a block group.

Note: this scenario is unlikely in a real wold application and can only
happen by this (ab)use of device-mapper targets.

CC: [email protected] # 5.12+
Signed-off-by: Naohiro Aota <[email protected]>
Signed-off-by: Johannes Thumshirn <[email protected]>
Signed-off-by: David Sterba <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants