Skip to main content
monta
Associate III
July 7, 2015
Question

freeRTOS task not working

  • July 7, 2015
  • 6 replies
  • 1485 views
Posted on July 07, 2015 at 18:51

Hello there, I wrote this simple code to test freeRTOS on my stm32f4 discovery , 

the code compiles nicely and give no errors but BlinkLedTask does not Blink the led on the board.

#include <stm32f4xx.h>

 

#include <misc.h>  

 

#include <stm32f4xx_rcc.h>

 

#include <stm32f4xx_usart.h> 

 

#include <stm32f4xx_gpio.h>

 

#include ''FreeRTOS.h''

 

#include ''task.h''

 

#include <math.h>

 

#include <misc.h>

 

 

 

#define LED_GREEN      12

 

#define LED_ORANGE     13

 

#define LED_RED        14

 

#define LED_BLUE       15

 

 

 

 

 

void init_LED();

 

 

 

void BlinkLedTask(void);

 

 

 

int main(void) {

 

  uint8_t ret;

 

 

 

  SystemInit();

 

  //NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);

 

 

 

  init_LED();

 

  // Create a task

 

  ret = xTaskCreate(''BlinkLedTask'', ''FPU'', configMINIMAL_STACK_SIZE, NULL, NULL, NULL);

 

 

 

  if (ret == pdTRUE) {

 

 GPIOD->BSRRL = (1 << 12);

 

    vTaskStartScheduler();  // should never return

 

  } else {

 

 GPIOD->BSRRL = (1 << 14);

 

    // --TODO blink some LEDs to indicate fatal system error

 

  }

 

 

 

  for (;;);

 

}

 

 

 

void vApplicationTickHook(void) {

 

}

 

 

 

void vApplicationMallocFailedHook(void) {

 

  taskDISABLE_INTERRUPTS();

 

  for(;;);

 

}

 

 

 

void vApplicationIdleHook(void) {

 

}

 

 

 

void vApplicationStackOverflowHook(xTaskHandle pxTask, signed char *pcTaskName) {

 

  (void) pcTaskName;

 

  (void) pxTask;

 

  taskDISABLE_INTERRUPTS();

 

  for(;;);

 

}

 

void BlinkLedTask(void)

 

   {

 

       for( ;; )

 

       {

 

      GPIOD->BSRRL = (1 << 13);

 

       }

 

 

 

       vTaskDelete( NULL );

 

   }

 

 

 

void init_LED()

 

{

 

int pin = LED_GREEN;

 

//

 

// Initialise the Clock.

 

RCC->AHB1ENR |= RCC_AHB1Periph_GPIOD;

 

//

 

//

 

GPIO_InitTypeDef GPIO_InitStructure;

 

 

 

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;

 

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;

 

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;

 

GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;

 

GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;

 

GPIO_Init(GPIOD, &GPIO_InitStructure);

 

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;

 

GPIO_Init(GPIOD, &GPIO_InitStructure);

 

}

    This topic has been closed for replies.

    6 replies

    Tesla DeLorean
    Guru
    July 7, 2015
    Posted on July 07, 2015 at 20:12

    Please edit your post, and use the Format Code Block tool (Paintbrush [<>]), as it's currently unreadable.

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    monta
    montaAuthor
    Associate III
    July 11, 2015
    Posted on July 11, 2015 at 21:59

    Hi there, thank you for replying, please check now and let me know. Thank you !!

    Tesla DeLorean
    Guru
    July 12, 2015
    Posted on July 12, 2015 at 04:10

    GPIOD->BSRRL = (1 << 13);  // Liable to just set the pin

    GPIOD->ODR ^= (1 << 13); // Toggle

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    monta
    montaAuthor
    Associate III
    July 12, 2015
    Posted on July 12, 2015 at 12:53

    Still not working :\ ?? 

    I'm suspecting the problem is here

    ret = xTaskCreate(''BlinkLedTask'', ''FPU'', configMINIMAL_STACK_SIZE, NULL, NULL, NULL);

    Tesla DeLorean
    Guru
    July 12, 2015
    Posted on July 12, 2015 at 19:54

    Do you have a scope on the LED, because it's probably not going to blink at a visible rate without some delay in the loop.

    Not much of a freeRTOS expert, do you have a breakpoint in the loop? How is this ''not working'' being determined?

    Does xCreateTask() return a failure code? What does it suggest is the problem?

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    monta
    montaAuthor
    Associate III
    July 17, 2015
    Posted on July 17, 2015 at 20:18

    Indeed that was the problem. Thumbs up !