I started (as a non programmer) with Thomas Roell and the Ladybug board. I used his board files and library forever.
Now Im porting to the STM32duino Core. Got through most porting issues with Generic L432KCUx series setting. But I used to write from a PC to my board through USB a large chunk of product calibration data all at once with no issues. (Maybe 256 bytes at least) using a basic Serial.read(); loop to bring it in.
Now it seems the buffer must be overflowing at > 64 bytes and I cant find where to set the USB buffer to higher values. Thats if the STM receive buffer even is causing the issue. Could it be the Windows USB transmit buffer? (I did not install any specific driver and using default ST PID/VID, so the PC is not using my driver which has different pid/vid - still basic CDC though).
This code below works for a max of A < 15. Filterxo[A] is a float and getdouble(); returns a conversion of serial characters to a floating number. Anything more than A>15 starts to screw up the values in the array. (I do increase the variable array size with this test).
for (uint16_t A = 0; A < 15; A++) {
Serial.println(A);
filterxo[A] = getdouble();
Serial.println(filterxo[A], 3);
Serial.read(); // get rid of spacer/term char x
}
I still need to make a variant of my board so I can use my own PID/VID, but it doesnt seem like there is a great step by step nube tutorial for the latest STM32 on Arduino 2.x available. Ive tried for a few hours with no luck but I think this is a secondary issue Ill post on a different topic.
Thanks for looking.
David
USB Buffer Over run STM32L432
Re: USB Buffer Over run STM32L432
As a bit different test, this shows a USB buffer size of 64 bytes max, but prints about 128 before losing it. The string variable teststr can go long if hardcoded:
else if (cmmd == 'c') {
while (Serial.available() == 0) {}
Serial.print("string started ");
Serial.println(Serial.available());
String teststr = Serial.readString();
Serial.print("string finished ");
Serial.println(Serial.available());
Serial.println(teststr);
teststr = "0x1x2x3x4x5x6x7x8x9x0x1x2x3x4x5x6x7x8x9x0x1x2x3x4x5x6x7x8x9x0x1x2x3x4x5x6x7x8x9x0x1x2x3x4x5x6x7x8x9x0x1x2x3x4x5x6x7x8x9x0x1x2x3x4x5x6x7x8x9x0x1x2x3x4x5x6x7x8x9x0x1x2x3x4x5x6x7x8x9x0x1x2x3x4x5x6x7x8x9x";
Serial.println(teststr);
}
Sending 201 bytes (using a terminal emulator called Termite):
c0x1x2x3x4x5x6x7x8x9x0x1x2x3x4x5x6x7x8x9x0x1x2x3x4x5x6x7x8x9x0x1x2x3x4x5x6x7x8x9x0x1x2x3x4x5x6x7x8x9x0x1x2x3x4x5x6x7x8x9x0x1x2x3x4x5x6x7x8x9x0x1x2x3x4x5x6x7x8x9x0x1x2x3x4x5x6x7x8x9x0x1x2x3x4x5x6x7x8x9x
Output is:
string started 63
string finished 0
0x1x2x3x4x5x6x7x8x9x0x1x2x3x4x5x6x7x8x9x0x1x2x3x4x5x6x7x8x9x0x1x2x3x4x5x6x7x8x9x0x1x2x3x4x5x6x7x8x9x0x1x2x3x4x5x6x7x8x9x0x1x2x3[00][00][00][00][00][00][00][00][00][00][00][00][00][00][00][00][00][00][00][00][00][00][00][00][00][00][00]x2x3x4x5x
0x1x2x3x4x5x6x7x8x9x0x1x2x3x4x5x6x7x8x9x0x1x2x3x4x5x6x7x8x9x0x1x2x3x4x5x6x7x8x9x0x1x2x3x4x5x6x7x8x9x0x1x2x3x4x5x6x7x8x9x0x1x2x3x4x5x6x7x8x9x0x1x2x3x4x5x6x7x8x9x0x1x2x3x4x5x6x7x8x9x0x1x2x3x4x5x6x7x8x9x
So hardcoded teststr prints out fine, but the USB input from Serial.readString chops off after about 128 bytes.
else if (cmmd == 'c') {
while (Serial.available() == 0) {}
Serial.print("string started ");
Serial.println(Serial.available());
String teststr = Serial.readString();
Serial.print("string finished ");
Serial.println(Serial.available());
Serial.println(teststr);
teststr = "0x1x2x3x4x5x6x7x8x9x0x1x2x3x4x5x6x7x8x9x0x1x2x3x4x5x6x7x8x9x0x1x2x3x4x5x6x7x8x9x0x1x2x3x4x5x6x7x8x9x0x1x2x3x4x5x6x7x8x9x0x1x2x3x4x5x6x7x8x9x0x1x2x3x4x5x6x7x8x9x0x1x2x3x4x5x6x7x8x9x0x1x2x3x4x5x6x7x8x9x";
Serial.println(teststr);
}
Sending 201 bytes (using a terminal emulator called Termite):
c0x1x2x3x4x5x6x7x8x9x0x1x2x3x4x5x6x7x8x9x0x1x2x3x4x5x6x7x8x9x0x1x2x3x4x5x6x7x8x9x0x1x2x3x4x5x6x7x8x9x0x1x2x3x4x5x6x7x8x9x0x1x2x3x4x5x6x7x8x9x0x1x2x3x4x5x6x7x8x9x0x1x2x3x4x5x6x7x8x9x0x1x2x3x4x5x6x7x8x9x
Output is:
string started 63
string finished 0
0x1x2x3x4x5x6x7x8x9x0x1x2x3x4x5x6x7x8x9x0x1x2x3x4x5x6x7x8x9x0x1x2x3x4x5x6x7x8x9x0x1x2x3x4x5x6x7x8x9x0x1x2x3x4x5x6x7x8x9x0x1x2x3[00][00][00][00][00][00][00][00][00][00][00][00][00][00][00][00][00][00][00][00][00][00][00][00][00][00][00]x2x3x4x5x
0x1x2x3x4x5x6x7x8x9x0x1x2x3x4x5x6x7x8x9x0x1x2x3x4x5x6x7x8x9x0x1x2x3x4x5x6x7x8x9x0x1x2x3x4x5x6x7x8x9x0x1x2x3x4x5x6x7x8x9x0x1x2x3x4x5x6x7x8x9x0x1x2x3x4x5x6x7x8x9x0x1x2x3x4x5x6x7x8x9x0x1x2x3x4x5x6x7x8x9x
So hardcoded teststr prints out fine, but the USB input from Serial.readString chops off after about 128 bytes.
Re: USB Buffer Over run STM32L432
well, format your post, comment so that it is more readable, e.g.
did you declare your filterxo array properly? e.g.
Code: Select all
for (uint16_t A = 0; A < 15; A++) {
Serial.println(A);
filterxo[A] = getdouble();
Serial.println(filterxo[A], 3);
Serial.read(); // get rid of spacer/term char x
}
Code: Select all
#include <Arduino.h>
double filterxo[16];
void setup() {
Serial.begin(); //assuming that you are using usb-cdc-serial, no baud rates etc is needed
}
void loop() {
for (uint16_t A = 0; A < 15; A++) {
Serial.println(A);
filterxo[A] = getdouble();
Serial.println(filterxo[A]); // double/float with decimals etc
// Serial.println(filterxo[A], HEX); // if you prefer hex use the symbol HEX https://github.com/stm32duino/Arduino_Core_STM32/blob/main/cores/arduino/Print.h#L30
Serial.read(); // get rid of spacer/term char x
}
}
Re: USB Buffer Over run STM32L432
Thanks for that.
Yes, the total code is quite large and worked perfectly for years.
Yes, the total code is quite large and worked perfectly for years.
Re: USB Buffer Over run STM32L432
well, I'm not too sure about your codes, but that Serial (including USB serial and HardwareSerial) uses a ringbuffer.
If the receiving end did not read the buffer, it is possible that it gets filled.
I reviewed the codes and found that there is
Serial.availableForWrite()
virtual int availableForWrite(void);
https://github.com/stm32duino/Arduino_C ... rial.h#L36
you may want to check that so that it doesn't overwrite the buffer in case it is full.
a code for a spinlock is typically like
for the rest, I'd refer to @fpiSTM as he may be more familiar with this.
If the receiving end did not read the buffer, it is possible that it gets filled.
I reviewed the codes and found that there is
Serial.availableForWrite()
virtual int availableForWrite(void);
https://github.com/stm32duino/Arduino_C ... rial.h#L36
you may want to check that so that it doesn't overwrite the buffer in case it is full.
a code for a spinlock is typically like
Code: Select all
void loop() {
// check that the serial buffer is not full.
while(! Serial.availableForWrite()) { asm ("wfi"); } // that asm is optional, wait for interrupt, normally systick 1ms
Serial.write(mybufferstuff, Serial.availableForWrite()); // write the next amount of stuff up to number of bytes available.
...
}