|
| 1 | +""" |
| 2 | +mbed SDK |
| 3 | +Copyright (c) 2014-2017 ARM Limited |
| 4 | +Copyright (c) 2018 Code::Blocks |
| 5 | +
|
| 6 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | +you may not use this file except in compliance with the License. |
| 8 | +You may obtain a copy of the License at |
| 9 | +
|
| 10 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +
|
| 12 | +Unless required by applicable law or agreed to in writing, software |
| 13 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | +See the License for the specific language governing permissions and |
| 16 | +limitations under the License. |
| 17 | +""" |
| 18 | +import copy |
| 19 | +import os |
| 20 | +from os.path import splitext, basename |
| 21 | +from os import remove |
| 22 | +from shutil import rmtree |
| 23 | +from tools.targets import TARGET_MAP |
| 24 | +from tools.export.exporters import Exporter |
| 25 | +from tools.export.makefile import GccArm |
| 26 | + |
| 27 | +class CodeBlocks(GccArm): |
| 28 | + NAME = 'Code::Blocks' |
| 29 | + |
| 30 | + DOT_IN_RELATIVE_PATH = True |
| 31 | + |
| 32 | + MBED_CONFIG_HEADER_SUPPORTED = True |
| 33 | + |
| 34 | + PREPROCESS_ASM = False |
| 35 | + |
| 36 | + POST_BINARY_WHITELIST = set([ |
| 37 | + "NCS36510TargetCode.ncs36510_addfib" |
| 38 | + ]) |
| 39 | + |
| 40 | + @staticmethod |
| 41 | + def filter_dot(str_in): |
| 42 | + """ |
| 43 | + Remove the './' prefix, if present. |
| 44 | + This function assumes that resources.win_to_unix() |
| 45 | + replaced all windows backslashes with slashes. |
| 46 | + """ |
| 47 | + if str_in is None: |
| 48 | + return None |
| 49 | + if str_in[:2] == './': |
| 50 | + return str_in[2:] |
| 51 | + return str_in |
| 52 | + |
| 53 | + def generate(self): |
| 54 | + self.resources.win_to_unix() |
| 55 | + |
| 56 | + comp_flags = [] |
| 57 | + debug_flags = [] |
| 58 | + next_is_include = False |
| 59 | + for f in self.flags['c_flags'] + self.flags['cxx_flags'] + self.flags['common_flags']: |
| 60 | + f=f.strip() |
| 61 | + if f == "-include": |
| 62 | + next_is_include = True |
| 63 | + continue |
| 64 | + if f == 'c': |
| 65 | + continue |
| 66 | + if next_is_include: |
| 67 | + f = '-include ' + f |
| 68 | + next_is_include = False |
| 69 | + if f.startswith('-O') or f.startswith('-g'): |
| 70 | + debug_flags.append(f) |
| 71 | + continue |
| 72 | + comp_flags.append(f) |
| 73 | + comp_flags = list(set(comp_flags)) |
| 74 | + inc_dirs = [self.filter_dot(s) for s in self.resources.inc_dirs]; |
| 75 | + inc_dirs = [x for x in inc_dirs if x is not None and x != '' and x != '.' and not x.startswith('bin') and not x.startswith('obj')]; |
| 76 | + |
| 77 | + c_sources = [self.filter_dot(s) for s in self.resources.c_sources] |
| 78 | + targ = TARGET_MAP[self.target] |
| 79 | + ncs36510fib = hasattr(targ, 'post_binary_hook') and targ.post_binary_hook['function'] == 'NCS36510TargetCode.ncs36510_addfib' |
| 80 | + if ncs36510fib: |
| 81 | + c_sources.append('ncs36510fib.c') |
| 82 | + c_sources.append('ncs36510trim.c') |
| 83 | + |
| 84 | + ctx = { |
| 85 | + 'project_name': self.project_name, |
| 86 | + 'debug_flags': debug_flags, |
| 87 | + 'comp_flags': comp_flags, |
| 88 | + 'ld_flags': self.flags['ld_flags'], |
| 89 | + 'headers': list(set([self.filter_dot(s) for s in self.resources.headers])), |
| 90 | + 'c_sources': c_sources, |
| 91 | + 's_sources': [self.filter_dot(s) for s in self.resources.s_sources], |
| 92 | + 'cpp_sources': [self.filter_dot(s) for s in self.resources.cpp_sources], |
| 93 | + 'include_paths': inc_dirs, |
| 94 | + 'linker_script': self.filter_dot(self.resources.linker_script), |
| 95 | + 'libraries': self.resources.libraries, |
| 96 | + 'ncs36510addfib': ncs36510fib, |
| 97 | + 'openocdboard': '' |
| 98 | + } |
| 99 | + |
| 100 | + openocd_board = { |
| 101 | + 'NCS36510': 'board/ncs36510_axdbg.cfg', |
| 102 | + 'DISCO_F429ZI': 'board/stm32f429discovery.cfg', |
| 103 | + 'DISCO_F469NI': 'board/stm32f469discovery.cfg', |
| 104 | + 'DISCO_L053C8': 'board/stm32l0discovery.cfg', |
| 105 | + 'DISCO_L072CZ_LRWAN1': 'board/stm32l0discovery.cfg', |
| 106 | + 'DISCO_F769NI': 'board/stm32f7discovery.cfg', |
| 107 | + 'DISCO_L475VG_IOT01A': 'board/stm32l4discovery.cfg', |
| 108 | + 'DISCO_L476VG': 'board/stm32l4discovery.cfg', |
| 109 | + 'NRF51822': 'board/nordic_nrf51822_mkit.cfg', |
| 110 | + 'NRF51822_BOOT': 'board/nordic_nrf51822_mkit.cfg', |
| 111 | + 'NRF51822_OTA': 'board/nordic_nrf51822_mkit.cfg', |
| 112 | + 'NRF51_DK_LEGACY': 'board/nordic_nrf51_dk.cfg', |
| 113 | + 'NRF51_DK_BOOT': 'board/nordic_nrf51_dk.cfg', |
| 114 | + 'NRF51_DK_OTA': 'board/nordic_nrf51_dk.cfg', |
| 115 | + 'NRF51_DK': 'board/nordic_nrf51_dk.cfg' |
| 116 | + } |
| 117 | + |
| 118 | + if self.target in openocd_board: |
| 119 | + ctx['openocdboard'] = openocd_board[self.target] |
| 120 | + |
| 121 | + self.gen_file('codeblocks/cbp.tmpl', ctx, "%s.%s" % (self.project_name, 'cbp')) |
| 122 | + |
| 123 | + if ncs36510fib: |
| 124 | + ctx = { |
| 125 | + 'mac_addr_low': 0xFFFFFFFF, |
| 126 | + 'mac_addr_high': 0xFFFFFFFF, |
| 127 | + 'clk_32k_trim': 0x39, |
| 128 | + 'clk_32m_trim': 0x17, |
| 129 | + 'rssi': 0x3D, |
| 130 | + 'txtune': 0xFFFFFFFF |
| 131 | + } |
| 132 | + if hasattr(targ, 'config'): |
| 133 | + for an, cn in [ ['mac-addr-low', 'mac_addr_low'], ['mac-addr-high', 'mac_addr_high'], |
| 134 | + ['32KHz-clk-trim', 'clk_32k_trim'], ['32MHz-clk-trim', 'clk_32m_trim'], |
| 135 | + ['rssi-trim', 'rssi'], ['txtune-trim', 'txtune'] ]: |
| 136 | + if an in targ.config: |
| 137 | + if 'value' in targ.config[an]: |
| 138 | + ctx[cn] = int(targ.config[an]['value'], 0) |
| 139 | + for f in [ 'ncs36510fib.c', 'ncs36510trim.c' ]: |
| 140 | + self.gen_file("codeblocks/%s" % f, ctx, f) |
| 141 | + |
| 142 | + # finally, generate the project file |
| 143 | + super(CodeBlocks, self).generate() |
| 144 | + |
| 145 | + @staticmethod |
| 146 | + def clean(project_name): |
| 147 | + for ext in ['cbp', 'depend', 'layout']: |
| 148 | + remove("%s.%s" % (project_name, ext)) |
| 149 | + for f in ['openocd.log', 'ncs36510fib.c', 'ncs36510trim.c']: |
| 150 | + remove(f) |
| 151 | + for d in ['bin', 'obj']: |
| 152 | + rmtree(d, ignore_errors=True) |
0 commit comments