ports: STM32-F103RB Nucleo + CC256x port removed

This commit is contained in:
Matthias Ringwald 2021-01-14 23:51:10 +01:00
parent 63aba030ad
commit 4f75656a02
12 changed files with 1 additions and 1068 deletions

View File

@ -28,6 +28,7 @@ A2DP Source: emit codec configure event with reconfigure flag set on reconfigure
HFP/GOEP Client/AVDTP/A2DP: return `SDP_SERVICE_NOT_FOUND` if no suitable SDP record is found
GATT Client: Skip MTU exchange after MTU exchange on ATT Server
AVDTP Source: `avdtp_source_stream_send_media_payload` includes SBC Header and was deprecated
Ports: STM32-F103RB Nucleo + CC256x port removed
## Release v1.2.1

View File

@ -1,2 +0,0 @@
libopencm3/
spp_and_le_counter.h

View File

@ -1,89 +0,0 @@
#
# Makefile for STM32-F103RB Nucleo board with CC256x Bluetooth modules
#
# BINARY=led_counter
BINARY=spp_and_gatt_counter
OPENCM3_DIR = libopencm3
LDSCRIPT = stm32f1-nucleo.ld
BTSTACK_ROOT ?= ../..
VPATH = $(BTSTACK_ROOT)/example
VPATH += $(BTSTACK_ROOT)/src
VPATH += $(BTSTACK_ROOT)/src/ble
VPATH += $(BTSTACK_ROOT)/src/classic
VPATH += $(BTSTACK_ROOT)/platform/embedded
VPATH += $(BTSTACK_ROOT)/chipset/cc256x
CORE = \
main.c \
btstack_linked_list.c \
btstack_memory.c \
btstack_memory_pool.c \
btstack_run_loop.c \
btstack_run_loop_embedded.c \
COMMON = \
ad_parser.c \
bluetooth_init_cc2564B_1.8_BT_Spec_4.1.c \
btstack_chipset_cc256x.c \
btstack_link_key_db_memory.c \
rfcomm.c \
sdp_client_rfcomm.c \
btstack_util.c \
btstack_crypto.c \
btstack_tlv.c \
hci.c \
hci_cmd.c \
hci_dump.c \
btstack_uart_block_embedded.c \
hci_transport_h4.c \
l2cap.c \
l2cap_signaling.c \
sdp_client.c \
sdp_server.c \
sdp_util.c \
spp_server.c \
BLE = \
att_db.c \
att_dispatch.c \
att_server.c \
le_device_db_memory.c \
sm.c \
# gatt_client.c \
CORE_OBJ = $(CORE:.c=.o)
COMMON_OBJ = $(COMMON:.c=.o)
BLE_OBJ = $(BLE:.c=.o)
OBJS += $(CORE_OBJ) $(COMMON_OBJ) $(BLE_OBJ)
CFLAGS = -I. \
-I$(BTSTACK_ROOT)/platform/embedded \
-I$(BTSTACK_ROOT)/src \
-I$(BTSTACK_ROOT)/chipset/cc256x
examples: libopencm3/lib/libopencm3_stm32f1.a spp_and_gatt_counter.h spp_and_gatt_counter.elf
include libopencm3.stm32f1.mk
# fetch and convert init scripts
include ${BTSTACK_ROOT}/chipset/cc256x/Makefile.inc
clean:
rm -f *.map *.o *.d *.out *.elf *.bin *.hex
distclean: clean
make -C libopencm3 clean
# git clone and compile libopencm3
libopencm3/lib/libopencm3_stm32f1.a:
rm -rf libopencm3
git clone https://github.com/libopencm3/libopencm3.git
make -C libopencm3
# compile GATT database
spp_and_gatt_counter.h: spp_and_gatt_counter.gatt
python3 ${BTSTACK_ROOT}/tool/compile_gatt.py $< $@

View File

