Skip to content

Commit ca86cbf

Browse files
Thomas SailerThomas Sailer
authored andcommitted
Code::Blocks project file exporter
1 parent 1529ad6 commit ca86cbf

File tree

7 files changed

+627
-6
lines changed

7 files changed

+627
-6
lines changed

targets/TARGET_ONSEMI/TARGET_NCS36510/device/TOOLCHAIN_GCC_ARM/NCS36510.ld

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
*/
44

55
MEMORY {
6+
FIB (rx) : ORIGIN = 0x00002000, LENGTH = 0x00000800
7+
TRIM (rx) : ORIGIN = 0x00002800, LENGTH = 0x00000800
68
VECTORS (rx) : ORIGIN = 0x00003000, LENGTH = 0x00000090
7-
FLASH (rx) : ORIGIN = 0x00003090, LENGTH = 320K - 4K - 0x90
8-
RAM (rwx) : ORIGIN = 0x3FFF4090, LENGTH = 48K - 0x90 /* 8_byte_aligned(35 vectors * 4 bytes each) = 0x90 */
9-
}
9+
FLASH (rx) : ORIGIN = 0x00003090, LENGTH = 320K - 4K - 0x90
10+
RAM (rwx) : ORIGIN = 0x3FFF4090, LENGTH = 48K - 0x90 /* 8_byte_aligned(35 vectors * 4 bytes each) = 0x90 */
11+
}
1012

