-
Notifications
You must be signed in to change notification settings - Fork 24
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
Initial UART HW flow control support #79
Conversation
StatusWork in progress - would be good if someone else would also find time to test this |
ESP8266/ESP8266.cpp
Outdated
&& _parser.recv("OK\n"); | ||
|
||
_serial.set_flow_control(SerialBase::CTS, NC, _serial_cts); | ||
} |
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.
Where is the else
case?
When no flow control pins are enabled, should it still call something, or is the point entirely skip it?
If device have flow control set as a default, should we still disable it?
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.
Also, on last case _serial.set_flow_contro()
is called after _parser.send()
, is this intentional?
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 understad it so that we are not taking orders from ESP8266 when to send until ESP8266 is configured to do so.
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.
When there are no pins configured for flow control there is no need to make any settings
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.
This won't actually be 100% solid. Eg if 1 app is busy streaming data, another app may be making read calls for its socket, despite the fact that the first app hasn't consumed its data. In that scenario we will be filling up local buffers with socket 1 data to deliver the socket 2 data.
Still, better than nothing.
ESP8266/ESP8266.cpp
Outdated
free(q); | ||
_heap_usage -= sizeof(struct packet) + alloc_len; |
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.
Formatting - tabs.
ESP8266/ESP8266.h
Outdated
@@ -304,6 +316,8 @@ class ESP8266 | |||
int _socket_open[SOCKET_COUNT]; | |||
nsapi_connection_status_t _connection_status; | |||
Callback<void(nsapi_event_t, intptr_t)> _connection_status_cb; | |||
static const int32_t _MAX_HEAP_USAGE = MBED_CONF_ESP8266_SOCKET_BUFSIZE; |
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.
Sizes should probably be size_t
throughout.
ESP8266/ESP8266.cpp
Outdated
_packets(0), | ||
// Big enough, target specific | ||
#ifndef MBED_CONF_ESP8266_SOCKET_BUFSIZE | ||
#define MBED_CONF_ESP8266_SOCKET_BUFSIZE 102400 |
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.
If you have a default in the JSON, don't need a default here. (Gets confusing when people try hacking around)
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.
True, I'll take this away and leave it to mbed_lib.json
ESP8266/ESP8266.cpp
Outdated
_serial.set_flow_control(SerialBase::RTSCTS, _serial_rts, _serial_cts); | ||
|
||
// Start ESP8266's flow control | ||
done = _parser.send("AT+UART_CUR=%u,%u,%u,%u,%u", ESP8266_DEFAULT_BAUD_RATE, DATABITS_8, STOPBITS_1, |
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.
If you're going to the trouble of using all those %u
to parametrise, then why not just have a single send
call that takes the mode as a parameter, rather than putting it in 3 places?
Personally wouldn't object to just putting 8,1,0
in there literally, rather than spending the code size on the %u
s.
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.
Personally wouldn't object to just putting 8,1,0 in there literally, rather than spending the code size on the %us.
I agree
ESP8266/ESP8266.cpp
Outdated
packet->next = 0; | ||
|
||
if (_parser.read((char*)(packet + 1), amount) < amount) { | ||
free(packet); | ||
_heap_usage -= pdu_len; | ||
MBED_ASSERT(_heap_usage >= 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.
... Although if you did change to size_t
, this would need to change to an assert that pdu_len >= _heap_usage
before subtraction.
ESP8266/ESP8266.h
Outdated
@@ -20,6 +20,7 @@ | |||
#include "ATCmdParser.h" | |||
#include "nsapi_types.h" | |||
#include "rtos.h" | |||
#include "UARTSerial.h" |
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.
Don't see reason for added include here.
ESP8266/ESP8266.cpp
Outdated
|
||
if ((_heap_usage + pdu_len) > _MAX_HEAP_USAGE) { | ||
debug("ESP8266: socket buffer max memory limit exceeded, either increase socket buffer size from mbed_lib.json or enable UART HW flow control\n"); | ||
MBED_ASSERT(false); |
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.
Use MBED_ERROR
instead. (Ask Kari for help)
* | ||
* @return true if started | ||
*/ | ||
bool start_uart_hw_flow_ctrl(); |
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.
Should this be private?
We are calling this, and not expecting users to call it? am I right?
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.
Called from ESP8266Interface.cpp so needs to be public
Required RTS/CTS wiringBootloader wiringBe aware that the ESP8266's RTS pin is GPIO15 which is also used for boot mode selection GPIO0 on ESPBeePull down for firmware update - pull up for flash boot ReferencesESPBee Pinout |
Since you already have pictures, can you add section to |
4616b77
to
62bd7c1
Compare
62bd7c1
to
28552b8
Compare
Squashed and rebased |
@marcuschangarm I fixed a stupid mistake which prevented flow control working at all. I had configured the flow control before running reset for the ESP8266.. Please update |
README.md updated to have an example how to enable UART HW flow control |
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.
On the previous section The serial port does not have hardware flow control enabled.
change this to does not have hardware flow control enabled by default
Then add a note that not all modules expose RTS/CTS pins.
3598917
to
5130604
Compare
Description
Enables UART HW flow control. Requires RTS/CTS wiring if ESP8266 is on a separate module or the pins are not connected for another reason.
Pull request type
[ ] Fix
[ ] Refactor
[ ] New target
[X] Feature
[ ] Breaking change
Example Mbed OS app config