我现在使用 CubeMx 4.23.0 和 STM32F7 1.8.0 MCU 的固件包是 Core746i 板上的 STM32F746。一切都是由 CubeMx 自动生成的。
主.c:
SCB_EnableICache();
SCB_EnableDCache();
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
MX_SDMMC1_SD_Init();
MX_USB_DEVICE_Init();
MX_FATFS_Init();
HAL_Delay(3000);
DebugString("start OK");
uint8_t res = 0;
FATFS SDFatFs;
FIL MyFile; /* File object */
char SD_Path[4];
res = f_mount(&SDFatFs, (TCHAR const*)SD_Path, 0);
sprintf(DebugStr, "f_mount = 0x%02X", res);
DebugString(DebugStr);
res = f_open(&MyFile, "test.txt", FA_READ);
sprintf(DebugStr, "f_open = 0x%02X", res);
DebugString(DebugStr);
sdmmc.c:
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 = 7;
//HAL_SD_Init(&hsd1);
// ^^^^^ I also tried this here
//HAL_SD_ConfigWideBusOperation(&hsd1, SDMMC_BUS_WIDE_4B)
//^^^^ and this
}
如果 f_mount(&SDFatFs, (TCHAR const*)SD_Path, 0) <- 此处为 1(强制安装),则输出为:
- f_mount = 0x03
- f_open = 0x01
使用 0(现在不要挂载)输出为:
- f_mount = 0x00
- f_open = 0x03
0x03 值是 FR_NOT_READY,但官方信息对此非常模糊
我尝试过的事情:
- 将 HAL_SD_Init(&hsd1) 添加到 MX_SDMMC1_SD_Init() 因为我没有找到 SD 卡 GPIO 初始化发生在哪里。
- 2 GB 无名 SD 卡,1 GB 创见卡。
- 不同的 hsd1.Init.ClockDiv 3 到 255。
- 彻底重新焊接一切。
- 使用 HAL_SD_ConfigWideBusOperation(&hsd1, SDMMC_BUS_WIDE_4B) 切换到 4 位宽总线;
- 打开和关闭引体向上。
但卡仍然没有安装。它采用 FAT 格式,在 PC 上工作,我尝试打开的文件存在,但为空。
如何让它安装?提前致谢!