SD CARD using SPI in STM32 || Cube-IDE || File handling || uart

Поделиться
HTML-код
  • Опубликовано: 21 янв 2025

Комментарии • 320

  • @aricrowe2887
    @aricrowe2887 4 года назад +4

    Great video, thank you so much for your help! As other users have mentioned, if using an stm32f0 discovery board, make sure to set the spi data size to 8 bits. I also ran into a error where I could not build my project with a max sector size of 4096 (too large) so I changed it to 2048 and it worked fine.

    • @sharanrv
      @sharanrv 4 года назад

      Hey! Are you using STM32F051 Board?

  • @jamestroup417
    @jamestroup417 4 года назад +2

    Awesome tutorial. I can confirm that this works on clone chip CS32F103 Bluepill board using 32Gig Transcend SD card . Thank you Controllers Tech for your hard work.

  • @dtonn
    @dtonn 2 года назад +1

    Valeu!

  • @golfercab7323
    @golfercab7323 4 года назад +2

    This helped a lot, thank you for the detailed walk-through!!!

  • @НикитаЩербаков-ж3х
    @НикитаЩербаков-ж3х 4 года назад +1

    Thank you very much for your initiative. The only sensible code that I found after a long time of searching. But in the beginning there was a problem: the program did not always work. In the end, the whole problem was in SPI1. After connecting the microsd module to SPI2, the program always worked. I'm using stm32f4discovery (stm32f407vg microcontroller).

    • @НикитаЩербаков-ж3х
      @НикитаЩербаков-ж3х 4 года назад

      By the way, I connected the sandisk 16gb fat32 memory card and the program worked.

    • @erdinckaya3731
      @erdinckaya3731 2 года назад

      @@НикитаЩербаков-ж3х I'm using the same item.I didnt get it worked. Could you tell me what was the error ? Are you also sure that it's all about SPI1 ?
      Thanks in advance..

  • @divanbessinger6899
    @divanbessinger6899 3 года назад +1

    Thanks for the video! I had to keep the MAXX_SS at 512 for my SDHC 16GB SanDisk to work.

  • @ibrahimkhadraoui7736
    @ibrahimkhadraoui7736 5 лет назад +2

    Thank you very much the best tutorials for stm32 in RUclips

  • @lauchokyip
    @lauchokyip 5 лет назад +2

    Great Video! Some boards set SPI to 4 bits ( hspi1.Init.DataSize = SPI_DATASIZE_8=4BIT). I changed it to ( hspi1.Init.DataSize = SPI_DATASIZE_8=8BIT). Btw I am using STM32F0Discovery Kit

    • @saikrishnakaruturi2958
      @saikrishnakaruturi2958 Год назад

      Hey are you able to read the file on the SD card using the STM32f0 series board?

  • @mukulsharma-no4uf
    @mukulsharma-no4uf Год назад +1

    Hello @ControllersTech I'm using the same MCU and same IDE as in your video, but my code gets stuck at HardFault_Handler(void) when i try to open a file. how to solve it?

  • @MrEdwardhartmann
    @MrEdwardhartmann 3 года назад

    Nice video - I am planning a project to take sound files (.wav) from a SD card and output to I2s on a STM32F411 and I have never used Cube to program. This looks like a great starting point - thanks for all the work.

    • @ControllersTech
      @ControllersTech  3 года назад +1

      Better watch the wave player video.
      That's exactly what's done in that.

    • @MrEdwardhartmann
      @MrEdwardhartmann 3 года назад

      @@ControllersTech thanks - I will

  • @Eckmuhl29
    @Eckmuhl29 2 года назад

    4:05 where do have those libraries? I dont get it

    • @ControllersTech
      @ControllersTech  2 года назад

      Download the code and look in the src and inc folders.

  • @ShawnHymel
    @ShawnHymel 4 года назад +5

    Thank you so much for posting this video! I was able to get it working with an SD card formatted with a block size (allocation unit size) of 512 bytes. How do you get it to work with other block sizes (for example, I'm trying to use a block size of 4096 bytes)? Is that possible?

    • @ControllersTech
      @ControllersTech  4 года назад +2

      Change the max sector size to 4096 in the fatfs setup.

    • @ShawnHymel
      @ShawnHymel 4 года назад

      @@ControllersTech Thank you. I can get it to work with cards up to 8 GB, but over that, they don't work. Is there something special I need to do with >8GB cards (other than format them with FAT32 and 4kB block sizes)?

    • @ShawnHymel
      @ShawnHymel 4 года назад +2

      I was able to get it working by upgrading to the newest version of the library: github.com/eziya/STM32_SPI_SDCARD.

  • @encryptedchannel213
    @encryptedchannel213 3 года назад +1

    ERROR!!! in mounting SD CARD... how get I solve this problem

  • @petervancaeseele9832
    @petervancaeseele9832 4 месяца назад

    Excellent! One small bug. There is a buffer overrun when reading file2.txt after being appended to. The file has more than 128 bytes in it.

  • @davidpelyva311
    @davidpelyva311 5 лет назад +4

    Thanks for the video. I tried to do everything according to your video, but it doesn't work.
    I'm working with the same SD-card module as you, but with an STM32L432KC. The first problem is that I don't have fsize parameter in FIL typedef.
    And the second is that it always says that the card is mounted successfully, even if there is NO CARD in the reader. What is more, I get Disk_error if I try to write or read a file on the card.
    Could you please help me?

    • @lauchokyip
      @lauchokyip 5 лет назад +1

      Try writing this
      DSTATUS my_status = SD_disk_initialize(0);
      if(my_status == STA_NOINIT ){
      send_uart ("error in initializing SD CARD...
      ");
      }
      if (my_status == STA_NODISK){
      send_uart ("No medium in the drive...
      ");
      }
      if (my_status == STA_PROTECT){
      send_uart (" Write protected...
      ");
      }
      This will help to know if your disk initialization fails. Remember to #include "fatfs_sd.h"

    • @ucNguyen-wu2xh
      @ucNguyen-wu2xh 5 лет назад

      I have Same problem. Did you solve it ?

    • @xZurdo-e1w
      @xZurdo-e1w 4 года назад

      @@ucNguyen-wu2xh I am using the STM32L4KC too. I used the same files that he used in the video, but I changed the HAL library
      with this #include "stm32l4xx_hal.h" in the fatfs file, and it worked.

    • @marc0711
      @marc0711 3 года назад

      Instead of the 'fsize' parameter you can use the 'f_tell' function.

  • @El_Alawy
    @El_Alawy Год назад

    hello, I followed all the steps but every time I find the sd-card empty. I tried to find what is the reason for that by making leds light at every operation of the SD_card function and found that the function enters the first if condition which mean (No SD Card found) and break.

  • @ControllersTech
    @ControllersTech  4 года назад +6

    I have updated the code on 1st JULY 2020. Read the Description for more info.

    • @emreseyyar5078
      @emreseyyar5078 4 года назад

      where can i download fatfs_sd.c and fatfs_sd.h libary ?

    • @ControllersTech
      @ControllersTech  4 года назад +2

      @@emreseyyar5078 go to the link in the description.. download the code, and you can find the files where i put them in the video

    • @alexandralopes1775
      @alexandralopes1775 4 года назад

      Thank you for the tutorial! Successfully tested on L433 Nucleo board! :) (with some small adaptations of course)

  • @batcircuit4742
    @batcircuit4742 10 месяцев назад

    I am getting "Hard error occurred in the low level disk I/O layer" Error while trying to get the card size, but the card size is displayed 0, what should I do?

  • @utsavsuha
    @utsavsuha 2 года назад

    Hello,
    Everything working well. But i need to log 10 bytes of the data after every 5 milli seconds and this should be done for 24 hours,
    The SPI hangs (remains in busy and locked state)after some times and i can only write for few mins of data.
    Please suggest

  • @nterminator8347
    @nterminator8347 4 года назад +1

    Hello! Thanks you for the video! My controller is F103C8. How can i get throw away trouble with an error of mounts the SD card while microcontroller initialized? I had my spi speed set to about 2.5MB. I'm was formatted my sd card to fat32 file system, block size 512. p.s. miso mosi connected cross to cross. p.p.s I'm use external +5 volt supply for sd card module. Maybe I'm doing something wrong?

    • @ControllersTech
      @ControllersTech  4 года назад +1

      debug and check the output of fresult.. and read the description

    • @nterminator8347
      @nterminator8347 4 года назад +1

      @@ControllersTech Hi. Tnx for the answer. fresult returns fr_not_ready, when 3rd argument is 1. If I use 0 its sayed its fr ok, but after when try to read or write the code its return fr disk error

    • @nterminator8347
      @nterminator8347 4 года назад

      I'm use 5 volts...

    • @erdinckaya3731
      @erdinckaya3731 2 года назад

      @@nterminator8347 I also need the answer of this question.
      I'm taking the same error and i also get fr_invalid_object error.
      How can i do more debugs without getting into low layer @Controllers Tech

    • @erdinckaya3731
      @erdinckaya3731 2 года назад

      @@ControllersTech waiting for you response below.. Thanks in advance..

  • @theraja011
    @theraja011 5 лет назад +1

    Thanks, Can you pls share any example regarding GSM communication with USART(with CTS/RTS).

  • @normanwiedemeyer3338
    @normanwiedemeyer3338 3 года назад

    Thank you very much, worked like a charm!

  • @mathiasclausen8501
    @mathiasclausen8501 3 месяца назад

    Was such a helpful video. I made it work with a MSPm0l1306, by doing some small changes to implement my communication, but it was so helpful to understand how I would glue my applikation to the FATFS library. For some reason It wouldnt work in your user_diskio so i just moved all the functions into the diskio and then it worked.
    Do you have or would you make, a video on how to implement it with dynamic memory allocation?

  • @alexandrev.3332
    @alexandrev.3332 2 года назад

    I am using a SanDisk 2GB microSD. Could be this problem? I tryed to format inf FAT and FAT32 and used and nothing is write

  • @GabiMartin97
    @GabiMartin97 2 года назад

    Working flawlessly. thanks

  • @xZurdo-e1w
    @xZurdo-e1w 4 года назад

    Great video! It was very helpful to me I am very thankful :)

  • @self-studyelectronicengine7294
    @self-studyelectronicengine7294 4 года назад +1

    Thanks for this Code
    please keep going and make video like this video

  • @sumeetgaikwad5702
    @sumeetgaikwad5702 Год назад

    hello sir , i want to interface sd card in spi mode with adi sc 594 mcu , do u have any link for other mcu then stm32

  • @alonsorodriguez6042
    @alonsorodriguez6042 4 года назад

    Hello, I have a question. I'm using FreeRtos and Timer 1 as the source, so there is no SysTick_Handler fuction in stm32f1xx_it.c. Where would I put the FatFsCnt check in this situation?

  • @sarathkumar-tf4lr
    @sarathkumar-tf4lr 4 года назад +1

    @controllerstech am using stm32l476rg micro controller when interfacing with micro sdcard adapter am using your program to control it as per your procedure to settings in cubemx....but i get the "ERROR!!! IN mounting sd card" what mistake maybe occurred in my side...please give the solution

    • @ControllersTech
      @ControllersTech  4 года назад +1

      You are getting error in mount itself. There isn't much i can do here.. It Could be anything..
      Check your connection
      Sd card is in FAT format ?
      Check the SPI speed, it should be around 2Mb/s
      Check the connection again.. there could be a loose wire.

    • @sarathkumar-tf4lr
      @sarathkumar-tf4lr 4 года назад

      @@ControllersTech my SD CARD is in FAT32(default) type.....how can i change into FAT type .....

    • @sarathkumar-tf4lr
      @sarathkumar-tf4lr 4 года назад

      @@ControllersTech when am debugging this code "fresult" return a FR_DISK_ERROR givs....what is the problem may happen...please give the solution....

    • @ControllersTech
      @ControllersTech  4 года назад

      Wait for few hrs. I am updating the code. It might work after that. Check after 4 hrs

    • @ControllersTech
      @ControllersTech  4 года назад

      Code updated... check the description

  • @fernandopiccoli4111
    @fernandopiccoli4111 Год назад

    Hey, I'm saving data on .csv format, and I can't update the file using f_lseek, cause I think it doesn't recognize the filinfo.fsize. Have any tips?

    • @ControllersTech
      @ControllersTech  Год назад

      you can also get the size using the function f_size
      elm-chan.org/fsw/ff/doc/size.html

  • @xRevollt
    @xRevollt 4 года назад +1

    I am having problems with the "fatfs_sd.h" file : BYTE, DSTATUS, DRESULT, DWORD etc all all marked as "unkown type". Using Keil IDE 5

    • @xRevollt
      @xRevollt 4 года назад

      Also using the Nucleo-STM32F446RE, if that matters

    • @ControllersTech
      @ControllersTech  4 года назад

      I will take a look at it again...

    • @ControllersTech
      @ControllersTech  4 года назад

      Looks like you haven't generated the code properly or something to do with keil..

    • @xRevollt
      @xRevollt 4 года назад

      @@ControllersTech What do you mean by not generating the code properly? I am using CubeMX version 5.5 to generate Keil projects. I added fatfs_sd.c and .h to their folder (Src and Inc respectively), and clicked "Add Existing File to group Application/User". Is there anything else to do to properly link the drivers?

    • @xRevollt
      @xRevollt 4 года назад

      @@ControllersTech Would it be preferable for me to use SDIO, rather than SPI, as it seems my board features a 4bit bus SDIO interface, which I've heard is 4 times as fast as SPI?

  • @purposeoflife47
    @purposeoflife47 3 года назад

    i m using this method and one of my sd card is working fine but other is not working. But both sd cards are working fine in laptop. I dont know what is wrong.

  • @netherlabgames7511
    @netherlabgames7511 4 года назад

    Every 512th character in the file is in error. This must be an indication of the block size being in error or something. What do I have to do, format the SD card? It says its block size is 512

  • @marcinorszulak7780
    @marcinorszulak7780 4 года назад

    Hi, Is there anything else to do, except replacing libraries with old one, to avoid getting FR_NO_FILESYSTEM? Iam using F303RE board

  • @35_GilangBagusSinatrya
    @35_GilangBagusSinatrya 5 месяцев назад +1

    Anyone, please helpme. Why f_puts don't work?

  • @alexandrev.3332
    @alexandrev.3332 2 года назад

    I tryed to invert the wires MOSI and MISO and nothing, i tryed to put external 5V to the SD card board and nothing, all the same error

  • @taamallahmedtahe7369
    @taamallahmedtahe7369 2 года назад

    Good morning i have a little project that i have to do but do you think that we can transfer files between two stm32 with spi ( files like .txt) thank youu

  • @suleyman9847
    @suleyman9847 2 года назад

    Thats a very useful video thnk you so much

  • @frasitdar1712
    @frasitdar1712 5 лет назад +1

    From where do i copy the library files fatfs_sd.c and .h files into the folders of project.

    • @ControllersTech
      @ControllersTech  5 лет назад

      Just download the code. They are in the inc and sec folders

  • @klaus9503
    @klaus9503 3 года назад

    Is there a way to send data with DMA ?

  • @sureshp632
    @sureshp632 4 года назад +1

    thank you sir can you guide how the usb interfacing

  • @bahadrguven6268
    @bahadrguven6268 3 года назад

    Does not print the value in the variable.Printing ASCI value.Can I fixed?

  • @alexandrev.3332
    @alexandrev.3332 2 года назад

    I put external 5V and not worked. I changed of sd card to another one of 16GB and still not working

    • @ControllersTech
      @ControllersTech  2 года назад

      One more comment from you and i will block you.
      I told you, ask in those groups. There is no point in spamming on RUclips

  • @LuisReyes-zg7mq
    @LuisReyes-zg7mq 4 года назад

    Is there a way to read last 'x' number of bytes from the card?

    • @ControllersTech
      @ControllersTech  4 года назад +1

      Yeah.. You can take a look at the f_lseek.
      Basically just move the pointer to (file size - x), and than read

  • @alexandrev.3332
    @alexandrev.3332 2 года назад

    I commented this lines and it is working now, pay attention everybody that is anyone that is starting with this example to comment this if you want to put the sd card in your pc to see the data that was written on the sd card. I used a 16GB San Disk Ultra MICRO SD HC I and now worked. I think that cards with 2GB not work because i tested with 2 of then, maybe i should make the same thing that i did when formatted the sd card. The codes of control tech work really, but if you download the already code you have to follow the comments of the video about change MAX_SS to 4096 and USE_LFN to ENABLED WITH STATIC WORKING buffer on bss . When you format the SD CARD should make with FAT 32 and choose 4096 bytes. And slow the speed of SPI to 2.25MBps and i put external 5V power. Control tech have very good videos. I don´t like when my things not work, sorry about my declaration that i did before. Thank you very much for this video. And i am sending my contribution to this site.
    /*************************REMOVING FILES FROM THE DIRECTORY ****************************/
    /*
    fresult = f_unlink("/file1.txt");
    if (fresult == FR_OK) send_uart("file1.txt removed successfully...
    ");
    fresult = f_unlink("/file2.txt");
    if (fresult == FR_OK) send_uart("file2.txt removed successfully...
    ");
    /* Unmount SDCARD */
    /*
    fresult = f_mount(NULL, "/", 1);
    if (fresult == FR_OK) send_uart ("SD CARD UNMOUNTED successfully...
    ");
    */

  • @ziyaonal4772
    @ziyaonal4772 4 года назад

    Can we use sdhc cards with this project?

  • @rubens5563
    @rubens5563 5 лет назад

    Thank you for sharing your work. I would like to know if the fatfs library is compatible with Keil

  • @electronicswitches6010
    @electronicswitches6010 4 года назад

    I am trying to create the file but file is not able to get created

  • @НикитаЩербаков-ж3х
    @НикитаЩербаков-ж3х 4 года назад

    Hello! Tell me, please, how can I assign a file name to some buffer?

  • @bahadrguven6268
    @bahadrguven6268 3 года назад

    I open a text file, type something and close it, I want to open it again and add something else without losing what I wrote first. it is not working.why?

    • @ControllersTech
      @ControllersTech  3 года назад

      You have to use the append attribute..
      Or do this
      Open the file
      Use lseek to point to the end of the file
      Write the data

    • @bahadrguven6268
      @bahadrguven6268 3 года назад

      @@ControllersTech Thanks a lot

    • @bahadrguven6268
      @bahadrguven6268 3 года назад

      @@ControllersTech what is the the append attribute ?I dont know.Can you help me ?

    • @ControllersTech
      @ControllersTech  3 года назад

      FA_APPEND

  • @BogdyMihy
    @BogdyMihy 4 года назад

    Hello! Thanks for the video, it seemed to me quite clear and concise!
    I have a problem however. After doing the f_open command I get a FR_NOT_READY from the fresult.
    I have followed all the indications in the video. The only thing that I don't understand is the clock. I have an STM32WB and as I am new to this I have no clue how to set it, so I basically just let it do it's thing.
    Do you have any idea why I might get that error?

    • @ControllersTech
      @ControllersTech  4 года назад

      Some connection problem. Make sure the card is formatted with FAT or FAT32
      Also try to reduce the SPI speed and see if it can help

    • @BogdyMihy
      @BogdyMihy 4 года назад

      @@ControllersTech Hey! I've just done it and there is no change. I get the same error. (I have a 16Gb card)
      I want to ask you though, why do you set for your clock the two options "HSE" and "PLLCLK" together? If I do this for my microcontroller I instantly get some 0xfffff8 error or something about "Failed to execute MI command".
      Also when you wrote this: fresult = f_mount(&fs, "/", 1); I saw that here you put 0 and on the website there's 1. What is this for?
      Thanks for answering!

    • @ControllersTech
      @ControllersTech  4 года назад +2

      HSE is for selecting external crystal for clock
      PLL is phase loop clock use in all the ARM processors.
      If u are having problems with the clock, i would advice you to not select the HSE and leave the clock input at HSI and use HCLK as 50 or 60 MHz.
      This video was made long ago, and i have modifies the code after that. That's why you might see some changes.
      Although the process remains same.
      Since it seems like you don't have much knowledge about stm32, i would say first try blinking led and start low.

    • @blahman442
      @blahman442 3 года назад

      I face the same issue. Did you fix it?

  • @desaoaraujo
    @desaoaraujo Год назад

    Thanks for the video!! Worked here in my STM32L152 Disco board, with minor adjustments. I was able to create files, write and read. However, a few weird outcomes: total and free sizes result with a dot before the number (numbers seem correct); also, the current version of FIL struct in ff.h doesn't seem to have the .fsize field, so I haven't found a way to read the correct amount of bytes yet.
    Thanks again!

  • @fatimahali2878
    @fatimahali2878 3 года назад

    How to make a file with increment filename?
    Can i make it with same configuration like in your video?

    • @ControllersTech
      @ControllersTech  3 года назад

      File name is a string.
      use something like this
      sprintf(namebuf, "file%d",indx++);
      That's it. Namebuf will have the file names like file1 file2 etc.

  • @MounikaGuntha
    @MounikaGuntha 10 месяцев назад

    Excellent sir,where i can find block diagram for this project??

  • @ubotics27
    @ubotics27 5 лет назад

    Very well explained! May I ask , how can you write data to the next line in the text file ? I have been trying to write Buffer data vertically in the TXT file but they all go horizontal. I will really appreciate your help .thanks

    • @ControllersTech
      @ControllersTech  5 лет назад +4

      Use the '
      ' at the end of the string. That way, next string will be written in the next line

  • @trigonokalanto3217
    @trigonokalanto3217 Год назад

    hello , first of all thanks for this tutorial. I tried this project with stm32f446re and it works pretty well. But i need to save a value every 10us at specific .txt file. For this reason i open , write and close the .txt file into an tim_irq_handler. It seems that the proccess of saving the data takes longer than expected. Do you have recommended changes in the above code to enhance performance?
    Thank you !

  • @naveenrajy2033
    @naveenrajy2033 5 лет назад

    I am trying to access SD card using MikroC for the Board-STM32F446RE...I am facing a problem on Intializing the card ...The statement Fat32_init() does not seems to be working...
    And there is no response from the MISO line .
    Can you please help on this.

    • @ControllersTech
      @ControllersTech  5 лет назад

      I don't know. It could be anything... Are u initialising all the peripherals by your own or using cubemx ?
      Also check what error are you getting. You can do this by checking the error status.

  • @kalaiarasi8931
    @kalaiarasi8931 Год назад

    Hi..The tutorial is really awesome.Asper the instruction i have implmented the code but i am gettingg DISK_Error fom return staement of FRESULT?How to troublehoot the prooblem.kinldy explain

  • @dzikrurrohmani7073
    @dzikrurrohmani7073 3 года назад

    what is the difference between "fresult = f_mount(&fs, "", 0);" and "fresult = f_mount(&fs, "/", 1);" ?

    • @ControllersTech
      @ControllersTech  3 года назад +1

      "0" means the card can be mounted later also. We have executed the command and now it can mount anytime.
      "1" means mount the card immediately.
      "/" Is the path of the sd card, where the mount will take place.

    • @dzikrurrohmani7073
      @dzikrurrohmani7073 3 года назад

      Thankyou sir..

    • @dzikrurrohmani7073
      @dzikrurrohmani7073 3 года назад

      @@ControllersTech I wanna ask again, why I can't use it inside HAL_TIM_PeriodElapsedCallback function for interrupt?

  • @mohdsufian2581
    @mohdsufian2581 4 года назад

    have you tried interfacing sht31 temperature and humidity sensor?
    and cmcu-811 VOC sensor?
    it would be very helpful if you post its tutorial

    • @ControllersTech
      @ControllersTech  4 года назад +1

      I don't have those modules.. will buy them when things will be better...

    • @mohdsufian2581
      @mohdsufian2581 4 года назад

      @@ControllersTech sure.... i am sharing my email adress let's have some conversation there.... may be i can help you buying those modules... or if u are from india i can send that module to ue place
      mail id1: msufian@enggenv.com
      mail id2: mohammadsufian95@gmail.com

    • @mohdsufian2581
      @mohdsufian2581 4 года назад

      @@ControllersTechalso I am having some other ideas for you that can help me also...
      looking forward to ur response, by the way, I am an R&D engineer, in a company near capital city Delhi

  • @supersayayin2goku
    @supersayayin2goku 3 года назад

    Hi, is it possible to store a file after or out the main function??

    • @ControllersTech
      @ControllersTech  3 года назад

      Out of the main function ? Means where ?
      Only the main function gets executed...
      You can write another function outside the main but you need to call it at some point in the main function

    • @supersayayin2goku
      @supersayayin2goku 3 года назад

      @@ControllersTech yeap in a external function and call it in the main thats what i mean

    • @ControllersTech
      @ControllersTech  3 года назад

      Yeah u can do that..

    • @supersayayin2goku
      @supersayayin2goku 3 года назад

      @@ControllersTech Its, becouse when i try my program stops

    • @ControllersTech
      @ControllersTech  3 года назад

      It doesn't stop. It might be going into hardfault because of some error u are making...
      Need more details of this

  • @vivekpkd
    @vivekpkd 4 года назад

    Can u please share this using standard peripheral library

  • @pierrebecam9452
    @pierrebecam9452 4 года назад

    Hello thx for this tuto ! I would like to do the same but with ide arduino ... I didn't find help in the internet, do you think it's possible to interface sd card with stm32f103c8 using spi and arduino ide ?

    • @ControllersTech
      @ControllersTech  4 года назад

      Just use the arduino code. What's the issue ?

  • @tjwelsh1438
    @tjwelsh1438 5 лет назад

    Adding this driver to my project overflowed my RAM by like 11kB, any idea where all this extra memory allocation is coming from? I've skimmed through fastfs_sd.c and .h and can't see anything obvious.

    • @ControllersTech
      @ControllersTech  5 лет назад

      Can't say really.. which controller are u using btw ?
      Try not using my code. See the video and write yourself. That way you always know what u r doing and the places, where things get messed up.

    • @tjwelsh1438
      @tjwelsh1438 5 лет назад

      @@ControllersTech Good advice, in the end it had nothing to do with your drivers. Thanks for sharing your code!

    • @kubalec1
      @kubalec1 5 лет назад

      ​@@tjwelsh1438 could You share the solution?

  • @radosawpuchalski2251
    @radosawpuchalski2251 4 года назад

    I have some strange problem during compiling. There are an compile error: "#error This file is not needed in current configuration. Remove from the project." in cc932.c.

    • @ControllersTech
      @ControllersTech  4 года назад

      Maybe things have changed with new version of HAL.. i have to check it again..

    • @radosawpuchalski2251
      @radosawpuchalski2251 4 года назад

      @@ControllersTech Thank you. Let me know, if you check, please. I have tried many solutions and I don't have an idea what to do.

    • @ControllersTech
      @ControllersTech  4 года назад

      Which controller do you have

    • @radosawpuchalski2251
      @radosawpuchalski2251 4 года назад

      @@ControllersTech I have checked F746ZG, but I have F410RRB and F103RB (all Nucleo boards) too. Of course I've changed header includes in every file with it.

  • @aaronrenny7246
    @aaronrenny7246 4 года назад

    Very informative video. Can i use the same code for interfacing in Keil software.? Please help.

  • @paulg.3067
    @paulg.3067 4 года назад

    What write speed (MB/s) to card can I expect using this method?

    • @ControllersTech
      @ControllersTech  4 года назад

      Not much. Try around 2Mb/s and than go higher..

  • @maliknouman9649
    @maliknouman9649 4 года назад

    I am new to the microcontroller programming.
    i have created the new project as per your video but i am not able to see the file "user_diskio.c" in may project and also not in your code(zip file which i downloaded from you link).
    and one more thing , are the files fatfs_sd.c and fatfs_sd.h are standard files or your custom made files,
    if these these are standard files then why these are not a part of the created project.

    • @ControllersTech
      @ControllersTech  4 года назад

      User_diskio.c file is in FATFS -> Target folder
      Fatfs_sd.c and .h are not the default files. You have to copy them from my project into yours.

    • @maliknouman9649
      @maliknouman9649 4 года назад

      thankyou for your time
      how can we create such library files

    • @ControllersTech
      @ControllersTech  4 года назад

      Which library file you are talking about

    • @maliknouman9649
      @maliknouman9649 4 года назад

      @@ControllersTech like fatfs_sd.c and fatfs_sd.h

    • @maliknouman9649
      @maliknouman9649 4 года назад

      i have created the project as per you video , i am receving the message "ERROR!!! in mounting SD CARD on uart terminal.
      i have tried it on STM32F103C(stm32 blue pil) and also i have amended the code a created a project for nucleoF767ZI again i am receiving the same "ERROR!!! in mounting SD CARD.
      i have made connection as follows
      for STM32F103c
      SD card stm32f103(SPI1)
      CS-----------------------> Pin PA4
      SCK-------------------->PA5(SCK1)
      MISO -------------------->PA6(MISO1)
      MOSI -------------------->PA7(MOSI1)
      for nucleo F767ZI
      SD card NucleoF767ZI(SPI1)
      CS-----------------------> PC4
      SCK-------------------->PA5(SCK)
      MISO -------------------->PA6(MISO)
      MOSI -------------------->PA7(MOSI)
      Vcc and Gnd are connected acordingly
      BUT using aduino i am able to write the data to sd card using STM32F03c

  • @jahnvibedia826
    @jahnvibedia826 5 лет назад

    I am using F401RE. I am finding problem in disk initialization.
    1. Even when I am not inserting the card there is no difference. It is executing f_mount successfully.
    2. The program does not enter the line ENTER_FF(fs) in ff.c for volume locking.

    • @ControllersTech
      @ControllersTech  5 лет назад

      1. Yes that's the bug in the code.
      2. I don't know much about it. I ported the code so that it can work with HAL library.
      What kind of error are u getting exactly

    • @jahnvibedia826
      @jahnvibedia826 5 лет назад

      @@ControllersTech I am not able to fetch any values in fs FATFS pointer in ff.c. I am unable to understand why this is happening. I also tried to understand and fetch information about the libraries. But none understood to an extent to solve the problem. Also how did you port the code ? Probably that can work for me too.

    • @ControllersTech
      @ControllersTech  5 лет назад

      There are few things
      * Some users have reported that SanDisk cards are not working.
      * Make sure the sd card is formatted in FAT
      * Use the smaller size at first. I have used a 1GB card while making this video

    • @jahnvibedia826
      @jahnvibedia826 5 лет назад

      @@ControllersTech I am using F401RE nucleo board. Is it possible that there might be a hardware problem? I read at some places that that might be an issue.

  • @dzikrurrohmani7073
    @dzikrurrohmani7073 3 года назад

    Can I change timer1 and timer2 variable inside fatfs_sd.c file?

    • @ControllersTech
      @ControllersTech  3 года назад +1

      They are used for timeout.
      How do you want to change them?

    • @dzikrurrohmani7073
      @dzikrurrohmani7073 3 года назад

      I already use ur code and works inside HAL_TIMPediodElapsedCallback, but max interrupt speed that I could generate is about 0.5 sec, I need it to be faster, what should I do?

  • @sureshp632
    @sureshp632 4 года назад

    Sir how to write sensor data to file.txt I am using buf but display zeros only f_sleek(&fil,fil.fsize) but error occur help me please

    • @ControllersTech
      @ControllersTech  4 года назад

      open it as to append data
      f_open(&fil, name, FA_OPEN_APPEND | FA_WRITE);
      and than write
      f_write(&fil, data, strlen (data), &bw);

  • @chelseacsl3884
    @chelseacsl3884 4 года назад

    Is it working if we do not use USART? And where do you connect those USART pins to?

    • @ControllersTech
      @ControllersTech  4 года назад

      Of course it works without uart. Uart is just to check, its like verbose in linux 😀. Pins are connected to the Tx and Rx pins..

    • @chelseacsl3884
      @chelseacsl3884 4 года назад

      Controllers Tech we did exactly what you did and when we step into the f_open it goes directly to res != fr_ok. Do you know why? Actually I think only the f_mount works fine.

    • @chelseacsl3884
      @chelseacsl3884 4 года назад

      Controllers Tech Actually f_mount is not working. It doesn’t go to else statement

    • @ControllersTech
      @ControllersTech  4 года назад

      Don't use larger storage card.
      Make sure the file system is FAT
      The card shoul not be write protected
      Some users reported that sandisk card doesn't work

    • @chelseacsl3884
      @chelseacsl3884 4 года назад

      @@ControllersTech And why sandisk doesn't work?

  • @willychen5444
    @willychen5444 4 года назад

    Thanks, it's help me a lot!

  • @alexandertoro8723
    @alexandertoro8723 5 лет назад

    Excellent tutorial.

  • @technopeak4313
    @technopeak4313 3 года назад

    i cannot write integer number in text file.i am using f_write.Can you help me?ASCI table writing?

    • @ControllersTech
      @ControllersTech  3 года назад

      Does f_write accepts integer number ?

    • @technopeak4313
      @technopeak4313 3 года назад

      @@ControllersTech DHT_GetData();
      /* USER CODE END WHILE */
      fresult = f_open(&fil,"file.txt",FA_OPEN_APPEND|FA_WRITE);
      f_write (&fil,&Temperature,1,&bw);
      fresult= f_close (&fil);
      fresult = f_open(&fil,"file.txt",FA_OPEN_APPEND|FA_WRITE);
      f_write (&fil,&Humidity,1,&bw);
      fresult= f_close (&fil);
      HAL_Delay(3000);

    • @technopeak4313
      @technopeak4313 3 года назад

      @@ControllersTech how can i fixed?ASCI number writing?

    • @ControllersTech
      @ControllersTech  3 года назад

      Are u serious ?
      Temperature is a float value.. f_write accepts a buffer..
      Use sprintf to convert and store those values in the buffer.
      And then send buffer

  • @david-kr1zw
    @david-kr1zw 5 лет назад

    Thank for going to the effort of publishing this. I’ve been wanting to get this working for a while so this video is going to be really useful. So far I’ve only “skim” watched it, and I’ve also looked at your website, but in both cases and for the life of me I can’t see where your fatfs_sd.c and fatfs_sd.h files are coming from. i.e. you say copy them into the project, buy where are you copying them from ? Apologies if it’s obvious, and thanks again.

    • @ControllersTech
      @ControllersTech  5 лет назад

      Download the code. Those files are present in src folder and inc folder

  • @aishwaryasr3913
    @aishwaryasr3913 Год назад

    Thank you for the video. I'm facing problem in writing to the SD card. The file gets created but not able to write. The f_write returns FR_INT_ERR. Can you please let me know what could be the issue?
    Note : I am able to read the data written on the card

  • @javib8970
    @javib8970 3 года назад

    I cant get it to work :(.Could anyone tell me the brand of SD card that worked for them?
    Im trying with 128Gb sandiskUltra and 4Gb microSD HC
    Im powering the 5v to the sd card reader from a lab power supply.
    Cheers

    • @javib8970
      @javib8970 3 года назад

      //this is my uart output using eziya fatfs_sd.h library
      //same outputs with sd card inserted and no sd card inserted
      SD card mounted successfully ...
      SD card total size: 5
      SD card free space: 5
      sorpesa.txt created with fresult: 255 (not event in the range of FRESULT enum)
      file closed with fresult: 9 /* (9) The file/directory object is invalid */
      file opened with fresult: 1 /* (1) A hard error occurred in the low level disk I/O layer */
      file closed again with fresult: 9 /* (9) The file/directory object is invalid */

    • @ControllersTech
      @ControllersTech  3 года назад

      Replace the mount with the below function
      fresult=f_mount(&fs, "/", 1); if(fresult == FR_OK){ send_uart("SD card mounted successfully ...

      "); }
      else { send_uart("error in mounting sd card ...

      ");}

    • @javib8970
      @javib8970 3 года назад

      @@ControllersTech
      error in mounting sd card ... fresult=FR_NOT_READY
      SD card total size: 5
      SD card free space: 5
      sorpesa.txt created with fresult: 255
      file closed with fresult: 9
      file opened with fresult: 1
      file closed again with fresult: 9
      i leave my code just in case someone else is willing to test in their own hardware setup
      gh repo clone javiBajoCero/bluepill_sd_spi

    • @andresfelipe6085
      @andresfelipe6085 3 года назад +1

      @@javib8970 i have the same problem . When the code try to open the file "log-file" or any other the fres variable it's FR_NOT_READY. I tried a lot of things, other codes, external power suply and upgrade the Cube Ide but doesn't work :c. Did you solve the problem?. I think that the problem is the FatFs file generate automatically

    • @javib8970
      @javib8970 3 года назад

      @@andresfelipe6085 i didnt solved the problem...
      I tried also to flash controllers tech github code but i get a weird error (wrong stlink serial number or something like that).
      Anyway im about to give up with this and try sdio interface in an stm32f4

  • @stefanputureanu9296
    @stefanputureanu9296 4 года назад

    I had made some changes, there are some variables types that are not right. I run this project at 18MBits/s with no errors. I used keil uVision.
    // "sprintf" needs an "unsigned long" input. Note that despite the fact that int and long are represented by the same number of bits, they are still different types.

  • @sureshp632
    @sureshp632 5 лет назад

    thank you sir once again.

  • @souradeepdas368
    @souradeepdas368 5 лет назад

    Plzzzzzzzzzzzzz help me. I have an tf card module and want to use it with stm32f103c8t6 in arduino (using SPI). But I cant do it. Plzzzz help me.

    • @ControllersTech
      @ControllersTech  5 лет назад

      If you are planning on using f103 as an Arduino, I can't help you out. Better look in the STM32duino forum..

  • @mohammadal-dossari299
    @mohammadal-dossari299 4 года назад

    It seems f_write can not exceed 1023 for "btw" which is the number of bytes to write. If I try to write 1024 byte, I have FR_DISCK_ERR.
    Can you help me, if that is the maximum length I can write Or there is another problem to be solved.
    Thank you

    • @ControllersTech
      @ControllersTech  4 года назад

      Try changing the data type of btw.. i don't remember what's defined in the code.. just increase it like from uint8 to uint16

    • @mohammadal-dossari299
      @mohammadal-dossari299 4 года назад

      @@ControllersTech "btw" is "UINT". I think it accepts 1024 byte

    • @mohammadal-dossari299
      @mohammadal-dossari299 4 года назад +1

      the problem solved. I think it is a bug in the Fatfs_sd.c
      In function "SD_TxDataBlock" there is NO "return TRUE" if the token =0xFD, it will be always "return False"
      my solution is just adding "else" for the "If" statement and return TRUE there.
      Also, eclipse raise a warning there ('resp' may be used uninitialized in this function) which is make sense in case of 0xFD token.

  • @jen8132-t9v
    @jen8132-t9v 4 года назад

    Is the link to the code broken or is it just me?

  • @AnglasMechatronics
    @AnglasMechatronics 4 года назад

    Great very good information, would you recommend some books from where you are learning all that, please I would appreciate it very much.

    • @ControllersTech
      @ControllersTech  4 года назад

      Don't know man.. I generally use the sensor datasheet itself. And rest is the research..

    • @jotham123
      @jotham123 4 года назад +1

      there's a book called Mastering STM32 - very useful.

  • @alexandrev.3332
    @alexandrev.3332 2 года назад

    I am getting this: ERROR!!! in mounting SD CARD...

    ----> I had formatted with FAT and FAT32, i used 2 micro SD cards and anyone works

  • @alidemir8434
    @alidemir8434 2 года назад

    i get invalid error what to do

  • @alexandrev.3332
    @alexandrev.3332 2 года назад

    I did in Arduino and the SD CARD kit that i have work very well. I buy one like your video, but your software don´t write or read anything of SD CARD, not work. I tryed to format in PC but nothing happens, always the same bad things.

    • @ControllersTech
      @ControllersTech  2 года назад

      You posted the comment on the website right?
      Just because you can't get it to work, "you think the code is very wrong" ?
      Sort the comments to "newest first" and see how many people got it to work.

    • @alexandrev.3332
      @alexandrev.3332 2 года назад

      @@ControllersTech Yes, i did all the things and not write or read, but with arduino read and write. I format with fat and then i tryed with fat32, anyone works. Why in arduino works very well. I have blue pill stm32f103c8t6 and i have this board to put the card

    • @alexandrev.3332
      @alexandrev.3332 2 года назад

      @@ControllersTech I copy your program and nothing happens, i did a lot of times and nothing happen or 2G micro SD card, only with Arduino, this is my question. Maybe there is something very simple that i don´t know

    • @ControllersTech
      @ControllersTech  2 года назад

      I don't know why it isn't working for you. Try using external 5V supply to the module. Don't use the bluepill's 5V.
      Also some particular types of sd card don't work. I don't remember which one exactly, but read the comments as some people have pointed it out.

    • @alexandrev.3332
      @alexandrev.3332 2 года назад

      @@ControllersTech But why this sd cards works on arduino uno?

  • @alexandrev.3332
    @alexandrev.3332 2 года назад

    The video is very good, i know that the problem is with me, but i can identify the error. I used your whole code download and nothing

  • @ehomen9310
    @ehomen9310 2 месяца назад

    my pusle stopped for a second when you pointed at options whitch pins are already taken by my previus code

  • @bdouram
    @bdouram 5 лет назад

    Hi! I followed the tutorial and i have to say thank you! But its not working for me. I have a STM32F446 Nucleo and i got the error saying STA_NO_INIT when i call the function SD_disk_initialize (the disk is not initialized). I watch the video billions of times, and the error persists.
    If you could help me, please.

    • @ControllersTech
      @ControllersTech  5 лет назад

      Have you formatted the card with FAT ?

    • @sribooshans4451
      @sribooshans4451 5 лет назад

      @Bruno Miranda Did you try it again? We are also trying to access a 8 GB SanDisk SD Card using Nucleo - F446RE and the MikroC PRO for ARM IDE. We are not able to initialise the SD card into SPI mode successfully. Please help us if you are able to get it!

    • @ControllersTech
      @ControllersTech  5 лет назад

      It depends on what error are you getting. Try the solution posted in the pinned comment..

    • @sribooshans4451
      @sribooshans4451 5 лет назад

      @@ControllersTech We are using SPI 8 Bit mode only

  • @saurabhkulkarni356
    @saurabhkulkarni356 3 года назад

    hello sir, please make video on MFRC522 RFID with stm32 f4

  • @ganeshgaikwad2158
    @ganeshgaikwad2158 5 лет назад +1

    Thank you sir.. for this amazing tutorial. Can you please guide for this with Compact flash card with stm32f3..

    • @xZurdo-e1w
      @xZurdo-e1w 4 года назад +1

      It's the same for other STM, I use the stm32l432kc and it works fine. For doing so, you have to change the name to the library according with your microcontroller in the fatfs file. For example: #include "stm32l4xx_hal.h" I included this in my case in yours: #include "stm32f3xx_hal.h" I think

    • @tomashort675
      @tomashort675 4 года назад +1

      @@xZurdo-e1w could you share your code for this type stm please?

  • @sureshp632
    @sureshp632 5 лет назад

    Thanking you sincerely regarding our tutorial. can you please guide Can TRANSCEIVER MCP 2551 WITH STM32F4

  • @nuhmusaozyoldas465
    @nuhmusaozyoldas465 4 года назад

    Does the memory card model matter?

    • @ControllersTech
      @ControllersTech  4 года назад +1

      I am going to update this code soon. So if it doesn't work for you right now, be patient. It will be done in 1 or 2 days

  • @arvinghahremani5116
    @arvinghahremani5116 4 года назад

    Thank you very much. I use stm32f103c8t6 and 2GB SD Card. but when run this code, I get successful mounting, 0 free and used space and nothing is created on my SD Card. could you help me please?

    • @ControllersTech
      @ControllersTech  4 года назад

      Are u sure mount is not giving you error ?

    • @arvinghahremani5116
      @arvinghahremani5116 4 года назад

      @@ControllersTech I used an external 5V power source for SD Card and it worked! thanks.

  • @danpommerening3490
    @danpommerening3490 3 года назад

    Ok I built this for STM32F411CEU WEACT board. using Chan's FatFs R0.12c
    Everthing works good except the "file.size" reference.
    This has been replaced in ChaN's FatFs R0.12c version with f_size(&fil).

    • @themest4833
      @themest4833 5 месяцев назад

      help me, I don't find a fsize, where is it?

  • @deepkumar-hk6wl
    @deepkumar-hk6wl 5 лет назад

    I am generating code for STM32F32373c using STM32cubeIDE ,but how can i add fatfs_sd.c and fatfs_sd.h
    I am unable to find this file. Please help me .....thank you

    • @ControllersTech
      @ControllersTech  5 лет назад

      Download the code. They are in the src and inc folders

  • @sureshp632
    @sureshp632 4 года назад

    Thanks sir how to write sensor reading data specially adc in txt file

  • @alexandrev.3332
    @alexandrev.3332 2 года назад

    Your software for me not worked. I make all the things and the total size shows zero and not write or read anything. I did all of the video and not work. I am using 2GB micro sd