cancel
Showing results for 
Search instead for 
Did you mean: 

Interfacing code of Ws2812b on stm32F1 is working but in a same way when i am trying it with Stm32F4 it is not working !!!!

ErVaibhavS
Associate III

TIM_HandleTypeDef htim3;

DMA_HandleTypeDef hdma_tim3_ch2;

/* TIM3 init function */

void MX_TIM3_Init(void)

{

 TIM_ClockConfigTypeDef sClockSourceConfig = {0};

 TIM_MasterConfigTypeDef sMasterConfig = {0};

 TIM_OC_InitTypeDef sConfigOC = {0};

 htim3.Instance = TIM3;

 htim3.Init.Prescaler = 0;

 htim3.Init.CounterMode = TIM_COUNTERMODE_UP;

 htim3.Init.Period = 125-1;

 htim3.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;

 htim3.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;

 if (HAL_TIM_Base_Init(&htim3) != HAL_OK)

 {

  Error_Handler();

 }

 sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;

 if (HAL_TIM_ConfigClockSource(&htim3, &sClockSourceConfig) != HAL_OK)

 {

  Error_Handler();

 }

 if (HAL_TIM_PWM_Init(&htim3) != HAL_OK)

 {

  Error_Handler();

 }

 sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;

 sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;

 if (HAL_TIMEx_MasterConfigSynchronization(&htim3, &sMasterConfig) != HAL_OK)

 {

  Error_Handler();

 }

 sConfigOC.OCMode = TIM_OCMODE_PWM1;

 sConfigOC.Pulse = 0;

 sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;

 sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;

 if (HAL_TIM_PWM_ConfigChannel(&htim3, &sConfigOC, TIM_CHANNEL_2) != HAL_OK)

 {

  Error_Handler();

 }

 HAL_TIM_MspPostInit(&htim3);

}

void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* tim_baseHandle)

{

 if(tim_baseHandle->Instance==TIM3)

 {

 /* USER CODE BEGIN TIM3_MspInit 0 */

 /* USER CODE END TIM3_MspInit 0 */

  /* TIM3 clock enable */

  __HAL_RCC_TIM3_CLK_ENABLE();

  /* TIM3 DMA Init */

  /* TIM3_CH2 Init */

  hdma_tim3_ch2.Instance = DMA1_Stream5;

  hdma_tim3_ch2.Init.Channel = DMA_CHANNEL_5;

  hdma_tim3_ch2.Init.Direction = DMA_PERIPH_TO_MEMORY;

  hdma_tim3_ch2.Init.PeriphInc = DMA_PINC_ENABLE;

  hdma_tim3_ch2.Init.MemInc = DMA_MINC_DISABLE;

  hdma_tim3_ch2.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD;

  hdma_tim3_ch2.Init.MemDataAlignment = DMA_MDATAALIGN_WORD;

  hdma_tim3_ch2.Init.Mode = DMA_CIRCULAR;

  hdma_tim3_ch2.Init.Priority = DMA_PRIORITY_HIGH;

  hdma_tim3_ch2.Init.FIFOMode = DMA_FIFOMODE_DISABLE;

  if (HAL_DMA_Init(&hdma_tim3_ch2) != HAL_OK)

  {

   Error_Handler();

  }

  __HAL_LINKDMA(tim_baseHandle,hdma[TIM_DMA_ID_CC2],hdma_tim3_ch2);

 /* USER CODE BEGIN TIM3_MspInit 1 */

 /* USER CODE END TIM3_MspInit 1 */

 }

}

void HAL_TIM_MspPostInit(TIM_HandleTypeDef* timHandle)

{

 GPIO_InitTypeDef GPIO_InitStruct = {0};

 if(timHandle->Instance==TIM3)

 {

 /* USER CODE BEGIN TIM3_MspPostInit 0 */

 /* USER CODE END TIM3_MspPostInit 0 */

  __HAL_RCC_GPIOA_CLK_ENABLE();

  /**TIM3 GPIO Configuration

  PA7   ------> TIM3_CH2

  */

  GPIO_InitStruct.Pin = GPIO_PIN_7;

  GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;

  GPIO_InitStruct.Pull = GPIO_NOPULL;

  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;

  GPIO_InitStruct.Alternate = GPIO_AF2_TIM3;

  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

 /* USER CODE BEGIN TIM3_MspPostInit 1 */

 /* USER CODE END TIM3_MspPostInit 1 */

 }

}

/* Main Code */

if (process_complete)

{

HAL_TIM_PWM_Start_DMA(&htim2, TIM_CHANNEL_3,(uint32_t*)LED_buffer,LED_BUFF_LEN);

process_complete=0;

}

1 ACCEPTED SOLUTION

Accepted Solutions
ErVaibhavS
Associate III

@Community member​ 

I got the solution. After changing the below setting it start working :

hdma_tim3_ch2.Init.Direction = DMA_MEMORY_TO_PERIPH;

 hdma_tim3_ch2.Init.PeriphInc = DMA_PINC_DISABLE;

 hdma_tim3_ch2.Init.MemInc = DMA_MINC_ENABLE;

View solution in original post

6 REPLIES 6
ErVaibhavS
Associate III

@Community member​ @Community member​  I am Interfacing ws2812b RGB LED .This i have interfaced with STM32F1 using TIMER 2 CHANNEL 3 it is working fine. but now i am trying to interface it with F4 via same method but it is not working.

Please Help it is urgent !!!

Watch DMA width, TIM3 16-bit as I recall​

Later code references TIM2 CH3 not TIM3 CH2​

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Sorry Clive !!! That i have posted mistakenly.Here is the actual code given below :

if (process_complete)

{

HAL_TIM_PWM_Start_DMA(&htim3, TIM_CHANNEL_2,(uint32_t*)LED_buffer,LED_BUFF_LEN);

process_complete=0;

}

What changes i have to do for 16 bit timer ?

ErVaibhavS
Associate III

@Community member​ 

I got the solution. After changing the below setting it start working :

hdma_tim3_ch2.Init.Direction = DMA_MEMORY_TO_PERIPH;

 hdma_tim3_ch2.Init.PeriphInc = DMA_PINC_DISABLE;

 hdma_tim3_ch2.Init.MemInc = DMA_MINC_ENABLE;

ErVaibhavS
Associate III

@Community member​ @Community member​ 

For F1 it works with the following DMA Settings :

 hdma_tim2_ch3.Init.Direction = DMA_PERIPH_TO_MEMORY;

  hdma_tim2_ch3.Init.PeriphInc = DMA_PINC_ENABLE;

  hdma_tim2_ch3.Init.MemInc = DMA_MINC_DISABLE;

Whereas for F4 it works with the follwing settings :

hdma_tim3_ch2.Init.Direction = DMA_MEMORY_TO_PERIPH;

  hdma_tim3_ch2.Init.PeriphInc = DMA_PINC_DISABLE;

  hdma_tim3_ch2.Init.MemInc = DMA_MINC_ENABLE;

Is it means that TIMxCCR3 is Memory side in F1 and TIMxCCR2 is peripheral side ? Can you explain more please !!!