chSysHalt (reason=0x8001918 "SV#8")

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

Moderator: RoccoMarco

User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: chSysHalt (reason=0x8001918 "SV#8")

Post by Giovanni »

OK, let me know. SV#8 would be something related to IRQs anyway.

Giovanni
0x3333
Posts: 57
Joined: Thu Mar 07, 2019 10:19 pm
Has thanked: 7 times
Been thanked: 6 times

Re: chSysHalt (reason=0x8001918 "SV#8")

Post by 0x3333 »

Also, I have CH_DBG_STATISTICS enabled, could this be a potential issue? As long as I can tell, nope, but...
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: chSysHalt (reason=0x8001918 "SV#8")

Post by Giovanni »

It should not be a problem, easy to disable it and check anyway.

Do a stack trace after the system is halted, that should give us hints.

Giovanni
0x3333
Posts: 57
Joined: Thu Mar 07, 2019 10:19 pm
Has thanked: 7 times
Been thanked: 6 times

Re: chSysHalt (reason=0x8001918 "SV#8")

Post by 0x3333 »

I have this stacktrace from the first test:

Code: Select all

bt
#0  chSysHalt (reason=0x8001918 "SV#8") at ./lib/chibios/os/rt/src/chsys.c:213
#1  _dbg_check_enter_isr () at ./lib/chibios/os/rt/src/chdebug.c:204
#2  0x080013f0 in VectorB0 () at ./lib/chibios/os/hal/ports/STM32/LLD/TIMv1/hal_st_lld.c:255
#3  <signal handler called>
#4  0x55555554 in ?? ()


Looks like a problem on TIM, but I'll check... Don't know if helps.

I'll have access to the boards only tonight, I'm GMT-3, so will take time. But I'll let you know.
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: chSysHalt (reason=0x8001918 "SV#8")

Post by Giovanni »

As supposed it looks IRQ-related, check priorities, for some reasons there is something not right. Are you mixing files from different ChibiOS versions?

Giovanni
0x3333
Posts: 57
Joined: Thu Mar 07, 2019 10:19 pm
Has thanked: 7 times
Been thanked: 6 times

Re: chSysHalt (reason=0x8001918 "SV#8")

Post by 0x3333 »

No, but i'm using trunk(Actualy, I'm using Alexandre's github sync, https://github.com/alex31/chibios_svn_mirror/).

Everything is stock. I'll try to revert to a specific version and see what happens.

Will try also the demo(For Maple board) to see if this happens too.

Also, will break after chibios init and inspect IRQ registers, really weird thing.
0x3333
Posts: 57
Joined: Thu Mar 07, 2019 10:19 pm
Has thanked: 7 times
Been thanked: 6 times

Re: chSysHalt (reason=0x8001918 "SV#8")

Post by 0x3333 »

I found why it is crashing :)

My app's main:

Code: Select all

int main(void)
{
    // System initialization
    halInit();
    chSysInit();

    // App initialization
    mainInit();

    while (true)
    {
        palToggleLine(LINE_ONBOARD_LED);

        chThdSleepMilliseconds(100);
    }
}


In GDB I added 2 breakpoints, _dbg_check_lock and _dbg_check_unlock(I changed functions to NOINLINE, just in case):

Code: Select all

(gdb) start
Temporary breakpoint 12 at 0x8000840: file ./lib/chibios/os/hal/ports/STM32/STM32F1xx/hal_lld.c, line 135.
Starting program: /Users/terciofilho/Code/f1template/out/TEMPLATE.elf

Breakpoint 5, main () at ./src/main.c:30
30       halInit();
(gdb) c
Continuing.

