Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: toolchains/iar.py
- Revision:
- 43:2a7da56ebd24
- Parent:
- 41:2a77626a4c21
--- a/toolchains/iar.py	Mon Nov 06 13:17:14 2017 -0600
+++ b/toolchains/iar.py	Tue Sep 25 13:43:09 2018 -0500
@@ -17,9 +17,11 @@
 import re
 from os import remove
 from os.path import join, splitext, exists
+from distutils.version import LooseVersion
 
 from tools.toolchains import mbedToolchain, TOOLCHAIN_PATHS
 from tools.hooks import hook_tool
+from tools.utils import run_cmd, NotSupportedException
 
 class IAR(mbedToolchain):
     LIBRARY_EXT = '.a'
@@ -28,6 +30,8 @@
 
     DIAGNOSTIC_PATTERN = re.compile('"(?P<file>[^"]+)",(?P<line>[\d]+)\s+(?P<severity>Warning|Error|Fatal error)(?P<message>.+)')
     INDEX_PATTERN  = re.compile('(?P<col>\s*)\^')
+    IAR_VERSION_RE = re.compile(b"IAR ANSI C/C\+\+ Compiler V(\d+\.\d+)")
+    IAR_VERSION = LooseVersion("7.80")
 
     @staticmethod
     def check_executable():
@@ -36,12 +40,9 @@
         Returns False otherwise."""
         return mbedToolchain.generic_check_executable("IAR", 'iccarm', 2, "bin")
 
-    def __init__(self, target, notify=None, macros=None,
-                 silent=False, extra_verbose=False, build_profile=None,
+    def __init__(self, target, notify=None, macros=None, build_profile=None,
                  build_dir=None):
-        mbedToolchain.__init__(self, target, notify, macros, silent,
-                               build_dir=build_dir,
-                               extra_verbose=extra_verbose,
+        mbedToolchain.__init__(self, target, notify, macros, build_dir=build_dir,
                                build_profile=build_profile)
         if target.core == "Cortex-M7F" or target.core == "Cortex-M7FD":
             cpuchoice = "Cortex-M7"
@@ -74,6 +75,12 @@
             c_flags_cmd.append("--fpu=VFPv5_sp")
         elif target.core == "Cortex-M23" or target.core == "Cortex-M33":
             self.flags["asm"] += ["--cmse"]
+            self.flags["common"] += ["--cmse"]
+
+        # Create Secure library
+        if target.core == "Cortex-M23" or self.target.core == "Cortex-M33":
+            secure_file = join(build_dir, "cmse_lib.o")
+            self.flags["ld"] += ["--import_cmse_lib_out=%s" % secure_file]
 
         IAR_BIN = join(TOOLCHAIN_PATHS['IAR'], "bin")
         main_cc = join(IAR_BIN, "iccarm")
@@ -88,6 +95,27 @@
         self.ar = join(IAR_BIN, "iarchive")
         self.elf2bin = join(IAR_BIN, "ielftool")
 
+    def version_check(self):
+        stdout, _, retcode = run_cmd([self.cc[0], "--version"], redirect=True)
+        msg = None
+        match = self.IAR_VERSION_RE.search(stdout)
+        found_version = match.group(1).decode("utf-8") if match else None
+        if found_version and LooseVersion(found_version) != self.IAR_VERSION:
+            msg = "Compiler version mismatch: Have {}; expected {}".format(
+                found_version, self.IAR_VERSION)
+        elif not match or len(match.groups()) != 1:
+            msg = ("Compiler version mismatch: Could Not detect compiler "
+                   "version; expected {}".format(self.IAR_VERSION))
+        if msg:
+            self.notify.cc_info({
+                "message": msg,
+                "file": "",
+                "line": "",
+                "col": "",
+                "severity": "ERROR",
+            })
+
+
     def parse_dependencies(self, dep_path):
         return [(self.CHROOT if self.CHROOT else '')+path.strip() for path in open(dep_path).readlines()
                 if (path and not path.isspace())]
@@ -98,7 +126,7 @@
             match = IAR.DIAGNOSTIC_PATTERN.match(line)
             if match is not None:
                 if msg is not None:
-                    self.cc_info(msg)
+                    self.notify.cc_info(msg)
                     msg = None
                 msg = {
                     'severity': match.group('severity').lower(),
@@ -115,13 +143,13 @@
                 match = IAR.INDEX_PATTERN.match(line)
                 if match is not None:
                     msg['col'] = len(match.group('col'))
-                    self.cc_info(msg)
+                    self.notify.cc_info(msg)
                     msg = None
                 else:
                     msg['text'] += line+"\n"
 
         if msg is not None:
-            self.cc_info(msg)
+            self.notify.cc_info(msg)
 
     def get_dep_option(self, object):
         base, _ = splitext(object)
@@ -137,17 +165,26 @@
 
     def get_compile_options(self, defines, includes, for_asm=False):
         opts = ['-D%s' % d for d in defines]
-        if for_asm :
+        if for_asm:
+            config_macros = self.config.get_config_data_macros()
+            macros_cmd = ['"-D%s"' % d.replace('"', '').replace('//','/\/') for d in config_macros]
+            if self.RESPONSE_FILES:
+                via_file = self.make_option_file(
+                    macros_cmd, "asm_macros_{}.xcl")
+                opts += ['-f', via_file]
+            else:
+                opts += macros_cmd
             return opts
-        if self.RESPONSE_FILES:
-            opts += ['-f', self.get_inc_file(includes)]
         else:
-            opts += ["-I%s" % i for i in includes]
+            if self.RESPONSE_FILES:
+                opts += ['-f', self.get_inc_file(includes)]
+            else:
+                opts += ["-I%s" % i for i in includes]
+            config_header = self.get_config_header()
+            if config_header is not None:
+                opts = opts + self.get_config_option(config_header)
 
-        config_header = self.get_config_header()
-        if config_header is not None:
-            opts = opts + self.get_config_option(config_header)
-        return opts
+            return opts
 
     @hook_tool
     def assemble(self, source, object, includes):
@@ -201,7 +238,7 @@
             cmd = [cmd_linker, '-f', link_files]
 
         # Exec command
-        self.cc_verbose("Link: %s" % ' '.join(cmd))
+        self.notify.cc_verbose("Link: %s" % ' '.join(cmd))
         self.default_cmd(cmd)
 
     @hook_tool
@@ -227,7 +264,7 @@
         cmd = self.hook.get_cmdline_binary(cmd)
 
         # Exec command
-        self.cc_verbose("FromELF: %s" % ' '.join(cmd))
+        self.notify.cc_verbose("FromELF: %s" % ' '.join(cmd))
         self.default_cmd(cmd)
 
     @staticmethod
@@ -236,7 +273,7 @@
 
     @staticmethod
     def make_ld_define(name, value):
-        return "--config_def %s=0x%x" % (name, value)
+        return "--config_def %s=%s" % (name, value)
 
     @staticmethod
     def redirect_symbol(source, sync, build_dir):
    