Skip to content

Commit

Permalink
Two more comments
Browse files Browse the repository at this point in the history
  • Loading branch information
multiplemonomials committed Sep 12, 2024
1 parent 13ed6ec commit ef4cfbd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 21 deletions.
33 changes: 13 additions & 20 deletions tools/python/mbed_tools/build/_internal/memory_banks.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
if TYPE_CHECKING:
from typing import Dict, Any, Set, TypedDict, NotRequired

import pathlib
import copy
import json
import logging

import humanize

from mbed_tools.lib.json_helpers import decode_json_file
from mbed_tools.project import MbedProgram

Expand All @@ -34,7 +34,7 @@ class MemoryBankInfo(TypedDict):
default: NotRequired[bool]
startup: NotRequired[bool]
access: Dict[str, bool]


class BanksByType(TypedDict):
"""
Expand All @@ -57,6 +57,9 @@ class BanksByType(TypedDict):
}


BANK_TYPES = ("RAM", "ROM")


def incorporate_memory_bank_data_from_cmsis(target_attributes: Dict[str, Any],
program: MbedProgram) -> None:
"""
Expand Down Expand Up @@ -121,18 +124,6 @@ def _apply_configured_overrides(banks_by_type: BanksByType, bank_config: Dict[st
return configured_memory_banks


def _pretty_print_size(size: int) -> str:
"""
Pretty-print a memory size as MiB/KiB/B
"""
if size >= 1024*1024 and (size % (1024*1024)) == 0:
return f"{size//(1024*1024)} MiB"
elif size >= 1024 and (size % 1024) == 0:
return f"{size//1024} kiB"
else:
return f"{size} B"


def _print_mem_bank_summary(banks_by_type: BanksByType, configured_banks_by_type: BanksByType) -> None:

"""
Expand All @@ -142,7 +133,8 @@ def _print_mem_bank_summary(banks_by_type: BanksByType, configured_banks_by_type
"""

print("Summary of available memory banks:")
for bank_type, banks in banks_by_type.items():
for bank_type in BANK_TYPES:
banks = banks_by_type[bank_type]

if len(banks) == 0:
logger.warning("No %s banks are known to the Mbed configuration system! This can cause problems with "
Expand All @@ -164,19 +156,19 @@ def _print_mem_bank_summary(banks_by_type: BanksByType, configured_banks_by_type
configured_size_str = ""
configured_start_addr_str = ""
if configured_size != bank_size:
configured_size_str = f" (configured to {_pretty_print_size(configured_size)})"
configured_size_str = f" (configured to {humanize.naturalsize(configured_size, binary=True)})"
if configured_start_addr != bank_start:
configured_start_addr_str = f" (configured to 0x{configured_start_addr:08x})"

print(f"{bank_index}. {bank_name}, "
f"start addr 0x{bank_start:08x}{configured_start_addr_str}, "
f"size {_pretty_print_size(bank_size)}{configured_size_str}")
f"size {humanize.naturalsize(bank_size, binary=True)}{configured_size_str}")

print()


def _generate_macros_for_memory_banks(banks_by_type: BanksByType,
configured_banks_by_type: BanksByType) -> Set[str]:
configured_banks_by_type: BanksByType) -> Set[str]:

"""
Generate a set of macros to define to pass the memory bank information into Mbed.
Expand All @@ -185,7 +177,8 @@ def _generate_macros_for_memory_banks(banks_by_type: BanksByType,
"""
all_macros: Set[str] = set()

for bank_type, banks in banks_by_type.items():
for bank_type in BANK_TYPES:
banks = banks_by_type[bank_type]

for bank_index, (bank_name, bank_data) in enumerate(banks.items()):

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def test_simple_memory_layout(self):
}
}

print(repr(process_memory_banks(config)))
process_memory_banks(config)

assert config["memory_bank_macros"] == {
# New style definitions (ROM)
Expand Down

0 comments on commit ef4cfbd

Please sign in to comment.