<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://miosix.org/wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Fede.tft</id>
	<title>Miosix Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://miosix.org/wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Fede.tft"/>
	<link rel="alternate" type="text/html" href="https://miosix.org/wiki/index.php?title=Special:Contributions/Fede.tft"/>
	<updated>2026-05-17T09:12:33Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.43.3</generator>
	<entry>
		<id>https://miosix.org/wiki/index.php?title=Miosix_processes&amp;diff=493</id>
		<title>Miosix processes</title>
		<link rel="alternate" type="text/html" href="https://miosix.org/wiki/index.php?title=Miosix_processes&amp;diff=493"/>
		<updated>2026-05-17T07:33:18Z</updated>

		<summary type="html">&lt;p&gt;Fede.tft: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;TODO: this part needs better documenting.&lt;br /&gt;
&lt;br /&gt;
A complete example for running processes can be found in [https://github.com/fedetft/miosix-kernel/tree/master/templates/processes templates/processes].&lt;br /&gt;
&lt;br /&gt;
To compile it, you have to change the default linker script for your board so that the size of the [[Process pool|process pool]], the memory allocator for processes is greater than zero. This needs to be done in the &#039;&#039;config/board&#039;&#039; directory for your board. For example, for an RP2040 the file is [https://github.com/fedetft/miosix-kernel/blob/master/miosix/config/board/rp2040_raspberry_pi_pico/Makefile.inc config/board/rp2040_raspberry_pi_pico/Makefile.inc].&lt;br /&gt;
&lt;br /&gt;
The linker script is usually simply called processes, and needs to be uncommented while also commenting the default linker script:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=bash&amp;gt;&lt;br /&gt;
## Select linker script&lt;br /&gt;
#LINKER_SCRIPT := unikernel.ld&lt;br /&gt;
LINKER_SCRIPT := processes.ld&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
TODO: explain how the Makefile for the kernel and the one for processes works, and the use of the &#039;&#039;-qkernelspace&#039;&#039; GCC option that has been added by the GCC patches as part of the [[Miosix Toolchain]] to change the code generation and linking stage to either build a position independent code program where the libc links with the libsyscalls (processes), or a non-position-independent code program where kercalls remain undefined references to be resolved at the link stage when linking with the kernel&#039;s libmiosix.a. Also explain the need for the postlinking stage (&#039;&#039;mx-postlinker&#039;&#039; tool) to specify the size of the RAM memory region of programs, as well as the stack size.&lt;/div&gt;</summary>
		<author><name>Fede.tft</name></author>
	</entry>
	<entry>
		<id>https://miosix.org/wiki/index.php?title=Miosix_processes&amp;diff=492</id>
		<title>Miosix processes</title>
		<link rel="alternate" type="text/html" href="https://miosix.org/wiki/index.php?title=Miosix_processes&amp;diff=492"/>
		<updated>2026-05-17T07:32:36Z</updated>

		<summary type="html">&lt;p&gt;Fede.tft: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;TODO: this part needs better documenting.&lt;br /&gt;
&lt;br /&gt;
A complete example for running processes can be found in [https://github.com/fedetft/miosix-kernel/tree/master/templates/processes templates/processes].&lt;br /&gt;
&lt;br /&gt;
To compile it, you have to change the default linker script for your board so that the size of the [[Process pool|process pool]], the memory allocator for processes is greater than zero. This needs to be done in the &#039;&#039;config/board&#039;&#039; directory for your board. For example, for an RP2040 the file is [https://github.com/fedetft/miosix-kernel/blob/master/miosix/config/board/rp2040_raspberry_pi_pico/Makefile.inc config/board/rp2040_raspberry_pi_pico/Makefile.inc].&lt;br /&gt;
&lt;br /&gt;
The linker script is usually simply called processes, and needs to be uncommented while also commenting the default linker script:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=bash&amp;gt;&lt;br /&gt;
## Select linker script&lt;br /&gt;
#LINKER_SCRIPT := unikernel.ld&lt;br /&gt;
LINKER_SCRIPT := processes.ld&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
TODO: explain how the Makefile for the kernel and the one for processes works, and the use of the &#039;&#039;-qkernelspace&#039;&#039; GCC option that has been added by the GCC patches as part of the [[Miosix toolchain]] to change the code generation and linking stage to either build a position independent code program where the libc links with the libsyscalls (processes), or a non-position-independent code program where kercalls remain undefined references to be resolved at the link stage when linking with the kernel&#039;s libmiosix.a. Also explain the need for the postlinking stage (&#039;&#039;mx-postlinker&#039;&#039; tool) to specify the size of the RAM memory region of programs, as well as the stack size.&lt;/div&gt;</summary>
		<author><name>Fede.tft</name></author>
	</entry>
	<entry>
		<id>https://miosix.org/wiki/index.php?title=Fluid_kernel&amp;diff=491</id>
		<title>Fluid kernel</title>
		<link rel="alternate" type="text/html" href="https://miosix.org/wiki/index.php?title=Fluid_kernel&amp;diff=491"/>
		<updated>2026-05-17T07:32:02Z</updated>

		<summary type="html">&lt;p&gt;Fede.tft: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;TODO: the fluid kernel architecture needs to be documented in the wiki.&lt;br /&gt;
In the meantime, you can read [https://ieeexplore.ieee.org/document/11173649 the paper].&lt;br /&gt;
&lt;br /&gt;
For a tutorial on [[Miosix processes]] read here.&lt;/div&gt;</summary>
		<author><name>Fede.tft</name></author>
	</entry>
	<entry>
		<id>https://miosix.org/wiki/index.php?title=Main_Page&amp;diff=490</id>
		<title>Main Page</title>
		<link rel="alternate" type="text/html" href="https://miosix.org/wiki/index.php?title=Main_Page&amp;diff=490"/>
		<updated>2026-05-17T07:31:16Z</updated>

		<summary type="html">&lt;p&gt;Fede.tft: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The Miosix wiki contains useful information for using the Miosix kernel.&lt;br /&gt;
&lt;br /&gt;
= Getting started =&lt;br /&gt;
This section will guide you from zero to compiling an hello world using Miosix.&lt;br /&gt;
&lt;br /&gt;
* [[Linux Quick Start|Getting Started on Linux]].&lt;br /&gt;
* [[Windows Quick Start|Getting Started on Windows]].&lt;br /&gt;
* [[MacOS Quick Start|Getting Started on MacOS]].&lt;br /&gt;
&lt;br /&gt;
= Software =&lt;br /&gt;
* See [[Miosix and git workflow]] to understand how to add Miosix as a dependency to your embedded application.&lt;br /&gt;
* Information on [[Debugging]] can be found here.&lt;br /&gt;
* Learn about the [[Fluid kernel|fluid kernel]] architecture and how to create programs that can run inside userspace [[Miosix processes|processes]].&lt;br /&gt;
* Have a look at the Miosix [[API list|APIs]], [[Library list|libraries]] and [[Examples list|examples]] that you can use for your applications.&lt;br /&gt;
* The page on [[Synchronization primitives]] lists the possible ways to shnchronize beween multiple threads or between a thread and an interrupt routine.&lt;br /&gt;
* How to [[Miosix code size optimization|reduce the kernel code size]] for deeply embedded applications.&lt;br /&gt;
* Notes about configuring [[IDEs]] for Miosix.&lt;br /&gt;
&lt;br /&gt;
= Hardware =&lt;br /&gt;
* Check out which microcontroller [[Board list|boards]] are supported by Miosix.&lt;br /&gt;
* Notes about flashing tools for [[Linux flashing tools | Linux]], [[Windows flashing tools | Windows]] and [[MacOS flashing tools | MacOS]].&lt;br /&gt;
* Notes on [[Miosix in emulation]] with QEMU and Renode.&lt;br /&gt;
&lt;br /&gt;
= Account creation =&lt;br /&gt;
Due to spam (within two days from setting up the wiki) account registration is disabled. If you want to create an account, ask to fede.tft&amp;amp;&amp;amp;miosix.org (s/&amp;amp;&amp;amp;/@/)&lt;br /&gt;
&lt;br /&gt;
= Index =&lt;br /&gt;
* [[Special:Categories|Categories]]&lt;br /&gt;
* [[Special:AllPages|All Pages]]&lt;/div&gt;</summary>
		<author><name>Fede.tft</name></author>
	</entry>
	<entry>
		<id>https://miosix.org/wiki/index.php?title=Miosix_processes&amp;diff=489</id>
		<title>Miosix processes</title>
		<link rel="alternate" type="text/html" href="https://miosix.org/wiki/index.php?title=Miosix_processes&amp;diff=489"/>
		<updated>2026-05-17T07:29:37Z</updated>

		<summary type="html">&lt;p&gt;Fede.tft: Created page with &amp;quot;TODO: this part needs better documenting.  A complete example for running processes can be found in [https://github.com/fedetft/miosix-kernel/tree/master/templates/processes templates/processes].  To compile it, you have to change the default linker script for your board so that the size of the process pool, the memory allocator for processes is greater than zero. This needs to be done in the &amp;#039;&amp;#039;config/board&amp;#039;&amp;#039; directory for your board. For example, for an...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;TODO: this part needs better documenting.&lt;br /&gt;
&lt;br /&gt;
A complete example for running processes can be found in [https://github.com/fedetft/miosix-kernel/tree/master/templates/processes templates/processes].&lt;br /&gt;
&lt;br /&gt;
To compile it, you have to change the default linker script for your board so that the size of the [[Process pool|process pool]], the memory allocator for processes is greater than zero. This needs to be done in the &#039;&#039;config/board&#039;&#039; directory for your board. For example, for an RP2040 the file is [https://github.com/fedetft/miosix-kernel/blob/master/miosix/config/board/rp2040_raspberry_pi_pico/Makefile.inc config/board/rp2040_raspberry_pi_pico/Makefile.inc].&lt;br /&gt;
&lt;br /&gt;
The linker script is usually simply called processes, and needs to be uncommented while also commenting the default linker script:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code lang=bash&amp;gt;&lt;br /&gt;
## Select linker script&lt;br /&gt;
#LINKER_SCRIPT := unikernel.ld&lt;br /&gt;
LINKER_SCRIPT := processes.ld&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
TODO: explain how the Makefile for the kernel and the one for processes works, and the use of the &#039;&#039;-qkernelspace&#039;&#039; GCC option that has been added by the GCC patches as part of the [[Miosix toolchain]] to change the code generation and linking stage to either build a position independent code program where the libc links with the libsyscalls (processes), or a non-position-independent code program where kercalls remain undefined references to be resolved at the link stage when linking with the kernel&#039;s libmiosix.a. Also explain the need for the postlinking stage (&#039;&#039;mx-postlinker&#039;&#039; tool) to specify the size of the RAM memory region of programs, as well as the stack size.&lt;/div&gt;</summary>
		<author><name>Fede.tft</name></author>
	</entry>
	<entry>
		<id>https://miosix.org/wiki/index.php?title=Linux_Netbeans_configuration&amp;diff=488</id>
		<title>Linux Netbeans configuration</title>
		<link rel="alternate" type="text/html" href="https://miosix.org/wiki/index.php?title=Linux_Netbeans_configuration&amp;diff=488"/>
		<updated>2026-05-17T07:20:08Z</updated>

		<summary type="html">&lt;p&gt;Fede.tft: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== Installing the IDE ===&lt;br /&gt;
&lt;br /&gt;
Netbeans is an IDE written in Java, and the Java virtual machine is needed to use the IDE. By default most Linux distributions do not come with a jvm pre-installed, so you need to install one.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo apt-get install openjdk-7-jre # Install Java for Ubuntu/Debian&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After that, you can install the Netbeans IDE. In theory, you could install it via apt-get, but in that way you will get the version of the IDE to write Java programs, not C/C++ programs. Even though you can install C/C++ support later, you will end up with an installation that requires far more disk space (up to several hundred megabytes). It is therefore best to download the IDE from the [https://netbeans.org/downloads Netbeans website] and install it manually. The download page will show many options depending on the programming language you are interested in. Among the possible versions choose the C/C++ version, because these are the languages used by Miosix.&lt;br /&gt;
&lt;br /&gt;
The downloaded file has a .sh extension, and a name like &#039;&#039;netbeans-8.0-cpp-linux.sh&#039;&#039;. You can install it by opening a terminal and typing&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo sh netbeans-8.0-cpp-linux.sh&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
a wizard will guide you through the installation.&lt;br /&gt;
&lt;br /&gt;
== Theme configuration ==&lt;br /&gt;
&lt;br /&gt;
If you use Gnome the IDE will use the right theme out of the box, but if you use a different desktop environment, like KDE there is a trick to get the nice theme, which consists in editing the .desktop file for Netbeans, which by default is in &#039;&#039;/usr/share/applications/netbeans-8.0.desktop&#039;&#039; (if you have installed a version of the IDE different from 8.0, the name will change likewise) and change the &#039;&#039;Exec=&#039;&#039; line from&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Exec=/bin/sh &amp;quot;/usr/local/netbeans-8.0/bin/netbeans&amp;quot;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
to the following value which will force the IDE to use the nice Linux theme&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Exec=/usr/local/netbeans-8.0/bin/netbeans --laf com.sun.java.swing.plaf.gtk.GTKLookAndFeel&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To edit the configuration file, which is writable only by root, you can use &#039;&#039;nano&#039;&#039; or &#039;&#039;vi&#039;&#039; from a shell.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo nano /usr/share/applications/netbeans-8.0.desktop&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Configuring the IDE ===&lt;br /&gt;
&lt;br /&gt;
Netbeans is a generic C/C++ IDE, and once installed is not set up by default to develop for ARM microcontrollers and Miosix. So you need to configure it. This is a one-time step that you will have to do again only if you re-install the IDE.&lt;br /&gt;
&lt;br /&gt;
Note: this assumes you have already installed the Miosix toolchain, if not read the [[Linux Quick Start]] tutorial first.&lt;br /&gt;
&lt;br /&gt;
Open the Netbeans IDE and click on &amp;quot;Tools &amp;gt; Options&amp;quot;. From the top of the options window select the C/C++ panel, and click the &amp;quot;Add&amp;quot; button to add a compiler to Netbeans. As &amp;quot;Base directory&amp;quot; choose &amp;quot;/opt/arm-miosix-eabi/arm-miosix-eabi/bin&amp;quot;. Choose &amp;quot;GNU&amp;quot; as &amp;quot;Tool collection family&amp;quot;, and &amp;quot;ARM_MIOSIX_EABI&amp;quot; as &amp;quot;Tool collection name&amp;quot;.&lt;br /&gt;
Note that you &#039;&#039;&#039;must&#039;&#039;&#039; use the &amp;quot;ARM_MIOSIX_EABI&amp;quot; name, or you&#039;ll have problems later.&lt;br /&gt;
The C and C++ compiler should be automatically filled in by Netbeans, if not copy them from the screenshot below.&lt;br /&gt;
&lt;br /&gt;
[[File:Nbsetup1-linux.png]]&lt;br /&gt;
&lt;br /&gt;
Last, you will need to set up the paths with the compiler libraries for code completion to work. Click on the &amp;quot;Code assistance&amp;quot; tab, and &amp;quot;C compiler&amp;quot; sub-tab. The list of folders and macro definitions should look like in this screenshot, if not, add the paths manually.&lt;br /&gt;
&lt;br /&gt;
[[File:Nbsetup2-linux.png]]&lt;br /&gt;
&lt;br /&gt;
Then click th &amp;quot;C++ compiler&amp;quot; sub-tab and check if the paths and macro definitions are correct. If not add the missing paths manually as in the next screenshot.&lt;br /&gt;
&lt;br /&gt;
[[File:Nbsetup3-linux.png]]&lt;br /&gt;
&lt;br /&gt;
Configuration is now complete. You can close the Options windows by clicking &amp;quot;Ok&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Building the Miosix kernel with Netbeans ===&lt;br /&gt;
&lt;br /&gt;
Select &amp;quot;File &amp;gt; Open project&amp;quot; and select the &amp;quot;miosix_np_2&amp;quot; directory withn the Miosix top level directory.&lt;br /&gt;
&lt;br /&gt;
[[File:Nbsetup4-linux.png]]&lt;br /&gt;
&lt;br /&gt;
You may want to rename the project from the default &amp;quot;miosix_np_2&amp;quot; to the name of the project you are going to develop, by right clicking on the project name and selecting &amp;quot;Rename&amp;quot;, once you have opened it.&lt;br /&gt;
&lt;br /&gt;
Miosix supports different boards, each of which has different board support packages and peripheral drivers. To get code completion support for your board you need to select it within the IDE, as in the following image&lt;br /&gt;
&lt;br /&gt;
[[File:Nbsetup5-linux.png]]&lt;br /&gt;
&lt;br /&gt;
Please note that in the [[Linux Quick Start]] you had to select the board to compile for by editing the [[Makefile.inc|miosix/config/Makefile.inc]]. The board selection within the IDE &#039;&#039;&#039;does not replace&#039;&#039;&#039; the need to edit Makefile.inc, they serve two different purposes:&lt;br /&gt;
* Board selection within the IDE is used by the IDE to set up code completion for your board&lt;br /&gt;
* Board selection in Makefile.inc tells the kernel for which board it needs to be compiled.&lt;br /&gt;
However, please note that you can edit Makefile.inc and [[miosix_settings.h|miosix/config/miosix_settings.h]] as regular source files within the IDE, without the need to use a standalone text editor.&lt;br /&gt;
&lt;br /&gt;
You can open main.cpp (double click on it from the left pane), and start typing your code. Code completion is invoked by typing the first letters of the function, variable, class or member function and hitting &amp;quot;Ctrl-space&amp;quot;. Netbeans also integrates with Doxygen documentation, so you can see the documentation for Miosix classes and functions directly from the IDE.&lt;br /&gt;
&lt;br /&gt;
[[File:Nbsetup6-linux.png]]&lt;br /&gt;
&lt;br /&gt;
Building is performed by clicking the hammer icon above the source code editor. The Output window will appear below the source editor showing the compilation progress and eventual compiler errors.&lt;br /&gt;
There is no known way to transfer the compiled program on a microcontroller board directly from the IDE, for this you will have to use the QSTLink2 tool as explained in [[Linux Quick Start]].&lt;br /&gt;
&lt;br /&gt;
[[Category:Installation and Configuration]]&lt;/div&gt;</summary>
		<author><name>Fede.tft</name></author>
	</entry>
	<entry>
		<id>https://miosix.org/wiki/index.php?title=Windows_Netbeans_configuration&amp;diff=487</id>
		<title>Windows Netbeans configuration</title>
		<link rel="alternate" type="text/html" href="https://miosix.org/wiki/index.php?title=Windows_Netbeans_configuration&amp;diff=487"/>
		<updated>2026-05-17T07:19:28Z</updated>

		<summary type="html">&lt;p&gt;Fede.tft: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== Installing the IDE ===&lt;br /&gt;
&lt;br /&gt;
Download the [https://netbeans.org/downloads Netbeans IDE]. Among the possible versions choose the C/C++ version.&lt;br /&gt;
Netbeans is an IDE written in Java, so it requires the JDK to function. If you don&#039;t have the JDK installed, download it from [http://www.oracle.com/technetwork/java/index.html here] and install it before installing Netbeans.&lt;br /&gt;
&lt;br /&gt;
=== Configuring the IDE ===&lt;br /&gt;
&lt;br /&gt;
Netbeans is a generic C/C++ IDE, and once installed is not set up by default to develop for ARM microcontrollers and Miosix. So you need to configure it. This is a one-time step that you will have to do again only if you re-install the IDE.&lt;br /&gt;
&lt;br /&gt;
Note: this assumes you have already installed the Miosix toolchain, if not read the [[Windows Quick Start]] tutorial first.&lt;br /&gt;
&lt;br /&gt;
Open the Netbeans IDE (there should be an icon on the Desktop after installation) and click on &amp;quot;Tools &amp;gt; Options&amp;quot;. From the top of the options window select the C/C++ panel, and click the &amp;quot;Add&amp;quot; button to add a compiler to Netbeans. As &amp;quot;Base directory&amp;quot; choose &amp;quot;C:\arm-miosix-eabi\arm-miosix-eabi\bin&amp;quot;. Choose &amp;quot;GNU MinGW&amp;quot; as &amp;quot;Tool collection family&amp;quot;, and &amp;quot;ARM_MIOSIX_EABI&amp;quot; as &amp;quot;Tool collection name&amp;quot;.&lt;br /&gt;
Note that you &#039;&#039;&#039;must&#039;&#039;&#039; use the &amp;quot;ARM_MIOSIX_EABI&amp;quot; name, or you&#039;ll have problems later.&lt;br /&gt;
The C and C++ compiler should be automatically filled in by Netbeans, if not copy them from the screenshot below. Please note that make.exe should have &#039;&#039;&#039;no path&#039;&#039;&#039; otherwise compiling will fail.&lt;br /&gt;
&lt;br /&gt;
[[File:Nbsetup1-windows.png]]&lt;br /&gt;
&lt;br /&gt;
Last, you will need to set up the paths with the compiler libraries for code completion to work. Click on the &amp;quot;Code assistance&amp;quot; tab, and &amp;quot;C compiler&amp;quot; sub-tab. The list of folders and macro definitions should look like in this screenshot, if not, add the paths manually.&lt;br /&gt;
&lt;br /&gt;
[[File:Nbsetup2-windows.png]]&lt;br /&gt;
&lt;br /&gt;
Then click th &amp;quot;C++ compiler&amp;quot; sub-tab and check if the paths and macro definitions are correct. If not add the missing paths manually as in the next screenshot.&lt;br /&gt;
&lt;br /&gt;
[[File:Nbsetup3-windows.png]]&lt;br /&gt;
&lt;br /&gt;
Configuration is now complete. You can close the Options windows by clicking &amp;quot;Ok&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Building the Miosix kernel with Netbeans ===&lt;br /&gt;
&lt;br /&gt;
Select &amp;quot;File &amp;gt; Open project&amp;quot; and select the &amp;quot;miosix_np_2&amp;quot; directory withn the Miosix top level directory.&lt;br /&gt;
&lt;br /&gt;
[[File:Nbsetup4-windows.png]]&lt;br /&gt;
&lt;br /&gt;
You may want to rename the project from the default &amp;quot;miosix_np_2&amp;quot; to the name of the project you are going to develop, by right clicking on the project name and selecting &amp;quot;Rename&amp;quot;, once you have opened it.&lt;br /&gt;
&lt;br /&gt;
Miosix supports different boards, each of which has different board support packages and peripheral drivers. To get code completion support for your board you need to select it within the IDE, as in the following image&lt;br /&gt;
&lt;br /&gt;
[[File:Nbsetup5-windows.png]]&lt;br /&gt;
&lt;br /&gt;
Please note that in the [[Windows Quick Start]] you had to select the board to compile for by editing the [[Makefile.inc|miosix/config/Makefile.inc]]. The board selection within the IDE &#039;&#039;&#039;does not replace&#039;&#039;&#039; the need to edit Makefile.inc, they serve two different purposes:&lt;br /&gt;
* Board selection within the IDE is used by the IDE to set up code completion for your board&lt;br /&gt;
* Board selection in Makefile.inc tells the kernel for which board it needs to be compiled.&lt;br /&gt;
However, please note that you can edit Makefile.inc and [[miosix_settings.h|miosix/config/miosix_settings.h]] as regular source files within the IDE, without the need to use Notepad++.&lt;br /&gt;
&lt;br /&gt;
You can open main.cpp (double click on it from the left pane), and start typing your code. Code completion is invoked by typing the first letters of the function, variable, class or member function and hitting &amp;quot;Ctrl-space&amp;quot;. Netbeans also integrates with Doxygen documentation, so you can see the documentation for Miosix classes and functions directly from the IDE.&lt;br /&gt;
&lt;br /&gt;
[[File:Nbsetup6-windows.png]]&lt;br /&gt;
&lt;br /&gt;
Building is performed by clicking the hammer icon above the source code editor. The Output window will appear below the source editor showing the compilation progress and eventual compiler errors.&lt;br /&gt;
There is no known way to transfer the compiled program on a microcontroller board directly from the IDE, for this you will have to use the QSTLink2 tool as explained in [[Windows Quick Start]].&lt;br /&gt;
&lt;br /&gt;
[[Category:Installation and Configuration]]&lt;/div&gt;</summary>
		<author><name>Fede.tft</name></author>
	</entry>
	<entry>
		<id>https://miosix.org/wiki/index.php?title=Miosix_and_git_workflow&amp;diff=486</id>
		<title>Miosix and git workflow</title>
		<link rel="alternate" type="text/html" href="https://miosix.org/wiki/index.php?title=Miosix_and_git_workflow&amp;diff=486"/>
		<updated>2026-05-17T07:18:01Z</updated>

		<summary type="html">&lt;p&gt;Fede.tft: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
= The Miosix git repository =&lt;br /&gt;
&lt;br /&gt;
Miosix uses the git version control system to manage the kernel source code. To download and use the kernel you have to clone its git repository. The main Miosix git repository is hosted on this website, miosix.org, but we have no web page where you can browse the kernel sources. For this, we use a [https://github.com/fedetft/miosix-kernel github mirror] and the two repositories will be always kept in sync.&lt;br /&gt;
&lt;br /&gt;
As the kernel is under active development, users are advised to periodically &#039;&#039;git fetch&#039;&#039; or check the [https://github.com/fedetft/miosix-kernel kernel page on github] to look for new features and bug fixes, and pull the changes if required.&lt;br /&gt;
&lt;br /&gt;
Cloning the kernel repository from miosix.org can be done with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git clone https://miosix.org/git-public/miosix-kernel.git&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
While cloning the github mirror with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git clone https://github.com/fedetft/miosix-kernel.git&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Branches ==&lt;br /&gt;
&lt;br /&gt;
By default, when cloning a repository, git will download the &#039;&#039;master&#039;&#039; branch. Miosix offers two additional branches, &#039;&#039;testing&#039;&#039; and &#039;&#039;unstable&#039;&#039;, and you should be aware of the conventions we use for how we manage branches:&lt;br /&gt;
* The &#039;&#039;master&#039;&#039; branch contains the stable kernel, it is updated infrequently, usually once a year when a new release is made. Sometimes, a few minor releases are updated in short order.&lt;br /&gt;
* The &#039;&#039;testing&#039;&#039; branch contains the in-development code that we consider almost ready. Use this branch to get more bleeding edge features.&lt;br /&gt;
* The &#039;&#039;unstable&#039;&#039; branch is where the Miosix development team is working. It&#039;s meant to be used only by people in contact with the development team, as we occasionally rebase and force-push changes, so you may have a hard time keeping your git repository in sync with ours (the commit you downloaded today may no longer exist after a force push). If you&#039;re writing applications, it&#039;s best to ignore this branch and wait for the desired change to trickle to testing.&lt;br /&gt;
&lt;br /&gt;
To checkout a specific branch, once you have cloned the git repository, use the following command&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
cd miosix-kernel&lt;br /&gt;
git checkout testing&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Using Miosix in your projects =&lt;br /&gt;
&lt;br /&gt;
The rest of this page explains how to set up a software project making use of the Miosix kernel. There are basically two ways to do so:&lt;br /&gt;
&lt;br /&gt;
* Using out of git tree projects: this is the suggested workflow for developing applications using Miosix. Your application directory (and optionally git repo) stay separate from the kernel directory and git repo. The kernel can be a git submodule of your project.&lt;br /&gt;
* Forking the Miosix kernel git repository. This is the suggested workflow for extending the kernel, such as adding new board support packages (BSPs).&lt;br /&gt;
&lt;br /&gt;
The two workflows can be combined, for example you may want to fork the kernel to add your BSPs, and then use the forked kernel as submodule for developing your applications.&lt;br /&gt;
&lt;br /&gt;
= Out of git tree projects =&lt;br /&gt;
&lt;br /&gt;
Out of git tree projects allow you to write applications in a directory that stays separate from the Miosix kernel directory. When we say &#039;&#039;out of git tree&#039;&#039;, we mean that your project is developed outside of the &#039;&#039;Miosix&#039;&#039; git tree. Your project can be a git repository too, but that is up to you to decide.&lt;br /&gt;
&lt;br /&gt;
Additionally, a key part of an out of git tree project is that it allows to perform the kernel configuration (that requires editing configuration files) without the need to make changes to files within the Miosix git repo &#039;&#039;at all&#039;&#039;. This last point is important both to have the Miosix git repository as a [http://www.git-scm.com/book/en/Git-Tools-Submodules git submodule] of your application&#039;s git repository, and to allow sharing the same downloaded copy of the Miosix kernel across different applications, each with its own configuration. The kernel source code size on the hard drive has grown bigger in recent years due to the inclusion of headers with peripheral registers definitions in the [https://github.com/fedetft/miosix-kernel/tree/master/miosix/arch/CMSIS CMSIS] directory, so you may want to share a single downloaded copy of the kernel across several projects.&lt;br /&gt;
&lt;br /&gt;
Note that the ability to develop applications without making changes to the kernel directory is currently limited to the use case of configuring the kernel for one of the available BSPs. If you need to add BSPs to the kernel, then you&#039;ll most likely also have to fork the kernel repository. The &#039;&#039;most likely&#039;&#039; is due to &#039;&#039;generic&#039;&#039; BSPs in the kernel, which can be identified in the list of boards in [https://github.com/fedetft/miosix-kernel/blob/master/miosix/config/Makefile.inc Makefile.inc] as &#039;&#039;&amp;lt;chip name&amp;gt;_generic&#039;&#039; such as  &#039;&#039;stm32f103xb_generic&#039;&#039;. If you&#039;re writing an application for a board that has a chip with a generic BSP in the kernel, you can (unless you &#039;&#039;really&#039;&#039; need to run some custom code during boot) get away with selecting the generic BSP without forking the kernel. If there&#039;s no generic BSP for your chip, or need to add support for an entirely new chip, then you&#039;ll have to fork the kernel to add it.&lt;br /&gt;
&lt;br /&gt;
== Organizing your out of git tree projects ==&lt;br /&gt;
&lt;br /&gt;
For an out of git tree project, you need to create a directory in your computer that will contain your project. The &#039;&#039;miosix-kernel&#039;&#039; directory (and git repo) can either be a subdirectory of your project&#039;s directory (common option when adding the Miosix kernel as a git submodule to your project):&lt;br /&gt;
&lt;br /&gt;
[[File:Out-of-tree-subdirectory.png]]&lt;br /&gt;
&lt;br /&gt;
Or you can organize your projects side by side to the kernel (common when sharing a single kernel among multiple projects):&lt;br /&gt;
&lt;br /&gt;
[[File:Out-of-tree-shared.png]]&lt;br /&gt;
&lt;br /&gt;
The only constraint (it&#039;s a limitation in the Makefile build systems), is that the &#039;&#039;relative&#039;&#039; path from your project directory to the kernel should not contain spaces. This practically means that you should not give your project directories names with spaces.&lt;br /&gt;
&lt;br /&gt;
== Adding Miosix as a submodule to your git project == &lt;br /&gt;
&lt;br /&gt;
Suppose you have a git repository called myapplication, which is the repo of your application, and you would like to download the miosix-kernel repository as a git submodule. Then open a shell in the test repository and type:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git submodule init&lt;br /&gt;
git submodule add https://miosix.org/git-public/miosix-kernel.git miosix-kernel&lt;br /&gt;
git commit -m &amp;quot;Added miosix-kernel as a git submodule&amp;quot;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Initializing an out of git tree project ==&lt;br /&gt;
&lt;br /&gt;
Using out of git tree projects implies having a build system in your project directory that can both compile the source code of your application and the Miosix kernel. Miosix provides two build systems, Makefiles and [[CMake]]. In this tutorial we&#039;ll use Makefiles.&lt;br /&gt;
&lt;br /&gt;
Miosix projects start from a template that you can find in the &#039;&#039;miosix-kernel/templates&#039;&#039; directory. You can copy the template yourself from the kernel source tree to your project directory, but in that case, you&#039;ll need to fix the relative paths in the build system. Alternatively, you can use the &#039;&#039;init_project_out_of_git_tree.pl&#039;&#039; script to initialize a project.&lt;br /&gt;
&lt;br /&gt;
Additionally, the kernel configuration directory needs to be copied to your project. This is necessary because you&#039;ll need to make changes to those files to select kernel build options, at minimum which board you want to compile the kernel for.&lt;br /&gt;
As you may know, git submodules work well if you never make changes in the submodule directory, otherwise you will have to basically fork the submodule, or you will find yourself making changes to a repository in a detached head state and risk losing them at the next git pull.&lt;br /&gt;
For this reason, we&#039;ll copy the config directory to your project and make changes there. The &#039;&#039;init_project_out_of_git_tree.pl&#039;&#039; performs also this action for you.&lt;br /&gt;
&lt;br /&gt;
=== Initialize a project using &#039;&#039;init_project_out_of_git_tree.pl&#039;&#039; ===&lt;br /&gt;
&lt;br /&gt;
Just open a shell in your project directory and invoke the perl script in the kernel:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=bash&amp;gt;&lt;br /&gt;
perl &amp;lt;path to the kernel&amp;gt;tools/init_project_out_of_git_tree.pl&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus for the case when the kernel is a subdirectory of your project that would be:&lt;br /&gt;
&amp;lt;source lang=bash&amp;gt;&lt;br /&gt;
perl miosix-kernel/tools/init_project_out_of_git_tree.pl&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
While for the side-by-side case:&lt;br /&gt;
&amp;lt;source lang=bash&amp;gt;&lt;br /&gt;
perl ../miosix-kernel/tools/init_project_out_of_git_tree.pl&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that you have to run the script without moving the current directory away from the one of your project. This means you can&#039;t &#039;&#039;cd&#039;&#039; to the &#039;&#039;miosix-kernel/tools&#039;&#039; directory, run the script there, and then &#039;&#039;cd&#039;&#039; back. The script withes the project files to the current directory it&#039;s been invoked from.&lt;br /&gt;
&lt;br /&gt;
If all goes well you&#039;ll get a message similar to:&lt;br /&gt;
&amp;lt;source lang=bash&amp;gt;&lt;br /&gt;
Successfully created Miosix project&lt;br /&gt;
Target directory: myapplication&lt;br /&gt;
Kernel directory: myapplication/miosix-kernel/miosix&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and your project should now contain the &#039;&#039;config&#039;&#039; directory and the &#039;&#039;main.cpp&#039;&#039;, &#039;&#039;Makefile&#039;&#039; and &#039;&#039;CMakeLists.txt&#039;&#039; files.&lt;br /&gt;
&lt;br /&gt;
From there, you&#039;ll need to edit the configuration as desired, and start building your application starting from &#039;&#039;main.cpp&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
=== Manually copying a template ===&lt;br /&gt;
&lt;br /&gt;
The perl script is convienient, but not necessary. It&#039;s possible to do the configuration manually by copying and editing files.&lt;br /&gt;
&lt;br /&gt;
To do so, there are 3 steps involved.&lt;br /&gt;
&lt;br /&gt;
First, copy the &#039;&#039;miosix-kernel/miosix/config&#039;&#039; directory to your project.&lt;br /&gt;
&lt;br /&gt;
Second, copy a template form the &#039;&#039;miosix-kernel/templates&#039;&#039; directory to your project. The &#039;&#039;simple&#039;&#039; template configures the kernel as a unikernel and will run your application in kernelspace. The &#039;&#039;processes&#039;&#039; template will allow you to develop (part of) your application in a userspace process with memory protection, bu that&#039;s a more advanced topic related to the [[fluid kernel]] concept.&lt;br /&gt;
&lt;br /&gt;
You shouldn&#039;t copy the template directory, rather its content, so the &#039;&#039;main.cpp&#039;&#039;, &#039;&#039;Makefile&#039;&#039; and &#039;&#039;CMakeLists.txt&#039;&#039; files in the case of the &#039;&#039;simple&#039;&#039; template.&lt;br /&gt;
&lt;br /&gt;
Third and final step, you should edit the build system to point to the correct kernel and config directory. This step was done automatically by the perl script, in this case you&#039;ll have to do it manually.&lt;br /&gt;
&lt;br /&gt;
Open the &#039;&#039;Makefile&#039;&#039; file, and edit the following lines:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=bash&amp;gt;&lt;br /&gt;
KPATH := ../../miosix&lt;br /&gt;
CONFPATH := $(KPATH)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first line, defining the KPATH variable should be assigned to the relative path from your project directory to the kernel directory. If your &#039;&#039;miosix-kernel&#039;&#039; is a subdirectory of your project that should be:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=bash&amp;gt;&lt;br /&gt;
KPATH := miosix-kernel/miosix&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The second line defines the CONFPATH variable, and since you want to the kernel to find the &#039;&#039;config&#039;&#039; directory in your project , and &#039;&#039;&#039;not&#039;&#039;&#039; the one in the &#039;&#039;miosix-kernel/miosix/config&#039;&#039; directory, you&#039;ll have to chege it to the current directory, or &#039;&#039;.&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=bash&amp;gt;&lt;br /&gt;
CONFPATH := .&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally, open &#039;&#039;CMakeLists.txt&#039;&#039;. Also in this case you&#039;ll have to tell it where is the kernel directory, and to use the &#039;&#039;config&#039;&#039; directory in your project. The kernel directory is specified by replacing:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=bash&amp;gt;&lt;br /&gt;
set(MIOSIX_KPATH ${CMAKE_SOURCE_DIR}/../../miosix)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=bash&amp;gt;&lt;br /&gt;
set(MIOSIX_KPATH ${CMAKE_SOURCE_DIR}/miosix-kernel/miosix)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Whiel to tell CMake to use the config directory in your project, uncomment the following line:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=bash&amp;gt;&lt;br /&gt;
set(MIOSIX_USER_CONFIG_PATH ${CMAKE_SOURCE_DIR}/config)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Forking the Miosix git repository =&lt;br /&gt;
&lt;br /&gt;
Forking the Miosix git repository simply means cloning the kernel repository and start making changes within the kernel. To clone the git repository you simply type the following commands:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git clone https://miosix.org/git-public/miosix-kernel.git&lt;br /&gt;
cd miosix-kernel&lt;br /&gt;
git checkout testing&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The Miosix top-level directory contains the following files and subdirectories:&lt;br /&gt;
&lt;br /&gt;
[[File:Miosix-top-level-directory.png]]&lt;br /&gt;
&lt;br /&gt;
The [https://github.com/fedetft/miosix-kernel/blob/master/README.md README.md] file contains more detailed information on how the kernel source code directory tree is structured, but a quick overview is that the entire kernel code is in the &#039;&#039;miosix&#039;&#039; subdirectory, &#039;&#039;templates&#039;&#039; contains application templates you can copy out of the kernel directory to create your out of tree projects, &#039;&#039;examples&#039;&#039; contains some demos of the Miosix APIs, wile &#039;&#039;tools&#039;&#039; contains scripts and support code that does not get compiled into the kernel. It also contains the scripts and patches used to build the [[Miosix Toolchain]], the GCC-based cross compiler used to build the kernel.&lt;br /&gt;
&lt;br /&gt;
== Making changes ==&lt;br /&gt;
&lt;br /&gt;
Once you start making changes you can simply commit in the cloned git repository. If you need to share your changes, perhaps because there are multiple developers, git allows to have multiple remotes for a repository, so you can leave the default remote to periodically pull updates and bugfixes from the upstream Miosix repository, as well as push and pull from your personal remote repository.&lt;br /&gt;
&lt;br /&gt;
== Testing changes ==&lt;br /&gt;
&lt;br /&gt;
Once you start making changes to the kernel, you&#039;ll most likely want to quickly test to see if they work, which entails compiling the kernel to check for compile-time errors, and flash it to a board to check the code works at run-time.&lt;br /&gt;
&lt;br /&gt;
To do so you can set up a Miosix out of git tree project as described earlier that points to your cloned kernel, but there&#039;s a quicker way: building the templates from within the kernel tree.&lt;br /&gt;
&lt;br /&gt;
To do so, you&#039;ll need to select the board you want to build directly in the [https://github.com/fedetft/miosix-kernel/blob/master/miosix/config/Makefile.inc miosix/config/Makefile.inc] inside the kernel source tree, and select additional options (if needed) directly in the [https://github.com/fedetft/miosix-kernel/blob/master/miosix/config/miosix_settings.h miosix/config/miosix_settings.h] inside the kernel source tree.&lt;br /&gt;
&lt;br /&gt;
Ad this point, you can &#039;&#039;cd&#039;&#039; to the &#039;&#039;templates/simple&#039;&#039; (or any other template directory) and type&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=bash&amp;gt;&lt;br /&gt;
make&lt;br /&gt;
make program&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
from that directory.&lt;br /&gt;
&lt;br /&gt;
Although convenient, this comes with two caveats that you should be careful about:&lt;br /&gt;
* If you also use the kernel for making out of tree projects, the scripts  such as &#039;&#039;init_project_out_of_git_tree.pl&#039;&#039;, when copying the configuration and template directory to initialize a out of tree project, will also copy the testing code with it. This is often just a minor inconvenience, which can easily be solved in many ways, such as by using &#039;&#039;git stash&#039;&#039; before running an &#039;&#039;init_project_out_of_git_tree.pl&#039;&#039; script to temporarily stash those changes.&lt;br /&gt;
* You should remember to &#039;&#039;&#039;not commit&#039;&#039;&#039; these changes to configuration files, especially when you plan to contribute patches upstream. The list of boards in Makefile.inc should by default have all the available boards commented out, so as to let users select the board they want by uncommenting it.&lt;br /&gt;
&lt;br /&gt;
== Running the Miosix regression testsuite ==&lt;br /&gt;
&lt;br /&gt;
Miosix comes with a regression test suite that exercises most of the kernel code and is useful when making changes to the kernel to verify the absence of regressions.&lt;br /&gt;
&lt;br /&gt;
To compile the testsuite you should follow the instructions above to moddify the kernel&#039;s &#039;&#039;miosix/config&#039;&#039; directory to select the board you want to run the testsuite on, and then compile the testuite that is in the &#039;&#039;tools/testsuite&#039;&#039; directory.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=bash&amp;gt;&lt;br /&gt;
cd tools/testsuite&lt;br /&gt;
make&lt;br /&gt;
make program&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that compiled firmware of the testsuite is quite large since it contains every function of the kernel, especially if compiled with support for the filesystem and userspace processes.&lt;br /&gt;
&lt;br /&gt;
Making it easier to run the testsuite on small microcontrollers with little FLASH and RAM memory is a work in progress, he Miosix development team &amp;quot;chops&amp;quot; the testsuite in smaller pieces by commenting out part of it and running it one piece at a time, this is a tip worth knowing if you need to run it on very small microcontrollers.&lt;br /&gt;
&lt;br /&gt;
== Contributing to Miosix ==&lt;br /&gt;
&lt;br /&gt;
Miosix uses a shared ownership model, meaning that you retain the copyright for the contributions you add to the kernel. Your contributions should however be licensed with the same license of the rest of the kernel:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=CPP&amp;gt;&lt;br /&gt;
/***************************************************************************&lt;br /&gt;
 *   Copyright (C) &amp;lt;year&amp;gt; by &amp;lt;your name&amp;gt;                                   *&lt;br /&gt;
 *                                                                         *&lt;br /&gt;
 *   This program is free software; you can redistribute it and/or modify  *&lt;br /&gt;
 *   it under the terms of the GNU General Public License as published by  *&lt;br /&gt;
 *   the Free Software Foundation; either version 2 of the License, or     *&lt;br /&gt;
 *   (at your option) any later version.                                   *&lt;br /&gt;
 *                                                                         *&lt;br /&gt;
 *   This program is distributed in the hope that it will be useful,       *&lt;br /&gt;
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *&lt;br /&gt;
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *&lt;br /&gt;
 *   GNU General Public License for more details.                          *&lt;br /&gt;
 *                                                                         *&lt;br /&gt;
 *   As a special exception, if other files instantiate templates or use   *&lt;br /&gt;
 *   macros or inline functions from this file, or you compile this file   *&lt;br /&gt;
 *   and link it with other works to produce a work based on this file,    *&lt;br /&gt;
 *   this file does not by itself cause the resulting work to be covered   *&lt;br /&gt;
 *   by the GNU General Public License. However the source code for this   *&lt;br /&gt;
 *   file must still be made available in accordance with the GNU General  *&lt;br /&gt;
 *   Public License. This exception does not invalidate any other reasons  *&lt;br /&gt;
 *   why a work based on this file might be covered by the GNU General     *&lt;br /&gt;
 *   Public License.                                                       *&lt;br /&gt;
 *                                                                         *&lt;br /&gt;
 *   You should have received a copy of the GNU General Public License     *&lt;br /&gt;
 *   along with this program; if not, see &amp;lt;http://www.gnu.org/licenses/&amp;gt;   *&lt;br /&gt;
 ***************************************************************************/&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Be sure to add the copyright notice to all nontrivial source files. An example of a trivial source file would be a forwarding header such as [https://github.com/fedetft/miosix-kernel/blob/master/miosix/arch/cpu/armv8m/interfaces-impl/endianness_impl.h this one].&lt;br /&gt;
&lt;br /&gt;
If you wrote the file you want to add from scratch, just add your name to the copyright notice. If instead you copy-pasted the file from another one already present in the kernel and modified it (this often happens when making BSPs as there&#039;s almost always a similar BSP in the kernel to take inspiration from), just append your name to the list of authors of the file you copied.&lt;br /&gt;
&lt;br /&gt;
Since we use github only as a mirror to our repository that we host on miosix.org, we do not accept pull requests. You will instead be required to make a [https://git-scm.com/docs/git-format-patch format-patch] with the changes you want to be pushed upstream and send it via email to fede.tft&amp;amp;&amp;amp;miosix.org (s/&amp;amp;&amp;amp;/@/). It may be a good idea to get in contact first to discuss the changes you want pushed upstream, especially if they include modifications to the kernel itself rather than being simply new BSPs.&lt;br /&gt;
&lt;br /&gt;
When submitting patches for inclusion, please make sure that commits are small and self-contained, in order to simplify the integration process.&lt;br /&gt;
&lt;br /&gt;
Your changes should apply to the latest &#039;&#039;testing&#039;&#039; branch. If changes are related to the kernel itself, we may request to rebase them on top of &#039;&#039;unstable&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
[[Category:Installation and Configuration]]&lt;/div&gt;</summary>
		<author><name>Fede.tft</name></author>
	</entry>
	<entry>
		<id>https://miosix.org/wiki/index.php?title=Fluid_kernel&amp;diff=485</id>
		<title>Fluid kernel</title>
		<link rel="alternate" type="text/html" href="https://miosix.org/wiki/index.php?title=Fluid_kernel&amp;diff=485"/>
		<updated>2026-05-17T07:16:03Z</updated>

		<summary type="html">&lt;p&gt;Fede.tft: Created page with &amp;quot;TODO: the fluid kernel architecture needs to be documented in the wiki. In the meantime, you can read [https://ieeexplore.ieee.org/document/11173649 the paper].&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;TODO: the fluid kernel architecture needs to be documented in the wiki.&lt;br /&gt;
In the meantime, you can read [https://ieeexplore.ieee.org/document/11173649 the paper].&lt;/div&gt;</summary>
		<author><name>Fede.tft</name></author>
	</entry>
	<entry>
		<id>https://miosix.org/wiki/index.php?title=Miosix_in_emulation&amp;diff=484</id>
		<title>Miosix in emulation</title>
		<link rel="alternate" type="text/html" href="https://miosix.org/wiki/index.php?title=Miosix_in_emulation&amp;diff=484"/>
		<updated>2026-05-15T16:14:12Z</updated>

		<summary type="html">&lt;p&gt;Fede.tft: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page attempts to provide enough instructions to try out Miosix under the most common system emulators.&lt;br /&gt;
Running Miosix under an emulator could be useful to try it out or debug it if you don&#039;t have (or if you don&#039;t want to buy) the required hardware.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Important:&#039;&#039;&#039; At the moment none of the emulators we have attempted to use have managed to properly boot a fully-functioning instance of Miosix and pass all self-tests. Some of them might work well enough for simple applications, but will fail when certain kernel APIs are called. &lt;br /&gt;
The main issue is how well emulators emulate the complex logic of the peripherals of a microcontroller. Often emulators claim to support a specific microcontroller, while the emulation of most peripherals is either completely missing or incomplete.&lt;br /&gt;
Hardware timers not running at the correct rate or at all is a common issue, also USART input appears to not work on any emulator. Therefore, &#039;&#039;&#039;do not base your opinion of Miosix on your experience with running it under emulation&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Miosix versions before 2.5, which are not [[Wikipedia:Tickless kernel|tickless kernels]], are known to work better under emulation.&lt;br /&gt;
&lt;br /&gt;
== QEMU ==&lt;br /&gt;
&lt;br /&gt;
[https://www.qemu.org QEMU] is an open-source virtual machine monitor and emulator software capable to emulate a wide range of hardware, including CPUs, graphics adapters, network cards, and storage devices. It is commonly used by software, firmware and hardware engineers for testing, debugging, and virtualization purposes. Furthermore, QEMU is easy to set-up from the command line.&lt;br /&gt;
&lt;br /&gt;
=== Supported boards ===&lt;br /&gt;
&lt;br /&gt;
The QEMU Documentation mentions a few supported STM32 boards. Among those, the [[Stm32f100rb stm32vldiscovery|STM32VLDISCOVERY]] board is supported by Miosix as well. However, at the moment we are writing, the latest version of QEMU (8.0.2) lacks support for many STM32 devices, and therefore a non-negligible amount of peripherals and interfaces are not available for emulation. Additionally, even the existing implementation of supported devices appears to be incomplete.&lt;br /&gt;
&lt;br /&gt;
To show the boards supported by the QEMU version installed on the system, type the following command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
qemu-system-arm -machine help&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Configuration of Miosix ===&lt;br /&gt;
&lt;br /&gt;
To make the Miosix kernel work on QEMU it is important to &#039;&#039;&#039;disable the DMA&#039;&#039;&#039; since it is unimplemented and will cause emulation to hang as soon as it is accessed.&lt;br /&gt;
To disable the DMA, it is sufficient to open the board settings file in the config directory [https://github.com/fedetft/miosix-kernel/blob/master/miosix/config/board/stm32f100rb_stm32vldiscovery/board_settings.h miosix/config/board/stm32f100rb_stm32vldiscovery/board_settings.h] and set &amp;lt;code&amp;gt;defaultSerialDma&amp;lt;/code&amp;gt; to false:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code lang=CPP&amp;gt;&lt;br /&gt;
const bool defaultSerialDma=false; &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It is also important to avoid the usage of unimplemented devices, such as GPIOs, therefore LEDs and buttons don&#039;t work.&lt;br /&gt;
&lt;br /&gt;
=== Launching emulation ===&lt;br /&gt;
&lt;br /&gt;
To emulate the board and launch the freshly compiled Miosix kernel you can use the following command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
qemu-system-arm -M stm32vldiscovery -kernel main.bin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For debug purposes, it is possible to obtain a list of all the unimplemented devices used by Miosix by adding the &amp;lt;code&amp;gt;-d unimp&amp;lt;/code&amp;gt; argument to the command line.&lt;br /&gt;
&lt;br /&gt;
Now, in the QEMU Monitor, it is possible to check the data transferred through the USART interface by opening the &amp;quot;View&amp;quot; pop-up menu on top and selecting &amp;quot;serial0&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Debugging the emulated machine with GDB ===&lt;br /&gt;
&lt;br /&gt;
To use GDB to monitor the loaded kernel, it is important to open a localhost tcp communication port for it and to start the emulated board in frozen mode (freeze at program\_counter=1). This is done by adding the arguments &amp;lt;code&amp;gt;-s -S&amp;lt;/code&amp;gt;&lt;br /&gt;
in the previously mentioned QEMU start emulation command. The first argument is the shorthand for &amp;lt;code&amp;gt;-gdb tcp:1234&amp;lt;/code&amp;gt;, while the second one is needed to start in frozen mode.&lt;br /&gt;
&lt;br /&gt;
Now GDB can be started with the command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
arm-miosix-eabi-gdb main.elf -ex &amp;quot;target remote localhost:1234&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== QEMU-STM32 ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/beckus/qemu_stm32 QEMU-STM32] is a QEMU fork which extends version 2.1.3 of the well-known emulator to the STM32 board family. In particular, the newly-supported boards are:&lt;br /&gt;
* Olimex STM32P103&lt;br /&gt;
* Olimexino_STM32&lt;br /&gt;
* STM32F103C8_BLUEPILL&lt;br /&gt;
&lt;br /&gt;
The last one of these boards is supported in Miosix with the name &amp;lt;code&amp;gt;stm32f103c8_breakout&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
QEMU-STM32 predates the current support for STM32 microcontrollers available in mainline QEMU, however its support is more complete. On the other hand, the development of QEMU-STM32 appears to not be active anymore in 2023, therefore building it requires to install several legacy dependencies. Additionally, the repository appears to reference several now inaccessible submodules. Therefore, to build QEMU-STM32 it is necessary to manually edit the submodule configuration to replace &amp;lt;code&amp;gt;git://git.qemu-project.org&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;git://github.com/rth7680&amp;lt;/code&amp;gt; with &amp;lt;code&amp;gt;https://gitlab.com/qemu-project&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Once you have built QEMU-STM32, using it is no different than a more recent version of QEMU. The command line to use for launching a build of Miosix for the BluePill board is the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
qemu-system-arm -machine stm32-f103c8 -kernel main.bin -serial stdio&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The setting &amp;lt;code&amp;gt;-serial stdio&amp;lt;/code&amp;gt; allows to use the standard input/output devices for sending/receiving USART data.&lt;br /&gt;
&lt;br /&gt;
== Renode ==&lt;br /&gt;
&lt;br /&gt;
[https://renode.io Renode] is an open-source simulation framework for hardware and software development. Its advertisements say it provides &amp;quot;a virtual environment where developers can simulate the behaviour of their devices and test their software on a virtual platform before deploying it on physical hardware&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Renode supports the [[Stm32f407vg stm32f4discovery|STM32F4_DISCOVERY]] board, which is a popular and well-tested target for Miosix as well. Renode supports the DMA and GPIO peripherals of the STM32, therefore no specific modifications of the Miosix code are required.&lt;br /&gt;
&lt;br /&gt;
=== Configuration of Renode ===&lt;br /&gt;
&lt;br /&gt;
Before using the STM32F4_DISCOVERY on Renode, it is necessary to:&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Add the CCM (&#039;Core Coupled Memory&#039;) in the memory map of Renode because it is not implemented by default. The easiest way to solve this problem is to modify the &amp;lt;code&amp;gt;renode/platforms/cpus/stm32f4.repl&amp;lt;/code&amp;gt; file, where all MCU registers are mapped. The following lines need to be added at the end of the file:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ccm: Memory.MappedMemory @ sysbus 0x10000000&lt;br /&gt;
    size: 0x10000&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Note!&#039;&#039;&#039; Make sure the code has the same indentation shown above, because it is significant for the compilation of the Platform Descriptor file.&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&lt;br /&gt;
Modify the &amp;lt;code&amp;gt;GPIO&amp;lt;/code&amp;gt; pin associated to the &amp;lt;code&amp;gt;UserLED&amp;lt;/code&amp;gt; because Miosix uses a different one. This could be done by modifying the &amp;lt;code&amp;gt;renode/platforms/boards/stm32f4_discovery.repl&amp;lt;/code&amp;gt; file and substituting &amp;lt;code&amp;gt;pin12&amp;lt;/code&amp;gt; with &amp;lt;code&amp;gt;pin14&amp;lt;/code&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gpioPortD:&lt;br /&gt;
    14 -&amp;gt; UserLED@0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Launching emulation ===&lt;br /&gt;
&lt;br /&gt;
To launch an instance of Miosix, built for the &amp;lt;code&amp;gt;stm32f407vg_stm32f4discovery&amp;lt;/code&amp;gt; target, launch Renode and write the following commands on the Renode console:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&lt;br /&gt;
Create a Machine, load the board and load the kernel:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mach create&lt;br /&gt;
machine LoadPlatformDescription @platforms/boards/stm32f4_discovery-kit.repl&lt;br /&gt;
sysbus LoadELF @main.elf&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&lt;br /&gt;
Open the serial monitor on USART3:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
showAnalyzer sysbus.usart3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&lt;br /&gt;
Start the GDB server (if needed):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
machine StartGdbServer 3333&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;3333&amp;lt;/code&amp;gt; is the remote port to specify in GDB to connect to the emulated machine.&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&lt;br /&gt;
Start the machine:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
start&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Renode provides very useful debugging commands, mainly to monitor the status of devices, such as &amp;lt;code&amp;gt;sysbus.gpioPortD.UserLED State&amp;lt;/code&amp;gt;, or &amp;lt;code&amp;gt;sysbus.gpioPortD GetGPIOs&amp;lt;/code&amp;gt; which prints the status of all the &#039;&#039;GPIO portD&#039;&#039; pins. To enable logs type the command &amp;lt;code&amp;gt;sysbus LogPeripheralAccess sysbus.gpioPortD True&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Acknowledgments ==&lt;br /&gt;
&lt;br /&gt;
Most of the contents of this page were contributed by Francesco Lenzi and Donato Carlo Giorgio. Thanks!&lt;/div&gt;</summary>
		<author><name>Fede.tft</name></author>
	</entry>
	<entry>
		<id>https://miosix.org/wiki/index.php?title=Synchronization_primitives&amp;diff=483</id>
		<title>Synchronization primitives</title>
		<link rel="alternate" type="text/html" href="https://miosix.org/wiki/index.php?title=Synchronization_primitives&amp;diff=483"/>
		<updated>2026-05-15T16:02:57Z</updated>

		<summary type="html">&lt;p&gt;Fede.tft: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Miosix provides synchronization primitives, both high and low level. High level synchronization primitives are standard mutexes and condition variables that are familiar to programmers of multithreaded applications. This page addresses in more detail the low level synchronization primitives which are Miosix-specific, and is most useful when developing low level code, especially device drivers, on Miosix.&lt;br /&gt;
&lt;br /&gt;
= High level synchronization primitives =&lt;br /&gt;
For what concerns high level synchronization primitives, Miosix provides the ususal mutexes and condition variables, accessible through three APIs:&lt;br /&gt;
* The C++11 classes such as &#039;&#039;std::thread&#039;&#039;, &#039;&#039;std::mutex&#039;&#039; and &#039;&#039;std::condition_variable&#039;&#039; through the C++ standard library&lt;br /&gt;
* The POSIX thread functions and opaque data types such as &#039;&#039;pthread_t&#039;&#039;, &#039;&#039;pthread_mutex_t&#039;&#039; and &#039;&#039;pthread_cond_t&#039;&#039; through the C standard library&lt;br /&gt;
* The native Miosix API which is the underlying implementation of all the other APIs. This is a C++ API including class &#039;&#039;Thread&#039;&#039; which is the actual Task Control Block (TCB) used by the scheduler, and classes &#039;&#039;Mutex&#039;&#039;, &#039;&#039;FastMutex&#039;&#039;, &#039;&#039;KernelMutex&#039;&#039; and &#039;&#039;ConditionVariable&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The use for these synchronization primitives is to protect data structures from concurrent access by multiple threads. These synchronization primitives are very easy to use, with almost no preconditions or special requirements, but cannot be used for more low-level tasks, such as synchronizing between threads and interrupt routines.&lt;br /&gt;
&lt;br /&gt;
Both the mutex and the condition variable are optimized for speed, for example a lock/unlock pair of function calls to an uncontended mutex take around 100 clock cycles on an architecture such as the Cortex-M. Recursive mutexes are supported, and so are mutexes with priority inheritance, as well as timed waits on condition variables.&lt;br /&gt;
&lt;br /&gt;
Just like the standard C++, RAII-style mutex locking is recommended also with the native API, through the provided &#039;&#039;Lock&amp;lt;T&amp;gt;&#039;&#039; and &#039;&#039;Unlock&amp;lt;T&amp;gt;&#039;&#039; classes. &lt;br /&gt;
Compare this example using directly the &#039;&#039;Mutex&#039;&#039; member functions&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;CPP&amp;quot;&amp;gt;&lt;br /&gt;
class Foo&lt;br /&gt;
{&lt;br /&gt;
    int x;&lt;br /&gt;
    Mutex m;&lt;br /&gt;
public:&lt;br /&gt;
    void decIfPositive()&lt;br /&gt;
    {&lt;br /&gt;
        m.lock();&lt;br /&gt;
        if(x&amp;lt;=0) return;&lt;br /&gt;
        x--;&lt;br /&gt;
        m.unlock();&lt;br /&gt;
    }&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As you can see, the code contains an error: the return in the middle of the function does not unlock the mutex, something that will likely cause problems.&lt;br /&gt;
&lt;br /&gt;
On the other hand, if a &#039;&#039;Lock&#039;&#039;&#039; is used&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;CPP&amp;quot;&amp;gt;&lt;br /&gt;
class Foo&lt;br /&gt;
{&lt;br /&gt;
    int x;&lt;br /&gt;
    Mutex m;&lt;br /&gt;
public:&lt;br /&gt;
    void decIfPositive()&lt;br /&gt;
    {&lt;br /&gt;
        Lock&amp;lt;Mutex&amp;gt; l(m);&lt;br /&gt;
        if(x&amp;lt;=0) return;&lt;br /&gt;
        x--;&lt;br /&gt;
    }&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
you don&#039;t have to worry about that. When considering that functions can return due to a propagation of a C++ exception, using locks is the only way to write exception-safe C++ code.&lt;br /&gt;
&lt;br /&gt;
If you need to temporarily unlock a mutex from within a scope where a &#039;&#039;Lock&#039;&#039; is in effect, this is made possible by creating an inner scope and using an &#039;&#039;Unlock&#039;&#039; object, like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;CPP&amp;quot;&amp;gt;&lt;br /&gt;
Mutex m;&lt;br /&gt;
{&lt;br /&gt;
    Lock&amp;lt;Mutex&amp;gt; l(m);&lt;br /&gt;
    //Now the Mutex is locked&lt;br /&gt;
    {&lt;br /&gt;
        Unlock&amp;lt;Mutex&amp;gt; u(l);&lt;br /&gt;
        //Now the mutex is unlocked&lt;br /&gt;
    }&lt;br /&gt;
    //Now the Mutex is again locked&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note how to create an &#039;&#039;Unlock&#039;&#039; object you have to pass a &#039;&#039;Lock&#039;&#039; to its constructor. This prevents you from trying to unlock a mutex you have not locked.&lt;br /&gt;
&lt;br /&gt;
For what concerns the &#039;&#039;ConditionVariable&#039;&#039; class, it provides the &#039;&#039;wait()&#039;&#039;, &#039;&#039;signal()&#039;&#039; and &#039;&#039;broadcast()&#039;&#039; member functions as you&#039;d expect. Moreover, there&#039;s an overload of &#039;&#039;wait()&#039;&#039; taking a &#039;&#039;Lock&#039;&#039; instead of a bare mutex for convenience.&lt;br /&gt;
&lt;br /&gt;
= Low level synchronization primitives =&lt;br /&gt;
&lt;br /&gt;
Miosix provides two low-level synchronization primitives, the GlobalIrqLock or &amp;quot;GIL&amp;quot; and the PauseKernelLock or &amp;quot;PK&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
== The GIL lock ==&lt;br /&gt;
&lt;br /&gt;
The GlobalIrqLock or &amp;quot;GIL&amp;quot;. On single core architectures, this lock disables interrupts and makes the code fragment taking this lock uninterruptible, not even by interrupt handlers. On multicore architectures, this lock disables interrupts on the core taking the lock, making the code fragment using it uninterruptible, not even by interrupt handlers. Additionally, only up to &#039;&#039;&#039;one&#039;&#039;&#039; core can take the GIL at any given time. If a second core attempts to take the GIL while another core has already taken it, it will block execution until the core holding the GIL has released it. Taking the GIL must be done using one of three [https://en.wikipedia.org/wiki/RAII RAII] C++ classes: &#039;&#039;GlobalIrqLock&#039;&#039;, which is recursive, thus allowing to take the lock multiple times, &#039;&#039;FastGlobalIrqLock&#039;&#039;, a faster but non-recursive version, or &#039;&#039;FastGlobalLockFromIrq&#039;&#039;, the only version that can be used to take the GIL from an interrupt handler (this version is not recursive).&lt;br /&gt;
&lt;br /&gt;
The GIL is used to implement device drivers that make use of interrupts, as well as inside the kernel, by the scheduler which also runs from inside an interrupt. Since both use the same lock, it&#039;s possible for an interrupt handler in a device driver to wakeup a thread from within an interrupt handler without corrupting the scheduler data structures.&lt;br /&gt;
&lt;br /&gt;
The reason why a regular mutex cannot be used for this purpose is because interrupts are by their very nature asymmetric. An interrupt can interrupt the code of a thread, but a thread cannot interrupt an interrupt. This means that when you&#039;re writing device drivers and you need to synchronize between an interrupt and normal code a mutex won&#039;t do the job. If the mutex is already locked when the interrupt code starts, trying to lock it within the interrupt will attempt to block the interrupt till the thread unlocks it, and as you can imagine, this won&#039;t end up well.&lt;br /&gt;
&lt;br /&gt;
To synchronize in such cases you have to temporarily disable interrupts from within your thread or main program, so that the thread and the interrupt won&#039;t try to access some data structure at the same time.&lt;br /&gt;
&lt;br /&gt;
There&#039;s nothing new in that, if you&#039;ve programmed microcontrollers before without an OS, you&#039;ve accustomed to disabling interrupts as a mean of synchronization. The only difference is that in multicore architectures, you&#039;ll have to remember to take the &#039;&#039;FastGlobalLockFromIrq&#039;&#039; also from within interrupt handlers before calling the scheduler API to wakeup tasks, as the scheduler could be running on another core causing a race condition. In single core architectures you don&#039;t technically need to put a &#039;&#039;FastGlobalLockFromIrq&#039;&#039; in interrupt handlers. If you do it will be optimized away as it&#039;s not required. Since there&#039;s no performance penalty, you may as well take the habit of always using &#039;&#039;FastGlobalLockFromIrq&#039;&#039;, just in case your driver gets reused in a multicore chip.&lt;br /&gt;
&lt;br /&gt;
Inside a critical section taking the GIL you should not call functions that cause a preemption, such as almost all high-level function form the C++ standard library (including &#039;&#039;printf()&#039;&#039;, &#039;&#039;&#039;malloc()/new&#039;&#039;&#039; and filesystem-related functions). Also, the only functions that are part of the Miosix kernel API that are safe to be called with the GIL locked are prefixed with IRQ. Why IRQ and not GIL you may say? It&#039;s because of older version of the kernel, before multicore support was introduced.&lt;br /&gt;
&lt;br /&gt;
More importantly, all functions of the kernel that are prefixed with IRQ are &#039;&#039;&#039;only&#039;&#039;&#039; safe to be called if you&#039;re holding the GIL.&lt;br /&gt;
&lt;br /&gt;
Some functions have both an IRQ and non IRQ version, such as &#039;&#039;miosix::getTime()&#039;&#039; and miosix::IRQgetTime()&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
== The PK lock ==&lt;br /&gt;
The PauseKernelLock or &amp;quot;PK&amp;quot;. This lock disables preemption. This means that the code fragment taking the lock cannot be preempted by other threads, but can be interrupted by interrupts. On multicore architectures, only up to &#039;&#039;&#039;one&#039;&#039;&#039; core can take the PK at any given time. If a second core attempts to take the PK while another core has already taken it, it will block execution until the core holding the PK has released it. Note that on multicore architectures, it is allowed for one core can take the GIL, while another core can take the PK.&lt;br /&gt;
&lt;br /&gt;
If the time spent with preemption disabled exceeds the thread&#039;s timeslice a preemption will occur immediately when releasing the lock.&lt;br /&gt;
&lt;br /&gt;
Despite faster than a mutex, these synchronization primitives carry some heavy restrictions, and are mostly used to implement parts of the kernel itself. The main isssue is that you must never force a preemption when the kernel is paused. If this happens, the kernel will likely lock up badly. Of course, this means you can&#039;t call &#039;&#039;Thread::yield()&#039;&#039; when the kernel is paused, but there are many more subtler ways to cause a preemption.&lt;br /&gt;
&lt;br /&gt;
In general, inside a critical section taking the GIL you should not call functions that cause a preemption, such as almost all high-level function form the C++ standard library (including &#039;&#039;printf()&#039;&#039; and filesystem-related functions). Also, the only functions that are part of the Miosix kernel API that are safe to be called with the PK locked are prefixed with PK.&lt;br /&gt;
&lt;br /&gt;
All in all, you won&#039;t find much need to use the PK synchronization primitive, unless you&#039;re writing kernel code. At that point, you&#039;ll find it useful. Miosix uses it internally to make regular mutexes and condition variables work.&lt;br /&gt;
&lt;br /&gt;
== Summarizing it all ==&lt;br /&gt;
The following table summarizes what you can do depending on what low level synchronization primitive you are using, as well as when you are writing the code of an interrupt service routine.&lt;br /&gt;
&lt;br /&gt;
Although it may seem complicated, it is because it contains all possible cases, most of which are rather uncommon. In most cases you&#039;ll be writing code while not being into the scope of any low level lock, so you can do everything but call functions prefixed with IRQ or PK. When you are within an interrupt or take the GIL, the other most common case, you will usually not need to call any function besides the kernel API prefixed with IRQ.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|&lt;br /&gt;
| file related operations&lt;br /&gt;
| printf, scanf, cin, cout&lt;br /&gt;
| Thread::yield(), Thread::sleep(), usleep()&lt;br /&gt;
| call kernel functions with no prefix&lt;br /&gt;
| call kernel functions with PK prefix&lt;br /&gt;
| call kernel functions with IRQ prefix&lt;br /&gt;
| allocate memory&lt;br /&gt;
| throw C++ exceptions&lt;br /&gt;
| delayMs() and delayUs()&lt;br /&gt;
|-&lt;br /&gt;
| Normal code&lt;br /&gt;
| style=&amp;quot;background-color: #80ff80;&amp;quot; | Yes&lt;br /&gt;
| style=&amp;quot;background-color: #80ff80;&amp;quot; | Yes&lt;br /&gt;
| style=&amp;quot;background-color: #80ff80;&amp;quot; | Yes&lt;br /&gt;
| style=&amp;quot;background-color: #80ff80;&amp;quot; | Yes&lt;br /&gt;
| style=&amp;quot;background-color: #ff8080;&amp;quot; | No&lt;br /&gt;
| style=&amp;quot;background-color: #ff8080;&amp;quot; | No&lt;br /&gt;
| style=&amp;quot;background-color: #80ff80;&amp;quot; | Yes&lt;br /&gt;
| style=&amp;quot;background-color: #80ff80;&amp;quot; | Yes&lt;br /&gt;
| style=&amp;quot;background-color: #80ff80;&amp;quot; | Yes&lt;br /&gt;
|-&lt;br /&gt;
| Within a PauseKernelLock&lt;br /&gt;
| style=&amp;quot;background-color: #ff8080;&amp;quot; | No&lt;br /&gt;
| style=&amp;quot;background-color: #ff8080;&amp;quot; | No&lt;br /&gt;
| style=&amp;quot;background-color: #ff8080;&amp;quot; | No&lt;br /&gt;
| style=&amp;quot;background-color: #ff8080;&amp;quot; | No&lt;br /&gt;
| style=&amp;quot;background-color: #80ff80;&amp;quot; | Yes&lt;br /&gt;
| style=&amp;quot;background-color: #ff8080;&amp;quot; | No&lt;br /&gt;
| style=&amp;quot;background-color: #80ff80;&amp;quot; | Yes&lt;br /&gt;
| style=&amp;quot;background-color: #80ff80;&amp;quot; | Yes&lt;br /&gt;
| style=&amp;quot;background-color: #80ff80;&amp;quot; | Yes&lt;br /&gt;
|-&lt;br /&gt;
| Within an GlobalIrqLock&lt;br /&gt;
| style=&amp;quot;background-color: #ff8080;&amp;quot; | No&lt;br /&gt;
| style=&amp;quot;background-color: #ff8080;&amp;quot; | No&lt;br /&gt;
| style=&amp;quot;background-color: #ff8080;&amp;quot; | No&lt;br /&gt;
| style=&amp;quot;background-color: #ff8080;&amp;quot; | No&lt;br /&gt;
| style=&amp;quot;background-color: #ff8080;&amp;quot; | No&lt;br /&gt;
| style=&amp;quot;background-color: #80ff80;&amp;quot; | Yes&lt;br /&gt;
| style=&amp;quot;background-color: #ff8080;&amp;quot; | No **&lt;br /&gt;
| style=&amp;quot;background-color: #ff8080;&amp;quot; | No **&lt;br /&gt;
| style=&amp;quot;background-color: #80ff80;&amp;quot; | Yes&lt;br /&gt;
|-&lt;br /&gt;
| Within a FastGlobalIrqLock&lt;br /&gt;
| style=&amp;quot;background-color: #ff8080;&amp;quot; | No&lt;br /&gt;
| style=&amp;quot;background-color: #ff8080;&amp;quot; | No&lt;br /&gt;
| style=&amp;quot;background-color: #ff8080;&amp;quot; | No&lt;br /&gt;
| style=&amp;quot;background-color: #ff8080;&amp;quot; | No&lt;br /&gt;
| style=&amp;quot;background-color: #ff8080;&amp;quot; | No&lt;br /&gt;
| style=&amp;quot;background-color: #ffff80;&amp;quot; | Yes *&lt;br /&gt;
| style=&amp;quot;background-color: #ff8080;&amp;quot; | No&lt;br /&gt;
| style=&amp;quot;background-color: #ff8080;&amp;quot; | No&lt;br /&gt;
| style=&amp;quot;background-color: #80ff80;&amp;quot; | Yes&lt;br /&gt;
|-&lt;br /&gt;
| Within an interrupt service routine (taking FastGlobalLockFromIrq in the multicore case)&lt;br /&gt;
| style=&amp;quot;background-color: #ff8080;&amp;quot; | No&lt;br /&gt;
| style=&amp;quot;background-color: #ff8080;&amp;quot; | No&lt;br /&gt;
| style=&amp;quot;background-color: #ff8080;&amp;quot; | No&lt;br /&gt;
| style=&amp;quot;background-color: #ff8080;&amp;quot; | No&lt;br /&gt;
| style=&amp;quot;background-color: #ff8080;&amp;quot; | No&lt;br /&gt;
| style=&amp;quot;background-color: #ffff80;&amp;quot; | Yes *&lt;br /&gt;
| style=&amp;quot;background-color: #ff8080;&amp;quot; | No&lt;br /&gt;
| style=&amp;quot;background-color: #ff8080;&amp;quot; | No&lt;br /&gt;
| style=&amp;quot;background-color: #80ff80;&amp;quot; | Yes&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;nowiki&amp;gt;*&amp;lt;/nowiki&amp;gt; = Most IRQ-prefixed functions can be called both with interrupts disabled (either within an &#039;&#039;GlobalIrqLock&#039;&#039;, &#039;&#039;FastGlobalIrqLockLock&#039;&#039; or &#039;&#039;FastGlobalLockFromIrq&#039;&#039;) and within an interrupt routine. The only exception being &#039;&#039;IRQregisterIrq&#039;&#039; and &#039;&#039;IRQunregisterIrq&#039;&#039; which are used for registering/unregistering interrupts, that cannot be called from within an interrupt handler and forcedly require a &#039;&#039;GlobalIrqLock&#039;&#039;. Refer to the doxygen documentation of the individual function when unsure.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;nowiki&amp;gt;**&amp;lt;/nowiki&amp;gt; = Used to be possible from Miosix v1.61 to Miosix v2.81, no longer possible since Miosix v2.99 due to multicore support. Now that a core can take the GIL and another core the PK, we must enforce that taking both locks can only be done by first taking the PK and then &amp;quot;upgrading&amp;quot; to the GIL. Doing the reverse would cause deadlocks, and since malloc/new take the PK, it&#039;s no longer possible to first take the GIL and then malloc.&lt;br /&gt;
&lt;br /&gt;
[[Category:API]]&lt;/div&gt;</summary>
		<author><name>Fede.tft</name></author>
	</entry>
	<entry>
		<id>https://miosix.org/wiki/index.php?title=Synchronization_primitives&amp;diff=482</id>
		<title>Synchronization primitives</title>
		<link rel="alternate" type="text/html" href="https://miosix.org/wiki/index.php?title=Synchronization_primitives&amp;diff=482"/>
		<updated>2026-05-15T16:02:28Z</updated>

		<summary type="html">&lt;p&gt;Fede.tft: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Miosix provides synchronization primitives, both high and low level. High level synchronization primitives are standard mutexes and condition variables that are familiar to programmers of multithreaded applications. This page addresses in more detail the low level synchronization primitives which are Miosix-specific, and is most useful when developing low level code, especially device drivers, on Miosix.&lt;br /&gt;
&lt;br /&gt;
= High level synchronization primitives =&lt;br /&gt;
For what concerns high level synchronization primitives, Miosix provides the ususal mutexes and condition variables, accessible through three APIs:&lt;br /&gt;
* The C++11 classes such as &#039;&#039;std::thread&#039;&#039;, &#039;&#039;std::mutex&#039;&#039; and &#039;&#039;std::condition_variable&#039;&#039; through the C++ standard library&lt;br /&gt;
* The POSIX thread functions and opaque data types such as &#039;&#039;pthread_t&#039;&#039;, &#039;&#039;pthread_mutex_t&#039;&#039; and &#039;&#039;pthread_cond_t&#039;&#039; through the C standard library&lt;br /&gt;
* The native Miosix API which is the underlying implementation of all the other APIs. This is a C++ API including class &#039;&#039;Thread&#039;&#039; which is the actual Task Control Block (TCB) used by the scheduler, and classes &#039;&#039;Mutex&#039;&#039;, &#039;&#039;FastMutex&#039;&#039;, &#039;&#039;KernelMutex&#039;&#039; and &#039;&#039;ConditionVariable&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The use for these synchronization primitives is to protect data structures from concurrent access by multiple threads. These synchronization primitives are very easy to use, with almost no preconditions or special requirements, but cannot be used for more low-level tasks, such as synchronizing between threads and interrupt routines.&lt;br /&gt;
&lt;br /&gt;
Both the mutex and the condition variable are optimized for speed, for example a lock/unlock pair of function calls to an uncontended mutex take around 100 clock cycles on an architecture such as the Cortex-M. Recursive mutexes are supported, and so are mutexes with priority inheritance, as well as timed waits on condition variables.&lt;br /&gt;
&lt;br /&gt;
Just like the standard C++, RAII-style mutex locking is recommended also with the native API, through the provided &#039;&#039;Lock&amp;lt;T&amp;gt;&#039;&#039; and &#039;&#039;Unlock&amp;lt;T&amp;gt;&#039;&#039; classes. &lt;br /&gt;
Compare this example using directly the &#039;&#039;Mutex&#039;&#039; member functions&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;CPP&amp;quot;&amp;gt;&lt;br /&gt;
class Foo&lt;br /&gt;
{&lt;br /&gt;
    int x;&lt;br /&gt;
    Mutex m;&lt;br /&gt;
public:&lt;br /&gt;
    void decIfPositive()&lt;br /&gt;
    {&lt;br /&gt;
        m.lock();&lt;br /&gt;
        if(x&amp;lt;=0) return;&lt;br /&gt;
        x--;&lt;br /&gt;
        m.unlock();&lt;br /&gt;
    }&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As you can see, the code contains an error: the return in the middle of the function does not unlock the mutex, something that will likely cause problems.&lt;br /&gt;
&lt;br /&gt;
On the other hand, if a &#039;&#039;Lock&#039;&#039;&#039; is used&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;CPP&amp;quot;&amp;gt;&lt;br /&gt;
class Foo&lt;br /&gt;
{&lt;br /&gt;
    int x;&lt;br /&gt;
    Mutex m;&lt;br /&gt;
public:&lt;br /&gt;
    void decIfPositive()&lt;br /&gt;
    {&lt;br /&gt;
        Lock&amp;lt;Mutex&amp;gt; l(m);&lt;br /&gt;
        if(x&amp;lt;=0) return;&lt;br /&gt;
        x--;&lt;br /&gt;
    }&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
you don&#039;t have to worry about that. When considering that functions can return due to a propagation of a C++ exception, using locks is the only way to write exception-safe C++ code.&lt;br /&gt;
&lt;br /&gt;
If you need to temporarily unlock a mutex from within a scope where a &#039;&#039;Lock&#039;&#039; is in effect, this is made possible by creating an inner scope and using an &#039;&#039;Unlock&#039;&#039; object, like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;CPP&amp;quot;&amp;gt;&lt;br /&gt;
Mutex m;&lt;br /&gt;
{&lt;br /&gt;
    Lock&amp;lt;Mutex&amp;gt; l(m);&lt;br /&gt;
    //Now the Mutex is locked&lt;br /&gt;
    {&lt;br /&gt;
        Unlock&amp;lt;Mutex&amp;gt; u(l);&lt;br /&gt;
        //Now the mutex is unlocked&lt;br /&gt;
    }&lt;br /&gt;
    //Now the Mutex is again locked&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note how to create an &#039;&#039;Unlock&#039;&#039; object you have to pass a &#039;&#039;Lock&#039;&#039; to its constructor. This prevents you from trying to unlock a mutex you have not locked.&lt;br /&gt;
&lt;br /&gt;
For what concerns the &#039;&#039;ConditionVariable&#039;&#039; class, it provides the &#039;&#039;wait()&#039;&#039;, &#039;&#039;signal()&#039;&#039; and &#039;&#039;broadcast()&#039;&#039; member functions as you&#039;d expect. Moreover, there&#039;s an overload of &#039;&#039;wait()&#039;&#039; taking a &#039;&#039;Lock&#039;&#039; instead of a bare mutex for convenience.&lt;br /&gt;
&lt;br /&gt;
= Low level synchronization primitives =&lt;br /&gt;
&lt;br /&gt;
Miosix provides two low-level synchronization primitives, the GlobalIrqLock or &amp;quot;GIL&amp;quot; and the PauseKernelLock or &amp;quot;PK&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
== The GIL lock ==&lt;br /&gt;
&lt;br /&gt;
The GlobalIrqLock or &amp;quot;GIL&amp;quot;. On single core architectures, this lock disables interrupts and makes the code fragment taking this lock uninterruptible, not even by interrupt handlers. On multicore architectures, this lock disables interrupts on the core taking the lock, making the code fragment using it uninterruptible, not even by interrupt handlers. Additionally, only up to &#039;&#039;&#039;one&#039;&#039;&#039; core can take the GIL at any given time. If a second core attempts to take the GIL while another core has already taken it, it will block execution until the core holding the GIL has released it. Taking the GIL must be done using one of three [https://en.wikipedia.org/wiki/RAII RAII] C++ classes: &#039;&#039;GlobalIrqLock&#039;&#039;, which is recursive, thus allowing to take the lock multiple times, &#039;&#039;FastGlobalIrqLock&#039;&#039;, a faster but non-recursive version, or &#039;&#039;FastGlobalLockFromIrq&#039;&#039;, the only version that can be used to take the GIL from an interrupt handler (this version is not recursive).&lt;br /&gt;
&lt;br /&gt;
The GIL is used to implement device drivers that make use of interrupts, as well as inside the kernel, by the scheduler which also runs from inside an interrupt. Since both use the same lock, it&#039;s possible for an interrupt handler in a device driver to wakeup a thread from within an interrupt handler without corrupting the scheduler data structures.&lt;br /&gt;
&lt;br /&gt;
The reason why a regular mutex cannot be used for this purpose is because interrupts are by their very nature asymmetric. An interrupt can interrupt the code of a thread, but a thread cannot interrupt an interrupt. This means that when you&#039;re writing device drivers and you need to synchronize between an interrupt and normal code a mutex won&#039;t do the job. If the mutex is already locked when the interrupt code starts, trying to lock it within the interrupt will attempt to block the interrupt till the thread unlocks it, and as you can imagine, this won&#039;t end up well.&lt;br /&gt;
&lt;br /&gt;
To synchronize in such cases you have to temporarily disable interrupts from within your thread or main program, so that the thread and the interrupt won&#039;t try to access some data structure at the same time.&lt;br /&gt;
&lt;br /&gt;
There&#039;s nothing new in that, if you&#039;ve programmed microcontrollers before without an OS, you&#039;ve accustomed to disabling interrupts as a mean of synchronization. The only difference is that in multicore architectures, you&#039;ll have to remember to take the &#039;&#039;FastGlobalLockFromIrq&#039;&#039; also from within interrupt handlers before calling the scheduler API to wakeup tasks, as the scheduler could be running on another core causing a race condition. In single core architectures you don&#039;t technically need to put a &#039;&#039;FastGlobalLockFromIrq&#039;&#039; in interrupt handlers. If you do it will be optimized away as it&#039;s not required. Since there&#039;s no performance penalty, you may as well take the habit of always using &#039;&#039;FastGlobalLockFromIrq&#039;&#039;, just in case your driver gets reused in a multicore chip.&lt;br /&gt;
&lt;br /&gt;
Inside a critical section taking the GIL you should not call functions that cause a preemption, such as almost all high-level function form the C++ standard library (including &#039;&#039;printf()&#039;&#039;, &#039;&#039;&#039;malloc()/new&#039;&#039;&#039; and filesystem-related functions). Also, the only functions that are part of the Miosix kernel API that are safe to be called with the GIL locked are prefixed with IRQ. Why IRQ and not GIL you may say? It&#039;s because of older version of the kernel, before multicore support was introduced.&lt;br /&gt;
&lt;br /&gt;
More importantly, all functions of the kernel that are prefixed with IRQ are &#039;&#039;&#039;only&#039;&#039;&#039; safe to be called if you&#039;re holding the GIL.&lt;br /&gt;
&lt;br /&gt;
Some functions have both an IRQ and non IRQ version, such as &#039;&#039;miosix::getTime()&#039;&#039; and miosix::IRQgetTime()&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
== The PK lock ==&lt;br /&gt;
The PauseKernelLock or &amp;quot;PK&amp;quot;. This lock disables preemption. This means that the code fragment taking the lock cannot be preempted by other threads, but can be interrupted by interrupts. On multicore architectures, only up to &#039;&#039;&#039;one&#039;&#039;&#039; core can take the PK at any given time. If a second core attempts to take the PK while another core has already taken it, it will block execution until the core holding the PK has released it. Note that on multicore architectures, it is allowed for one core can take the GIL, while another core can take the PK.&lt;br /&gt;
&lt;br /&gt;
If the time spent with preemption disabled exceeds the thread&#039;s timeslice a preemption will occur immediately when releasing the lock.&lt;br /&gt;
&lt;br /&gt;
Despite faster than a mutex, these synchronization primitives carry some heavy restrictions, and are mostly used to implement parts of the kernel itself. The main isssue is that you must never force a preemption when the kernel is paused. If this happens, the kernel will likely lock up badly. Of course, this means you can&#039;t call &#039;&#039;Thread::yield()&#039;&#039; when the kernel is paused, but there are many more subtler ways to cause a preemption.&lt;br /&gt;
&lt;br /&gt;
In general, inside a critical section taking the GIL you should not call functions that cause a preemption, such as almost all high-level function form the C++ standard library (including &#039;&#039;printf()&#039;&#039; and filesystem-related functions). Also, the only functions that are part of the Miosix kernel API that are safe to be called with the PK locked are prefixed with PK.&lt;br /&gt;
&lt;br /&gt;
All in all, you won&#039;t find much need to use the PK synchronization primitive, unless you&#039;re writing kernel code. At that point, you&#039;ll find it useful. Miosix uses it internally to make regular mutexes and condition variables work.&lt;br /&gt;
&lt;br /&gt;
== Summarizing it all ==&lt;br /&gt;
The following table summarizes what you can do depending on what low level synchronization primitive you are using, as well as when you are writing the code of an interrupt service routine.&lt;br /&gt;
&lt;br /&gt;
Although it may seem complicated, it is because it contains all possible cases, most of which are rather uncommon. In most cases you&#039;ll be writing code while not being into the scope of any low level lock, so you can do everything but call functions prefixed with IRQ or PK. When you are within an interrupt or take the GIL, the other most common case, you will usually not need to call any function besides the kernel API prefixed with IRQ.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|&lt;br /&gt;
| file related operations&lt;br /&gt;
| printf, scanf, cin, cout&lt;br /&gt;
| Thread::yield(), Thread::sleep(), usleep()&lt;br /&gt;
| call kernel functions with no prefix&lt;br /&gt;
| call kernel functions with PK prefix&lt;br /&gt;
| call kernel functions with IRQ prefix&lt;br /&gt;
| allocate memory&lt;br /&gt;
| throw C++ exceptions&lt;br /&gt;
| delayMs() and delayUs()&lt;br /&gt;
|-&lt;br /&gt;
| Normal code&lt;br /&gt;
| style=&amp;quot;background-color: #80ff80;&amp;quot; | Yes&lt;br /&gt;
| style=&amp;quot;background-color: #80ff80;&amp;quot; | Yes&lt;br /&gt;
| style=&amp;quot;background-color: #80ff80;&amp;quot; | Yes&lt;br /&gt;
| style=&amp;quot;background-color: #80ff80;&amp;quot; | Yes&lt;br /&gt;
| style=&amp;quot;background-color: #ff8080;&amp;quot; | No&lt;br /&gt;
| style=&amp;quot;background-color: #ff8080;&amp;quot; | No&lt;br /&gt;
| style=&amp;quot;background-color: #80ff80;&amp;quot; | Yes&lt;br /&gt;
| style=&amp;quot;background-color: #80ff80;&amp;quot; | Yes&lt;br /&gt;
| style=&amp;quot;background-color: #80ff80;&amp;quot; | Yes&lt;br /&gt;
|-&lt;br /&gt;
| Within a PauseKernelLock&lt;br /&gt;
| style=&amp;quot;background-color: #ff8080;&amp;quot; | No&lt;br /&gt;
| style=&amp;quot;background-color: #ff8080;&amp;quot; | No&lt;br /&gt;
| style=&amp;quot;background-color: #ff8080;&amp;quot; | No&lt;br /&gt;
| style=&amp;quot;background-color: #ff8080;&amp;quot; | No&lt;br /&gt;
| style=&amp;quot;background-color: #80ff80;&amp;quot; | Yes&lt;br /&gt;
| style=&amp;quot;background-color: #ff8080;&amp;quot; | No&lt;br /&gt;
| style=&amp;quot;background-color: #80ff80;&amp;quot; | Yes&lt;br /&gt;
| style=&amp;quot;background-color: #80ff80;&amp;quot; | Yes&lt;br /&gt;
| style=&amp;quot;background-color: #80ff80;&amp;quot; | Yes&lt;br /&gt;
|-&lt;br /&gt;
| Within an GlobalIrqLock&lt;br /&gt;
| style=&amp;quot;background-color: #ff8080;&amp;quot; | No&lt;br /&gt;
| style=&amp;quot;background-color: #ff8080;&amp;quot; | No&lt;br /&gt;
| style=&amp;quot;background-color: #ff8080;&amp;quot; | No&lt;br /&gt;
| style=&amp;quot;background-color: #ff8080;&amp;quot; | No&lt;br /&gt;
| style=&amp;quot;background-color: #ff8080;&amp;quot; | No&lt;br /&gt;
| style=&amp;quot;background-color: #80ff80;&amp;quot; | Yes&lt;br /&gt;
| style=&amp;quot;background-color: #ff8080;&amp;quot; | No **&lt;br /&gt;
| style=&amp;quot;background-color: #ff8080;&amp;quot; | No **&lt;br /&gt;
| style=&amp;quot;background-color: #80ff80;&amp;quot; | Yes&lt;br /&gt;
|-&lt;br /&gt;
| Within a FastGlobalIrqLock&lt;br /&gt;
| style=&amp;quot;background-color: #ff8080;&amp;quot; | No&lt;br /&gt;
| style=&amp;quot;background-color: #ff8080;&amp;quot; | No&lt;br /&gt;
| style=&amp;quot;background-color: #ff8080;&amp;quot; | No&lt;br /&gt;
| style=&amp;quot;background-color: #ff8080;&amp;quot; | No&lt;br /&gt;
| style=&amp;quot;background-color: #ff8080;&amp;quot; | No&lt;br /&gt;
| style=&amp;quot;background-color: #ffff80;&amp;quot; | Yes *&lt;br /&gt;
| style=&amp;quot;background-color: #ff8080;&amp;quot; | No&lt;br /&gt;
| style=&amp;quot;background-color: #ff8080;&amp;quot; | No&lt;br /&gt;
| style=&amp;quot;background-color: #80ff80;&amp;quot; | Yes&lt;br /&gt;
|-&lt;br /&gt;
| Within an interrupt service routine (taking FastGlobalLockFromIrq in the multicore case)&lt;br /&gt;
| style=&amp;quot;background-color: #ff8080;&amp;quot; | No&lt;br /&gt;
| style=&amp;quot;background-color: #ff8080;&amp;quot; | No&lt;br /&gt;
| style=&amp;quot;background-color: #ff8080;&amp;quot; | No&lt;br /&gt;
| style=&amp;quot;background-color: #ff8080;&amp;quot; | No&lt;br /&gt;
| style=&amp;quot;background-color: #ff8080;&amp;quot; | No&lt;br /&gt;
| style=&amp;quot;background-color: #ffff80;&amp;quot; | Yes *&lt;br /&gt;
| style=&amp;quot;background-color: #ff8080;&amp;quot; | No&lt;br /&gt;
| style=&amp;quot;background-color: #ff8080;&amp;quot; | No&lt;br /&gt;
| style=&amp;quot;background-color: #80ff80;&amp;quot; | Yes&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;nowiki&amp;gt;*&amp;lt;/nowiki&amp;gt; = Most IRQ-prefixed functions can be called both with interrupts disabled (either within an &#039;&#039;GlobalIrqLock&#039;&#039;, &#039;&#039;FastGlobalIrqLockLock&#039;&#039; or &#039;&#039;FastGlobalLockFromIrq&#039;&#039;) and within an interrupt routine. The only exception being &#039;&#039;IRQregisterIrq&#039;&#039; and &#039;&#039;IRQunregisterIrq&#039;&#039; which are used for registering/unregistering interrupts, that cannot be called from within an interrupt handler and forcedly require a &#039;&#039;GlobalIrqLock&#039;&#039;. Refer to the doxygen documentation of the individual function when unsure.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;nowiki&amp;gt;**&amp;lt;/nowiki&amp;gt; = USed to be possible from Miosix v1.61 to Miosix v2.81, no longer possible due to multicore support. Now that a core can take the GIL and another core the PK, we must enforce that taking both locks can only be done by first taking the PK and then &amp;quot;upgrading&amp;quot; to the GIL. Doing the reverse would cause deadlocks, and since malloc/new take the PK, it&#039;s no longer possible to first take the GIL and then malloc.&lt;br /&gt;
&lt;br /&gt;
[[Category:API]]&lt;/div&gt;</summary>
		<author><name>Fede.tft</name></author>
	</entry>
	<entry>
		<id>https://miosix.org/wiki/index.php?title=Synchronization_primitives&amp;diff=481</id>
		<title>Synchronization primitives</title>
		<link rel="alternate" type="text/html" href="https://miosix.org/wiki/index.php?title=Synchronization_primitives&amp;diff=481"/>
		<updated>2026-05-15T15:50:51Z</updated>

		<summary type="html">&lt;p&gt;Fede.tft: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Miosix provides synchronization primitives, both high and low level. High level synchronization primitives are standard mutexes and condition variables that are familiar to programmers of multithreaded applications. This page addresses in more detail the low level synchronization primitives which are Miosix-specific, and is most useful when developing low level code, especially device drivers, on Miosix.&lt;br /&gt;
&lt;br /&gt;
= High level synchronization primitives =&lt;br /&gt;
For what concerns high level synchronization primitives, Miosix provides the ususal mutexes and condition variables, accessible through three APIs:&lt;br /&gt;
* The C++11 classes such as &#039;&#039;std::thread&#039;&#039;, &#039;&#039;std::mutex&#039;&#039; and &#039;&#039;std::condition_variable&#039;&#039; through the C++ standard library&lt;br /&gt;
* The POSIX thread functions and opaque data types such as &#039;&#039;pthread_t&#039;&#039;, &#039;&#039;pthread_mutex_t&#039;&#039; and &#039;&#039;pthread_cond_t&#039;&#039; through the C standard library&lt;br /&gt;
* The native Miosix API which is the underlying implementation of all the other APIs. This is a C++ API including class &#039;&#039;Thread&#039;&#039; which is the actual Task Control Block (TCB) used by the scheduler, and classes &#039;&#039;Mutex&#039;&#039;, &#039;&#039;FastMutex&#039;&#039;, &#039;&#039;KernelMutex&#039;&#039; and &#039;&#039;ConditionVariable&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The use for these synchronization primitives is to protect data structures from concurrent access by multiple threads. These synchronization primitives are very easy to use, with almost no preconditions or special requirements, but cannot be used for more low-level tasks, such as synchronizing between threads and interrupt routines.&lt;br /&gt;
&lt;br /&gt;
Both the mutex and the condition variable are optimized for speed, for example a lock/unlock pair of function calls to an uncontended mutex take around 100 clock cycles on an architecture such as the Cortex-M. Recursive mutexes are supported, and so are mutexes with priority inheritance, as well as timed waits on condition variables.&lt;br /&gt;
&lt;br /&gt;
Just like the standard C++, RAII-style mutex locking is recommended also with the native API, through the provided &#039;&#039;Lock&amp;lt;T&amp;gt;&#039;&#039; and &#039;&#039;Unlock&amp;lt;T&amp;gt;&#039;&#039; classes. &lt;br /&gt;
Compare this example using directly the &#039;&#039;Mutex&#039;&#039; member functions&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;CPP&amp;quot;&amp;gt;&lt;br /&gt;
class Foo&lt;br /&gt;
{&lt;br /&gt;
    int x;&lt;br /&gt;
    Mutex m;&lt;br /&gt;
public:&lt;br /&gt;
    void decIfPositive()&lt;br /&gt;
    {&lt;br /&gt;
        m.lock();&lt;br /&gt;
        if(x&amp;lt;=0) return;&lt;br /&gt;
        x--;&lt;br /&gt;
        m.unlock();&lt;br /&gt;
    }&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As you can see, the code contains an error: the return in the middle of the function does not unlock the mutex, something that will likely cause problems.&lt;br /&gt;
&lt;br /&gt;
On the other hand, if a &#039;&#039;Lock&#039;&#039;&#039; is used&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;CPP&amp;quot;&amp;gt;&lt;br /&gt;
class Foo&lt;br /&gt;
{&lt;br /&gt;
    int x;&lt;br /&gt;
    Mutex m;&lt;br /&gt;
public:&lt;br /&gt;
    void decIfPositive()&lt;br /&gt;
    {&lt;br /&gt;
        Lock&amp;lt;Mutex&amp;gt; l(m);&lt;br /&gt;
        if(x&amp;lt;=0) return;&lt;br /&gt;
        x--;&lt;br /&gt;
    }&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
you don&#039;t have to worry about that. When considering that functions can return due to a propagation of a C++ exception, using locks is the only way to write exception-safe C++ code.&lt;br /&gt;
&lt;br /&gt;
If you need to temporarily unlock a mutex from within a scope where a &#039;&#039;Lock&#039;&#039; is in effect, this is made possible by creating an inner scope and using an &#039;&#039;Unlock&#039;&#039; object, like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;CPP&amp;quot;&amp;gt;&lt;br /&gt;
Mutex m;&lt;br /&gt;
{&lt;br /&gt;
    Lock&amp;lt;Mutex&amp;gt; l(m);&lt;br /&gt;
    //Now the Mutex is locked&lt;br /&gt;
    {&lt;br /&gt;
        Unlock&amp;lt;Mutex&amp;gt; u(l);&lt;br /&gt;
        //Now the mutex is unlocked&lt;br /&gt;
    }&lt;br /&gt;
    //Now the Mutex is again locked&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note how to create an &#039;&#039;Unlock&#039;&#039; object you have to pass a &#039;&#039;Lock&#039;&#039; to its constructor. This prevents you from trying to unlock a mutex you have not locked.&lt;br /&gt;
&lt;br /&gt;
For what concerns the &#039;&#039;ConditionVariable&#039;&#039; class, it provides the &#039;&#039;wait()&#039;&#039;, &#039;&#039;signal()&#039;&#039; and &#039;&#039;broadcast()&#039;&#039; member functions as you&#039;d expect. Moreover, there&#039;s an overload of &#039;&#039;wait()&#039;&#039; taking a &#039;&#039;Lock&#039;&#039; instead of a bare mutex for convenience.&lt;br /&gt;
&lt;br /&gt;
= Low level synchronization primitives =&lt;br /&gt;
&lt;br /&gt;
Miosix provides two low-level synchronization primitives, the GlobalIrqLock or &amp;quot;GIL&amp;quot; and the PauseKernelLock or &amp;quot;PK&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
== The GIL lock ==&lt;br /&gt;
&lt;br /&gt;
The GlobalIrqLock or &amp;quot;GIL&amp;quot;. On single core architectures, this lock disables interrupts and makes the code fragment taking this lock uninterruptible, not even by interrupt handlers. On multicore architectures, this lock disables interrupts on the core taking the lock, making the code fragment using it uninterruptible, not even by interrupt handlers. Additionally, only up to &#039;&#039;&#039;one&#039;&#039;&#039; core can take the GIL at any given time. If a second core attempts to take the GIL while another core has already taken it, it will block execution until the core holding the GIL has released it. Taking the GIL must be done using one of three [https://en.wikipedia.org/wiki/RAII RAII] C++ classes: &#039;&#039;GlobalIrqLock&#039;&#039;, which is recursive, thus allowing to take the lock multiple times, &#039;&#039;FastGlobalIrqLock&#039;&#039;, a faster but non-recursive version, or &#039;&#039;FastGlobalLockFromIrq&#039;&#039;, the only version that can be used to take the GIL from an interrupt handler (this version is not recursive).&lt;br /&gt;
&lt;br /&gt;
The GIL is used to implement device drivers that make use of interrupts, as well as inside the kernel, by the scheduler which also runs from inside an interrupt. Since both use the same lock, it&#039;s possible for an interrupt handler in a device driver to wakeup a thread from within an interrupt handler without corrupting the scheduler data structures.&lt;br /&gt;
&lt;br /&gt;
The reason why a regular mutex cannot be used for this purpose is because interrupts are by their very nature asymmetric. An interrupt can interrupt the code of a thread, but a thread cannot interrupt an interrupt. This means that when you&#039;re writing device drivers and you need to synchronize between an interrupt and normal code a mutex won&#039;t do the job. If the mutex is already locked when the interrupt code starts, trying to lock it within the interrupt will attempt to block the interrupt till the thread unlocks it, and as you can imagine, this won&#039;t end up well.&lt;br /&gt;
&lt;br /&gt;
To synchronize in such cases you have to temporarily disable interrupts from within your thread or main program, so that the thread and the interrupt won&#039;t try to access some data structure at the same time.&lt;br /&gt;
&lt;br /&gt;
There&#039;s nothing new in that, if you&#039;ve programmed microcontrollers before without an OS, you&#039;ve accustomed to disabling interrupts as a mean of synchronization. The only difference is that in multicore architectures, you&#039;ll have to remember to take the &#039;&#039;FastGlobalLockFromIrq&#039;&#039; also from within interrupt handlers before calling the scheduler API to wakeup tasks, as the scheduler could be running on another core causing a race condition. In single core architectures you don&#039;t technically need to put a &#039;&#039;FastGlobalLockFromIrq&#039;&#039; in interrupt handlers. If you do it will be optimized away as it&#039;s not required. Since there&#039;s no performance penalty, you may as well take the habit of always using &#039;&#039;FastGlobalLockFromIrq&#039;&#039;, just in case your driver gets reused in a multicore chip.&lt;br /&gt;
&lt;br /&gt;
Inside a critical section taking the GIL you should not call functions that cause a preemption, such as almost all high-level function form the C++ standard library (including &#039;&#039;printf()&#039;&#039; and filesystem-related functions). Also, the only functions that are part of the Miosix kernel API that are safe to be called with the GIL locked are prefixed with IRQ. Why IRQ and not GIL you may say? It&#039;s because of older version of the kernel, before multicore support was introduced.&lt;br /&gt;
&lt;br /&gt;
More importantly, all functions of the kernel that are prefixed with IRQ are &#039;&#039;&#039;only&#039;&#039;&#039; safe to be called if you&#039;re holding the GIL.&lt;br /&gt;
&lt;br /&gt;
Some functions have both an IRQ and non IRQ version, such as &#039;&#039;miosix::getTime()&#039;&#039; and miosix::IRQgetTime()&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
== The PK lock ==&lt;br /&gt;
The PauseKernelLock or &amp;quot;PK&amp;quot;. This lock disables preemption. This means that the code fragment taking the lock cannot be preempted by other threads, but can be interrupted by interrupts. On multicore architectures, only up to &#039;&#039;&#039;one&#039;&#039;&#039; core can take the PK at any given time. If a second core attempts to take the PK while another core has already taken it, it will block execution until the core holding the PK has released it. Note that on multicore architectures, it is allowed for one core can take the GIL, while another core can take the PK.&lt;br /&gt;
&lt;br /&gt;
If the time spent with preemption disabled exceeds the thread&#039;s timeslice a preemption will occur immediately when releasing the lock.&lt;br /&gt;
&lt;br /&gt;
Despite faster than a mutex, these synchronization primitives carry some heavy restrictions, and are mostly used to implement parts of the kernel itself. The main isssue is that you must never force a preemption when the kernel is paused. If this happens, the kernel will likely lock up badly. Of course, this means you can&#039;t call &#039;&#039;Thread::yield()&#039;&#039; when the kernel is paused, but there are many more subtler ways to cause a preemption.&lt;br /&gt;
&lt;br /&gt;
In general, inside a critical section taking the GIL you should not call functions that cause a preemption, such as almost all high-level function form the C++ standard library (including &#039;&#039;printf()&#039;&#039;, &#039;&#039;&#039;malloc()/new&#039;&#039;&#039; and filesystem-related functions). Also, the only functions that are part of the Miosix kernel API that are safe to be called with the PK locked are prefixed with PK.&lt;br /&gt;
&lt;br /&gt;
All in all, you won&#039;t find much need to use the PK synchronization primitive, unless you&#039;re writing kernel code. At that point, you&#039;ll find it useful. Miosix uses it internally to make regular mutexes and condition variables work.&lt;br /&gt;
&lt;br /&gt;
== Summarizing it all ==&lt;br /&gt;
The following table summarizes what you can do depending on what low level synchronization primitive you are using, as well as when you are writing the code of an interrupt service routine.&lt;br /&gt;
&lt;br /&gt;
Although it may seem complicated, it is because it contains all possible cases, most of which are rather uncommon. In most cases you&#039;ll be writing code while not being into the scope of any low level lock, so you can do everything but call functions prefixed with IRQ or PK. When you are within an interrupt or inside a lock to disable interrupts, the other most common case, you will usually not need to call any function, but just modify some of your own data structures.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|&lt;br /&gt;
| file related operations&lt;br /&gt;
| printf, scanf, cin, cout&lt;br /&gt;
| Thread::yield(), Thread::sleep(), usleep()&lt;br /&gt;
| call kernel functions with no prefix&lt;br /&gt;
| call kernel functions with PK prefix&lt;br /&gt;
| call kernel functions with IRQ prefix&lt;br /&gt;
| allocate memory&lt;br /&gt;
| throw C++ exceptions&lt;br /&gt;
| delayMs() and delayUs()&lt;br /&gt;
|-&lt;br /&gt;
| Normal code&lt;br /&gt;
| style=&amp;quot;background-color: #80ff80;&amp;quot; | Yes&lt;br /&gt;
| style=&amp;quot;background-color: #80ff80;&amp;quot; | Yes&lt;br /&gt;
| style=&amp;quot;background-color: #80ff80;&amp;quot; | Yes&lt;br /&gt;
| style=&amp;quot;background-color: #80ff80;&amp;quot; | Yes&lt;br /&gt;
| style=&amp;quot;background-color: #ff8080;&amp;quot; | No&lt;br /&gt;
| style=&amp;quot;background-color: #ff8080;&amp;quot; | No&lt;br /&gt;
| style=&amp;quot;background-color: #80ff80;&amp;quot; | Yes&lt;br /&gt;
| style=&amp;quot;background-color: #80ff80;&amp;quot; | Yes&lt;br /&gt;
| style=&amp;quot;background-color: #80ff80;&amp;quot; | Yes&lt;br /&gt;
|-&lt;br /&gt;
| Within a PauseKernelLock&lt;br /&gt;
| style=&amp;quot;background-color: #ff8080;&amp;quot; | No&lt;br /&gt;
| style=&amp;quot;background-color: #ff8080;&amp;quot; | No&lt;br /&gt;
| style=&amp;quot;background-color: #ff8080;&amp;quot; | No&lt;br /&gt;
| style=&amp;quot;background-color: #ff8080;&amp;quot; | No&lt;br /&gt;
| style=&amp;quot;background-color: #80ff80;&amp;quot; | Yes&lt;br /&gt;
| style=&amp;quot;background-color: #ff8080;&amp;quot; | No&lt;br /&gt;
| style=&amp;quot;background-color: #80ff80;&amp;quot; | Yes&lt;br /&gt;
| style=&amp;quot;background-color: #80ff80;&amp;quot; | Yes&lt;br /&gt;
| style=&amp;quot;background-color: #80ff80;&amp;quot; | Yes&lt;br /&gt;
|-&lt;br /&gt;
| Within an InterruptDisableLock&lt;br /&gt;
| style=&amp;quot;background-color: #ff8080;&amp;quot; | No&lt;br /&gt;
| style=&amp;quot;background-color: #ff8080;&amp;quot; | No&lt;br /&gt;
| style=&amp;quot;background-color: #ff8080;&amp;quot; | No&lt;br /&gt;
| style=&amp;quot;background-color: #ff8080;&amp;quot; | No&lt;br /&gt;
| style=&amp;quot;background-color: #ff8080;&amp;quot; | No&lt;br /&gt;
| style=&amp;quot;background-color: #ffff80;&amp;quot; | Yes *&lt;br /&gt;
| style=&amp;quot;background-color: #80ff80;&amp;quot; | Yes **&lt;br /&gt;
| style=&amp;quot;background-color: #80ff80;&amp;quot; | Yes **&lt;br /&gt;
| style=&amp;quot;background-color: #80ff80;&amp;quot; | Yes&lt;br /&gt;
|-&lt;br /&gt;
| Within a FastInterruptDisableLock&lt;br /&gt;
| style=&amp;quot;background-color: #ff8080;&amp;quot; | No&lt;br /&gt;
| style=&amp;quot;background-color: #ff8080;&amp;quot; | No&lt;br /&gt;
| style=&amp;quot;background-color: #ff8080;&amp;quot; | No&lt;br /&gt;
| style=&amp;quot;background-color: #ff8080;&amp;quot; | No&lt;br /&gt;
| style=&amp;quot;background-color: #ff8080;&amp;quot; | No&lt;br /&gt;
| style=&amp;quot;background-color: #ffff80;&amp;quot; | Yes *&lt;br /&gt;
| style=&amp;quot;background-color: #ff8080;&amp;quot; | No&lt;br /&gt;
| style=&amp;quot;background-color: #ff8080;&amp;quot; | No&lt;br /&gt;
| style=&amp;quot;background-color: #80ff80;&amp;quot; | Yes&lt;br /&gt;
|-&lt;br /&gt;
| Within an interrupt service routine&lt;br /&gt;
| style=&amp;quot;background-color: #ff8080;&amp;quot; | No&lt;br /&gt;
| style=&amp;quot;background-color: #ff8080;&amp;quot; | No&lt;br /&gt;
| style=&amp;quot;background-color: #ff8080;&amp;quot; | No&lt;br /&gt;
| style=&amp;quot;background-color: #ff8080;&amp;quot; | No&lt;br /&gt;
| style=&amp;quot;background-color: #ff8080;&amp;quot; | No&lt;br /&gt;
| style=&amp;quot;background-color: #ffff80;&amp;quot; | Yes *&lt;br /&gt;
| style=&amp;quot;background-color: #ff8080;&amp;quot; | No&lt;br /&gt;
| style=&amp;quot;background-color: #ff8080;&amp;quot; | No&lt;br /&gt;
| style=&amp;quot;background-color: #80ff80;&amp;quot; | Yes&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;nowiki&amp;gt;*&amp;lt;/nowiki&amp;gt; = Most IRQ-prefixed functions can be called both with interrupts disabled (either within an &#039;&#039;InterruptDisableLock&#039;&#039; or &#039;&#039;FastInterruptDisableLock&#039;&#039;) and within an interrupt routine. A few of them can only be called with interrupts disabled but not within an interrupt routine, and one of them, &#039;&#039;IRQfindNextThread()&#039;&#039; which is the scheduler, can only be called inside an interrupt routine but not with interrupts disabled. Refer to the doxygen documentation of the individual function when unsure.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;nowiki&amp;gt;**&amp;lt;/nowiki&amp;gt; = Starting from Miosix v1.61&lt;br /&gt;
&lt;br /&gt;
[[Category:API]]&lt;/div&gt;</summary>
		<author><name>Fede.tft</name></author>
	</entry>
	<entry>
		<id>https://miosix.org/wiki/index.php?title=GPIO_tutorial&amp;diff=480</id>
		<title>GPIO tutorial</title>
		<link rel="alternate" type="text/html" href="https://miosix.org/wiki/index.php?title=GPIO_tutorial&amp;diff=480"/>
		<updated>2026-05-15T15:08:39Z</updated>

		<summary type="html">&lt;p&gt;Fede.tft: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Include statements and namespace required to use this library&lt;br /&gt;
&amp;lt;source lang=&amp;quot;CPP&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;miosix.h&amp;gt;&lt;br /&gt;
using namespace miosix;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
This is a C++ library, it cannot be used from a C source file.&lt;br /&gt;
&lt;br /&gt;
A [https://en.wikipedia.org/wiki/GPIO GPIO] or general purpose input-output is a software-controllable pin of a microcontroller. To be able to control multiple GPIOs at the same time, most microcontrollers group GPIOs in ports, so GPIOs are specified by a port name, and a pin number within the port. The STM32 use letters to identify ports, so the GPIO 0 of port A is called PA0. The GPIO port and number are often specified at the pin headers on development boards such as the [[stm32f407vg_stm32f4discovery|STM32F4 Discovery]], in order to make it easy to connect wires to the correct GPIO. On the contrary, NXP uses numbers also for the ports, so the GPIO 0 of port 1 is called P1.0.&lt;br /&gt;
&lt;br /&gt;
== Declaring GPIOs ==&lt;br /&gt;
&lt;br /&gt;
A GPIO in Miosix is accessed using a C++ template class, the rationale behind this choice can be found [http://www.webalice.it/fede.tft/stm32/stm32_gpio_and_template_metaprogramming.html in this article], but in short it provides both optimal performance and a high-level API.&lt;br /&gt;
&lt;br /&gt;
As an example, assume there is a blue LED connected to GPIO PD15 and a button connected to PA0, to control them in software you first have to declare the GPIOs using the following syntax&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;CPP&amp;quot;&amp;gt;&lt;br /&gt;
using blueLed=Gpio&amp;lt;PD,15&amp;gt;;&lt;br /&gt;
using button=Gpio&amp;lt;PA,0&amp;gt;;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A declaration like this can appear both inside a function, if you are going to use the GPIO only inside that function, or be put at the top of a source file, to access the GPIO from all the functions of that file. It ca also appear in a header, allowing to &#039;&#039;#include&#039;&#039; GPIO definitions in multiple source files. Notice how PD means that this is a GPIO of port D, and 15 is the GPIO number within the port. This declaration introduces a template named blueLed that can later be used to access the GPIO.&lt;br /&gt;
&lt;br /&gt;
A common mistake is to declare the GPIO like this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;CPP&amp;quot;&amp;gt;&lt;br /&gt;
/* DON&#039;T WRITE CODE LIKE THIS */&lt;br /&gt;
using pd15=Gpio&amp;lt;GPIOD_BASE,15&amp;gt;;&lt;br /&gt;
using pa0=Gpio&amp;lt;GPIOA_BASE,0&amp;gt;;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
While the following code will work, it is discouraged to choose the GPIO name as just the port and number. It is way better to try using a name related to the function that the GPIO will be used for, as it leads to code that is easier to read and understand. For example, the first GPIO is connected to a blue LED, so blueLed is an appropriate name.&lt;br /&gt;
&lt;br /&gt;
== Configuring GPIOs ==&lt;br /&gt;
&lt;br /&gt;
Once you have declared a GPIO, you need to to configure it before using it. The most basic level of configuration is to select the GPIO &#039;&#039;direction&#039;&#039;, i.e, whether it is going to be used as an output, or an input.&lt;br /&gt;
&lt;br /&gt;
If a GPIO is configured as an output software can control the voltage at that pin, by selecting between a logic level 0, which corresponds to 0V, or a logic 1, whose voltage is VDD, which is the voltage used to power the microcontroller, in most cases 3.3V for the typical microcontrollers supported by Miosix.&lt;br /&gt;
&lt;br /&gt;
If a GPIO is configured as an input, software can sense the logic level at the pin, reading a logic level 0 if the voltage is close to 0V, or a logic 1 if it is close to VDD. Note that if the voltage is closed to hald of VDD, or if the GPIO is not connected to anything, the reading could be either 0 or 1, see the discussion about [https://en.wikipedia.org/wiki/Pull-up_resistor pull-up resistors] on Wikipedia for that.&lt;br /&gt;
&lt;br /&gt;
To configure the GPIO you can use the &#039;&#039;mode()&#039;&#039; member function of the GPIO class. For example, in your &#039;&#039;main()&#039;&#039; function you can do&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;CPP&amp;quot;&amp;gt;&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
    blueLed::mode(Mode::OUTPUT);&lt;br /&gt;
    button::mode(Mode::INPUT);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that all boards supported by Miosix have the &#039;&#039;OUTPUT&#039;&#039; and &#039;&#039;INPUT&#039;&#039; modes, but may have more options.&lt;br /&gt;
&lt;br /&gt;
Some for example, may have software controllable on-chip pull-up and/or pull-down resistors, or an analog input mode connected to an ADC to read analog voltages. The list of supported modes can be found in the gpio_impl.h file of your microcontroller. For example, for the STM32F4 chips, the file is in [https://github.com/fedetft/miosix-kernel/blob/master/miosix/arch/drivers/gpio/stm32_gpio.h miosix/arch/drivers/gpio/stm32_gpio.h].&lt;br /&gt;
&lt;br /&gt;
A noteworty example is the ALTERNATE function mode, that when selected connects the GPIO to some device-dependent hardware peripheral, such as an SPI, I2C or UART peripheral. In such a case, the pin stops being a GPIO in the sense that it is no longer software controllable, but is instead driven by the hardware peripheral. This is often used to implement communication protocols like SPI or I2C.&lt;br /&gt;
&lt;br /&gt;
However, these device-specific extensions are not discussed further here.&lt;br /&gt;
&lt;br /&gt;
== GPIO Writing ==&lt;br /&gt;
&lt;br /&gt;
To write to an OUTPUT configured GPIO, you can used the &#039;&#039;high()&#039;&#039; and &#039;&#039;low()&#039;&#039; member functions, as shown in this example that blinks a LED&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;CPP&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;thread&amp;gt;&lt;br /&gt;
#include &amp;lt;miosix.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
using namespace std;&lt;br /&gt;
using namespace miosix;&lt;br /&gt;
&lt;br /&gt;
using blueLed=Gpio&amp;lt;GPIOD_BASE,15&amp;gt;;&lt;br /&gt;
&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
    blueLed::mode(Mode::OUTPUT);&lt;br /&gt;
    for(;;)&lt;br /&gt;
    {&lt;br /&gt;
        blueLed::high();    //Turn the LED on&lt;br /&gt;
        this_thread::sleep_for(500ms);&lt;br /&gt;
        blueLed::low();     //Turn the LED off&lt;br /&gt;
        this_thread::sleep_for(500ms);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== GPIO Reading ==&lt;br /&gt;
&lt;br /&gt;
Reading from an INPUT configured GPIO is performed by using the &#039;&#039;value()&#039;&#039; member function, as shown in this example that polls a button every 10ms and turns on a LED for 10 seconds once it detects it is pressed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;CPP&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;thread&amp;gt;&lt;br /&gt;
#include &amp;lt;miosix.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
using namespace std;&lt;br /&gt;
using namespace miosix;&lt;br /&gt;
&lt;br /&gt;
using blueLed=Gpio&amp;lt;GPIOD_BASE,15&amp;gt;;&lt;br /&gt;
using button=Gpio&amp;lt;GPIOA_BASE,0&amp;gt;;&lt;br /&gt;
&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
    blueLed::mode(Mode::OUTPUT);&lt;br /&gt;
    button::mode(Mode::INPUT);&lt;br /&gt;
    for(;;)&lt;br /&gt;
    {&lt;br /&gt;
        //Poll the button every 10ms until it is pressed&lt;br /&gt;
        while(button::value()==0)  this_thread::sleep_for(10ms);&lt;br /&gt;
&lt;br /&gt;
        blueLed::high();      //Turn the LED on&lt;br /&gt;
        this_thread::sleep_for(10s);&lt;br /&gt;
        blueLed::low();       //Turn the LED off&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A common mistake is to forget the sleep when polling for the button, resulting in a code like this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;CPP&amp;quot;&amp;gt;&lt;br /&gt;
/* DON&#039;T WRITE CODE LIKE THIS */&lt;br /&gt;
for(;;)&lt;br /&gt;
{&lt;br /&gt;
    //Poll the button until it is pressed&lt;br /&gt;
    while(button::value()==0) ;&lt;br /&gt;
&lt;br /&gt;
    blueLed::high();      //Turn the LED on&lt;br /&gt;
    Thread::sleep(10000); //Wait 10s&lt;br /&gt;
    blueLed::low();       //Turn the LED off&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Although this code will work, it is bad. To see why, consider that Miosix is a multithreaded OS, so in the general case there will be other threads running other than your code, so it is not polite to spin in a while loop that may take an undefined time to complete chewing up 100% of the CPU. This will for sure prevent the kernel from putting the CPU in sleep resulting in a higher power consumption, and may slow down other threads that can have more important tasks to do than spinning on a GPIO.&lt;br /&gt;
&lt;br /&gt;
But you may be thinking that your application needs to be notified of the button being pressed &#039;&#039;as soon as possible&#039;&#039; and even a few milliseconds of delay are too much. In this case, this code is &#039;&#039;&#039;even more wrong&#039;&#039;&#039;, because Miosix is a timesharing system, so your code can and will be preempted by the operating system to prevent other threads from starving. If the event that you need to be notified about happens while your code is preempted, there will be a delay of up to a few milliseconds between the actual event and when you notice it anyway.&lt;br /&gt;
&lt;br /&gt;
To deal with situations where you need to be notified of pin change events events as soon as possible you need something more complicated, such as an [[Interrupt on pin change]] that will call an interrupt routine in response to an event, usually offering a time determinism of a few tens of microseconds, or a [[Timer input capture]] channel that provides a timestamp of an event with an accuracy of a few tens of nanoseconds.&lt;br /&gt;
&lt;br /&gt;
== Thread safety considerations ==&lt;br /&gt;
&lt;br /&gt;
All microcontroller, for self-evident reasons, provide hardware support to allow writing to GPIOs configured as OUTPUT in a thread-safe way, so you are free to call the &#039;&#039;high()&#039;&#039; and &#039;&#039;low()&#039;&#039; (and &#039;&#039;value()&#039;&#039; as well) from multiple threads.&lt;br /&gt;
&lt;br /&gt;
Unfortunately, configuring GPIOs is on most microcontrollers not thread-safe. That is, if you call &#039;&#039;mode()&#039;&#039; concurrently from multiple threads on the same GPIO port, you may inadvertently misconfigure some of the pins in that port.&lt;br /&gt;
&lt;br /&gt;
There are two ways to work around that, configuring all GPIOs in the &#039;&#039;main()&#039;&#039; before spawning any thread, and disabling interrupts while configuring GPIOs.&lt;br /&gt;
&lt;br /&gt;
=== Configuring GPIOs in the main() ===&lt;br /&gt;
&lt;br /&gt;
If you configure all the GPIOs in the &#039;&#039;main()&#039;&#039;, before spawning any thread, and later you no longer call &#039;&#039;mode()&#039;&#039; there are no way two threads could call &#039;&#039;mode()&#039;&#039; concurrently, and so there is no problem. However, this often goes against code modularity, and in some circumstances you may need to change a GPIO configuration at runtime.&lt;br /&gt;
&lt;br /&gt;
=== Disabling interrupts while configuring GPIOs ===&lt;br /&gt;
&lt;br /&gt;
To allow &#039;&#039;mode()&#039;&#039; to be freely called, you have to make sure no two concurrent calls to &#039;&#039;mode()&#039;&#039; can happen. Considering that configuring a GPIO is a very fast operation, it requires just a few clock cycles, this can be achieved by disabling interrupts while configuring the GPIOs. Keep in mind that disabling interrupts must be done with care, and striving as much as possible to minimize the amount of time spent with interrupts disabled, so as not to interfere with the real-time capabilities of the Miosix kernel.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;CPP&amp;quot;&amp;gt;&lt;br /&gt;
void someFunction()&lt;br /&gt;
{&lt;br /&gt;
    [...] //Some code&lt;br /&gt;
&lt;br /&gt;
    {&lt;br /&gt;
        FastGlobalIrqLock dLock;&lt;br /&gt;
        blueLed::mode(Mode::OUTPUT);&lt;br /&gt;
        button::mode(Mode::INPUT);&lt;br /&gt;
    }&lt;br /&gt;
   &lt;br /&gt;
    [...] //Some other code&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note the two curly braces surrounding the dLock object, that create a [https://en.wikipedia.org/wiki/Scope_%28computer_science%29 scope] delimiting the lines of code where interrupts are disabled.&lt;br /&gt;
&lt;br /&gt;
As a last note, you could also use a global [https://en.wikipedia.org/wiki/Mutex mutex] instead of disabling interrupts, but as previously mentioned configuring a GPIO is a very fast operation, it requires just a few clock cycles, so using a mutex would introduce more overhead.&lt;br /&gt;
&lt;br /&gt;
== Accessing GPIOs from multiple source files ==&lt;br /&gt;
&lt;br /&gt;
When dealing with large projects, it is common to split them in multiple source files. To access the GPIO definitions from multiple source files it is common practice in Miosix to declare them in a C++ header file, and &#039;&#039;#include&#039;&#039; it where needed. If that file contains all the GPIOs of a specific board, is is often called &#039;&#039;hwmapping.h&#039;&#039;. In such a case, [https://en.wikipedia.org/wiki/Namespace#Examples namespaces] can be used to group GPIOs by function. For an example, see the &#039;&#039;hwmapping.h&#039;&#039; file for the Sony smartwatch board [https://github.com/fedetft/miosix-kernel/blob/master/miosix/arch/board/stm32f205rg_sony-newman/interfaces-impl/hwmapping.h miosix/arch/board/stm32f205rg_sony-newman/interfaces-impl/hwmapping.h].&lt;br /&gt;
&lt;br /&gt;
== Related pages ==&lt;br /&gt;
* [[Example: Blinking led|Blinking led]]&lt;br /&gt;
&lt;br /&gt;
[[Category:API]]&lt;/div&gt;</summary>
		<author><name>Fede.tft</name></author>
	</entry>
	<entry>
		<id>https://miosix.org/wiki/index.php?title=Miosix_and_git_workflow&amp;diff=479</id>
		<title>Miosix and git workflow</title>
		<link rel="alternate" type="text/html" href="https://miosix.org/wiki/index.php?title=Miosix_and_git_workflow&amp;diff=479"/>
		<updated>2026-05-15T14:52:00Z</updated>

		<summary type="html">&lt;p&gt;Fede.tft: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
= The Miosix git repository =&lt;br /&gt;
&lt;br /&gt;
Miosix uses the git version control system to manage the kernel source code. To download and use the kernel you have to clone its git repository. The main Miosix git repository is hosted on this website, miosix.org, but we have no web page where you can browse the kernel sources. For this, we use a [https://github.com/fedetft/miosix-kernel github mirror] and the two repositories will be always kept in sync.&lt;br /&gt;
&lt;br /&gt;
As the kernel is under active development, users are advised to periodically &#039;&#039;git fetch&#039;&#039; or check the [https://github.com/fedetft/miosix-kernel kernel page on github] to look for new features and bug fixes, and pull the changes if required.&lt;br /&gt;
&lt;br /&gt;
Cloning the kernel repository from miosix.org can be done with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git clone https://miosix.org/git-public/miosix-kernel.git&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
While cloning the github mirror with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git clone https://github.com/fedetft/miosix-kernel.git&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Branches ==&lt;br /&gt;
&lt;br /&gt;
By default, when cloning a repository, git will download the &#039;&#039;master&#039;&#039; branch. Miosix offers two additional branches, &#039;&#039;testing&#039;&#039; and &#039;&#039;unstable&#039;&#039;, and you should be aware of the conventions we use for how we manage branches:&lt;br /&gt;
* The &#039;&#039;master&#039;&#039; branch contains the stable kernel, it is updated infrequently, usually once a year when a new release is made. Sometimes, a few minor releases are updated in short order.&lt;br /&gt;
* The &#039;&#039;testing&#039;&#039; branch contains the in-development code that we consider almost ready. Use this branch to get more bleeding edge features.&lt;br /&gt;
* The &#039;&#039;unstable&#039;&#039; branch is where the Miosix development team is working. It&#039;s meant to be used only by people in contact with the development team, as we occasionally rebase and force-push changes, so you may have a hard time keeping your git repository in sync with ours (the commit you downloaded today may no longer exist after a force push). If you&#039;re writing applications, it&#039;s best to ignore this branch and wait for the desired change to trickle to testing.&lt;br /&gt;
&lt;br /&gt;
To checkout a specific branch, once you have cloned the git repository, use the following command&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
cd miosix-kernel&lt;br /&gt;
git checkout testing&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Using Miosix in your projects =&lt;br /&gt;
&lt;br /&gt;
The rest of this page explains how to set up a software project making use of the Miosix kernel. There are basically two ways to do so:&lt;br /&gt;
&lt;br /&gt;
* Using out of git tree projects: this is the suggested workflow for developing applications using Miosix. Your application directory (and optionally git repo) stay separate from the kernel directory and git repo. The kernel can be a git submodule of your project.&lt;br /&gt;
* Forking the Miosix kernel git repository. This is the suggested workflow for extending the kernel, such as adding new board support packages (BSPs).&lt;br /&gt;
&lt;br /&gt;
The two workflows can be combined, for example you may want to fork the kernel to add your BSPs, and then use the forked kernel as submodule for developing your applications.&lt;br /&gt;
&lt;br /&gt;
= Out of git tree projects =&lt;br /&gt;
&lt;br /&gt;
Out of git tree projects allow you to write applications in a directory that stays separate from the Miosix kernel directory. When we say &#039;&#039;out of git tree&#039;&#039;, we mean that your project is developed outside of the &#039;&#039;Miosix&#039;&#039; git tree. Your project can be a git repository too, but that is up to you to decide.&lt;br /&gt;
&lt;br /&gt;
Additionally, a key part of an out of git tree project is that it allows to perform the kernel configuration (that requires editing configuration files) without the need to make changes to files within the Miosix git repo &#039;&#039;at all&#039;&#039;. This last point is important both to have the Miosix git repository as a [http://www.git-scm.com/book/en/Git-Tools-Submodules git submodule] of your application&#039;s git repository, and to allow sharing the same downloaded copy of the Miosix kernel across different applications, each with its own configuration. The kernel source code size on the hard drive has grown bigger in recent years due to the inclusion of headers with peripheral registers definitions in the [https://github.com/fedetft/miosix-kernel/tree/master/miosix/arch/CMSIS CMSIS] directory, so you may want to share a single downloaded copy of the kernel across several projects.&lt;br /&gt;
&lt;br /&gt;
Note that the ability to develop applications without making changes to the kernel directory is currently limited to the use case of configuring the kernel for one of the available BSPs. If you need to add BSPs to the kernel, then you&#039;ll most likely also have to fork the kernel repository. The &#039;&#039;most likely&#039;&#039; is due to &#039;&#039;generic&#039;&#039; BSPs in the kernel, which can be identified in the list of boards in [https://github.com/fedetft/miosix-kernel/blob/master/miosix/config/Makefile.inc Makefile.inc] as &#039;&#039;&amp;lt;chip name&amp;gt;_generic&#039;&#039; such as  &#039;&#039;stm32f103xb_generic&#039;&#039;. If you&#039;re writing an application for a board that has a chip with a generic BSP in the kernel, you can (unless you &#039;&#039;really&#039;&#039; need to run some custom code during boot) get away with selecting the generic BSP without forking the kernel. If there&#039;s no generic BSP for your chip, or need to add support for an entirely new chip, then you&#039;ll have to fork the kernel to add it.&lt;br /&gt;
&lt;br /&gt;
== Organizing your out of git tree projects ==&lt;br /&gt;
&lt;br /&gt;
For an out of git tree project, you need to create a directory in your computer that will contain your project. The &#039;&#039;miosix-kernel&#039;&#039; directory (and git repo) can either be a subdirectory of your project&#039;s directory (common option when adding the Miosix kernel as a git submodule to your project):&lt;br /&gt;
&lt;br /&gt;
[[File:Out-of-tree-subdirectory.png]]&lt;br /&gt;
&lt;br /&gt;
Or you can organize your projects side by side to the kernel (common when sharing a single kernel among multiple projects):&lt;br /&gt;
&lt;br /&gt;
[[File:Out-of-tree-shared.png]]&lt;br /&gt;
&lt;br /&gt;
The only constraint (it&#039;s a limitation in the Makefile build systems), is that the &#039;&#039;relative&#039;&#039; path from your project directory to the kernel should not contain spaces. This practically means that you should not give your project directories names with spaces.&lt;br /&gt;
&lt;br /&gt;
== Adding Miosix as a submodule to your git project == &lt;br /&gt;
&lt;br /&gt;
Suppose you have a git repository called myapplication, which is the repo of your application, and you would like to download the miosix-kernel repository as a git submodule. Then open a shell in the test repository and type:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git submodule init&lt;br /&gt;
git submodule add https://miosix.org/git-public/miosix-kernel.git miosix-kernel&lt;br /&gt;
git commit -m &amp;quot;Added miosix-kernel as a git submodule&amp;quot;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Initializing an out of git tree project ==&lt;br /&gt;
&lt;br /&gt;
Using out of git tree projects implies having a build system in your project directory that can both compile the source code of your application and the Miosix kernel. Miosix provides two build systems, Makefiles and [[CMake]]. In this tutorial we&#039;ll use Makefiles.&lt;br /&gt;
&lt;br /&gt;
Miosix projects start from a template that you can find in the &#039;&#039;miosix-kernel/templates&#039;&#039; directory. You can copy the template yourself from the kernel source tree to your project directory, but in that case, you&#039;ll need to fix the relative paths in the build system. Alternatively, you can use the &#039;&#039;init_project_out_of_git_tree.pl&#039;&#039; script to initialize a project.&lt;br /&gt;
&lt;br /&gt;
Additionally, the kernel configuration directory needs to be copied to your project. This is necessary because you&#039;ll need to make changes to those files to select kernel build options, at minimum which board you want to compile the kernel for.&lt;br /&gt;
As you may know, git submodules work well if you never make changes in the submodule directory, otherwise you will have to basically fork the submodule, or you will find yourself making changes to a repository in a detached head state and risk losing them at the next git pull.&lt;br /&gt;
For this reason, we&#039;ll copy the config directory to your project and make changes there. The &#039;&#039;init_project_out_of_git_tree.pl&#039;&#039; performs also this action for you.&lt;br /&gt;
&lt;br /&gt;
=== Initialize a project using &#039;&#039;init_project_out_of_git_tree.pl&#039;&#039; ===&lt;br /&gt;
&lt;br /&gt;
Just open a shell in your project directory and invoke the perl script in the kernel:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=bash&amp;gt;&lt;br /&gt;
perl &amp;lt;path to the kernel&amp;gt;tools/init_project_out_of_git_tree.pl&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus for the case when the kernel is a subdirectory of your project that would be:&lt;br /&gt;
&amp;lt;source lang=bash&amp;gt;&lt;br /&gt;
perl miosix-kernel/tools/init_project_out_of_git_tree.pl&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
While for the side-by-side case:&lt;br /&gt;
&amp;lt;source lang=bash&amp;gt;&lt;br /&gt;
perl ../miosix-kernel/tools/init_project_out_of_git_tree.pl&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that you have to run the script without moving the current directory away from the one of your project. This means you can&#039;t &#039;&#039;cd&#039;&#039; to the &#039;&#039;miosix-kernel/tools&#039;&#039; directory, run the script there, and then &#039;&#039;cd&#039;&#039; back. The script withes the project files to the current directory it&#039;s been invoked from.&lt;br /&gt;
&lt;br /&gt;
If all goes well you&#039;ll get a message similar to:&lt;br /&gt;
&amp;lt;source lang=bash&amp;gt;&lt;br /&gt;
Successfully created Miosix project&lt;br /&gt;
Target directory: myapplication&lt;br /&gt;
Kernel directory: myapplication/miosix-kernel/miosix&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and your project should now contain the &#039;&#039;config&#039;&#039; directory and the &#039;&#039;main.cpp&#039;&#039;, &#039;&#039;Makefile&#039;&#039; and &#039;&#039;CMakeLists.txt&#039;&#039; files.&lt;br /&gt;
&lt;br /&gt;
From there, you&#039;ll need to edit the configuration as desired, and start building your application starting from &#039;&#039;main.cpp&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
=== Manually copying a template ===&lt;br /&gt;
&lt;br /&gt;
The perl script is convienient, but not necessary. It&#039;s possible to do the configuration manually by copying and editing files.&lt;br /&gt;
&lt;br /&gt;
To do so, there are 3 steps involved.&lt;br /&gt;
&lt;br /&gt;
First, copy the &#039;&#039;miosix-kernel/miosix/config&#039;&#039; directory to your project.&lt;br /&gt;
&lt;br /&gt;
Second, copy a template form the &#039;&#039;miosix-kernel/templates&#039;&#039; directory to your project. The &#039;&#039;simple&#039;&#039; template configures the kernel as a unikernel and will run your application in kernelspace. The &#039;&#039;processes&#039;&#039; template will allow you to develop (part of) your application in a userspace process with memory protection, bu that&#039;s a more advanced topic realted to the [[fliod kernel]] concept.&lt;br /&gt;
&lt;br /&gt;
You shouldn&#039;t copy the template directory, rather its content, so the &#039;&#039;main.cpp&#039;&#039;, &#039;&#039;Makefile&#039;&#039; and &#039;&#039;CMakeLists.txt&#039;&#039; files in the case of the &#039;&#039;simple&#039;&#039; template.&lt;br /&gt;
&lt;br /&gt;
Third and final step, you should edit the build system to point to the correct kernel and config directory. This step was done automatically by the perl script, in this case you&#039;ll have to do it manually.&lt;br /&gt;
&lt;br /&gt;
Open the &#039;&#039;Makefile&#039;&#039; file, and edit the following lines:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=bash&amp;gt;&lt;br /&gt;
KPATH := ../../miosix&lt;br /&gt;
CONFPATH := $(KPATH)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first line, defining the KPATH variable should be assigned to the relative path from your project directory to the kernel directory. If your &#039;&#039;miosix-kernel&#039;&#039; is a subdirectory of your project that should be:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=bash&amp;gt;&lt;br /&gt;
KPATH := miosix-kernel/miosix&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The second line defines the CONFPATH variable, and since you want to the kernel to find the &#039;&#039;config&#039;&#039; directory in your project , and &#039;&#039;&#039;not&#039;&#039;&#039; the one in the &#039;&#039;miosix-kernel/miosix/config&#039;&#039; directory, you&#039;ll have to chege it to the current directory, or &#039;&#039;.&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=bash&amp;gt;&lt;br /&gt;
CONFPATH := .&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally, open &#039;&#039;CMakeLists.txt&#039;&#039;. Also in this case you&#039;ll have to tell it where is the kernel directory, and to use the &#039;&#039;config&#039;&#039; directory in your project. The kernel directory is specified by replacing:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=bash&amp;gt;&lt;br /&gt;
set(MIOSIX_KPATH ${CMAKE_SOURCE_DIR}/../../miosix)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=bash&amp;gt;&lt;br /&gt;
set(MIOSIX_KPATH ${CMAKE_SOURCE_DIR}/miosix-kernel/miosix)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Whiel to tell CMake to use the config directory in your project, uncomment the following line:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=bash&amp;gt;&lt;br /&gt;
set(MIOSIX_USER_CONFIG_PATH ${CMAKE_SOURCE_DIR}/config)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Forking the Miosix git repository =&lt;br /&gt;
&lt;br /&gt;
Forking the Miosix git repository simply means cloning the kernel repository and start making changes within the kernel. To clone the git repository you simply type the following commands:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git clone https://miosix.org/git-public/miosix-kernel.git&lt;br /&gt;
cd miosix-kernel&lt;br /&gt;
git checkout testing&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The Miosix top-level directory contains the following files and subdirectories:&lt;br /&gt;
&lt;br /&gt;
[[File:Miosix-top-level-directory.png]]&lt;br /&gt;
&lt;br /&gt;
The [https://github.com/fedetft/miosix-kernel/blob/master/README.md README.md] file contains more detailed information on how the kernel source code directory tree is structured, but a quick overview is that the entire kernel code is in the &#039;&#039;miosix&#039;&#039; subdirectory, &#039;&#039;templates&#039;&#039; contains application templates you can copy out of the kernel directory to create your out of tree projects, &#039;&#039;examples&#039;&#039; contains some demos of the Miosix APIs, wile &#039;&#039;tools&#039;&#039; contains scripts and support code that does not get compiled into the kernel. It also contains the scripts and patches used to build the [[Miosix Toolchain]], the GCC-based cross compiler used to build the kernel.&lt;br /&gt;
&lt;br /&gt;
== Making changes ==&lt;br /&gt;
&lt;br /&gt;
Once you start making changes you can simply commit in the cloned git repository. If you need to share your changes, perhaps because there are multiple developers, git allows to have multiple remotes for a repository, so you can leave the default remote to periodically pull updates and bugfixes from the upstream Miosix repository, as well as push and pull from your personal remote repository.&lt;br /&gt;
&lt;br /&gt;
== Testing changes ==&lt;br /&gt;
&lt;br /&gt;
Once you start making changes to the kernel, you&#039;ll most likely want to quickly test to see if they work, which entails compiling the kernel to check for compile-time errors, and flash it to a board to check the code works at run-time.&lt;br /&gt;
&lt;br /&gt;
To do so you can set up a Miosix out of git tree project as described earlier that points to your cloned kernel, but there&#039;s a quicker way: building the templates from within the kernel tree.&lt;br /&gt;
&lt;br /&gt;
To do so, you&#039;ll need to select the board you want to build directly in the [https://github.com/fedetft/miosix-kernel/blob/master/miosix/config/Makefile.inc miosix/config/Makefile.inc] inside the kernel source tree, and select additional options (if needed) directly in the [https://github.com/fedetft/miosix-kernel/blob/master/miosix/config/miosix_settings.h miosix/config/miosix_settings.h] inside the kernel source tree.&lt;br /&gt;
&lt;br /&gt;
Ad this point, you can &#039;&#039;cd&#039;&#039; to the &#039;&#039;templates/simple&#039;&#039; (or any other template directory) and type&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=bash&amp;gt;&lt;br /&gt;
make&lt;br /&gt;
make program&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
from that directory.&lt;br /&gt;
&lt;br /&gt;
Although convenient, this comes with two caveats that you should be careful about:&lt;br /&gt;
* If you also use the kernel for making out of tree projects, the scripts  such as &#039;&#039;init_project_out_of_git_tree.pl&#039;&#039;, when copying the configuration and template directory to initialize a out of tree project, will also copy the testing code with it. This is often just a minor inconvenience, which can easily be solved in many ways, such as by using &#039;&#039;git stash&#039;&#039; before running an &#039;&#039;init_project_out_of_git_tree.pl&#039;&#039; script to temporarily stash those changes.&lt;br /&gt;
* You should remember to &#039;&#039;&#039;not commit&#039;&#039;&#039; these changes to configuration files, especially when you plan to contribute patches upstream. The list of boards in Makefile.inc should by default have all the available boards commented out, so as to let users select the board they want by uncommenting it.&lt;br /&gt;
&lt;br /&gt;
== Running the Miosix regression testsuite ==&lt;br /&gt;
&lt;br /&gt;
Miosix comes with a regression test suite that exercises most of the kernel code and is useful when making changes to the kernel to verify the absence of regressions.&lt;br /&gt;
&lt;br /&gt;
To compile the testsuite you should follow the instructions above to moddify the kernel&#039;s &#039;&#039;miosix/config&#039;&#039; directory to select the board you want to run the testsuite on, and then compile the testuite that is in the &#039;&#039;tools/testsuite&#039;&#039; directory.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=bash&amp;gt;&lt;br /&gt;
cd tools/testsuite&lt;br /&gt;
make&lt;br /&gt;
make program&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that compiled firmware of the testsuite is quite large since it contains every function of the kernel, especially if compiled with support for the filesystem and userspace processes.&lt;br /&gt;
&lt;br /&gt;
Making it easier to run the testsuite on small microcontrollers with little FLASH and RAM memory is a work in progress, he Miosix development team &amp;quot;chops&amp;quot; the testsuite in smaller pieces by commenting out part of it and running it one piece at a time, this is a tip worth knowing if you need to run it on very small microcontrollers.&lt;br /&gt;
&lt;br /&gt;
== Contributing to Miosix ==&lt;br /&gt;
&lt;br /&gt;
Miosix uses a shared ownership model, meaning that you retain the copyright for the contributions you add to the kernel. Your contributions should however be licensed with the same license of the rest of the kernel:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=CPP&amp;gt;&lt;br /&gt;
/***************************************************************************&lt;br /&gt;
 *   Copyright (C) &amp;lt;year&amp;gt; by &amp;lt;your name&amp;gt;                                   *&lt;br /&gt;
 *                                                                         *&lt;br /&gt;
 *   This program is free software; you can redistribute it and/or modify  *&lt;br /&gt;
 *   it under the terms of the GNU General Public License as published by  *&lt;br /&gt;
 *   the Free Software Foundation; either version 2 of the License, or     *&lt;br /&gt;
 *   (at your option) any later version.                                   *&lt;br /&gt;
 *                                                                         *&lt;br /&gt;
 *   This program is distributed in the hope that it will be useful,       *&lt;br /&gt;
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *&lt;br /&gt;
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *&lt;br /&gt;
 *   GNU General Public License for more details.                          *&lt;br /&gt;
 *                                                                         *&lt;br /&gt;
 *   As a special exception, if other files instantiate templates or use   *&lt;br /&gt;
 *   macros or inline functions from this file, or you compile this file   *&lt;br /&gt;
 *   and link it with other works to produce a work based on this file,    *&lt;br /&gt;
 *   this file does not by itself cause the resulting work to be covered   *&lt;br /&gt;
 *   by the GNU General Public License. However the source code for this   *&lt;br /&gt;
 *   file must still be made available in accordance with the GNU General  *&lt;br /&gt;
 *   Public License. This exception does not invalidate any other reasons  *&lt;br /&gt;
 *   why a work based on this file might be covered by the GNU General     *&lt;br /&gt;
 *   Public License.                                                       *&lt;br /&gt;
 *                                                                         *&lt;br /&gt;
 *   You should have received a copy of the GNU General Public License     *&lt;br /&gt;
 *   along with this program; if not, see &amp;lt;http://www.gnu.org/licenses/&amp;gt;   *&lt;br /&gt;
 ***************************************************************************/&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Be sure to add the copyright notice to all nontrivial source files. An example of a trivial source file would be a forwarding header such as [https://github.com/fedetft/miosix-kernel/blob/master/miosix/arch/cpu/armv8m/interfaces-impl/endianness_impl.h this one].&lt;br /&gt;
&lt;br /&gt;
If you wrote the file you want to add from scratch, just add your name to the copyright notice. If instead you copy-pasted the file from another one already present in the kernel and modified it (this often happens when making BSPs as there&#039;s almost always a similar BSP in the kernel to take inspiration from), just append your name to the list of authors of the file you copied.&lt;br /&gt;
&lt;br /&gt;
Since we use github only as a mirror to our repository that we host on miosix.org, we do not accept pull requests. You will instead be required to make a [https://git-scm.com/docs/git-format-patch format-patch] with the changes you want to be pushed upstream and send it via email to fede.tft&amp;amp;&amp;amp;miosix.org (s/&amp;amp;&amp;amp;/@/). It may be a good idea to get in contact first to discuss the changes you want pushed upstream, especially if they include modifications to the kernel itself rather than being simply new BSPs.&lt;br /&gt;
&lt;br /&gt;
When submitting patches for inclusion, please make sure that commits are small and self-contained, in order to simplify the integration process.&lt;br /&gt;
&lt;br /&gt;
Your changes should apply to the latest &#039;&#039;testing&#039;&#039; branch. If changes are related to the kernel itself, we may request to rebase them on top of &#039;&#039;unstable&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
[[Category:Installation and Configuration]]&lt;/div&gt;</summary>
		<author><name>Fede.tft</name></author>
	</entry>
	<entry>
		<id>https://miosix.org/wiki/index.php?title=Miosix_and_git_workflow&amp;diff=478</id>
		<title>Miosix and git workflow</title>
		<link rel="alternate" type="text/html" href="https://miosix.org/wiki/index.php?title=Miosix_and_git_workflow&amp;diff=478"/>
		<updated>2026-05-15T14:34:44Z</updated>

		<summary type="html">&lt;p&gt;Fede.tft: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
= The Miosix git repository =&lt;br /&gt;
&lt;br /&gt;
Miosix uses the git version control system to manage the kernel source code. To download and use the kernel you have to clone its git repository. The main Miosix git repository is hosted on this website, miosix.org, but we have no web page where you can browse the kernel sources. For this, we use a [https://github.com/fedetft/miosix-kernel github mirror] and the two repositories will be always kept in sync.&lt;br /&gt;
&lt;br /&gt;
As the kernel is under active development, users are advised to periodically &#039;&#039;git fetch&#039;&#039; or check the [https://github.com/fedetft/miosix-kernel kernel page on github] to look for new features and bug fixes, and pull the changes if required.&lt;br /&gt;
&lt;br /&gt;
Cloning the kernel repository from miosix.org can be done with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git clone https://miosix.org/git-public/miosix-kernel.git&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
While cloning the github mirror with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git clone https://github.com/fedetft/miosix-kernel.git&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Branches ==&lt;br /&gt;
&lt;br /&gt;
By default, when cloning a repository, git will download the &#039;&#039;master&#039;&#039; branch. Miosix offers two additional branches, &#039;&#039;testing&#039;&#039; and &#039;&#039;unstable&#039;&#039;, and you should be aware of the conventions we use for how we manage branches:&lt;br /&gt;
* The &#039;&#039;master&#039;&#039; branch contains the stable kernel, it is updated infrequently, usually once a year when a new release is made. Sometimes, a few minor releases are updated in short order.&lt;br /&gt;
* The &#039;&#039;testing&#039;&#039; branch contains the in-development code that we consider almost ready. Use this branch to get more bleeding edge features.&lt;br /&gt;
* The &#039;&#039;unstable&#039;&#039; branch is where the Miosix development team is working. It&#039;s meant to be used only by people in contact with the development team, as we occasionally rebase and force-push changes, so you may have a hard time keeping your git repository in sync with ours (the commit you downloaded today may no longer exist after a force push). If you&#039;re writing applications, it&#039;s best to ignore this branch and wait for the desired change to trickle to testing.&lt;br /&gt;
&lt;br /&gt;
To checkout a specific branch, once you have cloned the git repository, use the following command&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
cd miosix-kernel&lt;br /&gt;
git checkout testing&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Using Miosix in your projects =&lt;br /&gt;
&lt;br /&gt;
The rest of this page explains how to set up a software project making use of the Miosix kernel. There are basically two ways to do so:&lt;br /&gt;
&lt;br /&gt;
* Using out of git tree projects: this is the suggested workflow for developing applications using Miosix. Your application directory (and optionally git repo) stay separate from the kernel directory and git repo. The kernel can be a git submodule of your project.&lt;br /&gt;
* Forking the Miosix kernel git repository. This is the suggested workflow for extending the kernel, such as adding new board support packages (BSPs).&lt;br /&gt;
&lt;br /&gt;
The two workflows can be combined, for example you may want to fork the kernel to add your BSPs, and then use the forked kernel as submodule for developing your applications.&lt;br /&gt;
&lt;br /&gt;
= Out of git tree projects =&lt;br /&gt;
&lt;br /&gt;
Out of git tree projects allow you to write applications in a directory that stays separate from the Miosix kernel directory. When we say &#039;&#039;out of git tree&#039;&#039;, we mean that your project is developed outside of the &#039;&#039;Miosix&#039;&#039; git tree. Your project can be a git repository too, but that is up to you to decide.&lt;br /&gt;
&lt;br /&gt;
Additionally, a key part of an out of git tree project is that it allows to perform the kernel configuration (that requires editing configuration files) without the need to make changes to files within the Miosix git repo &#039;&#039;at all&#039;&#039;. This last point is important both to have the Miosix git repository as a [http://www.git-scm.com/book/en/Git-Tools-Submodules git submodule] of your application&#039;s git repository, and to allow sharing the same downloaded copy of the Miosix kernel across different applications, each with its own configuration. The kernel source code size on the hard drive has grown bigger in recent years due to the inclusion of headers with peripheral registers definitions in the [https://github.com/fedetft/miosix-kernel/tree/master/miosix/arch/CMSIS CMSIS] directory, so you may want to share a single downloaded copy of the kernel across several projects.&lt;br /&gt;
&lt;br /&gt;
Note that the ability to develop applications without making changes to the kernel directory is currently limited to the use case of configuring the kernel for one of the available BSPs. If you need to add BSPs to the kernel, then you&#039;ll most likely also have to fork the kernel repository. The &#039;&#039;most likely&#039;&#039; is due to &#039;&#039;generic&#039;&#039; BSPs in the kernel, which can be identified in the list of boards in [https://github.com/fedetft/miosix-kernel/blob/master/miosix/config/Makefile.inc Makefile.inc] as &#039;&#039;&amp;lt;chip name&amp;gt;_generic&#039;&#039; such as  &#039;&#039;stm32f103xb_generic&#039;&#039;. If you&#039;re writing an application for a board that has a chip with a generic BSP in the kernel, you can (unless you &#039;&#039;really&#039;&#039; need to run some custom code during boot) get away with selecting the generic BSP without forking the kernel. If there&#039;s no generic BSP for your chip, or need to add support for an entirely new chip, then you&#039;ll have to fork the kernel to add it.&lt;br /&gt;
&lt;br /&gt;
== Organizing your out of git tree projects ==&lt;br /&gt;
&lt;br /&gt;
For an out of git tree project, you need to create a directory in your computer that will contain your project. The &#039;&#039;miosix-kernel&#039;&#039; directory (and git repo) can either be a subdirectory of your project&#039;s directory (common option when adding the Miosix kernel as a git submodule to your project):&lt;br /&gt;
&lt;br /&gt;
[[File:Out-of-tree-subdirectory.png]]&lt;br /&gt;
&lt;br /&gt;
Or you can organize your projects side by side to the kernel (common when sharing a single kernel among multiple projects):&lt;br /&gt;
&lt;br /&gt;
[[File:Out-of-tree-shared.png]]&lt;br /&gt;
&lt;br /&gt;
The only constraint (it&#039;s a limitation in the Makefile build systems), is that the &#039;&#039;relative&#039;&#039; path from your project directory to the kernel should not contain spaces. This practically means that you should not give your project directories names with spaces.&lt;br /&gt;
&lt;br /&gt;
== Adding Miosix as a submodule to your git project == &lt;br /&gt;
&lt;br /&gt;
Suppose you have a git repository called myapplication, which is the repo of your application, and you would like to download the miosix-kernel repository as a git submodule. Then open a shell in the test repository and type:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git submodule init&lt;br /&gt;
git submodule add https://miosix.org/git-public/miosix-kernel.git miosix-kernel&lt;br /&gt;
git commit -m &amp;quot;Added miosix-kernel as a git submodule&amp;quot;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Initializing an out of git tree project ==&lt;br /&gt;
&lt;br /&gt;
Using out of git tree projects implies having a build system in your project directory that can both compile the source code of your application and the Miosix kernel. Miosix provides two build systems, Makefiles and [[CMake]]. In this tutorial we&#039;ll use Makefiles.&lt;br /&gt;
&lt;br /&gt;
Miosix projects start from a template that you can find in the &#039;&#039;miosix-kernel/templates&#039;&#039; directory. You can copy the template yourself from the kernel source tree to your project directory, but in that case, you&#039;ll need to fix the relative paths in the build system. Alternatively, you can use the &#039;&#039;init_project_out_of_git_tree.pl&#039;&#039; script to initialize a project.&lt;br /&gt;
&lt;br /&gt;
Additionally, the kernel configuration directory needs to be copied to your project. This is necessary because you&#039;ll need to make changes to those files to select kernel build options, at minimum which board you want to compile the kernel for.&lt;br /&gt;
As you may know, git submodules work well if you never make changes in the submodule directory, otherwise you will have to basically fork the submodule, or you will find yourself making changes to a repository in a detached head state and risk losing them at the next git pull.&lt;br /&gt;
For this reason, we&#039;ll copy the config directory to your project and make changes there. The &#039;&#039;init_project_out_of_git_tree.pl&#039;&#039; performs also this action for you.&lt;br /&gt;
&lt;br /&gt;
=== Initialize a project using &#039;&#039;init_project_out_of_git_tree.pl&#039;&#039; ===&lt;br /&gt;
&lt;br /&gt;
Just open a shell in your project directory and invoke the perl script in the kernel:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=bash&amp;gt;&lt;br /&gt;
perl &amp;lt;path to the kernel&amp;gt;tools/init_project_out_of_git_tree.pl&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus for the case when the kernel is a subdirectory of your project that would be:&lt;br /&gt;
&amp;lt;source lang=bash&amp;gt;&lt;br /&gt;
perl miosix-kernel/tools/init_project_out_of_git_tree.pl&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
While for the side-by-side case:&lt;br /&gt;
&amp;lt;source lang=bash&amp;gt;&lt;br /&gt;
perl ../miosix-kernel/tools/init_project_out_of_git_tree.pl&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that you have to run the script without moving the current directory away from the one of your project. This means you can&#039;t &#039;&#039;cd&#039;&#039; to the &#039;&#039;miosix-kernel/tools&#039;&#039; directory, run the script there, and then &#039;&#039;cd&#039;&#039; back. The script withes the project files to the current directory it&#039;s been invoked from.&lt;br /&gt;
&lt;br /&gt;
If all goes well you&#039;ll get a message similar to:&lt;br /&gt;
&amp;lt;source lang=bash&amp;gt;&lt;br /&gt;
Successfully created Miosix project&lt;br /&gt;
Target directory: myapplication&lt;br /&gt;
Kernel directory: myapplication/miosix-kernel/miosix&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and your project should now contain the &#039;&#039;config&#039;&#039; directory and the &#039;&#039;main.cpp&#039;&#039;, &#039;&#039;Makefile&#039;&#039; and &#039;&#039;CMakeLists.txt&#039;&#039; files.&lt;br /&gt;
&lt;br /&gt;
=== Manually copying a template ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Forking the Miosix git repository =&lt;br /&gt;
&lt;br /&gt;
Forking the Miosix git repository simply means cloning the kernel repository and start making changes within the kernel. To clone the git repository you simply type the following commands:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git clone https://miosix.org/git-public/miosix-kernel.git&lt;br /&gt;
cd miosix-kernel&lt;br /&gt;
git checkout testing&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The Miosix top-level directory contains the following files and subdirectories:&lt;br /&gt;
&lt;br /&gt;
[[File:Miosix-top-level-directory.png]]&lt;br /&gt;
&lt;br /&gt;
The [https://github.com/fedetft/miosix-kernel/blob/master/README.md README.md] file contains more detailed information on how the kernel source code directory tree is structured, but a quick overview is that the entire kernel code is in the &#039;&#039;miosix&#039;&#039; subdirectory, &#039;&#039;templates&#039;&#039; contains application templates you can copy out of the kernel directory to create your out of tree projects, &#039;&#039;examples&#039;&#039; contains some demos of the Miosix APIs, wile &#039;&#039;tools&#039;&#039; contains scripts and support code that does not get compiled into the kernel. It also contains the scripts and patches used to build the [[Miosix Toolchain]], the GCC-based cross compiler used to build the kernel.&lt;br /&gt;
&lt;br /&gt;
== Making changes ==&lt;br /&gt;
&lt;br /&gt;
Once you start making changes you can simply commit in the cloned git repository. If you need to share your changes, perhaps because there are multiple developers, git allows to have multiple remotes for a repository, so you can leave the default remote to periodically pull updates and bugfixes from the upstream Miosix repository, as well as push and pull from your personal remote repository.&lt;br /&gt;
&lt;br /&gt;
== Testing changes ==&lt;br /&gt;
&lt;br /&gt;
Once you start making changes to the kernel, you&#039;ll most likely want to quickly test to see if they work, which entails compiling the kernel to check for compile-time errors, and flash it to a board to check the code works at run-time.&lt;br /&gt;
&lt;br /&gt;
To do so you can set up a Miosix out of git tree project as described earlier that points to your cloned kernel, but there&#039;s a quicker way: building the templates from within the kernel tree.&lt;br /&gt;
&lt;br /&gt;
To do so, you&#039;ll need to select the board you want to build directly in the [https://github.com/fedetft/miosix-kernel/blob/master/miosix/config/Makefile.inc miosix/config/Makefile.inc] inside the kernel source tree, and select additional options (if needed) directly in the [https://github.com/fedetft/miosix-kernel/blob/master/miosix/config/miosix_settings.h miosix/config/miosix_settings.h] inside the kernel source tree.&lt;br /&gt;
&lt;br /&gt;
Ad this point, you can &#039;&#039;cd&#039;&#039; to the &#039;&#039;templates/simple&#039;&#039; (or any other template directory) and type&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=bash&amp;gt;&lt;br /&gt;
make&lt;br /&gt;
make program&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
from that directory.&lt;br /&gt;
&lt;br /&gt;
Although convenient, this comes with two caveats that you should be careful about:&lt;br /&gt;
* If you also use the kernel for making out of tree projects, the scripts  such as &#039;&#039;init_project_out_of_git_tree.pl&#039;&#039;, when copying the configuration and template directory to initialize a out of tree project, will also copy the testing code with it. This is often just a minor inconvenience, which can easily be solved in many ways, such as by using &#039;&#039;git stash&#039;&#039; before running an &#039;&#039;init_project_out_of_git_tree.pl&#039;&#039; script to temporarily stash those changes.&lt;br /&gt;
* You should remember to &#039;&#039;&#039;not commit&#039;&#039;&#039; these changes to configuration files, especially when you plan to contribute patches upstream. The list of boards in Makefile.inc should by default have all the available boards commented out, so as to let users select the board they want by uncommenting it.&lt;br /&gt;
&lt;br /&gt;
== Running the Miosix regression testsuite ==&lt;br /&gt;
&lt;br /&gt;
Miosix comes with a regression test suite that exercises most of the kernel code and is useful when making changes to the kernel to verify the absence of regressions.&lt;br /&gt;
&lt;br /&gt;
To compile the testsuite you should follow the instructions above to moddify the kernel&#039;s &#039;&#039;miosix/config&#039;&#039; directory to select the board you want to run the testsuite on, and then compile the testuite that is in the &#039;&#039;tools/testsuite&#039;&#039; directory.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=bash&amp;gt;&lt;br /&gt;
cd tools/testsuite&lt;br /&gt;
make&lt;br /&gt;
make program&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that compiled firmware of the testsuite is quite large since it contains every function of the kernel, especially if compiled with support for the filesystem and userspace processes.&lt;br /&gt;
&lt;br /&gt;
Making it easier to run the testsuite on small microcontrollers with little FLASH and RAM memory is a work in progress, he Miosix development team &amp;quot;chops&amp;quot; the testsuite in smaller pieces by commenting out part of it and running it one piece at a time, this is a tip worth knowing if you need to run it on very small microcontrollers.&lt;br /&gt;
&lt;br /&gt;
== Contributing to Miosix ==&lt;br /&gt;
&lt;br /&gt;
Miosix uses a shared ownership model, meaning that you retain the copyright for the contributions you add to the kernel. Your contributions should however be licensed with the same license of the rest of the kernel:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=CPP&amp;gt;&lt;br /&gt;
/***************************************************************************&lt;br /&gt;
 *   Copyright (C) &amp;lt;year&amp;gt; by &amp;lt;your name&amp;gt;                                   *&lt;br /&gt;
 *                                                                         *&lt;br /&gt;
 *   This program is free software; you can redistribute it and/or modify  *&lt;br /&gt;
 *   it under the terms of the GNU General Public License as published by  *&lt;br /&gt;
 *   the Free Software Foundation; either version 2 of the License, or     *&lt;br /&gt;
 *   (at your option) any later version.                                   *&lt;br /&gt;
 *                                                                         *&lt;br /&gt;
 *   This program is distributed in the hope that it will be useful,       *&lt;br /&gt;
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *&lt;br /&gt;
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *&lt;br /&gt;
 *   GNU General Public License for more details.                          *&lt;br /&gt;
 *                                                                         *&lt;br /&gt;
 *   As a special exception, if other files instantiate templates or use   *&lt;br /&gt;
 *   macros or inline functions from this file, or you compile this file   *&lt;br /&gt;
 *   and link it with other works to produce a work based on this file,    *&lt;br /&gt;
 *   this file does not by itself cause the resulting work to be covered   *&lt;br /&gt;
 *   by the GNU General Public License. However the source code for this   *&lt;br /&gt;
 *   file must still be made available in accordance with the GNU General  *&lt;br /&gt;
 *   Public License. This exception does not invalidate any other reasons  *&lt;br /&gt;
 *   why a work based on this file might be covered by the GNU General     *&lt;br /&gt;
 *   Public License.                                                       *&lt;br /&gt;
 *                                                                         *&lt;br /&gt;
 *   You should have received a copy of the GNU General Public License     *&lt;br /&gt;
 *   along with this program; if not, see &amp;lt;http://www.gnu.org/licenses/&amp;gt;   *&lt;br /&gt;
 ***************************************************************************/&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Be sure to add the copyright notice to all nontrivial source files. An example of a trivial source file would be a forwarding header such as [https://github.com/fedetft/miosix-kernel/blob/master/miosix/arch/cpu/armv8m/interfaces-impl/endianness_impl.h this one].&lt;br /&gt;
&lt;br /&gt;
If you wrote the file you want to add from scratch, just add your name to the copyright notice. If instead you copy-pasted the file from another one already present in the kernel and modified it (this often happens when making BSPs as there&#039;s almost always a similar BSP in the kernel to take inspiration from), just append your name to the list of authors of the file you copied.&lt;br /&gt;
&lt;br /&gt;
Since we use github only as a mirror to our repository that we host on miosix.org, we do not accept pull requests. You will instead be required to make a [https://git-scm.com/docs/git-format-patch format-patch] with the changes you want to be pushed upstream and send it via email to fede.tft&amp;amp;&amp;amp;miosix.org (s/&amp;amp;&amp;amp;/@/). It may be a good idea to get in contact first to discuss the changes you want pushed upstream, especially if they include modifications to the kernel itself rather than being simply new BSPs.&lt;br /&gt;
&lt;br /&gt;
When submitting patches for inclusion, please make sure that commits are small and self-contained, in order to simplify the integration process.&lt;br /&gt;
&lt;br /&gt;
Your changes should apply to the latest &#039;&#039;testing&#039;&#039; branch. If changes are related to the kernel itself, we may request to rebase them on top of &#039;&#039;unstable&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
[[Category:Installation and Configuration]]&lt;/div&gt;</summary>
		<author><name>Fede.tft</name></author>
	</entry>
	<entry>
		<id>https://miosix.org/wiki/index.php?title=File:Out-of-tree-shared.png&amp;diff=477</id>
		<title>File:Out-of-tree-shared.png</title>
		<link rel="alternate" type="text/html" href="https://miosix.org/wiki/index.php?title=File:Out-of-tree-shared.png&amp;diff=477"/>
		<updated>2026-05-15T14:08:58Z</updated>

		<summary type="html">&lt;p&gt;Fede.tft: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Out-of-tree-shared&lt;/div&gt;</summary>
		<author><name>Fede.tft</name></author>
	</entry>
	<entry>
		<id>https://miosix.org/wiki/index.php?title=File:Out-of-tree-subdirectory.png&amp;diff=476</id>
		<title>File:Out-of-tree-subdirectory.png</title>
		<link rel="alternate" type="text/html" href="https://miosix.org/wiki/index.php?title=File:Out-of-tree-subdirectory.png&amp;diff=476"/>
		<updated>2026-05-15T14:07:15Z</updated>

		<summary type="html">&lt;p&gt;Fede.tft: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Out-of-tree-subdirectory&lt;/div&gt;</summary>
		<author><name>Fede.tft</name></author>
	</entry>
	<entry>
		<id>https://miosix.org/wiki/index.php?title=Miosix_and_git_workflow&amp;diff=475</id>
		<title>Miosix and git workflow</title>
		<link rel="alternate" type="text/html" href="https://miosix.org/wiki/index.php?title=Miosix_and_git_workflow&amp;diff=475"/>
		<updated>2026-05-15T09:44:27Z</updated>

		<summary type="html">&lt;p&gt;Fede.tft: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
= The Miosix git repository =&lt;br /&gt;
&lt;br /&gt;
Miosix uses the git version control system to manage the kernel source code. To download and use the kernel you have to clone its git repository. The main Miosix git repository is hosted on this website, miosix.org, but we have no web page where you can browse the kernel sources. For this, we use a [https://github.com/fedetft/miosix-kernel github mirror] and the two repositories will be always kept in sync.&lt;br /&gt;
&lt;br /&gt;
As the kernel is under active development, users are advised to periodically &#039;&#039;git fetch&#039;&#039; or check the [https://github.com/fedetft/miosix-kernel kernel page on github] to look for new features and bug fixes, and pull the changes if required.&lt;br /&gt;
&lt;br /&gt;
By default, when cloning a repository, git will download the &#039;&#039;master&#039;&#039; branch. Miosix offers two additional branches, &#039;&#039;testing&#039;&#039; and &#039;&#039;unstable&#039;&#039;, and you should be aware of the conventions we use for how we manage branches:&lt;br /&gt;
* The &#039;&#039;master&#039;&#039; branch contains the stable kernel, it is updated infrequently, usually once a year when a new release is made. Sometimes, a few minor releases are updated in short order.&lt;br /&gt;
* The &#039;&#039;testing&#039;&#039; branch contains the in-development code that we consider almost ready. Use this branch to get more bleeding edge features.&lt;br /&gt;
* The &#039;&#039;unstable&#039;&#039; branch is where the Miosix development team is working. It&#039;s meant to be used only by people in contact with the development team, as we occasionally rebase and force-push changes, so you may have a hard time keeping your git repository in sync with ours (the commit you downloaded today may no longer exist after a force push). If you&#039;re writing applications, it&#039;s best to ignore this branch and wait for the desired change to trickle to testing.&lt;br /&gt;
&lt;br /&gt;
Cloning the kernel repository from miosix.org can be done with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git clone https://miosix.org/git-public/miosix-kernel.git&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
While cloning the github mirror with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git clone https://github.com/fedetft/miosix-kernel.git&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To checkout a specific branch, once you have cloned the git repository, use the following command&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
cd miosix-kernel&lt;br /&gt;
git checkout testing&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The rest of this page explains how to set up a software project making use of the Miosix kernel, that can later allow updating the kernel through git without creating problems. There are basically two ways to do so:&lt;br /&gt;
&lt;br /&gt;
* Setting up out an out of git tree project: this is the suggested workflow for developing applications using Miosix. Your application directory and git repo stay separate from the kernel directory and git repo. The kernel can be a git submodule of your project.&lt;br /&gt;
* Forking the Miosix kernel git repository. This is the suggested workflow for extending the kernel, such as adding new board support packages (BSPs).&lt;br /&gt;
&lt;br /&gt;
The two workflows can be combined, for example you may want to fork the kernel to add your BSPs, and then use the forked kernel as submodule for developing your applications.&lt;br /&gt;
&lt;br /&gt;
= Setting up an out of git tree project =&lt;br /&gt;
&lt;br /&gt;
Out of git tree projects allow you to write applications in a directory that stays separate from the Miosix kernel directory. Additionally, they allow to perform the kernel configuration (that requires editing configuration files) without the need to make changes to files within the Miosix git repo &#039;&#039;at all&#039;&#039;. This last point is important both to have the Miosix git repository as a [http://www.git-scm.com/book/en/Git-Tools-Submodules git submodule] of your application&#039;s git repository, and to allow sharing the same downloaded copy of the Miosix kernel across different applications, each with its own configuration. The kernel source code size on the hard drive has grown bigger in recent years due to the inclusion of headers with peripheral registers definitions in the [https://github.com/fedetft/miosix-kernel/tree/master/miosix/arch/CMSIS CMSIS] directory, so you may want to share a single downloaded copy of the kernel across several projects.&lt;br /&gt;
&lt;br /&gt;
Note that the ability to develop applications without making changes to the kernel directory is currently limited to the use case of configuring the kernel for one of the available BSPs. If you need to add BSPs to the kernel, then you&#039;ll most likely also have to fork the kernel repository. The &#039;&#039;most likely&#039;&#039; is due to &#039;&#039;generic&#039;&#039; BSPs in the kernel, which can be identified in the list of boards in [https://github.com/fedetft/miosix-kernel/blob/master/miosix/config/Makefile.inc Makefile.inc] as &#039;&#039;&amp;lt;chip name&amp;gt;_generic&#039;&#039; such as  &#039;&#039;stm32f103xb_generic&#039;&#039;. If you&#039;re writing an application for a board that has a chip with a generic BSP in the kernel, you can (unless you &#039;&#039;really&#039;&#039; need to run some custom code during boot) get away with selecting the generic BSP without forking the kernel. If there&#039;s no generic BSP for your chip, or need to add support for an entirely new chip, then you&#039;ll have to fork the kernel to add it.&lt;br /&gt;
&lt;br /&gt;
Suppose you have a git repository called test, which is the repo of your application, and you would like to download the miosix-kernel repository as a git submodule. Then open a shell in the test repository and type&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git submodule init&lt;br /&gt;
git submodule add https://miosix.org/git-public/miosix-kernel.git miosix-kernel&lt;br /&gt;
cd miosix-kernel&lt;br /&gt;
git fetch origin&lt;br /&gt;
cd ..&lt;br /&gt;
git commit -a -m &amp;quot;Added miosix-kernel as a git submodule&amp;quot;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This solves the problem from the git side, now let&#039;s solve the problem from the Miosix side. As you may know, git submodules work well if you never make changes in the submodule directory, otherwise you will have to basically fork the submodule, or you will find yourself making changes to a repository in a detached head state and risk losing them at the next git pull.&lt;br /&gt;
&lt;br /&gt;
However, the &#039;&#039;Makefile&#039;&#039; for Miosix, as well as configuration files such as [[Makefile.inc|miosix/config/Makefile.inc]] and [[miosix_settings.h|miosix/config/miosix_settings.h]] are within the submodule directory, so how are you going to make use of the kernel without touching files in the submodule directory?&lt;br /&gt;
&lt;br /&gt;
The solution is out of git tree projects, a new feature added in Miosix 2.0 that basically moves the &#039;&#039;main.cpp&#039;&#039;, &#039;&#039;Makefile&#039;&#039;, &#039;&#039;config&#039;&#039; directory, and the Netbeans IDE project directory outside of the git repository, using tweaks to the &#039;&#039;Makefile&#039;&#039; paths so that the kernel will find the &#039;&#039;config&#039;&#039; directory outside of the kernel, not the one inside it. &lt;br /&gt;
&lt;br /&gt;
To get started with out of git tree projects, there is a perl script that is used to easily set everything up. For example, suppose you are in the directory of your git repository where you have added the &#039;&#039;miosix-kernel&#039;&#039; submodule, and want to set up an out of git tree project there, open a shell and type&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
perl miosix-kernel/miosix/_tools/init_project_out_of_git_tree.pl&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The script will create a Miosix out of git tree project in the directory it is called, basically creating a &#039;&#039;config&#039;&#039; directory with a copy of the configuration files you can edit, a &#039;&#039;Makefile&#039;&#039; and a &#039;&#039;main.cpp&#039;&#039; as usual, as well as a new &#039;&#039;miosix_np_2&#039;&#039; directory with a Netbeans IDE project.&lt;br /&gt;
&lt;br /&gt;
The main advantage of this solution is that it keeps your application and the kernel in two separate git repositories. The disadvantage is that if you need to make changes to the kernel other than to configuration files, you will need to clone the miosix-kernel repository anyway, as well as having to manage the complexity of having two git repositories.&lt;br /&gt;
&lt;br /&gt;
= Forking the Miosix git repository =&lt;br /&gt;
&lt;br /&gt;
Forking the Miosix git repository simply means cloning the kernel repository and start making changes within the kernel. To clone the git repository you simply type the following commands:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git clone https://miosix.org/git-public/miosix-kernel.git&lt;br /&gt;
cd miosix-kernel&lt;br /&gt;
git checkout testing&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The Miosix top-level directory contains the following files and subdirectories:&lt;br /&gt;
&lt;br /&gt;
[[File:Miosix-top-level-directory.png]]&lt;br /&gt;
&lt;br /&gt;
The [https://github.com/fedetft/miosix-kernel/blob/master/README.md README.md] file contains more detailed information on how the kernel source code directory tree is structured, but a quick overview is that the entire kernel code is in the &#039;&#039;miosix&#039;&#039; subdirectory, &#039;&#039;templates&#039;&#039; contains application templates you can copy out of the kernel directory to create your out of tree projects, &#039;&#039;examples&#039;&#039; contains some demos of the Miosix APIs, wile &#039;&#039;tools&#039;&#039; contains scripts and support code that does not get compiled into the kernel. It also contains the scripts and patches used to build the [[Miosix Toolchain]], the GCC-based cross compiler used to build the kernel.&lt;br /&gt;
&lt;br /&gt;
== Making changes ==&lt;br /&gt;
&lt;br /&gt;
Once you start making changes you can simply commit in the cloned git repository. If you need to share your changes, perhaps because there are multiple developers, git allows to have multiple remotes for a repository, so you can leave the default remote to periodically pull updates and bugfixes from the upstream Miosix repository, as well as push and pull from your personal remote repository.&lt;br /&gt;
&lt;br /&gt;
== Testing changes ==&lt;br /&gt;
&lt;br /&gt;
Once you start making changes to the kernel, you&#039;ll most likely want to quickly test to see if they work, which entails compiling the kernel to check for compile-time errors, and flash it to a board to check the code works at run-time.&lt;br /&gt;
&lt;br /&gt;
To do so you can set up a Miosix out of git tree project as described earlier that points to your cloned kernel, but there&#039;s a quicker way: building the templates from within the kernel tree.&lt;br /&gt;
&lt;br /&gt;
To do so, you&#039;ll need to select the board you want to build directly in the [https://github.com/fedetft/miosix-kernel/blob/master/miosix/config/Makefile.inc miosix/config/Makefile.inc] inside the kernel source tree, and select additional options (if needed) directly in the [https://github.com/fedetft/miosix-kernel/blob/master/miosix/config/miosix_settings.h miosix/config/miosix_settings.h] inside the kernel source tree.&lt;br /&gt;
&lt;br /&gt;
Ad this point, you can &#039;&#039;cd&#039;&#039; to the &#039;&#039;templates/simple&#039;&#039; (or any other template directory) and type&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=bash&amp;gt;&lt;br /&gt;
make&lt;br /&gt;
make program&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
from that directory.&lt;br /&gt;
&lt;br /&gt;
Although convenient, this comes with two caveats that you should be careful about:&lt;br /&gt;
* If you also use the kernel for making out of tree projects, the scripts  such as &#039;&#039;init_project_out_of_git_tree.pl&#039;&#039;, when copying the configuration and template directory to initialize a out of tree project, will also copy the testing code with it. This is often just a minor inconvenience, which can easily be solved in many ways, such as by using &#039;&#039;git stash&#039;&#039; before running an &#039;&#039;init_project_out_of_git_tree.pl&#039;&#039; script to temporarily stash those changes.&lt;br /&gt;
* You should remember to &#039;&#039;&#039;not commit&#039;&#039;&#039; these changes to configuration files, especially when you plan to contribute patches upstream. The list of boards in Makefile.inc should by default have all the available boards commented out, so as to let users select the board they want by uncommenting it.&lt;br /&gt;
&lt;br /&gt;
== Running the Miosix regression testsuite ==&lt;br /&gt;
&lt;br /&gt;
Miosix comes with a regression test suite that exercises most of the kernel code and is useful when making changes to the kernel to verify the absence of regressions.&lt;br /&gt;
&lt;br /&gt;
To compile the testsuite you should follow the instructions above to moddify the kernel&#039;s &#039;&#039;miosix/config&#039;&#039; directory to select the board you want to run the testsuite on, and then compile the testuite that is in the &#039;&#039;tools/testsuite&#039;&#039; directory.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=bash&amp;gt;&lt;br /&gt;
cd tools/testsuite&lt;br /&gt;
make&lt;br /&gt;
make program&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that compiled firmware of the testsuite is quite large since it contains every function of the kernel, especially if compiled with support for the filesystem and userspace processes.&lt;br /&gt;
&lt;br /&gt;
Making it easier to run the testsuite on small microcontrollers with little FLASH and RAM memory is a work in progress, he Miosix development team &amp;quot;chops&amp;quot; the testsuite in smaller pieces by commenting out part of it and running it one piece at a time, this is a tip worth knowing if you need to run it on very small microcontrollers.&lt;br /&gt;
&lt;br /&gt;
== Contributing to Miosix ==&lt;br /&gt;
&lt;br /&gt;
Miosix uses a shared ownership model, meaning that you retain the copyright for the contributions you add to the kernel. Your contributions should however be licensed with the same license of the rest of the kernel:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=CPP&amp;gt;&lt;br /&gt;
/***************************************************************************&lt;br /&gt;
 *   Copyright (C) &amp;lt;year&amp;gt; by &amp;lt;your name&amp;gt;                                   *&lt;br /&gt;
 *                                                                         *&lt;br /&gt;
 *   This program is free software; you can redistribute it and/or modify  *&lt;br /&gt;
 *   it under the terms of the GNU General Public License as published by  *&lt;br /&gt;
 *   the Free Software Foundation; either version 2 of the License, or     *&lt;br /&gt;
 *   (at your option) any later version.                                   *&lt;br /&gt;
 *                                                                         *&lt;br /&gt;
 *   This program is distributed in the hope that it will be useful,       *&lt;br /&gt;
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *&lt;br /&gt;
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *&lt;br /&gt;
 *   GNU General Public License for more details.                          *&lt;br /&gt;
 *                                                                         *&lt;br /&gt;
 *   As a special exception, if other files instantiate templates or use   *&lt;br /&gt;
 *   macros or inline functions from this file, or you compile this file   *&lt;br /&gt;
 *   and link it with other works to produce a work based on this file,    *&lt;br /&gt;
 *   this file does not by itself cause the resulting work to be covered   *&lt;br /&gt;
 *   by the GNU General Public License. However the source code for this   *&lt;br /&gt;
 *   file must still be made available in accordance with the GNU General  *&lt;br /&gt;
 *   Public License. This exception does not invalidate any other reasons  *&lt;br /&gt;
 *   why a work based on this file might be covered by the GNU General     *&lt;br /&gt;
 *   Public License.                                                       *&lt;br /&gt;
 *                                                                         *&lt;br /&gt;
 *   You should have received a copy of the GNU General Public License     *&lt;br /&gt;
 *   along with this program; if not, see &amp;lt;http://www.gnu.org/licenses/&amp;gt;   *&lt;br /&gt;
 ***************************************************************************/&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Be sure to add the copyright notice to all nontrivial source files. An example of a trivial source file would be a forwarding header such as [https://github.com/fedetft/miosix-kernel/blob/master/miosix/arch/cpu/armv8m/interfaces-impl/endianness_impl.h this one].&lt;br /&gt;
&lt;br /&gt;
If you wrote the file you want to add from scratch, just add your name to the copyright notice. If instead you copy-pasted the file from another one already present in the kernel and modified it (this often happens when making BSPs as there&#039;s almost always a similar BSP in the kernel to take inspiration from), just append your name to the list of authors of the file you copied.&lt;br /&gt;
&lt;br /&gt;
Since we use github only as a mirror to our repository that we host on miosix.org, we do not accept pull requests. You will instead be required to make a [https://git-scm.com/docs/git-format-patch format-patch] with the changes you want to be pushed upstream and send it via email to fede.tft&amp;amp;&amp;amp;miosix.org (s/&amp;amp;&amp;amp;/@/). It may be a good idea to get in contact first to discuss the changes you want pushed upstream, especially if they include modifications to the kernel itself rather than being simply new BSPs.&lt;br /&gt;
&lt;br /&gt;
When submitting patches for inclusion, please make sure that commits are small and self-contained, in order to simplify the integration process.&lt;br /&gt;
&lt;br /&gt;
Your changes should apply to the latest &#039;&#039;testing&#039;&#039; branch. If changes are related to the kernel itself, we may request to rebase them on top of &#039;&#039;unstable&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
[[Category:Installation and Configuration]]&lt;/div&gt;</summary>
		<author><name>Fede.tft</name></author>
	</entry>
	<entry>
		<id>https://miosix.org/wiki/index.php?title=Miosix_and_git_workflow&amp;diff=474</id>
		<title>Miosix and git workflow</title>
		<link rel="alternate" type="text/html" href="https://miosix.org/wiki/index.php?title=Miosix_and_git_workflow&amp;diff=474"/>
		<updated>2026-05-15T08:56:53Z</updated>

		<summary type="html">&lt;p&gt;Fede.tft: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
= The Miosix git repository =&lt;br /&gt;
&lt;br /&gt;
Miosix uses the git version control system to manage the kernel source code. To download and use the kernel you have to clone its git repository. The main Miosix git repository is hosted on this website, miosix.org, but we have no web page where you can browse the kernel sources. For this, we use a [https://github.com/fedetft/miosix-kernel github mirror] and the two repositories will be always kept in sync.&lt;br /&gt;
&lt;br /&gt;
As the kernel is under active development, users are advised to periodically &#039;&#039;git fetch&#039;&#039; or check the [https://github.com/fedetft/miosix-kernel kernel page on github] to look for new features and bug fixes, and pull the changes if required.&lt;br /&gt;
&lt;br /&gt;
By default, when cloning a repository, git will download the &#039;&#039;master&#039;&#039; branch. Miosix offers two additional branches, &#039;&#039;testing&#039;&#039; and &#039;&#039;unstable&#039;&#039;, and you should be aware of the conventions we use for how we manage branches:&lt;br /&gt;
* The &#039;&#039;master&#039;&#039; branch contains the stable kernel, it is updated infrequently, usually once a year when a new release is made. Sometimes, a few minor releases are updated in short order.&lt;br /&gt;
* The &#039;&#039;testing&#039;&#039; branch contains the in-development code that we consider almost ready. Use this branch to get more bleeding edge features.&lt;br /&gt;
* The &#039;&#039;unstable&#039;&#039; branch is where the Miosix development team is working. It&#039;s meant to be used only by people in contact with the development team, as we occasionally rebase and force-push changes, so you may have a hard time keeping your git repository in sync with ours (the commit you downloaded today may no longer exist after a force push). If you&#039;re writing applications, it&#039;s best to ignore this branch and wait for the desired change to trickle to testing.&lt;br /&gt;
&lt;br /&gt;
Cloning the kernel repository from miosix.org can be done with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git clone https://miosix.org/git-public/miosix-kernel.git&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
While cloning the github mirror with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git clone https://github.com/fedetft/miosix-kernel.git&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To checkout a specific branch, once you have cloned the git repository, use the following command&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
cd miosix-kernel&lt;br /&gt;
git checkout testing&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The rest of this page explains how to set up a software project making use of the Miosix kernel, that can later allow updating the kernel through git without creating problems. There are basically two ways to do so:&lt;br /&gt;
&lt;br /&gt;
* Setting up out an out of git tree project: this is the suggested workflow for developing applications using Miosix. Your application directory and git repo stay separate from the kernel directory and git repo. The kernel can be a git submodule of your project.&lt;br /&gt;
* Forking the Miosix kernel git repository. This is the suggested workflow for extending the kernel, such as adding new board support packages (BSPs).&lt;br /&gt;
&lt;br /&gt;
The two workflows can be combined, for example you may want to fork the kernel to add your BSPs, and then use the forked kernel as submodule for developing your applications.&lt;br /&gt;
&lt;br /&gt;
= Setting up an out of git tree project =&lt;br /&gt;
&lt;br /&gt;
Out of git tree projects allow you to write applications in a directory that stays separate from the Miosix kernel directory. Additionally, they allow to perform the kernel configuration (that requires editing configuration files) without the need to make changes to files within the Miosix git repo &#039;&#039;at all&#039;&#039;. This last point is important both to have the Miosix git repository as a [http://www.git-scm.com/book/en/Git-Tools-Submodules git submodule] of your application&#039;s git repository, and to allow sharing the same downloaded copy of the Miosix kernel across different applications, each with its own configuration. The kernel source code size on the hard drive has grown bigger in recent years due to the inclusion of headers with peripheral registers definitions in the [https://github.com/fedetft/miosix-kernel/tree/master/miosix/arch/CMSIS CMSIS] directory, so you may want to share a single downloaded copy of the kernel across several projects.&lt;br /&gt;
&lt;br /&gt;
Note that the ability to develop applications without making changes to the kernel directory is currently limited to the use case of configuring the kernel for one of the available BSPs. If you need to add BSPs to the kernel, then you&#039;ll most likely also have to fork the kernel repository. The &#039;&#039;most likely&#039;&#039; is due to &#039;&#039;generic&#039;&#039; BSPs in the kernel, which can be identified in the list of boards in [https://github.com/fedetft/miosix-kernel/blob/master/miosix/config/Makefile.inc Makefile.inc] as &#039;&#039;&amp;lt;chip name&amp;gt;_generic&#039;&#039; such as  &#039;&#039;stm32f103xb_generic&#039;&#039;. If you&#039;re writing an application for a board that has a chip with a generic BSP in the kernel, you can (unless you &#039;&#039;really&#039;&#039; need to run some custom code during boot) get away with selecting the generic BSP without forking the kernel. If there&#039;s no generic BSP for your chip, or need to add support for an entirely new chip, then you&#039;ll have to fork the kernel to add it.&lt;br /&gt;
&lt;br /&gt;
Suppose you have a git repository called test, which is the repo of your application, and you would like to download the miosix-kernel repository as a git submodule. Then open a shell in the test repository and type&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git submodule init&lt;br /&gt;
git submodule add https://miosix.org/git-public/miosix-kernel.git miosix-kernel&lt;br /&gt;
cd miosix-kernel&lt;br /&gt;
git fetch origin&lt;br /&gt;
cd ..&lt;br /&gt;
git commit -a -m &amp;quot;Added miosix-kernel as a git submodule&amp;quot;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This solves the problem from the git side, now let&#039;s solve the problem from the Miosix side. As you may know, git submodules work well if you never make changes in the submodule directory, otherwise you will have to basically fork the submodule, or you will find yourself making changes to a repository in a detached head state and risk losing them at the next git pull.&lt;br /&gt;
&lt;br /&gt;
However, the &#039;&#039;Makefile&#039;&#039; for Miosix, as well as configuration files such as [[Makefile.inc|miosix/config/Makefile.inc]] and [[miosix_settings.h|miosix/config/miosix_settings.h]] are within the submodule directory, so how are you going to make use of the kernel without touching files in the submodule directory?&lt;br /&gt;
&lt;br /&gt;
The solution is out of git tree projects, a new feature added in Miosix 2.0 that basically moves the &#039;&#039;main.cpp&#039;&#039;, &#039;&#039;Makefile&#039;&#039;, &#039;&#039;config&#039;&#039; directory, and the Netbeans IDE project directory outside of the git repository, using tweaks to the &#039;&#039;Makefile&#039;&#039; paths so that the kernel will find the &#039;&#039;config&#039;&#039; directory outside of the kernel, not the one inside it. &lt;br /&gt;
&lt;br /&gt;
To get started with out of git tree projects, there is a perl script that is used to easily set everything up. For example, suppose you are in the directory of your git repository where you have added the &#039;&#039;miosix-kernel&#039;&#039; submodule, and want to set up an out of git tree project there, open a shell and type&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
perl miosix-kernel/miosix/_tools/init_project_out_of_git_tree.pl&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The script will create a Miosix out of git tree project in the directory it is called, basically creating a &#039;&#039;config&#039;&#039; directory with a copy of the configuration files you can edit, a &#039;&#039;Makefile&#039;&#039; and a &#039;&#039;main.cpp&#039;&#039; as usual, as well as a new &#039;&#039;miosix_np_2&#039;&#039; directory with a Netbeans IDE project.&lt;br /&gt;
&lt;br /&gt;
The main advantage of this solution is that it keeps your application and the kernel in two separate git repositories. The disadvantage is that if you need to make changes to the kernel other than to configuration files, you will need to clone the miosix-kernel repository anyway, as well as having to manage the complexity of having two git repositories.&lt;br /&gt;
&lt;br /&gt;
= Forking the Miosix git repository =&lt;br /&gt;
&lt;br /&gt;
Forking the Miosix git repository simply means cloning the kernel repository and start making changes within the kernel. To clone the git repository you simply type the following commands:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git clone https://miosix.org/git-public/miosix-kernel.git&lt;br /&gt;
cd miosix-kernel&lt;br /&gt;
git checkout testing&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The Miosix top-level directory contains the following files and subdirectories:&lt;br /&gt;
&lt;br /&gt;
[[File:Miosix-top-level-directory.png]]&lt;br /&gt;
&lt;br /&gt;
The [https://github.com/fedetft/miosix-kernel/blob/master/README.md README.md] file contains more detailed information on how the kernel source code directory tree is structured, but a quick overview is that the entire kernel code is in the &#039;&#039;miosix&#039;&#039; subdirectory, &#039;&#039;templates&#039;&#039; contains application templates you can copy out of the kernel directory to create your out of tree projects, &#039;&#039;examples&#039;&#039; contains some demos of the Miosix APIs, wile &#039;&#039;tools&#039;&#039; contains scripts and support code that does not get compiled into the kernel. It also contains the scripts and patches used to build the [[Miosix Toolchain]], the GCC-based cross compiler used to build the kernel.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Making changes ===&lt;br /&gt;
&lt;br /&gt;
Once you start making changes you can simply commit in the cloned git repository. If you need to share your changes, perhaps because there are multiple developers, git allows to have multiple remotes for a repository, so you can leave the default remote to periodically pull updates and bugfixes from the upstream Miosix repository, as well as push and pull from your personal remote repository.&lt;br /&gt;
&lt;br /&gt;
== Contributing to Miosix ==&lt;br /&gt;
&lt;br /&gt;
Miosix uses a shared ownership model, meaning that you retain the copyright for the contributions you add to the kernel. Your contributions should however be licensed with the same license of the rest of the kernel:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=CPP&amp;gt;&lt;br /&gt;
/***************************************************************************&lt;br /&gt;
 *   Copyright (C) &amp;lt;year&amp;gt; by &amp;lt;your name&amp;gt;                                   *&lt;br /&gt;
 *                                                                         *&lt;br /&gt;
 *   This program is free software; you can redistribute it and/or modify  *&lt;br /&gt;
 *   it under the terms of the GNU General Public License as published by  *&lt;br /&gt;
 *   the Free Software Foundation; either version 2 of the License, or     *&lt;br /&gt;
 *   (at your option) any later version.                                   *&lt;br /&gt;
 *                                                                         *&lt;br /&gt;
 *   This program is distributed in the hope that it will be useful,       *&lt;br /&gt;
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *&lt;br /&gt;
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *&lt;br /&gt;
 *   GNU General Public License for more details.                          *&lt;br /&gt;
 *                                                                         *&lt;br /&gt;
 *   As a special exception, if other files instantiate templates or use   *&lt;br /&gt;
 *   macros or inline functions from this file, or you compile this file   *&lt;br /&gt;
 *   and link it with other works to produce a work based on this file,    *&lt;br /&gt;
 *   this file does not by itself cause the resulting work to be covered   *&lt;br /&gt;
 *   by the GNU General Public License. However the source code for this   *&lt;br /&gt;
 *   file must still be made available in accordance with the GNU General  *&lt;br /&gt;
 *   Public License. This exception does not invalidate any other reasons  *&lt;br /&gt;
 *   why a work based on this file might be covered by the GNU General     *&lt;br /&gt;
 *   Public License.                                                       *&lt;br /&gt;
 *                                                                         *&lt;br /&gt;
 *   You should have received a copy of the GNU General Public License     *&lt;br /&gt;
 *   along with this program; if not, see &amp;lt;http://www.gnu.org/licenses/&amp;gt;   *&lt;br /&gt;
 ***************************************************************************/&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Be sure to add the copyright notice to all nontrivial source files. An example of a trivial source file would be a forwarding header such as [https://github.com/fedetft/miosix-kernel/blob/master/miosix/arch/cpu/armv8m/interfaces-impl/endianness_impl.h this one].&lt;br /&gt;
&lt;br /&gt;
If you wrote the file you want to add from scratch, just add your name to the copyright notice. If instead you copy-pasted the file from another one already present in the kernel and modified it (this often happens when making BSPs as there&#039;s almost always a similar BSP in the kernel to take inspiration from), just append your name to the list of authors of the file you copied.&lt;br /&gt;
&lt;br /&gt;
== Contributions guidelines ==&lt;br /&gt;
&lt;br /&gt;
Since we use github only as a mirror to our repository that we host on miosix.org, we do not accept pull requests. You will instead be required to make a [https://git-scm.com/docs/git-format-patch format-patch] with the changes you want to be pushed upstream and send it via email to fede.tft&amp;amp;&amp;amp;miosix.org (s/&amp;amp;&amp;amp;/@/). It may be a good idea to get in contact first to discuss the changes you want pushed upstream, especially if they include modifications to the kernel itself rather than being simply new BSPs.&lt;br /&gt;
&lt;br /&gt;
When submitting patches for inclusion, please make sure that commits are small and self-contained, in order to simplify the integration process.&lt;br /&gt;
&lt;br /&gt;
Your changes should apply to the latest &#039;&#039;testing&#039;&#039; branch. If changes are related to the kernel itself, we may request to rebase them on top of &#039;&#039;unstable&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
[[Category:Installation and Configuration]]&lt;/div&gt;</summary>
		<author><name>Fede.tft</name></author>
	</entry>
	<entry>
		<id>https://miosix.org/wiki/index.php?title=File:Miosix-top-level-directory.png&amp;diff=473</id>
		<title>File:Miosix-top-level-directory.png</title>
		<link rel="alternate" type="text/html" href="https://miosix.org/wiki/index.php?title=File:Miosix-top-level-directory.png&amp;diff=473"/>
		<updated>2026-05-15T08:37:35Z</updated>

		<summary type="html">&lt;p&gt;Fede.tft: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Miosix-top-level-directory&lt;/div&gt;</summary>
		<author><name>Fede.tft</name></author>
	</entry>
	<entry>
		<id>https://miosix.org/wiki/index.php?title=Miosix_and_git_workflow&amp;diff=472</id>
		<title>Miosix and git workflow</title>
		<link rel="alternate" type="text/html" href="https://miosix.org/wiki/index.php?title=Miosix_and_git_workflow&amp;diff=472"/>
		<updated>2026-05-15T08:15:52Z</updated>

		<summary type="html">&lt;p&gt;Fede.tft: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
= The Miosix git repository =&lt;br /&gt;
&lt;br /&gt;
Miosix uses the git version control system to manage the kernel source code. To download and use the kernel you have to clone its git repository. The main Miosix git repository is hosted on this website, miosix.org, but we have no web page where you can browse the kernel sources. For this, we use a [https://github.com/fedetft/miosix-kernel github mirror] and the two repositories will be always kept in sync.&lt;br /&gt;
&lt;br /&gt;
As the kernel is under active development, users are advised to periodically &#039;&#039;git fetch&#039;&#039; or check the [https://github.com/fedetft/miosix-kernel kernel page on github] to look for new features and bug fixes, and pull the changes if required.&lt;br /&gt;
&lt;br /&gt;
By default, when cloning a repository, git will download the &#039;&#039;master&#039;&#039; branch. Miosix offers two additional branches, &#039;&#039;testing&#039;&#039; and &#039;&#039;unstable&#039;&#039;, and you should be aware of the conventions we use for how we manage branches:&lt;br /&gt;
* The &#039;&#039;master&#039;&#039; branch contains the stable kernel, it is updated infrequently, usually once a year when a new release is made. Sometimes, a few minor releases are updated in short order.&lt;br /&gt;
* The &#039;&#039;testing&#039;&#039; branch contains the in-development code that we consider almost ready. Use this branch to get more bleeding edge features.&lt;br /&gt;
* The &#039;&#039;unstable&#039;&#039; branch is where the Miosix development team is working. It&#039;s meant to be used only by people in contact with the development team, as we occasionally rebase and force-push changes, so you may have a hard time keeping your git repository in sync with ours (the commit you downloaded today may no longer exist after a force push). If you&#039;re writing applications, it&#039;s best to ignore this branch and wait for the desired change to trickle to testing.&lt;br /&gt;
&lt;br /&gt;
Cloning the kernel repository from miosix.org can be done with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git clone https://miosix.org/git-public/miosix-kernel.git&lt;br /&gt;
cd miosix-kernel&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
While cloning the github mirror with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git clone https://github.com/fedetft/miosix-kernel.git&lt;br /&gt;
cd miosix-kernel&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To checkout a specific branch, once you have cloned the git repository, use the following command&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git checkout testing&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The rest of this page explains how to set up a software project making use of the Miosix kernel, that can later allow updating the kernel through git without creating problems. There are basically two ways to do so:&lt;br /&gt;
&lt;br /&gt;
* Setting up out an out of git tree project: this is the suggested workflow for developing applications using Miosix. Your application directory and git repo stay separate from the kernel directory and git repo. The kernel can be a git submodule of your project.&lt;br /&gt;
* Forking the Miosix kernel git repository. This is the suggested workflow for extending the kernel, such as adding new board support packages (BSPs).&lt;br /&gt;
&lt;br /&gt;
The two workflows can be combined, for example you may want to fork the kernel to add your BSPs, and then use the forked kernel as submodule for developing your applications.&lt;br /&gt;
&lt;br /&gt;
== Setting up an out of git tree project == &lt;br /&gt;
&lt;br /&gt;
Out of git tree projects allow you to write applications in a directory that stays separate from the Miosix kernel directory. Additionally, they allow to perform the kernel configuration (that requires editing configuration files) without the need to make changes to files within the Miosix git repo &#039;&#039;at all&#039;&#039;. This last point is important both to have the Miosix git repository as a [http://www.git-scm.com/book/en/Git-Tools-Submodules git submodule] of your application&#039;s git repository, and to allow sharing the same downloaded copy of the Miosix kernel across different applications, each with its own configuration. The kernel source code size on the hard drive has grown bigger in recent years due to the inclusion of headers with peripheral registers definitions in the [https://github.com/fedetft/miosix-kernel/tree/master/miosix/arch/CMSIS CMSIS] directory, so you may want to share a single downloaded copy of the kernel across several projects.&lt;br /&gt;
&lt;br /&gt;
Note that the ability to develop applications without making changes to the kernel directory is currently limited to the use case of configuring the kernel for one of the available BSPs. If you need to add BSPs to the kernel, then you&#039;ll most likely also have to fork the kernel repository. The &#039;&#039;most likely&#039;&#039; is due to &#039;&#039;generic&#039;&#039; BSPs in the kernel, which can be identified in the list of boards in [https://github.com/fedetft/miosix-kernel/blob/master/miosix/config/Makefile.inc Makefile.inc] as &#039;&#039;&amp;lt;chip name&amp;gt;_generic&#039;&#039; such as  &#039;&#039;stm32f103xb_generic&#039;&#039;. If you&#039;re writing an application for a board that has a chip with a generic BSP in the kernel, you can (unless you &#039;&#039;really&#039;&#039; need to run some custom code during boot) get away with selecting the generic BSP without forking the kernel. If there&#039;s no generic BSP for your chip, or need to add support for an entirely new chip, then you&#039;ll have to fork the kernel to add it.&lt;br /&gt;
&lt;br /&gt;
Suppose you have a git repository called test, which is the repo of your application, and you would like to download the miosix-kernel repository as a git submodule. Then open a shell in the test repository and type&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git submodule init&lt;br /&gt;
git submodule add https://miosix.org/git-public/miosix-kernel.git miosix-kernel&lt;br /&gt;
cd miosix-kernel&lt;br /&gt;
git fetch origin&lt;br /&gt;
cd ..&lt;br /&gt;
git commit -a -m &amp;quot;Added miosix-kernel as a git submodule&amp;quot;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This solves the problem from the git side, now let&#039;s solve the problem from the Miosix side. As you may know, git submodules work well if you never make changes in the submodule directory, otherwise you will have to basically fork the submodule, or you will find yourself making changes to a repository in a detached head state and risk losing them at the next git pull.&lt;br /&gt;
&lt;br /&gt;
However, the &#039;&#039;Makefile&#039;&#039; for Miosix, as well as configuration files such as [[Makefile.inc|miosix/config/Makefile.inc]] and [[miosix_settings.h|miosix/config/miosix_settings.h]] are within the submodule directory, so how are you going to make use of the kernel without touching files in the submodule directory?&lt;br /&gt;
&lt;br /&gt;
The solution is out of git tree projects, a new feature added in Miosix 2.0 that basically moves the &#039;&#039;main.cpp&#039;&#039;, &#039;&#039;Makefile&#039;&#039;, &#039;&#039;config&#039;&#039; directory, and the Netbeans IDE project directory outside of the git repository, using tweaks to the &#039;&#039;Makefile&#039;&#039; paths so that the kernel will find the &#039;&#039;config&#039;&#039; directory outside of the kernel, not the one inside it. &lt;br /&gt;
&lt;br /&gt;
To get started with out of git tree projects, there is a perl script that is used to easily set everything up. For example, suppose you are in the directory of your git repository where you have added the &#039;&#039;miosix-kernel&#039;&#039; submodule, and want to set up an out of git tree project there, open a shell and type&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
perl miosix-kernel/miosix/_tools/init_project_out_of_git_tree.pl&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The script will create a Miosix out of git tree project in the directory it is called, basically creating a &#039;&#039;config&#039;&#039; directory with a copy of the configuration files you can edit, a &#039;&#039;Makefile&#039;&#039; and a &#039;&#039;main.cpp&#039;&#039; as usual, as well as a new &#039;&#039;miosix_np_2&#039;&#039; directory with a Netbeans IDE project.&lt;br /&gt;
&lt;br /&gt;
The main advantage of this solution is that it keeps your application and the kernel in two separate git repositories. The disadvantage is that if you need to make changes to the kernel other than to configuration files, you will need to clone the miosix-kernel repository anyway, as well as having to manage the complexity of having two git repositories.&lt;br /&gt;
&lt;br /&gt;
== Forking the Miosix git repository ==&lt;br /&gt;
&lt;br /&gt;
Forking the Miosix git repository simply means cloning the kernel repository and starting to write your application there. To clone the git repository you simply type the following commands:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git clone https://miosix.org/git-public/miosix-kernel.git&lt;br /&gt;
cd miosix-kernel&lt;br /&gt;
git fetch origin&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will create a directory, &#039;&#039;miosix-kernel&#039;&#039; on your filesystem. Within that directory, which is also called the Miosix &#039;&#039;&#039;top-level directory&#039;&#039;&#039; there are two more directories, &#039;&#039;miosix&#039;&#039; which contains the kernel sources, and &#039;&#039;miosix_np_2&#039;&#039; with the Netbeans IDE project files. Lastly, there are two files, &#039;&#039;main.cpp&#039;&#039;, where it is possible to start writing your application, and a &#039;&#039;Makefile&#039;&#039; where you can add other C or C++ source files to be compiled.&lt;br /&gt;
&lt;br /&gt;
[[File:Miosixtopleveldirectorylinux.png]]&lt;br /&gt;
&lt;br /&gt;
The top-level directory has been kept free of clutter, so as to invite users to write applications directly there.&lt;br /&gt;
&lt;br /&gt;
=== Making changes ===&lt;br /&gt;
&lt;br /&gt;
Once you start making changes you can simply commit in the cloned git repository. If you need to share your changes, perhaps because there are multiple developers, git allows to have multiple remotes for a repository, so you can leave the default remote to periodically pull updates and bugfixes from the upstream Miosix repository, as well as push and pull from your personal remote repository.&lt;br /&gt;
&lt;br /&gt;
The main advantage of this approach is that everything, both the kernel and your code are under a single git repository, so you don&#039;t have to manage multiple repositories.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Contributing to Miosix =&lt;br /&gt;
&lt;br /&gt;
If you make changes to the kernel and want to contribute them back to mainline Miosix, you can get in contact via email with fede.tft&amp;amp;&amp;amp;miosix.org (s/&amp;amp;&amp;amp;/@/). You will be required to make a format-patch with the changes you want to be pushed upstream.&lt;br /&gt;
&lt;br /&gt;
If you plan to make significant contributions, please get in touch to discuss how to best integrate changes and streamline the process.&lt;br /&gt;
&lt;br /&gt;
== Contributions guidelines ==&lt;br /&gt;
&lt;br /&gt;
When submitting patches for inclusion, please make sure that commits are small and self-contained, in order to simplify the integration process.&lt;br /&gt;
&lt;br /&gt;
Make sure that commits that you propose for upstream inclusion do not contain changes to the following files and directories:&lt;br /&gt;
&lt;br /&gt;
* The top-level &#039;&#039;main.cpp&#039;&#039; and &#039;&#039;Makefile&#039;&#039;. If you add example code to test a new feature and want to contribute it back, consider adding it to &#039;&#039;_miosix/examples&#039;&#039; or &#039;&#039;_miosix/tools&#039;&#039; instead.&lt;br /&gt;
* The miosix_np_2 directory. If you work on Miosix using Netbeans, the IDE will make changes to files in this directory. These are local changes that only matter to you, and should not be included in patches.&lt;br /&gt;
* The configuration options in [[Makefile.inc|miosix/config/Makefile.inc]] and [[miosix_settings.h|miosix/config/miosix_settings.h]]. In detail, when compiling the kernel, you will have to make changes to select a board and tweak some options. These changes only matter to you, and should not be included in patches. If on the other hand you are adding configuration options, perhaps because you are porting Miosix to another board, then it is ok to include those changes in commits to be sent upstream.&lt;br /&gt;
&lt;br /&gt;
If you don&#039;t want to have changes to those files show up on each &#039;&#039;git status&#039;&#039;, together with the burden of remembering not to accidentally &#039;&#039;git add&#039;&#039; those, you can exclude those files from git by running the following commands&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git update-index --skip-worktree main.cpp   &lt;br /&gt;
git update-index --skip-worktree Makefile   &lt;br /&gt;
git update-index --skip-worktree miosix_np_2/&lt;br /&gt;
# These two only if you are sure that you will not make additions to those files that need to be pushed upstream&lt;br /&gt;
git update-index --skip-worktree miosix/config/Makefile.inc&lt;br /&gt;
git update-index --skip-worktree miosix/config/miosix_settings.h&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Keep in mind that doing so makes it more difficult to switch between branches, as changes to skipped files won&#039;t show up on &#039;&#039;git status&#039;&#039; but will prevent switching to another branch.&lt;br /&gt;
&lt;br /&gt;
Another way to enforce those rules is to use the out of git tree project feature that replicates all those files out of the git repository. If you are also using submodules, it is recommended to read the git documentation regarding submodules [https://www.git-scm.com/book/en/v2/Git-Tools-Submodules] in order to understand how to make changes to submodules.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Installation and Configuration]]&lt;/div&gt;</summary>
		<author><name>Fede.tft</name></author>
	</entry>
	<entry>
		<id>https://miosix.org/wiki/index.php?title=Miosix_and_git_workflow&amp;diff=471</id>
		<title>Miosix and git workflow</title>
		<link rel="alternate" type="text/html" href="https://miosix.org/wiki/index.php?title=Miosix_and_git_workflow&amp;diff=471"/>
		<updated>2026-05-15T08:13:20Z</updated>

		<summary type="html">&lt;p&gt;Fede.tft: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
= The Miosix git repository =&lt;br /&gt;
&lt;br /&gt;
Miosix uses the git version control system to manage the kernel source code. To download and use the kernel you have to clone its git repository. The main Miosix git repository is hosted on this website, miosix.org, but we have no web page where you can browse the kernel sources. For this, we use a [https://github.com/fedetft/miosix-kernel github mirror] and the two repositories will be always kept in sync.&lt;br /&gt;
&lt;br /&gt;
As the kernel is under active development, users are advised to periodically &#039;&#039;git fetch&#039;&#039; or check the [https://github.com/fedetft/miosix-kernel kernel page on github] to look for new features and bug fixes, and pull the changes if required.&lt;br /&gt;
&lt;br /&gt;
By default, when cloning a repository, git will download the &#039;&#039;master&#039;&#039; branch. Miosix offers two additional branches, &#039;&#039;testing&#039;&#039; and &#039;&#039;unstable&#039;&#039;, and you should be aware of the conventions we use for how we manage branches:&lt;br /&gt;
* The &#039;&#039;master&#039;&#039; branch contains the stable kernel, it is updated infrequently, usually once a year when a new release is made. Sometimes, a few minor releases are updated in short order.&lt;br /&gt;
* The &#039;&#039;testing&#039;&#039; branch contains the in-development code that we consider almost ready. Use this branch to get more bleeding edge features.&lt;br /&gt;
* The &#039;&#039;unstable&#039;&#039; branch is where the Miosix development team is working. It&#039;s meant to be used only by people in contact with the development team, as we occasionally rebase and force-push changes, so you may have a hard time keeping your git repository in sync with ours (the commit you downloaded today may no longer exist after a force push). If you&#039;re writing applications, it&#039;s best to ignore this branch and wait for the desired change to trickle to testing.&lt;br /&gt;
&lt;br /&gt;
Cloning the kernel repository from miosix.org can be done with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git clone https://miosix.org/git-public/miosix-kernel.git&lt;br /&gt;
cd miosix-kernel&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
While cloning the github mirror with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git clone https://github.com/fedetft/miosix-kernel.git&lt;br /&gt;
cd miosix-kernel&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To checkout a specific branch, once you have cloned the git repository, use the following command&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git checkout testing&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The rest of this page explains how to set up a software project making use of the Miosix kernel, that can later allow updating the kernel through git without creating problems. There are basically two ways to do so:&lt;br /&gt;
&lt;br /&gt;
* Setting up out an out of git tree project: this is the suggested workflow for developing applications using Miosix. Your application directory and git repo stay separate from the kernel directory and git repo. The kernel can be a git submodule of your project.&lt;br /&gt;
* Forking the Miosix kernel git repository. This is the suggested workflow for extending the kernel, such as adding new board support packages (BSPs).&lt;br /&gt;
&lt;br /&gt;
The two workflows can be combined, for example you may want to fork the kernel to add your BSPs, and then use the forked kernel as submodule for developing your applications.&lt;br /&gt;
&lt;br /&gt;
== Setting up an out of git tree project == &lt;br /&gt;
&lt;br /&gt;
Out of git tree projects allow you to write applications in a directory that stays separate from the Miosix kernel directory. Additionally, they allow to perform the kernel configuration (that requires editing configuration files) without the need to make changes to files within the Miosix git repo &#039;&#039;at all&#039;&#039;. This last point is important both to have the Miosix git repository as a [http://www.git-scm.com/book/en/Git-Tools-Submodules git submodule] of your application&#039;s git repository, and to allow sharing the same downloaded copy of the Miosix kernel across different applications, each with its own configuration. The kernel source code size on the hard drive has grown bigger in recent years due to the inclusion of headers with peripheral registers definitions in the [https://github.com/fedetft/miosix-kernel/tree/master/miosix/arch/CMSIS CMSIS] directory, so you may want to share a single downloaded copy of the kernel across several projects.&lt;br /&gt;
&lt;br /&gt;
Note that the ability to develop applications without making changes to the kernel directory is currently limited to the use case of configuring the kernel for one of the available BSPs. If you need to add BSPs to the kernel, then you&#039;ll most likely also have to fork the kernel repository. The &#039;&#039;most likely&#039;&#039; is due to &#039;&#039;generic&#039;&#039; BSPs in the kernel (which can be identified in the list of board as &#039;&#039;&amp;lt;chip name&amp;gt;_generic&#039;&#039; such as  &#039;&#039;stm32f103xb_generic&#039;&#039;). If you&#039;re writing an application for a board that has a chip with a generic BSP in the kernel, you can (unless you &#039;&#039;really&#039;&#039; need to run some custom code during boot) get away with selecting the generic BSP even though the board you&#039;re developing for has not BSP in the kernel. If there&#039;s no generic BSP for your chip, or need to add support for an entirely new chip, then you&#039;ll have to fork the kernel to add it.&lt;br /&gt;
&lt;br /&gt;
Suppose you have a git repository called test, which is the repo of your application, and you would like to download the miosix-kernel repository as a git submodule. Then open a shell in the test repository and type&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git submodule init&lt;br /&gt;
git submodule add https://miosix.org/git-public/miosix-kernel.git miosix-kernel&lt;br /&gt;
cd miosix-kernel&lt;br /&gt;
git fetch origin&lt;br /&gt;
cd ..&lt;br /&gt;
git commit -a -m &amp;quot;Added miosix-kernel as a git submodule&amp;quot;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This solves the problem from the git side, now let&#039;s solve the problem from the Miosix side. As you may know, git submodules work well if you never make changes in the submodule directory, otherwise you will have to basically fork the submodule, or you will find yourself making changes to a repository in a detached head state and risk losing them at the next git pull.&lt;br /&gt;
&lt;br /&gt;
However, the &#039;&#039;Makefile&#039;&#039; for Miosix, as well as configuration files such as [[Makefile.inc|miosix/config/Makefile.inc]] and [[miosix_settings.h|miosix/config/miosix_settings.h]] are within the submodule directory, so how are you going to make use of the kernel without touching files in the submodule directory?&lt;br /&gt;
&lt;br /&gt;
The solution is out of git tree projects, a new feature added in Miosix 2.0 that basically moves the &#039;&#039;main.cpp&#039;&#039;, &#039;&#039;Makefile&#039;&#039;, &#039;&#039;config&#039;&#039; directory, and the Netbeans IDE project directory outside of the git repository, using tweaks to the &#039;&#039;Makefile&#039;&#039; paths so that the kernel will find the &#039;&#039;config&#039;&#039; directory outside of the kernel, not the one inside it. &lt;br /&gt;
&lt;br /&gt;
To get started with out of git tree projects, there is a perl script that is used to easily set everything up. For example, suppose you are in the directory of your git repository where you have added the &#039;&#039;miosix-kernel&#039;&#039; submodule, and want to set up an out of git tree project there, open a shell and type&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
perl miosix-kernel/miosix/_tools/init_project_out_of_git_tree.pl&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The script will create a Miosix out of git tree project in the directory it is called, basically creating a &#039;&#039;config&#039;&#039; directory with a copy of the configuration files you can edit, a &#039;&#039;Makefile&#039;&#039; and a &#039;&#039;main.cpp&#039;&#039; as usual, as well as a new &#039;&#039;miosix_np_2&#039;&#039; directory with a Netbeans IDE project.&lt;br /&gt;
&lt;br /&gt;
The main advantage of this solution is that it keeps your application and the kernel in two separate git repositories. The disadvantage is that if you need to make changes to the kernel other than to configuration files, you will need to clone the miosix-kernel repository anyway, as well as having to manage the complexity of having two git repositories.&lt;br /&gt;
&lt;br /&gt;
== Forking the Miosix git repository ==&lt;br /&gt;
&lt;br /&gt;
Forking the Miosix git repository simply means cloning the kernel repository and starting to write your application there. To clone the git repository you simply type the following commands:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git clone https://miosix.org/git-public/miosix-kernel.git&lt;br /&gt;
cd miosix-kernel&lt;br /&gt;
git fetch origin&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will create a directory, &#039;&#039;miosix-kernel&#039;&#039; on your filesystem. Within that directory, which is also called the Miosix &#039;&#039;&#039;top-level directory&#039;&#039;&#039; there are two more directories, &#039;&#039;miosix&#039;&#039; which contains the kernel sources, and &#039;&#039;miosix_np_2&#039;&#039; with the Netbeans IDE project files. Lastly, there are two files, &#039;&#039;main.cpp&#039;&#039;, where it is possible to start writing your application, and a &#039;&#039;Makefile&#039;&#039; where you can add other C or C++ source files to be compiled.&lt;br /&gt;
&lt;br /&gt;
[[File:Miosixtopleveldirectorylinux.png]]&lt;br /&gt;
&lt;br /&gt;
The top-level directory has been kept free of clutter, so as to invite users to write applications directly there.&lt;br /&gt;
&lt;br /&gt;
=== Making changes ===&lt;br /&gt;
&lt;br /&gt;
Once you start making changes you can simply commit in the cloned git repository. If you need to share your changes, perhaps because there are multiple developers, git allows to have multiple remotes for a repository, so you can leave the default remote to periodically pull updates and bugfixes from the upstream Miosix repository, as well as push and pull from your personal remote repository.&lt;br /&gt;
&lt;br /&gt;
The main advantage of this approach is that everything, both the kernel and your code are under a single git repository, so you don&#039;t have to manage multiple repositories.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Contributing to Miosix =&lt;br /&gt;
&lt;br /&gt;
If you make changes to the kernel and want to contribute them back to mainline Miosix, you can get in contact via email with fede.tft&amp;amp;&amp;amp;miosix.org (s/&amp;amp;&amp;amp;/@/). You will be required to make a format-patch with the changes you want to be pushed upstream.&lt;br /&gt;
&lt;br /&gt;
If you plan to make significant contributions, please get in touch to discuss how to best integrate changes and streamline the process.&lt;br /&gt;
&lt;br /&gt;
== Contributions guidelines ==&lt;br /&gt;
&lt;br /&gt;
When submitting patches for inclusion, please make sure that commits are small and self-contained, in order to simplify the integration process.&lt;br /&gt;
&lt;br /&gt;
Make sure that commits that you propose for upstream inclusion do not contain changes to the following files and directories:&lt;br /&gt;
&lt;br /&gt;
* The top-level &#039;&#039;main.cpp&#039;&#039; and &#039;&#039;Makefile&#039;&#039;. If you add example code to test a new feature and want to contribute it back, consider adding it to &#039;&#039;_miosix/examples&#039;&#039; or &#039;&#039;_miosix/tools&#039;&#039; instead.&lt;br /&gt;
* The miosix_np_2 directory. If you work on Miosix using Netbeans, the IDE will make changes to files in this directory. These are local changes that only matter to you, and should not be included in patches.&lt;br /&gt;
* The configuration options in [[Makefile.inc|miosix/config/Makefile.inc]] and [[miosix_settings.h|miosix/config/miosix_settings.h]]. In detail, when compiling the kernel, you will have to make changes to select a board and tweak some options. These changes only matter to you, and should not be included in patches. If on the other hand you are adding configuration options, perhaps because you are porting Miosix to another board, then it is ok to include those changes in commits to be sent upstream.&lt;br /&gt;
&lt;br /&gt;
If you don&#039;t want to have changes to those files show up on each &#039;&#039;git status&#039;&#039;, together with the burden of remembering not to accidentally &#039;&#039;git add&#039;&#039; those, you can exclude those files from git by running the following commands&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git update-index --skip-worktree main.cpp   &lt;br /&gt;
git update-index --skip-worktree Makefile   &lt;br /&gt;
git update-index --skip-worktree miosix_np_2/&lt;br /&gt;
# These two only if you are sure that you will not make additions to those files that need to be pushed upstream&lt;br /&gt;
git update-index --skip-worktree miosix/config/Makefile.inc&lt;br /&gt;
git update-index --skip-worktree miosix/config/miosix_settings.h&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Keep in mind that doing so makes it more difficult to switch between branches, as changes to skipped files won&#039;t show up on &#039;&#039;git status&#039;&#039; but will prevent switching to another branch.&lt;br /&gt;
&lt;br /&gt;
Another way to enforce those rules is to use the out of git tree project feature that replicates all those files out of the git repository. If you are also using submodules, it is recommended to read the git documentation regarding submodules [https://www.git-scm.com/book/en/v2/Git-Tools-Submodules] in order to understand how to make changes to submodules.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Installation and Configuration]]&lt;/div&gt;</summary>
		<author><name>Fede.tft</name></author>
	</entry>
	<entry>
		<id>https://miosix.org/wiki/index.php?title=Miosix_and_git_workflow&amp;diff=470</id>
		<title>Miosix and git workflow</title>
		<link rel="alternate" type="text/html" href="https://miosix.org/wiki/index.php?title=Miosix_and_git_workflow&amp;diff=470"/>
		<updated>2026-05-15T08:09:25Z</updated>

		<summary type="html">&lt;p&gt;Fede.tft: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
= The Miosix git repository =&lt;br /&gt;
&lt;br /&gt;
Miosix uses the git version control system to manage the kernel source code. To download and use the kernel you have to clone its git repository. The main Miosix git repository is hosted on this website, miosix.org, but we have no web page where you can browse the kernel sources. For this, we use a [https://github.com/fedetft/miosix-kernel github mirror] and the two repositories will be always kept in sync.&lt;br /&gt;
&lt;br /&gt;
As the kernel is under active development, users are advised to periodically &#039;&#039;git fetch&#039;&#039; or check the [https://github.com/fedetft/miosix-kernel kernel page on github] to look for new features and bug fixes, and pull the changes if required.&lt;br /&gt;
&lt;br /&gt;
By default, when cloning a repository, git will download the &#039;&#039;master&#039;&#039; branch. Miosix offers two additional branches, &#039;&#039;testing&#039;&#039; and &#039;&#039;unstable&#039;&#039;, and you should be aware of the conventions we use for how we manage branches:&lt;br /&gt;
* The &#039;&#039;master&#039;&#039; branch contains the stable kernel, it is updated infrequently, usually once a year when a new release is made. Sometimes, a few minor releases are updated in short order.&lt;br /&gt;
* The &#039;&#039;testing&#039;&#039; branch contains the in-development code that we consider almost ready. Use this branch to get more bleeding edge features.&lt;br /&gt;
* The &#039;&#039;unstable&#039;&#039; branch is where the Miosix development team is working. It&#039;s meant to be used only by people in contact with the development team, as we occasionally rebase and force-push changes, so you may have a hard time keeping your git repository in sync with ours (the commit you downloaded today may no longer exist after a force push). If you&#039;re writing applications, it&#039;s best to ignore this branch and wait for the desired change to trickle to testing.&lt;br /&gt;
&lt;br /&gt;
Cloning the kernel repository from miosix.org can be done with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git clone https://miosix.org/git-public/miosix-kernel.git&lt;br /&gt;
cd miosix-kernel&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
While cloning the github mirror with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git clone https://github.com/fedetft/miosix-kernel.git&lt;br /&gt;
cd miosix-kernel&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To checkout a specific branch, once you have cloned the git repository, use the following command&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git checkout testing&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The rest of this page explains how to set up a software project making use of the Miosix kernel, that can later allow updating the kernel through git without creating problems. There are basically two ways to do so:&lt;br /&gt;
&lt;br /&gt;
* Setting up out an out of git tree project: this is the suggested workflow for developing applications using Miosix. Your application directory and git repo stay separate from the kernel directory and git repo. The kernel can be a git submodule of your project.&lt;br /&gt;
* Forking the Miosix kernel git repository. This is the suggested workflow for extending the kernel, such as adding new board support packages (BSPs).&lt;br /&gt;
&lt;br /&gt;
The two workflows can be combined, for example you may want to fork the kernel to add your BSPs, and then use the forked kernel as submodule for developing your applications.&lt;br /&gt;
&lt;br /&gt;
== Setting up an out of git tree project == &lt;br /&gt;
&lt;br /&gt;
Out of git tree projects allow you to write applications in a directory that stays separate from the Miosix kernel directory. Additionally, they allow to perform the kernel configuration (that requires editing configuration files) without the need to make changes to files within the Miosix git repo &#039;&#039;at all&#039;&#039;. This last point is important both to have the Miosix git repository as a [http://www.git-scm.com/book/en/Git-Tools-Submodules git submodule] of your application&#039;s git repository, ad to allow sharing the same downloaded copy of the Miosix kernel across different applications, each with its own configuration. The kernel source code size on the hard drive has grown bigger in recent years due to the inclusion of headers with peripheral registers definitions in the [https://github.com/fedetft/miosix-kernel/tree/master/miosix/arch/CMSIS CMSIS] directory, so you may want to share a single downloaded copy of the kernel across several projects.&lt;br /&gt;
&lt;br /&gt;
Note that the ability to develop applications without making changes to the kernel directory is currently limited to the use case of configuring the kernel for one of the available BSPs. If you need to add BSPs to the kernel, then you&#039;ll most likely also have to fork the kernel repository. The &#039;&#039;most likely&#039;&#039; is due to &#039;&#039;generic&#039;&#039; BSPs in the kernel (which can be identified in the list of board as &#039;&#039;&amp;lt;chip name&amp;gt;_generic&#039;&#039; such as  &#039;&#039;stm32f103xb_generic&#039;&#039;). If you&#039;re writing an application for a board that has a chip with a generic BSP in the kernel, you can (unless you &#039;&#039;really&#039;&#039; need to run some custom code during boot) get away with selecting the generic BSP even though the board you&#039;re developing for has not BSP in the kernel. If there&#039;s no generic BSP for your chip, or need to add support for an entirely new chip, then you&#039;ll have to fork the kernel to add it.&lt;br /&gt;
&lt;br /&gt;
Suppose you have a git repository called test, which is the repo of your application, and you would like to download the miosix-kernel repository as a git submodule. Then open a shell in the test repository and type&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git submodule init&lt;br /&gt;
git submodule add https://miosix.org/git-public/miosix-kernel.git miosix-kernel&lt;br /&gt;
cd miosix-kernel&lt;br /&gt;
git fetch origin&lt;br /&gt;
cd ..&lt;br /&gt;
git commit -a -m &amp;quot;Added miosix-kernel as a git submodule&amp;quot;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This solves the problem from the git side, now let&#039;s solve the problem from the Miosix side. As you may know, git submodules work well if you never make changes in the submodule directory, otherwise you will have to basically fork the submodule, or you will find yourself making changes to a repository in a detached head state and risk losing them at the next git pull.&lt;br /&gt;
&lt;br /&gt;
However, the &#039;&#039;Makefile&#039;&#039; for Miosix, as well as configuration files such as [[Makefile.inc|miosix/config/Makefile.inc]] and [[miosix_settings.h|miosix/config/miosix_settings.h]] are within the submodule directory, so how are you going to make use of the kernel without touching files in the submodule directory?&lt;br /&gt;
&lt;br /&gt;
The solution is out of git tree projects, a new feature added in Miosix 2.0 that basically moves the &#039;&#039;main.cpp&#039;&#039;, &#039;&#039;Makefile&#039;&#039;, &#039;&#039;config&#039;&#039; directory, and the Netbeans IDE project directory outside of the git repository, using tweaks to the &#039;&#039;Makefile&#039;&#039; paths so that the kernel will find the &#039;&#039;config&#039;&#039; directory outside of the kernel, not the one inside it. &lt;br /&gt;
&lt;br /&gt;
To get started with out of git tree projects, there is a perl script that is used to easily set everything up. For example, suppose you are in the directory of your git repository where you have added the &#039;&#039;miosix-kernel&#039;&#039; submodule, and want to set up an out of git tree project there, open a shell and type&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
perl miosix-kernel/miosix/_tools/init_project_out_of_git_tree.pl&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The script will create a Miosix out of git tree project in the directory it is called, basically creating a &#039;&#039;config&#039;&#039; directory with a copy of the configuration files you can edit, a &#039;&#039;Makefile&#039;&#039; and a &#039;&#039;main.cpp&#039;&#039; as usual, as well as a new &#039;&#039;miosix_np_2&#039;&#039; directory with a Netbeans IDE project.&lt;br /&gt;
&lt;br /&gt;
The main advantage of this solution is that it keeps your application and the kernel in two separate git repositories. The disadvantage is that if you need to make changes to the kernel other than to configuration files, you will need to clone the miosix-kernel repository anyway, as well as having to manage the complexity of having two git repositories.&lt;br /&gt;
&lt;br /&gt;
== Forking the Miosix git repository ==&lt;br /&gt;
&lt;br /&gt;
Forking the Miosix git repository simply means cloning the kernel repository and starting to write your application there. To clone the git repository you simply type the following commands:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git clone https://miosix.org/git-public/miosix-kernel.git&lt;br /&gt;
cd miosix-kernel&lt;br /&gt;
git fetch origin&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will create a directory, &#039;&#039;miosix-kernel&#039;&#039; on your filesystem. Within that directory, which is also called the Miosix &#039;&#039;&#039;top-level directory&#039;&#039;&#039; there are two more directories, &#039;&#039;miosix&#039;&#039; which contains the kernel sources, and &#039;&#039;miosix_np_2&#039;&#039; with the Netbeans IDE project files. Lastly, there are two files, &#039;&#039;main.cpp&#039;&#039;, where it is possible to start writing your application, and a &#039;&#039;Makefile&#039;&#039; where you can add other C or C++ source files to be compiled.&lt;br /&gt;
&lt;br /&gt;
[[File:Miosixtopleveldirectorylinux.png]]&lt;br /&gt;
&lt;br /&gt;
The top-level directory has been kept free of clutter, so as to invite users to write applications directly there.&lt;br /&gt;
&lt;br /&gt;
=== Making changes ===&lt;br /&gt;
&lt;br /&gt;
Once you start making changes you can simply commit in the cloned git repository. If you need to share your changes, perhaps because there are multiple developers, git allows to have multiple remotes for a repository, so you can leave the default remote to periodically pull updates and bugfixes from the upstream Miosix repository, as well as push and pull from your personal remote repository.&lt;br /&gt;
&lt;br /&gt;
The main advantage of this approach is that everything, both the kernel and your code are under a single git repository, so you don&#039;t have to manage multiple repositories.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Contributing to Miosix =&lt;br /&gt;
&lt;br /&gt;
If you make changes to the kernel and want to contribute them back to mainline Miosix, you can get in contact via email with fede.tft&amp;amp;&amp;amp;miosix.org (s/&amp;amp;&amp;amp;/@/). You will be required to make a format-patch with the changes you want to be pushed upstream.&lt;br /&gt;
&lt;br /&gt;
If you plan to make significant contributions, please get in touch to discuss how to best integrate changes and streamline the process.&lt;br /&gt;
&lt;br /&gt;
== Contributions guidelines ==&lt;br /&gt;
&lt;br /&gt;
When submitting patches for inclusion, please make sure that commits are small and self-contained, in order to simplify the integration process.&lt;br /&gt;
&lt;br /&gt;
Make sure that commits that you propose for upstream inclusion do not contain changes to the following files and directories:&lt;br /&gt;
&lt;br /&gt;
* The top-level &#039;&#039;main.cpp&#039;&#039; and &#039;&#039;Makefile&#039;&#039;. If you add example code to test a new feature and want to contribute it back, consider adding it to &#039;&#039;_miosix/examples&#039;&#039; or &#039;&#039;_miosix/tools&#039;&#039; instead.&lt;br /&gt;
* The miosix_np_2 directory. If you work on Miosix using Netbeans, the IDE will make changes to files in this directory. These are local changes that only matter to you, and should not be included in patches.&lt;br /&gt;
* The configuration options in [[Makefile.inc|miosix/config/Makefile.inc]] and [[miosix_settings.h|miosix/config/miosix_settings.h]]. In detail, when compiling the kernel, you will have to make changes to select a board and tweak some options. These changes only matter to you, and should not be included in patches. If on the other hand you are adding configuration options, perhaps because you are porting Miosix to another board, then it is ok to include those changes in commits to be sent upstream.&lt;br /&gt;
&lt;br /&gt;
If you don&#039;t want to have changes to those files show up on each &#039;&#039;git status&#039;&#039;, together with the burden of remembering not to accidentally &#039;&#039;git add&#039;&#039; those, you can exclude those files from git by running the following commands&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git update-index --skip-worktree main.cpp   &lt;br /&gt;
git update-index --skip-worktree Makefile   &lt;br /&gt;
git update-index --skip-worktree miosix_np_2/&lt;br /&gt;
# These two only if you are sure that you will not make additions to those files that need to be pushed upstream&lt;br /&gt;
git update-index --skip-worktree miosix/config/Makefile.inc&lt;br /&gt;
git update-index --skip-worktree miosix/config/miosix_settings.h&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Keep in mind that doing so makes it more difficult to switch between branches, as changes to skipped files won&#039;t show up on &#039;&#039;git status&#039;&#039; but will prevent switching to another branch.&lt;br /&gt;
&lt;br /&gt;
Another way to enforce those rules is to use the out of git tree project feature that replicates all those files out of the git repository. If you are also using submodules, it is recommended to read the git documentation regarding submodules [https://www.git-scm.com/book/en/v2/Git-Tools-Submodules] in order to understand how to make changes to submodules.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Installation and Configuration]]&lt;/div&gt;</summary>
		<author><name>Fede.tft</name></author>
	</entry>
	<entry>
		<id>https://miosix.org/wiki/index.php?title=Miosix_and_git_workflow&amp;diff=469</id>
		<title>Miosix and git workflow</title>
		<link rel="alternate" type="text/html" href="https://miosix.org/wiki/index.php?title=Miosix_and_git_workflow&amp;diff=469"/>
		<updated>2026-05-15T08:05:27Z</updated>

		<summary type="html">&lt;p&gt;Fede.tft: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
= The Miosix git repository =&lt;br /&gt;
&lt;br /&gt;
Miosix uses the git version control system to manage the kernel source code. To download and use the kernel you have to clone its git repository. The main Miosix git repository is hosted on this website, miosix.org, but we have no web page where you can browse the kernel sources. For this, we use a [https://github.com/fedetft/miosix-kernel github mirror] and the two repositories will be always kept in sync.&lt;br /&gt;
&lt;br /&gt;
As the kernel is under active development, users are advised to periodically &#039;&#039;git fetch&#039;&#039; or check the [https://github.com/fedetft/miosix-kernel kernel page on github] to look for new features and bug fixes, and pull the changes if required.&lt;br /&gt;
&lt;br /&gt;
By default, when cloning a repository, git will download the &#039;&#039;master&#039;&#039; branch. Miosix offers two additional branches, &#039;&#039;testing&#039;&#039; and &#039;&#039;unstable&#039;&#039;, and you should be aware of the conventions we use for how we manage branches:&lt;br /&gt;
* The &#039;&#039;master&#039;&#039; branch contains the stable kernel, it is updated infrequently, usually once a year when a new release is made. Sometimes, a few minor releases are updated in short order.&lt;br /&gt;
* The &#039;&#039;testing&#039;&#039; branch contains the in-development code that we consider almost ready. Use this branch to get more bleeding edge features.&lt;br /&gt;
* The &#039;&#039;unstable&#039;&#039; branch is where the Miosix development team is working. It&#039;s meant to be used only by people in contact with the development team, as we occasionally rebase and force-push changes, so you may have a hard time keeping your git repository in sync with ours (the commit you downloaded today may no longer exist after a force push). If you&#039;re writing applications, it&#039;s best to ignore this branch and wait for the desired change to trickle to testing.&lt;br /&gt;
&lt;br /&gt;
Cloning the kernel repository from miosix.org can be done with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git clone https://miosix.org/git-public/miosix-kernel.git&lt;br /&gt;
cd miosix-kernel&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
While cloning the github mirror with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git clone https://github.com/fedetft/miosix-kernel.git&lt;br /&gt;
cd miosix-kernel&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To checkout a specific branch, once you have cloned the git repository, use the following command&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git checkout testing&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The rest of this page explains how to set up a software project making use of the Miosix kernel, that can later allow updating the kernel through git without creating problems. There are basically two ways to do so:&lt;br /&gt;
&lt;br /&gt;
* Setting up out an out of git tree project: this is the suggested workflow for developing applications using Miosix. Your application directory and git repo stay separate from the kernel directory and git repo. The kernel can be a git submodule of your project.&lt;br /&gt;
* Forking the Miosix kernel git repository. This is the suggested workflow for extending the kernel, such as adding new board support packages (BSPs).&lt;br /&gt;
&lt;br /&gt;
The two workflows can be combined, for example you may want to fork the kernel to add your BSPs, and then use the forked kernel as submodule for developing your applications.&lt;br /&gt;
&lt;br /&gt;
== Setting up an out of git tree project == &lt;br /&gt;
&lt;br /&gt;
Out of git tree projects allow you to write applications in a directory that stays separate from the Miosix kernel directory. Additionally, it allows to perform the kernel configuration (that requires editing configuration files) without the need to make changes to files within the Miosix git repo &#039;&#039;at all&#039;&#039;. This last point is important both to have the miosix git repository as a [http://www.git-scm.com/book/en/Git-Tools-Submodules git submodule] of your application&#039;s git repository, ad to allow sharing the same downloaded copy of the Miosix kernel across different applications, each with its own configuration.&lt;br /&gt;
&lt;br /&gt;
Note that the ability to develop applications without making changes to the kernel directory is currently limited to the use case of configuring the kernel for one of the available BSPs. If you need to add BSPs to the kernel, then you&#039;ll most likely also have to fork the kernel repository. The &#039;&#039;most likely&#039;&#039; is due to &#039;&#039;generic&#039;&#039; BSPs in the kernel (which can be identified in the list of board as &#039;&#039;&amp;lt;chip name&amp;gt;_generic&#039;&#039; such as  &#039;&#039;stm32f103xb_generic&#039;&#039;). If you&#039;re writing an application for a board that has a chip with a generic BSP in the kernel, you can (unless you &#039;&#039;really&#039;&#039; need to run some custom code during boot) get away with selecting the generic BSP even though the board you&#039;re developing for has not BSP in the kernel. If there&#039;s no generic BSP for your chip, or need to add support for an entirely new chip, then you&#039;ll have to fork the kernel to add it.&lt;br /&gt;
&lt;br /&gt;
Suppose you have a git repository called test, which is the repo of your application, and you would like to download the miosix-kernel repository as a git submodule. Then open a shell in the test repository and type&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git submodule init&lt;br /&gt;
git submodule add https://miosix.org/git-public/miosix-kernel.git miosix-kernel&lt;br /&gt;
cd miosix-kernel&lt;br /&gt;
git fetch origin&lt;br /&gt;
cd ..&lt;br /&gt;
git commit -a -m &amp;quot;Added miosix-kernel as a git submodule&amp;quot;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This solves the problem from the git side, now let&#039;s solve the problem from the Miosix side. As you may know, git submodules work well if you never make changes in the submodule directory, otherwise you will have to basically fork the submodule, or you will find yourself making changes to a repository in a detached head state and risk losing them at the next git pull.&lt;br /&gt;
&lt;br /&gt;
However, the &#039;&#039;Makefile&#039;&#039; for Miosix, as well as configuration files such as [[Makefile.inc|miosix/config/Makefile.inc]] and [[miosix_settings.h|miosix/config/miosix_settings.h]] are within the submodule directory, so how are you going to make use of the kernel without touching files in the submodule directory?&lt;br /&gt;
&lt;br /&gt;
The solution is out of git tree projects, a new feature added in Miosix 2.0 that basically moves the &#039;&#039;main.cpp&#039;&#039;, &#039;&#039;Makefile&#039;&#039;, &#039;&#039;config&#039;&#039; directory, and the Netbeans IDE project directory outside of the git repository, using tweaks to the &#039;&#039;Makefile&#039;&#039; paths so that the kernel will find the &#039;&#039;config&#039;&#039; directory outside of the kernel, not the one inside it. &lt;br /&gt;
&lt;br /&gt;
To get started with out of git tree projects, there is a perl script that is used to easily set everything up. For example, suppose you are in the directory of your git repository where you have added the &#039;&#039;miosix-kernel&#039;&#039; submodule, and want to set up an out of git tree project there, open a shell and type&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
perl miosix-kernel/miosix/_tools/init_project_out_of_git_tree.pl&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The script will create a Miosix out of git tree project in the directory it is called, basically creating a &#039;&#039;config&#039;&#039; directory with a copy of the configuration files you can edit, a &#039;&#039;Makefile&#039;&#039; and a &#039;&#039;main.cpp&#039;&#039; as usual, as well as a new &#039;&#039;miosix_np_2&#039;&#039; directory with a Netbeans IDE project.&lt;br /&gt;
&lt;br /&gt;
The main advantage of this solution is that it keeps your application and the kernel in two separate git repositories. The disadvantage is that if you need to make changes to the kernel other than to configuration files, you will need to clone the miosix-kernel repository anyway, as well as having to manage the complexity of having two git repositories.&lt;br /&gt;
&lt;br /&gt;
== Forking the Miosix git repository ==&lt;br /&gt;
&lt;br /&gt;
Forking the Miosix git repository simply means cloning the kernel repository and starting to write your application there. To clone the git repository you simply type the following commands:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git clone https://miosix.org/git-public/miosix-kernel.git&lt;br /&gt;
cd miosix-kernel&lt;br /&gt;
git fetch origin&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will create a directory, &#039;&#039;miosix-kernel&#039;&#039; on your filesystem. Within that directory, which is also called the Miosix &#039;&#039;&#039;top-level directory&#039;&#039;&#039; there are two more directories, &#039;&#039;miosix&#039;&#039; which contains the kernel sources, and &#039;&#039;miosix_np_2&#039;&#039; with the Netbeans IDE project files. Lastly, there are two files, &#039;&#039;main.cpp&#039;&#039;, where it is possible to start writing your application, and a &#039;&#039;Makefile&#039;&#039; where you can add other C or C++ source files to be compiled.&lt;br /&gt;
&lt;br /&gt;
[[File:Miosixtopleveldirectorylinux.png]]&lt;br /&gt;
&lt;br /&gt;
The top-level directory has been kept free of clutter, so as to invite users to write applications directly there.&lt;br /&gt;
&lt;br /&gt;
=== Making changes ===&lt;br /&gt;
&lt;br /&gt;
Once you start making changes you can simply commit in the cloned git repository. If you need to share your changes, perhaps because there are multiple developers, git allows to have multiple remotes for a repository, so you can leave the default remote to periodically pull updates and bugfixes from the upstream Miosix repository, as well as push and pull from your personal remote repository.&lt;br /&gt;
&lt;br /&gt;
The main advantage of this approach is that everything, both the kernel and your code are under a single git repository, so you don&#039;t have to manage multiple repositories.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Contributing to Miosix =&lt;br /&gt;
&lt;br /&gt;
If you make changes to the kernel and want to contribute them back to mainline Miosix, you can get in contact via email with fede.tft&amp;amp;&amp;amp;miosix.org (s/&amp;amp;&amp;amp;/@/). You will be required to make a format-patch with the changes you want to be pushed upstream.&lt;br /&gt;
&lt;br /&gt;
If you plan to make significant contributions, please get in touch to discuss how to best integrate changes and streamline the process.&lt;br /&gt;
&lt;br /&gt;
== Contributions guidelines ==&lt;br /&gt;
&lt;br /&gt;
When submitting patches for inclusion, please make sure that commits are small and self-contained, in order to simplify the integration process.&lt;br /&gt;
&lt;br /&gt;
Make sure that commits that you propose for upstream inclusion do not contain changes to the following files and directories:&lt;br /&gt;
&lt;br /&gt;
* The top-level &#039;&#039;main.cpp&#039;&#039; and &#039;&#039;Makefile&#039;&#039;. If you add example code to test a new feature and want to contribute it back, consider adding it to &#039;&#039;_miosix/examples&#039;&#039; or &#039;&#039;_miosix/tools&#039;&#039; instead.&lt;br /&gt;
* The miosix_np_2 directory. If you work on Miosix using Netbeans, the IDE will make changes to files in this directory. These are local changes that only matter to you, and should not be included in patches.&lt;br /&gt;
* The configuration options in [[Makefile.inc|miosix/config/Makefile.inc]] and [[miosix_settings.h|miosix/config/miosix_settings.h]]. In detail, when compiling the kernel, you will have to make changes to select a board and tweak some options. These changes only matter to you, and should not be included in patches. If on the other hand you are adding configuration options, perhaps because you are porting Miosix to another board, then it is ok to include those changes in commits to be sent upstream.&lt;br /&gt;
&lt;br /&gt;
If you don&#039;t want to have changes to those files show up on each &#039;&#039;git status&#039;&#039;, together with the burden of remembering not to accidentally &#039;&#039;git add&#039;&#039; those, you can exclude those files from git by running the following commands&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git update-index --skip-worktree main.cpp   &lt;br /&gt;
git update-index --skip-worktree Makefile   &lt;br /&gt;
git update-index --skip-worktree miosix_np_2/&lt;br /&gt;
# These two only if you are sure that you will not make additions to those files that need to be pushed upstream&lt;br /&gt;
git update-index --skip-worktree miosix/config/Makefile.inc&lt;br /&gt;
git update-index --skip-worktree miosix/config/miosix_settings.h&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Keep in mind that doing so makes it more difficult to switch between branches, as changes to skipped files won&#039;t show up on &#039;&#039;git status&#039;&#039; but will prevent switching to another branch.&lt;br /&gt;
&lt;br /&gt;
Another way to enforce those rules is to use the out of git tree project feature that replicates all those files out of the git repository. If you are also using submodules, it is recommended to read the git documentation regarding submodules [https://www.git-scm.com/book/en/v2/Git-Tools-Submodules] in order to understand how to make changes to submodules.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Installation and Configuration]]&lt;/div&gt;</summary>
		<author><name>Fede.tft</name></author>
	</entry>
	<entry>
		<id>https://miosix.org/wiki/index.php?title=Miosix_and_git_workflow&amp;diff=468</id>
		<title>Miosix and git workflow</title>
		<link rel="alternate" type="text/html" href="https://miosix.org/wiki/index.php?title=Miosix_and_git_workflow&amp;diff=468"/>
		<updated>2026-05-15T08:04:41Z</updated>

		<summary type="html">&lt;p&gt;Fede.tft: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
= The Miosix git repository =&lt;br /&gt;
&lt;br /&gt;
Miosix uses the git version control system to manage the kernel source code. To download and use the kernel you have to clone its git repository. The main Miosix git repository is hosted on this website, miosix.org, but we have no web page where you can browse the kernel sources. For this, we use a [https://github.com/fedetft/miosix-kernel github mirror] and the two repositories will be always kept in sync.&lt;br /&gt;
&lt;br /&gt;
As the kernel is under active development, users are advised to periodically &#039;&#039;git fetch&#039;&#039; or check the [https://github.com/fedetft/miosix-kernel kernel page on github] to look for new features and bug fixes, and pull the changes if required.&lt;br /&gt;
&lt;br /&gt;
By default, when cloning a repository, git will download the &#039;&#039;master&#039;&#039; branch. Miosix offers two additional branches, &#039;&#039;testing&#039;&#039; and &#039;&#039;unstable&#039;&#039;, and you should be aware of the conventions we use for how we manage branches:&lt;br /&gt;
* The &#039;&#039;master&#039;&#039; branch contains the stable kernel, it is updated infrequently, usually once a year when a new release is made. Sometimes, a few minor releases are updated in short order.&lt;br /&gt;
* The &#039;&#039;testing&#039;&#039; branch contains the in-development code that we consider almost ready. Use this branch to get more bleeding edge features.&lt;br /&gt;
* The &#039;&#039;unstable&#039;&#039; branch is where the Miosix development team is working. It&#039;s meant to be used only by people in contact with the development team, as we occasionally rebase and force-push changes, so you may have a hard time keeping your git repository in sync with ours (the commit you downloaded today may no longer exist after a force push). If you&#039;re writing applications, it&#039;s best to ignore this branch and wait for the desired change to trickle to testing.&lt;br /&gt;
&lt;br /&gt;
Cloning the kernel repository from miosix.org can be done with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git clone https://miosix.org/git-public/miosix-kernel.git&lt;br /&gt;
cd miosix-kernel&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
While cloning the github mirror with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git clone https://github.com/fedetft/miosix-kernel.git&lt;br /&gt;
cd miosix-kernel&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To checkout a specific branch, once you have cloned the git repository, use the following command&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git checkout testing&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The rest of this page explains how to set up a software project making use of the Miosix kernel, that can later allow updating the kernel through git without creating problems. There are basically two ways to do so:&lt;br /&gt;
&lt;br /&gt;
* Setting up out an out of git tree project: this is the suggested workflow for developing applications using Miosix. Your application directory and git repo stay separate from the kernel directory and git repo. The kernel can be a git submodule of your project.&lt;br /&gt;
* Forking the Miosix kernel git repository. This is the suggested workflow for extending the kernel, such as adding new board support packages (BSPs).&lt;br /&gt;
&lt;br /&gt;
The two workflows can be combined, for example you may want to fork the kernel to add your BSPs, and then use the forked kernel as submodule for developing your applications.&lt;br /&gt;
&lt;br /&gt;
== Setting up an out of git tree project == &lt;br /&gt;
&lt;br /&gt;
Out of git tree projects allow to write your application in your directory that stays separate from the Miosix kernel directory. Additionally, it allows to perform the kernel configuration (that requires editing configuration files) without the need to make changes to files within the Miosix git repo &#039;&#039;at all&#039;&#039;. This last point is important both to have the miosix git repository as a [http://www.git-scm.com/book/en/Git-Tools-Submodules git submodule] of your application&#039;s git repository, ad to allow sharing the same downloaded copy of the Miosix kernel across different applications, each with its own configuration.&lt;br /&gt;
&lt;br /&gt;
Note that the ability to develop applications without making changes to the kernel directory is currently limited to the use case of configuring the kernel for one of the available BSPs. If you need to add BSPs to the kernel, then you&#039;ll most likely also have to fork the kernel repository. The &#039;&#039;most likely&#039;&#039; is due to &#039;&#039;generic&#039;&#039; BSPs in the kernel (which can be identified in the list of board as &#039;&#039;&amp;lt;chip name&amp;gt;_generic&#039;&#039; such as  &#039;&#039;stm32f103xb_generic&#039;&#039;). If you&#039;re writing an application for a board that has a chip with a generic BSP in the kernel, you can (unless you &#039;&#039;really&#039;&#039; need to run some custom code during boot) get away with selecting the generic BSP even though the board you&#039;re developing for has not BSP in the kernel. If there&#039;s no generic BSP for your chip, or need to add support for an entirely new chip, then you&#039;ll have to fork the kernel to add it.&lt;br /&gt;
&lt;br /&gt;
Suppose you have a git repository called test, which is the repo of your application, and you would like to download the miosix-kernel repository as a git submodule. Then open a shell in the test repository and type&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git submodule init&lt;br /&gt;
git submodule add https://miosix.org/git-public/miosix-kernel.git miosix-kernel&lt;br /&gt;
cd miosix-kernel&lt;br /&gt;
git fetch origin&lt;br /&gt;
cd ..&lt;br /&gt;
git commit -a -m &amp;quot;Added miosix-kernel as a git submodule&amp;quot;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This solves the problem from the git side, now let&#039;s solve the problem from the Miosix side. As you may know, git submodules work well if you never make changes in the submodule directory, otherwise you will have to basically fork the submodule, or you will find yourself making changes to a repository in a detached head state and risk losing them at the next git pull.&lt;br /&gt;
&lt;br /&gt;
However, the &#039;&#039;Makefile&#039;&#039; for Miosix, as well as configuration files such as [[Makefile.inc|miosix/config/Makefile.inc]] and [[miosix_settings.h|miosix/config/miosix_settings.h]] are within the submodule directory, so how are you going to make use of the kernel without touching files in the submodule directory?&lt;br /&gt;
&lt;br /&gt;
The solution is out of git tree projects, a new feature added in Miosix 2.0 that basically moves the &#039;&#039;main.cpp&#039;&#039;, &#039;&#039;Makefile&#039;&#039;, &#039;&#039;config&#039;&#039; directory, and the Netbeans IDE project directory outside of the git repository, using tweaks to the &#039;&#039;Makefile&#039;&#039; paths so that the kernel will find the &#039;&#039;config&#039;&#039; directory outside of the kernel, not the one inside it. &lt;br /&gt;
&lt;br /&gt;
To get started with out of git tree projects, there is a perl script that is used to easily set everything up. For example, suppose you are in the directory of your git repository where you have added the &#039;&#039;miosix-kernel&#039;&#039; submodule, and want to set up an out of git tree project there, open a shell and type&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
perl miosix-kernel/miosix/_tools/init_project_out_of_git_tree.pl&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The script will create a Miosix out of git tree project in the directory it is called, basically creating a &#039;&#039;config&#039;&#039; directory with a copy of the configuration files you can edit, a &#039;&#039;Makefile&#039;&#039; and a &#039;&#039;main.cpp&#039;&#039; as usual, as well as a new &#039;&#039;miosix_np_2&#039;&#039; directory with a Netbeans IDE project.&lt;br /&gt;
&lt;br /&gt;
The main advantage of this solution is that it keeps your application and the kernel in two separate git repositories. The disadvantage is that if you need to make changes to the kernel other than to configuration files, you will need to clone the miosix-kernel repository anyway, as well as having to manage the complexity of having two git repositories.&lt;br /&gt;
&lt;br /&gt;
== Forking the Miosix git repository ==&lt;br /&gt;
&lt;br /&gt;
Forking the Miosix git repository simply means cloning the kernel repository and starting to write your application there. To clone the git repository you simply type the following commands:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git clone https://miosix.org/git-public/miosix-kernel.git&lt;br /&gt;
cd miosix-kernel&lt;br /&gt;
git fetch origin&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will create a directory, &#039;&#039;miosix-kernel&#039;&#039; on your filesystem. Within that directory, which is also called the Miosix &#039;&#039;&#039;top-level directory&#039;&#039;&#039; there are two more directories, &#039;&#039;miosix&#039;&#039; which contains the kernel sources, and &#039;&#039;miosix_np_2&#039;&#039; with the Netbeans IDE project files. Lastly, there are two files, &#039;&#039;main.cpp&#039;&#039;, where it is possible to start writing your application, and a &#039;&#039;Makefile&#039;&#039; where you can add other C or C++ source files to be compiled.&lt;br /&gt;
&lt;br /&gt;
[[File:Miosixtopleveldirectorylinux.png]]&lt;br /&gt;
&lt;br /&gt;
The top-level directory has been kept free of clutter, so as to invite users to write applications directly there.&lt;br /&gt;
&lt;br /&gt;
=== Making changes ===&lt;br /&gt;
&lt;br /&gt;
Once you start making changes you can simply commit in the cloned git repository. If you need to share your changes, perhaps because there are multiple developers, git allows to have multiple remotes for a repository, so you can leave the default remote to periodically pull updates and bugfixes from the upstream Miosix repository, as well as push and pull from your personal remote repository.&lt;br /&gt;
&lt;br /&gt;
The main advantage of this approach is that everything, both the kernel and your code are under a single git repository, so you don&#039;t have to manage multiple repositories.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Contributing to Miosix =&lt;br /&gt;
&lt;br /&gt;
If you make changes to the kernel and want to contribute them back to mainline Miosix, you can get in contact via email with fede.tft&amp;amp;&amp;amp;miosix.org (s/&amp;amp;&amp;amp;/@/). You will be required to make a format-patch with the changes you want to be pushed upstream.&lt;br /&gt;
&lt;br /&gt;
If you plan to make significant contributions, please get in touch to discuss how to best integrate changes and streamline the process.&lt;br /&gt;
&lt;br /&gt;
== Contributions guidelines ==&lt;br /&gt;
&lt;br /&gt;
When submitting patches for inclusion, please make sure that commits are small and self-contained, in order to simplify the integration process.&lt;br /&gt;
&lt;br /&gt;
Make sure that commits that you propose for upstream inclusion do not contain changes to the following files and directories:&lt;br /&gt;
&lt;br /&gt;
* The top-level &#039;&#039;main.cpp&#039;&#039; and &#039;&#039;Makefile&#039;&#039;. If you add example code to test a new feature and want to contribute it back, consider adding it to &#039;&#039;_miosix/examples&#039;&#039; or &#039;&#039;_miosix/tools&#039;&#039; instead.&lt;br /&gt;
* The miosix_np_2 directory. If you work on Miosix using Netbeans, the IDE will make changes to files in this directory. These are local changes that only matter to you, and should not be included in patches.&lt;br /&gt;
* The configuration options in [[Makefile.inc|miosix/config/Makefile.inc]] and [[miosix_settings.h|miosix/config/miosix_settings.h]]. In detail, when compiling the kernel, you will have to make changes to select a board and tweak some options. These changes only matter to you, and should not be included in patches. If on the other hand you are adding configuration options, perhaps because you are porting Miosix to another board, then it is ok to include those changes in commits to be sent upstream.&lt;br /&gt;
&lt;br /&gt;
If you don&#039;t want to have changes to those files show up on each &#039;&#039;git status&#039;&#039;, together with the burden of remembering not to accidentally &#039;&#039;git add&#039;&#039; those, you can exclude those files from git by running the following commands&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git update-index --skip-worktree main.cpp   &lt;br /&gt;
git update-index --skip-worktree Makefile   &lt;br /&gt;
git update-index --skip-worktree miosix_np_2/&lt;br /&gt;
# These two only if you are sure that you will not make additions to those files that need to be pushed upstream&lt;br /&gt;
git update-index --skip-worktree miosix/config/Makefile.inc&lt;br /&gt;
git update-index --skip-worktree miosix/config/miosix_settings.h&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Keep in mind that doing so makes it more difficult to switch between branches, as changes to skipped files won&#039;t show up on &#039;&#039;git status&#039;&#039; but will prevent switching to another branch.&lt;br /&gt;
&lt;br /&gt;
Another way to enforce those rules is to use the out of git tree project feature that replicates all those files out of the git repository. If you are also using submodules, it is recommended to read the git documentation regarding submodules [https://www.git-scm.com/book/en/v2/Git-Tools-Submodules] in order to understand how to make changes to submodules.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Installation and Configuration]]&lt;/div&gt;</summary>
		<author><name>Fede.tft</name></author>
	</entry>
	<entry>
		<id>https://miosix.org/wiki/index.php?title=Miosix_and_git_workflow&amp;diff=467</id>
		<title>Miosix and git workflow</title>
		<link rel="alternate" type="text/html" href="https://miosix.org/wiki/index.php?title=Miosix_and_git_workflow&amp;diff=467"/>
		<updated>2026-05-15T07:47:03Z</updated>

		<summary type="html">&lt;p&gt;Fede.tft: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
= The Miosix git repository =&lt;br /&gt;
&lt;br /&gt;
Miosix uses the git version control system to manage the kernel source code. To download and use the kernel you have to clone its git repository. The main Miosix git repository is hosted on this website, miosix.org, but we have no web page where you can browse the kernel sources. For this, we use a [https://github.com/fedetft/miosix-kernel github mirror] and the two repositories will be always kept in sync.&lt;br /&gt;
&lt;br /&gt;
As the kernel is under active development, users are advised to periodically &#039;&#039;git fetch&#039;&#039; or check the [https://github.com/fedetft/miosix-kernel kernel page on github] to look for new features and bug fixes, and pull the changes if required.&lt;br /&gt;
&lt;br /&gt;
By default, when cloning a repository, git will download the &#039;&#039;master&#039;&#039; branch. Miosix offers two additional branches, &#039;&#039;testing&#039;&#039; and &#039;&#039;unstable&#039;&#039;, and you should be aware of the conventions we use for how we manage branches:&lt;br /&gt;
* The &#039;&#039;master&#039;&#039; branch contains the stable kernel, it is updated infrequently, usually once a year when a new release is made. Sometimes, a few minor releases are updated in short order.&lt;br /&gt;
* The &#039;&#039;testing&#039;&#039; branch contains the in-development code that we consider almost ready. Use this branch to get more bleeding edge features.&lt;br /&gt;
* The &#039;&#039;unstable&#039;&#039; branch is where the Miosix development team is working. It&#039;s meant to be used only by people in contact with the development team, as we occasionally rebase and force-push changes, so you may have a hard time keeping your git repository in sync with ours (the commit you downloaded today may no longer exist after a force push). If you&#039;re writing applications, it&#039;s best to ignore this branch and wait for the desired change to trickle to testing.&lt;br /&gt;
&lt;br /&gt;
Cloning the kernel repository from miosix.org can be done with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git clone https://miosix.org/git-public/miosix-kernel.git&lt;br /&gt;
cd miosix-kernel&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
While cloning the github mirror with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git clone https://github.com/fedetft/miosix-kernel.git&lt;br /&gt;
cd miosix-kernel&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To checkout a specific branch, once you have cloned the git repository, use the following command&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git checkout testing&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The rest of this page explains how to set up a software project making use of the Miosix kernel, that can later allow updating the kernel through git without creating problems. There are basically two ways to do so:&lt;br /&gt;
&lt;br /&gt;
* Setting up out an out of git tree project: this is the suggested workflow for developing applications using Miosix. Your application directory and git repo stay separate from the kernel directory and git repo. The kernel can be a git submodule of your project.&lt;br /&gt;
* Forking the Miosix kernel git repository. This is the suggested workflow for extending the kernel, such as adding new board support packages (BSPs).&lt;br /&gt;
&lt;br /&gt;
The two workflows can be combined, for example you may want to fork the kernel to add your BSPs, and then use the forked kernel as submodule for developing your applications.&lt;br /&gt;
&lt;br /&gt;
== Setting up an out of git tree project == &lt;br /&gt;
&lt;br /&gt;
Out of git tree projects allow to write your application outside the Miosix top-level directory, without the need to make changes to files within the Miosix git repo &#039;&#039;at all&#039;&#039;. This allows to separate your application from Miosix, and was designed to have the miosix git repository as a [http://www.git-scm.com/book/en/Git-Tools-Submodules git submodule] of your application&#039;s git repository. This also allows to not have the source files of your application under any version control system, even though these days if you&#039;re writing code without a version control system you are really missing something.&lt;br /&gt;
&lt;br /&gt;
Suppose you have a git repository called test, which is the repo of your application, and you would like to download the miosix-kernel repository as a git submodule. Then open a shell in the test repository and type&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git submodule init&lt;br /&gt;
git submodule add https://miosix.org/git-public/miosix-kernel.git miosix-kernel&lt;br /&gt;
cd miosix-kernel&lt;br /&gt;
git fetch origin&lt;br /&gt;
cd ..&lt;br /&gt;
git commit -a -m &amp;quot;Added miosix-kernel as a git submodule&amp;quot;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This solves the problem from the git side, now let&#039;s solve the problem from the Miosix side. As you may know, git submodules work well if you never make changes in the submodule directory, otherwise you will have to basically fork the submodule, or you will find yourself making changes to a repository in a detached head state and risk losing them at the next git pull.&lt;br /&gt;
&lt;br /&gt;
However, the &#039;&#039;Makefile&#039;&#039; for Miosix, as well as configuration files such as [[Makefile.inc|miosix/config/Makefile.inc]] and [[miosix_settings.h|miosix/config/miosix_settings.h]] are within the submodule directory, so how are you going to make use of the kernel without touching files in the submodule directory?&lt;br /&gt;
&lt;br /&gt;
The solution is out of git tree projects, a new feature added in Miosix 2.0 that basically moves the &#039;&#039;main.cpp&#039;&#039;, &#039;&#039;Makefile&#039;&#039;, &#039;&#039;config&#039;&#039; directory, and the Netbeans IDE project directory outside of the git repository, using tweaks to the &#039;&#039;Makefile&#039;&#039; paths so that the kernel will find the &#039;&#039;config&#039;&#039; directory outside of the kernel, not the one inside it. &lt;br /&gt;
&lt;br /&gt;
To get started with out of git tree projects, there is a perl script that is used to easily set everything up. For example, suppose you are in the directory of your git repository where you have added the &#039;&#039;miosix-kernel&#039;&#039; submodule, and want to set up an out of git tree project there, open a shell and type&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
perl miosix-kernel/miosix/_tools/init_project_out_of_git_tree.pl&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The script will create a Miosix out of git tree project in the directory it is called, basically creating a &#039;&#039;config&#039;&#039; directory with a copy of the configuration files you can edit, a &#039;&#039;Makefile&#039;&#039; and a &#039;&#039;main.cpp&#039;&#039; as usual, as well as a new &#039;&#039;miosix_np_2&#039;&#039; directory with a Netbeans IDE project.&lt;br /&gt;
&lt;br /&gt;
The main advantage of this solution is that it keeps your application and the kernel in two separate git repositories. The disadvantage is that if you need to make changes to the kernel other than to configuration files, you will need to clone the miosix-kernel repository anyway, as well as having to manage the complexity of having two git repositories.&lt;br /&gt;
&lt;br /&gt;
== Forking the Miosix git repository ==&lt;br /&gt;
&lt;br /&gt;
Forking the Miosix git repository simply means cloning the kernel repository and starting to write your application there. To clone the git repository you simply type the following commands:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git clone https://miosix.org/git-public/miosix-kernel.git&lt;br /&gt;
cd miosix-kernel&lt;br /&gt;
git fetch origin&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will create a directory, &#039;&#039;miosix-kernel&#039;&#039; on your filesystem. Within that directory, which is also called the Miosix &#039;&#039;&#039;top-level directory&#039;&#039;&#039; there are two more directories, &#039;&#039;miosix&#039;&#039; which contains the kernel sources, and &#039;&#039;miosix_np_2&#039;&#039; with the Netbeans IDE project files. Lastly, there are two files, &#039;&#039;main.cpp&#039;&#039;, where it is possible to start writing your application, and a &#039;&#039;Makefile&#039;&#039; where you can add other C or C++ source files to be compiled.&lt;br /&gt;
&lt;br /&gt;
[[File:Miosixtopleveldirectorylinux.png]]&lt;br /&gt;
&lt;br /&gt;
The top-level directory has been kept free of clutter, so as to invite users to write applications directly there.&lt;br /&gt;
&lt;br /&gt;
=== Making changes ===&lt;br /&gt;
&lt;br /&gt;
Once you start making changes you can simply commit in the cloned git repository. If you need to share your changes, perhaps because there are multiple developers, git allows to have multiple remotes for a repository, so you can leave the default remote to periodically pull updates and bugfixes from the upstream Miosix repository, as well as push and pull from your personal remote repository.&lt;br /&gt;
&lt;br /&gt;
The main advantage of this approach is that everything, both the kernel and your code are under a single git repository, so you don&#039;t have to manage multiple repositories.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Contributing to Miosix =&lt;br /&gt;
&lt;br /&gt;
If you make changes to the kernel and want to contribute them back to mainline Miosix, you can get in contact via email with fede.tft&amp;amp;&amp;amp;miosix.org (s/&amp;amp;&amp;amp;/@/). You will be required to make a format-patch with the changes you want to be pushed upstream.&lt;br /&gt;
&lt;br /&gt;
If you plan to make significant contributions, please get in touch to discuss how to best integrate changes and streamline the process.&lt;br /&gt;
&lt;br /&gt;
== Contributions guidelines ==&lt;br /&gt;
&lt;br /&gt;
When submitting patches for inclusion, please make sure that commits are small and self-contained, in order to simplify the integration process.&lt;br /&gt;
&lt;br /&gt;
Make sure that commits that you propose for upstream inclusion do not contain changes to the following files and directories:&lt;br /&gt;
&lt;br /&gt;
* The top-level &#039;&#039;main.cpp&#039;&#039; and &#039;&#039;Makefile&#039;&#039;. If you add example code to test a new feature and want to contribute it back, consider adding it to &#039;&#039;_miosix/examples&#039;&#039; or &#039;&#039;_miosix/tools&#039;&#039; instead.&lt;br /&gt;
* The miosix_np_2 directory. If you work on Miosix using Netbeans, the IDE will make changes to files in this directory. These are local changes that only matter to you, and should not be included in patches.&lt;br /&gt;
* The configuration options in [[Makefile.inc|miosix/config/Makefile.inc]] and [[miosix_settings.h|miosix/config/miosix_settings.h]]. In detail, when compiling the kernel, you will have to make changes to select a board and tweak some options. These changes only matter to you, and should not be included in patches. If on the other hand you are adding configuration options, perhaps because you are porting Miosix to another board, then it is ok to include those changes in commits to be sent upstream.&lt;br /&gt;
&lt;br /&gt;
If you don&#039;t want to have changes to those files show up on each &#039;&#039;git status&#039;&#039;, together with the burden of remembering not to accidentally &#039;&#039;git add&#039;&#039; those, you can exclude those files from git by running the following commands&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git update-index --skip-worktree main.cpp   &lt;br /&gt;
git update-index --skip-worktree Makefile   &lt;br /&gt;
git update-index --skip-worktree miosix_np_2/&lt;br /&gt;
# These two only if you are sure that you will not make additions to those files that need to be pushed upstream&lt;br /&gt;
git update-index --skip-worktree miosix/config/Makefile.inc&lt;br /&gt;
git update-index --skip-worktree miosix/config/miosix_settings.h&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Keep in mind that doing so makes it more difficult to switch between branches, as changes to skipped files won&#039;t show up on &#039;&#039;git status&#039;&#039; but will prevent switching to another branch.&lt;br /&gt;
&lt;br /&gt;
Another way to enforce those rules is to use the out of git tree project feature that replicates all those files out of the git repository. If you are also using submodules, it is recommended to read the git documentation regarding submodules [https://www.git-scm.com/book/en/v2/Git-Tools-Submodules] in order to understand how to make changes to submodules.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Installation and Configuration]]&lt;/div&gt;</summary>
		<author><name>Fede.tft</name></author>
	</entry>
	<entry>
		<id>https://miosix.org/wiki/index.php?title=Miosix_and_git_workflow&amp;diff=466</id>
		<title>Miosix and git workflow</title>
		<link rel="alternate" type="text/html" href="https://miosix.org/wiki/index.php?title=Miosix_and_git_workflow&amp;diff=466"/>
		<updated>2026-05-15T07:41:12Z</updated>

		<summary type="html">&lt;p&gt;Fede.tft: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
= The Miosix git repository =&lt;br /&gt;
&lt;br /&gt;
Miosix uses the git version control system to manage the kernel source code. To download and use the kernel you have to clone its git repository. The main Miosix git repository is hosted on this website, miosix.org, but we have no web page where you can browse the kernel sources. For this, we use a [https://github.com/fedetft/miosix-kernel github mirror] and the two repositories will be always kept in sync.&lt;br /&gt;
&lt;br /&gt;
As the kernel is under active development, users are advised to periodically &#039;&#039;git fetch&#039;&#039; or check the [https://github.com/fedetft/miosix-kernel kernel page on github] to look for new features and bug fixes, and pull the changes if required.&lt;br /&gt;
&lt;br /&gt;
By default, when cloning a repository, git will download the &#039;&#039;master&#039;&#039; branch. Miosix offers two additional branches, &#039;&#039;testing&#039;&#039; and &#039;&#039;unstable&#039;&#039;, and you should be aware of the conventions we use for how we manage branches:&lt;br /&gt;
* The &#039;&#039;master&#039;&#039; branch contains the stable kernel, it is updated infrequently, usually once a year when a new release is made. Sometimes, a few minor releases are updated in short order.&lt;br /&gt;
* The &#039;&#039;testing&#039;&#039; branch contains the in-development code that we consider almost ready. Use this branch to get more bleeding edge features.&lt;br /&gt;
* The &#039;&#039;unstable&#039;&#039; branch is where the Miosix development team is working. It&#039;s meant to be used only by people in contact with the development team, as we occasionally rebase and force-push changes, so you may have a hard time keeping your git repository in sync with ours (the commit you downloaded today may no longer exist after a force push). If you&#039;re writing applications, it&#039;s best to ignore this branch and wait for the desired change to trickle to testing.&lt;br /&gt;
&lt;br /&gt;
Cloning the kernel repository from miosix.org can be done with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git clone https://miosix.org/git-public/miosix-kernel.git&lt;br /&gt;
cd miosix-kernel&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
While cloning the github mirror with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git clone https://github.com/fedetft/miosix-kernel.git&lt;br /&gt;
cd miosix-kernel&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To checkout a specific branch, once you have cloned the git repository, use the following command&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git checkout testing&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The rest of this page explains how to set up a software project making use of the Miosix kernel, that can later allow updating the kernel through git without creating problems. There are basically two ways to do so, forking the Miosix kernel git repository and developing your application there, or setting up out an out of git tree project.&lt;br /&gt;
&lt;br /&gt;
== Forking the Miosix git repository ==&lt;br /&gt;
&lt;br /&gt;
Forking the Miosix git repository simply means cloning the kernel repository and starting to write your application there. To clone the git repository you simply type the following commands:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git clone https://miosix.org/git-public/miosix-kernel.git&lt;br /&gt;
cd miosix-kernel&lt;br /&gt;
git fetch origin&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will create a directory, &#039;&#039;miosix-kernel&#039;&#039; on your filesystem. Within that directory, which is also called the Miosix &#039;&#039;&#039;top-level directory&#039;&#039;&#039; there are two more directories, &#039;&#039;miosix&#039;&#039; which contains the kernel sources, and &#039;&#039;miosix_np_2&#039;&#039; with the Netbeans IDE project files. Lastly, there are two files, &#039;&#039;main.cpp&#039;&#039;, where it is possible to start writing your application, and a &#039;&#039;Makefile&#039;&#039; where you can add other C or C++ source files to be compiled.&lt;br /&gt;
&lt;br /&gt;
[[File:Miosixtopleveldirectorylinux.png]]&lt;br /&gt;
&lt;br /&gt;
The top-level directory has been kept free of clutter, so as to invite users to write applications directly there.&lt;br /&gt;
&lt;br /&gt;
=== Making changes ===&lt;br /&gt;
&lt;br /&gt;
Once you start making changes you can simply commit in the cloned git repository. If you need to share your changes, perhaps because there are multiple developers, git allows to have multiple remotes for a repository, so you can leave the default remote to periodically pull updates and bugfixes from the upstream Miosix repository, as well as push and pull from your personal remote repository.&lt;br /&gt;
&lt;br /&gt;
The main advantage of this approach is that everything, both the kernel and your code are under a single git repository, so you don&#039;t have to manage multiple repositories.&lt;br /&gt;
&lt;br /&gt;
== Setting up an out of git tree project == &lt;br /&gt;
&lt;br /&gt;
Out of git tree projects allow to write your application outside the Miosix top-level directory, without the need to make changes to files within the Miosix git repo &#039;&#039;at all&#039;&#039;. This allows to separate your application from Miosix, and was designed to have the miosix git repository as a [http://www.git-scm.com/book/en/Git-Tools-Submodules git submodule] of your application&#039;s git repository. This also allows to not have the source files of your application under any version control system, even though these days if you&#039;re writing code without a version control system you are really missing something.&lt;br /&gt;
&lt;br /&gt;
Suppose you have a git repository called test, which is the repo of your application, and you would like to download the miosix-kernel repository as a git submodule. Then open a shell in the test repository and type&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git submodule init&lt;br /&gt;
git submodule add https://miosix.org/git-public/miosix-kernel.git miosix-kernel&lt;br /&gt;
cd miosix-kernel&lt;br /&gt;
git fetch origin&lt;br /&gt;
cd ..&lt;br /&gt;
git commit -a -m &amp;quot;Added miosix-kernel as a git submodule&amp;quot;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This solves the problem from the git side, now let&#039;s solve the problem from the Miosix side. As you may know, git submodules work well if you never make changes in the submodule directory, otherwise you will have to basically fork the submodule, or you will find yourself making changes to a repository in a detached head state and risk losing them at the next git pull.&lt;br /&gt;
&lt;br /&gt;
However, the &#039;&#039;Makefile&#039;&#039; for Miosix, as well as configuration files such as [[Makefile.inc|miosix/config/Makefile.inc]] and [[miosix_settings.h|miosix/config/miosix_settings.h]] are within the submodule directory, so how are you going to make use of the kernel without touching files in the submodule directory?&lt;br /&gt;
&lt;br /&gt;
The solution is out of git tree projects, a new feature added in Miosix 2.0 that basically moves the &#039;&#039;main.cpp&#039;&#039;, &#039;&#039;Makefile&#039;&#039;, &#039;&#039;config&#039;&#039; directory, and the Netbeans IDE project directory outside of the git repository, using tweaks to the &#039;&#039;Makefile&#039;&#039; paths so that the kernel will find the &#039;&#039;config&#039;&#039; directory outside of the kernel, not the one inside it. &lt;br /&gt;
&lt;br /&gt;
To get started with out of git tree projects, there is a perl script that is used to easily set everything up. For example, suppose you are in the directory of your git repository where you have added the &#039;&#039;miosix-kernel&#039;&#039; submodule, and want to set up an out of git tree project there, open a shell and type&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
perl miosix-kernel/miosix/_tools/init_project_out_of_git_tree.pl&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The script will create a Miosix out of git tree project in the directory it is called, basically creating a &#039;&#039;config&#039;&#039; directory with a copy of the configuration files you can edit, a &#039;&#039;Makefile&#039;&#039; and a &#039;&#039;main.cpp&#039;&#039; as usual, as well as a new &#039;&#039;miosix_np_2&#039;&#039; directory with a Netbeans IDE project.&lt;br /&gt;
&lt;br /&gt;
The main advantage of this solution is that it keeps your application and the kernel in two separate git repositories. The disadvantage is that if you need to make changes to the kernel other than to configuration files, you will need to clone the miosix-kernel repository anyway, as well as having to manage the complexity of having two git repositories.&lt;br /&gt;
&lt;br /&gt;
= Contributing to Miosix =&lt;br /&gt;
&lt;br /&gt;
If you make changes to the kernel and want to contribute them back to mainline Miosix, you can get in contact via email with fede.tft&amp;amp;&amp;amp;miosix.org (s/&amp;amp;&amp;amp;/@/). You will be required to make a format-patch with the changes you want to be pushed upstream.&lt;br /&gt;
&lt;br /&gt;
If you plan to make significant contributions, please get in touch to discuss how to best integrate changes and streamline the process.&lt;br /&gt;
&lt;br /&gt;
== Contributions guidelines ==&lt;br /&gt;
&lt;br /&gt;
When submitting patches for inclusion, please make sure that commits are small and self-contained, in order to simplify the integration process.&lt;br /&gt;
&lt;br /&gt;
Make sure that commits that you propose for upstream inclusion do not contain changes to the following files and directories:&lt;br /&gt;
&lt;br /&gt;
* The top-level &#039;&#039;main.cpp&#039;&#039; and &#039;&#039;Makefile&#039;&#039;. If you add example code to test a new feature and want to contribute it back, consider adding it to &#039;&#039;_miosix/examples&#039;&#039; or &#039;&#039;_miosix/tools&#039;&#039; instead.&lt;br /&gt;
* The miosix_np_2 directory. If you work on Miosix using Netbeans, the IDE will make changes to files in this directory. These are local changes that only matter to you, and should not be included in patches.&lt;br /&gt;
* The configuration options in [[Makefile.inc|miosix/config/Makefile.inc]] and [[miosix_settings.h|miosix/config/miosix_settings.h]]. In detail, when compiling the kernel, you will have to make changes to select a board and tweak some options. These changes only matter to you, and should not be included in patches. If on the other hand you are adding configuration options, perhaps because you are porting Miosix to another board, then it is ok to include those changes in commits to be sent upstream.&lt;br /&gt;
&lt;br /&gt;
If you don&#039;t want to have changes to those files show up on each &#039;&#039;git status&#039;&#039;, together with the burden of remembering not to accidentally &#039;&#039;git add&#039;&#039; those, you can exclude those files from git by running the following commands&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git update-index --skip-worktree main.cpp   &lt;br /&gt;
git update-index --skip-worktree Makefile   &lt;br /&gt;
git update-index --skip-worktree miosix_np_2/&lt;br /&gt;
# These two only if you are sure that you will not make additions to those files that need to be pushed upstream&lt;br /&gt;
git update-index --skip-worktree miosix/config/Makefile.inc&lt;br /&gt;
git update-index --skip-worktree miosix/config/miosix_settings.h&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Keep in mind that doing so makes it more difficult to switch between branches, as changes to skipped files won&#039;t show up on &#039;&#039;git status&#039;&#039; but will prevent switching to another branch.&lt;br /&gt;
&lt;br /&gt;
Another way to enforce those rules is to use the out of git tree project feature that replicates all those files out of the git repository. If you are also using submodules, it is recommended to read the git documentation regarding submodules [https://www.git-scm.com/book/en/v2/Git-Tools-Submodules] in order to understand how to make changes to submodules.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Installation and Configuration]]&lt;/div&gt;</summary>
		<author><name>Fede.tft</name></author>
	</entry>
	<entry>
		<id>https://miosix.org/wiki/index.php?title=MacOS_Quick_Start&amp;diff=465</id>
		<title>MacOS Quick Start</title>
		<link rel="alternate" type="text/html" href="https://miosix.org/wiki/index.php?title=MacOS_Quick_Start&amp;diff=465"/>
		<updated>2026-05-15T07:37:29Z</updated>

		<summary type="html">&lt;p&gt;Fede.tft: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{DISPLAYTITLE:macOS Quick Start}}&lt;br /&gt;
To be able to compile the Miosix kernel and your application, you need a patched version of the GCC compiler called [[Miosix Toolchain]]. This page explains how to install the precompiled Miosix Toolchain. If you prefer compiling GCC from sources, see [[Building GCC from sources]].&lt;br /&gt;
&lt;br /&gt;
Both macOS and Linux are POSIX-conformant Unix-like systems, therefore the steps required to get started with Miosix are very similar on both operating systems. This guide only covers the differences between the steps outlined in [[Linux Quick Start]] and the steps needed for macOS. Therefore reading the [[Linux Quick Start]] page first is recommended.&lt;br /&gt;
&lt;br /&gt;
== Before you begin ==&lt;br /&gt;
&lt;br /&gt;
=== Installing the Command Line Tools ===&lt;br /&gt;
&lt;br /&gt;
macOS provides essentials tools for developing software ([https://clang.llvm.org clang]-based C and C++ compilers, [https://git-scm.com git], and more) in a separate package called the &#039;&#039;Command Line Tools for Xcode&#039;&#039;. Despite the name, these tools do not require Xcode to be also installed, and since Xcode is a multi-gigabyte application which eats up quite the amount of disk space, you should &#039;&#039;&#039;not&#039;&#039;&#039; install Xcode, unless you are sure you need it for some other non-Miosix-related reason.&lt;br /&gt;
&lt;br /&gt;
To install the Command Line Tools open Terminal.app and then run the following command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
xcode-select --install&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then follow the instructions on screen to complete the installation.&lt;br /&gt;
&lt;br /&gt;
=== Installing STM32-specific tools ===&lt;br /&gt;
&lt;br /&gt;
STM32 microcontrollers are the most important target for Miosix, and programming them requires specialized tools which on Linux are often installed through a package manager.&lt;br /&gt;
&lt;br /&gt;
In contrast to Linux but similarly to Windows, macOS does not provide a system package manager. However, thanks to community efforts, there are two third-party package managers for macOS that provide a similar experience to Linux for easily installing tools and programs on the command line: [https://brew.sh Homebrew] and [https://www.macports.org MacPorts]. Both of them provide all packages you need to get started with development on STM32 MCUs.&lt;br /&gt;
&lt;br /&gt;
In the following discussion we will assume you have Homebrew available and installed on your system. If you prefer MacPorts, you can search the same packages (or &#039;ports&#039;) on the [https://ports.macports.org MacPorts port index].&lt;br /&gt;
&lt;br /&gt;
With Homebrew, installing st-flash and stm32flash can be performed through the following commands:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
brew install stlink&lt;br /&gt;
brew install stm32flash&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Homebrew, macOS, and filesystem permissions ====&lt;br /&gt;
&lt;br /&gt;
Homebrew specifically forbids being run with elevated privileges using &amp;lt;code&amp;gt;sudo&amp;lt;/code&amp;gt; when installing packages. This is different than what all other package managers (on Linux and macOS) do.&lt;br /&gt;
&lt;br /&gt;
[https://docs.brew.sh/FAQ#why-does-homebrew-say-sudo-is-bad According to Homebrew&#039;s developers], this approach purportedly has the advantage of reducing the attack surface of a hypothetic malware that modifies Homebrew&#039;s executables for malicious purposes, but it makes it possible for malware to modify all of the files installed by Homebrew easily (as executable distributed by Homebrew are often not signed).&lt;br /&gt;
&lt;br /&gt;
Other package managers such as MacPorts (or all Linux-based package managers for the various distributions) run as root (or as a specialized user with reduced privileges) in order to make it more difficult for malware to tamper any file in the package manager&#039;s prefix, and to prevent un-authorized users from modifying the set of packages installed.&lt;br /&gt;
&lt;br /&gt;
However tampering files installed by a package manager on macOS does not appear to be a popular attack vector for malware, thanks to the additional restrictions imposed on top of the standard Unix user permission system by the TCC subsystem in macOS ([https://eclecticlight.co/2023/02/11/permissions-sip-and-tcc-whos-controlling-access/ read this article] if you don&#039;t know what we are talking about). As a result the field importance of the security implications of Homebrew&#039;s choice about the ownership of all installed packages is not entirely clear.&lt;br /&gt;
&lt;br /&gt;
However, being aware of the tradeoff being made is something to be aware of before you choose to install Homebrew or MacPorts, depending on your security-related preferences.&lt;br /&gt;
&lt;br /&gt;
=== Serial port setup ===&lt;br /&gt;
&lt;br /&gt;
Serial port devices are available in &amp;lt;code&amp;gt;/dev&amp;lt;/code&amp;gt; just like in Linux, however macOS sets the permissions of the device files such that read and write access are available for all groups and users. There is no need to add you user to the &amp;lt;code&amp;gt;dialup&amp;lt;/code&amp;gt; group like on Linux.&lt;br /&gt;
&lt;br /&gt;
macOS ships with &amp;lt;code&amp;gt;screen&amp;lt;/code&amp;gt; built-in, there is no need to install it separately. If you find &amp;lt;code&amp;gt;screen&amp;lt;/code&amp;gt; uncomfortable to use for accessing serial ports, we recommend you use [https://github.com/tio/tio tio], which can be installed via Homebrew with this command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
brew install tio&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Install the Miosix Toolchain ==&lt;br /&gt;
&lt;br /&gt;
Download the latest version of the toolchain from the link provided in the [[Miosix Toolchain]] page. Choose the appropriate version to your Mac architecture, as newer Macs use ARM processors, while older ones use Intel processors. We provide native builds of the Miosix toolchain for both architectures. Make sure to install the macOS installable package, and not the Linux or Windows ones. Then you can install the toolchain by double-clicking the downloaded .pkg file.&lt;br /&gt;
&lt;br /&gt;
If the installer does not open and the following dialog box shows up:&lt;br /&gt;
&lt;br /&gt;
[[File:MacOS unidentified developer.png|The dialog box shown when Gatekeeper prevents opening an installer package.]]&lt;br /&gt;
&lt;br /&gt;
click with the right mouse button on the installer package (or click while pressing the &#039;&#039;control&#039;&#039; key on the keyboard) and select Open from the contextual menu. The dialog box will now let you open the package.&lt;br /&gt;
&lt;br /&gt;
Follow the steps presented by the assistant to install the Miosix toolchain on your system.&lt;br /&gt;
&lt;br /&gt;
== Get, configure, and compile the Miosix kernel sources ==&lt;br /&gt;
&lt;br /&gt;
At this point you can start following the steps outlined in [[Linux Quick Start#Configuring and compiling the kernel]] without modifications.&lt;br /&gt;
&lt;br /&gt;
Remember that there is no need to install &#039;&#039;git&#039;&#039; as it has been already installed as part of the Command Line Tools (if you have been following this guide to the letter).&lt;/div&gt;</summary>
		<author><name>Fede.tft</name></author>
	</entry>
	<entry>
		<id>https://miosix.org/wiki/index.php?title=Linux_Debugger_configuration&amp;diff=464</id>
		<title>Linux Debugger configuration</title>
		<link rel="alternate" type="text/html" href="https://miosix.org/wiki/index.php?title=Linux_Debugger_configuration&amp;diff=464"/>
		<updated>2026-05-10T21:44:46Z</updated>

		<summary type="html">&lt;p&gt;Fede.tft: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The debugging of Miosix on Linux can be done through [http://openocd.org/ OpenOCD], that creates a bridge between GDB and the JTAG device.&lt;br /&gt;
&lt;br /&gt;
= Setting up OpenOCD =&lt;br /&gt;
&lt;br /&gt;
== Install OpenOCD ==&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo apt install openocd # Install OpenOCD for Ubuntu/Debian&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Run OpenOCD ==&lt;br /&gt;
The OpenOCD configuration is included in the official Miosix distribution for most of the supported boards under the path &#039;miosix/arch/board/&amp;lt;board name&amp;gt;/openocd.cfg&#039;. For example for the stm32f429zi_stm32f4discovery board:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
openocd -f miosix/arch/board/stm32f429zi_stm32f4discovery/openocd.cfg&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
OpenOCD provides built-in configuration files for many boards, chips and debugging adapters. You can see the entire range of files in the directory &amp;lt;code&amp;gt;/usr/share/openocd/scripts&amp;lt;/code&amp;gt;. If Miosix does not provide a configuration file for you, in most cases there will be appropriate scripts available together with OpenOCD.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;If breakpoints don&#039;t work on your board&#039;&#039;&#039; you can try adding the option &amp;lt;code&amp;gt;-c &#039;gdb_breakpoint_override hard&#039;&amp;lt;/code&amp;gt; to the OpenOCD invocation. This option disables GDB software breakpoints and always forces the use of hardware breakpoints, which might be needed if OpenOCD provides an incomplete memory map to GDB.&lt;br /&gt;
&lt;br /&gt;
= Debugging with GDB =&lt;br /&gt;
The GDB used is provided by the official [[Miosix_Toolchain|Miosix Toolchain]]. Although the board is flashed with the &#039;&#039;.bin&#039;&#039; file, you&#039;ll have to pass the corresponding &#039;&#039;.elf&#039;&#039; file, since this file format includes debugging symbols.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
arm-miosix-eabi-gdb main.elf&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Connect GDB ==&lt;br /&gt;
OpenOCD provide a network interface for connect the debugger, the follow command is necessary for establish the connection:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
(gdb) target remote &amp;lt;ip&amp;gt;:&amp;lt;port&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The default socket is listening on port 3333 in the loopback interface of your computer. So you can use the default command:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
(gdb) target extended-remote :3333&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Reset the board ==&lt;br /&gt;
After the connection (and after each change of configuration) you must reset the board in a safe state:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
(gdb) monitor reset halt&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Using gdb ==&lt;br /&gt;
&lt;br /&gt;
This is not a full tutorial on using GDB, information can be found online. Here we only list the basics:&lt;br /&gt;
&lt;br /&gt;
Setting breakpoints can be done with the &#039;&#039;break&#039;&#039; command followed by the function name or source code line:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
(gdb) break main&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
(gdb) break main.cpp:30&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Running the board can be done with the &#039;&#039;run&#039;&#039; command, which will run till the first breakpoint is hit.&lt;br /&gt;
&lt;br /&gt;
Note that when in-circuit debugging there is only a limited number of hardware breakpoints you can set. If you exceed the number you can remove all breakpoints with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
(gdb) del break&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and start over.&lt;br /&gt;
&lt;br /&gt;
== Flash a new firmware ==&lt;br /&gt;
If you want to upload to the board a new firmware version you can made it through gdb and OpenOCD, you must indicate the binary file and the address of the flash memory of your board:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
(gdb) monitor reset halt&lt;br /&gt;
(gdb) monitor flash write_image erase main.bin 0x08000000&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Flashing while the board is running of course does not work, so you need to &#039;&#039;reset halt&#039;&#039; first. You&#039;ll also want to delete the old breakpoints, as they will not be in random locations.&lt;br /&gt;
&lt;br /&gt;
[[Category:Installation and Configuration]]&lt;/div&gt;</summary>
		<author><name>Fede.tft</name></author>
	</entry>
	<entry>
		<id>https://miosix.org/wiki/index.php?title=Linux_Debugger_configuration&amp;diff=463</id>
		<title>Linux Debugger configuration</title>
		<link rel="alternate" type="text/html" href="https://miosix.org/wiki/index.php?title=Linux_Debugger_configuration&amp;diff=463"/>
		<updated>2026-05-10T21:42:54Z</updated>

		<summary type="html">&lt;p&gt;Fede.tft: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The debugging of Miosix on Linux can be done through [http://openocd.org/ OpenOCD], that creates a bridge between GDB and the JTAG device.&lt;br /&gt;
&lt;br /&gt;
= Setting up OpenOCD =&lt;br /&gt;
&lt;br /&gt;
== Install OpenOCD ==&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo apt install openocd # Install OpenOCD for Ubuntu/Debian&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Run OpenOCD ==&lt;br /&gt;
The OpenOCD configuration is included in the official Miosix distribution for most of the supported boards under the path &#039;miosix/arch/board/&amp;lt;board name&amp;gt;/openocd.cfg&#039;. For example for the stm32f429zi_stm32f4discovery board:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
openocd -f miosix/arch/board/stm32f429zi_stm32f4discovery/openocd.cfg&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
OpenOCD provides built-in configuration files for many boards, chips and debugging adapters. You can see the entire range of files in the directory &amp;lt;code&amp;gt;/usr/share/openocd/scripts&amp;lt;/code&amp;gt;. If Miosix does not provide a configuration file for you, in most cases there will be appropriate scripts available together with OpenOCD.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;If breakpoints don&#039;t work on your board&#039;&#039;&#039; you can try adding the option &amp;lt;code&amp;gt;-c &#039;gdb_breakpoint_override hard&#039;&amp;lt;/code&amp;gt; to the OpenOCD invocation. This option disables GDB software breakpoints and always forces the use of hardware breakpoints, which might be needed if OpenOCD provides an incomplete memory map to GDB.&lt;br /&gt;
&lt;br /&gt;
= Debugging with GDB =&lt;br /&gt;
The GDB used is provided by the official [[Miosix_Toolchain|Miosix Toolchain]]. Although the board is flashed with the &#039;&#039;.bin&#039;&#039; file, you&#039;ll have to pass the corresponding &#039;&#039;.elf&#039;&#039; file, since this file format includes debugging symbols.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
arm-miosix-eabi-gdb main.elf&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Connect GDB ==&lt;br /&gt;
OpenOCD provide a network interface for connect the debugger, the follow command is necessary for establish the connection:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
(gdb) target remote &amp;lt;ip&amp;gt;:&amp;lt;port&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The default socket is listening on port 3333 in the loopback interface of your computer. So you can use the default command:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
(gdb) target extended-remote :3333&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Reset the board ==&lt;br /&gt;
After the connection (and after each change of configuration) you must reset the board in a safe state:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
(gdb) monitor reset halt&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Using gdb ==&lt;br /&gt;
&lt;br /&gt;
This is not a full tutorial on using GDB, information can be found online. Here we only list the basics:&lt;br /&gt;
&lt;br /&gt;
Setting breakpoints can be done with the &#039;&#039;break&#039;&#039; command followed by the function name or source code line:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
(gdb) break main&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
(gdb) break main.cpp:30&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Running the board can be done with the &#039;&#039;run&#039;&#039; command, which will run till the first breakpoint is hit.&lt;br /&gt;
&lt;br /&gt;
Note that when in-circuit debugging there is only a limited number of hardware breakpoints you can set. If you exceed the number you can remove all breakpoints with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
(gdb) del break&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and start over.&lt;br /&gt;
&lt;br /&gt;
== Flash a new firmware ==&lt;br /&gt;
If you want to upload to the board a new firmware version you can made it through gdb and OpenOCD, you must indicate the binary file and the address of the flash memory of your board:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
(gdb) monitor flash write_image erase main.bin 0x08000000&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
It&#039;s often necessary to perform a reset of the board before and after the firmware upload.&lt;br /&gt;
&lt;br /&gt;
[[Category:Installation and Configuration]]&lt;/div&gt;</summary>
		<author><name>Fede.tft</name></author>
	</entry>
	<entry>
		<id>https://miosix.org/wiki/index.php?title=Debugging&amp;diff=462</id>
		<title>Debugging</title>
		<link rel="alternate" type="text/html" href="https://miosix.org/wiki/index.php?title=Debugging&amp;diff=462"/>
		<updated>2026-05-10T21:31:41Z</updated>

		<summary type="html">&lt;p&gt;Fede.tft: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Miosix supports multiple debugging methods, useful in different use cases.&lt;br /&gt;
&lt;br /&gt;
= Enabling assertions in the kernel =&lt;br /&gt;
&lt;br /&gt;
A proactive tool to check for potential errors in using the kernel API is to enable optional assertions in the kernel in [https://github.com/fedetft/miosix-kernel/blob/master/miosix/config/miosix_settings.h config/miosix_settings.h]:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=CPP&amp;gt;&lt;br /&gt;
/// Enable additional assertions useful for debugging but adding more run-time&lt;br /&gt;
/// overhead. Three levels are implemented&lt;br /&gt;
/// None: Do not add extra checks, leading to fastest code. This is the default.&lt;br /&gt;
/// Application: Only add checks that are useful to debug kernel-level&lt;br /&gt;
/// application programming errors. Useful during application code debugging.&lt;br /&gt;
/// Kernel: Also add checks that are useful to debug kernel code. Useful&lt;br /&gt;
/// during kernel code debugging. Adds significant run-time overhead!&lt;br /&gt;
enum class ExtraChecks { None, Application, Kernel };&lt;br /&gt;
constexpr auto extraChecks=ExtraChecks::None;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The default is to disable optional assertions. This configuration, useful for a release build only performs minimal assertions in places where there is no impact on performance. You can change the assertion level by declaring the &#039;&#039;extraChecks&#039;&#039; variable to be &#039;&#039;Application&#039;&#039;, which is useful to add extra checks looking for wrong use of kernel APIs from applications. The &#039;&#039;Kernel&#039;&#039; choice is mainly meant for kernel development and mostly adds invariant checks in some kernel data structures, often causing considerable performance impact, such as turning some O(1) algorithms into O(N).&lt;br /&gt;
&lt;br /&gt;
= &#039;&#039;printf()&#039;&#039; debugging =&lt;br /&gt;
&lt;br /&gt;
On almost all boards, Miosix configures a serial port during the boot stage, which the kernel immediately uses to print boot logs. Here&#039;s an example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source&amp;gt;&lt;br /&gt;
Starting Kernel... Ok&lt;br /&gt;
Miosix v3.01 (stm32h755zi_nucleo, May  9 2026 16:53:23, gcc 15.2.0-mp4.2)&lt;br /&gt;
Mounting MountpointFs as / ... Ok&lt;br /&gt;
Mounting DevFs as /dev ... Ok&lt;br /&gt;
Mounting Fat32Fs as /sd ... Ok&lt;br /&gt;
OS Timer freq = 200000000 Hz&lt;br /&gt;
Available heap 511744 out of 519760 Bytes&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When the boot completes and the kernelspace &#039;&#039;main()&#039;&#039; starts, the serial port is available to applications for any use, including &#039;&#039;printf()&#039;&#039; debugging. Note that also &#039;&#039;stdin&#039;&#039; (&#039;&#039;scanf()&#039;&#039; etc.) is configured and working. More information can be found in the [[Serial ports and printf/scanf]] page.&lt;br /&gt;
&lt;br /&gt;
If processes are spawned, they inherit &#039;&#039;stdin&#039;&#039;, &#039;&#039;stdout&#039;&#039; and &#039;&#039;stderr&#039;&#039; from the kernel, so unless redirections are made, also the spawned processes will by default share the same serial port I/O as the kernel, and they too can use it for &#039;&#039;printf()&#039;&#039; debugging.&lt;br /&gt;
&lt;br /&gt;
On the minority of boards where a serial port is not available, it is sometimes possible to use the ARM DCC (Debug Comminication Channel) to redirect &#039;&#039;printf()&#039;&#039; through the SWD debugging interface and access it with gdb/openocd. DCC support is for &#039;&#039;stdout&#039;&#039; (&#039;&#039;printf()&#039;&#039;) only, there&#039;s no &#039;&#039;stdin&#039;&#039; (&#039;&#039;scanf()&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
Further reading for DCC support:&lt;br /&gt;
* [https://github.com/fedetft/miosix-kernel/blob/master/miosix/arch/drivers/dcc.h miosix/arch/drivers/dcc.h]&lt;br /&gt;
* [https://github.com/fedetft/miosix-kernel/blob/master/miosix/arch/board/nrf52840_generic/openocd.cfg miosix/arch/board/nrf52840_generic/openocd.cfg]&lt;br /&gt;
&lt;br /&gt;
= In-circuit debugging =&lt;br /&gt;
&lt;br /&gt;
In-circuit debugging usually takes longer to set-up, but is invaluable when debugging kernelspace application crashes and bugs that corrupt memory.&lt;br /&gt;
&lt;br /&gt;
An in-circuit debugger allows to physically halt the CPU inside a microcontroller, single-step it and view all the variables at any given time. It is a powerful tool to debug software running on a microcontroller.&lt;br /&gt;
&lt;br /&gt;
The only limitation of in-circuit debuggers is that they cannot be used to debug code that has to interact in real-time, as stopping the CPU blocks every activity of the kernel, including unrelated kernel threads and interrupt handlers.&lt;br /&gt;
&lt;br /&gt;
When you install the [[Miosix Toolchain]], it includes a precompiled gdb (&#039;&#039;arm-miosix-eabi-gdb&#039;&#039; for ARM microcontrollers) with support for remote debugging.&lt;br /&gt;
&lt;br /&gt;
An additional tool is needed to bridge gdb and the debugger hardware, usually [http://openocd.sourceforge.net openocd]. The following guides explain how to set up in-circuit debugging.&lt;br /&gt;
&lt;br /&gt;
* [[Linux Debugger configuration]]&lt;br /&gt;
* [[Windows Debugger configuration]]&lt;br /&gt;
&lt;br /&gt;
= Debugging unexpected kernel crashes =&lt;br /&gt;
&lt;br /&gt;
This method allows to get a head start of unexpected bugs by tracing the source code line when it happens the first time, avoiding in some cases the need to attach a debugger and wait for the bug to trigger again.&lt;br /&gt;
&lt;br /&gt;
Modern CPUs provide a fault reporting mechanism, usually through special interrupts that trigger when unexpected conditions occur, such as certain types of memory corruptions, undefined instructions, division by zero etc.&lt;br /&gt;
&lt;br /&gt;
The Miosix kernel, upon encountering such fault conditions, attempts to print the program counter value at the moment of the fault, and then reboot (note that in some architectures such as ARM Cortex, bugs that corrupt the stack to a point where it becomes impossible for the CPU to save the processor state upon entering the fault interrupt leave the kernel with no program counter information, in that case the error message mentions the program counter is missing).&lt;br /&gt;
&lt;br /&gt;
Applications running in kernelspace that cause such types of fault will thus cause a kernel reboot.&lt;br /&gt;
&lt;br /&gt;
Here&#039;s an example of a Miosix fault handler:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source&amp;gt;&lt;br /&gt;
***Unexpected UsageFault @ 0x08004874&lt;br /&gt;
Divide by zero&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you still have access to the exact elf file (main.elf) of the kernel that was flashed on the board, it&#039;s possible to trace the source code line that caused the fault from the fault address. Note that the result may not be fully precise as optimizations blur the mapping between the addresses of assembly instructions and source code lines. Rebuilding the kernel with optimizations disabled solves the issue, but you&#039;d better off just attaching an in-circuit debugger in this case. Some architectures also employ a write buffer, so a write instruction to a nonexistent address will only be caught by the architecture a few instructions later. The kernel will try to warn you when the printed address is imprecise.&lt;br /&gt;
&lt;br /&gt;
Once you have the address of the fault and the kernel elf file, tracing the source code line can be done by combining two tools which are part of the [[Miosix Toolchain]], &#039;&#039;arm-miosix-eabi-addr2line&#039;&#039; and &#039;&#039;arm-miosix-eabi-c++filt&#039;&#039; (replace 0x08004874 with the address of your fault):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ arm-miosix-eabi-addr2line 0x08004874 -e main.elf -f | arm-miosix-eabi-c++filt&lt;br /&gt;
main()&lt;br /&gt;
main.cpp:30&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Reference:&lt;br /&gt;
* [https://github.com/fedetft/miosix-kernel/blob/master/doc/textdoc/Error%20debug.txt Error debug.txt]&lt;br /&gt;
&lt;br /&gt;
= Debugging unexpected process crashes =&lt;br /&gt;
&lt;br /&gt;
Whenever a userspace process crashes, the kernel will by default print an error message to the default serial port, similar to a kernel fault handler. However, the kernel will not reboot as memory protection allows the kernel to keep running even in case of memory corruptions in userspace processes.&lt;br /&gt;
&lt;br /&gt;
A similar technique can be used combining &#039;&#039;arm-miosix-eabi-addr2line&#039;&#039; and &#039;&#039;arm-miosix-eabi-c++filt&#039;&#039; to trace the source code line from the fault address.&lt;br /&gt;
&lt;br /&gt;
TODO: a tutorial is needed&lt;br /&gt;
&lt;br /&gt;
= Using gdb with userspace processes =&lt;br /&gt;
&lt;br /&gt;
Using an in-circuit debugger to debug userspace processes is known not to work, as the fluid kernel memory model is not understood by debuggers. Moreover, an in-circuit debugger halts the entire kernel which is often undesirable as it interferes with interrupt handlers and makes it impossible to debug code that has to interact in real-time.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Coming soon&#039;&#039;&#039;: We are currently developing an in-kernel gdb server that will allow to debug individual processes while leaving the kernel running and able to keep processing real-time code.&lt;/div&gt;</summary>
		<author><name>Fede.tft</name></author>
	</entry>
	<entry>
		<id>https://miosix.org/wiki/index.php?title=Debugging&amp;diff=461</id>
		<title>Debugging</title>
		<link rel="alternate" type="text/html" href="https://miosix.org/wiki/index.php?title=Debugging&amp;diff=461"/>
		<updated>2026-05-10T21:28:06Z</updated>

		<summary type="html">&lt;p&gt;Fede.tft: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Miosix supports multiple debugging methods, useful in different use cases.&lt;br /&gt;
&lt;br /&gt;
= Enabling assertions in the kernel =&lt;br /&gt;
&lt;br /&gt;
A proactive tool to check for potential errors in using the kernel API is to enable optional assertions in the kernel in [https://github.com/fedetft/miosix-kernel/blob/master/miosix/config/miosix_settings.h config/miosix_settings.h]:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=CPP&amp;gt;&lt;br /&gt;
/// Enable additional assertions useful for debugging but adding more run-time&lt;br /&gt;
/// overhead. Three levels are implemented&lt;br /&gt;
/// None: Do not add extra checks, leading to fastest code. This is the default.&lt;br /&gt;
/// Application: Only add checks that are useful to debug kernel-level&lt;br /&gt;
/// application programming errors. Useful during application code debugging.&lt;br /&gt;
/// Kernel: Also add checks that are useful to debug kernel code. Useful&lt;br /&gt;
/// during kernel code debugging. Adds significant run-time overhead!&lt;br /&gt;
enum class ExtraChecks { None, Application, Kernel };&lt;br /&gt;
constexpr auto extraChecks=ExtraChecks::None;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The default is to disable optional assertions. This configuration, useful for a release build only performs minimal assertions in places where there is no impact on performance. You can change the assertion level by declaring the &#039;&#039;extraChecks&#039;&#039; variable to be &#039;&#039;Application&#039;&#039;, which is useful to add extra checks looking for wrong use of kernel APIs from applications. The &#039;&#039;Kernel&#039;&#039; choice is mainly meant for kernel development and mostly adds invariant checks in some kernel data structures, often causing considerable performance impact, such as turning some O(1) algorithms into O(N).&lt;br /&gt;
&lt;br /&gt;
= &#039;&#039;printf()&#039;&#039; debugging =&lt;br /&gt;
&lt;br /&gt;
On almost all boards, Miosix configures a serial port during the boot stage, which the kernel immediately uses to print boot logs. Here&#039;s an example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source&amp;gt;&lt;br /&gt;
Starting Kernel... Ok&lt;br /&gt;
Miosix v3.01 (stm32h755zi_nucleo, May  9 2026 16:53:23, gcc 15.2.0-mp4.2)&lt;br /&gt;
Mounting MountpointFs as / ... Ok&lt;br /&gt;
Mounting DevFs as /dev ... Ok&lt;br /&gt;
Mounting Fat32Fs as /sd ... Ok&lt;br /&gt;
OS Timer freq = 200000000 Hz&lt;br /&gt;
Available heap 511744 out of 519760 Bytes&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When the boot completes and the kernelspace &#039;&#039;main()&#039;&#039; starts, the serial port is available to applications for any use, including &#039;&#039;printf()&#039;&#039; debugging. Note that also &#039;&#039;stdin&#039;&#039; (&#039;&#039;scanf()&#039;&#039; etc.) is configured and working. More information can be found in the [[Serial ports and printf/scanf]] page.&lt;br /&gt;
&lt;br /&gt;
If processes are spawned, they inherit &#039;&#039;stdin&#039;&#039;, &#039;&#039;stdout&#039;&#039; and &#039;&#039;stderr&#039;&#039; from the kernel, so unless redirections are made, also the spawned processes will by default share the same serial port I/O as the kernel, and they too can use it for &#039;&#039;printf()&#039;&#039; debugging.&lt;br /&gt;
&lt;br /&gt;
On the minority of boards where a serial port is not available, it is sometimes possible to use the ARM DCC (Debug Comminication Channel) to redirect &#039;&#039;printf()&#039;&#039; through the SWD debugging interface and access it with gdb/openocd. DCC support is for &#039;&#039;stdout&#039;&#039; (&#039;&#039;printf()&#039;&#039;) only, there&#039;s no &#039;&#039;stdin&#039;&#039; (&#039;&#039;scanf()&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
Further reading for DCC support:&lt;br /&gt;
* [https://github.com/fedetft/miosix-kernel/blob/master/miosix/arch/drivers/dcc.h miosix/arch/drivers/dcc.h]&lt;br /&gt;
* [https://github.com/fedetft/miosix-kernel/blob/master/miosix/arch/board/nrf52840_generic/openocd.cfg miosix/arch/board/nrf52840_generic/openocd.cfg]&lt;br /&gt;
&lt;br /&gt;
= In-circuit debugging =&lt;br /&gt;
&lt;br /&gt;
In-circuit debugging usually takes longer to set-up, but is invaluable when debugging kernelspace application crashes and bugs that corrupt memory.&lt;br /&gt;
&lt;br /&gt;
An in-circuit debugger allows to physically halt the CPU inside a microcontroller, single-step it and view all the variables at any given time. It is a powerful tool to debug software running on a microcontroller.&lt;br /&gt;
&lt;br /&gt;
The only limitation of in-circuit debuggers is that they cannot be used to debug code that has to interact in real-time, as stopping the CPU blocks every activity of the kernel, including unrelated kernel threads and interrupt handlers.&lt;br /&gt;
&lt;br /&gt;
When you install the [[Miosix Toolchain]], it includes a precompiled gdb (&#039;&#039;arm-miosix-eabi-gdb&#039;&#039; for ARM microcontrollers) with support for remote debugging.&lt;br /&gt;
&lt;br /&gt;
An additional tool is needed to bridge gdb and the debugger hardware, usually [http://openocd.sourceforge.net openocd]. The following guides explain how to set up in-circuit debugging.&lt;br /&gt;
&lt;br /&gt;
* [[Linux Debugger configuration]]&lt;br /&gt;
* [[Windows Debugger configuration]]&lt;br /&gt;
&lt;br /&gt;
= Debugging unexpected kernel crashes =&lt;br /&gt;
&lt;br /&gt;
This method allows to get a head start of unexpected bugs by tracing the source code line when it happens the first time, avoiding in some cases the need to attach a debugger and wait for the bug to trigger again.&lt;br /&gt;
&lt;br /&gt;
Modern CPUs provide a fault reporting mechanism, usually through special interrupts that trigger when unexpected conditions occur, such as certain types of memory corruptions, undefined instructions, division by zero etc.&lt;br /&gt;
&lt;br /&gt;
The Miosix kernel, upon encountering such fault conditions, attempts to print the program counter value at the moment of the fault, and then reboot (note that in some architectures such as ARM Cortex, bugs that corrupt the stack to a point where it becomes impossible for the CPU to save the processor state upon entering the fault interrupt leave the kernel with no program counter information, in that case the error message mentions the program counter is missing).&lt;br /&gt;
&lt;br /&gt;
Applications running in kernelspace that cause such types of fault will thus cause a kernel reboot.&lt;br /&gt;
&lt;br /&gt;
Here&#039;s an example of a Miosix fault handler:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source&amp;gt;&lt;br /&gt;
***Unexpected UsageFault @ 0x08004874&lt;br /&gt;
Divide by zero&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you still have access to the exact elf file (main.elf) of the kernel that was flashed on the board, it&#039;s possible to trace the source code line that caused the fault from the fault address. Note that the result may not be fully precise as optimizations blur the mapping between the addresses of assembly instructions and source code lines. Rebuilding the kernel with optimizations disabled solves the issue, but you&#039;d better off just attaching an in-circuit debugger in this case. Some architectures also employ a write buffer, so a write instruction to a nonexistent address will only be caught by the architecture a few instructions later. The kernel will try to warn you when the printed address is imprecise.&lt;br /&gt;
&lt;br /&gt;
Once you have the address of the fault and the kernel elf file, tracing the source code line can be done by combining two tools which are part of the [[Miosix Toolchain]], &#039;&#039;arm-miosix-eabi-addr2line&#039;&#039; and &#039;&#039;arm-miosix-eabi-c++filt&#039;&#039; (replace 0x08004874 with the address of your fault):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ arm-miosix-eabi-addr2line 0x08004874 -e main.elf -f | arm-miosix-eabi-c++filt&lt;br /&gt;
main()&lt;br /&gt;
main.cpp:30&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Reference:&lt;br /&gt;
* [[https://github.com/fedetft/miosix-kernel/blob/master/doc/textdoc/Error%20debug.txt | Error debug]]&lt;br /&gt;
&lt;br /&gt;
= Debugging unexpected process crashes =&lt;br /&gt;
&lt;br /&gt;
Whenever a userspace process crashes, the kernel will by default print an error message to the default serial port, similar to a kernel fault handler. However, the kernel will not reboot as memory protection allows the kernel to keep running even in case of memory corruptions in userspace processes.&lt;br /&gt;
&lt;br /&gt;
A similar technique can be used combining &#039;&#039;arm-miosix-eabi-addr2line&#039;&#039; and &#039;&#039;arm-miosix-eabi-c++filt&#039;&#039; to trace the source code line from the fault address.&lt;br /&gt;
&lt;br /&gt;
TODO: a tutorial is needed&lt;br /&gt;
&lt;br /&gt;
= Using gdb with userspace processes =&lt;br /&gt;
&lt;br /&gt;
Using an in-circuit debugger to debug userspace processes is known not to work, as the fluid kernel memory model is not understood by debuggers. Moreover, an in-circuit debugger halts the entire kernel which is often undesirable as it interferes with interrupt handlers and makes it impossible to debug code that has to interact in real-time.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Coming soon&#039;&#039;&#039;: We are currently developing an in-kernel gdb server that will allow to debug individual processes while leaving the kernel running and able to keep processing real-time code.&lt;/div&gt;</summary>
		<author><name>Fede.tft</name></author>
	</entry>
	<entry>
		<id>https://miosix.org/wiki/index.php?title=Debugging&amp;diff=460</id>
		<title>Debugging</title>
		<link rel="alternate" type="text/html" href="https://miosix.org/wiki/index.php?title=Debugging&amp;diff=460"/>
		<updated>2026-05-10T21:26:50Z</updated>

		<summary type="html">&lt;p&gt;Fede.tft: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Miosix supports multiple debugging methods, useful in different use cases.&lt;br /&gt;
&lt;br /&gt;
= Enabling assertions in the kernel =&lt;br /&gt;
&lt;br /&gt;
A proactive tool to check for potential errors in using the kernel API is to enable optional assertions in the kernel in [https://github.com/fedetft/miosix-kernel/blob/master/miosix/config/miosix_settings.h config/miosix_settings.h]:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=CPP&amp;gt;&lt;br /&gt;
/// Enable additional assertions useful for debugging but adding more run-time&lt;br /&gt;
/// overhead. Three levels are implemented&lt;br /&gt;
/// None: Do not add extra checks, leading to fastest code. This is the default.&lt;br /&gt;
/// Application: Only add checks that are useful to debug kernel-level&lt;br /&gt;
/// application programming errors. Useful during application code debugging.&lt;br /&gt;
/// Kernel: Also add checks that are useful to debug kernel code. Useful&lt;br /&gt;
/// during kernel code debugging. Adds significant run-time overhead!&lt;br /&gt;
enum class ExtraChecks { None, Application, Kernel };&lt;br /&gt;
constexpr auto extraChecks=ExtraChecks::None;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The default is to disable optional assertions. This configuration, useful for a release build only performs minimal assertions in places where there is no impact on performance. You can change the assertion level by declaring the &#039;&#039;extraChecks&#039;&#039; variable to be &#039;&#039;Application&#039;&#039;, which is useful to add extra checks looking for wrong use of kernel APIs from applications. The &#039;&#039;Kernel&#039;&#039; choice is mainly meant for kernel development and mostly adds invariant checks in some kernel data structures, often causing considerable performance impact, such as turning some O(1) algorithms into O(N).&lt;br /&gt;
&lt;br /&gt;
= &#039;&#039;printf()&#039;&#039; debugging =&lt;br /&gt;
&lt;br /&gt;
On almost all boards, Miosix configures a serial port during the boot stage, which the kernel immediately uses to print boot logs. Here&#039;s an example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source&amp;gt;&lt;br /&gt;
Starting Kernel... Ok&lt;br /&gt;
Miosix v3.01 (stm32h755zi_nucleo, May  9 2026 16:53:23, gcc 15.2.0-mp4.2)&lt;br /&gt;
Mounting MountpointFs as / ... Ok&lt;br /&gt;
Mounting DevFs as /dev ... Ok&lt;br /&gt;
Mounting Fat32Fs as /sd ... Ok&lt;br /&gt;
OS Timer freq = 200000000 Hz&lt;br /&gt;
Available heap 511744 out of 519760 Bytes&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When the boot completes and the kernelspace &#039;&#039;main()&#039;&#039; starts, the serial port is available to applications for any use, including &#039;&#039;printf()&#039;&#039; debugging. Note that also &#039;&#039;stdin&#039;&#039; (&#039;&#039;scanf()&#039;&#039; etc.) is configured and working. More information can be found in the [[Serial ports and printf/scanf]] page.&lt;br /&gt;
&lt;br /&gt;
If processes are spawned, they inherit &#039;&#039;stdin&#039;&#039;, &#039;&#039;stdout&#039;&#039; and &#039;&#039;stderr&#039;&#039; from the kernel, so unless redirections are made, also the spawned processes will by default share the same serial port I/O as the kernel, and they too can use it for &#039;&#039;printf()&#039;&#039; debugging.&lt;br /&gt;
&lt;br /&gt;
On the minority of boards where a serial port is not available, it is sometimes possible to use the ARM DCC (Debug Comminication Channel) to redirect &#039;&#039;printf()&#039;&#039; through the SWD debugging interface and access it with gdb/openocd. DCC support is for &#039;&#039;stdout&#039;&#039; (&#039;&#039;printf()&#039;&#039;) only, there&#039;s no &#039;&#039;stdin&#039;&#039; (&#039;&#039;scanf()&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
Further reading for DCC support:&lt;br /&gt;
* [https://github.com/fedetft/miosix-kernel/blob/master/miosix/arch/drivers/dcc.h miosix/arch/drivers/dcc.h]&lt;br /&gt;
* [https://github.com/fedetft/miosix-kernel/blob/master/miosix/arch/board/nrf52840_generic/openocd.cfg miosix/arch/board/nrf52840_generic/openocd.cfg]&lt;br /&gt;
&lt;br /&gt;
= In-circuit debugging =&lt;br /&gt;
&lt;br /&gt;
In-circuit debugging usually takes longer to set-up, but is invaluable when debugging kernelspace application crashes and bugs that corrupt memory.&lt;br /&gt;
&lt;br /&gt;
An in-circuit debugger allows to physically halt the CPU inside a microcontroller, single-step it and view all the variables at any given time. It is a powerful tool to debug software running on a microcontroller.&lt;br /&gt;
&lt;br /&gt;
The only limitation of in-circuit debuggers is that they cannot be used to debug code that has to interact in real-time, as stopping the CPU blocks every activity o the kernel, including unrelated kernel threads and interrupt handlers.&lt;br /&gt;
&lt;br /&gt;
When you install the [[Miosix Toolchain]], it includes a precompiled gdb (&#039;&#039;arm-miosix-eabi-gdb&#039;&#039; for ARM microcontrollers) with support for remote debugging.&lt;br /&gt;
&lt;br /&gt;
An additional tool is needed to bridge gdb and the debugger hardware, usually [http://openocd.sourceforge.net openocd]. The following guides explain how to set up in-circuit debugging.&lt;br /&gt;
&lt;br /&gt;
* [[Linux Debugger configuration]]&lt;br /&gt;
* [[Windows Debugger configuration]]&lt;br /&gt;
&lt;br /&gt;
= Debugging unexpected kernel crashes =&lt;br /&gt;
&lt;br /&gt;
This method allows to get a head start of unexpected bugs by tracing the source code line when it happens the first time, avoiding in some cases the need to attach a debugger and wait for the bug to trigger again.&lt;br /&gt;
&lt;br /&gt;
Modern CPUs provide a fault reporting mechanism, usually through special interrupts that trigger when unexpected conditions occur, such as certain types of memory corruptions, undefined instructions, division by zero etc.&lt;br /&gt;
&lt;br /&gt;
The Miosix kernel, upon encountering such fault conditions, attempts to print the program counter value at the moment of the fault, and then reboot (note that in some architectures such as ARM Cortex, bugs that corrupt the stack to a point where it becomes impossible for the CPU to save the processor state upon entering the fault interrupt leave the kernel with no program counter information, in that case the error message mentions the program counter is missing).&lt;br /&gt;
&lt;br /&gt;
Applications running in kernelspace that cause such types of fault will thus cause a kernel reboot.&lt;br /&gt;
&lt;br /&gt;
Here&#039;s an example of a Miosix fault handler:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source&amp;gt;&lt;br /&gt;
***Unexpected UsageFault @ 0x08004874&lt;br /&gt;
Divide by zero&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you still have access to the exact elf file (main.elf) of the kernel that was flashed on the board, it&#039;s possible to trace the source code line that caused the fault from the fault address. Note that the result may not be fully precise as optimizations blur the mapping between the addresses of assembly instructions and source code lines. Rebuilding the kernel with optimizations disabled solves the issue, but you&#039;d better off just attaching an in-circuit debugger in this case. Some architectures also employ a write buffer, so a write instruction to a nonexistent address will only be caught by the architecture a few instructions later. The kernel will try to warn you when the printed address is imprecise.&lt;br /&gt;
&lt;br /&gt;
Once you have the address of the fault and the kernel elf file, tracing the source code line can be done by combining two tools which are part of the [[Miosix Toolchain]], &#039;&#039;arm-miosix-eabi-addr2line&#039;&#039; and &#039;&#039;arm-miosix-eabi-c++filt&#039;&#039; (replace 0x08004874 with the address of your fault):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ arm-miosix-eabi-addr2line 0x08004874 -e main.elf -f | arm-miosix-eabi-c++filt&lt;br /&gt;
main()&lt;br /&gt;
main.cpp:30&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Reference:&lt;br /&gt;
* [[https://github.com/fedetft/miosix-kernel/blob/master/doc/textdoc/Error%20debug.txt | Error debug]]&lt;br /&gt;
&lt;br /&gt;
= Debugging unexpected process crashes =&lt;br /&gt;
&lt;br /&gt;
Whenever a userspace process crashes, the kernel will by default print an error message to the default serial port, similar to a kernel fault handler. However, the kernel will not reboot as memory protection allows the kernel to keep running even in case of memory corruptions in userspace processes.&lt;br /&gt;
&lt;br /&gt;
A similar technique can be used combining &#039;&#039;arm-miosix-eabi-addr2line&#039;&#039; and &#039;&#039;arm-miosix-eabi-c++filt&#039;&#039; to trace the source code line from the fault address.&lt;br /&gt;
&lt;br /&gt;
TODO: a tutorial is needed&lt;br /&gt;
&lt;br /&gt;
= Using gdb with userspace processes =&lt;br /&gt;
&lt;br /&gt;
Using an in-circuit debugger to debug userspace processes is known not to work, as the fluid kernel memory model is not understood by debuggers. Moreover, an in-circuit debugger halts the entire kernel which is often undesirable as it interferes with interrupt handlers and makes it impossible to debug code that has to interact in real-time.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Coming soon&#039;&#039;&#039;: We are currently developing an in-kernel gdb server that will allow to debug individual processes while leaving the kernel running and able to keep processing real-time code.&lt;/div&gt;</summary>
		<author><name>Fede.tft</name></author>
	</entry>
	<entry>
		<id>https://miosix.org/wiki/index.php?title=Debugging&amp;diff=459</id>
		<title>Debugging</title>
		<link rel="alternate" type="text/html" href="https://miosix.org/wiki/index.php?title=Debugging&amp;diff=459"/>
		<updated>2026-05-10T21:25:25Z</updated>

		<summary type="html">&lt;p&gt;Fede.tft: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Miosix supports multiple debugging methods, useful in different use cases.&lt;br /&gt;
&lt;br /&gt;
= Enabling assertions in the kernel =&lt;br /&gt;
&lt;br /&gt;
A proactive tool to check for potential errors in using the kernel API is to enable optional assertions in the kernel.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=CPP&amp;gt;&lt;br /&gt;
/// Enable additional assertions useful for debugging but adding more run-time&lt;br /&gt;
/// overhead. Three levels are implemented&lt;br /&gt;
/// None: Do not add extra checks, leading to fastest code. This is the default.&lt;br /&gt;
/// Application: Only add checks that are useful to debug kernel-level&lt;br /&gt;
/// application programming errors. Useful during application code debugging.&lt;br /&gt;
/// Kernel: Also add checks that are useful to debug kernel code. Useful&lt;br /&gt;
/// during kernel code debugging. Adds significant run-time overhead!&lt;br /&gt;
enum class ExtraChecks { None, Application, Kernel };&lt;br /&gt;
constexpr auto extraChecks=ExtraChecks::None;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The default is to disable optional assertions. This configuration, useful for a release build only performs minimal assertions in places where there is no impact on performance. You can change the assertion level by declaring the &#039;&#039;extraChecks&#039;&#039; variable to be &#039;&#039;Application&#039;&#039;, which is useful to add extra checks looking for wrong use of kernel APIs from applications. The &#039;&#039;Kernel&#039;&#039; choice is mainly meant for kernel development and mostly adds invariant checks in some kernel data structures, often causing considerable performance impact, such as turning some O(1) algorithms into O(N).&lt;br /&gt;
&lt;br /&gt;
= &#039;&#039;printf()&#039;&#039; debugging =&lt;br /&gt;
&lt;br /&gt;
On almost all boards, Miosix configures a serial port during the boot stage, which the kernel immediately uses to print boot logs. Here&#039;s an example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source&amp;gt;&lt;br /&gt;
Starting Kernel... Ok&lt;br /&gt;
Miosix v3.01 (stm32h755zi_nucleo, May  9 2026 16:53:23, gcc 15.2.0-mp4.2)&lt;br /&gt;
Mounting MountpointFs as / ... Ok&lt;br /&gt;
Mounting DevFs as /dev ... Ok&lt;br /&gt;
Mounting Fat32Fs as /sd ... Ok&lt;br /&gt;
OS Timer freq = 200000000 Hz&lt;br /&gt;
Available heap 511744 out of 519760 Bytes&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When the boot completes and the kernelspace &#039;&#039;main()&#039;&#039; starts, the serial port is available to applications for any use, including &#039;&#039;printf()&#039;&#039; debugging. Note that also &#039;&#039;stdin&#039;&#039; (&#039;&#039;scanf()&#039;&#039; etc.) is configured and working. More information can be found in the [[Serial ports and printf/scanf]] page.&lt;br /&gt;
&lt;br /&gt;
If processes are spawned, they inherit &#039;&#039;stdin&#039;&#039;, &#039;&#039;stdout&#039;&#039; and &#039;&#039;stderr&#039;&#039; from the kernel, so unless redirections are made, also the spawned processes will by default share the same serial port I/O as the kernel, and they too can use it for &#039;&#039;printf()&#039;&#039; debugging.&lt;br /&gt;
&lt;br /&gt;
On the minority of boards where a serial port is not available, it is sometimes possible to use the ARM DCC (Debug Comminication Channel) to redirect &#039;&#039;printf()&#039;&#039; through the SWD debugging interface and access it with gdb/openocd. DCC support is for &#039;&#039;stdout&#039;&#039; (&#039;&#039;printf()&#039;&#039;) only, there&#039;s no &#039;&#039;stdin&#039;&#039; (&#039;&#039;scanf()&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
Further reading for DCC support:&lt;br /&gt;
* [https://github.com/fedetft/miosix-kernel/blob/master/miosix/arch/drivers/dcc.h miosix/arch/drivers/dcc.h]&lt;br /&gt;
* [https://github.com/fedetft/miosix-kernel/blob/master/miosix/arch/board/nrf52840_generic/openocd.cfg miosix/arch/board/nrf52840_generic/openocd.cfg]&lt;br /&gt;
&lt;br /&gt;
= In-circuit debugging =&lt;br /&gt;
&lt;br /&gt;
In-circuit debugging usually takes longer to set-up, but is invaluable when debugging kernelspace application crashes and bugs that corrupt memory.&lt;br /&gt;
&lt;br /&gt;
An in-circuit debugger allows to physically halt the CPU inside a microcontroller, single-step it and view all the variables at any given time. It is a powerful tool to debug software running on a microcontroller.&lt;br /&gt;
&lt;br /&gt;
The only limitation of in-circuit debuggers is that they cannot be used to debug code that has to interact in real-time, as stopping the CPU blocks every activity o the kernel, including unrelated kernel threads and interrupt handlers.&lt;br /&gt;
&lt;br /&gt;
When you install the [[Miosix Toolchain]], it includes a precompiled gdb (&#039;&#039;arm-miosix-eabi-gdb&#039;&#039; for ARM microcontrollers) with support for remote debugging.&lt;br /&gt;
&lt;br /&gt;
An additional tool is needed to bridge gdb and the debugger hardware, usually [http://openocd.sourceforge.net openocd]. The following guides explain how to set up in-circuit debugging.&lt;br /&gt;
&lt;br /&gt;
* [[Linux Debugger configuration]]&lt;br /&gt;
* [[Windows Debugger configuration]]&lt;br /&gt;
&lt;br /&gt;
= Debugging unexpected kernel crashes =&lt;br /&gt;
&lt;br /&gt;
This method allows to get a head start of unexpected bugs by tracing the source code line when it happens the first time, avoiding in some cases the need to attach a debugger and wait for the bug to trigger again.&lt;br /&gt;
&lt;br /&gt;
Modern CPUs provide a fault reporting mechanism, usually through special interrupts that trigger when unexpected conditions occur, such as certain types of memory corruptions, undefined instructions, division by zero etc.&lt;br /&gt;
&lt;br /&gt;
The Miosix kernel, upon encountering such fault conditions, attempts to print the program counter value at the moment of the fault, and then reboot (note that in some architectures such as ARM Cortex, bugs that corrupt the stack to a point where it becomes impossible for the CPU to save the processor state upon entering the fault interrupt leave the kernel with no program counter information, in that case the error message mentions the program counter is missing).&lt;br /&gt;
&lt;br /&gt;
Applications running in kernelspace that cause such types of fault will thus cause a kernel reboot.&lt;br /&gt;
&lt;br /&gt;
Here&#039;s an example of a Miosix fault handler:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source&amp;gt;&lt;br /&gt;
***Unexpected UsageFault @ 0x08004874&lt;br /&gt;
Divide by zero&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you still have access to the exact elf file (main.elf) of the kernel that was flashed on the board, it&#039;s possible to trace the source code line that caused the fault from the fault address. Note that the result may not be fully precise as optimizations blur the mapping between the addresses of assembly instructions and source code lines. Rebuilding the kernel with optimizations disabled solves the issue, but you&#039;d better off just attaching an in-circuit debugger in this case. Some architectures also employ a write buffer, so a write instruction to a nonexistent address will only be caught by the architecture a few instructions later. The kernel will try to warn you when the printed address is imprecise.&lt;br /&gt;
&lt;br /&gt;
Once you have the address of the fault and the kernel elf file, tracing the source code line can be done by combining two tools which are part of the [[Miosix Toolchain]], &#039;&#039;arm-miosix-eabi-addr2line&#039;&#039; and &#039;&#039;arm-miosix-eabi-c++filt&#039;&#039; (replace 0x08004874 with the address of your fault):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ arm-miosix-eabi-addr2line 0x08004874 -e main.elf -f | arm-miosix-eabi-c++filt&lt;br /&gt;
main()&lt;br /&gt;
main.cpp:30&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Reference:&lt;br /&gt;
* [[https://github.com/fedetft/miosix-kernel/blob/master/doc/textdoc/Error%20debug.txt | Error debug]]&lt;br /&gt;
&lt;br /&gt;
= Debugging unexpected process crashes =&lt;br /&gt;
&lt;br /&gt;
Whenever a userspace process crashes, the kernel will by default print an error message to the default serial port, similar to a kernel fault handler. However, the kernel will not reboot as memory protection allows the kernel to keep running even in case of memory corruptions in userspace processes.&lt;br /&gt;
&lt;br /&gt;
A similar technique can be used combining &#039;&#039;arm-miosix-eabi-addr2line&#039;&#039; and &#039;&#039;arm-miosix-eabi-c++filt&#039;&#039; to trace the source code line from the fault address.&lt;br /&gt;
&lt;br /&gt;
TODO: a tutorial is needed&lt;br /&gt;
&lt;br /&gt;
= Using gdb with userspace processes =&lt;br /&gt;
&lt;br /&gt;
Using an in-circuit debugger to debug userspace processes is known not to work, as the fluid kernel memory model is not understood by debuggers. Moreover, an in-circuit debugger halts the entire kernel which is often undesirable as it interferes with interrupt handlers and makes it impossible to debug code that has to interact in real-time.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Coming soon&#039;&#039;&#039;: We are currently developing an in-kernel gdb server that will allow to debug individual processes while leaving the kernel running and able to keep processing real-time code.&lt;/div&gt;</summary>
		<author><name>Fede.tft</name></author>
	</entry>
	<entry>
		<id>https://miosix.org/wiki/index.php?title=Debugging&amp;diff=458</id>
		<title>Debugging</title>
		<link rel="alternate" type="text/html" href="https://miosix.org/wiki/index.php?title=Debugging&amp;diff=458"/>
		<updated>2026-05-10T21:22:49Z</updated>

		<summary type="html">&lt;p&gt;Fede.tft: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Miosix supports multiple debugging methods, useful in different use cases.&lt;br /&gt;
&lt;br /&gt;
= Enabling assertions in the kernel =&lt;br /&gt;
&lt;br /&gt;
A proactive tool to check for potential errors in using the kernel API is to enable optional assertions in the kernel.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=CPP&amp;gt;&lt;br /&gt;
/// Enable additional assertions useful for debugging but adding more run-time&lt;br /&gt;
/// overhead. Three levels are implemented&lt;br /&gt;
/// None: Do not add extra checks, leading to fastest code. This is the default.&lt;br /&gt;
/// Application: Only add checks that are useful to debug kernel-level&lt;br /&gt;
/// application programming errors. Useful during application code debugging.&lt;br /&gt;
/// Kernel: Also add checks that are useful to debug kernel code. Useful&lt;br /&gt;
/// during kernel code debugging. Adds significant run-time overhead!&lt;br /&gt;
enum class ExtraChecks { None, Application, Kernel };&lt;br /&gt;
constexpr auto extraChecks=ExtraChecks::None;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The default is to disable optional assertions. This configuration, useful for a release build only performs minimal assertions in places where there is no impact on performance. You can change the assertion level by declaring the &#039;&#039;extraChecks&#039;&#039; variable to be &#039;&#039;Application&#039;&#039;, which is useful to add extra checks looking for wrong use of kernel APIs from applications. The &#039;&#039;Kernel&#039;&#039; choice is mainly meant for kernel development and mostly adds invariant checks in some kernel data structures, often causing considerable performance impact, such as turning some O(1) algorithms into O(N).&lt;br /&gt;
&lt;br /&gt;
= &#039;&#039;printf()&#039;&#039; debugging =&lt;br /&gt;
&lt;br /&gt;
On almost all boards, Miosix configures a serial port during the boot stage, which the kernel immediately uses to print boot logs. Here&#039;s an example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source&amp;gt;&lt;br /&gt;
Starting Kernel... Ok&lt;br /&gt;
Miosix v3.01 (stm32h755zi_nucleo, May  9 2026 16:53:23, gcc 15.2.0-mp4.2)&lt;br /&gt;
Mounting MountpointFs as / ... Ok&lt;br /&gt;
Mounting DevFs as /dev ... Ok&lt;br /&gt;
Mounting Fat32Fs as /sd ... Ok&lt;br /&gt;
OS Timer freq = 200000000 Hz&lt;br /&gt;
Available heap 511744 out of 519760 Bytes&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When the boot completes and the kernelspace &#039;&#039;main()&#039;&#039; starts, the serial port is available to applications for any use, including &#039;&#039;printf()&#039;&#039; debugging. Note that also &#039;&#039;stdin&#039;&#039; (&#039;&#039;scanf()&#039;&#039; etc.) is configured and working. More information can be found in the [[Serial ports and printf/scanf]] page.&lt;br /&gt;
&lt;br /&gt;
If processes are spawned, they inherit &#039;&#039;stdin&#039;&#039;, &#039;&#039;stdout&#039;&#039; and &#039;&#039;stderr&#039;&#039; from the kernel, so unless redirections are made, also the spawned processes will by default share the same serial port I/O as the kernel, and they too can use it for &#039;&#039;printf()&#039;&#039; debugging.&lt;br /&gt;
&lt;br /&gt;
On the minority of boards where a serial port is not available, it is sometimes possible to use the ARM DCC (Debug Comminication Channel) to redirect &#039;&#039;printf()&#039;&#039; through the SWD debugging interface and access it with gdb/openocd. DCC support is for &#039;&#039;stdout&#039;&#039; (&#039;&#039;printf()&#039;&#039;) only, there&#039;s no &#039;&#039;stdin&#039;&#039; (&#039;&#039;scanf()&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
Further reading for DCC support:&lt;br /&gt;
* [[https://github.com/fedetft/miosix-kernel/blob/master/miosix/arch/drivers/dcc.h miosix/arch/drivers/dcc.h]]&lt;br /&gt;
* [[https://github.com/fedetft/miosix-kernel/blob/master/miosix/arch/board/nrf52840_generic/openocd.cfg miosix/arch/board/nrf52840_generic/openocd.cfg]]&lt;br /&gt;
&lt;br /&gt;
= In-circuit debugging =&lt;br /&gt;
&lt;br /&gt;
In-circuit debugging usually takes longer to set-up, but is invaluable when debugging kernelspace application crashes and bugs that corrupt memory.&lt;br /&gt;
&lt;br /&gt;
An in-circuit debugger allows to physically halt the CPU inside a microcontroller, single-step it and view all the variables at any given time. It is a powerful tool to debug software running on a microcontroller.&lt;br /&gt;
&lt;br /&gt;
The only limitation of in-circuit debuggers is that they cannot be used to debug code that has to interact in real-time, as stopping the CPU blocks every activity o the kernel, including unrelated kernel threads and interrupt handlers.&lt;br /&gt;
&lt;br /&gt;
When you install the [[Miosix Toolchain]], it includes a precompiled gdb (&#039;&#039;arm-miosix-eabi-gdb&#039;&#039; for ARM microcontrollers) with support for remote debugging.&lt;br /&gt;
&lt;br /&gt;
An additional tool is needed to bridge gdb and the debugger hardware, usually [http://openocd.sourceforge.net openocd]. The following guides explain how to set up in-circuit debugging.&lt;br /&gt;
&lt;br /&gt;
* [[Linux Debugger configuration]]&lt;br /&gt;
* [[Windows Debugger configuration]]&lt;br /&gt;
&lt;br /&gt;
= Debugging unexpected kernel crashes =&lt;br /&gt;
&lt;br /&gt;
This method allows to get a head start of unexpected bugs by tracing the source code line when it happens the first time, avoiding in some cases the need to attach a debugger and wait for the bug to trigger again.&lt;br /&gt;
&lt;br /&gt;
Modern CPUs provide a fault reporting mechanism, usually through special interrupts that trigger when unexpected conditions occur, such as certain types of memory corruptions, undefined instructions, division by zero etc.&lt;br /&gt;
&lt;br /&gt;
The Miosix kernel, upon encountering such fault conditions, attempts to print the program counter value at the moment of the fault, and then reboot (note that in some architectures such as ARM Cortex, bugs that corrupt the stack to a point where it becomes impossible for the CPU to save the processor state upon entering the fault interrupt leave the kernel with no program counter information, in that case the error message mentions the program counter is missing).&lt;br /&gt;
&lt;br /&gt;
Applications running in kernelspace that cause such types of fault will thus cause a kernel reboot.&lt;br /&gt;
&lt;br /&gt;
Here&#039;s an example of a Miosix fault handler:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source&amp;gt;&lt;br /&gt;
***Unexpected UsageFault @ 0x08004874&lt;br /&gt;
Divide by zero&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you still have access to the exact elf file (main.elf) of the kernel that was flashed on the board, it&#039;s possible to trace the source code line that caused the fault from the fault address. Note that the result may not be fully precise as optimizations blur the mapping between the addresses of assembly instructions and source code lines. Rebuilding the kernel with optimizations disabled solves the issue, but you&#039;d better off just attaching an in-circuit debugger in this case. Some architectures also employ a write buffer, so a write instruction to a nonexistent address will only be caught by the architecture a few instructions later. The kernel will try to warn you when the printed address is imprecise.&lt;br /&gt;
&lt;br /&gt;
Once you have the address of the fault and the kernel elf file, tracing the source code line can be done by combining two tools which are part of the [[Miosix Toolchain]], &#039;&#039;arm-miosix-eabi-addr2line&#039;&#039; and &#039;&#039;arm-miosix-eabi-c++filt&#039;&#039; (replace 0x08004874 with the address of your fault):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ arm-miosix-eabi-addr2line 0x08004874 -e main.elf -f | arm-miosix-eabi-c++filt&lt;br /&gt;
main()&lt;br /&gt;
main.cpp:30&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Reference:&lt;br /&gt;
* [[https://github.com/fedetft/miosix-kernel/blob/master/doc/textdoc/Error%20debug.txt | Error debug]]&lt;br /&gt;
&lt;br /&gt;
= Debugging unexpected process crashes =&lt;br /&gt;
&lt;br /&gt;
Whenever a userspace process crashes, the kernel will by default print an error message to the default serial port, similar to a kernel fault handler. However, the kernel will not reboot as memory protection allows the kernel to keep running even in case of memory corruptions in userspace processes.&lt;br /&gt;
&lt;br /&gt;
A similar technique can be used combining &#039;&#039;arm-miosix-eabi-addr2line&#039;&#039; and &#039;&#039;arm-miosix-eabi-c++filt&#039;&#039; to trace the source code line from the fault address.&lt;br /&gt;
&lt;br /&gt;
TODO: a tutorial is needed&lt;br /&gt;
&lt;br /&gt;
= Using gdb with userspace processes =&lt;br /&gt;
&lt;br /&gt;
Using an in-circuit debugger to debug userspace processes is known not to work, as the fluid kernel memory model is not understood by debuggers. Moreover, an in-circuit debugger halts the entire kernel which is often undesirable as it interferes with interrupt handlers and makes it impossible to debug code that has to interact in real-time.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Coming soon&#039;&#039;&#039;: We are currently developing an in-kernel gdb server that will allow to debug individual processes while leaving the kernel running and able to keep processing real-time code.&lt;/div&gt;</summary>
		<author><name>Fede.tft</name></author>
	</entry>
	<entry>
		<id>https://miosix.org/wiki/index.php?title=Miosix_code_size_optimization&amp;diff=457</id>
		<title>Miosix code size optimization</title>
		<link rel="alternate" type="text/html" href="https://miosix.org/wiki/index.php?title=Miosix_code_size_optimization&amp;diff=457"/>
		<updated>2026-05-10T21:10:47Z</updated>

		<summary type="html">&lt;p&gt;Fede.tft: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Miosix is designed with the idea to be an &amp;quot;unix on a chip&amp;quot;, so it was built with the idea of packing as much standard compliance as possible, without cutting corners. Things like full support to the C and C++ standard libraries, including full support for the C++ STL, thread-safe exception handling, and seldom used features of the C standard libraries, including stdout redirection via&lt;br /&gt;
&amp;lt;source lang=&amp;quot;CPP&amp;quot;&amp;gt;&lt;br /&gt;
fclose(stdout);&lt;br /&gt;
stdout=fopen(&amp;quot;/sd/log.txt&amp;quot;,&amp;quot;w&amp;quot;);&lt;br /&gt;
puts(&amp;quot;writing to a file\n&amp;quot;);&lt;br /&gt;
fflush(stdout);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
are supported. This obviously comes with a code size penalty, especially considering that some features are enabled by default.&lt;br /&gt;
However, the kernel is very modular, so you don&#039;t have to pay the code size cost of unused features in your application.&lt;br /&gt;
&lt;br /&gt;
This guide lists a number of tips to adapt the Miosix kernel to the needs of code-size constrained embedded applications. The exact figures presented here may change as the kernel is developed further, but the tips are expected to remain valid. In this page we&#039;ll use as example the [[stm32f411ce_blackpill]] board but the tips presented here are generally applicable. For the application, we&#039;ll use an empty &#039;&#039;main()&#039;&#039; to focus on the size of the components of the kernel that are included by default as part of the boot phase:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;CPP&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;cstdio&amp;gt;&lt;br /&gt;
#include &amp;lt;thread&amp;gt;&lt;br /&gt;
#include &amp;lt;miosix.h&amp;gt;&lt;br /&gt;
#include &amp;lt;interfaces/bsp.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
using namespace std;&lt;br /&gt;
using namespace miosix;&lt;br /&gt;
&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
    return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With the default settings and, at the time of writing, Miosix version 3.01, the kernel size is a little over 40KB: 41304 bytes. With this guide it is possible to reduce code size down to 13KB with configuration options alone, and down to 8KB by slimming also the board support package.&lt;br /&gt;
&lt;br /&gt;
Note that optimizations can be applied in any order, there are no dependencies between the steps presented in this page, so you can mix and match to configure a kernel that suits the needs of your application.&lt;br /&gt;
&lt;br /&gt;
== Compile with Os ==&lt;br /&gt;
&lt;br /&gt;
The default [http://fedetft.wordpress.com/2009/10/01/gcc-optimization-flags GCC optimization flag] used in Miosix is &#039;&#039;-O2&#039;&#039;, which generates code optimized for speed. You can however choose &#039;&#039;-Os&#039;&#039; which optimizes for size by opening the file [https://github.com/fedetft/miosix-kernel/blob/master/miosix/config/Makefile.inc config/Makefile.inc], commenting out the &#039;&#039;-O2&#039;&#039; line, and uncommenting the &#039;&#039;-Os&#039;&#039; line, like this:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#OPT_OPTIMIZATION ?= -O0&lt;br /&gt;
#OPT_OPTIMIZATION ?= -O2&lt;br /&gt;
#OPT_OPTIMIZATION ?= -O3&lt;br /&gt;
OPT_OPTIMIZATION ?= -Os&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Remember to do a &#039;&#039;make clean; make&#039;&#039; to rebuild the entire kernel for the changes to take effect.&lt;br /&gt;
&lt;br /&gt;
The code size will usually decrease as a percentage of the total code size, as this option affects how the compiler generates code. 5 to 10% decrease is a common figure. Although I haven&#039;t found benchmarks showing how much this affects execution speed, usually the impact isn&#039;t that high, and code runs definitely much faster with respect to disabling optimizations altogether (with &#039;&#039;-O0&#039;&#039;), so if you are tight on code size this is an easy option that does not require to sacrifice any feature of the kernel.&lt;br /&gt;
&lt;br /&gt;
With the empty &#039;&#039;main()&#039;&#039;, Miosix v3.01 and the stm32f411ce_blackpill, the code size was reduced to 39368 bytes.&lt;br /&gt;
&lt;br /&gt;
== Disable DevFs ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; starting from Miosix 3, DevFs is disabled by default, so there&#039;s nothing to do here. This section is kept for reference.&lt;br /&gt;
&lt;br /&gt;
Miosix 2 comes with an in-memory filesystem, mounted at &#039;&#039;/dev&#039;&#039; where device files can be added, similarly to how a Linux machine works. The main purpose of this is to allow [[Miosix processes|processes]] to access peripherals, since due to memory protection they can&#039;t just access the peripheral registers. However, processes are currently disabled by default because they&#039;re still an experimental feature, so you can disable DevFs too. This can be done by commenting out the &#039;&#039;WITH_DEVFS&#039;&#039; line in [https://github.com/fedetft/miosix-kernel/blob/master/miosix/config/miosix_settings.h config/miosix_settings.h], like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;CPP&amp;quot;&amp;gt;&lt;br /&gt;
//#define WITH_DEVFS&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Disable the filesystem entirely ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; starting from Miosix 3, the filesystem is disabled by default since only some board provide the required hardware, so there&#039;s nothing to do here. This section is kept for reference.&lt;br /&gt;
&lt;br /&gt;
Miosix 2 has a completely rewritten filesystem subsystem, supporting multiple mountpoints, extensible filesystem types (currently Fat32 and DevFs), unicode UTF8 in file names, directory listing via the standard &#039;&#039;opendir()&#039;&#039;/&#039;&#039;readdir()&#039;&#039;/&#039;&#039;closedir()&#039;&#039; and more POSIX compliance, including inode emulation for Fat32. This comes at a code size cost, though. If your application does not need to read/write from files, you can disable the filesystem subsystem entirely. To do so, open [https://github.com/fedetft/miosix-kernel/blob/master/miosix/config/miosix_settings.h config/miosix_settings.h] and comment out both the &#039;&#039;WITH_DEVFS&#039;&#039; and &#039;&#039;WITH_FILESYSTEM&#039;&#039; lines.&lt;br /&gt;
&lt;br /&gt;
== Use iprintf() instead of printf() in your application ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; since this example focuses on an empty main, there&#039;s nothing to do here, but this tip is worth knowing when writing application code.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;iprintf()&#039;&#039; is a non-standard extension of the [https://www.sourceware.org/newlib newlib] C library used by Miosix. It can do all what &#039;&#039;printf()&#039;&#039; can do except printing floating point numbers, and that&#039;s why its code size is significantly lower, printing floating point numbers is quite complicated. Miosix already uses &#039;&#039;iprintf()&#039;&#039; internally, so to see the code size difference you have to write the following simple code in &#039;&#039;main()&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;CPP&amp;quot;&amp;gt;&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
    int i=0;&lt;br /&gt;
    printf(&amp;quot;%d\n&amp;quot;,i);&lt;br /&gt;
    //iprintf(&amp;quot;%d\n&amp;quot;,i);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Trying with &#039;&#039;iprintf()&#039;&#039; instead of &#039;&#039;printf()&#039;&#039;, a 18KB code size reduction is observed. Note that you have to use a format string containing a % argument, such as %d to see the code size difference. If there is no % in the format string, GCC may replace &#039;&#039;printf()&#039;&#039;/&#039;&#039;iprintf()&#039;&#039; with a call to &#039;&#039;puts()&#039;&#039; as an optimization, and no code size difference can be seen.&lt;br /&gt;
&lt;br /&gt;
== Disable the C++ exception runtime ==&lt;br /&gt;
&lt;br /&gt;
The Miosix kernel is by default compiled with support for C++ exceptions, and unless you&#039;re also enabling [[Miosix processes|processes]] that depend on C++ exceptions, it is possible to disable their support. To do so, open [https://github.com/fedetft/miosix-kernel/blob/master/miosix/config/Makefile.inc config/Makefile.inc] and uncomment the following line:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
OPT_EXCEPT := -fno-exceptions -fno-rtti -D__NO_EXCEPTIONS&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Remember to do a &#039;&#039;make clean; make&#039;&#039; to rebuild the entire kernel for the changes to take effect.&lt;br /&gt;
&lt;br /&gt;
The code size is reduced to 24384 bytes, but comes with quite an important side effect: if the heap is full, the kernel will reboot the machine. To explain why it is so, consider that the normal behavior in Miosix to handle a full heap is that the C &#039;&#039;malloc()&#039;&#039; returns &#039;&#039;NULL&#039;&#039;, while the C++ &#039;&#039;operator new&#039;&#039; throws an exception of type &#039;&#039;bad_alloc&#039;&#039;. Now, when exceptions are disabled, &#039;&#039;new&#039;&#039; can no longer throw, but C++ code inside the C++ standard library doesn&#039;t check for &#039;&#039;NULL&#039;&#039;, as it expects an exception, and that would result in undefined behavior. The only way to prevent undefined behavior, is to reboot the machine, and that is what Miosix does if you disable exceptions.&lt;br /&gt;
&lt;br /&gt;
== Disable boot logs ==&lt;br /&gt;
&lt;br /&gt;
Maybe you&#039;re not using &#039;&#039;printf()&#039;&#039; at all in your application, however in this case you&#039;re still paying for the code size of &#039;&#039;iprintf()&#039;&#039; as the kernel uses it to print boot logs and error logs. To disable them, you can open [https://github.com/fedetft/miosix-kernel/blob/master/miosix/config/miosix_settings.h config/miosix_settings.h] and comment out the lines &#039;&#039;#define WITH_BOOTLOG&#039;&#039; and &#039;&#039;#define WITH_ERRLOG&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;CPP&amp;quot;&amp;gt;&lt;br /&gt;
/// \def WITH_BOOTLOG&lt;br /&gt;
/// Uncomment to print bootlogs on stdout.&lt;br /&gt;
/// By default it is defined (bootlogs are printed)&lt;br /&gt;
//#define WITH_BOOTLOG&lt;br /&gt;
&lt;br /&gt;
/// \def WITH_ERRLOG&lt;br /&gt;
/// Uncomment for debug information on stdout.&lt;br /&gt;
/// By default it is defined (error information is printed)&lt;br /&gt;
//#define WITH_ERRLOG&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This allows to save the code size of iprintf, but this is only true if there&#039;s no &#039;&#039;printf()&#039;&#039; call in your code, otherewise the code size saving will be minimal.&lt;br /&gt;
&lt;br /&gt;
Also, keep in mind that error logs are a powerful tool to [[Debugging|debug]] crashes of your application or the kernel during code development, so you may want to disable them only in release builds, and keep them enabled during development.&lt;br /&gt;
&lt;br /&gt;
Finally, note that you can still access the serial port without using &#039;&#039;printf()&#039;&#039;, by means of the POSIX calls &#039;&#039;write()&#039;&#039; and &#039;&#039;read()&#039;&#039;, using &#039;&#039;STDOUT_FILENO&#039;&#039; and &#039;&#039;STDIN_FILENO&#039;&#039; as the &#039;&#039;fd&#039;&#039; argument.&lt;br /&gt;
&lt;br /&gt;
With this optimization, the code size is reduced to 13084 bytes.&lt;br /&gt;
&lt;br /&gt;
== One more thing, disable the serial port ==&lt;br /&gt;
&lt;br /&gt;
The kernel, during the boot process, configures a serial port on nearly all the supported boards. If you really have no use for the serial port, you can disable it entirely, saving additional code size. To do so there is no configuration option, but you can edit the board support package file of your board. For the &#039;&#039;stm32f411ce_blackpill&#039;&#039; it&#039;s [https://github.com/fedetft/miosix-kernel/blob/master/miosix/arch/board/stm32f411ce_blackpill/interfaces-impl/bsp.cpp miosix-kernel/miosix/arch/board/stm32f411ce_blackpill/interfaces-impl/bsp.cpp]. Open the file and comment out the following lines in &#039;&#039;IRQbspInit()&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;CPP&amp;quot;&amp;gt;&lt;br /&gt;
    // IRQsetDefaultConsole(&lt;br /&gt;
    //     STM32SerialBase::get&amp;lt;defaultSerialTxPin,defaultSerialRxPin,&lt;br /&gt;
    //     defaultSerialRtsPin,defaultSerialCtsPin&amp;gt;(&lt;br /&gt;
    //         defaultSerial,defaultSerialSpeed,&lt;br /&gt;
    //         defaultSerialFlowctrl,defaultSerialDma));&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
as well as the following line in &#039;&#039;shutdown()&#039;&#039; and &#039;&#039;reboot()&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;CPP&amp;quot;&amp;gt;&lt;br /&gt;
    //ioctl(STDOUT_FILENO,IOCTL_SYNC,0);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By applying also this last tip code size can be reduced to 8436 bytes.&lt;br /&gt;
&lt;br /&gt;
[[Category:Installation and Configuration]]&lt;br /&gt;
[[Category:Optimization]]&lt;/div&gt;</summary>
		<author><name>Fede.tft</name></author>
	</entry>
	<entry>
		<id>https://miosix.org/wiki/index.php?title=Miosix_code_size_optimization&amp;diff=456</id>
		<title>Miosix code size optimization</title>
		<link rel="alternate" type="text/html" href="https://miosix.org/wiki/index.php?title=Miosix_code_size_optimization&amp;diff=456"/>
		<updated>2026-05-10T21:07:54Z</updated>

		<summary type="html">&lt;p&gt;Fede.tft: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Miosix is designed with the idea to be an &amp;quot;unix on a chip&amp;quot;, so it was built with the idea of packing as much standard compliance as possible, without cutting corners. Things like full support to the C and C++ standard libraries, including full support for the C++ STL, thread-safe exception handling, and seldom used features of the C standard libraries, including stdout redirection via&lt;br /&gt;
&amp;lt;source lang=&amp;quot;CPP&amp;quot;&amp;gt;&lt;br /&gt;
fclose(stdout);&lt;br /&gt;
stdout=fopen(&amp;quot;/sd/log.txt&amp;quot;,&amp;quot;w&amp;quot;);&lt;br /&gt;
puts(&amp;quot;writing to a file\n&amp;quot;);&lt;br /&gt;
fflush(stdout);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
are supported. This obviously comes with a code size penalty, especially considering that some features are enabled by default.&lt;br /&gt;
However, the kernel is very modular, so you don&#039;t have to pay the code size cost of unused features in your application.&lt;br /&gt;
&lt;br /&gt;
This guide lists a number of tips to adapt the Miosix kernel to the needs of code-size constrained embedded applications. The exact figures presented here may change as the kernel is developed further, but the tips are expected to remain valid. In this page we&#039;ll use as example the [[stm32f411ce_blackpill]] board but the tips presented here are generally applicable. For the application, we&#039;ll use an empty &#039;&#039;main()&#039;&#039; to focus on the size of the components of the kernel that are included by default as part of the boot phase:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;CPP&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;cstdio&amp;gt;&lt;br /&gt;
#include &amp;lt;thread&amp;gt;&lt;br /&gt;
#include &amp;lt;miosix.h&amp;gt;&lt;br /&gt;
#include &amp;lt;interfaces/bsp.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
using namespace std;&lt;br /&gt;
using namespace miosix;&lt;br /&gt;
&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
    return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With the default settings and, at the time of writing, Miosix version 3.01, the kernel size is a little over 40KB: 41304 bytes. With this guide it is possible to reduce code size down to 13KB with configuration options alone, and down to 8KB by slimming also the board support package.&lt;br /&gt;
&lt;br /&gt;
Note that optimizations can be applied in any order, there are no dependencies between the steps presented in this page, so you can mix and match to configure a kernel that suits the needs of your application.&lt;br /&gt;
&lt;br /&gt;
== Compile with Os ==&lt;br /&gt;
&lt;br /&gt;
The default [http://fedetft.wordpress.com/2009/10/01/gcc-optimization-flags GCC optimization flag] used in Miosix is &#039;&#039;-O2&#039;&#039;, which generates code optimized for speed. You can however choose &#039;&#039;-Os&#039;&#039; which optimizes for size by opening the file [https://github.com/fedetft/miosix-kernel/blob/master/miosix/config/Makefile.inc config/Makefile.inc], commenting out the &#039;&#039;-O2&#039;&#039; line, and uncommenting the &#039;&#039;-Os&#039;&#039; line, like this:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#OPT_OPTIMIZATION ?= -O0&lt;br /&gt;
#OPT_OPTIMIZATION ?= -O2&lt;br /&gt;
#OPT_OPTIMIZATION ?= -O3&lt;br /&gt;
OPT_OPTIMIZATION ?= -Os&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Remember to do a &#039;&#039;make clean; make&#039;&#039; to rebuild the entire kernel for the changes to take effect.&lt;br /&gt;
&lt;br /&gt;
The code size will usually decrease as a percentage of the total code size, as this option affects how the compiler generates code. 5 to 10% decrease is a common figure. Although I haven&#039;t found benchmarks showing how much this affects execution speed, usually the impact isn&#039;t that high, and code runs definitely much faster with respect to disabling optimizations altogether (with &#039;&#039;-O0&#039;&#039;), so if you are tight on code size this is an easy option that does not require to sacrifice any feature of the kernel.&lt;br /&gt;
&lt;br /&gt;
With the empty &#039;&#039;main()&#039;&#039;, Miosix v3.10 and the stm32f411ce_blackpill, the code size was reduced to 39368 bytes.&lt;br /&gt;
&lt;br /&gt;
== Disable DevFs ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; starting from Miosix 3, DevFs is disabled by default, so there&#039;s nothing to do here. This section is kept for reference.&lt;br /&gt;
&lt;br /&gt;
Miosix 2 comes with an in-memory filesystem, mounted at &#039;&#039;/dev&#039;&#039; where device files can be added, similarly to how a Linux machine works. The main purpose of this is to allow [[Miosix processes|processes]] to access peripherals, since due to memory protection they can&#039;t just access the peripheral registers. However, processes are currently disabled by default because they&#039;re still an experimental feature, so you can disable DevFs too. This can be done by commenting out the &#039;&#039;WITH_DEVFS&#039;&#039; line in [https://github.com/fedetft/miosix-kernel/blob/master/miosix/config/miosix_settings.h config/miosix_settings.h], like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;CPP&amp;quot;&amp;gt;&lt;br /&gt;
//#define WITH_DEVFS&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Disable the filesystem entirely ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; starting from Miosix 3, the filesystem is disabled by default since only some board provide the required hardware, so there&#039;s nothing to do here. This section is kept for reference.&lt;br /&gt;
&lt;br /&gt;
Miosix 2 has a completely rewritten filesystem subsystem, supporting multiple mountpoints, extensible filesystem types (currently Fat32 and DevFs), unicode UTF8 in file names, directory listing via the standard &#039;&#039;opendir()&#039;&#039;/&#039;&#039;readdir()&#039;&#039;/&#039;&#039;closedir()&#039;&#039; and more POSIX compliance, including inode emulation for Fat32. This comes at a code size cost, though. If your application does not need to read/write from files, you can disable the filesystem subsystem entirely. To do so, open [https://github.com/fedetft/miosix-kernel/blob/master/miosix/config/miosix_settings.h config/miosix_settings.h] and comment out both the &#039;&#039;WITH_DEVFS&#039;&#039; and &#039;&#039;WITH_FILESYSTEM&#039;&#039; lines.&lt;br /&gt;
&lt;br /&gt;
== Use iprintf() instead of printf() in your application ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; since this example focuses on an empty main, there&#039;s nothing to do here, but this tip is worth knowing when writing application code.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;iprintf()&#039;&#039; is a non-standard extension of the [https://www.sourceware.org/newlib newlib] C library used by Miosix. It can do all what &#039;&#039;printf()&#039;&#039; can do except printing floating point numbers, and that&#039;s why its code size is significantly lower, printing floating point numbers is quite complicated. Miosix already uses &#039;&#039;iprintf()&#039;&#039; internally, so to see the code size difference you have to write the following simple code in &#039;&#039;main()&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;CPP&amp;quot;&amp;gt;&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
    int i=0;&lt;br /&gt;
    printf(&amp;quot;%d\n&amp;quot;,i);&lt;br /&gt;
    //iprintf(&amp;quot;%d\n&amp;quot;,i);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Trying with &#039;&#039;iprintf()&#039;&#039; instead of &#039;&#039;printf()&#039;&#039;, a 18KB code size reduction is observed. Note that you have to use a format string containing a % argument, such as %d to see the code size difference. If there is no % in the format string, GCC may replace &#039;&#039;printf()&#039;&#039;/&#039;&#039;iprintf()&#039;&#039; with a call to &#039;&#039;puts()&#039;&#039; as an optimization, and no code size difference can be seen.&lt;br /&gt;
&lt;br /&gt;
== Disable the C++ exception runtime ==&lt;br /&gt;
&lt;br /&gt;
The Miosix kernel is by default compiled with support for C++ exceptions, and unless you&#039;re also enabling [[Miosix processes|processes]] that depend on C++ exceptions, it is possible to disable their support. To do so, open [https://github.com/fedetft/miosix-kernel/blob/master/miosix/config/Makefile.inc config/Makefile.inc] and uncomment the following line:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
OPT_EXCEPT := -fno-exceptions -fno-rtti -D__NO_EXCEPTIONS&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Remember to do a &#039;&#039;make clean; make&#039;&#039; to rebuild the entire kernel for the changes to take effect.&lt;br /&gt;
&lt;br /&gt;
The code size is reduced to 24384 bytes, but comes with quite an important side effect: if the heap is full, the kernel will reboot the machine. To explain why it is so, consider that the normal behavior in Miosix to handle a full heap is that the C &#039;&#039;malloc()&#039;&#039; returns &#039;&#039;NULL&#039;&#039;, while the C++ &#039;&#039;operator new&#039;&#039; throws an exception of type &#039;&#039;bad_alloc&#039;&#039;. Now, when exceptions are disabled, &#039;&#039;new&#039;&#039; can no longer throw, but C++ code inside the C++ standard library doesn&#039;t check for &#039;&#039;NULL&#039;&#039;, as it expects an exception, and that would result in undefined behavior. The only way to prevent undefined behavior, is to reboot the machine, and that is what Miosix does if you disable exceptions.&lt;br /&gt;
&lt;br /&gt;
== Disable boot logs ==&lt;br /&gt;
&lt;br /&gt;
Maybe you&#039;re not using &#039;&#039;printf()&#039;&#039; at all in your application, however in this case you&#039;re still paying for the code size of &#039;&#039;iprintf()&#039;&#039; as the kernel uses it to print boot logs and error logs. To disable them, you can open [https://github.com/fedetft/miosix-kernel/blob/master/miosix/config/miosix_settings.h config/miosix_settings.h] and comment out the lines &#039;&#039;#define WITH_BOOTLOG&#039;&#039; and &#039;&#039;#define WITH_ERRLOG&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;CPP&amp;quot;&amp;gt;&lt;br /&gt;
/// \def WITH_BOOTLOG&lt;br /&gt;
/// Uncomment to print bootlogs on stdout.&lt;br /&gt;
/// By default it is defined (bootlogs are printed)&lt;br /&gt;
//#define WITH_BOOTLOG&lt;br /&gt;
&lt;br /&gt;
/// \def WITH_ERRLOG&lt;br /&gt;
/// Uncomment for debug information on stdout.&lt;br /&gt;
/// By default it is defined (error information is printed)&lt;br /&gt;
//#define WITH_ERRLOG&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This allows to save the code size of iprintf, but this is only true if there&#039;s no &#039;&#039;printf()&#039;&#039; call in your code, otherewise the code size saving will be minimal.&lt;br /&gt;
&lt;br /&gt;
Also, keep in mind that error logs are a powerful tool to [[Debugging|debug]] crashes of your application or the kernel during code development, so you may want to disable them only in release builds, and keep them enabled during development.&lt;br /&gt;
&lt;br /&gt;
Finally, note that you can still access the serial port without using &#039;&#039;printf()&#039;&#039;, by means of the POSIX calls &#039;&#039;write()&#039;&#039; and &#039;&#039;read()&#039;&#039;, using &#039;&#039;STDOUT_FILENO&#039;&#039; and &#039;&#039;STDIN_FILENO&#039;&#039; as the &#039;&#039;fd&#039;&#039; argument.&lt;br /&gt;
&lt;br /&gt;
With this optimization, the code size is reduced to 13084 bytes.&lt;br /&gt;
&lt;br /&gt;
== One more thing, disable the serial port ==&lt;br /&gt;
&lt;br /&gt;
The kernel, during the boot process, configures a serial port on nearly all the supported boards. If you really have no use for the serial port, you can disable it entirely, saving additional code size. To do so there is no configuration option, but you can edit the board support package file of your board. For the &#039;&#039;stm32f411ce_blackpill&#039;&#039; it&#039;s [https://github.com/fedetft/miosix-kernel/blob/master/miosix/arch/board/stm32f411ce_blackpill/interfaces-impl/bsp.cpp miosix-kernel/miosix/arch/board/stm32f411ce_blackpill/interfaces-impl/bsp.cpp]. Open the file and comment out the following lines in &#039;&#039;IRQbspInit()&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;CPP&amp;quot;&amp;gt;&lt;br /&gt;
    // IRQsetDefaultConsole(&lt;br /&gt;
    //     STM32SerialBase::get&amp;lt;defaultSerialTxPin,defaultSerialRxPin,&lt;br /&gt;
    //     defaultSerialRtsPin,defaultSerialCtsPin&amp;gt;(&lt;br /&gt;
    //         defaultSerial,defaultSerialSpeed,&lt;br /&gt;
    //         defaultSerialFlowctrl,defaultSerialDma));&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
as well as the following line in &#039;&#039;shutdown()&#039;&#039; and &#039;&#039;reboot()&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;CPP&amp;quot;&amp;gt;&lt;br /&gt;
    //ioctl(STDOUT_FILENO,IOCTL_SYNC,0);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By applying also this last tip code size can be reduced to 8436 bytes.&lt;br /&gt;
&lt;br /&gt;
[[Category:Installation and Configuration]]&lt;br /&gt;
[[Category:Optimization]]&lt;/div&gt;</summary>
		<author><name>Fede.tft</name></author>
	</entry>
	<entry>
		<id>https://miosix.org/wiki/index.php?title=Windows_Quick_Start&amp;diff=455</id>
		<title>Windows Quick Start</title>
		<link rel="alternate" type="text/html" href="https://miosix.org/wiki/index.php?title=Windows_Quick_Start&amp;diff=455"/>
		<updated>2026-05-10T21:03:18Z</updated>

		<summary type="html">&lt;p&gt;Fede.tft: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Installing the required software =&lt;br /&gt;
&lt;br /&gt;
== Miosix Toolchain ==&lt;br /&gt;
&lt;br /&gt;
To be able to compile the Miosix kernel and your application, you need a patched version of the GCC compiler called Miosix toolchain, you can find the link to download it [[Miosix Toolchain|here]]. At the end of the installation you will need to reboot your computer (sorry, it&#039;s Windows...)&lt;br /&gt;
&lt;br /&gt;
== Git ==&lt;br /&gt;
&lt;br /&gt;
To download the Miosix kernel and keep it up to date, you need the [https://en.wikipedia.org/wiki/Git_%28software%29 git] version control system.&lt;br /&gt;
&lt;br /&gt;
It is recommended to install it from [http://www.git-scm.com/download/win git-scm.com]. Please &#039;&#039;&#039;do not&#039;&#039;&#039; uncheck the &#039;&#039;Windows Explorer integration&#039;&#039; feature during the installation, as you will need it to install the kernel sources.&lt;br /&gt;
&lt;br /&gt;
== Perl ==&lt;br /&gt;
&lt;br /&gt;
The [https://en.wikipedia.org/wiki/Perl Perl] programming language is used by the Miosix build system. Unlike on GNU/Linux computers where Perl is pre-installed, for Windows you&#039;ll need to install it separately.&lt;br /&gt;
&lt;br /&gt;
[http://strawberryperl.com Strawberry perl] is the recomended Perl version for Miosix on Windows.&lt;br /&gt;
&lt;br /&gt;
== Flashing tool ==&lt;br /&gt;
&lt;br /&gt;
With the installed Miosix toolchain you&#039;ll be able to compile the kernel, but you&#039;ll also need a way to transfer it to your microcontroller. This operation is usually called &#039;flashing&#039; the microcontroller. Miosix can work with any flashing utility that accepts as input raw binary files, and on Windows you&#039;ll usually want to install the flashing tool provided by your chip vendor.&lt;br /&gt;
&lt;br /&gt;
For STM32 chips, you can use the STLink utility available [http://www.st.com/web/en/catalog/tools/PF258168# here].&lt;br /&gt;
&lt;br /&gt;
== Text editor or IDE ==&lt;br /&gt;
&lt;br /&gt;
It is recommended to download a better text editor than Notepad, as you will need it to edit the Miosix configuration files. [http://www.notepad-plus-plus.org/ Notepad++] is a good option, but many other options exist. Just &#039;&#039;&#039;don&#039;t use Notepad&#039;&#039;&#039;, because it does not recognize Unix [https://en.wikipedia.org/wiki/Line_ending line-endings] and will show you Miosix source files as if they were composed of a single line of text.&lt;br /&gt;
&lt;br /&gt;
As an alternative to Notepad++, you may want to use an [[IDEs|IDE]].&lt;br /&gt;
&lt;br /&gt;
== Serial port viewer ==&lt;br /&gt;
&lt;br /&gt;
Miosix redirects &#039;&#039;stdin&#039;&#039;/&#039;&#039;stdout&#039;&#039; to a serial port by default on most boards, so to see the boot log and the output of &#039;&#039;printf()&#039;&#039; in your application you need a program to interact with the serial port. [https://putty.org/index.html PuTTY] is an option, although old fashioned. TODO: There are likely better options for Windows too.&lt;br /&gt;
&lt;br /&gt;
= Downloading and configuring the Miosix kernel =&lt;br /&gt;
&lt;br /&gt;
This section is a stripped down guide with the bare minimum to get you started, we also have a full guide about [[Miosix and git workflow]]. Following the tutorial in this page, your project directory will &#039;&#039;&#039;not&#039;&#039;&#039; be under version control (git). The [[Miosix and git workflow]] page shows how to create a git repository for your project and add the Miosix kernel as a git submodule.&lt;br /&gt;
&lt;br /&gt;
Before downloading the kernel, however, you first have to create &#039;&#039;&#039;a directory for your project&#039;&#039;&#039; (in this case, the hello world), and then clone the kernel &#039;&#039;&#039;as a subdirectory&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Using the Windows explorer, create a &#039;&#039;&#039;hello&#039;&#039;&#039; directory, double click on it. Then right-click on the empty directory. Select &#039;&#039;Git bash&#039;&#039; to open a git shell. This opens a shell where you can type the commands to download the kernel.&lt;br /&gt;
&lt;br /&gt;
[[File:Git-bash-windows.png]]&lt;br /&gt;
&lt;br /&gt;
Note that it is possible to paste commands in the shell (so as to avoid typing them, which can be tedious and lead to typos), but you have to do it one line of text at a time, and to paste you need to use the &#039;&#039;Shift+Ins&#039;&#039; shortcut, not the usual &#039;&#039;Ctrl+V&#039;&#039; one. The last command, &#039;&#039;exit&#039;&#039;, will close the shell.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git clone https://github.com/fedetft/miosix-kernel.git&lt;br /&gt;
exit&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that there is also a &#039;&#039;Git GUI&#039;&#039; in the right click menu, but git is best used from a command line interface, you&#039;re on your own if you choose to use git from the GUI.&lt;br /&gt;
&lt;br /&gt;
== Initializing a Miosix project ==&lt;br /&gt;
&lt;br /&gt;
For reasons explained in depth in the [[Miosix and git workflow]] page, you&#039;ll need to copy the Miosix configuration directory from the kernel sources to your project directory, as well as create a template project where you can start writing code.&lt;br /&gt;
This can be automated with a [https://en.wikipedia.org/wiki/Perl Perl] script called &#039;&#039;init_project_out_of_git_tree.pl&#039;&#039;. To run it, you need to open a Windows terminal (which is a &#039;&#039;&#039;different&#039;&#039;&#039; terminal than the git bash we used before), which can be done by &#039;&#039;Shift+Right click&#039;&#039; and selecting &#039;&#039;Open command window here&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
[[File:Open-terminal-windows.png]]&lt;br /&gt;
&lt;br /&gt;
Then, type the following command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
perl miosix-kernel/tools/init_project_out_of_git_tree.pl&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Leave the terminal open as you&#039;ll need it later.&lt;br /&gt;
&lt;br /&gt;
You should run the script from the directory where you want to initialize your empty project, such as the &#039;&#039;&#039;hello&#039;&#039;&#039; directory in this tutorial. A successful run of the script produces the following output:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Successfully created Miosix project&lt;br /&gt;
Target directory: hello&lt;br /&gt;
Kernel directory: hello/miosix-kernel/miosix&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Your project directory should now look like the following picture, with the &#039;&#039;miosix-kernel&#039;&#039; directory containing the kernel sources, the &#039;&#039;config&#039;&#039; directory with the kernel configuration, the empty &#039;&#039;main.cpp&#039;&#039; and the build files for the two alternative build systems supported by Miosix: Makefile and CMake:&lt;br /&gt;
&lt;br /&gt;
[[File:Initialized-miosix-project-windows.png]]&lt;br /&gt;
&lt;br /&gt;
For this tutorial, we&#039;ll use the Makefile build system, have a look at the [[CMake]] page to learn how to use CMake instead.&lt;br /&gt;
&lt;br /&gt;
== Configuring the kernel ==&lt;br /&gt;
&lt;br /&gt;
The minimum configuration required to compile the kernel is to &#039;&#039;&#039;select a board&#039;&#039;&#039;, as the kernel needs to build the appropriate board support package for it.&lt;br /&gt;
&lt;br /&gt;
The Miosix kernel has several other build-time configuration options, to enable optional components (filesystem, userspace processes), select algorithms such as the scheduler and trade feature support for code size, but these won&#039;t be covered here.&lt;br /&gt;
The kernel is configured by editing files in the config directory, the two most important ones are [https://github.com/fedetft/miosix-kernel/blob/master/miosix/config/Makefile.inc Makefile.inc] and [https://github.com/fedetft/miosix-kernel/blob/master/miosix/config/miosix_settings.h miosix_settings.h].&lt;br /&gt;
&lt;br /&gt;
To select a board, using Notepad++ open the first one, &#039;&#039;config/Makefile.inc&#039;&#039;. Look for the &#039;&#039;OPT_BOARD&#039;&#039; section of the file, which contains the list of boards officially supported by the kernel. In this section, all boards appear commented out (the &#039;&#039;#&#039;&#039; sign is a comment in Makefile syntax), so you need to uncomment the line corrsponding to your board. [[Porting]] the kernel to a new board is an advanced topic not covered here, so we&#039;ll assume you&#039;ll want to use an officially supported board. As an example, in this tutorial we&#039;ll use the stm32f746zg_nucleo board:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
#OPT_BOARD := stm32f469ni_stm32f469i-disco&lt;br /&gt;
OPT_BOARD := stm32f746zg_nucleo&lt;br /&gt;
#OPT_BOARD := stm32f765ii_marco_ram_board&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you do not yet have a board, you can follow along and get to the compiled firmware anyway. If you&#039;re looking for suggestions on which board to get, consider that most boards currently supported by Miosix are for STM32 microcontrollers. Here&#039;s a basic guide:&lt;br /&gt;
* &#039;&#039;&#039;Nucleo&#039;&#039;&#039; STM32 boards produced by ST are good for beginners, as they allow to power the board, flash it, debug it and access the serial port all through a single USB connection with your computer. The stm32f401re_nucleo and stm32f411re_nucleo are realtively low cost.&lt;br /&gt;
* &#039;&#039;&#039;Discovery&#039;&#039;&#039; STM32 boards are also good, but they don&#039;t include an USB to serial adapter so you&#039;ll have to buy it separately and you&#039;ll end up having to connect two USB cables, one for power/programming/debugging and one for the serial port.&lt;br /&gt;
* &#039;&#039;&#039;Third party&#039;&#039;&#039; STM32 boards such as the stm32f411ce_blackpill are cheaper and great to embed in your hardware project, but you&#039;ll have to [[https://en.wikipedia.org/wiki/Soldering solder]] the pin header yourself, and you&#039;ll need to attach a separate USB to serial adapter, and if you want in-circuit debugging you&#039;ll need an STLink adapter, so you&#039;ll end up having to run up to three separate USB cables from your computer to the board for power/programming, serial port and debugging.&lt;br /&gt;
* Venturing outside of STM32, the &#039;&#039;&#039;RP2040&#039;&#039;&#039; is a good choice. Also in this case, you&#039;ll need a separate USB to serial adapter and some soldering skills, though.&lt;br /&gt;
&lt;br /&gt;
= Writing your first Miosix program =&lt;br /&gt;
&lt;br /&gt;
== Hello world ==&lt;br /&gt;
&lt;br /&gt;
With Notepad++ open the &#039;&#039;main.cpp&#039;&#039; file with your [[IDEs | IDE]] or text editor of choice, and replace its content with the following program:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;CPP&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;cstdio&amp;gt;&lt;br /&gt;
#include &amp;lt;thread&amp;gt;&lt;br /&gt;
#include &amp;lt;miosix.h&amp;gt;&lt;br /&gt;
#include &amp;lt;interfaces/bsp.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
using namespace std;&lt;br /&gt;
using namespace miosix;&lt;br /&gt;
&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
    for(;;)&lt;br /&gt;
    {&lt;br /&gt;
        iprintf(&amp;quot;Hello world\n&amp;quot;);&lt;br /&gt;
        ledOn();&lt;br /&gt;
        this_thread::sleep_for(500ms);&lt;br /&gt;
        ledOff();&lt;br /&gt;
        this_thread::sleep_for(500ms);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
At this point, it&#039;s good to have a quick walkthrough of this hello world program. Miosix is based on a [[Fluid kernel]] architecture: in a nutshell it&#039;s a kernel that supports writing applications both inside the kernel, and inside userspace programs. In this tutorial, we&#039;re using it as a unikernel. This means when power is applied to the board, the kernel will boot, and then start running the &#039;&#039;main()&#039;&#039; function you just wrote &#039;&#039;in kernelspace&#039;&#039;. This means you have both support for C/C++ standard libraries and unrestricted hardware access.&lt;br /&gt;
&lt;br /&gt;
This main() function will print &amp;quot;Hello world&amp;quot; and blink an LED approximately every second.&lt;br /&gt;
The printing is done with the &#039;&#039;iprintf()&#039;&#039; function. If you expected just &#039;&#039;printf()&#039;&#039; without the &#039;&#039;i&#039;&#039;, the reason is that Miosix uses the [https://sourceware.org/newlib/ Newlib] C standard library that provides both &#039;&#039;printf()&#039;&#039; and &#039;&#039;iprintf()&#039;&#039;, an optimized version that is smaller in code size but incapable of printing floating point numbers. So you can also use &#039;&#039;printf()&#039;&#039; if you wish, but this optimization is worth knowing from the start.&lt;br /&gt;
&lt;br /&gt;
Sleeping to blink the LED is done with the [https://en.cppreference.com/cpp/thread/sleep_for sleep_for()] function from the C++ standard library. Miosix supports other sleeping APIs, such as [https://pubs.opengroup.org/onlinepubs/9699919799/functions/nanosleep.html nanosleep()] from POSIX, or &#039;&#039;Thread::sleep()&#039;&#039;, a native Miosix function. All these functions do the same thing: they tell the scheduler to stop the currently running thread, run some other thread, and resume execution after a given time interval. Miosix is a preemptive multithreading operating system, so you should get comfortable with the fact that the code you&#039;re writing lives in a thread and shares the CPU with other threads.&lt;br /&gt;
&lt;br /&gt;
Many (but not all!) board support packages define the &#039;&#039;ledOn()&#039;&#039; and &#039;&#039;ledOff()&#039;&#039; functions to control one of the LED on the board. This should be true for all the boards that have at least one software-accessible LED. This is true for the &#039;&#039;stm32f746zg_nucleo&#039;&#039; board we selected, but if you selected a different board with no LEDs, then compiling will fail with an error related to &#039;&#039;ledOn()&#039;&#039; and &#039;&#039;ledOff()&#039;&#039;. You can comment out those two lines in this case, your hello world will only print to the serial port.&lt;br /&gt;
&lt;br /&gt;
== Compiling ==&lt;br /&gt;
&lt;br /&gt;
In the same terminal you used to run Perl, type &#039;&#039;make&#039;&#039; to build the kernel.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
make&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If all goes well, the result should look like this.&lt;br /&gt;
&lt;br /&gt;
[[File:Make-output-windows.png]]&lt;br /&gt;
&lt;br /&gt;
Otherwise, compiler errors will appear in the shell. The number that appears under &#039;&#039;text&#039;&#039; in the make output is the size in bytes of your application plus the kernel. Don&#039;t worry about the 42KBytes code size, you&#039;re compiling with the default Miosix options, if you want you can play around with the options later to  [[Miosix code size optimization|reduce the code size]].&lt;br /&gt;
&lt;br /&gt;
== Flashing ==&lt;br /&gt;
&lt;br /&gt;
The procedure to flash the microcontroller board on Windows depends on the vendor-provided flashing tool. They usually provide a GUI where you can load the &#039;&#039;.bin&#039;&#039; file and then connect to the board and flash it. For Miosix the file is named main.bin if you&#039;re not using processes, or image.bin if you are using processes. For this tutorial, look for &#039;&#039;main.bin&#039;&#039; in the &#039;&#039;&#039;hello&#039;&#039;&#039; directory.&lt;br /&gt;
&lt;br /&gt;
If you correctly flashed the board, the LED will start blinking.&lt;br /&gt;
&lt;br /&gt;
== Accessing the serial port ==&lt;br /&gt;
&lt;br /&gt;
The USB to serial port adapter will appear on Windows as a randomly numbered COM port. To figure out the right number, you&#039;ll have to open &#039;&#039;Devices&#039;&#039; from the control panel:&lt;br /&gt;
&lt;br /&gt;
[[File:Windows-list-devices.png]]&lt;br /&gt;
&lt;br /&gt;
Today, on my computer, Windows decided to assign the STM32 board to COM3.&lt;br /&gt;
&lt;br /&gt;
Next up, open PuTTY and configure it to open the right COM port. Starting from Miosix v3.00, all boards use by default a baud rate of 115200bit/s, so input 115200 in the &#039;&#039;Speed&#039;&#039; field:&lt;br /&gt;
&lt;br /&gt;
[[File:Windows-putty-configuration.png]]&lt;br /&gt;
&lt;br /&gt;
Finally, click &#039;&#039;Open&#039;&#039; and you should see the serial port messages from the microcontroller. Since the board will be already running when you connect, you can press the RESET button on the board to reboot it and see the boot logs:&lt;br /&gt;
&lt;br /&gt;
[[File:Windows-putty-serial.png]]&lt;br /&gt;
&lt;br /&gt;
= A note on uninstalling software =&lt;br /&gt;
&lt;br /&gt;
To uninstall the Miosix Toolchain, you can find the uninstaller in the start menu under &#039;&#039;Miosix Toolchain&#039;&#039;. Note that the other tools such as Git, Perl and the STLink  utility have their own uninstallers.&lt;br /&gt;
&lt;br /&gt;
[[Category:Installation and Configuration]]&lt;/div&gt;</summary>
		<author><name>Fede.tft</name></author>
	</entry>
	<entry>
		<id>https://miosix.org/wiki/index.php?title=Windows_Quick_Start&amp;diff=454</id>
		<title>Windows Quick Start</title>
		<link rel="alternate" type="text/html" href="https://miosix.org/wiki/index.php?title=Windows_Quick_Start&amp;diff=454"/>
		<updated>2026-05-10T21:00:27Z</updated>

		<summary type="html">&lt;p&gt;Fede.tft: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Installing the required software =&lt;br /&gt;
&lt;br /&gt;
== Miosix Toolchain ==&lt;br /&gt;
&lt;br /&gt;
To be able to compile the Miosix kernel and your application, you need a patched version of the GCC compiler called Miosix toolchain, you can find the link to download it [[Miosix Toolchain|here]]. At the end of the installation you will need to reboot your computer (sorry, it&#039;s Windows...)&lt;br /&gt;
&lt;br /&gt;
== Git ==&lt;br /&gt;
&lt;br /&gt;
To download the Miosix kernel and keep it up to date, you need the [https://en.wikipedia.org/wiki/Git_%28software%29 git] version control system.&lt;br /&gt;
&lt;br /&gt;
It is recommended to install it from [http://www.git-scm.com/download/win git-scm.com]. Please &#039;&#039;&#039;do not&#039;&#039;&#039; uncheck the &#039;&#039;Windows Explorer integration&#039;&#039; feature during the installation, as you will need it to install the kernel sources.&lt;br /&gt;
&lt;br /&gt;
== Perl ==&lt;br /&gt;
&lt;br /&gt;
The [https://en.wikipedia.org/wiki/Perl Perl] programming language is used by the Miosix build system. Unlike on GNU/Linux computers where Perl is pre-installed, for Windows you&#039;ll need to install it separately.&lt;br /&gt;
&lt;br /&gt;
[http://strawberryperl.com Strawberry perl] is the recomended Perl version for Miosix on Windows.&lt;br /&gt;
&lt;br /&gt;
== Flashing tool ==&lt;br /&gt;
&lt;br /&gt;
With the installed Miosix toolchain you&#039;ll be able to compile the kernel, but you&#039;ll also need a way to transfer it to your microcontroller. This operation is usually called &#039;flashing&#039; the microcontroller. Miosix can work with any flashing utility that accepts as input raw binary files, and on Windows you&#039;ll usually want to install the flashing tool provided by your chip vendor.&lt;br /&gt;
&lt;br /&gt;
For STM32 chips, you can use the STLink utility available [http://www.st.com/web/en/catalog/tools/PF258168# here].&lt;br /&gt;
&lt;br /&gt;
== Text editor or IDE ==&lt;br /&gt;
&lt;br /&gt;
It is recommended to download a better text editor than Notepad, as you will need it to edit the Miosix configuration files. [http://www.notepad-plus-plus.org/ Notepad++] is a good option, but many other options exist. Just &#039;&#039;&#039;don&#039;t use Notepad&#039;&#039;&#039;, because it does not recognize Unix [https://en.wikipedia.org/wiki/Line_ending line-endings] and will show you Miosix source files as if they were composed of a single line of text.&lt;br /&gt;
&lt;br /&gt;
As an alternative to Notepad++, you may want to use an [[IDEs|IDE]].&lt;br /&gt;
&lt;br /&gt;
== Serial port viewer ==&lt;br /&gt;
&lt;br /&gt;
Miosix redirects &#039;&#039;stdin&#039;&#039;/&#039;&#039;stdout&#039;&#039; to a serial port by default on most boards, so to see the boot log and the output of &#039;&#039;printf()&#039;&#039; in your application you need a program to interact with the serial port. [https://putty.org/index.html PuTTY] is an option, although old fashioned. TODO: There are likely better options for Windows too.&lt;br /&gt;
&lt;br /&gt;
= Downloading and configuring the Miosix kernel =&lt;br /&gt;
&lt;br /&gt;
This section is a stripped down guide with the bare minimum to get you started, we also have a full guide about [[Miosix and git workflow]]. Following the tutorial in this page, your project directory will &#039;&#039;&#039;not&#039;&#039;&#039; be under version control (git). The [[Miosix and git workflow]] page shows how to create a git repository for your project and add the Miosix kernel as a git submodule.&lt;br /&gt;
&lt;br /&gt;
Before downloading the kernel, however, you first have to create &#039;&#039;&#039;a directory for your project&#039;&#039;&#039; (in this case, the hello world), and then clone the kernel &#039;&#039;&#039;as a subdirectory&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Using the Windows explorer, create a &#039;&#039;&#039;hello&#039;&#039;&#039; directory, double click on it. Then right-click on the empty directory. Select &#039;&#039;Git bash&#039;&#039; to open a git shell. This opens a shell where you can type the commands to download the kernel.&lt;br /&gt;
&lt;br /&gt;
[[File:Git-bash-windows.png]]&lt;br /&gt;
&lt;br /&gt;
Note that it is possible to paste commands in the shell (so as to avoid typing them, which can be tedious and lead to typos), but you have to do it one line of text at a time, and to paste you need to use the &#039;&#039;Shift+Ins&#039;&#039; shortcut, not the usual &#039;&#039;Ctrl+V&#039;&#039; one. The last command, &#039;&#039;exit&#039;&#039;, will close the shell.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git clone https://github.com/fedetft/miosix-kernel.git&lt;br /&gt;
exit&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that there is also a &#039;&#039;Git GUI&#039;&#039; in the right click menu, but git is best used from a command line interface, you&#039;re on your own if you choose to use git from the GUI.&lt;br /&gt;
&lt;br /&gt;
== Initializing a Miosix project ==&lt;br /&gt;
&lt;br /&gt;
For reasons explained in depth in the [[Miosix and git workflow]] page, you&#039;ll need to copy the Miosix configuration directory from the kernel sources to your project directory, as well as create a template project where you can start writing code.&lt;br /&gt;
This can be automated with a [https://en.wikipedia.org/wiki/Perl Perl] script called &#039;&#039;init_project_out_of_git_tree.pl&#039;&#039;. To run it, you need to open a Windows terminal (which is a &#039;&#039;&#039;different&#039;&#039;&#039; terminal than the git bash we used before), which can be done by &#039;&#039;Shift+Right click&#039;&#039; and selecting &#039;&#039;Open command window here&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
[[File:Open-terminal-windows.png]]&lt;br /&gt;
&lt;br /&gt;
Then, type the following command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
perl miosix-kernel/tools/init_project_out_of_git_tree.pl&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Leave the terminal open as you&#039;ll need it later.&lt;br /&gt;
&lt;br /&gt;
You should run the script from the directory where you want to initialize your empty project, such as the &#039;&#039;&#039;hello&#039;&#039;&#039; directory in this tutorial. A successful run of the script produces the following output:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Successfully created Miosix project&lt;br /&gt;
Target directory: hello&lt;br /&gt;
Kernel directory: hello/miosix-kernel/miosix&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Your project directory should now look like the following picture, with the &#039;&#039;miosix-kernel&#039;&#039; directory containing the kernel sources, the &#039;&#039;config&#039;&#039; directory with the kernel configuration, the empty &#039;&#039;main.cpp&#039;&#039; and the build files for the two alternative build systems supported by Miosix: Makefile and CMake:&lt;br /&gt;
&lt;br /&gt;
[[File:Initialized-miosix-project-windows.png]]&lt;br /&gt;
&lt;br /&gt;
For this tutorial, we&#039;ll use the Makefile build system, have a look at the [[CMake]] page to learn how to use CMake instead.&lt;br /&gt;
&lt;br /&gt;
== Configuring the kernel ==&lt;br /&gt;
&lt;br /&gt;
The minimum configuration required to compile the kernel is to &#039;&#039;&#039;select a board&#039;&#039;&#039;, as the kernel needs to build the appropriate board support package for it.&lt;br /&gt;
&lt;br /&gt;
The Miosix kernel has several other build-time configuration options, to enable optional components (filesystem, userspace processes), select algorithms such as the scheduler and trade feature support for code size, but these won&#039;t be covered here.&lt;br /&gt;
The kernel is configured by editing files in the config directory, the two most important ones are [https://github.com/fedetft/miosix-kernel/blob/master/miosix/config/Makefile.inc Makefile.inc] and [https://github.com/fedetft/miosix-kernel/blob/master/miosix/config/miosix_settings.h miosix_settings.h].&lt;br /&gt;
&lt;br /&gt;
To select a board, using Notepad++ open the first one, &#039;&#039;config/Makefile.inc&#039;&#039;. Look for the &#039;&#039;OPT_BOARD&#039;&#039; section of the file, which contains the list of boards officially supported by the kernel. In this section, all boards appear commented out (the &#039;&#039;#&#039;&#039; sign is a comment in Makefile syntax), so you need to uncomment the line corrsponding to your board. [[Porting]] the kernel to a new board is an advanced topic not covered here, so we&#039;ll assume you&#039;ll want to use an officially supported board. As an example, in this tutorial we&#039;ll use the stm32f746zg_nucleo board:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
#OPT_BOARD := stm32f469ni_stm32f469i-disco&lt;br /&gt;
OPT_BOARD := stm32f746zg_nucleo&lt;br /&gt;
#OPT_BOARD := stm32f765ii_marco_ram_board&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you do not yet have a board, you can follow along and get to the compiled firmware anyway. If you&#039;re looking for suggestions on which board to get, consider that most boards currently supported by Miosix are for STM32 microcontrollers. Here&#039;s a basic guide:&lt;br /&gt;
* &#039;&#039;&#039;Nucleo&#039;&#039;&#039; STM32 boards produced by ST are good for beginners, as they allow to power the board, flash it, debug it and access the serial port all through a single USB connection with your computer. The stm32f401re_nucleo and stm32f411re_nucleo are realtively low cost.&lt;br /&gt;
* &#039;&#039;&#039;Discovery&#039;&#039;&#039; STM32 boards are also good, but they don&#039;t include an USB to serial adapter so you&#039;ll have to buy it separately and you&#039;ll end up having to connect two USB cables, one for power/programming/debugging and one for the serial port.&lt;br /&gt;
* &#039;&#039;&#039;Third party&#039;&#039;&#039; STM32 boards such as the stm32f411ce_blackpill are cheaper and great to embed in your hardware project, but you&#039;ll have to [[https://en.wikipedia.org/wiki/Soldering solder]] the pin header yourself, and you&#039;ll need to attach a separate USB to serial adapter, and if you want in-circuit debugging you&#039;ll need an STLink adapter, so you&#039;ll end up having to run up to three separate USB cables from your computer to the board for power/programming, serial port and debugging.&lt;br /&gt;
* Venturing outside of STM32, the &#039;&#039;&#039;RP2040&#039;&#039;&#039; is a good choice. Also in this case, you&#039;ll need a separate USB to serial adapter and some soldering skills, though.&lt;br /&gt;
&lt;br /&gt;
= Writing your first Miosix program =&lt;br /&gt;
&lt;br /&gt;
== Hello world ==&lt;br /&gt;
&lt;br /&gt;
With Notepad++ open the &#039;&#039;main.cpp&#039;&#039; file with your [[IDEs | IDE]] or text editor of choice, and replace its content with the following program:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;CPP&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;cstdio&amp;gt;&lt;br /&gt;
#include &amp;lt;thread&amp;gt;&lt;br /&gt;
#include &amp;lt;miosix.h&amp;gt;&lt;br /&gt;
#include &amp;lt;interfaces/bsp.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
using namespace std;&lt;br /&gt;
using namespace miosix;&lt;br /&gt;
&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
    for(;;)&lt;br /&gt;
    {&lt;br /&gt;
        iprintf(&amp;quot;Hello world\n&amp;quot;);&lt;br /&gt;
        ledOn();&lt;br /&gt;
        this_thread::sleep_for(500ms);&lt;br /&gt;
        ledOff();&lt;br /&gt;
        this_thread::sleep_for(500ms);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
At this point, it&#039;s good to have a quick walkthrough of this hello world program. Miosix is based on a [[Fluid kernel]] architecture: in a nutshell it&#039;s a kernel that supports writing applications both inside the kernel, and inside userspace programs. In this tutorial, we&#039;re using it as a unikernel. This means when power is applied to the board, the kernel will boot, and then start running the &#039;&#039;main()&#039;&#039; function you just wrote &#039;&#039;in kernelspace&#039;&#039;. This means you have both support for C/C++ standard libraries and unrestricted hardware access.&lt;br /&gt;
&lt;br /&gt;
This main() function will print &amp;quot;Hello world&amp;quot; and blink an LED approximately every second.&lt;br /&gt;
The printing is done with the &#039;&#039;iprintf()&#039;&#039; function. If you expected just &#039;&#039;printf()&#039;&#039; without the &#039;&#039;i&#039;&#039;, the reason is that Miosix uses the [https://sourceware.org/newlib/ Newlib] C standard library that provides both &#039;&#039;printf()&#039;&#039; and &#039;&#039;iprintf()&#039;&#039;, an optimized version that is smaller in code size but incapable of printing floating point numbers. So you can also use &#039;&#039;printf()&#039;&#039; if you wish, but this optimization is worth knowing from the start.&lt;br /&gt;
&lt;br /&gt;
Sleeping to blink the LED is done with the [https://en.cppreference.com/cpp/thread/sleep_for sleep_for()] function from the C++ standard library. Miosix supports other sleeping APIs, such as [https://pubs.opengroup.org/onlinepubs/9699919799/functions/nanosleep.html nanosleep()] from POSIX, or &#039;&#039;Thread::sleep()&#039;&#039;, a native Miosix function. All these functions do the same thing: they tell the scheduler to stop the currently running thread, run some other thread, and resume execution after a given time interval. Miosix is a preemptive multithreading operating system, so you should get comfortable with the fact that the code you&#039;re writing lives in a thread and shares the CPU with other threads.&lt;br /&gt;
&lt;br /&gt;
Many (but not all!) board support packages define the &#039;&#039;ledOn()&#039;&#039; and &#039;&#039;ledOff()&#039;&#039; functions to control one of the LED on the board. This should be true for all the boards that have at least one software-accessible LED. This is true for the &#039;&#039;stm32f746zg_nucleo&#039;&#039; board we selected, but if you selected a different board with no LEDs, then compiling will fail with an error related to &#039;&#039;ledOn()&#039;&#039; and &#039;&#039;ledOff()&#039;&#039;. You can comment out those two lines in this case, your hello world will only print to the serial port.&lt;br /&gt;
&lt;br /&gt;
== Compiling ==&lt;br /&gt;
&lt;br /&gt;
In the same terminal you used to run Perl, type &#039;&#039;make&#039;&#039; to build the kernel. If all goes well, the result should look like this.&lt;br /&gt;
&lt;br /&gt;
[[File:Make-output-windows.png]]&lt;br /&gt;
&lt;br /&gt;
Otherwise, compiler errors will appear in the shell. The number that appears under &#039;&#039;text&#039;&#039; in the make output is the size in bytes of your application plus the kernel. Don&#039;t worry about the 42KBytes code size, you&#039;re compiling with the default Miosix options, if you want you can play around with the options later to  [[Miosix code size optimization|reduce the code size]].&lt;br /&gt;
&lt;br /&gt;
== Flashing ==&lt;br /&gt;
&lt;br /&gt;
The procedure to flash the microcontroller board on Windows depends on the vendor-provided flashing tool. They usually provide a GUI where you can load the &#039;&#039;.bin&#039;&#039; file and then connect to the board and flash it. For Miosix the file is named main.bin if you&#039;re not using processes, or image.bin if you are using processes. For this tutorial, look for &#039;&#039;main.bin&#039;&#039; in the &#039;&#039;&#039;hello&#039;&#039;&#039; directory.&lt;br /&gt;
&lt;br /&gt;
If you correctly flashed the board, the LED will start blinking.&lt;br /&gt;
&lt;br /&gt;
== Accessing the serial port ==&lt;br /&gt;
&lt;br /&gt;
The USB to serial port adapter will appear on Windows as a randomly numbered COM port. To figure out the right number, you&#039;ll have to open &#039;&#039;Devices&#039;&#039; from the control panel:&lt;br /&gt;
&lt;br /&gt;
[[File:Windows-list-devices.png]]&lt;br /&gt;
&lt;br /&gt;
Today, on my computer, Windows decided to assign the STM32 board to COM3.&lt;br /&gt;
&lt;br /&gt;
Next up, open PuTTY and configure it to open the right COM port. Starting from Miosix v3.00, all boards use by default a baud rate of 115200bit/s, so input 115200 in the &#039;&#039;Speed&#039;&#039; field:&lt;br /&gt;
&lt;br /&gt;
[[File:Windows-putty-configuration.png]]&lt;br /&gt;
&lt;br /&gt;
Finally, click &#039;&#039;Open&#039;&#039; and you should see the serial port messages from the microcontroller. Since the board will be already running when you connect, you can press the RESET button on the board to reboot it and see the boot logs:&lt;br /&gt;
&lt;br /&gt;
[[File:Windows-putty-serial.png]]&lt;br /&gt;
&lt;br /&gt;
= A note on uninstalling software =&lt;br /&gt;
&lt;br /&gt;
To uninstall the Miosix Toolchain, you can find the uninstaller in the start menu under &#039;&#039;Miosix Toolchain&#039;&#039;. Note that the other tools such as Git, Perl and the STLink  utility have their own uninstallers.&lt;br /&gt;
&lt;br /&gt;
[[Category:Installation and Configuration]]&lt;/div&gt;</summary>
		<author><name>Fede.tft</name></author>
	</entry>
	<entry>
		<id>https://miosix.org/wiki/index.php?title=Linux_Quick_Start&amp;diff=453</id>
		<title>Linux Quick Start</title>
		<link rel="alternate" type="text/html" href="https://miosix.org/wiki/index.php?title=Linux_Quick_Start&amp;diff=453"/>
		<updated>2026-05-10T20:59:00Z</updated>

		<summary type="html">&lt;p&gt;Fede.tft: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
= Installing the required software =&lt;br /&gt;
&lt;br /&gt;
== Install the Miosix Toolchain ==&lt;br /&gt;
&lt;br /&gt;
To be able to compile the Miosix kernel and your application, you need a patched version of the GCC compiler called [[Miosix Toolchain]]. This page explains how to install the precompiled Miosix Toolchain. If you prefer compiling GCC from sources, see [[Building GCC from sources]]. The commands to run are as follows, where you&#039;ll need to replace &amp;lt;version&amp;gt; with the (usually latest) version found in the [[Miosix Toolchain]] page.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
wget https://miosix.org/toolchain/MiosixToolchainInstaller&amp;lt;version&amp;gt;.run&lt;br /&gt;
sh MiosixToolchainInstaller&amp;lt;version&amp;gt;.run&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The installer will ask for your root password to copy the compiler to the &#039;&#039;/opt&#039;&#039; directory, and put symlinks to &#039;&#039;/usr/bin&#039;&#039;. If you later want to uninstall the compiler, as part of the installation process an &#039;&#039;uninstall.sh&#039;&#039; script is placed together with the compiler in &#039;&#039;/opt/arm-miosix-eabi&#039;&#039;. Uninstalling the previous compiler is done automatically when upgrading to a newer version.&lt;br /&gt;
&lt;br /&gt;
If you do not trust the installer and want to verify its content, or you want to install it locally (in your home folder instead of system-wide), it is possible to extract the content of the installer with the following command. This operation also extracts, without running it, the &#039;&#039;installer.sh&#039;&#039; installation script.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sh MiosixToolchainInstaller&amp;lt;version&amp;gt;.run --noexec --keep&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For a local install you will need to set the &#039;&#039;PATH&#039;&#039; environment variable to include the extracted &#039;&#039;arm-miosix-eabi/bin&#039;&#039; directory.&lt;br /&gt;
&lt;br /&gt;
== Install a flashing tool ==&lt;br /&gt;
&lt;br /&gt;
With the installed Miosix toolchain you&#039;ll be able to compile the kernel, but you&#039;ll also need a way to transfer it to your microcontroller. This operation is usually called &#039;flashing&#039; the microcontroller. Miosix can work with any flashing utility that accepts as input raw binary files, so pick whatever your GNU/Linux distro of choice provides. Here is a list of suggestions for the most common microcontrollers used with Miosix: [[Linux flashing tools]].&lt;br /&gt;
&lt;br /&gt;
== Serial port setup ==&lt;br /&gt;
&lt;br /&gt;
Miosix redirects &#039;&#039;stdin&#039;&#039;/&#039;&#039;stdout&#039;&#039; to a serial port by default on most boards, so to see the boot log and the output of &#039;&#039;printf()&#039;&#039; in your application you need a program to interact with the serial port. A common one is &#039;&#039;GNU screen&#039;&#039;, but there are alternatives such as &#039;&#039;minicom&#039;&#039; or &#039;&#039;tio&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo apt install screen # For Ubuntu/Debian&lt;br /&gt;
sudo pacman -S screen   # For Arch Linux&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
On most GNU/Linux distros serial ports and USB to serial adapters like &#039;&#039;/dev/ttyUSB0&#039;&#039; and &#039;&#039;/dev/ttyACM0&#039;&#039; are owned by the &#039;&#039;dialout&#039;&#039; group, so to avoid the need to use &#039;&#039;sudo&#039;&#039; every time you run &#039;&#039;screen&#039;&#039; you need to add your user to that group before you can access them.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo usermod -a -G dialout `id -un` # Add yourself to the dialout group&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that you may need to reboot your computer before the change takes effect.&lt;br /&gt;
&lt;br /&gt;
= Downloading and configuring the Miosix kernel =&lt;br /&gt;
&lt;br /&gt;
To download the Miosix kernel you need [https://en.wikipedia.org/wiki/Git_%28software%29 git]. If you do not already have it installed you can install it now&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo apt install git # For Ubuntu/Debian&lt;br /&gt;
sudo pacman -S git   # For Arch Linux&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This section is a stripped down guide with the bare minimum to get you started, we also have a full guide about [[Miosix and git workflow]]. Following the tutorial in this page, your project directory will &#039;&#039;&#039;not&#039;&#039;&#039; be under version control (git). The [[Miosix and git workflow]] page shows how to create a git repository for your project and add the Miosix kernel as a git submodule.&lt;br /&gt;
&lt;br /&gt;
Before downloading the kernel, however, you first have to create &#039;&#039;&#039;a directory for your project&#039;&#039;&#039; (in this case, the hello world), and then clone the kernel &#039;&#039;&#039;as a subdirectory&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mkdir hello&lt;br /&gt;
cd hello&lt;br /&gt;
git clone https://github.com/fedetft/miosix-kernel.git&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Initializing a Miosix project ==&lt;br /&gt;
&lt;br /&gt;
For reasons explained in depth in the [[Miosix and git workflow]] page, you&#039;ll need to copy the Miosix configuration directory from the kernel sources to your project directory, as well as create a template project where you can start writing code.&lt;br /&gt;
This can be automated with a [https://en.wikipedia.org/wiki/Perl Perl] script called &#039;&#039;init_project_out_of_git_tree.pl&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
perl miosix-kernel/tools/init_project_out_of_git_tree.pl&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You should run the script from the directory where you want to initialize your empty project, such as the &#039;&#039;&#039;hello&#039;&#039;&#039; directory in this tutorial. A successful run of the script produces the following output:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Successfully created Miosix project&lt;br /&gt;
Target directory: hello&lt;br /&gt;
Kernel directory: hello/miosix-kernel/miosix&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Although Perl is pre-installed in almost all GNU/Linux distros, this script depends on the &#039;&#039;File::Copy::Recursive&#039;&#039; Perl module which often is not. If you get errors running the script, install the missing module as follows and try again:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo apt install libfile-copy-recursive-perl # For Ubuntu/Debian&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Your project directory should now look like the following picture, with the &#039;&#039;miosix-kernel&#039;&#039; directory containing the kernel sources, the &#039;&#039;config&#039;&#039; directory with the kernel configuration, the empty &#039;&#039;main.cpp&#039;&#039; and the build files for the two alternative build systems supported by Miosix: Makefile and CMake:&lt;br /&gt;
&lt;br /&gt;
[[File:Initialized-miosix-project-linux.png]]&lt;br /&gt;
&lt;br /&gt;
For this tutorial, we&#039;ll use the Makefile build system, have a look at the [[CMake]] page to learn how to use CMake instead.&lt;br /&gt;
&lt;br /&gt;
== Configuring the kernel ==&lt;br /&gt;
&lt;br /&gt;
The minimum configuration required to compile the kernel is to &#039;&#039;&#039;select a board&#039;&#039;&#039;, as the kernel needs to build the appropriate board support package for it.&lt;br /&gt;
&lt;br /&gt;
The Miosix kernel has several other build-time configuration options, to enable optional components (filesystem, userspace processes), select algorithms such as the scheduler and trade feature support for code size, but these won&#039;t be covered here.&lt;br /&gt;
The kernel is configured by editing files in the config directory, the two most important ones are [https://github.com/fedetft/miosix-kernel/blob/master/miosix/config/Makefile.inc Makefile.inc] and [https://github.com/fedetft/miosix-kernel/blob/master/miosix/config/miosix_settings.h miosix_settings.h].&lt;br /&gt;
&lt;br /&gt;
To select a board, open the first one, &#039;&#039;config/Makefile.inc&#039;&#039;. Look for the &#039;&#039;OPT_BOARD&#039;&#039; section of the file, which contains the list of boards officially supported by the kernel. In this section, all boards appear commented out (the &#039;&#039;#&#039;&#039; sign is a comment in Makefile syntax), so you need to uncomment the line corrsponding to your board. [[Porting]] the kernel to a new board is an advanced topic not covered here, so we&#039;ll assume you&#039;ll want to use an officially supported board. As an example, in this tutorial we&#039;ll use the stm32f746zg_nucleo board:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
#OPT_BOARD := stm32f469ni_stm32f469i-disco&lt;br /&gt;
OPT_BOARD := stm32f746zg_nucleo&lt;br /&gt;
#OPT_BOARD := stm32f765ii_marco_ram_board&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you do not yet have a board, you can follow along and get to the compiled firmware anyway. If you&#039;re looking for suggestions on which board to get, consider that most boards currently supported by Miosix are for STM32 microcontrollers. Here&#039;s a basic guide:&lt;br /&gt;
* &#039;&#039;&#039;Nucleo&#039;&#039;&#039; STM32 boards produced by ST are good for beginners, as they allow to power the board, flash it, debug it and access the serial port all through a single USB connection with your computer. The stm32f401re_nucleo and stm32f411re_nucleo are realtively low cost.&lt;br /&gt;
* &#039;&#039;&#039;Discovery&#039;&#039;&#039; STM32 boards are also good, but they don&#039;t include an USB to serial adapter so you&#039;ll have to buy it separately and you&#039;ll end up having to connect two USB cables, one for power/programming/debugging and one for the serial port.&lt;br /&gt;
* &#039;&#039;&#039;Third party&#039;&#039;&#039; STM32 boards such as the stm32f411ce_blackpill are cheaper and great to embed in your hardware project, but you&#039;ll have to [https://en.wikipedia.org/wiki/Soldering solder] the pin header yourself, and you&#039;ll need to attach a separate USB to serial adapter, and if you want in-circuit debugging you&#039;ll need an STLink adapter, so you&#039;ll end up having to run up to three separate USB cables from your computer to the board for power/programming, serial port and debugging.&lt;br /&gt;
* Venturing outside of STM32, the &#039;&#039;&#039;RP2040&#039;&#039;&#039; is a good choice. Also in this case, you&#039;ll need a separate USB to serial adapter and some soldering skills, though.&lt;br /&gt;
&lt;br /&gt;
= Writing your first Miosix program =&lt;br /&gt;
&lt;br /&gt;
== Hello world ==&lt;br /&gt;
&lt;br /&gt;
Open the &#039;&#039;main.cpp&#039;&#039; file with your [[IDEs | IDE]] or text editor of choice, and replace its content with the following program:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;CPP&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;cstdio&amp;gt;&lt;br /&gt;
#include &amp;lt;thread&amp;gt;&lt;br /&gt;
#include &amp;lt;miosix.h&amp;gt;&lt;br /&gt;
#include &amp;lt;interfaces/bsp.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
using namespace std;&lt;br /&gt;
using namespace miosix;&lt;br /&gt;
&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
    for(;;)&lt;br /&gt;
    {&lt;br /&gt;
        iprintf(&amp;quot;Hello world\n&amp;quot;);&lt;br /&gt;
        ledOn();&lt;br /&gt;
        this_thread::sleep_for(500ms);&lt;br /&gt;
        ledOff();&lt;br /&gt;
        this_thread::sleep_for(500ms);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
At this point, it&#039;s good to have a quick walkthrough of this hello world program. Miosix is based on a [[Fluid kernel]] architecture: in a nutshell it&#039;s a kernel that supports writing applications both inside the kernel, and inside userspace programs. In this tutorial, we&#039;re using it as a unikernel. This means when power is applied to the board, the kernel will boot, and then start running the &#039;&#039;main()&#039;&#039; function you just wrote &#039;&#039;in kernelspace&#039;&#039;. This means you have both support for C/C++ standard libraries and unrestricted hardware access.&lt;br /&gt;
&lt;br /&gt;
This main() function will print &amp;quot;Hello world&amp;quot; and blink an LED approximately every second.&lt;br /&gt;
The printing is done with the &#039;&#039;iprintf()&#039;&#039; function. If you expected just &#039;&#039;printf()&#039;&#039; without the &#039;&#039;i&#039;&#039;, the reason is that Miosix uses the [https://sourceware.org/newlib/ Newlib] C standard library that provides both &#039;&#039;printf()&#039;&#039; and &#039;&#039;iprintf()&#039;&#039;, an optimized version that is smaller in code size but incapable of printing floating point numbers. So you can also use &#039;&#039;printf()&#039;&#039; if you wish, but this optimization is worth knowing from the start.&lt;br /&gt;
&lt;br /&gt;
Sleeping to blink the LED is done with the [https://en.cppreference.com/cpp/thread/sleep_for sleep_for()] function from the C++ standard library. Miosix supports other sleeping APIs, such as [https://pubs.opengroup.org/onlinepubs/9699919799/functions/nanosleep.html nanosleep()] from POSIX, or &#039;&#039;Thread::sleep()&#039;&#039;, a native Miosix function. All these functions do the same thing: they tell the scheduler to stop the currently running thread, run some other thread, and resume execution after a given time interval. Miosix is a preemptive multithreading operating system, so you should get comfortable with the fact that the code you&#039;re writing lives in a thread and shares the CPU with other threads.&lt;br /&gt;
&lt;br /&gt;
Many (but not all!) board support packages define the &#039;&#039;ledOn()&#039;&#039; and &#039;&#039;ledOff()&#039;&#039; functions to control one of the LED on the board. This should be true for all the boards that have at least one software-accessible LED. This is true for the &#039;&#039;stm32f746zg_nucleo&#039;&#039; board we selected, but if you selected a different board with no LEDs, then compiling will fail with an error related to &#039;&#039;ledOn()&#039;&#039; and &#039;&#039;ledOff()&#039;&#039;. You can comment out those two lines in this case, your hello world will only print to the serial port.&lt;br /&gt;
&lt;br /&gt;
== Compiling ==&lt;br /&gt;
&lt;br /&gt;
To compile the kernel, open a terminal in the &#039;&#039;&#039;hello&#039;&#039;&#039; project directory and type:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
make -j`nproc`&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;-j`nproc`&#039;&#039; is optional, it will compile faster by using the multicore CPU in your computer. If you know how many cores you have, you can also specify the number explicitly, such as &#039;&#039;make -j8&#039;&#039;. If all goes well, the result should look like this:&lt;br /&gt;
&lt;br /&gt;
[[File:Make-output-linux.png]]&lt;br /&gt;
&lt;br /&gt;
Otherwise, compiler errors will appear in the shell. The number that appears under &#039;&#039;text&#039;&#039; in the make output is the size in bytes of your application plus the kernel. Don&#039;t worry about the 42KBytes code size, you&#039;re compiling with the default Miosix options, if you want you can play around with the options later to  [[Miosix code size optimization|reduce the code size]].&lt;br /&gt;
&lt;br /&gt;
== Flashing ==&lt;br /&gt;
&lt;br /&gt;
To flash the board, you can use the &#039;&#039;make program&#039;&#039; Makefile rule to automatically download the kernel to the board. Connect the USB cable first, and then run:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
make program&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If the operation completed successfully, then the output should be similar to this one, and the LED should blink on the board:&lt;br /&gt;
&lt;br /&gt;
[[File:Make program linux.png]]&lt;br /&gt;
&lt;br /&gt;
If the operation did not succeed, here are some common problems:&lt;br /&gt;
* You get a &#039;&#039;command not found&#039;&#039; error. You probably did not install the right flashing tool on your computer, read here [[Linux flashing tools]].&lt;br /&gt;
* The flashing tool starts, but throws an error such as &#039;&#039;Couldn&#039;t find any ST-Link devices&#039;&#039;. You probably do not have the right permissions to access the board. Try &#039;&#039;sudo make program&#039;&#039;. If that one works, you&#039;ll have to install &#039;&#039;udev rules&#039;&#039; to make the USB device of your board&#039;s programming interface accessible from your user. Unfortunately the details to installing (or writing from scratch) the correct udev rules file depend on the combination of the flashing tool and board. None of these are specific to Miosix, so look online in the documentation of your flashing tool.&lt;br /&gt;
&lt;br /&gt;
Another issue in some STM32 boards is that the flashing tool leaves the board in a state where the mcirocontroller blocks either after flashing or if you press the reset button on the board. This issue is again specific to the board and flashing tool and unrelated to Miosix. If you encounter this problem after having programmed the microcontroller, it is recommended to unplug and reconnect the USB cable to powercycle the board. At that point, you should see the LED blinking.&lt;br /&gt;
&lt;br /&gt;
== Accessing the serial port ==&lt;br /&gt;
&lt;br /&gt;
Starting from Miosix v3.00, all boards use by default a baud rate of 115200bit/s.&lt;br /&gt;
If you&#039;re using a &#039;&#039;&#039;Nucleo&#039;&#039;&#039; board from ST, the USB to serial port adapter will appear on your computer as &#039;&#039;/dev/ttyACM0&#039;&#039;, so use the &#039;&#039;screen&#039;&#039; program with the following parameters:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
screen /dev/ttyACM0 115200&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Since the board will be already running when you connect, you can press the RESET button on the board to reboot it and see the boot logs:&lt;br /&gt;
&lt;br /&gt;
[[File:Serial-view-linux.png]]&lt;br /&gt;
&lt;br /&gt;
Exiting the screen program is cumbersome at first, but you&#039;ll get used to it quickly. You have to type &#039;&#039;Ctrl-A&#039;&#039;, then &#039;&#039;k&#039;&#039; and &#039;&#039;y&#039;&#039;. Typing &#039;&#039;Ctrl-C&#039;&#039; won&#039;t stop the program, it will just send a &#039;&#039;Ctrl-C&#039;&#039; to the microcontroller.&lt;br /&gt;
&lt;br /&gt;
If you are using a board that does not have an integrated USB to serial adapter, you&#039;ll need to figure out to which pins is the default serial connected. To do so, you&#039;ll have to look for the kernel configuration file for your board. For example, for the &#039;&#039;stm32f411ce_blackpill&#039;&#039; the file is: [https://github.com/fedetft/miosix-kernel/blob/master/miosix/config/board/stm32f411ce_blackpill/board_settings.h config/board/stm32f411ce_blackpill/board_settings.h], where you&#039;ll find that the serial port TX pin is PA9, and the RX pin is PA10. Remember to cross the TX and RX pin, the TX pin of the microcontroller goes to the RX pin of the serial adapter! For reliable communication you&#039;ll also have to connect a wire between the board GND and the serial adapter GND.&lt;br /&gt;
&lt;br /&gt;
Another example would be for the RP2040. In this case the configuration file is [https://github.com/fedetft/miosix-kernel/blob/master/miosix/config/board/rp2040_raspberry_pi_pico/board_settings.h config/board/rp2040_raspberry_pi_pico/board_settings.h] and the serial TX pin is P0.0, while RX is P0.1.&lt;br /&gt;
&lt;br /&gt;
The most common standalone USB to serial adapters are based on the FTDI&#039;s FT232 chip, which appears on GNU/Linux as &#039;&#039;/dev/ttyUSB0&#039;&#039;, so the command to access the serial port would be:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
screen /dev/ttyUSB0 115200&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:Installation and Configuration]]&lt;/div&gt;</summary>
		<author><name>Fede.tft</name></author>
	</entry>
	<entry>
		<id>https://miosix.org/wiki/index.php?title=Linux_Quick_Start&amp;diff=452</id>
		<title>Linux Quick Start</title>
		<link rel="alternate" type="text/html" href="https://miosix.org/wiki/index.php?title=Linux_Quick_Start&amp;diff=452"/>
		<updated>2026-05-10T20:45:58Z</updated>

		<summary type="html">&lt;p&gt;Fede.tft: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
= Installing the required software =&lt;br /&gt;
&lt;br /&gt;
== Install the Miosix Toolchain ==&lt;br /&gt;
&lt;br /&gt;
To be able to compile the Miosix kernel and your application, you need a patched version of the GCC compiler called [[Miosix Toolchain]]. This page explains how to install the precompiled Miosix Toolchain. If you prefer compiling GCC from sources, see [[Building GCC from sources]]. The commands to run are as follows, where you&#039;ll need to replace &amp;lt;version&amp;gt; with the (usually latest) version found in the [[Miosix Toolchain]] page.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
wget https://miosix.org/toolchain/MiosixToolchainInstaller&amp;lt;version&amp;gt;.run&lt;br /&gt;
sh MiosixToolchainInstaller&amp;lt;version&amp;gt;.run&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The installer will ask for your root password to copy the compiler to the &#039;&#039;/opt&#039;&#039; directory, and put symlinks to &#039;&#039;/usr/bin&#039;&#039;. If you later want to uninstall the compiler, as part of the installation process an &#039;&#039;uninstall.sh&#039;&#039; script is placed together with the compiler in &#039;&#039;/opt/arm-miosix-eabi&#039;&#039;. Uninstalling the previous compiler is done automatically when upgrading to a newer version.&lt;br /&gt;
&lt;br /&gt;
If you do not trust the installer and want to verify its content, or you want to install it locally (in your home folder instead of system-wide), it is possible to extract the content of the installer with the following command. This operation also extracts, without running it, the &#039;&#039;installer.sh&#039;&#039; installation script.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sh MiosixToolchainInstaller&amp;lt;version&amp;gt;.run --noexec --keep&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For a local install you will need to set the &#039;&#039;PATH&#039;&#039; environment variable to include the extracted &#039;&#039;arm-miosix-eabi/bin&#039;&#039; directory.&lt;br /&gt;
&lt;br /&gt;
== Install a flashing tool ==&lt;br /&gt;
&lt;br /&gt;
With the installed Miosix toolchain you&#039;ll be able to compile the kernel, but you&#039;ll also need a way to transfer it to your microcontroller. This operation is usually called &#039;flashing&#039; the microcontroller. Miosix can work with any flashing utility that accepts as input raw binary files, so pick whatever your GNU/Linux distro of choice provides. Here is a list of suggestions for the most common microcontrollers used with Miosix: [[Linux flashing tools]].&lt;br /&gt;
&lt;br /&gt;
== Serial port setup ==&lt;br /&gt;
&lt;br /&gt;
Miosix redirects &#039;&#039;stdin&#039;&#039;/&#039;&#039;stdout&#039;&#039; to a serial port by default on most boards, so to see the boot log and the output of &#039;&#039;printf()&#039;&#039; in your application you need a program to interact with the serial port. A common one is &#039;&#039;GNU screen&#039;&#039;, but there are alternatives such as &#039;&#039;minicom&#039;&#039; or &#039;&#039;tio&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo apt install screen # For Ubuntu/Debian&lt;br /&gt;
sudo pacman -S screen   # For Arch Linux&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
On most GNU/Linux distros serial ports and USB to serial adapters like &#039;&#039;/dev/ttyUSB0&#039;&#039; and &#039;&#039;/dev/ttyACM0&#039;&#039; are owned by the &#039;&#039;dialout&#039;&#039; group, so to avoid the need to use &#039;&#039;sudo&#039;&#039; every time you run &#039;&#039;screen&#039;&#039; you need to add your user to that group before you can access them.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo usermod -a -G dialout `id -un` # Add yourself to the dialout group&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that you may need to reboot your computer before the change takes effect.&lt;br /&gt;
&lt;br /&gt;
= Downloading and configuring the Miosix kernel =&lt;br /&gt;
&lt;br /&gt;
To download the Miosix kernel you need [https://en.wikipedia.org/wiki/Git_%28software%29 git]. If you do not already have it installed you can install it now&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo apt install git # For Ubuntu/Debian&lt;br /&gt;
sudo pacman -S git   # For Arch Linux&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This section is a stripped down guide with the bare minimum to get you started, we also have a full guide about [[Miosix and git workflow]]. Following the tutorial in this page, your project directory will &#039;&#039;&#039;not&#039;&#039;&#039; be under version control (git). The [[Miosix and git workflow]] page shows how to create a git repository for your project and add the Miosix kernel as a git submodule.&lt;br /&gt;
&lt;br /&gt;
Before downloading the kernel, however, you first have to create &#039;&#039;&#039;a directory for your project&#039;&#039;&#039; (in this case, the hello world), and then clone the kernel &#039;&#039;&#039;as a subdirectory&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mkdir hello&lt;br /&gt;
cd hello&lt;br /&gt;
git clone https://github.com/fedetft/miosix-kernel.git&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Initializing a Miosix project ==&lt;br /&gt;
&lt;br /&gt;
For reasons explained in depth in the [[Miosix and git workflow]] page, you&#039;ll need to copy the Miosix configuration directory from the kernel sources to your project directory, as well as create a template project where you can start writing code.&lt;br /&gt;
This can be automated with a [https://en.wikipedia.org/wiki/Perl Perl] script called &#039;&#039;init_project_out_of_git_tree.pl&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
perl miosix-kernel/tools/init_project_out_of_git_tree.pl&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You should run the script from the directory where you want to initialize your empty project, such as the &#039;&#039;&#039;hello&#039;&#039;&#039; directory in this tutorial. A successful run of the script produces the following output:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Successfully created Miosix project&lt;br /&gt;
Target directory: hello&lt;br /&gt;
Kernel directory: hello/miosix-kernel/miosix&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Although Perl is pre-installed in almost all GNU/Linux distros, this script depends on the &#039;&#039;File::Copy::Recursive&#039;&#039; Perl module which often is not. If you get errors running the script, install the missing module as follows and try again:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo apt install libfile-copy-recursive-perl # For Ubuntu/Debian&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Your project directory should now look like the following picture, with the &#039;&#039;miosix-kernel&#039;&#039; directory containing the kernel sources, the &#039;&#039;config&#039;&#039; directory with the kernel configuration, the empty &#039;&#039;main.cpp&#039;&#039; and the build files for the two alternative build systems supported by Miosix: Makefile and CMake:&lt;br /&gt;
&lt;br /&gt;
[[File:Initialized-miosix-project-linux.png]]&lt;br /&gt;
&lt;br /&gt;
For this tutorial, we&#039;ll use the Makefile build system, have a look at the [[CMake]] page to learn how to use CMake instead.&lt;br /&gt;
&lt;br /&gt;
== Configuring the kernel ==&lt;br /&gt;
&lt;br /&gt;
The minimum configuration required to compile the kernel is to &#039;&#039;&#039;select a board&#039;&#039;&#039;, as the kernel needs to build the appropriate board support package for it.&lt;br /&gt;
&lt;br /&gt;
The Miosix kernel has several other build-time configuration options, to enable optional components (filesystem, userspace processes), select algorithms such as the scheduler and trade feature support for code size, but these won&#039;t be covered here.&lt;br /&gt;
The kernel is configured by editing files in the config directory, the two most important ones are [https://github.com/fedetft/miosix-kernel/blob/master/miosix/config/Makefile.inc Makefile.inc] and [https://github.com/fedetft/miosix-kernel/blob/master/miosix/config/miosix_settings.h miosix_settings.h].&lt;br /&gt;
&lt;br /&gt;
To select a board, open the first one, &#039;&#039;config/Makefile.inc&#039;&#039;. Look for the &#039;&#039;OPT_BOARD&#039;&#039; section of the file, which contains the list of boards officially supported by the kernel. In this section, all boards appear commented out (the &#039;&#039;#&#039;&#039; sign is a comment in Makefile syntax), so you need to uncomment the line corrsponding to your board. [[Porting]] the kernel to a new board is an advanced topic not covered here, so we&#039;ll assume you&#039;ll want to use an officially supported board. As an example, in this tutorial we&#039;ll use the stm32f746zg_nucleo board:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
#OPT_BOARD := stm32f469ni_stm32f469i-disco&lt;br /&gt;
OPT_BOARD := stm32f746zg_nucleo&lt;br /&gt;
#OPT_BOARD := stm32f765ii_marco_ram_board&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you do not yet have a board, you can follow along and get to the compiled firmware anyway. If you&#039;re looking for suggestions on which board to get, consider that most boards currently supported by Miosix are for STM32 microcontrollers. Here&#039;s a basic guide:&lt;br /&gt;
* &#039;&#039;&#039;Nucleo&#039;&#039;&#039; STM32 boards produced by ST are good for beginners, as they allow to power the board, flash it, debug it and access the serial port all through a single USB connection with your computer. The stm32f401re_nucleo and stm32f411re_nucleo are realtively low cost.&lt;br /&gt;
* &#039;&#039;&#039;Discovery&#039;&#039;&#039; STM32 boards are also good, but they don&#039;t include an USB to serial adapter so you&#039;ll have to buy it separately and you&#039;ll end up having to connect two USB cables, one for power/programming/debugging and one for the serial port.&lt;br /&gt;
* &#039;&#039;&#039;Third party&#039;&#039;&#039; STM32 boards such as the stm32f411ce_blackpill are cheaper and great to embed in your hardware project, but you&#039;ll have to [https://en.wikipedia.org/wiki/Soldering solder] the pin header yourself, and you&#039;ll need to attach a separate USB to serial adapter, and if you want in-circuit debugging you&#039;ll need an STLink adapter, so you&#039;ll end up having to run up to three separate USB cables from your computer to the board for power/programming, serial port and debugging.&lt;br /&gt;
* Venturing outside of STM32, the &#039;&#039;&#039;RP2040&#039;&#039;&#039; is a good choice. Also in this case, you&#039;ll need a separate USB to serial adapter and some soldering skills, though.&lt;br /&gt;
&lt;br /&gt;
= Writing your first Miosix program =&lt;br /&gt;
&lt;br /&gt;
== Hello world ==&lt;br /&gt;
&lt;br /&gt;
Open the &#039;&#039;main.cpp&#039;&#039; file with your [[IDEs | IDE]] or text editor of choice, and replace its content with the following program:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;CPP&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;cstdio&amp;gt;&lt;br /&gt;
#include &amp;lt;thread&amp;gt;&lt;br /&gt;
#include &amp;lt;miosix.h&amp;gt;&lt;br /&gt;
#include &amp;lt;interfaces/bsp.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
using namespace std;&lt;br /&gt;
using namespace miosix;&lt;br /&gt;
&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
    for(;;)&lt;br /&gt;
    {&lt;br /&gt;
        iprintf(&amp;quot;Hello world\n&amp;quot;);&lt;br /&gt;
        ledOn();&lt;br /&gt;
        this_thread::sleep_for(500ms);&lt;br /&gt;
        ledOff();&lt;br /&gt;
        this_thread::sleep_for(500ms);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
At this point, it&#039;s good to have a quick walkthrough of this hello world program. Miosix is based on a [[Fluid kernel]] architecture: in a nutshell it&#039;s kernel that supports writing applications both inside the kernel, and inside userspace programs. In this tutorial, we&#039;re using it as a unikernel. This means when power is applied to the board, the kernel will boot, and then start running the &#039;&#039;main()&#039;&#039; function you just wrote &#039;&#039;in kernelspace&#039;&#039;. This means you have both support for C/C++ standard libraries and unrestricted hardware access.&lt;br /&gt;
&lt;br /&gt;
This main() function will print &amp;quot;Hello world&amp;quot; and blink an LED approximately every second.&lt;br /&gt;
The printing is done with the &#039;&#039;iprintf()&#039;&#039; function. If you expected just &#039;&#039;printf()&#039;&#039; without the &#039;&#039;i&#039;&#039;, the reason is that Miosix uses the [https://sourceware.org/newlib/ Newlib] C standard library that provides both &#039;&#039;printf()&#039;&#039; and &#039;&#039;iprintf()&#039;&#039;, an optimized version that is smaller in code size but incapable of printing floating point numbers. So you can also use &#039;&#039;printf()&#039;&#039; if you wish, but this optimization is worth knowing from the start.&lt;br /&gt;
&lt;br /&gt;
Sleeping to blink the LED is done with the [https://en.cppreference.com/cpp/thread/sleep_for sleep_for()] function from the C++ standard library. Miosix supports other sleeping APIs, such as [https://pubs.opengroup.org/onlinepubs/9699919799/functions/nanosleep.html nanosleep()] from POSIX, or &#039;&#039;Thread::sleep()&#039;&#039;, a native Miosix function. All these functions do the same thing: they tell the scheduler to stop the currently running thread, run some other thread, and resume execution after a given time interval. Miosix is a preemptive multithreading operating system, so you should get comfortable with the fact that the code you&#039;re writing lives in a thread and shares the CPU with other threads.&lt;br /&gt;
&lt;br /&gt;
Many (but not all!) board support packages define the &#039;&#039;ledOn()&#039;&#039; and &#039;&#039;ledOff()&#039;&#039; functions to control one of the LED on the board. This should be true for all the boards that have at least one software-accessible LED. This is true for the &#039;&#039;stm32f746zg_nucleo&#039;&#039; board we selected, but if you selected a different board with no LEDs, then compiling will fail with an error related to &#039;&#039;ledOn()&#039;&#039; and &#039;&#039;ledOff()&#039;&#039;. You can comment out those two lines in this case, your hello world will only print to the serial port.&lt;br /&gt;
&lt;br /&gt;
== Compiling ==&lt;br /&gt;
&lt;br /&gt;
To compile the kernel, open a terminal in the &#039;&#039;&#039;hello&#039;&#039;&#039; project directory and type:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
make -j`nproc`&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;-j`nproc`&#039;&#039; is optional, it will compile faster by using the multicore CPU in your computer. If you know how many cores you have, you can also specify the number explicitly, such as &#039;&#039;make -j8&#039;&#039;. If all goes well, the result should look like this:&lt;br /&gt;
&lt;br /&gt;
[[File:Make-output-linux.png]]&lt;br /&gt;
&lt;br /&gt;
Otherwise, compiler errors will appear in the shell. The number that appears under &#039;&#039;text&#039;&#039; in the make output is the size in bytes of your application plus the kernel. Don&#039;t worry about the 42KBytes code size, you&#039;re compiling with the default Miosix options, if you want you can play around with the options later to  [[Miosix code size optimization|reduce the code size]].&lt;br /&gt;
&lt;br /&gt;
== Flashing ==&lt;br /&gt;
&lt;br /&gt;
To flash the board, you can use the &#039;&#039;make program&#039;&#039; Makefile rule to automatically download the kernel to the board. Connect the USB cable first, and then run:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
make program&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If the operation completed successfully, then the output should be similar to this one, and the LED should blink on the board:&lt;br /&gt;
&lt;br /&gt;
[[File:Make program linux.png]]&lt;br /&gt;
&lt;br /&gt;
If the operation did not succeed, here are some common problems:&lt;br /&gt;
* You get a &#039;&#039;command not found&#039;&#039; error. You probably did not install the right flashing tool on your computer, read here [[Linux flashing tools]].&lt;br /&gt;
* The flashing tool starts, but throws an error such as &#039;&#039;Couldn&#039;t find any ST-Link devices&#039;&#039;. You probably do not have the right permissions to access the board. Try &#039;&#039;sudo make program&#039;&#039;. If that one works, you&#039;ll have to install &#039;&#039;udev rules&#039;&#039; to make the USB device of your board&#039;s programming interface accessible from your user. Unfortunately the details to installing (or writing from scratch) the correct udev rules file depend on the combination of the flashing tool and board. None of these are specific to Miosix, so look online in the documentation of your flashing tool.&lt;br /&gt;
&lt;br /&gt;
Another issue in some STM32 boards is that the flashing tool leaves the board in a state where the mcirocontroller blocks either after flashing or if you press the reset button on the board. This issue is again specific to the board and flashing tool and unrelated to Miosix. If you encounter this problem after having programmed the microcontroller, it is recommended to unplug and reconnect the USB cable to powercycle the board. At that point, you should see the LED blinking.&lt;br /&gt;
&lt;br /&gt;
== Accessing the serial port ==&lt;br /&gt;
&lt;br /&gt;
Starting from Miosix v3.00, all boards use by default a baud rate of 115200bit/s.&lt;br /&gt;
If you&#039;re using a &#039;&#039;&#039;Nucleo&#039;&#039;&#039; board from ST, the USB to serial port adapter will appear on your computer as &#039;&#039;/dev/ttyACM0&#039;&#039;, so use the &#039;&#039;screen&#039;&#039; program with the following parameters:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
screen /dev/ttyACM0 115200&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Since the board will be already running when you connect, you can press the RESET button on the board to reboot it and see the boot logs:&lt;br /&gt;
&lt;br /&gt;
[[File:Serial-view-linux.png]]&lt;br /&gt;
&lt;br /&gt;
Exiting the screen program is cumbersome at first, but you&#039;ll get used to it quickly. You have to type &#039;&#039;Ctrl-A&#039;&#039;, then &#039;&#039;k&#039;&#039; and &#039;&#039;y&#039;&#039;. Typing &#039;&#039;Ctrl-C&#039;&#039; won&#039;t stop the program, it will just send a &#039;&#039;Ctrl-C&#039;&#039; to the microcontroller.&lt;br /&gt;
&lt;br /&gt;
If you are using a board that does not have an integrated USB to serial adapter, you&#039;ll need to figure out to which pins is the default serial connected. To do so, you&#039;ll have to look for the kernel configuration file for your board. For example, for the &#039;&#039;stm32f411ce_blackpill&#039;&#039; the file is: [https://github.com/fedetft/miosix-kernel/blob/master/miosix/config/board/stm32f411ce_blackpill/board_settings.h config/board/stm32f411ce_blackpill/board_settings.h], where you&#039;ll find that the serial port TX pin is PA9, and the RX pin is PA10. Remember to cross the TX and RX pin, the TX pin of the microcontroller goes to the RX pin of the serial adapter! For reliable communication you&#039;ll also have to connect a wire between the board GND and the serial adapter GND.&lt;br /&gt;
&lt;br /&gt;
Another example would be for the RP2040. In this case the configuration file is [https://github.com/fedetft/miosix-kernel/blob/master/miosix/config/board/rp2040_raspberry_pi_pico/board_settings.h config/board/rp2040_raspberry_pi_pico/board_settings.h] and the serial TX pin is P0.0, while RX is P0.1.&lt;br /&gt;
&lt;br /&gt;
The most common standalone USB to serial adapters are based on the FTDI&#039;s FT232 chip, which appears on GNU/Linux as &#039;&#039;/dev/ttyUSB0&#039;&#039;, so the command to access the serial port would be:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
screen /dev/ttyUSB0 115200&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:Installation and Configuration]]&lt;/div&gt;</summary>
		<author><name>Fede.tft</name></author>
	</entry>
	<entry>
		<id>https://miosix.org/wiki/index.php?title=Linux_Quick_Start&amp;diff=451</id>
		<title>Linux Quick Start</title>
		<link rel="alternate" type="text/html" href="https://miosix.org/wiki/index.php?title=Linux_Quick_Start&amp;diff=451"/>
		<updated>2026-05-10T20:42:48Z</updated>

		<summary type="html">&lt;p&gt;Fede.tft: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
= Installing the required software =&lt;br /&gt;
&lt;br /&gt;
== Install the Miosix Toolchain ==&lt;br /&gt;
&lt;br /&gt;
To be able to compile the Miosix kernel and your application, you need a patched version of the GCC compiler called [[Miosix Toolchain]]. This page explains how to install the precompiled Miosix Toolchain. If you prefer compiling GCC from sources, see [[Building GCC from sources]]. The commands to run are as follows, where you&#039;ll need to replace &amp;lt;version&amp;gt; with the (usually latest) version found in the [[Miosix Toolchain]] page.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
wget https://miosix.org/toolchain/MiosixToolchainInstaller&amp;lt;version&amp;gt;.run&lt;br /&gt;
sh MiosixToolchainInstaller&amp;lt;version&amp;gt;.run&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The installer will ask for your root password to copy the compiler to the &#039;&#039;/opt&#039;&#039; directory, and put symlinks to &#039;&#039;/usr/bin&#039;&#039;. If you later want to uninstall the compiler, as part of the installation process an &#039;&#039;uninstall.sh&#039;&#039; script is placed together with the compiler in &#039;&#039;/opt/arm-miosix-eabi&#039;&#039;. Uninstalling the previous compiler is done automatically when upgrading to a newer version.&lt;br /&gt;
&lt;br /&gt;
If you do not trust the installer and want to verify its content, or you want to install it locally (in your home folder instead of system-wide), it is possible to extract the content of the installer with the following command. This operation also extracts, without running it, the &#039;&#039;installer.sh&#039;&#039; installation script.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sh MiosixToolchainInstaller&amp;lt;version&amp;gt;.run --noexec --keep&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For a local install you will need to set the &#039;&#039;PATH&#039;&#039; environment variable to include the extracted &#039;&#039;arm-miosix-eabi/bin&#039;&#039; directory.&lt;br /&gt;
&lt;br /&gt;
== Install a flashing tool ==&lt;br /&gt;
&lt;br /&gt;
With the installed Miosix toolchain you&#039;ll be able to compile the kernel, but you&#039;ll also need a way to transfer it to your microcontroller. This operation is usually called &#039;flashing&#039; the microcontroller. Miosix can work with any flashing utility that accepts as input raw binary files, so pick whatever your GNU/Linux distro of choice provides. Here is a list of suggestions for the most common microcontrollers used with Miosix: [[Linux flashing tools]].&lt;br /&gt;
&lt;br /&gt;
== Serial port setup ==&lt;br /&gt;
&lt;br /&gt;
Miosix redirects &#039;&#039;stdin&#039;&#039;/&#039;&#039;stdout&#039;&#039; to a serial port by default on most boards, so to see the boot log and the output of &#039;&#039;printf()&#039;&#039; in your application you need a program to interact with the serial port. A common one is &#039;&#039;GNU screen&#039;&#039;, but there are alternatives such as &#039;&#039;minicom&#039;&#039; or &#039;&#039;tio&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo apt install screen # For Ubuntu/Debian&lt;br /&gt;
sudo pacman -S screen   # For Arch Linux&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
On most GNU/Linux distros serial ports and USB to serial adapters like &#039;&#039;/dev/ttyUSB0&#039;&#039; and &#039;&#039;/dev/ttyACM0&#039;&#039; are owned by the &#039;&#039;dialout&#039;&#039; group, so to avoid the need to use &#039;&#039;sudo&#039;&#039; every time you run &#039;&#039;screen&#039;&#039; you need to add your user to that group before you can access them.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo usermod -a -G dialout `id -un` # Add yourself to the dialout group&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that you may need to reboot your computer before the change takes effect.&lt;br /&gt;
&lt;br /&gt;
= Downloading and configuring the Miosix kernel =&lt;br /&gt;
&lt;br /&gt;
To download the Miosix kernel you need [https://en.wikipedia.org/wiki/Git_%28software%29 git]. If you do not already have it installed you can install it now&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo apt install git # For Ubuntu/Debian&lt;br /&gt;
sudo pacman -S git   # For Arch Linux&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This section is a stripped down guide with the bare minimum to get you started, we also have a full guide about [[Miosix and git workflow]]. Following the tutorial in this page, your project directory will &#039;&#039;&#039;not&#039;&#039;&#039; be under version control (git). The [[Miosix and git workflow]] page shows how to create a git repository for your project and add the Miosix kernel as a git submodule.&lt;br /&gt;
&lt;br /&gt;
Before downloading the kernel, however, you first have to create &#039;&#039;&#039;a directory for your project&#039;&#039;&#039; (in this case, the hello world), and then clone the kernel &#039;&#039;&#039;as a subdirectory&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mkdir hello&lt;br /&gt;
cd hello&lt;br /&gt;
git clone https://github.com/fedetft/miosix-kernel.git&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Initializing a Miosix project ==&lt;br /&gt;
&lt;br /&gt;
For reasons explained in depth in the [[Miosix and git workflow]] page, you&#039;ll need to copy the Miosix configuration directory from the kernel sources to your project directory, as well as create a template project where you can start writing code.&lt;br /&gt;
This can be automated with a [https://en.wikipedia.org/wiki/Perl Perl] script called &#039;&#039;init_project_out_of_git_tree.pl&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
perl miosix-kernel/tools/init_project_out_of_git_tree.pl&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You should run the script from the directory where you want to initialize your empty project, such as the &#039;&#039;&#039;hello&#039;&#039;&#039; directory in this tutorial. A successful run of the script produces the following output:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Successfully created Miosix project&lt;br /&gt;
Target directory: hello&lt;br /&gt;
Kernel directory: hello/miosix-kernel/miosix&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Although Perl is pre-installed in almost all GNU/Linux distros, this script depends on the &#039;&#039;File::Copy::Recursive&#039;&#039; Perl module which often is not. If you get errors running the script, install the missing module as follows and try again:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo apt install libfile-copy-recursive-perl # For Ubuntu/Debian&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Your project directory should now look like the following picture, with the &#039;&#039;miosix-kernel&#039;&#039; directory containing the kernel sources, the &#039;&#039;config&#039;&#039; directory with the kernel configuration, the empty &#039;&#039;main.cpp&#039;&#039; and the build files for the two alternative build systems supported by Miosix: Makefile and CMake:&lt;br /&gt;
&lt;br /&gt;
[[File:Initialized-miosix-project-linux.png]]&lt;br /&gt;
&lt;br /&gt;
For this tutorial, we&#039;ll use the Makefile build system, have a look at the [[CMake]] page to learn how to use CMake instead.&lt;br /&gt;
&lt;br /&gt;
== Configuring the kernel ==&lt;br /&gt;
&lt;br /&gt;
The minimum configuration required to compile the kernel is to &#039;&#039;&#039;select a board&#039;&#039;&#039;, as the kernel needs to build the appropriate board support package for it.&lt;br /&gt;
&lt;br /&gt;
The Miosix kernel has several other build-time configuration options, to enable optional components (filesystem, userspace processes), select algorithms such as the scheduler and trade feature support for code size, but these won&#039;t be covered here.&lt;br /&gt;
The kernel is configured by editing files in the config directory, the two most important ones are [https://github.com/fedetft/miosix-kernel/blob/master/miosix/config/Makefile.inc Makefile.inc] and [https://github.com/fedetft/miosix-kernel/blob/master/miosix/config/miosix_settings.h miosix_settings.h].&lt;br /&gt;
&lt;br /&gt;
To select a board, open the first one, &#039;&#039;config/Makefile.inc&#039;&#039;. Look for the &#039;&#039;OPT_BOARD&#039;&#039; section of the file, which contains the list of boards officially supported by the kernel. In this section, all boards appear commented out (the &#039;&#039;#&#039;&#039; sign is a comment in Makefile syntax), so you need to uncomment the line corrsponding to your board. [[Porting]] the kernel to a new board is an advanced topic not covered here, so we&#039;ll assume you&#039;ll want to use an officially supported board. As an example, in this tutorial we&#039;ll use the stm32f746zg_nucleo board:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
#OPT_BOARD := stm32f469ni_stm32f469i-disco&lt;br /&gt;
OPT_BOARD := stm32f746zg_nucleo&lt;br /&gt;
#OPT_BOARD := stm32f765ii_marco_ram_board&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you do not yet have a board, you can follow along and get to the compiled firmware anyway. If you&#039;re looking for suggestions on which board to get, consider that most boards currently supported by Miosix are for STM32 microcontrollers. Here&#039;s a basic guide:&lt;br /&gt;
* &#039;&#039;&#039;Nucleo&#039;&#039;&#039; STM32 boards produced by ST are good for beginners, as they allow to power the board, flash it, debug it and access the serial port all through a single USB connection with your computer. The stm32f401re_nucleo and stm32f411re_nucleo are realtively low cost.&lt;br /&gt;
* &#039;&#039;&#039;Discovery&#039;&#039;&#039; STM32 boards are also good, but they don&#039;t include an USB to serial adapter so you&#039;ll have to buy it separately and you&#039;ll end up having to connect two USB cables, one for power/programming/debugging and one for the serial port.&lt;br /&gt;
* &#039;&#039;&#039;Third party&#039;&#039;&#039; STM32 boards such as the stm32f411ce_blackpill are cheaper and great to embed in your hardware project, but you&#039;ll have to [https://en.wikipedia.org/wiki/Soldering solder] the pin header yourself, and you&#039;ll need to attach a separate USB to serial adapter, and if you want in-circuit debugging you&#039;ll need an STLink adapter, so you&#039;ll end up having to run up to three separate USB cables from your computer to the board for power/programming, serial port and debugging.&lt;br /&gt;
* Venturing outside of STM32, the &#039;&#039;&#039;RP2040&#039;&#039;&#039; is a good choice. Also in this case, you&#039;ll need a separate USB to serial adapter and some soldering skills, though.&lt;br /&gt;
&lt;br /&gt;
= Writing your first Miosix program =&lt;br /&gt;
&lt;br /&gt;
== Hello world ==&lt;br /&gt;
&lt;br /&gt;
Open the &#039;&#039;main.cpp&#039;&#039; file with your [[IDEs | IDE]] or text editor of choice, and replace its content with the following program:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;CPP&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;cstdio&amp;gt;&lt;br /&gt;
#include &amp;lt;thread&amp;gt;&lt;br /&gt;
#include &amp;lt;miosix.h&amp;gt;&lt;br /&gt;
#include &amp;lt;interfaces/bsp.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
using namespace std;&lt;br /&gt;
using namespace miosix;&lt;br /&gt;
&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
    for(;;)&lt;br /&gt;
    {&lt;br /&gt;
        iprintf(&amp;quot;Hello world\n&amp;quot;);&lt;br /&gt;
        ledOn();&lt;br /&gt;
        this_thread::sleep_for(500ms);&lt;br /&gt;
        ledOff();&lt;br /&gt;
        this_thread::sleep_for(500ms);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
At this point, it&#039;s good to have a quick walkthrough of this hello world program. Miosix is based on a [[Fluid kernel]] architecture: in a nutshell it&#039;s kernel that supports writing applications both inside the kernel, and inside userspace programs. In this tutorial, we&#039;re using it as a unikernel. This means when power is applied to the board, the kernel will boot, and then start running the &#039;&#039;main()&#039;&#039; function you just wrote &#039;&#039;in kernelspace&#039;&#039;. This means you have both support for C/C++ standard libraries and unrestricted hardware access.&lt;br /&gt;
&lt;br /&gt;
This main() function will print &amp;quot;Hello world&amp;quot; and blink an LED approximately every second.&lt;br /&gt;
The printing is done with the &#039;&#039;iprintf()&#039;&#039; function. If you expected just &#039;&#039;printf()&#039;&#039; without the &#039;&#039;i&#039;&#039;, the reason is that Miosix uses the [https://sourceware.org/newlib/ Newlib] C standard library that provides both &#039;&#039;printf()&#039;&#039; and &#039;&#039;iprintf()&#039;&#039;, an optimized version that is smaller in code size but incapable of printing floating point numbers. So you can also use &#039;&#039;printf()&#039;&#039; if you wish, but this optimization is worth knowing from the start.&lt;br /&gt;
&lt;br /&gt;
Sleeping to blink the LED is done with the [https://en.cppreference.com/cpp/thread/sleep_for sleep_for()] function from the C++ standard library. Miosix supports other sleeping APIs, such as [https://pubs.opengroup.org/onlinepubs/9699919799/functions/nanosleep.html nanosleep()] from POSIX, or &#039;&#039;Thread::sleep()&#039;&#039;, a native Miosix function. All these functions do the same thing: they tell the scheduler to stop the currently running thread, run some other thread, and resume execution after a given time interval. Miosix is a preemptive multithreading operating system, so you should get comfortable with the fact that the code you&#039;re writing lives in a thread and shares the CPU with other threads.&lt;br /&gt;
&lt;br /&gt;
Many (but not all!) board support packages define the &#039;&#039;ledOn()&#039;&#039; and &#039;&#039;ledOff()&#039;&#039; functions to control one of the LED on the board. This should be true for all the boards that have at least one software-accessible LED. This is true for the &#039;&#039;stm32f746zg_nucleo&#039;&#039; board we selected, but if you selected a different board with no LEDs, then compiling will fail with an error related to &#039;&#039;ledOn()&#039;&#039; and &#039;&#039;ledOff()&#039;&#039;. You can comment out those two lines in this case, your hello world will only print to the serial port.&lt;br /&gt;
&lt;br /&gt;
== Compiling ==&lt;br /&gt;
&lt;br /&gt;
To compile the kernel, open a terminal in the &#039;&#039;&#039;hello&#039;&#039;&#039; project directory and type:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
make -j`nproc`&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;-j`nproc`&#039;&#039; is optional, it will compile faster by using the multicore CPU in your computer. If you know how many cores you have, you can also specify the number explicitly, such as &#039;&#039;make -j8&#039;&#039;. If all goes well, the result should look like this:&lt;br /&gt;
&lt;br /&gt;
[[File:Make-output-linux.png]]&lt;br /&gt;
&lt;br /&gt;
Otherwise, compiler errors will appear in the shell. The number that appears under &#039;&#039;text&#039;&#039; in the make output is the size in bytes of your application plus the kernel. Don&#039;t worry about the 42KBytes code size, you&#039;re compiling with the default Miosix options, if you want you can play around with the options later to  [[Miosix code size optimization|reduce the code size]].&lt;br /&gt;
&lt;br /&gt;
== Flashing ==&lt;br /&gt;
&lt;br /&gt;
To flash the board, you can use the &#039;&#039;make program&#039;&#039; Makefile rule to automatically download the kernel to the board. Connect the USB cable first, and then run:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
make program&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If the operation completed successfully, the the output should be similar to this one, and the LED should blink on the board:&lt;br /&gt;
&lt;br /&gt;
[[File:Make program linux.png]]&lt;br /&gt;
&lt;br /&gt;
If the operation did not succeed, here are some common problems:&lt;br /&gt;
* You get a &#039;&#039;command not found&#039;&#039; error. You probably did not install the right flashing tool on your computer, read here [[Linux flashing tools]].&lt;br /&gt;
* The flashing tool starts, but throws an error such as &#039;&#039;Couldn&#039;t find any ST-Link devices&#039;&#039;. You probably do not have the right permissions to access the board. Try &#039;&#039;sudo make program&#039;&#039;. If that one works, you&#039;ll have to install &#039;&#039;udev rules&#039;&#039; to make the USB device of your board&#039;s programming interface accessible from your user. Unfortunately the details to installing (or writing from scratch) the correct udev rules file depend on the combination of the flashing tool and board. None of these are specific to Miosix, so look online in the documentation of your flashing tool.&lt;br /&gt;
&lt;br /&gt;
Another issue in some STM32 boards is that the flashing tool leaves the board in a state where the mcirocontroller blocks either after flashing or if you press the reset button on the board. This issue is again specific to the board and flashing tool and unrelated to Miosix. If you encounter this problem after having programmed the microcontroller, it is recommended to unplug and reconnect the USB cable to powercycle the board. At that point, you should see the LED blinking.&lt;br /&gt;
&lt;br /&gt;
== Accessing the serial port ==&lt;br /&gt;
&lt;br /&gt;
Starting from Miosix v3.00, all boards use by default a baud rate of 115200bit/s.&lt;br /&gt;
If you&#039;re using a &#039;&#039;&#039;Nucleo&#039;&#039;&#039; board from ST, the USB to serial port adapter will appear on your computer as &#039;&#039;/dev/ttyACM0&#039;&#039;, so use the &#039;&#039;screen&#039;&#039; program with the following parameters:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
screen /dev/ttyACM0 115200&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Since the board will be already running when you connect, you can press the RESET button on the board to reboot it and see the boot logs:&lt;br /&gt;
&lt;br /&gt;
[[File:Serial-view-linux.png]]&lt;br /&gt;
&lt;br /&gt;
Exiting the screen program is cumbersome at first, but you&#039;ll get used to it quickly. You have to type &#039;&#039;Ctrl-A&#039;&#039;, then &#039;&#039;k&#039;&#039; and &#039;&#039;y&#039;&#039;. Typing &#039;&#039;Ctrl-C&#039;&#039; won&#039;t stop the program, it will just send a &#039;&#039;Ctrl-C&#039;&#039; to the microcontroller.&lt;br /&gt;
&lt;br /&gt;
If you are using a board that does not have an integrated USB to serial adapter, you&#039;ll need to figure out to which pins is the default serial connected. To do so, you&#039;ll have to look for the kernel configuration file for your board. For example, for the &#039;&#039;stm32f411ce_blackpill&#039;&#039; the file is: [https://github.com/fedetft/miosix-kernel/blob/master/miosix/config/board/stm32f411ce_blackpill/board_settings.h config/board/stm32f411ce_blackpill/board_settings.h], where you&#039;ll find that the serial port TX pin is PA9, and the RX pin is PA10. Remember to cross the TX and RX pin, the TX pin of the microcontroller goes to the RX pin of the serial adapter! For reliable communication you&#039;ll also have to connect a wire between the board GND and the serial adapter GND.&lt;br /&gt;
&lt;br /&gt;
Another example would be for the RP2040. In this case the configuration file is [https://github.com/fedetft/miosix-kernel/blob/master/miosix/config/board/rp2040_raspberry_pi_pico/board_settings.h config/board/rp2040_raspberry_pi_pico/board_settings.h] and the serial TX pin is P0.0, while RX is P0.1.&lt;br /&gt;
&lt;br /&gt;
The most common standalone USB to serial adapters are based on the FTDI&#039;s FT232 chip, which appears on GNU/Linux as &#039;&#039;/dev/ttyUSB0&#039;&#039;, so the command to access the serial port would be:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
screen /dev/ttyUSB0 115200&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:Installation and Configuration]]&lt;/div&gt;</summary>
		<author><name>Fede.tft</name></author>
	</entry>
	<entry>
		<id>https://miosix.org/wiki/index.php?title=Windows_Quick_Start&amp;diff=450</id>
		<title>Windows Quick Start</title>
		<link rel="alternate" type="text/html" href="https://miosix.org/wiki/index.php?title=Windows_Quick_Start&amp;diff=450"/>
		<updated>2026-05-10T17:07:51Z</updated>

		<summary type="html">&lt;p&gt;Fede.tft: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Installing the required software =&lt;br /&gt;
&lt;br /&gt;
== Miosix Toolchain ==&lt;br /&gt;
&lt;br /&gt;
To be able to compile the Miosix kernel and your application, you need a patched version of the GCC compiler called Miosix toolchain, you can find the link to download it [[Miosix Toolchain|here]]. At the end of the installation you will need to reboot your computer (sorry, it&#039;s Windows...)&lt;br /&gt;
&lt;br /&gt;
== Git ==&lt;br /&gt;
&lt;br /&gt;
To download the Miosix kernel and keep it up to date, you need the [https://en.wikipedia.org/wiki/Git_%28software%29 git] version control system.&lt;br /&gt;
&lt;br /&gt;
It is recommended to install it from [http://www.git-scm.com/download/win git-scm.com]. Please &#039;&#039;&#039;do not&#039;&#039;&#039; uncheck the &#039;&#039;Windows Explorer integration&#039;&#039; feature during the installation, as you will need it to install the kernel sources.&lt;br /&gt;
&lt;br /&gt;
== Perl ==&lt;br /&gt;
&lt;br /&gt;
The [https://en.wikipedia.org/wiki/Perl Perl] programming language is used by the Miosix build system. Unlike on GNU/Linux computers where Perl is pre-installed, for Windows you&#039;ll need to install it separately.&lt;br /&gt;
&lt;br /&gt;
[http://strawberryperl.com Strawberry perl] is the recomended Perl version for Miosix on Windows.&lt;br /&gt;
&lt;br /&gt;
== Flashing tool ==&lt;br /&gt;
&lt;br /&gt;
With the installed Miosix toolchain you&#039;ll be able to compile the kernel, but you&#039;ll also need a way to transfer it to your microcontroller. This operation is usually called &#039;flashing&#039; the microcontroller. Miosix can work with any flashing utility that accepts as input raw binary files, and on Windows you&#039;ll usually want to install the flashing tool provided by your chip vendor.&lt;br /&gt;
&lt;br /&gt;
For STM32 chips, you can use the STLink utility available [http://www.st.com/web/en/catalog/tools/PF258168# here].&lt;br /&gt;
&lt;br /&gt;
== Text editor or IDE ==&lt;br /&gt;
&lt;br /&gt;
It is recommended to download a better text editor than Notepad, as you will need it to edit the Miosix configuration files. [http://www.notepad-plus-plus.org/ Notepad++] is a good option, but many other options exist. Just &#039;&#039;&#039;don&#039;t use Notepad&#039;&#039;&#039;, because it does not recognize Unix [https://en.wikipedia.org/wiki/Line_ending line-endings] and will show you Miosix source files as if they were composed of a single line of text.&lt;br /&gt;
&lt;br /&gt;
As an alternative to Notepad++, you may want to use an [[IDEs|IDE]].&lt;br /&gt;
&lt;br /&gt;
== Serial port viewer ==&lt;br /&gt;
&lt;br /&gt;
Miosix redirects &#039;&#039;stdin&#039;&#039;/&#039;&#039;stdout&#039;&#039; to a serial port by default on most boards, so to see the boot log and the output of &#039;&#039;printf()&#039;&#039; in your application you need a program to interact with the serial port. [https://putty.org/index.html PuTTY] is an option, although old fashioned. TODO: There are likely better options for Windows too.&lt;br /&gt;
&lt;br /&gt;
= Downloading and configuring the Miosix kernel =&lt;br /&gt;
&lt;br /&gt;
This section is a stripped down guide with the bare minimum to get you started, we also have a full guide about [[Miosix and git workflow]]. Following the tutorial in this page, your project directory will &#039;&#039;&#039;not&#039;&#039;&#039; be under version control (git). The [[Miosix and git workflow]] page shows how to create a git repository for your project and add the Miosix kernel as a git submodule.&lt;br /&gt;
&lt;br /&gt;
Before downloading the kernel, however, you first have to create &#039;&#039;&#039;a directory for your project&#039;&#039;&#039; (in this case, the hello world), and then clone the kernel &#039;&#039;&#039;as a subdirectory&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Using the Windows explorer, create a &#039;&#039;&#039;hello&#039;&#039;&#039; directory, double click on it. Then right-click on the empty directory. Select &#039;&#039;Git bash&#039;&#039; to open a git shell. This opens a shell where you can type the commands to download the kernel.&lt;br /&gt;
&lt;br /&gt;
[[File:Git-bash-windows.png]]&lt;br /&gt;
&lt;br /&gt;
Note that it is possible to paste commands in the shell (so as to avoid typing them, which can be tedious and lead to typos), but you have to do it one line of text at a time, and to paste you need to use the &#039;&#039;Shift+Ins&#039;&#039; shortcut, not the usual &#039;&#039;Ctrl+V&#039;&#039; one. The last command, &#039;&#039;exit&#039;&#039;, will close the shell.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git clone https://github.com/fedetft/miosix-kernel.git&lt;br /&gt;
exit&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that there is also a &#039;&#039;Git GUI&#039;&#039; in the right click menu, but git is best used from a command line interface, you&#039;re on your own if you choose to use git from the GUI.&lt;br /&gt;
&lt;br /&gt;
== Initializing a Miosix project ==&lt;br /&gt;
&lt;br /&gt;
For reasons explained in depth in the [[Miosix and git workflow]] page, you&#039;ll need to copy the Miosix configuration directory from the kernel sources to your project directory, as well as create a template project where you can start writing code.&lt;br /&gt;
This can be automated with a [https://en.wikipedia.org/wiki/Perl Perl] script called &#039;&#039;init_project_out_of_git_tree.pl&#039;&#039;. To run it, you need to open a Windows terminal (which is a &#039;&#039;&#039;different&#039;&#039;&#039; terminal than the git bash we used before), which can be done by &#039;&#039;Shift+Right click&#039;&#039; and selecting &#039;&#039;Open command window here&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
[[File:Open-terminal-windows.png]]&lt;br /&gt;
&lt;br /&gt;
Then, type the following command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
perl miosix-kernel/tools/init_project_out_of_git_tree.pl&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Leave the terminal open as you&#039;ll need it later.&lt;br /&gt;
&lt;br /&gt;
You should run the script from the directory where you want to initialize your empty project, such as the &#039;&#039;&#039;hello&#039;&#039;&#039; directory in this tutorial. A successful run of the script produces the following output:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Successfully created Miosix project&lt;br /&gt;
Target directory: hello&lt;br /&gt;
Kernel directory: hello/miosix-kernel/miosix&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Your project directory should now look like the following picture, with the &#039;&#039;miosix-kernel&#039;&#039; directory containing the kernel sources, the &#039;&#039;config&#039;&#039; directory with the kernel configuration, the empty &#039;&#039;main.cpp&#039;&#039; and the build files for the two alternative build systems supported by Miosix: Makefile and CMake:&lt;br /&gt;
&lt;br /&gt;
[[File:Initialized-miosix-project-windows.png]]&lt;br /&gt;
&lt;br /&gt;
For this tutorial, we&#039;ll use the Makefile build system, have a look at the [[CMake]] page to learn how to use CMake instead.&lt;br /&gt;
&lt;br /&gt;
== Configuring the kernel ==&lt;br /&gt;
&lt;br /&gt;
The minimum configuration required to compile the kernel is to &#039;&#039;&#039;select a board&#039;&#039;&#039;, as the kernel needs to build the appropriate board support package for it.&lt;br /&gt;
&lt;br /&gt;
The Miosix kernel has several other build-time configuration options, to enable optional components (filesystem, userspace processes), select algorithms such as the scheduler and trade feature support for code size, but these won&#039;t be covered here.&lt;br /&gt;
The kernel is configured by editing files in the config directory, the two most important ones are [https://github.com/fedetft/miosix-kernel/blob/master/miosix/config/Makefile.inc Makefile.inc] and [https://github.com/fedetft/miosix-kernel/blob/master/miosix/config/miosix_settings.h miosix_settings.h].&lt;br /&gt;
&lt;br /&gt;
To select a board, using Notepad++ open the first one, &#039;&#039;config/Makefile.inc&#039;&#039;. Look for the &#039;&#039;OPT_BOARD&#039;&#039; section of the file, which contains the list of boards officially supported by the kernel. In this section, all boards appear commented out (the &#039;&#039;#&#039;&#039; sign is a comment in Makefile syntax), so you need to uncomment the line corrsponding to your board. [[Porting]] the kernel to a new board is an advanced topic not covered here, so we&#039;ll assume you&#039;ll want to use an officially supported board. As an example, in this tutorial we&#039;ll use the stm32f746zg_nucleo board:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
#OPT_BOARD := stm32f469ni_stm32f469i-disco&lt;br /&gt;
OPT_BOARD := stm32f746zg_nucleo&lt;br /&gt;
#OPT_BOARD := stm32f765ii_marco_ram_board&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you do not yet have a board, you can follow along and get to the compiled firmware anyway. If you&#039;re looking for suggestions on which board to get, consider that most boards currently supported by Miosix are for STM32 microcontrollers. Here&#039;s a basic guide:&lt;br /&gt;
* &#039;&#039;&#039;Nucleo&#039;&#039;&#039; STM32 boards produced by ST are good for beginners, as they allow to power the board, flash it, debug it and access the serial port all through a single USB connection with your computer. The stm32f401re_nucleo and stm32f411re_nucleo are realtively low cost.&lt;br /&gt;
* &#039;&#039;&#039;Discovery&#039;&#039;&#039; STM32 boards are also good, but they don&#039;t include an USB to serial adapter so you&#039;ll have to buy it separately and you&#039;ll end up having to connect two USB cables, one for power/programming/debugging and one for the serial port.&lt;br /&gt;
* &#039;&#039;&#039;Third party&#039;&#039;&#039; STM32 boards such as the stm32f411ce_blackpill are cheaper and great to embed in your hardware project, but you&#039;ll have to [[https://en.wikipedia.org/wiki/Soldering solder]] the pin header yourself, and you&#039;ll need to attach a separate USB to serial adapter, and if you want in-circuit debugging you&#039;ll need an STLink adapter, so you&#039;ll end up having to run up to three separate USB cables from your computer to the board for power/programming, serial port and debugging.&lt;br /&gt;
* Venturing outside of STM32, the &#039;&#039;&#039;RP2040&#039;&#039;&#039; is a good choice. Also in this case, you&#039;ll need a separate USB to serial adapter and some soldering skills, though.&lt;br /&gt;
&lt;br /&gt;
= Writing your first Miosix program =&lt;br /&gt;
&lt;br /&gt;
== Hello world ==&lt;br /&gt;
&lt;br /&gt;
With Notepad++ open the &#039;&#039;main.cpp&#039;&#039; file with your [[IDEs | IDE]] or text editor of choice, and replace its content with the following program:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;CPP&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;cstdio&amp;gt;&lt;br /&gt;
#include &amp;lt;thread&amp;gt;&lt;br /&gt;
#include &amp;lt;miosix.h&amp;gt;&lt;br /&gt;
#include &amp;lt;interfaces/bsp.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
using namespace std;&lt;br /&gt;
using namespace miosix;&lt;br /&gt;
&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
    for(;;)&lt;br /&gt;
    {&lt;br /&gt;
        iprintf(&amp;quot;Hello world\n&amp;quot;);&lt;br /&gt;
        ledOn();&lt;br /&gt;
        this_thread::sleep_for(500ms);&lt;br /&gt;
        ledOff();&lt;br /&gt;
        this_thread::sleep_for(500ms);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
At this point, it&#039;s good to have a quick walkthrough of this hello world program. Miosix is based on a [[Fluid kernel]] architecture: in a nutshell it&#039;s kernel that supports writing applications both inside the kernel, and inside userspace programs. In this tutorial, we&#039;re using it as a unikernel. This means when power is applied to the board, the kernel will boot, and then start running the &#039;&#039;main()&#039;&#039; function you just wrote &#039;&#039;in kernelspace&#039;&#039;. This means you have both support for C/C++ standard libraries and unrestricted hardware access.&lt;br /&gt;
&lt;br /&gt;
This main() function will print &amp;quot;Hello world&amp;quot; and blink an LED approximately every second.&lt;br /&gt;
The printing is done with the &#039;&#039;iprintf()&#039;&#039; function. If you expected just &#039;&#039;printf()&#039;&#039; without the &#039;&#039;i&#039;&#039;, the reason is that Miosix uses the [https://sourceware.org/newlib/ Newlib] C standard library that provides both &#039;&#039;printf()&#039;&#039; and &#039;&#039;iprintf()&#039;&#039;, an optimized version that is smaller in code size but incapable of printing floating point numbers. So you can also use &#039;&#039;printf()&#039;&#039; if you wish, but this optimization is worth knowing from the start.&lt;br /&gt;
&lt;br /&gt;
Sleeping to blink the LED is done with the [https://en.cppreference.com/cpp/thread/sleep_for sleep_for()] function from the C++ standard library. Miosix supports other sleeping APIs, such as [https://pubs.opengroup.org/onlinepubs/9699919799/functions/nanosleep.html nanosleep()] from POSIX, or &#039;&#039;Thread::sleep()&#039;&#039;, a native Miosix function. All these functions do the same thing: they tell the scheduler to stop the currently running thread, run some other thread, and resume execution after a given time interval. Miosix is a preemptive multithreading operating system, so you should get comfortable with the fact that the code you&#039;re writing lives in a thread and shared the CPU with other threads.&lt;br /&gt;
&lt;br /&gt;
Many (but not all!) board support packages define the &#039;&#039;ledOn()&#039;&#039; and &#039;&#039;ledOff()&#039;&#039; functions to control one of the LED on the board. This should be true for all the boards that have at least one software-accessible LED. This is true for the &#039;&#039;stm32f746zg_nucleo&#039;&#039; board we selected, but if you selected a different board with no LEDs, then compiling will fail with an error related to &#039;&#039;ledOn()&#039;&#039; and &#039;&#039;ledOff()&#039;&#039;. You can comment out those two lines in this case, your hello world will only print to the serial port.&lt;br /&gt;
&lt;br /&gt;
== Compiling ==&lt;br /&gt;
&lt;br /&gt;
In the same terminal you used to run Perl, type &#039;&#039;make&#039;&#039; to build the kernel. If all goes well, the result should look like this.&lt;br /&gt;
&lt;br /&gt;
[[File:Make-output-windows.png]]&lt;br /&gt;
&lt;br /&gt;
Otherwise, compiler errors will appear in the shell. The number that appears under &#039;&#039;text&#039;&#039; in the make output is the size in bytes of your application plus the kernel. Don&#039;t worry about the 42KBytes code size, you&#039;re compiling with the default Miosix options, if you want you can play around with the options later to  [[Miosix code size optimization|reduce the code size]].&lt;br /&gt;
&lt;br /&gt;
== Flashing ==&lt;br /&gt;
&lt;br /&gt;
The procedure to flash the microcontroller board on Windows depends on the vendor-provided flashing tool. They usually provide a GUI where you can load the &#039;&#039;.bin&#039;&#039; file and then connect to the board and flash it. For Miosix the file is named main.bin if you&#039;re not using processes, or image.bin if you are using processes. For this tutorial, look for &#039;&#039;main.bin&#039;&#039; in the &#039;&#039;&#039;hello&#039;&#039;&#039; directory.&lt;br /&gt;
&lt;br /&gt;
If you correctly flashed the board, the LED will start blinking.&lt;br /&gt;
&lt;br /&gt;
== Accessing the serial port ==&lt;br /&gt;
&lt;br /&gt;
The USB to serial port adapter will appear on Windows as a randomly numbered COM port. To figure out the right number, you&#039;ll have to open &#039;&#039;Devices&#039;&#039; from the control panel:&lt;br /&gt;
&lt;br /&gt;
[[File:Windows-list-devices.png]]&lt;br /&gt;
&lt;br /&gt;
Today, on my computer, Windows decided to assign the STM32 board to COM3.&lt;br /&gt;
&lt;br /&gt;
Next up, open PuTTY and configure it to open the right COM port. Starting from Miosix v3.00, all boards use by default a baud rate of 115200bit/s, so input 115200 in the &#039;&#039;Speed&#039;&#039; field:&lt;br /&gt;
&lt;br /&gt;
[[File:Windows-putty-configuration.png]]&lt;br /&gt;
&lt;br /&gt;
Finally, click &#039;&#039;Open&#039;&#039; and you should see the serial port messages from the microcontroller. Since the board will be already running when you connect, you can press the RESET button on the board to reboot it and see the boot logs:&lt;br /&gt;
&lt;br /&gt;
[[File:Windows-putty-serial.png]]&lt;br /&gt;
&lt;br /&gt;
= A note on uninstalling software =&lt;br /&gt;
&lt;br /&gt;
To uninstall the Miosix Toolchain, you can find the uninstaller in the start menu under &#039;&#039;Miosix Toolchain&#039;&#039;. Note that the other tools such as Git, Perl and the STLink  utility have their own uninstallers.&lt;br /&gt;
&lt;br /&gt;
[[Category:Installation and Configuration]]&lt;/div&gt;</summary>
		<author><name>Fede.tft</name></author>
	</entry>
	<entry>
		<id>https://miosix.org/wiki/index.php?title=Windows_Quick_Start&amp;diff=449</id>
		<title>Windows Quick Start</title>
		<link rel="alternate" type="text/html" href="https://miosix.org/wiki/index.php?title=Windows_Quick_Start&amp;diff=449"/>
		<updated>2026-05-10T17:06:31Z</updated>

		<summary type="html">&lt;p&gt;Fede.tft: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Installing the required software =&lt;br /&gt;
&lt;br /&gt;
== Miosix Toolchain ==&lt;br /&gt;
&lt;br /&gt;
To be able to compile the Miosix kernel and your application, you need a patched version of the GCC compiler called Miosix toolchain, you can find the link to download it [[Miosix Toolchain|here]]. At the end of the installation you will need to reboot your computer (sorry, it&#039;s Windows...)&lt;br /&gt;
&lt;br /&gt;
== Git ==&lt;br /&gt;
&lt;br /&gt;
To download the Miosix kernel and keep it up to date, you need the [https://en.wikipedia.org/wiki/Git_%28software%29 git] version control system.&lt;br /&gt;
&lt;br /&gt;
It is recommended to install it from [http://www.git-scm.com/download/win git-scm.com]. Please &#039;&#039;&#039;do not&#039;&#039;&#039; uncheck the &#039;&#039;Windows Explorer integration&#039;&#039; feature during the installation, as you will need it to install the kernel sources.&lt;br /&gt;
&lt;br /&gt;
== Perl ==&lt;br /&gt;
&lt;br /&gt;
The [https://en.wikipedia.org/wiki/Perl Perl] programming language is used by the Miosix build system. Unlike on GNU/Linux computers where Perl is pre-installed, for Windows you&#039;ll need to install it separately.&lt;br /&gt;
&lt;br /&gt;
[http://strawberryperl.com Strawberry perl] is the recomended Perl version for Miosix on Windows.&lt;br /&gt;
&lt;br /&gt;
== Flashing tool ==&lt;br /&gt;
&lt;br /&gt;
With the installed Miosix toolchain you&#039;ll be able to compile the kernel, but you&#039;ll also need a way to transfer it to your microcontroller. This operation is usually called &#039;flashing&#039; the microcontroller. Miosix can work with any flashing utility that accepts as input raw binary files, and on Windows you&#039;ll usually want to install the flashing tool provided by your chip vendor.&lt;br /&gt;
&lt;br /&gt;
For STM32 chips, you can use the STLink utility available [http://www.st.com/web/en/catalog/tools/PF258168# here].&lt;br /&gt;
&lt;br /&gt;
== Text editor or IDE ==&lt;br /&gt;
&lt;br /&gt;
It is recommended to download a better text editor than Notepad, as you will need it to edit the Miosix configuration files. [http://www.notepad-plus-plus.org/ Notepad++] is a good option, but many other options exist. Just &#039;&#039;&#039;don&#039;t use Notepad&#039;&#039;&#039;, because it does not recognize Unix [https://en.wikipedia.org/wiki/Line_ending line-endings] and will show you Miosix source files as if they were composed of a single line of text.&lt;br /&gt;
&lt;br /&gt;
As an alternative to Notepad++, you may want to use an [[IDEs|IDE]].&lt;br /&gt;
&lt;br /&gt;
== Serial port viewer ==&lt;br /&gt;
&lt;br /&gt;
Miosix redirects &#039;&#039;stdin&#039;&#039;/&#039;&#039;stdout&#039;&#039; to a serial port by default on most boards, so to see the boot log and the output of &#039;&#039;printf()&#039;&#039; in your application you need a program to interact with the serial port. [https://putty.org/index.html PuTTY] is an option, although old fashioned. TODO: There are likely better options for Windows too.&lt;br /&gt;
&lt;br /&gt;
= Downloading and configuring the Miosix kernel =&lt;br /&gt;
&lt;br /&gt;
This section is a stripped down guide with the bare minimum to get you started, we also have a full guide about [[Miosix and git workflow]]. Following the tutorial in this page, your project directory will &#039;&#039;&#039;not&#039;&#039;&#039; be under version control (git). The [[Miosix and git workflow]] page shows how to create a git repository for your project and add the Miosix kernel as a git submodule.&lt;br /&gt;
&lt;br /&gt;
Before downloading the kernel, however, you first have to create &#039;&#039;&#039;a directory for your project&#039;&#039;&#039; (in this case, the hello world), and then clone the kernel &#039;&#039;&#039;as a subdirectory&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Using the Windows explorer, create a &#039;&#039;&#039;hello&#039;&#039;&#039; directory, double click on it. Then right-click on the empty directory. Select &#039;&#039;Git bash&#039;&#039; to open a git shell. This opens a shell where you can type the commands to download the kernel.&lt;br /&gt;
&lt;br /&gt;
[[File:Git-bash-windows.png]]&lt;br /&gt;
&lt;br /&gt;
Note that it is possible to paste commands in the shell (so as to avoid typing them, which can be tedious and lead to typos), but you have to do it one line of text at a time, and to paste you need to use the &#039;&#039;Shift+Ins&#039;&#039; shortcut, not the usual &#039;&#039;Ctrl+V&#039;&#039; one. The last command, &#039;&#039;exit&#039;&#039;, will close the shell.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git clone https://github.com/fedetft/miosix-kernel.git&lt;br /&gt;
exit&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that there is also a &#039;&#039;Git GUI&#039;&#039; in the right click menu, but git is best used from a command line interface, you&#039;re on your own if you choose to use git from the GUI.&lt;br /&gt;
&lt;br /&gt;
== Initializing a Miosix project ==&lt;br /&gt;
&lt;br /&gt;
For reasons explained in depth in the [[Miosix and git workflow]] page, you&#039;ll need to copy the Miosix configuration directory from the kernel sources to your project directory, as well as create a template project where you can start writing code.&lt;br /&gt;
This can be automated with a [https://en.wikipedia.org/wiki/Perl Perl] script called &#039;&#039;init_project_out_of_git_tree.pl&#039;&#039;. To run it, you need to open a Windows terminal (which is a &#039;&#039;&#039;different&#039;&#039;&#039; terminal than the git bash we used before), which can be done by &#039;&#039;Shift+Right click&#039;&#039; and selecting &#039;&#039;Open command window here&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
[[File:Open-terminal-windows.png]]&lt;br /&gt;
&lt;br /&gt;
Then, type the following command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
perl miosix-kernel/tools/init_project_out_of_git_tree.pl&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Leave the terminal open as you&#039;ll need it later.&lt;br /&gt;
&lt;br /&gt;
You should run the script from the directory where you want to initialize your empty project, such as the &#039;&#039;&#039;hello&#039;&#039;&#039; directory in this tutorial. A successful run of the script produces the following output:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Successfully created Miosix project&lt;br /&gt;
Target directory: hello&lt;br /&gt;
Kernel directory: hello/miosix-kernel/miosix&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Your project directory should now look like the following picture, with the &#039;&#039;miosix-kernel&#039;&#039; directory containing the kernel sources, the &#039;&#039;config&#039;&#039; directory with the kernel configuration, the empty &#039;&#039;main.cpp&#039;&#039; and the build files for the two alternative build systems supported by Miosix: Makefile and CMake:&lt;br /&gt;
&lt;br /&gt;
[[File:Initialized-miosix-project-windows.png]]&lt;br /&gt;
&lt;br /&gt;
For this tutorial, we&#039;ll use the Makefile build system, have a look at the [[CMake]] page to learn how to use CMake instead.&lt;br /&gt;
&lt;br /&gt;
== Configuring the kernel ==&lt;br /&gt;
&lt;br /&gt;
The minimum configuration required to compile the kernel is to &#039;&#039;&#039;select a board&#039;&#039;&#039;, as the kernel needs to build the appropriate board support package for it.&lt;br /&gt;
&lt;br /&gt;
The Miosix kernel has several other build-time configuration options, to enable optional components (filesystem, userspace processes), select algorithms such as the scheduler and trade feature support for code size, but these won&#039;t be covered here.&lt;br /&gt;
The kernel is configured by editing files in the config directory, the two most important ones are [https://github.com/fedetft/miosix-kernel/blob/master/miosix/config/Makefile.inc Makefile.inc] and [https://github.com/fedetft/miosix-kernel/blob/master/miosix/config/miosix_settings.h miosix_settings.h].&lt;br /&gt;
&lt;br /&gt;
To select a board, using Notepad++ open the first one, &#039;&#039;config/Makefile.inc&#039;&#039;. Look for the &#039;&#039;OPT_BOARD&#039;&#039; section of the file, which contains the list of boards officially supported by the kernel. In this section, all boards appear commented out (the &#039;&#039;#&#039;&#039; sign is a comment in Makefile syntax), so you need to uncomment the line corrsponding to your board. [[Porting]] the kernel to a new board is an advanced topic not covered here, so we&#039;ll assume you&#039;ll want to use an officially supported board. As an example, in this tutorial we&#039;ll use the stm32f746zg_nucleo board:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
#OPT_BOARD := stm32f469ni_stm32f469i-disco&lt;br /&gt;
OPT_BOARD := stm32f746zg_nucleo&lt;br /&gt;
#OPT_BOARD := stm32f765ii_marco_ram_board&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you do not yet have a board, you can follow along and get to the compiled firmware anyway. If you&#039;re looking for suggestions on which board to get, consider that most boards currently supported by Miosix are for STM32 microcontrollers. Here&#039;s a basic guide:&lt;br /&gt;
* &#039;&#039;&#039;Nucleo&#039;&#039;&#039; STM32 boards produced by ST are good for beginners, as they allow to power the board, flash it, debug it and access the serial port all through a single USB connection with your computer. The stm32f401re_nucleo and stm32f411re_nucleo are realtively low cost.&lt;br /&gt;
* &#039;&#039;&#039;Discovery&#039;&#039;&#039; STM32 boards are also good, but they don&#039;t include an USB to serial adapter so you&#039;ll have to buy it separately and you&#039;ll end up having to connect two USB cables, one for power/programming/debugging and one for the serial port.&lt;br /&gt;
* &#039;&#039;&#039;Third party&#039;&#039;&#039; STM32 boards such as the stm32f411ce_blackpill are cheaper and great to embed in your hardware project, but you&#039;ll have to [[https://en.wikipedia.org/wiki/Soldering solder]] the pin header yourself, and you&#039;ll need to attach a separate USB to serial adapter, and if you want in-circuit debugging you&#039;ll need an STLink adapter, so you&#039;ll end up having to run up to three separate USB cables from your computer to the board for power/programming, serial port and debugging.&lt;br /&gt;
* Venturing outside of STM32, the &#039;&#039;&#039;RP2040&#039;&#039;&#039; is a good choice. Also in this case, you&#039;ll need a separate USB to serial adapter and some soldering skills, though.&lt;br /&gt;
&lt;br /&gt;
= Writing your first Miosix program =&lt;br /&gt;
&lt;br /&gt;
== Hello world ==&lt;br /&gt;
&lt;br /&gt;
With Notepad++ open the &#039;&#039;main.cpp&#039;&#039; file with your [[IDEs | IDE]] or text editor of choice, and replace its content with the following program:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;CPP&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;cstdio&amp;gt;&lt;br /&gt;
#include &amp;lt;thread&amp;gt;&lt;br /&gt;
#include &amp;lt;miosix.h&amp;gt;&lt;br /&gt;
#include &amp;lt;interfaces/bsp.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
using namespace std;&lt;br /&gt;
using namespace miosix;&lt;br /&gt;
&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
    for(;;)&lt;br /&gt;
    {&lt;br /&gt;
        iprintf(&amp;quot;Hello world\n&amp;quot;);&lt;br /&gt;
        ledOn();&lt;br /&gt;
        this_thread::sleep_for(500ms);&lt;br /&gt;
        ledOff();&lt;br /&gt;
        this_thread::sleep_for(500ms);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
At this point, it&#039;s good to have a quick walkthrough of this hello world program. Miosix is based on a [[Fluid kernel]] architecture: in a nutshell it&#039;s kernel that supports writing applications both inside the kernel, and inside userspace programs. In this tutorial, we&#039;re using it as a unikernel. This means when power is applied to the board, the kernel will boot, and then start running the &#039;&#039;main()&#039;&#039; function you just wrote &#039;&#039;in kernelspace&#039;&#039;. This means you have both support for C/C++ standard libraries and unrestricted hardware access.&lt;br /&gt;
&lt;br /&gt;
This main() function will print &amp;quot;Hello world&amp;quot; and blink an LED approximately every second.&lt;br /&gt;
The printing is done with the &#039;&#039;iprintf()&#039;&#039; function. If you expected just &#039;&#039;printf()&#039;&#039; without the &#039;&#039;i&#039;&#039;, the reason is that Miosix uses the [https://sourceware.org/newlib/ Newlib] C standard library that provides both &#039;&#039;printf()&#039;&#039; and &#039;&#039;iprintf()&#039;&#039;, an optimized version that is smaller in code size but incapable of printing floating point numbers. So you can also use &#039;&#039;printf()&#039;&#039; if you wish, but this optimization is worth knowing from the start.&lt;br /&gt;
&lt;br /&gt;
Sleeping to blink the LED is done with the [https://en.cppreference.com/cpp/thread/sleep_for sleep_for()] function from the C++ standard library. Miosix supports other sleeping APIs, such as [https://pubs.opengroup.org/onlinepubs/9699919799/functions/nanosleep.html nanosleep()] from POSIX, or &#039;&#039;Thread::sleep()&#039;&#039;, a native Miosix function. All these functions do the same thing: they tell the scheduler to stop the currently running thread, run some other thread, and resume execution after a given time interval. Miosix is a preemptive multithreading operating system, so you should get comfortable with the fact that the code you&#039;re writing lives in a thread and shared the CPU with other threads.&lt;br /&gt;
&lt;br /&gt;
Many (but not all!) board support packages define the &#039;&#039;ledOn()&#039;&#039; and &#039;&#039;ledOff()&#039;&#039; functions to control one of the LED on the board. This should be true for all the boards that have at least one software-accessible LED. This is true for the &#039;&#039;stm32f746zg_nucleo&#039;&#039; board we selected, but if you selected a different board with no LEDs, then compiling will fail with an error related to &#039;&#039;ledOn()&#039;&#039; and &#039;&#039;ledOff()&#039;&#039;. You can comment out those two lines in this case, your hello world will only print to the serial port.&lt;br /&gt;
&lt;br /&gt;
== Compiling ==&lt;br /&gt;
&lt;br /&gt;
In the same terminal you used to run Perl, type &#039;&#039;make&#039;&#039; to build the kernel. If all goes well, the result should look like this.&lt;br /&gt;
&lt;br /&gt;
[[File:Make-output-windows.png]]&lt;br /&gt;
&lt;br /&gt;
Otherwise, compiler errors will appear in the shell. The number that appears under &#039;&#039;text&#039;&#039; in the make output is the size in bytes of your application plus the kernel. Don&#039;t worry about the 42KBytes code size, you&#039;re compiling with the default Miosix options, if you want you can play around with the options later to  [[Miosix code size optimization|reduce the code size]].&lt;br /&gt;
&lt;br /&gt;
== Flashing ==&lt;br /&gt;
&lt;br /&gt;
The procedure to flash the microcontroller board on Windows depends on the vendor-provided flashing tool. They usually provide a GUI where you can load the &#039;&#039;.bin&#039;&#039; file and then connect to the board and flash it. For Miosix the file is named main.bin if you&#039;re not using processes, or image.bin if you are using processes. For this tutorial, look for &#039;&#039;main.bin&#039;&#039; in the &#039;&#039;&#039;hello&#039;&#039;&#039; directory.&lt;br /&gt;
&lt;br /&gt;
If you correctly flashed the board, the LED will start blinking.&lt;br /&gt;
&lt;br /&gt;
== Accessing the serial port ==&lt;br /&gt;
&lt;br /&gt;
The USB to serial port adapter will appear on Windows appears as a randomly numbered COM port. To figure out the right number, you&#039;ll have to open &#039;&#039;Devices&#039;&#039; from the control panel:&lt;br /&gt;
&lt;br /&gt;
[[File:Windows-list-devices.png]]&lt;br /&gt;
&lt;br /&gt;
Today, on my computer, Windows decided to assign the STM32 board to COM3.&lt;br /&gt;
&lt;br /&gt;
Next up, open PuTTY and configure it to open the right COM port. Starting from Miosix v3.00, all boards use by default a baud rate of 115200bit/s, so input 115200 in the &#039;&#039;Speed&#039;&#039; field:&lt;br /&gt;
&lt;br /&gt;
[[File:Windows-putty-configuration.png]]&lt;br /&gt;
&lt;br /&gt;
Finally, click &#039;&#039;Open&#039;&#039; and you should see the serial port messages from the microcontroller. Since the board will be already running when you connect, you can press the RESET button on the board to reboot it and see the boot logs:&lt;br /&gt;
&lt;br /&gt;
[[File:Windows-putty-serial.png]]&lt;br /&gt;
&lt;br /&gt;
= A note on uninstalling software =&lt;br /&gt;
&lt;br /&gt;
To uninstall the Miosix Toolchain, you can find the uninstaller in the start menu under &#039;&#039;Miosix Toolchain&#039;&#039;. Note that the other tools such as Git, Perl and the STLink  utility have their own uninstallers.&lt;br /&gt;
&lt;br /&gt;
[[Category:Installation and Configuration]]&lt;/div&gt;</summary>
		<author><name>Fede.tft</name></author>
	</entry>
	<entry>
		<id>https://miosix.org/wiki/index.php?title=Windows_Quick_Start&amp;diff=448</id>
		<title>Windows Quick Start</title>
		<link rel="alternate" type="text/html" href="https://miosix.org/wiki/index.php?title=Windows_Quick_Start&amp;diff=448"/>
		<updated>2026-05-10T17:05:03Z</updated>

		<summary type="html">&lt;p&gt;Fede.tft: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Installing the required software =&lt;br /&gt;
&lt;br /&gt;
== Miosix Toolchain ==&lt;br /&gt;
&lt;br /&gt;
To be able to compile the Miosix kernel and your application, you need a patched version of the GCC compiler called Miosix toolchain, you can find the link to download it [[Miosix Toolchain|here]]. At the end of the installation you will need to reboot your computer (sorry, it&#039;s Windows...)&lt;br /&gt;
&lt;br /&gt;
== Git ==&lt;br /&gt;
&lt;br /&gt;
To download the Miosix kernel and keep it up to date, you need the [https://en.wikipedia.org/wiki/Git_%28software%29 git] version control system.&lt;br /&gt;
&lt;br /&gt;
It is recommended to install it from [http://www.git-scm.com/download/win git-scm.com]. Please &#039;&#039;&#039;do not&#039;&#039;&#039; uncheck the &#039;&#039;Windows Explorer integration&#039;&#039; feature during the installation, as you will need it to install the kernel sources.&lt;br /&gt;
&lt;br /&gt;
== Perl ==&lt;br /&gt;
&lt;br /&gt;
The [https://en.wikipedia.org/wiki/Perl Perl] programming language is used by the Miosix build system. Unlike on GNU/Linux computers where Perl is pre-installed, for Windows you&#039;ll need to install it separately.&lt;br /&gt;
&lt;br /&gt;
[http://strawberryperl.com Strawberry perl] is the recomended Perl version for Miosix on Windows.&lt;br /&gt;
&lt;br /&gt;
== Flashing tool ==&lt;br /&gt;
&lt;br /&gt;
With the installed Miosix toolchain you&#039;ll be able to compile the kernel, but you&#039;ll also need a way to transfer it to your microcontroller. This operation is usually called &#039;flashing&#039; the microcontroller. Miosix can work with any flashing utility that accepts as input raw binary files, and on Windows you&#039;ll usually want to install the flashing tool provided by your chip vendor.&lt;br /&gt;
&lt;br /&gt;
For STM32 chips, you can use the STLink utility available [http://www.st.com/web/en/catalog/tools/PF258168# here].&lt;br /&gt;
&lt;br /&gt;
== Text editor or IDE ==&lt;br /&gt;
&lt;br /&gt;
It is recommended to download a better text editor than Notepad, as you will need it to edit the Miosix configuration files. [http://www.notepad-plus-plus.org/ Notepad++] is a good option, but many other options exist. Just &#039;&#039;&#039;don&#039;t use Notepad&#039;&#039;&#039;, because it does not recognize Unix [https://en.wikipedia.org/wiki/Line_ending line-endings] and will show you Miosix source files as if they were composed of a single line of text.&lt;br /&gt;
&lt;br /&gt;
As an alternative to Notepad++, you may want to use an [[IDEs|IDE]].&lt;br /&gt;
&lt;br /&gt;
== Serial port viewer ==&lt;br /&gt;
&lt;br /&gt;
Miosix redirects &#039;&#039;stdin&#039;&#039;/&#039;&#039;stdout&#039;&#039; to a serial port by default on most boards, so to see the boot log and the output of &#039;&#039;printf()&#039;&#039; in your application you need a program to interact with the serial port. [https://putty.org/index.html PuTTY] is an option, although old fashioned. TODO: There are likely better options for Windows too.&lt;br /&gt;
&lt;br /&gt;
= Downloading and configuring the Miosix kernel =&lt;br /&gt;
&lt;br /&gt;
This section is a stripped down guide with the bare minimum to get you started, we also have a full guide about [[Miosix and git workflow]]. Following the tutorial in this page, your project directory will &#039;&#039;&#039;not&#039;&#039;&#039; be under version control (git). The [[Miosix and git workflow]] page shows how to create a git repository for your project and add the Miosix kernel as a git submodule.&lt;br /&gt;
&lt;br /&gt;
Before downloading the kernel, however, you first have to create &#039;&#039;&#039;a directory for your project&#039;&#039;&#039; (in this case, the hello world), and then clone the kernel &#039;&#039;&#039;as a subdirectory&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Using the Windows explorer, create a &#039;&#039;&#039;hello&#039;&#039;&#039; directory, double click on it. Then right-click on the empty directory. Select &#039;&#039;Git bash&#039;&#039; to open a git shell. This opens a shell where you can type the commands to download the kernel.&lt;br /&gt;
&lt;br /&gt;
[[File:Git-bash-windows.png]]&lt;br /&gt;
&lt;br /&gt;
Note that it is possible to paste commands in the shell (so as to avoid typing them, which can be tedious and lead to typos), but you have to do it one line of text at a time, and to paste you need to use the &#039;&#039;Shift+Ins&#039;&#039; shortcut, not the usual &#039;&#039;Ctrl+V&#039;&#039; one. The last command, &#039;&#039;exit&#039;&#039;, will close the shell.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git clone https://github.com/fedetft/miosix-kernel.git&lt;br /&gt;
exit&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that there is also a &#039;&#039;Git GUI&#039;&#039; in the right click menu, but git is best used from a command line interface, you&#039;re on your own if you choose to use git from the GUI.&lt;br /&gt;
&lt;br /&gt;
== Initializing a Miosix project ==&lt;br /&gt;
&lt;br /&gt;
For reasons explained in depth in the [[Miosix and git workflow]] page, you&#039;ll need to copy the Miosix configuration directory from the kernel sources to your project directory, as well as create a template project where you can start writing code.&lt;br /&gt;
This can be automated with a [https://en.wikipedia.org/wiki/Perl Perl] script called &#039;&#039;init_project_out_of_git_tree.pl&#039;&#039;. To run it, you need to open a Windows terminal (which is a &#039;&#039;&#039;different&#039;&#039;&#039; terminal than the git bash we used before), which can be done by &#039;&#039;Shift+Right click&#039;&#039; and selecting &#039;&#039;Open command window here&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
[[File:Open-terminal-windows.png]]&lt;br /&gt;
&lt;br /&gt;
Then, type the following command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
perl miosix-kernel/tools/init_project_out_of_git_tree.pl&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Leave the terminal open as you&#039;ll need it later.&lt;br /&gt;
&lt;br /&gt;
You should run the script from the directory where you want to initialize your empty project, such as the &#039;&#039;&#039;hello&#039;&#039;&#039; directory in this tutorial. A successful run of the script produces the following output:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Successfully created Miosix project&lt;br /&gt;
Target directory: hello&lt;br /&gt;
Kernel directory: hello/miosix-kernel/miosix&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Your project directory should now look like the following picture, with the &#039;&#039;miosix-kernel&#039;&#039; directory containing the kernel sources, the &#039;&#039;config&#039;&#039; directory with the kernel configuration, the empty &#039;&#039;main.cpp&#039;&#039; and the build files for the two alternative build systems supported by Miosix: Makefile and CMake:&lt;br /&gt;
&lt;br /&gt;
[[File:Initialized-miosix-project-windows.png]]&lt;br /&gt;
&lt;br /&gt;
For this tutorial, we&#039;ll use the Makefile build system, have a look at the [[CMake]] page to learn how to use CMake instead.&lt;br /&gt;
&lt;br /&gt;
== Configuring the kernel ==&lt;br /&gt;
&lt;br /&gt;
The minimum configuration required to compile the kernel is to &#039;&#039;&#039;select a board&#039;&#039;&#039;, as the kernel needs to build the appropriate board support package for it.&lt;br /&gt;
&lt;br /&gt;
The Miosix kernel has several other build-time configuration options, to enable optional components (filesystem, userspace processes), select algorithms such as the scheduler and trade feature support for code size, but these won&#039;t be covered here.&lt;br /&gt;
The kernel is configured by editing files in the config directory, the two most important ones are [https://github.com/fedetft/miosix-kernel/blob/master/miosix/config/Makefile.inc Makefile.inc] and [https://github.com/fedetft/miosix-kernel/blob/master/miosix/config/miosix_settings.h miosix_settings.h].&lt;br /&gt;
&lt;br /&gt;
To select a board, using Notepad++ open the first one, &#039;&#039;config/Makefile.inc&#039;&#039;. Look for the &#039;&#039;OPT_BOARD&#039;&#039; section of the file, which contains the list of boards officially supported by the kernel. In this section, all boards appear commented out (the &#039;&#039;#&#039;&#039; sign is a comment in Makefile syntax), so you need to uncomment the line corrsponding to your board. [[Porting]] the kernel to a new board is an advanced topic not covered here, so we&#039;ll assume you&#039;ll want to use an officially supported board. As an example, in this tutorial we&#039;ll use the stm32f746zg_nucleo board:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
#OPT_BOARD := stm32f469ni_stm32f469i-disco&lt;br /&gt;
OPT_BOARD := stm32f746zg_nucleo&lt;br /&gt;
#OPT_BOARD := stm32f765ii_marco_ram_board&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you do not yet have a board, you can follow along and get to the compiled firmware anyway. If you&#039;re looking for suggestions on which board to get, consider that most boards currently supported by Miosix are for STM32 microcontrollers. Here&#039;s a basic guide:&lt;br /&gt;
* &#039;&#039;&#039;Nucleo&#039;&#039;&#039; STM32 boards produced by ST are good for beginners, as they allow to power the board, flash it, debug it and access the serial port all through a single USB connection with your computer. The stm32f401re_nucleo and stm32f411re_nucleo are realtively low cost.&lt;br /&gt;
* &#039;&#039;&#039;Discovery&#039;&#039;&#039; STM32 boards are also good, but they don&#039;t include an USB to serial adapter so you&#039;ll have to buy it separately and you&#039;ll end up having to connect two USB cables, one for power/programming/debugging and one for the serial port.&lt;br /&gt;
* &#039;&#039;&#039;Third party&#039;&#039;&#039; STM32 boards such as the stm32f411ce_blackpill are cheaper and great to embed in your hardware project, but you&#039;ll have to [[https://en.wikipedia.org/wiki/Soldering solder]] the pin header yourself, and you&#039;ll need to attach a separate USB to serial adapter, and if you want in-circuit debugging you&#039;ll need an STLink adapter, so you&#039;ll end up having to run up to three separate USB cables from your computer to the board for power/programming, serial port and debugging.&lt;br /&gt;
* Venturing outside of STM32, the &#039;&#039;&#039;RP2040&#039;&#039;&#039; is a good choice. Also in this case, you&#039;ll need a separate USB to serial adapter and some soldering skills, though.&lt;br /&gt;
&lt;br /&gt;
= Writing your first Miosix program =&lt;br /&gt;
&lt;br /&gt;
== Hello world ==&lt;br /&gt;
&lt;br /&gt;
With Notepad++ open the &#039;&#039;main.cpp&#039;&#039; file with your [[IDEs | IDE]] or text editor of choice, and replace its content with the following program:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;CPP&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;cstdio&amp;gt;&lt;br /&gt;
#include &amp;lt;thread&amp;gt;&lt;br /&gt;
#include &amp;lt;miosix.h&amp;gt;&lt;br /&gt;
#include &amp;lt;interfaces/bsp.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
using namespace std;&lt;br /&gt;
using namespace miosix;&lt;br /&gt;
&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
    for(;;)&lt;br /&gt;
    {&lt;br /&gt;
        iprintf(&amp;quot;Hello world\n&amp;quot;);&lt;br /&gt;
        ledOn();&lt;br /&gt;
        this_thread::sleep_for(500ms);&lt;br /&gt;
        ledOff();&lt;br /&gt;
        this_thread::sleep_for(500ms);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
At this point, it&#039;s good to have a quick walkthrough of this hello world program. Miosix is based on a [[Fluid kernel]] architecture: in a nutshell it&#039;s kernel that supports writing applications both inside the kernel, and inside userspace programs. In this tutorial, we&#039;re using it as a unikernel. This means when power is applied to the board, the kernel will boot, and then start running the &#039;&#039;main()&#039;&#039; function you just wrote &#039;&#039;in kernelspace&#039;&#039;. This means you have both support for C/C++ standard libraries and unrestricted hardware access.&lt;br /&gt;
&lt;br /&gt;
This main() function will print &amp;quot;Hello world&amp;quot; and blink an LED approximately every second.&lt;br /&gt;
The printing is done with the &#039;&#039;iprintf()&#039;&#039; function. If you expected just &#039;&#039;printf()&#039;&#039; without the &#039;&#039;i&#039;&#039;, the reason is that Miosix uses the [https://sourceware.org/newlib/ Newlib] C standard library that provides both &#039;&#039;printf()&#039;&#039; and &#039;&#039;iprintf()&#039;&#039;, an optimized version that is smaller in code size but incapable of printing floating point numbers. So you can also use &#039;&#039;printf()&#039;&#039; if you wish, but this optimization is worth knowing from the start.&lt;br /&gt;
&lt;br /&gt;
Sleeping to blink the LED is done with the [https://en.cppreference.com/cpp/thread/sleep_for sleep_for()] function from the C++ standard library. Miosix supports other sleeping APIs, such as [https://pubs.opengroup.org/onlinepubs/9699919799/functions/nanosleep.html nanosleep()] from POSIX, or &#039;&#039;Thread::sleep()&#039;&#039;, a native Miosix function. All these functions do the same thing: they tell the scheduler to stop the currently running thread, run some other thread, and resume execution after a given time interval. Miosix is a preemptive multithreading operating system, so you should get comfortable with the fact that the code you&#039;re writing lives in a thread and shared the CPU with other threads.&lt;br /&gt;
&lt;br /&gt;
Many (but not all!) board support packages define the &#039;&#039;ledOn()&#039;&#039; and &#039;&#039;ledOff()&#039;&#039; functions to control one of the LED on the board. This should be true for all the boards that have at least one software-accessible LED. This is true for the &#039;&#039;stm32f746zg_nucleo&#039;&#039; board we selected, but if you selected a different board with no LEDs, then compiling will fail with an error related to &#039;&#039;ledOn()&#039;&#039; and &#039;&#039;ledOff()&#039;&#039;. You can comment out those two lines in this case, your hello world will only print to the serial port.&lt;br /&gt;
&lt;br /&gt;
== Compiling ==&lt;br /&gt;
&lt;br /&gt;
In the same terminal you used to run Perl, type &#039;&#039;make&#039;&#039; to build the kernel. If all goes well, the result should look like this.&lt;br /&gt;
&lt;br /&gt;
[[File:Make-output-windows.png]]&lt;br /&gt;
&lt;br /&gt;
Otherwise, compiler errors will appear in the shell. The number that appears under &#039;&#039;text&#039;&#039; in the make output is the size in bytes of your application plus the kernel. Don&#039;t worry about the 42KBytes code size, you&#039;re compiling with the default Miosix options, if you want you can play around with the options later to  [[Miosix code size optimization|reduce the code size]].&lt;br /&gt;
&lt;br /&gt;
== Flashing ==&lt;br /&gt;
&lt;br /&gt;
The procedure to flash the microcontroller board on Windows depends on the vendor-provided flashing tool. The usually provide a GUI where you can load the &#039;&#039;.bin&#039;&#039; file and then connect to the board and flash it. For Miosix the file is named main.bin if you&#039;re not using processes, or image.bin if you are using processes. For this tutorial, look for &#039;&#039;main.bin&#039;&#039; in the &#039;&#039;&#039;hello&#039;&#039;&#039; directory.&lt;br /&gt;
&lt;br /&gt;
If you correctly flashed the board, the LED will start blinking.&lt;br /&gt;
&lt;br /&gt;
== Accessing the serial port ==&lt;br /&gt;
&lt;br /&gt;
The USB to serial port adapter will appear on Windows appears as a randomly numbered COM port. To figure out the right number, you&#039;ll have to open &#039;&#039;Devices&#039;&#039; from the control panel:&lt;br /&gt;
&lt;br /&gt;
[[File:Windows-list-devices.png]]&lt;br /&gt;
&lt;br /&gt;
Today, on my computer, Windows decided to assign the STM32 board to COM3.&lt;br /&gt;
&lt;br /&gt;
Next up, open PuTTY and configure it to open the right COM port. Starting from Miosix v3.00, all boards use by default a baud rate of 115200bit/s, so input 115200 in the &#039;&#039;Speed&#039;&#039; field:&lt;br /&gt;
&lt;br /&gt;
[[File:Windows-putty-configuration.png]]&lt;br /&gt;
&lt;br /&gt;
Finally, click &#039;&#039;Open&#039;&#039; and you should see the serial port messages from the microcontroller. Since the board will be already running when you connect, you can press the RESET button on the board to reboot it and see the boot logs:&lt;br /&gt;
&lt;br /&gt;
[[File:Windows-putty-serial.png]]&lt;br /&gt;
&lt;br /&gt;
= A note on uninstalling software =&lt;br /&gt;
&lt;br /&gt;
To uninstall the Miosix Toolchain, you can find the uninstaller in the start menu under &#039;&#039;Miosix Toolchain&#039;&#039;. Note that the other tools such as Git, Perl and the STLink  utility have their own uninstallers.&lt;br /&gt;
&lt;br /&gt;
[[Category:Installation and Configuration]]&lt;/div&gt;</summary>
		<author><name>Fede.tft</name></author>
	</entry>
	<entry>
		<id>https://miosix.org/wiki/index.php?title=File:Windows-putty-serial.png&amp;diff=447</id>
		<title>File:Windows-putty-serial.png</title>
		<link rel="alternate" type="text/html" href="https://miosix.org/wiki/index.php?title=File:Windows-putty-serial.png&amp;diff=447"/>
		<updated>2026-05-10T17:04:49Z</updated>

		<summary type="html">&lt;p&gt;Fede.tft: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Windows-putty-serial&lt;/div&gt;</summary>
		<author><name>Fede.tft</name></author>
	</entry>
	<entry>
		<id>https://miosix.org/wiki/index.php?title=File:Windows-putty-configuration.png&amp;diff=446</id>
		<title>File:Windows-putty-configuration.png</title>
		<link rel="alternate" type="text/html" href="https://miosix.org/wiki/index.php?title=File:Windows-putty-configuration.png&amp;diff=446"/>
		<updated>2026-05-10T17:03:09Z</updated>

		<summary type="html">&lt;p&gt;Fede.tft: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Windows-putty-configuration&lt;/div&gt;</summary>
		<author><name>Fede.tft</name></author>
	</entry>
	<entry>
		<id>https://miosix.org/wiki/index.php?title=File:Windows-list-devices.png&amp;diff=445</id>
		<title>File:Windows-list-devices.png</title>
		<link rel="alternate" type="text/html" href="https://miosix.org/wiki/index.php?title=File:Windows-list-devices.png&amp;diff=445"/>
		<updated>2026-05-10T17:01:00Z</updated>

		<summary type="html">&lt;p&gt;Fede.tft: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Windows-list-devices&lt;/div&gt;</summary>
		<author><name>Fede.tft</name></author>
	</entry>
	<entry>
		<id>https://miosix.org/wiki/index.php?title=Windows_Quick_Start&amp;diff=444</id>
		<title>Windows Quick Start</title>
		<link rel="alternate" type="text/html" href="https://miosix.org/wiki/index.php?title=Windows_Quick_Start&amp;diff=444"/>
		<updated>2026-05-10T16:54:57Z</updated>

		<summary type="html">&lt;p&gt;Fede.tft: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Installing the required software =&lt;br /&gt;
&lt;br /&gt;
== Miosix Toolchain ==&lt;br /&gt;
&lt;br /&gt;
To be able to compile the Miosix kernel and your application, you need a patched version of the GCC compiler called Miosix toolchain, you can find the link to download it [[Miosix Toolchain|here]]. At the end of the installation you will need to reboot your computer (sorry, it&#039;s Windows...)&lt;br /&gt;
&lt;br /&gt;
== Git ==&lt;br /&gt;
&lt;br /&gt;
To download the Miosix kernel and keep it up to date, you need the [https://en.wikipedia.org/wiki/Git_%28software%29 git] version control system.&lt;br /&gt;
&lt;br /&gt;
It is recommended to install it from [http://www.git-scm.com/download/win git-scm.com]. Please &#039;&#039;&#039;do not&#039;&#039;&#039; uncheck the &#039;&#039;Windows Explorer integration&#039;&#039; feature during the installation, as you will need it to install the kernel sources.&lt;br /&gt;
&lt;br /&gt;
== Perl ==&lt;br /&gt;
&lt;br /&gt;
The [https://en.wikipedia.org/wiki/Perl Perl] programming language is used by the Miosix build system. Unlike on GNU/Linux computers where Perl is pre-installed, for Windows you&#039;ll need to install it separately.&lt;br /&gt;
&lt;br /&gt;
[http://strawberryperl.com Strawberry perl] is the recomended Perl version for Miosix on Windows.&lt;br /&gt;
&lt;br /&gt;
== Flashing tool ==&lt;br /&gt;
&lt;br /&gt;
With the installed Miosix toolchain you&#039;ll be able to compile the kernel, but you&#039;ll also need a way to transfer it to your microcontroller. This operation is usually called &#039;flashing&#039; the microcontroller. Miosix can work with any flashing utility that accepts as input raw binary files, and on Windows you&#039;ll usually want to install the flashing tool provided by your chip vendor.&lt;br /&gt;
&lt;br /&gt;
For STM32 chips, you can use the STLink utility available [http://www.st.com/web/en/catalog/tools/PF258168# here].&lt;br /&gt;
&lt;br /&gt;
== Text editor or IDE ==&lt;br /&gt;
&lt;br /&gt;
It is recommended to download a better text editor than Notepad, as you will need it to edit the Miosix configuration files. [http://www.notepad-plus-plus.org/ Notepad++] is a good option, but many other options exist. Just &#039;&#039;&#039;don&#039;t use Notepad&#039;&#039;&#039;, because it does not recognize Unix [https://en.wikipedia.org/wiki/Line_ending line-endings] and will show you Miosix source files as if they were composed of a single line of text.&lt;br /&gt;
&lt;br /&gt;
As an alternative to Notepad++, you may want to use an [[IDEs|IDE]].&lt;br /&gt;
&lt;br /&gt;
== Serial port viewer ==&lt;br /&gt;
&lt;br /&gt;
Miosix redirects &#039;&#039;stdin&#039;&#039;/&#039;&#039;stdout&#039;&#039; to a serial port by default on most boards, so to see the boot log and the output of &#039;&#039;printf()&#039;&#039; in your application you need a program to interact with the serial port. [https://putty.org/index.html PuTTY] is an option, although old fashioned. TODO: There are likely better options for Windows too.&lt;br /&gt;
&lt;br /&gt;
= Downloading and configuring the Miosix kernel =&lt;br /&gt;
&lt;br /&gt;
This section is a stripped down guide with the bare minimum to get you started, we also have a full guide about [[Miosix and git workflow]]. Following the tutorial in this page, your project directory will &#039;&#039;&#039;not&#039;&#039;&#039; be under version control (git). The [[Miosix and git workflow]] page shows how to create a git repository for your project and add the Miosix kernel as a git submodule.&lt;br /&gt;
&lt;br /&gt;
Before downloading the kernel, however, you first have to create &#039;&#039;&#039;a directory for your project&#039;&#039;&#039; (in this case, the hello world), and then clone the kernel &#039;&#039;&#039;as a subdirectory&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Using the Windows explorer, create a &#039;&#039;&#039;hello&#039;&#039;&#039; directory, double click on it. Then right-click on the empty directory. Select &#039;&#039;Git bash&#039;&#039; to open a git shell. This opens a shell where you can type the commands to download the kernel.&lt;br /&gt;
&lt;br /&gt;
[[File:Git-bash-windows.png]]&lt;br /&gt;
&lt;br /&gt;
Note that it is possible to paste commands in the shell (so as to avoid typing them, which can be tedious and lead to typos), but you have to do it one line of text at a time, and to paste you need to use the &#039;&#039;Shift+Ins&#039;&#039; shortcut, not the usual &#039;&#039;Ctrl+V&#039;&#039; one. The last command, &#039;&#039;exit&#039;&#039;, will close the shell.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git clone https://github.com/fedetft/miosix-kernel.git&lt;br /&gt;
exit&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that there is also a &#039;&#039;Git GUI&#039;&#039; in the right click menu, but git is best used from a command line interface, you&#039;re on your own if you choose to use git from the GUI.&lt;br /&gt;
&lt;br /&gt;
== Initializing a Miosix project ==&lt;br /&gt;
&lt;br /&gt;
For reasons explained in depth in the [[Miosix and git workflow]] page, you&#039;ll need to copy the Miosix configuration directory from the kernel sources to your project directory, as well as create a template project where you can start writing code.&lt;br /&gt;
This can be automated with a [https://en.wikipedia.org/wiki/Perl Perl] script called &#039;&#039;init_project_out_of_git_tree.pl&#039;&#039;. To run it, you need to open a Windows terminal (which is a &#039;&#039;&#039;different&#039;&#039;&#039; terminal than the git bash we used before), which can be done by &#039;&#039;Shift+Right click&#039;&#039; and selecting &#039;&#039;Open command window here&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
[[File:Open-terminal-windows.png]]&lt;br /&gt;
&lt;br /&gt;
Then, type the following command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
perl miosix-kernel/tools/init_project_out_of_git_tree.pl&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Leave the terminal open as you&#039;ll need it later.&lt;br /&gt;
&lt;br /&gt;
You should run the script from the directory where you want to initialize your empty project, such as the &#039;&#039;&#039;hello&#039;&#039;&#039; directory in this tutorial. A successful run of the script produces the following output:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Successfully created Miosix project&lt;br /&gt;
Target directory: hello&lt;br /&gt;
Kernel directory: hello/miosix-kernel/miosix&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Your project directory should now look like the following picture, with the &#039;&#039;miosix-kernel&#039;&#039; directory containing the kernel sources, the &#039;&#039;config&#039;&#039; directory with the kernel configuration, the empty &#039;&#039;main.cpp&#039;&#039; and the build files for the two alternative build systems supported by Miosix: Makefile and CMake:&lt;br /&gt;
&lt;br /&gt;
[[File:Initialized-miosix-project-windows.png]]&lt;br /&gt;
&lt;br /&gt;
For this tutorial, we&#039;ll use the Makefile build system, have a look at the [[CMake]] page to learn how to use CMake instead.&lt;br /&gt;
&lt;br /&gt;
== Configuring the kernel ==&lt;br /&gt;
&lt;br /&gt;
The minimum configuration required to compile the kernel is to &#039;&#039;&#039;select a board&#039;&#039;&#039;, as the kernel needs to build the appropriate board support package for it.&lt;br /&gt;
&lt;br /&gt;
The Miosix kernel has several other build-time configuration options, to enable optional components (filesystem, userspace processes), select algorithms such as the scheduler and trade feature support for code size, but these won&#039;t be covered here.&lt;br /&gt;
The kernel is configured by editing files in the config directory, the two most important ones are [https://github.com/fedetft/miosix-kernel/blob/master/miosix/config/Makefile.inc Makefile.inc] and [https://github.com/fedetft/miosix-kernel/blob/master/miosix/config/miosix_settings.h miosix_settings.h].&lt;br /&gt;
&lt;br /&gt;
To select a board, using Notepad++ open the first one, &#039;&#039;config/Makefile.inc&#039;&#039;. Look for the &#039;&#039;OPT_BOARD&#039;&#039; section of the file, which contains the list of boards officially supported by the kernel. In this section, all boards appear commented out (the &#039;&#039;#&#039;&#039; sign is a comment in Makefile syntax), so you need to uncomment the line corrsponding to your board. [[Porting]] the kernel to a new board is an advanced topic not covered here, so we&#039;ll assume you&#039;ll want to use an officially supported board. As an example, in this tutorial we&#039;ll use the stm32f746zg_nucleo board:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
#OPT_BOARD := stm32f469ni_stm32f469i-disco&lt;br /&gt;
OPT_BOARD := stm32f746zg_nucleo&lt;br /&gt;
#OPT_BOARD := stm32f765ii_marco_ram_board&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you do not yet have a board, you can follow along and get to the compiled firmware anyway. If you&#039;re looking for suggestions on which board to get, consider that most boards currently supported by Miosix are for STM32 microcontrollers. Here&#039;s a basic guide:&lt;br /&gt;
* &#039;&#039;&#039;Nucleo&#039;&#039;&#039; STM32 boards produced by ST are good for beginners, as they allow to power the board, flash it, debug it and access the serial port all through a single USB connection with your computer. The stm32f401re_nucleo and stm32f411re_nucleo are realtively low cost.&lt;br /&gt;
* &#039;&#039;&#039;Discovery&#039;&#039;&#039; STM32 boards are also good, but they don&#039;t include an USB to serial adapter so you&#039;ll have to buy it separately and you&#039;ll end up having to connect two USB cables, one for power/programming/debugging and one for the serial port.&lt;br /&gt;
* &#039;&#039;&#039;Third party&#039;&#039;&#039; STM32 boards such as the stm32f411ce_blackpill are cheaper and great to embed in your hardware project, but you&#039;ll have to [[https://en.wikipedia.org/wiki/Soldering solder]] the pin header yourself, and you&#039;ll need to attach a separate USB to serial adapter, and if you want in-circuit debugging you&#039;ll need an STLink adapter, so you&#039;ll end up having to run up to three separate USB cables from your computer to the board for power/programming, serial port and debugging.&lt;br /&gt;
* Venturing outside of STM32, the &#039;&#039;&#039;RP2040&#039;&#039;&#039; is a good choice. Also in this case, you&#039;ll need a separate USB to serial adapter and some soldering skills, though.&lt;br /&gt;
&lt;br /&gt;
= Writing your first Miosix program =&lt;br /&gt;
&lt;br /&gt;
== Hello world ==&lt;br /&gt;
&lt;br /&gt;
With Notepad++ open the &#039;&#039;main.cpp&#039;&#039; file with your [[IDEs | IDE]] or text editor of choice, and replace its content with the following program:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;CPP&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;cstdio&amp;gt;&lt;br /&gt;
#include &amp;lt;thread&amp;gt;&lt;br /&gt;
#include &amp;lt;miosix.h&amp;gt;&lt;br /&gt;
#include &amp;lt;interfaces/bsp.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
using namespace std;&lt;br /&gt;
using namespace miosix;&lt;br /&gt;
&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
    for(;;)&lt;br /&gt;
    {&lt;br /&gt;
        iprintf(&amp;quot;Hello world\n&amp;quot;);&lt;br /&gt;
        ledOn();&lt;br /&gt;
        this_thread::sleep_for(500ms);&lt;br /&gt;
        ledOff();&lt;br /&gt;
        this_thread::sleep_for(500ms);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
At this point, it&#039;s good to have a quick walkthrough of this hello world program. Miosix is based on a [[Fluid kernel]] architecture: in a nutshell it&#039;s kernel that supports writing applications both inside the kernel, and inside userspace programs. In this tutorial, we&#039;re using it as a unikernel. This means when power is applied to the board, the kernel will boot, and then start running the &#039;&#039;main()&#039;&#039; function you just wrote &#039;&#039;in kernelspace&#039;&#039;. This means you have both support for C/C++ standard libraries and unrestricted hardware access.&lt;br /&gt;
&lt;br /&gt;
This main() function will print &amp;quot;Hello world&amp;quot; and blink an LED approximately every second.&lt;br /&gt;
The printing is done with the &#039;&#039;iprintf()&#039;&#039; function. If you expected just &#039;&#039;printf()&#039;&#039; without the &#039;&#039;i&#039;&#039;, the reason is that Miosix uses the [https://sourceware.org/newlib/ Newlib] C standard library that provides both &#039;&#039;printf()&#039;&#039; and &#039;&#039;iprintf()&#039;&#039;, an optimized version that is smaller in code size but incapable of printing floating point numbers. So you can also use &#039;&#039;printf()&#039;&#039; if you wish, but this optimization is worth knowing from the start.&lt;br /&gt;
&lt;br /&gt;
Sleeping to blink the LED is done with the [https://en.cppreference.com/cpp/thread/sleep_for sleep_for()] function from the C++ standard library. Miosix supports other sleeping APIs, such as [https://pubs.opengroup.org/onlinepubs/9699919799/functions/nanosleep.html nanosleep()] from POSIX, or &#039;&#039;Thread::sleep()&#039;&#039;, a native Miosix function. All these functions do the same thing: they tell the scheduler to stop the currently running thread, run some other thread, and resume execution after a given time interval. Miosix is a preemptive multithreading operating system, so you should get comfortable with the fact that the code you&#039;re writing lives in a thread and shared the CPU with other threads.&lt;br /&gt;
&lt;br /&gt;
Many (but not all!) board support packages define the &#039;&#039;ledOn()&#039;&#039; and &#039;&#039;ledOff()&#039;&#039; functions to control one of the LED on the board. This should be true for all the boards that have at least one software-accessible LED. This is true for the &#039;&#039;stm32f746zg_nucleo&#039;&#039; board we selected, but if you selected a different board with no LEDs, then compiling will fail with an error related to &#039;&#039;ledOn()&#039;&#039; and &#039;&#039;ledOff()&#039;&#039;. You can comment out those two lines in this case, your hello world will only print to the serial port.&lt;br /&gt;
&lt;br /&gt;
== Compiling ==&lt;br /&gt;
&lt;br /&gt;
In the same terminal you used to run Perl, type &#039;&#039;make&#039;&#039; to build the kernel. If all goes well, the result should look like this.&lt;br /&gt;
&lt;br /&gt;
[[File:Make-output-windows.png]]&lt;br /&gt;
&lt;br /&gt;
Otherwise, compiler errors will appear in the shell. The number that appears under &#039;&#039;text&#039;&#039; in the make output is the size in bytes of your application plus the kernel. Don&#039;t worry about the 42KBytes code size, you&#039;re compiling with the default Miosix options, if you want you can play around with the options later to  [[Miosix code size optimization|reduce the code size]].&lt;br /&gt;
&lt;br /&gt;
== Flashing ==&lt;br /&gt;
&lt;br /&gt;
There are two ways to program the stm32f4discovery board. One is to use QSTLink2 directly from the terminal you already have open by typing &#039;make program&#039; (connect the USB cable first!), the other is through QSTLink2&#039;s GUI. You can find QSTLink2 in the start menu&lt;br /&gt;
&lt;br /&gt;
[[File:Qstlink2startmenuwindows.png]]&lt;br /&gt;
&lt;br /&gt;
Once you start it, you have to click on &#039;&#039;Connect&#039;&#039;, and it should find your &#039;&#039;stm32f4discovery&#039;&#039; board. After that, click on &#039;&#039;Send&#039;&#039; and select the &#039;&#039;main.bin&#039;&#039; file in the Miosix top-level directory.&lt;br /&gt;
&lt;br /&gt;
[[File:Qstlink2flashingwindows.png]]&lt;br /&gt;
&lt;br /&gt;
Note that, regardless of using QSTLink2 form the terminal or the GUI, there is a bug that in some circumstances blocks the microcontroller until the next powercycle. Therefore, after having programmed the microcontroller, it is recomended to unplug and reconnect the USB cable to powercycle the &#039;&#039;stm32f4discovery&#039;&#039; board. At that point, you shuold see the red LED blinking.&lt;br /&gt;
&lt;br /&gt;
= A note on uninstalling software =&lt;br /&gt;
&lt;br /&gt;
To uninstall the Miosix Toolchain, you can find the uninstaller in the start menu under &#039;&#039;Miosix Toolchain&#039;&#039;. Note that the other tools such as Git, Perl and the STLink  utility have their own uninstallers.&lt;br /&gt;
&lt;br /&gt;
[[Category:Installation and Configuration]]&lt;/div&gt;</summary>
		<author><name>Fede.tft</name></author>
	</entry>
</feed>