Commit Graph

2270 Commits

Author SHA1 Message Date
iabdalkader
23e2e00779 rp2/boards/ADAFRUIT_FEATHER_RP2040: Configure custom VID/PID. 2021-08-01 10:51:50 +10:00
iabdalkader
7ae9e6ef69 rp2/tusb_port: Allow boards to configure USB VID and PID.
By defining MICROPY_HW_USB_VID and MICROPY_HW_USB_PID.
2021-08-01 10:51:24 +10:00
robert-hh
b2533fe479 mimxrt/boards: Add support for the MIMXRT1050_EVKB board. 2021-07-31 16:26:39 +10:00
robert-hh
1074c784b0 mimxrt: Add support for Hyperflash chips.
Hyperflash is used by the MIMXRT1050_EVKB, MIMXRT1060_EVK and
MIMXRT1064_EVK boards.

This commit includes:
- add support for Hyperflash
- modify MIMXRT1060_EVK and MIMXRT1064_EVK to change from QSPI to
  hyperflash.
- minor incidental changes to other boards so they still build

Note: Erasing a sector on the hyperflash is slow. It takes about a second,
which seems too long, but matches the data sheet.
2021-07-31 16:25:40 +10:00
Damien George
40b8ff0a6f stm32/README.md: Update supported MCUs, and submodule and mboot use.
Also mention mpremote as a way to access the REPL.

Signed-off-by: Damien George <damien@micropython.org>
2021-07-31 15:12:13 +10:00
Tobias Thyrrestrup
60e3e51753 stm32/Makefile: Update to only pull in used Bluetooth library. 2021-07-31 15:11:46 +10:00
Tobias Thyrrestrup
7a1edb91cb stm32/boards/LEGO_HUB_NO6: Add board definition for LEGO_HUB_NO6.
Add basic support for LEGO HUB NO.6 (e.g. LEGO SPIKE Prime, LEGO MINDSTORMS
Robot Inventor).

See README.md for details.

Thanks to @dpgeorge for helping put this together.

Signed-off-by: Tobias Thyrrestrup <tt@LEGO.com>
2021-07-31 10:25:18 +10:00
Damien George
224ac355cd stm32/boards/NUCLEO_F439ZI: Add board definition for NUCLEO_F439ZI.
Signed-off-by: Damien George <damien@micropython.org>
2021-07-27 16:46:10 +10:00
Matúš Olekšák
0f0006f4e1 stm32/boards/STM32F429DISC: Set correct UART2 pins and add UART3/6. 2021-07-26 14:38:39 +10:00
Damien George
aa0cf873bf stm32/uart: Support low baudrates on LPUART1.
By selecting a larger prescaler when needed.

Signed-off-by: Damien George <damien@micropython.org>
2021-07-26 13:53:50 +10:00
Damien George
fef2114404 stm32/uart: Fix LPUART1 baudrate set/get.
It needs to use a different function because the formula to compute the
baudrate on LPUART1 is different to a normal UART.

Fixes issue #7466.

Signed-off-by: Damien George <damien@micropython.org>
2021-07-26 13:53:50 +10:00
robert-hh
ee49ae8f82 rp2/machine_uart: Fix read when FIFO has chars but ringbuf doesn't.
Prior to this fix, if the UART hardware FIFO had a few chars but still
below the FIFO trigger threshold, and the ringbuf was empty, the read
function would timeout if timeout==0 (the default timeout).

This fix follows the suggestion of @iabdalkader.
2021-07-25 17:48:50 +10:00
iabdalkader
2e62e13455 rp2/machine_uart: Fix poll ioctl to also check hardware FIFO.
The RX IRQ does not trigger if the FIFO is less than the trigger level, in
which case characters may be available in the FIFO, yet not in the ringbuf,
and the ioctl returns false.
2021-07-25 17:11:03 +10:00
Chris Wilson
aecb697c72 stm32/boards: Add support for SparkFun STM32 MicroMod Processor board.
Signed-off-by: Chris Wilson <christopher.david.wilson@gmail.com>
2021-07-23 22:03:16 +10:00
Damien George
14b853eae0 minimal/Makefile: Add support for building with user C modules.
Fixes issue #5750.

Signed-off-by: Damien George <damien@micropython.org>
2021-07-23 12:02:03 +10:00
Sashkoiv
753b08cae6 stm32/boards/NUCLEO_F446RE: Enable CAN bus support. 2021-07-23 00:06:13 +10:00
Roberto Colistete Jr
b099db4426 esp8266/Makefile: Add more libm files to build.
Allows MICROPY_PY_MATH_SPECIAL_FUNCTIONS to be enabled, and for ulab to be
built as a user C module.
2021-07-22 23:55:31 +10:00
Damien George
a5ac3d5645 samd: Add support for building with user C modules.
Fixes issue #7545.

Signed-off-by: Damien George <damien@micropython.org>
2021-07-22 22:22:03 +10:00
iabdalkader
7649f5fbd2 stm32/sdram: Make SDRAM test cache aware, and optional failure with msg.
* Make SDRAM test cache-aware for newer MCUs.
* Use the defined data bus width (instead of the fixed 8-bits).
* Allow optional failure on error with verbose error messages.
* Test speed is now inverted (test accepts exhaustive instead fast).
2021-07-22 16:47:49 +10:00
Damien George
6214fa3f9e esp32/mphalport: Always yield at least once in delay_ms.
This helps the OS switch to and give other threads processing time during
the sleep.  It also ensures that pending events are handled, even when
sleeping for 0ms.

Fixes issue #5344.

Signed-off-by: Damien George <damien@micropython.org>
2021-07-22 00:20:53 +10:00
Damien George
2cfbe5bc0f esp32/modmachine: Release the GIL in machine.idle().
So that other threads get a chance to run when taskYIELD() is called.

See issue #5344.

Signed-off-by: Damien George <damien@micropython.org>
2021-07-22 00:17:59 +10:00
Josh Lloyd
6bc50c4fa9 stm32/systick: Always POLL_HOOK when delaying for milliseconds.
Call MICROPY_EVENT_POLL_HOOK even on very short delays so that busy loops
that call sleep_ms still yield to events and other threads.

