Storage Method with FATFileSystem

Hi all,
I’m working on a device made by a portenta h7 that can be controlled remotely via wifi. I am able to record more data buffers at a frequency of 0.5kHz more or less. I am using mbed library but cannot store those buffers in the sd at an idle speed. Let’s say that if I record 30 sec at 500Hz, then I need about 300 seconds to save them.
My template is like this:

#include "SDMMCBlockDevice.h"
#include "FATFileSystem.h"
SDMMCBlockDevice block_device;
mbed::FATFileSystem fs("fs");
#include <SDRAM.h>
SDRAMClass mySDRAM;
unsigned long j = 1; unsigned long k = 0;
float *Data;
char output[10];
void setup() {
  /****  SETUP SD  ****/
  _UART_USB_.println("Mounting SDCARD...");
  int err =  fs.mount(&block_device);

  if (err) {
    _UART_USB_.println("No SD Card filesystem found, please check SD Card on computer and manually format if needed.");
    //int err = fs.reformat(&block_device);  // seriously don't want to format your good data
  }
  else {
    _UART_USB_.println(" SDCARD ready");
  }
  mySDRAM.begin(SDRAM_START_ADDRESS);
  Data = (float*)SDRAM.malloc(0.5 * 512 * 1024);
}

void loop() {
  //Phase of recording: fulfill Data at 500Hz

  //save it
  for (k = 1; k <= j - 1; k++)
  {
    _UART_USB_ .print("J: "); _UART_USB_ .print(k);  _UART_USB_ .print(" , ");
    _UART_USB_ .print("Space: "); _UART_USB_ .print(Data[k]);  _UART_USB_ .print(" \n ");
    sprintf(posiz, "%.2f", Data[k]); strcat(posiz, "\n ");
    const char* nomeid = myFileName.c_str();
    FILE *myFile = fopen(nomeid , "a");
    //                fwrite(&Data[k], 10, len, myFile);
    fprintf(myFile, posiz);
    fclose(myFile);
    _UART_USB_.println(j);
  }
  _UART_USB_.println("Saved");
}

Can someone give me some tips to improve the storage method? Thanks to all

Hello,

I’m not sure I understand your description, but all the code around is just a slowdown, I think.

void loop() {
  //Phase of recording: fulfill Data at 500Hz

  _UART_USB_.println("Save it");
  const char* nomeid = myFileName.c_str();
  FILE *myFile = fopen(nomeid , "a");
  for (k = 1; k <= j - 1; k++)
  {
    //_UART_USB_ .print("J: "); _UART_USB_ .print(k);  _UART_USB_ .print(" , ");
    //_UART_USB_ .print("Space: "); _UART_USB_ .print(Data[k]);  _UART_USB_ .print(" \n ");
    //sprintf(posiz, "%.2", Data[k]); strcat(posiz, "\n ");
    //fwrite(&Data[k], 10, len, myFile);

    fprintf(myFile, "%.2\n", Data[k]);

    //_UART_USB_.println(j);
  }
  fclose(myFile);
  _UART_USB_.println("Saved");
}

Open/CLose just once and formatting could be done directly in fprintf.

BR, Jan

Yes you re right, I just did it but I forgot to modify it. Anyway, opening and close the file outside of for loop doesn’t change the speed as I want. It is very slow. It needs 40 seconds more or less to store 1 sec of recording.

Did you try change SPI frequency? Default is 1Mhz after init.
The speed is also affected by the SD card itself.

BR, Jan