Buffered Serial echo not working

I am using the Buffered Serial API, and I want to read a character with the uart port. I am directly using the online example code from
[https://os.mbed.com/docs/mbed-os/v6.2/apis/serial-uart-apis.html]

*/

#include "mbed.h"

// Maximum number of element the application buffer can contain
#define MAXIMUM_BUFFER_SIZE                                                  32

// Create a DigitalOutput object to toggle an LED whenever data is received.
static DigitalOut led(LED1);

// Create a BufferedSerial object with a default baud rate.
static BufferedSerial serial_port(USBTX, USBRX);

int main(void)
{
    // Set desired properties (9600-8-N-1).
    serial_port.set_baud(9600);
    serial_port.set_format(
        /* bits */ 8,
        /* parity */ BufferedSerial::None,
        /* stop bit */ 1
    );

    // Application buffer to receive the data
    char buf[MAXIMUM_BUFFER_SIZE] = {0};

    while (1) {
        if (uint32_t num = serial_port.read(buf, sizeof(buf))) {
            // Toggle the LED.
            led = !led;

            // Echo the input back to the terminal.
            serial_port.write(buf, num);
        }
    }
}

I am not able to see any echo even though I send some data through the serial port with Putty.

I also checked serial_port.readable() and it never triggers.

I am not sure how to proceed forward. I only want to use buffered serial.

Hello,

I normally not use Putty but it looks like you need to change some settings.
Just try to run your app and before open a session change the Local echo: and Local line Editing: to Force ON in the Terminal settings.

I use Termite terminal, it is simplest.

BR, Jan

You’re not giving any value here, is that an mbed variable?

It is from Mbed’s examples and at the end of line is a number 32.

Its already On, thanks for the suggestion though. But its not working still.

I am using Max Fthr 32630

My bad :man_facepalming:

@parthsagar2010
Use UnbufferedSerial instead if you can or avoid maxim boards in general.
The MAX32630FTHR has noticable HW specs but produces a bunch of different weird things.
I am sure MAXIM has some software engineers but they are either totally uncapable or they just abandonned mbed withot communicating it.

But for sure neither Mbed core team, nor Maxim have any quality assurance. That is why the mbed website still states this board is mbed V6.3 compatible despite it is not.

Actually up until V5.9.7 the board is usable, but that mbed version is so ancient you can not even find its documentation on the mbed website, nor can you select that mbed version in the online compiler or in mbed Studio.

Your code example works on an NUCLEO-F401RE board using OS 6.3. I’m using PuTTY with 9600,8,N,1 with local echo set to “force off” (after all, we are expecting the CPU to send back the character we send to it) The LED on the board flashes on/off in a cycle for each keypress I put into PuTTY. I would suspect that mbed has a bug with supporting that MCU…

Yes, I guess MAX32630 has some compatibility issues with MBED. I cant even make the simple SD card example make it work . (SD Card File System - Cookbook | Mbed)

Somehow I was able to solve the issue by using the second example in BufferedSerial page by adding the following

FileHandle *mbed::mbed_override_console(int fd)
{
return &pc;
}

Firstly you found the SDFileSystem library written for Mbed OS 2, that might not work in Mbed OS 5 or 6 (actually SD card functionality has been merged into core somewhere around V5.10 if i remember right). So on recent versions you do not need to include any libraries.

Secondly the board has an on-board SD card slot, but in targets.json it is simply not defined. As a consequence Mbed does not know that this board could handle any SD relevant stuff.
Posted about it several times, but nobody seems to care.

Follow this tutorial to get SD working on this board (you will have to change the pin names to those of the on-board SD slot);
https://os.mbed.com/docs/mbed-os/v6.3/apis/sdblockdevice.html

Thanks Peter,

I am not able to find the mbed_app.json file in the online workspace. My goal is to make the SDBlockDevice work with latest MBed OS so that I can merge it with my existing code.

You must create one in the project folder with

{
    "target_overrides": {
        "*": {
            "target.components_add": ["SD"]
        }
    }
}

BR, Jan

Your code example works on an NUCLEO-F401RE board using OS 6.3.

its working for me.. .