-->
Page 1 of 3

Defining Rx-Tx ESP8266_pins to other GPIO_pins in the core ?

PostPosted: Fri Feb 05, 2016 12:46 pm
by costo
My project needs to have GPIO_pins 4&5 reconfigured as RXD/TXD pins and at the same time GPIO_pins 1&3 available as normal I/O pins.
My wish is that if I use any of the Serial communication functions that these are redirected over GPIO_pins 4&5
I guess that flashing the software from the IDE still needs to be done over the original RXD_TXD_pins GPIO 1&3 but that is no problem.

I understand that ESP8266 pins can be (re)configured for any function. So it probably is possible to make a change somewhere in a Arduino_ESP8266 core_file that defines the pins so that the Serial port is mapped to GPIO 4&5 and that GPIO 1&3 can be used as general GPIO especially I want I2C on these pins.

Does someone have a clue for me where I need to look , specially which file ,for these pin_defenitions ?

Re: Defining Rx-Tx ESP8266_pins to other GPIO_pins in the co

PostPosted: Fri Feb 05, 2016 12:53 pm
by martinayotte
If you look at this page wiki/doku.php?id=esp8266_gpio_pin_allocations,
You will see that Rx/Tx simply can NOT be remapped on GPIO4/GPIO5 ...

Re: Defining Rx-Tx ESP8266_pins to other GPIO_pins in the co

PostPosted: Fri Feb 05, 2016 1:25 pm
by costo
On that page I read:
This allows the MTDO and MTCK to be connected to a microcontroller as UART tx/rx. The bootup info will be output via U0TXD pin, but after start-up, the UART0 will output data via MTDO and receive via MTCK.


MTDO = GPIO_15 and MTCK = GPIO_13 so it should be possible to use these pins as UART ?
Meaning that all Serial communication is redirected to these ports if I add this function somewhere ?
#define FUNC_U0CTS 4
#define FUNC_U0RTS 4

void user_init(void) {
PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTCK_U, FUNC_U0CTS);//CONFIG MTCK PIN FUNC TO U0CTS
PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTDO_U, FUNC_U0RTS);//CONFIG MTDO PIN FUNC TO U0RTS
SET_PERI_REG_MASK(0x3ff00028 , BIT2);//SWAP PIN : U0TXD<==>U0RTS(MTDO) , U0RXD<==>U0CTS(MTCK)
......
}


Add this user_init(void) in my existing program ? Or does it need to be added somewhere in the core ?

Re: Defining Rx-Tx ESP8266_pins to other GPIO_pins in the co

PostPosted: Fri Feb 05, 2016 1:42 pm
by martinayotte
Yes, it seems too, but I've never tried it.

user_init() is the main() in plain SDK, so qeuivalent to setup() in Arduino.

So, it should look like that (notice the "extern C" to include the plain C "user_interface.h" from SDK) :

Code: Select allextern "C" {
#include "user_interface.h"
}

void setup() {
PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTCK_U, FUNC_U0CTS);//CONFIG MTCK PIN FUNC TO U0CTS
PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTDO_U, FUNC_U0RTS);//CONFIG MTDO PIN FUNC TO U0RTS
SET_PERI_REG_MASK(0x3ff00028 , BIT2);//SWAP PIN : U0TXD<==>U0RTS(MTDO) , U0RXD<==>U0CTS(MTCK)
......
}