Skip to main content
Visitor II
February 9, 2012
Question

SDIO and SD fat access example?

  • February 9, 2012
  • 82 replies
  • 16079 views
Posted on February 09, 2012 at 01:06

Hi Chaps,

Going slowly mad trying to get Chan Fat working with the sdio libs on a stm32f4.

I'm using the most recent (1.0.0) library for the F4, and the low level access demo within that library builds and (at least appears to ) work OK. 

I've spent many, many hours attempting to patch in 0.9 version of fatfs from chan (thks chan, you're a hero) - but I can't get it to work.

If possible, I'd really really appreciate a demo project/source (or direction to - though I've scoured the web and can't find anything that works!)

I'll post separately about the current problems I'm having with the my current build, but a working example would sort it.

Many thanks,

nat.

#hse-sdio-stm32 #stm32-fat-chanfat-fatfs-sdio #sdcard-stm32f4-sdio-fatfs #sdcard-stm32f4-sdio-fatfs
    This topic has been closed for replies.

    82 replies

    Graduate II
    June 8, 2015
    Posted on June 08, 2015 at 18:18

    The DISCO boards use an 8 MHz source, the EVAL boards typically used 25 MHz

    The comments are not where the clocks are actually defined.

    /* PLL_VCO = (HSE_VALUE or HSI_VALUE / PLL_M) * PLL_N */
    #define PLL_M 25 // For 25 MHz source, to 1 MHz comparison frequency
    #define PLL_N 336
    /* SYSCLK = PLL_VCO / PLL_P */
    #define PLL_P 2 // 168 MHz (336/2)
    /* USB OTG FS, SDIO and RNG Clock = PLL_VCO / PLLQ */
    #define PLL_Q 7 // 48 MHz (336/7)

    Visitor II
    June 8, 2015
    Posted on June 08, 2015 at 20:29

    these are the values in my system_stm32f4xx.c file. The last row in the  table in the comparison. mentions the sdio, usb is disabled. what do I need to do to make it enable ? 

    Graduate II
    June 8, 2015
    Posted on June 08, 2015 at 20:48

    these are the values in my system_stm32f4xx.c file. The last row in the  table in the comparison. mentions the sdio, usb is disabled. what do I need to do to make it enable ? 

    Use the diff tool and look at where the PLL defines are used. I'm pretty sure setting the Q tap is sufficient. Look at where it's programming the RCC registers, and review the Reference Manual for additional detail.

    If you're concerned about the internal clocks, output them via the MCO pins are review with a scope.

    Make sure that HSE_VALUE within the project matches crystal frequency you are using. All the other peripheral clocks come off the APB buses, these should all work irrespective of the SDIO (48 MHz) clock.

    I'm not going to try and second guess what's going on based on the software/hardware I don't have.
    Visitor II
    June 9, 2015
    Posted on June 09, 2015 at 07:25

    see below memory if three first registers CR, PLL_CFGR, RCC_CFGR after init.

    The when the pll is on the sdio works fine. but the usart6 is gone.

    after system_stm32f4xx.c startup, sdio work fine( it seems pll is on 03 0x40023803) usart not working

    Address   0 - 3     4 - 7     8 - B     C - F

    40023800  83840303  19544007  0A940000  00000000

    after calling hse turn on -  pll is off, sdio not working usart6 working

    Address   0 - 3     4 - 7     8 - B     C - F               

    40023800  83840300  10300024  0000000  00000000

    Visitor II
    June 9, 2015
    Posted on June 09, 2015 at 08:12

    Now I realize when the pll is on source of uart clock is somehow changed. I checked with scope. before pll configuration 115200 baud = 8.68us per bit. After 115200 baud is ~26us bit. is there a way to reconfigure to work ?  

    ~26us per it is not standard baud rate. what can I do ?

    Visitor II
    June 9, 2015
    Posted on June 09, 2015 at 09:33

    Hi Clive,

    You've mentioned the sd card performance as below

    51200 Bytes, 471825 Cycles

    13.021777 MBps Read

    I'm little confused about the term ''Cycles'' ,, Does it mean you read 51200 bytes 471825 times ? or is there any other meaning is there?

    You'll need Skype Credit

    Free via Skype

    Visitor II
    October 30, 2015
    Posted on October 30, 2015 at 06:42

    https://docs.google.com/open?id=0B7OY5pub_GfIa2k2MmFzelZFR1U

    Hi ,

     I am trying to write SD card at raw level using STM32F4. I  don't know whether it is possible and where to begin. Can you please help me?

    Graduate II
    October 30, 2015
    Posted on October 30, 2015 at 13:05

    I am trying to write SD card at raw level using STM32F4. I  don't know whether it is possible and where to begin.

    Bit puzzling then as to why you'd need to do that.

    The Raw IO functions exist below the FatFs implementation. You can read/write single sectors, or multiple sectors, from the media, just like any other block storage device.

    STM32F4xx_DSP_StdPeriph_Lib_V1.5.1\Project\STM32F4xx_StdPeriph_Examples\SDIO\SDIO_uSDCard

    Graduate II
    October 30, 2015
    Posted on October 30, 2015 at 13:14

    I'm little confused about the term ''Cycles'' ,, Does it mean you read 51200 bytes 471825 times ? or is there any other meaning is there?

    Machine Cycles are my unit of time measurement. For a processor running at 168MHz, Seconds = Cycles / 168,000,000

    Depending on how I've configured the software, you're looking at a 32768000 byte file, accessed a 1000 sequential 32768 byte blocks.

    You'll need Skype Credit

    Free via Skype

    Visitor II
    September 19, 2016
    Posted on September 19, 2016 at 22:52

    If I closed a file and then reopen it, I cannot write more data to it after reopening it, but if i keep it open i can write as many lines as i want then close it after i am finished writing. Does anyone have a similar issue withe ELM Chang's FATFS?

    See the example below. Thanks. if (f_mount(&FatFs, '''', 1) == FR_OK) { f_mkdir (''TEST''); count = 0; while(count < 200){ if(f_open(&fil, ''TEST/test.txt'', FA_OPEN_ALWAYS | FA_WRITE) != FR_OK){ break; } else{ sprintf(array,''This is file entry number: %d '',count); f_puts(array, &fil); if(f_close(&fil) != FR_OK){ break; } } count++; } f_mount(0, '''', 1); }

    http://stackoverflow.com/questions/39560704/elm-changs-fatfs#

    If I close a file and then reopen it, I cannot write more data to it after reopening it, but if i keep it open i can write as many lines as i want then close it when i am finish writing. See the example below. Thanks.

    if (f_mount(&FatFs, '''', 1) == FR_OK) { f_mkdir (''TEST''); count = 0; while(count < 200){ if(f_open(&fil, ''TEST/test.txt'', FA_OPEN_ALWAYS | FA_WRITE) != FR_OK){ break; } else{ sprintf(array,''This is file entry number: %d
    
    '',count); f_puts(array, &fil); if(f_close(&fil) != FR_OK){ break; } } count++; } f_mount(0, '''', 1);}