Fighting against Buffer Overruns

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

Moderators: RoccoMarco, lbednarz, tfAteba

Post Reply
Tabulous
Posts: 518
Joined: Fri May 03, 2013 12:02 pm
Has thanked: 7 times
Been thanked: 18 times

Fighting against Buffer Overruns

Post by Tabulous »

Curently i have a setup of this

SD1 = GSM modom
SD2 = GPS Receiver

#if !defined(SERIAL_BUFFERS_SIZE) || defined(__DOXYGEN__)
#define SERIAL_BUFFERS_SIZE 512
#endif

/*
* SERIAL driver system settings.
*/
#define STM32_SERIAL_USE_USART1 TRUE
#define STM32_SERIAL_USE_USART2 TRUE//FALSE
#define STM32_SERIAL_USE_USART3 FALSE
#define STM32_SERIAL_USART1_PRIORITY 7//12
#define STM32_SERIAL_USART2_PRIORITY 7//12
#define STM32_SERIAL_USART3_PRIORITY 12

But still i hit buffer overrun with GPS.

GPS will be sending, NMEA strings 4/5 of them every second.......
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Fighting against Buffer Overruns

Post by Giovanni »

Hi,

What is the port speed?

Giovanni
Tabulous
Posts: 518
Joined: Fri May 03, 2013 12:02 pm
Has thanked: 7 times
Been thanked: 18 times

Re: Fighting against Buffer Overruns

Post by Tabulous »

GPS is @ 9600 Baud
GSM is at 115200, but the comms to it are small (AT commands) and sporadic


also here is my receiving thread for ref.

Code: Select all

static THD_FUNCTION(ThreadGPS, arg)
{
msg_t c;
eventflags_t flags;
event_listener_t elGPSdata;


    (void)arg;
    chRegSetThreadName("gpsd");

    chEvtRegisterMask(chnGetEventSource(&SD2),
                      &elGPSdata,
                      EVENT_MASK(1));


    while( TRUE )
    {
          flags = chEvtGetAndClearFlags(&elGPSdata);

          if(flags & SD_OVERRUN_ERROR)
          {
              TGL_DEBUG(DBG_MASK_GPS, "Overrun GPS !\r\n");    // keep hitting this !!!!
          }

          if(flags & CHN_INPUT_AVAILABLE)
          {
             do
             {
                c = chnGetTimeout(&SD2, TIME_IMMEDIATE);

                if ( c != Q_TIMEOUT )
                {
                    decodeNMEAstateMachine( (char)c );
                }
             }
             while (c != Q_TIMEOUT);
          }

          chEvtWaitOneTimeout(EVENT_MASK(1), MS2ST(10));
    }
}
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Fighting against Buffer Overruns

Post by Giovanni »

hi,

The overflow can be caused by two possible problems:

1) When the driver is not able to serve USART interrupts quickly enough so there is an HW overflow condition.

2) When the application is not able to empty the queue fast enough, the ISR is not able to write in the queue the received byte. This can mitigated by increasing the queue size in halconf.h.

By placing breakpoints in the driver ISR you could try to understand what kind of overflow you are getting.

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

Re: Fighting against Buffer Overruns

Post by Giovanni »

Note that there is a discussion ongoing about use of the UART driver (with DMA) in this specific scenario: viewtopic.php?f=25&t=3441

Giovanni
Tabulous
Posts: 518
Joined: Fri May 03, 2013 12:02 pm
Has thanked: 7 times
Been thanked: 18 times

Re: Fighting against Buffer Overruns

Post by Tabulous »

Giovanni wrote:Note that there is a discussion ongoing about use of the UART driver (with DMA) in this specific scenario: viewtopic.php?f=25&t=3441

Giovanni


Think this is a different propersition to me, as there baud rates are very high, i'm only at 9600 so i should not really been having issues.

I'll have alook at the Interrupts and see what i can dig up.
Post Reply