This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC2642R: Gap Scan Heap Issue

Part Number: CC2642R
Other Parts Discussed in Thread: SYSBIOS

Hello

We are using simplelink_cc13x2_26x2_sdk_3_20_00_68 with IAR EWARM v8.32.1 and a CC2642R rev E based board.  We started with the Simple Central BLE5 application included with the SDK, removed the menu, did some re-arranging, and added a simple test hook which just starts a 5 second scan and traces out the response data as GapScan reports it.  When we receive GAP_EVT_SCAN_DISABLED, we wait a second and start another scan.  After a few scans it crashes.  I enabled the debug build to get HeapTracker and started tracing heap usage after each scan.  Here's the routine I call to start a scan (lifted from Simple Central):

***********************************************************

	// Set Scanner Event Mask
	GapScan_setEventMask(GAP_EVT_ADV_REPORT | GAP_EVT_SCAN_DUR_ENDED | GAP_EVT_SCAN_DISABLED);

	// Set Scan PHY parameters
	GapScan_setPhyParams(DEFAULT_SCAN_PHY, SCAN_TYPE_ACTIVE, SCAN_PARAM_DFLT_INTERVAL, SCAN_PARAM_DFLT_WINDOW);

	// Set Advertising report fields to keep
	temp16 = SC_ADV_RPT_FIELDS;
	GapScan_setParam(SCAN_PARAM_RPT_FIELDS, &temp16);
	
	// Set Scanning Primary PHY
	temp8 = DEFAULT_SCAN_PHY;
	GapScan_setParam(SCAN_PARAM_PRIM_PHYS, &temp8);
	
	// Set LL Duplicate Filter
	temp8 = SCAN_FLT_DUP_ENABLE;
	GapScan_setParam(SCAN_PARAM_FLT_DUP, &temp8);

	// Set PDU type filter -
	// Only 'Connectable' and 'Complete' packets are desired.
	// It doesn't matter if received packets are
	// whether Scannable or Non-Scannable, whether Directed or Undirected,
	// whether Scan_Rsp's or Advertisements, and whether Legacy or Extended.
	temp16 = SCAN_FLT_PDU_CONNECTABLE_ONLY | SCAN_FLT_PDU_COMPLETE_ONLY;
	GapScan_setParam(SCAN_PARAM_FLT_PDU_TYPE, &temp16);

	// start the scan
	GapScan_enable(0, 5000, 0);

*************************************************************

Here are the relevant traces:

HEAPMGR_CONFIG: 02  HEAPMGR_SIZE: 30000

scan start
Scan end e=15 n=0 r=1
Heap Usage: Total Sz: 30000, Free: 11776, LFS: 11608
Scan complete
scan start
Scan end e=15 n=0 r=1
Heap Usage: Total Sz: 30000, Free: 6016, LFS: 5840
Scan complete
scan start
Scan end e=15 n=0 r=1
Heap Usage: Total Sz: 30000, Free: 2888, LFS: 2680
Scan complete
scan start

The application then exceptions after this (the actual memory values vary from run to run but you see the trend).

I've tried calling GapScan_discardAdvReportList() after each scan completes but it doesn't help.  We sometimes get the SC_EVT_INSUFFICIENT_MEM event as well.  Any ideas?

Thanks

Mark

  • Sorry...typo in the code above.  GapScan_enable(0, 5000, 0); should be GapScan_enable(0, 500, 0);  It was a macro in the original code and I added one extra zero by accident when resolving it.

    Thanks

  • Mark,

    This is certainly strange. Can you provide the whole simple_central.c file? Is it basically some minor changes that you've made and you're able to reproduce it, or have you added a lot of your own application code? It would be ideal for us to recreate it with as minimal changes as possible. I've looped in someone on our team to help follow up. 

  • Hi Evan

    Thanks for responding.  As it is now, the file based on Simple Central has some hooks to another module which drives the "business logic".  That module also handles other non-Bluetooth related hardware, so it would be hard to use it to recreate the problem outside of the project.  I will copy and refactor it to work stand-alone in a test project.  This may give some insight into what I may be doing wrong as well.  I should be able to do this today and if it still doesn't work afterwards, I'll send you the test file which should be easy for you to use.

    I would've tried to recreate this using the stock Simple Central app but I don't have have a Launch Pad board and our hardware can't facilitate the menus.

    Thanks

    Mark

  • Evan, I'm inserting a file with the code which should work for you easily.  We did change the function name prefixes but for the most part, they are the same code wise.  There are some additional functions but they are not being used.  Thanks for your help.

    4520.Application.zip

  • Hello Mark,

    I compiled and ran your code and took a quick look in the ROV after a few rounds of scanning. It seems like the idle task (ti.sysbios.knl.Task.IdleTask) is allocating a lot of heap blocks for each round of scanning which is odd. I am not sure how this is happening yet.

    BTW: I am not familiar with "trace.h". Is this something you made?

  • Hi Eirik

    Yes, trace.h is the debug trace module in the project.  It just consists of a free I/O line used to transmit formatted text to a terminal program via the UART.  I didn't include that in the code I sent.

    Interesting about the idle task.  I hadn't considered that since we don't set up one explicitly for our use.  I'll do some reading about it on this end to familiarize myself with it.

    Thanks