# iwatake2222/digitalcamera_stm32 architecture

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

- Interactive diagram: https://gitdiagram.com/iwatake2222/digitalcamera_stm32
- Repository: https://github.com/iwatake2222/digitalcamera_stm32

## Overview

##### Project Type & Purpose
- This is an embedded system project for a digital camera built around an STM32F4 microcontroller.
- Its purpose is to capture still photos and record movies (both JPEG and Motion JPEG), provide a live view, and facilitate media playback using peripherals (camera module OV7670, LCD with ILI9341 controller, and an SD card for storage).

##### Analyzing the File Structure
- Top-Level Components:
– Directories such as Drivers (CMSIS and STM32 HAL drivers), Src (application source code and drivers), and Inc (header files). These indicate a layered design with hardware abstraction.
– The Middlewares folder contains external libraries for FreeRTOS (real-time operating system scheduler), FatFS (file system for SD card), and LibJPEG (for JPEG compression/decompression).
– The presence of a startup folder and configuration files (for CubeMX, linker file, etc.) confirms that the project is built on standard STM32 embedded design principles.
- Observations:
– There is clear separation between hardware drivers (e.g., for LCD, OV7670, UART) and application logic (mode manager, live view control, playback).
– Tools and documentation directories indicate that there are conversion tools (e.g., jpeg2RGB565.py) and design documents to aid the development.

##### Insights from the README
- It highlights the use of specific STM32 peripherals: DCMI for the camera, FSMC or similar interface for LCD, SPI for SD card, and interfaces for rotary encoders and buttons.
- The software is built using FreeRTOS to manage tasks, FatFS to handle file operations on the SD card, and LibJPEG for image processing.

- Main Components (each represented as a distinct block or component):
– Microcontroller (STM32F407 on the Discovery board), representing the core processing unit.
– Hardware Interfaces:
- Camera Module (OV7670) on the DCMI interface.
- Module (ILI9341) connected via FSMC/LCD driver.
- SD Card via SPI (plus FatFS integration).
- I2C bus for camera configuration.
- UART for terminal debugging.
- Rotary Encoders and Buttons (control inputs).
– Software Layers:
- Hardware Abstraction Layer (drivers under “Drivers” and “Inc” folders using STM32 HAL and CMSIS libraries).
- Middleware Layer:
- FreeRTOS – for task scheduling (look at Middlewares/Third_Party/FreeRTOS).
- FatFS – for file system management on SD card (in the FatFs folder).
- LibJPEG – for image handling (located in Middlewares/Third_Party/LibJPEG).
- Application Layer:
- Application logic in the “Src/app” folder (debugMonitor, liveviewCtrl, modeMgr, playbackCtrl).
- Additional services in “Src/service” (file and input services).
- Low-Level Initialization and Startup routines (startup folder and main.c, system_stm32f4xx.c).

- Relationships and Data Flow:
– Show that the hardware abstraction layer directly interfaces with the physical interfaces (DCMI for camera, FSMC for LCD, SPI for SD card).

- Architectural Patterns/Design Principles:
– Layered architecture: Separation of hardware-level drivers, middleware services, and application logic.
– Use of a Real-Time Operating System (FreeRTOS) for multitasking.
– Modular design approach allowing independent updating of drivers (e.g., for LCD or camera) without impacting higher-level services.

- Incorporate Relevant Technologies:
– STM32F407 (ARM Cortex-M4) as the MCU.
– STM32CubeMX and HAL libraries for peripheral configuration.
– External libraries: FreeRTOS, FatFS, LibJPEG.
– Tools: Python and batch scripts in “00_tools” for data conversion.

##### Final Assembly
- On one side, attach the interfaces: DCMI (with connection to OV7670), FSMC for LCD connection, SPI for SD card.
- On another side, layer the drivers (CMSIS, HAL), followed by middleware (FreeRTOS, FatFS, LibJPEG), and then the application logic (live view, mode management, and playback).
- Don’t forget to include peripheral debugging tools (USART2) and configuration inputs (buttons/rotary encoders).

## Diagram (Mermaid)

