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

Parents
  • Hello,

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

    Can you please share what it says in the log before this? And are you trying to read or write to some specific address right when this is happening?

    Is it possible for me to reproduce what you are seeing with an nRF52840 DK? If so, can you please upload an application (or a stripped down application) that reproduces the issue?

    Best regards,

    Edvin

Reply
  • Hello,

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

    Can you please share what it says in the log before this? And are you trying to read or write to some specific address right when this is happening?

    Is it possible for me to reproduce what you are seeing with an nRF52840 DK? If so, can you please upload an application (or a stripped down application) that reproduces the issue?

    Best regards,

    Edvin

Children
  • The log only shows this content:

    I'm still at the stage of just integrating FreeRTOS into multi_role and testing the counter changes.

    The most likely places where I might be reading or writing are in xQueueSend and xQueueReceive.

  • Ok. Based on the main.c file that you uploaded, I can't tell what the issue is. Is there a particular reason why you want to use FreeRTOS? I claim that you can do everything you use freertos for without it in the SDK. 

    If you want me to have a look, you can upload your application, and I will see if I get time before the weekend. If not, we are a bit short staffed until August, and the guy who knows FreeRTOS' ins and outs is also back in August.

    Have you tried debugging, setting breakpoints or adding logs to see exactly where it fails? Whether it is in xQueueSend or xQueueReceive?

    You can also compare your main.c file with the ble_app_hrs_freertos example in the SDK (SDK\examples\ble_peripheral\ble_app_hrs_freertos), to see if you can get anything out of how it is done there.

    Best regards,

    Edvin

  • Thank you for your reply.

    We originally wrote our own program with RTOS on TI, and now we want to port it to Nordic.

    I believe the queue might not be the issue because my COUNTER event is able to run counter++ after xQueueReceive.

    Additionally, I commented out all the code related to the queue, but the problem persists.

    I also tried to modify the code to be the same as ble_app_hrs_freertos, except for services_init(), sensor_simulator_init() and SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk in ble_app_hrs_freertos, but the result was the same.

    I forgot to mention earlier that <error> app: SOFTDEVICE: INVALID MEMORY ACCESS seems to be causing my development board to fail to "connect" with the phone.

    Here is my application:

    ble_app_multirole_lesc_RTOS - copy.rar

Related