Commit ffce77e1 authored by schneider's avatar schneider Committed by Rahix

fix(sdk): Plug in pre-release with BTLE support

Plug in a new SDK with improved BLE support (more source files
available)

Does not yet actually us BLE.
parent ca3aaa55

Too many changes to show.

To preserve performance only 1000 of 1000+ files are displayed.
...@@ -29,10 +29,15 @@ ...@@ -29,10 +29,15 @@
# property whatsoever. Maxim Integrated Products, Inc. retains all # property whatsoever. Maxim Integrated Products, Inc. retains all
# ownership rights. # ownership rights.
# #
# $Id: Makefile 41870 2019-03-26 14:20:03Z nathan.goldstick $ # $Id: Makefile 44505 2019-07-09 20:32:03Z nathan.goldstick $
# #
################################################################################ ################################################################################
# Include project configuration.
ifneq "$(wildcard config.mk)" ""
include config.mk
endif
# This is the name of the build output file # This is the name of the build output file
ifeq "$(PROJECT)" "" ifeq "$(PROJECT)" ""
PROJECT=max32665 PROJECT=max32665
...@@ -55,29 +60,6 @@ endif ...@@ -55,29 +60,6 @@ endif
TARGET_UC:=$(shell echo $(TARGET) | tr a-z A-Z) TARGET_UC:=$(shell echo $(TARGET) | tr a-z A-Z)
TARGET_LC:=$(shell echo $(TARGET) | tr A-Z a-z) TARGET_LC:=$(shell echo $(TARGET) | tr A-Z a-z)
# Beacon App Defines
ifneq "$(BEACON_APP_BEACON_APP_ADV_TYPE)" ""
PROJ_CFLAGS+=-DBEACON_APP_BEACON_APP_ADV_TYPE
endif
ifneq "$(BEACON_APP_MODE)" ""
PROJ_CFLAGS+=-DBEACON_APP_MODE
endif
ifneq "$(BEACON_APP_PEER_ADDR)" ""
PROJ_CFLAGS+=-DBEACON_APP_PEER_ADDR
endif
ifneq "$(BEACON_APP_USE_LEGACY_PDU)" ""
PROJ_CFLAGS+=-DBEACON_APP_USE_LEGACY_PDU
endif
ifneq "$(BEACON_APP_USE_ANON_ADV)" ""
PROJ_CFLAGS+=-DBEACON_APP_USE_ANON_ADV
endif
ifneq "$(BEACON_APP_USE_FRAG_PREF)" ""
PROJ_CFLAGS+=-DBEACON_APP_USE_FRAG_PREF
endif
ifneq "$(BEACON_APP_USE_PER_ADV)" ""
PROJ_CFLAGS+=-DBEACON_APP_USE_PER_ADV
endif
# Last octet address modifier # Last octet address modifier
ifneq "$(BLE_ADDR_LSB)" "" ifneq "$(BLE_ADDR_LSB)" ""
PROJ_CFLAGS+=-DBLE_ADDR_LSB=$(BLE_ADDR_LSB) PROJ_CFLAGS+=-DBLE_ADDR_LSB=$(BLE_ADDR_LSB)
...@@ -90,10 +72,8 @@ endif ...@@ -90,10 +72,8 @@ endif
# This is the path to the CMSIS root directory # This is the path to the CMSIS root directory
ifeq "$(MAXIM_PATH)" "" ifeq "$(MAXIM_PATH)" ""
LIBS_DIR=../../../Libraries LIBS_DIR=../../../Libraries
NDALIBS_DIR=../../../NDALibraries
else else
LIBS_DIR=/$(subst \,/,$(subst :,,$(MAXIM_PATH))/Firmware/$(TARGET_UC)/Libraries) LIBS_DIR=/$(subst \,/,$(subst :,,$(MAXIM_PATH))/Firmware/$(TARGET_UC)/Libraries)
NDALIBS_DIR=/$(subst \,/,$(subst :,,$(MAXIM_PATH))/Firmware/$(TARGET_UC)/NDALibraries)
endif endif
CMSIS_ROOT=$(LIBS_DIR)/CMSIS CMSIS_ROOT=$(LIBS_DIR)/CMSIS
...@@ -101,23 +81,105 @@ CMSIS_ROOT=$(LIBS_DIR)/CMSIS ...@@ -101,23 +81,105 @@ CMSIS_ROOT=$(LIBS_DIR)/CMSIS
SRCS = main.c SRCS = main.c
SRCS += stack_beacon.c SRCS += stack_beacon.c
SRCS += beacon_main.c SRCS += beacon_main.c
# Where to find source files for this test # Where to find source files for this test
VPATH = . VPATH = .
VPATH += fcl/src
# Where to find header files for this test # Where to find header files for this test
IPATH = . IPATH = .
################################################################################
# Project build configuration.
#-------------------------------------------------------------------------------
# Configuration passed via environment vars.
ifdef BTLE_APP_USE_LEGACY_API
ifeq "$(BTLE_APP_USE_LEGACY_API)" ""
PROJ_CFLAGS+=-DBTLE_APP_USE_LEGACY_API=TRUE
else
ifeq "$(BTLE_APP_USE_LEGACY_API)" "0"
else
ifeq "$(BTLE_APP_USE_LEGACY_API)" "FALSE"
else
PROJ_CFLAGS+=-DBTLE_APP_USE_LEGACY_API=TRUE
endif
endif
endif
endif
ifdef CONSOLE_UART
ifneq "$(CONSOLE_UART)" ""
PROJ_CFLAGS+=-DCONSOLE_UART=$(CONSOLE_UART)
endif
endif
ifdef ENABLE_SDMA
ifneq "$(ENABLE_SDMA)" ""
ifeq "$(ENABLE_SDMA)" "0"
undefine ENABLE_SDMA
else
ifeq "$(ENABLE_SDMA)" "FALSE"
undefine ENABLE_SDMA
else
ENABLE_SDMA=1
endif
endif
endif
endif
ifneq "$(ENABLE_SDMA)" ""
ifdef BTLE_APP_USE_LEGACY_API
ifneq "$(BTLE_APP_USE_LEGACY_API)" ""
ifeq "$(BTLE_APP_USE_LEGACY_API)" "0"
$(error SDMA currently requires BTLE_APP_USE_LEGACY_API)
endif
ifeq "$(BTLE_APP_USE_LEGACY_API)" "FALSE"
$(error SDMA currently requires BTLE_APP_USE_LEGACY_API)
endif
endif
endif
endif
#-------------------------------------------------------------------------------
# Configuration specified here.
#--------------------
# Stack configuration
# Enable assertion checking for development # Enable assertion checking for development
PROJ_CFLAGS+=-DMXC_ASSERT_ENABLE PROJ_CFLAGS+=-DMXC_ASSERT_ENABLE=TRUE
PROJ_CFLAGS+=-DASYMMETRIC -DWORD32 PROJ_CFLAGS+=-DWSF_TRACE_ENABLED=TRUE
PROJ_CFLAGS+=-DWSF_ASSERT_ENABLED=TRUE
# PROJ_CFLAGS+=-DLL_TRACE_ENABLED=TRUE
# PROJ_CFLAGS+=-DLL_DBG_PIN_ENABLED=TRUE
PROJ_CFLAGS+=-DWSF_MS_PER_TICK=1
#--------------------
# Application CFLAGS configuration
#--------------------
# Stack CFLAGS configuration
PROJ_CFLAGS+=-DINIT_BROADCASTER
# PROJ_CFLAGS+=-DINIT_OBSERVER
# PROJ_CFLAGS+=-DINIT_CENTRAL
PROJ_CFLAGS+=-DINIT_PERIPHERAL
PROJ_CFLAGS+=-DINIT_ENCRYPTED
ENABLE_LL_TESTER?=#1
# Use this variable to override default compilier optimization.
#MXC_OPTIMIZE_CFLAGS=-Os #MXC_OPTIMIZE_CFLAGS=-Os
#MXC_OPTIMIZE_CFLAGS=-O0 -fomit-frame-pointer
# Point this variable to a linker file to override the default file # Point this variable to a linker file to override the default file
#LINKERFILE=$(CMSIS_ROOT)/Device/Maxim/$(TARGET_UC)/Source/GCC/$(TARGET_LC).ld #LINKERFILE=$(CMSIS_ROOT)/Device/Maxim/$(TARGET_UC)/Source/GCC/$(TARGET_LC).ld
################################################################################ ################################################################################
# Include external library makefiles here # Include external library makefiles here
DEBUG=1
# Include the BSP # Include the BSP
BOARD_DIR=$(LIBS_DIR)/Boards/$(BOARD) BOARD_DIR=$(LIBS_DIR)/Boards/$(BOARD)
...@@ -128,7 +190,7 @@ PERIPH_DRIVER_DIR=$(LIBS_DIR)/$(TARGET)PeriphDriver ...@@ -128,7 +190,7 @@ PERIPH_DRIVER_DIR=$(LIBS_DIR)/$(TARGET)PeriphDriver
include ${PERIPH_DRIVER_DIR}/periphdriver.mk include ${PERIPH_DRIVER_DIR}/periphdriver.mk
# Include Cordio BTLE Library # Include Cordio BTLE Library
CORDIO_DIR=$(NDALIBS_DIR)/BTLE CORDIO_DIR=$(LIBS_DIR)/BTLE
include ${CORDIO_DIR}/btle.mk include ${CORDIO_DIR}/btle.mk
# Include MAXUSB library # Include MAXUSB library
......
# Specifies whether the legacy 4.2 api should be used.
# 1 by default.
# Set to 1 to use 4.2 advertisements.
# Set to 0 to use 5.0 extended advertisements.
BTLE_APP_USE_LEGACY_API?=1
# UART used for console output.
# 1 by default.
CONSOLE_UART?=1
# Run link layer using SDMA.
ENABLE_SDMA?=0
...@@ -29,34 +29,32 @@ ...@@ -29,34 +29,32 @@
* property whatsoever. Maxim Integrated Products, Inc. retains all * property whatsoever. Maxim Integrated Products, Inc. retains all
* ownership rights. * ownership rights.
* *
* $Date: 2019-03-26 14:20:03 +0000 (Tue, 26 Mar 2019) $ * $Date: 2019-07-12 10:56:57 -0500 (Fri, 12 Jul 2019) $
* $Revision: 41870 $ * $Revision: 44598 $
* *
******************************************************************************/ ******************************************************************************/
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include "mxc_config.h"
#include "wsf_types.h" #include "wsf_types.h"
#include "wsf_os.h" #include "wsf_os.h"
#include "wsf_buf.h" #include "wsf_buf.h"
#include "wsf_timer.h" #include "wsf_timer.h"
#include "wsf_trace.h" #include "wsf_trace.h"
#include "app_ui.h" #include "app_ui.h"
#include "ll_api.h"
#include "sch_api.h"
#include "beacon_api.h" #include "beacon_api.h"
#include "mxc_config.h"
#include "gcr_regs.h"
#include "mcr_regs.h"
#include "app_ui.h" #include "app_ui.h"
#include "hci_vs.h"
#include "hci_core.h" #include "hci_core.h"
/************************************************************************************************** /**************************************************************************************************
Macros Macros
**************************************************************************************************/ **************************************************************************************************/
/* Number of WSF buffer pools */ /* Size of buffer for stdio functions */
#define WSF_BUF_POOLS 6 #define WSF_BUF_POOLS 6
#define WSF_BUF_SIZE 0x1048
/* Size of buffer for stdio functions */ /* Size of buffer for stdio functions */
#define PRINTF_BUF_SIZE 128 #define PRINTF_BUF_SIZE 128
...@@ -65,12 +63,13 @@ ...@@ -65,12 +63,13 @@
Local Variables Local Variables
**************************************************************************************************/ **************************************************************************************************/
uint32_t SystemHeapSize=WSF_BUF_SIZE;
uint32_t SystemHeap[WSF_BUF_SIZE/4];
uint32_t SystemHeapStart;
/*! Buffer for stdio functions */ /*! Buffer for stdio functions */
char printf_buffer[PRINTF_BUF_SIZE]; char printf_buffer[PRINTF_BUF_SIZE];
/*! Free memory for pool buffers (use word elements for word alignment). */
static uint32_t mainBufMem[3584/sizeof(uint32_t)+96];
/*! Default pool descriptor. */ /*! Default pool descriptor. */
static wsfBufPoolDesc_t mainPoolDesc[WSF_BUF_POOLS] = static wsfBufPoolDesc_t mainPoolDesc[WSF_BUF_POOLS] =
{ {
...@@ -79,7 +78,7 @@ static wsfBufPoolDesc_t mainPoolDesc[WSF_BUF_POOLS] = ...@@ -79,7 +78,7 @@ static wsfBufPoolDesc_t mainPoolDesc[WSF_BUF_POOLS] =
{ 64, 4 }, { 64, 4 },
{ 128, 4 }, { 128, 4 },
{ 256, 4 }, { 256, 4 },
{ 384, 4 } { 512, 4 }
}; };
/************************************************************************************************** /**************************************************************************************************
...@@ -89,6 +88,12 @@ static wsfBufPoolDesc_t mainPoolDesc[WSF_BUF_POOLS] = ...@@ -89,6 +88,12 @@ static wsfBufPoolDesc_t mainPoolDesc[WSF_BUF_POOLS] =
/*! \brief Stack initialization for app. */ /*! \brief Stack initialization for app. */
extern void StackInitBeacon(void); extern void StackInitBeacon(void);
/*************************************************************************************************/
void PalSysAssertTrap(void)
{
while(1) {}
}
/*************************************************************************************************/ /*************************************************************************************************/
void SysTick_Handler(void) void SysTick_Handler(void)
{ {
...@@ -96,15 +101,17 @@ void SysTick_Handler(void) ...@@ -96,15 +101,17 @@ void SysTick_Handler(void)
} }
/*************************************************************************************************/ /*************************************************************************************************/
static void myTrace(const char *pStr, va_list args) static bool_t myTrace(const uint8_t *pBuf, uint32_t len)
{ {
extern uint8_t wsfCsNesting; extern uint8_t wsfCsNesting;
if (wsfCsNesting == 0) if (wsfCsNesting == 0)
{ {
vprintf(pStr, args); fwrite(pBuf, len, 1, stdout);
printf("\r\n"); return TRUE;
} }
return FALSE;
} }
/*************************************************************************************************/ /*************************************************************************************************/
...@@ -116,47 +123,23 @@ static void myTrace(const char *pStr, va_list args) ...@@ -116,47 +123,23 @@ static void myTrace(const char *pStr, va_list args)
/*************************************************************************************************/ /*************************************************************************************************/
static void WsfInit(void) static void WsfInit(void)
{ {
WsfTimerInit(); uint32_t bytesUsed;
WsfBufInit(sizeof(mainBufMem), (uint8_t*)mainBufMem, WSF_BUF_POOLS, mainPoolDesc); /* setup the systick for 1MS timer*/
WsfTraceRegister(myTrace);
}
/*************************************************************************************************/
/*!
* \brief Initialize platform.
*
* \param msPerTick Milliseconds per timer tick.
*
* \return None.
*/
/*************************************************************************************************/
void PlatformInit(void)
{
/* Change the pullup on the RST pin to 25K */
MXC_MCR->ctrl = 0x202;
/* Set VREGO_D to 1.3V */
*((volatile uint32_t*)0x40004410) = 0x50;
/* Set TX LDO to 1.1V and enable LDO. Set RX LDO to 0.9V and enable LDO */
MXC_GCR->btleldocn = 0xD9; // TX 1.1V RX 0.9V
/* Power up the 32MHz XO */
MXC_GCR->clkcn |= MXC_F_GCR_CLKCN_X32M_EN;
/* Enable peripheral clocks */
MXC_GCR->perckcn0 &= ~(MXC_F_GCR_PERCKCN0_GPIO0D | MXC_F_GCR_PERCKCN0_GPIO1D); // Clear GPIO0 and GPIO1 Disable
MXC_GCR->perckcn1 &= ~(MXC_F_GCR_PERCKCN1_BTLED | MXC_F_GCR_PERCKCN1_TRNGD ); // Clear BTLE and ICACHE0 disable
/* setup the systick */
SysTick->LOAD = (SystemCoreClock / 1000) * WSF_MS_PER_TICK; SysTick->LOAD = (SystemCoreClock / 1000) * WSF_MS_PER_TICK;
SysTick->VAL = 0; SysTick->VAL = 0;
SysTick->CTRL |= (SysTick_CTRL_CLKSOURCE_Msk | SysTick_CTRL_ENABLE_Msk | SysTick_CTRL_TICKINT_Msk); SysTick->CTRL |= (SysTick_CTRL_CLKSOURCE_Msk | SysTick_CTRL_ENABLE_Msk | SysTick_CTRL_TICKINT_Msk);
#ifndef __IAR_SYSTEMS_ICC__ WsfTimerInit();
/* Added to prevent printf() and friends from using malloc() */
setvbuf(stdout, printf_buffer, _IOLBF, PRINTF_BUF_SIZE); SystemHeapStart = (uint32_t)&SystemHeap;
#endif memset(SystemHeap, 0, sizeof(SystemHeap));
printf("SystemHeapStart = 0x%x\n", SystemHeapStart);
printf("SystemHeapSize = 0x%x\n", SystemHeapSize);
bytesUsed = WsfBufInit(WSF_BUF_POOLS, mainPoolDesc);
printf("bytesUsed = 0x%x\n", bytesUsed);
WsfTraceRegisterHandler(myTrace);
WsfTraceEnable(TRUE);
} }
/* /*
...@@ -167,42 +150,18 @@ void PlatformInit(void) ...@@ -167,42 +150,18 @@ void PlatformInit(void)
*/ */
void SetAddress(uint8_t event) void SetAddress(uint8_t event)
{ {
uint8_t bdAddr[6] = {0x20, 0x05, 0x44, 0x8B, 0x05, 0x00}; uint8_t bdAddr[6] = {0x02, 0x00, 0x44, 0x8B, 0x05, 0x00};
switch (event) { switch (event) {
case APP_UI_RESET_CMPL: case APP_UI_RESET_CMPL:
printf("Setting address -- MAC %02X:%02X:%02X:%02X:%02X:%02X\n", bdAddr[5], bdAddr[4], bdAddr[3], bdAddr[2], bdAddr[1], bdAddr[0]); printf("Setting address -- MAC %02X:%02X:%02X:%02X:%02X:%02X\n", bdAddr[5], bdAddr[4], bdAddr[3], bdAddr[2], bdAddr[1], bdAddr[0]);
LlSetBdAddr((uint8_t*)&bdAddr); HciVsSetBdAddr(bdAddr);
LlGetBdAddr(hciCoreCb.bdAddr);
break; break;
default: default:
break; break;
} }
} }
/*************************************************************************************************/
/*!
* \brief Initialize MAC layer.
*
* \param None.
*
* \return None.
*/
/*************************************************************************************************/
void MacInit(void)
{
wsfHandlerId_t handlerId;
/* Initialize link layer. */
BbInit();
handlerId = WsfOsSetNextHandler(SchHandler);
SchInit(handlerId);
LlAdvSlaveInit();
LlConnSlaveInit();
handlerId = WsfOsSetNextHandler(LlHandler);
LlHandlerInit(handlerId);
}
/*************************************************************************************************/ /*************************************************************************************************/
/*! /*!
* \fn main * \fn main
...@@ -216,11 +175,15 @@ void MacInit(void) ...@@ -216,11 +175,15 @@ void MacInit(void)
/*************************************************************************************************/ /*************************************************************************************************/
int main(void) int main(void)
{ {
#ifndef __IAR_SYSTEMS_ICC__
setvbuf(stdout, printf_buffer, _IOLBF, PRINTF_BUF_SIZE);
#endif
printf("\n\n***** MAX32665 BLE Beacon *****\n"); printf("\n\n***** MAX32665 BLE Beacon *****\n");
PlatformInit(); /* Initialize Radio */
WsfInit(); WsfInit();
MacInit();
StackInitBeacon(); StackInitBeacon();
BeaconStart(); BeaconStart();
......
...@@ -17,13 +17,14 @@ ...@@ -17,13 +17,14 @@
*/ */
/*************************************************************************************************/ /*************************************************************************************************/
#include <stdio.h>
#include <string.h>
#include "wsf_types.h" #include "wsf_types.h"
#include "wsf_os.h" #include "wsf_os.h"
#include "util/bstream.h" #include "util/bstream.h"
#include "beacon_api.h" #include "beacon_api.h"
#include "wdxs/wdxs_api.h" #include "wdxs/wdxs_api.h"
#include "hci_handler.h" #include "hci_handler.h"
#include "hci_api.h"
#include "dm_handler.h" #include "dm_handler.h"
#include "l2c_handler.h" #include "l2c_handler.h"
#include "att_handler.h" #include "att_handler.h"
...@@ -35,6 +36,56 @@ ...@@ -35,6 +36,56 @@
#include "svc_dis.h" #include "svc_dis.h"
#include "svc_core.h" #include "svc_core.h"
#include "sec_api.h" #include "sec_api.h"
#include "ll_init_api.h"
#define LL_IMPL_REV 0x2303
#define LL_MEMORY_FOOTPRINT 0xc152
uint8_t LlMem[LL_MEMORY_FOOTPRINT];
const LlRtCfg_t _ll_cfg = {
/* Device */
/*compId*/ LL_COMP_ID_ARM,
/*implRev*/ LL_IMPL_REV,
/*btVer*/ LL_VER_BT_CORE_SPEC_5_0,
/*_align32 */ 0, // padding for alignment
/* Advertiser */
/*maxAdvSets*/ 4, // 4 Extended Advertising Sets
/*maxAdvReports*/ 8,
/*maxExtAdvDataLen*/ LL_MAX_ADV_DATA_LEN,
/*defExtAdvDataFrag*/ 64,
/*auxDelayUsec*/ 0,
/* Scanner */
/*maxScanReqRcvdEvt*/ 4,
/*maxExtScanDataLen*/ LL_MAX_ADV_DATA_LEN,
/* Connection */
/*maxConn*/ 2,
/*nu