AnsweredAssumed Answered

Stm32F10X+FatFS+SDIO DMA HardFault

Question asked by drengubiak.branislav on Dec 15, 2015
Latest reply on Dec 17, 2015 by Edje
I have problem with STM32f103 FatFS library.
If I start it with 
SD_SetDeviceMode(SD_POLLING_MODE)
 everything works OK.

But when I change it to 
SD_SetDeviceMode(SD_DMA_MODE)
 it is fired HardFaultHandler.



    Thread #1 <main> (Suspended : Breakpoint)  
        HardFault_Handler() at exception_handlers.c:328 0x800011c  
        <signal handler called>() at 0xfffffff1
        0x0
        <signal handler called>() at 0xfffffff9
        SD_ReadBlock() at sdcard.c:916 0x800344c   
        disk_read() at diskio.c:95 0x80003ec   
        move_window() at ff.c:745 0x80004f6
        check_fs() at ff.c:2 184 0x800051a 
        find_volume() at ff.c:2 258 0x800060a  
        f_mount() at ff.c:2 441 0x8000984  
        <...more frames...>
JLinkGDBServerCL.exe   
 
[HardFault]
Stack frame:
 R0 =  10002000
 R1 =  00000001
 R2 =  00002A80
 R3 =  10001FFF
 R12 = 0000000D
 LR =  FFFFFFF9
 PC =  00000000
 PSR = 20000041
FSR/FAR:
 CFSR =  00020000
 HFSR =  40000000
 DFSR =  00000001
 AFSR =  00000000
Misc
 LR/EXC_RETURN= FFFFFFF1


Problem is fired when Reading FatFS->win. It is 512bytes buffer.
I align it by 
BYTE    __attribute__ ((aligned)) win [512];



sdio dma reading initialization is:
static void DMA_RxConfiguration(uint32_t *BufferDST, uint32_t BufferSize)
{
  DMA_InitTypeDef DMA_InitStructure;
 
 
  DMA_ClearFlag(DMA2_FLAG_TC4 | DMA2_FLAG_TE4 | DMA2_FLAG_HT4 | DMA2_FLAG_GL4);
 
 
  /* DMA2 Channel4 disable */
  DMA_Cmd(DMA2_Channel4, DISABLE);
 
 
  /* DMA2 Channel4 Config */
  DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)SDIO_FIFO_Address;
  DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)BufferDST;
  DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
  DMA_InitStructure.DMA_BufferSize = BufferSize / 4;
  DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
  DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
  DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word;
  DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Word;
  DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
  DMA_InitStructure.DMA_Priority = DMA_Priority_High;
  DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
  DMA_Init(DMA2_Channel4, &DMA_InitStructure);
 
 
  /* DMA2 Channel4 enable */
  DMA_Cmd(DMA2_Channel4, ENABLE);
}

Outcomes