# microchiptech/aws-iot-firmware-pic32mz architecture

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

- Interactive diagram: https://gitdiagram.com/microchiptech/aws-iot-firmware-pic32mz
- Repository: https://github.com/microchiptech/aws-iot-firmware-pic32mz

## Overview

##### Project type and purpose
- This is an embedded-firmware project for a PIC32MZ microcontroller that demonstrates how to connect an IoT Ethernet device to AWS IoT.

##### File structure
Top level:
- documents/ – guides and markdowns
- hardware/ – electrical schematic PDF
- software/aws-iot-ethernet/firmware/ – source code under a Microchip Harmony project
In firmware/src:
- app.c/.h, app1.c/.h, app2.c/.h – application modules
- app_insight_support, app_nvm_support – vendor-support libraries
- bsp_sys_init.c – board support package
- parson.c/.h – JSON parsing
- wolfmqttsdk/ – MQTT library
- system_config/.../framework – HAL drivers for ADC, CMP, clocks, ports
- system_config/.../net/pres – TLS/crypto glue
- system_config/.../system_* – startup, exceptions, tasks, interrupt handlers
Build system:
- Makefile, .hconfig, NetBeans project files

##### Extract architecture insights from README
- Connects IoT device securely to AWS IoT
- Based on Microchip Harmony + FreeRTOS
- Uses wolfMQTT for MQTT protocol

##### Main components
A. Hardware Platform
– PIC32MZ microcontroller board (Ethernet PHY + RJ45, external flash, sensors)
– Schematic (hardware/iot-ethernet-schematic.pdf)
B. Firmware Layers (stacked)
1. Boot & Initialization
- system_init, bsp_sys_init, FreeRTOS start
2. HAL / Drivers (Microchip Harmony framework)
- ADC, comparator, clock, ports, Ethernet MAC driver
3. Middleware
- Net Pres (TLS/crypto), parson JSON parser
- wolfMQTT SDK (mqtt_client, packet, socket)
4. Application Tasks
- app.c (sensor reading, state machine, MQTT publish/subscribe)
- app1.c, app2.c – additional feature demos
- app_insight_support, app_nvm_support – cloud insight & non-volatile storage
C. External Services
– AWS IoT Core (MQTT broker, certificates stored in device)

##### Relationships and interactions
- On reset→ bootloader/system_init initializes clocks, ports, FreeRTOS
- RTOS scheduler spins up application tasks
- App tasks call wolfMQTT client → which uses Net Pres for TLS →
which uses Ethernet driver → which goes to physical PHY → Ethernet cable → AWS IoT endpoint
- JSON payloads are built by parson and pushed via MQTT
- NVM support module persists device state locally

##### Architectural patterns and design principles
– Layered architecture (Hardware Abstraction → Middleware → Application)
– RTOS-based concurrency (tasks for networking, sensor, cloud)
– Secure communication via TLS and certificate authentication
– Modular code-separation (app, drivers, system_config, sdk)

