Browse Source
- Simplified tutorial on README.md - Converted examples to their interactive counterparts - Added version example - Added cmake-tutorial wiki entriespull/38/head v2024.01
Felipe Torrezan
9 months ago
186 changed files with 453 additions and 4164 deletions
@ -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 }} |
|||
|
@ -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=$<TARGET_FILE:${TARGET}> |
|||
# 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 $<IF:$<BOOL:$<TARGET_PROPERTY:${TARGET},DDF>>,$<TARGET_PROPERTY:${TARGET},DDF>,${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() |
@ -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 |
|||
$<$<COMPILE_LANGUAGE:C>:--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) |
@ -1,23 +0,0 @@ |
|||
#include <stdio.h> |
|||
#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; |
|||
} |
@ -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(); |
|||
} |
|||
} |
@ -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 |
@ -1,4 +0,0 @@ |
|||
#ifndef MYNUM_H |
|||
#define MYNUM_H |
|||
extern int mynum(); |
|||
#endif |
@ -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) |
@ -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 |
|||
$<$<COMPILE_LANGUAGE:C>:--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 $<TARGET_PROPERTY:NAME>.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 $<TARGET_PROPERTY:XCL> |
|||
# 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) |
@ -1,29 +0,0 @@ |
|||
#ifndef NDEBUG |
|||
#include <stdio.h> |
|||
#endif |
|||
#include <stdlib.h> |
|||
#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; |
|||
} |
|||
|
@ -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(); |
|||
} |
|||
} |
|||
|
@ -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 |
|||
$<$<COMPILE_LANGUAGE:C>:--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 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/.> ) |
@ -1,5 +0,0 @@ |
|||
#include "myMath.h" |
|||
|
|||
int add(int a, int b) { |
|||
return a + b; |
|||
} |
@ -1,5 +0,0 @@ |
|||
#include "myMath.h" |
|||
|
|||
int mul(int a, int b) { |
|||
return a * b; |
|||
} |
@ -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 |
@ -1,5 +0,0 @@ |
|||
#include "myMath.h" |
|||
|
|||
int sub(int a, int b) { |
|||
return a - --b; /* bug */ |
|||
} |
@ -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=$<TARGET_FILE:${TARGET}> |
|||
# 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 $<IF:$<BOOL:$<TARGET_PROPERTY:${TARGET},DDF>>,$<TARGET_PROPERTY:${TARGET},DDF>,${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() |
@ -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 |
|||
$<$<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> |
|||
$<$<COMPILE_LANGUAGE:ASM>:-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) |
@ -1,23 +0,0 @@ |
|||
#include <stdio.h> |
|||
#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; |
|||
} |
@ -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(); |
|||
} |
|||
} |
@ -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 |
@ -1,4 +0,0 @@ |
|||
#ifndef MYNUM_H |
|||
#define MYNUM_H |
|||
extern int mynum(); |
|||
#endif |
@ -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) |
@ -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 |
|||
$<$<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> ) |
|||
|
|||
# Set the linker flags for the target |
|||
target_link_options(myProgram PRIVATE |
|||
-rt |
|||
# Set the linker script |
|||
-f $<TARGET_PROPERTY:XCL> |
|||
${TOOLKIT_DIR}/lib/dlib/dl-pli-nlxd-1e16x01n.r51 |
|||
# Create a map file from the target's UBROF |
|||
-l $<TARGET_PROPERTY:NAME>.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) |
@ -1,29 +0,0 @@ |
|||
#ifndef NDEBUG |
|||
#include <stdio.h> |
|||
#endif |
|||
#include <stdlib.h> |
|||
#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; |
|||
} |
|||
|
@ -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(); |
|||
} |
|||
} |
|||
|
@ -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 |
|||
$<$<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> |
|||
$<$<COMPILE_LANGUAGE:ASM>:-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 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/.> ) |
@ -1,5 +0,0 @@ |
|||
#include "myMath.h" |
|||
|
|||
int add(int a, int b) { |
|||
return a + b; |
|||
} |
@ -1,5 +0,0 @@ |
|||
#include "myMath.h" |
|||
|
|||
int mul(int a, int b) { |
|||
return a * b; |
|||
} |
@ -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 |
@ -1,5 +0,0 @@ |
|||
#include "myMath.h" |
|||
|
|||
int sub(int a, int b) { |
|||
return a - --b; /* bug */ |
|||
} |
@ -0,0 +1,3 @@ |
|||
# Interactive examples |
|||
|
|||
Visit the [wiki](https://github.com/iarsystems/cmake-tutorial/wiki) for details and answers. |
@ -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) |
|||
|
@ -1,10 +0,0 @@ |
|||
#include <intrinsics.h> |
|||
#include <stdio.h> |
|||
|
|||
void main() { |
|||
while (1) { |
|||
printf("Hello world!\n"); |
|||
__no_operation(); |
|||
} |
|||
} |
|||
|
@ -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=$<TARGET_FILE:${TARGET}> |
|||
$<IF:$<BOOL:$<TARGET_PROPERTY:${TARGET},DMAC>>,--device_macro=$<TARGET_PROPERTY:${TARGET},DMAC>,> |
|||
# 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=$<IF:$<BOOL:$<TARGET_PROPERTY:${TARGET},CPU>>,$<TARGET_PROPERTY:${TARGET},CPU>,Cortex-M3> |
|||
--fpu=$<IF:$<BOOL:$<TARGET_PROPERTY:${TARGET},FPU>>,$<TARGET_PROPERTY:${TARGET},FPU>,None> |
|||
$<IF:$<BOOL:$<TARGET_PROPERTY:${TARGET},DEVICE>>,--device=$<TARGET_PROPERTY:${TARGET},DEVICE>,> |
|||
--semihosting |
|||
--endian=little |
|||
$<IF:$<BOOL:$<TARGET_PROPERTY:${TARGET},DDF>>,-p,> |
|||
$<IF:$<BOOL:$<TARGET_PROPERTY:${TARGET},DDF>>,$<TARGET_PROPERTY:${TARGET},DDF>,> ) |
|||
|
|||
# Set the test to interpret a C-SPY's message containing `PASS` |
|||
set_tests_properties(${TEST_NAME} PROPERTIES PASS_REGULAR_EXPRESSION "PASS") |
|||
endfunction() |
@ -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 $<TARGET_FILE:${TARGET}> $<IF:$<BOOL:$<TARGET_PROPERTY:${TARGET},OUTPUT_NAME>>,$<TARGET_PROPERTY:${TARGET},OUTPUT_NAME>,$<TARGET_PROPERTY:${TARGET},NAME>>.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 $<TARGET_FILE:${TARGET}> $<IF:$<BOOL:$<TARGET_PROPERTY:${TARGET},OUTPUT_NAME>>,$<TARGET_PROPERTY:${TARGET},OUTPUT_NAME>,$<TARGET_PROPERTY:${TARGET},NAME>>.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 $<TARGET_FILE:${TARGET}> $<IF:$<BOOL:$<TARGET_PROPERTY:${TARGET},OUTPUT_NAME>>,$<TARGET_PROPERTY:${TARGET},OUTPUT_NAME>,$<TARGET_PROPERTY:${TARGET},NAME>>.bin) |
|||
endfunction() |
@ -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 |
|||
$<$<COMPILE_LANGUAGE:C>:--dlib_config normal> |
|||
--cpu Cortex-M3 ) |
|||
|
|||
# Set the link options for the target |
|||
target_link_options(mixLanguages PRIVATE |
|||
$<$<CONFIG:Debug>:--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) |
@ -1,23 +0,0 @@ |
|||
#include <stdio.h> |
|||
#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; |
|||
} |
@ -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(); |
|||
} |
|||
} |
@ -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 |
@ -1,4 +0,0 @@ |
|||
#ifndef MYNUM_H |
|||
#define MYNUM_H |
|||
extern int mynum(); |
|||
#endif |
@ -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) |
@ -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 |
|||
$<$<COMPILE_LANGUAGE:C,CXX>:--dlib_config normal> |
|||
--cpu $<TARGET_PROPERTY:CPU> --fpu $<TARGET_PROPERTY:FPU> ) |
|||
|
|||
# Set the link options for the target |
|||
target_link_options(myProgram PRIVATE |
|||
# Genex evaluates if we are using the `Debug` configuration |
|||
$<$<CONFIG:Debug>:--semihosting --redirect ___write=___write_buffered> |
|||
# Create a map file from the target's ELF |
|||
--map $<TARGET_PROPERTY:NAME>.map |
|||
# Set the linker script |
|||
--config $<TARGET_PROPERTY:ICF> ) |
|||
|
|||
# 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) |
@ -1,29 +0,0 @@ |
|||
#ifndef NDEBUG |
|||
#include <stdio.h> |
|||
#endif |
|||
#include <stdlib.h> |
|||
#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; |
|||
} |
|||
|
@ -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(); |
|||
} |
|||
} |
|||
|
@ -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 |
|||
$<$<COMPILE_LANGUAGE:C>:--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 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/.> ) |
@ -1,5 +0,0 @@ |
|||
#include "myMath.h" |
|||
|
|||
int add(int a, int b) { |
|||
return a + b; |
|||
} |
@ -1,5 +0,0 @@ |
|||
#include "myMath.h" |
|||
|
|||
int mul(int a, int b) { |
|||
return a * b; |
|||
} |
@ -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 |
@ -1,5 +0,0 @@ |
|||
#include "myMath.h" |
|||
|
|||
int sub(int a, int b) { |
|||
return a - --b; /* bug */ |
|||
} |
@ -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=$<TARGET_FILE:${TARGET}> |
|||
# 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() |
@ -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 |
|||
$<$<COMPILE_LANGUAGE:C>:--enhanced_core -ms -y --initializers_in_flash --dlib --dlib_config ${TOOLKIT_DIR}/lib/dlib/dlAVR-3s-ec_mul-n.h> |
|||
$<$<COMPILE_LANGUAGE:ASM>:-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) |
@ -1,23 +0,0 @@ |
|||
#include <stdio.h> |
|||
#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; |
|||
} |
@ -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(); |
|||
} |
|||
} |
@ -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 |
@ -1,4 +0,0 @@ |
|||
#ifndef MYNUM_H |
|||
#define MYNUM_H |
|||
extern int mynum(); |
|||
#endif |
@ -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) |
@ -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 |
|||
$<$<COMPILE_LANGUAGE:C>:--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 $<TARGET_PROPERTY:XCL> |
|||
# Create a map file from the target's UBROF |
|||
-l $<TARGET_PROPERTY:NAME>.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) |
@ -1,29 +0,0 @@ |
|||
#ifndef NDEBUG |
|||
#include <stdio.h> |
|||
#endif |
|||
#include <stdlib.h> |
|||
#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; |
|||
} |
|||
|
@ -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(); |
|||
} |
|||
} |
|||
|
@ -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 |
|||
$<$<COMPILE_LANGUAGE:C>:--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 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/.> ) |
@ -1,5 +0,0 @@ |
|||
#include "myMath.h" |
|||
|
|||
int add(int a, int b) { |
|||
return a + b; |
|||
} |
@ -1,5 +0,0 @@ |
|||
#include "myMath.h" |
|||
|
|||
int mul(int a, int b) { |
|||
return a * b; |
|||
} |
@ -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 |
@ -1,5 +0,0 @@ |
|||
#include "myMath.h" |
|||
|
|||
int sub(int a, int b) { |
|||
return a - --b; /* bug */ |
|||
} |
@ -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/<arch>) |
|||
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) |
|||
|
@ -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=$<TARGET_FILE:libs> |
|||
# C-SPY driver options |
|||
--backend |
|||
--cpu=cortex-m4 |
|||
--semihosting) |
|||
|
|||
set_tests_properties(libs-test PROPERTIES PASS_REGULAR_EXPRESSION "2843410253") |
@ -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() |
@ -0,0 +1,8 @@ |
|||
#ifndef _FAST_CRC32_H_ |
|||
#define _FAST_CRC32_H_ |
|||
|
|||
#include <stdint.h> |
|||
|
|||
uint32_t Fast_CRC32(uint32_t crc, uint32_t const* data, uint32_t words); |
|||
|
|||
#endif /* _FAST_CRC32_H_ */ |
@ -0,0 +1,33 @@ |
|||
#include <stdint.h> |
|||
|
|||
#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; |
|||
} |
@ -0,0 +1,10 @@ |
|||
#include <stdio.h> |
|||
|
|||
#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)); |
|||
} |
@ -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=$<TARGET_FILE:mix> |
|||
# C-SPY driver options |
|||
--backend |
|||
--cpu=cortex-m4 |
|||
--semihosting) |
|||
|
|||
set_tests_properties(mix-test PROPERTIES PASS_REGULAR_EXPRESSION "42") |
@ -0,0 +1,4 @@ |
|||
#ifndef FUN_H |
|||
#define FUN_H |
|||
extern int fun(); |
|||
#endif |
@ -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 |
@ -0,0 +1,7 @@ |
|||
#include <stdio.h> |
|||
|
|||
#include "fun.h" |
|||
|
|||
void main() { |
|||
printf("%d\n", fun()); |
|||
} |
@ -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=$<TARGET_FILE:${TARGET}> |
|||
# 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 $<IF:$<BOOL:$<TARGET_PROPERTY:${TARGET},DDF>>,$<TARGET_PROPERTY:${TARGET},DDF>,${TOOLKIT_DIR}/config/debugger/ior7f701401.ddf> |
|||
--core=$<IF:$<BOOL:$<TARGET_PROPERTY:${TARGET},CPU>>,$<TARGET_PROPERTY:${TARGET},CPU>,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() |
@ -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 $<TARGET_FILE:${TARGET}> $<IF:$<BOOL:$<TARGET_PROPERTY:${TARGET},OUTPUT_NAME>>,$<TARGET_PROPERTY:${TARGET},OUTPUT_NAME>,$<TARGET_PROPERTY:${TARGET},NAME>>.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 $<TARGET_FILE:${TARGET}> $<IF:$<BOOL:$<TARGET_PROPERTY:${TARGET},OUTPUT_NAME>>,$<TARGET_PROPERTY:${TARGET},OUTPUT_NAME>,$<TARGET_PROPERTY:${TARGET},NAME>>.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 $<TARGET_FILE:${TARGET}> $<IF:$<BOOL:$<TARGET_PROPERTY:${TARGET},OUTPUT_NAME>>,$<TARGET_PROPERTY:${TARGET},OUTPUT_NAME>,$<TARGET_PROPERTY:${TARGET},NAME>>.bin) |
|||
endfunction() |
@ -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 |
|||
$<$<COMPILE_LANGUAGE:C>:--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 |
|||
$<$<CONFIG:Debug>:--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) |
@ -1,23 +0,0 @@ |
|||
#include <stdio.h> |
|||
#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; |
|||
} |
@ -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(); |
|||
} |
|||
} |
@ -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 |
@ -1,4 +0,0 @@ |
|||
#ifndef MYNUM_H |
|||
#define MYNUM_H |
|||
extern int mynum(); |
|||
#endif |
@ -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) |
@ -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 |
|||
$<$<COMPILE_LANGUAGE:C,CXX>:--lock_global_pointer_regs=0 --dlib_config ${TOOLKIT_DIR}/lib/DLib_Config_Normal.h> |
|||
--core $<TARGET_PROPERTY:CPU> --fpu=double --double=64 --data_model medium ) |
|||
|
|||
# Set the link options for the target |
|||
target_link_options(myProgram PRIVATE |
|||
$<$<CONFIG:Debug>:--debug_lib --redirect ___write=___write_buffered> |
|||
# Create a map file from the target's ELF |
|||
--map $<TARGET_PROPERTY:NAME>.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 $<TARGET_PROPERTY:ICF> ) |
|||
|
|||
# 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) |
@ -1,29 +0,0 @@ |
|||
#ifndef NDEBUG |
|||
#include <stdio.h> |
|||
#endif |
|||
#include <stdlib.h> |
|||
#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; |
|||
} |
|||
|
@ -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(); |
|||
} |
|||
} |
|||
|
@ -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 |
|||
$<$<COMPILE_LANGUAGE:C>:--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 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/.> ) |
@ -1,5 +0,0 @@ |
|||
#include "myMath.h" |
|||
|
|||
int add(int a, int b) { |
|||
return a + b; |
|||
} |
@ -1,5 +0,0 @@ |
|||
#include "myMath.h" |
|||
|
|||
int mul(int a, int b) { |
|||
return a * b; |
|||
} |
@ -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 |
@ -1,5 +0,0 @@ |
|||
#include "myMath.h" |
|||
|
|||
int sub(int a, int b) { |
|||
return a - --b; /* bug */ |
|||
} |
@ -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=$<TARGET_FILE:${TARGET}> |
|||
# 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 $<IF:$<BOOL:$<TARGET_PROPERTY:${TARGET},DDF>>,$<TARGET_PROPERTY:${TARGET},DDF>,${TOOLKIT_DIR}/config/debugger/ioriscv.ddf> |
|||
--core=$<IF:$<BOOL:$<TARGET_PROPERTY:${TARGET},CPU>>,$<TARGET_PROPERTY:${TARGET},CPU>,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() |
@ -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 $<TARGET_FILE:${TARGET}> $<IF:$<BOOL:$<TARGET_PROPERTY:${TARGET},OUTPUT_NAME>>,$<TARGET_PROPERTY:${TARGET},OUTPUT_NAME>,$<TARGET_PROPERTY:${TARGET},NAME>>.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 $<TARGET_FILE:${TARGET}> $<IF:$<BOOL:$<TARGET_PROPERTY:${TARGET},OUTPUT_NAME>>,$<TARGET_PROPERTY:${TARGET},OUTPUT_NAME>,$<TARGET_PROPERTY:${TARGET},NAME>>.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 $<TARGET_FILE:${TARGET}> $<IF:$<BOOL:$<TARGET_PROPERTY:${TARGET},OUTPUT_NAME>>,$<TARGET_PROPERTY:${TARGET},OUTPUT_NAME>,$<TARGET_PROPERTY:${TARGET},NAME>>.bin) |
|||
endfunction() |
@ -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 |
|||
$<$<COMPILE_LANGUAGE:C>:--dlib_config normal> |
|||
--core=RV32IMAFDC ) |
|||
|
|||
# Set the link options for the target |
|||
target_link_options(mixLanguages PRIVATE |
|||
$<$<CONFIG:Debug>:--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) |
@ -1,23 +0,0 @@ |
|||
#include <stdio.h> |
|||
#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; |
|||
} |
@ -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(); |
|||
} |
|||
} |
@ -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 |
@ -1,4 +0,0 @@ |
|||
#ifndef MYNUM_H |
|||
#define MYNUM_H |
|||
extern int mynum(); |
|||
#endif |
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue