Comments (6)
When you execute this in a thread you will get an address in the heap. FreeRTOS creates the thread's stack on the heap.
register char * stack_ptr asm("sp");
The next line can fail for the version of malloc on some ARM Arduino boards. It may be OK on Due.
char *heapend = sbrk(0);
If you create all threads in setup and don't call malloc directly you should be OK. FreeRTOS assumes you will use it's memory allocator. Here is the code is in heap_3.c
This allocator may fail in threads if malloc fails in threads. Some versions of malloc look at the stack pointer and find it in the heap and return null.
void *pvPortMalloc( size_t xWantedSize )
{
void *pvReturn;
vTaskSuspendAll();
{
pvReturn = malloc( xWantedSize );
traceMALLOC( pvReturn, xWantedSize );
}
( void ) xTaskResumeAll();
#if( configUSE_MALLOC_FAILED_HOOK == 1 )
{
if( pvReturn == NULL )
{
extern void vApplicationMallocFailedHook( void );
vApplicationMallocFailedHook();
}
}
#endif
return pvReturn;
}
/*-----------------------------------------------------------*/
void vPortFree( void *pv )
{
if( pv )
{
vTaskSuspendAll();
{
free( pv );
traceFREE( pv, 0 );
}
( void ) xTaskResumeAll();
}
}
from freertos-arduino.
Dynamic memory does not work for with threads for most versions of Arduino. There are multiple issues with malloc on Arduino
Various parts of the Arduino system uses malloc so you can't replace malloc with a thread safe versions of FreeRTOS's memory allocation.
from freertos-arduino.
I understand your answer but real question here is do heap and stack mamory overlaps for real or do I have wrong codo to show free mem?
I have come to this because I'm using your FreeRTOS port in my other project and suddenly I had experienced mcu freeze or variable redefine it self and other memory related symptoms.
from freertos-arduino.
Thank you for your answer now I know that my method show wrong free mem. If someone will have the same issue I would also suggest this video.
Is there any chance that API method xPortGetFreeHeapSize could work, because I have try it but then portUSING_MPU_WRAPPERS must be defined and when I do that, I get many errors.
from freertos-arduino.
Your use of mallinfo is about the best you can do.
xPortGetFreeHeapSize() will be not defined since I use heap_3.c. heap_3.c shown above, uses malloc() so there is not a definite amount of free heap. The stack and heap share the same area so the heap can grow. Also the heap is fragmented so it contains free memory.
heap_1.c, heap_2.c, and heap_4.c use a single array of size TOTAL_HEAP_SIZE for the FreeRTOS heap. xPortGetFreeHeapSize () returns how much memory is free in this array.
heap_5.c allows several arrays to be used and xPortGetFreeHeapSize () returns the total free memory in these arrays.
See this for more detail.
from freertos-arduino.
Thank you for your answers I will also try heap 2 to get more control over heap.
from freertos-arduino.
Related Issues (15)
- Update to FreeRTOS 8.2 HOT 4
- Serial.readString() returns empty String HOT 1
- Linking issue on a mac for Blinky project HOT 1
- ATTiny1634 support. HOT 5
- Supported processors
- Can the tick rate be adjusted? HOT 1
- Free_RTOS_ARM compatibility with teensy 3.1 HOT 1
- Timer not working HOT 1
- Need to include <avr/sleep.h> to use your code HOT 1
- Compile error with MKR1000 board HOT 1
- Adding Arduino Zero/SamD21 processors HOT 1
- FreeRTOS_AVR tick timer question. HOT 2
- Serial.read in task HOT 1
- Float not working with FreeRTOS_ARM HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from freertos-arduino.