Commit Graph

2606 Commits

Author SHA1 Message Date
Jonathan Bruchim
dde0735ac1 zephyr: Guard I2C code with appropriate ifdef config.
To reduce binary code size when not using I2C.

Signed-off-by: Jonathan Bruchim <yonbruchim@gmail.com>
2020-12-07 23:11:00 +11:00
Maureen Helm
92a5ee6ac1 zephyr: Replace broken shell_net_iface() with more general shell_exec().
The zephyr function net_shell_cmd_iface() was removed in zephyr v1.14.0,
therefore the MicroPython zephyr port did not build with newer zephyr
versions when CONFIG_NET_SHELL=y. Replace with a more general
shell_exec() function that can execute any zephyr shell command. For
example:

>>> zephyr.shell_exec("net")

Subcommands:
  allocs     :Print network memory allocations.
  arp        :Print information about IPv4 ARP cache.
  conn       :Print information about network connections.
  dns        :Show how DNS is configured.
  events     :Monitor network management events.
  gptp       :Print information about gPTP support.
  iface      :Print information about network interfaces.
  ipv6       :Print information about IPv6 specific information and
              configuration.
  mem        :Print information about network memory usage.
  nbr        :Print neighbor information.
  ping       :Ping a network host.
  pkt        :net_pkt information.
  ppp        :PPP information.
  resume     :Resume a network interface
  route      :Show network route.
  stacks     :Show network stacks information.
  stats      :Show network statistics.
  suspend    :Suspend a network interface
  tcp        :Connect/send/close TCP connection.
  vlan       :Show VLAN information.
  websocket  :Print information about WebSocket connections.

>>> zephyr.shell_exec("kernel")

kernel - Kernel commands
Subcommands:
  cycles   :Kernel cycles.
  reboot   :Reboot.
  stacks   :List threads stack usage.
  threads  :List kernel threads.
  uptime   :Kernel uptime.
  version  :Kernel version.

Signed-off-by: Maureen Helm <maureen.helm@nxp.com>
2020-12-07 23:01:00 +11:00
Damien George
cb1bb7592e stm32/Makefile: Change -O0 to -Og for DEBUG=1 builds.
The -Og optimisation level produces a more realistic build, gives a better
debugging experience, and generates smaller code than -O0, allowing debug
builds to fit in flash.

This commit also assigns variables in can.c to prevent warnings when -Og is
used, and builds a board in CI with DEBUG=1 enabled.

Signed-off-by: Damien George <damien@micropython.org>
2020-12-07 22:27:38 +11:00
Damien George
1e4e2644ec stm32: Add support for a board to reserve certain peripherals.
Allows reserving CAN, I2C, SPI, Timer and UART peripherals.  If reserved
the peripheral cannot be accessed from Python.

Signed-off-by: Damien George <damien@micropython.org>
2020-12-07 17:22:08 +11:00
Damien George
4ce6427bd7 stm32/i2c: Factor I2C finding code to i2c_find_peripheral function.
Signed-off-by: Damien George <damien@micropython.org>
2020-12-07 17:21:36 +11:00
iabdalkader
7dc2f4ed38 stm32/powerctrl: Ensure SysTick is disabled on STOP mode entry for H7.
Even though IRQs are disabled this seems to be required on H7 Rev Y,
otherwise Systick interrupt triggers and the MCU leaves the stop mode
immediately.
2020-12-07 17:00:56 +11:00
iabdalkader
7b9b6d080a stm32/powerctrl: Set H7 RTC wakeup flags. 2020-12-07 17:00:42 +11:00
iabdalkader
8add94e94e stm32/powerctrl: Disable RTC write protection before changing flags. 2020-12-07 17:00:21 +11:00
iabdalkader
463a275bc4 stm32/powerctrl: On H7, re-enable disabled OSCs/PLLs on exit from STOP.
This commit saves OSCs/PLLs state before STOP mode and restores them on
exit.  Some boards use HSI48 for USB for example, others have PLL2/3
enabled, etc.
2020-12-07 16:58:38 +11:00
iabdalkader
3e5dd2dbcc stm32/powerctrl: Fix STOP mode voltage scaling on H7 REV V devices. 2020-12-07 16:58:00 +11:00
iabdalkader
e9e619fa24 stm32/powerctrl: Define RCC_SR_SFTRSTF flag for H747. 2020-12-07 16:57:29 +11:00
iabdalkader
ce9197eb20 stm32/Makefile: Disable text compression in debug builds.
Otherwise the flash overflows.

Fixes issue #6653.
2020-12-07 16:45:15 +11:00
iabdalkader
849748873c stm32/modmachine: Add device and revision ids to machine.info(). 2020-12-07 16:39:18 +11:00
Jim Mussared
0e8af2b370 extmod/modbluetooth: Add API for L2CAP channels.
Also known as L2CAP "connection oriented channels". This provides a
socket-like data transfer mechanism for BLE.

Currently only implemented for NimBLE on STM32 / Unix.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2020-11-24 01:07:17 +11:00
Damien George
64180f0742 extmod/machine_i2c: Add init protocol method for generic I2C bindings.
Hardware I2C implementations must provide a .init() protocol method if they
want to support reconfiguration.  Otherwise the default is that i2c.init()
raises an OSError (currently the case for all ports).

mp_machine_soft_i2c_locals_dict is renamed to mp_machine_i2c_locals_dict to
match the generic SPI bindings.

Fixes issue #6623 (where calling .init() on a HW I2C would crash).

Signed-off-by: Damien George <damien@micropython.org>
2020-11-23 19:45:04 +11:00
JPFrancoia
3dcb551d89 nrf/README: Describe Pin numbering scheme for nRF52840.
Clarify that the nRF52840's GPIO 1.00 to 1.15 maps to Pin(32-47) in
MicroPython.
2020-11-22 21:01:49 +01:00
robert
5af3c046c7 esp32,esp8266: Remove "FAT" from warning message in inisetup.py.
Because FAT is not any more the only filesystem used.
2020-11-18 16:26:19 +11:00
Jim Mussared
240b3de8bc stm32/rfcore: Depend on NimBLE only when BLE enabled.
This fixes the build for non-STM32WB based boards when the NimBLE submodule
has not been fetched, and also allows STM32WB boards to build with BLE
disabled.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2020-11-18 14:45:51 +11:00
Jim Mussared
21c293fbcd stm32/rfcore: Don't send HCI ACL cmds while another is pending.
And, for TX, the next/prev entries ane unused so set them to NULL to
indicate this.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2020-11-16 17:09:12 +11:00
Jim Mussared
119c88ef17 stm32/flash: Implement WB55 flash locking.
This is needed to moderate concurrent access to the internal flash, as
while an erase/write is in progress execution will stall on the wireless
core due to the bus being locked.

This implements Figure 10 from AN5289 Rev 3.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2020-11-16 17:08:30 +11:00
Jim Mussared
a64121b0d4 stm32/rfcore: Make RX IRQ schedule the NimBLE handler.
This commit switches the STM32WB HCI interface (between the two CPUs) to
require the use of MICROPY_PY_BLUETOOTH_USE_SYNC_EVENTS, and as a
consequence to require NimBLE.  IPCC RX IRQs now schedule the NimBLE
handler to run via mp_sched_schedule.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2020-11-16 17:04:27 +11:00
Jim Mussared
61d1e4b01b extmod/nimble: Make stm32 and unix NimBLE ports use synchronous events.
This changes stm32 from using PENDSV to run NimBLE to use the MicroPython
scheduler instead.  This allows Python BLE callbacks to be invoked directly
(and therefore synchronously) rather than via the ringbuffer.

The NimBLE UART HCI and event processing now happens in a scheduled task
every 128ms.  When RX IRQ idle events arrive, it will also schedule this
task to improve latency.

There is a similar change for the unix port where the background thread now
queues the scheduled task.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2020-11-13 17:19:05 +11:00
Jim Mussared
81e92d3d6e extmod/modbluetooth: Re-instate optional no-ringbuf modbluetooth.
This requires that the event handlers are called from non-interrupt context
(i.e. the MicroPython scheduler).

This will allow the BLE stack (e.g. NimBLE) to run from the scheduler
rather than an IRQ like PENDSV, and therefore be able to invoke Python
callbacks directly/synchronously.  This allows writing Python BLE handlers
for events that require immediate response such as _IRQ_READ_REQUEST (which
was previous a hard IRQ) and future events relating to pairing/bonding.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2020-11-13 17:19:05 +11:00
Jim Mussared
4559bcb467 unix: Make mp_hal_delay_ms run MICROPY_EVENT_POLL_HOOK.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2020-11-13 17:19:05 +11:00
Andrew Leech
de60aa7d6b unix: Handle pending events/scheduler in MICROPY_EVENT_POLL_HOOK.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2020-11-13 17:19:05 +11:00
Damien George
cc2a35b7b2 stm32/rtc: Validate the RTC prescaler on boot and change if incorrect.
Devices with RTC backup-batteries have been shown (very rarely) to have
incorrect RTC prescaler values.  Such incorrect values mean the RTC counts
fast or slow, and will be wrong forever if the power/backup-battery is
always present.

This commit detects such a state at start up (hard reset) and corrects it
by reconfiguring the RTC prescaler values.

Signed-off-by: Damien George <damien@micropython.org>
2020-11-13 11:23:52 +11:00
Damien George
a0623a081c stm32/Makefile: Allow boards to extend all SRC variables.
And rename SRC_HAL -> HAL_SRC_C and SRC_USBDEV -> USBDEV_SRC_C for
consistency with other source variables.

Follow on from 0fff2e03fe

Signed-off-by: Damien George <damien@micropython.org>
2020-11-13 11:22:28 +11:00
Arrowana
922f81dfd1 extmod/machine_mem: Only allow integers in machine.memX subscript.
Prior to this change machine.mem32['foo'] (or using any other non-integer
subscript) could result in a fault due to 'foo' being interpreted as an
integer.  And when writing code it's hard to tell if the fault is due to a
bad subscript type, or an integer subscript that specifies an invalid
memory address.

The type of the object used in the subscript is now tested to be an
integer by using mp_obj_get_int_truncated instead of
mp_obj_int_get_truncated.  The performance hit of this change is minimal,
and machine.memX objects are more for convenience than performance (there
are many other ways to read/write memory in a faster way),

Fixes issue #6588.
2020-11-13 11:13:37 +11:00
Jonathan Hogg
8a917ad252 esp32/machine_pin: Reset pin if init sets mode.
This will forcibly grab the pin back from the ADC if it has previously been
associated with it.

Fixes #5771.
2020-11-12 15:27:41 +11:00
Sébastien NEDJAR
b04240cb77 stm32/Makefile: Make the generation of firmware.bin explicit.
The file `$(BUILD)/firmware.bin` was used by the target `deploy-stlink` and
`deploy-openocd` but it was generated indirectly by the target
`firmware.dfu`.

As this file could be used to program boards directly by a Mass Storage
copy, it's better to make it explicitly generated.

Additionally, some target are refactored to remove redundancy and be more
explicit on dependencies.
2020-11-12 15:22:44 +11:00
Damien George
b99300b53e stm32/boardctrl: Define MICROPY_BOARD_EARLY_INIT alongside others.
Signed-off-by: Damien George <damien@micropython.org>
2020-11-11 21:47:13 +11:00
Damien George
4c3976bbca stm32: Add MICROPY_BOARD calls in various places in stm32_main.
For a board to have full configurability of the soft reset loop.

Signed-off-by: Damien George <damien@micropython.org>
2020-11-11 21:41:04 +11:00
Damien George
1e297c8898 stm32/main: Move update_reset_mode to outside the soft-reset loop.
Running the update inside the soft-reset loop will mean that (on boards
like PYBD that use a bootloader) the same reset mode is used each
reset loop, eg factory reset occurs each time.

Signed-off-by: Damien George <damien@micropython.org>
2020-11-11 21:41:04 +11:00
Damien George
97960dc7de stm32: Support C++ code and user C modules written in C++.
Also build user C modules as part of the stm32 CI.

Signed-off-by: Damien George <damien@micropython.org>
2020-10-29 23:35:36 +11:00
Damien George
df3b466d6c stm32/boards: Factor out common data/bss/heap/stack linker sections.
Signed-off-by: Damien George <damien@micropython.org>
2020-10-29 23:31:59 +11:00
Damien George
a866f868f8 unix/Makefile: Move coverage.c and coveragecpp.cpp to coverage variant.
So that g++ is not needed to build a non-coverage unix variant.

Signed-off-by: Damien George <damien@micropython.org>
2020-10-29 23:30:04 +11:00
stijn
25c4563f26 examples: Add example code for user C modules, both C and C++.
Add working example code to provide a starting point for users with files
that they can just copy, and include the modules in the coverage test to
verify the complete user C module build functionality.  The cexample module
uses the code originally found in cmodules.rst, which has been updated to
reflect this and partially rewritten with more complete information.
2020-10-29 15:30:42 +11:00
stijn
fad4079778 esp32,unix: Support building C++ code.
Support building .cpp files and linking them into the micropython
executable in a way similar to how it is done for .c files.  The main
incentive here is to enable user C modules to use C++ files (which are put
in SRC_MOD_CXX by py.mk) since the core itself does not utilize C++.

However, to verify build functionality a unix overage test is added.  The
esp32 port already has CXXFLAGS so just add the user modules' flags to it.
For the unix port use a copy of the CFLAGS but strip the ones which are not
usable for C++.
2020-10-29 15:29:50 +11:00
stijn
f1666419a8 py/mkrules.mk: Add target for compiling C++ files.
Move the target from the ESP32 Makefile since that does what is needed
already, but also include files from user C modules as is done for the C
files.
2020-10-29 15:27:18 +11:00
Damien George
3e455e9792 stm32/rng: Use SysTick+RTC+unique-id to seed pRNG for MCUs without RNG.
The same seed will only occur if the board is the same, the RTC has the
same time (eg freshly powered up) and the first call to this function (eg
via an "import random") is done at exactly the same time since reset.

Signed-off-by: Damien George <damien@micropython.org>
2020-10-29 14:14:40 +11:00
robert
59019d7f75 stm32/mpconfigport.h: Seed the urandom module on import.
For seeding the rng_get function is used, which is also the heart of
uos.urandom and pyb.rng, and is a hardware RNG where available.
2020-10-29 14:12:53 +11:00
robert
057193e855 esp8266/mpconfigport.h: Seed the urandom module on import.
For seeding, the hardware RNG of the esp8266 is used.
2020-10-29 14:12:44 +11:00
robert
b4062894df esp32/mpconfigport.h: Seed the urandom module on import.
For seeding, the RNG function of the ESP-IDF is used, which is told to be a
true RNG, at least when WiFi or Bluetooth is enabled.  Seeding on import is
as per CPython.  To obtain a reproducible sequence of pseudo-random numbers
one must explicitly seed with a known value.
2020-10-29 14:11:08 +11:00
Damien George
0118c07916 stm32/machine_adc: Fix ADC auto-calibration to run when ADC not enabled.
Prior to this commit, the ADC calibration code was never executing because
ADVREGEN bit was set making the CR register always non-zero.

This commit changes the logic so that ADC calibration is always run when
the ADC is disabled and an ADC channel is initialised.  It also uses the LL
API functions to do the calibration, to make sure it is done correctly on
each MCU variant.

Signed-off-by: Damien George <damien@micropython.org>
2020-10-29 11:09:43 +11:00
Emil Renner Berthing
05f95682e7 unix: Enable more warnings. 2020-10-22 11:54:11 +02:00
Damien George
581d43b774 stm32/usbd_cdc_interface: Check and handle CDC TX wrap-overflow.
If the device is not connected over USB CDC to a host then all output to
the CDC (eg initial boot messages) is written to the CDC TX buffer with
wrapping, so that the most recent data is retained when the USB CDC is
eventually connected (eg so the REPL banner is displayed upon connection).

This commit fixes a bug in this behaviour, which was likely introduced in
e4fcd216e0, where the initial data in the CDC
TX buffer is repeated multiple times on first connection of the device to
the host.

Signed-off-by: Damien George <damien@micropython.org>
2020-10-22 15:32:41 +11:00
iabdalkader
a93d9b8c2d stm32: Fix broken build when FAT FS multi-partition is disabled. 2020-10-22 14:58:29 +11:00
Andrew Leech
97108fce57 esp32/mpconfigport.h: Enable MICROPY_PY_DELATTR_SETATTR.
To align with unix and stm32 ports.
2020-10-21 11:11:48 +11:00
Andrew Leech
32c99174e1 unix/mpconfigport.h: Enable MICROPY_PY_DELATTR_SETATTR.
This is a generally useful feature and because it's part of the object
model it cannot be added at runtime by some loadable Python code, so enable
it on the standard unix build.
2020-10-20 23:47:50 +11:00
Damien George
18518e26a7 ports: Use correct in/out endpoint size in TUD_CDC_DESCRIPTOR.
The last argument of TUD_CDC_DESCRIPTOR() is the endpoint size (or
wMaxPacketSize), not the CDC RX buffer size (which can be larger than the
endpoint size).

Signed-off-by: Damien George <damien@micropython.org>
2020-10-17 15:49:16 +11:00
Jim Mussared
893f75546c stm32/boards/NUCLEO_WB55/rfcore_firmware.py: Increase GET_STATE timeout.
When installing WS firmware, the very first GET_STATE can take several
seconds to respond (especially with the larger binaries like
BLE_stack_full).

Allows stm.rfcore_sys_hci to take an optional timeout, defaulting to
SYS_ACK_TIMEOUT_MS (which is 250ms).

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2020-10-16 10:45:03 +11:00
Jim Mussared
dfb63b5613 stm32/boards/NUCLEO_WB55/rfcore_firmware.py: Fix bad variable name.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2020-10-16 10:44:58 +11:00
Jim Mussared
520bb88d70 stm32/boards/NUCLEO_WB55/rfcore_firmware.py: Fix flash unlock.
The flash can sometimes be in an already-unlocked state, and attempting to
unlock it again will cause an immediate reset.  So make _Flash.unlock()
check FLASH_CR_LOCK to get the current state.

Also fix some magic numbers for FLASH_CR_LOCK AND FLASH_CR_STRT.

The machine.reset() could be removed because it no longer crashes now that
the flash unlock is fixed.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2020-10-16 10:43:36 +11:00
Jim Mussared
fa12bfc227 stm32/rfcore: Update to support WS=1.9.0.0.4.
This WS update to 1.9.0.0.4 broke the workaround used in rfcore for
OCF_CB_SET_EVENT_MASK2, so fix it to support WS 1.8 and 1.9.
2020-10-09 23:52:35 +11:00
Jim Mussared
222ec1a4a8 stm32/boards/NUCLEO_WB55: Add standalone WB55 FUS/WS firmware updater.
This commit adds a script that can be run on-device to install FUS and WS
binaries from the filesystem.  Instructions for use are provided in
the rfcore_firmware.py file.

The commit also removes unneeded functionality from the existing rfcore.py
debug script (and renames it rfcore_debug.py).
2020-10-08 17:39:15 +11:00
Jim Mussared
7c76a2dfcf stm32/rfcore: Add Python API for basic rfcore operations.
The new functions provide FUS/WS status, version and SYS HCI commands:
- stm.rfcore_status()
- stm.rfcore_fw_version(fw_id)
- stm.rfcore_sys_hci(ogf, ocf, cmd)
2020-10-08 17:37:11 +11:00
iabdalkader
9855b9cd82 stm32/sdcard: Fix H7 build when using SDMMC2.
Changes are:
- Fix missing IRQ handler when SDMMC2 is used instead of SDMMC1 with H7
  MCUs.
- Removed outdated H7 series compatibility macros.
- Defined common IRQ handler macro for F4 series.
2020-10-06 23:33:38 +11:00
iabdalkader
7497d891a7 stm32/sdio: Don't change any DMA2 settings on H7 MCUs.
DMA2 clock and registers should be left in their current state in the H7
build.
2020-10-06 23:31:08 +11:00
Damien George
1dc64359da esp32: Use path relative to root for netutils/timeutils headers.
Signed-off-by: Damien George <damien@micropython.org>
2020-10-06 12:32:20 +11:00
Damien George
0fff2e03fe stm32/Makefile: Allow boards to extend SRC_C, SRC_O and OBJ variables.
Signed-off-by: Damien George <damien@micropython.org>
2020-10-02 15:46:13 +10:00
Damien George
817b80a102 unix/variants: Enable MICROPY_DEBUG_PARSE_RULE_NAME on coverage build.
Signed-off-by: Damien George <damien@micropython.org>
2020-10-01 15:26:43 +10:00
Damien George
d4b61b0017 extmod/utime_mphal: Add generic utime.time_ns() function.
It requires mp_hal_time_ns() to be provided by a port.  This function
allows very accurate absolute timestamps.

Enabled on unix, windows, stm32, esp8266 and esp32.

Signed-off-by: Damien George <damien@micropython.org>
2020-10-01 14:20:42 +10:00
Damien George
905a18aafe unix,windows: Implement mp_hal_time_ns using gettimeofday.
This provides microsecond accuracy.

Signed-off-by: Damien George <damien@micropython.org>
2020-10-01 14:20:42 +10:00
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
aaed33896b extmod/machine_i2c: Remove "id" arg in SoftI2C constructor.
The SoftI2C constructor is now used soley to create SoftI2C instances, it
can no longer delegate to create a hardware-based I2C 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
Maureen Helm
997ec9e8cc zephyr: Update build instructions to v2.4.0.
Updates the zephyr port build instructions to use the latest zephyr
release tag.

Signed-off-by: Maureen Helm <maureen.helm@nxp.com>
2020-09-30 23:21:53 +10:00
Maureen Helm
f842e32155 zephyr: Const-ify struct device instance pointers.
Zephyr v2.4.0 added a const qualifier to usages of struct device to
allow storing device driver instances exclusively in flash and thereby
reduce ram footprint.

Signed-off-by: Maureen Helm <maureen.helm@nxp.com>
2020-09-30 23:21:53 +10:00
Maureen Helm
ce49be43b1 zephyr: Replace zephyr integer types with C99 types.
Zephyr v2.4.0 stopped using custom integer types in favor of C99 types
instead.

Signed-off-by: Maureen Helm <maureen.helm@nxp.com>
2020-09-30 23:21:53 +10:00
stijn
bada8c9231 windows: Update build instructions in README.
Make the instructions more complete by documenting all needed steps for
starting from scratch.  Also add a section for MSYS2 since the Travis build
uses it as well and it's a good alternative for Cygwin.  Remove the mingw32
reference since it's not readily available anymore in most Linux distros
nor compiles successfully.
2020-09-23 22:22:13 +10:00
Damien George
3e16763201 stm32/rfcore: Fix FUS layout and size of ipcc_device_info_table_t.
The device info table has a different layout when core 2 is in FUS mode.
In particular it's larger than the 32 bytes used when in WS mode and if the
correct amount of space is not allocated then the end of the table may be
overwritten with other data (eg with FUS version 0.5.3).  So update the
structure to fix this.

Also update rfcore.py to disable IRQs (which are enabled by rfcore.c), to
not depend on uctypes, and to not require the asm_thumb emitter.

Signed-off-by: Damien George <damien@micropython.org>
2020-09-22 14:08:22 +10:00
Damien George
42342fa3cb tests/basics: Add test for MICROPY_PY_ALL_INPLACE_SPECIAL_METHODS ops.
And enable this feature on unix, the coverage variant.  The .exp test file
is needed so the test can run on CPython versions prior to "@=" operator
support.

Signed-off-by: Damien George <damien@micropython.org>
2020-09-18 18:40:42 +10:00
Tweako
8af9796b16 stm32/led: Support PWM output without TIM3.
For example, the STM32WB55 doesn't have TIM3 but can still drive LEDs using
PWM on other timers.
2020-09-18 18:37:11 +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
Mirko Vogt
ecb36d2439 esp32/modnetwork: Re-enable PPP support for IDF-SDK >=v4.
PPP support was disabled in 96008ff59a -
marked as "unsupported" due to an early IDF v4 release.  With the currently
supported IDF v4.x version - 4c81978a - it appears to be working just fine.
2020-09-18 15:57:21 +10:00
Jim Mussared
52d6eeb409 esp32/boards/sdkconfig.base: Set default IDF log level to ERROR.
This commit changes the default logging level on all esp32 boards to ERROR.
The esp32 port is now stable enough that it makes sense to remove the info
logs to make the output cleaner, and to match other ports.  More verbose
logging can always be reenabled via esp.osdebug().

This also fixes issue #6354, error messages from NimBLE: the problem is
that ble.active(True) will cause the IDF's NimBLE port to reset the
"NimBLE" tag back to the default level (which was INFO prior to this
commit).  Even if the user had previously called esp.osdebug(None), because
the IDF is setting the "NimBLE" tag back to the default (INFO), the
messages will continue to be shown.

The one quirk is that if the user does want to see the additional logging,
then they must call esp.osdebug(0, 3) after ble.active(True) to undo the
IDF setting the level back to the default (now ERROR).  This means that
it's impossible (via Python/esp.osdebug) to see stack-startup logging,
you'd have to recompile with the default level changed back to INFO.
2020-09-18 15:53:56 +10:00
Damien George
b31cb21a39 stm32/servo: Fix angle and speed methods to work again with -ve args.
Fixes a regression introduced by 70affd9ba2

Fixes issue #6403

Signed-off-by: Damien George <damien@micropython.org>
2020-09-12 13:47:59 +10:00
Damien George
acdb0608b7 py/parse: Pass in an mp_print_t to mp_parse_node_print.
So the output can be redirected if needed.

Signed-off-by: Damien George <damien@micropython.org>
2020-09-11 23:00:03 +10:00
Jim Mussared
50efce8174 esp32/mpconfigport.h: Remove duplicate uhashlib registration. 2020-09-11 11:03:29 +10:00
stijn
70bec41089 windows: Show test failures in the Appveyor builds. 2020-09-11 10:56:02 +10:00
stijn
5b94c61097 windows/Makefile: Support freezing modules.
Alter the build flags as needed to support freezing modules with a
manifest.  This makes freezing works just like it does for e.g. the unix
port.
2020-09-11 10:52:52 +10:00
stijn
2a9ea69fa9 windows/msvc: Support freezing modules.
Support freezing modules via manifest.py for consistency with the other
ports.  In essence this comes down to calling makemanifest.py and adding
the resulting .c file to the build.  Note the file with preprocessed qstrs
has been renamed to match what makemanifest.py expects and which is also
the name all other ports use.
2020-09-11 10:52:35 +10:00
stijn
2e54d9d146 py: Fix handling of NaN in certain pow implementations.
Adds a new compile-time option MICROPY_PY_MATH_POW_FIX_NAN for use with
toolchains that don't handle pow-of-NaN correctly.
2020-09-11 10:04:57 +10:00
Damien George
709398daae stm32/rtc.h: Include py/obj.h to make header self contained.
Signed-off-by: Damien George <damien@micropython.org>
2020-09-10 20:46:40 +10:00
Damien George
547688c58c stm32/usb: Don't nul pyb_hid_report_desc if MICROPY_HW_USB_HID disabled.
So this code can be used if pyb_hid_report_desc is not included in the
port's root pointer list.

Signed-off-by: Damien George <damien@micropython.org>
2020-09-10 20:46:35 +10:00
Damien George
27e117307d nrf: Remove unnecessary includes of mpconfigport.h and its header guard.
The mpconfigport.h file is an internal header and should only ever be
included once by mpconfig.h.

Signed-off-by: Damien George <damien@micropython.org>
2020-09-09 00:13:34 +10:00
Damien George
75344af4ca nrf/main: Make mp_builtin_open signature match that in py/builtin.h.
Signed-off-by: Damien George <damien@micropython.org>
2020-09-09 00:13:34 +10:00
Albort Xue
5f50568b1f mimxrt/boards: Add MIMXRT1064_EVK board. 2020-09-09 00:06:33 +10:00
Jim Mussared
632e3b7acc stm32/boards/NUCLEO_WB55: Add Python helper code for rfcore.
This allows prototyping rfcore.c improvements from Python.

This was mostly written by @dpgeorge with small modifications to work after
rfcore_init() by @jimmo.
2020-09-08 23:54:02 +10:00
Jim Mussared
e2390d5a2f stm32/rfcore: Enable RX IRQ on BLE IPCC channel for better performance.
Before this change there was up to a 128ms delay on incoming payloads from
CPU2 as it was polled by SysTick.  Now the RX IRQ immediately schedules the
PendSV.
2020-09-08 23:53:12 +10:00
Jim Mussared
8b4ebd7166 stm32/rfcore: Refactor some helper funcs, and remove some magic numbers.
Also explain what the payload fixup code is doing.
2020-09-08 23:53:12 +10:00
Jim Mussared
01f2d77614 stm32/rfcore: Fix length matching in HCI parser. 2020-09-08 23:53:12 +10:00
Jim Mussared
0f28020a68 stm32/powerctrlboot: Acquire HSEM5 on STM32WB during SystemClock_Config.
This is required to allow using WS firmware newer than 1.1.1 concurrently
with USB (e.g. USB VCP).  It prevents CPU2 from modifying the CLK48 config
on boot.

Tested on WS=1.8 FUS=1.1.

See AN5289 and https://github.com/micropython/micropython/issues/6316
2020-09-08 23:53:12 +10:00
Jim Mussared
9c9cc7a02f stm32/boards/USBDONGLE_WB55: Add USE_MBOOT support. 2020-09-08 23:53:12 +10:00
Jim Mussared
30e8162ac4 stm32/rfcore: Update rfcore.c to match how ST examples work.
- Split tables and buffers into SRAM2A/2B.
- Use structs rather than word offsets to access tables.
- Use FLASH_IPCCDBA register value rather than option bytes directly.
2020-09-08 23:53:02 +10:00
Jim Mussared
b27edb8073 stm32/make-stmconst.py: Add support for WB55 header files. 2020-09-08 23:23:23 +10:00
Jim Mussared
126f972c34 extmod/nimble: Add timeout for HCI sync on startup.
This allows `ble.active(1)` to fail correctly if the HCI controller is
unavailable.

It also avoids an infine loop in the NimBLE event handler where NimBLE
doesn't correctly detect that the HCI controller is unavailable and keeps
trying to reset.

Furthermore, it fixes an issue where GATT service registrations were left
allocated, which led to a bad realloc if the stack was activated multiple
times.
2020-09-08 12:53:24 +10:00
Jim Mussared
311b8519af esp32: Pin MicroPython and NimBLE tasks to core 0.
MicroPython and NimBLE must be on the same core, for synchronisation of the
BLE ringbuf and the MicroPython scheduler.  However, in the current IDF
versions (3.3 and 4.0) there are issues (see e.g. #5489) with running
NimBLE on core 1.

This change - pinning both tasks to core 0 - makes it possible to reliably
run the BLE multitests on esp32 boards.
2020-09-08 12:53:24 +10:00
Jim Mussared
99a29ec705 extmod/btstack: Detect HCI UART init failure. 2020-09-08 12:53:24 +10:00
Andrew Leech
6077c63a45 stm32/mpbthciport: Increase char timeout of BT HCI UART.
The 2ms used previously was not long enough and it could lose HCI sync.

Also print error on tx failure to make this more obvious in the future.
2020-09-08 12:53:24 +10:00
Jim Mussared
c4af714d58 extmod/modbluetooth: Implement configuration of address modes.
Changes `BLE.config('mac')` to return a tuple (addr_mode, addr).

Adds `BLE.config(addr_mode=...)` to set the addressing mode.
2020-09-08 12:53:24 +10:00
Jim Mussared
1b1b22905e unix: Implement BLE H4 HCI UART for btstack/nimble.
This commit adds support for using Bluetooth on the unix port via a H4
serial interface (distinct from a USB dongle), with both BTstack and NimBLE
Bluetooth stacks.

Note that MICROPY_PY_BLUETOOTH is now disabled for the coverage variant.
Prior to this commit Bluetooth was anyway not being built on Travis because
libusb was not detected.  But now that bluetooth works in H4 mode it will
be built, and will lead to a large decrease in coverage because Bluetooth
tests cannot be run on Travis.
2020-09-08 12:53:24 +10:00
Jim Mussared
feed69aa5c unix/Makefile: Always enable -f*-sections regardless of DEBUG setting. 2020-09-08 12:53:16 +10:00
Jim Mussared
f3f31ac959 extmod/nimble: Make nimble_malloc work with allocated size. 2020-09-08 11:41:31 +10:00
Jim Mussared
ed14435a8e extmod/modbluetooth: Refactor stack/hci/driver/port bindings.
Previously the interaction between the different layers of the Bluetooth
stack was different on each port and each stack.  This commit defines
common interfaces between them and implements them for cyw43, btstack,
nimble, stm32, unix.
2020-09-08 11:41:31 +10:00
Jim Mussared
5ff265a3db stm32/modbluetooth_hci: Use a static mp_irq_obj_t for BT HCI UART IRQ.
So that the IRQ handler does not need to be traced by the GC.
2020-09-08 10:47:27 +10:00
Jim Mussared
23109988c2 stm32/uart: Allow static IRQ handler registration.
This will allow the HCI UART to use a non-heap mp_irq_obj_t, which avoids
needing to make a root pointer for it.
2020-09-08 10:46:30 +10:00
Damien George
3ff7079277 lib/utils/mpirq: Add mp_irq_init func, and clean up unused init method.
mp_irq_init() is useful when the IRQ object is allocated by the caller.

The mp_irq_methods_t.init method is not used anywhere so has been removed.

Signed-off-by: Damien George <damien@micropython.org>
2020-09-04 12:40:38 +10:00
Damien George
5e69926ea0 stm32/mpconfigport.h: Enable MICROPY_PY_REVERSE_SPECIAL_METHODS.
It's a useful core feature.

Signed-off-by: Damien George <damien@micropython.org>
2020-09-04 10:45:39 +10:00
Damien George
a909c21587 unix/fatfs_port: Fix month offset in timestamp calculation.
Signed-off-by: Damien George <damien@micropython.org>
2020-09-02 00:19:06 +10:00
Damien George
2a72e90ab8 extmod/vfs: Add option to use 1970 as Epoch.
By setting MICROPY_EPOCH_IS_1970 a port can opt to use 1970/1/1 as the
Epoch for timestamps returned by stat().  And this setting is enabled on
the unix and windows ports because that's what they use.

Signed-off-by: Damien George <damien@micropython.org>
2020-09-01 12:36:28 +10:00
Damien George
0385b21597 unix/modos: Support larger integer range in uos.stat fields.
On 32-bit builds these stat fields will overflow a small-int, so use
mp_obj_new_int_from_uint to construct the int object.

Signed-off-by: Damien George <damien@micropython.org>
2020-09-01 12:36:28 +10:00
Damien George
40153b800a esp32/mphalport: Fix mp_hal_time_ns offset.
gettimeofday returns seconds since 2000/1/1 so needs to be adjusted to
seconds since 1970/1/1 to give the correct return value of mp_hal_time_ns.

Signed-off-by: Damien George <damien@micropython.org>
2020-08-31 00:49:58 +10:00
Damien George
836bca9956 unix/variants: Fix fast and freedos variants so they build again.
This regressed in bd2fff6687

Signed-off-by: Damien George <damien@micropython.org>
2020-08-30 13:48:26 +10:00
Damien George
06659077a8 all: Update Python code to conform to latest black formatting.
Updating to Black v20.8b1 there are two changes that affect the code in
this repository:

- If there is a trailing comma in a list (eg [], () or function call) then
  that list is now written out with one line per element.  So remove such
  trailing commas where the list should stay on one line.

- Spaces at the start of """ doc strings are removed.

Signed-off-by: Damien George <damien@micropython.org>
2020-08-29 15:18:01 +10:00
Damien George
40d174ac7d stm32/powerctrl.h: Include stdbool.h to get definition of bool.
Signed-off-by: Damien George <damien@micropython.org>
2020-08-29 14:00:24 +10:00
Damien George
a93a378e93 zephyr/README: Update required Zephyr version and mention new features.
Signed-off-by: Damien George <damien@micropython.org>
2020-08-28 16:42:32 +10:00
Roberto Colistete Jr
91c5d168c0 nrf/Makefile: Improve user C modules support.
Add CFLAGS_EXTRA to CFLAGS. Include LDFLAGS_MOD to the compilation.
And, add SRC_MOD to SRC_QSTR.
2020-08-26 22:14:40 +02: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
Damien George
92899354d9 unix/fatfs_port: Implement get_fattime.
Signed-off-by: Damien George <damien@micropython.org>
2020-08-22 14:45:57 +10:00
Dave Hylands
8727c4e2ec stm32/pin_defs_stm32: Fix pin printing to show IN mode correctly.
Prior to this commit, if you configure a pin as an output type (I2C in this
example) and then later configure it back as an input, then it will report
the type incorrectly.  Example:

    >>> import machine
    >>> b6 = machine.Pin('B6')
    >>> b6
    Pin(Pin.cpu.B6, mode=Pin.IN)
    >>> machine.I2C(1)
    I2C(1, scl=B6, sda=B7, freq=420000)
    >>> b6
    Pin(Pin.cpu.B6, mode=Pin.ALT_OPEN_DRAIN, pull=Pin.PULL_UP, af=Pin.AF4_I2C1)
    >>> b6.init(machine.Pin.IN)
    >>> b6
    Pin(Pin.cpu.B6, mode=Pin.ALT_OPEN_DRAIN, af=Pin.AF4_I2C1)

With this commit the last print now works:

    >>> b6
    Pin(Pin.cpu.B6, mode=Pin.IN)
2020-08-21 13:42:47 +10:00
Maureen Helm
ac94e06f0b zephyr: Include storage/flash_map.h unconditionally.
Include storage/flash_map.h unconditionally so we always have access to the
FLASH_AREA_LABEL_EXISTS macro, even if CONFIG_FLASH_MAP is not defined.

This fixes a build error for the qemu_x86 board:

main.c:108:63: error: missing binary operator before token "("
  108 |     #elif defined(CONFIG_FLASH_MAP) && FLASH_AREA_LABEL_EXISTS(storage)
      |                                                               ^
../../py/mkrules.mk:88: recipe for target 'build/genhdr/qstr.i.last' failed

Signed-off-by: Maureen Helm <maureen.helm@nxp.com>
2020-08-21 11:23:43 +10:00
Damien George
fd2ff867a0 stm32/usbdev: Fix calculation of SCSI LUN size with multiple LUNs.
The SCSI driver calls GetCapacity to get the block size and number of
blocks of the underlying block-device/LUN.  It caches these values and uses
them later on to verify that reads/writes are within the bounds of the LUN.
But, prior to this commit, there was only one set of cached values for all
LUNs, so the bounds checking for a LUN could use incorrect values, values
from one of the other LUNs that most recently updated the cached values.
This would lead to failed SCSI requests.

This commit fixes this issue by having separate cached values for each LUN.

Signed-off-by: Damien George <damien@micropython.org>
2020-07-25 01:12:07 +10:00
Glenn Ruben Bakke
caaaa2b1f4 nrf: Enable more features for all targets.
Enabling the following features for all targets, except for nrf51
targets compiled to be used with SoftDevice:

- MICROPY_PY_ARRAY_SLICE_ASSIGN
- MICROPY_PY_SYS_STDFILES
- MICROPY_PY_UBINASCII
2020-07-22 12:54:20 +02:00
Glenn Ruben Bakke
0a79e18398 nrf: Split mpconfigport.h into multiple files.
Splitting mpconfigport.h into multiple device specific
files in order to facilitate variations between devices.

Due to the fact that the devices might have variations in
features and also variations in flash size it makes sense
that some devices offers more functionality than others
without being limited by restricted devices.

For example more micropython features can be activated for
nrf52840 with 1MB flash, compared to nrf51 with 256KB.
2020-07-22 12:54:20 +02:00
Zoltán Vörös
27767aafa2 lib/libm_dbl: Add round.c source code.
This code is imported from musl, to match existing code in libm_dbl.

The file is also added to the build in stm32/Makefile.  It's not needed by
the core code but, similar to c5cc64175b,
allows round() to be used by user C modules or board extensions.
2020-07-21 11:07:19 +10:00
Kenneth Ryerson
76fefad18b esp32/network_lan: Add support for IP101 PHY.
Signed-off-by: Kenneth Ryerson <kenneth.ryerson@gmail.com>
2020-07-21 00:59:47 +10:00
Jonathan Hogg
7dbef5377c esp32/esp32_rmt: Properly fix looping behaviour of RMT.
A previous commit 3a9d948032 can cause
lock-ups of the RMT driver, so this commit reverses that, adds a loop_en
flag, and explicitly controls the TX interrupt in write_pulses().  This
provides correct looping, non-blocking writes and sensible behaviour for
wait_done().

See also #6167.
2020-07-21 00:57:14 +10:00
Thorsten von Eicken
5264478007 extmod/modussl_mbedtls: Integrate shorter error strings.
The stm32 and esp32 ports now use shorter error strings for mbedtls errors.
Also, MBEDTLS_ERROR_C is enabled on stm32 by default to get these strings.
2020-07-21 00:31:05 +10:00
Jim Mussared
5d0be97bd9 unix: Make the MICROPY_xxx_ATOMIC_SECTION mutex recursive.
This mutex is used to make the unix port behave more like bare metal, i.e.
it allows "IRQ handlers" to run exclusively by making the mutex recursive.
2020-07-18 14:22:06 +10:00
Matt Trentini
486cb6dd4a nrf: Add board definition for nRF52840-MDK-USB-Dongle. 2020-07-16 23:47:13 +10:00
Glenn Ruben Bakke
95d0d1c486 nrf/boards: Enable RTCounter machine module for nrf9160 boards.
Resolves dependencies for MICROPY_PY_TIME_TICKS which
requires to link against nrfx_rtc.c functions by setting
MICROPY_PY_MACHINE_RTCOUNTER to 1.
2020-07-16 11:48:52 +02:00
Glenn Ruben Bakke
b776fe6969 nrf/nrfx_config: Disable RTC2 for nRF9160 targets.
nRF9160 does not have any RTC2. Disable the configuration in
case of NRF9160_XXAA.
2020-07-16 11:44:44 +02:00
Alex Tsamakos
f743bd3d25
nrf/boards: Add initial support for Actinius Icarus.
Example make command:

make BOARD=actinius_icarus
2020-07-10 03:48:30 +02:00
iabdalkader
c299cc94e3 stm32/pyb_can: Handle timeout arg for FDCAN in pyb_can_send.
Following the documented pyb can_send behavior in pyb.CAN docs.
2020-07-09 00:38:56 +10:00
iabdalkader
d07073f4e2 stm32/fdcan: Support maximum timeout of HAL_MAX_DELAY in can_receive. 2020-07-09 00:38:40 +10:00
iabdalkader
63b2eb27d4 stm32/fdcan: Use FDCAN_RXFxS_FxFL instead of hard-coded value. 2020-07-09 00:38:33 +10:00
iabdalkader
8594389fe7 stm32/fdcan: Use the right FIFO to calc element address in can_receive. 2020-07-09 00:37:50 +10:00
Damien George
f5dd46b479 unix/variants: Enable VFS and all supported filesystems on dev variant.
So that micropython-dev can be used to test VFS code, and inspect and build
filesystem images that are compatible with bare-metal systems.

Signed-off-by: Damien George <damien@micropython.org>
2020-07-08 23:57:25 +10:00
Martin Fischer
59ed3bdd9f nrf: Enable nrf tick support on all boards by default.
Having time.ticks_ms/us/add/diff is very useful and used by many drivers,
libraries and components.
2020-07-08 23:47:08 +10:00
Martin Fischer
15574cd665 nrf: Add support for time.ticks_xxx functions using RTC1.
This commit adds time.ticks_ms/us support using RTC1 as the timebase.  It
also adds the time.ticks_add/diff helper functions.  This feature can be
enabled using MICROPY_PY_TIME_TICKS.  If disabled the system uses the
legacy sleep methods and does not have any ticks functions.

In addition support for MICROPY_EVENT_POLL_HOOK was added to the
time.sleep_ms(x) function, making this function more power efficient and
allows support for select.poll/asyncio.  To support this, the RTC's CCR0
was used to schedule a ~1msec event to wakeup the CPU.

Some important notes about the RTC timebase:

- Since the granularity of RTC1's ticks are approx 30usec, time.ticks_us is
not perfect, does not have 1us resolution, but is otherwise quite usable.
For tighter measurments the ticker's 1MHz counter should be used.

- time.ticks_ms(x) should *not* be called in an IRQ with higher prio than
the RTC overflow irq (3).  If so it introduces a race condition and
possibly leads to wrong tick calculations.

See #6171 and #6202.
2020-07-08 23:47:02 +10:00
Glenn Ruben Bakke
c2317a3a8d nrf/Makefile: Disable ROM text compression when compiling for debug.
When compiling for debug (-O0) the .text segment cannot fit the flash
region when MICROPY_ROM_TEXT_COMPRESSION=1, because the compiler does not
optimise away the large if-else chain used to select the correct compressed
string.

This commit enforces MICROPY_ROM_TEXT_COMPRESSION=0 when compiling for
debug (DEBUG=1).
2020-07-01 22:54:52 +10:00
Glenn Ruben Bakke
f22f7b285e nrf/bluetooth/ble_uart: Swap end character on cooked strings.
Changing line ending character of cooked strings makes rshell/pyboard.py
work correctly over Bluetooth socat/pts devices.
2020-07-01 22:51:30 +10:00
Glenn Ruben Bakke
5996bf72f1 nrf/bluetooth/ble_uart: Fix random advertisement name.
The storage space of the advertisement name is not declared static, leading
to a random advertisement name.  This commit fixes the issue by declaring
it static.
2020-07-01 22:50:56 +10:00
Glenn Ruben Bakke
ab0c14dba0 nrf/bluetooth/ble_uart: Add mp_hal_stdio_poll function.
This adds support for enabling MICROPY_PY_SYS_STDFILES when running UART
over Bluetooth (NUS).
2020-07-01 22:50:41 +10:00
Glenn Ruben Bakke
fc1f22a097 nrf/bluetooth: Handle data length update request.
The Bluetooth link gets disconnected when connecting from a PC after 30-40
seconds.  This commit adds handling of the data length update request.  The
data length parameter pointer is set to NULL in the reply,  letting the
SoftDevice automatically set values and use them in the data length update
procedure.
2020-07-01 22:49:04 +10:00
Glenn Ruben Bakke
9dfb4ae6aa nrf/bluetooth/ble_uart: Fix implicit declaration of function.
mp_keyboard_interrupt() triggers a compiler error because the function is
implicitly declared.  This commit adds "py/runtime.h" to the includes.

Fixes issue #5732.
2020-07-01 22:48:25 +10:00
Jim Mussared
4050281311 unix: Enable uasyncio on dev variant. 2020-07-01 22:44:41 +10:00
Jim Mussared
27abac95d8 unix: Make manifest selection match other ports.
Changes are:
- The default manifest.py is moved to the variants directory (it's in
  "boards" in other ports).
- The coverage variant now uses a custom manifest in its variant directory
  to add frzmpy/frzstr.
- The frzmpy/frzstr tests are moved to variants/coverage/.
2020-07-01 22:42:55 +10:00
Andrew Leech
494bcad8ab stm32/mboot: Disable polling mode by default and use IRQ mode instead.
Polling mode will cause failures with the mass-erase command due to USB
timeouts, because the USB IRQs are not being serviced.  Swiching from
polling to IRQ mode fixes this because the USB IRQs can be serviced between
page erases.

Note that when the flash is being programmed or erased the MCU is halted
and cannot respond to USB IRQs, because mboot runs from flash, as opposed
to the built-in bootloader which is in system ROM.  But the maximum delay
in responding to an IRQ is the time taken to erase a single page, about
100ms for large pages, and that is short enough that the USB does not
timeout on the host side.

Recent tests have shown that in the current mboot code IRQ mode is pretty
much the same speed as polling mode (within timing error), code size is
slightly reduced in IRQ mode, and IRQ mode idles at about half of the power
consumption as polling mode.
2020-07-01 16:54:03 +10:00
Andrew Leech
95ec0debec stm32/mboot: Remove the use of timeout in DFU_GETSTATUS.
This is treated more like a "delay before continuing" in the spec and
official tools and does not appear to be really needed.  In particular,
downloading firmware is much slower with non-zero timeouts because the host
must pause by the timeout between sending each DFU_GETSTATUS to poll for
download/erase complete.
2020-07-01 16:33:10 +10:00
Damien George
41b7734c46 zephyr/make-minimal: Disable FAT and LFS2 options to make it build.
Signed-off-by: Damien George <damien@micropython.org>
2020-06-30 22:33:41 +10:00
Damien George
f84145bea1 zephyr: Implement machine.Pin.irq() for setting callbacks on pin change.
Supports hard and soft interrupts.  In the current implementation, soft
interrupt callbacks will only be called when the VM is executing, ie they
will not be called during a blocking kernel call like k_msleep.  And the
behaviour of hard interrupt callbacks will depend on the underlying device,
as well as the amount of ISR stack space.

Soft and hard interrupts tested on frdm_k64f and nucleo_f767zi boards.

Signed-off-by: Damien George <damien@micropython.org>
2020-06-30 22:33:41 +10:00
Damien George
65a7e00078 stm32/mboot: Add DFU logic to respond to DFU_GETSTATE request.
This is required for some DFU programmers, eg ST's DfuSe demo PC app.

Signed-off-by: Damien George <damien@micropython.org>
2020-06-30 21:28:24 +10:00
Andrew Leech
40006813c3 stm32/flash: Update flash_get_sector_info to return -1 on invalid addr.
So the caller can tell when an invalid address is used and can take
appropriate action.
2020-06-30 21:24:28 +10:00
Andrew Leech
8bbaa20227 stm32/mboot: Implement DFU mass erase.
The implementation internally uses sector erase to wipe everything except
the sector(s) that mboot lives in (by erasing starting from
APPLICATION_ADDR).

The erase command can take some time (eg an STM32F765 with 2MB of flash
takes 8 to 10 seconds).  This time is normally enough to make pydfu.py fail
with a timeout.  The DFU standard includes a mechanism for the DFU device
to request a longer timeout as part of the get-status response just before
starting an operation.  This timeout functionality has been implemented
here.
2020-06-30 21:22:21 +10:00
Damien George
048a1d675d stm32/timer: Properly initialise timer deadtime/brk on WB MCUs.
Signed-off-by: Damien George <damien@micropython.org>
2020-06-29 17:35:42 +10:00
Andrew Leech
e4fcd216e0 stm32/usbd_cdc_interface: Remove full==size-1 limitation on tx ringbuf.
Before this commit the USB VCP TX ring-buffer used the basic implementation
where it can only be filled to a maximum of buffer size-1.  For a 1024 size
buffer this means the largest packet that can be sent is 1023.  Once a
packet of this size is sent the next byte copied in goes to the final byte
in the buffer, so must be sent as a 1 byte packet before the read pointer
can be wrapped around to the beginning.  So in large streaming transfers,
watching the USB sniffer you basically get alternating 1023 byte packets
then 1 byte packets.

This commit changes the ring-buffer implementation to a scheme that doesn't
have the full-size limitation, and the USB VCP driver can now achieve a
constant stream of full-sized packets.  This scheme introduces a
restriction on the size of the buffer: it must be a power of 2, and the
maximum size is half of the size of the index (in this case the index is
16-bit, so the maximum size would be 32767 bytes rounded to 16384 for a
power-of-2).  But this is not a big limitation because the size of the
ring-buffer prior to this commit was restricted to powers of 2 because it
was using a mask-based method to wrap the indices.

For an explanation of the new scheme see
https://www.snellman.net/blog/archive/2016-12-13-ring-buffers/

The RX buffer could likely do with a similar change, though as it's not
read from in chunks like the TX buffer it doesn't present the same issue,
all that's lost is one byte capacity of the buffer.

USB VCP TX throughput is improved by this change, potentially doubling the
speed in certain cases.
2020-06-29 17:21:37 +10:00
Damien George
137df81757 stm32/i2cslave: Pass I2C instance to callbacks to support multi I2Cs.
By passing through the I2C instance to the application callbacks, the
application can implement multiple I2C slave devices on different
peripherals (eg I2C1 and I2C2).

This commit also adds a proper rw argument to i2c_slave_process_addr_match
for F7/H7/WB MCUs, and enables the i2c_slave_process_tx_end callback.
Mboot is also updated for these changes.

Signed-off-by: Damien George <damien@micropython.org>
2020-06-26 23:56:45 +10:00
Damien George
0a8ce0d568 stm32/mboot: Update README to describe WB and littlefs support.
Signed-off-by: Damien George <damien@micropython.org>
2020-06-26 21:26:06 +10:00
Damien George
67fd58bbd2 stm32/mboot: Add support for littlefs.
Mboot now supports FAT, LFS1 and LFS2 filesystems, to load firmware from.
The filesystem needed by the board must be explicitly enabled by the
configuration variables MBOOT_VFS_FAT, MBOOT_VFS_LFS1 and MBOOT_VFS_LFS2.
Boards that previously used FAT implicitly (with MBOOT_FSLOAD enabled) must
now add the following config to mpconfigboard.h:

    #define MBOOT_VFS_FAT (1)

Signed-off-by: Damien George <damien@micropython.org>
2020-06-26 21:17:02 +10:00
Damien George
390f32922d stm32/mboot: Decouple stream, filesystem and top-level loading code.
This commit factors the code for files and streaming to separate source
files (vfs_fat.c and gzstream.c respectively) and introduces an abstract
gzstream interface to make it easier to plug in different filesystems.

Signed-off-by: Damien George <damien@micropython.org>
2020-06-26 21:15:30 +10:00
Damien George
763bd448a4 stm32/mboot: Don't search for firmware on FS, just attempt to open it.
There's no need to do a directory listing to search for the given firmware
filename, it just takes extra time and code size.  Instead this commit
changes it so that the requested firmware file is opened immediately and
will abort if the file couldn't be opened.  This also allows to specify
files in a directory.

Signed-off-by: Damien George <damien@micropython.org>
2020-06-26 21:11:03 +10:00
Damien George
717b5073aa stm32/boards: Enable LFS2 on PYBD_SF3 and PYBD_SF6.
This was missed in commit 120368ba1a

Signed-off-by: Damien George <damien@micropython.org>
2020-06-25 16:32:48 +10:00
Damien George
c5af3217d9 stm32/timer: Support TIM1 on WB MCUs.
Signed-off-by: Damien George <damien@micropython.org>
2020-06-25 16:32:48 +10:00
Damien George
eb9850ef6c stm32/mpconfigport.h: Enable PY_IO_FILEIO when any VFS is enabled.
Previously, if FAT was not enabled but LFS1/2 was then MICROPY_PY_IO_FILEIO
would be disabled and file binary-mode was not supported.

Signed-off-by: Damien George <damien@micropython.org>
2020-06-25 16:32:48 +10:00
Damien George
b4dc4c5b9a stm32/mboot: Use additional CFLAGS to compile string0.c.
This is the same as a902b69dd5 but applied to
mboot's Makefile.

Signed-off-by: Damien George <damien@micropython.org>
2020-06-23 14:00:16 +10:00
Damien George
81a7293ed6 stm32/mboot: Set VTOR on start up to ensure it has the correct value.
Commit 8675858465 switched to using the CMSIS
provided SystemInit function which sets VTOR to 0x00000000 (previously it
was 0x08000000).  A VTOR of 0x00000000 will be correct on some MCUs but not
on others where the built-in bootloader is remapped to this address, via
__HAL_SYSCFG_REMAPMEMORY_SYSTEMFLASH().

To make sure mboot has the correct vector table, this commit explicitly
sets VTOR to the correct value of 0x08000000.

Signed-off-by: Damien George <damien@micropython.org>
2020-06-23 13:56:20 +10:00
Damien George
6f40e6e131 stm32/boards: Add build-time option for NUCLEO_WB55 to use mboot.
As an example of how to use mboot on a WB series MCU.

Signed-off-by: Damien George <damien@micropython.org>
2020-06-22 14:18:15 +10:00
Damien George
705728369d stm32/mboot: Add support for using mboot with WB MCUs.
Signed-off-by: Damien George <damien@micropython.org>
2020-06-22 14:18:15 +10:00
Damien George
8675858465 stm32/mboot: Use CMSIS system source code for SystemInit function.
There's no need to duplicate this functionality in mboot, the code provided
in stm32lib/CMSIS does the same thing and makes it easier to support other
MCU series.

Signed-off-by: Damien George <damien@micropython.org>
2020-06-22 14:18:15 +10:00
Damien George
a8778c8dc8 stm32/mboot: Use flash routines from main stm32 code rather than custom.
The flash functions in ports/stm32/flash.c are almost identical to those in
ports/stm32/mboot/main.c, so remove the duplicated code in mboot and use
instead the main stm32 code.  This also allows supporting other MCU series.

Signed-off-by: Damien George <damien@micropython.org>
2020-06-22 14:18:15 +10:00
Damien George
736daebfc8 stm32/flash: Add flash_is_valid_addr, and extend sectors for 2MB F7.
Signed-off-by: Damien George <damien@micropython.org>
2020-06-22 14:18:15 +10:00
Damien George
4c8a68df6f stm32/i2cslave: Add support for WB MCUs.
Signed-off-by: Damien George <damien@micropython.org>
2020-06-22 14:18:15 +10:00
Damien George
afd47d58ac stm32/flash: Make flash C-API reusable, and funcs return an error code.
This commit makes the low-level flash C functions usable by code other than
flashbdev.c (eg by mboot).  Changes in this commit are:
- flash_erase() and flash_write() now return an errno error code, a
  negative value on error.
- flash_erase() now automatically locks the flash, as well as unlocking it.
- flash_write() now automatically unlocks the flash, as well as locking it.
- flashbdev.c is modified for the above changes.

Signed-off-by: Damien George <damien@micropython.org>
2020-06-22 14:18:15 +10:00
Damien George
ce326699d7 stm32/powerctrlboot: Include irq.h to get definitions of IRQ priorities.
irq.h is included by py/mphal.h but it's better to be explicit, eg if mboot
uses powerctrlboot.c.

Signed-off-by: Damien George <damien@micropython.org>
2020-06-22 13:47:48 +10:00
Damien George
5f3c2f1fa8 stm32/irq: Clean up irq.h so it does not depend on core uPy defines.
The irq.h file now just provides low-level IRQ definitions and priorities.
All Python binding definitions are moved to modmachine.h, with some
renaming of pyb -> machine, and also the machine_idle definition (was
pyb_wfi) is moved to modmachine.c.

The cc3200 and teensy ports are updated to build with these changes.

Signed-off-by: Damien George <damien@micropython.org>
2020-06-22 13:47:15 +10:00
Damien George
f1ba2c9d88 qemu-arm/Makefile: Add CFLAGS_EXTRA to CFLAGS.
Signed-off-by: Damien George <damien@micropython.org>
2020-06-22 13:42:24 +10:00
Jonathan Hogg
3a9d948032 esp32/esp32_rmt: Call rmt_driver_install before rmt_config.
Otherwise the RMT will repeat pulses when using loop(True).  This repeating
is due to a bug in the IDF which will be fixed in an upcoming release, but
for now the accepted workaround is to swap these calls, which should still
work in the fixed version of the IDF.

Fixes issue #6167.
2020-06-19 22:11:14 +10:00
David Lechner
77ed6f69ac tools/uncrustify: Enable more opts to remove space between func and '('.
With only `sp_func_proto_paren = remove` set there are some cases where
uncrustify misses removing a space between the function name and the
opening '('.  This sets all of the related options to `force` as well.
2020-06-19 22:07:32 +10:00
Damien George
ce02d5e348 stm32/boards/NUCLEO_WB55: Add more CPU pins and aliases to SW1/2/3.
Signed-off-by: Damien George <damien@micropython.org>
2020-06-18 10:48:24 +10:00
Glenn Ruben Bakke
8d71cc2e7d nrf/bluetooth: Use MP_ERROR_TEXT for all error messages.
This follows up on commit def76fe4d9.

Fixes issue #6152.
2020-06-17 11:33:22 +10:00
Damien George
4b5dd012e0 stm32/rfcore: Leave txpower level as default when initialising rfcore.
And provide a convenient API function to change it (currently unused).

Fixes issue #5985.

Signed-off-by: Damien George <damien@micropython.org>
2020-06-17 00:10:29 +10:00
Damien George
289be6b352 stm32/usb: Add support for 2xVCP on L0, L432 and WB MCUs.
There are a maximum of 8 USB endpoints and each has 2 buffer slots
(in/out).  This commit add support for up to 8 endpoints and adds FIFO
configuration for USB profiles with 2xVCP on MCUs that have device-only USB
peripherals.

Tested on NUCLEO_WB55 in 2xVCP, 2xVCP+MSC and 2xVCP+MSC+HID mode.

Signed-off-by: Damien George <damien@micropython.org>
2020-06-17 00:09:42 +10:00
Damien George
da99e0f979 stm32/factoryreset: Provide empty create-FS function when FAT disabled.
Signed-off-by: Damien George <damien@micropython.org>
2020-06-17 00:09:37 +10:00
Jon Rob
1678f41744 esp32/esp32_rmt: Extend RMT to support carrier feature.
The ESP32 RMT peripheral has hardware support for a carrier frequency, and
this commit exposes it to Python with the keyword arguments carrier_freq
and carrier_duty_percent in the constructor.  Example usage:

    r = esp32.RMT(0, pin=Pin(2), clock_div=80, carrier_freq=38000, carrier_duty_percent=50)
2020-06-17 00:03:33 +10:00
Damien George
2c5993c59e ports: Disable MICROPY_PY_ASSIGN_EXPR in bare-arm and minimal ports.
To keep these ports as minimal as possible.
2020-06-16 22:06:21 +10:00
Damien George
2b9900380a stm32/boards/STM32F769DISC: Use macro instead of const for flash size.
So that the flash size can be changed in just one place.  Also remove the
duplicate cache entry.
2020-06-12 10:28:26 +10:00
Maureen Helm
1ae861819d zephyr: Use cmake find_package to locate zephyr.
Updates the zephyr port to use the ZEPHYR_BASE environment variable only to
locate the zephyr cmake package, allowing cmake to cache the variable.
2020-06-12 10:25:16 +10:00
Maureen Helm
b1651ff092 zephyr: Increase minimum required cmake version to 3.13.1.
The minimum required cmake version has been 3.13.1 since zephyr 1.14.0.
2020-06-12 10:25:13 +10:00
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
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
73670ef281 unix/unix_mphal: Adjust #if in mp_hal_stdin_rx_chr to improve format. 2020-02-28 10:30:28 +11:00
hahmadi
b169904254 stm32/mpconfigport.h: Add option to have custom help text.
Define MICROPY_PY_BUILTINS_HELP_TEXT in <yourboard>/mpconfigboard.h for a
custom help text.
2020-02-21 15:02:19 +11:00
Damien George
410757f4f4 unix/mphalport.h: Fix build when MICROPY_USE_READLINE=0.
If the built-in input() is enabled (which it is by default) then it needs
some form of readline, so supply it with one when MICROPY_USE_READLINE=0.

Fixes issue #5658.
2020-02-20 00:45:58 +11:00
Jim Mussared
a9ce8dfdaa esp32: Move to IDF 4.0 release version. 2020-02-20 00:34:31 +11:00
David Lechner
4adcaa4423 unix/mpthreadport: Fix Mac build by using SIGUSR1 if SIGRTMIN not avail.
Some platforms, like Apple, don't define SIGRTMIN, so fall back to SIGUSR1
in such a case.

Fixes #5659.
2020-02-20 00:30:08 +11:00
Andrew Leech
3fe83e4318 stm32/sdram: Fix compile issue from unused sdram startup test flag. 2020-02-18 14:22:03 +11:00
David Lechner
3bd2ae1a36 unix/mpthreadport: Use SIGRTMIN+5 instead of SIGUSR1 for thread-GC.
This changes the signal used to trigger garbage collection from SIGUSR1 to
SIGRTMIN + 5.  SIGUSR1 is quite common compared to SIGRTMIN (measured by
google search results) and is more likely to conflict with libraries that
may use the same signal.

POSIX specifies that there are at least 8 real-time signal so 5 was chosen
as a "random" number to further avoid potential conflict with libraries
that may use SIGRTMIN or SIGRTMAX.

Also, if we ever have a `usignal` module, it would be nice to leave SIGUSR1
and SIGUSR2 free for user programs.
2020-02-18 13:32:42 +11:00
Damien George
ac8383a95d nrf: Use MICROPY_HW_ENABLE_RNG instead of MICROPY_PY_RANDOM_HW_RNG.
The "random" module no longer uses the hardware RNG (the extmod version of
this module has a pseudo-random number generator), so the config option
MICROPY_PY_RANDOM_HW_RNG is no longer meaningful.  This commit replaces it
with MICROPY_HW_ENABLE_RNG, which controls whether the hardware RNG is
included in the build.
2020-02-18 12:43:16 +11:00
Damien George
6ad3bb1e12 nrf: Remove custom "random" module and use extmod version instead.
Hardware RNG code is moved to drivers/rng.[ch].
2020-02-18 12:43:16 +11:00
cccc
4f3e5ea934 nrf/drivers/bluetooth: Fix variable initialisation error with older gcc.
Without this change, arm-none-eabi-gcc version 4.9.3 (at least) would give
a "missing braces around initializer" error.
2020-02-16 23:46:27 +11:00
David Lechner
4af79e7694 unix/Makefile: Allow to install all variants of the executable.
The install target is current broken when PROG is used to override the
default executable name.  This fixes it by removing the redundant TARGET
variable and uses PROG directly instead.

The install and uninstall targets are also moved to the common unix
Makefile so that all variants can be installed in the same way.
2020-02-16 23:37:40 +11:00
David Lechner
c5f4268c99 unix/variants/standard: Fix role of PREFIX when used to install.
Currently it is not possible to override PREFIX when installing micropython
using the makefile.  It is common practice to be able to run something like
this:

    $ make install PREFIX=/usr DESTDIR=/tmp/staging

This fixes such usage.
2020-02-16 23:35:52 +11:00
Damien George
baf11f237b unix/Makefile: Remove old variant targets that are no longer needed.
To eliminate confusion about what targets to use when building.
2020-02-16 00:15:57 +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
97eca38c4f py: Add mp_raise_type helper macro and use it where appropriate.
This provides a more consistent C-level API to raise exceptions, ie moving
away from nlr_raise towards mp_raise_XXX.  It also reduces code size by a
small amount on some ports.
2020-02-13 11:03:37 +11:00
Damien George
5a755ac30a esp32/modsocket: Convert EADDRINUSE error code from lwip return value. 2020-02-11 13:59:09 +11:00
stijn
5f91933e54 windows: Improve default search path.
The default value for MICROPYPATH used in unix/main.c is
"~/.micropython/lib:/usr/lib/micropython" which has 2 problems when used in
the Windows port:
- it has a ':' as path separator but the port uses ';' so the entire string
  is effectively discarded since it gets interpreted as a single path which
  doesn't exist
- /usr/lib/micropython is not a valid path in a standard Windows
  environment

Override the value with a suitable default.
2020-02-11 13:34:35 +11:00
stijn
8b6e6008c7 unix/main: Use OS-dependent path separator when searching path. 2020-02-11 13:33:56 +11:00
Damien George
580fd636c0 nrf/drivers: Use mp_raise_msg where appropriate, and shorten exc msgs.
If the exception doesn't need printf-style formatting then calling
mp_raise_msg is more efficient.  Also shorten exception messages to match
style in core and other ports.
2020-02-11 11:45:14 +11:00
Damien George
ce40abcf21 stm32/usbd_cdc_interface: Remove "interrupt_char != -1" check.
It's not needed.  The C integer implicit promotion rules mean that the
uint8_t of the incoming character is promoted to a (signed) int, matching
the type of interrupt_char.  Thus the uint8_t incoming character can never
be equal to -1 (the value of interrupt_char that indicate that interruption
is disabled).
2020-02-07 16:08:37 +11:00
Damien George
046ae80bdf unix, windows: Use mp_keyboard_interrupt instead of custom code.
The mp_keyboard_interrupt() function does exactly what is needed here, and
using it gets ctrl-C working when MICROPY_ENABLE_SCHEDULER is enabled on
these ports (and MICROPY_ASYNC_KBD_INTR is disabled).
2020-02-07 16:08:33 +11:00
Damien George
abe2caf6df py/scheduler: Move clearing of kbd traceback to mp_keyboard_interrupt.
This is a more logical place to clear the KeyboardInterrupt traceback,
right before it is set as a pending exception.  The clearing is also
optimised from a function call to a simple store of NULL.
2020-02-07 16:08:31 +11:00
Damien George
f4641b2378 esp32/uart: Use core-provided mp_keyboard_interrupt, placed in IRAM. 2020-02-07 16:08:31 +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
eaf30c516a tests/unix: Add coverage tests for kbd-intr and scheduler. 2020-02-07 16:08:29 +11:00
Damien George
9efb36bfa6 py/scheduler: Move mp_keyboard_interrupt from lib/utils to py core.
This function is tightly coupled to the state and behaviour of the
scheduler, and is a core part of the runtime: to schedule a pending
exception.  So move it there.
2020-02-07 16:08:26 +11:00
Damien George
5a91cd9ff3 lib/utils/pyexec: Handle pending exceptions after disabling kbd intrs.
Pending exceptions would otherwise be handled later on where there may not
be an NLR handler in place.

A similar fix is also made to the unix port's REPL handler.

Fixes issues #4921 and #5488.
2020-02-07 16:08:26 +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
Maureen Helm
7a5752a748 zephyr: Enable littlefs.
Enables the littlefs (v1 and v2) filesystems in the zephyr port.

Example usage with the internal flash on the reel_board or the
rv32m1_vega_ri5cy board:

import os
from zephyr import FlashArea
bdev = FlashArea(FlashArea.STORAGE, 4096)
os.VfsLfs2.mkfs(bdev)
os.mount(bdev, '/flash')
with open('/flash/hello.txt','w') as f:
    f.write('Hello world')
print(open('/flash/hello.txt').read())

Things get a little trickier with the frdm_k64f due to the micropython
application spilling into the default flash storage partition defined
for this board. The zephyr build system doesn't enforce the flash
partitioning when mcuboot is not enabled (which it is not for
micropython). For now we can demonstrate that the littlefs filesystem
works on frdm_k64f by constructing the FlashArea block device on the
mcuboot scratch partition instead of the storage partition. Do this by
replacing the FlashArea.STORAGE constant above with the value 4.
2020-02-07 11:24:06 +11:00
Maureen Helm
86a66960f9 zephyr: Implement block device protocol via zephyr flash map api.
Introduces a new zephyr.FlashArea class that uses the zephyr flash map
api to implement the uos.AbstractBlockDev protocol. The flash driver is
enabled on the frdm_k64f board, reel_board, and rv32m1_vega_ri5cy board.

The standard and extended block device protocols are both supported,
therefore this class can be used with file systems like littlefs which
require the extended interface.
2020-02-07 11:24:06 +11:00
Maureen Helm
2d7ec8e704 zephyr: Enable fatfs.
Enables the fatfs filesystem in the zephyr port.

Example usage with an SD card on the mimxrt1050_evk board:

import zephyr, os
bdev = zephyr.DiskAccess('SDHC')
os.VfsFat.mkfs(bdev)
os.mount(bdev, '/sd')
with open('/sd/hello.txt','w') as f:
    f.write('Hello world')
print(open('/sd/hello.txt').read())
2020-02-07 11:24:06 +11:00
Maureen Helm
a0440b01ea zephyr: Enable virtual file system and uos module.
Enables the virtual file system and uos module in the zephyr port.
No concrete file system implementations are enabled yet.
2020-02-07 11:24:06 +11:00
Maureen Helm
cc19cf2549 zephyr: Implement block device protocol via zephyr disk access api.
Introduces a new zephyr.DiskAccess class that uses the zephyr disk
access api to implement the uos.AbstractBlockDev protocol. This can be
used with any type of zephyr disk access driver, which currently
includes SDHC, RAM, and FLASH implementations. The SDHC driver is
enabled on the mimxrt1050_evk board.

Only the standard block device protocol (without the offset parameter)
can be supported with the zephyr disk access api, therefore this class
cannot be used with file systems like littlefs which require the
extended interface. In the future it may be possible to implement the
extended interface in a new class using the zephyr flash api.
2020-02-07 11:24:06 +11:00
Damien George
d6a1e45caa stm32/usbd_conf: Allow boards to configure USB HS ULPI NXT/DIR pins. 2020-02-04 23:15:55 +11:00
Andrew Leech
ff9a61b5a8 stm32/sdram: Expose the result of sdram startup test in stm32_main.
This means boards can choose to only use it for gc heap if the test passes.
2020-02-04 18:18:41 +11:00
Jim Mussared
0645478475 esp32/Makefile: Reorder includes to build with latest toolchain.
Tested on:
- IDF3.3.1 (old toolchain)
- IDF4.0-beta1 (old toolchain)
- IDF4.0-beta1 (new toolchain from install.sh / export.sh)
2020-02-04 18:06:14 +11:00
David Lechner
f1b6e6bb15 unix/modos: Implement putenv and unsetenv to complement getenv.
CPython also has os.environ, which should be used instead of os.getenv()
due to caching in the os.environ mapping.  But for MicroPython it makes
sense to only implement the basic underlying methods, ie getenv/putenv/
unsetenv.
2020-02-04 17:54:31 +11:00
David Lechner
83439e38fc unix/main: Add command-line -h option for printing help text.
This adds a -h option to print the usage help text and adds a new, shorter
error message that is printed when invalid arguments are given.  This
behaviour follows CPython (and other tools) more closely.
2020-02-04 17:54:31 +11:00
David Lechner
5a63bc5a44 unix/main: Add #if guard around -v option usage and document -i/-m opts.
This commit modifies the usage() function to only print the -v option help
text when MICROPY_DEBUG_PRINTERS is enabled.  The -v option requires this
build option to be enabled for it to have any effect.

The usage text is also modified to show the -i and -m options, and also
show that running a command, module or file are mutually exclusive.
2020-02-04 17:53:35 +11:00
David Lechner
122baa6787 unix/main: Add support for MICROPYINSPECT environment variable.
This adds support for a MICROPYINSPECT environment variable that works
exactly like PYTHONINSPECT; per CPython docs:

    If this is set to a non-empty string it is equivalent to specifying the
    -i option.

    This variable can also be modified by Python code using os.environ to
    force inspect mode on program termination.
2020-02-04 17:52:58 +11:00
Maureen Helm
bc3ce86a5a zephyr: Remove reference to syscall_macros_h_target.
Zephyr removed the build target syscall_macros_h_target in commit
f4adf107f31674eb20881531900ff092cc40c07f.  Removes reference from
MicroPython to fix build errors in the zephyr port.

This change is not compatible with zephyr v2.1 or earlier.  It will be
compatible with Zephyr v2.2 when released.
2020-02-04 17:10:24 +11:00
Maureen Helm
a7663b862e zephyr: Replace deprecated time conversion macro.
The SYS_CLOCK_HW_CYCLES_TO_NS macro was deprecated in zephyr commit
8892406c1de21bd5de5877f39099e3663a5f3af1.  This commit updates MicroPython
to use the new k_cyc_to_ns_floor64 api and fix build warnings in the zephyr
port.

This change is compatible with Zephyr v2.1 and later.
2020-02-04 17:09:59 +11:00
Maureen Helm
c25e12d0dd zephyr: Update include paths for Zephyr v2.0.
Zephyr restructured its includes in v2.0 and removed compatibility shims
after two releases in commit 1342dadc365ee22199e51779185899ddf7478686.
Updates include paths in MicroPython accordingly to fix build errors in
the zephyr port.

These changes are compatible with Zephyr v2.0 and later.
2020-02-04 17:09:19 +11:00
David Lechner
4ab8bee82f unix/main: Print usage and NLR errors to stderr instead of stdout.
When stdout is redirected it is useful to have errors printed to stderr
instead of being redirected.

mp_stderr_print() can't be used in these two instances since the
MicroPython runtime is not running so we use fprintf(stderr) instead.
2020-02-01 22:44:08 +11:00
caochaowu
61f64c78a6 nrf/boards/common.ld: Add ENTRY(Reset_Handler) in linker script.
It's not strictly needed but can be helpful when using a debugger.
2020-02-01 00:09:44 +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
Damien George
af88e70414 stm32/powerctrl: Reenable PLL3 on H7 MCUs when waking from stop mode.
So that USB can work.
2020-01-31 23:25:18 +11:00
Damien George
2c8c2b935e stm32/powerctrl: Improve support for changing system freq on H7 MCUs.
This commit improves pllvalues.py to generate PLL values for H7 MCUs that
are valid (VCO in and out are in range) and extend for the entire range of
SYSCLK values up to 400MHz (up to 480MHz is currently unsupported).
2020-01-31 23:25:18 +11:00
Damien George
03b73ce329 stm32/stm32_it: Don't call __HAL_USB_HS_EXTI_CLEAR_FLAG on H7 MCUs.
It doesn't exist on these MCUs.
2020-01-31 23:25:18 +11:00
Damien George
257b17ec10 stm32/sdio: Add support for H7 MCUs.
The cyw43 driver on stm32 will now work with H7 MCUs.
2020-01-31 23:25:18 +11:00
Damien George
31ba06ce84 stm32/boards/stm32f746_af.csv: Add ADC alt functions to correct pins. 2020-01-30 16:31:11 +11:00
Damien George
68db7e01d8 stm32/powerctrl: Enable overdrive on F7 when waking from stop mode.
Because if the SYSCLK is set to 180MHz or higher it will require this to be
on already.
2020-01-30 16:30:03 +11:00
Damien George
29b84ea798 stm32/powerctrl: Disable HSI if not needed to save a bit of power. 2020-01-30 16:29:45 +11:00
Damien George
96a4435be1 stm32/boards/STM32F769DISC: Add config to use external SPI as filesys.
This board now has the following 3 build configurations:
- mboot + external QSPI in XIP mode + internal filesystem
- mboot + external QSPI with filesystem (the default)
- no mboot + external QSPI with filesystem
2020-01-30 14:40:38 +11:00
Damien George
7bb2bf965e stm32/Makefile: Allow a board's .mk file to add things to CFLAGS. 2020-01-30 14:39:46 +11:00
Andrew Leech
30501d3f54 drivers, stm32: Support SPI/QSPI flash chips over 16MB.
With a SPI flash that has more than 16MB, 32-bit addressing is required
rather than the standard 24-bit.  This commit adds support for 32-bit
addressing so that the SPI flash commands (read/write/erase) are selected
automatically depending on the size of the address being used at each
operation.
2020-01-30 13:18:38 +11:00
David Lechner
b72cb0ca1b py/mpthread.h: Use strong type for mp_thread_set_state() argument.
This modifies the signature of mp_thread_set_state() to use
mp_state_thread_t* instead of void*.  This matches the return type of
mp_thread_get_state(), which returns the same value.

`struct _mp_state_thread_t;` had to be moved before
`#include <mpthreadport.h>` since the stm32 port uses it in its
mpthreadport.h file.
2020-01-29 17:10:32 +11:00
Damien George
a542c6d7e0 stm32/powerctrl: For F7, allow PLLM!=HSE when setting PLLSAI to 48MHz.
PLLM is shared among all PLL blocks on F7 MCUs, and this calculation to
configure PLLSAI to have 48MHz on the P output previously assumed that PLLM
is equal to HSE (eg PLLM=25 for HSE=25MHz).  This commit relaxes this
assumption to allow other values of PLLM.
2020-01-29 16:49:13 +11:00
David Lechner
d89ed3e62b unix/unix_mphal: Add compile check for incompatible GIL+ASYNC_KBD_INTR.
It is not safe to enable MICROPY_ASYNC_KBD_INTR and MICROPY_PY_THREAD_GIL
at the same time.  This will trigger a compiler error to ensure that it
is not possible to make this mistake.
2020-01-26 23:31:27 +11:00
David Lechner
bc3499f010 windows/windows_mphal: Release GIL during system calls.
This releases the GIL during syscalls that could block.
2020-01-26 23:27:40 +11:00
David Lechner
fee7e5617f unix: Release GIL during all system calls.
Addition of GIL EXIT/ENTER pairs are:

- modos: release the GIL during system calls.  CPython does this as well.

- moduselect: release the GIL during the poll() syscall.  This call can be
  blocking, so it is important to allow other threads to run at this time.

- modusocket: release the GIL during system calls.  Many of these calls can
  be blocking, so it is important to allow other threads to run.

- unix_mphal: release the GIL during the read and write syscalls in
  mp_hal_stdin_rx_chr and mp_hal_stdout_tx_strn.  If we don't do this
  threads are blocked when the REPL or the builtin input function are used.

- file, main, mpconfigport.h: release GIL during syscalls in built-in
  functions that could block.
2020-01-26 23:21:29 +11:00
Damien George
96716b46e1 unix/Makefile: Reserve CFLAGS_EXTRA/LDFLAGS_EXTRA for external use.
When CFLAGS_EXTRA/LDFLAGS_EXTRA (or anything) is set on the command line of
a make invocation then it will completely override any setting or appending
of these variables in the makefile(s).  This means builds like the coverage
variant will have their mpconfigvariant.mk settings overridden.  Fix this
by using CFLAGS/LDFLAGS exclusively in the makefile(s), reserving the
CFLAGS_EXTRA/LDFLAGS_EXTRA variables for external command-line use only.
2020-01-24 11:51:21 +11:00
Yonatan Goldschmidt
35e664d779 tests/unix: Add coverage tests for mp_obj_is_type() and variants. 2020-01-24 10:57:17 +11:00
Damien George
27f41e624c tests/unix: Add coverage test for mp_obj_new_exception_args.
Because it's no longer called anywhere in the code.
2020-01-23 13:37:25 +11:00
Damien George
dccace6f3f tests/unix: Add coverage tests for pairheap data structure. 2020-01-22 17:31:18 +11:00
Damien George
f70373c7b2 stm32/softtimer: Change linear linked list to a pairing heap. 2020-01-22 17:31:18 +11:00
stijn
599371b133 windows: Support word-based move/delete key sequences for REPL.
Translate common Ctrl-Left/Right/Delete/Backspace to the EMACS-style
sequences (i.e. Alt key based) for forward-word, backward-word, forwad-kill
and backward-kill.  Requires MICROPY_REPL_EMACS_WORDS_MOVE to be defined so
the readline implementation interprets these.
2020-01-22 16:54:19 +11:00
adzierzanowski
a55c17dc69 esp32/modnetwork: Add max_clients kw-arg to WLAN.config for AP setting.
This allows the user to configure the maximum number of clients that are
connected to the access point.  Resolves #5125.
2020-01-22 16:43:25 +11:00
Jim Mussared
3032ae1155 esp32: Enable NimBLE support on all builds (IDF 3.3 and 4.0).
This commit updates the IDFv3 version to v3.3.1, and enables the
"ubluetooth" module by default on IDFv3 builds.
2020-01-15 00:24:43 +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
Memiks
4ab4bf3ec6 ports: Modify mp_hal_pin_write macro so it can be used as a function.
Even though it doesn't return anything it could still be used like a
function.  Addresses issue #5501.
2020-01-14 23:48:42 +11:00
Damien George
3448e69c2d tests/unix: Add coverage test for new mp_obj_int_get_uint_checked func. 2020-01-14 23:45:56 +11:00
Thorsten von Eicken
6632dd3981 esp32/modmachine: Add implementation of machine.soft_reset(). 2020-01-12 13:38:45 +11:00
Yonatan Goldschmidt
853aaa06f2 lib/mp-readline: Add word-based move/delete EMACS key sequences.
This commit adds backward-word, backward-kill-word, forward-word,
forward-kill-word sequences for the REPL, with bindings to Alt+F, Alt+B,
Alt+D and Alt+Backspace respectively.  It is disabled by default and can be
enabled via MICROPY_REPL_EMACS_WORDS_MOVE.

Further enabling MICROPY_REPL_EMACS_EXTRA_WORDS_MOVE adds extra bindings
for these new sequences: Ctrl+Right, Ctrl+Left and Ctrl+W.

The features are enabled on unix micropython-coverage and micropython-dev.
2020-01-12 13:09:27 +11:00
Jim Mussared
977b532c8f unix: Rename unix binaries to micropython-variant (not _variant).
For consistency with mpy-cross, and other unix tools in general.
2020-01-12 10:37:40 +11:00
Jim Mussared
2357338e93 unix: Add placeholder DEV variant with settrace enabled.
This will eventually become the "full featured" unix binary with more
features enabled, specifically useful for development and testing.
2020-01-12 10:37:23 +11:00
Jim Mussared
bd2fff6687 unix: Add build variants, analogous to boards on bare-metal.
Invoking "make" will still build the standard "micropython" executable, but
other variants are now build using, eg, "make VARIANT=minimal".  This
follows how bare-metal ports specify a particular board, and allows running
any make target (eg clean, test) with any variant.

Convenience targets (eg "make coverage") are provided to retain the old
behaviour, at least for now.

See issue #3043.
2020-01-12 10:34:23 +11:00
Damien George
bfbd94401d py: Make mp_obj_get_type() return a const ptr to mp_obj_type_t.
Most types are in rodata/ROM, and mp_obj_base_t.type is a constant pointer,
so enforce this const-ness throughout the code base.  If a type ever needs
to be modified (eg a user type) then a simple cast can be used.
2020-01-09 11:25:26 +11:00
Damien George
e3187b052f stm32/boards/PYBD: Change RTC asynch prediv from 1 to 4.
This change has the following effects:
- Reduces the resolution of the RTC sub-second counter from 30.52us to
  122.07us.
- Allows RTC.calibration() to now support positive values (as well as
  negative values).
- Reduces VBAT current consumption in standby mode by a small amount.

For general purpose use 122us resolution of the sub-second counter is
good enough, and the benefits of full range calibration and minor reduction
in VBAT consumption are worth the change.
2020-01-07 23:59:29 +11:00
Damien George
99b8c1a937 esp32/Makefile: Assign result of $call to dummy var for older make.
Make version 4.1 and lower does not allow $call as the main expression on a
line, so assign the result of the $call to a dummy variable.

Fixes issue #5426.
2020-01-06 23:03:22 +11:00
Nicko van Someren
4c93955b7b py/objslice: Add support for indices() method on slice objects.
Instances of the slice class are passed to __getitem__() on objects when
the user indexes them with a slice.  In practice the majority of the time
(other than passing it on untouched) is to work out what the slice means in
the context of an array dimension of a particular length.  Since Python 2.3
there has been a method on the slice class, indices(), that takes a
dimension length and returns the real start, stop and step, accounting for
missing or negative values in the slice spec.  This commit implements such
a indices() method on the slice class.

It is configurable at compile-time via MICROPY_PY_BUILTINS_SLICE_INDICES,
disabled by default, enabled on unix, stm32 and esp32 ports.

This commit also adds new tests for slice indices and for slicing unicode
strings.
2019-12-28 23:55:15 +11:00
Tim Gates
007a704d82 nrf/examples: Fix typo in mountsd.py, wireing -> wiring. 2019-12-28 12:07:30 +11:00
Damien George
269c9a08b6 unix/modos: Add uos.rename and uos.rmdir.
The existing uos.remove cannot be used to remove directories, instead
uos.rmdir is needed.  And also provide uos.rename to get a good set of
filesystem functionality without requiring additional Python-level os
functions (eg using ffi).
2019-12-28 11:54:49 +11:00
Andrew Leech
1b844e908c unix/modtime: Add utime.mktime function, to complement utime.localtime.
This also adds it to the windows port.
2019-12-28 11:11:54 +11:00
Yonatan Goldschmidt
b2e4a57289 nrf/main: Remove unnecessary repl_info(0) call.
It's statically initialized to 0.
2019-12-28 00:08:31 +11:00
Yonatan Goldschmidt
61d2b40ad5 lib/utils/pyexec: Introduce MICROPY_REPL_INFO, wrap debug prints in it.
For the 3 ports that already make use of this feature (stm32, nrf and
teensy) this doesn't make any difference, it just allows to disable it from
now on.

For other ports that use pyexec, this decreases code size because the debug
printing code is dead (it can't be enabled) but the compiler can't deduce
that, so code is still emitted.
2019-12-28 00:05:39 +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
Damien George
93509ac8c7 stm32: Add configuration to build in nanbox mode.
Most stm32 boards can now be built in nan-boxing mode via:

    $ make NANBOX=1

Note that if float is enabled then it will be forced to double-precision.
Also, native emitters will be disabled.
2019-12-27 22:54:53 +11:00
Damien George
d980d51807 stm32: Fix to build in nanbox mode. 2019-12-27 22:54:53 +11:00
Damien George
d97b40bdaa py: Introduce MP_ROM_FALSE/MP_ROM_TRUE for ROM to refer to bool objects.
This helps to prevent mistakes, and allows easily changing the ROM value of
False/True if needed.
2019-12-27 22:54:20 +11:00
Damien George
09376f0e47 py: Introduce MP_ROM_NONE macro for ROM to refer to None object.
This helps to prevent mistakes, and allows easily changing the ROM value of
None if needed.
2019-12-27 22:51:17 +11:00
Jim Mussared
90f286465b stm32/mbedtls: Resize mbedtls output buffer from 16 down to 4 kiB.
To reduce the size of the SSL context on the heap.  See issue #5303.
2019-12-21 00:02:24 +11:00
Damien George
7ac326c424 stm32/boards/PYBD: Include webrepl helper scripts in frozen manifest. 2019-12-20 13:20:20 +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
Matt Trentini
0e0e6132fd esp32/esp32_rmt: Add initial support for RMT peripheral.
This is an ESP32-specific peripheral so lives in the esp32 module.
2019-12-20 12:24:51 +11:00
David Lechner
882533ad92 qemu-arm/Makefile: Allow overriding CROSS_COMPILE from another makefile. 2019-12-19 17:59:32 +11:00
iabdalkader
3078a4b2e2 stm32/timer: Add missing TIM 1/15/16/17 IRQ handlers for H7 MCUs. 2019-12-19 17:19:53 +11:00
roland van straten
43b576d88d stm32/boards/NUCLEO_H743ZI: Add extra pins and peripheral definitions.
- Corrected pin assignments and checked with CubeMX.
- Added additional I2C and UARTs.
- Added Ethernet interface definitions with lwIP and SSL support (but
  Ethernet is currently unsupported on H7 MCUs so not fully enabled).
2019-12-19 16:54:33 +11:00
roland van straten
26a78edb49 stm32/boards/NUCLEO_F767ZI: Update pins, peripherals and total flash.
- Removed remarks on DFU/OCD in mpconfigboard.h because deploy-stlink works
  fine too.
- Added more UARTs, I2C, corrected SPI, CAN, etc; verified against CubeMX.
- Adapted pins.csv to remove errors, add omissions, etc. according to
  NUCLEO-144 User Manual.
- Changed linker file stm32f767.ld to reflect correct size of the Flash.
- Tested with LAN and SD card.
2019-12-19 11:43:19 +11:00
roland van straten
8af139e8a4 stm32/boards/NUCLEO_F767ZI: Add pins and config for using an SD card.
The Nucleo board does not have an SD card slot but does have the requisite
pins next to each other and labelled, so provide the configuration for
convenience.
2019-12-19 11:28:47 +11:00
Seon Rozenblum
0d82f5d8c8 esp32/boards/TINYPICO: Add tinypico.py, dotstar.py with custom manifest. 2019-12-19 10:05:01 +11:00
Damien George
1e2f751591 qemu-arm: Let tinytest.o be built by standard build rules.
This makes sure tinytest.o is rebuilt if any of its dependencies change.
2019-12-17 13:32:07 +11:00
Damien George
fb01415599 stm32/boards/PYBD_SF2: Configure LEDs as inverted, for LED.intensity(). 2019-12-13 17:28:24 +11:00
Damien George
71c6bfd08a stm32/modusocket: Handle case of NULL NIC in socket ioctl. 2019-12-13 14:45:21 +11:00
Damien George
c2eaf56634 stm32/Makefile: Enable max buffer size on W5200 NIC when used with lwIP.
Because in network_wiznet5k the TX/RX buffers are set to 16k each when in
MACRAW mode, which is used with lwIP.
2019-12-13 12:36:12 +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
Jim Mussared
b76f0a73bc stm32/main: Fix SKIPSD file detection so SD card is mounted by default.
The condition for skipping was accidentally inverted in
7723dac337

Fixes issue #5400.
2019-12-09 17:01:30 +11:00
Daniel Mizyrycki
2df6a0436d nrf/boards/particle_xenon: Enable USB CDC on Particle Xenon board. 2019-12-09 14:10:24 +11:00
Damiano Mazzella
cc634b9e92 stm32/boards/xxx_WB55: Enable littlefs2 on WB55 boards. 2019-12-09 14:07:29 +11:00
Andrej Krejcir
210d053286 nrf/main: Execute boot.py/main.py frozen modules without a file system.
When the file system is not enabled, the boot.py and main.py modules will
still be executed, if they are frozen.
2019-12-05 23:11:12 +11:00
Chris Mason
d61e7a6d8a stm32/uart: Add support for UART4/5 on L0 MCUs. 2019-12-05 15:31:41 +11:00
Andrew Leech
9ca8a503ed esp32/boards: Enable ULP in base sdk configuration.
Fixes issue #5159.
2019-12-05 15:28:56 +11:00
Damien George
40cc7ec677 stm32/mpconfigport.h: Use IRQ_PRI_PENDSV to protect bluetooth ringbuf.
The default protection for the BLE ringbuf is to use
MICROPY_BEGIN_ATOMIC_SECTION, which disables all interrupts. On stm32 it
only needs to disable the lowest priority IRQ, pendsv, because that's the
IRQ level at which the BLE stack is driven.
2019-12-04 13:39:22 +11:00
Damien George
ba5e4841ec stm32/main: Fix auto creation of pyb.Flash on boot with kw-only args. 2019-11-27 22:47:05 +11:00
Damien George
11c22430d4 stm32/boards/NUCLEO_L073RZ: Skip board-pin names for CPU only pins.
This board doesn't have much flash and removing these unneeded names saves
about 900 bytes of code size.
2019-11-27 21:59:47 +11:00
Damien George
77b8f86a5e stm32/qstrdefsport.h: Remove unused qstrs and make USB ones conditional.
qstrs in this file are always included in all builds, even if not used
anywhere.  So remove those that are never needed, and make USB names
conditional on having USB enabled.
2019-11-27 21:59:47 +11:00
Damien George
797c2e8fc2 stm32/storage: Make start/len args of pyb.Flash keyword only.
To allow the future possibility of initial positional args, like flash id.
2019-11-26 21:35:00 +11:00
Damien George
d8057c325a stm32/storage: Change storage_read/write_blocks to return int type.
And return -MP_EIO if calling storage_read_block/storage_write_block fails.
This lines up with the return type and value (negative for error) of the
calls to MICROPY_HW_BDEV_READBLOCKS (and WRITEBLOCKS, and BDEV2 versions).
2019-11-26 00:08:57 +11:00
Damien George
120368ba1a stm32/boards: Enable LFS2 on PYBv1.x and PYBD boards. 2019-11-26 00:08:57 +11:00
Damien George
715e4fc25f stm32/moduos: Add VfsLfs1 and VfsLfs2 to uos module, if enabled. 2019-11-26 00:07:09 +11:00
Damien George
7897f5d9be stm32/main: Auto detect block device used for main filesystem. 2019-11-26 00:07:09 +11:00
Damien George
c169094f61 stm32/storage: Make pyb.Flash configurable, and support ext block proto.
The pyb.Flash() class can now be used to construct objects which reference
sections of the flash storage, starting at a certain offset and going for a
certain length.  Such objects also support the extended block protocol.
The signature for the constructor is: pyb.Flash(start=-1, len=-1).
2019-11-26 00:07:09 +11:00
Damien George
7723dac337 stm32: Generalise flash mounting code so it supports arbitrary FS.
This commit refactors and generalises the boot-mount routine on stm32 so
that it can mount filesystems of arbitrary type.  That is, it no longer
assumes that the filesystem is FAT.  It does this by using mp_vfs_mount()
which does auto-detection of the filesystem type.
2019-11-25 18:10:58 +11:00
Jim Mussared
fbb7646e3b stm32/nimble_hci_uart.c: Prevent scheduler running during CYW-BT wakeup.
Using mp_hal_delay_ms allows the scheduler to run, which might result in
another transmit operation happening, which would bypass the sleep (and
fail).  Use mp_hal_delay_us instead.
2019-11-25 17:32:10 +11:00
Josh Lloyd
1530fda9cf esp32/machine_rtc: Reduce memory footprint of user mem functionality. 2019-11-21 16:55:12 +11:00
Josh Lloyd
ed2314f35a esp32/machine_rtc: Make RTC.memory size and availability configurable.
The compile-time configuration value MICROPY_HW_RTC_USER_MEM_MAX can now be
used to define the amount of memory set aside for RTC.memory().  If this
value is configured to zero then the RTC.memory functionality is not
included in the build.
2019-11-21 16:55:12 +11:00
Laurens Valk
2679c9e116 unix/modtermios: Fix output speed setter in tcsetattr.
The input speed was being set twice and the output speed was not set.
2019-11-21 12:10:32 +11:00
Yonatan Goldschmidt
973f68780d qemu-arm: Add ldscript dependency in the final firmware.elf target.
So that the target is rebuilt if the linker script changes.
2019-11-15 10:25:48 +11:00
Josh Lloyd
82d358510b esp32/rtc: Set system microseconds when setting time via RTC.datetime(). 2019-11-13 13:46:33 +11:00
Mike Causer
258b147830 stm32/boards/stm32f405_af.csv: Fix typo in ETH_RMII_REF_CLK on PA1. 2019-11-11 12:02:14 +11:00
Jim Mussared
71299d3224 esp32/boards/sdkconfig.base: Resize SSL output buffer from 16 to 4kiB.
The IDF heap is more fragmented with IDF 4 and mbedtls cannot allocate
enough RAM with 16+16kiB for both in and out buffers, so reduce output
buffer size.

Fixes issue #5303.
2019-11-11 11:55:58 +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
4be316fb07 esp32/moduos: Enable uos.VfsLfs2 for littlefs filesystems.
This commit adds support for littlefs (v2) on all esp32 boards.

The original FAT filesystem still works and any board with a preexisting
FAT filesystem will still work as normal.  It's possible to switch to
littlefs by reformatting the block device using:

    import uos, flashbdev
    uos.VfsLfs2.mkfs(flashbdev.bdev)

Then when the board reboots (soft or hard) the new littlefs filesystem will
be mounted.  It's possible to switch back to a FAT filesystem by formatting
with uos.VfsFat.mkfs(flashbdev.bdev).
2019-11-06 12:16:00 +11:00
Damien George
d01ca7888b esp32/esp32_partition: Support extended block protocol. 2019-11-06 12:15:34 +11:00
Andreas Motl
d209f9ebe7 esp32: Remove unused "esponewire.c" in favour of extmod/modonewire. 2019-11-05 14:57:05 +11:00
Damien George
cddb2dd0c3 stm32/mpthreadport: Include runtime.h to get defn of mp_raise_msg. 2019-11-05 13:20:25 +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
742030945c esp32/Makefile: Add correct arch to MPY_CROSS_FLAGS for native code. 2019-11-04 15:32:20 +11:00
Damien George
32eae53fbc stm32/boards: Enable support for bluetooth on WB55 boards. 2019-11-01 14:58:24 +11:00
Damien George
6a64b280d0 stm32: Add support for RF coprocessor on WB55 MCUs.
This requires a BLE wireless stack firmware to be already programmed in the
secure flash area of the device.
2019-11-01 14:52:17 +11:00
Damien George
40ea1915fc extmod/nimble: Factor out stm32-specific HCI UART RX/TX code. 2019-11-01 12:41:37 +11:00
Damien George
48b25a841b stm32: Add machine.Timer with soft timer implementation.
This commit adds an implementation of machine.Timer backed by the soft
timer mechanism.  It allows an arbitrary number of timers with 1ms
resolution, with an associated Python callback.  The Python-level API
matches existing ports that have a soft timer, and is used as:

    from machine import Timer
    t = Timer(freq=10, callback=lambda t:print(t))
    ...
    t = Timer(mode=Timer.ONE_SHOT, period=2000, callback=lambda t:print(t))
    ...
    t.deinit()
2019-10-31 22:12:55 +11:00
Damien George
a5d97f1db9 stm32: Add soft timer implementation, using SysTick at 1ms resolution.
This commit adds an implementation of a "software timer" with a 1ms
resolution, using SysTick.  It allows unlimited number of concurrent
timers (limited only by memory needed for each timer entry).  They can be
one-shot or periodic, and associated with a Python callback.

There is a very small overhead added to the SysTick IRQ, which could be
further optimised in the future, eg by patching SysTick_Handler code
dynamically.
2019-10-31 22:12:55 +11:00
Damien George
9ec73aedb4 stm32/timer: Fix Timer.freq() calc so mult doesn't overflow uint32_t.
Fixes issue #5280.
2019-10-31 12:49:18 +11:00
Damien George
660a61a388 extmod/vfs_lfs: Allow compiling in VfsLfs1 and VfsLfs2 separately.
These classes are enabled via the config options MICROPY_VFS_LFS1 and
MICROPY_VFS_LFS2, which are disabled by default.
2019-10-30 12:08:58 +11:00
Kamil Klimek
53f3cbc2c4 zephyr/main: Use mp_stack API instead of local pointer for stack top.
The MP_STATE_THREAD(stack_top) is always available so use it instead of
creating a separate variable.  This also allows gc_collect() to be used as
an independent function, without real_main() being called.
2019-10-29 23:05:07 +11:00
Damien George
4847460232 unix/mphalport.h: Define mp_hal_stdio_poll to dummy because it's unused.
And requires uintptr_t to declare the default version in py/mphal.h.
2019-10-29 22:22:37 +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
62d5659cdd unix: Enable uos.VfsLfs1, uos.VfsLfs2 on coverage build. 2019-10-29 14:17:29 +11:00
Damien George
9aabb6c01b extmod: Factor out block-device struct to make independent of fatfs. 2019-10-29 12:12:37 +11:00
Jim Mussared
ece4e21a55 stm32/Makefile: Only enable hardware sqrt on parts that support it.
Not enough to detect f7/h7, need to use the specific parts.

Follow-up to 580a2656d1.
2019-10-28 15:08:28 +11:00
Mike Teachman
f301170c7c esp32/machine_hw_spi: Fix exception msg when host is already in use.
When a SPI bus is initialized with a SPI host that is currently in use the
exception msg incorrectly indicates "SPI device already in use".  The
mention of "device" in the exception msg is confusing because the error is
about trying to use a SPI host that is already claimed.  A better exception
msg is "SPI host already in use".
2019-10-23 13:31:13 +11:00
Michael Neuling
079cc940a6 powerpc: Add initial port to bare metal PowerPC arch.
Runs in microwatt (GHDL and FPGA) and qemu.

Port done initially by Michael Neuling, with help from Anton Blanchard and
Jordan Niethe.
2019-10-22 22:45:33 +11:00
Andrew Leech
19ca025b45 stm32/sdram: Fix to use new mpu_config_start/mpu_config_end signature. 2019-10-22 22:02:06 +11:00
Jim Mussared
b02d7e612d extmod/modbluetooth: Rename module to "ubluetooth".
For consistency with "umachine". Now that weak links are enabled
by default for built-in modules, this should be a no-op, but allows
extension of the bluetooth module by user code.

Also move registration of ubluetooth to objmodule rather than
port-specific.
2019-10-22 21:58:05 +11:00
Damien George
1582c7eeb0 unix,windows: Enable module weak links. 2019-10-22 16:23:43 +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
912892b209 esp32: Add missing and necessary newline at EOF for sdkconfig.240mhz.
When these files get concatenated the newline-at-EOF is necessary so that
the start of the next file doesn't join with the end of the previous.
2019-10-21 23:54:59 +11:00
Jim Mussared
93bd61ca91 unix: Allow building without a manifest. 2019-10-21 23:21:18 +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
12413e92a3 stm32/powerctrlboot: Fix config of systick IRQ priority on F0/L0/WB MCU.
Prior to this commit the systick IRQ priority was set at lowest priority on
F0/L0/WB MCUs, because it was left at the default and never configured.
This commit ensures the priority is configured and sets it to the highest
priority.
2019-10-21 12:23:41 +11:00
Josh Lloyd
59c1b7d4b8 esp32/boards: Split out CPU frequency config, make 160MHz the default.
Remove the 240MHz CPU config option from sdkconfig.base and create a new
sdkconfig.240mhz file for those boards that want to use 240MHz on boot.

The default CPU frequency is now 160MHz (was 240MHz), to align with the ESP
IDF and support more boards (eg those with D2WD chips).

Fixes issue #5169.
2019-10-18 13:42:24 +11:00
Jeremy Herbert
7a7ee16ccf esp32/machine_uart: Add ability to invert UART pins. 2019-10-18 12:05:16 +11:00
Damien George
69b238ec63 stm32/accel: Fix Accel.read() method so it does read a byte.
This bug was introduced in a0f7b4c678
2019-10-18 11:53:34 +11:00
Frederic.Pierson
925f244ab3 stm32/boards: Add NADHAT_PYB405 board. 2019-10-18 11:41:22 +11:00
Frederic.Pierson
28062b5108 stm32/accel: Add support for KXTJ3. 2019-10-18 11:41:22 +11:00
Damien George
3105207aff stm32/accel: Rename MMA I2C macro constants to make it generic. 2019-10-18 11:35:32 +11:00
Damien George
4f2c737b0c stm32/mpu: Save and restore the IRQ state when configuring MPU.
In case IRQs are already disabled during the MPU configuration.

Fixes issue #5152.
2019-10-16 23:12:06 +11:00
iabdalkader
6e4468a2ab stm32/adc: Fix sampling for internal channels on H7 MCUs.
Set to 810 cycles following HAL examples.
2019-10-15 22:08:45 +11:00
iabdalkader
4cee42d864 stm32/adc: Use IS_CHANNEL_INTERNAL macro to check for internal channels. 2019-10-15 22:08:36 +11:00
iabdalkader
d523a377d1 stm32/adc: Remove unused macro and channel check, and fix spacing.
The call to is_adcx_channel is redundant because the channel is already
checked just before calling adc_init_single in adc_make_new.
2019-10-15 22:04:19 +11:00
iabdalkader
cb2b210d45 stm32/adc: Update ADC driver to work with the new H7 HAL.
Use NB_TO_CHANNEL to map decimal numbers to channel numbers.  And use the
correct rank to initialize channels (ADC_REGULAR_RANK_1).
2019-10-15 22:03:54 +11:00
Damien George
ce1de1faf0 esp32: Convert to use FROZEN_MANIFEST to specify frozen code.
All symlinks are removed.  boards/manifest.py is used as a default, and can
optionally use boards/manifest_release.py for more scripts.
2019-10-15 21:37:02 +11:00
Damien George
2e90ff7fa8 qemu-arm: Convert to use FROZEN_MANIFEST to specify frozen code. 2019-10-15 21:36:55 +11:00
Damien George
287800d6e1 stm32: Convert to use FROZEN_MANIFEST to specify frozen code.
All symlinks are removed, frozen files are now referenced via
boards/manifest.py.
2019-10-15 21:36:24 +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
b1c0355b93 unix: 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:35:27 +11:00
Jim Mussared
4b2b05718a esp32: Run NimBLE on the app core.
This prevents issues with concurrent access to the ringbuf.
MICROPY_BEGIN_ATOMIC_SECTION is only atomic to the same core.  We could
address this with a mutex, but it's also not safe to call mp_sched_schedule
across cores.
2019-10-15 17:22:15 +11:00
Jim Mussared
418f12c5f5 extmod/modbluetooth: Increase maximum connections from 1 to 4.
This avoids a confusing ENOMEM raised from gap_advertise if there is
currently an active connection.  This refers to the static connection
buffer pre-allocated by Nimble (nothing to do with MicroPython heap
memory).
2019-10-15 17:20:25 +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
3ee71ff314 minimal/frozentest.mpy: Recompile now that mpy format changed. 2019-10-15 16:58:58 +11:00
Jim Mussared
d5cbee3cfb esp32: Add 4.x version of IDLE WDT config. 2019-10-11 14:30:47 +11:00
ladyada
06ae818f93 stm32/boards: Add new board ADAFRUIT_F405_EXPRESS. 2019-10-11 11:50:36 +11:00
Glenn Ruben Bakke
98c2eabaff nrf/boards: Add nrf9160 pca10090 board. 2019-10-10 21:36:20 +02:00
Glenn Ruben Bakke
82fe6b0526 nrf: Add nrf9160 base support.
This patch add basic building blocks for nrf9P60.

It also includes a secure bootloader which forwards all
possible peripherals that are user selectable to become
non-secure. After configuring Flash, RAM and peripherals
the secure bootloader will jump to the non-secure domain
where MicroPython is placed.

The minimum size of a secure boot has to be a flash
block of 32Kb, hence why the linker scripts are
offsetting the main application this much.

The RAM offset is set to 128K, to allow for later
integration of Nordic Semiconductor's BSD socket
library which reserves the range 0x20010000 - 0x2001FFFF.
2019-10-10 21:35:27 +02:00
Glenn Ruben Bakke
01a3110e36 nrf/boards: Add support for pca10059.
Add support for pca10059 with REPL over tinyusb USB CDC.

The board also includes a board specific module that will
recover UICR->REGOUT0 in case this has been erased.

This initial support does not preserve any existing bootloader
on the pca10090 in case this was present, and expects to use all
available flash on the device.
2019-10-10 20:21:07 +02:00
Glenn Ruben Bakke
60b0b69f20 nrf: Add tinyusb support for nrf52840.
Add nrf-port finyusb driver files. USB CDC can be activated
by board configuration files using the MICROPY_HW_USB_CDC.

Updating BLE driver, Makefile, nrfx-glue and main.c to plug
in the tinyusb stack.
2019-10-10 20:21:07 +02:00
Glenn Ruben Bakke
1571120dc2 nrf/device: Correct SPIM3 IRQ handler entry for nrf52840. 2019-10-10 20:21:07 +02: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
Jim Mussared
580a2656d1 stm32: Use hardware double sqrt on F7/H7 MCUs.
Identical to cd527bb324 but for doubles.
This gives a -2.754% improvement on bm_float.py, and -35% improvement on
calling sqrt in a loop.
2019-10-10 17:39:32 +11:00
Andrey Belykh
305f537bf9 stm32/sdcard: Support boards with no SD card detect pin.
If MICROPY_HW_SDCARD_DETECT_PIN is not defined then the SD card will always
be detected as present.
2019-10-10 17:29:44 +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
2863dcdf4f nrf: Add support to activate MICROPY_PY_SYS_STDFILES.
Fixes issue #5162.
2019-10-08 16:38:04 +11:00
Andrew Leech
04fe62d06f stm32/mboot: Add option to automatically reset when USB is disconnected.
Enable in board config with: #define MBOOT_USB_RESET_ON_DISCONNECT (1)
2019-10-08 16:07:32 +11:00
Jim Mussared
cd8bbf4cfc esp32/boards: Enable BLE by default when building with IDF 4.x. 2019-10-08 14:50:01 +11:00
Jim Mussared
6a9bd1c1ab esp32: Implement BLE using Nimble from IDF 4.x. 2019-10-08 14:50:01 +11:00
Jim Mussared
902bb4ceae stm32: Extract port-specific Nimble implementation.
On other ports (e.g. ESP32) they provide a complete Nimble implementation
(i.e. we don't need to use the code in extmod/nimble). This change
extracts out the bits that we don't need to use in other ports:
 - malloc/free/realloc for Nimble memory.
 - pendsv poll handler
 - depowering the cywbt

Also cleans up the root pointer management.
2019-10-08 14:40:35 +11:00
Damien George
4a6974bea5 stm32/boards/PYBD_SF2: Put nimble library in external QSPI XIP flash.
The BLE stack is not performance critical, so put it in external
memory-mapped flash to save internal flash for other things (like frozen
bytecode).
2019-10-05 23:51:33 +10:00
Martin Fischer
a0ce01f62e stm32/usbdev: Fix compile error if MICROPY_HW_USB_CDC_NUM is set to 2.
Fixes regression introduced by 6705767da1
2019-10-05 23:33:38 +10:00
Damien George
917f027c0b esp32: Enable native emitter. 2019-10-05 13:45:25 +10:00
Chris Mason
0096041c99 stm32/{adc,machine_adc}: Change ADC clock and sampling time for F0 MCUs.
STM32F0 has PCLK=48MHz and maximum ADC clock is 14MHz so use PCLK/4=12MHz
to stay within spec of the ADC peripheral.  In pyb.ADC set common sampling
time to approx 4uS for internal and external sources.  In machine.ADC
reduce sample time to approx 1uS for external source, leave internal at
maximum sampling time.
2019-10-04 21:39:17 +10:00
Damien George
26e90a0514 stm32/boards: Enable MICROPY_HW_RTC_USE_LSE on L4 boards.
The previous commit changed the default configuration on L4 MCUs to use
LSI, so configure these boards to use LSE again.
2019-10-04 16:10:13 +10:00
hahmadi
266146ad64 stm32/system_stm32: Support selection of HSE and LSI on L4 MCUs.
This commit adds the option to use HSE or MSI system clock, and LSE or LSI
RTC clock, on L4 MCUs.

Note that prior to this commit the default clocks on an L4 part were MSI
and LSE.  The defaults are now MSI and LSI.

In mpconfigboard.h select the clock source via:

    #define MICROPY_HW_RTC_USE_LSE (0) or (1)
    #define MICROPY_HW_CLK_USE_HSE (0) or (1)

and the PLLSAI1 N,P,Q,R settings:

    #define MICROPY_HW_CLK_PLLSAIN (12)
    #define MICROPY_HW_CLK_PLLSAIP (RCC_PLLP_DIV7)
    #define MICROPY_HW_CLK_PLLSAIQ (RCC_PLLQ_DIV2)
    #define MICROPY_HW_CLK_PLLSAIR (RCC_PLLR_DIV2)
2019-10-04 16:09:06 +10:00
roland van straten
a069340c1e nrf/main: Update the way the LED is used on startup.
In case of LED1 being present, do a short blink during startup
instead of turning it on and leave it on.
2019-10-02 22:17:54 +02:00
roland van straten
226399bcef nrf/led: Expose public API for LED manipulation.
Aligned implementation with the STM32 port.
Added empty functions to be used when no LED is available.
2019-10-02 22:09:43 +02:00
Glenn Ruben Bakke
cf383412ef nrf/flash: Update flash driver to use nrfx_nvmc driver.
The the nrfx driver is aware of chip specific registers, while
the raw HAL abstraction is not. This driver enables use of NVMC
in non-secure domain for nrf9160.
2019-10-02 21:28:34 +02:00
Glenn Ruben Bakke
c561ae61a1 nrf/uart: Add support for UARTE (EasyDMA). 2019-10-02 21:20:56 +02:00
Glenn Ruben Bakke
02a8c31eef nrf/temp: Move module configuration guard.
This patch moves the check for MICROPY_PY_MACHINE_TEMP to come
before the inclusion of nrf_temp.h. The nrf_temp.h depends on
the NRF_TEMP_Type which might not be defined for all nRF devices.
2019-10-02 21:15:48 +02:00
Glenn Ruben Bakke
d2e730b727 nrf/i2c: Add support for TWIM (EasyDMA). 2019-10-02 20:42:06 +02:00
Damien George
fd9b7efe39 minimal/frozentest.mpy: Update due to change in bytecode. 2019-10-01 12:26:22 +10:00
Damien George
4c5e1a0368 py/bc: Change mp_code_state_t.exc_sp to exc_sp_idx.
Change from a pointer to an index, to make space in mp_code_state_t.
2019-10-01 12:26:22 +10:00
Jim Mussared
fafa9d35dd stm32/boards/PYBD: Enable BLE for Pyboard D. 2019-10-01 09:51:02 +10:00
Jim Mussared
6f35f214d3 stm32/mpconfigport.h: Add modbluetooth module to stm32. 2019-10-01 09:51:02 +10:00
Jim Mussared
f67fd95f8d unix/coverage: Add coverage tests for ringbuf. 2019-10-01 09:51:02 +10:00
Jim Mussared
d72dbb822c stm32: Provide port-specific implementation for Nimble on STM32. 2019-10-01 09:51:02 +10:00
Andrew Leech
4ba0aff472 stm32/uart: Add RTS/CTS pin configuration support to UART4. 2019-09-27 13:24:01 +10:00
Chris Mason
eb12fa3862 stm32/powerctrlboot: Add support for HSI at 8MHz on F0 MCUs.
For use with F0 MCUs that don't have HSI48.  Select the clock source
explicitly in mpconfigboard.h.

On the NUCLEO_F091RC board use HSE bypass when HSE is chosen because the
NUCLEO clock source is STLINK not a crystal.
2019-09-26 17:34:04 +10:00
Chris Mason
f16e4be3fa stm32/powerctrlboot: Fix clock and PLL selection for HSI48 on F0 MCUs.
Before this patch the UART baudrate on F0 MCUs was wrong because the
stm32lib SystemCoreClockUpdate sets SystemCoreClock to 8MHz instead of
48MHz if HSI48 is routed directly to SYSCLK.

The workaround is to use HSI48 -> PREDIV (/2) -> PLL (*2) -> SYSCLK.

Fixes issue #5049.
2019-09-26 17:32:22 +10:00
Damien George
3328b7d71f stm32: Support disabling the compiler.
Disable via "#define MICROPY_ENABLE_COMPILER (0)" in the board's
mpconfigboard.h file.
2019-09-26 17:05:40 +10:00
Damien George
9abfe85ace minimal/frozentest: Recompile now that mpy version has changed. 2019-09-26 16:40:54 +10:00
Josh Lloyd
7d58a197cf py: Rename MP_QSTR_NULL to MP_QSTRnull to avoid intern collisions.
Fixes #5140.
2019-09-26 16:04:56 +10:00
Andrew Leech
2397b44062 stm32/usbd_cdc_interface: Add CTS flow control option for USB VCP.
Enabled by default, but disabled when REPL is connected to the VCP (this is
the existing behaviour).  Can be configured at run-time with, eg:

    pyb.USB_VCP().init(flow=pyb.USB_VCP.RTS | pyb.USB_VCP.CTS)
2019-09-26 13:50:24 +10:00
Damien George
6b4666f8cf stm32/can: Guard header file by MICROPY_HW_ENABLE_CAN.
Because not all MCU series have a CAN peripheral.
2019-09-23 23:45:07 +10:00
Damien George
ca8ff99e8c stm32: Use mp_printf with MICROPY_ERROR_PRINTER for uncaught exceptions. 2019-09-23 17:15:07 +10:00
iabdalkader
4f78ba3cf4 stm32/boards/NUCLEO_H743ZI: Enable FDCAN on this board. 2019-09-23 17:00:54 +10:00
iabdalkader
f7a07b3605 stm32: Add support for FDCAN peripheral, exposed as pyb.CAN.
The new fdcan.c file provides the low-level C interface to the FDCAN
peripheral, and pyb_can.c is updated to support both traditional CAN and
FDCAN, depending on the MCU being compiled for.
2019-09-23 17:00:54 +10:00
Damien George
d06fd384c2 stm32/can: Factor CAN driver into low-level and Python bindings.
can.c now contains the low-level C interface to the CAN peripheral, and
pyb_can.c the Python-level class/methods/constants.
2019-09-23 16:58:08 +10:00
Chris Liechti
6f7e774d12 stm32/machine_i2c: Add ability to specify I2C(4) by name. 2019-09-23 15:08:24 +10:00
Jim Mussared
c33a4cc213 esp32/Makefile: Fix printing of supported git hash. 2019-09-20 14:37:53 +10:00
stijn
d96391aca3 mpy-cross,windows: Add msvc build of mpy-cross.
Add the project file to the mpy-cross directory, which is also where the
executable ends up, and change the Appveyor settings to build mpy-cross
with both msvc and mingw-w64 and verify this all works by running tests
with --via-mpy.
2019-09-18 22:16:36 +10:00
stijn
bc86c6252a windows: Default to binary mode for files.
If this is not set it might default to calls to open() to use text mode
which is usually not wanted, and even wrong and leading to incorrect
results when loading binary .mpy files.

This also means that text files written and read will not have line-ending
translation from \n to \r\n and vice-versa anymore.  This shouldn't be much
of a problem though since most tools dealing with text files adapt
automatically to any of the 2 formats.
2019-09-18 22:15:48 +10:00
stijn
6957939604 windows/msvc: Change the way sources are listed.
Reserve sources.props for listing just the MicroPython core and extmod
files, similar to how py.mk lists port-independent source files.  This
allows reusing the source list, for instance for building mpy-cross.  The
sources for building the executable itself are listed in the corresponding
project file, similar to how the other ports specify the source files in
their Makefile.
2019-09-18 22:15:10 +10:00
stijn
146c32a141 windows/msvc: Enable overriding directories used in the build.
Append to PyIncDirs, used to define include directories specific to
MicroPython, instead of just overwriting it so project files importing this
file can define additional directories.  And allow defining the target
directory for the executable instead of hardcoding it to the windows
directory.  Main reason for this change is that it will allow building
mpy-cross with msvc.
2019-09-18 22:14:37 +10:00
stijn
94873a4826 windows/msvc: Move build options from .vcxproj to .props files.
We want the .vcxproj to be just a container with the minimum content for
making it work as a project file for Visual Studio and MSBuild, whereas the
actual build options and actions get placed in separate reusable files.
This was roughly the case already except some compiler options were
overlooked; fix this here: we'll need those common options when adding a
project file for building mpy-cross.
2019-09-18 22:14:11 +10:00
stijn
b2b21839d3 windows/msvc: Remove unneeded definitions for qstr generation.
These were probably added to detect more qstrs but as long as the
micropython executable itself doesn't use the same build options the qstrs
would be unused anyway.  Furthermore these definitions are for internal use
and get enabled when corresponding MICROPY_EMIT_XXX are defined, in which
case the compiler would warn about symbol redefinitions since they'd be
defined both here and in the source.
2019-09-18 22:13:26 +10:00
Jim Mussared
62d78e231c esp32/main: Use both 3.3 and 4.0 config vars to enable SPIRAM. 2019-09-18 15:49:45 +10:00
iabdalkader
73c94bbbd4 stm32/modusocket: Fix NULL deref when accept() an unbound socket. 2019-09-17 12:30:10 +10:00
Jim Mussared
f469634c0c esp32: Add check to Makefile that the toolchain is in PATH. 2019-09-17 12:26:47 +10:00
Jim Mussared
970f798ea9 esp32: Add check to Makefile for pyparsing version. 2019-09-17 12:26:42 +10:00
Jim Mussared
96008ff59a esp32: Support building with ESP IDF 4.0-beta1.
This commit adds support for a second supported hash (currently set to the
4.0-beta1 tag).  When this hash is detected, the relevant changes are
applied.

This allows to start using v4 features (e.g. BLE with Nimble), and also
start doing testing, while still supporting the original, stable, v3.3 IDF.

Note: this feature is experimental, not well tested, and network.LAN and
network.PPP are currently unsupported.
2019-09-17 12:25:36 +10:00
Damien George
b45f9de809 bare-arm, minimal: Set CSUPEROPT=-Os to get minimal firmware size.
This option affects py/vm.c and py/gc.c and using -Os gets them compiling a
bit smaller, and small firmware is the aim of these two ports.  Also,
having these files compiled with -Os on these ports, and -O3 as the default
on other ports, gives a better understanding of code-size changes when
making changes to these files.
2019-09-17 11:43:52 +10:00
roland van straten
ac112f88d0 nrf/boards: Add board definition for uBlox Nina B1 series BLE modules. 2019-09-17 11:33:48 +10:00
Damien George
22099ab88f stm32/machine_adc: Fix build for F4 and L4 MCUs that only have ADC1. 2019-09-12 19:10:12 +10:00
Damien George
356a728bd0 esp32/Makefile: Add SDKCONFIG_H to QSTR_GLOBAL_REQUIREMENTS.
Fixes issue #5091.
2019-09-12 18:16:16 +10:00
Damien George
f66616556d stm32/lwip_inc: Enable LWIP_NETIF_EXT_STATUS_CALLBACK for mDNS.
This feature makes sure that mDNS is automatically restarted when there is
any change event on a netif.
2019-09-12 18:08:50 +10:00
Damien George
b0e17bbb9d stm32/lwip_inc: Allocate additional MEMP_SYS_TIMEOUT when mDNS enabled.
Since v2.1 of lwIP mDNS uses a MEMP_SYS_TIMEOUT slot, so allocate an extra
one when this feature is enabled.
2019-09-12 18:05:27 +10:00
Damien George
bcaafa3823 stm32/usb: Verify number of used endpoints doesn't exceed maximum. 2019-09-11 15:17:38 +10:00
Damien George
6705767da1 stm32/usb: Add support for VCP+MSC+HID mode, incl 2xVCP and 3xVCP. 2019-09-11 15:17:38 +10:00
cristian
cfec054073 stm32/board/NUCLEO_F746ZG: Enable Ethernet periph, lwip and ussl. 2019-09-11 11:20:58 +10:00
Jim Mussared
c8c37ca407 stm32/boards/STM32F769DISC: Fix number of SDRAM row bits.
According to the schematic, the SDRAM part on this board is a
MT48LC4M32B2B5-6A, with "Row addressing 4K A[11:0]" (per datasheet).  This
commit updates mpconfigboard.h from 13 to 12 to match.
2019-09-10 23:13:52 +10:00
Damien George
bd1d27f00f esp32/modules/inisetup.py: Use bdev.ioctl instead of bdev.SEC_SIZE.
Since the bdev is now a Partition it doesn't have SEC_SIZE.
2019-09-10 22:41:50 +10:00
Alex Albino
80d37d936c esp32: Add support for ESP32-D2WD with 2MiB internal flash.
This patch adds a partitions file for the D2WD and a new board GENERIC_D2WD
which runs on these chip variants.

Resolves issue #4986.
2019-09-10 15:22:16 +10:00
Damien George
31de44775c esp32: Add VFS FAT partition to partitions.csv and mount it as the FS.
This patch uses the newly-added esp32.Partition class to replace the
existing FlashBdev class.  Partition objects implement the block protocol
so can be directly mounted via uos.mount().  This has the following
benefits:

- allows the filesystem partition location and size to be specified in
  partitions.csv, and overridden by a particular board
- very easily allows to have multiple filesystems by simply adding extra
  entries to partitions.csv
- improves efficiency/speed of filesystem operations because the block
  device is implemented fully in C
- opens the possibility to have encrypted flash storage (since Partitions
  can be encrypted)

Note that this patch is fully backwards compatible: existing filesystems
remain untouched and work with this new code.
2019-09-10 15:14:13 +10:00
Christopher Wilson
f9d142523c stm32/boards/MIKROE_CLICKER2_STM32: Add MikroElektronika Clicker2 board.
- STM32F407VGT6 (1MB of Flash, 192+4 Kbytes of SRAM)
- 5V (via USB) or Li-Polymer Battery (3.7V) power input
- 2 x LEDs
- 2 x user switches
- 2 x mikroBUS sockets
- 2 x 1x26 mikromedia-compatible headers (52 pins)

https://www.mikroe.com/clicker-2-stm32f4
2019-09-10 13:57:01 +10:00
Damien George
2b07f56c2b stm32/boards/NUCLEO_L073RZ: Fix typo in MCU name. 2019-09-10 11:53:00 +10:00
Chris Wilson
a605b53702 stm32/mboot: Support boards with only two LEDs.
Mboot currently requires at least three LEDs to display each of the four
states.  However, since there are only four possible states, the states can
be displayed via binary counting on only 2 LEDs (if only 2 are available).
The existing patterns are still used for 3 or 4 LEDs.
2019-09-10 11:25:56 +10:00
Andrew Leech
380048df64 windows/Makefile: Make use of CFLAGS_EXTRA, LDFLAGS_EXTRA and SRC_MOD.
To be consistent with the unix port.
2019-09-10 11:20:36 +10:00
Damien George
e9af6f5f88 esp32/boards/TINYPICO: Switch to use QIO and 80MHz for SPI interface. 2019-09-10 11:10:19 +10:00
Braden Mars
5641aa55dd esp32: Update to use ESP IDF v3.3
Includes patches for CVE-2019-12586 & CVE-2019-12587
2019-09-07 01:28:11 -05:00
Damien George
bd2e46e0a5 stm32/boards/stm32wb55_af.csv: Fix ADC pin-channel function mapping. 2019-09-06 17:56:34 +10:00
Damien George
62fe013a5f stm32/machine_adc: Improve operation of ADC for H7, L4 and WB MCUs. 2019-09-06 17:55:12 +10:00
Jim Mussared
1f52a6f8e4 nrf/boards: Add Particle Xenon board configuration (an nRF52840). 2019-09-05 22:56:05 +10:00
Jim Mussared
d36fc4682e nrf/Makefile: Add support for flashing with a Black Magic Probe.
Also rename "flash" target to "deploy" to match other ports (but provide
"flash" as an alias for backwards compatibility).
2019-09-05 22:56:05 +10:00
Jim Mussared
353ed7705f nrf/boards/make-pins.py: Fix gen of board pins to use correct index.
It was previously not taking into account that the list of pins was sparse,
so using the wrong index.  The boards/X/pins.csv was generating the wrong
data for machine.Pin.board.

As part of this fix rename the variables to make it more clear what the
list contains (only board pins).
2019-09-05 22:52:24 +10:00
Damien George
9e90e2528b nrf/machine/adc: Fix mapping of ADC channel to pin. 2019-09-05 22:13:04 +10:00
Damien George
c7fb93b844 nrf/machine/adc: Allow to pass a Pin object in to ADC constructor. 2019-09-05 22:13:04 +10:00
Damien George
b766a6971e nrf: Add ADC channel mapping to alt function table. 2019-09-05 22:13:04 +10:00
Damien George
9cad134a2f nrf/machine/adc: Add ADC.read_u16() method. 2019-09-05 22:13:04 +10:00
Damien George
983283a8cd esp32/machine_adc: Add ADC.read_u16() method. 2019-09-05 22:13:04 +10: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
ebacdfabb6 stm32/machine_adc: Add machine.ADC class. 2019-09-04 15:40:24 +10:00
Jim Mussared
06661890de stm32/powerctrl: Fix machine.bootloader() for L0 MCUs. 2019-09-04 11:36:53 +10:00
Jim Mussared
8fc00928ea stm32/dma: Fix DMA config for L0 MCUs. 2019-09-03 23:33:09 +10:00
stijn
4beb6c21ca windows/msvc: Treat compiler warnings as errors.
This is consistent with the other ports and helps catching problems early.
2019-09-03 23:27:06 +10:00
Jim Mussared
74fe841449 docs/library/pyb.DAC.rst: Correct frequency for triangle mode output.
Also correct comments in related code.
2019-09-03 23:25:45 +10:00
Jim Mussared
50482cdc0c esp32/Makefile: Fix subst->patsubst in ESPIDF_BOOTLOADER_SUPPORT_O. 2019-09-03 23:21:50 +10:00
Damien George
060209240b esp8266: Put new profile code in iROM. 2019-08-30 16:49:02 +10:00
Milan Rossa
310b3d1b81 py: Integrate sys.settrace feature into the VM and runtime.
This commit adds support for sys.settrace, allowing to install Python
handlers to trace execution of Python code.  The interface follows CPython
as closely as possible.  The feature is disabled by default and can be
enabled via MICROPY_PY_SYS_SETTRACE.
2019-08-30 16:44:12 +10:00
Damien George
400a128e11 stm32/stm32_it: Include correct EXTI interrupt handlers for L0 MCUs. 2019-08-29 12:00:18 +10:00
Damien George
1fe1ff935b nrf: Clean up source by removing tabs, trailing spaces, non-ASCII chars. 2019-08-28 13:34:45 +10:00
Eric Poulsen
5635b96461 esp32: Add 'config' function to network.LAN, reusing network.WLAN. 2019-08-28 13:11:48 +10:00
iabdalkader
0bec07f32b stm32/extint: Fix EXTI mapping of PVD and RTC events for H7 MCUs. 2019-08-28 12:53:42 +10:00
Damien George
af20c2ead3 py: Add global default_emit_opt variable to make emit kind persistent.
mp_compile no longer takes an emit_opt argument, rather this setting is now
provided by the global default_emit_opt variable.

Now, when -X emit=native is passed as a command-line option, the emitter
will be set for all compiled modules (included imports), not just the
top-level script.

In the future there could be a way to also set this variable from a script.

Fixes issue #4267.
2019-08-28 12:47:58 +10:00
Damien George
15b36aa0af unix/main: Only accept full emit cmd-line options if native enabled. 2019-08-28 12:47:58 +10:00
Damien George
5789558d60 stm32/boards/PYBD_SF2: Exclude certain things when building mboot. 2019-08-28 12:37:13 +10:00
Damien George
68d74b0074 stm32/mboot/Makefile: Define "BUILDING_MBOOT" when building mboot.
So boards can configure their settings based on whether mboot or the main
firmware is being built.
2019-08-28 12:37:13 +10:00
Damien George
b1e04848ef stm32/mphalport: Put PYBD specific MAC code in board specific file. 2019-08-28 12:37:13 +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
roland van straten
fe3c064d42 samd: Add minimum config for Atmel SAMD21-XPLAINED-PRO board. 2019-08-20 21:30:36 +10:00
Damien George
05eb897d06 esp32: Add esp32.Partition class to expose partition and OTA funcs.
Partitions are exposed as a standard MicroPython block device.
2019-08-20 16:49:18 +10:00
Jim Mussared
0bd1eb80ff qemu-arm: Add testing of frozen native modules.
- Split 'qemu-arm' from 'unix' for generating tests.
- Add frozen module to the qemu-arm test build.
- Add test that reproduces the requirement to half-word align native
  function data.
2019-08-20 15:14:08 +10:00
Damien George
7d851a27f1 extmod/modure: Make regex dump-code debugging feature optional.
Enabled via MICROPY_PY_URE_DEBUG, disabled by default (but enabled on unix
coverage build).  This is a rarely used feature that costs a lot of code
(500-800 bytes flash).  Debugging of regular expressions can be done
offline with other tools.
2019-08-19 16:43:00 +10:00
stijn
af5c998f37 py/modmath: Implement math.isclose() for non-complex numbers.
As per PEP 485, this function appeared in for Python 3.5.  Configured via
MICROPY_PY_MATH_ISCLOSE which is disabled by default, but enabled for the
ports which already have MICROPY_PY_MATH_SPECIAL_FUNCTIONS enabled.
2019-08-17 23:23:17 +10:00
Damien George
3eff81288c stm32/i2c: Fix generation of restart condition for hw I2C on F0/F7.
Before this patch I2C transactions using a hardware I2C peripheral on F0/F7
MCUs would not correctly generate the I2C restart condition, and instead
would generate a stop followed by a start.  This is because the CR2 AUTOEND
bit was being set before CR2 START when the peripheral already had the I2C
bus from a previous transaction that did not generate a stop.

As a consequence all combined transactions, eg read-then-write for an I2C
memory transfer, generated a stop condition after the first transaction and
didn't generate a stop at the very end (but still released the bus).  Some
I2C devices require a repeated start to function correctly.

This patch fixes this by making sure the CR2 AUTOEND bit is set after the
start condition and slave address have been fully transferred out.
2019-08-16 13:34:04 +10:00
Jim Mussared
eb7eed5d92 samd/boards: Add Mini SAM M4 board configuration. 2019-08-16 00:28:30 +10:00
Jim Mussared
90188cc92b samd/boards: Add Adafruit Feather M0 Express board configuration. 2019-08-16 00:28:12 +10:00
Jim Mussared
a5d85d306c samd: Make common linker scripts, rename board.mk to mpconfigboard.mk.
The rename matches other ports, e.g. stm32, and gives consistency with
mpconfigboard.h.
2019-08-16 00:26:54 +10:00
Jim Mussared
8db517f26d esp32: Add per-board configs, following other ports.
Replaces the `SDKCONFIG` makefile variable with `BOARD`.  Defaults to
BOARD=GENERIC.  spiram can be enabled with `BOARD=GENERIC_SPIRAM`

Add example definition for TINYPICO, currently identical to GENERIC_SPIRAM
but with custom board/SoC names for the uPy banner.
2019-08-16 00:22:29 +10:00
Damien George
497683b315 gitignore: Put build-*/ pattern in top-level gitignore file. 2019-08-16 00:08:08 +10:00
Damien George
baeebc557c esp32/modules: On initial setup mount internal flash at root.
Like it's done on normal boot up.  Fixes issue #5004.
2019-08-15 22:03:09 +10:00
Milan Rossa
6f0c6bd774 unix: Enable sys.atexit, triggered after the main script ends. 2019-08-15 17:31:04 +10:00
Damien George
2ccf030fd1 esp32: Add support for mDNS queries and responder.
They are both enabled by default, but can be disabled by defining
MICROPY_HW_ENABLE_MDNS_QUERIES and/or MICROPY_HW_ENABLE_MDNS_RESPONDER to
0.  The hostname for the responder is currently taken from
tcpip_adapter_get_hostname() but should eventually be configurable.
2019-08-15 16:36:47 +10:00
Damien George
25d3509986 stm32/usbd: Make USB device FIFO sizes dynamically configurable.
Allows to optimise and configure the FIFO sizes depending on the USB device
configuration selected at runtime, eg VCP+MSC vs 3xVCP+MSC.
2019-08-15 13:56:50 +10:00
Damien George
8485b72d0d stm32/boards/NUCLEO_L432KC: Add config for USB VCP support. 2019-08-15 12:46:34 +10:00
Damien George
97e8e036c5 stm32/usbd: Support USB device mode on STM32L432 MCUs. 2019-08-15 12:46:04 +10:00
Damien George
bf733c27bb stm32/usbd: Introduce MICROPY_HW_USB_IS_MULTI_OTG to simplify USB config
This is an internal config value that is enabled for MCUs that have
multiple OTG instances, to simplify #if configuration of the USB code.
2019-08-15 12:19:28 +10:00
Damien George
ba607809f2 stm32/modpyb: Support building with PY_PYB_LEGACY on and HW_USB_HID off. 2019-08-15 12:03:32 +10:00
Kenta IDA
b6906fa573 esp32/network_ppp: Add authentication support to the PPP interface.
This commit adds the connect() method to the PPP interface and requires
that connect() be called after active(1).  This is a breaking change for
the PPP API.

With the connect() method it's now possible to pass in authentication
information for PAP/CHAP, eg:

    ppp.active(1)
    ppp.connect(authmode=ppp.AUTH_PAP, username="user", "password="password")

If no authentication is needed simply call connect() without any
parameters.  This will get the original behaviour of calling active(1).
2019-08-14 17:20:58 +10:00
Chris Wilson
3d02ebb4e8 stm32/sdcard: Support configuring the SD/MMC bus width to 1 or 4 bits.
Some SD/MMC breakout boards don't support 4-bit bus mode.  This adds a new
macro MICROPY_HW_SDMMC_BUS_WIDTH that allows each board to define the width
of the SD/MMC bus interface used on that board, defaulting to 4 bits.
2019-08-08 12:53:05 +10:00
Damien George
2d3d4f7483 esp8266/mpconfigport.h: Enable lwIP raw sockets. 2019-08-06 15:56:05 +10:00
Damien George
102815f700 stm32/mpconfigport.h: Enable lwIP raw sockets. 2019-08-06 15:56:05 +10:00
Damien George
0e2b224b07 stm32/lwip_inc: Enable raw socket type. 2019-08-06 15:56:05 +10:00
Damien George
7c15e50eb8 esp32/Makefile: Include CFLAGS_EXTRA in CFLAGS definition.
Following other ports, so builds can be customised more easily, eg on the
command line building with a user C-module.
2019-07-30 17:31:23 +10:00
Damien George
473157eeb9 stm32/usbd_hid_interface: Include extra header to build with threading. 2019-07-26 12:44:14 +10:00
Damien George
ad0b7cb017 stm32/boards/xxx_WB55: Enable USB HID now that it works on WB MCUs. 2019-07-25 17:49:53 +10:00
Damien George
fa07deda9f stm32/usbd_hid_interface: Rewrite USB HID interface code.
The previous version did not work on MCUs that only had USB device mode
(compared to OTG) because of the handling of NAK.  And this previous
handling of NAK had a race condition where a new packet could come in
before USBD_HID_SetNAK was called (since USBD_HID_ReceivePacket clears NAK
as part of its operation).  Furthermore, the double buffering of incoming
reports was not working, only one buffer could be used at a time.

This commit rewrites the HID interface code to have a single incoming
buffer, and only calls USBD_HID_ReceivePacket after the user has read the
incoming report (similar to how the VCP does its flow control).  As such,
USBD_HID_SetNAK and USBD_HID_ClearNAK are no longer needed.

API functionality from the user's point of view should be unchanged with
this commit.
2019-07-25 17:42:17 +10:00
Damien George
b1129df478 stm32/dma: Fix re-start of DMA stream by clearing all event flags.
As per the datasheet, all event flags for a stream must be cleared before
enabling it.  Fixes issue #4944 (with DAC.write_timed).
2019-07-25 16:48:26 +10:00
badlyby
3b258ef213 stm32/boards/NUCLEO_F722ZE: Add definition files for new board. 2019-07-25 16:31:36 +10:00
badlyby
09267bb147 stm32/boards/stm32f722.ld: Provide memory regions for internal FS. 2019-07-25 16:31:36 +10:00
badlyby
0da2f6f23a stm32/flashbdev: Support internal filesystem on STM32F722/23/32/33. 2019-07-25 16:31:12 +10:00
Amir Gonnen
995f9cfdfc esp32: Pin MicroPython tasks to a specific core.
On this port the GIL is enabled and everything works under the assumption
of the GIL, ie that a given task has exclusive access to the uPy state, and
any ISRs interrupt the current task and therefore the ISR inherits
exclusive access to the uPy state for the duration of its execution.

If the MicroPython tasks are not pinned to a specific core then an ISR may
be executed on a different core to the task, making it possible for the
main task and an ISR to execute in parallel, breaking the assumption of the
GIL.

The easiest and safest fix for this is to pin all MicroPython related code
to the same CPU core, as done by this patch.  Then any ISR that accesses
MicroPython state must be registered from a MicroPython task, to ensure it
is invoked on the same core.

See issue #4895.
2019-07-25 15:33:47 +10:00
Damien George
e3e7e3a781 esp32/Makefile: Simplify include of IDF source by using wildcards. 2019-07-20 14:07:18 +10:00
Damien George
b88e51d718 esp32/Makefile: Put OBJ and LIB rule additions in gen_espidf_lib_rule. 2019-07-20 13:04:55 +10:00
Jim Mussared
331c224e07 esp32/Makefile: Fix path expansion for ESPIDF_DRIVER_O.
It was using subst to s/.c/.o/ which changed .c anywhere in the path.
2019-07-20 12:32:43 +10:00
stijn
9da46a98cb windows/mpconfigport.h: Don't define restrict/inline/alignof for C++.
The C++ standard forbids redefining keywords, like inline and alignof, so
guard these definitions to avoid that, allowing to include the MicroPython
headers by C++ code.
2019-07-19 16:58:02 +10:00
Damien George
a29334761d esp32: Add support for hardware I2C. 2019-07-19 16:31:25 +10:00
Damien George
0c12adca46 stm32/boards/USBDONGLE_WB55: Add definition files for new board. 2019-07-17 17:00:34 +10:00
Damien George
d2a8fb747f stm32/boards/NUCLEO_WB55: Add definition files for new board. 2019-07-17 17:00:34 +10:00
Damien George
9849567a06 stm32/boards: Add MCU support files for STM32WB55. 2019-07-17 16:50:42 +10:00
Damien George
59b7166d87 stm32: Add initial support for STM32WBxx MCUs.
This new series of MCUs is similar to the L4 series with an additional
Cortex-M0 coprocessor.  The firmware for the wireless stack must be managed
separately and MicroPython does not currently interface to it.  Supported
features so far include: RTC, UART, USB, internal flash filesystem.
2019-07-17 16:33:31 +10:00
Damien George
d42392b9a7 stm32/make-stmconst.py: Allow more variation in parens and int-suffix L. 2019-07-17 16:27:17 +10:00
Damien George
02b2ad4fbd stm32/boards/STM32F769DISC: Fix length of FLASH_APP section.
Fixes issue #4924.
2019-07-17 16:19:50 +10:00
Damien George
baea43bba7 stm32/boards/B_L072Z_LRWAN1: Enable USB VCP support. 2019-07-16 14:50:44 +10:00
Damien George
64aebca155 stm32/Makefile: Allow a board to disable float support.
By using "MICROPY_FLOAT_IMPL = none" in its mpconfigboard.mk file.
2019-07-16 14:47:32 +10:00
Damien George
102d9911e9 stm32/mphalport: Fix GPIO clock enable for L0 MCUs. 2019-07-16 14:47:12 +10:00
Damien George
4096fa397b stm32/powerctrlboot: Increase SYSCLK to 32MHz for L0 MCUs. 2019-07-16 14:46:31 +10:00
Damien George
4c1ad1f691 stm32: Add support for USB on L0 MCUs. 2019-07-16 14:45:53 +10:00
Damien George
788e7f50f2 stm32/usbd_cdc_interface: Make CDC TX/RX buffer sizes configurable. 2019-07-16 14:41:59 +10:00
Damien George
f302f784e9 stm32/usb: Add config options to disable USB MSC and/or HID.
The new configurations MICROPY_HW_USB_MSC and MICROPY_HW_USB_HID can be
used by a board to enabled or disable MSC and/or HID.  They are both
enabled by default.
2019-07-16 14:39:21 +10:00
Damien George
fd49fcb229 stm32/gccollect: Always use MP_STATE_THREAD(stack_top) to get stack top.
In a non-thread build, using &_ram_end as the top-of-stack is no longer
correct because the stack is not always at the very top end of RAM.  See
eg 04c7cdb668 and
3786592097.  The correct value to use is
&_estack, which is the value stored in MP_STATE_THREAD(stack_top), and
using the same code for both thread and non-thread builds makes the code
cleaner.
2019-07-11 17:32:01 +10:00
Paul m. p. P
a1c870e9f4 javascript: Enable support for frozen bytecode via FROZEN_MPY_DIR. 2019-07-09 13:17:15 +10:00
Paul m. p. P
42d30c5baf unix/unix_mphal: Include time.h for CLOCK_MONOTONIC. 2019-07-09 13:05:59 +10:00
Damien George
a17b901a9e stm32/boards/B_L072Z_LRWAN1: Add definition files for new board. 2019-07-09 12:54:09 +10:00
Damien George
278e9bffe9 stm32/mboot: Update dependencies to enable parallel build with -j. 2019-07-09 11:46:47 +10:00
Damien George
342539bdcc stm32/mboot: Use STARTUP_FILE from stm32lib. 2019-07-09 11:35:47 +10:00
Damien George
5a81d2d6b8 stm32/mboot: Remove use of BSRRL/H for H7 MCUs due to stm32lib update. 2019-07-09 11:34:54 +10:00
Damien George
c8f19f1371 stm32/mboot: Make _estack an array to avoid compiler warnings.
The compiler can warn about out-of-bounds array access if _estack is just a
single uint8_t.
2019-07-09 11:33:57 +10:00
Damien George
d43dd886a5 stm32/boards/NUCLEO_F413ZH: Remove STARTUP_FILE, it's defined globally.
The Makefile now defines this variable to the correct value (but it can
still be overridden by a board if necessary).
2019-07-09 11:32:12 +10:00
Chris Mason
c24d81119c stm32/boards/NUCLEO_L452RE: Add definition files for new board. 2019-07-08 16:50:45 +10:00
Chris Mason
64181b5f76 stm32: Add support for STM32L452 MCUs. 2019-07-08 16:50:19 +10:00
Damien George
eea61a09c4 stm32/boards/NUCLEO_F446RE: Enable DAC. 2019-07-08 16:08:40 +10:00
Damien George
5fd62c8992 stm32: Remove SystemInit funcs, use stm32lib versions instead.
stm32lib now provides system_stm32XXxx.c source files for all MCU variants,
which includes SystemInit and prescaler tables.  Since these are quite
standard and don't need to be changed, switch to use them instead of custom
variants, making the start-up code cleaner.

The SystemInit code in stm32lib was checked and is equivalent to what is
removed from the stm32 port in this commit.
2019-07-08 15:23:53 +10:00
Damien George
c15dc2c4b9 stm32/powerctrl: Move F0's SystemClock_Config to powerctrlboot.c. 2019-07-08 15:23:53 +10:00
Damien George
21ecf8be5f stm32/powerctrl: Move L0's SystemClock_Config to powerctrlboot.c file. 2019-07-08 15:23:53 +10:00
Damien George
7c2e83324b stm32/boards/NUCLEO_L073RZ: Add definition files for new board. 2019-07-05 17:28:54 +10:00
Damien George
6053e450b8 stm32/mpconfigport.h: Make "framebuf" module configurable by a board. 2019-07-05 17:26:49 +10:00
Damien George
9c096c190c stm32/boards: Add MCU support files for STM32L072. 2019-07-05 17:26:03 +10:00
Damien George
23d9c6a0fd stm32: Add initial support for STM32L0xx MCUs. 2019-07-05 17:24:59 +10:00
Eric Poulsen
fa5c0b819c esp32/network_ppp: Add ppp_set_usepeerdns(pcb, 1) when init'ing iface.
Without this you often don't get any DNS server from your network provider.
Additionally, setting your own DNS _does not work_ without this option set
(which could be a bug in the PPP stack).
2019-07-04 11:17:41 +10:00
Damien George
c1a8c7fc09 stm32/boards/PYBD_SFx: Automatically turn on EN_3V3 when powering SD/MMC 2019-07-04 11:11:11 +10:00
Damien George
7f33f158b9 stm32/sdcard: Add hook for a board to power on SD/MMC. 2019-07-04 11:10:54 +10:00
Damien George
1cd2bc066d stm32/boards/PYBD_SFx: Configure EN_3V3 pin as output on boot.
But leave it turned off, the application must turn it on if/when needed.
2019-07-04 11:03:10 +10:00
Damien George
afb2e9dd94 stm32/modmachine: Disable IRQs before entering bootloader.
To make sure that the code that enters the bootloader is not interrupted.
2019-07-04 10:49:51 +10:00
Damien George
04da8864e5 stm32/lwip_inc: Define LWIP_NO_CTYPE_H=1 to use lwIP ctype funcs. 2019-07-04 10:36:51 +10:00
Damien George
592f68449d stm32/mpu: Include MPU functions when ETH is enabled. 2019-07-03 23:50:34 +10:00
Damien George
7cf8285ac8 stm32/boards: Remove startup_stm32*.s files now they are in stm32lib. 2019-07-03 23:44:17 +10:00
Damien George
6b6403ce76 stm32/Makefile: Use startup_stm32*.s file from stm32lib.
This means that each MCU now gets a unique IRQ table, eg a specific one for
STM32F405, STM32F411, etc rather than just STM32F4xx.
2019-07-03 23:42:36 +10:00
Damien George
241e577753 stm32/Makefile: Remove Wno-attributes for ll_usb HAL file.
This HAL file is now patched so it doesn't have these warnings.
2019-07-03 23:41:33 +10:00
Damien George
73e8b7e0e4 stm32: Update components to work with new H7xx HAL. 2019-07-03 23:40:49 +10:00
Damien George
3581deec81 stm32/boards/PYBD_SF2: Put mbedtls library code in external QSPI flash.
mbedtls is large and self contained so is a good candidate to be in
external XIP flash, to keep enough spare ROM in internal flash.
2019-07-03 16:50:02 +10:00
Damien George
f88cb8a514 stm32/modmachine: Make RTC class available in machine module.
This is a start to make a more consistent machine.RTC class across ports.
The stm32 pyb.RTC class at least has the datetime() method which behaves
the same as esp8266 and esp32, and with this patch the ntptime.py script
now works with stm32.
2019-07-03 16:46:07 +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
79b6688558 stm32/extint: Simplify bitband support config for different MCUs. 2019-07-03 12:02:58 +10:00
Damien George
14bec7964f stm32/spi: Factor out code to calculate SPI source frequency. 2019-07-03 12:02:46 +10:00
Damien George
f114ce0a4b stm32/usb: Add "port" keyword argument to pyb.usb_mode, to select FS/HS.
If the board supports it, the USB port can now be explicitly specified, eg:

    pyb.usb_mode('VCP', port=0).

port=0 is USB FS and port=1 is USB HS.
2019-07-03 11:58:56 +10:00
Damien George
46b3cc4572 stm32/usb: Add support to auto-detect USB interface, either FS or HS.
If both FS and HS USB peripherals are enabled for a board then the active
one used for the REPL will now be auto-detected, by checking to see if both
the DP and DM lines are actively pulled low.  By default the code falls
back to use MICROPY_HW_USB_MAIN_DEV if nothing can be detected.
2019-07-03 11:51:13 +10:00
Damien George
6d2e654b14 stm32/mpconfigport.h: Enable useful networking modules if lwIP enabled. 2019-07-03 11:21:45 +10:00
Damien George
d821a27b58 stm32/boards/PYBD_SFx: Put SPI flash to sleep during sleep modes. 2019-07-03 01:27:33 +10:00
Damien George
ea033bf25a stm32/powerctrl: Add hooks for a board to perform actions on sleep/wake. 2019-07-03 01:27:33 +10:00
Damien George
caabdd99c0 stm32/qspi: Handle bus acquisition.
When going out of memory-mapped mode to do a control transfer to the QSPI
flash, the MPU settings must be changed to forbid access to the memory
mapped region.  And any ongoing transfer (eg memory mapped continuous read)
must be aborted.
2019-07-03 01:27:33 +10:00
Damien George
2034c0a2e3 stm32/qspi: Force a reset of the QSPI peripheral when initialising it.
To ensure it is in a known state on start up.
2019-07-03 01:27:33 +10:00
Damien George
8da39fd182 stm32/qspi: Use MPU to allow access to valid memory-mapped QSPI region.
The Cortex-M7 CPU will do speculative loads from any memory location that
is not explicitly forbidden.  This includes the QSPI memory-mapped region
starting at 0x90000000 and with size 256MiB.  Speculative loads to this
QSPI region may 1) interfere with the QSPI peripheral registers (eg the
address register) if the QSPI is not in memory-mapped mode; 2) attempt to
access data outside the configured size of the QSPI flash when it is in
memory-mapped mode.  Both of these scenarios will lead to issues with the
QSPI peripheral (eg Cortex bus lock up in scenario 2).

To prevent such speculative loads from interfering with the peripheral the
MPU is configured in this commit to restrict access to the QSPI mapped
region: when not memory mapped the entire region is forbidden; when memory
mapped only accesses to the valid flash size are permitted.
2019-07-03 01:27:33 +10:00
Damien George
eca4115f66 stm32/sdram: Use MPU helper functions to configure MPU for SDRAM use. 2019-07-03 01:27:33 +10:00
Damien George
f7eb2c72f7 stm32/eth: Use MPU helper functions to configure MPU for ETH use. 2019-07-03 01:27:33 +10:00
Damien George
8dcf25e1bd stm32/mpu: Add helper functions for configuring MPU. 2019-07-03 01:27:33 +10:00
Damien George
08075beeb9 samd: Remove "makefile" file.
This file can be added by a user to customise the build process.
2019-07-02 17:09:59 +10:00
Damien George
097b0f9397 windows/mpconfigport.h: Define empty MP_WEAK symbol. 2019-07-01 22:53:00 +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
999733b1fb minimal: Use soft float for CROSS=1 Cortex-M4 target.
When compiled with hard float the system should enable FP access when it
starts or else FP instructions lead to a fault.  But this minimal port does
not enable (or use) FP and so, to keep it minimal, switch to use soft
floating point.  (This became an issue due to the recent commit
34c04d2319 which saves/restores FP registers
in the NLR state.)
2019-07-01 22:48:05 +10:00
Damien George
5f9bd11527 samd: Add new port to Microchip SAMDxx microcontrollers.
Initially supporting SAMD21 and SAMD51.
2019-07-01 17:19:18 +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
Chris Mason
3786592097 stm32/boards: Optimise flash and RAM allocation for L4 boards.
Optimisations are:
- Remove FLASH_ISR section since devices with a small flash sector erase
  size don't need special FLASH_ISR handling.  This reduces flash image by
  approx 1.5k.
- Make SRAM2 contiguous with SRAM1 where possible.
- Simplify configuration of 2k RAM buffer used for flash filesystem.

RAM changes with this commit:
- L432: stack   6k -> 10k,  bss + heap   42k ->  52k
- L476: stack  16k -> 30k,  bss + heap   80k ->  96k
- L496: stack 206k -> 16k,  bss + heap  112k -> 302k
2019-07-01 16:57:20 +10:00
Mikhail Zakharov
ced340d739 unix/unix_mphal: Use CLOCK_MONOTONIC for ticks_ms/us when available. 2019-06-26 11:07:45 +10:00
Glenn Ruben Bakke
d889def06b nrf/led: Adjust how board LEDs are defined.
Change static LED functions to lowercase names, and trim down source code
lines for variants of MICROPY_HW_LED_COUNT.  Also rename configuration for
MICROPY_HW_LEDx_LEVEL to MICROPY_HW_LEDx_PULLUP to align with global PULLUP
configuration.
2019-06-25 16:02:31 +10:00
Damien George
d21d578644 stm32/usb: Fix regression with auto USB PID value giving PID=0xffff.
Commit 9e68eec8ea introduced a regression
where the PID of the USB device would be 0xffff if the default value was
used.  This commit fixes that by using a signed int type.
2019-06-25 15:43:54 +10:00
Josh Lloyd
2f262d5f9a esp32/Makefile: Include all driver/*.c source files in the build.
Fixes #4869.
2019-06-25 15:12:34 +10:00
Damien George
009b1f6559 stm32/boards: Rework all stm32??xx_hal_conf.h files to use common code.
This eliminates a lot of duplicated code in these header files.
2019-06-25 14:18:24 +10:00
Damien George
f96f53cd97 stm32/boards: Add stm32??xx_hal_conf_base.h files with common settings.
These are intended to be used by all boards, to reduce the size of a
board's configuration.
2019-06-25 14:18:24 +10:00
Damien George
89ebb3325b stm32/boards/pllvalues.py: Support HSx_VALUE defined without uint32_t. 2019-06-25 14:18:24 +10:00
Damien George
04c7cdb668 stm32: Enter bootloader via a system reset.
Entering a bootloader (ST system bootloader, or custom mboot) from software
by directly branching to it is not reliable, and the reliability of it
working can depend on the peripherals that were enabled by the application
code.  It's also not possible to branch to a bootloader if the WDT is
enabled (unless the bootloader has specific provisions to feed the WDT).

This patch changes the way a bootloader is entered from software by first
doing a complete system reset, then branching to the desired bootloader
early on in the start-up process.  The top two words of RAM (of the stack)
are reserved to store flags indicating that the bootloader should be
entered after a reset.
2019-06-25 14:15:49 +10:00
Damien George
205c6d0dc9 stm32/Makefile: Print info messages about use of mboot/QSPI flash. 2019-06-24 21:59:58 +10:00
Damien George
5da60ff9cb stm32/boards: Enable ussl module via mbedtls for boards with network. 2019-06-24 17:48:28 +10:00
Damien George
b80bccccff esp32/modnetwork: Still try to reconnect to WLAN even with AUTH_FAIL.
WIFI_REASON_AUTH_FAIL does not necessarily mean the password is wrong, and
a wrong password may not lead to a WIFI_REASON_AUTH_FAIL error code.  So to
improve reliability connecting to a WLAN always reconnect regardless of the
error.
2019-06-22 21:50:49 +10:00
Damien George
3ee3995be1 esp32: Update to use ESP IDF v3.3-beta3.
This updates ESP IDF to use v3.3-beta3.  And also adjusts README.md to
point to stable docs which provide a link to download the correct toolchain
for this IDF version, namely 1.22.0-80-g6c4433a-5.2.0
2019-06-19 14:32:15 +10:00
Nicko van Someren
1a51fc9ddf esp32/machine_sdcard: Fix bug in SPI slot number selection.
And fix minor typo in docs when referring to SDCard class.
2019-06-17 12:36:22 +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
Chris Mason
14cf91f704 stm32: In link script, define start of stack separately from heap end.
Previously the end of the heap was the start (lowest address) of the stack.
With the changes in this commit these addresses are now independent,
allowing a board to place the heap and stack in separate locations.
2019-06-14 15:29:24 +10:00
Damien George
8b18cfedee stm32/usbd_msc: Allow to compile when USB enabled and SD card disabled. 2019-06-11 21:01:14 +10:00
Damien George
53200247b7 stm32/usb: Add "msc" kw-arg to pyb.usb_mode to select MSC logical units.
With this the user can select multiple logical units to expose over USB MSC
at once, eg: pyb.usb_mode('VCP+MSC', msc=(pyb.Flash(), pyb.SDCard())).  The
default behaviour is the original behaviour of just one unit at a time.
2019-06-11 16:22:09 +10:00
Damien George
9e68eec8ea stm32/usb: Use ARG_xxx enums to access kw args in pyb_usb_mode. 2019-06-11 15:50:21 +10:00
Damien George
38bcc99a58 stm32/usbd_msc: Provide Mode Sense response data in MSC interface.
Eventually these responses could be filled in by a function to make their
contents dynamic, depending on the attached logical units.  But for now
they are fixed, and this patch fixes the MODE SENSE(6) responses so it is
the correct length with the correct header.
2019-06-11 15:43:59 +10:00
Damien George
829aa58c5c stm32/usbd_msc: Provide custom irquiry processing by MSC interface.
So the MSC interface can customise the inquiry response based on the
attached logical units.
2019-06-11 15:43:58 +10:00
Damien George
518aa571ab stm32/usbd_msc: Rework USBD MSC code to support multiple logical units.
SCSI can support multiple logical units over the one interface (in this
case over USBD MSC) and here the MSC code is reworked to support this
feature.  At this point only one LU is used and the behaviour is mostly
unchanged from before, except the INQUIRY result is different (it will
report "Flash" for both flash and SD card).
2019-06-11 15:43:15 +10:00
Damien George
62f004ba42 stm32/lwip_inc: Update to enable mDNS, TCP listen backlog, faster DHCP. 2019-06-05 16:14:45 +10:00
Damien George
9e4b3681fd stm32: Support optional lwIP mDNS responder. 2019-06-05 16:14:09 +10:00
Damien George
fd839221fd stm32/boards/PYBD_SFx: Enable ussl module using mbedTLS. 2019-06-05 15:38:01 +10:00
Damien George
fed4c23590 stm32: Integrate optional mbedTLS component for ussl module.
To use it a board should define MICROPY_PY_USSL=1 and MICROPY_SSL_MBEDTLS=1
at the Makefile level.  With the provided configuration it adds about 64k
to the build.
2019-06-05 15:37:31 +10:00
Damien George
9d72f07b6d unix/mpconfigport.mk: Update comment about TLS implementations.
As long as the submodule is checked out, mbedTLS is now fully integrated
into the unix build if MICROPY_SSL_MBEDTLS=1.
2019-06-05 15:28:30 +10:00
Damien George
ce8262a164 stm32/modnetwork: Replace generic netif NIC polling with specific code.
It doesn't work to tie the polling of an underlying NIC driver (eg to check
the NIC for pending Ethernet frames) with its associated lwIP netif.  This
is because most NICs are implemented with IRQs and don't need polling,
because there can be multiple lwIP netif's per NIC driver, and because it
restricts the use of the netif->state variable.  Instead the NIC should
have its own specific way of processing incoming Ethernet frame.

This patch removes this generic NIC polling feature, and for the only
driver that uses it (Wiznet5k) replaces it with an explicit call to the
poll function (which could eventually be improved by using a proper
external interrupt).
2019-06-03 17:14:34 +10:00
Damien George
62fe47aa3a stm32/boards/PYBD_SFx: Enable CYW43 WLAN driver. 2019-06-03 17:14:34 +10:00
Damien George
8b7409c295 stm32: Integrate in the cyw43 driver and network.WLAN class.
Enable it by setting MICROPY_PY_NETWORK_CYW43=1 at the Makefile level.
2019-06-03 17:14:34 +10:00
Damien George
12ed6f91ee stm32: Add low-level SDIO interface for cyw43 driver. 2019-06-03 16:53:46 +10:00
Damien George
370a8116c4 stm32/mphalport: Add support for having MAC in OTP region. 2019-06-03 16:47:35 +10:00
Damien George
10e173aaea stm32/extint: Add extint_set() function for internal C access to EXTI. 2019-06-03 16:47:35 +10:00
Damien George
345e9864aa stm32/modpyb: Add pyb.country() function to set the country.
To be used for peripherals (like radio) that must be location aware.
2019-06-03 16:47:35 +10:00
Nicko van Someren
8e3af7d4c8 esp32: Add machine.SDCard class using built-in HW SD/MMC controller.
This adds support for SD cards using the ESP32's built-in hardware SD/MMC
host controller, over either the SDIO bus or SPI.  The class is available
as machine.SDCard and using it can be as simple as:

    uos.mount(machine.SDCard(), '/sd')
2019-06-03 00:37:41 +10:00
Damien George
8f55c74533 stm32/boards: Add board definition files for PYBD -SF2, -SF3, -SF6.
These are core configurations providing PYBv1.x-level features.
2019-05-31 22:44:25 +10:00
Damien George
34cae24e30 stm32/boards/pllvalues.py: Search nested headers for HSx_VALUE defines. 2019-05-31 21:44:53 +10:00
Damien George
f8274d5e7d stm32/boards/make-pins.py: Allow pins.csv to skip or hide board-pin name
If the board-pin name is left empty then only the cpu-pin name is used, eg
",PA0".  If the board-pin name starts with a hyphen then it's available as
a C definition but not in the firmware, eg "-X1,PA0".
2019-05-31 21:41:30 +10:00
Damien George
3fc7c8e35c stm32/usb: Include py/mpconfig.h instead of mpconfigboard.h.
Because py/mpconfig.h has header include guards.
2019-05-31 21:39:34 +10:00
Martin Dybdal
de76f73d34 esp32/machine_timer: Reuse Timer handles, deallocate only on soft-reset.
The patch solves the problem where multiple Timer objects (e.g. multiple
Timer(0) instances) could initialise multiple handles to the same internal
timer.  The list of timers is now maintained not for "active" timers (where
init is called), but for all timers created.  The timers are only removed
from the list of timers on soft-reset (machine_timer_deinit_all).

Fixes #4078.
2019-05-31 14:55:07 +10:00
Damien George
ff91b05cfa stm32/usb: Support up to 3 VCP interfaces on USB device peripheral.
To enable define MICROPY_HW_USB_CDC_NUM to 3.
2019-05-31 11:35:42 +10:00
Damien George
0c29502ad9 stm32/usb: Refactor CDC VCP code to enable N CDC interfaces.
The board config option MICROPY_HW_USB_ENABLE_CDC2 is now changed to
MICROPY_HW_USB_CDC_NUM, and the latter should be defined to the maximum
number of CDC interfaces to support (defaults to 1).
2019-05-30 21:11:04 +10:00
Damien George
0bb6b63e66 stm32/mboot/README: Fix some typos, describe bootloader and fwupdate.py. 2019-05-29 16:26:02 +10:00
Andrew Leech
66bcb5596a stm32/modmachine: In bootloader() disable caches before reset of periphs
Otherwise flushing and disabling the D-cache will give a hard-fault when
SDRAM is used.

Fixes #4818.
2019-05-29 15:50:17 +10:00
Damien George
883e987b90 esp32/modsocket: Raise EAGAIN when accept fails in non-blocking mode.
EAGAIN should be for pure non-blocking mode and ETIMEDOUT for when there is
a finite (but non-zero) timeout enabled.
2019-05-28 17:43:00 +10:00
Damien George
8c9758ff2e unix/modusocket: Raise ETIMEDOUT when connect or accept has timeout. 2019-05-28 17:22:54 +10:00
Tom Manning
887a6712c2 esp32/machine_touchpad: Use HW timer for FSM to enable wake-on-touch. 2019-05-28 11:14:34 +10:00
Andrew Leech
1470184bdd stm32/sdram: Update MPU settings to block invalid region, change attrs.
Set the active MPU region to the actual size of SDRAM configured and
invalidate the rest of the memory-mapped region, to prevent errors due to
CPU speculation.  Also update the attributes of the SDRAM region as per ST
recommendations, and change region numbers to avoid conflicts elsewhere in
the codebase (see eth usage).
2019-05-24 15:55:00 +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
c4a6d9c631 zephyr: Switch back to enabling I2C in board-specific configs.
I2C can't be enabled in prj_base.conf because it's a board-specific
feature.  For example, if a board doesn't have I2C but CONFIG_I2C=y then
the build will fail (on Zephyr build system side).  The patch here gets the
qemu_cortex_m3 build working again.
2019-05-24 15:33:02 +10:00
Paul Sokolovsky
b88bf42793 zephyr/README: Reorder content related to recently added I2C.
So it fits better with existing narrative.
2019-05-24 15:29:29 +10:00
stijn
2762f323bf windows: Fix line wrapping behaviour on the REPL.
This enables going back to previous wrapped lines using backspace or left
arrow: instead of just sticking to the beginning of a line, the cursor will
move a line up.
2019-05-23 22:11:11 +10:00
Andrew Leech
4f44778728 stm32/sdcard: Add switch break to ensure only correct SD/MMC IRQ is run. 2019-05-23 21:55:31 +10:00
Damien George
9cf1cbb057 nrf/mphalport: Use wfi to save power while waiting at the UART REPL. 2019-05-22 12:47:48 +10:00
Damien George
456c89f749 nrf/uart: Make UART print output something, and add write method. 2019-05-22 12:47:48 +10:00
Damien George
50d5114fcd nrf/mpconfigport.h: Enable MICROPY_KBD_EXCEPTION by default. 2019-05-22 12:47:48 +10:00
Damien George
302ffdba7f nrf/uart: Change UART driver to be non-blocking and use IRQs.
As part of this, ctrl-C is now able to interrupt a running program.
2019-05-22 12:47:19 +10:00
Glenn Ruben Bakke
d80abd035e nrf/nrfx_glue: Adapt to nrfx v.1.7.1.
Defining NRFX_STATIC_ASSERT macro to be empty, but available
to nrfx.
2019-05-21 23:16:20 +02:00
Damien George
c769da1aaa stm32/i2c: Support setting the I2C TIMINGR value via keyword arg.
On MCUs that have an I2C TIMINGR register, this can now be explicitly set
via the "timingr" keyword argument to the I2C constructor, for both
machine.I2C and pyb.I2C.  This allows to configure precise timing values
when the defaults are inadequate.
2019-05-21 13:45:17 +10:00
Damien George
ddc657658a stm32/machine_i2c: Simplify ROM initialisation of static HW I2C objects. 2019-05-21 12:38:34 +10:00
Andrew Leech
ed2b6ea0a8 stm32/i2c: Make timeout for hardware I2C configurable.
Previously the hardware I2C timeout was hard coded to 50ms which isn't
guaranteed to be enough depending on the clock stretching specs of the I2C
device(s) in use.

This patch ensures the hardware I2C implementation honors the existing
timeout argument passed to the machine.I2C constructor.  The default
timeout for software and hardware I2C is now 50ms.
2019-05-21 12:20:19 +10:00
Damien George
647b27d028 zephyr/machine_i2c: Update to support new C-level I2C API. 2019-05-20 15:04:29 +10:00
Damien George
bb29bde102 nrf/machine/i2c: Update to support new C-level I2C API. 2019-05-20 15:04:29 +10:00
Damien George
38ac697b45 stm32/machine_i2c: Update to support new C-level I2C API. 2019-05-20 15:04:29 +10:00
Damien George
1f63e9b701 stm32/adc: Fix VBAT_DIV to be 4 for STM32F411.
Fixes issue #4794.
2019-05-20 14:37:28 +10:00
Damien George
653e1756c0 various: Update early copyright years to match actual edit history. 2019-05-17 18:06:11 +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
e1e3704aa1 stm32/modmachine: Create dedicated asm function to branch to bootloader.
Recent gcc versions (at least 9.1) give a warning about using "sp" in the
clobber list.  Such code is removed by this patch.  A dedicated function is
instead used to set SP and branch to the bootloader so the code has full
control over what happens.

Fixes issue #4785.
2019-05-17 17:20:43 +10:00
Damien George
0557f0b74b esp32/network_ppp: Add a timeout for closing PPP connection.
This also fixes deleting the PPP task, since eTaskGetState() never returns
eDeleted.

A limitation with this patch: once the PPP is deactivated (ppp.active(0))
it cannot be used again. A new PPP instance must be created instead.
2019-05-17 17:14:45 +10:00
Damien George
2630d3e51f esp32/machine_uart: Implement UART.deinit() method. 2019-05-15 17:01:54 +10:00
iabdalkader
746fcea7f8 stm32/boards/NUCLEO_H743ZI: Enable SPI3 on this board. 2019-05-15 16:08:10 +10:00
iabdalkader
1646eff864 stm32/irq: Fix IRQ_ENABLE_STATS stats config to work on all MCUs.
Only the M4 and M7 MCUs have an FPU and FPU_IRQn, and FPU_IRQn is not
always the last entry/IRQ number.
2019-05-15 16:04:01 +10:00
iabdalkader
07af74daef stm32/spi: Enable SPI IRQs and add IRQHandlers for H7 MCUs.
The H7 HAL uses SPI IRQs when the SPI is running in DMA mode.
2019-05-15 15:59:25 +10:00
iabdalkader
123c065131 stm32/dma: Always reset and configure the H7 DMA peripheral.
This is required for the H7 DMA to work.
2019-05-15 15:55:41 +10:00
stijn
90fae9172a py/objarray: Add support for memoryview.itemsize attribute.
This allows figuring out the number of bytes in the memoryview object as
len(memview) * memview.itemsize.

The feature is enabled via MICROPY_PY_BUILTINS_MEMORYVIEW_ITEMSIZE and is
disabled by default.
2019-05-14 17:15:17 +10:00
iabdalkader
7359a9e2f2 stm32/dma: Initialise all members of DMA structs for H7 MCUs. 2019-05-13 12:57:44 +10:00
Damien George
7e21cf723a nrf: Change types to size_t for all uses of mp_obj_str_get_data. 2019-05-13 12:39:56 +10:00
Damien George
8586afa6f5 esp32/modnetwork: Change type to size_t for uses of mp_obj_str_get_data. 2019-05-13 12:39:03 +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
Andrew Leech
29865e3e58 stm32/rtc: Allow overriding startup timeouts from mpconfigboard. 2019-05-09 12:08:43 +10:00
Elad Namdar
3f54462add unix/modusocket: Fix use of setsockopt in usocket.settimeout impl.
The original code called setsockopt(SO_RCVTIMEO/SO_SNDTIMEO) with NULL
timeout structure argument, which is an illegal usage of that function.
The old code also didn't validate the return value of setsockopt, missing
the bug completely.
2019-05-08 13:12:30 +10:00
Damien George
b8c74014e4 stm32/usbd_cdc_interface: Don't retransmit chars if USB is reconnected.
Before this change, if the USB was reconnected it was possible that some
characters in the TX buffer were retransmitted because tx_buf_ptr_out and
tx_buf_ptr_out_shadow were reset while tx_buf_ptr_in wasn't.  That
behaviour is fixed here by retaining the TX buffer state across reconnects.

Fixes issue #4761.
2019-05-08 12:45:24 +10:00
Damien George
97753a1bbc stm32: Move factory reset files and code to separate source file.
The new function factory_reset_make_files() populates the given filesystem
with the default factory files.  It is defined with weak linkage so it can
be overridden by a board.

This commit also brings some minor user-facing changes:

- boot.py is now no longer created unconditionally if it doesn't exist, it
  is now only created when the filesystem is formatted and the other files
  are populated (so, before, if the user deleted boot.py it would be
  recreated at next boot; now it won't be).

- pybcdc.inf and README.txt are only created if the board has USB, because
  they only really make sense if the filesystem is exposed via USB.
2019-05-07 13:59:51 +10:00
Damien George
34942d0a72 stm32/machine_uart: Change default UART timeout to 0, for non blocking.
It's more common to need non-blocking behaviour when reading from a UART,
rather than having a large timeout like 1000ms (the original behaviour).
With a large timeout it's 1) likely that the function will read forever if
characters keep trickling it; or 2) the function will unnecessarily wait
when characters come sporadically, eg at a REPL prompt.
2019-05-07 13:56:42 +10:00
Yonatan Goldschmidt
ef9843653b extmod/moducryptolib: Add AES-CTR support.
Selectable at compile time via MICROPY_PY_UCRYPTOLIB_CTR.  Disabled by
default.
2019-05-06 18:09:48 +10:00
Damien George
906fb89fd7 unix/coverage: Add test for printing literal % character. 2019-05-03 23:21:28 +10:00
Nguyen Hoan Hoang
9a6f6fd68d nrf/boards: Add support for BLYST Nano module based boards.
- IBK-BLYST-NANO: Breakout board
- IDK-BLYST-NANO: DevKit board with builtin IDAP-M CMSIS-DAP Debug JTAG,
  RGB led
- BLUEIO-TAG-EVIM: Sensor tag board (environmental sensor
  (T, H, P, Air quality) + 9 axis motion sensor)

Also, the LED module has been updated to support individual base level
configuration of each LED. If set, this will be used instead of the
common configuration, MICROPY_HW_LED_PULLUP. The new configuration,
MICROPY_HW_LEDX_LEVEL, where X is the LED number can be used to set
the base level of the specific LED.
2019-05-02 22:33:44 +02:00
Chris Mason
2a791170ce stm32/boards: Add NUCLEO_F413ZH board configuration.
The alternate function pin allocations are different to other NUCLEO-144
boards.  This is because the STM32F413 has a very high peripheral count:
10x UART, 5x SPI, 3x I2C, 3x CAN.  The pinout was chosen to expose all
these devices on separate pins except CAN3 which shares a pin with UART1
and SPI1 which shares pins with DAC.
2019-05-02 16:33:30 +10:00
Chris Mason
1b956ec817 stm32: Add support for F413 MCUs.
Includes:
- Support for CAN3.
- Support for UART9 and UART10.
- stm32f413xg.ld and stm32f413xh.ld linker scripts.
- stm32f413_af.csv alternate function mapping.
- startup_stm32f413xx.s because F413 has different interrupt vector table.
- Memory configuration with: 240K filesystem, 240K heap, 16K stack.
2019-05-02 16:26:53 +10:00
Damien George
a974f2dc6e stm32/flash: Fix bug computing page number for L432 page erase. 2019-05-02 14:53:26 +10:00
Damien George
3fbf32b947 stm32/powerctrl: Support changing frequency when HSI is clock source.
This patch makes pllvalues.py generate two tables: one for when HSI is used
and one for when HSE is used.  The correct table is then selected at
compile time via the existing MICROPY_HW_CLK_USE_HSI.
2019-05-02 13:00:00 +10:00
stijn
34a7d7ebeb unix/gcollect: Make sure stack/regs get captured properly for GC.
When building with link time optimization enabled it is possible both
gc_collect() and gc_collect_regs_and_stack() get inlined into gc_alloc()
which can result in the regs variable being pushed on the stack earlier
than some of the registers. Depending on the calling convention, those
registers might however contain pointers to blocks which have just been
allocated in the caller of gc_alloc(). Then those pointers end up higher on
the stack than regs, aren't marked by gc_collect_root() and hence get
sweeped, even though they're still in use.

As reported in #4652 this happened for in 32-bit msvc release builds:
mp_lexer_new() does two consecutive allocations and the latter triggered a
gc_collect() which would sweep the memory of the first allocation again.
2019-05-01 15:06:21 +10:00
Damien George
cbeac903e8 stm32/main: Increase default UART REPL rx buffer from 64 to 260 bytes.
This allows the UART to buffer at least 256 bytes (taking into account the
extra byte needed by the ring buffer, and word alignment).
2019-05-01 14:53:21 +10:00
Damien George
ff0306dfa5 stm32/usb: Remove mp_hal_set_interrupt_char now that it's reset at boot. 2019-05-01 13:08:05 +10:00
Krono
fbd4e61e57 esp32/machine_wdt: Add timeout arg to select interval, make WDT panic.
The machine.WDT() now accepts the "timeout" keyword argument to select the
WDT interval.  And the WDT is changed to panic mode which means it will
reset the device if the interval expires (instead of just printing an error
message).
2019-04-30 16:53:05 +10:00
Damien George
8031b7a25c stm32/powerctrl: Deselect PLLSAI as 48MHz src before turning off PLLSAI.
On the STM32F722 (at least, but STM32F767 is not affected) the CK48MSEL bit
must be deselected before PLLSAION is turned off, or else the 48MHz
peripherals (RNG, SDMMC, USB) may get stuck without a clock source.

In such "lock up" cases it seems that these peripherals are still being
clocked from the PLLSAI even though the CK48MSEL bit is turned off.  A hard
reset does not get them out of this stuck state.  Enabling the PLLSAI and
then disabling it does get them out.  A test case to see this is:

    import machine, pyb
    for i in range(100):
        machine.freq(122_000000)
        machine.freq(120_000000)
        print(i, [pyb.rng() for _ in range(4)])

On occasion the RNG will just return 0's, but will get fixed again on the
next loop (when PLLSAI is enabled by the change to a SYSCLK of 122MHz).

Fixes issue #4696.
2019-04-29 16:31:32 +10:00
Damien George
d1dea4f577 javascript/library: Print data as raw bytes to stdout so unicode works. 2019-04-28 22:39:41 +10:00
Damien George
bd6fed8201 javascript/Makefile: Fix unrepresentable float error by using clamp.
Otherwise converting large floats to ints will fail (as seen by the
builtin_float_hash.py test).
2019-04-28 22:17:42 +10:00
Damien George
93f5f80216 javascript: Pass (error) exit value out from script to process caller. 2019-04-28 22:16:27 +10:00
Damien George
bd0bacb637 javascript/library: Use Buffer.alloc() since new Buffer() is deprecated. 2019-04-28 22:14:28 +10:00
Andrew Leech
70a28e3ad9 stm32/usb: Add USB device mode for VCP+VCP without MSC.
Selectable via pyb.usb_mode('VCP+VCP').
2019-04-28 21:31:47 +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
f66c4cbfa6 stm32/usbdev: Make USB device descriptors at runtime rather than static. 2019-04-26 10:07:49 +10:00
Damien George
aa7b32c811 stm32/dac: Rework DAC driver to use direct register access.
This patch makes the DAC driver simpler and removes the need for the ST
HAL.  As part of it, new helper functions are added to the DMA driver,
which also use direct register access instead of the ST HAL.

Main changes to the DAC interface are:

- The DAC uPy object is no longer allocated dynamically on the heap,
  rather it's statically allocated and the same object is retrieved for
  subsequent uses of pyb.DAC(<id>).  This allows to access the DAC objects
  without resetting the DAC peripheral.  It also means that the DAC is only
  reset if explicitly passed initialisation parameters, like "bits" or
  "buffering".

- The DAC.noise() and DAC.triangle() methods now output a signal which is
  full scale (previously it was a fraction of the full output voltage).

- The DAC.write_timed() method is fixed so that it continues in the
  background when another peripheral (eg SPI) uses the DMA (previously the
  DAC would stop if another peripheral finished with the DMA and shut the
  DMA peripheral off completely).

Based on the above, the following backwards incompatibilities are
introduced:

- pyb.DAC(id) will now only reset the DAC the first time it is called,
  whereas previously each call to create a DAC object would reset the DAC.
  To get the old behaviour pass the bits parameter like: pyb.DAC(id, bits).

- DAC.noise() and DAC.triangle() are now full scale.  To get previous
  behaviour (to change the amplitude and offset) write to the DAC_CR (MAMP
  bits) and DAC_DHR12Rx registers manually.
2019-04-24 15:51:19 +10:00
Damien George
8402c26cfa stm32/powerctrl: Enable EIWUP to ensure RTC wakes device from standby. 2019-04-18 17:15:11 +10:00
Damien George
11657f2f20 stm32/system_stm32f0: Add support for using HSE and PLL as SYSCLK.
To configure the SYSCLK on an F0 enable one of:

    MICROPY_HW_CLK_USE_HSI48
    MICROPY_HW_CLK_USE_HSE
    MICROPY_HW_CLK_USE_BYPASS
2019-04-18 16:00:45 +10:00
Damien George
f1774fa049 stm32/system_stm32f0: Enable PWR clock on startup.
To be consistent with how F4/F7/H7/L4 works in system_stm32.c.  The power
control peripheral is needed at least for the RTC.
2019-04-18 15:36:59 +10:00
Damien George
4ce0091449 esp32/README: Add info about pyparsing and the correct Python version.
See issue #4655.
2019-04-18 14:17:01 +10:00