Commit Graph

1767 Commits

Author SHA1 Message Date
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