Build system reference
libfx2 provides a flexible build system based on GNU Make for convenient development. It provides:
out-of-tree builds,
rebuilds after changes to application headers,
rebuilds (of both libfx2 and application) after changes to libfx2,
minimal and readable configuration for most common cases,
a
loadtarget for building and uploading the design using fx2tool.
To start using it, create a source file…
#include <fx2regs.h>
int main(void) {
IOA = OEA = 1;
while(1);
}
... and a Makefile, replacing .../libfx2 with the path to the root of this repository…
LIBFX2 = .../libfx2/firmware/library
include $(LIBFX2)/fx2rules.mk
... and you’re done! Running make will build a firmware.ihex, and running make load will run it on any connected Cypress development kit.
Of course, as your project grows, so has your build system. The configuration values that may be set are as follows:
TARGETsets the base name of the output Intel HEX file. It isfirmwareif not specified.
SOURCESlists the.cor.asmsource files to be built, without extension. It ismainif not specified.
LIBRARIESlists the standard libraries to be linked in, without extension. It isfx2isrsby default, and can be any offx2,fx2isrsandfx2usb.
VID,PIDset the USB VID:PID pair used to search for the development board. They are04B4:8613if not specified, which is the VID:PID pair of the Cypress development kit.
MODELsets the sdcc code model, one ofsmall,medium,largeorhuge. The libfx2 standard library as well as sdcc standard library are built for all code models. It issmallif not specified.
CODE_SIZE,XRAM_SIZEset the sizes of the corresponding sdcc segments. TheCODEandXRAMsegments must add up to at most0x4000. They are0x3e00and0x0200if not specified.
CFLAGSappends arbitrary flags to every sdcc invocation.
An elaborate Makefile could look as follows:
VID ?= 20b7
PID ?= 9db1
TARGET = glasgow
SOURCES = main leds fpga dac_ldo adc
LIBRARIES = fx2 fx2usb fx2isrs
MODEL = medium
CODE_SIZE = 0x3000
XRAM_SIZE = 0x1000
CFLAGS = -DSYNCDELAYLEN=16
LIBFX2 = ../vendor/libfx2/firmware/library
include $(LIBFX2)/fx2rules.mk