Commit Graph

1861 Commits

Author SHA1 Message Date
Damien George
9dedcf122d py/gc: Change include of stdint.h to stddef.h.
No std-int types are used in gc.h, but size_t is which needs stddef.h.

Signed-off-by: Damien George <damien@micropython.org>
2021-02-05 15:46:56 +11:00
Damien George
1f800cac3c rp2/micropy_rules.cmake: Fix makemoduledefs vpath to work with abs path.
In particular the firmware can now be built in a build directory that lives
outside the source tree, and the py/modarray.c file will still be found.

See issue #6837.

Signed-off-by: Damien George <damien@micropython.org>
2021-02-05 01:10:30 +11:00
Damien George
ad4656b861 all: Rename BYTES_PER_WORD to MP_BYTES_PER_OBJ_WORD.
The "word" referred to by BYTES_PER_WORD is actually the size of mp_obj_t
which is not always the same as the size of a pointer on the target
architecture.  So rename this config value to better reflect what it
measures, and also prefix it with MP_.

For uses of BYTES_PER_WORD in setting the stack limit this has been
changed to sizeof(void *), because the stack usually grows with
machine-word sized values (eg an nlr_buf_t has many machine words in it).

Signed-off-by: Damien George <damien@micropython.org>
2021-02-04 22:46:42 +11:00
Damien George
7c44354592 ports: Remove def of MP_PLAT_PRINT_STRN if it's the same as the default.
To simplify config, there's no need to specify MP_PLAT_PRINT_STRN if it's
the same as the default definition in py/mpconfig.h.

Signed-off-by: Damien George <damien@micropython.org>
2021-02-04 22:39:17 +11:00
Xiang Xiao
5fdf351178 py/gc: Don't include mpconfig.h and misc.h in gc.h.
Because gc.h doesn't reference any symbol from these header files.

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2021-02-04 22:37:26 +11:00
Damien George
7f7b4f2bc6 rp2/machine_adc: Only initialise the ADC periph if not already enabled.
Otherwise it resets the ADC peripheral each time a new ADC object is
constructed, which can reset other state that has already been set up.

See issue #6833.

Signed-off-by: Damien George <damien@micropython.org>
2021-02-04 10:55:43 +11:00
Damien George
195e7dfa06 rp2/modmachine: Implement additional functions incl unique_id and idle.
Added functions in the machine module are:
- unique_id (returns 8 bytes)
- soft_reset
- idle
- lightsleep, deepsleep (not power saving at the moment)
- disable_irq, enable_irq
- time_pulse_us

Signed-off-by: Damien George <damien@micropython.org>
2021-02-02 22:14:22 +11:00
stijn
81a4d96aed windows/msvc: Use same default python command as core. 2021-02-02 21:33:18 +11:00
stijn
0397448501 tests/run-tests: Change default Python command used on Windows.
Default to just calling python since that is most commonly available: the
official installer or zipfiles from python.org, anaconda, nupkg all result
in python being available but not python3.  In other words: the default
used so far is wrong.  Note that os.name is 'posix' when running the python
version which comes with Cygwin or MSys2 so they are not affected by this.
However of all possible ways to get Python on Windows, only Cygwin provides
no python command so update the default way for running tests in the
README.
2021-02-02 21:32:20 +11:00
Andrew Leech
5ef71cd167 stm32/mboot: Change debug compiler optimisation from -O0 to -Og.
With mboot encrpytion and fsload enabled, the DEBUG build -O0 compiler
settings result in mboot no longer fitting in the 32k sector.  This commit
changes this to -Og which also brings it into line with the regular stm32
build.
2021-02-02 21:25:13 +11:00
Damien George
7be1f77902 stm32/usbd_cdc_interface: Don't wait in usbd_cdc_tx_always if suspended.
MCUs with device-only USB peripherals (eg L0, WB) do not implement (at
least not in the ST HAL) the HAL_PCD_DisconnectCallback event.  So if a USB
cable is disconnected the USB driver does not deinitialise itself
(usbd_cdc_deinit is not called) and the CDC driver can stay in the
USBD_CDC_CONNECT_STATE_CONNECTED state.  Then if the USB was attached to
the REPL, output can become very slow waiting in usbd_cdc_tx_always for
500ms for each character.

The disconnect event is not implemented on these MCUs but the suspend event
is.  And in the situation where the USB cable is disconnected the suspend
event is raised because SOF packets are no longer received.

The issue of very slow output on these MCUs is fixed in this commit (really
worked around) by adding a check in usbd_cdc_tx_always to see if the USB
device state is suspended, and, if so, breaking out of the 500ms wait loop.
This should also help all MCUs for a real USB suspend.

A proper fix for MCUs with device-only USB would be to implement or somehow
synthesise the HAL_PCD_DisconnectCallback event.

See issue #6672.

Signed-off-by: Damien George <damien@micropython.org>
2021-02-02 12:09:33 +11:00
Tim Radvan
7a9027fd5d rp2/rp2_pio: Add JMP PIN support for PIO.
PIO state machines can make a conditional jump on the state of a pin: the
`JMP PIN` command.  This requires the pin to be configured with
`sm_config_set_jmp_pin`, but until now we didn't have a way of doing that
in MicroPython.

This commit adds a new `jmp_pin=None` argument to `StateMachine`.  If it is
not `None` then we try to interpret it as a Pin, and pass its value to
`sm_config_set_jmp_pin`.

Signed-off-by: Tim Radvan <tim@tjvr.org>
2021-02-02 11:32:48 +11:00
graham sanderson
52d3ae707d rp2/memmap_mp.ld: Update for latest SDK. 2021-02-02 10:59:10 +11:00
Andrew Scheller
c9210a65df rp2/machine_pin: Change N_GPIOS to NUM_BANK0_GPIOS for pico-sdk compat.
This fixes machine_pin.c to build against the new pico-sdk coming down the
pipeline, whilst still working with the existing version.
2021-02-02 09:50:55 +11:00
Damien George
ffded48810 zephyr/machine_uart: Fix arg of machine_uart_ioctl to make it uintptr_t.
Signed-off-by: Damien George <damien@micropython.org>
2021-02-01 22:30:50 +11:00
Christopher Tse
5c37e76e4f esp8266/modules/neopixel.py: Add timing param to NeoPixel constructor.
This matches the esp32 port.
2021-01-30 14:35:54 +11:00
Chris Hemingway
993ab6aa2c nrf/README: Add use of "make submodules" in alternative build paragraph.
Add "make submodules" to commands when building for the first time.
Otherwise, on a first time build, the submodules have not been checked out
and a lot of `fatal error: nrfx.h: No such file or directory` errors are
printed.
2021-01-30 14:32:55 +11:00
Andrew Scheller
499e199add docs,stm32: Fix minor typos in RTC docs, and->an. 2021-01-30 14:13:30 +11:00
stijn
b9a35bebf7 py/qstr.h: Remove QSTR_FROM_STR_STATIC macro.
It practically does the same as qstr_from_str and was only used in one
place, which should actually use the compile-time MP_QSTR_XXX form for
consistency; qstr_from_str is for runtime strings only.
2021-01-30 13:40:48 +11:00
Jim Mussared
0f9a9129da stm32/rfcore: Fix flow control for IPCC RX IRQ.
Don't clear the IPCC channel flag until we've actually handled the incoming
data, or else the wireless firmware may clobber the IPCC buffer if more
data arrives.  This requires masking the IRQ until the data is handled.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2021-01-30 13:21:04 +11:00
Damien George
469345e728 rp2: Add new port to Raspberry Pi RP2 microcontroller.
This commit adds a new port "rp2" which targets the new Raspberry Pi RP2040
microcontroller.

The build system uses pure cmake (with a small Makefile wrapper for
convenience).  The USB driver is TinyUSB, and there is a machine module
with most of the standard classes implemented.  Some examples are provided
in the examples/rp2/ directory.

Work done in collaboration with Graham Sanderson.

Signed-off-by: Damien George <damien@micropython.org>
2021-01-30 00:42:29 +11:00
Damien George
d1f120b142 stm32/main: Introduce MICROPY_HW_FLASH_MOUNT_AT_BOOT config option.
It's enabled by default to retain the existing behaviour.  A board can
disable this option if it manages mounting the filesystem itself, for
example in frozen code.

Signed-off-by: Damien George <damien@micropython.org>
2021-01-29 15:02:55 +11:00
Damien George
8f211df360 stm32/mboot/fwupdate.py: Refactor update_mpy with support for STATUS.
Changes are:
- refactor to use new _create_element function
- support extended version of MOUNT element with block size
- support STATUS element

Signed-off-by: Damien George <damien@micropython.org>
2021-01-29 15:02:55 +11:00
Damien George
bd7110a3d5 stm32/mboot: Introduce MBOOT_ERRNO_xxx constants and use them.
So that a failed update via fsload can be more easily diagnosed.

Signed-off-by: Damien George <damien@micropython.org>
2021-01-29 15:02:55 +11:00
Damien George
0efa0b5437 stm32/mboot: Add ELEM_TYPE_STATUS element so application can get status.
This new element takes the form: (ELEM_TYPE_STATUS, 4, <address>).  If this
element is present in the mboot command then mboot will store to the given
address the result of the filesystem firmware update process.  The address
can for example be an RTC backup register.

Signed-off-by: Damien George <damien@micropython.org>
2021-01-29 15:02:55 +11:00
Damien George
c1eb292927 stm32/mboot: Don't auto-detect littlefs block size.
Instead it is now passed in as an optional parameter to the ELEM_MOUNT
element, with a compile-time configurable default.

Signed-off-by: Damien George <damien@micropython.org>
2021-01-29 15:02:55 +11:00
Damien George
d1945cc2b5 stm32/main: Check block 0 and 1 when auto-detecting littlefs.
The superblock for littlefs is in block 0 and 1, but block 0 may be erased
or partially written, so block 1 must be checked if block 0 does not have a
valid littlefs superblock in it.

Prior to this commit, if block 0 did not contain a valid littlefs
superblock (but block 1 did) then the auto-detection would fail, mounting a
FAT filesystem would also fail, and the system would reformat the flash,
even though it may have contained a valid littlefs filesystem.  This is now
fixed.

Signed-off-by: Damien George <damien@micropython.org>
2021-01-29 15:02:55 +11:00
Vincent Duvert
45f0b6ab63 cc3200: Fix debug build.
* Fix a typo in the Makefile that prevented the debug build to be actually
  enabled when BTYPE=debug is used.

* Add a missing header in modmachine.c that is used when a debug build is
  created.
2021-01-23 17:44:27 +11:00
Vincent Duvert
342dc61784 cc3200/ftp: Add quotes to PWD response and allow FEAT prior to login.
This commit improves some FTP implementation details for better
compatibility with FTP clients:

* The PWD command now puts quotes around the directory name before
  returning it.  This fixes BBEdit’s FTP client, which performs a PWD after
  each CWD and gets confused if the returned directory path is not
  surrounded by quotes.

* The FEAT command is now allowed before logging in. This fixes the lftp
  client, which send FEAT first and gets confused (tries to use TLS) if the
  server responds with 332.
2021-01-23 17:40:53 +11:00
Oliver Joos
290dc1d5ee unix/modtime: Fix time() precision on unix ports with non-double floats.
With MICROPY_FLOAT_IMPL_FLOAT the results of utime.time(), gmtime() and
localtime() change only every 129 seconds.  As one consequence
tests/extmod/vfs_lfs_mtime.py will fail on a unix port with LFS support.

