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 <i.abdalkader@gmail.com>
This commit is contained in:
iabdalkader 2023-04-11 13:06:58 +02:00 committed by Damien George
parent 9ea9e04ef6
commit d30f61ba0d
1 changed files with 8 additions and 8 deletions

View File

@ -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);