-
Notifications
You must be signed in to change notification settings - Fork 513
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.availableForWrite() and Serial.blockOnOverrun() implementation, USB Serial fixes for STM32F2 #812
Conversation
… and USB Serial fixes for STM32F2
2552ef1
to
30589c6
Compare
{ | ||
return (USB_Rx_length - USB_Rx_ptr); | ||
int32_t available = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm concerned that USB_Rx_Buffer_head / USB_Rx_Buffer_tail will be changed by the USB IRQ after being tested.
As a minimum, capture the tail and head into a local variables, and use that so we are certain they are consistent.
A context switch after comparing head >= tail could see head roll over to the start of the buffer, which would then result in the incorrect size being returned.
…o circular buffers
@m-mcgowan I've update PR with some minor adjustments. Yeah, I was also concerned about possible computation inconsistencies. As I said earlier, the only places that could really use a critical section are To have a clearer picture:
RX:
So, just to be on a safe side, I've added critical sections in both I've also increased USB RX buffer size to 256, as 128 can only hold 2x |
Now that the buffering has been reworked, I'm thinking it would be possible to implement USB, flush, as with write, would be a no-op if not connected. |
The
|
…USB serial port state (open/closed)
@m-mcgowan I've updated the PR. Added:
|
Conflicts: hal/inc/hal_dynalib_usart.h user/tests/wiring/api/wiring.cpp wiring/src/spark_wiring_usartserial.cpp
Conflicts: wiring/inc/spark_wiring_usbserial.h
Also fixes #669 and #846 |
I'm testing this branch by making a copy of #include "application.h"
SYSTEM_MODE(SEMI_AUTOMATIC);
// ALL_LEVEL, TRACE_LEVEL, DEBUG_LEVEL, INFO_LEVEL, WARN_LEVEL, ERROR_LEVEL, PANIC_LEVEL, NO_LOG_LEVEL
Serial1DebugOutput debugOutput(9600, ALL_LEVEL);
int count = 0;
void setup() {
pinMode(D1, INPUT_PULLDOWN);
pinMode(D7, OUTPUT);
Particle.connect();
DEBUG_D("\r\n[ Particle.connect ]\r\n\r\n");
waitUntil(Particle.connected);
DEBUG_D("\r\n[ Particle.connected ]\r\n\r\n");
}
void loop() {
DEBUG_D("\r\n[ Going to sleep ]\r\n\r\n");
digitalWrite(D7, HIGH);
delay(1000);
System.sleep(D1, RISING, 60);
delay(1000);
digitalWrite(D7, LOW);
DEBUG_D("\r\n[ Waking up and publishing twice! ]\r\n\r\n");
Particle.publish("b", String(++count));
delay(3000);
Particle.publish("b", String(++count));
delay(3000);
}
|
…ght prevent CPU from entering WFI
1d57384
to
3f495bf
Compare
@technobly I believe 3f495bf should fix this issue. Apparently USARTs busy transferring data might prevent CPU from entering WFI. |
Serial.availableForWrite() and Serial.blockOnOverrun() implementation, USB Serial fixes for STM32F2
This PR also solves Issue #923 |
Added Serial.availableForWrite() method for hardware USARTs and USB Serial.
Added Serial.blockOnOverrun(bool) method to set blocking/non-blocking behavior on TX buffer overrun (default is blocking).
This PR also includes a number of fixes for USB Serial driver on STM32F2.
Closes #798