Implementing FATFS and USB MSC SD card examples together to store/access data to/from the file

Dear ,

Thanks a lot for your time.

We currently have a project using nRF52840 dongle and nRF connect SDK, implementing FATFS and USB MSC SD card examples together.

The nRF52840 by itself is powered by the battery source. When turned on, it will acquire data from peripherals and store it in the file on the SD card that is created by the program. When a data acquisition session is finished and it is connected to a PC via USB, the data file can be accessed by PC or Mac just like an SD card reader.

I am not sure if I get it correctly, but to be able to achieve the function described above, do I need to introduce a certain mechanism to check whether it's been connected to a USB port and then call the function usb_enable(NULL) so that it can then appear as a disk drive in PC or Mac? 

Do I always call usb_enable(NULL) like a process of initialisation? or do I only call this function when it's been connected to a USB port.

Thanks again. Kind regards, Kevin

Parents
  • Hi,

    It should be sufficient to call usb_enable() in the initialization. The USB library will handle attachment and such for you. It may not be easy to detect when using the dongle, but if you were to build the USB  Mass Storage sample for the nRF52840 DK, you can plug and replug the nRF USB port to a computer multiple times and observe that the mass storage drive will enumerate on the computer, even though you have only a single call to usb_enable() in the code. If you do not call this function, nothing will happen when you connect the USB.

    For your application to know when you are connected to a PC or not, you can pass a callback to usb_enable(), to get events when it connects/disconnects, in case you need to know when you should write to the MSC/SD card or not.

    For instance like this:

    Best regards,
    Jørgen

  • Hi Jørgen,

    Just letting you know that it's been resolved now.

    Thanks a lot for your help again.

    It would be of great help if you could also help with the other tickets I opened.

    Thanks again.

    Kind regards, Kevin

Reply
  • Hi Jørgen,

    Just letting you know that it's been resolved now.

    Thanks a lot for your help again.

    It would be of great help if you could also help with the other tickets I opened.

    Thanks again.

    Kind regards, Kevin

Children
No Data