cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F4 DISCOVERY + SDIO 1BIT + MDK 5 ISSUE

Yadav
Associate II

Dear All,

I am working with STM32F4 Discovery board. I have been stuck with the sd card interface for last 1 week. I have used cubemx version 4.26 for creating this project. But F_mount function is not working.Please find the below code. and kindly help me out to solve this issue.

#include "main.h"

#include "stm32f4xx_hal.h"

#include "fatfs.h"

/* USER CODE BEGIN Includes */

/* USER CODE END Includes */

/* Private variables ---------------------------------------------------------*/

SD_HandleTypeDef hsd;

/* USER CODE BEGIN PV */

/* Private variables ---------------------------------------------------------*/

/* USER CODE END PV */

/* Private function prototypes -----------------------------------------------*/

void SystemClock_Config(void);

static void MX_GPIO_Init(void);

sta

int main(void)

{

 HAL_Init();

 SystemClock_Config();

 MX_GPIO_Init();

 MX_SDIO_SD_Init();

 MX_FATFS_Init();

UINT testbyte;

HAL_Delay(10);

if(f_mount(&SDFatFS,SDPath,1)==FR_OK)

{

HAL_GPIO_TogglePin(GPIOD,GPIO_PIN_12);

char mypath[]="WRITE1.TXT\0";

f_open(&SDFile,mypath,FA_WRITE|FA_CREATE_ALWAYS);

char *mydata="HELLO WORLD\0";

f_write(&SDFile,&mydata,sizeof(mydata),&testbyte);

f_close(&SDFile);

HAL_Delay(1000);

HAL_GPIO_TogglePin(GPIOD,GPIO_PIN_13);

}

 while (1)

 {

 }

}

void SystemClock_Config(void)

{

 RCC_OscInitTypeDef RCC_OscInitStruct;

 RCC_ClkInitTypeDef RCC_ClkInitStruct;

 __HAL_RCC_PWR_CLK_ENABLE();

 __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);

  /**Initializes the CPU, AHB and APB busses clocks 

  */

 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;

 RCC_OscInitStruct.HSIState = RCC_HSI_ON;

 RCC_OscInitStruct.HSICalibrationValue = 16;

 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;

 RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;

 RCC_OscInitStruct.PLL.PLLM = 8;

 RCC_OscInitStruct.PLL.PLLN = 50;

 RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4;

 RCC_OscInitStruct.PLL.PLLQ = 7;

 if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)

 {

  _Error_Handler(__FILE__, __LINE__);

 }

  /**Initializes the CPU, AHB and APB busses clocks 

  */

 RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK

               |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;

 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;

 RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;

 RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV8;

 RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV4;

 if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)

 {

  _Error_Handler(__FILE__, __LINE__);

 }

  /**Configure the Systick interrupt time 

  */

 HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);

  /**Configure the Systick 

  */

 HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);

 /* SysTick_IRQn interrupt configuration */

 HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);

}

/* SDIO init function */

static void MX_SDIO_SD_Init(void)

{

 hsd.Instance = SDIO;

 hsd.Init.ClockEdge = SDIO_CLOCK_EDGE_RISING;

 hsd.Init.ClockBypass = SDIO_CLOCK_BYPASS_DISABLE;

 hsd.Init.ClockPowerSave = SDIO_CLOCK_POWER_SAVE_DISABLE;

 hsd.Init.BusWide = SDIO_BUS_WIDE_1B;

 hsd.Init.HardwareFlowControl = SDIO_HARDWARE_FLOW_CONTROL_DISABLE;

 hsd.Init.ClockDiv = 0;

}

/** Configure pins as 

    * Analog 

    * Input 

    * Output

    * EVENT_OUT

    * EXTI

*/

static void MX_GPIO_Init(void)

{

 GPIO_InitTypeDef GPIO_InitStruct;

 /* GPIO Ports Clock Enable */

 __HAL_RCC_GPIOD_CLK_ENABLE();

 __HAL_RCC_GPIOC_CLK_ENABLE();

 /*Configure GPIO pin Output Level */

 HAL_GPIO_WritePin(GPIOD, GPIO_PIN_12|GPIO_PIN_13, GPIO_PIN_RESET);

 /*Configure GPIO pins : PD12 PD13 */

 GPIO_InitStruct.Pin = GPIO_PIN_12|GPIO_PIN_13;

 GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;

 GPIO_InitStruct.Pull = GPIO_NOPULL;

 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;

 HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);

}

void _Error_Handler(char *file, int line)

{

 /* USER CODE BEGIN Error_Handler_Debug */

 /* User can add his own implementation to report the HAL error return state */

 while(1)

 {

 }

 /* USER CODE END Error_Handler_Debug */

}

#ifdef USE_FULL_ASSERT

/**

 * @brief Reports the name of the source file and the source line number

 *     where the assert_param error has occurred.

 * @param file: pointer to the source file name

 * @param line: assert_param error line source number

 * @retval None

 */

void assert_failed(uint8_t* file, uint32_t line)

 /* USER CODE BEGIN 6 */

 /* User can add his own implementation to report the file name and line number,

   tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */

 /* USER CODE END 6 */

}

#endif /* USE_FULL_ASSERT */

1 REPLY 1

Sorry can't help with CubeMX issues, please review examples under HAL trees for working SDIO/FATFS examples, and port to F4-DISCO

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..