Page 1 of 1

[stm32f4] uartStart on UARTD2 causes crash

Posted: Wed Jan 21, 2015 2:40 am
by mingthemad
I've been using Chibios for several years on the STM32F4x7 devices and it's been working great.

I'm about to implement a ModBus handler over RS-485 and I want to use the UART device driver on USART2.

However, the call to initialise the driver always causes the program to crash. The config is below.

If I enable the the serial driver on SD2, it works great. I've checked there are no DMA conflicts, and expanded the stack sizes beyond any reasonable limit.

Any ideas?

Craig

Code: Select all

  UARTConfig config = {
    &Modbus_TxEnd1, // uartcb_t                  txend1_cb;  // End of transmission buffer callback.
    &Modbus_TxEnd2, // uartcb_t                  txend2_cb;  // Physical end of transmission callback.
    &Modbus_RxEnd,  // uartcb_t                  rxend_cb;   // Receive buffer filled callback.
    &Modbus_RxOOB,  // uartccb_t                 rxchar_cb;  // Character received while out if the @p UART_RECEIVE state.
    &Modbus_RxTO,   // uartecb_t                 rxerr_cb;   // Receive error callback.

    9600,
    0,
    USART_CR2_STOP1_BITS | USART_CR2_LINEN,
    0
  };

Re: [stm32f4] uartStart on UARTD2 causes crash

Posted: Wed Jan 21, 2015 8:31 am
by mingthemad
Forgot to mention: I'm using version Chibios 2.6.6 with gcc 4.7.3

Re: [stm32f4] uartStart on UARTD2 causes crash

Posted: Wed Jan 21, 2015 11:07 am
by Giovanni
Hi,

Where the crash happens? in the start code or in some callback? after starting callbacks are immediately active.

Giovanni

Re: [stm32f4] uartStart on UARTD2 causes crash

Posted: Wed Jan 21, 2015 2:22 pm
by mingthemad
Giovanni wrote:Hi,

Where the crash happens? in the start code or in some callback? after starting callbacks are immediately active.

Giovanni


The callbacks are all empty functions at this time. As near as I can tell, the crash occurs inside uartStart which does not return. Unfortunately, the debugger is not being very useful right now for some reason.

I'll be able to look at the UART code again soon, but I have to get the ModBus working and so will be working with the Serial driver for a few days as a work-around because we need to verify our new hardware.

Thanks for your work on Chibios - it's working great for us!

Craig

Re: [stm32f4] uartStart on UARTD2 causes crash

Posted: Wed Jan 21, 2015 2:40 pm
by Giovanni
Hi,

Try compiling using -O0, this should make the code easier to debug, stepping becomes more reliable.

Giovanni

Re: [stm32f4] uartStart on UARTD2 causes crash

Posted: Thu Jan 22, 2015 2:30 am
by mingthemad
I found the problem.

The UARTConfig struct was declared on the stack, and hence was not available when the interrupt routine was called.

Once I made it static, everything started working. Making it global would work too.

Sorry for bugging everyone with a stupid problem :)

Craig

Re: [stm32f4] uartStart on UARTD2 causes crash

Posted: Thu Jan 22, 2015 7:37 am
by Chudik
Hi mingthemad,
Is your modbus code proprietary or you used some open source project for it?

I will need to implement this protocol in my current project based on MSP32L1 soon, but never wrote modbus firmware before.

Igor