-
Notifications
You must be signed in to change notification settings - Fork 1
/
nrf_flash_latest.pl
executable file
·45 lines (33 loc) · 1.15 KB
/
nrf_flash_latest.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#! /usr/bin/env perl
# Flasher tool for programming an nRF5x controller via the Segger J-Link programmer
# Relies on the Segger tools and the nrfjprog tool that can be installed with homebrew
# brew cask install nrf5x-command-line-tools
#
# Written by Lieven Hollevoet
#
use strict;
use warnings;
use 5.012;
use Time::localtime;
use File::stat;
# Find latest binfile to flash
my @files = <~/Downloads/*.hex>;
my $file;
my $to_flash;
$to_flash->{'created'} = 0;
foreach $file (@files) {
# print "\nFile: $file";
# print "\n Last access time: ", ctime( stat($file)->atime );
# print "\n Last modify time: ", ctime( stat($file)->mtime );
# print "\n File creation time: ", ctime( stat($file)->ctime );
# print "\n File creation time: ", stat($file)->ctime ;
my $created = stat($file)->ctime;
if ($to_flash->{'created'} < $created) {
$to_flash->{'created'} = $created;
$to_flash->{'file'} = $file;
}
}
say "Going to flash $to_flash->{'file'}\n\tcreated " . ctime($to_flash->{'created'}) . "\n\tto device";
# Execute command
system("nrfjprog -s 681684213 --program $to_flash->{'file'} --chiperase --verify");
say "Done";