update central to support up to 4 conn with 1 shared secure connection

- adjust SRAM for bluefruit & loop task
- adjust BLE_GATTS_ATTR_TABLE_SIZE from 0x1000 down to 0x0B00
This commit is contained in:
hathach committed 2017-02-18 01:41:07 +07:00
1 parent ecedd3d0e2
commit ecdc351087
7 files changed
+88 -37

No files matched your search

+15 -6
View File
@@ -90,24 +90,33 @@ int dbgHeapUsed(void)
return (mallinfo()).uordblks;
}
static void printCenter(const char* str, int width)
{
int lpad = (width-strlen(str))/2;
int rpad = width - strlen(str) - lpad;
Serial.printf("|%*c%s%*c|\n", lpad, ' ', str, rpad, ' ');
}
static void printMemRegion(const char* name, uint32_t top, uint32_t bottom, uint32_t used)
{
const int width = 21;
const int WIDTH = 21;
Serial.printf(" _____________________ 0x%08lX\n", top);
Serial.printf("| |\n");
int lpad = (width-strlen(name))/2;
int rpad = width - strlen(name) - lpad;
Serial.printf("|%*c%s%*c|\n", lpad, ' ', name, rpad, ' ');
printCenter(name, WIDTH);
char buffer[30];
if ( used )
{
Serial.printf("| %d / %d (%02lu%%) |\n", used, top-bottom, (used*100)/ (top-bottom));
sprintf(buffer, "%d / %d (%02lu%%)", used, top-bottom, (used*100)/ (top-bottom));
}else
{
Serial.printf("| %d |\n",top-bottom);
sprintf(buffer, "%d", top-bottom);
}
printCenter(buffer, WIDTH);
Serial.printf("|_____________________| 0x%08lX\n", bottom);
}
+1 -1
View File
@@ -21,7 +21,7 @@
void initVariant() __attribute__((weak));
void initVariant() { }
uint32_t _loopStacksize = 1024*2;
uint32_t _loopStacksize = 512*3;
uint32_t setLoopStacksize(void) __attribute__ ((weak));
@@ -0,0 +1,30 @@
/*********************************************************************
This is an example for our nRF52 based Bluefruit LE modules
Pick one up today in the adafruit shop!
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
MIT license, check LICENSE for more information
All text above, and the splash screen below must be included in
any redistribution
*********************************************************************/
#include <Arduino.h>
void setup()
{
Serial.begin(115200);
Serial.println("Bluefruit52 Memory Info Example");
}
void loop()
{
dbgMemInfo();
digitalToggle(LED_BUILTIN);
delay(5000); // wait for a second
}
@@ -21,7 +21,7 @@ void setup()
Serial.println("Bluefruit52 Central Scan Example");
// up to 1 peripheral conn and 1 central conn
Bluefruit.begin(0, 1);
Bluefruit.begin(true, true);
Bluefruit.setName("Bluefruit52");
// Start Central Scan
+18 -18
View File
@@ -38,10 +38,13 @@
#include <nffs_lib.h>
// Note chaning these parameters will affect APP_RAM_BASE
// --> need to update RAM in feather52_s132.ld linker
#define BLE_GATTS_ATTR_TABLE_SIZE 0x0B00
#define BLE_VENDOR_UUID_MAX 10
#define BLE_PRPH_MAX_CONN 1
#define BLE_CENTRAL_MAX_CONN 0
#define BLE_CENTRAL_MAX_SECURE_CONN 0
#define BLE_CENTRAL_MAX_CONN 4
#define BLE_CENTRAL_MAX_SECURE_CONN 1 // currently 1 to save SRAM
#define SVC_CONTEXT_FLAG (BLE_GATTS_SYS_ATTR_FLAG_SYS_SRVCS | BLE_GATTS_SYS_ATTR_FLAG_USR_SRVCS)
@@ -69,10 +72,7 @@
// Converts an integer of 625ms units to msecs
#define MS625TO1000(u625) ( ((u625)*5) / 8 )
// To change this value, an adjustment for SRAM is required in linker script
#define BLE_GATTS_ATTR_TABLE_SIZE 0x1000
#define BLUEFRUIT_TASK_STACKSIZE (1024*1)
#define BLUEFRUIT_TASK_STACKSIZE (512*3)
extern "C"
{
@@ -100,8 +100,8 @@ static void bluefruit_blinky_cb( TimerHandle_t xTimer )
*/
AdafruitBluefruit::AdafruitBluefruit(void)
{
_max_prph_conn = 1;
_max_central_conn = 0;
_prph_enabled = true;
_central_enabled = false;
_ble_event_sem = NULL;
@@ -142,10 +142,10 @@ AdafruitBluefruit::AdafruitBluefruit(void)
_discconnect_cb = NULL;
}
err_t AdafruitBluefruit::begin(uint8_t prph_conn, uint8_t central_conn)
err_t AdafruitBluefruit::begin(bool prph_enable, bool central_enable)
{
_max_prph_conn = prph_conn;
_max_central_conn = central_conn;
_prph_enabled = prph_enable;
_central_enabled = central_enable;
// Configure Clock
nrf_clock_lf_cfg_t clock_cfg =
@@ -163,9 +163,9 @@ err_t AdafruitBluefruit::begin(uint8_t prph_conn, uint8_t central_conn)
{
.common_enable_params = { .vs_uuid_count = BLE_VENDOR_UUID_MAX },
.gap_enable_params = {
.periph_conn_count = _max_prph_conn,
.central_conn_count = _max_central_conn,
.central_sec_count = _max_central_conn
.periph_conn_count = _prph_enabled ? 1 : 0,
.central_conn_count = _central_enabled ? BLE_CENTRAL_MAX_CONN : 0,
.central_sec_count = _central_enabled ? BLE_CENTRAL_MAX_SECURE_CONN : 0,
},
.gatts_enable_params = {
.service_changed = 1,
@@ -173,8 +173,8 @@ err_t AdafruitBluefruit::begin(uint8_t prph_conn, uint8_t central_conn)
}
};
extern uint32_t __data_start__; // defined in linker
uint32_t app_ram_base = (uint32_t) &__data_start__;
extern uint32_t __data_start__[]; // defined in linker
uint32_t app_ram_base = (uint32_t) __data_start__;
VERIFY_STATUS( sd_ble_enable(&params, &app_ram_base) );
@@ -203,7 +203,7 @@ err_t AdafruitBluefruit::begin(uint8_t prph_conn, uint8_t central_conn)
// Create RTOS Task for BLE Event
TaskHandle_t task_hdl;
xTaskCreate( adafruit_bluefruit_task, "ble handler", BLUEFRUIT_TASK_STACKSIZE, NULL, TASK_PRIO_HIGH, &task_hdl);
xTaskCreate( adafruit_bluefruit_task, "BLE Evt", BLUEFRUIT_TASK_STACKSIZE, NULL, TASK_PRIO_HIGH, &task_hdl);
_ble_event_sem = xSemaphoreCreateBinary();
VERIFY(_ble_event_sem, NRF_ERROR_NO_MEM);
@@ -213,7 +213,7 @@ err_t AdafruitBluefruit::begin(uint8_t prph_conn, uint8_t central_conn)
_led_blink_th = xTimerCreate(NULL, ms2tick(CFG_ADV_BLINKY_INTERVAL), true, NULL, bluefruit_blinky_cb);
// Also initialize nffs for bonding/config
nffs_pkg_init();
// nffs_pkg_init();
return ERROR_NONE;
}
+3 -3
View File
@@ -60,7 +60,7 @@ class AdafruitBluefruit
public:
AdafruitBluefruit(void); // Constructor
err_t begin(uint8_t prph_conn = 1, uint8_t central_conn = 0);
err_t begin(bool prph_enable = true, bool central_enable = false);
void autoConnLed(bool enabled);
void setConnLedInterval(uint32_t ms);
@@ -140,8 +140,8 @@ class AdafruitBluefruit
void _sd_event_isr(void);
private:
uint8_t _max_prph_conn;
uint8_t _max_central_conn;
bool _prph_enabled;
bool _central_enabled;
SemaphoreHandle_t _ble_event_sem;
BLEDfu _dfu_svc;
+20 -8
View File
@@ -7,17 +7,17 @@ MEMORY
{
FLASH (rx) : ORIGIN = 0x1c000, LENGTH = 0x64000
/* ATTR SIZE = 0x0580, mid bandwidth (central, prph, sec) = (0, 1, 0) */
/* ATTR SIZE = 0x0580, (central, prph, sec) = (0, 1, 0) */
/* RAM (rwx) : ORIGIN = 0x20002080, LENGTH = 0xdf80 */
/* ATTR SIZE = 0x1000, mid bandwidth (central, prph, sec) = (0, 1, 0) */
/* ATTR SIZE = 0x1000, (central, prph, sec) = (0, 1, 0) */
/* RAM (rwx) : ORIGIN = 0x20002B00, LENGTH = 0xD500 */
/* ATTR SIZE = 0x0B00, mid bandwidth (central, prph, sec) = (0, 1, 0) */
RAM (rwx) : ORIGIN = 0x20002600, LENGTH = 0xDA00
/* ATTR SIZE = 0x0B00, mid bandwidth (central, prph, sec) = (4, 1, 4) */
/*RAM (rwx) : ORIGIN = 0x20002600, LENGTH = 0xDA00*/
/* ATTR SIZE = 0x0B00, (central, prph, sec) = (0, 1, 0) */
/*RAM (rwx) : ORIGIN = 0x20001B00 + 0x0B00, LENGTH = 0xE500 - 0x0B00*/
/* ATTR SIZE = 0x0B00, (central, prph, sec) = (4, 1, 1) */
RAM (rwx) : ORIGIN = 0x20001B00 + 0x0B00 + 0x1280, LENGTH = 0xE500 - 0x0B00 - 0x1280
}
SECTIONS
@@ -30,4 +30,16 @@ SECTIONS
} > RAM
} INSERT AFTER .data;
INCLUDE "nrf5x_common.ld"
INCLUDE "nrf5x_common.ld"
/* S132 v2.0.1 role configuration SRAM usage */
/* APP_RAM_BASE_CENTRAL_LINKS_0_PERIPH_LINKS_1_SEC_COUNT_0_MID_BW 0x20001fe8 */
/* APP_RAM_BASE_CENTRAL_LINKS_4_PERIPH_LINKS_1_SEC_COUNT_1_MID_BW 0x20003268 inc = 1280 */
/* APP_RAM_BASE_CENTRAL_LINKS_4_PERIPH_LINKS_1_SEC_COUNT_2_MID_BW 0x20003438 inc = 1450 */
/* APP_RAM_BASE_CENTRAL_LINKS_4_PERIPH_LINKS_1_SEC_COUNT_4_MID_BW 0x200037d0 inc = 17e8 */
/* APP_RAM_BASE_CENTRAL_LINKS_5_PERIPH_LINKS_1_SEC_COUNT_5_MID_BW 0x20003dc8 inc = 1de0*/
/* APP_RAM_BASE_CENTRAL_LINKS_6_PERIPH_LINKS_1_SEC_COUNT_6_MID_BW 0x200043c0 inc = 23d8*/
/* APP_RAM_BASE_CENTRAL_LINKS_7_PERIPH_LINKS_1_SEC_COUNT_7_MID_BW 0x200049b8 inc = 29d0*/