Skip to content

Commit 9b1db83

Browse files
committed
Added required changes outside of TARGET_Cypress tree:
1. In drivers/Timer.cpp make sure that hardware timer is initialized outside of critical section. This is because on PSoC 6 hardware resources are shared between both cores and we have to make sure that the other core is not already using a particular resource. This mechanism is based on interprocessor communication taht cannot be handled iside of critical section. 2. Added support for post-binary hook function for PSoC 6 targets, so the hex image for M0+ CPU core can be merged with M4 core image for the final image. 3. Added possibility to use hook function from exportes, so the M0+ hex image could be included in the generated project. 4. Included hex images in the build dependency list, so the update of image is catched by the build process.
1 parent f906aac commit 9b1db83

File tree

12 files changed

+386
-13
lines changed

12 files changed

+386
-13
lines changed

drivers/Timer.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@ namespace mbed {
2323

2424
Timer::Timer() : _running(), _start(), _time(), _ticker_data(get_us_ticker_data()), _lock_deepsleep(true)
2525
{
26+
(void)ticker_read_us(_ticker_data); // Make sure h/w timer is initialized in non-critical context.
2627
reset();
2728
}
2829

2930
Timer::Timer(const ticker_data_t *data) : _running(), _start(), _time(), _ticker_data(data), _lock_deepsleep(true)
3031
{
32+
(void)ticker_read_us(_ticker_data); // Make sure h/w timer is initialized in non-critical context.
3133
reset();
3234
#if DEVICE_LPTICKER
3335
_lock_deepsleep = (data != get_lp_ticker_data());

features/storage/nvstore/mbed_lib.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,19 @@
2727
"macro_name": "NVSTORE_AREA_2_SIZE",
2828
"help": "Area 2 size"
2929
}
30+
},
31+
"target_overrides": {
32+
"FUTURE_SEQUANA": {
33+
"area_1_address": "0x100F8000",
34+
"area_1_size": 16384,
35+
"area_2_address": "0x100FC000",
36+
"area_2_size": 16384
37+
},
38+
"FUTURE_SEQUANA_M0": {
39+
"area_1_address": "0x10078000",
40+
"area_1_size": 16384,
41+
"area_2_address": "0x1007C000",
42+
"area_2_size": 16384
43+
}
3044
}
3145
}

targets/targets.json

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4533,5 +4533,82 @@
45334533
"detect_code": ["7016"],
45344534
"release_versions": ["5"],
45354535
"bootloader_supported": true
4536+
},
4537+
"MCU_PSOC6": {
4538+
"inherits": ["Target"],
4539+
"default_toolchain": "GCC_ARM",
4540+
"supported_toolchains": ["GCC_ARM", "IAR", "ARM"],
4541+
"core": "Cortex-M4F",
4542+
"OUTPUT_EXT": "hex",
4543+
"device_has": ["USTICKER", "INTERRUPTIN", "SERIAL", "SERIAL_ASYNCH", "SERIAL_FC", "PORTIN", "PORTOUT", "PORTINOUT", "RTC", "PWMOUT", "ANALOGIN", "ANALOGOUT", "I2C", "I2C_ASYNCH", "SPI", "SPI_ASYNCH", "STDIO_MESSAGES", "LPTICKER", "SLEEP", "FLASH" ],
4544+
"release_versions": ["5"],
4545+
"extra_labels": ["Cypress", "PSOC6"]
4546+
},
4547+
"MCU_PSOC6_M0": {
4548+
"inherits": ["MCU_PSOC6"],
4549+
"core": "Cortex-M0+",
4550+
"macros": ["MCU_PSOC6_M0"]
4551+
},
4552+
"MCU_PSOC6_M4": {
4553+
"inherits": ["MCU_PSOC6"],
4554+
"macros": ["MCU_PSOC6_M4"]
4555+
},
4556+
"FUTURE_SEQUANA_M0": {
4557+
"inherits": ["MCU_PSOC6_M0"],
4558+
"supported_form_factors": ["ARDUINO"],
4559+
"device_name": "CY8C6347BZI-BLD53M0+",
4560+
"extra_labels_add": ["CY8C63XX", "FUTURE_SEQUANA"],
4561+
"macros_add": ["CY8C6347BZI_BLD53"],
4562+
"detect_code": ["6000"],
4563+
"post_binary_hook": {
4564+
"function": "PSOC6Code.complete"
4565+
},
4566+
"config": {
4567+
"system-clock": {
4568+
"help": "Desired frequency of main clock (Hz)",
4569+
"value": "100000000UL",
4570+
"macro_name": "CY_CLK_HFCLK0_FREQ_HZ"
4571+
},
4572+
"peri-clock": {
4573+
"help": "Desired frequency of peripheral clock (Hz)",
4574+
"value": "50000000UL",
4575+
"macro_name": "CY_CLK_PERICLK_FREQ_HZ"
4576+
},
4577+
"m0-clock": {
4578+
"help": "Desired frequency of M0+ core clock (Hz)",
4579+
"value": "50000000UL",
4580+
"macro_name": "CY_CLK_SLOWCLK_FREQ_HZ"
4581+
}
4582+
}
4583+
},
4584+
"FUTURE_SEQUANA": {
4585+
"inherits": ["MCU_PSOC6_M4"],
4586+
"sub_target": "FUTURE_SEQUANA_M0",
4587+
"supported_form_factors": ["ARDUINO"],
4588+
"device_name": "CY8C6347BZI-BLD53M4",
4589+
"extra_labels_add": ["CY8C63XX", "CORDIO"],
4590+
"macros_add": ["CY8C6347BZI_BLD53"],
4591+
"detect_code": ["6000"],
4592+
"m0_core_img": "psoc63_m0_default_1.01.hex",
4593+
"post_binary_hook": {
4594+
"function": "PSOC6Code.complete"
4595+
},
4596+
"config": {
4597+
"system-clock": {
4598+
"help": "Desired frequency of main clock (Hz)",
4599+
"value": "100000000UL",
4600+
"macro_name": "CY_CLK_HFCLK0_FREQ_HZ"
4601+
},
4602+
"peri-clock": {
4603+
"help": "Desired frequency of peripheral clock (Hz)",
4604+
"value": "50000000UL",
4605+
"macro_name": "CY_CLK_PERICLK_FREQ_HZ"
4606+
},
4607+
"m0-clock": {
4608+
"help": "Desired frequency of M0+ core clock (Hz)",
4609+
"value": "50000000UL",
4610+
"macro_name": "CY_CLK_SLOWCLK_FREQ_HZ"
4611+
}
4612+
}
45364613
}
45374614
}

tools/export/__init__.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import copy
2525
from shutil import rmtree, copyfile
2626
import zipfile
27+
import inspect
28+
from inspect import getmro
2729

2830
from ..resources import Resources, FileType, FileRef
2931
from ..config import ALLOWED_FEATURES
@@ -129,6 +131,62 @@ def mcu_ide_matrix(verbose_html=False):
129131
return result
130132

131133

