Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -41,21 +45,23 @@ 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: $<'
$(CC) -std=gnu99 -DNDEBUG -D__NEWLIB__ -Os -g -Wall -Wunused -c -fmessage-length=0 -fno-builtin -ffunction-sections -fdata-sections -flto -ffat-lto-objects -mcpu=arm7tdmi -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.o)" -MT"$(@:%.o=%.d)" -o "$@" "$<"
@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)'
Expand Down
32 changes: 32 additions & 0 deletions boards/lpc2134_01.json
Original file line number Diff line number Diff line change
@@ -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"
}

30 changes: 30 additions & 0 deletions create_version.py
Original file line number Diff line number Diff line change
@@ -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()
26 changes: 26 additions & 0 deletions custom_upload.py
Original file line number Diff line number Diff line change
@@ -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)
11 changes: 11 additions & 0 deletions fix_linkflags.py
Original file line number Diff line number Diff line change
@@ -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")
)
Binary file added lpc21isp_linux
Binary file not shown.
Binary file added lpc21isp_win.exe
Binary file not shown.
28 changes: 28 additions & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
@@ -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
File renamed without changes.
File renamed without changes.