1113
/* Linker script to place sections and symbol values. Should be used together
1214
* with other linker script that defines memory regions FLASH and RAM.
@@ -37,7 +39,17 @@ MEMORY {
3739
ENTRY(Reset_Handler)
3840

3941
SECTIONS {
40-
.isr_vector :
42+
.fib :
43+
{
44+
KEEP(*(.fib))
45+
} > FIB
46+
47+
.trim :
48+
{
49+
KEEP(*(.trim))
50+
} > TRIM
51+
52+
.isr_vector :
4153
{
4254
__vector_table = .;
4355
KEEP(*(.vector_table))

tools/export/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
from ..targets import TARGET_NAMES
3131
from . import (lpcxpresso, ds5_5, iar, makefile, embitz, coide, kds, simplicity,
3232
atmelstudio, mcuxpresso, sw4stm32, e2studio, zip, cmsis, uvision,
33-
cdt, vscode, gnuarmeclipse, qtcreator, cmake, nb, cces)
33+
cdt, vscode, gnuarmeclipse, qtcreator, cmake, nb, cces, codeblocks)
3434

3535
EXPORTERS = {
3636
u'uvision5': uvision.Uvision,
@@ -61,7 +61,8 @@
6161
u'vscode_iar' : vscode.VSCodeIAR,
6262
u'vscode_armc5' : vscode.VSCodeArmc5,
6363
u'cmake_gcc_arm': cmake.GccArm,
64-
u'cces' : cces.CCES
64+
u'cces' : cces.CCES,
65+
u'codeblocks': codeblocks.CodeBlocks
6566
}
6667

6768
ERROR_MESSAGE_UNSUPPORTED_TOOLCHAIN = """

tools/export/codeblocks/__init__.py

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
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)

tools/export/codeblocks/cbp.tmpl

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
2+
<CodeBlocks_project_file>
3+
<FileVersion major="1" minor="6" />
4+
<Project>
5+
<Option title="{{project_name}}" />
6+
<Option pch_mode="2" />
7+
<Option compiler="arm-elf-gcc" />
8+
<Build>
9+
<Target title="Debug">
10+
<Option output="bin/Debug/{{project_name}}.elf" prefix_auto="1" extension_auto="0" />
11+
<Option object_output="obj/Debug/" />
12+
<Option type="1" />
13+
<Option compiler="arm-elf-gcc" />
14+
<Option use_console_runner="0" />
15+
<Compiler>
16+
{% for f in debug_flags -%}
17+
<Add option="{{f}}" />
18+
{% endfor -%}
19+
</Compiler>
20+
<Linker>
21+
<Add option='-Wl,-Map,&quot;bin/Debug/{{project_name}}.map&quot;' />
22+
</Linker>
23+
{% if ncs36510addfib -%}
24+
<ExtraCommands>
25+
<Add after="arm-none-eabi-objcopy -O ihex -R .fib -R .trim bin/Debug/{{project_name}}.elf bin/Debug/{{project_name}}.hex" />
26+
<Add after="mbed-os/tools/export/codeblocks/ncs36510addfib.py bin/Debug/{{project_name}}.hex bin/Debug/{{project_name}}.fib" />
27+
<Add after="arm-none-eabi-objcopy --update-section .fib=bin/Debug/{{project_name}}.fib bin/Debug/{{project_name}}.elf" />
28+
<Add after="arm-none-eabi-objcopy -O ihex bin/Debug/{{project_name}}.elf bin/Debug/{{project_name}}.hex" />
29+
</ExtraCommands>
30+
{% endif -%}
31+
</Target>
32+
<Target title="Release">
33+
<Option output="bin/Release/{{project_name}}.elf" prefix_auto="1" extension_auto="0" />
34+
<Option object_output="obj/Release/" />
35+
<Option type="1" />
36+
<Option compiler="arm-elf-gcc" />
37+
<Option use_console_runner="0" />
38+
<Linker>
39+
<Add option='-Wl,-Map,&quot;bin/Release/{{project_name}}.map&quot;' />
40+
</Linker>
41+
{% if ncs36510addfib -%}
42+
<ExtraCommands>
43+
<Add after="arm-none-eabi-objcopy -O ihex -R .fib -R .trim bin/Release/{{project_name}}.elf bin/Release/{{project_name}}.hex" />
44+
<Add after="mbed-os/tools/export/codeblocks/ncs36510addfib.py bin/Release/{{project_name}}.hex bin/Release/{{project_name}}.fib" />
45+
<Add after="arm-none-eabi-objcopy --update-section .fib=bin/Release/{{project_name}}.fib bin/Release/{{project_name}}.elf" />
46+
<Add after="arm-none-eabi-objcopy -O ihex bin/Release/{{project_name}}.elf bin/Release/{{project_name}}.hex" />
47+
</ExtraCommands>
48+
{% endif -%}
49+
</Target>
50+
</Build>
51+
<Compiler>
52+
{% for f in comp_flags -%}
53+
<Add option="{{f}}" />
54+
{% endfor -%}
55+
{% for f in include_paths -%}
56+
<Add directory="{{f}}" />
57+
{% endfor -%}
58+
</Compiler>
59+
<Linker>
60+
{% for f in ld_flags -%}
61+
<Add option="{{f}}" />
62+
{% endfor -%}
63+
<Add option="-T {{linker_script}}" />
64+
{% for f in libraries -%}
65+
<Add library="{{f}}" />
66+
{% endfor -%}
67+
</Linker>
68+
{% for f in headers -%}
69+
<Unit filename="{{f}}"/>
70+
{% endfor -%}
71+
{% for f in c_sources -%}
72+
<Unit filename="{{f}}">
73+
<Option compilerVar="CC" />
74+
</Unit>
75+
{% endfor -%}
76+
{% for f in s_sources -%}
77+
<Unit filename="{{f}}">
78+
<Option compilerVar="CPP" />
79+
</Unit>
80+
{% endfor -%}
81+
{% for f in cpp_sources -%}
82+
<Unit filename="{{f}}">
83+
<Option compilerVar="CPP" />
84+
</Unit>
85+
{% endfor -%}
86+
<Extensions>
87+
{% if openocdboard != '' -%}
88+
<debugger>
89+
<remote_debugging target="Release">
90+
<options conn_type="3" serial_baud="115200" pipe_command="openocd -p -l openocd.log -f {{openocdboard}}" additional_cmds='monitor reset halt&#x0A;monitor flash write_image erase &quot;bin/Release/{{project_name}}.elf&quot;&#x0A;file &quot;bin/Release/{{project_name}}.elf&quot;&#x0A;monitor reset halt&#x0A;' extended_remote="1" />
91+
</remote_debugging>
92+
<remote_debugging target="Debug">
93+
<options conn_type="3" serial_baud="115200" pipe_command="openocd -p -l openocd.log -f {{openocdboard}}" additional_cmds='monitor reset halt&#x0A;monitor flash write_image erase &quot;bin/Debug/{{project_name}}.elf&quot;&#x0A;file &quot;bin/Debug/{{project_name}}.elf&quot;&#x0A;monitor reset halt&#x0A;' extended_remote="1" />
94+
</remote_debugging>
95+
</debugger>
96+
{% endif -%}
97+
</Extensions>
98+
</Project>
99+
</CodeBlocks_project_file>

0 commit comments

Comments
 (0)