@@ -42,7 +42,6 @@ typedef struct _machine_uart_obj_t {
42
42
uint8_t bits ;
43
43
uint8_t parity ;
44
44
uint8_t stop ;
45
- uint32_t baudrate ;
46
45
int8_t tx ;
47
46
int8_t rx ;
48
47
int8_t rts ;
@@ -60,8 +59,10 @@ QueueHandle_t UART_QUEUE[UART_NUM_MAX] = {};
60
59
61
60
STATIC void machine_uart_print (const mp_print_t * print , mp_obj_t self_in , mp_print_kind_t kind ) {
62
61
machine_uart_obj_t * self = MP_OBJ_TO_PTR (self_in );
62
+ uint32_t baudrate ;
63
+ uart_get_baudrate (self -> uart_num , & baudrate );
63
64
mp_printf (print , "UART(%u, baudrate=%u, bits=%u, parity=%s, stop=%u, tx=%d, rx=%d, rts=%d, cts=%d, timeout=%u, timeout_char=%u)" ,
64
- self -> uart_num , self -> baudrate , self -> bits , _parity_name [self -> parity ],
65
+ self -> uart_num , baudrate , self -> bits , _parity_name [self -> parity ],
65
66
self -> stop , self -> tx , self -> rx , self -> rts , self -> cts , self -> timeout , self -> timeout_char );
66
67
}
67
68
@@ -86,9 +87,10 @@ STATIC void machine_uart_init_helper(machine_uart_obj_t *self, size_t n_args, co
86
87
uart_wait_tx_done (self -> uart_num , pdMS_TO_TICKS (1000 ));
87
88
88
89
// set baudrate
90
+ uint32_t baudrate = 115200 ;
89
91
if (args [ARG_baudrate ].u_int > 0 ) {
90
- self -> baudrate = args [ARG_baudrate ].u_int ;
91
- uart_set_baudrate (self -> uart_num , self -> baudrate );
92
+ uart_set_baudrate ( self -> uart_num , args [ARG_baudrate ].u_int ) ;
93
+ uart_get_baudrate (self -> uart_num , & baudrate );
92
94
}
93
95
94
96
uart_set_pin (self -> uart_num , args [ARG_tx ].u_int , args [ARG_rx ].u_int , args [ARG_rts ].u_int , args [ARG_cts ].u_int );
@@ -174,7 +176,7 @@ STATIC void machine_uart_init_helper(machine_uart_obj_t *self, size_t n_args, co
174
176
// set timeout_char
175
177
// make sure it is at least as long as a whole character (13 bits to be safe)
176
178
self -> timeout_char = args [ARG_timeout_char ].u_int ;
177
- uint32_t min_timeout_char = 13000 / self -> baudrate + 1 ;
179
+ uint32_t min_timeout_char = 13000 / baudrate + 1 ;
178
180
if (self -> timeout_char < min_timeout_char ) {
179
181
self -> timeout_char = min_timeout_char ;
180
182
}
@@ -209,7 +211,6 @@ STATIC mp_obj_t machine_uart_make_new(const mp_obj_type_t *type, size_t n_args,
209
211
machine_uart_obj_t * self = m_new_obj (machine_uart_obj_t );
210
212
self -> base .type = & machine_uart_type ;
211
213
self -> uart_num = uart_num ;
212
- self -> baudrate = 115200 ;
213
214
self -> bits = 8 ;
214
215
self -> parity = 0 ;
215
216
self -> stop = 1 ;
0 commit comments