stmhal: Clean up reset/soft-reset code; fix bug init'ing VCP exc.
Make a clearer distinction between init functions that must be done before any scripts can run (xxx_init0) and those that can be safely deferred (xxx_init). Fix bug initialising USB VCP exception. Addresses issue #788. Re-order some init function to improve reliability of reset/soft-reset.
This commit is contained in:
parent
8dbbbbc793
commit
ccacdf44b6
@ -346,7 +346,7 @@ const mp_obj_type_t extint_type = {
|
||||
.locals_dict = (mp_obj_t)&extint_locals_dict,
|
||||
};
|
||||
|
||||
void extint_init(void) {
|
||||
void extint_init0(void) {
|
||||
for (extint_vector_t *v = extint_vector; v < &extint_vector[EXTI_NUM_VECTORS]; v++) {
|
||||
v->callback_obj = mp_const_none;
|
||||
v->param = NULL;
|
||||
|
@ -46,7 +46,7 @@
|
||||
#define EXTI_TRIGGER_FALLING (offsetof(EXTI_TypeDef, FTSR))
|
||||
#define EXTI_TRIGGER_RISING_FALLING (EXTI_TRIGGER_RISING + EXTI_TRIGGER_FALLING) // just different from RISING or FALLING
|
||||
|
||||
void extint_init(void);
|
||||
void extint_init0(void);
|
||||
|
||||
uint extint_register(mp_obj_t pin_obj, uint32_t mode, uint32_t pull, mp_obj_t callback_obj, bool override_callback_obj, void *param);
|
||||
|
||||
|
@ -333,11 +333,26 @@ soft_reset:
|
||||
pyb_stdio_uart = NULL;
|
||||
#endif
|
||||
|
||||
readline_init();
|
||||
pin_init();
|
||||
extint_init();
|
||||
// Initialise low-level sub-systems. Here we need to very basic things like
|
||||
// zeroing out memory and resetting any of the sub-systems. Following this
|
||||
// we can run Python scripts (eg boot.py), but anything that is configurable
|
||||
// by boot.py must be set after boot.py is run.
|
||||
|
||||
// local filesystem init
|
||||
readline_init0();
|
||||
pin_init0();
|
||||
extint_init0();
|
||||
timer_init0();
|
||||
|
||||
#if MICROPY_HW_ENABLE_RNG
|
||||
rng_init0();
|
||||
#endif
|
||||
|
||||
i2c_init0();
|
||||
spi_init0();
|
||||
pyb_usb_init0();
|
||||
|
||||
// Initialise the local flash filesystem.
|
||||
// Create it if needed, and mount in on /flash.
|
||||
{
|
||||
// try to mount the flash
|
||||
FRESULT res = f_mount(&fatfs0, "/flash", 1);
|
||||
@ -383,7 +398,11 @@ soft_reset:
|
||||
}
|
||||
}
|
||||
|
||||
// make sure we have a /flash/boot.py
|
||||
// The current directory is used as the boot up directory.
|
||||
// It is set to the internal flash filesystem by default.
|
||||
f_chdrive("/flash");
|
||||
|
||||
// Make sure we have a /flash/boot.py. Create it if needed.
|
||||
{
|
||||
FILINFO fno;
|
||||
#if _USE_LFN
|
||||
@ -419,9 +438,6 @@ soft_reset:
|
||||
}
|
||||
}
|
||||
|
||||
// root device defaults to internal flash filesystem
|
||||
f_chdrive("/flash");
|
||||
|
||||
#if defined(USE_DEVICE_MODE)
|
||||
usb_storage_medium_t usb_medium = USB_STORAGE_MEDIUM_FLASH;
|
||||
#endif
|
||||
@ -433,7 +449,7 @@ soft_reset:
|
||||
if (res != FR_OK) {
|
||||
printf("[SD] could not mount SD card\n");
|
||||
} else {
|
||||
// use SD card as root device
|
||||
// use SD card as current directory
|
||||
f_chdrive("/sd");
|
||||
|
||||
// TODO these should go before the /flash entries in the path
|
||||
@ -448,9 +464,6 @@ soft_reset:
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
// Get rid of compiler warning if no SDCARD is configured.
|
||||
(void)first_soft_reset;
|
||||
#endif
|
||||
|
||||
// run boot.py, if it exists
|
||||
@ -469,6 +482,10 @@ soft_reset:
|
||||
led_state(3, 0);
|
||||
led_state(4, 0);
|
||||
|
||||
// Now we initialise sub-systems that need configuration from boot.py,
|
||||
// or whose initialisation can be safely deferred until after running
|
||||
// boot.py.
|
||||
|
||||
#if defined(USE_HOST_MODE)
|
||||
// USB host
|
||||
pyb_usb_host_init();
|
||||
@ -487,15 +504,6 @@ soft_reset:
|
||||
}
|
||||
#endif
|
||||
|
||||
timer_init0();
|
||||
|
||||
#if MICROPY_HW_ENABLE_RNG
|
||||
rng_init0();
|
||||
#endif
|
||||
|
||||
i2c_init0();
|
||||
spi_init0();
|
||||
|
||||
#if MICROPY_HW_HAS_MMA7660
|
||||
// MMA accel: init and reset
|
||||
accel_init();
|
||||
@ -511,7 +519,15 @@ soft_reset:
|
||||
dac_init();
|
||||
#endif
|
||||
|
||||
// now that everything is initialised, run main script
|
||||
#if MICROPY_HW_ENABLE_CC3K
|
||||
// wifi using the CC3000 driver
|
||||
pyb_wlan_init();
|
||||
pyb_wlan_start();
|
||||
#endif
|
||||
|
||||
// At this point everything is fully configured and initialised.
|
||||
|
||||
// Run the main script from the current directory.
|
||||
if (reset_mode == 1 && pyexec_mode_kind == PYEXEC_MODE_FRIENDLY_REPL) {
|
||||
const char *main_py;
|
||||
if (pyb_config_main == MP_OBJ_NULL) {
|
||||
@ -527,14 +543,8 @@ soft_reset:
|
||||
}
|
||||
}
|
||||
|
||||
#if MICROPY_HW_ENABLE_CC3K
|
||||
// wifi using the CC3000 driver
|
||||
pyb_wlan_init();
|
||||
pyb_wlan_start();
|
||||
#endif
|
||||
|
||||
// enter REPL
|
||||
// REPL mode can change, or it can request a soft reset
|
||||
// Main script is finished, so now go into REPL mode.
|
||||
// The REPL mode can change, or it can request a soft reset.
|
||||
for (;;) {
|
||||
if (pyexec_mode_kind == PYEXEC_MODE_RAW_REPL) {
|
||||
if (pyexec_raw_repl() != 0) {
|
||||
@ -547,6 +557,8 @@ soft_reset:
|
||||
}
|
||||
}
|
||||
|
||||
// soft reset
|
||||
|
||||
printf("PYB: sync filesystems\n");
|
||||
storage_flush();
|
||||
|
||||
|
@ -98,7 +98,7 @@ STATIC mp_obj_t pin_class_mapper;
|
||||
STATIC mp_obj_t pin_class_map_dict;
|
||||
STATIC bool pin_class_debug;
|
||||
|
||||
void pin_init(void) {
|
||||
void pin_init0(void) {
|
||||
pin_class_mapper = mp_const_none;
|
||||
pin_class_map_dict = mp_const_none;
|
||||
pin_class_debug = false;
|
||||
|
@ -78,7 +78,7 @@ typedef struct {
|
||||
extern const pin_named_pins_obj_t pin_board_pins_obj;
|
||||
extern const pin_named_pins_obj_t pin_cpu_pins_obj;
|
||||
|
||||
void pin_init(void);
|
||||
void pin_init0(void);
|
||||
const pin_obj_t *pin_find(mp_obj_t user_obj);
|
||||
const pin_obj_t *pin_find_named_pin(const pin_named_pin_t *pins, const char *name);
|
||||
const pin_af_obj_t *pin_find_af(const pin_obj_t *pin, uint8_t fn, uint8_t unit, uint8_t pin_type);
|
||||
|
@ -52,7 +52,7 @@ static const char *readline_hist[READLINE_HIST_SIZE] = {NULL, NULL, NULL, NULL,
|
||||
|
||||
enum { ESEQ_NONE, ESEQ_ESC, ESEQ_ESC_BRACKET, ESEQ_ESC_BRACKET_DIGIT, ESEQ_ESC_O };
|
||||
|
||||
void readline_init(void) {
|
||||
void readline_init0(void) {
|
||||
memset(readline_hist, 0, READLINE_HIST_SIZE * sizeof(const char*));
|
||||
}
|
||||
|
||||
|
@ -24,5 +24,5 @@
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
void readline_init(void);
|
||||
void readline_init0(void);
|
||||
int readline(vstr_t *line, const char *prompt);
|
||||
|
13
stmhal/usb.c
13
stmhal/usb.c
@ -45,8 +45,14 @@
|
||||
USBD_HandleTypeDef hUSBDDevice;
|
||||
#endif
|
||||
|
||||
static int dev_is_enabled = 0;
|
||||
mp_obj_t mp_const_vcp_interrupt = MP_OBJ_NULL;
|
||||
STATIC int dev_is_enabled = 0;
|
||||
STATIC mp_obj_t mp_const_vcp_interrupt = MP_OBJ_NULL;
|
||||
|
||||
void pyb_usb_init0(void) {
|
||||
// create an exception object for interrupting by VCP
|
||||
mp_const_vcp_interrupt = mp_obj_new_exception_msg(&mp_type_OSError, "VCPInterrupt");
|
||||
USBD_CDC_SetInterrupt(VCP_CHAR_NONE, mp_const_vcp_interrupt);
|
||||
}
|
||||
|
||||
void pyb_usb_dev_init(usb_device_mode_t mode, usb_storage_medium_t medium) {
|
||||
#ifdef USE_DEVICE_MODE
|
||||
@ -72,9 +78,6 @@ void pyb_usb_dev_init(usb_device_mode_t mode, usb_storage_medium_t medium) {
|
||||
USBD_Start(&hUSBDDevice);
|
||||
}
|
||||
dev_is_enabled = 1;
|
||||
|
||||
// create an exception object for interrupting by VCP
|
||||
mp_const_vcp_interrupt = mp_obj_new_exception_msg(&mp_type_OSError, "VCPInterrupt");
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -43,6 +43,7 @@ typedef enum {
|
||||
|
||||
const mp_obj_type_t pyb_usb_vcp_type;
|
||||
|
||||
void pyb_usb_init0(void);
|
||||
void pyb_usb_dev_init(usb_device_mode_t mode, usb_storage_medium_t medium);
|
||||
void pyb_usb_dev_stop(void);
|
||||
bool usb_vcp_is_enabled(void);
|
||||
|
Loading…
x
Reference in New Issue
Block a user