Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
e65751b
Ipv6 support v3
s-hadinger Jan 16, 2023
18c0a6c
Update toolchains and openocd for ESP-IDF v4.4.4
me-no-dev Feb 8, 2023
0ee74ee
Update get.py to support Apple ARM64
me-no-dev Feb 8, 2023
e531341
Update package version
me-no-dev Feb 8, 2023
1376ee0
Update ESP-IDF libs to v4.4.4
me-no-dev Feb 8, 2023
997542c
Fix compilation issue caused by ESP-Insights
me-no-dev Feb 9, 2023
3324aff
Update esptool to v4.4
me-no-dev Feb 9, 2023
8a458d1
Update esptool to v4.5
me-no-dev Feb 13, 2023
1ca741e
Merge branch 'master' into release/v2.x
me-no-dev Feb 15, 2023
0da8ecb
Merge branch 'master' into release/v2.x
me-no-dev Feb 20, 2023
213f976
Merge branch 'master' into release/v2.x
me-no-dev Feb 20, 2023
d6a850b
Update package_esp32_index.template.json
me-no-dev Feb 20, 2023
50269f6
Update esptool to v4.5.1
me-no-dev Mar 1, 2023
a069764
Add setMode function HardwareSerial.c to set the esp32 uart mode for …
jamesarm97 Mar 31, 2023
93903fc
Fix the F_CPU frequency definition for the ESP32-S3 in esp32-hal.h (#…
devrim-oguz Mar 31, 2023
e7d3a2f
Merge branch 'master' into release/v2.x
me-no-dev Mar 31, 2023
540ab86
Merge branch 'master' into release/v2.x
me-no-dev Apr 7, 2023
8fca365
Add support for esp-elf-gdb
me-no-dev Apr 7, 2023
2d7218b
WFG Crashfix (#8043)
mrengineer7777 Apr 10, 2023
2ff2b43
Update RainMaker and components
me-no-dev Apr 10, 2023
788a4ca
Merge branch 'master' into release/v2.x
me-no-dev Apr 10, 2023
483bebf
WiFiUDF Low memory fix (#8065)
mrengineer7777 Apr 11, 2023
25a5434
Tasmota release/
Jason2866 Apr 14, 2023
bdbfc45
Merge branch 'master' into release/v2.x
me-no-dev Apr 18, 2023
8d17f43
Merge branch 'release/v2.x' into merge_release/v2.x
Jason2866 Apr 18, 2023
da21d1a
Tasmota changes
Jason2866 Apr 18, 2023
16cee61
Enable DFU
me-no-dev Apr 19, 2023
a115594
Add required callbacks for TinyUSB DFU
me-no-dev Apr 19, 2023
71113c3
Merge branch 'master' into release/v2.x
me-no-dev Apr 19, 2023
d3254f7
Update version to 2.0.8
me-no-dev Apr 20, 2023
fb94d7d
Merge branch 'espressif:release/v2.x' into release/v2.x
Jason2866 Apr 20, 2023
f42cba9
Merge branch 'master' into release/v2.x
me-no-dev May 3, 2023
f89df42
BugFix FlashStringHelper Macros (#8143)
mrengineer7777 May 3, 2023
362a81b
Merge branch 'master' into release/v2.x
me-no-dev May 3, 2023
3670e2b
Update version to 2.0.9
me-no-dev May 3, 2023
a4889ba
Merge branch 'espressif:release/v2.x' into release/v2.x
Jason2866 May 3, 2023
0eb6f2b
Merge branch 'master' into PR_IPv6_final
Jason2866 May 5, 2023
02c75cb
timeout_ms
Jason2866 May 5, 2023
f4efcfa
updates from Upstream
Jason2866 May 5, 2023
e658551
disconnect reason
Jason2866 May 5, 2023
8301bc6
free / malloc from upstream
Jason2866 May 5, 2023
95bffce
`tv.tv_usec = (_timeout % 1000) * 1000;` align with upstream
Jason2866 May 7, 2023
f8f2f8c
changes 2023.05.31 from upstream `master`
Jason2866 May 31, 2023
447f6db
Merge branch 'master' into release/v2.x
me-no-dev May 31, 2023
0a97245
Merge branch 'espressif:release/v2.x' into release/v2.x
Jason2866 Jun 2, 2023
6512f03
Update package_esp32_index.template.json
Jason2866 Jun 2, 2023
a6b17e2
Merge pull request #224 from tasmota/release/v2.x
Jason2866 Jun 2, 2023
85e1d4e
Revert "Update PR to upstream"
Jason2866 Jun 2, 2023
bfad05b
Merge pull request #225 from tasmota/revert-224-release/v2.x
Jason2866 Jun 2, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add setMode function HardwareSerial.c to set the esp32 uart mode for …
…use with RS485 auto RTS (#7935)

* Added setMode function to set the esp32 uart mode

Used to set the esp32 uart mode for use with RS485 Half Duplex and the auto RTS pin mode. This will set/clear the RTS pin output to control the RE/DE pin on most RS485 chips.

* Add Success (bool) return in some functions

* Add Success (bool) return code to some functions

* Add Success (bool) return to some functions

* Add Success (bool) return to some functions

* Fix uartSetRxTimeout return type

---------

Co-authored-by: Rodrigo Garcia <rodrigo.garcia@espressif.com>
  • Loading branch information
jamesarm97 and SuGlider authored Mar 31, 2023
commit a069764db15f325eea81332752b9d2a91d74e60d
30 changes: 20 additions & 10 deletions cores/esp32/HardwareSerial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ void HardwareSerial::onReceive(OnReceiveCb function, bool onlyOnTimeout)
// A low value of FIFO Full bytes will consume more CPU time within the ISR
// A high value of FIFO Full bytes will make the application wait longer to have byte available for the Stkech in a streaming scenario
// Both RX FIFO Full and RX Timeout may affect when onReceive() will be called
void HardwareSerial::setRxFIFOFull(uint8_t fifoBytes)
bool HardwareSerial::setRxFIFOFull(uint8_t fifoBytes)
{
HSERIAL_MUTEX_LOCK();
// in case that onReceive() shall work only with RX Timeout, FIFO shall be high
Expand All @@ -242,14 +242,15 @@ void HardwareSerial::setRxFIFOFull(uint8_t fifoBytes)
fifoBytes = 120;
log_w("OnReceive is set to Timeout only, thus FIFO Full is now 120 bytes.");
}
uartSetRxFIFOFull(_uart, fifoBytes); // Set new timeout
bool retCode = uartSetRxFIFOFull(_uart, fifoBytes); // Set new timeout
if (fifoBytes > 0 && fifoBytes < SOC_UART_FIFO_LEN - 1) _rxFIFOFull = fifoBytes;
HSERIAL_MUTEX_UNLOCK();
return retCode;
}

// timout is calculates in time to receive UART symbols at the UART baudrate.
// the estimation is about 11 bits per symbol (SERIAL_8N1)
void HardwareSerial::setRxTimeout(uint8_t symbols_timeout)
bool HardwareSerial::setRxTimeout(uint8_t symbols_timeout)
{
HSERIAL_MUTEX_LOCK();

Expand All @@ -258,9 +259,10 @@ void HardwareSerial::setRxTimeout(uint8_t symbols_timeout)
_rxTimeout = symbols_timeout;
if (!symbols_timeout) _onReceiveTimeout = false; // only when RX timeout is disabled, we also must disable this flag

uartSetRxTimeout(_uart, _rxTimeout); // Set new timeout
bool retCode = uartSetRxTimeout(_uart, _rxTimeout); // Set new timeout

HSERIAL_MUTEX_UNLOCK();
return retCode;
}

void HardwareSerial::eventQueueReset()
Expand Down Expand Up @@ -548,28 +550,36 @@ void HardwareSerial::setRxInvert(bool invert)
}

// negative Pin value will keep it unmodified
void HardwareSerial::setPins(int8_t rxPin, int8_t txPin, int8_t ctsPin, int8_t rtsPin)
bool HardwareSerial::setPins(int8_t rxPin, int8_t txPin, int8_t ctsPin, int8_t rtsPin)
{
if(_uart == NULL) {
log_e("setPins() shall be called after begin() - nothing done\n");
return;
return false;
}

// uartSetPins() checks if pins are valid for each function and for the SoC
if (uartSetPins(_uart, rxPin, txPin, ctsPin, rtsPin)) {
// uartSetPins() checks if pins are valid for each function and for the SoC
bool retCode = uartSetPins(_uart, rxPin, txPin, ctsPin, rtsPin);
if (retCode) {
_txPin = _txPin >= 0 ? txPin : _txPin;
_rxPin = _rxPin >= 0 ? rxPin : _rxPin;
_rtsPin = _rtsPin >= 0 ? rtsPin : _rtsPin;
_ctsPin = _ctsPin >= 0 ? ctsPin : _ctsPin;
} else {
log_e("Error when setting Serial port Pins. Invalid Pin.\n");
}
return retCode;
}

// Enables or disables Hardware Flow Control using RTS and/or CTS pins (must use setAllPins() before)
void HardwareSerial::setHwFlowCtrlMode(uint8_t mode, uint8_t threshold)
bool HardwareSerial::setHwFlowCtrlMode(uint8_t mode, uint8_t threshold)
{
return uartSetHwFlowCtrlMode(_uart, mode, threshold);
}

// Sets the uart mode in the esp32 uart for use with RS485 modes (HwFlowCtrl must be disabled and RTS pin set)
bool HardwareSerial::setMode(uint8_t mode)
{
uartSetHwFlowCtrlMode(_uart, mode, threshold);
return uartSetMode(_uart, mode);
}

size_t HardwareSerial::setRxBufferSize(size_t new_size) {
Expand Down
11 changes: 6 additions & 5 deletions cores/esp32/HardwareSerial.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,13 @@ class HardwareSerial: public Stream
// Examples: Maximum for 11 bits symbol is 92 (SERIAL_8N2, SERIAL_8E1, SERIAL_8O1, etc), Maximum for 10 bits symbol is 101 (SERIAL_8N1).
// For example symbols_timeout=1 defines a timeout equal to transmission time of one symbol (~11 bit) on current baudrate.
// For a baudrate of 9600, SERIAL_8N1 (10 bit symbol) and symbols_timeout = 3, the timeout would be 3 / (9600 / 10) = 3.125 ms
void setRxTimeout(uint8_t symbols_timeout);
bool setRxTimeout(uint8_t symbols_timeout);

// setRxFIFOFull(uint8_t fifoBytes) will set the number of bytes that will trigger UART_INTR_RXFIFO_FULL interrupt and fill up RxRingBuffer
// This affects some functions such as Serial::available() and Serial.read() because, in a UART flow of receiving data, Serial internal
// RxRingBuffer will be filled only after these number of bytes arrive or a RX Timeout happens.
// This parameter can be set to 1 in order to receive byte by byte, but it will also consume more CPU time as the ISR will be activates often.
void setRxFIFOFull(uint8_t fifoBytes);
bool setRxFIFOFull(uint8_t fifoBytes);

// onReceive will setup a callback that will be called whenever an UART interruption occurs (UART_INTR_RXFIFO_FULL or UART_INTR_RXFIFO_TOUT)
// UART_INTR_RXFIFO_FULL interrupt triggers at UART_FULL_THRESH_DEFAULT bytes received (defined as 120 bytes by default in IDF)
Expand Down Expand Up @@ -161,10 +161,11 @@ class HardwareSerial: public Stream

// Negative Pin Number will keep it unmodified, thus this function can set individual pins
// SetPins shall be called after Serial begin()
void setPins(int8_t rxPin, int8_t txPin, int8_t ctsPin = -1, int8_t rtsPin = -1);
bool setPins(int8_t rxPin, int8_t txPin, int8_t ctsPin = -1, int8_t rtsPin = -1);
// Enables or disables Hardware Flow Control using RTS and/or CTS pins (must use setAllPins() before)
void setHwFlowCtrlMode(uint8_t mode = HW_FLOWCTRL_CTS_RTS, uint8_t threshold = 64); // 64 is half FIFO Length

bool setHwFlowCtrlMode(uint8_t mode = HW_FLOWCTRL_CTS_RTS, uint8_t threshold = 64); // 64 is half FIFO Length
// Used to set RS485 modes such as UART_MODE_RS485_HALF_DUPLEX for Auto RTS function on ESP32
bool setMode(uint8_t mode);
size_t setRxBufferSize(size_t new_size);
size_t setTxBufferSize(size_t new_size);

Expand Down
38 changes: 29 additions & 9 deletions cores/esp32/esp32-hal-uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,16 @@ bool uartSetPins(uart_t* uart, int8_t rxPin, int8_t txPin, int8_t ctsPin, int8_t
}

//
void uartSetHwFlowCtrlMode(uart_t *uart, uint8_t mode, uint8_t threshold) {
bool uartSetHwFlowCtrlMode(uart_t *uart, uint8_t mode, uint8_t threshold) {
if(uart == NULL) {
return;
return false;
}
// IDF will issue corresponding error message when mode or threshold are wrong and prevent crashing
// IDF will check (mode > HW_FLOWCTRL_CTS_RTS || threshold >= SOC_UART_FIFO_LEN)
uart_set_hw_flow_ctrl(uart->num, (uart_hw_flowcontrol_t) mode, threshold);
UART_MUTEX_LOCK();
bool retCode = (ESP_OK == uart_set_hw_flow_ctrl(uart->num, (uart_hw_flowcontrol_t) mode, threshold));
UART_MUTEX_UNLOCK();
return retCode;
}


Expand Down Expand Up @@ -244,26 +247,28 @@ void uartSetFastReading(uart_t* uart)
}


void uartSetRxTimeout(uart_t* uart, uint8_t numSymbTimeout)
bool uartSetRxTimeout(uart_t* uart, uint8_t numSymbTimeout)
{
if(uart == NULL) {
return;
return false;
}

UART_MUTEX_LOCK();
uart_set_rx_timeout(uart->num, numSymbTimeout);
bool retCode = (ESP_OK == uart_set_rx_timeout(uart->num, numSymbTimeout));
UART_MUTEX_UNLOCK();
return retCode;
}

void uartSetRxFIFOFull(uart_t* uart, uint8_t numBytesFIFOFull)
bool uartSetRxFIFOFull(uart_t* uart, uint8_t numBytesFIFOFull)
{
if(uart == NULL) {
return;
return false;
}

UART_MUTEX_LOCK();
uart_set_rx_full_threshold(uart->num, numBytesFIFOFull);
bool retCode = (ESP_OK == uart_set_rx_full_threshold(uart->num, numBytesFIFOFull));
UART_MUTEX_UNLOCK();
return retCode;
}

void uartEnd(uart_t* uart)
Expand Down Expand Up @@ -518,6 +523,21 @@ void uart_install_putc()
}
}

// Routines that take care of UART mode in the HardwareSerial Class code
// used to set UART_MODE_RS485_HALF_DUPLEX auto RTS for TXD for ESP32 chips
bool uartSetMode(uart_t *uart, uint8_t mode)
{
if (uart == NULL || uart->num >= SOC_UART_NUM)
{
return false;
}

UART_MUTEX_LOCK();
bool retCode = (ESP_OK == uart_set_mode(uart->num, mode));
UART_MUTEX_UNLOCK();
return retCode;
}

void uartSetDebug(uart_t* uart)
{
if(uart == NULL || uart->num >= SOC_UART_NUM) {
Expand Down
19 changes: 16 additions & 3 deletions cores/esp32/esp32-hal-uart.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@ extern "C" {
#define HW_FLOWCTRL_CTS 0x2 // use only CTS PIN for HW Flow Control
#define HW_FLOWCTRL_CTS_RTS 0x3 // use both CTS and RTS PIN for HW Flow Control

// These are Hardware Uart Modes possible usage
// equivalent to UDF enum uart_mode_t from
// https://github.com/espressif/esp-idf/blob/master/components/hal/include/hal/uart_types.h#L34-L40
#define MODE_UART 0x00 // mode: regular UART mode
#define MODE_RS485_HALF_DUPLEX 0x01 // mode: half duplex RS485 UART mode control by RTS pin
#define MODE_IRDA 0x02 // mode: IRDA UART mode
#define MODE_RS485_COLLISION_DETECT 0x03 // mode: RS485 collision detection UART mode (used for test purposes)
#define MODE_RS485_APP_CTRL 0x04

struct uart_struct_t;
typedef struct uart_struct_t uart_t;

Expand All @@ -83,8 +92,8 @@ void uartSetBaudRate(uart_t* uart, uint32_t baud_rate);
uint32_t uartGetBaudRate(uart_t* uart);

void uartSetRxInvert(uart_t* uart, bool invert);
void uartSetRxTimeout(uart_t* uart, uint8_t numSymbTimeout);
void uartSetRxFIFOFull(uart_t* uart, uint8_t numBytesFIFOFull);
bool uartSetRxTimeout(uart_t* uart, uint8_t numSymbTimeout);
bool uartSetRxFIFOFull(uart_t* uart, uint8_t numBytesFIFOFull);
void uartSetFastReading(uart_t* uart);

void uartSetDebug(uart_t* uart);
Expand All @@ -97,7 +106,11 @@ bool uartSetPins(uart_t* uart, int8_t rxPin, int8_t txPin, int8_t ctsPin, int8_t
void uartDetachPins(uart_t* uart, int8_t rxPin, int8_t txPin, int8_t ctsPin, int8_t rtsPin);

// Enables or disables HW Flow Control function -- needs also to set CTS and/or RTS pins
void uartSetHwFlowCtrlMode(uart_t *uart, uint8_t mode, uint8_t threshold);
bool uartSetHwFlowCtrlMode(uart_t *uart, uint8_t mode, uint8_t threshold);

// Used to set RS485 function -- needs to disable HW Flow Control and set RTS pin to use
// RTS pin becomes RS485 half duplex RE/DE
bool uartSetMode(uart_t *uart, uint8_t mode);

void uartStartDetectBaudrate(uart_t *uart);
unsigned long uartDetectBaudrate(uart_t *uart);
Expand Down