Hi everyone
I am trying to use xtimer method. I want to calculate how much miliseconds do my function.
Is there any xtimer counter to use?
I tried to use uint43 xtimer_now before and after the method but when I do the subtraction I get the result but then I get an error on my board
Below is my code
first_wakeup = xtimer_now();
printf("%" PRIu32 "\n", first_wakeup);
/*my method*/
last_wakeup = xtimer_now();
final_result = last_wakeup -
printf("%.2" PRIu32 "\n", last_wakeup - first_wakeup);
and this is the error
2016-04-07 14:06:16,042 - INFO # Context before hardfault:
2016-04-07 14:06:16,043 - INFO # r0: 0x00000000
2016-04-07 14:06:16,048 - INFO # r1: 0xf134b7e4
2016-04-07 14:06:16,048 - INFO # r2: 0x00000328
2016-04-07 14:06:16,054 - INFO # r3: 0x2000018c
2016-04-07 14:06:16,055 - INFO # r12: 0x00000000
2016-04-07 14:06:16,055 - INFO # lr: 0x08000fd3
2016-04-07 14:06:16,055 - INFO # pc: 0x08000fe4
2016-04-07 14:06:16,055 - INFO # psr: 0x21000021
2016-04-07 14:06:16,056 - INFO #
2016-04-07 14:06:16,056 - INFO # FSR/FAR:
2016-04-07 14:06:16,060 - INFO # CFSR: 0x00008200
2016-04-07 14:06:16,060 - INFO # HFSR: 0x40000000
2016-04-07 14:06:16,061 - INFO # DFSR: 0x00000008
2016-04-07 14:06:16,061 - INFO # AFSR: 0x00000000
2016-04-07 14:06:16,066 - INFO # BFAR: 0xf134b7e4
2016-04-07 14:06:16,066 - INFO # Misc
2016-04-07 14:06:16,066 - INFO # EXC_RET: 0xfffffff1
2016-04-07 14:06:16,078 - INFO # Attempting to reconstruct state for debugging...
2016-04-07 14:06:16,078 - INFO # In GDB:
2016-04-07 14:06:16,078 - INFO # set $pc=0x8000fe4
2016-04-07 14:06:16,079 - INFO # frame 0
2016-04-07 14:06:16,079 - INFO # bt
2016-04-07 14:06:16,079 - INFO #
2016-04-07 14:06:16,079 - INFO # ISR stack overflowed by at least 48 bytes.
When I remove this line ( printf("%.2" PRIu32 "\n", last_wakeup - first_wakeup); )
my program run without an error
All the best
Theodore
I noticed that you wrote %.2 for the format of the number. The period (".") doesn’t make sense in a format string for integer variables. Does it crash if you change the format string to only “%” or “%2” PRIu32?
I am sorry for the mistake
the right code is:
uint32_t first_wakeup,last_wakeup,final_result;
first_wakeup = xtimer_now();
printf("%" PRIu32 "\n", first_wakeup);
/*my method*/
last_wakeup = xtimer_now();
printf("%" PRIu32 "\n", last_wakeup);
final_result = last_wakeup - first_wakeup;
printf("%" PRIu32 "\n", final_result);
As I mentioned before, all the printfs shows up but I get an error
But when I remove
(final_result = last_wakeup - first_wakeup;
printf("%" PRIu32 "\n", final_result); )
it runs without error
I tried to search it and I find that there is an overflow with the substraction of uint32
I don't know how to fix it
Quoting Joakim Nohlgård <joakim.nohlgard@eistec.se>:
Hey Theodore,
on which board is this? Is your code in the main thread?
Could be a stack overflow.
Kaspar
The board is STM32F401RE nucleo
This part of code is on coap.c in microcoap_server in RIOT folder
If I remove the line with substraction it run without any problem.
I am sure that is stack overflow but I don't know how to fix it.
Can I avoid xtimer_now method? Is there other xtimer counter for this purpose?
Quoting Kaspar Schleiser <kaspar@schleiser.de>:
Hey,
If I remove the line with substraction it run without any problem.
I am sure that is stack overflow but I don't know how to fix it.
Can I avoid xtimer_now method? Is there other xtimer counter for this purpose?
xtimer_now() is very likely not the problem, printf might be.
You could try replacing printf with print_u32_dec() from the fmt module.
1. #include <fmt.h>
2. replace "printf("%u\n", variable);" with "print_u32_dec(variable);
print_str("\n");"
3. add "USEMODULE += fmt" to Makefile
Kaspar
The problem isn't in printfs. They show up but I get this error.
I just change it with print_u32_dec(variable). I continue to get the printfs but the errors remains to show up
2016-04-07 14:06:16,042 - INFO # Context before hardfault:
2016-04-07 14:06:16,043 - INFO # r0: 0x00000000
2016-04-07 14:06:16,048 - INFO # r1: 0xf134b7e4
2016-04-07 14:06:16,048 - INFO # r2: 0x00000328
2016-04-07 14:06:16,054 - INFO # r3: 0x2000018c
2016-04-07 14:06:16,055 - INFO # r12: 0x00000000
2016-04-07 14:06:16,055 - INFO # lr: 0x08000fd3
2016-04-07 14:06:16,055 - INFO # pc: 0x08000fe4
2016-04-07 14:06:16,055 - INFO # psr: 0x21000021
2016-04-07 14:06:16,056 - INFO #
2016-04-07 14:06:16,056 - INFO # FSR/FAR:
2016-04-07 14:06:16,060 - INFO # CFSR: 0x00008200
2016-04-07 14:06:16,060 - INFO # HFSR: 0x40000000
2016-04-07 14:06:16,061 - INFO # DFSR: 0x00000008
2016-04-07 14:06:16,061 - INFO # AFSR: 0x00000000
2016-04-07 14:06:16,066 - INFO # BFAR: 0xf134b7e4
2016-04-07 14:06:16,066 - INFO # Misc
2016-04-07 14:06:16,066 - INFO # EXC_RET: 0xfffffff1
2016-04-07 14:06:16,078 - INFO # Attempting to reconstruct state for
debugging...
2016-04-07 14:06:16,078 - INFO # In GDB:
2016-04-07 14:06:16,078 - INFO # set $pc=0x8000fe4
2016-04-07 14:06:16,079 - INFO # frame 0
2016-04-07 14:06:16,079 - INFO # bt
2016-04-07 14:06:16,079 - INFO #
2016-04-07 14:06:16,079 - INFO # ISR stack overflowed by at least 48 bytes.
Quoting Kaspar Schleiser <kaspar@schleiser.de>:
I fixed.
I allocated memory which I didn't free it
Thanks a lot for your help
Quoting Kaspar Schleiser <kaspar@schleiser.de>: