Browse Source

Merge branch 'inav_stack_check' of https://github.com/martinbudden/cleanflight into martinbudden-inav_stack_check

master
Konstantin Sharlaimov (DigitalEntity) 8 years ago
parent
commit
65e37cd476
  1. 1
      Makefile
  2. 64
      src/main/drivers/stack_check.c
  3. 3
      src/main/main.c
  4. 3
      src/main/scheduler/scheduler.h
  5. 8
      src/main/scheduler/scheduler_tasks.c
  6. 1
      src/main/scheduler/scheduler_tasks.h
  7. 3
      src/main/target/CJMCU/target.h
  8. 5
      src/main/target/link/stm32_flash.ld

1
Makefile

@ -396,6 +396,7 @@ COMMON_SRC = \
drivers/serial.c \
drivers/serial_uart.c \
drivers/sound_beeper.c \
drivers/stack_check.c \
drivers/system.c \
drivers/timer.c \
drivers/io_pca9685.c \

64
src/main/drivers/stack_check.c

@ -0,0 +1,64 @@
/*
* stack_check.c
*
* Created on: 23 Aug 2016
* Author: martinbudden
*/
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#include "platform.h"
#ifdef STACK_CHECK
#include "build/debug.h"
#define STACK_FILL_CHAR 0xa5
extern char _estack; // end of stack, declared in .LD file
extern char _Min_Stack_Size; // declared in .LD file
/*
* The ARM processor uses a full descending stack. This means the stack pointer holds the address
* of the last stacked item in memory. When the processor pushes a new item onto the stack,
* it decrements the stack pointer and then writes the item to the new memory location.
*
*
* RAM layout is generally as below, although some targets vary
*
* F1 Boards
* RAM is origin 0x20000000 length 20K that is:
* 0x20000000 to 0x20005000
*
* F3 Boards
* RAM is origin 0x20000000 length 40K that is:
* 0x20000000 to 0x2000a000
*
* F4 Boards
* RAM is origin 0x20000000 length 128K that is:
* 0x20000000 to 0x20020000
*
*/
void taskStackCheck(void)
{
char * const stackHighMem = &_estack;
const uint32_t stackSize = (uint32_t)&_Min_Stack_Size;
char * const stackLowMem = stackHighMem - stackSize;
const char * const stackCurrent = (char *)&stackLowMem;
char *p;
for (p = stackLowMem; p < stackCurrent; ++p) {
if (*p != STACK_FILL_CHAR) {
break;
}
}
#ifdef DEBUG_STACK
debug[0] = (uint32_t)stackHighMem & 0xffff;
debug[1] = (uint32_t)stackLowMem & 0xffff;
debug[2] = (uint32_t)stackCurrent & 0xffff;
debug[3] = (uint32_t)p & 0xffff; // watermark
#endif
}
#endif

3
src/main/main.c

@ -652,6 +652,9 @@ int main(void)
#ifdef LED_STRIP
setTaskEnabled(TASK_LEDSTRIP, feature(FEATURE_LED_STRIP));
#endif
#ifdef STACK_CHECK
setTaskEnabled(TASK_STACK_CHECK, true);
#endif
#ifdef USE_PMW_SERVO_DRIVER
setTaskEnabled(TASK_PWMDRIVER, feature(FEATURE_PWM_SERVO_DRIVER));

3
src/main/scheduler/scheduler.h

@ -71,6 +71,9 @@ typedef enum {
#ifdef USE_PMW_SERVO_DRIVER
TASK_PWMDRIVER,
#endif
#ifdef STACK_CHECK
TASK_STACK_CHECK,
#endif
/* Count of real tasks */
TASK_COUNT,

8
src/main/scheduler/scheduler_tasks.c

@ -139,4 +139,12 @@ cfTask_t cfTasks[TASK_COUNT] = {
},
#endif
#ifdef STACK_CHECK
[TASK_STACK_CHECK] = {
.taskName = "STACKCHECK",
.taskFunc = taskStackCheck,
.desiredPeriod = 1000000 / 10, // 10 Hz
.staticPriority = TASK_PRIORITY_IDLE,
},
#endif
};

1
src/main/scheduler/scheduler_tasks.h

@ -36,3 +36,4 @@ void taskSystem(void);
#ifdef USE_PMW_SERVO_DRIVER
void taskSyncPwmDriver(void);
#endif
void taskStackCheck(void);

3
src/main/target/CJMCU/target.h

@ -109,6 +109,9 @@
#undef BLACKBOX
#endif
#define STACK_CHECK
#define DEBUG_STACK
// Number of available PWM outputs
#define MAX_PWM_OUTPUT_PORTS 4

5
src/main/target/link/stm32_flash.ld

@ -110,6 +110,9 @@ SECTIONS
} >RAM
/* User_heap_stack section, used to check that there is enough RAM left */
_heap_stack_end = ORIGIN(RAM)+LENGTH(RAM) - 8; /* 8 bytes to allow for alignment */
_heap_stack_begin = _heap_stack_end - _Min_Stack_Size - _Min_Heap_Size;
. = _heap_stack_begin;
._user_heap_stack :
{
. = ALIGN(4);
@ -118,7 +121,7 @@ SECTIONS
. = . + _Min_Heap_Size;
. = . + _Min_Stack_Size;
. = ALIGN(4);
} >RAM
} >RAM = 0xa5
/* MEMORY_bank1 section, code must be located here explicitly */
/* Example: extern int foo(void) __attribute__ ((section (".mb1text"))); */

Loading…
Cancel
Save