-
-
Notifications
You must be signed in to change notification settings - Fork 19.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[PR] New config option USE_UART to enable an additional UART #11880
Conversation
I guess we already have a facility to use multiple serial connections, but it seems to be tailored for sending to and receiving from multiple hosts. See the And, as mentioned elsewhere, the |
The main problem with the AVR MarlinSerial class is that all methods are static. |
@thinkyhead HAL provided Serial1 ? .. Think twice ... ;) -- Not on AVR. What HAL provides is a define that redirects to the original Arduino serial class |
9d867f9
to
849dea9
Compare
Right. Maybe a better way to put it is, the HALs make allowances when possible. |
The code size explodes quite a bit if we were to make the serial class non-static. For this reason it seems prudent to keep the static class and use it when only a single port is configured for use. |
MarlinSerial to save progmem and sram
Using Arduino Serial adds a huge footprint to progmem and sram. Therefore I cloned MarlinSerial to MarlinUART and stripped it down to the core functionality. This way MarlinSerial remains static and can deal with host communication. And in case an additional serial interface is required for internal communication (like with MMU2), MarlinUART is enabled using the USE_UART option. |
@revilor : I have a better idea: templatize the MarlinSerial class based on selected port and options, so it keeps its static attribute, but allows multiple instances. This can avoid the huge code duplication ... |
@ejtagle Sounds legit. My C++ knowledge is from before templates, but I'll give it a try. Never too old to learn new stuff. Thankx. |
@revilor : I already have a prototype. Probably will require some review (even if it IS working!) due to cosmetics and style... ;) |
@ejtagle — Looking forward to polishing it up and giving it some tests! |
I am at it right now... I am sure it will be "interesting"... ;) |
@thinkyhead , @revilor PR #11982 is the implementation of the AVR and Due templatized Serial port class that allows multiple concurrent instances without the virtual function overhead ... To instantiate an extra serial port, look at the bottom of both MarlinSerial.cpp / MarlinSerial.h. In the case of AVR, you need to declare the ISR redirectors for the extra serial port, exactly as the one that is declared, but for the other port(s) |
@ejtagle — Now that the templatized serial port is merged, what are the implications for this PR? |
@thinkyhead : After PR #11982 , this PR is completely unneeded. If @revilor needs to use an extra UART, he just needs to instantiate the template a 3rd time (at the bottom of MarlinSerial.h and MarlinSerial.cpp) and that is all ;) |
In preparation for MMU2 support I added the option to activate another UART which will be required to send commands to the MMU unit.
For the start I added MarlinUART to the AVR HAL, which is just a wrapper for Arduino Serial. I'm not 100% sure this is the way to go, because there is also MarlinSerial which could possibly be adapted for that purpose. But I didn't want to mess with host communication so I did not touch MarlinSerial.
Please have a look if the way I started is the way to go. I'm open to any suggestions. Thankx.