Skip to content

Commit 964591e

Browse files
Implemented new build system with CMake
1 parent 463dd1c commit 964591e

29 files changed

Lines changed: 1878 additions & 19 deletions

File tree

.gitignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@ image.uf2
1515
*.d
1616

1717
# Exclude build directories and host executables
18-
miosix/_tools/filesystems/build
1918
miosix/_tools/filesystems/buildromfs
20-
miosix/_tools/bin2uf2/build
2119
miosix/_tools/bin2uf2/bin2uf2
2220

21+
# Exclude all build directories
22+
build
23+
2324
# Exclude Mac OS X temporary
2425
._*
2526
.DS_Store

CMakeLists.txt

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Copyright (C) 2024 by Skyward
2+
#
3+
# This program is free software; you can redistribute it and/or
4+
# it under the terms of the GNU General Public License as published
5+
# the Free Software Foundation; either version 2 of the License, or
6+
# (at your option) any later version.
7+
#
8+
# This program is distributed in the hope that it will be useful,
9+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
# GNU General Public License for more details.
12+
#
13+
# As a special exception, if other files instantiate templates or use
14+
# macros or inline functions from this file, or you compile this file
15+
# and link it with other works to produce a work based on this file,
16+
# this file does not by itself cause the resulting work to be covered
17+
# by the GNU General Public License. However the source code for this
18+
# file must still be made available in accordance with the GNU
19+
# Public License. This exception does not invalidate any other
20+
# why a work based on this file might be covered by the GNU General
21+
# Public License.
22+
#
23+
# You should have received a copy of the GNU General Public License
24+
# along with this program; if not, see <http://www.gnu.org/licenses/>
25+
26+
cmake_minimum_required(VERSION 3.16)
27+
28+
project(Main C CXX ASM)
29+
30+
# Set here your board of choice
31+
set(MIOSIX_OPT_BOARD NOT_SET CACHE STRING "Target board")
32+
33+
add_subdirectory(miosix EXCLUDE_FROM_ALL)
34+
include(LinkTarget)
35+
36+
# List here your source files (.s, .c and .cpp)
37+
add_executable(main main.cpp)
38+
miosix_link_target(main)
39+
40+
# List here additional include directories
41+
# target_include_directories(main PRIVATE here_your_includes)
42+
43+
# List here additional static libraries
44+
# target_link_libraries(main PRIVATE here_your_libraries)

miosix/CMakeLists.txt

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
# Copyright (C) 2024 by Skyward
2+
#
3+
# This program is free software; you can redistribute it and/or
4+
# it under the terms of the GNU General Public License as published
5+
# the Free Software Foundation; either version 2 of the License, or
6+
# (at your option) any later version.
7+
#
8+
# This program is distributed in the hope that it will be useful,
9+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
# GNU General Public License for more details.
12+
#
13+
# As a special exception, if other files instantiate templates or use
14+
# macros or inline functions from this file, or you compile this file
15+
# and link it with other works to produce a work based on this file,
16+
# this file does not by itself cause the resulting work to be covered
17+
# by the GNU General Public License. However the source code for this
18+
# file must still be made available in accordance with the GNU
19+
# Public License. This exception does not invalidate any other
20+
# why a work based on this file might be covered by the GNU General
21+
# Public License.
22+
#
23+
# You should have received a copy of the GNU General Public License
24+
# along with this program; if not, see <http://www.gnu.org/licenses/>
25+
26+
cmake_minimum_required(VERSION 3.16)
27+
28+
project(Miosix
29+
VERSION 2.7
30+
DESCRIPTION "OS kernel designed to run on 32bit microcontrollers."
31+
HOMEPAGE_URL "https://miosix.org"
32+
LANGUAGES C CXX
33+
)
34+
35+
set(MIOSIX_KPATH ${CMAKE_CURRENT_LIST_DIR} CACHE PATH "Path to the miosix kernel")
36+
37+
set(MIOSIX_KERNEL_SRC
38+
${MIOSIX_KPATH}/kernel/kernel.cpp
39+
${MIOSIX_KPATH}/kernel/sync.cpp
40+
${MIOSIX_KPATH}/kernel/error.cpp
41+
${MIOSIX_KPATH}/kernel/pthread.cpp
42+
${MIOSIX_KPATH}/kernel/boot.cpp
43+
${MIOSIX_KPATH}/kernel/elf_program.cpp
44+
${MIOSIX_KPATH}/kernel/process.cpp
45+
${MIOSIX_KPATH}/kernel/process_pool.cpp
46+
${MIOSIX_KPATH}/kernel/timeconversion.cpp
47+
${MIOSIX_KPATH}/kernel/intrusive.cpp
48+
${MIOSIX_KPATH}/kernel/cpu_time_counter.cpp
49+
${MIOSIX_KPATH}/kernel/scheduler/priority/priority_scheduler.cpp
50+
${MIOSIX_KPATH}/kernel/scheduler/control/control_scheduler.cpp
51+
${MIOSIX_KPATH}/kernel/scheduler/edf/edf_scheduler.cpp
52+
${MIOSIX_KPATH}/filesystem/file_access.cpp
53+
${MIOSIX_KPATH}/filesystem/file.cpp
54+
${MIOSIX_KPATH}/filesystem/path.cpp
55+
${MIOSIX_KPATH}/filesystem/stringpart.cpp
56+
${MIOSIX_KPATH}/filesystem/pipe/pipe.cpp
57+
${MIOSIX_KPATH}/filesystem/console/console_device.cpp
58+
${MIOSIX_KPATH}/filesystem/mountpointfs/mountpointfs.cpp
59+
${MIOSIX_KPATH}/filesystem/devfs/devfs.cpp
60+
${MIOSIX_KPATH}/filesystem/fat32/fat32.cpp
61+
${MIOSIX_KPATH}/filesystem/fat32/ff.cpp
62+
${MIOSIX_KPATH}/filesystem/fat32/diskio.cpp
63+
${MIOSIX_KPATH}/filesystem/fat32/wtoupper.cpp
64+
${MIOSIX_KPATH}/filesystem/fat32/ccsbcs.cpp
65+
${MIOSIX_KPATH}/filesystem/littlefs/lfs_miosix.cpp
66+
${MIOSIX_KPATH}/filesystem/littlefs/lfs.c
67+
${MIOSIX_KPATH}/filesystem/littlefs/lfs_util.c
68+
${MIOSIX_KPATH}/filesystem/romfs/romfs.cpp
69+
${MIOSIX_KPATH}/stdlib_integration/libc_integration.cpp
70+
${MIOSIX_KPATH}/stdlib_integration/libstdcpp_integration.cpp
71+
${MIOSIX_KPATH}/e20/e20.cpp
72+
${MIOSIX_KPATH}/e20/unmember.cpp
73+
${MIOSIX_KPATH}/util/util.cpp
74+
${MIOSIX_KPATH}/util/unicode.cpp
75+
${MIOSIX_KPATH}/util/version.cpp
76+
${MIOSIX_KPATH}/util/crc16.cpp
77+
${MIOSIX_KPATH}/util/lcd44780.cpp
78+
)
79+
80+
# Include the architecture options
81+
include(${MIOSIX_KPATH}/arch/CMakeLists.txt)
82+
83+
# Verify that all the required variables have been defined, otherwise abort
84+
set(REQUIRED_VARIABLES
85+
MIOSIX_OPT_BOARD
86+
MIOSIX_ARCH_INC
87+
MIOSIX_BOARD_INC
88+
MIOSIX_BOARD_SETTINGS_INC
89+
MIOSIX_LINKER_SCRIPT
90+
MIOSIX_A_FLAGS
91+
MIOSIX_C_FLAGS
92+
MIOSIX_CXX_FLAGS
93+
MIOSIX_L_FLAGS
94+
MIOSIX_ARCH_SRC
95+
)
96+
foreach(VARIABLE ${REQUIRED_VARIABLES})
97+
if(NOT DEFINED ${VARIABLE})
98+
message(FATAL_ERROR "arch/CMakeLists.txt must define ${VARIABLE}")
99+
endif()
100+
endforeach()
101+
102+
# The user can set a custom path for miosix_settings.h
103+
set(MIOSIX_SETTINGS_PATH ${MIOSIX_KPATH}/default CACHE PATH "Include directory for miosix_settings.h")
104+
mark_as_advanced(MIOSIX_SETTINGS_PATH)
105+
if(NOT MIOSIX_SETTINGS_PATH STREQUAL ${MIOSIX_KPATH}/default)
106+
message(NOTICE "You have set a custom path for miosix_settings.h")
107+
endif()
108+
109+
# Define the miosix library with kernel and architecture sources
110+
add_library(miosix STATIC ${MIOSIX_KERNEL_SRC} ${MIOSIX_ARCH_SRC})
111+
112+
target_include_directories(miosix PUBLIC
113+
${MIOSIX_KPATH}
114+
${MIOSIX_KPATH}/arch/common
115+
${MIOSIX_ARCH_INC}
116+
${MIOSIX_BOARD_INC}
117+
${MIOSIX_BOARD_SETTINGS_INC}
118+
${MIOSIX_SETTINGS_PATH}
119+
)
120+
121+
target_compile_options(miosix PUBLIC
122+
$<$<COMPILE_LANGUAGE:ASM>:${MIOSIX_A_FLAGS}>
123+
$<$<COMPILE_LANGUAGE:C>:${MIOSIX_C_FLAGS}>
124+
$<$<COMPILE_LANGUAGE:CXX>:${MIOSIX_CXX_FLAGS}>
125+
)
126+
127+
# Configure program command as a propery of the miosix library
128+
set_property(TARGET miosix PROPERTY PROGRAM_CMDLINE ${PROGRAM_CMDLINE})
129+
130+
# Add COMPILING_MIOSIX define for private headers
131+
target_compile_definitions(miosix PRIVATE $<$<COMPILE_LANGUAGE:C,CXX>:COMPILING_MIOSIX>)
132+
133+
# Configure linker file and options needed to link agains this library
134+
set_property(TARGET miosix PROPERTY LINK_DEPENDS ${MIOSIX_BOARD_INC}/${MIOSIX_LINKER_SCRIPT})
135+
target_link_options(miosix INTERFACE ${MIOSIX_L_FLAGS})
136+
137+
# Run the kernel_global_objects.pl script on all kernel objects
138+
add_custom_command(
139+
TARGET miosix PRE_LINK
140+
COMMAND perl ${MIOSIX_KPATH}/_tools/kernel_global_objects.pl $<TARGET_OBJECTS:miosix>
141+
VERBATIM
142+
COMMAND_EXPAND_LISTS
143+
)
144+
145+
# Optionally print the board list
146+
option(MIOSIX_PRINT_BOARD_LIST "Prints a list of the available boards" OFF)
147+
if(MIOSIX_PRINT_BOARD_LIST)
148+
message(STATUS "Available boards:")
149+
foreach(MIOSIX_OPT_BOARD ${MIOSIX_BOARDS})
150+
message(STATUS "\t${MIOSIX_OPT_BOARD}")
151+
endforeach()
152+
endif()
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Copyright (C) 2024 by Skyward
2+
#
3+
# This program is free software; you can redistribute it and/or
4+
# it under the terms of the GNU General Public License as published
5+
# the Free Software Foundation; either version 2 of the License, or
6+
# (at your option) any later version.
7+
#
8+
# This program is distributed in the hope that it will be useful,
9+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
# GNU General Public License for more details.
12+
#
13+
# As a special exception, if other files instantiate templates or use
14+
# macros or inline functions from this file, or you compile this file
15+
# and link it with other works to produce a work based on this file,
16+
# this file does not by itself cause the resulting work to be covered
17+
# by the GNU General Public License. However the source code for this
18+
# file must still be made available in accordance with the GNU
19+
# Public License. This exception does not invalidate any other
20+
# why a work based on this file might be covered by the GNU General
21+
# Public License.
22+
#
23+
# You should have received a copy of the GNU General Public License
24+
# along with this program; if not, see <http://www.gnu.org/licenses/>
25+
26+
cmake_minimum_required(VERSION 3.16)
27+
28+
project(BlinkingLED C CXX ASM)
29+
30+
# Set Miosix definitions and options
31+
add_compile_definitions($<$<COMPILE_LANGUAGE:C,CXX>:MIOSIX_SKIP_SETTINGS_EDIT>)
32+
set(MIOSIX_OPT_BOARD stm32f429zi_stm32f4discovery CACHE STRING "Target board")
33+
34+
add_subdirectory(../.. miosix EXCLUDE_FROM_ALL)
35+
36+
include(LinkTarget)
37+
38+
add_executable(blinking_led simple.cpp)
39+
miosix_link_target(blinking_led)
Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
11
#include <cstdio>
2-
#include <unistd.h>
2+
3+
#include "interfaces/bsp.h"
34
#include "miosix.h"
45

5-
using namespace std;
66
using namespace miosix;
77

8-
typedef Gpio<GPIOC_BASE,7> led;
9-
108
int main()
119
{
12-
13-
led::mode(Mode::OUTPUT);
14-
15-
for(;;) {
16-
led::high();
17-
sleep(1);
18-
led::low();
19-
sleep(1);
20-
}
21-
22-
return 0;
23-
24-
}
10+
while(true)
11+
{
12+
ledOn();
13+
printf("Led on\n");
14+
sleep(1);
15+
16+
ledOff();
17+
printf("Led off\n");
18+
sleep(1);
19+
}
20+
21+
return 0;
22+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Copyright (C) 2024 by Skyward
2+
#
3+
# This program is free software; you can redistribute it and/or
4+
# it under the terms of the GNU General Public License as published
5+
# the Free Software Foundation; either version 2 of the License, or
6+
# (at your option) any later version.
7+
#
8+
# This program is distributed in the hope that it will be useful,
9+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
# GNU General Public License for more details.
12+
#
13+
# As a special exception, if other files instantiate templates or use
14+
# macros or inline functions from this file, or you compile this file
15+
# and link it with other works to produce a work based on this file,
16+
# this file does not by itself cause the resulting work to be covered
17+
# by the GNU General Public License. However the source code for this
18+
# file must still be made available in accordance with the GNU
19+
# Public License. This exception does not invalidate any other
20+
# why a work based on this file might be covered by the GNU General
21+
# Public License.
22+
#
23+
# You should have received a copy of the GNU General Public License
24+
# along with this program; if not, see <http://www.gnu.org/licenses/>
25+
26+
cmake_minimum_required(VERSION 3.16)
27+
28+
project(ProcessesExamples C CXX ASM)
29+
30+
# Set Miosix definitions and options
31+
add_compile_definitions($<$<COMPILE_LANGUAGE:C,CXX>:PARSING_FROM_IDE>)
32+
add_compile_definitions($<$<COMPILE_LANGUAGE:C,CXX>:WITH_PROCESSES>)
33+
set(MIOSIX_OPT_BOARD stm32f429zi_stm32f4discovery CACHE STRING "Target board")
34+
set(MIOSIX_LINKER_SCRIPT stm32_2m+256k_rom_processes.ld CACHE FILEPATH "Linker script")
35+
36+
add_subdirectory(../.. miosix EXCLUDE_FROM_ALL)
37+
add_subdirectory(../../libsyscalls libsyscalls EXCLUDE_FROM_ALL)
38+
39+
include(LinkTarget)
40+
include(AddProcess)
41+
include(AddRomfsImage)
42+
43+
# Kernel level program
44+
add_executable(main main.cpp)
45+
miosix_link_target(main)
46+
47+
# Processes
48+
miosix_add_process(process1 process1.cpp)
49+
miosix_add_process(process2 process2.cpp)
50+
51+
# RomFS image
52+
miosix_add_romfs_image(
53+
IMAGE_NAME image
54+
DIR_NAME bin
55+
KERNEL main
56+
PROCESSES process1 process2
57+
)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include <spawn.h>
2+
#include <sys/wait.h>
3+
4+
#include <cstdio>
5+
6+
int main()
7+
{
8+
pid_t pid1, pid2;
9+
10+
// Arguments and environment variables
11+
const char *arg1[] = {"/bin/process1", nullptr};
12+
const char *arg2[] = {"/bin/process2", nullptr};
13+
const char *env[] = {nullptr};
14+
15+
// Start the processes
16+
posix_spawn(&pid1, arg1[0], NULL, NULL, (char *const *)arg1,
17+
(char *const *)env);
18+
posix_spawn(&pid2, arg2[0], NULL, NULL, (char *const *)arg2,
19+
(char *const *)env);
20+
21+
// Wait for them to end
22+
wait(NULL);
23+
wait(NULL);
24+
25+
printf("All processes ended\n");
26+
27+
return 0;
28+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include <cstdio>
2+
#include <ctime>
3+
4+
int main()
5+
{
6+
printf("Hi! I'm the process #1\n");
7+
8+
printf("I'll count to 10\n");
9+
const timespec sleep_time{.tv_sec = 1, .tv_nsec = 0};
10+
for (int i = 1; i <= 10; i++)
11+
{
12+
nanosleep(&sleep_time, NULL);
13+
printf("%d\n", i);
14+
}
15+
16+
return 0;
17+
}

0 commit comments

Comments
 (0)