Uninitialised Serial instance

I'm looking at a MilkV-Duo, which among other things has "large" and "small" RISC-V cores running Linux and either FreeRTOS or Arduino code respectively.

The Serial instance appears to not be initialised, but Serial0...Serial4 are.

In order to avoid changing the assumed output device in an existing diagnostic file which among other things outputs the main file name and date/time etc., is it possible to "forcibly initialise" (the variable representing?) the standard serial instance from e.g. Serial0?

My apologies for any poor terminology, but like the OP of Use Serial in Arduino as variable - Stack Overflow C++ is not my native language.

Have you tried a simple

#define Serial Serial0

?

That would only have an effect in the current sourcefile, not in the file containing the diagnostic code which refers to the standard Serial instance.

I see.

How about

#ifndef Serial
  #define Serial Serial0
#endif

You could replace the #ifndef bit with another check if it's insufficiently specific/effective.

But that would still mean modifying the file containing the diagnostic code (plus of course any pre-existing examples): I'd rather avoid that if possible.

The link in my OP shows how an intermediate variable can be used for the job, and I've previously been guided to something similar when I asked about changing the port assignment at runtime. But in the current case I'm asking specifically about modifying the content of the Serial instance, exported (but not fully initialised) by the Arduino libraries.

Not if you put the define stuff in the calling code before the diagnostic code is included. Assuming that the diagnostic code is some kind of header file that's being included. I don't know, of course, because I can only work with what you've told.

Perhaps it works better if you give some more specific information about the diagnostic code and how it works, and maybe provide one or two brief/minimal examples of your specific application(s) that you're trying to get to work. Also include clear requirements including what you do(n't) want to modify so that people can offer solutions that actually fit your purpose.

The diagnostic code is in a separate file being linked in.

I am explicitly asking about modifying Serial, not about fudging it with a define or macro which quite simply won't work.

You'd have to modify the board definition/platform. I would call that more fudgy than a define-based workaround.

Perhaps someone else can come up with a solution you're happier with. Good luck with your project!

At present I've got a definition for USART in the .h which corresponds to the .cpp being linked in and am using that in lieu of Serial, so that could probably go into platform.local.txt which I'm already using to make board names etc. accessible.

As an experiment I tried

Serial = HardwareSerial(0, PIN_UART0_RX, PIN_UART0_TX);

which compiled but crashed badly, I wasn't able to see Serial in .bss so suspect that nonsensical code was being generated.

MarkMLl

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.