2020-02-19 11:48 AM
Hello,
i switch from 1bit mode to 4bit mode in cubeMX (latest version on linux) an the reading only works in debug mode, when i connect my board to only power it doesn't work anymore.
In CubeMX under SDIO the DMA2_RX and DMA2_TX is set to stream3 and stream6 of DMA2.
But not i the drivers... :(
.
So i did a little research and found that the sd_read function never used the DMA function.
Neighter in 1bit nor in 4bit mode.
sd_diskio.c
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;
}
Function to call.
uint8_t BSP_SD_ReadBlocks_DMA(uint32_t *pData, uint32_t ReadAddr, uint32_t NumOfBlocks)
Also a problem, when I use 4bit mode with and with out any rework, the SD reading only works in debug mode not in real life. So I am now completely confused..
Is there any fix? Why the 4bit Mode only workes in debug mode (free running with no break points)
Why 1bit mode only works in debug mode when i try the bug fix
uint8_t BSP_SD_ReadBlocks_DMA(uint32_t *pData, uint32_t ReadAddr, uint32_t NumOfBlocks)
{
HAL_SD_StateTypeDef state_return;
HAL_SD_CardStateTypeDef sd_card_state_return;
uint32_t timeout = 0;
/* Read block(s) in DMA transfer mode */
if (HAL_SD_ReadBlocks_DMA(&hsd, (uint8_t *) pData, ReadAddr, NumOfBlocks)
!= HAL_OK) { return MSD_ERROR; }
timeout = 0;
do
{
state_return = HAL_SD_GetState(&hsd);
timeout++;
} while ((HAL_SD_STATE_BUSY == state_return) && (SD_DATATIMEOUT > timeout));
if (HAL_SD_STATE_READY != state_return) { return MSD_ERROR; }
timeout = 0;
do
{
sd_card_state_return = HAL_SD_GetCardState(&hsd);
timeout++;
} while ((HAL_SD_CARD_TRANSFER != sd_card_state_return) && (SD_DATATIMEOUT > timeout));
if ((SD_DATATIMEOUT <= timeout)) { return HAL_TIMEOUT; }
return MSD_OK;
}
DRESULT SD_read(BYTE lun, BYTE *buff, DWORD sector, UINT count)
{
if (BSP_SD_ReadBlocks_DMA((uint32_t*) buff, (uint32_t) (sector),
count) != MSD_OK)
{
return RES_ERROR;
}
return RES_OK;
}
2020-02-19 12:14 PM
Which STM32?
Debugger can add delays.
I have 4-bit SDIO/SDMMC + DMA working on all STM32 I've used. (F4, F7, L4, H7)
HAL typically has working DMA examples, and FATFS has diskio.c templates for DMA, etc.
2020-02-19 12:39 PM
Sorry.
STM32F407
2020-02-19 12:43 PM
I use only these few lines of code:
FATFS *fs; /* Ponter to the filesystem object */
fs = malloc(sizeof (FATFS));
f_mount(fs ,"", 1);
// Function
FRESULT res;
FIL file;
UINT cnt;
uint32_t filesize=0;
res = f_open( &file, FileName, FA_READ );
if(res) return 1;
filesize= f_size(&file);
// res = f_lseek(&file,0x2c);
// if(res) return 2;
f_read (&file,&signed_Buff[0],512,&cnt);
2020-03-04 11:14 AM
After I update my cubeIDE the 1bit mode also doesn't work. My be it doesn't mount because I switched to the a 32GB SD Card (FAT32) but I doesn't think so.
2020-03-04 12:40 PM
The functions return error codes so you can determine what they objected too.
If you have a disk error you'll need to look deeper into the routines in diskio.c
If you have a EXFAT volume, you will need to enable support in the ffconf.h file
2020-03-04 12:53 PM
Make sure HW FLOW CONTROL is NOT enabled
Check that callback functions are NOT weakly defined
2020-03-17 01:25 PM
I will try. Thanks for answer
2020-04-20 11:57 AM
Found the solution here! :D I forgot to set Pull UPs