port/posix-h4-da14531: port for da14531 dev kit usb and pro

This commit is contained in:
Matthias Ringwald 2022-01-22 20:44:14 +01:00
parent 58b031dbaf
commit a16c312c96
5 changed files with 482 additions and 0 deletions

101
port/posix-h4-da14531/.gitignore vendored Normal file
View File

@ -0,0 +1,101 @@
a2dp_sink_demo
a2dp_source_demo
ancs_client_demo
ancs_client_demo.h
att_delayed_read_response
att_delayed_read_response.h
att_delayed_response
att_delayed_response.h
audio_duplex
avrcp_browsing_client
BCM43430A1.hcd
ble_central_test
ble_peripheral
ble_peripheral_sm_minimal
ble_peripheral_test
bluetooth_init_cc256*
bluetooth_init_cc2560_2.44.c
bluetooth_init_cc2560a_2.14.c
bluetooth_init_cc2560B_1.2_BT_Spec_4.0.c
bluetooth_init_cc2564_2.14.c
bluetooth_init_cc2564B_1.2_BT_Spec_4.0.c
bluetooth_init_cc2567_2.4.c
bluetooth_init_cc2567_2.8.c
bnep_test
classic_test
dut_mode_classic
gap_dedicated_bonding
gap_inquiry
gap_inquiry_and_bond
gap_le_advertisements
gap_link_keys
gatt_battery_query
gatt_battery_query.h
gatt_browser
gatt_browser.h
gatt_counter
gatt_counter.h
gatt_heart_rate_client
gatt_streamer_server
gatt_streamer_server.h
hfp_ag_demo
hfp_hf_demo
hid_host_demo
hid_keyboard_demo
hid_mouse_demo
hog_keyboard_demo
hog_keyboard_demo.h
hog_mouse_demo
hog_mouse_demo.h
hsp_ag_demo
hsp_ag_test
hsp_hs_demo
hsp_hs_test
l2cap_test
le_counter
le_counter.h
le_credit_based_flow_control_mode_client
le_credit_based_flow_control_mode_server
le_credit_based_flow_control_mode_server.h
le_streamer
le_streamer.h
le_streamer_and_counter_client
le_streamer_and_counter_client.h
le_streamer_client
led_counter
mesh_node_demo
mesh_node_demo.h
mod_player
nordic_spp_le_counter
nordic_spp_le_counter.h
nordic_spp_le_streamer
nordic_spp_le_streamer.h
pan_lwip_http_server
pbap_client_demo
profile.h
sco_input.msbc
sco_input.wav
sco_output.msbc
sdp_bnep_query
sdp_general_query
sdp_rfcomm_query
sine_player
sm_pairing_central
sm_pairing_central.h
sm_pairing_peripheral
sm_pairing_peripheral.h
spp_and_gatt_counter
spp_and_gatt_counter.h
spp_and_gatt_streamer
spp_and_gatt_streamer.h
spp_and_le_counter
spp_and_le_counter.h
spp_and_le_streamer
spp_and_le_streamer.h
spp_counter
spp_streamer
spp_streamer_client
TIInit_12.10.28.c
TIInit_12.8.32.c
ublox_spp_le_counter
ublox_spp_le_counter.h

View File

@ -0,0 +1,36 @@
# Makefile for libusb based examples
BTSTACK_ROOT ?= ../..
CORE += \
btstack_chipset_da145xx.c \
btstack_run_loop_posix.c \
btstack_tlv_posix.c \
btstack_uart_posix.c \
hci_dump_posix_fs.c \
hci_transport_h4.c \
le_device_db_tlv.c \
main.c \
btstack_stdin_posix.c \
btstack_signal.c \
hci_531_active_uart_460800.c \
# examples
CLASSIC =
include ${BTSTACK_ROOT}/example/Makefile.inc
CFLAGS += -g -Wall -Werror \
-I$(BTSTACK_ROOT)/platform/posix \
-I$(BTSTACK_ROOT)/chipset/da145xx \
-I$(BTSTACK_ROOT)/platform/embedded \
-I${BTSTACK_ROOT}/3rd-party/tinydir
# add pthread for ctrl-c signal handler
LDFLAGS += -lpthread
VPATH += ${BTSTACK_ROOT}/platform/posix
VPATH += ${BTSTACK_ROOT}/chipset/da145xx
EXAMPLES = ${EXAMPLES_GENERAL} ${EXAMPLES_LE_ONLY}
all: ${EXAMPLES}

View File

@ -0,0 +1,82 @@
# BTstack Port for POSIX Systems with Dialog Semiconductor DA14531 Controller
This port allows to use the DA14531 connected via UART with BTstack running on a POSIX host system.
Instead of storing the HCI firmware in the OTP, it first downloads the hci_531_active_uart_460800.hex firmware
from the 6.0.16.1144 SDK, before BTstack starts up.
After Power Cycle, please start one of the test applications and press the Reset button to trigger firmware download.
Please note that it does not detect if the firmware has already been downloaded, so you need to Power Cycle
the DA14531 before starting an example again.
Alternatively, after running one of the examples once to upload the firmware, you can use the regular 'posix-h4' port
and change the initial UART baud rate to 460800 as long as you don't power cycle the dev kit.
For production use, the DA14531 could be power cycled from the main CPU during startup, e.g. after the call
to btstack_chipset_da145xx_download_firmware_with_uart, or, the HCI firmware could be burned into the OTP.
# Software Setup / Firmware
On the [DA14531 USB Development Kit](https://www.dialog-semiconductor.com/products/bluetooth-low-energy/da14531-development-kit-usb),
the UART is configured via DIP switched. By this, the mapping to the DA14531 GPIOs is fixed. In SDK 6.0.6.1144, the
GPIO mapping of RTS and CTS is flipped. In order to be able to us the same HCI firmware on both dev kits, we've
used the following configuration in `user_perip_setup.h`
```C
#define UART1_TX_PORT GPIO_PORT_0
#define UART1_TX_PIN GPIO_PIN_0
#define UART1_RX_PORT GPIO_PORT_0
#define UART1_RX_PIN GPIO_PIN_1
#define UART1_RTSN_PORT GPIO_PORT_0
#define UART1_RTSN_PIN GPIO_PIN_4
#define UART1_CTSN_PORT GPIO_PORT_0
#define UART1_CTSN_PIN GPIO_PIN_3
```
We also increased the UART baudrate to 460800
```C
#define UART1_BAUDRATE UART_BAUDRATE_460800
```
We also disabled the SLEEP mode in user_config.h:
```C
static const sleep_state_t app_default_sleep_mode = ARCH_SLEEP_OFF;
```
After compilation with Keil uVision 5, the generated .hex file is copied into btstack/chipset/da145xx as
`hci_531_active_uart_460800.hex`, and then
`convert_hex_files" is used to convert it into a C data array.
# Hardware Setup - Dev Kit Pro
To use the [DA14531 Dev Kit Pro](https://www.dialog-semiconductor.com/products/bluetooth-low-energy/da14530-and-da14531-development-kit-pro)
with BTstack, please make the following modifications:
- Follow Chapter 4.1 and Figure 4 in the [DA14531 Development Kit Pro Hardware User Manual
UM-B-114](https://www.dialog-semiconductor.com/sites/default/files/2021-06/UM-B-114_DA14531_Devkit_Pro_Hardware_User%20manual_1v5.pdf)
and set SW1 of the 14531 daughter board into position "BUCK" position marked with an "H" on the left side.
- configure the dev kit for Full UART (4-wire) Configuration by adding jumper wires between J1 and J2
# Hardware Setup - Dev Kit USB
To use the [Dev Kit USB](https://www.dialog-semiconductor.com/products/bluetooth-low-energy/da14531-development-kit-usb#tab-field_tab_content_overview)
with BTstack, please make the following modifications:
- Follow Chapter 5.6 in the [DA14531 USB Development Kit Hardware UM-B-125](https://www.dialog-semiconductor.com/sites/default/files/um-b-125_da14531_usb_development_kit_hw_manual_1v1.pdf)
and set the DIP switches as described.
# Example Run
```
$ ./gatt_counter
Packet Log: /tmp/hci_dump.pklg
Phase 1: Download firmware
Phase 2: Main app
BTstack counter 0001
BTstack up and running on 80:EA:CA:70:00:08.
```

View File

@ -0,0 +1,60 @@
//
// btstack_config.h for POSIX H4 + DA14585 port
//
// Documentation: https://bluekitchen-gmbh.com/btstack/#how_to/
//
#ifndef BTSTACK_CONFIG_H
#define BTSTACK_CONFIG_H
// Port related features
#define HAVE_ASSERT
#define HAVE_BTSTACK_STDIN
#define HAVE_MALLOC
#define HAVE_POSIX_FILE_IO
#define HAVE_POSIX_TIME
// BTstack features that can be enabled
#define ENABLE_BLE
#define ENABLE_LE_CENTRAL
#define ENABLE_L2CAP_LE_CREDIT_BASED_FLOW_CONTROL_MODE
#define ENABLE_LE_DATA_LENGTH_EXTENSION
#define ENABLE_LE_PERIPHERAL
#define ENABLE_LE_PRIVACY_ADDRESS_RESOLUTION
#define ENABLE_LE_SECURE_CONNECTIONS
#define ENABLE_LOG_ERROR
#define ENABLE_LOG_INFO
#define ENABLE_MICRO_ECC_FOR_LE_SECURE_CONNECTIONS
#define ENABLE_PRINTF_HEXDUMP
// work around bug in Controller ACL fragmentation
#define ENABLE_LE_LIMIT_ACL_FRAGMENT_BY_MAX_OCTETS
// work around bug in Controller
#define ENABLE_LE_WHITELIST_TOUCH_AFTER_RESOLVING_LIST_UPDATE
// BTstack configuration. buffers, sizes, ...
#define HCI_ACL_PAYLOAD_SIZE (1691 + 4)
#define HCI_INCOMING_PRE_BUFFER_SIZE 14 // sizeof benep heade, avoid memcpy
#define NVM_NUM_DEVICE_DB_ENTRIES 20
// Mesh Configuration
#define ENABLE_MESH
#define ENABLE_MESH_ADV_BEARER
#define ENABLE_MESH_GATT_BEARER
#define ENABLE_MESH_PB_ADV
#define ENABLE_MESH_PB_GATT
#define ENABLE_MESH_PROVISIONER
#define ENABLE_MESH_PROXY_SERVER
#define MAX_NR_MESH_SUBNETS 2
#define MAX_NR_MESH_TRANSPORT_KEYS 16
#define MAX_NR_MESH_VIRTUAL_ADDRESSES 16
// allow for one NetKey update
#define MAX_NR_MESH_NETWORK_KEYS (MAX_NR_MESH_SUBNETS+1)
#endif

View File

@ -0,0 +1,203 @@
/*
* Copyright (C) 2014 BlueKitchen GmbH
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holders nor the names of
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
* 4. Any redistribution, use, or modification is done solely for
* personal benefit and not for any commercial purpose or for
* monetary gain.
*
* THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BLUEKITCHEN
* GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
* THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* Please inquire about commercial licensing options at
* contact@bluekitchen-gmbh.com
*
*/
#define BTSTACK_FILE__ "main.c"
// *****************************************************************************
//
// minimal setup for HCI code
//
// *****************************************************************************
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include "btstack_config.h"
#include "ble/le_device_db_tlv.h"
#include "btstack_chipset_da145xx.h"
#include "btstack_debug.h"
#include "btstack_event.h"
#include "btstack_memory.h"
#include "btstack_run_loop.h"
#include "btstack_run_loop_posix.h"
#include "btstack_signal.h"
#include "btstack_stdin.h"
#include "btstack_tlv_posix.h"
#include "btstack_uart.h"
#include "hci.h"
#include "hci_531_active_uart_460800.h"
#include "hci_dump.h"
#include "hci_dump_posix_fs.h"
#include "hci_transport.h"
#include "hci_transport_h4.h"
static int main_argc;
static const char ** main_argv;
static const btstack_uart_t * uart_driver;
static btstack_uart_config_t uart_config;
#define TLV_DB_PATH_PREFIX "/tmp/btstack_"
#define TLV_DB_PATH_POSTFIX ".tlv"
static char tlv_db_path[100];
static const btstack_tlv_t * tlv_impl;
static btstack_tlv_posix_t tlv_context;
static bd_addr_t local_addr;
static bool shutdown_triggered;
int btstack_main(int argc, const char * argv[]);
static hci_transport_config_uart_t transport_config = {
HCI_TRANSPORT_CONFIG_UART,
460800,
0, // main baudrate
0, // flow control
NULL,
};
static btstack_packet_callback_registration_t hci_event_callback_registration;
static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
if (packet_type != HCI_EVENT_PACKET) return;
switch (hci_event_packet_get_type(packet)){
case BTSTACK_EVENT_STATE:
switch(btstack_event_state_get_state(packet)){
case HCI_STATE_WORKING:
gap_local_bd_addr(local_addr);
printf("BTstack up and running on %s.\n", bd_addr_to_str(local_addr));
strcpy(tlv_db_path, TLV_DB_PATH_PREFIX);
strcat(tlv_db_path, bd_addr_to_str(local_addr));
strcat(tlv_db_path, TLV_DB_PATH_POSTFIX);
tlv_impl = btstack_tlv_posix_init_instance(&tlv_context, tlv_db_path);
btstack_tlv_set_instance(tlv_impl, &tlv_context);
le_device_db_tlv_configure(tlv_impl, &tlv_context);
break;
case HCI_STATE_OFF:
btstack_tlv_posix_deinit(&tlv_context);
if (!shutdown_triggered) break;
// reset stdin
btstack_stdin_reset();
log_info("Good bye, see you.\n");
exit(0);
break;
default:
break;
}
break;
default:
break;
}
}
static void trigger_shutdown(void){
printf("CTRL-C - SIGINT received, shutting down..\n");
log_info("sigint_handler: shutting down");
shutdown_triggered = true;
hci_power_control(HCI_POWER_OFF);
}
static int led_state = 0;
void hal_led_toggle(void){
led_state = 1 - led_state;
printf("LED State %u\n", led_state);
}
static void phase2(int status){
if (status){
printf("Download firmware failed\n");
return;
}
printf("Phase 2: Main app\n");
// init HCI
const hci_transport_t * transport = hci_transport_h4_instance_for_uart(uart_driver);
hci_init(transport, (void*) &transport_config);
// inform about BTstack state
hci_event_callback_registration.callback = &packet_handler;
hci_add_event_handler(&hci_event_callback_registration);
// register callback for CTRL-c
btstack_signal_register_callback(SIGINT, &trigger_shutdown);
// setup app
btstack_main(main_argc, main_argv);
}
int main(int argc, const char * argv[]){
/// GET STARTED with BTstack ///
btstack_memory_init();
btstack_run_loop_init(btstack_run_loop_posix_get_instance());
// log into file using HCI_DUMP_PACKETLOGGER format
const char * pklg_path = "/tmp/hci_dump.pklg";
hci_dump_posix_fs_open(pklg_path, HCI_DUMP_PACKETLOGGER);
const hci_dump_t * hci_dump_impl = hci_dump_posix_fs_get_instance();
hci_dump_init(hci_dump_impl);
printf("Packet Log: %s\n", pklg_path);
// pick serial port and configure uart block driver
transport_config.device_name = "/dev/tty.usbserial-143342200";
uart_driver = btstack_uart_posix_instance();
// extract UART config from transport config, but overide initial uart speed
uart_config.baudrate = 115200;
uart_config.flowcontrol = 0;
uart_config.device_name = transport_config.device_name;
uart_driver->init(&uart_config);
main_argc = argc;
main_argv = argv;
// phase #1 download firmware
printf("Phase 1: Download firmware\n");
// phase #2 start main app
btstack_chipset_da145xx_download_firmware_with_uart(uart_driver, da145xx_fw_data, da145xx_fw_size, &phase2);
// go
btstack_run_loop_execute();
return 0;
}