I am driving a 32 GB SD card with Keil MDK5 Flash File System v6.14.1 with core LFN debug mode.Init, Mounting, and also read operations from SD card works properly. But creating or deleting a file and then open it in write mode doesn't work at all.
device: stm32H750vbt6 with ARM CORTEX-M7
core clock (frequency): 480e6
SDMMC1 configured clock (frequency): 100e6
RTOS type is CMSIS-RTOS2 Keil RTX version 5 (RTX5)
Number of open files that configured in FS_Config.c file: 5
Heap Size = 0x2000 > 5 * (608)
Stack Size: 0x400
Card Detect Input pin and Write Protect Input pin: not available
initialization code:
//file fsys_init.c #include "fsys_init.h" SD_HandleTypeDef hsd1; //fsys_init called in app_main thraed void fsys_init(void){ static volatile fsStatus error_tp; error_tp = finit ("M:"); if (error_tp != fsOK) fsys_error_handler(fsys_finit_error, error_tp); osDelay(10); // Mount the M: drive. error_tp = fsOK + 1; while(error_tp != fsOK ){ error_tp = fmount ("M:"); } //HAL_SD_MspInit(&hsd1); } /** * @brief SD MSP Initialization * This function configures the hardware resources used in this example * @param hsd: SD handle pointer * @retval None */ void HAL_SD_MspInit(SD_HandleTypeDef* hsd) { GPIO_InitTypeDef GPIO_InitStruct = {0}; RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0}; if(hsd->Instance==SDMMC1) { /* USER CODE BEGIN SDMMC1_MspInit 0 */ /* USER CODE END SDMMC1_MspInit 0 */ /** Initializes the peripherals clock */ PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_SDMMC; PeriphClkInitStruct.PLL2.PLL2M = 1; PeriphClkInitStruct.PLL2.PLL2N = 25; PeriphClkInitStruct.PLL2.PLL2P = 2; PeriphClkInitStruct.PLL2.PLL2Q = 2; PeriphClkInitStruct.PLL2.PLL2R = 2; PeriphClkInitStruct.PLL2.PLL2RGE = RCC_PLL2VCIRANGE_3; PeriphClkInitStruct.PLL2.PLL2VCOSEL = RCC_PLL2VCOWIDE; PeriphClkInitStruct.PLL2.PLL2FRACN = 0.0; PeriphClkInitStruct.SdmmcClockSelection = RCC_SDMMCCLKSOURCE_PLL2; if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK) { fsys_error_handler(0, 0); } /* Peripheral clock enable */ __HAL_RCC_SDMMC1_CLK_ENABLE(); __HAL_RCC_GPIOC_CLK_ENABLE(); __HAL_RCC_GPIOD_CLK_ENABLE(); /**SDMMC1 GPIO Configuration PC8 ------> SDMMC1_D0 PC9 ------> SDMMC1_D1 PC10 ------> SDMMC1_D2 PC11 ------> SDMMC1_D3 PC12 ------> SDMMC1_CK PD2 ------> SDMMC1_CMD */ GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11 |GPIO_PIN_12; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; GPIO_InitStruct.Alternate = GPIO_AF12_SDIO1; HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); GPIO_InitStruct.Pin = GPIO_PIN_2; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; GPIO_InitStruct.Alternate = GPIO_AF12_SDIO1; HAL_GPIO_Init(GPIOD, &GPIO_InitStruct); /* SDMMC1 interrupt Init */ HAL_NVIC_SetPriority(SDMMC1_IRQn, 0, 0); HAL_NVIC_EnableIRQ(SDMMC1_IRQn); /* USER CODE BEGIN SDMMC1_MspInit 1 */ /* USER CODE END SDMMC1_MspInit 1 */ } } void fsys_error_handler(fsys_error id, fsStatus error_tp){ __asm("BKPT #0"); }
After debugging the following events occurred when I tried to open and create "M:\filesys\Dump_file.logo" in write mode:
Event, Time (sec), Component, Event Property, Value 0, 0.00039830, EvCtrl, EventRecorderInitialize, Restart Count = 1 1, 0.00040655, EvCtrl, EventRecorderStart, 2, 0.00236864, EvCtrl, EventRecorderInitialize, Restart Count = 2 3, 0.00237939, EvCtrl, EventRecorderStart, 4, 0.00262214, FsCore, finit, drive=0x0800AFBC 5, 0.23689052, FsCore, fmount, drive=0x0800AFBC 6, 6.21071641, FsCore, sys_open, name=0x080048C8 openmode=0x00000004 7, 6.34828006, FsFAT, FileIsNonExistent, drive=M0 8, 6.47961456, FsMcMCI, TransferError, instance=0 events=0x00000084 9, 6.52405997, FsMcMCI, TransferError, instance=0 events=0x00000084 10, 6.56378528, FsMcMCI, TransferError, instance=0 events=0x00000084 11, 6.60354884, FsMcMCI, TransferError, instance=0 events=0x00000084 12, 6.64327516, FsMcMCI, TransferError, instance=0 events=0x00000084 13, 6.68302375, FsMcMCI, TransferError, instance=0 events=0x00000084 14, 6.72276447, FsMcMCI, TransferError, instance=0 events=0x00000084 15, 6.76250128, FsMcMCI, TransferError, instance=0 events=0x00000084 16, 6.80345253, FsFAT, SectorWriteFailed, drive=M0 sector=32640 count=1
The event TransferError is generated when data transfer is active and data block CRC check fails or Memory Card Control Layer does not receive ARM_MCI_EVENT_TRANSFER_COMPLETE event from the MCI driver.
Clever engineers, please help me to solve these bad events!!
sd card info: