2020-04-14 10:33 AM
Hey guys,
I'm pretty new to Stm32 controllers, but I might find a bug. Just want to report it, in case I am right.
Im using Stm32 Workbench Eclipse, Stm32CubeMX and a Nucleo-L476RG.
I tried to get a sd card working on my board. So I had a SD-Card onboard with a 4-bit bus on my Nucleo with following configs:
PC8 ------> SDMMC1_D0
PC9 ------> SDMMC1_D1
PC10 ------> SDMMC1_D2
PC11 ------> SDMMC1_D3
PC12 ------> SDMMC1_CK
PD2 ------> SDMMC1_CMD
The moment I set the settings in CubeMX I get this standard code as my SDMMC settings:
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;
First of all the (HAL_SD_Init(&hsd1) is missing.
Secondly the hsd1.Init.BusWide = SDMMC_BUS_WIDE_1B; is not set to 4B.
When I change it to 4B my whole IDE is not working in debug mode.
Is it me getting something wrong or why can't I use my sd card on a 4Bit bus?
Greetings,
Trung
2020-04-16 03:25 AM
Hello,
During initialization , the SD card must be configured with SDMMC_BUS_WIDE_1B, so it is normal to see this configuration during the initialization , after that we can switch the bus wide to 4B with the following function :
if (HAL_SD_ConfigWideBusOperation(&hsd1, SDMMC_BUS_WIDE_4B) != HAL_OK)
{
Error_Handler();
}
Of course all this configuration must be automatically generated by the STM32CubeMx.
Concerning the missing (HAL_SD_Init(&hsd1) , it is strange and i am not able to reproduce , can you send me your ioc file ?
Best Regards,
Mohamed Aymen.
2020-04-16 06:46 AM
Hi Mohamed,
of course, I will upload my ioc file.
In which case do I use the other two possibilities to initialize my sd ?
#define SDMMC_BUS_WIDE_1B ((uint32_t)0x00000000U)
-> #define SDMMC_BUS_WIDE_4B SDMMC_CLKCR_WIDBUS_0
-> #define SDMMC_BUS_WIDE_8B SDMMC_CLKCR_WIDBUS_1
It took me quite a while to understand that SDMMC_BUS_WIDE_1B is the only option working for me, since I didn't find any advices in any ref manual or datasheet.
Best Regards,
Trung Nguyen-Xuan
2020-04-16 07:49 AM
ST brings the interface up at 400 KHz 1-bit initially, and then increases speed and bus width.
The 4-bit wide bus is sensitive to noise, ringing and skewing, and has significantly less tolerance to how the socket/card is interfaced.
If the previously furnished demo code does not work, it suggests an interface level issue. If it did work, you need to double check the GPIO slew-rate and pull-up configurations being used in the failing code.
Known, working, build of code posted in the previous thread
2020-04-20 09:25 AM
Hello,
It will be internally checked.
Thank you and Best Regards,
Mohamed Aymen.
2020-04-20 09:40 AM
The problem maybe isn´t one ;) If you enable FatFS, the according HAL_SD_Init function isn´t inside the generated MX init function anymore. It´s somewhere inside the FatFS files (esp., when you enable the FatFS DMA template in cubeMX). These are copied over from predefined templates, but cubeMX is intelligent enough (exeptionally...), not to generate the HAL_SD_Init anymore because it already exists somewhere else...
2020-04-20 09:49 AM
Just found it: It´s inside FATFS->Target. The file is bsp_driver_sd.c and the function is:
__weak uint8_t BSP_SD_Init(void)
{
uint8_t sd_state = MSD_OK;
/* Check if the SD card is plugged in the slot */
if (BSP_SD_IsDetected() != SD_PRESENT)
{
return MSD_ERROR_SD_NOT_PRESENT;
}
/* HAL SD initialization */
sd_state = HAL_SD_Init(&hsd1);
/* Configure SD Bus width (4 bits mode selected) */
if (sd_state == MSD_OK)
{
/* Enable wide operation */
if (HAL_SD_ConfigWideBusOperation(&hsd1, SDMMC_BUS_WIDE_4B) != HAL_OK)
{
sd_state = MSD_ERROR;
}
}
/Charly
2020-04-22 07:21 AM
Hello @Community member-Xuan,
Best Regards,
Mohamed Aymen.