multi_role + FreeRTOS & SOFTDEVICE: INVALID MEMORY ACCESS

I'm using nRF52840 with nRF5_SDK_17.1.0_ddde560, and using the ble_app_multirole_lesc example file.

When I port FreeRTOS to the multi_role, there are no errors during compilation, and the counter runs after starting the debug session.

However, the RTT viewer shows <error> app: SOFTDEVICE: INVALID MEMORY ACCESS,

and the phone cannot connect to it.

Below is a portion of my code and files:

main.c

#include "FreeRTOS.h"
#include "task.h"
#include "timers.h"
#include "queue.h"
#include "portmacro.h"
#include "event_groups.h"

#define COUNTER 1

typedef struct
{
	uint8_t event;    // event type
	void *pData;   // event data pointer
}mrEvt_t;

int counter = 0;
QueueHandle_t appQueue;
TaskHandle_t  AppTask_handle;
TimerHandle_t xTimer_COUNTER;

void vAppTask(void *pvParameter);

static BaseType_t multirole_enqueueMsg(uint8_t event, uint8_t state, uint8_t *pData)
{
	BaseType_t success;
	mrEvt_t *pMsg = pvPortMalloc(sizeof(mrEvt_t));

	if (pMsg)
	{
		pMsg->event = event;
		pMsg->pData = pData;

		success = xQueueSend(appQueue, &pMsg, portMAX_DELAY);
 		return (success == pdPASS) ? pdPASS : pdFAIL;
	}
	return pdFAIL;
}

void vTimerCallback_COUNTER(void *pvParameters)
{
	multirole_enqueueMsg(COUNTER, 0, NULL);
}

void initTimer(void)
{
	xTimer_COUNTER = xTimerCreate("BLE_COUNTER", 100, pdTRUE, NULL, vTimerCallback_COUNTER);
}

void initQueue(void)
{
	appQueue = xQueueCreate(10, sizeof(mrEvt_t*));
}

void multirole_processAppMsg(void)
{
	mrEvt_t *pMsg;
	bool safeToDealloc = true;

	BaseType_t queue_receive = xQueueReceive(appQueue, &pMsg, portMAX_DELAY);
	if(queue_receive == pdPASS)
	{
		switch(pMsg->event)
		{
			case COUNTER:
				counter++;
				break;
		}
				
		if ((safeToDealloc == true) && (pMsg->pData != NULL))
		{
			vPortFree(pMsg->pData);
			safeToDealloc = false;
		}
	}
}

int main(void)
{
	bool erase_bonds;

	// Initialize.

	initTimer();
	initQueue();

	// Start execution.
	NRF_LOG_INFO("LE Secure Connections example started.");

	if (erase_bonds == true)
	{
		delete_bonds();
		// Scanning and advertising is started by PM_EVT_PEERS_DELETE_SUCEEDED.
	}
	else
	{
		adv_scan_start();
	}
		
	xTaskCreate(vAppTask, "AppTask", configMINIMAL_STACK_SIZE /*60*/, NULL, tskIDLE_PRIORITY + 1 /*0+1*/, &AppTask_handle);

	vTaskStartScheduler();

	// Enter main loop.
	for (;;)
	{
		idle_state_handle();
			
		APP_ERROR_HANDLER(NRF_ERROR_FORBIDDEN);
	}
}

void vAppTask(void *pvParameters)
{
	xTimerStart(xTimer_COUNTER, 0);
	
	for (;;)
	{	
		multirole_processAppMsg();
	}
}

sdk_config.h

#define NRFX_CLOCK_ENABLED 1
#define NRFX_CLOCK_CONFIG_LF_SRC 1
#define NRFX_CLOCK_CONFIG_IRQ_PRIORITY 6
#define NRFX_CLOCK_CONFIG_LOG_ENABLED 0
#define NRFX_CLOCK_CONFIG_LOG_LEVEL 3
#define NRFX_CLOCK_CONFIG_INFO_COLOR 0
#define NRFX_CLOCK_CONFIG_DEBUG_COLOR 0
#define NRF_CLOCK_ENABLED 1
#define CLOCK_CONFIG_LF_SRC 1
#define CLOCK_CONFIG_LF_CAL_ENABLED 0
#define CLOCK_CONFIG_IRQ_PRIORITY 6

Related