diff --git a/Makefile b/Makefile index 60bf62e..08c5b76 100644 --- a/Makefile +++ b/Makefile @@ -30,9 +30,13 @@ COLOR_END = $(shell echo "\033[0m") # Source files C_SRCS += $(wildcard $(SRC_DIR)*.c) $(BUILD_DIR)version.c -S_SRCS += $(wildcard $(SRC_DIR)*.s) +S_SRCS += $(wildcard $(SRC_DIR)*.S) -OBJS := $(patsubst $(SRC_DIR)%.c,$(BUILD_DIR)%.o,$(C_SRCS)) $(patsubst $(SRC_DIR)%.s,$(BUILD_DIR)%.o,$(S_SRCS)) +# filter out src/version.c created by PlatformIO +TMPVAR := $(C_SRCS) +C_SRCS = $(filter-out $(SRC_DIR)version.c, $(TMPVAR)) + +OBJS := $(patsubst $(SRC_DIR)%.c,$(BUILD_DIR)%.o,$(C_SRCS)) $(patsubst $(SRC_DIR)%.S,$(BUILD_DIR)%.o,$(S_SRCS)) C_DEPS := $(wildcard *.d) @@ -41,13 +45,15 @@ all: axf $(BUILD_DIR)version.c: $(BUILD_DIR)tag git describe --tag --always --dirty | \ sed 's/.*/const char* Version_GetGitVersion(void) { return "&"; }/' > $@ - # Always regenerate the git version .PHONY: $(BUILD_DIR)version.c $(BUILD_DIR)tag: + $(RM) $(SRC_DIR)version.c mkdir -p $(BUILD_DIR) touch $(BUILD_DIR)tag + # platformio will generate a version.c in this place, which messes with the build. + # remove it we're building from the makefile.. $(BUILD_DIR)%.o: $(SRC_DIR)%.c $(BUILD_DIR)tag @echo 'Building file: $<' @@ -55,7 +61,7 @@ $(BUILD_DIR)%.o: $(SRC_DIR)%.c $(BUILD_DIR)tag @echo 'Finished building: $(COLOR_GREEN)$<$(COLOR_END)' @echo ' ' -$(BUILD_DIR)%.o: $(SRC_DIR)%.s $(BUILD_DIR)tag +$(BUILD_DIR)%.o: $(SRC_DIR)%.S $(BUILD_DIR)tag @echo 'Building file: $<' $(CC) -c -x assembler-with-cpp -I $(BUILD_DIR) -DNDEBUG -D__NEWLIB__ -mcpu=arm7tdmi -o "$@" "$<" @echo 'Finished building: $(COLOR_GREEN)$<$(COLOR_END)' diff --git a/boards/lpc2134_01.json b/boards/lpc2134_01.json new file mode 100644 index 0000000..278e84b --- /dev/null +++ b/boards/lpc2134_01.json @@ -0,0 +1,32 @@ +{ + "build": { + "cpu": "arm7tdmi", + "f_cpu": "55296000L", + "mcu": "lpc2134" + }, + "connectivity": [ + ], + "debug": { + "jlink_device": "LPC2134", + "pyocd_target": "lpc2134", + "svd_path": "LPC176x5x_v0.2.svd" + }, + "frameworks": [ + "mbed" + ], + "name": "NXP LPC2134/01", + "upload": { + "maximum_ram_size": 16384, + "maximum_size": 131072, + "protocol": "mbed", + "protocols": [ + "jlink", + "blackmagic", + "cmsis-dap", + "mbed" + ] + }, + "url": "https://www.nxp.com/products/processors-and-microcontrollers/arm-microcontrollers/general-purpose-mcus/lpc2000-arm7/single-chip-16-32-bit-microcontrollers-32-64-128-256-512-kb-isp-iap-flash-with-10-bit-adc-and-dac:LPC2134FBD64", + "vendor": "NXP" +} + diff --git a/create_version.py b/create_version.py new file mode 100644 index 0000000..cfc711b --- /dev/null +++ b/create_version.py @@ -0,0 +1,30 @@ +import subprocess +import os +import traceback +import shutil +Import("env") + +def create_version_c(*args, **kwargs): + print("Creating version.c file from git describe..") + # sanity check: was this downlaoded via git? + if not os.path.isdir(".git"): + print("Aborting creation of version.c since this project was not cloned via `git`...") + return + # sanity check: do we have git? + if shutil.which("git") is None: + print("Command `git` is not available, aborting creation of src/version.c..") + return + try: + git_tag_cmd = ["git", "describe", "--tag", "--always", "--dirty"] + git_tag = subprocess.check_output(git_tag_cmd).decode('utf-8').strip() + print("Got tag: %s" % git_tag) + file_content = 'const char* Version_GetGitVersion(void) { return "%s"; }' % git_tag + with open("src/version.c", 'w') as out_file: + out_file.write(file_content) + print("Writing version.c okay.") + except Exception as exc: + print("Exception during creation of version.c occured: %s" % str(exc)) + print(traceback.format_exc()) + os.remove("src/version.c") + +create_version_c() diff --git a/custom_upload.py b/custom_upload.py new file mode 100644 index 0000000..4058ec6 --- /dev/null +++ b/custom_upload.py @@ -0,0 +1,26 @@ +Import("env") +import os +import platform +from platformio.builder.tools.pioupload import AutodetectUploadPort + +config = env.GetProjectConfig() +mcu_clock = config.get("upload_settings", "MCU_CLOCK") +flash_baud = config.get("upload_settings", "FLASH_BAUD") +#print("MCU_CLOCK: %s" % str(mcu_clock)) + +# Python callback +def on_upload(source, target, env): + AutodetectUploadPort(env) + #print(source, target) + firmware_path = str(source[0]) + # replace .bin with .hex. Upload needs .hex not .bin + firmware_path = firmware_path[:-3] + "hex" + print("Firmware path: %s" % firmware_path) + # find out what executable to call + uploader = "./lpc21isp_linux" + if platform.system() == "Windows": + uploader = "lpc21isp_win.exe" + # do something + env.Execute("%s \"%s\" %s %s %s" % (uploader, firmware_path, env.subst("$UPLOAD_PORT"), flash_baud, mcu_clock)) + +env.Replace(UPLOADCMD=on_upload) \ No newline at end of file diff --git a/fix_linkflags.py b/fix_linkflags.py new file mode 100644 index 0000000..346674c --- /dev/null +++ b/fix_linkflags.py @@ -0,0 +1,11 @@ +Import("env") +env.Append(LINKFLAGS=["-nostdlib"]) + +# Custom HEX from ELF +env.AddPostAction( + "$BUILD_DIR/${PROGNAME}.elf", + env.VerboseAction(" ".join([ + "$OBJCOPY", "-O", "ihex", "-R", ".eeprom", + "\"$BUILD_DIR/${PROGNAME}.elf\"", "\"$BUILD_DIR/${PROGNAME}.hex\"" + ]), "Building $BUILD_DIR/${PROGNAME}.hex") +) \ No newline at end of file diff --git a/lpc21isp_linux b/lpc21isp_linux new file mode 100755 index 0000000..a525b08 Binary files /dev/null and b/lpc21isp_linux differ diff --git a/lpc21isp_win.exe b/lpc21isp_win.exe new file mode 100644 index 0000000..69d4097 Binary files /dev/null and b/lpc21isp_win.exe differ diff --git a/platformio.ini b/platformio.ini new file mode 100644 index 0000000..8a1c6a0 --- /dev/null +++ b/platformio.ini @@ -0,0 +1,28 @@ +[upload_settings] +; value will be read by python script. analogous to Makefile +FLASH_BAUD = 57600 +MCU_CLOCK = 11059 + +[env:lpc2134_01] +platform = nxplpc +; use custom board definition for NXP LPC 2134/01 +board = lpc2134_01 +; use same linkerscript as Makefile uses +board_build.ldscript = T-962-controller.ld +; remove default thumb mode flag +build_unflags = -mthumb +; reproduce build flags from Makefile +build_flags = -DNDEBUG -D__NEWLIB__ -fno-builtin -fmessage-length=0 -flto -ffat-lto-objects -Wl,-u_printf_float -Wl,-u_scanf_float +; add -nostdlib to linkerflags via script; cannot be done via build_flags in this case +; see https://docs.platformio.org/en/latest/projectconf/advanced_scripting.html#extra-linker-flags-without-wl-prefix +; also creates additional HEX file (otherwise only .elf and .bin are there, but uploader needs .hex) +; reproduce creation of version.c file, as Makefile does (could also work without, but why not..) +extra_scripts = + fix_linkflags.py + pre:create_version.py + custom_upload.py +; upload via custom lpc21isp program. +; precompiled binaries for Windows and Linux exist in this directory. Assume Windows by default +upload_protocol = custom +;if explicit upload port is needed (will be auto-detected otherwise) +;upload_port = COM1 diff --git a/src/cr_startup_lpc21.s b/src/cr_startup_lpc21.S similarity index 100% rename from src/cr_startup_lpc21.s rename to src/cr_startup_lpc21.S diff --git a/src/import.s b/src/import.S similarity index 100% rename from src/import.s rename to src/import.S