Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f7c63ad

Browse filesBrowse files
committed
Fix heapBytesRemaining default value
configTOTAL_HEAP_SIZE could be not constant Signed-off-by: Frederic.Pillon <frederic.pillon@st.com>
1 parent 1715641 commit f7c63ad
Copy full SHA for f7c63ad

File tree

Expand file treeCollapse file tree

1 file changed

+7
-1
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+7
-1
lines changed

‎portable/MemMang/heap_useNewlib.c

Copy file name to clipboardExpand all lines: portable/MemMang/heap_useNewlib.c
+7-1Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,15 @@
7272
static int totalBytesProvidedBySBRK = 0;
7373
#endif
7474
extern char _end; // Defined in the linker script
75-
static int heapBytesRemaining = configTOTAL_HEAP_SIZE; // that's (&__HeapLimit)-(&__HeapBase)
75+
static int heapBytesRemaining = -1; // configTOTAL_HEAP_SIZE is not constant will be init later
7676

7777
//! sbrk/_sbrk version supporting reentrant newlib (depends upon above symbols defined by linker control file).
7878
char * sbrk(int incr) {
7979
static char *currentHeapEnd = &_end;
8080
vTaskSuspendAll(); // Note: safe to use before FreeRTOS scheduler started
81+
if (heapBytesRemaining == -1) {
82+
heapBytesRemaining = configTOTAL_HEAP_SIZE;
83+
}
8184
char *previousHeapEnd = currentHeapEnd;
8285
if (currentHeapEnd + incr > &_end + configTOTAL_HEAP_SIZE) {
8386
#if( configUSE_MALLOC_FAILED_HOOK == 1 )
@@ -145,6 +148,9 @@ void vPortFree( void *pv ) PRIVILEGED_FUNCTION {
145148

146149
size_t xPortGetFreeHeapSize( void ) PRIVILEGED_FUNCTION {
147150
struct mallinfo mi = mallinfo();
151+
if (heapBytesRemaining == -1) {
152+
heapBytesRemaining = configTOTAL_HEAP_SIZE;
153+
}
148154
return mi.fordblks + heapBytesRemaining;
149155
}
150156

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.