Skip to content

Commit ad83f64

Browse files
committed
Updated klib to latest version
1 parent 663ac0c commit ad83f64

4 files changed

Lines changed: 124 additions & 13 deletions

File tree

.vscode/c_cpp_properties.json

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"configurations": [
3+
{
4+
"name": "gcc-arm",
5+
"includePath": [
6+
"${workspaceFolder}",
7+
"${workspaceFolder}/../targets/arm",
8+
"${workspaceFolder}/../klib",
9+
"${workspaceFolder}/../targets/chip/${config:target_cpu}"
10+
],
11+
"defines": [
12+
"TARGET_CPU=${config:target_cpu}",
13+
"KLIB_IRQ=irq_ram",
14+
"KLIB_DEFAULT_COUT=rtt"
15+
],
16+
// "compilerPath": "path",
17+
"cStandard": "c17",
18+
"cppStandard": "c++23",
19+
"configurationProvider": "ms-vscode.cmake-tools",
20+
"intelliSenseMode": "gcc-arm",
21+
"compilerArgs": [
22+
"-nostdlib",
23+
"-nodefaultlibs",
24+
"-nostartfiles"
25+
]
26+
}
27+
],
28+
"version": 4
29+
}

.vscode/launch.json

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": "Upload Core #0",
9+
"cwd": "${workspaceFolder}",
10+
"executable": "${workspaceFolder}/build/klib.elf",
11+
"device": "${config:target_cpu_debug}",
12+
"interface": "swd",
13+
"request": "launch",
14+
"type": "cortex-debug",
15+
"runToEntryPoint": "main",
16+
"servertype": "jlink",
17+
"numberOfProcessors": 1,
18+
"targetProcessor": 0,
19+
"rttConfig": {
20+
"enabled": true,
21+
"address": "auto",
22+
"decoders": [
23+
{
24+
"label": "",
25+
"port": 0,
26+
"type": "console"
27+
}
28+
]
29+
},
30+
"svdFile": "${workspaceFolder}/../klib_other/klib-svd/${config:target_cpu}.svd"
31+
// "chainedConfigurations": {
32+
// "enabled": true,
33+
// "waitOnEvent": "postInit",
34+
// "lifeCycleShared": true,
35+
// "launches": [
36+
// {
37+
// "name": "Attach Core #1",
38+
// "folder": "",
39+
// "delayMs": 300
40+
// }
41+
// ],
42+
// }
43+
},
44+
],
45+
}

.vscode/settings.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
// target cpu, should be the same as in the defined
3+
// this can be used in the c_cpp_properties.json for
4+
// intellisense
5+
"target_cpu": "lpc1756",
6+
7+
// target cpu to use when using launch.json
8+
"target_cpu_debug": "lpc1756",
9+
"cmake.configureSettings": {
10+
"TARGET_CPU": "lpc1756",
11+
"TARGET_LOW_POWER_SLEEP": "1",
12+
"TARGET_BREAK_AT_RESERVED_HANDLER": "1"
13+
},
14+
"C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools",
15+
16+
"cortex-debug.variableUseNaturalFormat": false,
17+
"C_Cpp.default.browse.limitSymbolsToIncludedHeaders": true,
18+
"C_Cpp.default.intelliSenseMode": "gcc-arm"
19+
}

CMakeLists.txt

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,35 @@
1+
# The Generic system name is used for embedded targets (targets without OS) in
2+
# CMake
3+
set(CMAKE_SYSTEM_NAME Generic)
4+
set(CMAKE_SYSTEM_PROCESSOR ARM)
5+
6+
# Supress Error when trying to test the compiler
7+
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
8+
set(BUILD_SHARED_LIBS OFF)
9+
10+
# set minimum version of CMake.
11+
cmake_minimum_required(VERSION 3.22)
12+
13+
# set project name and version
14+
project(klib VERSION 0.0.1)
15+
16+
# provide the klib directory for the project (repo root, one level up)
17+
set(KLIB_DIR ${CMAKE_CURRENT_LIST_DIR}/..)
18+
19+
# include klib and all common toolchain + target setup from the klib repo root.
20+
# This configures the build-type flags, includes the target cpu (creating the
21+
# target_cpu / target_cpu_options targets), defines the add_linkerscript()
22+
# helper and builds the klib library target.
23+
# Note: KLIB_DIR needs to point to your klib installation folder.
24+
include(${KLIB_DIR}/CMakeLists.txt)
25+
126
# set the sources
2-
set(SOURCES
27+
set(SOURCES
328
${CMAKE_CURRENT_SOURCE_DIR}/main.cpp
429
${CMAKE_CURRENT_SOURCE_DIR}/button.cpp
530

631
# example for including the startup.cpp
7-
${CMAKE_SOURCE_DIR}/targets/chip/${TARGET_CPU}/startup.cpp
32+
${KLIB_DIR}/targets/chip/${TARGET_CPU}/startup.cpp
833
)
934

1035
set(HEADERS)
@@ -14,12 +39,6 @@ add_executable(klib_project
1439
${SOURCES} ${HEADERS}
1540
)
1641

17-
# enable LTO
18-
target_compile_options(klib PUBLIC "-flto")
19-
target_compile_options(klib PUBLIC "-fuse-linker-plugin")
20-
target_link_options(klib PUBLIC "-flto")
21-
target_link_options(klib PUBLIC "-fuse-linker-plugin")
22-
2342
# set the output filename
2443
set_target_properties(klib_project PROPERTIES OUTPUT_NAME "klib" SUFFIX ".elf")
2544

@@ -33,7 +52,7 @@ target_compile_definitions(klib PUBLIC "KLIB_DEFAULT_COUT=rtt")
3352
target_compile_definitions(klib PUBLIC "KLIB_DEFAULT_CIN=rtt")
3453

3554
# override the rtt buffer size (not required and not used when no segger rtt is used)
36-
target_compile_definitions(klib PUBLIC "BUFFER_SIZE_UP=512")
55+
target_compile_definitions(klib PUBLIC "BUFFER_SIZE_UP=256")
3756
target_compile_definitions(klib PUBLIC "BUFFER_SIZE_DOWN=16")
3857

3958
# set if we should support certain callbacks
@@ -49,13 +68,12 @@ target_link_libraries(klib_project PUBLIC m)
4968
set(TARGET_LINKERSCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/linkerscript.ld)
5069

5170
# link to the linkerscript of the target cpu
52-
target_link_options(klib_project PUBLIC "-T${TARGET_LINKERSCRIPT}")
53-
set_target_properties(klib_project PROPERTIES LINK_DEPENDS ${TARGET_LINKERSCRIPT})
71+
add_linkerscript(klib_project ${TARGET_LINKERSCRIPT} "")
5472

5573
# add the project directory to the include directories
56-
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
74+
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
5775

58-
# Custom commands for processing the build binary and show some statistics and debug info
76+
# Custom commands for processing the build binary and show some statistics and debug info
5977
add_custom_command(TARGET klib_project DEPENDS ${CMAKE_BINARY_DIR}/klib.elf POST_BUILD COMMAND arm-none-eabi-objcopy ARGS -O binary -R .bss -R .stack klib.elf klib.bin)
6078
add_custom_command(TARGET klib_project DEPENDS ${CMAKE_BINARY_DIR}/klib.elf POST_BUILD COMMAND arm-none-eabi-objcopy ARGS -O ihex -R .bss -R .stack klib.elf klib.hex)
6179
add_custom_command(TARGET klib_project DEPENDS ${CMAKE_BINARY_DIR}/klib.elf POST_BUILD COMMAND arm-none-eabi-objdump ARGS -C -S klib.elf > klib.lss)

0 commit comments

Comments
 (0)