Commit Graph

1712 Commits

Author SHA1 Message Date
Maureen Helm
4837b1caa2 zephyr: Convert DT_FLASH_AREA usages to new dts macros.
Converts DT_FLASH_AREA usages in the zephyr port to new device tree macros
introduced in zephyr 2.3.

Tested with littlefs on the reel_board.
2020-06-12 10:25:04 +10:00
Maureen Helm
6aff27ac3c zephyr: Update to new zephyr timeout API.
Updates the zephyr port to use the new timeout api introduced in zephyr
2.3.
2020-06-12 10:24:54 +10:00
Maureen Helm
db02cb061d zephyr: Update for refactored zephyr device structures.
Updates the zephyr port to use refactored device structures introduced in
zephyr 2.3.
2020-06-12 10:24:46 +10:00
Maureen Helm
8b061f2d79 zephyr: Fix floating point configuration.
Zephyr renamed CONFIG_FLOAT to CONFIG_FPU to better reflect its semantics
of enabling the hardware floating point unit (FPU) rather than enabling
toolchain-level floating point support (i.e., software floating point for
FPU-less socs).
2020-06-12 10:24:30 +10:00
Maureen Helm
38b4f1569e zephyr: Fix and rename stacks_analyze function in zephyr module.
Zephyr deprecated and then removed its stack_analyze function because it
was unsafe.  Use the new zephyr thread analyzer instead and rename the
MicroPython function to zephyr.thread_analyze() to be more consistent with
the implementation.

Tested on mimxrt1050_evk.

The output now looks like this:

>>> zephyr.thread_analyze()
Thread analyze:
 80004ff4            : unused 400 usage 112 / 512 (21 %)
 rx_workq            : unused 1320 usage 180 / 1500 (12 %)
 tx_workq            : unused 992 usage 208 / 1200 (17 %)
 net_mgmt            : unused 656 usage 112 / 768 (14 %)
 sysworkq            : unused 564 usage 460 / 1024 (44 %)
 idle                : unused 256 usage 64 / 320 (20 %)
 main                : unused 2952 usage 1784 / 4736 (37 %)
2020-06-12 10:24:01 +10:00
Albort Xue
05e5d411b5 mimxrt/boards: Set __heap_size__ to 0 in MIMXRT1011.ld.
Do not use the traditional C heap in order to save memory, because the
traditional C heap is unused in MicroPython.
2020-06-10 22:49:26 +10:00
Jim Mussared
3f77f2c60c unix/btstack_usb: Allow choosing adaptor via environment variable.
This allows running (for example):

    env MICROPYBTUSB=2-2 ./micropython-dev ../../examples/bluetooth/ble_temperature_central.py
2020-06-10 22:40:02 +10:00
jp-96
3705bc418c extmod/modbluetooth: Register default GATT service and fix esp32 init.
This is for the NimBLE bindings, to make sure the default GATT service
appears and that the esp32 initialises NimBLE correctly (it now matches
stm32).
2020-06-10 22:33:29 +10:00
Philipp Ebensberger
29e258611a mimxrt/boards: Integrate support for MIMXRT1020_EVK board. 2020-06-09 19:04:23 +10:00
Albort Xue
e0d539f79d mimxrt/boards: Enable LED class for MIMXRT1060_EVK board. 2020-06-09 18:51:08 +10:00
Jim Mussared
8e8dcdd34b esp32: Update IDF v4.0 supported hash to v4.0.1.
The main fix relevant to MicroPython is https://github.com/espressif/esp-idf/issues/4196

Release notes here
https://github.com/espressif/esp-idf/releases/tag/v4.0.1
2020-06-09 16:15:47 +10:00
Philipp Ebensberger
6ac05af8e1 mimxrt/tusb_config.h: Preliminary fix for TinyUSB HS endpoint overflow.
Sending more than 64 bytes to the USB CDC endpoint in HS mode will lead to
a hard crash.  This commit fixes the issue, although there may be a better
fix from upstream TinyUSB in the future.
2020-06-08 14:39:21 +10:00
Damien George
621f40b12c esp32/mpthreadport: Fix calculation of thread stack size.
With this commit the code should work correctly regardless of the size of
StackType_t (it's actually 1 byte in size for the esp32's custom FreeRTOS).

Fixes issue #6072.
2020-06-05 20:55:37 +10:00
Damien George
596fb73927 qemu-arm: Support building in debug mode with DEBUG=1.
Fixes issue #6095.
2020-06-05 20:52:10 +10:00
Philipp Ebensberger
02cc4462b7 mimxrt: Add initial impl of machine.LED class, and basic pin support.
This commit implements an LED class with rudimentary parts of a pin C API
to support it.  The LED class does not yet support setting an intensity.

This LED class is put in the machine module for the time being, until a
better place is found.

