apollo2-em9304: create examples based on template, README.md

This commit is contained in:
Matthias Ringwald 2017-12-20 17:30:18 +01:00
parent c5ae0d2317
commit e6c9673776
7 changed files with 859 additions and 0 deletions

View File

@ -0,0 +1,46 @@
# BTstack port for Ambiq Apollo2 with EM9304
This port uses the Ambiq Apollo2 EVB with their EM9304 (AM_BLE) shield.
HAL and BSP from Ambiq Suite 1.2.11 were used together with the regular ARM GCC.
Upload is possible via the internal J-Link interface or the 10-pin Mini ARM-JTAG Interface.
## Hardware
Ambiq Apollo2 EVB + AM_BLE Shield
- http://ambiqmicro.com/apollo-ultra-low-power-mcus/apollo2-mcu/
## Software
AmbiqSuite:
- http://ambiqmicro.com/apollo-ultra-low-power-mcus/apollo2-mcu/
Please clone BTstack as AmbiqSuite/third-party/bstack folder into the AmbiqSuite.
## Create Example Projects
To create example GCC projects, go to the Apollo2-EM9304 folder
$ cd port/apollo2-em9304
and run make
$ ./create_examples.py
All examples are placed in the boards/apollo2_evb_am_ble/examples folder with btstack_ prefix.
## Compile & Run Example Project
Go to to the gcc folder of one of the example folders and run make
$ run make
To upload, please follow the instructions in the Apollo Getting Started documents.
## Debug output
printf is routed over the USB connector of the EVB at 115200.
In port/apollo2-em9304/btstack_config.h additional debug information can be enabled by uncommenting ENABLE_LOG_INFO.
Also, the full packet log can be enabled in src/btstack_port.c by uncommenting the hci_dump_open(..) line. The console output can then be converted into .pklg files for OS X PacketLogger or WireShark by running tool/create_packet_log.py

View File

@ -0,0 +1,88 @@
#!/usr/bin/env python
#
# Create project files for all BTstack embedded examples in AmbiqSuite/boards/apollo2_evb_am_ble
import os
import shutil
import sys
import time
import subprocess
makefile_gatt_add_on = '''
$(CONFIG)/EXAMPLE.o: $(CONFIG)/EXAMPLE.h
$(CONFIG)/EXAMPLE.h: ../../../../../third_party/btstack/example/EXAMPLE.gatt
\t../../../../../third_party/btstack/tool/compile_gatt.py $^ $@
'''
# get script path
script_path = os.path.abspath(os.path.dirname(sys.argv[0]))
# validate AmbiqSuite root by reading VERSION.txt
am_root = script_path + "/../../../../"
am_version_txt = ""
try:
with open(am_root + 'VERSION.txt', 'r') as fin:
am_version_txt = fin.read() # Read the contents of the file into memory.
except:
pass
if len(am_version_txt) == 0:
print("Cannot find AmbiqSuite root. Make sure BTstack is checked out as AmbiqSuite/third/btstack");
sys.exit(1)
# show WICED version
print("Found AmbiqSuite SDK version: %s" % am_version_txt)
# path to examples
examples_embedded = script_path + "/../../example/"
# path to example template
example_template = script_path + "/example-template/"
# path to AmbiqSuite/boards/apollo2_evb_am_ble/examples
apps_btstack = am_root + "/boards/apollo2_evb_am_ble/examples/"
print("Creating examples in /boards/apollo2_evb_am_ble/examples:")
LE_EXAMPLES = ["ancs_client_demo", "gap_le_advertisements", "gatt_battery_query", "gatt_browser", "le_counter", "le_streamer", "le_streamer_client", "sm_pairing_peripheral", "sm_pairing_central"]
# iterate over btstack examples
for example in LE_EXAMPLES:
# create example folder
apps_folder = apps_btstack + "btstack_" + example + "/"
if not os.path.exists(apps_folder):
os.makedirs(apps_folder)
# copy project makefile
shutil.copyfile(example_template + "Makefile", apps_folder + "Makefile");
# create GCC folder
gcc_folder = apps_folder + "/gcc/"
if not os.path.exists(gcc_folder):
os.makedirs(gcc_folder)
# add rule to generate .h file in src folder if .gatt is present
gatt_path = examples_embedded + example + ".gatt"
need_h = False
if os.path.exists(gatt_path):
# create src folder
src_folder = apps_folder + "/src/"
if not os.path.exists(src_folder):
os.makedirs(src_folder)
need_h = True
# copy makefile and update project name
with open(gcc_folder + 'Makefile', "wt") as fout:
with open(example_template + 'gcc/Makefile', "rt") as fin:
for line in fin:
fout.write(line.replace('TARGET := EXAMPLE', 'TARGET := ' + example))
if (need_h):
fout.write(makefile_gatt_add_on.replace("EXAMPLE",example))
fout.write("INCLUDES += -I${CONFIG}\n")
# copy other files
for file in ['startup_gcc.c', 'btstack_template.ld']:
shutil.copyfile(example_template + "gcc/" + file, apps_folder + "/gcc/" + file);
print("- %s" % example)

View File

@ -0,0 +1,49 @@
#******************************************************************************
#
# Makefile - Rules for building the libraries, examples and docs.
#
# Copyright (c) 2017, Ambiq Micro
# All rights reserved.
#
# 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 holder nor the names of its
# contributors may be used to endorse or promote products derived from this
# software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 THE COPYRIGHT HOLDER 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.
#
# This is part of revision 1.2.11 of the AmbiqSuite Development Package.
#
#******************************************************************************
SUBDIRS:=$(dir $(wildcard */Makefile))
all:
@for i in ${SUBDIRS}; \
do \
$(MAKE) -C $${i} || exit $$?; \
done
clean:
@for i in ${SUBDIRS}; \
do \
$(MAKE) -C $${i} clean; \
done
.PHONY: $(SUBDIRS) all clean

View File

@ -0,0 +1,220 @@
#******************************************************************************
#
# Makefile - Rules for building the libraries, examples and docs.
#
# Copyright (c) 2017, Ambiq Micro
# All rights reserved.
#
# 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 holder nor the names of its
# contributors may be used to endorse or promote products derived from this
# software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 THE COPYRIGHT HOLDER 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.
#
# This is part of revision 1.2.11 of the AmbiqSuite Development Package.
#
#******************************************************************************
TARGET := EXAMPLE
COMPILERNAME := gcc
PROJECT := btstack_template_gcc
CONFIG := bin
AM_SoftwareRoot ?= ../../../../..
SHELL:=/bin/bash
#### Setup ####
TOOLCHAIN ?= arm-none-eabi
PART = apollo2
CPU = cortex-m4
FPU = fpv4-sp-d16
FABI = softfp
LINKER_FILE := ./btstack_template.ld
STARTUP_FILE := ./startup_$(COMPILERNAME).c
#### Required Executables ####
CC = $(TOOLCHAIN)-gcc
GCC = $(TOOLCHAIN)-gcc
CPP = $(TOOLCHAIN)-cpp
LD = $(TOOLCHAIN)-ld
CP = $(TOOLCHAIN)-objcopy
OD = $(TOOLCHAIN)-objdump
RD = $(TOOLCHAIN)-readelf
AR = $(TOOLCHAIN)-ar
SIZE = $(TOOLCHAIN)-size
RM = $(shell which rm 2>/dev/null)
EXECUTABLES = CC LD CP OD AR RD SIZE GCC
K := $(foreach exec,$(EXECUTABLES),\
$(if $(shell which $($(exec)) 2>/dev/null),,\
$(info $(exec) not found on PATH ($($(exec))).)$(exec)))
$(if $(strip $(value K)),$(info Required Program(s) $(strip $(value K)) not found))
ifneq ($(strip $(value K)),)
all clean:
$(info Tools $(TOOLCHAIN)-$(COMPILERNAME) not installed.)
$(RM) -rf bin
else
DEFINES = -DPART_$(PART)
DEFINES+= -DAM_PACKAGE_BGA
DEFINES += -DAM_PART_APOLLO2
INCLUDES = -I../src
INCLUDES += -I${AM_SoftwareRoot}/boards/apollo2_evb_am_ble/bsp
INCLUDES += -I${AM_SoftwareRoot}/utils
INCLUDES += -I${AM_SoftwareRoot}/devices
INCLUDES += -I${AM_SoftwareRoot}/mcu/apollo2
INCLUDES += -I${AM_SoftwareRoot}
VPATH = ${AM_SoftwareRoot}/utils
VPATH +=:${AM_SoftwareRoot}/devices
VPATH +=:../src
# BTstack
INCLUDES += -I${AM_SoftwareRoot}/third_party/btstack/src
INCLUDES += -I${AM_SoftwareRoot}/third_party/btstack/platform/embedded
INCLUDES += -I${AM_SoftwareRoot}/third_party/btstack/port/apollo2-em9304
INCLUDES += -I${AM_SoftwareRoot}/third_party/btstack/3rd-party/micro-ecc
VPATH += ${AM_SoftwareRoot}/third_party/btstack/3rd-party/micro-ecc
VPATH += ${AM_SoftwareRoot}/third_party/btstack/example
VPATH += ${AM_SoftwareRoot}/third_party/btstack/platform/embedded
VPATH += ${AM_SoftwareRoot}/third_party/btstack/port/apollo2-em9304
VPATH += ${AM_SoftwareRoot}/third_party/btstack/src
VPATH += ${AM_SoftwareRoot}/third_party/btstack/src/ble
VPATH += ${AM_SoftwareRoot}/third_party/btstack/src/ble/gatt-service
SRC += ad_parser.c
SRC += ancs_client.c
SRC += att_db.c
SRC += att_dispatch.c
SRC += att_server.c
SRC += battery_service_server.c
SRC += btstack_em9304_spi_embedded.c
SRC += btstack_linked_list.c
SRC += btstack_memory.c
SRC += btstack_memory_pool.c
SRC += btstack_port.c
SRC += btstack_ring_buffer.c
SRC += btstack_run_loop.c
SRC += btstack_run_loop_embedded.c
SRC += btstack_tlv.c
SRC += btstack_uart_block_embedded.c
SRC += btstack_util.c
SRC += device_information_service_server.c
SRC += gatt_client.c
SRC += hci.c
SRC += hci_cmd.c
SRC += hci_dump.c
SRC += hci_transport_em9304_spi.c
SRC += l2cap.c
SRC += l2cap_signaling.c
SRC += le_device_db_memory.c
SRC += sm.c
SRC += uECC.c
SRC += $(TARGET).c
SRC += am_util_delay.c
SRC += am_util_faultisr.c
SRC += am_util_stdio.c
SRC += am_devices_button.c
# SRC += am_devices_em9304.c
SRC += startup_gcc.c
CSRC = $(filter %.c,$(SRC))
ASRC = $(filter %.s,$(SRC))
OBJS = $(CSRC:%.c=$(CONFIG)/%.o)
OBJS+= $(ASRC:%.s=$(CONFIG)/%.o)
DEPS = $(CSRC:%.c=$(CONFIG)/%.d)
DEPS+= $(ASRC:%.s=$(CONFIG)/%.d)
LIBS = ${AM_SoftwareRoot}/boards/apollo2_evb_am_ble/bsp/gcc/bin/libam_bsp.a
LIBS += ${AM_SoftwareRoot}/mcu/apollo2/hal/gcc/bin/libam_hal.a
INCS = ${AM_SoftwareRoot}/boards/apollo2_evb_am_ble/bsp/am_bsp_gpio.h
INCS += ${AM_SoftwareRoot}/mcu/apollo2/hal/am_hal_pin.h
CFLAGS = -mthumb -mcpu=$(CPU) -mfpu=$(FPU) -mfloat-abi=$(FABI)
CFLAGS+= -ffunction-sections -fdata-sections
CFLAGS+= -MMD -MP -std=c99 -Wall -g
CFLAGS+= -O0
CFLAGS+= $(DEFINES)
CFLAGS+= $(INCLUDES)
CFLAGS+= -Dgcc
AM_LFLAGS = -mthumb -mcpu=$(CPU) -mfpu=$(FPU) -mfloat-abi=$(FABI)
AM_LFLAGS+= -nostartfiles -static
AM_LFLAGS+= -Wl,--gc-sections,--entry,am_reset_isr,-Map,$(CONFIG)/$(TARGET).map
AM_LFLAGS+= -Wl,--start-group -lm -lc -lgcc -Wl,--end-group
AM_LFLAGS+=
# Additional user specified CFLAGS
CFLAGS+=$(EXTRA_CFLAGS)
CPFLAGS = -Obinary
ODFLAGS = -S
#### Rules ####
all: directories $(CONFIG)/$(TARGET).bin
directories: $(CONFIG)
$(CONFIG):
@mkdir -p $@
$(CONFIG)/%.o: %.c $(CONFIG)/%.d $(INCS)
@echo " Compiling $(COMPILERNAME) $<" ;\
$(CC) -c $(CFLAGS) $< -o $@
$(CONFIG)/%.o: %.s $(CONFIG)/%.d $(INCS)
@echo " Assembling $(COMPILERNAME) $<" ;\
$(CC) -c $(CFLAGS) $< -o $@
$(CONFIG)/$(TARGET).elf: $(OBJS) $(LIBS)
@echo " Linking $(COMPILERNAME) $@" ;\
$(CC) -Wl,-T,$(LINKER_FILE) -o $@ $(OBJS) $(LIBS) $(AM_LFLAGS)
$(CONFIG)/$(TARGET).bin: $(CONFIG)/$(TARGET).elf
@echo " Copying $(COMPILERNAME) $@..." ;\
$(CP) $(CPFLAGS) $< $@ ;\
$(OD) $(ODFLAGS) $< > $(CONFIG)/$(TARGET).lst
clean:
@echo "Cleaning..." ;\
$(RM) -f $(OBJS) $(DEPS) \
$(CONFIG)/$(TARGET).bin $(CONFIG)/$(TARGET).elf \
$(CONFIG)/$(TARGET).lst $(CONFIG)/$(TARGET).map \
$(CONFIG)/$(TARGET).h
$(CONFIG)/%.d: ;
# Automatically include any generated dependencies
-include $(DEPS)
endif
.PHONY: all clean directories

