You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
rebar_api:debug("Found pico device, using ~p from devices list: ~p", [Pico, Path]),
169
+
{ok, Pico};
170
+
_ ->
171
+
not_found
172
+
end.
152
173
153
174
%% @private
154
175
wait_for_mount(Mount, Count) whenCount<30->
155
-
try
156
-
casefile:read_link_info(Mount) of
157
-
{ok, #file_info{type=directory} =_Info} ->
158
-
ok;
159
-
_ ->
160
-
timer:sleep(1000),
161
-
wait_for_mount(Mount, Count+1)
162
-
end
163
-
catch
164
-
_ ->
165
-
timer:sleep(1000),
166
-
wait_for_mount(Mount, Count+1)
176
+
caseMountof
177
+
"" ->
178
+
casefind_mounted_pico() of
179
+
not_found ->
180
+
timer:sleep(1000),
181
+
wait_for_mount(Mount, Count+1);
182
+
{ok, Pico} ->
183
+
casefile:read_link_info(Pico) of
184
+
{ok, #file_info{type=directory} =_Info} ->
185
+
{ok, Pico};
186
+
Err ->
187
+
rebar_api:abort("Pico mount point is not a directory (~p)", [Err])
188
+
end
189
+
end;
190
+
Path ->
191
+
casefile:read_link_info(Path) of
192
+
{ok, #file_info{type=directory} =_Info} ->
193
+
{ok, Path};
194
+
_ ->
195
+
timer:sleep(1000),
196
+
wait_for_mount(Mount, Count+1)
197
+
end
167
198
end;
168
-
wait_for_mount(Mount, 30) ->
169
-
rebar_api:error("Pico not mounted at ~s after 30 seconds. giving up...", [Mount]),
170
-
erlang:throw(mount_error).
199
+
wait_for_mount(_Mount, 30) ->
200
+
rebar_api:abort("Pico not mounted after 30 seconds. giving up...", []).
171
201
172
202
%% @private
173
-
check_pico_mount(Mount) ->
174
-
try
175
-
casefile:read_link_info(Mount) of
176
-
{ok, #file_info{type=directory} =_Info} ->
177
-
rebar_api:debug("Pico mounted at ~s.", [Mount]),
178
-
ok;
179
-
_ ->
180
-
rebar_api:error("Pico not mounted at ~s.", [Mount]),
181
-
erlang:throw(no_device)
182
-
end
183
-
catch
184
-
_ ->
185
-
rebar_api:error("Pico not mounted at ~s.", [Mount]),
186
-
erlang:throw(no_device)
203
+
get_pico_mount(Mount) ->
204
+
caseMountof
205
+
"" ->
206
+
casefind_mounted_pico() of
207
+
not_found ->
208
+
rebar_api:info("Waiting for an RP2 device to mount...", []),
209
+
wait_for_mount(Mount, 0);
210
+
{ok, Pico} ->
211
+
{ok, Pico}
212
+
end;
213
+
Path ->
214
+
casefile:read_link_info(Path) of
215
+
{ok, #file_info{type=directory} =_Info} ->
216
+
rebar_api:debug("Pico mounted at ~s.", [Mount]),
217
+
{ok, Path};
218
+
_ ->
219
+
rebar_api:info("Waiting for the device at path ~s to mount...", [
220
+
string:trim(Mount)
221
+
]),
222
+
wait_for_mount(Mount, 0)
223
+
end
187
224
end.
188
225
189
226
%% @private
190
-
needs_reset(ResetBase) ->
191
-
casefilelib:wildcard(ResetBase)of
227
+
needs_reset(ResetDev) ->
228
+
caseResetDevof
192
229
[] ->
193
230
false;
194
231
[ResetPort | _T] ->
195
232
casefile:read_link_info(ResetPort) of
196
233
{ok, #file_info{type=device} =_Info} ->
197
234
{true, ResetPort};
235
+
{ok, #file_info{type=symlink} =_Info} ->
236
+
{true, ResetPort};
198
237
_ ->
199
238
false
200
239
end;
@@ -203,31 +242,30 @@ needs_reset(ResetBase) ->
203
242
end.
204
243
205
244
%% @private
206
-
do_reset(ResetPort) ->
245
+
do_reset(ResetPort, Picotool) ->
207
246
Flag=get_stty_file_flag(),
208
247
BootselMode=lists:join("", [
209
248
"stty", Flag, ResetPort, "1200"
210
249
]),
211
-
rebar_api:debug("Resetting device at path ~s", [ResetPort]),
250
+
rebar_api:info("Resetting device at path ~s", [ResetPort]),
212
251
ResetStatus=os:cmd(BootselMode),
213
252
caseResetStatusof
214
253
"" ->
215
254
ok;
216
255
Error ->
217
-
caseos:find_executable(picotool)of
218
-
false ->
219
-
rebar_api:error(
220
-
"Warning: ~s~nUnable to locate 'picotool', close the serial monitor before flashing, or install picotool for automatic disconnect and BOOTSEL mode.",
256
+
casePicotoolof
257
+
"" ->
258
+
rebar_api:abort(
259
+
"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.",
221
260
[Error]
222
-
),
223
-
erlang:throw(reset_error);
224
-
Picotool ->
261
+
);
262
+
RP2tool ->
225
263
rebar_api:warn(
226
264
"Warning: ~s~nFor faster flashing remember to disconnect serial monitor first.",
227
265
[Error]
228
266
),
229
267
DevReset=lists:join("", [
230
-
Picotool, "reboot", "-f", "-u"
268
+
RP2tool, "reboot", "-f", "-u"
231
269
]),
232
270
rebar_api:warn("Disconnecting serial monitor with: `~s' in 5 seconds...", [
233
271
DevReset
@@ -239,8 +277,7 @@ do_reset(ResetPort) ->
239
277
"The device was asked to reboot into BOOTSEL mode." ->
240
278
ok;
241
279
BootError ->
242
-
rebar_api:error("Failed to prepare pico for flashing: ~s", [BootError]),
243
-
erlang:throw(picoflash_reboot_error)
280
+
rebar_api:abort("Failed to prepare pico for flashing: ~s", [BootError])
0 commit comments