From a5e8c85557512b22d480a15639819b844a90a3df Mon Sep 17 00:00:00 2001 From: Damjan Adamic Date: Fri, 20 Feb 2015 20:33:00 +0100 Subject: [PATCH 1/3] Interrupt stack size reduced to 1kB, enabled painting and display of free interrupt stack space --- radio/src/gui/Taranis/view_statistics.cpp | 8 +++++--- radio/src/opentx.h | 3 ++- radio/src/targets/simu/simpgmspace.cpp | 2 ++ radio/src/targets/sky9x/syscalls.c | 8 +++----- .../Source/Templates/gcc_ride7/startup_stm32f2xx.s | 13 +++++++++++++ radio/src/targets/taranis/stm32_flash_bl.ld | 7 +++++-- radio/src/targets/taranis/stm32_ramBoot.ld | 7 +++++-- radio/src/tasks_arm.cpp | 6 +++++- 8 files changed, 40 insertions(+), 14 deletions(-) diff --git a/radio/src/gui/Taranis/view_statistics.cpp b/radio/src/gui/Taranis/view_statistics.cpp index 99da45a65..5a113abc6 100755 --- a/radio/src/gui/Taranis/view_statistics.cpp +++ b/radio/src/gui/Taranis/view_statistics.cpp @@ -149,12 +149,14 @@ void menuStatisticsDebug(uint8_t event) lcd_puts(lcdLastPos, MENU_DEBUG_Y_MIXMAX, "ms"); lcd_putsLeft(MENU_DEBUG_Y_RTOS, STR_FREESTACKMINB); - lcd_putsAtt(MENU_DEBUG_COL1_OFS, MENU_DEBUG_Y_RTOS+1, "[Main]", SMLSIZE); + lcd_putsAtt(MENU_DEBUG_COL1_OFS, MENU_DEBUG_Y_RTOS+1, "[M]", SMLSIZE); lcd_outdezAtt(lcdLastPos, MENU_DEBUG_Y_RTOS, stack_free(0), UNSIGN|LEFT); - lcd_putsAtt(lcdLastPos+2, MENU_DEBUG_Y_RTOS+1, "[Mix]", SMLSIZE); + lcd_putsAtt(lcdLastPos+2, MENU_DEBUG_Y_RTOS+1, "[X]", SMLSIZE); lcd_outdezAtt(lcdLastPos, MENU_DEBUG_Y_RTOS, stack_free(1), UNSIGN|LEFT); - lcd_putsAtt(lcdLastPos+2, MENU_DEBUG_Y_RTOS+1, "[Audio]", SMLSIZE); + lcd_putsAtt(lcdLastPos+2, MENU_DEBUG_Y_RTOS+1, "[A]", SMLSIZE); lcd_outdezAtt(lcdLastPos, MENU_DEBUG_Y_RTOS, stack_free(2), UNSIGN|LEFT); + lcd_putsAtt(lcdLastPos+2, MENU_DEBUG_Y_RTOS+1, "[I]", SMLSIZE); + lcd_outdezAtt(lcdLastPos, MENU_DEBUG_Y_RTOS, stack_free(255), UNSIGN|LEFT); lcd_puts(3*FW, 7*FH+1, STR_MENUTORESET); lcd_status_line(); diff --git a/radio/src/opentx.h b/radio/src/opentx.h index c9bfaa994..3fcbc0753 100644 --- a/radio/src/opentx.h +++ b/radio/src/opentx.h @@ -720,7 +720,7 @@ extern uint8_t flightModeTransitionLast; extern int _end; extern int _estack; extern int _main_stack_start; - #define getAvailableMemory() ((unsigned int)((unsigned char *)&_estack - heap)) + #define getAvailableMemory() ((unsigned int)((unsigned char *)&_main_stack_start - heap)) #endif void evalFlightModeMixes(uint8_t mode, uint8_t tick10ms); @@ -940,6 +940,7 @@ extern uint16_t lastMixerDuration; #if defined(CPUARM) uint32_t stack_free(uint32_t tid); + void stack_paint(); #else uint16_t stack_free(); #endif diff --git a/radio/src/targets/simu/simpgmspace.cpp b/radio/src/targets/simu/simpgmspace.cpp index 1be32d8cc..77a05fef7 100644 --- a/radio/src/targets/simu/simpgmspace.cpp +++ b/radio/src/targets/simu/simpgmspace.cpp @@ -313,6 +313,8 @@ void *main_thread(void *) try { #endif + stack_paint(); + s_current_protocol[0] = 255; g_menuStackPtr = 0; diff --git a/radio/src/targets/sky9x/syscalls.c b/radio/src/targets/sky9x/syscalls.c index 98e270f65..09b70aa81 100644 --- a/radio/src/targets/sky9x/syscalls.c +++ b/radio/src/targets/sky9x/syscalls.c @@ -53,10 +53,8 @@ #undef errno extern int errno; -extern int _end; -extern int _estack; - -#define RAM_END (unsigned char *)&_estack +extern int _end; +extern int _main_stack_start; /*---------------------------------------------------------------------------- * Exported functions @@ -68,7 +66,7 @@ extern int _getpid ( void ) ; unsigned char *heap = (unsigned char *)&_end; extern caddr_t _sbrk(int nbytes) { - if (heap + nbytes < RAM_END-4096) { + if (heap + nbytes < (unsigned char *)&_main_stack_start) { unsigned char *prev_heap = heap; heap += nbytes; return (caddr_t) prev_heap; diff --git a/radio/src/targets/taranis/STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/CMSIS/Device/ST/STM32F2xx/Source/Templates/gcc_ride7/startup_stm32f2xx.s b/radio/src/targets/taranis/STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/CMSIS/Device/ST/STM32F2xx/Source/Templates/gcc_ride7/startup_stm32f2xx.s index cccf3f7a6..2fa2d4149 100644 --- a/radio/src/targets/taranis/STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/CMSIS/Device/ST/STM32F2xx/Source/Templates/gcc_ride7/startup_stm32f2xx.s +++ b/radio/src/targets/taranis/STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/CMSIS/Device/ST/STM32F2xx/Source/Templates/gcc_ride7/startup_stm32f2xx.s @@ -98,10 +98,23 @@ LoopFillZerobss: ldr r3, = _ebss cmp r2, r3 bcc FillZerobss + +/*Paint Main Stack */ + ldr r2, = _main_stack_start +PaintMainStack: + movs r3, #0x55555555 + str r3, [r2], #4 +LoopPaintMainStack: + ldr r3, = _estack + cmp r2, r3 + bcc PaintMainStack + /* Call the clock system intitialization function.*/ bl SystemInit + /* Call C++ constructors for static objects */ bl __libc_init_array + /* Call the application's entry point.*/ bl main bx lr diff --git a/radio/src/targets/taranis/stm32_flash_bl.ld b/radio/src/targets/taranis/stm32_flash_bl.ld index 4ff28f4db..43f2eeb83 100644 --- a/radio/src/targets/taranis/stm32_flash_bl.ld +++ b/radio/src/targets/taranis/stm32_flash_bl.ld @@ -37,7 +37,10 @@ _estack = 0x20020000; /* end of 128K SRAM */ /* Generate a link error if heap and stack don't fit into RAM */ _Min_Heap_Size = 0; /* required amount of heap */ -_Min_Stack_Size = 0x200; /* required amount of stack */ +_Main_Stack_Size = 1024; /* required amount of stack for interrupt stack (Main stack) */ + +/*Main stack end*/ +_main_stack_start = _estack - _Main_Stack_Size; /* Specify the memory areas */ MEMORY @@ -150,7 +153,7 @@ SECTIONS { . = ALIGN(4); . = . + _Min_Heap_Size; - . = . + _Min_Stack_Size; + . = . + _Main_Stack_Size; . = ALIGN(4); } >RAM diff --git a/radio/src/targets/taranis/stm32_ramBoot.ld b/radio/src/targets/taranis/stm32_ramBoot.ld index c8204c5ec..697df960b 100644 --- a/radio/src/targets/taranis/stm32_ramBoot.ld +++ b/radio/src/targets/taranis/stm32_ramBoot.ld @@ -24,7 +24,10 @@ _estack = 0x20020000; /* end of 128K SRAM */ /* Generate a link error if heap and stack don't fit into RAM */ _Min_Heap_Size = 0; /* required amount of heap */ -_Min_Stack_Size = 0x200; /* required amount of stack */ +_Main_Stack_Size = 1024; /* required amount of stack for interrupt stack (Main stack) */ + +/*Main stack end*/ +_main_stack_start = _estack - _Main_Stack_Size; /* Specify the memory areas */ MEMORY @@ -129,7 +132,7 @@ SECTIONS { . = ALIGN(4); . = . + _Min_Heap_Size; - . = . + _Min_Stack_Size; + . = . + _Main_Stack_Size; . = ALIGN(4); } >RAM diff --git a/radio/src/tasks_arm.cpp b/radio/src/tasks_arm.cpp index 971fb3115..8ca2b437a 100644 --- a/radio/src/tasks_arm.cpp +++ b/radio/src/tasks_arm.cpp @@ -99,11 +99,15 @@ uint32_t stack_free(uint32_t tid) stack = audioStack; size = AUDIO_STACK_SIZE; break; -#if 0 // defined(PCBTARANIS) && !defined(SIMU) +#if defined(PCBTARANIS) case 255: + #if defined(SIMU) + return 1024; + #else // main stack stack = (OS_STK *)&_main_stack_start; size = ((unsigned char *)&_estack - (unsigned char *)&_main_stack_start) / 4; + #endif break; #endif default: From 83dd03d654c20fff1c81ad2020f6766b9789f829 Mon Sep 17 00:00:00 2001 From: Damjan Adamic Date: Fri, 20 Feb 2015 20:35:29 +0100 Subject: [PATCH 2/3] failsafeCounter reduced to uint16_t (needed max value is 1000) --- radio/src/pulses/pulses_arm.cpp | 2 +- radio/src/pulses/pulses_arm.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/radio/src/pulses/pulses_arm.cpp b/radio/src/pulses/pulses_arm.cpp index 19cba05de..68fa7f036 100644 --- a/radio/src/pulses/pulses_arm.cpp +++ b/radio/src/pulses/pulses_arm.cpp @@ -38,7 +38,7 @@ uint8_t s_pulses_paused = 0; uint8_t s_current_protocol[NUM_MODULES] = { MODULES_INIT(255) }; -uint32_t failsafeCounter[NUM_MODULES] = { MODULES_INIT(100) }; +uint16_t failsafeCounter[NUM_MODULES] = { MODULES_INIT(100) }; uint8_t moduleFlag[NUM_MODULES] = { 0 }; void setupPulses(unsigned int port) diff --git a/radio/src/pulses/pulses_arm.h b/radio/src/pulses/pulses_arm.h index 62c2b7360..741ec3ec3 100644 --- a/radio/src/pulses/pulses_arm.h +++ b/radio/src/pulses/pulses_arm.h @@ -45,7 +45,7 @@ extern uint8_t s_current_protocol[NUM_MODULES]; extern uint8_t s_pulses_paused; -extern uint32_t failsafeCounter[NUM_MODULES]; +extern uint16_t failsafeCounter[NUM_MODULES]; void setupPulses(unsigned int port); void setupPulsesDSM2(unsigned int port); From 3ef447b7149dbd7a2911c70d8acda761ddbe63e7 Mon Sep 17 00:00:00 2001 From: Damjan Adamic Date: Fri, 20 Feb 2015 21:03:41 +0100 Subject: [PATCH 3/3] Compilation failure (thanks to Jenkins) --- radio/src/targets/simu/simpgmspace.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/radio/src/targets/simu/simpgmspace.cpp b/radio/src/targets/simu/simpgmspace.cpp index 77a05fef7..a6dcd9f88 100644 --- a/radio/src/targets/simu/simpgmspace.cpp +++ b/radio/src/targets/simu/simpgmspace.cpp @@ -313,8 +313,10 @@ void *main_thread(void *) try { #endif +#if defined(CPUARM) stack_paint(); - +#endif + s_current_protocol[0] = 255; g_menuStackPtr = 0;