mirror of
https://github.com/openmv/openmv.git
synced 2025-11-04 14:49:50 +08:00
clean up main.c
This commit is contained in:
parent
5460f7f5e1
commit
0c20049e3d
@ -72,9 +72,8 @@
|
|||||||
|
|
||||||
int errno;
|
int errno;
|
||||||
// Not sure why MP doesn't like vfs stored here anymore.
|
// Not sure why MP doesn't like vfs stored here anymore.
|
||||||
//extern char _vfs_buf;
|
extern char _vfs_buf;
|
||||||
//static fs_user_mount_t *vfs_fat = (fs_user_mount_t *) &_vfs_buf;
|
static fs_user_mount_t *vfs_fat = (fs_user_mount_t *) &_vfs_buf;
|
||||||
static fs_user_mount_t _vfs_fat, *vfs_fat = &_vfs_fat;
|
|
||||||
|
|
||||||
static const char fresh_main_py[] =
|
static const char fresh_main_py[] =
|
||||||
"# main.py -- put your code here!\n"
|
"# main.py -- put your code here!\n"
|
||||||
@ -183,6 +182,7 @@ static const char fresh_selftest_py[] =
|
|||||||
" print('')\n"
|
" print('')\n"
|
||||||
" test_int_adc()\n"
|
" test_int_adc()\n"
|
||||||
" test_color_bars()\n"
|
" test_color_bars()\n"
|
||||||
|
"\n"
|
||||||
;
|
;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -317,9 +317,6 @@ int main(void)
|
|||||||
led_init();
|
led_init();
|
||||||
pendsv_init();
|
pendsv_init();
|
||||||
|
|
||||||
// Disable all IRQs except Systick
|
|
||||||
irq_set_base_priority(1);
|
|
||||||
|
|
||||||
// Re-enable IRQs (disabled by bootloader)
|
// Re-enable IRQs (disabled by bootloader)
|
||||||
__enable_irq();
|
__enable_irq();
|
||||||
|
|
||||||
@ -404,6 +401,8 @@ soft_reset:
|
|||||||
if (res == FR_NO_FILESYSTEM) {
|
if (res == FR_NO_FILESYSTEM) {
|
||||||
// Create a fresh fs
|
// Create a fresh fs
|
||||||
make_flash_fs();
|
make_flash_fs();
|
||||||
|
// Flush storage
|
||||||
|
storage_flush();
|
||||||
} else if (res != FR_OK) {
|
} else if (res != FR_OK) {
|
||||||
__fatal_error("Could not access LFS\n");
|
__fatal_error("Could not access LFS\n");
|
||||||
}
|
}
|
||||||
@ -424,15 +423,10 @@ soft_reset:
|
|||||||
vfs->obj = MP_OBJ_FROM_PTR(vfs_fat);
|
vfs->obj = MP_OBJ_FROM_PTR(vfs_fat);
|
||||||
vfs->next = NULL;
|
vfs->next = NULL;
|
||||||
MP_STATE_VM(vfs_mount_table) = vfs;
|
MP_STATE_VM(vfs_mount_table) = vfs;
|
||||||
|
|
||||||
// The current directory is used as the boot up directory.
|
|
||||||
// It is set to the internal flash filesystem by default.
|
|
||||||
MP_STATE_PORT(vfs_cur) = vfs;
|
MP_STATE_PORT(vfs_cur) = vfs;
|
||||||
|
|
||||||
// Init USB device to default setting if it was not already configured
|
// Init USB device to default setting if it was not already configured
|
||||||
if (!(pyb_usb_flags & PYB_USB_FLAG_USB_MODE_CALLED)) {
|
|
||||||
pyb_usb_dev_init(USBD_VID, USBD_PID_CDC_MSC, USBD_MODE_CDC_MSC, NULL);
|
pyb_usb_dev_init(USBD_VID, USBD_PID_CDC_MSC, USBD_MODE_CDC_MSC, NULL);
|
||||||
}
|
|
||||||
|
|
||||||
// check sensor init result
|
// check sensor init result
|
||||||
if (first_soft_reset && sensor_init_ret != 0) {
|
if (first_soft_reset && sensor_init_ret != 0) {
|
||||||
@ -447,31 +441,35 @@ soft_reset:
|
|||||||
led_state(LED_BLUE, 0);
|
led_state(LED_BLUE, 0);
|
||||||
|
|
||||||
// Run self tests the first time only
|
// Run self tests the first time only
|
||||||
//f_res = f_stat_helper("/selftest.py", NULL);
|
f_res = f_stat(&vfs_fat->fatfs, "/selftest.py", NULL);
|
||||||
//if (first_soft_reset && f_res == FR_OK) {
|
if (first_soft_reset && f_res == FR_OK) {
|
||||||
// nlr_buf_t nlr;
|
nlr_buf_t nlr;
|
||||||
// if (nlr_push(&nlr) == 0) {
|
if (nlr_push(&nlr) == 0) {
|
||||||
// // Parse, compile and execute the self-tests script.
|
// Parse, compile and execute the self-tests script.
|
||||||
// pyexec_file("/selftest.py");
|
pyexec_file("/selftest.py");
|
||||||
// nlr_pop();
|
nlr_pop();
|
||||||
// } else {
|
} else {
|
||||||
// // Get the exception message. TODO: might be a hack.
|
// Get the exception message. TODO: might be a hack.
|
||||||
// mp_obj_str_t *str = mp_obj_exception_get_value((mp_obj_t)nlr.ret_val);
|
mp_obj_str_t *str = mp_obj_exception_get_value((mp_obj_t)nlr.ret_val);
|
||||||
// // If any of the self-tests fail log the exception message
|
// If any of the self-tests fail log the exception message
|
||||||
// // and loop forever. Note: IDE exceptions will not be caught.
|
// and loop forever. Note: IDE exceptions will not be caught.
|
||||||
// __fatal_error((const char*) str->data);
|
__fatal_error((const char*) str->data);
|
||||||
// }
|
}
|
||||||
|
|
||||||
// // Success: remove self tests script and flush cache
|
// Success: remove self tests script and flush cache
|
||||||
// f_unlink_helper("/selftest.py");
|
f_unlink(&vfs_fat->fatfs, "/selftest.py");
|
||||||
// storage_flush();
|
storage_flush();
|
||||||
|
|
||||||
// // Set flag for SWD debugger (main.py does not use the frame buffer).
|
// Set flag for SWD debugger (main.py does not use the frame buffer).
|
||||||
// MAIN_FB()->bpp = 0xDEADBEEF;
|
MAIN_FB()->bpp = 0xDEADBEEF;
|
||||||
//}
|
}
|
||||||
|
|
||||||
// Run the main script
|
// Run the main script
|
||||||
f_res = f_stat_helper("/main.py", NULL);
|
f_res = f_stat(&vfs_fat->fatfs, "/main.py", NULL);
|
||||||
|
if (f_res != FR_OK) {
|
||||||
|
led_state(LED_GREEN, 1);
|
||||||
|
}
|
||||||
|
|
||||||
if (first_soft_reset && f_res == FR_OK) {
|
if (first_soft_reset && f_res == FR_OK) {
|
||||||
nlr_buf_t nlr;
|
nlr_buf_t nlr;
|
||||||
if (nlr_push(&nlr) == 0) {
|
if (nlr_push(&nlr) == 0) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user