From cc55c0aea586e41624a24e8c8fccd8fb30480788 Mon Sep 17 00:00:00 2001 From: Liviu Ionescu Date: Mon, 23 Oct 2023 16:27:38 +0300 Subject: [PATCH] add platforms m3 m4f --- tests/package.json | 194 +++++++++++++-- tests/platform-qemu-cortex-m3/CMakeLists.txt | 146 ++++++++++++ tests/platform-qemu-cortex-m3/README.md | 55 +++++ .../cmake/dependencies-folders.cmake | 38 +++ .../cmake/platform-options.cmake | 128 ++++++++++ .../include/micro-os-plus/platform.h | 26 +++ .../include/micro-os-plus/platform/config.h | 38 +++ tests/platform-qemu-cortex-m3/meson.build | 220 ++++++++++++++++++ tests/platform-qemu-cortex-m3/meson/cross.ini | 22 ++ .../meson/dependencies-folders/meson.build | 50 ++++ .../meson/platform-options/meson.build | 135 +++++++++++ tests/platform-qemu-cortex-m4f/CMakeLists.txt | 147 ++++++++++++ tests/platform-qemu-cortex-m4f/README.md | 55 +++++ .../cmake/dependencies-folders.cmake | 40 ++++ .../cmake/platform-options.cmake | 128 ++++++++++ .../include/micro-os-plus/platform.h | 26 +++ .../include/micro-os-plus/platform/config.h | 38 +++ tests/platform-qemu-cortex-m4f/meson.build | 214 +++++++++++++++++ .../platform-qemu-cortex-m4f/meson/cross.ini | 22 ++ .../meson/dependencies-folders/meson.build | 50 ++++ .../meson/platform-options/meson.build | 136 +++++++++++ 21 files changed, 1888 insertions(+), 20 deletions(-) create mode 100644 tests/platform-qemu-cortex-m3/CMakeLists.txt create mode 100644 tests/platform-qemu-cortex-m3/README.md create mode 100644 tests/platform-qemu-cortex-m3/cmake/dependencies-folders.cmake create mode 100644 tests/platform-qemu-cortex-m3/cmake/platform-options.cmake create mode 100644 tests/platform-qemu-cortex-m3/include/micro-os-plus/platform.h create mode 100644 tests/platform-qemu-cortex-m3/include/micro-os-plus/platform/config.h create mode 100644 tests/platform-qemu-cortex-m3/meson.build create mode 100644 tests/platform-qemu-cortex-m3/meson/cross.ini create mode 100644 tests/platform-qemu-cortex-m3/meson/dependencies-folders/meson.build create mode 100644 tests/platform-qemu-cortex-m3/meson/platform-options/meson.build create mode 100644 tests/platform-qemu-cortex-m4f/CMakeLists.txt create mode 100644 tests/platform-qemu-cortex-m4f/README.md create mode 100644 tests/platform-qemu-cortex-m4f/cmake/dependencies-folders.cmake create mode 100644 tests/platform-qemu-cortex-m4f/cmake/platform-options.cmake create mode 100644 tests/platform-qemu-cortex-m4f/include/micro-os-plus/platform.h create mode 100644 tests/platform-qemu-cortex-m4f/include/micro-os-plus/platform/config.h create mode 100644 tests/platform-qemu-cortex-m4f/meson.build create mode 100644 tests/platform-qemu-cortex-m4f/meson/cross.ini create mode 100644 tests/platform-qemu-cortex-m4f/meson/dependencies-folders/meson.build create mode 100644 tests/platform-qemu-cortex-m4f/meson/platform-options/meson.build diff --git a/tests/package.json b/tests/package.json index dd0cefa..6e18e9d 100644 --- a/tests/package.json +++ b/tests/package.json @@ -120,12 +120,16 @@ ], "test-cortex-cmake": [ "xpm run test-qemu-cortex-m0-cmake", + "xpm run test-qemu-cortex-m3-cmake", + "xpm run test-qemu-cortex-m4f-cmake", "xpm run test-qemu-cortex-m7f-cmake", "xpm run test-qemu-cortex-a15-cmake", "xpm run test-qemu-cortex-a72-cmake" ], "test-cortex-meson": [ "xpm run test-qemu-cortex-m0-meson", + "xpm run test-qemu-cortex-m3-meson", + "xpm run test-qemu-cortex-m4f-meson", "xpm run test-qemu-cortex-m7f-meson", "xpm run test-qemu-cortex-a15-meson", "xpm run test-qemu-cortex-a72-meson" @@ -306,6 +310,22 @@ "xpm run build --config qemu-cortex-m0-cmake-release", "xpm run test --config qemu-cortex-m0-cmake-release" ], + "test-qemu-cortex-m3-cmake": [ + "xpm run prepare --config qemu-cortex-m3-cmake-debug", + "xpm run build --config qemu-cortex-m3-cmake-debug", + "xpm run test --config qemu-cortex-m3-cmake-debug", + "xpm run prepare --config qemu-cortex-m3-cmake-release", + "xpm run build --config qemu-cortex-m3-cmake-release", + "xpm run test --config qemu-cortex-m3-cmake-release" + ], + "test-qemu-cortex-m4f-cmake": [ + "xpm run prepare --config qemu-cortex-m4f-cmake-debug", + "xpm run build --config qemu-cortex-m4f-cmake-debug", + "xpm run test --config qemu-cortex-m4f-cmake-debug", + "xpm run prepare --config qemu-cortex-m4f-cmake-release", + "xpm run build --config qemu-cortex-m4f-cmake-release", + "xpm run test --config qemu-cortex-m4f-cmake-release" + ], "test-qemu-cortex-m7f-cmake": [ "xpm run prepare --config qemu-cortex-m7f-cmake-debug", "xpm run build --config qemu-cortex-m7f-cmake-debug", @@ -346,14 +366,6 @@ "xpm run build --config qemu-riscv-rv64imafdc-cmake-release", "xpm run test --config qemu-riscv-rv64imafdc-cmake-release" ], - "test-qemu-cortex-m7f-meson": [ - "xpm run prepare --config qemu-cortex-m7f-meson-debug", - "xpm run build --config qemu-cortex-m7f-meson-debug", - "xpm run test --config qemu-cortex-m7f-meson-debug", - "xpm run prepare --config qemu-cortex-m7f-meson-release", - "xpm run build --config qemu-cortex-m7f-meson-release", - "xpm run test --config qemu-cortex-m7f-meson-release" - ], "test-qemu-cortex-m0-meson": [ "xpm run prepare --config qemu-cortex-m0-meson-debug", "xpm run build --config qemu-cortex-m0-meson-debug", @@ -362,6 +374,30 @@ "xpm run build --config qemu-cortex-m0-meson-release", "xpm run test --config qemu-cortex-m0-meson-release" ], + "test-qemu-cortex-m3-meson": [ + "xpm run prepare --config qemu-cortex-m3-meson-debug", + "xpm run build --config qemu-cortex-m3-meson-debug", + "xpm run test --config qemu-cortex-m3-meson-debug", + "xpm run prepare --config qemu-cortex-m3-meson-release", + "xpm run build --config qemu-cortex-m3-meson-release", + "xpm run test --config qemu-cortex-m3-meson-release" + ], + "test-qemu-cortex-m4f-meson": [ + "xpm run prepare --config qemu-cortex-m4f-meson-debug", + "xpm run build --config qemu-cortex-m4f-meson-debug", + "xpm run test --config qemu-cortex-m4f-meson-debug", + "xpm run prepare --config qemu-cortex-m4f-meson-release", + "xpm run build --config qemu-cortex-m4f-meson-release", + "xpm run test --config qemu-cortex-m4f-meson-release" + ], + "test-qemu-cortex-m7f-meson": [ + "xpm run prepare --config qemu-cortex-m7f-meson-debug", + "xpm run build --config qemu-cortex-m7f-meson-debug", + "xpm run test --config qemu-cortex-m7f-meson-debug", + "xpm run prepare --config qemu-cortex-m7f-meson-release", + "xpm run build --config qemu-cortex-m7f-meson-release", + "xpm run test --config qemu-cortex-m7f-meson-release" + ], "test-qemu-cortex-a72-meson": [ "xpm run prepare --config qemu-cortex-a72-meson-debug", "xpm run build --config qemu-cortex-a72-meson-debug", @@ -437,6 +473,10 @@ "link-deps-cortex-cmake": [ "xpm run link-deps --config qemu-cortex-m7f-cmake-debug", "xpm run link-deps --config qemu-cortex-m7f-cmake-release", + "xpm run link-deps --config qemu-cortex-m4f-cmake-debug", + "xpm run link-deps --config qemu-cortex-m4f-cmake-release", + "xpm run link-deps --config qemu-cortex-m3-cmake-debug", + "xpm run link-deps --config qemu-cortex-m3-cmake-release", "xpm run link-deps --config qemu-cortex-m0-cmake-debug", "xpm run link-deps --config qemu-cortex-m0-cmake-release", "xpm run link-deps --config qemu-cortex-a72-cmake-debug", @@ -447,6 +487,10 @@ "link-deps-cortex-meson": [ "xpm run link-deps --config qemu-cortex-m7f-meson-debug", "xpm run link-deps --config qemu-cortex-m7f-meson-release", + "xpm run link-deps --config qemu-cortex-m4f-meson-debug", + "xpm run link-deps --config qemu-cortex-m4f-meson-release", + "xpm run link-deps --config qemu-cortex-m3-meson-debug", + "xpm run link-deps --config qemu-cortex-m3-meson-release", "xpm run link-deps --config qemu-cortex-m0-meson-debug", "xpm run link-deps --config qemu-cortex-m0-meson-release", "xpm run link-deps --config qemu-cortex-a72-meson-debug", @@ -513,6 +557,10 @@ "clean-cortex-cmake": [ "xpm run clean --config qemu-cortex-m7f-cmake-debug --ignore-errors", "xpm run clean --config qemu-cortex-m7f-cmake-release --ignore-errors", + "xpm run clean --config qemu-cortex-m4f-cmake-debug --ignore-errors", + "xpm run clean --config qemu-cortex-m4f-cmake-release --ignore-errors", + "xpm run clean --config qemu-cortex-m3-cmake-debug --ignore-errors", + "xpm run clean --config qemu-cortex-m3-cmake-release --ignore-errors", "xpm run clean --config qemu-cortex-m0-cmake-debug --ignore-errors", "xpm run clean --config qemu-cortex-m0-cmake-release --ignore-errors", "xpm run clean --config qemu-cortex-a72-cmake-debug --ignore-errors", @@ -523,6 +571,10 @@ "clean-cortex-meson": [ "xpm run clean --config qemu-cortex-m7f-meson-debug --ignore-errors", "xpm run clean --config qemu-cortex-m7f-meson-release --ignore-errors", + "xpm run clean --config qemu-cortex-m4f-meson-debug --ignore-errors", + "xpm run clean --config qemu-cortex-m4f-meson-release --ignore-errors", + "xpm run clean --config qemu-cortex-m3-meson-debug --ignore-errors", + "xpm run clean --config qemu-cortex-m3-meson-release --ignore-errors", "xpm run clean --config qemu-cortex-m0-meson-debug --ignore-errors", "xpm run clean --config qemu-cortex-m0-meson-release --ignore-errors", "xpm run clean --config qemu-cortex-a72-meson-debug --ignore-errors", @@ -1262,7 +1314,7 @@ "buildType": "Debug", "platformName": "qemu-cortex-m7f", "toolchainFileName": "arm-none-eabi-gcc.cmake", - "shortConfigurationName": "q1d" + "shortConfigurationName": "m7d" } }, "qemu-cortex-m7f-cmake-release": { @@ -1271,7 +1323,61 @@ ], "properties": { "buildType": "MinSizeRel", - "shortConfigurationName": "q1r" + "shortConfigurationName": "m7r" + } + }, + "qemu-cortex-m4f-cmake-debug": { + "inherit": [ + "short-win-paths-properties", + "cmake-actions", + "cortexm-actions", + "arm-cmsis-core-dependencies", + "arm-none-eabi-gcc-dependencies", + "bare-metal-dependencies", + "cortexm-dependencies", + "qemu-arm-dependencies" + ], + "properties": { + "buildType": "Debug", + "platformName": "qemu-cortex-m4f", + "toolchainFileName": "arm-none-eabi-gcc.cmake", + "shortConfigurationName": "m4d" + } + }, + "qemu-cortex-m4f-cmake-release": { + "inherit": [ + "qemu-cortex-m4f-cmake-debug" + ], + "properties": { + "buildType": "MinSizeRel", + "shortConfigurationName": "m4r" + } + }, + "qemu-cortex-m3-cmake-debug": { + "inherit": [ + "short-win-paths-properties", + "cmake-actions", + "cortexm-actions", + "arm-cmsis-core-dependencies", + "arm-none-eabi-gcc-dependencies", + "bare-metal-dependencies", + "cortexm-dependencies", + "qemu-arm-dependencies" + ], + "properties": { + "buildType": "Debug", + "platformName": "qemu-cortex-m3", + "toolchainFileName": "arm-none-eabi-gcc.cmake", + "shortConfigurationName": "m3d" + } + }, + "qemu-cortex-m3-cmake-release": { + "inherit": [ + "qemu-cortex-m3-cmake-debug" + ], + "properties": { + "buildType": "MinSizeRel", + "shortConfigurationName": "m3r" } }, "qemu-cortex-m0-cmake-debug": { @@ -1289,7 +1395,7 @@ "buildType": "Debug", "platformName": "qemu-cortex-m0", "toolchainFileName": "arm-none-eabi-gcc.cmake", - "shortConfigurationName": "q2d" + "shortConfigurationName": "m0d" } }, "qemu-cortex-m0-cmake-release": { @@ -1298,7 +1404,7 @@ ], "properties": { "buildType": "MinSizeRel", - "shortConfigurationName": "q2r" + "shortConfigurationName": "m0r" } }, "qemu-cortex-a72-cmake-debug": { @@ -1315,7 +1421,7 @@ "buildType": "Debug", "platformName": "qemu-cortex-a72", "toolchainFileName": "aarch64-none-elf-gcc.cmake", - "shortConfigurationName": "q3d" + "shortConfigurationName": "a7d" } }, "qemu-cortex-a72-cmake-release": { @@ -1324,7 +1430,7 @@ ], "properties": { "buildType": "MinSizeRel", - "shortConfigurationName": "q3r" + "shortConfigurationName": "a7r" } }, "qemu-cortex-a15-cmake-debug": { @@ -1341,7 +1447,7 @@ "buildType": "Debug", "platformName": "qemu-cortex-a15", "toolchainFileName": "arm-none-eabi-gcc.cmake", - "shortConfigurationName": "q4d" + "shortConfigurationName": "a1d" } }, "qemu-cortex-a15-cmake-release": { @@ -1350,7 +1456,7 @@ ], "properties": { "buildType": "MinSizeRel", - "shortConfigurationName": "q4r" + "shortConfigurationName": "a1r" } }, "qemu-riscv-rv32imac-cmake-debug": { @@ -1367,7 +1473,7 @@ "buildType": "Debug", "platformName": "qemu-riscv-rv32imac", "toolchainFileName": "riscv-none-elf-gcc.cmake", - "shortConfigurationName": "q5d" + "shortConfigurationName": "v3d" } }, "qemu-riscv-rv32imac-cmake-release": { @@ -1376,7 +1482,7 @@ ], "properties": { "buildType": "MinSizeRel", - "shortConfigurationName": "q5r" + "shortConfigurationName": "v3r" } }, "qemu-riscv-rv64imafdc-cmake-debug": { @@ -1393,7 +1499,7 @@ "buildType": "Debug", "platformName": "qemu-riscv-rv64imafdc", "toolchainFileName": "riscv-none-elf-gcc.cmake", - "shortConfigurationName": "q6d" + "shortConfigurationName": "v6d" } }, "qemu-riscv-rv64imafdc-cmake-release": { @@ -1402,7 +1508,7 @@ ], "properties": { "buildType": "MinSizeRel", - "shortConfigurationName": "q6r" + "shortConfigurationName": "v6r" } }, "qemu-cortex-m7f-meson-debug": { @@ -1429,6 +1535,54 @@ "buildType": "minsize" } }, + "qemu-cortex-m4f-meson-debug": { + "inherit": [ + "cortexm-actions", + "meson-cross-actions", + "arm-cmsis-core-dependencies", + "arm-none-eabi-gcc-dependencies", + "bare-metal-dependencies", + "cortexm-dependencies", + "qemu-arm-dependencies" + ], + "properties": { + "buildType": "debug", + "platformName": "qemu-cortex-m4f", + "toolchainFileName": "arm-none-eabi-gcc-{{ os.platform }}.ini" + } + }, + "qemu-cortex-m4f-meson-release": { + "inherit": [ + "qemu-cortex-m4f-meson-debug" + ], + "properties": { + "buildType": "minsize" + } + }, + "qemu-cortex-m3-meson-debug": { + "inherit": [ + "cortexm-actions", + "meson-cross-actions", + "arm-cmsis-core-dependencies", + "arm-none-eabi-gcc-dependencies", + "bare-metal-dependencies", + "cortexm-dependencies", + "qemu-arm-dependencies" + ], + "properties": { + "buildType": "debug", + "platformName": "qemu-cortex-m3", + "toolchainFileName": "arm-none-eabi-gcc-{{ os.platform }}.ini" + } + }, + "qemu-cortex-m3-meson-release": { + "inherit": [ + "qemu-cortex-m3-meson-debug" + ], + "properties": { + "buildType": "minsize" + } + }, "qemu-cortex-m0-meson-debug": { "inherit": [ "cortexm-actions", diff --git a/tests/platform-qemu-cortex-m3/CMakeLists.txt b/tests/platform-qemu-cortex-m3/CMakeLists.txt new file mode 100644 index 0000000..df630f2 --- /dev/null +++ b/tests/platform-qemu-cortex-m3/CMakeLists.txt @@ -0,0 +1,146 @@ +# ----------------------------------------------------------------------------- +# +# This file is part of the µOS++ distribution. +# (https://github.com/micro-os-plus/) +# Copyright (c) 2022 Liviu Ionescu. All rights reserved. +# +# Permission to use, copy, modify, and/or distribute this software +# for any purpose is hereby granted, under the terms of the MIT license. +# +# If a copy of the license was not distributed with this file, it can +# be obtained from https://opensource.org/licenses/MIT/. +# +# ----------------------------------------------------------------------------- + +message(VERBOSE "Processing 'tests/platform-qemu-cortex-m3'...") + +# ----------------------------------------------------------------------------- + +# set(xpack_create_listing true) +# set(xpack_create_hex true) + +# ----------------------------------------------------------------------------- + +# Define the tests executables. +function(add_test_executable name) + add_executable(${name}) + + set_target_properties(${name} + + PROPERTIES + OUTPUT_NAME "${name}" + ) + + # Include folders. + # `tests/platform-qemu-cortex-m3/include` was added globally. + target_include_directories(${name} PRIVATE + "../include" + ) + + message(VERBOSE "A+ -I tests/include") + + # Application sources. + target_sources(${name} PRIVATE + "../src/${name}.cpp" + ) + + message(VERBOSE "A+ tests/src/${name}.cpp") + + target_compile_definitions(${name} PRIVATE + + # None. + ) + + target_compile_options(${name} PRIVATE + + # None. + ) + + target_link_options(${name} PRIVATE + -Wl,-Map,platform-bin/${name}-map.txt + + # -v + ) + + target_link_libraries(${name} PRIVATE + + # Tested library. + micro-os-plus::micro-test-plus + + # Portable dependencies. + micro-os-plus::diag-trace + + # Platform specific dependencies. + micro-os-plus::platform # bring device & architecture too + + micro-os-plus::semihosting + micro-os-plus::startup + ) + + # TODO use add_custom_target() + # https://cmake.org/cmake/help/v3.20/command/add_custom_command.html + add_custom_command(TARGET ${name} POST_BUILD + COMMAND ${CMAKE_SIZE} --format=berkeley "$" + ) + + if(xpack_create_hex) + add_custom_command(TARGET ${name} POST_BUILD + COMMAND ${CMAKE_OBJCOPY} -O ihex "$" "$.hex" + ) + endif() + + if(xpack_create_listing) + add_custom_command(TARGET ${name} POST_BUILD + COMMAND ${CMAKE_OBJDUMP} --source --all-headers --demangle --line-numbers --wide "$" > ${name}-list.txt + VERBATIM + ) + endif() + + message(VERBOSE "A> ${name}") +endfunction() + +# ----------------------------------------------------------------------------- + +# sample-test +if(ENABLE_SAMPLE_TEST) + add_test_executable(sample-test) + + add_test( + NAME "sample-test" + + COMMAND qemu-system-arm${extension} + --machine mps2-an385 + --cpu cortex-m3 + --kernel sample-test.elf + --nographic + -d unimp,guest_errors + --semihosting-config enable=on,target=native,arg=sample-test,arg=one,arg=two + ) +endif() + +# ----------------------------------------------------------------------------- + +# unit-test +if(ENABLE_UNIT_TEST) + add_test_executable(unit-test) + + target_link_libraries(unit-test PRIVATE + micro-os-plus::micro-test-plus + ) + + add_test( + NAME "unit-test" + + COMMAND qemu-system-arm${extension} + --machine mps2-an385 + --cpu cortex-m3 + --kernel unit-test.elf + --nographic + -d unimp,guest_errors + --semihosting-config enable=on,target=native,arg=unit-test + + # --semihosting-config arg=--verbose + ) +endif() + +# ----------------------------------------------------------------------------- diff --git a/tests/platform-qemu-cortex-m3/README.md b/tests/platform-qemu-cortex-m3/README.md new file mode 100644 index 0000000..f343492 --- /dev/null +++ b/tests/platform-qemu-cortex-m3/README.md @@ -0,0 +1,55 @@ +# platform-qemu-cortex-m3 + +Support files for building Cortex-M3 application to run on the +QEMU "mps2-an385" emulated board (which is a Cortex-M3 board). + +## Include folders + +The following folders should be passed to the compiler during the build: + +- `include-config` +- `include-platform` + +The header files to be included in user projects are: + +```cpp +#include +#include +``` + +## Source files + +The source files to be added to user projects are: + +- none + +## Memory range + +The applications are built for the following memory range: + +- FLASH: 0x0000_0000-0x007F_FFFF (8 MB) +- RAM: 0x2000_0000-0x207F_FFFF (8 MB) +- HEAP: 0x2100_0000-0x21FF_FFFF (16 MB) +- stack: 0x2200_0000 + +The heap and stack are set automatically in `_startup()` to the values +returned by `SEMIHOSTING_SYS_HEAPINFO`. + +## QEMU invocation + +To run tests, pass the ELF file and the arguments: + +```sh +qemu-system-arm --machine mps2-an365 --cpu cortex-m3 --nographic -d unimp,guest_errors --kernel "unit-test.elf" --semihosting-config enable=on,target=native,arg=unit-test +``` + +For debug sessions start QEMU in GDB server mode by passing both `-s -S`: + +```sh +qemu-system-arm --machine mps2-an5365 --cpu cortex-m3 --nographic -d unimp,guest_errors -s -S --semihosting-config enable=on,target=native,arg=test +``` + +## Links + +- [QEMU Arm](https://www.qemu.org/docs/master/system/target-arm.html) +- [virt](https://www.qemu.org/docs/master/system/arm/virt.html) diff --git a/tests/platform-qemu-cortex-m3/cmake/dependencies-folders.cmake b/tests/platform-qemu-cortex-m3/cmake/dependencies-folders.cmake new file mode 100644 index 0000000..cf30fcb --- /dev/null +++ b/tests/platform-qemu-cortex-m3/cmake/dependencies-folders.cmake @@ -0,0 +1,38 @@ +# ----------------------------------------------------------------------------- +# +# This file is part of the µOS++ distribution. +# (https://github.com/micro-os-plus/) +# Copyright (c) 2022 Liviu Ionescu. All rights reserved. +# +# Permission to use, copy, modify, and/or distribute this software +# for any purpose is hereby granted, under the terms of the MIT license. +# +# If a copy of the license was not distributed with this file, it can +# be obtained from https://opensource.org/licenses/MIT/. +# +# ----------------------------------------------------------------------------- + +# Define a list of folders where the platform dependencies are located. + +# ----------------------------------------------------------------------------- + +# Required in devices-qemu-cortexm. +set(xpack_device_compile_definition "MICRO_OS_PLUS_DEVICE_QEMU_CORTEX_M3") + +set(xpack_platform_compile_definition "MICRO_OS_PLUS_PLATFORM_QEMU_CORTEX_M3") + +# ----------------------------------------------------------------------------- +set(xpack_dependencies_folders + + # The BINARY_DIR is the `build/` folder. + "${CMAKE_BINARY_DIR}/xpacks/@xpack-3rd-party/arm-cmsis-core" + "${CMAKE_BINARY_DIR}/xpacks/@micro-os-plus/architecture-cortexm" + "${CMAKE_BINARY_DIR}/xpacks/@micro-os-plus/devices-qemu-cortexm" + "${CMAKE_BINARY_DIR}/xpacks/@micro-os-plus/semihosting" + "${CMAKE_BINARY_DIR}/xpacks/@micro-os-plus/startup" + + # The SOURCE_DIR is the `tests` folder. + "${CMAKE_SOURCE_DIR}/xpacks/@micro-os-plus/diag-trace" +) + +# ----------------------------------------------------------------------------- diff --git a/tests/platform-qemu-cortex-m3/cmake/platform-options.cmake b/tests/platform-qemu-cortex-m3/cmake/platform-options.cmake new file mode 100644 index 0000000..fe674aa --- /dev/null +++ b/tests/platform-qemu-cortex-m3/cmake/platform-options.cmake @@ -0,0 +1,128 @@ +# ----------------------------------------------------------------------------- +# +# This file is part of the µOS++ distribution. +# (https://github.com/micro-os-plus/) +# Copyright (c) 2022-2023 Liviu Ionescu. All rights reserved. +# +# Permission to use, copy, modify, and/or distribute this software +# for any purpose is hereby granted, under the terms of the MIT license. +# +# If a copy of the license was not distributed with this file, it can +# be obtained from https://opensource.org/licenses/mit/. +# +# ----------------------------------------------------------------------------- + +# This file creates the platform specific library. + +message(VERBOSE "Including 'tests/platform-qemu-cortex-m3/cmake/platform.cmake'...") + +# ----------------------------------------------------------------------------- + +# Validate. +if(NOT DEFINED xpack_platform_compile_definition) + message(FATAL_ERROR "Define xpack_platform_compile_definition in ${PLATFORM_NAME}/cmake/dependencies.cmake") +endif() + +# ----------------------------------------------------------------------------- + +# Define the platform library. +add_library(platform-qemu-cortex-m3-interface INTERFACE EXCLUDE_FROM_ALL) + +target_include_directories(platform-qemu-cortex-m3-interface INTERFACE + + # This file is included from the tests folder. + "platform-${PLATFORM_NAME}/include" +) + +target_sources(platform-qemu-cortex-m3-interface INTERFACE + + # None. +) + +target_compile_definitions(platform-qemu-cortex-m3-interface INTERFACE + "${xpack_platform_compile_definition}" + + # Full POSIX conformance: + # https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap02.html#tag_02_01_03 + # _POSIX_C_SOURCE=200809L + + # For S_IREAD + _GNU_SOURCE +) + +set(xpack_platform_common_args + -mcpu=cortex-m3 + -mthumb + -mfloat-abi=soft + + # -fno-move-loop-invariants + + # Embedded builds must be warning free. + -Werror + + # -flto fails to run on QEMU. + # $<$:-flto> + # $<$:-flto> + $<$:-fno-omit-frame-pointer> + + # ... libs-c/src/stdlib/exit.c:132:46 + # $<$:-Wno-missing-attributes> + + # $<$:-fxxx> + + # https://cmake.org/cmake/help/v3.20/manual/cmake-generator-expressions.7.html?highlight=compile_language#genex:COMPILE_LANGUAGE + # $<$:-fno-exceptions> + # $<$:-fno-rtti> + # $<$:-fno-use-cxa-atexit> + $<$:-fno-threadsafe-statics> +) + +target_compile_options(platform-qemu-cortex-m3-interface INTERFACE + ${xpack_platform_common_args} +) + +# When `-flto` is used, the compile options must be passed to the linker too. +target_link_options(platform-qemu-cortex-m3-interface INTERFACE + + # -v + ${xpack_platform_common_args} + + -nostartfiles + + # --specs=rdimon.specs -Wl,--start-group -lgcc -lc -lc -lm -lrdimon -Wl,--end-group + + # Force the linker to keep the interrupt vectors which otherwise + # are not referred from anywhere. + # -u_interrupt_vectors + + # nano has no exceptions. + # -specs=nano.specs + -Wl,--gc-sections + + # .elf has a LOAD segment with RWX permissions (GCC 12) + -Wl,--no-warn-rwx-segment + + # Including files from other packages is not very nice, but functional. + # Use absolute paths, otherwise set -L. + -T${CMAKE_BINARY_DIR}/xpacks/@micro-os-plus/devices-qemu-cortexm/linker-scripts/mem-mps2-an385.ld + -T${CMAKE_BINARY_DIR}/xpacks/@micro-os-plus/architecture-cortexm/linker-scripts/sections-flash.ld + + # -T${CMAKE_BINARY_DIR}/xpacks/@micro-os-plus/architecture-cortexm/linker-scripts/sections-ram.ld +) + +target_link_libraries(platform-qemu-cortex-m3-interface INTERFACE + micro-os-plus::common-options + micro-os-plus::devices-qemu-cortexm +) + +if(COMMAND xpack_display_target_lists) + xpack_display_target_lists(platform-qemu-cortex-m3-interface) +endif() + +# ----------------------------------------------------------------------------- + +# Aliases. +add_library(micro-os-plus::platform ALIAS platform-qemu-cortex-m3-interface) +message(VERBOSE "> micro-os-plus::platform -> platform-qemu-cortex-m3-interface") + +# ----------------------------------------------------------------------------- diff --git a/tests/platform-qemu-cortex-m3/include/micro-os-plus/platform.h b/tests/platform-qemu-cortex-m3/include/micro-os-plus/platform.h new file mode 100644 index 0000000..78e7200 --- /dev/null +++ b/tests/platform-qemu-cortex-m3/include/micro-os-plus/platform.h @@ -0,0 +1,26 @@ +/* + * This file is part of the µOS++ distribution. + * (https://github.com/micro-os-plus/) + * Copyright (c) 2022 Liviu Ionescu. All rights reserved. + * + * Permission to use, copy, modify, and/or distribute this software + * for any purpose is hereby granted, under the terms of the MIT license. + * + * If a copy of the license was not distributed with this file, it can + * be obtained from https://opensource.org/licenses/MIT/. + */ + +#ifndef MICRO_OS_PLUS_PLATFORM_H_ +#define MICRO_OS_PLUS_PLATFORM_H_ + +#include + +// ---------------------------------------------------------------------------- + +// ... + +// ---------------------------------------------------------------------------- + +#endif /* MICRO_OS_PLUS_PLATFORM_H_ */ + +// ---------------------------------------------------------------------------- diff --git a/tests/platform-qemu-cortex-m3/include/micro-os-plus/platform/config.h b/tests/platform-qemu-cortex-m3/include/micro-os-plus/platform/config.h new file mode 100644 index 0000000..6dd152d --- /dev/null +++ b/tests/platform-qemu-cortex-m3/include/micro-os-plus/platform/config.h @@ -0,0 +1,38 @@ +/* + * This file is part of the µOS++ distribution. + * (https://github.com/micro-os-plus/) + * Copyright (c) 2022 Liviu Ionescu. All rights reserved. + * + * Permission to use, copy, modify, and/or distribute this software + * for any purpose is hereby granted, under the terms of the MIT license. + * + * If a copy of the license was not distributed with this file, it can + * be obtained from https://opensource.org/licenses/MIT/. + */ + +#ifndef MICRO_OS_PLUS_PLATFORM_CONFIG_H_ +#define MICRO_OS_PLUS_PLATFORM_CONFIG_H_ + +// ---------------------------------------------------------------------------- + +// On bare-metal platforms, tests are semihosted applications. +#define MICRO_OS_PLUS_USE_SEMIHOSTING + +#define MICRO_OS_PLUS_INCLUDE_SEMIHOSTING_SYSCALLS +#define MICRO_OS_PLUS_INCLUDE_SEMIHOSTING_STARTUP + +#define MICRO_OS_PLUS_INCLUDE_STARTUP +#define MICRO_OS_PLUS_INCLUDE_SBRK +#define MICRO_OS_PLUS_INCLUDE_EXIT + +#if defined(MICRO_OS_PLUS_TRACE) +// #define MICRO_OS_PLUS_USE_TRACE_SEMIHOSTING_DEBUG +#define MICRO_OS_PLUS_USE_TRACE_SEMIHOSTING_STDOUT +// #define MICRO_OS_PLUS_USE_TRACE_SEMIHOSTING_STDERR +#endif // MICRO_OS_PLUS_TRACE + +// ---------------------------------------------------------------------------- + +#endif /* MICRO_OS_PLUS_PLATFORM_CONFIG_H_ */ + +// ---------------------------------------------------------------------------- diff --git a/tests/platform-qemu-cortex-m3/meson.build b/tests/platform-qemu-cortex-m3/meson.build new file mode 100644 index 0000000..5c489c8 --- /dev/null +++ b/tests/platform-qemu-cortex-m3/meson.build @@ -0,0 +1,220 @@ +# ----------------------------------------------------------------------------- +# +# This file is part of the µOS++ distribution. +# (https://github.com/micro-os-plus/) +# Copyright (c) 2022 Liviu Ionescu. All rights reserved. +# +# Permission to use, copy, modify, and/or distribute this software +# for any purpose is hereby granted, under the terms of the MIT license. +# +# If a copy of the license was not distributed with this file, it can +# be obtained from https://opensource.org/licenses/MIT/. +# +# ----------------------------------------------------------------------------- + +# Create the test applications. + +message('Processing tests/platform-qemu-cortex-m3...') + +# ----------------------------------------------------------------------------- + +# Enable them only when needed. +xpack_create_listing = false +xpack_create_hex = false + +# ----------------------------------------------------------------------------- + +# Get the command names from the toolchain file. +size = find_program('size') +objdump = find_program('objdump') +objcopy = find_program('objcopy') + +# ----------------------------------------------------------------------------- + +# Define the tests executables. + +test_names = [ 'sample-test', 'unit-test' ] + +foreach name : test_names + + _local_compile_args = [] # Common C/C++ args. + _local_compile_c_args = [] + _local_compile_cpp_args = [] + _local_include_directories = [] + _local_sources = [] + _local_compile_definitions = [] + _local_dependencies = [] + _local_link_args = [] + _local_link_with = [] + + # --------------------------------------------------------------------------- + + _local_include_directories += [ + '../include', + ] + + _local_sources += [ + '../src/' + name + '.cpp', + ] + + _local_compile_c_args += platform_qemu_cortex_m3_dependency_compile_c_args + _local_compile_cpp_args += platform_qemu_cortex_m3_dependency_compile_cpp_args + + _local_compile_c_args += micro_os_plus_micro_test_plus_dependency_compile_c_args + _local_compile_cpp_args += micro_os_plus_micro_test_plus_dependency_compile_cpp_args + + _local_link_args += [ + '-Wl,-Map,'+ name + '-map.txt', + # '-v', + ] + + _local_dependencies += [ + # Tested library. + micro_os_plus_micro_test_plus_dependency, + + # Portable dependencies. + micro_os_plus_diag_trace_dependency, + ] + + if name == 'unit-test' + _local_dependencies += [ + micro_os_plus_micro_test_plus_dependency, + ] + endif + + _local_dependencies += [ + # Platform specific dependencies. + platform_qemu_cortex_m3_dependency, # bring device & architecture too + + micro_os_plus_semihosting_dependency, + micro_os_plus_startup_dependency, + ] + + # https://mesonbuild.com/Reference-manual.html#executable + exe = executable( + name, + include_directories: include_directories(_local_include_directories), + sources: files(_local_sources), + c_args: _local_compile_args + _local_compile_c_args + _local_compile_definitions, + cpp_args: _local_compile_args + _local_compile_cpp_args + _local_compile_definitions, + dependencies: _local_dependencies, + link_args: _local_link_args, + link_with: _local_link_with, + name_suffix: 'elf', + ) + + foreach xn : _local_include_directories + message('A+ -I ' + xn) + endforeach + # Note: depenedencies compile_args not shown. + foreach xn : _local_sources + _local_compile_definitions + _local_compile_args + _local_compile_c_args + _local_compile_cpp_args + _local_link_args + message('A+ ' + xn) + endforeach + message('A> ' + name) + + # Leave the result in a variable with the test name. + set_variable(name.underscorify(), exe) + + # https://mesonbuild.com/Reference-manual_functions.html#custom_target + custom_target( + name + '-size', + + input: exe, + output: name + '.size', + command: [ + size, + '--format=berkeley', + '@INPUT@' + ], + build_always_stale: true, + build_by_default: true, + ) + + # --source --all-headers --demangle --line-numbers --wide "xxx.elf" + custom_target( + name + '-list', + + input: exe, + output: name + '-list.txt', + command: [ + objdump, + '--source', + '--all-headers', + '--demangle', + '--line-numbers', + '--wide', + '@INPUT@' + ], + build_always_stale: true, + build_by_default: xpack_create_listing, + capture: true, + ) + + # -O ihex "xxx.elf" + custom_target( + name + '-hex', + + input: exe, + output: name + '.hex', + command: [ + objcopy, + '-O', + 'ihex', + '@INPUT@', + '@OUTPUT@', + ], + build_always_stale: true, + build_by_default: xpack_create_hex, + ) + +endforeach + +qemu = find_program('qemu-system-arm') + +# https://mesonbuild.com/Unit-tests.html#malloc_perturb_ +xpack_environment = environment() +xpack_environment.set('MALLOC_PERTURB_', '0') + +# ----------------------------------------------------------------------------- + +if enable_sample_test + + # https://mesonbuild.com/Reference-manual_functions.html#test + test( + 'sample-test', + qemu, + args: [ + '--machine', 'mps2-an385', + '--cpu', 'cortex-m3', + '--kernel', sample_test, + '--nographic', + '-d', 'unimp,guest_errors', + '--semihosting-config', 'enable=on,target=native,arg=sample-test,arg=one,arg=two', + ], + env: xpack_environment + ) + +endif + +# ----------------------------------------------------------------------------- + +if enable_unit_test + + # https://mesonbuild.com/Reference-manual_functions.html#test + test( + 'unit-test', + qemu, + args: [ + '--machine', 'mps2-an385', + '--cpu', 'cortex-m3', + '--kernel', unit_test, + '--nographic', + '-d', 'unimp,guest_errors', + '--semihosting-config', 'enable=on,target=native,arg=unit-test', + ], + env: xpack_environment + ) + +endif + +# ----------------------------------------------------------------------------- diff --git a/tests/platform-qemu-cortex-m3/meson/cross.ini b/tests/platform-qemu-cortex-m3/meson/cross.ini new file mode 100644 index 0000000..58c92d3 --- /dev/null +++ b/tests/platform-qemu-cortex-m3/meson/cross.ini @@ -0,0 +1,22 @@ +# https://mesonbuild.com/Machine-files.html +# https://mesonbuild.com/Cross-compilation.html +# https://mesonbuild.com/Reference-tables.html#cpu-families + +# The binaries are in the toolchain file. + +[host_machine] +system = 'bare' +cpu_family = 'arm' +cpu = 'cortex-m3' +endian = 'little' + +[constants] + +[properties] + +[built-in options] +warning_level = '0' +werror = true +# layout = 'flat' # 'mirror' # Broken! + +# ----------------------------------------------------------------------------- diff --git a/tests/platform-qemu-cortex-m3/meson/dependencies-folders/meson.build b/tests/platform-qemu-cortex-m3/meson/dependencies-folders/meson.build new file mode 100644 index 0000000..c0c7c5e --- /dev/null +++ b/tests/platform-qemu-cortex-m3/meson/dependencies-folders/meson.build @@ -0,0 +1,50 @@ +# ----------------------------------------------------------------------------- +# +# This file is part of the µOS++ distribution. +# (https://github.com/micro-os-plus/) +# Copyright (c) 2022 Liviu Ionescu. All rights reserved. +# +# Permission to use, copy, modify, and/or distribute this software +# for any purpose is hereby granted, under the terms of the MIT license. +# +# If a copy of the license was not distributed with this file, it can +# be obtained from https://opensource.org/licenses/MIT/. +# +# ----------------------------------------------------------------------------- + +# Define a list of folders where the platform dependencies are located. + +# ----------------------------------------------------------------------------- + +# Required in devices-qemu-cortexm. +xpack_device_compile_definition='MICRO_OS_PLUS_DEVICE_QEMU_CORTEX_M3' + +xpack_platform_compile_definition = 'MICRO_OS_PLUS_PLATFORM_QEMU_CORTEX_M3' + +# ----------------------------------------------------------------------------- + +# The base folder is tests. The order is significative. +xpack_dependencies_folders = [ + + 'xpacks/@micro-os-plus/diag-trace', # - + # - + # 'xpacks/@micro-os-plus/version', + + # - + xpack_build_folder_relative_path + '/xpacks/@xpack-3rd-party/arm-cmsis-core', + # (architecture) - + xpack_build_folder_relative_path + '/xpacks/@micro-os-plus/architecture-cortexm', + + # +(diag_trace, architecture) >semihosting + xpack_build_folder_relative_path + '/xpacks/@micro-os-plus/semihosting', + + # - + xpack_build_folder_relative_path + '/xpacks/@micro-os-plus/startup', + + # +(arm_cmsis_core_m, devices_cortexm, startup) >devices_qemu_cortexm + xpack_build_folder_relative_path + '/xpacks/@micro-os-plus/devices-qemu-cortexm', + + 'platform-qemu-cortex-m3/meson/platform-options', +] + +# ----------------------------------------------------------------------------- diff --git a/tests/platform-qemu-cortex-m3/meson/platform-options/meson.build b/tests/platform-qemu-cortex-m3/meson/platform-options/meson.build new file mode 100644 index 0000000..cbc4875 --- /dev/null +++ b/tests/platform-qemu-cortex-m3/meson/platform-options/meson.build @@ -0,0 +1,135 @@ +# ----------------------------------------------------------------------------- +# +# This file is part of the µOS++ distribution. +# (https://github.com/micro-os-plus/) +# Copyright (c) 2022 Liviu Ionescu. All rights reserved. +# +# Permission to use, copy, modify, and/or distribute this software +# for any purpose is hereby granted, under the terms of the MIT license. +# +# If a copy of the license was not distributed with this file, it can +# be obtained from https://opensource.org/licenses/MIT/. +# +# ----------------------------------------------------------------------------- + +message('Including platform-qemu-cortex-m3 common definitions...') + +# ----------------------------------------------------------------------------- + +_local_compile_args = [] # Common C/C++ args. +_local_compile_c_args = [] +_local_compile_cpp_args = [] +_local_include_directories = [] +_local_sources = [] +_local_compile_definitions = [] +_local_dependencies = [] +_local_link_args = [] +_local_link_with = [] + +# ----------------------------------------------------------------------------- + +_local_include_directories += [ + # Go back to the platform include. + '../../include', +] + +_local_sources += [ + # None. +] + +# Compiler definitions must passed as options. +_local_compile_definitions += [ + '-D' + xpack_platform_compile_definition, + + # Full POSIX conformance: + # https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap02.html#tag_02_01_03 + '-D_POSIX_C_SOURCE=200809L', + + # For S_IREAD + '-D_GNU_SOURCE' +] + +_local_compile_args += [ + # https://gcc.gnu.org/onlinedocs/gcc-11.3.0/gcc/ARM-Options.html#ARM-Options + '-mcpu=cortex-m3', + '-mthumb', + '-mfloat-abi=soft', + + # '-fno-move-loop-invariants', + + # Embedded builds must be warning free. + '-Werror', +] + +if get_option('buildtype').contains('debug') + _local_compile_args += [ + '-fno-omit-frame-pointer' + ] +else + _local_compile_args += [ + # -flto fails with undefined reference to `_write', `_fstat`... + # '-flto' + ] +endif + +_local_compile_cpp_args += [ + # '-fno-exceptions', + # '-fno-rtti', + # '-fno-use-cxa-atexit', + '-fno-threadsafe-statics', +] + +_local_compile_c_args += common_options_dependency_compile_c_args +_local_compile_cpp_args += common_options_dependency_compile_cpp_args + +_local_link_args += [ + '-v', + + '-nostartfiles', + # '--specs=rdimon.specs', '-Wl,--start-group', '-lgcc', '-lc', '-lc', '-lm', '-lrdimon', '-Wl,--end-group', + + # Ensure the linker will keep the interrupt vectors which otherwise + # are not referred from anywhere. + # '-u_interrupt_vectors', + + # nano has no exceptions. + # '-specs=nano.specs' + + '-Wl,--gc-sections', + + # .elf has a LOAD segment with RWX permissions (GCC 12) + '-Wl,--no-warn-rwx-segments', + + # Path are relative to the build folder. + '-Txpacks/@micro-os-plus/devices-qemu-cortexm/linker-scripts/mem-mps2-an385.ld', + '-Txpacks/@micro-os-plus/architecture-cortexm/linker-scripts/sections-flash.ld', + # '-Txpacks/@micro-os-plus/architecture-cortexm/linker-scripts/sections-ram.ld', +] + +_local_dependencies += [ + common_options_dependency, + micro_os_plus_devices_qemu_cortexm_dependency, +] + +# https://mesonbuild.com/Reference-manual_functions.html#declare_dependency +platform_qemu_cortex_m3_dependency = declare_dependency( + include_directories: include_directories(_local_include_directories), + sources: files(_local_sources), + compile_args: _local_compile_args + _local_compile_definitions, + dependencies: _local_dependencies, + link_args: _local_compile_args + _local_link_args, + link_with: _local_link_with, +) +platform_qemu_cortex_m3_dependency_compile_c_args = _local_compile_c_args +platform_qemu_cortex_m3_dependency_compile_cpp_args = _local_compile_cpp_args + +foreach xn : _local_include_directories + message('+ -I ' + xn) +endforeach +# Note: depenedencies compile_args not shown. +foreach xn : _local_sources + _local_compile_definitions + _local_compile_args + _local_compile_c_args + _local_compile_cpp_args + _local_link_args + message('+ ' + xn) +endforeach +message('> platform_qemu_cortex_m3_dependency') + +# ----------------------------------------------------------------------------- diff --git a/tests/platform-qemu-cortex-m4f/CMakeLists.txt b/tests/platform-qemu-cortex-m4f/CMakeLists.txt new file mode 100644 index 0000000..668d6ae --- /dev/null +++ b/tests/platform-qemu-cortex-m4f/CMakeLists.txt @@ -0,0 +1,147 @@ +# ----------------------------------------------------------------------------- +# +# This file is part of the µOS++ distribution. +# (https://github.com/micro-os-plus/) +# Copyright (c) 2022 Liviu Ionescu. All rights reserved. +# +# Permission to use, copy, modify, and/or distribute this software +# for any purpose is hereby granted, under the terms of the MIT license. +# +# If a copy of the license was not distributed with this file, it can +# be obtained from https://opensource.org/licenses/MIT/. +# +# ----------------------------------------------------------------------------- + +message(VERBOSE "Processing 'tests/platform-qemu-cortex-m4f'...") + +# ----------------------------------------------------------------------------- + +# set(xpack_create_listing true) +# set(xpack_create_hex true) + +# ----------------------------------------------------------------------------- + +# Define the tests executables. +function(add_test_executable name) + add_executable(${name}) + + set_target_properties(${name} + + PROPERTIES + OUTPUT_NAME "${name}" + ) + + # Include folders. + # `tests/platform-qemu-cortex-m4f/include` was added globally. + target_include_directories(${name} PRIVATE + "../include" + ) + + message(VERBOSE "A+ -I tests/include") + + # Application sources. + target_sources(${name} PRIVATE + "../src/${name}.cpp" + ) + + message(VERBOSE "A+ tests/src/${name}.cpp") + + target_compile_definitions(${name} PRIVATE + + # None. + ) + + target_compile_options(${name} PRIVATE + + # None. + ) + + target_link_options(${name} PRIVATE + + -Wl,-Map,platform-bin/${name}-map.txt + + # -v + ) + + target_link_libraries(${name} PRIVATE + + # Tested library. + micro-os-plus::micro-test-plus + + # Portable dependencies. + micro-os-plus::diag-trace + + # Platform specific dependencies. + micro-os-plus::platform # bring device & architecture too + + micro-os-plus::semihosting + micro-os-plus::startup + ) + + # TODO use add_custom_target() + # https://cmake.org/cmake/help/v3.20/command/add_custom_command.html + add_custom_command(TARGET ${name} POST_BUILD + COMMAND ${CMAKE_SIZE} --format=berkeley "$" + ) + + if(xpack_create_hex) + add_custom_command(TARGET ${name} POST_BUILD + COMMAND ${CMAKE_OBJCOPY} -O ihex "$" "$.hex" + ) + endif() + + if(xpack_create_listing) + add_custom_command(TARGET ${name} POST_BUILD + COMMAND ${CMAKE_OBJDUMP} --source --all-headers --demangle --line-numbers --wide "$" > ${name}-list.txt + VERBATIM + ) + endif() + + message(VERBOSE "A> ${name}") +endfunction() + +# ----------------------------------------------------------------------------- + +# sample-test +if(ENABLE_SAMPLE_TEST) + add_test_executable(sample-test) + + add_test( + NAME "sample-test" + + COMMAND qemu-system-arm${extension} + --machine mps2-an386 + --cpu cortex-m4 + --kernel sample-test.elf + --nographic + -d unimp,guest_errors + --semihosting-config enable=on,target=native,arg=sample-test,arg=one,arg=two + ) +endif() + +# ----------------------------------------------------------------------------- + +# unit-test +if(ENABLE_UNIT_TEST) + add_test_executable(unit-test) + + target_link_libraries(unit-test PRIVATE + micro-os-plus::micro-test-plus + ) + + add_test( + NAME "unit-test" + + COMMAND qemu-system-arm${extension} + --machine mps2-an386 + --cpu cortex-m4 + --kernel unit-test.elf + --nographic + -d unimp,guest_errors + --semihosting-config enable=on,target=native,arg=unit-test + + # --semihosting-config arg=--verbose + ) +endif() + +# ----------------------------------------------------------------------------- diff --git a/tests/platform-qemu-cortex-m4f/README.md b/tests/platform-qemu-cortex-m4f/README.md new file mode 100644 index 0000000..0711965 --- /dev/null +++ b/tests/platform-qemu-cortex-m4f/README.md @@ -0,0 +1,55 @@ +# platform-qemu-cortex-m4f + +Support files for building application to run on the QEMU "mps2-an386" +emulated board. + +## Include folders + +The following folders should be passed to the compiler during the build: + +- `include-config` +- `include-platform` + +The header files to be included in user projects are: + +```cpp +#include +#include +``` + +## Source files + +The source files to be added to user projects are: + +- none + +## Memory range + +The applications are built for the following memory range: + +- FLASH: 0x0000_0000-0x007F_FFFF (8 MB) +- RAM: 0x2000_0000-0x207F_FFFF (8 MB) +- HEAP: 0x6000_0000-0x60FF_FFFF (16 MB) +- stack: 0x6100_0000 + +The heap and stack are set automatically in `_startup()` to the values +returned by `SEMIHOSTING_SYS_HEAPINFO`. + +## QEMU invocation + +To run tests, pass the ELF file and the arguments: + +```sh +qemu-system-arm --machine mps2-an386 --cpu cortex-m4 --nographic -d unimp,guest_errors --kernel "unit-test.elf" --semihosting-config enable=on,target=native,arg=test +``` + +For debug sessions start QEMU in GDB server mode by passing both `-s -S`: + +```sh +qemu-system-arm --machine mps2-an386 --cpu cortex-m4 --nographic -d unimp,guest_errors -s -S --semihosting-config enable=on,target=native,arg=test +``` + +## Links + +- [QEMU Arm](https://www.qemu.org/docs/master/system/target-arm.html) +- [virt](https://www.qemu.org/docs/master/system/arm/virt.html) diff --git a/tests/platform-qemu-cortex-m4f/cmake/dependencies-folders.cmake b/tests/platform-qemu-cortex-m4f/cmake/dependencies-folders.cmake new file mode 100644 index 0000000..7039ab2 --- /dev/null +++ b/tests/platform-qemu-cortex-m4f/cmake/dependencies-folders.cmake @@ -0,0 +1,40 @@ +# ----------------------------------------------------------------------------- +# +# This file is part of the µOS++ distribution. +# (https://github.com/micro-os-plus/) +# Copyright (c) 2022 Liviu Ionescu. All rights reserved. +# +# Permission to use, copy, modify, and/or distribute this software +# for any purpose is hereby granted, under the terms of the MIT license. +# +# If a copy of the license was not distributed with this file, it can +# be obtained from https://opensource.org/licenses/MIT/. +# +# ----------------------------------------------------------------------------- + +# Define a list of folders where the platform dependencies are located. + +# ----------------------------------------------------------------------------- + +# Required in devices-qemu-cortexm. +set(xpack_device_compile_definition "MICRO_OS_PLUS_DEVICE_QEMU_CORTEX_M4") + +set(xpack_platform_compile_definition "MICRO_OS_PLUS_PLATFORM_QEMU_CORTEX_M4F") + +# ----------------------------------------------------------------------------- +set(xpack_dependencies_folders + + # Project dependencies. + + # The BINARY_DIR is the `build/` folder. + "${CMAKE_BINARY_DIR}/xpacks/@xpack-3rd-party/arm-cmsis-core" + "${CMAKE_BINARY_DIR}/xpacks/@micro-os-plus/architecture-cortexm" + "${CMAKE_BINARY_DIR}/xpacks/@micro-os-plus/devices-qemu-cortexm" + "${CMAKE_BINARY_DIR}/xpacks/@micro-os-plus/semihosting" + "${CMAKE_BINARY_DIR}/xpacks/@micro-os-plus/startup" + + # The SOURCE_DIR is the `tests` folder. + "${CMAKE_SOURCE_DIR}/xpacks/@micro-os-plus/diag-trace" +) + +# ----------------------------------------------------------------------------- diff --git a/tests/platform-qemu-cortex-m4f/cmake/platform-options.cmake b/tests/platform-qemu-cortex-m4f/cmake/platform-options.cmake new file mode 100644 index 0000000..73ee0da --- /dev/null +++ b/tests/platform-qemu-cortex-m4f/cmake/platform-options.cmake @@ -0,0 +1,128 @@ +# ----------------------------------------------------------------------------- +# +# This file is part of the µOS++ distribution. +# (https://github.com/micro-os-plus/) +# Copyright (c) 2022 Liviu Ionescu. All rights reserved. +# +# Permission to use, copy, modify, and/or distribute this software +# for any purpose is hereby granted, under the terms of the MIT license. +# +# If a copy of the license was not distributed with this file, it can +# be obtained from https://opensource.org/licenses/MIT/. +# +# ----------------------------------------------------------------------------- + +message(VERBOSE "Including 'tests/platform-qemu-cortex-m4f/cmake/platform.cmake'...") + +# ----------------------------------------------------------------------------- + +# Validate. +if(NOT DEFINED xpack_platform_compile_definition) + message(FATAL_ERROR "Define xpack_platform_compile_definition in ${PLATFORM_NAME}/cmake/dependencies.cmake") +endif() + +# ----------------------------------------------------------------------------- + +# Define the platform library. +add_library(platform-qemu-cortex-m4f-interface INTERFACE EXCLUDE_FROM_ALL) + +target_include_directories(platform-qemu-cortex-m4f-interface INTERFACE + + # This file is included from the tests folder. + "platform-${PLATFORM_NAME}/include" +) + +target_sources(platform-qemu-cortex-m4f-interface INTERFACE + + # None. +) + +target_compile_definitions(platform-qemu-cortex-m4f-interface INTERFACE + "${xpack_platform_compile_definition}" + + # Full POSIX conformance: + # https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap02.html#tag_02_01_03 + # _POSIX_C_SOURCE=200809L + + # For S_IREAD + _GNU_SOURCE +) + +set(xpack_platform_common_args + -mcpu=cortex-m4 + -mthumb + + # -mfloat-abi=soft + -mfloat-abi=hard + + # -fno-move-loop-invariants + + # Embedded builds must be warning free. + -Werror + + # -flto fails to run on QEMU. + # $<$:-flto> + # $<$:-flto> + $<$:-fno-omit-frame-pointer> + + # ... libs-c/src/stdlib/exit.c:132:46 + # $<$:-Wno-missing-attributes> + + # $<$:-fxxx> + + # https://cmake.org/cmake/help/v3.20/manual/cmake-generator-expressions.7.html?highlight=compile_language#genex:COMPILE_LANGUAGE + # $<$:-fno-exceptions> + # $<$:-fno-rtti> + # $<$:-fno-use-cxa-atexit> + $<$:-fno-threadsafe-statics> +) + +target_compile_options(platform-qemu-cortex-m4f-interface INTERFACE + ${xpack_platform_common_args} +) + +# When `-flto` is used, the compile options must be passed to the linker too. +target_link_options(platform-qemu-cortex-m4f-interface INTERFACE + + # -v + ${xpack_platform_common_args} + + -nostartfiles + + # --specs=rdimon.specs -Wl,--start-group -lgcc -lc -lc -lm -lrdimon -Wl,--end-group + + # Force the linker to keep the interrupt vectors which otherwise + # are not referred from anywhere. + # -u_interrupt_vectors + + # nano has no exceptions. + # -specs=nano.specs + -Wl,--gc-sections + + # .elf has a LOAD segment with RWX permissions (GCC 12) + -Wl,--no-warn-rwx-segment + + # Including files from other packages is not very nice, but functional. + # Use absolute paths, otherwise set -L. + -T${CMAKE_BINARY_DIR}/xpacks/@micro-os-plus/devices-qemu-cortexm/linker-scripts/mem-mps2-an386.ld + -T${CMAKE_BINARY_DIR}/xpacks/@micro-os-plus/architecture-cortexm/linker-scripts/sections-flash.ld + + # -T${CMAKE_BINARY_DIR}/xpacks/@micro-os-plus/architecture-cortexm/linker-scripts/sections-ram.ld +) + +target_link_libraries(platform-qemu-cortex-m4f-interface INTERFACE + micro-os-plus::common-options + micro-os-plus::devices-qemu-cortexm +) + +if(COMMAND xpack_display_target_lists) + xpack_display_target_lists(platform-qemu-cortex-m4f-interface) +endif() + +# ----------------------------------------------------------------------------- + +# Aliases. +add_library(micro-os-plus::platform ALIAS platform-qemu-cortex-m4f-interface) +message(VERBOSE "> micro-os-plus::platform -> platform-qemu-cortex-m4f-interface") + +# ----------------------------------------------------------------------------- diff --git a/tests/platform-qemu-cortex-m4f/include/micro-os-plus/platform.h b/tests/platform-qemu-cortex-m4f/include/micro-os-plus/platform.h new file mode 100644 index 0000000..78e7200 --- /dev/null +++ b/tests/platform-qemu-cortex-m4f/include/micro-os-plus/platform.h @@ -0,0 +1,26 @@ +/* + * This file is part of the µOS++ distribution. + * (https://github.com/micro-os-plus/) + * Copyright (c) 2022 Liviu Ionescu. All rights reserved. + * + * Permission to use, copy, modify, and/or distribute this software + * for any purpose is hereby granted, under the terms of the MIT license. + * + * If a copy of the license was not distributed with this file, it can + * be obtained from https://opensource.org/licenses/MIT/. + */ + +#ifndef MICRO_OS_PLUS_PLATFORM_H_ +#define MICRO_OS_PLUS_PLATFORM_H_ + +#include + +// ---------------------------------------------------------------------------- + +// ... + +// ---------------------------------------------------------------------------- + +#endif /* MICRO_OS_PLUS_PLATFORM_H_ */ + +// ---------------------------------------------------------------------------- diff --git a/tests/platform-qemu-cortex-m4f/include/micro-os-plus/platform/config.h b/tests/platform-qemu-cortex-m4f/include/micro-os-plus/platform/config.h new file mode 100644 index 0000000..6dd152d --- /dev/null +++ b/tests/platform-qemu-cortex-m4f/include/micro-os-plus/platform/config.h @@ -0,0 +1,38 @@ +/* + * This file is part of the µOS++ distribution. + * (https://github.com/micro-os-plus/) + * Copyright (c) 2022 Liviu Ionescu. All rights reserved. + * + * Permission to use, copy, modify, and/or distribute this software + * for any purpose is hereby granted, under the terms of the MIT license. + * + * If a copy of the license was not distributed with this file, it can + * be obtained from https://opensource.org/licenses/MIT/. + */ + +#ifndef MICRO_OS_PLUS_PLATFORM_CONFIG_H_ +#define MICRO_OS_PLUS_PLATFORM_CONFIG_H_ + +// ---------------------------------------------------------------------------- + +// On bare-metal platforms, tests are semihosted applications. +#define MICRO_OS_PLUS_USE_SEMIHOSTING + +#define MICRO_OS_PLUS_INCLUDE_SEMIHOSTING_SYSCALLS +#define MICRO_OS_PLUS_INCLUDE_SEMIHOSTING_STARTUP + +#define MICRO_OS_PLUS_INCLUDE_STARTUP +#define MICRO_OS_PLUS_INCLUDE_SBRK +#define MICRO_OS_PLUS_INCLUDE_EXIT + +#if defined(MICRO_OS_PLUS_TRACE) +// #define MICRO_OS_PLUS_USE_TRACE_SEMIHOSTING_DEBUG +#define MICRO_OS_PLUS_USE_TRACE_SEMIHOSTING_STDOUT +// #define MICRO_OS_PLUS_USE_TRACE_SEMIHOSTING_STDERR +#endif // MICRO_OS_PLUS_TRACE + +// ---------------------------------------------------------------------------- + +#endif /* MICRO_OS_PLUS_PLATFORM_CONFIG_H_ */ + +// ---------------------------------------------------------------------------- diff --git a/tests/platform-qemu-cortex-m4f/meson.build b/tests/platform-qemu-cortex-m4f/meson.build new file mode 100644 index 0000000..0f133b4 --- /dev/null +++ b/tests/platform-qemu-cortex-m4f/meson.build @@ -0,0 +1,214 @@ +# ----------------------------------------------------------------------------- +# +# This file is part of the µOS++ distribution. +# (https://github.com/micro-os-plus/) +# Copyright (c) 2022 Liviu Ionescu. All rights reserved. +# +# Permission to use, copy, modify, and/or distribute this software +# for any purpose is hereby granted, under the terms of the MIT license. +# +# If a copy of the license was not distributed with this file, it can +# be obtained from https://opensource.org/licenses/MIT/. +# +# ----------------------------------------------------------------------------- + +# Create the test applications. + +message('Processing tests/platform-qemu-cortex-m4f...') + +# ----------------------------------------------------------------------------- + +# Enable them only when needed. +xpack_create_listing = false +xpack_create_hex = false + +# ----------------------------------------------------------------------------- + +# Get the command names from the toolchain file. +size = find_program('size') +objdump = find_program('objdump') +objcopy = find_program('objcopy') + +# ----------------------------------------------------------------------------- + +# Define the tests executables. + +test_names = [ 'sample-test', 'unit-test' ] + +foreach name : test_names + + _local_compile_args = [] # Common C/C++ args. + _local_compile_c_args = [] + _local_compile_cpp_args = [] + _local_include_directories = [] + _local_sources = [] + _local_compile_definitions = [] + _local_dependencies = [] + _local_link_args = [] + _local_link_with = [] + + # --------------------------------------------------------------------------- + + _local_include_directories += [ + '../include', + ] + + _local_sources += [ + '../src/' + name + '.cpp', + ] + + _local_compile_c_args += platform_qemu_cortex_m4f_dependency_compile_c_args + _local_compile_cpp_args += platform_qemu_cortex_m4f_dependency_compile_cpp_args + + _local_compile_c_args += micro_os_plus_micro_test_plus_dependency_compile_c_args + _local_compile_cpp_args += micro_os_plus_micro_test_plus_dependency_compile_cpp_args + + _local_link_args += [ + '-Wl,-Map,'+ name + '-map.txt', + # '-v', + ] + + _local_dependencies += [ + # Tested library. + micro_os_plus_micro_test_plus_dependency, + + # Portable dependencies. + micro_os_plus_diag_trace_dependency, + ] + + _local_dependencies += [ + # Platform specific dependencies. + platform_qemu_cortex_m4f_dependency, # bring device & architecture too + + micro_os_plus_semihosting_dependency, + micro_os_plus_startup_dependency, + ] + + # https://mesonbuild.com/Reference-manual.html#executable + exe = executable( + name, + include_directories: include_directories(_local_include_directories), + sources: files(_local_sources), + c_args: _local_compile_args + _local_compile_c_args + _local_compile_definitions, + cpp_args: _local_compile_args + _local_compile_cpp_args + _local_compile_definitions, + dependencies: _local_dependencies, + link_args: _local_link_args, + link_with: _local_link_with, + name_suffix: 'elf', + ) + + foreach xn : _local_include_directories + message('A+ -I ' + xn) + endforeach + # Note: depenedencies compile_args not shown. + foreach xn : _local_sources + _local_compile_definitions + _local_compile_args + _local_compile_c_args + _local_compile_cpp_args + _local_link_args + message('A+ ' + xn) + endforeach + message('A> ' + name) + + # Leave the result in a variable with the test name. + set_variable(name.underscorify(), exe) + + # https://mesonbuild.com/Reference-manual_functions.html#custom_target + custom_target( + name + '-size', + + input: exe, + output: name + '.size', + command: [ + size, + '--format=berkeley', + '@INPUT@' + ], + build_always_stale: true, + build_by_default: true, + ) + + # --source --all-headers --demangle --line-numbers --wide "xxx.elf" + custom_target( + name + '-list', + + input: exe, + output: name + '-list.txt', + command: [ + objdump, + '--source', + '--all-headers', + '--demangle', + '--line-numbers', + '--wide', + '@INPUT@' + ], + build_always_stale: true, + build_by_default: xpack_create_listing, + capture: true, + ) + + # -O ihex "xxx.elf" + custom_target( + name + '-hex', + + input: exe, + output: name + '.hex', + command: [ + objcopy, + '-O', + 'ihex', + '@INPUT@', + '@OUTPUT@', + ], + build_always_stale: true, + build_by_default: xpack_create_hex, + ) + +endforeach + +qemu = find_program('qemu-system-arm') + +# https://mesonbuild.com/Unit-tests.html#malloc_perturb_ +xpack_environment = environment() +xpack_environment.set('MALLOC_PERTURB_', '0') + +# ----------------------------------------------------------------------------- + +if enable_sample_test + + # https://mesonbuild.com/Reference-manual_functions.html#test + test( + 'sample-test', + qemu, + args: [ + '--machine', 'mps2-an386', + '--cpu', 'cortex-m4', + '--kernel', sample_test, + '--nographic', + '-d', 'unimp,guest_errors', + '--semihosting-config', 'enable=on,target=native,arg=sample-test,arg=one,arg=two', + ], + env: xpack_environment + ) + +endif + +# ----------------------------------------------------------------------------- + +if enable_unit_test + + # https://mesonbuild.com/Reference-manual_functions.html#test + test( + 'unit-test', + qemu, + args: [ + '--machine', 'mps2-an386', + '--cpu', 'cortex-m4', + '--kernel', unit_test, + '--nographic', + '-d', 'unimp,guest_errors', + '--semihosting-config', 'enable=on,target=native,arg=unit-test', + ], + env: xpack_environment + ) + +endif + +# ----------------------------------------------------------------------------- diff --git a/tests/platform-qemu-cortex-m4f/meson/cross.ini b/tests/platform-qemu-cortex-m4f/meson/cross.ini new file mode 100644 index 0000000..bfae980 --- /dev/null +++ b/tests/platform-qemu-cortex-m4f/meson/cross.ini @@ -0,0 +1,22 @@ +# https://mesonbuild.com/Machine-files.html +# https://mesonbuild.com/Cross-compilation.html +# https://mesonbuild.com/Reference-tables.html#cpu-families + +# The binaries are in the toolchain file. + +[host_machine] +system = 'bare' +cpu_family = 'arm' +cpu = 'cortex-m4' +endian = 'little' + +[constants] + +[properties] + +[built-in options] +warning_level = '0' +werror = true +# layout = 'flat' # 'mirror' # Broken! + +# ----------------------------------------------------------------------------- diff --git a/tests/platform-qemu-cortex-m4f/meson/dependencies-folders/meson.build b/tests/platform-qemu-cortex-m4f/meson/dependencies-folders/meson.build new file mode 100644 index 0000000..8c8800d --- /dev/null +++ b/tests/platform-qemu-cortex-m4f/meson/dependencies-folders/meson.build @@ -0,0 +1,50 @@ +# ----------------------------------------------------------------------------- +# +# This file is part of the µOS++ distribution. +# (https://github.com/micro-os-plus/) +# Copyright (c) 2022 Liviu Ionescu. All rights reserved. +# +# Permission to use, copy, modify, and/or distribute this software +# for any purpose is hereby granted, under the terms of the MIT license. +# +# If a copy of the license was not distributed with this file, it can +# be obtained from https://opensource.org/licenses/MIT/. +# +# ----------------------------------------------------------------------------- + +# Define a list of folders where the platform dependencies are located. + +# ----------------------------------------------------------------------------- + +# Required in devices-qemu-cortexm. +xpack_device_compile_definition='MICRO_OS_PLUS_DEVICE_QEMU_CORTEX_M4' + +xpack_platform_compile_definition = 'MICRO_OS_PLUS_PLATFORM_QEMU_CORTEX_M4F' + +# ----------------------------------------------------------------------------- + +# The base folder is tests. The order is significative. +xpack_dependencies_folders = [ + + 'xpacks/@micro-os-plus/diag-trace', # - + # - + # 'xpacks/@micro-os-plus/version', + + # - + xpack_build_folder_relative_path + '/xpacks/@xpack-3rd-party/arm-cmsis-core', + # (architecture) - + xpack_build_folder_relative_path + '/xpacks/@micro-os-plus/architecture-cortexm', + + # +(diag_trace, architecture) >semihosting + xpack_build_folder_relative_path + '/xpacks/@micro-os-plus/semihosting', + + # - + xpack_build_folder_relative_path + '/xpacks/@micro-os-plus/startup', + + # +(arm_cmsis_core_m, devices_cortexm, startup) >devices_qemu_cortexm + xpack_build_folder_relative_path + '/xpacks/@micro-os-plus/devices-qemu-cortexm', + + 'platform-qemu-cortex-m4f/meson/platform-options', +] + +# ----------------------------------------------------------------------------- diff --git a/tests/platform-qemu-cortex-m4f/meson/platform-options/meson.build b/tests/platform-qemu-cortex-m4f/meson/platform-options/meson.build new file mode 100644 index 0000000..aa9b473 --- /dev/null +++ b/tests/platform-qemu-cortex-m4f/meson/platform-options/meson.build @@ -0,0 +1,136 @@ +# ----------------------------------------------------------------------------- +# +# This file is part of the µOS++ distribution. +# (https://github.com/micro-os-plus/) +# Copyright (c) 2022 Liviu Ionescu. All rights reserved. +# +# Permission to use, copy, modify, and/or distribute this software +# for any purpose is hereby granted, under the terms of the MIT license. +# +# If a copy of the license was not distributed with this file, it can +# be obtained from https://opensource.org/licenses/MIT/. +# +# ----------------------------------------------------------------------------- + +message('Including platform-qemu-cortex-m4f common definitions...') + +# ----------------------------------------------------------------------------- + +_local_compile_args = [] # Common C/C++ args. +_local_compile_c_args = [] +_local_compile_cpp_args = [] +_local_include_directories = [] +_local_sources = [] +_local_compile_definitions = [] +_local_dependencies = [] +_local_link_args = [] +_local_link_with = [] + +# ----------------------------------------------------------------------------- + +_local_include_directories += [ + # Go back to the platform include. + '../../include', +] + +_local_sources += [ + # None. +] + +# Compiler definitions must passed as options. +_local_compile_definitions += [ + '-D' + xpack_platform_compile_definition, + + # Full POSIX conformance: + # https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap02.html#tag_02_01_03 + '-D_POSIX_C_SOURCE=200809L', + + # For S_IREAD + '-D_GNU_SOURCE' +] + +_local_compile_args += [ + # https://gcc.gnu.org/onlinedocs/gcc-11.3.0/gcc/ARM-Options.html#ARM-Options + '-mcpu=cortex-m4', + '-mthumb', + '-mfloat-abi=hard', + # '-mfloat-abi=soft', + + # '-fno-move-loop-invariants', + + # Embedded builds must be warning free. + '-Werror', +] + +if get_option('buildtype').contains('debug') + _local_compile_args += [ + '-fno-omit-frame-pointer' + ] +else + _local_compile_args += [ + # -flto fails with undefined reference to `_write', `_fstat`... + # '-flto' + ] +endif + +_local_compile_cpp_args += [ + # '-fno-exceptions', + # '-fno-rtti', + # '-fno-use-cxa-atexit', + '-fno-threadsafe-statics', +] + +_local_compile_c_args += common_options_dependency_compile_c_args +_local_compile_cpp_args += common_options_dependency_compile_cpp_args + +_local_link_args += [ + '-v', + + '-nostartfiles', + # '--specs=rdimon.specs', '-Wl,--start-group', '-lgcc', '-lc', '-lc', '-lm', '-lrdimon', '-Wl,--end-group', + + # Ensure the linker will keep the interrupt vectors which otherwise + # are not referred from anywhere. + # '-u_interrupt_vectors', + + # nano has no exceptions. + # '-specs=nano.specs' + + '-Wl,--gc-sections', + + # .elf has a LOAD segment with RWX permissions (GCC 12) + '-Wl,--no-warn-rwx-segments', + + # Path are relative to the build folder. + '-Txpacks/@micro-os-plus/devices-qemu-cortexm/linker-scripts/mem-mps2-an385.ld', + '-Txpacks/@micro-os-plus/architecture-cortexm/linker-scripts/sections-flash.ld', + # '-Txpacks/@micro-os-plus/architecture-cortexm/linker-scripts/sections-ram.ld', +] + +_local_dependencies += [ + common_options_dependency, + micro_os_plus_devices_qemu_cortexm_dependency, +] + +# https://mesonbuild.com/Reference-manual_functions.html#declare_dependency +platform_qemu_cortex_m4f_dependency = declare_dependency( + include_directories: include_directories(_local_include_directories), + sources: files(_local_sources), + compile_args: _local_compile_args + _local_compile_definitions, + dependencies: _local_dependencies, + link_args: _local_compile_args + _local_link_args, + link_with: _local_link_with, +) +platform_qemu_cortex_m4f_dependency_compile_c_args = _local_compile_c_args +platform_qemu_cortex_m4f_dependency_compile_cpp_args = _local_compile_cpp_args + +foreach xn : _local_include_directories + message('+ -I ' + xn) +endforeach +# Note: depenedencies compile_args not shown. +foreach xn : _local_sources + _local_compile_definitions + _local_compile_args + _local_compile_c_args + _local_compile_cpp_args + _local_link_args + message('+ ' + xn) +endforeach +message('> platform_qemu_cortex_m4f_dependency') + +# -----------------------------------------------------------------------------