Git Product home page Git Product logo

Comments (6)

greiman avatar greiman commented on August 20, 2024 1

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.

greiman avatar greiman commented on August 20, 2024

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.

Formator avatar Formator commented on August 20, 2024

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.

Formator avatar Formator commented on August 20, 2024

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.

greiman avatar greiman commented on August 20, 2024

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.

Formator avatar Formator commented on August 20, 2024

Thank you for your answers I will also try heap 2 to get more control over heap.

from freertos-arduino.

Related Issues (15)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.