• AVR Freaks

SD Card as USB MSD device with FreeRTOS

New Member
  • Total Posts : 11
  • Reward points : 0
  • Joined: 2017/02/14 02:31:49
  • Location: 0
  • Status: offline
2017/03/16 07:14:05 (permalink)

SD Card as USB MSD device with FreeRTOS

I am trying to implement the USB driver on PIC32MZ so I can collect the Data in the SD Card when plugging it to a computer. I managed to have the msd_card harmony example working at an acceptable speed (1.5MB/s reading transfer).
Then, I added FreeRTOS to the demo, and after a few changes, I could have it almost working. But it still has 2 problems:
  • If I plug it to a computer, unplug it and plug it a second time, it usually freezes (configASSERT is triggered)
  • The transfer rate is about half of the initial one (800kB/s)
The changes I made were to put the DRV_SDCARD_Tasks, DRV_USBHS_Tasks and USB_DEVICE_Tasks function in a single task (DRV_SD_CARD_USB_Task), and the RTOS delay is automatically skipped if the power is detected on the USB bus. The CPU is loaded at something close to 100%, but this is not a problem, as there is nothing else to be done while transferring the data (and it can still be done by using a higher priority)
General Configuration:
  • PIC32MZ2048EFM144 (Starter kit + MEBII)
  • Harmony v1.10
  • FreeRTOS v9.0 - tick=1kHz
  • MPLAB X v3.55 - XC32 v1.42
FreeRTOS tasks:
  • _SYS_Tasks: prio=3, stack=1024, task delay=20ms
  • DRV_SD_CARD_USB_Tasks: prio=1, stack=4096, task delay=20ms (or no delay when usb power detected)
  • _APP_Tasks: prio=4, stack=1024, task delay=10ms - initialise the USB driver and then do nothing
  • _LED_Tasks: prio=2, stack=256, task delay=250ms - toggle a LED
Does anyone know how the reliability (and possibly, the transfer speed) could be improved ?
Thanks a lot

Attached Image(s)

Jump to:
© 2019 APG vNext Commercial Version 4.5