diff --git a/.github/workflows/issues.yml b/.github/workflows/issues.yml deleted file mode 100644 index bd11d0c..0000000 --- a/.github/workflows/issues.yml +++ /dev/null @@ -1,23 +0,0 @@ -name: Close inactive issues -on: - schedule: - - cron: "30 17 * * *" - -jobs: - close-issues: - runs-on: ubuntu-latest - permissions: - issues: write - pull-requests: write - steps: - - uses: actions/stale@v3 - with: - days-before-issue-stale: 30 - days-before-issue-close: 14 - stale-issue-label: "stale" - stale-issue-message: "This issue is stale because it has been open for 30 days with no activity. If there is no further activity, the ticket will be automatically closed in 14 days." - close-issue-message: "This issue was closed because it has been inactive for 14 days since being marked as stale." - days-before-pr-stale: -1 - days-before-pr-close: -1 - repo-token: ${{ secrets.GITHUB_TOKEN }} - diff --git a/LICENSE b/LICENSE index d3a88da..840297e 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2020-2021 IAR Systems AB +Copyright (c) 2020-2024 IAR Systems AB Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index b020a88..6116617 100644 --- a/README.md +++ b/README.md @@ -1,234 +1,167 @@ -# Tutorial
Building and testing with the IAR tools in CMake +# Building CMake projects with IAR -[CMake][url-cm-home] is an open-source, cross-platform family of tools maintained and supported by [Kitware][url-cm-kitware]. CMake is used to control the software compilation process - using simple configuration files - to generate native build scripts for a selected build system, like ninja, make, etc. For detailed documentation, visit the [CMake Documentation Page][url-cm-docs]. - -This tutorial serves as a very basic-level guide to using CMake together with the __IAR C/C++ compilers__ to cross-compile embedded software applications for the supported target architectures. +CMake is an open-source, cross-platform family of tools maintained and supported by Kitware. Among its many features, it essentially provides [Makefile Generators](https://cmake.org/cmake/help/latest/manual/cmake-generators.7.html#id11) and [Ninja Generators](https://cmake.org/cmake/help/latest/manual/cmake-generators.7.html#id12) which compose scripts for cross-compiling C/C++ embedded software projects based on one or more `CMakeLists.txt` configuration files. +This tutorial offers a short introduction for those seeking information on how to start using the IAR C/C++ Compiler together with CMake from the command line. While this guide is based on the IAR Build Tools for Arm version 9.50.1 on Linux, it should work with other supported IAR products with no or minimal changes. ## Prerequisites -This tutorial assumes that: +Before you begin, you will need to download and install the IAR product, CMake and then clone this repository. + +1) Download, install and activate[^1] your IAR product -* You are familiar with using the IAR and Kitware tools on the command line. +| __Product__ | __Evaluation__ | __IAR Customers (login required)__ | +| - | - | - | +| IAR Build Tools | [Contact us](https://iar.com/about/contact) | [for Arm](https://updates.iar.com/?product=BXARM) (or for others[^2]) | +| IAR Embedded Workbench | [Download](https://iar.com/downloads) | [for Arm](https://updates.iar.com/?product=EWARM) (or for others[^2]) | + +2) Download and install [CMake](https://github.com/Kitware/CMake/releases/latest). -* This repository is cloned to the development computer (it can also be downloaded as a zip archive by clicking the __Code__ button). +3) Clone this repository to your computer. For more information, see ["Cloning a repository"](https://docs.github.com/en/repositories/creating-and-managing-repositories/cloning-a-repository). -* The required tools are already installed on the system, according to the table below: +## Building a Basic CMake Project +The most basic CMake project is an executable built from a single source code file. For simple projects like this, a `CMakeLists.txt` file with about half dozen of commands is all that is required. -| __Tool__ | __Windows-based systems__ | __Linux-based systems__ | -|-----------------------------------------|---------------------------------------------------------------------------------------------------|--------------------------------------------------------------------| -| IAR C/C++ Compiler for... | `Arm`, `RISC-V`, `RL78`, `RX`, `RH850`,
`8051`, `AVR`, `MSP430`, `STM8` or `V850` | `Arm`, `AVR`, `RISC-V`, `RL78`, `RX` or `RH850` | -| [CMake 3.23+](https://cmake.org) | Download and install the [latest][url-cmake-dl] for `-windows-x86_x64.msi` | Use the [Kitware APT repository](https://apt.kitware.com/) or,
if suitable, the distribution-provided package | -| [Ninja 1.10+](https://ninja-build.org) | Download the latest [ninja-win.zip][url-ninja-dl] and extract "ninja.exe" to a directory belonging to the `PATH` environment variable (like `C:\Windows\`) | Usually, the distribution-provided package should be enough | +Any project's topmost `CMakeLists.txt` must start by specifying a minimum CMake version using the [`cmake_minimum_required()`][url-help-cmake_minimum_required] command. This establishes policy settings and ensures that CMake functions used in the project are run with a compatible version of CMake. ->:warning: Before being able to start using CMake, make sure the compiler license is activated. Refer to your product's documentation for details. +To start a project, use the [`project()`][url-help-project] command to set the project name. This call is required with every project and should be called soon after [`cmake_minimum_required()`][url-help-cmake_minimum_required]. This command can also be used to specify other project level information such as the language(s) used or its version number. ->:penguin: Recent **Linux distributions** offer relatively up-to-date packages for `cmake` and `ninja`. Once installed, these executables are normally found on the default search path, so that both can be executed directly from anywhere in the system. You can follow the official [Kitware's APT repository](https://apt.kitware.com/) instructions so you can use it with your package manager to stay always up-to-date. -> ->:thought_balloon: On **Windows-based systems**, the `cmake--windows-x86_x64.msi` installer wizard will offer you the choice of _adding the CMake directory to the system PATH for all users_ so that CMake can be executed from anywhere in your system. For the `ninja.exe` executable from the [`ninja-win.zip`](https://github.com/ninja-build/ninja/releases/latest) binary distribution archive, you can extract it to the CMake's `bin` directory inside its installation directory, or any other potential directory belonging to the `PATH` environment variable (like `C:\Windows\`). The same recommendation applies for when using CMake with alternative generators. For example, when using `cmake -G "Unix Makefiles"`, instead of `ninja.exe` you will need to use `make.exe` to build. In such a scenario, if the `make.exe` program cannot be found, CMake will fail immediately when you try to run the toolchain configuration step, returning with a fatal error message (for example, "`CMAKE_MAKE_PROGRAM not found`"). +Use the [`add_executable()`][url-help-add_executable] command to tell CMake to create an executable using the specified source code files. +Then use [`target_sources()`][url-help-target_sources] to list the source files required to build the target. -## Building Projects -To use CMake to build a project developed with an IAR compiler, you need at least: -* A toolchain file -* A `CMakeLists.txt` file -* The application source code +Use [`target_compile_options()`][url-help-target_compile_options] for setting up the compiler options to build the target. -### Configuring the toolchain file -By default, CMake uses what it assumes to be the host platform's default compiler. When the application targets an embedded platform (known as cross-compiling), a toolchain file `.cmake` can be used to specify the intended toolchain's location to its compiler and assembler. This section provides a simple generic template for the __IAR C/C++ compilers__. +And finally, set your target's linker options with [`target_link_options()`][url-help-target_link_options]: -In the [`examples/iar-toolchain.cmake`](examples/iar-toolchain.cmake) file: -* Set the `TOOLKIT` variable to the compiler's target architecture. ```cmake -# Action: Set the TOOLKIT variable -# Examples: arm, riscv, rh850, rl78, rx, stm8, 430, 8051, avr or v850 -# Alternative: override the default TOOLKIT (/path/to/installation/) -set(TOOLKIT arm) +# set the minimum required version of CMake to be 3.20 +cmake_minimum_required(VERSION 3.20) + +# set the project name +project(Tutorial) + +# add the executable target +add_executable(tutorial) + +# target sources +target_sources(tutorial PRIVATE tutorial.c) + +# compiler options +target_compile_options(tutorial PRIVATE --cpu=cortex-m4) + +# linker options +target_link_options(tutorial PRIVATE --semihosting) ``` ->:bulb: The default toolchain file will search for an available compiler on the default installation paths. You can also use the `TOOLKIT` variable to set a specific installation directory (for example, `C:/IAR/EWARM/N.nn`). - -### A minimal project -A CMake project is defined by one or more `CMakeLists.txt` file(s). This is how a simple `hello-world` project can be configured for the Arm target architecture: -* Change the directory to the `hello-world` project: +### Enabling the IAR Compiler +CMake uses the host platform's default compiler. When cross-compiling embedded applications, the compiler must be set manually via [`CMAKE__COMPILER`](https://cmake.org/cmake/help/latest/variable/CMAKE_LANG_COMPILER.html) variables for each supported language. Additionally, it is possible to specify a build tool via [`CMAKE_MAKE_PROGRAM`](): + +| Variable | Description | Examples | +| - | - | - | +| `CMAKE_C_COMPILER` | Must point to the C Compiler executable | `"C:/Program Files/..../arm/bin/iccarm.exe"`
`"/opt/iarsystems/bxarm/arm/bin/iccarm"` | +| `CMAKE_CXX_COMPILER` | Must point to the C++ Compiler executable | `"C:/Program Files/..../arm/bin/iccarm.exe"`
`"/opt/iarsystems/bxarm/arm/bin/iccarm"` | +| `CMAKE_ASM_COMPILER` | Must point to the Assembler executable | `"C:/Program Files/..../arm/bin/iasmarm.exe"`
`"/opt/iarsystems/bxarm/arm/bin/iasmarm"` | +| `CMAKE_MAKE_PROGRAM` | Must point to the build tool executable | `"C:/Program Files/..../common/bin/ninja.exe"`
`"/opt/iarsystems/bxarm/common/bin/ninja"` | + +CMake reads these variables from +- a separate file called "toolchain file" (for example by invoking `cmake` with [`--toolchain /path/to/bxarm.cmake`](tutorial/bxarm.cmake)) -or- +- invoking `cmake` with `-DCMAKE__COMPILER=...` on the command line, during the configuration phase -or- +- the user/system environment variables [`CC`](https://cmake.org/cmake/help/latest/envvar/CC.html), [`CXX`](https://cmake.org/cmake/help/latest/envvar/CXX.html) and [`ASM`](https://cmake.org/cmake/help/latest/envvar/ASM.html) which can be used to override the platform's default compiler. +- the IAR Embedded Workbench IDE 9.3 or later, shipped with IAR products starting from the IAR Embedded Workbench for Arm 9.50, where the available IAR toolchain environment is automatically set for CMake projects. + +### Configure and Build +We are ready to build our first project! Run CMake to configure the project and then build it with your chosen build tool. + +- Before starting to use CMake, make sure your compiler is working and does not run into any [license issues](#issues). Example (for Arm): ``` -cd /path/to/cmake-tutorial/examples/arm/hello-world +/path/to/iccarm --version ``` -* Verify the contents of the `CMakeLists.txt` file: +- From the terminal, navigate to the [tutorial](tutorial) directory and create a build directory: +``` +mkdir build +``` -https://github.com/IARSystems/cmake-tutorial/blob/985f597765bd1186867b4157af3d1afde6531943/examples/arm/hello-world/CMakeLists.txt#L1-L16 +- Next, navigate to that build directory and run CMake to configure the project and generate a native build system using the compiler specified in the `bxarm.cmake` toolchain file (if needed, edit the supplied toolchain file to match your tool): +``` +cd build +cmake .. -G Ninja --toolchain ../bxarm.cmake +``` -> :bulb: Adjust the target compiling/linking options for architectures other than __arm__. - -* Verify the contents of the `main.c` source file: - -https://github.com/IARSystems/cmake-tutorial/blob/985f597765bd1186867b4157af3d1afde6531943/examples/arm/hello-world/main.c#L1-L9 - -### Configuring the build system generator -Once you have created the minimal project with a suitable toolchain file, invoke CMake to configure the build environment for cross-compiling, choosing the _build system generator_ and _toolchain file_ to use for the project. - -In this example, take advantage of the `"Ninja Multi-Config"` generator option. This option can be used to generate build configurations for "Debug" and "Release" purposes. The general recommendation when using CMake is to perform an "out-of-source" build, which means creating a subdirectory for the output files. - - * Use the following command to generate the scripts for the build system inside the `_builds` subdirectory: -``` -cmake -B_builds -G "Ninja Multi-Config" --toolchain /path/to/iar-toolchain.cmake -``` ->:bulb: The `cmake --help` command provides more information. - -
Expected output example (click to expand): - ->``` ->-- The C compiler identification is IAR ARM N.nn ->-- Detecting C compiler ABI info ->-- Detecting C compiler ABI info - done ->-- Check for working C compiler: /path/to/toolkit_dir/bin/iccarm.exe - skipped ->-- Detecting C compile features ->-- Detecting C compile features - done ->-- Configuring done ->-- Generating done ->-- Build files have been written to: /path/to/cmake-tutorial/examples/arm/hello-world/_builds ->``` - -
- ->:warning: If by mistake the configuration step fails (for example, because of using the wrong option, the wrong selection, etc.), you might have to remove the `_builds` subdirectory before you try again. This helps CMake to avoid potential cache misses interference during the new attempt. - -### Building the project -* Once the `_builds` tree is configured, use CMake with the `--build` flag to build the project: -``` -cmake --build _builds -``` ->:bulb: The `cmake --help` command provides more information. - -
Expected output example (click to unfold): - ->``` ->[2/2] Linking C executable Debug\hello-world.elf ->``` - -
- -In the minimal example, we had an initial overview of what you need to bootstrap a CMake project for a simple executable file. Targets created from actual embedded software projects will typically require preprocessor symbols, compiler options, linker options and extended options. Additional project examples for the target architectures supported by CMake are provided as reference in the "[Examples](#examples)" section of this tutorial. - - -## Examples -Now that you know how to use CMake to _configure_ and _build_ embedded projects developed with the IAR tools, you can start to explore how projects can be configured in greater detail. - -In this section you will find descriptions for the provided [examples](examples). Each __architecture__ (__``__) subdirectory contains multiple examples. - -Optionally, each example's `CMakeLists.txt` file for target architectures contains the line `include(/path/to/iar-cspy-.cmake)` at the end, as an example that illustrates how to use CTest to invoke the __IAR C-SPY command line utility__ ([`cspybat.exe`][url-iar-docs-cspybat]) to perform automated tests using [macros][url-iar-docs-macros]. - -### Example 1 - Mixing C and assembler source code -The `examples//mix-c-asm` example project demonstrates the basic concepts of building a single executable file (`mixLanguages`) using __C__ and __assembler__ source code. - -It also shows how to use `target_compile_definitions()` to set preprocessor symbols that can be used in the target source code. - - -### Example 2 - Creating and using libraries -The `examples//using-libs` example project demonstrates some advanced features and building one executable file (`myProgram`) linked with a static library file (`myMath`) using __C__ source code. - -The top-level directory contains a `CMakeLists.txt` file that will add the `lib` and the `app` subdirectories, each one containing its own `CMakeLists.txt`. - -The `myMath` library file is located in the `lib` subdirectory. The library contains functions that take two integer parameters to perform basic arithmetic on, returning another integer as the result. - -The `myProgram` executable file is located in the `app` subdirectory. The application performs arithmetic operations using the functions in the `myMath` library. - -It also shows: -* How to use `set_target_properties()` to propagate configuration details across the target options. -* How to set `target_link_options()` to create a map file of the executable file. -* How to use `add_custom_command()` for generating `.bin`/`.hex`/`.srec` output using the `ielftool` utility. - - -### Testing the examples -CTest is an extension of CMake that can help you perform automated tests. With CTest, you can execute the target application directly on your host PC, evaluating its exit code. - -When cross-compiling, it is not possible to execute the target application directly on your host PC. However, you can execute the target application using the __IAR C-SPY Debugger__ and, for example, a custom function that wraps the required parameters (for example, `iar_cspy_add_test()`). A module named `iar-cspy-.cmake` is included in the `CMakeLists.txt` files for target architectures and illustrates the concept. - ->:warning: This section requires the __IAR C-SPY command line utility__ (`cspybat.exe`), which is installed with __IAR Embedded Workbench__. - -* Test the desired project example (*built with debug information*) by executing: - ``` - ctest --test-dir _builds --build-config Debug --output-on-failure --timeout 10 - ``` ->:bulb: The `ctest --help` command provides more information. - -
Expected output - Example 1 (click to unfold): - ->``` ->Internal ctest changing into directory: C:/path/to/cmake-tutorial/examples//mix-c-asm/_builds ->Test project C:/path/to/cmake-tutorial/examples//mix-c-asm/_builds -> Start 1: test_mynum ->1/1 Test #1: test_mynum ....................... Passed 0.20 sec -> ->100% tests passed, 0 tests failed out of 1 -> ->Total Test time (real) = 0.25 sec ->``` - -
- -
Expected output - Example 2 (click to unfold): - ->``` ->Internal ctest changing into directory: C:/path/to/cmake-tutorial/examples//using-libs/_builds ->Test project C:/path/to/cmake-tutorial/examples//using-libs/_builds -> Start 1: test_add ->1/3 Test #1: test_add ......................... Passed 0.44 sec -> Start 2: test_sub ->2/3 Test #2: test_sub .........................***Failed Required regular expression not found. Regex=[PASS] 0.44 sec ->-- app debug output begin -- ->40 + 2 = 42 ->-- C-SPY TEST:test_sub. Expected: 38 Result: FAIL ->40 - 2 = 39 ->40 * 2 = 80 ->-- app debug output end -- -> -> Start 3: test_mul ->3/3 Test #3: test_mul ......................... Passed 0.44 sec -> ->67% tests passed, 1 tests failed out of 3 -> ->Total Test time (real) = 1.34 sec -> ->The following tests FAILED: -> 2 - test_sub (Failed) ->Errors while running CTest ->``` - -
- - -## Debugging -When target applications are built with _debug information_, they can be debugged with the __IAR C-SPY Debugger__, directly in the __IAR Embedded Workbench__ IDE. - -The [Debugging an Externally Built Executable file][url-iar-docs-ext-elf] Technical Note has instructions for setting up a __debug-only__ project. - -## Issues -Did you find an issue or do you have a question related to the __cmake-tutorial__ tutorial? -- Visit the [cmake-tutorial wiki](https://github.com/IARSystems/cmake-tutorial/wiki). -- Check the public issue tracker for [earlier issues][url-repo-issue-old]. - - If you are reporting a [new][url-repo-issue-new] issue, please describe it in detail. +- Then call CMake for building the executable using the build system: +``` +cmake --build . +``` + +## Run +Let's test the application. To run the executable you will need the non-interactive[^3] command line interface for the IAR C-SPY Debugger (`cspybat`) with the proper drivers for the desired target. Amongst the many ways of accomplishing this, let's take advantage of the `add_test()` for testing the application in a Arm Cortex-M4 simulated target. + + In this example we will use Arm. To do so, we need to change the Tutorial's `CMakeLists.txt`: +- Firstly add [`enable_testing()`](https://cmake.org/cmake/help/latest/command/enable_testing.html#command:enable_testing) to enable testing: +```cmake +enable_testing() +``` + +- Then use [`add_test()`](https://cmake.org/cmake/help/latest/command/add_test.html#add-test) to encapsulate the command line `cspybat` needs. In the example below, the parameters are adjusted for simulating a generic Arm Cortex-M4 target environment: +```cmake +add_test(NAME tutorialTest + COMMAND /opt/iarsystems/bxarm/common/bin/CSpyBat + # C-SPY drivers for the Arm simulator via command line interface + /opt/iarsystems/bxarm/arm/bin/libarmPROC.so + /opt/iarsystems/bxarm/arm/bin/libarmSIM2.so + --plugin=/opt/iarsystems/bxarm/arm/bin/libarmLibsupportUniversal.so + # The target executable (built with debug information) + --debug_file=$ + # C-SPY driver options + --backend + --cpu=cortex-m4 + --semihosting) +``` + +- Now use the [`PASS_REGULAR_EXPRESSION`](https://cmake.org/cmake/help/latest/prop_test/PASS_REGULAR_EXPRESSION.html#prop_test:PASS_REGULAR_EXPRESSION) test property to validate if the program emits the expected string to the standard output (`stdout`). In this case, verifying that the usage message is printed when an incorrect number of arguments is provided. +```cmake +set_tests_properties(tutorialTest PROPERTIES PASS_REGULAR_EXPRESSION "Hello world!") +``` + +- Since `CMakeLists.txt` was modified, the build system needs to be reconfigured: +``` +cmake --build . +``` + +- And finally we call CMake's [`ctest`](https://cmake.org/cmake/help/latest/manual/ctest.1.html#manual:ctest(1)) which subsequently will execute `Tutorial.elf` using the IAR C-SPY Debugger for Arm: +``` +ctest +``` ## Conclusion -This tutorial provides information on how to start building embedded software projects and, also, on how to perform automated tests when using the IAR tools with CMake. When you have understood the core ideas presented here, a world of possibilities opens up. Such a setup might be useful depending on your organization's needs, and can be used as a starting point for particular customizations. +And this is what you need to know to start using CMake with the IAR tools from the command line. Proceed to the [wiki](https://github.com/IARSystems/cmake-tutorial/wiki) for more information. + +## Issues +Use the [CMake Issue Tracker](https://gitlab.kitware.com/cmake/cmake/-/issues/) to report CMake-related software defects. + +For questions/suggestions specifically related to this tutorial: +- Try the [wiki][url-repo-wiki]. +- Check for [earlier issues][url-repo-issue-old] in the issue tracker. +- If nothing helps, create a [new issue][url-repo-issue-new], describing in detail. + +Do not use the issue tracker if you need technical support. The issue tracker **is not a support forum**: +- If you run into license issues, refer to [IAR Customer Care](https://iar.com/knowledge/support/licensing-faq/). +- If you run into tools issues, contact [IAR Tech Support](https://iar.com/knowledge/support/request-technical-support/). + +[^1]: For more information, see the "Installation and Licensing" guide for your product. If you do not have a license, [contact us](https://iar.com/about/contact). +[^2]: CMake has built-in IAR C/C++ Compiler support for the following non-Arm architectures: 8051, AVR, MSP430, RH850, RISC-V, RL78, RX, STM8 and V850. +[^3]: For interactively debugging of executable files (`*.elf`) using the C-SPY Debugger from the IAR Embedded Workbench IDE, read [this technical note][url-iar-docs-ext-elf]. -[url-repo-home]: https://github.com/IARSystems/cmake-tutorial -[url-repo-issue-new]: https://github.com/IARSystems/cmake-tutorial/issues/new -[url-repo-issue-old]: https://github.com/IARSystems/cmake-tutorial/issues?q=is%3Aissue+is%3Aopen%7Cclosed - -[url-iar-docs-macros]: https://wwwfiles.iar.com/arm/webic/doc/EWARM_DebuggingGuide.ENU.pdf#page=417 -[url-iar-docs-cspybat]: https://wwwfiles.iar.com/arm/webic/doc/EWARM_DebuggingGuide.ENU.pdf#page=503 +[url-repo-wiki]: https://github.com/IARSystems/cmake-tutorial/wiki +[url-repo-issue-new]: https://github.com/IARSystems/cmake-tutorial/issues/new +[url-repo-issue-old]: https://github.com/IARSystems/cmake-tutorial/issues?q=is%3Aissue+is%3Aopen%7Cclosed + +[url-help-cmake_minimum_required]: https://cmake.org/cmake/help/latest/command/cmake_minimum_required.html#command:cmake_minimum_required +[url-help-project]: https://cmake.org/cmake/help/latest/command/project.html#command:project +[url-help-add_executable]: https://cmake.org/cmake/help/latest/command/add_executable.html#command:add_executable +[url-help-target_sources]: https://cmake.org/cmake/help/latest/command/target_sources.html#target-sources +[url-help-target_compile_options]: https://cmake.org/cmake/help/latest/command/target_compile_options.html#target-compile-options +[url-help-target_link_options]: https://cmake.org/cmake/help/latest/command/target_link_options.html#target-link-options + [url-iar-docs-ext-elf]: https://www.iar.com/knowledge/support/technical-notes/debugger/debugging-an-externally-built-executable-file/ - -[url-cmake-dl]: https://github.com/kitware/cmake/releases/latest -[url-ninja-dl]: https://github.com/ninja-build/ninja/releases/latest - -[url-gh-docs-notify]: https://docs.github.com/en/github/managing-subscriptions-and-notifications-on-github/setting-up-notifications/about-notifications - -[url-cm-home]: https://cmake.org -[url-cm-docs]: https://cmake.org/documentation -[url-cm-docs-genex]: https://cmake.org/cmake/help/latest/manual/cmake-generator-expressions.7.html -[url-cm-docs-ctest]: https://cmake.org/cmake/help/latest/manual/ctest.1.html -[url-cm-wiki]: https://gitlab.kitware.com/cmake/community/-/wikis/home -[url-cm-kitware]: https://kitware.com diff --git a/examples/430/iar-cspy-430.cmake b/examples/430/iar-cspy-430.cmake deleted file mode 100644 index d168eaa..0000000 --- a/examples/430/iar-cspy-430.cmake +++ /dev/null @@ -1,30 +0,0 @@ -# Example for creating a test for CTest -# to execute the `IAR C-SPY Command-line Utility (cspybat.exe)` - -function(iar_cspy_add_test TARGET TEST_NAME EXPECTED_OUTPUT) - # Add a test for CTest - add_test(NAME ${TEST_NAME} - COMMAND ${TOOLKIT_DIR}/../common/bin/cspybat --silent - # C-SPY drivers - "${TOOLKIT_DIR}/bin/${CMAKE_SYSTEM_PROCESSOR}proc.dll" - "${TOOLKIT_DIR}/bin/${CMAKE_SYSTEM_PROCESSOR}sim.dll" - "--plugin=${TOOLKIT_DIR}/bin/${CMAKE_SYSTEM_PROCESSOR}bat.dll" - --debug_file=$ - # C-SPY macros settings - "--macro=${CMAKE_CURRENT_SOURCE_DIR}/${TARGET}.mac" - "--macro_param=testName=\"${TEST_NAME}\"" - "--macro_param=testExpected=${EXPECTED_OUTPUT}" - # C-SPY backend setup - --backend - -p $>,$,${TOOLKIT_DIR}/config/debugger/msp430f149.ddf> - --hwmul_base=0x130 - --hardware_multiplier=16 - --hwmult_type=1 - --iv_base=0xFFE0 - --odd_word_check - --derivativeSim=MSP430F149 - -d sim ) - - # Set the test to interpret a C-SPY's message containing `PASS` - set_tests_properties(${TEST_NAME} PROPERTIES PASS_REGULAR_EXPRESSION "PASS") -endfunction() diff --git a/examples/430/mix-c-asm/CMakeLists.txt b/examples/430/mix-c-asm/CMakeLists.txt deleted file mode 100644 index ea6d21c..0000000 --- a/examples/430/mix-c-asm/CMakeLists.txt +++ /dev/null @@ -1,43 +0,0 @@ -cmake_minimum_required(VERSION 3.22) - -# Set the project name, [description] and [version], -# while enabling its required languages -project(Example1 - DESCRIPTION "Mixing C and Assembly" - VERSION 1.0.0 - LANGUAGES C ASM ) - -# Fallback option for generators other than `Ninja Multi-Config` -if (NOT CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE Debug) -endif() - -# Enable CTest -enable_testing() - -# Add the executable for the "mixLanguages" target -add_executable(mixLanguages - # Source files - main.c - mynum.asm ) - -# Set a preprocessor symbol, usable from "mixLanguages" target -target_compile_definitions(mixLanguages PUBLIC USE_ASM=1) - -# Set the compiler flags for the "mixLanguages" target -target_compile_options(mixLanguages PRIVATE - $<$:--multiplier=16 --dlib_config ${TOOLKIT_DIR}/lib/dlib/dl430fn.h> - -D__MSP430F149__ ) - -# Set the linker options for the "mixLanguages" target -target_link_options(mixLanguages PRIVATE - -f ${TOOLKIT_DIR}/config/linker/lnk430f149.xcl - ${TOOLKIT_DIR}/lib/dlib/dl430fn.r43 - # The `SHELL:` prefix prevents option de-duplication - "SHELL:-D_DATA16_HEAP_SIZE=50" - "SHELL:-D_STACK_SIZE=50" - "SHELL:-D_DATA20_HEAP_SIZE=50" ) - -# Optional: test the project with C-SPY -include(../iar-cspy-430.cmake) -iar_cspy_add_test(mixLanguages test_mynum 42) \ No newline at end of file diff --git a/examples/430/mix-c-asm/main.c b/examples/430/mix-c-asm/main.c deleted file mode 100644 index 05cefef..0000000 --- a/examples/430/mix-c-asm/main.c +++ /dev/null @@ -1,23 +0,0 @@ -#include -#include "mynum.h" - -int answer; - -int main(void) -{ -#if USE_ASM - answer = mynum(); -#else - answer = 10; -#endif -/* NDEBUG is set automatically for when - bulding with -DCMAKE_BUILD_TYPE=Release */ -#ifndef NDEBUG - printf("-- app debug output begin --\n"); - printf("mixLanguages v%d.%d.%d\n", 1, 0, 0); - printf("The answer is: %d.\n",answer); - printf("-- app debug output end --\n"); -#endif - - return 0; -} diff --git a/examples/430/mix-c-asm/mixLanguages.mac b/examples/430/mix-c-asm/mixLanguages.mac deleted file mode 100644 index b86170a..0000000 --- a/examples/430/mix-c-asm/mixLanguages.mac +++ /dev/null @@ -1,33 +0,0 @@ -__param testName; -__param testExpected; - -__var _breakID; -__var _result; - -execUserSetup() -{ - __message "C-SPY TEST: started..."; - __message "C-SPY TEST: When the `answer` variable is read, `checkanswer()` will execute."; - _breakID = __setSimBreak("answer", "R", "checkAnswer()"); -} - -Done() -{ - __message "-- C-SPY TEST: Done()"; - if (_result == testExpected) - { - __message "-- C-SPY TEST:", testName, ". Result: PASS"; - } else { - __message "-- C-SPY TEST:", testName, ". Expected: ", testExpected, " Result: FAIL"; - } -} - -checkAnswer() -{ - __message "-- C-SPY TEST: checkAnswer()"; - if (testName == "test_mynum") - { - _result = answer; - Done(); - } -} diff --git a/examples/430/mix-c-asm/mynum.asm b/examples/430/mix-c-asm/mynum.asm deleted file mode 100644 index 6a9871f..0000000 --- a/examples/430/mix-c-asm/mynum.asm +++ /dev/null @@ -1,28 +0,0 @@ - RSEG CSTACK:DATA:SORT:NOROOT(0) - - EXTERN ?longjmp_r4 - EXTERN ?longjmp_r5 - EXTERN ?setjmp_r4 - EXTERN ?setjmp_r5 - - PUBWEAK ?setjmp_save_r4 - PUBWEAK ?setjmp_save_r5 - PUBLIC mynum - - - RSEG `CODE`:CODE:REORDER:NOROOT(1) -mynum: - MOV.W #0x2A, R12 - RET - - RSEG `CODE`:CODE:REORDER:NOROOT(1) -?setjmp_save_r4: - REQUIRE ?setjmp_r4 - REQUIRE ?longjmp_r4 - - RSEG `CODE`:CODE:REORDER:NOROOT(1) -?setjmp_save_r5: - REQUIRE ?setjmp_r5 - REQUIRE ?longjmp_r5 - - END diff --git a/examples/430/mix-c-asm/mynum.h b/examples/430/mix-c-asm/mynum.h deleted file mode 100644 index 0d19df4..0000000 --- a/examples/430/mix-c-asm/mynum.h +++ /dev/null @@ -1,4 +0,0 @@ -#ifndef MYNUM_H -#define MYNUM_H -extern int mynum(); -#endif diff --git a/examples/430/using-libs/CMakeLists.txt b/examples/430/using-libs/CMakeLists.txt deleted file mode 100644 index 18292cf..0000000 --- a/examples/430/using-libs/CMakeLists.txt +++ /dev/null @@ -1,18 +0,0 @@ -cmake_minimum_required (VERSION 3.22) - -project (Example2 - DESCRIPTION "Creating and using libraries" - VERSION 1.0.0 - LANGUAGES C ) - -# Fallback option for generators other than `Ninja Multi-Config` -if (NOT CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE Debug) -endif() - -# Enable CTest -enable_testing() - -# Recurse into the "lib" and "app" subdirectiories -add_subdirectory(lib) -add_subdirectory(app) diff --git a/examples/430/using-libs/app/CMakeLists.txt b/examples/430/using-libs/app/CMakeLists.txt deleted file mode 100644 index e1be84d..0000000 --- a/examples/430/using-libs/app/CMakeLists.txt +++ /dev/null @@ -1,40 +0,0 @@ -# Add the executable for the "myProgram" target, -# specifying its source files -add_executable (myProgram - # Source files - main.c ) - -# Set the properties for the "myProgram" target -set_target_properties(myProgram PROPERTIES - XCL "${TOOLKIT_DIR}/config/linker/lnk430f149.xcl" - # C-SPY-related properties - DDF "${TOOLKIT_DIR}/config/debugger/msp430f149.ddf" ) - -# Set the compiler flags for the target -target_compile_options(myProgram PRIVATE - $<$:--multiplier=16 --double=32 --dlib_config ${TOOLKIT_DIR}/lib/dlib/dl430fn.h> - -D__MSP430F149__ ) - -# Set the linker flags for the target -target_link_options(myProgram PRIVATE - -s __program_start - # Create a map file from the target's UBROF - -l $.map - # The `SHELL:` prefix prevents option de-duplication - "SHELL:-D_DATA16_HEAP_SIZE=50" - "SHELL:-D_STACK_SIZE=50" - "SHELL:-D_DATA20_HEAP_SIZE=50" - # Set the linker script - -f $ - # The `SHELL:` prefix prevents option de-duplication - "SHELL:-f ${TOOLKIT_DIR}/config/linker/multiplier.xcl" - -rt ${TOOLKIT_DIR}/lib/dlib/dl430fn.r43 ) - -# Link "myProgram" against the "myMath" library -target_link_libraries(myProgram LINK_PUBLIC myMath) - -# Optional: test the project with C-SPY -include(../../iar-cspy-430.cmake) -iar_cspy_add_test(myProgram test_add 42) -iar_cspy_add_test(myProgram test_sub 38) -iar_cspy_add_test(myProgram test_mul 80) diff --git a/examples/430/using-libs/app/main.c b/examples/430/using-libs/app/main.c deleted file mode 100644 index 039b257..0000000 --- a/examples/430/using-libs/app/main.c +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef NDEBUG -#include -#endif -#include -#include "myMath.h" - -int a = 40, b = 2; -int addResult; -int subResult; -int mulResult; - -int main(void) -{ - addResult = add(a, b); - subResult = sub(a, b); - mulResult = mul(a, b); - -/* In CMake, the NDEBUG preprocessor symbol - is set automatically when the build configuration is set for Release */ -#ifndef NDEBUG - printf("-- app debug output begin --\n"); - printf("%d + %d = %d\n", a, b, addResult); - printf("%d - %d = %d\n", a, b, subResult); - printf("%d * %d = %d\n", a, b, mulResult); - printf("-- app debug output end --\n"); -#endif - return 0; -} - diff --git a/examples/430/using-libs/app/myProgram.mac b/examples/430/using-libs/app/myProgram.mac deleted file mode 100644 index 6e05ea5..0000000 --- a/examples/430/using-libs/app/myProgram.mac +++ /dev/null @@ -1,51 +0,0 @@ -__param testName; -__param testExpected; - -__var _breakID; -__var _result; - -execUserSetup() -{ - /* Set up immediate breakpoints. */ - _breakID = __setSimBreak("addResult", "R", "addAccess()"); - _breakID = __setSimBreak("subResult", "R", "subAccess()"); - _breakID = __setSimBreak("mulResult", "R", "mulAccess()"); -} - -Done() -{ - if (_result == testExpected) - { - __message "-- C-SPY TEST:", testName, ". Result: PASS"; - } else { - __message "-- C-SPY TEST:", testName, ". Expected: ", testExpected, " Result: FAIL"; - } -} - -addAccess() -{ - if (testName == "test_add") - { - _result = addResult; - Done(); - } -} - -subAccess() -{ - if (testName == "test_sub") - { - _result = subResult; - Done(); - } -} - -mulAccess() -{ - if (testName == "test_mul") - { - _result = mulResult; - Done(); - } -} - diff --git a/examples/430/using-libs/lib/CMakeLists.txt b/examples/430/using-libs/lib/CMakeLists.txt deleted file mode 100644 index 78bb672..0000000 --- a/examples/430/using-libs/lib/CMakeLists.txt +++ /dev/null @@ -1,17 +0,0 @@ -# The top-level CMakeLists.txt add this subdirectory -# This CMakeLists.txt builds the target "myMath" library -add_library(myMath - add.c - sub.c - mul.c ) - -# Set the compiler flags for the "myMath" target -target_compile_options(myMath PUBLIC - $<$:--multiplier=16 --double=32 --dlib_config ${TOOLKIT_DIR}/lib/dlib/dl430fn.h> - -D__MSP430F149__ ) - -# Define headers for the target -# PUBLIC headers are used for building the library -# PRIVATE sources, only used in this target -target_include_directories(myMath - PUBLIC $ ) diff --git a/examples/430/using-libs/lib/add.c b/examples/430/using-libs/lib/add.c deleted file mode 100644 index e0e8fdb..0000000 --- a/examples/430/using-libs/lib/add.c +++ /dev/null @@ -1,5 +0,0 @@ -#include "myMath.h" - -int add(int a, int b) { - return a + b; -} diff --git a/examples/430/using-libs/lib/mul.c b/examples/430/using-libs/lib/mul.c deleted file mode 100644 index 106fdb3..0000000 --- a/examples/430/using-libs/lib/mul.c +++ /dev/null @@ -1,5 +0,0 @@ -#include "myMath.h" - -int mul(int a, int b) { - return a * b; -} diff --git a/examples/430/using-libs/lib/myMath.h b/examples/430/using-libs/lib/myMath.h deleted file mode 100644 index 9c7aae3..0000000 --- a/examples/430/using-libs/lib/myMath.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef MY_MATH_H -#define MY_MATH_H - int add(int a, int b); - int sub(int a, int b); - int mul(int a, int b); -#endif diff --git a/examples/430/using-libs/lib/sub.c b/examples/430/using-libs/lib/sub.c deleted file mode 100644 index abefbab..0000000 --- a/examples/430/using-libs/lib/sub.c +++ /dev/null @@ -1,5 +0,0 @@ -#include "myMath.h" - -int sub(int a, int b) { - return a - --b; /* bug */ -} diff --git a/examples/8051/iar-cspy-8051.cmake b/examples/8051/iar-cspy-8051.cmake deleted file mode 100644 index f40036f..0000000 --- a/examples/8051/iar-cspy-8051.cmake +++ /dev/null @@ -1,30 +0,0 @@ -# Example for creating a test for CTest -# to execute the `IAR C-SPY Command-line Utility (cspybat.exe)` - -function(iar_cspy_add_test TARGET TEST_NAME EXPECTED_OUTPUT) - # Add a test for CTest - add_test(NAME ${TEST_NAME} - COMMAND ${TOOLKIT_DIR}/../common/bin/cspybat --silent - # C-SPY drivers - "${TOOLKIT_DIR}/bin/${CMAKE_SYSTEM_PROCESSOR}proc.dll" - "${TOOLKIT_DIR}/bin/${CMAKE_SYSTEM_PROCESSOR}sim.dll" - "--plugin=${TOOLKIT_DIR}/bin/${CMAKE_SYSTEM_PROCESSOR}bat.dll" - --debug_file=$ - # C-SPY macros settings - "--macro=${CMAKE_CURRENT_SOURCE_DIR}/${TARGET}.mac" - "--macro_param=testName=\"${TEST_NAME}\"" - "--macro_param=testExpected=${EXPECTED_OUTPUT}" - # C-SPY backend setup - --backend - --proc_core=plain - --proc_code_model=near - --proc_nr_virtual_regs 8 - --proc_pdata_bank_reg_addr 0xA0 - --proc_dptr_nr_of=1 - --proc_data_model=small - -p $>,$,${TOOLKIT_DIR}/config/devices/_generic/io8051.ddf> - --proc_driver sim ) - - # Set the test to interpret a C-SPY's message containing `PASS` - set_tests_properties(${TEST_NAME} PROPERTIES PASS_REGULAR_EXPRESSION "PASS") -endfunction() diff --git a/examples/8051/mix-c-asm/CMakeLists.txt b/examples/8051/mix-c-asm/CMakeLists.txt deleted file mode 100644 index 35903b4..0000000 --- a/examples/8051/mix-c-asm/CMakeLists.txt +++ /dev/null @@ -1,57 +0,0 @@ -cmake_minimum_required(VERSION 3.22) - -# Set the project name, [description] and [version], -# while enabling its required languages -project(Example1 - DESCRIPTION "Mixing C and Assembly" - VERSION 1.0.0 - LANGUAGES C ASM ) - -# Fallback option for generators other than `Ninja Multi-Config` -if (NOT CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE Debug) -endif() - -# Enable CTest -enable_testing() - -# Add the executable for the "mixLanguages" target -add_executable(mixLanguages - # Source files - main.c - mynum.asm ) - -# Set a preprocessor symbol, usable from "mixLanguages" target -target_compile_definitions(mixLanguages PUBLIC USE_ASM=1) - -# Set compile options for the target -target_compile_options(mixLanguages PRIVATE - $<$:--core=plain --dptr=16,1 --data_model=large --code_model=near --calling_convention=xdata_reentrant --place_constants=data --nr_virtual_regs 8 --dlib --dlib_config ${TOOLKIT_DIR}/lib/dlib/dl8051Normal.h> - $<$:-v0 -D__CORE__=1 -D__CODE_MODEL__=1 -D__DATA_MODEL__=1 -D__CALLING_CONVENTION__=2 -D__NUMBER_OF_DPTRS__=1> ) - -# Set the link options for the target -target_link_options(mixLanguages PRIVATE - -rt - -f ${TOOLKIT_DIR}/config/devices/_generic/lnk51ew_8051.xcl - ${TOOLKIT_DIR}/lib/dlib/dl-pli-nlxd-1e16x01n.r51 - # The `SHELL:` prefix prevents option de-duplication - "SHELL:-D_NR_OF_BANKS=0" - "SHELL:-D_CODEBANK_END=0" - "SHELL:-D_CODEBANK_START=0" - "SHELL:-D_NR_OF_VIRTUAL_REGISTERS=8" - "SHELL:-D?PBANK=0xA0" - "SHELL:-D_IDATA_STACK_SIZE=0x40" - "SHELL:-D?ESP=0" - "SHELL:-D?ESP_MASK=0" - "SHELL:-D_EXTENDED_STACK_START=0" - "SHELL:-D_EXTENDED_STACK_SIZE=0" - "SHELL:-D_PDATA_STACK_SIZE=0x80" - "SHELL:-D_XDATA_STACK_SIZE=0xEFF" - "SHELL:-D_XDATA_HEAP_SIZE=0xFF" - "SHELL:-D_FAR_HEAP_SIZE=0xFFF" - "SHELL:-D_HUGE_HEAP_SIZE=0xFFF" - "SHELL:-D_FAR22_HEAP_SIZE=0xFFF" ) - -# Optional: test the project with CTest and IAR C-SPY -include(../iar-cspy-8051.cmake) -iar_cspy_add_test(mixLanguages test_mynum 42) diff --git a/examples/8051/mix-c-asm/main.c b/examples/8051/mix-c-asm/main.c deleted file mode 100644 index 05cefef..0000000 --- a/examples/8051/mix-c-asm/main.c +++ /dev/null @@ -1,23 +0,0 @@ -#include -#include "mynum.h" - -int answer; - -int main(void) -{ -#if USE_ASM - answer = mynum(); -#else - answer = 10; -#endif -/* NDEBUG is set automatically for when - bulding with -DCMAKE_BUILD_TYPE=Release */ -#ifndef NDEBUG - printf("-- app debug output begin --\n"); - printf("mixLanguages v%d.%d.%d\n", 1, 0, 0); - printf("The answer is: %d.\n",answer); - printf("-- app debug output end --\n"); -#endif - - return 0; -} diff --git a/examples/8051/mix-c-asm/mixLanguages.mac b/examples/8051/mix-c-asm/mixLanguages.mac deleted file mode 100644 index b86170a..0000000 --- a/examples/8051/mix-c-asm/mixLanguages.mac +++ /dev/null @@ -1,33 +0,0 @@ -__param testName; -__param testExpected; - -__var _breakID; -__var _result; - -execUserSetup() -{ - __message "C-SPY TEST: started..."; - __message "C-SPY TEST: When the `answer` variable is read, `checkanswer()` will execute."; - _breakID = __setSimBreak("answer", "R", "checkAnswer()"); -} - -Done() -{ - __message "-- C-SPY TEST: Done()"; - if (_result == testExpected) - { - __message "-- C-SPY TEST:", testName, ". Result: PASS"; - } else { - __message "-- C-SPY TEST:", testName, ". Expected: ", testExpected, " Result: FAIL"; - } -} - -checkAnswer() -{ - __message "-- C-SPY TEST: checkAnswer()"; - if (testName == "test_mynum") - { - _result = answer; - Done(); - } -} diff --git a/examples/8051/mix-c-asm/mynum.asm b/examples/8051/mix-c-asm/mynum.asm deleted file mode 100644 index 7787eeb..0000000 --- a/examples/8051/mix-c-asm/mynum.asm +++ /dev/null @@ -1,20 +0,0 @@ - NAME mynum - - RSEG DOVERLAY:DATA:NOROOT(0) - RSEG IOVERLAY:IDATA:NOROOT(0) - RSEG ISTACK:IDATA:NOROOT(0) - RSEG PSTACK:XDATA:NOROOT(0) - RSEG XSTACK:XDATA:NOROOT(0) - - PUBLIC mynum - - RSEG NEAR_CODE:CODE:NOROOT(0) -mynum: - CODE - ; Saved register size: 0 - ; Auto size: 0 - MOV R2,#0x2A - MOV R3,#0x0 - RET - - END \ No newline at end of file diff --git a/examples/8051/mix-c-asm/mynum.h b/examples/8051/mix-c-asm/mynum.h deleted file mode 100644 index 0d19df4..0000000 --- a/examples/8051/mix-c-asm/mynum.h +++ /dev/null @@ -1,4 +0,0 @@ -#ifndef MYNUM_H -#define MYNUM_H -extern int mynum(); -#endif diff --git a/examples/8051/using-libs/CMakeLists.txt b/examples/8051/using-libs/CMakeLists.txt deleted file mode 100644 index 18292cf..0000000 --- a/examples/8051/using-libs/CMakeLists.txt +++ /dev/null @@ -1,18 +0,0 @@ -cmake_minimum_required (VERSION 3.22) - -project (Example2 - DESCRIPTION "Creating and using libraries" - VERSION 1.0.0 - LANGUAGES C ) - -# Fallback option for generators other than `Ninja Multi-Config` -if (NOT CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE Debug) -endif() - -# Enable CTest -enable_testing() - -# Recurse into the "lib" and "app" subdirectiories -add_subdirectory(lib) -add_subdirectory(app) diff --git a/examples/8051/using-libs/app/CMakeLists.txt b/examples/8051/using-libs/app/CMakeLists.txt deleted file mode 100644 index c6ec347..0000000 --- a/examples/8051/using-libs/app/CMakeLists.txt +++ /dev/null @@ -1,50 +0,0 @@ -# Add the executable for the "myProgram" target, -# specifying its source files -add_executable (myProgram - # Source files - main.c ) - -# Set the properties for the "myProgram" target -set_target_properties(myProgram PROPERTIES - XCL "${TOOLKIT_DIR}/config/devices/_generic/lnk51ew_8051.xcl" - # C-SPY-related properties - DDF "${TOOLKIT_DIR}/config/devices/_generic/io8051.ddf" ) - -# Set the compiler flags for the "myProgram" target -target_compile_options(myProgram PRIVATE - $<$:--core=plain --dptr=16,1 --data_model=large --code_model=near --calling_convention=xdata_reentrant --place_constants=data --nr_virtual_regs 8 --dlib --dlib_config ${TOOLKIT_DIR}/lib/dlib/dl8051Normal.h> ) - -# Set the linker flags for the target -target_link_options(myProgram PRIVATE - -rt - # Set the linker script - -f $ - ${TOOLKIT_DIR}/lib/dlib/dl-pli-nlxd-1e16x01n.r51 - # Create a map file from the target's UBROF - -l $.map - # The `SHELL:` prefix prevents option de-duplication - "SHELL:-D_NR_OF_BANKS=0" - "SHELL:-D_CODEBANK_END=0" - "SHELL:-D_CODEBANK_START=0" - "SHELL:-D_NR_OF_VIRTUAL_REGISTERS=8" - "SHELL:-D?PBANK=0xA0" - "SHELL:-D_IDATA_STACK_SIZE=0x40" - "SHELL:-D?ESP=0" - "SHELL:-D?ESP_MASK=0" - "SHELL:-D_EXTENDED_STACK_START=0" - "SHELL:-D_EXTENDED_STACK_SIZE=0" - "SHELL:-D_PDATA_STACK_SIZE=0x80" - "SHELL:-D_XDATA_STACK_SIZE=0xEFF" - "SHELL:-D_XDATA_HEAP_SIZE=0xFF" - "SHELL:-D_FAR_HEAP_SIZE=0xFFF" - "SHELL:-D_HUGE_HEAP_SIZE=0xFFF" - "SHELL:-D_FAR22_HEAP_SIZE=0xFFF" ) - -# Link "myProgram" against the "myMath" library -target_link_libraries(myProgram LINK_PUBLIC myMath) - -# Optional: test the project with CTest and IAR C-SPY -include(../../iar-cspy-8051.cmake) -iar_cspy_add_test(myProgram test_add 42) -iar_cspy_add_test(myProgram test_sub 38) -iar_cspy_add_test(myProgram test_mul 80) \ No newline at end of file diff --git a/examples/8051/using-libs/app/main.c b/examples/8051/using-libs/app/main.c deleted file mode 100644 index 039b257..0000000 --- a/examples/8051/using-libs/app/main.c +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef NDEBUG -#include -#endif -#include -#include "myMath.h" - -int a = 40, b = 2; -int addResult; -int subResult; -int mulResult; - -int main(void) -{ - addResult = add(a, b); - subResult = sub(a, b); - mulResult = mul(a, b); - -/* In CMake, the NDEBUG preprocessor symbol - is set automatically when the build configuration is set for Release */ -#ifndef NDEBUG - printf("-- app debug output begin --\n"); - printf("%d + %d = %d\n", a, b, addResult); - printf("%d - %d = %d\n", a, b, subResult); - printf("%d * %d = %d\n", a, b, mulResult); - printf("-- app debug output end --\n"); -#endif - return 0; -} - diff --git a/examples/8051/using-libs/app/myProgram.mac b/examples/8051/using-libs/app/myProgram.mac deleted file mode 100644 index 6e05ea5..0000000 --- a/examples/8051/using-libs/app/myProgram.mac +++ /dev/null @@ -1,51 +0,0 @@ -__param testName; -__param testExpected; - -__var _breakID; -__var _result; - -execUserSetup() -{ - /* Set up immediate breakpoints. */ - _breakID = __setSimBreak("addResult", "R", "addAccess()"); - _breakID = __setSimBreak("subResult", "R", "subAccess()"); - _breakID = __setSimBreak("mulResult", "R", "mulAccess()"); -} - -Done() -{ - if (_result == testExpected) - { - __message "-- C-SPY TEST:", testName, ". Result: PASS"; - } else { - __message "-- C-SPY TEST:", testName, ". Expected: ", testExpected, " Result: FAIL"; - } -} - -addAccess() -{ - if (testName == "test_add") - { - _result = addResult; - Done(); - } -} - -subAccess() -{ - if (testName == "test_sub") - { - _result = subResult; - Done(); - } -} - -mulAccess() -{ - if (testName == "test_mul") - { - _result = mulResult; - Done(); - } -} - diff --git a/examples/8051/using-libs/lib/CMakeLists.txt b/examples/8051/using-libs/lib/CMakeLists.txt deleted file mode 100644 index afb36c4..0000000 --- a/examples/8051/using-libs/lib/CMakeLists.txt +++ /dev/null @@ -1,17 +0,0 @@ -# The top-level CMakeLists.txt add this subdirectory -# This CMakeLists.txt builds the target "myMath" library -add_library(myMath - add.c - sub.c - mul.c ) - -# Set the compiler flags for the "myMath" target -target_compile_options(myMath PUBLIC - $<$:--core=plain --dptr=16,1 --data_model=large --code_model=near --calling_convention=xdata_reentrant --place_constants=data --nr_virtual_regs 8 --dlib --dlib_config ${TOOLKIT_DIR}/lib/dlib/dl8051Normal.h> - $<$:-v0 -D__CORE__=1 -D__CODE_MODEL__=1 -D__DATA_MODEL__=1 -D__CALLING_CONVENTION__=2 -D__NUMBER_OF_DPTRS__=1>) - -# Define headers for the target -# PUBLIC headers are used for building the library -# PRIVATE sources, only used in this target -target_include_directories(myMath - PUBLIC $ ) diff --git a/examples/8051/using-libs/lib/add.c b/examples/8051/using-libs/lib/add.c deleted file mode 100644 index e0e8fdb..0000000 --- a/examples/8051/using-libs/lib/add.c +++ /dev/null @@ -1,5 +0,0 @@ -#include "myMath.h" - -int add(int a, int b) { - return a + b; -} diff --git a/examples/8051/using-libs/lib/mul.c b/examples/8051/using-libs/lib/mul.c deleted file mode 100644 index 106fdb3..0000000 --- a/examples/8051/using-libs/lib/mul.c +++ /dev/null @@ -1,5 +0,0 @@ -#include "myMath.h" - -int mul(int a, int b) { - return a * b; -} diff --git a/examples/8051/using-libs/lib/myMath.h b/examples/8051/using-libs/lib/myMath.h deleted file mode 100644 index 9c7aae3..0000000 --- a/examples/8051/using-libs/lib/myMath.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef MY_MATH_H -#define MY_MATH_H - int add(int a, int b); - int sub(int a, int b); - int mul(int a, int b); -#endif diff --git a/examples/8051/using-libs/lib/sub.c b/examples/8051/using-libs/lib/sub.c deleted file mode 100644 index abefbab..0000000 --- a/examples/8051/using-libs/lib/sub.c +++ /dev/null @@ -1,5 +0,0 @@ -#include "myMath.h" - -int sub(int a, int b) { - return a - --b; /* bug */ -} diff --git a/examples/README.md b/examples/README.md new file mode 100644 index 0000000..770ffbf --- /dev/null +++ b/examples/README.md @@ -0,0 +1,3 @@ +# Interactive examples + +Visit the [wiki](https://github.com/iarsystems/cmake-tutorial/wiki) for details and answers. diff --git a/examples/arm/hello-world/CMakeLists.txt b/examples/arm/hello-world/CMakeLists.txt deleted file mode 100644 index d779c0e..0000000 --- a/examples/arm/hello-world/CMakeLists.txt +++ /dev/null @@ -1,17 +0,0 @@ -# CMake requires to set its minimum required version -cmake_minimum_required(VERSION 3.23) - -# Set the project name, enabling its required languages (e.g. ASM, C and/or CXX) -project(simpleProject LANGUAGES C) - -# Add a executable target named "hello-world" -add_executable(hello-world - # Target sources - main.c) - -# Set the target's compiler options -target_compile_options(hello-world PRIVATE --cpu=Cortex-M4 --fpu=VFPv4_sp --dlib_config normal) - -# Set the target's linker options -target_link_options(hello-world PRIVATE --semihosting --config ${TOOLKIT_DIR}/config/linker/ST/stm32f407xG.icf) - diff --git a/examples/arm/hello-world/main.c b/examples/arm/hello-world/main.c deleted file mode 100644 index 092bc57..0000000 --- a/examples/arm/hello-world/main.c +++ /dev/null @@ -1,10 +0,0 @@ -#include -#include - -void main() { - while (1) { - printf("Hello world!\n"); - __no_operation(); - } -} - diff --git a/examples/arm/iar-cspy-arm.cmake b/examples/arm/iar-cspy-arm.cmake deleted file mode 100644 index 720158b..0000000 --- a/examples/arm/iar-cspy-arm.cmake +++ /dev/null @@ -1,48 +0,0 @@ -# Example for creating a test for CTest -# to execute the `IAR C-SPY Command-line Utility (cspybat.exe)` - -function(iar_cspy_add_test TARGET TEST_NAME EXPECTED_OUTPUT) - find_program(CSPY_BAT - NAMES cspybat CSpyBat - PATHS ${TOOLKIT_DIR}/../common - PATH_SUFFIXES bin) - - # Check if C-SPY is being run from BX - if(WIN32) - set(libPREFIX "") - set(libPROCsuffix proc.dll) - set(libSIM2suffix sim2.dll) - set(libBATsuffix bat.dll) - else() - set(libPREFIX lib) - set(libPROCsuffix PROC.so) - set(libSIM2suffix SIM2.so) - set(libBATsuffix Bat.so) - endif() - - # Add a test for CTest - add_test(NAME ${TEST_NAME} - COMMAND ${CSPY_BAT} --silent - # C-SPY drivers - "${TOOLKIT_DIR}/bin/${libPREFIX}${CMAKE_SYSTEM_PROCESSOR}${libPROCsuffix}" - "${TOOLKIT_DIR}/bin/${libPREFIX}${CMAKE_SYSTEM_PROCESSOR}${libSIM2suffix}" - "--plugin=${TOOLKIT_DIR}/bin/${libPREFIX}${CMAKE_SYSTEM_PROCESSOR}${libBATsuffix}" - --debug_file=$ - $>,--device_macro=$,> - # C-SPY macros settings - "--macro=${CMAKE_CURRENT_SOURCE_DIR}/${TARGET}.mac" - "--macro_param=testName=\"${TEST_NAME}\"" - "--macro_param=testExpected=${EXPECTED_OUTPUT}" - # C-SPY backend setup - --backend - --cpu=$>,$,Cortex-M3> - --fpu=$>,$,None> - $>,--device=$,> - --semihosting - --endian=little - $>,-p,> - $>,$,> ) - - # Set the test to interpret a C-SPY's message containing `PASS` - set_tests_properties(${TEST_NAME} PROPERTIES PASS_REGULAR_EXPRESSION "PASS") -endfunction() diff --git a/examples/arm/iar-functions.cmake b/examples/arm/iar-functions.cmake deleted file mode 100644 index 4140d06..0000000 --- a/examples/arm/iar-functions.cmake +++ /dev/null @@ -1,16 +0,0 @@ -# CMake functions for the IAR Build Tools - -# Convert the ELF output to .hex -function(iar_elf_tool_hex TARGET) - add_custom_command(TARGET ${TARGET} POST_BUILD COMMAND ${CMAKE_IAR_ELFTOOL} --silent --ihex $ $>,$,$>.hex) -endfunction() - -# Convert the ELF output to .srec -function(iar_elf_tool_srec TARGET) - add_custom_command(TARGET ${TARGET} POST_BUILD COMMAND ${CMAKE_IAR_ELFTOOL} --silent --srec $ $>,$,$>.srec) -endfunction() - -# Convert the ELF output to .bin -function(iar_elf_tool_bin TARGET) - add_custom_command(TARGET ${TARGET} POST_BUILD COMMAND ${CMAKE_IAR_ELFTOOL} --silent --bin $ $>,$,$>.bin) -endfunction() \ No newline at end of file diff --git a/examples/arm/mix-c-asm/CMakeLists.txt b/examples/arm/mix-c-asm/CMakeLists.txt deleted file mode 100644 index 35a6a06..0000000 --- a/examples/arm/mix-c-asm/CMakeLists.txt +++ /dev/null @@ -1,39 +0,0 @@ -cmake_minimum_required(VERSION 3.22) - -# Set the project name, [description] and [version], -# while enabling its required languages -project(Example1 - DESCRIPTION "Mixing C and Assembly" - VERSION 1.0.0 - LANGUAGES C ASM ) - -# Fallback option for generators other than `Ninja Multi-Config` -if (NOT CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE Debug) -endif() - -# Enable CTest -enable_testing() - -# Add the executable for the "mixLanguages" target -add_executable(mixLanguages - # Source files - main.c - mynum.asm ) - -# Set a preprocessor symbol, usable from "mixLanguages" target -target_compile_definitions(mixLanguages PUBLIC USE_ASM=1) - -# Set compile options for the target -target_compile_options(mixLanguages PRIVATE - $<$:--dlib_config normal> - --cpu Cortex-M3 ) - -# Set the link options for the target -target_link_options(mixLanguages PRIVATE - $<$:--semihosting --redirect ___write=___write_buffered> - --config ${TOOLKIT_DIR}/config/generic.icf ) - -# Optional: test the project with CTest and IAR C-SPY -include(../iar-cspy-arm.cmake) -iar_cspy_add_test(mixLanguages test_mynum 42) diff --git a/examples/arm/mix-c-asm/main.c b/examples/arm/mix-c-asm/main.c deleted file mode 100644 index 05cefef..0000000 --- a/examples/arm/mix-c-asm/main.c +++ /dev/null @@ -1,23 +0,0 @@ -#include -#include "mynum.h" - -int answer; - -int main(void) -{ -#if USE_ASM - answer = mynum(); -#else - answer = 10; -#endif -/* NDEBUG is set automatically for when - bulding with -DCMAKE_BUILD_TYPE=Release */ -#ifndef NDEBUG - printf("-- app debug output begin --\n"); - printf("mixLanguages v%d.%d.%d\n", 1, 0, 0); - printf("The answer is: %d.\n",answer); - printf("-- app debug output end --\n"); -#endif - - return 0; -} diff --git a/examples/arm/mix-c-asm/mixLanguages.mac b/examples/arm/mix-c-asm/mixLanguages.mac deleted file mode 100644 index 3f00fe1..0000000 --- a/examples/arm/mix-c-asm/mixLanguages.mac +++ /dev/null @@ -1,33 +0,0 @@ -__param testName; -__param testExpected; - -__var _breakID; -__var _result; - -execUserSetup() -{ - __message "C-SPY TEST: started..."; - __message "C-SPY TEST: When the `answer` variable is read, `checkAnswer()` will execute."; - _breakID = __setSimBreak("answer", "R", "checkAnswer()"); -} - -Done() -{ - __message "-- C-SPY TEST: Done()"; - if (_result == testExpected) - { - __message "-- C-SPY TEST:", testName, ". Result: PASS"; - } else { - __message "-- C-SPY TEST:", testName, ". Expected: ", testExpected, " Result: FAIL"; - } -} - -checkAnswer() -{ - __message "-- C-SPY TEST: checkAnswer()"; - if (testName == "test_mynum") - { - _result = answer; - Done(); - } -} diff --git a/examples/arm/mix-c-asm/mynum.asm b/examples/arm/mix-c-asm/mynum.asm deleted file mode 100644 index 9f5723d..0000000 --- a/examples/arm/mix-c-asm/mynum.asm +++ /dev/null @@ -1,18 +0,0 @@ - - #define SHT_PROGBITS 0x1 - - PUBLIC mynum - - - SECTION `.text`:CODE:NOROOT(1) - THUMB -mynum: - MOVS R0,#+0x2A - BX LR ;; return - - SECTION `.iar_vfe_header`:DATA:NOALLOC:NOROOT(2) - SECTION_TYPE SHT_PROGBITS, 0 - DATA - DC32 0 - - END diff --git a/examples/arm/mix-c-asm/mynum.h b/examples/arm/mix-c-asm/mynum.h deleted file mode 100644 index 0d19df4..0000000 --- a/examples/arm/mix-c-asm/mynum.h +++ /dev/null @@ -1,4 +0,0 @@ -#ifndef MYNUM_H -#define MYNUM_H -extern int mynum(); -#endif diff --git a/examples/arm/using-libs/CMakeLists.txt b/examples/arm/using-libs/CMakeLists.txt deleted file mode 100644 index 18292cf..0000000 --- a/examples/arm/using-libs/CMakeLists.txt +++ /dev/null @@ -1,18 +0,0 @@ -cmake_minimum_required (VERSION 3.22) - -project (Example2 - DESCRIPTION "Creating and using libraries" - VERSION 1.0.0 - LANGUAGES C ) - -# Fallback option for generators other than `Ninja Multi-Config` -if (NOT CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE Debug) -endif() - -# Enable CTest -enable_testing() - -# Recurse into the "lib" and "app" subdirectiories -add_subdirectory(lib) -add_subdirectory(app) diff --git a/examples/arm/using-libs/app/CMakeLists.txt b/examples/arm/using-libs/app/CMakeLists.txt deleted file mode 100644 index d77e2bf..0000000 --- a/examples/arm/using-libs/app/CMakeLists.txt +++ /dev/null @@ -1,42 +0,0 @@ -# Add the executable for the "myProgram" target, -# specifying its source files -add_executable (myProgram - # Source files - main.c ) - -# Set the properties for the "myProgram" target -set_target_properties(myProgram PROPERTIES - DEVICE STM32F407VG - CPU Cortex-M4 - FPU VFPv4_sp - ICF "${TOOLKIT_DIR}/config/linker/ST/stm32f407xG.icf" - # C-SPY-related properties - DDF "${TOOLKIT_DIR}/config/debugger/ST/STM32F407VG.ddf" - DMAC "${TOOLKIT_DIR}/config/debugger/ST/STM32F4xx.dmac" ) - -# Set compile options for the target -target_compile_options(myProgram PRIVATE - $<$:--dlib_config normal> - --cpu $ --fpu $ ) - -# Set the link options for the target -target_link_options(myProgram PRIVATE - # Genex evaluates if we are using the `Debug` configuration - $<$:--semihosting --redirect ___write=___write_buffered> - # Create a map file from the target's ELF - --map $.map - # Set the linker script - --config $ ) - -# Link "myProgram" against the "myMath" library -target_link_libraries(myProgram LINK_PUBLIC myMath) - -# Optional: convert the output to .hex format -include(../../iar-functions.cmake) -iar_elf_tool_hex(myProgram) - -# Optional: test the project with CTest and IAR C-SPY -include(../../iar-cspy-arm.cmake) -iar_cspy_add_test(myProgram test_add 42) -iar_cspy_add_test(myProgram test_sub 38) -iar_cspy_add_test(myProgram test_mul 80) \ No newline at end of file diff --git a/examples/arm/using-libs/app/main.c b/examples/arm/using-libs/app/main.c deleted file mode 100644 index 039b257..0000000 --- a/examples/arm/using-libs/app/main.c +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef NDEBUG -#include -#endif -#include -#include "myMath.h" - -int a = 40, b = 2; -int addResult; -int subResult; -int mulResult; - -int main(void) -{ - addResult = add(a, b); - subResult = sub(a, b); - mulResult = mul(a, b); - -/* In CMake, the NDEBUG preprocessor symbol - is set automatically when the build configuration is set for Release */ -#ifndef NDEBUG - printf("-- app debug output begin --\n"); - printf("%d + %d = %d\n", a, b, addResult); - printf("%d - %d = %d\n", a, b, subResult); - printf("%d * %d = %d\n", a, b, mulResult); - printf("-- app debug output end --\n"); -#endif - return 0; -} - diff --git a/examples/arm/using-libs/app/myProgram.mac b/examples/arm/using-libs/app/myProgram.mac deleted file mode 100644 index 6e05ea5..0000000 --- a/examples/arm/using-libs/app/myProgram.mac +++ /dev/null @@ -1,51 +0,0 @@ -__param testName; -__param testExpected; - -__var _breakID; -__var _result; - -execUserSetup() -{ - /* Set up immediate breakpoints. */ - _breakID = __setSimBreak("addResult", "R", "addAccess()"); - _breakID = __setSimBreak("subResult", "R", "subAccess()"); - _breakID = __setSimBreak("mulResult", "R", "mulAccess()"); -} - -Done() -{ - if (_result == testExpected) - { - __message "-- C-SPY TEST:", testName, ". Result: PASS"; - } else { - __message "-- C-SPY TEST:", testName, ". Expected: ", testExpected, " Result: FAIL"; - } -} - -addAccess() -{ - if (testName == "test_add") - { - _result = addResult; - Done(); - } -} - -subAccess() -{ - if (testName == "test_sub") - { - _result = subResult; - Done(); - } -} - -mulAccess() -{ - if (testName == "test_mul") - { - _result = mulResult; - Done(); - } -} - diff --git a/examples/arm/using-libs/lib/CMakeLists.txt b/examples/arm/using-libs/lib/CMakeLists.txt deleted file mode 100644 index 56e804b..0000000 --- a/examples/arm/using-libs/lib/CMakeLists.txt +++ /dev/null @@ -1,16 +0,0 @@ -# The top-level CMakeLists.txt add this subdirectory -# This CMakeLists.txt builds the target "myMath" library -add_library(myMath - add.c - sub.c - mul.c ) - -# Set the compiler flags for the "myMath" target -target_compile_options(myMath PUBLIC - $<$:--cpu Cortex-M4 --dlib_config normal> ) - -# Define headers for the target -# PUBLIC headers are used for building the library -# PRIVATE sources, only used in this target -target_include_directories(myMath - PUBLIC $ ) diff --git a/examples/arm/using-libs/lib/add.c b/examples/arm/using-libs/lib/add.c deleted file mode 100644 index e0e8fdb..0000000 --- a/examples/arm/using-libs/lib/add.c +++ /dev/null @@ -1,5 +0,0 @@ -#include "myMath.h" - -int add(int a, int b) { - return a + b; -} diff --git a/examples/arm/using-libs/lib/mul.c b/examples/arm/using-libs/lib/mul.c deleted file mode 100644 index 106fdb3..0000000 --- a/examples/arm/using-libs/lib/mul.c +++ /dev/null @@ -1,5 +0,0 @@ -#include "myMath.h" - -int mul(int a, int b) { - return a * b; -} diff --git a/examples/arm/using-libs/lib/myMath.h b/examples/arm/using-libs/lib/myMath.h deleted file mode 100644 index 9c7aae3..0000000 --- a/examples/arm/using-libs/lib/myMath.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef MY_MATH_H -#define MY_MATH_H - int add(int a, int b); - int sub(int a, int b); - int mul(int a, int b); -#endif diff --git a/examples/arm/using-libs/lib/sub.c b/examples/arm/using-libs/lib/sub.c deleted file mode 100644 index abefbab..0000000 --- a/examples/arm/using-libs/lib/sub.c +++ /dev/null @@ -1,5 +0,0 @@ -#include "myMath.h" - -int sub(int a, int b) { - return a - --b; /* bug */ -} diff --git a/examples/avr/iar-cspy-avr.cmake b/examples/avr/iar-cspy-avr.cmake deleted file mode 100644 index 8ffb685..0000000 --- a/examples/avr/iar-cspy-avr.cmake +++ /dev/null @@ -1,25 +0,0 @@ -# Example for creating a test for CTest -# to execute the `IAR C-SPY Command-line Utility (cspybat.exe)` - -function(iar_cspy_add_test TARGET TEST_NAME EXPECTED_OUTPUT) - # Add a test for CTest - add_test(NAME ${TEST_NAME} - COMMAND ${TOOLKIT_DIR}/../common/bin/cspybat --silent - # C-SPY drivers - "${TOOLKIT_DIR}/bin/${CMAKE_SYSTEM_PROCESSOR}proc.dll" - "${TOOLKIT_DIR}/bin/${CMAKE_SYSTEM_PROCESSOR}sim.dll" - "--plugin=${TOOLKIT_DIR}/bin/${CMAKE_SYSTEM_PROCESSOR}libsupportbat.dll" - --debug_file=$ - # C-SPY macros settings - "--macro=${CMAKE_CURRENT_SOURCE_DIR}/${TARGET}.mac" - "--macro_param=testName=\"${TEST_NAME}\"" - "--macro_param=testExpected=${EXPECTED_OUTPUT}" - # C-SPY backend setup - --backend - -v3 - --enhanced_core - --disable_internal_eeprom ) - - # Set the test to interpret a C-SPY's message containing `PASS` - set_tests_properties(${TEST_NAME} PROPERTIES PASS_REGULAR_EXPRESSION "PASS") -endfunction() diff --git a/examples/avr/mix-c-asm/CMakeLists.txt b/examples/avr/mix-c-asm/CMakeLists.txt deleted file mode 100644 index ecd8944..0000000 --- a/examples/avr/mix-c-asm/CMakeLists.txt +++ /dev/null @@ -1,40 +0,0 @@ -cmake_minimum_required(VERSION 3.22) - -# Set the project name, [description] and [version], -# while enabling its required languages -project(Example1 - DESCRIPTION "Mixing C and Assembly" - VERSION 1.0.0 - LANGUAGES C ASM ) - -# Fallback option for generators other than `Ninja Multi-Config` -if (NOT CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE Debug) -endif() - -# Enable CTest -enable_testing() - -# Add the executable for the "mixLanguages" target -add_executable(mixLanguages - # Source files - main.c - mynum.asm ) - -# Set a preprocessor symbol, usable from "mixLanguages" target -target_compile_definitions(mixLanguages PUBLIC USE_ASM=1) - -# Set compile options for the target -target_compile_options(mixLanguages PRIVATE - $<$:--enhanced_core -ms -y --initializers_in_flash --dlib --dlib_config ${TOOLKIT_DIR}/lib/dlib/dlAVR-3s-ec_mul-n.h> - $<$:-u_enhancedCore> - -v3 ) - -# Set the link options for the target -target_link_options(mixLanguages PRIVATE - -rt ${TOOLKIT_DIR}/lib/dlib/dlAVR-3s-ec_mul-n.r90 - -f ${TOOLKIT_DIR}/src/template/lnk3s.xcl ) - -# Optional: test the project with CTest and IAR C-SPY -include(../iar-cspy-avr.cmake) -iar_cspy_add_test(mixLanguages test_mynum 42) diff --git a/examples/avr/mix-c-asm/main.c b/examples/avr/mix-c-asm/main.c deleted file mode 100644 index 05cefef..0000000 --- a/examples/avr/mix-c-asm/main.c +++ /dev/null @@ -1,23 +0,0 @@ -#include -#include "mynum.h" - -int answer; - -int main(void) -{ -#if USE_ASM - answer = mynum(); -#else - answer = 10; -#endif -/* NDEBUG is set automatically for when - bulding with -DCMAKE_BUILD_TYPE=Release */ -#ifndef NDEBUG - printf("-- app debug output begin --\n"); - printf("mixLanguages v%d.%d.%d\n", 1, 0, 0); - printf("The answer is: %d.\n",answer); - printf("-- app debug output end --\n"); -#endif - - return 0; -} diff --git a/examples/avr/mix-c-asm/mixLanguages.mac b/examples/avr/mix-c-asm/mixLanguages.mac deleted file mode 100644 index b86170a..0000000 --- a/examples/avr/mix-c-asm/mixLanguages.mac +++ /dev/null @@ -1,33 +0,0 @@ -__param testName; -__param testExpected; - -__var _breakID; -__var _result; - -execUserSetup() -{ - __message "C-SPY TEST: started..."; - __message "C-SPY TEST: When the `answer` variable is read, `checkanswer()` will execute."; - _breakID = __setSimBreak("answer", "R", "checkAnswer()"); -} - -Done() -{ - __message "-- C-SPY TEST: Done()"; - if (_result == testExpected) - { - __message "-- C-SPY TEST:", testName, ". Result: PASS"; - } else { - __message "-- C-SPY TEST:", testName, ". Expected: ", testExpected, " Result: FAIL"; - } -} - -checkAnswer() -{ - __message "-- C-SPY TEST: checkAnswer()"; - if (testName == "test_mynum") - { - _result = answer; - Done(); - } -} diff --git a/examples/avr/mix-c-asm/mynum.asm b/examples/avr/mix-c-asm/mynum.asm deleted file mode 100644 index 10ca514..0000000 --- a/examples/avr/mix-c-asm/mynum.asm +++ /dev/null @@ -1,15 +0,0 @@ - NAME mynum - - RSEG CSTACK:DATA:NOROOT(0) - RSEG RSTACK:DATA:NOROOT(0) - - PUBLIC mynum - - - RSEG CODE:CODE:NOROOT(1) -mynum: - LDI R16, 42 - LDI R17, 0 - RET - - END diff --git a/examples/avr/mix-c-asm/mynum.h b/examples/avr/mix-c-asm/mynum.h deleted file mode 100644 index 0d19df4..0000000 --- a/examples/avr/mix-c-asm/mynum.h +++ /dev/null @@ -1,4 +0,0 @@ -#ifndef MYNUM_H -#define MYNUM_H -extern int mynum(); -#endif diff --git a/examples/avr/using-libs/CMakeLists.txt b/examples/avr/using-libs/CMakeLists.txt deleted file mode 100644 index 18292cf..0000000 --- a/examples/avr/using-libs/CMakeLists.txt +++ /dev/null @@ -1,18 +0,0 @@ -cmake_minimum_required (VERSION 3.22) - -project (Example2 - DESCRIPTION "Creating and using libraries" - VERSION 1.0.0 - LANGUAGES C ) - -# Fallback option for generators other than `Ninja Multi-Config` -if (NOT CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE Debug) -endif() - -# Enable CTest -enable_testing() - -# Recurse into the "lib" and "app" subdirectiories -add_subdirectory(lib) -add_subdirectory(app) diff --git a/examples/avr/using-libs/app/CMakeLists.txt b/examples/avr/using-libs/app/CMakeLists.txt deleted file mode 100644 index 62bd3af..0000000 --- a/examples/avr/using-libs/app/CMakeLists.txt +++ /dev/null @@ -1,31 +0,0 @@ -# Add the executable for the "myProgram" target, -# specifying its source files -add_executable (myProgram - # Source files - main.c ) - -# Set the properties for the "myProgram" target -set_target_properties(myProgram PROPERTIES - XCL "${TOOLKIT_DIR}/src/template/lnk3s.xcl" ) - -# Set compile options for the target -target_compile_options(myProgram PRIVATE - $<$:--enhanced_core -ms -y --initializers_in_flash --dlib --dlib_config ${TOOLKIT_DIR}/lib/dlib/dlAVR-3s-ec_mul-n.h> - -v3 ) - -# Set the linker flags for the target -target_link_options(myProgram PRIVATE - -rt ${TOOLKIT_DIR}/lib/dlib/dlAVR-3s-ec_mul-n.r90 - # Set the linker script - -f $ - # Create a map file from the target's UBROF - -l $.map ) - -# Link "myProgram" against the "myMath" library -target_link_libraries(myProgram LINK_PUBLIC myMath) - -# Optional: test the project with CTest and IAR C-SPY -include(../../iar-cspy-avr.cmake) -iar_cspy_add_test(myProgram test_add 42) -iar_cspy_add_test(myProgram test_sub 38) -iar_cspy_add_test(myProgram test_mul 80) \ No newline at end of file diff --git a/examples/avr/using-libs/app/main.c b/examples/avr/using-libs/app/main.c deleted file mode 100644 index 039b257..0000000 --- a/examples/avr/using-libs/app/main.c +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef NDEBUG -#include -#endif -#include -#include "myMath.h" - -int a = 40, b = 2; -int addResult; -int subResult; -int mulResult; - -int main(void) -{ - addResult = add(a, b); - subResult = sub(a, b); - mulResult = mul(a, b); - -/* In CMake, the NDEBUG preprocessor symbol - is set automatically when the build configuration is set for Release */ -#ifndef NDEBUG - printf("-- app debug output begin --\n"); - printf("%d + %d = %d\n", a, b, addResult); - printf("%d - %d = %d\n", a, b, subResult); - printf("%d * %d = %d\n", a, b, mulResult); - printf("-- app debug output end --\n"); -#endif - return 0; -} - diff --git a/examples/avr/using-libs/app/myProgram.mac b/examples/avr/using-libs/app/myProgram.mac deleted file mode 100644 index 6e05ea5..0000000 --- a/examples/avr/using-libs/app/myProgram.mac +++ /dev/null @@ -1,51 +0,0 @@ -__param testName; -__param testExpected; - -__var _breakID; -__var _result; - -execUserSetup() -{ - /* Set up immediate breakpoints. */ - _breakID = __setSimBreak("addResult", "R", "addAccess()"); - _breakID = __setSimBreak("subResult", "R", "subAccess()"); - _breakID = __setSimBreak("mulResult", "R", "mulAccess()"); -} - -Done() -{ - if (_result == testExpected) - { - __message "-- C-SPY TEST:", testName, ". Result: PASS"; - } else { - __message "-- C-SPY TEST:", testName, ". Expected: ", testExpected, " Result: FAIL"; - } -} - -addAccess() -{ - if (testName == "test_add") - { - _result = addResult; - Done(); - } -} - -subAccess() -{ - if (testName == "test_sub") - { - _result = subResult; - Done(); - } -} - -mulAccess() -{ - if (testName == "test_mul") - { - _result = mulResult; - Done(); - } -} - diff --git a/examples/avr/using-libs/lib/CMakeLists.txt b/examples/avr/using-libs/lib/CMakeLists.txt deleted file mode 100644 index 2a1be82..0000000 --- a/examples/avr/using-libs/lib/CMakeLists.txt +++ /dev/null @@ -1,17 +0,0 @@ -# The top-level CMakeLists.txt add this subdirectory -# This CMakeLists.txt builds the target "myMath" library -add_library(myMath - add.c - sub.c - mul.c ) - -# Set the compiler flags for the "myMath" target -target_compile_options(myMath PUBLIC - $<$:--enhanced_core -ms -y --initializers_in_flash --dlib --dlib_config ${TOOLKIT_DIR}/lib/dlib/dlAVR-3s-ec_mul-n.h> - -v3 ) - -# Define headers for the target -# PUBLIC headers are used for building the library -# PRIVATE sources, only used in this target -target_include_directories(myMath - PUBLIC $ ) diff --git a/examples/avr/using-libs/lib/add.c b/examples/avr/using-libs/lib/add.c deleted file mode 100644 index e0e8fdb..0000000 --- a/examples/avr/using-libs/lib/add.c +++ /dev/null @@ -1,5 +0,0 @@ -#include "myMath.h" - -int add(int a, int b) { - return a + b; -} diff --git a/examples/avr/using-libs/lib/mul.c b/examples/avr/using-libs/lib/mul.c deleted file mode 100644 index 106fdb3..0000000 --- a/examples/avr/using-libs/lib/mul.c +++ /dev/null @@ -1,5 +0,0 @@ -#include "myMath.h" - -int mul(int a, int b) { - return a * b; -} diff --git a/examples/avr/using-libs/lib/myMath.h b/examples/avr/using-libs/lib/myMath.h deleted file mode 100644 index 9c7aae3..0000000 --- a/examples/avr/using-libs/lib/myMath.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef MY_MATH_H -#define MY_MATH_H - int add(int a, int b); - int sub(int a, int b); - int mul(int a, int b); -#endif diff --git a/examples/avr/using-libs/lib/sub.c b/examples/avr/using-libs/lib/sub.c deleted file mode 100644 index abefbab..0000000 --- a/examples/avr/using-libs/lib/sub.c +++ /dev/null @@ -1,5 +0,0 @@ -#include "myMath.h" - -int sub(int a, int b) { - return a - --b; /* bug */ -} diff --git a/examples/iar-toolchain.cmake b/examples/iar-toolchain.cmake deleted file mode 100644 index d94d5c3..0000000 --- a/examples/iar-toolchain.cmake +++ /dev/null @@ -1,51 +0,0 @@ -# Toolchain File for the IAR C/C++ Compiler - -# Action: Set the `TOOLKIT` variable -# Examples: arm, riscv, rh850, rl78, rx, stm8, 430, 8051, avr or v850 -# Alternative: override the default TOOLKIT_DIR (/path/to/installation/) -set(TOOLKIT arm) - -# Get the toolchain target from the TOOLKIT -get_filename_component(CMAKE_SYSTEM_PROCESSOR ${TOOLKIT} NAME) - -# Set CMake for cross-compiling -set(CMAKE_SYSTEM_NAME Generic) - -# IAR C Compiler -find_program(CMAKE_C_COMPILER - NAMES icc${CMAKE_SYSTEM_PROCESSOR} - PATHS ${TOOLKIT} - "$ENV{ProgramFiles}/IAR Systems/*" - "$ENV{ProgramFiles\(x86\)}/IAR Systems/*" - /opt/iarsystems/bx${CMAKE_SYSTEM_PROCESSOR} - PATH_SUFFIXES bin ${CMAKE_SYSTEM_PROCESSOR}/bin - REQUIRED ) - -# IAR C++ Compiler -find_program(CMAKE_CXX_COMPILER - NAMES icc${CMAKE_SYSTEM_PROCESSOR} - PATHS ${TOOLKIT} - "$ENV{PROGRAMFILES}/IAR Systems/*" - "$ENV{ProgramFiles\(x86\)}/IAR Systems/*" - /opt/iarsystems/bx${CMAKE_SYSTEM_PROCESSOR} - PATH_SUFFIXES bin ${CMAKE_SYSTEM_PROCESSOR}/bin - REQUIRED ) - -# IAR Assembler -find_program(CMAKE_ASM_COMPILER - NAMES iasm${CMAKE_SYSTEM_PROCESSOR} a${CMAKE_SYSTEM_PROCESSOR} - PATHS ${TOOLKIT} - "$ENV{PROGRAMFILES}/IAR Systems/*" - "$ENV{ProgramFiles\(x86\)}/IAR Systems/*" - /opt/iarsystems/bx${CMAKE_SYSTEM_PROCESSOR} - PATH_SUFFIXES bin ${CMAKE_SYSTEM_PROCESSOR}/bin - REQUIRED ) - -# Avoids running the linker during try_compile() -set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) - -# Set the TOOLKIT_DIR variable for the CMakeLists -get_filename_component(BIN_DIR ${CMAKE_C_COMPILER} DIRECTORY) -get_filename_component(TOOLKIT_DIR ${BIN_DIR} PATH) -unset(BIN_DIR) - diff --git a/examples/libs/CMakeLists.txt b/examples/libs/CMakeLists.txt new file mode 100644 index 0000000..f9c1966 --- /dev/null +++ b/examples/libs/CMakeLists.txt @@ -0,0 +1,32 @@ +cmake_minimum_required(VERSION 3.20) + +project(Libs LANGUAGES C) + +add_executable(libs) + +target_sources(libs PRIVATE main.c) + +# TODO 4: Add the `lib` subdirectory (contains the `lib` target) +add_subdirectory() + +# TODO 5: Link the `lib` against `libs` +target_link_libraries() + +target_link_options(libs PRIVATE --semihosting) + +enable_testing() + +add_test(NAME libs-test + COMMAND /opt/iarsystems/bxarm/common/bin/CSpyBat + # C-SPY drivers for the Arm simulator via command line interface + /opt/iarsystems/bxarm/arm/bin/libarmPROC.so + /opt/iarsystems/bxarm/arm/bin/libarmSIM2.so + --plugin=/opt/iarsystems/bxarm/arm/bin/libarmLibsupportUniversal.so + # The target executable (built with debug information) + --debug_file=$ + # C-SPY driver options + --backend + --cpu=cortex-m4 + --semihosting) + +set_tests_properties(libs-test PROPERTIES PASS_REGULAR_EXPRESSION "2843410253") diff --git a/examples/libs/lib/CMakeLists.txt b/examples/libs/lib/CMakeLists.txt new file mode 100644 index 0000000..10ddce5 --- /dev/null +++ b/examples/libs/lib/CMakeLists.txt @@ -0,0 +1,8 @@ +# TODO 1: Add a library target named `lib` +add_library() + +# TODO 2: Configure the `lib` target sources +target_sources() + +# TODO 3: Using the `PUBLIC` scope, expose the `lib` headers (inc) to other targets +target_include_directories() diff --git a/examples/libs/lib/inc/crc32.h b/examples/libs/lib/inc/crc32.h new file mode 100644 index 0000000..e2cf2f9 --- /dev/null +++ b/examples/libs/lib/inc/crc32.h @@ -0,0 +1,8 @@ +#ifndef _FAST_CRC32_H_ +#define _FAST_CRC32_H_ + +#include + +uint32_t Fast_CRC32(uint32_t crc, uint32_t const* data, uint32_t words); + +#endif /* _FAST_CRC32_H_ */ diff --git a/examples/libs/lib/src/crc32.c b/examples/libs/lib/src/crc32.c new file mode 100644 index 0000000..cf7754b --- /dev/null +++ b/examples/libs/lib/src/crc32.c @@ -0,0 +1,33 @@ +#include + +#include "crc32.h" + +#define CRC32_POLY 0x04C11DB7 + +/** + * @brief Fast CRC32 software implementation + * @retval CRC32 equivalent to STM32F407 HW-CRC + */ +uint32_t Fast_CRC32(uint32_t crc, uint32_t const* data, uint32_t words) +{ + const uint32_t crc32NibbleLUT[16] = { + 0x00000000,CRC32_POLY,0x09823B6E,0x0D4326D9, + 0x130476DC,0x17C56B6B,0x1A864DB2,0x1E475005, + 0x2608EDB8,0x22C9F00F,0x2F8AD6D6,0x2B4BCB61, + 0x350C9B64,0x31CD86D3,0x3C8EA00A,0x384FBDBD, }; + + while (words--) + { + crc = crc ^ *data++; + /* 8 rounds * 4-bit(nibble) = 32 bit(word) */ + crc = (crc << 4) ^ crc32NibbleLUT[crc >> 28]; + crc = (crc << 4) ^ crc32NibbleLUT[crc >> 28]; + crc = (crc << 4) ^ crc32NibbleLUT[crc >> 28]; + crc = (crc << 4) ^ crc32NibbleLUT[crc >> 28]; + crc = (crc << 4) ^ crc32NibbleLUT[crc >> 28]; + crc = (crc << 4) ^ crc32NibbleLUT[crc >> 28]; + crc = (crc << 4) ^ crc32NibbleLUT[crc >> 28]; + crc = (crc << 4) ^ crc32NibbleLUT[crc >> 28]; + } + return crc; +} diff --git a/examples/libs/main.c b/examples/libs/main.c new file mode 100644 index 0000000..f678c9f --- /dev/null +++ b/examples/libs/main.c @@ -0,0 +1,10 @@ +#include + +#include "crc32.h" + +__root const uint32_t data[4] = { 0x00010203, 0x04050607, 0x08090A0B, 0x0C0D0E0F }; + +void main() { + uint32_t const * p = data; + printf("%u\n",Fast_CRC32(0xFFFFFFFF, p, 4)); +} diff --git a/examples/mix/CMakeLists.txt b/examples/mix/CMakeLists.txt new file mode 100644 index 0000000..8e315af --- /dev/null +++ b/examples/mix/CMakeLists.txt @@ -0,0 +1,28 @@ +cmake_minimum_required(VERSION 3.20) + +# TODO 1: Enable Assembly (ASM) for the project +project(Mix LANGUAGES C) + +add_executable(mix) + +# TODO 2: Add `fun.s` source to the `mix` target +target_sources(mix PRIVATE main.c) + +target_link_options(mix PRIVATE --semihosting) + +enable_testing() + +add_test(NAME mix-test + COMMAND /opt/iarsystems/bxarm/common/bin/CSpyBat + # C-SPY drivers for the Arm simulator via command line interface + /opt/iarsystems/bxarm/arm/bin/libarmPROC.so + /opt/iarsystems/bxarm/arm/bin/libarmSIM2.so + --plugin=/opt/iarsystems/bxarm/arm/bin/libarmLibsupportUniversal.so + # The target executable (built with debug information) + --debug_file=$ + # C-SPY driver options + --backend + --cpu=cortex-m4 + --semihosting) + +set_tests_properties(mix-test PROPERTIES PASS_REGULAR_EXPRESSION "42") diff --git a/examples/mix/fun.h b/examples/mix/fun.h new file mode 100644 index 0000000..d4eb564 --- /dev/null +++ b/examples/mix/fun.h @@ -0,0 +1,4 @@ +#ifndef FUN_H +#define FUN_H +extern int fun(); +#endif diff --git a/examples/mix/fun.s b/examples/mix/fun.s new file mode 100644 index 0000000..0311034 --- /dev/null +++ b/examples/mix/fun.s @@ -0,0 +1,43 @@ +/* This Assembly source file implements + fun() for multiple target architectures */ + + NAME fun + + PUBLIC _fun + PUBLIC fun + +#if defined(__IASMARM__) + SECTION `.text`:CODE:NOROOT(1) + THUMB +#elif defined(__IASMAVR__) + RSEG CODE:CODE:NOROOT(1) +#elif defined(__IASMRISCV__) + SECTION `.text`:CODE:REORDER:NOROOT(2) + CODE +#elif defined(__IASMRL78__) || defined(__IASMRX__) + SECTION `.text`:CODE:NOROOT(0) + CODE +#endif + + +_fun: +fun: +#if defined(__IASMARM__) + MOVS R0, #+0x2A + BX LR +#elif defined(__IASMAVR__) + LDI R16, 42 + LDI R17, 0 + RET +#elif defined(__IASMRISCV__) + LI12 A0, 0x2A + RET +#elif defined(__IASMRL78__) + MOVW AX, #0x2A + RET +#elif defined(__IASMRX__) + MOV.L #0x2A, R1 + RTS +#endif + + END diff --git a/examples/mix/main.c b/examples/mix/main.c new file mode 100644 index 0000000..86f4411 --- /dev/null +++ b/examples/mix/main.c @@ -0,0 +1,7 @@ +#include + +#include "fun.h" + +void main() { + printf("%d\n", fun()); +} diff --git a/examples/rh850/iar-cspy-rh850.cmake b/examples/rh850/iar-cspy-rh850.cmake deleted file mode 100644 index 309e42a..0000000 --- a/examples/rh850/iar-cspy-rh850.cmake +++ /dev/null @@ -1,28 +0,0 @@ -# Example for creating a test for CTest -# to execute the `IAR C-SPY Command-line Utility (cspybat.exe)` - -function(iar_cspy_add_test TARGET TEST_NAME EXPECTED_OUTPUT) - # Add a test for CTest - add_test(NAME ${TEST_NAME} - COMMAND ${TOOLKIT_DIR}/../common/bin/cspybat --silent - # C-SPY drivers - "${TOOLKIT_DIR}/bin/${CMAKE_SYSTEM_PROCESSOR}proc.dll" - "${TOOLKIT_DIR}/bin/${CMAKE_SYSTEM_PROCESSOR}sim.dll" - "--plugin=${TOOLKIT_DIR}/bin/${CMAKE_SYSTEM_PROCESSOR}bat.dll" - --debug_file=$ - # C-SPY macros settings - "--macro=${CMAKE_CURRENT_SOURCE_DIR}/${TARGET}.mac" - "--macro_param=testName=\"${TEST_NAME}\"" - "--macro_param=testExpected=${EXPECTED_OUTPUT}" - # C-SPY backend setup - --backend - -p $>,$,${TOOLKIT_DIR}/config/debugger/ior7f701401.ddf> - --core=$>,$,g3m> - --fpu double - --double=64 - -d sim - --multicore_nr_of_cores=1 ) - - # Set the test to interpret a C-SPY's message containing `PASS` - set_tests_properties(${TEST_NAME} PROPERTIES PASS_REGULAR_EXPRESSION "PASS") -endfunction() diff --git a/examples/rh850/iar-functions.cmake b/examples/rh850/iar-functions.cmake deleted file mode 100644 index 4140d06..0000000 --- a/examples/rh850/iar-functions.cmake +++ /dev/null @@ -1,16 +0,0 @@ -# CMake functions for the IAR Build Tools - -# Convert the ELF output to .hex -function(iar_elf_tool_hex TARGET) - add_custom_command(TARGET ${TARGET} POST_BUILD COMMAND ${CMAKE_IAR_ELFTOOL} --silent --ihex $ $>,$,$>.hex) -endfunction() - -# Convert the ELF output to .srec -function(iar_elf_tool_srec TARGET) - add_custom_command(TARGET ${TARGET} POST_BUILD COMMAND ${CMAKE_IAR_ELFTOOL} --silent --srec $ $>,$,$>.srec) -endfunction() - -# Convert the ELF output to .bin -function(iar_elf_tool_bin TARGET) - add_custom_command(TARGET ${TARGET} POST_BUILD COMMAND ${CMAKE_IAR_ELFTOOL} --silent --bin $ $>,$,$>.bin) -endfunction() \ No newline at end of file diff --git a/examples/rh850/mix-c-asm/CMakeLists.txt b/examples/rh850/mix-c-asm/CMakeLists.txt deleted file mode 100644 index 395341c..0000000 --- a/examples/rh850/mix-c-asm/CMakeLists.txt +++ /dev/null @@ -1,43 +0,0 @@ -cmake_minimum_required(VERSION 3.22) - -# Set the project name, [description] and [version], -# while enabling its required languages -project(Example1 - DESCRIPTION "Mixing C and Assembly" - VERSION 1.0.0 - LANGUAGES C ASM ) - -# Fallback option for generators other than `Ninja Multi-Config` -if (NOT CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE Debug) -endif() - -# Enable CTest -enable_testing() - -# Add the executable for the "mixLanguages" target -add_executable(mixLanguages - # Source files - main.c - mynum.asm ) - -# Set a preprocessor symbol, usable from "mixLanguages" target -target_compile_definitions(mixLanguages PUBLIC USE_ASM=1) - -# Set compile options for the target -target_compile_options(mixLanguages PRIVATE - $<$:--lock_global_pointer_regs=0 --dlib_config ${TOOLKIT_DIR}/lib/DLib_Config_Normal.h> - --core g3m --fpu=double --double=64 --data_model medium ) - -# Set the link options for the target -target_link_options(mixLanguages PRIVATE - $<$:--debug_lib --redirect ___write=___write_buffered> - --config ${TOOLKIT_DIR}/config/lnkr7f701401.icf - # The `SHELL:` prefix prevents option de-duplication - "SHELL:--config_def CSTACK_SIZE=0x1000" - "SHELL:--config_def HEAP_SIZE=0x1000" - "SHELL:--config_def _SELF_SIZE=0x20000" ) - -# Optional: test the project with CTest and IAR C-SPY -include(../iar-cspy-rh850.cmake) -iar_cspy_add_test(mixLanguages test_mynum 42) diff --git a/examples/rh850/mix-c-asm/main.c b/examples/rh850/mix-c-asm/main.c deleted file mode 100644 index 05cefef..0000000 --- a/examples/rh850/mix-c-asm/main.c +++ /dev/null @@ -1,23 +0,0 @@ -#include -#include "mynum.h" - -int answer; - -int main(void) -{ -#if USE_ASM - answer = mynum(); -#else - answer = 10; -#endif -/* NDEBUG is set automatically for when - bulding with -DCMAKE_BUILD_TYPE=Release */ -#ifndef NDEBUG - printf("-- app debug output begin --\n"); - printf("mixLanguages v%d.%d.%d\n", 1, 0, 0); - printf("The answer is: %d.\n",answer); - printf("-- app debug output end --\n"); -#endif - - return 0; -} diff --git a/examples/rh850/mix-c-asm/mixLanguages.mac b/examples/rh850/mix-c-asm/mixLanguages.mac deleted file mode 100644 index b86170a..0000000 --- a/examples/rh850/mix-c-asm/mixLanguages.mac +++ /dev/null @@ -1,33 +0,0 @@ -__param testName; -__param testExpected; - -__var _breakID; -__var _result; - -execUserSetup() -{ - __message "C-SPY TEST: started..."; - __message "C-SPY TEST: When the `answer` variable is read, `checkanswer()` will execute."; - _breakID = __setSimBreak("answer", "R", "checkAnswer()"); -} - -Done() -{ - __message "-- C-SPY TEST: Done()"; - if (_result == testExpected) - { - __message "-- C-SPY TEST:", testName, ". Result: PASS"; - } else { - __message "-- C-SPY TEST:", testName, ". Expected: ", testExpected, " Result: FAIL"; - } -} - -checkAnswer() -{ - __message "-- C-SPY TEST: checkAnswer()"; - if (testName == "test_mynum") - { - _result = answer; - Done(); - } -} diff --git a/examples/rh850/mix-c-asm/mynum.asm b/examples/rh850/mix-c-asm/mynum.asm deleted file mode 100644 index 2d1e5e1..0000000 --- a/examples/rh850/mix-c-asm/mynum.asm +++ /dev/null @@ -1,19 +0,0 @@ - NAME mynum - - #define SHT_PROGBITS 0x1 - - PUBLIC _mynum - - - SECTION `.text`:CODE:NOROOT(2) - CODE -_mynum: - MOV 42,r10 - JMP [lp] - - SECTION `.iar_vfe_header`:DATA:NOALLOC:NOROOT(2) - SECTION_TYPE SHT_PROGBITS, 0 - DATA - DC32 0 - - END diff --git a/examples/rh850/mix-c-asm/mynum.h b/examples/rh850/mix-c-asm/mynum.h deleted file mode 100644 index 0d19df4..0000000 --- a/examples/rh850/mix-c-asm/mynum.h +++ /dev/null @@ -1,4 +0,0 @@ -#ifndef MYNUM_H -#define MYNUM_H -extern int mynum(); -#endif diff --git a/examples/rh850/using-libs/CMakeLists.txt b/examples/rh850/using-libs/CMakeLists.txt deleted file mode 100644 index 18292cf..0000000 --- a/examples/rh850/using-libs/CMakeLists.txt +++ /dev/null @@ -1,18 +0,0 @@ -cmake_minimum_required (VERSION 3.22) - -project (Example2 - DESCRIPTION "Creating and using libraries" - VERSION 1.0.0 - LANGUAGES C ) - -# Fallback option for generators other than `Ninja Multi-Config` -if (NOT CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE Debug) -endif() - -# Enable CTest -enable_testing() - -# Recurse into the "lib" and "app" subdirectiories -add_subdirectory(lib) -add_subdirectory(app) diff --git a/examples/rh850/using-libs/app/CMakeLists.txt b/examples/rh850/using-libs/app/CMakeLists.txt deleted file mode 100644 index 3a939ff..0000000 --- a/examples/rh850/using-libs/app/CMakeLists.txt +++ /dev/null @@ -1,42 +0,0 @@ -# Add the executable for the "myProgram" target, -# specifying its source files -add_executable (myProgram - # Source files - main.c ) - -# Set the properties for the "myProgram" target -set_target_properties(myProgram PROPERTIES - CPU g3m - ICF "${TOOLKIT_DIR}/config/lnkr7f701401.icf" - # C-SPY-related properties - DDF "${TOOLKIT_DIR}/config/debugger/ior7f701401.ddf" ) - -# Set compile options for the target -target_compile_options(myProgram PRIVATE - $<$:--lock_global_pointer_regs=0 --dlib_config ${TOOLKIT_DIR}/lib/DLib_Config_Normal.h> - --core $ --fpu=double --double=64 --data_model medium ) - -# Set the link options for the target -target_link_options(myProgram PRIVATE - $<$:--debug_lib --redirect ___write=___write_buffered> - # Create a map file from the target's ELF - --map $.map - # The `SHELL:` prefix prevents option de-duplication - "SHELL:--config_def CSTACK_SIZE=0x1000" - "SHELL:--config_def HEAP_SIZE=0x1000" - "SHELL:--config_def _SELF_SIZE=0x20000" - # Set the linker script - --config $ ) - -# Link "myProgram" against the "myMath" library -target_link_libraries(myProgram LINK_PUBLIC myMath) - -# Optional: convert the output to .hex format -include(../../iar-functions.cmake) -iar_elf_tool_hex(myProgram) - -# Optional: test the project with CTest and IAR C-SPY -include(../../iar-cspy-rh850.cmake) -iar_cspy_add_test(myProgram test_add 42) -iar_cspy_add_test(myProgram test_sub 38) -iar_cspy_add_test(myProgram test_mul 80) diff --git a/examples/rh850/using-libs/app/main.c b/examples/rh850/using-libs/app/main.c deleted file mode 100644 index 039b257..0000000 --- a/examples/rh850/using-libs/app/main.c +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef NDEBUG -#include -#endif -#include -#include "myMath.h" - -int a = 40, b = 2; -int addResult; -int subResult; -int mulResult; - -int main(void) -{ - addResult = add(a, b); - subResult = sub(a, b); - mulResult = mul(a, b); - -/* In CMake, the NDEBUG preprocessor symbol - is set automatically when the build configuration is set for Release */ -#ifndef NDEBUG - printf("-- app debug output begin --\n"); - printf("%d + %d = %d\n", a, b, addResult); - printf("%d - %d = %d\n", a, b, subResult); - printf("%d * %d = %d\n", a, b, mulResult); - printf("-- app debug output end --\n"); -#endif - return 0; -} - diff --git a/examples/rh850/using-libs/app/myProgram.mac b/examples/rh850/using-libs/app/myProgram.mac deleted file mode 100644 index 6e05ea5..0000000 --- a/examples/rh850/using-libs/app/myProgram.mac +++ /dev/null @@ -1,51 +0,0 @@ -__param testName; -__param testExpected; - -__var _breakID; -__var _result; - -execUserSetup() -{ - /* Set up immediate breakpoints. */ - _breakID = __setSimBreak("addResult", "R", "addAccess()"); - _breakID = __setSimBreak("subResult", "R", "subAccess()"); - _breakID = __setSimBreak("mulResult", "R", "mulAccess()"); -} - -Done() -{ - if (_result == testExpected) - { - __message "-- C-SPY TEST:", testName, ". Result: PASS"; - } else { - __message "-- C-SPY TEST:", testName, ". Expected: ", testExpected, " Result: FAIL"; - } -} - -addAccess() -{ - if (testName == "test_add") - { - _result = addResult; - Done(); - } -} - -subAccess() -{ - if (testName == "test_sub") - { - _result = subResult; - Done(); - } -} - -mulAccess() -{ - if (testName == "test_mul") - { - _result = mulResult; - Done(); - } -} - diff --git a/examples/rh850/using-libs/lib/CMakeLists.txt b/examples/rh850/using-libs/lib/CMakeLists.txt deleted file mode 100644 index ecb6acc..0000000 --- a/examples/rh850/using-libs/lib/CMakeLists.txt +++ /dev/null @@ -1,16 +0,0 @@ -# The top-level CMakeLists.txt add this subdirectory -# This CMakeLists.txt builds the target "myMath" library -add_library(myMath - add.c - sub.c - mul.c ) - -# Set the compiler flags for the "myMath" target -target_compile_options(myMath PUBLIC - $<$:--core g3m --double=64 --data_model medium --dlib_config ${TOOLKIT_DIR}/lib/DLib_Config_Normal.h> ) - -# Define headers for the target -# PUBLIC headers are used for building the library -# PRIVATE sources, only used in this target -target_include_directories(myMath - PUBLIC $ ) diff --git a/examples/rh850/using-libs/lib/add.c b/examples/rh850/using-libs/lib/add.c deleted file mode 100644 index e0e8fdb..0000000 --- a/examples/rh850/using-libs/lib/add.c +++ /dev/null @@ -1,5 +0,0 @@ -#include "myMath.h" - -int add(int a, int b) { - return a + b; -} diff --git a/examples/rh850/using-libs/lib/mul.c b/examples/rh850/using-libs/lib/mul.c deleted file mode 100644 index 106fdb3..0000000 --- a/examples/rh850/using-libs/lib/mul.c +++ /dev/null @@ -1,5 +0,0 @@ -#include "myMath.h" - -int mul(int a, int b) { - return a * b; -} diff --git a/examples/rh850/using-libs/lib/myMath.h b/examples/rh850/using-libs/lib/myMath.h deleted file mode 100644 index 9c7aae3..0000000 --- a/examples/rh850/using-libs/lib/myMath.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef MY_MATH_H -#define MY_MATH_H - int add(int a, int b); - int sub(int a, int b); - int mul(int a, int b); -#endif diff --git a/examples/rh850/using-libs/lib/sub.c b/examples/rh850/using-libs/lib/sub.c deleted file mode 100644 index abefbab..0000000 --- a/examples/rh850/using-libs/lib/sub.c +++ /dev/null @@ -1,5 +0,0 @@ -#include "myMath.h" - -int sub(int a, int b) { - return a - --b; /* bug */ -} diff --git a/examples/riscv/iar-cspy-riscv.cmake b/examples/riscv/iar-cspy-riscv.cmake deleted file mode 100644 index 8302e55..0000000 --- a/examples/riscv/iar-cspy-riscv.cmake +++ /dev/null @@ -1,25 +0,0 @@ -# Example for creating a test for CTest -# to execute the `IAR C-SPY Command-line Utility (cspybat.exe)` - -function(iar_cspy_add_test TARGET TEST_NAME EXPECTED_OUTPUT) - # Add a test for CTest - add_test(NAME ${TEST_NAME} - COMMAND ${TOOLKIT_DIR}/../common/bin/cspybat --silent - # C-SPY drivers - "${TOOLKIT_DIR}/bin/${CMAKE_SYSTEM_PROCESSOR}proc.dll" - "${TOOLKIT_DIR}/bin/${CMAKE_SYSTEM_PROCESSOR}sim.dll" - "--plugin=${TOOLKIT_DIR}/bin/${CMAKE_SYSTEM_PROCESSOR}bat.dll" - --debug_file=$ - # C-SPY macros settings - "--macro=${CMAKE_CURRENT_SOURCE_DIR}/${TARGET}.mac" - "--macro_param=testName=\"${TEST_NAME}\"" - "--macro_param=testExpected=${EXPECTED_OUTPUT}" - # C-SPY backend setup - --backend - -p $>,$,${TOOLKIT_DIR}/config/debugger/ioriscv.ddf> - --core=$>,$,RV32IMAC> - -d sim ) - - # Set the test to interpret a C-SPY's message containing `PASS` - set_tests_properties(${TEST_NAME} PROPERTIES PASS_REGULAR_EXPRESSION "PASS") -endfunction() diff --git a/examples/riscv/iar-functions.cmake b/examples/riscv/iar-functions.cmake deleted file mode 100644 index 4140d06..0000000 --- a/examples/riscv/iar-functions.cmake +++ /dev/null @@ -1,16 +0,0 @@ -# CMake functions for the IAR Build Tools - -# Convert the ELF output to .hex -function(iar_elf_tool_hex TARGET) - add_custom_command(TARGET ${TARGET} POST_BUILD COMMAND ${CMAKE_IAR_ELFTOOL} --silent --ihex $ $>,$,$>.hex) -endfunction() - -# Convert the ELF output to .srec -function(iar_elf_tool_srec TARGET) - add_custom_command(TARGET ${TARGET} POST_BUILD COMMAND ${CMAKE_IAR_ELFTOOL} --silent --srec $ $>,$,$>.srec) -endfunction() - -# Convert the ELF output to .bin -function(iar_elf_tool_bin TARGET) - add_custom_command(TARGET ${TARGET} POST_BUILD COMMAND ${CMAKE_IAR_ELFTOOL} --silent --bin $ $>,$,$>.bin) -endfunction() \ No newline at end of file diff --git a/examples/riscv/mix-c-asm/CMakeLists.txt b/examples/riscv/mix-c-asm/CMakeLists.txt deleted file mode 100644 index 6ae6e22..0000000 --- a/examples/riscv/mix-c-asm/CMakeLists.txt +++ /dev/null @@ -1,41 +0,0 @@ -cmake_minimum_required(VERSION 3.22) - -# Set the project name, [description] and [version], -# while enabling its required languages -project(Example1 - DESCRIPTION "Mixing C and Assembly" - VERSION 1.0.0 - LANGUAGES C ASM ) - -# Fallback option for generators other than `Ninja Multi-Config` -if (NOT CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE Debug) -endif() - -# Enable CTest -enable_testing() - -# Add the executable for the "mixLanguages" target -add_executable(mixLanguages - # Source files - main.c - mynum.asm ) - -# Set a preprocessor symbol, usable from the "mixLanguages" target -target_compile_definitions(mixLanguages PUBLIC USE_ASM=1) - -# Set compile options for the target -target_compile_options(mixLanguages PRIVATE - $<$:--dlib_config normal> - --core=RV32IMAFDC ) - -# Set the link options for the target -target_link_options(mixLanguages PRIVATE - $<$:--debug_lib --redirect ___write=___write_buffered> - # The `SHELL:` prefix prevents option de-duplication - "SHELL:--config_def CSTACK_SIZE=0x1000" - "SHELL:--config_def HEAP_SIZE=0x1000" ) - -# Optional: test the project with CTest and IAR C-SPY -include(../iar-cspy-riscv.cmake) -iar_cspy_add_test(mixLanguages test_mynum 42) \ No newline at end of file diff --git a/examples/riscv/mix-c-asm/main.c b/examples/riscv/mix-c-asm/main.c deleted file mode 100644 index 05cefef..0000000 --- a/examples/riscv/mix-c-asm/main.c +++ /dev/null @@ -1,23 +0,0 @@ -#include -#include "mynum.h" - -int answer; - -int main(void) -{ -#if USE_ASM - answer = mynum(); -#else - answer = 10; -#endif -/* NDEBUG is set automatically for when - bulding with -DCMAKE_BUILD_TYPE=Release */ -#ifndef NDEBUG - printf("-- app debug output begin --\n"); - printf("mixLanguages v%d.%d.%d\n", 1, 0, 0); - printf("The answer is: %d.\n",answer); - printf("-- app debug output end --\n"); -#endif - - return 0; -} diff --git a/examples/riscv/mix-c-asm/mixLanguages.mac b/examples/riscv/mix-c-asm/mixLanguages.mac deleted file mode 100644 index b86170a..0000000 --- a/examples/riscv/mix-c-asm/mixLanguages.mac +++ /dev/null @@ -1,33 +0,0 @@ -__param testName; -__param testExpected; - -__var _breakID; -__var _result; - -execUserSetup() -{ - __message "C-SPY TEST: started..."; - __message "C-SPY TEST: When the `answer` variable is read, `checkanswer()` will execute."; - _breakID = __setSimBreak("answer", "R", "checkAnswer()"); -} - -Done() -{ - __message "-- C-SPY TEST: Done()"; - if (_result == testExpected) - { - __message "-- C-SPY TEST:", testName, ". Result: PASS"; - } else { - __message "-- C-SPY TEST:", testName, ". Expected: ", testExpected, " Result: FAIL"; - } -} - -checkAnswer() -{ - __message "-- C-SPY TEST: checkAnswer()"; - if (testName == "test_mynum") - { - _result = answer; - Done(); - } -} diff --git a/examples/riscv/mix-c-asm/mynum.asm b/examples/riscv/mix-c-asm/mynum.asm deleted file mode 100644 index a32d75a..0000000 --- a/examples/riscv/mix-c-asm/mynum.asm +++ /dev/null @@ -1,16 +0,0 @@ - #define SHT_PROGBITS 0x1 - - PUBLIC mynum - - SECTION `.text`:CODE:REORDER:NOROOT(2) - CODE -mynum: - li12 a0, 0x2A - ret - - SECTION `.iar_vfe_header`:DATA:NOALLOC:NOROOT(2) - SECTION_TYPE SHT_PROGBITS, 0 - DATA - DC32 0 - - END diff --git a/examples/riscv/mix-c-asm/mynum.h b/examples/riscv/mix-c-asm/mynum.h deleted file mode 100644 index 0d19df4..0000000 --- a/examples/riscv/mix-c-asm/mynum.h +++ /dev/null @@ -1,4 +0,0 @@ -#ifndef MYNUM_H -#define MYNUM_H -extern int mynum(); -#endif diff --git a/examples/riscv/using-libs/CMakeLists.txt b/examples/riscv/using-libs/CMakeLists.txt deleted file mode 100644 index 18292cf..0000000 --- a/examples/riscv/using-libs/CMakeLists.txt +++ /dev/null @@ -1,18 +0,0 @@ -cmake_minimum_required (VERSION 3.22) - -project (Example2 - DESCRIPTION "Creating and using libraries" - VERSION 1.0.0 - LANGUAGES C ) - -# Fallback option for generators other than `Ninja Multi-Config` -if (NOT CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE Debug) -endif() - -# Enable CTest -enable_testing() - -# Recurse into the "lib" and "app" subdirectiories -add_subdirectory(lib) -add_subdirectory(app) diff --git a/examples/riscv/using-libs/app/CMakeLists.txt b/examples/riscv/using-libs/app/CMakeLists.txt deleted file mode 100644 index 6eef098..0000000 --- a/examples/riscv/using-libs/app/CMakeLists.txt +++ /dev/null @@ -1,42 +0,0 @@ -# Add the executable for the "myProgram" target, -# specifying its source files -add_executable (myProgram - # Source files - main.c ) - -# Set the properties for the "myProgram" target -set_target_properties(myProgram PROPERTIES - CPU RV32IMAFDC - ICF "${TOOLKIT_DIR}/config/linker/SiFive/hifive1.icf" - # C-SPY-related properties - DDF "${TOOLKIT_DIR}/config/debugger/SiFive/hifive1.ddf" ) - -# Set the compiler flags for the "myProgram" target -target_compile_options(myProgram PRIVATE - $<$:--dlib_config normal> - --core $ ) - -# Set the linker flags for the target -target_link_options(myProgram PRIVATE - # Genex evaluates if we are using the `Debug` configuration - $<$:--debug_lib --redirect ___write=___write_buffered> - # Create a map file from the target's ELF - --map $.map - # The `SHELL:` prefix prevents option de-duplication - "SHELL:--config_def CSTACK_SIZE=0x1000" - "SHELL:--config_def HEAP_SIZE=0x1000" - # Set the linker script - --config $ ) - -# Link "myProgram" against the "myMath" library -target_link_libraries(myProgram LINK_PUBLIC myMath) - -# Optional: convert the output to .hex format -include(../../iar-functions.cmake) -iar_elf_tool_hex(myProgram) - -# Optional: test the project with CTest and IAR C-SPY -include(../../iar-cspy-riscv.cmake) -iar_cspy_add_test(myProgram test_add 42) -iar_cspy_add_test(myProgram test_sub 38) -iar_cspy_add_test(myProgram test_mul 80) diff --git a/examples/riscv/using-libs/app/main.c b/examples/riscv/using-libs/app/main.c deleted file mode 100644 index 039b257..0000000 --- a/examples/riscv/using-libs/app/main.c +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef NDEBUG -#include -#endif -#include -#include "myMath.h" - -int a = 40, b = 2; -int addResult; -int subResult; -int mulResult; - -int main(void) -{ - addResult = add(a, b); - subResult = sub(a, b); - mulResult = mul(a, b); - -/* In CMake, the NDEBUG preprocessor symbol - is set automatically when the build configuration is set for Release */ -#ifndef NDEBUG - printf("-- app debug output begin --\n"); - printf("%d + %d = %d\n", a, b, addResult); - printf("%d - %d = %d\n", a, b, subResult); - printf("%d * %d = %d\n", a, b, mulResult); - printf("-- app debug output end --\n"); -#endif - return 0; -} - diff --git a/examples/riscv/using-libs/app/myProgram.mac b/examples/riscv/using-libs/app/myProgram.mac deleted file mode 100644 index 6e05ea5..0000000 --- a/examples/riscv/using-libs/app/myProgram.mac +++ /dev/null @@ -1,51 +0,0 @@ -__param testName; -__param testExpected; - -__var _breakID; -__var _result; - -execUserSetup() -{ - /* Set up immediate breakpoints. */ - _breakID = __setSimBreak("addResult", "R", "addAccess()"); - _breakID = __setSimBreak("subResult", "R", "subAccess()"); - _breakID = __setSimBreak("mulResult", "R", "mulAccess()"); -} - -Done() -{ - if (_result == testExpected) - { - __message "-- C-SPY TEST:", testName, ". Result: PASS"; - } else { - __message "-- C-SPY TEST:", testName, ". Expected: ", testExpected, " Result: FAIL"; - } -} - -addAccess() -{ - if (testName == "test_add") - { - _result = addResult; - Done(); - } -} - -subAccess() -{ - if (testName == "test_sub") - { - _result = subResult; - Done(); - } -} - -mulAccess() -{ - if (testName == "test_mul") - { - _result = mulResult; - Done(); - } -} - diff --git a/examples/riscv/using-libs/lib/CMakeLists.txt b/examples/riscv/using-libs/lib/CMakeLists.txt deleted file mode 100644 index 25203a5..0000000 --- a/examples/riscv/using-libs/lib/CMakeLists.txt +++ /dev/null @@ -1,16 +0,0 @@ -# The top-level CMakeLists.txt add this subdirectory -# This CMakeLists.txt builds the target "myMath" library -add_library(myMath - add.c - sub.c - mul.c ) - -# Set the compiler flags for the "myMath" target -target_compile_options(myMath PUBLIC - $<$:--core RV32IMAFDC --dlib_config normal> ) - -# Define headers for the target -# PUBLIC headers are used for building the library -# PRIVATE sources, only used in this target -target_include_directories(myMath - PUBLIC $ ) diff --git a/examples/riscv/using-libs/lib/add.c b/examples/riscv/using-libs/lib/add.c deleted file mode 100644 index e0e8fdb..0000000 --- a/examples/riscv/using-libs/lib/add.c +++ /dev/null @@ -1,5 +0,0 @@ -#include "myMath.h" - -int add(int a, int b) { - return a + b; -} diff --git a/examples/riscv/using-libs/lib/mul.c b/examples/riscv/using-libs/lib/mul.c deleted file mode 100644 index 106fdb3..0000000 --- a/examples/riscv/using-libs/lib/mul.c +++ /dev/null @@ -1,5 +0,0 @@ -#include "myMath.h" - -int mul(int a, int b) { - return a * b; -} diff --git a/examples/riscv/using-libs/lib/myMath.h b/examples/riscv/using-libs/lib/myMath.h deleted file mode 100644 index 9c7aae3..0000000 --- a/examples/riscv/using-libs/lib/myMath.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef MY_MATH_H -#define MY_MATH_H - int add(int a, int b); - int sub(int a, int b); - int mul(int a, int b); -#endif diff --git a/examples/riscv/using-libs/lib/sub.c b/examples/riscv/using-libs/lib/sub.c deleted file mode 100644 index abefbab..0000000 --- a/examples/riscv/using-libs/lib/sub.c +++ /dev/null @@ -1,5 +0,0 @@ -#include "myMath.h" - -int sub(int a, int b) { - return a - --b; /* bug */ -} diff --git a/examples/rl78/iar-cspy-rl78.cmake b/examples/rl78/iar-cspy-rl78.cmake deleted file mode 100644 index ea98452..0000000 --- a/examples/rl78/iar-cspy-rl78.cmake +++ /dev/null @@ -1,29 +0,0 @@ -# Example for creating a test for CTest -# to execute the `IAR C-SPY Command-line Utility (cspybat.exe)` - -function(iar_cspy_add_test TARGET TEST_NAME EXPECTED_OUTPUT) - # Add a test for CTest - add_test(NAME ${TEST_NAME} - COMMAND ${TOOLKIT_DIR}/../common/bin/cspybat --silent - # C-SPY drivers - "${TOOLKIT_DIR}/bin/${CMAKE_SYSTEM_PROCESSOR}proc.dll" - "${TOOLKIT_DIR}/bin/${CMAKE_SYSTEM_PROCESSOR}sim.dll" - "--plugin=${TOOLKIT_DIR}/bin/${CMAKE_SYSTEM_PROCESSOR}bat.dll" - --debug_file=$ - # C-SPY macros settings - "--macro=${CMAKE_CURRENT_SOURCE_DIR}/${TARGET}.mac" - "--macro_param=testName=\"${TEST_NAME}\"" - "--macro_param=testExpected=${EXPECTED_OUTPUT}" - # C-SPY backend setup - --backend - --core=$>,$,s3> - --double=32 - --near_const_location rom0 - --near_const_start 0xF3000 - --near_const_size 27.749 - -p $>,$,${TOOLKIT_DIR}/config/debugger/iorl78_s3.ddf> - -d sim ) - - # Set the test to interpret a C-SPY's message containing `PASS` - set_tests_properties(${TEST_NAME} PROPERTIES PASS_REGULAR_EXPRESSION "PASS") -endfunction() diff --git a/examples/rl78/iar-functions.cmake b/examples/rl78/iar-functions.cmake deleted file mode 100644 index 4140d06..0000000 --- a/examples/rl78/iar-functions.cmake +++ /dev/null @@ -1,16 +0,0 @@ -# CMake functions for the IAR Build Tools - -# Convert the ELF output to .hex -function(iar_elf_tool_hex TARGET) - add_custom_command(TARGET ${TARGET} POST_BUILD COMMAND ${CMAKE_IAR_ELFTOOL} --silent --ihex $ $>,$,$>.hex) -endfunction() - -# Convert the ELF output to .srec -function(iar_elf_tool_srec TARGET) - add_custom_command(TARGET ${TARGET} POST_BUILD COMMAND ${CMAKE_IAR_ELFTOOL} --silent --srec $ $>,$,$>.srec) -endfunction() - -# Convert the ELF output to .bin -function(iar_elf_tool_bin TARGET) - add_custom_command(TARGET ${TARGET} POST_BUILD COMMAND ${CMAKE_IAR_ELFTOOL} --silent --bin $ $>,$,$>.bin) -endfunction() \ No newline at end of file diff --git a/examples/rl78/mix-c-asm/CMakeLists.txt b/examples/rl78/mix-c-asm/CMakeLists.txt deleted file mode 100644 index cbd3b21..0000000 --- a/examples/rl78/mix-c-asm/CMakeLists.txt +++ /dev/null @@ -1,49 +0,0 @@ -cmake_minimum_required(VERSION 3.22) - -# Set the project name, [description] and [version], -# while enabling its required languages -project(Example1 - DESCRIPTION "Mixing C and Assembly" - VERSION 1.0.0 - LANGUAGES C ASM ) - -# Fallback option for generators other than `Ninja Multi-Config` -if (NOT CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE Debug) -endif() - -# Enable CTest -enable_testing() - -# Add the executable for the "mixLanguages" target -add_executable(mixLanguages - # Source files - main.c - mynum.asm ) - -# Set a preprocessor symbol, usable from "mixLanguages" target -target_compile_definitions(mixLanguages PUBLIC USE_ASM=1) - -# Set compile options for the target -target_compile_options(mixLanguages PRIVATE - $<$:--code_model=near --data_model=near --calling_convention=v2 --near_const_location=rom0 --double=32 --dlib_config ${TOOLKIT_DIR}/lib/DLib_Config_Normal.h> - $<$:-D__NEAR_MODEL__ -D__NEAR_DATA_MODEL__> - --core s3) - -# Set the link options for the target -target_link_options(mixLanguages PRIVATE - $<$:--debug_lib --redirect ___write=___write_buffered> - --config ${TOOLKIT_DIR}/config/lnkrl78_s3.icf - # The `SHELL:` prefix prevents option de-duplication - "SHELL:--config_def __RESERVE_OCD_ROM=1" - "SHELL:--config_def _STACK_SIZE=256" - "SHELL:--config_def _NEAR_HEAP_SIZE=1024" - "SHELL:--config_def _FAR_HEAP_SIZE=4096" - "SHELL:--config_def _HUGE_HEAP_SIZE=0" - "SHELL:--define_symbol _NEAR_CONST_LOCATION=0" - "SHELL:--config_def _NEAR_CONST_LOCATION_START=0x3000" - "SHELL:--config_def _NEAR_CONST_LOCATION_SIZE=0x6F00" ) - -# Optional: test the project with CTest and IAR C-SPY -include(../iar-cspy-rl78.cmake) -iar_cspy_add_test(mixLanguages test_mynum 42) \ No newline at end of file diff --git a/examples/rl78/mix-c-asm/main.c b/examples/rl78/mix-c-asm/main.c deleted file mode 100644 index 05cefef..0000000 --- a/examples/rl78/mix-c-asm/main.c +++ /dev/null @@ -1,23 +0,0 @@ -#include -#include "mynum.h" - -int answer; - -int main(void) -{ -#if USE_ASM - answer = mynum(); -#else - answer = 10; -#endif -/* NDEBUG is set automatically for when - bulding with -DCMAKE_BUILD_TYPE=Release */ -#ifndef NDEBUG - printf("-- app debug output begin --\n"); - printf("mixLanguages v%d.%d.%d\n", 1, 0, 0); - printf("The answer is: %d.\n",answer); - printf("-- app debug output end --\n"); -#endif - - return 0; -} diff --git a/examples/rl78/mix-c-asm/mixLanguages.mac b/examples/rl78/mix-c-asm/mixLanguages.mac deleted file mode 100644 index b86170a..0000000 --- a/examples/rl78/mix-c-asm/mixLanguages.mac +++ /dev/null @@ -1,33 +0,0 @@ -__param testName; -__param testExpected; - -__var _breakID; -__var _result; - -execUserSetup() -{ - __message "C-SPY TEST: started..."; - __message "C-SPY TEST: When the `answer` variable is read, `checkanswer()` will execute."; - _breakID = __setSimBreak("answer", "R", "checkAnswer()"); -} - -Done() -{ - __message "-- C-SPY TEST: Done()"; - if (_result == testExpected) - { - __message "-- C-SPY TEST:", testName, ". Result: PASS"; - } else { - __message "-- C-SPY TEST:", testName, ". Expected: ", testExpected, " Result: FAIL"; - } -} - -checkAnswer() -{ - __message "-- C-SPY TEST: checkAnswer()"; - if (testName == "test_mynum") - { - _result = answer; - Done(); - } -} diff --git a/examples/rl78/mix-c-asm/mynum.asm b/examples/rl78/mix-c-asm/mynum.asm deleted file mode 100644 index 93dd729..0000000 --- a/examples/rl78/mix-c-asm/mynum.asm +++ /dev/null @@ -1,17 +0,0 @@ - #define SHT_PROGBITS 0x1 - - PUBLIC _mynum - - - SECTION `.text`:CODE:NOROOT(0) - CODE -_mynum: - MOVW AX, #0x2A ;; 1 cycle - RET ;; 6 cycles - - SECTION `.iar_vfe_header`:DATA:NOALLOC:NOROOT(1) - SECTION_TYPE SHT_PROGBITS, 0 - DATA - DC32 0 - - END diff --git a/examples/rl78/mix-c-asm/mynum.h b/examples/rl78/mix-c-asm/mynum.h deleted file mode 100644 index 0d19df4..0000000 --- a/examples/rl78/mix-c-asm/mynum.h +++ /dev/null @@ -1,4 +0,0 @@ -#ifndef MYNUM_H -#define MYNUM_H -extern int mynum(); -#endif diff --git a/examples/rl78/using-libs/CMakeLists.txt b/examples/rl78/using-libs/CMakeLists.txt deleted file mode 100644 index 18292cf..0000000 --- a/examples/rl78/using-libs/CMakeLists.txt +++ /dev/null @@ -1,18 +0,0 @@ -cmake_minimum_required (VERSION 3.22) - -project (Example2 - DESCRIPTION "Creating and using libraries" - VERSION 1.0.0 - LANGUAGES C ) - -# Fallback option for generators other than `Ninja Multi-Config` -if (NOT CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE Debug) -endif() - -# Enable CTest -enable_testing() - -# Recurse into the "lib" and "app" subdirectiories -add_subdirectory(lib) -add_subdirectory(app) diff --git a/examples/rl78/using-libs/app/CMakeLists.txt b/examples/rl78/using-libs/app/CMakeLists.txt deleted file mode 100644 index 639f0b9..0000000 --- a/examples/rl78/using-libs/app/CMakeLists.txt +++ /dev/null @@ -1,48 +0,0 @@ -# Add the executable for the "myProgram" target, -# specifying its source files -add_executable (myProgram - # Source files - main.c ) - -# Set the properties for the "myProgram" target -set_target_properties(myProgram PROPERTIES - CPU s3 - ICF "${TOOLKIT_DIR}/config/lnkrl78_s3.icf" - # C-SPY-related properties - DDF "${TOOLKIT_DIR}/config/debugger/iorl78_s3.ddf" ) - -# Set compile options for the target -target_compile_options(myProgram PRIVATE - $<$:--code_model=near --data_model=near --calling_convention=v2 --near_const_location=rom0 --double=32 --dlib_config ${TOOLKIT_DIR}/lib/DLib_Config_Normal.h> - $<$:-D__NEAR_MODEL__ -D__NEAR_DATA_MODEL__> - --core $ ) - -# Set the link options for the target -target_link_options(myProgram PRIVATE - $<$:--debug_lib --redirect ___write=___write_buffered> - # Create a map file from the target's ELF - --map $.map - # The `SHELL:` prefix prevents option de-duplication - "SHELL:--config_def __RESERVE_OCD_ROM=1" - "SHELL:--config_def _STACK_SIZE=256" - "SHELL:--config_def _NEAR_HEAP_SIZE=1024" - "SHELL:--config_def _FAR_HEAP_SIZE=4096" - "SHELL:--config_def _HUGE_HEAP_SIZE=0" - "SHELL:--define_symbol _NEAR_CONST_LOCATION=0" - "SHELL:--config_def _NEAR_CONST_LOCATION_START=0x3000" - "SHELL:--config_def _NEAR_CONST_LOCATION_SIZE=0x6F00" - # Set the linker script - --config $ ) - -# Link "myProgram" against the "myMath" library -target_link_libraries(myProgram LINK_PUBLIC myMath) - -# Optional: convert the output to .hex format -include(../../iar-functions.cmake) -iar_elf_tool_hex(myProgram) - -# Optional: test the project with CTest and IAR C-SPY -include(../../iar-cspy-rl78.cmake) -iar_cspy_add_test(myProgram test_add 42) -iar_cspy_add_test(myProgram test_sub 38) -iar_cspy_add_test(myProgram test_mul 80) diff --git a/examples/rl78/using-libs/app/main.c b/examples/rl78/using-libs/app/main.c deleted file mode 100644 index 039b257..0000000 --- a/examples/rl78/using-libs/app/main.c +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef NDEBUG -#include -#endif -#include -#include "myMath.h" - -int a = 40, b = 2; -int addResult; -int subResult; -int mulResult; - -int main(void) -{ - addResult = add(a, b); - subResult = sub(a, b); - mulResult = mul(a, b); - -/* In CMake, the NDEBUG preprocessor symbol - is set automatically when the build configuration is set for Release */ -#ifndef NDEBUG - printf("-- app debug output begin --\n"); - printf("%d + %d = %d\n", a, b, addResult); - printf("%d - %d = %d\n", a, b, subResult); - printf("%d * %d = %d\n", a, b, mulResult); - printf("-- app debug output end --\n"); -#endif - return 0; -} - diff --git a/examples/rl78/using-libs/app/myProgram.mac b/examples/rl78/using-libs/app/myProgram.mac deleted file mode 100644 index 6e05ea5..0000000 --- a/examples/rl78/using-libs/app/myProgram.mac +++ /dev/null @@ -1,51 +0,0 @@ -__param testName; -__param testExpected; - -__var _breakID; -__var _result; - -execUserSetup() -{ - /* Set up immediate breakpoints. */ - _breakID = __setSimBreak("addResult", "R", "addAccess()"); - _breakID = __setSimBreak("subResult", "R", "subAccess()"); - _breakID = __setSimBreak("mulResult", "R", "mulAccess()"); -} - -Done() -{ - if (_result == testExpected) - { - __message "-- C-SPY TEST:", testName, ". Result: PASS"; - } else { - __message "-- C-SPY TEST:", testName, ". Expected: ", testExpected, " Result: FAIL"; - } -} - -addAccess() -{ - if (testName == "test_add") - { - _result = addResult; - Done(); - } -} - -subAccess() -{ - if (testName == "test_sub") - { - _result = subResult; - Done(); - } -} - -mulAccess() -{ - if (testName == "test_mul") - { - _result = mulResult; - Done(); - } -} - diff --git a/examples/rl78/using-libs/lib/CMakeLists.txt b/examples/rl78/using-libs/lib/CMakeLists.txt deleted file mode 100644 index 0ff703f..0000000 --- a/examples/rl78/using-libs/lib/CMakeLists.txt +++ /dev/null @@ -1,16 +0,0 @@ -# The top-level CMakeLists.txt add this subdirectory -# This CMakeLists.txt builds the target "myMath" library -add_library(myMath - add.c - sub.c - mul.c ) - -# Set the compiler flags for the "myMath" target -target_compile_options(myMath PUBLIC - $<$:--core s3 --dlib_config ${TOOLKIT_DIR}/lib/DLib_Config_Normal.h> ) - -# Define headers for the target -# PUBLIC headers are used for building the library -# PRIVATE sources, only used in this target -target_include_directories(myMath - PUBLIC $ ) diff --git a/examples/rl78/using-libs/lib/add.c b/examples/rl78/using-libs/lib/add.c deleted file mode 100644 index e0e8fdb..0000000 --- a/examples/rl78/using-libs/lib/add.c +++ /dev/null @@ -1,5 +0,0 @@ -#include "myMath.h" - -int add(int a, int b) { - return a + b; -} diff --git a/examples/rl78/using-libs/lib/mul.c b/examples/rl78/using-libs/lib/mul.c deleted file mode 100644 index 106fdb3..0000000 --- a/examples/rl78/using-libs/lib/mul.c +++ /dev/null @@ -1,5 +0,0 @@ -#include "myMath.h" - -int mul(int a, int b) { - return a * b; -} diff --git a/examples/rl78/using-libs/lib/myMath.h b/examples/rl78/using-libs/lib/myMath.h deleted file mode 100644 index 9c7aae3..0000000 --- a/examples/rl78/using-libs/lib/myMath.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef MY_MATH_H -#define MY_MATH_H - int add(int a, int b); - int sub(int a, int b); - int mul(int a, int b); -#endif diff --git a/examples/rl78/using-libs/lib/sub.c b/examples/rl78/using-libs/lib/sub.c deleted file mode 100644 index abefbab..0000000 --- a/examples/rl78/using-libs/lib/sub.c +++ /dev/null @@ -1,5 +0,0 @@ -#include "myMath.h" - -int sub(int a, int b) { - return a - --b; /* bug */ -} diff --git a/examples/rx/iar-cspy-rx.cmake b/examples/rx/iar-cspy-rx.cmake deleted file mode 100644 index 40e550c..0000000 --- a/examples/rx/iar-cspy-rx.cmake +++ /dev/null @@ -1,28 +0,0 @@ -# Example for creating a test for CTest -# to execute the `IAR C-SPY Command-line Utility (cspybat.exe)` - -function(iar_cspy_add_test TARGET TEST_NAME EXPECTED_OUTPUT) - # Add a test for CTest - add_test(NAME ${TEST_NAME} - COMMAND ${TOOLKIT_DIR}/../common/bin/cspybat --silent - # C-SPY drivers - "${TOOLKIT_DIR}/bin/${CMAKE_SYSTEM_PROCESSOR}proc.dll" - "${TOOLKIT_DIR}/bin/${CMAKE_SYSTEM_PROCESSOR}sim.dll" - "--plugin=${TOOLKIT_DIR}/bin/${CMAKE_SYSTEM_PROCESSOR}bat.dll" - --debug_file=$ - # C-SPY macros settings - "--macro=${CMAKE_CURRENT_SOURCE_DIR}/${TARGET}.mac" - "--macro_param=testName=\"${TEST_NAME}\"" - "--macro_param=testExpected=${EXPECTED_OUTPUT}" - # C-SPY backend setup - --backend - -p $>,$,${TOOLKIT_DIR}/config/debugger/ior5f563ne.ddf> - --core=$>,$,rxv1> - --endian=l - --double=64 - --int=32 - --fpu=32 ) - - # Set the test to interpret a C-SPY's message containing `PASS` - set_tests_properties(${TEST_NAME} PROPERTIES PASS_REGULAR_EXPRESSION "PASS") -endfunction() diff --git a/examples/rx/iar-functions.cmake b/examples/rx/iar-functions.cmake deleted file mode 100644 index 4140d06..0000000 --- a/examples/rx/iar-functions.cmake +++ /dev/null @@ -1,16 +0,0 @@ -# CMake functions for the IAR Build Tools - -# Convert the ELF output to .hex -function(iar_elf_tool_hex TARGET) - add_custom_command(TARGET ${TARGET} POST_BUILD COMMAND ${CMAKE_IAR_ELFTOOL} --silent --ihex $ $>,$,$>.hex) -endfunction() - -# Convert the ELF output to .srec -function(iar_elf_tool_srec TARGET) - add_custom_command(TARGET ${TARGET} POST_BUILD COMMAND ${CMAKE_IAR_ELFTOOL} --silent --srec $ $>,$,$>.srec) -endfunction() - -# Convert the ELF output to .bin -function(iar_elf_tool_bin TARGET) - add_custom_command(TARGET ${TARGET} POST_BUILD COMMAND ${CMAKE_IAR_ELFTOOL} --silent --bin $ $>,$,$>.bin) -endfunction() \ No newline at end of file diff --git a/examples/rx/mix-c-asm/CMakeLists.txt b/examples/rx/mix-c-asm/CMakeLists.txt deleted file mode 100644 index f556769..0000000 --- a/examples/rx/mix-c-asm/CMakeLists.txt +++ /dev/null @@ -1,44 +0,0 @@ -cmake_minimum_required(VERSION 3.22) - -# Set the project name, [description] and [version], -# while enabling its required languages -project(Example1 - DESCRIPTION "Mixing C and Assembly" - VERSION 1.0.0 - LANGUAGES C ASM ) - -# Fallback option for generators other than `Ninja Multi-Config` -if (NOT CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE Debug) -endif() - -# Enable CTest -enable_testing() - -# Add the executable for the "mixLanguages" target -add_executable(mixLanguages - # Source files - main.c - mynum.asm ) - -# Set a preprocessor symbol, usable from "mixLanguages" target -target_compile_definitions(mixLanguages PUBLIC USE_ASM=1) - -# Set compile options for the target -target_compile_options(mixLanguages PRIVATE - $<$:--align_func=1 --dlib_config normal> - --core=rxv1 --double=64) - -# Set the link options for the target -target_link_options(mixLanguages PRIVATE - $<$:--debug_lib --redirect ___write=___write_buffered> - --config ${TOOLKIT_DIR}/config/lnkr5f563ne.icf - --vfe - # The `SHELL:` prefix prevents option de-duplication - "SHELL:--config_def _USTACK_SIZE=0x800" - "SHELL:--config_def _ISTACK_SIZE=0x800" - "SHELL:--config_def _HEAP_SIZE=0x800" ) - -# Optional: test the project with CTest and IAR C-SPY -include(../iar-cspy-rx.cmake) -iar_cspy_add_test(mixLanguages test_mynum 42) \ No newline at end of file diff --git a/examples/rx/mix-c-asm/main.c b/examples/rx/mix-c-asm/main.c deleted file mode 100644 index 05cefef..0000000 --- a/examples/rx/mix-c-asm/main.c +++ /dev/null @@ -1,23 +0,0 @@ -#include -#include "mynum.h" - -int answer; - -int main(void) -{ -#if USE_ASM - answer = mynum(); -#else - answer = 10; -#endif -/* NDEBUG is set automatically for when - bulding with -DCMAKE_BUILD_TYPE=Release */ -#ifndef NDEBUG - printf("-- app debug output begin --\n"); - printf("mixLanguages v%d.%d.%d\n", 1, 0, 0); - printf("The answer is: %d.\n",answer); - printf("-- app debug output end --\n"); -#endif - - return 0; -} diff --git a/examples/rx/mix-c-asm/mixLanguages.mac b/examples/rx/mix-c-asm/mixLanguages.mac deleted file mode 100644 index b86170a..0000000 --- a/examples/rx/mix-c-asm/mixLanguages.mac +++ /dev/null @@ -1,33 +0,0 @@ -__param testName; -__param testExpected; - -__var _breakID; -__var _result; - -execUserSetup() -{ - __message "C-SPY TEST: started..."; - __message "C-SPY TEST: When the `answer` variable is read, `checkanswer()` will execute."; - _breakID = __setSimBreak("answer", "R", "checkAnswer()"); -} - -Done() -{ - __message "-- C-SPY TEST: Done()"; - if (_result == testExpected) - { - __message "-- C-SPY TEST:", testName, ". Result: PASS"; - } else { - __message "-- C-SPY TEST:", testName, ". Expected: ", testExpected, " Result: FAIL"; - } -} - -checkAnswer() -{ - __message "-- C-SPY TEST: checkAnswer()"; - if (testName == "test_mynum") - { - _result = answer; - Done(); - } -} diff --git a/examples/rx/mix-c-asm/mynum.asm b/examples/rx/mix-c-asm/mynum.asm deleted file mode 100644 index 6bbab42..0000000 --- a/examples/rx/mix-c-asm/mynum.asm +++ /dev/null @@ -1,16 +0,0 @@ - #define SHT_PROGBITS 0x1 - - PUBLIC _mynum - - SECTION `.text`:CODE:NOROOT(0) - CODE -_mynum: - MOV.L #0x2A,R1 - RTS - - SECTION `.iar_vfe_header`:DATA:NOALLOC:NOROOT(2) - SECTION_TYPE SHT_PROGBITS, 0 - DATA - DC32 0 - - END diff --git a/examples/rx/mix-c-asm/mynum.h b/examples/rx/mix-c-asm/mynum.h deleted file mode 100644 index 0d19df4..0000000 --- a/examples/rx/mix-c-asm/mynum.h +++ /dev/null @@ -1,4 +0,0 @@ -#ifndef MYNUM_H -#define MYNUM_H -extern int mynum(); -#endif diff --git a/examples/rx/using-libs/CMakeLists.txt b/examples/rx/using-libs/CMakeLists.txt deleted file mode 100644 index 18292cf..0000000 --- a/examples/rx/using-libs/CMakeLists.txt +++ /dev/null @@ -1,18 +0,0 @@ -cmake_minimum_required (VERSION 3.22) - -project (Example2 - DESCRIPTION "Creating and using libraries" - VERSION 1.0.0 - LANGUAGES C ) - -# Fallback option for generators other than `Ninja Multi-Config` -if (NOT CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE Debug) -endif() - -# Enable CTest -enable_testing() - -# Recurse into the "lib" and "app" subdirectiories -add_subdirectory(lib) -add_subdirectory(app) diff --git a/examples/rx/using-libs/app/CMakeLists.txt b/examples/rx/using-libs/app/CMakeLists.txt deleted file mode 100644 index dc8c824..0000000 --- a/examples/rx/using-libs/app/CMakeLists.txt +++ /dev/null @@ -1,42 +0,0 @@ -# Add the executable for the "myProgram" target, -# specifying its source files -add_executable (myProgram - # Source files - main.c ) - -# Set the properties for the "myProgram" target -set_target_properties(myProgram PROPERTIES - CPU rxv1 - ICF "${TOOLKIT_DIR}/config/lnkr5f563ne.icf" - # C-SPY-related properties - DDF "${TOOLKIT_DIR}/config/debugger/ior5f563ne.ddf" ) - -# Set compile options for the target -target_compile_options(myProgram PRIVATE - $<$:--align_func=1 --dlib_config normal> - --core $ --double=64 ) - -# Set the link options for the target -target_link_options(myProgram PRIVATE - $<$:--debug_lib --redirect ___write=___write_buffered> - # Create a map file from the target's ELF - --map $.map - # The `SHELL:` prefix prevents option de-duplication - "SHELL:--config_def _USTACK_SIZE=0x800" - "SHELL:--config_def _ISTACK_SIZE=0x800" - "SHELL:--config_def _HEAP_SIZE=0x800" - # Set the linker script - --config $ ) - -# Link "myProgram" against the "myMath" library -target_link_libraries(myProgram LINK_PUBLIC myMath) - -# Optional: convert the output to .hex format -include(../../iar-functions.cmake) -iar_elf_tool_hex(myProgram) - -# Optional: test the project with CTest and IAR C-SPY -include(../../iar-cspy-rx.cmake) -iar_cspy_add_test(myProgram test_add 42) -iar_cspy_add_test(myProgram test_sub 38) -iar_cspy_add_test(myProgram test_mul 80) \ No newline at end of file diff --git a/examples/rx/using-libs/app/main.c b/examples/rx/using-libs/app/main.c deleted file mode 100644 index 039b257..0000000 --- a/examples/rx/using-libs/app/main.c +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef NDEBUG -#include -#endif -#include -#include "myMath.h" - -int a = 40, b = 2; -int addResult; -int subResult; -int mulResult; - -int main(void) -{ - addResult = add(a, b); - subResult = sub(a, b); - mulResult = mul(a, b); - -/* In CMake, the NDEBUG preprocessor symbol - is set automatically when the build configuration is set for Release */ -#ifndef NDEBUG - printf("-- app debug output begin --\n"); - printf("%d + %d = %d\n", a, b, addResult); - printf("%d - %d = %d\n", a, b, subResult); - printf("%d * %d = %d\n", a, b, mulResult); - printf("-- app debug output end --\n"); -#endif - return 0; -} - diff --git a/examples/rx/using-libs/app/myProgram.mac b/examples/rx/using-libs/app/myProgram.mac deleted file mode 100644 index 6e05ea5..0000000 --- a/examples/rx/using-libs/app/myProgram.mac +++ /dev/null @@ -1,51 +0,0 @@ -__param testName; -__param testExpected; - -__var _breakID; -__var _result; - -execUserSetup() -{ - /* Set up immediate breakpoints. */ - _breakID = __setSimBreak("addResult", "R", "addAccess()"); - _breakID = __setSimBreak("subResult", "R", "subAccess()"); - _breakID = __setSimBreak("mulResult", "R", "mulAccess()"); -} - -Done() -{ - if (_result == testExpected) - { - __message "-- C-SPY TEST:", testName, ". Result: PASS"; - } else { - __message "-- C-SPY TEST:", testName, ". Expected: ", testExpected, " Result: FAIL"; - } -} - -addAccess() -{ - if (testName == "test_add") - { - _result = addResult; - Done(); - } -} - -subAccess() -{ - if (testName == "test_sub") - { - _result = subResult; - Done(); - } -} - -mulAccess() -{ - if (testName == "test_mul") - { - _result = mulResult; - Done(); - } -} - diff --git a/examples/rx/using-libs/lib/CMakeLists.txt b/examples/rx/using-libs/lib/CMakeLists.txt deleted file mode 100644 index e5a5a1c..0000000 --- a/examples/rx/using-libs/lib/CMakeLists.txt +++ /dev/null @@ -1,16 +0,0 @@ -# The top-level CMakeLists.txt add this subdirectory -# This CMakeLists.txt builds the target "myMath" library -add_library(myMath - add.c - sub.c - mul.c ) - -# Set the compiler flags for the "myMath" target -target_compile_options(myMath PUBLIC - $<$:--core rxv1 --double=64 --dlib_config normal> ) - -# Define headers for the target -# PUBLIC headers are used for building the library -# PRIVATE sources, only used in this target -target_include_directories(myMath - PUBLIC $ ) diff --git a/examples/rx/using-libs/lib/add.c b/examples/rx/using-libs/lib/add.c deleted file mode 100644 index e0e8fdb..0000000 --- a/examples/rx/using-libs/lib/add.c +++ /dev/null @@ -1,5 +0,0 @@ -#include "myMath.h" - -int add(int a, int b) { - return a + b; -} diff --git a/examples/rx/using-libs/lib/mul.c b/examples/rx/using-libs/lib/mul.c deleted file mode 100644 index 106fdb3..0000000 --- a/examples/rx/using-libs/lib/mul.c +++ /dev/null @@ -1,5 +0,0 @@ -#include "myMath.h" - -int mul(int a, int b) { - return a * b; -} diff --git a/examples/rx/using-libs/lib/myMath.h b/examples/rx/using-libs/lib/myMath.h deleted file mode 100644 index 9c7aae3..0000000 --- a/examples/rx/using-libs/lib/myMath.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef MY_MATH_H -#define MY_MATH_H - int add(int a, int b); - int sub(int a, int b); - int mul(int a, int b); -#endif diff --git a/examples/rx/using-libs/lib/sub.c b/examples/rx/using-libs/lib/sub.c deleted file mode 100644 index abefbab..0000000 --- a/examples/rx/using-libs/lib/sub.c +++ /dev/null @@ -1,5 +0,0 @@ -#include "myMath.h" - -int sub(int a, int b) { - return a - --b; /* bug */ -} diff --git a/examples/stm8/iar-cspy-stm8.cmake b/examples/stm8/iar-cspy-stm8.cmake deleted file mode 100644 index d3f0d78..0000000 --- a/examples/stm8/iar-cspy-stm8.cmake +++ /dev/null @@ -1,24 +0,0 @@ -# Example for creating a test for CTest -# to execute the `IAR C-SPY Command-line Utility (cspybat.exe)` - -function(iar_cspy_add_test TARGET TEST_NAME EXPECTED_OUTPUT) - # Add a test for CTest - add_test(NAME ${TEST_NAME} - COMMAND ${TOOLKIT_DIR}/../common/bin/cspybat --silent - # C-SPY drivers - "${TOOLKIT_DIR}/bin/${CMAKE_SYSTEM_PROCESSOR}proc.dll" - "${TOOLKIT_DIR}/bin/${CMAKE_SYSTEM_PROCESSOR}sim.dll" - "--plugin=${TOOLKIT_DIR}/bin/${CMAKE_SYSTEM_PROCESSOR}bat.dll" - --debug_file=$ - # C-SPY macros settings - "--macro=${CMAKE_CURRENT_SOURCE_DIR}/${TARGET}.mac" - "--macro_param=testName=\"${TEST_NAME}\"" - "--macro_param=testExpected=${EXPECTED_OUTPUT}" - # C-SPY backend setup - --backend - -p $>,$,${TOOLKIT_DIR}/config/ddf/iostm8.ddf> ) - - # Set the test to interpret a C-SPY's message containing `PASS` - set_tests_properties(${TEST_NAME} PROPERTIES PASS_REGULAR_EXPRESSION "PASS") -endfunction() - diff --git a/examples/stm8/iar-functions.cmake b/examples/stm8/iar-functions.cmake deleted file mode 100644 index 4140d06..0000000 --- a/examples/stm8/iar-functions.cmake +++ /dev/null @@ -1,16 +0,0 @@ -# CMake functions for the IAR Build Tools - -# Convert the ELF output to .hex -function(iar_elf_tool_hex TARGET) - add_custom_command(TARGET ${TARGET} POST_BUILD COMMAND ${CMAKE_IAR_ELFTOOL} --silent --ihex $ $>,$,$>.hex) -endfunction() - -# Convert the ELF output to .srec -function(iar_elf_tool_srec TARGET) - add_custom_command(TARGET ${TARGET} POST_BUILD COMMAND ${CMAKE_IAR_ELFTOOL} --silent --srec $ $>,$,$>.srec) -endfunction() - -# Convert the ELF output to .bin -function(iar_elf_tool_bin TARGET) - add_custom_command(TARGET ${TARGET} POST_BUILD COMMAND ${CMAKE_IAR_ELFTOOL} --silent --bin $ $>,$,$>.bin) -endfunction() \ No newline at end of file diff --git a/examples/stm8/mix-c-asm/CMakeLists.txt b/examples/stm8/mix-c-asm/CMakeLists.txt deleted file mode 100644 index 6de1789..0000000 --- a/examples/stm8/mix-c-asm/CMakeLists.txt +++ /dev/null @@ -1,43 +0,0 @@ -cmake_minimum_required(VERSION 3.22) - -# Set the project name, [description] and [version], -# while enabling its required languages -project(Example1 - DESCRIPTION "Mixing C and Assembly" - VERSION 1.0.0 - LANGUAGES C ASM ) - -# Fallback option for generators other than `Ninja Multi-Config` -if (NOT CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE Debug) -endif() - -# Enable CTest -enable_testing() - -# Add the executable for the "mixLanguages" target -add_executable(mixLanguages - # Source files - main.c - mynum.asm ) - -# Set a preprocessor symbol, usable from "mixLanguages" target -target_compile_definitions(mixLanguages PUBLIC USE_ASM=1) - -# Set the compiler flags for the "mixLanguages" target -target_compile_options(mixLanguages PRIVATE - $<$:--vregs 16 --dlib_config ${TOOLKIT_DIR}/lib/dlstm8smn.h> - --data_model medium --code_model small ) - -# Set the linker options for the "mixLanguages" target - -target_link_options(mixLanguages PRIVATE - $<$:--debug_lib --redirect ___write=___write_buffered> - --config ${TOOLKIT_DIR}/config/lnkstm8.icf - # The `SHELL:` prefix prevents option de-duplication - "SHELL:--config_def _CSTACK_SIZE=0x100" - "SHELL:--config_def _HEAP_SIZE=0x100" ) - -# Optional: test the project with CTest and IAR C-SPY -include(../iar-cspy-stm8.cmake) -iar_cspy_add_test(mixLanguages test_mynum 42) \ No newline at end of file diff --git a/examples/stm8/mix-c-asm/main.c b/examples/stm8/mix-c-asm/main.c deleted file mode 100644 index 05cefef..0000000 --- a/examples/stm8/mix-c-asm/main.c +++ /dev/null @@ -1,23 +0,0 @@ -#include -#include "mynum.h" - -int answer; - -int main(void) -{ -#if USE_ASM - answer = mynum(); -#else - answer = 10; -#endif -/* NDEBUG is set automatically for when - bulding with -DCMAKE_BUILD_TYPE=Release */ -#ifndef NDEBUG - printf("-- app debug output begin --\n"); - printf("mixLanguages v%d.%d.%d\n", 1, 0, 0); - printf("The answer is: %d.\n",answer); - printf("-- app debug output end --\n"); -#endif - - return 0; -} diff --git a/examples/stm8/mix-c-asm/mixLanguages.mac b/examples/stm8/mix-c-asm/mixLanguages.mac deleted file mode 100644 index b86170a..0000000 --- a/examples/stm8/mix-c-asm/mixLanguages.mac +++ /dev/null @@ -1,33 +0,0 @@ -__param testName; -__param testExpected; - -__var _breakID; -__var _result; - -execUserSetup() -{ - __message "C-SPY TEST: started..."; - __message "C-SPY TEST: When the `answer` variable is read, `checkanswer()` will execute."; - _breakID = __setSimBreak("answer", "R", "checkAnswer()"); -} - -Done() -{ - __message "-- C-SPY TEST: Done()"; - if (_result == testExpected) - { - __message "-- C-SPY TEST:", testName, ". Result: PASS"; - } else { - __message "-- C-SPY TEST:", testName, ". Expected: ", testExpected, " Result: FAIL"; - } -} - -checkAnswer() -{ - __message "-- C-SPY TEST: checkAnswer()"; - if (testName == "test_mynum") - { - _result = answer; - Done(); - } -} diff --git a/examples/stm8/mix-c-asm/mynum.asm b/examples/stm8/mix-c-asm/mynum.asm deleted file mode 100644 index aa08000..0000000 --- a/examples/stm8/mix-c-asm/mynum.asm +++ /dev/null @@ -1,12 +0,0 @@ - PUBLIC mynum - - - SECTION `.near_func.text`:CODE:REORDER:NOROOT(0) - CODE -mynum: - LDW X, #0x2a - RET - - SECTION VREGS:DATA:REORDER:NOROOT(0) - - END diff --git a/examples/stm8/mix-c-asm/mynum.h b/examples/stm8/mix-c-asm/mynum.h deleted file mode 100644 index 0d19df4..0000000 --- a/examples/stm8/mix-c-asm/mynum.h +++ /dev/null @@ -1,4 +0,0 @@ -#ifndef MYNUM_H -#define MYNUM_H -extern int mynum(); -#endif diff --git a/examples/stm8/using-libs/CMakeLists.txt b/examples/stm8/using-libs/CMakeLists.txt deleted file mode 100644 index 18292cf..0000000 --- a/examples/stm8/using-libs/CMakeLists.txt +++ /dev/null @@ -1,18 +0,0 @@ -cmake_minimum_required (VERSION 3.22) - -project (Example2 - DESCRIPTION "Creating and using libraries" - VERSION 1.0.0 - LANGUAGES C ) - -# Fallback option for generators other than `Ninja Multi-Config` -if (NOT CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE Debug) -endif() - -# Enable CTest -enable_testing() - -# Recurse into the "lib" and "app" subdirectiories -add_subdirectory(lib) -add_subdirectory(app) diff --git a/examples/stm8/using-libs/app/CMakeLists.txt b/examples/stm8/using-libs/app/CMakeLists.txt deleted file mode 100644 index db1961d..0000000 --- a/examples/stm8/using-libs/app/CMakeLists.txt +++ /dev/null @@ -1,41 +0,0 @@ -# Add the executable for the "myProgram" target, -# specifying its source files -add_executable (myProgram - # Source files - main.c ) - -# Set the properties for the "myProgram" target -set_target_properties(myProgram PROPERTIES - ARCHITECTURE ${CMAKE_SYSTEM_PROCESSOR} - ICF "${TOOLKIT_DIR}/config/lnkstm8.icf" - # C-SPY-related properties - DDF "${TOOLKIT_DIR}/config/ddf/iostm8.ddf" ) - -# Set compile options for the target -target_compile_options(myProgram PRIVATE - $<$:--vregs 16 --dlib_config ${TOOLKIT_DIR}/lib/dlstm8smn.h> - --data_model medium --code_model small ) - -# Set the link options for the target -target_link_options(myProgram PRIVATE - $<$:--debug_lib --redirect ___write=___write_buffered> - # Create a map file from the target's ELF - --map $.map - # The `SHELL:` prefix prevents option de-duplication - "SHELL:--config_def _CSTACK_SIZE=0x100" - "SHELL:--config_def _HEAP_SIZE=0x100" - # Set the linker script - --config $ ) - -# Link "myProgram" against the "myMath" library -target_link_libraries(myProgram LINK_PUBLIC myMath) - -# Optional: convert the output to .hex format -include(../../iar-functions.cmake) -iar_elf_tool_hex(myProgram) - -# Optional: test the project with CTest and IAR C-SPY -include(../../iar-cspy-stm8.cmake) -iar_cspy_add_test(myProgram test_add 42) -iar_cspy_add_test(myProgram test_sub 38) -iar_cspy_add_test(myProgram test_mul 80) \ No newline at end of file diff --git a/examples/stm8/using-libs/app/main.c b/examples/stm8/using-libs/app/main.c deleted file mode 100644 index 039b257..0000000 --- a/examples/stm8/using-libs/app/main.c +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef NDEBUG -#include -#endif -#include -#include "myMath.h" - -int a = 40, b = 2; -int addResult; -int subResult; -int mulResult; - -int main(void) -{ - addResult = add(a, b); - subResult = sub(a, b); - mulResult = mul(a, b); - -/* In CMake, the NDEBUG preprocessor symbol - is set automatically when the build configuration is set for Release */ -#ifndef NDEBUG - printf("-- app debug output begin --\n"); - printf("%d + %d = %d\n", a, b, addResult); - printf("%d - %d = %d\n", a, b, subResult); - printf("%d * %d = %d\n", a, b, mulResult); - printf("-- app debug output end --\n"); -#endif - return 0; -} - diff --git a/examples/stm8/using-libs/app/myProgram.mac b/examples/stm8/using-libs/app/myProgram.mac deleted file mode 100644 index 6e05ea5..0000000 --- a/examples/stm8/using-libs/app/myProgram.mac +++ /dev/null @@ -1,51 +0,0 @@ -__param testName; -__param testExpected; - -__var _breakID; -__var _result; - -execUserSetup() -{ - /* Set up immediate breakpoints. */ - _breakID = __setSimBreak("addResult", "R", "addAccess()"); - _breakID = __setSimBreak("subResult", "R", "subAccess()"); - _breakID = __setSimBreak("mulResult", "R", "mulAccess()"); -} - -Done() -{ - if (_result == testExpected) - { - __message "-- C-SPY TEST:", testName, ". Result: PASS"; - } else { - __message "-- C-SPY TEST:", testName, ". Expected: ", testExpected, " Result: FAIL"; - } -} - -addAccess() -{ - if (testName == "test_add") - { - _result = addResult; - Done(); - } -} - -subAccess() -{ - if (testName == "test_sub") - { - _result = subResult; - Done(); - } -} - -mulAccess() -{ - if (testName == "test_mul") - { - _result = mulResult; - Done(); - } -} - diff --git a/examples/stm8/using-libs/lib/CMakeLists.txt b/examples/stm8/using-libs/lib/CMakeLists.txt deleted file mode 100644 index 7b9106b..0000000 --- a/examples/stm8/using-libs/lib/CMakeLists.txt +++ /dev/null @@ -1,16 +0,0 @@ -# The top-level CMakeLists.txt add this subdirectory -# This CMakeLists.txt builds the target "myMath" library -add_library(myMath - add.c - sub.c - mul.c ) - -# Set the compiler flags for the "myMath" target -target_compile_options(myMath PUBLIC - $<$:--data_model medium --code_model small --vregs 16 --dlib_config ${TOOLKIT_DIR}/lib/dlstm8smn.h> ) - -# Define headers for the target -# PUBLIC headers are used for building the library -# PRIVATE sources, only used in this target -target_include_directories(myMath - PUBLIC $ ) diff --git a/examples/stm8/using-libs/lib/add.c b/examples/stm8/using-libs/lib/add.c deleted file mode 100644 index e0e8fdb..0000000 --- a/examples/stm8/using-libs/lib/add.c +++ /dev/null @@ -1,5 +0,0 @@ -#include "myMath.h" - -int add(int a, int b) { - return a + b; -} diff --git a/examples/stm8/using-libs/lib/mul.c b/examples/stm8/using-libs/lib/mul.c deleted file mode 100644 index 106fdb3..0000000 --- a/examples/stm8/using-libs/lib/mul.c +++ /dev/null @@ -1,5 +0,0 @@ -#include "myMath.h" - -int mul(int a, int b) { - return a * b; -} diff --git a/examples/stm8/using-libs/lib/myMath.h b/examples/stm8/using-libs/lib/myMath.h deleted file mode 100644 index 9c7aae3..0000000 --- a/examples/stm8/using-libs/lib/myMath.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef MY_MATH_H -#define MY_MATH_H - int add(int a, int b); - int sub(int a, int b); - int mul(int a, int b); -#endif diff --git a/examples/stm8/using-libs/lib/sub.c b/examples/stm8/using-libs/lib/sub.c deleted file mode 100644 index abefbab..0000000 --- a/examples/stm8/using-libs/lib/sub.c +++ /dev/null @@ -1,5 +0,0 @@ -#include "myMath.h" - -int sub(int a, int b) { - return a - --b; /* bug */ -} diff --git a/examples/v850/iar-cspy-v850.cmake b/examples/v850/iar-cspy-v850.cmake deleted file mode 100644 index dd2f140..0000000 --- a/examples/v850/iar-cspy-v850.cmake +++ /dev/null @@ -1,25 +0,0 @@ -# Example for creating a test for CTest -# to execute the `IAR C-SPY Command-line Utility (cspybat.exe)` - -function(iar_cspy_add_test TARGET TEST_NAME EXPECTED_OUTPUT) - # Add a test for CTest - add_test(NAME ${TEST_NAME} - COMMAND ${TOOLKIT_DIR}/../common/bin/cspybat --silent - # C-SPY drivers - "${TOOLKIT_DIR}/bin/${CMAKE_SYSTEM_PROCESSOR}proc.dll" - "${TOOLKIT_DIR}/bin/${CMAKE_SYSTEM_PROCESSOR}sim.dll" - "--plugin=${TOOLKIT_DIR}/bin/${CMAKE_SYSTEM_PROCESSOR}bat.dll" - --debug_file=$ - # C-SPY macros settings - "--macro=${CMAKE_CURRENT_SOURCE_DIR}/${TARGET}.mac" - "--macro_param=testName=\"${TEST_NAME}\"" - "--macro_param=testExpected=${EXPECTED_OUTPUT}" - # C-SPY backend setup - --backend - -v00 - -p $>,$,${TOOLKIT_DIR}/config/ddf/iov850.ddf> - -d sim ) - - # Set the test to interpret a C-SPY's message containing `PASS` - set_tests_properties(${TEST_NAME} PROPERTIES PASS_REGULAR_EXPRESSION "PASS") -endfunction() \ No newline at end of file diff --git a/examples/v850/mix-c-asm/CMakeLists.txt b/examples/v850/mix-c-asm/CMakeLists.txt deleted file mode 100644 index 8324ec1..0000000 --- a/examples/v850/mix-c-asm/CMakeLists.txt +++ /dev/null @@ -1,46 +0,0 @@ -cmake_minimum_required(VERSION 3.22) - -# Set the project name, [description] and [version], -# while enabling its required languages -project(Example1 - DESCRIPTION "Mixing C and Assembly" - VERSION 1.0.0 - LANGUAGES C ASM ) - -# Fallback option for generators other than `Ninja Multi-Config` -if (NOT CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE Debug) -endif() - -# Enable CTest -enable_testing() - -# Add the executable for the "mixLanguages" target -add_executable(mixLanguages - # Source files - main.c - mynum.asm ) - -# Set a preprocessor symbol, usable from "mixLanguages" target -target_compile_definitions(mixLanguages PUBLIC USE_ASM=1) - -# Set the compiler flags for the "mixLanguages" target -target_compile_options(mixLanguages PRIVATE - $<$:-v0 -mt --code_model normal --lock_regs 0 --migration_preprocessor_extensions --dlib_config ${TOOLKIT_DIR}/lib/dl85nn0.h > - $<$:-v0 -DCODE_MODEL_NORMAL -DDATA_MODEL_TINY -w+ -s+> ) - -# Set the linker options for the "mixLanguages" target -target_link_options(mixLanguages PRIVATE - -f ${TOOLKIT_DIR}/config/lnk85.xcl - -rt - -s __program_start - # The `SHELL:` prefix prevents option de-duplication - "SHELL:-D_CSTACK_SIZE=1000" - ${TOOLKIT_DIR}/lib/dl85nn0.r85 - "SHELL:-e_PrintfFull=_Printf" - "SHELL:-e_ScanfFull=_Scanf" - "SHELL:-D_HEAP_SIZE=1000" ) - -# Optional: test the project with CTest and IAR C-SPY -include(../iar-cspy-v850.cmake) -iar_cspy_add_test(mixLanguages test_mynum 42) \ No newline at end of file diff --git a/examples/v850/mix-c-asm/main.c b/examples/v850/mix-c-asm/main.c deleted file mode 100644 index 05cefef..0000000 --- a/examples/v850/mix-c-asm/main.c +++ /dev/null @@ -1,23 +0,0 @@ -#include -#include "mynum.h" - -int answer; - -int main(void) -{ -#if USE_ASM - answer = mynum(); -#else - answer = 10; -#endif -/* NDEBUG is set automatically for when - bulding with -DCMAKE_BUILD_TYPE=Release */ -#ifndef NDEBUG - printf("-- app debug output begin --\n"); - printf("mixLanguages v%d.%d.%d\n", 1, 0, 0); - printf("The answer is: %d.\n",answer); - printf("-- app debug output end --\n"); -#endif - - return 0; -} diff --git a/examples/v850/mix-c-asm/mixLanguages.mac b/examples/v850/mix-c-asm/mixLanguages.mac deleted file mode 100644 index b86170a..0000000 --- a/examples/v850/mix-c-asm/mixLanguages.mac +++ /dev/null @@ -1,33 +0,0 @@ -__param testName; -__param testExpected; - -__var _breakID; -__var _result; - -execUserSetup() -{ - __message "C-SPY TEST: started..."; - __message "C-SPY TEST: When the `answer` variable is read, `checkanswer()` will execute."; - _breakID = __setSimBreak("answer", "R", "checkAnswer()"); -} - -Done() -{ - __message "-- C-SPY TEST: Done()"; - if (_result == testExpected) - { - __message "-- C-SPY TEST:", testName, ". Result: PASS"; - } else { - __message "-- C-SPY TEST:", testName, ". Expected: ", testExpected, " Result: FAIL"; - } -} - -checkAnswer() -{ - __message "-- C-SPY TEST: checkAnswer()"; - if (testName == "test_mynum") - { - _result = answer; - Done(); - } -} diff --git a/examples/v850/mix-c-asm/mynum.asm b/examples/v850/mix-c-asm/mynum.asm deleted file mode 100644 index 0e2efaa..0000000 --- a/examples/v850/mix-c-asm/mynum.asm +++ /dev/null @@ -1,39 +0,0 @@ - NAME mynum - - RSEG CSTACK:DATA:SORT:NOROOT(2) - - EXTERN ?longjmp10 - EXTERN ?longjmp2 - EXTERN ?longjmp6 - EXTERN ?setjmp10 - EXTERN ?setjmp2 - EXTERN ?setjmp6 - - PUBWEAK ?setjmp_save_lock10 - PUBWEAK ?setjmp_save_lock2 - PUBWEAK ?setjmp_save_lock6 - PUBLIC mynum - - - RSEG `CODE`:CODE:NOROOT(2) - CODE -mynum: - MOVEA 42,zero,r1 - JMP [lp] - - RSEG `CODE`:CODE:NOROOT(2) -?setjmp_save_lock10: - REQUIRE ?setjmp10 - REQUIRE ?longjmp10 - - RSEG `CODE`:CODE:NOROOT(2) -?setjmp_save_lock6: - REQUIRE ?setjmp6 - REQUIRE ?longjmp6 - - RSEG `CODE`:CODE:NOROOT(2) -?setjmp_save_lock2: - REQUIRE ?setjmp2 - REQUIRE ?longjmp2 - - END diff --git a/examples/v850/mix-c-asm/mynum.h b/examples/v850/mix-c-asm/mynum.h deleted file mode 100644 index 0d19df4..0000000 --- a/examples/v850/mix-c-asm/mynum.h +++ /dev/null @@ -1,4 +0,0 @@ -#ifndef MYNUM_H -#define MYNUM_H -extern int mynum(); -#endif diff --git a/examples/v850/using-libs/CMakeLists.txt b/examples/v850/using-libs/CMakeLists.txt deleted file mode 100644 index 18292cf..0000000 --- a/examples/v850/using-libs/CMakeLists.txt +++ /dev/null @@ -1,18 +0,0 @@ -cmake_minimum_required (VERSION 3.22) - -project (Example2 - DESCRIPTION "Creating and using libraries" - VERSION 1.0.0 - LANGUAGES C ) - -# Fallback option for generators other than `Ninja Multi-Config` -if (NOT CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE Debug) -endif() - -# Enable CTest -enable_testing() - -# Recurse into the "lib" and "app" subdirectiories -add_subdirectory(lib) -add_subdirectory(app) diff --git a/examples/v850/using-libs/app/CMakeLists.txt b/examples/v850/using-libs/app/CMakeLists.txt deleted file mode 100644 index 2bd75ea..0000000 --- a/examples/v850/using-libs/app/CMakeLists.txt +++ /dev/null @@ -1,38 +0,0 @@ -# Add the executable for the "myProgram" target, -# specifying its source files -add_executable (myProgram - # Source files - main.c ) - -# Set the properties for the "myProgram" target -set_target_properties(myProgram PROPERTIES - XCL "${TOOLKIT_DIR}/config/lnk85.xcl" - DDF "${TOOLKIT_DIR}/config/ddf/iov850.ddf" ) - -# Set compile options for the target -target_compile_options(myProgram PRIVATE - $<$:-v0 -mt --code_model normal --lock_regs 0 --migration_preprocessor_extensions --dlib_config ${TOOLKIT_DIR}/lib/dl85nn0.h >) - -# Set the link options for the target -target_link_options(myProgram PRIVATE - # Set the linker script - -f $ - -rt - -s __program_start - # Create a map file from the target's UBROF - -l $.map - # The `SHELL:` prefix prevents option de-duplication - "SHELL:-D_CSTACK_SIZE=1000" - ${TOOLKIT_DIR}/lib/dl85nn0.r85 - "SHELL:-e_PrintfFull=_Printf" - "SHELL:-e_ScanfFull=_Scanf" - "SHELL:-D_HEAP_SIZE=1000" ) - -# Link "myProgram" against the "myMath" library -target_link_libraries(myProgram LINK_PUBLIC myMath) - -# Optional: test the project with CTest and IAR C-SPY -include(../../iar-cspy-v850.cmake) -iar_cspy_add_test(myProgram test_add 42) -iar_cspy_add_test(myProgram test_sub 38) -iar_cspy_add_test(myProgram test_mul 80) \ No newline at end of file diff --git a/examples/v850/using-libs/app/main.c b/examples/v850/using-libs/app/main.c deleted file mode 100644 index 039b257..0000000 --- a/examples/v850/using-libs/app/main.c +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef NDEBUG -#include -#endif -#include -#include "myMath.h" - -int a = 40, b = 2; -int addResult; -int subResult; -int mulResult; - -int main(void) -{ - addResult = add(a, b); - subResult = sub(a, b); - mulResult = mul(a, b); - -/* In CMake, the NDEBUG preprocessor symbol - is set automatically when the build configuration is set for Release */ -#ifndef NDEBUG - printf("-- app debug output begin --\n"); - printf("%d + %d = %d\n", a, b, addResult); - printf("%d - %d = %d\n", a, b, subResult); - printf("%d * %d = %d\n", a, b, mulResult); - printf("-- app debug output end --\n"); -#endif - return 0; -} - diff --git a/examples/v850/using-libs/app/myProgram.mac b/examples/v850/using-libs/app/myProgram.mac deleted file mode 100644 index 6e05ea5..0000000 --- a/examples/v850/using-libs/app/myProgram.mac +++ /dev/null @@ -1,51 +0,0 @@ -__param testName; -__param testExpected; - -__var _breakID; -__var _result; - -execUserSetup() -{ - /* Set up immediate breakpoints. */ - _breakID = __setSimBreak("addResult", "R", "addAccess()"); - _breakID = __setSimBreak("subResult", "R", "subAccess()"); - _breakID = __setSimBreak("mulResult", "R", "mulAccess()"); -} - -Done() -{ - if (_result == testExpected) - { - __message "-- C-SPY TEST:", testName, ". Result: PASS"; - } else { - __message "-- C-SPY TEST:", testName, ". Expected: ", testExpected, " Result: FAIL"; - } -} - -addAccess() -{ - if (testName == "test_add") - { - _result = addResult; - Done(); - } -} - -subAccess() -{ - if (testName == "test_sub") - { - _result = subResult; - Done(); - } -} - -mulAccess() -{ - if (testName == "test_mul") - { - _result = mulResult; - Done(); - } -} - diff --git a/examples/v850/using-libs/lib/CMakeLists.txt b/examples/v850/using-libs/lib/CMakeLists.txt deleted file mode 100644 index 1d7fbae..0000000 --- a/examples/v850/using-libs/lib/CMakeLists.txt +++ /dev/null @@ -1,16 +0,0 @@ -# The top-level CMakeLists.txt add this subdirectory -# This CMakeLists.txt builds the target "myMath" library -add_library(myMath - add.c - sub.c - mul.c ) - -# Set the compiler flags for the "myMath" target -target_compile_options(myMath PUBLIC - $<$:-v0 -mt --code_model normal --lock_regs 0 --migration_preprocessor_extensions --dlib_config ${TOOLKIT_DIR}/lib/dl85nn0.h > ) - -# Define headers for the target -# PUBLIC headers are used for building the library -# PRIVATE sources, only used in this target -target_include_directories(myMath - PUBLIC $ ) diff --git a/examples/v850/using-libs/lib/add.c b/examples/v850/using-libs/lib/add.c deleted file mode 100644 index e0e8fdb..0000000 --- a/examples/v850/using-libs/lib/add.c +++ /dev/null @@ -1,5 +0,0 @@ -#include "myMath.h" - -int add(int a, int b) { - return a + b; -} diff --git a/examples/v850/using-libs/lib/mul.c b/examples/v850/using-libs/lib/mul.c deleted file mode 100644 index 106fdb3..0000000 --- a/examples/v850/using-libs/lib/mul.c +++ /dev/null @@ -1,5 +0,0 @@ -#include "myMath.h" - -int mul(int a, int b) { - return a * b; -} diff --git a/examples/v850/using-libs/lib/myMath.h b/examples/v850/using-libs/lib/myMath.h deleted file mode 100644 index 9c7aae3..0000000 --- a/examples/v850/using-libs/lib/myMath.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef MY_MATH_H -#define MY_MATH_H - int add(int a, int b); - int sub(int a, int b); - int mul(int a, int b); -#endif diff --git a/examples/v850/using-libs/lib/sub.c b/examples/v850/using-libs/lib/sub.c deleted file mode 100644 index abefbab..0000000 --- a/examples/v850/using-libs/lib/sub.c +++ /dev/null @@ -1,5 +0,0 @@ -#include "myMath.h" - -int sub(int a, int b) { - return a - --b; /* bug */ -} diff --git a/examples/version/CMakeLists.txt b/examples/version/CMakeLists.txt new file mode 100644 index 0000000..21dc8f2 --- /dev/null +++ b/examples/version/CMakeLists.txt @@ -0,0 +1,33 @@ +cmake_minimum_required(VERSION 3.20) + +# TODO 1: Add the `project()`'s `VERSION` and set it to `2.7.1` +project(Project LANGUAGES C) + +add_executable(version) + +target_sources(version PRIVATE main.c) + +# TODO 2: Configure `version.h.in` to generate `version.h` +configure_file() + +# TODO 3: Add the Project Binary Directory to the target's include directories +target_include_directories() + +target_link_options(version PRIVATE --semihosting) + +enable_testing() + +add_test(NAME version-test + COMMAND /opt/iarsystems/bxarm/common/bin/CSpyBat + # C-SPY drivers for the Arm simulator via command line interface + /opt/iarsystems/bxarm/arm/bin/libarmPROC.so + /opt/iarsystems/bxarm/arm/bin/libarmSIM2.so + --plugin=/opt/iarsystems/bxarm/arm/bin/libarmLibsupportUniversal.so + # The target executable (built with debug information) + --debug_file=$ + # C-SPY driver options + --backend + --cpu=cortex-m4 + --semihosting) + +set_tests_properties(version-test PROPERTIES PASS_REGULAR_EXPRESSION "2.7.1") diff --git a/examples/version/main.c b/examples/version/main.c new file mode 100644 index 0000000..a2448ad --- /dev/null +++ b/examples/version/main.c @@ -0,0 +1,7 @@ +#include + +#include "version.h" + +void main() { + printf("%d.%d.%d\n", Project_VERSION_MAJOR, Project_VERSION_MINOR, Project_VERSION_PATCH); +} diff --git a/examples/version/version.h.in b/examples/version/version.h.in new file mode 100644 index 0000000..bf12cfc --- /dev/null +++ b/examples/version/version.h.in @@ -0,0 +1,4 @@ +// TODO 4: Define the C macros with the CMake placeholders for version +#define Project_VERSION_MAJOR +#define Project_VERSION_MINOR +#define Project_VERSION_PATCH diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt deleted file mode 100644 index ae9e752..0000000 --- a/tests/CMakeLists.txt +++ /dev/null @@ -1,89 +0,0 @@ -cmake_minimum_required(VERSION 3.22) - -set(TOOLKIT_DIR $ENV{TOOLKIT_DIR}) -set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) - -list(APPEND CMAKE_CONFIGURATION_TYPES Debug Release RelWithDebInfo MinSizeRel) - -project(IAR-test LANGUAGES C CXX ASM) - -if(CMAKE_GENERATOR MATCHES "Ninja Multi-Config") - set(LINKER_MAP --map $/$.map) -else() - if(NOT CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE Debug) - endif() - set(LINKER_MAP --map ${CMAKE_CURRENT_BINARY_DIR}/$-${CMAKE_BUILD_TYPE}.map) -endif() - -# arch-specific -if(TARGET_ARCH STREQUAL arm) - set(LINKER_OPTS "SHELL:--config ${TOOLKIT_DIR}/config/generic.icf") -elseif(TARGET_ARCH STREQUAL avr) - set(ICC_OPTS -v3 --enhanced_core -ms) - set(ASM_OPTS -D__IASMAVR__) - set(LINKER_OPTS -f ${TOOLKIT_DIR}/src/template/lnk3s.xcl -rt -s __program_start ${TOOLKIT_DIR}/lib/dlib/dlAVR-3s-ec_mul-n.r90) - set(LINKER_MAP -l $/$.map) -elseif(TARGET_ARCH STREQUAL 430) - set(ASM_OPTS -D__IASM430__) - set(LINKER_OPTS -D_STACK_SIZE=0x40 -D_DATA16_HEAP_SIZE=0x40 -D_DATA20_HEAP_SIZE=0x40) - set(LINKER_OPTS ${LINKER_OPTS} "SHELL:-f ${TOOLKIT_DIR}/config/linker/lnk430f149.xcl -f ${TOOLKIT_DIR}/config/linker/multiplier.xcl") - set(LINKER_OPTS ${LINKER_OPTS} -s __program_start -rt ${TOOLKIT_DIR}/lib/dlib/dl430fn.r43) - set(LINKER_MAP -l $/$.map) -elseif(TARGET_ARCH STREQUAL 8051) - set(ASM_OPTS -D__IASM8051__ -D__CORE__=1 -D__CODE_MODEL=1 -D__DATA_MODEL__=1 -D__CALLING_CONVENTION__=2) - set(ICC_OPTS --core=plain --dptr=16,1 --data_model=large --code_model=near) - set(ICC_OPTS ${ICC_OPTS} --calling_convention=xdata_reentrant --place_constants=data --nr_virtual_regs 8) - set(ICC_OPTS ${ICC_OPTS} --dlib_config ${TOOLKIT_DIR}/lib/dlib/dl8051Normal.h) - set(LINKER_OPTS -f ${TOOLKIT_DIR}/config/devices/_generic/lnk51ew_8052.xcl -rt -s __program_start ${TOOLKIT_DIR}/lib/dlib/dl-pli-nlxd-1e16x01n.r51) - set(LINKER_OPTS ${LINKER_OPTS} -D_NR_OF_VIRTUAL_REGISTERS=8 -D?PBANK=0xA0 -D?CBANK=0xF0 ) - set(LINKER_OPTS ${LINKER_OPTS} -D?CBANK_MASK=0x30 -e?BCALL_30=?BCALL -e?BRET_30=?BRET -e?BDISPATCH_30=?BDISPATCH -D_CODEBANK_START=0x8000 ) - set(LINKER_OPTS ${LINKER_OPTS} -D_CODEBANK_END=0xFFFF -D_NR_OF_BANKS=0x03 ) - set(LINKER_OPTS ${LINKER_OPTS} -D_IDATA_STACK_SIZE=0x40 -D?ESP=0 -D?ESP_MASK=0 -D_EXTENDED_STACK_START=0 -D_EXTENDED_STACK_SIZE=0 ) - set(LINKER_OPTS ${LINKER_OPTS} -D_PDATA_STACK_SIZE=0x80 -D_XDATA_STACK_SIZE=0xEFF -D_XDATA_HEAP_SIZE=0xFF -D_FAR_HEAP_SIZE=0xFFF ) - set(LINKER_OPTS ${LINKER_OPTS} -D_HUGE_HEAP_SIZE=0xFFF -D_FAR22_HEAP_SIZE=0xFFF ) - set(LINKER_MAP -l $/$.map) -elseif(TARGET_ARCH MATCHES "(riscv|rx)") - set(LINKER_OPTS "SHELL:--config_def CSTACK_SIZE=0x1000 --config_def HEAP_SIZE=0x1000 --debug_lib") -elseif(TARGET_ARCH STREQUAL rh850) - set(LINKER_OPTS "SHELL:--config_def CSTACK_SIZE=0x1000 --config_def HEAP_SIZE=0x1000 --config_def _SELF_SIZE=0x20000 - --config ${TOOLKIT_DIR}/config/lnkr7f701401.icf") -elseif(TARGET_ARCH STREQUAL rl78) - set(LINKER_OPTS "SHELL:--config_def _STACK_SIZE=256 --config_def _NEAR_HEAP_SIZE=0x400 --config_def - _FAR_HEAP_SIZE=4096 --config_def _HUGE_HEAP_SIZE=0 --config_def _NEAR_CONST_LOCATION_START=0x2000 --config_def - _NEAR_CONST_LOCATION_SIZE=0x6F00 --define_symbol _NEAR_CONST_LOCATION=0 --debug_lib --config ${TOOLKIT_DIR}/config/lnkrl78_s3.icf") -elseif(TARGET_ARCH STREQUAL rx) - set(LINKER_OPTS "SHELL:--config_def _USTACK_SIZE=0x1000 --config_def _ISTACK_SIZE=0x1000 _HEAP_SIZE=0x1000 --debug_lib") -elseif(TARGET_ARCH STREQUAL stm8) - set(LINKER_OPTS "SHELL:--config_def _CSTACK_SIZE=0x100 --config_def _HEAP_SIZE=0x100") -endif() - -# Test the IAR C Compiler -add_executable(test-c) -target_sources(test-c PRIVATE module.c) -target_compile_options(test-c PRIVATE $<$:-Ol> -e ${ICC_OPTS}) -target_compile_definitions(test-c PRIVATE CSYMBOL=32) -target_link_options(test-c PRIVATE - ${LINKER_MAP} - ${LINKER_OPTS} -) - -# Test the IAR C++ Compiler -add_executable(test-cxx) -target_sources(test-cxx PRIVATE module.cxx) -target_compile_options(test-cxx PRIVATE $<$:-Om> -e ${ICC_OPTS}) -target_compile_definitions(test-cxx PRIVATE CXXSYM=64) -target_link_options(test-cxx PRIVATE - ${LINKER_MAP} - ${LINKER_OPTS} -) - -# Test the IAR Assembler -add_executable(test-asm) -target_sources(test-asm PRIVATE module.asm) -target_compile_definitions(test-asm PRIVATE ASMSYM=16 ${ASM_OPTS}) -target_link_options(test-asm PRIVATE - ${LINKER_MAP} - ${LINKER_OPTS} -) - diff --git a/tests/README.md b/tests/README.md deleted file mode 100644 index 1dacc85..0000000 --- a/tests/README.md +++ /dev/null @@ -1,78 +0,0 @@ -# Tests for the IAR toolchains on CMake -The tests in this directory are for the CMake Modules for the IAR Toolchains (e.g., `/path/to/share/cmake-x.xx/Modules/Compiler/IAR-*.cmake`). - -The `run-tests.sh` script will... -- build one executable for each supported language (`C`, `CXX` and `ASM`) using... -- the default CMake build configurations (`Debug`, `Release`, `DebWithRelInfo` and `MinSizeRel`). - -## Environment -The script was used with the following environments providing GNU Bash: - -- Cygwin (https://cygwin.com) - - IAR Embedded Workbench - - CMake for Windows - - Ninja for Windows -- MINGW64 (https://msys2.org) - - IAR Embedded Workbench - - CMake for Windows - - Ninja for Windows -- Ubuntu 20.04 (/WSL2) - - IAR Build Tools for Linux - - Cmake for Linux - - Ninja for Linux - -## Environment variables -### IAR_TOOL_ROOT -Export the `$IAR_TOOL_ROOT` environment variable, pointing to the top-level location in which all the IAR toolchains are installed. (Default: `/opt/iarsystems`) - -| Examples | Effect | -| :---------------------------- | :-------------------------------------------------------------------- | -| `/c/IAR_Systems` | Perform tests on all toolchains found on the top-level directory. | -| `/c/IAR_Systems/EW/ARM` | Perform tests only using the toolchains found in the `ARM` directory. | -| `/c/IAR_Systems/EW/ARM/[7-9]*` | Perform tests on "Embedded Workbench for Arm" from V7 to V9. | -| `/c/IAR_Systems/EW/ARM/9.30.1` | Perform tests only using "Embedded Workbench 9.30.1". | - -### IAR_LMS2_SERVER_IP (optional) -Export the `IAR_LMS2_SERVER_IP` environment variable pointing to the license server, if the client's 1st-time license setup is required. Applies to the `-GL` and `-NW` products. (Default: not set) - -### CMAKE_GENERATOR (optional) -Export the `CMAKE_GENERATOR` environment variable to specify which generator to use. (Default: `Ninja Multi-Config`) - -### MSYSTEM -This environment variable is automatically set by MSYS2, MINGW64 and MINGW32. Cygwin users must set it manually. - -Example: `export MSYSTEM=CYGWIN` - -## Examples - -### Using __MINGW64__ -The example below will test every tool found in `C:\IAR_Systems\EW` using MINGW64: -```bash -export IAR_TOOL_ROOT=/c/IAR_Systems/EW -# Extracted from a zip archive -export PATH=/c/cmake-3.25.0-x86_64/bin:$PATH -git clone https://github.com/iarsystems/cmake-tutorial ~ -cd ~/cmake-tutorial/tests -./run-tests.sh -``` - -### Using __Ubuntu (/WSL2)__ -The example below will test every tool found in `/opt/iarsystems` using Ubuntu (WSL2): -```bash -git clone https://github.com/iarsystems/cmake-tutorial ~ -cd ~/cmake-tutorial/tests -./run-tests.sh -``` - -### Using __Cygwin__ -The example below will test every tool found in `C:\IAR_Systems\EW` using Cygwin: -```bash -export IAR_TOOL_ROOT=/cygdrive/c/IAR_Systems/EW -# Only required by Cygwin -export MSYSTEM=CYGWIN -# Extracted from a zip archive -export PATH=/cygdrive/c/cmake-3.25.0-x86_64/bin:$PATH -git clone https://github.com/iarsystems/cmake-tutorial ~ -cd ~/cmake-tutorial/tests -./run-tests.sh -``` diff --git a/tests/module.asm b/tests/module.asm deleted file mode 100644 index 1e08236..0000000 --- a/tests/module.asm +++ /dev/null @@ -1,41 +0,0 @@ -#if defined(__IASM8051__) || defined(__IASM430__) - NAME main -#else - MODULE main -#endif - - PUBLIC main - PUBLIC __iar_program_start - PUBLIC __program_start - -#if defined(__IASMSTM8__) - EXTERN CSTACK$$Limit - SECTION `.near_func.text`:CODE:NOROOT(0) -#elif defined(__IASMAVR__) - ORG $0 - RJMP main - RSEG CODE -#elif defined(__IASM8051__) - ORG 0FFFEh - DC16 main - RSEG RCODE -?cmain: -#elif defined(__IASM430__) - ORG 0FFFEh - DC16 init - RSEG CSTACK - RSEG CODE -init: - MOV #SFE(CSTACK), SP -#else - EXTERN __iar_static_base$$GPREL - SECTION CSTACK:DATA:NOROOT(4) - SECTION `.cstartup`:CODE(2) - CODE -#endif - -__program_start: -__iar_program_start: -main: - NOP - END diff --git a/tests/module.c b/tests/module.c deleted file mode 100644 index f29b4b6..0000000 --- a/tests/module.c +++ /dev/null @@ -1,7 +0,0 @@ -#include "module.h" -__root int i; -__root int main() { - i = INTERNAL; - return i; -} - diff --git a/tests/module.cxx b/tests/module.cxx deleted file mode 100644 index f29b4b6..0000000 --- a/tests/module.cxx +++ /dev/null @@ -1,7 +0,0 @@ -#include "module.h" -__root int i; -__root int main() { - i = INTERNAL; - return i; -} - diff --git a/tests/module.h b/tests/module.h deleted file mode 100644 index 77d46b1..0000000 --- a/tests/module.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef __MODULE_H__ -#define __MODULE_H__ - -#if defined(__cplusplus) -#define INTERNAL CXXSYM -#elif !defined(__cplusplus) && defined(__IAR_SYSTEMS_ICC__) -#define INTERNAL CSYMBOL -#elif defined(__IAR_SYSTEMS_ASM__) -#define INTERNAL ASMSYM -#else -#error "Unable to determine INTERNAL symbol." -#endif /* __IAR_SYSTEMS_ICC */ - -#endif /* __MODULE_H__ */ diff --git a/tests/run-tests.sh b/tests/run-tests.sh deleted file mode 100755 index d60a638..0000000 --- a/tests/run-tests.sh +++ /dev/null @@ -1,217 +0,0 @@ -#!/bin/bash - -# Copyright (c) 2022 IAR Systems AB -# -# Test CMake with the IAR Build Tools -# -# See LICENSE for detailed license information -# - -# Environment variables that can be set for this script -# -# IAR_TOOL_ROOT -# Top-level location in which the IAR toolchains are installed -# MINGW64: with the full path (e.g.,) `/c/IAR_Systems/` -# Default: /opt/iarsystems -# -# IAR_LMS2_SERVER_IP -# If defined, automatic license setup will be performed -# -# MSYSTEM -# Only required for Windows hosts (e.g., MINGW64 or CYGWIN) -# Set by default by MINGW64 (and MINGW32) -# CygWin users: must manually export the variable to CYGWIN -# (e.g., export MSYSTEM=CYGWIN) -# -# CMAKE_GENERATOR -# Default: "Ninja Multi-Config" -# (e.g., export CMAKE_GENERATOR="MinGW Makefiles") -# - -BUILD_CFGS=(Debug RelWithDebInfo Release MinSizeRel) - -if ! ((${#IAR_TOOL_ROOT[@]})); then - IAR_TOOL_ROOT=/opt/iarsystems -fi - -if [ ! -z "$MSYSTEM" ]; then - EXT=.exe; -fi - -function lms2-setup() { - if [ ! -z $IAR_LMS2_SERVER_IP ]; then - LLM=$(dirname ${p})/../../common/bin/LightLicenseManager; - if [ -f $LLM ]; then - HAS_SETUP=$(${LLM} | grep setup); - if [ ! -z $HAS_SETUP ]; then - SETUP_CMD=setup; - else - SETUP_CMD=""; - fi - $LLM $SETUP_CMD -s $IAR_LMS2_SERVER_IP; - fi - fi -} - -function find_icc() { - if [ "$MSYSTEM" = "" ]; then - export CC="${p}"; - export CXX="${p}"; - else - export CC=$(cygpath -m "${p}"); - export CXX=$CC; - fi - export TOOLKIT_DIR=$(dirname $(dirname $CC)) - echo "Using CC: $CC"; - echo "Using CXX: $CXX"; -} - -function find_ilink() { - if [ "$MSYSTEM" = "" ]; then - export ASM=$(dirname ${p})/iasm${a}; - else - export ASM=$(cygpath -m $(dirname ${p})/iasm${a}${EXT}); - fi - echo "Using ASM: $ASM"; -} - -function find_xlink() { - if [ "$MSYSTEM" = "" ]; then - export ASM=$(cygpath -m $(dirname ${p})/a${a}${EXT}); - else - export ASM=$(dirname ${p})/a${a}; - fi - echo "Using ASM_COMPILER: $ASM"; -} - -function cmake_set_gen() { - # If no CMAKE_GENERATOR is set, defaults to `Ninja Multi-Config` - if [ "$CMAKE_GENERATOR" = "" ]; then - if [ "$MSYSTEM" = "" ]; then - export CMAKE_MAKE_PROGRAM=$(which ninja); - else - export CMAKE_MAKE_PROGRAM=$(cygpath -m $(which ninja)); - fi - if [ ! -f $CMAKE_MAKE_PROGRAM ]; then - echo "FATAL ERROR: CMAKE_MAKE_PROGRAM not found ($CMAKE_MAKE_PROGRAM). No ninja executable found either."; - exit 1; - fi - export CMAKE_GENERATOR="Ninja Multi-Config"; - else - export CONFIGURATION_TYPES=(Debug Release RelWithDebInfo MinSizeRel) - fi -} - -function cmake_configure() { - # Remove stale builds - rm -rf _build*; - if [ -z ${CONFIGURATION_TYPES} ]; then - cmake -B_builds -DTARGET_ARCH=${a} -DTOOLKIT_DIR=${TOOLKIT_DIR}; - else - for cfg in ${CONFIGURATION_TYPES[@]}; do - cmake -B_build-${cfg} -DCMAKE_BUILD_TYPE=${cfg} -DTARGET_ARCH=${a} -DTOOLKIT_DIR=${TOOLKIT_DIR} - done - fi - if [ $? -ne 0 ]; then - echo "FATAL ERROR: CMake configuration phase."; - exit 1; - fi -} - -function check_output() { - if [ -z ${CONFIGURATION_TYPES} ]; then - if [ -f _builds/${cfg}/test-c.${OUTPUT_FORMAT,,} ]; then - echo "+${cfg}:C ${OUTPUT_FORMAT} built successfully."; - else - echo "-${cfg}:C ${OUTPUT_FORMAT} not built."; - fi - if [ -f _builds/${cfg}/test-cxx.${OUTPUT_FORMAT,,} ]; then - echo "+${cfg}:CXX ${OUTPUT_FORMAT} built successfully."; - else - echo "-${cfg}:CXX ${OUTPUT_FORMAT} not built."; - fi - if [ -f _builds/${cfg}/test-asm.${OUTPUT_FORMAT,,} ]; then - echo "+${cfg}:ASM ${OUTPUT_FORMAT} built successfully."; - else - echo "-${cfg}:ASM ${OUTPUT_FORMAT} not built."; - fi - else - if [ -f _build-${cfg}/test-c.${OUTPUT_FORMAT,,} ]; then - echo "+${cfg}:C ${OUTPUT_FORMAT} built successfully."; - else - echo "-${cfg}:C ${OUTPUT_FORMAT} not built."; - fi - if [ -f _build-${cfg}/test-cxx.${OUTPUT_FORMAT,,} ]; then - echo "+${cfg}:CXX ${OUTPUT_FORMAT} built successfully."; - else - echo "-${cfg}:CXX ${OUTPUT_FORMAT} not built."; - fi - if [ -f _build-${cfg}/test-asm.${OUTPUT_FORMAT,,} ]; then - echo "+${cfg}:ASM ${OUTPUT_FORMAT} built successfully."; - else - echo "-${cfg}:ASM ${OUTPUT_FORMAT} not built."; - fi - fi -} - -function cmake_build() { - if [ -z ${CONFIGURATION_TYPES} ]; then - for cfg in ${BUILD_CFGS[@]}; do - echo "===== Build configuration: [${cfg}]"; - cmake --build _builds --config ${cfg} --verbose; - if [ $? -ne 0 ]; then - echo "FAIL: CMake building phase (${cfg})."; - exit 1; - fi - check_output; - done - else - for cfg in ${CONFIGURATION_TYPES[@]}; do - echo "===== Build configuration: [${cfg}]"; - cmake --build _build-${cfg} --verbose; - if [ $? -ne 0 ]; then - echo "FAIL: CMake building phase (${cfg})."; - exit 1; - fi - check_output; - done - - fi -} - -cmake_set_gen; - -echo "----------- ilink tools"; -ILINK_TOOL=(arm riscv rh850 rl78 rx stm8); -OUTPUT_FORMAT=ELF; -for r in ${IAR_TOOL_ROOT[@]}; do - for a in ${ILINK_TOOL[@]}; do - for b in $(find ${r} -path "*/${a}/bin"); do - for p in $(find ${b} -executable -name icc${a}${EXT}); do - find_icc; - find_ilink; - lms2-setup; - cmake_configure; - cmake_build; - done - done - done -done - -echo "----------- xlink tools"; -XLINK_TOOL=(8051 430 avr); -OUTPUT_FORMAT=BIN; -for r in ${IAR_TOOL_ROOT[@]}; do - for a in ${XLINK_TOOL[@]}; do - for b in $(find ${r} -path "*/${a}/bin"); do - for p in $(find ${b} -executable -name icc${a}${EXT}); do - find_icc; - find_xlink; - lms2-setup; - cmake_configure; - cmake_build; - done - done - done -done - diff --git a/tutorial/CMakeLists.txt b/tutorial/CMakeLists.txt new file mode 100644 index 0000000..81b3f71 --- /dev/null +++ b/tutorial/CMakeLists.txt @@ -0,0 +1,34 @@ +# set the minimum required version of CMake to be 3.20 +cmake_minimum_required(VERSION 3.20) + +# set the project name +project(Tutorial) + +# add the executable target +add_executable(tutorial) + +# target sources +target_sources(tutorial PRIVATE tutorial.c) + +# compiler options +target_compile_options(tutorial PRIVATE --cpu=cortex-m4) + +# linker options +target_link_options(tutorial PRIVATE --semihosting) + +enable_testing() + +add_test(NAME tutorialTest + COMMAND /opt/iarsystems/bxarm/common/bin/CSpyBat + # C-SPY drivers for the Arm simulator via command line interface + /opt/iarsystems/bxarm/arm/bin/libarmPROC.so + /opt/iarsystems/bxarm/arm/bin/libarmSIM2.so + --plugin=/opt/iarsystems/bxarm/arm/bin/libarmLibsupportUniversal.so + # The target executable (built with debug information) + --debug_file=$ + # C-SPY driver options + --backend + --cpu=cortex-m4 + --semihosting) + +set_tests_properties(tutorialTest PROPERTIES PASS_REGULAR_EXPRESSION "Hello world!") diff --git a/tutorial/bxarm.cmake b/tutorial/bxarm.cmake new file mode 100644 index 0000000..dc8d1ad --- /dev/null +++ b/tutorial/bxarm.cmake @@ -0,0 +1,27 @@ +# Toolchain File for the IAR C/C++ Compiler + +# Set CMake for cross-compiling +set(CMAKE_SYSTEM_NAME Generic) + +# Set CMake to use the IAR C/C++ Compiler from the IAR Build Tools for Arm +# Update if using a different supported target or operating system +set(CMAKE_ASM_COMPILER /opt/iarsystems/bxarm/arm/bin/iasmarm) +set(CMAKE_C_COMPILER /opt/iarsystems/bxarm/arm/bin/iccarm) +set(CMAKE_CXX_COMPILER /opt/iarsystems/bxarm/arm/bin/iccarm) + +# Avoids running the linker during try_compile() +set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) + +# Set the default build tool for Ninja gnerators +# Reasonably recent IAR products ships with ninja (https://ninja-build.org) +# The CMake code block below tries to find it. If not found, +# manually install the desired build system in your operating system +# Alternatively: set(CMAKE_MAKE_PROGRAM "/usr/bin/ninja") +if(CMAKE_GENERATOR MATCHES "^Ninja.*$") + find_program(CMAKE_MAKE_PROGRAM + NAMES ninja + PATHS $ENV{PATH} + /opt/iarsystems/bxarm/common/bin + REQUIRED) +endif() + diff --git a/tutorial/ewarm.cmake b/tutorial/ewarm.cmake new file mode 100644 index 0000000..2da3ef4 --- /dev/null +++ b/tutorial/ewarm.cmake @@ -0,0 +1,26 @@ +# Toolchain File for the IAR C/C++ Compiler + +# Set CMake for cross-compiling +set(CMAKE_SYSTEM_NAME Generic) + +# Set CMake to use the IAR C/C++ Compiler from the IAR Embedded Workbench for Arm +# Update if using a different supported target or operating system +set(CMAKE_ASM_COMPILER "C:/Program Files/IAR Systems/Embedded Workbench 9.3/arm/bin/iasmarm.exe") +set(CMAKE_C_COMPILER "C:/Program Files/IAR Systems/Embedded Workbench 9.3/arm/bin/iccarm.exe") +set(CMAKE_CXX_COMPILER "C:/Program Files/IAR Systems/Embedded Workbench 9.3/arm/bin/iccarm.exe") + +# Avoids running the linker during try_compile() +set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) + +# Set the default build tool for Ninja gnerators +# Reasonably recent IAR products ships with ninja (https://ninja-build.org) +# The CMake code block below tries to find it. If not found, +# manually install the desired build system in your operating system +# Alternatively: set(CMAKE_MAKE_PROGRAM "C:/path/to/ninja.exe") +if(CMAKE_GENERATOR MATCHES "^Ninja.*$") + find_program(CMAKE_MAKE_PROGRAM + NAMES ninja.exe + PATHS $ENV{PATH} + "C:/Program Files/IAR Systems/Embedded Workbench 9.3/common/bin" + REQUIRED) +endif() diff --git a/tutorial/tutorial.c b/tutorial/tutorial.c new file mode 100644 index 0000000..13ef719 --- /dev/null +++ b/tutorial/tutorial.c @@ -0,0 +1,5 @@ +#include + +void main() { + printf("Hello world!"); +}