Unable to delete a file using SD library

Status
Not open for further replies.
I've been trying to delete a file if a version number doesn't match. Below is a part from the code (link to github below):

Code:
#include <SD.h>

...

const char CONFIG_FILE[] = "CONFIG.CFG"; 
const uint8_t HEADER_VERSION = 1;

configFile = SD.open(CONFIG_FILE, FILE_WRITE);

...

  if (configFile)
  {
    DEBUG_PRINTLN("CONFIG Present.");

    configFile.seek(0);

    // Check for version
    configFile.readStringUntil(',');
    int version = configFile.readStringUntil('\n').toInt();
    if (version < HEADER_VERSION)
    {
      // Wrong version, create new file
      DEBUG_PRINTLN("Too old version, recreating file...");
      SD.remove(CONFIG_FILE);
      //SD.remove("CONFIG.CFG");

...

For some reasons, I have the following error message when compiling:
Code:
.pio\build\teensy31\src\main.cpp.o: In function `initConfig()':
main.cpp:(.text._Z10initConfigv+0x116): undefined reference to `SDClass::remove(char const*)'

I tried changing the variable types without success. Even the commented line doesn't work.

Here is my current set-up:
 
@woodencase01 - I am not sure why you are getting the compile time error as I have not used PlatformIO yet. Compiling the SD example 'Files.ino' which includes SD.remove() compiles without error using the Arduino IDE 1.8.12 and TD 1.52 beta 2. The one thing I did see was you did not close the file before you tried to use SD.remove(). This might be a problem. Try configFile.close() first. Then use SD.remove("CONFIG.DAT") and see if that works.

Good luck.
 
Thanks for your reply.

I'm running TD 1.51 as of platform-teensy 4.8.0

I get the same error from the file.ino example.

Something looks weird however, SD.open and SD.exists come from dir_t3.cpp, while SD.remove comes from SD.cpp
SD.remove is grayed out due to the "#ifndef __SD_t3_H__"
Could that be the reason?
 
I started this reply earlier then got distracted an hour or so ... matches the above crossposting. Something is wrong with the include chain and library usage it seems in the build environment. PIO never used here - but the IDE/TD install CMDLine triggered from my editor of choice works to run the tested build environment.

IIRC looking at gihub code … This code is using the AUDIO library - that may be causing the confusion as it uses SD lib as well?

What happens if "#include <SD.h>" is removed from main.cpp? Does the Audio.h drag in its copy?

Odd - if the right version of the SD lib is in use it seems like it should work based on example - there "file.txt" version works :: ...\hardware\teensy\avr\libraries\SD\examples\Files\Files.ino
Code:
  // delete the file:
  Serial.println("Removing example.txt...");
  SD.remove("example.txt");

At runtime it might be good to do this before remove():: configFile.close();
 
Last edited:
@woodencase01 - I may be wrong here but make sure you have not uncommented line 37 in SD_t3.h.
Code:
// This Teensy 3.x optimized version is a work-in-progress.
//
// Uncomment this line to use the Teensy version, which completely replaces
// all of the normal Arduino SD library code.  The optimized version is
// currently read-only.  It CAN NOT WRITE ANYTHING TO YOUR SD CARD.  However,
// it is *much* faster for reading more than 1 file at a time, especially for
// the Teensy Audio Library to play and mix multiple sound files.
// On Teensy 3.5 & 3.6, this optimization does NOT SUPPORT the built-in SD
// sockets.  It only works with SD cards connected to the SPI pins.
//
[COLOR="#FF0000"]//#define USE_TEENSY3_OPTIMIZED_CODE[/COLOR]

Based on this:
Code:
#if !defined(__SD_t3_H__) && defined(__arm__) && [COLOR="#FF0000"]defined(USE_TEENSY3_OPTIMIZED_CODE[/COLOR])
#define __SD_t3_H__
#define __SD_H__

It seems to pull in a read only situation. With it commented out it just uses 'SD.h' which looks like it is using the SDFat filesystem. If I am correct:)
 
Thaks for your help, you pointed me in the right direction.

While tinkering with the WAV player, I uncommented the following code:
Code:
//#define USE_TEENSY3_OPTIMIZED_CODE
in SD_t3.h

This is what's causing problem.
I remember reading about this define, where it would prevent to write to SD when it is activated, thus explaining why the function remove wouldn't work!
 
@woodencase01 - Glad you got it working. Hopefully you are on to bigger and better things:)
Thanks
 
Status
Not open for further replies.
Back
Top