Skip to content

Commit

Permalink
Calculate and print stack size on AVR builds
Browse files Browse the repository at this point in the history
  • Loading branch information
drashna committed Jul 14, 2024
1 parent c738804 commit a6aa100
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions builddefs/message.mk
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,10 @@ endef
MSG_AVAILABLE_KEYMAPS = $(eval $(call GENERATE_MSG_AVAILABLE_KEYMAPS))$(MSG_AVAILABLE_KEYMAPS_ACTUAL)

MSG_BOOTLOADER_NOT_FOUND_BASE = Bootloader not found. Make sure the board is in bootloader mode. See https://docs.qmk.fm/\#/newbs_flashing\n
MSG_CHECK_STACKSIZE = Checking stack size of $(TARGET)
MSG_CHECK_FILESIZE = Checking file size of $(TARGET).$(FIRMWARE_FORMAT)
MSG_MEMORY_OVERFLOW = $(ERROR_COLOR)RAM usage (not including stack) exceeds available RAM by $(RAM_OVERFLOW_AMOUNT) bytes\n
MSG_STACK_SIZE = Available stack size: $(STACK_SIZE) bytes\n
MSG_FILE_TOO_BIG = $(ERROR_COLOR)The firmware is too large!$(NO_COLOR) $(CURRENT_SIZE)/$(MAX_SIZE) ($(OVER_SIZE) bytes over)\n
MSG_FILE_TOO_SMALL = The firmware is too small! $(CURRENT_SIZE)/$(MAX_SIZE)\n
MSG_FILE_JUST_RIGHT = The firmware size is fine - $(CURRENT_SIZE)/$(MAX_SIZE) ($(PERCENT_SIZE)%%, $(FREE_SIZE) bytes free)\n
Expand Down
12 changes: 12 additions & 0 deletions platforms/avr/platform.mk
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,18 @@ check-size:
fi ; \
fi ; \
fi
$(eval END_POINTER=$(shell printf "%d" $$(( 0xffff & 0x$$( if [ -f $(BUILD_DIR)/$(TARGET).elf ]; then avr-objdump -t $(BUILD_DIR)/$(TARGET).elf | grep -e '\b_end\b' | cut -c -8; else printf 0; fi ) )) ))
$(eval STACK_POINTER=$(shell printf "%d" $$(( 0xffff & 0x$$( if [ -f $(BUILD_DIR)/$(TARGET).elf ]; then avr-objdump -t $(BUILD_DIR)/$(TARGET).elf | grep -e '\b__stack\b' | cut -c -8; else printf 0; fi ) )) ))
$(eval STACK_SIZE=$(shell expr $(STACK_POINTER) + 1 - $(END_POINTER)))
$(eval RAM_OVERFLOW_AMOUNT=$(shell expr 0 - $(STACK_SIZE)))
if [ $(STACK_POINTER) -gt 0 ] && [ $(END_POINTER) -gt 0 ]; then \
$(SILENT) || printf "$(MSG_CHECK_STACKSIZE)" | $(AWK_CMD); \
if [ $(STACK_SIZE) -lt 0 ] ; then \
printf "\n * $(MSG_MEMORY_OVERFLOW)"; $(PRINT_ERROR_PLAIN); \
else \
$(SILENT) || printf "\n * $(MSG_STACK_SIZE)"; \
fi ; \
fi

# Convert hex to bin.
bin: $(BUILD_DIR)/$(TARGET).hex
Expand Down

0 comments on commit a6aa100

Please sign in to comment.