Wykres commitów

290 Commity (master)

Autor SHA1 Wiadomość Data
Damien George 71f3ade770 ports: Support legacy soft I2C/SPI construction via id=-1 arg.
With a warning that this way of constructing software I2C/SPI is
deprecated.  The check and warning will be removed in a future release.

This should help existing code to migrate to the new SoftI2C/SoftSPI types.

Signed-off-by: Damien George <damien@micropython.org>
2020-10-01 12:57:10 +10:00
Damien George 39d50d129c ports: Add SoftI2C and SoftSPI to machine module where appropriate.
Previous commits removed the ability for one I2C/SPI constructor to
construct both software- or hardware-based peripheral instances.  Such
construction is now split to explicit soft and non-soft types.

This commit makes both types available in all ports that previously could
create both software and hardware peripherals: machine.I2C and machine.SPI
construct hardware instances, while machine.SoftI2C and machine.SoftSPI
create software instances.

This is a breaking change for use of software-based I2C and SPI.  Code that
constructed I2C/SPI peripherals in the following way will need to be
changed:

    machine.I2C(-1, ...)            ->  machine.SoftI2C(...)
    machine.I2C(scl=scl, sda=sda)   ->  machine.SoftI2C(scl=scl, sda=sda)

    machine.SPI(-1, ...)            ->  machine.SoftSPI(...)
    machine.SPI(sck=sck, mosi=mosi, miso=miso)
                        ->  machine.SoftSPI(sck=sck, mosi=mosi, miso=miso)

Code which uses machine.I2C and machine.SPI classes to access hardware
peripherals does not need to change.

Signed-off-by: Damien George <damien@micropython.org>
2020-10-01 12:57:10 +10:00
Damien George 9e0533b9e1 extmod/machine_spi: Remove "id" arg in SoftSPI constructor.
The SoftSPI constructor is now used soley to create SoftSPI instances, it
can no longer delegate to create a hardware-based SPI instance.

Signed-off-by: Damien George <damien@micropython.org>
2020-10-01 12:57:10 +10:00
Damien George c35deb2625 extmod/machine_i2c: Rename type to SoftI2C and add custom print method.
Also rename machine_i2c_type to mp_machine_soft_i2c_type.  These changes
make it clear that it's a soft-I2C implementation, and match SoftSPI.

Signed-off-by: Damien George <damien@micropython.org>
2020-10-01 12:57:10 +10:00
Damien George 8f20cdc353 all: Rename absolute time-based functions to include "epoch".
For time-based functions that work with absolute time there is the need for
an Epoch, to set the zero-point at which the absolute time starts counting.
Such functions include time.time() and filesystem stat return values.  And
different ports may use a different Epoch.

To make it clearer what functions use the Epoch (whatever it may be), and
make the ports more consistent with their use of the Epoch, this commit
renames all Epoch related functions to include the word "epoch" in their
name (and remove references to "2000").

Along with this rename, the following things have changed:

- mp_hal_time_ns() is now specified to return the number of nanoseconds
  since the Epoch, rather than since 1970 (but since this is an internal
  function it doesn't change anything for the user).

- littlefs timestamps on the esp8266 have been fixed (they were previously
  off by 30 years in nanoseconds).

Otherwise, there is no functional change made by this commit.

Signed-off-by: Damien George <damien@micropython.org>
2020-09-18 17:20:34 +10:00
Damien George bd7af6151d ports: Add utime.gmtime() function.
To portably get the Epoch.  This is simply aliased to localtime() on ports
that are not timezone aware.

Signed-off-by: Damien George <damien@micropython.org>
2020-09-18 16:25:36 +10:00
Damien George b28758054b esp8266: Remove release-specific manifest, disable osdebug by default.
This commit removes release-specific builds for the esp8266 and makes the
normal build of the GENERIC board more like the release build.  This makes
esp8266 like all the other ports, for which there is no difference between
a daily build and a release build, making things less confusing.

Release builds were previously defined by UART_OS=-1 (disable OS messages)
and using manifest_release.py to include more frozen modules.

The changes in this commit are:
- Remove manifest_release.py.
- Add existing modules from manifest_release.py (except example code)
  to the GENERIC board's manifest.py file.
- Change UART_OS default to -1 to disable OS messages by default.

Signed-off-by: Damien George <damien@micropython.org>
2020-09-18 16:01:42 +10:00
Damien George ee50a6effe py/mphal.h: Introduce mp_hal_time_ns and implement on various ports.
This should return a 64-bit value being the number of nanoseconds since
1970/1/1.

Signed-off-by: Damien George <damien@micropython.org>
2020-08-22 16:13:44 +10:00
Olivier Ortigues e32302c1a6 esp8266/esppwm: Fix PWM glitch when setting duty on different channel.
The PWM driver uses a double buffer for the PWM timing array, one in
current use and the other one to update when changing duty parameters.
The issue was that once the duty parameters were changed the updated buffer
was applied immediately without synchronising to the start of the PWM
period.  By moving the buffer toggling/swapping to the interrupt when the
cycle is done there are no more glitches.
2020-05-27 16:15:28 +10:00
Rafael Römhild 8f3167a962 esp8266/boards: Allow configuring btree/FAT/LFS2 support when building.
Prior to e0905e85a7 it was possible to
disable btree support on build.  This patch allows to configure btree
support on make again and also the two new introduced options for FAT and
LFS2 filesystems.
2020-05-14 22:16:01 +10:00
Damien George 67fca2b715 esp8266/uart: Move a few functions from iRAM to iROM.
They call functions in iROM so do not need to be in iRAM.
2020-05-08 23:44:57 +10:00
Damien George f2218c2fbd esp8266/esp_mphal: Move most functions in esp_mphal.c from iRAM to iROM.
The ones that are moved out of iRAM should not need to be there, because
either they call functions in iROM (eg mp_hal_stdout_tx_str), or they are
only ever called from a function in iROM and not from an interrupt (eg
ets_esf_free_bufs).

This frees up about 800 bytes of iRAM.
2020-05-08 23:44:57 +10:00
Damien George caa7725642 esp8266/boards: Move py/pairheap.c code from iRAM to iROM.
It doesn't need to be in iRAM.
2020-05-08 23:40:22 +10:00
Damien George e12de1fd9d esp8266: Clean up Pin intr handler by moving all code to machine_pin.c.
The macro MP_FASTCODE is used to explicitly place required functions in
iRAM, instead of needing a separate .c file.
2020-05-08 23:40:22 +10:00
Damien George 419d1aa617 esp8266/mpconfigport.h: Add definitions for BEGIN/END_ATOMIC_SECTION.
These are needed to ensure correct operation of the MicroPython scheduler.
2020-04-30 23:47:11 +10:00
Damien George 0bd58a5613 esp8266/machine_pin: Move pin_intr_handler to iRAM, de-support hard IRQ.
GPIO interrupts can occur when the flash ROM cache is in use and so the
GPIO interrupt handler must be in iRAM.  This commit moves the handler to
iRAM, and also moves mp_sched_schedule to iRAM which is called by
pin_intr_handler.

As part of this fix the Pin class can no longer support hard=True in the
Pin.irq() method, because the VM and runtime are too big to put in iRAM.

Fixes #5714.
2020-04-30 23:47:11 +10:00
Damien George e08ca78f40 py/stream: Remove mp_stream_errno and use system errno instead.
This change is made for two reasons:

1. A 3rd-party library (eg berkeley-db-1.xx, axtls) may use the system
   provided errno for certain errors, and yet MicroPython stream objects
   that it calls will be using the internal mp_stream_errno.  So if the
   library returns an error it is not known whether the corresponding errno
   code is stored in the system errno or mp_stream_errno.  Using the system
   errno in all cases (eg in the mp_stream_posix_XXX wrappers) fixes this
   ambiguity.

2. For systems that have threading the system-provided errno should always
   be used because the errno value is thread-local.

For systems that do not have an errno, the new lib/embed/__errno.c file is
provided.
2020-04-27 23:58:46 +10:00
stijn 84fa3312cf all: Format code to add space after C++-style comment start.
Note: the uncrustify configuration is explicitly set to 'add' instead of
'force' in order not to alter the comments which use extra spaces after //
as a means of indenting text for clarity.
2020-04-23 11:24:25 +10:00
stijn d6243568a0 all: Remove commented-out include statements. 2020-04-23 11:24:15 +10:00
Jim Mussared 073b9a5eb8 ports: Enable error text compression for various ports, but not all.
Enabled on: bare-arm, minimal, unix coverage/dev/minimal, stm32, esp32,
esp8266, cc3200, teensy, qemu-arm, nrf.  Not enabled on others to be able
to test the code when the feature is disabled (the default case).

Code size change for this commit:

   bare-arm:  -600 -0.906%
minimal x86:  -308 -0.208%
   unix x64:    +0 +0.000%
unix nanbox:    +0 +0.000%
      stm32: -3368 -0.869% PYBV10
     cc3200: -1024 -0.558%
    esp8266: -2512 -0.368% GENERIC
      esp32: -2876 -0.205% GENERIC[incl -3168(data)]
        nrf: -1708 -1.173% pca10040
       samd:    +0 +0.000% ADAFRUIT_ITSYBITSY_M4_EXPRESS
2020-04-05 15:02:06 +10:00
Jim Mussared def76fe4d9 all: Use MP_ERROR_TEXT for all error messages. 2020-04-05 15:02:06 +10:00
Damien George 497ca99eb2 esp8266/makeimg.py: Print out info about RAM segments when building fw. 2020-04-04 16:30:39 +11:00
Damien George e0905e85a7 esp8266: Change from FAT to littlefs v2 as default filesystem.
This commit changes the esp8266 boards to use littlefs v2 as the
filesystem, rather than FAT.  Since the esp8266 doesn't expose the
filesystem to the PC over USB there's no strong reason to keep it as FAT.
Littlefs is smaller in code size, is more efficient in use of flash to
store data, is resilient over power failure, and using it saves about 4k of
heap RAM, which can now be used for other things.

This is a backwards incompatible change because all existing esp8266 boards
will need to update their filesystem after installing new firmware (eg
backup old files, install firmware, restore files to new filesystem).

As part of this commit the memory layout of the default board (GENERIC) has
changed.  It now allocates all 1M of memory-mapped flash to the firmware,
so the filesystem area starts at the 2M point.  This is done to allow more
frozen bytecode to be stored in the 1M of memory-mapped flash.  This
requires an esp8266 module with 2M or more of flash to work, so a new board
called GENERIC_1M is added which has the old memory-mapping (but still
changed to use littlefs for the filesystem).

In summary there are now 3 esp8266 board definitions:
- GENERIC_512K: for 512k modules, doesn't have a filesystem.
- GENERIC_1M: for 1M modules, 572k for firmware+frozen code, 396k for
  filesystem (littlefs).
- GENERIC: for 2M (or greater) modules, 968k for firmware+frozen code,
  1M+ for filesystem (littlefs), FAT driver also included in firmware for
  use on, eg, external SD cards.
2020-04-04 16:30:36 +11:00
Damien George 1a3e386c67 all: Remove spaces inside and around parenthesis.
Using new options enabled in the uncrustify configuration.
2020-03-28 23:36:44 +11:00
Damien George 1d4d688b3b esp8266: Enable and freeze uasyncio.
Only included in GENERIC build.
2020-03-26 01:25:46 +11:00
Zoltán Vörös c5cc64175b ports: Add lib/libm/roundf.c to bare-metal Makefile's.
This function is not used by the core but having it as part of the build
allows it to be used by user C modules, or board extensions.  The linker
won't include it in the final firmware if it remains unused.
2020-03-25 01:22:00 +11:00
Damien George 9fa32169e9 esp8266/modnetwork: Add support for wlan.ifconfig('dhcp').
Fixes issue #5780.
2020-03-25 00:43:04 +11:00
Damien George feb2577585 all: Remove spaces between nested paren and inside function arg paren.
Using new options enabled in the uncrustify configuration.
2020-03-25 00:39:46 +11:00
Jim Mussared 0cd13081df esp8266/README.md: Add docker build instructions. 2020-03-22 13:26:03 +11:00
Damien George 8d34344dce esp8266/modmachine: Implement machine.soft_reset().
Fixes issue #5764.
2020-03-20 13:40:01 +11:00
Damien George a017576706 esp8266/machine_pin: Disable ets_loop_iter during hard IRQ handler.
Otherwise ets_loop_iter may be reentered.  Related to issue #5714.
2020-03-10 16:48:34 +11:00
Damien George 69661f3343 all: Reformat C and Python source code with tools/codeformat.py.
This is run with uncrustify 0.70.1, and black 19.10b0.
2020-02-28 10:33:03 +11:00
Damien George 3f39d18c2b all: Add *FORMAT-OFF* in various places.
This string is recognised by uncrustify, to disable formatting in the
region marked by these comments.  This is necessary in the qstrdef*.h files
to prevent modification of the strings within the Q(...).  In other places
it is used to prevent excessive reformatting that would make the code less
readable.
2020-02-28 10:31:07 +11:00
Damien George ad7213d3c3 py: Add mp_raise_msg_varg helper and use it where appropriate.
This commit adds mp_raise_msg_varg(type, fmt, ...) as a helper for
nlr_raise(mp_obj_new_exception_msg_varg(type, fmt, ...)).  It makes the
C-level API for raising exceptions more consistent, and reduces code size
on most ports:

   bare-arm:   +28 +0.042%
minimal x86:  +100 +0.067%
   unix x64:   -56 -0.011%
unix nanbox:  -300 -0.068%
      stm32:  -204 -0.054% PYBV10
     cc3200:    +0 +0.000%
    esp8266:   -64 -0.010% GENERIC
      esp32:  -104 -0.007% GENERIC
        nrf:  -136 -0.094% pca10040
       samd:    +0 +0.000% ADAFRUIT_ITSYBITSY_M4_EXPRESS
2020-02-13 11:52:40 +11:00
Damien George 8d0421c3cf esp8266: Put mp_keyboard_interrupt in IRAM.
It was originally in IRAM due to the linker script specification, but
since the function moved from lib/utils/interrupt_char.c to py/scheduler.c
it needs to be put back in IRAM.
2020-02-07 16:08:31 +11:00
Damien George 98a3911c43 py/scheduler: Add "raise_exc" argument to mp_handle_pending.
Previous behaviour is when this argument is set to "true", in which case
the function will raise any pending exception.  Setting it to "false" will
cancel any pending exception.
2020-02-07 16:08:20 +11:00
Damien George e3ff52863b esp8266/modules/ntptime.py: Add comment about configuring NTP host.
The ability to change the host is a frequently requested feature, so
explicitly document how it can be achieved using the existing code.

See issues #2121, #4385, #4622, #5122, #5536.
2020-01-31 23:54:11 +11:00
JensDiemer c14ff6194c esp8266/modules: Fix AttributeError in _boot.py if flash not formatted.
Prior to this commit, if the flash filesystem was not formatted then it
would error: "AttributeError: 'FlashBdev' object has no attribute 'mount'".
That is due to it not being able to detect the filesystem on the block
device and just trying to mount the block device directly.

This commit fixes the issue by just catching all exceptions.  Also it's not
needed to try the mount if `flashbdev.bdev` is None.
2020-01-14 23:53:49 +11:00
David Lechner e79424d672 ports: Allow overriding CROSS_COMPILE in a custom makefile.
Many ports already allow overriding CROSS_COMPILE.  This modifies the
remaining ports to allow it as well.
2019-12-27 23:53:16 +11:00
Jim Mussared 7ce1e0b1dc extmod/webrepl: Move webrepl scripts to common place and use manifest.
Move webrepl support code from ports/esp8266/modules into extmod/webrepl
(to be alongside extmod/modwebrepl.c), and use frozen manifests to include
it in the build on esp8266 and esp32.

A small modification is made to webrepl.py to make it work on non-ESP
ports, i.e. don't call dupterm_notify if not available.
2019-12-20 12:59:13 +11:00
Damien George b47e155bd0 py/persistentcode: Add ability to relocate loaded native code.
Implements text, rodata and bss generalised relocations, as well as generic
qstr-object linking.  This allows importing dynamic native modules on all
supported architectures in a unified way.
2019-12-12 20:15:28 +11:00
Damien George 799b6d1e0c extmod: Consolidate FAT FS config to MICROPY_VFS_FAT across all ports.
This commit removes the Makefile-level MICROPY_FATFS config and moves the
MICROPY_VFS_FAT config to the Makefile level to replace it.  It also moves
the include of the oofatfs source files in the build from each port to a
central place in extmod/extmod.mk.

For a port to enabled VFS FAT support it should now set MICROPY_VFS_FAT=1
at the level of the Makefile.  This will include the relevant oofatfs files
in the build and set MICROPY_VFS_FAT=1 at the C (preprocessor) level.
2019-11-11 11:37:38 +11:00
Damien George cea9209e0f esp8266/moduos: Add optional support for VfsLfs1 and VfsLfs2.
With this commit an esp8266-based board can now be built with littlefs
support via, eg "make MICROPY_VFS_LFS2=1".
2019-11-07 18:44:16 +11:00
Damien George 6eee5413ff esp8266/modules/flashbdev.py: Support extended block protocol. 2019-11-07 18:43:37 +11:00
Damien George c13f9f209d all: Convert nlr_raise(mp_obj_new_exception_msg(x)) to mp_raise_msg(x).
This helper function was added a while ago and these are the remaining
cases to convert, to save a bit of code size.
2019-11-05 11:35:45 +11:00
Damien George cfe1c5abf8 extmod/vfs: Rename BP_IOCTL_xxx constants to MP_BLOCKDEV_IOCTL_xxx.
Also rename SEC_COUNT to BLOCK_COUNT and SEC_SIZE to BLOCK_SIZE.
2019-10-29 14:17:29 +11:00
Damien George d2384efa80 py: Automatically provide weak links from "foo" to "ufoo" module name.
This commit implements automatic module weak links for all built-in
modules, by searching for "ufoo" in the built-in module list if "foo"
cannot be found.  This means that all modules named "ufoo" are always
available as "foo".  Also, a port can no longer add any other weak links,
which makes strict the definition of a weak link.

It saves some code size (about 100-200 bytes) on ports that previously had
lots of weak links.

Some changes from the previous behaviour:
- It doesn't intern the non-u module names (eg "foo" is not interned),
  which saves code size, but will mean that "import foo" creates a new qstr
  (namely "foo") in RAM (unless the importing module is frozen).
- help('modules') no longer lists non-u module names, only the u-variants;
  this reduces duplication in the help listing.

Weak links are effectively the same as having a set of symbolic links on
the filesystem that is searched last.  So an "import foo" will search
built-in modules first, then all paths in sys.path, then weak links last,
importing "ufoo" if it exists.  Thus a file called "foo.py" somewhere in
sys.path will still have precedence over the weak link of "foo" to "ufoo".

See issues: #1740, #4449, #5229, #5241.
2019-10-22 15:30:52 +11:00
Damien George f1d91908fa esp8266/boards: Add manifest_release.py with files for a release.
A release also sets: UART_OS = -1
2019-10-22 00:23:22 +11:00
Jim Mussared df7f632fd7 esp8266: Allow building without a manifest. 2019-10-21 23:21:14 +11:00
Jim Mussared 8ba963cfa3 tools/makemanifest.py: Eval relative paths w.r.t. current manifest file.
When loading a manifest file, e.g. by include(), it will chdir first to the
directory of that manifest.  This means that all file operations within a
manifest are relative to that manifest's location.

As a consequence of this, additional environment variables are needed to
find absolute paths, so the following are added: $(MPY_LIB_DIR),
$(PORT_DIR), $(BOARD_DIR).  And rename $(MPY) to $(MPY_DIR) to be
consistent.

Existing manifests are updated to match.
2019-10-21 23:01:41 +11:00
Damien George 2fd3f2520d esp8266: Convert to use FROZEN_MANIFEST to specify frozen code.
Removes symlinks in modules directory, all frozen code is now specified by
manifest.py.
2019-10-15 21:36:02 +11:00
Damien George d7a9388fe0 ports: Add new make target "submodules" which inits required modules. 2019-10-15 17:14:41 +11:00
Damien George 79ab82ea77 esp8266/modules/ntptime.py: Always close socket, and set day-of-week.
Fixes issue #5189.
2019-10-10 18:05:56 +11:00
Mike Causer 53a9b45da1 esp8266: Add per-board configs, following other ports.
The specific board can be selected with the BOARD makefile variable.  This
defaults (if not specified) to BOARD=GENERIC, which is the original default
firmware build.  For the 512k target use BOARD=GENERIC_512K.
2019-10-10 16:32:25 +11:00
Damien George 0e72cc9029 esp8266/machine_adc: Add read_u16 method and refactor. 2019-09-05 22:13:04 +10:00
Damien George 625609a737 esp8266/machine_adc: Rename pyb_adc_* to machine_adc_*. 2019-09-04 16:17:10 +10:00
Damien George 060209240b esp8266: Put new profile code in iROM. 2019-08-30 16:49:02 +10:00
Damien George 96ace8082e esp8266/machine_uart: Allow remapping UART TX/RX pins from 1/3 to 15/13.
Via the standard tx/rx arguments: UART(0, 115200, tx=Pin(15), rx=Pin(13)).

Resolves issue #4718.
2019-08-21 21:16:40 +10:00
Damien George 2d3d4f7483 esp8266/mpconfigport.h: Enable lwIP raw sockets. 2019-08-06 15:56:05 +10:00
Damien George ef00048fed extmod/modwebrepl: Add config option to put filebuf[512] on stack/bss.
Since the esp8266 has a small stack this buffer is kept in the BSS.
2019-07-03 12:55:57 +10:00
Damien George 89a23a05b3 esp8266: Provide custom machine_time_pulse_us that feeds soft WDT.
So that the timeout for machine.time_pulse_us() can be large.

Fixes issue #2775.
2019-07-01 22:53:00 +10:00
Damien George c80614dfc8 ports: Provide mp_hal_stdio_poll for sys.stdio polling where needed. 2019-07-01 17:10:12 +10:00
Paul m. p. P 637aa9784d esp8266/uart: Fix invalid ringbuf name when event driven REPL enabled. 2019-06-17 12:34:10 +10:00
Damien George 5357dad52e esp8266: Fix ticks_ms to correctly handle wraparound of system counter.
Fixes issue #4795.
2019-05-24 15:37:34 +10:00
Paul Sokolovsky 016d9a40fe various: Add and update my copyright line based on git history.
For modules I initially created or made substantial contributions to.
2019-05-17 18:04:15 +10:00
Damien George 99a8fa7940 esp8266/modmachine: Handle overflow of timer to get longer periods.
Can now handle up to about 298 days maximum for millisecond periods.

Fixes issue #4664.
2019-05-10 15:50:35 +10:00
Damien George 0646e607b5 ports: Convert to use pyexec_file_if_exists() to execute boot/main.py.
The stm32 and nrf ports already had the behaviour that they would first
check if the script exists before executing it, and this patch makes all
other ports work the same way.  This helps when developing apps because
it's hard to tell (when unconditionally trying to execute the scripts) if
the resulting OSError at boot up comes from missing boot.py or main.py, or
from some other error.  And it's not really an error if these scripts don't
exist.
2019-04-26 15:22:14 +10:00
Damien George c7d19dc0ad ports/{stm32,esp8266}: Set mpy-cross native arch for frozen native code. 2019-03-14 12:22:49 +11:00
Damien George b5f33ac2cb ports: Update to work with new oofatfs version. 2019-03-05 15:56:39 +11:00
Damien George 8ce22662fe esp8266/modmachine: Call ets_event_poll after waiti in machine.idle.
Because "waiti 0" may have waited for a while (eg 500ms) and the internal
WDT may need to be fed immediately.

Fixes issue #4459.
2019-02-28 15:44:37 +11:00
Yonatan Goldschmidt bc4f8b438b extmod/moduwebsocket: Refactor `websocket` to `uwebsocket`.
As mentioned in #4450, `websocket` was experimental with a single intended
user, `webrepl`. Therefore, we'll make this change without a weak
link `websocket` -> `uwebsocket`.
2019-02-14 00:35:45 +11:00
Mike Causer 812969d615 all: Change PYB message prefix to MPY.
Replaces "PYB: soft reboot" with "MPY: soft reboot", etc.

Having a consistent prefix across ports reduces the difference between
ports, which is a general goal.  And this change won't break pyboard.py
because that tool only looks for "soft reboot".
2019-02-12 15:18:33 +11:00
Damien George 6e30f96b0b ports: Convert legacy uppercase macro names to lowercase. 2019-02-12 14:54:51 +11:00
Damien George 3ff3e96865 esp8266/modmachine: In lightsleep, only waiti if wifi is turned off.
Otherwise the STA interface can't do DTIM sleeping correctly and power
consumption goes up.
2019-01-31 00:05:00 +11:00
Damien George 808dc95ab8 esp8266/modmachine: Implement simple machine.lightsleep function.
Use of "waiti 0" reduces power consumption by about 3mA compared to a
time.sleep_ms call.
2019-01-30 14:05:53 +11:00
Damien George 2911e3554a esp8266/modmachine: Rename machine.sleep to machine.lightsleep.
While keeping machine.sleep as an alias for machine.lightsleep for
backwards compatibility.
2019-01-30 14:05:53 +11:00
Damien George d7cc92383c esp8266/modmachine: Implement optional time_ms arg to machine.deepsleep. 2019-01-30 14:05:53 +11:00
Damien George 18d3a5df26 esp8266/esp_mphal: Provide mp_hal_pin_od_high_dht so DHT works reliably.
The original behaviour of open-drain-high was to use the open-drain mode of
the GPIO pin, and this seems to make driving a DHT more reliable.  See
issue #4233.
2019-01-22 00:26:04 +11:00
Damien George 36808d4e6a esp8266/main: Activate UART(0) on dupterm for REPL before boot.py runs.
So that the user can explicitly deactivate UART(0) if needed.  See
issue #4314.

This introduces some risk to "brick" the device, if the user disables the
REPL without providing an alternative REPL (eg WebREPL), or any way to
reenable it.  In such a case the device needs to be erased and
reprogrammed.  This seems unavoidable, given the desire to have the option
to use the UART for something other than the REPL.
2019-01-16 17:24:23 +11:00
Damien George 52bec93755 esp8266/machine_uart: Add rxbuf keyword arg to UART constructor/init.
As per the machine.UART documentation, this is used to set the length of
the UART RX buffer.
2018-12-05 23:31:24 +11:00
Damien George da1d849ad1 stm32,esp8266,cc3200: Use MICROPY_GC_STACK_ENTRY_TYPE to save some RAM. 2018-12-04 18:32:10 +11:00
Damien George 62b4bebf64 esp8266/modnetwork: Wait for iface to go down before forcing power mgmt.
If the STA interface is connected to an AP then it must be fully
disconnected and deactivated before forcing the power management on.
2018-12-04 10:20:45 +11:00
Damien George 321d75e087 esp8266/modnetwork: Automatically do radio sleep if no interface active.
Reduces current of device by about 55mA when radio is sleeping.
2018-12-01 17:20:05 +11:00
Damien George 9e2dd93145 esp8266/ets_alt_task: Process idle callback if no other events occurred. 2018-12-01 17:20:05 +11:00
Damien George 51482ba925 README: Remove references to "make axtls", it's no longer needed.
Since 0be2ea50e9 axtls is automatically built
as part of the usual "make" build process.
2018-11-15 14:48:17 +11:00
Damien George 746dbf78d3 py/py.mk: When building axtls use -Wno-all to prevent all warnings.
Building axtls gives a lot of warnings with -Wall enabled, and explicitly
disabling all of them cannot be done in a way compatible with gcc and
clang, and likely other compilers.  So just use -Wno-all to prevent all of
the extra warnings (in addition to the necessary -Wno-unused-parameter,
-Wno-uninitialized, -Wno-sign-compare and -Wno-old-style-definition).

Fixes issue #4182.
2018-10-27 23:53:08 +11:00
Damien George bbccb0f630 esp8266: Remove scanning of GC pointers in native code block.
The native code no longer holds live GC pointers so doesn't need to be
scanned.
2018-09-27 23:46:09 +10:00
Damien George 5cd2c7f2e7 esp8266/main: Increase heap by 2kb, now that axtls rodata is in ROM. 2018-09-08 00:09:03 +10:00
Damien George eed83caf1d esp8266/Makefile: Remove build of libaxtls.a and add back tuned config. 2018-09-08 00:07:23 +10:00
Damien George da2d2b6d88 py/mpconfig.h: Introduce MICROPY_DEBUG_PRINTER for debugging output.
This patch in effect renames MICROPY_DEBUG_PRINTER_DEST to
MICROPY_DEBUG_PRINTER, moving its default definition from
lib/utils/printf.c to py/mpconfig.h to make it official and documented, and
makes this macro a pointer rather than the actual mp_print_t struct.  This
is done to get consistency with MICROPY_ERROR_PRINTER, and provide this
macro for use outside just lib/utils/printf.c.

Ports are updated to use the new macro name.
2018-08-02 14:04:44 +10:00
Nicko van Someren c3c914f4dd esp8266,esp32: Implement high-res timers using new tick_hz argument.
machine.Timer now takes a new argument in its constructor (or init method):
tick_hz which specified the units for the period argument.  The period of
the timer in seconds is: period/tick_hz.

For backwards compatibility tick_hz defaults to 1000.  If the user wants to
specify the period (numerator) in microseconds then tick_hz can be set to
1000000.  The user can also specify a period of an arbitrary number of
cycles of an arbitrary frequency using these two arguments.

An additional freq argument has been added to allow frequencies to be
specified directly in Hertz.  This supports floating point values when
available.
2018-07-17 13:17:23 +10:00
Damien George bccf9d3dcf esp8266: Let machine.WDT trigger the software WDT if obj is not fed.
This patch allows scripts to have more control over the software WDT.  If
an instance of machine.WDT is created then the underlying OS is prevented
from feeding the software WDT, and it is up to the user script to feed it
instead via WDT.feed().  The timeout for this WDT is currently fixed and
will be between 1.6 and 3.2 seconds.
2018-07-03 15:31:10 +10:00
Damien George b6e5f82ba5 esp8266/modesp: Run ets_loop_iter before/after doing flash erase/write.
A flash erase/write takes a while and during that time tasks may be
scheduled via an IRQ.  To prevent overflow of the task queue (and loss of
tasks) call ets_loop_iter() before and after slow flash operations.

Note: if a task is posted to a full queue while a flash operation is in
progress then this leads to a fault when trying to print out the error
message that the queue is full.  This patch doesn't try to fix this
particular issue, it just prevents it from happening in the first place.
2018-07-03 14:46:29 +10:00
Damien George 8f86fbfd6c ports: Enable ure.sub() on stm32, esp8266 (not 512k) and esp32. 2018-07-02 15:13:18 +10:00
Damien George d800ed1877 esp8266/esp8266_common.ld: Put mp_keyboard_interrupt in iRAM.
This function may be called from a UART IRQ, which may interrupt the system
when it is erasing/reading/writing flash.  In such a case all code
executing from the IRQ must be in iRAM (because the SPI flash is busy), so
put mp_keyboard_interrupt in iRAM so ctrl-C can be caught during flash
access.

This patch also takes get_fattime out of iRAM and puts it in iROM to make
space for mp_keyboard_interrupt.  There's no real need to have get_fattime
in iRAM because it calls other functions in iROM.

Fixes issue #3897.
2018-06-28 12:55:54 +10:00
Damien George bc6c56d75d esp8266/mpconfigport.h: Enable ucryptolib module for standard build.
It remains disabled for the 512k build.
2018-06-27 16:45:22 +10:00
Damien George 565f590586 ports: Enable IOBase on unix, stm32, esp8266 and esp32.
It's a core feature, in particular required for user-streams with uasyncio.
2018-06-12 12:29:26 +10:00
Damien George b2fa1b50ed ports: Call gc_sweep_all() when doing a soft reset.
This calls finalisers of things like files and sockets to cleanly close
them.
2018-06-12 11:56:25 +10:00
Damien George 93150a0d40 ports: Enable descriptors on stm32, esp8266, esp32 ports.
They are now efficient (in runtime performance) and provide a useful
feature that's hard to obtain without them enabled.

See issue #3644 and PR #3826 for background.
2018-06-08 12:23:08 +10:00
Damien George f35aae366c extmod/vfs_fat: Rename FileIO/TextIO types to mp_type_vfs_fat_XXX.
So they don't clash with other VFS implementations.
2018-06-06 14:28:23 +10:00
Damien George aace60a75e esp8266/modules/ntptime.py: Remove print of newly-set time.
It should be up to the user if they want to print the new time out or not.

Fixes issue #3766.
2018-06-05 14:30:35 +10:00
Damien George 20b4b85f72 ports: Enable MICROPY_PY_BUILTINS_ROUND_INT on selected ports. 2018-05-22 14:18:16 +10:00
Damien George afd0701bf7 esp8266: Change UART(0) to attach to REPL via uos.dupterm interface.
This patch makes it so that UART(0) can by dynamically attached to and
detached from the REPL by using the uos.dupterm function.  Since WebREPL
uses dupterm slot 0 the UART uses dupterm slot 1 (a slot which is newly
introduced by this patch).  UART(0) must now be attached manually in
boot.py (or otherwise) and inisetup.py is changed to provide code to do
this.  For example, to attach use:

    import uos, machine
    uart = machine.UART(0, 115200)
    uos.dupterm(uart, 1)

and to detach use:

    uos.dupterm(None, 1)

When attached, all incoming chars on UART(0) go straight to stdin so
uart.read() will always return None.  Use sys.stdin.read() if it's needed
to read characters from the UART(0) while it's also used for the REPL (or
detach, read, then reattach).  When detached the UART(0) can be used for
other purposes.

