GigaR1 USB filewrite

using Arduino gigaR1 board, using the example of the file write for writing a data file into USB-A, the example code does not create the expected file on the USB-A, i.e., /usb/numbers.txt.
The example code works with Serial.print all numbers, and open() and fclose() work as shown from the Serial monitor.
compiling and downloading and code look work, just no text file was created on the USB
P.s. The example of FileReading works, it can read the Arduino.txt on the USB stick.
Does anyone know the problem with the file writing problem?
Thanks,
Jun

You're using the default example, nothing changed? Even if it's in the IDE, it's still advantageous to post your < CODE/> in the post too.

1 Like

from the library: Arduino_USBHostMbed5, an example of FileWrite, only change: while (!msd.connected()) to while (!msd.connect()),
No numbers.txt was created in the USB. although it looks like the code works.
Thanks

Below is the code
/*
Portenta - FileWrite

The sketch shows how to mount an usb storage device and how to
write a file, eventually overwriting the original content.

The circuit:

  • Portenta H7

This example code is in the public domain.
*/

#include <Arduino_USBHostMbed5.h>
#include <DigitalOut.h>
#include <FATFileSystem.h>

USBHostMSD msd;
mbed::FATFileSystem usb("usb");

// mbed::DigitalOut pin5(PC_6, 0);
mbed::DigitalOut otg(PB_8, 1);

void setup() {
Serial.begin(115200);
while (!Serial);
msd.connect();

while (!msd.connect()) {
//while (!port.connected()) {
delay(1000);
}

Serial.println("Mounting USB device...");
int err = usb.mount(&msd);
if (err) {
Serial.print("Error mounting USB device ");
Serial.println(err);
while (1);
}
Serial.print("read done ");
mbed::fs_file_t file;
struct dirent *ent;
int dirIndex = 0;
int res = 0;
Serial.println("Open /usb/numbers.txt");
FILE *f = fopen("/usb/numbers.txt", "w+");
for (int i = 0; i < 10; i++) {
Serial.print("Writing numbers (");
Serial.print(i);
Serial.println("/10)");
fflush(stdout);
err = fprintf(f, "%d\n", i);
if (err < 0) {
Serial.println("Fail :(");
error("error: %s (%d)\n", strerror(errno), -errno);
}
}

Serial.println("File closing");
fflush(stdout);
err = fclose(f);
if (err < 0) {
Serial.print("fclose error:");
Serial.print(strerror(errno));
Serial.print(" (");
Serial.print(-errno);
Serial.print(")");
} else {
Serial.println("File closed");
}
}

void loop() {
delay(1000);
// handle disconnection and reconnection
if (!msd.connected()) {
msd.connect();
}
}

I've moved your topic to the dedicated Giga R1 category; I hope it gets the attention of the right people.

1 Like

Thanks,
but where is the "dedicated Giga R1 " category?
It looks this is in the Giga R1 category.

Now it is as I moved it there :wink: It's a subcategory of Hardware.

Anyone run the example "FileWrite" of Arduino_USBHostMbed5 on Arduino Giga R1 WIFI?

It just does not generate a file to write in it in USB. the code works after change:
while (!msd.connected()) to while (!msd.connect()).

The examples"FileRead" and "DirList" both work.

Thanks,

I have merged your cross-posts @jzhao.

Cross-posting is against the Arduino forum rules. The reason is that duplicate posts can waste the time of the people trying to help. Someone might spend a lot of time investigating and writing a detailed answer on one topic, without knowing that someone else already did the same in the other topic.

Repeated cross-posting can result in a suspension from the forum.

In the future, please only create one topic for each distinct subject matter. This is basic forum etiquette, as explained in the "How to get the best out of this forum" guide. It contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

1 Like

Hi, can you try adding this section to your sketch?

void setup(){
  pinMode(PA_15, OUTPUT); //enable the USB-A port
}

void loop(){
  digitalWrite(PA_15, HIGH); //write a high state
  //digitalWrite(PA_15, LOW); //write a low state
}

For more details on this, check the USB feature guide

We tried the example again from our end,

  1. Format the USB
  2. USB should be in FAT32 format.
  3. Add the following session to the sketch
void setup() {
  Serial.begin(115200);
  
  pinMode(PA_15, OUTPUT); //enable the USB-A port
  digitalWrite(PA_15, HIGH);
  
  while (!Serial);

For more details on this, check the USB feature guide

The USB is FAT32 format, The ReadFile and DirFind examples work, the WriteFile example does not work, the code looks work, The file to write in the USB is normally closed as the serial monitor ouput indicated, but, no File is generated in the USB.
Thanks

Yes, after these codes were added in, the ReadFile works , but writeFile example does not work.

The light on USB always flashing, it looks try to make communication, but, no text file is generated in the USB. as said, it can read a text file from the USB using the FileRead example.
Thanks for any clues for solving the problem.

This is interesting, we tried the example again from our end and confirmed it works. We used the example directly from the USB feature guide, that I shared above. Do you get any output in the serial monitor after uploading the sketch?

yes, get out in the serial monitor, and the code looks run well by showing the file is closed from the serial monitor, but, not text file was generated in the USB.

Can you get in contact with us directly through the contact us form?
We would like to understand more on the setup and exact steps to recreate the issue. From our we tried and we were able to get the sketch working with folder created in the USB. The steps we followed was shared above already.

Thanks,

sent the form in Contact, as requested.

Is it possible the problem is related to the non-USB 2.0 format, or Arduino IDE 2.0, or Mac-Pro 2017? tried a few USB, same problem, do not know they are USB 2.0 or others. but, the FileRead and Dirlist examples work fine.

Have you tried this example on a different computer and maybe with a different USB stick (FAT32 format) by any chance?

not tried other computers because I have no computer with USB-C connection,
Tried other USB-A stickers, same problem.

Ummm.. The circuit says it uses a Portenta H7……