Commit 4aeea753 authored by Henrik Brix Andersen's avatar Henrik Brix Andersen Committed by Carles Cufi
Browse files

samples: canbus: canopen: add program download support



Add optional program download support to the CANopen sample.

Signed-off-by: default avatarHenrik Brix Andersen <hebad@vestas.com>
parent 3c2984d4
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -16,3 +16,4 @@ board_runner_args(pyocd "--target=k64f")
include(${ZEPHYR_BASE}/boards/common/pyocd.board.cmake)
include(${ZEPHYR_BASE}/boards/common/jlink.board.cmake)
include(${ZEPHYR_BASE}/boards/common/openocd.board.cmake)
include(${ZEPHYR_BASE}/boards/common/canopen.board.cmake)
+1 −0
Original line number Diff line number Diff line
@@ -16,3 +16,4 @@ board_runner_args(pyocd "--target=ke18f16")
include(${ZEPHYR_BASE}/boards/common/pyocd.board.cmake)
include(${ZEPHYR_BASE}/boards/common/jlink.board.cmake)
include(${ZEPHYR_BASE}/boards/common/openocd.board.cmake)
include(${ZEPHYR_BASE}/boards/common/canopen.board.cmake)
+4 −0
Original line number Diff line number Diff line
@@ -2,6 +2,10 @@

cmake_minimum_required(VERSION 3.13.1)

macro(app_set_runner_args)
  board_runner_args(canopen "--node-id=${CONFIG_CANOPEN_NODE_ID}")
endmacro()

find_package(Zephyr HINTS $ENV{ZEPHYR_BASE})
project(CANopen)

+52 −1
Original line number Diff line number Diff line
@@ -15,7 +15,7 @@ CANopen protocol stack.

Apart from the CANopen protocol stack integration, this sample also
demonstrates the use of non-volatile storage for the CANopen object
dictionary.
dictionary and optionally program download over CANopen.

Requirements
************
@@ -327,6 +327,57 @@ Running the above Python code should produce the following output:
   Button press counter: 9
   Button press counter: 10

Testing CANopen Program Download
********************************

Building and Running for FRDM-K64F
==================================
The sample can be rebuilt with MCUboot and program download support
for the FRDM-K64F as follows:

#. Build and flash MCUboot by following the instructions in the
   :ref:`mcuboot` documentation page.

#. Rebuild the CANopen sample with MCUboot support:

   .. zephyr-app-commands::
      :zephyr-app: samples/subsys/canbus/canopen
      :board: frdm_k64f
      :goals: build
      :gen-args: -DCONFIG_BOOTLOADER_MCUBOOT=y
      :compact:

#. Sign the newly rebuilt CANopen sample binary (using either the
   demonstration-only RSA key from MCUboot or any other key used when
   building MCUboot itself):

   .. code-block:: console

      west sign -t imgtool --bin --no-hex -- --key mcuboot/root-rsa-2048.pem \
              --version 1.0.0

#. Flash the newly signed CANopen sample binary using west:

   .. code-block:: console

      west flash --skip-rebuild --bin-file zephyr/zephyr.signed.bin

#. Confirm the newly flashed firmware image using west:

   .. code-block:: console

      west flash --skip-rebuild --runner canopen --confirm-only

#. Finally, resign the CANopen sample binary with a new version number
   and perform a program download over CANopen:

   .. code-block:: console

      west sign -t imgtool --bin --no-hex  -- --key mcuboot/root-rsa-2048.pem \
              --version 1.0.1
      west flash --skip-rebuild --bin-file zephyr/zephyr.signed.bin \
              --runner canopen

Modifying the Object Dictionary
*******************************
The CANopen object dictionary used in this sample application can be
+9 −1
Original line number Diff line number Diff line
@@ -74,6 +74,10 @@ struct sCO_OD_RAM CO_OD_RAM = {
/*1003*/ { 0, 0, 0, 0, 0, 0, 0, 0 },
/*1010*/ { 0x00000003 },
/*1011*/ { 0x00000001 },
/*1f50*/ { 0 },
/*1f51*/ { 0x0L },
/*1f56*/ { 0x0000L },
/*1f57*/ { 0x0000L },
/*2100*/ { 0x0L, 0x0L, 0x0L, 0x0L, 0x0L, 0x0L, 0x0L, 0x0L, 0x0L, 0x0L },
/*2102*/ 0x0000L,

@@ -275,7 +279,7 @@ struct sCO_OD_EEPROM CO_OD_EEPROM = {
/*******************************************************************************
   OBJECT DICTIONARY
*******************************************************************************/
const CO_OD_entry_t CO_OD[41] = {
const CO_OD_entry_t CO_OD[45] = {

	{ 0x1000, 0x00, 0x85, 4, (void *)&CO_OD_ROM.deviceType },
	{ 0x1001, 0x00, 0x26, 1, (void *)&CO_OD_RAM.errorRegister },
@@ -314,6 +318,10 @@ const CO_OD_entry_t CO_OD[41] = {
	{ 0x1a01, 0x08, 0x00, 4, (void *)&OD_record1a01 },
	{ 0x1a02, 0x08, 0x00, 0, (void *)&OD_record1a02 },
	{ 0x1a03, 0x08, 0x00, 0, (void *)&OD_record1a03 },
	{ 0x1f50, 0x01, 0x0a, 0, (void *)0 },
	{ 0x1f51, 0x01, 0x0e, 1, (void *)&CO_OD_RAM.programControl[0] },
	{ 0x1f56, 0x01, 0x86, 4, (void *)&CO_OD_RAM.programSoftwareIdentification[0] },
	{ 0x1f57, 0x01, 0x86, 4, (void *)&CO_OD_RAM.flashStatusIdentification[0] },
	{ 0x1f80, 0x00, 0x8d, 4, (void *)&CO_OD_ROM.NMTStartup },
	{ 0x2100, 0x00, 0x26, 10, (void *)&CO_OD_RAM.errorStatusBits },
	{ 0x2101, 0x00, 0xa7, 4, (void *)&CO_OD_EEPROM.powerOnCounter },
Loading