Gsm shield and SD card

Hello I need some help.

I have a Arduino Ethernet and an Arduino Gsm shield, the official one.
I am trying to start the gsm shield, after the SD card and create a file on the sd card, but it blocks.
Can you check what is wrong on this code/

Thank you.

////////////////////////////////////////////////////////////////////////////////
///////////////////// Library and initializations //////////////////////////////
////////////////////////////////////////////////////////////////////////////////
#include <GSM.h>
#include <SD.h>

GSM gsmAccess;
GSMVoiceCall vcs;
GSM_SMS sms;

GSM3ShieldV1DirectModemProvider modemAccess;

char charbuffer[20];

////////////////////////////////////////////////////////////////////////////////
///////////////PIN Number of the SIM card, phone numbers and SMS////////////////
////////////////////////////////////////////////////////////////////////////////

#define PINNUMBER ""

File myFile;
/////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////

void setup()
{
  Serial.begin(9600);
  Serial.println("Network TEST");
  start_gsm();
  Serial.println("---------------------------------------------------");
  start_sd();
  creat_file();
  Serial.println("DATA.txt created");

}

void loop()
{
}

void start_gsm()
{
  Serial.println("Waiting for the GSM Shield...");
 
  boolean notConnected = true;
    while(notConnected)
  {
    if(gsmAccess.begin(PINNUMBER)==GSM_READY)
      notConnected = false;
    else
    {
      Serial.println("Not connected");
      delay(1000);
    }
  }
  
  Serial.println("GSM Shield initialized");
}


void start_sd()
{
    Serial.print("Initializing SD card...");
  
  pinMode(10, OUTPUT);
   
  if (!SD.begin(4)) {
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization done.");  
}
  

void creat_file()
{
   //Creat the new file  
  Serial.println("Creating DATA.txt...");
  myFile = SD.open("DATA.txt", FILE_WRITE);
  myFile.close();
  Serial.println("DATA.txt is created");
}

sometimes give me this:

øøøøNetwork TEST
Waiting for the GSM Shield…
GSM Shield initialized

Initwwwww???ýØ?}µLõâ

I cannot help you but would like to know if you make it work as I would also like to use Arduino Ethernet + GSM shield.

It appears you may be running out of SRAM. The symptoms could range from garbage on the serial monitor to a reboot of the Arduino.

Try adding this function and call it before calling each device setup function.

int freeRam() {
  extern int __heap_start,*__brkval;
  int v;
  return (int)&v - (__brkval == 0 ? (int)&__heap_start : (int) __brkval);  
}

edit: Then use it like this:

Serial.print(F("Free RAM: "));
Serial.println(freeRam());

It will not show zero if you run out of SRAM. It will show a negative or an unrealistic large value.

Can you test the code? It start to loop.