cancel
Showing results for 
Search instead for 
Did you mean: 

stm32U575 GPDMA PWM

caiChangKun
Associate II

STM32CubMx 版本 6.9.1
GPDMA
PWM
配置

微信图片_20231123181456.png微信图片_20231123181511.png微信图片_20231123181515.png


法典

/* TIM4 初始化函数 */
void MX_TIM4_Init(void)

{

/* 用户代码以 4 开头TIM0_Init */

/* 用户代码结束 TIM4_Init 0 */

TIM_ClockConfigTypeDef sClockSourceConfig = {0};
TIM_MasterConfigTypeDef sMasterConfig = {0};
TIM_OC_InitTypeDef sConfigOC = {0};

/* USER CODE BEGIN TIM4_Init 1 */

/* USER CODE END TIM4_Init 1 */
htim4.Instance = TIM4;
htim4.Init.Prescaler = 159;
htim4.Init.CounterMode = TIM_COUNTERMODE_UP;
htim4.Init.Period = 9999;
htim4.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
htim4.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
if (HAL_TIM_Base_Init(&htim4) != HAL_OK)
{
Error_Handler();
}
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
if (HAL_TIM_ConfigClockSource(&htim4, &sClockSourceConfig) != HAL_OK)
{
Error_Handler();
}
if (HAL_TIM_OC_Init(&htim4) != HAL_OK)
{
Error_Handler();
}
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
if (HAL_TIMEx_MasterConfigSynchronization(&htim4, &sMasterConfig) != HAL_OK)
{
Error_Handler();
}
sConfigOC.OCMode = TIM_OCMODE_TOGGLE;
sConfigOC.Pulse = 0;
sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
if (HAL_TIM_OC_ConfigChannel(&htim4, &sConfigOC, TIM_CHANNEL_1) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN TIM4_Init 2 */

/* USER CODE END TIM4_Init 2 */
HAL_TIM_MspPostInit(&htim4);


}

if(tim_baseHandle->Instance==TIM4)
{
/* USER CODE BEGIN TIM4_MspInit 0 */

/* USER CODE END TIM4_MspInit 0 */
/* TIM4 clock enable */
__HAL_RCC_TIM4_CLK_ENABLE();

/* TIM4 DMA Init */
/* GPDMA1_REQUEST_TIM4_CH1 Init */
NodeConfig.NodeType = DMA_GPDMA_LINEAR_NODE;
NodeConfig.Init.Request = GPDMA1_REQUEST_TIM4_CH1;
NodeConfig.Init.BlkHWRequest = DMA_BREQ_SINGLE_BURST;
NodeConfig.Init.Direction = DMA_MEMORY_TO_PERIPH;
NodeConfig.Init.SrcInc = DMA_SINC_INCREMENTED;
NodeConfig.Init.DestInc = DMA_DINC_INCREMENTED;
NodeConfig.Init.SrcDataWidth = DMA_SRC_DATAWIDTH_WORD;
NodeConfig.Init.DestDataWidth = DMA_DEST_DATAWIDTH_WORD;
NodeConfig.Init.SrcBurstLength = 1;
NodeConfig.Init.DestBurstLength = 1;
NodeConfig.Init.TransferAllocatedPort = DMA_SRC_ALLOCATED_PORT0|DMA_DEST_ALLOCATED_PORT0;
NodeConfig.Init.TransferEventMode = DMA_TCEM_BLOCK_TRANSFER;
NodeConfig.Init.Mode = DMA_NORMAL;
NodeConfig.TriggerConfig.TriggerPolarity = DMA_TRIG_POLARITY_MASKED;
NodeConfig.DataHandlingConfig.DataExchange = DMA_EXCHANGE_NONE;
NodeConfig.DataHandlingConfig.DataAlignment = DMA_DATA_RIGHTALIGN_ZEROPADDED;
if (HAL_DMAEx_List_BuildNode(&NodeConfig, &Node_GPDMA1_Channel6) != HAL_OK)
{
Error_Handler();

}

if (HAL_DMAEx_List_InsertNode(&List_GPDMA1_Channel6, NULL, &Node_GPDMA1_Channel6) != HAL_OK)
{
Error_Handler();

}

if (HAL_DMAEx_List_SetCircularMode(&List_GPDMA1_Channel6) != HAL_OK)
{
Error_Handler();

}

handle_GPDMA1_Channel6.Instance = GPDMA1_Channel6;
handle_GPDMA1_Channel6.InitLinkedList.Priority = DMA_LOW_PRIORITY_HIGH_WEIGHT;
handle_GPDMA1_Channel6.InitLinkedList.LinkStepMode = DMA_LSM_FULL_EXECUTION;
handle_GPDMA1_Channel6.InitLinkedList.LinkAllocatedPort = DMA_LINK_ALLOCATED_PORT0;
handle_GPDMA1_Channel6.InitLinkedList.TransferEventMode = DMA_TCEM_BLOCK_TRANSFER;
handle_GPDMA1_Channel6.InitLinkedList.LinkedListMode = DMA_LINKEDLIST_CIRCULAR;
if (HAL_DMAEx_List_Init(&handle_GPDMA1_Channel6) != HAL_OK)
{
Error_Handler();

}

if (HAL_DMAEx_List_LinkQ(&handle_GPDMA1_Channel6, &List_GPDMA1_Channel6) != HAL_OK)
{
Error_Handler();

}

__HAL_LINKDMA(tim_baseHandle, hdma[TIM_DMA_ID_CC1], handle_GPDMA1_Channel6);

if (HAL_DMA_ConfigChannelAttributes(&handle_GPDMA1_Channel6, DMA_CHANNEL_NPRIV) != HAL_OK)
{
Error_Handler();

}

/* TIM4 interrupt Init */
HAL_NVIC_SetPriority(TIM4_IRQn, 5, 0);
HAL_NVIC_EnableIRQ(TIM4_IRQn);
/* USER CODE BEGIN TIM4_MspInit 1 */

/* USER CODE END TIM4_MspInit 1 */
}

uint32_t Buff[8]={3000,6000,7000,3000,6000,7000,3000,6000};
void TIM4_Init()
{
    MX_TIM4_Init();
    HAL_TIM_OC_Start_DMA(&htim4, TIM_CHANNEL_1,(uint32_t*)Buff,32);
}
void HAL_TIM_PWM_PulseFinishedCallback(TIM_HandleTypeDef *htim)
{
   if(htim == (&htim4))
  {
     HAL_TIM_PWM_Stop_DMA(&htim4, TIM_CHANNEL_1); 

   }
}
problem


caiChangKun_0-1700734818455.png

Only the first value has an effect

The following are all 10ms cycles for level flipping

The CCR values of other channels have also been changed

caiChangKun_1-1700735043768.png

我想知道如何在STM32U575中实现DMA+PWM比较输出

 

6 REPLIES 6
Sarra.S
ST Employee

Hello @caiChangKun, Welcome to ST Community,

The code and configuration are clear, I can assume that you want to use DMA with PWM. But your problem is not really clear... Could you please explain your issue/ your question in English? 

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

caiChangKun
Associate II

Using GPMDA to perform PWM comparison output on STM32U757. Only the first pulse conversion period is 3ms, and the others are 10ms. Additionally, the CCR values of other channels are also modified.

Using GPMDA to perform PWM comparison output on STM32U757. Only the first pulse conversion period is 3ms, and the others are 10ms. Additionally, the CCR values of other channels are also modified.

 

我想比较GPDMA+PWM的输出,在固定时间段内进行多次电平翻转。

Sarra.S
ST Employee

Hello @caiChangKun

This could be related to the config of your TIM/DMA, make sure ARR  is strictly greater than the CCR value 

 

 

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

caiChangKun_0-1700876810547.png


Yes, my ARR value is greater than the CCR value. The issue is that only the first 3000 value is effective. I am only sending the CCR value to channel 1, but the values of my other channels are also being changed. Why is that?