Add posix-h4-bcm port for newer Infineon controllers

This commit is contained in:
Matthias Ringwald 2023-04-06 11:35:18 +02:00
parent 0df9df8ce4
commit 893dbb9455
6 changed files with 507 additions and 0 deletions

View File

@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- nxp: support for bootloader version v1, e.g. NXP 88W8997
- Port for Renesas RA6M4 with DA14531
- Port for NXP Controller on POSIX (posix-h4-nxp)
- Port for newer Infineon Controller on POSIX (posix-h4-bcm) that requires autobaud-mode
## Removed
- AVDTP Source: avdtp_source_stream_send_media_payload, use avdtp_source_stream_send_media_payload_rtp instead

1
port/posix-h4-bcm/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
cmake-build-debug

View File

@ -0,0 +1,181 @@
cmake_minimum_required (VERSION 3.18)
project(BTstack-posix-nxp)
SET(BTSTACK_ROOT ${CMAKE_SOURCE_DIR}/../..)
# extra compiler warnings
if ("${CMAKE_C_COMPILER_ID}" MATCHES ".*Clang.*")
# using Clang
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wunused-variable -Wswitch-default -Werror")
elseif ("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU")
# using GCC
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wunused-but-set-variable -Wunused-variable -Wswitch-default -Werror")
elseif ("${CMAKE_C_COMPILER_ID}" STREQUAL "Intel")
# using Intel C++
elseif ("${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC")
# using Visual Studio C++
endif()
# pkgconfig
find_package(PkgConfig QUIET)
# portaudio
if (PgConfig_FOUND)
pkg_check_modules(PORTAUDIO REQUIRED portaudio-2.0)
if(PORTAUDIO_FOUND)
message("HAVE_PORTAUDIO")
include_directories(${PORTAUDIO_INCLUDE_DIRS})
link_directories(${PORTAUDIO_LIBRARY_DIRS})
link_libraries(${PORTAUDIO_LIBRARIES})
# CMake 3.12 - add_compile_definitions(HAVE_PORTAUDIO)
SET(CMAKE_C_FLAGS "-DHAVE_PORTAUDIO")
endif()
endif()
# to generate .h from .gatt files
find_package (Python REQUIRED COMPONENTS Interpreter)
include_directories(${CMAKE_CURRENT_BINARY_DIR})
# local dir for btstack_config.h after build dir to avoid using .h from Makefile
include_directories(.)
include_directories(${BTSTACK_ROOT}/3rd-party/micro-ecc)
include_directories(${BTSTACK_ROOT}/3rd-party/bluedroid/decoder/include)
include_directories(${BTSTACK_ROOT}/3rd-party/bluedroid/encoder/include)
include_directories(${BTSTACK_ROOT}/3rd-party/lc3-google/include)
include_directories(${BTSTACK_ROOT}/3rd-party/md5)
include_directories(${BTSTACK_ROOT}/3rd-party/hxcmod-player)
include_directories(${BTSTACK_ROOT}/3rd-party/hxcmod-player/mod)
include_directories(${BTSTACK_ROOT}/3rd-party/lwip/core/src/include)
include_directories(${BTSTACK_ROOT}/3rd-party/lwip/dhcp-server)
include_directories(${BTSTACK_ROOT}/3rd-party/rijndael)
include_directories(${BTSTACK_ROOT}/3rd-party/yxml)
include_directories(${BTSTACK_ROOT}/3rd-party/tinydir)
include_directories(${BTSTACK_ROOT}/src)
include_directories(${BTSTACK_ROOT}/chipset/bcm)
include_directories(${BTSTACK_ROOT}/platform/embedded)
include_directories(${BTSTACK_ROOT}/platform/lwip)
include_directories(${BTSTACK_ROOT}/platform/lwip/port)
include_directories(${BTSTACK_ROOT}/platform/posix)
file(GLOB SOURCES_SRC "${BTSTACK_ROOT}/src/*.c" "${BTSTACK_ROOT}/example/sco_demo_util.c")
file(GLOB SOURCES_BLE "${BTSTACK_ROOT}/src/ble/*.c")
file(GLOB SOURCES_BLUEDROID "${BTSTACK_ROOT}/3rd-party/bluedroid/encoder/srce/*.c" "${BTSTACK_ROOT}/3rd-party/bluedroid/decoder/srce/*.c")
file(GLOB SOURCES_CLASSIC "${BTSTACK_ROOT}/src/classic/*.c")
file(GLOB SOURCES_MESH "${BTSTACK_ROOT}/src/mesh/*.c")
file(GLOB SOURCES_GATT "${BTSTACK_ROOT}/src/ble/gatt-service/*.c")
file(GLOB SOURCES_UECC "${BTSTACK_ROOT}/3rd-party/micro-ecc/uECC.c")
file(GLOB SOURCES_HXCMOD "${BTSTACK_ROOT}/3rd-party/hxcmod-player/*.c" "${BTSTACK_ROOT}/3rd-party/hxcmod-player/mods/*.c")
file(GLOB SOURCES_MD5 "${BTSTACK_ROOT}/3rd-party/md5/md5.c")
file(GLOB SOURCES_RIJNDAEL "${BTSTACK_ROOT}/3rd-party/rijndael/rijndael.c")
file(GLOB SOURCES_YXML "${BTSTACK_ROOT}/3rd-party/yxml/yxml.c")
file(GLOB SOURCES_POSIX "${BTSTACK_ROOT}/platform/posix/*.c")
file(GLOB SOURCES_BCM "${BTSTACK_ROOT}/chipset/bcm/*.c")
file(GLOB SOURCES_LC3_GOOGLE "${BTSTACK_ROOT}/3rd-party/lc3-google/src/*.c")
file(GLOB SOURCES_PORT "*.c")
set(LWIP_CORE_SRC
${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/def.c
${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/inet_chksum.c
${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/init.c
${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/ip.c
${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/mem.c
${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/memp.c
${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/netif.c
${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/pbuf.c
${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/tcp.c
${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/tcp_in.c
${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/tcp_out.c
${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/timeouts.c
${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/udp.c
)
set (LWIP_IPV4_SRC
${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/ipv4/acd.c
${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/ipv4/dhcp.c
${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/ipv4/etharp.c
${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/ipv4/icmp.c
${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/ipv4/ip4.c
${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/ipv4/ip4_addr.c
${BTSTACK_ROOT}/3rd-party/lwip/core/src/core/ipv4/ip4_frag.c
)
set (LWIP_NETIF_SRC
${BTSTACK_ROOT}/3rd-party/lwip/core/src/netif/ethernet.c
)
set (LWIP_HTTPD
${BTSTACK_ROOT}/3rd-party/lwip/core/src/apps/http/altcp_proxyconnect.c
${BTSTACK_ROOT}/3rd-party/lwip/core/src/apps/http/fs.c
${BTSTACK_ROOT}/3rd-party/lwip/core/src/apps/http/httpd.c
)
set (LWIP_DHCPD
${BTSTACK_ROOT}/3rd-party/lwip/dhcp-server/dhserver.c
)
set (LWIP_PORT
${BTSTACK_ROOT}/platform/lwip/port/sys_arch.c
${BTSTACK_ROOT}//platform/lwip/bnep_lwip.c
)
set (SOURCES_LWIP ${LWIP_CORE_SRC} ${LWIP_IPV4_SRC} ${LWIP_NETIF_SRC} ${LWIP_HTTPD} ${LWIP_DHCPD} ${LWIP_PORT})
file(GLOB SOURCES_BLE_OFF "${BTSTACK_ROOT}/src/ble/le_device_db_memory.c")
list(REMOVE_ITEM SOURCES_BLE ${SOURCES_BLE_OFF})
file(GLOB SOURCES_POSIX_OFF "${BTSTACK_ROOT}/platform/posix/le_device_db_fs.c")
list(REMOVE_ITEM SOURCES_POSIX ${SOURCES_POSIX_OFF})
set(SOURCES
${SOURCES_BLE}
${SOURCES_BLUEDROID}
${SOURCES_CLASSIC}
${SOURCES_GATT}
${SOURCES_HXCMOD}
${SOURCES_LIBUSB}
${SOURCES_MD5}
${SOURCES_MESH}
${SOURCES_BCM}
${SOURCES_PORT}
${SOURCES_RIJNDAEL}
${SOURCES_SRC}
${SOURCES_CSR}
${SOURCES_UECC}
${SOURCES_POSIX}
${SOURCES_YXML}
)
list(SORT SOURCES)
# create static lib
add_library(btstack STATIC ${SOURCES})
# Add BCM Support
include(${BTSTACK_ROOT}/chipset/bcm/bcm.cmake)
# CYW55573
file(DOWNLOAD https://github.com/murata-wireless/meta-murata-wireless/raw/imx-kirkstone-fafnir/recipes-connectivity/murata-binaries/murata-binaries/CYW55560A1_001.002.087.0108.0000.sLNA.hcd
${CMAKE_CURRENT_BINARY_DIR}/CYW55560A1_001.002.087.0108.0000.sLNA.hcd)
# get list of examples, skipping mesh_node_demo
include(../../example/CMakeLists.txt)
set (EXAMPLES ${EXAMPLES_GENERAL} ${EXAMPLES_CLASSIC_ONLY} ${EXAMPLES_LE_ONLY} ${EXAMPLES_DUAL_MODE})
list(REMOVE_DUPLICATES EXAMPLES)
list(REMOVE_ITEM EXAMPLES "mesh_node_demo")
# create targets
foreach(EXAMPLE ${EXAMPLES})
# get c file
set (SOURCES_EXAMPLE ${BTSTACK_ROOT}/example/${EXAMPLE}.c)
# add GATT DB creation
if ( "${EXAMPLES_GATT_FILES}" MATCHES ${EXAMPLE} )
message("example ${EXAMPLE} -- with GATT DB")
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${EXAMPLE}.h
DEPENDS ${BTSTACK_ROOT}/example/${EXAMPLE}.gatt
COMMAND ${Python_EXECUTABLE}
ARGS ${BTSTACK_ROOT}/tool/compile_gatt.py ${BTSTACK_ROOT}/example/${EXAMPLE}.gatt ${CMAKE_CURRENT_BINARY_DIR}/${EXAMPLE}.h
)
list(APPEND SOURCES_EXAMPLE ${CMAKE_CURRENT_BINARY_DIR}/${EXAMPLE}.h)
else()
message("example ${EXAMPLE}")
endif()
add_executable(${EXAMPLE} ${SOURCES_EXAMPLE})
target_link_libraries(${EXAMPLE} btstack)
endforeach(EXAMPLE)

View File

@ -0,0 +1,36 @@
# BTstack Port for POSIX Systems with modern Infineon (CYW) H4 Bluetooth Controller
## Configuration
Newer Infineon Airoc (tm) Controllers like the CYW5557x series accept PatchRAM upload only in a so-called
'auto-baud mode' which is entered by asserting CTS (low) and starting/resetting the controller via BT_REG_EN.
This port currently only supports the CYW5557x Controllers and slowly uploads the firmware at 115200.
## Compilation
BTstack's posix-h4-bcm port does not have additional dependencies. You can directly run cmake and then your default
build system. E.g. with Ninja:
mkdir build
cd build
cmake -G Ninja ..
ninja
## Running the examples
On start, BTstack opens the serial port, which asserts CTS, and requests you to reset the Controller with a countdown.
$ ./gatt_counter
Packet Log: /tmp/hci_dump.pklg
Phase 1: Download firmware
Please reset Bluetooth Controller, e.g. via RESET button. Firmware download starts in:
3
2
1
Firmware download started
Phase 2: Main app
...
BTstack up and running at 55:56:0A:0A:76:93
## ToDo
- increase baud rate for firmware upload
- query controller to select correct PatchRAM file

View File

@ -0,0 +1,63 @@
//
// btstack_config.h for generic POSIX H4 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_EM9304_PATCH_CONTAINER
#define HAVE_MALLOC
#define HAVE_POSIX_FILE_IO
#define HAVE_POSIX_TIME
// BTstack features that can be enabled
#define ENABLE_ATT_DELAYED_RESPONSE
#define ENABLE_BLE
#define ENABLE_CLASSIC
#define ENABLE_CROSS_TRANSPORT_KEY_DERIVATION
#define ENABLE_HFP_WIDE_BAND_SPEECH
#define ENABLE_L2CAP_ENHANCED_RETRANSMISSION_MODE
#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
#define ENABLE_SCO_OVER_HCI
#define ENABLE_SDP_DES_DUMP
#define ENABLE_SOFTWARE_AES128
// 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 16
#define NVM_NUM_LINK_KEYS 16
// 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

225
port/posix-h4-bcm/main.c Normal file
View File

@ -0,0 +1,225 @@
/*
* 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 "bluetooth_company_id.h"
#include "ble/le_device_db_tlv.h"
#include "btstack_chipset_bcm.h"
#include "btstack_chipset_bcm_download_firmware.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_stdin.h"
#include "btstack_uart.h"
#include "btstack_tlv_posix.h"
#include "classic/btstack_link_key_db_tlv.h"
#include "hci.h"
#include "hci_dump.h"
#include "hci_transport_h4.h"
#include "hci_dump_posix_fs.h"
#include "hci_dump_posix_stdout.h"
int btstack_main(int argc, const char * argv[]);
#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 hci_transport_config_uart_t transport_config = {
HCI_TRANSPORT_CONFIG_UART,
115200,
921600, // main baudrate
1, // flow control
NULL,
BTSTACK_UART_PARITY_OFF, // parity
};
static btstack_uart_config_t uart_config;
static int main_argc;
static const char ** main_argv;
static btstack_packet_callback_registration_t hci_event_callback_registration;
static void sigint_handler(int param){
UNUSED(param);
printf("CTRL-C - SIGINT received, shutting down..\n");
log_info("sigint_handler: shutting down");
// reset anyway
btstack_stdin_reset();
// power down
hci_power_control(HCI_POWER_OFF);
hci_close();
log_info("Good bye, see you.\n");
exit(0);
}
static int led_state = 0;
void hal_led_toggle(void){
led_state = 1 - led_state;
printf("LED State %u\n", led_state);
}
static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
bd_addr_t addr;
if (packet_type != HCI_EVENT_PACKET) return;
switch (hci_event_packet_get_type(packet)){
case BTSTACK_EVENT_STATE:
if (btstack_event_state_get_state(packet) != HCI_STATE_WORKING) break;
gap_local_bd_addr(addr);
printf("BTstack up and running at %s\n", bd_addr_to_str(addr));
// setup TLV
btstack_strcpy(tlv_db_path, sizeof(tlv_db_path), TLV_DB_PATH_PREFIX);
btstack_strcat(tlv_db_path, sizeof(tlv_db_path), bd_addr_to_str(addr));
btstack_strcat(tlv_db_path, sizeof(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);
#ifdef ENABLE_CLASSIC
hci_set_link_key_db(btstack_link_key_db_tlv_get_instance(tlv_impl, &tlv_context));
#endif
#ifdef ENABLE_BLE
le_device_db_tlv_configure(tlv_impl, &tlv_context);
#endif
break;
default:
break;
}
}
static void phase2(int status);
int main(int argc, const char * argv[]){
/// GET STARTED with BTstack ///
btstack_memory_init();
#if 1
// 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();
printf("Packet Log: %s\n", pklg_path);
#else
// log to stdout for debugging/development
const hci_dump_t * hci_dump_impl = hci_dump_posix_stdout_get_instance();
#endif
hci_dump_init(hci_dump_impl);
// setup run loop
btstack_run_loop_init(btstack_run_loop_posix_get_instance());
// pick serial port and configure uart driver
transport_config.device_name = "/dev/tty.usbserial-FT1XBGIM"; // murata m.2 adapter
// get BCM chipset driver
const btstack_chipset_t * chipset = btstack_chipset_bcm_instance();
chipset->init(&transport_config);
// set chipset name
btstack_chipset_bcm_set_device_name("CYW55560A1");
// setup UART driver
const btstack_uart_t * uart_driver = (const btstack_uart_t *) btstack_uart_posix_instance();
// extract UART config from transport config
uart_config.baudrate = transport_config.baudrate_init;
uart_config.flowcontrol = transport_config.flowcontrol;
uart_config.device_name = transport_config.device_name;
uart_driver->init(&uart_config);
// setup HCI (to be able to use bcm chipset driver)
// init HCI
const hci_transport_t * transport = hci_transport_h4_instance(uart_driver);
hci_init(transport, (void*) &transport_config);
hci_set_chipset(btstack_chipset_bcm_instance());
// inform about BTstack state
hci_event_callback_registration.callback = &packet_handler;
hci_add_event_handler(&hci_event_callback_registration);
// handle CTRL-c
signal(SIGINT, sigint_handler);
main_argc = argc;
main_argv = argv;
// phase #1 download firmware
printf("Phase 1: Download firmware\n");
// phase #2 start main app
btstack_chipset_bcm_download_firmware_with_uart(uart_driver, 0, &phase2);
// go
btstack_run_loop_execute();
return 0;
}
static void phase2(int status){
if (status){
printf("Download firmware failed\n");
return;
}
printf("Phase 2: Main app\n");
// setup app
btstack_main(main_argc, main_argv);
}