See related issue #5344.
2021-07-22 00:15:36 +10:00
Mike Causer
cc77b30639 rp2/machine_spi: Allow boards to configure SPI pins using new macros. 2021-07-19 23:16:11 +10:00
Mike Causer
79da7757cc rp2/machine_i2c: Allow boards to configure I2C pins using new macros. 2021-07-19 23:16:11 +10:00
iabdalkader
4f2a10bfc9 rp2/machine_uart: Allow overriding default machine UART pins. 2021-07-19 23:14:02 +10:00
iabdalkader
8599f7a68d rp2/machine_uart: Add hardware flow control support. 2021-07-19 23:13:57 +10:00
Damien George
c77225ae5b esp32/boards/GENERIC_C3: Add generic C3-based board.
Signed-off-by: Damien George <damien@micropython.org>
2021-07-18 23:58:24 +10:00
Damien George
6823514845 esp32: Add initial support for ESP32C3 SoCs.
Supported features for this SoC are:
- UART REPL, filesystem
- Pin, ADC, PWM, SoftI2C, SoftSPI, Timer, RTC
- OneWire, DHT, NeoPixel
- RMT
- WiFi, Bluetooth

Signed-off-by: Damien George <damien@micropython.org>
2021-07-18 23:58:24 +10:00
Damien George
59dbbe9be7 esp32: Fix use of mp_int_t, size_t and uintptr_t.
Signed-off-by: Damien George <damien@micropython.org>
2021-07-18 23:58:16 +10:00
Damien George
0fc0ccabec esp32/machine_i2s: Add MICROPY_PY_MACHINE_I2S option, enable by default.
Signed-off-by: Damien George <damien@micropython.org>
2021-07-18 12:31:13 +10:00
Damien George
1f9243f8d4 esp32/machine_dac: Add MICROPY_PY_MACHINE_DAC option, enable by default.
Signed-off-by: Damien George <damien@micropython.org>
2021-07-18 12:11:10 +10:00
David P
d3f6ce7dc3 nrf/modules: Replace master/slave with controller/peripheral in SPI.
Also remove mistaken usage of MASTER/SLAVE constants in comments.
2021-07-18 11:23:41 +10:00
David P
f365025c9c stm32: Replace master/slave with controller/peripheral in I2C and SPI.
Replace "master" with "controller" and "slave" with "peripheral" in
comments, errors, and debug messages.

Add CONTROLLER and PERIPHERAL constants to pyb.SPI and pyb.I2C classes;
retain MASTER and SLAVE constants for backward compatiblity.
2021-07-18 11:23:41 +10:00
Jonathan Hogg
8be29b9b1b esp32/machine_hw_spi: Use a 2 item SPI queue for long transfers.
Using a 2-item transaction queue instead of 1 allows long transfers to 
be executed with the minimum inter-transaction delay. Limit maximum 
transaction length to ensure an integer multiple of the SPI `bits` 
setting are transferred. Fixes #7511.
2021-07-16 16:12:45 +01:00
Jonathan Hogg
eb3029c669 esp32/machine_spi: Calculate actual attained baudrate.
Calculate the actual baudrate that the hardware is capable of achieving 
and remember it so that printing the SPI object will show this. Fixes 
#7530.
2021-07-16 23:05:30 +10:00
robert-hh
98c5703027 mimxrt/machine_i2c: Add hardware-based machine.I2C to machine module.
It uses non-blocking transfer of data.  Advantage over SoftI2C:
- Higher data rate up to ~3 MHZ.
- Full protocol support.
2021-07-15 00:36:31 +10:00
Damien George
06277a9169 mimxrt/machine_led: Use mp_raise_msg_varg helper.
Signed-off-by: Damien George <damien@micropython.org>
2021-07-15 00:12:41 +10:00
Damien George
38a204ed96 py: Introduce and use mp_raise_type_arg helper.
To reduce code size.

Signed-off-by: Damien George <damien@micropython.org>
2021-07-15 00:12:41 +10:00
Jim Mussared
22fdb21302 windows/appveyor: Update to VS 2017 and use Python 3.8 for build/test.
MicroPython implements some 3.5+ features, and this change helps to reduce
the need for some .exp files in the test suite.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2021-07-15 00:10:52 +10:00
Damien George
6430cd3e02 unix/variants: Enable help and help("modules") on standard and dev.
See related #1354, #2906, #3436.

Signed-off-by: Damien George <damien@micropython.org>
2021-07-13 16:18:15 +10:00
Damien George
240888a0d2 unix/Makefile: Add back LIB_SRC_C to list of object files.
This fixes the dev build (it needs LIB_SRC_C for Bluetooth) which was
broken by 136369d72f.

Signed-off-by: Damien George <damien@micropython.org>
2021-07-13 15:58:39 +10:00
Damien George
831cc4a61d stm32/boards/NUCLEO_F446RE: Fix I2C1 pin assignment to match datasheet.
Thanks to @aureliano2nd.

Signed-off-by: Damien George <damien@micropython.org>
2021-07-13 15:25:27 +10:00
Damien George
136369d72f all: Update to point to files in new shared/ directory.
Signed-off-by: Damien George <damien@micropython.org>
2021-07-12 17:08:10 +10:00
Damien George
925878b2f8 ports: Update for move of crypto-algorithms, uzlib to lib.
Signed-off-by: Damien George <damien@micropython.org>
2021-07-12 16:37:20 +10:00
Damien George
0613d3e356 rp2/tusb_config.h: Set CFG_TUD_CDC_EP_BUFSIZE to 256.
This improves the speed of data going out of the MCU.

See related #7479.

Signed-off-by: Damien George <damien@micropython.org>
2021-07-08 13:20:53 +10:00
Damien George
132d93886f ports: Use common mp_hal_stdout_tx_strn_cooked instead of custom one.
To reduce code duplication.

Signed-off-by: Damien George <damien@micropython.org>
2021-07-08 12:59:31 +10:00
Bryan Tong Minh
3d9af87721 windows/Makefile: Add .exe extension to executables name.
Uses the same logic applied in 5b57ae985f
to determine when to add .exe.

See related: #3310, #3361, #3370, #4143, #5727.
2021-07-08 12:35:08 +10:00
Julia
3966f67746 zephyr/machine_spi: Add support for hardware SPI.
Adds support for hardware SPI to the zephyr port.  Consistent with other
ports, such as rp2 and stm32, we only implement the SPI protocol functions
(init and transfer).  Explicit sck/mosi/miso selection is not supported
and new SPI instances are initialized with default values.
2021-07-06 00:00:57 +10:00
Mike Teachman
8a5bfe44a5 esp32,stm32: Add new machine.I2S class for I2S protocol support.
This commit adds I2S protocol support for the esp32 and stm32 ports, via
a new machine.I2S class.  It builds on the stm32 work of blmorris, #1361.

Features include:
- a consistent I2S API across the esp32 and stm32 ports
- I2S configurations supported:
  - master transmit and master receive
  - 16-bit and 32-bit sample sizes
  - mono and stereo formats
  - sampling frequency
  - 3 modes of operation:
    - blocking
    - non-blocking with callback
    - uasyncio
  - internal ring buffer size can be tuned
- documentation for Pyboards and esp32-based boards
- tested on the following development boards:
  - Pyboard D SF2W
  - Pyboard V1.1
  - ESP32 with SPIRAM
  - ESP32

Signed-off-by: Mike Teachman <mike.teachman@gmail.com>
2021-07-05 23:42:25 +10:00
Damien George
031fe0f144 rp2/CMakeLists.txt: Suppress compiler errors for pico-sdk and tinyusb.
These warnings appear with GCC 11.  Keep them as warnings but not as
compiler errors so they can be dealt with properly in the future.

Signed-off-by: Damien George <damien@micropython.org>
2021-07-05 16:18:28 +10:00
Damien George
86ef965352 stm32/adc: Simplify and generalise how pin_adcX table is defined.
The ADC_FIRST_GPIO_CHANNEL and ADC_LAST_GPIO_CHANNEL macros are no longer
needed.  Instead the pin_adcX table (X = 1, 2, 3) is now generated to be
the exact size needed for a given MCU, and MP_ARRAY_SIZE(pin_adcX) is used
to determine the upper bound.

This commit also allows CPU pins to be excluded from ADC configuration if
they are hidden by prefixing their name with a "-".

Signed-off-by: Damien George <damien@micropython.org>
2021-07-05 16:03:11 +10:00
iabdalkader
0e11966ce9 stm32/adc: Define the ADC instance used for internal channels. 2021-07-02 23:33:51 +10:00
iabdalkader
ff7be31f26 stm32/adc: Allow using ADC12 and ADC3 for H7.
* Modify common functions in adc.c to accept ADC handle.
* Most external channels are connected to ADC12 which is used by default.
* For ADCAll (internal channels) ADC3 is used instead.
* Issue #4435 is possibly related (at least partially fixed).
2021-07-02 23:33:51 +10:00
Damien George
076caf317e javascript/Makefile: Suppress compiler errors from array bounds.
Signed-off-by: Damien George <damien@micropython.org>
2021-07-02 23:10:22 +10:00
Jonathan Hogg
18e48a71ee esp32/esp32_rmt: Enhance RMT with idle_level and write_pulses modes.
This change allows specification of the idle level and TX carrier output
level (through changed initialisation API), and more flexible specification
of pulses for write_pulses.

This is a breaking change for the esp32.RMT constructor API.  Previous code
of this form:

    esp32.RMT(..., carrier_duty_percent=D, carrier_freq=F)

will now raise an exception and should be changed to:

    esp32.RMT(..., tx_carrier=(F, D, 1))
2021-07-01 13:39:39 +10:00
robert-hh
efa97beb99 tools/autobuild: Add mimxrt port to build scripts for nightly builds.
The firmware for Teensy 4.0, Teensy 4.1 and MIMXRT1020_EVK are created.
Users of other MIMXRT10xx_EVK boards should be able to build the firmware
themselves, they might need specific DEBUG settings.

The Makefile had to be changed in order to build the .bin file as well.
2021-07-01 12:29:16 +10:00
David Lechner
8182f34584 stm32/main: Call mp_deinit() at end of main.
This adds a call to mp_deinit() in the main function of the STM32 port.
This enables the use of MICROPY_PORT_DEINIT_FUNC on that port, as well as
cleaning up the GIL if threading is enabled.
2021-07-01 12:26:40 +10:00
iabdalkader
a32a7421d6 stm32/dma: Add DMAMUX configuration for H7 to fix dma_nohal_init.
Fixes issue #5619.
2021-07-01 12:23:19 +10:00
iabdalkader
f4dce15c87 stm32/sdio: Fix undefined reference to DMA stream on H7.
Follow up to a96afae90f
2021-07-01 12:21:32 +10:00
Damien George
87985fc7e9 stm32/boardctrl: Skip running main.py if boot.py had an error.
Previous behaviour was: if boot.py had an exception then main.py would
still run, which is arguably unexpected behaviour.

This commit changes the behaviour so main.py is not run if boot.py has an
error.

Signed-off-by: Damien George <damien@micropython.org>
2021-06-30 13:24:40 +10:00
robert-hh
cbc9a591a4 mimxrt/modmachine: Add a few minor methods to the machine module.
Mostly for compatibility reasons:
- idle()
- disable_irq()
- enable_irq()
- time_pulse_us()
2021-06-26 22:27:02 +10:00
robert-hh
552e11bf64 mimxrt/mimxrt_flash: Remove commented-out code. 2021-06-26 22:27:02 +10:00
robert-hh
c8284c9b50 mimxrt/main: Extend the information returned by help(). 2021-06-26 22:27:02 +10:00
robert-hh
4eabff53cb mimxrt/main: Skip running main.py if boot.py failed.
See related #7379.
2021-06-26 22:27:02 +10:00
robert-hh
b35566af79 mimxrt/boards: Set vfs partition start to 1 MBbyte.
This avoids the irritation of the PJRC HalfKay loader on Teensy 4.0.  Block
0 and 1 are properly erased and the additional formatting in the make
script is not required anymore.
2021-06-26 22:27:02 +10:00
robert-hh
a262faa227 mimxrt/moduos: Seed the PRNG on boot using the TRNG. 2021-06-26 22:27:02 +10:00
robert-hh
f45412793e mimxrt/machine_spi: Add the SPI class to the machine module.
This class supports SPI bus controller mode, with blocking transfers.

SPI device numbers start at 0, to comply with the pinout of the Teensy
boards.  With the configured clock frequency the fastest baud rate is
33MHz.  For messages longer 16 bytes DMA is used.  The class uses the
existing framework with extmod/machine_spi.c.

Extended driver options:

- drive=n with n being between 1 and 6 or PIN.POWER_1 to PIN.POWER_6.
  Since the pins used by the SPI are fixed, no Pin settings can be made.
  Thus the drive option is added allowing to control ringing and crosstalk
  on the connection.

- gap_ns=nnnnn is the time between sent data items in a frame given in ns.
  Default is 2 clock cycles.
2021-06-26 22:14:47 +10:00
Jonathan Hogg
30422ca7c2 esp32/esp32_rmt: Fix RMT looping in newer IDF versions.
When looping, now disable the TX interrupt after calling rmt_write_items()
function to handle change in IDF behaviour (since v4.1).  Also check length
of pulses to ensure it fits hardware limit.

Fixes issue #7403.
2021-06-25 12:05:12 +10:00
Damien George
c13853f4da javascript: Rework Makefile and GC so it works with latest Emscripten.
The GC now works correctly using asyncify and the functions
emscripten_scan_stack() and emscripten_scan_registers().  Stack/call depth
is monitored via the use of the pystack option.

Fixes issue #6738.

Signed-off-by: Damien George <damien@micropython.org>
2021-06-25 11:29:39 +10:00
Krzysztof Adamski
feb7e2e864 rp2/machine_rtc: In RTC.datetime, compute weekday automatically.
Calculating the weekday each time you want to set a date is error prone and
tiresome.  MicroPython can do it on its own - hardware on some ports do not
support storing weekday in hardware and always computes it on the fly,
ignoring the value given to the constructor.

During discussion for #7432 the conclusion was that there seems to be no
obvious reason to let user set the weekday to an incorrect value so it
makes sense to just ignore the provided weekday value and always compute
the correct value.  This patch introduces this change for the rp2 port.

Signed-off-by: Krzysztof Adamski <k@japko.eu>
2021-06-25 10:29:45 +10:00
Krzysztof Adamski
35b1359a3a rp2: Use 0=Monday datetime convention in RTC.
The RTC in rp2 can store any, even wrong, number as a weekday in RTC.  It
was, however, discussed in #7394 that we would like to unify all ports and
use 0 as Monday, not Sunday in the machine.RTC implementation.

This patch makes sure that the default date set in RTC is adheres to this
convention.  It also fixes the example in quickref to use proper weekday to
avoid confusion.

Signed-off-by: Krzysztof Adamski <k@japko.eu>
2021-06-25 10:29:12 +10:00
Krzysztof Adamski
6409bbcb72 mimxrt: Move calc_weekday helper function to timeutils.
This function may be useful for other ports as well so lets move it to
timeutils so it can be reused.

Signed-off-by: Krzysztof Adamski <k@japko.eu>
2021-06-25 10:28:32 +10:00
Amir Gonnen
cb332ddae8 unix/modffi: Add option to lock GC in callback, and cfun access.
Add an optional 'lock' kwarg to callback that locks GC and scheduler.  This
allows the callback to be invoked asynchronously in 'interrupt context',
for example as a signal handler.

Also add the 'cfun' member function to callback, that allows retrieving the
C callback function address.  This is needed when the callback should be
set to a struct field.

See related #7373.

Signed-off-by: Amir Gonnen <amirgonnen@gmail.com>
2021-06-24 23:12:26 +10:00
Damien George
0009a7dc30 esp32/main: Allow MICROPY_DIR to be overridden.
This is necessary when building a custom out-of-tree board.

Signed-off-by: Damien George <damien@micropython.org>
2021-06-24 16:03:25 +10:00
Damien George
63b8b79610 stm32/usb: Make irq's default trigger enable all events.
Following how other .irq() methods work on other objects.

Signed-off-by: Damien George <damien@micropython.org>
2021-06-23 16:11:37 +10:00
Damien George
38bc5a9f67 stm32: Provide a custom BTstack runloop that integrates with soft timer.
It reschedules the BT HCI poll soft timer so that it is called exactly when
the next timer expires.

Signed-off-by: Damien George <damien@micropython.org>
2021-06-23 13:14:26 +10:00
Damien George
74c2c31811 stm32/mpbthciport: Change from systick to soft-timer for BT scheduling.
Instead of using systick the BT subsystem is now scheduled using a soft
timer.  This means it is scheduled only when it is enabled.

Signed-off-by: Damien George <damien@micropython.org>
2021-06-23 13:14:26 +10:00
Damien George
60f1f76984 stm32/softtimer: Add soft_timer_reinsert() helper function.
And call mp_pairheap_init_node() in soft_timer_static_init() so that
reinsert can be called after static_init.

Signed-off-by: Damien George <damien@micropython.org>
2021-06-23 13:14:26 +10:00
Michael Weiss
b3a34dde36 esp32,esp8266: Add __len__ to NeoPixel driver to support iterating.
Signed-off-by: mishafarms <github@mishafarms.us>
2021-06-22 16:33:55 +10:00
Damien George
bbf9dd849a esp32/boards/sdkconfig.base: Disable MEMPROT_FEATURE to alloc from IRAM.
Dynamically generate/loaded native code (eg from @micropython.native or
native .mpy files) needs to be able allocate from IRAM, and the memory
protection feature must be disabled for that to work.  Disabling it is
needed to get native code working on ESP32-S2 and -C3.

Signed-off-by: Damien George <damien@micropython.org>
2021-06-20 22:54:20 +10:00
David Lechner
259d9b69fe py/mpstate: Schedule KeyboardInterrupt on main thread.
This introduces a new macro to get the main thread and uses it to ensure
that asynchronous exceptions such as KeyboardInterrupt (CTRL+C) are only
scheduled on the main thread. This is more deterministic than being
scheduled on a random thread and is more in line with CPython that only
allow signal handlers to run on the main thread.

