Skip to content

Commit baafb29

Browse files
committed
stmhal: Add uart.sendbreak() method, to send a break condition.
1 parent 089c3f3 commit baafb29

4 files changed

Lines changed: 19 additions & 0 deletions

File tree

docs/library/pyb.UART.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,3 +134,9 @@ Methods
134134

135135
Write a single character on the bus. ``char`` is an integer to write.
136136
Return value: ``None``.
137+
138+
.. method:: uart.sendbreak()
139+
140+
Send a break condition on the bus. This drives the bus low for a duration
141+
of 13 bits.
142+
Return value: ``None``.

stmhal/qstrdefsport.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ Q(any)
186186
Q(writechar)
187187
Q(readchar)
188188
Q(readinto)
189+
Q(sendbreak)
189190
Q(RTS)
190191
Q(CTS)
191192

stmhal/uart.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,14 @@ STATIC mp_obj_t pyb_uart_readchar(mp_obj_t self_in) {
614614
}
615615
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_uart_readchar_obj, pyb_uart_readchar);
616616

617+
// uart.sendbreak()
618+
STATIC mp_obj_t pyb_uart_sendbreak(mp_obj_t self_in) {
619+
pyb_uart_obj_t *self = self_in;
620+
self->uart.Instance->CR1 |= USART_CR1_SBK;
621+
return mp_const_none;
622+
}
623+
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_uart_sendbreak_obj, pyb_uart_sendbreak);
624+
617625
STATIC const mp_map_elem_t pyb_uart_locals_dict_table[] = {
618626
// instance methods
619627

@@ -634,6 +642,7 @@ STATIC const mp_map_elem_t pyb_uart_locals_dict_table[] = {
634642

635643
{ MP_OBJ_NEW_QSTR(MP_QSTR_writechar), (mp_obj_t)&pyb_uart_writechar_obj },
636644
{ MP_OBJ_NEW_QSTR(MP_QSTR_readchar), (mp_obj_t)&pyb_uart_readchar_obj },
645+
{ MP_OBJ_NEW_QSTR(MP_QSTR_sendbreak), (mp_obj_t)&pyb_uart_sendbreak_obj },
637646

638647
// class constants
639648
{ MP_OBJ_NEW_QSTR(MP_QSTR_RTS), MP_OBJ_NEW_SMALL_INT(UART_HWCONTROL_RTS) },

tests/pyb/uart.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,6 @@
1212
print(uart.write('123'))
1313
print(uart.write(b'abcd'))
1414
print(uart.writechar(1))
15+
16+
# make sure this method exists
17+
uart.sendbreak()

0 commit comments

Comments
 (0)