Skip to content

Commit

Permalink
upload_fs: Add Jlink serial number to uploader script
Browse files Browse the repository at this point in the history
  • Loading branch information
Leonardo da Silva Bispo authored and Kampi committed Jul 31, 2024
1 parent 2dbc15f commit 34c3315
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 8 deletions.
12 changes: 10 additions & 2 deletions app/scripts/rtt_flash_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,20 @@ def load_data(jlink, file, partition):


def rtt_run_flush_loader(
target_device, file, partition, jlink_speed="auto", read_data_only=False
target_device,
file,
partition,
jlink_speed="auto",
read_data_only=False,
serial_number=None,
):
"""Creates connection to target via RTT and either writes a file or reads from flash.
Args:
target_device (string): The target CPU to connect to.
file (string): The binary file to write to target or dump target flash content in.
read_data_only (bool): optional bool indication if flash should be read instead of written to.
serial_number (string): JLink serial number
Returns:
Always returns ``0`` or a JLinkException.
Expand All @@ -174,7 +180,7 @@ def rtt_run_flush_loader(
"""
jlink = pylink.JLink()
print("Connecting to JLink...")
jlink.open()
jlink.open(serial_no=serial_number)
print("Connecting to %s..." % target_device)
jlink.set_tif(pylink.enums.JLinkInterfaces.SWD)

Expand Down Expand Up @@ -241,6 +247,7 @@ def rtt_run_flush_loader(
jlink.close()
pass


def erase_external_flash(target_device, jlink_speed="auto"):
jlink = pylink.JLink()
print("Connecting to JLink...")
Expand All @@ -261,6 +268,7 @@ def erase_external_flash(target_device, jlink_speed="auto"):
jlink.reset(0, False)
print("Done. Wait for watch ti reboot...")


if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Open RTT console.")
parser.add_argument(
Expand Down
33 changes: 27 additions & 6 deletions app/scripts/upload_fs_west_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,39 @@ def do_add_parser(self, parser_adder):
default="raw",
help="raw or fs. fs to load littlefs image, raw to load custom binary",
)

parser.add_argument(
"--read_file", type=str, help="If set dump flash to this filename"
)

parser.add_argument(
"-p",
"--partition",
type=str,
help="Label of partition in DTS to write to. Leave blank to use auto guess name.",
)

parser.add_argument(
"--speed",
help="JLink speed (int): connection speed in kHz, one of {5-12000, 'auto', 'adaptive'}",
default="auto",
required=False,
)

parser.add_argument(
"--speed", help="JLink speed (int): connection speed in kHz, one of {5-12000, 'auto', 'adaptive'}", default='auto', required=False
)
"-s",
"--serial_number",
type=str,
help="JLink serial number",
default=None,
required=False,
)

return parser

def do_run(self, args, unknown_args):
if args.erase:
sys.exit(
erase_external_flash("nRF5340_XXAA")
)
sys.exit(erase_external_flash("nRF5340_XXAA"))
return
log.inf("Creating image")
img_size = 2 * 1024 * 1024
Expand Down Expand Up @@ -92,5 +106,12 @@ def do_run(self, args, unknown_args):
)
log.inf("Uploading image")
sys.exit(
rtt_run_flush_loader("nRF5340_XXAA", filename, partition, args.speed, args.read_file)
rtt_run_flush_loader(
"nRF5340_XXAA",
filename,
partition,
args.speed,
args.read_file,
args.serial_number,
)
)

0 comments on commit 34c3315

Please sign in to comment.