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
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,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/bspCan/test)
add_subdirectory(platforms/stm32/bsp/bxCanTransceiver/test)

elseif (OPENBSW_PLATFORM STREQUAL "s32k1xx")

add_subdirectory(platforms/s32k1xx/unitTest EXCLUDE_FROM_ALL)
Expand Down
54 changes: 54 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,32 @@
"OPENBSW_PLATFORM": "s32k1xx"
}
},
{
"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": "tests-stm32-release",
"displayName": "Configure for testing STM32 modules (release)",
"description": "Configure for testing STM32 modules (release)",
"inherits": "_config-base",
"binaryDir": "${sourceDir}/build/tests/stm32/Release",
"cacheVariables": {
"CMAKE_DEFAULT_BUILD_TYPE": "Release",
"CMAKE_CONFIGURATION_TYPES": "Release",
"BUILD_EXECUTABLE": "unitTest",
"OPENBSW_PLATFORM": "stm32"
}
},
{
"name": "posix-freertos",
"displayName": "POSIX-FREERTOS compliant configuration",
Expand Down Expand Up @@ -228,6 +254,20 @@
"configurePreset": "tests-s32k1xx-release",
"configuration": "Release"
},
{
"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": "tests-stm32-release",
"displayName": "Build tests of STM32 modules (release)",
"description": "Build tests of STM32 modules (release)",
"configurePreset": "tests-stm32-release",
"configuration": "Release"
},
{
"name": "posix-freertos",
"displayName": "build POSIX-FREERTOS",
Expand Down Expand Up @@ -305,6 +345,20 @@
"description": "Run tests of S32K1XX modules (release)",
"configuration": "Release",
"configurePreset": "tests-s32k1xx-release"
},
{
"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-stm32-release",
"displayName": "Run tests of STM32 modules (release)",
"description": "Run tests of STM32 modules (release)",
"configuration": "Release",
"configurePreset": "tests-stm32-release"
}
]
}
2 changes: 2 additions & 0 deletions NOTICE.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ We recommend to read their licenses, as their terms may differ from the terms de
| ThreadX Linux Port | 6.4.3 | MIT | ``platforms/posix/3rdparty/threadx/LICENSE.md`` |
| CMSIS | 6.1.0 | Apache v2 | ``libs/3rdparty/cmsis/LICENSE`` |
| NXP S32K148 Headers | 1.1a | BSD-3 | ``platforms/s32k1xx/bsp/bspMcu/include/3rdparty/nxp/*.h`` |
| ST STM32F4 Device Headers | 2.6.11 | Apache v2 | ``platforms/stm32/bsp/bspMcu/include/3rdparty/st/LICENSE`` |
| ST STM32G4 Device Headers | 1.2.6 | Apache v2 | ``platforms/stm32/bsp/bspMcu/include/3rdparty/st/LICENSE`` |
| CodeCoverage | | BSD-3 | ``cmake/modules/CodeCoverage.cmake`` |

## MISRA
Expand Down
1 change: 1 addition & 0 deletions doc/dev/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ Eclipse OpenBSW is a trademark of the Eclipse Foundation.
modules/common
modules/posix
modules/s32k1xx
modules/stm32
modules/executables
modules/mocks

Expand Down
22 changes: 22 additions & 0 deletions doc/dev/modules/stm32.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
..
*******************************************************************************
Copyright (c) 2026 An Dao
This program and the accompanying materials are made available under the
terms of the Apache License Version 2.0 which is available at
https://www.apache.org/licenses/LICENSE-2.0

SPDX-License-Identifier: Apache-2.0
*******************************************************************************

STM32
=====

BSP
---

.. toctree::
:maxdepth: 1
:glob:

../../../platforms/stm32/**/doc/index
26 changes: 26 additions & 0 deletions platforms/stm32/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
if (NOT BUILD_EXECUTABLE STREQUAL "unitTest")
if (NOT DEFINED STM32_CHIP)
message(
FATAL_ERROR
"STM32_CHIP must be defined (e.g., STM32F413ZH or STM32G474RE)")
endif ()

if (STM32_CHIP STREQUAL "STM32F413ZH")
include(${CMAKE_CURRENT_LIST_DIR}/cmake/stm32f413zh.cmake)
elseif (STM32_CHIP STREQUAL "STM32G474RE")
include(${CMAKE_CURRENT_LIST_DIR}/cmake/stm32g474re.cmake)
else ()
message(
FATAL_ERROR
"Unsupported STM32_CHIP: ${STM32_CHIP}. Supported: STM32F413ZH, STM32G474RE"
)
endif ()

add_subdirectory(bsp)

# ETL implementation
add_subdirectory(etlImpl)
else ()
# Unit-test builds compile the transceivers against mock devices.
add_subdirectory(bsp)
endif ()
32 changes: 32 additions & 0 deletions platforms/stm32/bsp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
if (BUILD_EXECUTABLE STREQUAL "unitTest")
# Unit test builds: only compile transceivers (with mock devices). Skip
# hardware-dependent modules (bspMcu, bspClock, bspCan, etc.).
add_subdirectory(bxCanTransceiver)
add_subdirectory(bspUart)
else ()
add_subdirectory(bspMcu)
add_subdirectory(bspClock)
add_subdirectory(bspInterruptsImpl)
add_subdirectory(bspUart)
add_subdirectory(bspTimer)
add_subdirectory(bspIo)
add_subdirectory(bspAdc)
add_subdirectory(bspEepromDriver)
add_subdirectory(bspCan)

# CAN transceiver - selected by chip family
if (CAN_TYPE STREQUAL "BXCAN")
add_subdirectory(bxCanTransceiver)
endif ()

# Aggregated BSP target
add_library(socBsp INTERFACE)
target_link_libraries(
socBsp
INTERFACE bspClock
bspInterruptsImpl
bspIo
bspMcu
bspTimer
bspUart)
endif ()
6 changes: 6 additions & 0 deletions platforms/stm32/bsp/bspAdc/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
add_library(bspAdc src/adc/Adc.cpp)
target_include_directories(bspAdc PUBLIC include)
target_link_libraries(
bspAdc
PUBLIC bspMcu
PRIVATE platform)
54 changes: 54 additions & 0 deletions platforms/stm32/bsp/bspAdc/include/adc/Adc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/********************************************************************************
* Copyright (c) 2026 An Dao
*
* This program and the accompanying materials are made available under the
* terms of the Apache License Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0
*
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/

#pragma once

#include <mcu/mcu.h>
#include <stdint.h>

namespace bios
{

enum class AdcResolution : uint8_t
{
BITS_12 = 0U,
BITS_10 = 1U,
BITS_8 = 2U,
BITS_6 = 3U
};

struct AdcConfig
{
ADC_TypeDef* peripheral;
AdcResolution resolution;
uint8_t samplingTime; // SMPR code (0-7)
};

class Adc
{
public:
explicit Adc(AdcConfig const& config);

void init();
uint16_t readChannel(uint8_t channel);
uint16_t readTemperature();
uint16_t readVrefint();

private:
AdcConfig const fConfig;
bool fInitialized;

void enableClock();
void calibrate();
void configureChannel(uint8_t channel);
uint16_t startAndRead();
};

} // namespace bios
2 changes: 2 additions & 0 deletions platforms/stm32/bsp/bspAdc/module.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
maturity: raw
oss: true
Loading
Loading