2013-08-06 13:38:00 +00:00
|
|
|
"""
|
|
|
|
mbed SDK
|
|
|
|
Copyright (c) 2011-2013 ARM Limited
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
"""
|
2015-03-25 13:43:06 +00:00
|
|
|
from workspace_tools.export.exporters import Exporter
|
2015-03-05 14:58:24 +00:00
|
|
|
import re
|
2015-03-25 12:03:50 +00:00
|
|
|
import os
|
2013-02-18 15:32:11 +00:00
|
|
|
class IAREmbeddedWorkbench(Exporter):
|
2015-03-25 13:43:06 +00:00
|
|
|
"""
|
|
|
|
Exporter class for IAR Systems.
|
|
|
|
"""
|
2013-02-18 15:32:11 +00:00
|
|
|
NAME = 'IAR'
|
|
|
|
TOOLCHAIN = 'IAR'
|
2014-05-29 13:42:03 +00:00
|
|
|
|
2014-03-18 10:52:34 +00:00
|
|
|
TARGETS = [
|
|
|
|
'LPC1768',
|
2014-10-27 12:21:44 +00:00
|
|
|
'LPC1347',
|
2014-11-18 13:54:40 +00:00
|
|
|
'LPC11U24',
|
|
|
|
'LPC11U35_401',
|
|
|
|
'LPC11U35_501',
|
2015-02-20 14:59:16 +00:00
|
|
|
#Removed LPCCAPPUCCINO linker file and startup file missing
|
|
|
|
#'LPCCAPPUCCINO',
|
2014-11-18 15:01:34 +00:00
|
|
|
'LPC1114',
|
2014-11-18 15:09:38 +00:00
|
|
|
'LPC1549',
|
2014-11-18 15:19:26 +00:00
|
|
|
'LPC812',
|
|
|
|
'LPC4088',
|
2015-02-08 10:56:39 +00:00
|
|
|
'LPC4088_DM',
|
2015-03-04 12:49:44 +00:00
|
|
|
'LPC824',
|
2014-05-27 15:21:27 +00:00
|
|
|
'UBLOX_C027',
|
2014-05-28 09:54:42 +00:00
|
|
|
'ARCH_PRO',
|
2014-10-29 16:44:38 +00:00
|
|
|
'K20D50M',
|
2014-10-30 11:38:53 +00:00
|
|
|
'KL05Z',
|
2014-10-30 09:43:53 +00:00
|
|
|
'KL25Z',
|
2014-10-30 12:14:10 +00:00
|
|
|
'KL46Z',
|
2014-10-30 17:29:24 +00:00
|
|
|
'K22F',
|
2014-10-30 18:07:44 +00:00
|
|
|
'K64F',
|
2014-11-07 08:49:42 +00:00
|
|
|
'NUCLEO_F030R8',
|
2015-09-11 13:11:35 +00:00
|
|
|
'NUCLEO_F031K6',
|
2015-10-01 12:03:52 +00:00
|
|
|
'NUCLEO_F042K6',
|
2014-12-18 08:30:19 +00:00
|
|
|
'NUCLEO_F070RB',
|
2014-11-07 08:49:42 +00:00
|
|
|
'NUCLEO_F072RB',
|
|
|
|
'NUCLEO_F091RC',
|
2014-12-02 06:51:14 +00:00
|
|
|
'NUCLEO_F103RB',
|
2014-10-28 09:17:38 +00:00
|
|
|
'NUCLEO_F302R8',
|
2015-10-12 09:34:06 +00:00
|
|
|
'NUCLEO_F303K8',
|
2014-12-02 06:51:14 +00:00
|
|
|
'NUCLEO_F303RE',
|
2014-10-31 12:40:36 +00:00
|
|
|
'NUCLEO_F334R8',
|
2014-10-27 10:20:08 +00:00
|
|
|
'NUCLEO_F401RE',
|
2015-10-27 12:50:52 +00:00
|
|
|
'NUCLEO_F410RB',
|
2014-10-15 13:00:35 +00:00
|
|
|
'NUCLEO_F411RE',
|
2015-08-17 12:37:28 +00:00
|
|
|
'NUCLEO_F446RE',
|
2014-11-05 09:42:44 +00:00
|
|
|
'NUCLEO_L053R8',
|
2015-03-16 13:43:51 +00:00
|
|
|
'NUCLEO_L073RZ',
|
2014-10-27 16:23:06 +00:00
|
|
|
'NUCLEO_L152RE',
|
2015-09-23 09:32:38 +00:00
|
|
|
'NUCLEO_L476RG',
|
2015-11-09 09:59:13 +00:00
|
|
|
'DISCO_F429ZI',
|
2015-04-30 10:57:14 +00:00
|
|
|
'DISCO_L053C8',
|
2015-05-18 14:19:33 +00:00
|
|
|
'DISCO_F334C8',
|
2015-10-21 14:26:06 +00:00
|
|
|
'DISCO_F469NI',
|
2015-06-18 09:16:09 +00:00
|
|
|
'DISCO_F746NG',
|
2015-07-28 08:30:26 +00:00
|
|
|
'DISCO_L476VG',
|
2016-01-05 16:24:31 +00:00
|
|
|
'B96B_F446VE',
|
2015-02-20 14:59:16 +00:00
|
|
|
#'STM32F407', Fails to build same for GCC
|
2015-04-09 17:55:08 +00:00
|
|
|
'MAXWSNENV',
|
|
|
|
'MAX32600MBED',
|
2014-11-12 22:21:13 +00:00
|
|
|
'MTS_MDOT_F405RG',
|
2014-12-05 23:34:38 +00:00
|
|
|
'MTS_MDOT_F411RE',
|
2014-11-14 17:29:46 +00:00
|
|
|
'MTS_DRAGONFLY_F411RE',
|
2015-02-04 10:29:31 +00:00
|
|
|
'NRF51822',
|
2015-03-02 09:38:46 +00:00
|
|
|
'NRF51_DK',
|
|
|
|
'NRF51_DONGLE',
|
|
|
|
'DELTA_DFCM_NNN40',
|
|
|
|
'SEEED_TINY_BLE',
|
|
|
|
'HRM1017',
|
|
|
|
'ARCH_BLE',
|
2015-04-23 07:55:29 +00:00
|
|
|
'MOTE_L152RC',
|
2015-12-23 09:48:13 +00:00
|
|
|
'EFM32PG_STK3401',
|
2014-03-18 10:52:34 +00:00
|
|
|
]
|
2014-05-29 13:42:03 +00:00
|
|
|
|
2013-02-18 15:32:11 +00:00
|
|
|
def generate(self):
|
2015-03-25 13:43:06 +00:00
|
|
|
"""
|
|
|
|
Generates the project files
|
|
|
|
"""
|
2014-10-10 08:40:23 +00:00
|
|
|
sources = []
|
|
|
|
sources += self.resources.c_sources
|
|
|
|
sources += self.resources.cpp_sources
|
|
|
|
sources += self.resources.s_sources
|
2015-03-25 13:43:06 +00:00
|
|
|
|
|
|
|
iar_files = IarFolder("", "", [])
|
2015-03-05 14:58:24 +00:00
|
|
|
for source in sources:
|
|
|
|
iar_files.insert_file(source)
|
2015-03-25 13:43:06 +00:00
|
|
|
|
2013-02-18 15:32:11 +00:00
|
|
|
ctx = {
|
|
|
|
'name': self.program_name,
|
|
|
|
'include_paths': self.resources.inc_dirs,
|
|
|
|
'linker_script': self.resources.linker_script,
|
|
|
|
'object_files': self.resources.objects,
|
|
|
|
'libraries': self.resources.libraries,
|
2014-11-11 14:56:26 +00:00
|
|
|
'symbols': self.get_symbols(),
|
2015-03-05 14:58:24 +00:00
|
|
|
'source_files': iar_files.__str__(),
|
2015-03-02 09:38:46 +00:00
|
|
|
'binary_files': self.resources.bin_files,
|
2013-02-18 15:32:11 +00:00
|
|
|
}
|
2014-10-10 08:40:23 +00:00
|
|
|
self.gen_file('iar_%s.ewp.tmpl' % self.target.lower(), ctx, '%s.ewp' % self.program_name)
|
2013-02-18 15:32:11 +00:00
|
|
|
self.gen_file('iar.eww.tmpl', ctx, '%s.eww' % self.program_name)
|
2015-02-20 14:59:16 +00:00
|
|
|
self.gen_file('iar_%s.ewd.tmpl' % self.target.lower(), ctx, '%s.ewd' % self.program_name)
|
2015-03-05 14:58:24 +00:00
|
|
|
|
2015-03-25 13:43:06 +00:00
|
|
|
class IarFolder():
|
|
|
|
"""
|
|
|
|
This is a recursive folder object.
|
|
|
|
To present the folder structure in the IDE as it is presented on the disk.
|
|
|
|
This can be used for uvision as well if you replace the __str__ method.
|
|
|
|
Example:
|
|
|
|
files: ./main.cpp, ./apis/I2C.h, ./mbed/common/I2C.cpp
|
|
|
|
in the project this would look like:
|
|
|
|
main.cpp
|
|
|
|
common/I2C.cpp
|
|
|
|
input:
|
|
|
|
folder_level : folder path to current folder
|
|
|
|
folder_name : name of current folder
|
|
|
|
source_files : list of source_files (all must be in same directory)
|
|
|
|
"""
|
2015-03-05 14:58:24 +00:00
|
|
|
def __init__(self, folder_level, folder_name, source_files):
|
|
|
|
self.folder_level = folder_level
|
|
|
|
self.folder_name = folder_name
|
|
|
|
self.source_files = source_files
|
2015-03-25 13:43:06 +00:00
|
|
|
self.sub_folders = {}
|
|
|
|
|
2015-03-05 14:58:24 +00:00
|
|
|
def __str__(self):
|
2015-03-25 13:43:06 +00:00
|
|
|
"""
|
|
|
|
converts the folder structue to IAR project format.
|
|
|
|
"""
|
2015-03-05 14:58:24 +00:00
|
|
|
group_start = ""
|
|
|
|
group_end = ""
|
|
|
|
if self.folder_name != "":
|
|
|
|
group_start = "<group>\n<name>%s</name>\n" %(self.folder_name)
|
|
|
|
group_end = "</group>\n"
|
|
|
|
|
|
|
|
str_content = group_start
|
|
|
|
#Add files in current folder
|
|
|
|
if self.source_files:
|
|
|
|
for src in self.source_files:
|
2015-03-25 12:03:50 +00:00
|
|
|
str_content += "<file>\n<name>$PROJ_DIR$/%s</name>\n</file>\n" % src
|
2015-03-25 13:43:06 +00:00
|
|
|
#Add sub folders
|
2015-03-05 14:58:24 +00:00
|
|
|
if self.sub_folders:
|
|
|
|
for folder_name in self.sub_folders.iterkeys():
|
|
|
|
str_content += self.sub_folders[folder_name].__str__()
|
2015-03-25 13:43:06 +00:00
|
|
|
|
2015-03-05 14:58:24 +00:00
|
|
|
str_content += group_end
|
|
|
|
return str_content
|
2015-03-25 13:43:06 +00:00
|
|
|
|
2015-03-05 14:58:24 +00:00
|
|
|
def insert_file(self, source_input):
|
2015-03-25 13:43:06 +00:00
|
|
|
"""
|
|
|
|
Inserts a source file into the folder tree
|
|
|
|
"""
|
|
|
|
if self.source_files:
|
|
|
|
#All source_files in a IarFolder must be in same directory.
|
|
|
|
dir_sources = IarFolder.get_directory(self.source_files[0])
|
|
|
|
#Check if sources are already at their deepest level.
|
|
|
|
if not self.folder_level == dir_sources:
|
2015-03-05 14:58:24 +00:00
|
|
|
_reg_exp = r"^" + re.escape(self.folder_level) + r"[/\\]?([^/\\]+)"
|
2015-03-25 13:43:06 +00:00
|
|
|
folder_name = re.match(_reg_exp, dir_sources).group(1)
|
|
|
|
self.sub_folders[folder_name] = IarFolder(os.path.join(self.folder_level, folder_name), folder_name, self.source_files)
|
2015-03-05 14:58:24 +00:00
|
|
|
self.source_files = []
|
2015-03-25 13:43:06 +00:00
|
|
|
|
|
|
|
dir_input = IarFolder.get_directory(source_input)
|
2015-03-05 14:58:24 +00:00
|
|
|
if dir_input == self.folder_level:
|
|
|
|
self.source_files.append(source_input)
|
|
|
|
else:
|
|
|
|
_reg_exp = r"^" + re.escape(self.folder_level) + r"[/\\]?([^/\\]+)"
|
2015-03-25 13:43:06 +00:00
|
|
|
folder_name = re.match(_reg_exp, dir_input).group(1)
|
2015-03-05 14:58:24 +00:00
|
|
|
if self.sub_folders.has_key(folder_name):
|
|
|
|
self.sub_folders[folder_name].insert_file(source_input)
|
|
|
|
else:
|
2015-03-25 13:43:06 +00:00
|
|
|
if self.folder_level == "":
|
|
|
|
#Top level exception
|
|
|
|
self.sub_folders[folder_name] = IarFolder(folder_name, folder_name, [source_input])
|
2015-03-05 14:58:24 +00:00
|
|
|
else:
|
2015-03-25 13:43:06 +00:00
|
|
|
self.sub_folders[folder_name] = IarFolder(os.path.join(self.folder_level, folder_name), folder_name, [source_input])
|
2015-03-05 14:58:24 +00:00
|
|
|
|
2015-03-25 13:43:06 +00:00
|
|
|
@staticmethod
|
2015-03-05 14:58:24 +00:00
|
|
|
def get_directory(file_path):
|
2015-03-25 13:43:06 +00:00
|
|
|
"""
|
|
|
|
Returns the directory of the file
|
|
|
|
"""
|
2015-03-25 12:03:50 +00:00
|
|
|
return os.path.dirname(file_path)
|