Skip to content

Adds full Opta support #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ The library supports and is tested on:
- Portenta H7 with Portenta Breakout Board (SD Card and USB Thumb Drive)
- Portenta H7 with Portenta Vision Shield (SD Card)
- Portenta Machine Control (USB Thumb Drive)
- Opta (USB Thumb Drive)


## Usage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ enum TestTypes : uint8_t
TEST_PORTENTA_H7_SDCARD,
TEST_PORTENTA_H7_USB,
TEST_PORTENTA_MACHINE_CONTROL_SDCARD,
TEST_PORTENTA_MACHINE_CONTROL_USB
TEST_PORTENTA_MACHINE_CONTROL_USB,
TEST_OPTA_SDCARD,
TEST_OPTA_USB
};

// !!! TEST CONFIGURATION !!! -->
Expand Down Expand Up @@ -45,11 +47,11 @@ void setup() {
int fileDescriptor = 0;
int retVal = -1;

if ((TEST_PORTENTA_C33_USB == selectedTest) || (TEST_PORTENTA_H7_USB == selectedTest) || (TEST_PORTENTA_MACHINE_CONTROL_USB == selectedTest))
if ((TEST_PORTENTA_C33_USB == selectedTest) || (TEST_PORTENTA_H7_USB == selectedTest) || (TEST_PORTENTA_MACHINE_CONTROL_USB == selectedTest) || (TEST_OPTA_USB == selectedTest))
{
deviceName = DEV_USB;
}
else if ((TEST_PORTENTA_C33_SDCARD == selectedTest) || (TEST_PORTENTA_H7_SDCARD == selectedTest) || (TEST_PORTENTA_MACHINE_CONTROL_SDCARD == selectedTest))
else if ((TEST_PORTENTA_C33_SDCARD == selectedTest) || (TEST_PORTENTA_H7_SDCARD == selectedTest) || (TEST_PORTENTA_MACHINE_CONTROL_SDCARD == selectedTest) || (TEST_OPTA_SDCARD == selectedTest))
{
deviceName = DEV_SDCARD;
}
Expand All @@ -59,18 +61,23 @@ void setup() {
}

Serial.begin(9600);
while (!Serial) ; // Wait for the serial port to be ready
// We can't have the Serial Monitor connected when we test USB on the Opta, and this will cause
// the test to freeze unless we skip it
if (TEST_OPTA_USB != selectedTest)
{
while (!Serial) ; // Wait for the serial port to be ready
}

Serial.println("Testing started, please wait...");
Serial.println();

if (TEST_PORTENTA_MACHINE_CONTROL_SDCARD == selectedTest)
if ((TEST_PORTENTA_MACHINE_CONTROL_SDCARD == selectedTest) || (TEST_OPTA_SDCARD == selectedTest))
{
// Machine Control no SD Card supported test -->
// Machine Control and Opta no SD Card supported test -->
retVal = mount(DEV_SDCARD, FS_FAT, MNT_DEFAULT);
if ((-1 != retVal) || (ENOTBLK != errno))
{
Serial.println("[FAIL] Machine Control no SD Card supported test failed");
Serial.println("[FAIL] Machine Control and Opta no SD Card supported test failed");
}
else
{
Expand All @@ -80,7 +87,7 @@ void setup() {
(void) umount(DEV_SDCARD);
for ( ; ; ) ; // Stop testing here
}
// <-- Machine Control no SD Card supported test
// <-- Machine Control and Opta no SD Card supported test
}

// Register hotplug callback for SD Card test -->
Expand Down Expand Up @@ -110,7 +117,7 @@ void setup() {
// <-- Register nullptr callback test
}

if ((TEST_PORTENTA_H7_USB == selectedTest) || (TEST_PORTENTA_MACHINE_CONTROL_USB == selectedTest))
if ((TEST_PORTENTA_H7_USB == selectedTest) || (TEST_PORTENTA_MACHINE_CONTROL_USB == selectedTest) || (TEST_OPTA_USB == selectedTest))
{
// Register unsupported callback test -->
retVal = register_hotplug_callback(DEV_USB, usbCallback);
Expand All @@ -135,7 +142,7 @@ void setup() {
delay(500);
}
}
else if ((TEST_PORTENTA_H7_USB == selectedTest) || (TEST_PORTENTA_MACHINE_CONTROL_USB == selectedTest))
else if ((TEST_PORTENTA_H7_USB == selectedTest) || (TEST_PORTENTA_MACHINE_CONTROL_USB == selectedTest) || (TEST_OPTA_USB == selectedTest))
{
// These boards don't support hotplug callbacks, so loop on mount() tries
while (0 != mount(DEV_USB, FS_FAT, MNT_DEFAULT)) {
Expand Down Expand Up @@ -457,6 +464,25 @@ void setup() {
Serial.println("FAILURE: Finished with errors (see list above for details)");
}
// <-- Final report

// Opta final report -->
if (TEST_OPTA_USB == selectedTest)
{
(void) mount(deviceName, FS_FAT, MNT_DEFAULT);
FILE *logFile = fopen("/usb/testlog.txt", "w");
if (true == allTestsOk)
{
fprintf(logFile, "SUCCESS: Finished without errors");
fclose(logFile);
}
else
{
fprintf(logFile, "FAILURE: Finished with errors");
fclose(logFile);
}
(void) umount(deviceName);
}
// <--
}

void loop() {
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name=Arduino_POSIXStorage
version=1.0.0
author=Arduino
maintainer=Arduino <[email protected]>
sentence=POSIX Storage Library for the Portenta C33, Portenta H7, and Portenta Machine Control
sentence=POSIX Storage Library for the Portenta C33, Portenta H7, Portenta Machine Control, and Opta
paragraph=One-stop solution for using POSIX storage functions with SD cards and USB thumb drives with a unified API and without the need for separate libraries.
category=Data Storage
url=https://github.com/arduino-libraries/Arduino_POSIXStorage/
Expand Down
4 changes: 2 additions & 2 deletions src/Arduino_POSIXStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* - Portenta H7 with Portenta Breakout Board (SD Card and USB Thumb Drive)
* - Portenta H7 with Portenta Vision Shield (SD Card)
* - Portenta Machine Control (USB Thumb Drive)
* - Opta (USB Thumb Drive)
*
* After making changes:
*
Expand Down Expand Up @@ -67,7 +68,6 @@
#elif defined(ARDUINO_OPTA)
#include <Arduino_USBHostMbed5.h>
#include <BlockDevice.h>
#include <DigitalIn.h>
#else
#error "The POSIXStorage library does not support this board"
#endif
Expand Down Expand Up @@ -240,7 +240,7 @@ void deleteDevice(const enum StorageDevices deviceName, struct DeviceFileSystemC
// The USBHostMSD class for the H7 doesn't correctly support object destruction, so we only delete
// the device object on other platforms or if the device is an SD Card -->
bool deleteDevice = false;
#if (!defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_OPTA))
#if (!(defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_OPTA)))
(void) deviceName; // Silence -Wunused-parameter, because this variable is only used on the H7
deleteDevice = true;
#else
Expand Down
1 change: 1 addition & 0 deletions src/Arduino_POSIXStorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* - Portenta H7 with Portenta Breakout Board (SD Card and USB Thumb Drive)
* - Portenta H7 with Portenta Vision Shield (SD Card)
* - Portenta Machine Control (USB Thumb Drive)
* - Opta (USB Thumb Drive)
*
* After making changes:
*
Expand Down