From c42492369826c742585a6333e08d8e8aeb071443 Mon Sep 17 00:00:00 2001 From: Jacob Alexander Date: Sat, 19 Apr 2014 00:10:28 -0700 Subject: [PATCH] Adding chip usage display after build completion. - Uses an internal database of microcontroller sizes --- Lib/CMake/arm.cmake | 17 +++++++++++++++++ Lib/CMake/avr.cmake | 27 ++++++++++++++++++++++++++ Lib/CMake/modules.cmake | 7 +++---- Lib/CMake/sizeCalculator | 41 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 88 insertions(+), 4 deletions(-) create mode 100755 Lib/CMake/sizeCalculator diff --git a/Lib/CMake/arm.cmake b/Lib/CMake/arm.cmake index 6045afc..c8e5ce6 100644 --- a/Lib/CMake/arm.cmake +++ b/Lib/CMake/arm.cmake @@ -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.*$" ) diff --git a/Lib/CMake/avr.cmake b/Lib/CMake/avr.cmake index b191fe7..f27efb9 100644 --- a/Lib/CMake/avr.cmake +++ b/Lib/CMake/avr.cmake @@ -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 diff --git a/Lib/CMake/modules.cmake b/Lib/CMake/modules.cmake index dad2edb..689725d 100644 --- a/Lib/CMake/modules.cmake +++ b/Lib/CMake/modules.cmake @@ -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}" ) diff --git a/Lib/CMake/sizeCalculator b/Lib/CMake/sizeCalculator new file mode 100755 index 0000000..1bf814e --- /dev/null +++ b/Lib/CMake/sizeCalculator @@ -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) +# --target= | 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 +