With this patch these functions only return floats if
MICROPY_FLOAT_IMPL_DOUBLE is used.  Otherwise they return integers.
2021-01-23 16:55:24 +11:00
IhorNehrutsa
769e822f19 esp32/modnetwork: Synchronize WiFi AUTH_xxx constants with IDF values. 2021-01-23 16:49:16 +11:00
Yonatan Schachter
063d7cc0e2 zephyr: Add basic UART functionality to machine module.
Currently supports only polling read and write.

Signed-off-by: Yonatan Schachter <yonatan.schachter@gmail.com>
2021-01-23 16:31:00 +11:00
Damien George
49dd9ba1a5 stm32/Makefile: Use MBOOT_PACK_KEYS_FILE as depedency of .pack.dfu.
To match the definition of GENERATE_PACK_DFU, so a board can customise the
location/name of this file if needed.

Signed-off-by: Damien George <damien@micropython.org>
2021-01-18 13:53:54 +11:00
Damien George
f6e6ef69e0 stm32/boards/NUCLEO_WB55: Enable MBOOT with packing mode.
To have at least one board configured with MBOOT_ENABLE_PACKING, for CI
testing purposes and demonstration of the feature.

Signed-off-by: Damien George <damien@micropython.org>
2021-01-18 12:43:01 +11:00
Damien George
c6f334272a stm32/mboot: Add support for signed and encrypted firmware updates.
This commit adds support to stm32's mboot for signe, encrypted and
compressed DFU updates.  It is based on inital work done by Andrew Leech.

The feature is enabled by setting MBOOT_ENABLE_PACKING to 1 in the board's
mpconfigboard.mk file, and by providing a header file in the board folder
(usually called mboot_keys.h) with a set of signing and encryption keys
(which can be generated by mboot_pack_dfu.py).  The signing and encryption
is provided by libhydrogen.  Compression is provided by uzlib.  Enabling
packing costs about 3k of flash.

The included mboot_pack_dfu.py script converts a .dfu file to a .pack.dfu
file which can be subsequently deployed to a board with mboot in packing
mode.  This .pack.dfu file is created as follows:
- the firmware from the original .dfu is split into chunks (so the
  decryption can fit in RAM)
- each chunk is compressed, encrypted, a header added, then signed
- a special final chunk is added with a signature of the entire firmware
- all chunks are concatenated to make the final .pack.dfu file

The .pack.dfu file can be deployed over USB or from the internal filesystem
on the device (if MBOOT_FSLOAD is enabled).

See #5267 and #5309 for additional discussion.

Signed-off-by: Damien George <damien@micropython.org>
2021-01-18 12:43:01 +11:00
Damien George
09e67de327 stm32/mboot/gzstream: Fix lost data decompressing final part of file.
Prior to this fix, the final piece of data in a compressed file may have
been lost when decompressing.

Signed-off-by: Damien George <damien@micropython.org>
2021-01-18 12:43:01 +11:00
Damien George
505a1853b9 teensy: Fix build errors and warnings and enable -Werror.
Changes are:
- Remove include of stm32's adc.h because it was recently changed and is
  no longer compatible with teensy (and not used anyway).
- Remove define of __disable_irq in mpconfigport.h because it was clashing
  with an equivalent definition in core/mk20dx128.h.
- Add -Werror to CFLAGS, and change -std=gnu99 to -std=c99.

Signed-off-by: Damien George <damien@micropython.org>
2020-12-18 13:48:57 +11:00
Damien George
e715a8fb9b stm32/boards/PYBD_SF2: Disable SPIFLASH_ENABLE_CACHE for mboot builds.
Mboot builds do not use the external SPI flash in caching mode, and
explicitly disabling it saves RAM and a small bit of flash.

Signed-off-by: Damien George <damien@micropython.org>
2020-12-18 13:39:32 +11:00
Damien George
e43a74a4db drivers/memory/spiflash: Add MICROPY_HW_SPIFLASH_ENABLE_CACHE option.
This only needs to be enabled if a board uses FAT FS on external SPI flash.
When disabled (and using external SPI flash) 4k of RAM can be saved.

Signed-off-by: Damien George <damien@micropython.org>
2020-12-18 13:39:32 +11:00
Damien George
061cb1a73a stm32/main: Do extended readblocks call when auto-detecting littlefs.
When littlefs is enabled extended reading must be supported, and using this
function to read the first block for auto-detection is more efficient (a
smaller read) and does not require a cached SPI-flash read.

Signed-off-by: Damien George <damien@micropython.org>
2020-12-18 13:39:28 +11:00
Damien George
80883a82c0 stm32/adc: Deselect VBAT after reading to prevent battery drain.
Signed-off-by: Damien George <damien@micropython.org>
2020-12-18 13:32:02 +11:00
iabdalkader
b603066bc2 stm32/sdram: Add SDRAM enter/leave self-refresh mode functions.
These functions enable SDRAM data retention in stop mode.  Example usage,
in mpconfigboard.h:

    #define MICROPY_BOARD_ENTER_STOP sdram_enter_low_power();
    #define MICROPY_BOARD_LEAVE_STOP sdram_leave_low_power();
2020-12-17 23:19:25 +11:00
iabdalkader
32d76e5de6 stm32/system_stm32: Enable DBGMCU in low-power modes for debug builds. 2020-12-17 23:04:42 +11:00
iabdalkader
20f8ce1982 stm32/pyb_can: Add ability to calculate CAN bit timing from baudrate.
Calculate the bit timing from baudrate if provided, allowing sample point
override.  This makes it a lot easier to make CAN work between different
MCUs with different clocks, prescalers etc.

Tested on F4, F7 and H7 Y/V variants.
2020-12-17 23:01:15 +11:00
Damien George
f305c62a5f stm32/usb: Allocate 128 bytes to CDC data out EPs on non-multi-OTG MCUs.
This much buffer space is required for CDC data out endpoints to avoid any
buffer overflows when the USB CDC is saturated with data.

Signed-off-by: Damien George <damien@micropython.org>
2020-12-10 12:26:25 +11:00
Damien George
460a181b77 stm32/mboot: Enable LFS2_READONLY for mboot builds with littlefs.
To reduce code size, since mboot does not modify the filesystem.

Signed-off-by: Damien George <damien@micropython.org>
2020-12-09 13:19:31 +11:00
Reinhard Feger
032e095620 stm32/boards/NUCLEO_H743ZI: Enable ethernet peripheral. 2020-12-08 15:27:51 +11:00
Reinhard Feger
d986b20122 stm32/eth: Add support for H7 processors. 2020-12-08 15:27:44 +11:00
Reinhard Feger
cd61fc8e44 stm32/boards/stm32h743.ld: Enable D2 RAM and add eth-buffer section. 2020-12-08 15:27:27 +11:00
Glenn Ruben Bakke
d0b8554df4 nrf: Change selected boards to utilize pre-flashed bootloader.
The nrf52840-mdk-usb-dongle and pca10050 comes with a pre-flashed
bootloader (OpenBootloader).

This commit updates the boards "mpconfigboard.mk" to use DFU as
default flashing method and set the corresponding BOOTLOADER
settings such that nrf52840_open_bootloader_1.2.x.ld linker
script is used.

The default DFU flashing method can be disabled by issuing "DFU=0"
when invoking make. This will lead to "segger" being used as default
flashing tool. When using "DFU=0", the linker scripts will not
compensate for any MBR and Bootloader region being present, and might
overwrite them if they were present.

The commit also removes the custom linker script specific to
nrf52840-mdk-usb-dongle as it now points to a generic.

Updated nrf52840-mdk-usb-dongle's README.md to be more clear on
how to deploy the built firmware.

The port README.md has also been updated. In the list of target
boards a new column has been added to indicate which bootloader
is present on the target board. And for consistency, changed all
examples in the README.md to use "deploy" instead of "flash".
2020-12-07 20:04:50 +01:00