defines for GPIO pin assignments; version string

pull/7/head
Thorsten von Eicken 10 years ago
parent bbbeab3519
commit 7ff16bc321
  1. 2
      .gitignore
  2. 116
      Makefile
  3. 1
      html/index.tpl
  4. 60
      serial/serbridge.c
  5. 2
      serial/serbridge.h
  6. 79
      serial/serled.c
  7. 9
      serial/serled.h
  8. 10
      serial/uart.c
  9. 4
      user/cgi.c
  10. 2
      user/cgiflash.c
  11. 21
      user/console.c
  12. 10
      user/log.c
  13. 2
      user/status.h
  14. 12
      user/user_main.c
  15. 6
      wiflash

2
.gitignore vendored

@ -7,3 +7,5 @@ espfs/espfstest/*.o
espfs/espfstest/espfstest espfs/espfstest/espfstest
*.DS_Store *.DS_Store
html_compressed/ html_compressed/
esp-link.tgz
tve-patch/

@ -1,3 +1,63 @@
#
# Makefile for esp-link - https://github.com/jeelabs/esp-link
#
# Start by setting the directories for the toolchain a few lines down
# the default target will build the firmware images
# `make flash` will flash the esp serially
# `make wiflash` will flash the esp over wifi
# `VERBOSE=1 make ...` will print debug info
# `ESP_HOSTNAME=my.esp.example.com make wiflash` is an easy way to override a variable
#
# Makefile heavily adapted to esp-link and wireless flashing by Thorsten von Eicken
# Original from esphttpd and others...
# --------------- toolchain configuration ---------------
# Base directory for the compiler. Needs a / at the end.
# Typically you'll install https://github.com/pfalcon/esp-open-sdk
XTENSA_TOOLS_ROOT ?= $(abspath ../esp-open-sdk/xtensa-lx106-elf/bin)/
# Base directory of the ESP8266 SDK package, absolute
# Typically you'll download from Espressif's BBS, http://bbs.espressif.com/viewforum.php?f=5
SDK_BASE ?= $(abspath ../esp_iot_sdk_v1.1.0)
# Esptool.py path and port, only used for 1-time serial flashing
# Typically you'll use https://github.com/themadinventor/esptool
ESPTOOL ?= $(abspath ../esptool/esptool.py)
ESPPORT ?= /dev/ttyUSB0
ESPBAUD ?= 460800
# --------------- chipset configuration ---------------
ESP_SPI_SIZE ?= 0 # 0->512KB
ESP_FLASH_MODE ?= 0 # 0->QIO
ESP_FLASH_FREQ_DIV ?= 0 # 0->40Mhz
ESP_FLASH_MAX ?= 241664 # max bin file for 512KB flash: 236KB
# hostname or IP address for wifi flashing
ESP_HOSTNAME ?= esp8266
# The pin assignments below are used when the settings in flash are invalid, they
# can be changed via the web interface
# GPIO pin used to reset attached microcontroller, acative low
MCU_RESET_PIN ?= 12
# GPIO pin used with reset to reprogram MCU (ISP=in-system-programming, unused with AVRs), active low
MCU_ISP_PIN ?= 13
# GPIO pin used for "connectivity" LED, active low
LED_CONN_PIN ?= 0
# GPIO pin used for "serial activity" LED, active low
LED_SERIAL_PIN ?= 2
# --------------- esp-link version ---------------
# 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
VERSION := "esp-link custom version"
DATE := $(shell date '+%F %T')
BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
SHA := $(shell if git diff --quiet HEAD; then git symbolic-ref HEAD | cut -d"/" -f 3; \
else echo "development"; fi)
VERSION := esp-link - $(BRANCH) - $(DATE) - $(SHA)
# --------------- esphttpd config options --------------- # --------------- esphttpd config options ---------------
@ -30,54 +90,33 @@ YUI-COMPRESSOR ?= /usr/bin/yui-compressor
# Because the decompression is done in the esp8266, it does not require any support in the browser. # Because the decompression is done in the esp8266, it does not require any support in the browser.
USE_HEATSHRINK ?= yes USE_HEATSHRINK ?= yes
# -------------- End of esphttpd config options ------------- # -------------- End of config options -------------
# Output directors to store intermediate compiled files # Output directors to store intermediate compiled files
# relative to the project directory # relative to the project directory
BUILD_BASE = build BUILD_BASE = build
FW_BASE = firmware FW_BASE = firmware
# Base directory for the compiler. Needs a / at the end;
XTENSA_TOOLS_ROOT ?= $(abspath ../esp-open-sdk/xtensa-lx106-elf/bin)/
# Base directory of the ESP8266 SDK package, absolute
SDK_BASE ?= $(abspath ../esp_iot_sdk_v1.1.0)
#Esptool.py path and port
ESPTOOL ?= esptool.py
ESPPORT ?= /dev/ttyUSB0
#ESPDELAY indicates seconds to wait between flashing the two binary images
ESPDELAY ?= 3
ESPBAUD ?= 460800
# name for the target project # name for the target project
TARGET = httpd TARGET = httpd
# espressif tool to concatenate sections for OTA upload using bootloader v1.2+ # espressif tool to concatenate sections for OTA upload using bootloader v1.2+
APPGEN_TOOL ?= gen_appbin.py APPGEN_TOOL ?= gen_appbin.py
ESP_SPI_SIZE ?= 0 # 0->512KB
ESP_FLASH_MODE ?= 0 # 0->QIO
ESP_FLASH_FREQ_DIV ?= 0 # 0->40Mhz
ESP_FLASH_MAX ?= 241664 # max bin file for 512KB flash: 236KB
ESP_HOSTNAME ?= esp8266
# which modules (subdirectories) of the project to include in compiling # which modules (subdirectories) of the project to include in compiling
#MODULES = driver user lwip/api lwip/app lwip/core lwip/core/ipv4 lwip/netif
MODULES = espfs httpd user serial MODULES = espfs httpd user serial
EXTRA_INCDIR = include . lib/heatshrink/ EXTRA_INCDIR = include . lib/heatshrink/
# libraries used in this project, mainly provided by the SDK # libraries used in this project, mainly provided by the SDK
LIBS = c gcc hal phy pp net80211 wpa main lwip LIBS = c gcc hal phy pp net80211 wpa main lwip
# compiler flags using during compilation of source files # compiler flags using during compilation of source files
CFLAGS = -Os -ggdb -std=c99 -Werror -Wpointer-arith -Wundef -Wall -Wl,-EL -fno-inline-functions \ CFLAGS = -Os -ggdb -std=c99 -Werror -Wpointer-arith -Wundef -Wall -Wl,-EL -fno-inline-functions \
-nostdlib -mlongcalls -mtext-section-literals -D__ets__ -DICACHE_FLASH -D_STDINT_H \ -nostdlib -mlongcalls -mtext-section-literals -D__ets__ -DICACHE_FLASH -D_STDINT_H \
-Wno-address -DFIRMWARE_SIZE=$(ESP_FLASH_MAX) -Wno-address -DFIRMWARE_SIZE=$(ESP_FLASH_MAX) \
-DMCU_RESET_PIN=$(MCU_RESET_PIN) -DMCU_ISP_PIN=$(MCU_ISP_PIN) \
-DLED_CONN_PIN=$(LED_CONN_PIN) -DLED_SERIAL_PIN=$(LED_SERIAL_PIN) \
"-DVERSION=$(VERSION)"
# linker flags used to generate the main object file # linker flags used to generate the main object file
LDFLAGS = -nostdlib -Wl,--no-check-sections -u call_user_start -Wl,-static LDFLAGS = -nostdlib -Wl,--no-check-sections -u call_user_start -Wl,-static
@ -101,8 +140,6 @@ OBJCP := $(XTENSA_TOOLS_ROOT)xtensa-lx106-elf-objcopy
OBJDP := $(XTENSA_TOOLS_ROOT)xtensa-lx106-elf-objdump OBJDP := $(XTENSA_TOOLS_ROOT)xtensa-lx106-elf-objdump
####
#### no user configurable options below here
#### ####
SRC_DIR := $(MODULES) SRC_DIR := $(MODULES)
BUILD_DIR := $(addprefix $(BUILD_BASE)/,$(MODULES)) BUILD_DIR := $(addprefix $(BUILD_BASE)/,$(MODULES))
@ -152,7 +189,12 @@ endef
.PHONY: all checkdirs clean webpages.espfs .PHONY: all checkdirs clean webpages.espfs
all: checkdirs $(FW_BASE) firmware/user1.bin firmware/user2.bin all: echo_version checkdirs $(FW_BASE) firmware/user1.bin firmware/user2.bin
echo_version:
@echo VERSION: $(VERSION)
user/version.h:
$(TARGET_OUT): $(APP_AR) $(LD_SCRIPT) $(TARGET_OUT): $(APP_AR) $(LD_SCRIPT)
$(vecho) "LD $@" $(vecho) "LD $@"
@ -209,8 +251,10 @@ $(BUILD_DIR):
wiflash: all wiflash: all
./wiflash $(ESP_HOSTNAME) firmware/user1.bin firmware/user2.bin ./wiflash $(ESP_HOSTNAME) firmware/user1.bin firmware/user2.bin
flash: $(TARGET_OUT) $(FW_BASE) flash: all
$(Q) $(ESPTOOL) --port $(ESPPORT) --baud $(ESPBAUD) write_flash 0x00000 $(FW_BASE)/0x00000.bin 0x40000 $(FW_BASE)/0x40000.bin $(Q) $(ESPTOOL) --port $(ESPPORT) --baud $(ESPBAUD) write_flash \
0x00000 "$(SDK_BASE)/bin/boot_v1.4(b1).bin" 0x01000 $(FW_BASE)/user1.bin \
0x7E000 $(SDK_BASE)/bin/blank.bin
$(BUILD_BASE)/espfs_img.o: html/ html/wifi/ espfs/mkespfsimage/mkespfsimage $(BUILD_BASE)/espfs_img.o: html/ html/wifi/ espfs/mkespfsimage/mkespfsimage
ifeq ("$(COMPRESS_W_YUI)","yes") ifeq ("$(COMPRESS_W_YUI)","yes")
@ -245,12 +289,16 @@ build/eagle.esphttpd2.v6.ld: $(SDK_LDDIR)/eagle.app.v6.new.512.app2.ld
-e '/^ irom0_0_seg/ s/2B000/38000/' \ -e '/^ irom0_0_seg/ s/2B000/38000/' \
$(SDK_LDDIR)/eagle.app.v6.new.512.app2.ld >$@ $(SDK_LDDIR)/eagle.app.v6.new.512.app2.ld >$@
blankflash:
$(Q) $(ESPTOOL) --port $(ESPPORT) --baud $(ESPBAUD) write_flash 0x7E000 $(SDK_BASE)/bin/blank.bin
espfs/mkespfsimage/mkespfsimage: espfs/mkespfsimage/ espfs/mkespfsimage/mkespfsimage: espfs/mkespfsimage/
$(Q) $(MAKE) -C espfs/mkespfsimage USE_HEATSHRINK="$(USE_HEATSHRINK)" GZIP_COMPRESSION="$(GZIP_COMPRESSION)" $(Q) $(MAKE) -C espfs/mkespfsimage USE_HEATSHRINK="$(USE_HEATSHRINK)" GZIP_COMPRESSION="$(GZIP_COMPRESSION)"
release: all
$(Q) rm -rf release; mkdir -p release/esp-link
$(Q) cp firmware/user1.bin firmware/user2.bin $(SDK_BASE)/bin/blank.bin \
"$(SDK_BASE)/bin/boot_v1.4(b1).bin" wiflash release/esp-link
$(Q) tar zcf esp-link.tgz -C release esp-link
$(Q) rm -rf release
clean: clean:
$(Q) rm -f $(APP_AR) $(Q) rm -f $(APP_AR)
$(Q) rm -f $(TARGET_OUT) $(Q) rm -f $(TARGET_OUT)

@ -3,6 +3,7 @@
<div id="main"> <div id="main">
<div class="header"> <div class="header">
<h1><span class="esp">esp</span> link</h1> <h1><span class="esp">esp</span> link</h1>
<h2>%version%</h2>
</div> </div>
<div class="content"> <div class="content">

@ -8,19 +8,10 @@
#include "uart.h" #include "uart.h"
#include "serbridge.h" #include "serbridge.h"
#include "serled.h"
#include "console.h" #include "console.h"
#if 1 static uint8_t mcu_reset_pin, mcu_isp_pin;
// GPIO for esp-03 module with gpio12->reset, gpio13->isp, gpio2->"ser" LED
#define MCU_RESET 12
#define MCU_ISP 13
#define MCU_LED 2
#else
// GPIO for esp-01 module with gpio0->reset, gpio2->isp
#define MCU_RESET 0
#define MCU_ISP 2
#undef MCU_LED
#endif
static struct espconn serbridgeConn; static struct espconn serbridgeConn;
static esp_tcp serbridgeTcp; static esp_tcp serbridgeTcp;
@ -88,6 +79,8 @@ static void ICACHE_FLASH_ATTR serbridgeSentCb(void *arg) {
//os_printf("%d ST\n", system_get_time()); //os_printf("%d ST\n", system_get_time());
conn->readytosend = true; conn->readytosend = true;
sendtxbuffer(conn); // send possible new data in txbuffer sendtxbuffer(conn); // send possible new data in txbuffer
serledFlash(50); // short blink on serial LED
} }
// Telnet protocol characters // Telnet protocol characters
@ -154,21 +147,21 @@ telnetUnwrap(uint8_t *inBuf, int len, uint8_t state)
case TN_setControl: // switch control line and delay a tad case TN_setControl: // switch control line and delay a tad
switch (c) { switch (c) {
case DTR_ON: case DTR_ON:
os_printf("MCU reset\n"); os_printf("MCU reset gpio%d\n", mcu_reset_pin);
GPIO_OUTPUT_SET(MCU_RESET, 0); GPIO_OUTPUT_SET(mcu_reset_pin, 0);
os_delay_us(100L); os_delay_us(100L);
break; break;
case DTR_OFF: case DTR_OFF:
GPIO_OUTPUT_SET(MCU_RESET, 1); GPIO_OUTPUT_SET(mcu_reset_pin, 1);
os_delay_us(100L); os_delay_us(100L);
break; break;
case RTS_ON: case RTS_ON:
os_printf("MCU ISP\n"); os_printf("MCU ISP gpio%d\n", mcu_isp_pin);
GPIO_OUTPUT_SET(MCU_ISP, 0); GPIO_OUTPUT_SET(mcu_isp_pin, 0);
os_delay_us(100L); os_delay_us(100L);
break; break;
case RTS_OFF: case RTS_OFF:
GPIO_OUTPUT_SET(MCU_ISP, 1); GPIO_OUTPUT_SET(mcu_isp_pin, 1);
os_delay_us(100L); os_delay_us(100L);
break; break;
} }
@ -198,16 +191,16 @@ static void ICACHE_FLASH_ATTR serbridgeRecvCb(void *arg, char *data, unsigned sh
if ((len == 2 && strncmp(data, "0 ", 2) == 0) || if ((len == 2 && strncmp(data, "0 ", 2) == 0) ||
(len == 2 && strncmp(data, "?\n", 2) == 0) || (len == 2 && strncmp(data, "?\n", 2) == 0) ||
(len == 3 && strncmp(data, "?\r\n", 3) == 0)) { (len == 3 && strncmp(data, "?\r\n", 3) == 0)) {
os_printf("MCU Reset=%d ISP=%d\n", MCU_RESET, MCU_ISP); os_printf("MCU Reset=%d ISP=%d\n", mcu_reset_pin, mcu_isp_pin);
os_delay_us(2*1000L); // time for os_printf to happen os_delay_us(2*1000L); // time for os_printf to happen
// send reset to arduino/ARM // send reset to arduino/ARM
GPIO_OUTPUT_SET(MCU_RESET, 0); GPIO_OUTPUT_SET(mcu_reset_pin, 0);
os_delay_us(100L); os_delay_us(100L);
GPIO_OUTPUT_SET(MCU_ISP, 0); GPIO_OUTPUT_SET(mcu_isp_pin, 0);
os_delay_us(100L); os_delay_us(100L);
GPIO_OUTPUT_SET(MCU_RESET, 1); GPIO_OUTPUT_SET(mcu_reset_pin, 1);
os_delay_us(100L); os_delay_us(100L);
GPIO_OUTPUT_SET(MCU_ISP, 1); GPIO_OUTPUT_SET(mcu_isp_pin, 1);
os_delay_us(1000L); os_delay_us(1000L);
conn->conn_mode = cmAVR; conn->conn_mode = cmAVR;
@ -231,6 +224,8 @@ static void ICACHE_FLASH_ATTR serbridgeRecvCb(void *arg, char *data, unsigned sh
} else { } else {
uart0_tx_buffer(data, len); uart0_tx_buffer(data, len);
} }
serledFlash(50); // short blink on serial LED
} }
// Error callback (it's really poorly named, it's not a "connection reconnected" callback, // Error callback (it's really poorly named, it's not a "connection reconnected" callback,
@ -253,9 +248,9 @@ static void ICACHE_FLASH_ATTR serbridgeDisconCb(void *arg) {
{ {
if (connData[i].conn_mode == cmAVR) { if (connData[i].conn_mode == cmAVR) {
// send reset to arduino/ARM // send reset to arduino/ARM
GPIO_OUTPUT_SET(MCU_RESET, 0); GPIO_OUTPUT_SET(mcu_reset_pin, 0);
os_delay_us(100L); os_delay_us(100L);
GPIO_OUTPUT_SET(MCU_RESET, 1); GPIO_OUTPUT_SET(mcu_reset_pin, 1);
} }
connData[i].conn = NULL; connData[i].conn = NULL;
} }
@ -303,7 +298,7 @@ serbridgeUartCb(char *buf, int length) {
} }
// Start transparent serial bridge TCP server on specified port (typ. 23) // Start transparent serial bridge TCP server on specified port (typ. 23)
void ICACHE_FLASH_ATTR serbridgeInit(int port) { void ICACHE_FLASH_ATTR serbridgeInit(int port, uint8_t reset_pin, uint8_t isp_pin) {
int i; int i;
for (i = 0; i < MAX_CONN; i++) { for (i = 0; i < MAX_CONN; i++) {
connData[i].conn = NULL; connData[i].conn = NULL;
@ -314,13 +309,14 @@ void ICACHE_FLASH_ATTR serbridgeInit(int port) {
serbridgeTcp.local_port = port; serbridgeTcp.local_port = port;
serbridgeConn.proto.tcp = &serbridgeTcp; serbridgeConn.proto.tcp = &serbridgeTcp;
PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTDI_U, FUNC_GPIO12); mcu_reset_pin = reset_pin;
PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTCK_U , FUNC_GPIO13); mcu_isp_pin = isp_pin;
//GPIO_OUTPUT_SET(MCU_ISP, 1); // set both pins to 1 so we don't cause a reset
//GPIO_OUTPUT_SET(MCU_RESET, 0); GPIO_OUTPUT_SET(mcu_isp_pin, 1);
#ifdef MCU_LED GPIO_OUTPUT_SET(mcu_reset_pin, 1);
GPIO_OUTPUT_SET(MCU_LED, 1); // switch pin mux to make these pins GPIO pins
#endif makeGpio(mcu_reset_pin);
makeGpio(mcu_isp_pin);
espconn_regist_connectcb(&serbridgeConn, serbridgeConnectCb); espconn_regist_connectcb(&serbridgeConn, serbridgeConnectCb);
espconn_accept(&serbridgeConn); espconn_accept(&serbridgeConn);

@ -32,7 +32,7 @@ struct serbridgeConnData {
uint8_t telnet_state; uint8_t telnet_state;
}; };
void ICACHE_FLASH_ATTR serbridgeInit(int port); void ICACHE_FLASH_ATTR serbridgeInit(int port, uint8_t reset_pin, uint8_t isp_pin);
void ICACHE_FLASH_ATTR serbridgeUartCb(char *buf, int len); void ICACHE_FLASH_ATTR serbridgeUartCb(char *buf, int len);
#endif /* __SER_BRIDGE_H__ */ #endif /* __SER_BRIDGE_H__ */

