Skip to content

Commit

Permalink
Build elf
Browse files Browse the repository at this point in the history
  • Loading branch information
dzid26 committed Jun 4, 2024
1 parent 75bb929 commit df5bb76
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ This project is being developed and maintained for free by a community of users.
1. Clone this repository
2. Install the SDCC compiler

## Debugging
- You can use [STMStdudio](https://www.st.com/en/development-tools/stm-studio-stm8.html) to plot global variables in real-time

### Compile the firmware
`cd src/controller/` and use `make` or `compile.bat` to compile the firmware.

Expand Down
20 changes: 9 additions & 11 deletions src/controller/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#Compiler
CC = sdcc --verbose
OBJCOPY = stm8-objcopy
OBJCOPY = objcopy
SIZE = stm8-size

#Platform
Expand All @@ -29,8 +29,6 @@ IDIR1 = ../common
# In case you ever want a different name for the main source file
MAINSRC = $(PNAME).c

ELF_SECTIONS_TO_REMOVE = -R DATA -R INITIALIZED -R SSEG -R .debug_line -R .debug_loc -R .debug_abbrev -R .debug_info -R .debug_pubnames -R .debug_frame

# These are the sources that must be compiled to .rel files:
EXTRASRCS = \
$(SDIR)/stm8s_iwdg.c \
Expand Down Expand Up @@ -67,7 +65,7 @@ RELS = $(addprefix $(ODIR)/,$(notdir $(EXTRASRCS:.c=.rel)))

override INCLUDES += -I$(IDIR) -I$(IDIR1)
override CFLAGS += -m$(PLATFORM) -D$(DEVICE) -Ddouble=float --std-c99 --nolospre --opt-code-speed --peep-asm --peep-file peep.txt
override DEBUG_FLAGS += --out-fmt-ihx --debug
override DEBUG_FLAGS += --out-fmt-elf --debug
LIBS =

# This just provides the conventional target name "all"; it is optional
Expand All @@ -77,10 +75,9 @@ all: mkdir $(PNAME)

# How to build the overall program
$(PNAME): $(MAINSRC) $(RELS)
$(CC) $(INCLUDES) $(CFLAGS) $(DEBUG_FLAGS) $(LIBS) $(MAINSRC) $(RELS) -o$(ODIR)/
# $(SIZE) $(PNAME).elf
# $(OBJCOPY) -O binary $(ELF_SECTIONS_TO_REMOVE) $(PNAME).elf $(PNAME).bin
# $(OBJCOPY) -O ihex $(ELF_SECTIONS_TO_REMOVE) $(PNAME).elf $(PNAME).hex
$(CC) $(INCLUDES) $(CFLAGS) $(DEBUG_FLAGS) $(LIBS) $(MAINSRC) $(RELS) -o$(ODIR)/$(PNAME).elf

$(OBJCOPY) -O ihex -g $(ELF_SECTIONS_TO_REMOVE) $(ODIR)/$(PNAME).elf $(ODIR)/$(PNAME).hex

#Rules for firmware sources
$(ODIR)/%.rel: %.c $(HEADERS)
Expand All @@ -96,9 +93,6 @@ $(ODIR)/%.rel: $(SDIR)/%.c
# Necessary because .rel is not one of the standard suffixes.
.SUFFIXES: .c .rel

# hex:
# @cd $(ODIR)
# $(OBJCOPY) -O ihex $(ELF_SECTIONS_TO_REMOVE) $(PNAME).elf $(PNAME).ihx*

backup:
stm8flash -c stlinkv2 -p stm8s105?6 -s opt -r $(ODIR)/TSDZ_orig_opt.bin
Expand All @@ -118,3 +112,7 @@ clean:

mkdir:
mkdir -p $(ODIR)


# debug_make:
# $(foreach var,$(.VARIABLES),$(info $(var) = $($(var))))
Binary file added tools/cygwin/bin/objcopy.exe
Binary file not shown.

0 comments on commit df5bb76

Please sign in to comment.