stm32duino/STM32FreeRTOS

Any way to use serialEvent or something similar?

mcastillof opened this issue · 1 comments

Hello, I was trying to use SerialEvent() but seems like it is not going to work with FreeRTOS. I may be doing something wrong.

I need to receive long burst of data over a serial port. Until now I was suspending other tasks as soon as I know that the data was about to be (or being) transmitted. Then I recall that Arduino has this SerialEvent() mechnism, and I thought that this could be handy. Is there any way to make SerialEvent() work or is there something similar that I can use with FreeRTOS?

A minimal working example (well, it's not working 😄 ) was added below. It has this two lines in setup():

    vTaskStartScheduler();
    while(1);

if both are commented, then SerialEvent() works, but the scheduler is not running. If those are left uncommented, then the scheduler working but serialEvent() is not.

I'm using this flags (put this in a file called build_opt.h in the same folder of the .ino code):
-DENABLE_HWSERIAL5 -DPIN_SERIAL5_RX=PD2 -DPIN_SERIAL5_TX=PC12

This is the code:


#include <STM32FreeRTOS.h>

String inputString = "";
bool stringComplete = false;

void Task1( void *pvParameters );

HardwareSerial Serial5(PD2, PC12);


void setup() 
{
    Serial5.begin(115200);
    inputString.reserve(200);

    xTaskCreate(Task1, (const portCHAR *)"task1", 128, NULL, 2, NULL);
  
    vTaskStartScheduler();
    while(1);
}


void loop() {
    if (stringComplete) 
    {
        Serial5.print("\nrecv: ");
        Serial5.println(inputString);

        inputString = "";
        stringComplete = false;
    }
}


void serialEvent5() 
{
    while (Serial5.available()) 
    {
        char inChar = (char)Serial5.read();
        inputString += inChar;
  
        if (inChar == '\n' || inChar == '\r') 
        {
            stringComplete = true;
        }
    }
}


void serialEventRun(void)
{
    #if defined(HAVE_HWSERIAL5)
        if (serialEvent5 && Serial5.available()) 
        {
            serialEvent5();
        }
    #endif
}


void Task1(void *pvParameters)
{
    for (;;) 
    {
        Serial5.println("task1");
        vTaskDelay(1000); 
    }
}

Loop is never called...
See comments in examples:

For this kind of request, please use the forum. Issue is mainly for bug report l.
Thanks.