```mermaid
graph TD
  %% MCU & Initialization
  subgraph "MCU & Initialization"
    S1("Startup Code"):::init
    M1("main.c"):::init
    M2("system_stm32f4xx.c"):::init
    MCU("STM32F407 MCU"):::mcu
  end
  S1 --> MCU
  M1 --> MCU
  M2 --> MCU

  %% Hardware Abstraction Layer
  subgraph "Hardware Abstraction Layer"
    HALA("CMSIS Drivers"):::hal
    HALB("STM32F4xx HAL Driver"):::hal
    HALC("HAL Config & IRQ"):::hal
  end
  MCU --> HALA
  MCU --> HALB
  HALA --> HALC
  HALB --> HALC

  %% Middleware Layer
  subgraph "Middleware"
    RTOS("FreeRTOS"):::middleware
    FATFS("FatFS"):::middleware
    JPEG("LibJPEG"):::middleware
  end

  %% Application Layer
  subgraph "Application Layer"
    APP("App Tasks"):::app
    SERV("Services"):::app
  end

  %% Hardware Peripherals
  subgraph "Hardware Peripherals"
    CAM("Camera (OV7670)"):::hw
    DISP("Display (ILI9341)"):::hw
    SD("SD Card (SPI)"):::hw
    UART("UART Debug"):::hw
    CTRL("Control Inputs"):::hw
  end

  %% Tools
  DT("Data Conversion Tools"):::tools

  %% Connections between layers
  MCU -->|"uses"| HALA
  MCU -->|"uses"| HALB

  APP -->|"calls_drivers"| HALA
  APP -->|"calls_drivers"| HALB
  SERV -->|"calls_drivers"| HALA
  SERV -->|"calls_drivers"| HALB

  HALA -->|"interfaces"| CAM
  HALB -->|"interfaces"| DISP
  HALC -->|"interfaces"| UART
  HALC -->|"interfaces"| SD
  HALC -->|"interfaces"| CTRL

  APP -->|"uses_RTOS"| RTOS
  APP -->|"uses_FatFS"| FATFS
  APP -->|"uses_LibJPEG"| JPEG
  RTOS -->|"schedules"| APP

  APP -->|"builds_assets"| DT

  %% Styling
  classDef init fill:#90ee90,stroke:#006400,stroke-width:2px,color:#000;
  classDef mcu fill:#f4a460,stroke:#8b4513,stroke-width:2px,color:#000;
  classDef hal fill:#add8e6,stroke:#4682b4,stroke-width:2px,color:#000;
  classDef middleware fill:#dda0dd,stroke:#9932cc,stroke-width:2px,color:#000;
  classDef app fill:#ffb6c1,stroke:#ff69b4,stroke-width:2px,color:#000;
  classDef hw fill:#e0ffff,stroke:#20b2aa,stroke-width:2px,color:#000;
  classDef tools fill:#ffffe0,stroke:#ffd700,stroke-width:2px,color:#000;

  %% Click Events
  click S1 "https://github.com/iwatake2222/digitalcamera_stm32/blob/master/startup/startup_stm32f407xx.s"
  click M1 "https://github.com/iwatake2222/digitalcamera_stm32/blob/master/Src/main.c"
  click M2 "https://github.com/iwatake2222/digitalcamera_stm32/blob/master/Src/system_stm32f4xx.c"
  click HALA "https://github.com/iwatake2222/digitalcamera_stm32/tree/master/Drivers/CMSIS"
  click HALB "https://github.com/iwatake2222/digitalcamera_stm32/tree/master/Drivers/STM32F4xx_HAL_Driver"
  click HALC "https://github.com/iwatake2222/digitalcamera_stm32/blob/master/Inc/stm32f4xx_hal_conf.h"
  click RTOS "https://github.com/iwatake2222/digitalcamera_stm32/tree/master/Middlewares/Third_Party/FreeRTOS"
  click FATFS "https://github.com/iwatake2222/digitalcamera_stm32/tree/master/Middlewares/Third_Party/FatFs"
  click JPEG "https://github.com/iwatake2222/digitalcamera_stm32/tree/master/Middlewares/Third_Party/LibJPEG"
  click APP "https://github.com/iwatake2222/digitalcamera_stm32/tree/master/Src/app"
  click SERV "https://github.com/iwatake2222/digitalcamera_stm32/tree/master/Src/service"
  click CAM "https://github.com/iwatake2222/digitalcamera_stm32/tree/master/Src/driver/ov7670"
  click DISP "https://github.com/iwatake2222/digitalcamera_stm32/tree/master/Src/driver/lcdIli9341"
  click UART "https://github.com/iwatake2222/digitalcamera_stm32/tree/master/Src/driver/uartTerminal"
  click DT "https://github.com/iwatake2222/digitalcamera_stm32/tree/master/00_tools"
```
