Skip to content

Commit

Permalink
Cleaned up xdc config file for release build, and modified linked scr…
Browse files Browse the repository at this point in the history
…ipt so that a flashable executable was created
  • Loading branch information
danieldegrasse committed Aug 14, 2020
1 parent 19694d0 commit 9544c6d
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 22 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
*.map
sd_logger
.vscode
*.bin
6 changes: 5 additions & 1 deletion EK_TM4C123GXL.lds
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ SECTIONS {
PROVIDE (_vtable_base_address =
DEFINED(_vtable_base_address) ? _vtable_base_address : 0x20000000);

.vtable (_vtable_base_address) : AT (_vtable_base_address) {
/*
* Mark the vtable as NOLOAD to prevent objcopy from allocating space
* for it. If space is allocated, ROM will be too big.
*/
.vtable (_vtable_base_address) (NOLOAD) : {
KEEP (*(.vtable))
} > REGION_DATA

Expand Down
2 changes: 1 addition & 1 deletion commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ const CmdEntry COMMANDS[] = {
int handle_command(CLIContext *ctx, char *cmd) {
const CmdEntry *entry;
int argc;
char *arguments[MAX_ARGC], *saveptr, cmd_buf[CLI_MAX_LINE];
char *arguments[MAX_ARGC], *saveptr, cmd_buf[CLI_MAX_LINE + 1];
strncpy(cmd_buf, cmd, CLI_MAX_LINE);
// The parser interprets a space as a delimeter between arguments.
// Init strtok_r.
Expand Down
34 changes: 28 additions & 6 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ CODEGEN_INSTALL_DIR = /usr

CC = "$(CODEGEN_INSTALL_DIR)/bin/arm-none-eabi-gcc"
LNK = "$(CODEGEN_INSTALL_DIR)/bin/arm-none-eabi-gcc"
OBJCPY = "$(CODEGEN_INSTALL_DIR)/bin/arm-none-eabi-objcopy"

XDC_INSTALL_DIR := /home/danieldegrasse/ti/xdctools_3_32_00_06_core
TIRTOS_INSTALL_DIR := /home/danieldegrasse/ti/tirtos_tivac_2_16_01_14
Expand All @@ -22,9 +23,9 @@ UIA_PACKAGES_DIR = $(UIA_INSTALL_DIR)/packages

XDCPATH = $(TIRTOS_PACKAGES_DIR);$(TIDRIVERS_PACKAGES_DIR);$(BIOS_PACKAGES_DIR);$(NDK_PACKAGES_DIR);$(NS_PACKAGES_DIR);$(UIA_PACKAGES_DIR);

CFLAGS = -I$(TIVAWARE_INSTALL_DIR) -I$(BIOS_PACKAGES_DIR)/ti/sysbios/posix -D_POSIX_SOURCE -D PART_TM4C123GH6PM -D gcc -D TIVAWARE -mcpu=cortex-m4 -march=armv7e-m -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16 -ffunction-sections -fdata-sections -g -gstrict-dwarf -Wall
CFLAGS = -I$(TIVAWARE_INSTALL_DIR) -I$(BIOS_PACKAGES_DIR)/ti/sysbios/posix -D_POSIX_SOURCE -D PART_TM4C123GH6PM -D gcc -D TIVAWARE -mcpu=cortex-m4 -march=armv7e-m -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16 -ffunction-sections -fdata-sections -gstrict-dwarf -Wall

LFLAGS = -Wl,-T,EK_TM4C123GXL.lds -Wl,-Map,$(NAME).map -Wl,-T,$(NAME)/linker.cmd -L$(TIVAWARE_INSTALL_DIR)/grlib/gcc -L$(TIVAWARE_INSTALL_DIR)/usblib/gcc -L$(TIVAWARE_INSTALL_DIR)/driverlib/gcc -lgr -lusb -ldriver -march=armv7e-m -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16 -nostartfiles -static -Wl,--gc-sections -L$(BIOS_PACKAGES_DIR)/gnu/targets/arm/libs/install-native/arm-none-eabi/lib/armv7e-m/fpu -lgcc -lc -lm -lrdimon
LFLAGS = -Wl,-T,EK_TM4C123GXL.lds -Wl,-Map,$(NAME).map -Wl,-T,$(NAME)/linker.cmd -L$(TIVAWARE_INSTALL_DIR)/grlib/gcc -L$(TIVAWARE_INSTALL_DIR)/usblib/gcc -L$(TIVAWARE_INSTALL_DIR)/driverlib/gcc -lgr -lusb -ldriver -march=armv7e-m -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16 -nostartfiles -static -Wl,--gc-sections -L$(BIOS_PACKAGES_DIR)/gnu/targets/arm/libs/install-native/arm-none-eabi/lib/armv7e-m/fpu -lgcc -lc -lm

###################### SHOULD NOT MODIFY BELOW THIS LINE ############################
export XDCPATH
Expand Down Expand Up @@ -83,7 +84,22 @@ LFLAGS +=

.PRECIOUS: %/compiler.opt %/linker.cmd

all: $(PROG).out
# Debug builds are the default target
debug: CFLAGS += -g
# Add rdimon lib for semihosting
debug: LFLAGS += -lrdimon
# Set BUILDTYPE to debug (for the .cfg file)
debug: BUILDTYPE = debug
# Do not create a bin file, it won't work with semihosting enabled.
debug: $(PROG).out

# Release builds add -O2 and remove semihosting
release: CFLAGS += -O2
release: LFLAGS += -lnosys
# Set BUILDTYPE to release (for the .cfg file)
release: BUILDTYPE = release
release: $(PROG).bin
@echo "Release build complete"

%/compiler.opt: %/linker.cmd;

Expand All @@ -93,7 +109,8 @@ all: $(PROG).out

%/linker.cmd: %.cfg
@ echo Running Configuro...
@ $(XDC_INSTALL_DIR)/xs xdc.tools.configuro -c "$(CODEGEN_INSTALL_DIR)" -t $(XDCTARGET) -p $(PLATFORM) --compileOptions "$(CFLAGS)" $(NAME).cfg
@ # Add the buildtype variable here
@ $(XDC_INSTALL_DIR)/xs xdc.tools.configuro -c "$(CODEGEN_INSTALL_DIR)" -t $(XDCTARGET) -p $(PLATFORM) -Dbuildtype=$(BUILDTYPE) --compileOptions "$(CFLAGS)" $(NAME).cfg

%.obj: %.c $(NAME)/compiler.opt
@ echo Building $@
Expand All @@ -107,6 +124,10 @@ all: $(PROG).out
@ echo Building $@
@ $(CC) $(CFLAGS) $< -c @$(NAME)/compiler.opt -o $@

$(PROG).bin: $(PROG).out
@echo creating .bin file...
@ $(OBJCPY) -O binary ${<} ${@}

$(PROG).out: $(OBJECTS) $(NAME)/linker.cmd
@ echo linking...
@ $(LNK) $(OBJECTS) $(LFLAGS) -o $(PROG).out
Expand All @@ -115,16 +136,17 @@ clean:
@ echo Cleaning...
@ $(call remove, $(OBJECTS))
@ $(call remove, $(PROG).out)
@ $(call remove, $(PROG).bin)
@ $(call remove, $(NAME).map)
@ $(RMDIR) $(NAME)

debug: $(PROG).out
debugger: $(PROG).out
# Start gdb
$(CODEGEN_INSTALL_DIR)/bin/arm-none-eabi-gdb --command gdb.command

debugserver:
# Run openocd
/usr/bin/openocd -f /usr/share/openocd/scripts/board/ek-tm4c123gxl.cfg

.PHONY: debug debugserver
.PHONY: debugger debugserver

56 changes: 42 additions & 14 deletions sd_logger.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ var Clock = xdc.useModule('ti.sysbios.knl.Clock');
Clock.tickPeriod = 1000;


/* ================= Debug/Release configuration =========== */
// Read environment variable to see if we are doing a release build or not
var ReleaseBuild = environment["buildtype"] == "release";
if (ReleaseBuild) {
print("Release build requested");
} else {
print("Debug build requested")
}

/* ================ Defaults (module) configuration ================ */
var Defaults = xdc.useModule('xdc.runtime.Defaults');
Expand All @@ -58,8 +66,12 @@ var Defaults = xdc.useModule('xdc.runtime.Defaults');
* section. As a result, Error and Assert messages will contain an
* "unknown module" prefix instead of the actual module name.
*/
Defaults.common$.namedModule = true;
//Defaults.common$.namedModule = false;
if (ReleaseBuild) {
Defaults.common$.namedModule = false;
}
else {
Defaults.common$.namedModule = true;
}



Expand All @@ -79,8 +91,11 @@ var Error = xdc.useModule('xdc.runtime.Error');
* footprint.
* Using Error.policySpin, the Error.raiseHook will NOT called.
*/
Error.policyFxn = Error.policyDefault;
//Error.policyFxn = Error.policySpin;
if (ReleaseBuild) {
Error.policyFxn = Error.policySpin;
} else {
Error.policyFxn = Error.policyDefault;
}
/*
* If Error.policyFxn is set to Error.policyDefault, this function is called
Expand All @@ -96,8 +111,11 @@ Error.policyFxn = Error.policyDefault;
* Errors invoke custom user function. See the Error module documentation
* for more details.
*/
Error.raiseHook = Error.print;
//Error.raiseHook = null;
if (ReleaseBuild) {
Error.raiseHook = null;
} else {
Error.raiseHook = Error.print;
}
//Error.raiseHook = "&myErrorFxn";
/*
Expand Down Expand Up @@ -125,8 +143,11 @@ var m3Hwi = xdc.useModule('ti.sysbios.family.arm.m3.Hwi');
* Disabling the runtime check improves runtime performance and yields a
* reduced flash footprint.
*/
halHwi.checkStackFlag = true;
//halHwi.checkStackFlag = false;
if (ReleaseBuild) {
halHwi.checkStackFlag = false;
} else {
halHwi.checkStackFlag = true;
}
/*
* The following options alter the system's behavior when a hardware exception
Expand All @@ -149,8 +170,11 @@ halHwi.checkStackFlag = true;
* plugging in a default while(1) trap when exception occur. This option
* does not raise an error with the Error module.
*/
m3Hwi.enableException = true;
//m3Hwi.enableException = false;
if (ReleaseBuild) {
m3Hwi.enableException = false;
} else {
m3Hwi.enableException = true;
}
//m3Hwi.excHandlerFunc = null;

/*
Expand Down Expand Up @@ -205,12 +229,16 @@ var BIOS = xdc.useModule('ti.sysbios.BIOS');
* - false
* Disables asserts for a reduced code footprint and better performance.
*/
BIOS.assertsEnabled = true;
//BIOS.assertsEnabled = false;
if (ReleaseBuild) {
BIOS.assertsEnabled = false;
} else {
BIOS.assertsEnabled = true;
}

/*
* Specify default heap size for BIOS.
* Heap is larger to support Sysmin printf.
* TODO: heap size might be able to be decreased in a release build
*/
BIOS.heapSize = 4096;

Expand Down Expand Up @@ -292,15 +320,15 @@ if (!Program.build.target.$name.match(/iar/)) {
* Reducing the system stack size (used by ISRs and Swis) to reduce
* RAM usage.
*/
Program.stack = 512;
Program.stack = 512;
}



/*
* Enable Semihosting for GNU targets to print to CCS console
*/
if (Program.build.target.$name.match(/gnu/)) {
if (Program.build.target.$name.match(/gnu/) && !ReleaseBuild) {
var SemiHost = xdc.useModule('ti.sysbios.rts.gnu.SemiHostSupport');
}

Expand Down

0 comments on commit 9544c6d

Please sign in to comment.