134+
def get_target_exporter(target, toolchain):
135+
"""Locate target-specyfic exporter function.
136+
Positional Arguments:
137+
target - the target object for inspection
138+
toolchain - the toolchain object for inspection
139+
"""
140+
# If there's no hook, simply return
141+
target_obj = toolchain.config.target
142+
try:
143+
hook_data = target_obj.post_binary_hook
144+
except AttributeError:
145+
return None
146+
# A hook was found. The hook's name is in the format
147+
# "classname.functionname"
148+
temp = hook_data["export_function"].split(".")
149+
if len(temp) != 2:
150+
raise HookError(
151+
("Invalid format for hook '%s' in target '%s'"
152+
% (hook_data["export_function"], target_obj.name)) +
153+
" (must be 'class_name.function_name')")
154+
class_name, function_name = temp
155+
# "class_name" must refer to a class in tools/targets module, so check if the
156+
# class exists
157+
from .. import targets
158+
from targets import HookError
159+
mdata = dict([(m[0], m[1]) for m in
160+
inspect.getmembers(sys.modules[targets.__name__])])
161+
162+
if class_name not in mdata or \
163+
not inspect.isclass(mdata[class_name]):
164+
print (mdata)
165+
raise HookError(
166+
("Class '%s' required by '%s' in target '%s'"
167+
% (class_name, hook_data["export_function"], target_obj.name)) +
168+
" not found in targets.py")
169+
# "function_name" must refer to a static function inside class
170+
# "class_name"
171+
cls = mdata[class_name]
172+
if (not hasattr(cls, function_name)) or \
173+
(not inspect.isfunction(getattr(cls, function_name))):
174+
raise HookError(
175+
("Static function '%s' " % function_name) +
176+
("required by '%s' " % hook_data["export_function"]) +
177+
("in target '%s' " % target_obj.name) +
178+
("not found in class '%s'" % class_name))
179+
# Check if the hook specification also has toolchain restrictions
180+
toolchain_restrictions = set(hook_data.get("toolchains", []))
181+
toolchain_labels = set(c.__name__ for c in getmro(toolchain.__class__))
182+
if toolchain_restrictions and \
183+
not toolchain_labels.intersection(toolchain_restrictions):
184+
return None
185+
# Finally, get the requested function
186+
print("Found function '%s' in class '%s'."% (function_name, class_name))
187+
return getattr(cls, function_name)
188+
189+
132190
def get_exporter_toolchain(ide):
133191
""" Return the exporter class and the toolchain string as a tuple
134192
@@ -158,6 +216,9 @@ def generate_project_files(resources, export_path, target, name, toolchain, ide,
158216
exporter_cls, _ = get_exporter_toolchain(ide)
159217
exporter = exporter_cls(target, export_path, name, toolchain,
160218
extra_symbols=macros, resources=resources)
219+
# Locate target-specyfic exporter if specified.
220+
exporter.TARGET_EXPORTER = get_target_exporter(target, toolchain)
221+
161222
exporter.generate()
162223
files = exporter.generated_files
163224
return files, exporter

tools/export/codeblocks/__init__.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ class CodeBlocks(GccArm):
3535
PREPROCESS_ASM = False
3636

3737
POST_BINARY_WHITELIST = set([
38-
"NCS36510TargetCode.ncs36510_addfib"
38+
"NCS36510TargetCode.ncs36510_addfib",
39+
"PSOC6Code.complete"
3940
])
4041

4142
@staticmethod
@@ -132,7 +133,9 @@ def generate(self):
132133
'NRF51_DK_LEGACY': 'board/nordic_nrf51_dk.cfg',
133134
'NRF51_DK_BOOT': 'board/nordic_nrf51_dk.cfg',
134135
'NRF51_DK_OTA': 'board/nordic_nrf51_dk.cfg',
135-
'NRF51_DK': 'board/nordic_nrf51_dk.cfg'
136+
'NRF51_DK': 'board/nordic_nrf51_dk.cfg',
137+
'FUTURE_SEQUANA': 'board/cy8ckit_062_ble.cfg',
138+
'FUTURE_SEQUANA_M0': 'board/cy8ckit_062_ble.cfg'
136139
}
137140

138141
if self.target in openocd_board:
@@ -162,7 +165,7 @@ def generate(self):
162165
if ignorefiles:
163166
with open(self.gen_file_dest('.mbedignore'), 'a') as f:
164167
for fi in ignorefiles:
165-
f.write("%s\n" % fi)
168+
f.write("%s\n" % fi)
166169

167170
# finally, generate the project file
168171
super(CodeBlocks, self).generate()

tools/export/exporters.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class Exporter(object):
5353
TARGETS = set()
5454
TOOLCHAIN = None
5555
CLEAN_FILES = ("GettingStarted.html",)
56-
56+
TARGET_EXPORTER = None
5757

5858
def __init__(self, target, export_dir, project_name, toolchain,
5959
extra_symbols=None, resources=None):

tools/export/gnuarmeclipse/__init__.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
1717
Title: GNU ARM Eclipse (http://gnuarmeclipse.github.io) exporter.
1818
19-
Description: Creates a managed build project that can be imported by
19+
Description: Creates a managed build project that can be imported by
2020
the GNU ARM Eclipse plug-ins.
2121
2222
Author: Liviu Ionescu <[email protected]>
@@ -64,7 +64,8 @@ def id(self):
6464
"TEENSY3_1Code.binary_hook",
6565
"MCU_NRF51Code.binary_hook",
6666
"LPCTargetCode.lpc_patch",
67-
"LPC4088Code.binary_hook"
67+
"LPC4088Code.binary_hook",
68+
"PSOC6Code.complete"
6869
])
6970

7071
class GNUARMEclipse(Exporter):
@@ -249,9 +250,9 @@ def build(project_name, log_name="build_log.txt", cleanup=True):
249250
Headless build an Eclipse project.
250251
251252
The following steps are performed:
252-
- a temporary workspace is created,
253+
- a temporary workspace is created,
253254
- the project is imported,
254-
- a clean build of all configurations is performed and
255+
- a clean build of all configurations is performed and
255256
- the temporary workspace is removed.
256257
257258
The build results are in the Debug & Release folders.
@@ -354,7 +355,7 @@ def compute_exclusions(self):
354355
The steps are:
355356
- get the list of source folders, as dirname(source_file)
356357
- compute the top folders (subfolders of the project folder)
357-
- iterate all subfolders and add them to a tree, with all
358+
- iterate all subfolders and add them to a tree, with all
358359
nodes markes as 'not used'
359360
- iterate the source folders and mark them as 'used' in the
360361
tree, including all intermediate nodes
@@ -401,8 +402,8 @@ def process_options(self, opts, flags_in):
401402
402403
Once identified, the options are removed from the command lines.
403404
404-
The options that were not identified are options that do not
405-
have CDT equivalents and will be passed in the 'Other options'
405+
The options that were not identified are options that do not
406+
have CDT equivalents and will be passed in the 'Other options'
406407
categories.
407408
408409
Although this process does not have a very complicated logic,

tools/export/iar/iar_definitions.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,5 +320,20 @@
320320
},
321321
"STM32L432KC": {
322322
"OGChipSelectEditMenu": "STM32L432KC\tST STM32L432KC"
323+
},
324+
"CY8C6347BZI-BLD53M0+": {
325+
"OGChipSelectEditMenu": "CY8C6347BZI-BLD53M0+\tCypress CY8C6347BZI-BLD53M0+",
326+
"CoreVariant": 35,
327+
"GFPUCoreSlave": 35,
328+
"GBECoreSlave": 35,
329+
"GFPUCoreSlave2": 35
330+
},
331+
"CY8C6347BZI-BLD53M4": {
332+
"OGChipSelectEditMenu": "CY8C6347BZI-BLD53M4\tCypress CY8C6347BZI-BLD53M4",
333+
"CoreVariant": 39,
334+
"GFPUCoreSlave": 39,
335+
"GBECoreSlave": 39,
336+
"FPU2": 6,
337+
"GFPUCoreSlave2": 39
323338
}
324339
}

tools/export/makefile/__init__.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ class Makefile(Exporter):
5454
"MCU_NRF51Code.binary_hook",
5555
"TEENSY3_1Code.binary_hook",
5656
"LPCTargetCode.lpc_patch",
57-
"LPC4088Code.binary_hook"
57+
"LPC4088Code.binary_hook",
58+
"PSOC6Code.complete"
5859
])
5960

6061
@classmethod
@@ -145,6 +146,12 @@ def generate(self):
145146
new_asm_flags.append(flag)
146147
ctx['asm_flags'] = new_asm_flags
147148

149+
# If there is a target-specific exporter function, call it now.
150+
if self.TARGET_EXPORTER:
151+
print ("Calling target exporter...")
152+
self.TARGET_EXPORTER(self, ctx)
153+
154+
# Generate makefiles.
148155
for templatefile in \
149156
['makefile/%s_%s.tmpl' % (self.TEMPLATE,
150157
self.target.lower())] + \
@@ -154,6 +161,7 @@ def generate(self):
154161
['makefile/%s.tmpl' % self.TEMPLATE]:
155162
try:
156163
self.gen_file(templatefile, ctx, 'Makefile')
164+
print("Generated Makefile from %s"%templatefile)
157165
break
158166
except TemplateNotFound:
159167
pass

0 commit comments

Comments
 (0)