1
votes

I am looking forward to implement some file operations on a USB device which will be plugged into a microcontroller-based bench-top device. The device does not have any OS/RTOS and only runs on a firmware code that I plan to develop. The firmware will have all the necessary functionalities (UART, timer, SPI, I2C, external memory controller etc) that an embedded device usually has.

My questions are:

  1. Can the libusb library be incorporated into the firmware that I plan to develop?
  2. Does the libusb work in non-operating system based environment? Or will I have to choose an OS that I can port onto the microcontroller and then use the libusb library in user space?
1
It is always better to ask an open "How do I solve this problem?" question rather than think of your own solution then ask "How do I make this solution work?". The question you should probably be asking is "How do I support a USB filesystem device on xxxx microcontroller". usblib is probably unsuitable because of dependencies not available to your system (such as a POSIX API and driver model for example), but if you were less cagey about what microcontroller you were using you would get a better more useful answer.Clifford
@Clifford - the actual question asked is not a how to do it, but rather a simple can it be doneChris Stratton
Yes, given sufficient memory this can be done, even without an operating system. However, the more interesting question is if it is the right solution for your problem, even if you were targeting a desktop PC. You mention "file operations" and that is not normally something one would want to do with libusb, but rather using a mass storage & file system driver. Many embedded chips with USB host or OTG ports already have sample code for mounting and accessing a USB mass storage "stick".Chris Stratton
"No" with a well thought out reason, could save someone weeks of banging their head against a problem and gradually discovering the roadblocks more experienced engineers already know about.Chris Stratton
@WedaPashi : Then I suggest that unless you intend to embed Linux, that you use USB "bare-metal" support as part of your selection criteria. Even if you are using an RTOS kernel, most do not mandate a device model so an integration of a bare metal solution is required. For example STM32 has the USB on-the-go Host and device library (UM1021), which I have used sucessfully bare-metal and with Keil RTX, FreeRTOS and Segger embOS.Clifford

1 Answers

3
votes

libusb is currently only supported on Linux, OS X, Windows, Windows CE, Android, and OpenBSD/NetBSD. So yes, it does require an underlying OS. Unless your microcontroller is an ARM that can run Linux, it would not be possible to run libusb without porting the low-level code to your microcontroller hardware and making it work without an OS which would be a huge amount of work.

If you have a microcontroller with USB capability, it is very likely the manufacturer already has a library to access the USB functionality, and/or there are third-party libraries available.