@ -1,54 +0,0 @@
# STM32 F103RB Nucleo with CC256x
BTstack port for STM32 F103RB Nucleo board and CC256x Bluetooth chipset
based on GNU Tools for ARM Embedded Processors and libopencm3
Requirements:
- GNU Tools for ARM Embedded Processors: https://launchpad.net/gcc-arm-embedded
- libopencm3 is automatically fetched and build from its git repository by make
- openocd 0.8.0 (or higher) is used to upload firmware
Components:
- STM32 F103RB Nucleo Board
- User's Manual: http://www.st.com/web/en/resource/technical/document/user_manual/DM00105823.pdf
- CC2564B Bluetooth Controller:
1. The best option is to get it as a BoostPack
- Info: BOOST-CC2564MODA: http://www.ti.com/tool/BOOST-CC2564MODA
2. Alternatively, get the evaluation module together with the EM Wireless Booster pack and a 32.768 kHz oscillator
- EM Wireless Booster Pack:
- Info: http://www.ti.com/tool/boost-ccemadapter
- User Guide: http://www.ti.com/lit/ug/swru338a/swru338a.pdf
- Booster Pack Pinout: http://www.ti.com/ww/en/launchpad/dl/boosterpack-pinout-v2.pdf
- CC256x Evaluation Module:
- Info: http://www.ti.com/tool/cc256xqfnem
Configuration:
- Sys tick 250 ms
- LED on PA5, on when MCU in Run mode and off while in Sleep mode
- Debug UART: USART2 - 9600/8/N/1, TX on PA2
- Bluetooth: USART3 with hardware flowcontrol RTS. IRQ on CTS Rising. TX PB10, RX PB11, CTS PB13 (in), RTS PB14 (out), N_SHUTDOWN PB15
Setup with CC2564 BoosterPack (BOOST-CC2564MODA):
- Connect STM32 Nucleo Board to EM Wireless Board (see BoosterPack pinout)
- GND: CN10-9 - 20 (J2)
- VCC: CN7 -16 - 1 (J1)
- RX3: CN10-18 - 3 (J1)
- TX3: CN10-25 - 4 (J1)
- CTS3: CN10-30 - 36 (J4)
- RTS3: CN10-28 - 37 (J4)
- N_SHUTDOWN: CN10-26 - 19 (J2)
Setup with EM Wireless BoosterPack + CC256x Evaluation Module:
- Solder 32.768 kHz quarz oscillator to EM Adapter Booster Pack as explained in 4.7 of the EM Wireless Booster Pack User Guide. If you don't have an oscillator of that size, you might solder one upside done (turtle-on-back style) to the unused upper right pad and wire GCC, VCC, and clock with thin wires.
- Connect STM32 Nucleo Board to EM Wireless Board (see BoosterPack pinout)
- GND: CN10-9 - 20 (LP2)
- VCC: CN7 -16 - 1 (LP1)
- RX3: CN10-18 - 3 (LP1)
- TX3: CN10-25 - 4 (LP1)
- CTS3: CN10-30 - 11 (LP2)
- RTS3: CN10-28 - 12 (LP2)
- N_SHUTDOWN: CN10-26 - 10 (LP1)
TODO:
- figure out how to compile multiple examples with single Makefile/folder

View File

@ -1,38 +0,0 @@
//
// btstack_config.h for STM32F103RB Nucleo + TI CC256B port
//
#ifndef BTSTACK_CONFIG_H
#define BTSTACK_CONFIG_H
// Port related features
#define HAVE_EMBEDDED_TICK
// BTstack features that can be enabled
#define ENABLE_BLE
#define ENABLE_CLASSIC
#define ENABLE_LE_CENTRAL
#define ENABLE_LE_PERIPHERAL
#define ENABLE_PRINTF_HEXDUMP
#define ENABLE_SCO_OVER_HCI
// BTstack configuration. buffers, sizes, ...
#define HCI_ACL_PAYLOAD_SIZE 52
#define MAX_NR_BNEP_CHANNELS 0
#define MAX_NR_BNEP_SERVICES 0
#define MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES 2
#define MAX_NR_GATT_CLIENTS 1
#define MAX_NR_HCI_CONNECTIONS MAX_SPP_CONNECTIONS
#define MAX_NR_HFP_CONNECTIONS 0
#define MAX_NR_L2CAP_CHANNELS (1+MAX_SPP_CONNECTIONS)
#define MAX_NR_L2CAP_SERVICES 2
#define MAX_NR_LE_DEVICE_DB_ENTRIES 1
#define MAX_NR_RFCOMM_CHANNELS MAX_SPP_CONNECTIONS
#define MAX_NR_RFCOMM_MULTIPLEXERS MAX_SPP_CONNECTIONS
#define MAX_NR_RFCOMM_SERVICES 1
#define MAX_NR_SERVICE_RECORD_ITEMS 4
#define MAX_NR_SM_LOOKUP_ENTRIES 3
#define MAX_NR_WHITELIST_ENTRIES 1
#define MAX_SPP_CONNECTIONS 1
#endif

View File

@ -1,239 +0,0 @@
##
## This file is part of the libopencm3 project.
##
## Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
## Copyright (C) 2010 Piotr Esden-Tempski <piotr@esden.net>
## Copyright (C) 2013 Frantisek Burian <BuFran@seznam.cz>
##
## This library is free software: you can redistribute it and/or modify
## it under the terms of the GNU Lesser General Public License as published by
## the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
##
## This library is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU Lesser General Public License for more details.
##
## You should have received a copy of the GNU Lesser General Public License
## along with this library. If not, see <http://www.gnu.org/licenses/>.
##
# Be silent per default, but 'make V=1' will show all compiler calls.
ifneq ($(V),1)
Q := @
NULL := 2>/dev/null
endif
###############################################################################
# Executables
PREFIX ?= arm-none-eabi
CC := $(PREFIX)-gcc
CXX := $(PREFIX)-g++
LD := $(PREFIX)-gcc
AR := $(PREFIX)-ar
AS := $(PREFIX)-as
OBJCOPY := $(PREFIX)-objcopy
OBJDUMP := $(PREFIX)-objdump
GDB := $(PREFIX)-gdb
STFLASH = $(shell which st-flash)
STYLECHECK := /checkpatch.pl
STYLECHECKFLAGS := --no-tree -f --terse --mailback
STYLECHECKFILES := $(shell find . -name '*.[ch]')
###############################################################################
# Source files
# LDSCRIPT ?= $(BINARY).ld
# OBJS += $(BINARY).o
ifeq ($(strip $(OPENCM3_DIR)),)
# user has not specified the library path, so we try to detect it
# where we search for the library
LIBPATHS := ./libopencm3 ../../../../libopencm3 ../../../../../libopencm3
OPENCM3_DIR := $(wildcard $(LIBPATHS:=/locm3.sublime-project))
OPENCM3_DIR := $(firstword $(dir $(OPENCM3_DIR)))
ifeq ($(strip $(OPENCM3_DIR)),)
$(warning Cannot find libopencm3 library in the standard search paths.)
$(error Please specify it through OPENCM3_DIR variable!)
endif
endif
ifeq ($(V),1)
$(info Using $(OPENCM3_DIR) path to library)
endif
INCLUDE_DIR = $(OPENCM3_DIR)/include
LIB_DIR = $(OPENCM3_DIR)/lib
SCRIPT_DIR = $(OPENCM3_DIR)/scripts
###############################################################################
# C flags
CFLAGS += -Os -g
# CFLAGS += -Wextra -Wshadow -Wimplicit-function-declaration
# CFLAGS += -Wredundant-decls -Wmissing-prototypes -Wstrict-prototypes
# CFLAGS += -fno-common -ffunction-sections -fdata-sections
###############################################################################
# C++ flags
CXXFLAGS += -Os -g
CXXFLAGS += -Wextra -Wshadow -Wredundant-decls -Weffc++
CXXFLAGS += -fno-common -ffunction-sections -fdata-sections
###############################################################################
# C & C++ preprocessor common flags
CPPFLAGS += -MD
CPPFLAGS += -Wall -Wundef
CPPFLAGS += -I$(INCLUDE_DIR) $(DEFS)
###############################################################################
# Linker flags
LDFLAGS += --static -nostartfiles
LDFLAGS += -L$(LIB_DIR)
LDFLAGS += -T$(LDSCRIPT)
LDFLAGS += -Wl,-Map=$(*).map
LDFLAGS += -Wl,--gc-sections
ifeq ($(V),1)
LDFLAGS += -Wl,--print-gc-sections
endif
###############################################################################
# Used libraries
LDLIBS += -l$(LIBNAME)
LDLIBS += -Wl,--start-group -lc -lgcc -lnosys -Wl,--end-group
###############################################################################
###############################################################################
###############################################################################
.SUFFIXES: .elf .bin .hex .srec .list .map .images
.SECONDEXPANSION:
.SECONDARY:
# all: elf
#
# elf: $(BINARY).elf
# bin: $(BINARY).bin
# hex: $(BINARY).hex
# srec: $(BINARY).srec
# list: $(BINARY).list
# images: $(BINARY).images
# flash: $(BINARY).flash
%.images: %.bin %.hex %.srec %.list %.map
@#printf "*** $* images generated ***\n"
%.bin: %.elf
@#printf " OBJCOPY $(*).bin\n"
$(Q)$(OBJCOPY) -Obinary $(*).elf $(*).bin
%.hex: %.elf
@#printf " OBJCOPY $(*).hex\n"
$(Q)$(OBJCOPY) -Oihex $(*).elf $(*).hex
%.srec: %.elf
@#printf " OBJCOPY $(*).srec\n"
$(Q)$(OBJCOPY) -Osrec $(*).elf $(*).srec
%.list: %.elf
@#printf " OBJDUMP $(*).list\n"
$(Q)$(OBJDUMP) -S $(*).elf > $(*).list
%.elf %.map: $(OBJS) %.o $(LDSCRIPT) $(LIB_DIR)/lib$(LIBNAME).a
@#printf " LD $(*).elf\n"
$(Q)$(LD) $(LDFLAGS) $(ARCH_FLAGS) $(OBJS) $(*).o $(LDLIBS) -o $(*).elf
%.o: %.c
@#printf " CC $(*).c\n"
$(Q)$(CC) $(CFLAGS) $(CPPFLAGS) $(ARCH_FLAGS) -o $(*).o -c $<
%.o: %.cxx
@#printf " CXX $(*).cxx\n"
$(Q)$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(ARCH_FLAGS) -o $(*).o -c $<
%.o: %.cpp
@#printf " CXX $(*).cpp\n"
$(Q)$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(ARCH_FLAGS) -o $(*).o -c $<
clean:
@#printf " CLEAN\n"
$(Q)$(RM) *.o *.d *.elf *.bin *.hex *.srec *.list *.map
stylecheck: $(STYLECHECKFILES:=.stylecheck)
styleclean: $(STYLECHECKFILES:=.styleclean)
# the cat is due to multithreaded nature - we like to have consistent chunks of text on the output
%.stylecheck: %
$(Q)$(SCRIPT_DIR)$(STYLECHECK) $(STYLECHECKFLAGS) $* > $*.stylecheck; \
if [ -s $*.stylecheck ]; then \
cat $*.stylecheck; \
else \
rm -f $*.stylecheck; \
fi;
%.styleclean:
$(Q)rm -f $*.stylecheck;
%.stlink-flash: %.bin
@printf " FLASH $<\n"
$(Q)$(STFLASH) write $(*).bin 0x8000000
ifeq ($(STLINK_PORT),)
ifeq ($(BMP_PORT),)
ifeq ($(OOCD_SERIAL),)
%.flash: %.hex
@printf " FLASH $<\n"
@# IMPORTANT: Don't use "resume", only "reset" will work correctly!
$(Q)$(OOCD) \
-f board/$(OOCD_BOARD).cfg \
-c "init" -c "reset init" \
-c "flash write_image erase $(*).hex" \
-c "reset" \
-c "shutdown" $(NULL)
else
%.flash: %.hex
@printf " FLASH $<\n"
@# IMPORTANT: Don't use "resume", only "reset" will work correctly!
$(Q)$(OOCD) \
-f board/$(OOCD_BOARD).cfg \
-c "ft2232_serial $(OOCD_SERIAL)" \
-c "init" -c "reset init" \
-c "flash write_image erase $(*).hex" \
-c "reset" \
-c "shutdown" $(NULL)
endif
else
%.flash: %.elf
@printf " GDB $(*).elf (flash)\n"
$(Q)$(GDB) --batch \
-ex 'target extended-remote $(BMP_PORT)' \
-x $(SCRIPT_DIR)/black_magic_probe_flash.scr \
$(*).elf
endif
else
%.flash: %.elf
@printf " GDB $(*).elf (flash)\n"
$(Q)$(GDB) --batch \
-ex 'target extended-remote $(STLINK_PORT)' \
-x $(SCRIPT_DIR)/stlink_flash.scr \
$(*).elf
endif
.PHONY: images clean stylecheck styleclean elf bin hex srec list
-include $(OBJS:.o=.d)

