OPC UA server on an ARM microcontroller with different RTOS
The rapid advance of connectivity and automation in production facilities and factories is increasing the demands placed on secure and reliable data transport. One possible solution to these challenges is OPC UA.
OPC stands for “Open Platform Communications” and is a communication standard for Industry 4.0 and IoT. OPC standardises access to machines, devices and other systems in the industrial environment, thus enabling manufacturer-independent data exchange. The UA or “Unified Architecture” extension is the standard's latest specification. The introduction of TCP/IP communication has made the standard platform independent, further expanding the potential applications.
At CSA Boostcamp 2022, we explored this communication standard in depth and identified its potential using a simple application. The open source implementation “open62541”, which is based exclusively on the IEC 62541 standard, was tested on the STM32H735-DK Discovery Kit. Open62541 runs on many common operating systems and is ideally suited to embedded systems with microcontrollers due to its minimal memory footprint. In our demo application, an OPC UA server was created on an embedded device, communication was established via a client on a Windows PC and data was exchanged with the server. To evaluate the porting options, the OPC UA server was implemented and tested on the same embedded device with two different operating systems and network stacks.
OPC UA is based on the concept that every piece of information is represented by a “node”. A node can be a variable, a data type, a reference, an object, etc. Open62541 can be created in various configurations. To account for the limited storage resources in a microcontroller, namespace zero was used in a minimal version. This defines the basic nodeset and may not be expanded with application-specific nodes. First, the FreeRTOS operating system was used together with the LwIP network stack. A sample project from STM32CubeIDE was set up to establish a connection via TCP/IP and as the basis for the demo application.
In the FreeRTOS heap memory, about 20kB of memory was occupied by the OPC UA server. When connecting a client, a send and receive buffer is required for each runtime. In addition, each created node has a memory footprint. Its size depends on the information that the respective node represents. This memory footprint must be taken into account when planning the memory resources per use case. In our demo application, 300 variable nodes were created for the test and nearly 270kB was occupied in RAM.
To use the OPC UA server's data, a corresponding remote station (client) is required. This was emulated using the software UaExpert on a Windows PC. UaExpert is a freely available UA reference client from Unified Automation. In our demo application, the client can read the node structure of the server as well as the individual variable values of the nodes. The variable value was incremented with each key press on the STM32H735-DK. An LED on the STM32 board could be switched on and off by the client via another node.
In a second step, the FreeRTOS operating system was replaced with AzureRTOS and the LwIP network stack was replaced with NetX. Porting the network functions proved to be a challenge. However, Azure offers a compatibility wrapper that supports the necessary BSD Socket API. As a result, the porting of the network functions from LwIP to NetX was ultimately achieved with a reasonable amount of effort. To increase security, user name and password authentication was implemented on the server in a further step. A client now had to authenticate itself when connecting to the server. In addition, encryption may be able to enhance security further. Open62541 supports mbed TLS, OpenSSL and LibreSSL.
OPC UA enables manufacturer-neutral data transport in countless areas of application. Information is transported securely and reliably from the manufacturing level to the production planning or ERP system. For example, embedded UA servers can be integrated into a network at the field level using standardised interfaces. It is possible to distribute components across multiple locations and to separate networks securely using firewalls.
We here at CSA Engineering AG will be happy to support you in your next project with OPC UA.