I have connected PICAN to a ECU Simulator, for which I'm pretty sure I can at-least get the response for (cansend can0 7DF#0201050000000000). Another weird things is that same setup worked really well a week back and then suddenly (after some cleanup un-related) things have stopped working.pin 25 (gpio25) function gpio_in in lo; irq 505 (edge-falling)
Finally this is my complete IRQ setup, starting from 480.dtparam=spi=on
dtoverlay=mcp2515-can0-overlay,oscillator=16000000,interrupt=25
dtoverlay=spi-bcm2835-overlay
# cat pins
registered pins: 54
pin 0 (gpio0) function gpio_in in hi; irq 480 (none)
pin 1 (gpio1) function gpio_in in hi; irq 481 (none)
pin 2 (gpio2) function gpio_in in hi; irq 482 (none)
pin 3 (gpio3) function gpio_in in hi; irq 483 (none)
pin 4 (gpio4) function gpio_in in hi; irq 484 (none)
pin 5 (gpio5) function gpio_in in hi; irq 485 (none)
pin 6 (gpio6) function gpio_in in hi; irq 486 (none)
pin 7 (gpio7) function alt0 in hi; irq 487 (none)
pin 8 (gpio8) function alt0 in hi; irq 488 (none)
pin 9 (gpio9) function alt0 in lo; irq 489 (none)
pin 10 (gpio10) function alt0 in lo; irq 490 (none)
pin 11 (gpio11) function alt0 in lo; irq 491 (none)
pin 12 (gpio12) function gpio_in in lo; irq 492 (none)
pin 13 (gpio13) function gpio_in in lo; irq 493 (none)
pin 14 (gpio14) function alt0 in hi; irq 494 (none)
pin 15 (gpio15) function alt0 in hi; irq 495 (none)
pin 16 (gpio16) function gpio_in in lo; irq 496 (none)
pin 17 (gpio17) function gpio_in in lo; irq 497 (none)
pin 18 (gpio18) function gpio_in in lo; irq 498 (none)
pin 19 (gpio19) function gpio_in in lo; irq 499 (none)
pin 20 (gpio20) function gpio_in in lo; irq 500 (none)
pin 21 (gpio21) function gpio_in in lo; irq 501 (none)
pin 22 (gpio22) function gpio_in in lo; irq 502 (none)
pin 23 (gpio23) function gpio_in in hi; irq 503 (none)
pin 24 (gpio24) function gpio_in in hi; irq 504 (none)
pin 25 (gpio25) function gpio_in in lo; irq 505 (edge-falling)
pin 26 (gpio26) function gpio_in in lo; irq 506 (none)
pin 27 (gpio27) function gpio_in in lo; irq 507 (none)
pin 28 (gpio28) function gpio_in in hi; irq 508 (none)
pin 29 (gpio29) function gpio_in in hi; irq 509 (none)
pin 30 (gpio30) function gpio_in in lo; irq 510 (none)
Foundation kernels are the ones that come with rpi-update - i would test with those as these are known to work with the device tree overlays.chintan09 wrote:Interesting to know about differences in IRQ, don't know where this differences come from.
One question, when you say stock kernel, what image you exactly mean. I thought using rpi-3.18.y kernel is a stock image. If not, could you please point to a working image in your opinion and I can directly use them and give a try.
Code: Select all
dtparam=spi=on
dtoverlay=mcp2515-can0-overlay,oscillator=20000000,interrupt=25
dtoverlay=spi-bcm2835-overlay
Code: Select all
mcp251x spi0.0: unable to set initial baudrate!
mcp251x spi0.0: can0: bit-timing not yet defined
Code: Select all
mcp251x spi0.0: CNF: 0x03 0xb5 0x01
the status (viapier1999 wrote: Note the 20 MHz oscillator which is the freq of my can device.
The problem is that when I show the status of can interface it shows a clock of 8000000 which is the value of the default value and which means that ‘oscillator=20000000’ parameter isn’t picked up.
Code: Select all
ip -d -s link show can0
these are actually warnings that you have not set up the bitrate of the interface yet - you need to runpier1999 wrote: The result is that I always get these errors:Code: Select all
mcp251x spi0.0: unable to set initial baudrate! mcp251x spi0.0: can0: bit-timing not yet defined
Code: Select all
/sbin/ip link set can0 up type can bitrate 500000
This does no longer show up with the newer kernels - the "bit-timing not yet defined" now indicates that the device has been identified correctly and the device is ready to configure/use.pier1999 wrote: and never gotCode: Select all
mcp251x spi0.0: CNF: 0x03 0xb5 0x01
One more thing, when I runpier1999 wrote:Thanks for the reply.
When I bring the interface up, messages about the missing baudrate disappear and the interface status is ERROR-ACTIVE (which I learnt from the previous setup is the right status) .
As soon as I try to send a message or there is a message waiting to be read, I get 2 error frames and the status of the interface turns to ERROR-PASSIVE. The clock value I read from the interface status is 8000000 and not the expected 10000000 for a 20Mhz oscillator.
Regards, Pier
Code: Select all
vcdbg log msg
Code: Select all
005069.580: dtparam: i2c_arm=on
005071.646: dtparam: spi=on
005079.598: Loaded overlay 'spi-bcm2835-overlay'
005087.423: Loaded overlay 'mcp2515-can0-overlay'
005103.762: dtparam: oscillator=20000000
005105.854: dtparam: interrupt=25
Code: Select all
oscillator = <&can0_osc>,"oscillator-frequency";
Code: Select all
oscillator = <&can0_osc>,"clock-frequency";
Where can I find such patch?msperl wrote:if you wire the RX0BF and RX1BF pins (10 and 11) of the mcp2515 to some GPIOs on the rpi then - with the corresponding patch to the driver you can reduce latencies by about 20us
Code: Select all
diff --git a/drivers/net/can/spi/mcp251x.c b/drivers/net/can/spi/mcp251x.c
index bf63fee..78014a9 100644
--- a/drivers/net/can/spi/mcp251x.c
+++ b/drivers/net/can/spi/mcp251x.c
@@ -70,6 +70,7 @@
#include <linux/module.h>
#include <linux/netdevice.h>
#include <linux/of.h>
+#include <linux/of_gpio.h>
#include <linux/of_device.h>
#include <linux/platform_device.h>
#include <linux/slab.h>
@@ -198,6 +199,13 @@
#define RXMSIDL(n) ((n) * 4 + 0x21)
#define RXMEID8(n) ((n) * 4 + 0x22)
#define RXMEID0(n) ((n) * 4 + 0x23)
+#define BFPCTRL 0x0c
+# define BFPCTRL_B0BFM 0x01
+# define BFPCTRL_B1BFM 0x02
+# define BFPCTRL_B0BFE 0x04
+# define BFPCTRL_B1BFE 0x08
+# define BFPCTRL_B0BFS 0x10
+# define BFPCTRL_B1BFS 0x20
#define GET_BYTE(val, byte) \
(((val) >> ((byte) * 8)) & 0xff)
@@ -269,6 +277,8 @@ struct mcp251x_priv {
struct regulator *power;
struct regulator *transceiver;
struct clk *clk;
+
+ int gpio_rx[2];
};
#define MCP251X_IS(_model) \
@@ -557,6 +567,20 @@ static int mcp251x_set_normal_mode(struct spi_device *spi)
{
struct mcp251x_priv *priv = spi_get_drvdata(spi);
unsigned long timeout;
+#ifdef CONFIG_GPIOLIB
+ u8 data;
+#endif
+
+#ifdef CONFIG_GPIOLIB
+ /* set output PINS for RX0/RX1 with the correct function */
+ data = 0;
+ if (gpio_is_valid(priv->gpio_rx[0]))
+ data |= BFPCTRL_B0BFM | BFPCTRL_B0BFE;
+ if (gpio_is_valid(priv->gpio_rx[1]))
+ data |= BFPCTRL_B1BFM | BFPCTRL_B1BFE;
+ if (data)
+ mcp251x_write_reg(spi, BFPCTRL, data);
+#endif
/* Enable interrupts */
mcp251x_write_reg(spi, CANINTE,
@@ -639,7 +663,7 @@ static int mcp251x_hw_reset(struct spi_device *spi)
/* Wait for oscillator startup timer after reset */
mdelay(MCP251X_OST_DELAY_MS);
-
+
reg = mcp251x_read_reg(spi, CANSTAT);
if ((reg & CANCTRL_REQOP_MASK) != CANCTRL_REQOP_CONF)
return -ENODEV;
@@ -812,6 +836,26 @@ static irqreturn_t mcp251x_can_ist(int irq, void *dev_id)
u8 clear_intf = 0;
int can_id = 0, data1 = 0;
+#ifdef CONFIG_GPIOLIB
+ /* check the gpios and handle the receive messages
+ * as quickly as possible
+ */
+ if (gpio_is_valid(priv->gpio_rx[0]) &&
+ (gpio_get_value(priv->gpio_rx[0]) == 0)) {
+ mcp251x_hw_rx(spi, 0);
+ if (mcp251x_is_2510(spi))
+ mcp251x_write_bits(spi, CANINTF,
+ CANINTF_RX0IF, 0x00);
+ }
+ if (gpio_is_valid(priv->gpio_rx[1]) &&
+ (gpio_get_value(priv->gpio_rx[1]) == 0)) {
+ mcp251x_hw_rx(spi, 0);
+ if (mcp251x_is_2510(spi))
+ mcp251x_write_bits(spi, CANINTF,
+ CANINTF_RX1IF, 0x00);
+ }
+#endif
+
mcp251x_read_2regs(spi, CANINTF, &intf, &eflag);
/* mask out flags we don't care about */
@@ -1093,6 +1137,16 @@ static int mcp251x_can_probe(struct spi_device *spi)
goto out_clk;
}
+#ifdef CONFIG_GPIOLIB
+ if (spi->dev.of_node) {
+ priv->gpio_rx[0] = of_get_gpio(spi->dev.of_node, 0);
+ priv->gpio_rx[1] = of_get_gpio(spi->dev.of_node, 1);
+ } else {
+ priv->gpio_rx[0] = -ENOENT;
+ priv->gpio_rx[1] = -ENOENT;
+ }
+#endif
+
ret = mcp251x_power_enable(priv->power, 1);
if (ret)
goto out_clk;
Code: Select all
gpios = <&gpio X 0>, <&gpio Y 0>;
What improvement has kernel version 4.0 or later? Is this patch will be included in kernel 4.0?msperl wrote: But for all practical purposes you should be using kernel version 4.0 or later, as only this has one improvement that helps more that that "small" patch here...
4.0 contains an improvement that improves speed of spi_sync calls when the spi-bus driver use a newer driver model (which the bcm2835 does).MrBool wrote:msperl, thank you very much for reply.
What improvement has kernel version 4.0 or later? Is this patch will be included in kernel 4.0?
Well - If you have GPIOs that are unused (and would remain that way) then you may want to add a wire for them to those pins - just add a pullup and prepare to connect it via a 0Ohm resistor.MrBool wrote: I'm designing now my board for compute module and I don't know is it good idea to connect signals RX0BF and RX1BF to GPIOs?