Skip to content

Commit

Permalink
stm32/mpbthciport: Increase char timeout of BT HCI UART.
Browse files Browse the repository at this point in the history
The 2ms used previously was not long enough and it could lose HCI sync.

Also print error on tx failure to make this more obvious in the future.
  • Loading branch information
pi-anl authored and dpgeorge committed Sep 8, 2020
1 parent 8b00aea commit 6077c63
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions ports/stm32/mpbthciport.c
Expand Up @@ -142,8 +142,9 @@ int mp_bluetooth_hci_uart_init(uint32_t port, uint32_t baudrate) {
mp_bluetooth_hci_uart_obj.base.type = &pyb_uart_type;
mp_bluetooth_hci_uart_obj.uart_id = port;
mp_bluetooth_hci_uart_obj.is_static = true;
mp_bluetooth_hci_uart_obj.timeout = 2;
mp_bluetooth_hci_uart_obj.timeout_char = 2;
// We don't want to block indefinitely, but expect flow control is doing its job.
mp_bluetooth_hci_uart_obj.timeout = 200;
mp_bluetooth_hci_uart_obj.timeout_char = 200;
MP_STATE_PORT(pyb_uart_obj_all)[mp_bluetooth_hci_uart_obj.uart_id - 1] = &mp_bluetooth_hci_uart_obj;

// This also initialises the UART.
Expand Down Expand Up @@ -184,7 +185,11 @@ int mp_bluetooth_hci_uart_write(const uint8_t *buf, size_t len) {
// DEBUG_printf("mp_bluetooth_hci_uart_write (stm32)\n");

mp_bluetooth_hci_controller_wakeup();
uart_tx_strn(&mp_bluetooth_hci_uart_obj, (void *)buf, len);
int errcode;
uart_tx_data(&mp_bluetooth_hci_uart_obj, (void *)buf, len, &errcode);
if (errcode != 0) {
printf("\nmp_bluetooth_hci_uart_write: failed to write to UART %d\n", errcode);
}
return 0;
}

Expand Down

0 comments on commit 6077c63

Please sign in to comment.