STM32 DMA application (a) data transmission between SRAM and flash

Recommended for you: Get network issues from WhatsUp Gold. Not end users.

One, why to use DMA?

DMA Full name: Direct MemoryAccess is the direct memory access,

It can directly manipulate memory so has the following advantages:

Without access to the CPU to operate with memory, this can liberate CPU out to do other things,

Because of the data transmission can he memory time, without CPU, so greatly accelerate the speed of data transmission, is a kind of high speed data transmission,

Two.DMA there are several ways of transmitting data:

(1)Memory to memory between; i.e.: SRAMßà SRAM

(2)The memory to between peripherals; (for example: serial data received from the data register à memory)

(3) Peripheral to the memory.,

Three. The transmission of data width is how, data transmission is what form? DMA data transmission in what quantities?

The A. data source address to a destination address width data transmission or transmission data form, there are several: 1 bytes); 2) half word; 3) the word [1 byte =8bit 1 half word =2 byte =16 1 full word =2 half word =4 byte =32]

65536 is the maximum amount of data transmission in B.

We look at the stm32f103ve data manual chapter ninth DMA probably understand the characteristics of DMA:

Four, how to use the DMA configuration software?

(1)The configuration of DMA

*Function name: Dma_Init  
*Function Description: use DMA to transmit data memory to achieve the purpose of flash high speed transmission
*Input parameters: None 
*Return value: no
*Other Description: no
*Current version: v1.0  
*Authors: Yin Xuan 
*Completion: December 1, 2013 
*Date modified version number changes modify the content 
void Dma_Init(void)
  DMA_InitTypeDef  DMA_InitStructure;
  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
	/* DMA channel6 configuration */
  DMA_InitStructure.DMA_PeripheralBaseAddr = (u32)SRC_Const_Buffer;			//Peripheral address
  DMA_InitStructure.DMA_MemoryBaseAddr = (u32)DST_Buffer;					//Memory address
  DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;   						//Peripherals as DMA source DMA_DIR_PeripheralDST; // peripheral as the destination address 
  DMA_InitStructure.DMA_BufferSize = BufferSize;							//The transmission size
  DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Enable;			//Increased peripheral address
  DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;					//Memory address increment enable
  DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word;	//Memory storage: byte DMA_MemoryDataSize_Word; // word (32 bit)
  DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Word;
  DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;		//DMA_Mode_Normal normal mode, delivered only once; DMA_Mode_Circular: circulation patterns, transport does not stop;
  DMA_InitStructure.DMA_Priority = DMA_Priority_High;
  DMA_InitStructure.DMA_M2M = DMA_M2M_Enable;
  DMA_Init(DMA1_Channel1, &DMA_InitStructure);

  /* Enable DMA Channel1 Transfer Complete interrupt */
  DMA_ITConfig(DMA1_Channel1, DMA_IT_TC, ENABLE);
  /* Get Current Data Counter value before transfer begins */
  CurrDataCounter= DMA_GetCurrDataCounter(DMA1_Channel1);
  /* Enable DMA Channel6 transfer */
  DMA_Cmd(DMA1_Channel1, ENABLE);

Set the DMA priority 2

*Function name: NVIC_Config  
*Function Description: interrupt priority configuration DMA
*Input parameters: None 
*Return value: no
*Other Description: no
*Current version: v1.0  
*Authors: Yin Xuan 
*Completion: December 1, 2013 
*Date modified version number changes modify the content 
void NVIC_Config(void)
	NVIC_InitTypeDef NVIC_InitStructure;
	/* Configure one bit for preemption priority -------------------------------- */

	 /* Enable DMA channel1 IRQ Channel */
	NVIC_InitStructure.NVIC_IRQChannel = DMA1_Channel1_IRQn;
	NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
	NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
	NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

3 in the stm3210x_it.c file to add the DMA interrupt function

* Function Name  : DMAChannel1_IRQHandler
* Description    : This function handles DMA Stream 1 interrupt request.
* Input          : None
* Output         : None
* Return         : None
void DMA1_Channel1_IRQHandler(void)
	/* Test on DMA Channel1 Transfer Complete interrupt */
  if(DMA_GetITStatus(DMA1_IT_TC1))		//DMA1_IT_TC1: channel 1 transmission complete interrupt
    /* Get Current Data Counter value after complete transfer */
   CurrDataCounter= DMA_GetCurrDataCounter(DMA1_Channel1); 	//The number of data to return the current DMA channel 1 remaining transmission
    /* Clear DMA Channel1 Half Transfer, Transfer Complete and Global interrupt pending bits */
    DMA_ClearITPendingBit(DMA1_IT_GL1);		//Clear interrupt 1 global interrupt

The 4 main function parts:

int main(void)
	int count;
	NVIC_SetVectorTable(NVIC_VectTab_FLASH,0x00);  // NVIC_VectTab_FLASH=0x08000000
// 	RCC_Config();
	/* Get Current Data Counter value before transfer begins */
	CurrDataCounter= DMA_GetCurrDataCounter(DMA1_Channel1);	//·µ»Øµ±Ç°DMAͨµÀx, Ê£Óà´ý´«ÊäÊý¾ÝÊýÄ¿
 	while( CurrDataCounter!=0) ;


Key problem

Ask 1:

Using position memory window observations of SRC_Const_Buffer and DST_Buffer's, can be found in SRC_Const_Buffer

The address is 0x08001384, namely, Flash; DST_Buffer address is 0x20000030, namely RAM,

Answer 1:

Cannot change its value variable (global and local) are stored in the FLASH, changes are stored in SRAM

The definition of SRC_Const_Buffer: uc32 SRC_Const_Buffert

Search uc32 source.

typedef const uint32_tuc32; /*!<Read Only */

The definition of DST_Buffer: u32DST_Buffer[BufferSize];

Search U32 source.

Typedef uint32_t u32;

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Posted by Cosmo at December 17, 2013 - 12:28 PM