Debug access without reset?

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderator: RoccoMarco

User avatar
Korken
Posts: 270
Joined: Wed Apr 02, 2014 4:09 pm
Has thanked: 5 times
Been thanked: 6 times

Debug access without reset?

Post 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!
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Debug access without reset?

Post by Giovanni »

This is very strange, are you running/debugging with debug options enabled?

Giovanni
User avatar
Korken
Posts: 270
Joined: Wed Apr 02, 2014 4:09 pm
Has thanked: 5 times
Been thanked: 6 times

Re: Debug access without reset?

Post by Korken »

Yes I am, all debug options enabled compiled with -Og to get acceptable optimizations while still being able to debug.

//Emil
User avatar
Korken
Posts: 270
Joined: Wed Apr 02, 2014 4:09 pm
Has thanked: 5 times
Been thanked: 6 times

Re: Debug access without reset?

Post 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
User avatar
Korken
Posts: 270
Joined: Wed Apr 02, 2014 4:09 pm
Has thanked: 5 times
Been thanked: 6 times

Re: Debug access without reset?

Post 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?
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Debug access without reset?

Post 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
User avatar
Korken
Posts: 270
Joined: Wed Apr 02, 2014 4:09 pm
Has thanked: 5 times
Been thanked: 6 times

Re: Debug access without reset?

Post 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!
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Debug access without reset?

Post 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
User avatar
Korken
Posts: 270
Joined: Wed Apr 02, 2014 4:09 pm
Has thanked: 5 times
Been thanked: 6 times

Re: Debug access without reset?

Post 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.
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Debug access without reset?

Post by Giovanni »

chconf.h or the compiler command line.

Giovanni
Post Reply