Hello ı am using Mcuxpresso 11.1.1 and MIMXRT 1052 on custom board. I tried to use my sd card but can not detect sd card. Tried to modify "evkbimxrt1050_sdcard_polling" example. First ı link application to ram and change the SD_CD_SW connection.
Example use gpio_io,28 (GPIO_B1_12), we want to use gpio_io,24 (GPIO_B1_08). I used default settings.
Some of our schematics:
My Pins:
"evkbimxrt1050_sdcard_polling" examples pins :
Code stuck at this function :
status_t SDMMCHOST_WaitCardDetectStatus(SDMMCHOST_TYPE *base, const sdmmchost_detect_card_t *cd, bool waitCardStatus)
{
sdmmchost_detect_card_type_t cdType = kSDMMCHOST_DetectCardByGpioCD;
if (cd != NULL)
{
cdType = cd->cdType;
}
if (waitCardStatus != s_sdInsertedFlag)
{
/* Wait card inserted. */
do
{
if (cdType != kSDMMCHOST_DetectCardByGpioCD)
{
if (SDMMCHOST_CARD_DETECT_INSERT_STATUS(base))
{
s_sdInsertedFlag = true;
}
}
else
{
if (SDMMCHOST_CARD_DETECT_INSERT_STATUS(base))
{
s_sdInsertedFlag = true;
}
}
} while (waitCardStatus != s_sdInsertedFlag);
}
return kStatus_Success;
}
Hi Omer Kaan Basakinci ,
Thank you for your interest in NXP Semiconductor products and
for the opportunity to serve you.
In addition, modify the pin initialization, you need to do some other modification, for instance, adapt the BOARD_SDCardDetectInit() function in the BOARD_SD_Config() function.
So please go through the code carefully to find out where the places that need to modify.
Have a great day,
TIC
-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!
- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------
Hi jeremyzhou
Thanks for your reply,
I did some chnages in "sdcard_polling" and "sdcard_fatfs" so i can detect, init, write to sd card. However ı can do that with 1gb (fat) sd card. When ı tried to use 32gb (fat32) sd card, errors occurs at making file system (fatfs). 32gb sd card work with evaluation module perfectly, ı still get error at making file system. Do you know what cause that ?
Thanks for your time,
Kind Regards.
Hi Omer Kaan Basakinci ,
Thanks for your reply.
1) Do you know what causes that?
-- To figure it out, I think I need to know the more details about the phenomenon, so I was wondering if you can introduce the code changes and error message.
And did you try to test with 8G and 16G SD card? What's the testing result of them?
Have a great day,
TIC
-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!
- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------
Hi jeremyzhou
Thanks for your reply.
I tried 8gb and 16 gb sd card (fat 32) result not changed. Code stuck in ff.c folder at :
do { /* Fill FAT sectors */
n = (nsect > sz_buf) ? sz_buf : nsect;
if (disk_write(pdrv, buf, sect, (UINT)n) != RES_OK) LEAVE_MKFS(FR_DISK_ERR);
mem_set(buf, 0, ss);
sect += n; nsect -= n;
} while (nsect);
so cannot make file system in main() :
if (f_mkfs(driverNumberBuffer, FM_ANY, 0U, work, sizeof work))
{
PRINTF("Make file system failed.\r\n");
return -1;
}
Another problem caught my attention, when ı run the code for the first time, ı get the same error with 1gb sd card but when ı try it for the second time, the problem is solved and it does not appear again in my next attemps. When ı removed the card and try the other cards, the process turns back for 1gb sd card.
My changes:
Main:
In sdcardWaitCardInsert() function
SD_WaitCardDetectStatus(SD_HOST_BASEADDR, &s_sdCardDetect, true) changed to SD_WaitCardDetectStatus(SD_HOST_BASEADDR, &s_sdCardDetect, false) because in the card inserted mode sd_cd_sw signal should be low . Our design needs to work the opposite way.
Pin tool:
Changed gpıo 28 to gpıo 24 also include label and identifier changes.
in sdcard initilization at probe bus voltage:
Removed the check if card support 1.8v. I removed this part because it cause meaningless error.
status_t SD_ProbeBusVoltage(sd_card_t *card)
{
assert(card);
uint32_t applicationCommand41Argument = 0U;
status_t error = kStatus_Success;
/* 3.3V voltage should be supported as default */
applicationCommand41Argument |=
SDMMC_MASK(kSD_OcrVdd29_30Flag) | SDMMC_MASK(kSD_OcrVdd32_33Flag) | SDMMC_MASK(kSD_OcrVdd33_34Flag);
/* make sure card signal line voltage is 3.3v before initalization */
if ((card->usrParam.cardVoltage != NULL) && (card->usrParam.cardVoltage->cardSignalLine3V3 != NULL))
{
card->usrParam.cardVoltage->cardSignalLine3V3();
}
else
{
SDMMCHOST_SWITCH_VOLTAGE180V(card->host.base, false);
}
card->operationVoltage = kCARD_OperationVoltage330V;
/* allow user select the work voltage, if not select, sdmmc will handle it automatically */
if (kSDMMCHOST_SupportV180 != SDMMCHOST_NOT_SUPPORT)
{
applicationCommand41Argument |= SDMMC_MASK(kSD_OcrSwitch18RequestFlag);
}
do
{
/* card go idle */
if (kStatus_Success != SD_GoIdle(card))
{
error = kStatus_SDMMC_GoIdleFailed;
break;
}
/* Check card's supported interface condition. */
if (kStatus_Success == SD_SendInterfaceCondition(card))
{
/* SDHC or SDXC card */
applicationCommand41Argument |= SDMMC_MASK(kSD_OcrHostCapacitySupportFlag);
card->flags |= kSD_SupportSdhcFlag;
}
else
{
/* SDSC card */
if (kStatus_Success != SD_GoIdle(card))
{
error = kStatus_SDMMC_GoIdleFailed;
break;
}
}
/* Set card interface condition according to SDHC capability and card's supported interface condition. */
if (kStatus_Success != SD_ApplicationSendOperationCondition(card, applicationCommand41Argument))
{
error = kStatus_SDMMC_HandShakeOperationConditionFailed;
break;
}
/* check if card support 1.8V */
/* if ((card->flags & kSD_SupportVoltage180v))
{
error = SD_SwitchVoltage(card);
if (kStatus_SDMMC_SwitchVoltageFail == error)
{
break;
}
if (error == kStatus_SDMMC_SwitchVoltage18VFail33VSuccess)
{
applicationCommand41Argument &= ~SDMMC_MASK(kSD_OcrSwitch18RequestFlag);
card->flags &= ~kSD_SupportVoltage180v;
continue;
}
else
{
card->operationVoltage = kCARD_OperationVoltage180V;
break;
}
}*/
break;
} while (1U);
return error;
}
and last in board.h folder:
#define BOARD_USDHC_CD_GPIO_BASE GPIO2
#define BOARD_USDHC_CD_GPIO_PIN 28
#define BOARD_USDHC_CD_PORT_IRQ GPIO2_Combined_16_31_IRQn
#define BOARD_USDHC_CD_PORT_IRQ_HANDLER GPIO2_Combined_16_31_IRQHandler
changed to
#define BOARD_USDHC_CD_GPIO_BASE GPIO2
#define BOARD_USDHC_CD_GPIO_PIN 24
#define BOARD_USDHC_CD_PORT_IRQ GPIO2_Combined_16_31_IRQn
#define BOARD_USDHC_CD_PORT_IRQ_HANDLER GPIO2_Combined_16_31_IRQHandler
Thanks for your time,
Kind Regards.
Hi Omer Kaan Basakinci ,
Thanks for your reply.
I'd like to know the more details about your testing.
1) Whether the sdcard_polling demo project can work well when inserting the 8 and 32GB cards.
2) According to your reply, you found that code would be stuck in ff.c folder at :
do { /* Fill FAT sectors */
n = (nsect > sz_buf) ? sz_buf : nsect;
if (disk_write(pdrv, buf, sect, (UINT)n) != RES_OK) LEAVE_MKFS(FR_DISK_ERR);
mem_set(buf, 0, ss);
sect += n; nsect -= n;
} while (nsect);
I'd like to know whether it would print the message 'the Make file system failed' finally or just be stuck in above code.
Have a great day,
TIC
-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!
- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------
Hi jeremyzhou
Thanks for your reply.
1) Whether the sdcard_polling demo project can work well when inserting the 8 and 32GB cards.
I tried 8 and 32 gb, both did not worked. I tried different frequencies each, according to in the below code.
static void BOARD_USDHCClockConfiguration(void)
{
CLOCK_InitSysPll(&sysPllConfig_BOARD_BootClockRUN);
/*configure system pll PFD0 fractional divider to 24, output clock is 528MHZ * 18 / 24 = 396 MHZ*/
CLOCK_InitSysPfd(kCLOCK_Pfd0, 12U);
/* Configure USDHC clock source and divider */
CLOCK_SetDiv(kCLOCK_Usdhc1Div, 0U);
CLOCK_SetMux(kCLOCK_Usdhc1Mux, 1U);
}
2)I'd like to know whether it would print the message 'the Make file system failed' finally or just be stuck in above code.
If ı debug the code step by step prints message. And when ı step into the code , the code stucked.
Thanks for your time,
Kind Regards.
Hi Omer Kaan Basakinci ,
Thanks for your reply.
I'd like to know what the exact errors happen when running
sdcard_polling demo project for a test with the 8 and 32GB cards.
Further, I'd like to suggest you try to use the logic analyzer to visualize the signal, it may provide some clues about the errors.
Have a great day,
TIC
-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!
- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------