If there are no objects in any of the dupterm slots when the REPL is
started (on hard or soft reset) then UART(0) is automatically attached.
Without this, the only way to recover a board without a REPL would be to
completely erase and reflash (which would install the default boot.py which
attaches the REPL).
2018-05-21 11:31:59 +10:00
Damien George 58331e3c28 esp8266/modmachine: Allow I2C and SPI to be configured out of the build.
I2C costs about 3000 bytes of code, and SPI costs about 4400 bytes.
2018-05-17 23:37:12 +10:00
Damien George dd13065843 esp8266/modnetwork: Raise ValueError when getting invalid WLAN id.
Instead of crashing due to out-of-bounds array access.  Fixes #3348.
2018-05-17 22:12:24 +10:00
Damien George f8a5cd24d8 esp8266/modnetwork: Return empty str for hostname if STA is inactive.
Instead of crashing due to NULL pointer dereference.  Fixes issue #3341.
2018-05-17 22:11:22 +10:00
Damien George 94a79f340d esp8266/mpconfigport.h: Add some weak links to common Python modules.
To make it easier/simpler to write code that can run under both CPython and
on an ESP8266 board.
2018-05-17 13:27:18 +10:00
Damien George 6410e174c5 esp8266: Disable DEBUG_PRINTERS for 512k build.
Disabling this saves around 6000 bytes of code space and gets the 512k
build fitting in the available flash again (it increased lately due to an
increase in the size of the ESP8266 SDK).
2018-05-02 15:51:19 +10:00
Lars Kellogg-Stedman d8fdb77ac9 esp8266/modnetwork: Allow to get ESSID of AP that STA is connected to.
This patch enables iface.config('essid') to work for both AP and STA
interfaces.
2018-05-01 16:37:02 +10:00
Damien George 033c32e694 esp8266/esp_mphal.h: Fix I2C glitching by using input mode for od_high.
Certain pins (eg 4 and 5) seem to behave differently at the hardware level
when in open-drain mode: they glitch when set "high" and drive the pin
active high for a brief period before disabling the output driver.  To work
around this make the pin an input to let it float high.
2018-03-12 12:45:09 +11:00
Damien George 58ebeca6a9 drivers/bus: Pull out software SPI implementation to dedicated driver.
This patch takes the software SPI implementation from extmod/machine_spi.c
and moves it to a dedicated file in drivers/bus/softspi.c.  This allows the
SPI driver to be used independently of the uPy runtime, making it a more
general component.
2018-03-10 00:59:43 +11:00
Olivier Ortigues b691aa0aae esp8266/esppwm: Always start timer to avoid glitch from full to nonfull.
The PWM at full value was not considered as an "active" channel so if no
other channel was used the timer used to mange PWM was not started.  So
when another duty value was set the PWM timer restarted and there was a
visible glitch when driving LEDs.  Such a glitch can be seen with the
following code (assuming active-low LED on pin 0):

    p = machine.PWM(machine.Pin(0))
    p.duty(1023) # full width, LED is off
    p.duty(1022) # LED flashes brightly then goes dim

This patch fixes the glitch.
2018-03-05 11:39:44 +11:00
Damien George c5fe610ba1 esp8266/modnetwork: Implement WLAN.status('rssi') for STA interface.
This will return the RSSI of the AP that the STA is connected to.
2018-02-26 16:41:13 +11:00
Damien George 01dcd5bb71 esp8266/uart: Allow to compile with event-driven REPL. 2018-02-26 16:10:27 +11:00
Damien George 82828340a0 ports: Enable ucollections.deque on relevant ports.
These ports are all capable of running uasyncio.
2018-02-21 22:55:13 +11:00
Olivier Ortigues 359d2bdf84 esp8266/README.md: Update build instruction to reflect new ports dir. 2018-02-15 11:14:52 +11:00
Olivier Ortigues 5c83d05b49 esp8266/esppwm: Clip negative duty numbers to 0.
Prior to this patch a negative duty would lead to full PWM.
2018-02-15 11:12:41 +11:00
Damien George a40ce1d829 esp8266/modules: Move dht.py driver to drivers/dht directory. 2018-01-31 18:11:06 +11:00
Damien George 9bcdb0acd1 esp8266/Makefile: Remove commented-out unused lines.
These were copied from the stm32 port (then stmhal) at the very beginning
of this port, with the anticipation that the esp8266 port would have board
definition files with a list of valid pins and their names.  But that has
not been implemented and likely won't be, so remove the corresponding lines
from the Makefile.
2017-12-22 17:16:42 +11:00
Damien George badaf3ecfe esp8266/machine_hspi: After an SPI write wait for last byte to transfer.
Because otherwise the function can return with data still waiting to be
clocked out, and CS might then be disabled before the SPI transaction is
complete.  Fixes issue #3487.
2017-12-14 10:43:18 +11:00
Paul Sokolovsky 3a431fba50 esp8266/modnetwork: Make sure to intern string passed to .config("param").
This is the proper fix for
https://github.com/micropython/micropython/issues/3442.
2017-12-04 00:13:10 +02:00
Damien George 4e056d82cc esp8266/modules/webrepl_setup: Fix first-time enable of WebREPL.
Prior to this fix, enabling WebREPL for the first time via webrepl_setup
did not work at all because "boot.py" did not contain any lines with
"webrepl" in them that could be uncommented.
2017-11-30 10:54:33 +11:00
Damien George 4601759bf5 py/objstr: Remove "make_qstr_if_not_already" arg from mp_obj_new_str.
This patch simplifies the str creation API to favour the common case of
creating a str object that is not forced to be interned.  To force
interning of a new str the new mp_obj_new_str_via_qstr function is added,
and should only be used if warranted.

