Commit Graph

1792 Commits

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