Skip to main content
mrjaner
Associate II
November 13, 2014
Question

Dma external memory problem

  • November 13, 2014
  • 3 replies
  • 768 views
Posted on November 13, 2014 at 07:30

i want to transfer my src array to external memory, but i could transfer only first member of my array (0x01) to GPIO ports and hold, where is other 9 members? :( what can i do?


#define SRAM_BANK_ADDR ((uint32_t)0x60000000)

#define BUF_SIZE ((uint32_t)0x10)


const
uint32_t src[BUF_SIZE]= {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 0x08, 0x09, 0x10}


DMA_HandleTypeDef dmaHandleSram;


void
dmaInit(
void
)

{

dmaHandleSram.Init.Channel =DMA_CHANNEL_0; 

dmaHandleSram.Init.Direction =DMA_MEMORY_TO_MEMORY; 

dmaHandleSram.Init.PeriphInc =DMA_PINC_ENABLE; 

dmaHandleSram.Init.MemInc =DMA_MINC_ENABLE; 

dmaHandleSram.Init.PeriphDataAlignment =DMA_PDATAALIGN_WORD; 

dmaHandleSram.Init.MemDataAlignment =DMA_MDATAALIGN_WORD; 

dmaHandleSram.Init.Mode =DMA_NORMAL; 

dmaHandleSram.Init.Priority =DMA_PRIORITY_HIGH; 

dmaHandleSram.Init.FIFOMode =DMA_FIFOMODE_DISABLE; 

dmaHandleSram.Init.FIFOThreshold =DMA_FIFO_THRESHOLD_FULL; 

dmaHandleSram.Init.MemBurst =DMA_MBURST_SINGLE; 

dmaHandleSram.Init.PeriphBurst =DMA_PBURST_SINGLE; 


//Select the DMA instance to be used for the transfer : DMA2_Stream0

dmaHandleMem2Sram.Instance = DMA2_Stream0;


//Select Call-backs functions called after Transfer complete and Transfer error

dmaHandleMem2Sram.XferCpltCallback = dmaComplete;

dmaHandleMem2Sram.XferErrorCallback = dmaError;


//Initialize the DMA stream

if
(HAL_DMA_Init(&dmaHandleSram) != HAL_OK)

{

Error_Handler(); 
//Initialization Error

}


//Configure NVIC for DMA transfer complete/error interrupts

HAL_NVIC_SetPriority(DMA2_Stream0_IRQn, 0, 0);

HAL_NVIC_EnableIRQ(DMA2_Stream0_IRQn);



__DMA2_CLK_ENABLE();


//Initialize the DMA stream

if
(HAL_DMA_Init(&dmaHandleSram) != HAL_OK)

{

Error_Handler(); 
//Initialization Error

}



HAL_NVIC_SetPriority(DMA2_Stream1_IRQn, 0, 0);

HAL_NVIC_EnableIRQ(DMA2_Stream1_IRQn);


if
(HAL_DMA_Start_IT(&dmaHandleSram, (uint32_t)src, (uint32_t)0X60000000, size) != HAL_OK)

{

Error_Handler(); 
//Initialization Error

}

}


void
fmcSramInit(
void
)

{

SRAM_HandleTypeDef hsram;

FMC_NORSRAM_TimingTypeDef SRAM_Timing;


//SRAM Configuration

hsram.Instance = FMC_NORSRAM_DEVICE;

hsram.Extended = FMC_NORSRAM_EXTENDED_DEVICE;


SRAM_Timing.AddressSetupTime = 1; 

SRAM_Timing.AddressHoldTime = 1; 

SRAM_Timing.DataSetupTime = 1; 

SRAM_Timing.BusTurnAroundDuration = 0;

SRAM_Timing.CLKDivision = 5; 

SRAM_Timing.DataLatency = 0; 

SRAM_Timing.AccessMode = FSMC_ACCESS_MODE_A; 


hsram.Init.NSBank = FSMC_NORSRAM_BANK1; 
// 0x60000000 

hsram.Init.DataAddressMux = FSMC_DATA_ADDRESS_MUX_DISABLE; 

hsram.Init.MemoryType = FSMC_MEMORY_TYPE_PSRAM; 

hsram.Init.MemoryDataWidth = FSMC_NORSRAM_MEM_BUS_WIDTH_16;

hsram.Init.BurstAccessMode = FSMC_BURST_ACCESS_MODE_ENABLE;

hsram.Init.WaitSignalPolarity = FSMC_WAIT_SIGNAL_POLARITY_HIGH; 

hsram.Init.WrapMode = FSMC_WRAP_MODE_DISABLE;

hsram.Init.WaitSignalActive = FSMC_WAIT_TIMING_BEFORE_WS;

hsram.Init.WriteOperation = FSMC_WRITE_OPERATION_ENABLE;

hsram.Init.WaitSignal = FSMC_WAIT_SIGNAL_DISABLE;

hsram.Init.ExtendedMode = FSMC_EXTENDED_MODE_DISABLE; 

hsram.Init.AsynchronousWait = FSMC_ASYNCHRONOUS_WAIT_DISABLE;

hsram.Init.WriteBurst = FSMC_WRITE_BURST_ENABLE;


__FSMC_CLK_ENABLE();


//Initialize the SRAM controller

if
(HAL_SRAM_Init(&hsram, &SRAM_Timing, &SRAM_Timing) != HAL_OK)

{

//Initialization Error

Error_Handler();

}


}


void
FSMC_GPIOInit(
void
)

{

GPIO_InitTypeDef GPIO_InitStructure;


//Enable GPIOD and GPIOE clock

__GPIOD_CLK_ENABLE();

__GPIOE_CLK_ENABLE();


//Setup for output pins

GPIO_InitStructure.Mode = GPIO_MODE_AF_PP;

GPIO_InitStructure.Pull = GPIO_PULLUP;

GPIO_InitStructure.Speed = GPIO_SPEED_HIGH;

GPIO_InitStructure.Alternate = GPIO_AF12_FSMC;



// D0=PD14 D1=PD15 D2=PD0 D3=PD1 D4=PE7 D5=PE8 D6=PE9 D7=PE10 NOE=PD4 NWE=PD5 NWAIT=PD6 CLKOUT=PD3

//Configure PortD pins for us as FSMC output pins

GPIO_InitStructure.Pin = GPIO_PIN_14 | GPIO_PIN_15 | GPIO_PIN_3 | GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_3;

HAL_GPIO_Init(GPIOD, &GPIO_InitStructure);

GPIO_InitStructure.Pin = GPIO_PIN_7 | GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10;

HAL_GPIO_Init(GPIOE, &GPIO_InitStructure); 

}

best regards #dma-fsmc
This topic has been closed for replies.

3 replies

Amel NASRI
ST Technical Moderator
November 13, 2014
Posted on November 13, 2014 at 10:58

What is ''size'' value?

-Mayla-

To give better visibility on the answered topics, please click on "Best Answer" on the reply which solved your issue or answered your question.
mrjaner
mrjanerAuthor
Associate II
November 13, 2014
Posted on November 13, 2014 at 20:56

it is size of src array :( do you think it is wrong?

megahercas6
Associate III
November 13, 2014
Posted on November 13, 2014 at 21:38

DMA_InitStructure.DMA_BufferSize = 10;