7
7
//! - Enabling read protection
8
8
//! - Disabling read protection
9
9
//! - Resetting target
10
- //!
10
+ //!
11
11
//! All commands above can be combined in a single command line invocation by chaining them.
12
- //!
12
+ //!
13
13
//! If you need other commands, feel free to open an issue or a pull request. :smile:
14
14
//!
15
15
//! # Example usage:
28
28
//! ```sh
29
29
//! STM32_CUBE_PROGRAMMER_DIR=`installation_dir` stm32cubeprogrammer-cli unprotect reset flash-hex `path_to_hex_file` protect
30
30
//! ```
31
- //!
31
+ //!
32
32
//! Use the `--list` flag to list available probes.
33
33
//! ```sh
34
34
//! stm32cubeprogrammer-cli --stm32-cube-programmer-dir `installation_dir` --list
49
49
50
50
mod display_handler;
51
51
mod parse;
52
+ mod output;
52
53
53
54
use anyhow:: Context ;
54
55
use display_handler:: DisplayHandler ;
@@ -198,8 +199,14 @@ fn main() -> Result<(), anyhow::Error> {
198
199
// Parse command line arguments
199
200
let options = parse:: options ( ) . run ( ) ;
200
201
202
+ let verbosity = if options. quiet {
203
+ log:: LevelFilter :: Error
204
+ } else {
205
+ options. verbose
206
+ } ;
207
+
201
208
// Init api
202
- let display_handler = init_display_handler ( options . verbosity ) ;
209
+ let display_handler = init_display_handler ( verbosity) ;
203
210
let api = stm32cubeprogrammer:: CubeProgrammer :: builder ( )
204
211
. cube_programmer_dir ( & options. stm32_cube_programmer_dir )
205
212
. display_callback ( display_handler. clone ( ) )
@@ -255,8 +262,10 @@ fn main() -> Result<(), anyhow::Error> {
255
262
256
263
// Handle commands
257
264
for command in options. target_commands {
258
- match command {
265
+ let command_output = match command {
259
266
parse:: TargetCommand :: FlashBin ( bin_file_info) => {
267
+ log:: info!( "Flash binary file: {}" , bin_file_info) ;
268
+
260
269
display_handler
261
270
. lock ( )
262
271
. unwrap ( )
@@ -268,6 +277,8 @@ fn main() -> Result<(), anyhow::Error> {
268
277
. with_context ( || "Failed to flash binary file" ) ?;
269
278
}
270
279
parse:: TargetCommand :: FlashHex { file } => {
280
+ log:: info!( "Flash hex file: `{:?}`" , file) ;
281
+
271
282
display_handler
272
283
. lock ( )
273
284
. unwrap ( )
@@ -279,6 +290,8 @@ fn main() -> Result<(), anyhow::Error> {
279
290
. with_context ( || "Failed to flash hex file" ) ?;
280
291
}
281
292
parse:: TargetCommand :: UpdateBleStack ( ble_stack_info) => {
293
+ log:: info!( "Update BLE stack: {}" , ble_stack_info) ;
294
+
282
295
display_handler
283
296
. lock ( )
284
297
. unwrap ( )
@@ -318,7 +331,23 @@ fn main() -> Result<(), anyhow::Error> {
318
331
. with_context ( || "Failed to start BLE stack" ) ?;
319
332
}
320
333
}
334
+ parse:: TargetCommand :: BleStackInfo { compare } => {
335
+ let fus_programmer = programmer_connection. fus_connection ( ) ?;
336
+ let target_version = fus_programmer. fus_info ( ) . wireless_stack_version ;
337
+
338
+ log:: info!( "FUS info: {}" , fus_programmer. fus_info( ) ) ;
339
+
340
+ if let Some ( compare) = compare {
341
+ log:: info!( "Comparing BLE stack versions. Given version: {} ; Version on target: {} ; Stack up to date: {}" , compare, target_version, compare == target_version) ;
342
+ }
343
+
344
+ fus_programmer
345
+ . start_wireless_stack ( )
346
+ . with_context ( || "Failed to start BLE stack" ) ?;
347
+ }
321
348
parse:: TargetCommand :: Reset ( reset_mode) => {
349
+ log:: info!( "Resetting target: {:?}" , reset_mode) ;
350
+
322
351
display_handler
323
352
. lock ( )
324
353
. unwrap ( )
@@ -330,6 +359,8 @@ fn main() -> Result<(), anyhow::Error> {
330
359
. with_context ( || "Failed to reset target" ) ?;
331
360
}
332
361
parse:: TargetCommand :: MassErase => {
362
+ log:: info!( "Mass erase" ) ;
363
+
333
364
display_handler
334
365
. lock ( )
335
366
. unwrap ( )
@@ -341,6 +372,8 @@ fn main() -> Result<(), anyhow::Error> {
341
372
. with_context ( || "Failed to mass erase target" ) ?;
342
373
}
343
374
parse:: TargetCommand :: Protect => {
375
+ log:: info!( "Enable read protection" ) ;
376
+
344
377
display_handler
345
378
. lock ( )
346
379
. unwrap ( )
@@ -352,6 +385,8 @@ fn main() -> Result<(), anyhow::Error> {
352
385
. with_context ( || "Failed to enable read protection" ) ?;
353
386
}
354
387
parse:: TargetCommand :: Unprotect => {
388
+ log:: info!( "Disable read protection" ) ;
389
+
355
390
display_handler
356
391
. lock ( )
357
392
. unwrap ( )
0 commit comments