Embedded & ECU Software

BSP Debugging Guide

A practical engineering guide to diagnosing Board Support Package behavior across a hardware prototype, device drivers, application code, and an RTOS-based firmware module.

Engineering model

How BSP fits together

A Board Support Package adapts a hardware board to the software that runs on it. Debugging therefore requires separating board-specific configuration, device-driver behavior, runtime services, and application assumptions, then checking the interfaces between them. The investigation depends on the hardware prototype, existing source code, and interface specification, with STM32 providing a representative target platform.

Core concepts

The parts of a practical BSP setup

01

Hardware adaptation

The BSP provides the board-specific software needed to make the hardware usable by the operating system or application. A mismatch here can affect many higher-level functions at once.

02

Device-driver boundary

A device driver controls a hardware peripheral through a defined interface. Debugging this boundary means checking whether configuration, requests, returned status, and observed hardware behavior agree.

03

Runtime integration

An RTOS changes how the BSP is initialized and used by firmware modules. Scheduling and runtime-service assumptions must remain consistent with the BSP interfaces.

04

Resource-constrained implementation

C is commonly used for BSP implementation, so data representation, lifetime, error handling, and shared state require explicit review during debugging.

Define the BSP boundary before debugging

Start by identifying which behavior belongs to the BSP and which behavior belongs to the surrounding firmware module.

Treat the BSP as the adaptation layer between the hardware board and the software above it. Record the board-specific initialization, device-driver interfaces, RTOS dependencies, and configuration values that are part of the BSP. This prevents an application defect from being mistaken for a hardware adaptation defect.

AreaQuestion to answerUseful evidence
Hardware adaptationWhich board behavior is configured or exposed by the BSP?Hardware prototype and existing source code
Device driverWhich interface controls the peripheral and reports status?Interface specification and driver source code
RTOS integrationWhich runtime services or scheduling assumptions does the BSP use?Existing source code and configuration
Firmware moduleWhich behavior is expected above the BSP boundary?Firmware module definition and interface specification

Establish a reproducible observation

A BSP defect is easier to isolate when the same hardware and software conditions produce the same symptom.

  1. 01

    Record the target configuration

    Identify the hardware prototype, STM32 variant, BSP configuration, RTOS usage, and firmware module involved in the behavior.

  2. 02

    Describe the observed behavior

    State what the target does, when it does it, and whether the behavior occurs during initialization, normal execution, or integration with another component.

  3. 03

    Define the expected interface behavior

    Use the interface specification to record expected inputs, outputs, status values, and sequencing at the affected boundary.

  4. 04

    Repeat without changing multiple layers

    Reproduce the behavior while keeping the BSP, device driver, and surrounding firmware module unchanged except for one controlled observation or correction.

  • Separate a failure that occurs on every execution from one that depends on runtime timing or interaction with the RTOS.
  • Compare the configured target with the actual hardware prototype rather than assuming the board matches the source-code assumptions.
  • Preserve the original observation before applying a corrective change.

Trace initialization and ownership

Many BSP failures originate from an incorrect order of setup or unclear ownership of a device-driver interface.

Review the path from board configuration through device-driver setup to the first use by the firmware module. Check that each required value is established before it is consumed, that initialization is performed by one defined owner, and that repeated initialization is either supported or prevented. When an RTOS is present, also check whether a runtime service or task can access the interface before the BSP has completed its setup.

  • Confirm that the selected hardware configuration matches the hardware prototype.
  • Check that device-driver state is initialized before an interface call can occur.
  • Check that status and error results are handled rather than discarded.
  • Check that shared BSP state has one clear owner when multiple firmware components use it.
  • Check that the interface specification and the implementation use the same data meaning and units.

Debug device-driver behavior

Device-driver debugging should move from the interface call to the peripheral result, without assuming that a successful function return proves correct hardware behavior.

ObservationPossible interpretationNext check
The interface rejects a requestInput, state, or configuration may not satisfy the defined contractCompare the call arguments and current state with the interface specification
The interface accepts a request but no expected behavior followsThe driver may not be connected correctly to the hardware or its configurationTrace the driver path and compare it with the hardware prototype
Behavior changes with RTOS activityShared state, execution order, or runtime assumptions may be involvedReview access ownership and the sequence of runtime calls
A CAN driver, LIN driver, or Ethernet driver behaves differently across targetsThe BSP may expose different board-specific configuration or driver assumptionsCompare target configuration and interface behavior across the hardware prototypes

Use the smallest complete path that demonstrates the issue: the caller, the device-driver interface, the BSP configuration, and the resulting hardware behavior. Avoid changing the firmware module and driver implementation at the same time, because that removes the distinction between an interface defect and a driver defect.

Review C implementation risks

BSP code written in C is close to hardware behavior, so small representation and lifetime errors can appear as broad integration failures.

  • Check that values passed across an interface have the expected type, range, and interpretation.
  • Check that pointers refer to valid storage for the full period in which the device driver or RTOS may use them.
  • Check that status values are not overwritten before the caller evaluates them.
  • Check that shared state is updated consistently when more than one execution context can access it.
  • Check that error paths leave the BSP and device driver in a defined state.

Review the source code from the interface declaration through the implementation and its callers. The goal is not only to find a suspicious statement, but to establish whether the same data and state assumptions are preserved across the entire BSP boundary.

Validate the correction

A correction is credible only when it restores the defined interface behavior and does not break neighboring BSP functions.

  1. 01

    Reproduce the original behavior

    Confirm that the original observation is still understood and that the test conditions are unchanged.

  2. 02

    Apply one bounded correction

    Change the relevant configuration, BSP implementation, device driver, or firmware module without mixing unrelated cleanup.

  3. 03

    Exercise the affected interface

    Test the expected inputs, outputs, status handling, and hardware behavior described by the interface specification.

  4. 04

    Check RTOS interaction

    If the BSP is used with an RTOS, repeat the behavior under the relevant execution and access conditions.

  5. 05

    Run adjacent integration checks

    Verify that related device-driver paths and firmware modules still behave as expected on the hardware prototype.

  • Keep the failing condition and corrected condition separately recorded.
  • Confirm that the correction works on the intended STM32 target rather than only in a limited execution path.
  • Update the existing source code or configuration so the reasoning behind the correction remains visible.

BSP debugging workflow by symptom

The symptom usually points to a boundary to inspect first, not to a guaranteed root cause.

SymptomFirst boundary to inspectReasoning
The firmware module cannot use a board functionBSP configuration and device-driver interfaceThe adaptation layer may not expose the expected contract
A device-driver call returns an unexpected statusInterface inputs, driver state, and error handlingThe implementation may disagree with the defined interface behavior
Behavior changes when the RTOS is activeRuntime ownership and execution orderThe same interface may be accessed under different runtime conditions
Only one hardware prototype shows the issueBoard-specific configuration and hardware assumptionsThe source code may not match that target configuration
A correction fixes one path but breaks anotherShared BSP state or incomplete integration checksThe change may have altered a dependency used by another firmware module

Engineering pitfalls

Common mistakes

  1. Treating the BSP as ordinary application code

    The BSP is tied to board behavior and device-driver contracts. Debugging only the calling firmware module can miss a configuration or adaptation defect.

  2. Assuming a successful interface call proves correct hardware behavior

    A return value may only indicate that the request was accepted. The resulting hardware behavior and status handling still need to be checked.

  3. Changing configuration and implementation together

    When several layers change at once, the engineer loses the ability to identify which assumption corrected or introduced the behavior.

  4. Ignoring RTOS execution conditions

    A BSP that works in one execution sequence may fail when runtime services or multiple firmware components access the same interface.

  5. Discarding status and error results

    Unexamined results remove evidence about where the interface contract diverges from the implementation.

  6. Testing only the original failing path

    A BSP correction can affect shared device-driver state or neighboring firmware modules, so related integration behavior must also be checked.

FAQ

BSP questions

What should be checked first when a BSP fails on a hardware prototype?
First compare the target configuration with the actual hardware prototype, then trace the affected interface from the firmware module through the device driver and BSP. Use the interface specification to define the expected behavior before changing implementation.
How can an engineer distinguish a BSP defect from a firmware-module defect?
Check whether the BSP and device-driver interface produces the specified result with controlled inputs. If the interface behavior is correct but the caller interprets it incorrectly, the issue is more likely above the BSP boundary; if the interface behavior is incorrect, continue through the BSP and driver path.
Why can an RTOS expose a BSP problem that is not visible otherwise?
The RTOS can change execution order and the conditions under which firmware components access shared BSP or device-driver state. A sequence that appears correct in isolation may fail when runtime services and other components interact with it.
Should initialization be moved into the firmware module to simplify debugging?
Not by default. First establish which layer owns initialization and which order the interface requires. Moving responsibility may hide an ownership problem and can create repeated or conflicting setup.
What evidence is most useful during BSP debugging?
The hardware prototype, relevant existing source code, configuration, interface specification, observed status results, and a repeatable description of the behavior provide the strongest starting evidence. Together they connect the intended contract to the actual implementation.

Engineering support

Discuss a BSP Project

Need focused support developing, integrating, configuring, debugging, or testing a BSP and its firmware module? Get practical engineering help grounded in your source code, interface specification, and hardware prototype.