使用CubeMX和CubeIDE。在sTM32 F446VET开发板上的SD卡遇到问题。 if(f_mount(&SDFatFS, (TCHAR const*)SDPath, 0) != FR_OK) { Error_Handler(); } else { /*DWORD fre_clust,tot_sect,fre_sect; FATFS *fs; f_getfree("1:",&fre_clust,&fs ); //if (res) die(res); /* Get total sectors and free sectors */ //tot_sect = (fs->n_fatent - 2) * fs->csize; // fre_sect = fre_clust * fs->csize;
/* Print the free space (assuming 512 bytes/sector) // printf("%10lu KiB total drive space.\n%10lu KiB available.\n", tot_sect / 2, fre_sect / 2);*/
res=f_mkfs((TCHAR const*)SDPath, FM_ANY, 0, rtext, sizeof(rtext)); if(res != FR_OK) { Error_Handler(); } else { //Open file for writing (Create) if(f_open(&SDFile, "STM32.TXT", FA_CREATE_ALWAYS | FA_WRITE) != FR_OK) { Error_Handler(); } else { //Write to the text file res = f_write(&SDFile, wtext, strlen((char *)wtext), (void *)&byteswritten); if((byteswritten == 0) || (res != FR_OK)) { Error_Handler(); } else { f_close(&SDFile); } } } } f_mount(&SDFatFS, (TCHAR const*)NULL, 0); 错误出现在f_mkfs()函数,它返回FR_NOT_READY错误。相同的代码在NUCLEO F446RE和STM32F746G-DISCO开发板上测试均正常工作,能够创建并写入文本文件。 使用逻辑分析仪连接SD卡时,时钟信号显示正常,但SDIO_CMD和SDIO_D0引脚完全没有信号。 是否可能和电阻有关?Discovery开发板的SDIO线路上使用了47K或4.7K电阻。
|