Fixes issue #7026.

Signed-off-by: David Lechner <david@pybricks.com>
2021-06-19 09:49:00 +10:00
David Lechner
ca920f7218 py/mpstate: Make exceptions thread-local.
This moves mp_pending_exception from mp_state_vm_t to mp_state_thread_t.
This allows exceptions to be scheduled on a specific thread.

Signed-off-by: David Lechner <david@pybricks.com>
2021-06-19 09:43:44 +10:00
Damien George
eb7ae538f9 esp8266/boards/GENERIC_512K: Add custom minimal _boot.py.
Commit 0abf6f830c removed _boot.py from the
manifest for the GENERIC_512K board because the build does not include a
filesystem.  But the main code expects _boot.py to be there and prints an
error if it's not.  So add a custom _boot.py, which just sets the
gc.threshold().

Signed-off-by: Damien George <damien@micropython.org>
2021-06-18 14:13:18 +10:00
Damien George
4eb13c50cd esp32/machine_sdcard: Use deinit_p to deinit SD bus in SPI mode.
Fixes issue #7352.

Signed-off-by: Damien George <damien@micropython.org>
2021-06-18 09:55:22 +10:00
Jonathan Hogg
89945b1989 esp32/machine_hw_spi: Allow None for unused pins in initializer.
Make the hardware SPI initializer method match the `init()` method by 
allowing `None` to be given for `sck`/`mosi`/`miso` to specify an unused 
signal.
2021-06-17 18:52:22 +10:00
Thomas Wenrich
060066804a esp32/modnetwork: Add "reconnects" option to WLAN STA interface.
This adds a wlan.config(reconnects=N) option to set the number of reconnect
attempts that will be made if the WLAN connection goes down.  The default
is N=-1 (infinite retries, current behavior).  Setting
wlan.config(reconnects=0) will disable the reconnect attempts.

A nice side effect of reconnects=0 is that wlan.status() will report the
disconnect reason now.  See related issue #5326.
2021-06-17 18:48:06 +10:00
Tobias Eydam
48437cec45 esp32/network_lan: Add Ethernet support for IDF v4.1 and above.
Ethernet-PHYs from ESP-IDF (LAN8720, IP101, RTL8201, DP83848) are now
supported in IDF v4.1 and above.  PHY_KSZ8041 is only for ESP-IDF 4.3 and
above.  ESP32S2 is not supported.

Signed-off-by: Tobias Eydam <eydam-prototyping@outlook.com>
2021-06-17 15:36:14 +10:00
robert-hh
8edc3aacdd mimxrt/modutime: Extend the time module.
Methods added:
- time.time()
- time.time_ns()
- time.gmtime()
- time.localtime()
- time.mktime()

The rp2 port was uses as the template for the change.
2021-06-16 01:50:09 +10:00
robert-hh
7417c6ac91 mimxrt/machine_pin: Implement pin.irq() functionality. 2021-06-16 01:42:10 +10:00
robert-hh
689476c576 mimxrt/machine_uart: Add the UART class to the machine module.
The implementation uses the LPUARTx devices.  Up to 8 UARTs can be used,
given that the pins are accessible.  E.g. 8 on Teensy 4.1, 5 on
MIMXRT1020_EVK.

For Tennsy 4.0 and 4.1 the UART numbers are as printed on the pinout 1..N.
The MIMXRT10xx-EVK boards have only one UART named, which gets the number
1.  All other UART are assigned to different Pins:

MIMXRT1010-EVK:
    D0/D1   UART 1
    D6/D7   UART 2
    A0/D4   UART 3

MIMXRT1020-EVK:
    D0/D1   UART 1
    D6/D9   UART 2
    D10/D12 UART 3
    D14/D15 UART 4
    A0/A1   UART 5

MIMXRT1050-EVK, MIMXRT1060-EVK, MIMXRT1064-EVK:
    D0/D1   UART 1
    D7/D6   UART 2
    D8/D9   UART 3
    A1/A0   UART 4
2021-06-16 01:21:15 +10:00
Pavol Rusnak
95048129b1 unix: Fix build on arm64-darwin due to integer cast.
This fixes error: cast to smaller integer type 'int' from 'pthread_t'.
pthread_t is defined as long, not as int.

Signed-off-by: Pavol Rusnak <pavol@rusnak.io>
2021-06-15 00:08:24 +10:00
Krzysztof Adamski
e7f7094ef6 rp2/machine_rtc: Check return value from rtc_set_datetime.
The rtc_set_datetime() from pico-sdk will validate the values in the
datetime_t structure and refuse to set the time if they aren't valid. It
makes sense to raise an exception if this happens instead of failing
silently which might be confusing (as an example, see:
https://github.com/micropython/micropython/pull/6928#issuecomment-860166044
).
2021-06-15 00:06:26 +10:00
iabdalkader
66115a3744 stm32/eth: Fix eth_link_status function to use correct BSR bit.
Fixes #7346.
2021-06-13 12:29:11 +10:00
iabdalkader
51614ce365 stm32/eth: Add low-power mode configuration option.
Add low power functionality configurable with:

    lan.config(low_power=True/False)
2021-06-13 12:27:33 +10:00
robert-hh
3ab8806c0d mimxrt/machine_rtc: Maintain microsecond offset.
The supplied value for microseconds in datetime() will be treated as a
starting value for the reported microseconds.  Due to internal processing
in setting the time, there is an offset about 1 ms.
2021-06-12 23:20:12 +10:00
robert-hh
fd4eec5555 mimxrt/machine_rtc: Change RTC.datetime() tuple to match other ports.
This change moves the datetime tuple format back to the one used by all the
other ports:

    (year, month, day, weekday, hour, minute, second, microsecond)

Weekday is a number between 0 and 6, with 0 assigned to Monday.  It has to
be provided when setting the RTC with datetime(), but will be ignored on
entry and calculated when needed.

The weekday() method was removed, since that is now again a part of the
datetime tuple.

The now() method was updated so it continues to return a tuple that matches
CPython's datetime module.
2021-06-12 23:15:05 +10:00
Krzysztof Adamski
37d01d4be3 rp2/machine_rtc: Add initial support for RTC.
Initial support for machine.RTC on rp2 port. It only supports datetime()
method and nothing else. The method gets/returns a tuple of 8 items, just
like esp32 port, for example, but the usec parameter is ignored as the RP2
RTC only works up to seconds precision.

The Pico RTC isn't very useful as the time is lost during reset and there
seems to be no way to easily power up just the RTC clock with a low current
voltage, but still there seems to be use-cases for that, see issues #6831,
and a Thonny issue #1592. It was also requested for inclusion on v1.15
roadmap on #6832.

Signed-off-by: Krzysztof Adamski <k@japko.eu>
2021-06-12 23:02:54 +10:00
IhorNehrutsa
da8aad18a4 esp32/README: Describe how to select compatible version of existing IDF. 2021-06-11 19:52:10 +10:00
noslaver
f314cac604 esp32/partitions-2MiB.csv: Update table so firmware fits.
The current MicroPython app size is larger than the size allocated in the
partitions table.
2021-06-11 17:57:40 +10:00
Damien George
865abba197 esp32/makeimg.py: Load sizes from partition table and verify data fits.
Changes introduced are:
- the application offset is now loaded from the partition table instead of
  being hard-coded to 0x10000
- maximum size of all sections is computed using the partition table
- an error is generated if any section overflows its allocated space
- remaining bytes are printed for each section

Signed-off-by: Damien George <damien@micropython.org>
2021-06-11 15:43:49 +10:00
Damien George
61f91de361 stm32/sdram: Prevent array-bounds warnings with GCC 11.
Signed-off-by: Damien George <damien@micropython.org>
2021-06-10 22:48:54 +10:00
Damien George
cf849d84b9 stm32/boards: Enable MICROPY_HW_SPIFLASH_ENABLE_CACHE on VCC_GND boards.
Because these boards use the SPI flash cache in their bdev.c configuration.

Signed-off-by: Damien George <damien@micropython.org>
2021-06-10 22:48:17 +10:00
Damien George
71e3538a32 stm32/usb: Add USB_VCP.irq method, to set a callback on USB data RX.
Usage:

    usb = pyb.USB_VCP()
    usb.irq(lambda u:print(u, u.read()), usb.IRQ_RX)

Signed-off-by: Damien George <damien@micropython.org>
2021-06-10 15:26:21 +10:00
Zoltán Vörös
8c02b94946 nrf: Add more math sources to Makefile, and enable log2 implementation.
This commit adds a few math functions to the source list in the Makefile,
and implements the log2f function, so that ulab can be compiled on the nrf
boards.  It also addresses part of #5162.
2021-06-08 16:39:47 +10:00
Abilio Marques
525a920ca5 unix/modffi: Fix conversion between Python integers and ffi types.
This commit fixes the following problems converting to/from Python integers
and ffi types:
- integers of 8 and 16 bits not working on big endian
- integers of 64 bits not working on 32 bits architectures
- unsigned returns were converted to signed Python integers

Fixes issue #7269.
2021-06-08 13:06:17 +10:00
Damien George
d00523ba0c zephyr/boards: Enable ubluetooth on nucleo_wb55rg board.
Signed-off-by: Damien George <damien@micropython.org>
2021-06-06 21:57:44 +10:00
Damien George
80e79a777d zephyr: Add initial ubluetooth module integration.
Currently only advertising and scanning are supported, using the ring
buffer for events (ie not synchronous events at this stage).

The ble_gap_advertise.py multi-test passes (tested on a nucleo_wb55rg
board).

Signed-off-by: Damien George <damien@micropython.org>
2021-06-06 21:57:06 +10:00
Maureen Helm
5cb2ade65b zephyr: Update to Zephyr v2.6.0.
Updates the zephyr port build instructions and CI to use the latest
zephyr release tag.

Signed-off-by: Maureen Helm <maureen.helm@nxp.com>
2021-06-06 20:17:42 +10:00
Maureen Helm
3331b1811d zephyr: Disable CONFIG_NET_SOCKETS_POSIX_NAMES.
Zephyr's default value for CONFIG_NET_SOCKETS_POSIX_NAMES was changed
from false to true between Zephyr v2.5.0 and v2.6.0. This caused
conflicts in MicroPython, which uses the zsock_ prefixed functions, so
disable it.

Signed-off-by: Maureen Helm <maureen.helm@nxp.com>
2021-06-06 20:17:42 +10:00
Maureen Helm
f17c0db5f7 zephyr: Update disk access configuration for Zephyr v2.6.0.
Zephyr's Kconfig symbols and defaults for SDHC/SDMMC disk drivers and
the disk access subsystem were reworked between Zephyr v2.5.0 and
v2.6.0. Update MicroPython accordingly.

Signed-off-by: Maureen Helm <maureen.helm@nxp.com>
2021-06-06 20:17:42 +10:00
Damien George
36cb365cad unix/main: Increase stack limit on ARM architectures.
Signed-off-by: Damien George <damien@micropython.org>
2021-06-05 11:03:09 +10:00
leo chung
fad0efdcf2 esp32/Makefile: Fix wrong target for partition-table.bin.
"$(BUILD)/partition_table/partition  -table.bin" is typing mistake.

Signed-off-by: leo chung <gewalalb@gmail.com>
2021-06-04 01:04:35 +10:00
robert-hh
53fea8598e mimxrt/boards: Add board configuration files for Teensy 4.1.
These are at the moment more or less identical to the Teensy 4.0 files,
except for the pins.csv file and the flash size.
2021-06-04 01:00:39 +10:00
Philipp Ebensberger
b8c65b174f mimxrt/machine_adc: Add the ADC class to the machine module.
This adds the machine.ADC class with the read_u16() method.  make-pins.py
and supporting files are updated to generate ADC information.
2021-06-04 00:51:58 +10:00
robert-hh
bbdc98f72e mimxrt: Enable many Python and some extmod features.
Besides Python features this includes the extmod modules which make use of
the Pin module, especially machine.softSPI, machine.SoftI2C and onewire.
2021-06-04 00:38:18 +10:00
robert-hh
a40e1473dc mimxrt: Add floating point support.
Since not all boards support double fp, all board specific .mk files are
affected too.
2021-06-04 00:37:22 +10:00
robert-hh
2f365d234e mimxrt/machine_rtc: Add the RTC class to the machine module.
Initial version, using the LP RTC clock.  It provides setting the date and
time with rtc.init() or rtc.datetime(), and reading the date and time with
rtc.datetime() or rtc.now().  The method weekday() reports the weekday of
the current date.  It starts with 0 for Monday.

The tuple order for datetime() and now() matches the CPython sequence:
(year, month, day, hour, minute, second, microsecond, TZ).  TZ is ignored
and reported as None.  Microsecond is provided at a best effort.

If a battery is not supplied, the default boot date/time is 1970/1/1 0:0:0.
With a battery, the clock continues to run even when the board is not
powered.  The clock is quite precise.  If not, using rtc.calibration() may
help.
2021-06-03 15:24:04 +10:00
robert-hh
d79105d7c0 mimxrt/machine_timer: Leave the Timer clock source at IPG clock.
Setting it to OSC_CLK interferes the utime module's functionality.  This is
still an area demanding an understanding.
2021-06-03 13:03:02 +10:00
robert-hh
cdd95ce737 mimxrt/machine_timer: Reuse any existing timer objects.
So there is a 1-1 mapping of hardware timer to Python object.
2021-06-03 13:02:51 +10:00
robert-hh
5226d6e1ee mimxrt: Remove __WFE() from MICROPY_EVENT_POLL_HOOK.
The device is unreliable with the WFE included.  This needs further
investigation.
2021-06-03 12:21:36 +10:00
robert-hh
4c407c790f mimxrt: Add the Timer class to the machine module.
It supports three hardware timer channels based on the PIT timers of the
MIMXRT MCU.  The timer id's are 0, 1 and 2.  On soft reboot all active
timers will be stopped via finalisers.
2021-06-02 00:33:13 +10:00
robert-hh
745b4319a2 mimxrt/boards/TEENSY40: Re-create the flash FS after deploy.
This is required since the Teensy Halfkay loader attempts to erase all of
the flash but fails to do so, at least in my tests.  Formatting brings it
back to a known state.
2021-06-01 23:52:45 +10:00
robert-hh
dfd4324eb1 mimxrt: Add flash storage support with VFS and littlefs filesystem.
This commit adds full support for a filesystem on all boards, with a block
device object mimxrt.Flash() and uos.VfsLfs2 enabled.

Main changes are:
- Refactoring of linker scripts to accomodate reserved area for VFS.  VFS
  will take up most of the available flash. 1M is reserved for code.  9K is
  reserved for flash configuration, interrupts, etc.
- Addition of _boot.py with filesystem init code, called from main.c.
- Definition of the mimxrt module with a Flash class in modmimxrt.[ch].
- Implementation of a flash driver class in mimxrt_flash.c.  All flashing
  related functions are stored in ITCM RAM.
- Addition of the uos module with filesystem functions.
- Implementation of uos.urandom() for the sake of completeness of the uos
  module.

It uses sample code from CircuitPython supplied under MIT license, which
uses the NXP SDK example code.

Done in collaboration with Philipp Ebensberger aka @alphaFred who
contributed the essential part to enable writing to flash while code is
executing, among other things.
2021-06-01 23:42:57 +10:00
robert-hh
c303b15f10 mimxrt: Enable frozen modules. 2021-06-01 22:57:09 +10:00
robert-hh
fdaf2b80d9 mimxrt: Add custom help text and enable help("modules"). 2021-06-01 22:52:44 +10:00
Joseph Chiu
c5d2095e59 esp32/espneopixel: Add support for GPIO32 and GPIO33.
Adds support for NeoPixels on GPIO32 and GPIO33 on ESP32.  Otherwise,
NeoPixels wired to GPIO32/33 wll silently fail without any hints to the
user.

With thanks to @robert-hh.

Fixes issue #7221.
2021-05-30 23:36:50 +10:00
IAMLIUBO
a18f695e29 esp32/boards: Add M5STACK_ATOM board definition.
ATOM is a very small ESP32 development board produced by M5Stack, with a
size of 24mm * 24mm, with peripherals such as WS2812, IR, button, MPU6886
(Only Matrix), and 8 GPIO extensions.  It also has a plastic shell.
2021-05-30 23:15:13 +10:00
Damien George
db8704ecbd esp8266,esp32: Update manifest to point to new dirs in micropython-lib.
Following a refactoring of micropython-lib.

Signed-off-by: Damien George <damien@micropython.org>
2021-05-28 18:32:56 +10:00
Damien George
211c3e41f1 stm32/boards/PYBD_SF2: Disable GCC 11 warnings for array bounds.
With GCC 11 there is now a warning about array bounds of OTP-mac, due to
the OTP being a literal address.

Signed-off-by: Damien George <damien@micropython.org>
2021-05-27 23:57:51 +10:00
Damien George
62f75376dd stm32/boards/NUCLEO_L432KC: Fix FS size and enable LFS1 filesystem.
Signed-off-by: Damien George <damien@micropython.org>
2021-05-27 12:18:41 +10:00
Damien George
0abf6f830c esp8266/boards/GENERIC_512K: Add custom manifest without FS modules.
The 512k build does not have a filesystem so there is no reason to include
the filesystem-related modules.  This commit provides a custom manifest.py
for this board which no longer includes: _boot.py, flashbdev.py,
inisetup.py, upip.py, upip_utarfile.py.  This cuts the build down by about
9k of flash.

Signed-off-by: Damien George <damien@micropython.org>
2021-05-26 21:41:40 +10:00
Damien George
b84406f313 qemu-arm: Add support for Cortex-A9 via sabrelite board.
Signed-off-by: Damien George <damien@micropython.org>
2021-05-26 16:24:00 +10:00
robert-hh
c732b80f05 mimxrt: Extend the Pin module for SoftI2C, SoftSPI support.
This change consists mostly of changing and extending the required
definitions in mphalport.h.
2021-05-25 20:43:52 +02:00
Philipp Ebensberger
c326d9a67b mimxrt: Enable built-in help. 2021-05-26 00:12:45 +10:00
Philipp Ebensberger
ff5d39529c mimxrt: Implement machine.Pin class.
- modified pin type from pin_obj_t to machine_pin_obj_t
- created machine_pin.c
- implemented basic version of make-pins.py to genertate pins.c/.h files
  automatically; the only alternate function currently supported is GPIO
