(for mcp2515 controller like the PiCAN2)
-
fork (or clone)
nerves_system_rpi3locally into the parent directory of your project -
edit
mix.exsand change thenerves_system_rpi3lines to point to your local one:def system("rpi3"), do: [{:nerves_system_rpi3, path: "../nerves_system_rpi3", runtime: false}] -
mix deps.get -
mkdir config/rpi3to set up a place to store some customized rpi configs -
copy over
fwup.confandconfig.txtfrom your localnerves_system_rpi3repocp ../nerves_system_rpi3/fwup.conf config/rpi3/fwup.conf cp ../nerves_system_rpi3/config.txt config/rpi3/config.txt -
in
config/config.exspoint nerves at newfwup.conffile:config :nerves, :firmware, fwup_conf: "config/rpi3/fwup.conf" -
edit
config/rpi3/fwup.confto include the additional overlays needed, by default themcp2515-can0overlay is not included in the base image. insidefwup.confnotice how the the overlay is set up forw1-gpio-pullupand use that as a pattern for adding our new overlay. search for all the lines containingw1-gpio-pullup, this will get you oriented for how the overlay is defined and then copied to each partition. You will need to do the same for themcp2515-can0overlay. There are four lines to add.-
set up a new file resource definition (around line 117) by adding:
file-resource mcp2515-can0.dtbo { host-path = "${NERVES_SYSTEM}/images/rpi-firmware/overlays/mcp2515-can0.dtbo" }
-
write the overlay file inside the
task completeblock (add around line 212) with all the otheron-resourcelines:on-resource mcp2515-can0.dtbo { fat_write(${BOOT_A_PART_OFFSET}, "overlays/mcp2515-can0.dtbo") }
-
do the same inside the
task upgrade.ablock (around line 268):on-resource mcp2515-can0.dtbo { fat_write(${BOOT_A_PART_OFFSET}, "overlays/mcp2515-can0.dtbo") }
-
finally, add an on-resource line for
task upgrade.b(around line 328), note that the variable used infat_writeis different than for the previous steps:on-resource mcp2515-can0.dtbo { fat_write(${BOOT_B_PART_OFFSET}, "overlays/mcp2515-can0.dtbo") }
-
-
inside
config/rpi3/fwup.conffind thefile-resourcedefinition forconfig.txtand change it to point at the one you copied intoconfig/rpi3/config.txtfile-resource config.txt { host-path = "${NERVES_APP}/config/rpi3/config.txt" } -
edit
config/rpi3/config.txtand define the mcp2515 overlay by adding:dtoverlay=mcp2515-can0,oscillator=16000000,interrupt=25 -
Inside your project directory:
mix nerves.system.shelland when that loads, do the following:-
configure the kernel:
mix linux-menuconfig- Networking support -> <*> CAN bus subsystem support
- Networking support -> CAN bus subsystem support -> CAN Device Drivers -> CAN SPI interfaces -> <*> Microchip MCP251x SPI CAN controllers
- Select <SAVE>
- Select <EXIT> as many times as needed until you are dropped back in the nerves system shell
-
safe the kernel config:
make linux-savedefconfig -
IMPORTANT: you need to copy the newly saved kernel defconfig back into the rpi3 system using something like:
cp build/linux-04c8e47067d4873c584395e5cb260b4f170a99ea/defconfig /nerves/env/nerves_system_rpi3/linux-4.4.defconfig -
OPTIONAL: add usefull can-related packages:
mix menuconfig- Target packages -> Networking applications -> iproute2
- Target packages -> Networking applications -> can-utils
- Select <SAVE>
- Select <Exit> until you are dropped back to shell
-
save the package config:
make savedefconfig -
exitto leave nerves.system.shell
-
-
mix compileNOTE: this will take forever the first time. on my four year old macbook pro this took about 4 hours -
mix firmware -
then depending on your project setup:
mix firmware.burn/mix firmware.push ...
with any luck, you should now have a can0 device listed in /proc/net/dev on your rpi3.
to pop into something similar to a console shell, run Nerves.Runtime.Shell.start from the iex prompt. From here you can do handy things like:
cat /proc/net/dev
and
ip link set can0 up type can bitrate 250000 (substitute 250000 with whatever bitrate you need for your vehicle)