# aloebs29/flash_management architecture

> Architecture diagram of the GitHub repository aloebs29/flash_management, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/aloebs29/flash_management
- Repository: https://github.com/aloebs29/flash_management

## Overview

##### Main Components

a. Hardware Layer:
- STM32L432KC MCU
- MT29F1G01ABAFDWB SPI NAND Flash Chip
- LED Indicator
- UART Interface

b. Software Stack (from bottom to top):
- Low-Level Drivers (ST LL)
- Hardware Interface Modules
- Flash Translation Layer (Dhara)
- File System Layer (FAT FS)
- Shell Interface

##### Important Elements to Highlight

- Data flow (e.g., file operations flowing from shell to FAT FS)
- Dependencies between components
- Hardware interfaces (SPI, UART)

##### Additional Details

- Notes about key buffer sizes (NAND page size)
- Critical paths for data flow
- Error handling flow
- Potential future expansion points (USB MSC support)

## Diagram (Mermaid)

```mermaid
graph TB
    %% Style definitions
    classDef hardware fill:#d3d3d3,stroke:#333
    classDef driver fill:#b3d9ff,stroke:#333
    classDef interface fill:#ffe6cc,stroke:#333
    classDef ftl fill:#d9f2d9,stroke:#333
    classDef filesystem fill:#e6ccff,stroke:#333
    classDef application fill:#ffcccc,stroke:#333

    %% Application Layer
    subgraph Application
        Shell["Shell Interface"]
        ShellCmd["Command Handler"]
    end

    %% File System Layer
    subgraph FileSystem
        FATFS["FAT FS Core"]
        DiskIO["Disk I/O Interface"]
        FTLDiskIO["FTL Disk Interface"]
    end

    %% Flash Translation Layer
    subgraph FTL
        Dhara["Dhara FTL"]
        NANDInterface["NAND Interface"]
        Journal["Journal Management"]
        Map["Map Management"]
        MemMgmt["Memory Management"]
    end

    %% Hardware Interface Layer
    subgraph HWInterface
        LED["LED Interface"]
        UART["UART Interface"]
        SPI["SPI Interface"]
        NANDDriver["NAND Flash Driver"]
    end

    %% Low-Level Drivers
    subgraph LLDrivers
        GPIO_LL["GPIO Driver"]
        SPI_LL["SPI Driver"]
        UART_LL["UART Driver"]
        SYS_LL["System Driver"]
    end

    %% Hardware Layer
    subgraph Hardware
        MCU["STM32L432KC MCU"]
        NANDChip["MT29F1G01ABAFDWB"]
        LEDHw["LED"]
        UARTHw["UART"]
    end

    %% Connections
    Shell --> ShellCmd
    ShellCmd --> FATFS
    ShellCmd --> NANDDriver
    FATFS --> DiskIO
    DiskIO --> FTLDiskIO
    FTLDiskIO --> Dhara
    Dhara --> NANDInterface
    Dhara --> Journal
    Dhara --> Map
    MemMgmt --> Dhara
    NANDInterface --> NANDDriver
    NANDDriver --> SPI
    LED --> GPIO_LL
    UART --> UART_LL
    SPI --> SPI_LL
    GPIO_LL --> MCU
    SPI_LL --> MCU
    UART_LL --> MCU
    MCU --> NANDChip
    MCU --> LEDHw
    MCU --> UARTHw

    %% Click events for component mapping
    click Shell "https://github.com/aloebs29/flash_management/blob/master/src/modules/shell.h"
    click ShellCmd "https://github.com/aloebs29/flash_management/blob/master/src/modules/shell_cmd.h"
    click FATFS "https://github.com/aloebs29/flash_management/blob/master/src/fatfs/ff.h"
    click DiskIO "https://github.com/aloebs29/flash_management/blob/master/src/fatfs/diskio.h"
    click FTLDiskIO "https://github.com/aloebs29/flash_management/blob/master/src/modules/nand_ftl_diskio.h"
    click Dhara "https://github.com/aloebs29/flash_management/tree/master/src/dhara/"
    click NANDInterface "https://github.com/aloebs29/flash_management/blob/master/src/dhara/nand.h"
    click Journal "https://github.com/aloebs29/flash_management/blob/master/src/dhara/journal.h"
    click Map "https://github.com/aloebs29/flash_management/blob/master/src/dhara/map.h"
    click MemMgmt "https://github.com/aloebs29/flash_management/blob/master/src/modules/mem.h"
    click LED "https://github.com/aloebs29/flash_management/blob/master/src/modules/led.h"
    click UART "https://github.com/aloebs29/flash_management/blob/master/src/modules/uart.h"
    click SPI "https://github.com/aloebs29/flash_management/blob/master/src/modules/spi.h"
    click NANDDriver "https://github.com/aloebs29/flash_management/blob/master/src/modules/spi_nand.h"
    click GPIO_LL "https://github.com/aloebs29/flash_management/blob/master/src/st/ll/stm32l4xx_ll_gpio.h"
    click SPI_LL "https://github.com/aloebs29/flash_management/blob/master/src/st/ll/stm32l4xx_ll_spi.h"
    click UART_LL "https://github.com/aloebs29/flash_management/blob/master/src/st/ll/stm32l4xx_ll_usart.h"
    click SYS_LL "https://github.com/aloebs29/flash_management/blob/master/src/st/ll/stm32l4xx_ll_system.h"
    click MCU "https://github.com/aloebs29/flash_management/blob/master/src/st/stm32l432xx.h"

    %% Style applications
    class Shell,ShellCmd application
    class FATFS,DiskIO,FTLDiskIO filesystem
    class Dhara,NANDInterface,Journal,Map,MemMgmt ftl
    class LED,UART,SPI,NANDDriver interface
    class GPIO_LL,SPI_LL,UART_LL,SYS_LL driver
    class MCU,NANDChip,LEDHw,UARTHw hardware
```
