stmhal: In safe mode, still mount SD card and present as MSD over USB.
It's still "safe" because no scripts are run. Remove the SD card if you want to access the internal flash filesystem. Addresses issue #616. Also: remove obsolete pyb.source_dir setting, and reset pyb.main and pyb.usb_mode settings on soft-reset.
This commit is contained in:
parent
b0accc8571
commit
b63be37be1
@ -127,26 +127,15 @@ void disable_irq(void) {
|
||||
__disable_irq();
|
||||
}
|
||||
|
||||
STATIC mp_obj_t pyb_config_source_dir = MP_OBJ_NULL;
|
||||
STATIC mp_obj_t pyb_config_main = MP_OBJ_NULL;
|
||||
STATIC mp_obj_t pyb_config_usb_mode = MP_OBJ_NULL;
|
||||
|
||||
STATIC mp_obj_t pyb_source_dir(mp_obj_t source_dir) {
|
||||
if (MP_OBJ_IS_STR(source_dir)) {
|
||||
pyb_config_source_dir = source_dir;
|
||||
}
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(pyb_source_dir_obj, pyb_source_dir);
|
||||
|
||||
STATIC mp_obj_t pyb_main(mp_obj_t main) {
|
||||
if (MP_OBJ_IS_STR(main)) {
|
||||
pyb_config_main = main;
|
||||
}
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(pyb_main_obj, pyb_main);
|
||||
|
||||
STATIC mp_obj_t pyb_usb_mode(mp_obj_t usb_mode) {
|
||||
@ -155,7 +144,6 @@ STATIC mp_obj_t pyb_usb_mode(mp_obj_t usb_mode) {
|
||||
}
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(pyb_usb_mode_obj, pyb_usb_mode);
|
||||
|
||||
static const char fresh_boot_py[] =
|
||||
@ -444,7 +432,7 @@ soft_reset:
|
||||
|
||||
#if MICROPY_HW_HAS_SDCARD
|
||||
// if an SD card is present then mount it on /sd/
|
||||
if (reset_mode == 1 && sdcard_is_present()) {
|
||||
if (sdcard_is_present()) {
|
||||
FRESULT res = f_mount(&fatfs1, "/sd", 1);
|
||||
if (res != FR_OK) {
|
||||
printf("[SD] could not mount SD card\n");
|
||||
@ -466,7 +454,12 @@ soft_reset:
|
||||
}
|
||||
#endif
|
||||
|
||||
// reset config variables; they should be set by boot.py
|
||||
pyb_config_main = MP_OBJ_NULL;
|
||||
pyb_config_usb_mode = MP_OBJ_NULL;
|
||||
|
||||
// run boot.py, if it exists
|
||||
// TODO perhaps have pyb.reboot([bootpy]) function to soft-reboot and execute custom boot.py
|
||||
if (reset_mode == 1) {
|
||||
const char *boot_py = "boot.py";
|
||||
FRESULT res = f_stat(boot_py, NULL);
|
||||
@ -491,17 +484,14 @@ soft_reset:
|
||||
pyb_usb_host_init();
|
||||
#elif defined(USE_DEVICE_MODE)
|
||||
// USB device
|
||||
if (reset_mode == 1) {
|
||||
usb_device_mode_t usb_mode = USB_DEVICE_MODE_CDC_MSC;
|
||||
if (pyb_config_usb_mode != MP_OBJ_NULL) {
|
||||
if (strcmp(mp_obj_str_get_str(pyb_config_usb_mode), "CDC+HID") == 0) {
|
||||
usb_mode = USB_DEVICE_MODE_CDC_HID;
|
||||
}
|
||||
usb_device_mode_t usb_mode = USB_DEVICE_MODE_CDC_MSC;
|
||||
// if we are not in reset_mode==1, this config variable will always be NULL
|
||||
if (pyb_config_usb_mode != MP_OBJ_NULL) {
|
||||
if (strcmp(mp_obj_str_get_str(pyb_config_usb_mode), "CDC+HID") == 0) {
|
||||
usb_mode = USB_DEVICE_MODE_CDC_HID;
|
||||
}
|
||||
pyb_usb_dev_init(usb_mode, usb_medium);
|
||||
} else {
|
||||
pyb_usb_dev_init(USB_DEVICE_MODE_CDC_MSC, usb_medium);
|
||||
}
|
||||
pyb_usb_dev_init(usb_mode, usb_medium);
|
||||
#endif
|
||||
|
||||
#if MICROPY_HW_HAS_MMA7660
|
||||
|
@ -341,7 +341,6 @@ STATIC mp_obj_t pyb_hid_send_report(mp_obj_t arg) {
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_hid_send_report_obj, pyb_hid_send_report);
|
||||
|
||||
MP_DECLARE_CONST_FUN_OBJ(pyb_source_dir_obj); // defined in main.c
|
||||
MP_DECLARE_CONST_FUN_OBJ(pyb_main_obj); // defined in main.c
|
||||
MP_DECLARE_CONST_FUN_OBJ(pyb_usb_mode_obj); // defined in main.c
|
||||
|
||||
@ -360,7 +359,6 @@ STATIC const mp_map_elem_t pyb_module_globals_table[] = {
|
||||
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_stop), (mp_obj_t)&pyb_stop_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_standby), (mp_obj_t)&pyb_standby_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_source_dir), (mp_obj_t)&pyb_source_dir_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_main), (mp_obj_t)&pyb_main_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_usb_mode), (mp_obj_t)&pyb_usb_mode_obj },
|
||||
|
||||
|
@ -39,7 +39,6 @@ Q(disable_irq)
|
||||
Q(enable_irq)
|
||||
Q(stop)
|
||||
Q(standby)
|
||||
Q(source_dir)
|
||||
Q(main)
|
||||
Q(usb_mode)
|
||||
Q(sync)
|
||||
|
Loading…
Reference in New Issue
Block a user