Sd card unmonted after spi.begin ( rfid and tft incompatibility )

Hi, I am facing a problem when using the hardware : esp32, rfid reader and a tft display with an sd card reader builtin. The rfid demands the use of the spi, and it seems internally the sd card also uses it, the problem is that when we enable it the sd card unmounts, example :

#include <SPI.h>
#include <FS.h>
#include <SD.h>
#include <TFT_eSPI.h>
#include <MFRC522.h>
#include <JPEGDecoder.h>  // JPEG decoder library
MFRC522 rfid(21, 4);
MFRC522::MIFARE_Key key;
TFT_eSPI tft = TFT_eSPI();

void setup() {
  Serial.begin(115200);

  digitalWrite(22, HIGH); // Touch controller chip select (if used)
  digitalWrite(TFT_CS, HIGH); // TFT screen chip select
  digitalWrite( 5, HIGH); // SD card chips select, must use GPIO 5 (ESP32 SS)
  tft.begin();

  if (!SD.begin(5, tft.getSPIinstance())) {
    Serial.println("Card Mount Failed");
    return;
  }  

  doFile( "/lena20k.jpg" );     
  delay(4000);

  SPI.begin(); // <<<------- after this line, the sd card is unmounted for some reason :(

  doFile("/lena20k.jpg");     
  
}

void doFile( const char *filename ) {
  File jpegFile = SD.open( filename, FILE_READ);  // Open the named file (the Jpeg decoder library will close it) or, file handle reference for SD library
  if ( !jpegFile ) { 
    Serial.print("ERROR: File \""); Serial.print(filename); Serial.println ("\" not found!");
  } else {
    Serial.print("File found :\""); Serial.println(filename); 
  }
}

void loop() { }

Did anyone face something like this ? And have a solution other then reading everything you need and put in memory ?

Adding the log for clarification :

File found :"/lena20k.jpg
ERROR: File "/lena20k.jpg" not found!

You should select a different SS pin for either the SD card reader or the RFID reader (I would go for the SD card reader, since it would be easier. Use anything other than 5 when initializing the SD card reader). When using the same SS pin for 2 devices, you'll get an undefined behavior (since 2 modules would be selected at the same time). That's how SPI works...

Very many varieties of hardware there, some of which may be incompatible.

If you do want help provide details or links to all the hardware devices you are using, and of course a schematic showing how you have it all connected.

Hi, thanks for the awser, the display is the ILI9488 SDCARD, it seems to be an requirement of this sdcard to use the select pin 5. The rfid is the Mfrc, its using the rst pin 4, miso=19, mosi=23, sck=18, sda=21, how can I swap selection ? I tried to look into its datasheat and I could not find anything about chip selection on this, so I am not sure its using the same pin...

I am not sure I am using the same pin... For the sdcard, its seems to be an requirement to use the SS 5, but for the rfid reader, I am not sure, I could not find anything about the SS pin in this, its the Rfid Mfrc522 Mifare, it dosent seems to have an SS pin...

What is the purpose of this line? The SPI has already been initialized by this point by either the TFT or SD libraries.