Wykres commitów

1653 Commity (master)

Autor SHA1 Wiadomość Data
Angus Gratton 801910fc83 all: Add missing imports for micropython.const.
Found by Ruff checking F821.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2023-08-16 16:13:27 +10:00
Jim Mussared 9573d31071 all: Remove query-variants make target.
This is difficult to implement on cmake-based ports, and having the list
of variants in mpconfigboard.{cmake,mk} duplicates information that's
already in board.json.

This removes the existing query-variants make target from stm32 & rp2
and the definition of BOARD_VARIANTS from the various board files.

Also renames the cmake variable to MICROPY_BOARD_VARIANT to match other
variables such as MICROPY_BOARD. The make variable stays as
BOARD_VARIANT.

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-08-15 17:37:44 +10:00
Jim Mussared 24a6e951ec ports: Simplify board feature tags in board.json.
This commit:
- Finds a common set of board feature tags and maps existing features to
  that reduced set.
- Removes some less-useful board feature tags.
- Ensures all MCUs are specified correctly.
- Ensures all boards have a vendor (and fixes some vendor names).

This is to make the downloads page show a less intimidating set of filters.

Work done in conjunction with Matt Trentini <matt.trentini@gmail.com>.

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-08-10 14:54:03 +10:00
Jim Mussared 975a687447 py/mpconfig: Add MICROPY_PY_PLATFORM, enabled at extra features level.
Previously this was explicitly enabled on esp32/stm32/renesas/mimxrt/samd,
but didn't get a default feature level because it wasn't in py/mpconfig.h.

With this commit it's now enabled at the "extra features" level, which adds
rp2, unix-standard, windows, esp8266, webassembly, and some nrf boards.

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-07-24 23:53:20 +10:00
Jim Mussared 3533924c36 extmod/moddeflate: Add deflate module providing the DeflateIO class.
This provides similar functionality to the former zlib.DecompIO and
especially CPython's gzip.GzipFile for both compression and decompression.

This class can be used directly, and also can be used from Python to
implement (via io.BytesIO) zlib.decompress and zlib.compress, as well as
gzip.GzipFile.

Enable/disable this on all ports/boards that zlib was previously configured
for.

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-07-21 19:32:40 +10:00
Jim Mussared e6c290c3d1 lib/uzlib: Add a source_read_data var to pass to source_read_cb.
For better abstraction for users of this API.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-07-21 19:29:34 +10:00
Jim Mussared d75a3cd861 lib/uzlib: Combine zlib/gzip header parsing to allow auto-detect.
This supports `wbits` values between +40 to +47.

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-07-21 19:29:34 +10:00
Jim Mussared c2b8e6e5d6 lib/uzlib: Clean up tinf -> uzlib rename.
This library used a mix of "tinf" and "uzlib" to refer to itself.  Remove
all use of "tinf" in the public API.

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-07-21 19:29:24 +10:00
Jim Mussared 198311c780 py/stream: Add mp_stream___exit___obj that calls mp_stream_close.
There are enough places that implement __exit__ by forwarding directly to
mp_stream_close that this saves code size.

For the cases where __exit__ is a no-op, additionally make their
MP_STREAM_CLOSE ioctl handled as a no-op.

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-07-21 18:49:03 +10:00
Jim Mussared add1200343 all: Remove the zlib module.
This will be replaced with a new deflate module providing the same
functionality, with an optional frozen Python wrapper providing a
replacement zlib module.

binascii.crc32 is temporarily disabled.

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-07-21 18:48:29 +10:00
Angus Gratton 4548928449 stm32/boards/B_L072Z_LRWAN1: Lower default ROM level to "Core".
Re-enable some features required for the board to still build and the lora
driver to run.

This board only has 192KB of flash total, so default stm32 build is very
close to the limit.

Before:

LINK build-B_L072Z_LRWAN1/firmware.elf
   text    data     bss     dec     hex filename
 184352      68   14112  198532   30784 build-B_L072Z_LRWAN1/firmware.elf

(12256 bytes free)

After:

LINK build-B_L072Z_LRWAN1/firmware.elf
   text    data     bss     dec     hex filename
 155028      68   14052  169148   294bc build-B_L072Z_LRWAN1/firmware.elf

(41580 bytes free)

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2023-07-20 21:48:10 +10:00
Angus Gratton 3aabdf2f6b stm32/boards/B_L072Z_LRWAN1: Add pin definitions for internal SX1262.
Includes fixing the SCK connection pin.

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2023-07-20 21:47:55 +10:00
Damien George 88771c1500 renesas-ra,stm32: Remove duplicate machine module from constants list.
In the u-module renaming done in 30628d1bb7,
these duplicate lines were accidentally left.

Signed-off-by: Damien George <damien@micropython.org>
2023-07-13 13:18:09 +10:00
Damien George 62673a7708 stm32/mpconfigport: Always define MICROPY_SOFT_TIMER_TICKS_MS.
Even if MICROPY_PY_MACHINE is disabled, the soft timer is still used.

Signed-off-by: Damien George <damien@micropython.org>
2023-07-13 13:10:31 +10:00
Victor Rajewski 730525cec9 stm32/qspi: Allow qspi_write_cmd_data to write cmd with 1 data byte.
The existing qspi for stm32 implementation can only send a spi command with
exactly 0 or 2 data bytes.  Certain spiflash chips (e.g. AT25SF321B) have
commands that only take a single data byte, and will ignore the command if
more than that is sent.  This commit allows sending a command with a single
data byte.

Signed-off-by: Victor Rajewski <victor@allumeenergy.com.au>
2023-07-13 12:49:51 +10:00
Yuuki NAGAO 409978a1fb stm32/adc: Fix pyb.ADCAll.read_core_bat on G4 and L4 MCUs.
Update adc_refcor before reading ADC_CHANNEL_VBAT because VREFINT_CAL is at
VDDA=3.0V.

Signed-off-by: Yuuki NAGAO <wf.yn386@gmail.com>
2023-07-13 12:40:55 +10:00
Yuuki NAGAO cb38f77918 stm32/adc: Add workaround for ADC errata with G4 MCUs.
For STM32G4, there is a errata on ADC that may get wrong ADC result.
According to the errata sheet, this can be avoid by performing two
consecutive ADC conversions and keep second result.

Signed-off-by: Yuuki NAGAO <wf.yn386@gmail.com>
2023-07-13 12:40:52 +10:00
Yuuki NAGAO 0a31b9bf78 stm32/machine_adc: Fix machine.ADC to work on G4 MCUs.
Signed-off-by: Yuuki NAGAO <wf.yn386@gmail.com>
2023-07-13 12:39:12 +10:00
Yuuki NAGAO d9764ad140 stm32/adc: Fix reading internal ADC channels on G4 MCUs.
For STM32G4 series, the internal sensors are connected to:
- ADC1_IN16: Temperature sensor
- ADC1_IN17: Battery voltage monitoring
- ADC1_IN18: Internal voltage reference
but ADC_CHANNEL_TEMPSENSOR_ADC1, ADC_CHANNEL_VBAT,
ADC_CHANNEL_VREFINT are not defined as 16, 17, 18.

This commit converts channel 16, 17, 18 to ADC_CHANNEL_x in
adc_get_internal_channel().

Signed-off-by: Yuuki NAGAO <wf.yn386@gmail.com>
2023-07-13 12:39:12 +10:00
Yuuki NAGAO 0ba94a67ba stm32/adc: Fix pyb.ADCAll.read_core_temp for G4 MCUs.
For STM32G4,
 * TS_CAL1 raw data acquired at a temperature of 30°C
 * TS_CAL2 raw data acquired at a temperature of 130°C
Also, these values are at VDDA=3.0V.

Signed-off-by: Yuuki NAGAO <wf.yn386@gmail.com>
2023-07-13 12:39:06 +10:00
Yuuki NAGAO de8035b510 stm32/adc: Fix ADC clock prescaler for G4 MCUs.
For STM32G4, ADC clock frequency should be equal or less than 60MHz.
To satisfy this specification, ADC clock prescaler should be equal or
greater than 4 (For example, NUCLEO_G474RE runs 170MHz).

In addition, to obtain accurate internal channel value,
the ADC clock prescaler is set to 16 because vbat needs at least 12us
(16/170*247.5=23.3us).

