2018-02-20 03:47 AM
2018-02-20 06:28 AM
You're probably trashing the memory in the system because your BSP_SD_ReadBlocks() is trying to read into a 32-bit word. If you want to read/write 10 512-byte blocks you're going to need to use a 5KB block of RAM to achieve that.
Also writing to arbitrary blocks runs the risk of trashing the file system on the card.
Perhaps skip the block test, and see if FatFs functions better without them.
There seems to be an odd mix of references to SDIO and SPI to access the card
2018-02-20 09:55 AM
i am trying all thing to access SD Card using SDIO FATFS,
also as you suggested.but not any change in result. FR_DISK_ERR((2018-02-20 02:05 PM
There have been several thread on these types of issues, you'd want to instrument BSP_SD_ReadBlocks() to understand the interactions there, and perhaps reflect those in your initial read test.
You could see if less aggressive clocking works.
Not familiar with the socket/wiring in use here. I generally recommend using sockets with pull-ups there rather than on the STM32 side.
Here we use the STM32F407G-DISCO we use the STM32F4DIS-BB breakout board with microSD socket.
Look also at using the HAL examples rather than the CubeMX generated stuff, I'm not wading into debugging exercise with Cube.
2018-02-21 02:45 AM
Thanks for replying very fast.
but still my problem as it is. no any change in result.
As you suggested i am trying all thing.from hardware to software,I also using sockets with pull-ups, on the STM32 side.I also read many recent thread, related this issues.
but not solve my problem,Now this is very symple code for SDIO FATFS, you can seeany problem in my code?
/* Includes ------------------------------------------------------------------*/
&sharpinclude 'main.h'&sharpinclude 'stm32f4xx_hal.h'&sharpinclude '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);static void MX_SDIO_SD_Init(void);/* USER CODE BEGIN PFP */
/* Private function prototypes -----------------------------------------------*//* USER CODE END PFP */
/* USER CODE BEGIN 0 */
FATFS fatfs;FIL myfile;FRESULT fresult;uint8_t buffer[50];/* USER CODE END 0 *//**
* @brief The application entry point. * * @retval None */int main(void){ /* USER CODE BEGIN 1 *//* 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(); HAL_Delay(200); /* USER CODE BEGIN 2 */ /* USER CODE END 2 */ fresult = f_mount(&fatfs,'',1); /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) {/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */}
/**
* @brief System Clock Configuration * @retval None */void SystemClock_Config(void){RCC_OscInitTypeDef RCC_OscInitStruct;
RCC_ClkInitTypeDef RCC_ClkInitStruct;/**Configure the main internal regulator output voltage
*/ __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_HSE; RCC_OscInitStruct.HSEState = RCC_HSE_ON; RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; RCC_OscInitStruct.PLL.PLLM = 8; RCC_OscInitStruct.PLL.PLLN = 336; RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2; 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_DIV4; RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5) != 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 = 1;}
/** 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_GPIOH_CLK_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_14|GPIO_PIN_15 |GPIO_PIN_6|GPIO_PIN_7, GPIO_PIN_RESET);/*Configure GPIO pins : PD12 PD13 PD14 PD15
PD6 PD7 */ GPIO_InitStruct.Pin = GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15 |GPIO_PIN_6|GPIO_PIN_7; 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);}
/* USER CODE BEGIN 4 */
/* USER CODE END 4 */