summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/littlefs/lfs2.c13
-rw-r--r--ports/esp32/main.c10
-rw-r--r--ports/esp32/usb.c6
-rw-r--r--ports/esp32/usb.h2
-rw-r--r--shared/tinyusb/mp_usbd.h27
5 files changed, 34 insertions, 24 deletions
diff --git a/lib/littlefs/lfs2.c b/lib/littlefs/lfs2.c
index abdec19d7..6c3c3ece7 100644
--- a/lib/littlefs/lfs2.c
+++ b/lib/littlefs/lfs2.c
@@ -93,6 +93,7 @@ static int lfs2_bd_read(lfs2_t *lfs2,
// bypass cache?
diff = lfs2_aligndown(diff, lfs2->cfg->read_size);
int err = lfs2->cfg->read(lfs2->cfg, block, off, data, diff);
+ LFS2_ASSERT(err <= 0);
if (err) {
return err;
}
@@ -739,6 +740,7 @@ static lfs2_stag_t lfs2_dir_getslice(lfs2_t *lfs2, const lfs2_mdir_t *dir,
int err = lfs2_bd_read(lfs2,
NULL, &lfs2->rcache, sizeof(ntag),
dir->pair[0], off, &ntag, sizeof(ntag));
+ LFS2_ASSERT(err <= 0);
if (err) {
return err;
}
@@ -767,6 +769,7 @@ static lfs2_stag_t lfs2_dir_getslice(lfs2_t *lfs2, const lfs2_mdir_t *dir,
err = lfs2_bd_read(lfs2,
NULL, &lfs2->rcache, diff,
dir->pair[0], off+sizeof(tag)+goff, gbuffer, diff);
+ LFS2_ASSERT(err <= 0);
if (err) {
return err;
}
@@ -828,9 +831,6 @@ static int lfs2_dir_getread(lfs2_t *lfs2, const lfs2_mdir_t *dir,
size -= diff;
continue;
}
-
- // rcache takes priority
- diff = lfs2_min(diff, rcache->off-off);
}
// load to cache, first condition can no longer fail
@@ -1282,6 +1282,7 @@ static lfs2_stag_t lfs2_dir_fetchmatch(lfs2_t *lfs2,
if (err == LFS2_ERR_CORRUPT) {
break;
}
+ return err;
}
lfs2_fcrc_fromle32(&fcrc);
@@ -2267,7 +2268,7 @@ static int lfs2_dir_relocatingcommit(lfs2_t *lfs2, lfs2_mdir_t *dir,
}
}
- if (dir->erased) {
+ if (dir->erased && dir->count < 0xff) {
// try to commit
struct lfs2_commit commit = {
.block = dir->pair[0],
@@ -5225,7 +5226,9 @@ static int lfs2_fs_gc_(lfs2_t *lfs2) {
}
// try to populate the lookahead buffer, unless it's already full
- if (lfs2->lookahead.size < 8*lfs2->cfg->lookahead_size) {
+ if (lfs2->lookahead.size < lfs2_min(
+ 8 * lfs2->cfg->lookahead_size,
+ lfs2->block_count)) {
err = lfs2_alloc_scan(lfs2);
if (err) {
return err;
diff --git a/ports/esp32/main.c b/ports/esp32/main.c
index bd5775bc6..74e31647d 100644
--- a/ports/esp32/main.c
+++ b/ports/esp32/main.c
@@ -107,7 +107,7 @@ void mp_task(void *pvParameter) {
#if MICROPY_HW_ESP_USB_SERIAL_JTAG
usb_serial_jtag_init();
#elif MICROPY_HW_ENABLE_USBDEV
- usb_init();
+ usb_phy_init();
#endif
#if MICROPY_HW_ENABLE_UART_REPL
uart_stdout_init();
@@ -145,6 +145,11 @@ soft_reset:
// run boot-up scripts
pyexec_frozen_module("_boot.py", false);
int ret = pyexec_file_if_exists("boot.py");
+
+ #if MICROPY_HW_ENABLE_USBDEV
+ mp_usbd_init();
+ #endif
+
if (ret & PYEXEC_FORCED_EXIT) {
goto soft_reset_exit;
}
@@ -193,7 +198,7 @@ soft_reset_exit:
mp_thread_deinit();
#endif
- #if MICROPY_HW_ENABLE_USB_RUNTIME_DEVICE
+ #if MICROPY_HW_ENABLE_USBDEV
mp_usbd_deinit();
#endif
@@ -219,6 +224,7 @@ soft_reset_exit:
mp_deinit();
fflush(stdout);
+
goto soft_reset;
}
diff --git a/ports/esp32/usb.c b/ports/esp32/usb.c
index 750dd59ee..b90f53aa4 100644
--- a/ports/esp32/usb.c
+++ b/ports/esp32/usb.c
@@ -38,7 +38,7 @@
static usb_phy_handle_t phy_hdl;
-void usb_init(void) {
+void usb_phy_init(void) {
// ref: https://github.com/espressif/esp-usb/blob/4b6a798d0bed444fff48147c8dcdbbd038e92892/device/esp_tinyusb/tinyusb.c
// Configure USB PHY
@@ -51,10 +51,6 @@ void usb_init(void) {
// Init ESP USB Phy
usb_new_phy(&phy_conf, &phy_hdl);
-
- // Init MicroPython / TinyUSB
- mp_usbd_init();
-
}
#if CONFIG_IDF_TARGET_ESP32S3
diff --git a/ports/esp32/usb.h b/ports/esp32/usb.h
index 2bfa3d31a..99437266d 100644
--- a/ports/esp32/usb.h
+++ b/ports/esp32/usb.h
@@ -28,7 +28,7 @@
#define MICROPY_HW_USB_CDC_TX_TIMEOUT_MS (500)
-void usb_init(void);
+void usb_phy_init(void);
void usb_usj_mode(void);
#endif // MICROPY_INCLUDED_ESP32_USB_H
diff --git a/shared/tinyusb/mp_usbd.h b/shared/tinyusb/mp_usbd.h
index 176b1ba50..b46555536 100644
--- a/shared/tinyusb/mp_usbd.h
+++ b/shared/tinyusb/mp_usbd.h
@@ -88,9 +88,22 @@ extern const uint8_t mp_usbd_builtin_desc_cfg[MP_USBD_BUILTIN_DESC_CFG_LEN];
void mp_usbd_task_callback(mp_sched_node_t *node);
-#if MICROPY_HW_ENABLE_USB_RUNTIME_DEVICE
-void mp_usbd_deinit(void);
+#if !MICROPY_HW_ENABLE_USB_RUNTIME_DEVICE
+
+static inline void mp_usbd_init(void) {
+ // Without runtime USB support, this can be a thin wrapper wrapper around tusb_init()
+ // which is called in the below helper function.
+ mp_usbd_init_tud();
+}
+
+static inline void mp_usbd_deinit(void) {
+ // Called in soft reset path. No-op if no runtime USB devices require cleanup.
+}
+
+#else
+// Runtime USB Device support requires more complex init/deinit
void mp_usbd_init(void);
+void mp_usbd_deinit(void);
const char *mp_usbd_runtime_string_cb(uint8_t index);
@@ -142,15 +155,7 @@ static inline bool mp_usb_device_builtin_enabled(const mp_obj_usb_device_t *usbd
return usbd->builtin_driver != MP_OBJ_FROM_PTR(&mp_type_usb_device_builtin_none);
}
-#else // Static USBD drivers only
-
-static inline void mp_usbd_init(void) {
- // Without runtime USB support, this can be a thin wrapper wrapper around tusb_init()
- // which is called in the below helper function.
- mp_usbd_init_tud();
-}
-
-#endif
+#endif // MICROPY_HW_ENABLE_USB_RUNTIME_DEVICE
#endif // MICROPY_HW_ENABLE_USBDEV