cancel
Showing results for 
Search instead for 
Did you mean: 

Problem mounting SDCard on STM32h745 using HAL

JArap.1
Associate

Hi, I'm having some issues mounting my SDCARD on my board. I'm trying to write data to the SD card using SDIO 4-Wire and I'm using a STM32h745 Nucleo board with a Waveshare Adapter but so far, I've been unsuccessful in getting the SD card initialised. I'm able to initialise the card and the card is detected (I'm able to read CID Data and confirm it is the correct card) but when I try to mount the card:

void StartDefaultTask(void const * argument)
{
  /* USER CODE BEGIN StartDefaultTask */
 
	if(f_mount(&fs, SDPath, 0) == FR_OK)
	{
		HAL_GPIO_WritePin(GPIOE, GPIO_PIN_1, GPIO_PIN_SET);
	}
  /* Infinite loop */
  for(;;)
  {
    osDelay(1);
  }
  /* USER CODE END StartDefaultTask */
}

I seem to get stuck in the initial SD_read function in sd_diskio.c

DRESULT SD_read(BYTE lun, BYTE *buff, DWORD sector, UINT count)
{
  DRESULT res = RES_ERROR;
  uint32_t timer;
#if (osCMSIS < 0x20000U)
  osEvent event;
#else
  uint16_t event;
  osStatus_t status;
#endif
#if (ENABLE_SD_DMA_CACHE_MAINTENANCE == 1)
  uint32_t alignedAddr;
#endif
  /*
  * ensure the SDCard is ready for a new operation
  */
 
  if (SD_CheckStatusWithTimeout(SD_TIMEOUT) < 0)
  {
    return res;
  }
 
#if defined(ENABLE_SCRATCH_BUFFER)
  if (!((uint32_t)buff & 0x3))
  {
#endif
    /* Fast path cause destination buffer is correctly aligned */
    uint8_t ret = BSP_SD_ReadBlocks_DMA((uint32_t*)buff, (uint32_t)(sector), count);
 
    if (ret == MSD_OK) {
#if (osCMSIS < 0x20000U)
    /* wait for a message from the queue or a timeout */
    event = osMessageGet(SDQueueID, SD_TIMEOUT);

I get stuck at this line:

event = osMessageGet(SDQueueID, SD_TIMEOUT);

and the debugger never seems to break out of this.

I've searched through the forums and online and I've tried the following things:

Configured MPU for AXI_SRAM:

void MPU_Config(void)
{
  MPU_Region_InitTypeDef MPU_InitStruct = {0};
 
  /* Disables the MPU */
  HAL_MPU_Disable();
  /** Initializes and configures the Region and the memory to be protected
  */
  MPU_InitStruct.Enable = MPU_REGION_ENABLE;
  MPU_InitStruct.Number = MPU_REGION_NUMBER0;
  MPU_InitStruct.BaseAddress = 0x24000000;
  MPU_InitStruct.Size = MPU_REGION_SIZE_512KB;
  MPU_InitStruct.SubRegionDisable = 0x0;
  MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL0;
  MPU_InitStruct.AccessPermission = MPU_REGION_FULL_ACCESS;
  MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_ENABLE;
  MPU_InitStruct.IsShareable = MPU_ACCESS_NOT_SHAREABLE;
  MPU_InitStruct.IsCacheable = MPU_ACCESS_CACHEABLE;
  MPU_InitStruct.IsBufferable = MPU_ACCESS_NOT_BUFFERABLE;
 
  HAL_MPU_ConfigRegion(&MPU_InitStruct);
  /* Enables the MPU */
  HAL_MPU_Enable(MPU_PRIVILEGED_DEFAULT);
 
}

Disabled SD_TRANSCIEVER:

#define  USE_SD_TRANSCEIVER           0U               /*!< use uSD Transceiver */

PLL1Q is 96MHz and I'm using a clock divider of 2 for a 48MHz clock and as this version of the H7 is a 480MHz clock.

I attached a sample repository here at https://github.com/4ptrextor/H7Daq

Any help is appreciated. Beers/coffee on me.

EDIT: managed to mount the sdCard but the same problem occurs when I try to create a file to write to. I keep getting stuck and timing out at the SD_READ function

0 REPLIES 0