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

Thread: Problem using Serial1.addMemoryForWrite()

  1. #1

    Problem using Serial1.addMemoryForWrite()


    I'm trying to use Serial1.addMemoryForWrite() to increase the size of the transmit buffer so that I can load up my entire serial packet in one go, then go off and do other stuff while it's transmitting.

    However, I'm getting the following error:

    error: 'class HardwareSerial' has no member named 'addMemoryForWrite'

    I'm using a Teensy 3.6 and am using Visual Code / PlatformIO for the IDE. I have Teensyduino 1.55 installed with Arduino 1.8.15.

    When I dig into HardwareSerial.h I do not see addMemoryForWrite.

    However, when I look at I do see it there. In fact, that file looks significantly different than what I have (copied below).

    Do I have an out of date version, or is this not supported on Teensy 3.6, or am I completely missing something else

    #ifdef __cplusplus
    #include "Stream.h"
    class HardwareSerial : public Stream
    	constexpr HardwareSerial() {}
    	virtual void begin(uint32_t baud) { serial_begin(BAUD2DIV(baud)); }
    	virtual void begin(uint32_t baud, uint32_t format) {
    					  serial_format(format); }
    	virtual void end(void)		{ serial_end(); }
    	virtual void transmitterEnable(uint8_t pin) { serial_set_transmit_pin(pin); }
    	virtual void setRX(uint8_t pin) { serial_set_rx(pin); }
    	virtual void setTX(uint8_t pin, bool opendrain=false) { serial_set_tx(pin, opendrain); }
    	virtual bool attachRts(uint8_t pin) { return serial_set_rts(pin); }
    	virtual bool attachCts(uint8_t pin) { return serial_set_cts(pin); }
    	virtual int available(void)     { return serial_available(); }
    	virtual int peek(void)          { return serial_peek(); }
    	virtual int read(void)          { return serial_getchar(); }
    	virtual void flush(void)        { serial_flush(); }
    	virtual void clear(void)	{ serial_clear(); }
    	virtual int availableForWrite(void) { return serial_write_buffer_free(); }
    	using Print::write;
    	virtual size_t write(uint8_t c) { serial_putchar(c); return 1; }
    	virtual size_t write(unsigned long n)   { return write((uint8_t)n); }
    	virtual size_t write(long n)            { return write((uint8_t)n); }
    	virtual size_t write(unsigned int n)    { return write((uint8_t)n); }
    	virtual size_t write(int n)             { return write((uint8_t)n); }
    	virtual size_t write(const uint8_t *buffer, size_t size)
    					{ serial_write(buffer, size); return size; }
            virtual size_t write(const char *str)	{ size_t len = strlen(str);
    					  serial_write((const uint8_t *)str, len);
    					  return len; }
    	virtual size_t write9bit(uint32_t c)	{ serial_putchar(c); return 1; }
    	operator bool()			{ return true; }
    extern HardwareSerial Serial1;
    extern void serialEvent1(void);

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Quote Originally Posted by Geomancer View Post
    Do I have an out of date version,
    Sure looks that like an old file.

    or is this not supported on Teensy 3.6,
    It is supported in 1.55.

    Test with Arduino first, then check on PlatformIO. Try compiling a simple program like:

    void setup() {
      static uint8_t buf[300];
      Serial1.addMemoryForWrite(buf, sizeof(buf));
    void loop() {
    This definitely compiles for Teensy 3.6 without any errors using Teensyduino 1.55. Check if your copy of Arduino and PlatformIO can compile it.

    If it compiles, try editing that HardwareSerial.h file. Add a syntax error and recompile. Maybe you're looking at an old file which isn't actually used?

  3. #3
    Worked fine in Arduino.

    Dug into PlatformIO and realized it doesn't actually use Teensyduino (at least, not the one installed for use by the Arduino IDE). It had its own set of files, and I found I needed to update the "Platform" to the latest version.

    Doing so fixed the error and it's now compiling.

    Knew it had to be something dumb that I was missing. I'm much more of a hardware guy than software.

    Thank you greatly for your help.

Posting Permissions

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