Micro-controllers, wireless transmission and database
This project assumes you have already installed STM32CubeIDE. You need to have previously done a basic blink sketch with blue-pill using STM32CubeIDE. I have made a complete video from installing STM32CubeIDE to LED blink program. You can watch it by clicking this link. https://www.youtube.com/watch?v=kXg467nVd_A
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
Taken from https://blog.naver.com/eziya76/221188701172
Inside Core/Inc Folder
fatfs_sd.hInside Core/Src Folder
fatfs_sd.cInside Core/Src Folder
stm32f1xx_it.cInside FATFS/Target Folder
user_diskio.c/* USER CODE BEGIN PD */ FATFS fs; FIL fil; /* USER CODE END PD */ /* USER CODE BEGIN 2 */ HAL_Delay(500); f_mount(&fs, "", 0); f_open(&fil, "write.txt", FA_OPEN_ALWAYS | FA_WRITE | FA_READ); f_lseek(&fil, fil.fsize); f_puts("Hello from Nizar\n", &fil); f_close(&fil); /* USER CODE END 2 */
/* USER CODE BEGIN PD */ FATFS *pfs; DWORD fre_clust; uint32_t totalSpace, freeSpace; /* USER CODE END PD */ /* USER CODE BEGIN 2 */ f_getfree("", &fre_clust, &pfs); totalSpace = (uint32_t)((pfs->n_fatent - 2) * pfs->csize * 0.5); freeSpace = (uint32_t)(fre_clust * pfs->csize * 0.5); /* USER CODE END 2 */
/* USER CODE BEGIN Includes */ #include <string.h> /* USER CODE END Includes */ /* USER CODE BEGIN PD */ char buffer[100]; /* USER CODE END PD */ /* USER CODE BEGIN 2 */ f_open(&fil, "read.txt", FA_READ); // Reads line by line until the end while(f_gets(buffer, sizeof(buffer), &fil)) { // Can use the buffer for something useful // memset(buffer,0,sizeof(buffer)); } f_close(&fil); /* USER CODE END 2 */