Skip to main content
tkor.1
Associate
November 12, 2020
Question

DMA CCR1 CCR2 conflict I can have signal on PB6 or PB7 but not both on one time. by changing CCR1 and CCR2 arrangement. CCR1, CCR1 =signal on PB6 CCR1, CCR2 = signal on PB7 CCR2, CCR2 = signal on PB7 CCR2, CCR1 = signal on PB6

  • November 12, 2020
  • 3 replies
  • 727 views

..

This topic has been closed for replies.

3 replies

tkor.1
tkor.1Author
Associate
November 12, 2020
#define SAMPLES 100
#include <libmaple/dma.h>
 
dma_tube_config dma_cfg, dma_cfg2;
int val1[SAMPLES];
int val2[SAMPLES]; // *******************
int amp = 35;
int cnt = 0;
int time_track = 0;
float stp = 6.2831 / SAMPLES;
int ret = 17;
int out1 = PB7; // TIM4_CH2 DMA_CH4 . 
int out2 = PB6; // TIM4_CH1 DMA_CH3 . *************************** 
 
timer_dev *dev1 = PIN_MAP[out2].timer_device; 
timer_dev *dev2 = PIN_MAP[out2].timer_device;
 
void timer_conf()
{
// PB7 TIM4_CH2 DMA_CH4
 timer_dma_set_base_addr(dev1, TIMER_DMA_BASE_CCR2); // CCR1, CCR1 = PB6
 timer_dma_set_burst_len(dev1, 1); // CCR1, CCR2 = PB7
 timer_dma_enable_req(dev1, PIN_MAP[out1].timer_channel); //CCR2, CCR2 = PB7
 timer_set_reload(dev1, 102); //CCR2, CCR1 = PB6
 timer_set_prescaler(dev1, 0);
 
 
 // PB6 TIM4_CH1 DMA_CH3 . *********************
 timer_dma_set_base_addr(dev2, TIMER_DMA_BASE_CCR2);
 timer_dma_set_burst_len(dev2, 1);
 timer_dma_enable_req(dev2, PIN_MAP[out2].timer_channel);
 timer_set_reload(dev2, 102);
 timer_set_prescaler(dev2, 0);
}
void dma_conf()
{
 dma_init(DMA1);
 // PB7 TIM4_CH2 DMA_CH4
 // PB6 TIM4_CH1 DMA_CH3
 dma_cfg.tube_dst = &(dev1->regs.gen->DMAR); // PB7
 dma_cfg.tube_dst = &(dev2->regs.gen->DMAR); // PB6********************
 dma_cfg.tube_src = val1; // PB7
 dma_cfg.tube_src = val2; // PB6********************
 dma_cfg.tube_src_size = DMA_SIZE_32BITS;
 dma_cfg.tube_nr_xfers = SAMPLES;
 dma_cfg.tube_flags = DMA_CFG_SRC_INC | DMA_CFG_CIRC;
 
 dma_cfg.tube_req_src = DMA_REQ_SRC_TIM4_CH2; //PB7
 dma_cfg.tube_req_src = DMA_REQ_SRC_TIM4_CH1; //PB6 ********************
 dma_cfg.target_data = 0;
 ret = dma_tube_cfg(DMA1, DMA_CH4, &dma_cfg);
 ret = dma_tube_cfg(DMA1, DMA_CH3, &dma_cfg);
}
void dma_start()
{
 // PB7 TIM4_CH2 DMA_CH4
 dma_enable(DMA1, DMA_CH4);
 timer_resume(dev1);
 dma_enable(DMA1, DMA_CH3);
 timer_resume(dev2);
 
}
void init_wave()
{
 int i;
 for (i = 0; i < SAMPLES; i++)
 {
 val1[i] = 50 + amp * sin(stp * i);
 val2[i] = 50 + amp * sin(stp * i); //************************
 }
}
void setup() {
 pinMode(out1, PWM);
 pinMode(out2, PWM);
 
 
 timer_conf();
 dma_conf();
 dma_start();
 init_wave();
}
void loop() {
}

waclawek.jan
Super User
November 13, 2020

What is this, Arduino and 'F103?

I am not familiar with Arduino, but it appears that you want to run two different DMA channels using the same timer's DCR/DMAR registers. This won't work. But why don't you do it in the way it's designed, i.e. using only one DMA channel updating both CCR1 and CCR2 upon a single trigger from Update?

You may want to read out the timer and DMA registers content and check them against the respective chapters in RM, or post them here.

JW

tkor.1
tkor.1Author
Associate
November 13, 2020

I am using arduino IDE and stm32f103, I need 2 outputs from timer # 4, I have one on PB7 to get second I have a problem.

 But why don't you do it in the way it's designed, i.e. using only one DMA channel updating both CCR1 and CCR2 upon a single trigger from Update ? =. This i don't know