Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ if (BUILD_RUST)
set(Rust_CARGO_TARGET
"thumbv7em-none-eabihf"
CACHE STRING "Rust target triple")
elseif (BUILD_TARGET_PLATFORM STREQUAL "NUCLEO_F413ZH"
OR BUILD_TARGET_PLATFORM STREQUAL "NUCLEO_G474RE")
set(Rust_CARGO_TARGET
"thumbv7em-none-eabihf"
CACHE STRING "Rust target triple")
endif ()

add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/libs/3rdparty/corrosion)
Expand Down Expand Up @@ -120,6 +125,10 @@ if (BUILD_EXECUTABLE STREQUAL "referenceApp")
if (BUILD_TARGET_PLATFORM STREQUAL "S32K148EVB")
set(OPENBSW_PLATFORM_DIR
"${CMAKE_CURRENT_SOURCE_DIR}/platforms/s32k1xx")
elseif (BUILD_TARGET_PLATFORM STREQUAL "NUCLEO_F413ZH"
OR BUILD_TARGET_PLATFORM STREQUAL "NUCLEO_G474RE")
set(OPENBSW_PLATFORM_DIR
"${CMAKE_CURRENT_SOURCE_DIR}/platforms/stm32")
else ()
set(OPENBSW_PLATFORM_DIR "${CMAKE_CURRENT_SOURCE_DIR}/platforms/posix")
endif ()
Expand Down Expand Up @@ -186,6 +195,13 @@ if (BUILD_EXECUTABLE STREQUAL "unitTest")
add_subdirectory(platforms/posix/bsp/bspEepromDriver/test)
add_subdirectory(platforms/posix/bsp/socketCanTransceiver/test)

elseif (OPENBSW_PLATFORM STREQUAL "stm32")

add_subdirectory(platforms/stm32/unitTest EXCLUDE_FROM_ALL)

add_subdirectory(platforms/stm32/bsp/bxCanTransceiver/test)
add_subdirectory(platforms/stm32/bsp/bspUart/test)

elseif (OPENBSW_PLATFORM STREQUAL "s32k1xx")

