Mini64SE R6 + sdcard Coocox Fatfs spi
Hello. Quite a long time I been wanting to add to my development on microcontrollers such inexhaustible tool storage as sd card. For this we will use today Mini64SE R6 and cardholder sd card.
We will connect SPI1 у in following order:
PA4-CS
PA5-SCLK
PA6-MISO
PA7-MOSI
3.3v and GND to power supply with 47 uF capacitor close to the card holder.
Pins MOSI, MISO, CS connected to +3.3v thru 10К resistors.
Then decided to look for the finished project, so as to not have to deal with FATFS.
I found such a progect at first sight he could not meet my needs,but it was only at first then I had to connect it from the very beginning to FATFS . Plus the fact it was written in CooCox I decided to try it out, as yet not chosen a convenient programming environment for stm32.
Let us go to site http://www.coocox.org/Downloads.htm and download CoIDE, and install it.
Then download GCC ARM and install it to.
In CoIDE menu Progect>Select toolchain path setting a path to compiler
in my case it is C:\Program Files\GNU Tools ARM Embedded\4.7 2014q2\bin
Now download progect sd-test new
#include "stm32f10x_conf.h" #include "ff.h" char buff[1024]; // буфер для читання / запису int main(void) { SysTick_Config(SystemCoreClock /100);//10ms FRESULT result; // змонтувати диск FATFS FATFS_Obj; disk_initialize (0); result = f_mount(0, &FATFS_Obj); if (result != FR_OK) { //printf("Помилка монтування диска %d\r\n", result); } // Рахуемо файли в кореневому каталозі DIR dir; FILINFO fileInfo; int nFiles = 0; result = f_opendir(&dir, "/"); if (result == FR_OK) { while (((result = f_readdir(&dir, &fileInfo)) == FR_OK) && fileInfo.fname[0]) { nFiles++; } } f_closedir(&dir); // відкриваємо файл readme.txt для чтання FIL file; UINT nRead, nWritten; result = f_open(&file, "readme.txt", FA_OPEN_EXISTING | FA_READ); if (result == FR_OK) { f_read(&file, &buff, 1024, &nRead); f_close(&file); } // створюємо файл write.txt result = f_open(&file, "write.txt", FA_CREATE_ALWAYS | FA_WRITE); if (result == FR_OK) { f_write(&file, &buff, nRead, &nWritten); f_close(&file); } while(1) { } } void SysTick_Handler(void) { disk_timerproc (); // Тактування часових затримок FatFs }
Algorithm is simple mounting the file system > read the contents of a file readme.txt in buffer > write buffer to file write.txt. And thats it.