From d30f61ba0d533f5889d036b24423521e8a2b77a4 Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Tue, 11 Apr 2023 13:06:58 +0200 Subject: [PATCH] drivers/ninaw10/nina_bt_hci: Make some minor fixes to HCI driver. Fixes are: - Reset the module first before changing GPIO1 direction. - Skip spurious bytes received after reset. - Use HCI UART ID and baudrate when reinitializing UART. - Disable all printf output which causes unit-tests to fail. Signed-off-by: iabdalkader --- drivers/ninaw10/nina_bt_hci.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/ninaw10/nina_bt_hci.c b/drivers/ninaw10/nina_bt_hci.c index 6dc3204471..754e99ed76 100644 --- a/drivers/ninaw10/nina_bt_hci.c +++ b/drivers/ninaw10/nina_bt_hci.c @@ -50,7 +50,7 @@ #define OCF_SET_EVENT_MASK (0x0001) #define OCF_RESET (0x0003) -#define error_printf(...) mp_printf(&mp_plat_print, "nina_bt_hci.c: " __VA_ARGS__) +#define error_printf(...) // mp_printf(&mp_plat_print, "nina_bt_hci.c: " __VA_ARGS__) #define debug_printf(...) // mp_printf(&mp_plat_print, "nina_bt_hci.c: " __VA_ARGS__) // Provided by the port, and also possibly shared with the stack. @@ -86,7 +86,7 @@ static int nina_hci_cmd(int ogf, int ocf, size_t param_len, const uint8_t *param buf[i] = mp_bluetooth_hci_uart_readchar(); // There seems to be a sync issue with this fw/module. - if (i == 0 && buf[0] == 0xFF) { + if (i == 0 && (buf[0] == 0xFF || buf[0] == 0xFE)) { continue; } @@ -121,19 +121,19 @@ static int nina_hci_cmd(int ogf, int ocf, size_t param_len, const uint8_t *param int mp_bluetooth_hci_controller_init(void) { // This is called immediately after the UART is initialised during stack initialisation. - mp_hal_pin_output(MICROPY_HW_NINA_GPIO1); mp_hal_pin_output(MICROPY_HW_NINA_RESET); - - mp_hal_pin_write(MICROPY_HW_NINA_GPIO1, 0); mp_hal_pin_write(MICROPY_HW_NINA_RESET, 0); - mp_hal_delay_ms(100); + + mp_hal_pin_output(MICROPY_HW_NINA_GPIO1); + mp_hal_pin_write(MICROPY_HW_NINA_GPIO1, 0); + mp_hal_delay_ms(150); mp_hal_pin_write(MICROPY_HW_NINA_RESET, 1); mp_hal_delay_ms(750); - // The UART must be re-initialize here because the GPIO1/RX pin is used initially + // The UART must be re-initialized here because the GPIO1/RX pin is used initially // to reset the module in Bluetooth mode. This will change back the pin to UART RX. - mp_bluetooth_hci_uart_init(0, 0); + mp_bluetooth_hci_uart_init(MICROPY_HW_BLE_UART_ID, MICROPY_HW_BLE_UART_BAUDRATE); // Send reset command return nina_hci_cmd(OGF_HOST_CTL, OCF_RESET, 0, NULL);