Skip to content

Adding ProGen as default exporter for uvision4 and IAR #1484

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
url='https://github.com/mbedmicro/mbed',
packages=find_packages(),
license=LICENSE,
install_requires=["PrettyTable>=0.7.2", "PySerial>=2.7", "IntelHex>=1.3", "colorama>=0.3.3", "Jinja2>=2.7.3"])
install_requires=["PrettyTable>=0.7.2", "PySerial>=2.7", "IntelHex>=1.3", "colorama>=0.3.3", "Jinja2>=2.7.3", "project-generator>=0.8.4,<0.9.0"])

# Restore previous private_settings if needed
if backup:
Expand Down
26 changes: 22 additions & 4 deletions workspace_tools/export/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
from workspace_tools.export.exporters import zip_working_directory_and_clean_up, OldLibrariesException
from workspace_tools.targets import TARGET_NAMES, EXPORT_MAP

from project_generator_definitions.definitions import ProGenDef

EXPORTERS = {
'uvision': uvision4.Uvision4,
'lpcxpresso': codered.CodeRed,
Expand Down Expand Up @@ -59,7 +61,7 @@ def export(project_path, project_name, ide, target, destination='/tmp/',
if tempdir is None:
tempdir = tempfile.mkdtemp()

report = {'success': False}
report = {'success': False, 'errormsg':''}
if ide is None or ide == "zip":
# Simple ZIP exporter
try:
Expand All @@ -72,20 +74,36 @@ def export(project_path, project_name, ide, target, destination='/tmp/',
report['errormsg'] = ERROR_MESSAGE_NOT_EXPORT_LIBS
else:
if ide not in EXPORTERS:
report['errormsg'] = "Unsupported toolchain"
report['errormsg'] = ERROR_MESSAGE_UNSUPPORTED_TOOLCHAIN % (target, ide)
else:
Exporter = EXPORTERS[ide]
target = EXPORT_MAP.get(target, target)
if target not in Exporter.TARGETS:
report['errormsg'] = ERROR_MESSAGE_UNSUPPORTED_TOOLCHAIN % (target, ide)
# use progen targets or mbed exporters targets, check progen attribute
use_progen = False
supported = True
try:
if Exporter.PROGEN_ACTIVE:
use_progen = True
except AttributeError:
pass
if use_progen:
if target not in Exporter.PROGEN_TARGETS.keys() or not ProGenDef(ide).is_supported(Exporter.PROGEN_TARGETS[target]):
supported = False
else:
if target not in Exporter.TARGETS:
supported = False

if supported:
# target checked, export
try:
exporter = Exporter(target, tempdir, project_name, build_url_resolver, extra_symbols=extra_symbols)
exporter.scan_and_copy_resources(project_path, tempdir)
exporter.generate()
report['success'] = True
except OldLibrariesException, e:
report['errormsg'] = ERROR_MESSAGE_NOT_EXPORT_LIBS
else:
report['errormsg'] = ERROR_MESSAGE_UNSUPPORTED_TOOLCHAIN % (target, ide)

zip_path = None
if report['success']:
Expand Down
121 changes: 120 additions & 1 deletion workspace_tools/export/exporters.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,99 @@
from workspace_tools.toolchains import TOOLCHAIN_CLASSES
from workspace_tools.targets import TARGET_MAP

from project_generator.generate import Generator
from project_generator.project import Project
from project_generator.settings import ProjectSettings

class OldLibrariesException(Exception): pass

class Exporter():
class Exporter(object):
TEMPLATE_DIR = dirname(__file__)
DOT_IN_RELATIVE_PATH = False

# mapping mbed to progen targets
PROGEN_TARGETS = {
'LPC1768': 'mbed-lpc1768',
'LPC11U24': 'lpc11u24_201',
'LPC1347':'lpc1347',
'LPC1114':'lpc1114_102',
'LPC11C24':'lpc11c24_301',
'LPC4088':'lpc4088',
'LPC4088_DM':'lpc4088',
'LPC4330_M4':'lpc4330',
'LPC4337':'lpc4337',
'LPC812':'lpc812m101',
'LPC824': 'lpc824m201',
'LPC1549':'lpc1549',
'LPC11U68':'lpc11u68',
'LPC11U35_501':'lpc11u35_501',
'LPC11U35_401': 'lpc11u35_401',
'LPC11U37H_401':'lpc11u37_401',

'KL05Z':'frdm-kl05z',
'KL25Z':'frdm-kl25z',
'KL43Z':'frdm-kl43z',
'KL46Z':'frdm-kl46z',
'K64F': 'frdm-k64f',
'K22F': 'frdm-k22f',
'K20D50M': 'frdm-k20d50m',
'TEENSY3_1':'teensy-31',

'NUCLEO_F030R8':'nucleo-f030r8',
'NUCLEO_F031K6':'nucleo-f031k6',
'NUCLEO_F042K6':'nucleo-f042k6',
'NUCLEO_F070RB':'nucleo-f070rb',
'NUCLEO_F072RB':'nucleo-f072rb',
'NUCLEO_F091RC':'nucleo-f091rc',
'NUCLEO_F103RB':'nucleo-f103rb',
'NUCLEO_F302R8':'nucleo-f302r8',
'NUCLEO_F303K8':'nucleo-f303k8',
'NUCLEO_F303RE':'nucleo-f303re',
'NUCLEO_F334R8':'nucleo-f334r8',
'NUCLEO_F401RE':'nucleo-f401re',
'NUCLEO_F410RB':'nucleo-f410rb',
'NUCLEO_F411RE':'nucleo-f411re',
'NUCLEO_F446RE':'nucleo-f446re',
'NUCLEO_L053R8':'nucleo-l053r8',
'NUCLEO_L073RZ':'nucleo-l073rz',
'NUCLEO_L152RE':'nucleo-l152re',
'NUCLEO_L476RG':'nucleo-l476rg',

'DISCO_F407VG':'disco-f407vg',
'DISCO_F429ZI':'disco-f429zi',
'DISCO_L053C8':'disco-l053c8',
'DISCO_F334C8':'disco-f334c8',
'DISCO_F469NI':'disco-f469ni',
'DISCO_F746NG':'disco-f746ng',
'DISCO_L476VG':'disco-l476vg',

'UBLOX_C027':'ublox-c027',
'NRF51822':'mkit',
'HRM1017':'hrm1017',
'RBLAB_NRF51822':'rblab-nrf51822',
'ARCH_PRO':'arch-pro',
'ARCH_BLE':'arch-ble',
'MTS_GAMBIT':'mts-gambit',
'ARCH_MAX':'lpc1768',
'MTS_MDOT_F405RG':'mts-mdot-f405rg',
'MTS_MDOT_F411RE': 'mts-mdot-f411re',
'MTS_DRAGONFLY_F411RE': 'mts-dragonfly-f411re',
'NRF51_DK':'nrf51-dk',
'NRF51_DONGLE':'nrf51-dongle',
'SEEED_TINY_BLE':'seed-tinyble',

'DELTA_DFCM_NNN40':'dfcm-nnn40',
'MAXWSNENV':'maxwsnenv',
'MAX32600MBED':'max32600mbed',
'MOTE_L152RC':'stm32l151rc',
'NZ32SC151':'stm32l151rc',

'SAMR21G18A':'samr21g18a',
'SAMD21J18A':'samd21j18a',
'SAMD21G18A':'samd21g18a',
'SAML21J18A':'samr21j18a',
}

def __init__(self, target, inputDir, program_name, build_url_resolver, extra_symbols=None):
self.inputDir = inputDir
self.target = target
Expand All @@ -42,6 +129,32 @@ def __scan_and_copy(self, src_path, trg_path):
self.toolchain.copy_files(r, trg_path, rel_path=src_path)
return resources

def get_project_data(self):
""" Get ProGen project data """
# provide default data, some tools don't require any additional
# tool specific settings
sources = []
for r_type in ['c_sources', 'cpp_sources', 's_sources']:
for file in getattr(self.resources, r_type):
sources.append(file)

project_data = {
'common': {
'sources': {
'Source Files': sources + self.resources.hex_files +
self.resources.objects + self.resources.libraries,
},
'includes': {
'Include Files': self.resources.headers,
},
'target': [self.PROGEN_TARGETS[self.target]],
'macros': self.get_symbols(),
'export_dir': [self.inputDir],
'linker_file': [self.resources.linker_script],
}
}
return project_data

def __scan_all(self, path):
resources = []

Expand Down Expand Up @@ -89,6 +202,12 @@ def scan_and_copy_resources(self, prj_path, trg_path):
# if not self.toolchain.mbed_libs:
# raise OldLibrariesException()

def gen_file_progen(self, tool_name, project_data):
"""" Generate project using ProGen Project API """
settings = ProjectSettings()
project = Project(self.program_name, [project_data], settings)
project.generate(tool_name, copied=True)

def gen_file(self, template_file, data, target_file):
template_path = join(Exporter.TEMPLATE_DIR, template_file)
template = self.jinja_environment.get_template(template_file)
Expand Down
8 changes: 0 additions & 8 deletions workspace_tools/export/iar.eww.tmpl

This file was deleted.

101 changes: 14 additions & 87 deletions workspace_tools/export/iar.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,102 +17,29 @@
from workspace_tools.export.exporters import Exporter
import re
import os

class IAREmbeddedWorkbench(Exporter):
"""
Exporter class for IAR Systems.
"""
NAME = 'IAR'
TOOLCHAIN = 'IAR'

TARGETS = [
'LPC1768',
'LPC1347',
'LPC11U24',
'LPC11U35_401',
'LPC11U35_501',
#Removed LPCCAPPUCCINO linker file and startup file missing
#'LPCCAPPUCCINO',
'LPC1114',
'LPC1549',
'LPC812',
'LPC4088',
'LPC4088_DM',
'LPC824',
'UBLOX_C027',
'ARCH_PRO',
'K20D50M',
'KL05Z',
'KL25Z',
'KL46Z',
'K22F',
'K64F',
'NUCLEO_F030R8',
'NUCLEO_F031K6',
'NUCLEO_F042K6',
'NUCLEO_F070RB',
'NUCLEO_F072RB',
'NUCLEO_F091RC',
'NUCLEO_F103RB',
'NUCLEO_F302R8',
'NUCLEO_F303K8',
'NUCLEO_F303RE',
'NUCLEO_F334R8',
'NUCLEO_F401RE',
'NUCLEO_F410RB',
'NUCLEO_F411RE',
'NUCLEO_F446RE',
'NUCLEO_L053R8',
'NUCLEO_L073RZ',
'NUCLEO_L152RE',
'NUCLEO_L476RG',
'DISCO_F429ZI',
'DISCO_L053C8',
'DISCO_F334C8',
'DISCO_F469NI',
'DISCO_F746NG',
'DISCO_L476VG',
#'STM32F407', Fails to build same for GCC
'MAXWSNENV',
'MAX32600MBED',
'MTS_MDOT_F405RG',
'MTS_MDOT_F411RE',
'MTS_DRAGONFLY_F411RE',
'NRF51822',
'NRF51_DK',
'NRF51_DONGLE',
'DELTA_DFCM_NNN40',
'SEEED_TINY_BLE',
'HRM1017',
'ARCH_BLE',
'MOTE_L152RC',
]
PROGEN_ACTIVE = True

def generate(self):
"""
Generates the project files
"""
sources = []
sources += self.resources.c_sources
sources += self.resources.cpp_sources
sources += self.resources.s_sources

iar_files = IarFolder("", "", [])
for source in sources:
iar_files.insert_file(source)

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,
'symbols': self.get_symbols(),
'source_files': iar_files.__str__(),
'binary_files': self.resources.bin_files,
""" Generates the project files """
project_data = self.get_project_data()
tool_specific = {
'iar': {
'misc': {
'cxx_flags': ['--no_rtti', '--no_exceptions'],
'c_flags': ['--diag_suppress=Pa050,Pa084,Pa093,Pa082'],
}
}
}
self.gen_file('iar_%s.ewp.tmpl' % self.target.lower(), ctx, '%s.ewp' % self.program_name)
self.gen_file('iar.eww.tmpl', ctx, '%s.eww' % self.program_name)
self.gen_file('iar_%s.ewd.tmpl' % self.target.lower(), ctx, '%s.ewd' % self.program_name)
project_data['tool_specific'] = {}
project_data['tool_specific'].update(tool_specific)
self.gen_file_progen('iar_arm', project_data)

class IarFolder():
"""
Expand Down
Loading