diff --git a/example/example.sct b/example/example.sct
index 79105f1..acdf9df 100644
--- a/example/example.sct
+++ b/example/example.sct
@@ -13,23 +13,24 @@
#define HEAP_ALIGN 8
#define HEAP_SIZE (RAM1_LIMIT - AlignExpr(ImageLimit(RW_IRAM1), HEAP_ALIGN))
+
LR_IROM1 0x00000000 0x00040000 { ; load region size_region
- ER_IROM1 0x00000000 0x00040000 { ; load address = execution address
- *.o (RESET, +First)
- *(InRoot$$Sections)
- .ANY (+RO)
- .ANY (+XO)
- }
-
- ARM_LIB_STACK RAM1_BASE ALIGN 8 EMPTY STACK_SIZE {}
-
- ;RW_IRAM1 0x20000000 0x00020000 { ; RW data
- RW_IRAM1 +0 { ; RW data
- .ANY (+RW +ZI)
- }
-
- ARM_LIB_HEAP +0 ALIGN HEAP_ALIGN EMPTY HEAP_SIZE {}
-
- ScatterAssert(ImageLimit(ARM_LIB_HEAP) <= RAM1_LIMIT)
+ ER_IROM1 0x00000000 0x00040000 { ; load address = execution address
+ *.o (RESET, +First)
+ *(InRoot$$Sections)
+ .ANY (+RO)
+ .ANY (+XO)
+ }
+
+ ARM_LIB_STACK RAM1_BASE ALIGN 8 EMPTY FILL 0xDEADBEEF STACK_SIZE {}
+
+ RW_IRAM1 +0 { ; RW data
+ .ANY (+RW +ZI)
+ }
+
+ ARM_LIB_HEAP +0 ALIGN HEAP_ALIGN EMPTY HEAP_SIZE {}
+
+ ScatterAssert(ImageLimit(ARM_LIB_HEAP) <= RAM1_LIMIT)
}
+
diff --git a/example/example.uvoptx b/example/example.uvoptx
index afb0af7..9e68388 100644
--- a/example/example.uvoptx
+++ b/example/example.uvoptx
@@ -364,54 +364,6 @@
0
0
- 94
- 1
- 0
- 0
- 0
- 0
- 0
- 0
- 0
- <1>.\main.c
-
-
-
-
- 1
- 0
- 93
- 1
- 0
- 0
- 0
- 0
- 0
- 0
- 0
- <1>.\main.c
-
-
-
-
- 2
- 0
- 92
- 1
- 0
- 0
- 0
- 0
- 0
- 0
- 0
- <1>.\main.c
-
-
-
-
- 3
- 0
62
1
0
@@ -785,7 +737,7 @@
perf_counter_lib
- 0
+ 1
0
0
0
@@ -857,7 +809,7 @@
::Device
- 1
+ 0
0
0
1
diff --git a/example/example.uvprojx b/example/example.uvprojx
index 0a2546b..ffe5702 100644
--- a/example/example.uvprojx
+++ b/example/example.uvprojx
@@ -10,7 +10,7 @@
example_arm_compiler_6
0x4
ARM-ADS
- 6180000::V6.18::ARMCLANG
+ 6190000::V6.19::ARMCLANG
1
@@ -52,7 +52,7 @@
example
1
0
- 0
+ 1
1
1
.\
@@ -337,7 +337,7 @@
0
0
- -Wno-missing-prototypes -Wno-reserved-identifier -Wno-sign-conversion -Wno-c11-extensions -Wno-implicit-int-conversion
+ -Wno-missing-prototypes -Wno-reserved-identifier -Wno-sign-conversion -Wno-c11-extensions -Wno-implicit-int-conversion -Wno-invalid-utf8
__PERF_COUNTER_CFG_USE_SYSTICK_WRAPPER__
..
@@ -530,7 +530,7 @@
library
0x4
ARM-ADS
- 6180000::V6.18::ARMCLANG
+ 6190000::V6.19::ARMCLANG
1
diff --git a/example/main.c b/example/main.c
index 26192c0..aad9088 100644
--- a/example/main.c
+++ b/example/main.c
@@ -63,6 +63,66 @@ static example_lv0_t s_tItem[8] = {
{.chID = 7},
};
+#if defined(__clang__)
+# pragma clang diagnostic push
+# pragma clang diagnostic ignored "-Wdollar-in-identifier-extension"
+# pragma clang diagnostic ignored "-Wdouble-promotion"
+#endif
+uint32_t calculate_stack_usage_topdown(void)
+{
+ extern uint32_t Image$$ARM_LIB_STACK$$Limit[];
+ extern uint32_t Image$$ARM_LIB_STACK$$Length;
+
+ uint32_t *pwStack = Image$$ARM_LIB_STACK$$Limit;
+ uint32_t wStackSize = (uintptr_t)&Image$$ARM_LIB_STACK$$Length / 4;
+ uint32_t wStackUsed = 0;
+
+
+ do {
+ if (*--pwStack == 0xDEADBEEF) {
+ break;
+ }
+ wStackUsed++;
+ } while(--wStackSize);
+
+
+ printf("\r\nStack Usage: [%d/%d] %2.2f%%\r\n",
+ wStackUsed * 4,
+ (uintptr_t)&Image$$ARM_LIB_STACK$$Length,
+ ( (float)wStackUsed * 400.0f
+ / (float)(uintptr_t)&Image$$ARM_LIB_STACK$$Length));
+
+ return wStackUsed * 4;
+}
+
+uint32_t calculate_stack_usage_bottomup(void)
+{
+ extern uint32_t Image$$ARM_LIB_STACK$$Base[];
+ extern uint32_t Image$$ARM_LIB_STACK$$Length;
+
+ uint32_t *pwStack = Image$$ARM_LIB_STACK$$Base;
+ uint32_t wStackSize = (uintptr_t)&Image$$ARM_LIB_STACK$$Length;
+ uint32_t wStackUsed = wStackSize / 4;
+
+ do {
+ if (*pwStack++ != 0xDEADBEEF) {
+ break;
+ }
+ } while(--wStackUsed);
+
+ printf("\r\nStack Usage: [%d/%d] %2.2f%%\r\n",
+ wStackUsed * 4,
+ wStackSize,
+ ( (float)wStackUsed * 400.0f / (float)wStackSize));
+
+ return wStackUsed * 4;
+}
+
+#if defined(__clang__)
+# pragma clang diagnostic pop
+#endif
+
+
/*----------------------------------------------------------------------------
Main function
*----------------------------------------------------------------------------*/
@@ -120,6 +180,9 @@ int main (void)
printf("used clock cycle: %d", (int32_t)(get_system_ticks() - tStart));
} while(0);
+ calculate_stack_usage_topdown();
+ calculate_stack_usage_bottomup();
+
while (1) {
printf("\r\nhello world\r\n");
delay_ms(1000);
diff --git a/lib/perf_counter.h b/lib/perf_counter.h
index 77ad411..cd2b55d 100644
--- a/lib/perf_counter.h
+++ b/lib/perf_counter.h
@@ -285,7 +285,7 @@ extern "C" {
#endif
#if __PLOOC_VA_NUM_ARGS() != 0
-#warning Please enable GNC extensions, it is required by __cycleof__() and \
+#warning Please enable GNU extensions, it is required by __cycleof__() and \
__super_loop_monitor__()
#endif
@@ -472,9 +472,6 @@ __attribute__((noinline))
extern int64_t clock(void);
#endif
-
-
-
/*! @} */
/*!
@@ -607,7 +604,6 @@ extern int64_t __stop_task_cycle_counter(task_cycle_info_t *ptInfo);
* special conditions *
*----------------------------------------------------------------------------*/
-
/*! \brief initialise cycle counter service
* \note - don't forget to tell the function whether the systick is already
* used by user applications.
diff --git a/lib/perf_counter.lib b/lib/perf_counter.lib
index 591357e..12866c9 100644
Binary files a/lib/perf_counter.lib and b/lib/perf_counter.lib differ