stm32/mpbthciport: Only init the uart once, then use uart_set_baudrate.
Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
parent
d2a34c62e7
commit
bffb71f523
@ -32,8 +32,6 @@
|
||||
#include "pendsv.h"
|
||||
#include "lib/utils/mpirq.h"
|
||||
|
||||
#include "py/obj.h"
|
||||
|
||||
#if MICROPY_PY_BLUETOOTH
|
||||
|
||||
#define DEBUG_printf(...) // printf("mpbthciport.c: " __VA_ARGS__)
|
||||
@ -197,8 +195,18 @@ int mp_bluetooth_hci_uart_init(uint32_t port, uint32_t baudrate) {
|
||||
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 and adds the RXIDLE IRQ handler.
|
||||
mp_bluetooth_hci_uart_set_baudrate(baudrate);
|
||||
// Initialise the UART.
|
||||
uart_init(&mp_bluetooth_hci_uart_obj, 115200, UART_WORDLENGTH_8B, UART_PARITY_NONE, UART_STOPBITS_1, UART_HWCONTROL_RTS | UART_HWCONTROL_CTS);
|
||||
uart_set_rxbuf(&mp_bluetooth_hci_uart_obj, sizeof(hci_uart_rxbuf), hci_uart_rxbuf);
|
||||
|
||||
// Add IRQ handler for IDLE (i.e. packet finished).
|
||||
uart_irq_config(&mp_bluetooth_hci_uart_obj, false);
|
||||
mp_irq_init(&mp_bluetooth_hci_uart_irq_obj, &uart_irq_methods, MP_OBJ_FROM_PTR(&mp_bluetooth_hci_uart_obj));
|
||||
mp_bluetooth_hci_uart_obj.mp_irq_obj = &mp_bluetooth_hci_uart_irq_obj;
|
||||
mp_bluetooth_hci_uart_obj.mp_irq_trigger = UART_FLAG_IDLE;
|
||||
mp_bluetooth_hci_uart_irq_obj.handler = MP_OBJ_FROM_PTR(&mp_uart_interrupt_obj);
|
||||
mp_bluetooth_hci_uart_irq_obj.ishard = true;
|
||||
uart_irq_config(&mp_bluetooth_hci_uart_obj, true);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -213,22 +221,7 @@ int mp_bluetooth_hci_uart_deinit(void) {
|
||||
|
||||
int mp_bluetooth_hci_uart_set_baudrate(uint32_t baudrate) {
|
||||
DEBUG_printf("mp_bluetooth_hci_uart_set_baudrate(%lu) (stm32)\n", baudrate);
|
||||
if (!baudrate) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
uart_init(&mp_bluetooth_hci_uart_obj, baudrate, UART_WORDLENGTH_8B, UART_PARITY_NONE, UART_STOPBITS_1, UART_HWCONTROL_RTS | UART_HWCONTROL_CTS);
|
||||
uart_set_rxbuf(&mp_bluetooth_hci_uart_obj, sizeof(hci_uart_rxbuf), hci_uart_rxbuf);
|
||||
|
||||
// Add IRQ handler for IDLE (i.e. packet finished).
|
||||
uart_irq_config(&mp_bluetooth_hci_uart_obj, false);
|
||||
mp_irq_init(&mp_bluetooth_hci_uart_irq_obj, &uart_irq_methods, MP_OBJ_FROM_PTR(&mp_bluetooth_hci_uart_obj));
|
||||
mp_bluetooth_hci_uart_obj.mp_irq_obj = &mp_bluetooth_hci_uart_irq_obj;
|
||||
mp_bluetooth_hci_uart_obj.mp_irq_trigger = UART_FLAG_IDLE;
|
||||
mp_bluetooth_hci_uart_irq_obj.handler = MP_OBJ_FROM_PTR(&mp_uart_interrupt_obj);
|
||||
mp_bluetooth_hci_uart_irq_obj.ishard = true;
|
||||
uart_irq_config(&mp_bluetooth_hci_uart_obj, true);
|
||||
|
||||
uart_set_baudrate(&mp_bluetooth_hci_uart_obj, baudrate);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user