[riot-devel] xtimer problem

Theodore Kotsonis kotsonis at aueb.gr
Thu Apr 7 17:23:44 CEST 2016


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 at eistec.se>:

> 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?
> On Apr 7, 2016 4:29 PM, "Theodore Kotsonis" <kotsonis at aueb.gr> wrote:
>
>> 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
>>
>>
>> _______________________________________________
>> devel mailing list
>> devel at riot-os.org
>> https://lists.riot-os.org/mailman/listinfo/devel
>>





More information about the devel mailing list