Home Learning Paths ECU Lab Assessments Interview Preparation Arena Pricing Log In Sign Up

0x34 RequestDownload Service

Pythonrequest_download.py
#!/usr/bin/env python3
# 0x34 RequestDownload: declare block to program
import udsoncan, struct
from udsoncan.client import Client

def request_download(client, start_addr: int, length: int,
                     compression: int = 0x00, encrypting: int = 0x00) -> int:
    # dataFormatIdentifier: high nibble = compression, low nibble = encryption
    dfi = (compression << 4) | encrypting

    # memoryAddressAndLengthFormatIdentifier: 0x44 = 4-byte address, 4-byte length
    memloc = udsoncan.MemoryLocation(
        address=start_addr,
        memorysize=length,
        address_format=32,
        memorysize_format=32
    )

    resp = client.request_download(dfi, memloc)
    if not resp.positive:
        raise Exception(f"RequestDownload failed: NRC 0x{resp.code:02X}")

    # ECU responds with maxNumberOfBlockLength (max bytes per TransferData block)
    max_block_len = resp.service_data.max_block_length
    print(f"RequestDownload OK: max block length = {max_block_len} bytes")
    return max_block_len

# Example:
# max_block = request_download(client, 0x80080000, 0x00780000)  # 7.5 MB application block
# NRC 0x31 (requestOutOfRange): address/size not matching any configured block
# NRC 0x33 (securityAccessDenied): Level 2 not unlocked

0x36 TransferData Sequence

Pythontransfer_data.py
#!/usr/bin/env python3
# 0x36 TransferData: send firmware in blocks
import udsoncan, math
from pathlib import Path

def transfer_firmware(client, image_path: str, max_block_len: int):
    image = Path(image_path).read_bytes()
    total_size = len(image)
    block_size = max_block_len - 2  # subtract 0x36 SID + sequence byte overhead

    num_blocks = math.ceil(total_size / block_size)
    print(f"Transferring {total_size:,} bytes in {num_blocks} blocks "
          f"of {block_size} bytes each")

    for seq in range(1, num_blocks + 1):
        offset = (seq - 1) * block_size
        chunk  = image[offset : offset + block_size]

        resp = client.transfer_data(seq & 0xFF, chunk)  # sequence wraps 0x00–0xFF
        if not resp.positive:
            raise Exception(f"TransferData block {seq} failed: NRC 0x{resp.code:02X}")

        # Progress
        pct = (seq / num_blocks) * 100
        print(f"  Block {seq}/{num_blocks} ({pct:.0f}%) — {len(chunk)} bytes", end="
")

        # NRC 0x71 (transferDataSuspended): ECU ran out of buffer; retry after delay
        # NRC 0x72 (generalProgrammingFailure): flash write error; abort programming

    print(f"
Transfer complete: {total_size:,} bytes sent")

0x37 RequestTransferExit

0x37 RequestTransferExit and Post-Transfer Verification
  Tester → ECU:  0x37                              (end transfer)
  ECU verifies internal CRC over received data:
  ├── Match:    ECU → Tester: 0x77 [transferResponseParameterRecord]
  │             (may include CRC in response for tester verification)
  └── Mismatch: ECU → Tester: 0x7F 0x37 0x72 (generalProgrammingFailure)
                → tester must restart from 0x34 RequestDownload

  What ECU checks at 0x37:
  ├── CRC-32 or SHA-256 of received data matches expected (from OTA manifest)
  ├── Block sequence counter: all expected sequences received
  └── Length: total bytes received == declared length in 0x34

  Tester-side verification (optional but recommended):
  ├── Read back block via 0x23 ReadMemoryByAddress or checksum DID
  └── Compare with expected hash from release manifest

Transfer Error Handling and Recovery

ErrorNRCRecovery Action
Flash write error0x72 generalProgrammingFailureRe-erase block (0x31); restart from 0x34
Wrong sequence number0x24 requestSequenceErrorRe-send from last confirmed sequence; or restart
Buffer overflow in ECU0x71 transferDataSuspendedWait 500ms; retry same block
Wrong block length0x13 incorrectMessageLengthCheck max_block_length from 0x34 response; reduce block size
S3 timeout during transferSession reset → ECU back in DefaultTesterPresent must be sent every 2s; automation critical

Summary

The 0x34/0x36/0x37 triplet is the core flash transfer protocol. The max block length from the 0x34 response is the most important parameter — it defines the maximum TransferData payload size and directly controls programming throughput. Over CAN at 500 kbit/s with 8-byte frames: a 256-byte block takes ~40 ms; for a 4 MB application, that's 16,000 blocks × 40 ms = 640 seconds without pipelining. Over DoIP/Ethernet with 4 kB blocks, the same transfer takes ~2 seconds. Block size optimisation is the single biggest throughput lever in flash programming.

🔬 Deep Dive — Core Concepts Expanded

This section builds on the foundational concepts covered above with additional technical depth, edge cases, and configuration nuances that separate competent engineers from experts. When working on production ECU projects, the details covered here are the ones most commonly responsible for integration delays and late-phase defects.

Key principles to reinforce:

  • Configuration over coding: In AUTOSAR and automotive middleware environments, correctness is largely determined by ARXML configuration, not application code. A correctly implemented algorithm can produce wrong results due to a single misconfigured parameter.
  • Traceability as a first-class concern: Every configuration decision should be traceable to a requirement, safety goal, or architecture decision. Undocumented configuration choices are a common source of regression defects when ECUs are updated.
  • Cross-module dependencies: In tightly integrated automotive software stacks, changing one module's configuration often requires corresponding updates in dependent modules. Always perform a dependency impact analysis before submitting configuration changes.

🏭 How This Topic Appears in Production Projects

  • Project integration phase: The concepts covered in this lesson are most commonly encountered during ECU integration testing — when multiple software components from different teams are combined for the first time. Issues that were invisible in unit tests frequently surface at this stage.
  • Supplier/OEM interface: This is a topic that frequently appears in technical discussions between Tier-1 ECU suppliers and OEM system integrators. Engineers who can speak fluently about these details earn credibility and are often brought into critical design review meetings.
  • Automotive tool ecosystem: Vector CANoe/CANalyzer, dSPACE tools, and ETAS INCA are the standard tools used to validate and measure the correct behaviour of the systems described in this lesson. Familiarity with these tools alongside the conceptual knowledge dramatically accelerates debugging in real projects.

⚠️ Common Mistakes and How to Avoid Them

  1. Assuming default configuration is correct: Automotive software tools ship with default configurations that are designed to compile and link, not to meet project-specific requirements. Every configuration parameter needs to be consciously set. 'It compiled' is not the same as 'it is correctly configured'.
  2. Skipping documentation of configuration rationale: In a 3-year ECU project with team turnover, undocumented configuration choices become tribal knowledge that disappears when engineers leave. Document why a parameter is set to a specific value, not just what it is set to.
  3. Testing only the happy path: Automotive ECUs must behave correctly under fault conditions, voltage variations, and communication errors. Always test the error handling paths as rigorously as the nominal operation. Many production escapes originate in untested error branches.
  4. Version mismatches between teams: In a multi-team project, the BSW team, SWC team, and system integration team may use different versions of the same ARXML file. Version management of all ARXML files in a shared repository is mandatory, not optional.

📊 Industry Note

Engineers who master both the theoretical concepts and the practical toolchain skills covered in this course are among the most sought-after professionals in the automotive software industry. The combination of AUTOSAR standards knowledge, safety engineering understanding, and hands-on configuration experience commands premium salaries at OEMs and Tier-1 suppliers globally.

← PreviousReprogramming Sequence OverviewNext →RoutineControl (0x31): Erase, Verify, Check