Signed-off-by: Yuuki NAGAO <wf.yn386@gmail.com>
2023-07-13 12:39:01 +10:00
Yuuki NAGAO ec9ea97413 stm32/dac: Fix dac.write_timed on G4 MCUs to use 32-bit DMA access.
For STMG4 MCUs, the peripheral registers for DAC have to be accessed by
words (32bits) because DAC is connected to AHB directly.

(This requirement is also there for other MCU series.  However, if DAC is
connected to APB like F4/L1/L4 MCUs, AHB byte or half-word transfer is
changed into a 32-bit APB transfer.  This means that PSIZE does not have to
be DMA_PDATAALIGN_WORD on these MCUs, and in fact must be BYTE/HALFWORD to
function correctly.)

Fixes issue #9563.

Signed-off-by: Yuuki NAGAO <wf.yn386@gmail.com>
2023-07-13 12:23:34 +10:00
Damien George 7bced2eaec stm32/modmachine: Make machine_reset_cause_obj public.
To match the other functions in the machine module, in particular so that
MICROPY_PY_MACHINE can be disabled without getting a compiler warning about
unused code.

Signed-off-by: Damien George <damien@micropython.org>
2023-07-11 13:45:53 +10:00
Tobias Thyrrestrup dd8de8b412 stm32/modmachine: Remove duplicate machine_timer_type declaration.
Signed-off-by: Tobias Thyrrestrup <tt@LEGO.com>
2023-07-11 12:34:51 +10:00
Yuuki NAGAO a2c02014cd stm32: Modify RCC->APB2ENR directly instead of HAL API.
Also, it is needed only when USB is enabled.

Signed-off-by: Yuuki NAGAO <wf.yn386@gmail.com>
2023-06-27 22:28:31 +09:00
Yuuki NAGAO 7ca3c1d892 stm32: Add USB support for STM32L1 MCUs.
Signed-off-by: Yuuki NAGAO <wf.yn386@gmail.com>
2023-06-27 22:28:31 +09:00
Jim Mussared 7979a4d267 ports: In machine_i2s.c, rename uasyncio to asyncio.
Mostly updates comments, but also renames the UASYNCIO enum value to
ASYNCIO.

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-06-19 18:36:54 +10:00
Jim Mussared 2fbc08c462 extmod/asyncio: Rename uasyncio to asyncio.
The asyncio module now has much better CPython compatibility and
deserves to be just called "asyncio".

This will avoid people having to write `from uasyncio import asyncio`.

Renames all files, and updates port manifests to use the new path. Also
renames the built-in _uasyncio to _asyncio.

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-06-19 17:33:03 +10:00
Damien George 6f74146bc1 stm32/boards/STM32H573I_DK: Add H5 board definition files.
Signed-off-by: Damien George <damien@micropython.org>
2023-06-15 11:09:37 +10:00
Damien George 56a22ddc8b stm32/octospi: Add preliminary support for OCTOSPI peripheral.
It currently operates in 1-line (SPI) mode only.

Signed-off-by: Damien George <damien@micropython.org>
2023-06-15 11:09:37 +10:00
Damien George ec4232b32e stm32/boards: Add ld, af.csv and hal_conf_base.h files for H5 MCUs.
Signed-off-by: Damien George <damien@micropython.org>
2023-06-15 11:09:37 +10:00
Damien George 61339aa506 stm32: Add initial support for H5 MCUs.
This commit adds initial support for STM32H5xx MCUs.  The following
features have been confirmed to be working on an STM32H573:
- UART over REPL and USB CDC
- USB CDC and MSC
- internal flash filesystem
- machine.Pin
- machine.SPI transfers with DMA
- machine.ADC
- machine.RTC
- pyb.LED
- pyb.Switch
- pyb.rng
- mboot

Signed-off-by: Damien George <damien@micropython.org>
2023-06-15 11:09:20 +10:00
Damien George f7f8332ddf stm32/machine_adc: Handle ADC resolution less than 8 bits on all MCUs.
All MCUs can have 6-bit resolution; see adc_cr_to_bits_table.

Signed-off-by: Damien George <damien@micropython.org>
2023-06-15 11:02:55 +10:00
Damien George 92d2de82e2 stm32/usbd_conf: Treat G0 USB periph as MICROPY_HW_USB_IS_MULTI_OTG=0.
The G0 USB peripheral behaves more like MICROPY_HW_USB_IS_MULTI_OTG=0 than
that config =1.  This fixes the configuration of the PMA FIFO buffers.

Signed-off-by: Damien George <damien@micropython.org>
2023-06-15 11:02:53 +10:00
Damien George b839acc7d9 stm32/main: Start UART REPL as early as possible.
For debugging purposes, to see output from other peripherals.

Also reset the pyb_stdio_uart state at the end of soft reset, in case it
points to a heap-allocated object.

Signed-off-by: Damien George <damien@micropython.org>
2023-06-15 11:02:49 +10:00
Damien George fb1bdf0ff2 stm32/make-stmconst.py: Support structs with names ending in _t.
Signed-off-by: Damien George <damien@micropython.org>
2023-06-15 11:02:41 +10:00
Damien George 68b09abc45 stm32/Makefile: Pass relevant CPU flags to assembler.
Needed for compiling gchelper_thumb2 on cortex-m33.

Signed-off-by: Damien George <damien@micropython.org>
2023-06-15 11:02:34 +10:00
Damien George f01d5fb657 py/mkrules.mk: Automatically configure frozen options when manifest set.
Following how mkrules.cmake works.  This makes it easy for a port to enable
frozen code, by defining FROZEN_MANIFEST in its Makefile.

Signed-off-by: Damien George <damien@micropython.org>
2023-06-08 23:12:56 +10:00
Damien George 30100e9b3d stm32/boards: Use default spibdev config where appropriate.
Signed-off-by: Damien George <damien@micropython.org>
2023-06-08 23:01:03 +10:00
Damien George 3b370157d0 stm32/mpconfigboard_common: Provide default spidev config.
Signed-off-by: Damien George <damien@micropython.org>
2023-06-08 23:01:03 +10:00
Jim Mussared a1fbb1980c extmod/modtimeq: Remove timeq module.
This is a MicroPython-specific module that existed to support the old
version of uasyncio.  It's undocumented and not enabled on all ports and
takes up code size unnecessarily.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-06-08 17:54:28 +10:00
Jim Mussared 5fd042e7d1 all: Replace all uses of umodule in Python code.
Applies to drivers/examples/extmod/port-modules/tools.

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-06-08 17:54:24 +10:00
Jim Mussared 2eba98f1e0 all: Use MP_REGISTER_EXTENSIBLE_MODULE for overrideable built-ins.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-06-08 17:54:21 +10:00
Jim Mussared 45ac651d1a all: Rename *umodule*.c to remove the "u" prefix.
Updates any includes, and references from Makefiles/CMake.

This essentially reverts what was done long ago in commit
136b5cbd76

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-06-08 17:54:17 +10:00
Jim Mussared 0ceccd4cf8 all: Rename *umodule*.h to remove the "u" prefix.
This work was funded through GitHub Sponsors.

Also updates #includes.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-06-08 17:54:14 +10:00
Jim Mussared f5f9edf645 all: Rename UMODULE to MODULE in preprocessor/Makefile vars.
This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-06-08 17:54:11 +10:00
Jim Mussared 7f5d5c7271 all: Rename mod_umodule*, ^umodule* to remove the "u" prefix.
This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-06-08 17:54:07 +10:00
Jim Mussared 1bf2dcb15e all: Rename mp_umodule*, mp_module_umodule* to remove the "u" prefix.
This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-06-08 17:54:04 +10:00
Jim Mussared 30628d1bb7 all: Rename MP_QSTR_umodule to MP_QSTR_module everywhere.
This renames the builtin-modules, such that help('modules') and printing
the module object will show "module" rather than "umodule".

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-06-08 17:53:57 +10:00
Damien George e4886dda85 stm32/help: Exclude legacy entries from help, and adjust constant names.
Signed-off-by: Damien George <damien@micropython.org>
2023-06-02 12:43:58 +10:00
Jim Mussared aac8744671 stm32/help: Don't include unavailable features in help().
This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-06-02 11:49:13 +10:00
Jim Mussared 1d4b4f0ce2 ports: Standardise docs link in help text.
Updates all `help()` output to use the phrase:
`For online docs please visit http://docs.micropython.org/`

Some ports previously used different wording, some pointed to the wrong
link.  Also make all ports use `help.c` for consistency.

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-06-02 11:48:46 +10:00
robert-hh 1c53bda27f ports: Remove os.sync() implementation from stm32 and renesas-ra.
Now that this code was moved to extmod/moduos.c.

