Skip to content

Commit b7d0f46

Browse files
committed
Initial commit
0 parents  commit b7d0f46

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

117 files changed

+3840
-0
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
_builds
2+
Testing
3+

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2020-2021 IAR Systems AB
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+334
Large diffs are not rendered by default.

examples/iar-toolchain.cmake

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Toolchain File for the IAR C/C++ Compiler
2+
3+
# "Generic" is used when cross compiling
4+
set(CMAKE_SYSTEM_NAME Generic)
5+
6+
# Avoids running the linker during try_compile()
7+
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
8+
9+
# Action: Set the `<arch>` to the compiler's target architecture
10+
# Examples: 430, 8051, arm, avr, riscv, rx, rl78, rh850, stm8 or v850
11+
set(CMAKE_SYSTEM_PROCESSOR <arch>)
12+
13+
# Action: Set the `IAR_INSTALL_DIR` to the tool installation path
14+
set(IAR_INSTALL_DIR <path-to>/<embedded-workbench-installation-dir>)
15+
16+
# Set a generic `TOOLKIT_DIR` location for the supported architectures
17+
set(TOOLKIT_DIR "${IAR_INSTALL_DIR}/${CMAKE_SYSTEM_PROCESSOR}")
18+
19+
# Add the selected IAR toolchain to the PATH (only while CMake is running)
20+
if(UNIX)
21+
set(ENV{PATH} "${TOOLKIT_DIR}/bin:$ENV{PATH}")
22+
else()
23+
set(ENV{PATH} "${TOOLKIT_DIR}/bin;$ENV{PATH}")
24+
endif()
25+
26+
# CMake requires individual variables for the C Compiler, C++ Compiler and Assembler
27+
set(CMAKE_C_COMPILER "icc${CMAKE_SYSTEM_PROCESSOR}")
28+
set(CMAKE_CXX_COMPILER "icc${CMAKE_SYSTEM_PROCESSOR}")
29+
set(CMAKE_ASM_COMPILER "iasm${CMAKE_SYSTEM_PROCESSOR}")

examples/mix-c-asm/430/CMakeLists.txt

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
cmake_minimum_required(VERSION 3.22)
2+
3+
# Set the project name, [description] and [version],
4+
# while enabling its required languages
5+
project(Example1
6+
DESCRIPTION "Mixing C and Assembly"
7+
VERSION 1.0.0
8+
LANGUAGES C ASM )
9+
10+
# Add the executable for the "mixLanguages" target,
11+
# specifying its source files
12+
add_executable(mixLanguages
13+
# Source files
14+
../sources/main.c
15+
../sources/mynum-${CMAKE_SYSTEM_PROCESSOR}.asm )
16+
17+
# Set a preprocessor symbol, usable from "mixLanguages" target
18+
target_compile_definitions(mixLanguages PUBLIC USE_ASM=1)
19+
20+
# Set the compiler flags for the "mixLanguages" target
21+
target_compile_options(mixLanguages PRIVATE
22+
$<$<COMPILE_LANGUAGE:C>:--multiplier=16 --dlib_config ${TOOLKIT_DIR}/lib/dlib/dl430fn.h>
23+
-D__MSP430F149__ )
24+
25+
# Set the linker options for the "mixLanguages" target
26+
target_link_options(mixLanguages PRIVATE
27+
-f ${TOOLKIT_DIR}/config/linker/lnk430f149.xcl
28+
${TOOLKIT_DIR}/lib/dlib/dl430fn.r43
29+
# The `SHELL:` prefix prevents option de-duplication
30+
"SHELL:-D_DATA16_HEAP_SIZE=50"
31+
"SHELL:-D_STACK_SIZE=50"
32+
"SHELL:-D_DATA20_HEAP_SIZE=50" )
33+
34+
# Enable CTest
35+
enable_testing()
36+
37+
# The macro `add_test_cspy()` is a wrapper
38+
# To execute the `IAR C-SPY Debugger` (cspybat.exe) via `CTest`
39+
macro(add_test_cspy TESTNAME EXPECTED)
40+
# IAR C-SPY drivers to be used for the selected architecture
41+
list(APPEND _CSPY_DRIVERS
42+
"${TOOLKIT_DIR}/bin/${CMAKE_SYSTEM_PROCESSOR}proc.dll"
43+
"${TOOLKIT_DIR}/bin/${CMAKE_SYSTEM_PROCESSOR}sim.dll"
44+
"--plugin=${TOOLKIT_DIR}/bin/${CMAKE_SYSTEM_PROCESSOR}bat.dll" )
45+
46+
# IAR C-SPY parameters for the "mixLanguages" target
47+
list(APPEND _CSPYBAT_PARAMETERS
48+
--debug_file=$<TARGET_FILE:mixLanguages> )
49+
50+
# IAR C-SPY macros that integrates with CTest
51+
set (_CSPYBAT_TEST_MACRO
52+
"--macro=${CMAKE_CURRENT_SOURCE_DIR}/../sources/test.mac"
53+
"--macro_param=testName=\"${TESTNAME}\""
54+
"--macro_param=testExpected=${EXPECTED}" )
55+
56+
# IAR C-SPY backend parameters for the "mixLanguages" target
57+
list(APPEND _CSPYBAT_PARAMETERS_BACKEND
58+
-p ${TOOLKIT_DIR}/config/debugger/msp430f149.ddf
59+
--hwmul_base=0x130
60+
--hardware_multiplier=16
61+
--hwmult_type=1
62+
--iv_base=0xFFE0
63+
--odd_word_check
64+
--derivativeSim=MSP430F149
65+
-d sim )
66+
67+
# This list concatenates the previous lists to execute `cspybat`
68+
list(APPEND _CSPYBAT_COMMAND
69+
${TOOLKIT_DIR}/../common/bin/cspybat
70+
--silent
71+
${_CSPY_DRIVERS}
72+
${_CSPYBAT_PARAMETERS}
73+
${_CSPYBAT_TEST_MACRO}
74+
--backend
75+
${_CSPYBAT_PARAMETERS_BACKEND} )
76+
77+
# This is the `CTest` function that adds test capabilities
78+
add_test(NAME ${TESTNAME} COMMAND ${_CSPYBAT_COMMAND})
79+
80+
# Set the test to interpret a C-SPY's message containing `PASS`
81+
set_tests_properties(${TESTNAME} PROPERTIES PASS_REGULAR_EXPRESSION "PASS")
82+
83+
# Cleanup
84+
unset(_CSPY_DRIVERS)
85+
unset(_CSPYBAT_COMMAND)
86+
unset(_CSPYBAT_PARAMETERS)
87+
unset(_CSPYBAT_PARAMETERS_BACKEND)
88+
endmacro()
89+
90+
# Tests to be executed with `cspybat` directly from `CTest`
91+
add_test_cspy(test_mynum 42)
+105
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
cmake_minimum_required(VERSION 3.22)
2+
3+
# Set the project name, [description] and [version],
4+
# while enabling its required languages
5+
project(Example1
6+
DESCRIPTION "Mixing C and Assembly"
7+
VERSION 1.0.0
8+
LANGUAGES C ASM )
9+
10+
# Add the executable for the "mixLanguages" target,
11+
# specifying its source files
12+
add_executable(mixLanguages
13+
# Source files
14+
../sources/main.c
15+
../sources/mynum-${CMAKE_SYSTEM_PROCESSOR}.asm )
16+
17+
# Set a preprocessor symbol, usable from "mixLanguages" target
18+
target_compile_definitions(mixLanguages PUBLIC USE_ASM=1)
19+
20+
# Set the compiler flags for the "mixLanguages" target
21+
target_compile_options(mixLanguages PRIVATE
22+
$<$<COMPILE_LANGUAGE:C>:--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>
23+
$<$<COMPILE_LANGUAGE:ASM>:-v0 -D__CORE__=1 -D__CODE_MODEL__=1 -D__DATA_MODEL__=1 -D__CALLING_CONVENTION__=2 -D__NUMBER_OF_DPTRS__=1> )
24+
25+
# Set the linker options for the "mixLanguages" target
26+
target_link_options(mixLanguages PRIVATE
27+
-rt
28+
-f ${TOOLKIT_DIR}/config/devices/_generic/lnk51ew_8051.xcl
29+
${TOOLKIT_DIR}/lib/dlib/dl-pli-nlxd-1e16x01n.r51
30+
# The `SHELL:` prefix prevents option de-duplication
31+
"SHELL:-D_NR_OF_BANKS=0"
32+
"SHELL:-D_CODEBANK_END=0"
33+
"SHELL:-D_CODEBANK_START=0"
34+
"SHELL:-D_NR_OF_VIRTUAL_REGISTERS=8"
35+
"SHELL:-D?PBANK=0xA0"
36+
"SHELL:-D_IDATA_STACK_SIZE=0x40"
37+
"SHELL:-D?ESP=0"
38+
"SHELL:-D?ESP_MASK=0"
39+
"SHELL:-D_EXTENDED_STACK_START=0"
40+
"SHELL:-D_EXTENDED_STACK_SIZE=0"
41+
"SHELL:-D_PDATA_STACK_SIZE=0x80"
42+
"SHELL:-D_XDATA_STACK_SIZE=0xEFF"
43+
"SHELL:-D_XDATA_HEAP_SIZE=0xFF"
44+
"SHELL:-D_FAR_HEAP_SIZE=0xFFF"
45+
"SHELL:-D_HUGE_HEAP_SIZE=0xFFF"
46+
"SHELL:-D_FAR22_HEAP_SIZE=0xFFF" )
47+
48+
# Enable CTest
49+
enable_testing()
50+
51+
# The macro `add_test_cspy()` is a wrapper
52+
# To execute the `IAR C-SPY Debugger` (cspybat.exe) via `CTest`
53+
macro(add_test_cspy TESTNAME EXPECTED)
54+
# IAR C-SPY drivers to be used for the selected architecture
55+
list(APPEND _CSPY_DRIVERS
56+
"${TOOLKIT_DIR}/bin/${CMAKE_SYSTEM_PROCESSOR}proc.dll"
57+
"${TOOLKIT_DIR}/bin/${CMAKE_SYSTEM_PROCESSOR}sim.dll"
58+
"--plugin=${TOOLKIT_DIR}/bin/${CMAKE_SYSTEM_PROCESSOR}bat.dll" )
59+
60+
# IAR C-SPY parameters for the "mixLanguages" target
61+
list(APPEND _CSPYBAT_PARAMETERS
62+
--debug_file=$<TARGET_FILE:mixLanguages> )
63+
64+
# IAR C-SPY macros that integrates with CTest
65+
set (_CSPYBAT_TEST_MACRO
66+
"--macro=${CMAKE_CURRENT_SOURCE_DIR}/../sources/test.mac"
67+
"--macro_param=testName=\"${TESTNAME}\""
68+
"--macro_param=testExpected=${EXPECTED}" )
69+
70+
# IAR C-SPY backend parameters for the "mixLanguages" target
71+
list(APPEND _CSPYBAT_PARAMETERS_BACKEND
72+
-p ${TOOLKIT_DIR}/config/devices/_generic/io8051.ddf
73+
--proc_core=plain
74+
--proc_code_model=near
75+
--proc_nr_virtual_regs=8
76+
--proc_pdata_bank_reg_addr=0xA0
77+
--proc_dptr_nr_of=1
78+
--proc_data_model=small
79+
--proc_driver=sim )
80+
81+
# This list concatenates the previous lists to execute `cspybat`
82+
list(APPEND _CSPYBAT_COMMAND
83+
${TOOLKIT_DIR}/../common/bin/cspybat
84+
--silent
85+
${_CSPY_DRIVERS}
86+
${_CSPYBAT_PARAMETERS}
87+
${_CSPYBAT_TEST_MACRO}
88+
--backend
89+
${_CSPYBAT_PARAMETERS_BACKEND} )
90+
91+
# This is the `CTest` function that adds test capabilities
92+
add_test(NAME ${TESTNAME} COMMAND ${_CSPYBAT_COMMAND})
93+
94+
# Set the test to interpret a C-SPY's message containing `PASS`
95+
set_tests_properties(${TESTNAME} PROPERTIES PASS_REGULAR_EXPRESSION "PASS")
96+
97+
# Cleanup
98+
unset(_CSPY_DRIVERS)
99+
unset(_CSPYBAT_COMMAND)
100+
unset(_CSPYBAT_PARAMETERS)
101+
unset(_CSPYBAT_PARAMETERS_BACKEND)
102+
endmacro()
103+
104+
# Tests to be executed with `cspybat` directly from `CTest`
105+
add_test_cspy(test_mynum 42)

