fix optiboot: it accumulated too much from failed attempts

pull/326/head V3.1.85.alpha
Thorsten von Eicken 8 years ago
parent 02599ab172
commit 5d0e51f2c1
No known key found for this signature in database
GPG Key ID: C7F972A59D834B46
  1. 14
      Makefile
  2. 14
      esp-link/cgioptiboot.c
  3. 20
      esp-link/cgipins.c
  4. 9
      esp-link/config.c
  5. 2
      esp-link/config.h
  6. 9
      esp-link/main.c
  7. 7
      html/home.html
  8. 8
      html/ui.js
  9. 22
      serial/serbridge.c
  10. 11
      serial/uart.c

@ -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

@ -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<length; i++) DBG(" %x", buf[i]);
DBG("\n");
}
#endif
// skip in-sync responses
static short ICACHE_FLASH_ATTR skipInSync(char *buf, short length) {
while (length > 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) {

@ -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<<ser)) { coll = "Serial LED"; goto collision; }
pins |= 1 << ser;
}
if (uart0_tx_enable >= 0) {
if (pins & (1<<uart0_tx_enable)) { coll = "UART0 TX Enable"; goto collision; }
pins |= 1 << uart0_tx_enable;
if (tx_enable >= 0) {
if (pins & (1<<tx_enable)) { coll = "TX Enable"; goto collision; }
pins |= 1 << tx_enable;
}
if (swap) {
if (pins & (1<<15)) { coll = "Uart TX"; goto collision; }
@ -96,9 +96,9 @@ int ICACHE_FLASH_ATTR cgiPinsSet(HttpdConnData *connData) {
flashConfig.ser_led_pin = ser;
flashConfig.swap_uart = swap;
flashConfig.rx_pullup = rxpup;
flashConfig.uart0_tx_enable_pin = uart0_tx_enable;
os_printf("Pins changed: reset=%d isp=%d conn=%d ser=%d swap=%d rx-pup=%d uart0_tx_enable=%d\n",
reset, isp, conn, ser, swap, rxpup, uart0_tx_enable);
flashConfig.tx_enable_pin = tx_enable;
os_printf("Pins changed: reset=%d isp=%d conn=%d ser=%d swap=%d rx-pup=%d tx_enable=%d\n",
reset, isp, conn, ser, swap, rxpup, tx_enable);
// apply the changes
serbridgeInitPins();

@ -34,7 +34,7 @@ FlashConfig flashDefault = {
.data_bits = EIGHT_BITS,
.parity = NONE_BITS,
.stop_bits = ONE_STOP_BIT,
.uart0_tx_enable_pin = -1,
.tx_enable_pin = -1,
};
typedef union {
@ -161,6 +161,13 @@ bool ICACHE_FLASH_ATTR configRestore(void) {
flashConfig.parity = flashDefault.parity;
flashConfig.stop_bits = flashDefault.stop_bits;
}
if (flashConfig.tx_enable_pin == 0 &&
(flashConfig.conn_led_pin == 0 || flashConfig.reset_pin == 0 ||
flashConfig.isp_pin == 0 || flashConfig.ser_led_pin == 0)) {
// just added tx_enable_pin and it got the default 0, which is not good, need to default to
// disabled.
flashConfig.tx_enable_pin = -1;
}
return true;
}

@ -41,7 +41,7 @@ typedef struct {
int8_t data_bits;
int8_t parity;
int8_t stop_bits;
int8_t uart0_tx_enable_pin;
int8_t tx_enable_pin;
} FlashConfig;
extern FlashConfig flashConfig;

@ -32,7 +32,10 @@
#include "log.h"
#include "gpio.h"
#include "cgiservices.h"
#ifdef WEBSERVER
#include "web-server.h"
#endif
#ifdef SYSLOG
#include "syslog.h"
@ -108,8 +111,10 @@ HttpdBuiltInUrl builtInUrls[] = {
#ifdef MQTT
{ "/mqtt", cgiMqtt, NULL },
#endif
#ifdef WEBSERVER
{ "/web-server/upload", cgiWebServerSetupUpload, NULL },
{ "*.json", WEB_CgiJsonHook, NULL }, //Catch-all cgi JSON queries
#endif
{ "*", cgiEspFsHook, NULL }, //Catch-all cgi function for the filesystem
{ NULL, NULL, NULL }
};
@ -170,7 +175,7 @@ user_init(void) {
gpio_output_set(0, 0, 0, (1<<15)); // some people tie it to GND, gotta ensure it's disabled
// init UART
uart_init(CALC_UARTMODE(flashConfig.data_bits, flashConfig.parity, flashConfig.stop_bits),
flashConfig.baud_rate, flashConfig.uart0_tx_enable_pin, 115200);
flashConfig.baud_rate, flashConfig.tx_enable_pin, 115200);
logInit(); // must come after init of uart
// Say hello (leave some time to cause break in TX after boot loader's msg
os_delay_us(10000L);
@ -188,7 +193,9 @@ user_init(void) {
//os_printf("espFsInit %s\n", res?"ERR":"ok");
// mount the http handlers
httpdInit(builtInUrls, 80);
#ifdef WEBSERVER
WEB_Init();
#endif
// init the wifi-serial transparent bridge (port 23)
serbridgeInit(23, 2323);

@ -77,9 +77,10 @@
AVR:not used, esp8266:gpio2, ARM:ISP</div>
</div>
<div class="pure-control-group">
<label for="pin-uart0-tx-enable">TX Enable</label>
<select id="pin-uart0-tx-enable"></select>
<div class="popup">A pin that should be asserted high whilst transmitting (eg. to put RS/485 trancievers into TX mode)</div>
<label for="pin-txen">TX Enable</label>
<select id="pin-txen"></select>
<div class="popup">A pin that should be asserted high while transmitting
(eg. to put RS/485 trancievers into TX mode)</div>
</div>
<div class="pure-control-group">
<label for="pin-conn">Conn LED</label>

@ -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 = "&";
});

@ -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)

@ -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;

Loading…
Cancel
Save