From db4e0092170914f2d74b5946f56789f36add2e27 Mon Sep 17 00:00:00 2001 From: Radomir Dopieralski Date: Tue, 11 Oct 2016 12:22:36 +0200 Subject: esp8266/mpconfigport: Enable MICROPY_PY_BUILTINS_SLICE_ATTRS --- esp8266/mpconfigport.h | 1 + 1 file changed, 1 insertion(+) (limited to 'esp8266') diff --git a/esp8266/mpconfigport.h b/esp8266/mpconfigport.h index 19cf9a679..5f65e920f 100644 --- a/esp8266/mpconfigport.h +++ b/esp8266/mpconfigport.h @@ -33,6 +33,7 @@ #define MICROPY_PY_BUILTINS_FROZENSET (1) #define MICROPY_PY_BUILTINS_SET (1) #define MICROPY_PY_BUILTINS_SLICE (1) +#define MICROPY_PY_BUILTINS_SLICE_ATTRS (1) #define MICROPY_PY_BUILTINS_PROPERTY (1) #define MICROPY_PY___FILE__ (0) #define MICROPY_PY_GC (1) -- cgit v1.2.3 From 11fc6553e831885d993c8a6c09ae98aa74fdf6b7 Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 11 Oct 2016 16:22:21 +1100 Subject: esp8266: Enable sys.{stdin,stdout,stderr}.buffer for raw serial access. --- esp8266/mpconfigport.h | 1 + 1 file changed, 1 insertion(+) (limited to 'esp8266') diff --git a/esp8266/mpconfigport.h b/esp8266/mpconfigport.h index 5f65e920f..ee32a848d 100644 --- a/esp8266/mpconfigport.h +++ b/esp8266/mpconfigport.h @@ -50,6 +50,7 @@ #define MICROPY_PY_SYS_MAXSIZE (1) #define MICROPY_PY_SYS_EXIT (1) #define MICROPY_PY_SYS_STDFILES (1) +#define MICROPY_PY_SYS_STDIO_BUFFER (1) #define MICROPY_PY_UERRNO (1) #define MICROPY_PY_UBINASCII (1) #define MICROPY_PY_UCTYPES (1) -- cgit v1.2.3 From af8d791bd09e2d735ec59424ec05f495348d99e7 Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 11 Oct 2016 16:23:20 +1100 Subject: esp8266: Enable importing of precompiled .mpy files. --- esp8266/mpconfigport.h | 1 + py/emitglue.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'esp8266') diff --git a/esp8266/mpconfigport.h b/esp8266/mpconfigport.h index ee32a848d..33f319f69 100644 --- a/esp8266/mpconfigport.h +++ b/esp8266/mpconfigport.h @@ -9,6 +9,7 @@ #define MICROPY_ALLOC_PARSE_RULE_INC (8) #define MICROPY_ALLOC_PARSE_RESULT_INC (8) #define MICROPY_ALLOC_PARSE_CHUNK_INIT (64) +#define MICROPY_PERSISTENT_CODE_LOAD (1) #define MICROPY_EMIT_X64 (0) #define MICROPY_EMIT_THUMB (0) #define MICROPY_EMIT_INLINE_THUMB (0) diff --git a/py/emitglue.c b/py/emitglue.c index f4b59df3e..dc5be6e0e 100644 --- a/py/emitglue.c +++ b/py/emitglue.c @@ -425,7 +425,7 @@ mp_raw_code_t *mp_raw_code_load_file(const char *filename) { return rc; } -#elif defined(__thumb2__) +#elif defined(__thumb2__) || defined(__xtensa__) // fatfs file reader (assume thumb2 arch uses fatfs...) #include "lib/fatfs/ff.h" -- cgit v1.2.3 From ed878275b020c006ec197bb5f5bdd8179fb36a4c Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 14 Oct 2016 01:27:53 +1100 Subject: esp8266: Enable micropython.alloc_emergency_exception_buf(). --- esp8266/mpconfigport.h | 1 + 1 file changed, 1 insertion(+) (limited to 'esp8266') diff --git a/esp8266/mpconfigport.h b/esp8266/mpconfigport.h index 33f319f69..6d0deba8d 100644 --- a/esp8266/mpconfigport.h +++ b/esp8266/mpconfigport.h @@ -18,6 +18,7 @@ #define MICROPY_DEBUG_PRINTER_DEST mp_debug_print #define MICROPY_ENABLE_GC (1) #define MICROPY_STACK_CHECK (1) +#define MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF (1) #define MICROPY_REPL_EVENT_DRIVEN (0) #define MICROPY_REPL_AUTO_INDENT (1) #define MICROPY_HELPER_REPL (1) -- cgit v1.2.3 From a97284423eba9470c16c5f02fadea14bd8263751 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Fri, 14 Oct 2016 20:13:02 +0300 Subject: extmod/utime_mphal: Factor out implementations in terms of mp_hal_* for reuse. As long as a port implement mp_hal_sleep_ms(), mp_hal_ticks_ms(), etc. functions, it can just use standard implementations of utime.sleel_ms(), utime.ticks_ms(), etc. Python-level functions. --- esp8266/modutime.c | 62 +++++-------------------------------- esp8266/mpconfigport.h | 1 + extmod/utime_mphal.c | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++ extmod/utime_mphal.h | 36 ++++++++++++++++++++++ py/mpconfig.h | 6 ++++ py/mphal.h | 4 +++ py/py.mk | 1 + 7 files changed, 139 insertions(+), 54 deletions(-) create mode 100644 extmod/utime_mphal.c create mode 100644 extmod/utime_mphal.h (limited to 'esp8266') diff --git a/esp8266/modutime.c b/esp8266/modutime.c index 4b94ace74..abfe069cc 100644 --- a/esp8266/modutime.c +++ b/esp8266/modutime.c @@ -38,6 +38,7 @@ #include "modpybrtc.h" #include "timeutils.h" #include "user_interface.h" +#include "extmod/utime_mphal.h" /// \module time - time related functions /// @@ -99,53 +100,6 @@ STATIC mp_obj_t time_mktime(mp_obj_t tuple) { } MP_DEFINE_CONST_FUN_OBJ_1(time_mktime_obj, time_mktime); -/// \function sleep(seconds) -/// Sleep for the given number of seconds. -STATIC mp_obj_t time_sleep(mp_obj_t seconds_o) { - #if MICROPY_PY_BUILTINS_FLOAT - mp_hal_delay_ms(1000 * mp_obj_get_float(seconds_o)); - #else - mp_hal_delay_ms(1000 * mp_obj_get_int(seconds_o)); - #endif - return mp_const_none; -} -MP_DEFINE_CONST_FUN_OBJ_1(time_sleep_obj, time_sleep); - -STATIC mp_obj_t time_sleep_ms(mp_obj_t arg) { - mp_hal_delay_ms(mp_obj_get_int(arg)); - return mp_const_none; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_1(time_sleep_ms_obj, time_sleep_ms); - -STATIC mp_obj_t time_sleep_us(mp_obj_t arg) { - mp_hal_delay_us(mp_obj_get_int(arg)); - return mp_const_none; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_1(time_sleep_us_obj, time_sleep_us); - -STATIC mp_obj_t time_ticks_ms(void) { - return MP_OBJ_NEW_SMALL_INT(mp_hal_ticks_ms() & MP_SMALL_INT_POSITIVE_MASK); -} -STATIC MP_DEFINE_CONST_FUN_OBJ_0(time_ticks_ms_obj, time_ticks_ms); - -STATIC mp_obj_t time_ticks_us(void) { - return MP_OBJ_NEW_SMALL_INT(mp_hal_ticks_us() & MP_SMALL_INT_POSITIVE_MASK); -} -STATIC MP_DEFINE_CONST_FUN_OBJ_0(time_ticks_us_obj, time_ticks_us); - -STATIC mp_obj_t time_ticks_cpu(void) { - return MP_OBJ_NEW_SMALL_INT(mp_hal_ticks_cpu() & MP_SMALL_INT_POSITIVE_MASK); -} -STATIC MP_DEFINE_CONST_FUN_OBJ_0(time_ticks_cpu_obj, time_ticks_cpu); - -STATIC mp_obj_t time_ticks_diff(mp_obj_t start_in, mp_obj_t end_in) { - // we assume that the arguments come from ticks_xx so are small ints - uint32_t start = MP_OBJ_SMALL_INT_VALUE(start_in); - uint32_t end = MP_OBJ_SMALL_INT_VALUE(end_in); - return MP_OBJ_NEW_SMALL_INT((end - start) & MP_SMALL_INT_POSITIVE_MASK); -} -STATIC MP_DEFINE_CONST_FUN_OBJ_2(time_ticks_diff_obj, time_ticks_diff); - /// \function time() /// Returns the number of seconds, as an integer, since 1/1/2000. STATIC mp_obj_t time_time(void) { @@ -159,13 +113,13 @@ STATIC const mp_map_elem_t time_module_globals_table[] = { { MP_OBJ_NEW_QSTR(MP_QSTR_localtime), (mp_obj_t)&time_localtime_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_mktime), (mp_obj_t)&time_mktime_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_sleep), (mp_obj_t)&time_sleep_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_sleep_ms), (mp_obj_t)&time_sleep_ms_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_sleep_us), (mp_obj_t)&time_sleep_us_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_ticks_ms), (mp_obj_t)&time_ticks_ms_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_ticks_us), (mp_obj_t)&time_ticks_us_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_ticks_cpu), (mp_obj_t)&time_ticks_cpu_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_ticks_diff), (mp_obj_t)&time_ticks_diff_obj }, + { MP_OBJ_NEW_QSTR(MP_QSTR_sleep), (mp_obj_t)&mp_utime_sleep_obj }, + { MP_OBJ_NEW_QSTR(MP_QSTR_sleep_ms), (mp_obj_t)&mp_utime_sleep_ms_obj }, + { MP_OBJ_NEW_QSTR(MP_QSTR_sleep_us), (mp_obj_t)&mp_utime_sleep_us_obj }, + { MP_OBJ_NEW_QSTR(MP_QSTR_ticks_ms), (mp_obj_t)&mp_utime_ticks_ms_obj }, + { MP_OBJ_NEW_QSTR(MP_QSTR_ticks_us), (mp_obj_t)&mp_utime_ticks_us_obj }, + { MP_OBJ_NEW_QSTR(MP_QSTR_ticks_cpu), (mp_obj_t)&mp_utime_ticks_cpu_obj }, + { MP_OBJ_NEW_QSTR(MP_QSTR_ticks_diff), (mp_obj_t)&mp_utime_ticks_diff_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_time), (mp_obj_t)&time_time_obj }, }; diff --git a/esp8266/mpconfigport.h b/esp8266/mpconfigport.h index 6d0deba8d..201057f12 100644 --- a/esp8266/mpconfigport.h +++ b/esp8266/mpconfigport.h @@ -62,6 +62,7 @@ #define MICROPY_PY_UJSON (1) #define MICROPY_PY_URANDOM (1) #define MICROPY_PY_URE (1) +#define MICROPY_PY_UTIME_MP_HAL (1) #define MICROPY_PY_UZLIB (1) #define MICROPY_PY_LWIP (1) #define MICROPY_PY_MACHINE (1) diff --git a/extmod/utime_mphal.c b/extmod/utime_mphal.c new file mode 100644 index 000000000..9471ad525 --- /dev/null +++ b/extmod/utime_mphal.c @@ -0,0 +1,83 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2013-2016 Damien P. George + * Copyright (c) 2016 Paul Sokolovsky + * + * 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/mpconfig.h" +#if MICROPY_PY_UTIME_MP_HAL + +#include + +#include "py/obj.h" +#include "py/mphal.h" +#include "py/smallint.h" +#include "extmod/utime_mphal.h" + +STATIC mp_obj_t time_sleep(mp_obj_t seconds_o) { + #if MICROPY_PY_BUILTINS_FLOAT + mp_hal_delay_ms(1000 * mp_obj_get_float(seconds_o)); + #else + mp_hal_delay_ms(1000 * mp_obj_get_int(seconds_o)); + #endif + return mp_const_none; +} +MP_DEFINE_CONST_FUN_OBJ_1(mp_utime_sleep_obj, time_sleep); + +STATIC mp_obj_t time_sleep_ms(mp_obj_t arg) { + mp_hal_delay_ms(mp_obj_get_int(arg)); + return mp_const_none; +} +MP_DEFINE_CONST_FUN_OBJ_1(mp_utime_sleep_ms_obj, time_sleep_ms); + +STATIC mp_obj_t time_sleep_us(mp_obj_t arg) { + mp_hal_delay_us(mp_obj_get_int(arg)); + return mp_const_none; +} +MP_DEFINE_CONST_FUN_OBJ_1(mp_utime_sleep_us_obj, time_sleep_us); + +STATIC mp_obj_t time_ticks_ms(void) { + return MP_OBJ_NEW_SMALL_INT(mp_hal_ticks_ms() & MP_SMALL_INT_POSITIVE_MASK); +} +MP_DEFINE_CONST_FUN_OBJ_0(mp_utime_ticks_ms_obj, time_ticks_ms); + +STATIC mp_obj_t time_ticks_us(void) { + return MP_OBJ_NEW_SMALL_INT(mp_hal_ticks_us() & MP_SMALL_INT_POSITIVE_MASK); +} +MP_DEFINE_CONST_FUN_OBJ_0(mp_utime_ticks_us_obj, time_ticks_us); + +STATIC mp_obj_t time_ticks_cpu(void) { + return MP_OBJ_NEW_SMALL_INT(mp_hal_ticks_cpu() & MP_SMALL_INT_POSITIVE_MASK); +} +MP_DEFINE_CONST_FUN_OBJ_0(mp_utime_ticks_cpu_obj, time_ticks_cpu); + +STATIC mp_obj_t time_ticks_diff(mp_obj_t start_in, mp_obj_t end_in) { + // we assume that the arguments come from ticks_xx so are small ints + uint32_t start = MP_OBJ_SMALL_INT_VALUE(start_in); + uint32_t end = MP_OBJ_SMALL_INT_VALUE(end_in); + return MP_OBJ_NEW_SMALL_INT((end - start) & MP_SMALL_INT_POSITIVE_MASK); +} +MP_DEFINE_CONST_FUN_OBJ_2(mp_utime_ticks_diff_obj, time_ticks_diff); + +#endif // MICROPY_PY_UTIME_MP_HAL diff --git a/extmod/utime_mphal.h b/extmod/utime_mphal.h new file mode 100644 index 000000000..4f2395a09 --- /dev/null +++ b/extmod/utime_mphal.h @@ -0,0 +1,36 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2013-2016 Damien P. George + * Copyright (c) 2016 Paul Sokolovsky + * + * 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" + +MP_DECLARE_CONST_FUN_OBJ(mp_utime_sleep_obj); +MP_DECLARE_CONST_FUN_OBJ(mp_utime_sleep_ms_obj); +MP_DECLARE_CONST_FUN_OBJ(mp_utime_sleep_us_obj); +MP_DECLARE_CONST_FUN_OBJ(mp_utime_ticks_ms_obj); +MP_DECLARE_CONST_FUN_OBJ(mp_utime_ticks_us_obj); +MP_DECLARE_CONST_FUN_OBJ(mp_utime_ticks_cpu_obj); +MP_DECLARE_CONST_FUN_OBJ(mp_utime_ticks_diff_obj); diff --git a/py/mpconfig.h b/py/mpconfig.h index e33a41f7a..dcdaffe0f 100644 --- a/py/mpconfig.h +++ b/py/mpconfig.h @@ -860,6 +860,12 @@ typedef double mp_float_t; #define MICROPY_PY_UERRNO (0) #endif +// Whether to provide "utime" module functions implementation +// in terms of mp_hal_* functions. +#ifndef MICROPY_PY_UTIME_MP_HAL +#define MICROPY_PY_UTIME_MP_HAL (0) +#endif + // Whether to provide "_thread" module #ifndef MICROPY_PY_THREAD #define MICROPY_PY_THREAD (0) diff --git a/py/mphal.h b/py/mphal.h index 54a45b024..8d5654f9e 100644 --- a/py/mphal.h +++ b/py/mphal.h @@ -66,6 +66,10 @@ mp_uint_t mp_hal_ticks_ms(void); mp_uint_t mp_hal_ticks_us(void); #endif +#ifndef mp_hal_ticks_cpu +mp_uint_t mp_hal_ticks_cpu(void); +#endif + // If port HAL didn't define its own pin API, use generic // "virtual pin" API from the core. #ifndef mp_hal_pin_obj_t diff --git a/py/py.mk b/py/py.mk index 741ad52f9..8caa37f8a 100644 --- a/py/py.mk +++ b/py/py.mk @@ -229,6 +229,7 @@ PY_O_BASENAME = \ ../extmod/vfs_fat_file.o \ ../extmod/vfs_fat_lexer.o \ ../extmod/vfs_fat_misc.o \ + ../extmod/utime_mphal.o \ ../extmod/moduos_dupterm.o \ ../lib/embed/abort_.o \ ../lib/utils/printf.o \ -- cgit v1.2.3 From 799ccdc7892a036bf7d1e3c378f3abaa3ef9fee3 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Sun, 16 Oct 2016 10:48:42 +0300 Subject: esp8266, stmhal, unix: MAKE_FROZEN is consistently defined in mkenv.mk. --- esp8266/Makefile | 1 - stmhal/Makefile | 1 - unix/Makefile | 2 +- 3 files changed, 1 insertion(+), 3 deletions(-) (limited to 'esp8266') diff --git a/esp8266/Makefile b/esp8266/Makefile index d86fec180..65a513afd 100644 --- a/esp8266/Makefile +++ b/esp8266/Makefile @@ -12,7 +12,6 @@ include ../py/py.mk MPY_CROSS = ../mpy-cross/mpy-cross MPY_TOOL = ../tools/mpy-tool.py -MAKE_FROZEN = ../tools/make-frozen.py FROZEN_DIR = scripts FROZEN_MPY_DIR = modules diff --git a/stmhal/Makefile b/stmhal/Makefile index 7be0f28fe..06be7acc8 100644 --- a/stmhal/Makefile +++ b/stmhal/Makefile @@ -276,7 +276,6 @@ all: $(BUILD)/firmware.dfu $(BUILD)/firmware.hex ifneq ($(FROZEN_DIR),) CFLAGS += -DMICROPY_MODULE_FROZEN_STR OBJ += $(BUILD)/frozen-files.o -MAKE_FROZEN = ../tools/make-frozen.py $(BUILD)/frozen-files.o: $(BUILD)/frozen-files.c $(call compile_c) diff --git a/unix/Makefile b/unix/Makefile index 4a313b3a8..53ff4cb48 100644 --- a/unix/Makefile +++ b/unix/Makefile @@ -273,7 +273,7 @@ coverage_test: coverage gcov -o build-coverage/extmod ../extmod/*.c $(BUILD)/_frozen_upip.c: $(BUILD)/frozen_upip/upip.py - ../tools/make-frozen.py $(dir $^) > $@ + $(MAKE_FROZEN) $(dir $^) > $@ # Select latest upip version available UPIP_TARBALL := $(shell ls -1 -v ../tools/micropython-upip-*.tar.gz | tail -n1) -- cgit v1.2.3 From 4d45f286ebab62fd7c7b524bdfcdf58522b911c8 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Tue, 18 Oct 2016 00:06:59 +0300 Subject: esp8266/Makefile: Use latest esptool.py flash size auto-detection. --- esp8266/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'esp8266') diff --git a/esp8266/Makefile b/esp8266/Makefile index 65a513afd..1586c576c 100644 --- a/esp8266/Makefile +++ b/esp8266/Makefile @@ -18,7 +18,7 @@ FROZEN_MPY_DIR = modules PORT ?= /dev/ttyACM0 BAUD ?= 115200 FLASH_MODE ?= qio -FLASH_SIZE ?= 8m +FLASH_SIZE ?= detect CROSS_COMPILE = xtensa-lx106-elf- ESP_SDK = $(shell $(CC) -print-sysroot)/usr -- cgit v1.2.3 From 20d0271863bfe231c6f0974e35d11fad60e7e832 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Tue, 18 Oct 2016 15:18:07 +0300 Subject: esp8266/esp_init_data: Auto-initialize system params with vendor SDK 2.0.0. SDK 2.0.0 goes into boot loop if a firmware is programmed over erased flash, causing problems with user experience. This change implements behavior similar to older SDKs': if clean flash is detected, default system parameters are used. --- esp8266/Makefile | 1 + esp8266/esp8266.ld | 2 +- esp8266/esp_init_data.c | 80 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 esp8266/esp_init_data.c (limited to 'esp8266') diff --git a/esp8266/Makefile b/esp8266/Makefile index 1586c576c..c57206c4d 100644 --- a/esp8266/Makefile +++ b/esp8266/Makefile @@ -65,6 +65,7 @@ SRC_C = \ main.c \ help.c \ esp_mphal.c \ + esp_init_data.c \ gccollect.c \ lexerstr32.c \ uart.c \ diff --git a/esp8266/esp8266.ld b/esp8266/esp8266.ld index c726790d3..5251d1681 100644 --- a/esp8266/esp8266.ld +++ b/esp8266/esp8266.ld @@ -20,7 +20,7 @@ PHDRS irom0_0_phdr PT_LOAD; } -ENTRY(call_user_start) +ENTRY(firmware_start) EXTERN(_DebugExceptionVector) EXTERN(_DoubleExceptionVector) EXTERN(_KernelExceptionVector) diff --git a/esp8266/esp_init_data.c b/esp8266/esp_init_data.c new file mode 100644 index 000000000..b229f751d --- /dev/null +++ b/esp8266/esp_init_data.c @@ -0,0 +1,80 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2016 Paul Sokolovsky + * + * 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 +#include "ets_sys.h" +#include "etshal.h" +#include "esp_mphal.h" +#include "user_interface.h" +#include "extmod/misc.h" + +uint32_t SPIRead(uint32_t offset, void *buf, uint32_t len); +uint32_t SPIWrite(uint32_t offset, const void *buf, uint32_t len); +uint32_t SPIEraseSector(int sector); +NORETURN void call_user_start(void); +void ets_printf(const char *fmt, ...); +extern char flashchip; + +static const uint8_t default_init_data[] __attribute__((aligned(4))) = { +0x05, 0x00, 0x04, 0x02, 0x05, 0x05, 0x05, 0x02, 0x05, 0x00, 0x04, 0x05, 0x05, 0x04, 0x05, 0x05, +0x04, 0xfe, 0xfd, 0xff, 0xf0, 0xf0, 0xf0, 0xe0, 0xe0, 0xe0, 0xe1, 0x0a, 0xff, 0xff, 0xf8, 0x00, +0xf8, 0xf8, 0x52, 0x4e, 0x4a, 0x44, 0x40, 0x38, 0x00, 0x00, 0x01, 0x01, 0x02, 0x03, 0x04, 0x05, +0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0xe1, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x93, 0x43, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +}; + +void firmware_start(void) { + // For SDK 1.5.2, either address has shifted and not mirrored in + // eagle.rom.addr.v6.ld, or extra initial member was added. + SpiFlashChip *flash = (SpiFlashChip*)(&flashchip + 4); + + char buf[128]; + SPIRead(flash->chip_size - 4 * 0x1000, buf, sizeof(buf)); + /*for (int i = 0; i < sizeof(buf); i++) { + static char hexf[] = "%x "; + ets_printf(hexf, buf[i]); + }*/ + + bool inited = false; + for (int i = 0; i < sizeof(buf); i++) { + if (buf[i] != 0xff) { + inited = true; + break; + } + } + + if (!inited) { + static char msg[] = "Writing init data\n"; + ets_printf(msg); + SPIRead((uint32_t)&default_init_data - 0x40200000, buf, sizeof(buf)); + SPIWrite(flash->chip_size - 4 * 0x1000, buf, sizeof(buf)); + } + + asm("j call_user_start"); +} -- cgit v1.2.3 From 6566e3f6a87ea0080d93a59f750b6616276841a0 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Wed, 19 Oct 2016 00:01:14 +0300 Subject: esp8266/esp8266.ld: Move help.o to iROM. --- esp8266/esp8266.ld | 1 + 1 file changed, 1 insertion(+) (limited to 'esp8266') diff --git a/esp8266/esp8266.ld b/esp8266/esp8266.ld index 5251d1681..59d7dd20d 100644 --- a/esp8266/esp8266.ld +++ b/esp8266/esp8266.ld @@ -132,6 +132,7 @@ SECTIONS *gccollect.o(.literal* .text*) *gchelper.o(.literal* .text*) + *help.o(.literal* .text*) *lexerstr32.o(.literal* .text*) *utils.o(.literal* .text*) *modpyb.o(.literal*, .text*) -- cgit v1.2.3 From e7e0d91be8ab717b4ba854172a44a9b561e79225 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Wed, 19 Oct 2016 00:04:30 +0300 Subject: esp8266/esp8266.ld: Move modmachine.o to iROM. --- esp8266/esp8266.ld | 1 + 1 file changed, 1 insertion(+) (limited to 'esp8266') diff --git a/esp8266/esp8266.ld b/esp8266/esp8266.ld index 59d7dd20d..332949166 100644 --- a/esp8266/esp8266.ld +++ b/esp8266/esp8266.ld @@ -142,6 +142,7 @@ SECTIONS *modpybadc.o(.literal*, .text*) *modpybuart.o(.literal*, .text*) *modpybi2c.o(.literal*, .text*) + *modmachine.o(.literal*, .text*) *modmachinewdt.o(.literal*, .text*) *modpybspi.o(.literal*, .text*) *modpybhspi.o(.literal*, .text*) -- cgit v1.2.3 From 462748de0c2668d40b7f2ea8f2b264d134d5d39b Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Wed, 19 Oct 2016 00:12:54 +0300 Subject: esp8266/esp8266.ld: Move main.o to iROM. --- esp8266/esp8266.ld | 1 + 1 file changed, 1 insertion(+) (limited to 'esp8266') diff --git a/esp8266/esp8266.ld b/esp8266/esp8266.ld index 332949166..010a4cac6 100644 --- a/esp8266/esp8266.ld +++ b/esp8266/esp8266.ld @@ -130,6 +130,7 @@ SECTIONS *stmhal/pybstdio.o(.literal*, .text*) + build/main.o(.literal* .text*) *gccollect.o(.literal* .text*) *gchelper.o(.literal* .text*) *help.o(.literal* .text*) -- cgit v1.2.3 From 9514d847feb70c330d310a366b92013960729bdc Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Wed, 19 Oct 2016 00:20:10 +0300 Subject: esp8266: Add MP_FASTCODE modifier to put a function to iRAM. It can be used in the following manner: void MP_FASTCODE(foo)(int arg) { ... } --- esp8266/esp8266.ld | 3 ++- esp8266/mpconfigport.h | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) (limited to 'esp8266') diff --git a/esp8266/esp8266.ld b/esp8266/esp8266.ld index 010a4cac6..5fb6f1379 100644 --- a/esp8266/esp8266.ld +++ b/esp8266/esp8266.ld @@ -202,7 +202,8 @@ SECTIONS *(.entry.text) *(.init.literal) *(.init) - *(.literal .text .literal.* .text.* .stub .gnu.warning .gnu.linkonce.literal.* .gnu.linkonce.t.*.literal .gnu.linkonce.t.*) + *(.literal .text .literal.* .text.* .iram0.literal .iram0.text .iram0.text.*.literal .iram0.text.*) + *(.stub .gnu.warning .gnu.linkonce.literal.* .gnu.linkonce.t.*.literal .gnu.linkonce.t.*) *(.fini.literal) *(.fini) *(.gnu.version) diff --git a/esp8266/mpconfigport.h b/esp8266/mpconfigport.h index 201057f12..602b3e9c8 100644 --- a/esp8266/mpconfigport.h +++ b/esp8266/mpconfigport.h @@ -182,4 +182,6 @@ extern const struct _mp_obj_module_t onewire_module; #define MICROPY_HW_MCU_NAME "ESP8266" #define MICROPY_PY_SYS_PLATFORM "esp8266" +#define MP_FASTCODE(n) __attribute__((section(".iram0.text." #n))) n + #define _assert(expr) ((expr) ? (void)0 : __assert_func(__FILE__, __LINE__, __func__, #expr)) -- cgit v1.2.3 From 204222653edbc2d01b5aed38b1de71a767cb5748 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Wed, 19 Oct 2016 00:20:34 +0300 Subject: esp8266/main: Mark nlr_jump_fail() as MP_FASTCODE. It's probably not strictly needed so far, but serves as an example of MP_FASTCODE use and may be helpful in the future. --- esp8266/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'esp8266') diff --git a/esp8266/main.c b/esp8266/main.c index c938dcb30..033ab7afe 100644 --- a/esp8266/main.c +++ b/esp8266/main.c @@ -141,7 +141,7 @@ mp_obj_t mp_builtin_open(uint n_args, const mp_obj_t *args, mp_map_t *kwargs) { } MP_DEFINE_CONST_FUN_OBJ_KW(mp_builtin_open_obj, 1, mp_builtin_open); -void nlr_jump_fail(void *val) { +void MP_FASTCODE(nlr_jump_fail)(void *val) { printf("NLR jump failed\n"); for (;;) { } -- cgit v1.2.3 From 3f251efb9bb22fe45ef5392b8ed9d6f9148415e7 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Thu, 20 Oct 2016 16:49:45 +0300 Subject: esp8266/modules/webrepl: Enforce only one concurrent WebREPL connection. Concurrent WebREPL connections were never supported, now actually check for this. --- esp8266/modules/webrepl.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'esp8266') diff --git a/esp8266/modules/webrepl.py b/esp8266/modules/webrepl.py index da3e70c59..b200f4fc8 100644 --- a/esp8266/modules/webrepl.py +++ b/esp8266/modules/webrepl.py @@ -31,6 +31,10 @@ def setup_conn(port, accept_handler): def accept_conn(listen_sock): global client_s cl, remote_addr = listen_sock.accept() + if uos.dupterm(): + print("\nConcurrent WebREPL connection from", remote_addr, "rejected") + cl.close() + return print("\nWebREPL connection from:", remote_addr) client_s = cl websocket_helper.server_handshake(cl) -- cgit v1.2.3 From b440307b4a15a540413a7a9f699d388c7428a63c Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Fri, 21 Oct 2016 01:08:43 +0300 Subject: py/py.mk: Automatically add frozen.c to source list if FROZEN_DIR is defined. Now frozen modules generation handled fully by py.mk and available for reuse by any port. --- esp8266/Makefile | 6 +++--- py/py.mk | 4 ++++ zephyr/Makefile | 1 - 3 files changed, 7 insertions(+), 4 deletions(-) (limited to 'esp8266') diff --git a/esp8266/Makefile b/esp8266/Makefile index c57206c4d..5f0044df0 100644 --- a/esp8266/Makefile +++ b/esp8266/Makefile @@ -7,14 +7,15 @@ MICROPY_PY_USSL = 1 MICROPY_SSL_AXTLS = 1 MICROPY_PY_BTREE = 1 +FROZEN_DIR = scripts +FROZEN_MPY_DIR = modules + # include py core make definitions include ../py/py.mk MPY_CROSS = ../mpy-cross/mpy-cross MPY_TOOL = ../tools/mpy-tool.py -FROZEN_DIR = scripts -FROZEN_MPY_DIR = modules PORT ?= /dev/ttyACM0 BAUD ?= 115200 FLASH_MODE ?= qio @@ -90,7 +91,6 @@ SRC_C = \ modmachine.c \ modonewire.c \ ets_alt_task.c \ - $(BUILD)/frozen.c \ fatfs_port.c \ axtls_helpers.c \ hspi.c \ diff --git a/py/py.mk b/py/py.mk index 8caa37f8a..ab07bbbde 100644 --- a/py/py.mk +++ b/py/py.mk @@ -237,6 +237,10 @@ PY_O_BASENAME = \ # prepend the build destination prefix to the py object files PY_O = $(addprefix $(PY_BUILD)/, $(PY_O_BASENAME)) +ifneq ($(FROZEN_DIR),) +PY_O += $(BUILD)/$(BUILD)/frozen.o +endif + # Sources that may contain qstrings SRC_QSTR_IGNORE = nlr% emitnx% emitnthumb% emitnarm% SRC_QSTR = $(SRC_MOD) $(addprefix py/,$(filter-out $(SRC_QSTR_IGNORE),$(PY_O_BASENAME:.o=.c)) emitnative.c) diff --git a/zephyr/Makefile b/zephyr/Makefile index 1db84cb32..9682dc5cc 100644 --- a/zephyr/Makefile +++ b/zephyr/Makefile @@ -41,7 +41,6 @@ SRC_C = main.c \ lib/utils/interrupt_char.c \ lib/utils/pyhelp.c \ lib/mp-readline/readline.c \ - $(BUILD)/frozen.c \ $(SRC_MOD) # List of sources for qstr extraction -- cgit v1.2.3