Skip to main content
Trevor Jones
Senior
September 6, 2019
Question

does a 32GByte ultra SD work in FatFS ?

  • September 6, 2019
  • 22 replies
  • 3614 views

I have a shiny new Samsung EVO 32GB formated as 29.8GB Fat32

will it work ?

I have a H743

tried the FatFS application

it doesn't find the card.

FATFS_LinkDriver fails

This topic has been closed for replies.

22 replies

Tesla DeLorean
Guru
September 6, 2019

Should do, ClockDiv should be constrained by driver code. FATFS_LinkDriver is before the file system touches it.

Any other cards working? Card Present signal?

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
Tesla DeLorean
Guru
September 6, 2019

Don't reformat or use mkfs on the card

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
Trevor Jones
Senior
September 6, 2019

Its a new card, I only save 2 text files .

no other cards here.

what value should we have for ClockDiv?

I have the SDMMC1.2 clock source set to 48MHz,

Tesla DeLorean
Guru
September 6, 2019

Probably going to constrain it to 4 down stream. The SDMMC unit should typically clock at 200 MHz, likely limiting wire clock to 25 MHz

Make sure the TRANSCEIVER option is disabled in stm32h7xx_hal_conf.h if you don't actually have one.

CubeMX generated?

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
Trevor Jones
Senior
September 6, 2019

not cube generated,, hacked an application in the repository...

I have a cube file but not sure the correct way to initialize it to read a file into ram.

Tesla DeLorean
Guru
September 6, 2019

f_mount, f_open, f_read

Link Layer failing precedes all that though

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
Trevor Jones
Senior
September 6, 2019

gets stuck here in the cube file:

   if(f_mount(&fs, "", 1))

   {

      f_open(&file, "sample1.txt", FA_WRITE | FA_CREATE_ALWAYS); // < --- stuck here

Tesla DeLorean
Guru
September 6, 2019

Likely stuck elsewhere...

Figure out what it is spinning on, and that you have IRQ handlers, etc.

EVAL example will be using the transceiver.

You have a debug uart? which/pins?

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
Trevor Jones
Senior
September 6, 2019

std RTx1 PA9/PA10 for debug port.

turned of the TRANSCEIVER option = 0...

stuck here

DRESULT SD_read(BYTE lun, BYTE *buff, DWORD sector, UINT count)
{
 DRESULT res = RES_ERROR;
 ReadStatus = 0;
 uint32_t timeout;
#if (ENABLE_SD_DMA_CACHE_MAINTENANCE == 1)
 uint32_t alignedAddr;
#endif
 
 if(BSP_SD_ReadBlocks_DMA((uint32_t*)buff,
 (uint32_t) (sector),
 count) == MSD_OK)
 {
 /* Wait that the reading process is completed or a timeout occurs */
 timeout = HAL_GetTick();
 while((ReadStatus == 0) && ((HAL_GetTick() - timeout) < SD_TIMEOUT)) /// <---- stuck here
 {
 }
 /* incase of a timeout return error */
 if (ReadStatus == 0)
 {
 res = RES_ERROR;
 }
 else

Trevor Jones
Senior
September 6, 2019

set SDMMC1.2 clock to 200MHz

added this, but now it wont compile.

"

Error      undefined reference to `FS_FileOperations'   H743_LCD_2   C:\Users\DAVE\STM32Cube\Repository\STM32Cube_FW_H7_V1.5.0\Projects\H743-144-LCD1\Src\bios.c   250   

		if(FATFS_LinkDriver(&SD_Driver, SDPath) == 0)
	{
		FRESULT res;
 
		res = f_mkfs(SDPath, FM_ANY, 0, workBuffer, sizeof(workBuffer));
 
		if (res != FR_OK)
		{
			Error_Handler();
		}
 
		FS_FileOperations();
	}
 
	/* Unlink SD diskio driver */
	FATFS_UnLinkDriver(SDPath);

Tesla DeLorean
Guru
September 6, 2019

Yeah, wouldn't do that, apt to trash the media. Get READ working 100% first

FS_FileOperations() is some LCD User Interface stuff

Do this first

{

 FATFS *fs;

 DWORD fre_clust, fre_sect, tot_sect;

 /* Get volume information and free clusters of drive 1 */

 res = f_getfree("", &fre_clust, &fs);

 if (res != FR_OK)

 {

  printf("res = %d f_getfree\n", res);

  return;

 }

 switch(fs->fs_type)

 {

  case FS_FAT12 : puts("FAT12"); break;

  case FS_FAT16 : puts("FAT16"); break;

  case FS_FAT32 : puts("FAT32"); break;

  case FS_EXFAT : puts("EXFAT"); break;

  default : puts("Unknown FAT");

 }

 /* Get total sectors and free sectors */

 tot_sect = (fs->n_fatent - 2) * fs->csize;

 fre_sect = fre_clust * fs->csize;

 /* Print the free space (assuming 512 bytes/sector) */

 printsize(tot_sect / 2, "total drive space");

 printsize(fre_sect / 2, "available");

 printsize((tot_sect - fre_sect) / 2, "used");

}

in the sd_diskio_dma

/**

 * @brief Rx Transfer completed callbacks

 * @param hsd: SD handle

 * @retval None

 */

void BSP_SD_ReadCpltCallback(void)

{

 ReadStatus = 1;

}

in the bsp

/**

 * @brief Rx Transfer completed callbacks

 * @param hsd: SD handle

 * @retval None

 */

void HAL_SD_RxCpltCallback(SD_HandleTypeDef *hsd) // <- make sure you have this

{

 BSP_SD_ReadCpltCallback(); // which calls this, that flags completion

}

Or do without DMA

/**

 * @brief Reads Sector(s)

 * @param lun : not used

 * @param *buff: Data buffer to store read data

 * @param sector: Sector address (LBA)

 * @param count: Number of sectors to read (1..128)

 * @retval DRESULT: Operation result

 */

DRESULT SD_read(BYTE lun, BYTE *buff, DWORD sector, UINT count)

{

 DRESULT res = RES_ERROR;

 if(BSP_SD_ReadBlocks((uint32_t*)buff,

            (uint32_t) (sector),

            count, SD_TIMEOUT) == MSD_OK)

 {

  /* wait until the read operation is finished */

  while(BSP_SD_GetCardState()!= MSD_OK)

  {

  }

  res = RES_OK;

 }

 return res;

}

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
Bill Dempsey
Associate III
September 6, 2019

"does a 32GByte ultra SD work in FatFS ?"

I'm able to use one with a F446 running FatFS,,,, I use the mbed libs for SD and not had an issue.

Tesla DeLorean
Guru
September 6, 2019

This is a non-DMA test for the SR1, so same USART1

Should output stats and a directory for card, then clocks/plls

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
Trevor Jones
Senior
September 6, 2019
I will have to check that when I get home.
but from the code on the forum,
I got this result..
res = 12 f_getfree