The Open Source Real-time Ethernet on Raspberry Pi 2 article would have given a good idea on running the POWERLINK on Raspberry Pi2 using pre-build binaries. Now let us see how to build our own POWERLINK binaries and also access the raspberry Pi 2 GPIO’s using POWERLINK application.

Follow the below steps to compile, build, run openPOWERLINK on Raspberry Pi2.

1. Download and install dependencis

On Windows PC

  • Download the following packages and copy it into your USB thumb drive

  • openPOWERLINK source-code

 

On Raspberry Pi 2 (On all the three boards)

Connect the USB thumb drive into the Raspberry Pi2 board and follow the instructions given below:

  • Open the terminal (you can use the short cut key “ctrl + alt + t”)

  • Mount the USB thumb drive as highlighted in the below screen shot

  • Create a directory “oplk_Pi2” in the path /home/linaro as highlighted in the below screen shot

    • Command – sudo mkdir /home/linaro/oplk_Pi2

  • Copy the packages from the USB thumb drive into the Raspberry Pi 2’s directory (/home/linaro/oplk_Pi2)

    • Command – sudo cp -R * /home/linaro/oplk_Pi2

  • Change administrative privileges to the oplk_Pi2 folder

    • Command – sudo chmod -R +x /home/linaro/oplk_Pi2

  • Navigate to the oplk_Pi2 folder

    • Command – cd /home/linaro/oplk_Pi2

  • Now list all the folders using “ls” command as highlighted in the below screen shot:

  • Now extract the downloaded packages one by one and install them as shown below:

    • To install Libpcap

      • Command – tar -xvf Install_pcap.sh.tar.gz

      • Command – sudo ./Install_pcap.sh

  • To install Cmake-gui

    • Command – sudo ./Install_cmake.sh

2. Create a openCONFIGURATOR project
    • Open the openCONFIGURATOR tool from your start menu
    • Once the application is loaded, select “Open Existing Project” and click ‘Ok’

    • Navigate to the path ‘C:/openPOWERLINK/apps/common/openCONFIGURATOR_projects/Demo_3CN’ and double click on ‘Demo_3CN.xml’

    • Now the project wil be imported to the tool with three CN configuration
    • The cycle time is set to 50000us by default as shown below

    • Click on CN_1(1) and change the Pollresponse timeout to 300us as shown below

    • Click on CN_2(32) and change the Pollresponse timeout to 400us as shown below

  • Simillarly click on CN_3(110) and change the Pollresponse timeout to 500us as shown below:

Note: The CN_3(110) will not be used in the POWERLINK network and can be used by the user in future

    • Click on the TPDO-00 of the CN_1(1) and you will find 1 byte of object mapped to the TPDO by default

    • Click on the RPDO-00 of the CN_1(1) and you will find the 1 byte of object mapped to the RPDO by default

Simillarly you can find the TPDO and RPDO being mapped to 1 byte for the CN_2(32) and CN_3(110) also.

    • These mappings will be reflected to the MN’s PDO as well
    • In the below screen shot, you can find the MN’s TPDO-00 being mapped with 1 byte for the CN_1(1) and MN’s TPDO-01 being mapped with 1 byte for the CN_2(32)


    • Once the configurations and mapping are done, the project can be built by pressing ‘F7’ or as shown below

    • Once you click the build project, an autogenerate window will pop up. Click ‘yes’ to continue to build the project

    • Once the project is built successfully, the output files will be generated at the location ‘C:/openPOWERLINK/apps/common/openCONFIGURATOR_projects/Demo_3CN/output’. Refer to info log at the bottom of the tool

    • Now navigate to the output path of the generated files and copy the ‘xap.h’ file

    • Replace the copied ‘xap.h’ file from the path ‘C:/openPOWERLINK/apps/demo_mn_console/src’

  • Note: The ‘mnobd.cdc’ can be invoked directly from any path while running the demo application and so there is no need to replace the CDC
3. Compile and build MN

The demo uses three Raspberry Pi2 boards, one acting as the network master (POWERLINK Managing Node / MN) and the other two as network slaves (POWERLINK Controlled Node / CN). List of hardware needed:

Step 1:

File name: “linux.cmake”

Path: “/home/linaro/oplk_Pi2/openPOWERLINK/apps/demo_mn_console”