add_subdirectory(platforms/s32k1xx/unitTest EXCLUDE_FROM_ALL)
Expand Down
131 changes: 131 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,99 @@
"OPENBSW_PLATFORM": "posix"
}
},
{
"name": "tests-stm32-debug",
"displayName": "Configure for testing STM32 modules (debug)",
"description": "Configure for testing STM32 modules (debug)",
"inherits": "_config-base",
"binaryDir": "${sourceDir}/build/tests/stm32/Debug",
"cacheVariables": {
"CMAKE_DEFAULT_BUILD_TYPE": "Debug",
"CMAKE_CONFIGURATION_TYPES": "Debug",
"BUILD_EXECUTABLE": "unitTest",
"OPENBSW_PLATFORM": "stm32"
}
},
{
"name": "nucleo-f413zh-freertos-gcc",
"generator": "Ninja Multi-Config",
"displayName": "NUCLEO-F413ZH FreeRTOS configuration (GCC)",
"description": "Configure for NUCLEO-F413ZH platform using ARM GCC toolchain",
"inherits": "_config-base",
"toolchainFile": "${sourceDir}/cmake/toolchains/ArmNoneEabi-gcc.cmake",
"binaryDir": "${sourceDir}/build/${presetName}",
"cacheVariables": {
"BUILD_EXECUTABLE": "referenceApp",
"BUILD_TARGET_PLATFORM": "NUCLEO_F413ZH",
"BUILD_TARGET_RTOS": "FREERTOS",
"STM32_CHIP": "STM32F413ZH",
"CMAKE_ASM_FLAGS_RELWITHDEBINFO": "-g3",
"CMAKE_CONFIGURATION_TYPES": "RelWithDebInfo;Debug;Release",
"CMAKE_C_FLAGS_RELWITHDEBINFO": "-g3 -O2 -DNDEBUG",
"CMAKE_CXX_FLAGS_RELWITHDEBINFO": "-g3 -O2 -DNDEBUG",
"CMAKE_DEFAULT_BUILD_TYPE": "RelWithDebInfo"
}
},
{
"name": "nucleo-g474re-freertos-gcc",
"generator": "Ninja Multi-Config",
"displayName": "NUCLEO-G474RE FreeRTOS configuration (GCC)",
"description": "Configure for NUCLEO-G474RE platform using ARM GCC toolchain",
"inherits": "_config-base",
"toolchainFile": "${sourceDir}/cmake/toolchains/ArmNoneEabi-gcc.cmake",
"binaryDir": "${sourceDir}/build/${presetName}",
"cacheVariables": {
"BUILD_EXECUTABLE": "referenceApp",
"BUILD_TARGET_PLATFORM": "NUCLEO_G474RE",
"BUILD_TARGET_RTOS": "FREERTOS",
"STM32_CHIP": "STM32G474RE",
"CMAKE_ASM_FLAGS_RELWITHDEBINFO": "-g3",
"CMAKE_CONFIGURATION_TYPES": "RelWithDebInfo;Debug;Release",
"CMAKE_C_FLAGS_RELWITHDEBINFO": "-g3 -O2 -DNDEBUG",
"CMAKE_CXX_FLAGS_RELWITHDEBINFO": "-g3 -O2 -DNDEBUG",
"CMAKE_DEFAULT_BUILD_TYPE": "RelWithDebInfo"
}
},
{
"name": "nucleo-f413zh-threadx-gcc",
"generator": "Ninja Multi-Config",
"displayName": "NUCLEO-F413ZH ThreadX configuration (GCC)",
"description": "Configure for NUCLEO-F413ZH platform with ThreadX using ARM GCC toolchain",
"inherits": "_config-base",
"toolchainFile": "${sourceDir}/cmake/toolchains/ArmNoneEabi-gcc.cmake",
"binaryDir": "${sourceDir}/build/${presetName}",
"cacheVariables": {
"BUILD_EXECUTABLE": "referenceApp",
"BUILD_TARGET_PLATFORM": "NUCLEO_F413ZH",
"BUILD_TARGET_RTOS": "THREADX",
"STM32_CHIP": "STM32F413ZH",
"CMAKE_ASM_FLAGS_RELWITHDEBINFO": "-g3",
"CMAKE_CONFIGURATION_TYPES": "RelWithDebInfo;Debug;Release",
"CMAKE_C_FLAGS_RELWITHDEBINFO": "-g3 -O2 -DNDEBUG",
"CMAKE_CXX_FLAGS_RELWITHDEBINFO": "-g3 -O2 -DNDEBUG",
"CMAKE_DEFAULT_BUILD_TYPE": "RelWithDebInfo"
}
},
{
"name": "nucleo-g474re-threadx-gcc",
"generator": "Ninja Multi-Config",
"displayName": "NUCLEO-G474RE ThreadX configuration (GCC)",
"description": "Configure for NUCLEO-G474RE platform with ThreadX using ARM GCC toolchain",
"inherits": "_config-base",
"toolchainFile": "${sourceDir}/cmake/toolchains/ArmNoneEabi-gcc.cmake",
"binaryDir": "${sourceDir}/build/${presetName}",
"cacheVariables": {
"BUILD_EXECUTABLE": "referenceApp",
"BUILD_TARGET_PLATFORM": "NUCLEO_G474RE",
"BUILD_TARGET_RTOS": "THREADX",
"STM32_CHIP": "STM32G474RE",
"CMAKE_ASM_FLAGS_RELWITHDEBINFO": "-g3",
"CMAKE_CONFIGURATION_TYPES": "RelWithDebInfo;Debug;Release",
"CMAKE_C_FLAGS_RELWITHDEBINFO": "-g3 -O2 -DNDEBUG",
"CMAKE_CXX_FLAGS_RELWITHDEBINFO": "-g3 -O2 -DNDEBUG",
"CMAKE_DEFAULT_BUILD_TYPE": "RelWithDebInfo"
}
},
{
"name": "tests-posix-release",
"displayName": "Configure for testing POSIX and generic modules (release)",
Expand Down Expand Up @@ -200,6 +293,37 @@
}
],
"buildPresets": [
{
"name": "tests-stm32-debug",
"displayName": "Build tests of STM32 modules (debug)",
"description": "Build tests of STM32 modules (debug)",
"configurePreset": "tests-stm32-debug",
"configuration": "Debug"
},
{
"name": "nucleo-f413zh-freertos-gcc",
"displayName": "NUCLEO-F413ZH FreeRTOS build (GCC)",
"description": "Build reference application for NUCLEO-F413ZH platform with GCC",
"configurePreset": "nucleo-f413zh-freertos-gcc"
},
{
"name": "nucleo-g474re-freertos-gcc",
"displayName": "NUCLEO-G474RE FreeRTOS build (GCC)",
"description": "Build reference application for NUCLEO-G474RE platform with GCC",
"configurePreset": "nucleo-g474re-freertos-gcc"
},
{
"name": "nucleo-f413zh-threadx-gcc",
"displayName": "NUCLEO-F413ZH ThreadX build (GCC)",
"description": "Build reference application for NUCLEO-F413ZH platform with ThreadX using GCC",
"configurePreset": "nucleo-f413zh-threadx-gcc"
},
{
"name": "nucleo-g474re-threadx-gcc",
"displayName": "NUCLEO-G474RE ThreadX build (GCC)",
"description": "Build reference application for NUCLEO-G474RE platform with ThreadX using GCC",
"configurePreset": "nucleo-g474re-threadx-gcc"
},
{
"name": "tests-posix-debug",
"displayName": "Build tests of POSIX and generic modules (debug)",
Expand Down Expand Up @@ -278,6 +402,13 @@
}
],
"testPresets": [
{
"name": "tests-stm32-debug",
"displayName": "Run tests of STM32 modules (debug)",
"description": "Run tests of STM32 modules (debug)",
"configuration": "Debug",
"configurePreset": "tests-stm32-debug"
},
{
"name": "tests-posix-debug",
"displayName": "Run tests of POSIX and generic modules (debug)",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Minimal board configuration — expanded in subsequent PRs
12 changes: 12 additions & 0 deletions executables/referenceApp/platforms/nucleo_g474re/Options.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
set(OPENBSW_PLATFORM "stm32" CACHE STRING "" FORCE)
set(STM32_CHIP "STM32G474RE" CACHE STRING "" FORCE)
set(BUILD_TARGET_RTOS "FREERTOS" CACHE STRING "")
set(PLATFORM_SUPPORT_CAN OFF CACHE BOOL "" FORCE)
set(PLATFORM_SUPPORT_IO OFF CACHE BOOL "" FORCE)
set(PLATFORM_SUPPORT_ETHERNET OFF CACHE BOOL "" FORCE)
set(PLATFORM_SUPPORT_TRANSPORT OFF CACHE BOOL "" FORCE)
set(PLATFORM_SUPPORT_UDS OFF CACHE BOOL "" FORCE)
set(PLATFORM_SUPPORT_WATCHDOG OFF CACHE BOOL "" FORCE)
set(PLATFORM_SUPPORT_MPU OFF CACHE BOOL "" FORCE)
set(PLATFORM_SUPPORT_STORAGE OFF CACHE BOOL "" FORCE)
set(PLATFORM_SUPPORT_ROM_CHECK OFF CACHE BOOL "" FORCE)
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Copyright 2024 Contributors to the Eclipse Foundation
#
# SPDX-License-Identifier: EPL-2.0

add_library(
bspConfiguration
src/bsp/stdIo/stdIo.cpp
src/bsp/uart/UartConfig.cpp)

target_include_directories(bspConfiguration PUBLIC include)

target_link_libraries(bspConfiguration PUBLIC bspUart PRIVATE bspMcu platform)
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
.. _bspconfig_nucleo_g474re:

bspConfiguration - NUCLEO-G474RE
================================

Overview
--------

The ``bspConfiguration`` module contains hardware-specific configuration for the
NUCLEO-G474RE evaluation board. Driver logic is separated from its configuration
so that users can customise a project for different boards or pin assignments
without modifying driver source code.

The STM32G474RE platform exposes a minimal set of BSP peripherals required for
the CAN reference application:

- **bspUart** — USART2 configuration (ST-LINK Virtual COM Port on PA2/PA3).
- **bspStdIo** — Standard I/O bridge that routes ``putByteToStdout`` /
``getByteFromStdin`` through the configured UART instance.

.. note::

Unlike the S32K148EVB reference application, this platform does not include
ADC, PWM, or digital I/O configuration modules because the CAN reference
application does not require analogue inputs or GPIO-driven outputs.
These modules can be added following the same configuration pattern if
a future application requires them.

Hardware Summary
^^^^^^^^^^^^^^^^

.. csv-table::
:widths: 30, 70
:width: 100%

"MCU", "STM32G474RE (Arm Cortex-M4F, 170 MHz, single-precision FPU)"
"UART peripheral", "USART2 — routed to ST-LINK/V3 Virtual COM Port"
"UART TX pin", "PA2 (AF7)"
"UART RX pin", "PA3 (AF7)"
"UART baud rate", "115 200 baud (BRR = 1476 at 170 MHz APB1)"
"CAN peripheral", "FDCAN1 (configured in CanSystem, not bspConfiguration)"

Build Integration
^^^^^^^^^^^^^^^^^

The CMake target ``bspConfiguration`` is a static library that compiles:

- ``src/bsp/stdIo/stdIo.cpp``
- ``src/bsp/uart/UartConfig.cpp``

It publicly exposes its ``include/`` directory and links against ``bspUart``,
``bspMcu``, and ``platform``.

.. toctree::
:hidden:

user/index
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
.. _bspConfig_StdIo_G474RE:

bspStdIo
========

Overview
--------

The standard I/O bridge provides the ``putByteToStdout`` and
``getByteFromStdin`` C-linkage functions required by the OpenBSW logging
framework. These functions route character-level I/O through the UART
``TERMINAL`` instance configured in :ref:`bspConfig_Uart_G474RE`.

Implementation
--------------

``stdIo.cpp`` implements two ``extern "C"`` functions that the OpenBSW
``logger`` module calls for character output and input:

.. code-block:: cpp

extern "C" void putByteToStdout(uint8_t const byte)
{
static bsp::Uart& uart
= bsp::Uart::getInstance(bsp::Uart::Id::TERMINAL);
uart.write(etl::span<uint8_t const>(&byte, 1U));
}

extern "C" int32_t getByteFromStdin()
{
static bsp::Uart& uart
= bsp::Uart::getInstance(bsp::Uart::Id::TERMINAL);
uint8_t dataByte = 0;
etl::span<uint8_t> data(&dataByte, 1U);
uart.read(data);
if (data.size() == 0)
{
return -1;
}
return data[0];
}

Function Reference
^^^^^^^^^^^^^^^^^^

.. csv-table::
:header: "Function", "Description"
:widths: 35, 65
:width: 100%

"``putByteToStdout(uint8_t byte)``", "Transmits one byte over USART2 TX (PA2). Called by the logger framework for each character of a log message. Uses polling — blocks until the UART TX register is free."
"``getByteFromStdin() → int32_t``", "Attempts to read one byte from USART2 RX (PA3). Returns the byte value (0–255) on success, or ``-1`` if no data is available. Non-blocking."

Design Decisions
----------------

**Lazy singleton initialisation**
Both functions use a ``static`` local reference to the UART instance.
The reference is resolved once on the first call and cached for all
subsequent calls, avoiding a global constructor ordering dependency.

**Polling mode**
Character I/O uses the polling UART backend. This is adequate for debug
logging at 115 200 baud but would need to be replaced with a DMA or
interrupt-driven backend for production telemetry.

**Return value convention**
``getByteFromStdin`` follows the POSIX ``getchar()`` convention: a
non-negative value represents a valid byte, and ``-1`` signals that no
input is available.

Dependencies
------------

.. csv-table::
:widths: 40, 60
:width: 100%

"``bsp/uart/UartConfig.h``", "Provides ``Uart::Id::TERMINAL`` to select the correct UART instance"
"``platform/estdint.h``", "Fixed-width integer types (``uint8_t``, ``int32_t``)"
Loading
Loading