ArchitectureΒΆ

This document provides a detailed overview of the Nexus platform architecture.

Design PrinciplesΒΆ

Nexus is built on the following design principles:

  1. Separation of Concerns: Each layer has a specific responsibility

  2. Abstraction: Hide implementation details behind clean interfaces

  3. Portability: Minimize platform-specific code in applications

  4. Testability: Design for unit testing and simulation

  5. Resource Efficiency: Optimize for constrained embedded systems

Layer ArchitectureΒΆ

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                      Applications                            β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                      Middleware                              β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”           β”‚
β”‚  β”‚  Shell  β”‚ β”‚   Log   β”‚ β”‚  Config β”‚ β”‚  Event  β”‚           β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜           β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                         OSAL                                 β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”           β”‚
β”‚  β”‚  Task   β”‚ β”‚  Mutex  β”‚ β”‚  Queue  β”‚ β”‚  Timer  β”‚           β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜           β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                          HAL                                 β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”           β”‚
β”‚  β”‚  GPIO   β”‚ β”‚  UART   β”‚ β”‚   SPI   β”‚ β”‚   I2C   β”‚           β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜           β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                    Platform / Hardware                       β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”           β”‚
β”‚  β”‚ STM32F4 β”‚ β”‚ STM32H7 β”‚ β”‚  ESP32  β”‚ β”‚  nRF52  β”‚           β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜           β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Application LayerΒΆ

User applications built on top of Nexus platform. Applications should:

  • Use only public APIs from lower layers

  • Avoid direct hardware access

  • Be portable across supported platforms

Middleware LayerΒΆ

Common services that provide higher-level functionality:

  • Log Framework: Flexible logging with multiple backends

  • Shell: Command-line interface for debugging

  • Config: Configuration management and persistence

  • Event: Event-driven programming support

See Log Framework for detailed Log Framework documentation.

OSAL LayerΒΆ

OS Abstraction Layer provides portable RTOS primitives:

  • Task: Thread/task management

  • Mutex: Mutual exclusion locks

  • Semaphore: Binary and counting semaphores

  • Queue: Message queues for inter-task communication

  • Timer: Software timers

Supported backends:

  • FreeRTOS

  • Native (pthreads for PC simulation)

  • Bare-metal (cooperative scheduling)

See OS Abstraction Layer (OSAL) for detailed OSAL documentation.

HAL LayerΒΆ

Hardware Abstraction Layer provides unified peripheral APIs:

  • GPIO: General-purpose I/O

  • UART: Serial communication

  • SPI: SPI bus master/slave

  • I2C: I2C bus master/slave

  • Timer: Hardware timers and PWM

  • ADC: Analog-to-digital conversion

See Hardware Abstraction Layer (HAL) for detailed HAL documentation.

Platform LayerΒΆ

MCU-specific implementations including:

  • Startup code and system initialization

  • Linker scripts

  • Vendor SDK integration

  • Clock and power management

Data FlowΒΆ

Application
    β”‚
    β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Middleware    β”‚  ← Uses OSAL for threading, HAL for I/O
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚
         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚      OSAL       β”‚  ← Uses HAL for timing
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚
         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚       HAL       β”‚  ← Uses Platform for hardware access
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚
         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚    Platform     β”‚  ← Direct hardware access
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Dependency RulesΒΆ

Strict dependency rules ensure clean architecture:

  1. Upper layers depend on lower layers (never reverse)

  2. Same-layer components are independent (no horizontal dependencies)

  3. Platform layer is the only layer with hardware access

βœ… Application β†’ Middleware β†’ OSAL β†’ HAL β†’ Platform
❌ HAL β†’ Middleware (reverse dependency)
❌ GPIO β†’ UART (horizontal dependency within HAL)

Memory ManagementΒΆ

Nexus supports multiple memory management strategies:

Static Allocation

All memory allocated at compile time. Suitable for safety-critical systems.

Dynamic Allocation

Runtime memory allocation using malloc/free. More flexible but requires careful management.

Pool Allocation

Fixed-size memory pools for predictable allocation patterns.

Configuration example:

/* Static allocation mode */
#define NEXUS_USE_STATIC_ALLOC  1
#define NEXUS_MAX_TASKS         8
#define NEXUS_MAX_MUTEXES       16

Error HandlingΒΆ

All Nexus APIs follow consistent error handling:

/* All functions return status codes */
hal_status_t status = hal_gpio_init(port, pin, &config);
if (status != HAL_OK) {
    /* Handle error */
    LOG_ERROR("GPIO init failed: %d", status);
}

Common status codes:

Status

Description

XXX_OK

Operation successful

XXX_ERROR

General error

XXX_ERROR_PARAM

Invalid parameter

XXX_ERROR_STATE

Invalid state

XXX_ERROR_TIMEOUT

Operation timed out

XXX_ERROR_NO_MEMORY

Memory allocation failed

Build SystemΒΆ

Nexus uses CMake for cross-platform build configuration:

# Select platform
cmake -B build -DNEXUS_PLATFORM=stm32f4

# Enable features
cmake -B build \
    -DNEXUS_PLATFORM=stm32f4 \
    -DNEXUS_BUILD_TESTS=ON \
    -DNEXUS_ENABLE_LOG=ON

Key CMake options:

Option

Description

NEXUS_PLATFORM

Target platform (stm32f4, native)

NEXUS_BUILD_TESTS

Build unit tests

NEXUS_ENABLE_LOG

Enable log framework

NEXUS_ENABLE_COVERAGE

Enable code coverage

Next StepsΒΆ