Skip to content

Commit

Permalink
Merge pull request #873 from flit/bugfix/flash_verify_init_failure
Browse files Browse the repository at this point in the history
Several flash related fixes
  • Loading branch information
flit committed May 17, 2020
1 parent f816900 commit 9c933a5
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 13 deletions.
2 changes: 1 addition & 1 deletion pyocd/core/coresight_target.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ def add_core(self, core):
def create_init_sequence(self):
seq = CallSequence(
('load_svd', self.load_svd),
('create_flash', self.create_flash),
('pre_connect', self.pre_connect),
('dp_init', self.dp.init_sequence),
('create_discoverer', self.create_discoverer),
Expand All @@ -144,6 +143,7 @@ def create_init_sequence(self):
('halt_on_connect', self.perform_halt_on_connect),
('post_connect', self.post_connect),
('post_connect_hook', self.post_connect_hook),
('create_flash', self.create_flash),
('notify', lambda : self.session.notify(Target.Event.POST_CONNECT, self))
)

Expand Down
6 changes: 5 additions & 1 deletion pyocd/flash/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,11 @@ def _enable_read_access(self):
memory mapped and accessible.
"""
if not self.algo_inited_for_read:
self.flash.init(self.flash.Operation.VERIFY)
try:
self.flash.init(self.flash.Operation.VERIFY)
except FlashFailure:
# If initing for verify fails, then try again in erase mode.
self.flash.init(self.flash.Operation.ERASE)
self.algo_inited_for_read = True

def _build_sectors_and_pages(self, keep_unwritten):
Expand Down
13 changes: 7 additions & 6 deletions pyocd/gdbserver/gdbserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -714,12 +714,13 @@ def flash_op(self, data):
elif b'FlashDone' in ops :
# Only program if we received data.
if self.flash_loader is not None:
# Write all buffered flash contents.
self.flash_loader.commit()

# Set flash loader to None so that on the next flash command a new
# object is used.
self.flash_loader = None
try:
# Write all buffered flash contents.
self.flash_loader.commit()
finally:
# Set flash loader to None so that on the next flash command a new
# object is used.
self.flash_loader = None

self.first_run_after_reset_or_flash = True
if self.thread_provider is not None:
Expand Down
4 changes: 1 addition & 3 deletions pyocd/target/builtin/target_MKL28Z512xxx7.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,12 @@ def __init__(self, target):
self._saved_firccsr = 0
self._saved_rccr = 0

def prepare_target(self, operation, address=None, clock=0, reset=True):
def prepare_target(self):
"""!
This function sets up target clocks to ensure that flash is clocked at the maximum
of 24MHz. Doing so gets the best flash programming performance. The FIRC clock source
is used so that there is no dependency on an external crystal frequency.
"""
super(Flash_kl28z, self).init(operation, address, clock, reset)

# Enable FIRC.
value = self.target.read32(SCG_FIRCCSR)
self._saved_firccsr = value
Expand Down
10 changes: 8 additions & 2 deletions pyocd/tools/pyocd.py
Original file line number Diff line number Diff line change
Expand Up @@ -1028,7 +1028,10 @@ def handle_savemem(self, args):
region = self.session.target.memory_map.get_region_for_address(addr)
flash_init_required = region is not None and region.is_flash and not region.is_powered_on_boot and region.flash is not None
if flash_init_required:
region.flash.init(region.flash.Operation.VERIFY)
try:
region.flash.init(region.flash.Operation.VERIFY)
except exceptions.FlashFailure:
region.flash.init(region.flash.Operation.ERASE)

data = bytearray(self.target.aps[self.selected_ap].read_memory_block8(addr, count))

Expand Down Expand Up @@ -1082,7 +1085,10 @@ def handle_compare(self, args):
region = self.session.target.memory_map.get_region_for_address(addr)
flash_init_required = region is not None and region.is_flash and not region.is_powered_on_boot and region.flash is not None
if flash_init_required:
region.flash.init(region.flash.Operation.VERIFY)
try:
region.flash.init(region.flash.Operation.VERIFY)
except exceptions.FlashFailure:
region.flash.init(region.flash.Operation.ERASE)

with open(filename, 'rb') as f:
file_data = f.read(length)
Expand Down

0 comments on commit 9c933a5

Please sign in to comment.