-
Notifications
You must be signed in to change notification settings - Fork 73
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
Serial output does not use Arduino's Print class #20
Comments
Hi, Mattjijs: Thanks for your note. Your observation that Bitlash doesn’t use the Print class is quite correct. When I first wrote Bitlash in 2008 the Print class didn’t exist, and anyway the ATMega168 didn’t have room for Bitlash plus other large libraries. Your suggestion to use the Print class is interesting. There is enough space on the newer Arduinos for the code. Of course any integration would need to be optional since there are users out there who need every available byte. I wonder how many of the benefits would be available without rewriting all the output generating routines, including func_printf (which includes some custom functionality compared with regular printf). Do you have any thoughts on this? -br On Jan 23, 2014, at 2:29 PM, Matthijs Kooijman [email protected] wrote:
|
Thanks for clarifying. I actually expect that using the Print and Stream (which is the Print equivalent for input) classes won't take up much extra space, since you'll be already using them if you use the existing Serial classes (so the code has to be there anyway). I just had a closer look at the existing bitlash code to figure out what combinations of serial input and output are supported now. Some relevant observations:
I also found the Regarding using the official SoftwareSerial library, it seems that it does not have any support for running in a TX-only mode. This means that if we'd use it, RAM for the RX buffer will be always allocated. So we'd probably better implement a custom version of software serial (using the existing code in the bitlash library) and use that (can just be a subclass of Print for example). Regarding func_printf, I guess we should just keep that and just have it print to the output Print class. I'll see if I can come up with a proof-of-concept, to see how this might look. |
A not-so-related question: Is there any particular reason to use .c files instead of .cpp? I'm missing function overloading and references :-) |
Wait, that's actually very much related: The Print and Stream classes can of course not be used without using C++... |
Oh, it seems the main source file is bitlash.cpp, which includes all .c files, so they are really compiled as C++ and not C. I guess the naming is just misleading (and confuses my automatic syntax checker as well), so I'll rename them in a first commit. |
One more question (sorry for the flood...): What are the supported usecases for compiling outside of the Arduino environment? I see the unix stuff, which should work on a random unix machine, but also things like:
Which suggest to me that perhaps it is supported to compile for an Arduino mega |
Many questions, many answers...
-br |
Thanks for your replies!
Hmm, does using a constant baudrate reduce code size? I could imagine this only happens when the baudrate is inlined, but then why doesn't this work for inlining from the main sketch? In any case, I'll just leave this in for now, I was just being curious.
The fact that it uses a .cpp extension also means the compiler actually compiles as C++. However, that in itself should not increase code size (and even doing some OO coding doesn't per se, as long as you keep thinking about what your write, of course).
Ok, then I'll initially focus on just the Arduino and Linux builds (for lack of OSX here). |
I accidentally commented in the wrong issue, here's the discussion so far: Matthijs:
Bill:
|
For avropendous, do you have any reference about how to compile things for that target? I couldn't find any Arduino core for it at all? Wrt the TEENSY defines, they don't actually seem to be used anywhere? Perhaps the way to support Teensy was to define AVROPENDOUS as well as TEENSY or something? In any case, the Teensy should make its (usb?) serial port available as as Stream object just like regular Arduinos, so re-adding support should be trivial I think (if it defines |
Wrt to the extra binary size, I already reclaimed 290 bytes which were due to two debug prints :-) Furthermore, I made some changes to reduce the overhead slightly, but there is still some 300 bytes (IIRC) left. This is mostly due to the fact that the Stream* and Print* used are two bytes and calling functions on them needs to load pointers from the vtable, making all operations on them a few bytes bigger than before. I suppose this is not normally a problem, but for the small targets, it is. I'm not working on making the |
I've pushed more commits to https://github.com/Pinoccio/library-bitlash/commits/printstream With the new commits, the overhead (on a Uno) is reduced to 254 bytes of flash on normal build, 98 bytes when DEFAULT_CONSOLE_ONLY is defined. For builds with SERIAL_OVERRIDE and SOFTWARE_SERIAL_TX disabled (and optionally also TINY_BUILD enabled), the binary size even shrinks by 32 or 36 bytes :-) Here's the results for testing on a uno. Note that I compiled the master branch with 0ea04a8 and 0b419cc included, to fix compilation.
In the default builds the memory usage increased by 30 bytes. I'll have a look what causes that, but it doesn't look unacceptable to me. For the small builds, the memory usage actual shrinks by 1 byte :-) |
I just noticed that the memory figures in the above test were way too Furthermore, notice that the above numbers are with the Arduino core Again compiled for a Uno:
|
Also tried on 1.0.5 and (with one extra change), things also compile there. The binary sizes are abit bigger, but the difference between master and printstream are the same as for 1.5.5. |
I’ve lost track of the Avro stuff, but there were some users, so why not leave the defines there? Teensy includes an installer and downloader that makes modifications to the Arduino environment. You can find out more here: http://www.pjrc.com/teensy/index.html — anyway, that is why you don’t see any references in the code. They aren’t there until you install the Teensy stuff. -br On Jan 30, 2014, at 1:08 AM, Matthijs Kooijman [email protected] wrote:
|
The reason I deleted the stuff was mostly that the "serialRead" macro and friends were removed and I'm not sure what the relevant replacement would be. However, assuming that the AVROPENDOUS build actually uses some Arduino-like core and makes a "Serial" object available, I guess I could just remove the serialAvailable etc. macros and leave the other stuff in. As for the Teensy defines, I'm not sure I understand what you mean. I know that Paul supplies Teensyduino as a modified Arduino environment. I was planning to give it a whirl to do some compiletesting with the updated bitlash library soon (though I just found out that it only has a binary-blob installer which I don't really like). However, even this installer heavily modifies my Arduino environment, I suppose it will not touch the bitlash library code itself, right? And the source files inside the Arduino / Teensy core should never actually see bitlash.h, so any It looks like the TEENSY stuff was introduced in this commit (even though the commit message doesn't betray this): 2bc8314 It looks to me like before that commit, having AVR_AT90USB162 implied having an AVROPENDOUS board. However, since the TEENSY uses the same chip, this commit forces users to choose between AVROPENDOUS_BUILD and TEENSY, with TEENSY as the default. The empty #ifdef block (2bc83149#diff-6a3da1044bed8984108a96fd058ca54fR285) looks like it was intended to get TEENSY-specific defines later, but that never happened. With that in mind, perhaps I should indeed just leave those around. Ideally, we'd autodetect the board type used, but it seems you'll need IDE version 1.5.x for that, which adds -DARDUINO_UNO (etc.) to the commandline (depending on a value from boards.txt). So, I'll drop that "remove AVROPENDOUS" commit :-) |
I just pushed a few more commits to my printstream branch. I still have one commit pending here locally to make the UNIX_BUILD working again, but I'm out of time until monday, so I'll push that later. If you have specific comments, already let me hear them (or if you'd rather wait until I get everything squashed together into proper form, that's also ok). |
This reverts commit 6978906. See billroy#20 (comment)
My understanding is that Teensyduino modifies the #defines presented to sketches when they are compiled in the Arduino IDE for the Teensy build target. Code for the Teensy and other builds cannot be disturbed as a result of this code package, because there are existing users who rely on them. -br On Jan 31, 2014, at 9:42 AM, Matthijs Kooijman [email protected] wrote:
|
This reverts commit 6978906. See billroy#20 (comment)
This reverts commit 6978906. See billroy#20 (comment)
I have installed TeensyDuino and (after some further tweaks) confirmed that the code now still compiles for the Teensy 2.0, Teensy++ 2.0, Teensy 3.0 and Teensy 3.1. I don't have the actual hardware to verify it also runs correctly, though. The AVROPENDOUS stuff is also back in place, so expect that should work as before as well. Furthermore, I've added a commit to fix UNIX_BUILD support with the new Stream stuff. However, instead of adding the Stream and Print definitions to bitlash, it seemed more sensible to put all of the Arduino-on-Unix stuff into a separate library. This was something I was already planning to do for a while, so this seemed like a good occasion. The result is the ArduinoUnix library: https://github.com/matthijskooijman/ArduinoUnix Using it allows the bitlash-unix code to be cleaned up a bit as well, since a lot of the stub implementations are now no longer needed. I think the implementation should be completed for now, so I'll start merging commits to clean up the commit history and then submit a pullrequest for the code. |
I just created pullrequest #31 from the cleaned up code. The original history is still available here: https://github.com/Pinoccio/library-bitlash/tree/printstream-history |
And I've ordered a Teensy 2.0 and 3.1 so I can actually test if that still works (and for other testing as well, don't worry) ;-p |
This reverts commit 6978906. See billroy#20 (comment)
While looking over the code, I found that the serial output code is using an "sp" function to print strings to various locations, optionally doing software serial on arbitrary pins.
Is there any reason you're not using Arduino's Print class, possibly combined with the SoftwareSerial library to do this stuff? Sounds like you'd get cleaner code and also get printing numbers, String objects, Printable objects, etc. for free? Also, you could then just pass in a Print& on startup, instead of selecting a serial port through defines etc.
Mind you, I haven't looked long enough to know wether this is actually feasible, but before I look closer and invest more time, I thought I'd ask around first.
Perhaps one reason for not doing this is compatibility with older Arduino versions, but perhaps those are not longer so relevant nowadays?
The text was updated successfully, but these errors were encountered: