Hello,
I am currently trying to run a Mass Storage Device example on FRDM-MCXN974 with SD card support and FreeRTOS. I managed to get the standard example to run fine. The code contains two tasks APP_task and USB_DeviceTask, I am trying to reduce this code to only one task, which I have designed as follows:
int main(void)
{
/* Initialize board hardware. */
APP_InitBoard();
USB_DeviceApplicationInit();
usb_echo("Available heap size before task creation: %d bytes\r\n", xPortGetFreeHeapSize());
if (g_msc.deviceHandle)
{
if (xTaskCreate(USB_DeviceTask, /* pointer to the task */
(char const *)"usb device task", /* task name for kernel awareness debugging */
9000L / sizeof(portSTACK_TYPE), /* task stack size */
g_msc.deviceHandle, /* optional task startup argument */
4, /* initial priority */
&g_msc.device_task_handle /* optional task handle to create */
) != pdPASS)
{
usb_echo("usb device task create failed!\r\n");
return 1;
}
}
vTaskStartScheduler();
while (1)
{
;
}
return 1;
}
But It always end with fard-fault in USB_DeviceApplicationInit() as in the attached picture.
The original code looked like this:
int main(void)
{
/* board initialization... */
/* task... */
if (xTaskCreate(APP_task, /* pointer to the task */
(char const *)"app task", /* task name for kernel awareness debugging */
5000L / sizeof(portSTACK_TYPE), /* task stack size */
&g_msc, /* optional task startup argument */
3, /* initial priority */
&g_msc.application_task_handle /* optional task handle to create */
) != pdPASS)
{
usb_echo("app task create failed!\r\n");
}
vTaskStartScheduler();
return 1;
}
void USB_DeviceTask(void *handle)
{
while (1U)
{
USB_DeviceTaskFn(handle);
}
}
void APP_task(void *handle)
{
USB_DeviceApplicationInit();
#if USB_DEVICE_CONFIG_USE_TASK
if (g_msc.deviceHandle)
{
if (xTaskCreate(USB_DeviceTask, /* pointer to the task */
(char const *)"usb device task", /* task name for kernel awareness debugging */
5000L / sizeof(portSTACK_TYPE), /* task stack size */
g_msc.deviceHandle, /* optional task startup argument */
5, /* initial priority */
&g_msc.device_task_handle /* optional task handle to create */
) != pdPASS)
{
usb_echo("usb device task create failed!\r\n");
return;
}
}
while (1)
{
}
}
Did I miss anything? Can I somehow reduce the code just to one task?
Thank you very much.