One LED is supported on TEENSY40 and MIMXRT1010_EVK boards.
2020-06-05 11:47:48 +10:00
Damien George
8e591d412a minimal: Make build more flexible and work as 64-bit build.
Changes are:
- string0 is no longer built when building for host as the target, because
  it'll be provided by the system libc and may in some cases clash with the
  system one (eg on OSX).
- mp_int_t/mp_uint_t are defined in terms of intptr_t/uintptr_t to support
  both 32-bit and 64-bit builds.
- Configuration values which are the default in py/mpconfig.h are removed
  from mpconfigport.h to make the configuration a bit more minimal, eg as
  a better starting point for new ports.
2020-06-02 15:43:44 +10:00
stinos
da71f55e23 stm32/Makefile: Quote libgcc path so spaces are not an issue.
Fixes #3116.
2020-06-02 14:11:08 +10:00
David Spickett
a4086a2f13 qemu-arm/README: Update link to toolchain.
New releases have moved from launchpad to developer.arm.com.
2020-06-02 14:09:56 +10:00
Damien George
246f3f640d stm32/boards/xxx_WB55: Enable pyb.ADC and hardware SPI on WB55 boards.
These features are now supported (although machine.ADC is recommended over
pyb.ADC).
2020-06-02 10:48:49 +10:00
Damien George
c8985d52d3 stm32/dma: Add support for DMA on STM32WB, with SPI settings provided. 2020-06-02 10:48:49 +10:00
Damien George
0f7b5cceea stm32/machine_adc: Make setting of ADC1_COMMON->CCR clearer on STM32WB. 2020-06-02 10:48:49 +10:00
Damien George
5210fc51ec stm32/adc: Add support to pyb.ADC for STM32WB MCUs. 2020-06-02 10:48:49 +10:00
Damien George
68d053c66e stm32/modmachine: Allow changing AHB and APB bus frequencies on STM32WB.
For now SYSCLK cannot be changed and must remain at 64MHz.
2020-06-02 10:48:49 +10:00
Damien George
9ae50d22c9 stm32/machine_uart: Allow re-init'ing a static UART object.
Just disallow changing the rxbuf which will be some static RAM (can't free
it and soft-reset would lose any dynamically allocated buffer).
2020-06-01 21:41:54 +10:00
Damien George
88971342b1 stm32/machine_uart: Retain attached-to-repl setting when init'ing UART. 2020-06-01 21:41:50 +10:00
Joel Stanley
f03d030080 powerpc/uart: Choose which UART to use at build time, not runtime.
Microwatt may have firmware that places data in r3, which was used to
detect microwatt vs powernv.  This breaks the existing probing of the UART
type in this powerpc port.

Instead build only the appropriate UART into the firmware, selected by
passing the option UART=potato or UART=lpc_serial to the Makefile.

A future enhancement would be to parse the device tree and configure
MicroPython based on the settings.
2020-05-29 22:54:55 +10:00
Thorsten von Eicken
50a7ba2348 esp32/modmachine: Fix machine.reset_cause to use IDF's esp_reset_reason.
The code previously called rtc_get_reset_reason which is a "raw" reset
cause.  The ESP-IDF massages that for the proper reset cause available from
esp_reset_reason.

Fixes issue #5134.
2020-05-29 22:27:53 +10:00
cccc
1662a0b06f esp32/machine_sdcard: Add "freq" keyword arg to SDCard constructor.
To allow high speed access.
2020-05-28 12:19:04 +10:00
stijn
9523ca92e0 windows: Make appveyor.yml self-contained.
Add configuration which otherwise has to be set via the UI so the file is
more self-contained, and remove configuration which is not needed because
it's the same as the default.  The major change here is that for a while
now Appveyor has been using Visual Studio 2015 by default while we still
want to support 2013.
2020-05-28 09:56:35 +10:00
stijn
81db22f693 py/modmath: Work around msvc float bugs in atan2, fmod and modf.
Older implementations deal with infinity/negative zero incorrectly.  This
commit adds generic fixes that can be enabled by any port that needs them,
along with new tests cases.
2020-05-28 09:54:54 +10:00
Joel Stanley
b65482ffa8 powerpc: Set better default compiler.
Most developers use a compiler which is called powerpc64le-linux-gnu-gcc.
2020-05-27 17:02:04 +10:00
Joel Stanley
25bc42e754 powerpc: Fix Makefile rule when linking.
The linker script was included in the "$^" inputs, causing the build to
fail:

 LINK build/firmware.elf
 powerpc64le-linux-gnu-ld: error: linker script file 'powerpc.lds' appears multiple times

As a fix the linker script is left as a dependency of the elf, but only the
object files are linked.
2020-05-27 17:00:44 +10:00
Albort Xue
b3bc9808f2 mimxrt/boards: Add MIMXRT1060_EVK board. 2020-05-27 16:49:52 +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
Yu-Ming Chang
dd8db974d7 unix/main: Enter REPL when inspect active, even with stdin redirected.
This is how CPython behaves.
2020-05-16 14:13:15 +10:00
Jim Mussared
cd9a8c1742 nrf: Add openocd as a supported flasher.
Tested with the Particle Debugger on a Xenon.
2020-05-15 15:06:02 +10:00
Jim Mussared
e7f8c7d9a3 nrf: Update to work with nrfx v2.0.0, to match TinyUSB.
Commit 6cea369b89 updated the TinyUSB
submodule to a version based on nrfx v2.0.0.  This commit updates the nrf
port to work with the latest TinyUSB and nrfx v2.0.0.
2020-05-15 15:06:02 +10:00
Damien George
8f348778e1 nrf/mphalport: Remove need for "syntax unified" in mp_hal_delay_us.
Because it can confuse older versions of gcc.  Instead use the correct
instruction for Thumb vs Thumb-2 (sub vs subs) so the assembler emits the
2-byte instruction.

Related to commit 1aa9ff9141.
2020-05-15 15:04:49 +10:00
Damien George
eb5e9c00f8 nrf/Makefile: Don't use -fno-builtin for Cortex-M0 builds.
So that error string compression is optimised correctly (it needs strcmp to
be optimised away by the compiler).
2020-05-15 13:39:12 +10:00
Thomas Roberts
463c0fb2f4 stm32/boards: Add board config for Nucleo-F412ZG development board. 2020-05-15 10:48:48 +10:00
Thomas Roberts
d7399679de stm32: Add support for F412 MCUs. 2020-05-15 10:08:30 +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
3b6c9119eb extmod/modbluetooth: Add support for changing the GAP device name.
This commit allows the user to set/get the GAP device name used by service
0x1800, characteristic 0x2a00.  The usage is:

    BLE.config(gap_name="myname")
    print(BLE.config("gap_name"))

As part of this change the compile-time setting
MICROPY_PY_BLUETOOTH_DEFAULT_NAME is renamed to
MICROPY_PY_BLUETOOTH_DEFAULT_GAP_NAME to emphasise its link to GAP and this
new "gap_name" config value.  And the default value of this for the NimBLE
bindings is changed from "PYBD" to "MPY NIMBLE" to be more generic.
2020-05-11 21:30:41 +10:00
Thorsten von Eicken
f385b7bfa8 stm32/README: Reorg DFU flashing instructions with addition for PYBD. 2020-05-11 21:23:41 +10:00
Thorsten von Eicken
ab4e197707 esp32/modsocket: Fix getaddrinfo to raise on error.
This commit fixes the behaviour of socket.getaddrinfo on the ESP32 so it
raises an OSError when the name resolution fails instead of returning a []
or a resolution for 0.0.0.0.

Tests are added (generic and ESP32-specific) to verify behaviour consistent
with CPython, modulo the different types of exceptions per MicroPython
documentation.
2020-05-09 16:43:48 +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
e2def200bf stm32/boards/PYBD_SF2: Put BTstack library in external QSPI XIP flash.
In the same way the nimble stack is put there.
2020-05-05 20:21:15 +10:00
Maureen Helm
25434e976b zephyr: Use zephyr build system to merge configurations.
The zephyr build system supports merging application-level board
configurations, so there is no need to reproduce this functionality in
MicroPython.

If CONF_FILE is not explicitly set, then the zephyr build system looks for
prj.conf in the application directory.  Therefore we rename the MicroPython
prj_base.conf to prj.conf.

Furthermore, if the zephyr build system finds boards/$(BOARD).conf in the
application directory, it merges that configuration with prj.conf.
Therefore we rename all the MicroPython board .conf files and move them
into a boards/ directory.

The minimal configuration, prj_minimal.conf, is left in the application
directory because it is used as an explicitly set CONF_FILE in
make-minimal.
2020-05-05 00:48:44 +10:00
Thorsten von Eicken
40e9227733 esp32/partitions: Update comments in files regarding offset. 2020-05-03 15:01:26 +10:00
Thorsten von Eicken
952ff8a8ea esp32: Improve support for OTA updates.
This commit adds several small items to improve the support for OTA
updates on an esp32:

- a partition table for 4MB flash modules that has two OTA partitions ready
  to go to do updates
- a GENERIC_OTA board that uses that partition table and that enables
  automatic roll-back in the bootloader
- a new esp32.Partition.mark_app_valid_cancel_rollback() class-method to
  signal that the boot is successful and should not be rolled back at the
  next reset
- an automated test for doing an OTA update
- documentation updates
2020-05-03 15:00:45 +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
5c8bf12acf all: Fix auto-enable of MICROPY_GCREGS_SETJMP to select GC behaviour.
Only enable it if MICROPY_GCREGS_SETJMP is not already defined, and no
supported architecture is defined.
2020-04-30 16:49:42 +10:00
Jim Mussared
710426024a all: Factor gchelper code to one place and use it for unix & ARM ports.
No functionality change is intended with this commit, it just consolidates
the separate implementations of GC helper code to the lib/utils/ directory
as a general set of helper functions useful for any port.  This reduces
duplication of code, and makes it easier for future ports or embedders to
get the GC implementation correct.

