aboutsummaryrefslogtreecommitdiff
path: root/ports/stm32/usb.c
diff options
context:
space:
mode:
authorAndrew Leech2019-02-21 05:23:41 +1100
committerDamien George2019-04-01 13:04:05 +1100
commit9d6f70f7154aa01a02d3de1c669241e3a1439218 (patch)
tree315110ddce74aadf6ff0e69dbe40e5ff983676b6 /ports/stm32/usb.c
parent0fb15fc3f4b532faa3ca4fe49809f9d9e6c5cd53 (diff)
stm32: Make default USB_VCP stream go through uos.dupterm for main REPL.
Use uos.dupterm for REPL configuration of the main USB_VCP(0) stream on dupterm slot 1, if USB is enabled. This means dupterm can also be used to disable the boot REPL port if desired, via uos.dupterm(None, 1). For efficiency this adds a simple hook to the global uos.dupterm code to work with streams that are known to be native streams.
Diffstat (limited to 'ports/stm32/usb.c')
-rw-r--r--ports/stm32/usb.c27
1 files changed, 20 insertions, 7 deletions
diff --git a/ports/stm32/usb.c b/ports/stm32/usb.c
index 1ff62b4ab..1db32c9ae 100644
--- a/ports/stm32/usb.c
+++ b/ports/stm32/usb.c
@@ -111,6 +111,10 @@ const mp_rom_obj_tuple_t pyb_usb_hid_keyboard_obj = {
};
void pyb_usb_init0(void) {
+ usb_device.usbd_cdc_itf.attached_to_repl = false;
+ #if MICROPY_HW_USB_ENABLE_CDC2
+ usb_device.usbd_cdc2_itf.attached_to_repl = false;
+ #endif
mp_hal_set_interrupt_char(-1);
MP_STATE_PORT(pyb_hid_report_desc) = MP_OBJ_NULL;
}
@@ -380,7 +384,7 @@ typedef struct _pyb_usb_vcp_obj_t {
usbd_cdc_itf_t *cdc_itf;
} pyb_usb_vcp_obj_t;
-STATIC const pyb_usb_vcp_obj_t pyb_usb_vcp_obj = {{&pyb_usb_vcp_type}, &usb_device.usbd_cdc_itf};
+const pyb_usb_vcp_obj_t pyb_usb_vcp_obj = {{&pyb_usb_vcp_type}, &usb_device.usbd_cdc_itf};
#if MICROPY_HW_USB_ENABLE_CDC2
STATIC const pyb_usb_vcp_obj_t pyb_usb_vcp2_obj = {{&pyb_usb_vcp_type}, &usb_device.usbd_cdc2_itf};
#endif
@@ -390,6 +394,10 @@ STATIC void pyb_usb_vcp_print(const mp_print_t *print, mp_obj_t self_in, mp_prin
mp_printf(print, "USB_VCP(%u)", id);
}
+void usb_vcp_attach_to_repl(const pyb_usb_vcp_obj_t *self, bool attached) {
+ self->cdc_itf->attached_to_repl = attached;
+}
+
/// \classmethod \constructor()
/// Create a new USB_VCP object.
STATIC mp_obj_t pyb_usb_vcp_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
@@ -566,13 +574,18 @@ 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);
- 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;
+ 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;
}
- return ret;
}
STATIC mp_uint_t pyb_usb_vcp_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) {