diff options
Diffstat (limited to 'ports/stm32/usb.c')
| -rw-r--r-- | ports/stm32/usb.c | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/ports/stm32/usb.c b/ports/stm32/usb.c index ca5cc682e..f2f3d7458 100644 --- a/ports/stm32/usb.c +++ b/ports/stm32/usb.c @@ -634,6 +634,12 @@ STATIC void pyb_usb_vcp_print(const mp_print_t *print, mp_obj_t self_in, mp_prin void usb_vcp_attach_to_repl(const pyb_usb_vcp_obj_t *self, bool attached) { self->cdc_itf->attached_to_repl = attached; + if (attached) { + // Default behavior is non-blocking when attached to repl + self->cdc_itf->flow &= ~USBD_CDC_FLOWCONTROL_CTS; + } else { + self->cdc_itf->flow |= USBD_CDC_FLOWCONTROL_CTS; + } } /// \classmethod \constructor() @@ -791,6 +797,7 @@ STATIC const mp_rom_map_elem_t pyb_usb_vcp_locals_dict_table[] = { // class constants { MP_ROM_QSTR(MP_QSTR_RTS), MP_ROM_INT(USBD_CDC_FLOWCONTROL_RTS) }, + { MP_ROM_QSTR(MP_QSTR_CTS), MP_ROM_INT(USBD_CDC_FLOWCONTROL_CTS) }, }; STATIC MP_DEFINE_CONST_DICT(pyb_usb_vcp_locals_dict, pyb_usb_vcp_locals_dict_table); @@ -808,18 +815,13 @@ STATIC mp_uint_t pyb_usb_vcp_read(mp_obj_t self_in, void *buf, mp_uint_t size, i STATIC mp_uint_t pyb_usb_vcp_write(mp_obj_t self_in, const void *buf, mp_uint_t size, int *errcode) { pyb_usb_vcp_obj_t *self = MP_OBJ_TO_PTR(self_in); - if (self->cdc_itf->attached_to_repl) { - usbd_cdc_tx_always(self->cdc_itf, (const byte*)buf, size); - return size; - } else { - int ret = usbd_cdc_tx(self->cdc_itf, (const byte*)buf, size, 0); - if (ret == 0) { - // return EAGAIN error to indicate non-blocking - *errcode = MP_EAGAIN; - return MP_STREAM_ERROR; - } - return ret; + int ret = usbd_cdc_tx_flow(self->cdc_itf, (const byte*)buf, size); + if (ret == 0) { + // return EAGAIN error to indicate non-blocking + *errcode = MP_EAGAIN; + return MP_STREAM_ERROR; } + return ret; } STATIC mp_uint_t pyb_usb_vcp_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) { |
