stack overflow, if i use a varibale in a task
Posted: Tue Sep 17, 2019 3:10 am
Hello,
my attempts to use a variable in the task fails miserably. What am i doing incorrectly?
thank you in advance:
this works:
This does not:
the only difference is :
printf("Current led is - %d \n",current_led);
Output:
Thank you for your advice.
my attempts to use a variable in the task fails miserably. What am i doing incorrectly?
thank you in advance:
this works:
Code: Select all
[Codebox=c file=Untitled.c]
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_system.h"
#include "esp_spi_flash.h"
#include "driver/gpio.h"
#include "nvs_flash.h"
#include <stdint.h>
void blinking_task(void *pvParameter)
{
// set gpio and its direction
gpio_pad_select_gpio(BLINK_GPIO);
gpio_set_direction(BLINK_GPIO, GPIO_MODE_OUTPUT);
int current_led = 1;
while (1)
{
gpio_set_level(BLINK_GPIO, 1);
vTaskDelay(1000 / portTICK_PERIOD_MS);
gpio_set_level(BLINK_GPIO, 0);
vTaskDelay(1000 / portTICK_PERIOD_MS);
[b] // printf("Current led is - %d \n",current_led);[/b]
printf("blah \n");
}
}
void main{} {
BaseType_t xReturned;
xReturned = xTaskCreate(blinking_task, "blinky", configMINIMAL_STACK_SIZE, NULL, 5, NULL);
}[/Codebox]
Code: Select all
[Codebox=c file=Untitled.c]
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_system.h"
#include "esp_spi_flash.h"
#include "driver/gpio.h"
#include "nvs_flash.h"
#include <stdint.h>
void blinking_task(void *pvParameter)
{
// set gpio and its direction
gpio_pad_select_gpio(BLINK_GPIO);
gpio_set_direction(BLINK_GPIO, GPIO_MODE_OUTPUT);
int current_led = 1;
while (1)
{
gpio_set_level(BLINK_GPIO, 1);
vTaskDelay(1000 / portTICK_PERIOD_MS);
gpio_set_level(BLINK_GPIO, 0);
vTaskDelay(1000 / portTICK_PERIOD_MS);
[b]printf("Current led is - %d \n",current_led);[/b]
printf("blah \n");
}
}
void main{} {
BaseType_t xReturned;
xReturned = xTaskCreate(blinking_task, "blinky", configMINIMAL_STACK_SIZE, NULL, 5, NULL);
}
[/Codebox]
the only difference is :
printf("Current led is - %d \n",current_led);
Output:
- ␛[0;32mI (246) cpu_start: Starting scheduler on PRO CPU.␛[0m
- ␛[0;32mI (0) cpu_start: Starting scheduler on APP CPU.␛[0m
- Hello world!
- Current led is - 1
- blah
- ***ERROR*** A stack overflow in task blinky has been detected.
- abort() was called at PC 0x40089714 on core 0
- Backtrace: 0x40089403:0x3ffb3b50 0x400896fd:0x3ffb3b70 0x40089714:0x3ffb3b90 0x400876a9:0x3ffb3bb0 0x40086ac8:0x3ffb3bd0 0x40086a7e:0x00000006
- Rebooting...
- ets Jun 8 2016 00:22:57
Thank you for your advice.