@@ -650,21 +650,21 @@ def _get_mem_specs(self, memories, cmsis_part, exception_text):
650
650
raise ConfigException (exception_text )
651
651
652
652
def get_all_active_memories (self , memory_list ):
653
- """Get information of all available rom/ram memories in the form of dictionary
654
- {Memory: [start_addr, size]}. Takes in the argument, a list of all available
653
+ """Get information of all available rom/ram memories in the form of dictionary
654
+ {Memory: [start_addr, size]}. Takes in the argument, a list of all available
655
655
regions within the ram/rom memory"""
656
656
# Override rom_start/rom_size
657
657
#
658
658
# This is usually done for a target which:
659
659
# 1. Doesn't support CMSIS pack, or
660
660
# 2. Supports TrustZone and user needs to change its flash partition
661
-
661
+
662
662
available_memories = {}
663
663
# Counter to keep track of ROM/RAM memories supported by target
664
664
active_memory_counter = 0
665
665
# Find which memory we are dealing with, RAM/ROM
666
666
active_memory = 'ROM' if any ('ROM' in mem_list for mem_list in memory_list ) else 'RAM'
667
-
667
+
668
668
try :
669
669
cmsis_part = self ._get_cmsis_part ()
670
670
except ConfigException :
@@ -683,7 +683,7 @@ def get_all_active_memories(self, memory_list):
683
683
684
684
present_memories = set (cmsis_part ['memory' ].keys ())
685
685
valid_memories = set (memory_list ).intersection (present_memories )
686
-
686
+
687
687
for memory in valid_memories :
688
688
mem_start , mem_size = self ._get_mem_specs (
689
689
[memory ],
@@ -709,7 +709,7 @@ def get_all_active_memories(self, memory_list):
709
709
mem_start = int (mem_start , 0 )
710
710
mem_size = int (mem_size , 0 )
711
711
available_memories [memory ] = [mem_start , mem_size ]
712
-
712
+
713
713
return available_memories
714
714
715
715
@property
@@ -1092,17 +1092,37 @@ def _check_required_parameters(params):
1092
1092
"' doesn't have a value" )
1093
1093
1094
1094
@staticmethod
1095
- def parameters_to_macros (params ):
1096
- """ Encode the configuration parameters as C macro definitions.
1095
+ def _parameters_and_config_macros_to_macros (params , macros ):
1096
+ """ Return the macro definitions generated for a dictionary of
1097
+ ConfigParameters and a dictionary of ConfigMacros (as returned by
1098
+ get_config_data). The ConfigMacros override any matching macros set by
1099
+ the ConfigParameters.
1097
1100
1098
1101
Positional arguments:
1099
1102
params - a dictionary mapping a name to a ConfigParameter
1103
+ macros - a dictionary mapping a name to a ConfigMacro
1100
1104
1101
- Return: a list of strings that encode the configuration parameters as
1102
- C pre-processor macros
1105
+ Return: a list of strings that are the C pre-processor macros
1103
1106
"""
1104
- return ['%s=%s' % (m .macro_name , m .value ) for m in params .values ()
1105
- if m .value is not None ]
1107
+ all_macros = {
1108
+ p .macro_name : p .value for p in params .values () if p .value is not None
1109
+ }
1110
+
1111
+ config_macros = {
1112
+ m .macro_name : m .macro_value for m in macros .values ()
1113
+ }
1114
+
1115
+ all_macros .update (config_macros )
1116
+ macro_list = []
1117
+ for name , value in all_macros .items ():
1118
+ # If the macro does not have a value, just append the name.
1119
+ # Otherwise, append the macro as NAME=VALUE
1120
+ if value is None :
1121
+ macro_list .append (name )
1122
+ else :
1123
+ macro_list .append ("%s=%s" % (name , value ))
1124
+
1125
+ return macro_list
1106
1126
1107
1127
@staticmethod
1108
1128
def config_macros_to_macros (macros ):
@@ -1126,8 +1146,7 @@ def config_to_macros(config):
1126
1146
"""
1127
1147
params , macros = config [0 ], config [1 ]
1128
1148
Config ._check_required_parameters (params )
1129
- return Config .config_macros_to_macros (macros ) + \
1130
- Config .parameters_to_macros (params )
1149
+ return Config ._parameters_and_config_macros_to_macros (params , macros )
1131
1150
1132
1151
def get_config_data_macros (self ):
1133
1152
""" Convert a Config object to a list of C macros
0 commit comments