uart driver & _unhandled_exception

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, utzig, tfAteba, barthess

sntnjrg
Posts: 65
Joined: Mon Jul 22, 2019 2:19 pm
Has thanked: 18 times
Been thanked: 3 times

uart driver & _unhandled_exception

Postby sntnjrg » Fri Aug 30, 2019 3:22 pm

Hi,

I am developing a example where I use the UART driver to read data of a compass. When the program is executed, it obtained a _unhandled_exception. From this post http://www.chibios.com/forum/viewtopic.php?f=3&t=1305&start=20#p28854, I copy the file exceptionvectors.c in my project.

My rxend callback is;

Code: Select all

static void rxend_cb_(UARTDriver *uartp) {
  (void)uartp;

  chSysLockFromISR();
  memcpy(raw_msg, rx_block_buffer, READING_BLOCK_SIZE_L4R5ZI);
  read_block_uart_driver_(raw_msg);
  uartStartReceiveI(&UART_DRIVE_L4R5ZI, READING_BLOCK_SIZE_L4R5ZI,
                    rx_block_buffer);
  chSysUnlockFromISR();
  BLINKER_TOGGLE
  ;
}

The read_block_uart_driver_() function reads (read from buffer, no from driver) until a complete message is available and, in this case, signals another thread to process the message. Internally, the buffer passed by parameter is copied to another buffer and this buffer is processed. The code used to signal the thread is:

Code: Select all

    push_buffer_policyI(&uart_bp, bp); //adds the new element to FIFO object
    chEvtSignalI(uart_th_consumer, UART_CONSUMER_EVENT_L4R5ZI);

After executing the program, the stack contains the following:

Code: Select all

Thread [1] (Suspended: Signal 'SIGINT' received. Description: Interrupt.)   
   4 HardFault_Handler() undefined_exception_handler.c:48 0x08001bfa   
   3 <signal handler called>()  0xfffffff1   
   2 _idle_thread() chsys.c:72 0x08000e40   
   1 _port_thread_start() chcoreasm_v7m.S:119 0x080002c2   

Line marked (FAULT_PSP has the value: 0x20000b00 <ch_idle_thread_wa+120>):

Code: Select all

void HardFault_Handler(void) {
#ifdef DEBUG_BACKTRACE
    asm("mrs %0, psp" : "=r"(FAULT_PSP) : :);
    stack_pointer = FAULT_PSP; // <-- HERE, it has the value: 0x20000b00 <ch_idle_thread_wa+120>
    // Here will be good to assert Error LED, like
    // GPIOA->ODR |= 1;
    while(1);
#else

Disassenbly:

Code: Select all

08001bfa:   b.n 0x8001bfa <HardFault_Handler+10>

I don't know how to interpret this output. Can anyone help me?

Thank you.

User avatar
Giovanni
Site Admin
Posts: 14457
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: uart driver & _unhandled_exception

Postby Giovanni » Fri Aug 30, 2019 3:40 pm

Hi,

It is likely a stack overflow, you should verify that.

Enable stack checks and see if it is caught (CH_DBG_ENABLE_STACK_CHECK, PORT_ENABLE_GUARD_PAGES).

Giovanni

sntnjrg
Posts: 65
Joined: Mon Jul 22, 2019 2:19 pm
Has thanked: 18 times
Been thanked: 3 times

Re: uart driver & _unhandled_exception

Postby sntnjrg » Fri Aug 30, 2019 4:08 pm

Thank you Giovanni,

I have activated those options but I have not observed anything different.

The rxend_cb_ callback is blocking, isn't it? It's not invoked again until it's finished.

If I comment on the DEBUG_BACKTRACE macro, I get this stack:

Code: Select all

Thread [1] (Suspended: Signal 'SIGTRAP' received. Description: Trace/breakpoint trap.)   
   9 HardFault_Handler() undefined_exception_handler.c:90 0x08001d3a   
   8 <signal handler called>()  0xfffffff1   
   7 memcpy()  0x08000360   
   6 read_block_uart_driver_() uart_driver_block_program.c:89 0x080016cc   
   5 rxend_cb_() uart_driver_block_program.c:152 0x080016cc   
   4 uart_lld_serve_rx_end_irq() hal_uart_lld.c:324 0x08000f16   
   3 Vector6C() stm32_dma.c:264 0x08003c20   
   2 <signal handler called>()  0xfffffffd   
   1 <symbol is not available> 0x55555554   


The line is:

Code: Select all

memcpy(compass_msg, sp, n);


where sp is a pointer to char. Its value is 0x0 .

User avatar
Giovanni
Site Admin
Posts: 14457
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: uart driver & _unhandled_exception

Postby Giovanni » Fri Aug 30, 2019 4:13 pm

It is like an ISR, you need to start another receive operation in order to get another callback.

Giovanni

sntnjrg
Posts: 65
Joined: Mon Jul 22, 2019 2:19 pm
Has thanked: 18 times
Been thanked: 3 times

Re: uart driver & _unhandled_exception

Postby sntnjrg » Sat Aug 31, 2019 11:39 am

Hi Giovanni,

The problem was a stack overflow in a thread.

Thanks for the help.


Return to “General Support”

Who is online

Users browsing this forum: No registered users and 51 guests