Keyboard firmwares for Atmel AVR and Cortex-M
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. """
  2. mbed SDK
  3. Copyright (c) 2011-2013 ARM Limited
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.apache.org/licenses/LICENSE-2.0
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. """
  14. from workspace_tools.export.exporters import Exporter
  15. import re
  16. import os
  17. class IAREmbeddedWorkbench(Exporter):
  18. """
  19. Exporter class for IAR Systems.
  20. """
  21. NAME = 'IAR'
  22. TOOLCHAIN = 'IAR'
  23. TARGETS = [
  24. 'LPC1768',
  25. 'LPC1347',
  26. 'LPC11U24',
  27. 'LPC11U35_401',
  28. 'LPC11U35_501',
  29. #Removed LPCCAPPUCCINO linker file and startup file missing
  30. #'LPCCAPPUCCINO',
  31. 'LPC1114',
  32. 'LPC1549',
  33. 'LPC812',
  34. 'LPC4088',
  35. 'LPC4088_DM',
  36. 'LPC824',
  37. 'UBLOX_C027',
  38. 'ARCH_PRO',
  39. 'K20D50M',
  40. 'KL05Z',
  41. 'KL25Z',
  42. 'KL46Z',
  43. 'K22F',
  44. 'K64F',
  45. 'NUCLEO_F030R8',
  46. 'NUCLEO_F070RB',
  47. 'NUCLEO_F072RB',
  48. 'NUCLEO_F091RC',
  49. 'NUCLEO_F103RB',
  50. 'NUCLEO_F302R8',
  51. 'NUCLEO_F303RE',
  52. 'NUCLEO_F334R8',
  53. 'NUCLEO_F401RE',
  54. 'NUCLEO_F411RE',
  55. 'NUCLEO_L053R8',
  56. 'NUCLEO_L073RZ',
  57. 'NUCLEO_L152RE',
  58. #'STM32F407', Fails to build same for GCC
  59. 'MAXWSNENV',
  60. 'MAX32600MBED',
  61. 'MTS_MDOT_F405RG',
  62. 'MTS_MDOT_F411RE',
  63. 'MTS_DRAGONFLY_F411RE',
  64. 'NRF51822',
  65. 'NRF51_DK',
  66. 'NRF51_DONGLE',
  67. 'DELTA_DFCM_NNN40',
  68. 'SEEED_TINY_BLE',
  69. 'HRM1017',
  70. 'ARCH_BLE',
  71. 'MOTE_L152RC',
  72. ]
  73. def generate(self):
  74. """
  75. Generates the project files
  76. """
  77. sources = []
  78. sources += self.resources.c_sources
  79. sources += self.resources.cpp_sources
  80. sources += self.resources.s_sources
  81. iar_files = IarFolder("", "", [])
  82. for source in sources:
  83. iar_files.insert_file(source)
  84. ctx = {
  85. 'name': self.program_name,
  86. 'include_paths': self.resources.inc_dirs,
  87. 'linker_script': self.resources.linker_script,
  88. 'object_files': self.resources.objects,
  89. 'libraries': self.resources.libraries,
  90. 'symbols': self.get_symbols(),
  91. 'source_files': iar_files.__str__(),
  92. 'binary_files': self.resources.bin_files,
  93. }
  94. self.gen_file('iar_%s.ewp.tmpl' % self.target.lower(), ctx, '%s.ewp' % self.program_name)
  95. self.gen_file('iar.eww.tmpl', ctx, '%s.eww' % self.program_name)
  96. self.gen_file('iar_%s.ewd.tmpl' % self.target.lower(), ctx, '%s.ewd' % self.program_name)
  97. class IarFolder():
  98. """
  99. This is a recursive folder object.
  100. To present the folder structure in the IDE as it is presented on the disk.
  101. This can be used for uvision as well if you replace the __str__ method.
  102. Example:
  103. files: ./main.cpp, ./apis/I2C.h, ./mbed/common/I2C.cpp
  104. in the project this would look like:
  105. main.cpp
  106. common/I2C.cpp
  107. input:
  108. folder_level : folder path to current folder
  109. folder_name : name of current folder
  110. source_files : list of source_files (all must be in same directory)
  111. """
  112. def __init__(self, folder_level, folder_name, source_files):
  113. self.folder_level = folder_level
  114. self.folder_name = folder_name
  115. self.source_files = source_files
  116. self.sub_folders = {}
  117. def __str__(self):
  118. """
  119. converts the folder structue to IAR project format.
  120. """
  121. group_start = ""
  122. group_end = ""
  123. if self.folder_name != "":
  124. group_start = "<group>\n<name>%s</name>\n" %(self.folder_name)
  125. group_end = "</group>\n"
  126. str_content = group_start
  127. #Add files in current folder
  128. if self.source_files:
  129. for src in self.source_files:
  130. str_content += "<file>\n<name>$PROJ_DIR$/%s</name>\n</file>\n" % src
  131. #Add sub folders
  132. if self.sub_folders:
  133. for folder_name in self.sub_folders.iterkeys():
  134. str_content += self.sub_folders[folder_name].__str__()
  135. str_content += group_end
  136. return str_content
  137. def insert_file(self, source_input):
  138. """
  139. Inserts a source file into the folder tree
  140. """
  141. if self.source_files:
  142. #All source_files in a IarFolder must be in same directory.
  143. dir_sources = IarFolder.get_directory(self.source_files[0])
  144. #Check if sources are already at their deepest level.
  145. if not self.folder_level == dir_sources:
  146. _reg_exp = r"^" + re.escape(self.folder_level) + r"[/\\]?([^/\\]+)"
  147. folder_name = re.match(_reg_exp, dir_sources).group(1)
  148. self.sub_folders[folder_name] = IarFolder(os.path.join(self.folder_level, folder_name), folder_name, self.source_files)
  149. self.source_files = []
  150. dir_input = IarFolder.get_directory(source_input)
  151. if dir_input == self.folder_level:
  152. self.source_files.append(source_input)
  153. else:
  154. _reg_exp = r"^" + re.escape(self.folder_level) + r"[/\\]?([^/\\]+)"
  155. folder_name = re.match(_reg_exp, dir_input).group(1)
  156. if self.sub_folders.has_key(folder_name):
  157. self.sub_folders[folder_name].insert_file(source_input)
  158. else:
  159. if self.folder_level == "":
  160. #Top level exception
  161. self.sub_folders[folder_name] = IarFolder(folder_name, folder_name, [source_input])
  162. else:
  163. self.sub_folders[folder_name] = IarFolder(os.path.join(self.folder_level, folder_name), folder_name, [source_input])
  164. @staticmethod
  165. def get_directory(file_path):
  166. """
  167. Returns the directory of the file
  168. """
  169. return os.path.dirname(file_path)