# robotpatient/manikin_sensor_node architecture

> Architecture diagram of the GitHub repository robotpatient/manikin_sensor_node, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/robotpatient/manikin_sensor_node
- Repository: https://github.com/robotpatient/manikin_sensor_node

## Overview

##### Project Type and Purpose
- This is an embedded-firmware project for the “Manikin Sensor Node,” running on an STM32F4 series MCU.
- It implements sensor sampling, storage (flash), communication over USB-CDC and CAN bus, and a command-line interface (CLI), all built on top of the ST HAL and FreeRTOS hooks.

##### High-Level Architectural Layers
- Hardware Layer
- STM32F405 microcontroller block
- On-chip peripherals: GPIO, I2C, SPI, timers, watchdog, USB FS, CAN, internal flash memory
- HAL / BSP Layer
- stm32f4xx_hal_conf.h, board_conf.h, usbd_conf.h
- manikin_software_hooks/hal_drivers providing platform-specific wrappers for I2C, SPI, timer, watchdog, error functions
- RTOS / System Hooks
- FreeRTOS integration: freertos_hooks.c
- interrupt handlers, syscalls, HAL MSP (msp.c), error handling hooks
- Middleware / Drivers
- CAN driver: can_wrapper.{c,h}
- USB CDC: usb_device.c, usbd_*.c
- Flash driver: flash.{c,h}
- CLI: cli.{c,h}, cli_setup.{c,h}
- Application Layer
- Sampling logic: sampling.c/h
- Main initialization & scheduler startup: main.cpp
- Configuration headers under config/

##### Components & Interactions
- MCU Hardware ⇄ HAL/BSP
- HAL config headers select which peripherals are enabled/configured
- HAL MSP routines handle low-level Init/DeInit
- HAL/BSP ⇄ Drivers
- Drivers call HAL API for peripheral operations
- manikin_software_hooks supply target-specific implementations
- Drivers ⇄ Application
- Sampling task triggers peripheral reads via I2C/SPI drivers
- CLI task sends and receives commands through USB/CAN wrappers
- Flash driver is used by sampling or CLI for non-volatile storage
- RTOS Scheduler
- Manages tasks: Sampling, CLI, USB/CAN handlers, flash tasks
- External Interfaces
- USB CDC to host PC for data logging / CLI
- CAN bus to manikin control network

