Skip to content

feat(stm32): DoCAN transport addressing and UDS session config#421

Draft
nhuvaoanh123 wants to merge 10 commits into
eclipse-openbsw:mainfrom
nhuvaoanh123:stm32-pr-9
Draft

feat(stm32): DoCAN transport addressing and UDS session config#421
nhuvaoanh123 wants to merge 10 commits into
eclipse-openbsw:mainfrom
nhuvaoanh123:stm32-pr-9

Conversation

@nhuvaoanh123
Copy link
Copy Markdown

Purpose of this PR

  • Bugfix
  • New Feature
  • Documentation Update
  • Other

Description

Ninth PR in the STM32 platform series. Configures the DoCAN transport layer for standard UDS diagnostics over CAN bus.

Changes

  1. DoCanSystem.cpp: Update CAN addressing from S32K defaults (0x02A/0x0F0) to standard OBD-II UDS IDs (0x7E0 request / 0x7E8 response)
  2. appConfig.h: Set LOGICAL_ADDRESS to 0x0600 for STM32 diagnostics
  3. DiagSession.cpp: Add AppProgrammingSession — uses programming-session response byte (0x02) without triggering the bootloader shutdown sequence, keeping the UDS dispatcher alive for service-level programming operations

Cross-platform impact

The DiagSession change modifies shared code but only activates when PLATFORM_SUPPORT_UDS=ON. Existing S32K and POSIX builds are unaffected — they use different session configurations and don't register this session type.

Milestone

With PR 10 (UDS services), TesterPresent (0x3E) works end-to-end over CAN bus.

Depends on #420 (PR 8: F413ZH). PR 9 of 10.

Related Issues

Part of STM32 platform port — see #413 for series overview.

Breaking Changes

  • Yes
  • No — shared code change is additive and behind feature flag

Test Plan

  1. Build all presets (posix, S32K, STM32) — verify no regressions
  2. CAN bus test: send TesterPresent (0x3E 00) to 0x7E0, expect positive response on 0x7E8

Regression Tests

Have tests been added/updated? [ ] Yes [x] No — integration tests via CAN bus in PR 10

nhuvaoanh123 pushed a commit to nhuvaoanh123/openbsw that referenced this pull request Mar 30, 2026
Add full UDS (Unified Diagnostic Services) implementation for STM32:

Services:
- DiagnosticSessionControl (0x10) — default, extended, programming sessions
- SecurityAccess (0x27) — seed/key authentication
- TesterPresent (0x3E) — keep-alive
- ClearDiagnosticInformation (0x14) — DTC clearing
- ReadDtcInformation (0x19) — DTC status and snapshot reads
- ControlDtcSetting (0x85) — DTC recording on/off
- RoutineControl (0x31) — demo routine for HIL testing
- WriteDataByIdentifier (0x2E) — VIN write support
- DTC Manager — centralized fault code lifecycle

Architecture:
- All services compile conditionally (PLATFORM_SUPPORT_UDS=ON)
- UdsSystem task manages service registration and lifecycle
- Stm32-prefixed files are STM32-specific implementations
- Existing posix/S32K UDS services are unmodified

Qualification: 405 HIL tests passing across 5 test suites on NUCLEO-G474RE.
Test dashboard: https://nhuvaoanh123.github.io/openbsw/

Depends on eclipse-openbsw#421 (PR 9: DoCAN transport). PR 10 of 10.
nhuvaoanh123 pushed a commit to nhuvaoanh123/openbsw that referenced this pull request Mar 30, 2026
Add full UDS (Unified Diagnostic Services) implementation for STM32:

Services:
- DiagnosticSessionControl (0x10) — default, extended, programming sessions
- SecurityAccess (0x27) — seed/key authentication
- TesterPresent (0x3E) — keep-alive
- ClearDiagnosticInformation (0x14) — DTC clearing
- ReadDtcInformation (0x19) — DTC status and snapshot reads
- ControlDtcSetting (0x85) — DTC recording on/off
- RoutineControl (0x31) — demo routine for HIL testing
- WriteDataByIdentifier (0x2E) — VIN write support
- DTC Manager — centralized fault code lifecycle

Architecture:
- All services compile conditionally (PLATFORM_SUPPORT_UDS=ON)
- UdsSystem task manages service registration and lifecycle
- Stm32-prefixed files are STM32-specific implementations
- Existing posix/S32K UDS services are unmodified

