cancel
Showing results for 
Search instead for 
Did you mean: 

Problems with CubeMX and TIM1+DMA for PWM on STM32MP157 - DK1

KDehm
Associate III

I'm trying to get PWM running on an STM32MP157-DK1.

When i run the example code "TIM_DMABurst" there is a PWM (had oscilloscope on Pin). Then I configured TIM1 on Channel 1 and the DMA on Stream2 with CubeMX. The generated code looks exactly the same like in the example, but there is no PWM output.

Is there a problem with the HAL driver, or maybe clock configuration? Spent hours in debugging this, but i need PWM to drive a WS2812 LED Strip.

I recognized that the example jumps over SystemClock_Config() (works without ENGENEERING_MODE).

The code shows the beginning of main.c.

I'm thankful for every advise!

#include "main.h"
#include "openamp.h"
 
 
/* Private variables ---------------------------------------------------------*/
IPCC_HandleTypeDef hipcc;
 
TIM_HandleTypeDef htim1;
DMA_HandleTypeDef hdma_tim1_up;
 
uint32_t Prescaler ;
 
/* Capture Compare buffer */
uint32_t aSRC_Buffer[3] = {0x0FFF, 0x0000, 0x0555};
 
/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
void PeriphCommonClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_DMA_Init(void);
static void MX_IPCC_Init(void);
static void MX_TIM1_Init(void);
int MX_OPENAMP_Init(int RPMsgRole, rpmsg_ns_bind_cb ns_bind_cb);
 
 
int main(void)
{
 
  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();
 
  if(IS_ENGINEERING_BOOT_MODE())
  {
    /* Configure the system clock */
    SystemClock_Config();
  }
 
  __HAL_RCC_HSEM_CLK_ENABLE();
 
  Prescaler = (HAL_RCCEx_GetPeriphCLKFreq(RCC_PERIPHCLK_TIMG2)/ (16 * 1000000)) - 1 ;
 
  /* IPCC initialisation */
   MX_IPCC_Init();
  /* OpenAmp initialisation ---------------------------------*/
  MX_OPENAMP_Init(RPMSG_REMOTE, NULL);
 
  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_DMA_Init();
  MX_TIM1_Init();
 
 
  /*## Start PWM signal generation in DMA mode ############*/
  if(HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_1) != HAL_OK)
  {
    /* Starting PWM generation Error */
    Error_Handler();
  }
 
  /*## Start DMA Burst transfer #######*/
  HAL_TIM_DMABurst_WriteStart(&htim1, TIM_DMABASE_ARR, TIM_DMA_UPDATE,  (uint32_t*)aSRC_Buffer, TIM_DMABURSTLENGTH_3TRANSFERS);
 
 
  while (1)
  {
 
  }
}

3 REPLIES 3
PatrickF
ST Employee

Hello,

Could you share your .ioc (CubeMx) config file ?

Have you check if the PWM pin muxing configuration in MX_TIM1_Init() is ok.

We have identified some issues in CubeMx code generation.

In order 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.

Hi,

I use GPIO PE9 as TIM1 Channel1 output. Seems to be identical to the example.

Thanks!

  GPIO_InitTypeDef GPIO_InitStruct = {0};
  if(htim->Instance==TIM1)
  {  
    __HAL_RCC_GPIOE_CLK_ENABLE();
    /**TIM1 GPIO Configuration    
    PE9     ------> TIM1_CH1 
    */
    GPIO_InitStruct.Pin = GPIO_PIN_9;
    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
    GPIO_InitStruct.Alternate = GPIO_AF1_TIM1;
    HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
  }

Najib Kassab
Associate III

I have the same issue and it turns out it is because when Linux is running, It take the control of clock configurations, so you need to see the clock in order to get the correct duty_cycle...etc to your pwn signals by typing cat /sys/kernel/debug/clk/clk_summary

and see your timer clock