Page 1 of 3

Debug access without reset?

Posted: Sat Jun 28, 2014 1:50 pm
by Korken
Hi,

I have been hunting a bug that is extremely strange on my STM32F405 using ChibiStudio and a ST-Link V2.
The program works fine as long as the debugger is connected, but if I start the system without the debugger connected it hangs very quickly (within 0-5 seconds).
So I want to let the system hang and then insert the debugger to see if it is in the SysHalt (and see the reason) or where it has stopped.

Is this possible? Because in ChibiStuidio I must flash to access with the debugger (?).
Or is the some other good procedure to debug this kind of problem? I have never had this type of problem before, so I am not sure how to address it.

Thanks in advance!

Re: Debug access without reset?

Posted: Sat Jun 28, 2014 1:53 pm
by Giovanni
This is very strange, are you running/debugging with debug options enabled?

Giovanni

Re: Debug access without reset?

Posted: Sat Jun 28, 2014 2:01 pm
by Korken
Yes I am, all debug options enabled compiled with -Og to get acceptable optimizations while still being able to debug.

//Emil

Re: Debug access without reset?

Posted: Sat Jun 28, 2014 2:22 pm
by Korken
Okey, after some hacking I found how to access it without a reset ( :D ) and it hangs here (in the assert):

Code: Select all

/**
 * @brief   Leaves the kernel lock mode.
 *
 * @special
 */
static inline void chSysUnlock(void) {

  _dbg_check_unlock();
  _stats_stop_measure_crit_thd();

  /* The following condition can be triggered by the use of i-class functions
     in a critical section not followed by a chSchResceduleS(), this means
     that the current thread has a lower priority than the next thread in
     the ready list.*/
  chDbgAssert(ch.rlist.r_current->p_prio >= ch.rlist.r_queue.p_next->p_prio,
              "priority violation, missing reschedule");

  port_unlock();
}

So apparently I am not using chSchResceduleS() somewhere.

Here is the call that makes this assert go wrong:

Code: Select all

osalSysLock();

if (chEvtIsListeningI(&estimation_events_es))
    chEvtBroadcastFlagsI(&estimation_events_es, ESTIMATION_NEW_ESTIMATION_EVENTMASK);

osalSysUnlock();


Does this need a call to chSchResceduleS()?

Best Regards
Emil

Re: Debug access without reset?

Posted: Sat Jun 28, 2014 2:41 pm
by Korken
Of course the answer was yes (which was also in the documentation).
Just one question though, I have a

Code: Select all

if (chEvtIsListeningI(&......))
    chEvtBroadcastFlagsI(&....., ......);

inside a ISR (with osalSysLockFromISR() ). But chSchResceduleS() is only allowed inside thread context.
And I am anuable to find the ISR version of that function.

What is the correct procedure then?

Re: Debug access without reset?

Posted: Sat Jun 28, 2014 3:39 pm
by Giovanni
You cannot context switch directly in a ISR or callback, so only i-class functions there. The reschedule is performed automatically on ISR/callback exit so there is no equivalent for chSchResceduleS().

When an assertion fails you should retrieve the message pointed by dbg_panic_msg, it specifies the nature of the error (see the error codes table in the debug section of the kernel documentation).

Giovanni

Re: Debug access without reset?

Posted: Sat Jun 28, 2014 3:57 pm
by Korken
Ah thank you for the explanation!
I was digging in the ISR exit codes and found exactly what you are telling me.

Yeah, the dbg_panic_msg I got was "chSysUnlock" but the Link Register was pointing to the call in my previous post, that's how I found it.
The string "priority violation, missing reschedule" did not show, since chDbgAssert is defined as

Code: Select all

#if !defined(chDbgAssert)
#define chDbgAssert(c, r) do {                                              \
  if (NIL_CFG_ENABLE_ASSERTS && !(c))                                       \
    chSysHalt(__func__);                                                    \
} while (0)
#endif /* !defined(chDbgAssert) */
so to get the extra information I will have to define my own assert (this I have done now to get more exact errors).

But after this I feel like I have a much better feel for ChibiOS and how to catch bugs. :D

Thanks for the help Giovanni!

Re: Debug access without reset?

Posted: Sat Jun 28, 2014 4:02 pm
by Giovanni
The string is not used by default because footprint, it is there for extended assertions implementations, that is basically what you did.

Giovanni

Re: Debug access without reset?

Posted: Sat Jun 28, 2014 4:18 pm
by Korken
Ah yes, I remember when we discussed this the last time.

However, I must ask, what is the standard procedure to define a new chDbgAssert?
I would assume to put it in chconf.h, but the chdebug.h file does not include any file so I am a bit unsure of how to best override the standard assert.

Re: Debug access without reset?

Posted: Sat Jun 28, 2014 4:28 pm
by Giovanni
chconf.h or the compiler command line.

Giovanni