Qualification: 405 HIL tests passing across 5 test suites on NUCLEO-G474RE.
Test dashboard: https://nhuvaoanh123.github.io/openbsw/

Depends on eclipse-openbsw#421 (PR 9: DoCAN transport). PR 10 of 10.
…ker scripts

Add the STM32 platform skeleton for OpenBSW, supporting both STM32F4 (bxCAN)
and STM32G4 (FDCAN) families via chip selection cmake variables.

Contents:
- ARM CMSIS-Core headers (Cortex-M4) with Apache-2.0 license
- ST device headers for STM32F413ZH and STM32G474RE
- GNU AS startup files and linker scripts for both chips
- Chip-selection cmake modules (stm32f413zh.cmake, stm32g474re.cmake)
- CMakePresets for NUCLEO-G474RE and NUCLEO-F413ZH (FreeRTOS + ThreadX)
- Platform integration in root CMakeLists.txt

Milestone: `cmake --preset nucleo-g474re-freertos-gcc` configures successfully.
This is PR 1 of 10 — subsequent PRs add BSP drivers, RTOS config, and UDS services.
nhuvaoanh123 added a commit to nhuvaoanh123/openbsw that referenced this pull request Mar 30, 2026
Add full UDS (Unified Diagnostic Services) implementation for STM32:

Services:
- DiagnosticSessionControl (0x10) — default, extended, programming sessions
- SecurityAccess (0x27) — seed/key authentication
- TesterPresent (0x3E) — keep-alive
- ClearDiagnosticInformation (0x14) — DTC clearing
- ReadDtcInformation (0x19) — DTC status and snapshot reads
- ControlDtcSetting (0x85) — DTC recording on/off
- RoutineControl (0x31) — demo routine for HIL testing
- WriteDataByIdentifier (0x2E) — VIN write support
- DTC Manager — centralized fault code lifecycle

Architecture:
- All services compile conditionally (PLATFORM_SUPPORT_UDS=ON)
- UdsSystem task manages service registration and lifecycle
- Stm32-prefixed files are STM32-specific implementations
- Existing posix/S32K UDS services are unmodified

Qualification: 405 HIL tests passing across 5 test suites on NUCLEO-G474RE.
Test dashboard: https://nhuvaoanh123.github.io/openbsw/

Depends on eclipse-openbsw#421 (PR 9: DoCAN transport). PR 10 of 10.
nhuvaoanh123 added a commit to nhuvaoanh123/openbsw that referenced this pull request Mar 31, 2026
Add full UDS (Unified Diagnostic Services) implementation for STM32:

Services:
- DiagnosticSessionControl (0x10) — default, extended, programming sessions
- SecurityAccess (0x27) — seed/key authentication
- TesterPresent (0x3E) — keep-alive
- ClearDiagnosticInformation (0x14) — DTC clearing
- ReadDtcInformation (0x19) — DTC status and snapshot reads
- ControlDtcSetting (0x85) — DTC recording on/off
- RoutineControl (0x31) — demo routine for HIL testing
- WriteDataByIdentifier (0x2E) — VIN write support
- DTC Manager — centralized fault code lifecycle

Architecture:
- All services compile conditionally (PLATFORM_SUPPORT_UDS=ON)
- UdsSystem task manages service registration and lifecycle
- Stm32-prefixed files are STM32-specific implementations
- Existing posix/S32K UDS services are unmodified

Qualification: 405 HIL tests passing across 5 test suites on NUCLEO-G474RE.
Test dashboard: https://nhuvaoanh123.github.io/openbsw/

Depends on eclipse-openbsw#421 (PR 9: DoCAN transport). PR 10 of 10.
nhuvaoanh123 and others added 9 commits March 31, 2026 14:26
- Change .fpu softvfp → fpv4-sp-d16 in both startup files to match
  the toolchain's -mfloat-abi=hard -mfpu=fpv4-sp-d16 flags. The
  mismatch produced conflicting ELF float ABI attributes.

- Add FPU CP10/CP11 enable block to F413 startup (was only in G474).
  Both are Cortex-M4F; ThreadX needs early FPU access since it does
  not enable the FPU in its port (unlike FreeRTOS port.c).

- Add OPENBSW_PLATFORM=stm32 branch to root CMakeLists.txt so the
  tests-stm32-debug preset no longer hits FATAL_ERROR at configure.
  Add platforms/stm32/unitTest/ stub (mirrors s32k1xx pattern).

- Add ST BSD-3-Clause LICENSE file under 3rdparty/st/ for vendor
  header compliance — the headers reference a LICENSE file that was
  missing.

- Remove dead bspMcu/linker/ scripts and STM32_LINKER_SCRIPT cmake
  variables. The real linker scripts live in each board's
  referenceApp/platforms/*/main/linkerscript/application.ld, wired
  via PROP_LINKER_SCRIPT on the startUp INTERFACE library.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add the complete low-level BSP layer for STM32F4/G4 platforms:

- bspClock: Clock configuration for F4 (100 MHz HSE) and G4 (170 MHz PLL)
- bspUart: USART2 driver with DMA-ready ring buffer, VCP console output
- bspIo: GPIO driver with pin configuration (AF, push-pull, speed)
- bspTimer: SysTick-based system timer for RTOS tick and delays
- bspInterruptsImpl: NVIC interrupt enable/disable (FreeRTOS + ThreadX variants)
- bspAdc: ADC driver for analog inputs
- bspEepromDriver: Flash-based EEPROM emulation
- etlImpl: ETL clock and print backends for STM32
- bspConfiguration: NUCLEO-G474RE board pin mappings (UART, LED, etc.)

Milestone: cmake configures with all BSP modules. Boots to UART console with PR 6 (RTOS).
Depends on PR 1 (MCU foundation). PR 2 of 10.
Add CAN peripheral drivers for both STM32 CAN controller variants:

- BxCanDevice: Basic Extended CAN controller (STM32F4 family)
- FdCanDevice: Flexible Data-rate CAN controller (STM32G4 family)
- BxCanTransceiver: OpenBSW CAN transceiver adapter for bxCAN
- Unit test infrastructure (unitTest CMakeLists, mock device headers)

The bspCan module uses compile-time chip selection (CAN_TYPE=BXCAN|FDCAN)
to build only the relevant driver. Tests use mock register headers for
host-based verification.

Milestone: `cmake --preset tests-stm32-debug` configures. Tests run in CI Docker.
Depends on eclipse-openbsw#414 (PR 2: BSP drivers). PR 3 of 10.
Add the FdCanTransceiver module — OpenBSW ICanTransceiver adapter for
STM32G4 FDCAN peripheral. Mirrors the bxCAN transceiver from PR 3 but
supports FD frames (up to 64-byte payload) and extended filter banks.

- FdCanTransceiver: ICanTransceiver implementation for FDCAN
- Unit tests with mock FdCanDevice headers for host verification
- Updated bsp/CMakeLists.txt for CAN_TYPE-based transceiver selection

Milestone: `cmake --preset tests-stm32-debug` configures with both transceivers.
Depends on eclipse-openbsw#415 (PR 3: bxCAN/FDCAN drivers). PR 4 of 10.
Add fault handling and watchdog safety infrastructure:

- hardFaultHandler: ARM Cortex-M4 HardFault handler in assembly — captures
  register state (R0-R12, LR, PC, PSR) for post-mortem analysis
- safeBspMcuWatchdog: IWDG (Independent Watchdog) driver with configurable
  timeout, kick interface, and reset-reason detection
- SafetyManager: Board-level safety lifecycle integration for G474RE

Milestone: cmake configures with safety modules. Watchdog activates with PR 6 (RTOS).
Depends on eclipse-openbsw#416 (PR 4: FDCAN transceiver). PR 5 of 10.
Add FreeRTOS Cortex-M4 port and NUCLEO-G474RE board configuration,
producing the first bootable reference app binary for STM32.

- FreeRTOS CM4 SysTick port (port.c, portmacro.h) for Cortex-M4F
- FreeRTOS core configuration (FreeRTOSConfig.h for G474RE)
- Board main: startup, clock init, UART console, task creation
- StaticBsp: lifecycle hooks for BSP init/shutdown
- CAN system integration (ISR handlers, CanSystem task)
- Application linker script for G474RE (512 KB Flash, 128 KB SRAM)
- Full Options.cmake with platform feature flags

OpenBSW now supports dual-RTOS design: FreeRTOS (this PR) and ThreadX (PR 7),
selectable at configure time via BUILD_TARGET_RTOS.

Milestone: `cmake --build --preset nucleo-g474re-freertos-gcc` produces bootable ELF.
Reference app boots on NUCLEO-G474RE with UART console output.
Depends on eclipse-openbsw#417 (PR 5: safety). PR 6 of 10.
Add ThreadX RTOS support as an alternative to FreeRTOS for STM32 platforms:

- ThreadX Cortex-M4 GNU port (context save/restore, scheduler, timer ISR)
- tx_port.h and tx_user.h configuration for G474RE
- ThreadX core configuration module for NUCLEO-G474RE
- Updated platform CMakeLists for dual-RTOS selection

Build with: `cmake --preset nucleo-g474re-threadx-gcc`

The main/ directory (PR 6) already contains ThreadX-specific hooks
(tx_initialize_low_level.S, tx_execution_initialize.c, osHooks/threadx/).

Milestone: `cmake --preset nucleo-g474re-threadx-gcc` configures successfully.
Depends on eclipse-openbsw#418 (PR 6: FreeRTOS board config). PR 7 of 10.
Add complete board configuration for NUCLEO-F413ZH (STM32F413ZH):
- Cortex-M4, 100 MHz, 1.5 MB Flash, 320 KB SRAM
- bxCAN peripheral (vs FDCAN on G474RE)
- Board-specific BSP configuration, safety manager, FreeRTOS/ThreadX configs
- Main application with CAN ISR handlers and lifecycle hooks
- Linker script for F413ZH memory layout

Both boards now build and boot:
- G474RE (FDCAN): `cmake --preset nucleo-g474re-freertos-gcc`
- F413ZH (bxCAN): `cmake --preset nucleo-f413zh-freertos-gcc`

Milestone: F413ZH builds and produces bootable ELF.
Depends on eclipse-openbsw#419 (PR 7: ThreadX). PR 8 of 10.
Configure the DoCAN transport layer for STM32 UDS diagnostics:

- DoCanSystem: Change CAN addressing from S32K default (0x02A/0x0F0) to
  standard OBD-II UDS IDs (0x7E0 request / 0x7E8 response)
- appConfig: Update LOGICAL_ADDRESS to 0x0600 for STM32 diagnostics
- DiagSession: Add AppProgrammingSession that uses programming-session
  response byte (0x02) without triggering bootloader shutdown — enables
  UDS programming-session services while keeping the dispatcher alive

The DiagSession change affects all platforms but only activates when
PLATFORM_SUPPORT_UDS=ON. Existing S32K and POSIX builds are unaffected
as they use different session configurations.

Milestone: TesterPresent (0x3E) works end-to-end over CAN bus with PR 10.
Depends on eclipse-openbsw#420 (PR 8: F413ZH). PR 9 of 10.
nhuvaoanh123 added a commit to nhuvaoanh123/openbsw that referenced this pull request Mar 31, 2026
Add full UDS (Unified Diagnostic Services) implementation for STM32:

Services:
- DiagnosticSessionControl (0x10) — default, extended, programming sessions
- SecurityAccess (0x27) — seed/key authentication
- TesterPresent (0x3E) — keep-alive
- ClearDiagnosticInformation (0x14) — DTC clearing
- ReadDtcInformation (0x19) — DTC status and snapshot reads
- ControlDtcSetting (0x85) — DTC recording on/off
- RoutineControl (0x31) — demo routine for HIL testing
- WriteDataByIdentifier (0x2E) — VIN write support
- DTC Manager — centralized fault code lifecycle

Architecture:
- All services compile conditionally (PLATFORM_SUPPORT_UDS=ON)
- UdsSystem task manages service registration and lifecycle
- Stm32-prefixed files are STM32-specific implementations
- Existing posix/S32K UDS services are unmodified

Qualification: 405 HIL tests passing across 5 test suites on NUCLEO-G474RE.
Test dashboard: https://nhuvaoanh123.github.io/openbsw/

Depends on eclipse-openbsw#421 (PR 9: DoCAN transport). PR 10 of 10.
@nhuvaoanh123 nhuvaoanh123 marked this pull request as draft May 1, 2026 19:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant