11 years, 8 months ago.

Strange SD card behavior

Hi mbed community,

My embed seems to 'crash' when I upload certain firmware. By crash I mean it ejects the disk (mbed connected trough usb).

I'm currently using a mbed for the LOAS Laser project, but I'm getting some strange behavior, which might be related to probably related the SD card. I'm probably using a NXP LPC1768. More about the LOAS Laser project: http://redmine.laoslaser.org/projects/laos/wiki. I have a old Rev 0.1that has worked fine and a newer Rev 0.3 version.

For the project they made a test firmware: http://redmine.laoslaser.org/projects/laos/wiki/TestFirmware Source: https://github.com/LaosLaser/Firmware/tree/master/iotest_board Bin: http://www.laoslaser.org/files/laos_iotest_board_LPC1768.bin

After connecting the mbed to my laptop trough usb and powering the laosboard inc the mbed I get a new disk. I can copy the test bin to here. Then I press the mbed reset button and it seems to program the mbed with the code. Using the Arduino IDE I get the following result:

LaOS Test program

++++++++++++++++++

Use these keys to test functionality

xX: X Step/Dir	yY: Y Step/Dir	zZ: Z Step/Dir	tT: Ext Step/Dir

e: Toggle Stepper enable

s: SD-Card

i: I2C

1/2/3/4: Outputs

xhome=1, yhome=1, zmin=1, zmax=1

I can send a s character to test the SD-card. When there is no SD card or it's a SD card it can't handle it gives:

No disk, or could not put SD card in to SPI idle state

When I insert one specific one it seems to work and it gives: <</code>>Testing IO board SD card: Write... Testing IO board SD card: Read... Result: 'bla bla ' <</code>>

This only works with one (the Emtec 2GB), of the four SD cards (all FAT formatted) I tried. /media/uploads/peteruithoven/img_0272.jpg

So now I try the regular firmware. Firm ware info: http://redmine.laoslaser.org/projects/laos/wiki/Firmware Source: https://github.com/LaosLaser/Firmware/blob/master/laser/ Bin: https://github.com/LaosLaser/Firmware/blob/master/laoslaser-29-12-2012.bin

I remove the SD card, I have the mbed connected trough usb, I remove the test firmware and give it the regular firmware. I have the Arduino IDE open on 115200 baud so I can listen to serial response. I disconnected all the cabled from the board except power supply. I press the mbed reset button. After a few blinks I get the response:

LaosDisplay()
Display() Simulation=ON, I2C Baudrate=9600
LAOS v0.3Dec 29 2012 15:52:17...
BOOT...
þTEST SD...
No disk, or could not put SD card in to SPI idle state
þSD NOT READY!

It keeps trying to connect and giving the same message. When I give it one of the SD cards that are somehow not supported it just gives the same message. When I give it the SD card that worked for the test firmware it gives:

LaosDisplay()
Display() Simulation=ON, I2C Baudrate=9600
LAOS v0.3Dec 29 2012 15:52:17...
BOOT...
þTEST SD...
SD: READY...

And then it for some reason ejects the disk (my os gives the warning that I didn't safely remove the disk). From then on I get nothing trough the serial connection. Not even after unpowering or pressing the mbed reset button. Until I give it the .bin again and than this just repeats.

When I remove the mbed from the laos board it doesn't communicate trough serial at all. I have no experience with mbed, so no clue why. (I do have quite some experience with Arduino's and several variations.

What's also good to know, this happens on both versions of the LOAS board. And the old version has actually worked for months.

So the big question, why this eject or crash? What could cause this? What can I try to get to the bottom of this?

The oldest firmware bin (laoslaser-12-08-2012.bin) does get further than SD: Ready...

posted by Peter Uithoven 13 May 2013

Somehow running the oldest firmware first and then uploading the latest seems to work.

posted by Peter Uithoven 13 May 2013

1 Answer

11 years, 8 months ago.

The relevant peice of code seems to be the following:

 printf("TEST SD...\n"); 
  FILE *fp = sd.openfile("test.txt", "wb");
  if ( fp == NULL )
  {
    mnu->SetScreen("SD NOT READY!"); 
    wait(2.0);
    mbed_reset();
  }
  else
  {
    printf("SD: READY...\n");
    fclose(fp);
    removefile("test.txt");
  }
  
  // See if there's a .bin file on the SD
  // if so, put it on the MBED and reboot
  if (SDcheckFirmware()) mbed_reset();
  
  mnu->SetScreen(VERSION_STRING);
  printf("START...\n");

mbed_reset() seems to run just fine when there is no SD card, so it might be something in SDcheckFirmware(). It doesn't get further because I never get the "START" print.

int SDcheckFirmware() {
    extern LaosFileSystem sd;
    DIR *d;
    struct dirent *p;
    d = opendir("/sd");
    if(d != NULL) {
        while((p = readdir(d)) != NULL) {
            if (strncmp(p->d_name, "longname.sy",11)) {
                if (isFirmware(p->d_name)) {
                    installFirmware(p->d_name);
                    return 1;
                }
            }
        }
    } else {
        printf("SDcheckFirmware: Could not open directory!\n\r");
    }
    return 0;
}