2017-05-14 12:03 AM
Hi there
I waste much time on mounting sdcard in my prgram. the chip is stm32f745vg and i work with Firmware version 1.7 CubMX 4.19 and Keil 5.16
in CubeMX, i choose SDMMC1 in 1-bit mode with clock 48MHz(PLLQ=9) and FatFS --> SD Card. i leave Fatfs Options in Default(no change). other Configurations:
Flash Interface --> Enable
ART ACCLERATOR --> Enable
Instruction PreFetch -->Enable
CPU ICach --> Enable
CPU DCach --> Enable
GPIO Configuration
SDMMC divide Factor=0
when i try to use f_mount function, i receive FR_DISK_ERR error as result Value.
no difference in Activating SD interrupt. my program is :
////////////////////////////////////////////////////////////////////////////
SD_HandleTypeDef hsd1;
FRESULT res3,res1,res2;FATFS SDFatFs; FIL MyFile;/* USER CODE BEGIN PV *//* Private variables ---------------------------------------------------------*//* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);void Error_Handler(void);static void MX_GPIO_Init(void);static void MX_SDMMC1_SD_Init(void);/* USER CODE BEGIN PFP */
/* Private function prototypes -----------------------------------------------*//* USER CODE END PFP */
/* USER CODE BEGIN 0 */
/* USER CODE END 0 */
int main(void)
{ uint32_t byteswritten; uint8_t wtext[] = 'This is STM32 working with FatFs';/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration----------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();/* Configure the system clock */
SystemClock_Config();/* Initialize all configured peripherals */
MX_GPIO_Init(); HAL_Delay(200); HAL_GPIO_WritePin(GPIOD,GPIO_PIN_1,GPIO_PIN_RESET); ---for activating uSD Power that Connected with trsistor HAL_Delay(1000); MX_SDMMC1_SD_Init(); HAL_SD_Init(&hsd1); HAL_Delay(200); MX_FATFS_Init();/* USER CODE BEGIN 2 */
res1=f_mount(&SDFatFs, SD_Path, 1); if(res1 != FR_OK) { /* FatFs Initialization Error */ HAL_GPIO_WritePin(GPIOD,GPIO_PIN_8,GPIO_PIN_SET); } else { res2=f_open(&MyFile, 'STM32.TXT', FA_CREATE_ALWAYS | FA_WRITE); if(res2 != FR_OK) { HAL_GPIO_WritePin(GPIOD,GPIO_PIN_9,GPIO_PIN_SET); } else { res3 = f_write(&MyFile, wtext, sizeof(wtext), (void *)&byteswritten); if((byteswritten == 0) || (res3 != FR_OK)) { /* 'STM32.TXT' file Write or EOF Error */ HAL_GPIO_WritePin(GPIOD,GPIO_PIN_10,GPIO_PIN_SET); } else { /*##-6- Close the open text file #################################*/ f_close(&MyFile); /*##-7- Open the text file object with read access ###############*/ } } } FATFS_UnLinkDriver(SD_Path); /* USER CODE END 2 *//* Infinite loop */
/* USER CODE BEGIN WHILE */ while (1) { /* USER CODE END WHILE *//* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
my SD Configuration is :
static void MX_SDMMC1_SD_Init(void)
{hsd1.Instance = SDMMC1;
hsd1.Init.ClockEdge = SDMMC_CLOCK_EDGE_RISING; hsd1.Init.ClockBypass = SDMMC_CLOCK_BYPASS_DISABLE; hsd1.Init.ClockPowerSave = SDMMC_CLOCK_POWER_SAVE_DISABLE; hsd1.Init.BusWide = SDMMC_BUS_WIDE_1B; hsd1.Init.HardwareFlowControl = SDMMC_HARDWARE_FLOW_CONTROL_DISABLE; hsd1.Init.ClockDiv = 0;}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Please Help me!!!!
thank you
2017-05-14 11:04 AM
Should your function call HAL_SD_Init(&hsd1, &SDCardInfo1); ?
Looking at the FatFs level isn't going to shine much light on failing layers below that.
2017-05-15 10:03 AM
the function HAL_SD_Init has just one input parameter. i think SDCardInfoTypeDef type has been omitted in Firmware version 1.6 and 1.7 .
2017-05-15 05:12 PM
Dear Ehsan Behravan.
Why not try reference board like STM32F746-Disco?AFAIK,Many problems lies on D.I.Y. hardware(lack of pullups,weakness powerlines....).2017-05-15 11:14 PM
Thanks for your reply.
my board is a custom board and i have not authority to change it to a Disco-Board.
I've Designed SD Circuit from ST example Boards. only difference is a transistor for selecting the power of sd card. it means i should RESET a GPIO to connect sd power. i will attach the circuit.
every yellow ports in the figure, is connected to MCU directly.
2017-05-15 11:49 PM
it worked. there is a problem in hardware level. I omitted the transistor(BCX53) and connected VDD_MCU to VDD_uSD directly. everthink is OK.In fact the transistor has decreased voltage level. so VDD was lower than Vdd High.
Thanks everyone for your answer.