Skip to content

vTaskDelay Don't seem to be working #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
SocketNet opened this issue Apr 16, 2019 · 7 comments
Closed

vTaskDelay Don't seem to be working #17

SocketNet opened this issue Apr 16, 2019 · 7 comments
Labels
question Further information is requested

Comments

@SocketNet
Copy link

SocketNet commented Apr 16, 2019

#include <Arduino.h>
#include <STM32FreeRTOS.h>

#define LED PC13

void task(void *pvParameters)
{
  Serial.println("task start");
  for (;;)
  {

    digitalWrite(LED, HIGH);
    vTaskDelay(100);
    digitalWrite(LED, LOW);
    vTaskDelay(100);
  }
}

void setup()
{
  Serial.begin(115200);
  Serial.println("Serial start");
  pinMode(LED, OUTPUT);
  xTaskCreate(task, "task", 128, NULL, 2, NULL);
  vTaskStartScheduler();
}

void loop()
{
  for (int i = 65; i < 91; i++)
  {
    Serial.println((char)i);
    delay(1000);
  }
}
@fpistm
Copy link
Member

fpistm commented Apr 16, 2019

Loop is called thanks:

#if ( configUSE_IDLE_HOOK == 1 )
/** vApplicationIdleHook() will only be called if configUSE_IDLE_HOOK is set
to 1 in FreeRTOSConfig.h. It will be called on each iteration of the idle
task. It is essential that code added to this hook function never attempts
to block in any way (for example, call xQueueReceive() with a block time
specified, or call vTaskDelay()). If the application makes use of the
vTaskDelete() API function (as this demo application does) then it is also
important that vApplicationIdleHook() is permitted to return to its calling
function, because it is the responsibility of the idle task to clean up
memory allocated by the kernel to any task that has since been deleted. */
void __attribute__((weak)) vApplicationIdleHook( void ) {
void loop();
loop();
}
#endif /* configUSE_IDLE_HOOK == 1 */

Your loop take too much time. You should not called delay. In a general way, avoid to use loop, create dedicated task. Moreover, your blink is very quick ( 100 ms)

Check this example:
https://github.com/stm32duino/STM32FreeRTOS/blob/master/examples/frBlinkPrint/frBlinkPrint.ino

@fpistm fpistm added the question Further information is requested label Apr 16, 2019
@SocketNet
Copy link
Author

thank you but i try you frBlinkPrint.ino example into stm32f103c8t6 led not work

@fpistm
Copy link
Member

fpistm commented Apr 17, 2019

@SocketNet
I've just tried with my BP and it's works fine with HardwareSerial.
Note that if you use USB CDC for Serial then you will have to use the heap management number 3
See #16 (comment)

@SocketNet
Copy link
Author

myconfig

[env:genericSTM32F103C8]
platform = ststm32
board = genericSTM32F103C8
framework = arduino
upload_protocol = serial
board_build.core = STM32

code

  #include <Arduino.h>
  #include <STM32FreeRTOS.h>


  void task(void *pvParameters)
  {
    Serial.println("task start");
    for (;;)
    {
      for (int i = 65; i < 91; i++)
      {
        Serial.println((char)i);
        vTaskDelay(500 / portTICK_RATE_MS);
      }
    
    }
  }

  void setup()
  {
    Serial.begin(9600);
    Serial.println("Serial start");
    xTaskCreate(task, "task", configMINIMAL_STACK_SIZE + 128, NULL, tskIDLE_PRIORITY + 2, NULL);
    vTaskStartScheduler();
    while(1);
  }

  void loop()
  {
    
  }

The console only outputs "A", and the task seems to stop as soon as it arrives vTaskDelay and never continues.

@fpistm
Copy link
Member

fpistm commented Apr 18, 2019

OK, you used PIO.
So, you should open an issue on its GitHub.
It works with Arduino IDE and we don't support PIO.
Maybe you can linked to platformio/platform-ststm32#237

@SocketNet
Copy link
Author

ok Thanks again

@ivankravets
Copy link
Contributor

@fpistm Please merge this #18 and we will reindex this library in our registry. We need to instruct PlatformIO Build System to not archive library and link as plain objects.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants