2025-01-28 05:38 AM
Hi! I am trying to learn about interfacing with an stm32f405 as a USB Mass Storage Device. My (homemade) development board has an onboard microSD card slot, and so I would like to present the card as my mass storage.
I'm running into some problems with this, however, and here are my symptoms:
I have tried swapping out my development board for an Adafruit Feather that uses the same exact microcontroller, and this exhibits the same behavior. I have tried swapping my memory card, and my USB cable.
This is my first foray into this, so I am rather inexperienced in knowing where/how to troubleshoot this. I have a vague sense that SD cards can be finicky, though I am not sure how true that is. I'm curious if anyone might be able to suggest some troubleshooting steps, or learning resources that might help me teach myself what might be going wrong here?
Thank you!
Solved! Go to Solution.
2025-01-29 04:55 AM - edited 2025-01-29 04:57 AM
Hm, digging through the forums, this "1-bit works, 4-bit doesn't" problem seems pretty commonly reported, and commonly traced to a HAL issue, rather than a hardware issue.
This solution:
seems to work in my case. Namely, HAL creates this code natively for my f4 MCU:
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_4B;
hsd.Init.HardwareFlowControl = SDIO_HARDWARE_FLOW_CONTROL_DISABLE;
hsd.Init.ClockDiv = 5;
if (HAL_SD_Init(&hsd) != HAL_OK)
{
Error_Handler();
}
if (HAL_SD_ConfigWideBusOperation(&hsd, SDIO_BUS_WIDE_4B) != HAL_OK)
{
Error_Handler();
}
and, if I change line 5 above to be:
hsd.Init.BusWide = SDIO_BUS_WIDE_1B;
such that we init at 1b mode, then shift to 4b mode, my device seems to present itself (and mount itself) fine on my macbook, and I can successfully copy a file to/from it.
2025-01-29 04:55 AM - edited 2025-01-29 04:57 AM
Hm, digging through the forums, this "1-bit works, 4-bit doesn't" problem seems pretty commonly reported, and commonly traced to a HAL issue, rather than a hardware issue.
This solution:
seems to work in my case. Namely, HAL creates this code natively for my f4 MCU:
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_4B;
hsd.Init.HardwareFlowControl = SDIO_HARDWARE_FLOW_CONTROL_DISABLE;
hsd.Init.ClockDiv = 5;
if (HAL_SD_Init(&hsd) != HAL_OK)
{
Error_Handler();
}
if (HAL_SD_ConfigWideBusOperation(&hsd, SDIO_BUS_WIDE_4B) != HAL_OK)
{
Error_Handler();
}
and, if I change line 5 above to be:
hsd.Init.BusWide = SDIO_BUS_WIDE_1B;
such that we init at 1b mode, then shift to 4b mode, my device seems to present itself (and mount itself) fine on my macbook, and I can successfully copy a file to/from it.