Alessandro Angelino / mbed-tools

Fork of mbed-tools by Morpheus

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers sw4stm32.py Source File

sw4stm32.py

00001 """
00002 mbed SDK
00003 Copyright (c) 2011-2016 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 exporters import Exporter
00018 from os.path import splitext, basename, join
00019 from random import randint
00020 from tools.utils import mkdir
00021 
00022 
00023 class Sw4STM32(Exporter):
00024     NAME = 'Sw4STM32'
00025     TOOLCHAIN = 'GCC_ARM'
00026 
00027     BOARDS = {
00028         # 'DISCO_F051R8':     {'name': 'STM32F0DISCOVERY',        'mcuId': 'STM32F051R8Tx'},
00029         # 'DISCO_F303VC':     {'name': 'STM32F3DISCOVERY',        'mcuId': 'STM32F303VCTx'},
00030         'DISCO_F334C8':     {'name': 'STM32F3348DISCOVERY',     'mcuId': 'STM32F334C8Tx'},
00031         # 'DISCO_F401VC':     {'name': 'STM32F401C-DISCO',        'mcuId': 'STM32F401VCTx'},
00032         'DISCO_F407VG':     {'name': 'STM32F4DISCOVERY',        'mcuId': 'STM32F407VGTx'},
00033         'DISCO_F429ZI':     {'name': 'STM32F429I-DISCO',        'mcuId': 'STM32F429ZITx'},
00034         'DISCO_F746NG':     {'name': 'STM32F746G-DISCO',        'mcuId': 'STM32F746NGHx'},
00035         'DISCO_L053C8':     {'name': 'STM32L0538DISCOVERY',     'mcuId': 'STM32L053C8Tx'},
00036         'DISCO_L476VG':     {'name':  'STM32L476G-DISCO',       'mcuId': 'STM32L476VGTx'},
00037         'DISCO_F469NI':     {'name': 'DISCO-F469NI',            'mcuId': 'STM32F469NIHx'},
00038         'NUCLEO_F030R8':    {'name': 'NUCLEO-F030R8',           'mcuId': 'STM32F030R8Tx'},
00039         'NUCLEO_F070RB':    {'name': 'NUCLEO-F070RB',           'mcuId': 'STM32F070RBTx'},
00040         'NUCLEO_F072RB':    {'name': 'NUCLEO-F072RB',           'mcuId': 'STM32F072RBTx'},
00041         'NUCLEO_F091RC':    {'name': 'NUCLEO-F091RC',           'mcuId': 'STM32F091RCTx'},
00042         'NUCLEO_F103RB':    {'name': 'NUCLEO-F103RB',           'mcuId': 'STM32F103RBTx'},
00043         'NUCLEO_F302R8':    {'name': 'NUCLEO-F302R8',           'mcuId': 'STM32F302R8Tx'},
00044         'NUCLEO_F303RE':    {'name': 'NUCLEO-F303RE',           'mcuId': 'STM32F303RETx'},
00045         'NUCLEO_F334R8':    {'name': 'NUCLEO-F334R8',           'mcuId': 'STM32F334R8Tx'},
00046         'NUCLEO_F401RE':    {'name': 'NUCLEO-F401RE',           'mcuId': 'STM32F401RETx'},
00047         'NUCLEO_F411RE':    {'name': 'NUCLEO-F411RE',           'mcuId': 'STM32F411RETx'},
00048         'NUCLEO_F446RE':    {'name': 'NUCLEO-F446RE',           'mcuId': 'STM32F446RETx'},
00049         'NUCLEO_L053R8':    {'name': 'NUCLEO-L053R8',           'mcuId': 'STM32L053R8Tx'},
00050         'NUCLEO_L073RZ':    {'name': 'NUCLEO-L073RZ',           'mcuId': 'STM32L073RZTx'},
00051         'NUCLEO_L152RE':    {'name': 'NUCLEO-L152RE',           'mcuId': 'STM32L152RETx'},
00052         'NUCLEO_L476RG':    {'name': 'NUCLEO-L476RG',           'mcuId': 'STM32L476RGTx'},
00053         'NUCLEO_F031K6':    {'name': 'NUCLEO-F031K6',           'mcuId': 'STM32F031K6Tx'},
00054         'NUCLEO_F042K6':    {'name': 'NUCLEO-F042K6',           'mcuId': 'STM32F042K6Tx'},
00055         'NUCLEO_F303K8':    {'name': 'NUCLEO-F303K8',           'mcuId': 'STM32F303K8Tx'},
00056         'NUCLEO_F410RB':    {'name': 'NUCLEO-F410RB',           'mcuId': 'STM32F410RBTx'},
00057     }
00058 
00059     TARGETS = BOARDS.keys()
00060 
00061     def __gen_dir(self, dirname):
00062         settings = join(self.inputDir, dirname)
00063         mkdir(settings)
00064 
00065     def __generate_uid(self):
00066         return "%0.9u" % randint(0, 999999999)
00067 
00068     def generate(self):
00069         libraries = []
00070         for lib in self.resources.libraries:
00071             l, _ = splitext(basename(lib))
00072             libraries.append(l[3:])
00073 
00074         ctx = {
00075             'name': self.program_name,
00076             'include_paths': self.resources.inc_dirs,
00077             'linker_script': self.resources.linker_script,
00078             'library_paths': self.resources.lib_dirs,
00079             'object_files': self.resources.objects,
00080             'libraries': libraries,
00081             'symbols': self.get_symbols(),
00082             'board_name': self.BOARDS[self.target.upper()]['name'],
00083             'mcu_name': self.BOARDS[self.target.upper()]['mcuId'],
00084             'debug_config_uid': self.__generate_uid(),
00085             'debug_tool_compiler_uid': self.__generate_uid(),
00086             'debug_tool_compiler_input_uid': self.__generate_uid(),
00087             'release_config_uid': self.__generate_uid(),
00088             'release_tool_compiler_uid': self.__generate_uid(),
00089             'release_tool_compiler_input_uid': self.__generate_uid(),
00090             'uid': self.__generate_uid()
00091         }
00092 
00093         self.__gen_dir('.settings')
00094         self.gen_file('sw4stm32_language_settings_commom.tmpl', ctx, '.settings/language.settings.xml')
00095         self.gen_file('sw4stm32_project_common.tmpl', ctx, '.project')
00096         self.gen_file('sw4stm32_cproject_common.tmpl', ctx, '.cproject')