View File

@ -0,0 +1,64 @@
/******************************************************************************
*
* hello_world_uart.ld - Linker script for applications using startup_gnu.c
*
*****************************************************************************/
ENTRY(am_reset_isr)
MEMORY
{
FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 1024K
SRAM (rwx) : ORIGIN = 0x10000000, LENGTH = 256K
}
SECTIONS
{
.text :
{
. = ALIGN(4);
KEEP(*(.isr_vector))
*(.text)
*(.text*)
*(.rodata)
*(.rodata*)
. = ALIGN(4);
_etext = .;
} > FLASH
/* User stack section initialized by startup code. */
.stack (NOLOAD):
{
. = ALIGN(8);
*(.stack)
*(.stack*)
. = ALIGN(8);
} > SRAM
.data :
{
. = ALIGN(4);
_sdata = .;
*(.data)
*(.data*)
. = ALIGN(4);
_edata = .;
} > SRAM AT>FLASH
/* used by startup to initialize data */
_init_data = LOADADDR(.data);
.bss :
{
. = ALIGN(4);
_sbss = .;
*(.bss)
*(.bss*)
*(COMMON)
. = ALIGN(4);
_ebss = .;
} > SRAM
.ARM.attributes 0 : { *(.ARM.attributes) }
}

View File

@ -0,0 +1,316 @@
//*****************************************************************************
//
//! @file startup_gcc.c
//!
//! @brief Definitions for interrupt handlers, the vector table, and the stack.
//
//*****************************************************************************
//*****************************************************************************
//
// Copyright (c) 2017, Ambiq Micro
// All rights reserved.
//
// 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 holder nor the names of its
// contributors may be used to endorse or promote products derived from this
// software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 THE COPYRIGHT HOLDER 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.
//
// This is part of revision v1.2.10-1-gc24dfba-hotfix of the AmbiqSuite Development Package.
//
//*****************************************************************************
#include <stdint.h>
//*****************************************************************************
//
// Forward declaration of interrupt handlers.
//
//*****************************************************************************
extern void am_reset_isr(void) __attribute ((naked));
extern void am_nmi_isr(void) __attribute ((weak));
extern void am_fault_isr(void) __attribute ((weak));
extern void am_mpufault_isr(void) __attribute ((weak, alias ("am_fault_isr")));
extern void am_busfault_isr(void) __attribute ((weak, alias ("am_fault_isr")));
extern void am_usagefault_isr(void) __attribute ((weak, alias ("am_fault_isr")));
extern void am_svcall_isr(void) __attribute ((weak, alias ("am_default_isr")));
extern void am_debugmon_isr(void) __attribute ((weak, alias ("am_default_isr")));
extern void am_pendsv_isr(void) __attribute ((weak, alias ("am_default_isr")));
extern void am_systick_isr(void) __attribute ((weak, alias ("am_default_isr")));
extern void am_brownout_isr(void) __attribute ((weak, alias ("am_default_isr")));
extern void am_watchdog_isr(void) __attribute ((weak, alias ("am_default_isr")));
extern void am_clkgen_isr(void) __attribute ((weak, alias ("am_default_isr")));
extern void am_vcomp_isr(void) __attribute ((weak, alias ("am_default_isr")));
extern void am_ioslave_ios_isr(void) __attribute ((weak, alias ("am_default_isr")));
extern void am_ioslave_acc_isr(void) __attribute ((weak, alias ("am_default_isr")));
extern void am_iomaster0_isr(void) __attribute ((weak, alias ("am_default_isr")));
extern void am_iomaster1_isr(void) __attribute ((weak, alias ("am_default_isr")));
extern void am_iomaster2_isr(void) __attribute ((weak, alias ("am_default_isr")));
extern void am_iomaster3_isr(void) __attribute ((weak, alias ("am_default_isr")));
extern void am_iomaster4_isr(void) __attribute ((weak, alias ("am_default_isr")));
extern void am_iomaster5_isr(void) __attribute ((weak, alias ("am_default_isr")));
extern void am_gpio_isr(void) __attribute ((weak, alias ("am_default_isr")));
extern void am_ctimer_isr(void) __attribute ((weak, alias ("am_default_isr")));
extern void am_uart_isr(void) __attribute ((weak, alias ("am_default_isr")));
extern void am_uart1_isr(void) __attribute ((weak, alias ("am_default_isr")));
extern void am_adc_isr(void) __attribute ((weak, alias ("am_default_isr")));
extern void am_pdm_isr(void) __attribute ((weak, alias ("am_default_isr")));
extern void am_stimer_isr(void) __attribute ((weak, alias ("am_default_isr")));
extern void am_stimer_cmpr0_isr(void) __attribute ((weak, alias ("am_default_isr")));
extern void am_stimer_cmpr1_isr(void) __attribute ((weak, alias ("am_default_isr")));
extern void am_stimer_cmpr2_isr(void) __attribute ((weak, alias ("am_default_isr")));
extern void am_stimer_cmpr3_isr(void) __attribute ((weak, alias ("am_default_isr")));
extern void am_stimer_cmpr4_isr(void) __attribute ((weak, alias ("am_default_isr")));
extern void am_stimer_cmpr5_isr(void) __attribute ((weak, alias ("am_default_isr")));
extern void am_stimer_cmpr6_isr(void) __attribute ((weak, alias ("am_default_isr")));
extern void am_stimer_cmpr7_isr(void) __attribute ((weak, alias ("am_default_isr")));
extern void am_flash_isr(void) __attribute ((weak, alias ("am_default_isr")));
extern void am_software0_isr(void) __attribute ((weak, alias ("am_default_isr")));
extern void am_software1_isr(void) __attribute ((weak, alias ("am_default_isr")));
extern void am_software2_isr(void) __attribute ((weak, alias ("am_default_isr")));
extern void am_software3_isr(void) __attribute ((weak, alias ("am_default_isr")));
extern void am_default_isr(void) __attribute ((weak));
//*****************************************************************************
//
// The entry point for the application.
//
//*****************************************************************************
extern int main(void);
//*****************************************************************************
//
// Reserve space for the system stack.
//
//*****************************************************************************
__attribute__ ((section(".stack")))
static uint32_t g_pui32Stack[1024];
//*****************************************************************************
//
// The vector table. Note that the proper constructs must be placed on this to
// ensure that it ends up at physical address 0x0000.0000.
//
// Note: Aliasing and weakly exporting am_mpufault_isr, am_busfault_isr, and
// am_usagefault_isr does not work if am_fault_isr is defined externally.
// Therefore, we'll explicitly use am_fault_isr in the table for those vectors.
//
//*****************************************************************************
__attribute__ ((section(".isr_vector")))
void (* const g_am_pfnVectors[])(void) =
{
(void (*)(void))((uint32_t)g_pui32Stack + sizeof(g_pui32Stack)),
// The initial stack pointer
am_reset_isr, // The reset handler
am_nmi_isr, // The NMI handler
am_fault_isr, // The hard fault handler
am_fault_isr, // The MPU fault handler
am_fault_isr, // The bus fault handler
am_fault_isr, // The usage fault handler
0, // Reserved
0, // Reserved
0, // Reserved
0, // Reserved
am_svcall_isr, // SVCall handle
am_debugmon_isr, // Debug monitor handler
0, // Reserved
am_pendsv_isr, // The PendSV handler
am_systick_isr, // The SysTick handler
//
// Peripheral Interrupts
//
am_brownout_isr, // 0: Brownout
am_watchdog_isr, // 1: Watchdog
am_clkgen_isr, // 2: CLKGEN
am_vcomp_isr, // 3: Voltage Comparator
am_ioslave_ios_isr, // 4: I/O Slave general
am_ioslave_acc_isr, // 5: I/O Slave access
am_iomaster0_isr, // 6: I/O Master 0
am_iomaster1_isr, // 7: I/O Master 1
am_iomaster2_isr, // 8: I/O Master 2
am_iomaster3_isr, // 9: I/O Master 3
am_iomaster4_isr, // 10: I/O Master 4
am_iomaster5_isr, // 11: I/O Master 5
am_gpio_isr, // 12: GPIO
am_ctimer_isr, // 13: CTIMER
am_uart_isr, // 14: UART
am_uart1_isr, // 15: UART
am_adc_isr, // 16: ADC
am_pdm_isr, // 17: ADC
am_stimer_isr, // 18: SYSTEM TIMER
am_stimer_cmpr0_isr, // 19: SYSTEM TIMER COMPARE0
am_stimer_cmpr1_isr, // 20: SYSTEM TIMER COMPARE1
am_stimer_cmpr2_isr, // 21: SYSTEM TIMER COMPARE2
am_stimer_cmpr3_isr, // 22: SYSTEM TIMER COMPARE3
am_stimer_cmpr4_isr, // 23: SYSTEM TIMER COMPARE4
am_stimer_cmpr5_isr, // 24: SYSTEM TIMER COMPARE5
am_stimer_cmpr6_isr, // 25: SYSTEM TIMER COMPARE6
am_stimer_cmpr7_isr, // 26: SYSTEM TIMER COMPARE7
am_flash_isr, // 27: FLASH
am_software0_isr, // 28: SOFTWARE0
am_software1_isr, // 29: SOFTWARE1
am_software2_isr, // 30: SOFTWARE2
am_software3_isr // 31: SOFTWARE3
};
//*****************************************************************************
//
// The following are constructs created by the linker, indicating where the
// the "data" and "bss" segments reside in memory. The initializers for the
// "data" segment resides immediately following the "text" segment.
//
//*****************************************************************************
extern uint32_t _etext;
extern uint32_t _sdata;
extern uint32_t _edata;
extern uint32_t _sbss;
extern uint32_t _ebss;
//*****************************************************************************
//
// This is the code that gets called when the processor first starts execution
// following a reset event. Only the absolutely necessary set is performed,
// after which the application supplied entry() routine is called.
//
//*****************************************************************************
#if defined(__GNUC_STDC_INLINE__)
void
am_reset_isr(void)
{
//
// Set the vector table pointer.
//
__asm(" ldr r0, =0xE000ED08\n"
" ldr r1, =g_am_pfnVectors\n"
" str r1, [r0]");
//
// Set the stack pointer.
//
__asm(" ldr sp, [r1]");
#ifndef NOFPU
//
// Enable the FPU.
//
__asm("ldr r0, =0xE000ED88\n"
"ldr r1,[r0]\n"
"orr r1,#(0xF << 20)\n"
"str r1,[r0]\n"
"dsb\n"
"isb\n");
#endif
//
// Copy the data segment initializers from flash to SRAM.
//
__asm(" ldr r0, =_init_data\n"
" ldr r1, =_sdata\n"
" ldr r2, =_edata\n"
"copy_loop:\n"
" ldr r3, [r0], #4\n"
" str r3, [r1], #4\n"
" cmp r1, r2\n"
" blt copy_loop\n");
//
// Zero fill the bss segment.
//
__asm(" ldr r0, =_sbss\n"
" ldr r1, =_ebss\n"
" mov r2, #0\n"
"zero_loop:\n"
" cmp r0, r1\n"
" it lt\n"
" strlt r2, [r0], #4\n"
" blt zero_loop");
//
// Call the application's entry point.
//
main();
//
// If main returns then execute a break point instruction
//
__asm(" bkpt ");
}
#else
#error GNU STDC inline not supported.
#endif
//*****************************************************************************
//
// This is the code that gets called when the processor receives a NMI. This
// simply enters an infinite loop, preserving the system state for examination
// by a debugger.
//
//*****************************************************************************
void
am_nmi_isr(void)
{
//
// Go into an infinite loop.
//
while(1)
{
}
}
//*****************************************************************************
//
// This is the code that gets called when the processor receives a fault
// interrupt. This simply enters an infinite loop, preserving the system state
// for examination by a debugger.
//
//*****************************************************************************
void
am_fault_isr(void)
{
//
// Go into an infinite loop.
//
while(1)
{
}
}
//*****************************************************************************
//
// This is the code that gets called when the processor receives an unexpected
// interrupt. This simply enters an infinite loop, preserving the system state
// for examination by a debugger.
//
//*****************************************************************************
void
am_default_isr(void)
{
//
// Go into an infinite loop.
//
while(1)
{
}
}

View File

@ -0,0 +1,76 @@
// le_counter.h generated from ../../example/le_counter.gatt for BTstack
// binary representation
// attribute size in bytes (16), flags(16), handle (16), uuid (16/128), value(...)
#include <stdint.h>
const uint8_t profile_data[] =
{
// 0x0001 PRIMARY_SERVICE-GAP_SERVICE
0x0a, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x28, 0x00, 0x18,
// 0x0002 CHARACTERISTIC-GAP_DEVICE_NAME-READ
0x0d, 0x00, 0x02, 0x00, 0x02, 0x00, 0x03, 0x28, 0x02, 0x03, 0x00, 0x00, 0x2a,
// 0x0003 VALUE-GAP_DEVICE_NAME-READ-'LE Counter'
0x12, 0x00, 0x02, 0x00, 0x03, 0x00, 0x00, 0x2a, 0x4c, 0x45, 0x20, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x65, 0x72,
// add Battery Service
// #import <battery_service.gatt> -- BEGIN
// Specification Type org.bluetooth.service.battery_service
// https://www.bluetooth.com/api/gatt/xmlfile?xmlFileName=org.bluetooth.service.battery_service.xml
// Battery Service 180F
// 0x0004 PRIMARY_SERVICE-ORG_BLUETOOTH_SERVICE_BATTERY_SERVICE
0x0a, 0x00, 0x02, 0x00, 0x04, 0x00, 0x00, 0x28, 0x0f, 0x18,
// 0x0005 CHARACTERISTIC-ORG_BLUETOOTH_CHARACTERISTIC_BATTERY_LEVEL-DYNAMIC | READ | NOTIFY
0x0d, 0x00, 0x02, 0x00, 0x05, 0x00, 0x03, 0x28, 0x12, 0x06, 0x00, 0x19, 0x2a,
// 0x0006 VALUE-ORG_BLUETOOTH_CHARACTERISTIC_BATTERY_LEVEL-DYNAMIC | READ | NOTIFY-''
0x08, 0x00, 0x02, 0x01, 0x06, 0x00, 0x19, 0x2a,
// 0x0007 CLIENT_CHARACTERISTIC_CONFIGURATION
0x0a, 0x00, 0x1b, 0x01, 0x07, 0x00, 0x02, 0x29, 0x00, 0x00,
// #import <battery_service.gatt> -- END
// 0x0008 PRIMARY_SERVICE-GATT_SERVICE
0x0a, 0x00, 0x02, 0x00, 0x08, 0x00, 0x00, 0x28, 0x01, 0x18,
// 0x0009 CHARACTERISTIC-GATT_SERVICE_CHANGED-READ
0x0d, 0x00, 0x02, 0x00, 0x09, 0x00, 0x03, 0x28, 0x02, 0x0a, 0x00, 0x05, 0x2a,
// 0x000a VALUE-GATT_SERVICE_CHANGED-READ-''
0x08, 0x00, 0x02, 0x00, 0x0a, 0x00, 0x05, 0x2a,
// Counter Service
// 0x000b PRIMARY_SERVICE-0000FF10-0000-1000-8000-00805F9B34FB
0x18, 0x00, 0x02, 0x00, 0x0b, 0x00, 0x00, 0x28, 0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80, 0x00, 0x10, 0x00, 0x00, 0x10, 0xff, 0x00, 0x00,
// Counter Characteristic, with read and notify
// 0x000c CHARACTERISTIC-0000FF11-0000-1000-8000-00805F9B34FB-READ | NOTIFY | DYNAMIC
0x1b, 0x00, 0x02, 0x00, 0x0c, 0x00, 0x03, 0x28, 0x12, 0x0d, 0x00, 0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80, 0x00, 0x10, 0x00, 0x00, 0x11, 0xff, 0x00, 0x00,
// 0x000d VALUE-0000FF11-0000-1000-8000-00805F9B34FB-READ | NOTIFY | DYNAMIC-''
0x16, 0x00, 0x02, 0x03, 0x0d, 0x00, 0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80, 0x00, 0x10, 0x00, 0x00, 0x11, 0xff, 0x00, 0x00,
// 0x000e CLIENT_CHARACTERISTIC_CONFIGURATION
0x0a, 0x00, 0x1b, 0x01, 0x0e, 0x00, 0x02, 0x29, 0x00, 0x00,
// END
0x00, 0x00,
}; // total size 122 bytes
//
// list service handle ranges
//
#define ATT_SERVICE_GAP_SERVICE_START_HANDLE 0x0001
#define ATT_SERVICE_GAP_SERVICE_END_HANDLE 0x0003
#define ATT_SERVICE_ORG_BLUETOOTH_SERVICE_BATTERY_SERVICE_START_HANDLE 0x0004
#define ATT_SERVICE_ORG_BLUETOOTH_SERVICE_BATTERY_SERVICE_END_HANDLE 0x0007
#define ATT_SERVICE_GATT_SERVICE_START_HANDLE 0x0008
#define ATT_SERVICE_GATT_SERVICE_END_HANDLE 0x000a
#define ATT_SERVICE_0000FF10_0000_1000_8000_00805F9B34FB_START_HANDLE 0x000b
#define ATT_SERVICE_0000FF10_0000_1000_8000_00805F9B34FB_END_HANDLE 0x000e
//
// list mapping between characteristics and handles
//
#define ATT_CHARACTERISTIC_GAP_DEVICE_NAME_01_VALUE_HANDLE 0x0003
#define ATT_CHARACTERISTIC_ORG_BLUETOOTH_CHARACTERISTIC_BATTERY_LEVEL_01_VALUE_HANDLE 0x0006
#define ATT_CHARACTERISTIC_ORG_BLUETOOTH_CHARACTERISTIC_BATTERY_LEVEL_01_CLIENT_CONFIGURATION_HANDLE 0x0007
#define ATT_CHARACTERISTIC_GATT_SERVICE_CHANGED_01_VALUE_HANDLE 0x000a
#define ATT_CHARACTERISTIC_0000FF11_0000_1000_8000_00805F9B34FB_01_VALUE_HANDLE 0x000d
#define ATT_CHARACTERISTIC_0000FF11_0000_1000_8000_00805F9B34FB_01_CLIENT_CONFIGURATION_HANDLE 0x000e