MAX32630FTHR : cannot use Serial interrupt

Hi,

I am using a MAX32630FTHR board. I want to generate an interrupt when a character has been transmitted to the TX pin of an UART. I am using the Serial library, I can send and receive characters, but interrupts do not work and I have found several people encoutering the same issue on the web. Even the given example here : https://os.mbed.com/handbook/Serial does not work :

#include "mbed.h"

DigitalOut led1(LED1);
DigitalOut led2(LED2);

Serial pc(USBTX, USBRX);

void callback() {
    // Note: you need to actually read from the serial to clear the RX interrupt
    printf("%c\n", pc.getc());
    led2 = !led2;
}

int main() {
    pc.attach(&callback);

    while (1) {
        led1 = !led1;
        wait(0.5);
    }
}

It is supposed to blink the LED, but when I send a character to the board it gets stuck (the LED stops blinking) and nothing more happens.
Is there a solution ?

Hi,

I just took a look at the attach function:
@param type Which serial interrupt to attach the member function to (Serial::RxIrq for receive, TxIrq for transmit buffer empty)
void attach(Callback<void()> func, IrqType type = RxIrq);

So as you do not specify the type in your program it is using RxIrq, do you want to be using TxIrq for your purposes ?

Regards
Anna

On the above example it was supposed to work on the RxIrq interrupt, but I have read in another thread that Serial is deprecated and it is better to use UARTSerial.

So I am using the following constructor in the UARTSerial.cpp file :

UARTSerial::UARTSerial(PinName tx, PinName rx, int baud) :
    SerialBase(tx, rx, baud),
    _blocking(false),
    _tx_irq_enabled(true),
    _rx_irq_enabled(true),
    _dcd_irq(NULL)
{
    /* Attatch IRQ routines to the serial device. */
    SerialBase::attach(callback(this, &UARTSerial::rx_irq), RxIrq);
    SerialBase::attach(callback(this, &UARTSerial::tx_irq), TxIrq);
}

The Rx interrupt is working, that is, I can see UARTSerial::rx_irq being called when I receive a character. But the UARTSerial::tx_irq is not being called when I send a character.

So far I have found that the SerialBase::_irq_handler function (SerialBase.cpp file) is actually called, but the irq_type is RxIrq, and it should be equal to TxIrq. I suppose it is due to the following lines in the uart_handler found in the serial_api.c file :

void uart_handler(serial_t *obj)
{
    // clear interrupts
    volatile uint32_t flags = obj->uart->intfl;
    obj->uart->intfl = flags;

    if (obj && obj->id) {
		irq_handler(obj->id, RxIrq);
    }
}

As you can see, the uart irq handler calls the SerialBase::_irq_handler indicating irq_type = RxIrq , which is not what I want. I want to discriminate between RxIrq and TxIrq but I do not know how to do it. If I write the following :

    if (obj && obj->id) {
		irq_handler(obj->id, TxIrq);
    }

the SerialBase::_irq_handler is never called.

What do I have to change to make it work ? Has anyone been able to get TxIrq working ?

The program is based on the MAXREFDES101# source code and it can be found here :

I have just tested the UnbufferedSerial API example and it works with this board.

Note that the USBtx and USBrx pins,as defined in the example, will be routed via the max32625pico interface which I used to flash the firmware to this board. If you’re wanting to use the usb on this board you have to set up a virtual serial port etc.

These tiny Maxim boards are brilliant!!, BUT disappointingly…

Maxim serial UART interface does have (or has) big problems .
I did report this to Maxim directly but no one was interested there.
They dumped it on MBED and pretty much walked away.
If you try and contact them, and I have a few times, they treat you like you are piece of dried up dog pooh.
So its at the back of my spares rack for now :frowning:

I have not tried recently but the maximum UART board rate I could achieve was around 115200 way below the RM specs.
Hopefully this may change.

I may have another go with OS6