mirror of
https://github.com/iNavFlight/inav.git
synced 2025-07-23 16:25:26 +03:00
Add actual stack watermarking to startup code; add stack status to CLI status
This commit is contained in:
parent
65e37cd476
commit
7cc049a3c6
9 changed files with 599 additions and 478 deletions
|
@ -19,6 +19,7 @@
|
||||||
|
|
||||||
extern char _estack; // end of stack, declared in .LD file
|
extern char _estack; // end of stack, declared in .LD file
|
||||||
extern char _Min_Stack_Size; // declared in .LD file
|
extern char _Min_Stack_Size; // declared in .LD file
|
||||||
|
static uint32_t _Used_Stack_Size;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The ARM processor uses a full descending stack. This means the stack pointer holds the address
|
* The ARM processor uses a full descending stack. This means the stack pointer holds the address
|
||||||
|
@ -54,11 +55,25 @@ void taskStackCheck(void)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_Used_Stack_Size = (uint32_t)stackHighMem - (uint32_t)p;
|
||||||
|
|
||||||
#ifdef DEBUG_STACK
|
#ifdef DEBUG_STACK
|
||||||
debug[0] = (uint32_t)stackHighMem & 0xffff;
|
debug[0] = (uint32_t)stackHighMem & 0xffff;
|
||||||
debug[1] = (uint32_t)stackLowMem & 0xffff;
|
debug[1] = (uint32_t)stackLowMem & 0xffff;
|
||||||
debug[2] = (uint32_t)stackCurrent & 0xffff;
|
debug[2] = (uint32_t)stackCurrent & 0xffff;
|
||||||
debug[3] = (uint32_t)p & 0xffff; // watermark
|
debug[3] = (uint32_t)p & 0xffff;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32_t getTotalStackSize(void)
|
||||||
|
{
|
||||||
|
return (uint32_t)&_Min_Stack_Size;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t getUsedStackSize(void)
|
||||||
|
{
|
||||||
|
return _Used_Stack_Size;
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
23
src/main/drivers/stack_check.h
Executable file
23
src/main/drivers/stack_check.h
Executable file
|
@ -0,0 +1,23 @@
|
||||||
|
/*
|
||||||
|
* This file is part of Cleanflight.
|
||||||
|
*
|
||||||
|
* Cleanflight is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Cleanflight is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifdef STACK_CHECK
|
||||||
|
uint32_t getTotalStackSize(void);
|
||||||
|
uint32_t getUsedStackSize(void);
|
||||||
|
#endif
|
|
@ -52,6 +52,7 @@
|
||||||
#include "drivers/timer.h"
|
#include "drivers/timer.h"
|
||||||
#include "drivers/pwm_rx.h"
|
#include "drivers/pwm_rx.h"
|
||||||
#include "drivers/sdcard.h"
|
#include "drivers/sdcard.h"
|
||||||
|
#include "drivers/stack_check.h"
|
||||||
|
|
||||||
#include "drivers/buf_writer.h"
|
#include "drivers/buf_writer.h"
|
||||||
|
|
||||||
|
@ -2817,6 +2818,10 @@ static void cliStatus(char *cmdline)
|
||||||
const uint16_t i2cErrorCounter = 0;
|
const uint16_t i2cErrorCounter = 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef STACK_CHECK
|
||||||
|
cliPrintf("Used stack: %d, Total stack: %d\r\n", getUsedStackSize(), getTotalStackSize());
|
||||||
|
#endif
|
||||||
|
|
||||||
cliPrintf("Cycle Time: %d, I2C Errors: %d, config size: %d\r\n", cycleTime, i2cErrorCounter, sizeof(master_t));
|
cliPrintf("Cycle Time: %d, I2C Errors: %d, config size: %d\r\n", cycleTime, i2cErrorCounter, sizeof(master_t));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -98,6 +98,19 @@ LoopFillZerobss:
|
||||||
cmp r2, r3
|
cmp r2, r3
|
||||||
bcc FillZerobss
|
bcc FillZerobss
|
||||||
|
|
||||||
|
/* Mark the heap and stack */
|
||||||
|
ldr r2, =_heap_stack_begin
|
||||||
|
b LoopMarkHeapStack
|
||||||
|
|
||||||
|
MarkHeapStack:
|
||||||
|
movs r3, 0xa5a5a5a5
|
||||||
|
str r3, [r2], #4
|
||||||
|
|
||||||
|
LoopMarkHeapStack:
|
||||||
|
ldr r3, = _heap_stack_end
|
||||||
|
cmp r2, r3
|
||||||
|
bcc MarkHeapStack
|
||||||
|
|
||||||
/* Call the clock system intitialization function.*/
|
/* Call the clock system intitialization function.*/
|
||||||
bl SystemInit
|
bl SystemInit
|
||||||
/* Call the application's entry point.*/
|
/* Call the application's entry point.*/
|
||||||
|
|
|
@ -97,6 +97,19 @@ LoopFillZerobss:
|
||||||
cmp r2, r3
|
cmp r2, r3
|
||||||
bcc FillZerobss
|
bcc FillZerobss
|
||||||
|
|
||||||
|
/* Mark the heap and stack */
|
||||||
|
ldr r2, =_heap_stack_begin
|
||||||
|
b LoopMarkHeapStack
|
||||||
|
|
||||||
|
MarkHeapStack:
|
||||||
|
movs r3, 0xa5a5a5a5
|
||||||
|
str r3, [r2], #4
|
||||||
|
|
||||||
|
LoopMarkHeapStack:
|
||||||
|
ldr r3, = _heap_stack_end
|
||||||
|
cmp r2, r3
|
||||||
|
bcc MarkHeapStack
|
||||||
|
|
||||||
/* Call the clock system intitialization function.*/
|
/* Call the clock system intitialization function.*/
|
||||||
bl SystemInit
|
bl SystemInit
|
||||||
/* Call the application's entry point.*/
|
/* Call the application's entry point.*/
|
||||||
|
|
|
@ -105,6 +105,19 @@ LoopFillZerobss:
|
||||||
cmp r2, r3
|
cmp r2, r3
|
||||||
bcc FillZerobss
|
bcc FillZerobss
|
||||||
|
|
||||||
|
/* Mark the heap and stack */
|
||||||
|
ldr r2, =_heap_stack_begin
|
||||||
|
b LoopMarkHeapStack
|
||||||
|
|
||||||
|
MarkHeapStack:
|
||||||
|
movs r3, 0xa5a5a5a5
|
||||||
|
str r3, [r2], #4
|
||||||
|
|
||||||
|
LoopMarkHeapStack:
|
||||||
|
ldr r3, = _heap_stack_end
|
||||||
|
cmp r2, r3
|
||||||
|
bcc MarkHeapStack
|
||||||
|
|
||||||
/* Call the clock system intitialization function.*/
|
/* Call the clock system intitialization function.*/
|
||||||
bl SystemInit
|
bl SystemInit
|
||||||
/* Call the application's entry point.*/
|
/* Call the application's entry point.*/
|
||||||
|
|
|
@ -108,6 +108,19 @@ LoopFillZerobss:
|
||||||
cmp r2, r3
|
cmp r2, r3
|
||||||
bcc FillZerobss
|
bcc FillZerobss
|
||||||
|
|
||||||
|
/* Mark the heap and stack */
|
||||||
|
ldr r2, =_heap_stack_begin
|
||||||
|
b LoopMarkHeapStack
|
||||||
|
|
||||||
|
MarkHeapStack:
|
||||||
|
movs r3, 0xa5a5a5a5
|
||||||
|
str r3, [r2], #4
|
||||||
|
|
||||||
|
LoopMarkHeapStack:
|
||||||
|
ldr r3, = _heap_stack_end
|
||||||
|
cmp r2, r3
|
||||||
|
bcc MarkHeapStack
|
||||||
|
|
||||||
/* Call the clock system intitialization function.*/
|
/* Call the clock system intitialization function.*/
|
||||||
bl SystemInit
|
bl SystemInit
|
||||||
/* Call the application's entry point.*/
|
/* Call the application's entry point.*/
|
||||||
|
|
|
@ -107,6 +107,19 @@ LoopFillZerobss:
|
||||||
cmp r2, r3
|
cmp r2, r3
|
||||||
bcc FillZerobss
|
bcc FillZerobss
|
||||||
|
|
||||||
|
/* Mark the heap and stack */
|
||||||
|
ldr r2, =_heap_stack_begin
|
||||||
|
b LoopMarkHeapStack
|
||||||
|
|
||||||
|
MarkHeapStack:
|
||||||
|
movs r3, 0xa5a5a5a5
|
||||||
|
str r3, [r2], #4
|
||||||
|
|
||||||
|
LoopMarkHeapStack:
|
||||||
|
ldr r3, = _heap_stack_end
|
||||||
|
cmp r2, r3
|
||||||
|
bcc MarkHeapStack
|
||||||
|
|
||||||
/*FPU settings*/
|
/*FPU settings*/
|
||||||
ldr r0, =0xE000ED88 /* Enable CP10,CP11 */
|
ldr r0, =0xE000ED88 /* Enable CP10,CP11 */
|
||||||
ldr r1,[r0]
|
ldr r1,[r0]
|
||||||
|
|
|
@ -107,6 +107,19 @@ LoopFillZerobss:
|
||||||
cmp r2, r3
|
cmp r2, r3
|
||||||
bcc FillZerobss
|
bcc FillZerobss
|
||||||
|
|
||||||
|
/* Mark the heap and stack */
|
||||||
|
ldr r2, =_heap_stack_begin
|
||||||
|
b LoopMarkHeapStack
|
||||||
|
|
||||||
|
MarkHeapStack:
|
||||||
|
movs r3, 0xa5a5a5a5
|
||||||
|
str r3, [r2], #4
|
||||||
|
|
||||||
|
LoopMarkHeapStack:
|
||||||
|
ldr r3, = _heap_stack_end
|
||||||
|
cmp r2, r3
|
||||||
|
bcc MarkHeapStack
|
||||||
|
|
||||||
/*FPU settings*/
|
/*FPU settings*/
|
||||||
ldr r0, =0xE000ED88 /* Enable CP10,CP11 */
|
ldr r0, =0xE000ED88 /* Enable CP10,CP11 */
|
||||||
ldr r1,[r0]
|
ldr r1,[r0]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue