Skip to content

Commit fc7012f

Browse files
Undo much of UART refactoring, set fifo IRQ to 16
Remove the refactoring of pin control and other little things not directly related to GDB processing. Should greatly reduce the diff size in uart.c. Should also remove any register value changes (intended or otherwise) introduced in the original PR from @kylefleming. Set the FIFO interrupt to 16 chars when in GDB mode, matching the latest UART configuration for highest speed.
1 parent 0e2adcb commit fc7012f

File tree

2 files changed

+80
-81
lines changed

2 files changed

+80
-81
lines changed

cores/esp8266/uart.c

Lines changed: 75 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ uart_get_rx_buffer_size(uart_t* uart)
300300
}
301301

302302

303-
static void ICACHE_RAM_ATTR
303+
void ICACHE_RAM_ATTR
304304
uart_isr(void * arg)
305305
{
306306
uart_t* uart = (uart_t*)arg;
@@ -411,9 +411,9 @@ uart_do_write_char(const int uart_nr, char c)
411411
size_t
412412
uart_write_char(uart_t* uart, char c)
413413
{
414-
if(uart == NULL || !uart->tx_enabled) {
414+
if(uart == NULL || !uart->tx_enabled)
415415
return 0;
416-
}
416+
417417
if(gdbstub_has_uart_isr_control() && uart->uart_nr == UART0) {
418418
gdbstub_write_char(c);
419419
return 1;
@@ -506,43 +506,6 @@ uart_get_baudrate(uart_t* uart)
506506
return uart->baud_rate;
507507
}
508508

509-
void uart0_enable_tx_pin(uint8_t pin)
510-
{
511-
switch(pin) {
512-
case 1:
513-
pinMode(pin, SPECIAL);
514-
break;
515-
case 2:
516-
case 15:
517-
pinMode(pin, FUNCTION_4);
518-
break;
519-
}
520-
}
521-
522-
void uart0_enable_rx_pin(uint8_t pin)
523-
{
524-
switch(pin) {
525-
case 3:
526-
pinMode(pin, SPECIAL);
527-
break;
528-
case 13:
529-
pinMode(pin, FUNCTION_4);
530-
break;
531-
}
532-
}
533-
534-
void uart1_enable_tx_pin(uint8_t pin)
535-
{
536-
if(pin == 2) {
537-
pinMode(pin, SPECIAL);
538-
}
539-
}
540-
541-
void uart_disable_pin(uint8_t pin)
542-
{
543-
pinMode(pin, INPUT);
544-
}
545-
546509
uart_t*
547510
uart_init(int uart_nr, int baudrate, int config, int mode, int tx_pin, size_t rx_size)
548511
{
@@ -583,16 +546,20 @@ uart_init(int uart_nr, int baudrate, int config, int mode, int tx_pin, size_t rx
583546
return NULL;
584547
}
585548
uart->rx_buffer = rx_buffer;
586-
uart0_enable_rx_pin(uart->rx_pin);
549+
pinMode(uart->rx_pin, SPECIAL);
587550
}
588551
if(uart->tx_enabled)
589552
{
590-
if (tx_pin == 2) {
591-
uart->tx_pin = 2;
592-
} else {
593-
uart->tx_pin = 1;
594-
}
595-
uart0_enable_tx_pin(uart->tx_pin);
553+
if (tx_pin == 2)
554+
{
555+
uart->tx_pin = 2;
556+
pinMode(uart->tx_pin, FUNCTION_4);
557+
}
558+
else
559+
{
560+
uart->tx_pin = 1;
561+
pinMode(uart->tx_pin, FUNCTION_0);
562+
}
596563
}
597564
else
598565
{
@@ -646,14 +613,33 @@ uart_uninit(uart_t* uart)
646613
return;
647614

648615
if(uart->tx_enabled && (!gdbstub_has_uart_isr_control() || uart->uart_nr != UART0)) {
649-
uart_disable_pin(uart->tx_pin);
616+
switch(uart->tx_pin)
617+
{
618+
case 1:
619+
pinMode(1, INPUT);
620+
break;
621+
case 2:
622+
pinMode(2, INPUT);
623+
break;
624+
case 15:
625+
pinMode(15, INPUT);
626+
break;
627+
}
650628
}
651629

652630
if(uart->rx_enabled) {
653631
free(uart->rx_buffer->buffer);
654632
free(uart->rx_buffer);
655633
if(!gdbstub_has_uart_isr_control()) {
656-
uart_disable_pin(uart->rx_pin);
634+
switch(uart->rx_pin)
635+
{
636+
case 3:
637+
pinMode(3, INPUT);
638+
break;
639+
case 13:
640+
pinMode(13, INPUT);
641+
break;
642+
}
657643
uart_stop_isr(uart);
658644
}
659645
}
@@ -669,39 +655,46 @@ uart_swap(uart_t* uart, int tx_pin)
669655
switch(uart->uart_nr)
670656
{
671657
case UART0:
672-
if(uart->tx_enabled) { //TX
673-
uart_disable_pin(uart->tx_pin);
674-
}
675-
if(uart->rx_enabled) { //RX
676-
uart_disable_pin(uart->rx_pin);
677-
}
678-
679-
if(((uart->tx_pin == 1 || uart->tx_pin == 2) && uart->tx_enabled)
680-
|| (uart->rx_pin == 3 && uart->rx_enabled)) {
681-
if(uart->tx_enabled) { //TX
658+
if(((uart->tx_pin == 1 || uart->tx_pin == 2) && uart->tx_enabled) || (uart->rx_pin == 3 && uart->rx_enabled))
659+
{
660+
if(uart->tx_enabled) //TX
661+
{
662+
pinMode(uart->tx_pin, INPUT);
682663
uart->tx_pin = 15;
683664
}
684-
if(uart->rx_enabled) { //RX
665+
if(uart->rx_enabled) //RX
666+
{
667+
pinMode(uart->rx_pin, INPUT);
685668
uart->rx_pin = 13;
686669
}
670+
if(uart->tx_enabled)
671+
pinMode(uart->tx_pin, FUNCTION_4); //TX
672+
673+
if(uart->rx_enabled)
674+
pinMode(uart->rx_pin, FUNCTION_4); //RX
675+
687676
IOSWAP |= (1 << IOSWAPU0);
688-
} else {
689-
if(uart->tx_enabled) { //TX
677+
}
678+
else
679+
{
680+
if(uart->tx_enabled) //TX
681+
{
682+
pinMode(uart->tx_pin, INPUT);
690683
uart->tx_pin = (tx_pin == 2)?2:1;
691684
}
692-
if(uart->rx_enabled) { //RX
685+
if(uart->rx_enabled) //RX
686+
{
687+
pinMode(uart->rx_pin, INPUT);
693688
uart->rx_pin = 3;
694689
}
695-
IOSWAP &= ~(1 << IOSWAPU0);
696-
}
690+
if(uart->tx_enabled)
691+
pinMode(uart->tx_pin, (tx_pin == 2)?FUNCTION_4:SPECIAL); //TX
697692

698-
if(uart->tx_enabled) { //TX
699-
uart0_enable_tx_pin(uart->tx_pin);
700-
}
701-
if(uart->rx_enabled) { //RX
702-
uart0_enable_rx_pin(uart->rx_pin);
703-
}
693+
if(uart->rx_enabled)
694+
pinMode(3, SPECIAL); //RX
704695

696+
IOSWAP &= ~(1 << IOSWAPU0);
697+
}
705698
break;
706699
case UART1:
707700
// Currently no swap possible! See GPIO pins used by UART
@@ -720,15 +713,19 @@ uart_set_tx(uart_t* uart, int tx_pin)
720713
switch(uart->uart_nr)
721714
{
722715
case UART0:
723-
if(uart->tx_enabled) {
724-
if (uart->tx_pin == 1 && tx_pin == 2) {
725-
uart_disable_pin(uart->tx_pin);
716+
if(uart->tx_enabled)
717+
{
718+
if (uart->tx_pin == 1 && tx_pin == 2)
719+
{
720+
pinMode(uart->tx_pin, INPUT);
726721
uart->tx_pin = 2;
727-
uart0_enable_tx_pin(uart->tx_pin);
728-
} else if (uart->tx_pin == 2 && tx_pin != 2) {
729-
uart_disable_pin(uart->tx_pin);
722+
pinMode(uart->tx_pin, FUNCTION_4);
723+
}
724+
else if (uart->tx_pin == 2 && tx_pin != 2)
725+
{
726+
pinMode(uart->tx_pin, INPUT);
730727
uart->tx_pin = 1;
731-
uart0_enable_tx_pin(uart->tx_pin);
728+
pinMode(uart->tx_pin, SPECIAL);
732729
}
733730
}
734731

libraries/GDBStub/src/internal/gdbstub.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include <GDBStub.h>
1111
#include <stddef.h>
12+
#include <Arduino.h>
1213
#include "ets_sys.h"
1314
#include "eagle_soc.h"
1415
#include "c_types.h"
@@ -781,8 +782,9 @@ static void ATTR_GDBINIT configure_uart() {}
781782
static void ATTR_GDBINIT configure_uart() {
782783

783784
#ifdef ARDUINO
784-
uart0_enable_tx_pin(1);
785-
uart0_enable_rx_pin(3);
785+
// Set the UART input/output pins to TX=1, RX=3
786+
pinMode(3, SPECIAL);
787+
pinMode(1, FUNCTION_0);
786788
#endif
787789

788790
WRITE_PERI_REG(UART_CONF0(0), 0b00011100); //8N1
@@ -875,7 +877,7 @@ static void ATTR_GDBINIT install_uart_hdlr() {
875877
configure_uart();
876878

877879
WRITE_PERI_REG(UART_CONF1(0),
878-
((100 & UART_RXFIFO_FULL_THRHD) << UART_RXFIFO_FULL_THRHD_S) |
880+
((16 & UART_RXFIFO_FULL_THRHD) << UART_RXFIFO_FULL_THRHD_S) |
879881
((0x02 & UART_RX_TOUT_THRHD) << UART_RX_TOUT_THRHD_S) |
880882
UART_RX_TOUT_EN);
881883

0 commit comments

Comments
 (0)