Description: Include the wiring Pi library to the openPOWERLINK make file.

To download the modified file, click here

compile and build MN

Step 2:

File name: “app.c”

Path: “/home/linaro/oplk_Pi2/openPOWERLINK/apps/demo_mn_console”

Description: Include the “wiring Pi” header to app.c

To download the modified file, click here

compile and build MN

Step 3:

File name: “app.c”

Path: “/home/linaro/oplk_Pi2/openPOWERLINK/apps/demo_mn_console”

Description: Call the wiring Pi setup function to make GPIO Header Pin 17 as DigitalInput (Here Pin 0 is re-mapped as GPIO Header Pin 17)

To download the modified file, click herecompile and build MN

Step 4:

File name: “app.c”

Path: “/home/linaro/oplk_Pi2/openPOWERLINK/apps/demo_mn_console”

Description: If the input provided to GPIO Header Pin 17 is HIGH, then data with value 1 is processed as PDO to Slave 1 and 32 else 0 is processed.

compile and build MN

Once the code changes are completed, the openPOWERLINK source code can be compiled as follows,

Building Stack libraries:

  • open terminal and type in cmake-gui. A user interface dialog box opens

compile and build MN

compile and build MN

  • In the source code space click “Browse Source” and give the path oplk_v2.1.1/stack and click open

  • In “Where to build the binaries” click browse build and give the path oplk_v2.1.1/stack/build/linux and click open

  • Click “Configure”. A dialog box opens. Click “Use default native compilers” and click “Finish”

  • Un-check all other libraries except MNAPP_USERINTF and MNDRV_PCAP

  • Here the CMAKE_BUILD_TYPE will be in “Release” by default

compile and build MN

  • Click “Configure” and then click Generate

  • Now in the terminal navigate to build to binaries path and type in “make install”. This will install the stack binaries in release mode

compile and build MN

compile and build MN

  • Now switch over to cmake-gui and replace the CMAKE_BUILD_TYPE to “Debug” and rest of the configurations the same

compile and build MN

  • Click “Configure” and then click “Generate”

  • In the terminal navigate to the build to binaries path and type in “make install”. This will install the stack binaries in “Debug” mode

compile and build MN

compile and build MN

Building pcap driver

  • Switch to cmake-gui

  • In the source code space click “Browse Source” and give the path oplk_v2.1.1/drivers/linux/drv_daemon_pcap and click open

  • In “Where to build the binaries” click browse build and give the path oplk_v2.1.1/drivers/linux/drv_daemon_pcap/build and click open

  • Click “Configure”. A dialog box opens. Click “Use default native compilers” and click “Finish”

compile and build MN

compile and build MN

  • In the configuration settings, check the CFG_OPLK_MN and click “Configure” then “Generate”

compile and build MN

  • In the terminal navigate to the build to binaries path and type in “make install”. This will install the pcap binaries

compile and build MN

Building a Demo Application

  • Switch to cmake-gui

  • In the source code space click “Browse Source” and give the path oplk_v2.1.1/apps/demo_mn_console and click open

  • In “Where to build the binaries” click browse build and give the path oplk_v2.1.1/apps/demo_mn_console/build/linux and click open

  • Click “Configure”. A dialog box opens. Click “Use default native compilers” and click “Finish”

compile and build MN

compile and build MN

  • In the configuration settings select “Linux Userspace Daemon” for CFG_BUILD_KERNEL_STACK

compile and build MN

compile and build MN

  • Click “Configure” twice then “Generate”

  • In the terminal, navigate to the build to binaries path and type in “make install”. This will install the application binaries

compile and build MN

compile and build MN

4. Compile and build CN

Following are the code changes to be carried out to control the ON/OFF state of the openPOWERLINK slave GPIOs from openPOWERLINK master via PDO over POWERLINK network.

Following are the code changes to be carried out to control the ON/OFF state of the openPOWERLINK slave GPIOs from openPOWERLINK master via PDO over POWERLINK network.

Step 1:

File name: “linux.cmake”

Path: “/home/linaro/oplk_Pi2/openPOWERLINK/apps/demo_cn_console”

Description: Include the wiring Pi library to the openPOWERLINK make file.

To download the modified file, click here

Step 2:

File name: “app.c”

Path: “/home/linaro/oplk_Pi2/openPOWERLINK/apps/demo_cn_console”