- added af.csv files for all supported MCUs
- replaced pins.c/pins.h files with pin.csv for all boards
- implemented on/off/high/low/value/init methods
- Implemented IN/OUT/OPEN_DRAIN modes
- modified LDFLAGS for DEBUG build to get usefull .elf file for debugging

Signed-off-by: Philipp Ebensberger
2021-05-26 00:12:42 +10:00
Damien George
ea81bcf1c0 stm32/mboot: Leave bootloader from thread mode, not from IRQ.
Leaving the bootloader from an IRQ (eg USB or I2C IRQ) will not work if
MBOOT_LEAVE_BOOTLOADER_VIA_RESET is disabled, ie if mboot jumps directly to
the application.  This is because the CPU will still be in IRQ state when
the application starts and IRQs of lower priority will be blocked.

Fix this by setting a flag when the bootloader should finish, and exit the
bootloader always from the main (top level) thread.

This also improves the USB behaviour of mboot: it no longer abruptly
disconnects when the manifest command is sent.

Signed-off-by: Damien George <damien@micropython.org>
2021-05-21 00:46:01 +10:00
Damien George
748339b281 stm32/uart: Configure pull-up only on RX and CTS, not TX and RTS.
RX and CTS are the input pins and pull-ups are enabled so they don't cause
a problem if left unconnected.  But the output pins don't need a pull up
(they were originally all configured with pull up in commit
8f7491a109).

If needed, the pull-ups can be disabled in Python using machine.Pin after
the UART is constructed.

See issue #4369.

Signed-off-by: Damien George <damien@micropython.org>
2021-05-21 00:38:04 +10:00
Damien George
a96afae90f stm32/sdio: Fix case of SDIO DMA turning off mid transfer.
The DMA driver will turn off DMA if it hasn't been used for an amount of
time (to save power).  The SDIO driver for cyw43 WLAN was not informing the
DMA driver that it was using DMA and there was a chance that the DMA would
turn off in the middle of an SDIO DMA transfer.  The symptoms of this would
be printing of SDIO error messages and a failure to communicate with the
cyw43 WLAN module.

This commit fixes this issue by changing the SDIO driver to use the
dma_nohal_XXX API to initialise and start the DMA.

Signed-off-by: Damien George <damien@micropython.org>
2021-05-21 00:08:13 +10:00
Mike Causer
47b778332a all: Replace busses with buses.
"buses" is the widely accepted plural form of "bus".
2021-05-20 23:22:03 +10:00
Mike Causer
1ca66efbf7 stm32/boards: Add VCC_GND_F407ZG board. 2021-05-20 23:17:51 +10:00
Mike Causer
c24003abec stm32/boards: Add VCC_GND_F407VE board. 2021-05-20 23:15:56 +10:00
Damien George
7408ca1d78 mimxrt: Improve ticks and sleep functions using GPT.
SysTick cannot wake the CPU from WFI/WFE so a hardware timer is needed to
keep track of ticks/delay (similar to the nrf port).

Fixes issue #7234.

Signed-off-by: Damien George <damien@micropython.org>
2021-05-18 22:36:32 +10:00
Bruno Martins
ea2d83e961 nrf/boards: Add support for evk_nina_b3 board. 2021-05-18 12:14:57 +10:00
Bruno Martins
94fb5e7f5a nrf: Add machine.memXX, and allow boards to customise some features. 2021-05-18 12:01:51 +10:00
Mike Causer
605b74f390 esp32/boards: Fix spelling mistakes in comments for UM_xxx boards. 2021-05-14 22:26:29 +10:00
Mike Causer
9e65662a11 esp32/boards: Set default I2C and SPI pins on UM_xxx boards.
And fix incorrect I2C and SPI pins in the feathers2 module.
2021-05-14 22:26:05 +10:00
Mike Causer
538b9a9be5 esp32/machine_i2c: Allow boards to configure I2C pins using new macros.
Following how SPI is configured (and how stm32 does it).
2021-05-14 22:22:13 +10:00
Damien George
9a0bca2c2a stm32/mboot: Make LEDs and reset-mode selection more configurable.
A board can now customise mboot with:
- MBOOT_LED1, MBOOT_LED2, MBOOT_LED3, MBOOT_LED4: if it needs to have
  different LEDs for mboot compared to the application
- MBOOT_BOARD_LED_INIT: if it needs a fully customised LED init function
- MBOOT_BOARD_LED_STATE: if it needs a fully customised LED state-setting
  function
- MBOOT_BOARD_GET_RESET_MODE: if it needs a fully customised function to
  get the reset mode

With full customisation, the only requirement is a single LED to show the
status of the bootloader (idle, erasing, flashing, etc), which can be
configured to do nothing if needed.

Signed-off-by: Damien George <damien@micropython.org>
2021-05-12 13:44:57 +10:00
Damien George
6639e282c7 stm32/mboot: Add MBOOT_LEAVE_BOOTLOADER_VIA_RESET option.
It is enabled by default to get the standard behaviour of doing a reset
after it is finished, but can be disabled by a board to jump straight to
the application (likely the board needs to use MBOOT_BOARD_CLEANUP to make
this work).

The application is passed a reset mode of BOARDCTRL_RESET_MODE_BOOTLOADER
if the bootloader was active and entered via a jump.

Signed-off-by: Damien George <damien@micropython.org>
2021-05-12 13:44:52 +10:00
Damien George
9ee116c452 stm32/boardctrl: Adjust logic for running boot.py, main.py.
This new logic is equivalent to the old logic when the only possibilities
for reset_mode are NORMAL, SAFE_MODE and FILESYSTEM, which is the standard
case.  But the new logic also allows other reset_mode values (eg
BOOTLOADER) to run boot.py and main.py.

Signed-off-by: Damien George <damien@micropython.org>
2021-05-12 13:44:47 +10:00