2017-11-17 07:19 PM
Hello.
Faced with the problem.
The code generated in the CubeMX for FatFs+SDIO does not work.
The example from the repository is working.
Library Chan 0.12s working, something is wrong in the code generator.
I tried all the tips read in community, but it all ends with the initialization of the SD. Is there anyone who solved this problem. I'm using version 4.22.1.
2017-11-18 04:32 AM
Good day.
I want to communicate the good news.
After spending a couple of sleepless nights and analyzing the work of the library HAL for working with SDIO + FATFS found to date the only option.
To restore the library functionality, three functions of recording, reading, and CTL must be replaced.
You can take them from the example from the ST in the file cd_diskio.c.
Well, fix the function SD_initialize
DSTATUS SD_initialize(BYTE lun)
{ // return SD_CheckStatus(lun); Stat = STA_NOINIT;if(BSP_SD_Init() == MSD_OK)
{ return SD_CheckStatus(lun); }return Stat;
}/**
* @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, SDMMC_DATATIMEOUT) == MSD_OK) { /* wait until the read operation is finished */ while(BSP_SD_GetCardState()!= MSD_OK) { } res = RES_OK; }return res;
}/**
* @brief Writes Sector(s) * @param lun : not used * @param *buff: Data to be written * @param sector: Sector address (LBA) * @param count: Number of sectors to write (1..128) * @retval DRESULT: Operation result */ #if _USE_WRITE == 1 DRESULT SD_write(BYTE lun, const BYTE *buff, DWORD sector, UINT count) { DRESULT res = RES_ERROR;if(BSP_SD_WriteBlocks((uint32_t*)buff,
(uint32_t)(sector), count, SDMMC_DATATIMEOUT) == MSD_OK) { /* wait until the Write operation is finished */ while(BSP_SD_GetCardState() != MSD_OK) { } res = RES_OK; }return res;
} #endif /* _USE_WRITE == 1 *//**
* @brief I/O control operation * @param lun : not used * @param cmd: Control code * @param *buff: Buffer to send/receive control data * @retval DRESULT: Operation result */ #if _USE_IOCTL == 1 DRESULT SD_ioctl(BYTE lun, BYTE cmd, void *buff) { DRESULT res = RES_ERROR; BSP_SD_CardInfo CardInfo;if (Stat & STA_NOINIT) return RES_NOTRDY;
switch (cmd)
{ /* Make sure that no pending write process */ case CTRL_SYNC : res = RES_OK; break;/* Get number of sectors on the disk (DWORD) */
case GET_SECTOR_COUNT : BSP_SD_GetCardInfo(&CardInfo); *(DWORD*)buff = CardInfo.LogBlockNbr; res = RES_OK; break;/* Get R/W sector size (WORD) */
case GET_SECTOR_SIZE : BSP_SD_GetCardInfo(&CardInfo); *(WORD*)buff = CardInfo.LogBlockSize; res = RES_OK; break;/* Get erase block size in unit of sector (DWORD) */
case GET_BLOCK_SIZE : BSP_SD_GetCardInfo(&CardInfo); *(DWORD*)buff = CardInfo.LogBlockSize; res = RES_OK; break;default:
res = RES_PARERR; }return res;
} #endif /* _USE_IOCTL == 1 */You can fix the file, save it and rewrite it after generation.
And you can make changes to the template and the file will be generated when the project is created.
Dear engineers.
Please correct this problem of the library.
I add a fixed tamplet for the F7 series.
Replacing this file along the way Disk:\Program Files\STMicroelectronics\STM32Cube\STM32CubeMX\db\templates, you will not need to make manual changes after the project is generated in CubeMX 4.1.
Best regards,
George.
________________ Attachments : fatfs_sd_diskio_template_c.ftl.zip : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006Hy2N&d=%2Fa%2F0X0000000b3z%2FJ4EoP6lSskV8shBBc64uJzj_DvJfYkaRAsV4SRIjZqs&asPdf=false2017-11-18 04:54 PM
Hello.
Today I spent some time editing the file fatfs_sd_diskio_template_c.ftl.
The problem is that the compilation conditions are not fulfilled. For this reason, there is one way, to create the cd_diskio.c file manually and after creating the project to rewrite its file into it.
How the functions should look, you can look in the file of the template.
An explanation of how to do this I gave in the example you.
Best regards,
George.
2018-01-22 01:16 AM
Thank You!
Your post helped me to save a lot of time!
2018-01-26 05:56 PM
The holiday continues.
The problem with the F7 FATFS series went from 4.23.0 to 4.24.0.
But if you use 4.22.1 with the library F7_1.9.0 to generate the project, it works fine.
It can be concluded that there is an error in the tamplets for the F7 series.
Find that yet failed.
Solve this problem please.
Best regards,
George.
2018-03-19 11:08 AM
I spent several nights on this problem. I tried with CubeMX Version 4.24.0 and the latest CubeMX Version 4.25.0, but the problem is not fixed yet.
Look like there are issues with these two functions generated by CubeMX version 4.24.0 and 4.25.0 relate to DMA.
My program get hang here.
Generated from CubeMX
BSP_SD_ReadBlocks_DMA((uint32_t*)buff, (uint32_t) (sector), count)
BSP_SD_WriteBlocks_DMA((uint32_t*)buff, (uint32_t) (sector), count)
From George above
BSP_SD_ReadBlocks((uint32_t*)buff,
(uint32_t) (sector),
count, SDMMC_DATATIMEOUT)
BSP_SD_WriteBlocks((uint32_t*)buff,
(uint32_t)(sector),
count, SDMMC_DATATIMEOUT)
I replaced the SD_read() and SD_write() functions generated by the CubeMX with the SD_read() and SD_write() functions from George. It works! Thanks George!
Nghia
2018-03-19 11:36 AM
Likely want DMA if you have any contention on the memory from DSI/LTDC LCD screens. Writing has easily triggered TX_UNDERRUN error in polled operation at nominal speeds.