Gleb Klochkov / Mbed OS Climatcontroll_Main

Dependencies:   esp8266-driver

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers __init__.py Source File

__init__.py

00001 """
00002 mbed SDK
00003 Copyright (c) 2011-2017 ARM Limited
00004 
00005 Licensed under the Apache License, Version 2.0 (the "License");
00006 you may not use this file except in compliance with the License.
00007 You may obtain a copy of the License at
00008 
00009 http://www.apache.org/licenses/LICENSE-2.0
00010 
00011 Unless required by applicable law or agreed to in writing, software
00012 distributed under the License is distributed on an "AS IS" BASIS,
00013 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014 See the License for the specific language governing permissions and
00015 limitations under the License.
00016 """
00017 from __future__ import print_function, absolute_import
00018 from builtins import str
00019 
00020 from os.path import splitext, basename, join
00021 import shutil
00022 from tools.utils import mkdir
00023 from tools.export.gnuarmeclipse import GNUARMEclipse
00024 from tools.export.gnuarmeclipse import UID
00025 from tools.build_api import prepare_toolchain
00026 from tools.targets import TARGET_MAP
00027 from sys import flags, platform
00028 
00029 # Global random number generator instance.
00030 u = UID()
00031 
00032 
00033 class Sw4STM32 (GNUARMEclipse):
00034     """
00035     Sw4STM32 class
00036     """
00037     NAME = 'Sw4STM32'
00038     TOOLCHAIN = 'GCC_ARM'
00039 
00040     BOARDS = {
00041         'B96B_F446VE':
00042         {
00043             'name': 'B96B-F446VE',
00044             'mcuId': 'STM32F446VETx'
00045         },
00046         'DISCO_F051R8':
00047         {
00048             'name': 'STM32F0DISCOVERY',
00049             'mcuId': 'STM32F051R8Tx'
00050         },
00051         'DISCO_F303VC':
00052         {
00053             'name': 'STM32F3DISCOVERY',
00054             'mcuId': 'STM32F303VCTx'
00055         },
00056         'DISCO_F334C8':
00057         {
00058             'name': 'STM32F3348DISCOVERY',
00059             'mcuId': 'STM32F334C8Tx'
00060         },
00061         'DISCO_F401VC':
00062         {
00063             'name': 'STM32F401C-DISCO',
00064             'mcuId': 'STM32F401VCTx'
00065         },
00066         'DISCO_F407VG':
00067         {
00068             'name': 'STM32F4DISCOVERY',
00069             'mcuId': 'STM32F407VGTx'
00070         },
00071         'DISCO_F413ZH':
00072         {
00073             'name': 'DISCO_F413',
00074             'mcuId': 'STM32F413ZHTx'
00075         },
00076         'DISCO_F429ZI':
00077         {
00078             'name': 'STM32F429I-DISCO',
00079             'mcuId': 'STM32F429ZITx'
00080         },
00081         'DISCO_F469NI':
00082         {
00083             'name': 'DISCO-F469NI',
00084             'mcuId': 'STM32F469NIHx'
00085         },
00086         'DISCO_F746NG':
00087         {
00088             'name': 'STM32F746G-DISCO',
00089             'mcuId': 'STM32F746NGHx'
00090         },
00091         'DISCO_F769NI':
00092         {
00093             'name': 'DISCO-F769NI',
00094             'mcuId': 'STM32F769NIHx'
00095         },
00096         'DISCO_L053C8':
00097         {
00098             'name': 'STM32L0538DISCOVERY',
00099             'mcuId': 'STM32L053C8Tx'
00100         },
00101         'DISCO_L072CZ_LRWAN1':
00102         {
00103             'name': 'DISCO-L072CZ-LRWAN1',
00104             'mcuId': 'STM32L072CZTx'
00105         },
00106         'MTB_MURATA_ABZ':
00107         {
00108             'name': 'MTB-MURATA-ABZ',
00109             'mcuId': 'STM32L0x2xZ'
00110         },
00111         'DISCO_L475VG_IOT01A':
00112         {
00113             'name': 'STM32L475G-DISCO',
00114             'mcuId': 'STM32L475VGTx'
00115         },
00116         'DISCO_L476VG':
00117         {
00118             'name': 'STM32L476G-DISCO',
00119             'mcuId': 'STM32L476VGTx'
00120         },
00121         'NUCLEO_F030R8':
00122         {
00123             'name': 'NUCLEO-F030R8',
00124             'mcuId': 'STM32F030R8Tx'
00125         },
00126         'NUCLEO_F031K6':
00127         {
00128             'name': 'NUCLEO-F031K6',
00129             'mcuId': 'STM32F031K6Tx'
00130         },
00131         'NUCLEO_F042K6':
00132         {
00133             'name': 'NUCLEO-F042K6',
00134             'mcuId': 'STM32F042K6Tx'
00135         },
00136         'NUCLEO_F070RB':
00137         {
00138             'name': 'NUCLEO-F070RB',
00139             'mcuId': 'STM32F070RBTx'
00140         },
00141         'NUCLEO_F072RB':
00142         {
00143             'name': 'NUCLEO-F072RB',
00144             'mcuId': 'STM32F072RBTx'
00145         },
00146         'NUCLEO_F091RC':
00147         {
00148             'name': 'NUCLEO-F091RC',
00149             'mcuId': 'STM32F091RCTx'
00150         },
00151         'NUCLEO_F103RB':
00152         {
00153             'name': 'NUCLEO-F103RB',
00154             'mcuId': 'STM32F103RBTx'
00155         },
00156         'NUCLEO_F207ZG':
00157         {
00158             'name': 'NUCLEO-F207ZG',
00159             'mcuId': 'STM32F207ZGTx'
00160         },
00161         'NUCLEO_F302R8':
00162         {
00163             'name': 'NUCLEO-F302R8',
00164             'mcuId': 'STM32F302R8Tx'
00165         },
00166         'NUCLEO_F303K8':
00167         {
00168             'name': 'NUCLEO-F303K8',
00169             'mcuId': 'STM32F303K8Tx'
00170         },
00171         'NUCLEO_F303RE':
00172         {
00173             'name': 'NUCLEO-F303RE',
00174             'mcuId': 'STM32F303RETx'
00175         },
00176         'NUCLEO_F303ZE':
00177         {
00178             'name': 'NUCLEO-F303ZE',
00179             'mcuId': 'STM32F303ZETx'
00180         },
00181         'NUCLEO_F334R8':
00182         {
00183             'name': 'NUCLEO-F334R8',
00184             'mcuId': 'STM32F334R8Tx'
00185         },
00186         'NUCLEO_F401RE':
00187         {
00188             'name': 'NUCLEO-F401RE',
00189             'mcuId': 'STM32F401RETx'
00190         },
00191         'NUCLEO_F410RB':
00192         {
00193             'name': 'NUCLEO-F410RB',
00194             'mcuId': 'STM32F410RBTx'
00195         },
00196         'NUCLEO_F411RE':
00197         {
00198             'name': 'NUCLEO-F411RE',
00199             'mcuId': 'STM32F411RETx'
00200         },
00201         'NUCLEO_F413ZH':
00202         {
00203             'name': 'NUCLEO-F413ZH',
00204             'mcuId': 'STM32F413ZHTx'
00205         },
00206         'NUCLEO_F429ZI':
00207         {
00208             'name': 'NUCLEO-F429ZI',
00209             'mcuId': 'STM32F429ZITx'
00210         },
00211         'NUCLEO_F446RE':
00212         {
00213             'name': 'NUCLEO-F446RE',
00214             'mcuId': 'STM32F446RETx'
00215         },
00216         'NUCLEO_F446ZE':
00217         {
00218             'name': 'NUCLEO-F446ZE',
00219             'mcuId': 'STM32F446ZETx'
00220         },
00221         'NUCLEO_F746ZG':
00222         {
00223             'name': 'NUCLEO-F746ZG',
00224             'mcuId': 'STM32F746ZGTx'
00225         },
00226         'NUCLEO_F767ZI':
00227         {
00228             'name': 'NUCLEO-F767ZI',
00229             'mcuId': 'STM32F767ZITx'
00230         },
00231         'NUCLEO_L011K4':
00232         {
00233             'name': 'NUCLEO-L011K4',
00234             'mcuId': 'STM32L011K4Tx'
00235         },
00236         'NUCLEO_L031K6':
00237         {
00238             'name': 'NUCLEO-L031K6',
00239             'mcuId': 'STM32L031K6Tx'
00240         },
00241         'NUCLEO_L053R8':
00242         {
00243             'name': 'NUCLEO-L053R8',
00244             'mcuId': 'STM32L053R8Tx'
00245         },
00246         'NUCLEO_L073RZ':
00247         {
00248             'name': 'NUCLEO-L073RZ',
00249             'mcuId': 'STM32L073RZTx'
00250         },
00251         'MTB_RAK811':
00252         {
00253             'name': 'MTB-RAK-811',
00254             'mcuId': 'STM32L151CBUxA'
00255         },
00256         'NUCLEO_L152RE':
00257         {
00258             'name': 'NUCLEO-L152RE',
00259             'mcuId': 'STM32L152RETx'
00260         },
00261         'NUCLEO_L432KC':
00262         {
00263             'name': 'NUCLEO-L432KC',
00264             'mcuId': 'STM32L432KCUx'
00265         },
00266         'MTB_ADV_WISE_1510':
00267         {
00268             'name': 'MTB-ADV-WISE-1510',
00269             'mcuId': 'STM32L443xC'
00270         },
00271         'NUCLEO_L476RG':
00272         {
00273             'name': 'NUCLEO-L476RG',
00274             'mcuId': 'STM32L476RGTx'
00275         },
00276         'NUCLEO_L486RG':
00277         {
00278             'name': 'NUCLEO-L486RG',
00279             'mcuId': 'STM32L486RGTx'
00280         },
00281         'NUCLEO_L496ZG':
00282         {
00283             'name': 'NUCLEO-L496ZG',
00284             'mcuId': 'STM32L496ZGTx'
00285         },
00286         'NUCLEO_L496ZG_P':
00287         {
00288             'name': 'NUCLEO-L496ZG',
00289             'mcuId': 'STM32L496ZGTx'
00290         },
00291     }
00292 
00293 
00294     @classmethod
00295     def is_target_supported (cls, target_name):
00296         target = TARGET_MAP[target_name]
00297         target_supported = bool(set(target.resolution_order_names)
00298                                 .intersection(set(cls.BOARDS.keys())))
00299         toolchain_supported = cls.TOOLCHAIN in target.supported_toolchains
00300         return target_supported and toolchain_supported
00301 
00302     def __gen_dir(self, dir_name):
00303         """
00304         Method that creates directory
00305         """
00306         settings = join(self.export_dir, dir_name)
00307         mkdir(settings)
00308 
00309     def get_fpu_hardware (self, fpu_unit):
00310         """
00311         Convert fpu unit name into hardware name.
00312         """
00313         hw = ''
00314         fpus = {
00315             'fpv4spd16': 'fpv4-sp-d16',
00316             'fpv5d16': 'fpv5-d16',
00317             'fpv5spd16': 'fpv5-sp-d16'
00318         }
00319         if fpu_unit in fpus:
00320             hw = fpus[fpu_unit]
00321         return hw
00322 
00323     def process_sw_options (self, opts, flags_in):
00324         """
00325         Process System Workbench specific options.
00326 
00327         System Workbench for STM32 has some compile options, which are not recognized by the GNUARMEclipse exporter.
00328         Those are handled in this method.
00329         """
00330         opts['c']['preprocess'] = False
00331         if '-E' in flags_in['c_flags']:
00332             opts['c']['preprocess'] = True
00333         opts['cpp']['preprocess'] = False
00334         if '-E' in flags_in['cxx_flags']:
00335             opts['cpp']['preprocess'] = True
00336         opts['c']['slowflashdata'] = False
00337         if '-mslow-flash-data' in flags_in['c_flags']:
00338             opts['c']['slowflashdata'] = True
00339         opts['cpp']['slowflashdata'] = False
00340         if '-mslow-flash-data' in flags_in['cxx_flags']:
00341             opts['cpp']['slowflashdata'] = True
00342         if opts['common']['optimization.messagelength']:
00343             opts['common']['optimization.other'] += ' -fmessage-length=0'
00344         if opts['common']['optimization.signedchar']:
00345             opts['common']['optimization.other'] += ' -fsigned-char'
00346         if opts['common']['optimization.nocommon']:
00347             opts['common']['optimization.other'] += ' -fno-common'
00348         if opts['common']['optimization.noinlinefunctions']:
00349             opts['common']['optimization.other'] += ' -fno-inline-functions'
00350         if opts['common']['optimization.freestanding']:
00351             opts['common']['optimization.other'] += ' -ffreestanding'
00352         if opts['common']['optimization.nobuiltin']:
00353             opts['common']['optimization.other'] += ' -fno-builtin'
00354         if opts['common']['optimization.spconstant']:
00355             opts['common']['optimization.other'] += ' -fsingle-precision-constant'
00356         if opts['common']['optimization.nomoveloopinvariants']:
00357             opts['common']['optimization.other'] += ' -fno-move-loop-invariants'
00358         if opts['common']['warnings.unused']:
00359             opts['common']['warnings.other'] += ' -Wunused'
00360         if opts['common']['warnings.uninitialized']:
00361             opts['common']['warnings.other'] += ' -Wuninitialized'
00362         if opts['common']['warnings.missingdeclaration']:
00363             opts['common']['warnings.other'] += ' -Wmissing-declarations'
00364         if opts['common']['warnings.pointerarith']:
00365             opts['common']['warnings.other'] += ' -Wpointer-arith'
00366         if opts['common']['warnings.padded']:
00367             opts['common']['warnings.other'] += ' -Wpadded'
00368         if opts['common']['warnings.shadow']:
00369             opts['common']['warnings.other'] += ' -Wshadow'
00370         if opts['common']['warnings.logicalop']:
00371             opts['common']['warnings.other'] += ' -Wlogical-op'
00372         if opts['common']['warnings.agreggatereturn']:
00373             opts['common']['warnings.other'] += ' -Waggregate-return'
00374         if opts['common']['warnings.floatequal']:
00375             opts['common']['warnings.other'] += ' -Wfloat-equal'
00376         opts['ld']['strip'] = False
00377         if '-s' in flags_in['ld_flags']:
00378             opts['ld']['strip'] = True
00379         opts['ld']['shared'] = False
00380         if '-shared' in flags_in['ld_flags']:
00381             opts['ld']['shared'] = True
00382         opts['ld']['soname'] = ''
00383         opts['ld']['implname'] = ''
00384         opts['ld']['defname'] = ''
00385         for item in flags_in['ld_flags']:
00386             if item.startswith('-Wl,-soname='):
00387                 opts['ld']['soname'] = item[len('-Wl,-soname='):]
00388             if item.startswith('-Wl,--out-implib='):
00389                 opts['ld']['implname'] = item[len('-Wl,--out-implib='):]
00390             if item.startswith('-Wl,--output-def='):
00391                 opts['ld']['defname'] = item[len('-Wl,--output-def='):]
00392         opts['common']['arm.target.fpu.hardware'] = self.get_fpu_hardware (
00393             opts['common']['arm.target.fpu.unit'])
00394         opts['common']['debugging.codecov'] = False
00395         if '-fprofile-arcs' in flags_in['common_flags'] and '-ftest-coverage' in flags_in['common_flags']:
00396             opts['common']['debugging.codecov'] = True
00397         # Passing linker options to linker with '-Wl,'-prefix.
00398         for index in range(len(opts['ld']['flags'])):
00399             item = opts['ld']['flags'][index]
00400             if not item.startswith('-Wl,'):
00401                 opts['ld']['flags'][index] = '-Wl,' + item
00402         # Strange System Workbench feature: If first parameter in Other flags is a
00403         # define (-D...), Other flags will be replaced by defines and other flags
00404         # are completely ignored. Moving -D parameters to defines.
00405         for compiler in ['c', 'cpp', 'as']:
00406             tmpList = opts[compiler]['other'].split(' ')
00407             otherList = []
00408             for item in tmpList:
00409                 if item.startswith('-D'):
00410                     opts[compiler]['defines'].append(str(item[2:]))
00411                 else:
00412                     otherList.append(item)
00413             opts[compiler]['other'] = ' '.join(otherList)
00414         # Assembler options
00415         for as_def in opts['as']['defines']:
00416             if '=' in as_def:
00417                 opts['as']['other'] += ' --defsym ' + as_def
00418             else:
00419                 opts['as']['other'] += ' --defsym ' + as_def + '=1'
00420 
00421     def generate (self):
00422         """
00423         Generate the .project and .cproject files.
00424         """
00425         options = {}
00426 
00427         if not self.resources.linker_script:
00428             raise NotSupportedException("No linker script found.")
00429 
00430         print('\nCreate a System Workbench for STM32 managed project')
00431         print('Project name: {0}'.format(self.project_name))
00432         print('Target:       {0}'.format(self.toolchain.target.name))
00433         print('Toolchain:    {0}'.format(self.TOOLCHAIN ) + '\n')
00434 
00435         self.resources.win_to_unix()
00436 
00437         config_header = self.filter_dot(self.toolchain.get_config_header())
00438 
00439         libraries = []
00440         for lib in self.resources.libraries:
00441             library, _ = splitext(basename(lib))
00442             libraries.append(library[3:])
00443 
00444         self.system_libraries  = [
00445             'stdc++', 'supc++', 'm', 'c', 'gcc', 'nosys'
00446         ]
00447 
00448         profiles = self.get_all_profiles()
00449         self.as_defines  = [s.replace('"', '"')
00450                            for s in self.toolchain.get_symbols(True)]
00451         self.c_defines  = [s.replace('"', '"')
00452                           for s in self.toolchain.get_symbols()]
00453         self.cpp_defines  = self.c_defines 
00454 
00455         self.include_path  = []
00456         for s in self.resources.inc_dirs:
00457             self.include_path .append("../" + self.filter_dot(s))
00458         print('Include folders: {0}'.format(len(self.include_path )))
00459 
00460         self.compute_exclusions()
00461 
00462         print('Exclude folders: {0}'.format(len(self.excluded_folders)))
00463 
00464         ld_script = self.filter_dot(self.resources.linker_script)
00465         print('Linker script:   {0}'.format(ld_script))
00466 
00467         lib_dirs = [self.filter_dot(s) for s in self.resources.lib_dirs]
00468 
00469         preproc_cmd = basename(self.toolchain.preproc[0]) + " " + " ".join(self.toolchain.preproc[1:])
00470 
00471         for id in ['debug', 'release']:
00472             opts = {}
00473             opts['common'] = {}
00474             opts['as'] = {}
00475             opts['c'] = {}
00476             opts['cpp'] = {}
00477             opts['ld'] = {}
00478 
00479             opts['id'] = id
00480             opts['name'] = opts['id'].capitalize()
00481 
00482             profile = profiles[id]
00483 
00484             # A small hack, do not bother with src_path again,
00485             # pass an empty string to avoid crashing.
00486             src_paths = ['']
00487             toolchain = prepare_toolchain(
00488                 src_paths, "", self.toolchain.target.name, self.TOOLCHAIN , build_profile=[profile])
00489 
00490             # Hack to fill in build_dir
00491             toolchain.build_dir = self.toolchain.build_dir
00492 
00493             flags = self.toolchain_flags(toolchain)
00494 
00495             # Most GNU ARM Eclipse options have a parent,
00496             # either debug or release.
00497             if '-O0' in flags['common_flags'] or '-Og' in flags['common_flags']:
00498                 opts['parent_id'] = 'debug'
00499             else:
00500                 opts['parent_id'] = 'release'
00501 
00502             self.process_options(opts, flags)
00503 
00504             opts['c']['defines'] = self.c_defines 
00505             opts['cpp']['defines'] = self.cpp_defines 
00506             opts['as']['defines'] = self.as_defines 
00507 
00508             self.process_sw_options (opts, flags)
00509 
00510             opts['ld']['library_paths'] = [
00511                 self.filter_dot(s) for s in self.resources.lib_dirs]
00512 
00513             opts['ld']['user_libraries'] = libraries
00514             opts['ld']['system_libraries'] = self.system_libraries 
00515             opts['ld']['script'] = "linker-script-" + id + ".ld"
00516 
00517             # Unique IDs used in multiple places.
00518             uid = {}
00519             uid['config'] = u.id
00520             uid['tool_c_compiler'] = u.id
00521             uid['tool_c_compiler_input'] = u.id
00522             uid['tool_cpp_compiler'] = u.id
00523             uid['tool_cpp_compiler_input'] = u.id
00524 
00525             opts['uid'] = uid
00526 
00527             options[id] = opts
00528 
00529         ctx = {
00530             'name': self.project_name,
00531             'platform': platform,
00532             'include_paths': self.include_path ,
00533             'config_header': config_header,
00534             'exclude_paths': '|'.join(self.excluded_folders),
00535             'ld_script': ld_script,
00536             'library_paths': lib_dirs,
00537             'object_files': self.resources.objects,
00538             'libraries': libraries,
00539             'board_name': self.BOARDS [self.target.upper()]['name'],
00540             'mcu_name': self.BOARDS [self.target.upper()]['mcuId'],
00541             'cpp_cmd': preproc_cmd,
00542             'options': options,
00543             # id property of 'u' will generate new random identifier every time
00544             # when called.
00545             'u': u
00546         }
00547 
00548         self.__gen_dir ('.settings')
00549         self.gen_file('sw4stm32/language_settings_commom.tmpl',
00550                       ctx, '.settings/language.settings.xml')
00551         self.gen_file('sw4stm32/project_common.tmpl', ctx, '.project')
00552         self.gen_file('sw4stm32/cproject_common.tmpl', ctx, '.cproject')
00553         self.gen_file('sw4stm32/makefile.targets.tmpl', ctx,
00554                       'makefile.targets', trim_blocks=True, lstrip_blocks=True)
00555         self.gen_file('sw4stm32/launch.tmpl', ctx, self.project_name +
00556                       ' ' + options['debug']['name'] + '.launch')
00557 
00558     @staticmethod
00559     def clean (_):
00560         shutil.rmtree(".settings")