Ports should now link against gchelper_native.c and either gchelper_m0.s or
gchelper_m3.s (currently only Cortex-M is supported but other architectures
can follow), or use the fallback gchelper_generic.c which will work on
x86/x64/ARM.

The gc_helper_get_sp function from gchelper_m3.s is not really GC related
and was only used by cc3200, so it has been moved to that port and renamed
to cortex_m3_get_sp.
2020-04-29 23:45:19 +10:00
Jim Mussared
2e3c42775a unix: Add btstack to the unix submodules list.
But only when bluetooth is enabled, i.e. if building the dev or coverage
variants, and we have libusb available.

Update travis to match, i.e. specify the variant when doing
`make submodules`.
2020-04-29 16:54:12 +10:00
Jim Mussared
ebfd9ff2e6 extmod/modbluetooth: Fix sign compare and unused variable warnings. 2020-04-29 16:54:12 +10:00
Jim Mussared
af226199ea unix: Enable modbluetooth on the "dev" and "coverage" variants.
And MICROPY_PY_URANDOM_EXTRA_FUNCS is enabled on "dev" so tha the Bluetooth
examples all run.
2020-04-29 16:53:13 +10:00
Jim Mussared
7563d58210 unix: Add support for modbluetooth and BLE using btstack.
This commit adds full support to the unix port for Bluetooth using the
common extmod/modbluetooth Python bindings.  This uses the libusb HCI
transport, which supports many common USB BT adaptors.
2020-04-29 16:45:46 +10:00
Jim Mussared
50e44f477b stm32/main: Peform a clean shutdown of btstack on soft reset.
Not just NimBLE.
2020-04-29 16:45:46 +10:00
Jim Mussared
8119ec0765 extmod/modbluetooth: Don't hold atomic section during mp_sched_schedule.
Because, for example, on unix the atomic section isn't re-entrant, and
mp_sched_schedule() will try to re-acquire the atomic section.
2020-04-29 16:45:40 +10:00
Jim Mussared
0da47ecc93 stm32/Makefile: Rename SRC_LIB to LIB_SRC_C to match other ports. 2020-04-29 16:38:18 +10:00
Jim Mussared
cb5994d96e unix/modmachine: Add machine.idle(), implemented using sched_yield.
Also add a definition of MICROPY_EVENT_POLL_HOOK so the unix port can build
against modules that require this.
2020-04-29 16:37:46 +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
Thorsten von Eicken
1ae7e0e561 esp32: Consolidate check_esp_err functions and add IDF error string.
This commit consolidates a number of check_esp_err functions that check
whether an ESP-IDF return code is OK and raises an exception if not.  The
exception raised is an OSError with the error code as the first argument
(negative if it's ESP-IDF specific) and the ESP-IDF error string as the
second argument.

This commit also fixes esp32.Partition.set_boot to use check_esp_err, and
uses that function for a unit test.
2020-04-23 10:59:07 +10:00
Thorsten von Eicken
a177831c46 esp32/modesp32: Add idf_heap_info(capabilities) to esp32 module.
This commit adds an idf_heap_info(capabilities) method to the esp32 module
which returns info about the ESP-IDF heaps.  It's useful to get a bit of a
picture of what's going on when code fails because ESP-IDF can't allocate
memory anymore.  Includes documentation and a test.
2020-04-23 00:02:11 +10:00
Andrew Leech
8ee2e1fdbc stm32/mboot: Expose custom DFU USB VID/PID values at makefile level.
In mboot, the ability to override the USB vendor/product id's was added
back in 5688c9ba09.  However, when the main
firmware is turned into a DFU file the default VID/PID are used there.
pydfu.py doesn't care about this but dfu-util does and prevents its use
when the VID/PID don't match.

This commit exposes BOOTLOADER_DFU_USB_VID/PID as make variables, for use
on either command line or mpconfigboard.mk, to set VID/PID in both mboot
and DFU files.
2020-04-18 23:02:00 +10:00
stijn
30840ebc99 all: Enable extra conversion warnings where applicable.
Add -Wdouble-promotion and -Wfloat-conversion for most ports to ban out
implicit floating point conversions, and add extra Travis builds using
MICROPY_FLOAT_IMPL_FLOAT to uncover warnings which weren't found
previously.  For the unix port -Wsign-comparison is added as well but only
there since only clang supports this but gcc doesn't.
2020-04-18 22:42:28 +10:00
stijn
70affd9ba2 all: Fix implicit floating point to integer conversions.
These are found when building with -Wfloat-conversion.
2020-04-18 22:42:24 +10:00
stijn
bcf01d1686 all: Fix implicit conversion from double to float.
These are found when building with -Wfloat-conversion.
2020-04-18 22:42:24 +10:00
stijn
0ba68f8a1d all: Fix implicit floating point promotion.
Initially some of these were found building the unix coverage variant on
MacOS because that build uses clang and has -Wdouble-promotion enabled, and
clang performs more vigorous promotion checks than gcc.  Additionally the
codebase has been compiled with clang and msvc (the latter with warning
level 3), and with MICROPY_FLOAT_IMPL_FLOAT to find the rest of the
conversions.

Fixes are implemented either as explicit casts, or by using the correct
type, or by using one of the utility functions to handle floating point
casting; these have been moved from nativeglue.c to the public API.
2020-04-18 22:36:14 +10:00
stijn
b909e8b2dd Revert "all: Fix implicit casts of float/double, and signed comparison."
This reverts commit a2110bd3fc.  There's
nothing inherently wrong with it, but upcoming commits will apply similar
fixes in a slightly different way.
2020-04-18 22:36:06 +10:00
Martin Fischer
28833690bb stm32/mboot/README: Clarify that mboot can access FAT formatted FS only. 2020-04-16 16:28:07 +10:00
Martin Fischer
7942d0b688 stm32/storage: Fix start address of second, internal block device. 2020-04-16 16:25:20 +10:00
Damien George
f534b99765 esp32: Update to ESP IDF v3.3.2. 2020-04-14 23:30:03 +10:00
Damien George
8e048d2548 all: Clean up error strings to use lowercase and change cannot to can't.
Now that error string compression is supported it's more important to have
consistent error string formatting (eg all lowercase English words,
consistent contractions).  This commit cleans up some of the strings to
make them more consistent.
2020-04-13 22:19:37 +10:00
David Lechner
1bbc15dd15 unix/Makefile: Fix regression using install on non-GNU systems.
This was fixed previously in 31fc81d3b8 but
regressed in 4af79e7694.

Fixes #5885.
2020-04-13 22:11:36 +10:00
Jim Mussared
c2cfbcc8d4 unix: Implement MICROPY_BEGIN/END_ATOMIC_SECTION protection macros.
This macro is used to implement global serialisation, typically by
disabling IRQs.  On the unix port, if threading is enabled, use the
existing thread mutex (that protects the thread list structure) for this
purpose.  Other places in the code (eg the scheduler) assume this macro
will provide serialisation.
2020-04-13 21:44:09 +10:00
Jim Mussared
45cf76465c unix: Fix behaviour of COPT/NDEBUG for unix variants.
Based on eg 1e6fd9f2b4, it's understood that
the intention for unix builds is that regular builds disable assert, but
the coverage build should set -O0 and enable asserts.

It looks like this didn't work (even before variants were introduced, eg at
v1.11) -- coverage always built with -Os and -DNDEBUG.

This commit makes it possible for variants to have finer-grained control
over COPT flags, and enables assert() and -O0 on coverage builds.

Other variants already match the defaults so they have been updated.
2020-04-13 21:20:32 +10:00
Damien George
d6f80963df esp32/espneopixel: Use integer arithmetic to compute timing values. 2020-04-09 16:23:34 +10:00
Damien George
e292296d52 py/objexcept: Remove optional TimeoutError exception.
TimeoutError was added back in 077812b2ab for
the cc3200 port. In f522849a4d the cc3200
port enabled use of it in the socket module aliased to socket.timeout.  So
it was never added to the builtins.  Then it was replaced by
OSError(ETIMEDOUT) in 047af9b10b.

The esp32 port enables this exception, since the very beginning of that
port, but it could never be accessed because it's not in builtins.

It's being removed: 1) to not encourage its use; 2) because there are a lot
of other OSError subclasses which are not defined at all, and having
TimeoutError is a bit inconsistent.

Note that ports can add anything to the builtins via MICROPY_PORT_BUILTINS.
And they can also define their own exceptions using the
MP_DEFINE_EXCEPTION() macro.
2020-04-09 16:09:38 +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
Jim Mussared
92c83bd16b windows: Update genhdr.targets to match makeqstrdefs.py args. 2020-04-05 14:29:49 +10:00
Jim Mussared
1921224272 extmod/modubinascii: Make code private and module self-contained.
This commit makes all functions and function wrappers in modubinascii.c
STATIC and conditional on the MICROPY_PY_UBINASCII setting, which will
exclude the file from qstr/ compressed-string searching when ubinascii is
not enabled.  The now-unused modubinascii.h header file is also removed.

The cc3200 port is updated accordingly to use this module in its entirety
instead of providing its own top-level definition of ubinascii.

This was originally like this because the cc3200 port has its own ubinascii
module which referenced these methods.  The plan appeared to be that the
API might diverge (e.g. hardware crc), but this should be done similar to
I2C/SPI via a port-specific handler, rather than the port having its own
definition of the module.  Having a centralised module definition also
enforces consistency of the API among ports.
2020-04-05 14:13:53 +10:00
Jim Mussared
994c1dd57a stm32/Makefile: Add missing ordering dependency on generated headers. 2020-04-05 14:12:59 +10:00
Damien George
312c699491 esp32: Change from FAT to littlefs v2 as default filesystem.
This commit changes the default filesystem type for esp32 to littlefs v2.
This port already enables both VfsFat and VfsLfs2, so either can be used
for the filesystem, and existing systems that use FAT will still work.
2020-04-04 17:03:30 +11: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
Jim Mussared
e97bb58f0e esp32/README.md: Fix typo in venv instructions. 2020-04-02 22:52:48 +11:00
Damien George
8fff0b0acd unix/mpthreadport: Ensure enough thread stack to detect overflow.
Following up to 5e6cee07ab, some systems (eg
FreeBSD 12.0 64-bit) will crash if the stack-overflow margin is too small.
It seems the margin of 8192 bytes (or thereabouts) is always needed.  This
commit adds this much margin if the requested stack size is too small.

Fixes issue #5824.
2020-03-31 09:35:46 +11:00
David Lechner
a2110bd3fc all: Fix implicit casts of float/double, and signed comparison.
These were found by buiding the unix coverage variant on macOS (so clang
compiler).  Mostly, these are fixing implicit cast of float/double to
mp_float_t which is one of those two and one mp_int_t to size_t fix for
good measure.
2020-03-30 12:04:21 +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
83461e37d4 stm32/boards: Disable pend_throw, uheapq, utimeq on small-flash boards.
These are mainly used by the previous version of uasyncio which is now
replaced by a newer version, with built-in C module _uasyncio.  Saves about
1300 bytes of flash.
2020-03-28 13:55:59 +11:00
Damien George
09154f585f stm32/mpconfigport.h: Make most extended modules configurable by board. 2020-03-28 13:46:35 +11:00
David Lechner
9418611c8a unix: Implement PEP 475 to retry syscalls failing with EINTR.
https://www.python.org/dev/peps/pep-0475/

This implements something similar to PEP 475 on the unix port, and for the
VfsPosix class.

There are a few differences from the CPython implementation:
- Since we call mp_handle_pending() between any ENITR's, additional
  functions could be called if MICROPY_ENABLE_SCHEDULER is enabled, not
  just signal handlers.
- CPython only handles signal on the main thread, so other threads will
  raise InterruptedError instead of retrying.  On MicroPython,
  mp_handle_pending() will currently raise exceptions on any thread.

A new macro MP_HAL_RETRY_SYSCALL is introduced to reduce duplicated code
and ensure that all instances behave the same.  This will also allow other
ports that use POSIX-like system calls (and use, eg, VfsPosix) to provide
their own implementation if needed.
2020-03-27 14:40:46 +11:00
David Lechner
5e6cee07ab unix/mpthreadport: Fix crash when thread stack size <= 8k.
The stack size adjustment for detecting stack overflow in threads was not
taking into account that the requested stack size could be <= 8k, in which
case the subtraction would overflow.  This is fixed in this commit by
ensuring that the adjustment can't be more than the available size.

This fixes the test tests/thread/thread_stacksize1.py which sometimes
crashes with a segmentation fault because of an uncaught NLR jump, which is
a "maximum recursion depth exceeded" exception.

Suggested-by: @dpgeorge
2020-03-27 13:59:18 +11:00
Damien George
dbba6b05dc stm32/mpconfigport.h: Remove unused root pointer for BTstack bindings.
This was a cut-and-paste error from the NimBLE bindings.
2020-03-27 00:30:37 +11:00
Damien George
ad004db662 esp32: Enable and freeze uasyncio. 2020-03-26 01:25:46 +11:00
Damien George
1d4d688b3b esp8266: Enable and freeze uasyncio.
Only included in GENERIC build.
2020-03-26 01:25:46 +11:00
Damien George
35e2dd0979 stm32: Enable and freeze uasyncio. 2020-03-26 01:25:45 +11:00
Damien George
91dd3948e8 unix: Enable uasyncio C helper module on coverage build. 2020-03-26 01:25:45 +11:00
Damien George
f05ae416ff stm32/softtimer: Initialise pairing-heap node before pushing to heap. 2020-03-26 01:21:04 +11:00
Damien George
f9741d18f6 unix/coverage: Init all pairheap test nodes before using them. 2020-03-26 01:21:04 +11:00
Damien George
ab00f4c44e qemu-arm: Set default board as mps2-an385 to get more flash for tests.
And use Ubuntu bionic for qemu-arm Travic CI job.
2020-03-26 01:21:04 +11:00
Damien George
f8fc78691d py/mpconfig.h: Enable MICROPY_MODULE_GETATTR by default.
To enable lazy loading of submodules (among other things), which is very
useful for MicroPython libraries that want to have optional subcomponents.

Disabled explicitly on minimal ports.
2020-03-26 01:21:04 +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
bf4fb16250 esp32/modsocket: Handle poll of a closed socket.
This gets tests/extmod/uselect_poll_basic.py working on the esp32.
2020-03-25 01:17:12 +11:00
David Lechner
d0edaf88a3 windows/windows_mphal: Fix missing semicolon. 2020-03-25 00:59:34 +11:00
David Lechner
3b07736b6d unix,windows: Use STDIN_FILENO, STDOUT_FILENO macros where appropriate.
This replaces 0 and 1 with STDIN_FILENO and STDOUT_FILENO to make the
intention of the code clearer.
2020-03-25 00:59:05 +11:00
David Lechner
100012bec6 windows: Remove custom definition of MP_PLAT_PRINT_STRN.
This removes the port-specific definition of MP_PLAT_PRINT_STRN on the
windows port, so that the default mp_hal_stdout_tx_strn_cooked() is always
used.  This fixes releasing the GIL during the call to write() (this was
missed in bc3499f010).

Also, mp_hal_dupterm_tx_strn() was defined but never used anywhere so it is
safe to delete it.
2020-03-25 00:56:38 +11:00
David Lechner
b1066a9f96 unix: Remove custom definition of MP_PLAT_PRINT_STRN.
This removes the port-specific definition of MP_PLAT_PRINT_STRN on the unix
port.  Since fee7e5617f this is no longer a
single function call so we are not really optimising anything over using
the default definition of MP_PLAT_PRINT_STRN which calls
mp_hal_stdout_tx_strn_cooked().
2020-03-25 00:54:18 +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
stijn
f62cc41fac windows/msvc: Fix warnings regarding function declarations.
Fix missing mkdir and gettimeofday declarations, then silence msvc-specific
compiler warning C4996: 'The POSIX name for this item is deprecated'.
2020-03-25 00:38:11 +11:00
Maureen Helm
76a5b3a97a zephyr: Update machine.Pin class to use new zephyr gpio api.
Zephyr v2.2 reworked its gpio api to support linux device tree bindings and
pin logical levels.  This commit updates the zephyr port's machine.Pin
class to replace the deprecated gpio api calls with the new supported gpio
api.  This resolves several build warnings.

Tested on frdm_k64f and mimxrt1050_evk boards.
2020-03-25 00:29:42 +11:00
Damien George
40255aff23 stm32/mboot: Remove unnecessary test for led being 1 in led_state.
The "led" argument is always a pointer to the GPIO port, or'd with the pin
that the LED is on, so testing that it is "1" is unnecessary.  The type of
"led" is also changed to uint32_t so it can properly hold a 32-bit pointer.
2020-03-25 00:10:32 +11:00
Andrew Leech
9dd470b768 stm32/mboot: Update LED0 state from systick handler.
Updating the LED0 state from systick handler ensures LED0 is always
consistent with its flash rate regardless of other processing going on in
either interrupts or main.  This improves the visible stability of the
bootloader, rather than LED0 flashing somewhat randomly at times.

This commit also changes the LED0 flash rate depending on the current state
of DFU, giving slightly more visual feedback on what the device is doing.
2020-03-25 00:08:32 +11:00
Andrew Leech
f7130a99b6 stm32/mboot: Protect against invalid address flash writes.
And provide a DFU error message for invalid erases and writes.
2020-03-22 15:23:49 +11:00
Andrew Leech
b41d08cf15 stm32/mboot: Update dfu state/status flags to better match standard. 2020-03-22 14:11:16 +11:00
Andrew Leech
03b1ed80e7 stm32/mboot: Allow overriding led_init and led_state in board folder.
Allows for custom functions/logic to display mboot state.
2020-03-22 13:48:45 +11:00
Jim Mussared
9715905b18 esp32/README.md: Update build instructions for newer toolchain.
Also fix Espressif links to the specific version they apply to.
2020-03-22 13:26:03 +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
2cdf1d25f5 unix: Remove custom file implementation to use extmod's VFS POSIX one.
The implementation in extmod/vfs_posix_file.c is now equivalent to that in
ports/unix/file.c, so remove the latter and use the former instead.
2020-03-18 21:01:07 +11:00
Damien George
ad9a0ec8ab all: Convert exceptions to use mp_raise_XXX helpers in remaining places. 2020-03-18 17:26:19 +11:00
Damien George
eae495a714 stm32/main: Fix bug mounting 3rd SD partition.
Fixes issue #5753.
2020-03-12 12:34:31 +11:00
Maureen Helm
110a610f70 zephyr: Execute main.py file if it exists.
Adds support in the zephyr port to execute main.py if the file system is
enabled and the file exists. Existing support for executing a main.py
frozen module is preserved, since pyexec_file_if_exists() works just
like pyexec_frozen_module() if there's no vfs.
2020-03-11 08:30:42 -05:00
Maureen Helm
78c7e4a859 zephyr: Enable usb mass storage class on mimxrt1050_evk.
Enables the zephyr usb device stack and mass storage class on the
mimxrt1050_evk board. The mass storage class is backed by the sdhc disk
access driver, so it's now possible to browse and modify the contents of
the SD card from a USB host (your PC). This is in preparation to support
writing a main.py script to the SD card, and then executing it after the
next reset.
2020-03-11 07:46:41 -05:00
Maureen Helm
5feb54afbb zephyr: Mount a file system during init.
Adds support in the zephyr port to mount a file system if a block device
(sdhc disk access or flash area) is available. The mount point is either
"/sd" or "/flash" depending on the type of block device.

