cancel
Showing results for 
Search instead for 
Did you mean: 

FR_NO_FILESYSTEM ,FatFs,4-pins SDcard with Nucleo-L476RG

anna23
Associate II

Posted on February 22, 2017 at 09:18

Hey all,

I want to write to SD card, I'm Using cube-mxstm32Nucleo-L476RG MCU ,and 4-pin SD card,

I attach my cube project, the main program has the following code:

declaring and init :

FATFS SDFatFs;

FIL MyFile;

extern char SD_Path[4]; /* SD logical drive path */

/* USER CODE END 0 */

int main(void)

{

/* USER CODE BEGIN 1 */

FRESULT res;

uint32_t byteswriten,byteread;

uint8_t wtext[]='Hello from STM32!!\0';

/* USER CODE END 1 */

/* MCU Configuration----------------------------------------------------------*/

/* Reset of all peripherals, Initializes the Flash interface and the Systick. */

HAL_Init();

/* Configure the system clock */

SystemClock_Config();

/* Initialize all configured peripherals */

MX_GPIO_Init();

MX_DMA_Init();

MX_DFSDM1_Init();

MX_SDMMC1_SD_Init();

MX_FATFS_Init();

MX_TIM6_Init();

MX_SDMMC1_SD_Init();

I am trying to write to sd card by the following code:

if(res=f_mount(&SDFatFs,(TCHAR const*)SD_Path,0)!=FR_OK)

{

Error_Handler();

}

else

{

if(res=f_open(&MyFile,'0:/mywrite.txt',FA_CREATE_ALWAYS | FA_WRITE ) != FR_OK)

{

Error_Handler();

}

else

{

res=f_write(&MyFile,wtext,sizeof(wtext),(void*)&byteswriten);

if((byteswriten==0) || (res!=FR_OK))

{

Error_Handler();

}

else

{

HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_SET);

}

f_close(&MyFile);

}

}

I get FR_NO_FILESYSTEM if the SD is connected and if the SD is not connected, I get FR_NOT_READY,

Thanks for any help.

Note: this post was migrated and contained many threaded conversations, some content may be missing.

This discussion is locked. Please start a new topic to ask your question.
14 REPLIES 14
Posted on May 16, 2018 at 14:02

The stm32_adafruit_sd.c code in the HAL trees should support SDHC/XC (>= 4GB) cards via SPI. The larger cards use a slightly different command/protocol to address the blocks on the media.

STM32Cube_FW_F4_V1.19.0\Drivers\BSP\Adafruit_Shield\stm32_adafruit_sd.c

I've used this code on NUCLEO boards to support MicroSD cards. I don't have the shield but wired the socket using equivalent pins.

FatFS should support FAT32 volumes with usually settings, for >=64GB media you'd want to enable EXFAT support

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on May 16, 2018 at 14:22

i am using stm32f103ze controller,in my code option is their for fat32 operation,i dont know why it is not working for 8gb card,so if u have any fat technical specifications pdf or fat tutorial can u send me.

                                                                                                                                          THANKS FOR THE HELP

Posted on May 16, 2018 at 15:18

It's not working because the SPI-SD code you are using only supports SD cards, the SDHC and SDXC cards use a slightly different protocol, and are not compatible with code that only uses the old protocol.

The SPI code I have cited supports BOTH class of cards, you'll need to use that as the basis for your own solution.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on May 17, 2018 at 07:10

thanks clive,i need a site for entire project for accesing sd card using spi + fat32 for stm32103zc controller.if u have that info plz share it.

Posted on May 21, 2018 at 13:32

Hi Clive One,

I AM WRITING DATA TO WORD DOCUMENT AND EXCEL DOCUMENT USING SD+SPI+FAT DRIVER,BUT IN EXCEL DOCUMENT ,ALL THE DATA(40KB) IS GETTING STORED IN FIRST BLOCK ONLY,HOW TO CHANGE THE BLOCK TO STORE DATA BY INCREMENT ROW AND COLUMN.

THANK YOU

Announcement

We’re moving the ST Community to a new platform to give you a better and more reliable community experience.