Show device system information (MCU, Frequency, RAM, Flash, Debugging tools) in a build log

This commit is contained in:
Ivan Kravets
2018-01-25 17:58:52 +02:00
parent dabe9ba2a7
commit f8dafbca80
8 changed files with 82 additions and 20 deletions

View File

@ -7,7 +7,9 @@ PlatformIO 3.0
3.5.2 (2018-??-??)
~~~~~~~~~~~~~~~~~~
* Show all available upload protocols before firmware uploading
* Show device system information (MCU, Frequency, RAM, Flash, Debugging tools)
in a build log
* Show all available upload protocols before firmware uploading in a build log
* Handle "os.mbed.com" URL as a Mercurial (hg) repository
* Improved support for old mbed libraries without manifest
* Fixed issue with duplicated "include" records when generating data for IDE

2
docs

Submodule docs updated: a65d042693...ec9ec10dcd

View File

@ -184,7 +184,8 @@ if "idedata" in COMMAND_LINE_TARGETS:
env.Exit(1)
def print_upload_protocols_info(source, target, env):
def print_upload_protocols_info( # pylint: disable=unused-argument
source, target, _):
selected = env.subst("$UPLOAD_PROTOCOL")
available = env.BoardConfig().get("upload", {}).get(
"protocols", [selected])

View File

@ -41,8 +41,9 @@ def PioPlatform(env):
def BoardConfig(env, board=None):
p = initPioPlatform(env['PLATFORM_MANIFEST'])
try:
assert env.get("BOARD", board), "BoardConfig: Board is not defined"
config = p.board_config(board if board else env.get("BOARD"))
board = board or env.get("BOARD")
assert board, "BoardConfig: Board is not defined"
config = p.board_config(board)
except (AssertionError, exception.UnknownBoard) as e:
sys.stderr.write("Error: %s\n" % str(e))
env.Exit(1)
@ -97,6 +98,50 @@ def LoadPioPlatform(env, variables):
env.Replace(LDSCRIPT_PATH=board_config.get("build.ldscript"))
def PrintSystemInfo(env):
data = []
debug_tools = None
mcu = env.subst("$BOARD_MCU")
f_cpu = env.subst("$BOARD_F_CPU")
if mcu:
data.append(mcu.upper())
if f_cpu:
f_cpu = int("".join([c for c in str(f_cpu) if c.isdigit()]))
data.append("%dMHz" % (f_cpu / 1000000))
if "BOARD" in env:
board_config = env.BoardConfig()
debug_tools = board_config.get("debug", {}).get("tools")
ram = board_config.get("upload", {}).get("maximum_ram_size")
flash = board_config.get("upload", {}).get("maximum_size")
for (key, value) in (("RAM", ram), ("Flash", flash)):
if not value:
continue
data.append("%s/%s" % (key, util.format_filesize(value)))
if data:
print "System: %s" % " ".join(data)
# Debugging
if not debug_tools:
return
data = []
onboard = []
external = []
for key, value in debug_tools.items():
if value.get("onboard"):
onboard.append(key)
else:
external.append(key)
if onboard:
data.append("ON-BORD(%s)" % ", ".join(sorted(onboard)))
if external:
data.append("EXTERNAL(%s)" % ", ".join(sorted(external)))
print "Debug: %s" % " ".join(data)
def exists(_):
return True
@ -106,4 +151,5 @@ def generate(env):
env.AddMethod(BoardConfig)
env.AddMethod(GetFrameworkScript)
env.AddMethod(LoadPioPlatform)
env.AddMethod(PrintSystemInfo)
return env

View File

@ -42,6 +42,8 @@ def BuildProgram(env):
_append_pio_macros()
env.PrintSystemInfo()
# fix ASM handling under non-casitive OS
if not case_sensitive_suffixes(".s", ".S"):
env.Replace(AS="$CC", ASCOM="$ASPPCOM")

View File

@ -16,6 +16,7 @@ import json
import click
from platformio import util
from platformio.managers.platform import PlatformManager
@ -60,22 +61,13 @@ def print_boards(boards):
click.echo("-" * terminal_width)
for board in boards:
ram_size = board['ram']
if ram_size >= 1024:
if ram_size % 1024:
ram_size = "%.1fkB" % (ram_size / 1024.0)
else:
ram_size = "%dkB" % (ram_size / 1024)
else:
ram_size = "%dB" % ram_size
click.echo(
BOARDLIST_TPL.format(
type=click.style(board['id'], fg="cyan"),
mcu=board['mcu'],
frequency="%dMhz" % (board['fcpu'] / 1000000),
flash="%dkB" % (board['rom'] / 1024),
ram=ram_size,
frequency="%dMHz" % (board['fcpu'] / 1000000),
flash=util.format_filesize(board['rom']),
ram=util.format_filesize(board['ram']),
name=board['name']))

View File

@ -684,9 +684,11 @@ class PlatformBoardConfig(object):
"mcu":
self._manifest.get("build", {}).get("mcu", "").upper(),
"fcpu":
int(
re.sub(r"[^\d]+", "",
self._manifest.get("build", {}).get("f_cpu", "0L"))),
int("".join([
c for c in str(
self._manifest.get("build", {}).get("f_cpu", "0L"))
if c.isdigit()
])),
"ram":
self._manifest.get("upload", {}).get("maximum_ram_size", 0),
"rom":

View File

@ -743,6 +743,23 @@ def parse_date(datestr):
return time.strptime(datestr)
def format_filesize(filesize):
base = 1024
unit = 0
suffix = "B"
filesize = float(filesize)
if filesize < base:
return "%d%s" % (filesize, suffix)
for i, suffix in enumerate("KMGTPEZY"):
unit = base**(i + 2)
if filesize >= unit:
continue
if filesize % (base**(i + 1)):
return "%.2f%s" % ((base * filesize / unit), suffix)
break
return "%d%s" % ((base * filesize / unit), suffix)
def rmtree_(path):
def _onerror(_, name, __):