Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 7 of 7

Thread: Increasing serial2.c receive buffer size

  1. #1
    Junior Member
    Join Date
    Mar 2016
    Location
    Austin TX
    Posts
    5

    Increasing serial2.c receive buffer size

    I'm using a Teensy 3.2, Arduino IDE 1.8.9 and teensyduino 1.46.

    I found some useful tips in https://forum.pjrc.com/threads/49470...al+buffer+size and other places.

    I have been changing the value in the line from serial2.c:

    #ifndef SERIAL2_RX_BUFFER_SIZE
    #define SERIAL2_RX_BUFFER_SIZE 2048 // number of incoming bytes to buffer
    I'd like to get it up to 5000 or so.

    I have been forcing a rebuild all by changing the optimiztation between "faster" and "fastest". The verbose compile message shows

    Using core 'teensy3' from platform in folder: C:\Program Files\Arduino\hardware\teensy\avr
    Build options changed, rebuilding all
    but further into the messages it says

    Compiling core...
    Using precompiled core: C:\Users\DHP-1006\AppData\Local\Temp\arduino_cache_942169\core\ core_teensy_avr_teensy31_usb_serial,speed_96,opt_o 2std,keys_en-us_71a00981eaa0bad0868b6b2ed88d327b.a
    Linking everything together...

    I found the referenced file and it is a couple of days old. That means at some point there was a real rebuild but I don't know what caused it. I've tried changing the extension of a renamed copy of the original serial2.c but there was no improvement.

    I have a few questions:

    How can I reliably cause a full rebuild? Will that actually change the buffer size?

    How can I access the value of SERIAL2_RX_BUFFER_SIZE from the main program?

    Thanks,

    John

  2. #2
    Junior Member
    Join Date
    Mar 2016
    Location
    Austin TX
    Posts
    5
    I see that Paul has recently put on Github some files to "Allow huge serial buffers on Teensy 3.x". This sounds great, but I don't know how to apply the changes.

    https://github.com/PaulStoffregen/co...92c606ce7457f5

    I guess I'll try making the edits by hand. The odd thing is that I'm sure this was working a couple of years ago, but I overwrote serial2.c with an update.

  3. #3
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    9,019
    That pending item allows for HUGE buffers over 65KB - where a 16 bit integer won't work.

    This should be where a simple change in the define will get the needed size:
    https://github.com/PaulStoffregen/co.../serial2.c#L40

    That looks like the notes in the OP - those are CORE files so changing them must rebuild - also closing the IDE and restarting will build all.

  4. #4
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    5,679
    It's a shame that arduino *still* does not support user-defined #defines or project settings.

    @defragster: With our batch or with this, it's so easy...

    I wonder when Massimo will make his promise come true and turn arduino into a useful ide. He announced it 3 or 4 years ago when I asked him about it. They are all great in announcing.
    Nothing happened. The "IDE" as he calls it is not an IDE, but a simple editor (and a pretty dumb one) from the previous century...

    @jss: Just find a way to do a
    Code:
    #define SERIAL2_RX_BUFFER_SIZE 2048
    from extern. If it is defined, it will override the setting in serial2.c.
    There are ways
    Last edited by Frank B; 07-18-2019 at 08:05 PM.

  5. #5
    Junior Member
    Join Date
    Mar 2016
    Location
    Austin TX
    Posts
    5
    Thanks guys, I restarted the IDE and the rest of the stuff works, bringing a 1000 4 byte integers into the Teensy.

  6. #6
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    5,040
    For what it is worth, with Teensy 4 code base, I added a couple of non-standard methods, so you could do something like:
    Code:
    uint8_t serial2_rx_extra_buffer[2048];
    
    void setup() {
    ...
        Serial2.addStorageForRead(serial2_rx_extra_buffer, sizeof(serial2_rx_extra_buffer));
        Serial2.begin(...);
    
    }
    But again only for T4 stuff. I had a version for T3.x a long time ago, but was never integrated.

    Edit: As for asking for the size of read buffer, as I mentioned on your other thread. If you change something only in a .c file, than only that .c file will know about it.
    Unless of course the object or the like has a method to access it...

    With TX Buffer size, you can probably grab it, by doing something like:
    Serial2.begin(115200);
    txBufferSize = Serial2.availableForWrite();

    Which should be equal or near to the size...

  7. #7
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    5,679
    Yea, a good possibilitly and workaround, too.
    However, project-settings would be so much more easy and usable and don't need extra code.. well..if they existed "officially".

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •