<?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=Daniele.cattaneo</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=Daniele.cattaneo"/>
	<link rel="alternate" type="text/html" href="https://miosix.org/wiki/index.php?title=Special:Contributions/Daniele.cattaneo"/>
	<updated>2026-04-14T23:07:25Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.43.3</generator>
	<entry>
		<id>https://miosix.org/wiki/index.php?title=Adding_support_for_a_new_STM32_board_in_Miosix&amp;diff=390</id>
		<title>Adding support for a new STM32 board in Miosix</title>
		<link rel="alternate" type="text/html" href="https://miosix.org/wiki/index.php?title=Adding_support_for_a_new_STM32_board_in_Miosix&amp;diff=390"/>
		<updated>2026-04-09T17:04:58Z</updated>

		<summary type="html">&lt;p&gt;Daniele.cattaneo: Outline what is yet to be written&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Miosix&#039;s main target platform is, naturally, STM32 microcontrollers by ST Microelectronics, in part for historical reasons, but mainly because STM32 chips (and their clones) are extremely popular for both the industry and hobbyists.&lt;br /&gt;
&lt;br /&gt;
However, the success of the STM32 line has spawned an abundance of different chips, all with different sets of built-in peripherals, Flash sizes, Ram sizes, CPU cores, and so on. Fortunately, most STM32 chips are similar enough that it is usually easy to port a new STM32 board to Miosix.&lt;br /&gt;
&lt;br /&gt;
== Components of a Miosix port ==&lt;br /&gt;
&lt;br /&gt;
The core of the Miosix kernel is platform-independent. The contact point between the platform-independent part of Miosix and the platform-dependent parts consist in a set of &#039;&#039;&#039;interfaces&#039;&#039;&#039; that need to be fully implemented for a board to function.&lt;br /&gt;
&lt;br /&gt;
The header files that define these interfaces are in the miosix/interfaces and miosix/interfaces_private directories. The implementations are in the arch directory, split by board, chip and cpu.&lt;br /&gt;
&lt;br /&gt;
The Miosix build system makes sure that the correct board/chip/cpu-specific header files and source code files for the selected board are used during the compilation.&lt;br /&gt;
&lt;br /&gt;
A port of Miosix to a new board needs to provide the files required for the missing interfaces implementations.&lt;br /&gt;
&lt;br /&gt;
=== Miosix interfaces ===&lt;br /&gt;
&lt;br /&gt;
Miosix&#039;s interfaces are usually implemented either at CPU level, at chip level, or board level, depending on the case.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot;&lt;br /&gt;
|+ Caption text&lt;br /&gt;
|-&lt;br /&gt;
! Header !! Typical Implementation !! Private !! Description&lt;br /&gt;
|-&lt;br /&gt;
| interfaces/arch_registers.h || arch/board/&amp;lt;board_name&amp;gt;/interfaces-impl/arch_registers_impl.h || No || Register definitions for the chip.&lt;br /&gt;
|-&lt;br /&gt;
| interfaces/atomic_ops.h || arch/cpu/&amp;lt;cpu_name&amp;gt;/interfaces-impl/atomics_ops_impl.h || No || Implementation of atomic primitives&lt;br /&gt;
|-&lt;br /&gt;
| interfaces/bsp.h, interfaces_private/bsp_private.h || arch/board/&amp;lt;board_name&amp;gt;/interfaces-impl/{bsp_impl.h,bsp.cpp} || In part || Board Support Package: configuration of the board at boot, board reboot and shutdown&lt;br /&gt;
|-&lt;br /&gt;
| interfaces/cpu_const.h || arch/cpu/&amp;lt;cpu_name&amp;gt;/interfaces-impl/cpu_const_[smp_]impl.h || No || Low-level CPU architecture parameters, such as the number of CPU cores, configurables regarding the behavior during context switches, and so on. (SMP file only for SMP platforms)&lt;br /&gt;
|-&lt;br /&gt;
| interfaces/delays.h || arch/chip/&amp;lt;chip_name&amp;gt;/interfaces-impl/delays.cpp || No || Low-level delays implemented by CPU spinning (no timers allowed, used early at boot)&lt;br /&gt;
|-&lt;br /&gt;
| interfaces/endianness.h || arch/cpu/&amp;lt;cpu_name&amp;gt;/interfaces-impl/endianness_impl.h || No || Optimized implementation of byte-swapping primitives, for big endian support&lt;br /&gt;
|-&lt;br /&gt;
| interfaces/gpio.h || arch/chip/&amp;lt;chip_name&amp;gt;/interfaces-impl/gpio_impl.h || No || Gpio class implementation for this chip. Usually just includes one of the Gpio drivers in arch/drivers/gpio.&lt;br /&gt;
|-&lt;br /&gt;
| interfaces/interrupts.h || arch/cpu/&amp;lt;cpu_name&amp;gt;/interfaces-impl/interrupts_impl.h || No || Implementation of primitives for enabling or disabling interrupts, and for registering IRQ vectors.&lt;br /&gt;
|-&lt;br /&gt;
| interfaces/poweroff.h || arch/chip/&amp;lt;chip_name&amp;gt;/interfaces-impl/poweroff.cpp || No || Chip reboot and shutdown&lt;br /&gt;
|-&lt;br /&gt;
| interfaces_private/cpu.h || arch/cpu/&amp;lt;cpu_name&amp;gt;/interfaces-impl/{cpu_impl.h,cpu.cpp} || Yes || Context switching primitives&lt;br /&gt;
|-&lt;br /&gt;
| interfaces_private/os_timer.h || arch/drivers/os_timer/... || Yes || Timer driver for context switches and general kernel timekeeping&lt;br /&gt;
|-&lt;br /&gt;
| interfaces_private/sleep.h || arch/drivers/sleep/... || Yes || CPU sleep and deep sleep (deep sleep is implemented in arch/chip or arch/board)&lt;br /&gt;
|-&lt;br /&gt;
| interfaces_private/smp_locks.h || arch/chip/&amp;lt;chip_name&amp;gt;/interfaces-impl/smp_locks_impl.h || Yes || Implementation of spinlocks (SMP platforms only)&lt;br /&gt;
|-&lt;br /&gt;
| interfaces_private/smp.h || arch/chip/&amp;lt;chip_name&amp;gt;/interfaces-impl/smp.cpp || Yes || Initialization of other CPU cores and SMP primitives (SMP platforms only)&lt;br /&gt;
|-&lt;br /&gt;
| interfaces_private/userspace.h || arch/cpu/&amp;lt;cpu_name&amp;gt;/interfaces-impl/userspace_impl.h || Yes || Implementation of memory protection primitives&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
TODO:&lt;br /&gt;
* what to copy past and from where, new chip vs old chip vs new chip that is similar to old&lt;br /&gt;
* makefiles/cmake&lt;br /&gt;
For new chips:&lt;br /&gt;
* clock configuration code &amp;amp; PLL&lt;br /&gt;
* os_timer&lt;br /&gt;
* gpio (sometimes)&lt;br /&gt;
* serial port configuration&lt;br /&gt;
For new boards:&lt;br /&gt;
* BSP init&lt;br /&gt;
* arch_registers (to be moved!!!)&lt;br /&gt;
extras:&lt;br /&gt;
* sdmmc&lt;/div&gt;</summary>
		<author><name>Daniele.cattaneo</name></author>
	</entry>
	<entry>
		<id>https://miosix.org/wiki/index.php?title=Adding_support_for_a_new_STM32_board_in_Miosix&amp;diff=389</id>
		<title>Adding support for a new STM32 board in Miosix</title>
		<link rel="alternate" type="text/html" href="https://miosix.org/wiki/index.php?title=Adding_support_for_a_new_STM32_board_in_Miosix&amp;diff=389"/>
		<updated>2026-04-09T16:58:35Z</updated>

		<summary type="html">&lt;p&gt;Daniele.cattaneo: Start writing a porting guide&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Miosix&#039;s main target platform is, naturally, STM32 microcontrollers by ST Microelectronics, in part for historical reasons, but mainly because STM32 chips (and their clones) are extremely popular for both the industry and hobbyists.&lt;br /&gt;
&lt;br /&gt;
However, the success of the STM32 line has spawned an abundance of different chips, all with different sets of built-in peripherals, Flash sizes, Ram sizes, CPU cores, and so on. Fortunately, most STM32 chips are similar enough that it is usually easy to port a new STM32 board to Miosix.&lt;br /&gt;
&lt;br /&gt;
== Components of a Miosix port ==&lt;br /&gt;
&lt;br /&gt;
The core of the Miosix kernel is platform-independent. The contact point between the platform-independent part of Miosix and the platform-dependent parts consist in a set of &#039;&#039;&#039;interfaces&#039;&#039;&#039; that need to be fully implemented for a board to function.&lt;br /&gt;
&lt;br /&gt;
The header files that define these interfaces are in the miosix/interfaces and miosix/interfaces_private directories. The implementations are in the arch directory, split by board, chip and cpu.&lt;br /&gt;
&lt;br /&gt;
The Miosix build system makes sure that the correct board/chip/cpu-specific header files and source code files for the selected board are used during the compilation.&lt;br /&gt;
&lt;br /&gt;
A port of Miosix to a new board needs to provide the files required for the missing interfaces implementations.&lt;br /&gt;
&lt;br /&gt;
=== Miosix interfaces ===&lt;br /&gt;
&lt;br /&gt;
Miosix&#039;s interfaces are usually implemented either at CPU level, at chip level, or board level, depending on the case.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot;&lt;br /&gt;
|+ Caption text&lt;br /&gt;
|-&lt;br /&gt;
! Header !! Typical Implementation !! Private !! Description&lt;br /&gt;
|-&lt;br /&gt;
| interfaces/arch_registers.h || arch/board/&amp;lt;board_name&amp;gt;/interfaces-impl/arch_registers_impl.h || No || Register definitions for the chip.&lt;br /&gt;
|-&lt;br /&gt;
| interfaces/atomic_ops.h || arch/cpu/&amp;lt;cpu_name&amp;gt;/interfaces-impl/atomics_ops_impl.h || No || Implementation of atomic primitives&lt;br /&gt;
|-&lt;br /&gt;
| interfaces/bsp.h, interfaces_private/bsp_private.h || arch/board/&amp;lt;board_name&amp;gt;/interfaces-impl/{bsp_impl.h,bsp.cpp} || In part || Board Support Package: configuration of the board at boot, board reboot and shutdown&lt;br /&gt;
|-&lt;br /&gt;
| interfaces/cpu_const.h || arch/cpu/&amp;lt;cpu_name&amp;gt;/interfaces-impl/cpu_const_[smp_]impl.h || No || Low-level CPU architecture parameters, such as the number of CPU cores, configurables regarding the behavior during context switches, and so on. (SMP file only for SMP platforms)&lt;br /&gt;
|-&lt;br /&gt;
| interfaces/delays.h || arch/chip/&amp;lt;chip_name&amp;gt;/interfaces-impl/delays.cpp || No || Low-level delays implemented by CPU spinning (no timers allowed, used early at boot)&lt;br /&gt;
|-&lt;br /&gt;
| interfaces/endianness.h || arch/cpu/&amp;lt;cpu_name&amp;gt;/interfaces-impl/endianness_impl.h || No || Optimized implementation of byte-swapping primitives, for big endian support&lt;br /&gt;
|-&lt;br /&gt;
| interfaces/gpio.h || arch/chip/&amp;lt;chip_name&amp;gt;/interfaces-impl/gpio_impl.h || No || Gpio class implementation for this chip. Usually just includes one of the Gpio drivers in arch/drivers/gpio.&lt;br /&gt;
|-&lt;br /&gt;
| interfaces/interrupts.h || arch/cpu/&amp;lt;cpu_name&amp;gt;/interfaces-impl/interrupts_impl.h || No || Implementation of primitives for enabling or disabling interrupts, and for registering IRQ vectors.&lt;br /&gt;
|-&lt;br /&gt;
| interfaces/poweroff.h || arch/chip/&amp;lt;chip_name&amp;gt;/interfaces-impl/poweroff.cpp || No || Chip reboot and shutdown&lt;br /&gt;
|-&lt;br /&gt;
| interfaces_private/cpu.h || arch/cpu/&amp;lt;cpu_name&amp;gt;/interfaces-impl/{cpu_impl.h,cpu.cpp} || Yes || Context switching primitives&lt;br /&gt;
|-&lt;br /&gt;
| interfaces_private/os_timer.h || arch/drivers/os_timer/... || Yes || Timer driver for context switches and general kernel timekeeping&lt;br /&gt;
|-&lt;br /&gt;
| interfaces_private/sleep.h || arch/drivers/sleep/... || Yes || CPU sleep and deep sleep (deep sleep is implemented in arch/chip or arch/board)&lt;br /&gt;
|-&lt;br /&gt;
| interfaces_private/smp_locks.h || arch/chip/&amp;lt;chip_name&amp;gt;/interfaces-impl/smp_locks_impl.h || Yes || Implementation of spinlocks (SMP platforms only)&lt;br /&gt;
|-&lt;br /&gt;
| interfaces_private/smp.h || arch/chip/&amp;lt;chip_name&amp;gt;/interfaces-impl/smp.cpp || Yes || Initialization of other CPU cores and SMP primitives (SMP platforms only)&lt;br /&gt;
|-&lt;br /&gt;
| interfaces_private/userspace.h || arch/cpu/&amp;lt;cpu_name&amp;gt;/interfaces-impl/userspace_impl.h || Yes || Implementation of memory protection primitives&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Daniele.cattaneo</name></author>
	</entry>
	<entry>
		<id>https://miosix.org/wiki/index.php?title=User:Daniele.cattaneo&amp;diff=388</id>
		<title>User:Daniele.cattaneo</title>
		<link rel="alternate" type="text/html" href="https://miosix.org/wiki/index.php?title=User:Daniele.cattaneo&amp;diff=388"/>
		<updated>2026-04-09T15:54:37Z</updated>

		<summary type="html">&lt;p&gt;Daniele.cattaneo: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Hi :)&lt;br /&gt;
&lt;br /&gt;
Github (work): [https://github.com/danielecattaneo]&lt;br /&gt;
&lt;br /&gt;
Github (personal): Secret&lt;br /&gt;
&lt;br /&gt;
MInimal Operating System with posIX&lt;br /&gt;
&lt;br /&gt;
[[Miosix in emulation]]&lt;br /&gt;
&lt;br /&gt;
[[arch directory restructuring]]&lt;br /&gt;
&lt;br /&gt;
[[Miosix 3]]&lt;br /&gt;
&lt;br /&gt;
[[Multicore]]&lt;br /&gt;
&lt;br /&gt;
[[mxgui qtsimulator on windows]]&lt;br /&gt;
&lt;br /&gt;
[[Adding support for a new STM32 board in Miosix]]&lt;/div&gt;</summary>
		<author><name>Daniele.cattaneo</name></author>
	</entry>
	<entry>
		<id>https://miosix.org/wiki/index.php?title=Linux_Debugger_configuration&amp;diff=387</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=387"/>
		<updated>2026-04-08T09:22:11Z</updated>

		<summary type="html">&lt;p&gt;Daniele.cattaneo: Use extended-remote&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-get 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 under the path &#039;miosix/arch&#039;. You must choose the proper config file for the device in use. 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/cortexM4_stm32f4/stm32f429zi_stm32f4discovery/stm32f4discovery.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]]. If you haven&#039;t already installed it&#039;s time to do it. The debugger must be launched on the ELF binary file.&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;
=== 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>Daniele.cattaneo</name></author>
	</entry>
	<entry>
		<id>https://miosix.org/wiki/index.php?title=Linux_Debugger_configuration&amp;diff=386</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=386"/>
		<updated>2026-04-08T09:12:07Z</updated>

		<summary type="html">&lt;p&gt;Daniele.cattaneo: Fix openocd link&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-get 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 under the path &#039;miosix/arch&#039;. You must choose the proper config file for the device in use. 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/cortexM4_stm32f4/stm32f429zi_stm32f4discovery/stm32f4discovery.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]]. If you haven&#039;t already installed it&#039;s time to do it. The debugger must be launched on the ELF binary file.&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 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;
=== 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>Daniele.cattaneo</name></author>
	</entry>
	<entry>
		<id>https://miosix.org/wiki/index.php?title=User:Daniele.cattaneo&amp;diff=385</id>
		<title>User:Daniele.cattaneo</title>
		<link rel="alternate" type="text/html" href="https://miosix.org/wiki/index.php?title=User:Daniele.cattaneo&amp;diff=385"/>
		<updated>2026-04-07T11:15:58Z</updated>

		<summary type="html">&lt;p&gt;Daniele.cattaneo: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Hi :)&lt;br /&gt;
&lt;br /&gt;
Github (work): [https://github.com/danielecattaneo]&lt;br /&gt;
&lt;br /&gt;
Github (personal): Secret&lt;br /&gt;
&lt;br /&gt;
MInimal Operating System with posIX&lt;br /&gt;
&lt;br /&gt;
[[Miosix in emulation]]&lt;br /&gt;
&lt;br /&gt;
[[arch directory restructuring]]&lt;br /&gt;
&lt;br /&gt;
[[Miosix 3]]&lt;br /&gt;
&lt;br /&gt;
[[Multicore]]&lt;br /&gt;
&lt;br /&gt;
[[mxgui qtsimulator on windows]]&lt;br /&gt;
&lt;br /&gt;
[[Adding support for a board in Miosix]]&lt;/div&gt;</summary>
		<author><name>Daniele.cattaneo</name></author>
	</entry>
	<entry>
		<id>https://miosix.org/wiki/index.php?title=User:Daniele.cattaneo&amp;diff=384</id>
		<title>User:Daniele.cattaneo</title>
		<link rel="alternate" type="text/html" href="https://miosix.org/wiki/index.php?title=User:Daniele.cattaneo&amp;diff=384"/>
		<updated>2026-04-01T15:12:04Z</updated>

		<summary type="html">&lt;p&gt;Daniele.cattaneo: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Hi :)&lt;br /&gt;
&lt;br /&gt;
Github (work): [https://github.com/danielecattaneo]&lt;br /&gt;
&lt;br /&gt;
Github (personal): Secret&lt;br /&gt;
&lt;br /&gt;
[[Miosix in emulation]]&lt;br /&gt;
&lt;br /&gt;
[[arch directory restructuring]]&lt;br /&gt;
&lt;br /&gt;
[[Miosix 3]]&lt;br /&gt;
&lt;br /&gt;
[[Multicore]]&lt;br /&gt;
&lt;br /&gt;
[[mxgui qtsimulator on windows]]&lt;br /&gt;
&lt;br /&gt;
[[Adding support for a board in Miosix]]&lt;/div&gt;</summary>
		<author><name>Daniele.cattaneo</name></author>
	</entry>
	<entry>
		<id>https://miosix.org/wiki/index.php?title=Mxgui_qtsimulator_on_windows&amp;diff=383</id>
		<title>Mxgui qtsimulator on windows</title>
		<link rel="alternate" type="text/html" href="https://miosix.org/wiki/index.php?title=Mxgui_qtsimulator_on_windows&amp;diff=383"/>
		<updated>2026-04-01T15:11:37Z</updated>

		<summary type="html">&lt;p&gt;Daniele.cattaneo: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;On windows, an easy way to compile the mxgui qtsimulator is to use the MSYS2 toolchain, which provides a Unix-like environment for Windows development.&lt;br /&gt;
&lt;br /&gt;
== 1. Install MSYS2 ==&lt;br /&gt;
Download the MSYS 2 toolchain by downloading the prebuilt packages from the official site https://www.msys2.org. Then, follow the instructions on the website to install it.&lt;br /&gt;
&lt;br /&gt;
=== Different toolchains in MSYS2 ===&lt;br /&gt;
&lt;br /&gt;
MSYS2 itself is just a unix-like environment running on Windows, like its predecessor Cygwin. Within this environment, MSYS2 provides multiple toolchains which target different architectures (x86_64 or ARM), use different main compilers (GCC or clang), or a different C runtime library (UCRT or mingw).&lt;br /&gt;
&lt;br /&gt;
The recommended toolchain by the MSYS2 project at the current time is &#039;&#039;&#039;UCRT64&#039;&#039;&#039;, which targets x86_64, uses the GCC compiler and the UCRT runtime. [https://learn.microsoft.com/en-us/cpp/windows/universal-crt-deployment?view=msvc-170 UCRT] is a modern C runtime for Windows, included with the OS since Windows 10, which removes the need to install the C runtime separately when distributing a program (as previously required).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;margin: 0 0; background: #e0f7e0; padding: 0 10px; border: 1px solid #c0d0c0&amp;quot;&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Trivia&#039;&#039;&#039;: Before UCRT was introduced, the previous standard C runtime for MSYS2 was mingw. However, mingw was simply a wrapper augmenting an old Microsoft C runtime (&#039;&#039;msvcrt.dll&#039;&#039;) which for binary compatibility reasons is frozen in time since the release of Windows 95&amp;lt;ref&amp;gt;https://devblogs.microsoft.com/oldnewthing/20140411-00/?p=1273&amp;lt;/ref&amp;gt;. As a result, mingw always had serious compatibility problems and bugs.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
MSYS2 adds menu items to the Start menu which launch bash shells with pre-configured paths (&#039;&#039;&#039;environments&#039;&#039;&#039;) for each one of the toolchains.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;clear: both&amp;quot;&amp;gt;&lt;br /&gt;
[[File:Msys2 toolchains.png|frame|center]]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
All of the following steps are intended to be executed using the shell opened by clicking on &#039;&#039;&#039;MSYS2 UCRT64&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
== 2. Install build tools and prerequisites ==&lt;br /&gt;
&lt;br /&gt;
Open the &#039;&#039;&#039;MSYS2 UCRT64&#039;&#039;&#039; shell and perform an upgrade:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pacman -Syuu&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Answer Yes to all prompts. If a &amp;quot;base system upgrade&amp;quot; was needed, at this point the shell will close. In this case, just open it up again.&lt;br /&gt;
&lt;br /&gt;
Install the toolchain (including gcc and binutils):&lt;br /&gt;
&amp;lt;div style=&amp;quot;margin: 0 0; background: #f7f7e0; padding: 0 10px; border: 1px solid #d0d0c0&amp;quot;&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: The &#039;&#039;mingw-w64-ucrt-x86_64&#039;&#039; prefix in the package name identifies the toolchain and &#039;&#039;usually&#039;&#039; needs to be specified for all packages. Some packages that work the same way for all toolchains are exceptions to this rule.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pacman -S mingw-w64-ucrt-x86_64-toolchain&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Install build automation tools (note that only CMake has a special version depending on the toolchain here):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pacman -S make difftools mingw-w64-ucrt-x86_64-cmake&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Install the dependencies for the simulator and the code generation tools:&lt;br /&gt;
&amp;lt;div style=&amp;quot;margin: 0 0; background: #f7f7e0; padding: 0 10px; border: 1px solid #d0d0c0&amp;quot;&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: When installing qt5 type enter to install all packages.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pacman -S mingw-w64-ucrt-x86_64-qt5 mingw-w64-ucrt-x86_64-libpng mingw-w64-ucrt-x86_64-zlib mingw-w64-ucrt-x86_64-boost&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== 3. Build the code generation tools ==&lt;br /&gt;
&lt;br /&gt;
Let us assume you already cloned mxgui&#039;s repository somewhere on your filesystem. If you haven&#039;t, do it now.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;margin: 0 0; background: #e0f7e0; padding: 0 10px; border: 1px solid #c0d0c0&amp;quot;&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Tip&#039;&#039;&#039;: For using git on Windows, we recommend the official distribution (Git for Windows: https://git-scm.com/install/windows) and TortoiseGit for shell integration and GUI support (https://tortoisegit.org).&lt;br /&gt;
&lt;br /&gt;
You can also install git inside MSYS2 by executing &amp;lt;code&amp;gt;pacman -S git&amp;lt;/code&amp;gt;. However, this installs a different and separate version of Git, which exists simultaneously and independently from Git for Windows. By default you can&#039;t use Git for Windows inside a MSYS2 shell, or MSYS2-installed git in a Windows shell.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, change directory to the mxgui repository&#039;s root.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;margin: 0 0; background: #e0f7e0; padding: 0 10px; border: 1px solid #c0d0c0&amp;quot;&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Tip&#039;&#039;&#039;: Instead of typing the path manually, you can drag the directory on the terminal window to insert the path automatically.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;div style=&amp;quot;margin: 0 0; background: #f7e0e0; padding: 0 10px; border: 1px solid #d0c0c0&amp;quot;&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Warning&#039;&#039;&#039;: MSYS2 natively accepts only Unix-style paths with forward-slashes. Windows style paths with backslashes usually don&#039;t work.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd /c/Users/me/Documents/mxgui&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Change directory to &amp;lt;code&amp;gt;_tools/code_generators&amp;lt;/code&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd _tools/code_generators&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Build the code generators with CMake.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mkdir build&lt;br /&gt;
cd build&lt;br /&gt;
cmake ..&lt;br /&gt;
make&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;div style=&amp;quot;margin: 0 0; background: #f7f7e0; padding: 0 10px; border: 1px solid #d0d0c0&amp;quot;&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: If you want to make the compilation faster by using all the CPU cores in your machine, instead of just typing &amp;lt;code&amp;gt;make&amp;lt;/code&amp;gt; type &amp;lt;code&amp;gt;make -j4&amp;lt;/code&amp;gt; where 4 stands for the number of CPU cores you have.&lt;br /&gt;
&lt;br /&gt;
Of course you can do this any time you use make to compile something, not just for this one case.&lt;br /&gt;
&lt;br /&gt;
If you don&#039;t know how many cores your CPU has, check in Task Manager.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== 4. Build the simulator ==&lt;br /&gt;
&lt;br /&gt;
Now we only need to build the simulator. Change directory to the simulator&#039;s root:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd ../../qtsimulator&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then build it like we did for the code generators:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mkdir build&lt;br /&gt;
cd build&lt;br /&gt;
cmake ..&lt;br /&gt;
make&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now you should be able to run the simulator!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./qtsimulator.exe&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;clear: both&amp;quot;&amp;gt;&lt;br /&gt;
[[File:Mxgui simulator on Windows 11.png|frame|center]]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;margin: 0 0; background: #f7e0e0; padding: 0 10px; border: 1px solid #d0c0c0&amp;quot;&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Warning&#039;&#039;&#039;: If you double-click on the &amp;lt;code&amp;gt;qtsimulator.exe&amp;lt;/code&amp;gt; executable in Windows Explorer, it probably won&#039;t work because of some missing DLLs. This is normal. The missing DLLs are located in &amp;lt;code&amp;gt;C:\msys64\ucrt64\bin&amp;lt;/code&amp;gt;, a directory that the MSYS2 shell configuration adds to the PATH variable automatically, but is not normally included in PATH.&lt;br /&gt;
&lt;br /&gt;
To make the simulator executable work when double-clicked, first check all the required DLLs by executing &amp;lt;code&amp;gt;lld qtsimulator.exe&amp;lt;/code&amp;gt; in the MSYS2 shell, and then copy the DLLs located in &amp;lt;code&amp;gt;C:\msys64\ucrt64\bin&amp;lt;/code&amp;gt; to the same directory as &amp;lt;code&amp;gt;qtsimulator.exe&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
However, unless you want to distribute the compiled simulator, it&#039;s much simpler to just always run it from inside an MSYS2 UCRT64 terminal window.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;/div&gt;</summary>
		<author><name>Daniele.cattaneo</name></author>
	</entry>
	<entry>
		<id>https://miosix.org/wiki/index.php?title=Mxgui_qtsimulator_on_windows&amp;diff=382</id>
		<title>Mxgui qtsimulator on windows</title>
		<link rel="alternate" type="text/html" href="https://miosix.org/wiki/index.php?title=Mxgui_qtsimulator_on_windows&amp;diff=382"/>
		<updated>2026-03-26T18:22:02Z</updated>

		<summary type="html">&lt;p&gt;Daniele.cattaneo: Page created&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;On windows, an easy way to compile the mxgui qtsimulator is to use the MSYS2 toolchain, which provides a Unix-like environment for Windows development.&lt;br /&gt;
&lt;br /&gt;
== 1. Install MSYS2 ==&lt;br /&gt;
Download the MSYS 2 toolchain by downloading the prebuilt packages from the official site https://www.msys2.org. Then, follow the instructions on the website to install it.&lt;br /&gt;
&lt;br /&gt;
=== Different toolchains in MSYS2 ===&lt;br /&gt;
&lt;br /&gt;
MSYS2 itself is just a unix-like environment running on Windows, like its predecessor Cygwin. Within this environment, MSYS2 provides multiple toolchains which target different architectures (x86_64 or ARM), use different main compilers (GCC or clang), or a different C runtime library (UCRT or mingw).&lt;br /&gt;
&lt;br /&gt;
The recommended toolchain by the MSYS2 project at the current time is &#039;&#039;&#039;UCRT64&#039;&#039;&#039;, which targets x86_64, uses the GCC compiler and the UCRT runtime. [https://learn.microsoft.com/en-us/cpp/windows/universal-crt-deployment?view=msvc-170 UCRT] is a modern C runtime for Windows, included with the OS since Windows 10, which removes the need to install the C runtime separately when distributing a program (as previously required).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;margin: 0 0; background: #e0f7e0; padding: 0 10px; border: 1px solid #c0d0c0&amp;quot;&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Trivia&#039;&#039;&#039;: Before UCRT was introduced, the previous standard C runtime for MSYS2 was mingw. However, mingw was simply a wrapper augmenting an old Microsoft C runtime (&#039;&#039;msvcrt.dll&#039;&#039;) which for binary compatibility reasons is frozen in time since the release of Windows 95&amp;lt;ref&amp;gt;https://devblogs.microsoft.com/oldnewthing/20140411-00/?p=1273&amp;lt;/ref&amp;gt;. As a result, mingw always had serious compatibility problems and bugs.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
MSYS2 adds menu items to the Start menu which launch bash shells with pre-configured paths (&#039;&#039;&#039;environments&#039;&#039;&#039;) for each one of the toolchains.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;clear: both&amp;quot;&amp;gt;&lt;br /&gt;
[[File:Msys2 toolchains.png|frame|center]]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
All of the following steps are intended to be executed using the shell opened by clicking on &#039;&#039;&#039;MSYS2 UCRT64&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
== 2. Install build tools and prerequisites ==&lt;br /&gt;
&lt;br /&gt;
Open the &#039;&#039;&#039;MSYS2 UCRT64&#039;&#039;&#039; shell and perform an upgrade:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pacman -Syuu&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Answer Yes to all prompts. If a &amp;quot;base system upgrade&amp;quot; was needed, at this point the shell will close. In this case, just open it up again.&lt;br /&gt;
&lt;br /&gt;
Install the toolchain (including gcc and binutils):&lt;br /&gt;
&amp;lt;div style=&amp;quot;margin: 0 0; background: #f7f7e0; padding: 0 10px; border: 1px solid #d0d0c0&amp;quot;&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: The &#039;&#039;mingw-w64-ucrt-x86_64&#039;&#039; prefix in the package name identifies the toolchain and &#039;&#039;usually&#039;&#039; needs to be specified for all packages. Some packages that work the same way for all toolchains are exceptions to this rule.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pacman -S mingw-w64-ucrt-x86_64-toolchain&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Install build automation tools (note that only CMake has a special version depending on the toolchain here):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pacman -S make difftools mingw-w64-ucrt-x86_64-cmake&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Install the dependencies for the simulator and the code generation tools:&lt;br /&gt;
&amp;lt;div style=&amp;quot;margin: 0 0; background: #f7f7e0; padding: 0 10px; border: 1px solid #d0d0c0&amp;quot;&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: When installing qt5 type enter to install all packages.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pacman -S mingw-w64-ucrt-x86_64-qt5 mingw-w64-ucrt-x86_64-libpng mingw-w64-ucrt-x86_64-zlib mingw-w64-ucrt-x86_64-boost&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== 3. Build the code generation tools ==&lt;br /&gt;
&lt;br /&gt;
Let us assume you already cloned mxgui&#039;s repository somewhere on your filesystem. If you haven&#039;t, do it now.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;margin: 0 0; background: #e0f7e0; padding: 0 10px; border: 1px solid #c0d0c0&amp;quot;&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Tip&#039;&#039;&#039;: For using git on Windows, we recommend the official distribution (Git for Windows: https://git-scm.com/install/windows) and TortoiseGit for shell integration and GUI support (https://tortoisegit.org).&lt;br /&gt;
&lt;br /&gt;
You can also install git inside MSYS2 by executing &amp;lt;code&amp;gt;pacman -S git&amp;lt;/code&amp;gt;. However, this installs a different and separate version of Git, which exists simultaneously and independently from Git for Windows. By default you can&#039;t use Git for Windows inside a MSYS2 shell, or MSYS2-installed git in a Windows shell.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Change directory to &amp;lt;code&amp;gt;_tools/code_generators&amp;lt;/code&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd ../../_tools/code_generators&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Build the code generators with CMake.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mkdir build&lt;br /&gt;
cd build&lt;br /&gt;
cmake ..&lt;br /&gt;
make&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;div style=&amp;quot;margin: 0 0; background: #f7f7e0; padding: 0 10px; border: 1px solid #d0d0c0&amp;quot;&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: If you want to make the compilation faster by using all the CPU cores in your machine, instead of just typing &amp;lt;code&amp;gt;make&amp;lt;/code&amp;gt; type &amp;lt;code&amp;gt;make -j4&amp;lt;/code&amp;gt; where 4 stands for the number of CPU cores you have.&lt;br /&gt;
&lt;br /&gt;
Of course you can do this any time you use make to compile something, not just for this one case.&lt;br /&gt;
&lt;br /&gt;
If you don&#039;t know how many cores your CPU has, check in Task Manager.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== 4. Build the simulator ==&lt;br /&gt;
&lt;br /&gt;
Now we only need to build the simulator. Change directory to the simulator&#039;s root:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd ../../qtsimulator&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then build it like we did for the code generators:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mkdir build&lt;br /&gt;
cd build&lt;br /&gt;
cmake ..&lt;br /&gt;
make&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now you should be able to run the simulator!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./qtsimulator.exe&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;clear: both&amp;quot;&amp;gt;&lt;br /&gt;
[[File:Mxgui simulator on Windows 11.png|frame|center]]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;margin: 0 0; background: #f7e0e0; padding: 0 10px; border: 1px solid #d0c0c0&amp;quot;&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Warning&#039;&#039;&#039;: If you double-click on the &amp;lt;code&amp;gt;qtsimulator.exe&amp;lt;/code&amp;gt; executable in Windows Explorer, it probably won&#039;t work because of some missing DLLs. This is normal. The missing DLLs are located in &amp;lt;code&amp;gt;C:\msys64\ucrt64\bin&amp;lt;/code&amp;gt;, a directory that the MSYS2 shell configuration adds to the PATH variable automatically, but is not normally included in PATH.&lt;br /&gt;
&lt;br /&gt;
To make the simulator executable work when double-clicked, first check all the required DLLs by executing &amp;lt;code&amp;gt;lld qtsimulator.exe&amp;lt;/code&amp;gt; in the MSYS2 shell, and then copy the DLLs located in &amp;lt;code&amp;gt;C:\msys64\ucrt64\bin&amp;lt;/code&amp;gt; to the same directory as &amp;lt;code&amp;gt;qtsimulator.exe&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
However, unless you want to distribute the compiled simulator, it&#039;s much simpler to just always run it from inside an MSYS2 UCRT64 terminal window.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;/div&gt;</summary>
		<author><name>Daniele.cattaneo</name></author>
	</entry>
	<entry>
		<id>https://miosix.org/wiki/index.php?title=File:Mxgui_simulator_on_Windows_11.png&amp;diff=381</id>
		<title>File:Mxgui simulator on Windows 11.png</title>
		<link rel="alternate" type="text/html" href="https://miosix.org/wiki/index.php?title=File:Mxgui_simulator_on_Windows_11.png&amp;diff=381"/>
		<updated>2026-03-26T18:12:35Z</updated>

		<summary type="html">&lt;p&gt;Daniele.cattaneo: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Screenshot of the mxgui simulator on Windows 11&lt;/div&gt;</summary>
		<author><name>Daniele.cattaneo</name></author>
	</entry>
	<entry>
		<id>https://miosix.org/wiki/index.php?title=File:Msys2_toolchains.png&amp;diff=380</id>
		<title>File:Msys2 toolchains.png</title>
		<link rel="alternate" type="text/html" href="https://miosix.org/wiki/index.php?title=File:Msys2_toolchains.png&amp;diff=380"/>
		<updated>2026-03-26T13:47:57Z</updated>

		<summary type="html">&lt;p&gt;Daniele.cattaneo: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Toolchains available in a default installation of MSYS2&lt;/div&gt;</summary>
		<author><name>Daniele.cattaneo</name></author>
	</entry>
	<entry>
		<id>https://miosix.org/wiki/index.php?title=User:Daniele.cattaneo&amp;diff=379</id>
		<title>User:Daniele.cattaneo</title>
		<link rel="alternate" type="text/html" href="https://miosix.org/wiki/index.php?title=User:Daniele.cattaneo&amp;diff=379"/>
		<updated>2026-03-26T11:47:47Z</updated>

		<summary type="html">&lt;p&gt;Daniele.cattaneo: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Hi :)&lt;br /&gt;
&lt;br /&gt;
Github (work): [https://github.com/danielecattaneo]&lt;br /&gt;
&lt;br /&gt;
Github (personal): Secret&lt;br /&gt;
&lt;br /&gt;
[[Miosix in emulation]]&lt;br /&gt;
&lt;br /&gt;
[[arch directory restructuring]]&lt;br /&gt;
&lt;br /&gt;
[[Miosix 3]]&lt;br /&gt;
&lt;br /&gt;
[[Multicore]]&lt;br /&gt;
&lt;br /&gt;
[[mxgui qtsimulator on windows]]&lt;/div&gt;</summary>
		<author><name>Daniele.cattaneo</name></author>
	</entry>
	<entry>
		<id>https://miosix.org/wiki/index.php?title=Library_list&amp;diff=376</id>
		<title>Library list</title>
		<link rel="alternate" type="text/html" href="https://miosix.org/wiki/index.php?title=Library_list&amp;diff=376"/>
		<updated>2026-03-24T00:14:55Z</updated>

		<summary type="html">&lt;p&gt;Daniele.cattaneo: Add ST HAL guide link&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Libraries are additional components not part of the Miosix kernel that can be downloaded to add functionality to the kernel.&lt;br /&gt;
&lt;br /&gt;
* [[mxgui]] is a GUI library for graphic displays&lt;br /&gt;
* [[mxusb]] is an USB stack, currently targeting stm32f1 microcontrollers only.&lt;br /&gt;
&lt;br /&gt;
You can also use the [[ST HAL Support in Miosix|STMicroelectronics HAL code]] (with minimal adaptations) for any peripheral that does not have native Miosix drivers. However this is not recommended as in our experience the HAL often contains buggy or suboptimal drivers.&lt;br /&gt;
&lt;br /&gt;
[[Category:Libraries]]&lt;/div&gt;</summary>
		<author><name>Daniele.cattaneo</name></author>
	</entry>
	<entry>
		<id>https://miosix.org/wiki/index.php?title=ST_Hal_Support_in_Miosix&amp;diff=375</id>
		<title>ST Hal Support in Miosix</title>
		<link rel="alternate" type="text/html" href="https://miosix.org/wiki/index.php?title=ST_Hal_Support_in_Miosix&amp;diff=375"/>
		<updated>2026-03-24T00:12:37Z</updated>

		<summary type="html">&lt;p&gt;Daniele.cattaneo: Daniele.cattaneo moved page ST Hal Support in Miosix to ST HAL Support in Miosix: Misspelled title&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;#REDIRECT [[ST HAL Support in Miosix]]&lt;/div&gt;</summary>
		<author><name>Daniele.cattaneo</name></author>
	</entry>
	<entry>
		<id>https://miosix.org/wiki/index.php?title=ST_HAL_Support_in_Miosix&amp;diff=374</id>
		<title>ST HAL Support in Miosix</title>
		<link rel="alternate" type="text/html" href="https://miosix.org/wiki/index.php?title=ST_HAL_Support_in_Miosix&amp;diff=374"/>
		<updated>2026-03-24T00:12:37Z</updated>

		<summary type="html">&lt;p&gt;Daniele.cattaneo: Daniele.cattaneo moved page ST Hal Support in Miosix to ST HAL Support in Miosix: Misspelled title&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;If you are developing or have existing code that uses the HAL from ST Microelectronics, you can port it fairly easily into Miosix by following this guide:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: The content of this page was tested on Miosix v3.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: Miosix uses C++ instead of C&lt;br /&gt;
&lt;br /&gt;
;1. Follow the [[Quick start]] guide to configure the kernel and install all the required tools&lt;br /&gt;
;2. Include &amp;quot;miosix.h&amp;quot; in your program&#039;s main file (remember that the file main file must be named &amp;quot;main.cpp&amp;quot;) and wherever else you need to use Miosix&#039;s APIs;&lt;br /&gt;
;3. Remove the clock configuration: Miosix already handles the clock configuration and keeping it in the code would result in a lockup of the microcontroller.&lt;br /&gt;
&lt;br /&gt;
:Usually the clock configuration is generated by STM32Cube and it looks like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
static void SystemClock_Config(void)&lt;br /&gt;
{&lt;br /&gt;
 RCC_ClkInitTypeDef RCC_ClkInitStruct;&lt;br /&gt;
 RCC_OscInitTypeDef RCC_OscInitStruct;&lt;br /&gt;
 &lt;br /&gt;
 /* Enable Power Control clock */&lt;br /&gt;
 __HAL_RCC_PWR_CLK_ENABLE();&lt;br /&gt;
 &lt;br /&gt;
 /* The voltage scaling allows optimizing the power consumption when the device is &lt;br /&gt;
    clocked below the maximum system frequency, to update the voltage scaling value &lt;br /&gt;
    regarding system frequency refer to product datasheet.  */&lt;br /&gt;
 __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE3);&lt;br /&gt;
 &lt;br /&gt;
 /* Enable MSI Oscillator */&lt;br /&gt;
 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_MSI;&lt;br /&gt;
 RCC_OscInitStruct.MSIState = RCC_MSI_ON;&lt;br /&gt;
 RCC_OscInitStruct.MSIClockRange = RCC_MSIRANGE_5;&lt;br /&gt;
 RCC_OscInitStruct.MSICalibrationValue=0x00;&lt;br /&gt;
 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;&lt;br /&gt;
 if(HAL_RCC_OscConfig(&amp;amp;RCC_OscInitStruct) != HAL_OK)&lt;br /&gt;
 {&lt;br /&gt;
   /* Initialization Error */&lt;br /&gt;
   Error_Handler();&lt;br /&gt;
 }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
For some peripherals you might need to adjust peripheral-level clock configuration registers.&lt;br /&gt;
&lt;br /&gt;
:If your code contains interrupts refer to the section below.&lt;br /&gt;
&lt;br /&gt;
:Here an example code of the main.cpp for a blinking led in a Nucleo-L053R8 board:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#include &amp;quot;miosix.h&amp;quot;&lt;br /&gt;
#include &amp;quot;stm32l053xx.h&amp;quot;&lt;br /&gt;
#include &amp;quot;stm32l0xx_hal.h&amp;quot;&lt;br /&gt;
#include &amp;lt;interfaces/bsp.h&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
using namespace miosix;&lt;br /&gt;
&lt;br /&gt;
static void MX_GPIO_Init(void);&lt;br /&gt;
&lt;br /&gt;
int main() {&lt;br /&gt;
  iprintf(&amp;quot;Hello world, write your application here\n&amp;quot;);&lt;br /&gt;
  HAL_Init();&lt;br /&gt;
&lt;br /&gt;
  MX_GPIO_Init();&lt;br /&gt;
  for (;;) {&lt;br /&gt;
    HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5);&lt;br /&gt;
    HAL_Delay(500);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
static void MX_GPIO_Init(void) {&lt;br /&gt;
  __HAL_RCC_GPIOC_CLK_ENABLE();&lt;br /&gt;
  __HAL_RCC_GPIOA_CLK_ENABLE();&lt;br /&gt;
&lt;br /&gt;
  GPIO_InitTypeDef GPIO_InitStruct = {0};&lt;br /&gt;
&lt;br /&gt;
  // Configure Led pin&lt;br /&gt;
  GPIO_InitStruct.Pin = GPIO_PIN_5;&lt;br /&gt;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;&lt;br /&gt;
  GPIO_InitStruct.Pull = GPIO_NOPULL;&lt;br /&gt;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;&lt;br /&gt;
&lt;br /&gt;
  HAL_GPIO_Init(GPIOA, &amp;amp;GPIO_InitStruct);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
;4. Include in the Makefile all the libraries and all the file .c needed to compile the program&lt;br /&gt;
Remember to include the HAL libraries and .c files used&lt;br /&gt;
&lt;br /&gt;
;5. add a CFLAGS and CXXFLAGS that defines the type of board that you are using in the Makefile &lt;br /&gt;
:(ex: CFLAGS += -DSTM32L053xx and CXXFLAGS += -DSTM32L053xx  for a stm32l053-R8).&lt;br /&gt;
:If you want, you can instead uncomment the type of the board in the Miosix folder (ex: for an stm32l053-R8, you need to uncomment &amp;quot;#define STM32L053xx&amp;quot; in &amp;quot;miosix/arch/common/CMSIS/Device/ST/STM32L0xx/Include/stm32l0xx.h&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
;5b. You need to do that also for any Shield that you are using.&lt;br /&gt;
&lt;br /&gt;
;6. Create an implementation of the function HAL_Delay() by using the Miosix primitive Thread::Sleep(). You can put the implementation in a separate file (called for example wrapper.cpp) or wherever else you like.&lt;br /&gt;
&lt;br /&gt;
:Here the part that you need to modify in the example of the Makefile for the previous example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#Prevoius code&lt;br /&gt;
SRC :=main.cpp \&lt;br /&gt;
    STM32CubeL0/Drivers/STM32L0xx_HAL_Driver/Src/stm32l0xx_hal.c \&lt;br /&gt;
    STM32CubeL0/Drivers/BSP/STM32L0xx_Nucleo/stm32l0xx_nucleo.c \&lt;br /&gt;
	STM32CubeL0/Drivers/STM32L0xx_HAL_Driver/Src/stm32l0xx_hal_gpio.h \&lt;br /&gt;
	STM32CubeL0/Drivers/STM32L0xx_HAL_Driver/Src/stm32l0xx_hal_cortex.c \&lt;br /&gt;
	wrapper.cpp&lt;br /&gt;
&lt;br /&gt;
INCLUDE_DIRS := -ISTM32CubeL0/Drivers/STM32L0xx_HAL_Driver/Inc \&lt;br /&gt;
	-ISTM32CubeL0/Drivers/BSP/STM32L0xx_Nucleo \&lt;br /&gt;
	-Imiosix/arch/common/CMSIS/Device/ST/STM32L0xx/Include/ \&lt;br /&gt;
	-ISTM32CubeL0/Projects/NUCLEO-L053R8/Examples/GPIO/GPIO_IOToggle/Inc&lt;br /&gt;
&lt;br /&gt;
#Other code&lt;br /&gt;
&lt;br /&gt;
CFLAGS += -DSTM32L053xx&lt;br /&gt;
&lt;br /&gt;
CXXFLAGS += -DSTM32L053xx&lt;br /&gt;
&lt;br /&gt;
#Other code&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
;7. Compile and flash the program. This is done by using the command &amp;quot;make&amp;quot; and &amp;quot;make program&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=== Interrupts ===&lt;br /&gt;
&lt;br /&gt;
ST&#039;s HAL expects interrupt handler functions to be defined statically with weak symbols, allowing to define an interrupt handler for a given IRQ number by simply defining a function with the correct name. This does not work in Miosix and thus the code needs to be adapted.&lt;br /&gt;
&lt;br /&gt;
In Miosix interrupt handlers need to be registered at runtime in order to be called. This is done by creating a lock and registering the IRQ like in the following example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
  GlobalIrqLock lock; //disable interrupts on the core that acquired the lock (all in single core)&lt;br /&gt;
  IRQregisterIrq(lock, SPI2_IRQn, &amp;amp;SPIx_IRQHandler); //setup for SPI2, SPIx_IRQHandler is the handler called when the SPI finished sending a message&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This needs to be done for each interrupt that you have to register.&lt;br /&gt;
&lt;br /&gt;
Keep in mind that the GlobalIrqLock object is a RAII style acquisition primitive. In other words the lock is held as long the &amp;quot;lock&amp;quot; variable exists, thus encapsulating its declaration in a block (curly brackets) will release the lock automatically when the block ends.&lt;/div&gt;</summary>
		<author><name>Daniele.cattaneo</name></author>
	</entry>
	<entry>
		<id>https://miosix.org/wiki/index.php?title=ST_HAL_Support_in_Miosix&amp;diff=373</id>
		<title>ST HAL Support in Miosix</title>
		<link rel="alternate" type="text/html" href="https://miosix.org/wiki/index.php?title=ST_HAL_Support_in_Miosix&amp;diff=373"/>
		<updated>2026-03-24T00:11:40Z</updated>

		<summary type="html">&lt;p&gt;Daniele.cattaneo: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;If you are developing or have existing code that uses the HAL from ST Microelectronics, you can port it fairly easily into Miosix by following this guide:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: The content of this page was tested on Miosix v3.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: Miosix uses C++ instead of C&lt;br /&gt;
&lt;br /&gt;
;1. Follow the [[Quick start]] guide to configure the kernel and install all the required tools&lt;br /&gt;
;2. Include &amp;quot;miosix.h&amp;quot; in your program&#039;s main file (remember that the file main file must be named &amp;quot;main.cpp&amp;quot;) and wherever else you need to use Miosix&#039;s APIs;&lt;br /&gt;
;3. Remove the clock configuration: Miosix already handles the clock configuration and keeping it in the code would result in a lockup of the microcontroller.&lt;br /&gt;
&lt;br /&gt;
:Usually the clock configuration is generated by STM32Cube and it looks like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
static void SystemClock_Config(void)&lt;br /&gt;
{&lt;br /&gt;
 RCC_ClkInitTypeDef RCC_ClkInitStruct;&lt;br /&gt;
 RCC_OscInitTypeDef RCC_OscInitStruct;&lt;br /&gt;
 &lt;br /&gt;
 /* Enable Power Control clock */&lt;br /&gt;
 __HAL_RCC_PWR_CLK_ENABLE();&lt;br /&gt;
 &lt;br /&gt;
 /* The voltage scaling allows optimizing the power consumption when the device is &lt;br /&gt;
    clocked below the maximum system frequency, to update the voltage scaling value &lt;br /&gt;
    regarding system frequency refer to product datasheet.  */&lt;br /&gt;
 __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE3);&lt;br /&gt;
 &lt;br /&gt;
 /* Enable MSI Oscillator */&lt;br /&gt;
 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_MSI;&lt;br /&gt;
 RCC_OscInitStruct.MSIState = RCC_MSI_ON;&lt;br /&gt;
 RCC_OscInitStruct.MSIClockRange = RCC_MSIRANGE_5;&lt;br /&gt;
 RCC_OscInitStruct.MSICalibrationValue=0x00;&lt;br /&gt;
 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;&lt;br /&gt;
 if(HAL_RCC_OscConfig(&amp;amp;RCC_OscInitStruct) != HAL_OK)&lt;br /&gt;
 {&lt;br /&gt;
   /* Initialization Error */&lt;br /&gt;
   Error_Handler();&lt;br /&gt;
 }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
For some peripherals you might need to adjust peripheral-level clock configuration registers.&lt;br /&gt;
&lt;br /&gt;
:If your code contains interrupts refer to the section below.&lt;br /&gt;
&lt;br /&gt;
:Here an example code of the main.cpp for a blinking led in a Nucleo-L053R8 board:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#include &amp;quot;miosix.h&amp;quot;&lt;br /&gt;
#include &amp;quot;stm32l053xx.h&amp;quot;&lt;br /&gt;
#include &amp;quot;stm32l0xx_hal.h&amp;quot;&lt;br /&gt;
#include &amp;lt;interfaces/bsp.h&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
using namespace miosix;&lt;br /&gt;
&lt;br /&gt;
static void MX_GPIO_Init(void);&lt;br /&gt;
&lt;br /&gt;
int main() {&lt;br /&gt;
  iprintf(&amp;quot;Hello world, write your application here\n&amp;quot;);&lt;br /&gt;
  HAL_Init();&lt;br /&gt;
&lt;br /&gt;
  MX_GPIO_Init();&lt;br /&gt;
  for (;;) {&lt;br /&gt;
    HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5);&lt;br /&gt;
    HAL_Delay(500);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
static void MX_GPIO_Init(void) {&lt;br /&gt;
  __HAL_RCC_GPIOC_CLK_ENABLE();&lt;br /&gt;
  __HAL_RCC_GPIOA_CLK_ENABLE();&lt;br /&gt;
&lt;br /&gt;
  GPIO_InitTypeDef GPIO_InitStruct = {0};&lt;br /&gt;
&lt;br /&gt;
  // Configure Led pin&lt;br /&gt;
  GPIO_InitStruct.Pin = GPIO_PIN_5;&lt;br /&gt;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;&lt;br /&gt;
  GPIO_InitStruct.Pull = GPIO_NOPULL;&lt;br /&gt;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;&lt;br /&gt;
&lt;br /&gt;
  HAL_GPIO_Init(GPIOA, &amp;amp;GPIO_InitStruct);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
;4. Include in the Makefile all the libraries and all the file .c needed to compile the program&lt;br /&gt;
Remember to include the HAL libraries and .c files used&lt;br /&gt;
&lt;br /&gt;
;5. add a CFLAGS and CXXFLAGS that defines the type of board that you are using in the Makefile &lt;br /&gt;
:(ex: CFLAGS += -DSTM32L053xx and CXXFLAGS += -DSTM32L053xx  for a stm32l053-R8).&lt;br /&gt;
:If you want, you can instead uncomment the type of the board in the Miosix folder (ex: for an stm32l053-R8, you need to uncomment &amp;quot;#define STM32L053xx&amp;quot; in &amp;quot;miosix/arch/common/CMSIS/Device/ST/STM32L0xx/Include/stm32l0xx.h&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
;5b. You need to do that also for any Shield that you are using.&lt;br /&gt;
&lt;br /&gt;
;6. Create an implementation of the function HAL_Delay() by using the Miosix primitive Thread::Sleep(). You can put the implementation in a separate file (called for example wrapper.cpp) or wherever else you like.&lt;br /&gt;
&lt;br /&gt;
:Here the part that you need to modify in the example of the Makefile for the previous example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#Prevoius code&lt;br /&gt;
SRC :=main.cpp \&lt;br /&gt;
    STM32CubeL0/Drivers/STM32L0xx_HAL_Driver/Src/stm32l0xx_hal.c \&lt;br /&gt;
    STM32CubeL0/Drivers/BSP/STM32L0xx_Nucleo/stm32l0xx_nucleo.c \&lt;br /&gt;
	STM32CubeL0/Drivers/STM32L0xx_HAL_Driver/Src/stm32l0xx_hal_gpio.h \&lt;br /&gt;
	STM32CubeL0/Drivers/STM32L0xx_HAL_Driver/Src/stm32l0xx_hal_cortex.c \&lt;br /&gt;
	wrapper.cpp&lt;br /&gt;
&lt;br /&gt;
INCLUDE_DIRS := -ISTM32CubeL0/Drivers/STM32L0xx_HAL_Driver/Inc \&lt;br /&gt;
	-ISTM32CubeL0/Drivers/BSP/STM32L0xx_Nucleo \&lt;br /&gt;
	-Imiosix/arch/common/CMSIS/Device/ST/STM32L0xx/Include/ \&lt;br /&gt;
	-ISTM32CubeL0/Projects/NUCLEO-L053R8/Examples/GPIO/GPIO_IOToggle/Inc&lt;br /&gt;
&lt;br /&gt;
#Other code&lt;br /&gt;
&lt;br /&gt;
CFLAGS += -DSTM32L053xx&lt;br /&gt;
&lt;br /&gt;
CXXFLAGS += -DSTM32L053xx&lt;br /&gt;
&lt;br /&gt;
#Other code&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
;7. Compile and flash the program. This is done by using the command &amp;quot;make&amp;quot; and &amp;quot;make program&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=== Interrupts ===&lt;br /&gt;
&lt;br /&gt;
ST&#039;s HAL expects interrupt handler functions to be defined statically with weak symbols, allowing to define an interrupt handler for a given IRQ number by simply defining a function with the correct name. This does not work in Miosix and thus the code needs to be adapted.&lt;br /&gt;
&lt;br /&gt;
In Miosix interrupt handlers need to be registered at runtime in order to be called. This is done by creating a lock and registering the IRQ like in the following example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
  GlobalIrqLock lock; //disable interrupts on the core that acquired the lock (all in single core)&lt;br /&gt;
  IRQregisterIrq(lock, SPI2_IRQn, &amp;amp;SPIx_IRQHandler); //setup for SPI2, SPIx_IRQHandler is the handler called when the SPI finished sending a message&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This needs to be done for each interrupt that you have to register.&lt;br /&gt;
&lt;br /&gt;
Keep in mind that the GlobalIrqLock object is a RAII style acquisition primitive. In other words the lock is held as long the &amp;quot;lock&amp;quot; variable exists, thus encapsulating its declaration in a block (curly brackets) will release the lock automatically when the block ends.&lt;/div&gt;</summary>
		<author><name>Daniele.cattaneo</name></author>
	</entry>
	<entry>
		<id>https://miosix.org/wiki/index.php?title=File:Stm3220g_serial.jpg&amp;diff=371</id>
		<title>File:Stm3220g serial.jpg</title>
		<link rel="alternate" type="text/html" href="https://miosix.org/wiki/index.php?title=File:Stm3220g_serial.jpg&amp;diff=371"/>
		<updated>2026-03-14T21:18:41Z</updated>

		<summary type="html">&lt;p&gt;Daniele.cattaneo: Daniele.cattaneo uploaded a new version of File:Stm3220g serial.jpg&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Location of serial pins on stm3220g board&lt;/div&gt;</summary>
		<author><name>Daniele.cattaneo</name></author>
	</entry>
	<entry>
		<id>https://miosix.org/wiki/index.php?title=Stm32f207ig_stm3220g-eval&amp;diff=370</id>
		<title>Stm32f207ig stm3220g-eval</title>
		<link rel="alternate" type="text/html" href="https://miosix.org/wiki/index.php?title=Stm32f207ig_stm3220g-eval&amp;diff=370"/>
		<updated>2026-03-14T21:16:44Z</updated>

		<summary type="html">&lt;p&gt;Daniele.cattaneo: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This board has an STM32F207IG, a Cortex-M3 running at 120MHz with 1MB of FLASH and 128KB of RAM, plus 2MB of external SRAM. In addtion, the board has some nice peripherals including an USB port and a 320x240 LCD display.&lt;br /&gt;
Also, there is a microSD socket allowing filesystem support. Due to GPIO conflicts between the USART and SDIO the SD card works in 1-bit mode instead of 4-bit, thus write speed is limited in this board.&lt;br /&gt;
&lt;br /&gt;
To develop for this board you&#039;ll need an USB to serial adapter to be able to deploy your code to the board through its serial bootloader as well as to be able to see debug messages as printf is redirected to the serial port on this board. Optionally, you&#039;ll need a JTAG in circuit debugger compatible with OpenOCD and Linux, an [https://www.olimex.com/Products/ARM/JTAG/ARM-USB-OCD ARM-USB-OCD] was tested succesfully.&lt;br /&gt;
&lt;br /&gt;
[[File:Stm3220g-eval.jpg|frameless]]&lt;br /&gt;
&lt;br /&gt;
== Configuring the kernel ==&lt;br /&gt;
&lt;br /&gt;
The minimum configuration required is to edit the [[Makefile.inc|miosix/config/Makefile.inc]] file to uncomment the &#039;&#039;OPT_BOARD := stm32f207ig_stm3220g-eval&#039;&#039; line. If you had compiled the kernel before, it is recommended to do a &#039;&#039;make clean&#039;&#039; (or in the Netbeans IDE, to click on the &amp;quot;Clean project&amp;quot; button) to avoid leaving object files around. After, do a &#039;&#039;make&#039;&#039; to compile.&lt;br /&gt;
&lt;br /&gt;
In addition, this board has a couple of board-specific options in the Makefile.inc file. For convenience, the relevant part of that configuration file is reported here so as to be easily located within the file&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
##---------------------------------------------------------------------------&lt;br /&gt;
## stm32f207ig_stm3220g-eval&lt;br /&gt;
##&lt;br /&gt;
ifeq ($(OPT_BOARD),stm32f207ig_stm3220g-eval)&lt;br /&gt;
&lt;br /&gt;
  ## Linker script type, there are three options&lt;br /&gt;
  ## 1) Code in FLASH, stack + heap in internal RAM (file *_rom.ld)&lt;br /&gt;
  ##    the most common choice, available for all microcontrollers&lt;br /&gt;
  ## 2) Code in FLASH stack in internal RAM heap in external RAM (file&lt;br /&gt;
  ##    *_xram.ld) useful for hardware like STM3220G-EVAL when big heap is&lt;br /&gt;
  ##    needed. The microcontroller must have an external memory interface.&lt;br /&gt;
  ## 3) Code + stack + heap in external RAM, (file *_all_in_xram.ld)&lt;br /&gt;
  ##    useful for debugging code in hardware like STM3220G-EVAL. Code runs&lt;br /&gt;
  ##    *very* slow compared to FLASH. Works only with a booloader that&lt;br /&gt;
  ##    forwards interrrupts @ 0x64000000 (see miosix/bootloaders for one).&lt;br /&gt;
  ##    The microcontroller must have an external memory interface.&lt;br /&gt;
  ## Warning! enable external ram if you use a linker script that requires it&lt;br /&gt;
  ## (see the XRAM flag below)&lt;br /&gt;
  LINKER_SCRIPT_PATH := arch/cortexM3_stm32f2/stm32f207ig_stm3220g-eval/&lt;br /&gt;
  #LINKER_SCRIPT := $(LINKER_SCRIPT_PATH)stm32_1m+128k_rom.ld&lt;br /&gt;
  #LINKER_SCRIPT := $(LINKER_SCRIPT_PATH)stm32_1m+128k_xram.ld&lt;br /&gt;
  LINKER_SCRIPT := $(LINKER_SCRIPT_PATH)stm32_1m+128k_all_in_xram.ld&lt;br /&gt;
  &lt;br /&gt;
  ## Enable/disable initialization of external RAM at boot. Three options:&lt;br /&gt;
  ## __ENABLE_XRAM : If you want the heap in xram (with an appropriate linker&lt;br /&gt;
  ## script selected above)&lt;br /&gt;
  ## __ENABLE_XRAM and __CODE_IN_XRAM : Debug mode with code + stack + heap&lt;br /&gt;
  ## in xram (with an appropriate linker script selected above)&lt;br /&gt;
  ## none selected : don&#039;t use xram (with an appropriate linker script&lt;br /&gt;
  ## selected above)&lt;br /&gt;
  #XRAM := -D__ENABLE_XRAM&lt;br /&gt;
  XRAM := -D__ENABLE_XRAM -D__CODE_IN_XRAM&lt;br /&gt;
  &lt;br /&gt;
endif&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As can be seen, there are two options for this board: LINKER_SCRIPT and XRAM. The comments explain in detail the meaning of there options, so it isn&#039;t necessary to further explain them.&lt;br /&gt;
&lt;br /&gt;
After modifying configuration files it is recommended to do a make clean; make (or in the Netbeans IDE, to click on the &amp;quot;Clean and build project&amp;quot; button) to be sure that changes are applied.&lt;br /&gt;
&lt;br /&gt;
== Loading code ==&lt;br /&gt;
&lt;br /&gt;
As explained before, there are more than one linker script for this board, and the selected linker script affects the way code should be loaded on the board.&lt;br /&gt;
&lt;br /&gt;
===stm32_1m+128k_all_in_xram.ld===&lt;br /&gt;
This is the default linker script, it is very useful for debugging code on this board, as it locates everything (code, stack, heap) in the external RAM. It has the disadvantage that the loaded code is lost upon reboot (being in a volatile memory) and that code will run ~10 times slower due to external RAM access timings, but for debugging, these are not issues.&lt;br /&gt;
&lt;br /&gt;
To be able to use this linker script you need to program a bootloader into the microcontroller&#039;s FLASH memory that allows code loading to the external RAM as well as forwarding interrupts there.&lt;br /&gt;
This bootloader is in the &#039;&#039;miosix/_tools/bootloaders/stm32/uc_loader_stm3220g-eval&#039;&#039; directory, and information on how to install it can be found in the &#039;&#039;miosix/_doc/textdoc/stm32-bootloader.txt&#039;&#039; file. For programming the bootloader the [http://sourceforge.net/projects/stm32flash stm32flash] tool can be used.&lt;br /&gt;
&lt;br /&gt;
===stm32_1m+128k_rom.ld and stm32_1m+128k_xram.ld===&lt;br /&gt;
&lt;br /&gt;
These linker scripts put the code in FLASH, so you need to program the microcontroller&#039;s FLASH every time you change your code, but code will run faster and won&#039;t be lost at each reboot.&lt;br /&gt;
&lt;br /&gt;
A simple way to load code in FLASH is to use the stm32flash tool. After having installed it on your system, all you need to do is to connect a serial cable between the USART1 connector on the board and your PC. USB to serial adapters work well if you don&#039;t have a serial port. Then, flip up the boot0 switch on your board, and hit the Reset key.&lt;br /&gt;
On the PC side, you&#039;ll need to run the&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
stm32flash -w main.hex -v /dev/ttyUSB0&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Of course, replace /dev/ttyUSB0 with your serial port device name.&lt;br /&gt;
After that, flip down the boot0 switch and hit again Reset. The code you have loaded should start.&lt;br /&gt;
&lt;br /&gt;
== Reading printf output ==&lt;br /&gt;
&lt;br /&gt;
The board support package of this board simply redirects printf to the serial port USART3. The board has an RS232 connector, so you&#039;ll simply need to connect it to your computer via a serial cable, or use an USB to serial adapter connected to pins PC10 (USART3 TX) and PC11 (USART3 RX), which are exposed on pins 36 (PC10) and 35 (PC11) of CN4.&lt;br /&gt;
The serial port baudrate is set to 115200baud, 8N1.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;clear: both&amp;quot;&amp;gt;&lt;br /&gt;
[[File:Stm3220g serial.jpg|frame|center|Location of serial pins]]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
On Linux you can use screen. Open a terminal and type &#039;&#039;screen /dev/ttyUSB0 115200&#039;&#039; (Note that to quit from screen you need to type &amp;quot;Ctrl-C, \&amp;quot;). You&#039;ll need to change /dev/ttyUSB0 with your serial port device name.&lt;br /&gt;
&lt;br /&gt;
On windows you can use HyperTerminal, you need to configure it to use the required baud rate, no flow control, and select the correct COM port device name.&lt;br /&gt;
&lt;br /&gt;
== In circuit debugging ==&lt;br /&gt;
&lt;br /&gt;
In-circuit debugging requires an USB to JTAG adapter. Ther recomended one is the [https://www.olimex.com/Products/ARM/JTAG/ARM-USB-OCD ARM-USB-OCD]. If you use a different one, you may need to modify the &#039;&#039;miosix/arch/arm7_lpc2000/lpc2138_miosix_board/lpc2138_armusbocd.cfg&#039;&#039; to adapt it to your JTAG tool.&lt;br /&gt;
&lt;br /&gt;
Before you begin you should note that the Miosix kernel will put the CPU to a low power state when no thread is running. This low power state will usually confuse debuggers and make them lose sync with the CPU. To avoid this you need to edit the [[miosix_settings.h|miosix/config/miosix_settings.h]] file and uncomment &#039;&#039;#define JTAG_DISABLE_SLEEP&#039;&#039; line. This will prevent the kernel from putting the CPU in its low power state making debugging possible.&lt;br /&gt;
Also, to be able to precisely single-step your code you need to disable compiler optimizations as gdb is incapable of reliably debug an optimized code. The option is in the miosix/config/Makefile.inc file and is the &#039;&#039;OPT_OPTIMIZATION := -O0&#039;&#039; that should be uncommented while the other lines related to the same option should be commented out.&lt;br /&gt;
&lt;br /&gt;
After modifying configuration files it is recommended to do a &#039;&#039;make clean; make&#039;&#039; (or in the Netbeans IDE, to click on the &amp;quot;Clean and build project&amp;quot; button) to be sure that changes are applied.&lt;br /&gt;
&lt;br /&gt;
On the software side, you need to open two shells. In one do a&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo openocd -f miosix/arch/cortexM3_stm32f2/stm32f207ig_stm3220g-eval/stm3220g_eval.cfg&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will start the OpenOCD program that will connect to the board and listen for GDB connections.&lt;br /&gt;
&lt;br /&gt;
In the second shell type the following commands&lt;br /&gt;
&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;
target remote :3333&lt;br /&gt;
monitor soft_reset_halt&lt;br /&gt;
load&lt;br /&gt;
break main&lt;br /&gt;
continue&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first command will start the gdb debugger. The following commands are typed into the gdb console, and tell it to connect to OpenOCD, reset the board and stop at the beginning of main()&lt;br /&gt;
Please not that the load command implies that you are using the stm32_512k+64k_all_in_xram.ld linker script, and will instruct gdb to load your code in RAM. If you are using another linker script that loads code in FLASH you&#039;ll need to replace this command with a&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
monitor flash write_image erase main.bin 0x08000000&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
that will program the FLASH memory.&lt;br /&gt;
&lt;br /&gt;
From there on, have a look at [[Quick_start]] for debugger commands.&lt;br /&gt;
&lt;br /&gt;
== (Optional) Configuring the Netbeans IDE ==&lt;br /&gt;
To have a fully working code completion that can also resolve the board-specific symbols, right click on the project, go to Set Configuration and select the right board.&lt;br /&gt;
&lt;br /&gt;
[[File:Netbeans-config.png]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Boards]]&lt;/div&gt;</summary>
		<author><name>Daniele.cattaneo</name></author>
	</entry>
	<entry>
		<id>https://miosix.org/wiki/index.php?title=Stm32f207ig_stm3220g-eval&amp;diff=369</id>
		<title>Stm32f207ig stm3220g-eval</title>
		<link rel="alternate" type="text/html" href="https://miosix.org/wiki/index.php?title=Stm32f207ig_stm3220g-eval&amp;diff=369"/>
		<updated>2026-03-14T21:04:11Z</updated>

		<summary type="html">&lt;p&gt;Daniele.cattaneo: Fix image&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This board has an STM32F207IG, a Cortex-M3 running at 120MHz with 1MB of FLASH and 128KB of RAM, plus 2MB of external SRAM. In addtion, the board has some nice peripherals including an USB port and a 320x240 LCD display.&lt;br /&gt;
Also, there is a microSD socket allowing filesystem support. Due to GPIO conflicts between the USART and SDIO the SD card works in 1-bit mode instead of 4-bit, thus write speed is limited in this board.&lt;br /&gt;
&lt;br /&gt;
To develop for this board you&#039;ll need an USB to serial adapter to be able to deploy your code to the board through its serial bootloader as well as to be able to see debug messages as printf is redirected to the serial port on this board. Optionally, you&#039;ll need a JTAG in circuit debugger compatible with OpenOCD and Linux, an [https://www.olimex.com/Products/ARM/JTAG/ARM-USB-OCD ARM-USB-OCD] was tested succesfully.&lt;br /&gt;
&lt;br /&gt;
[[File:Stm3220g-eval.jpg|frameless]]&lt;br /&gt;
&lt;br /&gt;
== Configuring the kernel ==&lt;br /&gt;
&lt;br /&gt;
The minimum configuration required is to edit the [[Makefile.inc|miosix/config/Makefile.inc]] file to uncomment the &#039;&#039;OPT_BOARD := stm32f207ig_stm3220g-eval&#039;&#039; line. If you had compiled the kernel before, it is recommended to do a &#039;&#039;make clean&#039;&#039; (or in the Netbeans IDE, to click on the &amp;quot;Clean project&amp;quot; button) to avoid leaving object files around. After, do a &#039;&#039;make&#039;&#039; to compile.&lt;br /&gt;
&lt;br /&gt;
In addition, this board has a couple of board-specific options in the Makefile.inc file. For convenience, the relevant part of that configuration file is reported here so as to be easily located within the file&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
##---------------------------------------------------------------------------&lt;br /&gt;
## stm32f207ig_stm3220g-eval&lt;br /&gt;
##&lt;br /&gt;
ifeq ($(OPT_BOARD),stm32f207ig_stm3220g-eval)&lt;br /&gt;
&lt;br /&gt;
  ## Linker script type, there are three options&lt;br /&gt;
  ## 1) Code in FLASH, stack + heap in internal RAM (file *_rom.ld)&lt;br /&gt;
  ##    the most common choice, available for all microcontrollers&lt;br /&gt;
  ## 2) Code in FLASH stack in internal RAM heap in external RAM (file&lt;br /&gt;
  ##    *_xram.ld) useful for hardware like STM3220G-EVAL when big heap is&lt;br /&gt;
  ##    needed. The microcontroller must have an external memory interface.&lt;br /&gt;
  ## 3) Code + stack + heap in external RAM, (file *_all_in_xram.ld)&lt;br /&gt;
  ##    useful for debugging code in hardware like STM3220G-EVAL. Code runs&lt;br /&gt;
  ##    *very* slow compared to FLASH. Works only with a booloader that&lt;br /&gt;
  ##    forwards interrrupts @ 0x64000000 (see miosix/bootloaders for one).&lt;br /&gt;
  ##    The microcontroller must have an external memory interface.&lt;br /&gt;
  ## Warning! enable external ram if you use a linker script that requires it&lt;br /&gt;
  ## (see the XRAM flag below)&lt;br /&gt;
  LINKER_SCRIPT_PATH := arch/cortexM3_stm32f2/stm32f207ig_stm3220g-eval/&lt;br /&gt;
  #LINKER_SCRIPT := $(LINKER_SCRIPT_PATH)stm32_1m+128k_rom.ld&lt;br /&gt;
  #LINKER_SCRIPT := $(LINKER_SCRIPT_PATH)stm32_1m+128k_xram.ld&lt;br /&gt;
  LINKER_SCRIPT := $(LINKER_SCRIPT_PATH)stm32_1m+128k_all_in_xram.ld&lt;br /&gt;
  &lt;br /&gt;
  ## Enable/disable initialization of external RAM at boot. Three options:&lt;br /&gt;
  ## __ENABLE_XRAM : If you want the heap in xram (with an appropriate linker&lt;br /&gt;
  ## script selected above)&lt;br /&gt;
  ## __ENABLE_XRAM and __CODE_IN_XRAM : Debug mode with code + stack + heap&lt;br /&gt;
  ## in xram (with an appropriate linker script selected above)&lt;br /&gt;
  ## none selected : don&#039;t use xram (with an appropriate linker script&lt;br /&gt;
  ## selected above)&lt;br /&gt;
  #XRAM := -D__ENABLE_XRAM&lt;br /&gt;
  XRAM := -D__ENABLE_XRAM -D__CODE_IN_XRAM&lt;br /&gt;
  &lt;br /&gt;
endif&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As can be seen, there are two options for this board: LINKER_SCRIPT and XRAM. The comments explain in detail the meaning of there options, so it isn&#039;t necessary to further explain them.&lt;br /&gt;
&lt;br /&gt;
After modifying configuration files it is recommended to do a make clean; make (or in the Netbeans IDE, to click on the &amp;quot;Clean and build project&amp;quot; button) to be sure that changes are applied.&lt;br /&gt;
&lt;br /&gt;
== Loading code ==&lt;br /&gt;
&lt;br /&gt;
As explained before, there are more than one linker script for this board, and the selected linker script affects the way code should be loaded on the board.&lt;br /&gt;
&lt;br /&gt;
===stm32_1m+128k_all_in_xram.ld===&lt;br /&gt;
This is the default linker script, it is very useful for debugging code on this board, as it locates everything (code, stack, heap) in the external RAM. It has the disadvantage that the loaded code is lost upon reboot (being in a volatile memory) and that code will run ~10 times slower due to external RAM access timings, but for debugging, these are not issues.&lt;br /&gt;
&lt;br /&gt;
To be able to use this linker script you need to program a bootloader into the microcontroller&#039;s FLASH memory that allows code loading to the external RAM as well as forwarding interrupts there.&lt;br /&gt;
This bootloader is in the &#039;&#039;miosix/_tools/bootloaders/stm32/uc_loader_stm3220g-eval&#039;&#039; directory, and information on how to install it can be found in the &#039;&#039;miosix/_doc/textdoc/stm32-bootloader.txt&#039;&#039; file. For programming the bootloader the [http://sourceforge.net/projects/stm32flash stm32flash] tool can be used.&lt;br /&gt;
&lt;br /&gt;
===stm32_1m+128k_rom.ld and stm32_1m+128k_xram.ld===&lt;br /&gt;
&lt;br /&gt;
These linker scripts put the code in FLASH, so you need to program the microcontroller&#039;s FLASH every time you change your code, but code will run faster and won&#039;t be lost at each reboot.&lt;br /&gt;
&lt;br /&gt;
A simple way to load code in FLASH is to use the stm32flash tool. After having installed it on your system, all you need to do is to connect a serial cable between the USART1 connector on the board and your PC. USB to serial adapters work well if you don&#039;t have a serial port. Then, flip up the boot0 switch on your board, and hit the Reset key.&lt;br /&gt;
On the PC side, you&#039;ll need to run the&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
stm32flash -w main.hex -v /dev/ttyUSB0&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Of course, replace /dev/ttyUSB0 with your serial port device name.&lt;br /&gt;
After that, flip down the boot0 switch and hit again Reset. The code you have loaded should start.&lt;br /&gt;
&lt;br /&gt;
== Reading printf output ==&lt;br /&gt;
&lt;br /&gt;
The board support package of this board simply redirects printf to the serial port USART3. The board has an RS232 connector, so you&#039;ll simply need to connect it to your computer via a serial cable, or use an USB to serial adapter connected to pins PC10 (USART3 TX) and PC11 (USART3 RX), which are exposed on pins 36 (PC10) and 35 (PC11) of CN4.&lt;br /&gt;
The serial port baudrate is set to 19200baud, 8N1.&lt;br /&gt;
&lt;br /&gt;
[[File:Stm3220g serial.jpg|frame|Location of serial pins]]&lt;br /&gt;
&lt;br /&gt;
On Linux you can use screen. Open a terminal and type &#039;&#039;screen /dev/ttyUSB0 19200&#039;&#039; (Note that to quit from screen you need to type &amp;quot;Ctrl-C, \&amp;quot;). You&#039;ll need to change /dev/ttyUSB0 with your serial port device name.&lt;br /&gt;
&lt;br /&gt;
On windows you can use HyperTerminal, you need to configure it to use the required baud rate, no flow control, and select the correct COM port device name.&lt;br /&gt;
&lt;br /&gt;
== In circuit debugging ==&lt;br /&gt;
&lt;br /&gt;
In-circuit debugging requires an USB to JTAG adapter. Ther recomended one is the [https://www.olimex.com/Products/ARM/JTAG/ARM-USB-OCD ARM-USB-OCD]. If you use a different one, you may need to modify the &#039;&#039;miosix/arch/arm7_lpc2000/lpc2138_miosix_board/lpc2138_armusbocd.cfg&#039;&#039; to adapt it to your JTAG tool.&lt;br /&gt;
&lt;br /&gt;
Before you begin you should note that the Miosix kernel will put the CPU to a low power state when no thread is running. This low power state will usually confuse debuggers and make them lose sync with the CPU. To avoid this you need to edit the [[miosix_settings.h|miosix/config/miosix_settings.h]] file and uncomment &#039;&#039;#define JTAG_DISABLE_SLEEP&#039;&#039; line. This will prevent the kernel from putting the CPU in its low power state making debugging possible.&lt;br /&gt;
Also, to be able to precisely single-step your code you need to disable compiler optimizations as gdb is incapable of reliably debug an optimized code. The option is in the miosix/config/Makefile.inc file and is the &#039;&#039;OPT_OPTIMIZATION := -O0&#039;&#039; that should be uncommented while the other lines related to the same option should be commented out.&lt;br /&gt;
&lt;br /&gt;
After modifying configuration files it is recommended to do a &#039;&#039;make clean; make&#039;&#039; (or in the Netbeans IDE, to click on the &amp;quot;Clean and build project&amp;quot; button) to be sure that changes are applied.&lt;br /&gt;
&lt;br /&gt;
On the software side, you need to open two shells. In one do a&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo openocd -f miosix/arch/cortexM3_stm32f2/stm32f207ig_stm3220g-eval/stm3220g_eval.cfg&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will start the OpenOCD program that will connect to the board and listen for GDB connections.&lt;br /&gt;
&lt;br /&gt;
In the second shell type the following commands&lt;br /&gt;
&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;
target remote :3333&lt;br /&gt;
monitor soft_reset_halt&lt;br /&gt;
load&lt;br /&gt;
break main&lt;br /&gt;
continue&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first command will start the gdb debugger. The following commands are typed into the gdb console, and tell it to connect to OpenOCD, reset the board and stop at the beginning of main()&lt;br /&gt;
Please not that the load command implies that you are using the stm32_512k+64k_all_in_xram.ld linker script, and will instruct gdb to load your code in RAM. If you are using another linker script that loads code in FLASH you&#039;ll need to replace this command with a&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
monitor flash write_image erase main.bin 0x08000000&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
that will program the FLASH memory.&lt;br /&gt;
&lt;br /&gt;
From there on, have a look at [[Quick_start]] for debugger commands.&lt;br /&gt;
&lt;br /&gt;
== (Optional) Configuring the Netbeans IDE ==&lt;br /&gt;
To have a fully working code completion that can also resolve the board-specific symbols, right click on the project, go to Set Configuration and select the right board.&lt;br /&gt;
&lt;br /&gt;
[[File:Netbeans-config.png]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Boards]]&lt;/div&gt;</summary>
		<author><name>Daniele.cattaneo</name></author>
	</entry>
	<entry>
		<id>https://miosix.org/wiki/index.php?title=File:Stm3220g_serial.jpg&amp;diff=368</id>
		<title>File:Stm3220g serial.jpg</title>
		<link rel="alternate" type="text/html" href="https://miosix.org/wiki/index.php?title=File:Stm3220g_serial.jpg&amp;diff=368"/>
		<updated>2026-03-14T21:03:21Z</updated>

		<summary type="html">&lt;p&gt;Daniele.cattaneo: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Location of serial pins on stm3220g board&lt;/div&gt;</summary>
		<author><name>Daniele.cattaneo</name></author>
	</entry>
	<entry>
		<id>https://miosix.org/wiki/index.php?title=Stm32f207ig_stm3220g-eval&amp;diff=367</id>
		<title>Stm32f207ig stm3220g-eval</title>
		<link rel="alternate" type="text/html" href="https://miosix.org/wiki/index.php?title=Stm32f207ig_stm3220g-eval&amp;diff=367"/>
		<updated>2026-03-14T20:59:19Z</updated>

		<summary type="html">&lt;p&gt;Daniele.cattaneo: Add serial pin location image&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This board has an STM32F207IG, a Cortex-M3 running at 120MHz with 1MB of FLASH and 128KB of RAM, plus 2MB of external SRAM. In addtion, the board has some nice peripherals including an USB port and a 320x240 LCD display.&lt;br /&gt;
Also, there is a microSD socket allowing filesystem support. Due to GPIO conflicts between the USART and SDIO the SD card works in 1-bit mode instead of 4-bit, thus write speed is limited in this board.&lt;br /&gt;
&lt;br /&gt;
To develop for this board you&#039;ll need an USB to serial adapter to be able to deploy your code to the board through its serial bootloader as well as to be able to see debug messages as printf is redirected to the serial port on this board. Optionally, you&#039;ll need a JTAG in circuit debugger compatible with OpenOCD and Linux, an [https://www.olimex.com/Products/ARM/JTAG/ARM-USB-OCD ARM-USB-OCD] was tested succesfully.&lt;br /&gt;
&lt;br /&gt;
[[File:Stm3220g-eval.jpg|frameless]]&lt;br /&gt;
&lt;br /&gt;
== Configuring the kernel ==&lt;br /&gt;
&lt;br /&gt;
The minimum configuration required is to edit the [[Makefile.inc|miosix/config/Makefile.inc]] file to uncomment the &#039;&#039;OPT_BOARD := stm32f207ig_stm3220g-eval&#039;&#039; line. If you had compiled the kernel before, it is recommended to do a &#039;&#039;make clean&#039;&#039; (or in the Netbeans IDE, to click on the &amp;quot;Clean project&amp;quot; button) to avoid leaving object files around. After, do a &#039;&#039;make&#039;&#039; to compile.&lt;br /&gt;
&lt;br /&gt;
In addition, this board has a couple of board-specific options in the Makefile.inc file. For convenience, the relevant part of that configuration file is reported here so as to be easily located within the file&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
##---------------------------------------------------------------------------&lt;br /&gt;
## stm32f207ig_stm3220g-eval&lt;br /&gt;
##&lt;br /&gt;
ifeq ($(OPT_BOARD),stm32f207ig_stm3220g-eval)&lt;br /&gt;
&lt;br /&gt;
  ## Linker script type, there are three options&lt;br /&gt;
  ## 1) Code in FLASH, stack + heap in internal RAM (file *_rom.ld)&lt;br /&gt;
  ##    the most common choice, available for all microcontrollers&lt;br /&gt;
  ## 2) Code in FLASH stack in internal RAM heap in external RAM (file&lt;br /&gt;
  ##    *_xram.ld) useful for hardware like STM3220G-EVAL when big heap is&lt;br /&gt;
  ##    needed. The microcontroller must have an external memory interface.&lt;br /&gt;
  ## 3) Code + stack + heap in external RAM, (file *_all_in_xram.ld)&lt;br /&gt;
  ##    useful for debugging code in hardware like STM3220G-EVAL. Code runs&lt;br /&gt;
  ##    *very* slow compared to FLASH. Works only with a booloader that&lt;br /&gt;
  ##    forwards interrrupts @ 0x64000000 (see miosix/bootloaders for one).&lt;br /&gt;
  ##    The microcontroller must have an external memory interface.&lt;br /&gt;
  ## Warning! enable external ram if you use a linker script that requires it&lt;br /&gt;
  ## (see the XRAM flag below)&lt;br /&gt;
  LINKER_SCRIPT_PATH := arch/cortexM3_stm32f2/stm32f207ig_stm3220g-eval/&lt;br /&gt;
  #LINKER_SCRIPT := $(LINKER_SCRIPT_PATH)stm32_1m+128k_rom.ld&lt;br /&gt;
  #LINKER_SCRIPT := $(LINKER_SCRIPT_PATH)stm32_1m+128k_xram.ld&lt;br /&gt;
  LINKER_SCRIPT := $(LINKER_SCRIPT_PATH)stm32_1m+128k_all_in_xram.ld&lt;br /&gt;
  &lt;br /&gt;
  ## Enable/disable initialization of external RAM at boot. Three options:&lt;br /&gt;
  ## __ENABLE_XRAM : If you want the heap in xram (with an appropriate linker&lt;br /&gt;
  ## script selected above)&lt;br /&gt;
  ## __ENABLE_XRAM and __CODE_IN_XRAM : Debug mode with code + stack + heap&lt;br /&gt;
  ## in xram (with an appropriate linker script selected above)&lt;br /&gt;
  ## none selected : don&#039;t use xram (with an appropriate linker script&lt;br /&gt;
  ## selected above)&lt;br /&gt;
  #XRAM := -D__ENABLE_XRAM&lt;br /&gt;
  XRAM := -D__ENABLE_XRAM -D__CODE_IN_XRAM&lt;br /&gt;
  &lt;br /&gt;
endif&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As can be seen, there are two options for this board: LINKER_SCRIPT and XRAM. The comments explain in detail the meaning of there options, so it isn&#039;t necessary to further explain them.&lt;br /&gt;
&lt;br /&gt;
After modifying configuration files it is recommended to do a make clean; make (or in the Netbeans IDE, to click on the &amp;quot;Clean and build project&amp;quot; button) to be sure that changes are applied.&lt;br /&gt;
&lt;br /&gt;
== Loading code ==&lt;br /&gt;
&lt;br /&gt;
As explained before, there are more than one linker script for this board, and the selected linker script affects the way code should be loaded on the board.&lt;br /&gt;
&lt;br /&gt;
===stm32_1m+128k_all_in_xram.ld===&lt;br /&gt;
This is the default linker script, it is very useful for debugging code on this board, as it locates everything (code, stack, heap) in the external RAM. It has the disadvantage that the loaded code is lost upon reboot (being in a volatile memory) and that code will run ~10 times slower due to external RAM access timings, but for debugging, these are not issues.&lt;br /&gt;
&lt;br /&gt;
To be able to use this linker script you need to program a bootloader into the microcontroller&#039;s FLASH memory that allows code loading to the external RAM as well as forwarding interrupts there.&lt;br /&gt;
This bootloader is in the &#039;&#039;miosix/_tools/bootloaders/stm32/uc_loader_stm3220g-eval&#039;&#039; directory, and information on how to install it can be found in the &#039;&#039;miosix/_doc/textdoc/stm32-bootloader.txt&#039;&#039; file. For programming the bootloader the [http://sourceforge.net/projects/stm32flash stm32flash] tool can be used.&lt;br /&gt;
&lt;br /&gt;
===stm32_1m+128k_rom.ld and stm32_1m+128k_xram.ld===&lt;br /&gt;
&lt;br /&gt;
These linker scripts put the code in FLASH, so you need to program the microcontroller&#039;s FLASH every time you change your code, but code will run faster and won&#039;t be lost at each reboot.&lt;br /&gt;
&lt;br /&gt;
A simple way to load code in FLASH is to use the stm32flash tool. After having installed it on your system, all you need to do is to connect a serial cable between the USART1 connector on the board and your PC. USB to serial adapters work well if you don&#039;t have a serial port. Then, flip up the boot0 switch on your board, and hit the Reset key.&lt;br /&gt;
On the PC side, you&#039;ll need to run the&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
stm32flash -w main.hex -v /dev/ttyUSB0&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Of course, replace /dev/ttyUSB0 with your serial port device name.&lt;br /&gt;
After that, flip down the boot0 switch and hit again Reset. The code you have loaded should start.&lt;br /&gt;
&lt;br /&gt;
== Reading printf output ==&lt;br /&gt;
&lt;br /&gt;
The board support package of this board simply redirects printf to the serial port USART3. The board has an RS232 connector, so you&#039;ll simply need to connect it to your computer via a serial cable, or use an USB to serial adapter connected to pins PC10 (USART3 TX) and PC11 (USART3 RX), which are exposed on pins 36 (PC10) and 35 (PC11) of CN4.&lt;br /&gt;
The serial port baudrate is set to 19200baud, 8N1.&lt;br /&gt;
&lt;br /&gt;
[[File:Stm32f3220g serial.jpg|thumb|Location of the serial pins]]&lt;br /&gt;
&lt;br /&gt;
On Linux you can use screen. Open a terminal and type &#039;&#039;screen /dev/ttyUSB0 19200&#039;&#039; (Note that to quit from screen you need to type &amp;quot;Ctrl-C, \&amp;quot;). You&#039;ll need to change /dev/ttyUSB0 with your serial port device name.&lt;br /&gt;
&lt;br /&gt;
On windows you can use HyperTerminal, you need to configure it to use the required baud rate, no flow control, and select the correct COM port device name.&lt;br /&gt;
&lt;br /&gt;
== In circuit debugging ==&lt;br /&gt;
&lt;br /&gt;
In-circuit debugging requires an USB to JTAG adapter. Ther recomended one is the [https://www.olimex.com/Products/ARM/JTAG/ARM-USB-OCD ARM-USB-OCD]. If you use a different one, you may need to modify the &#039;&#039;miosix/arch/arm7_lpc2000/lpc2138_miosix_board/lpc2138_armusbocd.cfg&#039;&#039; to adapt it to your JTAG tool.&lt;br /&gt;
&lt;br /&gt;
Before you begin you should note that the Miosix kernel will put the CPU to a low power state when no thread is running. This low power state will usually confuse debuggers and make them lose sync with the CPU. To avoid this you need to edit the [[miosix_settings.h|miosix/config/miosix_settings.h]] file and uncomment &#039;&#039;#define JTAG_DISABLE_SLEEP&#039;&#039; line. This will prevent the kernel from putting the CPU in its low power state making debugging possible.&lt;br /&gt;
Also, to be able to precisely single-step your code you need to disable compiler optimizations as gdb is incapable of reliably debug an optimized code. The option is in the miosix/config/Makefile.inc file and is the &#039;&#039;OPT_OPTIMIZATION := -O0&#039;&#039; that should be uncommented while the other lines related to the same option should be commented out.&lt;br /&gt;
&lt;br /&gt;
After modifying configuration files it is recommended to do a &#039;&#039;make clean; make&#039;&#039; (or in the Netbeans IDE, to click on the &amp;quot;Clean and build project&amp;quot; button) to be sure that changes are applied.&lt;br /&gt;
&lt;br /&gt;
On the software side, you need to open two shells. In one do a&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo openocd -f miosix/arch/cortexM3_stm32f2/stm32f207ig_stm3220g-eval/stm3220g_eval.cfg&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will start the OpenOCD program that will connect to the board and listen for GDB connections.&lt;br /&gt;
&lt;br /&gt;
In the second shell type the following commands&lt;br /&gt;
&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;
target remote :3333&lt;br /&gt;
monitor soft_reset_halt&lt;br /&gt;
load&lt;br /&gt;
break main&lt;br /&gt;
continue&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first command will start the gdb debugger. The following commands are typed into the gdb console, and tell it to connect to OpenOCD, reset the board and stop at the beginning of main()&lt;br /&gt;
Please not that the load command implies that you are using the stm32_512k+64k_all_in_xram.ld linker script, and will instruct gdb to load your code in RAM. If you are using another linker script that loads code in FLASH you&#039;ll need to replace this command with a&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
monitor flash write_image erase main.bin 0x08000000&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
that will program the FLASH memory.&lt;br /&gt;
&lt;br /&gt;
From there on, have a look at [[Quick_start]] for debugger commands.&lt;br /&gt;
&lt;br /&gt;
== (Optional) Configuring the Netbeans IDE ==&lt;br /&gt;
To have a fully working code completion that can also resolve the board-specific symbols, right click on the project, go to Set Configuration and select the right board.&lt;br /&gt;
&lt;br /&gt;
[[File:Netbeans-config.png]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Boards]]&lt;/div&gt;</summary>
		<author><name>Daniele.cattaneo</name></author>
	</entry>
	<entry>
		<id>https://miosix.org/wiki/index.php?title=File:Stm32f3220g_serial.jpg&amp;diff=366</id>
		<title>File:Stm32f3220g serial.jpg</title>
		<link rel="alternate" type="text/html" href="https://miosix.org/wiki/index.php?title=File:Stm32f3220g_serial.jpg&amp;diff=366"/>
		<updated>2026-03-14T20:58:16Z</updated>

		<summary type="html">&lt;p&gt;Daniele.cattaneo: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Serial TX/RX pins location on stm3220g board.&lt;/div&gt;</summary>
		<author><name>Daniele.cattaneo</name></author>
	</entry>
	<entry>
		<id>https://miosix.org/wiki/index.php?title=Miosix_3&amp;diff=365</id>
		<title>Miosix 3</title>
		<link rel="alternate" type="text/html" href="https://miosix.org/wiki/index.php?title=Miosix_3&amp;diff=365"/>
		<updated>2026-03-12T14:15:19Z</updated>

		<summary type="html">&lt;p&gt;Daniele.cattaneo: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;TODO list for Miosix 3 for development purposes&lt;br /&gt;
* CMake in mainline&lt;br /&gt;
** Basato sul CMake di Skyward&lt;br /&gt;
* Restructuring driver per deduplicare&lt;br /&gt;
* Eliminazione codice di startup di ST e delle define stupid CLOCK512MHZ=5120000000&lt;br /&gt;
** Driver PLL&lt;br /&gt;
* Modifica driver per interrupt registrabili a runtime&lt;br /&gt;
* Aggiornamento dei CMSIS&lt;br /&gt;
* Split board e chip&lt;br /&gt;
* Driver della seriale rifatto e ripulito&lt;br /&gt;
* Compressione .data in elf processi&lt;br /&gt;
* Compressione kernel in RAM&lt;/div&gt;</summary>
		<author><name>Daniele.cattaneo</name></author>
	</entry>
	<entry>
		<id>https://miosix.org/wiki/index.php?title=Mxgui_OLED_example&amp;diff=357</id>
		<title>Mxgui OLED example</title>
		<link rel="alternate" type="text/html" href="https://miosix.org/wiki/index.php?title=Mxgui_OLED_example&amp;diff=357"/>
		<updated>2025-12-18T00:18:10Z</updated>

		<summary type="html">&lt;p&gt;Daniele.cattaneo: Update instructions to latest Miosix version.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Before you begin =&lt;br /&gt;
&lt;br /&gt;
This tutorial is mainly focused at showing&lt;br /&gt;
* How to add Mxgui to your project&lt;br /&gt;
* How to drive a small OLED display that can be easily found on ebay with Mxgui&lt;br /&gt;
&lt;br /&gt;
[[File:Small_oled.jpg]]&lt;br /&gt;
&lt;br /&gt;
This tutorial assumes that you have read the [[Miosix and git workflow]] and that you have already downloaded and configured the kernel.&lt;br /&gt;
The code of this example can be found in the mxgui library itself https://github.com/fedetft/mxgui/tree/master/_examples/display_ly091wg14&lt;br /&gt;
&lt;br /&gt;
= Configuration =&lt;br /&gt;
&lt;br /&gt;
In the Miosix top-level directory (or in the directory of your project if you are using an out of git tree project download the mxgui library. If you are under a git repository&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git submodule add https://github.com/fedetft/mxgui.git&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or if your project directory is not under git&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/mxgui.git&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you are using an out of git tree project setup is is recomended to copy the mxgui/config/mxgui_settings.h file in your project config directory as you&#039;ll need to edit it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
cp mxgui/config/mxgui_settings.h config&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now edit your makefile to add the following:&lt;br /&gt;
&lt;br /&gt;
Add the mxgui directory to SUBDIRS so when you run make, the graphics library will be compiled&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
SUBDIRS += mxgui&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Add libmxgui.a to LIBS so the the graphics library will be linked&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
LIBS := mxgui/libmxgui.a&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Add both the mxgui directory and the directory one level upper to INCLUDE_DIRS so includes will work&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
INCLUDE_DIRS := -Imxgui&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, edit mxgui_settings.h as follows, commenting out the following line.&lt;br /&gt;
The purpose of this change is to disable the input module of the library, as in this example we don&#039;t have a touchscreen driver.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
#define MXGUI_LEVEL_2&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Replace your main with the example code and edit it as needed to match the pins to the ones of the display&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
cp mxgui/_examples/display_ly091wg14/main.cpp .&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Build the example with make, and flash it with make program.&lt;/div&gt;</summary>
		<author><name>Daniele.cattaneo</name></author>
	</entry>
	<entry>
		<id>https://miosix.org/wiki/index.php?title=Multicore&amp;diff=352</id>
		<title>Multicore</title>
		<link rel="alternate" type="text/html" href="https://miosix.org/wiki/index.php?title=Multicore&amp;diff=352"/>
		<updated>2025-04-01T16:24:09Z</updated>

		<summary type="html">&lt;p&gt;Daniele.cattaneo: Created page with &amp;quot;Since release 3.0, Miosix supports multicore (SMP) microcontrollers, such as the RP2040. SMP support is required in three key areas: boot, locking, interrupts and scheduler. The kernel is configured with SMP enabled if the board configuration defines the macro WITH_SMP, otherwise only the first core is used.  == SMP interfaces ==  SMP-specific functions that need to be implemented by each architecture port are defined in smp.h. Other interfaces related to SMP support, bu...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Since release 3.0, Miosix supports multicore (SMP) microcontrollers, such as the RP2040.&lt;br /&gt;
SMP support is required in three key areas: boot, locking, interrupts and scheduler.&lt;br /&gt;
The kernel is configured with SMP enabled if the board configuration defines the macro WITH_SMP, otherwise only the first core is used.&lt;br /&gt;
&lt;br /&gt;
== SMP interfaces ==&lt;br /&gt;
&lt;br /&gt;
SMP-specific functions that need to be implemented by each architecture port are defined in smp.h.&lt;br /&gt;
Other interfaces related to SMP support, but not specific to it, are os_timer.h, interrupts.h, cpu_const.h and atomic_ops.h.&lt;br /&gt;
&lt;br /&gt;
== Boot ==&lt;br /&gt;
&lt;br /&gt;
At boot, if SMP is enabled, Miosix calls a platform-specific function defined in smp.h called IRQinitSMP().&lt;br /&gt;
This function is responsible early at boot for doing the following:&lt;br /&gt;
&lt;br /&gt;
* Allocating a system stack (in ARM parlance, the stack for interrupt handlers) for all non-zero cores.&lt;br /&gt;
* Starting up all other cores (except core 0 which is already started up) and configuring their system stacks and process stacks (in ARM parlance, the stack for running non-interrupt code).&lt;br /&gt;
* Configuring the interrupt vectors for all cores to be the same as core 0 (the interrupt vectors are shared for all cores, but the enabled/disabled state must be per-core).&lt;br /&gt;
* Initializing and starting the OS timer for all cores included core 0.&lt;br /&gt;
* Jumping to the specified main function in all cores.&lt;br /&gt;
&lt;br /&gt;
At the end of this function, all other cores must be up enough to be able to immediately process a IRQinvokeSchedulerOnCore or an IRQcallOnCore, which will be discussed later.&lt;br /&gt;
&lt;br /&gt;
== Locking ==&lt;br /&gt;
&lt;br /&gt;
When in kernel mode, the hardware implicitly creates one special &amp;quot;thread&amp;quot; that needs to be synchronized against: interrupt handlers.&lt;br /&gt;
Interrupt handlers access OS state (specifically, peripheral driver state, or scheduler state for the timer interrupt) but --- barring magic shenanigans that are complicated to implement and add significant overhead --- cannot yield to another thread.&lt;br /&gt;
Hence one cannot use conventional synchronization primitives.&lt;br /&gt;
&lt;br /&gt;
In the single core case, the easiest way to ensure mutual exclusion with an interrupt handler is to disable interrupts altogether.&lt;br /&gt;
Since preemption is driven by interrupts (even wakeups, at least in ARM architectures, due to the use of PendSV for implementing the Yield primitive) this also has the effect of disabling preemption.&lt;br /&gt;
Disabling preemption means we also are in mutual exclusion with other pieces of code that disable/enable interrupts.&lt;br /&gt;
There is no need to disable interrupts in interrupt handlers because they already are assumed to run in mutual exclusion between each other.&lt;br /&gt;
In reality this is not strictly true on platforms that have nested interrupts but Miosix disables nested interrupts.&lt;br /&gt;
&lt;br /&gt;
In an SMP architectures, being in an interrupt handler and/or disabling interrupts does &#039;&#039;&#039;not&#039;&#039;&#039; ensure mutual exclusion with other interrupt handlers or with other pieces of code which run with interrupts disabled.&lt;br /&gt;
This is because interrupts are per-core, and the interrupt disabling flag is also per-core.&lt;br /&gt;
Even with interrupts disabled, or in an interrupt handler, the other cores can run code in parallel, with interrupts disabled or not, or even in an interrupt handler.&lt;br /&gt;
&lt;br /&gt;
The solution to this is to use spinlocks.&lt;br /&gt;
A fundamental property of spinlocks, as opposed to other synchronization methods, is that they do not require anything from the operating system, they can always be used even with preemption disabled or in an interrupt handler.&lt;br /&gt;
Unfortunately they also burn CPU cycles, but at least on ARM the WFE instruction can be used to put a core to sleep while waiting for a spinlock to be released, and the SEV instruction can wake all cores sleeping on a WFE when a spinlock is released.&lt;br /&gt;
These instructions work even with interrupts disabled.&lt;/div&gt;</summary>
		<author><name>Daniele.cattaneo</name></author>
	</entry>
	<entry>
		<id>https://miosix.org/wiki/index.php?title=User:Daniele.cattaneo&amp;diff=351</id>
		<title>User:Daniele.cattaneo</title>
		<link rel="alternate" type="text/html" href="https://miosix.org/wiki/index.php?title=User:Daniele.cattaneo&amp;diff=351"/>
		<updated>2025-03-28T14:45:38Z</updated>

		<summary type="html">&lt;p&gt;Daniele.cattaneo: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Hi :)&lt;br /&gt;
&lt;br /&gt;
Github (work): [https://github.com/danielecattaneo]&lt;br /&gt;
&lt;br /&gt;
Github (personal): Secret&lt;br /&gt;
&lt;br /&gt;
[[Miosix in emulation]]&lt;br /&gt;
&lt;br /&gt;
[[arch directory restructuring]]&lt;br /&gt;
&lt;br /&gt;
[[Miosix 3]]&lt;br /&gt;
&lt;br /&gt;
[[Multicore]]&lt;/div&gt;</summary>
		<author><name>Daniele.cattaneo</name></author>
	</entry>
	<entry>
		<id>https://miosix.org/wiki/index.php?title=Arch_directory_restructuring&amp;diff=350</id>
		<title>Arch directory restructuring</title>
		<link rel="alternate" type="text/html" href="https://miosix.org/wiki/index.php?title=Arch_directory_restructuring&amp;diff=350"/>
		<updated>2024-10-23T00:12:45Z</updated>

		<summary type="html">&lt;p&gt;Daniele.cattaneo: More details that were missing&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The &#039;&#039;arch&#039;&#039; directory is a mess with lots of copy-pasted code. Ideally it should be &#039;&#039;&#039;consistently and logically organized&#039;&#039;&#039;: each directory should have a documented purpose in order to leave as little doubt as possible about &#039;&#039;what goes where&#039;&#039;. Additionally, each directory&#039;s purpose makes sense in the overall structure, without overlaps between the scope of each directory.&lt;br /&gt;
At the moment however we observe this is not the case. We believe that in order to make the future growth of Miosix simpler and faster, the right moment to rectify the situation is now.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Update 31/12/2023&#039;&#039; I discovered a bug in the testing branch of Miosix which was caused by the copy-pasting of gpio_impl.h: version 1.4 (sic, see comments) didn&#039;t have the alternateFunction method of Gpio, even though serial_stm32.cpp assumes it always exists. (btw don&#039;t we have git? manual versioning in comments is not a robust practice!!!) I bet other similar bugs exist.&lt;br /&gt;
&lt;br /&gt;
== Some definitions ==&lt;br /&gt;
&lt;br /&gt;
Common sense suggests the following taxonomy of parts for MCU-equipped devices targeted by Miosix:&lt;br /&gt;
* Board: The device itself being targeted. It&#039;s called a board because nobody has observed any MCU wired with point-to-point wiring yet (citation needed). Includes the MCU itself plus any peripheral external to the MCU but &#039;&#039;&#039;driven&#039;&#039;&#039; by it.&lt;br /&gt;
* Chip: The MCU itself. May come in RAM/OTP/ROM/Flash size variations, which are mostly ignored.&lt;br /&gt;
* Chip family: A set of MCU types from the same manufacturer with the same microprocessor core but potentially different set of peripherals. While the available set of peripherals may vary, the behaviour and I/O ports of each kind of peripheral are the same across the entire family. Thanks to the brilliant ideas of the various marketing departments of each vendor, the classification here can get very fluid.&lt;br /&gt;
* Core: The microprocessor core used by a given chip family.&lt;br /&gt;
&lt;br /&gt;
Let&#039;s take as an example the classic stm32f4discovery board that is the most common development device for Miosix:&lt;br /&gt;
* The board is the stm32f4discovery itself. It includes the chip, and miscellaneous peripherals such as an accelerometer and a Cirrus Logic audio chip. The STLink programming interface and the power supply are &#039;&#039;&#039;not&#039;&#039;&#039; considered relevant parts of the board for Miosix, as the MCU is not in control of what they do.&lt;br /&gt;
* The chip is an STM32F407VGT6. The VGT6 suffix of the chip name specifies package (100 pin LQFP), Flash size (1MB) and temperature range options (see the datasheet at the &amp;quot;Ordering Information&amp;quot; page).&lt;br /&gt;
* The chip family is STM32F4. This can be inferred by the fact that all available chips with this prefix in the part name share the same reference manual. (Notice that this is a slight simplification of reality because there are STM32F4 chips that are not covered by the same reference manual as the STM32F407 but the point we want to get across is that multiple MCUs share roughly the same silicon behaviour and drivers)&lt;br /&gt;
* The core is an ARM Cortex M4, as stated in the datasheet. Roughly, ST buys the Verilog for the core from ARM and then takes care of the manufacturing. As far as we know, ARM&#039;s licence only allows ST to customize the core in very limited ways, so all Cortex M4 cores should behave basically the same, even from other vendors. Tunables may be things like the number of MPU regions or whether floating point is available or not, which may be important or not.&lt;br /&gt;
&lt;br /&gt;
=== What is an architecture? ===&lt;br /&gt;
&lt;br /&gt;
One definition we did not give is the definition of what an &#039;&#039;&#039;architecture&#039;&#039;&#039; is. The reason is that there is no accepted definition for this term, especially for forum pundits and bloggers, but also in academia. The RISC school of thought (Patterson/Hennessy and their spawn) historically associated an &#039;&#039;architecture&#039;&#039; with a combination of what are more specifically called the &#039;&#039;instruction set architecture&#039;&#039; (ISA) and the &#039;&#039;microarchitecture&#039;&#039; of a core. The ISA is the overall structure and design of the instructions, as opposed to the &#039;&#039;instruction set&#039;&#039; proper which is the set of instructions accepted by a specific core. The &#039;&#039;&#039;microarchitecture&#039;&#039;&#039; is the overall internal design of the core itself.&lt;br /&gt;
&lt;br /&gt;
Their thesis was that the microarchitecture design will follow naturally from the definition of the ISA, hence simpler ISAs (RISC) to implement always lead to more efficient and generally better cores. Therefore one can consider the &#039;&#039;&#039;architecture&#039;&#039;&#039; to be primarily determined by the ISA. However the industry has proven them wrong, and the most glaring example are Intel x86 chips, which have seen an increasing variety of microarchitectures implementing the same ISA (variously extended of course) with wildly varying levels of (non-)efficiency (in all possible ramifications of &amp;quot;efficiency&amp;quot;). Closer to Miosix&#039;s targets, the ARM ISA has been extended so much over the years that its core RISC design has now evolved to basically a traditional CISC ISA, but ARM chips still come in every possible size and flavour.&lt;br /&gt;
&lt;br /&gt;
When we talk about x86 &amp;quot;architectures&amp;quot; or ARM &amp;quot;architectures&amp;quot;, but do we mean desktop-grade chips or microcontrollers? Even though they have the same &amp;quot;architecture&amp;quot; the cores in these two classes of chips have nothing to do with each other, they don&#039;t even share the same instruction decoder probably. Hence our conclusion that the word &amp;quot;architecture&amp;quot; has now lost all useful meaning for our purposes, and is only useful for void parlor chitchat.&lt;br /&gt;
&lt;br /&gt;
And then we come to Miosix which defines &amp;quot;architecture&amp;quot; (arch) as... a board. Which is not what anyone means when they talk about architecture of anything. For Miosix, an &amp;quot;architecture&amp;quot; is more like what in common parlance would be meant as a &amp;quot;platform&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
== Current structure ==&lt;br /&gt;
&lt;br /&gt;
Here&#039;s a schematic diagram of how the Miosix &#039;&#039;arch&#039;&#039; directory (plus related directories) is configured. In the following &#039;&#039;/&#039;&#039; refers to the &#039;&#039;miosix&#039;&#039; directory at the top level of the repository.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
arch                        Architecture-specific files&lt;br /&gt;
  common                      Pool of useful files. Very few files here are common to all archs.&lt;br /&gt;
    CMSIS                       Collection of ARM &amp;amp; vendor headers following the CMSIS standard&lt;br /&gt;
    core                        Board independent drivers required for the OS to function (roughly)&lt;br /&gt;
      atomic_ops_*.h              Core dependent&lt;br /&gt;
      cache_*.cpp/h               Core dependent. This is not required at all for Miosix to work but is nevertheless here&lt;br /&gt;
      *_os_timer.cpp              Chip family dependent&lt;br /&gt;
      endianness_*.h              Core dependent. Should have a generic (slow) implementation but it&#039;s missing.&lt;br /&gt;
      interrupts.h                Umbrella header for interrupts_*.h&lt;br /&gt;
      interrupts_*.h              Core dependent. Misleading name, this is for fault handling.&lt;br /&gt;
      memory_protection.h         Umbrella header for mpu_*.h. Required only for process mode. Name is not consistent with other umbrella headers, should have been &amp;quot;mpu.h&amp;quot;&lt;br /&gt;
      mpu_*.cpp/h                 Core dependent.&lt;br /&gt;
    drivers                     Miscellaneous drivers, which are &amp;quot;common&amp;quot; only very roughly&lt;br /&gt;
      dcc.cpp/h                   Core dependent (but common to all ARM cores apparently)&lt;br /&gt;
      *_adc.cpp/h                 Chip family dependent&lt;br /&gt;
      serial.h                    Umbrella header for *serial*.h&lt;br /&gt;
      *serial*.cpp/h              Chip family dependent&lt;br /&gt;
      sd_*.cpp/h                  Chip family dependent&lt;br /&gt;
      servo_*.cpp/h               Board dependent really, should go into utils&lt;br /&gt;
      *_hardware_rng.cpp/h        Chip family dependent&lt;br /&gt;
      *_rtc.cpp/h                 Chip family dependent&lt;br /&gt;
      *_sgm.cpp/h                 Chip family dependent&lt;br /&gt;
      *_wd.cpp/h                  Chip family dependent&lt;br /&gt;
      *_i2c.cpp/h                 Chip family dependent&lt;br /&gt;
  &amp;lt;board group name&amp;gt;          Board group specific files.&lt;br /&gt;
    common                      Common drivers and configuration for all the boards in the group&lt;br /&gt;
      arch_settings.h             Core dependent. Misleading name, defines requirements for ctxsave&lt;br /&gt;
      interfaces-impl             The actual drivers, most of them required by Miosix to function.&lt;br /&gt;
        arch_registers_impl.h     Chip family dependent. Includes the appropriate register definitions&lt;br /&gt;
        delays.cpp                Chip family dependent as it also depends on ROM/Flash speed. Actually application dependent (!) as cache/prefetch mechanisms can be configured but whatever.&lt;br /&gt;
        gpio_impl.cpp/h           Chip family dependent.&lt;br /&gt;
        portability_impl.h        Core dependent.&lt;br /&gt;
        portability.cpp           Core dependent.&lt;br /&gt;
      drivers                 Miscellaneous drivers not required by Miosix to function, with exceptions (atsam4l clock)&lt;br /&gt;
        *.cpp/h&lt;br /&gt;
    &amp;lt;board name&amp;gt;              Board/chip specific files.&lt;br /&gt;
      core                      Board/chip dependent code required for the OS to function.&lt;br /&gt;
        stage_1_boot.c/cpp/s      Chip dependent. Interrupt vector table, reset handler, clock tree setup, bss/data initialization&lt;br /&gt;
      interfaces_impl         Important board/chip specific drivers, most of them required by Miosix to function.&lt;br /&gt;
        bsp_impl.h              Board dependent. Useful board-specific definitions.&lt;br /&gt;
        bsp.cpp                 Board dependent. Useful board-specific functions.&lt;br /&gt;
        hwmapping.h             Board dependent. GPIO pin definitions.&lt;br /&gt;
        deep_sleep.cpp          Chip family dependent. Optional implementation of deep sleep primitives.&lt;br /&gt;
        delays.cpp              See above. Sometimes it&#039;s here, with no true reason why.&lt;br /&gt;
        arch_registers_impl.h     See above. Sometimes it&#039;s here, depends on chip.&lt;br /&gt;
        ...                     Some boards have extra miscellaneous drivers here&lt;br /&gt;
      *.h                     Some boards have chip registers definitions here (LPC2138)&lt;br /&gt;
      *.cfg                   Some boards have OpenOCD config files here&lt;br /&gt;
      *.ld                    Chip family specific. Linker files for different RAM/Flash configurations&lt;br /&gt;
interfaces                  Headers for hardware interfaces TO miosix (internals) and SOME interfaces OF miosix to the application (APIs). Only commonality is that they are all hardware dependent (while stuff in utils/kernel is &#039;&#039;generally&#039;&#039; hardware independent)&lt;br /&gt;
  arch_registers.h            API. Umbrella for &amp;quot;arch_registers_impl.h&amp;quot;, selected through include search path manipulation.&lt;br /&gt;
  atomic_ops.h                API. Umbrella for &amp;quot;atomic_ops_*.h&amp;quot;, selected through ifdefs.&lt;br /&gt;
  bsp.h                       API + internal prototypes (IRQbspInit, bspInit2). Umbrella for &amp;quot;bsp_impl.h&amp;quot;, selected through include search path manipulation.&lt;br /&gt;
  deep_sleep.h                Internal prototypes only. Not an umbrella header.&lt;br /&gt;
  delays.h                    API. Not an umbrella header.&lt;br /&gt;
  endianness.h                API. Umbrella for &amp;quot;endianness_*.h&amp;quot;, selected through ifdefs.&lt;br /&gt;
  gpio.h                      API. Umbrella for &amp;quot;gpio_impl.h&amp;quot;, selected through include search path manipulation.&lt;br /&gt;
  os_timer.h                  Internal declarations. Not an umbrella header.&lt;br /&gt;
  portability.h               Internal declarations. Primitives for context switching and syscalls. Umbrella for &amp;quot;portability_impl.h&amp;quot;, selected through include search path manipulation.&lt;br /&gt;
util                        Additional APIs made available for applications as utilities, built on top of kernel primitives or other drivers&lt;br /&gt;
  lcd44780.cpp/h              Driver for Hitachi-standard HD44780 character displays.&lt;br /&gt;
  software_i2c/spi.h          Bit-banged i2c/spi implementations. Arguably drivers.&lt;br /&gt;
  utils.cpp/h                 Memory/CPU usage profiling. Misleading name. Not a driver&lt;br /&gt;
  ...                         Other files are not related to hardware&lt;br /&gt;
config                      Configuration files, user-modifiable&lt;br /&gt;
  Makefile.inc                List of board + selection of board to build for + selection of compile time options through defines passed as argument to the compiler. The first section of the file arguably is not user-modifiable configuration.&lt;br /&gt;
  miosix-settings.h           Global settings selected through defines in header files&lt;br /&gt;
  arch                        Board-dependent settings&lt;br /&gt;
    &amp;lt;board group&amp;gt;&lt;br /&gt;
      &amp;lt;board&amp;gt;&lt;br /&gt;
        board_settings.h      Board-dependent settings selected through defines in header files&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&amp;lt;board group name&amp;gt;&#039;&#039; is defined as the name of the chip core, followed by an underscore, followed by the name of a chip family. &#039;&#039;&amp;lt;board name&amp;gt;&#039;&#039; is defined by the name of the chip, followed by an underscore, followed by a &amp;quot;common name&amp;quot; of the board. For commercial prototyping boards or specific devices, &amp;quot;common name&amp;quot; is derived from the name given by the manufacturer, or a name which is in common use with some exceptions (i.e. stm32f103 bluepill boards are named &amp;quot;breakout&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
Some general patterns can be inferred:&lt;br /&gt;
* Apart from minor exceptions, directories named &#039;&#039;&#039;core&#039;&#039;&#039; contain drivers required for the OS to function.&lt;br /&gt;
* Directories named &#039;&#039;&#039;interfaces_impl&#039;&#039;&#039; generally contain implementations of things defined in /interfaces. Header files in &#039;&#039;&#039;interfaces_impl&#039;&#039;&#039; are always given the ``_impl`` suffix. C++ files are usually not given the &amp;quot;_impl&amp;quot; suffix but sometimes they have it (gpio_impl.cpp).&lt;br /&gt;
* Directories named &#039;&#039;&#039;common&#039;&#039;&#039; contain code shared by multiple boards. No attempt is made to separate different levels of commonality apart from chip-family specific stuff which is grouped by board group.&lt;br /&gt;
&lt;br /&gt;
=== Include paths ===&lt;br /&gt;
&lt;br /&gt;
The current directory structure allows the Makefile to select the implementation of some file by solely changing the include search paths of the compiler. This mostly applies to files in &#039;&#039;&amp;lt;board group name&amp;gt;/&amp;lt;board name&amp;gt;&#039;&#039; and in &#039;&#039;&amp;lt;board group name&amp;gt;/config&#039;&#039;. The Makefile defines several variables that are used to refer to specific paths in the directory tree:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Variable !! Value Pattern !! Scope !! Is config !! Defined by !! Description&lt;br /&gt;
|-&lt;br /&gt;
| LINKER_SCRIPT_PATH || arch/&amp;lt;board group name&amp;gt;/&amp;lt;board name&amp;gt;/ || Board || Yes || Makefile.inc || Directory where the linker scripts are found&lt;br /&gt;
|-&lt;br /&gt;
| LINKER_SCRIPT || $(LINKER_SCRIPT_PATH)/&amp;lt;script&amp;gt;.ld || Board || Yes || Makefile.inc || Path of the linker script&lt;br /&gt;
|-&lt;br /&gt;
| ARCH_INC ||  arch/&amp;lt;board group name&amp;gt;/common || Board group || No || Makefile.inc || Path of the common directory of the board group&lt;br /&gt;
|-&lt;br /&gt;
| BOARD_INC || arch/&amp;lt;board group name&amp;gt;/&amp;lt;board name&amp;gt; || Board || No || Makefile.inc || Path of the board directory&lt;br /&gt;
|-&lt;br /&gt;
| BOOT_FILE || $(BOARD_INC)/core/stage_1_boot.o || Board || No || Makefile.inc || Path of the object file for the board bootstrap code&lt;br /&gt;
|-&lt;br /&gt;
| ARCH_SRC || $(BOARD_INC)/*/*.cpp $(ARCH_INC)/*/*.cpp arch/common/drivers/*.cpp || Board + Board group || No || Sources for the drivers enabled for this board&lt;br /&gt;
|-&lt;br /&gt;
| KPATH || miosix || Global || Yes || Appl. Makefile || Root directory of the kernel files&lt;br /&gt;
|-&lt;br /&gt;
| CONFPATH || $(KPATH) || Global || Yes || Appl. Makefile || Root directory for configuration files&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
For reference, the final include paths, defined by the application makefile, are:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$(CONFPATH)&lt;br /&gt;
$(CONFPATH)/config/$(BOARD_INC)&lt;br /&gt;
$(KPATH)&lt;br /&gt;
$(KPATH)/arch/common&lt;br /&gt;
$(KPATH)/$(ARCH_INC)&lt;br /&gt;
$(KPATH)/$(BOARD_INC)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notice that, despite the name of the defines, there is no distinction between include paths and source paths, as includes are alongside the source. We do not have a problem with this approach, however it results in all includes being publicly available for applications, which is something that is not entirely desirable.&lt;br /&gt;
&lt;br /&gt;
==== Drivers selected by include path ====&lt;br /&gt;
&lt;br /&gt;
Sometimes Miosix&#039;s headers include files that depend on the board selected for building. This of course can give problems when reorganizing files around. The affected files are:&lt;br /&gt;
&lt;br /&gt;
* interfaces/arch_registers.h&lt;br /&gt;
* interfaces/bsp.h&lt;br /&gt;
* interfaces/gpio.h&lt;br /&gt;
* interfaces/portability.h&lt;br /&gt;
&lt;br /&gt;
Overall selecting different files through the include paths is desirable, so we want to avoid adding additional architecture-specific ifdefs as much as possible.&lt;br /&gt;
&lt;br /&gt;
=== Issues ===&lt;br /&gt;
&lt;br /&gt;
Experience has shown this organization has the following problems:&lt;br /&gt;
* What goes where is not well defined due to the vagueness of directory names&lt;br /&gt;
** This leads to files being in the wrong place even though it&#039;s not obvious&lt;br /&gt;
*** servo_* is the most glaring example&lt;br /&gt;
*** The location of delays.cpp and arch_registers_impl.h is also inconsistent&lt;br /&gt;
* The two level board group/board classification does not reflect reality, which leads to missing code sharing opportunities:&lt;br /&gt;
** GPIO implementations are duplicated multiple times as they are common to multiple chip families and not to a single one.&lt;br /&gt;
** Bootstrap code is duplicated multiple times as they are common to boards with the same chip and not common to the board.&lt;br /&gt;
** Portability code (i.e. context save/restore primitives mostly) is duplicated multiple times as they are common to a given core and not to a chip family&lt;br /&gt;
** Linker scripts are also duplicated multiple times&lt;br /&gt;
* Classifications sometimes privilege syntax rather than semantics, in an inconsistent fashion&lt;br /&gt;
** Directories named &#039;&#039;&#039;interfaces_impl&#039;&#039;&#039; contain drivers just like directories named &#039;&#039;&#039;drivers&#039;&#039;&#039;, except that they included from /interfaces.&lt;br /&gt;
** What is &#039;&#039;&#039;common&#039;&#039;&#039; and what is not loosely determined by the amount of code sharing but most stuff not under a &#039;&#039;&#039;common&#039;&#039;&#039; directory is duplicated at least twice&lt;br /&gt;
&lt;br /&gt;
Of course, the root issue is the fluidity of the distinction between chip and chip family, and how each vendor manages and/or defines each family. For instance, STM32 chips all have similar USART (serial) implementations, but at least two versions can be distinguished through different register definitions and feature sets. Therefore the same overall driver can be shared across almost all STM32 chips, however the driver is littered with &#039;&#039;ifdef&#039;&#039;s to single out the specificity of each implementation. There is really no strict distinction to what can be found where, as the vendors can and do mix and match peripherals even amongst themselves. For example, some STM32 chips have Synopsis-designed USB interfaces which can also be found on chips from vendors that are not ST.&lt;br /&gt;
 &lt;br /&gt;
These considerations highlight that the solution to handling the issue of organizing platform-specific code in a consistent way to &#039;&#039;&#039;minimize code duplication&#039;&#039;&#039; is not to &#039;&#039;&#039;add&#039;&#039;&#039; hierarchy levels, but to remove them. This runs contrary from the naive consideration that &amp;quot;Board includes Chip, which belongs to Chip Family, which contains a Core&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
== A proposal ==&lt;br /&gt;
&lt;br /&gt;
Pointing out what&#039;s wrong is easy, fixing it up is hard. Of course &amp;quot;what we should do&amp;quot; is a matter of opinion, and a valid answer to that could even be &amp;quot;nothing&amp;quot;. Overall, what we ultimately want is for all drivers to be decoupled from boards and board groups, in order to be able to classify each driver depending on its actual logical group it belongs to. We can take this opportunity for a more radical restructuring of Miosix&#039;s source tree, or we can opt for more conservative solutions.&lt;br /&gt;
&lt;br /&gt;
=== With classification per device type ===&lt;br /&gt;
&lt;br /&gt;
This proposal is the most radical as it splits the drivers in a completely different way than what is currently done: by device type. For instance all USART drivers go in a &amp;quot;serial&amp;quot; directory, all GPIO drivers go in a GPIO directory, and so on. This approach scales well when there are a lot of drivers around, but completely prevents selection of drivers by using the include paths.&lt;br /&gt;
&lt;br /&gt;
The arch directory has been named &amp;quot;platform&amp;quot; because of our general dislike of the &amp;quot;architecture&amp;quot; word, but that&#039;s really just a bonus. Most other operating systems use &amp;quot;arch&amp;quot; as a directory for drivers and target-specific stuff, so keeping the name &amp;quot;arch&amp;quot; is also an option. We also moved the interfaces headers under the &amp;quot;platform&amp;quot; (&amp;quot;arch&amp;quot;) directory, since they basically are just umbrella headers for various drivers. This loses the distinction of some of them being more essential than others, additional directories can be added for this purpose.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
platform&lt;br /&gt;
  arch_registers.h&lt;br /&gt;
  atomic_ops.h&lt;br /&gt;
  bsp.h&lt;br /&gt;
  deep_sleep.h&lt;br /&gt;
  delays.h&lt;br /&gt;
  endianness.h&lt;br /&gt;
  gpio.h&lt;br /&gt;
  os_timer.h&lt;br /&gt;
  portability.h&lt;br /&gt;
  memory_protection.h&lt;br /&gt;
  interrupts.h&lt;br /&gt;
  mpu.h&lt;br /&gt;
  serial.h&lt;br /&gt;
  arch_registers&lt;br /&gt;
    CMSIS&lt;br /&gt;
    &amp;lt;chip/chip family&amp;gt;&lt;br /&gt;
      arch_registers_impl.h&lt;br /&gt;
      ....h&lt;br /&gt;
  core&lt;br /&gt;
    boot&lt;br /&gt;
      &amp;lt;chip&amp;gt;&lt;br /&gt;
        stage_1_boot.c/cpp/s&lt;br /&gt;
    atomic_ops&lt;br /&gt;
      atomic_ops_*.h&lt;br /&gt;
    os_timer&lt;br /&gt;
      *_os_timer.cpp&lt;br /&gt;
    endianness&lt;br /&gt;
      endianness_*.h&lt;br /&gt;
    faults&lt;br /&gt;
      interrupts_*.h&lt;br /&gt;
    mpu&lt;br /&gt;
      *_mpu.cpp/h&lt;br /&gt;
    portability&lt;br /&gt;
      &amp;lt;core&amp;gt;&lt;br /&gt;
        arch_settings.h&lt;br /&gt;
        portability_impl.h&lt;br /&gt;
        portability.cpp&lt;br /&gt;
    gpio&lt;br /&gt;
      &amp;lt;chip/chip family&amp;gt;&lt;br /&gt;
        gpio_impl.cpp/h&lt;br /&gt;
    delays&lt;br /&gt;
      &amp;lt;chip/chip family&amp;gt;&lt;br /&gt;
        delays.cpp&lt;br /&gt;
  drivers&lt;br /&gt;
    arm_dcc.cpp/h&lt;br /&gt;
    deep_sleep&lt;br /&gt;
      deep_sleep.cpp&lt;br /&gt;
    cache&lt;br /&gt;
      cache_*.cpp/h&lt;br /&gt;
    serial&lt;br /&gt;
      *_serial.cpp/h&lt;br /&gt;
    adc&lt;br /&gt;
      *_adc.cpp/h&lt;br /&gt;
    sd&lt;br /&gt;
      *_sd.cpp/h&lt;br /&gt;
    servo&lt;br /&gt;
      *_servo.cpp/h&lt;br /&gt;
    hardware_rng&lt;br /&gt;
      *_hardware_rng.cpp/h&lt;br /&gt;
    rtc&lt;br /&gt;
      *_rtc.cpp/h&lt;br /&gt;
    sgm&lt;br /&gt;
      *_sgm.cpp/h&lt;br /&gt;
    wd&lt;br /&gt;
      *_wd.cpp/h&lt;br /&gt;
    i2c&lt;br /&gt;
      *_i2c.cpp/h&lt;br /&gt;
      software_i2c.h&lt;br /&gt;
    spi&lt;br /&gt;
      software_spi.h&lt;br /&gt;
    display&lt;br /&gt;
      lcd44780.cpp/h&lt;br /&gt;
    ...&lt;br /&gt;
  board&lt;br /&gt;
    &amp;lt;board&amp;gt;&lt;br /&gt;
      bsp_impl.h&lt;br /&gt;
      bsp.cpp&lt;br /&gt;
      hwmapping.h&lt;br /&gt;
      *.cfg&lt;br /&gt;
  linker_scripts&lt;br /&gt;
    &amp;lt;chip&amp;gt;&lt;br /&gt;
      *.ld&lt;br /&gt;
config&lt;br /&gt;
  Makefile.inc&lt;br /&gt;
  miosix_settings.h&lt;br /&gt;
  &amp;lt;board&amp;gt;&lt;br /&gt;
    board_settings.h&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Without classification per device type ===&lt;br /&gt;
&lt;br /&gt;
This is just the same proposal as before but which classifies drivers only by &amp;quot;manufacturer&amp;quot; or chip. This allows to use the include trick for selecting headers.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
platform&lt;br /&gt;
  arch_registers.h&lt;br /&gt;
  atomic_ops.h&lt;br /&gt;
  bsp.h&lt;br /&gt;
  deep_sleep.h&lt;br /&gt;
  delays.h&lt;br /&gt;
  endianness.h&lt;br /&gt;
  gpio.h&lt;br /&gt;
  os_timer.h&lt;br /&gt;
  portability.h&lt;br /&gt;
  memory_protection.h&lt;br /&gt;
  interrupts.h&lt;br /&gt;
  mpu.h&lt;br /&gt;
  serial.h&lt;br /&gt;
  arch_registers&lt;br /&gt;
    CMSIS&lt;br /&gt;
    &amp;lt;chip/chip family&amp;gt;&lt;br /&gt;
      arch_registers_impl.h&lt;br /&gt;
      ....h&lt;br /&gt;
  core&lt;br /&gt;
    &amp;lt;chip/chip family&amp;gt;&lt;br /&gt;
      stage_1_boot.c/cpp/s&lt;br /&gt;
      *_os_timer.cpp&lt;br /&gt;
      *_mpu.cpp/h&lt;br /&gt;
      gpio_impl.cpp/h&lt;br /&gt;
      delays.cpp&lt;br /&gt;
    &amp;lt;core&amp;gt;&lt;br /&gt;
      atomic_ops_*.h&lt;br /&gt;
      endianness_*.h&lt;br /&gt;
      interrupts_*.h&lt;br /&gt;
      arch_settings.h&lt;br /&gt;
      portability_impl.h&lt;br /&gt;
      portability.cpp&lt;br /&gt;
  drivers&lt;br /&gt;
    dcc.cpp/h&lt;br /&gt;
    *_servo.cpp/h&lt;br /&gt;
    software_i2c.h&lt;br /&gt;
    software_spi.h&lt;br /&gt;
    lcd44780.cpp/h&lt;br /&gt;
    &amp;lt;core&amp;gt;&lt;br /&gt;
      cache_*.cpp/h&lt;br /&gt;
    &amp;lt;chip/chip family&amp;gt;&lt;br /&gt;
      deep_sleep.cpp&lt;br /&gt;
      *_serial.cpp/h&lt;br /&gt;
      *_adc.cpp/h&lt;br /&gt;
      *_sd.cpp/h&lt;br /&gt;
      *_hardware_rng.cpp/h&lt;br /&gt;
      *_rtc.cpp/h&lt;br /&gt;
      *_sgm.cpp/h&lt;br /&gt;
      *_wd.cpp/h&lt;br /&gt;
      *_i2c.cpp/h&lt;br /&gt;
    ...&lt;br /&gt;
  board&lt;br /&gt;
    &amp;lt;board&amp;gt;&lt;br /&gt;
      bsp_impl.h&lt;br /&gt;
      bsp.cpp&lt;br /&gt;
      hwmapping.h&lt;br /&gt;
      *.cfg&lt;br /&gt;
  linker_scripts&lt;br /&gt;
    &amp;lt;chip&amp;gt;&lt;br /&gt;
      *.ld&lt;br /&gt;
config&lt;br /&gt;
  Makefile.inc&lt;br /&gt;
  miosix_settings.h&lt;br /&gt;
  &amp;lt;board&amp;gt;&lt;br /&gt;
    board_settings.h&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== With minimal changes to the existing structure ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
arch&lt;br /&gt;
  common&lt;br /&gt;
    CMSIS&lt;br /&gt;
      core&lt;br /&gt;
        boot&lt;br /&gt;
          &amp;lt;chip&amp;gt;_stage_1_boot.c/cpp/s&lt;br /&gt;
        &amp;lt;core&amp;gt;_portability&lt;br /&gt;
            arch_settings.h&lt;br /&gt;
            portability_impl.h&lt;br /&gt;
            portability.cpp&lt;br /&gt;
        &amp;lt;chip family&amp;gt;&lt;br /&gt;
          delays.cpp&lt;br /&gt;
          gpio_impl.cpp/h&lt;br /&gt;
          deep_sleep.cpp&lt;br /&gt;
        (all other existing files)&lt;br /&gt;
      drivers&lt;br /&gt;
        All miscellaneous drivers in board directory are moved here&lt;br /&gt;
        (all other existing files)&lt;br /&gt;
    linker_scripts&lt;br /&gt;
      &amp;lt;chip&amp;gt;&lt;br /&gt;
        *.ld&lt;br /&gt;
  &amp;lt;board group name&amp;gt;&lt;br /&gt;
    common&lt;br /&gt;
      (should now be empty)&lt;br /&gt;
    &amp;lt;board name&amp;gt;&lt;br /&gt;
      interfaces_impl&lt;br /&gt;
        bsp_impl.h&lt;br /&gt;
        bsp.cpp&lt;br /&gt;
        hwmapping.h&lt;br /&gt;
      *.cfg&lt;br /&gt;
interfaces                    Unmodified&lt;br /&gt;
config                        Unmodified&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Daniele.cattaneo</name></author>
	</entry>
	<entry>
		<id>https://miosix.org/wiki/index.php?title=Miosix_3&amp;diff=345</id>
		<title>Miosix 3</title>
		<link rel="alternate" type="text/html" href="https://miosix.org/wiki/index.php?title=Miosix_3&amp;diff=345"/>
		<updated>2024-03-22T17:23:33Z</updated>

		<summary type="html">&lt;p&gt;Daniele.cattaneo: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;TODO list for Miosix 3 for development purposes&lt;br /&gt;
* CMake in mainline&lt;br /&gt;
** Basato sul CMake di Skyward&lt;br /&gt;
* Restructuring driver per deduplicare&lt;br /&gt;
* Eliminazione codice di startup di ST e delle define stupid CLOCK512MHZ=5120000000&lt;br /&gt;
** Driver PLL&lt;br /&gt;
* Modifica driver per interrupt registrabili a runtime&lt;br /&gt;
* Aggiornamento dei CMSIS&lt;br /&gt;
* Split board e chip&lt;br /&gt;
* Driver della seriale rifatto e ripulito&lt;br /&gt;
* Compressione .data in elf processi&lt;br /&gt;
* Compressione kernel in RAM&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Compressione ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[17:09] Federico Terraneo&lt;br /&gt;
cazzo sai che in futuro mi è venuta un&#039;idea&lt;br /&gt;
[17:10] Federico Terraneo&lt;br /&gt;
una volta che iniziamo a giocare con la compressione anche noi&lt;br /&gt;
[17:10] Federico Terraneo&lt;br /&gt;
potremmo comprimere la copia di .data all&#039;interno dei processi e del kernel&lt;br /&gt;
[17:10] Federico Terraneo&lt;br /&gt;
easy win, ed è un&#039;altro piccolo paper&lt;br /&gt;
[17:10] Federico Terraneo&lt;br /&gt;
e non impedisce xip&lt;br /&gt;
[17:11] Federico Terraneo&lt;br /&gt;
no idea cosa sia&lt;br /&gt;
[17:13] Daniele Cattaneo&lt;br /&gt;
bella idea! anche se non ci si guadagna poi tantissimo credo&lt;br /&gt;
[17:13] Federico Terraneo&lt;br /&gt;
abbastanza % da meritare un paper imho&lt;br /&gt;
[17:14] Federico Terraneo&lt;br /&gt;
e se il codice della decompressione inizi ad averlo in giro per fare altre cose why not?&lt;br /&gt;
[17:14] Federico Terraneo&lt;br /&gt;
per i processi è easy&lt;br /&gt;
[17:14] Federico Terraneo&lt;br /&gt;
il loader decomprime&lt;br /&gt;
[17:14] Federico Terraneo&lt;br /&gt;
per il kernel è più tricky perchè non il codice di decompressione non deve dipendere da .data a sua volta&lt;br /&gt;
[17:15] Federico Terraneo&lt;br /&gt;
e in ogni caso bisogna patchare ld per comprimere la sezione .data&lt;br /&gt;
[17:15] Federico Terraneo&lt;br /&gt;
o lo mettiamo nel postlinker&lt;br /&gt;
[17:15] Federico Terraneo&lt;br /&gt;
possiamo scegliere&lt;br /&gt;
[17:15] Federico Terraneo&lt;br /&gt;
anche se forse dovremmo patchare ld e basta e togliere il postlinker&lt;br /&gt;
[17:17] Federico Terraneo&lt;br /&gt;
le dipendenze nel kernel le risolvi facendo un vero e proprio stage 1 loader separato&lt;br /&gt;
[17:18] Federico Terraneo&lt;br /&gt;
che pensos ervirà anche se vogliamo fare il kernel compresso che si decomprime ed esegue in ram&lt;br /&gt;
[17:18] Federico Terraneo&lt;br /&gt;
che è un&#039;opzione utile se hai poca flash e tanta ram o se inizia voler scrivere in flash senza stallare tutto l&#039;os&lt;br /&gt;
[17:18] Federico Terraneo&lt;br /&gt;
durante il ciclo di erase&lt;br /&gt;
[17:19] Federico Terraneo&lt;br /&gt;
boh, come ti dicevo ho idee per vari modi di piazzare il codice del kernel e dei processi per dare flessibilità&lt;br /&gt;
[17:19] Federico Terraneo&lt;br /&gt;
c&#039;è anche la compressione degli eseguibili nel romfs&lt;br /&gt;
[17:20] Federico Terraneo&lt;br /&gt;
tante idee&lt;br /&gt;
[17:20] Federico Terraneo&lt;br /&gt;
anche se i benchark su linux imostrano che la config attuale è la più veloce&lt;br /&gt;
[17:20] Federico Terraneo&lt;br /&gt;
forse per iniziare a mettere cose in ram ci vogliono gli f7 con la cache&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Daniele.cattaneo</name></author>
	</entry>
	<entry>
		<id>https://miosix.org/wiki/index.php?title=Miosix_3&amp;diff=344</id>
		<title>Miosix 3</title>
		<link rel="alternate" type="text/html" href="https://miosix.org/wiki/index.php?title=Miosix_3&amp;diff=344"/>
		<updated>2024-03-22T17:23:25Z</updated>

		<summary type="html">&lt;p&gt;Daniele.cattaneo: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;TODO list for Miosix 3 for development purposes&lt;br /&gt;
* CMake in mainline&lt;br /&gt;
** Basato sul CMake di Skyward&lt;br /&gt;
* Restructuring driver per deduplicare&lt;br /&gt;
* Eliminazione codice di startup di ST e delle define stupid CLOCK512MHZ=5120000000&lt;br /&gt;
** Driver PLL&lt;br /&gt;
* Modifica driver per interrupt registrabili a runtime&lt;br /&gt;
* Aggiornamento dei CMSIS&lt;br /&gt;
* Split board e chip&lt;br /&gt;
* Driver della seriale rifatto e ripulito&lt;br /&gt;
* Compressione .data in elf processi&lt;br /&gt;
* Compressione kernel in RAM&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Compressione ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
[17:09] Federico Terraneo&lt;br /&gt;
cazzo sai che in futuro mi è venuta un&#039;idea&lt;br /&gt;
[17:10] Federico Terraneo&lt;br /&gt;
una volta che iniziamo a giocare con la compressione anche noi&lt;br /&gt;
[17:10] Federico Terraneo&lt;br /&gt;
potremmo comprimere la copia di .data all&#039;interno dei processi e del kernel&lt;br /&gt;
[17:10] Federico Terraneo&lt;br /&gt;
easy win, ed è un&#039;altro piccolo paper&lt;br /&gt;
[17:10] Federico Terraneo&lt;br /&gt;
e non impedisce xip&lt;br /&gt;
[17:11] Federico Terraneo&lt;br /&gt;
no idea cosa sia&lt;br /&gt;
[17:13] Daniele Cattaneo&lt;br /&gt;
bella idea! anche se non ci si guadagna poi tantissimo credo&lt;br /&gt;
[17:13] Federico Terraneo&lt;br /&gt;
abbastanza % da meritare un paper imho&lt;br /&gt;
[17:14] Federico Terraneo&lt;br /&gt;
e se il codice della decompressione inizi ad averlo in giro per fare altre cose why not?&lt;br /&gt;
[17:14] Federico Terraneo&lt;br /&gt;
per i processi è easy&lt;br /&gt;
[17:14] Federico Terraneo&lt;br /&gt;
il loader decomprime&lt;br /&gt;
[17:14] Federico Terraneo&lt;br /&gt;
per il kernel è più tricky perchè non il codice di decompressione non deve dipendere da .data a sua volta&lt;br /&gt;
[17:15] Federico Terraneo&lt;br /&gt;
e in ogni caso bisogna patchare ld per comprimere la sezione .data&lt;br /&gt;
[17:15] Federico Terraneo&lt;br /&gt;
o lo mettiamo nel postlinker&lt;br /&gt;
[17:15] Federico Terraneo&lt;br /&gt;
possiamo scegliere&lt;br /&gt;
[17:15] Federico Terraneo&lt;br /&gt;
anche se forse dovremmo patchare ld e basta e togliere il postlinker&lt;br /&gt;
[17:17] Federico Terraneo&lt;br /&gt;
le dipendenze nel kernel le risolvi facendo un vero e proprio stage 1 loader separato&lt;br /&gt;
[17:18] Federico Terraneo&lt;br /&gt;
che pensos ervirà anche se vogliamo fare il kernel compresso che si decomprime ed esegue in ram&lt;br /&gt;
[17:18] Federico Terraneo&lt;br /&gt;
che è un&#039;opzione utile se hai poca flash e tanta ram o se inizia voler scrivere in flash senza stallare tutto l&#039;os&lt;br /&gt;
[17:18] Federico Terraneo&lt;br /&gt;
durante il ciclo di erase&lt;br /&gt;
[17:19] Federico Terraneo&lt;br /&gt;
boh, come ti dicevo ho idee per vari modi di piazzare il codice del kernel e dei processi per dare flessibilità&lt;br /&gt;
[17:19] Federico Terraneo&lt;br /&gt;
c&#039;è anche la compressione degli eseguibili nel romfs&lt;br /&gt;
[17:20] Federico Terraneo&lt;br /&gt;
tante idee&lt;br /&gt;
[17:20] Federico Terraneo&lt;br /&gt;
anche se i benchark su linux imostrano che la config attuale è la più veloce&lt;br /&gt;
[17:20] Federico Terraneo&lt;br /&gt;
forse per iniziare a mettere cose in ram ci vogliono gli f7 con la cache&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;/div&gt;</summary>
		<author><name>Daniele.cattaneo</name></author>
	</entry>
	<entry>
		<id>https://miosix.org/wiki/index.php?title=Miosix_3&amp;diff=343</id>
		<title>Miosix 3</title>
		<link rel="alternate" type="text/html" href="https://miosix.org/wiki/index.php?title=Miosix_3&amp;diff=343"/>
		<updated>2024-03-22T17:23:06Z</updated>

		<summary type="html">&lt;p&gt;Daniele.cattaneo: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;TODO list for Miosix 3 for development purposes&lt;br /&gt;
* CMake in mainline&lt;br /&gt;
** Basato sul CMake di Skyward&lt;br /&gt;
* Restructuring driver per deduplicare&lt;br /&gt;
* Eliminazione codice di startup di ST e delle define stupid CLOCK512MHZ=5120000000&lt;br /&gt;
** Driver PLL&lt;br /&gt;
* Modifica driver per interrupt registrabili a runtime&lt;br /&gt;
* Aggiornamento dei CMSIS&lt;br /&gt;
* Split board e chip&lt;br /&gt;
* Driver della seriale rifatto e ripulito&lt;br /&gt;
* Compressione .data in elf processi&lt;br /&gt;
* Compressione kernel in RAM&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
## Compressione&lt;br /&gt;
&lt;br /&gt;
[17:09] Federico Terraneo&lt;br /&gt;
cazzo sai che in futuro mi è venuta un&#039;idea&lt;br /&gt;
[17:10] Federico Terraneo&lt;br /&gt;
una volta che iniziamo a giocare con la compressione anche noi&lt;br /&gt;
[17:10] Federico Terraneo&lt;br /&gt;
potremmo comprimere la copia di .data all&#039;interno dei processi e del kernel&lt;br /&gt;
[17:10] Federico Terraneo&lt;br /&gt;
easy win, ed è un&#039;altro piccolo paper&lt;br /&gt;
[17:10] Federico Terraneo&lt;br /&gt;
e non impedisce xip&lt;br /&gt;
[17:11] Federico Terraneo&lt;br /&gt;
no idea cosa sia&lt;br /&gt;
[17:13] Daniele Cattaneo&lt;br /&gt;
bella idea! anche se non ci si guadagna poi tantissimo credo&lt;br /&gt;
[17:13] Federico Terraneo&lt;br /&gt;
abbastanza % da meritare un paper imho&lt;br /&gt;
[17:14] Federico Terraneo&lt;br /&gt;
e se il codice della decompressione inizi ad averlo in giro per fare altre cose why not?&lt;br /&gt;
[17:14] Federico Terraneo&lt;br /&gt;
per i processi è easy&lt;br /&gt;
[17:14] Federico Terraneo&lt;br /&gt;
il loader decomprime&lt;br /&gt;
[17:14] Federico Terraneo&lt;br /&gt;
per il kernel è più tricky perchè non il codice di decompressione non deve dipendere da .data a sua volta&lt;br /&gt;
[17:15] Federico Terraneo&lt;br /&gt;
e in ogni caso bisogna patchare ld per comprimere la sezione .data&lt;br /&gt;
[17:15] Federico Terraneo&lt;br /&gt;
o lo mettiamo nel postlinker&lt;br /&gt;
[17:15] Federico Terraneo&lt;br /&gt;
possiamo scegliere&lt;br /&gt;
[17:15] Federico Terraneo&lt;br /&gt;
anche se forse dovremmo patchare ld e basta e togliere il postlinker&lt;br /&gt;
[17:17] Federico Terraneo&lt;br /&gt;
le dipendenze nel kernel le risolvi facendo un vero e proprio stage 1 loader separato&lt;br /&gt;
[17:18] Federico Terraneo&lt;br /&gt;
che pensos ervirà anche se vogliamo fare il kernel compresso che si decomprime ed esegue in ram&lt;br /&gt;
[17:18] Federico Terraneo&lt;br /&gt;
che è un&#039;opzione utile se hai poca flash e tanta ram o se inizia voler scrivere in flash senza stallare tutto l&#039;os&lt;br /&gt;
[17:18] Federico Terraneo&lt;br /&gt;
durante il ciclo di erase&lt;br /&gt;
[17:19] Federico Terraneo&lt;br /&gt;
boh, come ti dicevo ho idee per vari modi di piazzare il codice del kernel e dei processi per dare flessibilità&lt;br /&gt;
[17:19] Federico Terraneo&lt;br /&gt;
c&#039;è anche la compressione degli eseguibili nel romfs&lt;br /&gt;
[17:20] Federico Terraneo&lt;br /&gt;
tante idee&lt;br /&gt;
[17:20] Federico Terraneo&lt;br /&gt;
anche se i benchark su linux imostrano che la config attuale è la più veloce&lt;br /&gt;
[17:20] Federico Terraneo&lt;br /&gt;
forse per iniziare a mettere cose in ram ci vogliono gli f7 con la cache&lt;/div&gt;</summary>
		<author><name>Daniele.cattaneo</name></author>
	</entry>
	<entry>
		<id>https://miosix.org/wiki/index.php?title=Miosix_3&amp;diff=342</id>
		<title>Miosix 3</title>
		<link rel="alternate" type="text/html" href="https://miosix.org/wiki/index.php?title=Miosix_3&amp;diff=342"/>
		<updated>2024-03-22T16:29:25Z</updated>

		<summary type="html">&lt;p&gt;Daniele.cattaneo: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;TODO list for Miosix 3 for development purposes&lt;br /&gt;
* CMake in mainline&lt;br /&gt;
** Basato sul CMake di Skyward&lt;br /&gt;
* Restructuring driver per deduplicare&lt;br /&gt;
* Eliminazione codice di startup di ST e delle define stupid CLOCK512MHZ=5120000000&lt;br /&gt;
** Driver PLL&lt;br /&gt;
* Modifica driver per interrupt registrabili a runtime&lt;br /&gt;
* Aggiornamento dei CMSIS&lt;br /&gt;
* Split board e chip&lt;br /&gt;
* Driver della seriale rifatto e ripulito&lt;br /&gt;
* Compressione .data in elf processi&lt;br /&gt;
* Compressione kernel in RAM&lt;/div&gt;</summary>
		<author><name>Daniele.cattaneo</name></author>
	</entry>
	<entry>
		<id>https://miosix.org/wiki/index.php?title=Quick_start&amp;diff=341</id>
		<title>Quick start</title>
		<link rel="alternate" type="text/html" href="https://miosix.org/wiki/index.php?title=Quick_start&amp;diff=341"/>
		<updated>2024-03-17T17:30:33Z</updated>

		<summary type="html">&lt;p&gt;Daniele.cattaneo: Better instructions for configuring VSCode.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;To start using Miosix you need a patched version of the GCC compiler called [[Miosix Toolchain]] and git to download the kernel sources. Optionally you can also use an IDE to simplify code development, and an in-circuit debugger to speed up bug fixing.&lt;br /&gt;
&lt;br /&gt;
= Getting started =&lt;br /&gt;
&lt;br /&gt;
This section will guide you through the installation of the minimum requirements to start using Miosix: installing the compiler, and downloading the kernel.&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;
= Miosix and git workflow =&lt;br /&gt;
&lt;br /&gt;
See [[Miosix and git workflow]] to understand how to manage the Miosix git repository.&lt;br /&gt;
&lt;br /&gt;
= In-circuit debugger =&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. Miosix uses GDB and [http://openocd.sourceforge.net openocd] for in-circuit debugging.&lt;br /&gt;
&lt;br /&gt;
* [[Linux Debugger configuration]]&lt;br /&gt;
* [[Windows Debugger configuration]]&lt;br /&gt;
&lt;br /&gt;
= IDEs =&lt;br /&gt;
&lt;br /&gt;
At the moment the simplest way to develop Miosix is to use a plain text editor. Alternatively, you can use any IDE that supports Makefiles to take advantage of features such as autocompletion and/or debugger integration (where available).&lt;br /&gt;
&lt;br /&gt;
== Visual Studio Code ==&lt;br /&gt;
&lt;br /&gt;
Visual Studio Code is known to work properly on the Miosix source tree with the standard C/C++ and Makefile extensions. After installing these extensions, you need to configure IntelliSense in the C/C++ extension to use the include paths found from the Makefile by setting the &#039;&#039;Configuration provider&#039;&#039; for the workspace to &amp;lt;code&amp;gt;ms-vscode.makefile-tools&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Integration with GDB/openocd has not been tested but you can run GDB/openocd manually in the integrated terminal.&lt;br /&gt;
&lt;br /&gt;
== Netbeans IDE ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Important:&#039;&#039;&#039; These instructions were developed back when NetBeans was still a Sun product, they are probably outdated by now!&lt;br /&gt;
&lt;br /&gt;
For a long time the default IDE to develop for Miosix has been [https://netbeans.org/ Netbeans]. NetBeans does not come with Miosix support out of the box, so you have to configure it first.&lt;br /&gt;
&lt;br /&gt;
* [[Linux Netbeans configuration]]&lt;br /&gt;
* [[Windows Netbeans configuration]]&lt;br /&gt;
* [[OSX Netbeans configuration]]&lt;br /&gt;
&lt;br /&gt;
== Other IDEs ==&lt;br /&gt;
&lt;br /&gt;
* [[VisualStudio Quick Start|Windows Visual Studio configuration]] using VisualGDB which integrates in-circuit debugging support.&lt;br /&gt;
* [[Linux Eclipse configuration|Eclipse]], which has the added feature to allow in-circuit debugging directly from the IDE.&lt;br /&gt;
* [[Linux QtCreator configuration]]&lt;br /&gt;
* [[Windows QtCreator configuration]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Installation and Configuration]]&lt;/div&gt;</summary>
		<author><name>Daniele.cattaneo</name></author>
	</entry>
	<entry>
		<id>https://miosix.org/wiki/index.php?title=Arch_directory_restructuring&amp;diff=340</id>
		<title>Arch directory restructuring</title>
		<link rel="alternate" type="text/html" href="https://miosix.org/wiki/index.php?title=Arch_directory_restructuring&amp;diff=340"/>
		<updated>2023-12-31T17:29:36Z</updated>

		<summary type="html">&lt;p&gt;Daniele.cattaneo: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The &#039;&#039;arch&#039;&#039; directory is a mess with lots of copy-pasted code. Ideally it should be &#039;&#039;&#039;consistently and logically organized&#039;&#039;&#039;: each directory should have a documented purpose in order to leave as little doubt as possible about &#039;&#039;what goes where&#039;&#039;. Additionally, each directory&#039;s purpose makes sense in the overall structure, without overlaps between the scope of each directory.&lt;br /&gt;
At the moment however we observe this is not the case. We believe that in order to make the future growth of Miosix simpler and faster, the right moment to rectify the situation is now.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Update 31/12/2023&#039;&#039; I discovered a bug in the testing branch of Miosix which was caused by the copy-pasting of gpio_impl.h: version 1.4 (sic, see comments) didn&#039;t have the alternateFunction method of Gpio, even though serial_stm32.cpp assumes it always exists. (btw don&#039;t we have git? manual versioning in comments is not a robust practice!!!) I bet other similar bugs exist.&lt;br /&gt;
&lt;br /&gt;
== Some definitions ==&lt;br /&gt;
&lt;br /&gt;
Common sense suggests the following taxonomy of parts for MCU-equipped devices targeted by Miosix:&lt;br /&gt;
* Board: The device itself being targeted. It&#039;s called a board because nobody has observed any MCU wired with point-to-point wiring yet. Includes the MCU itself plus any peripheral external to the MCU but &#039;&#039;&#039;driven&#039;&#039;&#039; by it.&lt;br /&gt;
* Chip: The MCU itself. May come in RAM/OTP/ROM/Flash size variations, which are mostly ignored.&lt;br /&gt;
* Chip family: A set of MCU types from the same manufacturer with the same microprocessor core but potentially different set of peripherals. While the available set of peripherals may vary, the behaviour and I/O ports of each kind of peripheral are the same across the entire family. Thanks to the brilliant ideas of the various marketing departments of each vendor, the classification here can get very fluid.&lt;br /&gt;
* Core: The microprocessor core used by a given chip family.&lt;br /&gt;
&lt;br /&gt;
Let&#039;s take as an example the classic stm32f4discovery board that is the most common development device for Miosix:&lt;br /&gt;
* The board is the stm32f4discovery itself. It includes the chip, and miscellaneous peripherals such as an accelerometer and a Cirrus Logic audio chip. The STLink programming interface and the power supply are &#039;&#039;&#039;not&#039;&#039;&#039; considered relevant parts of the board for Miosix, as the MCU is not in control of what they do.&lt;br /&gt;
* The chip is an STM32F407VGT6. The VGT6 suffix of the chip name specifies package (100 pin LQFP), Flash size (1MB) and temperature range options (see the datasheet at the &amp;quot;Ordering Information&amp;quot; page).&lt;br /&gt;
* The chip family is STM32F4. This can be inferred by the fact that all available chips with this prefix in the part name share the same reference manual.&lt;br /&gt;
* The core is an ARM Cortex M4, as stated in the datasheet. Roughly, ST buys the Verilog for the core from ARM and then takes care of the manufacturing. As far as we know, ARM&#039;s licence shouldn&#039;t allow ST to customize the core in any way, so all Cortex M4 cores should behave the same, even from other vendors.&lt;br /&gt;
&lt;br /&gt;
=== What is an architecture? ===&lt;br /&gt;
&lt;br /&gt;
One definition we did not give is the definition of what an &#039;&#039;&#039;architecture&#039;&#039;&#039; is. The reason is that there is no accepted definition for this term, especially for forum pundits and bloggers, but also in academia. The RISC school of thought (Patterson/Hennessy and their spawn) historically associated an &#039;&#039;architecture&#039;&#039; with a combination of what are more specifically called the &#039;&#039;instruction set architecture&#039;&#039; (ISA) and the &#039;&#039;microarchitecture&#039;&#039; of a core. The ISA is the overall structure and design of the instructions, as opposed to the &#039;&#039;instruction set&#039;&#039; proper which is the set of instructions accepted by a specific core. The &#039;&#039;&#039;microarchitecture&#039;&#039;&#039; is the overall internal design of the core itself.&lt;br /&gt;
&lt;br /&gt;
Their thesis was that the microarchitecture design will follow naturally from the definition of the ISA, hence simpler ISAs (RISC) to implement always lead to more efficient and generally better cores. Therefore one can consider the &#039;&#039;&#039;architecture&#039;&#039;&#039; to be primarily determined by the ISA. However the industry has proven them wrong, and the most glaring example are Intel x86 chips, which have seen an increasing variety of microarchitectures implementing the same ISA (variously extended of course) with wildly varying levels of (non-)efficiency (in all possible ramifications of &amp;quot;efficiency&amp;quot;). Closer to Miosix&#039;s targets, the ARM ISA has been extended so much over the years that its core RISC design has now evolved to basically a traditional CISC ISA, but ARM chips still come in every possible size and flavour.&lt;br /&gt;
&lt;br /&gt;
When we talk about x86 &amp;quot;architectures&amp;quot; or ARM &amp;quot;architectures&amp;quot;, but do we mean desktop-grade chips or microcontrollers? Even though they have the same &amp;quot;architecture&amp;quot; the cores in these two classes of chips have nothing to do with each other, they don&#039;t even share the same instruction decoder probably. Hence our conclusion that the word &amp;quot;architecture&amp;quot; has now lost all useful meaning for our purposes, and is only useful for void parlor chitchat.&lt;br /&gt;
&lt;br /&gt;
And then we come to Miosix which defines &amp;quot;architecture&amp;quot; (arch) as... a board. Which is not what anyone means when they talk about architecture of anything. For Miosix, an &amp;quot;architecture&amp;quot; is more like what in common parlance would be meant as a &amp;quot;platform&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
== Current structure ==&lt;br /&gt;
&lt;br /&gt;
Here&#039;s a schematic diagram of how the Miosix &#039;&#039;arch&#039;&#039; directory (plus related directories) is configured. In the following &#039;&#039;/&#039;&#039; refers to the &#039;&#039;miosix&#039;&#039; directory at the top level of the repository.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
arch                        Architecture-specific files&lt;br /&gt;
  common                      Pool of useful files. Very few files here are common to all archs.&lt;br /&gt;
    CMSIS                       Collection of ARM &amp;amp; vendor headers following the CMSIS standard&lt;br /&gt;
    core                        Board independent drivers required for the OS to function (roughly)&lt;br /&gt;
      atomic_ops_*.h              Core dependent&lt;br /&gt;
      cache_*.cpp/h               Core dependent. This is not required at all for Miosix to work but is nevertheless here&lt;br /&gt;
      *_os_timer.cpp              Chip family dependent&lt;br /&gt;
      endianness_*.h              Core dependent. Should have a generic (slow) implementation but it&#039;s missing.&lt;br /&gt;
      interrupts.h                Umbrella header for interrupts_*.h&lt;br /&gt;
      interrupts_*.h              Core dependent. Misleading name, this is for fault handling.&lt;br /&gt;
      memory_protection.h         Umbrella header for mpu_*.h. Required only for process mode. Name is not consistent with other umbrella headers, should have been &amp;quot;mpu.h&amp;quot;&lt;br /&gt;
      mpu_*.cpp/h                 Core dependent.&lt;br /&gt;
    drivers                     Miscellaneous drivers, which are &amp;quot;common&amp;quot; only very roughly&lt;br /&gt;
      dcc.cpp/h                   Core dependent (but common to all ARM cores apparently)&lt;br /&gt;
      *_adc.cpp/h                 Chip family dependent&lt;br /&gt;
      serial.h                    Umbrella header for *serial*.h&lt;br /&gt;
      *serial*.cpp/h              Chip family dependent&lt;br /&gt;
      sd_*.cpp/h                  Chip family dependent&lt;br /&gt;
      servo_*.cpp/h               Board dependent really, should go into utils&lt;br /&gt;
      *_hardware_rng.cpp/h        Chip family dependent&lt;br /&gt;
      *_rtc.cpp/h                 Chip family dependent&lt;br /&gt;
      *_sgm.cpp/h                 Chip family dependent&lt;br /&gt;
      *_wd.cpp/h                  Chip family dependent&lt;br /&gt;
      *_i2c.cpp/h                 Chip family dependent&lt;br /&gt;
  &amp;lt;board group name&amp;gt;          Board group specific files.&lt;br /&gt;
    common                      Common drivers and configuration for all the boards in the group&lt;br /&gt;
      arch_settings.h             Core dependent. Misleading name, defines requirements for ctxsave&lt;br /&gt;
      interfaces-impl             The actual drivers, most of them required by Miosix to function.&lt;br /&gt;
        arch_registers_impl.h     Chip family dependent. Includes the appropriate register definitions&lt;br /&gt;
        delays.cpp                Chip family dependent as it also depends on ROM/Flash speed. Actually application dependent (!) as cache/prefetch mechanisms can be configured but whatever.&lt;br /&gt;
        gpio_impl.cpp/h           Chip family dependent.&lt;br /&gt;
        portability_impl.h        Core dependent.&lt;br /&gt;
        portability.cpp           Core dependent.&lt;br /&gt;
      drivers                 Miscellaneous drivers not required by Miosix to function, with exceptions (atsam4l clock)&lt;br /&gt;
        *.cpp/h&lt;br /&gt;
    &amp;lt;board name&amp;gt;              Board/chip specific files.&lt;br /&gt;
      core                      Board/chip dependent code required for the OS to function.&lt;br /&gt;
        stage_1_boot.c/cpp/s      Chip dependent. Interrupt vector table, reset handler, clock tree setup, bss/data initialization&lt;br /&gt;
      interfaces_impl         Important board/chip specific drivers, most of them required by Miosix to function.&lt;br /&gt;
        bsp_impl.h              Board dependent. Useful board-specific definitions.&lt;br /&gt;
        bsp.cpp                 Board dependent. Useful board-specific functions.&lt;br /&gt;
        hwmapping.h             Board dependent. GPIO pin definitions.&lt;br /&gt;
        deep_sleep.cpp          Chip family dependent. Optional implementation of deep sleep primitives.&lt;br /&gt;
        delays.cpp              See above. Sometimes it&#039;s here, with no true reason why.&lt;br /&gt;
        arch_registers_impl.h     See above. Sometimes it&#039;s here, depends on chip.&lt;br /&gt;
        ...                     Some boards have extra miscellaneous drivers here&lt;br /&gt;
      *.h                     Some boards have chip registers definitions here (LPC2138)&lt;br /&gt;
      *.cfg                   Some boards have OpenOCD config files here&lt;br /&gt;
      *.ld                    Chip family specific. Linker files for different RAM/Flash configurations&lt;br /&gt;
interfaces                  Headers for hardware interfaces TO miosix (internals) and SOME interfaces OF miosix to the application (APIs). Only commonality is that they are all hardware dependent (while stuff in utils/kernel is &#039;&#039;generally&#039;&#039; hardware independent)&lt;br /&gt;
  arch_registers.h            API. Umbrella for &amp;quot;arch_registers_impl.h&amp;quot;, selected through include search path manipulation.&lt;br /&gt;
  atomic_ops.h                API. Umbrella for &amp;quot;atomic_ops_*.h&amp;quot;, selected through ifdefs.&lt;br /&gt;
  bsp.h                       API + internal prototypes (IRQbspInit, bspInit2). Umbrella for &amp;quot;bsp_impl.h&amp;quot;, selected through include search path manipulation.&lt;br /&gt;
  deep_sleep.h                Internal prototypes only. Not an umbrella header.&lt;br /&gt;
  delays.h                    API. Not an umbrella header.&lt;br /&gt;
  endianness.h                API. Umbrella for &amp;quot;endianness_*.h&amp;quot;, selected through ifdefs.&lt;br /&gt;
  gpio.h                      API. Umbrella for &amp;quot;gpio_impl.h&amp;quot;, selected through include search path manipulation.&lt;br /&gt;
  os_timer.h                  Internal declarations. Not an umbrella header.&lt;br /&gt;
  portability.h               Internal declarations. Primitives for context switching and syscalls. Umbrella for &amp;quot;portability_impl.h&amp;quot;, selected through include search path manipulation.&lt;br /&gt;
util                        Additional APIs made available for applications as utilities, built on top of kernel primitives or other drivers&lt;br /&gt;
  lcd44780.cpp/h              Driver for Hitachi-standard HD44780 character displays.&lt;br /&gt;
  software_i2c/spi.h          Bit-banged i2c/spi implementations. Arguably drivers.&lt;br /&gt;
  utils.cpp/h                 Memory/CPU usage profiling. Misleading name. Not a driver&lt;br /&gt;
  ...                         Other files are not related to hardware&lt;br /&gt;
config                      Configuration files, user-modifiable&lt;br /&gt;
  Makefile.inc                List of board + selection of board to build for + selection of compile time options through defines passed as argument to the compiler. The first section of the file arguably is not user-modifiable configuration.&lt;br /&gt;
  miosix-settings.h           Global settings selected through defines in header files&lt;br /&gt;
  arch                        Board-dependent settings&lt;br /&gt;
    &amp;lt;board group&amp;gt;&lt;br /&gt;
      &amp;lt;board&amp;gt;&lt;br /&gt;
        board_settings.h      Board-dependent settings selected through defines in header files&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&amp;lt;board group name&amp;gt;&#039;&#039; is defined as the name of the chip core, followed by an underscore, followed by the name of a chip family. &#039;&#039;&amp;lt;board name&amp;gt;&#039;&#039; is defined by the name of the chip, followed by an underscore, followed by a &amp;quot;common name&amp;quot; of the board. For commercial prototyping boards or specific devices, &amp;quot;common name&amp;quot; is derived from the name given by the manufacturer, or a name which is in common use with some exceptions (i.e. stm32f103 bluepill boards are named &amp;quot;breakout&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
Some general patterns can be inferred:&lt;br /&gt;
* Apart from minor exceptions, directories named &#039;&#039;&#039;core&#039;&#039;&#039; contain drivers required for the OS to function.&lt;br /&gt;
* Directories named &#039;&#039;&#039;interfaces_impl&#039;&#039;&#039; generally contain implementations of things defined in /interfaces. Header files in &#039;&#039;&#039;interfaces_impl&#039;&#039;&#039; are always given the ``_impl`` suffix. C++ files are usually not given the &amp;quot;_impl&amp;quot; suffix but sometimes they have it (gpio_impl.cpp).&lt;br /&gt;
* Directories named &#039;&#039;&#039;common&#039;&#039;&#039; contain code shared by multiple boards. No attempt is made to separate different levels of commonality apart from chip-family specific stuff which is grouped by board group.&lt;br /&gt;
&lt;br /&gt;
=== Include paths ===&lt;br /&gt;
&lt;br /&gt;
The current directory structure allows the Makefile to select the implementation of some file by solely changing the include search paths of the compiler. This mostly applies to files in &#039;&#039;&amp;lt;board group name&amp;gt;/&amp;lt;board name&amp;gt;&#039;&#039; and in &#039;&#039;&amp;lt;board group name&amp;gt;/config&#039;&#039;. The Makefile defines several variables that are used to refer to specific paths in the directory tree:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Variable !! Value Pattern !! Scope !! Is config !! Defined by !! Description&lt;br /&gt;
|-&lt;br /&gt;
| LINKER_SCRIPT_PATH || arch/&amp;lt;board group name&amp;gt;/&amp;lt;board name&amp;gt;/ || Board || Yes || Makefile.inc || Directory where the linker scripts are found&lt;br /&gt;
|-&lt;br /&gt;
| LINKER_SCRIPT || $(LINKER_SCRIPT_PATH)/&amp;lt;script&amp;gt;.ld || Board || Yes || Makefile.inc || Path of the linker script&lt;br /&gt;
|-&lt;br /&gt;
| ARCH_INC ||  arch/&amp;lt;board group name&amp;gt;/common || Board group || No || Makefile.inc || Path of the common directory of the board group&lt;br /&gt;
|-&lt;br /&gt;
| BOARD_INC || arch/&amp;lt;board group name&amp;gt;/&amp;lt;board name&amp;gt; || Board || No || Makefile.inc || Path of the board directory&lt;br /&gt;
|-&lt;br /&gt;
| BOOT_FILE || $(BOARD_INC)/core/stage_1_boot.o || Board || No || Makefile.inc || Path of the object file for the board bootstrap code&lt;br /&gt;
|-&lt;br /&gt;
| ARCH_SRC || $(BOARD_INC)/*/*.cpp $(ARCH_INC)/*/*.cpp arch/common/drivers/*.cpp || Board + Board group || No || Sources for the drivers enabled for this board&lt;br /&gt;
|-&lt;br /&gt;
| KPATH || miosix || Global || Yes || Appl. Makefile || Root directory of the kernel files&lt;br /&gt;
|-&lt;br /&gt;
| CONFPATH || $(KPATH) || Global || Yes || Appl. Makefile || Root directory for configuration files&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
For reference, the final include paths, defined by the application makefile, are:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$(CONFPATH)&lt;br /&gt;
$(CONFPATH)/config/$(BOARD_INC)&lt;br /&gt;
$(KPATH)&lt;br /&gt;
$(KPATH)/arch/common&lt;br /&gt;
$(KPATH)/$(ARCH_INC)&lt;br /&gt;
$(KPATH)/$(BOARD_INC)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notice that, despite the name of the defines, there is no distinction between include paths and source paths, as includes are alongside the source. We do not have a problem with this approach, however it results in all includes being publicly available for applications, which is something that is not entirely desirable.&lt;br /&gt;
&lt;br /&gt;
==== Drivers selected by include path ====&lt;br /&gt;
&lt;br /&gt;
Sometimes Miosix&#039;s headers include files that depend on the board selected for building. This of course can give problems when reorganizing files around. The affected files are:&lt;br /&gt;
&lt;br /&gt;
* interfaces/arch_registers.h&lt;br /&gt;
* interfaces/bsp.h&lt;br /&gt;
* interfaces/gpio.h&lt;br /&gt;
* interfaces/portability.h&lt;br /&gt;
&lt;br /&gt;
Overall selecting different files through the include paths is desirable, so we want to avoid adding additional architecture-specific ifdefs as much as possible.&lt;br /&gt;
&lt;br /&gt;
=== Issues ===&lt;br /&gt;
&lt;br /&gt;
Experience has shown this organization has the following problems:&lt;br /&gt;
* What goes where is not well defined due to the vagueness of directory names&lt;br /&gt;
** This leads to files being in the wrong place even though it&#039;s not obvious&lt;br /&gt;
*** servo_* is the most glaring example&lt;br /&gt;
*** The location of delays.cpp and arch_registers_impl.h is also inconsistent&lt;br /&gt;
* The two level board group/board classification does not reflect reality, which leads to missing code sharing opportunities:&lt;br /&gt;
** GPIO implementations are duplicated multiple times as they are common to multiple chip families and not to a single one.&lt;br /&gt;
** Bootstrap code is duplicated multiple times as they are common to boards with the same chip and not common to the board.&lt;br /&gt;
** Portability code (i.e. context save/restore primitives mostly) is duplicated multiple times as they are common to a given core and not to a chip family&lt;br /&gt;
** Linker scripts are also duplicated multiple times&lt;br /&gt;
* Classifications sometimes privilege syntax rather than semantics, in an inconsistent fashion&lt;br /&gt;
** Directories named &#039;&#039;&#039;interfaces_impl&#039;&#039;&#039; contain drivers just like directories named &#039;&#039;&#039;drivers&#039;&#039;&#039;, except that they included from /interfaces.&lt;br /&gt;
** What is &#039;&#039;&#039;common&#039;&#039;&#039; and what is not loosely determined by the amount of code sharing but most stuff not under a &#039;&#039;&#039;common&#039;&#039;&#039; directory is duplicated at least twice&lt;br /&gt;
&lt;br /&gt;
Of course, the root issue is the fluidity of the distinction between chip and chip family, and how each vendor manages and/or defines each family. For instance, STM32 chips all have similar USART (serial) implementations, but at least two versions can be distinguished through different register definitions and feature sets. Therefore the same overall driver can be shared across almost all STM32 chips, however the driver is littered with &#039;&#039;ifdef&#039;&#039;s to single out the specificity of each implementation. There is really no strict distinction to what can be found where, as the vendors can and do mix and match peripherals even amongst themselves. For example, some STM32 chips have Synopsis-designed USB interfaces which can also be found on chips from vendors that are not ST.&lt;br /&gt;
 &lt;br /&gt;
These considerations highlight that the solution to handling the issue of organizing platform-specific code in a consistent way to &#039;&#039;&#039;minimize code duplication&#039;&#039;&#039; is not to &#039;&#039;&#039;add&#039;&#039;&#039; hierarchy levels, but to remove them. This runs contrary from the naive consideration that &amp;quot;Board includes Chip, which belongs to Chip Family, which contains a Core&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
== A proposal ==&lt;br /&gt;
&lt;br /&gt;
Pointing out what&#039;s wrong is easy, fixing it up is hard. Of course &amp;quot;what we should do&amp;quot; is a matter of opinion, and a valid answer to that could even be &amp;quot;nothing&amp;quot;. Overall, what we ultimately want is for all drivers to be decoupled from boards and board groups, in order to be able to classify each driver depending on its actual logical group it belongs to. We can take this opportunity for a more radical restructuring of Miosix&#039;s source tree, or we can opt for more conservative solutions.&lt;br /&gt;
&lt;br /&gt;
=== With classification per device type ===&lt;br /&gt;
&lt;br /&gt;
This proposal is the most radical as it splits the drivers in a completely different way than what is currently done: by device type. For instance all USART drivers go in a &amp;quot;serial&amp;quot; directory, all GPIO drivers go in a GPIO directory, and so on. This approach scales well when there are a lot of drivers around, but completely prevents selection of drivers by using the include paths.&lt;br /&gt;
&lt;br /&gt;
The arch directory has been named &amp;quot;platform&amp;quot; because of our general dislike of the &amp;quot;architecture&amp;quot; word, but that&#039;s really just a bonus. Most other operating systems use &amp;quot;arch&amp;quot; as a directory for drivers and target-specific stuff, so keeping the name &amp;quot;arch&amp;quot; is also an option. We also moved the interfaces headers under the &amp;quot;platform&amp;quot; (&amp;quot;arch&amp;quot;) directory, since they basically are just umbrella headers for various drivers. This loses the distinction of some of them being more essential than others, additional directories can be added for this purpose.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
platform&lt;br /&gt;
  arch_registers.h&lt;br /&gt;
  atomic_ops.h&lt;br /&gt;
  bsp.h&lt;br /&gt;
  deep_sleep.h&lt;br /&gt;
  delays.h&lt;br /&gt;
  endianness.h&lt;br /&gt;
  gpio.h&lt;br /&gt;
  os_timer.h&lt;br /&gt;
  portability.h&lt;br /&gt;
  memory_protection.h&lt;br /&gt;
  interrupts.h&lt;br /&gt;
  mpu.h&lt;br /&gt;
  serial.h&lt;br /&gt;
  arch_registers&lt;br /&gt;
    CMSIS&lt;br /&gt;
    &amp;lt;chip/chip family&amp;gt;&lt;br /&gt;
      arch_registers_impl.h&lt;br /&gt;
      ....h&lt;br /&gt;
  core&lt;br /&gt;
    boot&lt;br /&gt;
      &amp;lt;chip&amp;gt;&lt;br /&gt;
        stage_1_boot.c/cpp/s&lt;br /&gt;
    atomic_ops&lt;br /&gt;
      atomic_ops_*.h&lt;br /&gt;
    os_timer&lt;br /&gt;
      *_os_timer.cpp&lt;br /&gt;
    endianness&lt;br /&gt;
      endianness_*.h&lt;br /&gt;
    faults&lt;br /&gt;
      interrupts_*.h&lt;br /&gt;
    mpu&lt;br /&gt;
      *_mpu.cpp/h&lt;br /&gt;
    portability&lt;br /&gt;
      &amp;lt;core&amp;gt;&lt;br /&gt;
        arch_settings.h&lt;br /&gt;
        portability_impl.h&lt;br /&gt;
        portability.cpp&lt;br /&gt;
    gpio&lt;br /&gt;
      &amp;lt;chip/chip family&amp;gt;&lt;br /&gt;
        gpio_impl.cpp/h&lt;br /&gt;
    delays&lt;br /&gt;
      &amp;lt;chip/chip family&amp;gt;&lt;br /&gt;
        delays.cpp&lt;br /&gt;
  drivers&lt;br /&gt;
    arm_dcc.cpp/h&lt;br /&gt;
    deep_sleep&lt;br /&gt;
      deep_sleep.cpp&lt;br /&gt;
    cache&lt;br /&gt;
      cache_*.cpp/h&lt;br /&gt;
    serial&lt;br /&gt;
      *_serial.cpp/h&lt;br /&gt;
    adc&lt;br /&gt;
      *_adc.cpp/h&lt;br /&gt;
    sd&lt;br /&gt;
      *_sd.cpp/h&lt;br /&gt;
    servo&lt;br /&gt;
      *_servo.cpp/h&lt;br /&gt;
    hardware_rng&lt;br /&gt;
      *_hardware_rng.cpp/h&lt;br /&gt;
    rtc&lt;br /&gt;
      *_rtc.cpp/h&lt;br /&gt;
    sgm&lt;br /&gt;
      *_sgm.cpp/h&lt;br /&gt;
    wd&lt;br /&gt;
      *_wd.cpp/h&lt;br /&gt;
    i2c&lt;br /&gt;
      *_i2c.cpp/h&lt;br /&gt;
      software_i2c.h&lt;br /&gt;
    spi&lt;br /&gt;
      software_spi.h&lt;br /&gt;
    display&lt;br /&gt;
      lcd44780.cpp/h&lt;br /&gt;
    ...&lt;br /&gt;
  board&lt;br /&gt;
    &amp;lt;board&amp;gt;&lt;br /&gt;
      bsp_impl.h&lt;br /&gt;
      bsp.cpp&lt;br /&gt;
      hwmapping.h&lt;br /&gt;
      *.cfg&lt;br /&gt;
  linker_scripts&lt;br /&gt;
    &amp;lt;chip&amp;gt;&lt;br /&gt;
      *.ld&lt;br /&gt;
config&lt;br /&gt;
  Makefile.inc&lt;br /&gt;
  miosix_settings.h&lt;br /&gt;
  &amp;lt;board&amp;gt;&lt;br /&gt;
    board_settings.h&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Without classification per device type ===&lt;br /&gt;
&lt;br /&gt;
This is just the same proposal as before but which classifies drivers only by &amp;quot;manufacturer&amp;quot; or chip. This allows to use the include trick for selecting headers.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
platform&lt;br /&gt;
  arch_registers.h&lt;br /&gt;
  atomic_ops.h&lt;br /&gt;
  bsp.h&lt;br /&gt;
  deep_sleep.h&lt;br /&gt;
  delays.h&lt;br /&gt;
  endianness.h&lt;br /&gt;
  gpio.h&lt;br /&gt;
  os_timer.h&lt;br /&gt;
  portability.h&lt;br /&gt;
  memory_protection.h&lt;br /&gt;
  interrupts.h&lt;br /&gt;
  mpu.h&lt;br /&gt;
  serial.h&lt;br /&gt;
  arch_registers&lt;br /&gt;
    CMSIS&lt;br /&gt;
    &amp;lt;chip/chip family&amp;gt;&lt;br /&gt;
      arch_registers_impl.h&lt;br /&gt;
      ....h&lt;br /&gt;
  core&lt;br /&gt;
    &amp;lt;chip/chip family&amp;gt;&lt;br /&gt;
      stage_1_boot.c/cpp/s&lt;br /&gt;
      *_os_timer.cpp&lt;br /&gt;
      *_mpu.cpp/h&lt;br /&gt;
      gpio_impl.cpp/h&lt;br /&gt;
      delays.cpp&lt;br /&gt;
    &amp;lt;core&amp;gt;&lt;br /&gt;
      atomic_ops_*.h&lt;br /&gt;
      endianness_*.h&lt;br /&gt;
      interrupts_*.h&lt;br /&gt;
      arch_settings.h&lt;br /&gt;
      portability_impl.h&lt;br /&gt;
      portability.cpp&lt;br /&gt;
  drivers&lt;br /&gt;
    dcc.cpp/h&lt;br /&gt;
    *_servo.cpp/h&lt;br /&gt;
    software_i2c.h&lt;br /&gt;
    software_spi.h&lt;br /&gt;
    lcd44780.cpp/h&lt;br /&gt;
    &amp;lt;core&amp;gt;&lt;br /&gt;
      cache_*.cpp/h&lt;br /&gt;
    &amp;lt;chip/chip family&amp;gt;&lt;br /&gt;
      deep_sleep.cpp&lt;br /&gt;
      *_serial.cpp/h&lt;br /&gt;
      *_adc.cpp/h&lt;br /&gt;
      *_sd.cpp/h&lt;br /&gt;
      *_hardware_rng.cpp/h&lt;br /&gt;
      *_rtc.cpp/h&lt;br /&gt;
      *_sgm.cpp/h&lt;br /&gt;
      *_wd.cpp/h&lt;br /&gt;
      *_i2c.cpp/h&lt;br /&gt;
    ...&lt;br /&gt;
  board&lt;br /&gt;
    &amp;lt;board&amp;gt;&lt;br /&gt;
      bsp_impl.h&lt;br /&gt;
      bsp.cpp&lt;br /&gt;
      hwmapping.h&lt;br /&gt;
      *.cfg&lt;br /&gt;
  linker_scripts&lt;br /&gt;
    &amp;lt;chip&amp;gt;&lt;br /&gt;
      *.ld&lt;br /&gt;
config&lt;br /&gt;
  Makefile.inc&lt;br /&gt;
  miosix_settings.h&lt;br /&gt;
  &amp;lt;board&amp;gt;&lt;br /&gt;
    board_settings.h&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== With minimal changes to the existing structure ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
arch&lt;br /&gt;
  common&lt;br /&gt;
    CMSIS&lt;br /&gt;
      core&lt;br /&gt;
        boot&lt;br /&gt;
          &amp;lt;chip&amp;gt;_stage_1_boot.c/cpp/s&lt;br /&gt;
        &amp;lt;core&amp;gt;_portability&lt;br /&gt;
            arch_settings.h&lt;br /&gt;
            portability_impl.h&lt;br /&gt;
            portability.cpp&lt;br /&gt;
        &amp;lt;chip family&amp;gt;&lt;br /&gt;
          delays.cpp&lt;br /&gt;
          gpio_impl.cpp/h&lt;br /&gt;
          deep_sleep.cpp&lt;br /&gt;
        (all other existing files)&lt;br /&gt;
      drivers&lt;br /&gt;
        All miscellaneous drivers in board directory are moved here&lt;br /&gt;
        (all other existing files)&lt;br /&gt;
    linker_scripts&lt;br /&gt;
      &amp;lt;chip&amp;gt;&lt;br /&gt;
        *.ld&lt;br /&gt;
  &amp;lt;board group name&amp;gt;&lt;br /&gt;
    common&lt;br /&gt;
      (should now be empty)&lt;br /&gt;
    &amp;lt;board name&amp;gt;&lt;br /&gt;
      interfaces_impl&lt;br /&gt;
        bsp_impl.h&lt;br /&gt;
        bsp.cpp&lt;br /&gt;
        hwmapping.h&lt;br /&gt;
      *.cfg&lt;br /&gt;
interfaces                    Unmodified&lt;br /&gt;
config                        Unmodified&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Daniele.cattaneo</name></author>
	</entry>
	<entry>
		<id>https://miosix.org/wiki/index.php?title=Miosix_3&amp;diff=339</id>
		<title>Miosix 3</title>
		<link rel="alternate" type="text/html" href="https://miosix.org/wiki/index.php?title=Miosix_3&amp;diff=339"/>
		<updated>2023-11-28T16:58:47Z</updated>

		<summary type="html">&lt;p&gt;Daniele.cattaneo: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;TODO list for Miosix 3 for development purposes&lt;br /&gt;
* CMake in mainline&lt;br /&gt;
** Basato sul CMake di Skyward&lt;br /&gt;
* Restructuring driver per deduplicare&lt;br /&gt;
* Eliminazione codice di startup di ST e delle define stupid CLOCK512MHZ=5120000000&lt;br /&gt;
** Driver PLL&lt;br /&gt;
* Modifica driver per interrupt registrabili a runtime&lt;br /&gt;
* Aggiornamento dei CMSIS&lt;br /&gt;
* Split board e chip&lt;br /&gt;
* Driver della seriale rifatto e ripulito&lt;/div&gt;</summary>
		<author><name>Daniele.cattaneo</name></author>
	</entry>
	<entry>
		<id>https://miosix.org/wiki/index.php?title=Miosix_3&amp;diff=338</id>
		<title>Miosix 3</title>
		<link rel="alternate" type="text/html" href="https://miosix.org/wiki/index.php?title=Miosix_3&amp;diff=338"/>
		<updated>2023-11-28T16:58:24Z</updated>

		<summary type="html">&lt;p&gt;Daniele.cattaneo: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;TODO list for Miosix 3&lt;br /&gt;
* CMake in mainline&lt;br /&gt;
** Basato sul CMake di Skyward&lt;br /&gt;
* Restructuring driver per deduplicare&lt;br /&gt;
* Eliminazione codice di startup di ST e delle define stupid CLOCK512MHZ=5120000000&lt;br /&gt;
** Driver PLL&lt;br /&gt;
* Modifica driver per interrupt registrabili a runtime&lt;br /&gt;
* Aggiornamento dei CMSIS&lt;br /&gt;
* Split board e chip&lt;br /&gt;
* Driver della seriale rifatto e ripulito&lt;/div&gt;</summary>
		<author><name>Daniele.cattaneo</name></author>
	</entry>
	<entry>
		<id>https://miosix.org/wiki/index.php?title=Miosix_3&amp;diff=337</id>
		<title>Miosix 3</title>
		<link rel="alternate" type="text/html" href="https://miosix.org/wiki/index.php?title=Miosix_3&amp;diff=337"/>
		<updated>2023-11-28T16:13:12Z</updated>

		<summary type="html">&lt;p&gt;Daniele.cattaneo: Created page with &amp;quot;* CMake in mainline ** Basato sul CMake di Skyward * Restructuring driver per deduplicare * Eliminazione codice di startup di ST e delle define stupid CLOCK512MHZ=5120000000 ** Driver PLL * Modifica driver per interrupt registrabili a runtime * Aggiornamento dei CMSIS * Split board e chip * Driver della seriale rifatto e ripulito&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* CMake in mainline&lt;br /&gt;
** Basato sul CMake di Skyward&lt;br /&gt;
* Restructuring driver per deduplicare&lt;br /&gt;
* Eliminazione codice di startup di ST e delle define stupid CLOCK512MHZ=5120000000&lt;br /&gt;
** Driver PLL&lt;br /&gt;
* Modifica driver per interrupt registrabili a runtime&lt;br /&gt;
* Aggiornamento dei CMSIS&lt;br /&gt;
* Split board e chip&lt;br /&gt;
* Driver della seriale rifatto e ripulito&lt;/div&gt;</summary>
		<author><name>Daniele.cattaneo</name></author>
	</entry>
	<entry>
		<id>https://miosix.org/wiki/index.php?title=User:Daniele.cattaneo&amp;diff=336</id>
		<title>User:Daniele.cattaneo</title>
		<link rel="alternate" type="text/html" href="https://miosix.org/wiki/index.php?title=User:Daniele.cattaneo&amp;diff=336"/>
		<updated>2023-11-28T13:39:58Z</updated>

		<summary type="html">&lt;p&gt;Daniele.cattaneo: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Hi :)&lt;br /&gt;
&lt;br /&gt;
Github (work): [https://github.com/danielecattaneo]&lt;br /&gt;
&lt;br /&gt;
Github (personal): Secret&lt;br /&gt;
&lt;br /&gt;
[[Miosix in emulation]]&lt;br /&gt;
&lt;br /&gt;
[[arch directory restructuring]]&lt;br /&gt;
&lt;br /&gt;
[[Miosix 3]]&lt;/div&gt;</summary>
		<author><name>Daniele.cattaneo</name></author>
	</entry>
	<entry>
		<id>https://miosix.org/wiki/index.php?title=User:Daniele.cattaneo&amp;diff=335</id>
		<title>User:Daniele.cattaneo</title>
		<link rel="alternate" type="text/html" href="https://miosix.org/wiki/index.php?title=User:Daniele.cattaneo&amp;diff=335"/>
		<updated>2023-11-28T13:39:49Z</updated>

		<summary type="html">&lt;p&gt;Daniele.cattaneo: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Hi :)&lt;br /&gt;
&lt;br /&gt;
Github (work): [https://github.com/danielecattaneo]&lt;br /&gt;
&lt;br /&gt;
Github (personal): Secret&lt;br /&gt;
&lt;br /&gt;
[[Miosix in emulation]]&lt;br /&gt;
&lt;br /&gt;
[[arch directory restructuring]]&lt;br /&gt;
&lt;br /&gt;
[[Future]]&lt;/div&gt;</summary>
		<author><name>Daniele.cattaneo</name></author>
	</entry>
	<entry>
		<id>https://miosix.org/wiki/index.php?title=Arch_directory_restructuring&amp;diff=334</id>
		<title>Arch directory restructuring</title>
		<link rel="alternate" type="text/html" href="https://miosix.org/wiki/index.php?title=Arch_directory_restructuring&amp;diff=334"/>
		<updated>2023-11-17T23:14:43Z</updated>

		<summary type="html">&lt;p&gt;Daniele.cattaneo: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The &#039;&#039;arch&#039;&#039; directory is a mess with lots of copy-pasted code. Ideally it should be &#039;&#039;&#039;consistently and logically organized&#039;&#039;&#039;: each directory should have a documented purpose in order to leave as little doubt as possible about &#039;&#039;what goes where&#039;&#039;. Additionally, each directory&#039;s purpose makes sense in the overall structure, without overlaps between the scope of each directory.&lt;br /&gt;
At the moment however we observe this is not the case. We believe that in order to make the future growth of Miosix simpler and faster, the right moment to rectify the situation is now.&lt;br /&gt;
&lt;br /&gt;
== Some definitions ==&lt;br /&gt;
&lt;br /&gt;
Common sense suggests the following taxonomy of parts for MCU-equipped devices targeted by Miosix:&lt;br /&gt;
* Board: The device itself being targeted. It&#039;s called a board because nobody has observed any MCU wired with point-to-point wiring yet. Includes the MCU itself plus any peripheral external to the MCU but &#039;&#039;&#039;driven&#039;&#039;&#039; by it.&lt;br /&gt;
* Chip: The MCU itself. May come in RAM/OTP/ROM/Flash size variations, which are mostly ignored.&lt;br /&gt;
* Chip family: A set of MCU types from the same manufacturer with the same microprocessor core but potentially different set of peripherals. While the available set of peripherals may vary, the behaviour and I/O ports of each kind of peripheral are the same across the entire family. Thanks to the brilliant ideas of the various marketing departments of each vendor, the classification here can get very fluid.&lt;br /&gt;
* Core: The microprocessor core used by a given chip family.&lt;br /&gt;
&lt;br /&gt;
Let&#039;s take as an example the classic stm32f4discovery board that is the most common development device for Miosix:&lt;br /&gt;
* The board is the stm32f4discovery itself. It includes the chip, and miscellaneous peripherals such as an accelerometer and a Cirrus Logic audio chip. The STLink programming interface and the power supply are &#039;&#039;&#039;not&#039;&#039;&#039; considered relevant parts of the board for Miosix, as the MCU is not in control of what they do.&lt;br /&gt;
* The chip is an STM32F407VGT6. The VGT6 suffix of the chip name specifies package (100 pin LQFP), Flash size (1MB) and temperature range options (see the datasheet at the &amp;quot;Ordering Information&amp;quot; page).&lt;br /&gt;
* The chip family is STM32F4. This can be inferred by the fact that all available chips with this prefix in the part name share the same reference manual.&lt;br /&gt;
* The core is an ARM Cortex M4, as stated in the datasheet. Roughly, ST buys the Verilog for the core from ARM and then takes care of the manufacturing. As far as we know, ARM&#039;s licence shouldn&#039;t allow ST to customize the core in any way, so all Cortex M4 cores should behave the same, even from other vendors.&lt;br /&gt;
&lt;br /&gt;
=== What is an architecture? ===&lt;br /&gt;
&lt;br /&gt;
One definition we did not give is the definition of what an &#039;&#039;&#039;architecture&#039;&#039;&#039; is. The reason is that there is no accepted definition for this term, especially for forum pundits and bloggers, but also in academia. The RISC school of thought (Patterson/Hennessy and their spawn) historically associated an &#039;&#039;architecture&#039;&#039; with a combination of what are more specifically called the &#039;&#039;instruction set architecture&#039;&#039; (ISA) and the &#039;&#039;microarchitecture&#039;&#039; of a core. The ISA is the overall structure and design of the instructions, as opposed to the &#039;&#039;instruction set&#039;&#039; proper which is the set of instructions accepted by a specific core. The &#039;&#039;&#039;microarchitecture&#039;&#039;&#039; is the overall internal design of the core itself.&lt;br /&gt;
&lt;br /&gt;
Their thesis was that the microarchitecture design will follow naturally from the definition of the ISA, hence simpler ISAs (RISC) to implement always lead to more efficient and generally better cores. Therefore one can consider the &#039;&#039;&#039;architecture&#039;&#039;&#039; to be primarily determined by the ISA. However the industry has proven them wrong, and the most glaring example are Intel x86 chips, which have seen an increasing variety of microarchitectures implementing the same ISA (variously extended of course) with wildly varying levels of (non-)efficiency (in all possible ramifications of &amp;quot;efficiency&amp;quot;). Closer to Miosix&#039;s targets, the ARM ISA has been extended so much over the years that its core RISC design has now evolved to basically a traditional CISC ISA, but ARM chips still come in every possible size and flavour.&lt;br /&gt;
&lt;br /&gt;
When we talk about x86 &amp;quot;architectures&amp;quot; or ARM &amp;quot;architectures&amp;quot;, but do we mean desktop-grade chips or microcontrollers? Even though they have the same &amp;quot;architecture&amp;quot; the cores in these two classes of chips have nothing to do with each other, they don&#039;t even share the same instruction decoder probably. Hence our conclusion that the word &amp;quot;architecture&amp;quot; has now lost all useful meaning for our purposes, and is only useful for void parlor chitchat.&lt;br /&gt;
&lt;br /&gt;
And then we come to Miosix which defines &amp;quot;architecture&amp;quot; (arch) as... a board. Which is not what anyone means when they talk about architecture of anything. For Miosix, an &amp;quot;architecture&amp;quot; is more like what in common parlance would be meant as a &amp;quot;platform&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
== Current structure ==&lt;br /&gt;
&lt;br /&gt;
Here&#039;s a schematic diagram of how the Miosix &#039;&#039;arch&#039;&#039; directory (plus related directories) is configured. In the following &#039;&#039;/&#039;&#039; refers to the &#039;&#039;miosix&#039;&#039; directory at the top level of the repository.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
arch                        Architecture-specific files&lt;br /&gt;
  common                      Pool of useful files. Very few files here are common to all archs.&lt;br /&gt;
    CMSIS                       Collection of ARM &amp;amp; vendor headers following the CMSIS standard&lt;br /&gt;
    core                        Board independent drivers required for the OS to function (roughly)&lt;br /&gt;
      atomic_ops_*.h              Core dependent&lt;br /&gt;
      cache_*.cpp/h               Core dependent. This is not required at all for Miosix to work but is nevertheless here&lt;br /&gt;
      *_os_timer.cpp              Chip family dependent&lt;br /&gt;
      endianness_*.h              Core dependent. Should have a generic (slow) implementation but it&#039;s missing.&lt;br /&gt;
      interrupts.h                Umbrella header for interrupts_*.h&lt;br /&gt;
      interrupts_*.h              Core dependent. Misleading name, this is for fault handling.&lt;br /&gt;
      memory_protection.h         Umbrella header for mpu_*.h. Required only for process mode. Name is not consistent with other umbrella headers, should have been &amp;quot;mpu.h&amp;quot;&lt;br /&gt;
      mpu_*.cpp/h                 Core dependent.&lt;br /&gt;
    drivers                     Miscellaneous drivers, which are &amp;quot;common&amp;quot; only very roughly&lt;br /&gt;
      dcc.cpp/h                   Core dependent (but common to all ARM cores apparently)&lt;br /&gt;
      *_adc.cpp/h                 Chip family dependent&lt;br /&gt;
      serial.h                    Umbrella header for *serial*.h&lt;br /&gt;
      *serial*.cpp/h              Chip family dependent&lt;br /&gt;
      sd_*.cpp/h                  Chip family dependent&lt;br /&gt;
      servo_*.cpp/h               Board dependent really, should go into utils&lt;br /&gt;
      *_hardware_rng.cpp/h        Chip family dependent&lt;br /&gt;
      *_rtc.cpp/h                 Chip family dependent&lt;br /&gt;
      *_sgm.cpp/h                 Chip family dependent&lt;br /&gt;
      *_wd.cpp/h                  Chip family dependent&lt;br /&gt;
      *_i2c.cpp/h                 Chip family dependent&lt;br /&gt;
  &amp;lt;board group name&amp;gt;          Board group specific files.&lt;br /&gt;
    common                      Common drivers and configuration for all the boards in the group&lt;br /&gt;
      arch_settings.h             Core dependent. Misleading name, defines requirements for ctxsave&lt;br /&gt;
      interfaces-impl             The actual drivers, most of them required by Miosix to function.&lt;br /&gt;
        arch_registers_impl.h     Chip family dependent. Includes the appropriate register definitions&lt;br /&gt;
        delays.cpp                Chip family dependent as it also depends on ROM/Flash speed. Actually application dependent (!) as cache/prefetch mechanisms can be configured but whatever.&lt;br /&gt;
        gpio_impl.cpp/h           Chip family dependent.&lt;br /&gt;
        portability_impl.h        Core dependent.&lt;br /&gt;
        portability.cpp           Core dependent.&lt;br /&gt;
      drivers                 Miscellaneous drivers not required by Miosix to function, with exceptions (atsam4l clock)&lt;br /&gt;
        *.cpp/h&lt;br /&gt;
    &amp;lt;board name&amp;gt;              Board/chip specific files.&lt;br /&gt;
      core                      Board/chip dependent code required for the OS to function.&lt;br /&gt;
        stage_1_boot.c/cpp/s      Chip dependent. Interrupt vector table, reset handler, clock tree setup, bss/data initialization&lt;br /&gt;
      interfaces_impl         Important board/chip specific drivers, most of them required by Miosix to function.&lt;br /&gt;
        bsp_impl.h              Board dependent. Useful board-specific definitions.&lt;br /&gt;
        bsp.cpp                 Board dependent. Useful board-specific functions.&lt;br /&gt;
        hwmapping.h             Board dependent. GPIO pin definitions.&lt;br /&gt;
        deep_sleep.cpp          Chip family dependent. Optional implementation of deep sleep primitives.&lt;br /&gt;
        delays.cpp              See above. Sometimes it&#039;s here, with no true reason why.&lt;br /&gt;
        arch_registers_impl.h     See above. Sometimes it&#039;s here, depends on chip.&lt;br /&gt;
        ...                     Some boards have extra miscellaneous drivers here&lt;br /&gt;
      *.h                     Some boards have chip registers definitions here (LPC2138)&lt;br /&gt;
      *.cfg                   Some boards have OpenOCD config files here&lt;br /&gt;
      *.ld                    Chip family specific. Linker files for different RAM/Flash configurations&lt;br /&gt;
interfaces                  Headers for hardware interfaces TO miosix (internals) and SOME interfaces OF miosix to the application (APIs). Only commonality is that they are all hardware dependent (while stuff in utils/kernel is &#039;&#039;generally&#039;&#039; hardware independent)&lt;br /&gt;
  arch_registers.h            API. Umbrella for &amp;quot;arch_registers_impl.h&amp;quot;, selected through include search path manipulation.&lt;br /&gt;
  atomic_ops.h                API. Umbrella for &amp;quot;atomic_ops_*.h&amp;quot;, selected through ifdefs.&lt;br /&gt;
  bsp.h                       API + internal prototypes (IRQbspInit, bspInit2). Umbrella for &amp;quot;bsp_impl.h&amp;quot;, selected through include search path manipulation.&lt;br /&gt;
  deep_sleep.h                Internal prototypes only. Not an umbrella header.&lt;br /&gt;
  delays.h                    API. Not an umbrella header.&lt;br /&gt;
  endianness.h                API. Umbrella for &amp;quot;endianness_*.h&amp;quot;, selected through ifdefs.&lt;br /&gt;
  gpio.h                      API. Umbrella for &amp;quot;gpio_impl.h&amp;quot;, selected through include search path manipulation.&lt;br /&gt;
  os_timer.h                  Internal declarations. Not an umbrella header.&lt;br /&gt;
  portability.h               Internal declarations. Primitives for context switching and syscalls. Umbrella for &amp;quot;portability_impl.h&amp;quot;, selected through include search path manipulation.&lt;br /&gt;
util                        Additional APIs made available for applications as utilities, built on top of kernel primitives or other drivers&lt;br /&gt;
  lcd44780.cpp/h              Driver for Hitachi-standard HD44780 character displays.&lt;br /&gt;
  software_i2c/spi.h          Bit-banged i2c/spi implementations. Arguably drivers.&lt;br /&gt;
  utils.cpp/h                 Memory/CPU usage profiling. Misleading name. Not a driver&lt;br /&gt;
  ...                         Other files are not related to hardware&lt;br /&gt;
config                      Configuration files, user-modifiable&lt;br /&gt;
  Makefile.inc                List of board + selection of board to build for + selection of compile time options through defines passed as argument to the compiler. The first section of the file arguably is not user-modifiable configuration.&lt;br /&gt;
  miosix-settings.h           Global settings selected through defines in header files&lt;br /&gt;
  arch                        Board-dependent settings&lt;br /&gt;
    &amp;lt;board group&amp;gt;&lt;br /&gt;
      &amp;lt;board&amp;gt;&lt;br /&gt;
        board_settings.h      Board-dependent settings selected through defines in header files&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&amp;lt;board group name&amp;gt;&#039;&#039; is defined as the name of the chip core, followed by an underscore, followed by the name of a chip family. &#039;&#039;&amp;lt;board name&amp;gt;&#039;&#039; is defined by the name of the chip, followed by an underscore, followed by a &amp;quot;common name&amp;quot; of the board. For commercial prototyping boards or specific devices, &amp;quot;common name&amp;quot; is derived from the name given by the manufacturer, or a name which is in common use with some exceptions (i.e. stm32f103 bluepill boards are named &amp;quot;breakout&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
Some general patterns can be inferred:&lt;br /&gt;
* Apart from minor exceptions, directories named &#039;&#039;&#039;core&#039;&#039;&#039; contain drivers required for the OS to function.&lt;br /&gt;
* Directories named &#039;&#039;&#039;interfaces_impl&#039;&#039;&#039; generally contain implementations of things defined in /interfaces. Header files in &#039;&#039;&#039;interfaces_impl&#039;&#039;&#039; are always given the ``_impl`` suffix. C++ files are usually not given the &amp;quot;_impl&amp;quot; suffix but sometimes they have it (gpio_impl.cpp).&lt;br /&gt;
* Directories named &#039;&#039;&#039;common&#039;&#039;&#039; contain code shared by multiple boards. No attempt is made to separate different levels of commonality apart from chip-family specific stuff which is grouped by board group.&lt;br /&gt;
&lt;br /&gt;
=== Include paths ===&lt;br /&gt;
&lt;br /&gt;
The current directory structure allows the Makefile to select the implementation of some file by solely changing the include search paths of the compiler. This mostly applies to files in &#039;&#039;&amp;lt;board group name&amp;gt;/&amp;lt;board name&amp;gt;&#039;&#039; and in &#039;&#039;&amp;lt;board group name&amp;gt;/config&#039;&#039;. The Makefile defines several variables that are used to refer to specific paths in the directory tree:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Variable !! Value Pattern !! Scope !! Is config !! Defined by !! Description&lt;br /&gt;
|-&lt;br /&gt;
| LINKER_SCRIPT_PATH || arch/&amp;lt;board group name&amp;gt;/&amp;lt;board name&amp;gt;/ || Board || Yes || Makefile.inc || Directory where the linker scripts are found&lt;br /&gt;
|-&lt;br /&gt;
| LINKER_SCRIPT || $(LINKER_SCRIPT_PATH)/&amp;lt;script&amp;gt;.ld || Board || Yes || Makefile.inc || Path of the linker script&lt;br /&gt;
|-&lt;br /&gt;
| ARCH_INC ||  arch/&amp;lt;board group name&amp;gt;/common || Board group || No || Makefile.inc || Path of the common directory of the board group&lt;br /&gt;
|-&lt;br /&gt;
| BOARD_INC || arch/&amp;lt;board group name&amp;gt;/&amp;lt;board name&amp;gt; || Board || No || Makefile.inc || Path of the board directory&lt;br /&gt;
|-&lt;br /&gt;
| BOOT_FILE || $(BOARD_INC)/core/stage_1_boot.o || Board || No || Makefile.inc || Path of the object file for the board bootstrap code&lt;br /&gt;
|-&lt;br /&gt;
| ARCH_SRC || $(BOARD_INC)/*/*.cpp $(ARCH_INC)/*/*.cpp arch/common/drivers/*.cpp || Board + Board group || No || Sources for the drivers enabled for this board&lt;br /&gt;
|-&lt;br /&gt;
| KPATH || miosix || Global || Yes || Appl. Makefile || Root directory of the kernel files&lt;br /&gt;
|-&lt;br /&gt;
| CONFPATH || $(KPATH) || Global || Yes || Appl. Makefile || Root directory for configuration files&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
For reference, the final include paths, defined by the application makefile, are:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$(CONFPATH)&lt;br /&gt;
$(CONFPATH)/config/$(BOARD_INC)&lt;br /&gt;
$(KPATH)&lt;br /&gt;
$(KPATH)/arch/common&lt;br /&gt;
$(KPATH)/$(ARCH_INC)&lt;br /&gt;
$(KPATH)/$(BOARD_INC)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notice that, despite the name of the defines, there is no distinction between include paths and source paths, as includes are alongside the source. We do not have a problem with this approach, however it results in all includes being publicly available for applications, which is something that is not entirely desirable.&lt;br /&gt;
&lt;br /&gt;
==== Drivers selected by include path ====&lt;br /&gt;
&lt;br /&gt;
Sometimes Miosix&#039;s headers include files that depend on the board selected for building. This of course can give problems when reorganizing files around. The affected files are:&lt;br /&gt;
&lt;br /&gt;
* interfaces/arch_registers.h&lt;br /&gt;
* interfaces/bsp.h&lt;br /&gt;
* interfaces/gpio.h&lt;br /&gt;
* interfaces/portability.h&lt;br /&gt;
&lt;br /&gt;
Overall selecting different files through the include paths is desirable, so we want to avoid adding additional architecture-specific ifdefs as much as possible.&lt;br /&gt;
&lt;br /&gt;
=== Issues ===&lt;br /&gt;
&lt;br /&gt;
Experience has shown this organization has the following problems:&lt;br /&gt;
* What goes where is not well defined due to the vagueness of directory names&lt;br /&gt;
** This leads to files being in the wrong place even though it&#039;s not obvious&lt;br /&gt;
*** servo_* is the most glaring example&lt;br /&gt;
*** The location of delays.cpp and arch_registers_impl.h is also inconsistent&lt;br /&gt;
* The two level board group/board classification does not reflect reality, which leads to missing code sharing opportunities:&lt;br /&gt;
** GPIO implementations are duplicated multiple times as they are common to multiple chip families and not to a single one.&lt;br /&gt;
** Bootstrap code is duplicated multiple times as they are common to boards with the same chip and not common to the board.&lt;br /&gt;
** Portability code (i.e. context save/restore primitives mostly) is duplicated multiple times as they are common to a given core and not to a chip family&lt;br /&gt;
** Linker scripts are also duplicated multiple times&lt;br /&gt;
* Classifications sometimes privilege syntax rather than semantics, in an inconsistent fashion&lt;br /&gt;
** Directories named &#039;&#039;&#039;interfaces_impl&#039;&#039;&#039; contain drivers just like directories named &#039;&#039;&#039;drivers&#039;&#039;&#039;, except that they included from /interfaces.&lt;br /&gt;
** What is &#039;&#039;&#039;common&#039;&#039;&#039; and what is not loosely determined by the amount of code sharing but most stuff not under a &#039;&#039;&#039;common&#039;&#039;&#039; directory is duplicated at least twice&lt;br /&gt;
&lt;br /&gt;
Of course, the root issue is the fluidity of the distinction between chip and chip family, and how each vendor manages and/or defines each family. For instance, STM32 chips all have similar USART (serial) implementations, but at least two versions can be distinguished through different register definitions and feature sets. Therefore the same overall driver can be shared across almost all STM32 chips, however the driver is littered with &#039;&#039;ifdef&#039;&#039;s to single out the specificity of each implementation. There is really no strict distinction to what can be found where, as the vendors can and do mix and match peripherals even amongst themselves. For example, some STM32 chips have Synopsis-designed USB interfaces which can also be found on chips from vendors that are not ST.&lt;br /&gt;
 &lt;br /&gt;
These considerations highlight that the solution to handling the issue of organizing platform-specific code in a consistent way to &#039;&#039;&#039;minimize code duplication&#039;&#039;&#039; is not to &#039;&#039;&#039;add&#039;&#039;&#039; hierarchy levels, but to remove them. This runs contrary from the naive consideration that &amp;quot;Board includes Chip, which belongs to Chip Family, which contains a Core&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
== A proposal ==&lt;br /&gt;
&lt;br /&gt;
Pointing out what&#039;s wrong is easy, fixing it up is hard. Of course &amp;quot;what we should do&amp;quot; is a matter of opinion, and a valid answer to that could even be &amp;quot;nothing&amp;quot;. Overall, what we ultimately want is for all drivers to be decoupled from boards and board groups, in order to be able to classify each driver depending on its actual logical group it belongs to. We can take this opportunity for a more radical restructuring of Miosix&#039;s source tree, or we can opt for more conservative solutions.&lt;br /&gt;
&lt;br /&gt;
=== With classification per device type ===&lt;br /&gt;
&lt;br /&gt;
This proposal is the most radical as it splits the drivers in a completely different way than what is currently done: by device type. For instance all USART drivers go in a &amp;quot;serial&amp;quot; directory, all GPIO drivers go in a GPIO directory, and so on. This approach scales well when there are a lot of drivers around, but completely prevents selection of drivers by using the include paths.&lt;br /&gt;
&lt;br /&gt;
The arch directory has been named &amp;quot;platform&amp;quot; because of our general dislike of the &amp;quot;architecture&amp;quot; word, but that&#039;s really just a bonus. Most other operating systems use &amp;quot;arch&amp;quot; as a directory for drivers and target-specific stuff, so keeping the name &amp;quot;arch&amp;quot; is also an option. We also moved the interfaces headers under the &amp;quot;platform&amp;quot; (&amp;quot;arch&amp;quot;) directory, since they basically are just umbrella headers for various drivers. This loses the distinction of some of them being more essential than others, additional directories can be added for this purpose.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
platform&lt;br /&gt;
  arch_registers.h&lt;br /&gt;
  atomic_ops.h&lt;br /&gt;
  bsp.h&lt;br /&gt;
  deep_sleep.h&lt;br /&gt;
  delays.h&lt;br /&gt;
  endianness.h&lt;br /&gt;
  gpio.h&lt;br /&gt;
  os_timer.h&lt;br /&gt;
  portability.h&lt;br /&gt;
  memory_protection.h&lt;br /&gt;
  interrupts.h&lt;br /&gt;
  mpu.h&lt;br /&gt;
  serial.h&lt;br /&gt;
  arch_registers&lt;br /&gt;
    CMSIS&lt;br /&gt;
    &amp;lt;chip/chip family&amp;gt;&lt;br /&gt;
      arch_registers_impl.h&lt;br /&gt;
      ....h&lt;br /&gt;
  core&lt;br /&gt;
    boot&lt;br /&gt;
      &amp;lt;chip&amp;gt;&lt;br /&gt;
        stage_1_boot.c/cpp/s&lt;br /&gt;
    atomic_ops&lt;br /&gt;
      atomic_ops_*.h&lt;br /&gt;
    os_timer&lt;br /&gt;
      *_os_timer.cpp&lt;br /&gt;
    endianness&lt;br /&gt;
      endianness_*.h&lt;br /&gt;
    faults&lt;br /&gt;
      interrupts_*.h&lt;br /&gt;
    mpu&lt;br /&gt;
      *_mpu.cpp/h&lt;br /&gt;
    portability&lt;br /&gt;
      &amp;lt;core&amp;gt;&lt;br /&gt;
        arch_settings.h&lt;br /&gt;
        portability_impl.h&lt;br /&gt;
        portability.cpp&lt;br /&gt;
    gpio&lt;br /&gt;
      &amp;lt;chip/chip family&amp;gt;&lt;br /&gt;
        gpio_impl.cpp/h&lt;br /&gt;
    delays&lt;br /&gt;
      &amp;lt;chip/chip family&amp;gt;&lt;br /&gt;
        delays.cpp&lt;br /&gt;
  drivers&lt;br /&gt;
    arm_dcc.cpp/h&lt;br /&gt;
    deep_sleep&lt;br /&gt;
      deep_sleep.cpp&lt;br /&gt;
    cache&lt;br /&gt;
      cache_*.cpp/h&lt;br /&gt;
    serial&lt;br /&gt;
      *_serial.cpp/h&lt;br /&gt;
    adc&lt;br /&gt;
      *_adc.cpp/h&lt;br /&gt;
    sd&lt;br /&gt;
      *_sd.cpp/h&lt;br /&gt;
    servo&lt;br /&gt;
      *_servo.cpp/h&lt;br /&gt;
    hardware_rng&lt;br /&gt;
      *_hardware_rng.cpp/h&lt;br /&gt;
    rtc&lt;br /&gt;
      *_rtc.cpp/h&lt;br /&gt;
    sgm&lt;br /&gt;
      *_sgm.cpp/h&lt;br /&gt;
    wd&lt;br /&gt;
      *_wd.cpp/h&lt;br /&gt;
    i2c&lt;br /&gt;
      *_i2c.cpp/h&lt;br /&gt;
      software_i2c.h&lt;br /&gt;
    spi&lt;br /&gt;
      software_spi.h&lt;br /&gt;
    display&lt;br /&gt;
      lcd44780.cpp/h&lt;br /&gt;
    ...&lt;br /&gt;
  board&lt;br /&gt;
    &amp;lt;board&amp;gt;&lt;br /&gt;
      bsp_impl.h&lt;br /&gt;
      bsp.cpp&lt;br /&gt;
      hwmapping.h&lt;br /&gt;
      *.cfg&lt;br /&gt;
  linker_scripts&lt;br /&gt;
    &amp;lt;chip&amp;gt;&lt;br /&gt;
      *.ld&lt;br /&gt;
config&lt;br /&gt;
  Makefile.inc&lt;br /&gt;
  miosix_settings.h&lt;br /&gt;
  &amp;lt;board&amp;gt;&lt;br /&gt;
    board_settings.h&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Without classification per device type ===&lt;br /&gt;
&lt;br /&gt;
This is just the same proposal as before but which classifies drivers only by &amp;quot;manufacturer&amp;quot; or chip. This allows to use the include trick for selecting headers.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
platform&lt;br /&gt;
  arch_registers.h&lt;br /&gt;
  atomic_ops.h&lt;br /&gt;
  bsp.h&lt;br /&gt;
  deep_sleep.h&lt;br /&gt;
  delays.h&lt;br /&gt;
  endianness.h&lt;br /&gt;
  gpio.h&lt;br /&gt;
  os_timer.h&lt;br /&gt;
  portability.h&lt;br /&gt;
  memory_protection.h&lt;br /&gt;
  interrupts.h&lt;br /&gt;
  mpu.h&lt;br /&gt;
  serial.h&lt;br /&gt;
  arch_registers&lt;br /&gt;
    CMSIS&lt;br /&gt;
    &amp;lt;chip/chip family&amp;gt;&lt;br /&gt;
      arch_registers_impl.h&lt;br /&gt;
      ....h&lt;br /&gt;
  core&lt;br /&gt;
    &amp;lt;chip/chip family&amp;gt;&lt;br /&gt;
      stage_1_boot.c/cpp/s&lt;br /&gt;
      *_os_timer.cpp&lt;br /&gt;
      *_mpu.cpp/h&lt;br /&gt;
      gpio_impl.cpp/h&lt;br /&gt;
      delays.cpp&lt;br /&gt;
    &amp;lt;core&amp;gt;&lt;br /&gt;
      atomic_ops_*.h&lt;br /&gt;
      endianness_*.h&lt;br /&gt;
      interrupts_*.h&lt;br /&gt;
      arch_settings.h&lt;br /&gt;
      portability_impl.h&lt;br /&gt;
      portability.cpp&lt;br /&gt;
  drivers&lt;br /&gt;
    dcc.cpp/h&lt;br /&gt;
    *_servo.cpp/h&lt;br /&gt;
    software_i2c.h&lt;br /&gt;
    software_spi.h&lt;br /&gt;
    lcd44780.cpp/h&lt;br /&gt;
    &amp;lt;core&amp;gt;&lt;br /&gt;
      cache_*.cpp/h&lt;br /&gt;
    &amp;lt;chip/chip family&amp;gt;&lt;br /&gt;
      deep_sleep.cpp&lt;br /&gt;
      *_serial.cpp/h&lt;br /&gt;
      *_adc.cpp/h&lt;br /&gt;
      *_sd.cpp/h&lt;br /&gt;
      *_hardware_rng.cpp/h&lt;br /&gt;
      *_rtc.cpp/h&lt;br /&gt;
      *_sgm.cpp/h&lt;br /&gt;
      *_wd.cpp/h&lt;br /&gt;
      *_i2c.cpp/h&lt;br /&gt;
    ...&lt;br /&gt;
  board&lt;br /&gt;
    &amp;lt;board&amp;gt;&lt;br /&gt;
      bsp_impl.h&lt;br /&gt;
      bsp.cpp&lt;br /&gt;
      hwmapping.h&lt;br /&gt;
      *.cfg&lt;br /&gt;
  linker_scripts&lt;br /&gt;
    &amp;lt;chip&amp;gt;&lt;br /&gt;
      *.ld&lt;br /&gt;
config&lt;br /&gt;
  Makefile.inc&lt;br /&gt;
  miosix_settings.h&lt;br /&gt;
  &amp;lt;board&amp;gt;&lt;br /&gt;
    board_settings.h&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== With minimal changes to the existing structure ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
arch&lt;br /&gt;
  common&lt;br /&gt;
    CMSIS&lt;br /&gt;
      core&lt;br /&gt;
        boot&lt;br /&gt;
          &amp;lt;chip&amp;gt;_stage_1_boot.c/cpp/s&lt;br /&gt;
        &amp;lt;core&amp;gt;_portability&lt;br /&gt;
            arch_settings.h&lt;br /&gt;
            portability_impl.h&lt;br /&gt;
            portability.cpp&lt;br /&gt;
        &amp;lt;chip family&amp;gt;&lt;br /&gt;
          delays.cpp&lt;br /&gt;
          gpio_impl.cpp/h&lt;br /&gt;
          deep_sleep.cpp&lt;br /&gt;
        (all other existing files)&lt;br /&gt;
      drivers&lt;br /&gt;
        All miscellaneous drivers in board directory are moved here&lt;br /&gt;
        (all other existing files)&lt;br /&gt;
    linker_scripts&lt;br /&gt;
      &amp;lt;chip&amp;gt;&lt;br /&gt;
        *.ld&lt;br /&gt;
  &amp;lt;board group name&amp;gt;&lt;br /&gt;
    common&lt;br /&gt;
      (should now be empty)&lt;br /&gt;
    &amp;lt;board name&amp;gt;&lt;br /&gt;
      interfaces_impl&lt;br /&gt;
        bsp_impl.h&lt;br /&gt;
        bsp.cpp&lt;br /&gt;
        hwmapping.h&lt;br /&gt;
      *.cfg&lt;br /&gt;
interfaces                    Unmodified&lt;br /&gt;
config                        Unmodified&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Daniele.cattaneo</name></author>
	</entry>
	<entry>
		<id>https://miosix.org/wiki/index.php?title=Arch_directory_restructuring&amp;diff=333</id>
		<title>Arch directory restructuring</title>
		<link rel="alternate" type="text/html" href="https://miosix.org/wiki/index.php?title=Arch_directory_restructuring&amp;diff=333"/>
		<updated>2023-11-16T09:13:19Z</updated>

		<summary type="html">&lt;p&gt;Daniele.cattaneo: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The &#039;&#039;arch&#039;&#039; directory is a mess with lots of copy-pasted code. Ideally it should be &#039;&#039;&#039;consistently and logically organized&#039;&#039;&#039;: each directory should have a documented purpose in order to leave as little doubt as possible about &#039;&#039;what goes where&#039;&#039;. Additionally, each directory&#039;s purpose makes sense in the overall structure, without overlaps between the scope of each directory.&lt;br /&gt;
At the moment however we observe this is not the case. We believe that in order to make the future growth of Miosix simpler and faster, the right moment to rectify the situation is now.&lt;br /&gt;
&lt;br /&gt;
== Some definitions ==&lt;br /&gt;
&lt;br /&gt;
Common sense suggests the following taxonomy of parts for MCU-equipped devices targeted by Miosix:&lt;br /&gt;
* Board: The device itself being targeted. It&#039;s called a board because nobody has observed any MCU wired with point-to-point wiring yet. Includes the MCU itself plus any peripheral external to the MCU but &#039;&#039;&#039;driven&#039;&#039;&#039; by it.&lt;br /&gt;
* Chip: The MCU itself. May come in RAM/OTP/ROM/Flash size variations, which are mostly ignored.&lt;br /&gt;
* Chip family: A set of MCU types from the same manufacturer with the same microprocessor core but potentially different set of peripherals. While the available set of peripherals may vary, the behaviour and I/O ports of each kind of peripheral are the same across the entire family. Thanks to the brilliant ideas of the various marketing departments of each vendor, the classification here can get very fluid.&lt;br /&gt;
* Core: The microprocessor core used by a given chip family.&lt;br /&gt;
&lt;br /&gt;
Let&#039;s take as an example the classic stm32f4discovery board that is the most common development device for Miosix:&lt;br /&gt;
* The board is the stm32f4discovery itself. It includes the chip, and miscellaneous peripherals such as an accelerometer and a Cirrus Logic audio chip. The STLink programming interface and the power supply are &#039;&#039;&#039;not&#039;&#039;&#039; considered relevant parts of the board for Miosix, as the MCU is not in control of what they do.&lt;br /&gt;
* The chip is an STM32F407VGT6. The VGT6 suffix of the chip name specifies package (100 pin LQFP), Flash size (1MB) and temperature range options (see the datasheet at the &amp;quot;Ordering Information&amp;quot; page).&lt;br /&gt;
* The chip family is STM32F4. This can be inferred by the fact that all available chips with this prefix in the part name share the same reference manual.&lt;br /&gt;
* The core is an ARM Cortex M4, as stated in the datasheet. Roughly, ST buys the Verilog for the core from ARM and then takes care of the manufacturing. As far as we know, ARM&#039;s licence shouldn&#039;t allow ST to customize the core in any way, so all Cortex M4 cores should behave the same, even from other vendors.&lt;br /&gt;
&lt;br /&gt;
=== What is an architecture? ===&lt;br /&gt;
&lt;br /&gt;
One definition we did not give is the definition of what an &#039;&#039;&#039;architecture&#039;&#039;&#039; is. The reason is that there is no accepted definition for this term, especially for forum pundits and bloggers, but also in academia. The RISC school of thought (Patterson/Hennessy and their spawn) historically associated an &#039;&#039;architecture&#039;&#039; with a combination of what are more specifically called the &#039;&#039;instruction set architecture&#039;&#039; (ISA) and the &#039;&#039;microarchitecture&#039;&#039; of a core. The ISA is the overall structure and design of the instructions, as opposed to the &#039;&#039;instruction set&#039;&#039; proper which is the set of instructions accepted by a specific core. The &#039;&#039;&#039;microarchitecture&#039;&#039;&#039; is the overall internal design of the core itself.&lt;br /&gt;
&lt;br /&gt;
Their thesis was that the microarchitecture design will follow naturally from the definition of the ISA, hence simpler ISAs (RISC) to implement always lead to more efficient and generally better cores. Therefore one can consider the &#039;&#039;&#039;architecture&#039;&#039;&#039; to be primarily determined by the ISA. However the industry has proven them wrong, and the most glaring example are Intel x86 chips, which have seen an increasing variety of microarchitectures implementing the same ISA (variously extended of course) with wildly varying levels of (non-)efficiency (in all possible ramifications of &amp;quot;efficiency&amp;quot;). Closer to Miosix&#039;s targets, the ARM ISA has been extended so much over the years that its core RISC design has now evolved to basically a traditional CISC ISA, but ARM chips still come in every possible size and flavour.&lt;br /&gt;
&lt;br /&gt;
When we talk about x86 &amp;quot;architectures&amp;quot; or ARM &amp;quot;architectures&amp;quot;, but do we mean desktop-grade chips or microcontrollers? Even though they have the same &amp;quot;architecture&amp;quot; the cores in these two classes of chips have nothing to do with each other, they don&#039;t even share the same instruction decoder probably. Hence our conclusion that the word &amp;quot;architecture&amp;quot; has now lost all useful meaning for our purposes, and is only useful for void parlor chitchat.&lt;br /&gt;
&lt;br /&gt;
And then we come to Miosix which defines &amp;quot;architecture&amp;quot; (arch) as... a board. Which is not what anyone means when they talk about architecture of anything. For Miosix, an &amp;quot;architecture&amp;quot; is more like what in common parlance would be meant as a &amp;quot;platform&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
== Current structure ==&lt;br /&gt;
&lt;br /&gt;
Here&#039;s a schematic diagram of how the Miosix &#039;&#039;arch&#039;&#039; directory (plus related directories) is configured. In the following &#039;&#039;/&#039;&#039; refers to the &#039;&#039;miosix&#039;&#039; directory at the top level of the repository.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
arch                        Architecture-specific files&lt;br /&gt;
  common                      Pool of useful files. Very few files here are common to all archs.&lt;br /&gt;
    CMSIS                       Collection of ARM &amp;amp; vendor headers following the CMSIS standard&lt;br /&gt;
    core                        Board independent drivers required for the OS to function (roughly)&lt;br /&gt;
      atomic_ops_*.h              Core dependent&lt;br /&gt;
      cache_*.cpp/h               Core dependent. This is not required at all for Miosix to work but is nevertheless here&lt;br /&gt;
      *_os_timer.cpp              Chip family dependent&lt;br /&gt;
      endianness_*.h              Core dependent. Should have a generic (slow) implementation but it&#039;s missing.&lt;br /&gt;
      interrupts.h                Umbrella header for interrupts_*.h&lt;br /&gt;
      interrupts_*.h              Core dependent. Misleading name, this is for fault handling.&lt;br /&gt;
      memory_protection.h         Umbrella header for mpu_*.h. Required only for process mode. Name is not consistent with other umbrella headers, should have been &amp;quot;mpu.h&amp;quot;&lt;br /&gt;
      mpu_*.cpp/h                 Core dependent.&lt;br /&gt;
    drivers                     Miscellaneous drivers, which are &amp;quot;common&amp;quot; only very roughly&lt;br /&gt;
      dcc.cpp/h                   Core dependent (but common to all ARM cores apparently)&lt;br /&gt;
      *_adc.cpp/h                 Chip family dependent&lt;br /&gt;
      serial.h                    Umbrella header for *serial*.h&lt;br /&gt;
      *serial*.cpp/h              Chip family dependent&lt;br /&gt;
      sd_*.cpp/h                  Chip family dependent&lt;br /&gt;
      servo_*.cpp/h               Board dependent really, should go into utils&lt;br /&gt;
      *_hardware_rng.cpp/h        Chip family dependent&lt;br /&gt;
      *_rtc.cpp/h                 Chip family dependent&lt;br /&gt;
      *_sgm.cpp/h                 Chip family dependent&lt;br /&gt;
      *_wd.cpp/h                  Chip family dependent&lt;br /&gt;
      *_i2c.cpp/h                 Chip family dependent&lt;br /&gt;
  &amp;lt;board group name&amp;gt;          Board group specific files.&lt;br /&gt;
    common                      Common drivers and configuration for all the boards in the group&lt;br /&gt;
      arch_settings.h             Core dependent. Misleading name, defines requirements for ctxsave&lt;br /&gt;
      interfaces-impl             The actual drivers, most of them required by Miosix to function.&lt;br /&gt;
        arch_registers_impl.h     Chip family dependent. Includes the appropriate register definitions&lt;br /&gt;
        delays.cpp                Chip family dependent as it also depends on ROM/Flash speed. Actually application dependent (!) as cache/prefetch mechanisms can be configured but whatever.&lt;br /&gt;
        gpio_impl.cpp/h           Chip family dependent.&lt;br /&gt;
        portability_impl.h        Core dependent.&lt;br /&gt;
        portability.cpp           Core dependent.&lt;br /&gt;
      drivers                 Miscellaneous drivers not required by Miosix to function, with exceptions (atsam4l clock)&lt;br /&gt;
        *.cpp/h&lt;br /&gt;
    &amp;lt;board name&amp;gt;              Board/chip specific files.&lt;br /&gt;
      core                      Board/chip dependent code required for the OS to function.&lt;br /&gt;
        stage_1_boot.c/cpp/s      Chip dependent. Interrupt vector table, reset handler, clock tree setup, bss/data initialization&lt;br /&gt;
      interfaces_impl         Important board/chip specific drivers, most of them required by Miosix to function.&lt;br /&gt;
        bsp_impl.h              Board dependent. Useful board-specific definitions.&lt;br /&gt;
        bsp.cpp                 Board dependent. Useful board-specific functions.&lt;br /&gt;
        hwmapping.h             Board dependent. GPIO pin definitions.&lt;br /&gt;
        deep_sleep.cpp          Chip family dependent. Optional implementation of deep sleep primitives.&lt;br /&gt;
        delays.cpp              See above. Sometimes it&#039;s here, with no true reason why.&lt;br /&gt;
        arch_registers_impl.h     See above. Sometimes it&#039;s here, depends on chip.&lt;br /&gt;
        ...                     Some boards have extra miscellaneous drivers here&lt;br /&gt;
      *.h                     Some boards have chip registers definitions here (LPC2138)&lt;br /&gt;
      *.cfg                   Some boards have OpenOCD config files here&lt;br /&gt;
      *.ld                    Chip family specific. Linker files for different RAM/Flash configurations&lt;br /&gt;
interfaces                  Headers for hardware interfaces TO miosix (internals) and SOME interfaces OF miosix to the application (APIs). Only commonality is that they are all hardware dependent (while stuff in utils/kernel is &#039;&#039;generally&#039;&#039; hardware independent)&lt;br /&gt;
  arch_registers.h            API. Umbrella for &amp;quot;arch_registers_impl.h&amp;quot;, selected through include search path manipulation.&lt;br /&gt;
  atomic_ops.h                API. Umbrella for &amp;quot;atomic_ops_*.h&amp;quot;, selected through ifdefs.&lt;br /&gt;
  bsp.h                       API + internal prototypes (IRQbspInit, bspInit2). Umbrella for &amp;quot;bsp_impl.h&amp;quot;, selected through include search path manipulation.&lt;br /&gt;
  deep_sleep.h                Internal prototypes only. Not an umbrella header.&lt;br /&gt;
  delays.h                    API. Not an umbrella header.&lt;br /&gt;
  endianness.h                API. Umbrella for &amp;quot;endianness_*.h&amp;quot;, selected through ifdefs.&lt;br /&gt;
  gpio.h                      API. Umbrella for &amp;quot;gpio_impl.h&amp;quot;, selected through include search path manipulation.&lt;br /&gt;
  os_timer.h                  Internal declarations. Not an umbrella header.&lt;br /&gt;
  portability.h               Internal declarations. Primitives for context switching and syscalls. Umbrella for &amp;quot;portability_impl.h&amp;quot;, selected through include search path manipulation.&lt;br /&gt;
util                        Additional APIs made available for applications as utilities, built on top of kernel primitives or other drivers&lt;br /&gt;
  lcd44780.cpp/h              Driver for Hitachi-standard HD44780 character displays.&lt;br /&gt;
  software_i2c/spi.h          Bit-banged i2c/spi implementations. Arguably drivers.&lt;br /&gt;
  utils.cpp/h                 Memory/CPU usage profiling. Misleading name. Not a driver&lt;br /&gt;
  ...                         Other files are not related to hardware&lt;br /&gt;
config                      Configuration files, user-modifiable&lt;br /&gt;
  Makefile.inc                List of board + selection of board to build for + selection of compile time options through defines passed as argument to the compiler. The first section of the file arguably is not user-modifiable configuration.&lt;br /&gt;
  miosix-settings.h           Global settings selected through defines in header files&lt;br /&gt;
  arch                        Board-dependent settings&lt;br /&gt;
    &amp;lt;board group&amp;gt;&lt;br /&gt;
      &amp;lt;board&amp;gt;&lt;br /&gt;
        board_settings.h      Board-dependent settings selected through defines in header files&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&amp;lt;board group name&amp;gt;&#039;&#039; is defined as the name of the chip core, followed by an underscore, followed by the name of a chip family. &#039;&#039;&amp;lt;board name&amp;gt;&#039;&#039; is defined by the name of the chip, followed by an underscore, followed by a &amp;quot;common name&amp;quot; of the board. For commercial prototyping boards or specific devices, &amp;quot;common name&amp;quot; is derived from the name given by the manufacturer, or a name which is in common use with some exceptions (i.e. stm32f103 bluepill boards are named &amp;quot;breakout&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
Some general patterns can be inferred:&lt;br /&gt;
* Apart from minor exceptions, directories named &#039;&#039;&#039;core&#039;&#039;&#039; contain drivers required for the OS to function.&lt;br /&gt;
* Directories named &#039;&#039;&#039;interfaces_impl&#039;&#039;&#039; generally contain implementations of things defined in /interfaces. Header files in &#039;&#039;&#039;interfaces_impl&#039;&#039;&#039; are always given the ``_impl`` suffix. C++ files are usually not given the &amp;quot;_impl&amp;quot; suffix but sometimes they have it (gpio_impl.cpp).&lt;br /&gt;
* Directories named &#039;&#039;&#039;common&#039;&#039;&#039; contain code shared by multiple boards. No attempt is made to separate different levels of commonality apart from chip-family specific stuff which is grouped by board group.&lt;br /&gt;
&lt;br /&gt;
=== Include paths ===&lt;br /&gt;
&lt;br /&gt;
The current directory structure allows the Makefile to select the implementation of some file by solely changing the include search paths of the compiler. This mostly applies to files in &#039;&#039;&amp;lt;board group name&amp;gt;/&amp;lt;board name&amp;gt;&#039;&#039; and in &#039;&#039;&amp;lt;board group name&amp;gt;/config&#039;&#039;. The Makefile defines several variables that are used to refer to specific paths in the directory tree:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Variable !! Value Pattern !! Scope !! Is config !! Defined by !! Description&lt;br /&gt;
|-&lt;br /&gt;
| LINKER_SCRIPT_PATH || arch/&amp;lt;board group name&amp;gt;/&amp;lt;board name&amp;gt;/ || Board || Yes || Makefile.inc || Directory where the linker scripts are found&lt;br /&gt;
|-&lt;br /&gt;
| LINKER_SCRIPT || $(LINKER_SCRIPT_PATH)/&amp;lt;script&amp;gt;.ld || Board || Yes || Makefile.inc || Path of the linker script&lt;br /&gt;
|-&lt;br /&gt;
| ARCH_INC ||  arch/&amp;lt;board group name&amp;gt;/common || Board group || No || Makefile.inc || Path of the common directory of the board group&lt;br /&gt;
|-&lt;br /&gt;
| BOARD_INC || arch/&amp;lt;board group name&amp;gt;/&amp;lt;board name&amp;gt; || Board || No || Makefile.inc || Path of the board directory&lt;br /&gt;
|-&lt;br /&gt;
| BOOT_FILE || $(BOARD_INC)/core/stage_1_boot.o || Board || No || Makefile.inc || Path of the object file for the board bootstrap code&lt;br /&gt;
|-&lt;br /&gt;
| ARCH_SRC || $(BOARD_INC)/*/*.cpp $(ARCH_INC)/*/*.cpp arch/common/drivers/*.cpp || Board + Board group || No || Sources for the drivers enabled for this board&lt;br /&gt;
|-&lt;br /&gt;
| KPATH || miosix || Global || Yes || Appl. Makefile || Root directory of the kernel files&lt;br /&gt;
|-&lt;br /&gt;
| CONFPATH || $(KPATH) || Global || Yes || Appl. Makefile || Root directory for configuration files&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
For reference, the final include paths, defined by the application makefile, are:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$(CONFPATH)&lt;br /&gt;
$(CONFPATH)/config/$(BOARD_INC)&lt;br /&gt;
$(KPATH)&lt;br /&gt;
$(KPATH)/arch/common&lt;br /&gt;
$(KPATH)/$(ARCH_INC)&lt;br /&gt;
$(KPATH)/$(BOARD_INC)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notice that, despite the name of the defines, there is no distinction between include paths and source paths, as includes are alongside the source. We do not have a problem with this approach, however it results in all includes being publicly available for applications, which is something that is not entirely desirable.&lt;br /&gt;
&lt;br /&gt;
=== Issues ===&lt;br /&gt;
&lt;br /&gt;
Experience has shown this organization has the following problems:&lt;br /&gt;
* What goes where is not well defined due to the vagueness of directory names&lt;br /&gt;
** This leads to files being in the wrong place even though it&#039;s not obvious&lt;br /&gt;
*** servo_* is the most glaring example&lt;br /&gt;
*** The location of delays.cpp and arch_registers_impl.h is also inconsistent&lt;br /&gt;
* The two level board group/board classification does not reflect reality, which leads to missing code sharing opportunities:&lt;br /&gt;
** GPIO implementations are duplicated multiple times as they are common to multiple chip families and not to a single one.&lt;br /&gt;
** Bootstrap code is duplicated multiple times as they are common to boards with the same chip and not common to the board.&lt;br /&gt;
** Portability code (i.e. context save/restore primitives mostly) is duplicated multiple times as they are common to a given core and not to a chip family&lt;br /&gt;
* Classifications sometimes privilege syntax rather than semantics, in an inconsistent fashion&lt;br /&gt;
** Directories named &#039;&#039;&#039;interfaces_impl&#039;&#039;&#039; contain drivers just like directories named &#039;&#039;&#039;drivers&#039;&#039;&#039;, except that they included from /interfaces.&lt;br /&gt;
** What is &#039;&#039;&#039;common&#039;&#039;&#039; and what is not loosely determined by the amount of code sharing but most stuff not under a &#039;&#039;&#039;common&#039;&#039;&#039; directory is duplicated at least twice&lt;br /&gt;
&lt;br /&gt;
Of course, the root issue is the fluidity of the distinction between chip and chip family, and how each vendor manages and/or defines each family. For instance, STM32 chips all have similar USART (serial) implementations, but at least two versions can be distinguished through different register definitions and feature sets. Therefore the same overall driver can be shared across almost all STM32 chips, however the driver is littered with &#039;&#039;ifdef&#039;&#039;s to single out the specificity of each implementation. There is really no strict distinction to what can be found where, as the vendors can and do mix and match peripherals even amongst themselves. For example, some STM32 chips have Synopsis-designed USB interfaces which can also be found on chips from vendors that are not ST.&lt;br /&gt;
 &lt;br /&gt;
These considerations highlight that the solution to handling the issue of organizing platform-specific code in a consistent way to &#039;&#039;&#039;minimize code duplication&#039;&#039;&#039; is not to &#039;&#039;&#039;add&#039;&#039;&#039; hierarchy levels, but to remove them. This runs contrary from the naive consideration that &amp;quot;Board includes Chip, which belongs to Chip Family, which contains a Core&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
== A proposal ==&lt;br /&gt;
&lt;br /&gt;
Pointing out what&#039;s wrong is easy, fixing it up is hard. Of course &amp;quot;what we should do&amp;quot; is a matter of opinion, and a valid answer to that could even be &amp;quot;nothing&amp;quot;. If I were to do something, I would do the following:&lt;br /&gt;
&lt;br /&gt;
=== With classification per device type ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
platform&lt;br /&gt;
  arch_registers.h&lt;br /&gt;
  atomic_ops.h&lt;br /&gt;
  bsp.h&lt;br /&gt;
  deep_sleep.h&lt;br /&gt;
  delays.h&lt;br /&gt;
  endianness.h&lt;br /&gt;
  gpio.h&lt;br /&gt;
  os_timer.h&lt;br /&gt;
  portability.h&lt;br /&gt;
  memory_protection.h&lt;br /&gt;
  interrupts.h&lt;br /&gt;
  mpu.h&lt;br /&gt;
  serial.h&lt;br /&gt;
  arch_registers&lt;br /&gt;
    CMSIS&lt;br /&gt;
    &amp;lt;chip/chip family&amp;gt;&lt;br /&gt;
      arch_registers_impl.h&lt;br /&gt;
      ....h&lt;br /&gt;
  core&lt;br /&gt;
    boot&lt;br /&gt;
      &amp;lt;chip&amp;gt;&lt;br /&gt;
        stage_1_boot.c/cpp/s&lt;br /&gt;
    atomic_ops&lt;br /&gt;
      atomic_ops_*.h&lt;br /&gt;
    os_timer&lt;br /&gt;
      *_os_timer.cpp&lt;br /&gt;
    endianness&lt;br /&gt;
      endianness_*.h&lt;br /&gt;
    faults&lt;br /&gt;
      interrupts_*.h&lt;br /&gt;
    mpu&lt;br /&gt;
      *_mpu.cpp/h&lt;br /&gt;
    portability&lt;br /&gt;
      &amp;lt;core&amp;gt;&lt;br /&gt;
        arch_settings.h&lt;br /&gt;
        portability_impl.h&lt;br /&gt;
        portability.cpp&lt;br /&gt;
    gpio&lt;br /&gt;
      &amp;lt;chip/chip family&amp;gt;&lt;br /&gt;
        gpio_impl.cpp/h&lt;br /&gt;
    delays&lt;br /&gt;
      &amp;lt;chip/chip family&amp;gt;&lt;br /&gt;
        delays.cpp&lt;br /&gt;
  drivers&lt;br /&gt;
    arm_dcc.cpp/h&lt;br /&gt;
    deep_sleep&lt;br /&gt;
      deep_sleep.cpp&lt;br /&gt;
    cache&lt;br /&gt;
      cache_*.cpp/h&lt;br /&gt;
    serial&lt;br /&gt;
      *_serial.cpp/h&lt;br /&gt;
    adc&lt;br /&gt;
      *_adc.cpp/h&lt;br /&gt;
    sd&lt;br /&gt;
      *_sd.cpp/h&lt;br /&gt;
    servo&lt;br /&gt;
      *_servo.cpp/h&lt;br /&gt;
    hardware_rng&lt;br /&gt;
      *_hardware_rng.cpp/h&lt;br /&gt;
    rtc&lt;br /&gt;
      *_rtc.cpp/h&lt;br /&gt;
    sgm&lt;br /&gt;
      *_sgm.cpp/h&lt;br /&gt;
    wd&lt;br /&gt;
      *_wd.cpp/h&lt;br /&gt;
    i2c&lt;br /&gt;
      *_i2c.cpp/h&lt;br /&gt;
      software_i2c.h&lt;br /&gt;
    spi&lt;br /&gt;
      software_spi.h&lt;br /&gt;
    display&lt;br /&gt;
      lcd44780.cpp/h&lt;br /&gt;
    ...&lt;br /&gt;
  board&lt;br /&gt;
    &amp;lt;board&amp;gt;&lt;br /&gt;
      bsp_impl.h&lt;br /&gt;
      bsp.cpp&lt;br /&gt;
      hwmapping.h&lt;br /&gt;
      *.cfg&lt;br /&gt;
  linker_scripts&lt;br /&gt;
    &amp;lt;chip&amp;gt;&lt;br /&gt;
      *.ld&lt;br /&gt;
config&lt;br /&gt;
  Makefile.inc&lt;br /&gt;
  miosix_settings.h&lt;br /&gt;
  &amp;lt;board&amp;gt;&lt;br /&gt;
    board_settings.h&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Without classification per device type ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
platform&lt;br /&gt;
  arch_registers.h&lt;br /&gt;
  atomic_ops.h&lt;br /&gt;
  bsp.h&lt;br /&gt;
  deep_sleep.h&lt;br /&gt;
  delays.h&lt;br /&gt;
  endianness.h&lt;br /&gt;
  gpio.h&lt;br /&gt;
  os_timer.h&lt;br /&gt;
  portability.h&lt;br /&gt;
  memory_protection.h&lt;br /&gt;
  interrupts.h&lt;br /&gt;
  mpu.h&lt;br /&gt;
  serial.h&lt;br /&gt;
  arch_registers&lt;br /&gt;
    CMSIS&lt;br /&gt;
    &amp;lt;chip/chip family&amp;gt;&lt;br /&gt;
      arch_registers_impl.h&lt;br /&gt;
      ....h&lt;br /&gt;
  core&lt;br /&gt;
    &amp;lt;chip/chip family&amp;gt;&lt;br /&gt;
      stage_1_boot.c/cpp/s&lt;br /&gt;
      *_os_timer.cpp&lt;br /&gt;
      *_mpu.cpp/h&lt;br /&gt;
      gpio_impl.cpp/h&lt;br /&gt;
      delays.cpp&lt;br /&gt;
    &amp;lt;core&amp;gt;&lt;br /&gt;
      atomic_ops_*.h&lt;br /&gt;
      endianness_*.h&lt;br /&gt;
      interrupts_*.h&lt;br /&gt;
      arch_settings.h&lt;br /&gt;
      portability_impl.h&lt;br /&gt;
      portability.cpp&lt;br /&gt;
  drivers&lt;br /&gt;
    dcc.cpp/h&lt;br /&gt;
    *_servo.cpp/h&lt;br /&gt;
    software_i2c.h&lt;br /&gt;
    software_spi.h&lt;br /&gt;
    lcd44780.cpp/h&lt;br /&gt;
    &amp;lt;core&amp;gt;&lt;br /&gt;
      cache_*.cpp/h&lt;br /&gt;
    &amp;lt;chip/chip family&amp;gt;&lt;br /&gt;
      deep_sleep.cpp&lt;br /&gt;
      *_serial.cpp/h&lt;br /&gt;
      *_adc.cpp/h&lt;br /&gt;
      *_sd.cpp/h&lt;br /&gt;
      *_hardware_rng.cpp/h&lt;br /&gt;
      *_rtc.cpp/h&lt;br /&gt;
      *_sgm.cpp/h&lt;br /&gt;
      *_wd.cpp/h&lt;br /&gt;
      *_i2c.cpp/h&lt;br /&gt;
    ...&lt;br /&gt;
  board&lt;br /&gt;
    &amp;lt;board&amp;gt;&lt;br /&gt;
      bsp_impl.h&lt;br /&gt;
      bsp.cpp&lt;br /&gt;
      hwmapping.h&lt;br /&gt;
      *.cfg&lt;br /&gt;
  linker_scripts&lt;br /&gt;
    &amp;lt;chip&amp;gt;&lt;br /&gt;
      *.ld&lt;br /&gt;
config&lt;br /&gt;
  Makefile.inc&lt;br /&gt;
  miosix_settings.h&lt;br /&gt;
  &amp;lt;board&amp;gt;&lt;br /&gt;
    board_settings.h&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== With minimal changes to the existing structure ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
arch&lt;br /&gt;
  common&lt;br /&gt;
    CMSIS&lt;br /&gt;
      core&lt;br /&gt;
        boot&lt;br /&gt;
          &amp;lt;chip&amp;gt;_stage_1_boot.c/cpp/s&lt;br /&gt;
        &amp;lt;core&amp;gt;_portability&lt;br /&gt;
            arch_settings.h&lt;br /&gt;
            portability_impl.h&lt;br /&gt;
            portability.cpp&lt;br /&gt;
        &amp;lt;chip family&amp;gt;&lt;br /&gt;
          delays.cpp&lt;br /&gt;
          gpio_impl.cpp/h&lt;br /&gt;
          deep_sleep.cpp&lt;br /&gt;
        (all other existing files)&lt;br /&gt;
      drivers&lt;br /&gt;
        All miscellaneous drivers in board directory are moved here&lt;br /&gt;
        (all other existing files)&lt;br /&gt;
    linker_scripts&lt;br /&gt;
      &amp;lt;chip&amp;gt;&lt;br /&gt;
        *.ld&lt;br /&gt;
  &amp;lt;board group name&amp;gt;&lt;br /&gt;
    common&lt;br /&gt;
      (should now be empty)&lt;br /&gt;
    &amp;lt;board name&amp;gt;&lt;br /&gt;
      interfaces_impl&lt;br /&gt;
        bsp_impl.h&lt;br /&gt;
        bsp.cpp&lt;br /&gt;
        hwmapping.h&lt;br /&gt;
      *.cfg&lt;br /&gt;
interfaces                    Unmodified&lt;br /&gt;
config                        Unmodified&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Daniele.cattaneo</name></author>
	</entry>
	<entry>
		<id>https://miosix.org/wiki/index.php?title=Arch_directory_restructuring&amp;diff=332</id>
		<title>Arch directory restructuring</title>
		<link rel="alternate" type="text/html" href="https://miosix.org/wiki/index.php?title=Arch_directory_restructuring&amp;diff=332"/>
		<updated>2023-11-13T15:44:25Z</updated>

		<summary type="html">&lt;p&gt;Daniele.cattaneo: Start of proposal&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The &#039;&#039;arch&#039;&#039; directory is a mess with lots of copy-pasted code. Ideally it should be &#039;&#039;&#039;consistently and logically organized&#039;&#039;&#039;: each directory should have a documented purpose in order to leave as little doubt as possible about &#039;&#039;what goes where&#039;&#039;. Additionally, each directory&#039;s purpose makes sense in the overall structure, without overlaps between the scope of each directory.&lt;br /&gt;
At the moment however we observe this is not the case. We believe that in order to make the future growth of Miosix simpler and faster, the right moment to rectify the situation is now.&lt;br /&gt;
&lt;br /&gt;
== Some definitions ==&lt;br /&gt;
&lt;br /&gt;
Common sense suggests the following taxonomy of parts for MCU-equipped devices targeted by Miosix:&lt;br /&gt;
* Board: The device itself being targeted. It&#039;s called a board because nobody has observed any MCU wired with point-to-point wiring yet. Includes the MCU itself plus any peripheral external to the MCU but &#039;&#039;&#039;driven&#039;&#039;&#039; by it.&lt;br /&gt;
* Chip: The MCU itself. May come in RAM/OTP/ROM/Flash size variations, which are mostly ignored.&lt;br /&gt;
* Chip family: A set of MCU types from the same manufacturer with the same microprocessor core but potentially different set of peripherals. While the available set of peripherals may vary, the behaviour and I/O ports of each kind of peripheral are the same across the entire family. Thanks to the brilliant ideas of the various marketing departments of each vendor, the classification here can get very fluid.&lt;br /&gt;
* Core: The microprocessor core used by a given chip family.&lt;br /&gt;
&lt;br /&gt;
Let&#039;s take as an example the classic stm32f4discovery board that is the most common development device for Miosix:&lt;br /&gt;
* The board is the stm32f4discovery itself. It includes the chip, and miscellaneous peripherals such as an accelerometer and a Cirrus Logic audio chip. The STLink programming interface and the power supply are &#039;&#039;&#039;not&#039;&#039;&#039; considered relevant parts of the board for Miosix, as the MCU is not in control of what they do.&lt;br /&gt;
* The chip is an STM32F407VGT6. The VGT6 suffix of the chip name specifies package (100 pin LQFP), Flash size (1MB) and temperature range options (see the datasheet at the &amp;quot;Ordering Information&amp;quot; page).&lt;br /&gt;
* The chip family is STM32F4. This can be inferred by the fact that all available chips with this prefix in the part name share the same reference manual.&lt;br /&gt;
* The core is an ARM Cortex M4, as stated in the datasheet. Roughly, ST buys the Verilog for the core from ARM and then takes care of the manufacturing. As far as we know, ARM&#039;s licence shouldn&#039;t allow ST to customize the core in any way, so all Cortex M4 cores should behave the same, even from other vendors.&lt;br /&gt;
&lt;br /&gt;
=== What is an architecture? ===&lt;br /&gt;
&lt;br /&gt;
One definition we did not give is the definition of what an &#039;&#039;&#039;architecture&#039;&#039;&#039; is. The reason is that there is no accepted definition for this term, especially for forum pundits and bloggers, but also in academia. The RISC school of thought (Patterson/Hennessy and their spawn) historically associated an &#039;&#039;architecture&#039;&#039; with a combination of what are more specifically called the &#039;&#039;instruction set architecture&#039;&#039; (ISA) and the &#039;&#039;microarchitecture&#039;&#039; of a core. The ISA is the overall structure and design of the instructions, as opposed to the &#039;&#039;instruction set&#039;&#039; proper which is the set of instructions accepted by a specific core. The &#039;&#039;&#039;microarchitecture&#039;&#039;&#039; is the overall internal design of the core itself.&lt;br /&gt;
&lt;br /&gt;
Their thesis was that the microarchitecture design will follow naturally from the definition of the ISA, hence simpler ISAs (RISC) to implement always lead to more efficient and generally better cores. Therefore one can consider the &#039;&#039;&#039;architecture&#039;&#039;&#039; to be primarily determined by the ISA. However the industry has proven them wrong, and the most glaring example are Intel x86 chips, which have seen an increasing variety of microarchitectures implementing the same ISA (variously extended of course) with wildly varying levels of (non-)efficiency (in all possible ramifications of &amp;quot;efficiency&amp;quot;). Closer to Miosix&#039;s targets, the ARM ISA has been extended so much over the years that its core RISC design has now evolved to basically a traditional CISC ISA, but ARM chips still come in every possible size and flavour.&lt;br /&gt;
&lt;br /&gt;
When we talk about x86 &amp;quot;architectures&amp;quot; or ARM &amp;quot;architectures&amp;quot;, but do we mean desktop-grade chips or microcontrollers? Even though they have the same &amp;quot;architecture&amp;quot; the cores in these two classes of chips have nothing to do with each other, they don&#039;t even share the same instruction decoder probably. Hence our conclusion that the word &amp;quot;architecture&amp;quot; has now lost all useful meaning for our purposes, and is only useful for void parlor chitchat.&lt;br /&gt;
&lt;br /&gt;
And then we come to Miosix which defines &amp;quot;architecture&amp;quot; (arch) as... a board. Which is not what anyone means when they talk about architecture of anything. For Miosix, an &amp;quot;architecture&amp;quot; is more like what in common parlance would be meant as a &amp;quot;platform&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
== Current structure ==&lt;br /&gt;
&lt;br /&gt;
Here&#039;s a schematic diagram of how the Miosix &#039;&#039;arch&#039;&#039; directory (plus related directories) is configured. In the following &#039;&#039;/&#039;&#039; refers to the &#039;&#039;miosix&#039;&#039; directory at the top level of the repository.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
arch                        Architecture-specific files&lt;br /&gt;
  common                      Pool of useful files. Very few files here are common to all archs.&lt;br /&gt;
    CMSIS                       Collection of ARM &amp;amp; vendor headers following the CMSIS standard&lt;br /&gt;
    core                        Board independent drivers required for the OS to function (roughly)&lt;br /&gt;
      atomic_ops_*.h              Core dependent&lt;br /&gt;
      cache_*.cpp/h               Core dependent. This is not required at all for Miosix to work but is nevertheless here&lt;br /&gt;
      *_os_timer.cpp              Chip family dependent&lt;br /&gt;
      endianness_*.h              Core dependent. Should have a generic (slow) implementation but it&#039;s missing.&lt;br /&gt;
      interrupts.h                Umbrella header for interrupts_*.h&lt;br /&gt;
      interrupts_*.h              Core dependent. Misleading name, this is for fault handling.&lt;br /&gt;
      memory_protection.h         Umbrella header for mpu_*.h. Required only for process mode. Name is not consistent with other umbrella headers, should have been &amp;quot;mpu.h&amp;quot;&lt;br /&gt;
      mpu_*.cpp/h                 Core dependent.&lt;br /&gt;
    drivers                     Miscellaneous drivers, which are &amp;quot;common&amp;quot; only very roughly&lt;br /&gt;
      dcc.cpp/h                   Core dependent (but common to all ARM cores apparently)&lt;br /&gt;
      *_adc.cpp/h                 Chip family dependent&lt;br /&gt;
      serial.h                    Umbrella header for *serial*.h&lt;br /&gt;
      *serial*.cpp/h              Chip family dependent&lt;br /&gt;
      sd_*.cpp/h                  Chip family dependent&lt;br /&gt;
      servo_*.cpp/h               Board dependent really, should go into utils&lt;br /&gt;
      *_hardware_rng.cpp/h        Chip family dependent&lt;br /&gt;
      *_rtc.cpp/h                 Chip family dependent&lt;br /&gt;
      *_sgm.cpp/h                 Chip family dependent&lt;br /&gt;
      *_wd.cpp/h                  Chip family dependent&lt;br /&gt;
      *_i2c.cpp/h                 Chip family dependent&lt;br /&gt;
  &amp;lt;board group name&amp;gt;          Board group specific files.&lt;br /&gt;
    common                      Common drivers and configuration for all the boards in the group&lt;br /&gt;
      arch_settings.h             Core dependent. Misleading name, defines requirements for ctxsave&lt;br /&gt;
      interfaces-impl             The actual drivers, most of them required by Miosix to function.&lt;br /&gt;
        arch_registers_impl.h     Chip family dependent. Includes the appropriate register definitions&lt;br /&gt;
        delays.cpp                Chip family dependent as it also depends on ROM/Flash speed. Actually application dependent (!) as cache/prefetch mechanisms can be configured but whatever.&lt;br /&gt;
        gpio_impl.cpp/h           Chip family dependent.&lt;br /&gt;
        portability_impl.h        Core dependent.&lt;br /&gt;
        portability.cpp           Core dependent.&lt;br /&gt;
      drivers                 Miscellaneous drivers not required by Miosix to function, with exceptions (atsam4l clock)&lt;br /&gt;
        *.cpp/h&lt;br /&gt;
    &amp;lt;board name&amp;gt;              Board/chip specific files.&lt;br /&gt;
      core                      Board/chip dependent code required for the OS to function.&lt;br /&gt;
        stage_1_boot.c/cpp/s      Chip dependent. Interrupt vector table, reset handler, clock tree setup, bss/data initialization&lt;br /&gt;
      interfaces_impl         Important board/chip specific drivers, most of them required by Miosix to function.&lt;br /&gt;
        bsp_impl.h              Board dependent. Useful board-specific definitions.&lt;br /&gt;
        bsp.cpp                 Board dependent. Useful board-specific functions.&lt;br /&gt;
        hwmapping.h             Board dependent. GPIO pin definitions.&lt;br /&gt;
        deep_sleep.cpp          Chip family dependent. Optional implementation of deep sleep primitives.&lt;br /&gt;
        delays.cpp              See above. Sometimes it&#039;s here, with no true reason why.&lt;br /&gt;
        arch_registers_impl.h     See above. Sometimes it&#039;s here, depends on chip.&lt;br /&gt;
        ...                     Some boards have extra miscellaneous drivers here&lt;br /&gt;
      *.h                     Some boards have chip registers definitions here (LPC2138)&lt;br /&gt;
      *.cfg                   Some boards have OpenOCD config files here&lt;br /&gt;
      *.ld                    Chip family specific. Linker files for different RAM/Flash configurations&lt;br /&gt;
interfaces                  Headers for hardware interfaces TO miosix (internals) and SOME interfaces OF miosix to the application (APIs). Only commonality is that they are all hardware dependent (while stuff in utils/kernel is &#039;&#039;generally&#039;&#039; hardware independent)&lt;br /&gt;
  arch_registers.h            API. Umbrella for &amp;quot;arch_registers_impl.h&amp;quot;, selected through include search path manipulation.&lt;br /&gt;
  atomic_ops.h                API. Umbrella for &amp;quot;atomic_ops_*.h&amp;quot;, selected through ifdefs.&lt;br /&gt;
  bsp.h                       API + internal prototypes (IRQbspInit, bspInit2). Umbrella for &amp;quot;bsp_impl.h&amp;quot;, selected through include search path manipulation.&lt;br /&gt;
  deep_sleep.h                Internal prototypes only. Not an umbrella header.&lt;br /&gt;
  delays.h                    API. Not an umbrella header.&lt;br /&gt;
  endianness.h                API. Umbrella for &amp;quot;endianness_*.h&amp;quot;, selected through ifdefs.&lt;br /&gt;
  gpio.h                      API. Umbrella for &amp;quot;gpio_impl.h&amp;quot;, selected through include search path manipulation.&lt;br /&gt;
  os_timer.h                  Internal declarations. Not an umbrella header.&lt;br /&gt;
  portability.h               Internal declarations. Primitives for context switching and syscalls. Umbrella for &amp;quot;portability_impl.h&amp;quot;, selected through include search path manipulation.&lt;br /&gt;
util                        Additional APIs made available for applications as utilities, built on top of kernel primitives or other drivers&lt;br /&gt;
  lcd44780.cpp/h              Driver for Hitachi-standard HD44780 character displays.&lt;br /&gt;
  software_i2c/spi.h          Bit-banged i2c/spi implementations. Arguably drivers.&lt;br /&gt;
  utils.cpp/h                 Memory/CPU usage profiling. Misleading name. Not a driver&lt;br /&gt;
  ...                         Other files are not related to hardware&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&amp;lt;board group name&amp;gt;&#039;&#039; is defined as the name of the chip core, followed by an underscore, followed by the name of a chip family. &#039;&#039;&amp;lt;board name&amp;gt;&#039;&#039; is defined by the name of the chip, followed by an underscore, followed by a &amp;quot;common name&amp;quot; of the board. For commercial prototyping boards or specific devices, &amp;quot;common name&amp;quot; is derived from the name given by the manufacturer, or a name which is in common use with some exceptions (i.e. stm32f103 bluepill boards are named &amp;quot;breakout&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
Some general patterns can be inferred:&lt;br /&gt;
* Apart from minor exceptions, directories named &#039;&#039;&#039;core&#039;&#039;&#039; contain drivers required for the OS to function.&lt;br /&gt;
* Directories named &#039;&#039;&#039;interfaces_impl&#039;&#039;&#039; generally contain implementations of things defined in /interfaces. Header files in &#039;&#039;&#039;interfaces_impl&#039;&#039;&#039; are always given the ``_impl`` suffix. C++ files are usually not given the &amp;quot;_impl&amp;quot; suffix but sometimes they have it (gpio_impl.cpp).&lt;br /&gt;
* Directories named &#039;&#039;&#039;common&#039;&#039;&#039; contain code shared by multiple boards. No attempt is made to separate different levels of commonality apart from chip-family specific stuff which is grouped by board group.&lt;br /&gt;
&lt;br /&gt;
=== Issues ===&lt;br /&gt;
&lt;br /&gt;
Experience has shown this organization has the following problems:&lt;br /&gt;
* What goes where is not well defined due to the vagueness of directory names&lt;br /&gt;
** This leads to files being in the wrong place even though it&#039;s not obvious&lt;br /&gt;
*** servo_* is the most glaring example&lt;br /&gt;
*** The location of delays.cpp and arch_registers_impl.h is also inconsistent&lt;br /&gt;
* The two level board group/board classification does not reflect reality, which leads to missing code sharing opportunities:&lt;br /&gt;
** GPIO implementations are duplicated multiple times as they are common to multiple chip families and not to a single one.&lt;br /&gt;
** Bootstrap code is duplicated multiple times as they are common to boards with the same chip and not common to the board.&lt;br /&gt;
** Portability code (i.e. context save/restore primitives mostly) is duplicated multiple times as they are common to a given core and not to a chip family&lt;br /&gt;
* Classifications sometimes privilege syntax rather than semantics, in an inconsistent fashion&lt;br /&gt;
** Directories named &#039;&#039;&#039;interfaces_impl&#039;&#039;&#039; contain drivers just like directories named &#039;&#039;&#039;drivers&#039;&#039;&#039;, except that they included from /interfaces.&lt;br /&gt;
** What is &#039;&#039;&#039;common&#039;&#039;&#039; and what is not loosely determined by the amount of code sharing but most stuff not under a &#039;&#039;&#039;common&#039;&#039;&#039; directory is duplicated at least twice&lt;br /&gt;
&lt;br /&gt;
Of course, the root issue is the fluidity of the distinction between chip and chip family, and how each vendor manages and/or defines each family. For instance, STM32 chips all have similar USART (serial) implementations, but at least two versions can be distinguished through different register definitions and feature sets. Therefore the same overall driver can be shared across almost all STM32 chips, however the driver is littered with &#039;&#039;ifdef&#039;&#039;s to single out the specificity of each implementation. There is really no strict distinction to what can be found where, as the vendors can and do mix and match peripherals even amongst themselves. For example, some STM32 chips have Synopsis-designed USB interfaces which can also be found on chips from vendors that are not ST.&lt;br /&gt;
 &lt;br /&gt;
These considerations highlight that the solution to handling the issue of organizing platform-specific code in a consistent way to &#039;&#039;&#039;minimize code duplication&#039;&#039;&#039; is not to &#039;&#039;&#039;add&#039;&#039;&#039; hierarchy levels, but to remove them. This runs contrary from the naive consideration that &amp;quot;Board includes Chip, which belongs to Chip Family, which contains a Core&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
== A proposal ==&lt;br /&gt;
&lt;br /&gt;
Pointing out what&#039;s wrong is easy, fixing it up is hard. Of course &amp;quot;what we should do&amp;quot; is a matter of opinion, and a valid answer to that could even be &amp;quot;nothing&amp;quot;. If I were to do something, I would do the following:&lt;br /&gt;
&lt;br /&gt;
=== With classification per device type ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
platform&lt;br /&gt;
  arch_registers.h&lt;br /&gt;
  atomic_ops.h&lt;br /&gt;
  bsp.h&lt;br /&gt;
  deep_sleep.h&lt;br /&gt;
  delays.h&lt;br /&gt;
  endianness.h&lt;br /&gt;
  gpio.h&lt;br /&gt;
  os_timer.h&lt;br /&gt;
  portability.h&lt;br /&gt;
  memory_protection.h&lt;br /&gt;
  interrupts.h&lt;br /&gt;
  mpu.h&lt;br /&gt;
  serial.h&lt;br /&gt;
  arch_registers&lt;br /&gt;
    CMSIS&lt;br /&gt;
    &amp;lt;chip/chip family&amp;gt;&lt;br /&gt;
      arch_registers_impl.h&lt;br /&gt;
      ....h&lt;br /&gt;
  core&lt;br /&gt;
    boot&lt;br /&gt;
      &amp;lt;chip&amp;gt;&lt;br /&gt;
        stage_1_boot.c/cpp/s&lt;br /&gt;
    atomic_ops&lt;br /&gt;
      atomic_ops_*.h&lt;br /&gt;
    os_timer&lt;br /&gt;
      *_os_timer.cpp&lt;br /&gt;
    endianness&lt;br /&gt;
      endianness_*.h&lt;br /&gt;
    faults&lt;br /&gt;
      interrupts_*.h&lt;br /&gt;
    mpu&lt;br /&gt;
      *_mpu.cpp/h&lt;br /&gt;
    portability&lt;br /&gt;
      &amp;lt;core&amp;gt;&lt;br /&gt;
        arch_settings.h&lt;br /&gt;
        portability_impl.h&lt;br /&gt;
        portability.cpp&lt;br /&gt;
    gpio&lt;br /&gt;
      &amp;lt;chip/chip family&amp;gt;&lt;br /&gt;
        gpio_impl.cpp/h&lt;br /&gt;
    delays&lt;br /&gt;
      &amp;lt;chip/chip family&amp;gt;&lt;br /&gt;
        delays.cpp&lt;br /&gt;
  drivers&lt;br /&gt;
    arm_dcc.cpp/h&lt;br /&gt;
    deep_sleep&lt;br /&gt;
      deep_sleep.cpp&lt;br /&gt;
    cache&lt;br /&gt;
      cache_*.cpp/h&lt;br /&gt;
    serial&lt;br /&gt;
      *_serial.cpp/h&lt;br /&gt;
    adc&lt;br /&gt;
      *_adc.cpp/h&lt;br /&gt;
    sd&lt;br /&gt;
      *_sd.cpp/h&lt;br /&gt;
    servo&lt;br /&gt;
      *_servo.cpp/h&lt;br /&gt;
    hardware_rng&lt;br /&gt;
      *_hardware_rng.cpp/h&lt;br /&gt;
    rtc&lt;br /&gt;
      *_rtc.cpp/h&lt;br /&gt;
    sgm&lt;br /&gt;
      *_sgm.cpp/h&lt;br /&gt;
    wd&lt;br /&gt;
      *_wd.cpp/h&lt;br /&gt;
    i2c&lt;br /&gt;
      *_i2c.cpp/h&lt;br /&gt;
      software_i2c.h&lt;br /&gt;
    spi&lt;br /&gt;
      software_spi.h&lt;br /&gt;
    display&lt;br /&gt;
      lcd44780.cpp/h&lt;br /&gt;
    ...&lt;br /&gt;
  board&lt;br /&gt;
    &amp;lt;board&amp;gt;&lt;br /&gt;
      bsp_impl.h&lt;br /&gt;
      bsp.cpp&lt;br /&gt;
      hwmapping.h&lt;br /&gt;
      *.cfg&lt;br /&gt;
  linker_scripts&lt;br /&gt;
    &amp;lt;chip&amp;gt;&lt;br /&gt;
      *.ld&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Without classification per device type ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
platform&lt;br /&gt;
  arch_registers.h&lt;br /&gt;
  atomic_ops.h&lt;br /&gt;
  bsp.h&lt;br /&gt;
  deep_sleep.h&lt;br /&gt;
  delays.h&lt;br /&gt;
  endianness.h&lt;br /&gt;
  gpio.h&lt;br /&gt;
  os_timer.h&lt;br /&gt;
  portability.h&lt;br /&gt;
  memory_protection.h&lt;br /&gt;
  interrupts.h&lt;br /&gt;
  mpu.h&lt;br /&gt;
  serial.h&lt;br /&gt;
  arch_registers&lt;br /&gt;
    CMSIS&lt;br /&gt;
    &amp;lt;chip/chip family&amp;gt;&lt;br /&gt;
      arch_registers_impl.h&lt;br /&gt;
      ....h&lt;br /&gt;
  core&lt;br /&gt;
    &amp;lt;chip/chip family&amp;gt;&lt;br /&gt;
      stage_1_boot.c/cpp/s&lt;br /&gt;
      *_os_timer.cpp&lt;br /&gt;
      *_mpu.cpp/h&lt;br /&gt;
      gpio_impl.cpp/h&lt;br /&gt;
      delays.cpp&lt;br /&gt;
    &amp;lt;core&amp;gt;&lt;br /&gt;
      atomic_ops_*.h&lt;br /&gt;
      endianness_*.h&lt;br /&gt;
      interrupts_*.h&lt;br /&gt;
      arch_settings.h&lt;br /&gt;
      portability_impl.h&lt;br /&gt;
      portability.cpp&lt;br /&gt;
  drivers&lt;br /&gt;
    dcc.cpp/h&lt;br /&gt;
    *_servo.cpp/h&lt;br /&gt;
    software_i2c.h&lt;br /&gt;
    software_spi.h&lt;br /&gt;
    lcd44780.cpp/h&lt;br /&gt;
    &amp;lt;core&amp;gt;&lt;br /&gt;
      cache_*.cpp/h&lt;br /&gt;
    &amp;lt;chip/chip family&amp;gt;&lt;br /&gt;
      deep_sleep.cpp&lt;br /&gt;
      *_serial.cpp/h&lt;br /&gt;
      *_adc.cpp/h&lt;br /&gt;
      *_sd.cpp/h&lt;br /&gt;
      *_hardware_rng.cpp/h&lt;br /&gt;
      *_rtc.cpp/h&lt;br /&gt;
      *_sgm.cpp/h&lt;br /&gt;
      *_wd.cpp/h&lt;br /&gt;
      *_i2c.cpp/h&lt;br /&gt;
    ...&lt;br /&gt;
  board&lt;br /&gt;
    &amp;lt;board&amp;gt;&lt;br /&gt;
      bsp_impl.h&lt;br /&gt;
      bsp.cpp&lt;br /&gt;
      hwmapping.h&lt;br /&gt;
      *.cfg&lt;br /&gt;
  linker_scripts&lt;br /&gt;
    &amp;lt;chip&amp;gt;&lt;br /&gt;
      *.ld&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Daniele.cattaneo</name></author>
	</entry>
	<entry>
		<id>https://miosix.org/wiki/index.php?title=Arch_directory_restructuring&amp;diff=331</id>
		<title>Arch directory restructuring</title>
		<link rel="alternate" type="text/html" href="https://miosix.org/wiki/index.php?title=Arch_directory_restructuring&amp;diff=331"/>
		<updated>2023-11-13T14:47:44Z</updated>

		<summary type="html">&lt;p&gt;Daniele.cattaneo: More&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The &#039;&#039;arch&#039;&#039; directory is a mess with lots of copy-pasted code. Ideally it should be &#039;&#039;&#039;consistently and logically organized&#039;&#039;&#039;: each directory should have a documented purpose in order to leave as little doubt as possible about &#039;&#039;what goes where&#039;&#039;. Additionally, each directory&#039;s purpose makes sense in the overall structure, without overlaps between the scope of each directory.&lt;br /&gt;
At the moment however we observe this is not the case. We believe that in order to make the future growth of Miosix simpler and faster, the right moment to rectify the situation is now.&lt;br /&gt;
&lt;br /&gt;
== Some definitions ==&lt;br /&gt;
&lt;br /&gt;
Common sense suggests the following taxonomy of parts for MCU-equipped devices targeted by Miosix:&lt;br /&gt;
* Board: The device itself being targeted. It&#039;s called a board because nobody has observed any MCU wired with point-to-point wiring yet. Includes the MCU itself plus any peripheral external to the MCU but &#039;&#039;&#039;driven&#039;&#039;&#039; by it.&lt;br /&gt;
* Chip: The MCU itself. May come in RAM/OTP/ROM/Flash size variations, which are mostly ignored.&lt;br /&gt;
* Chip family: A set of MCU types from the same manufacturer with the same microprocessor core but potentially different set of peripherals. While the available set of peripherals may vary, the behaviour and I/O ports of each kind of peripheral are the same across the entire family. Thanks to the brilliant ideas of the various marketing departments of each vendor, the classification here can get very fluid.&lt;br /&gt;
* Core: The microprocessor core used by a given chip family.&lt;br /&gt;
&lt;br /&gt;
Let&#039;s take as an example the classic stm32f4discovery board that is the most common development device for Miosix:&lt;br /&gt;
* The board is the stm32f4discovery itself. It includes the chip, and miscellaneous peripherals such as an accelerometer and a Cirrus Logic audio chip. The STLink programming interface and the power supply are &#039;&#039;&#039;not&#039;&#039;&#039; considered relevant parts of the board for Miosix, as the MCU is not in control of what they do.&lt;br /&gt;
* The chip is an STM32F407VGT6. The VGT6 suffix of the chip name specifies package (100 pin LQFP), Flash size (1MB) and temperature range options (see the datasheet at the &amp;quot;Ordering Information&amp;quot; page).&lt;br /&gt;
* The chip family is STM32F4. This can be inferred by the fact that all available chips with this prefix in the part name share the same reference manual.&lt;br /&gt;
* The core is an ARM Cortex M4, as stated in the datasheet. Roughly, ST buys the Verilog for the core from ARM and then takes care of the manufacturing. As far as we know, ARM&#039;s licence shouldn&#039;t allow ST to customize the core in any way, so all Cortex M4 cores should behave the same, even from other vendors.&lt;br /&gt;
&lt;br /&gt;
=== What is an architecture? ===&lt;br /&gt;
&lt;br /&gt;
One definition we did not give is the definition of what an &#039;&#039;&#039;architecture&#039;&#039;&#039; is. The reason is that there is no accepted definition for this term, especially for forum pundits and bloggers, but also in academia. The RISC school of thought (Patterson/Hennessy and their spawn) historically associated an &#039;&#039;architecture&#039;&#039; with a combination of what are more specifically called the &#039;&#039;instruction set architecture&#039;&#039; (ISA) and the &#039;&#039;microarchitecture&#039;&#039; of a core. The ISA is the overall structure and design of the instructions, as opposed to the &#039;&#039;instruction set&#039;&#039; proper which is the set of instructions accepted by a specific core. The &#039;&#039;&#039;microarchitecture&#039;&#039;&#039; is the overall internal design of the core itself.&lt;br /&gt;
&lt;br /&gt;
Their thesis was that the microarchitecture design will follow naturally from the definition of the ISA, hence simpler ISAs (RISC) to implement always lead to more efficient and generally better cores. Therefore one can consider the &#039;&#039;&#039;architecture&#039;&#039;&#039; to be primarily determined by the ISA. However the industry has proven them wrong, and the most glaring example are Intel x86 chips, which have seen an increasing variety of microarchitectures implementing the same ISA (variously extended of course) with wildly varying levels of (non-)efficiency (in all possible ramifications of &amp;quot;efficiency&amp;quot;). Closer to Miosix&#039;s targets, the ARM ISA has been extended so much over the years that its core RISC design has now evolved to basically a traditional CISC ISA, but ARM chips still come in every possible size and flavour.&lt;br /&gt;
&lt;br /&gt;
When we talk about x86 &amp;quot;architectures&amp;quot; or ARM &amp;quot;architectures&amp;quot;, but do we mean desktop-grade chips or microcontrollers? Even though they have the same &amp;quot;architecture&amp;quot; the cores in these two classes of chips have nothing to do with each other, they don&#039;t even share the same instruction decoder probably. Hence our conclusion that the word &amp;quot;architecture&amp;quot; has now lost all useful meaning for our purposes, and is only useful for void parlor chitchat.&lt;br /&gt;
&lt;br /&gt;
And then we come to Miosix which defines &amp;quot;architecture&amp;quot; (arch) as... a board. Which is not what anyone means when they talk about architecture of anything. For Miosix, an &amp;quot;architecture&amp;quot; is more like what in common parlance would be meant as a &amp;quot;platform&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
== Current structure ==&lt;br /&gt;
&lt;br /&gt;
Here&#039;s a schematic diagram of how the Miosix &#039;&#039;arch&#039;&#039; directory (plus related directories) is configured. In the following &#039;&#039;/&#039;&#039; refers to the &#039;&#039;miosix&#039;&#039; directory at the top level of the repository.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
arch                        Architecture-specific files&lt;br /&gt;
  common                      Pool of useful files. Very few files here are common to all archs.&lt;br /&gt;
    CMSIS                       Collection of ARM &amp;amp; vendor headers following the CMSIS standard&lt;br /&gt;
    core                        Board independent drivers required for the OS to function (roughly)&lt;br /&gt;
      atomic_ops_*.h              Core dependent&lt;br /&gt;
      cache_*.cpp/h               Core dependent. This is not required at all for Miosix to work but is nevertheless here&lt;br /&gt;
      *_os_timer.cpp              Chip family dependent&lt;br /&gt;
      endianness_*.h              Core dependent. Should have a generic (slow) implementation but it&#039;s missing.&lt;br /&gt;
      interrupts.h                Umbrella header for interrupts_*.h&lt;br /&gt;
      interrupts_*.h              Core dependent. Misleading name, this is for fault handling.&lt;br /&gt;
      memory_protection.h         Umbrella header for mpu_*.h. Required only for process mode. Name is not consistent with other umbrella headers, should have been &amp;quot;mpu.h&amp;quot;&lt;br /&gt;
      mpu_*.cpp/h                 Core dependent.&lt;br /&gt;
    drivers                     Miscellaneous drivers, which are &amp;quot;common&amp;quot; only very roughly&lt;br /&gt;
      dcc.cpp/h                   Core dependent (but common to all ARM cores apparently)&lt;br /&gt;
      *_adc.cpp/h                 Chip family dependent&lt;br /&gt;
      serial.h                    Umbrella header for *serial*.h&lt;br /&gt;
      *serial*.cpp/h              Chip family dependent&lt;br /&gt;
      sd_*.cpp/h                  Chip family dependent&lt;br /&gt;
      servo_*.cpp/h               Board dependent really, should go into utils&lt;br /&gt;
      *_hardware_rng.cpp/h        Chip family dependent&lt;br /&gt;
      *_rtc.cpp/h                 Chip family dependent&lt;br /&gt;
      *_sgm.cpp/h                 Chip family dependent&lt;br /&gt;
      *_wd.cpp/h                  Chip family dependent&lt;br /&gt;
      *_i2c.cpp/h                 Chip family dependent&lt;br /&gt;
  &amp;lt;board group name&amp;gt;          Board group specific files.&lt;br /&gt;
    common                      Common drivers and configuration for all the boards in the group&lt;br /&gt;
      arch_settings.h             Core dependent. Misleading name, defines requirements for ctxsave&lt;br /&gt;
      interfaces-impl             The actual drivers, most of them required by Miosix to function.&lt;br /&gt;
        arch_registers_impl.h     Chip family dependent. Includes the appropriate register definitions&lt;br /&gt;
        delays.cpp                Chip family dependent as it also depends on ROM/Flash speed. Actually application dependent (!) as cache/prefetch mechanisms can be configured but whatever.&lt;br /&gt;
        gpio_impl.cpp/h           Chip family dependent.&lt;br /&gt;
        portability_impl.h        Core dependent.&lt;br /&gt;
        portability.cpp           Core dependent.&lt;br /&gt;
      drivers                 Miscellaneous drivers not required by Miosix to function, with exceptions (atsam4l clock)&lt;br /&gt;
        *.cpp/h&lt;br /&gt;
    &amp;lt;board name&amp;gt;              Board/chip specific files.&lt;br /&gt;
      core                      Board/chip dependent code required for the OS to function.&lt;br /&gt;
        stage_1_boot.c/cpp/s      Chip dependent. Interrupt vector table, reset handler, clock tree setup, bss/data initialization&lt;br /&gt;
      interfaces_impl         Important board/chip specific drivers, most of them required by Miosix to function.&lt;br /&gt;
        bsp_impl.h              Board dependent. Useful board-specific definitions.&lt;br /&gt;
        bsp.cpp                 Board dependent. Useful board-specific functions.&lt;br /&gt;
        hwmapping.h             Board dependent. GPIO pin definitions.&lt;br /&gt;
        deep_sleep.cpp          Chip family dependent. Optional implementation of deep sleep primitives.&lt;br /&gt;
        delays.cpp              See above. Sometimes it&#039;s here, with no true reason why.&lt;br /&gt;
        arch_registers_impl.h     See above. Sometimes it&#039;s here, depends on chip.&lt;br /&gt;
        ...                     Some boards have extra miscellaneous drivers here&lt;br /&gt;
      *.h                     Some boards have chip registers definitions here (LPC2138)&lt;br /&gt;
      *.cfg                   Some boards have OpenOCD config files here&lt;br /&gt;
      *.ld                    Chip family specific. Linker files for different RAM/Flash configurations&lt;br /&gt;
interfaces                  Headers for hardware interfaces TO miosix (internals) and SOME interfaces OF miosix to the application (APIs). Only commonality is that they are all hardware dependent (while stuff in utils/kernel is &#039;&#039;generally&#039;&#039; hardware independent)&lt;br /&gt;
  arch_registers.h            API. Umbrella for &amp;quot;arch_registers_impl.h&amp;quot;, selected through include search path manipulation.&lt;br /&gt;
  atomic_ops.h                API. Umbrella for &amp;quot;atomic_ops_*.h&amp;quot;, selected through ifdefs.&lt;br /&gt;
  bsp.h                       API + internal prototypes (IRQbspInit, bspInit2). Umbrella for &amp;quot;bsp_impl.h&amp;quot;, selected through include search path manipulation.&lt;br /&gt;
  deep_sleep.h                Internal prototypes only. Not an umbrella header.&lt;br /&gt;
  delays.h                    API. Not an umbrella header.&lt;br /&gt;
  endianness.h                API. Umbrella for &amp;quot;endianness_*.h&amp;quot;, selected through ifdefs.&lt;br /&gt;
  gpio.h                      API. Umbrella for &amp;quot;gpio_impl.h&amp;quot;, selected through include search path manipulation.&lt;br /&gt;
  os_timer.h                  Internal declarations. Not an umbrella header.&lt;br /&gt;
  portability.h               Internal declarations. Primitives for context switching and syscalls. Umbrella for &amp;quot;portability_impl.h&amp;quot;, selected through include search path manipulation.&lt;br /&gt;
util                        Additional APIs made available for applications as utilities, built on top of kernel primitives or other drivers&lt;br /&gt;
  lcd44780.cpp/h              Driver for Hitachi-standard HD44780 character displays.&lt;br /&gt;
  software_i2c/spi.h          Bit-banged i2c/spi implementations. Arguably drivers.&lt;br /&gt;
  utils.cpp/h                 Memory/CPU usage profiling. Misleading name. Not a driver&lt;br /&gt;
  ...                         Other files are not related to hardware&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&amp;lt;board group name&amp;gt;&#039;&#039; is defined as the name of the chip core, followed by an underscore, followed by the name of a chip family. &#039;&#039;&amp;lt;board name&amp;gt;&#039;&#039; is defined by the name of the chip, followed by an underscore, followed by a &amp;quot;common name&amp;quot; of the board. For commercial prototyping boards or specific devices, &amp;quot;common name&amp;quot; is derived from the name given by the manufacturer, or a name which is in common use with some exceptions (i.e. stm32f103 bluepill boards are named &amp;quot;breakout&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
Some general patterns can be inferred:&lt;br /&gt;
* Apart from minor exceptions, directories named &#039;&#039;&#039;core&#039;&#039;&#039; contain drivers required for the OS to function.&lt;br /&gt;
* Directories named &#039;&#039;&#039;interfaces_impl&#039;&#039;&#039; generally contain implementations of things defined in /interfaces. Header files in &#039;&#039;&#039;interfaces_impl&#039;&#039;&#039; are always given the ``_impl`` suffix. C++ files are usually not given the &amp;quot;_impl&amp;quot; suffix but sometimes they have it (gpio_impl.cpp).&lt;br /&gt;
* Directories named &#039;&#039;&#039;common&#039;&#039;&#039; contain code shared by multiple boards. No attempt is made to separate different levels of commonality apart from chip-family specific stuff which is grouped by board group.&lt;br /&gt;
&lt;br /&gt;
=== Issues ===&lt;br /&gt;
&lt;br /&gt;
Experience has shown this organization has the following problems:&lt;br /&gt;
* What goes where is not well defined due to the vagueness of directory names&lt;br /&gt;
** This leads to files being in the wrong place even though it&#039;s not obvious&lt;br /&gt;
*** servo_* is the most glaring example&lt;br /&gt;
*** The location of delays.cpp and arch_registers_impl.h is also inconsistent&lt;br /&gt;
* The two level board group/board classification does not reflect reality, which leads to missing code sharing opportunities:&lt;br /&gt;
** GPIO implementations are duplicated multiple times as they are common to multiple chip families and not to a single one.&lt;br /&gt;
** Bootstrap code is duplicated multiple times as they are common to boards with the same chip and not common to the board.&lt;br /&gt;
** Portability code (i.e. context save/restore primitives mostly) is duplicated multiple times as they are common to a given core and not to a chip family&lt;br /&gt;
* Classifications sometimes privilege syntax rather than semantics, in an inconsistent fashion&lt;br /&gt;
** Directories named &#039;&#039;&#039;interfaces_impl&#039;&#039;&#039; contain drivers just like directories named &#039;&#039;&#039;drivers&#039;&#039;&#039;, except that they included from /interfaces.&lt;br /&gt;
** What is &#039;&#039;&#039;common&#039;&#039;&#039; and what is not loosely determined by the amount of code sharing but most stuff not under a &#039;&#039;&#039;common&#039;&#039;&#039; directory is duplicated at least twice&lt;br /&gt;
&lt;br /&gt;
Of course, the root issue is the fluidity of the distinction between chip and chip family, and how each vendor manages and/or defines each family. For instance, STM32 chips all have similar USART (serial) implementations, but at least two versions can be distinguished through different register definitions and feature sets. Therefore the same overall driver can be shared across almost all STM32 chips, however the driver is littered with &#039;&#039;ifdef&#039;&#039;s to single out the specificity of each implementation. There is really no strict distinction to what can be found where, as the vendors can and do mix and match peripherals even amongst themselves. For example, some STM32 chips have Synopsis-designed USB interfaces which can also be found on chips from vendors that are not ST.&lt;br /&gt;
 &lt;br /&gt;
These considerations highlight that the solution to handling the issue of organizing platform-specific code in a consistent way to &#039;&#039;&#039;minimize code duplication&#039;&#039;&#039; is not to &#039;&#039;&#039;add&#039;&#039;&#039; hierarchy levels, but to remove them. This runs contrary from the naive consideration that &amp;quot;Board includes Chip, which belongs to Chip Family, which contains a Core&amp;quot;.&lt;/div&gt;</summary>
		<author><name>Daniele.cattaneo</name></author>
	</entry>
	<entry>
		<id>https://miosix.org/wiki/index.php?title=Arch_directory_restructuring&amp;diff=330</id>
		<title>Arch directory restructuring</title>
		<link rel="alternate" type="text/html" href="https://miosix.org/wiki/index.php?title=Arch_directory_restructuring&amp;diff=330"/>
		<updated>2023-11-13T13:24:04Z</updated>

		<summary type="html">&lt;p&gt;Daniele.cattaneo: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The &#039;&#039;arch&#039;&#039; directory is a mess with lots of copy-pasted code. Let&#039;s fix that!&lt;br /&gt;
&lt;br /&gt;
== Some definitions ==&lt;br /&gt;
&lt;br /&gt;
Common sense suggests the following taxonomy of parts for MCU-equipped devices targeted by Miosix:&lt;br /&gt;
* Board: The device itself being targeted. It&#039;s called a board because nobody has observed any MCU wired with point-to-point wiring yet. Includes the MCU itself plus any peripheral external to the MCU but &#039;&#039;&#039;driven&#039;&#039;&#039; by it.&lt;br /&gt;
* Chip: The MCU itself. May come in RAM/OTP/ROM/Flash size variations, which are mostly ignored.&lt;br /&gt;
* Chip family: A set of MCU types from the same manufacturer with the same microprocessor core but potentially different set of peripherals. While the available set of peripherals may vary, the behaviour and I/O ports of each kind of peripheral are the same across the entire family. Thanks to the brilliant ideas of the various marketing departments of each vendor, the classification here can get very fluid.&lt;br /&gt;
* Core: The microprocessor core used by a given chip family.&lt;br /&gt;
&lt;br /&gt;
Let&#039;s take as an example the classic stm32f4discovery board that is the most common development device for Miosix:&lt;br /&gt;
* The board is the stm32f4discovery itself. It includes the chip, and miscellaneous peripherals such as an accelerometer and a Cirrus Logic audio chip. The STLink programming interface and the power supply are &#039;&#039;&#039;not&#039;&#039;&#039; considered relevant parts of the board for Miosix, as the MCU is not in control of what they do.&lt;br /&gt;
* The chip is an STM32F407VGT6. The VGT6 suffix of the chip name specifies package (100 pin LQFP), Flash size (1MB) and temperature range options (see the datasheet at the &amp;quot;Ordering Information&amp;quot; page).&lt;br /&gt;
* The chip family is STM32F4. This can be inferred by the fact that all available chips with this prefix in the part name share the same reference manual.&lt;br /&gt;
* The core is an ARM Cortex M4, as stated in the datasheet. Roughly, ST buys the Verilog for the core from ARM and then takes care of the manufacturing. As far as we know, ARM&#039;s licence shouldn&#039;t allow ST to customize the core in any way, so all Cortex M4 cores should behave the same, even from other vendors.&lt;br /&gt;
&lt;br /&gt;
One definition we did not give is the definition of what an &#039;&#039;&#039;architecture&#039;&#039;&#039; is. The reason is that there is no accepted definition for this term, especially for forum pundits and bloggers, but also in academia. The RISC school of thought (Patterson/Hennessy and their spawn) historically associated an &#039;&#039;architecture&#039;&#039; with a combination of what are more specifically called the &#039;&#039;instruction set architecture&#039;&#039; (ISA) and the &#039;&#039;microarchitecture&#039;&#039; of a core. Their thesis was that the microarchitecture design will follow naturally from the definition of the ISA, hence simpler ISAs (RISC) to implement always lead to more efficient and generally better cores. However the industry has proven them wrong, and the most glaring example are Intel x86 chips, which have seen an increasing variety of microarchitectures implementing the same ISA (variously extended of course) with wildly varying levels of (non-)efficiency (in all possible ramifications of &amp;quot;efficiency&amp;quot;). Closer to Miosix&#039;s targets, the ARM ISA has been extended so much over the years that its core RISC design has now evolved to basically a traditional CISC ISA, but ARM chips still come in every possible size and flavour. Usually we talk about x86 &amp;quot;architectures&amp;quot; or ARM &amp;quot;architectures&amp;quot;, but do we mean desktop-grade chips or microcontrollers? Even though they have the same &amp;quot;architecture&amp;quot; the cores in these two classes of chips have nothing to do with each other, they don&#039;t even share the same instruction decoder probably. Hence our conclusion that the word &amp;quot;architecture&amp;quot; has now lost all useful meaning for our purposes, and is only useful for void parlor chitchat.&lt;br /&gt;
&lt;br /&gt;
And then we come to Miosix which defines &amp;quot;architecture&amp;quot; (arch) as... a board. Which is not what anyone means when they talk about architecture of anything. For Miosix, an &amp;quot;architecture&amp;quot; is more like what in common parlance would be meant as a &amp;quot;platform&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
== Current structure ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
arch                        &lt;br /&gt;
  common                      Pool of useful files. Very few files here are common to all archs.&lt;br /&gt;
    CMSIS                       Collection of ARM &amp;amp; vendor headers following the CMSIS standard&lt;br /&gt;
    core                        Board independent drivers required for the OS to function (roughly)&lt;br /&gt;
      atomic_ops_*.h              Core dependent&lt;br /&gt;
      cache_*.cpp/h               Core dependent. This is not required at all for Miosix to work but is nevertheless here&lt;br /&gt;
      *_os_timer.cpp              Chip family dependent&lt;br /&gt;
      endianness_*.h              Core dependent. Should have a generic (slow) implementation but it&#039;s missing.&lt;br /&gt;
      interrupts.h                Umbrella header for interrupts_*.h&lt;br /&gt;
      interrupts_*.h              Core dependent. Misleading name, this is for fault handling.&lt;br /&gt;
      memory_protection.h         Umbrella header for mpu_*.h. Required only for process mode. Name is not consistent with other umbrella headers, should have been &amp;quot;mpu.h&amp;quot;&lt;br /&gt;
      mpu_*.cpp/h                 Core dependent.&lt;br /&gt;
    drivers                     Miscellaneous drivers, which are &amp;quot;common&amp;quot; only very roughly&lt;br /&gt;
      dcc.cpp/h                   Core dependent (but common to all ARM cores apparently)&lt;br /&gt;
      *_adc.cpp/h                 Chip family dependent&lt;br /&gt;
      serial.h                    Umbrella header for *serial*.h&lt;br /&gt;
      *serial*.cpp/h              Chip family dependent&lt;br /&gt;
      sd_*.cpp/h                  Chip family dependent&lt;br /&gt;
      servo_*.cpp/h               Board dependent really, should go into utils&lt;br /&gt;
      *_hardware_rng.cpp/h        Chip family dependent&lt;br /&gt;
      *_rtc.cpp/h                 Chip family dependent&lt;br /&gt;
      *_sgm.cpp/h                 Chip family dependent&lt;br /&gt;
      *_wd.cpp/h                  Chip family dependent&lt;br /&gt;
      *_i2c.cpp/h                 Chip family dependent&lt;br /&gt;
  &amp;lt;board group name&amp;gt;          Board specific files.Board names are decided based on chip family but also include the core in their name&lt;br /&gt;
    common                      Common drivers and configuration for all the boards in the group&lt;br /&gt;
      arch_settings.h             Core dependent. Misleading name, defines requirements for ctxsave&lt;br /&gt;
      interfaces-impl             The actual drivers&lt;br /&gt;
        arch_registers_impl.h     Chip family dependent. Includes the appropriate register definitions&lt;br /&gt;
        delays.cpp                Chip family dependent as it also depends on ROM/Flash speed. Actually application dependent (!) as cache/prefetch mechanisms can be configured but whatever.&lt;br /&gt;
        gpio_impl.cpp/h           Chip family dependent.&lt;br /&gt;
        portability_impl.h        Core dependent.&lt;br /&gt;
        portability.cpp           Core dependent.&lt;br /&gt;
    &amp;lt;board name&amp;gt;              Board/chip specific files.&lt;br /&gt;
      core                      Board/chip dependent code required for the OS to function.&lt;br /&gt;
        stage_1_boot.c/cpp/s      Chip dependent. Interrupt vector table, reset handler, clock tree setup, bss/data initialization&lt;br /&gt;
      interfaces_impl         Board/chip specific drivers.&lt;br /&gt;
        bsp_impl.h              Board dependent. Useful board-specific definitions.&lt;br /&gt;
        bsp.cpp                 Board dependent. Useful board-specific functions.&lt;br /&gt;
        hwmapping.h             Board dependent. GPIO pin definitions.&lt;br /&gt;
        delays.cpp              See above. Sometimes it&#039;s here, with no true reason why.&lt;br /&gt;
        arch_registers_impl.h     See above. Sometimes it&#039;s here, depends on chip.&lt;br /&gt;
        ...                     Some boards have extra miscellaneous drivers here&lt;br /&gt;
interfaces                 &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&amp;lt;board group name&amp;gt;&#039;&#039; is defined as the name of the chip core, followed by an underscore, followed by the name of a chip family. &#039;&#039;&amp;lt;board name&amp;gt;&#039;&#039; is defined by the name of the chip, followed by an underscore, followed by a &amp;quot;common name&amp;quot; of the board. For commercial prototyping boards or specific devices, &amp;quot;common name&amp;quot; is derived from the name given by the manufacturer, or a name which is in common use with some exceptions (i.e. stm32f103 bluepill boards are named &amp;quot;breakout&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
Some general patterns can be inferred:&lt;br /&gt;
* Apart from minor exceptions, directories named &#039;&#039;&#039;core&#039;&#039;&#039; contain drivers required for the OS to function.&lt;br /&gt;
* Directories named &#039;&#039;&#039;interfaces_impl&#039;&#039;&#039; generally contain implementations of things defined in /interfaces. Header files in &#039;&#039;&#039;interfaces_impl&#039;&#039;&#039; are always given the ``_impl`` suffix. C++ files are usually not given the &amp;quot;_impl&amp;quot; suffix but sometimes they have it (gpio_impl.cpp).&lt;br /&gt;
* Directories named &#039;&#039;&#039;common&#039;&#039;&#039; contain code shared by multiple boards. No attempt is made to separate different levels of commonality apart from chip-family specific stuff which is grouped by board group.&lt;br /&gt;
&lt;br /&gt;
=== Issues ===&lt;br /&gt;
&lt;br /&gt;
Experience has shown this organization has the following problems:&lt;br /&gt;
* What goes where is not well defined due to the vagueness of directory names, which leads to files being in the wrong place even though it&#039;s not obvious&lt;br /&gt;
** servo_* is the most glaring example&lt;br /&gt;
** The location of delays.cpp and arch_registers_impl.h is also inconsistent&lt;br /&gt;
* The two level board group/board classification does not reflect reality, which leads to missing code sharing opportunities:&lt;br /&gt;
** GPIO implementations are duplicated multiple times as they are common to multiple chip families and not to a single one.&lt;br /&gt;
** Bootstrap code is duplicated multiple times as they are common to boards with the same chip and not common to the board.&lt;br /&gt;
** Portability code (i.e. context save/restore primitives mostly) is duplicated multiple times as they are common to a given core and not to a chip family&lt;/div&gt;</summary>
		<author><name>Daniele.cattaneo</name></author>
	</entry>
	<entry>
		<id>https://miosix.org/wiki/index.php?title=Arch_directory_restructuring&amp;diff=329</id>
		<title>Arch directory restructuring</title>
		<link rel="alternate" type="text/html" href="https://miosix.org/wiki/index.php?title=Arch_directory_restructuring&amp;diff=329"/>
		<updated>2023-11-13T13:17:39Z</updated>

		<summary type="html">&lt;p&gt;Daniele.cattaneo: Fix lists once again&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The &#039;&#039;arch&#039;&#039; directory is a mess with lots of copy-pasted code. Let&#039;s fix that!&lt;br /&gt;
&lt;br /&gt;
== Some definitions ==&lt;br /&gt;
&lt;br /&gt;
Common sense suggests the following taxonomy of parts for MCU-equipped devices targeted by Miosix:&lt;br /&gt;
* Board: The device itself being targeted. It&#039;s called a board because nobody has observed any MCU wired with point-to-point wiring yet. Includes the MCU itself plus any peripheral external to the MCU but &#039;&#039;&#039;driven&#039;&#039;&#039; by it.&lt;br /&gt;
* Chip: The MCU itself. May come in RAM/OTP/ROM/Flash size variations, which are mostly ignored.&lt;br /&gt;
* Chip family: A set of MCU types from the same manufacturer with the same microprocessor core but potentially different set of peripherals. While the available set of peripherals may vary, the behaviour and I/O ports of each kind of peripheral are the same across the entire family. Thanks to the brilliant ideas of the various marketing departments of each vendor, the classification here can get very fluid.&lt;br /&gt;
* Core: The microprocessor core used by a given chip family.&lt;br /&gt;
&lt;br /&gt;
Let&#039;s take as an example the classic stm32f4discovery board that is the most common development device for Miosix:&lt;br /&gt;
* The board is the stm32f4discovery itself. It includes the chip, and miscellaneous peripherals such as an accelerometer and a Cirrus Logic audio chip. The STLink programming interface and the power supply are &#039;&#039;&#039;not&#039;&#039;&#039; considered relevant parts of the board for Miosix, as the MCU is not in control of what they do.&lt;br /&gt;
* The chip is an STM32F407VGT6. The VGT6 suffix of the chip name specifies package (100 pin LQFP), Flash size (1MB) and temperature range options (see the datasheet at the &amp;quot;Ordering Information&amp;quot; page).&lt;br /&gt;
* The chip family is STM32F4. This can be inferred by the fact that all available chips with this prefix in the part name share the same reference manual.&lt;br /&gt;
* The core is an ARM Cortex M4, as stated in the datasheet. Roughly, ST buys the Verilog for the core from ARM and then takes care of the manufacturing. As far as we know, ARM&#039;s licence shouldn&#039;t allow ST to customize the core in any way, so all Cortex M4 cores should behave the same, even from other vendors.&lt;br /&gt;
&lt;br /&gt;
One definition we did not give is the definition of what an &#039;&#039;&#039;architecture&#039;&#039;&#039; is. The reason is that there is no accepted definition for this term, especially for forum pundits and bloggers, but also in academia. The RISC school of thought (Patterson/Hennessy and their spawn) historically associated an &#039;&#039;architecture&#039;&#039; with a combination of what are more specifically called the &#039;&#039;instruction set architecture&#039;&#039; (ISA) and the &#039;&#039;microarchitecture&#039;&#039; of a core. Their thesis was that the microarchitecture design will follow naturally from the definition of the ISA, hence simpler ISAs (RISC) to implement always lead to more efficient and generally better cores. However the industry has proven them wrong, and the most glaring example are Intel x86 chips, which have seen an increasing variety of microarchitectures implementing the same ISA (variously extended of course) with wildly varying levels of (non-)efficiency (in all possible ramifications of &amp;quot;efficiency&amp;quot;). Closer to Miosix&#039;s targets, the ARM ISA has been extended so much over the years that its core RISC design has now evolved to basically a traditional CISC ISA, but ARM chips still come in every possible size and flavour. Usually we talk about x86 &amp;quot;architectures&amp;quot; or ARM &amp;quot;architectures&amp;quot;, but do we mean desktop-grade chips or microcontrollers? Even though they have the same &amp;quot;architecture&amp;quot; the cores in these two classes of chips have nothing to do with each other, they don&#039;t even share the same instruction decoder probably. Hence our conclusion that the word &amp;quot;architecture&amp;quot; has now lost all useful meaning for our purposes, and is only useful for void parlor chitchat.&lt;br /&gt;
&lt;br /&gt;
And then we come to Miosix which defines &amp;quot;architecture&amp;quot; (arch) as... a board. Which is not what anyone means when they talk about architecture of anything. For Miosix, an &amp;quot;architecture&amp;quot; is more like what in common parlance would be meant as a &amp;quot;platform&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
== Current structure ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
arch                        &lt;br /&gt;
  common                      Pool of useful files. Very few files here are common to all archs.&lt;br /&gt;
    CMSIS                       Collection of ARM &amp;amp; vendor headers following the CMSIS standard&lt;br /&gt;
    core                        Board independent drivers required for the OS to function (roughly)&lt;br /&gt;
      atomic_ops_*.h              Core dependent&lt;br /&gt;
      cache_*.cpp/h               Core dependent. This is not required for Miosix but is nevertheless here&lt;br /&gt;
      *_os_timer.cpp              Chip family dependent&lt;br /&gt;
      endianness_*.h              Core dependent. Should have a generic (slow) implementation.&lt;br /&gt;
      interrupts.h                Umbrella header for interrupts_*.h&lt;br /&gt;
      interrupts_*.h              Core dependent. Misleading name, this is for fault handling.&lt;br /&gt;
      memory_protection.h         Umbrella header for mpu_*.h. Required only for process mode.&lt;br /&gt;
      mpu_*.cpp/h                 Core dependent.&lt;br /&gt;
    drivers                     Miscellaneous drivers, which are &amp;quot;common&amp;quot; only very roughly&lt;br /&gt;
      dcc.cpp/h                   Core dependent (but common to all ARM cores apparently)&lt;br /&gt;
      *_adc.cpp/h                 Chip family dependent&lt;br /&gt;
      serial.h                    Umbrella header for *serial*.h&lt;br /&gt;
      *serial*.cpp/h              Chip family dependent&lt;br /&gt;
      sd_*.cpp/h                  Chip family dependent&lt;br /&gt;
      servo_*.cpp/h               Board dependent really, should go into utils&lt;br /&gt;
      *_hardware_rng.cpp/h        Chip family dependent&lt;br /&gt;
      *_rtc.cpp/h                 Chip family dependent&lt;br /&gt;
      *_sgm.cpp/h                 Chip family dependent&lt;br /&gt;
      *_wd.cpp/h                  Chip family dependent&lt;br /&gt;
      *_i2c.cpp/h                 Chip family dependent&lt;br /&gt;
  &amp;lt;board group name&amp;gt;          Board specific files.Board names are decided based on chip family but also include the core in their name&lt;br /&gt;
    common                      Common drivers and configuration for all the boards in the group&lt;br /&gt;
      arch_settings.h             Core dependent. Misleading name, defines requirements for ctxsave&lt;br /&gt;
      interfaces-impl             The actual drivers&lt;br /&gt;
        arch_registers_impl.h     Chip family dependent. Includes the appropriate register definitions&lt;br /&gt;
        delays.cpp                Chip family dependent as it also depends on ROM/Flash speed. Actually application dependent (!) as cache/prefetch mechanisms can be configured but whatever.&lt;br /&gt;
        gpio_impl.cpp/h           Chip family dependent.&lt;br /&gt;
        portability_impl.h        Core dependent.&lt;br /&gt;
        portability.cpp           Core dependent.&lt;br /&gt;
    &amp;lt;board name&amp;gt;              Board/chip specific files.&lt;br /&gt;
      core                      Board/chip dependent code required for the OS to function.&lt;br /&gt;
        stage_1_boot.c/cpp/s      Chip dependent. Interrupt vector table, reset handler, clock tree setup, bss/data initialization&lt;br /&gt;
      interfaces_impl         Board/chip specific drivers.&lt;br /&gt;
        bsp_impl.h              Board dependent. Useful board-specific definitions.&lt;br /&gt;
        bsp.cpp                 Board dependent. Useful board-specific functions.&lt;br /&gt;
        hwmapping.h             Board dependent. GPIO pin definitions.&lt;br /&gt;
        delays.cpp              See above. Sometimes it&#039;s here, with no true reason why.&lt;br /&gt;
        arch_registers_impl.h     See above. Sometimes it&#039;s here, depends on chip.&lt;br /&gt;
        ...                     Some boards have extra miscellaneous drivers here&lt;br /&gt;
interfaces                 &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&amp;lt;board group name&amp;gt;&#039;&#039; is defined as the name of the chip core, followed by an underscore, followed by the name of a chip family. &#039;&#039;&amp;lt;board name&amp;gt;&#039;&#039; is defined by the name of the chip, followed by an underscore, followed by a &amp;quot;common name&amp;quot; of the board. For commercial prototyping boards or specific devices, &amp;quot;common name&amp;quot; is derived from the name given by the manufacturer, or a name which is in common use with some exceptions (i.e. stm32f103 bluepill boards are named &amp;quot;breakout&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
Some general patterns can be inferred:&lt;br /&gt;
* Apart from minor exceptions, directories named &#039;&#039;&#039;core&#039;&#039;&#039; contain drivers required for the OS to function.&lt;br /&gt;
* Directories named &#039;&#039;&#039;interfaces_impl&#039;&#039;&#039; generally contain implementations of things defined in /interfaces. Header files in &#039;&#039;&#039;interfaces_impl&#039;&#039;&#039; are always given the ``_impl`` suffix. C++ files are usually not given the &amp;quot;_impl&amp;quot; suffix but sometimes they have it (gpio_impl.cpp).&lt;br /&gt;
* Directories named &#039;&#039;&#039;common&#039;&#039;&#039; contain code shared by multiple boards. No attempt is made to separate different levels of commonality apart from chip-family specific stuff which is grouped by board group.&lt;br /&gt;
&lt;br /&gt;
=== Issues ===&lt;br /&gt;
&lt;br /&gt;
Experience has shown this organization has the following problems:&lt;br /&gt;
* What goes where is not well defined due to the vagueness of directory names, which leads to files being in the wrong place even though it&#039;s not obvious&lt;br /&gt;
** servo_* is the most glaring example&lt;br /&gt;
** The location of delays.cpp and arch_registers_impl.h is also inconsistent&lt;br /&gt;
* The two level board group/board classification does not reflect reality, which leads to missing code sharing opportunities:&lt;br /&gt;
** GPIO implementations are duplicated multiple times as they are common to multiple chip families and not to a single one.&lt;br /&gt;
** Bootstrap code is duplicated multiple times as they are common to boards with the same chip and not common to the board.&lt;br /&gt;
** Portability code (i.e. context save/restore primitives mostly) is duplicated multiple times as they are common to a given core and not to a chip family&lt;/div&gt;</summary>
		<author><name>Daniele.cattaneo</name></author>
	</entry>
	<entry>
		<id>https://miosix.org/wiki/index.php?title=Arch_directory_restructuring&amp;diff=328</id>
		<title>Arch directory restructuring</title>
		<link rel="alternate" type="text/html" href="https://miosix.org/wiki/index.php?title=Arch_directory_restructuring&amp;diff=328"/>
		<updated>2023-11-13T13:16:47Z</updated>

		<summary type="html">&lt;p&gt;Daniele.cattaneo: Fix lists&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The &#039;&#039;arch&#039;&#039; directory is a mess with lots of copy-pasted code. Let&#039;s fix that!&lt;br /&gt;
&lt;br /&gt;
== Some definitions ==&lt;br /&gt;
&lt;br /&gt;
Common sense suggests the following taxonomy of parts for MCU-equipped devices targeted by Miosix:&lt;br /&gt;
* Board: The device itself being targeted. It&#039;s called a board because nobody has observed any MCU wired with point-to-point wiring yet. Includes the MCU itself plus any peripheral external to the MCU but &#039;&#039;&#039;driven&#039;&#039;&#039; by it.&lt;br /&gt;
* Chip: The MCU itself. May come in RAM/OTP/ROM/Flash size variations, which are mostly ignored.&lt;br /&gt;
* Chip family: A set of MCU types from the same manufacturer with the same microprocessor core but potentially different set of peripherals. While the available set of peripherals may vary, the behaviour and I/O ports of each kind of peripheral are the same across the entire family. Thanks to the brilliant ideas of the various marketing departments of each vendor, the classification here can get very fluid.&lt;br /&gt;
* Core: The microprocessor core used by a given chip family.&lt;br /&gt;
&lt;br /&gt;
Let&#039;s take as an example the classic stm32f4discovery board that is the most common development device for Miosix:&lt;br /&gt;
* The board is the stm32f4discovery itself. It includes the chip, and miscellaneous peripherals such as an accelerometer and a Cirrus Logic audio chip. The STLink programming interface and the power supply are &#039;&#039;&#039;not&#039;&#039;&#039; considered relevant parts of the board for Miosix, as the MCU is not in control of what they do.&lt;br /&gt;
* The chip is an STM32F407VGT6. The VGT6 suffix of the chip name specifies package (100 pin LQFP), Flash size (1MB) and temperature range options (see the datasheet at the &amp;quot;Ordering Information&amp;quot; page).&lt;br /&gt;
* The chip family is STM32F4. This can be inferred by the fact that all available chips with this prefix in the part name share the same reference manual.&lt;br /&gt;
* The core is an ARM Cortex M4, as stated in the datasheet. Roughly, ST buys the Verilog for the core from ARM and then takes care of the manufacturing. As far as we know, ARM&#039;s licence shouldn&#039;t allow ST to customize the core in any way, so all Cortex M4 cores should behave the same, even from other vendors.&lt;br /&gt;
&lt;br /&gt;
One definition we did not give is the definition of what an &#039;&#039;&#039;architecture&#039;&#039;&#039; is. The reason is that there is no accepted definition for this term, especially for forum pundits and bloggers, but also in academia. The RISC school of thought (Patterson/Hennessy and their spawn) historically associated an &#039;&#039;architecture&#039;&#039; with a combination of what are more specifically called the &#039;&#039;instruction set architecture&#039;&#039; (ISA) and the &#039;&#039;microarchitecture&#039;&#039; of a core. Their thesis was that the microarchitecture design will follow naturally from the definition of the ISA, hence simpler ISAs (RISC) to implement always lead to more efficient and generally better cores. However the industry has proven them wrong, and the most glaring example are Intel x86 chips, which have seen an increasing variety of microarchitectures implementing the same ISA (variously extended of course) with wildly varying levels of (non-)efficiency (in all possible ramifications of &amp;quot;efficiency&amp;quot;). Closer to Miosix&#039;s targets, the ARM ISA has been extended so much over the years that its core RISC design has now evolved to basically a traditional CISC ISA, but ARM chips still come in every possible size and flavour. Usually we talk about x86 &amp;quot;architectures&amp;quot; or ARM &amp;quot;architectures&amp;quot;, but do we mean desktop-grade chips or microcontrollers? Even though they have the same &amp;quot;architecture&amp;quot; the cores in these two classes of chips have nothing to do with each other, they don&#039;t even share the same instruction decoder probably. Hence our conclusion that the word &amp;quot;architecture&amp;quot; has now lost all useful meaning for our purposes, and is only useful for void parlor chitchat.&lt;br /&gt;
&lt;br /&gt;
And then we come to Miosix which defines &amp;quot;architecture&amp;quot; (arch) as... a board. Which is not what anyone means when they talk about architecture of anything. For Miosix, an &amp;quot;architecture&amp;quot; is more like what in common parlance would be meant as a &amp;quot;platform&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
== Current structure ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
arch                        &lt;br /&gt;
  common                      Pool of useful files. Very few files here are common to all archs.&lt;br /&gt;
    CMSIS                       Collection of ARM &amp;amp; vendor headers following the CMSIS standard&lt;br /&gt;
    core                        Board independent drivers required for the OS to function (roughly)&lt;br /&gt;
      atomic_ops_*.h              Core dependent&lt;br /&gt;
      cache_*.cpp/h               Core dependent. This is not required for Miosix but is nevertheless here&lt;br /&gt;
      *_os_timer.cpp              Chip family dependent&lt;br /&gt;
      endianness_*.h              Core dependent. Should have a generic (slow) implementation.&lt;br /&gt;
      interrupts.h                Umbrella header for interrupts_*.h&lt;br /&gt;
      interrupts_*.h              Core dependent. Misleading name, this is for fault handling.&lt;br /&gt;
      memory_protection.h         Umbrella header for mpu_*.h. Required only for process mode.&lt;br /&gt;
      mpu_*.cpp/h                 Core dependent.&lt;br /&gt;
    drivers                     Miscellaneous drivers, which are &amp;quot;common&amp;quot; only very roughly&lt;br /&gt;
      dcc.cpp/h                   Core dependent (but common to all ARM cores apparently)&lt;br /&gt;
      *_adc.cpp/h                 Chip family dependent&lt;br /&gt;
      serial.h                    Umbrella header for *serial*.h&lt;br /&gt;
      *serial*.cpp/h              Chip family dependent&lt;br /&gt;
      sd_*.cpp/h                  Chip family dependent&lt;br /&gt;
      servo_*.cpp/h               Board dependent really, should go into utils&lt;br /&gt;
      *_hardware_rng.cpp/h        Chip family dependent&lt;br /&gt;
      *_rtc.cpp/h                 Chip family dependent&lt;br /&gt;
      *_sgm.cpp/h                 Chip family dependent&lt;br /&gt;
      *_wd.cpp/h                  Chip family dependent&lt;br /&gt;
      *_i2c.cpp/h                 Chip family dependent&lt;br /&gt;
  &amp;lt;board group name&amp;gt;          Board specific files.Board names are decided based on chip family but also include the core in their name&lt;br /&gt;
    common                      Common drivers and configuration for all the boards in the group&lt;br /&gt;
      arch_settings.h             Core dependent. Misleading name, defines requirements for ctxsave&lt;br /&gt;
      interfaces-impl             The actual drivers&lt;br /&gt;
        arch_registers_impl.h     Chip family dependent. Includes the appropriate register definitions&lt;br /&gt;
        delays.cpp                Chip family dependent as it also depends on ROM/Flash speed. Actually application dependent (!) as cache/prefetch mechanisms can be configured but whatever.&lt;br /&gt;
        gpio_impl.cpp/h           Chip family dependent.&lt;br /&gt;
        portability_impl.h        Core dependent.&lt;br /&gt;
        portability.cpp           Core dependent.&lt;br /&gt;
    &amp;lt;board name&amp;gt;              Board/chip specific files.&lt;br /&gt;
      core                      Board/chip dependent code required for the OS to function.&lt;br /&gt;
        stage_1_boot.c/cpp/s      Chip dependent. Interrupt vector table, reset handler, clock tree setup, bss/data initialization&lt;br /&gt;
      interfaces_impl         Board/chip specific drivers.&lt;br /&gt;
        bsp_impl.h              Board dependent. Useful board-specific definitions.&lt;br /&gt;
        bsp.cpp                 Board dependent. Useful board-specific functions.&lt;br /&gt;
        hwmapping.h             Board dependent. GPIO pin definitions.&lt;br /&gt;
        delays.cpp              See above. Sometimes it&#039;s here, with no true reason why.&lt;br /&gt;
        arch_registers_impl.h     See above. Sometimes it&#039;s here, depends on chip.&lt;br /&gt;
        ...                     Some boards have extra miscellaneous drivers here&lt;br /&gt;
interfaces                 &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&amp;lt;board group name&amp;gt;&#039;&#039; is defined as the name of the chip core, followed by an underscore, followed by the name of a chip family. &#039;&#039;&amp;lt;board name&amp;gt;&#039;&#039; is defined by the name of the chip, followed by an underscore, followed by a &amp;quot;common name&amp;quot; of the board. For commercial prototyping boards or specific devices, &amp;quot;common name&amp;quot; is derived from the name given by the manufacturer, or a name which is in common use with some exceptions (i.e. stm32f103 bluepill boards are named &amp;quot;breakout&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
Some general patterns can be inferred:&lt;br /&gt;
* Apart from minor exceptions, directories named &#039;&#039;&#039;core&#039;&#039;&#039; contain drivers required for the OS to function.&lt;br /&gt;
* Directories named &#039;&#039;&#039;interfaces_impl&#039;&#039;&#039; generally contain implementations of things defined in /interfaces. Header files in &#039;&#039;&#039;interfaces_impl&#039;&#039;&#039; are always given the ``_impl`` suffix. C++ files are usually not given the &amp;quot;_impl&amp;quot; suffix but sometimes they have it (gpio_impl.cpp).&lt;br /&gt;
* Directories named &#039;&#039;&#039;common&#039;&#039;&#039; contain code shared by multiple boards. No attempt is made to separate different levels of commonality apart from chip-family specific stuff which is grouped by board group.&lt;br /&gt;
&lt;br /&gt;
=== Issues ===&lt;br /&gt;
&lt;br /&gt;
Experience has shown this organization has the following problems:&lt;br /&gt;
* What goes where is not well defined due to the vagueness of directory names, which leads to files being in the wrong place even though it&#039;s not obvious&lt;br /&gt;
  * servo_* is the most glaring example&lt;br /&gt;
  * The location of delays.cpp and arch_registers_impl.h is also inconsistent&lt;br /&gt;
* The two level board group/board classification does not reflect reality, which leads to missing code sharing opportunities:&lt;br /&gt;
  * GPIO implementations are duplicated multiple times as they are common to multiple chip families and not to a single one.&lt;br /&gt;
  * Bootstrap code is duplicated multiple times as they are common to boards with the same chip and not common to the board.&lt;br /&gt;
  * Portability code (i.e. context save/restore primitives mostly) is duplicated multiple times as they are common to a given core and not to a chip family&lt;/div&gt;</summary>
		<author><name>Daniele.cattaneo</name></author>
	</entry>
	<entry>
		<id>https://miosix.org/wiki/index.php?title=Arch_directory_restructuring&amp;diff=327</id>
		<title>Arch directory restructuring</title>
		<link rel="alternate" type="text/html" href="https://miosix.org/wiki/index.php?title=Arch_directory_restructuring&amp;diff=327"/>
		<updated>2023-11-13T13:16:08Z</updated>

		<summary type="html">&lt;p&gt;Daniele.cattaneo: Start writing&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The &#039;&#039;arch&#039;&#039; directory is a mess with lots of copy-pasted code. Let&#039;s fix that!&lt;br /&gt;
&lt;br /&gt;
== Some definitions ==&lt;br /&gt;
&lt;br /&gt;
Common sense suggests the following taxonomy of parts for MCU-equipped devices targeted by Miosix:&lt;br /&gt;
 * Board: The device itself being targeted. It&#039;s called a board because nobody has observed any MCU wired with point-to-point wiring yet. Includes the MCU itself plus any peripheral external to the MCU but &#039;&#039;&#039;driven&#039;&#039;&#039; by it.&lt;br /&gt;
 * Chip: The MCU itself. May come in RAM/OTP/ROM/Flash size variations, which are mostly ignored.&lt;br /&gt;
 * Chip family: A set of MCU types from the same manufacturer with the same microprocessor core but potentially different set of peripherals. While the available set of peripherals may vary, the behaviour and I/O ports of each kind of peripheral are the same across the entire family. Thanks to the brilliant ideas of the various marketing departments of each vendor, the classification here can get very fluid.&lt;br /&gt;
 * Core: The microprocessor core used by a given chip family.&lt;br /&gt;
&lt;br /&gt;
Let&#039;s take as an example the classic stm32f4discovery board that is the most common development device for Miosix:&lt;br /&gt;
 * The board is the stm32f4discovery itself. It includes the chip, and miscellaneous peripherals such as an accelerometer and a Cirrus Logic audio chip. The STLink programming interface and the power supply are &#039;&#039;&#039;not&#039;&#039;&#039; considered relevant parts of the board for Miosix, as the MCU is not in control of what they do.&lt;br /&gt;
 * The chip is an STM32F407VGT6. The VGT6 suffix of the chip name specifies package (100 pin LQFP), Flash size (1MB) and temperature range options (see the datasheet at the &amp;quot;Ordering Information&amp;quot; page).&lt;br /&gt;
 * The chip family is STM32F4. This can be inferred by the fact that all available chips with this prefix in the part name share the same reference manual.&lt;br /&gt;
 * The core is an ARM Cortex M4, as stated in the datasheet. Roughly, ST buys the Verilog for the core from ARM and then takes care of the manufacturing. As far as we know, ARM&#039;s licence shouldn&#039;t allow ST to customize the core in any way, so all Cortex M4 cores should behave the same, even from other vendors.&lt;br /&gt;
&lt;br /&gt;
One definition we did not give is the definition of what an &#039;&#039;&#039;architecture&#039;&#039;&#039; is. The reason is that there is no accepted definition for this term, especially for forum pundits and bloggers, but also in academia. The RISC school of thought (Patterson/Hennessy and their spawn) historically associated an &#039;&#039;architecture&#039;&#039; with a combination of what are more specifically called the &#039;&#039;instruction set architecture&#039;&#039; (ISA) and the &#039;&#039;microarchitecture&#039;&#039; of a core. Their thesis was that the microarchitecture design will follow naturally from the definition of the ISA, hence simpler ISAs (RISC) to implement always lead to more efficient and generally better cores. However the industry has proven them wrong, and the most glaring example are Intel x86 chips, which have seen an increasing variety of microarchitectures implementing the same ISA (variously extended of course) with wildly varying levels of (non-)efficiency (in all possible ramifications of &amp;quot;efficiency&amp;quot;). Closer to Miosix&#039;s targets, the ARM ISA has been extended so much over the years that its core RISC design has now evolved to basically a traditional CISC ISA, but ARM chips still come in every possible size and flavour. Usually we talk about x86 &amp;quot;architectures&amp;quot; or ARM &amp;quot;architectures&amp;quot;, but do we mean desktop-grade chips or microcontrollers? Even though they have the same &amp;quot;architecture&amp;quot; the cores in these two classes of chips have nothing to do with each other, they don&#039;t even share the same instruction decoder probably. Hence our conclusion that the word &amp;quot;architecture&amp;quot; has now lost all useful meaning for our purposes, and is only useful for void parlor chitchat.&lt;br /&gt;
&lt;br /&gt;
And then we come to Miosix which defines &amp;quot;architecture&amp;quot; (arch) as... a board. Which is not what anyone means when they talk about architecture of anything. For Miosix, an &amp;quot;architecture&amp;quot; is more like what in common parlance would be meant as a &amp;quot;platform&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
== Current structure ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
arch                        &lt;br /&gt;
  common                      Pool of useful files. Very few files here are common to all archs.&lt;br /&gt;
    CMSIS                       Collection of ARM &amp;amp; vendor headers following the CMSIS standard&lt;br /&gt;
    core                        Board independent drivers required for the OS to function (roughly)&lt;br /&gt;
      atomic_ops_*.h              Core dependent&lt;br /&gt;
      cache_*.cpp/h               Core dependent. This is not required for Miosix but is nevertheless here&lt;br /&gt;
      *_os_timer.cpp              Chip family dependent&lt;br /&gt;
      endianness_*.h              Core dependent. Should have a generic (slow) implementation.&lt;br /&gt;
      interrupts.h                Umbrella header for interrupts_*.h&lt;br /&gt;
      interrupts_*.h              Core dependent. Misleading name, this is for fault handling.&lt;br /&gt;
      memory_protection.h         Umbrella header for mpu_*.h. Required only for process mode.&lt;br /&gt;
      mpu_*.cpp/h                 Core dependent.&lt;br /&gt;
    drivers                     Miscellaneous drivers, which are &amp;quot;common&amp;quot; only very roughly&lt;br /&gt;
      dcc.cpp/h                   Core dependent (but common to all ARM cores apparently)&lt;br /&gt;
      *_adc.cpp/h                 Chip family dependent&lt;br /&gt;
      serial.h                    Umbrella header for *serial*.h&lt;br /&gt;
      *serial*.cpp/h              Chip family dependent&lt;br /&gt;
      sd_*.cpp/h                  Chip family dependent&lt;br /&gt;
      servo_*.cpp/h               Board dependent really, should go into utils&lt;br /&gt;
      *_hardware_rng.cpp/h        Chip family dependent&lt;br /&gt;
      *_rtc.cpp/h                 Chip family dependent&lt;br /&gt;
      *_sgm.cpp/h                 Chip family dependent&lt;br /&gt;
      *_wd.cpp/h                  Chip family dependent&lt;br /&gt;
      *_i2c.cpp/h                 Chip family dependent&lt;br /&gt;
  &amp;lt;board group name&amp;gt;          Board specific files.Board names are decided based on chip family but also include the core in their name&lt;br /&gt;
    common                      Common drivers and configuration for all the boards in the group&lt;br /&gt;
      arch_settings.h             Core dependent. Misleading name, defines requirements for ctxsave&lt;br /&gt;
      interfaces-impl             The actual drivers&lt;br /&gt;
        arch_registers_impl.h     Chip family dependent. Includes the appropriate register definitions&lt;br /&gt;
        delays.cpp                Chip family dependent as it also depends on ROM/Flash speed. Actually application dependent (!) as cache/prefetch mechanisms can be configured but whatever.&lt;br /&gt;
        gpio_impl.cpp/h           Chip family dependent.&lt;br /&gt;
        portability_impl.h        Core dependent.&lt;br /&gt;
        portability.cpp           Core dependent.&lt;br /&gt;
    &amp;lt;board name&amp;gt;              Board/chip specific files.&lt;br /&gt;
      core                      Board/chip dependent code required for the OS to function.&lt;br /&gt;
        stage_1_boot.c/cpp/s      Chip dependent. Interrupt vector table, reset handler, clock tree setup, bss/data initialization&lt;br /&gt;
      interfaces_impl         Board/chip specific drivers.&lt;br /&gt;
        bsp_impl.h              Board dependent. Useful board-specific definitions.&lt;br /&gt;
        bsp.cpp                 Board dependent. Useful board-specific functions.&lt;br /&gt;
        hwmapping.h             Board dependent. GPIO pin definitions.&lt;br /&gt;
        delays.cpp              See above. Sometimes it&#039;s here, with no true reason why.&lt;br /&gt;
        arch_registers_impl.h     See above. Sometimes it&#039;s here, depends on chip.&lt;br /&gt;
        ...                     Some boards have extra miscellaneous drivers here&lt;br /&gt;
interfaces                 &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&amp;lt;board group name&amp;gt;&#039;&#039; is defined as the name of the chip core, followed by an underscore, followed by the name of a chip family. &#039;&#039;&amp;lt;board name&amp;gt;&#039;&#039; is defined by the name of the chip, followed by an underscore, followed by a &amp;quot;common name&amp;quot; of the board. For commercial prototyping boards or specific devices, &amp;quot;common name&amp;quot; is derived from the name given by the manufacturer, or a name which is in common use with some exceptions (i.e. stm32f103 bluepill boards are named &amp;quot;breakout&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
Some general patterns can be inferred:&lt;br /&gt;
 * Apart from minor exceptions, directories named &#039;&#039;&#039;core&#039;&#039;&#039; contain drivers required for the OS to function.&lt;br /&gt;
 * Directories named &#039;&#039;&#039;interfaces_impl&#039;&#039;&#039; generally contain implementations of things defined in /interfaces. Header files in &#039;&#039;&#039;interfaces_impl&#039;&#039;&#039; are always given the ``_impl`` suffix. C++ files are usually not given the &amp;quot;_impl&amp;quot; suffix but sometimes they have it (gpio_impl.cpp).&lt;br /&gt;
 * Directories named &#039;&#039;&#039;common&#039;&#039;&#039; contain code shared by multiple boards. No attempt is made to separate different levels of commonality apart from chip-family specific stuff which is grouped by board group.&lt;br /&gt;
&lt;br /&gt;
=== Issues ===&lt;br /&gt;
&lt;br /&gt;
Experience has shown this organization has the following problems:&lt;br /&gt;
 * What goes where is not well defined due to the vagueness of directory names, which leads to files being in the wrong place even though it&#039;s not obvious&lt;br /&gt;
   * servo_* is the most glaring example&lt;br /&gt;
   * The location of delays.cpp and arch_registers_impl.h is also inconsistent&lt;br /&gt;
 * The two level board group/board classification does not reflect reality, which leads to missing code sharing opportunities:&lt;br /&gt;
   * GPIO implementations are duplicated multiple times as they are common to multiple chip families and not to a single one.&lt;br /&gt;
   * Bootstrap code is duplicated multiple times as they are common to boards with the same chip and not common to the board.&lt;br /&gt;
   * Portability code (i.e. context save/restore primitives mostly) is duplicated multiple times as they are common to a given core and not to a chip family&lt;/div&gt;</summary>
		<author><name>Daniele.cattaneo</name></author>
	</entry>
	<entry>
		<id>https://miosix.org/wiki/index.php?title=User:Daniele.cattaneo&amp;diff=326</id>
		<title>User:Daniele.cattaneo</title>
		<link rel="alternate" type="text/html" href="https://miosix.org/wiki/index.php?title=User:Daniele.cattaneo&amp;diff=326"/>
		<updated>2023-11-13T11:29:53Z</updated>

		<summary type="html">&lt;p&gt;Daniele.cattaneo: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Hi :)&lt;br /&gt;
&lt;br /&gt;
Github (work): [https://github.com/danielecattaneo]&lt;br /&gt;
&lt;br /&gt;
Github (personal): Secret&lt;br /&gt;
&lt;br /&gt;
[[Miosix in emulation]]&lt;br /&gt;
&lt;br /&gt;
[[arch directory restructuring]]&lt;/div&gt;</summary>
		<author><name>Daniele.cattaneo</name></author>
	</entry>
	<entry>
		<id>https://miosix.org/wiki/index.php?title=Linux_Debugger_configuration&amp;diff=321</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=321"/>
		<updated>2023-07-03T20:37:35Z</updated>

		<summary type="html">&lt;p&gt;Daniele.cattaneo: Bold markup rather than italic.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The debugging of Miosix on Linux can be done through [http://openocd.net/ 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-get 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 under the path &#039;miosix/arch&#039;. You must choose the proper config file for the device in use. 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/cortexM4_stm32f4/stm32f429zi_stm32f4discovery/stm32f4discovery.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]]. If you haven&#039;t already installed it&#039;s time to do it. The debugger must be launched on the ELF binary file.&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 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;
=== 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>Daniele.cattaneo</name></author>
	</entry>
	<entry>
		<id>https://miosix.org/wiki/index.php?title=Linux_Debugger_configuration&amp;diff=320</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=320"/>
		<updated>2023-07-03T20:37:08Z</updated>

		<summary type="html">&lt;p&gt;Daniele.cattaneo: Add troubleshooting info for the case in which breakpoints don&amp;#039;t work.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The debugging of Miosix on Linux can be done through [http://openocd.net/ 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-get 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 under the path &#039;miosix/arch&#039;. You must choose the proper config file for the device in use. 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/cortexM4_stm32f4/stm32f429zi_stm32f4discovery/stm32f4discovery.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;If breakpoints don&#039;t work on your board&#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]]. If you haven&#039;t already installed it&#039;s time to do it. The debugger must be launched on the ELF binary file.&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 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;
=== 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>Daniele.cattaneo</name></author>
	</entry>
	<entry>
		<id>https://miosix.org/wiki/index.php?title=MacOS_Quick_Start&amp;diff=319</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=319"/>
		<updated>2023-06-11T20:17:19Z</updated>

		<summary type="html">&lt;p&gt;Daniele.cattaneo: MacOS is now called macOS.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{DISPLAYTITLE:macOS Quick Start}}&lt;br /&gt;
This page explains how to install the precompiled Miosix Toolchain, which since January 2023 is also available for macOS. The building instructions previously found on this page have been updated and moved to [[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. 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 is recommended first.&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;
QSTLink2 is not supported on macOS.&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. 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. If you are using an Apple Silicon (ARM) Mac, the installer will automatically propose to install Rosetta for you in case it is not already installed.&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>Daniele.cattaneo</name></author>
	</entry>
</feed>