Skip to content
Permalink
Browse files

drivers: can: mcp2515: Add driver for MCP2515 CAN controller

The MCP2515 is a CAN controller that can be connected via SPI to an
host MCU. This driver adds support for the MCP2515 as a new driver in
the CAN subsystem.
As it is a SPI peripheral it uses a thread for its interrupt
handling and the received message filtering is done inside this
interrupt thread, as the MCP2515 filter capabilities are not sufficient
for the Zephyr CAN interface.
The driver was validated with an external CAN logger and the adjusted
CAN sample application.

Signed-off-by: Karsten Koenig <karsten.koenig.030@gmail.com>
  • Loading branch information...
karstenkoenig authored and nashif committed Jun 12, 2018
1 parent b8774ae commit 35b930848801089b6f00ae9f78ebaea9dd325430
Showing with 933 additions and 2 deletions.
  1. +1 −0 CODEOWNERS
  2. +3 −2 drivers/can/CMakeLists.txt
  3. +1 −0 drivers/can/Kconfig
  4. +138 −0 drivers/can/Kconfig.mcp2515
  5. +639 −0 drivers/can/mcp2515.c
  6. +131 −0 drivers/can/mcp2515.h
  7. +20 −0 dts/bindings/can/mcp,mcp2515.yaml
@@ -106,6 +106,7 @@
/drivers/adc/ @anangl
/drivers/bluetooth/ @sjanc @jhedberg @Vudentz
/drivers/can/ @alexanderwachter
/drivers/can/*mcp2515* @karstenkoenig
/drivers/clock_control/*stm32f4* @rsalveti @idlethread
/drivers/counter/ @nordic-krch
/drivers/display/ @vanwinkeljan
@@ -1,4 +1,5 @@
# SPDX-License-Identifier: Apache-2.0

zephyr_sources_ifdef(CONFIG_CAN_STM32 stm32_can.c)
zephyr_sources_ifdef(CONFIG_USERSPACE can_handlers.c)
zephyr_sources_ifdef(CONFIG_CAN_STM32 stm32_can.c)
zephyr_sources_ifdef(CONFIG_CAN_MCP2515 mcp2515.c)
zephyr_sources_ifdef(CONFIG_USERSPACE can_handlers.c)
@@ -36,5 +36,6 @@ config CAN_1
Enable CAN controller 1

source "drivers/can/Kconfig.stm32"
source "drivers/can/Kconfig.mcp2515"

endif # CAN
@@ -0,0 +1,138 @@
# Kconfig.mcp2515 - MCP2515 CAN configuration options

#
# Copyright (c) 2018 Karsten Koenig
#
# SPDX-License-Identifier: Apache-2.0
#

config CAN_MCP2515
bool "MCP2515 CAN Driver"
depends on SPI
help
Enable MCP2515 CAN Driver

if CAN_MCP2515

config CAN_MCP2515_NAME
string "Driver name"
default "MCP2515"

config CAN_MCP2515_OSC_FREQ
int "Oscillator frequency"
default 8000000
help
Specify the frequency of the oscillator connected to the MCP2515.

config CAN_PROP_SEG
int "Prop_Seg"
default 2
range 1 8
help
Time quantums of propagation segment (ISO 11898-1)

config CAN_PHASE_SEG1
int "Phase_Seg1"
default 7
range 1 8
help
Time quantums of phase buffer 1 segment (ISO 11898-1)

config CAN_PHASE_SEG2
int "Phase_Seg2"
default 6
range 2 8
help
Time quantums of phase buffer 2 segment (ISO 11898-1)

config CAN_SJW
int "SJW"
default 1
range 1 4
help
Resynchronization jump width (ISO 11898-1)

config CAN_MCP2515_SPI_PORT_NAME
string "SPI device where MCP2515 is connected"
default "SPI_1"
help
Specify the device name of the SPI device to which MCP2515 is
connected.

config CAN_MCP2515_SPI_SLAVE
int "SPI Slave Select where MCP2515 is connected"
default 1
help
Specify the slave select pin of the SPI to which MCP2515 is
connected.

config CAN_MCP2515_SPI_FREQ
int "SPI frequency to use with MCP2515"
default 1000000
help
SPI frequency to use with MCP2515

config CAN_MCP2515_INT_PORT_NAME
string "INT GPIO controller port name"
default "GPIO_0"
help
GPIO port where INT is connected.

config CAN_MCP2515_INT_PIN
int "INT GPIO pin"
default 19
help
GPIO pin where INT is connected.

config CAN_MCP2515_INT_THREAD_STACK_SIZE
int "Stack size for interrupt handler"
default 512
help
Size of the stack used for internal thread which is ran for
interrupt handling and incoming packets.

config CAN_MCP2515_INT_THREAD_PRIO
int "Priority for interrupt handler"
default 2
help
Priority level of the internal thread which is ran for
interrupt handling and incoming packets.

config CAN_MCP2515_GPIO_SPI_CS
bool "Manage SPI CS through a GPIO pin"
help
This option is useful if one needs to manage SPI CS through a GPIO
pin to by-pass the SPI controller's CS logic.

if CAN_MCP2515_GPIO_SPI_CS
config CAN_MCP2515_SPI_CS_PORT_NAME
string "GPIO driver's name to use to drive SPI CS through"
help
This option is mandatory to set which GPIO controller to use in
order to actually emulate the SPI CS.

config CAN_MCP2515_SPI_CS_PIN
int "GPIO PIN to use to drive SPI CS through"
default 0
help
This option is mandatory to set which GPIO pin to use in order
to actually emulate the SPI CS.

endif #CAN_MCP2515_GPIO_SPI_CS

config CAN_MCP2515_MAX_FILTER
int "Maximum number of concurrent active filters"
default 5
range 1 32
help
Defines the array size of the callback/msgq pointers.
Must be at least the size of concurrent reads.


config CAN_MCP2515_INIT_PRIORITY
int "Init priority"
default 80
help
MCP2515 driver initialization priority, must be higher than SPI.

endif # CAN_MCP2515

0 comments on commit 35b9308

Please sign in to comment.
You can’t perform that action at this time.