Managing S7-400 Local Data Stack Allocation and Resolving CFC Compilation Exhaustion
When a CFC compilation or download fails due to 'Local Data Requirements being larger than the local stack configured' in SIMATIC PCS 7, the CPU priority class (OB) has exceeded its allocated local data memory (L-stack). Standard Library string functions (such as LEFT, RIGHT, or CONCAT) allocate temporary string buffers of up to 256 bytes per call on the L-stack. To resolve this, inspect the Chart Reference Data to identify the consuming OB, expand the OB local data partition in HW Config under CPU Properties > Memory > Local Data, or encapsulate string operations within a custom Function Block using static instance memory.
Table of Contents
- Executive Summary
- Architecture and Fundamental Mechanics
- Step-by-Step Implementation Procedure
- Verification
- Limitations and Operational Precautions
- Engineer FAQ
- Technical References
- Related Articles
- Related Tags
Executive Summary
In SIMATIC PCS 7 (V8.0 through V9.1), S7-400 automation controllers manage temporary execution memory via a dedicated Local Data Stack (L-stack) partitioned across execution priority classes (Organization Blocks). When engineers introduce complex logic, batch reporting blocks, or standard string-manipulation functions (e.g. LEFT, RIGHT, CONCAT), local data usage can surge unexpectedly, causing CFC compilation errors or preventing delta downloads. A single direct instantiation of a string-processing function can consume up to 260 bytes of local stack memory. This article examines the mechanics of the S7-400 L-stack, how to diagnose consumption via Chart Reference Data, and methods to safely reconfigure memory partitions in HW Config.
Architecture and Fundamental Mechanics
Architecture and Mechanics of the S7-400 Local Data Stack (L-stack):
- S7-400 Local Data Memory Structure:
- The CPU provides a fixed physical memory pool for temporary local variables (
VAR_TEMP), compiler scratch registers, and block parameter passing. Depending on the CPU model (CPU 414, 416, 417, 410), this pool ranges from 16 KB up to 64 KB. - This memory pool is not shared dynamically at runtime; it is statically partitioned across priority classes (Priority Class 1 for OB1, Priority Classes 12–18 for cyclic interrupts OB30–OB38, Priority Class 27 for OB100, etc.) in HW Config.
-
If any single OB exceeds its configured local data quota, the CPU triggers a programming fault (Event ID
16#45- Local data allocation error), and the CFC compiler will refuse to generate executable machine code. -
String Manipulation Overhead and Temporary Variables:
- In IEC 61131-3 and STEP 7, a standard
STRINGvariable is defined with a 2-byte header (maximum length, current length) followed by characters up to 254 bytes (total 256 bytes). - Standard Library string functions (such as
LEFT- FC20,RIGHT- FC32,MID- FC26) pass strings by value or create temporary intermediate string buffers on the L-stack. -
When placed directly on a CFC chart, each string block call forces the CFC code generator to allocate fresh temporary local data in that OB's stack frame (often 256–260 bytes per block). Calling 10 or 12 such blocks in OB35 quickly exhausts a default 1024-byte partition.
-
The Custom Function Block (FB) Encapsulation Difference:
- When string operations are wrapped inside a custom Function Block (FB), intermediate variables can be declared as static variables (
VARinstead ofVAR_TEMP). - Static variables are stored permanently in the block's instance Data Block (DB) in user work memory, completely bypassing the temporary L-stack. Consequently, instantiating the custom FB on a CFC chart adds virtually zero demand to the OB's local data stack.
Step-by-Step Implementation Procedure
Step-by-Step Procedure to Diagnose and Resolve Local Data Stack Exhaustion:
- Inspect Local Data Consumption via Chart Reference Data:
- In the CFC editor, select menu Options -> Reference Data -> Display.
- In the Reference Data window, select view Local Data Requirements (or press Ctrl+L).
- Examine the table displaying each Organization Block (e.g. OB1, OB32, OB35, OB100).
- Identify which OB has an 'Actual' or 'Calculated' requirement exceeding or nearing the 'Configured' limit. - Identify Heavy Block Contributors:
- In SIMATIC Manager Component View, open the Blocks folder.
- Right-click any suspected block (e.g.UNIT_PLC, custom string FBs, standard library FCs) -> select Object Properties.
- Click the General - Part 2 tab to review the block's declared 'Local Data' requirement in bytes. - Reallocate Local Data Partitions in HW Config:
- Open HW Config in SIMATIC Manager.
- Double-click the CPU 41x-x module to open Properties - CPU.
- Select the Memory tab.
- Under the Local Data section, inspect the table listing Priority Classes 1 through 29.
- Increase the byte allocation for the offending priority class (e.g., increase Priority Class 12 / OB35 from1024to2048or4096bytes).
- Ensure the total allocated bytes across all priority classes does not exceed the maximum total local data capacity supported by that specific CPU model.
- Click OK, save, and compile HW Config. - Encapsulate String Operations into Custom Function Blocks:
- If HW Config expansion is constrained, create a custom SCL Function Block (FB).
- Declare all intermediate string variables underVAR(static) rather thanVAR_TEMP.
- Call the standard string functions internally within the FB.
- Replace the discrete standard string FCs on the CFC chart with the single custom FB. - Recompile CFC Charts and Download:
- In CFC, select Chart -> Compile -> Charts as Program.
- Confirm that compilation completes with zero errors.
- Perform download to the controller.
Verification
Verification Procedure:
1. Reference Data Verification: Re-open Chart Reference Data -> 'Local Data Requirements'. Verify that the configured memory now comfortably exceeds peak calculated requirements for all priority classes (maintaining a safety margin of at least 20%).
2. Compiler Verification: Execute a full CFC compilation; confirm that the compiler log confirms successful code generation with 0 errors.
3. Online Diagnostics: Connect online to the CPU in STEP 7; open Module Information -> Diagnostic Buffer. Verify the absence of any Event ID 16#45 (local data allocation fault).
Limitations and Operational Precautions
Operational Precautions and HW Config Boundaries:
- Controller STOP Requirement for HW Config: On standard S7-400 CPUs (e.g. CPU 414, 416, 417), downloading modified local data memory partitions in HW Config requires transitioning the CPU to STOP mode unless Configuration in RUN (CiR) is pre-configured and the specific parameter allows dynamic allocation.
- Global Pool Constraints: Expanding one priority class necessarily reduces available headroom for others if the CPU's maximum local data memory limit is reached.
- Do not use temporary string variables in high-frequency cyclic OBs (e.g. OB36 / 10ms or OB38 / 1ms), as local stack thrashing degrades deterministic cycle execution.
Engineer FAQ
Why does adding standard library FCs like 'LEFT' increase local data so rapidly?
Standard library string FCs declare 256-byte temporary string buffers on the L-stack for input and output manipulation. Multiple calls in the same OB accumulate peak stack depth rapidly.
Where in SIMATIC Manager can I see the local data used by an individual block?
Open the S7 Program Blocks folder, right-click the block, select Object Properties, and view the 'General - Part 2' tab.
Can I reallocate local data memory without stopping the controller?
On classic S7-400 CPUs, changing local data partitions in HW Config requires a STOP download. On CPU 410-5H, local data allocation is managed dynamically by firmware and accommodates larger structures automatically.
What is the difference between VAR and VAR_TEMP regarding local data?
Variables in VAR_TEMP consume temporary L-stack memory allocated during block execution. Variables in VAR reside permanently in the block's instance DB in work memory and do not consume L-stack memory.
Which priority class corresponds to cyclic interrupt OB35?
In the S7-400 memory configuration table, OB35 corresponds to Priority Class 12 by default.
Technical References
- SIMATIC S7-400 CPU Specifications and Memory Architecture Manual
- SIMATIC Process Control System PCS 7 CFC for S7 / S7-FH Manual
- SIMATIC STEP 7 V5.6 Programming with STEP 7 Manual
Related Articles
- Resolving Missing AS RT PO Expansion and Activating CPU 410-5H System Expansion Cards
- Resolving Error 299:207 during CFC Compilation and Restoring Corrupted Chart Databases
- Removing Locked Interconnections, Text References, and Un-deletable Links in CFC Charts
Related Tags
- Local Data Stack
- S7-400 Memory
- CFC Compilation
- Priority Classes
- Organization Blocks