I am working on file system middleware component to interface the SD card with lpc1768.I double checked all the resource requirements and configuraton of all the components required.Still, fmount function returns the fsMediaError and is unable to amount the memory drive.I have no clue of the issue. Can anyone please help me out on this ?
Am using the code given below to initialize and mount the sd card.
void sd_init(void) {fsStatus stat; SystemInit(); LPC_GPIO2->FIODIR=0XFFFFFFFF; printf ("Initializing and mounting enabled drives...\n\n"); /* Initialize and mount drive "M0" */ stat = finit ("M0:"); if (stat == fsOK) { stat = fmount ("M0:"); if (stat == fsOK) { LPC_GPIO2->FIOPIN=0xfffffff1; printf ("Drive M0 ready!\n"); } else if (stat == fsNoFileSystem) { /* Format the drive */ LPC_GPIO2->FIOPIN=0xfffffff2; printf ("Drive M0 not formatted!\n"); } else if (stat==fsMmediaError){ printf ("Drive M0 mount failed with error code %d\n", stat); LPC_GPIO2->FIOPIN=0xfffffff3; } } else { printf ("Drive M0 initialization failed!\n"); } printf ("\nDone!\n"); }
Hi, I am having what may be a similar issue, just moved over to keil from microelecktronika compiler and have working application but now i am trying to get to grips with keil.
SETUP: STM32F407VG, SD card connected to SPI3, CS connected to Port D Pin 3.
Used STM32CubeMX and selected SPI3 as Port c, pins 10, 11, 12. Set PD3 as GPIO Output. Clock is 25MHZ xtal and PLL to 150MHZ
RTX operating system, 1 Blinking task with an led connected to PB0 flashing every second. During this second i try and mount SD Card but it is failing with fsMediaError.
Have checked the card and its file system is ok, tried multiple cards and same result.
Also created function to set CS pin as shown
int32_t fs_mc_spi_control_ss (uint32_t drive_num, uint32_t ss){ if (ss==1) HAL_GPIO_WritePin(GPIOD,GPIO_PIN_3,GPIO_PIN_SET); else HAL_GPIO_WritePin(GPIOD,GPIO_PIN_3,GPIO_PIN_RESET); return ss; }
My writefile function is as below;
void WriteFile() { fsStatus st; if (finit("M0:") == fsOK) { st=fmount("M0:"); if (st == fsOK) HAL_GPIO_TogglePin(GPIOB,GPIO_PIN_1); ; } FILE *f=fopen("try.txt","a"); if (f!=NULL) { HAL_GPIO_TogglePin(GPIOB,GPIO_PIN_2); fprintf(f,"Test\n"); fclose(f); } }
The purpose of the toggle pins is to see if it worked.
I am not looking for someone to fix this but a pointer in the right direction would be really much appreciated.
Consider if the pin is active LOW
Yes, if you mean in the CS code, have tried both.
still no difference.
I am sure i am missing something silly, this has been puzzling me for about 70 hours at this point.
int32_t fs_mc_spi_control_ss (uint32_t drive_num, uint32_t ss){ if (ss==0) HAL_GPIO_WritePin(GPIOD,GPIO_PIN_3,GPIO_PIN_SET); else HAL_GPIO_WritePin(GPIOD,GPIO_PIN_3,GPIO_PIN_RESET); return ss; }
about ready to give up and continue on with the Mikroelektronika, where I have written FTP, HTTP, SD Card logging etc. Went to keil as I thought they had built in functions etc and I would like to use the RTOS.
I have probed with a scope and spi3 is not working, no clock signals etc. I am baffled and just dont know what to do.
I am wondering what fmount does before it starts up spi, as no matter if i set spi3 clock active high or low I do not get a signal on the clock line. always seems to be floating.
Any ideas?
The obvious place to start would be that the SPI3 peripheral clock is enabled, on the right APB, and that you have the pins correctly configured. So the AHB clock for the GPIO, and the Alternate Function of SPI3 selected.
Have tried all of this, just cannot get sd card to mount.
I have followed this app note http://www.keil.com/appnotes/files/apnt_273.pdf to the letter but still does not work on spi3.
Has anyone managed to get STM32F407VG working with SD card on spi3?
Likely to be very few in a hijacked LPC1768 thread.
I don't suppose SPI3 is magically different from SPI1 or SPI2 in this context. Try presenting the board/chip specific code, the devil is in the detail.