@ -0,0 +1,79 @@
#include <esp8266.h>
#include <serled.h>
static ETSTimer serledTimer;
static uint8_t serledPin;
static void ICACHE_FLASH_ATTR setSerled(int on) {
// LED is active-low
if (on) {
gpio_output_set(0, (1<<serledPin), (1<<serledPin), 0);
} else {
gpio_output_set((1<<serledPin), 0, (1<<serledPin), 0);
}
}
static void ICACHE_FLASH_ATTR serledTimerCb(void *v) {
setSerled(0);
}
void ICACHE_FLASH_ATTR serledFlash(int duration) {
setSerled(1);
os_timer_disarm(&serledTimer);
os_timer_setfn(&serledTimer, serledTimerCb, NULL);
os_timer_arm(&serledTimer, duration, 0);
}
void ICACHE_FLASH_ATTR serledInit(uint8_t pin) {
serledPin = pin;
makeGpio(pin);
gpio_output_set(0, 0, (1<<pin), 0);
serledFlash(1000); // turn it on for 1 second
}
// Make a pin be GPIO, i.e. set the mux so the pin has the gpio function
void ICACHE_FLASH_ATTR makeGpio(uint8_t pin) {
uint32_t addr;
uint8_t func = 3;
switch (pin) {
case 0:
addr = PERIPHS_IO_MUX_GPIO0_U;
func = 0;
break;
case 1:
addr = PERIPHS_IO_MUX_U0TXD_U;
break;
case 2:
addr = PERIPHS_IO_MUX_GPIO2_U;
func = 0;
break;
case 3:
addr = PERIPHS_IO_MUX_U0RXD_U;
break;
case 4:
addr = PERIPHS_IO_MUX_GPIO4_U;
func = 0;
break;
case 5:
addr = PERIPHS_IO_MUX_GPIO5_U;
func = 0;
break;
case 6:
case 7:
case 8:
case 9:
case 10:
case 11:
addr = PERIPHS_IO_MUX_SD_CMD_U - 4 * (11-pin);
break;
case 12:
case 13:
case 14:
case 15:
addr = PERIPHS_IO_MUX_MTDO_U - 4 * (15-pin);
break;
default:
return;
}
PIN_FUNC_SELECT(addr, func);
}

