rp2/rp2_flash: Call MICROPY_EVENT_POLL_HOOK_FAST after reading flash.

To allow the USB to work in cases where there is a lot of filesystem
access, in particular on boot.

For example, registering of the USB CDC interface may fail if:
- the board file system is lfs2 (default), and
- sys.path contains entries for the local file system (default), and
- files are imported by boot.py or main.py from frozen bytecode of the file
  system (common) and the file system contains many files, like 100.

In that case the board is very busy with scanning LFS, and registering the
USB interface seems to time out.  This commit fixes this by allowing the
USB to make progress during filesystem reads.

Also switch existing MICROPY_EVENT_POLL_HOOK uses in this file to
MICROPY_EVENT_POLL_HOOK_FAST now that the latter macro exists.
pull/10423/head
robert-hh 2023-01-06 11:36:18 +01:00 zatwierdzone przez Damien George
rodzic b208cf23e2
commit 5890a17ae0
1 zmienionych plików z 7 dodań i 2 usunięć

Wyświetl plik

@ -120,6 +120,11 @@ STATIC mp_obj_t rp2_flash_readblocks(size_t n_args, const mp_obj_t *args) {
offset += mp_obj_get_int(args[3]);
}
memcpy(bufinfo.buf, (void *)(XIP_BASE + self->flash_base + offset), bufinfo.len);
// MICROPY_EVENT_POLL_HOOK_FAST is called here to avoid a fail in registering
// USB at boot time, if the board is busy loading files or scanning the file
// system. MICROPY_EVENT_POLL_HOOK_FAST calls tud_task(). As the alternative
// tud_task() should be called in the USB IRQ. See discussion in PR #10423.
MICROPY_EVENT_POLL_HOOK_FAST;
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(rp2_flash_readblocks_obj, 3, 4, rp2_flash_readblocks);
@ -134,7 +139,7 @@ STATIC mp_obj_t rp2_flash_writeblocks(size_t n_args, const mp_obj_t *args) {
mp_uint_t atomic_state = MICROPY_BEGIN_ATOMIC_SECTION();
flash_range_erase(self->flash_base + offset, bufinfo.len);
MICROPY_END_ATOMIC_SECTION(atomic_state);
MICROPY_EVENT_POLL_HOOK
MICROPY_EVENT_POLL_HOOK_FAST;
// TODO check return value
} else {
offset += mp_obj_get_int(args[3]);
@ -143,7 +148,7 @@ STATIC mp_obj_t rp2_flash_writeblocks(size_t n_args, const mp_obj_t *args) {
mp_uint_t atomic_state = MICROPY_BEGIN_ATOMIC_SECTION();
flash_range_program(self->flash_base + offset, bufinfo.buf, bufinfo.len);
MICROPY_END_ATOMIC_SECTION(atomic_state);
MICROPY_EVENT_POLL_HOOK
MICROPY_EVENT_POLL_HOOK_FAST;
// TODO check return value
return mp_const_none;
}