Тёмный

29. STM32CubeIDE SD CARD. SPI with STM32F103C8T6 

MicroPeta by Nizar Mohideen
Подписаться 7 тыс.
Просмотров 22 тыс.
50% 1

STM32 Blue Pill for beginners
Code and diagram are at www.micropeta.com/video29

Опубликовано:

 

1 авг 2021

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 94   
@NizarMohideen
@NizarMohideen 2 года назад
There are two additional info 1. Make sure sd card module gets 5V. Try separate power supply if possible 2. When you format SD card in windows10 with FAT32, select 4096bytes for allocation unit size.
@htlee5371
@htlee5371 Год назад
I tried this on F401CCU6,I had to change f_lseek(&fil, fil.fsize) => f_lseek(&fil, fil.fptr).At first,no file was generated.Then I saw this commet,I formatted the card to 4096 and connected 5 volts to vcc.Finally,It worked.👍👍👍👍
@danhchucao3246
@danhchucao3246 25 дней назад
Sir, I follow exactly what u did but when I use Usb cable which give 5V to sd MH-SD card module with sd card adapter, however I cant find the text file in the micro sd card although my system file of sd card was FAT32 and allocation size was 4096bytes. I use STM32F103C8T6, windows 10, and ST link v-2. Please help me, I am really losing patient on this
@kajtus940
@kajtus940 Год назад
Thank You Nizar you are the best! Your explanation is very clear and code is working [just change f_lseek function to -> f_lseek(&fil, f_size(&fil)); ], also thanks for SD reformatting info!
@L2.Lagrange
@L2.Lagrange 3 месяца назад
Looks very helpful. I'll be following this tutorial later
@jaimecordoba7363
@jaimecordoba7363 4 месяца назад
Nice tutorial, Sir. Thank you very much!
@NizarMohideen
@NizarMohideen 4 месяца назад
You are welcome!
@coolchriss
@coolchriss 2 месяца назад
Great tutorial! I appreciate your generousity on giving lessons, I hope you make same tutorial using the chip l293 for both DC motor and stepper motor, again thank you so much❤
@anandakrishnannair
@anandakrishnannair 2 года назад
Thank you for your help sir!
@NizarMohideen
@NizarMohideen 2 года назад
You are most welcome
@carlosbarberis49
@carlosbarberis49 Год назад
Very good tutorial I tried it with the Nucleo STM32F446RE I had to make a few minor changes but got everything working just fine. The only question I have...Where do I find the additional SD card commands like: create directory, delete directory, delete file, rename file and append to file. Are these functions available within this library somewhere???
@user-lf3nt1mk4h
@user-lf3nt1mk4h 2 месяца назад
Thank you very much for your patient guidance. I have benefited a lot,thank you❤!
@kaktusjack1033
@kaktusjack1033 7 месяцев назад
excellent explanation
@angelramirezmartinez2598
@angelramirezmartinez2598 Год назад
It worked with 8MHZ in all the clocks, with the stm32f103c8t6 and stm32f411e board. What should I have to modify if I want to increase the clock frequency for example to 72 Mhz?
@michaelbertocchi
@michaelbertocchi 3 месяца назад
I've seen many of your super interesting videos! Is this application also adaptable to stm32g431kb?
@eklimann
@eklimann Год назад
HELLO FROM POLAND NIZAR THANK YOU FOR WORKING CODE
@trungkiennguyen1603
@trungkiennguyen1603 2 года назад
Hello, in this tutorial, I saw you to use SPI 1 for communicating between STM32F103 and SD card module. I want to ask you that dose it work well if I use SPI 2? If it is OK, do I have to change any things in SD library?. Thank you so much!
@NizarMohideen
@NizarMohideen 2 года назад
Actually, the library creator "Lee Ji-hoon" used with spi2. It will work The link is below github.com/eziya/STM32_SPI_SDCARD/tree/master/STM32F4_HAL_SPI_SDCARD I suggest if you want SPI2 with STM32F103C8T6, try with SPI1 first. If everything works well, change to SPI2 You need to modify fifth last line in fatfs_sd.h file extern SPI_HandleTypeDef hspi1; Thanks
@firebirdonfire
@firebirdonfire Год назад
I can't seem to get this to work at all with the Nucleo F446RE Board. Everything looks correct, but I can't get anything to write to the SD card... I'm using SPI2, pins PB13, 14, and 15. My CS Pin is on PB12. Everything programs, just no file on the SD card...
@shenghuang4678
@shenghuang4678 2 месяца назад
Thanks, my friends. It's helpful. I have a class10 card worked but a class4 card can't work at all. I don't know the reason.
@smallick653
@smallick653 Год назад
Hi, is it possible to store a firmware in SD card module and make it work for stm32 chip. Instead of using internal flash memory? I mean can we use external SD card as flash memory for stm32 chip?
@bharatpatidar9629
@bharatpatidar9629 Год назад
Is the procedure applicable on stm32f401 nucleo board?
@hadhemimasghouni7686
@hadhemimasghouni7686 Год назад
Could this code be implemented on stm32F76 ? in fact ,i tried to generate it but i got a prblm with the mounting ...
@lc7827
@lc7827 3 месяца назад
Code works fine. However, if you use 3.3V SD card module, you may need to add extra capacitor (47uF? or more) between 3.3V and GND. Without it SD seem to draw too much current and project no longer works.
@gabrielcabrerasanchez1542
@gabrielcabrerasanchez1542 2 года назад
Hi again bro, a question ,In which file is the function f_lseek(&fil, fil.fsize);? , because I can't find it in the files
@NizarMohideen
@NizarMohideen 2 года назад
f_lseek(&fil, fil.fsize); is in a built-in library of CubeIDE. When Click Middleware → Click FATFS, it will kick in
@NizarMohideen
@NizarMohideen 2 года назад
Middlewares/Third_party/FatFs/src/ff.c
@NizarMohideen
@NizarMohideen 2 года назад
/*-----------------------------------------------------------------------*/ /* Seek File R/W Pointer */ /*-----------------------------------------------------------------------*/ FRESULT f_lseek ( FIL* fp, /* Pointer to the file object */ DWORD ofs /* File pointer from top of file */ ) { FRESULT res; DWORD clst, bcs, nsect, ifptr; #if _USE_FASTSEEK DWORD cl, pcl, ncl, tcl, dsc, tlen, ulen, *tbl; #endif res = validate(fp); /* Check validity of the object */ if (res != FR_OK) LEAVE_FF(fp->fs, res); if (fp->err) /* Check error */ LEAVE_FF(fp->fs, (FRESULT)fp->err); #if _USE_FASTSEEK if (fp->cltbl) { /* Fast seek */ if (ofs == CREATE_LINKMAP) { /* Create CLMT */ tbl = fp->cltbl; tlen = *tbl++; ulen = 2; /* Given table size and required table size */ cl = fp->sclust; /* Top of the chain */ if (cl) { do { /* Get a fragment */ tcl = cl; ncl = 0; ulen += 2; /* Top, length and used items */ do { pcl = cl; ncl++; cl = get_fat(fp->fs, cl); if (cl fs, FR_INT_ERR); if (cl == 0xFFFFFFFF) ABORT(fp->fs, FR_DISK_ERR); } while (cl == pcl + 1); if (ulen fs->n_fatent); /* Repeat until end of chain */ } *fp->cltbl = ulen; /* Number of items used */ if (ulen fp->fsize) /* Clip offset at the file size */ ofs = fp->fsize; fp->fptr = ofs; /* Set file pointer */ if (ofs) { fp->clust = clmt_clust(fp, ofs - 1); dsc = clust2sect(fp->fs, fp->clust); if (!dsc) ABORT(fp->fs, FR_INT_ERR); dsc += (ofs - 1) / SS(fp->fs) & (fp->fs->csize - 1); if (fp->fptr % SS(fp->fs) && dsc != fp->dsect) { /* Refill sector cache if needed */ #if !_FS_TINY #if !_FS_READONLY if (fp->flag & FA__DIRTY) { /* Write-back dirty sector cache */ if (disk_write(fp->fs->drv, fp->buf.d8, fp->dsect, 1) != RES_OK) ABORT(fp->fs, FR_DISK_ERR); fp->flag &= ~FA__DIRTY; } #endif if (disk_read(fp->fs->drv, fp->buf.d8, dsc, 1) != RES_OK) /* Load current sector */ ABORT(fp->fs, FR_DISK_ERR); #endif fp->dsect = dsc; } } } } else #endif /* Normal Seek */ { if (ofs > fp->fsize /* In read-only mode, clip offset with the file size */ #if !_FS_READONLY && !(fp->flag & FA_WRITE) #endif ) ofs = fp->fsize; ifptr = fp->fptr; fp->fptr = nsect = 0; if (ofs) { bcs = (DWORD)fp->fs->csize * SS(fp->fs); /* Cluster size (byte) */ if (ifptr > 0 && (ofs - 1) / bcs >= (ifptr - 1) / bcs) { /* When seek to same or following cluster, */ fp->fptr = (ifptr - 1) & ~(bcs - 1); /* start from the current cluster */ ofs -= fp->fptr; clst = fp->clust; } else { /* When seek to back cluster, */ clst = fp->sclust; /* start from the first cluster */ #if !_FS_READONLY if (clst == 0) { /* If no cluster chain, create a new chain */ clst = create_chain(fp->fs, 0); if (clst == 1) ABORT(fp->fs, FR_INT_ERR); if (clst == 0xFFFFFFFF) ABORT(fp->fs, FR_DISK_ERR); fp->sclust = clst; } #endif fp->clust = clst; } if (clst != 0) { while (ofs > bcs) { /* Cluster following loop */ #if !_FS_READONLY if (fp->flag & FA_WRITE) { /* Check if in write mode or not */ clst = create_chain(fp->fs, clst); /* Force stretch if in write mode */ if (clst == 0) { /* When disk gets full, clip file size */ ofs = bcs; break; } } else #endif clst = get_fat(fp->fs, clst); /* Follow cluster chain if not in write mode */ if (clst == 0xFFFFFFFF) ABORT(fp->fs, FR_DISK_ERR); if (clst = fp->fs->n_fatent) ABORT(fp->fs, FR_INT_ERR); fp->clust = clst; fp->fptr += bcs; ofs -= bcs; } fp->fptr += ofs; if (ofs % SS(fp->fs)) { nsect = clust2sect(fp->fs, clst); /* Current sector */ if (!nsect) ABORT(fp->fs, FR_INT_ERR); nsect += ofs / SS(fp->fs); } } } if (fp->fptr % SS(fp->fs) && nsect != fp->dsect) { /* Fill sector cache if needed */ #if !_FS_TINY #if !_FS_READONLY if (fp->flag & FA__DIRTY) { /* Write-back dirty sector cache */ if (disk_write(fp->fs->drv, fp->buf.d8, fp->dsect, 1) != RES_OK) ABORT(fp->fs, FR_DISK_ERR); fp->flag &= ~FA__DIRTY; } #endif if (disk_read(fp->fs->drv, fp->buf.d8, nsect, 1) != RES_OK) /* Fill sector cache */ ABORT(fp->fs, FR_DISK_ERR); #endif fp->dsect = nsect; } #if !_FS_READONLY if (fp->fptr > fp->fsize) { /* Set file change flag if the file size is extended */ fp->fsize = fp->fptr; fp->flag |= FA__WRITTEN; } #endif } LEAVE_FF(fp->fs, res); }
@gabrielcabrerasanchez1542
@gabrielcabrerasanchez1542 2 года назад
Thanks bro, If I have other problems, I'll let you know, hoping for some help, haha
@gabrielcabrerasanchez1542
@gabrielcabrerasanchez1542 2 года назад
Hey bro I saw a new change for the function f_lseek(&fil,fil.size()); if someone has a problem to intance the method fil.size try to use f_size(&fil) so the function f_lseek would be f_lseek(&fil,f_size(&fil));
@komaroviecoclubpodcast4029
@komaroviecoclubpodcast4029 2 года назад
write function works but read does not any possible solution?
@sudharaniinti
@sudharaniinti 9 месяцев назад
Will this work for STM32F303RE?
@rafaeldelpino2378
@rafaeldelpino2378 7 месяцев назад
Is this bluepill original or clone? Here with clone noway to work with debugger
@p.kaikieu4796
@p.kaikieu4796 3 месяца назад
Dear sir, can u make a video that use another SPI product like Matrix led SPI; 7_seg led SPI ? thank u so much for reading my comment
@priyanshusrivastava9288
@priyanshusrivastava9288 2 года назад
Hello, I want to do continuos adc data logging in sd at 500Hz rate using the same, can you please tell how?
@NizarMohideen
@NizarMohideen 2 года назад
I am not sure whether spi sd card is capable of writing 500 times in one second. You can put the data in a array buffer and then write it to sd card every one second. If there any data loss, you can reduce the data logging rate.
@vidyadharisakala2204
@vidyadharisakala2204 Год назад
My module is stm32f407zgt6 which has it's own sd card slot
@maltheengstrm3317
@maltheengstrm3317 7 месяцев назад
kan ikke lige få det til at virke med STM32F103RT6. compiler fint. kan bare ikke med den version af Cubmx / middelware som jeg har adgang til.
@MounikaGuntha
@MounikaGuntha 3 месяца назад
I am working on stm32F103C8T6 bluepill..i had done samething in the viedo,but it does not store anything in my SD Card. I am giving 5 Volts to the Vcc.I am using 32 GB Micro Sd card,but it does not show anything.what should i do??
@NizarMohideen
@NizarMohideen 3 месяца назад
Please check everything Wishing you al the best
@thanhnguyentien5317
@thanhnguyentien5317 2 года назад
Hello I did the same thing you did it doesn't give any error and shows the same debug as you but when I open the SD file, it's not there Please help me fix it!
@NizarMohideen
@NizarMohideen 2 года назад
Hi, 1. Check the card works on a PC and it’s file system is FAT32 2. Make sure SD card reader VCC gets 5V (Supply 5V to Micro-controller via USB before connecting st-link) 3. Try with a different SD card if you have another. 4. Check the wiring connectins
@thanhnguyentien5317
@thanhnguyentien5317 2 года назад
@@NizarMohideen Thank you sir, it worked!
@ufukcanaydogan7559
@ufukcanaydogan7559 2 года назад
@@thanhnguyentien5317 What was your problem?
@RDGamezz
@RDGamezz 2 года назад
@@thanhnguyentien5317 What was the problem, can you please help me
@premapatil5415
@premapatil5415 2 месяца назад
hello sir, this code is working and executes successfully with 0 errors, but the file "write.txt"is not creating into the sd card, can you please give me the solution for this problem sir?
@rift3353
@rift3353 2 года назад
is it same if i try in STM32F4 discovery?
@NizarMohideen
@NizarMohideen 2 года назад
The library creator named eziya in github used it for STM32F4. github.com/eziya/STM32_SPI_SDCARD/tree/master/STM32F4_HAL_SPI_SDCARD I modified to work with STM32F1. You can use the original codes
@thanhg01
@thanhg01 2 года назад
Hi Bro ! I have a string , Ex : Helpme = " nguyentienthanh"; I want to save "Helpme" in SD_card Because "Helpme" always changing Can you help me write a function that saves string like above? Thanks you very much !!
@NizarMohideen
@NizarMohideen 2 года назад
Hi Thành Tiến, You can use separate files for each variables. For example Helpme = " nguyentienthanh"; you can use Helpme.txt and then save the variable without f_lseek(&fil, fil.fsize); It will overwrite in the beginning of the file. Another option is to use eeprom as I have shown in video-no-66 and video-no-67 of my RU-vid channel. Thanks
@Mintonperformance
@Mintonperformance Год назад
update the f_lseek function --- f_lseek(&fil, f_size(&fil));
@gurumultitask9979
@gurumultitask9979 2 года назад
can you show me adding SPI and LCD TFT to GRBL?
@NizarMohideen
@NizarMohideen 2 года назад
I am not familiar with GRBL I have some types of lcd or tft with stm32. links ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-9F2gTb3n_p0.html ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-l-JVnlJIPao.html ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-8hypVJ2U7OE.html
@mastermindsouravnaskar7382
@mastermindsouravnaskar7382 2 месяца назад
can i use free rtos ? is there ant tutorial on it?
@NizarMohideen
@NizarMohideen 2 месяца назад
ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-GDLeBBvOTmo.html
@meetshah4285
@meetshah4285 Год назад
Hello, I am using STM32L432 board and I want to write and read data from the SD card, similar to this video. All the settings you did in .ioc were done by me too. The file built with 0warnings and 0 errors. The addition of the unint line in include files was done by me for the respective header files too. I am not able to see the text file on the SD card. Can you help me. Thank you for the video. Please help me. Thank you
@meetshah4285
@meetshah4285 Год назад
Just one more addition. For me, I was getting error for fil.fsize so I used f_size(&fil) for f_sleek(&fil, f_size(&fil));
@kamarmeredow7644
@kamarmeredow7644 7 месяцев назад
Hi @NizarMohideen, In fatfs_sd.c GET_SECTOR_SIZE command always returns 512. So i cannot understand what is the meaning of setting MAX_SS config to 4096 in CubeMX. Maybe i dont understand something here?
@manofmesopotamia7602
@manofmesopotamia7602 7 месяцев назад
maybe , we can use this tutorial to read gcode!
@alexandrev.3332
@alexandrev.3332 2 года назад
Format with FAT32 and 4096 bytes, only work with this
@NizarMohideen
@NizarMohideen 2 года назад
Thanks for the infomation
@amarashokraut2542
@amarashokraut2542 Месяц назад
I got errors ‘FIL’ has no member named ‘fsize’
@NizarMohideen
@NizarMohideen Месяц назад
use f_lseek(&fil, f_size(&fil)); instead. Thanks
@tienleminh8129
@tienleminh8129 2 года назад
11:50, after I built the code, it made an error: "region `RAM' overflowed by 8592 bytes " could you help me please
@NizarMohideen
@NizarMohideen 2 года назад
It seems like you are using STM32F103C6T6. You need to use at least STM32F103C8T6.
@tienleminh8129
@tienleminh8129 2 года назад
@@NizarMohideen I repaired it, thanks a lot for your support
@NizarMohideen
@NizarMohideen 2 года назад
Thanks
@jadsieltrrs6299
@jadsieltrrs6299 2 года назад
@@tienleminh8129 how did you fix it ?
@tienleminh8129
@tienleminh8129 2 года назад
@@jadsieltrrs6299 "It seems like you are using STM32F103C6T6. You need to use at least STM32F103C8T6"
@ufukcanaydogan7559
@ufukcanaydogan7559 2 года назад
Can ı run with Micro SD Card?
@NizarMohideen
@NizarMohideen 2 года назад
Yes. This module is for Micro SD Card
@ufukcanaydogan7559
@ufukcanaydogan7559 2 года назад
@@NizarMohideen Thank you, ı have another question. ı did everything but ı couldn't get data in my sd card. Where is my data?
@NizarMohideen
@NizarMohideen 2 года назад
When you format SD card in windows10 with FAT32, select 4096bytes for allocation unit size.
@ufukcanaydogan7559
@ufukcanaydogan7559 2 года назад
@@NizarMohideen I will try it. Thank you
@ufukcanaydogan7559
@ufukcanaydogan7559 2 года назад
@@NizarMohideen No sir, it wasn't run..:(
@blahman442
@blahman442 2 года назад
I get disk not ready error. What could be the reason?
@NizarMohideen
@NizarMohideen 2 года назад
Hi, 1. Check the card works on a PC and it’s file system is FAT32 2. Make sure SD card reader VCC gets 5V (Supply 5V to Micro-controller via USB before connecting st-link) 3. Try with a different SD card if you have another.
@blahman442
@blahman442 2 года назад
@@NizarMohideen I have tried everything earlier as well. It does not work. I used a 16 GB SD card of San disk formatted as FAT32. Gave external 5V supply. Card works perfectly fine when connected to arduino uno.
@NizarMohideen
@NizarMohideen 2 года назад
If you are using STM32F103C8T6,It should work. To check the solder joints in pins PA4,PA5 PA6 PA7 ,5V AND G, you can connect LED's on it and run a simple blink program. If solder joints are good, make sure PA7 - MOSI / PA6- MISO Make sure the library file name spellings fatfs_sd.h / fatfs_sd.c Make sure you followed all the CUBEIDE settings given below Click connectivity → Click SPI1 For Mode select Full Duplex Master Set PA4 to GPIO_Output Click Middleware → Click FATFS Tick User-defined Configuration → Set Defines For USE LFN (Use Long Filename) select Enabled with static working buffer on the BSS For Max SS (Maximum Sector Size) select 4096 After all if it still not works, you can send me the main.c - user_diskio.c - stm32f1xx_it.c (3 files) to my email nizarmohideen@hotmail.com, I can find any errors on it for you Good luck
@user-qw9ch7yo4g
@user-qw9ch7yo4g 2 года назад
me too, of cause using the EXACT same STM32F103C8T6 and card slot and etc. And I have checked hundreds times of pins and the cubide settings, but it alwals give me a FR_NOT_READY. When I debug into the code, it seems initialize failed, because SD_SendCmd(CMD0, 0) returned 255 instead of 1
@user-qw9ch7yo4g
@user-qw9ch7yo4g 2 года назад
Oh by the way. I have 4 different micro sd cards, they all returns FR_NOT_READY. Is it possible that the firmware package version has some problem? I'm using FW_F1 V1.8.0, and I don't know why stm32cubeide doesn't let choose version earlier than 1.8.0. of cause i have downloaded some old versions in package manager.
@vidyadharisakala2204
@vidyadharisakala2204 Год назад
Hi Nizar while i am running this program in sdio i am getting this error can you tell me why it is coming like that [STM32F407ZGTx.cpu] halted due to debug-request, current mode: Thread xPSR: 0x01000000 pc: 0x08000900 msp: 0x20020000
Далее
Interfacing with an SD Card
28:04
Просмотров 8 тыс.
Едим ЕДУ на ЗАПРАВКАХ 24 Часа !
28:51
Crazy Girl destroy RC CARS 👩🤪🚘🚨
00:20
Просмотров 4,2 млн
SD Card Interfacing with STM32 - STM32 SPI
15:32
Просмотров 10 тыс.
Едим ЕДУ на ЗАПРАВКАХ 24 Часа !
28:51