AnsweredAssumed Answered

STM3210C-Eval DMA-CRC

Question asked by arslan.bahadir on Nov 25, 2013
Latest reply on Nov 25, 2013 by Clive One
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.

Outcomes