I am trying to interface an SD card with LPC1768 using SPI protocol.I am using File system middleware provided in ARM MDK which uses CMSIS SPI DRIVER API as the lowest layer to communicate with the hardware.The following code is to initialize and mount the memory card drive.It is expected to receive a fsOK status for successful mounting but instead, the fmount function doesn't return any status or error code and nothing happens, as far as switch case instruction is concerned.
What could be the problem ?
void init_filesystem (void) { stat1=finit("M0:"); if(stat==fsOK) { LPC_GPIO1->FIOPIN=0XFFFFFFFF; stat2==fmount("M0:"); switch(stat2) { case fsOK: LPC_GPIO2->FIOPIN=0X00000001; break; case fsError: LPC_GPIO2->FIOPIN=0X00000002; break; case fsNoMedia : LPC_GPIO2->FIOPIN=0X00000004; break; case fsNoFileSystem : LPC_GPIO2->FIOPIN=0X00000008; break; case fsNoFreeSpace : LPC_GPIO2->FIOPIN=0X00000010; break; case fsFileNotFound : LPC_GPIO2->FIOPIN=0X00000020; break; case fsDirNotEmpty: LPC_GPIO2->FIOPIN=0X00000040; break; case fsTooManyOpenFiles: LPC_GPIO2->FIOPIN=0X00000080; break; case fsUnsupported: LPC_GPIO2->FIOPIN=0X00000100; break; case fsAccessDenied: LPC_GPIO2->FIOPIN=0X00000200; break; case InvalidParameter; LPC_GPIO2->FIOPIN=0X00000400; break; case fsInvalidDrive : LPC_GPIO2->FIOPIN=0X00000800; break; case fsInvalidPath : LPC_GPIO2->FIOPIN=0X00001000; break; case fsUninitializedDrive : LPC_GPIO2->FIOPIN=0X00002000; break; \ case fsDriverError: LPC_GPIO2->FIOPIN=0X00004000; break; case fsMediaError : LPC_GPIO2->FIOPIN=0X00008000; break; } } }
I have added the default statement but the function must return a value from the status enum.Actually, the problem is whenever I insert the memory card and try to run the following initializing code,even the code statement after calling the fmount function doesn't work at all.And as soon as I remove the memory card and reset the controller with same code,switch case instruction of media error gets executed.
void init_filesystem (void) { stat1=finit("M0:"); if(stat==fsOK) { stat2==fmount("M0:"); LPC_GPIO1->FIOPIN=0XFFFFFFFF; switch(stat2) { case fsOK: LPC_GPIO2->FIOPIN=0X00000001; break; case fsError: LPC_GPIO2->FIOPIN=0X00000002; break; case fsNoMedia : LPC_GPIO2->FIOPIN=0X00000004; break; case fsNoFileSystem : LPC_GPIO2->FIOPIN=0X00000008; break; case fsNoFreeSpace : LPC_GPIO2->FIOPIN=0X00000010; break; case fsFileNotFound : LPC_GPIO2->FIOPIN=0X00000020; break; case fsDirNotEmpty: LPC_GPIO2->FIOPIN=0X00000040; break; case fsTooManyOpenFiles: LPC_GPIO2->FIOPIN=0X00000080; break; case fsUnsupported: LPC_GPIO2->FIOPIN=0X00000100; break; case fsAccessDenied: LPC_GPIO2->FIOPIN=0X00000200; break; case InvalidParameter; LPC_GPIO2->FIOPIN=0X00000400; break; case fsInvalidDrive : LPC_GPIO2->FIOPIN=0X00000800; break; case fsInvalidPath : LPC_GPIO2->FIOPIN=0X00001000; break; case fsUninitializedDrive : LPC_GPIO2->FIOPIN=0X00002000; break; \ case fsDriverError: LPC_GPIO2->FIOPIN=0X00004000; break; case fsMediaError : LPC_GPIO2->FIOPIN=0X00008000; break; default: LPC_GPIO->FIOPIN=OXFFFF0000; } }
And yeah, assigning problem is not there in the main code.
So why did you a second time post code containing == instead of = for the "assign"?
stat2==fmount("M0:");
Next thing - if you get an exception somewhere in the driver code then the processor will lock up and never return back to the switch statement.
Yeah, I guess fmount function is fetching some kind of exception.But the problem is am not having any kind of hardware debugger to know what kind of exception it is.How should I know about the exception ?
It's possible to write an exception handler that toggles an I/O pin to inform that an exception has happened.
But in your case, the first step is to verify if the execution returns from the function call.
The code statement after the function call doesn't get executed, so it seems like execution is being prompted by function call only. Can you please provide a headstart on writing an exception handler for this purpose ?
Note that your code doesn't convince me that the code after the call doesn't get called - have you made sure that the processor pins are outputs so your assigns really matters?
Your exception handler just needs to flip an I/O pin and then busy-loop. You should be able to manage that yourself.
Yes, I have made sure that controller pins are outputs.I haven't shown that part in this initialization function.
I will flip the I/O by myself.I just wanted to know the syntax of defining an exception handler.