View File

@ -1,43 +0,0 @@
##
## This file is part of the libopencm3 project.
##
## Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
## Copyright (C) 2010 Piotr Esden-Tempski <piotr@esden.net>
##
## This library is free software: you can redistribute it and/or modify
## it under the terms of the GNU Lesser General Public License as published by
## the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
##
## This library is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU Lesser General Public License for more details.
##
## You should have received a copy of the GNU Lesser General Public License
## along with this library. If not, see <http://www.gnu.org/licenses/>.
##
LIBNAME = opencm3_stm32f1
DEFS = -DSTM32F1
FP_FLAGS ?= -msoft-float
ARCH_FLAGS = -mthumb -mcpu=cortex-m3 $(FP_FLAGS) -mfix-cortex-m3-ldrd
################################################################################
# OpenOCD specific variables
OOCD ?= openocd
OOCD_BOARD ?= st_nucleo_f103rb
################################################################################
# Black Magic Probe specific variables
# Set the BMP_PORT to a serial port and then BMP is used for flashing
BMP_PORT ?=
################################################################################
# texane/stlink specific variables
#STLINK_PORT ?= :4242
include libopencm3.rules.mk

View File

@ -1,106 +0,0 @@
/*
* This file is part of the libopencm3 project.
*
* Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
/* Generic linker script for STM32 targets using libopencm3. */
/* Memory regions must be defined in the ld script which includes this one. */
/* Enforce emmition of the vector table. */
EXTERN (vector_table)
/* Define the entry point of the output file. */
ENTRY(reset_handler)
/* Define sections. */
SECTIONS
{
.text : {
*(.vectors) /* Vector table */
*(.text*) /* Program code */
. = ALIGN(4);
*(.rodata*) /* Read-only data */
. = ALIGN(4);
} >rom
/* C++ Static constructors/destructors, also used for __attribute__
* ((constructor)) and the likes */
.preinit_array : {
. = ALIGN(4);
__preinit_array_start = .;
KEEP (*(.preinit_array))
__preinit_array_end = .;
} >rom
.init_array : {
. = ALIGN(4);
__init_array_start = .;
KEEP (*(SORT(.init_array.*)))
KEEP (*(.init_array))
__init_array_end = .;
} >rom
.fini_array : {
. = ALIGN(4);
__fini_array_start = .;
KEEP (*(.fini_array))
KEEP (*(SORT(.fini_array.*)))
__fini_array_end = .;
} >rom
/*
* Another section used by C++ stuff, appears when using newlib with
* 64bit (long long) printf support
*/
.ARM.extab : {
*(.ARM.extab*)
} >rom
.ARM.exidx : {
__exidx_start = .;
*(.ARM.exidx*)
__exidx_end = .;
} >rom
. = ALIGN(4);
_etext = .;
.data : {
_data = .;
*(.data*) /* Read-write initialized data */
. = ALIGN(4);
_edata = .;
} >ram AT >rom
_data_loadaddr = LOADADDR(.data);
.bss : {
*(.bss*) /* Read-write zero initialized data */
*(COMMON)
. = ALIGN(4);
_ebss = .;
} >ram
/*
* The .eh_frame section appears to be used for C++ exception handling.
* You may need to fix this if you're using C++.
*/
/DISCARD/ : { *(.eh_frame) }
. = ALIGN(4);
end = .;
}
PROVIDE(_stack = ORIGIN(ram) + LENGTH(ram));

View File

@ -1,478 +0,0 @@
/*
* 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 MATTHIAS
* RINGWALD 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"
#include <libopencm3/cm3/nvic.h>
#include <libopencm3/cm3/systick.h>
#include <libopencm3/stm32/dma.h>
#include <libopencm3/stm32/gpio.h>
#include <libopencm3/stm32/rcc.h>
#include <libopencm3/stm32/usart.h>
#include <libopencm3/stm32/exti.h>
#include <libopencmsis/core_cm3.h>
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
#include "btstack_event.h"
#include "btstack_run_loop.h"
#include "btstack_run_loop_embedded.h"
#include "hci.h"
#include "bluetooth_company_id.h"
#include "btstack_chipset_cc256x.h"
#include "btstack_memory.h"
#include "classic/btstack_link_key_db.h"
// STDOUT_FILENO and STDERR_FILENO are defined by <unistd.h> with GCC
// (this is a hack for IAR)
#ifndef STDOUT_FILENO
#define STDERR_FILENO 1
#endif
#ifndef STDERR_FILENO
#define STDERR_FILENO 2
#endif
// Configuration
// LED2 on PA5
// Debug: USART2, TX on PA2
// Bluetooth: USART3. TX PB10, RX PB11, CTS PB13 (in), RTS PB14 (out), N_SHUTDOWN PB15
#define GPIO_LED2 GPIO5
#define USART_CONSOLE USART2
#define GPIO_BT_N_SHUTDOWN GPIO15
#define GPIO_DEBUG_0 GPIO1
#define GPIO_DEBUG_1 GPIO2
// btstack code starts there
void btstack_main(void);
static void bluetooth_power_cycle(void);
// hal_tick.h inmplementation
#include "hal_tick.h"
static void dummy_handler(void);
static void (*tick_handler)(void) = &dummy_handler;
static int hal_uart_needed_during_sleep = 1;
static void dummy_handler(void){};
static btstack_packet_callback_registration_t hci_event_callback_registration;
void hal_tick_init(void){
systick_set_reload(800000); // 1/4 of clock -> 250 ms tick
systick_set_clocksource(STK_CSR_CLKSOURCE_AHB);
systick_counter_enable();
systick_interrupt_enable();
}
int hal_tick_get_tick_period_in_ms(void){
return 100;
}
void hal_tick_set_handler(void (*handler)(void)){
if (handler == NULL){
tick_handler = &dummy_handler;
return;
}
tick_handler = handler;
}
void sys_tick_handler(void){
(*tick_handler)();
}
static void msleep(uint32_t delay) {
uint32_t wake = btstack_run_loop_embedded_get_ticks() + delay / hal_tick_get_tick_period_in_ms();
while (wake > btstack_run_loop_embedded_get_ticks());
}
// hal_led.h implementation
#include "hal_led.h"
void hal_led_off(void);
void hal_led_on(void);
void hal_led_off(void){
gpio_clear(GPIOA, GPIO_LED2);
}
void hal_led_on(void){
gpio_set(GPIOA, GPIO_LED2);
}
void hal_led_toggle(void){
gpio_toggle(GPIOA, GPIO_LED2);
}
// hal_cpu.h implementation
#include "hal_cpu.h"
void hal_cpu_disable_irqs(void){
__disable_irq();
}
void hal_cpu_enable_irqs(void){
__enable_irq();
}
void hal_cpu_enable_irqs_and_sleep(void){
hal_led_off();
__enable_irq();
__asm__("wfe"); // go to sleep if event flag isn't set. if set, just clear it. IRQs set event flag
// note: hal_uart_needed_during_sleep can be used to disable peripheral clock if it's not needed for a timer
hal_led_on();
}
// hal_uart_dma.c implementation
#include "hal_uart_dma.h"
// handlers
static void (*rx_done_handler)(void) = dummy_handler;
static void (*tx_done_handler)(void) = dummy_handler;
static void (*cts_irq_handler)(void) = dummy_handler;
static void hal_uart_manual_rts_set(void){
gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO_USART3_RTS);
}
static void hal_uart_manual_rts_clear(void){
gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO_USART3_RTS);
}
void hal_uart_dma_set_sleep(uint8_t sleep){
if (sleep){
hal_uart_manual_rts_set();
} else {
hal_uart_manual_rts_clear();
}
hal_uart_needed_during_sleep = !sleep;
}
// DMA1_CHANNEL2 UART3_TX
void dma1_channel2_isr(void) {
if ((DMA1_ISR & DMA_ISR_TCIF2) != 0) {
DMA1_IFCR |= DMA_IFCR_CTCIF2;
dma_disable_transfer_complete_interrupt(DMA1, DMA_CHANNEL2);
usart_disable_tx_dma(USART3);
dma_disable_channel(DMA1, DMA_CHANNEL2);
(*tx_done_handler)();
}
}
// DMA1_CHANNEL2 UART3_RX
void dma1_channel3_isr(void){
if ((DMA1_ISR & DMA_ISR_TCIF3) != 0) {
DMA1_IFCR |= DMA_IFCR_CTCIF3;
dma_disable_transfer_complete_interrupt(DMA1, DMA_CHANNEL3);
usart_disable_rx_dma(USART3);
dma_disable_channel(DMA1, DMA_CHANNEL3);
gpio_set(GPIOB, GPIO_DEBUG_1);
// hal_uart_manual_rts_set();
(*rx_done_handler)();
}
}
// CTS RISING ISR
void exti15_10_isr(void){
exti_reset_request(EXTI13);
(*cts_irq_handler)();
}
void hal_uart_dma_init(void){
bluetooth_power_cycle();
}
void hal_uart_dma_set_block_received( void (*the_block_handler)(void)){
rx_done_handler = the_block_handler;
}
void hal_uart_dma_set_block_sent( void (*the_block_handler)(void)){
tx_done_handler = the_block_handler;
}
void hal_uart_dma_set_csr_irq_handler( void (*the_irq_handler)(void)){
if (the_irq_handler){
/* Configure the EXTI13 interrupt (USART3_CTS is on PB13) */
nvic_enable_irq(NVIC_EXTI15_10_IRQ);
exti_select_source(EXTI13, GPIOB);
exti_set_trigger(EXTI13, EXTI_TRIGGER_RISING);
exti_enable_request(EXTI13);
} else {
exti_disable_request(EXTI13);
nvic_disable_irq(NVIC_EXTI15_10_IRQ);
}
cts_irq_handler = the_irq_handler;
}
int hal_uart_dma_set_baud(uint32_t baud){
usart_disable(USART3);
usart_set_baudrate(USART3, baud);
usart_enable(USART3);
return 0;
}
void hal_uart_dma_send_block(const uint8_t *data, uint16_t size){
// printf("hal_uart_dma_send_block size %u\n", size);
/*
* USART3_TX Using DMA_CHANNEL2
*/
/* Reset DMA channel*/
dma_channel_reset(DMA1, DMA_CHANNEL2);
dma_set_peripheral_address(DMA1, DMA_CHANNEL2, (uint32_t)&USART3_DR);
dma_set_memory_address(DMA1, DMA_CHANNEL2, (uint32_t)data);
dma_set_number_of_data(DMA1, DMA_CHANNEL2, size);
dma_set_read_from_memory(DMA1, DMA_CHANNEL2);
dma_enable_memory_increment_mode(DMA1, DMA_CHANNEL2);
dma_set_peripheral_size(DMA1, DMA_CHANNEL2, DMA_CCR_PSIZE_8BIT);
dma_set_memory_size(DMA1, DMA_CHANNEL2, DMA_CCR_MSIZE_8BIT);
dma_set_priority(DMA1, DMA_CHANNEL2, DMA_CCR_PL_VERY_HIGH);
dma_enable_transfer_complete_interrupt(DMA1, DMA_CHANNEL2);
dma_enable_channel(DMA1, DMA_CHANNEL2);
usart_enable_tx_dma(USART3);
}
void hal_uart_dma_receive_block(uint8_t *data, uint16_t size){
// hal_uart_manual_rts_clear();
gpio_clear(GPIOB, GPIO_DEBUG_1);
/*
* USART3_RX is on DMA_CHANNEL3
*/
// printf("hal_uart_dma_receive_block req size %u\n", size);
/* Reset DMA channel*/
dma_channel_reset(DMA1, DMA_CHANNEL3);
dma_set_peripheral_address(DMA1, DMA_CHANNEL3, (uint32_t)&USART3_DR);
dma_set_memory_address(DMA1, DMA_CHANNEL3, (uint32_t)data);
dma_set_number_of_data(DMA1, DMA_CHANNEL3, size);
dma_set_read_from_peripheral(DMA1, DMA_CHANNEL3);
dma_enable_memory_increment_mode(DMA1, DMA_CHANNEL3);
dma_set_peripheral_size(DMA1, DMA_CHANNEL3, DMA_CCR_PSIZE_8BIT);
dma_set_memory_size(DMA1, DMA_CHANNEL3, DMA_CCR_MSIZE_8BIT);
dma_set_priority(DMA1, DMA_CHANNEL3, DMA_CCR_PL_HIGH);
dma_enable_transfer_complete_interrupt(DMA1, DMA_CHANNEL3);
dma_enable_channel(DMA1, DMA_CHANNEL3);
usart_enable_rx_dma(USART3);
}
// end of hal_uart
/**
* Use USART_CONSOLE as a console.
* This is a syscall for newlib
* @param file
* @param ptr
* @param len
* @return
*/
int _write(int file, char *ptr, int len);
int _write(int file, char *ptr, int len){
int i;
if (file == STDOUT_FILENO || file == STDERR_FILENO) {
for (i = 0; i < len; i++) {
if (ptr[i] == '\n') {
usart_send_blocking(USART_CONSOLE, '\r');
}
usart_send_blocking(USART_CONSOLE, ptr[i]);
}
return i;
}
errno = EIO;
return -1;
}
static void clock_setup(void){
/* Enable clocks for GPIO port A (for GPIO_USART1_TX) and USART1 + USART2. */
/* needs to be done before initializing other peripherals */
rcc_periph_clock_enable(RCC_GPIOA);
rcc_periph_clock_enable(RCC_GPIOB);
rcc_periph_clock_enable(RCC_USART2);
rcc_periph_clock_enable(RCC_USART3);
rcc_periph_clock_enable(RCC_DMA1);
rcc_periph_clock_enable(RCC_AFIO); // needed by EXTI interrupts
}
static void gpio_setup(void){
/* Set GPIO5 (in GPIO port A) to 'output push-pull'. [LED] */
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO_LED2);
// PB1 and PB2 as debug output
gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO_DEBUG_0 | GPIO_DEBUG_1);
}
static void debug_usart_setup(void){
/* Setup GPIO pin GPIO_USART2_TX/GPIO2 on GPIO port A for transmit. */
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO_USART2_TX);
/* Setup UART parameters. */
usart_set_baudrate(USART2, 9600);
usart_set_databits(USART2, 8);
usart_set_stopbits(USART2, USART_STOPBITS_1);
usart_set_mode(USART2, USART_MODE_TX);
usart_set_parity(USART2, USART_PARITY_NONE);
usart_set_flow_control(USART2, USART_FLOWCONTROL_NONE);
/* Finally enable the USART. */
usart_enable(USART2);
}
static void bluetooth_setup(void){
printf("\nBluetooth starting...\n");
// n_shutdown as output
gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_PUSHPULL,GPIO_BT_N_SHUTDOWN);
// tx output
gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO_USART3_TX);
// rts output (default to 1)
gpio_set(GPIOB, GPIO_USART3_RTS);
gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO_USART3_RTS);
// rx input
gpio_set_mode(GPIOB, GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO_USART3_RX);
// cts as input
gpio_set_mode(GPIOB, GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO_USART3_CTS);
/* Setup UART parameters. */
usart_set_baudrate(USART3, 115200);
usart_set_databits(USART3, 8);
usart_set_stopbits(USART3, USART_STOPBITS_1);
usart_set_mode(USART3, USART_MODE_TX_RX);
usart_set_parity(USART3, USART_PARITY_NONE);
usart_set_flow_control(USART3, USART_FLOWCONTROL_RTS);
/* Finally enable the USART. */
usart_enable(USART3);
// TX
nvic_set_priority(NVIC_DMA1_CHANNEL2_IRQ, 0);
nvic_enable_irq(NVIC_DMA1_CHANNEL2_IRQ);
// RX
nvic_set_priority(NVIC_DMA1_CHANNEL3_IRQ, 0);
nvic_enable_irq(NVIC_DMA1_CHANNEL3_IRQ);
}
// reset Bluetooth using n_shutdown
static void bluetooth_power_cycle(void){
printf("Bluetooth power cycle\n");
gpio_clear(GPIOA, GPIO_LED2);
gpio_clear(GPIOB, GPIO_BT_N_SHUTDOWN);
msleep(250);
gpio_set(GPIOA, GPIO_LED2);
gpio_set(GPIOB, GPIO_BT_N_SHUTDOWN);
msleep(500);
}
// after HCI Reset, use 115200. Then increase baud reate to 468000.
// (on nucleo board without external crystall, running at 8 Mhz, 1 mbps was not possible)
static const hci_transport_config_uart_t config = {
HCI_TRANSPORT_CONFIG_UART,
115200,
460800,
1,
NULL
};
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:
if (btstack_event_state_get_state(packet) != HCI_STATE_WORKING) return;
printf("BTstack up and running.\n");
break;
case HCI_EVENT_COMMAND_COMPLETE:
if (HCI_EVENT_IS_COMMAND_COMPLETE(packet, hci_read_local_version_information)){
uint16_t manufacturer = little_endian_read_16(packet, 10);
uint16_t lmp_subversion = little_endian_read_16(packet, 12);
// assert manufacturer is TI
if (manufacturer != BLUETOOTH_COMPANY_ID_TEXAS_INSTRUMENTS_INC){
printf("ERROR: Expected Bluetooth Chipset from TI but got manufacturer 0x%04x\n", manufacturer);
break;
}
// assert correct init script is used based on expected lmp_subversion
if (lmp_subversion != btstack_chipset_cc256x_lmp_subversion()){
printf("Error: LMP Subversion does not match initscript! ");
printf("Your initscripts is for %s chipset\n", btstack_chipset_cc256x_lmp_subversion() < lmp_subversion ? "an older" : "a newer");
printf("Please update Makefile to include the appropriate bluetooth_init_cc256???.c file\n");
break;
}
}
break;
default:
break;
}
}
int main(void)
{
clock_setup();
gpio_setup();
hal_tick_init();
debug_usart_setup();
bluetooth_setup();
// start with BTstack init - especially configure HCI Transport
btstack_memory_init();
btstack_run_loop_init(btstack_run_loop_embedded_get_instance());
// init HCI
hci_init(hci_transport_h4_instance(btstack_uart_block_embedded_instance()), (void*) &config);
hci_set_link_key_db(btstack_link_key_db_memory_instance());
hci_set_chipset(btstack_chipset_cc256x_instance());
// inform about BTstack state
hci_event_callback_registration.callback = &packet_handler;
hci_add_event_handler(&hci_event_callback_registration);
// hand over to btstack embedded code
btstack_main();
// go
btstack_run_loop_execute();
return 0;
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 274 KiB

View File

@ -1,12 +0,0 @@
PRIMARY_SERVICE, GAP_SERVICE
CHARACTERISTIC, GAP_DEVICE_NAME, READ, "SPP+LE Counter"
PRIMARY_SERVICE, GATT_SERVICE
CHARACTERISTIC, GATT_DATABASE_HASH, READ,
// Counter Service
PRIMARY_SERVICE, 0000FF10-0000-1000-8000-00805F9B34FB
// Counter Characteristic, with read and notify
CHARACTERISTIC, 0000FF11-0000-1000-8000-00805F9B34FB, READ | NOTIFY | DYNAMIC,

View File

@ -1,7 +0,0 @@
MEMORY
{
rom (rx) : ORIGIN = 0x08000000, LENGTH = 128K
ram (rwx) : ORIGIN = 0x20000000, LENGTH = 20K
}
INCLUDE libopencm3_stm32f1.ld