cancel
Showing results for 
Search instead for 
Did you mean: 

STM3210C-Eval DMA-CRC

sukrubahadirarslan
Associate III
Posted on November 25, 2013 at 20:23

hello forum. I want to use DMA and CRC . 

First I want to calculate the CRC code and then I want to write this calculated CRC code in SRAM . So ı write this code :

#include ''stm32f10x.h''

#include ''stm32_eval.h''

#include <stdio.h>

#define CRC_DR_Address 0x40023000;

#define SRAM_Address   0x20000040;

uint32_t crc;

uint32_t crctestdata[] =

{0x01026604,   0x05060708,    0x090a0b0c,    0x0d0e0f00};

DMA_InitTypeDef Dma_Config_Anahtari;

NVIC_InitTypeDef Nvic_Config_Anahtari;

GPIO_InitTypeDef Gpio_Config_Anahtari;

void RCC_Configuration(void);

void Gpio_Configuration(void);

void Nvic_Configuration(void);

void Dma_Configuration(void);

void Dma_Interrupt_Configuration(void);

void Dma_Activation(void);

void DMA1_Channel1_IRQHandler()

{

DMA_ClearFlag(DMA1_FLAG_TC1);

DMA_ClearITPendingBit(DMA1_IT_TC1);

GPIO_SetBits(GPIOD,GPIO_Pin_7);

}

int main(void)

{

  /*!< At this stage the microcontroller clock setting is already configured, 

       this is done through SystemInit() function which is called from startup

       file (startup_stm32f10x_xx.s) before to branch to application main.

       To reconfigure the default setting of SystemInit() function, refer to

       system_stm32f10x.c file

     */   

  

RCC_Configuration();

Nvic_Configuration();

Gpio_Configuration();

Dma_Configuration();

Dma_Interrupt_Configuration();

Dma_Activation();    *** When I activate the dma channel , TCIF flag is set and then  SRAM is filled with default CRC -> DR value 0xFFFFFFFF

so why TCIF flag is set and how can ı solve this problem ?

CRC_ResetDR();

  crc = CRC_CalcBlockCRC(crctestdata,4);

  while (1)

  {

  }

}

#ifdef  USE_FULL_ASSERT

/**

  * @brief  Reports the name of the source file and the source line number

  *         where the assert_param error has occurred.

  * @param  file: pointer to the source file name

  * @param  line: assert_param error line source number

  * @retval None

  */

void assert_failed(uint8_t* file, uint32_t line)

  /* User can add his own implementation to report the file name and line number,

     ex: printf(''Wrong parameters value: file %s on line %d\r\n'', file, line) */

  /* Infinite loop */

  while (1)

  {

  }

}

#endif

void RCC_Configuration()

{

RCC_HCLKConfig(RCC_SYSCLK_Div1);

RCC_PCLK2Config(RCC_HCLK_Div1);

RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD,ENABLE);

RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1 | RCC_AHBPeriph_CRC,ENABLE);

}

void Dma_Configuration()

{

Dma_Config_Anahtari.DMA_Mode = DMA_Mode_Normal;

Dma_Config_Anahtari.DMA_M2M = DMA_M2M_Enable;

Dma_Config_Anahtari.DMA_MemoryInc = DMA_MemoryInc_Disable;

Dma_Config_Anahtari.DMA_PeripheralInc = DMA_PeripheralInc_Enable;

Dma_Config_Anahtari.DMA_MemoryDataSize = DMA_MemoryDataSize_Word;

Dma_Config_Anahtari.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word;

Dma_Config_Anahtari.DMA_Priority = DMA_Priority_VeryHigh;

Dma_Config_Anahtari.DMA_BufferSize = 4;

Dma_Config_Anahtari.DMA_DIR = DMA_DIR_PeripheralDST;

Dma_Config_Anahtari.DMA_MemoryBaseAddr = CRC_DR_Address;

Dma_Config_Anahtari.DMA_PeripheralBaseAddr = SRAM_Address;

DMA_Init(DMA1_Channel1,&Dma_Config_Anahtari);

}

void Dma_Interrupt_Configuration()

{

DMA_ITConfig(DMA1_Channel1,DMA_IT_TC,ENABLE);

}

void Nvic_Configuration()

