I'm making a datalogger based around the STM32F405 microcontroller that logs all CANbus traffic onto a micro SD card, but the function File.write() stops being able to write after seemingly random amounts of time

I'm programming this microcontroller using STM32duino, basically treating it as the new Adafruit Feather STM32F405 (since it's the same microcontroller)

I've got it printing out the result of File.write() whenever it tries to write and every time I run the program, it eventually just starts returning 0 when it stops being able to write to the SD card. My question is why?

I'm relatively sure it's not a RAM issue because even after it stops writing the program still runs just fine (other than not being able to write obviously) but it very well could be since I don't have much of a way to actively monitor RAM usage.

Here is the whole code. All the CAN bus handling I did not write, my code starts at "uint8_t insertStr(uint8_t index, char* b1, char* b2)"

Edit by admin: posted the code on Pastebin, rather than a huge chunck here, which possible might freeze the browser (?)
https://pastebin.com/Z3291wCf

If anyone has any insights I would love to hear them. Been banging my head against this problem for the better part of 2 days. Thank you!
*bump*

I've not been able to figure anything new out since I first posted.
If anyone's got any insight or have had a similar problem, please let me know
With absolutely no knowledge of the underlying system, is it possible there's a buffer that's getting full and needs to be flushed to disk? I see you have a flush, but not where you're getting the assumption that the buffer is at least 2KB:

Code:
        if(dataFile.size() - oldFileSize > 2000) { //Write to SD card before unwritten data becomes too large
          digitalWrite(PA7, HIGH); //indicate that we're writing to the SD card
          dataFile.flush();
          digitalWrite(PA7, LOW);
          oldFileSize = dataFile.size();
        }
I have tried buffer sizes as small as 64 and still no dice.
To be clear, it's not that it doesn't write to the card, it usually goes through a few cycles of filling and flushing whatever buffer size I set before it randomly stops being able to write and even read from the card.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are GMT - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement