Skip to content

Commit 17a671c

Browse files
carlescufikartben
authored andcommitted
scripts: runners: nrf: Default to soft reset for the nRF52 series
The Nordic nRF52 series have a peculiarity that is not shared with any other Nordic families of SoCs: the reset pin can be reconfigured as a regular GPIO. This has an unintended consequence: if the user has reconfigured the pin in Devicetree to be a GPIO, `west flash` will override that and configure the IC to use it as a reset pin, and the firmware at boot won't be able to switch it back to GPIO, because that requires a UICR erase. This behavior is very confusing to users, because the GPIO does not work at all, since it is now just a reset line. With this patch, `west flash` defaults to using soft reset instead of pin reset for the nRF52 family of devices, to avoid overwriting the reset pin configuration that the user includes in the image. In order to be able to continue to use pin reset for users that so desire it, a new option `--pinreset` is added that forces the use of pin reset. The existing `--softreset` option is left exactly as it was, but it is now applicable only to families other than the nRF52. Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
1 parent a316ca9 commit 17a671c

File tree

5 files changed

+81
-57
lines changed

5 files changed

+81
-57
lines changed

doc/releases/migration-guide-4.1.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ Boards
5050
the required configuration by using ``mikroe_weather_click_i2c`` or ``mikroe_weather_click_spi``
5151
instead of ``mikroe_weather_click``.
5252

53+
* All nRF52-based boards will now default to soft (system) reset
54+
instead of pin reset when flashing with ``west flash``. If you want to keep
55+
using pin reset on the nRF52 family of ICs you can use ``west flash --pinreset``.
56+
5357
Devicetree
5458
**********
5559

scripts/west_commands/runners/nrf_common.py

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,14 @@ def _get_suit_starter():
7878
class NrfBinaryRunner(ZephyrBinaryRunner):
7979
'''Runner front-end base class for nrf tools.'''
8080

81-
def __init__(self, cfg, family, softreset, dev_id, erase=False,
81+
def __init__(self, cfg, family, softreset, pinreset, dev_id, erase=False,
8282
reset=True, tool_opt=None, force=False, recover=False):
8383
super().__init__(cfg)
8484
self.hex_ = cfg.hex_file
8585
# The old --nrf-family options takes upper-case family names
8686
self.family = family.lower() if family else None
8787
self.softreset = softreset
88+
self.pinreset = pinreset
8889
self.dev_id = dev_id
8990
self.erase = bool(erase)
9091
self.reset = bool(reset)
@@ -117,9 +118,14 @@ def do_add_parser(cls, parser):
117118
'NRF54H', 'NRF91', 'NRF92'],
118119
help='''MCU family; still accepted for
119120
compatibility only''')
121+
# Not using a mutual exclusive group for softreset and pinreset due to
122+
# the way dump_runner_option_help() works in run_common.py
120123
parser.add_argument('--softreset', required=False,
121124
action='store_true',
122-
help='use reset instead of pinreset')
125+
help='use softreset instead of pinreset')
126+
parser.add_argument('--pinreset', required=False,
127+
action='store_true',
128+
help='use pinreset instead of softreset')
123129
parser.add_argument('--snr', required=False, dest='dev_id',
124130
help='obsolete synonym for -i/--dev-id')
125131
parser.add_argument('--force', required=False,
@@ -412,13 +418,18 @@ def program_hex(self):
412418

413419

414420
def reset_target(self):
415-
if self.family == 'nrf52' and not self.softreset:
421+
# Default to soft reset on nRF52 only, because ICs in these series can
422+
# reconfigure the reset pin as a regular GPIO
423+
default = "RESET_SYSTEM" if self.family == 'nrf52' else "RESET_PIN"
424+
kind = ("RESET_SYSTEM" if self.softreset else "RESET_PIN" if
425+
self.pinreset else default)
426+
427+
if self.family == 'nrf52' and kind == "RESET_PIN":
428+
# Write to the UICR enabling nRESET in the corresponding pin
416429
self.exec_op('pinreset-enable')
417430

418-
if self.softreset:
419-
self.exec_op('reset', kind="RESET_SYSTEM")
420-
else:
421-
self.exec_op('reset', kind="RESET_PIN")
431+
self.logger.debug(f'Reset kind: {kind}')
432+
self.exec_op('reset', kind=kind)
422433

423434
@abc.abstractmethod
424435
def do_require(self):
@@ -488,6 +499,10 @@ def flush_ops(self, force=True):
488499
def do_run(self, command, **kwargs):
489500
self.do_require()
490501

502+
if self.softreset and self.pinreset:
503+
raise RuntimeError('Options --softreset and --pinreset are mutually '
504+
'exclusive.')
505+
491506
self.ensure_output('hex')
492507
if IntelHex is None:
493508
raise RuntimeError('Python dependency intelhex was missing; '

scripts/west_commands/runners/nrfjprog.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
class NrfJprogBinaryRunner(NrfBinaryRunner):
1818
'''Runner front-end for nrfjprog.'''
1919

20-
def __init__(self, cfg, family, softreset, dev_id, erase=False,
20+
def __init__(self, cfg, family, softreset, pinreset, dev_id, erase=False,
2121
reset=True, tool_opt=None, force=False, recover=False,
2222
qspi_ini=None):
2323

24-
super().__init__(cfg, family, softreset, dev_id, erase, reset,
24+
super().__init__(cfg, family, softreset, pinreset, dev_id, erase, reset,
2525
tool_opt, force, recover)
2626

2727
self.qspi_ini = qspi_ini
@@ -37,7 +37,7 @@ def tool_opt_help(cls) -> str:
3737
@classmethod
3838
def do_create(cls, cfg, args):
3939
return NrfJprogBinaryRunner(cfg, args.nrf_family, args.softreset,
40-
args.dev_id, erase=args.erase,
40+
args.pinreset, args.dev_id, erase=args.erase,
4141
reset=args.reset,
4242
tool_opt=args.tool_opt, force=args.force,
4343
recover=args.recover, qspi_ini=args.qspi_ini)

scripts/west_commands/runners/nrfutil.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
class NrfUtilBinaryRunner(NrfBinaryRunner):
1717
'''Runner front-end for nrfutil.'''
1818

19-
def __init__(self, cfg, family, softreset, dev_id, erase=False,
19+
def __init__(self, cfg, family, softreset, pinreset, dev_id, erase=False,
2020
reset=True, tool_opt=None, force=False, recover=False,
2121
suit_starter=False):
2222

23-
super().__init__(cfg, family, softreset, dev_id, erase, reset,
23+
super().__init__(cfg, family, softreset, pinreset, dev_id, erase, reset,
2424
tool_opt, force, recover)
2525

2626
self.suit_starter = suit_starter
@@ -39,7 +39,7 @@ def tool_opt_help(cls) -> str:
3939
@classmethod
4040
def do_create(cls, cfg, args):
4141
return NrfUtilBinaryRunner(cfg, args.nrf_family, args.softreset,
42-
args.dev_id, erase=args.erase,
42+
args.pinreset, args.dev_id, erase=args.erase,
4343
reset=args.reset,
4444
tool_opt=args.tool_opt, force=args.force,
4545
recover=args.recover,

0 commit comments

Comments
 (0)