Apart from simplifying the mp_obj_new_str function (and making it have the
same signature as mp_obj_new_bytes), this patch also reduces code size by a
bit (-16 bytes for bare-arm and roughly -40 bytes on the bare-metal archs).
2017-11-16 13:17:51 +11:00
Paul Sokolovsky 964bf935a3 esp8266/esp8266_common.ld: Put .text of more libs into .irom0.text .
Recent vendor SDKs ship libs with code in .text section, which previously
was going into .irom0.text. Adjust the linker script to route these
sections back to iROM (follows upstream change).
2017-11-14 09:24:33 +02:00
Paul Sokolovsky 0535d03370 esp8266/README: Add section on using upip. 2017-11-12 18:34:56 +02:00
Paul Sokolovsky 9c209e4d09 esp8266/README: Emphasize the need to change default WiFi password. 2017-11-12 18:34:46 +02:00
Paul Sokolovsky 1b146e9de9 py/mpconfig: Introduce reusable MP_HTOBE32(), etc. macros.
Macros to convert big-endian values to host byte order and vice-versa.
These were defined in adhoc way for some ports (e.g. esp8266), allow
reuse, provide default implementations, while allow ports to override.
2017-11-08 19:47:37 +02:00
Paul Sokolovsky e766a4af4a esp8266/etshal.h: Make function prototypes compatible with ESP SDK 2.1.0+.
In the vendor SDK 2.1.0, some of the functions which previously didn't
have prototypes, finally acquired them. Change prototypes on our side
to match those in vendor headers, to avoid warnings-as-errors.
2017-11-05 00:29:33 +02:00
Damien George f4059dcc0c all: Use NULL instead of "" when calling mp_raise exception helpers.
This is the established way of doing it and reduces code size by a little
bit.
2017-10-24 22:39:36 +11:00
Damien George 37282f8fc1 extmod/uos_dupterm: Update uos.dupterm() and helper funcs to have index.
The uos.dupterm() signature and behaviour is updated to reflect the latest
enhancements in the docs.  It has minor backwards incompatibility in that
it no longer accepts zero arguments.

