Skip to content

HardwareSerial: fix issue with swapping pins twice #3258

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
12 changes: 6 additions & 6 deletions cores/esp8266/HardwareSerial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ HardwareSerial::HardwareSerial(int uart_nr)
: _uart_nr(uart_nr), _rx_size(256)
{}

void HardwareSerial::begin(unsigned long baud, SerialConfig config, SerialMode mode, uint8_t tx_pin)
void HardwareSerial::begin(unsigned long baud, SerialConfig config, SerialMode mode, int tx_pin, int rx_pin)
{
end();
_uart = uart_init(_uart_nr, baud, (int) config, (int) mode, tx_pin, _rx_size);
_uart = uart_init(_uart_nr, baud, (int) config, (int) mode, tx_pin, rx_pin, _rx_size);
}

void HardwareSerial::end()
Expand All @@ -62,23 +62,23 @@ size_t HardwareSerial::setRxBufferSize(size_t size){
return _rx_size;
}

void HardwareSerial::swap(uint8_t tx_pin)
void HardwareSerial::swap()
{
if(!_uart) {
return;
}
uart_swap(_uart, tx_pin);
uart_swap(_uart);
}

void HardwareSerial::set_tx(uint8_t tx_pin)
void HardwareSerial::set_tx(int tx_pin)
{
if(!_uart) {
return;
}
uart_set_tx(_uart, tx_pin);
}

void HardwareSerial::pins(uint8_t tx, uint8_t rx)
void HardwareSerial::pins(int tx, int rx)
{
if(!_uart) {
return;
Expand Down
20 changes: 8 additions & 12 deletions cores/esp8266/HardwareSerial.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,40 +72,36 @@ class HardwareSerial: public Stream

void begin(unsigned long baud)
{
begin(baud, SERIAL_8N1, SERIAL_FULL, 1);
begin(baud, SERIAL_8N1, SERIAL_FULL, -1, -1);
}
void begin(unsigned long baud, SerialConfig config)
{
begin(baud, config, SERIAL_FULL, 1);
begin(baud, config, SERIAL_FULL, -1, -1);
}
void begin(unsigned long baud, SerialConfig config, SerialMode mode)
{
begin(baud, config, mode, 1);
begin(baud, config, mode, -1, -1);
}

void begin(unsigned long baud, SerialConfig config, SerialMode mode, uint8_t tx_pin);
void begin(unsigned long baud, SerialConfig config, SerialMode mode, int tx_pin, int rx_pin);

void end();

size_t setRxBufferSize(size_t size);

void swap()
{
swap(1);
}
void swap(uint8_t tx_pin); //toggle between use of GPIO13/GPIO15 or GPIO3/GPIO(1/2) as RX and TX
void swap(); //toggle between use of GPIO13/GPIO15 or GPIO3/GPIO1 as RX and TX

/*
* Toggle between use of GPIO1 and GPIO2 as TX on UART 0.
* Set TX pin. On UART0, either GPIO1 or GPIO2 can be used.
* Note: UART 1 can't be used if GPIO2 is used with UART 0!
*/
void set_tx(uint8_t tx_pin);
void set_tx(int tx_pin);

/*
* UART 0 possible options are (1, 3), (2, 3) or (15, 13)
* UART 1 allows only TX on 2 if UART 0 is not (2, 3)
*/
void pins(uint8_t tx, uint8_t rx);
void pins(int tx, int rx);

int available(void) override;
int peek(void) override;
Expand Down
7 changes: 3 additions & 4 deletions cores/esp8266/core_esp8266_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,20 +147,19 @@ extern "C" void __gdb_do_break(){}
extern "C" void gdb_do_break(void) __attribute__ ((weak, alias("__gdb_do_break")));

void init_done() {
system_set_os_print(1);
gdb_init();
do_global_ctors();
printf("\n%08x\n", core_version);
esp_schedule();
}

extern "C" void uart0_wait_tx_empty();

extern "C" void user_init(void) {
struct rst_info *rtc_info_ptr = system_get_rst_info();
memcpy((void *) &resetInfo, (void *) rtc_info_ptr, sizeof(resetInfo));

uart0_wait_tx_empty();
uart_div_modify(0, UART_CLK_FREQ / (115200));

init();

initVariant();
Expand Down
Loading