{

Nvic_Config_Anahtari.NVIC_IRQChannel = DMA1_Channel1_IRQn;

Nvic_Config_Anahtari.NVIC_IRQChannelCmd = ENABLE;

Nvic_Config_Anahtari.NVIC_IRQChannelPreemptionPriority = 0x0f;

Nvic_Config_Anahtari.NVIC_IRQChannelSubPriority = 0x0f;

NVIC_Init(&Nvic_Config_Anahtari);

}

void Gpio_Configuration()

{

Gpio_Config_Anahtari.GPIO_Mode = GPIO_Mode_Out_PP;

Gpio_Config_Anahtari.GPIO_Pin = GPIO_Pin_7;

Gpio_Config_Anahtari.GPIO_Speed = GPIO_Speed_50MHz;

GPIO_Init(GPIOD,&Gpio_Config_Anahtari);

}

void Dma_Activation()

{

DMA_Cmd(DMA1_Channel1,ENABLE);

}

thank you.
3 REPLIES 3
Posted on November 25, 2013 at 20:54

The direction of the DMA is wrong.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
sukrubahadirarslan
Associate III
Posted on November 25, 2013 at 21:34

I think direction of dma is correct .

when I am changing the direction of dma CNDTR register is not decrease and SRAM still in default value.

Posted on November 25, 2013 at 23:05

I think direction of dma is correct. when I am changing the direction of dma CNDTR register is not decrease and SRAM still in default value.

Yet it fills your memory with junk, how do you rationalize that? You set the peripheral memory to be your ram buffer, and you set the peripheral as a destination.

// STM32F1xx CRC DMA - sourcer32@gmail.com
#include ''stm32f10x.h''
volatile int CrcComplete;
uint32_t TestVector[] =
{ 0x01026604, 0x05060708, 0x090a0b0c, 0x0d0e0f00 }; // 0x8F7F6AC8
/******************************************************************************/
void RCC_Configuration()
{
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD, ENABLE);
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1 | RCC_AHBPeriph_CRC, ENABLE);
}
/******************************************************************************/
void DMA_Configuration(void)
{
DMA_InitTypeDef DMA_InitStructure;
DMA_InitStructure.DMA_Mode = DMA_Mode_Normal; // Do it once
DMA_InitStructure.DMA_M2M = DMA_M2M_Enable; // Mem to Mem(Peripheral) - untriggered
DMA_InitStructure.DMA_Priority = DMA_Priority_VeryHigh;
DMA_InitStructure.DMA_BufferSize = 4; // Four 32-bit words
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST; // From MEMORY(SRAM) TO PERIPHERAL(CRC)
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; // Does move
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Word; // 32-bit
DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)&TestVector[0];
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; // Doesn't move
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word;
DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&CRC->DR;
DMA_Init(DMA1_Channel1,&DMA_InitStructure);
}
/******************************************************************************/
void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_InitStructure.NVIC_IRQChannel = DMA1_Channel1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_Init(&NVIC_InitStructure);
}
/******************************************************************************/
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOD, &GPIO_InitStructure);
}
/******************************************************************************/
void DMA1_Channel1_IRQHandler(void)
{
if (DMA_GetITStatus(DMA1_IT_TC1)) // Qualify
{
DMA_ClearITPendingBit(DMA1_IT_TC1); // Clear
GPIO_SetBits(GPIOD,GPIO_Pin_7);
CrcComplete = 1;
}
}
/******************************************************************************/
int main(void)
{
uint32_t crc;
/*!< 
At
this stage the microcontroller clock setting is already configured,
this is done through SystemInit() function which is called from startup
file (startup_stm32f10x_xx.s) before to branch to application main.
To reconfigure the default setting of SystemInit() function, refer to
system_stm32f10x.c file
*/
RCC_Configuration();
NVIC_Configuration();
GPIO_Configuration();
// Using DMA
DMA_Configuration();
CrcComplete
= 
0
;
CRC_ResetDR();
DMA_ITConfig(DMA1_Channel1, DMA_IT_TC, ENABLE);
DMA_Cmd(DMA1_Channel1, ENABLE);
while(CrcComplete == 0); // Spin
crc
= 
CRC
->DR;
// Manual
CRC_ResetDR();
crc = CRC_CalcBlockCRC(TestVector, 4);
while(1);
}
/******************************************************************************/
#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t* file, uint32_t line)
{
/* User can add his own implementation to report the file name and line number,
ex: printf(''Wrong parameters value: file %s on line %d

'', file, line) */
/* Infinite loop */
while (1)
{
}
}
#endif

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..