Breakpoint 1, _dbg_check_lock () at ./lib/chibios/os/rt/src/chdebug.c:150
150     if ((ch.dbg.isr_cnt != (cnt_t)0) || (ch.dbg.lock_cnt != (cnt_t)0)) {
(gdb) c
Continuing.

Breakpoint 2, _dbg_check_unlock () at ./lib/chibios/os/rt/src/chdebug.c:163
163     if ((ch.dbg.isr_cnt != (cnt_t)0) || (ch.dbg.lock_cnt <= (cnt_t)0)) {
(gdb) c
Continuing.

Breakpoint 1, _dbg_check_lock () at ./lib/chibios/os/rt/src/chdebug.c:150
150     if ((ch.dbg.isr_cnt != (cnt_t)0) || (ch.dbg.lock_cnt != (cnt_t)0)) {
(gdb) c
Continuing.

Breakpoint 2, _dbg_check_unlock () at ./lib/chibios/os/rt/src/chdebug.c:163
163     if ((ch.dbg.isr_cnt != (cnt_t)0) || (ch.dbg.lock_cnt <= (cnt_t)0)) {
(gdb) c
Continuing.

Breakpoint 1, _dbg_check_lock () at ./lib/chibios/os/rt/src/chdebug.c:150
150     if ((ch.dbg.isr_cnt != (cnt_t)0) || (ch.dbg.lock_cnt != (cnt_t)0)) {
(gdb) c
Continuing.

Breakpoint 2, _dbg_check_unlock () at ./lib/chibios/os/rt/src/chdebug.c:163
163     if ((ch.dbg.isr_cnt != (cnt_t)0) || (ch.dbg.lock_cnt <= (cnt_t)0)) {
(gdb) c
Continuing.

Breakpoint 1, _dbg_check_lock () at ./lib/chibios/os/rt/src/chdebug.c:150
150     if ((ch.dbg.isr_cnt != (cnt_t)0) || (ch.dbg.lock_cnt != (cnt_t)0)) {
(gdb) c
Continuing.

Breakpoint 2, _dbg_check_unlock () at ./lib/chibios/os/rt/src/chdebug.c:163
163     if ((ch.dbg.isr_cnt != (cnt_t)0) || (ch.dbg.lock_cnt <= (cnt_t)0)) {
(gdb) c
Continuing.

Breakpoint 1, _dbg_check_lock () at ./lib/chibios/os/rt/src/chdebug.c:150
150     if ((ch.dbg.isr_cnt != (cnt_t)0) || (ch.dbg.lock_cnt != (cnt_t)0)) {
(gdb) bt
#0  _dbg_check_lock () at ./lib/chibios/os/rt/src/chdebug.c:150
#1  0x08000dc6 in chSysLock () at ./lib/chibios/os/rt/src/chthreads.c:651
#2  chThdSleep (time=120) at ./lib/chibios/os/rt/src/chthreads.c:653
#3  main () at ./src/main.c:40
(gdb) c
Continuing.
^C
Program received signal SIGINT, Interrupt.
chSysHalt (reason=0x8001918 "SV#8") at ./lib/chibios/os/rt/src/chsys.c:213
213     }
(gdb)


As we can see, several lock/unlock sequences, in the last call to _dbg_check_lock, is in fact from chThdSleepMilliseconds, thus, locking the system, when the SysTick IRQ is handled, the system is locked, so the SV#8.

If I create an empty thread, another crash happens, SV#4.

Code: Select all

static THD_WORKING_AREA(waThread1, 128);
static __attribute__((noreturn)) THD_FUNCTION(Thread1, arg)
{

    (void)arg;
    chRegSetThreadName("blinker");
    while (true)
    {
        palToggleLine(LINE_ONBOARD_LED);
        chThdSleepMilliseconds(100);
    }
}

int main(void)
{
    // System initialization
    halInit();
    chSysInit();

    // App initialization
    mainInit();

    chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);

    while (true)
    {
        chThdSleepMilliseconds(100);
    }
}


Code: Select all

chSysHalt (reason=0x8001ab4 "SV#4") at ./lib/chibios/os/rt/src/chsys.c:213

(gdb) bt
#0  chSysHalt (reason=0x8001ab4 "SV#4") at ./lib/chibios/os/rt/src/chsys.c:213
#1  _dbg_check_lock () at ./lib/chibios/os/rt/src/chdebug.c:151
#2  0x08000994 in chSysLock () at ./lib/chibios/os/rt/src/chthreads.c:651
#3  chThdSleep (time=200) at ./lib/chibios/os/rt/src/chthreads.c:653
#4  Thread1 (arg=<optimized out>) at ./src/main.c:35
#5  0x0800025e in _port_thread_start () at ./lib/chibios/os/common/ports/ARMCMx/compilers/GCC/chcoreasm_v7m.S:119
0x3333
Posts: 57
Joined: Thu Mar 07, 2019 10:19 pm
Has thanked: 7 times
Been thanked: 6 times

Re: chSysHalt (reason=0x8001918 "SV#8")

Post by 0x3333 »

Found the issue.

Happen to be that I included my appconf.h(Which has all the defines for debug/release) in chconf.h. The CH_DBG_SYSTEM_STATE_CHECK wasn't defined inside chconf.h, but outside in appconf.h

Fixed by moving all my defines from appconf.h to UDEFS in Makefile. Isn't my best option, but fixed the problem.

Thanks for your time.
Post Reply