[stm32f4] uartStart on UARTD2 causes crash

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

Moderator: RoccoMarco

Post Reply
mingthemad
Posts: 12
Joined: Wed Sep 26, 2012 4:33 am

[stm32f4] uartStart on UARTD2 causes crash

Post 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
  };
mingthemad
Posts: 12
Joined: Wed Sep 26, 2012 4:33 am

Re: [stm32f4] uartStart on UARTD2 causes crash

Post by mingthemad »

Forgot to mention: I'm using version Chibios 2.6.6 with gcc 4.7.3
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: [stm32f4] uartStart on UARTD2 causes crash

Post by Giovanni »

Hi,

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

Giovanni
mingthemad
Posts: 12
Joined: Wed Sep 26, 2012 4:33 am

Re: [stm32f4] uartStart on UARTD2 causes crash

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

Re: [stm32f4] uartStart on UARTD2 causes crash

Post by Giovanni »

Hi,

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

Giovanni
mingthemad
Posts: 12
Joined: Wed Sep 26, 2012 4:33 am

Re: [stm32f4] uartStart on UARTD2 causes crash

Post 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
User avatar
Chudik
Posts: 152
Joined: Fri Jan 16, 2015 7:51 am
Has thanked: 7 times
Been thanked: 1 time

Re: [stm32f4] uartStart on UARTD2 causes crash

Post 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
Post Reply