Skip to content

esp32/machine_uart: Change sendbreak() implementation to simply pull the pin low for the break period #17698

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
19 changes: 10 additions & 9 deletions ports/esp32/machine_uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -508,20 +508,21 @@ static bool mp_machine_uart_txdone(machine_uart_obj_t *self) {
}

static void mp_machine_uart_sendbreak(machine_uart_obj_t *self) {
// Save settings
// Calculate the length of the break, as 13 bits.
uint32_t baudrate;
check_esp_err(uart_get_baudrate(self->uart_num, &baudrate));
uint32_t break_delay_us = 13000000 / baudrate;

// Synthesise the break condition by reducing the baud rate,
// and cater for the worst case of 5 data bits, no parity.
check_esp_err(uart_wait_tx_done(self->uart_num, pdMS_TO_TICKS(1000)));
check_esp_err(uart_set_baudrate(self->uart_num, baudrate * 6 / 15));
char buf[1] = {0};
uart_write_bytes(self->uart_num, buf, 1);
// Wait for any outstanding data to be transmitted.
check_esp_err(uart_wait_tx_done(self->uart_num, pdMS_TO_TICKS(1000)));

// Restore original setting
check_esp_err(uart_set_baudrate(self->uart_num, baudrate));
// Set the TX pin to output, pull it low, and wait for the break period.
mp_hal_pin_output(self->tx);
mp_hal_pin_write(self->tx, 0);
mp_hal_delay_us(break_delay_us);

// Restore original UART pin settings.
check_esp_err(uart_set_pin(self->uart_num, self->tx, self->rx, self->rts, self->cts));
}

// Configure the timer used for IRQ_RXIDLE
Expand Down
34 changes: 12 additions & 22 deletions tests/extmod_hardware/machine_uart_irq_break.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,13 @@
if "ESP32S2" in _machine or "ESP32C3" in _machine or "ESP32C6" in _machine:
print("SKIP")
raise SystemExit
# ESP32 needs separate UART instances for the test
recv_uart_id = 1
recv_tx_pin = 14
recv_rx_pin = 5
send_uart_id = 2
send_tx_pin = 4
send_rx_pin = 12
uart_id = 1
tx_pin = 4
rx_pin = 5
elif "rp2" in sys.platform:
recv_uart_id = 0
send_uart_id = 0
recv_tx_pin = "GPIO0"
recv_rx_pin = "GPIO1"
uart_id = 0
tx_pin = "GPIO0"
rx_pin = "GPIO1"
else:
print("Please add support for this test on this platform.")
raise SystemExit
Expand All @@ -42,22 +37,17 @@ def irq(u):

# Test that the IRQ is called for each break received.
for bits_per_s in (2400, 9600, 57600):
recv_uart = UART(recv_uart_id, bits_per_s, tx=recv_tx_pin, rx=recv_rx_pin)
if recv_uart_id != send_uart_id:
send_uart = UART(send_uart_id, bits_per_s, tx=send_tx_pin, rx=send_rx_pin)
else:
send_uart = recv_uart

recv_uart.irq(irq, recv_uart.IRQ_BREAK)
uart = UART(uart_id, bits_per_s, tx=tx_pin, rx=rx_pin)
uart.irq(irq, uart.IRQ_BREAK)

print("write", bits_per_s)
for i in range(3):
send_uart.write(str(i))
send_uart.flush()
uart.write(str(i))
uart.flush()
time.sleep_ms(10)
send_uart.sendbreak()
uart.sendbreak()
time.sleep_ms(10)
if "esp32" in sys.platform:
# On esp32 a read is needed to read in the break byte.
recv_uart.read()
uart.read()
print("done")
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy