Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Bluetooth Mesh build support #1692

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 43 additions & 2 deletions src/rp2_common/pico_btstack/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ if (EXISTS ${PICO_BTSTACK_PATH}/${BTSTACK_TEST_PATH})
${PICO_BTSTACK_PATH}/src/hci_event.c
${PICO_BTSTACK_PATH}/src/l2cap.c
${PICO_BTSTACK_PATH}/src/l2cap_signaling.c
${PICO_BTSTACK_PATH}/src/mesh/gatt-service/mesh_provisioning_service_server.c
${PICO_BTSTACK_PATH}/src/mesh/gatt-service/mesh_proxy_service_server.c
${PICO_BTSTACK_PATH}/3rd-party/md5/md5.c
${PICO_BTSTACK_PATH}/3rd-party/yxml/yxml.c
${CMAKE_CURRENT_LIST_DIR}/btstack_stdin_pico.c
Expand Down Expand Up @@ -154,6 +152,49 @@ if (EXISTS ${PICO_BTSTACK_PATH}/${BTSTACK_TEST_PATH})
ENABLE_CLASSIC=1
)

pico_add_library(pico_btstack_mesh)
target_sources(pico_btstack_mesh INTERFACE
${PICO_BTSTACK_PATH}/src/mesh/mesh.c
${PICO_BTSTACK_PATH}/src/mesh/adv_bearer.c
${PICO_BTSTACK_PATH}/src/mesh/beacon.c
${PICO_BTSTACK_PATH}/src/mesh/gatt_bearer.c
${PICO_BTSTACK_PATH}/src/mesh/gatt-service/mesh_provisioning_service_server.c
${PICO_BTSTACK_PATH}/src/mesh/gatt-service/mesh_proxy_service_server.c
${PICO_BTSTACK_PATH}/src/mesh/mesh.c
${PICO_BTSTACK_PATH}/src/mesh/mesh_access.c
${PICO_BTSTACK_PATH}/src/mesh/mesh_configuration_client.c
${PICO_BTSTACK_PATH}/src/mesh/mesh_configuration_server.c
${PICO_BTSTACK_PATH}/src/mesh/mesh_crypto.c
${PICO_BTSTACK_PATH}/src/mesh/mesh_foundation.c
${PICO_BTSTACK_PATH}/src/mesh/mesh_generic_default_transition_time_client.c
${PICO_BTSTACK_PATH}/src/mesh/mesh_generic_default_transition_time_server.c
${PICO_BTSTACK_PATH}/src/mesh/mesh_generic_level_client.c
${PICO_BTSTACK_PATH}/src/mesh/mesh_generic_level_server.c
${PICO_BTSTACK_PATH}/src/mesh/mesh_generic_on_off_client.c
${PICO_BTSTACK_PATH}/src/mesh/mesh_generic_on_off_server.c
${PICO_BTSTACK_PATH}/src/mesh/mesh_health_server.c
${PICO_BTSTACK_PATH}/src/mesh/mesh_iv_index_seq_number.c
${PICO_BTSTACK_PATH}/src/mesh/mesh_keys.c
${PICO_BTSTACK_PATH}/src/mesh/mesh_lower_transport.c
${PICO_BTSTACK_PATH}/src/mesh/mesh_network.c
${PICO_BTSTACK_PATH}/src/mesh/mesh_node.c
${PICO_BTSTACK_PATH}/src/mesh/mesh_peer.c
${PICO_BTSTACK_PATH}/src/mesh/mesh_proxy.c
${PICO_BTSTACK_PATH}/src/mesh/mesh_upper_transport.c
${PICO_BTSTACK_PATH}/src/mesh/mesh_virtual_addresses.c
${PICO_BTSTACK_PATH}/src/mesh/pb_adv.c
${PICO_BTSTACK_PATH}/src/mesh/pb_gatt.c
${PICO_BTSTACK_PATH}/src/mesh/provisioning.c
${PICO_BTSTACK_PATH}/src/mesh/provisioning_device.c
${PICO_BTSTACK_PATH}/src/mesh/provisioning_provisioner.c
)
pico_mirrored_target_link_libraries(pico_btstack_mesh INTERFACE
pico_btstack_ble
)
target_compile_definitions(pico_btstack_mesh_headers INTERFACE
ENABLE_MESH=1
)

pico_add_library(pico_btstack_flash_bank)
target_sources(pico_btstack_flash_bank INTERFACE
${CMAKE_CURRENT_LIST_DIR}/btstack_flash_bank.c
Expand Down
42 changes: 42 additions & 0 deletions test/pico_btstack_mesh_test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
cmake_minimum_required(VERSION 3.5)

include(pico_sdk_import.cmake)
project(mesh_node_demo C CXX ASM)

set(PICO_BOARD pico_w)
set(CMAKE_C STANDARD 11)
set(CMAKE_CXX_STANDARD 17)

pico_sdk_init()

add_compile_options(
-Wall
-Wno-format # int != int32_t as far as the compiler is concerned because gcc has int32_t as long int
-Wno-unused-function # we have some for the docs that aren't called
-Wno-maybe-uninitialized
-O3
-g
)

add_executable(mesh_node_demo mesh_node_demo.c)

pico_enable_stdio_usb(mesh_node_demo 1) # Enable USB output
pico_enable_stdio_uart(mesh_node_demo 0) # Disable UART output
pico_add_extra_outputs(mesh_node_demo) # Generate map/bin/hex/uf2

target_include_directories(mesh_node_demo
PRIVATE ${CMAKE_CURRENT_LIST_DIR}
)

target_link_libraries(mesh_node_demo
hardware_adc
pico_btstack_cyw43
pico_btstack_mesh
pico_cyw43_arch_lwip_threadsafe_background
pico_stdlib
)

target_link_options(mesh_node_demo
PRIVATE "LINKER:--print-memory-usage"
PRIVATE "LINKER:--verbose"
)
52 changes: 52 additions & 0 deletions test/pico_btstack_mesh_test/btstack_config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
//
// btstack_config.h for Raspberry Pi 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 // Already defined in pico_btstack_ble
#define ENABLE_LE_CENTRAL
#define ENABLE_LE_DATA_LENGTH_EXTENSION
#define ENABLE_LE_PERIPHERAL
#define ENABLE_LE_SECURE_CONNECTIONS
#define ENABLE_LOG_ERROR
#define ENABLE_LOG_INFO
#define ENABLE_PRINTF_HEXDUMP

// Mesh Configuration
//#define ENABLE_MESH // Already defined in pico_btstack_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

// BTstack configuration. buffers, sizes, ...
#define HCI_ACL_CHUNK_SIZE_ALIGNMENT 4
#define HCI_ACL_PAYLOAD_SIZE (1691 + 4)
#define HCI_INCOMING_PRE_BUFFER_SIZE 14 // sizeof BNEP header, avoid memcpy
#define HCI_OUTGOING_PRE_BUFFER_SIZE 4

#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)

#define NVM_NUM_DEVICE_DB_ENTRIES 16
#define NVM_NUM_LINK_KEYS 16

#endif
21 changes: 21 additions & 0 deletions test/pico_btstack_mesh_test/lwipopts.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#ifndef _LWIPOPTS_H
#define _LWIPOPTS_H

// Generally you would define your own explicit list of lwIP options
// (see https://www.nongnu.org/lwip/2_1_x/group__lwip__opts.html)
//
// This example uses a common include to avoid repetition
#include "lwipopts_examples_common.h"

#if !NO_SYS
#define TCPIP_THREAD_STACKSIZE 1024
#define DEFAULT_THREAD_STACKSIZE 1024
#define DEFAULT_RAW_RECVMBOX_SIZE 8
#define TCPIP_MBOX_SIZE 8
#define LWIP_TIMEVAL_PRIVATE 0

// not necessary, can be done either way
#define LWIP_TCPIP_CORE_LOCKING_INPUT 1
#endif

#endif
90 changes: 90 additions & 0 deletions test/pico_btstack_mesh_test/lwipopts_examples_common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#ifndef _LWIPOPTS_EXAMPLE_COMMONH_H
#define _LWIPOPTS_EXAMPLE_COMMONH_H


// Common settings used in most of the pico_w examples
// (see https://www.nongnu.org/lwip/2_1_x/group__lwip__opts.html for details)

// allow override in some examples
#ifndef NO_SYS
#define NO_SYS 1
#endif
// allow override in some examples
#ifndef LWIP_SOCKET
#define LWIP_SOCKET 0
#endif
#if PICO_CYW43_ARCH_POLL
#define MEM_LIBC_MALLOC 1
#else
// MEM_LIBC_MALLOC is incompatible with non polling versions
#define MEM_LIBC_MALLOC 0
#endif
#define MEM_ALIGNMENT 4
#define MEM_SIZE 4000
#define MEMP_NUM_TCP_SEG 32
#define MEMP_NUM_ARP_QUEUE 10
#define PBUF_POOL_SIZE 24
#define LWIP_ARP 1
#define LWIP_ETHERNET 1
#define LWIP_ICMP 1
#define LWIP_RAW 1
#define TCP_WND (8 * TCP_MSS)
#define TCP_MSS 1460
#define TCP_SND_BUF (8 * TCP_MSS)
#define TCP_SND_QUEUELEN ((4 * (TCP_SND_BUF) + (TCP_MSS - 1)) / (TCP_MSS))
#define LWIP_NETIF_STATUS_CALLBACK 1
#define LWIP_NETIF_LINK_CALLBACK 1
#define LWIP_NETIF_HOSTNAME 1
#define LWIP_NETCONN 0
#define MEM_STATS 0
#define SYS_STATS 0
#define MEMP_STATS 0
#define LINK_STATS 0
// #define ETH_PAD_SIZE 2
#define LWIP_CHKSUM_ALGORITHM 3
#define LWIP_DHCP 1
#define LWIP_IPV4 1
#define LWIP_TCP 1
#define LWIP_UDP 1
#define LWIP_DNS 1
#define LWIP_TCP_KEEPALIVE 1
#define LWIP_NETIF_TX_SINGLE_PBUF 1
#define DHCP_DOES_ARP_CHECK 0
#define LWIP_DHCP_DOES_ACD_CHECK 0

#ifndef NDEBUG
#define LWIP_DEBUG 1
#define LWIP_STATS 1
#define LWIP_STATS_DISPLAY 1
#endif

#define ETHARP_DEBUG LWIP_DBG_OFF
#define NETIF_DEBUG LWIP_DBG_OFF
#define PBUF_DEBUG LWIP_DBG_OFF
#define API_LIB_DEBUG LWIP_DBG_OFF
#define API_MSG_DEBUG LWIP_DBG_OFF
#define SOCKETS_DEBUG LWIP_DBG_OFF
#define ICMP_DEBUG LWIP_DBG_OFF
#define INET_DEBUG LWIP_DBG_OFF
#define IP_DEBUG LWIP_DBG_OFF
#define IP_REASS_DEBUG LWIP_DBG_OFF
#define RAW_DEBUG LWIP_DBG_OFF
#define MEM_DEBUG LWIP_DBG_OFF
#define MEMP_DEBUG LWIP_DBG_OFF
#define SYS_DEBUG LWIP_DBG_OFF
#define TCP_DEBUG LWIP_DBG_OFF
#define TCP_INPUT_DEBUG LWIP_DBG_OFF
#define TCP_OUTPUT_DEBUG LWIP_DBG_OFF
#define TCP_RTO_DEBUG LWIP_DBG_OFF
#define TCP_CWND_DEBUG LWIP_DBG_OFF
#define TCP_WND_DEBUG LWIP_DBG_OFF
#define TCP_FR_DEBUG LWIP_DBG_OFF
#define TCP_QLEN_DEBUG LWIP_DBG_OFF
#define TCP_RST_DEBUG LWIP_DBG_OFF
#define UDP_DEBUG LWIP_DBG_OFF
#define TCPIP_DEBUG LWIP_DBG_OFF
#define PPP_DEBUG LWIP_DBG_OFF
#define SLIP_DEBUG LWIP_DBG_OFF
#define DHCP_DEBUG LWIP_DBG_OFF

#endif /* __LWIPOPTS_H__ */
Loading