Commit Graph

53 Commits

Author SHA1 Message Date
Rodrigo Garcia
b1d072df9f
Implements UART SerialHardware Refactoring on top of IDF (#5549)
## Summary
This PR is a complete reffactoring of UART Serial Hardware and respective HAL in order to use IDF instead of current Register manipulation approach. 

It  implements Arduino SerialEvent functionality. 

Fix #5287  
Fix #5273 
Fix #5519 
Fix #5247 
Fix #5403
Fix #5429
Fix #5047
Fix #5463
Fix #5362 
Fix #5112  
Fix #5443 

## Impact
It solves many reported issues related to UART.
It was tested and works fine for ESP32, ESP-S2 and ESP32-C3.
2021-08-23 17:25:33 +03:00
me-no-dev
b580bb23fd Add log_buf to pretty print buffers
```
/* 0x0000 */ 0x7b, 0x7b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,    // {{..............
/* 0x0010 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,    // ................
```
2021-08-17 17:01:16 +03:00
Me No Dev
0b0dfab3cf
Fix race in log_printf (#5523)
Fixes: https://github.com/espressif/arduino-esp32/issues/5513

Can still race if Serial.begin() is not called in setup()
2021-08-11 13:46:08 +03:00
Rodrigo Garcia
5458df0a54
Fixes Serial.end() hanging on ESP32-S2 (#5434)
Fixes: #5429
2021-07-21 17:02:06 +03:00
Rodrigo Garcia
676f5cfe30
fix UART FIFO test for being full (#5390)
Fixes #5362
2021-07-16 03:21:49 +03:00
Rodrigo Garcia
f4f1c8956b
pinMatrixInDetach() has wrong parameter (#5385)
Fixes #5112
Call to pinMatrixInDetach() was changed from version 1.0.6 in version 2.0.0 injecting a bug as seen in cores/esp32/esp32-hal-uart.c
80418fadcf

Co-authored-by: Me No Dev <me-no-dev@users.noreply.github.com>
2021-07-15 02:07:43 +03:00
Me No Dev
404a31f445
Initial Esp32c3 Support (#5060) 2021-04-14 18:10:05 +03:00
me-no-dev
371f382db7 Fix Serial RX and add option for FIFO Full Threshold in Serial.begin
Fixes: https://github.com/espressif/arduino-esp32/issues/5005
2021-04-08 15:29:53 +03:00
Me No Dev
5502879a5b
v2.0.0 Add support for ESP32S2 and update ESP-IDF to 4.4 (#4996)
This is very much still work in progress and much more will change before the final 2.0.0

Some APIs have changed. New libraries have been added. LittleFS included.

Co-authored-by: Seon Rozenblum <seonr@3sprockets.com>
Co-authored-by: Me No Dev <me-no-dev@users.noreply.github.com>
Co-authored-by: geeksville <kevinh@geeksville.com>
Co-authored-by: Mike Dunston <m_dunston@comcast.net>
Co-authored-by: Unexpected Maker <seon@unexpectedmaker.com>
Co-authored-by: Seon Rozenblum <seonr@3sprockets.com>
Co-authored-by: microDev <70126934+microDev1@users.noreply.github.com>
Co-authored-by: tobozo <tobozo@users.noreply.github.com>
Co-authored-by: bobobo1618 <bobobo1618@users.noreply.github.com>
Co-authored-by: lorol <lorolouis@gmail.com>
Co-authored-by: geeksville <kevinh@geeksville.com>
Co-authored-by: Limor "Ladyada" Fried <limor@ladyada.net>
Co-authored-by: Sweety <switi.mhaiske@espressif.com>
Co-authored-by: Loick MAHIEUX <loick111@gmail.com>
Co-authored-by: Larry Bernstone <lbernstone@gmail.com>
Co-authored-by: Valerii Koval <valeros@users.noreply.github.com>
Co-authored-by: 快乐的我531 <2302004040@qq.com>
Co-authored-by: chegewara <imperiaonline4@gmail.com>
Co-authored-by: Clemens Kirchgatterer <clemens@1541.org>
Co-authored-by: Aron Rubin <aronrubin@gmail.com>
Co-authored-by: Pete Lewis <601236+lewispg228@users.noreply.github.com>
2021-04-05 14:23:58 +03:00
me-no-dev
8dc70e0add Revert "Update licenses"
This reverts commit 4b3f5c8ed4.
2021-03-11 12:11:53 +02:00
me-no-dev
4b3f5c8ed4 Update licenses 2021-02-18 12:14:35 +02:00
Bert Melis
f98fc7ee9f
fix hwSerial tx only flush (#4263) 2020-10-01 15:30:45 +03:00
brian-r-calder
8fcc914853
Added facility to invert the polarity of input UART bits. (#4200) 2020-10-01 13:58:48 +03:00
lbernstone
80418fadcf
Fixes UART detach. Fixes #3878 (#3894)
* Fixes UART detach.  Fixes #3878

* 0 is not a good holder value for pins!

* 0 is not a good holder value for pins!
2020-09-30 15:04:18 +03:00
Admar Schoonen
e34e0b45de
Fixed bug where mutex would not be unlocked (#3837)
Fixed bug where uartResizeRxBuffer() did not unlock mutex if creation of queue failed.
2020-09-30 14:56:41 +03:00
hreintke
49b76649f1
HardwareSerial bugfix & improvement (#3713)
Co-authored-by: Me No Dev <me-no-dev@users.noreply.github.com>
2020-05-05 17:55:58 +03:00
hreintke
ed220bd042 Minimize HardwareSerial Receive and Transmit delays (#3664)
* Minimize HardwareSerial Receive and Transmit delays

* Remove uartRxFifoToQueue from esp-hal-uart.h

Co-authored-by: Me No Dev <me-no-dev@users.noreply.github.com>
2020-01-27 00:38:06 +02:00
chuck todd
9ad860758c Fix Memory leak in addApbChangeCallback() (#3560)
* `ledcWriteTone()` added a `apbcallback()` evertime the tone value was non zero.  
* `addApbChangeCallback()` did not detect duplicate callbacks.
* changed the apbcallback list to a double link to support roll forward, roll back execution.  This made the sequences of clock change callback start with the newest registered -> to oldest on the `before` then oldest -> newest after the clock change.  This made the UART debug log output have minimal gibberish during the clock change.
* change how the UART callback handled the MUTEX because if any `apbchangeCallback()` executed a `log_x()` a deadlock would occur.

This fixes #3555
2019-12-30 21:35:29 +02:00
chuck todd
7d2632c024 Implement Tx only Flush (#3433)
* add option to Flush() to only clear txQueue

Add the option to cause Flush() to just wait for tx data to clear the tx fifo and uart, leave the rx queue and rx fifo as is.

* support tx only flush()

* support tx only Flush()

* support txOnly for Flush()

* compatibility to Stream()

* compatibility for Stream()

* default value error

* default value error

* Update esp32-hal-uart.h

* Update esp32-hal-uart.c

* Update HardwareSerial.cpp

* sp

* correctly implement flushTxOnly()
2019-11-11 15:37:35 +01:00
Jeroen88
f71a4bd406 Bugfix/detect baudrate (#3188)
* Expose uartStartDetectBaudrate(uart_t *) in esp32-hal-uart.h and call it from HardwareSerial::begin() if baudrate detection is requested (by passing a baudrate of 0) to solve baudrate detection problems

* Avoid a division by zero error in uartGetBaudRate()
2019-09-09 00:59:32 +03:00
Roman Savrulin
03066e42ef Flush UART RX queue too (#3009) 2019-08-20 16:48:52 +03:00
Mike Dunston
f3c1a91f8e adding uartRxActive to expose the RX state machine status as a boolean value (#2457) 2019-03-03 15:47:24 +01:00
me-no-dev
70656aa129 fix leak in log_printf 2019-01-09 21:37:31 +01:00
Me No Dev
2fd39b1aff
Handle APB frequency change (#2250)
* Add APB change callbacks and move cpu code to own file

* Properly set esp_timer and FreeRTOS tick dividers

* Improve updated devisors

* No need to update REF_TICK yet

* Add initial handling for UART baud change

* fix uartWriteBuf and uartDetectBaudrate

* trigger callbacks even when APB did not change

* toggle UART ISR on CPU change

* add XTAL freq getter and add cpu freq validation

* Support CPU frequency changes in I2C (#2287)

**esp32-hal-i2c.c**
* add callback for cpu frequency changes
* adjust fifo thresholds based on cpu frequency and i2c bus frequency
* reduce i2c bus frequency if differential is too small
**Wire.h**
* version to 1.1.0

* Implement clock change for the other peripherals

* remove bad CPU clock values from the menu

* Add note to CPU freqs that support WiFi and BT
2019-01-09 10:07:54 +01:00
atanisoft
4f9a90fa0e fix #2232 and #2033 (#2233) 2018-12-23 19:06:43 +02:00
Me No Dev
c827bb4177
CPU and APB Frequency support (#2220)
* Add support to HAL for APB frequencies different than 80MHz

* Add support for CPU frequencies in the IDE board menu

* Switch to fast set_config

* Add method to uart so debug can be reassigned after apb frequency switch

* Return real APB frequency
2018-12-20 01:57:32 +01:00
Bert Melis
44ca2ee976 Fix uart TX flushing (#2029)
wait for FSM to return idle
2018-11-19 17:04:05 +01:00
Jeroen88
233d31bed2 Added baudrate detection to esp32-hal-uart and HardwareSerial (#1961)
* Added baudrate detection to esp32-hal-uart and HardwareSerial

* Solved compiler warning for uartResizeRxBuffer()

* Add unit to header variable name (timeout_ms)

* Reverting accidentally changed files to master

* Add small delay after baudrate detection
2018-11-19 16:51:55 +01:00
Baruch Nissenbaum
a6a9a518a7 _uart_isr use wr_addr != rd_addr as test for internal queue not empty (#1849) 2018-09-17 21:19:51 +02:00
Adam Coddington
ce61074802 Add functionality allowing rxBuffer of HardwareSerial to be changed in size via HardwareSerial::setRxBufferSize. (#1855) 2018-09-17 21:16:18 +02:00
chemicstry
12ca9e8b52 Port UART reset fix from ESP-IDF (#1408) 2018-07-03 17:54:08 +02:00
mtabu
aa1288aa6e HardwareSerial - availableForWrite() support (#1226)
* HardwareSerial - availableForWrite() support

* fix indentation errors (tab vs space)
2018-04-06 19:07:46 +03:00
me-no-dev
db77195404 Fix Serial 2017-09-27 13:50:05 +08:00
me-no-dev
e2bd93c092 Fix UART0 not able to read/available 2017-09-22 14:17:25 +08:00
me-no-dev
59a6800cdf Enable clocks for UART1 and 2
Recent change in IDF disables those clocks at boot. This change should
help with that.

Fixes: https://github.com/espressif/esp-idf/issues/975
2017-09-10 20:24:41 +03:00
me-no-dev
77b03472c6 Set uart queue to NULL after free
Fixes: https://github.com/espressif/arduino-esp32/issues/435
2017-08-17 19:04:20 +03:00
Pranav Cherukupalli
41e36a72f3 uartEnd: Unlock mutex before detaching rx and tx (#554)
* uartEnd: Unlock mutex before detaching rx and tx

This should solve the device freezing issue when Serial.end() is called

* Unlock UART MUTEX only for detaching Rx and Tx

* Thanks to @me-no-dev for pointing it out that
   uart->dev->conf0.val can be inside mutex lock
2017-08-04 12:00:51 +03:00
me-no-dev
a1bef8b5c3 improve Serial repeated begin/baud change 2017-08-02 00:32:42 +03:00
Claude Heintz
23acb4d17b Two Stop Bit Workaround (#461)
* Update esp32-hal-uart.c

* Two Stop Bit Workaround

see https://github.com/espressif/esp-idf/blob/master/components/driver/uart.c  lines 118-127
2017-06-22 19:40:31 +02:00
me-no-dev
c2f83f48e0 Revert "Fix enable Update partition"
This reverts commit 63e1daa5ea67ce0f9b89b789e4bb26672f64d32e.
2017-06-03 20:11:41 +03:00
me-no-dev
2e5743eaa1 Fix enable Update partition 2017-06-03 20:11:41 +03:00
me-no-dev
4b47402afd Use static buffer for log_printf 2017-05-15 20:53:45 +03:00
me-no-dev
f5d6828c5a Adjust interrupt numbers for GPIO and Touch 2016-12-09 13:22:56 +02:00
me-no-dev
c30012ab78 Add Kconfig for IDF and option to disable HAL mutexes
IDF Options:
- Autostart Arduino (implements app_main)
- Disable HAL locks
- Set HAL debug level
- Auto-connect STA if configured (else will connect after WiFi.begin())
2016-11-18 15:07:25 +02:00
me-no-dev
bfe6e5ae77 optimize log facility for multi threading
- Shorten filenames
- Add log_printf with mutex locking to play nice with Serial and two
cores
2016-11-13 13:40:31 +02:00
me-no-dev
fb8f1244b7 wrong count checked for uartWrite 2016-10-29 14:34:18 +03:00
me-no-dev
6327bbd3e9 do not lock for ets_printf 2016-10-17 15:34:55 +03:00
me-no-dev
242bca9451 Implement thread-safe uart 2016-10-14 03:07:21 +03:00
me-no-dev
17c8ceb1b9 UART rework
many possible problems fixed in preparation for thread-safe
2016-10-14 03:02:40 +03:00
me-no-dev
658f81b792 attach uart isr on the current core 2016-10-11 11:16:43 +03:00