I was testing an idea to detect if an watcher application could save in RAM was thread was causing the watchdog reset.
The solution was easy to implement, I just reserve a area in the linkerscript:
diff --git a/boards/arm/stm32/stm32f401rc-rs485/scripts/ld.script b/boards/arm/stm32/stm32f401rc-rs485/scripts/ld.script
index 96355a3762..98eb837c92 100644
--- a/boards/arm/stm32/stm32f401rc-rs485/scripts/ld.script
+++ b/boards/arm/stm32/stm32f401rc-rs485/scripts/ld.script
@@ -82,6 +82,10 @@ SECTIONS
_edata = ABSOLUTE(.);
} > sram AT > flash + .no_init : {
+ *(.no_init)
+ } > sram
+
.bss : {
_sbss = ABSOLUTE(.);
*(.bss .bss.*)
Then in my application I just define a variable to use that area:
diff --git a/examples/hello/hello_main.c b/examples/hello/hello_main.c
index 2cd6cb400..717f5e881 100644
--- a/examples/hello/hello_main.c
+++ b/examples/hello/hello_main.c
@@ -25,6 +25,8 @@
#include <nuttx/config.h>
#include <stdio.h> +int count __attribute__ ((section (".no_init")));
+
/****************************************************************************
* Public Functions
****************************************************************************/
@@ -35,6 +37,14 @@
int main(int argc, FAR char *argv[])
{
- printf("Hello, World!!\n");
+ /* Hack to initialize variable correctly first time */
+
+ if (count < 0 || count > 100)
+ {
+ count = 0;
+ }
+
+ printf("This program was executed %d times\n", ++count);
return 0;
}
And this was the result:
NuttShell (NSH) NuttX-12.4.0-RC0
nsh> hello
This program was executed 1 times
nsh>
NuttShell (NSH) NuttX-12.4.0-RC0
nsh> hello
This program was executed 2 times
nsh>
Helpful resource: https://community.st.com/t5/stm32-mcus-products/how-to-retain-global-variable-after-nvic-reset-in-stm32f302r8/td-p/161899