Running UARTS in different Threads

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

Moderator: RoccoMarco

Post Reply
kdsouza
Posts: 14
Joined: Thu Jul 02, 2015 3:26 pm
Has thanked: 1 time

Running UARTS in different Threads

Post by kdsouza »

I am Using the STM32F103RGT7 with the STM32F103-FATFS Example on Core 2.6.

Application Perepherals Configured
1. Serial1.
2. Serial2.
3. Serial3.
4. SPI2.
5. ADC0 - Only 1 pin.
6. Some GPIO's for LEDs.

UART1 : Device A
UART2 : Console
UART3 : Device B

The Peripheral code (read/write) for Serial1 & Serial3 works fine Individually (If ran one after the other from the Console).

Now in our application we need Serial1 & Serial3 running in parallel.

Now when I put the two ( Serial 1 & Serial 3) Rx in different threads, Only one works fine, the other doesn't work( Hangs ).

The freezing happens on a specific point ( Thread 3 after sending the 4th Command to the module ) where the device has to read from the Module.
When the module is used individually it works fine without any freezing or getting stuck but when its used in a thread it doesn't pass the 4th command ( commands are AT Commands working fine if ran individually).

I increased the stack sizes to 8192 for All three Threads. It works for a while and then goes in Unhandled Exception Code.

Thread Summary
Thread 1 : Blinking LED as per the FATFS Demo Code.
Thread 2 : Obtain Serial1's data via AsyncRead ( infinite loop).
Thread 3 : Confugure the Serial3 Device & Read The Output ( infinite loop).

Thread Creation

Code: Select all

//In Main
  chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
  chThdCreateStatic(waThread2, sizeof(waThread2), NORMALPRIO, Thread2, NULL);
  chThdCreateStatic(waThread3, sizeof(waThread3), NORMALPRIO, Thread3, NULL);


Code: Select all

static msg_t Thread3(void *arg) {
  (void)arg;
  chRegSetThreadName("redpine");
  chprintf(&SD2,"Starting Redpine in 5 secs\r\n");
  chThdSleepMilliseconds(5000);
  redpine_process(); //Inidialize Code
  chprintf(&SD2,"Redpine Setup Done Going to Decompose\r\n");
  decompose_redpine();
  //Never Reaches Here
  return 0;
}



Code: Select all

static msg_t Thread2(void *arg)
{

  //(void)arg;
  chRegSetThreadName("read_gps");
    gps_read(); //FUnction Outputs on Serial2 Latitude,Longitude

     //Never Reaches Here
  return 0;
}
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Running UARTS in different Threads

Post by Giovanni »

I don't see anything obviously wrong, probably the real problem is not where are you looking. I can only recommend to proceed as described here: http://chibios.org/dokuwiki/doku.php?id ... ebug_guide

Giovanni
kdsouza
Posts: 14
Joined: Thu Jul 02, 2015 3:26 pm
Has thanked: 1 time

Re: Running UARTS in different Threads

Post by kdsouza »

Allright the key was to use UART instead of Serial.

In my setup I need to have SPI2 Running so UART1 can't be used due to the DMA Buffer Sharing.

So instead of using Serial 1,2,3 I am using Serial 1 & 2 ( 2 is the Shell Serial and Work will be done only if it is actually connected to a console port which is going to happen only incase of debugging so Serial 2 is no big of a deal.)

I turned Serial 3 into UART3 which does most of the Heavy work. Now the Idle thread also gets time and the application also runs smoothly.

My Lesson was if the Idle thread is not getting any time, something is not right with my code :ugeek:

Cheers
Post Reply