The STATIC macro was introduced a very long time ago in commit
d5df6cd44a. The original reason for this was
to have the option to define it to nothing so that all static functions
become global functions and therefore visible to certain debug tools, so
one could do function size comparison and other things.
This STATIC feature is rarely (if ever) used. And with the use of LTO and
heavy inline optimisation, analysing the size of individual functions when
they are not static is not a good representation of the size of code when
fully optimised.
So the macro does not have much use and it's simpler to just remove it.
Then you know exactly what it's doing. For example, newcomers don't have
to learn what the STATIC macro is and why it exists. Reading the code is
also less "loud" with a lowercase static.
One other minor point in favour of removing it, is that it stops bugs with
`STATIC inline`, which should always be `static inline`.
Methodology for this commit was:
1) git ls-files | egrep '\.[ch]$' | \
xargs sed -Ei "s/(^| )STATIC($| )/\1static\2/"
2) Do some manual cleanup in the diff by searching for the word STATIC in
comments and changing those back.
3) "git-grep STATIC docs/", manually fixed those cases.
4) "rg -t python STATIC", manually fixed codegen lines that used STATIC.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
It's no longer supported by Emscripten (at least at 3.1.55). And it's not
needed when the output is WASM, which it is by default.
Signed-off-by: Damien George <damien@micropython.org>
Because `mpthreadport.h` is included by `mpthread.h`.
Also remove unnecessary include of `mpthreadport.h` in esp32's `main.c`.
Signed-off-by: Damien George <damien@micropython.org>
The patch enables SDRAM banks 1 and 2 to be accessible at 0xC0000000 and
0xD0000000 respectively (default mapping) or remapped to addresses
0x60000000 and 0x70000000.
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
This combines the argument parsing and checking for the machine.SPI.init()
and machine.SPI() interfaces.
The only real difference was unspecified arguments in init() mean to keep
the same value, while in new they get default values.
Behavior has changed for passing the "id" argument to init(). On other
ports this isn't allowed. But on esp32 it would change the SPI controller
of the static SPI instance to the new id. This results in multiple static
spi objects for the same controller and they would fight over which one has
inconsistent mpy vs esp-idf state. This has been changed to not allow "id"
with init(), like other ports.
In a few causes, a loop is used over arguments that are handled the same
way instead of cut & pasting the same stanza of code for each argument.
The init_internal function had a lot of arguments, which is not efficient
to pass. Pass the args mp_arg_val_t array instead as a single argument.
This reduced both the number of C lines and the compiled code size.
Summary of code size change: Two argument lists of 72 bytes are replaced
by a single shared 72 byte list. New shared argument parsing code is small
enough to be inlined, but is still efficient enough to shrink the overall
code size by 349 bytes of the three argument handlering functions.
add/remove: 0/0 grow/shrink: 0/3 up/down: 0/-349 (-349)
Function old new delta
machine_hw_spi_make_new 255 203 -52
machine_hw_spi_init 122 67 -55
machine_hw_spi_init_internal 698 456 -242
Total: Before=1227667, After=1227318, chg -0.03%
add/remove: 2/0 grow/shrink: 0/2 up/down: 92/-144 (-52)
Data old new delta
spi_allowed_args - 72 +72
defaults$0 - 20 +20
allowed_args$1 240 168 -72
allowed_args$0 1080 1008 -72
Total: Before=165430, After=165378, chg -0.03%
add/remove: 0/0 grow/shrink: 0/0 up/down: 0/0 (0)
Signed-off-by: Trent Piepho <tpiepho@gmail.com>
The size of the flash varies among MCU variants. Instead of requiring a
build-time variable to configure this, compute it at runtime using the
special device information word accessible through the FLASH_SIZE macro.
This feature is currently only implemented for H5 MCUs, but can be extended
to others.
Signed-off-by: Damien George <damien@micropython.org>
Allows bytecode itself to be used instead of an mp_raw_code_t in the simple
and common cases of a bytecode function without any children.
This can be used to further reduce frozen code size, and has the potential
to optimise other areas like importing.
Signed-off-by: Damien George <damien@micropython.org>
The Python BLE IRQ handler will most likely run on the NimBLE task, so its
C stack must be large enough to accommodate reasonably complicated Python
code (eg a few call depths). So increase this stack size.
Also increase the headroom from 1024 to 2048 bytes. This is needed because
(1) the esp32 architecture uses a fair amount of stack in general; and (2)
by the time execution gets to setting the Python stack top via
`mp_stack_set_top()` in this interlock code, about 600 bytes of stack are
already used, which reduces the amount available for Python.
Fixes issue #12349.
Signed-off-by: Damien George <damien@micropython.org>
In case callbacks must run (eg a disconnect event happens during the
deinit) and the GIL must be obtained to run the callback.
Fixes part of issue #12349.
Signed-off-by: Damien George <damien@micropython.org>
PPP is not that commonly used, let it be turned off in the board config to
save space. It is still on by default.
On an basic ESP32-S3 build, turning off PPP with LWIP still on saves ~35 kB
of codend 4 kB of data.
text data bss dec hex filename
1321257 304296 2941433 4566986 45afca before-ppp-off.elf
1285101 299920 2810305 4395326 43113e after-ppp-off.elf
-------------------------------
-36156 -4376 -56
Note that the BSS segment size includes all NOBITS sections in ELF file.
Some of these are aligned to 64kB chunk sized dummy blocks, I think for
alignment to MMU boundaries, and these went down by 1 block each, so 128
kiB of BSS is not really part of the binary size reduction.
Signed-off-by: Trent Piepho <tpiepho@gmail.com>
For mimxrt, nrf, renesas-ra, rp2 and samd ports, this commit implements
similar behaviour to the stm32 port, where USB is only brought up after
boot.py completes execution.
Currently this doesn't add any useful functionality (and may break
workflows that depend on USB-CDC being live in boot.py), however it's a
precondition for more usable workflows with USB devices defined in
Python (allows setting up USB interfaces in boot.py before the device
enumerates for the first time).
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
Obtaining the stack-top via a few function calls may yield a pointer which
is too deep within the stack. So require the user to obtain it from a
higher level (or via some other means).
Fixes issue #11781.
Signed-off-by: YAMAMOTO Takashi <yamamoto@midokura.com>
The current `ssl` module has quite a few differences to the CPython
implementation. This change moves the MicroPython variant to a new `tls`
module and provides a wrapper module for `ssl` (in micropython-lib).
Users who only rely on implemented comparible behavior can continue to use
`ssl`, while users that rely on non-compatible behavior should switch to
`tls`. Then we can make the facade in `ssl` more strictly adhere to
CPython.
Signed-off-by: Felix Dörre <felix@dogcraft.de>
By moving to GitHub actions, all MicroPython CI builds are now on GitHub
actions. This allows faster parallel builds and saves time by not building
when no relevant files changed.
This reveals a few failing tests, so those are temporarily disabled until
they can be fixed.
Signed-off-by: David Lechner <david@pybricks.com>
Signed-off-by: Damien George <damien@micropython.org>
When compiler optimizations are enabled on the mingw version of gcc, we are
getting failing tests because of rounding issues, for example:
print(float("1e24"))
would print
9.999999999999999e+23
instead of
1e+24
It turns out special compiler options are needed to get GCC to use the SSE
instruction set instead of the 387 coprocessor (which uses 80-bit precision
internall).
Signed-off-by: David Lechner <david@pybricks.com>
Currently, only the processor's SPI2 bus is enabled (though the related
pins are labeled SPI1 in the Portenta H7 documentation). This commit
enables the processor's SPI1 bus, which is accessible via the board's
high-density connectors.
Signed-off-by: Jim Lipsey <github@lipsey.org>
Changes include:
- Some mbedtls source files renamed or deprecated.
- Our `mbedtls_config.h` files are renamed to `mbedtls_config_port.h`, so
they don't clash with mbedtls's new default configuration file named
`mbedtls_config.h`.
- MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_KEY_EXCHANGE is deprecated.
- MBEDTLS_HAVE_TIME now requires an `mbedtls_ms_time` function to be
defined but it's only used for TLSv1.3 (currently not enabled in
MicroPython so there is a lazy implementation, i.e. seconds * 1000).
- `tests/multi_net/ssl_data.py` is removed (due to deprecation of
MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_KEY_EXCHANGE), there are the existing
`ssl_cert_rsa.py` and `sslcontext_server_client.py` tests which do very
similar, simple SSL data transfer.
- Tests now use an EC key by default (they are smaller and faster), and the
RSA key has been regenerated due to the old PKCS encoding used by openssl
rsa command, see
https://stackoverflow.com/questions/40822328/openssl-rsa-key-pem-and-der-conversion-does-not-match
(and `tests/README.md` has been updated accordingly).
Signed-off-by: Carlos Gil <carlosgilglez@gmail.com>
This simplifes the port configuration. It enables quite a few new
features, including the `math` and `cmath` modules, adding about 20k to the
firmware size.
Signed-off-by: Damien George <damien@micropython.org>
This is not enabled on any other MCU port, and is essentially unused on
esp8266 because mp_verbose_flag is always 0. Disabling saves ~7k of flash.
Signed-off-by: Damien George <damien@micropython.org>
The standard Arduino pinout uses LEDR/G/B and LED_BUILTIN (if available).
This patch adds aliases to match the standard pinout, while retaining
LED_RED/GREEN/BLUE for compatibility with existing scripts and examples.
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
This will apply to bare-arm and minimal, as well as the minimal unix
variant.
Change the default to MICROPY_QSTR_BYTES_IN_HASH=1 for the CORE,BASIC
levels, 2 for >=EXTRA.
Removes explicit setting of MICROPY_QSTR_BYTES_IN_HASH==1 in ports that
don't set the feature level (because 1 is implied by the default level,
CORE). Applies to cc3200, pic16bt, powerpc.
Removes explicit setting for nRF (which sets feature level). Also for samd,
which sets CORE for d21 and FULL for d51. This means that d21 is unchanged
with MICROPY_QSTR_BYTES_IN_HASH==1, but d51 now moves from 1 to 2 (roughly
adds 1kiB).
The only remaining port which explicitly set bytes-in-hash is rp2 because
it's high-flash (hence CORE level) but lowish-SRAM, so it's worthwhile
saving the RAM for runtime qstrs.
This work was funded through GitHub Sponsors.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
Sets MICROPY_QSTR_BYTES_IN_HASH==0 on stm32x0 boards.
This saves e.g. 2kiB on NUCLEO_F091.
This work was funded through GitHub Sponsors.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
This reverts the change from ce2058685b.
Without abspath, the build artefacts (object files) for boards with source
files are placed outside the build directory, because the BOARD_DIR
variable starts with "..". For the list of source files added to SRC_C,
none of them can start with "..". The usual fix for that would be to make
the files relative to the top of the MicroPython repo (because of the vpath
rule), eg ports/stm32/boards/$(BOARD). But then the $(wildcard ...)
pattern won't find files in this directory.
So abspath is necessary, although it will prevent building when there is a
space in the path. A better solution for spaces needs to be found.
Signed-off-by: Damien George <damien@micropython.org>
Make can't handle paths with spaces, see https://savannah.gnu.org/bugs/?712
The following workarounds exist:
- When using make's built-in functions:
- Use relative paths wherever possible to avoid spaces in the first
place.
- All spaces in paths can be escaped with backslashes; quotes don't
work.
- Some users use the shell to temporarily rename directories, or to
create symlinks without spaces.
- When using make to pass commands to the system's shell, enclose paths in
quotes. While make will still interpret quoted strings with spaces as
multiple words, the system's shell will correctly parse the resulting
command.
This commit contains the following fixes:
- In ports/stm32/mboot/Makefile: Use relative paths to avoid spaces when
using built-in functions.
- In all other files: Use quotes to enclose paths when make is used to call
shell functions.
All changes have been tested with a directory containing spaces.
Signed-off-by: Iksas <iksas@mailbox.org>
The irq service routine cleared the RT interrupt bit on TX interrupt. This
opens the possibility that an RT interrupt is missed.
Signed-off-by: Maarten van der Schrieck <maarten@thingsconnected.nl>
The `_start` function prototype is now declared as no-return, so `main()`
can't return.
To fix this, `main()` is replaced with `_start`.
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>