Signed-off-by: robert-hh <robert@hammelrath.com>
2023-06-01 11:39:01 +10:00
Damien George b57b079bbe stm32/boards/NUCLEO_L4A6ZG: Add new board definition.
Signed-off-by: Damien George <damien@micropython.org>
2023-05-24 11:25:53 +10:00
Damien George 87cf439e0d stm32/adc: Add support for STM32L4A6 MCUs.
Signed-off-by: Damien George <damien@micropython.org>
2023-05-24 11:25:50 +10:00
Jim Mussared 0ba08e6299 stm32/boards/NUCLEO_G474RE: Make it easier to enable USB.
This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-05-24 11:13:23 +10:00
Jim Mussared f4b4d05e49 stm32/usb: Fix USB support on STM32G4.
Also fix MAX_ENDPOINT definition for G0, which follows G4.

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-05-24 11:12:45 +10:00
iabdalkader bfcaf39197 stm32/irq: Fix typo in comment about priorities.
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2023-05-19 22:23:33 +10:00
Andrew Leech f03ac04321 stm32/mboot: Fix alignment of packed final buffer.
Once all the firmware has been flashed and the final signatures checked,
mboot writes the "all good" byte into the header of the application.  This
step uses the buffer firmware_head which, if unaligned in the build, fails
when cast to a uint64_t* in flash.c.

Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
2023-05-19 22:16:53 +10:00
brave ulysses ad216be5f1 stm32/boards/stm32h723_af.csv: Fix ADC AF definitions.
These were incorrectly added in d995c01042.
The fix here includes the full differential ADC definitions.

Signed-off-by: brave ulysses <brave_ulysses@email.com>
2023-05-19 22:12:05 +10:00
Jim Lipsey 7333c06d05 stm32/boards/ARDUINO_PORTENTA_H7: Enable FDCAN.
Add pin definitions to enable FDCAN support using the pyb.CAN() class.
2023-05-09 13:25:03 +10:00
Christian Clauss 2a1db770ce all: Fix cases of Python variable assigned but never used.
This fixes ruff rule F841.
2023-05-02 16:36:05 +10:00
Christian Clauss 79e57473b2 all: Fix various Python coding inconsistencies found by ruff.
This fixes:
- type-comparison (E721): do not compare types, use isinstance().
- string-dot-format-missing-arguments (F524): .format call is missing
  argument(s) for placeholder(s): {message}.
- f-string-missing-placeholders (F541).
- is-literal (F632): Use != to compare constant literals.

The last one is fixed by just comparing for truthfulness of `state`.
2023-05-02 16:14:45 +10:00
Damien George b1229efbd1 all: Fix spelling mistakes based on codespell check.
Signed-off-by: Damien George <damien@micropython.org>
2023-04-27 18:03:06 +10:00
Damien George 996a1f911b stm32/modutime: Use extmod version of time module.
No API or functional change.

Signed-off-by: Damien George <damien@micropython.org>
2023-04-27 15:11:52 +10:00
Damien George 9955553001 extmod/modutime: Provide a generic time module.
Based on extmod/utime_mphal.c, with:
- a globals dict added
- time.localtime wrapper added
- time.time wrapper added
- time.time_ns function added

New configuration options are added for this module:
- MICROPY_PY_UTIME (enabled at basic features level)
- MICROPY_PY_UTIME_GMTIME_LOCALTIME_MKTIME
- MICROPY_PY_UTIME_TIME_TIME_NS

Signed-off-by: Damien George <damien@micropython.org>
2023-04-27 15:09:56 +10:00
Damien George 083dc1f082 ports: Use extmod version of mktime instead of port-specific one.
Apart from slight differences in the error message, the functionality of
all ports is unchanged.

Signed-off-by: Damien George <damien@micropython.org>
2023-04-27 14:55:07 +10:00
Damien George a14e79bcfb stm32/cyw43_configport: Provide cyw43_hal_pin_config_irq_falling func.
Signed-off-by: Damien George <damien@micropython.org>
2023-04-26 12:57:35 +10:00
Jim Mussared 256f47e2f8 extmod/btstack: Fix indicate/notify queuing.
This adds a mechanism to track a pending notify/indicate operation that
is deferred due to the send buffer being full. This uses a tracked alloc
that is passed as the content arg to the callback.

This replaces the previous mechanism that did this via the global pending
op queue, shared with client read/write ops.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-04-26 11:37:20 +10:00
Damien George 9e6885ad82 extmod/btstack: Switch to use hci_dump_init instead of hci_dump_open.
The latter is no longer available in the version of BTstack now in use by
this repository.

Signed-off-by: Damien George <damien@micropython.org>
2023-04-22 00:39:31 +10:00
David Grayson c046b23ea2 shared/runtime/pyexec: Don't allow Ctrl+C to interrupt frozen boot code.
Helps prevent the filesystem from getting formatted by mistake, among other
things.  For example, on a Pico board, entering Ctrl+D and Ctrl+C fast many
times will eventually wipe the filesystem (without warning or notice).

Further rationale: Ctrl+C is used a lot by automation scripts (eg mpremote)
and UI's (eg Mu, Thonny) to get the board into a known state.  If the board
is not responding for a short time then it's not possible to know if it's
just a slow start up (eg in _boot.py), or an infinite loop in the main
application.  The former should not be interrupted, but the latter should.
The only way to distinguish these two cases would be to wait "long enough",
and if there's nothing on the serial after "long enough" then assume it's
running the application and Ctrl+C should break out of it.  But defining
"long enough" is impossible for all the different boards and their possible
behaviour.  The solution in this commit is to make it so that frozen
start-up code cannot be interrupted by Ctrl+C.  That code then effectively
acts like normal C start-up code, which also cannot be interrupted.

Note: on the stm32 port this was never seen as an issue because all
start-up code is in C.  But now other ports start to put more things in
_boot.py and so this problem crops up.

Signed-off-by: David Grayson <davidegrayson@gmail.com>
2023-04-05 10:38:50 +10:00
Jan Hrudka 5652f1f661 stm32/flash: Fix get_bank function for STM32H750.
STM32H750 has only 1 flash bank so function get_bank should always return
FLASH_BANK_1.
2023-04-04 14:58:54 +10:00
Sebastian Romero 0a3600a9ad stm32/boards/ARDUINO_NICLA_VISION: Fix incorrect bootloader PID. 2023-03-31 17:11:14 +11:00
Damien George 31e7a0587d stm32/boards/NUCLEO_G0B1RE: Add config for USB and mboot.
But leave these disabled.

Signed-off-by: Damien George <damien@micropython.org>
2023-03-22 16:38:03 +11:00
Damien George 31638473b7 stm32/mboot: Add support for G0 MCUs.
Signed-off-by: Damien George <damien@micropython.org>
2023-03-22 16:38:03 +11:00
Damien George c7923b1139 stm32: Add support for USB on G0 MCUs.
Signed-off-by: Damien George <damien@micropython.org>
2023-03-22 16:38:03 +11:00
Damien George 051e2900d9 stm32/boards/NUCLEO_H723ZG: Add new H723 board.
The following have been tested and are working:
- 550MHz CPU frequency
- UART REPL via ST-Link
- USB REPL and mass storage
- 3x LEDs and 1x user button
- Ethernet

Signed-off-by: Damien George <damien@micropython.org>
2023-03-21 14:05:59 +11:00
Damien George d995c01042 stm32/boards: Add ld and af.csv for H723.
Signed-off-by: Damien George <damien@micropython.org>
2023-03-21 14:02:49 +11:00
Damien George 13fcd8440e stm32: Add support for STM32H723 MCUs.
Signed-off-by: Damien George <damien@micropython.org>
2023-03-21 14:02:49 +11:00
Damien George 3187e4c7e7 stm32/mphalport: Update HAL version to 1.11.0 to match stm32lib.
Signed-off-by: Damien George <damien@micropython.org>
2023-03-21 14:02:49 +11:00
Damien George 42511b5291 stm32/boards/NUCLEO_H743ZI2: Fix MCU tag in board.json file.
Signed-off-by: Damien George <damien@micropython.org>
2023-03-20 15:24:45 +11:00
iabdalkader a197823eb7 ports: Fix MCU tags in Arduino board.json files. 2023-03-20 15:22:24 +11:00
Christian Clauss 4376c969f6 all: Fix Python comparison to None and True, and use "not in".
These are basic PEP8 recommendations.
2023-03-10 13:32:24 +11:00
Damien George b3c8ab37ec py/gc: Make gc_dump_info/gc_dump_alloc_table take a printer as argument.
So that callers can redirect the output if needed.

Signed-off-by: Damien George <damien@micropython.org>
2023-03-10 10:58:10 +11:00
Damien George b336b6bb74 stm32/pybthread: Make pyb_thread_dump take a printer as its argument.
Signed-off-by: Damien George <damien@micropython.org>
2023-03-09 13:20:59 +11:00
Damien George 067c7cd9dc stm32/pin: Make pin_find debug output use mp_printf.
Signed-off-by: Damien George <damien@micropython.org>
2023-03-09 13:20:59 +11:00
Damien George f43c4dfc68 stm32/extint: Make ExtInt.regs print using mp_printf.
Signed-off-by: Damien George <damien@micropython.org>
2023-03-09 13:20:59 +11:00
Damien George f6a35f76af stm32/modmachine: Make machine.info print using mp_printf.
Signed-off-by: Damien George <damien@micropython.org>
2023-03-09 13:20:59 +11:00
Damien George 6c8b19c7e2 stm32/spi: Return error code and raise exception if SPI init fails.
Signed-off-by: Damien George <damien@micropython.org>
2023-03-09 12:47:45 +11:00
Damien George 98937dcfc2 stm32/i2c: Return error code and raise exception if I2C init fails.
Signed-off-by: Damien George <damien@micropython.org>
2023-03-09 12:47:45 +11:00
Damien George b981e37ccd stm32/main: Use mp_printf instead of printf for MPY start-up messages.
Signed-off-by: Damien George <damien@micropython.org>
2023-03-09 12:47:45 +11:00
Damien George b9dad0add2 stm32: Remove commented-out printf's and debugging code.
Signed-off-by: Damien George <damien@micropython.org>
2023-03-09 12:47:45 +11:00
iabdalkader 8307046406 stm32/boards: Include "senml" in manifest for ARDUINO boards. 2023-03-09 10:37:06 +11:00
Damien George a234aa44f3 stm32/powerctrl: Don't compile WB helpers on WL MCUs.
Signed-off-by: Damien George <damien@micropython.org>
2023-03-08 23:57:53 +11:00
Damien George 8b3f1d47a6 stm32/powerctrlboot: Provide custom SystemInit for WB55.
Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
Signed-off-by: Damien George <damien@micropython.org>
2023-03-08 14:04:14 +11:00
Andrew Leech c551723914 stm32/powerctrl: Disable WB55 BLE before entering deepsleep.
Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
2023-03-08 14:03:36 +11:00
Andrew Leech 2eca86e8fa stm32/powerctrl: Add sleep RCC semaphore management for WB55 MCUs.
Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
2023-03-08 11:33:00 +11:00
iabdalkader e764bf0138 stm32/cyw43_configport: Add cyw43_sdio_enable_high_speed_4bit function.
Needed by the latest version of cyw43-driver.
2023-03-08 00:59:36 +11:00
iabdalkader 40a49f5a7a stm32/boards/ARDUINO_GIGA: Add support for Arduino Giga H7 board. 2023-03-08 00:55:51 +11:00
iabdalkader b6904cba76 stm32/boards/ARDUINO_NICLA_VISION: Add support for Arduino Nicla Vision. 2023-03-08 00:55:38 +11:00
iabdalkader 449be91e1a stm32/Makefile: Include HAL HSEM driver on H747 MCUs. 2023-03-08 00:55:01 +11:00
iabdalkader d18de7ec81 stm32/boards/ARDUINO_PORTENTA_H7: Update board config files.
Changes are:
- Freeze micropython-lib time module to get strftime.
- Reserve the last 1MB of QSPI flash for (optional) WiFi firmware storage.
- Disable SD card mount on boot.
- Enable high-speed BLE firmware download.
2023-03-08 00:51:33 +11:00
iabdalkader 0f92954eee stm32/cyw43_configport: Allow boards to override default resource files. 2023-03-02 22:44:29 +11:00
iabdalkader e98d7ec804 stm32/boards/PYBD_SF2: Set CYW43 Bluetooth fimrware download baudrate. 2023-03-02 22:30:31 +11:00
iabdalkader 4937174b43 stm32/cyw43_configport: Fix build for boards without an RF switch.
Check if an RF switch is enabled before defining the RF switch pin.
2023-03-01 10:05:04 +11:00
Jim Mussared 7d40317a4a stm32: Add a default implementation of pyb.country.
This is for boards without networking support so that the default boot.py
continues to work.

Also update boot.py to use network.country and network.hostname instead.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-03-01 01:28:12 +11:00
Damien George 593375aa5d stm32/boards: Update linker scripts now that big_const is gone.
Signed-off-by: Damien George <damien@micropython.org>
2023-03-01 01:27:51 +11:00
Jim Mussared bad0098a49 stm32: Update to use the open-source lib version of cyw43-driver.
This removes the previous WiFi driver from drivers/cyw43 (but leaves behind
the BT driver), and makes the stm32 port (i.e. PYBD and Portenta) use the
new "lib/cyw43-driver" open-source driver already in use by the rp2 port.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-03-01 01:27:12 +11:00
Jim Mussared a377302623 extmod/modnetwork: Add network.hostname() and network.country().
This provides a standard interface to setting the global networking config
for all interfaces and interface types.

For ports that already use either a static hostname (mimxrt, rp2) they will
now use the configured value. The default is configured by the port
(or optionally the board).

For interfaces that previously supported .config(hostname), this is still
supported but now implemented using the global network.hostname.

Similarly, pyb.country and rp2.country are now deprecated, but the methods
still exist (and forward to network.hostname).

Because ESP32/ESP8266 do not use extmod/modnetwork.c they are not affected
by this commit.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-03-01 01:26:17 +11:00
Damien George 8d9a7fd228 stm32/Makefile: Clean up nested if-else to chained if-else-if.
Makefile's support "else ifdef", so use it to make the logic clearer.

Also dedent some associated lines for consistency.

Signed-off-by: Damien George <damien@micropython.org>
2023-02-23 10:14:04 +11:00
Jim Mussared 69b93527d5 ports: Make BOARD default from BOARD_DIR in Makefile's.
This allows:

    $ make BOARD_DIR=path/to/board

to infer BOARD=board, rather than the previous behavior that required
additionally setting BOARD explicitly.

Also makes the same change for VARIANT_DIR -> VARIANT on Unix.

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
Signed-off-by: Damien George <damien@micropython.org>
2023-02-23 09:47:08 +11:00
robert-hh de1f1dd164 shared/runtime/softtimer: Use consistently the same clock source.
Before, both uwTick and mp_hal_ticks_ms() were used as clock source.  That
assumes, that these two are synchronous and start with the same value,
which may be not the case for all ports.  If the lag between uwTick and
mp_hal_ticks_ms() is larger than the timer interval, the timer would either
rush up until the times are synchronous, or not start until uwTick wraps
over.

As suggested by @dpgeorge, MICROPY_SOFT_TIMER_TICKS_MS is now used in
softtimer.c, which has to be defined in a port's mpconfigport.h with
the variable that holds the SysTick counter.

Note that it's not possible to switch everything in softtimer.c to use
mp_hal_ticks_ms() because the logic in SysTick_Handler that schedules
soft_timer_handler() uses (eg on mimxrt) the uwTick variable directly
(named systick_ms there), and mp_hal_ticks_ms() uses a different source
timer.  Thus it is made fully configurable.
2023-02-16 12:59:48 +11:00
Jim Mussared 4eb72b34df stm32/boards/ARDUINO_PORTENTA_H7: Use default aioble.
The default now includes all sub-components (security, l2cap, etc)
and using the kwarg options is no longer supported.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-02-16 12:32:03 +11:00
iabdalkader e140c7d26a stm32/boards/ARDUINO_PORTENTA_H7: Fix macro value check for QSPI.
QSPI deepsleep should be enabled only when the internal flash storage is
not used.
2023-02-16 12:21:48 +11:00
Andrew Leech 75e7e7d034 stm32/boards/STM32F769DISC: Fix building with USE_QSPI_XIP=1.
Signed-off-by: Damien George <damien@micropython.org>
2023-02-16 12:04:29 +11:00
Jim Mussared 8b27482692 top: Update Python formatting to black "2023 stable style".
See https://black.readthedocs.io/en/stable/the_black_code_style/index.html

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-02-02 12:51:03 +11:00
Damien George fe2a8332ff stm32/boards/NUCLEO_H743ZI2: Refer to NUCLEO_H743ZI for frozen manifest.
Fixes build issue introduced by 6250337c9c

Signed-off-by: Damien George <damien@micropython.org>
2023-02-01 23:22:18 +11:00
Jim Mussared 6250337c9c ports: Make all network-capable boards use bundle-networking.
This will ensure that any board with networking support gets:
 - webrepl
 - mip
 - urequests
 - ntptime

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-02-01 12:42:06 +11:00
David Lechner 3446d440f6 shared/runtime/gchelper: Drop cpu directive from ARM asm helpers.
This drops the `.cpu` directive from the ARM gchelper_*.s files.  Having
this directive breaks the linker when targeting older CPUs (e.g. `-mthumb
-mthumb-interwork` for `-mcpu=arm7tdmi`).  The actual target CPU should be
determined by the compiler options.

The exact CPU doesn't actually matter, but rather the supported assembly
instruction set.  So the files are renamed to *_thumb1.s and *thumb2.s to
indicate the instruction set support instead of the CPU support.

Signed-off-by: David Lechner <david@pybricks.com>
2023-01-28 15:51:38 +11:00
iabdalkader 3b5cafc716 stm32/Makefile: Leave DFU mode after download when using dfu-util.
Not all DFU bootloaders exit after download, this modifier is required for
some boards to reset, otherwise they sit idle in DFU mode.
2023-01-19 16:23:22 +11:00
Andrew Leech fa57ee971b stm32/boards: Consolidate linker snippets to reduce duplication.
This commit uses the REGION_ALIAS GNU linker command to simplify the linker
snippets and consolidate the duplication.

Signed-off-by: Damien George <damien@micropython.org>
2023-01-13 15:14:26 +11:00
Damien George bb77c1d5a3 stm32/powerctrl: Fix build on STM32G0xx and STM32H7Bx MCUs.
STM32G0xx doesn't have DBGMCU, and STM32H7Bx doesn't have EXTI_D2.

Signed-off-by: Damien George <damien@micropython.org>
2022-12-16 16:48:59 +11:00
Jim Mussared 5f8f32f917 extmod/modnetwork: Use a type protocol to implement NIC functions.
This was previously implemented by adding additional members to the
mp_obj_type_t defined for each NIC, which is difficult to do cleanly with
the new object type slots mechanism. The way this works is also not
supported on GCC 8.x and below.

Instead replace it with the type protocol, which is a much simpler way of
achieving the same thing.

This affects the WizNet (in non-LWIP mode) and Nina NIC drivers.

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-12-15 17:40:06 +11:00
brave ulysses 7f71057a89 stm32/boards/NUCLEO_F756ZG: Add board definition for NUCLEO-F756ZG.
Signed-off-by: Damien George <damien@micropython.org>
2022-12-15 14:59:26 +11:00
iabdalkader 5b7f71882b stm32/powerctrl: Improve standby mode entry code for H7 MCUs.
Changes in this commit:
- Clear and mask D2 EXTIs.
- Set correct voltage scaling level for standby mode.
- Disable debug MCU (if debugging is disabled), for all MCU series.
2022-12-15 14:39:28 +11:00
Dale Weber f2de289ef3 stm32/boards/NUCLEO_F429ZI: Enable I2C1 and I2C2 with default pins.
The datasheet on page 55 shows PF0 (SDA) and PF1 (SCL) are the pins for
I2C2, but these pins do not work.  Checking the MBED pinout for the
NUCLEO-F429ZI shows:

    I2C1: PB8 (SCL) and PB9 (SDA).
    I2C2: PB10 (SCL) and PB11 (SDA).

Both of these work and can be scanned and find devices connected to them.

Signed-off-by: Dale Weber <hybotics.sd@gmail.com>.
2022-12-13 17:35:55 +11:00
Damien George b042fd5120 drivers/bus: Change QSPI read_cmd signature to return an error code.
Signed-off-by: Damien George <damien@micropython.org>
2022-12-09 13:25:18 +11:00
Andrew Leech 7ee5afe8d1 drivers/bus: Detect QSPI transfer errors and pass up to spiflash driver.
This changes the signatures of QSPI write_cmd_data, write_cmd_addr_data and
read_cmd_qaddr_qdata so they return an error code.  The softqspi and stm32
hardware qspi driver are updated to follow this new signature.  Also the
spiflash driver is updated to use these new return values.

Signed-off-by: Damien George <damien@micropython.org>
2022-12-09 13:25:18 +11:00
iabdalkader fb7d211530 stm32/boards: Add missing LPUART macros for H7 HAL.
The STM32H7xx HAL LPUART AF macros are missing the number, this HAL is the
only one that's inconsistent in the way it defines LPUART AF macros, so we
only need to define them for H7.
2022-12-01 15:35:07 +11:00
Damien George 771c16f3d9 stm32/mboot: Make all mboot sectors erase/write protected.
Prior to this commit, only sector 0 was erase/write protected, which may
not be enough to protect all of mboot (especially if mboot lives at a
higher address than the start of flash).

This commit makes sure all internal flash sectors that mboot lives in are
protected from erasing and writing.  The linker script must define
_mboot_writable_flash_start for this to work.

Signed-off-by: Damien George <damien@micropython.org>
2022-11-30 17:19:36 +11:00
yn386 e18e47fa81 stm32/i2c: Add hardware I2C implementation for STM32L4.
For STM32L4, hardware I2C can be implemented by using TIMINGR.
This commit enables:
- Use of hardware I2C in machine.I2C.
- Specifying a frequency greater than or equal to 400KHz with pyb.I2C.
2022-11-18 15:01:13 +11:00
yn386 d0bea69c5e stm32/i2c: Add hardware I2C implementation for STM32L1.
For STM32L1, hardware I2C can be implemented the same as STM32F4 for
machine.I2C.

Tested on NUCLEO-L152RE.
2022-11-18 14:48:49 +11:00
yn386 f6b5d1838b stm32/adc: Fix ADCAll.read_core_temp() on L4 MCUs.
TS_CAL1 and TS_CAL2 of STM32L4 are at VDDA=3.0V, so the reference
correction factor should be updated before reading tempsensor.
2022-11-18 14:46:14 +11:00
yn386 2154ee2163 stm32/adc: Fix reading internal ADC channels on L4 MCUs.
For STM32L4 series, the internal sensors are connected to:
- ADC1_IN0: Internal voltage reference
- ADC1_IN17: Temperature sensor
- ADC1_IN18: VBAT battery voltage monitoring
but ADC_CHANNEL_VREFINT, ADC_CHANNEL_VBAT, ADC_CHANNEL_TEMPSENSOR are not
defined as 0, 17, 18.

This commit converts channel 0, 17, 18 to ADC_CHANNEL_x in
adc_get_internal_channel().
2022-11-18 14:38:58 +11:00
yn386 a74e4fabeb stm32/i2c: Fix I2C frequency calc so it doesn't exceed requested rate.
Prior to this commit, the actual I2C frequency can be faster than specified
one and it may exceed the I2C's specification for Fast Mode.  The frequency
of SCL should be less than or equal to 400KHz in Fast Mode.

This commit fixes this issue for F4 MCUs by rounding up the division in the
frequency calculation.
2022-11-18 14:25:19 +11:00
yn386 65d82066a8 stm32/pyb_i2c: Fix failing pyb.I2C(dma=True) after receiving 1 byte.
Excuting the code:

    i2c = I2C(1, I2C.CONTROLLER, dma=True)
    tmp = i2c.recv(1, i2c_addr)
    recv_data = bytearray(56)
    i2c.recv(recv_data, i2c_addr)

The second i2c.recv() fails with OSError: [Errno 110] ETIMEDOUT.  When
receiving greater than or equal to 2 bytes at first i2c.recv(), the second
i2c.recv() succeeds.  This issue does not occur without DMA.

Details of change: when executing I2C with DMA:

- Bit 11 of I2Cx_CR2 (DMA Request Enable) should be 1 to indicate that DMA
  transfer is enabled.  This bit is set after I2C event interrupt is
  enabled in HAL_I2C_Master_Transmit_DMA()/HAL_I2C_Master_Receive_DMA(), so
  DMA Request Enable bit might be 0 in IRQHandler.

