Commit graph

37 commits

Author SHA1 Message Date
Earle F. Philhower, III
e05dd50d62
Convert to SDK RP2350A/B determination (#2898)
* Convert to SDK RP2350A/B determination

Fixes #2878

The SDK uses `defined(PICO_RP2350) && !PICO_RP2350A` to indicate an RP2350B
chip, not the define PICO_RP2350B.

Match the SDK's usage by converting from `defined(PICO_RP2350B)` to
`defined(PICO_RP2350) && !PICO_RP2350A` and update the chip variants
accordingly.

* Need to explicitly override PICO_RP2350A for all

The *SDK*'s board definition file hardcodes a PICO_RP2350A value for
all boards, but we use the same board file for both A and B variants.
Override the SDK board definition in the variant definition file.

* Generic RP2350 needs 2-stage PICO_RP2350A setting

Also ensure SDK board definition included before pins_arduino.h for
clearing up redefinition errors.

* Factor out undef PICO_RP2350A

* Update Arduino.h
2025-04-08 16:02:54 -07:00
Earle F. Philhower, III
5bfc35caf5
Enable add'l UART_AUX pinouts for RP2350 (#2837)
Fixes #2835.  Thanks @deltaford!
2025-03-05 07:02:32 -08:00
Earle F. Philhower, III
1f291482cd Fix SerialUART RP2350B define checks
Fixes #2460
2024-09-16 09:27:08 -07:00
Earle F. Philhower, III
76811d3c66
Add RP2350B generic/Pimoroni PGA2350 support (#2433)
* Add support for the extra 16 GPIO pins in the menus and core.
* Clean up Generic RP2350 PSRAM ("none" is valid) and flash (other than 16MB) options.
* Add extra GPIO<->peripheral connections
* Add Pimoroni PGA2350 RP2350B-based board
* Pins 32-47 can be used for PIOPrograms
* Avoid hang when PSRAM fails to initialize
* Move libpico to an RP2350B board for SDK (otherwise the SDK drops all GPIOHI support)
2024-09-11 18:55:28 -07:00
Earle F. Philhower, III
226a318897
Add serial inversion for UART and SerialPIO (#2395)
Use real GPIO pad inversion to allow inverted RX, TX, and controls for
the hardware UART and software PIO-emulated serial ports.

Adds ``setInvertTX(bool)`` and ``setInvertRX(bool)`` calls to both ports,
with ``setInvertControl(bool)`` for the HW UARTS.
2024-08-31 07:46:11 -07:00
Earle F. Philhower, III
a8d1067125
Unswap CTS/RTS enable on SeriaUART (#2052)
Fixes #2047
2024-03-10 13:23:33 -07:00
Earle F. Philhower, III
456b474a48
Allow re-setting identical pins without panic() (#1655)
Setting a pin to the current value is a no-op, not fatal.

Fixes #1652
2023-08-21 08:52:49 -07:00
Earle F. Philhower, III
b400897ca2
Avoid initial glitch on Serial1/2 when RX high (#1154)
Fixes #1153

Set up the GPIO redirects before the UART is pulled from reset to avoid
a possible bad byte at `Serial1/2.begin()`.
2023-02-01 19:15:58 -08:00
Earle F. Philhower, III
ecaa2bd778
Fix SerialUART::overflow reporting race condition (#1133)
Fixes #1132
2023-01-21 01:38:15 -08:00
Gavin Hurlbut
9a241b0e43
Add Serial UART break reporting (#1130)
Added SerialUART::getBreakReceived()
2023-01-20 16:54:31 -08:00
Earle F. Philhower, III
80d6e2f0ec
Throw away UART bytes with errors in reception (#1036)
Fixes #1021

The UART hardware will push characters into the receive FIFO even if there
are parity, framing, or other errors.  These are invalid and shouldn't be
returned to the application, so drop them if errors detected.

This will also avoid the glitch-induced initial garbage character.
2022-12-09 12:30:52 -08:00
Earle F. Philhower, III
0cd5b0ac47
Allow setCTS/RTS(UART_PIN_NOT_DEFINED) (#881)
Fixes #880
2022-09-26 08:13:44 -07:00
Earle F. Philhower, III
85d39cf242
Restore GPIO functions on SerialUART::end (#836)
Fix #834
2022-09-04 19:23:51 -07:00
Earle F. Philhower, III
cabb06d495
Fix UART wrong ::available() during wraparound (#739)
Fixes #735 .  Thanks to @ Haggarman for the find and fix.
2022-08-06 09:38:16 -07:00
Earle F. Philhower, III
10b869ef30
Fix XIAO RP2040, allow swapping HW units 0/1 (#606)
Add plumbing to allow `Wire`, `Serial1`, `SPI1` to map to the 2nd
hardware unit for devices where the PCB layout only brings out the
2nd port.

Fix the Seeedstudio XAIO pins

Fixes #594
2022-06-04 21:37:28 -07:00
Earle F. Philhower, III
3ee031abc9
Add ::overflow() return to SerialUART/SerialPIO (#547)
Matching the Arduino SoftwareSerial API
2022-04-24 14:44:23 -07:00
Earle F. Philhower, III
061b38f0b8
Add RTS/CTS to Arduino Nano Connect Serial2(NINA) (#525)
Fixes #524
2022-03-30 14:12:24 -07:00
Earle F. Philhower, III
53043830e7
Avoid "chunkiness" of UART FIFO availability (#511)
* Avoid "chunkiness" of UART FIFO availability

The UART FIFO will generate an IRQ to transfer data into the SerialUART
FIFOs either every 4 received bytes, or every 4 idle byte times.  This
causes the ::available count to report "0" until either of those two
cases happen, causing a potentially delay in data becoming available to
the app.

Change the code to pull data from the HW FIFO on a read/available/peek.
Use a non-blocking mutex and IRQ disabling to safely empty the FIFO from
user space.  The mutex added to the IRQ is non-blocking and will be
a single CAS the vast majority of the time, so it should not impact the
Serial performance.

Fixes #464 and others where `setPollingMode()` was needed as a workaround.

Make sure we have all mutexes locked before we disable the port and free
the queue to avoid evil cases.

Only init the mutexes once, on object creation.

In polled mode, don't bother acquiring/releasing the fifo mutex.

When begin() is called on an already running port, call end() to clean
up the old data/etc. before making a new queue/config.  This avoids a
memory leak and potential write-after-free case.
2022-03-16 08:46:20 -07:00
Pontus Oldberg
f8e8a7b72e
Updating LoRa board pins and UART hw flow. (#499)
* Added missing SERIAL2 and LoRa module GIO pins.
* Added support for enabling UART CTS and RTS pins.
2022-02-22 01:45:24 -08:00
Earle F. Philhower, III
44cd697b29
Add SerialUART::setPollingMode() (#473)
Fixes #472

Instead of using interrupts, explicitly call the IRQ handler dueing Serial
read/peek/available calls.

Add to keywords.txt for syntax hilighting.

Add poll calls in the SerialUART::write-like calls (write,
flush, etc.)

Really remove division from IRQ routines/
2022-02-10 12:22:27 -08:00
Earle F. Philhower, III
ba92377eba
Decrease size of used FIFO in SerialUART (#471)
Fixes #468

The FIFO limit was set to 1/2, or 16 bytes on POR and not set by the core,
so for low baud this could result in a LONG time without data moving from
hardware FIFO to the SW ring buffer and timeouts/etc.

Now use the API call which sets it to 1/8, or 4 bytes of data to speed up
the transfer 4x.

Also avoid using the divider in the IRQ routine because it is not clear
from the docs of the Pico SDK IRQ callback routine preserves divider
state or not.  If not, doing division in an IRQ could result in random
data corruption in the main app.

Add memory barriers to ensure the order of data into RAM is preserved
and that GCC doesn't reorder writes.
2022-02-08 12:14:40 -08:00
Earle F. Philhower, III
4cd65d1512
Remove timeout for SerialUART/SerialPIO::read/peek (#466)
Fixes #464 and other incompatibilities

Remove the timeout check from ::read and ::peek on the SerialUART/PIO
classes  (SerialUSB already ignores it).  See documentation
https://www.arduino.cc/reference/en/language/functions/communication/serial/settimeout/
and thanks to @jandrassy's explanation
https://github.com/earlephilhower/arduino-pico/issues/464#issuecomment-1031657044
2022-02-07 12:33:49 -08:00
Earle F. Philhower, III
576f8941d6
Add setFIFOSize to UART Serial ports (#410)
Allow setting the size of the receive buffer by the application using a
call to Serial1/2.setFIFOSize(xxx) before the begin() call.
2022-01-04 19:02:38 -08:00
Earle F. Philhower, III
3a2a7f8cf1
Fix hang on Serial overflow, PIOSerial stop bit handling (#401)
When the Serial software FIFOs overeflowed, the IRQ handler would not
read any more data from the hardware FIFOs.  This would cause the
IRQ handler to be continually called as soon as it exited since the
HW FIFOS were not empty.

Now always read every available HW FIFO entry and throw out any that
don't fit in the SW FIFO.

Also fix a too long by half stop bit timing in the PIOSerial receiver.
2022-01-02 05:46:33 -08:00
Earle F. Philhower, III
dc1198bd9c
Use interrupts to capture Serial UART data, not polling (#393)
PR #379 was an ugly hack which works only if you poll the Serial port more
frequently than ~8 byte times.

This PR replaces the polling with an IRQ based lockless writer/reader queue
so that even if you only read every 32 byte times, the Serial1/2 port should
not lose data.  It also should use less CPU and allow for somewhat higher
throughput.
2021-12-28 08:21:03 -08:00
Earle F. Philhower, III
a58f49018a
Add a poor-man's software FIFO for serial UART reads (#379)
Because the hardware FIFO is quite small and doesn't report the actual number
of bytes available, implement a software FIFO that will pull all available
bytes out of the HW FIFO on any Serial call.  It's not as efficient or as
bulletproof as an IRQ based method, but it is simpler to implement and can
help with issues like #378
2021-12-23 07:41:34 -08:00
Earle F. Philhower, III
27476815ab
Fix SerialUART flush (#215)
Serial1.flush/Serial2.flush was not waiting for the proper FIFO to clear.
Use the proper call from the Pico SDK.

Thanks to Peter Remias for noting it.
2021-06-16 08:25:24 -07:00
Earle F. Philhower, III
30704a7c5e
Obey timeout value on SerialUART.read/.peek (#211)
Fixes a hang when reading from the Serial UART ports because before the
core would pause indefinitely for the next character.

Now, wait up to Serial.setTimeout() milliseconds and if it times out
return -1 to the app.

Fixes #210
2021-06-13 14:11:23 -07:00
Earle F. Philhower, III
fd685aac82
PANIC on attempting an invalid setXXX pin (#182)
Fixes #169

Trying to change pinout while running, or to an illegal configuration,
will now immediately panic() with an error message.  Such an attempt
is a pretty big problem since pinouts are hardware related/static.

Prior code would fail silently and return false, but nobody checked
the setXXX return values, anyway.
2021-05-29 10:50:13 -07:00
Earle F. Philhower, III
8016a932f3
Add astyle format, boards.txt, and package check (#166)
Miscellaneous CI checks for code style, boards.txt update, and that all
referenced packages are available.
2021-05-24 15:01:03 -07:00
Earle F. Philhower, III
6e51516d6c
Set default pins for peripherals per datasheet (#103)
Using the official Raspberry Pi Pico datasheet and the Adafruit Feather
RP2040 schematic, set the default pins for peripherals to match.

Fixes #92
2021-04-16 10:23:43 -07:00
Earle F. Philhower, III
c988c1c8a4 Add debug prints on error conditions to the core 2021-03-30 18:17:52 -07:00
Earle F. Philhower, III
09ec5e0d22 Refactor USB/UART mutexes, code cleanup, CoreMutex addition
Add a CoreMutex class which implements a deadlock-safe mutex and reqork
the SerialUSB and SerialUART classes to use it to synchronize output
when in a multicore sketch.
2021-03-27 09:41:23 -07:00
Earle F. Philhower, III
b463825374 Rationalize pin selection using readable template
Use a constexpr template to calculate the valid pins for different IO
hardware.  This lets us have an easily readable list of pin numbers that
we can adjust/check.
2021-03-25 17:54:46 -07:00
Earle F. Philhower, III
c4bbccdead Add serialEvent support for USB, UART0, UART1 2021-03-25 12:42:05 -07:00
Earle F. Philhower, III
25d351f404 Remove PIO global headers from UART object 2021-03-20 20:17:08 -07:00
Earle F. Philhower, III
f6fcfd147b Add hardware Serial UARTs 2021-03-13 10:24:18 -08:00