cancel
Showing results for 
Search instead for 
Did you mean: 

I'm using Shimmer 2r and I need to write on SD card using TinyOs and FatFS. I always get FR_DISK_ERROR when I try to open file; both if it exists and if it not. I tried to format SD: nothing change. How can I solve?

FManc.1
Associate II

This is my TestSD_C.ns file:

#define NEW_PRINTF_SEMANTICS

#include "printf.h"

#include "FatFs.h"

configuration TestSD_C {

}

implementation {

components MainC, TestSD_P;

TestSD_P -> MainC.Boot;

components FatFsP, diskIOC;

TestSD_P.FatFs -> FatFsP;

FatFsP.diskIO -> diskIOC;

FatFsP.diskIOStdControl -> diskIOC;

components new TimerMilliC() as Timer;

TestSD_P.Timer -> Timer;

components PrintfC, SerialStartC;

}

This is my SDTest_P.ns file:

#include "FatFs.h"

#include "Timer.h"

#include "printf.h"

module TestSD_P {

uses {

interface Boot;

interface FatFs;

interface Timer<TMilli> as Timer;

}

}

implementation{

FATFS fs;

FIL fp;

uint8_t mount;

uint8_t open;

void printError(uint8_t resWrite);

event void Boot.booted() {

call Timer.startPeriodic( 1000 );

mount = call FatFs.mount(&fs);

open = call FatFs.fopen(&fp, "test.txt", (FA_CREATE_ALWAYS | FA_WRITE | FA_READ));

}

event void Timer.fired(){

open = call FatFs.fopen(&fp, "test.txt", (FA_CREATE_ALWAYS | FA_WRITE | FA_READ));

printf("Mount: ");

printError(mount);

printf(" Open: ");

printError(open);

printf("\n");

printfflush();

}

async event void FatFs.mediaAvailable() {}

async event void FatFs.mediaUnavailable() {}

void printError(uint8_t resWrite){

if( resWrite == FR_OK )

printf( "OK" );

else if( resWrite == FR_INT_ERR )

printf( "FR_INT_ERR" );

else if( resWrite == FR_NOT_READY )

printf( "FR_NOT_READY" );

else if( resWrite == FR_INT_ERR )

printf( "FR_INT_ERR" );

else if( resWrite == FR_NO_FILE )

printf( "FR_NO_FILE" );

else if( resWrite == FR_INT_ERR )

printf( "FR_INT_ERR" );

else if( resWrite == FR_INVALID_NAME )

printf( "FR_INVALID_NAME" );

else if( resWrite == FR_DENIED )

printf( "FR_DENIED" );

else if( resWrite == FR_WRITE_PROTECTED )

printf( "FR_WRITE_PROTECTED" );

else if( resWrite == FR_INVALID_OBJECT )

printf( "FR_INVALID_OBJECT" );

else if( resWrite == FR_TIMEOUT )

printf( "FR_TIMEOUT" );

else if( resWrite == FR_DISK_ERR )

printf( "FR_DISK_ERR" );

else

printf( "ALTRO" );

}

}

1 REPLY 1
Eleon BORLINI
ST Employee

Hi @FManc.1​ , Shimmer 2r tool has a dedicated Support page, please refer to that one. Regards