Commit Graph

1356 Commits

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