f_mkfs returns fa_not_ready
Hi all
I'm new in implementing SD-Card, however i've managed to run the example from the repository. I am using STM32429i-Eval Board with cubeMX and CubeIDE.
Question is that when I run the example code on the board it works fine but when I create a new project (code generated by cubeMX) and copy the example code in it, the function f_mkfs() returns FA_NOT_READY error. All the hardware pin configurations are according to the schematic provided by the Eval-Board. Have a look at my code please.
#include "main.h"
#include "fatfs.h"
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */
/* USER CODE END PTD */
/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
/* USER CODE END PD */
/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */
/* USER CODE END PM */
/* Private variables ---------------------------------------------------------*/
SD_HandleTypeDef hsd;
/* USER CODE BEGIN PV */
static uint8_t buffer[_MAX_SS];
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_SDIO_SD_Init(void);
/* USER CODE BEGIN PFP */
/* USER CODE END PFP */
/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
/* USER CODE END 0 */
/**
* @brief The application entry point.
* @retval int
*/
int main(void)
{
/* USER CODE BEGIN 1 */
uint8_t wtext[] = "this is test program";
uint32_t byteswritten;
FRESULT res;
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_SDIO_SD_Init();
MX_FATFS_Init();
/* USER CODE BEGIN 2 */
if(f_mount(&SDFatFS, (TCHAR const*)SDPath, 0) == FR_OK)
{
res = f_mkfs((TCHAR const*)SDPath, FM_ANY, 0, buffer, sizeof(buffer));
if(res == FR_OK)
{
if(f_open(&SDFile, "STM32.TXT", FA_CREATE_ALWAYS | FA_WRITE))
{
if(f_write(&SDFile, wtext, sizeof(wtext), (void *)&byteswritten) == FR_OK)
{
f_close(&SDFile);
}
}
}
}
FATFS_UnLinkDriver(SDPath);
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
}
