-->
Page 1 of 2

How to bootloader with serial peripheral device?

PostPosted: Tue Mar 08, 2016 11:47 am
by nemik
Hi guys,

So I'm making a little board based on a NodeMCU and another peripheral I communicate with over serial. Now, I'd like to have bi-directional serial with Rx and Tx to the peripheral and at the same time, let users re-flash the NodeMCU should they need it.

But I'm running into roadblocks on how to do this. If I connect the serial lines from the NodeMCU/esp8266 to the other device, its serial will interfere with the bootloader. I tried to do something like tie the ESP's reset and GPIO 0 lines to inputs on the peripheral so that if it detects them to reset and be low, to not start serial. But the ESP is weird in that it uses GPIO0 as an output for a while too along with input so it doesn't seem reliable.

Another thing I did was use the second serial peripheral on the ESP8266 that's on pins 13 and 15. But GPIO 15 must be held low to boot normally and that's what goes to the other peripheral's RX line which pulls it high (serial RX does that). And those lines aren't connected to the NodeMCU's USB serial chip so it's not as nice for debugging.

I'm ready to say screwit and just use a toggle switch to turn power on or off to the other peripheral so it won't interrupt. But I really don't want to add components to the board for something that feels like it should be possible in software and clever layout, I just can't seem to get it.

And yes, I already can flash OTA over wifi, but I want to make the USB/Serial route an option for my users in case they need that lower level of flashing if their OTA firmware screws up.

Any suggestions would be greatly appreciated, thank you!

Re: How to bootloader with serial peripheral device?

PostPosted: Thu Mar 10, 2016 12:41 pm
by nemik
I think I figured this out. In case anyone else runs into this problem, here's what I did.

I hooked up an 'enable' GPIO (GPIO5 but whatever you want is fine) from the ESP8266 to another GPIO on my serial peripheral and pulled it high with a 10k resistor. I also connected the esp8266's reset pin to another GPIO on the serial peripheral.
I then connected the serial normally, peripheral RX -> ESP-TX and peripheral TX -> ESP-RX.

Now when the esp8266 resets, I make the other peripheral reset too. When the other peripheral boots up, it checks the status of the enable pin (GPIO5 from esp). If it's high, it will not initialize its serial port peripheral and will make the pins on its UART floating (no pull downs in any direction). This enables the NodeMCU USB-Serial CP21012 chip to flash the esp8266 without a problem over its Rx/Tx lines.

When I want my esp8266 program to boot up normally though (not flash) and talk to the peripheral, I set the enable GPIO5 as an output and pull it low. The other peripheral sees this line low and enables its UART on those pins and now it and the esp8266 can happily communicate.

Anyway, hopefully this helps someone else if you're running into the same thing.

Re: How to bootloader with serial peripheral device?

PostPosted: Thu Jul 21, 2016 3:25 pm
by aesilky
I've been struggling with a very similar situation, but I'm hoping there is another solution.

I very much appreciate your post, and will store it away for future reference - but I'm hoping something else can be done.

The ESP8266-12E diagram shows 2 serial ports (UARTS) and the pins they are connected to. As you, I am currently using Serial (UART0) to connect to my peripheral. As you point out, this interferes with programming and (typical) logging. Also, as you suggested, I currently have a toggle switch. This "works", but adds (hopefully) unneeded complexity to the solution. In addition, it means that I can't take advantage of typical logging mechanisms. For logging I enabled Serial1 (UART1) thanks to finding the "PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO2_U, FUNC_U1TXD_BK);" configuration, I was able to get Serial1 TX working, so I can use it for logging - but it's not convenient... I have to connect a second serial cable and open up a terminal program to use it to monitor (currently using CuteCom on my Linux machine). That is in addition to needing to include the toggle switch into the circuit.

I'm really hoping there is a way to use Serial1 (UART1) as a full, bidirectional, TX-RX serial port. I can use it to connect to my peripheral and leave Serial (UART0) for the USB to use for programming and default logging.

Re: How to bootloader with serial peripheral device?

PostPosted: Thu Jul 21, 2016 4:16 pm
by martinayotte
aesilky wrote:I'm really hoping there is a way to use Serial1 (UART1) as a full, bidirectional, TX-RX serial port.

Unfortunately, UART1 has only TX, this missing RX on UART1 is by hardware design.
You will never see it, except if Espressif provide new chip revision after redesign.