6 years ago.

Runtime error when combine EthernetInterface and SD-Driver

I can write file to SD-CARD with SD-Driver only. It's work. I can receive IP Address from DHCP with EthernetInterface only. It's work. but when I combine 2 code, I have error on runtime.

RESULT: I can receive IP Address from DHCP normally, but I have an error from SD-Driver "Failure 5" /media/uploads/t2dear_ict/capture1.jpg

MY CODE

#include "mbed.h"
#include "FATFileSystem.h"
#include "SDBlockDevice.h"
#include <errno.h>
#include "EthernetInterface.h"

EthernetInterface net;
SDBlockDevice sd1(MBED_CONF_APP_SPI_MOSI, MBED_CONF_APP_SPI_MISO, MBED_CONF_APP_SPI_CLK, 
    MBED_CONF_APP_SPI_CS);

void return_error(int ret_val){
  if (ret_val)
    printf("Failure. %d\r\n", ret_val);
  else
    printf("done.\r\n");
}

void errno_error(void* ret_val){
  if (ret_val == NULL)
    printf(" Failure. %d \r\n", errno);
  else
    printf(" done.\r\n");
}
 
int main() {
    net.connect();
    
    FATFileSystem fs1("sd1", &sd1); 
    printf("Welcome to the filesystem example.\r\n");

    printf("Opening a new file, stampvalue.txt.");
    FILE* fd1;
    fd1 = fopen("/sd1/stampvalue.txt", "w+");
    errno_error(fd1);

    for (int i = 0; i < 20; i++){
        printf("Writing decimal stampvalue to a file (%d/20)\r", i);
        fprintf(fd1, "%d\n", i);
    }
    printf("Writing decimal stampvalue to a file (20/20) done.\r\n");
    printf("Closing file.\r\n");
    fclose(fd1);
    printf(" done.\r\n");
        
    net.disconnect();

    while(1) {  }
    
} 

NOTE: I use Nucleo F746ZG board, MbedOS-5, SD-Driver from https://github.com/ARMmbed/sd-driver/

/media/uploads/t2dear_ict/capture.jpg

Sorry for english language.

1 Answer

6 years ago.

Hi,

This is a known issue and it is due to a conflict between SPI and Ethernet pins on Nucleo_144 boards.

See here for more information: https://os.mbed.com/teams/ST/wiki/Nucleo-144pins-ethernet-spi-conflict

Regards