From 5d0e51f2c1aa96280f1d37252e04d4c5e32df2ea Mon Sep 17 00:00:00 2001 From: Thorsten von Eicken Date: Sat, 17 Jun 2017 17:59:47 -0700 Subject: [PATCH] fix optiboot: it accumulated too much from failed attempts --- Makefile | 14 +------------- esp-link/cgioptiboot.c | 14 ++++++++++++-- esp-link/cgipins.c | 20 ++++++++++---------- esp-link/config.c | 9 ++++++++- esp-link/config.h | 2 +- esp-link/main.c | 9 ++++++++- html/home.html | 7 ++++--- html/ui.js | 8 ++++---- serial/serbridge.c | 22 +++++++++++----------- serial/uart.c | 11 ++++------- 10 files changed, 63 insertions(+), 53 deletions(-) diff --git a/Makefile b/Makefile index 1193e89..8459303 100644 --- a/Makefile +++ b/Makefile @@ -163,6 +163,7 @@ else ifeq ("$(FLASH_SIZE)","2MB") ESP_SPI_SIZE ?= 4 # 6->4MB (1MB+1MB) or 4->4MB (512KB+512KB) ESP_FLASH_MODE ?= 0 # 0->QIO, 2->DIO ESP_FLASH_FREQ_DIV ?= 15 # 15->80Mhz +:q ET_FS ?= 16m # 16Mbit flash size in esptool flash command ET_FF ?= 80m # 80Mhz flash speed in esptool flash command ET_BLANK ?= 0x1FE000 # where to flash blank.bin to erase wireless settings @@ -200,19 +201,6 @@ endif VERSION :=$(VERSION) $(info VERSION is $(VERSION)) -# OLD - DEPRECATED -# This queries git to produce a version string like "esp-link v0.9.0 2015-06-01 34bc76" -# If you don't have a proper git checkout or are on windows, then simply swap for the constant -# Steps to release: create release on github, git pull, git describe --tags to verify you're -# on the release tag, make release, upload esp-link.tgz into the release files -#VERSION ?= "esp-link custom version" -#DATE := $(shell date '+%F %T') -#BRANCH ?= $(shell if git diff --quiet HEAD; then git describe --tags; \ -# else git symbolic-ref --short HEAD; fi) -#SHA := $(shell if git diff --quiet HEAD; then git rev-parse --short HEAD | cut -d"/" -f 3; \ -# else echo "development"; fi) -#VERSION ?=esp-link $(BRANCH) - $(DATE) - $(SHA) - # Output directors to store intermediate compiled files # relative to the project directory BUILD_BASE = build diff --git a/esp-link/cgioptiboot.c b/esp-link/cgioptiboot.c index a220fbd..c94ac96 100644 --- a/esp-link/cgioptiboot.c +++ b/esp-link/cgioptiboot.c @@ -437,6 +437,14 @@ static void ICACHE_FLASH_ATTR optibootTimerCB(void *arg) { } } +#if 0 +static void ICACHE_FLASH_ATTR print_buff(char *msg, char *buf, short length) { + DBG("OB GOT %s %d:", msg, length); + for (int i=0; i 1 && buf[0] == STK_INSYNC && buf[1] == STK_OK) { @@ -449,6 +457,7 @@ static short ICACHE_FLASH_ATTR skipInSync(char *buf, short length) { // receive response from optiboot, we only store the last response static void ICACHE_FLASH_ATTR optibootUartRecv(char *buf, short length) { + //print_buff("RAW", buf, length); // append what we got to what we have accumulated if (responseLen < RESP_SZ-1) { char *rb = responseBuf+responseLen; @@ -457,6 +466,7 @@ static void ICACHE_FLASH_ATTR optibootUartRecv(char *buf, short length) { responseLen = rb-responseBuf; responseBuf[responseLen] = 0; // string terminator } + //print_buff("RBUF", responseBuf, responseLen); // dispatch based the current state switch (progState) { @@ -471,13 +481,13 @@ static void ICACHE_FLASH_ATTR optibootUartRecv(char *buf, short length) { } else if (responseLen > 1 && responseBuf[responseLen-2] == STK_INSYNC && responseBuf[responseLen-1] == STK_OK) { // got sync response - os_memcpy(responseBuf, responseBuf+2, responseLen-2); - responseLen -= 2; + responseLen = 0; // ignore anything that may have accumulated // send request to get signature uart0_write_char(STK_READ_SIGN); uart0_write_char(CRC_EOP); progState++; armTimer(PGM_INTERVAL); // reset timer + //DBG("OB: got sync, sent read-sig\n"); } else { // nothing useful, keep at most half the buffer for error message purposes if (responseLen > RESP_SZ/2) { diff --git a/esp-link/cgipins.c b/esp-link/cgipins.c index 94de000..bf4754d 100644 --- a/esp-link/cgipins.c +++ b/esp-link/cgipins.c @@ -32,10 +32,10 @@ int ICACHE_FLASH_ATTR cgiPinsGet(HttpdConnData *connData) { int len; len = os_sprintf(buff, - "{ \"reset\":%d, \"isp\":%d, \"conn\":%d, \"ser\":%d, \"swap\":%d, \"rxpup\":%d, \"uart0-tx-enable\":%d }", + "{ \"reset\":%d, \"isp\":%d, \"conn\":%d, \"ser\":%d, \"swap\":%d, \"rxpup\":%d, \"txen\":%d }", flashConfig.reset_pin, flashConfig.isp_pin, flashConfig.conn_led_pin, flashConfig.ser_led_pin, !!flashConfig.swap_uart, !!flashConfig.rx_pullup, - flashConfig.uart0_tx_enable_pin); + flashConfig.tx_enable_pin); jsonHeader(connData, 200); httpdSend(connData, buff, len); @@ -49,7 +49,7 @@ int ICACHE_FLASH_ATTR cgiPinsSet(HttpdConnData *connData) { } int8_t ok = 0; - int8_t reset, isp, conn, ser, uart0_tx_enable; + int8_t reset, isp, conn, ser, tx_enable; uint8_t swap, rxpup; ok |= getInt8Arg(connData, "reset", &reset); ok |= getInt8Arg(connData, "isp", &isp); @@ -57,7 +57,7 @@ int ICACHE_FLASH_ATTR cgiPinsSet(HttpdConnData *connData) { ok |= getInt8Arg(connData, "ser", &ser); ok |= getBoolArg(connData, "swap", &swap); ok |= getBoolArg(connData, "rxpup", &rxpup); - ok |= getInt8Arg(connData, "uart0-tx-enable", &uart0_tx_enable); + ok |= getInt8Arg(connData, "txen", &tx_enable); if (ok < 0) return HTTPD_CGI_DONE; char *coll; @@ -77,9 +77,9 @@ int ICACHE_FLASH_ATTR cgiPinsSet(HttpdConnData *connData) { if (pins & (1<= 0) { - if (pins & (1<= 0) { + if (pins & (1<
- - - + + +
diff --git a/html/ui.js b/html/ui.js index 2457330..eb50b4c 100644 --- a/html/ui.js +++ b/html/ui.js @@ -393,7 +393,7 @@ function showNotification(text) { //===== GPIO Pin mux card var pinPresets = { - // array: reset, isp, conn, ser, swap, rxpup, uart0-tx-enable + // array: reset, isp, conn, ser, swap, rxpup, txen "esp-01": [ 0, -1, 2, -1, 0, 1, -1 ], "esp-12": [ 12, 14, 0, 2, 0, 1, -1 ], "esp-12 swap": [ 1, 3, 0, 2, 1, 1, -1 ], @@ -418,7 +418,7 @@ function createPresets(sel) { setPP("ser", pp[3]); setPP("swap", pp[4]); $("#pin-rxpup").checked = !!pp[5]; - setPP("uart0-tx-enable", pp[6]); + setPP("txen", pp[6]); sel.value = 0; }; @@ -454,7 +454,7 @@ function displayPins(resp) { createSelectForPin("ser", resp["ser"]); $("#pin-swap").value = resp["swap"]; $("#pin-rxpup").checked = !!resp["rxpup"]; - createSelectForPin("uart0-tx-enable", resp["uart0-tx-enable"]); + createSelectForPin("txen", resp["txen"]); createPresets($("#pin-preset")); $("#pin-spinner").setAttribute("hidden", ""); @@ -471,7 +471,7 @@ function setPins(ev) { ev.preventDefault(); var url = "/pins"; var sep = "?"; - ["reset", "isp", "conn", "ser", "swap", "uart0-tx-enable"].forEach(function(p) { + ["reset", "isp", "conn", "ser", "swap", "txen"].forEach(function(p) { url += sep + p + "=" + $("#pin-"+p).value; sep = "&"; }); diff --git a/serial/serbridge.c b/serial/serbridge.c index 2fde395..74d1fc1 100644 --- a/serial/serbridge.c +++ b/serial/serbridge.c @@ -18,7 +18,7 @@ static struct espconn serbridgeConn1; // plain bridging port static struct espconn serbridgeConn2; // programming port static esp_tcp serbridgeTcp1, serbridgeTcp2; -static int8_t mcu_reset_pin, mcu_isp_pin, uart0_tx_enable_pin; +static int8_t mcu_reset_pin, mcu_isp_pin, tx_enable_pin; uint8_t in_mcu_flashing; // for disabling slip during MCU flashing @@ -557,10 +557,10 @@ serbridgeInitPins() { mcu_reset_pin = flashConfig.reset_pin; mcu_isp_pin = flashConfig.isp_pin; - uart0_tx_enable_pin = flashConfig.uart0_tx_enable_pin; + tx_enable_pin = flashConfig.tx_enable_pin; #ifdef SERBR_DBG os_printf("Serbridge pins: reset=%d isp=%d tx_enable=%d swap=%d\n", - mcu_reset_pin, mcu_isp_pin, uart0_tx_enable_pin, flashConfig.swap_uart); + mcu_reset_pin, mcu_isp_pin, tx_enable_pin, flashConfig.swap_uart); #endif if (flashConfig.swap_uart) { @@ -583,21 +583,21 @@ serbridgeInitPins() * then switch pin mux to make these pins GPIO pins */ if (mcu_isp_pin >= 0) { - GPIO_OUTPUT_SET(mcu_isp_pin, 1); - makeGpio(mcu_isp_pin); + GPIO_OUTPUT_SET(mcu_isp_pin, 1); + makeGpio(mcu_isp_pin); } if (mcu_reset_pin >= 0) { - GPIO_OUTPUT_SET(mcu_reset_pin, 1); - makeGpio(mcu_reset_pin); + GPIO_OUTPUT_SET(mcu_reset_pin, 1); + makeGpio(mcu_reset_pin); } // set TX_ENABLE to 0 so we start up listening - if (uart0_tx_enable_pin >= 0) { - GPIO_OUTPUT_SET(uart0_tx_enable_pin, 0); - makeGpio(uart0_tx_enable_pin); - uart0_set_tx_enable_pin(uart0_tx_enable_pin); + if (tx_enable_pin >= 0) { + GPIO_OUTPUT_SET(tx_enable_pin, 0); + makeGpio(tx_enable_pin); } + uart0_set_tx_enable_pin(tx_enable_pin); // must set to -1 if that's its value } // Start transparent serial bridge TCP server on specified port (typ. 23) diff --git a/serial/uart.c b/serial/uart.c index 1bcdd17..46e42f6 100644 --- a/serial/uart.c +++ b/serial/uart.c @@ -45,7 +45,7 @@ static void uart0_rx_intr_handler(void *para); *******************************************************************************/ void ICACHE_FLASH_ATTR uart0_set_tx_enable_pin(int8_t pin) { - uart0_tx_enable_pin = pin; + uart0_tx_enable_pin = pin; } /****************************************************************************** @@ -59,14 +59,11 @@ static void ICACHE_FLASH_ATTR tx_enable(bool state) { if (uart0_tx_enable_pin >= 0) { -#ifdef SERBR_DBG - os_printf("TX_ENABLE gpio%d state=%d\n", uart0_tx_enable_pin, (int)state); -#endif + DBG_UART("TX_ENABLE gpio%d state=%d\n", uart0_tx_enable_pin, (int)state); GPIO_OUTPUT_SET(uart0_tx_enable_pin, (state) ? 1 : 0); + } else { + DBG_UART("TX Enable: no pin\n"); } -#ifdef SERBR_DBG - else { os_printf("TX Enable: no pin\n"); } -#endif } os_timer_t uart_tx_enable_timer;