This commit is contained in:
Josh Stewart 2022-01-18 16:58:00 +11:00
commit 42247d2e78
2 changed files with 19 additions and 4 deletions

View File

@ -306,8 +306,21 @@ STM32RTC& rtc = STM32RTC::getInstance();
uint16_t freeRam() uint16_t freeRam()
{ {
char top = 't'; uint32_t freeRam;
return &top - reinterpret_cast<char*>(sbrk(0)); uint32_t stackTop;
uint32_t heapTop;
// current position of the stack.
stackTop = (uint32_t)&stackTop;
// current position of heap.
void *hTop = malloc(1);
heapTop = (uint32_t)hTop;
free(hTop);
freeRam = stackTop - heapTop;
if(freeRam>0xFFFF){return 0xFFFF;}
else{return freeRam;}
} }
void doSystemReset( void ) void doSystemReset( void )

View File

@ -385,6 +385,7 @@ void ftm2_isr(void)
uint16_t freeRam() uint16_t freeRam()
{ {
uint32_t freeRam;
uint32_t stackTop; uint32_t stackTop;
uint32_t heapTop; uint32_t heapTop;
@ -395,9 +396,10 @@ uint16_t freeRam()
void *hTop = malloc(1); void *hTop = malloc(1);
heapTop = (uint32_t)hTop; heapTop = (uint32_t)hTop;
free(hTop); free(hTop);
freeRam = stackTop - heapTop;
// The difference is the free, available ram. if(freeRam>0xFFFF){return 0xFFFF;}
return (uint16_t)stackTop - heapTop; else{return freeRam;}
} }
//This function is used for attempting to set the RTC time during compile //This function is used for attempting to set the RTC time during compile