Introduction on how to get POWERLINK working on Raspberry PI 2

 

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.

Download and install dependencies

A) On Windows PC
  1. openPOWERLINK dependencies
    1. Libpcap-dev
  2. Dependency file 1 for pcap library
  3. Dependancy file 2 for pcap library
  4. Install_pcap.sh
  5. Cmake-gui
    1. Dependency file 1 for cmake-gui
    2. Dependancy file 2 for cmake-gui
    3. Install_cmake.sh
    4. Wiring Pi
    5. Install openCONFIGURATOR for windows
B) 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:
  1. Open the terminal (you can use the short cut key “ctrl + alt + t”)
  2. Mount the USB thumb drive as highlighted in the below screen shot
  3. Create a directory “oplk_Pi2” in the path /home/linaro as highlighted in the below screen shot
    1. sudo mkdir /home/linaro/oplk_Pi2
  4. Copy the packages from the USB thumb drive into the Raspberry Pi 2’s directory (/home/linaro/oplk_Pi2)
  5. sudo cp -R * /home/linaro/oplk_Pi2
  6. Change administrative privileges to the oplk_Pi2 folder sudo chmod -R +x /home/linaro/oplk_Pi2
  7. Navigate to the oplk_Pi2 folder
    1. cd /home/linaro/oplk_Pi2
  8. Now list all the folders using “ls” command as highlighted in the below screen shot:
  9. Now extract the downloaded packages one by one and install them as shown below:
  10. To install Libpcap
    1. tar -xvf Install_pcap.sh.tar.gz
    2. sudo ./Install_pcap.sh RPI2
  11. To install Cmake-gui
    1. sudo ./Install_cmake.sh
 
 
3) Create a openCONFIGURATOR Project
  1. Open the openCONFIGURATOR tool from your start menu
  2. Once the application is loaded, select “Open Existing Project” and click ‘Ok’
  3. Navigate to the path ‘C:/openPOWERLINK/apps/common/openCONFIGURATOR_projects/Demo_3CN’ and double click on ‘Demo_3CN.xml’
  4. Now the project wil be imported to the tool with three CN configuration
  5. The cycle time is set to 50000us by default as shown below
  6. Click on CN_1(1) and change the Pollresponse timeout to 300us as shown below
  7. Click on CN_2(32) and change the Pollresponse timeout to 400us as shown below
  8. Similarly click on CN_3(110) and change the Poll response timeout to 500us as shown below:

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

  9. Click on the TPDO-00 of the CN_1(1) and you will find 1 byte of object mapped to the TPDO by default
  10. 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

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

  11. These mappings will be reflected to the MN’s PDO as well
  12. 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)
  13. Once the configurations and mapping are done, the project can be built by pressing ‘F7’ or as shown below
  14. Once you click the build project, an auto generate window will pop up. Click ‘yes’ to continue to build the project
  15. 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
  16. Now navigate to the output path of the generated files and copy the ‘xap.h’ file
  17. Replace the copied ‘xap.h’ file from the path ‘C:/openPOWERLINK/apps/demo_mn_console/src’
  18. 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
Download
To download the modified file, Click here…
compile and build N
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
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,

 
3) 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/