Resetting the BTStack

406 views
Skip to first unread message

Richard Sawler

unread,
Oct 28, 2021, 2:45:54 PM10/28/21
to btstack-dev
Hello,

I am using the BTStack running on an STM32L4 MCU with the ATWILC3000 wifi/BLE controller. I have finished my port and the BLE functionality works great as I am able to add and remove connections and transfer data between devices.

My challenge now is that I want to turn off the WILC3000 device when I am not using the BLE connection. This would require that I pause or stop the BTStack when I power off the device and then reinitialize the device and the stack when the device is powered back on.

I do not see a clean way to handle this use case and am wondering if you have an direction on stopping and restarting the BT Stack.

Thank you

Matthias Ringwald

unread,
Oct 29, 2021, 9:50:32 AM10/29/21
to btsta...@googlegroups.com
Hi Richard

The official way to power off a Bluetooth Controller is to call hci_power_control(HCI_POWER_OFF) - analog to the initial power on in all examples.
You can turn the WILC3000 off either in the HCI Transport or btstack_power_t impelemntation. Power off and later on works in the libusb port.

Cheers
Matthias
> --
> You received this message because you are subscribed to the Google Groups "btstack-dev" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to btstack-dev...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/btstack-dev/a1ceeea2-bd39-4163-8643-b9ab12298f1bn%40googlegroups.com.

Ricky Sawler

unread,
Nov 18, 2021, 8:39:40 AM11/18/21
to btstack-dev

Hi Matthias,

I am not sure that I fully understand how to integrate powering the WILC up/down with the bt stack. Maybe I need to provide a little more context to help frame the question.

I am running the bt stack with freertos on an STM32L4MCU. I have ported code based on Atmel Studio Framework example projects which used a ATSAM7 microcontroller to allow me to power on the WILC module and have a functional BLE UART connected to the Microchip Bluetooth Data mobile application.

Here is the code which starts my Bluetooth task once the WILC has been powered up

       btstack_run_loop_task = xHandle;

    // start with BTstack init - especially configure HCI Transport
    btstack_memory_init();

    btstack_run_loop_init(btstack_run_loop_freertos_get_instance());

    // setup UART HAL + Run Loop integration
    uart_driver = btstack_uart_block_freertos_instance();    // RTOS

    // extract UART config from transport config, but disable flow control and use default baudrate
    uart_config.baudrate    = HCI_DEFAULT_BAUDRATE;
    uart_config.flowcontrol = 0;
    uart_config.device_name = transport_config.device_name;
    uart_driver->init(&uart_config);
    btstack_chipset_atwilc3000_download_firmware(uart_driver, transport_config.baudrate_init, transport_config.flowcontrol, NULL, 0, &bt_app_init);
    btstack_run_loop_execute();

The btstack_chipset_atwilc3000_download_firmware function includes the following to complete the firmware download and configure the uart for normal operation

static void atwilc3000_start(void);
static void atwilc3000_w4_command_complete_reset(void);
static void atwilc3000_w4_command_complete_read_local_version_information(void);
static void atwilc3000_wait_for_reset_completed(void);
static void atwilc3000_configure_uart(btstack_timer_source_t * ts);
atwilc3000_done();

Once the download firmware process is complete the bt_app_init function is called which handles initializing the HCI transport layer

static void bt_app_init(int status){
    // init HCI
    const hci_transport_t *transport = hci_transport_h4_instance(uart_driver);
    hci_init(transport, (void*) &transport_config);
    hci_set_chipset(btstack_chipset_atwilc3000_instance());
    hci_set_link_key_db(btstack_link_key_db_memory_instance());

        tss_app_setup(); 
        // turn on! 
        hci_power_control(HCI_POWER_ON);
}

Once all of this initialization has finished I am able to see the device advertised on the Microchip Bluetooth Data mobile application and open the transparent serial service.

At this point in our application I want to power down the WILC device to save power and therefore “pause” the btstack. I think you are suggesting this would be done by calling the hci_power_control(HCI_POWER_OFF) command? Will this decouple the btstack from the controller? I would then be able to power off the WILC hardware leaving the bt stack running in an IDLE state?

Later in the application I will wont to turn the WILC controller back on and reconnect to the btstack. I will again need to go through the btstack_chipset_atwilc3000_download_firmware process but perhaps I don’t need to do the full HCI initialization process again? But I will need to connect the HCI interface to the controller and power the HCI interface back on. Which HCI initialization functions are needed for this step?

Thanks for your support

sven.kr...@gmail.com

unread,
Nov 18, 2021, 10:09:30 AM11/18/21
to btsta...@googlegroups.com
Hi,

I have already done this (with a CC2564). Before you power down you have to send the power off command: hci_power_control(HCI_POWER_OFF); Then you can pull the reset of the bt module, release the UART and power off the device (it depends on your hardware)

To re-power just do the same thing as on normal power up. Power on the device, bring up the UART, perform a reset. After this you can start with HCI_POWER_ON

It's a good thing to split the initialization functions. One for the static initialization like btstack_memory_init() and one to bringup the stack running. The first one is called only once during powerup and the second one is called every time you bring up the bluetooth.

Hope it helps!

Kind regards

Sven

At this point in our application I want to power down the WILC device to save power and therefore “pause” the btstack. I think you are suggesting this would be done by calling the hci_power_control(HCI_POWER_OFF)command? Will this decouple the btstack from the controller? I would then be able to power off the WILC hardware leaving the bt stack running in an IDLE state?

Later in the application I will wont to turn the WILC controller back on and reconnect to the btstack. I will again need to go through the btstack_chipset_atwilc3000_download_firmware process but perhaps I don’t need to do the full HCI initialization process again? But I will need to connect the HCI interface to the controller and power the HCI interface back on. Which HCI initialization functions are needed for this step?

Thanks for your support

On Friday, October 29, 2021 at 10:50:32 AM UTC-3 Matthias Ringwald wrote:
Hi Richard

The official way to power off a Bluetooth Controller is to call hci_power_control(HCI_POWER_OFF) - analog to the initial power on in all examples.
You can turn the WILC3000 off either in the HCI Transport or btstack_power_t impelemntation. Power off and later on works in the libusb port.

Cheers
Matthias

> On 28 Oct 2021, at 15:31, Richard Sawler <junk4...@gmail.com> wrote:
>
> Hello,
>
> I am using the BTStack running on an STM32L4 MCU with the ATWILC3000 wifi/BLE controller. I have finished my port and the BLE functionality works great as I am able to add and remove connections and transfer data between devices.
>
> My challenge now is that I want to turn off the WILC3000 device when I am not using the BLE connection. This would require that I pause or stop the BTStack when I power off the device and then reinitialize the device and the stack when the device is powered back on.
>
> I do not see a clean way to handle this use case and am wondering if you have an direction on stopping and restarting the BT Stack.
>
> Thank you
>
> --
> You received this message because you are subscribed to the Google Groups "btstack-dev" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to btstack-dev...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/btstack-dev/a1ceeea2-bd39-4163-8643-b9ab12298f1bn%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "btstack-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to btstack-dev...@googlegroups.com.

Matthias Ringwald

unread,
Nov 22, 2021, 8:59:14 AM11/22/21
to btsta...@googlegroups.com
Hi Ricky

Did you get it to work with Sven's recommendations? After hci_power_control(HCI_POWER_OFF), you have to wait for state 'OFF'. You can then disable power etc. Alternatively, you could implement the btstack_control_t interface ffrom btstack_control.h and then configure hci with hci_set_control(..).

The BTstack run loop keeps active, but it won't do anything. To continue later, you'll need to power your controller again and, in the case of the ATWILC3000, upload the firmware patch. After that, you can call hci_power_control(HCI_POWER_ON) as already mentioned. It will start up the stack again.

Best
Matthias
> To view this discussion on the web visit https://groups.google.com/d/msgid/btstack-dev/b65a253539d783749b7e8c1d6d2a88b91bf1b2ee.camel%40gmail.com.

Ricky Sawler

unread,
Nov 22, 2021, 1:16:03 PM11/22/21
to btstack-dev
Hi Matthias and Sven,
Thank you for your responses. I was able to get this to work after separating some of the initialization and changing my boot sequencing a bit. I did not end up implementing the btstack_control_t interface.

Ricky Sawler

unread,
Dec 2, 2021, 1:53:58 PM12/2/21
to btstack-dev
Hello Matthias,

I have a follow-up question to putting the HCI to sleep. If I call hci_power_control(HCI_POWER_OFF) when I have an LE connection the connection is not closing well. Is there a a clean to force all active connections to disconnect and is this something I should have to do when I power off the HCI?

Matthias Ringwald

unread,
Dec 2, 2021, 4:12:12 PM12/2/21
to btsta...@googlegroups.com
Hi Ricky

What happens to active LE connections? Could you be more specific? and/or also provide hci_dump.pklg files.
After call hci_power_control(HCI_POWER_OFF), you'll need to wait until you receive the event OFF before powering down the Controller.

The code for power down includes logic to close all active HCI connections and properly notify higher layers - even in the case of a crashed Bluetooth Controller (at least on on the latest versions of master & develop).

Best
Matthias
> To view this discussion on the web visit https://groups.google.com/d/msgid/btstack-dev/d68e86e2-c52a-4223-8811-35ca586a5855n%40googlegroups.com.

Reply all
Reply to author
Forward
0 new messages