summaryrefslogtreecommitdiff
path: root/esp8266
diff options
context:
space:
mode:
Diffstat (limited to 'esp8266')
-rw-r--r--esp8266/Makefile10
-rw-r--r--esp8266/esp8266.ld8
-rw-r--r--esp8266/esp_init_data.c80
-rw-r--r--esp8266/main.c2
-rw-r--r--esp8266/modules/webrepl.py4
-rw-r--r--esp8266/modutime.c62
-rw-r--r--esp8266/mpconfigport.h7
7 files changed, 111 insertions, 62 deletions
diff --git a/esp8266/Makefile b/esp8266/Makefile
index d86fec180..5f0044df0 100644
--- a/esp8266/Makefile
+++ b/esp8266/Makefile
@@ -7,19 +7,19 @@ 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
-MAKE_FROZEN = ../tools/make-frozen.py
-FROZEN_DIR = scripts
-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
@@ -66,6 +66,7 @@ SRC_C = \
main.c \
help.c \
esp_mphal.c \
+ esp_init_data.c \
gccollect.c \
lexerstr32.c \
uart.c \
@@ -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/esp8266/esp8266.ld b/esp8266/esp8266.ld
index c726790d3..5fb6f1379 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)
@@ -130,8 +130,10 @@ SECTIONS
*stmhal/pybstdio.o(.literal*, .text*)
+ build/main.o(.literal* .text*)
*gccollect.o(.literal* .text*)
*gchelper.o(.literal* .text*)
+ *help.o(.literal* .text*)
*lexerstr32.o(.literal* .text*)
*utils.o(.literal* .text*)
*modpyb.o(.literal*, .text*)
@@ -141,6 +143,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*)
@@ -199,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/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 <stdio.h>
+#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");
+}
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 (;;) {
}
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)
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 19cf9a679..602b3e9c8 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)
@@ -17,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)
@@ -33,6 +35,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)
@@ -49,6 +52,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)
@@ -58,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)
@@ -177,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))