This repository is a port of the open-source P-Net evaluation version to RT-Thread, used for implementing the P-Net protocol stack for Profinet devices.
Open the bsp's env interface, go to ->RT-Thread online packages->IoT, and find [*] P-Net stack for Profinet device implementation ---> to enable it. Also, leave configurations for the user:
-*- Default netif name for P-NET --->
-> (e00) default ethernet interface name for p-net app, default as 'e00
-*- Enable P-NET sample board config --->
-> (0x0209) p-ent user led pin
-> (0x0005) p-net user key pin
-*- Default root filesystem path for P-NET --->
-> [*] p-net using ramfs filesystem by default, or you can turn this off and choose another way to enable the filesystem
-> (8192) default memory size for ramfs
-*- P-NET sample slave network ip config --->
-> (192.168.10.100) set static ip address for profinet slaver
-> (192.168.10.1) set static gateway address for profinet slaver
-> (255.255.255.0) set static mask address for profinet slaver
version (latest) --->
Next, configure DHCP to be disabled and use a static IP. Go to → RT-Thread Components → Network → LwIP: lightweight TCP/stack, and disable DHCP:
After completing the configuration, compile and download the program to the development board.
Connect the development board to the PC using an Ethernet cable, and configure a static IP on the PC side:
Check the IP information on the development board and test the connectivity:
CODESYS Overview: CODESYS is a PLC software developed by the German company 3S. It integrates functions like PLC logic, motion control, and configuration displays. CODESYS, short for "Controller Development System," is an industrial automation programming tool based on the IEC 61131-3 standard. It supports multiple programming languages (e.g., ladder diagram, structured text, function block diagram) and offers a wide range of libraries and functional modules, helping engineers quickly develop and debug PLCs and industrial control systems. Its flexibility and powerful features make it widely used in industrial automation.
Ensure that the CODESYS software is installed. After installation, the following three pieces of software will be used:
First, open CODESYS V3.5 SP20 Patch 3, select -> New Project -> Projects -> Standard Project, configure the project name and location, then click OK:
After the following popup, keep the default Settings (CODESYS Control Win V3 (CODESYS)/x64 (CODESYS)) and click OK:
Note: If you purchased the CODESYS Control RTE SL, you can choose the device: CODESYS Control RTE V3 (CODESYS) / x64 (CODESYS). For normal evaluation purposes, you can skip installing this extension package and select CODESYS Control Win V3 (CODESYS) / x64 (CODESYS) device to create the project.
After the creation is successful, you will see the main interface:
Open the following two software applications:
Go back to the CODESYS master software, double-click Device (CODESYS Control Win V3 x64) -> Communication Settings -> Scan Network:
After the device user login window appears, configure the username and password (user-defined):
Check if the gateway device and softPLC device are online:
GSD (Generic Station Description) files: These are used in PROFIBUS DP (GSD files) and PROFINET IO (GSDML files) communication, acting as a bridge between the CPU module and IO modules in a PLC system. They typically include channel data, parameter data, diagnostic data, and user-defined data.
The GSDML file for this project is located at:
Install the GSDML file from the device repository by selecting GSDML-V2.4-RT-Labs-P-Net-Sample-App-20220324.xml under the above path:
After the installation is successful, you will see the P-net slave description file:
the left navigation panel -> General, and modify the default slave IP parameters according to the prompts.
You should now see that the PN master has successfully come online:
After the development board is powered on, once the NIC link up is detected, the secondary PN station is automatically started:
In this section, we will use CODESYS and PRONETA software to test the interaction between PN master and slave as well as network topology status.
Go back to the CODESYS software, select PN_Controller from the left navigation panel, right-click and scan for devices. After clicking on the device name, click Blink LED:
At this point, you will see the log output on the development board (PN slave IO), and the onboard User LED will blink:
In the device scanning interface, click the I&M button at the bottom left, modify the information, and write the new I&M data:
PNIO will update the slave configuration information:
Click I&M again to see that the I&M modification has been successfully applied!
First, click on the left panel to navigate to Device -> PLC Logic -> Application -> PLC_PRG(PRG), and use ST (Structured Text) language to program, defining variables and writing program code:
Variable Definitions: These variables define the input state of the button (in_pin_button_LED), the output state of the LED (out_pin_LED), and the state variable controlling whether the LED should blink (flashing). The oscillator state (oscillator_state) and oscillator cycle counter (oscillator_cycles) are used to create the blinking effect.
PROGRAM PLC_PRG
VAR
in_pin_button_LED: BOOL;
out_pin_LED: BOOL;
in_pin_button_LED_previous: BOOL;
flashing: BOOL := TRUE;
oscillator_state: BOOL := FALSE;
oscillator_cycles: UINT := 0;
END_VAR
Program Definition:
oscillator_cycles is incremented by 1. When the counter exceeds 200, it resets the counter and toggles the oscillator_state (TRUE or FALSE) to create periodic changes.in_pin_button_LED is TRUE) and the previous cycle's button state was FALSE, the flashing state is toggled. This means every time the button is pressed, the LED blinking state will toggle.flashing is TRUE, the LED will blink according to the oscillator_state. If flashing is FALSE, the LED will be turned off.At the end of each cycle, the current button state is saved in in_pin_button_LED_previous to detect the next button press event.
oscillator_cycles := oscillator_cycles + 1;
IF oscillator_cycles > 200 THEN
oscillator_cycles := 0;
oscillator_state := NOT oscillator_state;
END_IF
IF in_pin_button_LED = TRUE THEN
IF in_pin_button_LED_previous = FALSE THEN
flashing := NOT flashing;
END_IF
out_pin_LED := TRUE;
ELSIF flashing = TRUE THEN
out_pin_LED := oscillator_state;
ELSE
out_pin_LED := FALSE;
END_IF
in_pin_button_LED_previous := in_pin_button_LED;
The configuration in the project is shown in the image below:
Next, we need to add a built-in I/O module. Right-click on P_Net_multi_module_sample_app and add an I/O module (DIO 8xLogicLevel), as shown in the following image:
Next, double-click the DIO_8xLogicLevel node, select PNIO Module I/O Mapping, and edit Input Bit 7 and Output Bit 7, binding them to the PLC variables:
Then, click on the "Compile -> Generate Code" in the top navigation bar, followed by "Online -> Login", and run the program to observe the phenomenon:
Next, return to CODESYS and double-click on Device -> PLC Logic -> Application -> PLC_PRG(PRG). At this point, you can dynamically observe the program's running status. For example, by holding down the KEY0 button on the EtherKit development board, you can see that the values of in_pin_button_LED and in_pin_button_LED_previous are both FALSE. When you release KEY0, the value of flashing will toggle once.
PRONETA Overview: PRONETA Basic is a simple tool for quickly analyzing and configuring PROFINET networks. It also supports basic testing of ET 200 distributed IO systems and other components.
Open the PRONETA software and add the GSDML file:
After installation is successful, you can see the status information:
Click Settings -> Network Adapter and choose the PN corresponding Ethernet port:
Select Network Analysis -> Online from the top left navigation panel, click Refresh, and after a moment, you should see the PN network status. The specific PNIO information can be viewed on the right sidebar. Since we modified the PNIO information in CODESYS, you can also see the updated information here.
Since pnet only supports a single AR by default, we need to disable the gateway device and softPLC device on the CODESYS master:
Then, refresh the device and right-click rt-labs-dev to test the LED and I&M data modification: