FreeRTOS +FAT + STM32F746G Discovery

vnnetech wrote on Tuesday, November 19, 2019:

Hi everybody,
i am new with FreeRTOS and try to learn file system with FreeRTOS + FAT. Base to Demo on STM32F4 i modified the ff_disk.c for STM32F746G-DISCO board, and used heap_4.c instead of heap_5.c.
After SD Card was initial, i had prolem with function FF_SDDiskMount called in FF_SDDiskInit.
FF_Disk_t *FF_SDDiskInit( const char *pcName )
{

pxDisk->xStatus.bIsInitialised = pdTRUE;
pxDisk->xStatus.bPartitionNumber = xPartitionNumber;
if( FF_SDDiskMount( pxDisk ) == 0 )
{
FF_SDDiskDelete( pxDisk );
pxDisk = NULL;
}
else
{

}
I tried to debug and i saw the error is no partition has been found. The function FF_PartitionSearch in ff_ioman.c returned error after it was called. The error is at line 1071
FF_Error_t FF_PartitionSearch( FF_IOManager_t *pxIOManager, FF_SPartFound_t *pPartsFound )
{

FF_PRINTF( “FF_PartitionSearch: [%02X,%02X] No signature (%02X %02X), no PBR neither\n”,
FF_getChar( ucDataBuffer, 0 ),
FF_getChar( ucDataBuffer, 2 ),
FF_getChar( ucDataBuffer, FF_FAT_MBR_SIGNATURE ),
FF_getChar( ucDataBuffer, FF_FAT_MBR_SIGNATURE + 1 ) );

			/* No MBR and no PBR then no partition found. */
			xError = FF_ERR_IOMAN_INVALID_FORMAT | FF_PARTITIONSEARCH;
			break;

}
I was wondering if anyone has tried it on the STM32F746G-Disco, any help would be appreciated.
Thanks in advance!
Ngoc

heinbali01 wrote on Tuesday, November 19, 2019:

It looks like your lower-level driver doesn’t yet work.

Can you look at the very first initialisation, does it discover the SD-card parameters correctly, just as size and other things?

Is it possible to let it read the 512 bytes from sector-0? Can you attach it to your post?

vnnetech wrote on Wednesday, November 20, 2019:

Thanks Hein, that is the problem. The HAL_SD_ReadBlocks_DMA of STM32F7 need block address, and I still gave it the normal address like in STM32F4. Now I can go a step further.

heinbali01 wrote on Wednesday, November 20, 2019:

If I am not mistaken,the choice of using a block- versus a byte-address depends on (size of the) the card, doesn’t it?

vnnetech wrote on Thursday, November 21, 2019:

Hi Hein,
I am also new with ST Controller. What I saw the functions HAL_SD_ReadBlocks_DMA and HAL_SD_WriteBlocks_DMA in stm32f7xx_hal_sd.c are different in stm32f4xx_hal_sd.c
In stm32f7 it do not have param BlockSize
/**

  • @brief Reads block(s) from a specified address in a card. The Data transfer
  •     is managed by DMA mode. 
    
  • @note This API should be followed by a check on the card state through
  •     HAL_SD_GetCardState().
    
  • @note You could also check the DMA transfer process through the SD Rx
  •     interrupt event.
    
  • @param hsd Pointer SD handle
  • @param pData Pointer to the buffer that will contain the received data
  • @param BlockAdd Block Address from where data is to be read
  • @param NumberOfBlocks Number of blocks to read.
  • @retval HAL status
    */
    HAL_StatusTypeDef HAL_SD_ReadBlocks_DMA(SD_HandleTypeDef *hsd, uint8_t *pData, uint32_t BlockAdd, uint32_t NumberOfBlocks)

and in stm32f4 (I took it from demo sources code)
/**

  • @brief Reads block(s) from a specified address in a card. The Data transfer
  •     is managed by DMA mode.
    
  • @note This API should be followed by the function HAL_SD_CheckReadOperation()
  •     to check the completion of the read process
    
  • @param hsd: SD handle
  • @param pReadBuffer: Pointer to the buffer that will contain the received data
  • @param ReadAddr: Address from where data is to be read
  • @param BlockSize: SD card Data block size
  • @note BlockSize must be 512 bytes.
  • @param NumberOfBlocks: Number of blocks to read.
  • @retval SD Card error state
    */
    HAL_SD_ErrorTypedef HAL_SD_ReadBlocks_DMA(SD_HandleTypeDef *hsd, uint32_t *pReadBuffer, uint64_t ReadAddr, uint32_t BlockSize, uint32_t NumberOfBlocks)

heinbali01 wrote on Friday, November 22, 2019:

Hello Ngoc,
in stm32f4xx_hal_sd.c you will find this code:

  if (hsd->CardType == HIGH_CAPACITY_SD_CARD)
  {
    BlockSize = 512;
    ReadAddr /= 512;
  }

The variable CardType was set during the initialisation. SDHC cards use sector numbers, older SD cards use a byte offset.
The STM32F7 uses the same logic.

I hope this answers your question. If not, please say so.