@KurtE - @wwatson
Been playing with debug on and off most of the day (between chores) and think there is going to be one drawback. Let me explain.
I have been trying to debug why partitions are not working with the USB sticks. Have an idea but can not seem to find where it is the function is getting called from.
The sketch I am using is as follows;
#include <LibPrintf.h>
#include <Arduino_USBHostMbed5.h>
#include "MBRBlockDevice.h"
#include "FATFileSystem.h"
#include <errno.h>
USBHostMSD msd;
mbed::MBRBlockDevice part1(&msd, 1);
mbed::MBRBlockDevice part2(&msd, 2);
static mbed::FATFileSystem fs1;
static mbed::FATFileSystem fs2;
void setup() {
Serial.begin(115200);
pinMode(PA_15, OUTPUT); //enable the USB-A port
digitalWrite(PA_15, HIGH);
// put your setup code here, to run once:
while(!Serial);
Serial.println("Test diskio");
while (!msd.connect()) {
delay(1000);
}
Serial.println("done.");
Serial.print("Mounting USB device... ");
int err;
err = forcemountboth();
printf("forcemountboth %d\n", err);
FILE *f;
fopen("/fs1/hi.txt", "w+");
printf("fopen fs1 %p %d\n", f, errno);
if(!errno){
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);
}
}
err = fclose(f);
printf("fclose fs1 %d\n", err);
}
f = fopen("/fs2/hi2.txt", "w");
printf("fopen fs2 %p %d\n", f, errno);
if(!errno) {
err = fwrite("hello", 1, 5, f);
printf("fwrite fs2 %d\n", err);
err = fclose(f);
printf("fclose fs2 %d\n", err);
}
/*
Serial.println("Content of partition 1:");
printDirectory("/fs1");
Serial.println("Content of partition 2:");
printDirectory("/fs2");
*/
Serial.println("Unmounting partitions...");
fs1.unmount();
fs2.unmount();
}
void loop() {
digitalWrite(LED_BUILTIN,!digitalRead(LED_BUILTIN));
delay(1000);
}
void printDirectory(char* name) {
DIR *d;
struct dirent *p;
d = opendir(name);
if (d != NULL) {
while ((p = readdir(d)) != NULL) {
Serial.println(p->d_name);
}
}
closedir(d);
}
int mountboth() {
int err;
err = 0;
if (!err) {
Serial.println("partition 1 exists\n");
err = fs1.mount(&part1);
if (!err) {
Serial.println("FAT filesystem exists on partition 1");
}
} else {
Serial.print("ERROR: "); Serial.println(err);
Serial.println("Partition 1 not found");
return 1;
}
err = 0;
if (!err) {
Serial.println("partition 2 exists\n");
err = fs2.mount(&part2); // checkfor FAT filesystem
if (!err) {
Serial.println("FAT filesystem exists on partition 2");
}
} else {
Serial.println("Partition 2 not found");
return 1;
}
return 0;
}
int forcemountboth() {
int err = mountboth();
if (err) {
Serial.print("Mount both error: "); Serial.println(err);
while(1){}
}
}
When I insert the breakpoints on the fopen for instance it should show me what function is begin called and where like it would do if i put a breakpoint on print for instance but it doesn't. More than likely since there is no associated .cpp file since that stuff is all precompiled. All I see in the serial monitor is;
Test diskio
done.
Mounting USB device... partition 1 exists
FAT filesystem exists on partition 1
partition 2 exists
forcemountboth 0
fopen fs1 (nil) 19
fopen fs2 (nil) 19
Unmounting partitions...
Error code 19 I believe is
"FR_INVALID_PARAMETER" /* (19) Given parameter is invalid */