2015-12-15 8:20 AM
I have problem with STM32f103 FatFS library.
If I start it withSD_SetDeviceMode(SD_POLLING_MODE)SD_SetDeviceMode(SD_DMA_MODE)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= FFFFFFF1BYTE __attribute__ ((aligned)) win [512];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);
}2015-12-15 8:43 AM
Make sure the stack is sufficiently large, and that if you DMA into the stack (local/auto variables) that the scope is valid over the entire DMA transaction.
I'd guess your DMA is trashing the stack, or other parts of the memory arena. You might want to fill unused memory, or guard regions around the DMA area, and confirm it's not exceeding its bounds.2015-12-15 11:39 PM
Stack is laaaaarge
__Main_Stack_Size = 4096;NVIC_Configuration();
Status = SD_Init();
Status = SD_GetCardInfo(&SDCardInfo);
if (Status == SD_OK) // ----------------- Select Card --------------------------------
Status = SD_SelectDeselect((u32) (SDCardInfo.RCA << 16));
if (Status == SD_OK) // Set Device Transfer Mode to DMA
Status = SD_SetDeviceMode(SD_DMA_MODE); // SD_POLLING_MODE SD_DMA_MODE SD_INTERRUPT_MODE
fr = f_mount(&FatFs, ''0:'', 1); General Registers General Purpose and FPU Register Group 
r0 268496896 
r1 512 
r2 0 
r3 1110443404 
r4 42 
r5 512 
r6 536874840 
r7 536874840 
r8 512 
r9 9 
r10 3372728174 
r11 3342186858 
r12 13 
sp 0x20009c98 
lr 4294967281 
pc 0x800011c <
HardFault_Handler
> 
xpsr 1627389955 
MSP 536911000 
PSP 626494284 
PRIMASK 0 
BASEPRI 0 
FAULTMASK 0 
CONTROL 0 2015-12-17 2:14 PM
__process_stack_size big enough?
