Guest User

Untitled

a guest
Mar 16th, 2023
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. SetupSamplingTimer()
  2. {
  3. //Init clock
  4. RCC->APB2ENR |= RCC_APB2ENR_TIM8EN;
  5. //Main sampling timer
  6. TIM1->DIER = 0;
  7. TIM1->SR &= ~TIM_SR_UIF;
  8. TIM1->CNT = 0;
  9. TIM1->PSC = 0;
  10. TIM1->CR1 = TIM_CR1_URS;
  11. TIM1->ARR = period; //1Mhz clock it should be
  12. TIM1->CR2 = 0;
  13. TIM1->DIER = TIM_DIER_UDE;
  14. TIM1->EGR = TIM_EGR_UG;
  15. }
  16.  
  17. SetupSamplingDMA(void *dataBuffer, uint32_t dataTransferCount)
  18. {
  19. RCC_AHB1PeriphClockCmd(RCC_AHB1ENR_DMA2EN, ENABLE);
  20.  
  21. //TIM1_UP -> DMA2, Ch6, Stream5
  22. //DMA should be stopped before this point
  23. DMA2_Stream5->CR = (DMA_SxCR_CHSEL_1 | DMA_SxCR_CHSEL_2) | DMA_PDATAALIGN_BYTE | DMA_SxCR_MINC | DMA_SxCR_CIRC;
  24. DMA2_Stream5->M0AR = (uint32_t)dataBuffer;//samplingRam;
  25. DMA2_Stream5->PAR = (uint32_t)&(SAMPLING_PORT->IDR);
  26. DMA2_Stream5->NDTR = dataTransferCount; //transferCount->512
  27. DMA2_Stream5->FCR = DMA_SxFCR_DMDIS | DMA_SxFCR_FTH;
  28. }
  29.  
  30. //Start DMA & Timer
  31. DMA2->HIFCR = DMA_HIFCR_CTCIF5;
  32. DMA2_Stream5->CR |= DMA_SxCR_EN;
  33. TIM1->CR1 |= TIM_CR1_CEN;
Advertisement
Add Comment
Please, Sign In to add comment