@@ -117,12 +117,12 @@ static size_t PLACE_IN_DTCM_BSS(_pystack[CIRCUITPY_PYSTACK_SIZE / sizeof(size_t)
117117#endif
118118
119119static void reset_devices (void ) {
120- #if CIRCUITPY_BLEIO_HCI
120+ #if CIRCUITPY_BLEIO_HCI
121121 bleio_reset ();
122- #endif
122+ #endif
123123}
124124
125- STATIC void start_mp (supervisor_allocation * heap ) {
125+ STATIC void start_mp (supervisor_allocation * heap ) {
126126 autoreload_stop ();
127127 supervisor_workflow_reset ();
128128
@@ -135,13 +135,13 @@ STATIC void start_mp(supervisor_allocation* heap) {
135135 }
136136
137137
138- #if MICROPY_MAX_STACK_USAGE
138+ #if MICROPY_MAX_STACK_USAGE
139139 // _ezero (same as _ebss) is an int, so start 4 bytes above it.
140140 if (stack_get_bottom () != NULL ) {
141141 mp_stack_set_bottom (stack_get_bottom ());
142142 mp_stack_fill_with_sentinel ();
143143 }
144- #endif
144+ #endif
145145
146146 // Sync the file systems in case any used RAM from the GC to cache. As soon
147147 // as we re-init the GC all bets are off on the cache.
@@ -201,8 +201,8 @@ STATIC void stop_mp(void) {
201201
202202// Look for the first file that exists in the list of filenames, using mp_import_stat().
203203// Return its index. If no file found, return -1.
204- STATIC const char * first_existing_file_in_list (const char * const * filenames ) {
205- for (int i = 0 ; filenames [i ] != (char * )"" ; i ++ ) {
204+ STATIC const char * first_existing_file_in_list (const char * const * filenames ) {
205+ for (int i = 0 ; filenames [i ] != (char * )"" ; i ++ ) {
206206 mp_import_stat_t stat = mp_import_stat (filenames [i ]);
207207 if (stat == MP_IMPORT_STAT_FILE ) {
208208 return filenames [i ];
@@ -211,8 +211,8 @@ STATIC const char* first_existing_file_in_list(const char * const * filenames) {
211211 return NULL ;
212212}
213213
214- STATIC bool maybe_run_list (const char * const * filenames , pyexec_result_t * exec_result ) {
215- const char * filename = first_existing_file_in_list (filenames );
214+ STATIC bool maybe_run_list (const char * const * filenames , pyexec_result_t * exec_result ) {
215+ const char * filename = first_existing_file_in_list (filenames );
216216 if (filename == NULL ) {
217217 return false;
218218 }
@@ -226,10 +226,10 @@ STATIC bool maybe_run_list(const char * const * filenames, pyexec_result_t* exec
226226}
227227
228228STATIC void count_strn (void * data , const char * str , size_t len ) {
229- * (size_t * )data += len ;
229+ * (size_t * )data += len ;
230230}
231231
232- STATIC void cleanup_after_vm (supervisor_allocation * heap , mp_obj_t exception ) {
232+ STATIC void cleanup_after_vm (supervisor_allocation * heap , mp_obj_t exception ) {
233233 // Get the traceback of any exception from this run off the heap.
234234 // MP_OBJ_SENTINEL means "this run does not contribute to traceback storage, don't touch it"
235235 // MP_OBJ_NULL (=0) means "this run completed successfully, clear any stored traceback"
@@ -249,13 +249,12 @@ STATIC void cleanup_after_vm(supervisor_allocation* heap, mp_obj_t exception) {
249249 // making it fail, but at this point I believe they are not worth spending code on.
250250 if (prev_traceback_allocation != NULL ) {
251251 vstr_t vstr ;
252- vstr_init_fixed_buf (& vstr , traceback_len , (char * )prev_traceback_allocation -> ptr );
252+ vstr_init_fixed_buf (& vstr , traceback_len , (char * )prev_traceback_allocation -> ptr );
253253 mp_print_t print = {& vstr , (mp_print_strn_t )vstr_add_strn };
254254 mp_obj_print_exception (& print , exception );
255- ((char * )prev_traceback_allocation -> ptr )[traceback_len ] = '\0' ;
255+ ((char * )prev_traceback_allocation -> ptr )[traceback_len ] = '\0' ;
256256 }
257- }
258- else {
257+ } else {
259258 prev_traceback_allocation = NULL ;
260259 }
261260 }
@@ -335,17 +334,17 @@ STATIC bool run_code_py(safe_mode_t safe_mode) {
335334 uint8_t next_code_stickiness_situation = SUPERVISOR_NEXT_CODE_OPT_NEWLY_SET ;
336335
337336 if (safe_mode == NO_SAFE_MODE ) {
338- static const char * const supported_filenames [] = STRING_LIST (
337+ static const char * const supported_filenames [] = STRING_LIST (
339338 "code.txt" , "code.py" , "main.py" , "main.txt" );
340339 #if CIRCUITPY_FULL_BUILD
341- static const char * const double_extension_filenames [] = STRING_LIST (
340+ static const char * const double_extension_filenames [] = STRING_LIST (
342341 "code.txt.py" , "code.py.txt" , "code.txt.txt" ,"code.py.py" ,
343342 "main.txt.py" , "main.py.txt" , "main.txt.txt" ,"main.py.py" );
344343 #endif
345344
346345 stack_resize ();
347346 filesystem_flush ();
348- supervisor_allocation * heap = allocate_remaining_memory ();
347+ supervisor_allocation * heap = allocate_remaining_memory ();
349348
350349 // Prepare the VM state. Includes an alarm check/reset for sleep.
351350 start_mp (heap );
@@ -356,14 +355,14 @@ STATIC bool run_code_py(safe_mode_t safe_mode) {
356355
357356 // Check if a different run file has been allocated
358357 if (next_code_allocation ) {
359- ((next_code_info_t * )next_code_allocation -> ptr )-> options &= ~SUPERVISOR_NEXT_CODE_OPT_NEWLY_SET ;
360- next_code_options = ((next_code_info_t * )next_code_allocation -> ptr )-> options ;
361- if (((next_code_info_t * )next_code_allocation -> ptr )-> filename [0 ] != '\0' ) {
362- const char * next_list [] = {((next_code_info_t * )next_code_allocation -> ptr )-> filename , "" };
358+ ((next_code_info_t * )next_code_allocation -> ptr )-> options &= ~SUPERVISOR_NEXT_CODE_OPT_NEWLY_SET ;
359+ next_code_options = ((next_code_info_t * )next_code_allocation -> ptr )-> options ;
360+ if (((next_code_info_t * )next_code_allocation -> ptr )-> filename [0 ] != '\0' ) {
361+ const char * next_list [] = {((next_code_info_t * )next_code_allocation -> ptr )-> filename , "" };
363362 // This is where the user's python code is actually executed:
364363 found_main = maybe_run_list (next_list , & result );
365364 if (!found_main ) {
366- serial_write (((next_code_info_t * )next_code_allocation -> ptr )-> filename );
365+ serial_write (((next_code_info_t * )next_code_allocation -> ptr )-> filename );
367366 serial_write_compressed (translate (" not found.\n" ));
368367 }
369368 }
@@ -374,14 +373,14 @@ STATIC bool run_code_py(safe_mode_t safe_mode) {
374373 found_main = maybe_run_list (supported_filenames , & result );
375374 // If that didn't work, double check the extensions
376375 #if CIRCUITPY_FULL_BUILD
377- if (!found_main ){
376+ if (!found_main ) {
378377 found_main = maybe_run_list (double_extension_filenames , & result );
379378 if (found_main ) {
380379 serial_write_compressed (translate ("WARNING: Your code filename has two extensions\n" ));
381380 }
382381 }
383382 #else
384- (void ) found_main ;
383+ (void )found_main ;
385384 #endif
386385 }
387386
@@ -400,7 +399,7 @@ STATIC bool run_code_py(safe_mode_t safe_mode) {
400399 // the options because it can be treated like any other reason-for-stickiness bit. The
401400 // source is different though: it comes from the options that will apply to the next run,
402401 // while the rest of next_code_options is what applied to this run.
403- if (next_code_allocation != NULL && (((next_code_info_t * )next_code_allocation -> ptr )-> options & SUPERVISOR_NEXT_CODE_OPT_NEWLY_SET )) {
402+ if (next_code_allocation != NULL && (((next_code_info_t * )next_code_allocation -> ptr )-> options & SUPERVISOR_NEXT_CODE_OPT_NEWLY_SET )) {
404403 next_code_options |= SUPERVISOR_NEXT_CODE_OPT_NEWLY_SET ;
405404 }
406405
@@ -562,7 +561,7 @@ STATIC bool run_code_py(safe_mode_t safe_mode) {
562561 }
563562
564563 #if !CIRCUITPY_STATUS_LED
565- port_interrupt_after_ticks (time_to_epaper_refresh );
564+ port_interrupt_after_ticks (time_to_epaper_refresh );
566565 #endif
567566 #endif
568567
@@ -645,72 +644,70 @@ STATIC void __attribute__ ((noinline)) run_boot_py(safe_mode_t safe_mode) {
645644 && safe_mode == NO_SAFE_MODE
646645 && MP_STATE_VM (vfs_mount_table ) != NULL ;
647646
648- if (!ok_to_run ) {
649- return ;
650- }
651-
652- static const char * const boot_py_filenames [] = STRING_LIST ("boot.py" , "boot.txt" );
647+ static const char * const boot_py_filenames [] = STRING_LIST ("boot.py" , "boot.txt" );
653648
654649 // Do USB setup even if boot.py is not run.
655650
656- supervisor_allocation * heap = allocate_remaining_memory ();
651+ supervisor_allocation * heap = allocate_remaining_memory ();
657652 start_mp (heap );
658653
659- #if CIRCUITPY_USB
654+ #if CIRCUITPY_USB
660655 // Set up default USB values after boot.py VM starts but before running boot.py.
661656 usb_set_defaults ();
662- #endif
663-
664- #ifdef CIRCUITPY_BOOT_OUTPUT_FILE
665- vstr_t boot_text ;
666- vstr_init (& boot_text , 512 );
667- boot_output = & boot_text ;
668657 #endif
669658
670- // Write version info
671- mp_printf (& mp_plat_print , "%s\nBoard ID:%s\n" , MICROPY_FULL_VERSION_INFO , CIRCUITPY_BOARD_ID );
672-
673659 pyexec_result_t result = {0 , MP_OBJ_NULL , 0 };
674660
675- bool found_boot = maybe_run_list (boot_py_filenames , & result );
676- (void ) found_boot ;
661+ if (ok_to_run ) {
662+ #ifdef CIRCUITPY_BOOT_OUTPUT_FILE
663+ vstr_t boot_text ;
664+ vstr_init (& boot_text , 512 );
665+ boot_output = & boot_text ;
666+ #endif
667+
668+ // Write version info
669+ mp_printf (& mp_plat_print , "%s\nBoard ID:%s\n" , MICROPY_FULL_VERSION_INFO , CIRCUITPY_BOARD_ID );
670+
671+ bool found_boot = maybe_run_list (boot_py_filenames , & result );
672+ (void )found_boot ;
677673
678674
679- #ifdef CIRCUITPY_BOOT_OUTPUT_FILE
680- // Get the base filesystem.
681- fs_user_mount_t * vfs = (fs_user_mount_t * ) MP_STATE_VM (vfs_mount_table )-> obj ;
682- FATFS * fs = & vfs -> fatfs ;
675+ #ifdef CIRCUITPY_BOOT_OUTPUT_FILE
676+ // Get the base filesystem.
677+ fs_user_mount_t * vfs = (fs_user_mount_t * )MP_STATE_VM (vfs_mount_table )-> obj ;
678+ FATFS * fs = & vfs -> fatfs ;
683679
684- boot_output = NULL ;
685- bool write_boot_output = (common_hal_mcu_processor_get_reset_reason () == RESET_REASON_POWER_ON );
686- FIL boot_output_file ;
687- if (f_open (fs , & boot_output_file , CIRCUITPY_BOOT_OUTPUT_FILE , FA_READ ) == FR_OK ) {
688- char * file_contents = m_new (char , boot_text .alloc );
689- UINT chars_read ;
690- if (f_read (& boot_output_file , file_contents , 1 + boot_text .len , & chars_read ) == FR_OK ) {
691- write_boot_output =
692- (chars_read != boot_text .len ) || (memcmp (boot_text .buf , file_contents , chars_read ) != 0 );
680+ boot_output = NULL ;
681+ bool write_boot_output = (common_hal_mcu_processor_get_reset_reason () == RESET_REASON_POWER_ON );
682+ FIL boot_output_file ;
683+ if (f_open (fs , & boot_output_file , CIRCUITPY_BOOT_OUTPUT_FILE , FA_READ ) == FR_OK ) {
684+ char * file_contents = m_new (char , boot_text .alloc );
685+ UINT chars_read ;
686+ if (f_read (& boot_output_file , file_contents , 1 + boot_text .len , & chars_read ) == FR_OK ) {
687+ write_boot_output =
688+ (chars_read != boot_text .len ) || (memcmp (boot_text .buf , file_contents , chars_read ) != 0 );
689+ }
690+ // no need to f_close the file
693691 }
694- // no need to f_close the file
695- }
696692
697- if (write_boot_output ) {
698- // Wait 1 second before opening CIRCUITPY_BOOT_OUTPUT_FILE for write,
699- // in case power is momentary or will fail shortly due to, say a low, battery.
700- mp_hal_delay_ms (1000 );
701-
702- // USB isn't up, so we can write the file.
703- // operating at the oofatfs (f_open) layer means the usb concurrent write permission
704- // is not even checked!
705- f_open (fs , & boot_output_file , CIRCUITPY_BOOT_OUTPUT_FILE , FA_WRITE | FA_CREATE_ALWAYS );
706- UINT chars_written ;
707- f_write (& boot_output_file , boot_text .buf , boot_text .len , & chars_written );
708- f_close (& boot_output_file );
709- filesystem_flush ();
693+ if (write_boot_output ) {
694+ // Wait 1 second before opening CIRCUITPY_BOOT_OUTPUT_FILE for write,
695+ // in case power is momentary or will fail shortly due to, say a low, battery.
696+ mp_hal_delay_ms (1000 );
697+
698+ // USB isn't up, so we can write the file.
699+ // operating at the oofatfs (f_open) layer means the usb concurrent write permission
700+ // is not even checked!
701+ f_open (fs , & boot_output_file , CIRCUITPY_BOOT_OUTPUT_FILE , FA_WRITE | FA_CREATE_ALWAYS );
702+ UINT chars_written ;
703+ f_write (& boot_output_file , boot_text .buf , boot_text .len , & chars_written );
704+ f_close (& boot_output_file );
705+ filesystem_flush ();
706+ }
707+ #endif
710708 }
711- #endif
712709
713- #if CIRCUITPY_USB
710+ #if CIRCUITPY_USB
714711 // Some data needs to be carried over from the USB settings in boot.py
715712 // to the next VM, while the heap is still available.
716713 // Its size can vary, so save it temporarily on the stack,
@@ -719,21 +716,21 @@ STATIC void __attribute__ ((noinline)) run_boot_py(safe_mode_t safe_mode) {
719716 size_t size = usb_boot_py_data_size ();
720717 uint8_t usb_boot_py_data [size ];
721718 usb_get_boot_py_data (usb_boot_py_data , size );
722- #endif
719+ #endif
723720
724721 cleanup_after_vm (heap , result .exception );
725722
726- #if CIRCUITPY_USB
723+ #if CIRCUITPY_USB
727724 // Now give back the data we saved from the heap going away.
728725 usb_return_boot_py_data (usb_boot_py_data , size );
729- #endif
726+ #endif
730727}
731728
732729STATIC int run_repl (void ) {
733730 int exit_code = PYEXEC_FORCED_EXIT ;
734731 stack_resize ();
735732 filesystem_flush ();
736- supervisor_allocation * heap = allocate_remaining_memory ();
733+ supervisor_allocation * heap = allocate_remaining_memory ();
737734 start_mp (heap );
738735
739736 #if CIRCUITPY_USB
@@ -878,7 +875,7 @@ void gc_collect(void) {
878875
879876 // This collects root pointers from the VFS mount table. Some of them may
880877 // have lost their references in the VM even though they are mounted.
881- gc_collect_root ((void * * )& MP_STATE_VM (vfs_mount_table ), sizeof (mp_vfs_mount_t ) / sizeof (mp_uint_t ));
878+ gc_collect_root ((void * * )& MP_STATE_VM (vfs_mount_table ), sizeof (mp_vfs_mount_t ) / sizeof (mp_uint_t ));
882879
883880 background_callback_gc_collect ();
884881
@@ -908,18 +905,20 @@ void gc_collect(void) {
908905
909906 // This naively collects all object references from an approximate stack
910907 // range.
911- gc_collect_root ((void * * )sp , ((uint32_t )port_stack_get_top () - sp ) / sizeof (uint32_t ));
908+ gc_collect_root ((void * * )sp , ((uint32_t )port_stack_get_top () - sp ) / sizeof (uint32_t ));
912909 gc_collect_end ();
913910}
914911
915912void NORETURN nlr_jump_fail (void * val ) {
916913 reset_into_safe_mode (MICROPY_NLR_JUMP_FAIL );
917- while (true) {}
914+ while (true) {
915+ }
918916}
919917
920918void NORETURN __fatal_error (const char * msg ) {
921919 reset_into_safe_mode (MICROPY_FATAL_ERROR );
922- while (true) {}
920+ while (true) {
921+ }
923922}
924923
925924#ifndef NDEBUG
0 commit comments