STM32F030 and SPWF01 WiFi Module

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

Moderator: RoccoMarco

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

STM32F030 and SPWF01 WiFi Module

Post by Tabulous »

Hi
i am currently working with the above aparts, and am experiencing serial data loss/corruption.

The interface to the WiFi module is a simple UART 115200 with hardware flow control. Module is controlled via AT commands.


All the AT command control works fine, as the data returned from the module is not large. 10-20 byte responses.


Now when i get the module to do a HTTP POST to webserver, the response to this is quite long, basically its the HTTP 200 OK crap you get back from a server, so it can be a good few 100 bytes.

The issue is the MCU is not getting everything correctly, i've checked if everything is coming out of the WiFi module TX pin Ok and it is.


Flow control is all enable as i can see the CTS line holding the WiFi off periodically. I've also increased the 'SERIAL_BUFFERS_SIZE' upto 128bytes in the halconf.h
I've tried changing the Threads priority, this made no difference.

This is my Thread code

Code: Select all

static THD_FUNCTION(ThreadAthl, arg)
{
msg_t c;
eventflags_t flags;
ATHND_ST *pd = &at;
event_listener_t elModemdata;


    (void)arg;
    chRegSetThreadName("athl");
    sdStart(&SD2, &serialconfig);

    /* Register thread watchdog */
//    watchdogRegister( APPWTDG_ATC );

    chEvtRegister(chnGetEventSource(&SD2),
                  &elModemdata, EVENT_MASK(1));

    while( TRUE )
    {
//        watchdogNotify( APPWTDG_ATC );

        flags = chEvtGetAndClearFlags(&elModemdata);

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

              if ( c != Q_TIMEOUT )
              {

                  switch( pd->service )
                  {
                      case DAT_MODE:
                          data_mode_handler( c );
                          break;

                      case CMD_MODE:
                          command_mode_handler( c );
                          break;
                  }

                  MBS_DEBUG( DBG_MASK_ATC, "%c", c );
              }
           }
           while ( c != Q_TIMEOUT );
        }

        chEvtWaitOneTimeout(EVENT_MASK(1), MS2ST(10));
    }

//    return( 0 );
}


This line just outputs what is received, and this does not match what is coming out of the WiFi Module TX pin
MBS_DEBUG( DBG_MASK_ATC, "%c", c );

What else can i look at ?
Last edited by Tabulous on Mon Dec 14, 2015 9:35 am, edited 1 time in total.
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: STM32F030 and SPWF01 WiFi Module

Post by Giovanni »

Hi,

Are you getting overflow event flags?

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

Re: STM32F030 and SPWF01 WiFi Module

Post by Tabulous »

Giovanni wrote:Hi,

Are you getting overflow event flags?

Giovanni


Should the flow control not stop this happening ?

Just added a check for overrun and yes it looks like this is hapening
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: STM32F030 and SPWF01 WiFi Module

Post by Giovanni »

There are two kind of overflows: data overflow (queue full) and ISR overflow.

Probably the ISR is not serviced fast enough. Move the USART IRQ priority to 3 and see if this helps. The default priority is very low and all other IRQs can preempt it.

Please also place breakpoints and see what kind of overflow you are getting.

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

Re: STM32F030 and SPWF01 WiFi Module

Post by Tabulous »

Giovanni wrote:There are two kind of overflows: data overflow (queue full) and ISR overflow.

Probably the ISR is not serviced fast enough. Move the USART IRQ priority to 3 and see if this helps. The default priority is very low and all other IRQs can preempt it.

Please also place breakpoints and see what kind of overflow you are getting.

Giovanni


By default its 3 anyways, as per define in mcuconf.h

#define STM32_SERIAL_USART2_PRIORITY 3

I put break on this this code and it never hits it

Code: Select all

static void set_error(SerialDriver *sdp, uint32_t isr) {
  eventflags_t sts = 0;

  if (isr & USART_ISR_ORE)
    sts |= SD_OVERRUN_ERROR;
  if (isr & USART_ISR_PE)
    sts |= SD_PARITY_ERROR;
  if (isr & USART_ISR_FE)
    sts |= SD_FRAMING_ERROR;
  if (isr & USART_ISR_NE)
    sts |= SD_NOISE_ERROR;
  osalSysLockFromISR();
  chnAddFlagsI(sdp, sts);
  osalSysUnlockFromISR();
}


but checking this in the thread

Code: Select all

        if(flags & SD_OVERRUN_ERROR)
        {
            MBS_DEBUG( DBG_MASK_ATC, "Overrun !\r\n" );
        }


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

Re: STM32F030 and SPWF01 WiFi Module

Post by Giovanni »

Hi,

There is another overflow case in the ISR, where the char is queued, set the breakpoint there too. If you hit that then the thread does not empty the queue fast enough and the received character cannot be queued. It means that the queue is full.

About the priority, sorry, 3 was for M3/M4/M7, on the M0 set it to 1 (highest).

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

Re: STM32F030 and SPWF01 WiFi Module

Post by Tabulous »

Giovanni wrote:Hi,

There is another overflow case in the ISR, where the char is queued, set the breakpoint there too. If you hit that then the thread does not empty the queue fast enough and the received character cannot be queued. It means that the queue is full.

About the priority, sorry, 3 was for M3/M4/M7, on the M0 set it to 1 (highest).

Giovanni


its hitting the chnAddFlagsI(sdp, SD_OVERRUN_ERROR); in this

Code: Select all

void sdIncomingDataI(SerialDriver *sdp, uint8_t b) {

  osalDbgCheckClassI();
  osalDbgCheck(sdp != NULL);

  if (iqIsEmptyI(&sdp->iqueue))
    chnAddFlagsI(sdp, CHN_INPUT_AVAILABLE);
  if (iqPutI(&sdp->iqueue, b) < Q_OK)
    chnAddFlagsI(sdp, SD_OVERRUN_ERROR);
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: STM32F030 and SPWF01 WiFi Module

Post by Giovanni »

Hi,

It means that the ISR is unable to put data in queue because the queue is full. This is cause by the queue not being emptied fast enough, check the thread that does that.

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

Re: STM32F030 and SPWF01 WiFi Module

Post by Tabulous »

Giovanni wrote:Hi,

It means that the ISR is unable to put data in queue because the queue is full. This is cause by the queue not being emptied fast enough, check the thread that does that.

Giovanni


my recieving thread is here

Code: Select all

static THD_FUNCTION(ThreadAthl, arg)
{
msg_t c;
eventflags_t flags;
ATHND_ST *pd = &at;
event_listener_t elModemdata;


    (void)arg;
    chRegSetThreadName("athl");
    sdStart(&SD2, &serialconfig);

    /* Register thread watchdog */
//    watchdogRegister( APPWTDG_ATC );

    chEvtRegister(chnGetEventSource(&SD2),
                  &elModemdata, EVENT_MASK(1));

    while( TRUE )
    {
//        watchdogNotify( APPWTDG_ATC );

        flags = chEvtGetAndClearFlags(&elModemdata);

        if(flags & SD_OVERRUN_ERROR)
        {
            MBS_DEBUG( DBG_MASK_ATC, "Overrun !\r\n" );
        }

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

              if ( c != Q_TIMEOUT )
              {

                  switch( pd->service )
                  {
                      case DAT_MODE:
                          data_mode_handler( c );
                          break;

                      case CMD_MODE:
                          command_mode_handler( c );
                          break;
                  }

//                  MBS_DEBUG( DBG_MASK_ATC, "%c", c );
              }
           }
           while ( c != Q_TIMEOUT );
        }

        chEvtWaitOneTimeout(EVENT_MASK(1), MS2ST(10));
    }

//    return( 0 );
}


i do have a this to wait for 10ms this might not help.......chEvtWaitOneTimeout(EVENT_MASK(1), MS2ST(10));
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: STM32F030 and SPWF01 WiFi Module

Post by Giovanni »

The timeout does not matter, it is the execution time of those handlers that you should verify. If you don't get data fast enough the queue will fill.

Giovanni
Post Reply