|
14 | 14 | See the License for the specific language governing permissions and
|
15 | 15 | limitations under the License.
|
16 | 16 | """
|
17 |
| -from exporters import Exporter |
18 |
| -from os.path import basename |
| 17 | +from os.path import basename, join, dirname |
| 18 | +from project_generator_definitions.definitions import ProGenDef |
19 | 19 |
|
| 20 | +from workspace_tools.export.exporters import Exporter |
| 21 | +from workspace_tools.targets import TARGET_MAP, TARGET_NAMES |
20 | 22 |
|
| 23 | +# If you wish to add a new target, add it to project_generator_definitions, and then |
| 24 | +# define progen_target name in the target class (`` self.progen_target = 'my_target_name' ``) |
| 25 | +# There are 2 default mbed templates (predefined settings) uvision.uvproj and uvproj_microlib.uvproj.tmpl |
21 | 26 | class Uvision4(Exporter):
|
| 27 | + """ |
| 28 | + Exporter class for uvision. This class uses project generator. |
| 29 | + """ |
| 30 | + # These 2 are currently for exporters backward compatiblity |
22 | 31 | NAME = 'uVision4'
|
| 32 | + TOOLCHAIN = 'ARM' |
| 33 | + # PROGEN_ACTIVE contains information for exporter scripts that this is using progen |
| 34 | + PROGEN_ACTIVE = True |
23 | 35 |
|
24 |
| - TARGETS = [ |
25 |
| - 'LPC1768', |
26 |
| - 'LPC11U24', |
27 |
| - 'LPC11U35_401', |
28 |
| - 'LPC11U35_501', |
29 |
| - 'KL05Z', |
30 |
| - 'KL25Z', |
31 |
| - 'KL43Z', |
32 |
| - 'KL46Z', |
33 |
| - 'K64F', |
34 |
| - 'K22F', |
35 |
| - 'K20D50M', |
36 |
| - 'TEENSY3_1', |
37 |
| - 'LPC1347', |
38 |
| - 'LPC1114', |
39 |
| - 'LPC11C24', |
40 |
| - 'LPC4088', |
41 |
| - 'LPC4088_DM', |
42 |
| - 'LPC4330_M4', |
43 |
| - 'LPC4337', |
44 |
| - 'LPC812', |
45 |
| - 'LPC824', |
46 |
| - 'SSCI824', |
47 |
| - 'NUCLEO_F030R8', |
48 |
| - 'NUCLEO_F031K6', |
49 |
| - 'NUCLEO_F042K6', |
50 |
| - 'NUCLEO_F070RB', |
51 |
| - 'NUCLEO_F072RB', |
52 |
| - 'NUCLEO_F091RC', |
53 |
| - 'NUCLEO_F103RB', |
54 |
| - 'NUCLEO_F302R8', |
55 |
| - 'NUCLEO_F303K8', |
56 |
| - 'NUCLEO_F303RE', |
57 |
| - 'NUCLEO_F334R8', |
58 |
| - 'NUCLEO_F401RE', |
59 |
| - 'NUCLEO_F410RB', |
60 |
| - 'NUCLEO_F411RE', |
61 |
| - 'NUCLEO_F446RE', |
62 |
| - 'NUCLEO_F746ZG', |
63 |
| - 'NUCLEO_L053R8', |
64 |
| - 'NUCLEO_L073RZ', |
65 |
| - 'NUCLEO_L152RE', |
66 |
| - 'NUCLEO_L476RG', |
67 |
| - 'B96B_F446VE', |
68 |
| - 'UBLOX_C027', |
69 |
| - 'LPC1549', |
70 |
| - 'LPC11U68', |
71 |
| - # Removed as uvision4_lpc11u35_501.uvproj.tmpl is missing. |
72 |
| - #'LPC11U35_501', |
73 |
| - 'NRF51822', |
74 |
| - 'HRM1017', |
75 |
| - 'RBLAB_NRF51822', |
76 |
| - 'ARCH_PRO', |
77 |
| - 'ARCH_BLE', |
78 |
| - 'DISCO_F051R8', |
79 |
| - 'DISCO_F100RB', |
80 |
| - 'DISCO_F303VC', |
81 |
| - 'DISCO_F407VG', |
82 |
| - 'DISCO_F429ZI', |
83 |
| - 'DISCO_F469NI', |
84 |
| - 'DISCO_L053C8', |
85 |
| - 'DISCO_F334C8', |
86 |
| - 'DISCO_F746NG', |
87 |
| - 'DISCO_L476VG', |
88 |
| - 'MTS_GAMBIT', |
89 |
| - 'ARCH_MAX', |
90 |
| - 'MTS_MDOT_F405RG', |
91 |
| - 'NRF51_DK', |
92 |
| - 'NRF51_DONGLE', |
93 |
| - 'SEEED_TINY_BLE', |
94 |
| - 'LPC11U37H_401', |
95 |
| - 'DELTA_DFCM_NNN40', |
96 |
| - 'MAXWSNENV', |
97 |
| - 'MAX32600MBED', |
98 |
| - 'MOTE_L152RC', |
99 |
| - 'NZ32_SC151', |
100 |
| - 'SAMR21G18A', |
101 |
| - 'SAMD21J18A', |
102 |
| - 'SAMD21G18A', |
103 |
| - 'SAML21J18A', |
104 |
| - ] |
| 36 | + # backward compatibility with our scripts |
| 37 | + TARGETS = [] |
| 38 | + for target in TARGET_NAMES: |
| 39 | + try: |
| 40 | + if (ProGenDef('uvision').is_supported(str(TARGET_MAP[target])) or |
| 41 | + ProGenDef('uvision').is_supported(TARGET_MAP[target].progen['target'])): |
| 42 | + TARGETS.append(target) |
| 43 | + except AttributeError: |
| 44 | + # target is not supported yet |
| 45 | + continue |
105 | 46 |
|
106 |
| - USING_MICROLIB = [ |
107 |
| - 'LPC11U24', |
108 |
| - 'LPC11U35_401', |
109 |
| - 'LPC11U35_501', |
110 |
| - 'LPC1114', |
111 |
| - 'LPC11C24', |
112 |
| - 'LPC812', |
113 |
| - 'LPC824', |
114 |
| - 'SSCI824', |
115 |
| - 'NUCLEO_F030R8', |
116 |
| - 'NUCLEO_F031K6', |
117 |
| - 'NUCLEO_F042K6', |
118 |
| - 'NUCLEO_F070RB', |
119 |
| - 'NUCLEO_F072RB', |
120 |
| - 'NUCLEO_F091RC', |
121 |
| - 'NUCLEO_F103RB', |
122 |
| - 'NUCLEO_F302R8', |
123 |
| - 'NUCLEO_F303K8', |
124 |
| - 'NUCLEO_F303RE', |
125 |
| - 'NUCLEO_F334R8', |
126 |
| - 'NUCLEO_F401RE', |
127 |
| - 'NUCLEO_F410RB', |
128 |
| - 'NUCLEO_F411RE', |
129 |
| - 'NUCLEO_F446RE', |
130 |
| - 'NUCLEO_F746ZG', |
131 |
| - 'NUCLEO_L053R8', |
132 |
| - 'NUCLEO_L073RZ', |
133 |
| - 'NUCLEO_L152RE', |
134 |
| - 'NUCLEO_L476RG', |
135 |
| - 'DISCO_F051R8', |
136 |
| - 'DISCO_F100RB', |
137 |
| - 'DISCO_F334C8', |
138 |
| - 'DISCO_F429ZI', |
139 |
| - 'DISCO_F469NI', |
140 |
| - 'DISCO_L053C8', |
141 |
| - 'DISCO_L476VG', |
142 |
| - 'B96B_F446VE', |
143 |
| - 'DISCO_F407VG', |
144 |
| - 'DISCO_F303VC', |
145 |
| - 'LPC1549', |
146 |
| - 'LPC11U68', |
147 |
| - 'LPC11U35_501', |
148 |
| - 'KL05Z', |
149 |
| - 'LPC11U37H_401', |
150 |
| - 'MOTE_L152RC', |
151 |
| - 'NZ32_SC151', |
152 |
| - 'SAMR21G18A', |
153 |
| - 'SAMD21J18A', |
154 |
| - 'SAMD21G18A', |
155 |
| - 'SAML21J18A', |
156 |
| - 'ARM_IOTSS_BEID', |
157 |
| - 'ARM_MPS2_M0', |
158 |
| - 'ARM_MPS2_M0P', |
159 |
| - 'ARM_MPS2_M3', |
160 |
| - 'ARM_MPS2_M4', |
161 |
| - 'ARM_MPS2_M7', |
162 |
| - ] |
163 | 47 |
|
164 |
| - FILE_TYPES = { |
165 |
| - 'c_sources':'1', |
166 |
| - 'cpp_sources':'8', |
167 |
| - 's_sources':'2' |
168 |
| - } |
169 |
| - |
170 |
| - FLAGS = [ |
171 |
| - "--gnu", "--no_rtti", |
172 |
| - ] |
173 |
| - |
174 |
| - # By convention uVision projects do not show header files in the editor: |
175 |
| - # 'headers':'5', |
176 |
| - |
177 |
| - def get_toolchain(self): |
178 |
| - return 'uARM' if (self.target in self.USING_MICROLIB) else 'ARM' |
| 48 | + def generate(self): |
| 49 | + """ Generates the project files """ |
| 50 | + project_data = self.progen_get_project_data() |
| 51 | + tool_specific = {} |
| 52 | + # Expand tool specific settings by uvision specific settings which are required |
| 53 | + try: |
| 54 | + if TARGET_MAP[self.target].progen['uvision']['template']: |
| 55 | + tool_specific['uvision'] = TARGET_MAP[self.target].progen['uvision'] |
| 56 | + except KeyError: |
| 57 | + # use default template |
| 58 | + # by the mbed projects |
| 59 | + tool_specific['uvision'] = { |
| 60 | + 'template': [join(dirname(__file__), 'uvision.uvproj.tmpl')], |
| 61 | + } |
179 | 62 |
|
180 |
| - def get_flags(self): |
181 |
| - return self.FLAGS |
| 63 | + project_data['tool_specific'] = {} |
| 64 | + project_data['tool_specific'].update(tool_specific) |
| 65 | + # armasm does not like floating numbers in macros, timestamp to int |
| 66 | + i = 0 |
| 67 | + for macro in project_data['common']['macros']: |
| 68 | + if macro.startswith('MBED_BUILD_TIMESTAMP'): |
| 69 | + timestamp = macro[len('MBED_BUILD_TIMESTAMP='):] |
| 70 | + project_data['common']['macros'][i] = 'MBED_BUILD_TIMESTAMP=' + str(int(float(timestamp))) |
| 71 | + break |
| 72 | + i += 1 |
| 73 | + project_data['common']['macros'].append('__ASSERT_MSG') |
| 74 | + self.progen_gen_file('uvision', project_data) |
182 | 75 |
|
183 |
| - def generate(self): |
184 |
| - source_files = { |
185 |
| - 'mbed': [], |
186 |
| - 'hal': [], |
187 |
| - 'src': [] |
188 |
| - } |
189 |
| - for r_type, n in Uvision4.FILE_TYPES.iteritems(): |
190 |
| - for file in getattr(self.resources, r_type): |
191 |
| - f = {'name': basename(file), 'type': n, 'path': file} |
192 |
| - if file.startswith("mbed\\common"): |
193 |
| - source_files['mbed'].append(f) |
194 |
| - elif file.startswith("mbed\\targets"): |
195 |
| - source_files['hal'].append(f) |
196 |
| - else: |
197 |
| - source_files['src'].append(f) |
198 |
| - source_files = dict( [(k,v) for k,v in source_files.items() if len(v)>0]) |
199 |
| - ctx = { |
200 |
| - 'name': self.program_name, |
201 |
| - 'include_paths': self.resources.inc_dirs, |
202 |
| - 'scatter_file': self.resources.linker_script, |
203 |
| - 'object_files': self.resources.objects + self.resources.libraries, |
204 |
| - 'source_files': source_files.items(), |
205 |
| - 'symbols': self.get_symbols() + ['__ASSERT_MSG'], |
206 |
| - 'hex_files' : self.resources.hex_files, |
207 |
| - 'flags' : self.get_flags(), |
208 |
| - } |
209 |
| - target = self.target.lower() |
210 |
| - # Project file |
211 |
| - self.gen_file('uvision4_%s.uvproj.tmpl' % target, ctx, '%s.uvproj' % self.program_name) |
212 |
| - self.gen_file('uvision4_%s.uvopt.tmpl' % target, ctx, '%s.uvopt' % self.program_name) |
0 commit comments