diff options
Diffstat (limited to 'esp8266')
-rw-r--r-- | esp8266/Makefile | 20 | ||||
-rw-r--r-- | esp8266/README.md | 14 | ||||
-rw-r--r-- | esp8266/eagle.rom.addr.v6.ld | 32 | ||||
-rw-r--r-- | esp8266/esp_mphal.c | 14 | ||||
-rw-r--r-- | esp8266/fatfs_port.c | 41 | ||||
-rw-r--r-- | esp8266/main.c | 3 | ||||
-rw-r--r-- | esp8266/modesp.c | 6 | ||||
-rw-r--r-- | esp8266/modmachine.c | 2 | ||||
-rw-r--r-- | esp8266/modnetwork.c | 6 | ||||
-rw-r--r-- | esp8266/modpybrtc.c | 6 | ||||
-rw-r--r-- | esp8266/modpybrtc.h | 2 | ||||
-rw-r--r-- | esp8266/modpybuart.c | 103 | ||||
-rw-r--r-- | esp8266/modules/_boot.py (renamed from esp8266/scripts/_boot.py) | 3 | ||||
-rw-r--r-- | esp8266/modules/flashbdev.py (renamed from esp8266/scripts/flashbdev.py) | 0 | ||||
-rw-r--r-- | esp8266/modules/webrepl.py (renamed from esp8266/scripts/webrepl.py) | 0 | ||||
-rw-r--r-- | esp8266/modules/webrepl_setup.py (renamed from esp8266/scripts/webrepl_setup.py) | 0 | ||||
-rw-r--r-- | esp8266/mpconfigport.h | 2 | ||||
-rw-r--r-- | esp8266/scripts/inisetup.py | 2 | ||||
-rw-r--r-- | esp8266/scripts/websocket_helper.py | 19 | ||||
-rw-r--r-- | esp8266/uart.c | 6 | ||||
-rw-r--r-- | esp8266/uart.h | 1 |
21 files changed, 231 insertions, 51 deletions
diff --git a/esp8266/Makefile b/esp8266/Makefile index 65093d819b..00826cfe46 100644 --- a/esp8266/Makefile +++ b/esp8266/Makefile @@ -8,9 +8,12 @@ MICROPY_PY_USSL = 1 # include py core make definitions include ../py/py.mk +MPY_CROSS = ../mpy-cross/mpy-cross +MPY_TOOL = ../tools/mpy-tool.py MAKE_FROZEN = ../tools/make-frozen.py SCRIPTDIR = scripts +FROZEN_MPY_DIR = modules PORT ?= /dev/ttyACM0 BAUD ?= 115200 CROSS_COMPILE = xtensa-lx106-elf- @@ -131,6 +134,9 @@ DRIVERS_SRC_C = $(addprefix drivers/,\ SRC_S = \ gchelper.s \ +FROZEN_MPY_PY_FILES := $(shell find $(FROZEN_MPY_DIR)/ -type f -name '*.py') +FROZEN_MPY_MPY_FILES := $(addprefix $(BUILD)/,$(FROZEN_MPY_PY_FILES:.py=.mpy)) + OBJ = OBJ += $(PY_O) OBJ += $(addprefix $(BUILD)/, $(SRC_C:.c=.o)) @@ -139,6 +145,7 @@ OBJ += $(addprefix $(BUILD)/, $(STM_SRC_C:.c=.o)) OBJ += $(addprefix $(BUILD)/, $(EXTMOD_SRC_C:.c=.o)) OBJ += $(addprefix $(BUILD)/, $(LIB_SRC_C:.c=.o)) OBJ += $(addprefix $(BUILD)/, $(DRIVERS_SRC_C:.c=.o)) +OBJ += $(BUILD)/$(BUILD)/frozen_mpy.o #OBJ += $(BUILD)/pins_$(BOARD).o # List of sources for qstr extraction @@ -163,11 +170,22 @@ $(BUILD)/frozen.c: $(wildcard $(SCRIPTDIR)/*) $(CONFVARS_FILE) $(ECHO) "Generating $@" $(Q)$(MAKE_FROZEN) $(SCRIPTDIR) > $@ +# to build .mpy files from .py files +$(BUILD)/$(FROZEN_MPY_DIR)/%.mpy: $(FROZEN_MPY_DIR)/%.py + @$(ECHO) "MPY $<" + $(Q)$(MKDIR) -p $(dir $@) + $(Q)$(MPY_CROSS) -o $@ -s $(^:$(FROZEN_MPY_DIR)/%=%) $^ + +# to build frozen_mpy.c from all .mpy files +$(BUILD)/frozen_mpy.c: $(FROZEN_MPY_MPY_FILES) $(BUILD)/genhdr/qstrdefs.generated.h + @$(ECHO) "Creating $@" + $(Q)$(PYTHON) $(MPY_TOOL) -f -q $(BUILD)/genhdr/qstrdefs.preprocessed.h $(FROZEN_MPY_MPY_FILES) > $@ + .PHONY: deploy deploy: $(BUILD)/firmware-combined.bin $(ECHO) "Writing $< to the board" - $(Q)esptool.py --port $(PORT) --baud $(BAUD) write_flash --flash_size=8m 0 $< + $(Q)esptool.py --port $(PORT) --baud $(BAUD) write_flash --verify --flash_size=8m 0 $< #$(Q)esptool.py --port $(PORT) --baud $(BAUD) write_flash --flash_size=8m 0 $(BUILD)/firmware.elf-0x00000.bin 0x9000 $(BUILD)/firmware.elf-0x0[1-f]000.bin reset: diff --git a/esp8266/README.md b/esp8266/README.md index 0509a3799b..b9162e9585 100644 --- a/esp8266/README.md +++ b/esp8266/README.md @@ -1,12 +1,12 @@ MicroPython port to ESP8266 =========================== -This is a highly experimental port of MicroPython for the WiFi modules based +This is an experimental port of MicroPython for the WiFi modules based on Espressif ESP8266 chip. -WARNING: The port is highly experimental and any APIs are subject to change. +WARNING: The port is experimental and many APIs are subject to change. -Currently implemented features include: +Supported features include: - REPL (Python prompt) over UART0. - Garbage collector, exceptions. - Unicode support. @@ -19,6 +19,8 @@ Currently implemented features include: - 1-Wire and WS2812 (aka Neopixel) protocols support. - Internal filesystem using the flash. - WebREPL over WiFi from a browser (clients at https://github.com/micropython/webrepl). +- Modules for HTTP, MQTT, many other formats and protocols via + https://github.com/micropython/micropython-lib . Work-in-progress documentation is available at http://docs.micropython.org/en/latest/esp8266/ . @@ -39,6 +41,12 @@ $ git submodule update --init See the README in the repository root for more information about external dependencies. +The MicroPython cross-compiler must be built to pre-compile some of the +built-in scripts to bytecode. This can be done using: +```bash +$ make -C mpy-cross +``` + Then, to build MicroPython for the ESP8266, just run: ```bash $ cd esp8266 diff --git a/esp8266/eagle.rom.addr.v6.ld b/esp8266/eagle.rom.addr.v6.ld index 30e238f5a5..ce071a3bb9 100644 --- a/esp8266/eagle.rom.addr.v6.ld +++ b/esp8266/eagle.rom.addr.v6.ld @@ -47,25 +47,25 @@ PROVIDE ( _NMIExceptionVector = 0x40000020 ); PROVIDE ( _ResetHandler = 0x400000a4 ); PROVIDE ( _ResetVector = 0x40000080 ); PROVIDE ( _UserExceptionVector = 0x40000050 ); -PROVIDE ( __adddf3 = 0x4000c538 ); -PROVIDE ( __addsf3 = 0x4000c180 ); -PROVIDE ( __divdf3 = 0x4000cb94 ); +__adddf3 = 0x4000c538; +__addsf3 = 0x4000c180; +__divdf3 = 0x4000cb94; __divdi3 = 0x4000ce60; __divsi3 = 0x4000dc88; -PROVIDE ( __extendsfdf2 = 0x4000cdfc ); -PROVIDE ( __fixdfsi = 0x4000ccb8 ); -PROVIDE ( __fixunsdfsi = 0x4000cd00 ); -PROVIDE ( __fixunssfsi = 0x4000c4c4 ); -PROVIDE ( __floatsidf = 0x4000e2f0 ); -PROVIDE ( __floatsisf = 0x4000e2ac ); -PROVIDE ( __floatunsidf = 0x4000e2e8 ); -PROVIDE ( __floatunsisf = 0x4000e2a4 ); -PROVIDE ( __muldf3 = 0x4000c8f0 ); +__extendsfdf2 = 0x4000cdfc; +__fixdfsi = 0x4000ccb8; +__fixunsdfsi = 0x4000cd00; +__fixunssfsi = 0x4000c4c4; +__floatsidf = 0x4000e2f0; +__floatsisf = 0x4000e2ac; +__floatunsidf = 0x4000e2e8; +__floatunsisf = 0x4000e2a4; +__muldf3 = 0x4000c8f0; __muldi3 = 0x40000650; -PROVIDE ( __mulsf3 = 0x4000c3dc ); -PROVIDE ( __subdf3 = 0x4000c688 ); -PROVIDE ( __subsf3 = 0x4000c268 ); -PROVIDE ( __truncdfsf2 = 0x4000cd5c ); +__mulsf3 = 0x4000c3dc; +__subdf3 = 0x4000c688; +__subsf3 = 0x4000c268; +__truncdfsf2 = 0x4000cd5c; __udivdi3 = 0x4000d310; __udivsi3 = 0x4000e21c; __umoddi3 = 0x4000d770; diff --git a/esp8266/esp_mphal.c b/esp8266/esp_mphal.c index 9f090a0973..3cc4610825 100644 --- a/esp8266/esp_mphal.c +++ b/esp8266/esp_mphal.c @@ -161,21 +161,21 @@ static int call_dupterm_read(void) { nlr_buf_t nlr; if (nlr_push(&nlr) == 0) { - mp_obj_t read_m[3]; - mp_load_method(MP_STATE_PORT(term_obj), MP_QSTR_read, read_m); - read_m[2] = MP_OBJ_NEW_SMALL_INT(1); - mp_obj_t res = mp_call_method_n_kw(1, 0, read_m); + mp_obj_t readinto_m[3]; + mp_load_method(MP_STATE_PORT(term_obj), MP_QSTR_readinto, readinto_m); + readinto_m[2] = MP_STATE_PORT(dupterm_arr_obj); + mp_obj_t res = mp_call_method_n_kw(1, 0, readinto_m); if (res == mp_const_none) { nlr_pop(); return -2; } - mp_buffer_info_t bufinfo; - mp_get_buffer_raise(res, &bufinfo, MP_BUFFER_READ); - if (bufinfo.len == 0) { + if (res == MP_OBJ_NEW_SMALL_INT(0)) { mp_uos_deactivate("dupterm: EOF received, deactivating\n", MP_OBJ_NULL); nlr_pop(); return -1; } + mp_buffer_info_t bufinfo; + mp_get_buffer_raise(MP_STATE_PORT(dupterm_arr_obj), &bufinfo, MP_BUFFER_READ); nlr_pop(); if (*(byte*)bufinfo.buf == interrupt_char) { mp_keyboard_interrupt(); diff --git a/esp8266/fatfs_port.c b/esp8266/fatfs_port.c index c62ae2e7dc..b87906f789 100644 --- a/esp8266/fatfs_port.c +++ b/esp8266/fatfs_port.c @@ -1,6 +1,43 @@ +/* + * This file is part of the Micro Python project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2013, 2014, 2016 Damien P. George + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "py/obj.h" #include "lib/fatfs/ff.h" -#include "lib/fatfs/diskio.h" +#include "timeutils.h" +#include "modpybrtc.h" DWORD get_fattime(void) { - return 0; + + // TODO: Optimize division (there's no HW division support on ESP8266, + // so it's expensive). + uint32_t secs = (uint32_t)(pyb_rtc_get_us_since_2000() / 1000000); + + timeutils_struct_time_t tm; + timeutils_seconds_since_2000_to_struct_time(secs, &tm); + + return (((DWORD)(tm.tm_year - 1980) << 25) | ((DWORD)tm.tm_mon << 21) | ((DWORD)tm.tm_mday << 16) | + ((DWORD)tm.tm_hour << 11) | ((DWORD)tm.tm_min << 5) | ((DWORD)tm.tm_sec >> 1)); } diff --git a/esp8266/main.c b/esp8266/main.c index 9cc955e44c..21bb6e0e0f 100644 --- a/esp8266/main.c +++ b/esp8266/main.c @@ -34,6 +34,7 @@ #include "py/stackctrl.h" #include "py/mphal.h" #include "py/gc.h" +#include "lib/mp-readline/readline.h" #include "lib/utils/pyexec.h" #include "gccollect.h" #include "user_interface.h" @@ -56,7 +57,9 @@ STATIC void mp_reset(void) { #endif MP_STATE_PORT(mp_kbd_exception) = mp_obj_new_exception(&mp_type_KeyboardInterrupt); MP_STATE_PORT(term_obj) = MP_OBJ_NULL; + MP_STATE_PORT(dupterm_arr_obj) = MP_OBJ_NULL; pin_init0(); + readline_init0(); #if MICROPY_MODULE_FROZEN pyexec_frozen_module("_boot.py"); pyexec_file("boot.py"); diff --git a/esp8266/modesp.c b/esp8266/modesp.c index 0c6cc423e1..99f063a756 100644 --- a/esp8266/modesp.c +++ b/esp8266/modesp.c @@ -46,6 +46,7 @@ #include "espneopixel.h" #include "espapa102.h" #include "modpyb.h" +#include "modpybrtc.h" #define MODESP_ESPCONN (0) @@ -540,8 +541,11 @@ STATIC mp_obj_t esp_sleep_type(mp_uint_t n_args, const mp_obj_t *args) { STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(esp_sleep_type_obj, 0, 1, esp_sleep_type); STATIC mp_obj_t esp_deepsleep(mp_uint_t n_args, const mp_obj_t *args) { + uint32_t sleep_us = n_args > 0 ? mp_obj_get_int(args[0]) : 0; + // prepare for RTC reset at wake up + rtc_prepare_deepsleep(sleep_us); system_deep_sleep_set_option(n_args > 1 ? mp_obj_get_int(args[1]) : 0); - system_deep_sleep(n_args > 0 ? mp_obj_get_int(args[0]) : 0); + system_deep_sleep(sleep_us); return mp_const_none; } STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(esp_deepsleep_obj, 0, 2, esp_deepsleep); diff --git a/esp8266/modmachine.c b/esp8266/modmachine.c index 36872c9dff..80ae7ac2a0 100644 --- a/esp8266/modmachine.c +++ b/esp8266/modmachine.c @@ -103,6 +103,8 @@ STATIC mp_obj_t machine_deepsleep(void) { } } + // prepare for RTC reset at wake up + rtc_prepare_deepsleep(sleep_us); // put the device in a deep-sleep state system_deep_sleep_set_option(0); // default power down mode; TODO check this system_deep_sleep(sleep_us); diff --git a/esp8266/modnetwork.c b/esp8266/modnetwork.c index c0763ce0eb..7cfa3ff77a 100644 --- a/esp8266/modnetwork.c +++ b/esp8266/modnetwork.c @@ -142,7 +142,13 @@ STATIC void esp_scan_cb(scaninfo *si, STATUS status) { struct bss_info *bs; STAILQ_FOREACH(bs, si->pbss, next) { mp_obj_tuple_t *t = mp_obj_new_tuple(6, NULL); + #if 1 + // struct bss_info::ssid_len is not documented in SDK API Guide, + // but is present in SDK headers since 1.4.0 + t->items[0] = mp_obj_new_bytes(bs->ssid, bs->ssid_len); + #else t->items[0] = mp_obj_new_bytes(bs->ssid, strlen((char*)bs->ssid)); + #endif t->items[1] = mp_obj_new_bytes(bs->bssid, sizeof(bs->bssid)); t->items[2] = MP_OBJ_NEW_SMALL_INT(bs->channel); t->items[3] = MP_OBJ_NEW_SMALL_INT(bs->rssi); diff --git a/esp8266/modpybrtc.c b/esp8266/modpybrtc.c index 484d0d82fd..9685248034 100644 --- a/esp8266/modpybrtc.c +++ b/esp8266/modpybrtc.c @@ -120,6 +120,12 @@ uint64_t pyb_rtc_get_us_since_2000() { return (((uint64_t)rtc_ticks * cal) >> 12) + delta; }; +void rtc_prepare_deepsleep(uint64_t sleep_us) { + // RTC time will reset at wake up. Let's be preared for this. + int64_t delta = pyb_rtc_get_us_since_2000() + sleep_us; + system_rtc_mem_write(MEM_DELTA_ADDR, &delta, sizeof(delta)); +} + STATIC mp_obj_t pyb_rtc_datetime(mp_uint_t n_args, const mp_obj_t *args) { if (n_args == 1) { // Get time diff --git a/esp8266/modpybrtc.h b/esp8266/modpybrtc.h index b4ca780712..5b9d9fc766 100644 --- a/esp8266/modpybrtc.h +++ b/esp8266/modpybrtc.h @@ -30,3 +30,5 @@ extern uint64_t pyb_rtc_alarm0_expiry; void pyb_rtc_set_us_since_2000(uint64_t nowus); uint64_t pyb_rtc_get_us_since_2000(); + +void rtc_prepare_deepsleep(uint64_t sleep_us); diff --git a/esp8266/modpybuart.c b/esp8266/modpybuart.c index 5971ffecec..f27ee4e2d2 100644 --- a/esp8266/modpybuart.c +++ b/esp8266/modpybuart.c @@ -36,32 +36,39 @@ #include "py/mperrno.h" #include "modpyb.h" -// baudrate is currently fixed to this value -#define UART_BAUDRATE (115200) +// UartDev is defined and initialized in rom code. +extern UartDevice UartDev; typedef struct _pyb_uart_obj_t { mp_obj_base_t base; uint8_t uart_id; + uint8_t bits; + uint8_t parity; + uint8_t stop; + uint32_t baudrate; uint16_t timeout; // timeout waiting for first char (in ms) uint16_t timeout_char; // timeout waiting between chars (in ms) } pyb_uart_obj_t; +STATIC const char *_parity_name[] = {"None", "1", "0"}; + /******************************************************************************/ // MicroPython bindings for UART STATIC void pyb_uart_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { pyb_uart_obj_t *self = MP_OBJ_TO_PTR(self_in); - mp_printf(print, "UART(%u, baudrate=%u, timeout=%u, timeout_char=%u)", - self->uart_id, UART_BAUDRATE, self->timeout, self->timeout_char); + mp_printf(print, "UART(%u, baudrate=%u, bits=%u, parity=%s, stop=%u, timeout=%u, timeout_char=%u)", + self->uart_id, self->baudrate, self->bits, _parity_name[self->parity], + self->stop, self->timeout, self->timeout_char); } STATIC void pyb_uart_init_helper(pyb_uart_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { - enum { ARG_timeout, ARG_timeout_char }; + enum { ARG_baudrate, ARG_bits, ARG_parity, ARG_stop, ARG_timeout, ARG_timeout_char }; static const mp_arg_t allowed_args[] = { - //{ MP_QSTR_baudrate, MP_ARG_REQUIRED | MP_ARG_INT, {.u_int = 9600} }, - //{ MP_QSTR_bits, MP_ARG_INT, {.u_int = 8} }, - //{ MP_QSTR_parity, MP_ARG_OBJ, {.u_obj = mp_const_none} }, - //{ MP_QSTR_stop, MP_ARG_INT, {.u_int = 1} }, + { MP_QSTR_baudrate, MP_ARG_INT, {.u_int = 0} }, + { MP_QSTR_bits, MP_ARG_INT, {.u_int = 0} }, + { MP_QSTR_parity, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, + { MP_QSTR_stop, MP_ARG_INT, {.u_int = 0} }, //{ MP_QSTR_tx, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, //{ MP_QSTR_rx, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, { MP_QSTR_timeout, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0} }, @@ -70,16 +77,84 @@ STATIC void pyb_uart_init_helper(pyb_uart_obj_t *self, size_t n_args, const mp_o mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + // set baudrate + if (args[ARG_baudrate].u_int > 0) { + self->baudrate = args[ARG_baudrate].u_int; + UartDev.baut_rate = self->baudrate; // Sic! + } + + // set data bits + switch (args[ARG_bits].u_int) { + case 0: + break; + case 5: + UartDev.data_bits = UART_FIVE_BITS; + self->bits = 5; + break; + case 6: + UartDev.data_bits = UART_SIX_BITS; + self->bits = 6; + break; + case 7: + UartDev.data_bits = UART_SEVEN_BITS; + self->bits = 7; + break; + case 8: + UartDev.data_bits = UART_EIGHT_BITS; + self->bits = 8; + break; + default: + nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "invalid data bits")); + break; + } + + // set parity + if (args[ARG_parity].u_obj != MP_OBJ_NULL) { + if (args[ARG_parity].u_obj == mp_const_none) { + UartDev.parity = UART_NONE_BITS; + self->parity = 0; + } else { + mp_int_t parity = mp_obj_get_int(args[ARG_parity].u_obj); + if (parity & 1) { + UartDev.parity = UART_ODD_BITS; + self->parity = 1; + } else { + UartDev.parity = UART_EVEN_BITS; + self->parity = 2; + } + } + } + + // set stop bits + switch (args[ARG_stop].u_int) { + case 0: + break; + case 1: + UartDev.stop_bits = UART_ONE_STOP_BIT; + self->stop = 1; + break; + case 2: + UartDev.stop_bits = UART_TWO_STOP_BIT; + self->stop = 2; + break; + default: + nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "invalid stop bits")); + break; + } + // set timeout self->timeout = args[ARG_timeout].u_int; // set timeout_char // make sure it is at least as long as a whole character (13 bits to be safe) self->timeout_char = args[ARG_timeout_char].u_int; - uint32_t min_timeout_char = 13000 / UART_BAUDRATE + 1; + uint32_t min_timeout_char = 13000 / self->baudrate + 1; if (self->timeout_char < min_timeout_char) { self->timeout_char = min_timeout_char; } + + // setup + uart_setup(self->uart_id); } STATIC mp_obj_t pyb_uart_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { @@ -95,6 +170,12 @@ STATIC mp_obj_t pyb_uart_make_new(const mp_obj_type_t *type, size_t n_args, size pyb_uart_obj_t *self = m_new_obj(pyb_uart_obj_t); self->base.type = &pyb_uart_type; self->uart_id = uart_id; + self->baudrate = 115200; + self->bits = 8; + self->parity = 0; + self->stop = 1; + self->timeout = 0; + self->timeout_char = 0; // init the peripheral mp_map_t kw_args; @@ -191,6 +272,6 @@ const mp_obj_type_t pyb_uart_type = { .make_new = pyb_uart_make_new, .getiter = mp_identity, .iternext = mp_stream_unbuffered_iter, - .stream_p = &uart_stream_p, + .protocol = &uart_stream_p, .locals_dict = (mp_obj_dict_t*)&pyb_uart_locals_dict, }; diff --git a/esp8266/scripts/_boot.py b/esp8266/modules/_boot.py index c950de6758..2cacb56760 100644 --- a/esp8266/scripts/_boot.py +++ b/esp8266/modules/_boot.py @@ -1,3 +1,4 @@ +import gc import uos from flashbdev import bdev @@ -7,3 +8,5 @@ try: except OSError: import inisetup vfs = inisetup.setup() + +gc.collect() diff --git a/esp8266/scripts/flashbdev.py b/esp8266/modules/flashbdev.py index 07ed966020..07ed966020 100644 --- a/esp8266/scripts/flashbdev.py +++ b/esp8266/modules/flashbdev.py diff --git a/esp8266/scripts/webrepl.py b/esp8266/modules/webrepl.py index da3e70c595..da3e70c595 100644 --- a/esp8266/scripts/webrepl.py +++ b/esp8266/modules/webrepl.py diff --git a/esp8266/scripts/webrepl_setup.py b/esp8266/modules/webrepl_setup.py index d0bf8465d5..d0bf8465d5 100644 --- a/esp8266/scripts/webrepl_setup.py +++ b/esp8266/modules/webrepl_setup.py diff --git a/esp8266/mpconfigport.h b/esp8266/mpconfigport.h index 544edc408f..90dbc00098 100644 --- a/esp8266/mpconfigport.h +++ b/esp8266/mpconfigport.h @@ -74,7 +74,9 @@ #define MICROPY_ERROR_REPORTING (MICROPY_ERROR_REPORTING_NORMAL) #define MICROPY_STREAMS_NON_BLOCK (1) #define MICROPY_MODULE_FROZEN_STR (1) +#define MICROPY_MODULE_FROZEN_MPY (1) #define MICROPY_MODULE_FROZEN_LEXER mp_lexer_new_from_str32 +#define MICROPY_QSTR_EXTRA_POOL mp_qstr_frozen_const_pool #define MICROPY_FATFS_ENABLE_LFN (1) #define MICROPY_FATFS_RPATH (2) diff --git a/esp8266/scripts/inisetup.py b/esp8266/scripts/inisetup.py index 461690b162..7d8f6fa0a8 100644 --- a/esp8266/scripts/inisetup.py +++ b/esp8266/scripts/inisetup.py @@ -40,7 +40,9 @@ def setup(): with open("/boot.py", "w") as f: f.write("""\ # This file is executed on every boot (including wake-boot from deepsleep) +import gc #import webrepl #webrepl.start() +gc.collect() """) return vfs diff --git a/esp8266/scripts/websocket_helper.py b/esp8266/scripts/websocket_helper.py index 22ac28592d..9c06db5023 100644 --- a/esp8266/scripts/websocket_helper.py +++ b/esp8266/scripts/websocket_helper.py @@ -36,21 +36,20 @@ def server_handshake(sock): if DEBUG: print("Sec-WebSocket-Key:", webkey, len(webkey)) - respkey = webkey + b"258EAFA5-E914-47DA-95CA-C5AB0DC85B11" - respkey = hashlib.sha1(respkey).digest() + d = hashlib.sha1(webkey) + d.update(b"258EAFA5-E914-47DA-95CA-C5AB0DC85B11") + respkey = d.digest() respkey = binascii.b2a_base64(respkey)[:-1] + if DEBUG: + print("respkey:", respkey) - resp = b"""\ + sock.send(b"""\ HTTP/1.1 101 Switching Protocols\r Upgrade: websocket\r Connection: Upgrade\r -Sec-WebSocket-Accept: %s\r -\r -""" % respkey - - if DEBUG: - print(resp) - sock.send(resp) +Sec-WebSocket-Accept: """) + sock.send(respkey) + sock.send("\r\n\r\n") # Very simplified client handshake, works for MicroPython's diff --git a/esp8266/uart.c b/esp8266/uart.c index 1c317a1cb6..d724331c41 100644 --- a/esp8266/uart.c +++ b/esp8266/uart.c @@ -237,6 +237,12 @@ void ICACHE_FLASH_ATTR uart_reattach() { uart_init(UART_BIT_RATE_74880, UART_BIT_RATE_74880); } +void ICACHE_FLASH_ATTR uart_setup(uint8 uart) { + ETS_UART_INTR_DISABLE(); + uart_config(uart); + ETS_UART_INTR_ENABLE(); +} + // Task-based UART interface #include "py/obj.h" diff --git a/esp8266/uart.h b/esp8266/uart.h index 8e09beea58..21894d3fa6 100644 --- a/esp8266/uart.h +++ b/esp8266/uart.h @@ -96,5 +96,6 @@ int uart_rx_char(void); void uart_tx_one_char(uint8 uart, uint8 TxChar); void uart_flush(uint8 uart); void uart_os_config(int uart); +void uart_setup(uint8 uart); #endif // _INCLUDED_UART_H_ |