This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Access SD Card on RA6M5 Controller

Hi team,

I wanted to access the SD Card contents... both read and write operations on SD card in R7FA6M5BF3CFC microcontroller... Request you to please provide step by step instructions on how to handle this issue... Am using E2Studio ide

Am using SanDisk 64 GB SD card for this requirement...The Clock set for PCLKB is 50Mhz...And i have selected the stack SDHI(r_sdhi).. And g_transfer0 Transfer(r_dtc) i.e DTC instead of DMAC....

Here am not using any thread and am not wanting to use it... Below is my code 

void hal_entry(void)
{
/* TODO: add your own code here */
fsp_err_t err = FSP_SUCCESS;

g_transfer_complete_spi = true;

if (g_transfer_complete_spi == true)
{
//SD Card Implementation
for (uint32_t i = 0; i < SDHI_MAX_BLOCK_SIZE; i++)
{
g_src[i] = (uint8_t) ('A' + (i % 26));
}


R_BSP_SoftwareDelay (100U, BSP_DELAY_UNITS_MILLISECONDS);
/* Open the SDHI driver. */
err = R_SDHI_Open (&g_sdmmc0_ctrl, &g_sdmmc0_cfg);
assert(FSP_SUCCESS == err);

R_BSP_SoftwareDelay (100U, BSP_DELAY_UNITS_MILLISECONDS);
/* Check if card is inserted. */
err = R_SDHI_StatusGet (&g_sdmmc0_ctrl, &status);
assert(FSP_SUCCESS == err);
if (!status.card_inserted)
{
while (!g_card_inserted)
{
__NOP();
/* Wait for a card insertion interrupt. */
}
}

/* A device shall be ready to accept the first command within 1ms from detecting VDD min. Reference section 6.4.1.1
* "Power Up Time of Card" in the SD Physical Layer Simplified Specification Version 6.00. */
R_BSP_SoftwareDelay (1U, BSP_DELAY_UNITS_MILLISECONDS);
/* Initialize the SD card. This should not be done until the card is plugged in for SD devices. */
err = R_SDHI_MediaInit (&g_sdmmc0_ctrl, NULL);
assert(FSP_SUCCESS == err);
err = R_SDHI_Write (&g_sdmmc0_ctrl, g_src, 3, 1);
assert(FSP_SUCCESS == err);
while (!g_transfer_complete)
{
/* Wait for transfer. */
}
err = R_SDHI_Read (&g_sdmmc0_ctrl, g_dest, 3, 1);
assert(FSP_SUCCESS == err);
while (!g_transfer_complete)
{
/* Wait for transfer. */
}
}

#if BSP_TZ_SECURE_BUILD
/* Enter non-secure code */
R_BSP_NonSecureEnter();
#endif
}

void callback_sdcard(sdmmc_callback_args_t *p_args)
{

switch (p_args->event)
{
case SDMMC_EVENT_CARD_REMOVED:
__BKPT(0);
break;
case SDMMC_EVENT_CARD_INSERTED:
__BKPT(0);
break;
case SDMMC_EVENT_RESPONSE:
break;
case SDMMC_EVENT_SDIO:
break;
case SDMMC_EVENT_TRANSFER_COMPLETE:
g_transfer_complete = 1;
break;
case SDMMC_EVENT_TRANSFER_ERROR:
break;
case SDMMC_EVENT_ERASE_COMPLETE:
break;
case SDMMC_EVENT_ERASE_BUSY:
break;
default:
break;
}
}

Here the SD card is not getting detected... The SD card is in good condition... Here the Callback function is not getting triggerred... when i debugged using JLINK with the SD card inserted on Microcontroller , R_SDHI_Open (&g_sdmmc0_ctrl, &g_sdmmc0_cfg); is successful, and   err = R_SDHI_StatusGet (&g_sdmmc0_ctrl, &status); is also successful.. But inside the "status" parameter, There is "card_inserted" parameter which is always false... 

Request you to kindly do the needful.. Do let me know  for any queries...

 

Regards,

Vikram.

  




[locked by: IK_Renesas at 14:12 (GMT 0) on 12 Jan 2024]
Parents Reply
  • After checking the project you provided, I saw that you set mcu to run BKPT in sdcard_callback. So that when the sd card connects the mcu will came to BKPT, that may cause the mcu stop running normal code. Maybe you can change the process in sdcard_callback.

    And before open the sdhi, could you set the cs# pin to 0, aka the P415.

Children