2018-11-22 05:35 AM
Hello
I'm testing implementation of sdcard / FatFS on F446.
First I started with the example. It works.
Now, I'm trying to implement a basic test app created from scratch with CubeMx.
I configured a simple project with fatFS, SDIO, no DMA, no OS.
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration----------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_DMA_Init();
MX_SDIO_SD_Init();
MX_FATFS_Init();
/* USER CODE BEGIN 2 */
testSD();
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1) {
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
}
void testSD() {
if (f_mount(&SDFatFS, (TCHAR const*) SDPath, 0) == FR_OK) {
if (f_mkfs(SDPath, FM_ANY, 0, workBuffer, sizeof(workBuffer)) != FR_OK) {
FIL file;
if (f_open(&file, "a.txt", FA_CREATE_ALWAYS | FA_WRITE) == FR_OK) {
uint32_t byteswritten; /* File write/read counts */
uint8_t wtext[] = "This is STM32 working with FatFs uSD\r\n";
f_write(&file, wtext, sizeof(wtext), (void *) &byteswritten);
f_close(&file);
}
}
}
}
With this code, is seems that the SDMMC module does not answer to any command and the first one
happens with this call stack:
SDMMC_GetCmdResp1() at stm32f4xx_ll_sdmmc.c:1 197
SDMMC_CmdAppCommand() at stm32f4xx_ll_sdmmc.c:892
SD_PowerON() at stm32f4xx_hal_sd.c:2 561
HAL_SD_InitCard() at stm32f4xx_hal_sd.c:386
HAL_SD_Init() at stm32f4xx_hal_sd.c:335
BSP_SD_Init() at bsp_driver_sd.c:81
SD_initialize() at sd_diskio.c:146
disk_initialize() at diskio.c:100
f_mkfs() at ff.c:5 323
initFS() at testSD.c:34
testSD() at testSD.c:123
main() at main.c:117
SDMMC_GetCmdResp1() returns SDMMC_ERROR_CMD_RSP_TIMEOUT.
I did compare the configuration of my app and the example. I compared clocks, interruptions (it seems that none is used).
I also compared the calls that are made to sd or fatFS libs and I can't see the difference.
What did I miss?
If needed, ioc file is here: https://we.tl/t-6FzT0Plvh4 .
Thanks
Julien
2018-11-22 07:49 AM
Almost certainly not an issue with top level code, so focus on the low level plumbing.
Also I would not MKFS on known good formatted SD Cards.
Start at the lowest level, and have test code that only reads.
Disable Flow control.
Dump registers (RCC, SDIO) and compare/contrast working/non-working.
Surprised there would be no interrupt handler code.
Review other threads with issues using CubeMX SDIO/SDMMC, automated tools tend to break things consistently.
2018-11-27 06:32 AM
Pff, my bad. SD pins where not the same in the soft and hard....
Thanks for helping a mentally disabled...