Resolving S7-317 Insufficient Memory Error on Program Download

David Krause14 min read
S7-300SiemensTroubleshooting
Licensed PE Working through this on a live machine? A Maine-licensed engineer can take it from here — included with IMD hardware, by the hour for everything else. Book an engineer

Resolving S7-317 Insufficient Memory Error on Program Download

The SIMATIC S7-317 CPU (6ES7317-2EK14-0AB0 and variants) is a workhorse of the S7-300 family, but it presents a unique memory model that can cause confusing download failures. A common field symptom is an "Insufficient memory in CPU" or "Not enough memory space on the target module" error during a TIA Portal download, while the online diagnostics simultaneously show load memory at 90%+ free. This guide explains the root cause, walks through diagnostics, and documents the field-proven workaround of pre-loading an empty project before the real project.

1. Problem Overview

Engineers report the following scenario on a CPU 317-2 PN/DP or CPU 317-2 DP:

  • Project compiled cleanly in TIA Portal (no warnings or errors).
  • Online connection to the CPU is healthy (no PG/PC interface faults).
  • TIA Portal reports "Insufficient memory space on the target module" or "Insufficient memory in CPU" when pressing the Download button.
  • Selecting Compress in the download dialog does not resolve the error.
  • Online & Diagnostics shows the load memory is 93% free, work memory 58% free, and retentive area 15% free.
  • Yesterday the identical program downloaded without issue.

Because compression is the standard remediation for fragmented load memory, and the load memory has plenty of free space, the operator is left without a clear path forward. The naive interpretation is that the CPU is "lying" about its free space, but the cause is more subtle and tied to the S7-300 memory model.

Critical distinction: The download error is raised when the CPU cannot allocate work memory for the incoming blocks. Load memory is the cause of the error only if it is truly full; when load memory has space, the cause is almost always work memory fragmentation or accumulated online/runtime data. Compression only defragments the load memory, which is why it does not help here.

2. S7-317 Memory Architecture

Unlike the S7-400, the S7-300 has no integrated load memory. The Micro Memory Card (MMC) is mandatory for operation, and it serves three distinct purposes simultaneously.

CPU 317-2 PN/DP (6ES7317-2EK14-0AB0) memory map
Region Type Size Location Notes
Work memory, code RAM (volatile) 1 MB combined CPU module Code blocks (OB/FB/FC/DB-SYS)
Work memory, data RAM (volatile) included above CPU module DBs and runtime data
Load memory Flash (MMC) 6ES7953-8LP20-0AA0 Project, symbols, comments
Retentive memory Non-volatile RAM Up to 700 KB CPU module, backed by MMC Retentive bits, timers, counters, DB portions

According to the S7-300 CPU 31xC and CPU 31x: Technical specifications manual, the load memory is implemented entirely on the MMC. The MMC uses an internal Flash Translation Layer (FTL) that maps logical block numbers to physical pages. The CPU operating system also reserves a portion of the MMC for service data: diagnostic buffer dumps, online project shadows, system blocks (SDBs), and trace buffers.

This service data is hidden from the load-memory free-percentage calculation in TIA Portal's Online & Diagnostics, but it is still written to the MMC and counted against the file system capacity. On an 8 MB MMC, the service data area can occupy 200–600 KB depending on firmware version and number of online sessions.

3. Root Cause Analysis

Three independent, and additive, causes account for almost every S7-317 download error reported with this symptom pattern:

3.1 Work memory fragmentation

The CPU allocates work memory for code and data in fixed-size pages. When a project is modified, blocks are deleted and recreated. Deleted blocks leave holes in the page table that cannot be reused until the next STOP/RUN transition or an explicit compress operation. If the offline project has grown slightly (for example, you added a comment that increased the block length, or a single DB grew by a few bytes), the new combined size can no longer fit contiguously even though the sum of the holes is large enough.

The classic compress operation reorders the load memory but does not necessarily rebuild the work-memory page table. The CPU performs a work-memory defragmentation only on a STOP-to-RUN transition when the operating system detects that the current layout cannot satisfy the allocation request.

3.2 MMC service data accumulation

Each online session writes diagnostic data, SDB versioning metadata, and connection descriptions to the MMC. Over months of operation, this service data can grow to several hundred KB. The percentage shown in Online & Diagnostics is calculated as:

Load memory free % = (Total MMC size − Active project blocks) / Total MMC size

Service data is excluded from the numerator, so the free-percentage display is misleading. The user can still have 93% free of project blocks, but the MMC file system can be 70% full when service data is included. When the TIA Portal downloader writes a new SDB or a new online shadow, the write can fail with an out-of-space condition.

3.3 Online project mismatch

If the offline project in TIA Portal has been compiled and changed (for example, a recompile, a hardware re-detect, or a re-import of symbols) without a corresponding download, the CPU's online shadow of the project diverges from the new compiled output. The downloader then attempts to write the delta, but the online shadow's internal block table does not match, and the CPU rejects the write as an internal consistency error that surfaces as an "insufficient memory" event.

4. Memory Diagnostic Procedure

Before applying the workaround, capture a memory snapshot to confirm the root cause. All steps use TIA Portal V16 or later; equivalent steps for STEP 7 V5.5+ are noted where they differ.

  1. Open the project in TIA Portal and establish an online connection to the S7-317.
  2. Right-click the CPU in the project tree and choose Online & Diagnostics.
  3. Navigate to Diagnostics > Memory and record the four values: load memory free, work memory free, retentive memory free, and total MMC size.
  4. Navigate to Diagnostics > Diagnostic buffer and read the most recent entries. Look for event IDs W:16#0300 0007 ("Insufficient memory for function") or W:16#0300 0001 ("Communication fault") right before the download attempt.
  5. Open the project tree, right-click the CPU, and choose PLC > Assign PLC name to confirm the PG/PC interface is correct. A wrong interface target can produce a misleading memory error.
  6. Navigate to Diagnostics > Operating mode and confirm the CPU is in RUN or STOP, and that no write-protected switch is engaged.
  7. For STEP 7 V5.5+ users, open SIMATIC Manager > PLC > Module Information and select the Memory tab for an equivalent view.

Compare the recorded values against the expected values for the specific CPU variant. Reference values for the most common S7-317 variants are listed below.

S7-317 family memory specifications
CPU order number Work memory (code+data) Max MMC size Retentive memory (max)
6ES7317-2AK14-0AB0 (CPU 317-2 DP) 1 MB 8 MB 700 KB
6ES7317-2EK14-0AB0 (CPU 317-2 PN/DP) 1 MB 8 MB 700 KB
6ES7317-2FJ14-0AB0 (CPU 317F-2 PN/DP) 1.5 MB 8 MB 700 KB
6ES7317-6FF04-0AB0 (CPU 317T-2 DP) 1.5 MB 8 MB 700 KB
6ES7317-7UL10-0AB0 (CPU 317-2 PN/DP FW 3.3) 1 MB 8 MB 700 KB
The 8 MB MMC catalog number 6ES7953-8LP20-0AA0 is the largest MMC released for the S7-300 family. Going larger is not an option; the S7-300 MMC controller hardware cannot address MMCs above 8 MB.

5. Resolution: The Empty-Project Workaround

The field-proven workaround documented in the source incident is to download an empty project first, then download the real project. The mechanism is not obvious, so it is worth understanding what each step does.

5.1 Procedure

  1. Create a new TIA Portal project with the same S7-317 hardware configuration as the target CPU. No program blocks, no HMI tags, no technology objects.
  2. Compile the empty project to HW-only.
  3. Connect online, right-click the CPU, and choose Download to device > Hardware configuration only. This writes a minimal SDB set to the MMC and forces the CPU to reinitialize its online shadow.
  4. Wait for the CPU to return to RUN (or STOP if it was stopped). Confirm the diagnostic buffer is cleared of the previous memory error.
  5. Open the original project. Compile the software (full recompile, not incremental).
  6. Download the full project to the same CPU. Select Download to device > All and accept the prompt to overwrite existing blocks.
  7. Verify the download completes without the memory error.

5.2 Why it works

Step 3 is the key. The download of an empty hardware configuration performs three actions internally:

  • It deletes the previous online project shadow from the MMC, freeing the service-data area.
  • It issues a STOP-to-RUN transition to the CPU, which triggers an internal work-memory defragmentation.
  • It rewrites the SDB set to a clean state, which aligns the offline and online configuration tables.

After step 3, the CPU is in a "factory fresh" memory state from the perspective of the downloader, even though the retentive data is preserved. The subsequent full download in step 6 succeeds because the work-memory page table has been rebuilt and the MMC service-data area is empty.

Data block re-initialization: The empty-project download does not reset DB contents. The CPU is not factory-reset; only the project shadow and SDBs are rewritten. The actual runtime values in the work-memory data area are untouched as long as the same DB numbers are present after the subsequent full download. If the offline project has new DBs, those DBs will be initialized to their initial values during the second download, which is normal TIA Portal behavior.

6. Alternative Resolution Paths

If the empty-project workaround is not practical (for example, on a live plant where you cannot tolerate a CPU restart), the following alternatives are available, in order of preference.

6.1 MMC swap and external cleanup

  1. Stop the CPU, place the mode selector in STOP, and power down.
  2. Remove the MMC (6ES7953-8LP20-0AA0 or smaller).
  3. Insert the MMC into a USB card reader connected to a Windows PC. Modern laptops and most desktops have built-in SD/MMC readers; the Siemens PG field programmer has one as well.
  4. Open the MMC in Windows Explorer. The card presents as a removable drive with three folders: SIMATIC, FWUPDATE (if used for firmware), and CRASHES (a directory of crash dumps).
  5. Delete the contents of the CRASHES directory, but do not delete or modify anything inside SIMATIC.
  6. Safely eject the MMC, reinsert it into the CPU, and power up. The CPU will boot and report a "Memory card inconsistent" diagnostic event; this is normal and clears on the next full download.
Do not format the MMC as FAT in Windows. The S7-300 MMC uses a custom Flash Translation Layer. Formatting destroys the partition table and requires a Siemens Field PG with the S7 MMC service tool to restore.

6.2 MRES (memory reset)

  1. Place the mode selector in STOP.
  2. Rotate to MRES and hold for 3 seconds until the STOP LED flashes slowly.
  3. Release and rotate back to MRES within 3 seconds. The CPU performs a full memory reset, including a work-memory clear and an MMC rescan.
  4. The CPU returns to STOP with all data blocks initialized. The retentive area is also cleared.

MRES is a more aggressive option than the empty-project workaround. Use it only when the empty-project approach has failed, and only when losing the retentive data is acceptable.

6.3 Firmware update to latest service pack

Firmware versions before V3.3 of the CPU 317-2 PN/DP and V2.6 of the CPU 317-2 DP have known issues with work-memory allocation in large projects. The CPU 317-2 PN/DP firmware V3.3.17 release includes a fix for work-memory page-table handling that reduces the frequency of these false "insufficient memory" errors. Updating requires the MMC-based firmware update procedure documented in the S7-300 Operations List manual.

6.4 Project-side remediation

  • Enable Optimized block access only where the application requires it; non-optimized blocks consume more work memory per DB.
  • Reduce the number of M bits, timers, and counters; each instance uses retentive memory space.
  • Consolidate FB instances into multi-instance DBs to reduce per-instance overhead.
  • Move large read-only data (recipe arrays, language text) to the load memory (MMC) and access by slice; the load memory is not a bottleneck because it has free space.

7. MMC Specifications and Compatibility

The MMC is the load memory and the only non-volatile storage in the S7-317. Siemens publishes the following catalog numbers for S7-300-compatible MMCs in the S7-300 Micro Memory Card (MMC) catalog page.

S7-300 MMC catalog numbers and capacities
Order number Capacity For CPU 317? Notes
6ES7953-8LF20-0AA0 512 KB Yes Minimum for firmware update
6ES7953-8LG20-0AA0 1 MB Yes
6ES7953-8LJ20-0AA0 2 MB Yes
6ES7953-8LL20-0AA0 4 MB Yes
6ES7953-8LM20-0AA0 4 MB (long) Yes Industrial temperature grade
6ES7953-8LP20-0AA0 8 MB Yes Maximum supported

Each MMC has a write-cycle endurance rated at 100,000 erase cycles per block. In continuous-data-logging applications where DBs are written to the MMC frequently, the MMC can wear out, producing exactly the same "insufficient memory" symptom because the FTL cannot allocate new physical pages. Replacing the MMC with a fresh 6ES7953-8LP20-0AA0 and re-downloading the project is a definitive fix in that scenario. Wear-out can be confirmed by reading the diagnostic buffer for event W:16×0352 "Flash error during write to MMC".

8. Preventive Measures

  • Schedule periodic memory resets. On machines with high online-churn (frequent HMI tag updates, recipe downloads, drive parameter changes), perform a full download to a freshly compressed MMC at every major maintenance interval (typically every 6–12 months).
  • Avoid offline/online drift. Recompile in TIA Portal only when you intend to download. An offline recompile that is not downloaded leaves the CPU's online shadow out of date, and the next full download can fail with a memory error.
  • Use the largest available MMC. The 8 MB MMC gives the FTL more wear-leveling headroom, which extends the service life of the card under continuous write workloads.
  • Keep firmware current. Apply the latest service packs; they include work-memory allocator fixes that reduce fragmentation.
  • Monitor the diagnostic buffer for memory-related warnings. Event W:16×0300 0007 ("Insufficient memory for function") is a leading indicator. Address it before the next scheduled download.
  • Enable project consistency checks. In TIA Portal, choose Project > Compiler > Show all messages and resolve any warnings about block size or instance depth before attempting a download.

9. Verification

After applying the workaround, confirm the fix with the following checks:

  1. Download completes without error. TIA Portal displays a green checkmark and the success summary.
  2. Online & Diagnostics > Memory now shows load memory free at the expected post-download value (typically 80–90%).
  3. The diagnostic buffer shows event W:16×0301 0001 ("Download of project data successful") as the most recent user action.
  4. CPU is in RUN and the application behaves identically to before the failed download attempt. All IO, drives, and HMI are responsive.
  5. Retentive values (counters, timers, persistent DB tags) match the values from before the download.

If the same error recurs within hours or days of the recovery, the root cause is more likely MMC wear-out. Replace the MMC and repeat the empty-project workaround on the new card.

10. Related Diagnostic Buffer Event IDs

Memory-related event IDs in the CPU 317 diagnostic buffer
Event ID Meaning Recommended action
W:16×0300 0001 Communication fault / PG request failed Verify PG/PC interface and cable
W:16×0300 0007 Insufficient memory for function Apply empty-project workaround or MRES
W:16×0351 Memory card inserted/removed Confirm physical seating; reinsert MMC
W:16×0352 Flash error during write to MMC Replace MMC; back up project first
W:16×0301 0001 Download of project data successful No action; informational
W:16×0301 0002 Download of project data failed Check event ID that immediately follows for the root cause

Why does the S7-317 report "insufficient memory" when load memory is 93% free?

The error refers to work memory, not load memory. Work memory in the S7-317 is volatile RAM in the CPU module, separate from the MMC. The CPU allocates work memory in pages; when a project is recompiled or its blocks change, the new allocation can fail to fit contiguously even though the total free work memory is large enough. The free-percentage display in TIA Portal shows only load memory, which is why the numbers appear inconsistent.

Why does downloading an empty project fix the download error?

The empty-project download performs three actions: it deletes the online project shadow from the MMC (clearing accumulated service data), it forces a STOP-to-RUN transition (triggering an internal work-memory defragmentation), and it rewrites the SDB set to a clean state. After these actions, the work-memory page table is rebuilt and the MMC service-data area is empty, allowing the subsequent full download to allocate space without conflict.

Does the empty-project workaround reset my data blocks?

No, as long as the subsequent full download includes the same DB numbers. The empty-project download clears the online project shadow and the SDBs, but the runtime values in the work-memory data area remain intact. When the full project is downloaded next, existing DBs retain their current values, and any new DBs are initialized to their declared initial values per normal TIA Portal behavior. The MRES procedure is a separate, more aggressive option that does clear all data.

Can I use a larger than 8 MB MMC in the S7-317?

No. The 6ES7953-8LP20-0AA0 (8 MB) is the largest MMC released for the S7-300 family. The S7-300 MMC controller hardware cannot address MMCs above 8 MB, regardless of the physical card capacity. If you need more load memory, you must migrate to an S7-1500 with its larger SD card support.

How do I read the MMC contents on a PC?

Remove the MMC from the CPU while the CPU is powered down and insert it into a USB MMC/SD card reader on a Windows PC. The card appears as a removable drive with three folders: SIMATIC, FWUPDATE, and CRASHES. You can safely delete the contents of CRASHES to reclaim space. Do not modify or delete anything inside SIMATIC, and do not format the card, because the S7-300 MMC uses a custom Flash Translation Layer that Windows cannot recreate.

Back to blog