summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--stmhal/extint.c2
-rw-r--r--stmhal/extint.h2
-rw-r--r--stmhal/main.c72
-rw-r--r--stmhal/pin.c2
-rw-r--r--stmhal/pin.h2
-rw-r--r--stmhal/readline.c2
-rw-r--r--stmhal/readline.h2
-rw-r--r--stmhal/usb.c13
-rw-r--r--stmhal/usb.h1
9 files changed, 57 insertions, 41 deletions
diff --git a/stmhal/extint.c b/stmhal/extint.c
index d2eace5745..3044e7904a 100644
--- a/stmhal/extint.c
+++ b/stmhal/extint.c
@@ -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;
diff --git a/stmhal/extint.h b/stmhal/extint.h
index d15d1ef944..cae23959cf 100644
--- a/stmhal/extint.h
+++ b/stmhal/extint.h
@@ -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);
diff --git a/stmhal/main.c b/stmhal/main.c
index 442ff99347..4f5277975b 100644
--- a/stmhal/main.c
+++ b/stmhal/main.c
@@ -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.
+
+ readline_init0();
+ pin_init0();
+ extint_init0();
+ timer_init0();
+
+#if MICROPY_HW_ENABLE_RNG
+ rng_init0();
+#endif
- // local filesystem init
+ 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();
diff --git a/stmhal/pin.c b/stmhal/pin.c
index 20661cfceb..2d7466d3cb 100644
--- a/stmhal/pin.c
+++ b/stmhal/pin.c
@@ -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;
diff --git a/stmhal/pin.h b/stmhal/pin.h
index 8513db109b..51a434f1d0 100644
--- a/stmhal/pin.h
+++ b/stmhal/pin.h
@@ -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);
diff --git a/stmhal/readline.c b/stmhal/readline.c
index 14c9b9fb96..5ef86c44fa 100644
--- a/stmhal/readline.c
+++ b/stmhal/readline.c
@@ -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*));
}
diff --git a/stmhal/readline.h b/stmhal/readline.h
index 4c1de71fec..8bbc43b435 100644
--- a/stmhal/readline.h
+++ b/stmhal/readline.h
@@ -24,5 +24,5 @@
* THE SOFTWARE.
*/
-void readline_init(void);
+void readline_init0(void);
int readline(vstr_t *line, const char *prompt);
diff --git a/stmhal/usb.c b/stmhal/usb.c
index 7db8ca218a..40c474f432 100644
--- a/stmhal/usb.c
+++ b/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
}
diff --git a/stmhal/usb.h b/stmhal/usb.h
index 6d2d469fe9..594e99e18d 100644
--- a/stmhal/usb.h
+++ b/stmhal/usb.h
@@ -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);