0
\$\begingroup\$

I am using TIMER2 + CHANNEL 2 PWM to generate 800 Khz wave. The idea is to vary the duty cycle of this wave as per a statically generated pixel bit array (1 SK6812 pixel = 32 bit GRBW = 32 bytes of data) to generate the appropriate signal for 10 SK6812 connected in a chain. Using DMA to transfer the array to the timer PWM unit.

Using STM32 cubemx as a starting point to generate the project.

main.c

  /* Configure the system clock */
  SystemClock_Config();

  /* USER CODE BEGIN SysInit */

  /* USER CODE END SysInit */

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_DMA_Init();
  MX_TIM2_Init();
  /* USER CODE BEGIN 2 */

    //LED TOGGLE
    HAL_GPIO_WritePin(GPIOC, GPIO_PIN_8, GPIO_PIN_SET);
    HAL_GPIO_WritePin(GPIOC, GPIO_PIN_9, GPIO_PIN_SET);
    HAL_Delay(1000);
    HAL_GPIO_WritePin(GPIOC, GPIO_PIN_8, GPIO_PIN_RESET);
    HAL_GPIO_WritePin(GPIOC, GPIO_PIN_9, GPIO_PIN_RESET);
    HAL_Delay(1000);
    HAL_GPIO_WritePin(GPIOC, GPIO_PIN_8, GPIO_PIN_SET);
    HAL_GPIO_WritePin(GPIOC, GPIO_PIN_9, GPIO_PIN_SET);
    HAL_Delay(1000);
    HAL_GPIO_WritePin(GPIOC, GPIO_PIN_8, GPIO_PIN_RESET);
    HAL_GPIO_WritePin(GPIOC, GPIO_PIN_9, GPIO_PIN_RESET);

    //HAL_TIM_Base_Start(&htim2);
    HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_2);

    uint32_t green[32] = {10, 10, 10, 10, 10, 10, 10, 10, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5};
    uint32_t red[32] = {5, 5, 5, 5, 5, 5, 5, 5, 10, 10, 10, 10, 10, 10, 10, 10, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5};
    uint32_t blue[33] = {0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 10, 10, 10, 10, 10, 10, 10, 10, 5, 5, 5, 5, 5, 5, 5, 5};

    uint32_t* gbig = malloc(321);
    gbig[0] = 0;
    for(uint8_t i = 0; i < 10; i++)
    {
        memcpy(gbig + 1 + (32 * i), red, sizeof(red));
    }

    HAL_TIM_PWM_Start_DMA(&htim2, TIM_CHANNEL_2, gbig, 321);
    //HAL_Delay(1000);
    //HAL_TIM_Base_Start(&htim2);
    //HAL_TIM_PWM_Start_DMA(&htim2, TIM_CHANNEL_2, blue, 33);
    //HAL_Delay(1000);
    //HAL_TIM_Base_Start(&htim2);
    //HAL_TIM_PWM_Start_DMA(&htim2, TIM_CHANNEL_2, green, 33);
    //HAL_Delay(1000);

  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {

  /* USER CODE END WHILE */

  /* USER CODE BEGIN 3 */

  }
  /* USER CODE END 3 */

}

stm32f0xx_it.c

void HAL_TIM_TxCpltCallback(TIM_HandleTypeDef* tim)
{
    if(tim->Instance == TIM2)
    {
        //HAL_TIM_PWM_Stop(tim, TIM_CHANNEL_2);
        //HAL_TIM_Base_Stop(tim);
    }
}

My questions are :

  1. On boot I am toggling on board leds. When I burn the code, the led toggle but I do not get any activity on the SK6812 strip. If I reset the baord, the led toggle again and the led strip comes on with the right color immediately. As per my code, the dma transfer should only begin after the led are done toggling

  2. The first DMA transfer works. However the subsequent ones, after the delay do not.

Any help would be great on what I am doing wrong / missing here.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.