Mass Storage FRDM-MCXN947 With SD Card

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Mass Storage FRDM-MCXN947 With SD Card

ソリューションへジャンプ
3,940件の閲覧回数
Doly02
Contributor I

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.

ラベル(3)
0 件の賞賛
返信
1 解決策
3,852件の閲覧回数
Joey_z
NXP Employee
NXP Employee

hi,Doly02

I don't think it's possible that the SD_Init () function is still connected to the FreeRTOS task resource, and the program ends up with a hard failure, and SD card initialization is done in the USB_DeviceApplicationInit() function. You can refer to the frdmmcxn947_dev_msc_disk_bm demo program where the USB_DeviceApplicationInit() function is initialized in main.

XuZhang_0-1729048195303.png

If you use SD cards in Freertos, ensure that the tasks have enough stack space and do not conflict with other tasks, ensure that the initialization and use of the SD card is thread-safe, and you can use the Mutex provided by FreeRTOS to prevent problems caused by multiple tasks accessing the SD card at the same time. If the SD card initialization is done in one task, and other tasks need to wait for the initialization to complete before using the SD card, then Semaphore or other synchronization mechanism should be used to coordinate the tasks.

BR

Xu Zhang

元の投稿で解決策を見る

0 件の賞賛
返信
5 返答(返信)
3,938件の閲覧回数
Doly02
Contributor I
 
0 件の賞賛
返信
3,898件の閲覧回数
Joey_z
NXP Employee
NXP Employee

hi,Doly02

Thank you for your interest in NXP Semiconductor products and the opportunity to serve you, I will gladly help you with this.

You can try to modify the frdmmcxn947_dev_msc_disk_freertos demo program in the way shown in the picture.

XuZhang_0-1728899840169.pngXuZhang_1-1728899848333.png

 

Wish it helps you.

If you still have question about it,please kindly let me know.

BR

Zhang Xu

0 件の賞賛
返信
3,881件の閲覧回数
Doly02
Contributor I
Hi XuZhang,
thank you for your reply and great support from NXP. I am developing device on FreeRTOS that has two task and each of them uses SD card. When I move the initialization to the main (to not initialize SD card twice), there is probably still issue that SD_Init() function still has a connection to FreeRTOS task resources, and program ends up in hard-fault, is that possible?
0 件の賞賛
返信
3,853件の閲覧回数
Joey_z
NXP Employee
NXP Employee

hi,Doly02

I don't think it's possible that the SD_Init () function is still connected to the FreeRTOS task resource, and the program ends up with a hard failure, and SD card initialization is done in the USB_DeviceApplicationInit() function. You can refer to the frdmmcxn947_dev_msc_disk_bm demo program where the USB_DeviceApplicationInit() function is initialized in main.

XuZhang_0-1729048195303.png

If you use SD cards in Freertos, ensure that the tasks have enough stack space and do not conflict with other tasks, ensure that the initialization and use of the SD card is thread-safe, and you can use the Mutex provided by FreeRTOS to prevent problems caused by multiple tasks accessing the SD card at the same time. If the SD card initialization is done in one task, and other tasks need to wait for the initialization to complete before using the SD card, then Semaphore or other synchronization mechanism should be used to coordinate the tasks.

BR

Xu Zhang

0 件の賞賛
返信
3,729件の閲覧回数
Doly02
Contributor I
Thank you, so the best way is to use as a baseline bare-metal example for my project
0 件の賞賛
返信