@ -0,0 +1,9 @@
#ifndef SERLED_H
#define SERLED_H
void serledFlash(int duration);
void serledInit(uint8_t pin);
void makeGpio(uint8_t pin);
#endif

@ -167,6 +167,8 @@ uart0_sendStr(const char *str)
} }
} }
static bool rx_bad; // set to true on framing error to avoid printing errors continuously
/****************************************************************************** /******************************************************************************
* FunctionName : uart0_rx_intr_handler * FunctionName : uart0_rx_intr_handler
* Description : Internal used function * Description : Internal used function
@ -183,23 +185,25 @@ uart0_rx_intr_handler(void *para)
if(UART_FRM_ERR_INT_ST == (READ_PERI_REG(UART_INT_ST(uart_no)) & UART_FRM_ERR_INT_ST)) if(UART_FRM_ERR_INT_ST == (READ_PERI_REG(UART_INT_ST(uart_no)) & UART_FRM_ERR_INT_ST))
{ {
os_printf("FRM_ERR\r\n"); if (!rx_bad) os_printf("FRM_ERR\n");
rx_bad = true;
//clear rx and tx fifo //clear rx and tx fifo
SET_PERI_REG_MASK(UART_CONF0(uart_no), UART_RXFIFO_RST); SET_PERI_REG_MASK(UART_CONF0(uart_no), UART_RXFIFO_RST);
CLEAR_PERI_REG_MASK(UART_CONF0(uart_no), UART_RXFIFO_RST); CLEAR_PERI_REG_MASK(UART_CONF0(uart_no), UART_RXFIFO_RST);
// reset interrupt // reset interrupt
WRITE_PERI_REG(UART_INT_CLR(uart_no), UART_FRM_ERR_INT_CLR); WRITE_PERI_REG(UART_INT_CLR(uart_no), UART_FRM_ERR_INT_CLR);
} }
if(UART_RXFIFO_FULL_INT_ST == (READ_PERI_REG(UART_INT_ST(uart_no)) & UART_RXFIFO_FULL_INT_ST)) if(UART_RXFIFO_FULL_INT_ST == (READ_PERI_REG(UART_INT_ST(uart_no)) & UART_RXFIFO_FULL_INT_ST))
{ {
//os_printf("fifo full\r\n"); //os_printf("fifo fullr\n");
ETS_UART_INTR_DISABLE(); ETS_UART_INTR_DISABLE();
system_os_post(recvTaskPrio, 0, 0); system_os_post(recvTaskPrio, 0, 0);
} }
else if(UART_RXFIFO_TOUT_INT_ST == (READ_PERI_REG(UART_INT_ST(uart_no)) & UART_RXFIFO_TOUT_INT_ST)) else if(UART_RXFIFO_TOUT_INT_ST == (READ_PERI_REG(UART_INT_ST(uart_no)) & UART_RXFIFO_TOUT_INT_ST))
{ {
rx_bad = false;
ETS_UART_INTR_DISABLE(); ETS_UART_INTR_DISABLE();
//os_printf("stat:%02X",*(uint8 *)UART_INT_ENA(uart_no)); //os_printf("stat:%02X",*(uint8 *)UART_INT_ENA(uart_no));
system_os_post(recvTaskPrio, 0, 0); system_os_post(recvTaskPrio, 0, 0);

@ -74,6 +74,10 @@ int ICACHE_FLASH_ATTR tplCounter(HttpdConnData *connData, char *token, void **ar
} else if (os_strcmp(token, "head")==0) { } else if (os_strcmp(token, "head")==0) {
printHead(connData); printHead(connData);
buff[0] = 0; buff[0] = 0;
} else if (os_strcmp(token, "version")==0) {
# define VERS_STR_STR(V) #V
# define VERS_STR(V) VERS_STR_STR(V)
os_sprintf(buff, "%s", VERS_STR(VERSION));
} else if (os_strcmp(token, "counter")==0) { } else if (os_strcmp(token, "counter")==0) {
hitCounter++; hitCounter++;
os_sprintf(buff, "%ld", hitCounter); os_sprintf(buff, "%ld", hitCounter);

@ -27,6 +27,7 @@ static char* ICACHE_FLASH_ATTR check_header(void *buf) {
return NULL; return NULL;
} }
#if 0
//===== Cgi that reads the SPI flash. Assumes 512KByte flash. //===== Cgi that reads the SPI flash. Assumes 512KByte flash.
int ICACHE_FLASH_ATTR cgiReadFlash(HttpdConnData *connData) { int ICACHE_FLASH_ATTR cgiReadFlash(HttpdConnData *connData) {
int *pos=(int *)&connData->cgiData; int *pos=(int *)&connData->cgiData;
@ -48,6 +49,7 @@ int ICACHE_FLASH_ATTR cgiReadFlash(HttpdConnData *connData) {
*pos+=1024; *pos+=1024;
if (*pos>=0x40200000+(512*1024)) return HTTPD_CGI_DONE; else return HTTPD_CGI_MORE; if (*pos>=0x40200000+(512*1024)) return HTTPD_CGI_DONE; else return HTTPD_CGI_MORE;
} }
#endif
//===== Cgi to query which firmware needs to be uploaded next //===== Cgi to query which firmware needs to be uploaded next
int ICACHE_FLASH_ATTR cgiGetFirmwareNext(HttpdConnData *connData) { int ICACHE_FLASH_ATTR cgiGetFirmwareNext(HttpdConnData *connData) {

@ -6,20 +6,27 @@
// Microcontroller console capturing the last 1024 characters received on the uart so // Microcontroller console capturing the last 1024 characters received on the uart so
// they can be shown on a web page // they can be shown on a web page
// Buffer to hold concole contents.
// Invariants:
// - console_rd==console_wr <=> buffer empty
// - *console_rd == next char to read
// - *console_wr == next char to write
// - 0 <= console_xx < BUF_MAX
// - (console_wr+1)%BUF_MAX) == console_rd <=> buffer full
#define BUF_MAX (1024) #define BUF_MAX (1024)
static char console_buf[BUF_MAX]; static char console_buf[BUF_MAX];
static int console_wr, console_rd; static int console_wr, console_rd;
static int console_pos; // offset since reset of console_rd position static int console_pos; // offset since reset of buffer
static void ICACHE_FLASH_ATTR static void ICACHE_FLASH_ATTR
console_write(char c) { console_write(char c) {
int wr = (console_wr+1)%BUF_MAX; console_buf[console_wr] = c;
if (wr == console_rd) { console_wr = (console_wr+1) % BUF_MAX;
if (console_wr == console_rd) {
// full, we write anyway and loose the oldest char
console_rd = (console_rd+1) % BUF_MAX; // full, eat first char console_rd = (console_rd+1) % BUF_MAX; // full, eat first char
console_pos++; console_pos++;
} }
console_buf[console_wr] = c;
console_wr = wr;
} }
// return previous character in console, 0 if at start // return previous character in console, 0 if at start
@ -41,11 +48,13 @@ tplConsole(HttpdConnData *connData, char *token, void **arg) {
if (token==NULL) return HTTPD_CGI_DONE; if (token==NULL) return HTTPD_CGI_DONE;
if (os_strcmp(token, "console") == 0) { if (os_strcmp(token, "console") == 0) {
if (console_wr < console_rd) { if (console_wr > console_rd) {
httpdSend(connData, console_buf+console_rd, console_wr-console_rd); httpdSend(connData, console_buf+console_rd, console_wr-console_rd);
} else if (console_rd != console_wr) { } else if (console_rd != console_wr) {
httpdSend(connData, console_buf+console_rd, BUF_MAX-console_rd); httpdSend(connData, console_buf+console_rd, BUF_MAX-console_rd);
httpdSend(connData, console_buf, console_wr); httpdSend(connData, console_buf, console_wr);
} else {
httpdSend(connData, "<buffer empty>", -1);
} }
} else if (os_strcmp(token, "head")==0) { } else if (os_strcmp(token, "head")==0) {
printHead(connData); printHead(connData);

@ -7,6 +7,7 @@
// The web log has a 1KB circular in-memory buffer which os_printf prints into and // The web log has a 1KB circular in-memory buffer which os_printf prints into and
// the HTTP handler simply displays the buffer content on a web page. // the HTTP handler simply displays the buffer content on a web page.
// see consolse.c for invariants (same here)
#define BUF_MAX (1024) #define BUF_MAX (1024)
static char log_buf[BUF_MAX]; static char log_buf[BUF_MAX];
static int log_wr, log_rd; static int log_wr, log_rd;
@ -27,11 +28,10 @@ log_uart(bool enable) {
static void ICACHE_FLASH_ATTR static void ICACHE_FLASH_ATTR
log_write(char c) { log_write(char c) {
int wr = (log_wr+1)%BUF_MAX;
if (wr == log_rd)
log_rd = (log_rd+1) % BUF_MAX; // full, eat first char
log_buf[log_wr] = c; log_buf[log_wr] = c;
log_wr = wr; log_wr = (log_wr+1) % BUF_MAX;
if (log_wr == log_rd)
log_rd = (log_rd+1) % BUF_MAX; // full, eat first char
} }
#if 0 #if 0
@ -74,6 +74,8 @@ tplLog(HttpdConnData *connData, char *token, void **arg) {
} else if (log_rd != log_wr) { } else if (log_rd != log_wr) {
httpdSend(connData, log_buf+log_rd, BUF_MAX-log_rd); httpdSend(connData, log_buf+log_rd, BUF_MAX-log_rd);
httpdSend(connData, log_buf, log_wr); httpdSend(connData, log_buf, log_wr);
} else {
httpdSend(connData, "<buffer empty>", -1);
} }
} else if (os_strcmp(token, "head")==0) { } else if (os_strcmp(token, "head")==0) {
printHead(connData); printHead(connData);

@ -2,7 +2,7 @@
#define STATUS_H #define STATUS_H
void statusWifiUpdate(uint8_t state); void statusWifiUpdate(uint8_t state);
void statusInit(void); void statusInit(uint8_t pin);
#endif #endif

@ -21,6 +21,7 @@
#include "uart.h" #include "uart.h"
#include "serbridge.h" #include "serbridge.h"
#include "status.h" #include "status.h"
#include "serled.h"
#include "console.h" #include "console.h"
#include "log.h" #include "log.h"
#define MCU_RESET 12 #define MCU_RESET 12
@ -59,7 +60,7 @@ should be placed above the URLs they protect.
*/ */
HttpdBuiltInUrl builtInUrls[]={ HttpdBuiltInUrl builtInUrls[]={
{"/", cgiRedirect, "/index.tpl"}, {"/", cgiRedirect, "/index.tpl"},
{"/flash/read", cgiReadFlash, NULL}, //{"/flash/read", cgiReadFlash, NULL},
{"/flash/next", cgiGetFirmwareNext, NULL}, {"/flash/next", cgiGetFirmwareNext, NULL},
{"/flash/upload", cgiUploadFirmware, NULL}, {"/flash/upload", cgiUploadFirmware, NULL},
{"/flash/reboot", cgiRebootFirmware, NULL}, {"/flash/reboot", cgiRebootFirmware, NULL},
@ -110,9 +111,12 @@ void user_init(void) {
uart_init(BIT_RATE_115200, BIT_RATE_115200); uart_init(BIT_RATE_115200, BIT_RATE_115200);
// say hello (leave some time to cause break in TX after boot loader's msg // say hello (leave some time to cause break in TX after boot loader's msg
os_delay_us(10000L); os_delay_us(10000L);
os_printf("\n\nInitializing esp-link\n"); # define VERS_STR_STR(V) #V
# define VERS_STR(V) VERS_STR_STR(V)
os_printf("\n\nInitializing esp-link\n" VERS_STR(VERSION) "\n");
// Status LEDs // Status LEDs
statusInit(); statusInit(LED_CONN_PIN);
serledInit(LED_SERIAL_PIN);
// Wifi // Wifi
wifiInit(); wifiInit();
// init the flash filesystem with the html stuff // init the flash filesystem with the html stuff
@ -121,7 +125,7 @@ void user_init(void) {
// mount the http handlers // mount the http handlers
httpdInit(builtInUrls, 80); httpdInit(builtInUrls, 80);
// init the wifi-serial transparent bridge (port 23) // init the wifi-serial transparent bridge (port 23)
serbridgeInit(23); serbridgeInit(23, MCU_RESET_PIN, MCU_ISP_PIN);
uart_add_recv_cb(&serbridgeUartCb); uart_add_recv_cb(&serbridgeUartCb);
#ifdef SHOW_HEAP_USE #ifdef SHOW_HEAP_USE
os_timer_disarm(&prHeapTimer); os_timer_disarm(&prHeapTimer);

@ -82,7 +82,7 @@ while true; do
next=`curl -m 10 $v -s "http://$hostname/flash/next"` next=`curl -m 10 $v -s "http://$hostname/flash/next"`
if [[ $? != 0 ]]; then if [[ $? != 0 ]]; then
echo "Error retrieving http://$hostname/flash/next" >&2 echo "Error retrieving http://$hostname/flash/next" >&2
break exit 1
fi fi
case "$next" in case "$next" in
user1.bin) user1.bin)
@ -94,8 +94,8 @@ while true; do
fw="$user2" fw="$user2"
break;; break;;
*) *)
echo "Cannot parse result of retrieving http://$hostname/flash/next" >&2 echo "Error retrieving or parsing http://$hostname/flash/next" >&2
sleep 2 exit 1
;; ;;
esac esac
done done

Loading…
Cancel
Save