All of lore.kernel.org
 help / color / mirror / Atom feed
From: Fabio Baltieri <fabio.baltieri@gmail.com>
To: Oliver Hartkopp <socketcan@hartkopp.net>
Cc: Marc Kleine-Budde <mkl@pengutronix.de>,
	"Max S." <max@schneidersoft.net>,
	linux-can@vger.kernel.org
Subject: Re: usb-can device
Date: Wed, 29 Aug 2012 01:34:59 +0200	[thread overview]
Message-ID: <20120828233459.GA3046@gmail.com> (raw)
In-Reply-To: <503B1198.3010506@hartkopp.net>

Hello everyone,

On Mon, Aug 27, 2012 at 08:20:08AM +0200, Oliver Hartkopp wrote:
> > There is no standard driver, however I was thinking last week that
> > someone should write a CDC CAN driver. CDC Ethernet is a standard to
> > send ethernet frames over USB.
>
> Due to the lack of USB CAN Hardware, where i could implement my own firmware i
> thought about using http://www.8devices.com/product/2/usb2can which is pretty
> cheap and also provides schematics to be able to alter the firmware with it's
> onboard JTAG interface (see schematic):
> 
> http://www.8devices.com/uploads/downloads/usb2can.pdf
> 
> The idea is to bring the USB CAN interface as near as possible to the
> SocketCAN network interface:

Oliver, I developed an USB to CANBUS interface some months ago, that
I'm currently using for all my tests and developement.

I had the intention to release the full hardware, firmware and kernel
driver code, but I still have not had time to write a decent
documentation, a blog post, request proper USB IDs and design a rev2 -
anyway, as there seems to be some interest on the subject I pushed the
current design (hardware is in Eagle 6 format) on github at:

https://github.com/fabiobaltieri/open-usb-can

The hardware is currently based on an ATMega32U2 (yes, a 16MHz 8-bit
AVR) + MCP2515 as can controller, not exactly the best performing
hardware but really cheap and easy to hack.  Also, there are mounting
options for both normal and isolated transceiver (using an ADM3053,
should come cheaper and smaller than isolator + dc/dc + normal xcvr).

The USB stack is based on Werner Almesberger's ben-wpan code, which is
lightweight and clean, while the kernel driver is based on code from
ems_usb and esd_usb2.

In my test this design seems to perform quite well with busses up to
250kbps, and I also used it on my Toyota's 500kbps bus with very few rx
overruns.

So, this is probabily not the best bust sniffer in the world, but should
be ok for protocol development and testing.

The USB protocol I implemented at the time share some of your ideas (the
code is in the kernel-module directory):

> - send struct can_frames
> - receive struct can_frames (for instant CAN data forwarding)

I'm using a packed version of struct can_frame, that was to save some
bytes in USB messages and MCU's memory but should not really make a big
difference.

> - receive struct can_frames (for instant CAN error messages(!) forwarding)

Got it! No difference between normal and error frames in my kernel
driver.  The firmware speaks socketcan! (I stole some headers :-) )

> - send an endian pattern inside the USB URB (*1)

That should be easy to implement... sure it makes sense to do that in
the USB controller rather than the host?  That's just a le32_to_cpu per
packet...

> - send skb->sk pointers along with CAN data (*2)

That's to be implemented, I'm echoing from tx URB callback as ems, but I
have a buffer status pointer and two spare bytes in the rx message which
may be used to implement a better echo strategy.

> - define a simple interface for open/close/bitrate-setting

I'm using just some control requests for CAN_START and CAN_STOP and a
dedicated CAN_PUT_CONFIG with a specific struct open_usb_can_config for
configuration which is basically a subset of struct can_bittiming using
8-bit fields.

Oliver, Marc, do you think that this design my be used as a base to do
some generic USB-CAN (CDC CAN?) protocol development?  I would be happy
to help!

Max, does this helps you with the design?  I understand that you are
using some other Atmel MCUs... maybe you can directly re-use part of the
code.

Fabio

  parent reply	other threads:[~2012-08-28 23:35 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-26 15:52 usb-can device Max S.
2012-08-26 16:28 ` Marc Kleine-Budde
2012-08-27  6:20   ` Oliver Hartkopp
     [not found]     ` <20120827081028.GA417@vandijck-laurijssen.be>
2012-08-27  9:05       ` Marc Kleine-Budde
     [not found]     ` <1346071259.3928.33.camel@slaptop>
2012-08-28 11:58       ` Oliver Hartkopp
2012-08-28 12:13         ` Marc Kleine-Budde
2012-08-28 12:18           ` Oliver Hartkopp
2012-08-28 12:20             ` Marc Kleine-Budde
2012-08-28 14:30     ` Max S.
2012-08-29 10:55       ` Oliver Hartkopp
2012-08-28 23:34     ` Fabio Baltieri [this message]
2012-08-29 11:02       ` Oliver Hartkopp
2012-09-09 13:41         ` Pavel Pisa

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20120828233459.GA3046@gmail.com \
    --to=fabio.baltieri@gmail.com \
    --cc=linux-can@vger.kernel.org \
    --cc=max@schneidersoft.net \
    --cc=mkl@pengutronix.de \
    --cc=socketcan@hartkopp.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.