Skip to content

UnbufferedSerial does not expose enable_* functions from SerialBase; behavior not predictable when exposed #14052

@petertorelli

Description

@petertorelli

Description of defect

The documentation claims UnbufferedSerial has two functions, enable_input and enable_output. However, they are not defined in the base class and SerialBase is not accessible as it is a private base class. There is also an issue where using the enable_* functions on an STM board has no problem, but running on a Cypress board corrupts the port.

Target(s) affected by this defect ?

I tested on a CY8CPROTO_062_4343W and NUCLEO_F429ZI, but I assume all since it is a header issue.

Toolchain(s) (name and version) displaying this defect ?

GCC_ARM

What version of Mbed-os are you using (tag or sha) ?

6.5.0

What version(s) of tools are you using. List all that apply (E.g. mbed-cli)

mbed: 1.10.4

How is this defect reproduced ?

#include "mbed.h"

UnbufferedSerial pc(USBTX, USBRX);

int
main()
{
	printf("Serial enabled, disabling.\n");
	pc.sync();
	pc.enable_input(false);
	pc.enable_output(false);
	pc.enable_input(true);
	pc.enable_output(true);
	printf("Serial enabled, this should be visible.\n");

}

This will fail to compile with this error

./main.cpp:13:5: error: request for member 'enable_output' is ambiguous
  pc.enable_output(true);
     ^~~~~~~~~~~~~
In file included from ./mbed-os/connectivity/netsocket/include/netsocket/nsapi_ppp.h:22,
                 from ./mbed-os/mbed.h:28,
                 from ./main.cpp:1:
./mbed-os/platform/include/platform/FileHandle.h:210:17: note: candidates are: 'virtual int mbed::FileHandle::enable_output(bool)'
     virtual int enable_output(bool enabled)
                 ^~~~~~~~~~~~~
In file included from ./mbed-os/drivers/include/drivers/UnbufferedSerial.h:26,
                 from ./mbed-os/mbed.h:71,
                 from ./main.cpp:1:
./mbed-os/drivers/include/drivers/SerialBase.h:144:10: note:                 'void mbed::SerialBase::enable_output(bool)'
     void enable_output(bool enable = true);
          ^~~~~~~~~~~~~

It can be fixed by adding these two lines to UnbufferedSerial.h:

    using SerialBase::enable_input;
    using SerialBase::enable_output;

Furthermore, this code works with the fixes on the NUCLEO, but it fails on the CYPRESS board (screen fills with garbage characters). I suspect the deinit/reinit of the serial object is the culprit in the Cypress case.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions