|
| 1 | +# Arduino POSIXStorage Library |
| 2 | + |
| 3 | +The Arduino POSIXStorage Library complements the POSIX storage functions already included in the Renesas core and the Arduino_USBHostMbed5 library. It also makes them available to use in sketches. |
| 4 | + |
| 5 | +The library supports and is tested on: |
| 6 | +- Portenta C33 with Portenta Breakout Board (SD Card and USB Thumb Drive) |
| 7 | +- Portenta C33 with Portenta Vision Shield (SD Card) |
| 8 | +- Portenta H7 with Portenta Breakout Board (SD Card and USB Thumb Drive) |
| 9 | +- Portenta H7 with Portenta Vision Shield (SD Card) |
| 10 | +- Portenta Machine Control (USB Thumb Drive) |
| 11 | + |
| 12 | + |
| 13 | +## Usage |
| 14 | + |
| 15 | +For detailed information on usage, see the API and Examples sections below. This is a very basic example of how to include and use the library: |
| 16 | + |
| 17 | +```cpp |
| 18 | +#include "POSIXStorage.h" |
| 19 | + |
| 20 | +void setup() { |
| 21 | + mount(DEV_SDCARD, FS_FAT, MNT_DEFAULT); |
| 22 | +// ... |
| 23 | +// Use various POSIX storage functions. |
| 24 | +// ... |
| 25 | + umount(DEV_SDCARD); |
| 26 | +} |
| 27 | + |
| 28 | +void loop() { |
| 29 | +} |
| 30 | +``` |
| 31 | + |
| 32 | +It is necessary to install the Arduino_USBHostMbed5 library to use POSIXStorage on Portenta H7 and Portenta Machine Control. No additional library is needed on Portenta C33. |
| 33 | + |
| 34 | +The library automatically detects different types of Portenta H7 / Portenta Machine Control boards. This detection should work in the absolute majority of cases, but if you have trouble with USB on the Portenta Machine control you can try to add #define AUTOMATIC_OVERRIDE_PORTENTA_MACHINE_CONTROL just before #include "POSIXStorage.h". The automatic detection should work even with custom boards, but if you have trouble with USB on a custom board, try to add #define AUTOMATIC_OVERRIDE_PORTENTA_H7 in a similar manner. |
| 35 | + |
| 36 | +## API |
| 37 | + |
| 38 | +The following POSIX functions are not a part of the library but are made available and work more or less according to the specification: close, closedir, fcntl, fsync, fstat, ftruncate, isatty, lseek, mkdir, open, opendir, poll, read, remove, rewinddir, seekdir, stat, statvfs, telldir, and write. |
| 39 | + |
| 40 | +Many ISO C standard functions are also made available. For example: fopen, fprintf, and fclose. |
| 41 | + |
| 42 | +Start pathnames on SD Cards with "/sdcard/" and pathnames on USB thumb drives with "/usb/". See the Examples section below for examples. |
| 43 | + |
| 44 | +The following are additional functions provided by the library: |
| 45 | + |
| 46 | +### `int` [`mount`](#)`(enum DeviceNames deviceName, enum FileSystems fileSystem, enum MountFlags mountFlags)` |
| 47 | + |
| 48 | +Attach a file system to a device. |
| 49 | + |
| 50 | +#### Parameters |
| 51 | +* `deviceName` The device to attach to: DEV_SDCARD or DEV_USB. |
| 52 | +* `fileSystem` The file system type to attach: FS_FAT or FS_LITTLEFS. |
| 53 | +* `mountFlags` The only valid flag at this time: MNT_DEFAULT (future platforms might also support MNT_RDONLY). |
| 54 | + |
| 55 | +#### Returns |
| 56 | +On success: 0. On failure: -1 with an error code in the errno variable. |
| 57 | + |
| 58 | + |
| 59 | +### `int` [`umount`](#)`(enum DeviceNames deviceName)` |
| 60 | + |
| 61 | +Remove the attached file system from a device. |
| 62 | + |
| 63 | +#### Parameters |
| 64 | +* `deviceName` The device to remove from: DEV_SDCARD or DEV_USB. |
| 65 | + |
| 66 | +#### Returns |
| 67 | +On success: 0. On failure: -1 with an error code in the errno variable. |
| 68 | + |
| 69 | + |
| 70 | +### `int` [`register_hotplug_callback`](#)`(enum DeviceNames deviceName, void (*callbackFunction)())` |
| 71 | + |
| 72 | +Register a hotplug callback function. Currently only supported for DEV_USB on Portenta C33. |
| 73 | + |
| 74 | +#### Parameters |
| 75 | +* `deviceName` The device to register for: DEV_SDCARD or DEV_USB. |
| 76 | +* `callbackFunction` A function pointer to the callback. |
| 77 | + |
| 78 | +#### Returns |
| 79 | +On success: 0. On failure: -1 with an error code in the errno variable. |
| 80 | + |
| 81 | + |
| 82 | +### `int` [`deregister_hotplug_callback`](#)`(enum DeviceNames deviceName)` |
| 83 | + |
| 84 | +Deregister a previously registered hotplug callback function. Not currently supported on any platform. |
| 85 | + |
| 86 | +#### Parameters |
| 87 | +* `deviceName` The device to deregister for: DEV_SDCARD or DEV_USB. |
| 88 | + |
| 89 | +#### Returns |
| 90 | +On success: 0. On failure: -1 with an error code in the errno variable. |
| 91 | + |
| 92 | + |
| 93 | +### `int` [`mkfs`](#)`(enum DeviceNames deviceName, enum FileSystems fileSystem)` |
| 94 | + |
| 95 | +Format a device (make file system). |
| 96 | + |
| 97 | +#### Parameters |
| 98 | +* `deviceName` The device to format: DEV_SDCARD or DEV_USB. |
| 99 | +* `fileSystem` The file system type to format: FS_FAT or FS_LITTLEFS. FS_FAT is probably the better choice for both SD Cards and USB thumb drives in most cases. |
| 100 | + |
| 101 | +#### Returns |
| 102 | +On success: 0. On failure: -1 with an error code in the errno variable. |
| 103 | + |
| 104 | + |
| 105 | +## Examples |
| 106 | + |
| 107 | +- **SD_Card_Example:** This example shows how to mount an SD Card and write to and read from a file. |
| 108 | +- **USB_No_Hotplug_Example:** This example shows how to mount a USB thumb drive, without hotplug registration, and write to and read from a file. |
| 109 | +- **USB_Hotplug_Example:** This example shows how to mount a USB thumb drive, with hotplug registration, and write to and read from a file. |
| 110 | + |
| 111 | +## License |
| 112 | + |
| 113 | +This library is released under the [LGPLv2.1 license](https://www.gnu.org/licenses/old-licenses/lgpl-2.1-standalone.html). |
0 commit comments