Skip to content
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

Teensy3 addMemoryForWrite/Read issue #627

Open
revahsta opened this issue Nov 18, 2021 · 0 comments
Open

Teensy3 addMemoryForWrite/Read issue #627

revahsta opened this issue Nov 18, 2021 · 0 comments

Comments

@revahsta
Copy link

I ran into an issue while using the serial addMemoryForWrite() function, which I believe I've tracked down to an bug in the teensy3 serialX.c.

In teensy3/serialX.c, the buffer head and tails (tx_buffer_head, etc.) are declared as different types depending on what SERIALX_TX_BUFFER_SIZE is set to. However, this does not take into account memory added using addMemoryForWrite() at runtime. With the default SERIAL_TX_BUFFER_SIZE the head/tail will beuint8_t, so if I pass in say an extra 256 bytes of buffer memory then they will be unable to point to data in the upper part of that extra buffer.

Looking at the serial output with a logic analyzer, this will show up as unexpected serial write behavior (e.g. extra bytes being sent periodically). Below is a script that will intermittently show such behavior (tested on a Teensy 3.2):

uint8_t serial_tx_buf[256];

uint8_t data_packet[55];

elapsedMillis elapsed_time_ms = 0u;

void setup()
{
  Serial1.addMemoryForWrite(serial_tx_buf, sizeof(serial_tx_buf));
  Serial1.begin(57600);

  memset(data_packet, 0x69, sizeof(data_packet));
}

void loop()
{
  elapsed_time_ms = 0;

  Serial1.write(data_packet, sizeof(data_packet));

  if (elapsed_time_ms < 1000) {
    delay(1000 - elapsed_time_ms);
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant