# myeongcheolko/kortos architecture

> Architecture diagram of the GitHub repository myeongcheolko/kortos, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-03). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/myeongcheolko/kortos
- Repository: https://github.com/myeongcheolko/kortos

## Overview

KoRTOS is a bare-metal Cortex-M4 RTOS paired with an STM32F446 register-level HAL. An application creates tasks and synchronization objects, starts the kernel, and the scheduler dispatches tasks using the Cortex-M port; tasks may use kernel queues, semaphores, and mutexes or access peripherals through HAL drivers. The README documents the kernel/port split and HAL capabilities; sampled source confirms scheduler/port and selected app-to-driver relationships. Other HAL-to-kernel wiring is not assumed.

Main entry points: [`kortos_hal/STM32F446xx/kortos_hal.h`](https://github.com/myeongcheolko/kortos/blob/main/kortos_hal/STM32F446xx/kortos_hal.h) (HAL include interface), [`kernel/kernel.c`](https://github.com/myeongcheolko/kortos/blob/main/kernel/kernel.c) (Scheduler and primitives), [`sample_apps/kernel/CAN_loopback_mutex_queue.c`](https://github.com/myeongcheolko/kortos/blob/main/sample_apps/kernel/CAN_loopback_mutex_queue.c) (Application tasks), [`port/arm/cortex_m4/port.c`](https://github.com/myeongcheolko/kortos/blob/main/port/arm/cortex_m4/port.c) (Context switching)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_kernel["Portable kernel"]
  node_api["Kernel API<br/>[kortos.h]"]
  node_core["Scheduler and primitives<br/>[kernel.c]"]
  node_config["Kernel configuration<br/>[kortos_config.h]"]
end

subgraph group_port["Cortex-M4 port"]
  node_portcode["Context switching<br/>[port.c]"]
  node_portapi["Port interface<br/>[port.h]"]
end

subgraph group_hal["STM32 peripheral HAL"]
  node_gpio["GPIO driver<br/>[GPIO.c]"]
  node_spi["SPI driver<br/>[SPI.c]"]
  node_i2c["I2C driver<br/>[I2C.c]"]
  node_usart["USART driver<br/>[USART.c]"]
  node_can["CAN driver<br/>[CAN.c]"]
  node_registers["Peripheral registers<br/>[STM32F446xx.h]"]
  node_rcc["Clock control<br/>[rcc.c]"]
  node_halapi["HAL include interface<br/>[kortos_hal.h]"]
end

subgraph group_boot["Board bring-up"]
  node_startup["Startup and vectors<br/>[startup.c]"]
  node_syscalls["System calls<br/>[syscalls.c]"]
  node_sysmem["Heap support<br/>[sysmem.c]"]
end

subgraph group_examples["Sample applications"]
  node_app["Application tasks"]
  node_haldemo["SPI exchange demo"]
end

node_developer(("Application developer"))

node_developer -->|"implements"| node_app
node_app -->|"calls"| node_api
node_api -->|"implemented by"| node_core
node_core -->|"yields to"| node_portcode
node_portcode -->|"ticks and schedules"| node_core
node_core -->|"uses settings"| node_config
node_app -->|"transmits frames"| node_can
node_app -->|"configures pins"| node_gpio
node_haldemo -->|"exchanges data"| node_spi
node_haldemo -->|"reads and toggles"| node_gpio
node_halapi -->|"includes"| node_gpio
node_halapi -->|"includes"| node_spi
node_halapi -->|"includes"| node_i2c
node_halapi -->|"includes"| node_usart
node_halapi -->|"includes"| node_can
node_startup -.->|"starts runtime"| node_core
node_portapi -->|"declares services"| node_portcode
node_registers -.->|"defines registers"| node_rcc

click node_app "https://github.com/myeongcheolko/kortos/blob/main/sample_apps/kernel/CAN_loopback_mutex_queue.c"
click node_api "https://github.com/myeongcheolko/kortos/blob/main/kernel/kortos.h"
click node_core "https://github.com/myeongcheolko/kortos/blob/main/kernel/kernel.c"
click node_config "https://github.com/myeongcheolko/kortos/blob/main/config/kortos_config.h"
click node_portcode "https://github.com/myeongcheolko/kortos/blob/main/port/arm/cortex_m4/port.c"
click node_portapi "https://github.com/myeongcheolko/kortos/blob/main/port/arm/cortex_m4/port.h"
click node_gpio "https://github.com/myeongcheolko/kortos/blob/main/kortos_hal/STM32F446xx/GPIO.c"
click node_spi "https://github.com/myeongcheolko/kortos/blob/main/kortos_hal/STM32F446xx/SPI.c"
click node_i2c "https://github.com/myeongcheolko/kortos/blob/main/kortos_hal/STM32F446xx/I2C.c"
click node_usart "https://github.com/myeongcheolko/kortos/blob/main/kortos_hal/STM32F446xx/USART.c"
click node_can "https://github.com/myeongcheolko/kortos/blob/main/kortos_hal/STM32F446xx/CAN.c"
click node_registers "https://github.com/myeongcheolko/kortos/blob/main/kortos_hal/STM32F446xx/STM32F446xx.h"
click node_rcc "https://github.com/myeongcheolko/kortos/blob/main/kortos_hal/STM32F446xx/rcc.c"
click node_halapi "https://github.com/myeongcheolko/kortos/blob/main/kortos_hal/STM32F446xx/kortos_hal.h"
click node_startup "https://github.com/myeongcheolko/kortos/blob/main/bsp/STM32F446xx/startup.c"
click node_syscalls "https://github.com/myeongcheolko/kortos/blob/main/bsp/STM32F446xx/syscalls.c"
click node_sysmem "https://github.com/myeongcheolko/kortos/blob/main/bsp/STM32F446xx/sysmem.c"
click node_haldemo "https://github.com/myeongcheolko/kortos/blob/main/sample_apps/hal/SPI_send_receive_arduino.c"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_api,node_core,node_config toneBlue
class node_portcode,node_portapi toneAmber
class node_gpio,node_spi,node_i2c,node_usart,node_can,node_registers,node_rcc,node_halapi toneMint
class node_startup,node_syscalls,node_sysmem toneRose
class node_app,node_haldemo,node_developer toneIndigo
```

## Components

### Portable kernel

- [Kernel API](https://github.com/myeongcheolko/kortos/blob/main/kernel/kortos.h): `kernel/kortos.h`
- [Scheduler and primitives](https://github.com/myeongcheolko/kortos/blob/main/kernel/kernel.c): `kernel/kernel.c`
- [Kernel configuration](https://github.com/myeongcheolko/kortos/blob/main/config/kortos_config.h): `config/kortos_config.h`

### Cortex-M4 port

- [Context switching](https://github.com/myeongcheolko/kortos/blob/main/port/arm/cortex_m4/port.c): `port/arm/cortex_m4/port.c`
- [Port interface](https://github.com/myeongcheolko/kortos/blob/main/port/arm/cortex_m4/port.h): `port/arm/cortex_m4/port.h`

### STM32 peripheral HAL

- [GPIO driver](https://github.com/myeongcheolko/kortos/blob/main/kortos_hal/STM32F446xx/GPIO.c): `kortos_hal/STM32F446xx/GPIO.c`
- [SPI driver](https://github.com/myeongcheolko/kortos/blob/main/kortos_hal/STM32F446xx/SPI.c): `kortos_hal/STM32F446xx/SPI.c`
- [I2C driver](https://github.com/myeongcheolko/kortos/blob/main/kortos_hal/STM32F446xx/I2C.c): `kortos_hal/STM32F446xx/I2C.c`
- [USART driver](https://github.com/myeongcheolko/kortos/blob/main/kortos_hal/STM32F446xx/USART.c): `kortos_hal/STM32F446xx/USART.c`
- [CAN driver](https://github.com/myeongcheolko/kortos/blob/main/kortos_hal/STM32F446xx/CAN.c): `kortos_hal/STM32F446xx/CAN.c`
- [Peripheral registers](https://github.com/myeongcheolko/kortos/blob/main/kortos_hal/STM32F446xx/STM32F446xx.h): `kortos_hal/STM32F446xx/STM32F446xx.h`
- [Clock control](https://github.com/myeongcheolko/kortos/blob/main/kortos_hal/STM32F446xx/rcc.c): `kortos_hal/STM32F446xx/rcc.c`
- [HAL include interface](https://github.com/myeongcheolko/kortos/blob/main/kortos_hal/STM32F446xx/kortos_hal.h): `kortos_hal/STM32F446xx/kortos_hal.h`

### Board bring-up

- [Startup and vectors](https://github.com/myeongcheolko/kortos/blob/main/bsp/STM32F446xx/startup.c): `bsp/STM32F446xx/startup.c`
- [System calls](https://github.com/myeongcheolko/kortos/blob/main/bsp/STM32F446xx/syscalls.c): `bsp/STM32F446xx/syscalls.c`
- [Heap support](https://github.com/myeongcheolko/kortos/blob/main/bsp/STM32F446xx/sysmem.c): `bsp/STM32F446xx/sysmem.c`

### Sample applications

- [Application tasks](https://github.com/myeongcheolko/kortos/blob/main/sample_apps/kernel/CAN_loopback_mutex_queue.c): `sample_apps/kernel/CAN_loopback_mutex_queue.c`
- [SPI exchange demo](https://github.com/myeongcheolko/kortos/blob/main/sample_apps/hal/SPI_send_receive_arduino.c): `sample_apps/hal/SPI_send_receive_arduino.c`

### Other components

- **Application developer**

## Connections

- Application developer → Application tasks: implements
- Application tasks → Kernel API: calls (evidence: `sample_apps/kernel/CAN_loopback_mutex_queue.c`)
- Kernel API → Scheduler and primitives: implemented by (evidence: `kernel/kernel.c`)
- Scheduler and primitives → Context switching: yields to
- Context switching → Scheduler and primitives: ticks and schedules (evidence: `port/arm/cortex_m4/port.c`)
- Scheduler and primitives → Kernel configuration: uses settings
- Application tasks → CAN driver: transmits frames (evidence: `sample_apps/kernel/CAN_loopback_mutex_queue.c`)
- Application tasks → GPIO driver: configures pins (evidence: `sample_apps/kernel/CAN_loopback_mutex_queue.c`)
- SPI exchange demo → SPI driver: exchanges data (evidence: `sample_apps/hal/SPI_send_receive_arduino.c`)
- SPI exchange demo → GPIO driver: reads and toggles (evidence: `sample_apps/hal/SPI_send_receive_arduino.c`)
- HAL include interface → GPIO driver: includes (evidence: `kortos_hal/STM32F446xx/kortos_hal.h`)
- HAL include interface → SPI driver: includes (evidence: `kortos_hal/STM32F446xx/kortos_hal.h`)
- HAL include interface → I2C driver: includes (evidence: `kortos_hal/STM32F446xx/kortos_hal.h`)
- HAL include interface → USART driver: includes (evidence: `kortos_hal/STM32F446xx/kortos_hal.h`)
- HAL include interface → CAN driver: includes (evidence: `kortos_hal/STM32F446xx/kortos_hal.h`)
- Startup and vectors → Scheduler and primitives: starts runtime
- Port interface → Context switching: declares services (evidence: `port/arm/cortex_m4/port.c`)
- Peripheral registers → Clock control: defines registers
