2017-11-29 05:53 AM
Good day everyone,
I'm not sure if this is a bug or I'm looking at this incorrectly, but It seems to be a bug.
While calling the f_mount function there is a point where SD_read is called.
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; endifif(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)) { } /* incase of a timeout return error */ if (ReadStatus == 0) { res = RES_ERROR; } else { ReadStatus = 0; timeout = HAL_GetTick();while((HAL_GetTick() - timeout) < SD_TIMEOUT)
{ if (BSP_SD_GetCardState() == SD_TRANSFER_OK) { res = RES_OK; if (ENABLE_SD_DMA_CACHE_MAINTENANCE == 1) /* the SCB_InvalidateDCache_by_Addr() requires a 32-Bit aligned address, adjust the address and the D-Cache size to invalidate accordingly. */ alignedAddr = (uint32_t)buff & ~3; SCB_InvalidateDCache_by_Addr((uint32_t*)alignedAddr, count*BLOCKSIZE + ((uint32_t)buff - alignedAddr)); endif break; } } } }return res;
}After this call my code enters
f(BSP_SD_ReadBlocks_DMA((uint32_t*)buff,(uint32_t) (sector),count) == MSD_OK)
and passes it successfully, after which it gets stuck in the while loop.
while((ReadStatus == 0) && ((HAL_GetTick() - timeout) < SD_TIMEOUT))
{ }After this the problem occurs and that is:
if (ReadStatus == 0)
{ res = RES_ERROR; }the function always gets stuck here no matter what. So i went and looked at all the calls for ReadStatus in my project and this popped up:
From here it seems there's one callback that will ensure the SD_Read passes and thats BSP_SD_ReadCpltCallback. Although this is never called anywhere in the project and therefore SD_Read always fails. Therefore it always remain 0 and the LL read function fails. This is cube generated.
Is this a mistake from my side or CubeMX??
I'm using the latest cube(V 4.0 and the latest Hal(1.8.0) for the stm32F7
f_mount-sdcard sdcard cubemx-project stm32f7-hal stm32f7Solved! Go to Solution.
2017-11-29 07:21 AM
Hello
Reishauer.Ian
,Iwill raise this issue internally forcheck and investigation.
Best Regards
Imen
2017-11-29 07:21 AM
Hello
Reishauer.Ian
,Iwill raise this issue internally forcheck and investigation.
Best Regards
Imen
2017-11-29 08:34 AM
Thank you, the write function seems fine as it internally sets the write flag to 1, it looks like this was just forgotten in the read function
2017-11-30 02:52 PM
Same issue here.
Furthermore, the Cube generated sd_diskio.c doesn't call BSP_SD_Init() during SD_initialize().
2017-12-01 04:47 PM
Same issue, after I implemented the fix to SD_initialize, as well as SD_read and SD_write I can successfully mount and open files. F_write still fails which seems very odd(cause I can create files), but trying to debug it. Once I figure out why its bugging out I should be able to completely use the FATFS system.
2017-12-02 04:00 AM
same issue with
V 4.22.1 and the latest Hal(1.8.0) for the stm32F7
2017-12-06 08:16 AM
Hi
Reishauer.Ian
,It seems you identified root cause of your issue as stated in
https://community.st.com/0D50X00009XkXg5SAF
.For others having similar issues, please do the following:
1) Re-defineSD_initialize as following (in case code is generated with CubeMX 4.23):
Depending on you application requirement:
FreeRTOS not used:
In the generated file 'your_project/src/sd_diskio.c', re-define 'SD_initialize' as following:DSTATUS SD_initialize(BYTE lun)
{ if(BSP_SD_Init() == MSD_OK) { Stat = SD_CheckStatus(lun); } return Stat; }FreeRTOS used:
In the generated file 'your_project/src/sd_diskio.c', re-define 'SD_initialize' as following:DSTATUS SD_initialize(BYTE lun)
{ Stat = STA_NOINIT; /* * check that the kernel has been started before continuing * as the osMessage API will fail otherwise */ if(osKernelRunning()) { if(BSP_SD_Init() == MSD_OK) { Stat = SD_CheckStatus(lun); } /* * if the SD is correctly initialized, create the operation queue */ if (Stat != STA_NOINIT) { osMessageQDef(SD_Queue, QUEUE_SIZE, uint16_t); SDQueueID = osMessageCreate (osMessageQ(SD_Queue), NULL); } } return Stat; }2) Apply the fix suggested by
Reishauer.Ian
in the other discussions.If you still face issues, please let us know about them.
-Amel
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2017-12-06 09:52 AM
Hi Amel, Both posts I Made are issues.
The one being the flag never being set (ReadStatus =1) and the state of the sdcard that is never returned to Ready.
I hope these help anyone that has a similar issue.
-Piet
2017-12-08 03:42 AM
Ok
Reishauer.Ian
,As already said by
DAHMEN.IMEN
, the case is already raised internally.Similar issue is already discussed in
https://community.st.com/0D50X00009XkWyLSAV
and a solution is suggeste there.You can test it and let us know if it is working for you.
-Amel
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2017-12-08 03:58 AM
Hi Amel,
My issues are completely resolved as mentioned after implementing the changes I have mentioned above. I understand the issues have been raised internally, I was merely replying to you.
Kind Regards,
Piet