# greatscottgadgets/hackrf architecture

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

- Interactive diagram: https://gitdiagram.com/greatscottgadgets/hackrf
- Repository: https://github.com/greatscottgadgets/hackrf

## Overview

##### Main Components

a. Hardware Layer:
- RF Frontend (based on /hardware/hackrf-one/frontend.kicad_sch)
- Baseband Processing (based on /hardware/hackrf-one/baseband.kicad_sch)
- MCU/Control Unit (based on /hardware/hackrf-one/mcu.kicad_sch)
- CPLD Interface (firmware/cpld)
- External Interfaces (USB, RF, Clock)

b. Firmware Layer:
- Main USB Interface (firmware/hackrf_usb)
- Common Libraries (firmware/common)
- Hardware Drivers
- RF Path Control
- SGPIO Interface
- USB Communication
- Clock Management

c. Host Software Layer:
- libhackrf (host/libhackrf)
- HackRF Tools (host/hackrf-tools)
- External Software Support

**[Host Software Layer]**
- ↕ USB
**[Firmware Layer]**
- ↕
**[Hardware Layer]**

##### Specific Implementation Details

a. Hardware Layer (Bottom):
- Baseband processing components
- LPC4320/4330 MCU
- CPLD for high-speed digital interfacing
- Clock distribution (Si5351C)
- Flash memory (W25Q80BV)

b. Firmware Layer (Middle):
- Firmware modules:
- USB stack
- RF control
- Streaming data path
- Configuration interfaces
- M0/M4 core separation
- SGPIO interface to CPLD

c. Host Software Layer (Top):
- libhackrf API
- Command-line tools
- External software integration points

##### Additional Elements

- Frequency ranges (30 MHz to 6 GHz)
- Sample rate capabilities
- External clock inputs
- Expansion interfaces
- Opera Cake connections

##### Critical Interfaces to Highlight

- USB 2.0 interface
- RF input/output
- Clock input
- GPIO expansion
- JTAG debugging
- SPI flash programming

Remember to emphasize:
- The RF signal path
- Digital sample processing
- Control interfaces
- Host communication
- Configuration management
- External synchronization capabilities

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles and classes
    classDef hardware fill:#f9f,stroke:#333,stroke-width:2px
    classDef firmware fill:#aff,stroke:#333,stroke-width:2px
    classDef software fill:#ffa,stroke:#333,stroke-width:2px
    classDef interface fill:#ddd,stroke:#333,stroke-width:2px
    classDef rf fill:#9f9,stroke:#333,stroke-width:2px

    %% Host Software Layer
    subgraph Host
        LibHackRF["libhackrf API"]
        Tools["HackRF Tools"]
        ExtSoft["External Software"]
        
        LibHackRF --> Tools
        LibHackRF --> ExtSoft
    end

    %% Firmware Layer
    subgraph Firmware
        USB["USB Interface"]
        Common["Common Libraries"]
        RFPath["RF Path Control"]
        SGPIO["SGPIO Interface"]
        USBComm["USB Communication"]
        Clock["Clock Management"]

        USB --> Common
        Common --> RFPath
        Common --> SGPIO
        Common --> USBComm
        Common --> Clock
    end

    %% Hardware Layer
    subgraph Hardware
        RF["RF Frontend"]
        Baseband["Baseband Processing"]
        MCU["MCU/Control Unit"]
        CPLD["CPLD Interface"]
        ExtInt["External Interfaces"]

        RF <--> Baseband
        Baseband <--> MCU
        MCU <--> CPLD
        MCU <--> ExtInt
    end

    %% Inter-layer connections
    LibHackRF <--> USB
    USB <--> MCU
    SGPIO <--> CPLD

    %% Click events for component mapping
    click RF "https://github.com/greatscottgadgets/hackrf/blob/master/hardware/hackrf-one/frontend.kicad_sch"
    click Baseband "https://github.com/greatscottgadgets/hackrf/blob/master/hardware/hackrf-one/baseband.kicad_sch"
    click MCU "https://github.com/greatscottgadgets/hackrf/blob/master/hardware/hackrf-one/mcu.kicad_sch"
    click CPLD "https://github.com/greatscottgadgets/hackrf/tree/master/firmware/cpld/sgpio_if"
    click USB "https://github.com/greatscottgadgets/hackrf/tree/master/firmware/hackrf_usb"
    click Common "https://github.com/greatscottgadgets/hackrf/tree/master/firmware/common"
    click RFPath "https://github.com/greatscottgadgets/hackrf/blob/master/firmware/common/rf_path.c"
    click SGPIO "https://github.com/greatscottgadgets/hackrf/blob/master/firmware/common/sgpio.c"
    click USBComm "https://github.com/greatscottgadgets/hackrf/blob/master/firmware/common/usb.c"
    click Clock "https://github.com/greatscottgadgets/hackrf/blob/master/firmware/common/clkin.c"
    click LibHackRF "https://github.com/greatscottgadgets/hackrf/tree/master/host/libhackrf"
    click Tools "https://github.com/greatscottgadgets/hackrf/tree/master/host/hackrf-tools"

    %% Style applications
    class RF,Baseband,MCU,CPLD,ExtInt hardware
    class USB,Common,RFPath,SGPIO,USBComm,Clock firmware
    class LibHackRF,Tools,ExtSoft software
    class ExtInt interface
    class RF rf

    %% Legend
    subgraph Legend
        H["Hardware Component"]:::hardware
        F["Firmware Component"]:::firmware
        S["Software Component"]:::software
        I["Interface"]:::interface
        R["RF Component"]:::rf
    end
```
