@@ -129,6 +129,7 @@ static const char *help_text =
129129"Specific commands for the board:\n"
130130" pyb.info() -- print some general information\n"
131131" pyb.gc() -- run the garbage collector\n"
132+ " pyb.repl_info(<val>) -- enable/disable printing of info after each command\n"
132133" pyb.delay(<n>) -- wait for n milliseconds\n"
133134" pyb.Led(<n>) -- create Led object for LED n (n=1,2)\n"
134135" Led methods: on(), off()\n"
@@ -215,6 +216,13 @@ static mp_obj_t pyb_info(void) {
215216 return mp_const_none ;
216217}
217218
219+ static bool repl_display_debugging_info = 0 ;
220+
221+ static mp_obj_t pyb_set_repl_info (mp_obj_t o_value ) {
222+ repl_display_debugging_info = mp_obj_get_int (o_value );
223+ return mp_const_none ;
224+ }
225+
218226#if MICROPY_HW_HAS_SDCARD
219227// SD card test
220228static mp_obj_t pyb_sd_test (void ) {
@@ -429,15 +437,18 @@ void do_repl(void) {
429437 if (nlr_push (& nlr ) == 0 ) {
430438 rt_call_function_0 (module_fun );
431439 nlr_pop ();
432- // optional timing
433- if (0 ) {
434- uint32_t ticks = sys_tick_counter - start ; // TODO implement a function that does this properly
435- printf ("(took %lu ms)\n" , ticks );
436- }
437440 } else {
438441 // uncaught exception
439442 mp_obj_print_exception ((mp_obj_t )nlr .ret_val );
440443 }
444+
445+ // display debugging info if wanted
446+ if (repl_display_debugging_info ) {
447+ uint32_t ticks = sys_tick_counter - start ; // TODO implement a function that does this properly
448+ printf ("took %lu ms\n" , ticks );
449+ gc_collect ();
450+ pyb_info ();
451+ }
441452 }
442453 }
443454 }
@@ -643,6 +654,8 @@ int main(void) {
643654
644655 mp_obj_t m = mp_obj_new_module (MP_QSTR_pyb );
645656 rt_store_attr (m , MP_QSTR_info , rt_make_function_n (0 , pyb_info ));
657+ rt_store_attr (m , MP_QSTR_gc , (mp_obj_t )& pyb_gc_obj );
658+ rt_store_attr (m , qstr_from_str ("repl_info" ), rt_make_function_n (1 , pyb_set_repl_info ));
646659#if MICROPY_HW_HAS_SDCARD
647660 rt_store_attr (m , MP_QSTR_sd_test , rt_make_function_n (0 , pyb_sd_test ));
648661#endif
@@ -651,7 +664,6 @@ int main(void) {
651664 rt_store_attr (m , MP_QSTR_source_dir , rt_make_function_n (1 , pyb_source_dir ));
652665 rt_store_attr (m , MP_QSTR_main , rt_make_function_n (1 , pyb_main ));
653666 rt_store_attr (m , MP_QSTR_sync , rt_make_function_n (0 , pyb_sync ));
654- rt_store_attr (m , MP_QSTR_gc , (mp_obj_t )& pyb_gc_obj );
655667 rt_store_attr (m , MP_QSTR_delay , rt_make_function_n (1 , pyb_delay ));
656668#if MICROPY_HW_HAS_SWITCH
657669 rt_store_attr (m , MP_QSTR_switch , (mp_obj_t )& pyb_switch_obj );
0 commit comments