diff --git a/port/wiced/btstack_config.h b/port/wiced/btstack_config.h index 85a15c623..f9c731fe2 100644 --- a/port/wiced/btstack_config.h +++ b/port/wiced/btstack_config.h @@ -12,7 +12,7 @@ // BTstack features that can be enabled #define ENABLE_BLE #define ENABLE_CLASSIC -#define ENABLE_LE_SECURE_CONNECTIONS +// #define ENABLE_LE_SECURE_CONNECTIONS #define ENABLE_LOG_ERROR #define ENABLE_LOG_INFO diff --git a/port/wiced/create_examples.py b/port/wiced/create_examples.py index 6eb32f0a0..0bd4bd6d8 100755 --- a/port/wiced/create_examples.py +++ b/port/wiced/create_examples.py @@ -20,6 +20,7 @@ GLOBAL_INCLUDES += . $(NAME)_SOURCES := ../../../libraries/btstack/example/EXAMPLE.c $(NAME)_COMPONENTS += btstack/port/wiced +$(NAME)_CFLAGS += ADDITIONAL_CFLAGS ''' gatt_update_template = '''#!/bin/sh @@ -45,7 +46,14 @@ if not "WICED Version" in wiced_version: sys.exit(1) # show WICED version -print("Found %s" % wiced_version) +wiced_version = wiced_version.split()[2] +print("Found WICED SDK version: %s" % wiced_version) + +additional_cflags = "" +if wiced_version < "3.4.0": + print("Adding WICED_UART_READ_DOES_NOT_RETURN_BYTES_READ for SDK < 3.4.0") + additional_cflags = "-DWICED_UART_READ_DOES_NOT_RETURN_BYTES_READ" + # path to examples examples_embedded = script_path + "/../../example/" @@ -68,7 +76,7 @@ for file in os.listdir(examples_embedded): # create .mk file with open(apps_folder + example + ".mk", "wt") as fout: - fout.write(mk_template.replace("EXAMPLE", example).replace("TOOL", script_path).replace("DATE",time.strftime("%c"))) + fout.write(mk_template.replace("EXAMPLE", example).replace("TOOL", script_path).replace("ADDITIONAL_CFLAGS", additional_cflags).replace("DATE",time.strftime("%c"))) # create update_gatt.sh if .gatt file is present gatt_path = examples_embedded + example + ".gatt" diff --git a/port/wiced/hci_transport_h4_wiced.c b/port/wiced/hci_transport_h4_wiced.c index f7804f5a8..445261812 100644 --- a/port/wiced/hci_transport_h4_wiced.c +++ b/port/wiced/hci_transport_h4_wiced.c @@ -121,10 +121,22 @@ static wiced_result_t h4_main_notify_packet_send(void *arg){ } // executed on rx worker thread + static void h4_rx_worker_receive_bytes(int bytes_to_read){ + +#ifdef WICED_UART_READ_DOES_NOT_RETURN_BYTES_READ + // older API passes in number of bytes to read (checked in 3.3.1 and 3.4.0) platform_uart_receive_bytes(wiced_bt_uart_driver, &hci_packet[rx_worker_read_pos], bytes_to_read, WICED_NEVER_TIMEOUT); +#else + // newer API uses pointer to return number of read bytes + uint32_t bytes = bytes_to_read; + platform_uart_receive_bytes(wiced_bt_uart_driver, &hci_packet[rx_worker_read_pos], &bytes, WICED_NEVER_TIMEOUT); + // assumption: bytes = bytes_to_rad as timeout is never +#endif rx_worker_read_pos += bytes_to_read; + } + static wiced_result_t h4_rx_worker_receive_packet(void * arg){ #ifdef WICED_BT_UART_MANUAL_CTS_RTS diff --git a/port/wiced/main.c b/port/wiced/main.c index 2fa4667f2..53e850378 100644 --- a/port/wiced/main.c +++ b/port/wiced/main.c @@ -79,10 +79,10 @@ void application_start(void){ btstack_run_loop_init(btstack_run_loop_wiced_get_instance()); // enable full log output while porting - // hci_dump_open(NULL, HCI_DUMP_STDOUT); + hci_dump_open(NULL, HCI_DUMP_STDOUT); // init HCI - hci_init(hci_transport_h4_instance(btstack_uart_block_embedded_instance()), (void*) &hci_transport_config_uart); + hci_init(hci_transport_h4_instance(NULL), (void*) &hci_transport_config_uart); hci_set_link_key_db(btstack_link_key_db_memory_instance()); hci_set_chipset(btstack_chipset_bcm_instance()); diff --git a/port/wiced/readme.md b/port/wiced/readme.md index 37cd71fb9..4dcb51d6d 100644 --- a/port/wiced/readme.md +++ b/port/wiced/readme.md @@ -1,6 +1,8 @@ # BTstack port for WICED platform -To integrate BTstack into the WICED SDK, please move the BTstack project into WICED-SDK-X/libraries. +Only tested on Redbear Duo platform. Please install [RedBear WICED Add-On](https://github.com/redbear/WICED-SDK) first. + +To integrate BTstack into the WICED SDK, please move the BTstack project into WICED-SDK-3.5.2/libraries. Then create projects for BTstack examples in WICED/apps/btstack by running: ./create_examples.py @@ -13,15 +15,13 @@ to build the SPP-and-LE-Counter example. See WICED documentation about how to install it. -Only tested on Redbear Duo platform. - It should work with all WICED platforms that contain a Broadcom Bluetooth chipset. The maximal baud rate is limited to 3 mbps. The port uses the generated WIFI address plus 1 as Bluetooth MAC address. -The examples that implement a BLE Peripheral/provide a GATT Server use the GATT DB in the .gatt file. +The examples that implement a BLE Peripheral/provide a GATT Server that uses the GATT DB in the .gatt file. After modifying the .gatt file, please run ./update_gatt_db.sh in the apps/btstack/$(EXAMPLE) folder. diff --git a/port/wiced/wiced.mk b/port/wiced/wiced.mk index 817b56f53..59b7c293e 100644 --- a/port/wiced/wiced.mk +++ b/port/wiced/wiced.mk @@ -24,6 +24,7 @@ $(NAME)_SOURCES += \ ../../src/classic/sdp_client.c \ ../../src/classic/sdp_client_rfcomm.c \ ../../src/classic/sdp_util.c \ + ../../src/classic/spp_server.c \ ../../src/btstack_linked_list.c \ ../../src/btstack_memory.c \ ../../src/btstack_memory_pool.c \ @@ -39,7 +40,11 @@ $(NAME)_SOURCES += \ $(NAME)_SOURCES += \ main.c \ btstack_run_loop_wiced.c \ - btstack_uart_block_embedded.c \ hci_transport_h4_wiced.c \ ../../chipset/bcm/btstack_chipset_bcm.c \ - ../../../drivers/bluetooth/firmware/$(BT_CHIP)$(BT_CHIP_REVISION)/bt_firmware_image.c \ + +ifeq ($(BT_CHIP_XTAL_FREQUENCY),) +$(NAME)_SOURCES := ../../../drivers/bluetooth/firmware/$(BT_CHIP)$(BT_CHIP_REVISION)/bt_firmware_image.c +else +$(NAME)_SOURCES := ../../../drivers/bluetooth/firmware/$(BT_CHIP)$(BT_CHIP_REVISION)/$(BT_CHIP_XTAL_FREQUENCY)/bt_firmware_image.c +endif