##### Relevant technologies/frameworks
– Microchip Harmony framework (system_config & drivers)
– FreeRTOS (task scheduling)
– wolfMQTT (embedded MQTT client)
– parson (JSON parser)
– TLS/crypto via Net Pres module
– Microchip MPLAB X / Makefile build system

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Cloud Service
    AWS["AWS IoT Core"]:::cloud

    %% Middleware Layer
    subgraph "Middleware" 
        direction TB
        MQTT["wolfMQTT Client"]:::middleware
        TLS["Net Pres TLS/crypto"]:::middleware
        JSON["Parson JSON Parser"]:::middleware
    end

    %% HAL / Drivers Layer
    subgraph "HAL / Drivers" 
        direction TB
        ADC["ADC Driver"]:::driver
        CMP["Comparator Driver"]:::driver
        CLK["Clock Driver"]:::driver
        PORTS["Ports Driver"]:::driver
        ETH_DRV["Ethernet MAC Driver"]:::driver
    end

    %% OS & Initialization Layer
    subgraph "Boot & Initialization" 
        direction TB
        BSP["BSP & Board Init"]:::os
        SYSINIT["System Init"]:::os
        SYSEX["System Exceptions"]:::os
        SYSINT["System Interrupts"]:::os
        SYSTASK["System Tasks"]:::os
        FREERTOS["FreeRTOS Kernel"]:::os
    end

    %% Application Layer
    subgraph "Application Tasks" 
        direction TB
        MAIN["main.c"]:::app
        APP["app.c / app.h"]:::app
        APP1["app1.c / app1.h"]:::app
        APP2["app2.c / app2.h"]:::app
        INSIGHT["app_insight_support"]:::app
        NVM["app_nvm_support"]:::nvm
    end

    %% Hardware Platform
    subgraph "Hardware Platform" 
        direction TB
        CPU["PIC32MZ MCU"]:::hardware
        PHY["Ethernet PHY & RJ45"]:::hardware
        FLASH["External Flash"]:::hardware
        SENSOR["Sensors / ADC Inputs"]:::hardware
        SCHEMATIC["Ethernet Schematic"]:::hardware
    end

    %% Connections
    AWS -->|"MQTT over TLS"|PHY
    PHY -->|"Ethernet Cable"|ETH_DRV
    ETH_DRV -->|"Ethernet Driver API"|TLS
    TLS -->|"secure socket"|MQTT
    JSON -->|"build payload"|MQTT
    MQTT -->|"publish/subscribe"|APP
    SENSOR -->|"analog data"|ADC
    ADC -->|"digital value"|APP
    APP -->|"store state"|NVM
    APP -->|"cloud insight"|INSIGHT
    MAIN -->|"starts tasks"|FREERTOS
    FREERTOS -->|"schedules"|APP
    FREERTOS -->|"schedules"|APP1
    FREERTOS -->|"schedules"|APP2
    BSP -->|"initializes hardware"|SYSINIT
    SYSINIT -->|"sets up clocks and ports"|CLK
    SYSINT -->|"handles interrupts"|APP
    SYSTASK -->|"manages system tasks"|FREERTOS

    %% Click Events
    click SCHEMATIC "https://github.com/microchiptech/aws-iot-firmware-pic32mz/blob/master/hardware/iot-ethernet-schematic.pdf"
    click BSP "https://github.com/microchiptech/aws-iot-firmware-pic32mz/blob/master/software/aws-iot-ethernet/firmware/src/bsp_sys_init.c"
    click SYSINIT "https://github.com/microchiptech/aws-iot-firmware-pic32mz/blob/master/software/aws-iot-ethernet/firmware/src/system_config/DM990004_IoT_Ethernet/system_init.c"
    click SYSEX "https://github.com/microchiptech/aws-iot-firmware-pic32mz/blob/master/software/aws-iot-ethernet/firmware/src/system_config/DM990004_IoT_Ethernet/system_exceptions.c"
    click SYSINT "https://github.com/microchiptech/aws-iot-firmware-pic32mz/blob/master/software/aws-iot-ethernet/firmware/src/system_config/DM990004_IoT_Ethernet/system_interrupt.c"
    click SYSTASK "https://github.com/microchiptech/aws-iot-firmware-pic32mz/blob/master/software/aws-iot-ethernet/firmware/src/system_config/DM990004_IoT_Ethernet/system_tasks.c"
    click FREERTOS "https://github.com/microchiptech/aws-iot-firmware-pic32mz/blob/master/software/aws-iot-ethernet/firmware/src/system_config/DM990004_IoT_Ethernet/FreeRTOSConfig.h"
    click ADC "https://github.com/microchiptech/aws-iot-firmware-pic32mz/blob/master/software/aws-iot-ethernet/firmware/src/system_config/DM990004_IoT_Ethernet/framework/driver/adc/src/drv_adc_static.c"
    click CMP "https://github.com/microchiptech/aws-iot-firmware-pic32mz/blob/master/software/aws-iot-ethernet/firmware/src/system_config/DM990004_IoT_Ethernet/framework/driver/cmp/src/drv_cmp_static.c"
    click CLK "https://github.com/microchiptech/aws-iot-firmware-pic32mz/blob/master/software/aws-iot-ethernet/firmware/src/system_config/DM990004_IoT_Ethernet/framework/system/clk/src/sys_clk_static.c"
    click PORTS "https://github.com/microchiptech/aws-iot-firmware-pic32mz/blob/master/software/aws-iot-ethernet/firmware/src/system_config/DM990004_IoT_Ethernet/framework/system/ports/src/sys_ports_static.c"
    click TLS "https://github.com/microchiptech/aws-iot-firmware-pic32mz/blob/master/software/aws-iot-ethernet/firmware/src/system_config/DM990004_IoT_Ethernet/framework/net/pres/net_pres_enc_glue.c"
    click JSON "https://github.com/microchiptech/aws-iot-firmware-pic32mz/blob/master/software/aws-iot-ethernet/firmware/src/parson.c"
    click MQTT "https://github.com/microchiptech/aws-iot-firmware-pic32mz/blob/master/software/aws-iot-ethernet/firmware/src/wolfmqttsdk/src/mqtt_client.c"
    click MAIN "https://github.com/microchiptech/aws-iot-firmware-pic32mz/blob/master/software/aws-iot-ethernet/firmware/src/main.c"
    click APP "https://github.com/microchiptech/aws-iot-firmware-pic32mz/blob/master/software/aws-iot-ethernet/firmware/src/app.c"
    click APP1 "https://github.com/microchiptech/aws-iot-firmware-pic32mz/blob/master/software/aws-iot-ethernet/firmware/src/app1.c"
    click APP2 "https://github.com/microchiptech/aws-iot-firmware-pic32mz/blob/master/software/aws-iot-ethernet/firmware/src/app2.c"
    click INSIGHT "https://github.com/microchiptech/aws-iot-firmware-pic32mz/blob/master/software/aws-iot-ethernet/firmware/src/app_insight_support.c"
    click NVM "https://github.com/microchiptech/aws-iot-firmware-pic32mz/blob/master/software/aws-iot-ethernet/firmware/src/app_nvm_support.c"

    %% Styles
    classDef hardware fill:#ccffcc,stroke:#333,stroke-width:1px
    classDef driver fill:#cce5ff,stroke:#333,stroke-width:1px
    classDef os fill:#cce5ff,stroke:#333,stroke-width:1px
    classDef middleware fill:#cce5ff,stroke:#333,stroke-width:1px
    classDef app fill:#ffd699,stroke:#333,stroke-width:1px
    classDef nvm fill:#ffe5cc,stroke:#333,stroke-width:1px
    classDef cloud fill:#dddddd,stroke:#333,stroke-width:1px
```
