打印

at32f413 DMA新手求助

[复制链接]
727|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
ryan39343551|  楼主 | 2023-3-6 14:56 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
使用DMA更新PWM脉宽数据,TIMR5输出两路PWM,频率相同,脉宽不同,以下代码PWM正常工作,DMA无法更新数据。感谢大佬们帮忙看看一下。void tmr5_configuration(void)
{
        tmr_output_config_type tmr_output_struct;
  /* Init TMR5 */       
        tmr_base_init(TMR5, 250-1, 0);                                //200MHz/250=800KHz
        //tmr_base_init(TMR5, 300-1, 0);                                //240MHz/300=800KHz
  tmr_cnt_dir_set(TMR5, TMR_COUNT_UP);        //定时器计数器向上计数

        /* TMR configuration as output mode */
  tmr_output_default_para_init(&tmr_output_struct);

        tmr_output_struct.oc_mode = TMR_OUTPUT_CONTROL_PWM_MODE_B;
  tmr_output_struct.oc_output_state = TRUE;
  tmr_output_struct.oc_polarity = TMR_OUTPUT_ACTIVE_LOW;
  tmr_output_struct.oc_idle_state = TRUE;
  tmr_output_struct.occ_output_state = TRUE;
  tmr_output_struct.occ_polarity = TMR_OUTPUT_ACTIVE_LOW;
  tmr_output_struct.occ_idle_state = FALSE;
       
        /* TMR5 channel 1 configuration */       
  tmr_output_channel_config(TMR5, TMR_SELECT_CHANNEL_1, &tmr_output_struct);
        tmr_output_channel_buffer_enable(TMR5, TMR_SELECT_CHANNEL_1, TRUE);

       
        /* TMR5 channel 2 configuration */       
  tmr_output_channel_config(TMR5, TMR_SELECT_CHANNEL_2, &tmr_output_struct);
        tmr_output_channel_buffer_enable(TMR5, TMR_SELECT_CHANNEL_2, TRUE);
        }
       
void dma2_5_configuration(void)
{
        dma_init_type dma_init_struct = {0};

        dma_reset(DMA2_CHANNEL5);
        dma_reset(DMA2_CHANNEL4);
  /* dma1 channel7 configuration */
  dma_default_para_init(&dma_init_struct);
  dma_init_struct.buffer_size =ArgbPixelBuffNub+ArgbPixelResetNub;        //设置 DMA 通道传输数据量
  dma_init_struct.direction = DMA_DIR_MEMORY_TO_PERIPHERAL;                                        //方向为存储器到外设
  dma_init_struct.memory_base_addr = (uint32_t)temp_buffer_argb2;                //设置 DMA 通道存储器地址
  dma_init_struct.memory_data_width = DMA_MEMORY_DATA_WIDTH_BYTE;                //存储器数据宽度为字节
  dma_init_struct.memory_inc_enable = TRUE;                                                                                                        //存储器地址递增
  dma_init_struct.peripheral_base_addr = (uint32_t)0x40000C34;                        //TMR5_C1DT_ADDRESS;                        //设置 DMA 通道的外设地址
  dma_init_struct.peripheral_data_width = DMA_PERIPHERAL_DATA_WIDTH_BYTE;                //外设数据宽度为字节
  dma_init_struct.peripheral_inc_enable = FALSE;                                                                                //外设地址不递增
  dma_init_struct.priority = DMA_PRIORITY_MEDIUM;                                                                                //DMA 通道优先级为中
  dma_init_struct.loop_mode_enable = TRUE;                                                                                                        //DMA 通道为循环模式

       
  dma_init(DMA2_CHANNEL5, &dma_init_struct);
       
        dma_init_struct.memory_base_addr = (uint32_t)temp_buffer_argb1;                                                        //设置 DMA 通道存储器地址
        dma_init_struct.peripheral_base_addr = (uint32_t)0x40000C38;                        //TMR5_C2DT_ADDRESS;                                        //设置 DMA 通道的外设地址
        dma_init(DMA2_CHANNEL4, &dma_init_struct);
        }


void ARGB_configuration(void)
{
        tmr5_configuration();
        tmr_channel_value_set(TMR5, TMR_SELECT_CHANNEL_2, temp_buffer_argb1[0]);
        tmr_channel_value_set(TMR5, TMR_SELECT_CHANNEL_1, temp_buffer_argb2[0]);
        tmr_dma_request_enable(TMR5, TMR_OVERFLOW_DMA_REQUEST, TRUE);
        dma2_5_configuration();
        dma_flexible_config(DMA2, FLEX_CHANNEL4|FLEX_CHANNEL5, DMA_FLEXIBLE_TMR3_OVERFLOW);
        dma_channel_enable(DMA2_CHANNEL4, TRUE);
        dma_channel_enable(DMA2_CHANNEL5, TRUE);
       
        tmr_output_enable(TMR5, TRUE);
  tmr_counter_enable(TMR5, TRUE);
               
        }

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

2

主题

10

帖子

0

粉丝