Skip to content

Commit 46bd7de

Browse files
committed
Make pico_flash provider picotool path configurable
Changes the pico_flash provider to allow setting the full path to picotool as an environment variable, in rebar.config, or from cli parameters when exacuting the task. Closes #40 Signed-off-by: Winford <winford@object.stream>
1 parent ec4fd6d commit 46bd7de

File tree

3 files changed

+30
-13
lines changed

3 files changed

+30
-13
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1616
### Added
1717
- Added dialyzer task to simplify running dialyzer on AtomVM applications.
1818
- Added support for rp2350 devices to allow for default detection of the device mount path.
19+
- Added configuration paramenter for setting the path to picotool for the pico_flash task.
1920

2021
### Changed
2122
- The `uf2create` task now creates `universal` format uf2 files by default, suitable for both

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,7 @@ The following table enumerates the properties that may be defined in your projec
449449
|-----|------|-------------|
450450
| `path` | `string()` | Path to pico device |
451451
| `reset` | `string()` | Path to serial device to reset before flashing |
452+
| `picotool` | `string()` | Path to picotool executable |
452453

453454
Example:
454455

@@ -458,6 +459,7 @@ Alternatively, the following environment variables may be used to control the ab
458459

459460
* `ATOMVM_REBAR3_PLUGIN_PICO_MOUNT_PATH` | `ATOMVM_PICO_MOUNT_PATH`
460461
* `ATOMVM_REBAR3_PLUGIN_PICO_RESET_DEV` | `ATOMVM_PICO_RESET_DEV`
462+
* `ATOMVM_REBAR3_PLUGIN_PICOTOOL` | `ATOMVM_PICOTOOL`
461463

462464
Any setting specified on the command line take precedence over entries in `rebar.config`, which in turn take precedence over environment variable settings, which in turn take precedence over the default values specified above.
463465

src/atomvm_pico_flash_provider.erl

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@
3434
{path, $p, "path", string,
3535
"Path to pico device (Defaults Linux: /run/media/${USER}/RPI-RP2, MacOS: /Volumes/RPI-RP2)"},
3636
{reset, $r, "reset", string,
37-
"Path to serial device to reset before flashing (Defaults Linux: /dev/ttyACM0, MacOS: /dev/cu.usbmodem14*)"}
37+
"Path to serial device to reset before flashing (Defaults Linux: /dev/ttyACM0, MacOS: /dev/cu.usbmodem14*)"},
38+
{picotool, $t, "picotool", string, "Path to picotool utility (Default is to search in PATH)"}
3839
]).
3940

4041
%%
@@ -72,7 +73,8 @@ do(State) ->
7273
ok = do_flash(
7374
rebar_state:project_apps(State),
7475
maps:get(path, Opts),
75-
maps:get(reset, Opts)
76+
maps:get(reset, Opts),
77+
maps:get(picotool, Opts)
7678
),
7779
{ok, State}
7880
catch
@@ -109,9 +111,22 @@ env_opts() ->
109111
reset => os:getenv(
110112
"ATOMVM_REBAR3_PLUGIN_PICO_RESET_DEV",
111113
get_reset_dev()
114+
),
115+
picotool => os:getenv(
116+
"ATOMVM_REBAR3_PLUGIN_PICOTOOL",
117+
os:getenv("ATOMVM_PICOTOOL", find_picotool())
112118
)
113119
}.
114120

121+
%% @private
122+
find_picotool() ->
123+
case os:find_executable("picotool") of
124+
false ->
125+
"";
126+
Picotool ->
127+
Picotool
128+
end.
129+
115130
%% @private
116131
get_stty_file_flag() ->
117132
{_Fam, System} = os:type(),
@@ -228,7 +243,7 @@ needs_reset(ResetDev) ->
228243
end.
229244

230245
%% @private
231-
do_reset(ResetPort) ->
246+
do_reset(ResetPort, Picotool) ->
232247
Flag = get_stty_file_flag(),
233248
BootselMode = lists:join(" ", [
234249
"stty", Flag, ResetPort, "1200"
@@ -239,20 +254,19 @@ do_reset(ResetPort) ->
239254
"" ->
240255
ok;
241256
Error ->
242-
case os:find_executable(picotool) of
243-
false ->
244-
rebar_api:error(
245-
"Warning: ~s~nUnable to locate 'picotool', close the serial monitor before flashing, or install picotool for automatic disconnect and BOOTSEL mode.",
257+
case Picotool of
258+
"" ->
259+
rebar_api:abort(
260+
"Warning: ~s~nUnable to locate 'picotool', close the serial monitor before flashing, or supply the path to picotool if it is not installed in your PATH for automatic disconnect and BOOTSEL mode.",
246261
[Error]
247-
),
248-
erlang:throw(reset_error);
249-
Picotool ->
262+
);
263+
RP2tool ->
250264
rebar_api:warn(
251265
"Warning: ~s~nFor faster flashing remember to disconnect serial monitor first.",
252266
[Error]
253267
),
254268
DevReset = lists:join(" ", [
255-
Picotool, "reboot", "-f", "-u"
269+
RP2tool, "reboot", "-f", "-u"
256270
]),
257271
rebar_api:warn("Disconnecting serial monitor with: `~s' in 5 seconds...", [
258272
DevReset
@@ -284,14 +298,14 @@ get_uf2_appname(ProjectApps) ->
284298
binary_to_list(rebar_app_info:name(App)).
285299

286300
%% @private
287-
do_flash(ProjectApps, PicoPath, ResetDev) ->
301+
do_flash(ProjectApps, PicoPath, ResetDev, Picotool) ->
288302
case needs_reset(ResetDev) of
289303
false ->
290304
rebar_api:debug("No Pico reset device found matching ~s.", [ResetDev]),
291305
ok;
292306
{true, ResetPort} ->
293307
rebar_api:debug("Pico at ~s needs reset...", [ResetPort]),
294-
do_reset(ResetPort),
308+
do_reset(ResetPort, Picotool),
295309
rebar_api:info("Waiting for the device at path ~s to settle and mount...", [PicoPath]),
296310
wait_for_mount(PicoPath, 0)
297311
end,

0 commit comments

Comments
 (0)