PlatformIO Community

RawSerial Mbed callback function never called

Hi everyone,
I’m working on a project on the Gapuino development board, my goal is to implement rosserial_mbed module on the Gap8 to be able to communicate with a ROS (melodic) node running on Ubuntu 18.04.

Rosserial relies on BufferedSerial library, which is an implementation of Mbed RawSerial, by exploiting its ability to attach callback functions on the UART rx pin to store data inside a buffer. This is done in order to have non-blocking read/write functionalities.

I narrowed the problem down to an interrupt handling issue on the Gap8, which seems unable to call callbacks on the triggering of the UART rx pin. To demonstrate what I just explained, I wrote down a simple example program to show such issue:

#include "mbed.h"

RawSerial pc(USBTX, USBRX, 9600);

void FooCallback(void)
{
    printf("This function never gets called\n");
}

int main(void)
{
    // Attach callback on UART rx
    pc.attach(&FooCallback, RawSerial::RxIrq);

    while(1)
    {
        // Do stuff
        printf("...\n");
    }
}

I want to also add a finding (which could be unrelated to the issue) that emerged when reading at the source code for the porting of the mbed library for the Gap8. I came across this line of code inside serial_api.c which states that uart_irq_rx “/* Do no support in GAP8 */”.

My current setup is the following:

  • OS: Ubuntu 18.04
  • IDE: Visual Studio Code running PlatformIO extension
  • Board: GAPuino GAP8
  • Platform: RISC-V GAP
  • Framework: Mbed

Thank you in advance, any suggestion is welcomed.

Interesting that that commend is there but yet beneath it there’s code for interfacing with the UART IRQs (TX and RX), and calling into registered callback handlers. Maybe it’s a left-over comment.

Now if I read the board JSON correctly then there’s a built-in debugger on the board. Have you tried doing a Run -> Start debugging in VSCode and checking whether the interrupt service routine

is hit, and then further down the chain your function?

printf() within an interrupt routine is a bad idea to possible mutex locks. You may be able to do a pure pc.puts("string\n"); though.

1 Like

Oh actually I take that back. Looking at the function which is supposed to point the microcontrollers UART IRQ function to the SDK custom ones, it does

So due to the commented out code, it actually does absolutely nothing and doesn’t configure the interrupt configuration unit (NVIC or whatever that thing has).

I see you’ve already opened https://github.com/GreenWaves-Technologies/gap_sdk/issues/164. As this seems to be a case of missing functionality in there, it’s the right place.

1 Like

Thank you very much for taking the time for investigating this issue. That’s what I feared too, and the debugger in vscode confirmed it as the breakpoint at the uart0_irq_rx function is never encountered during runtime.

I’m implementing a quick and ugly fix by bypassing the function entirely and rely on a separate thread to check and read the buffer. I’m not sure the gap_sdk dev team will fix it though, as the support for Mbed has ended and they will only support FreeRTOS and PULP-OS from now on.

Thank you again, have a nice day.