Skip to content

Commit 888a0c5

Browse files
authored
Merge pull request #4224 from microDev1/busio-uart-rp
RP2040: Support for UART
2 parents 2e6e91d + 7562b0c commit 888a0c5

File tree

12 files changed

+292
-348
lines changed

12 files changed

+292
-348
lines changed

locale/circuitpython.pot

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@ msgid "All SPI peripherals are in use"
333333
msgstr ""
334334

335335
#: ports/esp32s2/common-hal/busio/UART.c ports/nrf/common-hal/busio/UART.c
336+
#: ports/raspberrypi/common-hal/busio/UART.c
336337
msgid "All UART peripherals are in use"
337338
msgstr ""
338339

@@ -952,6 +953,7 @@ msgid "Failed to acquire mutex, err 0x%04x"
952953
msgstr ""
953954

954955
#: ports/mimxrt10xx/common-hal/busio/UART.c ports/nrf/common-hal/busio/UART.c
956+
#: ports/raspberrypi/common-hal/busio/UART.c
955957
msgid "Failed to allocate RX buffer"
956958
msgstr ""
957959

@@ -1219,7 +1221,8 @@ msgstr ""
12191221
msgid "Invalid bits per value"
12201222
msgstr ""
12211223

1222-
#: ports/nrf/common-hal/busio/UART.c ports/stm/common-hal/busio/UART.c
1224+
#: ports/nrf/common-hal/busio/UART.c ports/raspberrypi/common-hal/busio/UART.c
1225+
#: ports/stm/common-hal/busio/UART.c
12231226
msgid "Invalid buffer size"
12241227
msgstr ""
12251228

@@ -1294,10 +1297,10 @@ msgstr ""
12941297
#: ports/esp32s2/common-hal/busio/I2C.c ports/esp32s2/common-hal/busio/SPI.c
12951298
#: ports/esp32s2/common-hal/busio/UART.c ports/esp32s2/common-hal/canio/CAN.c
12961299
#: ports/mimxrt10xx/common-hal/busio/I2C.c
1297-
#: ports/mimxrt10xx/common-hal/busio/SPI.c
1298-
#: ports/mimxrt10xx/common-hal/busio/UART.c ports/nrf/common-hal/busio/I2C.c
1300+
#: ports/mimxrt10xx/common-hal/busio/SPI.c ports/nrf/common-hal/busio/I2C.c
12991301
#: ports/raspberrypi/common-hal/busio/I2C.c
13001302
#: ports/raspberrypi/common-hal/busio/SPI.c
1303+
#: ports/raspberrypi/common-hal/busio/UART.c
13011304
msgid "Invalid pins"
13021305
msgstr ""
13031306

@@ -1346,7 +1349,8 @@ msgstr ""
13461349
msgid "Invalid wave file"
13471350
msgstr ""
13481351

1349-
#: ports/stm/common-hal/busio/UART.c
1352+
#: ports/mimxrt10xx/common-hal/busio/UART.c ports/nrf/common-hal/busio/UART.c
1353+
#: ports/raspberrypi/common-hal/busio/UART.c ports/stm/common-hal/busio/UART.c
13501354
msgid "Invalid word/bit length"
13511355
msgstr ""
13521356

@@ -1846,7 +1850,7 @@ msgstr ""
18461850
msgid "RNG Init Error"
18471851
msgstr ""
18481852

1849-
#: ports/nrf/common-hal/busio/UART.c
1853+
#: ports/nrf/common-hal/busio/UART.c ports/raspberrypi/common-hal/busio/UART.c
18501854
msgid "RS485 Not yet supported on this device"
18511855
msgstr ""
18521856

@@ -2156,10 +2160,6 @@ msgstr ""
21562160
msgid "UART Re-init error"
21572161
msgstr ""
21582162

2159-
#: ports/raspberrypi/common-hal/busio/UART.c
2160-
msgid "UART not yet supported"
2161-
msgstr ""
2162-
21632163
#: ports/stm/common-hal/busio/UART.c
21642164
msgid "UART write error"
21652165
msgstr ""
@@ -2488,7 +2488,7 @@ msgid "binary op %q not implemented"
24882488
msgstr ""
24892489

24902490
#: shared-bindings/busio/UART.c
2491-
msgid "bits must be 7, 8 or 9"
2491+
msgid "bits must be in range 5 to 9"
24922492
msgstr ""
24932493

24942494
#: shared-bindings/audiomixer/Mixer.c

ports/atmel-samd/boards/catwan_usbstick/mpconfigboard.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@ LONGINT_IMPL = NONE
1111
CIRCUITPY_FULL_BUILD = 0
1212
CIRCUITPY_COUNTIO = 0
1313
CIRCUITPY_ROTARYIO = 0
14+
15+
SUPEROPT_GC = 0

ports/mimxrt10xx/common-hal/busio/UART.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
9393
self->character_bits = bits;
9494
self->timeout_ms = timeout * 1000;
9595

96+
if (self->character_bits != 7 && self->character_bits != 8) {
97+
mp_raise_ValueError(translate("Invalid word/bit length"));
98+
}
99+
96100
// We are transmitting one direction if one pin is NULL and the other isn't.
97101
bool is_onedirection = (rx == NULL) != (tx == NULL);
98102
bool uart_taken = false;
@@ -154,10 +158,6 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
154158
mp_raise_ValueError(translate("Hardware in use, try alternative pins"));
155159
}
156160

157-
if(self->rx == NULL && self->tx == NULL) {
158-
mp_raise_ValueError(translate("Invalid pins"));
159-
}
160-
161161
if (is_onedirection && ((rts != NULL) || (cts != NULL))) {
162162
mp_raise_ValueError(translate("Both RX and TX required for flow control"));
163163
}

ports/nrf/common-hal/busio/UART.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ static uint32_t get_nrf_baud (uint32_t baudrate) {
7070
{ 14400, NRF_UARTE_BAUDRATE_14400 },
7171
{ 19200, NRF_UARTE_BAUDRATE_19200 },
7272
{ 28800, NRF_UARTE_BAUDRATE_28800 },
73-
{ 31250, NRF_UARTE_BAUDRATE_31250 },
73+
{ 31250, NRF_UARTE_BAUDRATE_31250 },
7474
{ 38400, NRF_UARTE_BAUDRATE_38400 },
75-
{ 56000, NRF_UARTE_BAUDRATE_56000 },
75+
{ 56000, NRF_UARTE_BAUDRATE_56000 },
7676
{ 57600, NRF_UARTE_BAUDRATE_57600 },
7777
{ 76800, NRF_UARTE_BAUDRATE_76800 },
7878
{ 115200, NRF_UARTE_BAUDRATE_115200 },
@@ -144,6 +144,10 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
144144
mp_float_t timeout, uint16_t receiver_buffer_size, byte* receiver_buffer,
145145
bool sigint_enabled) {
146146

147+
if (bits != 8) {
148+
mp_raise_ValueError(translate("Invalid word/bit length"));
149+
}
150+
147151
if ((rs485_dir != NULL) || (rs485_invert)) {
148152
mp_raise_ValueError(translate("RS485 Not yet supported on this device"));
149153
}

0 commit comments

Comments
 (0)