Compiling STL Source Files into S7 Blocks in STEP 7
Engineers migrating legacy S5 programs to S7-300/S7-400 platforms routinely encounter a single, consolidated STL source file containing dozens of network blocks (OB, FC, FB, DB, UDT). The task is to split that monolithic source back into the original block structure and compile each block into a downloadable program object. This reference covers the complete workflow: generating source from existing blocks, manually restructuring converted S5 source, diagnosing the classic VOID compile error, and verifying the final block library.
1. STL Source File Model in STEP 7
A STEP 7 STL source file is an ASCII text container that holds one or more block declarations followed by their code networks. Each block type has its own opening keyword and a closing END_ terminator that must be matched by the compiler. The file is edited either inside the STL Editor of the SIMATIC Manager or in any external text editor, then compiled back into the S7 program container.
The block declaration syntax is fixed and case-insensitive but must include a return type (or VOID for code-only blocks) followed by the begin/end envelope:
| Block Type | Declaration Line | Closing | Purpose |
|---|---|---|---|
| Organization Block | ORGANIZATION_BLOCK OB 1 |
END_ORGANIZATION_BLOCK |
Main, interrupt, error OBs |
| Function | FUNCTION FC 30 : VOID |
END_FUNCTION |
Reusable code block, no static memory |
| Function Block | FUNCTION_BLOCK FB 10 |
END_FUNCTION_BLOCK |
Reusable block with instance DB |
| Data Block | DATA_BLOCK DB 20 |
END_DATA_BLOCK |
Structured / address-assigned data |
| Instance DB |
DATA_BLOCK DB 100(assigned to an FB) |
END_DATA_BLOCK |
Runtime data for an FB |
| User-Defined Type | TYPE UDT 1 |
END_TYPE |
Custom data structure |
VOID means the FC returns no value; INT, REAL, BOOL, WORD, DWORD, BYTE, CHAR, STRING, and DINT are also valid.2. Prerequisites
- SIMATIC Manager (STEP 7 V5.x) installed with the optional S5 to S7 Converter package for legacy migration paths. For TIA Portal users, the equivalent functionality is described in the official Saving blocks as external source files documentation.
- An S7 project (S7-300, S7-400, or WinAC) containing a Sources folder in the program container.
- Read/write access to the project path on the engineering station.
- Familiarity with STL mnemonics:
A,O,AN,S,R,=,L,T,U(,UN(,JC,JCN,CALL,BE,BEU,BEB. - (For S5 migration) The original S5 STL/STL source or a converted source file generated by the converter.
3. Generating Source from Existing Blocks
When you already have compiled blocks (FC, FB, DB, OB, UDT) and want to edit them as text or back them up externally, generate a single source file that contains every block. This is the reverse path of the migration problem and is useful for diff/merge, version control, and bulk find/replace operations.
- Open the SIMATIC Manager and select the Program Blocks folder (or the S7 program container) of the target station.
- Right-click the Sources folder and choose Insert New Object → STL Source File. Name it (e.g.,
PlantLibrary) and confirm with OK. - Open the new (empty) source file. The compiler inserts a header comment block automatically.
- Select the blocks in Program Blocks that you want to export (Ctrl+Click for non-contiguous selections).
- Drag the selection onto the open source editor. Each selected block is written into the source as a separate, properly delimited declaration. FBs, FCs, OBs, DBs, and UDTs are all supported.
- Alternatively, choose File → Generate Source from the menu bar of the Program Blocks window, then pick the blocks and an output source name.
- Save the source (Ctrl+S).
The result is a single .s7s (or .awl in some installations) text file containing every block. You can edit it directly, then recompile to overwrite the original blocks.
4. Converting an S5 Program to S7 STL Source
Siemens historically supplied the S5 to S7 Converter as an optional add-on under Start → SIMATIC → STEP 7 → S5 to S7 Converter. The converter reads an S5 program file (.s5p on disk) and produces an S7 project containing:
- An S7 program container with converted FC, FB, DB, OB equivalents.
- A single STL source file inside the Sources folder that aggregates the converted code. The source is the canonical, human-editable form of the migration and is the file engineers edit to clean up conversion artifacts before re-compilation.
- A conversion log listing remapped operand areas, changed mnemonics, and unresolved references.
Open the converted STL source in the STL editor. The first declaration looks similar to this:
FUNCTION FC 30 : VOID
BEGIN
NETWORK
TITLE = converted FC30 - motor interlock
A "M 0.1";
AN "I 1.7";
S "M 0.2";
END_FUNCTION
Each block in the converted source is delimited by a FUNCTION ... END_FUNCTION (or analogous) envelope. To split the aggregate source back into separate blocks, copy each envelope (declaration through terminator) into its own STL source file or compile the aggregate file directly and let STEP 7 create the individual block objects.
5. The VOID Keyword: Compile Error Root Cause
The single most common compile error after an S5-to-S7 conversion is a parse failure caused by the return type placed immediately after the colon in the FC declaration. Two scenarios produce this error:
-
Missing
VOID: Older converter outputs or hand-typed declarations omit the return type, leaving the parser expecting a type token that never arrives. -
Stray/misplaced
VOID: The S5-to-S7 converter often prefixesVOIDin front of the block instead of after the colon, producing lines such asVOID FUNCTION FC 30. The grammar requiresVOIDto appear after the colon, not beforeFUNCTION.
Correct syntax accepted by the compiler:
FUNCTION FC 30 : VOID
BEGIN
...
END_FUNCTION
Incorrect syntax that fails to compile:
VOID FUNCTION FC 30 // wrong position
BEGIN
...
END_FUNCTION
Use Edit → Find/Replace with Regular expressions enabled to bulk-fix legacy sources:
- Search:
^VOID\s+FUNCTION\s+(FC|FB|OB)\s+(\d+) - Replace:
FUNCTION \1 \2 : VOID
For FBs that legitimately return a value, replace VOID with the correct type (INT, REAL, etc.). For multi-instance FBs, the FC equivalent remains VOID because the multi-instance model is FB-only.
VOID outright — the FC parser requires a return type token. Use VOID for code-only blocks and a primitive type for blocks that return values.6. Step-by-Step: Compile an STL Source into Blocks
- In SIMATIC Manager, open the Sources folder of the target S7 program.
- Double-click the STL source (e.g.,
PlantLibraryorS5_Migrated) to open the STL editor. - Verify the syntax of each block declaration. Confirm that every
FUNCTIONline carries a return type, everyBEGINis paired with a matchingEND_FUNCTION/END_ORGANIZATION_BLOCK/END_DATA_BLOCK/END_FUNCTION_BLOCK, and that block numbers are unique within their type. - Select File → Compile from the menu bar, or press Ctrl+B. STEP 7 parses the source and creates each declared block in Program Blocks. Existing blocks with the same number are overwritten after a confirmation prompt.
- Watch the Compiler Output window. Errors are listed with the line number and a short description. Double-click an error to jump to the offending line.
- Fix each error, save the source (Ctrl+S), and recompile until the output is clean.
- After a successful compile, the newly generated blocks appear in the Program Blocks folder with the symbols from the source comments (when Symbolic Names is enabled).
7. Block Type Reference and Syntax Templates
The following templates cover the four block types you will encounter most often when migrating S5 programs. Paste them into a new STL source, then replace the placeholder numbers and code.
7.1 Function (FC) without Return Value
FUNCTION FC 100 : VOID
VAR_TEMP
tAux : INT;
END_VAR
BEGIN
NETWORK
TITLE = sample FC
L 0;
T #tAux;
BE;
END_FUNCTION
7.2 Function Block (FB) with Instance Data
FUNCTION_BLOCK FB 50
VAR
iCounter : INT;
bEnable : BOOL;
END_VAR
VAR_TEMP
tLoop : INT;
END_VAR
BEGIN
NETWORK
TITLE = sample FB
A #bEnable;
JCN _SKIP;
L #iCounter;
+ 1;
T #iCounter;
_SKIP: NOP 0;
END_FUNCTION_BLOCK
7.3 Data Block (DB) with Address Assignment
DATA_BLOCK DB 200
STRUCT
iSetpoint : INT;
rActual : REAL;
bReady : BOOL;
sLabel : STRING[20];
END_STRUCT;
BEGIN
END_DATA_BLOCK
7.4 Organization Block (OB1 cyclic main)
ORGANIZATION_BLOCK OB 1
BEGIN
NETWORK
TITLE = cyclic main
CALL FC 100;
CALL FB 50 , DB 50;
BE;
END_ORGANIZATION_BLOCK
8. Converting Block Types via Source Edit
STEP 7 does not provide a direct "convert FC to FB" wizard. The pragmatic path is source-level conversion:
- Generate source from the existing FC (drag the FC onto a new STL source).
- Edit the source: change
FUNCTION FC x : VOIDtoFUNCTION_BLOCK FB y; replaceEND_FUNCTIONwithEND_FUNCTION_BLOCK; convert anyVAR_TEMPtoVARif you need retentive state across calls. - Compile the source. The new FB object appears in Program Blocks.
- Generate an instance DB for the new FB: right-click Program Blocks → Insert New Object → Data Block; specify DB number and tie it to the FB via the Instance Of dropdown.
CALL FB 50, DB 50 references in the calling OBs and FCs after the conversion.9. Verification Procedure
After a successful compile, perform these checks before downloading to the PLC:
- Cross-reference: Open Options → Reference Data → Display. Verify that every called block exists, every referenced tag is declared, and there are no unresolved operands.
- Symbol table consistency: Open the symbol table and confirm that every tag referenced in the new blocks has a defined symbol. Missing symbols produce downloads that succeed but operate on undefined addresses.
- Block consistency check: In SIMATIC Manager, select Program Blocks and choose Edit → Check Block Consistency. Resolve any reported inconsistencies before download.
- Download to PLCSIM: Use PLCSIM (S7-PLCSIM) to validate the compiled blocks in an offline simulation. Cycle power (STOP → RUN) and exercise the call hierarchy before connecting to real hardware.
- Watch tables: Build a watch table that monitors the input, output, and intermediate tags of each newly compiled block. Trigger a single scan and verify that the block produces the expected results.
-
Compiler output review: Re-read the compiler output for warnings (yellow) as well as errors (red). The converter can emit warnings about implicit type conversions, missing
BEGINalignment, or deprecated mnemonics.
10. Troubleshooting Matrix
| Symptom | Likely Cause | Fix |
|---|---|---|
| Compile fails with "Syntax error before FUNCTION/FB/OB/DB" |
VOID keyword placed before FUNCTION instead of after the colon |
Edit the declaration to read FUNCTION FC 30 : VOID
|
| Compile fails with "Return type expected" | FC declaration missing the return type token after the colon | Append : VOID (or another type) to the FC declaration line |
| Compile fails with "Block already exists, overwrite?" and the cancel path returns errors | Block number collides with an existing compiled block; type mismatch | Rename the new block to a free number or remove the existing block first |
| Compile succeeds but blocks do not appear in Program Blocks | Source file was edited externally without a BOM or with non-ASCII characters | Re-save as ANSI text; remove any Unicode characters; recompile |
| FC compiled but call site reports "Block not found" | Symbol table entry missing or pointing at the wrong FC number | Update the symbol and confirm the actual FC number matches the call site |
| FB compiled but instance DB reports "Type mismatch" | Instance DB created before the FB; FB interface changed after the DB was generated | Delete the instance DB, regenerate after the FB is compiled cleanly |
| OB1 calls an FC that compiles but produces wrong results at runtime | Local temp VAR_TEMP variable reused across networks without re-initialization |
Initialize each VAR_TEMP at the top of the FC or use distinct temporaries |
Source generated by S5-to-S7 converter lists every block on a single line with no BEGIN
|
Converter output truncated or corrupted | Re-run the conversion; verify the S5 source is not read-only; check disk space |
Compile output shows "Unknown instruction" on every line after NETWORK
|
Source opened in wrong editor (LAD/FBD) instead of STL | Right-click the source → Open with → STL Editor |
| Compilation overwrites blocks without prompting after firmware migration | Auto-overwrite flag enabled in SIMATIC Manager options | Options → Customize: disable "Overwrite without prompt"; recompile |
11. Best Practices for STL Source Maintenance
- One source file per logical unit. Keep migration sources separate from ongoing maintenance sources to avoid accidental overwrites.
- Header comments with block numbers. Insert a comment block at the top of each STL source listing every contained block number, version, and date. This aids diff/merge and review.
- External version control. STL sources are plain text — store them in Git, SVN, or TFS alongside the project. STEP 7 regenerates the binary blocks on every compile, but only the source text is diff-friendly.
-
Consistent indentation. Use two-space indentation inside
NETWORKblocks so that nested bit logic and arithmetic read cleanly. -
Explicit
NETWORKseparators. Every FC, FB, and OB network begins withNETWORKfollowed optionally byTITLE = .... This drives the LAD/FBD view if a colleague later switches representation. -
Avoid
U(/O(nesting beyond 7 levels. The STL parser stack is limited; deep nesting produces obscure "Stack overflow" compile errors. -
Use symbols, not absolute addresses. Replace
I 1.7with"EM_Stop"in the symbol table; the converter already generates symbolic operand references that are far easier to maintain.
12. Working with TIA Portal (V20)
Engineers who migrated from SIMATIC Manager to TIA Portal can still manage STL and SCL blocks as external source files. The workflow is described in the official Saving blocks as external source files documentation. The same FUNCTION ... END_FUNCTION grammar applies. Compile is invoked by right-clicking the source in the project tree and selecting Compile → Software (rebuild all blocks). Errors land in the Compile tab of the Inspector window.
FAQ
How do I compile an STL source file in STEP 7 SIMATIC Manager?
Open the STL source from the Sources folder, then press Ctrl+B or choose File → Compile. STEP 7 creates each declared block in Program Blocks. Errors appear in the Compiler Output window; double-click an error to jump to the offending line.
What causes the “VOID” compile error after an S5-to-S7 conversion?
The S5-to-S7 converter places VOID before FUNCTION. The STEP 7 grammar requires VOID after the colon: FUNCTION FC 30 : VOID. Use Find/Replace with the regex ^VOID\s+FUNCTION\s+(FC|FB|OB)\s+(\d+) and replace with FUNCTION \1 \2 : VOID.
Can I convert an FC into an FB by editing the source?
Yes. Generate source from the FC, change the declaration to FUNCTION_BLOCK FB x, replace END_FUNCTION with END_FUNCTION_BLOCK, move VAR_TEMP variables to VAR for retentive state, compile, then create an instance DB tied to the new FB.
Why do my compiled blocks not appear in Program Blocks?
The source file is typically encoded with non-ANSI characters (UTF-8 BOM, Unicode dashes, smart quotes) or opened in the LAD/FBD editor. Re-save the file as plain ANSI text and right-click → Open with → STL Editor before compiling.
Does TIA Portal accept legacy STL sources from SIMATIC Manager?
Yes. TIA Portal V20 supports external STL/SCL sources as documented in the official Siemens external source files documentation. Verify that the target S7-1500 CPU has the STL language option enabled before importing.