This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

freertos is blocked in vPortSuppressTicksAndSleep function

Hi everyone,

I am trying to port freertos on the nRF52832, but it is blocked in the vPortSuppressTicksAndSleep function. Below is the code for configuring the system and the freertos:

int main(void)
{
	/*
	 * Config hardware peripherals
	 */
	ConfigSystem();
	UARTFlush();

	/*
	 * Config FreeRTOS
	 */
	xMutex = xSemaphoreCreateBinary();
	if(xTaskCreate(TaskTest1, "Task 1", configMINIMAL_STACK_SIZE, NULL, 1, NULL) != pdPASS)
		SystemRunOutOfMemory();
	if(xTaskCreate(TaskTest2, "Task 2", configMINIMAL_STACK_SIZE, NULL, 1, NULL) != pdPASS)
		SystemRunOutOfMemory();

	/*
	 * Activate deep sleep mode
	 */
	SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
    ret_code_t err_code = app_timer_init();
    APP_ERROR_CHECK(err_code);

	// Start FreeRTOS scheduler.
	vTaskStartScheduler();

	while(1)
	{
		PrintError("Forbidden for RTOS status!");
		UARTFlush();
	}
}

void TaskTest1(void * pvParameter)
{
	while(1)
	{
		xSemaphoreTake(xMutex, portMAX_DELAY);
		PrintDebug("Task 1");
		UARTFlush();
		xSemaphoreGive(xMutex);
		vTaskDelay(1);
	}
}

void TaskTest2(void * pvParameter)
{
	while(1)
	{
		xSemaphoreTake(xMutex, portMAX_DELAY);
		PrintDebug("Task 2");
		UARTFlush();
		xSemaphoreGive(xMutex);
		vTaskDelay(1);
	}
}

PrintDebug function:

void PrintDebug(const char *string, ...)
{
	volatile char txBuf[100];

	DEBUG_HEADER();
    va_list arg;

    memset((void *) txBuf, 0, sizeof(txBuf));

    va_start(arg, string);
    vsprintf((char *) txBuf, string, arg);
    va_end(arg);
    UARTWrite((uint8_t *) txBuf, strlen((const char *) txBuf));

    COLOR_ENDL();
}

UART_ERR_CODE_t UARTWrite(uint8_t *pByte, uint8_t length)
{
	UART_ERR_CODE_t errCode = UART_ERR_SUCCESS;
	// Write bytes to TX buffer
	errCode |= WriteToTXBuff(pByte, length);

	return errCode;
}

static UART_ERR_CODE_t WriteToTXBuff(uint8_t *byte, uint8_t length)
{
	UART_ERR_CODE_t err = UART_ERR_SUCCESS;
	// If TX buffer is full, return error code
	if(controlBlock.txBufferAvailable == 0)
		return UART_ERR_BYTES_ABORTED;

	// Write bytes to TX buffer until TX buffer is full or all bytes are transmitted
	while((controlBlock.txBufferAvailable != 0) && (length != 0))
	{
		if(xQueueSendToBack(txBuffer, ( void * )byte, (TickType_t) 0) != pdPASS)
			break;
		byte++;
		controlBlock.txBufferAvailable--;
		length--;
	}

	if((controlBlock.txBufferAvailable == 0) && (length != 0))
		err |= UART_ERR_BYTES_ABORTED;

	return err;
}

The code is blocked in the vPortSuppressTicksAndSleep function at the line while (0 == (NVIC->ISPR[0] | NVIC->ISPR[1])) when the program moves to xSemaphoreTake(xMutex, portMAX_DELAY) in TaskTest1 function.

Related