Description: Include the “wiring Pi” header to app.c

To download the modified file, click here

Step 3:

File name: “app.c”

Path: “/home/linaro/oplk_Pi2/openPOWERLINK/apps/demo_cn_console”

Description: Call the wiring Pi setup function to make GPIO Header Pin 17 as DigitalInput (Here Pin 0 is re-mapped as GPIO Header Pin 17)

Step 4:

File name: “app.c”

Path: “/home/linaro/oplk_Pi2/openPOWERLINK/apps/demo_cn_console”

Description: Once the slave receives the PDO data from the master, it writes the value to the GPIO Header Pin 17.

code changes

Once the code changes are completed, the openPOWERLINK source code can be compiled as follows,

Building Stack libraries:

  • open terminal and type in cmake-gui. A user interface dialog box opens

embedded

 

  • In the source code space click “Browse Source” and give the path oplk_v2.1.1/stack and click open

  • In “Where to build the binaries” click browse build and give the path oplk_v2.1.1/stack/build/linux and click open

  • Click “Configure”. A dialog box opens. Click “Use default native compilers” and click “Finish”

    cn_build/cn_build

     

  • Un-check all other libraries except CNAPP_USERINTF and CNDRV_PCAP

  • Here the CMAKE_BUILD_TYPE will be in “Release” by default

 

  • Once the build is completed successfully, CN stack binaries will be installed in “Release” mode

Photos

embedded

 

  • Now switch over to cmake-gui and replace the CMAKE_BUILD_TYPE to “Debug” and rest of the configurations the same

  • Click “Configure” and then click “Generate”

application

 

  • In the terminal navigate to the build to binaries path and type in “make install”. This will install the stack binaries in “Debug” mode

embedded-application

embedded-application

Building a Linux PCAP User Space Daemon

  • Switch to cmake-gui

  • In the source code space click “Browse Source” and give the path oplk_v2.1.1/drivers/linux/drv_daemon_pcap and click open

  • In “Where to build the binaries” click browse build and give the path oplk_v2.1.1/drivers/linux/drv_daemon_pcap/build and click open

  • Click “Configure”. A dialog box opens. Click “Use default native compilers” and click “Finish”

embedded-application

embedded-application

  • Un-check the “OPLK_CFG_MN” which will configure as CN

embedded-application

 

  • In the terminal navigate to the build to binaries path and type in “make install”. This will install the pcap binaries

embedded-application

Building a Demo Application

  • Open cmake-gui.

  • In the source code space click “Browse Source” and give the path oplk_v2.1.1/apps/demo_cn_console and click open

  • In “Where to build the binaries” click browse build and give the path oplk_v2.1.1/apps/demo_cn_console/build/linux and click open

  • Click “Configure”. A dialog box opens. Click “Use default native compilers” and click “Finish”

embedded-application

embedded-application

  • In the configuration settings select “Linux Userspace Daemon” for CFG_BUILD_KERNEL_STACK

embedded-software

embedded-software

 

  • Click “Configure” twice then “Generate”

  • In the terminal, navigate to the build to binaries path and type in “make install”. This will install the application binaries

embedded-software

embedded-software

On Raspberry Pi 2 (On Slave board – 2)

Configuration steps to configure Raspberry Pi 2 as openPOWERLINK Slave node:

Repeat the steps as carried out for “Slave 1” before making the following changes:

  • Open the file from the path /home/linaro/oplk_v2.1.1/apps/demo_cn_console/src/main.c and change the NODEID to 32 as shown below

5. Environment setup to run openPOWERLINK

On Raspberry Pi2 (On Master board)

All the binaries will be installed in the bin folder of the oplk_v2.1.1 directory. To run the binaries follow the screen shot below.

  • Load the “tun” module before running the pcap driver

  • Run the pcap driver from the path oplk_v2.1.1/bin/linux/armv7l/oplkd-pcap/

  • Run the demo_mn_console app from the path oplk_v2.1.1/bin/linux/armv7l/demo_mn_console/

On Raspberry Pi 2 (On Slave board – 1 and 2)

  • Load the “tun” module before running the pcap driver

  • Run the pcap driver from the path oplk_v2.1.1/bin/linux/armv7l/oplkd-pcap/

  • Run the demo_cn_console app from the path oplk_v2.1.1/bin/linux/armv7l/demo_cn_console/