leds.c
void vUpdateLedStrip( void * pvParameters  )
{
    TickType_t xLastWakeTime;
    const TickType_t xFrequency = 10;

    /* Initialize the xLastWakeTime variable with the current time. */
    xLastWakeTime = xTaskGetTickCount();

    /* Initialize start time.*/
    uint16_t usStartTime = TIM12->CNT;

     /* Create variable to hold the buffer index. */
     uint16_t usBufferIndex = 0;

    while ( 1 )
    {
        usBufferIndex = 0;

        /* Fill transmit buffer with correct compare values to achieve the
        correct pulse widths according to color values */
        for (uint16_t usI = 0; usI < NUMBER_OF_LEDS; usI++)
        {
            for (uint8_t ucJ = 0; ucJ < COLOR_CHANNELS; ucJ++)
            {
                for (uint8_t ucK = 0; ucK < 8; ucK++)
                {
                    uint8_t ucBit = ( ucLeds[usI][ucJ] & (0x80 >> ucK) ) >> (7 - ucK);
                    usLedDutyCycleBuffer[usBufferIndex] = LOW_THRESH + ucBit * ( (uint16_t)HIGH_THRESH - LOW_THRESH );
                    usBufferIndex++;
                }
            }
        }

        /* Set TIM4 CNT so an interrupt occurs to transfer the first byte. */
        TIM4->CNT = CLOCK_THRESH-1;

        /* Reset the pin used for transferring data. */
        GPIOB->ODR &= ~(0x01<<6);

        /* Clear the DMA flags. */
        DMA_ClearFlag(DMA1_Stream0,DMA_FLAG_TCIF0);
        DMA_ClearFlag(DMA1_Stream0,DMA_FLAG_HTIF0);
        DMA_ClearFlag(DMA1_Stream0,DMA_FLAG_FEIF0);

        /* Set the number of bytes to be transferred */
        DMA1_Stream0->NDTR = TOTAL_PERIODS;

        /* Start the DMA peripheral. */
        DMA_Cmd(DMA1_Stream0, ENABLE);

        /* Start the timer used for generating the PWM. */
        TIM_Cmd(TIM4, ENABLE);

        /* Check the stack size. */
        xLedsAvailableStack = uxTaskGetStackHighWaterMark( xUpdateLedsHandle );

        if (xLedsAvailableStack <= 20)
        {
            /* Turn orangle LED on if stack overflow is imminent/detected. */
            STM_EVAL_LEDOn( LED3 );
        }

        /* Update the high water mark for task length. */
        if ( (uint16_t)TIM12->CNT - usStartTime > xDebugStats.usPatternClocks )
        {
            xDebugStats.usUpdateLEDsClocks = (uint16_t)TIM12->CNT - usStartTime;
        }

        /* Wait for the next cycle. */
         vTaskDelayUntil( &xLastWakeTime, xFrequency );

        /* Initialize the start time. */
        usStartTime = TIM12->CNT;
    }
}
/**
  * @brief  Task that initiates the PWM stream to the individually addressable LEDs.
  * @note   Executes every 10ms resulting in a 100Hz update rate.
  * @retval None
  */
@brief  Task that initiates the PWM stream to the individually addressable LEDs.
@note   Executes every 10ms resulting in a 100Hz update rate.
@retval None
@brief Task that initiates the PWM stream to the individually addressable LEDs . @note Executes every 10ms resulting in a 100Hz update rate . @retval None
void vUpdateLedStrip( void * pvParameters  )
{
    TickType_t xLastWakeTime;
    const TickType_t xFrequency = 10;
    xLastWakeTime = xTaskGetTickCount();
    uint16_t usStartTime = TIM12->CNT;
     uint16_t usBufferIndex = 0;
    while ( 1 )
    {
        usBufferIndex = 0;
        for (uint16_t usI = 0; usI < NUMBER_OF_LEDS; usI++)
        {
            for (uint8_t ucJ = 0; ucJ < COLOR_CHANNELS; ucJ++)
            {
                for (uint8_t ucK = 0; ucK < 8; ucK++)
                {
                    uint8_t ucBit = ( ucLeds[usI][ucJ] & (0x80 >> ucK) ) >> (7 - ucK);
                    usLedDutyCycleBuffer[usBufferIndex] = LOW_THRESH + ucBit * ( (uint16_t)HIGH_THRESH - LOW_THRESH );
                    usBufferIndex++;
                }
            }
        }
        TIM4->CNT = CLOCK_THRESH-1;
        GPIOB->ODR &= ~(0x01<<6);
        DMA_ClearFlag(DMA1_Stream0,DMA_FLAG_TCIF0);
        DMA_ClearFlag(DMA1_Stream0,DMA_FLAG_HTIF0);
        DMA_ClearFlag(DMA1_Stream0,DMA_FLAG_FEIF0);
        DMA1_Stream0->NDTR = TOTAL_PERIODS;
        DMA_Cmd(DMA1_Stream0, ENABLE);
        TIM_Cmd(TIM4, ENABLE);
        xLedsAvailableStack = uxTaskGetStackHighWaterMark( xUpdateLedsHandle );
        if (xLedsAvailableStack <= 20)
        {
            STM_EVAL_LEDOn( LED3 );
        }
        if ( (uint16_t)TIM12->CNT - usStartTime > xDebugStats.usPatternClocks )
        {
            xDebugStats.usUpdateLEDsClocks = (uint16_t)TIM12->CNT - usStartTime;
        }
         vTaskDelayUntil( &xLastWakeTime, xFrequency );
        usStartTime = TIM12->CNT;
    }
}
void vUpdateLedStrip ( void * pvParameters ) { TickType_t xLastWakeTime ; const TickType_t xFrequency = 10 ; xLastWakeTime = xTaskGetTickCount ( ) ; uint16_t usStartTime = TIM12 -> CNT ; uint16_t usBufferIndex = 0 ; while ( 1 ) { usBufferIndex = 0 ; for ( uint16_t usI = 0 ; usI < NUMBER_OF_LEDS ; usI ++ ) { for ( uint8_t ucJ = 0 ; ucJ < COLOR_CHANNELS ; ucJ ++ ) { for ( uint8_t ucK = 0 ; ucK < 8 ; ucK ++ ) { uint8_t ucBit = ( ucLeds [ usI ] [ ucJ ] & ( 0x80 >> ucK ) ) >> ( 7 - ucK ) ; usLedDutyCycleBuffer [ usBufferIndex ] = LOW_THRESH + ucBit * ( ( uint16_t ) HIGH_THRESH - LOW_THRESH ) ; usBufferIndex ++ ; } } } TIM4 -> CNT = CLOCK_THRESH - 1 ; GPIOB -> ODR &= ~ ( 0x01 << 6 ) ; DMA_ClearFlag ( DMA1_Stream0 , DMA_FLAG_TCIF0 ) ; DMA_ClearFlag ( DMA1_Stream0 , DMA_FLAG_HTIF0 ) ; DMA_ClearFlag ( DMA1_Stream0 , DMA_FLAG_FEIF0 ) ; DMA1_Stream0 -> NDTR = TOTAL_PERIODS ; DMA_Cmd ( DMA1_Stream0 , ENABLE ) ; TIM_Cmd ( TIM4 , ENABLE ) ; xLedsAvailableStack = uxTaskGetStackHighWaterMark ( xUpdateLedsHandle ) ; if ( xLedsAvailableStack <= 20 ) { STM_EVAL_LEDOn ( LED3 ) ; } if ( ( uint16_t ) TIM12 -> CNT - usStartTime > xDebugStats . usPatternClocks ) { xDebugStats . usUpdateLEDsClocks = ( uint16_t ) TIM12 -> CNT - usStartTime ; } vTaskDelayUntil ( & xLastWakeTime , xFrequency ) ; usStartTime = TIM12 -> CNT ; } }
@brief  Task that initiates the PWM stream to the individually addressable LEDs.
@brief Task that initiates the PWM stream to the individually addressable LEDs .
/* Initialize the xLastWakeTime variable with the current time. */ /* Initialize start time.*/ /* Create variable to hold the buffer index. */ /* Fill transmit buffer with correct compare values to achieve the
        correct pulse widths according to color values */ /* Set TIM4 CNT so an interrupt occurs to transfer the first byte. */ /* Reset the pin used for transferring data. */ /* Clear the DMA flags. */ /* Set the number of bytes to be transferred */ /* Start the DMA peripheral. */ /* Start the timer used for generating the PWM. */ /* Check the stack size. */ /* Turn orangle LED on if stack overflow is imminent/detected. */ /* Update the high water mark for task length. */ /* Wait for the next cycle. */ /* Initialize the start time. */