Skip to content

Commit 19fb1b4

Browse files
committed
stmhal: Add USB_VCP.setinterrupt method, to disable CTRL-C.
1 parent b395220 commit 19fb1b4

File tree

5 files changed

+19
-1
lines changed

5 files changed

+19
-1
lines changed

docs/library/pyb.USB_VCP.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@ Constructors
1717
Methods
1818
-------
1919

20+
.. method:: usb_vcp.setinterrupt(chr)
21+
22+
Set the character which interrupts running Python code. This is set
23+
to 3 (CTRL-C) by default, and when a CTRL-C character is received over
24+
the USB VCP port, a KeyboardInterrupt exception is raised.
25+
26+
Set to -1 to disable this interrupt feature. This is useful when you
27+
want to send raw bytes over the USB VCP port.
28+
2029
.. method:: usb_vcp.any()
2130

2231
Return ``True`` if any characters waiting, else ``False``.

docs/tutorial/pass_through.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ It's as simple as::
77
import select
88

99
def pass_through(usb, uart):
10+
usb.setinterrupt(-1)
1011
while True:
1112
select.select([usb, uart], [], [])
1213
if usb.any():

stmhal/qstrdefsport.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ Q(tell)
8585

8686
// for USB VCP class
8787
Q(USB_VCP)
88+
Q(setinterrupt)
8889
Q(send)
8990
Q(recv)
9091
Q(timeout)

stmhal/usb.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,12 @@ STATIC mp_obj_t pyb_usb_vcp_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint
174174
return (mp_obj_t)&pyb_usb_vcp_obj;
175175
}
176176

177+
STATIC mp_obj_t pyb_usb_vcp_setinterrupt(mp_obj_t self_in, mp_obj_t int_chr_in) {
178+
usb_vcp_set_interrupt_char(mp_obj_get_int(int_chr_in));
179+
return mp_const_none;
180+
}
181+
STATIC MP_DEFINE_CONST_FUN_OBJ_2(pyb_usb_vcp_setinterrupt_obj, pyb_usb_vcp_setinterrupt);
182+
177183
/// \method any()
178184
/// Return `True` if any characters waiting, else `False`.
179185
STATIC mp_obj_t pyb_usb_vcp_any(mp_obj_t self_in) {
@@ -252,6 +258,7 @@ mp_obj_t pyb_usb_vcp___exit__(mp_uint_t n_args, const mp_obj_t *args) {
252258
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_usb_vcp___exit___obj, 4, 4, pyb_usb_vcp___exit__);
253259

254260
STATIC const mp_map_elem_t pyb_usb_vcp_locals_dict_table[] = {
261+
{ MP_OBJ_NEW_QSTR(MP_QSTR_setinterrupt), (mp_obj_t)&pyb_usb_vcp_setinterrupt_obj },
255262
{ MP_OBJ_NEW_QSTR(MP_QSTR_any), (mp_obj_t)&pyb_usb_vcp_any_obj },
256263
{ MP_OBJ_NEW_QSTR(MP_QSTR_send), (mp_obj_t)&pyb_usb_vcp_send_obj },
257264
{ MP_OBJ_NEW_QSTR(MP_QSTR_recv), (mp_obj_t)&pyb_usb_vcp_recv_obj },

stmhal/usbd_cdc_interface.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ int USBD_CDC_Rx(uint8_t *buf, uint32_t len, uint32_t timeout) {
482482
for (uint32_t i = 0; i < len; i++) {
483483
// Wait until we have at least 1 byte to read
484484
uint32_t start = HAL_GetTick();
485-
while (!dev_is_connected || UserRxBufLen == UserRxBufCur) {
485+
while (UserRxBufLen == UserRxBufCur) {
486486
// Wraparound of tick is taken care of by 2's complement arithmetic.
487487
if (HAL_GetTick() - start >= timeout) {
488488
// timeout

0 commit comments

Comments
 (0)