Adding chip usage display after build completion.
- Uses an internal database of microcontroller sizes
This commit is contained in:
parent
38266ca2cc
commit
c424923698
@ -33,6 +33,23 @@ message( "${CHIP}" )
|
||||
set( MCU "${CHIP}" ) # For loading script compatibility
|
||||
|
||||
|
||||
#| Chip Size Database
|
||||
#| Teensy 3.0
|
||||
if ( "${CHIP}" MATCHES "mk20dx128" )
|
||||
set( SIZE_RAM 16384 )
|
||||
set( SIZE_FLASH 131072 )
|
||||
|
||||
#| Teensy 3.1
|
||||
elseif ( "${CHIP}" MATCHES "mk20dx256" )
|
||||
set( SIZE_RAM 65536 )
|
||||
set( SIZE_FLASH 262144 )
|
||||
|
||||
#| Unknown ARM
|
||||
else ()
|
||||
message( AUTHOR_WARNING "CHIP: ${CHIP} - Unknown ARM microcontroller" )
|
||||
endif ()
|
||||
|
||||
|
||||
#| Chip Base Type
|
||||
#| Automatically chosed based on the chip name.
|
||||
if ( "${CHIP}" MATCHES "^mk20dx.*$" )
|
||||
|
@ -36,6 +36,33 @@ message( STATUS "MCU Selected:" )
|
||||
message( "${MCU}" )
|
||||
|
||||
|
||||
#| Chip Size Database
|
||||
#| Teensy 1.0
|
||||
if ( "${CHIP}" MATCHES "at90usb162" )
|
||||
set( SIZE_RAM 512 )
|
||||
set( SIZE_FLASH 15872 )
|
||||
|
||||
#| Teensy 2.0
|
||||
elseif ( "${CHIP}" MATCHES "atmega32u4" )
|
||||
set( SIZE_RAM 2560 )
|
||||
set( SIZE_FLASH 32256 )
|
||||
|
||||
#| Teensy++ 1.0
|
||||
elseif ( "${CHIP}" MATCHES "at90usb646" )
|
||||
set( SIZE_RAM 4096 )
|
||||
set( SIZE_FLASH 64512 )
|
||||
|
||||
#| Teensy++ 2.0
|
||||
elseif ( "${CHIP}" MATCHES "at90usb1286" )
|
||||
set( SIZE_RAM 8192 )
|
||||
set( SIZE_FLASH 130048 )
|
||||
|
||||
#| Unknown AVR
|
||||
else ()
|
||||
message( AUTHOR_WARNING "CHIP: ${CHIP} - Unknown AVR microcontroller" )
|
||||
endif ()
|
||||
|
||||
|
||||
#| Extra Compiler Sources
|
||||
#| Mostly for convenience functions like interrupt handlers
|
||||
set( COMPILER_SRCS
|
||||
|
@ -67,7 +67,6 @@ add_definitions(
|
||||
|
||||
|
||||
|
||||
|
||||
###
|
||||
# Module Processing
|
||||
#
|
||||
@ -286,11 +285,11 @@ add_custom_command( TARGET ${TARGET_ELF} POST_BUILD
|
||||
#
|
||||
|
||||
#| After Changes Size Information
|
||||
#| TODO Do lookup on Flash and RAM sizes and do % used
|
||||
add_custom_target( SizeAfter ALL
|
||||
COMMAND ${CMAKE_SIZE} --target=${FORMAT} ${TARGET_HEX} ${TARGET_ELF}
|
||||
COMMAND ${CMAKE_SOURCE_DIR}/Lib/CMake/sizeCalculator ${CMAKE_SIZE} ${FORMAT} ${TARGET_ELF} ${SIZE_RAM} " SRAM"
|
||||
COMMAND ${CMAKE_SOURCE_DIR}/Lib/CMake/sizeCalculator ${CMAKE_SIZE} ${FORMAT} ${TARGET_HEX} ${SIZE_FLASH} "Flash"
|
||||
DEPENDS ${TARGET_ELF}
|
||||
COMMENT "Size after generation\n\tFlash Usage: data (hex)\n\t RAM Usage: data (elf)"
|
||||
COMMENT "Chip usage for ${CHIP}"
|
||||
)
|
||||
|
||||
|
||||
|
41
Lib/CMake/sizeCalculator
Executable file
41
Lib/CMake/sizeCalculator
Executable file
@ -0,0 +1,41 @@
|
||||
#!/bin/bash
|
||||
#| Jacob Alexander 2014
|
||||
#| Arg List
|
||||
#| 1 - size binary (e.g. avr-size)
|
||||
#| 2 - target binary (e.g. ihex)
|
||||
#| 3 - binary file (e.g. kiibohd.hex)
|
||||
#| 4 - total available (flash/ram) in bytes
|
||||
#| 5 - flash/ram
|
||||
|
||||
|
||||
# Looks for the data column, to get the flash/ram used (in bytes)
|
||||
# <size binary> --target=<target binary> <binary file> | cut -f2 | tail -n 1
|
||||
USED=$("$1" --target="$2" "$3" | cut -f2 | tail -n 1)
|
||||
|
||||
# Calculates the total flash/ram used
|
||||
TOTAL="$4"
|
||||
PERCENTAGE=$((USED * 100 / TOTAL))
|
||||
|
||||
# Size Colours
|
||||
# Red/Flashing - Almost full
|
||||
if (( PERCENTAGE > 95 )); then
|
||||
COLOR="\t\033[1;5;31m"
|
||||
# Red - Getting full
|
||||
elif (( PERCENTAGE > 90 )); then
|
||||
COLOR="\t\033[1;31m"
|
||||
|
||||
# Yellow - Starting to fill up
|
||||
elif (( PERCENTAGE > 50 )); then
|
||||
COLOR="\t\033[1;33m"
|
||||
|
||||
# Green - Lots of room
|
||||
else
|
||||
COLOR="\t\033[1;32m"
|
||||
fi
|
||||
|
||||
# Displays Results
|
||||
NAME="$5"
|
||||
echo -e "\t\033[1m${NAME}\033[m: ${COLOR}${PERCENTAGE}%\033[m ${USED}/${TOTAL}\tbytes"
|
||||
|
||||
exit 0
|
||||
|
Reference in New Issue
Block a user