AnsweredAssumed Answered

SRAM and DMA in STM32F7

Question asked by flodin.rickard on Oct 23, 2017
Latest reply on Oct 25, 2017 by waclawek.jan

I am working on a project where I have a STM32F7 which shall read data from an external SRAM using DMA.

 

The SRAM has 16 bit adressbus and 8 bit databus. I want the data to be copied to a 16bit buffer in the STM32F7 with DMA. However I only get the 8 bit data in the 16 bitbuffer, highest 8 bits are always 0.

 

The code looks like:

void PF_Init_DMA()
{
s_bTransferComplete = 0;
s_bTransferError = 0;

__HAL_RCC_DMA2_CLK_ENABLE();

s_hDMA.Init.Channel = DMA_CHANNEL_0; //DMA_CHANNEL_0
s_hDMA.Init.Direction = DMA_MEMORY_TO_MEMORY; //M2M transfer mode
s_hDMA.Init.PeriphInc = DMA_PINC_ENABLE; //Peripheral increment mode Enable
s_hDMA.Init.MemInc = DMA_MINC_ENABLE; //Memory increment mode Enable
s_hDMA.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE; //Peripheral data alignment : Word
s_hDMA.Init.MemDataAlignment = DMA_PDATAALIGN_HALFWORD; //memory data alignment : Word
s_hDMA.Init.Mode = DMA_NORMAL; //Normal DMA mode
s_hDMA.Init.Priority = DMA_PRIORITY_HIGH; //priority level : high
s_hDMA.Init.FIFOMode = DMA_FIFOMODE_DISABLE; //FIFO mode disabled
s_hDMA.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_FULL;
s_hDMA.Init.MemBurst = DMA_MBURST_SINGLE; //Memory burst
s_hDMA.Init.PeriphBurst = DMA_PBURST_SINGLE; //Peripheral burst

s_hDMA.Instance = DMA2_Stream0;
if(HAL_DMA_Init(&s_hDMA) != HAL_OK)
{
}

HAL_DMA_RegisterCallback(&s_hDMA, HAL_DMA_XFER_CPLT_CB_ID, TransferComplete);
HAL_DMA_RegisterCallback(&s_hDMA, HAL_DMA_XFER_ERROR_CB_ID, TransferError);

HAL_NVIC_SetPriority(DMA2_Stream0_IRQn, 0, 1);
HAL_NVIC_EnableIRQ(DMA2_Stream0_IRQn);

}

 

 


uint8 PF_Init_SRAM()
{
// Init SRAM
/* SRAM device configuration */
__HAL_RCC_FMC_FORCE_RESET();
__HAL_RCC_FMC_RELEASE_RESET();
HAL_SRAM_DeInit(&sramHandle);

sramHandle.Instance = FMC_NORSRAM_DEVICE;
sramHandle.Extended = FMC_NORSRAM_EXTENDED_DEVICE;

/* Timing configuration derived from system clock (up to 216Mhz)
for 72 Mhz as SRAM clock frequency */
Timing.AddressSetupTime = 2;
Timing.AddressHoldTime = 1;
Timing.DataSetupTime = 2;
Timing.BusTurnAroundDuration = 1;
Timing.CLKDivision = 3;
Timing.DataLatency = 2;
Timing.AccessMode = FMC_ACCESS_MODE_A;

 

sramHandle.Init.NSBank = FMC_NORSRAM_BANK1;
sramHandle.Init.DataAddressMux = FMC_DATA_ADDRESS_MUX_DISABLE;
sramHandle.Init.MemoryType = FMC_MEMORY_TYPE_SRAM;
sramHandle.Init.MemoryDataWidth = FMC_NORSRAM_MEM_BUS_WIDTH_8;
sramHandle.Init.BurstAccessMode = FMC_BURST_ACCESS_MODE_DISABLE;
sramHandle.Init.WaitSignalPolarity = FMC_WAIT_SIGNAL_POLARITY_LOW;
sramHandle.Init.WaitSignalActive = FMC_WAIT_TIMING_BEFORE_WS;
sramHandle.Init.WriteOperation = FMC_WRITE_OPERATION_DISABLE;
sramHandle.Init.WaitSignal = FMC_WAIT_SIGNAL_DISABLE;
sramHandle.Init.ExtendedMode = FMC_EXTENDED_MODE_DISABLE;
sramHandle.Init.AsynchronousWait = FMC_ASYNCHRONOUS_WAIT_ENABLE;
sramHandle.Init.WriteBurst = FMC_WRITE_BURST_DISABLE;
sramHandle.Init.ContinuousClock = FMC_CONTINUOUS_CLOCK_SYNC_ASYNC;
sramHandle.Init.WriteFifo = FMC_WRITE_FIFO_DISABLE;

sramHandle.hdma = PF_DMA_GetHandler();
/* Initialize the SRAM controller */
if(HAL_SRAM_Init(&sramHandle, &Timing, &Timing) != HAL_OK)
{
/* Initialization Error */
printf("SRAM Error\r\n");
SRAMInit = FALSE;
return PF_ERROR;
}

__HAL_RCC_FMC_CLK_ENABLE();
}

 

 

void PF_SRAM_Read(uint32_t *pAddress, uint16_t *pDstBuffer, uint32_t BufferSize)
{
HAL_SRAM_Read_DMA(&sramHandle, pAddress, pDstBuffer, BufferSize);
}

 

 

I use bank1 and reads data from adress:

#define EMI_START_ADDRESS ((uint32_t)0x60000000)

 

 

According to FMC in RM0410 it should be possible to use 8 bit SRAM datawith to 16 bit RAM but either way I try it doesn't work.

 

Please help me understand what is wrong here.

Outcomes