File tree 2 files changed +39
-4
lines changed
libraries/ESP32/examples/ArduinoStackSize 2 files changed +39
-4
lines changed Original file line number Diff line number Diff line change @@ -179,10 +179,8 @@ uint16_t makeWord(uint8_t h, uint8_t l);
179
179
180
180
#define word (...) makeWord(__VA_ARGS__)
181
181
182
- #define ESP_LOOP_TASK_STACK_SIZE (sz ) \
183
- size_t getArduinoLoopTaskStackSize (void ) { \
184
- return sz; \
185
- }
182
+ size_t getArduinoLoopTaskStackSize (void );
183
+ #define SET_LOOPTASK_STACK_SIZE (sz ) size_t getArduinoLoopTaskStackSize () { return sz;}
186
184
187
185
unsigned long pulseIn (uint8_t pin, uint8_t state, unsigned long timeout = 1000000L );
188
186
unsigned long pulseInLong (uint8_t pin, uint8_t state, unsigned long timeout = 1000000L );
Original file line number Diff line number Diff line change
1
+ /*
2
+ ESP32 Arduino creates a task to run setup() and then to execute loop() continuously
3
+ This task can be found at https://github.com/espressif/arduino-esp32/blob/master/cores/esp32/main.cpp
4
+
5
+ By default "loopTask" will be created with a stack size of 8KB.
6
+ This should be plenty for most general sketches.
7
+
8
+ There is a way to change the stack size of this task by using
9
+ SET_LOOPTASK_STACK_SIZE(size);
10
+ It will bypass the default stack size of 8KB and allow the user to define a new size.
11
+
12
+ It is recommend this value to be higher than 8KB, for instance 16KB.
13
+ This increasing may be necessary for the sketches that use deep recursion for instance.
14
+
15
+ In this example, you can verify it by changing or just commenting out SET_LOOPTASK_STACK_SIZE();
16
+ */
17
+
18
+ #define ARDUINO_TASK_STACK_SIZE (16 *1024 ) // 16KB
19
+
20
+ // This sets Arduino Stack Size - comment this line to use default 8K stack size
21
+ SET_LOOPTASK_STACK_SIZE (ARDUINO_TASK_STACK_SIZE);
22
+
23
+ void setup () {
24
+ Serial.begin (115200 );
25
+
26
+ Serial.printf (" Arduino Stack was set to %d bytes" , getArduinoLoopTaskStackSize ());
27
+
28
+ // Print unused stack for the task that is running setup()
29
+ Serial.printf (" \n Setup() - Free Stack Space: %d" , uxTaskGetStackHighWaterMark (NULL ));
30
+ }
31
+
32
+ void loop () {
33
+ delay (1000 );
34
+
35
+ // Print unused stack for the task that is running loop() - the same as for setup()
36
+ Serial.printf (" \n Loop() - Free Stack Space: %d" , uxTaskGetStackHighWaterMark (NULL ));
37
+ }
You can’t perform that action at this time.
0 commit comments