summaryrefslogtreecommitdiffstatshomepage
path: root/esp8266
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2017-08-14 12:19:09 +1000
committerDamien George <damien.p.george@gmail.com>2017-08-14 12:19:09 +1000
commitbb254ba0ea89ce60dd6deab94991b2651c00dff3 (patch)
treefa2b66f3a1a9fd4bb90b2c83ce9954099b06fe01 /esp8266
parent5e76ea4affd0bd46e67b456496818803010a2d24 (diff)
parente4e4526954f8bcd88ceb21fe789963bfa710fa4f (diff)
downloadmicropython-bb254ba0ea89ce60dd6deab94991b2651c00dff3.tar.gz
micropython-bb254ba0ea89ce60dd6deab94991b2651c00dff3.zip
Merge tag 'v1.8.3' into parse-bytecode
Many small improvements and additions, with btree support in ESP8266 port This release brings various improvements and additions to the core, extended modules and the ESP8266 port, as well as enhancements to the docs. There is now a "threshold" function in the gc module for the user to configure the garbage collector to run earlier than usual, in order to help reduce fragmentation of the heap. The btree module is now available in the ESP8266 port, and there is improved WebREPL file transfer: get file is now non-blocking (this change requires an update of the client software). py core: - nlrx64.S: prefix mp_thread_get_state with an underscore on Mac - stream: implement 2- and 3-arg write() method as an extension to CPython - gc: implement GC running by allocation threshold, user configurable - fix nlrthumb.c when DEBUG=1 is defined - obj: issue a warning when str and bytes objects are compared - mpconfig.h: fix description for MICROPY_PY_STR_BYTES_CMP_WARN - objstrunicode: str_index_to_ptr: should handle bytes too - objstrunicode: str_index_to_ptr: implement positive indexing properly - stream: implement generic flush() method, in terms of C-level ioctl - objstringio: add MP_STREAM_FLUSH ioctl and flush() method - objstringio: implement MP_STREAM_SEEK ioctl and add seek() method - stream: add adapter methods with POSIX-compatible signatures - mpconfig.h: add MICROPY_STREAMS_POSIX_API setting - py.mk: extra switches to build "embedded" BerkeleyDB BTree lib - mkrules.mk: allow to add more items for "clean" target using CLEAN_EXTRA - objstr: make .partition()/.rpartition() methods configurable - mpconfig.h: define MP_ALWAYSINLINE for reuse extmod: - modussl: rename to modussl_axtls.c, to allow impl using other SSL libs - modussl_axtls: further changes to allow alternative SSL modules - modussl_axtls: add dummy setblocking() method - vfs_fat: implement rmdir() method (aliases to unlink) - modussl_axtls: use mp_stream_close() method - modwebrepl: use mp_stream_close() method - modbtree: check __bt_open() return value for error - modbtree: switch to accepting stream object instead of filename - modbtree: implement __contains__ operation - modwebrepl: factor out "GET" iteration to write_file_chunk() - modwebrepl: make GET_FILE operation non-blocking - modbtree: open(): add option kwargs - modwebsocket: add readline method - modwebsocket: make compatible with non-default object models - modwebsocket: use mp_rom_map_elem_t and friends - modwebrepl: add GET_VER operation to query MicroPython version lib: - axtls: upgrade to axTLS 1.5.4 + MicroPython patchset - axtls: update, fixes esp8266 build - utils/stdout_helpers: move from minimal/uart_extra.c for reuse - embed/abort_: implementation of abort_() function raising uPy exception - berkeley-db-1.xx: switch to "embedded" branch - berkeley-db-1.xx: update, sets default page size to 4096 tests: - add test for extended arguments to stream .write() method - extmod/machine_pinbase: skip if machine.PinBase is not available - bytes_compare: rework test for bytes <-> str comparison - extmod/btree1: close database at the end of test - unicode_subscr.py: detailed test for subscripting unicode strings - run-tests: make "regex'ed .exp" facility available to device tests - io/bytesio_ext: test for .seek()/.flush() on BytesIO - extmod/btree1: tests against in-memory DB (using io.BytesIO) - machine_mem.py: too non-portable, rework as an example for unix port - machine1: revamp to work with unix port (which has "umachine") - basics: bytes/str.partition/rpartition are now optional mpy-cross: - fix Makefile to handle gc-sections linker flags on OS X - use binary file translation mode for creating mpy files on windows - fix mingw and msys2 compilation minimal port: - disable MICROPY_GC_ALLOC_THRESHOLD unix port: - mpthreadport: adjust minimum thread stack, and stack limit check - cache libaxtls.a in local build dir - disable MICROPY_GC_ALLOC_THRESHOLD for minimal build - enable MICROPY_PY_STR_BYTES_CMP_WARN - mpconfigport.h: include stdio.h by default - file: implement MP_STREAM_FLUSH ioctl - file: ioctl(): check that file is open before operations - file: fdfile_ioctl(): fix argument to check_fd_is_open() - file: use generic stream flush() method - enable websocket module - moduselect: allow poll.register(), etc. accept fd-like objects stmhal port: - fix malloc when used with external libraries - make SPI NSS pin definition optional - fix I2C mappings for STM32F429DISC board esp8266 port: - select axTLS for SSL implementation, following recent refactor - moduos: add rmdir() function - cache Xtensa-built libaxtls.a in local build dir - enable MICROPY_PY_STR_BYTES_CMP_WARN - dupterm_task_init() should be called before running _boot.py, etc - _boot.py: set GC alloc threshold to half of heap size - _boot.py: decrease GC alloc threshold to quarter of heap size - modpybuart: fix UART parity setting - axtls_helpers: remove abort_(), now in lib/embed/ - mpconfigport.h: include sys/types.h for POSIX types definitions - esp_mphal: implement libc's errno - enable btree module - eagle.rom.addr.v6.ld: add Enable_QMode symbol from SDK 2.0.0 - make APA102 driver inclusion configurable - makeimg.py: store firmware size as last 4 bytes of padding area - makeimg.py: append md5 hash to the generated binary - modesp: add check_fw() function to check integrity of the firmware - scripts/port_diag.py: include esp.check_fw() call - flashbdev: reserve extra sysparam sector for SDK 2.0.0 compatibility - scripts/inisetup: add commented-out call to esp.osdebug(None) - modmachine: implement idle() function - esp_mphal.h: add mp_hal_ticks_cpu() for reuse - modutime: actually implement ticks_cpu() - modmachine: implement dummy sleep() function - tutorial/intro: reword para abou -fm dio switch - modules/flashbdev: start filesystem at 0x90000 - esp8266.ld: increase firmware image size to 0x90000 (576K) docs: - add DHT to ESP8266 Quick Ref and Tutorial - fix some spelling mistakes - array: document array module - library/index: include array module in ToC - esp8266/intro: rename to "Getting started" from "Introduction" - esp8266/intro: add troubleshooting section - esp8266/quickref: link to installation instructions - esp8266/tutorial/intro: add anchor for link from quickeref - esp8266/intro: focus on hazards of unearthed power wrt electronics - uio: mention seek()/flush() support for io.BytesIO misc: - logo/1bit-logo A black & white version of the logo examples: - http_server*: update for buffered-like streams (read line by line) - embedding: example for embedding MicroPython in an app - embedding: add README - http_client*: be sure to close socket - network: split recv- and read-based HTTP servers qemu-arm: - enable gcc LTO option for nlrthumb.c
Diffstat (limited to 'esp8266')
-rw-r--r--esp8266/Makefile10
-rw-r--r--esp8266/axtls_helpers.c3
-rw-r--r--esp8266/eagle.rom.addr.v6.ld1
-rw-r--r--esp8266/esp8266.ld3
-rw-r--r--esp8266/esp_mphal.c5
-rw-r--r--esp8266/esp_mphal.h6
-rw-r--r--esp8266/espapa102.c5
-rw-r--r--esp8266/espneopixel.c14
-rw-r--r--esp8266/etshal.h7
-rw-r--r--esp8266/main.c2
-rw-r--r--esp8266/makeimg.py27
-rw-r--r--esp8266/modesp.c23
-rw-r--r--esp8266/modmachine.c15
-rw-r--r--esp8266/modpybuart.c2
-rw-r--r--esp8266/modules/_boot.py1
-rw-r--r--esp8266/modules/flashbdev.py8
-rw-r--r--esp8266/moduos.c6
-rw-r--r--esp8266/modutime.c3
-rw-r--r--esp8266/mpconfigport.h6
-rw-r--r--esp8266/scripts/inisetup.py2
-rw-r--r--esp8266/scripts/port_diag.py2
-rw-r--r--esp8266/uart.h10
22 files changed, 129 insertions, 32 deletions
diff --git a/esp8266/Makefile b/esp8266/Makefile
index 00826cfe46..ea9c7eb871 100644
--- a/esp8266/Makefile
+++ b/esp8266/Makefile
@@ -4,6 +4,8 @@ include ../py/mkenv.mk
QSTR_DEFS = qstrdefsport.h #$(BUILD)/pins_qstr.h
MICROPY_PY_USSL = 1
+MICROPY_SSL_AXTLS = 1
+MICROPY_PY_BTREE = 1
# include py core make definitions
include ../py/py.mk
@@ -87,6 +89,7 @@ SRC_C = \
$(BUILD)/frozen.c \
fatfs_port.c \
axtls_helpers.c \
+ $(SRC_MOD)
STM_SRC_C = $(addprefix stmhal/,\
pybstdio.c \
@@ -153,7 +156,7 @@ SRC_QSTR += $(SRC_C) $(STM_SRC_C) $(EXTMOD_SRC_C) $(DRIVERS_SRC_C)
# Append any auto-generated sources that are needed by sources listed in SRC_QSTR
SRC_QSTR_AUTO_DEPS +=
-all: $(BUILD)/firmware-combined.bin
+all: $(BUILD)/libaxtls.a $(BUILD)/firmware-combined.bin
CONFVARS_FILE = $(BUILD)/confvars
@@ -229,8 +232,11 @@ $(BUILD)/firmware.elf: $(OBJ)
include ../py/mkrules.mk
-axtls:
+axtls: $(BUILD)/libaxtls.a
+
+$(BUILD)/libaxtls.a:
cd ../lib/axtls; cp config/upyconfig config/.config
cd ../lib/axtls; make oldconfig -B
cd ../lib/axtls; make clean
cd ../lib/axtls; make all CC="$(CC)" LD="$(LD)" AR="$(AR)" CFLAGS_EXTRA="$(CFLAGS_XTENSA) -Dabort=abort_ -DRT_MAX_PLAIN_LENGTH=1024 -DRT_EXTRA=3072"
+ cp ../lib/axtls/_stage/libaxtls.a $@
diff --git a/esp8266/axtls_helpers.c b/esp8266/axtls_helpers.c
index 097d9ed4c3..6d508fdeb1 100644
--- a/esp8266/axtls_helpers.c
+++ b/esp8266/axtls_helpers.c
@@ -43,9 +43,6 @@ void *calloc(size_t nmemb, size_t size) {
void *realloc(void *ptr, size_t size) {
return gc_realloc(ptr, size, true);
}
-void abort_(void) {
- printf("Aborted\n");
-}
#define PLATFORM_HTONL(_n) ((uint32_t)( (((_n) & 0xff) << 24) | (((_n) & 0xff00) << 8) | (((_n) >> 8) & 0xff00) | (((_n) >> 24) & 0xff) ))
#undef htonl
diff --git a/esp8266/eagle.rom.addr.v6.ld b/esp8266/eagle.rom.addr.v6.ld
index ce071a3bb9..1b3ce55d01 100644
--- a/esp8266/eagle.rom.addr.v6.ld
+++ b/esp8266/eagle.rom.addr.v6.ld
@@ -20,6 +20,7 @@ PROVIDE ( SPI_read_status = 0x400043c8 );
PROVIDE ( SPI_write_status = 0x40004400 );
PROVIDE ( SPI_write_enable = 0x4000443c );
PROVIDE ( Wait_SPI_Idle = 0x4000448c );
+PROVIDE ( Enable_QMode = 0x400044c0 );
PROVIDE ( SPIEraseArea = 0x40004b44 );
PROVIDE ( SPIEraseBlock = 0x400049b4 );
PROVIDE ( SPIEraseChip = 0x40004984 );
diff --git a/esp8266/esp8266.ld b/esp8266/esp8266.ld
index 79bdf87f71..a55aff52e5 100644
--- a/esp8266/esp8266.ld
+++ b/esp8266/esp8266.ld
@@ -5,7 +5,7 @@ MEMORY
dport0_0_seg : org = 0x3ff00000, len = 0x10
dram0_0_seg : org = 0x3ffe8000, len = 0x14000
iram1_0_seg : org = 0x40100000, len = 0x8000
- irom0_0_seg : org = 0x40209000, len = 0x80000
+ irom0_0_seg : org = 0x40209000, len = 0x87000
}
/* define the top of RAM */
@@ -121,6 +121,7 @@ SECTIONS
*lib/fatfs/*.o*(.literal*, .text*)
*/libaxtls.a:(.literal*, .text*)
+ *lib/berkeley-db-1.xx/*.o(.literal*, .text*)
*lib/libm/*.o*(.literal*, .text*)
*lib/mp-readline/*.o(.literal*, .text*)
*lib/netutils/*.o*(.literal*, .text*)
diff --git a/esp8266/esp_mphal.c b/esp8266/esp_mphal.c
index 3cc4610825..a2710af2e6 100644
--- a/esp8266/esp_mphal.c
+++ b/esp8266/esp_mphal.c
@@ -259,3 +259,8 @@ int ets_esf_free_bufs(int idx) {
}
return cnt;
}
+
+extern int mp_stream_errno;
+int *__errno() {
+ return &mp_stream_errno;
+}
diff --git a/esp8266/esp_mphal.h b/esp8266/esp_mphal.h
index 91fee21198..fa52ae53a2 100644
--- a/esp8266/esp_mphal.h
+++ b/esp8266/esp_mphal.h
@@ -47,6 +47,12 @@ void mp_hal_init(void);
void mp_hal_rtc_init(void);
uint32_t mp_hal_ticks_us(void);
+__attribute__((always_inline)) static inline uint32_t mp_hal_ticks_cpu(void) {
+ uint32_t ccount;
+ __asm__ __volatile__("rsr %0,ccount":"=a" (ccount));
+ return ccount;
+}
+
void mp_hal_delay_us(uint32_t);
void mp_hal_set_interrupt_char(int c);
uint32_t mp_hal_get_cpu_freq(void);
diff --git a/esp8266/espapa102.c b/esp8266/espapa102.c
index e5f3024b10..4295fe42d8 100644
--- a/esp8266/espapa102.c
+++ b/esp8266/espapa102.c
@@ -24,6 +24,9 @@
* THE SOFTWARE.
*/
+#include "py/mpconfig.h"
+#if MICROPY_ESP8266_APA102
+
#include <stdio.h>
#include "c_types.h"
#include "eagle_soc.h"
@@ -108,3 +111,5 @@ void esp_apa102_write(uint8_t clockPin, uint8_t dataPin, uint8_t *pixels, uint32
_esp_apa102_append_additionial_cycles(clockPinMask, dataPinMask, numBytes);
_esp_apa102_end_frame(clockPinMask, dataPinMask);
}
+
+#endif
diff --git a/esp8266/espneopixel.c b/esp8266/espneopixel.c
index 26776f025e..0f12f4c820 100644
--- a/esp8266/espneopixel.c
+++ b/esp8266/espneopixel.c
@@ -9,16 +9,10 @@
#include "eagle_soc.h"
#include "user_interface.h"
#include "espneopixel.h"
+#include "esp_mphal.h"
#define NEO_KHZ400 (1)
-static uint32_t _getCycleCount(void) __attribute__((always_inline));
-static inline uint32_t _getCycleCount(void) {
- uint32_t ccount;
- __asm__ __volatile__("rsr %0,ccount":"=a" (ccount));
- return ccount;
-}
-
void /*ICACHE_RAM_ATTR*/ esp_neopixel_write(uint8_t pin, uint8_t *pixels, uint32_t numBytes, bool is800KHz) {
uint8_t *p, *end, pix, mask;
@@ -49,10 +43,10 @@ void /*ICACHE_RAM_ATTR*/ esp_neopixel_write(uint8_t pin, uint8_t *pixels, uint32
for(t = time0;; t = time0) {
if(pix & mask) t = time1; // Bit high duration
- while(((c = _getCycleCount()) - startTime) < period); // Wait for bit start
+ while(((c = mp_hal_ticks_cpu()) - startTime) < period); // Wait for bit start
GPIO_REG_WRITE(GPIO_OUT_W1TS_ADDRESS, pinMask); // Set high
startTime = c; // Save start time
- while(((c = _getCycleCount()) - startTime) < t); // Wait high duration
+ while(((c = mp_hal_ticks_cpu()) - startTime) < t); // Wait high duration
GPIO_REG_WRITE(GPIO_OUT_W1TC_ADDRESS, pinMask); // Set low
if(!(mask >>= 1)) { // Next bit/byte
if(p >= end) break;
@@ -60,5 +54,5 @@ void /*ICACHE_RAM_ATTR*/ esp_neopixel_write(uint8_t pin, uint8_t *pixels, uint32
mask = 0x80;
}
}
- while((_getCycleCount() - startTime) < period); // Wait for last bit
+ while((mp_hal_ticks_cpu() - startTime) < period); // Wait for last bit
}
diff --git a/esp8266/etshal.h b/esp8266/etshal.h
index 0185a9e22c..dd61ddec93 100644
--- a/esp8266/etshal.h
+++ b/esp8266/etshal.h
@@ -20,6 +20,13 @@ void ets_timer_arm_new(os_timer_t *tim, uint32_t millis, bool repeat, bool is_mi
void ets_timer_setfn(os_timer_t *tim, ETSTimerFunc callback, void *cb_data);
void ets_timer_disarm(os_timer_t *tim);
+// Opaque structure
+typedef char MD5_CTX[64];
+
+void MD5Init(MD5_CTX *context);
+void MD5Update(MD5_CTX *context, const void *data, unsigned int len);
+void MD5Final(unsigned char digest[16], MD5_CTX *context);
+
// These prototypes are for recent SDKs with "malloc tracking"
void *pvPortMalloc(unsigned sz, const char *fname, int line);
void vPortFree(void *p, const char *fname, int line);
diff --git a/esp8266/main.c b/esp8266/main.c
index 21bb6e0e0f..71dfeb2ac6 100644
--- a/esp8266/main.c
+++ b/esp8266/main.c
@@ -60,6 +60,7 @@ STATIC void mp_reset(void) {
MP_STATE_PORT(dupterm_arr_obj) = MP_OBJ_NULL;
pin_init0();
readline_init0();
+ dupterm_task_init();
#if MICROPY_MODULE_FROZEN
pyexec_frozen_module("_boot.py");
pyexec_file("boot.py");
@@ -85,7 +86,6 @@ void init_done(void) {
#if MICROPY_REPL_EVENT_DRIVEN
pyexec_event_repl_init();
#endif
- dupterm_task_init();
#if !MICROPY_REPL_EVENT_DRIVEN
soft_reset:
diff --git a/esp8266/makeimg.py b/esp8266/makeimg.py
index e63f956bdd..091854fa4d 100644
--- a/esp8266/makeimg.py
+++ b/esp8266/makeimg.py
@@ -1,23 +1,40 @@
import sys
+import struct
+import hashlib
SEGS_MAX_SIZE = 0x9000
assert len(sys.argv) == 4
+md5 = hashlib.md5()
+
with open(sys.argv[3], 'wb') as fout:
with open(sys.argv[1], 'rb') as f:
data_flash = f.read()
fout.write(data_flash)
+ # First 4 bytes include flash size, etc. which may be changed
+ # by esptool.py, etc.
+ md5.update(data_flash[4:])
print('flash ', len(data_flash))
+ with open(sys.argv[2], 'rb') as f:
+ data_rom = f.read()
+
pad = b'\xff' * (SEGS_MAX_SIZE - len(data_flash))
- fout.write(pad)
+ assert len(pad) >= 4
+ fout.write(pad[:-4])
+ md5.update(pad[:-4])
+ len_data = struct.pack("I", SEGS_MAX_SIZE + len(data_rom))
+ fout.write(len_data)
+ md5.update(len_data)
print('padding ', len(pad))
- with open(sys.argv[2], 'rb') as f:
- data_rom = f.read()
- fout.write(data_rom)
- print('irom0text', len(data_rom))
+ fout.write(data_rom)
+ md5.update(data_rom)
+ print('irom0text', len(data_rom))
+
+ fout.write(md5.digest())
print('total ', SEGS_MAX_SIZE + len(data_rom))
+ print('md5 ', md5.hexdigest())
diff --git a/esp8266/modesp.c b/esp8266/modesp.c
index 99f063a756..39cc514afc 100644
--- a/esp8266/modesp.c
+++ b/esp8266/modesp.c
@@ -633,6 +633,24 @@ STATIC mp_obj_t esp_flash_size(void) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(esp_flash_size_obj, esp_flash_size);
+STATIC mp_obj_t esp_check_fw(void) {
+ MD5_CTX ctx;
+ uint32_t *sz_p = (uint32_t*)0x40208ffc;
+ printf("size: %d\n", *sz_p);
+ MD5Init(&ctx);
+ MD5Update(&ctx, (char*)0x40200004, *sz_p - 4);
+ unsigned char digest[16];
+ MD5Final(digest, &ctx);
+ printf("md5: ");
+ for (int i = 0; i < 16; i++) {
+ printf("%02x", digest[i]);
+ }
+ printf("\n");
+ return mp_obj_new_bool(memcmp(digest, (void*)(0x40200000 + *sz_p), sizeof(digest)) == 0);
+}
+STATIC MP_DEFINE_CONST_FUN_OBJ_0(esp_check_fw_obj, esp_check_fw);
+
+
STATIC mp_obj_t esp_neopixel_write_(mp_obj_t pin, mp_obj_t buf, mp_obj_t is800k) {
mp_buffer_info_t bufinfo;
mp_get_buffer_raise(buf, &bufinfo, MP_BUFFER_READ);
@@ -642,6 +660,7 @@ STATIC mp_obj_t esp_neopixel_write_(mp_obj_t pin, mp_obj_t buf, mp_obj_t is800k)
}
STATIC MP_DEFINE_CONST_FUN_OBJ_3(esp_neopixel_write_obj, esp_neopixel_write_);
+#if MICROPY_ESP8266_APA102
STATIC mp_obj_t esp_apa102_write_(mp_obj_t clockPin, mp_obj_t dataPin, mp_obj_t buf) {
mp_buffer_info_t bufinfo;
mp_get_buffer_raise(buf, &bufinfo, MP_BUFFER_READ);
@@ -651,6 +670,7 @@ STATIC mp_obj_t esp_apa102_write_(mp_obj_t clockPin, mp_obj_t dataPin, mp_obj_t
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_3(esp_apa102_write_obj, esp_apa102_write_);
+#endif
STATIC mp_obj_t esp_freemem() {
return MP_OBJ_NEW_SMALL_INT(system_get_free_heap_size());
@@ -695,10 +715,13 @@ STATIC const mp_map_elem_t esp_module_globals_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR_getaddrinfo), (mp_obj_t)&esp_getaddrinfo_obj },
#endif
{ MP_OBJ_NEW_QSTR(MP_QSTR_neopixel_write), (mp_obj_t)&esp_neopixel_write_obj },
+ #if MICROPY_ESP8266_APA102
{ MP_OBJ_NEW_QSTR(MP_QSTR_apa102_write), (mp_obj_t)&esp_apa102_write_obj },
+ #endif
{ MP_OBJ_NEW_QSTR(MP_QSTR_dht_readinto), (mp_obj_t)&dht_readinto_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_freemem), (mp_obj_t)&esp_freemem_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_meminfo), (mp_obj_t)&esp_meminfo_obj },
+ { MP_OBJ_NEW_QSTR(MP_QSTR_check_fw), (mp_obj_t)&esp_check_fw_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_info), (mp_obj_t)&pyb_info_obj }, // TODO delete/rename/move elsewhere
{ MP_OBJ_NEW_QSTR(MP_QSTR_malloc), (mp_obj_t)&esp_malloc_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_free), (mp_obj_t)&esp_free_obj },
diff --git a/esp8266/modmachine.c b/esp8266/modmachine.c
index 80ae7ac2a0..b3a42618e5 100644
--- a/esp8266/modmachine.c
+++ b/esp8266/modmachine.c
@@ -26,6 +26,7 @@
*/
#include <stdint.h>
+#include <stdio.h>
#include "py/obj.h"
#include "py/runtime.h"
@@ -82,6 +83,18 @@ STATIC mp_obj_t machine_unique_id(void) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(machine_unique_id_obj, machine_unique_id);
+STATIC mp_obj_t machine_idle(void) {
+ asm("waiti 0");
+ return mp_const_none;
+}
+STATIC MP_DEFINE_CONST_FUN_OBJ_0(machine_idle_obj, machine_idle);
+
+STATIC mp_obj_t machine_sleep(void) {
+ printf("Warning: not yet implemented\n");
+ return mp_const_none;
+}
+STATIC MP_DEFINE_CONST_FUN_OBJ_0(machine_sleep_obj, machine_sleep);
+
STATIC mp_obj_t machine_deepsleep(void) {
// default to sleep forever
uint32_t sleep_us = 0;
@@ -222,6 +235,8 @@ STATIC const mp_rom_map_elem_t machine_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR_reset), MP_ROM_PTR(&machine_reset_obj) },
{ MP_ROM_QSTR(MP_QSTR_reset_cause), MP_ROM_PTR(&machine_reset_cause_obj) },
{ MP_ROM_QSTR(MP_QSTR_unique_id), MP_ROM_PTR(&machine_unique_id_obj) },
+ { MP_ROM_QSTR(MP_QSTR_idle), MP_ROM_PTR(&machine_idle_obj) },
+ { MP_ROM_QSTR(MP_QSTR_sleep), MP_ROM_PTR(&machine_sleep_obj) },
{ MP_ROM_QSTR(MP_QSTR_deepsleep), MP_ROM_PTR(&machine_deepsleep_obj) },
{ MP_ROM_QSTR(MP_QSTR_disable_irq), MP_ROM_PTR(&machine_disable_irq_obj) },
diff --git a/esp8266/modpybuart.c b/esp8266/modpybuart.c
index f27ee4e2d2..25320fa1e7 100644
--- a/esp8266/modpybuart.c
+++ b/esp8266/modpybuart.c
@@ -112,9 +112,11 @@ STATIC void pyb_uart_init_helper(pyb_uart_obj_t *self, size_t n_args, const mp_o
if (args[ARG_parity].u_obj != MP_OBJ_NULL) {
if (args[ARG_parity].u_obj == mp_const_none) {
UartDev.parity = UART_NONE_BITS;
+ UartDev.exist_parity = UART_STICK_PARITY_DIS;
self->parity = 0;
} else {
mp_int_t parity = mp_obj_get_int(args[ARG_parity].u_obj);
+ UartDev.exist_parity = UART_STICK_PARITY_EN;
if (parity & 1) {
UartDev.parity = UART_ODD_BITS;
self->parity = 1;
diff --git a/esp8266/modules/_boot.py b/esp8266/modules/_boot.py
index 2cacb56760..c200b3d3f9 100644
--- a/esp8266/modules/_boot.py
+++ b/esp8266/modules/_boot.py
@@ -1,4 +1,5 @@
import gc
+gc.threshold((gc.mem_free() + gc.mem_alloc()) // 4)
import uos
from flashbdev import bdev
diff --git a/esp8266/modules/flashbdev.py b/esp8266/modules/flashbdev.py
index 07ed966020..98b0208fb6 100644
--- a/esp8266/modules/flashbdev.py
+++ b/esp8266/modules/flashbdev.py
@@ -3,8 +3,8 @@ import esp
class FlashBdev:
SEC_SIZE = 4096
- START_SEC = 0x89000 // SEC_SIZE
- NUM_BLK = 0x73
+ START_SEC = 0x90000 // SEC_SIZE
+ NUM_BLK = 0x6b
def __init__(self, blocks=NUM_BLK):
self.blocks = blocks
@@ -64,5 +64,5 @@ size = esp.flash_size()
if size < 1024*1024:
bdev = None
else:
- # 16K at the flash end is reserved for SDK params storage
- bdev = FlashBdev((size - 16384) // FlashBdev.SEC_SIZE - FlashBdev.START_SEC)
+ # 20K at the flash end is reserved for SDK params storage
+ bdev = FlashBdev((size - 20480) // FlashBdev.SEC_SIZE - FlashBdev.START_SEC)
diff --git a/esp8266/moduos.c b/esp8266/moduos.c
index 74262d86b1..af149625d6 100644
--- a/esp8266/moduos.c
+++ b/esp8266/moduos.c
@@ -95,6 +95,11 @@ STATIC mp_obj_t os_mkdir(mp_obj_t path_in) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(os_mkdir_obj, os_mkdir);
+STATIC mp_obj_t os_rmdir(mp_obj_t path_in) {
+ return vfs_proxy_call(MP_QSTR_rmdir, 1, &path_in);
+}
+STATIC MP_DEFINE_CONST_FUN_OBJ_1(os_rmdir_obj, os_rmdir);
+
STATIC mp_obj_t os_chdir(mp_obj_t path_in) {
return vfs_proxy_call(MP_QSTR_chdir, 1, &path_in);
}
@@ -155,6 +160,7 @@ STATIC const mp_rom_map_elem_t os_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR_VfsFat), MP_ROM_PTR(&mp_fat_vfs_type) },
{ MP_ROM_QSTR(MP_QSTR_listdir), MP_ROM_PTR(&os_listdir_obj) },
{ MP_ROM_QSTR(MP_QSTR_mkdir), MP_ROM_PTR(&os_mkdir_obj) },
+ { MP_ROM_QSTR(MP_QSTR_rmdir), MP_ROM_PTR(&os_rmdir_obj) },
{ MP_ROM_QSTR(MP_QSTR_chdir), MP_ROM_PTR(&os_chdir_obj) },
{ MP_ROM_QSTR(MP_QSTR_getcwd), MP_ROM_PTR(&os_getcwd_obj) },
{ MP_ROM_QSTR(MP_QSTR_remove), MP_ROM_PTR(&os_remove_obj) },
diff --git a/esp8266/modutime.c b/esp8266/modutime.c
index 356785d3a9..bf56feb5ce 100644
--- a/esp8266/modutime.c
+++ b/esp8266/modutime.c
@@ -134,8 +134,7 @@ STATIC mp_obj_t time_ticks_us(void) {
STATIC MP_DEFINE_CONST_FUN_OBJ_0(time_ticks_us_obj, time_ticks_us);
STATIC mp_obj_t time_ticks_cpu(void) {
- // TODO
- return MP_OBJ_NEW_SMALL_INT(0 & MP_SMALL_INT_POSITIVE_MASK);
+ 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);
diff --git a/esp8266/mpconfigport.h b/esp8266/mpconfigport.h
index 90dbc00098..7b3558ffc2 100644
--- a/esp8266/mpconfigport.h
+++ b/esp8266/mpconfigport.h
@@ -72,7 +72,10 @@
#define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_MPZ)
#define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_FLOAT)
#define MICROPY_ERROR_REPORTING (MICROPY_ERROR_REPORTING_NORMAL)
+#define MICROPY_WARNINGS (1)
+#define MICROPY_PY_STR_BYTES_CMP_WARN (1)
#define MICROPY_STREAMS_NON_BLOCK (1)
+#define MICROPY_STREAMS_POSIX_API (1)
#define MICROPY_MODULE_FROZEN_STR (1)
#define MICROPY_MODULE_FROZEN_MPY (1)
#define MICROPY_MODULE_FROZEN_LEXER mp_lexer_new_from_str32
@@ -85,6 +88,7 @@
#define MICROPY_FATFS_LFN_CODE_PAGE (437) /* 1=SFN/ANSI 437=LFN/U.S.(OEM) */
#define MICROPY_FSUSERMOUNT (1)
#define MICROPY_VFS_FAT (1)
+#define MICROPY_ESP8266_APA102 (1)
#define MICROPY_EVENT_POLL_HOOK {ets_event_poll();}
#define MICROPY_VM_HOOK_COUNT (10)
@@ -114,6 +118,8 @@ typedef void *machine_ptr_t; // must be of pointer size
typedef const void *machine_const_ptr_t; // must be of pointer size
typedef long mp_off_t;
typedef uint32_t sys_prot_t; // for modlwip
+// ssize_t, off_t as required by POSIX-signatured functions in stream.h
+#include <sys/types.h>
#define MP_PLAT_PRINT_STRN(str, len) mp_hal_stdout_tx_strn_cooked(str, len)
diff --git a/esp8266/scripts/inisetup.py b/esp8266/scripts/inisetup.py
index 7d8f6fa0a8..1cb9f0dd95 100644
--- a/esp8266/scripts/inisetup.py
+++ b/esp8266/scripts/inisetup.py
@@ -40,6 +40,8 @@ def setup():
with open("/boot.py", "w") as f:
f.write("""\
# This file is executed on every boot (including wake-boot from deepsleep)
+#import esp
+#esp.osdebug(None)
import gc
#import webrepl
#webrepl.start()
diff --git a/esp8266/scripts/port_diag.py b/esp8266/scripts/port_diag.py
index aa696b1abb..f2abd8066d 100644
--- a/esp8266/scripts/port_diag.py
+++ b/esp8266/scripts/port_diag.py
@@ -17,6 +17,8 @@ def main():
FREQ_MAP = {0: "40MHZ", 1: "26MHZ", 2: "20MHz", 0xf: "80MHz"}
print("Byte @2: %02x" % ROM[2])
print("Byte @3: %02x (Flash size: %s Flash freq: %s)" % (ROM[3], SZ_MAP.get(ROM[3] >> 4, "?"), FREQ_MAP.get(ROM[3] & 0xf)))
+ print("Firmware checksum:")
+ print(esp.check_fw())
print("\nNetworking:")
print("STA ifconfig:", network.WLAN(network.STA_IF).ifconfig())
diff --git a/esp8266/uart.h b/esp8266/uart.h
index 21894d3fa6..2b97683ff8 100644
--- a/esp8266/uart.h
+++ b/esp8266/uart.h
@@ -1,6 +1,8 @@
#ifndef _INCLUDED_UART_H_
#define _INCLUDED_UART_H_
+#include <eagle_soc.h>
+
#define UART0 (0)
#define UART1 (1)
@@ -18,14 +20,14 @@ typedef enum {
} UartStopBitsNum;
typedef enum {
- UART_NONE_BITS = 0,
- UART_ODD_BITS = 0,
- UART_EVEN_BITS = BIT4
+ UART_NONE_BITS = 0,
+ UART_ODD_BITS = BIT0,
+ UART_EVEN_BITS = 0
} UartParityMode;
typedef enum {
UART_STICK_PARITY_DIS = 0,
- UART_STICK_PARITY_EN = BIT3 | BIT5
+ UART_STICK_PARITY_EN = BIT1
} UartExistParity;
typedef enum {