- In case of data receive:
    - When only 1 byte receiption, clear I2Cx_CR1's bit 10 (ACK).
    - When only 2 byte receiption, clear I2Cx_CR1's bit 10 (ACK) and set
      bit 11 (POS).
    - When greater than or equal to 2 byte receiption, bit 12 of I2Cx_CR2
      (DMA Last Transfer) should set to generate NACK when DMA transfer
      completed.

Otherwise, the I2C bus may be busy after received data from peripheral.
2022-11-18 13:55:14 +11:00
Jim Mussared 5ef3aec33c stm32/Makefile: Set MPY_CROSS_FLAGS based on MCU type.
Previously it was hardcoded to armv7m, which would have failed on M0/M0+.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-11-17 22:10:41 +11:00
Koen De Vleeschauwer e7875829c2 stm32/usbd_desc: Support USB strings on CDC interface descriptors.
A board can now name the CDC ports, eg:

    #define MICROPY_HW_USB_CDC_NUM                  (3)
    #define MICROPY_HW_USB_INTERFACE_CDC0_STRING    "REPL"
    #define MICROPY_HW_USB_INTERFACE_CDC1_STRING    "GDB Server"
    #define MICROPY_HW_USB_INTERFACE_CDC2_STRING    "UART Port"

Signed-off-by: Damien George <damien@micropython.org>
2022-11-15 16:23:42 +11:00
iabdalkader 8ddb4567ff stm32/boards/ARDUINO_PORTENTA_H7: Add more modules, I2C1 and SE pin.
Changes in this commit are:
- Increase CDC buffer size.
- Define I2C1 SCL/SDA pins.
- Add crypto device enable pin to board pins.
- Update deploy instructions.
- Add ntptime, urequests and logging to manifest.
2022-11-14 18:59:17 +11:00
Angus Gratton b3e38ac632 stm32/spi: Downgrade SPIHandle definitions to static.
Seems unused outside of spi.c, spi_obj[] array is the expected way to
iterate these.

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2022-11-11 13:23:24 +11:00
iabdalkader 71881116e6 extmod/extmod.mk: Set default mbedtls config file in extmod Makefile. 2022-11-09 18:43:13 +01:00
robert-hh 2426ddb575 stm32/modmachine: Move dht_readinto() to the machine module. 2022-11-09 15:57:46 +11:00
iabdalkader ebb1a4ecb0 stm32/boards/ARDUINO_PORTENTA_H7: Add custom mbedtls config. 2022-11-08 23:46:06 +11:00
iabdalkader d2c2846820 stm32/Makefile: Allow overriding the default MBEDTLS_CONFIG_FILE. 2022-11-08 23:43:43 +11:00
iabdalkader efe7dac0aa stm32/mbedtls: Enable mbedtls certificate time validation.
This is a reimplementation of b560b9fe71 for
the stm32 port.
2022-11-08 23:41:03 +11:00
Damien George cd35b8a2a3 extmod/machine_timer: Move stm32's implementation of machine.Timer here.
So it can be reused by other ports.

Signed-off-by: Damien George <damien@micropython.org>
2022-10-27 14:32:43 +11:00
Jim Mussared 5ee1cb2771 stm32/boards/ARDUINO_PORTENTA_H7: Revert to single-precision float.
Using repr C is incompatible with double-precision floats on 32-bit arch.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-10-25 14:46:04 +11:00
Damien George 8874a09119 extmod/mbedtls: Enable elliptic curve DH and DSA cryptography.
This is necessary to access sites that only support these protocols.

The rp2 port already has ECDH enabled, so this just adds ECDSA there.  The
other ports now gain both ECDH and ECDSA.  The code size increase is:

- rp2 (PICO_W): +2916 bytes flash, +24 bytes BSS
- stm32 (PYBD_SF6): +20480 bytes flash, +32 bytes data, +48 bytes BSS
- mimxrt (TEENSY41): +20708 bytes flash, +32 bytes data, +48 bytes BSS
- unix (standard x86-64): +39344 executable, +1744 bytes data, +96 BSS

This is obviously a large increase in code size.  But there doesn't seem to
be any other option because without elliptic curve cryptography devices are
partially cut off from the internet.  For use cases that require small
firmware size, they'll need to build custom firmware with a custom mbedtls
config.

Signed-off-by: Damien George <damien@micropython.org>
2022-10-22 19:08:21 +11:00
Damien George 9347545f9e extmod/mbedtls: Enable MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_KEY_EXCHANGE.
This was already enabled on all ports except mimxrt.  Now it's enabled on
all of them.

Signed-off-by: Damien George <damien@micropython.org>
2022-10-22 19:06:21 +11:00
Damien George b337678964 extmod/mbedtls: Add common configuration file, and use it in all ports.
This is a no-op change.

Signed-off-by: Damien George <damien@micropython.org>
2022-10-22 19:06:21 +11:00
Damien George 67f98ba10c extmod/btstack: Update BTstack bindings to work with latest BTstack.
The following multi-tests pass (eg with PYBD_SF6+LEGO_HUB_NO6):

    ble_gap_advertise.py
    ble_gap_connect.py
    ble_gap_device_name.py
    ble_gattc_discover_services.py
    ble_gatt_data_transfer.py
    perf_gatt_char_write.py
    perf_gatt_notify.py
    stress_log_filesystem.py

These are the same tests that passed prior to this BTstack update.

Also tested on the unix port using H4 transport.

Signed-off-by: Damien George <damien@micropython.org>
2022-10-22 14:28:25 +11:00
iabdalkader af4ba6d1b4 stm32: Rename machine I2C and SPI types consistently across ports.
This renames:
- machine_hard_i2c_type -> machine_i2c_type
- machine_hard_spi_type -> machine_spi_type
2022-10-22 12:54:42 +11:00
Jim Mussared d6d8722558 extmod: Make extmod.mk self-contained.
This makes it so that all a port needs to do is set the relevant variables
and "include extmod.mk" and doesn't need to worry about adding anything to
OBJ, CFLAGS, SRC_QSTR, etc.

Make all extmod variables (src, flags, etc) private to extmod.mk.

Also move common/shared, extmod-related fragments (e.g. wiznet, cyw43,
bluetooth) into extmod.mk.

Now that SRC_MOD, CFLAGS_MOD, CXXFLAGS_MOD are unused by both extmod.mk
(and user-C-modules in a previous commit), remove all uses of them from
port makefiles.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-10-11 23:31:49 +11:00
Jim Mussared 87011f6353 extmod/extmod.mk: Make extmod.mk handle GIT_SUBMODULES.
This applies to nimble, btstack, axtls, mbedtls, lwip.

Rather than having the ports individually manage GIT_SUBMODULES for these
components, make extmod.mk append them when the relevant feature is
enabled.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-10-11 23:29:09 +11:00
Jim Mussared 3cc6decfc4 py/py.mk: Make user-C-module handling self-contained in py.mk.
Removes the need for the port to add anything to OBJS or SRC_QSTR.

Also makes it possible for user-C-modules to differentiate between code
that should be processed for QSTR vs other files (e.g. helpers and
libraries).

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-10-11 23:23:18 +11:00
Jim Mussared 67d05ed02b ports: Make generated pin.c handling more consistent across ports.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-10-11 23:18:46 +11:00
Jim Mussared 17f2783e4a all: Use += rather than = everywhere for CFLAGS/LDFLAGS/LIBS.
This avoids a surprise where an = can cancel out an earlier +=.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-10-11 23:17:41 +11:00
yn386 e6d3513187 stm32/boards/NUCLEO_L152RE: Add NUCLEO-L152RE board support.
This change adds NUCLEO-L152RE support to the STM32 port.
NUCLEO-L152RE: https://www.st.com/en/evaluation-tools/nucleo-l152re.html
This board use STM32L152RE:
https://www.st.com/en/microcontrollers-microprocessors/stm32l152re.html
2022-09-25 23:56:41 +10:00
yn386 427d72667f stm32: Add support for STM32L1 MCUs.
This change adds STM32L1 support to the STM32 port.
2022-09-25 23:56:41 +10:00
Jatty_ 30e50ab195 stm32/make-stmconst.py: Support TypeDef's with a single char prefix.
Update the regex to support parsing files from the STM32CubeU5 library.
2022-09-23 16:09:38 +10:00
Jim Mussared 94beeabd2e py/obj: Convert make_new into a mp_obj_type_t slot.
Instead of being an explicit field, it's now a slot like all the other
methods.

This is a marginal code size improvement because most types have a make_new
(100/138 on PYBV11), however it improves consistency in how types are
declared, removing the special case for make_new.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-09-19 19:06:15 +10:00
Jim Mussared 6da41b5900 py/obj: Merge getiter and iternext mp_obj_type_t slots.
The goal here is to remove a slot (making way to turn make_new into a slot)
as well as reduce code size by the ~40 references to mp_identity_getiter
and mp_stream_unbuffered_iter.

This introduces two new type flags:
- MP_TYPE_FLAG_ITER_IS_ITERNEXT: This means that the "iter" slot in the
  type is "iternext", and should use the identity getiter.
- MP_TYPE_FLAG_ITER_IS_CUSTOM: This means that the "iter" slot is a pointer
  to a mp_getiter_iternext_custom_t instance, which then defines both
  getiter and iternext.

And a third flag that is the OR of both, MP_TYPE_FLAG_ITER_IS_STREAM: This
means that the type should use the identity getiter, and
mp_stream_unbuffered_iter as iternext.

Finally, MP_TYPE_FLAG_ITER_IS_GETITER is defined as a no-op flag to give
the default case where "iter" is "getiter".

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-09-19 19:06:13 +10:00
Jim Mussared 9dce82776d all: Remove unnecessary locals_dict cast.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-09-19 19:06:01 +10:00
Jim Mussared 662b9761b3 all: Make all mp_obj_type_t defs use MP_DEFINE_CONST_OBJ_TYPE.
In preparation for upcoming rework of mp_obj_type_t layout.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-09-19 19:06:01 +10:00
Jim Mussared 6e75d177e7 stm32/boards/PYB: Fix handling of BOARD_VARIANT selection.
The matches should not have been quoted.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-09-08 14:54:48 +10:00
Jim Mussared d84c6ef0e8 ports: Use micropython-lib version of drivers in manifests. 2022-09-08 11:27:05 +10:00
yn386 719dbbf563 stm32/boards: Add alternate function list for STM32F446RE.
Signed-off-by: Damien George <damien@micropython.org>
2022-09-06 16:55:24 +10:00
yn386 989b8c728b stm32/timer: Fix use of timer channel callback() method on L4 MCUs.
Since L4 HAL version 1.17.0, HAL_TIM_IC_Start_IT() checks whether specified
channel of timer is busy or not, which is the case if this function is
called more than once without first calling HAL_TIM_IC_Stop_IT().  The fix
in this commit is to call the stop function before calling start.  The PWM
and OC modes have the same issue with the same fix.

Fixes issue #8732.
2022-09-06 16:35:46 +10:00
yn386 da50827657 stm32/pyb_i2c: Fix pyb.I2C to work with dma=True on F4 MCUs.
Prior to this commit, excuting this code:

    i2c = I2C(1, I2C.CONTROLLER, dma=True)
    i2c.send(data, addr=i2c_addr)

the call to i2c.send() does not return and the board needs a reset.  This
code works when dma=False.

According to the specification, I2Cx_EV_IRQHandler should:
- Write DR to address when Start condition generated.
- Clear ADDR by reading SR2 after reading SR2 when address sent.

These processes are included in HAL_I2C_EV_IRQHandler(), however the
firmware size increses about 2KB if HAL_I2C_EV_IRQHandler is called.  This
commit adds above processes to i2c_ev_irq_handler, and increases firmware
by less than 100 bytes.

Fixes issue #2643.
2022-09-06 16:13:47 +10:00
yn386 8770cd2f4d stm32/adc: Make ADCAll.read_channel reject invalid channels.
pyb.ADC(channel) checks whether specified channel is valid or have ADC
capability but pyb.ADCAll().read_channel() does not.

This change adds checking whether specified channel is valid and throw
ValueError if channel is invalid.  This is same as pyb.ADC().
2022-09-06 15:22:16 +10:00
Damien George 4e4c28bf27 stm32/boards: Only freeze LCD160CR driver in PYB board firmware.
Although this driver and associated hardware can be used on any board, it
makes to only freeze it for PYB and PYBD boards.  It can be easily copied
to any board if needed.

Fixes issue #8056.

Signed-off-by: Damien George <damien@micropython.org>
2022-09-06 12:53:46 +10:00
Jim Mussared fb20dbe4d1 stm32/boards/LEGO_HUB_NO6: Update manifest to new format.
This was added after 203dae41f and missed in the rebase.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-09-06 10:57:33 +10:00
Jim Mussared 203dae41fb all: Update all manifest.py files to use new features.
Changes in this commit:
- Manifest include's now use the directory path where possible (no longer
  necessary to include the manifest.py file explicitly).
- Add manifest.py for all drivers and components that are referenced by
  port/board manifests.
- Replace all uses of freeze() with package()/module(), except for port and
  board modules.
- Use opt=3 everywhere, for consistency and to reduce code size.
- Use require() instead of include() for all micropython-lib references.
- Remove support for optional board-level manifest.py in mimxrt port, to
  make it behave the same as other ports (the board must set
  FROZEN_MANIFEST to a custom manifest.py, which can optionally include the
  default, port-level manifest).
- Also reinstates modules that were accidentally removed from the esp8266
  512k build in fbe9417b90.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
Signed-off-by: Damien George <damien@micropython.org>
2022-09-05 18:43:18 +10:00
robert-hh 8ea6fefc6d stm32/machine_uart: Implement uart.flush() and uart.txdone().
Since uart.write() of the STM32 port waits until all bytes have
been sent, uart.flush() and uart.txdone() are implemented as empty
functions to provide API consistency.

uart.flush()

flush() will always return immediately.

ret = uart.txdone()

uart.txdone() will always return True.
2022-08-31 00:18:35 +10:00
Jim Mussared 8a0ee5a5c0 py/objstr: Split mp_obj_str_from_vstr into bytes/str versions.
Previously the desired output type was specified.  Now make the type part
of the function name.  Because this function is used in a few places this
saves code size due to smaller call-site.

This makes `mp_obj_new_str_type_from_vstr` a private function of objstr.c
(which is almost the only place where the output type isn't a compile-time
constant).

This saves ~140 bytes on PYBV11.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-08-26 16:43:55 +10:00
Damien George 1855df6361 stm32: Remove support for CC3000 WiFi driver.
It has been about 8 years since support for this chip was added.  Reasons
to remove it are:
- It is no longer easy to obtain this part.
- There are now many other options for WiFi.
- It's not a good use of developer time to maintain it.

Signed-off-by: Damien George <damien@micropython.org>
2022-08-26 12:51:37 +10:00
Jim Mussared 986ad6bf1d stm32/boardctrl: Use HAL_Delay instead of mp_hal_delay_ms.
Not safe to use mp_hal_delay_ms before boot if threading is enabled,
because threading will not have been initialised, and
MICROPY_EVENT_POLL_HOOK assumes threading is initialised.

HAL_Delay doesn't call MICROPY_EVENT_POLL_HOOK, but is still
power-efficient like mp_hal_delay_ms (unlike mp_hal_delay_us).

Fixes #7816.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-08-26 12:48:04 +10:00
Jim Mussared 492ba5eaf2 stm32: Move board variant config to mpconfigboard.mk.
Rather than having the autobuild know about the particular variants, have
the mpconfigboard.mk describe them and make autobuild discover them
automatically.

Adds a "query-variants" target to stm32/Makefile to allow the set of
possible variants to be queried.

Removes pybv3 from the autobuild as this isn't use by the downloads page.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-08-26 09:38:38 +10:00
Andrew Leech 923375380b stm32/boards: Increase mboot region to 32k for WB55 boards.
If mboot is built with support for packing (signing/encryption) it needs up
to 32KiB.  So for simplicity increase the mboot region to 32KiB
unconditionally for WB55 boards (custom WB55 board configurations can still
provide their own linker scripts to override this).
2022-08-25 17:02:56 +10:00
Damiano Mazzella 1fbf0efaeb stm32/sdram: Enable MPU for unaligned access on H7 MCUs.
So that SDRAM can be used as the heap on ARDUINO_PORTENTA_H7, for example.

Fixes issue #9087.
2022-08-25 16:20:51 +10:00
robert-hh 54eaa8c8a6 stm32/mphalport: Add mp_hal_get_spi_obj() helper function.
The function spi_from_mp_obj() is kept since it is used by the cc3k driver.
2022-08-23 14:59:48 +10:00
robert-hh c3305c49e4 stm32: Add definitions required for lwIP version of Wiznet NIC. 2022-08-23 14:58:13 +10:00
robert-hh 717924001d stm32: Switch Wiznet to use lib/wiznet5k and extmod/network_wiznet5k.
Instead of the old Wiznet driver in drivers/wiznet5k.
2022-08-23 14:57:54 +10:00
Damien George 8f4c108025 all: Remove MICROPY_PY_IO_FILEIO config option.
Since commit e65d1e69e8 there is no longer an
io.FileIO class, so this option is no longer needed.

This option also controlled whether or not files supported being opened in
binary mode (eg 'rb'), and could, if disabled, lead to confusion as to why
opening a file in binary mode silently did the wrong thing (it would just
open in text mode if MICROPY_PY_IO_FILEIO was disabled).

The various VFS implementations (POSIX, FAT, LFS) were the only places
where enabling this option made a difference, and in almost all cases where
one of these filesystems were enabled, MICROPY_PY_IO_FILEIO was also
enabled.  So it makes sense to just unconditionally enable this feature
(ability to open a file in binary mode) in all cases, and so just remove
this config option altogether.  That makes configuration simpler and means
binary file support always exists (and opening a file in binary mode is
arguably more fundamental than opening in text mode, so if anything should
be configurable then it should be the ability to open in text mode).

Signed-off-by: Damien George <damien@micropython.org>
2022-08-18 11:54:17 +10:00
Angus Gratton a16a330da5 nrf,stm32: Don't enable debug info by default if LTO is on.
It seems sometimes gcc with LTO will generate otherwise valid assembly
listings that cause 'as' to error out when generating DWARF debug info; see
https://sourceware.org/bugzilla/show_bug.cgi?id=29494

Therefore, don't enable -g by default if LTO is on.

Enabling LTO=1 DEBUG=1 is still possible but may result in random errors
at link time due to 'as' (the error in this case is "Error: unaligned
opcodes detected in executable segment", and the only other easy workaround
is CFLAGS+=-fno-jump-tables which may increase code size significantly).

Follows on from fdfe4eca74
2022-08-15 22:55:34 +10:00
Andrew Leech 6804b6f54f stm32/boards/NUCLEO_WB55: Add error handling to firmware update scripts.
In-the-field use of these FUS/WS firmware update scripts has exposed some
weak points, causing corrupted FUS/WS firmware to be flashed to the unit.

The problems are mostly caused with the ST GUI application, but sometimes
from un-recognised failures during bin file transfer to the WB55 prior to
running the rfcore_firmware.py script.  Other failures were caused by
incorrect load addresses being used, again both from user error copying the
address from the HTML release notes to the GUI tool, but also from
similarly not updating the address correctly in rfcore_firmware.py

To guard against these errors and make it easier to prepare different
versions, this commit adds a few features to the rfcore firmware update
tools:
- When creating the bin file, automatically parse the release note in the
  folder to get the correct address.
- Add a footer to the bin file containing the name, version, CRC, address
  etc.
- Before flashing rfcore, check if the same version is already installed.
- Verify the CRC and obfuscation key before flashing bin.
- Log the name and version of file being flashed.
2022-08-08 23:42:20 +10:00
David Lechner 10f85fee18 stm32/boards/LEGO_HUB_NO7: Add LEGO Hub No. 7 board definition.
This adds support for the LEGO Hub No. 7, aka LEGO Technic Small hub, aka
LEGO SPIKE Essential hub.  This board is largely similar to Hub No. 6:

- Same MCU (STM32F413 - different packaging with fewer pins).
- Same Bluetooth chip (TI CC2564).
- Same IMU chip.
- Similar external flash chip - 4MiB instead of 32MiB.
- 2 I/O ports instead of 6.
- No display - only status and battery LEDs.
- Different LED driver chip.
- Only 1 button which is also the power button.
- No speaker.

Signed-off-by: David Lechner <david@pybricks.com>
2022-08-06 00:01:31 +10:00
David Lechner 0f0f2351bb stm32/boards/LEGO_HUB_NO6/cc2564: Make timer configurable.
This adds configurable macros to define the timer and channel used to
provide the Bluetooth 32768 MHz clock.  This will allow code to be shared
with LEGO_HUB_NO7.

Signed-off-by: David Lechner <david@pybricks.com>
2022-08-06 00:01:28 +10:00
David Lechner f69af16619 stm32/boards/LEGO_HUB_NO6/spiflash: Pick command type at runtime.
This changes spiflash.py to read the flash chip ID at runtime to select the
read/write/erase commands.  This will allow the code to be shared with
LEGO_HUB_NO7 which doesn't use the 32-bit commands.

Also remove an unused constant while we are touching this.

Signed-off-by: David Lechner <david@pybricks.com>
2022-08-06 00:01:24 +10:00
David Lechner 9a51273d96 stm32/boards/LEGO_HUB_NO6/appupdate: Detect filesystem size at runtime.
This changes appupdate.py to get the filesystem size at runtime.  This will
allow the code to be shared with LEGO_HUB_NO7 which has a similar flash
chip with a different size.

Signed-off-by: David Lechner <david@pybricks.com>
2022-08-06 00:01:10 +10:00
David Lechner 7cc6df3303 stm32/boards/LEGO_HUB_NO6: Use named pins.
This changes all uses of pins to use the alias names of the pins.  This
makes the code easier to understand and will also allow sharing more code
with LEGO_HUB_NO7.

Signed-off-by: David Lechner <david@pybricks.com>
2022-08-05 23:57:35 +10:00
David Lechner 6152bbe3dd stm32/boards/LEGO_HUB_NO6: Fix typo in README.
This fixes a typo in the build directory path.

Signed-off-by: David Lechner <david@pybricks.com>
2022-08-05 23:57:15 +10:00
Angus Gratton fdfe4eca74 ports: Always include debug information in the ELF.
For bare metal ARM & xtensa targets, passing -g will make the ELF file
larger but doesn't change the binary size.  However, this means tools like
gdb, addr2line, etc can extract source-level information from the ELF.

Also standardise -ggdb to -g, these produce the exact same ELF file on
arm-none-eabi-gcc and will use DWARF format for all these ports.
2022-07-29 11:24:00 +10:00
Jim Mussared 092784da19 ports: Remove unused mp_type_{fileio/textio} macros in mpconfigport.h.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-07-26 18:07:22 +10:00
Tim Gates f736afb577 drivers,ports: Fix a few typos in comments.
Fixes:
- Should read `definitions` rather than `defintions`.
- Should read `resolution` rather than `resoultion`.
- Should read `inefficient` rather than `inefficent`.
- Should read `closed` rather than `closded`.

Signed-off-by: Tim Gates <tim.gates@iress.com>
2022-07-23 23:24:24 +10:00
robert-hh c781899438 stm32/softtimer: Switch to use softtimer code from shared/runtime. 2022-07-19 12:33:19 +10:00
Damien George b89422ceaa extmod: Always use custom mbedtls error message code.
All ports that use mbedtls use the custom error messages in
mp_mbedtls_errors.c.  This commit simplifies the build so that ports don't
need to explicitly add this file, it's now used by default when mbedtls is
enabled.

Signed-off-by: Damien George <damien@micropython.org>
2022-07-18 22:55:22 +10:00
Angus Gratton 1d23c01dd6 stm32/Makefile: Workaround LTO linker order bug in binutils <2.35.
Assembly files with weak symbols need to be linked first to avoid issues
with the weak symbols being incorrectly linked instead of strong ones.

See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83967 and
https://bugs.launchpad.net/gcc-arm-embedded/+bug/1747966

This is the workaround suggested in comment 10 of the gcc-arm-embedded bug.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2022-07-18 16:12:08 +10:00
David Lechner 7e4b205cb0 py/mpstate: Drop MICROPY_PORT_ROOT_POINTERS from mp_state_vm_t.
All in-tree uses of MICROPY_PORT_ROOT_POINTERS have been replaced with
MP_REGISTER_ROOT_POINTER(), so now we can remove both
MICROPY_PORT_ROOT_POINTERS and MICROPY_BOARD_ROOT_POINTERS from the code
and remaining config files.

Signed-off-by: David Lechner <david@pybricks.com>
2022-07-18 13:51:16 +10:00
David Lechner 816e4537f2 stm32: Use MP_REGISTER_ROOT_POINTER().
This uses MP_REGISTER_ROOT_POINTER() to register all port-specific root
pointers in the stm32 port.

Signed-off-by: David Lechner <david@pybricks.com>
2022-07-18 13:50:34 +10:00