Tested with an sdhc disk access block device and fatfs on the
mimxrt1050_evk board.

Tested with a flash area block device and littlefs on the reel_board.
2020-03-11 07:46:41 -05:00
Damien George
359213fbe1 unix/Makefile: Detect and pass thru mpy-cross flags when running tests. 2020-03-11 20:20:18 +11:00
Andrew Leech
86bfabec11 py/modmicropython: Add heap_locked function to test state of heap.
This commit adds micropython.heap_locked() which returns the current
lock-depth of the heap, and can be used by Python code to check if the heap
is locked or not.  This new function is configured via
MICROPY_PY_MICROPYTHON_HEAP_LOCKED and is disabled by default.

This commit also changes the return value of micropython.heap_unlock() so
it returns the current lock-depth as well.
2020-03-11 16:54:16 +11:00
Jim Mussared
7eea0d8b6c mimxrt: Add MIMXRT1010 board. 2020-03-11 15:36:27 +11:00
Jim Mussared
f46782dde9 mimxrt: Add new, minimal port to NXP i.MX RT series CPUs.
This is an extremely minimal port to the NXP i.MX RT, in the style of the
SAMD port  It's largely based on the TinyUSB mimxrt implementation, using
the NXP SDK.  It currently supports the Teensy 4.0 board with a REPL over
the USB-VCP interface.

This commit also adds the NXP SDK submodule (also from TinyUSB) to
lib/nxp_driver.

Note: if you already have the tinyusb submodule initialized recursively you
will need to run the following as the tinyusb sub-submodules have been
rearranged (upstream):

    git submodule deinit lib/tinyusb
    rm -rf .git/modules/lib/tinyusb
    git submodule update --init lib/tinyusb
2020-03-11 15:34:13 +11:00
Jim Mussared
211032a5c9 samd: Fix to build with latest tinyusb. 2020-03-11 15:34:10 +11:00
Damien George
ed848553b4 extmod/vfs: Factor out vfs mount-and-chdir helper from stm32. 2020-03-11 14:24:26 +11:00
Thomas Friebel
bd746a4630 esp32: Deinitialize Bluetooth on soft reset.
This fixes a crash, caused by NimBLE continuing to call the Python BLE
interrupt handler after soft reboot.
2020-03-11 13:02:00 +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
e965363b6b stm32: Refactor Bluetooth HCI RX to be independent of transport layer.
Now all HCI specific code (eg UART vs WB55 internal messaging) is confined
to modbluetooth_hci.c.
2020-03-10 01:53:42 +11:00
Damien George
0674917bc5 extmod/btstack: Implement advertising.
Work done in collaboration with Jim Mussared aka @jimmo.
2020-03-10 01:53:42 +11:00
Damien George
51f8591097 stm32/boards/PYBD: Allow building with BTstack (via make command line).
Work done in collaboration with Jim Mussared aka @jimmo.
2020-03-10 01:53:42 +11:00
Damien George
0e95815bfb stm32: Add bindings for BTstack implementation.
Work done in collaboration with Jim Mussared aka @jimmo.
2020-03-10 01:53:42 +11:00
Damien George
894c550c86 stm32: Refactor bluetooth stack/hci/driver bindings.
This makes a cleaner separation between the: driver, HCI UART and BT stack.
Also updated the naming to be more consistent (mp_bluetooth_hci_*).

Work done in collaboration with Jim Mussared aka @jimmo.
2020-03-10 01:53:42 +11:00
Damien George
c44d52f33e extmod/modbluetooth_nimble: Move nimble specific code, factor nimble.mk.
Move extmod/modbluetooth_nimble.* to extmod/nimble.  And move common
Makefile lines to extmod/nimble/nimble.mk (which was previously only used
by stm32).  This allows (upcoming) btstack to follow a similar structure.

Work done in collaboration with Jim Mussared aka @jimmo.
2020-03-06 12:35:20 +11:00
Damien George
44aa5b2200 stm32/modnetwork: Remove redundant call to nimble_poll in lwip poll.
The bluetooth stack has its own dedicated polling function, see
mod_bluetooth_nimble_poll_wrapper().
2020-03-06 12:35:20 +11:00
Damien George
3e0b46b9af unix/file: Don't raise OSError(EINVAL) on sys.stdin/out/err.flush().
sys.stdout.flush() is needed on CPython to flush the output, and the change
in this commit makes such an expression also work on MicroPython (although
MicroPython doesn't actual need to do any flushing).
2020-03-04 12:39:55 +11:00