|
| 1 | +# wolfIP PIC32MZ EF port - build with Microchip XC32 |
| 2 | +# |
| 3 | +# Copyright (C) 2026 wolfSSL Inc. Part of the wolfIP TCP/IP stack (GPLv3). |
| 4 | +# |
| 5 | +# Phase 0: clocks + UART2 console + heartbeat. |
| 6 | +# Phase 1: wolfCrypt PIC32MZ hardware TRNG self-test. |
| 7 | +# Phase 2: MDIO + LAN8740 PHY link bring-up. |
| 8 | +# (Full Ethernet RX/TX driver + wolfIP core are added in later phases.) |
| 9 | +# |
| 10 | +# Usage: |
| 11 | +# make # build app.hex |
| 12 | +# make flash # program over the on-board debugger (v6.20 IPE) |
| 13 | +# make clean |
| 14 | +# Overridable: |
| 15 | +# XC32_BIN= XC32 bin dir (default /opt/microchip/xc32/v5.10/bin) |
| 16 | +# DFP= device family pack version dir |
| 17 | +# DEVICE= 32MZ2048EFM144 |
| 18 | +# WOLFSSL_ROOT= path to wolfssl checkout (used from Phase 1 on) |
| 19 | +# MDB= MPLAB X MDB CLI (default v6.20; v6.30 dropped the EF SK debugger) |
| 20 | + |
| 21 | +XC32_BIN ?= /opt/microchip/xc32/v5.10/bin |
| 22 | +DFP ?= /opt/microchip/mplabx/v6.30/packs/Microchip/PIC32MZ-EF_DFP/1.5.173 |
| 23 | +DEVICE ?= 32MZ2048EFM144 |
| 24 | + |
| 25 | +CC := $(XC32_BIN)/xc32-gcc |
| 26 | +BIN2HEX := $(XC32_BIN)/xc32-bin2hex |
| 27 | +SIZE := $(XC32_BIN)/xc32-size |
| 28 | + |
| 29 | +# Flashing via MDB (Microchip DeBugger CLI). The headless ipecmd cannot resolve |
| 30 | +# device packs ("Unable to locate DFP"), but MDB launches the full platform and |
| 31 | +# resolves them like the IDE/IPE GUI does. Default tool is an MPLAB ICD 5 on the |
| 32 | +# ICSP header; the EF Starter Kit's flaky on-board debugger (MDB tool type "sk", |
| 33 | +# only in v6.20) proved unreliable over USB, so an external debugger is preferred. |
| 34 | +MDB ?= /opt/microchip/mplabx/v6.30/mplab_platform/bin/mdb.sh |
| 35 | +MDB_DEVICE ?= PIC32MZ2048EFM144 |
| 36 | +MDB_TOOL ?= icd5 |
| 37 | + |
| 38 | +ROOT := ../../.. |
| 39 | +# Default to a wolfssl checkout sitting beside the wolfip repo. |
| 40 | +WOLFSSL_ROOT ?= $(ROOT)/../wolfssl |
| 41 | + |
| 42 | +# -O1 is available in the free XC32 edition (-O2/-Os/-O3 need a PRO license). |
| 43 | +CFLAGS := -mprocessor=$(DEVICE) -mdfp="$(DFP)" |
| 44 | +CFLAGS += -O1 -g -Wall -Wextra -ffunction-sections -fdata-sections |
| 45 | +CFLAGS += -I. -I$(ROOT) -I$(ROOT)/src |
| 46 | +CFLAGS += -DWOLFSSL_USER_SETTINGS -I$(WOLFSSL_ROOT) |
| 47 | +CFLAGS += $(EXTRA_CFLAGS) |
| 48 | + |
| 49 | +# Heap for the Hash-DRBG (wc_InitRng allocates the DRBG state). |
| 50 | +LDFLAGS := -mprocessor=$(DEVICE) -mdfp="$(DFP)" |
| 51 | +LDFLAGS += -Wl,--defsym,_min_heap_size=0x8000 |
| 52 | +LDFLAGS += -Wl,--gc-sections -Wl,-Map=app.map,--cref |
| 53 | + |
| 54 | +# Port + application sources (strict warnings) |
| 55 | +APP_SRCS := device_config.c clock_init.c uart_console.c timebase.c \ |
| 56 | + wolf_compat.c rng_selftest.c pic32mz_eth.c phy_lan8740.c main.c |
| 57 | +APP_OBJS := $(patsubst %.c,%.o,$(APP_SRCS)) |
| 58 | + |
| 59 | +# wolfcrypt sources for the RNG self-test (compiled with relaxed warnings). |
| 60 | +# Pulled directly from the sibling wolfssl checkout, no copy. |
| 61 | +WC_SRC := $(WOLFSSL_ROOT)/wolfcrypt/src |
| 62 | +WC_NAMES := random sha256 hash wc_port logging memory error |
| 63 | +WC_OBJS := $(addsuffix .o,$(addprefix wc_,$(WC_NAMES))) |
| 64 | +CFLAGS_WC := -mprocessor=$(DEVICE) -mdfp="$(DFP)" -O1 -g \ |
| 65 | + -ffunction-sections -fdata-sections \ |
| 66 | + -DWOLFSSL_USER_SETTINGS -I. -I$(WOLFSSL_ROOT) |
| 67 | + |
| 68 | +# wolfIP core stack (relaxed warnings; does not need wolfssl). |
| 69 | +CFLAGS_CORE := -mprocessor=$(DEVICE) -mdfp="$(DFP)" -O1 -g \ |
| 70 | + -ffunction-sections -fdata-sections -I. -I$(ROOT) -I$(ROOT)/src |
| 71 | + |
| 72 | +ALL_OBJS := $(APP_OBJS) wolfip.o $(WC_OBJS) |
| 73 | + |
| 74 | +all: app.hex |
| 75 | + @echo "Built PIC32MZ wolfIP port" |
| 76 | + @$(SIZE) app.elf |
| 77 | + |
| 78 | +app.elf: $(ALL_OBJS) |
| 79 | + $(CC) $(CFLAGS) $(ALL_OBJS) $(LDFLAGS) -o $@ |
| 80 | + |
| 81 | +app.hex: app.elf |
| 82 | + $(BIN2HEX) $< |
| 83 | + |
| 84 | +%.o: %.c |
| 85 | + $(CC) $(CFLAGS) -c $< -o $@ |
| 86 | + |
| 87 | +wc_%.o: $(WC_SRC)/%.c |
| 88 | + $(CC) $(CFLAGS_WC) -c $< -o $@ |
| 89 | + |
| 90 | +wolfip.o: $(ROOT)/src/wolfip.c |
| 91 | + $(CC) $(CFLAGS_CORE) -c $< -o $@ |
| 92 | + |
| 93 | +# Program the hex over an MPLAB ICD 5 (on the ICSP/debug header) via MDB. Close |
| 94 | +# the MPLAB X IPE/IDE GUI first so it isn't holding the tool. Command script: |
| 95 | +# set programoptions.eraseb4program true -> full chip erase before program |
| 96 | +# hwtool icd5 -p -> connect the ICD 5 for programming |
| 97 | +# program <app.hex> / Reset -> program, then release from reset |
| 98 | +# The trailing "Reset" is required: -p alone leaves the target held in reset. |
| 99 | +# See the mplab-icd5 skill for connection/wiring troubleshooting. |
| 100 | +flash: app.hex |
| 101 | + @printf 'device %s\nset programoptions.eraseb4program true\nhwtool %s -p\nprogram %s\nReset\nquit\n' \ |
| 102 | + "$(MDB_DEVICE)" "$(MDB_TOOL)" "$(CURDIR)/app.hex" > mdb_flash.cmd |
| 103 | + cd $(dir $(MDB)) && sh ./mdb.sh $(CURDIR)/mdb_flash.cmd |
| 104 | + |
| 105 | +clean: |
| 106 | + rm -f *.o app.elf app.hex app.map mdb_flash.cmd MPLABXLog.* log.* |
| 107 | + |
| 108 | +.PHONY: all clean flash |
0 commit comments