The dupterm_rx helper function is moved from esp8266 to extmod and
generalised to support multiple dupterm slots.

A port can specify multiple slots by defining the MICROPY_PY_OS_DUPTERM
config macro to an integer, being the number of slots it wants to have;
0 means to disable the dupterm feature altogether.

The unix and esp8266 ports are updated to work with the new interface and
are otherwise unchanged with respect to functionality.
2017-10-13 20:01:57 +11:00
Vitor Massaru Iha 1b7d6a7951 esp8266/modules/webrepl_setup: Add info about allowed password length.
This patch also makes the code more concise by combining the checks for the
password length.
2017-10-11 11:37:01 +11:00
Damien George 6db132e130 esp8266/modnetwork: Add "bssid" keyword arg to WLAN.connect() method. 2017-10-09 23:09:06 +11:00
Damien George a3dc1b1957 all: Remove inclusion of internal py header files.
Header files that are considered internal to the py core and should not
normally be included directly are:
    py/nlr.h - internal nlr configuration and declarations
    py/bc0.h - contains bytecode macro definitions
    py/runtime0.h - contains basic runtime enums

Instead, the top-level header files to include are one of:
    py/obj.h - includes runtime0.h and defines everything to use the
        mp_obj_t type
    py/runtime.h - includes mpstate.h and hence nlr.h, obj.h, runtime0.h,
        and defines everything to use the general runtime support functions

Additional, specific headers (eg py/objlist.h) can be included if needed.
2017-10-04 12:37:50 +11:00
Damien George b00040c43c esp8266/esp_mphal: Send data in chunks to mp_uos_dupterm_tx_strn.
Sending byte-by-byte is inefficient and leads to errors in the WebSocket
protocol when sending utf-8 encoded characters.
2017-10-03 23:24:24 +11:00
Damien George da8c4c2653 py/builtinhelp: Change signature of help text var from pointer to array.
As a pointer (const char *) it takes up an extra word of storage which is
in RAM.
2017-09-12 16:03:52 +10:00
Paul Sokolovsky 9355cca610 esp8266: Set DEFPSIZE=1024, MINCACHE=3 for "btree" module.
Defaults of 4096 and 5 respectively are too high to esp8266, causing
out of memory with a database beyond couple of pages.
2017-09-10 13:54:00 +03:00
Paul Sokolovsky 9b4666dad5 esp8266/posix_helpers: Set ENOMEM on memory alloc failure.
POSIX requires malloc(), etc. to set ENOMEM on the failure, and e.g.
BerkeleyDB relies on this:

http://pubs.opengroup.org/onlinepubs/9699919799/functions/malloc.html

This should fix confusing OSError exceptions with 0 error code when
working with btree module.
2017-09-10 09:55:18 +03:00
Paul Sokolovsky 5671a11b81 esp8266: Rename axtls_helpers.c to posix_helpers.c.
As it's used by BerkeleyDB, etc.
2017-09-10 09:47:20 +03:00
Damien George 4a93801c12 all: Update Makefiles and others to build with new ports/ dir layout.
Also renames "stmhal" to "stm32" in documentation and everywhere else.
2017-09-06 14:09:13 +10:00
Damien George 01dd7804b8 ports: Make new ports/ sub-directory and move all ports there.
This is to keep the top-level directory clean, to make it clear what is
core and what is a port, and to allow the repository to grow with new ports
in a sustainable way.
2017-09-06 13:40:51 +10:00