##### Architectural Patterns
- Layered approach (hardware abstraction, middleware, application)
- Modular drivers each responsible for a single peripheral or protocol
- FreeRTOS hooks for portability and OS integration
- Separation of concerns: config vs. code, HAL vs. wrappers vs. application logic

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Compile-time Config
    subgraph "Compile-time Config"
        CONFIG1["CMakeLists.txt"]:::config
        CONFIG2["src/manikin_software_hooks/CMakeLists.txt"]:::config
        CONFIG3["config/stm32f4xx_hal_conf.h"]:::config
        CONFIG4["config/board_conf.h"]:::config
        CONFIG5["config/usbd_conf.h"]:::config
    end

    %% HAL/BSP Layer
    subgraph "HAL/BSP Layer"
        HAL_API["HAL API"]:::hal
        BSP1["manikin_i2c_functions"]:::hal
        BSP2["manikin_spi_functions"]:::hal
        BSP3["manikin_timer_functions"]:::hal
        BSP4["manikin_watchdog_functions"]:::hal
        BSP5["manikin_error_functions"]:::hal
        BSP6["manikin_platform.h"]:::hal
        BSP7["manikin_software_conf.h"]:::hal
    end

    %% RTOS / System Hooks
    subgraph "RTOS / System Hooks"
        RTOS1["freertos_hooks.c"]:::rtos
        RTOS2["hal_msp.c"]:::rtos
        RTOS3["interrupt_handler.c"]:::rtos
        RTOS4["syscalls.c"]:::rtos
        RTOS5["error_handling.c"]:::rtos
        Scheduler["RTOS Scheduler"]:::rtosCore
    end

    %% Drivers
    subgraph "Drivers"
        CANW["CAN Wrapper"]:::drivers
        USBD["USB CDC Driver"]:::drivers
        FLASHD["Flash Driver"]:::drivers
        CLI_D["CLI Driver"]:::drivers
    end

    %% Application Layer
    subgraph "Application Layer"
        MAIN["Main Init & Scheduler Startup"]:::app
        SAMPLING["Sampling Task"]:::app
        CLI_TASK["CLI Task"]:::app
    end

    %% Hardware Layer
    subgraph "Hardware Layer"
        MCU["STM32F405 MCU"]:::hardware
    end

    %% Connections
    CONFIG1 -->|builds| HAL_API
    CONFIG2 -->|builds| HAL_API
    CONFIG3 -->|configures| HAL_API
    CONFIG4 -->|configures| HAL_API
    CONFIG5 -->|configures| HAL_API

    MAIN -->|starts| Scheduler
    Scheduler -->|schedules| SAMPLING
    Scheduler -->|schedules| CLI_TASK

    SAMPLING -->|stores| FLASHD
    SAMPLING -->|sends| CANW
    SAMPLING -->|sends| USBD
    CLI_TASK -->|uses| CANW
    CLI_TASK -->|uses| USBD

    FLASHD -->|calls HAL| HAL_API
    CANW -->|calls HAL| HAL_API
    USBD -->|calls HAL| HAL_API
    CLI_D -->|calls HAL| HAL_API

    HAL_API -->|drives| MCU

    MCU -->|interrupt| RTOS3
    RTOS3 -->|notifies| Scheduler
    RTOS2 -->|init hooks| HAL_API

    %% Click Events
    click CONFIG1 "https://github.com/robotpatient/manikin_sensor_node/blob/main/CMakeLists.txt"
    click CONFIG2 "https://github.com/robotpatient/manikin_sensor_node/blob/main/src/manikin_software_hooks/CMakeLists.txt"
    click CONFIG3 "https://github.com/robotpatient/manikin_sensor_node/blob/main/config/stm32f4xx_hal_conf.h"
    click CONFIG4 "https://github.com/robotpatient/manikin_sensor_node/blob/main/config/board_conf.h"
    click CONFIG5 "https://github.com/robotpatient/manikin_sensor_node/blob/main/config/usbd_conf.h"
    click BSP1 "https://github.com/robotpatient/manikin_sensor_node/blob/main/src/manikin_software_hooks/hal_drivers/manikin_i2c_functions.c"
    click BSP2 "https://github.com/robotpatient/manikin_sensor_node/blob/main/src/manikin_software_hooks/hal_drivers/manikin_spi_functions.c"
    click BSP3 "https://github.com/robotpatient/manikin_sensor_node/blob/main/src/manikin_software_hooks/hal_drivers/manikin_timer_functions.c"
    click BSP4 "https://github.com/robotpatient/manikin_sensor_node/blob/main/src/manikin_software_hooks/hal_drivers/manikin_watchdog_functions.c"
    click BSP5 "https://github.com/robotpatient/manikin_sensor_node/blob/main/src/manikin_software_hooks/hal_drivers/manikin_error_functions.c"
    click BSP6 "https://github.com/robotpatient/manikin_sensor_node/blob/main/src/manikin_software_hooks/conf/manikin_platform.h"
    click BSP7 "https://github.com/robotpatient/manikin_sensor_node/blob/main/src/manikin_software_hooks/conf/manikin_software_conf.h"
    click RTOS1 "https://github.com/robotpatient/manikin_sensor_node/blob/main/src/hooks/freertos_hooks.c"
    click RTOS2 "https://github.com/robotpatient/manikin_sensor_node/blob/main/src/hooks/hal_msp.c"
    click RTOS3 "https://github.com/robotpatient/manikin_sensor_node/blob/main/src/hooks/interrupt_handler.c"
    click RTOS4 "https://github.com/robotpatient/manikin_sensor_node/blob/main/src/hooks/syscalls.c"
    click RTOS5 "https://github.com/robotpatient/manikin_sensor_node/blob/main/src/hooks/error_handling.c"
    click CANW "https://github.com/robotpatient/manikin_sensor_node/blob/main/src/can/can_wrapper.c"
    click USBD "https://github.com/robotpatient/manikin_sensor_node/blob/main/src/usb/usb_device.c"
    click FLASHD "https://github.com/robotpatient/manikin_sensor_node/blob/main/src/flash/flash.c"
    click CLI_D "https://github.com/robotpatient/manikin_sensor_node/blob/main/src/cli/cli.c"
    click SAMPLING "https://github.com/robotpatient/manikin_sensor_node/blob/main/src/sampling.c"
    click MAIN "https://github.com/robotpatient/manikin_sensor_node/blob/main/src/main.cpp"

    %% Styles
    classDef hardware fill:#AAAAAA,stroke:#333,stroke-width:1px
    classDef hal fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef rtos fill:#FFA500,stroke:#333,stroke-width:1px
    classDef rtosCore fill:#FF8C00,stroke:#333,stroke-width:2px
    classDef drivers fill:#90EE90,stroke:#333,stroke-width:1px
    classDef app fill:#4682B4,stroke:#333,stroke-width:1px
    classDef config fill:#DDA0DD,stroke:#333,stroke-width:1px
```