examples/mix-c-asm/arm/CMakeLists.txt

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
cmake_minimum_required(VERSION 3.22)
2+
3+
# Set the project name, [description] and [version],
4+
# while enabling its required languages
5+
project(Example1
6+
DESCRIPTION "Mixing C and Assembly"
7+
VERSION 1.0.0
8+
LANGUAGES C ASM )
9+
10+
# Add the executable for the "mixLanguages" target,
11+
# specifying its source files
12+
add_executable(mixLanguages
13+
# Source files
14+
../sources/main.c
15+
../sources/mynum-${CMAKE_SYSTEM_PROCESSOR}.asm )
16+
17+
# Set a preprocessor symbol, usable from "mixLanguages" target
18+
target_compile_definitions(mixLanguages PUBLIC USE_ASM=1)
19+
20+
# Set the compiler flags for the "mixLanguages" target
21+
target_compile_options(mixLanguages PRIVATE
22+
$<$<COMPILE_LANGUAGE:C>:--dlib_config normal>
23+
--cpu Cortex-M3 )
24+
25+
# Set the linker options for the "mixLanguages" target
26+
target_link_options(mixLanguages PRIVATE
27+
$<$<CONFIG:Debug>:--semihosting --redirect ___write=___write_buffered>
28+
--config ${TOOLKIT_DIR}/config/generic.icf )
29+
30+
# Enable CTest
31+
enable_testing()
32+
33+
# The macro `add_test_cspy()` is a wrapper
34+
# To execute the `IAR C-SPY Debugger` (cspybat.exe) via `CTest`
35+
macro(add_test_cspy TESTNAME EXPECTED)
36+
# IAR C-SPY drivers to be used for the selected architecture
37+
list(APPEND _CSPY_DRIVERS
38+
"${TOOLKIT_DIR}/bin/${CMAKE_SYSTEM_PROCESSOR}proc.dll"
39+
"${TOOLKIT_DIR}/bin/${CMAKE_SYSTEM_PROCESSOR}sim2.dll"
40+
"--plugin=${TOOLKIT_DIR}/bin/${CMAKE_SYSTEM_PROCESSOR}bat.dll" )
41+
42+
# IAR C-SPY parameters for the "mixLanguages" target
43+
list(APPEND _CSPYBAT_PARAMETERS
44+
--debug_file=$<TARGET_FILE:mixLanguages> )
45+
46+
# IAR C-SPY macros that integrates with CTest
47+
set (_CSPYBAT_TEST_MACRO
48+
"--macro=${CMAKE_CURRENT_SOURCE_DIR}/../sources/test.mac"
49+
"--macro_param=testName=\"${TESTNAME}\""
50+
"--macro_param=testExpected=${EXPECTED}" )
51+
52+
# IAR C-SPY backend parameters for the "mixLanguages" target
53+
list(APPEND _CSPYBAT_PARAMETERS_BACKEND
54+
--endian=little
55+
--cpu=Cortex-M3
56+
--fpu=None
57+
--semihosting
58+
--multicore_nr_of_cores=1 )
59+
60+
# This list concatenates the previous lists to execute `cspybat`
61+
list(APPEND _CSPYBAT_COMMAND
62+
${TOOLKIT_DIR}/../common/bin/cspybat
63+
--silent
64+
${_CSPY_DRIVERS}
65+
${_CSPYBAT_PARAMETERS}
66+
${_CSPYBAT_TEST_MACRO}
67+
--backend
68+
${_CSPYBAT_PARAMETERS_BACKEND} )
69+
70+
# This is the `CTest` function that adds test capabilities
71+
add_test(NAME ${TESTNAME} COMMAND ${_CSPYBAT_COMMAND})
72+
73+
# Set the test to interpret a C-SPY's message containing `PASS`
74+
set_tests_properties(${TESTNAME} PROPERTIES PASS_REGULAR_EXPRESSION "PASS")
75+
76+
# Cleanup
77+
unset(_CSPY_DRIVERS)
78+
unset(_CSPYBAT_COMMAND)
79+
unset(_CSPYBAT_PARAMETERS)
80+
unset(_CSPYBAT_PARAMETERS_BACKEND)
81+
endmacro()
82+
83+
# Tests to be executed with `cspybat` directly from `CTest`
84+
add_test_cspy(test_mynum 42)

0 commit comments

Comments
 (0)